Skip to content

Commit

Permalink
Merge pull request #101 from tinymanorg/feat/tiny-1773-swap-router-v2
Browse files Browse the repository at this point in the history
Swap route v2 - implement v2 changes
  • Loading branch information
gulcinuras authored Jan 13, 2025
2 parents 44ea94e + 29795f6 commit cfec8cf
Show file tree
Hide file tree
Showing 43 changed files with 490 additions and 480 deletions.
3 changes: 1 addition & 2 deletions dist/governance/proposal-voting/constants.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ declare enum ProposalVote {
}
declare const EXECUTION_HASH_SIZE = 34;
declare const CREATE_PROPOSAL_DEFAULT_EXECUTION_HASH_ARGUMENT: Uint8Array;
declare const EXECUTOR_FALLBACK_ADDRESS = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ";
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 };
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 };
3 changes: 1 addition & 2 deletions dist/governance/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ declare function getBias(slope: number, timeDelta: number): number;
declare function calculateTinyPower(lockAmount: number, lockEndTime: number, timeStamp?: number): number;
declare function getCumulativePowerDelta(bias: number, slope: number, timeDelta: number): number;
declare function getGlobalState(algod: AlgodClient, appId: number): Promise<Record<string, any>>;
declare function concatUint8Arrays(...arrays: Uint8Array[]): Uint8Array;
declare function generateCidFromProposalMetadata(metadata: Record<string, any>): Promise<string>;
declare function combineAndRegroupTxns(...txns: Transaction[][]): Transaction[];
declare function getAllBoxNames(algod: AlgodClient, appId: number): Promise<Uint8Array[]>;
export { calculateTinyPower, combineAndRegroupTxns, concatUint8Arrays, doesBoxExist, generateCidFromProposalMetadata, getAllBoxNames, getBias, getCumulativePowerDelta, getGlobalState, getRawBoxValue };
export { calculateTinyPower, combineAndRegroupTxns, doesBoxExist, generateCidFromProposalMetadata, getAllBoxNames, getBias, getCumulativePowerDelta, getGlobalState, getRawBoxValue };
46 changes: 23 additions & 23 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
import SwapQuoteError from "./util/error/SwapQuoteError";
export type { InitiatorSigner, SignerTransaction, SupportedNetwork } from "./util/commonTypes";
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";
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";
export * from "./swap/v2/router";
export * from "./swap/common/utils";
export { applySlippageToAmount, ASSET_OPT_IN_PROCESS_TXN_COUNT, convertFromBaseUnits, convertToBaseUnits, sendAndWaitRawTransaction, getTxnGroupID, sumUpTxnFees } from "./util/util";
export { applySlippageToAmount, ASSET_OPT_IN_PROCESS_TXN_COUNT, convertFromBaseUnits, convertToBaseUnits, getTxnGroupID, sendAndWaitRawTransaction, sumUpTxnFees } from "./util/util";
export { generateOptIntoAssetTxns } from "./util/asset/assetUtils";
export type { AccountAsset, TinymanAnalyticsApiAsset, IndexerAssetInformation, AssetWithIdAndAmount } from "./util/asset/assetModels";
export type { AccountAsset, AssetWithIdAndAmount, IndexerAssetInformation, TinymanAnalyticsApiAsset } from "./util/asset/assetModels";
export { ALGO_ASSET, ALGO_ASSET_ID, POOL_TOKEN_UNIT_NAME } from "./util/asset/assetConstants";
export { getAccountInformation, calculateAccountMinimumRequiredBalance, hasSufficientMinimumBalance, isAccountOptedIntoApp, getAccountExcessWithinPool, getAccountExcess, getMinRequiredBalanceToOptIn } from "./util/account/accountUtils";
export { calculateAccountMinimumRequiredBalance, getAccountExcess, getAccountExcessWithinPool, getAccountInformation, getMinRequiredBalanceToOptIn, hasSufficientMinimumBalance, isAccountOptedIntoApp } from "./util/account/accountUtils";
export type { AccountInformationData } from "./util/account/accountTypes";
export type { ContractVersionValue } from "./contract/types";
export { CONTRACT_VERSION } from "./contract/constants";
export { tinymanContract_v2 } from "./contract/v2/contract";
export type { ContractVersionValue } from "./contract/types";
export { tinymanContract_v1_1 } from "./contract/v1_1/contract";
export { getValidatorAppID, generateOptIntoValidatorTxns, OPT_IN_VALIDATOR_APP_PROCESS_TXN_COUNT, generateOptOutOfValidatorTxns, OPT_OUT_VALIDATOR_APP_PROCESS_TXN_COUNT } from "./validator";
export type { V1PoolInfo, V2PoolInfo, PoolReserves } from "./util/pool/poolTypes";
export { tinymanContract_v2 } from "./contract/v2/contract";
export { generateOptIntoValidatorTxns, generateOptOutOfValidatorTxns, getValidatorAppID, OPT_IN_VALIDATOR_APP_PROCESS_TXN_COUNT, OPT_OUT_VALIDATOR_APP_PROCESS_TXN_COUNT } from "./validator";
export type { PoolReserves, V1PoolInfo, V2PoolInfo } from "./util/pool/poolTypes";
export { PoolStatus } from "./util/pool/poolTypes";
export { poolUtils } from "./util/pool";
export { Bootstrap } from "./bootstrap";
export type { V1_1AddLiquidityQuote, V1_1AddLiquidityExecution } from "./add-liquidity/v1_1/types";
export { V1_1AddLiquidityTxnIndices, V1_1_ADD_LIQUIDITY_PROCESS_TXN_COUNT } from "./add-liquidity/v1_1/constants";
export type { V2InitialAddLiquidityQuote, V2AddLiquidityInternalSwapQuote, V2FlexibleAddLiquidityQuote, V2SingleAssetInAddLiquidityQuote, V2AddLiquidityExecution } from "./add-liquidity/v2/types";
export { V2AddLiquidityType, V2AddLiquidityTxnIndices } from "./add-liquidity/v2/constants";
export { getAddLiquidityTotalFee } from "./add-liquidity/util";
export { AddLiquidity } from "./add-liquidity";
export { getAddLiquidityTotalFee } from "./add-liquidity/util";
export { V1_1_ADD_LIQUIDITY_PROCESS_TXN_COUNT, V1_1AddLiquidityTxnIndices } from "./add-liquidity/v1_1/constants";
export type { V1_1AddLiquidityExecution, V1_1AddLiquidityQuote } from "./add-liquidity/v1_1/types";
export { V2AddLiquidityTxnIndices, V2AddLiquidityType } from "./add-liquidity/v2/constants";
export type { V2AddLiquidityExecution, V2AddLiquidityInternalSwapQuote, V2FlexibleAddLiquidityQuote, V2InitialAddLiquidityQuote, V2SingleAssetInAddLiquidityQuote } from "./add-liquidity/v2/types";
export type { V1_1RemoveLiquidityExecution, V1_1RemoveLiquidityQuote } from "./remove-liquidity/v1_1/types";
export type { V2RemoveLiquidityQuote, V2SingleAssetRemoveLiquidityQuote, V2RemoveLiquidityExecution } from "./remove-liquidity/v2/types";
export type { V2RemoveLiquidityExecution, V2RemoveLiquidityQuote, V2SingleAssetRemoveLiquidityQuote } from "./remove-liquidity/v2/types";
export { RemoveLiquidity } from "./remove-liquidity";
export { V1_1_REMOVE_LIQUIDITY_TXN_COUNT } from "./remove-liquidity/v1_1/constants";
export { V2_REMOVE_LIQUIDITY_APP_CALL_INNER_TXN_COUNT } from "./remove-liquidity/v2/constants";
export { RemoveLiquidity } from "./remove-liquidity";
export type { SwapQuote, V1SwapExecution, V2SwapExecution, DirectSwapQuote, SwapRoute, GenerateSwapTxnsParams } from "./swap/types";
export * from "./swap/v2/util";
export { SwapType } from "./swap/constants";
export { Swap } from "./swap";
export { SwapType } from "./swap/constants";
export type { DirectSwapQuote, GenerateSwapTxnsParams, SwapQuote, SwapRouterResponse, V1SwapExecution, V2SwapExecution } from "./swap/types";
export * from "./swap/v2/util";
export { SwapQuoteType } from "./swap/types";
export { SwapQuoteError };
export { SwapQuoteErrorType } from "./util/error/SwapQuoteError";
export { redeemExcessAsset, redeemAllExcessAsset, generateRedeemTxns, REDEEM_PROCESS_TXN_COUNT } from "./redeem";
export { generateRedeemTxns, REDEEM_PROCESS_TXN_COUNT, redeemAllExcessAsset, redeemExcessAsset } from "./redeem";
export { fetchFolksLendingPool, LendingPool } from "./folks-lending-pools";
export type { FolksLendingPool } from "./folks-lending-pools/types";
export { prepareCommitTransactions, getStakingAppID } from "./stake";
export { tinymanJSSDKConfig } from "./config";
export { getStakingAppID, prepareCommitTransactions } from "./stake";
export { combineAndRegroupSignerTxns, getAppCallInnerAssetData } from "./util/transaction/transactionUtils";
export { TinymanGovernanceClient } from "./governance";
export type { RawBoxCacheValue } from "./governance/types";
export { TinymanSTAlgoClient } from "./liquid-stake/stAlgoClient";
export { TinymanTAlgoClient } from "./liquid-stake/tAlgoClient";
export { AccountState } from "./governance/vault/storage";
export { getStartTimestampOfWeek } from "./governance/vault/utils";
export { ProposalVote } from "./governance/proposal-voting/constants";
export { generateProposalMetadata } from "./governance/proposal-voting/transactions";
export type { GenerateProposalMetadataPayload } from "./governance/proposal-voting/types";
export { intToBytes } from "./governance/util/utils";
export { generateCidFromProposalMetadata, calculateTinyPower, combineAndRegroupTxns, concatUint8Arrays } from "./governance/utils";
export { AccountState } from "./governance/vault/storage";
export { getStartTimestampOfWeek } from "./governance/vault/utils";
export { calculateTinyPower, combineAndRegroupTxns, generateCidFromProposalMetadata } from "./governance/utils";
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/stake.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ declare function prepareCommitTransactions({ client, stakingAppID, program, requ
requiredAssetID?: number;
}): Promise<SignerTransaction[]>;
declare function getStakingAppID(network: SupportedNetwork): 51948952 | 649588853;
export { prepareCommitTransactions, getStakingAppID };
export { getStakingAppID, prepareCommitTransactions };
2 changes: 1 addition & 1 deletion dist/swap/common/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ declare function getSwapQuoteRate(quote: SwapQuote): number;
*/
declare function getBestQuote(quotes: SwapQuote[]): SwapQuote;
declare function isSwapQuoteErrorCausedByAmount(error: Error): boolean;
export { calculateSwapRate, calculatePriceImpact, getSwapQuotePriceImpact, getAssetInFromSwapQuote, getAssetOutFromSwapQuote, getAssetInAndAssetOutFromSwapQuote, getSwapQuoteContractVersion, getSwapTotalFee, getSwapQuoteRate, getBestQuote, isSwapQuoteErrorCausedByAmount };
export { calculatePriceImpact, calculateSwapRate, getAssetInAndAssetOutFromSwapQuote, getAssetInFromSwapQuote, getAssetOutFromSwapQuote, getBestQuote, getSwapQuoteContractVersion, getSwapQuotePriceImpact, getSwapQuoteRate, getSwapTotalFee, isSwapQuoteErrorCausedByAmount };
9 changes: 6 additions & 3 deletions dist/swap/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,23 @@ export declare const Swap: {
}) => Promise<Omit<import("./types").V1SwapExecution, "fees" | "groupID">>;
};
v2: {
getQuote: ({ type, amount, assetIn, assetOut, network, isSwapRouterEnabled, pool }: {
getQuote: ({ type, amount, assetIn, assetOut, network, slippage, isSwapRouterEnabled, 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, pool }: {
getFixedInputSwapQuote: ({ amount, assetIn, assetOut, isSwapRouterEnabled, 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 }: {
Expand All @@ -76,12 +78,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, pool }: {
getFixedOutputSwapQuote: ({ amount, assetIn, assetOut, isSwapRouterEnabled, 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[]>;
Expand Down
55 changes: 29 additions & 26 deletions dist/swap/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Algodv2 } from "algosdk";
import { Algodv2, TransactionType } from "algosdk";
import { AssetWithIdAndAmount, TinymanAnalyticsApiAsset } from "../util/asset/assetModels";
import { SignerTransaction, SupportedNetwork } from "../util/commonTypes";
import { PoolReserves, V1PoolInfo, V2PoolInfo } from "../util/pool/poolTypes";
Expand Down Expand Up @@ -41,41 +41,42 @@ export interface SwapRoutePool {
asset_2: SwapRouteAsset;
version: "2.0";
}
export type SwapRoute = {
quote: SwapRouterQuote;
pool: SwapRoutePool;
}[];
export interface SwapRouterQuote {
swap_type: SwapType;
amount_in: {
asset: SwapRouteAsset;
amount: string;
};
amount_out: {
asset: SwapRouteAsset;
amount: string;
};
swap_fees: {
amount: string;
asset: SwapRouteAsset;
};
price: number;
price_impact: number;
}
export interface FetchSwapRouteQuotesPayload {
asset_in_id: string;
asset_out_id: string;
amount: string;
input_amount?: string;
output_amount?: string;
swap_type: SwapType;
slippage: number;
}
export type SwapRouterResponse = FetchSwapRouteQuotesPayload & {
route: SwapRoute;
price_impact: string;
export type SwapRouterResponse = Pick<FetchSwapRouteQuotesPayload, "swap_type"> & {
asset_in: Pick<TinymanAnalyticsApiAsset, "id" | "decimals" | "name" | "unit_name">;
asset_out: Pick<TinymanAnalyticsApiAsset, "id" | "decimals" | "name" | "unit_name">;
price_impact: string | null;
status: {
round_number: string;
round_datetime: string;
};
transaction_count: number | null;
transactions: SwapRouterTransactionRecipe[] | null;
transaction_fee: string | null;
swap_fee: string | null;
input_amount: string | null;
output_amount: string | null;
asset_ids: number[] | null;
pool_ids: string[] | null;
};
export interface SwapRouterTransactionRecipe {
type: TransactionType;
receiver?: string;
app_id: number;
asset_id: number;
amount: number;
args: string[] | null;
accounts?: string[];
assets?: number[];
apps?: number[];
}
export type GetSwapQuoteParams = {
assetIn: Pick<TinymanAnalyticsApiAsset, "id" | "decimals">;
assetOut: Pick<TinymanAnalyticsApiAsset, "id" | "decimals">;
Expand All @@ -88,6 +89,8 @@ export type GetSwapQuoteParams = {
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;
};
export type SwapQuote = {
data: DirectSwapQuoteAndPool;
Expand Down
14 changes: 14 additions & 0 deletions dist/swap/v1_1/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ import { PoolReserves, V1PoolInfo } from "../../util/pool/poolTypes";
import { GenerateV1_1SwapTxnsParams, SwapQuote, V1SwapExecution } from "../types";
import { SwapType } from "../constants";
import { AssetWithIdAndAmount } from "../../util/asset/assetModels";
/**
* @deprecated Use `generateTxns` in V2 instead. This will be removed soon.
*/
declare function signTxns({ pool, txGroup, initiatorSigner }: {
pool: V1PoolInfo;
txGroup: SignerTransaction[];
initiatorSigner: InitiatorSigner;
}): Promise<Uint8Array[]>;
/**
* @deprecated Use `generateTxns` in V2 instead. This will be removed soon.
*/
declare function generateTxns({ client, quoteAndPool, swapType, slippage, initiatorAddr }: GenerateV1_1SwapTxnsParams): Promise<SignerTransaction[]>;
/**
* @deprecated Use `getQuote` in V2 instead. This will be removed soon.
*
* @param type - Type of the swap
* @param pool - Information for the pool.
Expand All @@ -26,6 +33,8 @@ declare function getQuote(type: SwapType, pool: V1PoolInfo, reserves: PoolReserv
assetOut: number;
}): SwapQuote;
/**
* @deprecated Use `getFixedInputSwapQuote` in V2 instead. This will be removed soon.
*
* Get a quote for a fixed input swap This does not execute any transactions.
*
* @param params.pool Information for the pool.
Expand All @@ -44,6 +53,8 @@ declare function getFixedInputSwapQuote({ pool, reserves, assetIn, decimals }: {
};
}): SwapQuote;
/**
* @deprecated Use `getFixedOutputSwapQuote` in V2 instead. This will be removed soon.
*
* Get a quote for a fixed output swap This does not execute any transactions.
*
* @param params.pool Information for the pool.
Expand All @@ -62,6 +73,7 @@ declare function getFixedOutputSwapQuote({ pool, reserves, assetOut, decimals }:
};
}): SwapQuote;
/**
* @deprecated
* Execute a fixed output swap with the desired quantities.
*
* @param params.client An Algodv2 client.
Expand All @@ -87,6 +99,8 @@ declare function executeFixedOutputSwap({ client, pool, signedTxns, assetIn, ass
initiatorAddr: string;
}): Promise<Omit<V1SwapExecution, "fees" | "groupID">>;
/**
* @deprecated Use `execute` in V2 instead. This will be removed soon.
*
* Execute a swap with the desired quantities.
*
* @param params.client An Algodv2 client.
Expand Down
Loading

0 comments on commit cfec8cf

Please sign in to comment.