Skip to content

Commit 1feb8cc

Browse files
authored
Merge pull request #112 from tinymanorg/feat/split-router
Implement swap-router v3
2 parents 9ccfcca + 96bfb45 commit 1feb8cc

22 files changed

+279
-111
lines changed

dist/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import SwapQuoteError from "./util/error/SwapQuoteError";
22
export type { InitiatorSigner, SignerTransaction, SupportedNetwork } from "./util/commonTypes";
33
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";
4-
export * from "./swap/v2/router";
4+
export * from "./swap/router";
55
export * from "./swap/common/utils";
66
export { applySlippageToAmount, ASSET_OPT_IN_PROCESS_TXN_COUNT, convertFromBaseUnits, convertToBaseUnits, getTxnGroupID, sendAndWaitRawTransaction, sumUpTxnFees, joinByteArrays, intToBytes } from "./util/util";
77
export { generateOptIntoAssetTxns } from "./util/asset/assetUtils";

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/swap/router/constants.d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { SupportedNetwork } from "../../util/commonTypes";
2+
import { SwapType } from "../constants";
3+
export declare const SWAP_ROUTER_APP_ID: Record<SupportedNetwork, number>;
4+
/**
5+
* Inner txn counts according to the swap type
6+
*/
7+
export declare const SWAP_ROUTER_INNER_TXN_COUNT: Record<SwapType, number>;
8+
export declare enum V2SwapRouterSwapAppCallArgsIndices {
9+
TxnType = 0,
10+
InputAmount = 1,
11+
OutputAmount = 2,
12+
Routes = 3,
13+
Pools = 4,
14+
Swaps = 5
15+
}
16+
export declare enum V2SwapRouterAppCallArgsTxnType {
17+
Swap = "swap",
18+
AssetOptIn = "asset_opt_in",
19+
Noop = "noop"
20+
}
21+
export declare const SWAP_ROUTER_SWAP_APP_CALL_ARGS_LENGTH = 6;

dist/swap/router/swap-router.d.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import algosdk, { Algodv2 } from "algosdk";
2+
import { SupportedNetwork } from "../../util/commonTypes";
3+
import { SwapType } from "../constants";
4+
import { SwapRouterResponse } from "../types";
5+
export declare function generateSwapRouterTxns({ initiatorAddr, client, route }: {
6+
client: Algodv2;
7+
initiatorAddr: string;
8+
route: SwapRouterResponse;
9+
}): Promise<{
10+
txn: algosdk.Transaction;
11+
signers: string[];
12+
}[]>;
13+
export declare function getSwapRoute({ amount, assetInID, assetOutID, swapType, network, slippage }: {
14+
assetInID: number;
15+
assetOutID: number;
16+
swapType: SwapType;
17+
amount: number | bigint;
18+
network: SupportedNetwork;
19+
slippage: string;
20+
}): Promise<SwapRouterResponse>;

dist/swap/router/util.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { SupportedNetwork } from "../../util/commonTypes";
2+
import { SwapRouterResponse } from "../types";
3+
declare function getSwapRouteRate(route: Pick<SwapRouterResponse, "input_asset" | "output_asset" | "input_amount" | "output_amount">): number;
4+
declare function getSwapRouterAppID(network: SupportedNetwork): number;
5+
declare function getAssetOutFromSwapRoute(route: Pick<SwapRouterResponse, "output_asset" | "output_amount">): {
6+
asset: Pick<import("../..").TinymanAnalyticsApiAsset, "id" | "decimals" | "name" | "unit_name">;
7+
amount: bigint;
8+
};
9+
declare function getAssetInFromSwapRoute(route: Pick<SwapRouterResponse, "input_asset" | "input_amount">): {
10+
asset: Pick<import("../..").TinymanAnalyticsApiAsset, "id" | "decimals" | "name" | "unit_name">;
11+
amount: bigint;
12+
};
13+
declare function getAssetInAndOutFromSwapRoute(route: Pick<SwapRouterResponse, "input_asset" | "output_asset" | "input_amount" | "output_amount">): {
14+
assetIn: {
15+
asset: Pick<import("../..").TinymanAnalyticsApiAsset, "id" | "decimals" | "name" | "unit_name">;
16+
amount: bigint;
17+
};
18+
assetOut: {
19+
asset: Pick<import("../..").TinymanAnalyticsApiAsset, "id" | "decimals" | "name" | "unit_name">;
20+
amount: bigint;
21+
};
22+
};
23+
export { getAssetInAndOutFromSwapRoute, getAssetInFromSwapRoute, getAssetOutFromSwapRoute, getSwapRouterAppID, getSwapRouteRate };

