Skip to content

Commit cfec8cf

Browse files
authored
Merge pull request #101 from tinymanorg/feat/tiny-1773-swap-router-v2
Swap route v2 - implement v2 changes
2 parents 44ea94e + 29795f6 commit cfec8cf

43 files changed

Lines changed: 490 additions & 480 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dist/governance/proposal-voting/constants.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ declare enum ProposalVote {
1111
}
1212
declare const EXECUTION_HASH_SIZE = 34;
1313
declare const CREATE_PROPOSAL_DEFAULT_EXECUTION_HASH_ARGUMENT: Uint8Array;
14-
declare const EXECUTOR_FALLBACK_ADDRESS = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ";
15-
export { PROPOSAL_BOX_PREFIX, PROPOSAL_BOX_SIZE, PROPOSAL_BOX_COST, ProposalVote, ACCOUNT_ATTENDANCE_SHEET_BOX_SIZE, ATTENDANCE_SHEET_BOX_PREFIX, ATTENDANCE_SHEET_BOX_COST, EXECUTION_HASH_SIZE, CREATE_PROPOSAL_DEFAULT_EXECUTION_HASH_ARGUMENT, EXECUTOR_FALLBACK_ADDRESS };
14+
export { PROPOSAL_BOX_PREFIX, PROPOSAL_BOX_SIZE, PROPOSAL_BOX_COST, ProposalVote, ACCOUNT_ATTENDANCE_SHEET_BOX_SIZE, ATTENDANCE_SHEET_BOX_PREFIX, ATTENDANCE_SHEET_BOX_COST, EXECUTION_HASH_SIZE, CREATE_PROPOSAL_DEFAULT_EXECUTION_HASH_ARGUMENT };

dist/governance/utils.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ declare function getBias(slope: number, timeDelta: number): number;
1313
declare function calculateTinyPower(lockAmount: number, lockEndTime: number, timeStamp?: number): number;
1414
declare function getCumulativePowerDelta(bias: number, slope: number, timeDelta: number): number;
1515
declare function getGlobalState(algod: AlgodClient, appId: number): Promise<Record<string, any>>;
16-
declare function concatUint8Arrays(...arrays: Uint8Array[]): Uint8Array;
1716
declare function generateCidFromProposalMetadata(metadata: Record<string, any>): Promise<string>;
1817
declare function combineAndRegroupTxns(...txns: Transaction[][]): Transaction[];
1918
declare function getAllBoxNames(algod: AlgodClient, appId: number): Promise<Uint8Array[]>;
20-
export { calculateTinyPower, combineAndRegroupTxns, concatUint8Arrays, doesBoxExist, generateCidFromProposalMetadata, getAllBoxNames, getBias, getCumulativePowerDelta, getGlobalState, getRawBoxValue };
19+
export { calculateTinyPower, combineAndRegroupTxns, doesBoxExist, generateCidFromProposalMetadata, getAllBoxNames, getBias, getCumulativePowerDelta, getGlobalState, getRawBoxValue };

