@paraswap/dex-lib 2.13.0 → 2.14.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.
Files changed (74) hide show
  1. package/build/config.js +5 -23
  2. package/build/config.js.map +1 -1
  3. package/build/dex/curve-v1/config.js +0 -2
  4. package/build/dex/curve-v1/config.js.map +1 -1
  5. package/build/dex/curve-v1/curve-v1.js +0 -2
  6. package/build/dex/curve-v1/curve-v1.js.map +1 -1
  7. package/build/dex/curve-v1/types.d.ts +0 -1
  8. package/build/dex/curve-v1/types.js.map +1 -1
  9. package/build/dex/index.js +2 -2
  10. package/build/dex/index.js.map +1 -1
  11. package/build/dex/simple-exchange.d.ts +0 -1
  12. package/build/dex/simple-exchange.js +1 -3
  13. package/build/dex/simple-exchange.js.map +1 -1
  14. package/build/lib/decoders.d.ts +1 -2
  15. package/build/lib/decoders.js +1 -8
  16. package/build/lib/decoders.js.map +1 -1
  17. package/build/lib/multi-wrapper.d.ts +1 -2
  18. package/build/lib/multi-wrapper.js.map +1 -1
  19. package/build/lib/tokens/balancer-fetcher.js +5 -4
  20. package/build/lib/tokens/balancer-fetcher.js.map +1 -1
  21. package/build/lib/tokens/utils.d.ts +2 -2
  22. package/build/lib/tokens/utils.js +1 -1
  23. package/build/lib/tokens/utils.js.map +1 -1
  24. package/build/types.d.ts +0 -3
  25. package/dex-template/__DexName__-e2e.test.ts.template +0 -1
  26. package/dex-template/__DexName__-events.test.ts.template +0 -1
  27. package/dex-template/__DexName__-integration.test.ts.template +0 -1
  28. package/dex-template/__DexName__-pool.ts.template +5 -8
  29. package/package.json +1 -1
  30. package/scripts/generate-bytecode.ts +0 -2
  31. package/src/abi/woo-fi/WooFeeManager.abi.json +318 -0
  32. package/src/abi/{woo-fi-v2/WooPPV2.abi.json → woo-fi/WooPP.abi.json} +169 -201
  33. package/src/abi/{woo-fi-v2/WooOracleV2.abi.json → woo-fi/Wooracle.abi.json} +50 -148
  34. package/src/config.ts +5 -27
  35. package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +1 -0
  36. package/src/dex/curve-v1/config.ts +0 -2
  37. package/src/dex/curve-v1/curve-v1-e2e.test.ts +37 -18
  38. package/src/dex/curve-v1/curve-v1.ts +0 -2
  39. package/src/dex/curve-v1/types.ts +0 -1
  40. package/src/dex/index.ts +2 -2
  41. package/src/dex/simple-exchange.ts +1 -4
  42. package/src/dex/woo-fi/config.ts +141 -0
  43. package/src/dex/woo-fi/constants.ts +21 -0
  44. package/src/dex/woo-fi/types.ts +55 -0
  45. package/src/dex/woo-fi/woo-fi-decimal-math.ts +45 -0
  46. package/src/dex/woo-fi/woo-fi-e2e.test.ts +183 -0
  47. package/src/dex/woo-fi/woo-fi-integration.test.ts +416 -0
  48. package/src/dex/woo-fi/woo-fi-math.ts +527 -0
  49. package/src/dex/woo-fi/woo-fi.ts +693 -0
  50. package/src/lib/decoders.ts +1 -12
  51. package/src/lib/multi-wrapper.ts +1 -2
  52. package/src/lib/tokens/balancer-fetcher.ts +6 -5
  53. package/src/lib/tokens/utils.ts +3 -5
  54. package/src/types.ts +0 -4
  55. package/tests/constants-e2e.ts +9 -9
  56. package/tests/tenderly-simulation.ts +1 -1
  57. package/tests/utils-e2e.ts +0 -2
  58. package/tests/utils.ts +0 -2
  59. package/src/abi/woo-fi-v2/IntegrationHelper.abi.json +0 -116
  60. package/src/dex/woo-fi-v2/config.ts +0 -87
  61. package/src/dex/woo-fi-v2/constants.ts +0 -22
  62. package/src/dex/woo-fi-v2/decoders.ts +0 -45
  63. package/src/dex/woo-fi-v2/types.ts +0 -63
  64. package/src/dex/woo-fi-v2/utils.ts +0 -19
  65. package/src/dex/woo-fi-v2/woo-fi-v2-e2e.test.ts +0 -216
  66. package/src/dex/woo-fi-v2/woo-fi-v2-integration.test.ts +0 -495
  67. package/src/dex/woo-fi-v2/woo-fi-v2-math.ts +0 -195
  68. package/src/dex/woo-fi-v2/woo-fi-v2-pool.ts +0 -112
  69. package/src/dex/woo-fi-v2/woo-fi-v2.ts +0 -487
  70. package/src/lib/log-messages-suppressor.ts +0 -173
  71. package/src/lib/stateful-rpc-poller/state-polling-manager.ts +0 -320
  72. package/src/lib/stateful-rpc-poller/stateful-rpc-poller.ts +0 -604
  73. package/src/lib/stateful-rpc-poller/types.ts +0 -66
  74. package/src/lib/stateful-rpc-poller/utils.ts +0 -23
