@swapkit/helpers 4.0.0-beta.32 → 4.0.0-beta.34
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/dist/api/index.js +2 -2
- package/dist/api/index.js.map +1 -1
- package/dist/{chunk-ganzk321.js → chunk-hm14bfyg.js} +3 -3
- package/dist/{chunk-fazw0jvt.js.map → chunk-hm14bfyg.js.map} +1 -1
- package/dist/chunk-vb4wtm2w.js +4 -0
- package/dist/{chunk-ganzk321.js.map → chunk-vb4wtm2w.js.map} +1 -1
- package/dist/contracts.cjs +4 -0
- package/dist/contracts.cjs.map +10 -0
- package/dist/contracts.js +4 -0
- package/dist/contracts.js.map +10 -0
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +11 -11
- package/dist/index.js +3 -3
- package/dist/index.js.map +11 -11
- package/dist/tokens.cjs +4 -0
- package/dist/tokens.cjs.map +10 -0
- package/dist/tokens.js +4 -0
- package/dist/tokens.js.map +10 -0
- package/dist/types/api/index.d.ts +238 -0
- package/dist/types/api/index.d.ts.map +1 -0
- package/dist/types/api/microgard/endpoints.d.ts +25 -0
- package/dist/types/api/microgard/endpoints.d.ts.map +1 -0
- package/dist/types/api/microgard/types.d.ts +56 -0
- package/dist/types/api/microgard/types.d.ts.map +1 -0
- package/dist/types/api/midgard/endpoints.d.ts +35 -0
- package/dist/types/api/midgard/endpoints.d.ts.map +1 -0
- package/dist/types/api/midgard/types.d.ts +102 -0
- package/dist/types/api/midgard/types.d.ts.map +1 -0
- package/dist/types/api/swapkitApi/endpoints.d.ts +194 -0
- package/dist/types/api/swapkitApi/endpoints.d.ts.map +1 -0
- package/dist/types/api/swapkitApi/types.d.ts +7238 -0
- package/dist/types/api/swapkitApi/types.d.ts.map +1 -0
- package/dist/types/api/thornode/endpoints.d.ts +31 -0
- package/dist/types/api/thornode/endpoints.d.ts.map +1 -0
- package/dist/types/api/thornode/types.d.ts +264 -0
- package/dist/types/api/thornode/types.d.ts.map +1 -0
- package/dist/types/api/thorswapStatic/endpoints.d.ts +7 -0
- package/dist/types/api/thorswapStatic/endpoints.d.ts.map +1 -0
- package/dist/types/api/thorswapStatic/types.d.ts +22 -0
- package/dist/types/api/thorswapStatic/types.d.ts.map +1 -0
- package/dist/types/contracts.d.ts +2 -0
- package/dist/types/contracts.d.ts.map +1 -0
- package/{src/index.ts → dist/types/index.d.ts} +3 -4
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/modules/assetValue.d.ts +71 -0
- package/dist/types/modules/assetValue.d.ts.map +1 -0
- package/dist/types/modules/bigIntArithmetics.d.ts +56 -0
- package/dist/types/modules/bigIntArithmetics.d.ts.map +1 -0
- package/dist/types/modules/feeMultiplier.d.ts +45 -0
- package/dist/types/modules/feeMultiplier.d.ts.map +1 -0
- package/dist/types/modules/requestClient.d.ts +22 -0
- package/dist/types/modules/requestClient.d.ts.map +1 -0
- package/dist/types/modules/swapKitConfig.d.ts +98 -0
- package/dist/types/modules/swapKitConfig.d.ts.map +1 -0
- package/dist/types/modules/swapKitError.d.ts +829 -0
- package/dist/types/modules/swapKitError.d.ts.map +1 -0
- package/dist/types/modules/swapKitNumber.d.ts +7 -0
- package/dist/types/modules/swapKitNumber.d.ts.map +1 -0
- package/dist/types/tokens.d.ts +2 -0
- package/dist/types/tokens.d.ts.map +1 -0
- package/dist/types/types/chains.d.ts +187 -0
- package/dist/types/types/chains.d.ts.map +1 -0
- package/dist/types/types/commonTypes.d.ts +37 -0
- package/dist/types/types/commonTypes.d.ts.map +1 -0
- package/dist/types/types/derivationPath.d.ts +17 -0
- package/dist/types/types/derivationPath.d.ts.map +1 -0
- package/dist/types/types/errors/apiV1.d.ts +2 -0
- package/dist/types/types/errors/apiV1.d.ts.map +1 -0
- package/{src/types/index.ts → dist/types/types/index.d.ts} +1 -1
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/quotes.d.ts +170 -0
- package/dist/types/types/quotes.d.ts.map +1 -0
- package/dist/types/types/radix.d.ts +15 -0
- package/dist/types/types/radix.d.ts.map +1 -0
- package/dist/types/types/sdk.d.ts +35 -0
- package/dist/types/types/sdk.d.ts.map +1 -0
- package/dist/types/types/wallet.d.ts +121 -0
- package/dist/types/types/wallet.d.ts.map +1 -0
- package/dist/types/utils/asset.d.ts +40 -0
- package/dist/types/utils/asset.d.ts.map +1 -0
- package/dist/types/utils/derivationPath.d.ts +19 -0
- package/dist/types/utils/derivationPath.d.ts.map +1 -0
- package/dist/types/utils/explorerUrls.d.ts +10 -0
- package/dist/types/utils/explorerUrls.d.ts.map +1 -0
- package/dist/types/utils/liquidity.d.ts +59 -0
- package/dist/types/utils/liquidity.d.ts.map +1 -0
- package/dist/types/utils/memo.d.ts +65 -0
- package/dist/types/utils/memo.d.ts.map +1 -0
- package/dist/types/utils/others.d.ts +9 -0
- package/dist/types/utils/others.d.ts.map +1 -0
- package/dist/types/utils/validators.d.ts +3 -0
- package/dist/types/utils/validators.d.ts.map +1 -0
- package/dist/types/utils/wallets.d.ts +32 -0
- package/dist/types/utils/wallets.d.ts.map +1 -0
- package/package.json +14 -15
- package/dist/chunk-06q78xy3.js +0 -4
- package/dist/chunk-06q78xy3.js.map +0 -10
- package/dist/chunk-0q5vvg5c.js +0 -5
- package/dist/chunk-0q5vvg5c.js.map +0 -10
- package/dist/chunk-18bxh1n7.js +0 -5
- package/dist/chunk-18bxh1n7.js.map +0 -10
- package/dist/chunk-3qya5ng9.js +0 -4
- package/dist/chunk-3qya5ng9.js.map +0 -10
- package/dist/chunk-4yqymkbp.js +0 -5
- package/dist/chunk-4yqymkbp.js.map +0 -10
- package/dist/chunk-50gpwcq9.js +0 -4
- package/dist/chunk-50gpwcq9.js.map +0 -10
- package/dist/chunk-6atq9cs7.js +0 -4
- package/dist/chunk-6atq9cs7.js.map +0 -10
- package/dist/chunk-6m0d5pv4.js +0 -5
- package/dist/chunk-6m0d5pv4.js.map +0 -10
- package/dist/chunk-8x46g3wq.js +0 -5
- package/dist/chunk-8x46g3wq.js.map +0 -10
- package/dist/chunk-92sk0g47.js +0 -5
- package/dist/chunk-92sk0g47.js.map +0 -10
- package/dist/chunk-9f2b3enk.js +0 -5
- package/dist/chunk-9f2b3enk.js.map +0 -10
- package/dist/chunk-adrafsdk.js +0 -5
- package/dist/chunk-adrafsdk.js.map +0 -10
- package/dist/chunk-b1hang9z.js +0 -5
- package/dist/chunk-b1hang9z.js.map +0 -10
- package/dist/chunk-becdmywt.js +0 -4
- package/dist/chunk-becdmywt.js.map +0 -10
- package/dist/chunk-ehz0t9d1.js +0 -4
- package/dist/chunk-ehz0t9d1.js.map +0 -10
- package/dist/chunk-fazw0jvt.js +0 -4
- package/dist/chunk-fm9ycn0h.js +0 -5
- package/dist/chunk-fm9ycn0h.js.map +0 -10
- package/dist/chunk-g67e2r57.js +0 -4
- package/dist/chunk-g67e2r57.js.map +0 -10
- package/dist/chunk-he3vy8gt.js +0 -4
- package/dist/chunk-he3vy8gt.js.map +0 -10
- package/dist/chunk-jjayk2y5.js +0 -4
- package/dist/chunk-jjayk2y5.js.map +0 -10
- package/dist/chunk-mmyv2vsv.js +0 -5
- package/dist/chunk-mmyv2vsv.js.map +0 -10
- package/dist/chunk-phev7aw7.js +0 -4
- package/dist/chunk-phev7aw7.js.map +0 -10
- package/dist/chunk-rhqk87p2.js +0 -5
- package/dist/chunk-rhqk87p2.js.map +0 -10
- package/dist/chunk-rnv7fdjk.js +0 -4
- package/dist/chunk-rnv7fdjk.js.map +0 -10
- package/dist/chunk-rwh98p1c.js +0 -4
- package/dist/chunk-rwh98p1c.js.map +0 -10
- package/dist/chunk-v9zj2gsj.js +0 -5
- package/dist/chunk-v9zj2gsj.js.map +0 -10
- package/dist/chunk-vv5bgsn8.js +0 -4
- package/dist/chunk-vv5bgsn8.js.map +0 -10
- package/dist/chunk-vwh9jfxn.js +0 -5
- package/dist/chunk-vwh9jfxn.js.map +0 -10
- package/dist/chunk-x0rqy75t.js +0 -4
- package/dist/chunk-x0rqy75t.js.map +0 -10
- package/dist/contracts/index.cjs +0 -4
- package/dist/contracts/index.cjs.map +0 -38
- package/dist/contracts/index.js +0 -4
- package/dist/contracts/index.js.map +0 -38
- package/dist/tokens/index.cjs +0 -4
- package/dist/tokens/index.cjs.map +0 -10
- package/dist/tokens/index.js +0 -4
- package/dist/tokens/index.js.map +0 -10
- package/src/api/index.ts +0 -19
- package/src/api/microgard/endpoints.ts +0 -83
- package/src/api/microgard/types.ts +0 -57
- package/src/api/midgard/endpoints.ts +0 -90
- package/src/api/midgard/types.ts +0 -106
- package/src/api/swapkitApi/endpoints.ts +0 -193
- package/src/api/swapkitApi/types.ts +0 -635
- package/src/api/thornode/endpoints.ts +0 -116
- package/src/api/thornode/types.ts +0 -276
- package/src/api/thorswapStatic/endpoints.ts +0 -46
- package/src/api/thorswapStatic/types.ts +0 -18
- package/src/contracts/abis/avaxGeneric.ts +0 -92
- package/src/contracts/abis/avaxWoofi.ts +0 -145
- package/src/contracts/abis/bscGeneric.ts +0 -106
- package/src/contracts/abis/chainflipGateway.ts +0 -330
- package/src/contracts/abis/erc20.ts +0 -99
- package/src/contracts/abis/ethGeneric.ts +0 -92
- package/src/contracts/abis/mayaEvmVaults.ts +0 -331
- package/src/contracts/abis/pancakeV2.ts +0 -145
- package/src/contracts/abis/pangolin.ts +0 -120
- package/src/contracts/abis/sushiswap.ts +0 -120
- package/src/contracts/abis/tcEthVault.ts +0 -650
- package/src/contracts/abis/traderJoe.ts +0 -120
- package/src/contracts/abis/uniswapV2.ts +0 -120
- package/src/contracts/abis/uniswapV2Leg.ts +0 -128
- package/src/contracts/abis/uniswapV3_100.ts +0 -128
- package/src/contracts/abis/uniswapV3_10000.ts +0 -128
- package/src/contracts/abis/uniswapV3_3000.ts +0 -128
- package/src/contracts/abis/uniswapV3_500.ts +0 -128
- package/src/contracts/index.ts +0 -95
- package/src/contracts/routers/index.ts +0 -58
- package/src/contracts/routers/kyber.ts +0 -402
- package/src/contracts/routers/oneinch.ts +0 -2188
- package/src/contracts/routers/pancakeswap.ts +0 -340
- package/src/contracts/routers/pangolin.ts +0 -340
- package/src/contracts/routers/sushiswap.ts +0 -340
- package/src/contracts/routers/traderJoe.ts +0 -340
- package/src/contracts/routers/uniswapv2.ts +0 -340
- package/src/contracts/routers/uniswapv3.ts +0 -254
- package/src/contracts/routers/woofi.ts +0 -171
- package/src/modules/__tests__/assetValue.test.ts +0 -877
- package/src/modules/__tests__/bigIntArithmetics.test.ts +0 -30
- package/src/modules/__tests__/swapKitConfig.test.ts +0 -37
- package/src/modules/__tests__/swapKitNumber.test.ts +0 -560
- package/src/modules/assetValue.ts +0 -387
- package/src/modules/bigIntArithmetics.ts +0 -436
- package/src/modules/feeMultiplier.ts +0 -87
- package/src/modules/requestClient.ts +0 -83
- package/src/modules/swapKitConfig.ts +0 -143
- package/src/modules/swapKitError.ts +0 -442
- package/src/modules/swapKitNumber.ts +0 -16
- package/src/tokens/index.ts +0 -15
- package/src/tokens/lists/camelot_v3.ts +0 -16060
- package/src/tokens/lists/caviar_v1.ts +0 -1704
- package/src/tokens/lists/chainflip.ts +0 -104
- package/src/tokens/lists/index.ts +0 -14
- package/src/tokens/lists/jupiter.ts +0 -33563
- package/src/tokens/lists/mayachain.ts +0 -509
- package/src/tokens/lists/near.ts +0 -458
- package/src/tokens/lists/oneinch.ts +0 -15006
- package/src/tokens/lists/openocean_v2.ts +0 -12434
- package/src/tokens/lists/pancakeswap.ts +0 -6136
- package/src/tokens/lists/pangolin_v1.ts +0 -75
- package/src/tokens/lists/sushiswap_v2.ts +0 -595
- package/src/tokens/lists/thorchain.ts +0 -748
- package/src/tokens/lists/traderjoe_v2.ts +0 -594
- package/src/tokens/lists/uniswap_v2.ts +0 -11484
- package/src/tokens/lists/uniswap_v3.ts +0 -19424
- package/src/types/chains.ts +0 -555
- package/src/types/commonTypes.ts +0 -58
- package/src/types/derivationPath.ts +0 -58
- package/src/types/errors/apiV1.ts +0 -0
- package/src/types/quotes.ts +0 -172
- package/src/types/radix.ts +0 -14
- package/src/types/sdk.ts +0 -42
- package/src/types/tokens.ts +0 -17
- package/src/types/wallet.ts +0 -166
- package/src/utils/__tests__/asset.test.ts +0 -193
- package/src/utils/__tests__/derivationPath.test.ts +0 -16
- package/src/utils/__tests__/memo.test.ts +0 -103
- package/src/utils/__tests__/others.test.ts +0 -88
- package/src/utils/__tests__/validators.test.ts +0 -24
- package/src/utils/asset.ts +0 -231
- package/src/utils/derivationPath.ts +0 -98
- package/src/utils/liquidity.ts +0 -179
- package/src/utils/memo.ts +0 -143
- package/src/utils/others.ts +0 -86
- package/src/utils/plugin.ts +0 -13
- package/src/utils/tokens.ts +0 -73
- package/src/utils/validators.ts +0 -32
- package/src/utils/wallets.ts +0 -276
package/src/utils/liquidity.ts
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import { SwapKitNumber } from "../index";
|
|
2
|
-
import { BaseDecimal } from "../types/chains";
|
|
3
|
-
|
|
4
|
-
type ShareParams<T extends {}> = T & {
|
|
5
|
-
liquidityUnits: string;
|
|
6
|
-
poolUnits: string;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
type PoolParams = {
|
|
10
|
-
runeAmount: string;
|
|
11
|
-
assetAmount: string;
|
|
12
|
-
runeDepth: string;
|
|
13
|
-
assetDepth: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Ref: https://gitlab.com/thorchain/thornode/-/issues/657
|
|
18
|
-
* share = (s * A * (2 * T^2 - 2 * T * s + s^2))/T^3
|
|
19
|
-
* s = stakeUnits for member (after factoring in withdrawBasisPoints)
|
|
20
|
-
* T = totalPoolUnits for pool
|
|
21
|
-
* A = assetDepth to be withdrawn
|
|
22
|
-
*
|
|
23
|
-
* Formula:
|
|
24
|
-
* share = (s * A * (2 * T^2 - 2 * T * s + s^2))/T^3
|
|
25
|
-
* (part1 * (part2 - part3 + part4)) / part5
|
|
26
|
-
*/
|
|
27
|
-
export function getAsymmetricRuneShare({
|
|
28
|
-
liquidityUnits,
|
|
29
|
-
poolUnits,
|
|
30
|
-
runeDepth,
|
|
31
|
-
}: ShareParams<{ runeDepth: string }>) {
|
|
32
|
-
const s = toTCSwapKitNumber(liquidityUnits);
|
|
33
|
-
const T = toTCSwapKitNumber(poolUnits);
|
|
34
|
-
const A = toTCSwapKitNumber(runeDepth);
|
|
35
|
-
|
|
36
|
-
const part1 = s.mul(A);
|
|
37
|
-
const part2 = T.mul(T).mul(2);
|
|
38
|
-
const part3 = T.mul(s).mul(2);
|
|
39
|
-
const part4 = s.mul(s);
|
|
40
|
-
const part5 = T.mul(T).mul(T);
|
|
41
|
-
|
|
42
|
-
const numerator = part1.mul(part2.sub(part3).add(part4));
|
|
43
|
-
|
|
44
|
-
return numerator.div(part5);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function getAsymmetricAssetShare({
|
|
48
|
-
liquidityUnits,
|
|
49
|
-
poolUnits,
|
|
50
|
-
assetDepth,
|
|
51
|
-
}: ShareParams<{ assetDepth: string }>) {
|
|
52
|
-
const s = toTCSwapKitNumber(liquidityUnits);
|
|
53
|
-
const T = toTCSwapKitNumber(poolUnits);
|
|
54
|
-
const A = toTCSwapKitNumber(assetDepth);
|
|
55
|
-
|
|
56
|
-
const part1 = s.mul(A);
|
|
57
|
-
const part2 = T.mul(T).mul(2);
|
|
58
|
-
const part3 = T.mul(s).mul(2);
|
|
59
|
-
const part4 = s.mul(s);
|
|
60
|
-
const numerator = part1.mul(part2.sub(part3).add(part4));
|
|
61
|
-
const part5 = T.mul(T).mul(T);
|
|
62
|
-
|
|
63
|
-
return numerator.div(part5);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function getAsymmetricRuneWithdrawAmount({
|
|
67
|
-
percent,
|
|
68
|
-
runeDepth,
|
|
69
|
-
liquidityUnits,
|
|
70
|
-
poolUnits,
|
|
71
|
-
}: ShareParams<{ percent: number; runeDepth: string }>) {
|
|
72
|
-
return getAsymmetricRuneShare({ runeDepth, liquidityUnits, poolUnits }).mul(percent);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function getAsymmetricAssetWithdrawAmount({
|
|
76
|
-
percent,
|
|
77
|
-
assetDepth,
|
|
78
|
-
liquidityUnits,
|
|
79
|
-
poolUnits,
|
|
80
|
-
}: ShareParams<{ percent: number; assetDepth: string }>) {
|
|
81
|
-
return getAsymmetricAssetShare({ assetDepth, liquidityUnits, poolUnits }).mul(percent);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function toTCSwapKitNumber(value: string) {
|
|
85
|
-
return SwapKitNumber.fromBigInt(BigInt(value), BaseDecimal.THOR);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function getSymmetricPoolShare({
|
|
89
|
-
liquidityUnits,
|
|
90
|
-
poolUnits,
|
|
91
|
-
runeDepth,
|
|
92
|
-
assetDepth,
|
|
93
|
-
}: ShareParams<{
|
|
94
|
-
runeDepth: string;
|
|
95
|
-
assetDepth: string;
|
|
96
|
-
}>) {
|
|
97
|
-
return {
|
|
98
|
-
assetAmount: toTCSwapKitNumber(assetDepth).mul(liquidityUnits).div(poolUnits),
|
|
99
|
-
runeAmount: toTCSwapKitNumber(runeDepth).mul(liquidityUnits).div(poolUnits),
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export function getSymmetricWithdraw({
|
|
104
|
-
liquidityUnits,
|
|
105
|
-
poolUnits,
|
|
106
|
-
runeDepth,
|
|
107
|
-
assetDepth,
|
|
108
|
-
percent,
|
|
109
|
-
}: ShareParams<{
|
|
110
|
-
runeDepth: string;
|
|
111
|
-
assetDepth: string;
|
|
112
|
-
percent: number;
|
|
113
|
-
}>) {
|
|
114
|
-
return Object.fromEntries(
|
|
115
|
-
Object.entries(getSymmetricPoolShare({ liquidityUnits, poolUnits, runeDepth, assetDepth })).map(
|
|
116
|
-
([name, value]) => [name, value.mul(percent)],
|
|
117
|
-
),
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export function getEstimatedPoolShare({
|
|
122
|
-
runeDepth,
|
|
123
|
-
poolUnits,
|
|
124
|
-
assetDepth,
|
|
125
|
-
liquidityUnits,
|
|
126
|
-
runeAmount,
|
|
127
|
-
assetAmount,
|
|
128
|
-
}: ShareParams<{
|
|
129
|
-
runeAmount: string;
|
|
130
|
-
assetAmount: string;
|
|
131
|
-
runeDepth: string;
|
|
132
|
-
assetDepth: string;
|
|
133
|
-
}>) {
|
|
134
|
-
const R = new SwapKitNumber({ value: runeDepth, decimal: 8 });
|
|
135
|
-
const A = new SwapKitNumber({ value: assetDepth, decimal: 8 });
|
|
136
|
-
const P = new SwapKitNumber({ value: poolUnits, decimal: 8 });
|
|
137
|
-
const runeAddAmount = new SwapKitNumber({ value: runeAmount, decimal: 8 });
|
|
138
|
-
const assetAddAmount = new SwapKitNumber({ value: assetAmount, decimal: 8 });
|
|
139
|
-
|
|
140
|
-
// liquidityUnits = P * (r*A + a*R + 2*r*a) / (r*A + a*R + 2*R*A)
|
|
141
|
-
const rA = runeAddAmount.mul(A);
|
|
142
|
-
const aR = assetAddAmount.mul(R);
|
|
143
|
-
const ra = runeAddAmount.mul(assetAddAmount);
|
|
144
|
-
const RA = R.mul(A);
|
|
145
|
-
const numerator = P.mul(rA.add(aR.add(ra.mul(2))));
|
|
146
|
-
const denominator = rA.add(aR.add(RA.mul(2)));
|
|
147
|
-
const liquidityUnitsAfterAdd = numerator.div(denominator);
|
|
148
|
-
const estimatedLiquidityUnits = toTCSwapKitNumber(liquidityUnits).add(liquidityUnitsAfterAdd);
|
|
149
|
-
|
|
150
|
-
if (liquidityUnitsAfterAdd.getBaseValue("number") === 0) {
|
|
151
|
-
return estimatedLiquidityUnits.div(P).getBaseValue("number");
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// get pool units after add
|
|
155
|
-
const newPoolUnits = P.add(estimatedLiquidityUnits);
|
|
156
|
-
|
|
157
|
-
return estimatedLiquidityUnits.div(newPoolUnits).getBaseValue("number");
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export function getLiquiditySlippage({
|
|
161
|
-
runeAmount,
|
|
162
|
-
assetAmount,
|
|
163
|
-
runeDepth,
|
|
164
|
-
assetDepth,
|
|
165
|
-
}: PoolParams) {
|
|
166
|
-
if (runeAmount === "0" || assetAmount === "0" || runeDepth === "0" || assetDepth === "0")
|
|
167
|
-
return 0;
|
|
168
|
-
// formula: (t * R - T * r)/ (T*r + R*T)
|
|
169
|
-
const R = toTCSwapKitNumber(runeDepth);
|
|
170
|
-
const T = toTCSwapKitNumber(assetDepth);
|
|
171
|
-
const assetAddAmount = toTCSwapKitNumber(assetAmount);
|
|
172
|
-
const runeAddAmount = toTCSwapKitNumber(runeAmount);
|
|
173
|
-
|
|
174
|
-
const numerator = assetAddAmount.mul(R).sub(T.mul(runeAddAmount));
|
|
175
|
-
const denominator = T.mul(runeAddAmount).add(R.mul(T));
|
|
176
|
-
|
|
177
|
-
// set absolute value of percent, no negative allowed
|
|
178
|
-
return Math.abs(numerator.div(denominator).getBaseValue("number"));
|
|
179
|
-
}
|
package/src/utils/memo.ts
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { match } from "ts-pattern";
|
|
2
|
-
import { Chain } from "../types/chains";
|
|
3
|
-
import { MemoType } from "../types/sdk";
|
|
4
|
-
|
|
5
|
-
export function getMemoForLeaveAndBond({ type, address }: BondOrLeaveParams) {
|
|
6
|
-
return `${type}:${address}`;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function getMemoForUnbond({ address, unbondAmount }: UnbondParams) {
|
|
10
|
-
return `${MemoType.UNBOND}:${address}:${unbondAmount}`;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Deposit
|
|
15
|
-
*/
|
|
16
|
-
export function getMemoForRunePoolDeposit(affiliate?: WithAffiliate<{}>) {
|
|
17
|
-
return addAffiliate(MemoType.RUNEPOOL_DEPOSIT, affiliate);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function getMemoForDeposit({
|
|
21
|
-
chain,
|
|
22
|
-
symbol,
|
|
23
|
-
address,
|
|
24
|
-
...affiliate
|
|
25
|
-
}: WithAffiliate<{
|
|
26
|
-
chain: Chain;
|
|
27
|
-
symbol: string;
|
|
28
|
-
address?: string;
|
|
29
|
-
}>) {
|
|
30
|
-
const poolIdentifier = getPoolIdentifier({ chain, symbol });
|
|
31
|
-
const addressPart = address ? `:${address}:` : ":";
|
|
32
|
-
|
|
33
|
-
return addAffiliate(`${MemoType.DEPOSIT}:${poolIdentifier}${addressPart}`, affiliate);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Withdraw
|
|
38
|
-
*/
|
|
39
|
-
export function getMemoForWithdraw({
|
|
40
|
-
chain,
|
|
41
|
-
symbol,
|
|
42
|
-
ticker,
|
|
43
|
-
basisPoints,
|
|
44
|
-
targetAsset,
|
|
45
|
-
}: WithdrawParams) {
|
|
46
|
-
const shortenedSymbol =
|
|
47
|
-
chain === "ETH" && ticker !== "ETH" ? `${ticker}-${symbol.slice(-3)}` : symbol;
|
|
48
|
-
const targetPart = targetAsset ? `:${targetAsset}` : "";
|
|
49
|
-
|
|
50
|
-
return `${MemoType.WITHDRAW}:${chain}.${shortenedSymbol}:${basisPoints}${targetPart}`;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function getMemoForRunePoolWithdraw({
|
|
54
|
-
basisPoints,
|
|
55
|
-
...affiliate
|
|
56
|
-
}: WithAffiliate<{ basisPoints: number }>) {
|
|
57
|
-
return addAffiliate(`${MemoType.RUNEPOOL_WITHDRAW}:${basisPoints}`, affiliate);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* TNS
|
|
62
|
-
*/
|
|
63
|
-
export function getMemoForNameRegister({ name, chain, address, owner }: NameRegisterParams) {
|
|
64
|
-
const baseMemo = `${MemoType.NAME_REGISTER}:${name}:${chain}:${address}`;
|
|
65
|
-
const ownerAssignmentOrChangePart = owner ? `:${owner}` : "";
|
|
66
|
-
|
|
67
|
-
return `${baseMemo}${ownerAssignmentOrChangePart}`;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function getMemoForNamePreferredAssetRegister({
|
|
71
|
-
name,
|
|
72
|
-
chain,
|
|
73
|
-
asset,
|
|
74
|
-
payout,
|
|
75
|
-
owner,
|
|
76
|
-
}: PreferredAssetRegisterParams) {
|
|
77
|
-
return `${MemoType.NAME_REGISTER}:${name}:${chain}:${payout}:${owner}:${asset}`;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function getMemoForTcyClaim(
|
|
81
|
-
memoType: MemoType.CLAIM_TCY,
|
|
82
|
-
{ address }: WithAffiliate<{ address: string }>,
|
|
83
|
-
) {
|
|
84
|
-
return `${memoType}:${address}`;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function getMemoForTcyStake(
|
|
88
|
-
memoType: MemoType.STAKE_TCY | MemoType.UNSTAKE_TCY,
|
|
89
|
-
{ unstakeBps, ...affiliate }: WithAffiliate<{ unstakeBps?: number }>,
|
|
90
|
-
) {
|
|
91
|
-
const bps = unstakeBps ? `:${unstakeBps}` : "";
|
|
92
|
-
const baseMemo = `${memoType}${bps}`;
|
|
93
|
-
|
|
94
|
-
return addAffiliate(`${baseMemo}`, affiliate);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Internal helpers
|
|
99
|
-
*/
|
|
100
|
-
function addAffiliate(
|
|
101
|
-
memo: string,
|
|
102
|
-
{ affiliateAddress, affiliateBasisPoints }: WithAffiliate<{}> = {},
|
|
103
|
-
) {
|
|
104
|
-
const affiliatedMemo = `${memo}${affiliateAddress ? `:${affiliateAddress}:${affiliateBasisPoints || 0}` : ""}`;
|
|
105
|
-
|
|
106
|
-
return affiliatedMemo.endsWith(":") ? affiliatedMemo.slice(0, -1) : affiliatedMemo;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function getPoolIdentifier({
|
|
110
|
-
chain,
|
|
111
|
-
symbol,
|
|
112
|
-
}: {
|
|
113
|
-
chain: Chain;
|
|
114
|
-
symbol: string;
|
|
115
|
-
}) {
|
|
116
|
-
return match(chain)
|
|
117
|
-
.with(Chain.Bitcoin, Chain.Dogecoin, Chain.Litecoin, () => chain.slice(0, 1).toLowerCase())
|
|
118
|
-
.with(Chain.BitcoinCash, () => "c")
|
|
119
|
-
.otherwise(() => `${chain}.${symbol}`);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
type WithAffiliate<T extends {}> = T & {
|
|
123
|
-
affiliateAddress?: string;
|
|
124
|
-
affiliateBasisPoints?: number;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
type BondOrLeaveParams = { type: MemoType.BOND | MemoType.LEAVE; address: string };
|
|
128
|
-
type UnbondParams = { address: string; unbondAmount: number };
|
|
129
|
-
type NameRegisterParams = { name: string; chain: string; address: string; owner?: string };
|
|
130
|
-
type PreferredAssetRegisterParams = {
|
|
131
|
-
name: string;
|
|
132
|
-
chain: Chain;
|
|
133
|
-
asset: string;
|
|
134
|
-
payout: string;
|
|
135
|
-
owner: string;
|
|
136
|
-
};
|
|
137
|
-
type WithdrawParams = {
|
|
138
|
-
chain: Chain;
|
|
139
|
-
symbol: string;
|
|
140
|
-
ticker: string;
|
|
141
|
-
basisPoints: number;
|
|
142
|
-
targetAsset?: string;
|
|
143
|
-
};
|
package/src/utils/others.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { RequestClient } from "../modules/requestClient";
|
|
2
|
-
import { SKConfig } from "../modules/swapKitConfig";
|
|
3
|
-
import { type ErrorKeys, SwapKitError } from "../modules/swapKitError";
|
|
4
|
-
import { Chain, ChainId, StagenetChain } from "../types";
|
|
5
|
-
|
|
6
|
-
// 10 rune for register, 1 rune per year
|
|
7
|
-
// MINIMUM_REGISTRATION_FEE = 11
|
|
8
|
-
export function getTHORNameCost(numberOfYears: number) {
|
|
9
|
-
if (numberOfYears < 0)
|
|
10
|
-
throw new SwapKitError({
|
|
11
|
-
errorKey: "helpers_invalid_number_of_years",
|
|
12
|
-
info: { numberOfYears },
|
|
13
|
-
});
|
|
14
|
-
return 10 + numberOfYears;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// 10 CACAO for register
|
|
18
|
-
// 1.0512 CACAO per year
|
|
19
|
-
export function getMAYANameCost(numberOfYears: number) {
|
|
20
|
-
if (numberOfYears < 0)
|
|
21
|
-
throw new SwapKitError({
|
|
22
|
-
errorKey: "helpers_invalid_number_of_years",
|
|
23
|
-
info: { numberOfYears },
|
|
24
|
-
});
|
|
25
|
-
// round to max 10 decimals
|
|
26
|
-
return Math.round((10 + numberOfYears * 1.0512) * 1e10) / 1e10;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function wrapWithThrow<T>(fn: () => T, errorKey?: ErrorKeys) {
|
|
30
|
-
try {
|
|
31
|
-
return fn();
|
|
32
|
-
} catch (error) {
|
|
33
|
-
if (errorKey) {
|
|
34
|
-
throw new SwapKitError(errorKey, error);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function getChainIdentifier<T extends Chain>(chain: T) {
|
|
42
|
-
switch (chain) {
|
|
43
|
-
case Chain.THORChain:
|
|
44
|
-
return `${chain}.RUNE`;
|
|
45
|
-
|
|
46
|
-
case Chain.Cosmos:
|
|
47
|
-
return `${chain}.ATOM`;
|
|
48
|
-
|
|
49
|
-
case Chain.BinanceSmartChain:
|
|
50
|
-
return `${chain}`;
|
|
51
|
-
|
|
52
|
-
default:
|
|
53
|
-
return `${chain}.${chain}`;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const warnings = new Set();
|
|
58
|
-
export function warnOnce(condition: boolean, warning: string) {
|
|
59
|
-
if (condition) {
|
|
60
|
-
if (warnings.has(warning)) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
warnings.add(warning);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export async function getDynamicChainId(chainId: ChainId = ChainId.THORChain) {
|
|
69
|
-
if (![ChainId.THORChainStagenet, ChainId.THORChain, "thorchain-mainnet-v1"].includes(chainId)) {
|
|
70
|
-
return chainId;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
try {
|
|
74
|
-
const rpcUrl =
|
|
75
|
-
SKConfig.get("rpcUrls")[
|
|
76
|
-
chainId !== ChainId.THORChain ? StagenetChain.THORChain : Chain.THORChain
|
|
77
|
-
];
|
|
78
|
-
|
|
79
|
-
const response = await RequestClient.get<{ result: { node_info: { network: string } } }>(
|
|
80
|
-
`${rpcUrl}/status`,
|
|
81
|
-
);
|
|
82
|
-
return response.result.node_info.network as ChainId;
|
|
83
|
-
} catch (_error) {
|
|
84
|
-
return chainId;
|
|
85
|
-
}
|
|
86
|
-
}
|
package/src/utils/plugin.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ProviderName, SwapKitPluginParams } from "../types";
|
|
2
|
-
|
|
3
|
-
export function createPlugin<
|
|
4
|
-
const Name extends string,
|
|
5
|
-
T extends (params: SwapKitPluginParams) => Record<string, unknown>,
|
|
6
|
-
K extends { supportedSwapkitProviders?: (ProviderName | string)[] },
|
|
7
|
-
>({ name, properties, methods }: { name: Name; properties?: K; methods: T }) {
|
|
8
|
-
function plugin(pluginParams: SwapKitPluginParams) {
|
|
9
|
-
return { ...methods(pluginParams), ...properties } as K & ReturnType<T>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return { [name]: plugin } as { [key in Name]: typeof plugin };
|
|
13
|
-
}
|
package/src/utils/tokens.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { match } from "ts-pattern";
|
|
2
|
-
import type * as tokenLists from "../tokens/lists";
|
|
3
|
-
|
|
4
|
-
export type TokenLists = {
|
|
5
|
-
camelot: typeof tokenLists.CamelotV3List;
|
|
6
|
-
caviar: typeof tokenLists.CaviarV1List;
|
|
7
|
-
chainflip: typeof tokenLists.ChainflipList;
|
|
8
|
-
jupiter: typeof tokenLists.JupiterList;
|
|
9
|
-
mayachain: typeof tokenLists.MayaList;
|
|
10
|
-
oneinch: typeof tokenLists.OneInchList;
|
|
11
|
-
openocean: typeof tokenLists.OpenOceanV2List;
|
|
12
|
-
pancakeswap: typeof tokenLists.PancakeswapList;
|
|
13
|
-
pangolin: typeof tokenLists.PangolinList;
|
|
14
|
-
sushiswap: typeof tokenLists.SushiswapList;
|
|
15
|
-
thorchain: typeof tokenLists.ThorchainList;
|
|
16
|
-
traderjoe: typeof tokenLists.TraderjoeV2List;
|
|
17
|
-
uniswap: typeof tokenLists.UniswapV2List;
|
|
18
|
-
uniswapv3: typeof tokenLists.UniswapV3List;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type TokenListName = keyof TokenLists;
|
|
22
|
-
|
|
23
|
-
const defaultLists = [
|
|
24
|
-
"camelot",
|
|
25
|
-
"caviar",
|
|
26
|
-
"chainflip",
|
|
27
|
-
"jupiter",
|
|
28
|
-
"mayachain",
|
|
29
|
-
"oneinch",
|
|
30
|
-
"openocean",
|
|
31
|
-
"pancakeswap",
|
|
32
|
-
"pangolin",
|
|
33
|
-
"sushiswap",
|
|
34
|
-
"thorchain",
|
|
35
|
-
"traderjoe",
|
|
36
|
-
"uniswap",
|
|
37
|
-
"uniswapv3",
|
|
38
|
-
] as TokenListName[];
|
|
39
|
-
|
|
40
|
-
export async function loadTokenLists<T extends TokenListName[]>(pickedLists?: T) {
|
|
41
|
-
const listsToLoad = pickedLists || defaultLists;
|
|
42
|
-
const lists = {} as { [key in T[number]]: TokenLists[key] };
|
|
43
|
-
|
|
44
|
-
for (const list of listsToLoad) {
|
|
45
|
-
const tokenList = await loadTokenList(list);
|
|
46
|
-
|
|
47
|
-
// @ts-expect-error - It's fine to do this because we know the type of the list
|
|
48
|
-
lists[list] = tokenList;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return lists;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function loadTokenList<T extends TokenListName>(listName: T): Promise<TokenLists[T]> {
|
|
55
|
-
const { list } = await match(listName as TokenListName)
|
|
56
|
-
.with("camelot", () => import("../tokens/lists/camelot_v3"))
|
|
57
|
-
.with("caviar", () => import("../tokens/lists/caviar_v1"))
|
|
58
|
-
.with("chainflip", () => import("../tokens/lists/chainflip"))
|
|
59
|
-
.with("jupiter", () => import("../tokens/lists/jupiter"))
|
|
60
|
-
.with("mayachain", () => import("../tokens/lists/mayachain"))
|
|
61
|
-
.with("oneinch", () => import("../tokens/lists/oneinch"))
|
|
62
|
-
.with("openocean", () => import("../tokens/lists/openocean_v2"))
|
|
63
|
-
.with("pancakeswap", () => import("../tokens/lists/pancakeswap"))
|
|
64
|
-
.with("pangolin", () => import("../tokens/lists/pangolin_v1"))
|
|
65
|
-
.with("sushiswap", () => import("../tokens/lists/sushiswap_v2"))
|
|
66
|
-
.with("thorchain", () => import("../tokens/lists/thorchain"))
|
|
67
|
-
.with("traderjoe", () => import("../tokens/lists/traderjoe_v2"))
|
|
68
|
-
.with("uniswap", () => import("../tokens/lists/uniswap_v2"))
|
|
69
|
-
.with("uniswapv3", () => import("../tokens/lists/uniswap_v3"))
|
|
70
|
-
.exhaustive();
|
|
71
|
-
|
|
72
|
-
return list as unknown as TokenLists[T];
|
|
73
|
-
}
|
package/src/utils/validators.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { SKConfig } from "../modules/swapKitConfig";
|
|
2
|
-
import { SwapKitError } from "../modules/swapKitError";
|
|
3
|
-
import type { Chain } from "../types/chains";
|
|
4
|
-
|
|
5
|
-
// Backward compatibility
|
|
6
|
-
const supportedChains = ["TERRA", ...SKConfig.get("chains")];
|
|
7
|
-
|
|
8
|
-
export function validateIdentifier(identifier = "") {
|
|
9
|
-
const uppercasedIdentifier = identifier.toUpperCase();
|
|
10
|
-
|
|
11
|
-
const [chain] = uppercasedIdentifier.split(".") as [Chain, string];
|
|
12
|
-
if (supportedChains.includes(chain)) return true;
|
|
13
|
-
|
|
14
|
-
const [synthChain] = uppercasedIdentifier.split("/") as [Chain, string];
|
|
15
|
-
if (supportedChains.includes(synthChain)) return true;
|
|
16
|
-
|
|
17
|
-
throw new SwapKitError({
|
|
18
|
-
errorKey: "helpers_invalid_identifier",
|
|
19
|
-
info: {
|
|
20
|
-
message: `Invalid identifier: ${identifier}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`,
|
|
21
|
-
identifier,
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function validateTNS(name: string) {
|
|
27
|
-
if (name.length > 30) return false;
|
|
28
|
-
|
|
29
|
-
const regex = /^[a-zA-Z0-9+_-]+$/g;
|
|
30
|
-
|
|
31
|
-
return !!name.match(regex);
|
|
32
|
-
}
|