dist/index.d.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
11
import SwapQuoteError from "./util/error/SwapQuoteError";
22
export type { InitiatorSigner, SignerTransaction, SupportedNetwork } from "./util/commonTypes";
3-
export { BASE_MINIMUM_BALANCE, MINIMUM_BALANCE_REQUIRED_PER_ASSET, MINIMUM_BALANCE_REQUIRED_PER_APP, MINIMUM_BALANCE_REQUIRED_PER_BYTE_SCHEMA, MINIMUM_BALANCE_REQUIRED_PER_INT_SCHEMA_VALUE, MINIMUM_ADD_LIQUIDITY_AMOUNT } from "./util/constant";
3+
export { BASE_MINIMUM_BALANCE, MINIMUM_ADD_LIQUIDITY_AMOUNT, MINIMUM_BALANCE_REQUIRED_PER_APP, MINIMUM_BALANCE_REQUIRED_PER_ASSET, MINIMUM_BALANCE_REQUIRED_PER_BYTE_SCHEMA, MINIMUM_BALANCE_REQUIRED_PER_INT_SCHEMA_VALUE } from "./util/constant";
44
export * from "./swap/v2/router";
55
export * from "./swap/common/utils";
6-
export { applySlippageToAmount, ASSET_OPT_IN_PROCESS_TXN_COUNT, convertFromBaseUnits, convertToBaseUnits, sendAndWaitRawTransaction, getTxnGroupID, sumUpTxnFees } from "./util/util";
6+
export { applySlippageToAmount, ASSET_OPT_IN_PROCESS_TXN_COUNT, convertFromBaseUnits, convertToBaseUnits, getTxnGroupID, sendAndWaitRawTransaction, sumUpTxnFees } from "./util/util";
77
export { generateOptIntoAssetTxns } from "./util/asset/assetUtils";
8-
export type { AccountAsset, TinymanAnalyticsApiAsset, IndexerAssetInformation, AssetWithIdAndAmount } from "./util/asset/assetModels";
8+
export type { AccountAsset, AssetWithIdAndAmount, IndexerAssetInformation, TinymanAnalyticsApiAsset } from "./util/asset/assetModels";
99
export { ALGO_ASSET, ALGO_ASSET_ID, POOL_TOKEN_UNIT_NAME } from "./util/asset/assetConstants";
10-
export { getAccountInformation, calculateAccountMinimumRequiredBalance, hasSufficientMinimumBalance, isAccountOptedIntoApp, getAccountExcessWithinPool, getAccountExcess, getMinRequiredBalanceToOptIn } from "./util/account/accountUtils";
10+
export { calculateAccountMinimumRequiredBalance, getAccountExcess, getAccountExcessWithinPool, getAccountInformation, getMinRequiredBalanceToOptIn, hasSufficientMinimumBalance, isAccountOptedIntoApp } from "./util/account/accountUtils";
1111
export type { AccountInformationData } from "./util/account/accountTypes";
12-
export type { ContractVersionValue } from "./contract/types";
1312
export { CONTRACT_VERSION } from "./contract/constants";
14-
export { tinymanContract_v2 } from "./contract/v2/contract";
13+
export type { ContractVersionValue } from "./contract/types";
1514
export { tinymanContract_v1_1 } from "./contract/v1_1/contract";
16-
export { getValidatorAppID, generateOptIntoValidatorTxns, OPT_IN_VALIDATOR_APP_PROCESS_TXN_COUNT, generateOptOutOfValidatorTxns, OPT_OUT_VALIDATOR_APP_PROCESS_TXN_COUNT } from "./validator";
17-
export type { V1PoolInfo, V2PoolInfo, PoolReserves } from "./util/pool/poolTypes";
15+
export { tinymanContract_v2 } from "./contract/v2/contract";
16+
export { generateOptIntoValidatorTxns, generateOptOutOfValidatorTxns, getValidatorAppID, OPT_IN_VALIDATOR_APP_PROCESS_TXN_COUNT, OPT_OUT_VALIDATOR_APP_PROCESS_TXN_COUNT } from "./validator";
17+
export type { PoolReserves, V1PoolInfo, V2PoolInfo } from "./util/pool/poolTypes";
1818
export { PoolStatus } from "./util/pool/poolTypes";
1919
export { poolUtils } from "./util/pool";
2020
export { Bootstrap } from "./bootstrap";
21-
export type { V1_1AddLiquidityQuote, V1_1AddLiquidityExecution } from "./add-liquidity/v1_1/types";
22-
export { V1_1AddLiquidityTxnIndices, V1_1_ADD_LIQUIDITY_PROCESS_TXN_COUNT } from "./add-liquidity/v1_1/constants";
23-
export type { V2InitialAddLiquidityQuote, V2AddLiquidityInternalSwapQuote, V2FlexibleAddLiquidityQuote, V2SingleAssetInAddLiquidityQuote, V2AddLiquidityExecution } from "./add-liquidity/v2/types";
24-
export { V2AddLiquidityType, V2AddLiquidityTxnIndices } from "./add-liquidity/v2/constants";
25-
export { getAddLiquidityTotalFee } from "./add-liquidity/util";
2621
export { AddLiquidity } from "./add-liquidity";
22+
export { getAddLiquidityTotalFee } from "./add-liquidity/util";
23+
export { V1_1_ADD_LIQUIDITY_PROCESS_TXN_COUNT, V1_1AddLiquidityTxnIndices } from "./add-liquidity/v1_1/constants";
24+
export type { V1_1AddLiquidityExecution, V1_1AddLiquidityQuote } from "./add-liquidity/v1_1/types";
25+
export { V2AddLiquidityTxnIndices, V2AddLiquidityType } from "./add-liquidity/v2/constants";
26+
export type { V2AddLiquidityExecution, V2AddLiquidityInternalSwapQuote, V2FlexibleAddLiquidityQuote, V2InitialAddLiquidityQuote, V2SingleAssetInAddLiquidityQuote } from "./add-liquidity/v2/types";
2727
export type { V1_1RemoveLiquidityExecution, V1_1RemoveLiquidityQuote } from "./remove-liquidity/v1_1/types";
28-
export type { V2RemoveLiquidityQuote, V2SingleAssetRemoveLiquidityQuote, V2RemoveLiquidityExecution } from "./remove-liquidity/v2/types";
28+
export type { V2RemoveLiquidityExecution, V2RemoveLiquidityQuote, V2SingleAssetRemoveLiquidityQuote } from "./remove-liquidity/v2/types";
29+
export { RemoveLiquidity } from "./remove-liquidity";
2930
export { V1_1_REMOVE_LIQUIDITY_TXN_COUNT } from "./remove-liquidity/v1_1/constants";
3031
export { V2_REMOVE_LIQUIDITY_APP_CALL_INNER_TXN_COUNT } from "./remove-liquidity/v2/constants";
31-
export { RemoveLiquidity } from "./remove-liquidity";
32-
export type { SwapQuote, V1SwapExecution, V2SwapExecution, DirectSwapQuote, SwapRoute, GenerateSwapTxnsParams } from "./swap/types";
33-
export * from "./swap/v2/util";
34-
export { SwapType } from "./swap/constants";
3532
export { Swap } from "./swap";
33+
export { SwapType } from "./swap/constants";
34+
export type { DirectSwapQuote, GenerateSwapTxnsParams, SwapQuote, SwapRouterResponse, V1SwapExecution, V2SwapExecution } from "./swap/types";
35+
export * from "./swap/v2/util";
3636
export { SwapQuoteType } from "./swap/types";
3737
export { SwapQuoteError };
3838
export { SwapQuoteErrorType } from "./util/error/SwapQuoteError";
39-
export { redeemExcessAsset, redeemAllExcessAsset, generateRedeemTxns, REDEEM_PROCESS_TXN_COUNT } from "./redeem";
39+
export { generateRedeemTxns, REDEEM_PROCESS_TXN_COUNT, redeemAllExcessAsset, redeemExcessAsset } from "./redeem";
4040
export { fetchFolksLendingPool, LendingPool } from "./folks-lending-pools";
4141
export type { FolksLendingPool } from "./folks-lending-pools/types";
42-
export { prepareCommitTransactions, getStakingAppID } from "./stake";
4342
export { tinymanJSSDKConfig } from "./config";
43+
export { getStakingAppID, prepareCommitTransactions } from "./stake";
4444
export { combineAndRegroupSignerTxns, getAppCallInnerAssetData } from "./util/transaction/transactionUtils";
4545
export { TinymanGovernanceClient } from "./governance";
4646
export type { RawBoxCacheValue } from "./governance/types";
4747
export { TinymanSTAlgoClient } from "./liquid-stake/stAlgoClient";
4848
export { TinymanTAlgoClient } from "./liquid-stake/tAlgoClient";
49-
export { AccountState } from "./governance/vault/storage";
50-
export { getStartTimestampOfWeek } from "./governance/vault/utils";
5149
export { ProposalVote } from "./governance/proposal-voting/constants";
5250
export { generateProposalMetadata } from "./governance/proposal-voting/transactions";
5351
export type { GenerateProposalMetadataPayload } from "./governance/proposal-voting/types";
5452
export { intToBytes } from "./governance/util/utils";
55-
export { generateCidFromProposalMetadata, calculateTinyPower, combineAndRegroupTxns, concatUint8Arrays } from "./governance/utils";
53+
export { AccountState } from "./governance/vault/storage";
54+
export { getStartTimestampOfWeek } from "./governance/vault/utils";
55+
export { calculateTinyPower, combineAndRegroupTxns, generateCidFromProposalMetadata } from "./governance/utils";

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/stake.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ declare function prepareCommitTransactions({ client, stakingAppID, program, requ
1616
requiredAssetID?: number;
1717
}): Promise<SignerTransaction[]>;
1818
declare function getStakingAppID(network: SupportedNetwork): 51948952 | 649588853;
19-
export { prepareCommitTransactions, getStakingAppID };
19+
export { getStakingAppID, prepareCommitTransactions };