@@ -0,0 +1,141 @@
1
+ import { DexParams } from './types';
2
+ import { DexConfigMap, AdapterMappings } from '../../types';
3
+ import { Network, SwapSide } from '../../constants';
4
+
5
+ export const WooFiConfig: DexConfigMap<DexParams> = {
6
+ WooFi: {
7
+ [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
+ [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
+ [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
+ [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
+
130
+ export const Adapters: Record<number, AdapterMappings> = {
131
+ [Network.BSC]: { [SwapSide.SELL]: [{ name: 'BscAdapter01', index: 13 }] },
132
+ [Network.AVALANCHE]: {
133
+ [SwapSide.SELL]: [{ name: 'AvalancheAdapter01', index: 12 }],
134
+ },
135
+ [Network.FANTOM]: {
136
+ [SwapSide.SELL]: [{ name: 'FantomAdapter01', index: 8 }],
137
+ },
138
+ [Network.POLYGON]: {
139
+ [SwapSide.SELL]: [{ name: 'PolygonAdapter02', index: 4 }],
140
+ },
141
+ };
@@ -0,0 +1,21 @@
1
+ import { PoolState } from './types';
2
+
3
+ export const WOO_FI_GAS_COST = 270 * 1000;
4
+
5
+ export const USD_PRECISION = 2;
6
+
7
+ export const MIN_CONVERSION_RATE = 1;
8
+
9
+ export const NULL_STATE: PoolState = {
10
+ feeRates: {},
11
+ tokenInfos: {},
12
+ tokenStates: {},
13
+ oracleTimestamp: 0n,
14
+ isPaused: false,
15
+ guardian: {
16
+ globalBound: 0n,
17
+ refInfos: {},
18
+ },
19
+ chainlink: { latestRoundDatas: {} },
20
+ wooPPBalances: {},
21
+ };
@@ -0,0 +1,55 @@
1
+ import { Address, Token } from '../../types';
2
+
3
+ export type TokenInfo = {
4
+ reserve: bigint;
5
+ R: bigint;
6
+ threshold: bigint;
7
+ target: bigint;
8
+ lastResetTimestamp: bigint;
9
+ };
10
+
11
+ export type TokenState = {
12
+ priceNow: bigint;
13
+ spreadNow: bigint;
14
+ coeffNow: bigint;
15
+ };
16
+
17
+ export type RefInfo = {
18
+ chainlinkRefOracle: Address;
19
+ refPriceFixCoeff: bigint;
20
+ minInputAmount: bigint;
21
+ maxInputAmount: bigint;
22
+ bound: bigint;
23
+ };
24
+
25
+ export type LatestRoundData = {
26
+ answer: bigint;
27
+ };
28
+
29
+ export type PoolState = {
30
+ feeRates: Record<Address, bigint>;
31
+ tokenInfos: Record<Address, TokenInfo>;
32
+ tokenStates: Record<Address, TokenState>;
33
+ oracleTimestamp: bigint;
34
+ isPaused: boolean;
35
+ guardian: {
36
+ globalBound: bigint;
37
+ refInfos: Record<Address, RefInfo>;
38
+ };
39
+ chainlink: {
40
+ latestRoundDatas: Record<Address, LatestRoundData>;
41
+ };
42
+ wooPPBalances: Record<Address, bigint>;
43
+ };
44
+
45
+ export type WooFiData = {};
46
+
47
+ export type DexParams = {
48
+ wooPPAddress: Address;
49
+ wooOracleAddress: Address;
50
+ wooFeeManagerAddress: Address;
51
+ wooGuardianAddress: Address;
52
+ quoteToken: Token;
53
+ baseTokens: Record<string, Token>;
54
+ rebateTo: Address;
55
+ };
@@ -0,0 +1,45 @@
1
+ import { BI_POWS } from '../../bigint-constants';
2
+
3
+ class WooFiDecimalMath {
4
+ readonly ONE = BI_POWS[18];
5
+ readonly TWO = 2n * BI_POWS[18];
6
+ readonly ONE2 = BI_POWS[36];
7
+
8
+ mulFloor(target: bigint, d: bigint): bigint {
9
+ // target.mul(d) / (10**18);
10
+ return (target * d) / BI_POWS[18];
11
+ }
12
+
13
+ mulCeil(target: bigint, d: bigint): bigint {
14
+ // _divCeil(target.mul(d), 10 ** 18);
15
+ return this._divCeil(target * d, BI_POWS[18]);
16
+ }
17
+
18
+ divFloor(target: bigint, d: bigint): bigint {
19
+ // target.mul(10 ** 18).div(d);
20
+ return (target * BI_POWS[18]) / d;
21
+ }
22
+
23
+ divCeil(target: bigint, d: bigint): bigint {
24
+ // _divCeil(target.mul(10 ** 18), d);
25
+ return this._divCeil(target * BI_POWS[18], d);
26
+ }
27
+
28
+ reciprocalFloor(target: bigint): bigint {
29
+ // uint256(10 ** 36).div(target);
30
+ return BI_POWS[36] / target;
31
+ }
32
+
33
+ reciprocalCeil(target: bigint): bigint {
34
+ // _divCeil(uint256(10 ** 36), target);
35
+ return this._divCeil(BI_POWS[36], target);
36
+ }
37
+
38
+ private _divCeil(a: bigint, b: bigint): bigint {
39
+ const quotient = a / b;
40
+ const remainder = a - quotient * b;
41
+ return remainder > 0n ? quotient + 1n : quotient;
42
+ }
43
+ }
44
+
45
+ export const wooFiDecimalMath = new WooFiDecimalMath();
@@ -0,0 +1,183 @@
1
+ import dotenv from 'dotenv';
2
+ dotenv.config();
3
+
4
+ import { testE2E } from '../../../tests/utils-e2e';
5
+ import {
6
+ Tokens,
7
+ Holders,
8
+ NativeTokenSymbols,
9
+ } from '../../../tests/constants-e2e';
10
+ import { Network, ContractMethod, SwapSide } from '../../constants';
11
+ import { StaticJsonRpcProvider } from '@ethersproject/providers';
12
+ import { generateConfig } from '../../config';
13
+
14
+ const dexKey = 'WooFi';
15
+
16
+ async function testForNetwork(
17
+ network: Network,
18
+ tokenASymbol: string,
19
+ tokenBSymbol: string,
20
+ tokenAAmount: string,
21
+ tokenBAmount: string,
22
+ nativeTokenAmount: string,
23
+ ) {
24
+ const tokens = Tokens[network];
25
+ const holders = Holders[network];
26
+ const provider = new StaticJsonRpcProvider(
27
+ generateConfig(network).privateHttpProvider,
28
+ network,
29
+ );
30
+ const nativeTokenSymbol = NativeTokenSymbols[network];
31
+
32
+ const sideToContractMethods = new Map([
33
+ [
34
+ SwapSide.SELL,
35
+ [
36
+ ContractMethod.simpleSwap,
37
+ ContractMethod.multiSwap,
38
+ ContractMethod.megaSwap,
39
+ ],
40
+ ],
41
+ ]);
42
+
43
+ sideToContractMethods.forEach((contractMethods, side) =>
44
+ contractMethods.forEach((contractMethod: ContractMethod) => {
45
+ describe(`${contractMethod}`, () => {
46
+ it(`${network} ${side} ${contractMethod} ${nativeTokenSymbol} -> QUOTE TOKEN`, async () => {
47
+ await testE2E(
48
+ tokens[nativeTokenSymbol],
49
+ tokens[tokenBSymbol],
50
+ holders[nativeTokenSymbol],
51
+ side === SwapSide.SELL ? nativeTokenAmount : tokenBAmount,
52
+ side,
53
+ dexKey,
54
+ contractMethod,
55
+ network,
56
+ provider,
57
+ );
58
+ });
59
+ it(`${network} ${side} ${contractMethod} QUOTE TOKEN -> ${nativeTokenSymbol}`, async () => {
60
+ await testE2E(
61
+ tokens[tokenBSymbol],
62
+ tokens[nativeTokenSymbol],
63
+ holders[tokenBSymbol],
64
+ side === SwapSide.SELL ? tokenBAmount : nativeTokenAmount,
65
+ side,
66
+ dexKey,
67
+ contractMethod,
68
+ network,
69
+ provider,
70
+ );
71
+ });
72
+ it(`${network} ${side} ${contractMethod} BASE TOKEN -> QUOTE TOKEN`, async () => {
73
+ await testE2E(
74
+ tokens[tokenASymbol],
75
+ tokens[tokenBSymbol],
76
+ holders[tokenASymbol],
77
+ side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
78
+ side,
79
+ dexKey,
80
+ contractMethod,
81
+ network,
82
+ provider,
83
+ );
84
+ });
85
+ it(`${network} ${side} ${contractMethod} QUOTE TOKEN -> BASE TOKEN`, async () => {
86
+ await testE2E(
87
+ tokens[tokenBSymbol],
88
+ tokens[tokenASymbol],
89
+ holders[tokenBSymbol],
90
+ side === SwapSide.SELL ? tokenBAmount : tokenAAmount,
91
+ side,
92
+ dexKey,
93
+ contractMethod,
94
+ network,
95
+ provider,
96
+ );
97
+ });
98
+ });
99
+ }),
100
+ );
101
+ }
102
+
103
+ describe('WooFi E2E', () => {
104
+ describe('WooFi BSC', () => {
105
+ const network = Network.BSC;
106
+
107
+ const tokenASymbol: string = 'WBNB';
108
+ const tokenBSymbol: string = 'USDT';
109
+
110
+ const tokenAAmount: string = '3000000000000000000';
111
+ const tokenBAmount: string = '111000000000000000000';
112
+ const nativeTokenAmount = '3000000000000000000';
113
+
114
+ testForNetwork(
115
+ network,
116
+ tokenASymbol,
117
+ tokenBSymbol,
118
+ tokenAAmount,
119
+ tokenBAmount,
120
+ nativeTokenAmount,
121
+ );
122
+ });
123
+
124
+ describe('WooFi Avalanche', () => {
125
+ const network = Network.AVALANCHE;
126
+
127
+ const tokenASymbol: string = 'WAVAX';
128
+ const tokenBSymbol: string = 'USDC';
129
+
130
+ const tokenAAmount: string = '3000000000000000000';
131
+ const tokenBAmount: string = '111000000';
132
+ const nativeTokenAmount = '3000000000000000000';
133
+
134
+ testForNetwork(
135
+ network,
136
+ tokenASymbol,
137
+ tokenBSymbol,
138
+ tokenAAmount,
139
+ tokenBAmount,
140
+ nativeTokenAmount,
141
+ );
142
+ });
143
+
144
+ describe('WooFi Fantom', () => {
145
+ const network = Network.FANTOM;
146
+
147
+ const tokenASymbol: string = 'WFTM';
148
+ const tokenBSymbol: string = 'USDC';
149
+
150
+ const tokenAAmount: string = '333000000000000000000';
151
+ const tokenBAmount: string = '111000000';
152
+ const nativeTokenAmount = '333000000000000000000';
153
+
154
+ testForNetwork(
155
+ network,
156
+ tokenASymbol,
157
+ tokenBSymbol,
158
+ tokenAAmount,
159
+ tokenBAmount,
160
+ nativeTokenAmount,
161
+ );
162
+ });
163
+
164
+ describe('WooFi Polygon', () => {
165
+ const network = Network.POLYGON;
166
+
167
+ const tokenASymbol: string = 'WMATIC';
168
+ const tokenBSymbol: string = 'USDC';
169
+
170
+ const tokenAAmount: string = '3000000000000000000';
171
+ const tokenBAmount: string = '1000000';
172
+ const nativeTokenAmount = '3000000000000000000';
173
+
174
+ testForNetwork(
175
+ network,
176
+ tokenASymbol,
177
+ tokenBSymbol,
178
+ tokenAAmount,
179
+ tokenBAmount,
180
+ nativeTokenAmount,
181
+ );
182
+ });
183
+ });