Skip to content

Commit

Permalink
Merge pull request #103 from tinymanorg/chore/tiny-1787-always-enable…
Browse files Browse the repository at this point in the history
…-swap-router

Enable swap-router as default
  • Loading branch information
gulcinuras authored Jan 22, 2025
2 parents cfec8cf + b0662d6 commit 9542273
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 71 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions dist/swap/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,22 @@ export declare const Swap: {
}) => Promise<Omit<import("./types").V1SwapExecution, "fees" | "groupID">>;
};
v2: {
getQuote: ({ type, amount, assetIn, assetOut, network, slippage, isSwapRouterEnabled, pool }: {
getQuote: ({ type, amount, assetIn, assetOut, network, slippage, pool }: {
type: import("./constants").SwapType;
amount: number | bigint;
assetIn: import("../util/asset/assetModels").AssetWithIdAndDecimals;
assetOut: import("../util/asset/assetModels").AssetWithIdAndDecimals;
pool: import("..").V2PoolInfo | null;
network: import("..").SupportedNetwork;
slippage: number;
isSwapRouterEnabled?: boolean | undefined;
}) => Promise<import("./types").SwapQuote>;
getFixedInputSwapQuote: ({ amount, assetIn, assetOut, isSwapRouterEnabled, network, slippage, pool }: {
getFixedInputSwapQuote: ({ amount, assetIn, assetOut, network, slippage, pool }: {
amount: number | bigint;
assetIn: import("../util/asset/assetModels").AssetWithIdAndDecimals;
assetOut: import("../util/asset/assetModels").AssetWithIdAndDecimals;
network: import("..").SupportedNetwork;
pool: import("..").V2PoolInfo | null;
slippage: number;
isSwapRouterEnabled?: boolean | undefined;
}) => Promise<import("./types").SwapQuote>;
getFixedInputDirectSwapQuote: ({ amount, assetIn, assetOut, pool }: {
pool: import("..").V2PoolInfo;
Expand All @@ -78,14 +76,13 @@ export declare const Swap: {
assetIn: import("../util/asset/assetModels").AssetWithIdAndDecimals;
assetOut: import("../util/asset/assetModels").AssetWithIdAndDecimals;
}) => import("./types").SwapQuote;
getFixedOutputSwapQuote: ({ amount, assetIn, assetOut, isSwapRouterEnabled, network, slippage, pool }: {
getFixedOutputSwapQuote: ({ amount, assetIn, assetOut, network, slippage, pool }: {
amount: number | bigint;
assetIn: import("../util/asset/assetModels").AssetWithIdAndDecimals;
assetOut: import("../util/asset/assetModels").AssetWithIdAndDecimals;
pool: import("..").V2PoolInfo | null;
network: import("..").SupportedNetwork;
slippage: number;
isSwapRouterEnabled?: boolean | undefined;
}) => Promise<import("./types").SwapQuote>;
generateTxns: (params: import("./types").GenerateSwapTxnsParams) => Promise<import("..").SignerTransaction[]>;
signTxns: ({ txGroup, initiatorSigner }: {
Expand Down
2 changes: 0 additions & 2 deletions dist/swap/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ export type GetSwapQuoteParams = {
amount: number | bigint;
type: SwapType;
network: SupportedNetwork;
/** If `true`, the function will also check the quotes that use swap route */
isSwapRouterEnabled?: boolean;
/** Slippage rate. Should be given as 0.1% -> 0.001. */
slippage: number;
};
Expand Down
2 changes: 1 addition & 1 deletion dist/swap/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CONTRACT_VERSION } from "../contract/constants";
import { InitiatorSigner, SignerTransaction } from "../util/commonTypes";
import { V1PoolInfo } from "../util/pool/poolTypes";
import { GetSwapQuoteBySwapTypeParams, GenerateSwapTxnsParams, GetSwapQuoteParams, SwapQuote, ExecuteSwapCommonParams } from "./types";
import { SwapType } from "./constants";
import { ExecuteSwapCommonParams, GenerateSwapTxnsParams, GetSwapQuoteBySwapTypeParams, GetSwapQuoteParams, SwapQuote } from "./types";
/**
* Gets the best quote for swap from the pools and swap router and returns the best option.
*/
Expand Down
10 changes: 3 additions & 7 deletions dist/swap/v2/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@ declare function execute({ client, quote, txGroup, signedTxns }: {
* @param assetOut - Asset to be received
* @param amount - Amount of asset to be swapped
* @param network - Network to be used
* @param isSwapRouterEnabled - Whether the swap router is enabled
* @returns A promise for the Swap quote
*/
declare function getQuote({ type, amount, assetIn, assetOut, network, slippage, isSwapRouterEnabled, pool }: {
declare function getQuote({ type, amount, assetIn, assetOut, network, slippage, pool }: {
type: SwapType;
amount: number | bigint;
assetIn: AssetWithIdAndDecimals;
assetOut: AssetWithIdAndDecimals;
pool: V2PoolInfo | null;
network: SupportedNetwork;
slippage: number;
isSwapRouterEnabled?: boolean;
}): Promise<SwapQuote>;
declare function getFixedInputDirectSwapQuote({ amount, assetIn, assetOut, pool }: {
pool: V2PoolInfo;
Expand All @@ -53,26 +51,24 @@ declare function getFixedOutputDirectSwapQuote({ amount, assetIn, assetOut, pool
/**
* @returns A quote for a fixed input swap. Does NOT execute any transactions.
*/
declare function getFixedInputSwapQuote({ amount, assetIn, assetOut, isSwapRouterEnabled, network, slippage, pool }: {
declare function getFixedInputSwapQuote({ amount, assetIn, assetOut, network, slippage, pool }: {
amount: number | bigint;
assetIn: AssetWithIdAndDecimals;
assetOut: AssetWithIdAndDecimals;
network: SupportedNetwork;
pool: V2PoolInfo | null;
slippage: number;
isSwapRouterEnabled?: boolean;
}): Promise<SwapQuote>;
/**
* @returns A quote for a fixed output swap. Does NOT execute any transactions.
*/
declare function getFixedOutputSwapQuote({ amount, assetIn, assetOut, isSwapRouterEnabled, network, slippage, pool }: {
declare function getFixedOutputSwapQuote({ amount, assetIn, assetOut, network, slippage, pool }: {
amount: number | bigint;
assetIn: AssetWithIdAndDecimals;
assetOut: AssetWithIdAndDecimals;
pool: V2PoolInfo | null;
network: SupportedNetwork;
slippage: number;
isSwapRouterEnabled?: boolean;
}): Promise<SwapQuote>;
declare function calculateFixedInputSwap({ inputSupply, outputSupply, swapInputAmount, totalFeeShare, decimals }: {
inputSupply: bigint;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tinymanorg/tinyman-js-sdk",
"version": "4.1.3",
"version": "4.1.4",
"description": "Tinyman JS SDK",
"author": "Tinyman Core Team",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/liquid-stake/tAlgoClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe("TinymanTAlgoClient", () => {

// Check if the account has the correct amount of tALGOs
expect(tAlgoAccountAsset?.amount).toBeCloseTo(expectedTAlgoAmount);
}, 10000);
}, 18000);
it("should create burn transactions", async () => {
const spy = jest.spyOn(client, "burn");

Expand Down
2 changes: 0 additions & 2 deletions src/swap/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ export type GetSwapQuoteParams = {
amount: number | bigint;
type: SwapType;
network: SupportedNetwork;
/** If `true`, the function will also check the quotes that use swap route */
isSwapRouterEnabled?: boolean;
/** Slippage rate. Should be given as 0.1% -> 0.001. */
slippage: number;
};
Expand Down
28 changes: 13 additions & 15 deletions src/swap/utils.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import {CONTRACT_VERSION} from "../contract/constants";
import {getAssetId} from "../util/asset/assetUtils";
import {InitiatorSigner, SignerTransaction} from "../util/commonTypes";
import SwapQuoteError, {SwapQuoteErrorType} from "../util/error/SwapQuoteError";
import {V1PoolInfo} from "../util/pool/poolTypes";
import {
GetSwapQuoteBySwapTypeParams,
getBestQuote,
getSwapQuoteContractVersion,
isSwapQuoteErrorCausedByAmount
} from "./common/utils";
import {SwapType} from "./constants";
import {
ExecuteSwapCommonParams,
GenerateSwapTxnsParams,
GetSwapQuoteBySwapTypeParams,
GetSwapQuoteParams,
SwapQuote,
SwapQuoteType,
ExecuteSwapCommonParams
SwapQuoteType
} from "./types";
import {SwapType} from "./constants";
import {SwapV1_1} from "./v1_1";
import {SwapV2} from "./v2";
import {
getBestQuote,
getSwapQuoteContractVersion,
isSwapQuoteErrorCausedByAmount
} from "./common/utils";
import {getAssetId} from "../util/asset/assetUtils";
import SwapQuoteError, {SwapQuoteErrorType} from "../util/error/SwapQuoteError";

/**
* Gets the best quote for swap from the pools and swap router and returns the best option.
Expand Down Expand Up @@ -74,7 +74,7 @@ function validateQuotes(promises: Promise<SwapQuote>[]): Promise<SwapQuote[]> {
export async function getFixedInputSwapQuote(
params: GetSwapQuoteBySwapTypeParams
): Promise<SwapQuote> {
const {amount, assetIn, assetOut, isSwapRouterEnabled, pools} = params;
const {amount, assetIn, assetOut, pools} = params;

const quotePromises: Promise<SwapQuote>[] = [];

Expand Down Expand Up @@ -124,7 +124,6 @@ export async function getFixedInputSwapQuote(
decimals: assetOut.decimals
},
pool: v2Pool?.info ?? null,
isSwapRouterEnabled,
network: params.network,
slippage: params.slippage
})
Expand All @@ -142,7 +141,7 @@ export async function getFixedInputSwapQuote(
export async function getFixedOutputSwapQuote(
params: GetSwapQuoteBySwapTypeParams
): Promise<SwapQuote> {
const {amount, assetIn, assetOut, pools, isSwapRouterEnabled} = params;
const {amount, assetIn, assetOut, pools} = params;

const quotePromises: Promise<SwapQuote>[] = [];

Expand Down Expand Up @@ -192,7 +191,6 @@ export async function getFixedOutputSwapQuote(
decimals: assetOut.decimals
},
pool: v2Pool?.info ?? null,
isSwapRouterEnabled,
network: params.network,
slippage: params.slippage
})
Expand Down
53 changes: 20 additions & 33 deletions src/swap/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ async function execute({
* @param assetOut - Asset to be received
* @param amount - Amount of asset to be swapped
* @param network - Network to be used
* @param isSwapRouterEnabled - Whether the swap router is enabled
* @returns A promise for the Swap quote
*/
async function getQuote({
Expand All @@ -214,7 +213,6 @@ async function getQuote({
assetOut,
network,
slippage,
isSwapRouterEnabled,
pool
}: {
type: SwapType;
Expand All @@ -224,7 +222,6 @@ async function getQuote({
pool: V2PoolInfo | null;
network: SupportedNetwork;
slippage: number;
isSwapRouterEnabled?: boolean;
}): Promise<SwapQuote> {
let quote: SwapQuote;

Expand All @@ -233,7 +230,6 @@ async function getQuote({
assetIn,
assetOut,
amount,
isSwapRouterEnabled,
network,
pool,
slippage
Expand All @@ -243,7 +239,6 @@ async function getQuote({
amount,
assetIn,
assetOut,
isSwapRouterEnabled,
network,
pool,
slippage
Expand Down Expand Up @@ -460,7 +455,6 @@ async function getFixedInputSwapQuote({
amount,
assetIn,
assetOut,
isSwapRouterEnabled,
network,
slippage,
pool
Expand All @@ -471,7 +465,6 @@ async function getFixedInputSwapQuote({
network: SupportedNetwork;
pool: V2PoolInfo | null;
slippage: number;
isSwapRouterEnabled?: boolean;
}): Promise<SwapQuote> {
const quotePromises: Promise<SwapQuote>[] = [];

Expand Down Expand Up @@ -509,18 +502,16 @@ async function getFixedInputSwapQuote({
);
}

if (isSwapRouterEnabled) {
quotePromises.push(
getSwapRoute({
amount,
assetInID: assetIn.id,
assetOutID: assetOut.id,
swapType: SwapType.FixedInput,
network,
slippage
}).then((data) => ({type: SwapQuoteType.Router, data}))
);
}
quotePromises.push(
getSwapRoute({
amount,
assetInID: assetIn.id,
assetOutID: assetOut.id,
swapType: SwapType.FixedInput,
network,
slippage
}).then((data) => ({type: SwapQuoteType.Router, data}))
);

const validQuotes = await validateQuotes(quotePromises);

Expand All @@ -534,7 +525,6 @@ async function getFixedOutputSwapQuote({
amount,
assetIn,
assetOut,
isSwapRouterEnabled,
network,
slippage,
pool
Expand All @@ -545,7 +535,6 @@ async function getFixedOutputSwapQuote({
pool: V2PoolInfo | null;
network: SupportedNetwork;
slippage: number;
isSwapRouterEnabled?: boolean;
}): Promise<SwapQuote> {
const quotePromises: Promise<SwapQuote>[] = [
new Promise((resolve, reject) => {
Expand All @@ -564,18 +553,16 @@ async function getFixedOutputSwapQuote({
})
];

if (isSwapRouterEnabled) {
quotePromises.push(
getSwapRoute({
amount,
assetInID: assetIn.id,
assetOutID: assetOut.id,
swapType: SwapType.FixedOutput,
network,
slippage
}).then((data) => ({type: SwapQuoteType.Router, data}))
);
}
quotePromises.push(
getSwapRoute({
amount,
assetInID: assetIn.id,
assetOutID: assetOut.id,
swapType: SwapType.FixedOutput,
network,
slippage
}).then((data) => ({type: SwapQuoteType.Router, data}))
);

const validQuotes = await validateQuotes(quotePromises);

Expand Down

0 comments on commit 9542273

Please sign in to comment.