@paraswap/dex-lib 2.16.2-balancer-v2-buy → 2.16.2
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/build/abi/uniswap-v3/UniswapV3Pool.abi.json +363 -67
- package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +119 -23
- package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +285 -0
- package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +583 -0
- package/build/config.js +5 -5
- package/build/config.js.map +1 -1
- package/build/dex/balancer-v2/balancer-v2.d.ts +8 -2
- package/build/dex/balancer-v2/balancer-v2.js +7 -1
- package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
- package/build/dex/balancer-v2/config.d.ts +7 -2
- package/build/dex/balancer-v2/config.js +30 -20
- package/build/dex/balancer-v2/config.js.map +1 -1
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/uniswap-v3/config.js +38 -0
- package/build/dex/uniswap-v3/config.js.map +1 -1
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +12 -0
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +23 -0
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +1 -0
- package/build/dex/uniswap-v3/types.d.ts +3 -0
- package/build/dex/uniswap-v3/types.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +2 -1
- package/build/dex/uniswap-v3/uniswap-v3-pool.js +3 -2
- package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3.js +6 -3
- package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/uniswap-v3/UniswapV3Pool.abi.json +363 -67
- package/src/abi/uniswap-v3/UniswapV3Quoter.abi.json +119 -23
- package/src/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +285 -0
- package/src/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +583 -0
- package/src/config.ts +5 -6
- package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +7 -14
- package/src/dex/balancer-v2/balancer-v2.ts +4 -1
- package/src/dex/balancer-v2/config.ts +35 -23
- package/src/dex/index.ts +2 -0
- package/src/dex/uniswap-v3/config.ts +46 -0
- package/src/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.ts +28 -0
- package/src/dex/uniswap-v3/types.ts +3 -0
- package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +156 -0
- package/src/dex/uniswap-v3/uniswap-v3-pool.ts +3 -2
- package/src/dex/uniswap-v3/uniswap-v3.ts +7 -3
- package/.idea/aws.xml +0 -17
- package/.idea/codeStyles/Project.xml +0 -19
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/paraswap-dex-lib.iml +0 -9
- package/.idea/runConfigurations.xml +0 -10
- package/.idea/vcs.xml +0 -6
- package/build/abi/woo-fi/WooFeeManager.abi.json +0 -318
- package/build/abi/woo-fi/WooPP.abi.json +0 -548
- package/build/abi/woo-fi/Wooracle.abi.json +0 -260
- package/build/dex/aave-v3/tokens/arbitrum.json +0 -50
- package/build/dex/aave-v3/tokens/avalanche.json +0 -74
- package/build/dex/aave-v3/tokens/fantom.json +0 -62
- package/build/dex/aave-v3/tokens/optimism.json +0 -50
- package/build/dex/aave-v3/tokens/polygon.json +0 -116
- package/build/dex/quickswap-v3.d.ts +0 -21
- package/build/dex/quickswap-v3.js +0 -40
- package/build/dex/quickswap-v3.js.map +0 -1
- package/build/dex/woo-fi/config.d.ts +0 -4
- package/build/dex/woo-fi/config.js +0 -141
- package/build/dex/woo-fi/config.js.map +0 -1
- package/build/dex/woo-fi/constants.d.ts +0 -5
- package/build/dex/woo-fi/constants.js +0 -20
- package/build/dex/woo-fi/constants.js.map +0 -1
- package/build/dex/woo-fi/types.d.ts +0 -48
- package/build/dex/woo-fi/types.js +0 -3
- package/build/dex/woo-fi/types.js.map +0 -1
- package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +0 -14
- package/build/dex/woo-fi/woo-fi-decimal-math.js +0 -42
- package/build/dex/woo-fi/woo-fi-decimal-math.js.map +0 -1
- package/build/dex/woo-fi/woo-fi-math.d.ts +0 -31
- package/build/dex/woo-fi/woo-fi-math.js +0 -300
- package/build/dex/woo-fi/woo-fi-math.js.map +0 -1
- package/build/dex/woo-fi/woo-fi.d.ts +0 -65
- package/build/dex/woo-fi/woo-fi.js +0 -480
- package/build/dex/woo-fi/woo-fi.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"quickswap-v3.js","sourceRoot":"","sources":["../../src/dex/quickswap-v3.ts"],"names":[],"mappings":";;;AAAA,4CAAiD;AAIjD,6CAAyD;AACzD,sDAA+C;AAG/C,MAAM,6BAA6B,GAAmC;IACpE,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE,4CAA4C;CAChE,CAAC;AAWF,MAAa,WACX,SAAQ,sBAAS;IAKjB,YAAY,SAAqB;QAC/B,KAAK,CACH,SAAS,EACT,aAAa,EACb,6BAA6B,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAC7D,CAAC;IACJ,CAAC;IAED,2DAA2D;IACjD,UAAU,CAClB,IAIG,EACH,IAAc;QAEd,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;YACrB,OAAO,IAAI,CAAC;SACb;QAED,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,MAAM,CAClC,CACE,EAAE,KAAK,EAAE,KAAK,EAAwC,EACtD,IAAI,EACJ,KAAK,EACiC,EAAE;YACxC,IAAI,KAAK,KAAK,CAAC,EAAE;gBACf,OAAO;oBACL,KAAK,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC;oBAC7B,KAAK,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC;iBACrC,CAAC;aACH;iBAAM;gBACL,OAAO;oBACL,KAAK,EAAE,CAAC,GAAG,KAAK,EAAE,SAAS,CAAC;oBAC5B,KAAK,EAAE,CAAC,GAAG,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC;iBACjC,CAAC;aACH;QACH,CAAC,EACD,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CACzB,CAAC;QAEF,OAAO,IAAI,KAAK,oBAAQ,CAAC,GAAG;YAC1B,CAAC,CAAC,IAAA,eAAI,EAAC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;YACxC,CAAC,CAAC,IAAA,eAAI,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACzB,CAAC;;AAnDH,kCAoDC;AAhDQ,mBAAO,GAAG,CAAC,aAAa,CAAC,CAAC"}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Adapters = exports.WooFiConfig = void 0;
|
|
4
|
-
const constants_1 = require("../../constants");
|
|
5
|
-
exports.WooFiConfig = {
|
|
6
|
-
WooFi: {
|
|
7
|
-
[constants_1.Network.BSC]: {
|
|
8
|
-
wooPPAddress: '0xbf365Ce9cFcb2d5855521985E351bA3bcf77FD3F',
|
|
9
|
-
wooOracleAddress: '0x6b6fBEc7934b104e81b2046D24A990e03e17afDC',
|
|
10
|
-
wooFeeManagerAddress: '0xaA6c60D638d34261B764fEDB551E50Ab02c34C90',
|
|
11
|
-
wooGuardianAddress: '0x910723e3c6a68276687b50613a1a9e42cc6589b4',
|
|
12
|
-
quoteToken: {
|
|
13
|
-
// USDT
|
|
14
|
-
address: '0x55d398326f99059ff775485246999027b3197955',
|
|
15
|
-
decimals: 18,
|
|
16
|
-
},
|
|
17
|
-
baseTokens: {
|
|
18
|
-
WBNB: {
|
|
19
|
-
address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
|
|
20
|
-
decimals: 18,
|
|
21
|
-
},
|
|
22
|
-
BTCB: {
|
|
23
|
-
address: '0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c',
|
|
24
|
-
decimals: 18,
|
|
25
|
-
},
|
|
26
|
-
ETH: {
|
|
27
|
-
address: '0x2170ed0880ac9a755fd29b2688956bd959f933f8',
|
|
28
|
-
decimals: 18,
|
|
29
|
-
},
|
|
30
|
-
WOO: {
|
|
31
|
-
address: '0x4691937a7508860f876c9c0a2a617e7d9e945d4b',
|
|
32
|
-
decimals: 18,
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
rebateTo: '0xcbb65ad3e64f404b5411486e15561bfb645ce642',
|
|
36
|
-
},
|
|
37
|
-
[constants_1.Network.AVALANCHE]: {
|
|
38
|
-
wooPPAddress: '0x1df3009c57a8B143c6246149F00B090Bce3b8f88',
|
|
39
|
-
wooOracleAddress: '0x25a4d4a094A084c7ad45Ac273cF7D6B6bfae7D4E',
|
|
40
|
-
wooFeeManagerAddress: '0x209102c0D2E34282494114ea76D5251c8e7Ea7ab',
|
|
41
|
-
wooGuardianAddress: '0x58c73f7e102bc6bcdc6b092ef0399b3e06d6b3e3',
|
|
42
|
-
quoteToken: {
|
|
43
|
-
// USDC
|
|
44
|
-
address: '0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
|
|
45
|
-
decimals: 6,
|
|
46
|
-
},
|
|
47
|
-
baseTokens: {
|
|
48
|
-
WAVAX: {
|
|
49
|
-
address: '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7',
|
|
50
|
-
decimals: 18,
|
|
51
|
-
},
|
|
52
|
-
['BTC.b']: {
|
|
53
|
-
address: '0x152b9d0FdC40C096757F570A51E494bd4b943E50',
|
|
54
|
-
decimals: 8,
|
|
55
|
-
},
|
|
56
|
-
['WETH.e']: {
|
|
57
|
-
address: '0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB',
|
|
58
|
-
decimals: 18,
|
|
59
|
-
},
|
|
60
|
-
['WOO.e']: {
|
|
61
|
-
address: '0xaBC9547B534519fF73921b1FBA6E672b5f58D083',
|
|
62
|
-
decimals: 18,
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
rebateTo: '0x1bf4c97384e7bdc609017305edb23fd28c13e76a',
|
|
66
|
-
},
|
|
67
|
-
[constants_1.Network.FANTOM]: {
|
|
68
|
-
wooPPAddress: '0x9503E7517D3C5bc4f9E4A1c6AE4f8B33AC2546f2',
|
|
69
|
-
wooOracleAddress: '0x209102c0D2E34282494114ea76D5251c8e7Ea7ab',
|
|
70
|
-
wooFeeManagerAddress: '0xBE1a0FccCFA9c9065152B7770B918f7C59914E8D',
|
|
71
|
-
wooGuardianAddress: '0x128758d0e909624841AB29D53919646BFBDa5dB2',
|
|
72
|
-
quoteToken: {
|
|
73
|
-
// USDC
|
|
74
|
-
address: '0x04068da6c83afcfa0e13ba15a6696662335d5b75',
|
|
75
|
-
decimals: 6,
|
|
76
|
-
},
|
|
77
|
-
baseTokens: {
|
|
78
|
-
WFTM: {
|
|
79
|
-
address: '0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83',
|
|
80
|
-
decimals: 18,
|
|
81
|
-
},
|
|
82
|
-
BTC: {
|
|
83
|
-
address: '0x321162Cd933E2Be498Cd2267a90534A804051b11',
|
|
84
|
-
decimals: 8,
|
|
85
|
-
},
|
|
86
|
-
ETH: {
|
|
87
|
-
address: '0x74b23882a30290451A17c44f4F05243b6b58C76d',
|
|
88
|
-
decimals: 18,
|
|
89
|
-
},
|
|
90
|
-
WOO: {
|
|
91
|
-
address: '0x6626c47c00F1D87902fc13EECfaC3ed06D5E8D8a',
|
|
92
|
-
decimals: 18,
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
rebateTo: '0xced122f9b99d224675eeda13f0c14639c5633f91',
|
|
96
|
-
},
|
|
97
|
-
[constants_1.Network.POLYGON]: {
|
|
98
|
-
wooPPAddress: '0x7400B665C8f4f3a951a99f1ee9872efb8778723d',
|
|
99
|
-
wooOracleAddress: '0x2Fe5E5D341cFFa606a5d9DA1B6B646a381B0f7ec',
|
|
100
|
-
wooFeeManagerAddress: '0x7214833BE05Ce39f6dCd97668e521162e6C18937',
|
|
101
|
-
wooGuardianAddress: '0xF5d215d9C84778F85746D15762DaF39B9E83a2d6',
|
|
102
|
-
quoteToken: {
|
|
103
|
-
// USDC
|
|
104
|
-
address: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
|
|
105
|
-
decimals: 6,
|
|
106
|
-
},
|
|
107
|
-
baseTokens: {
|
|
108
|
-
WMATIC: {
|
|
109
|
-
address: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
|
|
110
|
-
decimals: 18,
|
|
111
|
-
},
|
|
112
|
-
WBTC: {
|
|
113
|
-
address: '0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6',
|
|
114
|
-
decimals: 8,
|
|
115
|
-
},
|
|
116
|
-
WETH: {
|
|
117
|
-
address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',
|
|
118
|
-
decimals: 18,
|
|
119
|
-
},
|
|
120
|
-
WOO: {
|
|
121
|
-
address: '0x1B815d120B3eF02039Ee11dC2d33DE7aA4a8C603',
|
|
122
|
-
decimals: 18,
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
rebateTo: '0x0c84cd406b8a4e07df9a1b15ef348023a1dcd075',
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
exports.Adapters = {
|
|
130
|
-
[constants_1.Network.BSC]: { [constants_1.SwapSide.SELL]: [{ name: 'BscAdapter01', index: 13 }] },
|
|
131
|
-
[constants_1.Network.AVALANCHE]: {
|
|
132
|
-
[constants_1.SwapSide.SELL]: [{ name: 'AvalancheAdapter01', index: 12 }],
|
|
133
|
-
},
|
|
134
|
-
[constants_1.Network.FANTOM]: {
|
|
135
|
-
[constants_1.SwapSide.SELL]: [{ name: 'FantomAdapter01', index: 8 }],
|
|
136
|
-
},
|
|
137
|
-
[constants_1.Network.POLYGON]: {
|
|
138
|
-
[constants_1.SwapSide.SELL]: [{ name: 'PolygonAdapter02', index: 4 }],
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
//# sourceMappingURL=config.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/dex/woo-fi/config.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NULL_STATE = exports.MIN_CONVERSION_RATE = exports.USD_PRECISION = exports.WOO_FI_GAS_COST = void 0;
|
|
4
|
-
exports.WOO_FI_GAS_COST = 270 * 1000;
|
|
5
|
-
exports.USD_PRECISION = 2;
|
|
6
|
-
exports.MIN_CONVERSION_RATE = 1;
|
|
7
|
-
exports.NULL_STATE = {
|
|
8
|
-
feeRates: {},
|
|
9
|
-
tokenInfos: {},
|
|
10
|
-
tokenStates: {},
|
|
11
|
-
oracleTimestamp: 0n,
|
|
12
|
-
isPaused: false,
|
|
13
|
-
guardian: {
|
|
14
|
-
globalBound: 0n,
|
|
15
|
-
refInfos: {},
|
|
16
|
-
},
|
|
17
|
-
chainlink: { latestRoundDatas: {} },
|
|
18
|
-
wooPPBalances: {},
|
|
19
|
-
};
|
|
20
|
-
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/dex/woo-fi/constants.ts"],"names":[],"mappings":";;;AAEa,QAAA,eAAe,GAAG,GAAG,GAAG,IAAI,CAAC;AAE7B,QAAA,aAAa,GAAG,CAAC,CAAC;AAElB,QAAA,mBAAmB,GAAG,CAAC,CAAC;AAExB,QAAA,UAAU,GAAc;IACnC,QAAQ,EAAE,EAAE;IACZ,UAAU,EAAE,EAAE;IACd,WAAW,EAAE,EAAE;IACf,eAAe,EAAE,EAAE;IACnB,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE;QACR,WAAW,EAAE,EAAE;QACf,QAAQ,EAAE,EAAE;KACb;IACD,SAAS,EAAE,EAAE,gBAAgB,EAAE,EAAE,EAAE;IACnC,aAAa,EAAE,EAAE;CAClB,CAAC"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Address, Token } from '../../types';
|
|
2
|
-
export declare type TokenInfo = {
|
|
3
|
-
reserve: bigint;
|
|
4
|
-
R: bigint;
|
|
5
|
-
threshold: bigint;
|
|
6
|
-
target: bigint;
|
|
7
|
-
lastResetTimestamp: bigint;
|
|
8
|
-
};
|
|
9
|
-
export declare type TokenState = {
|
|
10
|
-
priceNow: bigint;
|
|
11
|
-
spreadNow: bigint;
|
|
12
|
-
coeffNow: bigint;
|
|
13
|
-
};
|
|
14
|
-
export declare type RefInfo = {
|
|
15
|
-
chainlinkRefOracle: Address;
|
|
16
|
-
refPriceFixCoeff: bigint;
|
|
17
|
-
minInputAmount: bigint;
|
|
18
|
-
maxInputAmount: bigint;
|
|
19
|
-
bound: bigint;
|
|
20
|
-
};
|
|
21
|
-
export declare type LatestRoundData = {
|
|
22
|
-
answer: bigint;
|
|
23
|
-
};
|
|
24
|
-
export declare type PoolState = {
|
|
25
|
-
feeRates: Record<Address, bigint>;
|
|
26
|
-
tokenInfos: Record<Address, TokenInfo>;
|
|
27
|
-
tokenStates: Record<Address, TokenState>;
|
|
28
|
-
oracleTimestamp: bigint;
|
|
29
|
-
isPaused: boolean;
|
|
30
|
-
guardian: {
|
|
31
|
-
globalBound: bigint;
|
|
32
|
-
refInfos: Record<Address, RefInfo>;
|
|
33
|
-
};
|
|
34
|
-
chainlink: {
|
|
35
|
-
latestRoundDatas: Record<Address, LatestRoundData>;
|
|
36
|
-
};
|
|
37
|
-
wooPPBalances: Record<Address, bigint>;
|
|
38
|
-
};
|
|
39
|
-
export declare type WooFiData = {};
|
|
40
|
-
export declare type DexParams = {
|
|
41
|
-
wooPPAddress: Address;
|
|
42
|
-
wooOracleAddress: Address;
|
|
43
|
-
wooFeeManagerAddress: Address;
|
|
44
|
-
wooGuardianAddress: Address;
|
|
45
|
-
quoteToken: Token;
|
|
46
|
-
baseTokens: Record<string, Token>;
|
|
47
|
-
rebateTo: Address;
|
|
48
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dex/woo-fi/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
declare class WooFiDecimalMath {
|
|
2
|
-
readonly ONE: bigint;
|
|
3
|
-
readonly TWO: bigint;
|
|
4
|
-
readonly ONE2: bigint;
|
|
5
|
-
mulFloor(target: bigint, d: bigint): bigint;
|
|
6
|
-
mulCeil(target: bigint, d: bigint): bigint;
|
|
7
|
-
divFloor(target: bigint, d: bigint): bigint;
|
|
8
|
-
divCeil(target: bigint, d: bigint): bigint;
|
|
9
|
-
reciprocalFloor(target: bigint): bigint;
|
|
10
|
-
reciprocalCeil(target: bigint): bigint;
|
|
11
|
-
private _divCeil;
|
|
12
|
-
}
|
|
13
|
-
export declare const wooFiDecimalMath: WooFiDecimalMath;
|
|
14
|
-
export {};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.wooFiDecimalMath = void 0;
|
|
4
|
-
const bigint_constants_1 = require("../../bigint-constants");
|
|
5
|
-
class WooFiDecimalMath {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.ONE = bigint_constants_1.BI_POWS[18];
|
|
8
|
-
this.TWO = 2n * bigint_constants_1.BI_POWS[18];
|
|
9
|
-
this.ONE2 = bigint_constants_1.BI_POWS[36];
|
|
10
|
-
}
|
|
11
|
-
mulFloor(target, d) {
|
|
12
|
-
// target.mul(d) / (10**18);
|
|
13
|
-
return (target * d) / bigint_constants_1.BI_POWS[18];
|
|
14
|
-
}
|
|
15
|
-
mulCeil(target, d) {
|
|
16
|
-
// _divCeil(target.mul(d), 10 ** 18);
|
|
17
|
-
return this._divCeil(target * d, bigint_constants_1.BI_POWS[18]);
|
|
18
|
-
}
|
|
19
|
-
divFloor(target, d) {
|
|
20
|
-
// target.mul(10 ** 18).div(d);
|
|
21
|
-
return (target * bigint_constants_1.BI_POWS[18]) / d;
|
|
22
|
-
}
|
|
23
|
-
divCeil(target, d) {
|
|
24
|
-
// _divCeil(target.mul(10 ** 18), d);
|
|
25
|
-
return this._divCeil(target * bigint_constants_1.BI_POWS[18], d);
|
|
26
|
-
}
|
|
27
|
-
reciprocalFloor(target) {
|
|
28
|
-
// uint256(10 ** 36).div(target);
|
|
29
|
-
return bigint_constants_1.BI_POWS[36] / target;
|
|
30
|
-
}
|
|
31
|
-
reciprocalCeil(target) {
|
|
32
|
-
// _divCeil(uint256(10 ** 36), target);
|
|
33
|
-
return this._divCeil(bigint_constants_1.BI_POWS[36], target);
|
|
34
|
-
}
|
|
35
|
-
_divCeil(a, b) {
|
|
36
|
-
const quotient = a / b;
|
|
37
|
-
const remainder = a - quotient * b;
|
|
38
|
-
return remainder > 0n ? quotient + 1n : quotient;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.wooFiDecimalMath = new WooFiDecimalMath();
|
|
42
|
-
//# sourceMappingURL=woo-fi-decimal-math.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"woo-fi-decimal-math.js","sourceRoot":"","sources":["../../../src/dex/woo-fi/woo-fi-decimal-math.ts"],"names":[],"mappings":";;;AAAA,6DAAiD;AAEjD,MAAM,gBAAgB;IAAtB;QACW,QAAG,GAAG,0BAAO,CAAC,EAAE,CAAC,CAAC;QAClB,QAAG,GAAG,EAAE,GAAG,0BAAO,CAAC,EAAE,CAAC,CAAC;QACvB,SAAI,GAAG,0BAAO,CAAC,EAAE,CAAC,CAAC;IAqC9B,CAAC;IAnCC,QAAQ,CAAC,MAAc,EAAE,CAAS;QAChC,4BAA4B;QAC5B,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,0BAAO,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC;IAED,OAAO,CAAC,MAAc,EAAE,CAAS;QAC/B,qCAAqC;QACrC,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,0BAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IAChD,CAAC;IAED,QAAQ,CAAC,MAAc,EAAE,CAAS;QAChC,+BAA+B;QAC/B,OAAO,CAAC,MAAM,GAAG,0BAAO,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC;IAED,OAAO,CAAC,MAAc,EAAE,CAAS;QAC/B,qCAAqC;QACrC,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,0BAAO,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAChD,CAAC;IAED,eAAe,CAAC,MAAc;QAC5B,iCAAiC;QACjC,OAAO,0BAAO,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC;IAC9B,CAAC;IAED,cAAc,CAAC,MAAc;QAC3B,uCAAuC;QACvC,OAAO,IAAI,CAAC,QAAQ,CAAC,0BAAO,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC;IAEO,QAAQ,CAAC,CAAS,EAAE,CAAS;QACnC,MAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,CAAC;QACvB,MAAM,SAAS,GAAG,CAAC,GAAG,QAAQ,GAAG,CAAC,CAAC;QACnC,OAAO,SAAS,GAAG,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;IACnD,CAAC;CACF;AAEY,QAAA,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { PoolState, TokenInfo } from './types';
|
|
2
|
-
import { wooFiDecimalMath } from './woo-fi-decimal-math';
|
|
3
|
-
import { Address, Logger } from '../../types';
|
|
4
|
-
export declare class WooFiMath {
|
|
5
|
-
private readonly logger;
|
|
6
|
-
private readonly _quoteToken;
|
|
7
|
-
readonly dMath: typeof wooFiDecimalMath;
|
|
8
|
-
private readonly _MIN_INPUT_DEFAULT;
|
|
9
|
-
private readonly _MAX_INPUT_DEFAULT;
|
|
10
|
-
state: PoolState;
|
|
11
|
-
constructor(logger: Logger, _quoteToken: Address);
|
|
12
|
-
querySellBase(baseToken: Address, baseAmounts: bigint[]): bigint[] | null;
|
|
13
|
-
querySellQuote(baseToken: Address, quoteAmounts: bigint[]): bigint[] | null;
|
|
14
|
-
protected _takeFee(amounts: bigint[], feeRate: bigint): bigint[];
|
|
15
|
-
protected _getQuoteAmountSellBase(baseToken: Address, baseAmounts: bigint[]): bigint[];
|
|
16
|
-
protected _getBaseAmountSellQuote(baseToken: string, quoteAmounts: bigint[]): bigint[];
|
|
17
|
-
protected _getBoughtAmount(baseInfo: TokenInfo, quoteInfo: TokenInfo, p: bigint, k: bigint, isSellBase: boolean): {
|
|
18
|
-
baseBought: bigint;
|
|
19
|
-
quoteBought: bigint;
|
|
20
|
-
};
|
|
21
|
-
protected _getBaseAmountLowBaseSide(p: bigint, k: bigint, r: bigint, quoteAmount: bigint): bigint;
|
|
22
|
-
protected _getQuoteAmountLowQuoteSide(p: bigint, k: bigint, r: bigint, baseAmount: bigint): bigint;
|
|
23
|
-
protected _getBaseAmountLowQuoteSide(p: bigint, k: bigint, r: bigint, quoteAmount: bigint): bigint;
|
|
24
|
-
protected _getQuoteAmountLowBaseSide(p: bigint, k: bigint, r: bigint, baseAmount: bigint): bigint;
|
|
25
|
-
protected _autoUpdate(quoteTokenAddress: string, baseTokenAddress: string): void;
|
|
26
|
-
private _checkInputAmount;
|
|
27
|
-
private _checkSwapAmount;
|
|
28
|
-
checkSwapPrice(price: bigint, fromToken: Address, toToken: Address): void;
|
|
29
|
-
private _refPrice;
|
|
30
|
-
private _boundForTokens;
|
|
31
|
-
}
|
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WooFiMath = void 0;
|
|
4
|
-
const woo_fi_decimal_math_1 = require("./woo-fi-decimal-math");
|
|
5
|
-
const bigint_constants_1 = require("../../bigint-constants");
|
|
6
|
-
const utils_1 = require("../../utils");
|
|
7
|
-
const constants_1 = require("./constants");
|
|
8
|
-
const constants_2 = require("../../constants");
|
|
9
|
-
function handleMathError(e, logger) {
|
|
10
|
-
if (e instanceof Error && e.message.startsWith('WooGuardian:')) {
|
|
11
|
-
logger.warn('WooFi Guardian check Error:', e);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
logger.error('Unexpected error in WooFi math:', e);
|
|
15
|
-
}
|
|
16
|
-
class WooFiMath {
|
|
17
|
-
constructor(logger, _quoteToken) {
|
|
18
|
-
this.logger = logger;
|
|
19
|
-
this._quoteToken = _quoteToken;
|
|
20
|
-
// dMath = decimalMath
|
|
21
|
-
this.dMath = woo_fi_decimal_math_1.wooFiDecimalMath;
|
|
22
|
-
this._MIN_INPUT_DEFAULT = bigint_constants_1.BI_POWS[16]; // 0.01 xToken
|
|
23
|
-
this._MAX_INPUT_DEFAULT = bigint_constants_1.BI_POWS[20]; // 100 xToken
|
|
24
|
-
this.state = constants_1.NULL_STATE;
|
|
25
|
-
}
|
|
26
|
-
querySellBase(baseToken, baseAmounts) {
|
|
27
|
-
try {
|
|
28
|
-
const _baseAmounts = baseAmounts.map(baseAmount => {
|
|
29
|
-
try {
|
|
30
|
-
this._checkInputAmount(baseToken, baseAmount);
|
|
31
|
-
return baseAmount;
|
|
32
|
-
}
|
|
33
|
-
catch (e) {
|
|
34
|
-
if (e instanceof Error &&
|
|
35
|
-
e.message.includes('WooGuardian: inputAmount')) {
|
|
36
|
-
return 0n;
|
|
37
|
-
}
|
|
38
|
-
throw e;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
this._autoUpdate(this._quoteToken, baseToken);
|
|
42
|
-
const quoteAmounts = this._getQuoteAmountSellBase(baseToken, _baseAmounts);
|
|
43
|
-
const feeRate = this.state.feeRates[baseToken];
|
|
44
|
-
return this._takeFee(quoteAmounts, feeRate);
|
|
45
|
-
}
|
|
46
|
-
catch (e) {
|
|
47
|
-
handleMathError(e, this.logger);
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
querySellQuote(baseToken, quoteAmounts) {
|
|
52
|
-
try {
|
|
53
|
-
let _quoteAmounts = quoteAmounts.map(quoteAmount => {
|
|
54
|
-
try {
|
|
55
|
-
this._checkInputAmount(this._quoteToken, quoteAmount);
|
|
56
|
-
return quoteAmount;
|
|
57
|
-
}
|
|
58
|
-
catch (e) {
|
|
59
|
-
if (e instanceof Error &&
|
|
60
|
-
e.message.startsWith('Error message: WooGuardian: inputAmount')) {
|
|
61
|
-
return 0n;
|
|
62
|
-
}
|
|
63
|
-
throw e;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
this._autoUpdate(this._quoteToken, baseToken);
|
|
67
|
-
const feeRate = this.state.feeRates[baseToken];
|
|
68
|
-
_quoteAmounts = this._takeFee(_quoteAmounts, feeRate);
|
|
69
|
-
return this._getBaseAmountSellQuote(baseToken, _quoteAmounts);
|
|
70
|
-
}
|
|
71
|
-
catch (e) {
|
|
72
|
-
handleMathError(e, this.logger);
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
_takeFee(amounts, feeRate) {
|
|
77
|
-
return amounts.map(amount => {
|
|
78
|
-
const lpFee = this.dMath.mulCeil(amount, feeRate);
|
|
79
|
-
return amount === 0n ? 0n : amount - lpFee;
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
_getQuoteAmountSellBase(baseToken, baseAmounts) {
|
|
83
|
-
const quoteInfo = this.state.tokenInfos[this._quoteToken];
|
|
84
|
-
const baseInfo = this.state.tokenInfos[baseToken];
|
|
85
|
-
let { priceNow: p, spreadNow: s, coeffNow: k, } = this.state.tokenStates[baseToken];
|
|
86
|
-
this.checkSwapPrice(p, baseToken, this._quoteToken);
|
|
87
|
-
// price: p * (1 - s / 2)
|
|
88
|
-
p = this.dMath.mulFloor(p, this.dMath.ONE - this.dMath.divCeil(s, this.dMath.TWO));
|
|
89
|
-
const { baseBought, quoteBought } = this._getBoughtAmount(baseInfo, quoteInfo, p, k, true);
|
|
90
|
-
return baseAmounts.map(baseAmount => {
|
|
91
|
-
if (baseAmount === 0n)
|
|
92
|
-
return 0n;
|
|
93
|
-
let quoteAmount;
|
|
94
|
-
if (baseBought > 0n) {
|
|
95
|
-
const quoteSold = this._getQuoteAmountLowBaseSide(p, k, baseInfo.R, baseBought);
|
|
96
|
-
if (baseAmount > baseBought) {
|
|
97
|
-
const newBaseSold = baseAmount - baseBought;
|
|
98
|
-
quoteAmount =
|
|
99
|
-
quoteSold +
|
|
100
|
-
this._getQuoteAmountLowQuoteSide(p, k, this.dMath.ONE, newBaseSold);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
const newBaseBought = baseBought - baseAmount;
|
|
104
|
-
quoteAmount =
|
|
105
|
-
quoteSold -
|
|
106
|
-
this._getQuoteAmountLowBaseSide(p, k, baseInfo.R, newBaseBought);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
const baseSold = this._getBaseAmountLowQuoteSide(p, k, this.dMath.ONE, quoteBought);
|
|
111
|
-
const newBaseSold = baseAmount + baseSold;
|
|
112
|
-
const newQuoteBought = this._getQuoteAmountLowQuoteSide(p, k, this.dMath.ONE, newBaseSold);
|
|
113
|
-
quoteAmount =
|
|
114
|
-
newQuoteBought > quoteBought ? newQuoteBought - quoteBought : 0n;
|
|
115
|
-
}
|
|
116
|
-
this._checkSwapAmount(baseToken, this._quoteToken, baseAmount, quoteAmount);
|
|
117
|
-
if (quoteAmount > this.state.wooPPBalances[this._quoteToken]) {
|
|
118
|
-
// require(quoteAmount <= IERC20(quoteToken).balanceOf(address(this)), 'WooPP: INSUFF_QUOTE');
|
|
119
|
-
return 0n;
|
|
120
|
-
}
|
|
121
|
-
return quoteAmount;
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
_getBaseAmountSellQuote(baseToken, quoteAmounts) {
|
|
125
|
-
const quoteInfo = this.state.tokenInfos[this._quoteToken];
|
|
126
|
-
const baseInfo = this.state.tokenInfos[baseToken];
|
|
127
|
-
let { priceNow: p, spreadNow: s, coeffNow: k, } = this.state.tokenStates[baseToken];
|
|
128
|
-
this.checkSwapPrice(p, baseToken, this._quoteToken);
|
|
129
|
-
// price: p * (1 + s / 2)
|
|
130
|
-
p = this.dMath.mulCeil(p, this.dMath.ONE + this.dMath.divCeil(s, this.dMath.TWO));
|
|
131
|
-
const { baseBought, quoteBought } = this._getBoughtAmount(baseInfo, quoteInfo, p, k, false);
|
|
132
|
-
return quoteAmounts.map(quoteAmount => {
|
|
133
|
-
if (quoteAmount === 0n)
|
|
134
|
-
return 0n;
|
|
135
|
-
let baseAmount;
|
|
136
|
-
if (quoteBought > 0) {
|
|
137
|
-
const baseSold = this._getBaseAmountLowQuoteSide(p, k, baseInfo.R, quoteBought);
|
|
138
|
-
if (quoteAmount > quoteBought) {
|
|
139
|
-
const newQuoteSold = quoteAmount - quoteBought;
|
|
140
|
-
baseAmount =
|
|
141
|
-
baseSold +
|
|
142
|
-
this._getBaseAmountLowBaseSide(p, k, this.dMath.ONE, newQuoteSold);
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
const newQuoteBought = quoteBought - quoteAmount;
|
|
146
|
-
baseAmount =
|
|
147
|
-
baseSold -
|
|
148
|
-
this._getBaseAmountLowQuoteSide(p, k, baseInfo.R, newQuoteBought);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
const quoteSold = this._getQuoteAmountLowBaseSide(p, k, this.dMath.ONE, baseBought);
|
|
153
|
-
const newQuoteSold = quoteAmount + quoteSold;
|
|
154
|
-
const newBaseBought = this._getBaseAmountLowBaseSide(p, k, this.dMath.ONE, newQuoteSold);
|
|
155
|
-
baseAmount =
|
|
156
|
-
newBaseBought > baseBought ? newBaseBought - baseBought : 0n;
|
|
157
|
-
}
|
|
158
|
-
this._checkSwapAmount(this._quoteToken, baseToken, quoteAmount, baseAmount);
|
|
159
|
-
if (baseAmount > this.state.wooPPBalances[baseToken]) {
|
|
160
|
-
// require(baseAmount <= IERC20(baseToken).balanceOf(address(this)), 'WooPP: INSUFF_BASE');
|
|
161
|
-
return 0n;
|
|
162
|
-
}
|
|
163
|
-
return baseAmount;
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
_getBoughtAmount(baseInfo, quoteInfo, p, k, isSellBase) {
|
|
167
|
-
let baseBought = 0n;
|
|
168
|
-
let quoteBought = 0n;
|
|
169
|
-
let baseSold = 0n;
|
|
170
|
-
if (baseInfo.reserve < baseInfo.target) {
|
|
171
|
-
baseBought = baseInfo.target - baseInfo.reserve;
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
baseSold = baseInfo.reserve - baseInfo.target;
|
|
175
|
-
}
|
|
176
|
-
let quoteSold = 0n;
|
|
177
|
-
if (quoteInfo.reserve < quoteInfo.target) {
|
|
178
|
-
quoteBought = quoteInfo.target - quoteInfo.reserve;
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
quoteSold = quoteInfo.reserve - quoteInfo.target;
|
|
182
|
-
}
|
|
183
|
-
if (this.dMath.mulCeil(baseSold, p) > quoteSold) {
|
|
184
|
-
baseSold = baseSold - this.dMath.divFloor(quoteSold, p);
|
|
185
|
-
quoteSold = 0n;
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
quoteSold = quoteSold - this.dMath.mulCeil(baseSold, p);
|
|
189
|
-
baseSold = 0n;
|
|
190
|
-
}
|
|
191
|
-
const virtualBaseBought = this._getBaseAmountLowBaseSide(p, k, this.dMath.ONE, quoteSold);
|
|
192
|
-
if (isSellBase === virtualBaseBought < baseBought) {
|
|
193
|
-
baseBought = virtualBaseBought;
|
|
194
|
-
}
|
|
195
|
-
const virtualQuoteBought = this._getQuoteAmountLowQuoteSide(p, k, this.dMath.ONE, baseSold);
|
|
196
|
-
if (isSellBase === virtualQuoteBought > quoteBought) {
|
|
197
|
-
quoteBought = virtualQuoteBought;
|
|
198
|
-
}
|
|
199
|
-
return { baseBought, quoteBought };
|
|
200
|
-
}
|
|
201
|
-
_getBaseAmountLowBaseSide(p, k, r, quoteAmount) {
|
|
202
|
-
// priceFactor = 1 + k * quoteAmount * r;
|
|
203
|
-
const priceFactor = this.dMath.ONE +
|
|
204
|
-
this.dMath.mulCeil(this.dMath.mulCeil(k, quoteAmount), r);
|
|
205
|
-
// quoteAmount / p / priceFactor;
|
|
206
|
-
return this.dMath.divFloor(this.dMath.divFloor(quoteAmount, p), priceFactor);
|
|
207
|
-
}
|
|
208
|
-
_getQuoteAmountLowQuoteSide(p, k, r, baseAmount) {
|
|
209
|
-
// priceFactor = 1 + k * baseAmount * p * r;
|
|
210
|
-
const priceFactor = this.dMath.ONE +
|
|
211
|
-
this.dMath.mulCeil(this.dMath.mulCeil(this.dMath.mulCeil(k, baseAmount), p), r);
|
|
212
|
-
// baseAmount * p / priceFactor;
|
|
213
|
-
return this.dMath.divFloor(this.dMath.mulFloor(baseAmount, p), priceFactor);
|
|
214
|
-
}
|
|
215
|
-
_getBaseAmountLowQuoteSide(p, k, r, quoteAmount) {
|
|
216
|
-
// priceFactor = (1 - k * quoteAmount * r);
|
|
217
|
-
const priceFactor = this.dMath.ONE -
|
|
218
|
-
this.dMath.mulFloor(this.dMath.mulFloor(k, quoteAmount), r);
|
|
219
|
-
// quoteAmount / p / priceFactor;
|
|
220
|
-
return this.dMath.divFloor(this.dMath.divFloor(quoteAmount, p), priceFactor);
|
|
221
|
-
}
|
|
222
|
-
_getQuoteAmountLowBaseSide(p, k, r, baseAmount) {
|
|
223
|
-
// priceFactor = 1 - k * baseAmount * p * r;
|
|
224
|
-
const priceFactor = this.dMath.ONE -
|
|
225
|
-
this.dMath.mulFloor(this.dMath.mulFloor(this.dMath.mulFloor(k, baseAmount), p), r);
|
|
226
|
-
// baseAmount * p / priceFactor;
|
|
227
|
-
return this.dMath.divFloor(this.dMath.mulFloor(baseAmount, p), priceFactor);
|
|
228
|
-
}
|
|
229
|
-
_autoUpdate(quoteTokenAddress, baseTokenAddress) {
|
|
230
|
-
const quoteInfo = this.state.tokenInfos[quoteTokenAddress];
|
|
231
|
-
const baseInfo = this.state.tokenInfos[baseTokenAddress];
|
|
232
|
-
if (this.state.oracleTimestamp !== baseInfo.lastResetTimestamp) {
|
|
233
|
-
baseInfo.target =
|
|
234
|
-
baseInfo.threshold > baseInfo.reserve
|
|
235
|
-
? baseInfo.threshold
|
|
236
|
-
: baseInfo.reserve;
|
|
237
|
-
baseInfo.lastResetTimestamp = this.state.oracleTimestamp;
|
|
238
|
-
}
|
|
239
|
-
if (this.state.oracleTimestamp !== quoteInfo.lastResetTimestamp) {
|
|
240
|
-
quoteInfo.target =
|
|
241
|
-
quoteInfo.threshold > quoteInfo.reserve
|
|
242
|
-
? quoteInfo.threshold
|
|
243
|
-
: quoteInfo.reserve;
|
|
244
|
-
quoteInfo.lastResetTimestamp = this.state.oracleTimestamp;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
_checkInputAmount(token, inputAmount) {
|
|
248
|
-
(0, utils_1._require)(inputAmount < bigint_constants_1.BI_MAX_UINT96, `WooGuardian: inputAmount_uint96_OVERFLOW in _checkInputAmount for ${token}`);
|
|
249
|
-
const info = this.state.guardian.refInfos[token];
|
|
250
|
-
const minInputAmount = info.minInputAmount != 0n ? info.minInputAmount : this._MIN_INPUT_DEFAULT;
|
|
251
|
-
const maxInputAmount = info.maxInputAmount != 0n ? info.maxInputAmount : this._MAX_INPUT_DEFAULT;
|
|
252
|
-
(0, utils_1._require)(inputAmount >= minInputAmount, `WooGuardian: inputAmount_LTM in _checkInputAmount for ${token}`);
|
|
253
|
-
(0, utils_1._require)(inputAmount <= maxInputAmount, `WooGuardian: inputAmount_GTM in _checkInputAmount for ${token}`);
|
|
254
|
-
}
|
|
255
|
-
_checkSwapAmount(fromToken, toToken, fromAmount, toAmount) {
|
|
256
|
-
if (this.state.guardian.refInfos[fromToken].chainlinkRefOracle ===
|
|
257
|
-
constants_2.NULL_ADDRESS ||
|
|
258
|
-
this.state.guardian.refInfos[toToken].chainlinkRefOracle === constants_2.NULL_ADDRESS) {
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
const refPrice = this._refPrice(fromToken, toToken);
|
|
262
|
-
const refToAmount = this.dMath.mulFloor(fromAmount, refPrice);
|
|
263
|
-
const bound = this._boundForTokens(fromToken, toToken);
|
|
264
|
-
(0, utils_1._require)(this.dMath.mulFloor(refToAmount, bigint_constants_1.BI_POWS[18] - bound) <= toAmount &&
|
|
265
|
-
toAmount <= this.dMath.mulCeil(refToAmount, bigint_constants_1.BI_POWS[18] + bound), `WooGuardian: TO_AMOUNT_UNRELIABLE in _checkSwapAmount for ${toToken}`);
|
|
266
|
-
}
|
|
267
|
-
checkSwapPrice(price, fromToken, toToken) {
|
|
268
|
-
if (this.state.guardian.refInfos[fromToken].chainlinkRefOracle ===
|
|
269
|
-
constants_2.NULL_ADDRESS ||
|
|
270
|
-
this.state.guardian.refInfos[toToken].chainlinkRefOracle === constants_2.NULL_ADDRESS) {
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
const refPrice = this._refPrice(fromToken, toToken);
|
|
274
|
-
const bound = this._boundForTokens(fromToken, toToken);
|
|
275
|
-
(0, utils_1._require)(this.dMath.mulFloor(refPrice, bigint_constants_1.BI_POWS[18] - bound) <= price &&
|
|
276
|
-
price <= this.dMath.mulCeil(refPrice, bigint_constants_1.BI_POWS[18] + bound), `WooGuardian: PRICE_UNRELIABLE in checkSwapPrice fromToken=${fromToken} and toToken=${toToken}`);
|
|
277
|
-
}
|
|
278
|
-
_refPrice(fromToken, toToken) {
|
|
279
|
-
const baseInfo = this.state.guardian.refInfos[fromToken];
|
|
280
|
-
const quoteInfo = this.state.guardian.refInfos[toToken];
|
|
281
|
-
(0, utils_1._require)(baseInfo.chainlinkRefOracle !== constants_2.NULL_ADDRESS, `WooGuardian: fromToken_RefOracle_INVALID: ${fromToken}`);
|
|
282
|
-
(0, utils_1._require)(quoteInfo.chainlinkRefOracle !== constants_2.NULL_ADDRESS, `WooGuardian: toToken_RefOracle_INVALID: ${toToken}`);
|
|
283
|
-
const { answer: rawBaseRefPrice } = this.state.chainlink.latestRoundDatas[baseInfo.chainlinkRefOracle];
|
|
284
|
-
(0, utils_1._require)(rawBaseRefPrice >= 0, `WooGuardian: INVALID_CHAINLINK_PRICE in _refPrice for ${fromToken}`);
|
|
285
|
-
const { answer: rawQuoteRefPrice } = this.state.chainlink.latestRoundDatas[quoteInfo.chainlinkRefOracle];
|
|
286
|
-
(0, utils_1._require)(rawQuoteRefPrice >= 0, `WooGuardian: INVALID_CHAINLINK_QUOTE_PRICE in _refPrice for ${toToken}`);
|
|
287
|
-
const baseRefPrice = rawBaseRefPrice * baseInfo.refPriceFixCoeff;
|
|
288
|
-
const quoteRefPrice = rawQuoteRefPrice * quoteInfo.refPriceFixCoeff;
|
|
289
|
-
return this.dMath.divFloor(baseRefPrice, quoteRefPrice);
|
|
290
|
-
}
|
|
291
|
-
_boundForTokens(token1, token2) {
|
|
292
|
-
const info1 = this.state.guardian.refInfos[token1];
|
|
293
|
-
const bound1 = info1.bound !== 0n ? info1.bound : this.state.guardian.globalBound;
|
|
294
|
-
const info2 = this.state.guardian.refInfos[token2];
|
|
295
|
-
const bound2 = info2.bound != 0n ? info2.bound : this.state.guardian.globalBound;
|
|
296
|
-
return bound1 > bound2 ? bound1 : bound2;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
exports.WooFiMath = WooFiMath;
|
|
300
|
-
//# sourceMappingURL=woo-fi-math.js.map
|