dist/swap/common/utils.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ declare function getSwapQuoteRate(quote: SwapQuote): number;
4040
*/
4141
declare function getBestQuote(quotes: SwapQuote[]): SwapQuote;
4242
declare function isSwapQuoteErrorCausedByAmount(error: Error): boolean;
43-
export { calculateSwapRate, calculatePriceImpact, getSwapQuotePriceImpact, getAssetInFromSwapQuote, getAssetOutFromSwapQuote, getAssetInAndAssetOutFromSwapQuote, getSwapQuoteContractVersion, getSwapTotalFee, getSwapQuoteRate, getBestQuote, isSwapQuoteErrorCausedByAmount };
43+
export { calculatePriceImpact, calculateSwapRate, getAssetInAndAssetOutFromSwapQuote, getAssetInFromSwapQuote, getAssetOutFromSwapQuote, getBestQuote, getSwapQuoteContractVersion, getSwapQuotePriceImpact, getSwapQuoteRate, getSwapTotalFee, isSwapQuoteErrorCausedByAmount };

dist/swap/index.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,23 @@ export declare const Swap: {
4747
}) => Promise<Omit<import("./types").V1SwapExecution, "fees" | "groupID">>;
4848
};
4949
v2: {
50-
getQuote: ({ type, amount, assetIn, assetOut, network, isSwapRouterEnabled, pool }: {
50+
getQuote: ({ type, amount, assetIn, assetOut, network, slippage, isSwapRouterEnabled, pool }: {
5151
type: import("./constants").SwapType;
5252
amount: number | bigint;
5353
assetIn: import("../util/asset/assetModels").AssetWithIdAndDecimals;
5454
assetOut: import("../util/asset/assetModels").AssetWithIdAndDecimals;
5555
pool: import("..").V2PoolInfo | null;
5656
network: import("..").SupportedNetwork;
57+
slippage: number;
5758
isSwapRouterEnabled?: boolean | undefined;
5859
}) => Promise<import("./types").SwapQuote>;
59-
getFixedInputSwapQuote: ({ amount, assetIn, assetOut, isSwapRouterEnabled, network, pool }: {
60+
getFixedInputSwapQuote: ({ amount, assetIn, assetOut, isSwapRouterEnabled, network, slippage, pool }: {
6061
amount: number | bigint;
6162
assetIn: import("../util/asset/assetModels").AssetWithIdAndDecimals;
6263
assetOut: import("../util/asset/assetModels").AssetWithIdAndDecimals;
6364
network: import("..").SupportedNetwork;
6465
pool: import("..").V2PoolInfo | null;
66+
slippage: number;
6567
isSwapRouterEnabled?: boolean | undefined;
6668
}) => Promise<import("./types").SwapQuote>;
6769
getFixedInputDirectSwapQuote: ({ amount, assetIn, assetOut, pool }: {
@@ -76,12 +78,13 @@ export declare const Swap: {
7678
assetIn: import("../util/asset/assetModels").AssetWithIdAndDecimals;
7779
assetOut: import("../util/asset/assetModels").AssetWithIdAndDecimals;
7880
}) => import("./types").SwapQuote;
79-
getFixedOutputSwapQuote: ({ amount, assetIn, assetOut, isSwapRouterEnabled, network, pool }: {
81+
getFixedOutputSwapQuote: ({ amount, assetIn, assetOut, isSwapRouterEnabled, network, slippage, pool }: {
8082
amount: number | bigint;
8183
assetIn: import("../util/asset/assetModels").AssetWithIdAndDecimals;
8284
assetOut: import("../util/asset/assetModels").AssetWithIdAndDecimals;
8385
pool: import("..").V2PoolInfo | null;
8486
network: import("..").SupportedNetwork;
87+
slippage: number;
8588
isSwapRouterEnabled?: boolean | undefined;
8689
}) => Promise<import("./types").SwapQuote>;
8790
generateTxns: (params: import("./types").GenerateSwapTxnsParams) => Promise<import("..").SignerTransaction[]>;

dist/swap/types.d.ts

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Algodv2 } from "algosdk";
1+
import { Algodv2, TransactionType } from "algosdk";
22
import { AssetWithIdAndAmount, TinymanAnalyticsApiAsset } from "../util/asset/assetModels";
33
import { SignerTransaction, SupportedNetwork } from "../util/commonTypes";
44
import { PoolReserves, V1PoolInfo, V2PoolInfo } from "../util/pool/poolTypes";
@@ -41,41 +41,42 @@ export interface SwapRoutePool {
4141
asset_2: SwapRouteAsset;
4242
version: "2.0";
4343
}
44-
export type SwapRoute = {
45-
quote: SwapRouterQuote;
46-
pool: SwapRoutePool;
47-
}[];
48-
export interface SwapRouterQuote {
49-
swap_type: SwapType;
50-
amount_in: {
51-
asset: SwapRouteAsset;
52-
amount: string;
53-
};
54-
amount_out: {
55-
asset: SwapRouteAsset;
56-
amount: string;
57-
};
58-
swap_fees: {
59-
amount: string;
60-
asset: SwapRouteAsset;
61-
};
62-
price: number;
63-
price_impact: number;
64-
}
6544
export interface FetchSwapRouteQuotesPayload {
6645
asset_in_id: string;
6746
asset_out_id: string;
68-
amount: string;
47+
input_amount?: string;
48+
output_amount?: string;
6949
swap_type: SwapType;
50+
slippage: number;
7051
}
71-
export type SwapRouterResponse = FetchSwapRouteQuotesPayload & {
72-
route: SwapRoute;
73-
price_impact: string;
52+
export type SwapRouterResponse = Pick<FetchSwapRouteQuotesPayload, "swap_type"> & {
53+
asset_in: Pick<TinymanAnalyticsApiAsset, "id" | "decimals" | "name" | "unit_name">;
54+
asset_out: Pick<TinymanAnalyticsApiAsset, "id" | "decimals" | "name" | "unit_name">;
55+
price_impact: string | null;
7456
status: {
7557
round_number: string;
7658
round_datetime: string;
7759
};
60+
transaction_count: number | null;
61+
transactions: SwapRouterTransactionRecipe[] | null;
62+
transaction_fee: string | null;
63+
swap_fee: string | null;
64+
input_amount: string | null;
65+
output_amount: string | null;
66+
asset_ids: number[] | null;
67+
pool_ids: string[] | null;
7868
};
69+
export interface SwapRouterTransactionRecipe {
70+
type: TransactionType;
71+
receiver?: string;
72+
app_id: number;
73+
asset_id: number;
74+
amount: number;
75+
args: string[] | null;
76+
accounts?: string[];
77+
assets?: number[];
78+
apps?: number[];
79+
}
7980
export type GetSwapQuoteParams = {
8081
assetIn: Pick<TinymanAnalyticsApiAsset, "id" | "decimals">;
8182
assetOut: Pick<TinymanAnalyticsApiAsset, "id" | "decimals">;
@@ -88,6 +89,8 @@ export type GetSwapQuoteParams = {
8889
network: SupportedNetwork;
8990
/** If `true`, the function will also check the quotes that use swap route */
9091
isSwapRouterEnabled?: boolean;
92+
/** Slippage rate. Should be given as 0.1% -> 0.001. */
93+
slippage: number;
9194
};
9295
export type SwapQuote = {
9396
data: DirectSwapQuoteAndPool;

dist/swap/v1_1/index.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ import { PoolReserves, V1PoolInfo } from "../../util/pool/poolTypes";
44
import { GenerateV1_1SwapTxnsParams, SwapQuote, V1SwapExecution } from "../types";
55
import { SwapType } from "../constants";
66
import { AssetWithIdAndAmount } from "../../util/asset/assetModels";
7+
/**
8+
* @deprecated Use `generateTxns` in V2 instead. This will be removed soon.
9+
*/
710
declare function signTxns({ pool, txGroup, initiatorSigner }: {
811
pool: V1PoolInfo;
912
txGroup: SignerTransaction[];
1013
initiatorSigner: InitiatorSigner;
1114
}): Promise<Uint8Array[]>;
15+
/**
16+
* @deprecated Use `generateTxns` in V2 instead. This will be removed soon.
17+
*/
1218
declare function generateTxns({ client, quoteAndPool, swapType, slippage, initiatorAddr }: GenerateV1_1SwapTxnsParams): Promise<SignerTransaction[]>;
1319
/**
20+
* @deprecated Use `getQuote` in V2 instead. This will be removed soon.
1421
*
1522
* @param type - Type of the swap
1623
* @param pool - Information for the pool.
@@ -26,6 +33,8 @@ declare function getQuote(type: SwapType, pool: V1PoolInfo, reserves: PoolReserv
2633
assetOut: number;
2734
}): SwapQuote;
2835
/**
36+
* @deprecated Use `getFixedInputSwapQuote` in V2 instead. This will be removed soon.
37+
*
2938
* Get a quote for a fixed input swap This does not execute any transactions.
3039
*
3140
* @param params.pool Information for the pool.
@@ -44,6 +53,8 @@ declare function getFixedInputSwapQuote({ pool, reserves, assetIn, decimals }: {
4453
};
4554
}): SwapQuote;
4655
/**
56+
* @deprecated Use `getFixedOutputSwapQuote` in V2 instead. This will be removed soon.
57+
*
4758
* Get a quote for a fixed output swap This does not execute any transactions.
4859
*
4960
* @param params.pool Information for the pool.
@@ -62,6 +73,7 @@ declare function getFixedOutputSwapQuote({ pool, reserves, assetOut, decimals }:
6273
};
6374
}): SwapQuote;
6475
/**
76+
* @deprecated
6577
* Execute a fixed output swap with the desired quantities.
6678
*
6779
* @param params.client An Algodv2 client.
@@ -87,6 +99,8 @@ declare function executeFixedOutputSwap({ client, pool, signedTxns, assetIn, ass
8799
initiatorAddr: string;
88100
}): Promise<Omit<V1SwapExecution, "fees" | "groupID">>;
89101
/**
102+
* @deprecated Use `execute` in V2 instead. This will be removed soon.
103+
*
90104
* Execute a swap with the desired quantities.
91105
*
92106
* @param params.client An Algodv2 client.

0 commit comments

Comments
 (0)