@pancakeswap/stable-swap-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/dist/amm/amm.d.ts +24 -0
- package/dist/amm/amm.d.ts.map +1 -0
- package/dist/amm/getLPOutput.d.ts +10 -0
- package/dist/amm/getLPOutput.d.ts.map +1 -0
- package/dist/amm/getLPOutputWithoutFee.d.ts +4 -0
- package/dist/amm/getLPOutputWithoutFee.d.ts.map +1 -0
- package/dist/amm/getSwapOutput.d.ts +15 -0
- package/dist/amm/getSwapOutput.d.ts.map +1 -0
- package/dist/amm/index.d.ts +6 -0
- package/dist/amm/index.d.ts.map +1 -0
- package/dist/amm/utils.d.ts +4 -0
- package/dist/amm/utils.d.ts.map +1 -0
- package/dist/constants/index.d.ts +4 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/pools/arb.d.ts +3 -0
- package/dist/constants/pools/arb.d.ts.map +1 -0
- package/dist/constants/pools/bsc.d.ts +3 -0
- package/dist/constants/pools/bsc.d.ts.map +1 -0
- package/dist/constants/pools/bscTestnet.d.ts +3 -0
- package/dist/constants/pools/bscTestnet.d.ts.map +1 -0
- package/dist/constants/pools/index.d.ts +6 -0
- package/dist/constants/pools/index.d.ts.map +1 -0
- package/dist/constants/pools/pools.d.ts +14 -0
- package/dist/constants/pools/pools.d.ts.map +1 -0
- package/dist/index.cjs +468 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +450 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BigintIsh } from '@pancakeswap/swap-sdk-core';
|
|
2
|
+
interface Params {
|
|
3
|
+
amplifier: BigintIsh;
|
|
4
|
+
balances: BigintIsh[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Calculate the constant D of Curve AMM formula
|
|
8
|
+
* @see https://classic.curve.fi/files/stableswap-paper.pdf
|
|
9
|
+
*/
|
|
10
|
+
export declare function getD({ amplifier, balances }: Params): bigint;
|
|
11
|
+
interface GetYParams {
|
|
12
|
+
amplifier: BigintIsh;
|
|
13
|
+
balances: BigintIsh[];
|
|
14
|
+
i: number;
|
|
15
|
+
j: number;
|
|
16
|
+
x: BigintIsh;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Calculate the expected token amount y after user deposit
|
|
20
|
+
* @see https://classic.curve.fi/files/stableswap-paper.pdf
|
|
21
|
+
*/
|
|
22
|
+
export declare function getY({ amplifier, balances, i, j, x }: GetYParams): bigint;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=amm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amm.d.ts","sourceRoot":"","sources":["../../src/amm/amm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAa,MAAM,4BAA4B,CAAA;AAGjE,UAAU,MAAM;IACd,SAAS,EAAE,SAAS,CAAA;IACpB,QAAQ,EAAE,SAAS,EAAE,CAAA;CACtB;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,MAAM,GAAG,MAAM,CAkC5D;AAED,UAAU,UAAU;IAClB,SAAS,EAAE,SAAS,CAAA;IACpB,QAAQ,EAAE,SAAS,EAAE,CAAA;IAErB,CAAC,EAAE,MAAM,CAAA;IAET,CAAC,EAAE,MAAM,CAAA;IAET,CAAC,EAAE,SAAS,CAAA;CACb;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,UAAU,GAAG,MAAM,CA+CzE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BigintIsh, CurrencyAmount, Currency, Percent } from '@pancakeswap/swap-sdk-core';
|
|
2
|
+
export interface GetLPOutputParams {
|
|
3
|
+
amplifier: BigintIsh;
|
|
4
|
+
balances: CurrencyAmount<Currency>[];
|
|
5
|
+
amounts: CurrencyAmount<Currency>[];
|
|
6
|
+
totalSupply: CurrencyAmount<Currency>;
|
|
7
|
+
fee: Percent;
|
|
8
|
+
}
|
|
9
|
+
export declare function getLPOutput({ amplifier, balances, totalSupply, amounts, fee, }: GetLPOutputParams): CurrencyAmount<Currency>;
|
|
10
|
+
//# sourceMappingURL=getLPOutput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLPOutput.d.ts","sourceRoot":"","sources":["../../src/amm/getLPOutput.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,QAAQ,EAAQ,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAM/F,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,SAAS,CAAA;IAEpB,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC,EAAE,CAAA;IAEpC,OAAO,EAAE,cAAc,CAAC,QAAQ,CAAC,EAAE,CAAA;IAEnC,WAAW,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAA;IAErC,GAAG,EAAE,OAAO,CAAA;CACb;AAED,wBAAgB,WAAW,CAAC,EAC1B,SAAS,EACT,QAAQ,EACR,WAAW,EACX,OAAO,EACP,GAAG,GACJ,EAAE,iBAAiB,GAAG,cAAc,CAAC,QAAQ,CAAC,CAoD9C"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CurrencyAmount, Currency } from '@pancakeswap/swap-sdk-core';
|
|
2
|
+
import { GetLPOutputParams } from './getLPOutput';
|
|
3
|
+
export declare function getLPOutputWithoutFee(params: Omit<GetLPOutputParams, 'fee'>): CurrencyAmount<Currency>;
|
|
4
|
+
//# sourceMappingURL=getLPOutputWithoutFee.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLPOutputWithoutFee.d.ts","sourceRoot":"","sources":["../../src/amm/getLPOutputWithoutFee.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAW,MAAM,4BAA4B,CAAA;AAE9E,OAAO,EAAe,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAE9D,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,IAAI,CAAC,iBAAiB,EAAE,KAAK,CAAC,GAAG,cAAc,CAAC,QAAQ,CAAC,CAEtG"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BigintIsh, CurrencyAmount, Currency, Percent } from '@pancakeswap/swap-sdk-core';
|
|
2
|
+
export interface GetSwapOutputParams {
|
|
3
|
+
amplifier: BigintIsh;
|
|
4
|
+
balances: CurrencyAmount<Currency>[];
|
|
5
|
+
amount: CurrencyAmount<Currency>;
|
|
6
|
+
outputCurrency: Currency;
|
|
7
|
+
fee: Percent;
|
|
8
|
+
}
|
|
9
|
+
export declare function getSwapOutput({ amplifier, balances: balanceAmounts, outputCurrency, amount, fee, }: GetSwapOutputParams): CurrencyAmount<Currency>;
|
|
10
|
+
export declare function getSwapOutputWithoutFee(params: Omit<GetSwapOutputParams, 'fee'>): CurrencyAmount<Currency>;
|
|
11
|
+
export declare function getSwapInput({ amount, ...rest }: GetSwapOutputParams): CurrencyAmount<Currency>;
|
|
12
|
+
export declare function getSwapInputWithtouFee(params: Omit<GetSwapOutputParams, 'fee'>): CurrencyAmount<Currency>;
|
|
13
|
+
export declare const getQuoteExactIn: (params: GetSwapOutputParams) => [CurrencyAmount<Currency>, Pick<GetSwapOutputParams, 'balances' | 'fee' | 'amplifier'>];
|
|
14
|
+
export declare const getQuoteExactOut: (params: GetSwapOutputParams) => [CurrencyAmount<Currency>, Pick<GetSwapOutputParams, 'balances' | 'fee' | 'amplifier'>];
|
|
15
|
+
//# sourceMappingURL=getSwapOutput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSwapOutput.d.ts","sourceRoot":"","sources":["../../src/amm/getSwapOutput.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,QAAQ,EAAE,OAAO,EAAQ,MAAM,4BAA4B,CAAA;AAO/F,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,SAAS,CAAA;IAEpB,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC,EAAE,CAAA;IAEpC,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAA;IAEhC,cAAc,EAAE,QAAQ,CAAA;IAExB,GAAG,EAAE,OAAO,CAAA;CACb;AAED,wBAAgB,aAAa,CAAC,EAC5B,SAAS,EACT,QAAQ,EAAE,cAAc,EACxB,cAAc,EACd,MAAM,EACN,GAAG,GACJ,EAAE,mBAAmB,GAAG,cAAc,CAAC,QAAQ,CAAC,CA0ChD;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,IAAI,CAAC,mBAAmB,EAAE,KAAK,CAAC,GAAG,cAAc,CAAC,QAAQ,CAAC,CAE1G;AAED,wBAAgB,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,EAAE,mBAAmB,4BAKpE;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,IAAI,CAAC,mBAAmB,EAAE,KAAK,CAAC,4BAE9E;AAmCD,eAAO,MAAM,eAAe,WAfhB,mBAAmB,KAC1B,CAAC,eAAe,QAAQ,CAAC,EAAE,KAAK,mBAAmB,EAAE,UAAU,GAAG,KAAK,GAAG,WAAW,CAAC,CAcrC,CAAA;AAEtD,eAAO,MAAM,gBAAgB,WAjBjB,mBAAmB,KAC1B,CAAC,eAAe,QAAQ,CAAC,EAAE,KAAK,mBAAmB,EAAE,UAAU,GAAG,KAAK,GAAG,WAAW,CAAC,CAgBnC,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { getLPOutputWithoutFee } from './getLPOutputWithoutFee';
|
|
2
|
+
import { getLPOutput } from './getLPOutput';
|
|
3
|
+
import { getSwapOutput, getSwapOutputWithoutFee, getSwapInput, getSwapInputWithtouFee, getQuoteExactIn, getQuoteExactOut } from './getSwapOutput';
|
|
4
|
+
import { getD } from './amm';
|
|
5
|
+
export { getQuoteExactIn, getQuoteExactOut, getSwapInput, getSwapInputWithtouFee, getSwapOutput, getSwapOutputWithoutFee, getLPOutputWithoutFee, getLPOutput, getD, };
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/amm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EACL,aAAa,EACb,uBAAuB,EACvB,YAAY,EACZ,sBAAsB,EACtB,eAAe,EACf,gBAAgB,EACjB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAE5B,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,sBAAsB,EACtB,aAAa,EACb,uBAAuB,EACvB,qBAAqB,EACrB,WAAW,EACX,IAAI,GACL,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CurrencyAmount, Currency } from '@pancakeswap/swap-sdk-core';
|
|
2
|
+
export declare const getRawAmount: (amount: CurrencyAmount<Currency>) => bigint;
|
|
3
|
+
export declare const parseAmount: (currency: Currency, rawAmount: bigint) => CurrencyAmount<Currency>;
|
|
4
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/amm/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAIrE,eAAO,MAAM,YAAY,WAAY,eAAe,QAAQ,CAAC,WAE5D,CAAA;AAED,eAAO,MAAM,WAAW,aAAc,QAAQ,aAAa,MAAM,6BAEhE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,cAAc,SAAS,CAAA;AAEvB,eAAO,MAAM,mBAAmB,SAAmB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arb.d.ts","sourceRoot":"","sources":["../../../src/constants/pools/arb.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE5C,eAAO,MAAM,KAAK,EAAE,cAAc,EAqBjC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bsc.d.ts","sourceRoot":"","sources":["../../../src/constants/pools/bsc.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE5C,eAAO,MAAM,KAAK,EAAE,cAAc,EAyHjC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bscTestnet.d.ts","sourceRoot":"","sources":["../../../src/constants/pools/bscTestnet.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAI5C,eAAO,MAAM,KAAK,EAAE,cAAc,EAiDjC,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ChainId } from '@pancakeswap/chains';
|
|
2
|
+
import { isStableSwapSupported, STABLE_SUPPORTED_CHAIN_IDS } from './pools';
|
|
3
|
+
import { StableSwapPool } from '../../types';
|
|
4
|
+
export declare function getStableSwapPools(chainId: ChainId): StableSwapPool[];
|
|
5
|
+
export { isStableSwapSupported, STABLE_SUPPORTED_CHAIN_IDS };
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/constants/pools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAE7C,OAAO,EAAE,qBAAqB,EAAmB,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAC5F,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE5C,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,cAAc,EAAE,CAMrE;AAED,OAAO,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ChainId } from '@pancakeswap/chains';
|
|
2
|
+
import { StableSwapPool } from '../../types';
|
|
3
|
+
export type StableSwapPoolMap<TChainId extends number> = {
|
|
4
|
+
[chainId in TChainId]: StableSwapPool[];
|
|
5
|
+
};
|
|
6
|
+
export declare const isStableSwapSupported: (chainId: number | undefined) => chainId is ChainId.BSC | ChainId.BSC_TESTNET | ChainId.ARBITRUM_ONE;
|
|
7
|
+
export declare const STABLE_SUPPORTED_CHAIN_IDS: readonly [ChainId.BSC, ChainId.BSC_TESTNET, ChainId.ARBITRUM_ONE];
|
|
8
|
+
export type StableSupportedChainId = (typeof STABLE_SUPPORTED_CHAIN_IDS)[number];
|
|
9
|
+
export declare const STABLE_POOL_MAP: {
|
|
10
|
+
56: StableSwapPool[];
|
|
11
|
+
97: StableSwapPool[];
|
|
12
|
+
42161: StableSwapPool[];
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=pools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pools.d.ts","sourceRoot":"","sources":["../../../src/constants/pools/pools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAE7C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAK5C,MAAM,MAAM,iBAAiB,CAAC,QAAQ,SAAS,MAAM,IAAI;KACtD,OAAO,IAAI,QAAQ,GAAG,cAAc,EAAE;CACxC,CAAA;AAED,eAAO,MAAM,qBAAqB,YAAa,MAAM,GAAG,SAAS,wEAKhE,CAAA;AAED,eAAO,MAAM,0BAA0B,mEAAoE,CAAA;AAE3G,MAAM,MAAM,sBAAsB,GAAG,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAA;AAEhF,eAAO,MAAM,eAAe;;;;CAIyB,CAAA"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var swapSdkCore = require('@pancakeswap/swap-sdk-core');
|
|
4
|
+
var invariant = require('tiny-invariant');
|
|
5
|
+
var chains = require('@pancakeswap/chains');
|
|
6
|
+
var tokens = require('@pancakeswap/tokens');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var invariant__default = /*#__PURE__*/_interopDefault(invariant);
|
|
11
|
+
|
|
12
|
+
// src/amm/getLPOutputWithoutFee.ts
|
|
13
|
+
function getD({ amplifier, balances }) {
|
|
14
|
+
const numOfCoins = balances.length;
|
|
15
|
+
invariant__default.default(numOfCoins > 1, "To get constant D, pool should have at least two coins.");
|
|
16
|
+
const sum = balances.reduce((s, cur) => s + BigInt(cur), swapSdkCore.ZERO);
|
|
17
|
+
if (sum === swapSdkCore.ZERO) {
|
|
18
|
+
return swapSdkCore.ZERO;
|
|
19
|
+
}
|
|
20
|
+
const n = BigInt(numOfCoins);
|
|
21
|
+
const precision = swapSdkCore.ONE;
|
|
22
|
+
const ann = BigInt(amplifier) * n;
|
|
23
|
+
let dPrev = swapSdkCore.ZERO;
|
|
24
|
+
let d = sum;
|
|
25
|
+
for (let i = 0; i < 255; i += 1) {
|
|
26
|
+
let dp = d;
|
|
27
|
+
for (const b of balances) {
|
|
28
|
+
dp = dp * d / (BigInt(b) * n + 1n);
|
|
29
|
+
}
|
|
30
|
+
dPrev = d;
|
|
31
|
+
d = (ann * sum + dp * n) * d / ((ann - swapSdkCore.ONE) * d + (n + swapSdkCore.ONE) * dp);
|
|
32
|
+
if (d > dPrev && d - dPrev <= precision) {
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
if (d <= dPrev && dPrev - d <= precision) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return d;
|
|
40
|
+
}
|
|
41
|
+
function getY({ amplifier, balances, i, j, x }) {
|
|
42
|
+
const numOfCoins = balances.length;
|
|
43
|
+
invariant__default.default(numOfCoins > 1, "To get y, pool should have at least two coins.");
|
|
44
|
+
invariant__default.default(i !== j && i >= 0 && j >= 0 && i < numOfCoins && j < numOfCoins, `Invalid i: ${i} and j: ${j}`);
|
|
45
|
+
const n = BigInt(numOfCoins);
|
|
46
|
+
const d = getD({ amplifier, balances });
|
|
47
|
+
let sum = swapSdkCore.ZERO;
|
|
48
|
+
let c = d;
|
|
49
|
+
const ann = BigInt(amplifier) * n;
|
|
50
|
+
for (const [index, b2] of balances.entries()) {
|
|
51
|
+
if (index === j) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
let balanceAfterDeposit = BigInt(b2);
|
|
55
|
+
if (index === i) {
|
|
56
|
+
balanceAfterDeposit += BigInt(x);
|
|
57
|
+
}
|
|
58
|
+
invariant__default.default(balanceAfterDeposit > swapSdkCore.ZERO, "Insufficient liquidity");
|
|
59
|
+
sum += balanceAfterDeposit;
|
|
60
|
+
c = c * d / (balanceAfterDeposit * n);
|
|
61
|
+
}
|
|
62
|
+
c = c * d / (ann * n);
|
|
63
|
+
const b = sum + d / ann;
|
|
64
|
+
const precision = swapSdkCore.ONE;
|
|
65
|
+
let yPrev = swapSdkCore.ZERO;
|
|
66
|
+
let y = d;
|
|
67
|
+
for (let k = 0; k < 255; k += 1) {
|
|
68
|
+
yPrev = y;
|
|
69
|
+
y = (y * y + c) / (2n * y + b - d);
|
|
70
|
+
if (y > yPrev && y - yPrev <= precision) {
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
if (y <= yPrev && yPrev - y <= precision) {
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return y;
|
|
78
|
+
}
|
|
79
|
+
var PRECISION = 10n ** 18n;
|
|
80
|
+
var getRawAmount = (amount) => {
|
|
81
|
+
return amount.quotient * PRECISION / 10n ** BigInt(amount.currency.decimals);
|
|
82
|
+
};
|
|
83
|
+
var parseAmount = (currency, rawAmount) => {
|
|
84
|
+
return swapSdkCore.CurrencyAmount.fromRawAmount(currency, rawAmount * 10n ** BigInt(currency.decimals) / PRECISION);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// src/amm/getLPOutput.ts
|
|
88
|
+
function getLPOutput({
|
|
89
|
+
amplifier,
|
|
90
|
+
balances,
|
|
91
|
+
totalSupply,
|
|
92
|
+
amounts,
|
|
93
|
+
fee
|
|
94
|
+
}) {
|
|
95
|
+
const lpToken = totalSupply.currency;
|
|
96
|
+
const lpTotalSupply = totalSupply.quotient;
|
|
97
|
+
if (lpTotalSupply === swapSdkCore.ZERO || !balances.length || balances.every((b) => b.quotient === swapSdkCore.ZERO)) {
|
|
98
|
+
const d = getD({ amplifier, balances: amounts.map(getRawAmount) });
|
|
99
|
+
return swapSdkCore.CurrencyAmount.fromRawAmount(lpToken, d);
|
|
100
|
+
}
|
|
101
|
+
const currentBalances = [];
|
|
102
|
+
const newBalances = [];
|
|
103
|
+
for (const [i, balance] of balances.entries()) {
|
|
104
|
+
const amount = amounts[i] || swapSdkCore.CurrencyAmount.fromRawAmount(balance.currency, 0);
|
|
105
|
+
invariant__default.default(
|
|
106
|
+
amount.currency.wrapped.equals(balance.currency.wrapped),
|
|
107
|
+
"User input currency should be the same as pool balance currency."
|
|
108
|
+
);
|
|
109
|
+
const balanceRaw = getRawAmount(balance);
|
|
110
|
+
const amountRaw = getRawAmount(amount);
|
|
111
|
+
currentBalances.push(balanceRaw);
|
|
112
|
+
newBalances.push(balanceRaw + amountRaw);
|
|
113
|
+
}
|
|
114
|
+
const d0 = getD({ amplifier, balances: currentBalances });
|
|
115
|
+
const d1 = getD({ amplifier, balances: newBalances });
|
|
116
|
+
invariant__default.default(d1 >= d0, "D1 should be greater than or equal than d0.");
|
|
117
|
+
const isFirstSupply = lpTotalSupply <= swapSdkCore.ZERO;
|
|
118
|
+
if (isFirstSupply) {
|
|
119
|
+
return swapSdkCore.CurrencyAmount.fromRawAmount(totalSupply.currency, d1);
|
|
120
|
+
}
|
|
121
|
+
const n = currentBalances.length;
|
|
122
|
+
const eachTokenFee = fee.multiply(n).divide(4 * (n - 1));
|
|
123
|
+
let d2 = d1;
|
|
124
|
+
for (const [i, b] of currentBalances.entries()) {
|
|
125
|
+
const idealBalance = d1 * b / d0;
|
|
126
|
+
let diff = swapSdkCore.ZERO;
|
|
127
|
+
if (idealBalance > newBalances[i]) {
|
|
128
|
+
diff = idealBalance - newBalances[i];
|
|
129
|
+
} else {
|
|
130
|
+
diff = newBalances[i] - idealBalance;
|
|
131
|
+
}
|
|
132
|
+
const feeAmount = eachTokenFee.multiply(diff).quotient;
|
|
133
|
+
newBalances[i] = newBalances[i] - feeAmount;
|
|
134
|
+
}
|
|
135
|
+
d2 = getD({ amplifier, balances: newBalances });
|
|
136
|
+
const expectedMintLP = lpTotalSupply * (d2 - d0) / d0;
|
|
137
|
+
return swapSdkCore.CurrencyAmount.fromRawAmount(totalSupply.currency, expectedMintLP);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// src/amm/getLPOutputWithoutFee.ts
|
|
141
|
+
function getLPOutputWithoutFee(params) {
|
|
142
|
+
return getLPOutput({ ...params, fee: new swapSdkCore.Percent(0) });
|
|
143
|
+
}
|
|
144
|
+
var pools = [
|
|
145
|
+
{
|
|
146
|
+
lpSymbol: "lisUSD-BUSD LP",
|
|
147
|
+
lpAddress: "0xB6040A9F294477dDAdf5543a24E5463B8F2423Ae",
|
|
148
|
+
token: tokens.bscTokens.hay,
|
|
149
|
+
quoteToken: tokens.bscTokens.busd,
|
|
150
|
+
stableSwapAddress: "0x49079D07ef47449aF808A4f36c2a8dEC975594eC",
|
|
151
|
+
infoStableSwapAddress: "0xa680d27f63Fa5E213C502d1B3Ca1EB6a3C1b31D6",
|
|
152
|
+
stableLpFee: 2e-4,
|
|
153
|
+
stableLpFeeRateOfTotalFee: 0.5
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
lpSymbol: "USDT-BUSD LP",
|
|
157
|
+
lpAddress: "0x36842F8fb99D55477C0Da638aF5ceb6bBf86aA98",
|
|
158
|
+
token: tokens.bscTokens.usdt,
|
|
159
|
+
quoteToken: tokens.bscTokens.busd,
|
|
160
|
+
stableSwapAddress: "0x169F653A54ACD441aB34B73dA9946e2C451787EF",
|
|
161
|
+
infoStableSwapAddress: "0xa680d27f63Fa5E213C502d1B3Ca1EB6a3C1b31D6",
|
|
162
|
+
stableLpFee: 5e-5,
|
|
163
|
+
stableLpFeeRateOfTotalFee: 0.5
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
lpSymbol: "USDC-BUSD LP",
|
|
167
|
+
lpAddress: "0x1A77C359D0019cD8F4d36b7CDf5a88043D801072",
|
|
168
|
+
token: tokens.bscTokens.usdc,
|
|
169
|
+
quoteToken: tokens.bscTokens.busd,
|
|
170
|
+
stableSwapAddress: "0xc2F5B9a3d9138ab2B74d581fC11346219eBf43Fe",
|
|
171
|
+
infoStableSwapAddress: "0xa680d27f63Fa5E213C502d1B3Ca1EB6a3C1b31D6",
|
|
172
|
+
stableLpFee: 5e-5,
|
|
173
|
+
stableLpFeeRateOfTotalFee: 0.5
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
lpSymbol: "USDT-USDC LP",
|
|
177
|
+
lpAddress: "0xee1bcc9F1692E81A281b3a302a4b67890BA4be76",
|
|
178
|
+
token: tokens.bscTokens.usdt,
|
|
179
|
+
quoteToken: tokens.bscTokens.usdc,
|
|
180
|
+
stableSwapAddress: "0x3EFebC418efB585248A0D2140cfb87aFcc2C63DD",
|
|
181
|
+
infoStableSwapAddress: "0xa680d27f63Fa5E213C502d1B3Ca1EB6a3C1b31D6",
|
|
182
|
+
stableLpFee: 5e-5,
|
|
183
|
+
stableLpFeeRateOfTotalFee: 0.5
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
lpSymbol: "axlUSDC-USDT LP",
|
|
187
|
+
lpAddress: "0x1c7e5a3A72b6D94DE5Ec20812E3e68713978a584",
|
|
188
|
+
token: tokens.bscTokens.axlusdc,
|
|
189
|
+
quoteToken: tokens.bscTokens.usdt,
|
|
190
|
+
stableSwapAddress: "0x6D8fba276ec6F1EDa2344DA48565AdbCA7e4FFa5",
|
|
191
|
+
infoStableSwapAddress: "0x150c8AbEB487137acCC541925408e73b92F39A50",
|
|
192
|
+
stableLpFee: 2e-4,
|
|
193
|
+
stableLpFeeRateOfTotalFee: 0.5
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
lpSymbol: "WBNB-stkBNB LP",
|
|
197
|
+
lpAddress: "0x9976f5c8BEfDee650226d5571d5F5551e8722b75",
|
|
198
|
+
token: tokens.bscTokens.wbnb,
|
|
199
|
+
quoteToken: tokens.bscTokens.stkbnb,
|
|
200
|
+
stableSwapAddress: "0x0b03e3d6Ec0c5e5bBf993dED8D947C6fb6eEc18D",
|
|
201
|
+
infoStableSwapAddress: "0x150c8AbEB487137acCC541925408e73b92F39A50",
|
|
202
|
+
stableLpFee: 2e-4,
|
|
203
|
+
stableLpFeeRateOfTotalFee: 0.5
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
lpSymbol: "BNBx-BNB LP",
|
|
207
|
+
lpAddress: "0x92357Ab9003CA881E08e32CDAE59B10B3161b05C",
|
|
208
|
+
token: tokens.bscTokens.bnbx,
|
|
209
|
+
quoteToken: tokens.bscTokens.wbnb,
|
|
210
|
+
stableSwapAddress: "0x9c138bE1D76ee4C5162E0fe9D4eEA5542a23D1bD",
|
|
211
|
+
infoStableSwapAddress: "0x150c8AbEB487137acCC541925408e73b92F39A50",
|
|
212
|
+
stableLpFee: 2e-4,
|
|
213
|
+
stableLpFeeRateOfTotalFee: 0.5
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
lpSymbol: "lisUSD-USDT LP",
|
|
217
|
+
lpAddress: "0xB2Aa63f363196caba3154D4187949283F085a488",
|
|
218
|
+
token: tokens.bscTokens.hay,
|
|
219
|
+
quoteToken: tokens.bscTokens.usdt,
|
|
220
|
+
stableSwapAddress: "0xb1Da7D2C257c5700612BdE35C8d7187dc80d79f1",
|
|
221
|
+
infoStableSwapAddress: "0x150c8AbEB487137acCC541925408e73b92F39A50",
|
|
222
|
+
stableLpFee: 4e-4,
|
|
223
|
+
stableLpFeeRateOfTotalFee: 0.5
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
lpSymbol: "CAKE-sdCAKE LP",
|
|
227
|
+
lpAddress: "0xB1D54d76E2cB9425Ec9c018538cc531440b55dbB",
|
|
228
|
+
token: tokens.bscTokens.cake,
|
|
229
|
+
quoteToken: tokens.bscTokens.sdcake,
|
|
230
|
+
stableSwapAddress: "0xb8204D31379A9B317CD61C833406C972F58ecCbC",
|
|
231
|
+
infoStableSwapAddress: "0x150c8AbEB487137acCC541925408e73b92F39A50",
|
|
232
|
+
stableLpFee: 1e-3,
|
|
233
|
+
stableLpFeeRateOfTotalFee: 0.5
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
lpSymbol: "CAKE-mCAKE LP",
|
|
237
|
+
lpAddress: "0xb9dC6396AcFFD24E0f69Dfd3231fDaeB31514D02",
|
|
238
|
+
token: tokens.bscTokens.cake,
|
|
239
|
+
quoteToken: tokens.bscTokens.mcake,
|
|
240
|
+
stableSwapAddress: "0xc54d35a8Cfd9f6dAe50945Df27A91C9911A03ab1",
|
|
241
|
+
infoStableSwapAddress: "0x150c8AbEB487137acCC541925408e73b92F39A50",
|
|
242
|
+
stableLpFee: 5e-3,
|
|
243
|
+
stableLpFeeRateOfTotalFee: 0.5
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
lpSymbol: "mPENDLE-PENDLE LP",
|
|
247
|
+
lpAddress: "0x183F325b33d190597D80d1B46D865d0250fD9BF2",
|
|
248
|
+
token: tokens.bscTokens.mpendle,
|
|
249
|
+
quoteToken: tokens.bscTokens.pendle,
|
|
250
|
+
stableSwapAddress: "0xD8CB82059da7215b1a9604E845d49D3e78d0f95A",
|
|
251
|
+
infoStableSwapAddress: "0x150c8AbEB487137acCC541925408e73b92F39A50",
|
|
252
|
+
stableLpFee: 25e-4,
|
|
253
|
+
stableLpFeeRateOfTotalFee: 0.5
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
lpSymbol: "mDLP-DLP LP",
|
|
257
|
+
lpAddress: "0xA2915ae3bc8C6C03f59496B6Dd26aa6a4335b788",
|
|
258
|
+
token: tokens.bscTokens.mdlp,
|
|
259
|
+
quoteToken: tokens.bscTokens.dlp,
|
|
260
|
+
stableSwapAddress: "0x25d0eD3b1cE5aF0F3Ac7da4b39B46FC409bF67e2",
|
|
261
|
+
infoStableSwapAddress: "0x150c8AbEB487137acCC541925408e73b92F39A50",
|
|
262
|
+
stableLpFee: 25e-4,
|
|
263
|
+
stableLpFeeRateOfTotalFee: 0.5
|
|
264
|
+
}
|
|
265
|
+
];
|
|
266
|
+
var pools2 = [
|
|
267
|
+
{
|
|
268
|
+
lpSymbol: "PENDLE-mPENDLE LP",
|
|
269
|
+
lpAddress: "0x1A2329546f11e4fE55b853D98Bba2c4678E3105A",
|
|
270
|
+
token: tokens.arbitrumTokens.pendle,
|
|
271
|
+
quoteToken: tokens.arbitrumTokens.mpendle,
|
|
272
|
+
stableSwapAddress: "0x73ed25e04Aa673ddf7411441098fC5ae19976CE0",
|
|
273
|
+
infoStableSwapAddress: "0x58B2F00f74a1877510Ec37b22f116Bf5D63Ab1b0",
|
|
274
|
+
stableLpFee: 25e-4,
|
|
275
|
+
stableLpFeeRateOfTotalFee: 0.5
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
lpSymbol: "DLP-mDLP LP",
|
|
279
|
+
lpAddress: "0x0db5e247ab73FBaE16d9301f2977f974EC0AA336",
|
|
280
|
+
token: tokens.arbitrumTokens.dlp,
|
|
281
|
+
quoteToken: tokens.arbitrumTokens.mdlp,
|
|
282
|
+
stableSwapAddress: "0xd0f0be815a76eFE677c92b07b39a5e972BAf22bD",
|
|
283
|
+
infoStableSwapAddress: "0x58B2F00f74a1877510Ec37b22f116Bf5D63Ab1b0",
|
|
284
|
+
stableLpFee: 25e-4,
|
|
285
|
+
stableLpFeeRateOfTotalFee: 0.5
|
|
286
|
+
}
|
|
287
|
+
];
|
|
288
|
+
var mockUSDT = new swapSdkCore.Token(chains.ChainId.BSC_TESTNET, "0x0fB5D7c73FA349A90392f873a4FA1eCf6a3d0a96", 18, "USDT", "MOCK Token");
|
|
289
|
+
var pools3 = [
|
|
290
|
+
// {
|
|
291
|
+
// lpSymbol: 'USDC-BUSD LP',
|
|
292
|
+
// lpAddress: '0xd1742b5eC6798cEB8C791e0ebbEf606A4946f67E',
|
|
293
|
+
// token: bscTestnetTokens.usdc, // coins[0]
|
|
294
|
+
// quoteToken: bscTestnetTokens.busd, // coins[1]
|
|
295
|
+
// stableSwapAddress: '0x1288026D2c5a76A5bfb0730F615131A448f4Ad06',
|
|
296
|
+
// infoStableSwapAddress: '0xaE6C14AAA753B3FCaB96149e1E10Bc4EDF39F546',
|
|
297
|
+
// },
|
|
298
|
+
{
|
|
299
|
+
lpSymbol: "USDT-WBNB LP",
|
|
300
|
+
lpAddress: "0x4c091Dc4418Bd3353A87488535528FD86954da2c",
|
|
301
|
+
token: mockUSDT,
|
|
302
|
+
// coins[0]
|
|
303
|
+
quoteToken: tokens.bscTestnetTokens.wbnb,
|
|
304
|
+
// coins[1]
|
|
305
|
+
stableSwapAddress: "0xBcd585Ee8B8Ac8de6b0e45dA32Aa31703036b2a1",
|
|
306
|
+
infoStableSwapAddress: "0x0A548d59D04096Bc01206D58C3D63c478e1e06dB",
|
|
307
|
+
stableLpFee: 4e-4,
|
|
308
|
+
stableLpFeeRateOfTotalFee: 0.5
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
lpSymbol: "USDT-BUSD LP",
|
|
312
|
+
lpAddress: "0x746a7063101E2D3305D1556888ee08193f2B9a07",
|
|
313
|
+
token: mockUSDT,
|
|
314
|
+
// coins[0]
|
|
315
|
+
quoteToken: tokens.bscTestnetTokens.busd,
|
|
316
|
+
// coins[1]
|
|
317
|
+
stableSwapAddress: "0xE25A1352477f3DB9B3008B31e9b7a07a18f8A9e6",
|
|
318
|
+
infoStableSwapAddress: "0x0A548d59D04096Bc01206D58C3D63c478e1e06dB",
|
|
319
|
+
stableLpFee: 4e-4,
|
|
320
|
+
stableLpFeeRateOfTotalFee: 0.5
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
lpSymbol: "BUSD-USDC LP",
|
|
324
|
+
lpAddress: "0x7CA885d338462790DD1B5416ebe6bec75ee045a1",
|
|
325
|
+
token: tokens.bscTestnetTokens.mockBusd,
|
|
326
|
+
// coins[0]
|
|
327
|
+
quoteToken: tokens.bscTestnetTokens.usdc,
|
|
328
|
+
// coins[1]
|
|
329
|
+
stableSwapAddress: "0xd5E56CD4c8111643a94Ee084df31F44055a1EC9F",
|
|
330
|
+
infoStableSwapAddress: "0xaE6C14AAA753B3FCaB96149e1E10Bc4EDF39F546",
|
|
331
|
+
stableLpFee: 2e-4,
|
|
332
|
+
stableLpFeeRateOfTotalFee: 0.5
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
lpSymbol: "USDT-BUSD LP",
|
|
336
|
+
lpAddress: "0x9Fa2Ef2C3dF6F903F4b73047311e861C51a11B60",
|
|
337
|
+
token: tokens.bscTestnetTokens.usdt,
|
|
338
|
+
// coins[0]
|
|
339
|
+
quoteToken: tokens.bscTestnetTokens.mockBusd,
|
|
340
|
+
// coins[1]
|
|
341
|
+
stableSwapAddress: "0xc418d68751Cbe0407C8fdd90Cde73cE95b892f39",
|
|
342
|
+
infoStableSwapAddress: "0xaE6C14AAA753B3FCaB96149e1E10Bc4EDF39F546",
|
|
343
|
+
stableLpFee: 2e-4,
|
|
344
|
+
stableLpFeeRateOfTotalFee: 0.5
|
|
345
|
+
}
|
|
346
|
+
];
|
|
347
|
+
|
|
348
|
+
// src/constants/pools/pools.ts
|
|
349
|
+
var isStableSwapSupported = (chainId) => {
|
|
350
|
+
if (!chainId) {
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
return STABLE_SUPPORTED_CHAIN_IDS.includes(chainId);
|
|
354
|
+
};
|
|
355
|
+
var STABLE_SUPPORTED_CHAIN_IDS = [chains.ChainId.BSC, chains.ChainId.BSC_TESTNET, chains.ChainId.ARBITRUM_ONE];
|
|
356
|
+
var STABLE_POOL_MAP = {
|
|
357
|
+
[chains.ChainId.BSC]: pools,
|
|
358
|
+
[chains.ChainId.BSC_TESTNET]: pools3,
|
|
359
|
+
[chains.ChainId.ARBITRUM_ONE]: pools2
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
// src/constants/pools/index.ts
|
|
363
|
+
function getStableSwapPools(chainId) {
|
|
364
|
+
if (!isStableSwapSupported(chainId)) {
|
|
365
|
+
return [];
|
|
366
|
+
}
|
|
367
|
+
return STABLE_POOL_MAP[chainId] || [];
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// src/constants/index.ts
|
|
371
|
+
var ONE_HUNDRED_PERCENT = new swapSdkCore.Percent("1");
|
|
372
|
+
|
|
373
|
+
// src/amm/getSwapOutput.ts
|
|
374
|
+
function getSwapOutput({
|
|
375
|
+
amplifier,
|
|
376
|
+
balances: balanceAmounts,
|
|
377
|
+
outputCurrency,
|
|
378
|
+
amount,
|
|
379
|
+
fee
|
|
380
|
+
}) {
|
|
381
|
+
const validateAmountOut = (a) => invariant__default.default(!a.lessThan(swapSdkCore.ZERO), "Insufficient liquidity to perform the swap");
|
|
382
|
+
let i = null;
|
|
383
|
+
let j = null;
|
|
384
|
+
const balances = [];
|
|
385
|
+
for (const [index, b] of balanceAmounts.entries()) {
|
|
386
|
+
balances.push(getRawAmount(b));
|
|
387
|
+
if (b.currency.wrapped.equals(amount.currency.wrapped)) {
|
|
388
|
+
i = index;
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
if (b.currency.wrapped.equals(outputCurrency.wrapped)) {
|
|
392
|
+
j = index;
|
|
393
|
+
continue;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
invariant__default.default(
|
|
397
|
+
i !== null && j !== null && i !== j,
|
|
398
|
+
"Input currency or output currency does not match currencies of token balances."
|
|
399
|
+
);
|
|
400
|
+
if (amount.quotient < swapSdkCore.ZERO) {
|
|
401
|
+
const x = ONE_HUNDRED_PERCENT.subtract(fee).invert().multiply(getRawAmount(amount)).quotient;
|
|
402
|
+
const y2 = getY({ amplifier, balances, i, j, x });
|
|
403
|
+
const dy2 = y2 - balances[j];
|
|
404
|
+
const amountOut2 = parseAmount(outputCurrency, dy2);
|
|
405
|
+
validateAmountOut(amountOut2);
|
|
406
|
+
return amountOut2;
|
|
407
|
+
}
|
|
408
|
+
const y = getY({ amplifier, balances, i, j, x: getRawAmount(amount) });
|
|
409
|
+
const dy = balances[j] - y;
|
|
410
|
+
const feeAmount = fee.multiply(dy).quotient;
|
|
411
|
+
const amountOut = parseAmount(outputCurrency, dy - feeAmount);
|
|
412
|
+
validateAmountOut(amountOut);
|
|
413
|
+
return amountOut;
|
|
414
|
+
}
|
|
415
|
+
function getSwapOutputWithoutFee(params) {
|
|
416
|
+
return getSwapOutput({ ...params, fee: new swapSdkCore.Percent(0) });
|
|
417
|
+
}
|
|
418
|
+
function getSwapInput({ amount, ...rest }) {
|
|
419
|
+
return getSwapOutput({
|
|
420
|
+
...rest,
|
|
421
|
+
amount: swapSdkCore.CurrencyAmount.fromRawAmount(amount.currency, -amount.quotient)
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
function getSwapInputWithtouFee(params) {
|
|
425
|
+
return getSwapInput({ ...params, fee: new swapSdkCore.Percent(0) });
|
|
426
|
+
}
|
|
427
|
+
function createQuoteGetter(isExactIn) {
|
|
428
|
+
const getSwapQuote = isExactIn ? getSwapOutput : getSwapInput;
|
|
429
|
+
const applySwap = (balances, amount, quote) => balances.map((b) => {
|
|
430
|
+
if (b.currency.equals(amount.currency)) {
|
|
431
|
+
return isExactIn ? b.add(amount) : b.subtract(amount);
|
|
432
|
+
}
|
|
433
|
+
if (b.currency.equals(quote.currency)) {
|
|
434
|
+
return isExactIn ? b.subtract(quote) : b.add(quote);
|
|
435
|
+
}
|
|
436
|
+
return b;
|
|
437
|
+
});
|
|
438
|
+
return function getQuote(params) {
|
|
439
|
+
const { balances, amplifier, fee, amount } = params;
|
|
440
|
+
const quote = getSwapQuote(params);
|
|
441
|
+
return [
|
|
442
|
+
quote,
|
|
443
|
+
{
|
|
444
|
+
balances: applySwap(balances, amount, quote),
|
|
445
|
+
amplifier,
|
|
446
|
+
fee
|
|
447
|
+
}
|
|
448
|
+
];
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
var getQuoteExactIn = createQuoteGetter(true);
|
|
452
|
+
var getQuoteExactOut = createQuoteGetter(false);
|
|
453
|
+
|
|
454
|
+
exports.ONE_HUNDRED_PERCENT = ONE_HUNDRED_PERCENT;
|
|
455
|
+
exports.STABLE_SUPPORTED_CHAIN_IDS = STABLE_SUPPORTED_CHAIN_IDS;
|
|
456
|
+
exports.getD = getD;
|
|
457
|
+
exports.getLPOutput = getLPOutput;
|
|
458
|
+
exports.getLPOutputWithoutFee = getLPOutputWithoutFee;
|
|
459
|
+
exports.getQuoteExactIn = getQuoteExactIn;
|
|
460
|
+
exports.getQuoteExactOut = getQuoteExactOut;
|
|
461
|
+
exports.getStableSwapPools = getStableSwapPools;
|
|
462
|
+
exports.getSwapInput = getSwapInput;
|
|
463
|
+
exports.getSwapInputWithtouFee = getSwapInputWithtouFee;
|
|
464
|
+
exports.getSwapOutput = getSwapOutput;
|
|
465
|
+
exports.getSwapOutputWithoutFee = getSwapOutputWithoutFee;
|
|
466
|
+
exports.isStableSwapSupported = isStableSwapSupported;
|
|
467
|
+
//# sourceMappingURL=out.js.map
|
|
468
|
+
//# sourceMappingURL=index.cjs.map
|