dist/swap/router/v2/constants.d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { SupportedNetwork } from "../../../util/commonTypes";
2+
import { SwapType } from "../../constants";
3+
export declare const SWAP_ROUTER_APP_ID: Record<SupportedNetwork, number>;
4+
/**
5+
* Inner txn counts according to the swap type
6+
*/
7+
export declare const SWAP_ROUTER_INNER_TXN_COUNT: Record<SwapType, number>;
8+
export declare enum V2SwapRouterSwapAppCallArgsIndices {
9+
TxnType = 0,
10+
InputAmount = 1,
11+
OutputAmount = 2,
12+
Routes = 3,
13+
Pools = 4,
14+
Swaps = 5
15+
}
16+
export declare enum V2SwapRouterAppCallArgsTxnType {
17+
Swap = "swap",
18+
AssetOptIn = "asset_opt_in",
19+
Noop = "noop"
20+
}
21+
export declare const SWAP_ROUTER_SWAP_APP_CALL_ARGS_LENGTH = 6;

dist/swap/router/v2/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./swap-router";
2+
export * from "./util";
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import algosdk, { Algodv2, SuggestedParams } from "algosdk";
2+
import { SupportedNetwork } from "../../../util/commonTypes";
3+
import { SwapType } from "../../constants";
4+
import { SwapRouterResponse, SwapRouterTransactionRecipe } from "../../types";
5+
export declare function generateSwapRouterTxns({ initiatorAddr, client, route }: {
6+
client: Algodv2;
7+
initiatorAddr: string;
8+
route: SwapRouterResponse;
9+
}): Promise<{
10+
txn: algosdk.Transaction;
11+
signers: string[];
12+
}[]>;
13+
export declare function generateSwapRouterTxnFromRecipe(recipe: SwapRouterTransactionRecipe, suggestedParams: SuggestedParams, userAddress: string): algosdk.Transaction;
14+
export declare function getSwapRoute({ amount, assetInID, assetOutID, swapType, network, slippage }: {
15+
assetInID: number;
16+
assetOutID: number;
17+
swapType: SwapType;
18+
amount: number | bigint;
19+
network: SupportedNetwork;
20+
slippage: number;
21+
}): Promise<SwapRouterResponse>;

dist/swap/router/v2/util.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { SupportedNetwork } from "../../../util/commonTypes";
2+
import { SwapRouterResponse } from "../../types";
3+
declare function getSwapRouteRate(route: Pick<SwapRouterResponse, "asset_in" | "asset_out" | "input_amount" | "output_amount">): number;
4+
declare function getSwapRouterAppID(network: SupportedNetwork): number;
5+
declare function getAssetOutFromSwapRoute(route: Pick<SwapRouterResponse, "asset_out" | "output_amount">): {
6+
asset: Pick<import("../../..").TinymanAnalyticsApiAsset, "id" | "decimals" | "name" | "unit_name">;
7+
amount: bigint;
8+
};
9+
declare function getAssetInFromSwapRoute(route: Pick<SwapRouterResponse, "asset_in" | "input_amount">): {
10+
asset: Pick<import("../../..").TinymanAnalyticsApiAsset, "id" | "decimals" | "name" | "unit_name">;
11+
amount: bigint;
12+
};
13+
declare function getAssetInAndOutFromSwapRoute(route: Pick<SwapRouterResponse, "asset_in" | "asset_out" | "input_amount" | "output_amount">): {
14+
assetIn: {
15+
asset: Pick<import("../../..").TinymanAnalyticsApiAsset, "id" | "decimals" | "name" | "unit_name">;
16+
amount: bigint;
17+
};
18+
assetOut: {
19+
asset: Pick<import("../../..").TinymanAnalyticsApiAsset, "id" | "decimals" | "name" | "unit_name">;
20+
amount: bigint;
21+
};
22+
};
23+
export { getAssetInAndOutFromSwapRoute, getAssetInFromSwapRoute, getAssetOutFromSwapRoute, getSwapRouterAppID, getSwapRouteRate };

0 commit comments

Comments
 (0)