@paraswap/dex-lib 2.26.2 → 2.26.3-curve-v1-wbeth-freth

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.
@@ -19,6 +19,8 @@ import { address as TBTCPoolAddress } from './pools/tBTCpool';
19
19
  import { address as USDKPoolAddress } from './pools/usdkpool';
20
20
  import { address as USTPoolAddress } from './pools/ustpool';
21
21
  import { address as SLINKPoolAddress } from './pools/sLinkpool';
22
+ import { address as WBETHPoolAddress } from './pools/wbETHpool';
23
+ import { address as FRXETHPoolAddress } from './pools/frxETHpool';
22
24
 
23
25
  import { DexParams } from './types';
24
26
  import { DexConfigMap, AdapterMappings } from '../../types';
@@ -101,6 +103,8 @@ export const CurveV1Config: DexConfigMap<DexParams> = {
101
103
  USDKPoolAddress,
102
104
  USTPoolAddress,
103
105
  SLINKPoolAddress,
106
+ WBETHPoolAddress,
107
+ FRXETHPoolAddress,
104
108
  ],
105
109
  pools: {
106
110
  Compound: {
@@ -259,6 +263,34 @@ export const CurveV1Config: DexConfigMap<DexParams> = {
259
263
  isMetapool: false,
260
264
  baseToken: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
261
265
  },
266
+ wbETH: {
267
+ underlying: [],
268
+ coins: [
269
+ '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
270
+ '0xa2e3356610840701bdf5611a53974510ae27e2e1',
271
+ ],
272
+ address: '0xbfab6fa95e0091ed66058ad493189d2cb29385e6',
273
+ name: 'wbETH',
274
+ type: 2,
275
+ version: 3,
276
+ isLending: false,
277
+ isMetapool: false,
278
+ baseToken: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
279
+ },
280
+ frxETH: {
281
+ underlying: [],
282
+ coins: [
283
+ '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
284
+ '0x5e8422345238f34275888049021821e8e08caa1f',
285
+ ],
286
+ address: '0xa1f8a6807c402e4a15ef4eba36528a3fed24e577',
287
+ name: 'wbETH',
288
+ type: 2,
289
+ version: 3,
290
+ isLending: false,
291
+ isMetapool: false,
292
+ baseToken: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
293
+ },
262
294
  stETH: {
263
295
  underlying: [],
264
296
  coins: [
@@ -27,21 +27,41 @@ describe('CurveV1 E2E', () => {
27
27
  [
28
28
  {
29
29
  symbol: 'USDT',
30
- amount: (10 ** 8).toString(),
30
+ amount: '1000000000000',
31
31
  },
32
32
  {
33
33
  symbol: 'DAI',
34
- amount: (10 ** 8).toString(),
34
+ amount: '10000000000000000000',
35
35
  },
36
36
  ],
37
37
  [
38
38
  {
39
39
  symbol: 'CUSDC',
40
- amount: (10 ** 8).toString(),
40
+ amount: '1000000000000',
41
41
  },
42
42
  {
43
43
  symbol: 'CDAI',
44
- amount: (10 ** 8).toString(),
44
+ amount: '1000000000',
45
+ },
46
+ ],
47
+ [
48
+ {
49
+ symbol: 'ETH',
50
+ amount: '5000000000000000000',
51
+ },
52
+ {
53
+ symbol: 'wBETH',
54
+ amount: '5000000000000000000',
55
+ },
56
+ ],
57
+ [
58
+ {
59
+ symbol: 'ETH',
60
+ amount: '1666000000000000000',
61
+ },
62
+ {
63
+ symbol: 'frxETH',
64
+ amount: '10000000000000000',
45
65
  },
46
66
  ],
47
67
  ];
@@ -74,6 +94,19 @@ describe('CurveV1 E2E', () => {
74
94
  provider,
75
95
  );
76
96
  });
97
+ it(`${pair[1].symbol} -> ${pair[0].symbol}`, async () => {
98
+ await testE2E(
99
+ tokens[pair[1].symbol],
100
+ tokens[pair[0].symbol],
101
+ holders[pair[1].symbol],
102
+ side === SwapSide.SELL ? pair[1].amount : pair[0].amount,
103
+ side,
104
+ dexKey,
105
+ contractMethod,
106
+ network,
107
+ provider,
108
+ );
109
+ });
77
110
  });
78
111
  });
79
112
  }),
@@ -43,6 +43,8 @@ import { DUSDPool, address as DUSDPoolAddress } from './pools/DUSDpool';
43
43
  import { BBTCPool, address as BBTCPoolAddress } from './pools/bBTCpool';
44
44
  import { GUSDPool, address as GUSDPoolAddress } from './pools/GUSDpool';
45
45
  import { HUSDPool, address as HUSDPoolAddress } from './pools/HUSDpool';
46
+ import { WBETHPool, address as WBETHPoolAddress } from './pools/wbETHpool';
47
+ import { FRXETHPool, address as FRXPoolAddress } from './pools/frxETHpool';
46
48
  import {
47
49
  LinkUSDPool,
48
50
  address as LinkUSDPoolAddress,
@@ -294,6 +296,10 @@ export class CurveV1
294
296
  return new SETHPool(this.dexKey, this.dexHelper);
295
297
  case STETHPoolAddress:
296
298
  return new STETHPool(this.dexKey, this.dexHelper);
299
+ case WBETHPoolAddress:
300
+ return new WBETHPool(this.dexKey, this.dexHelper);
301
+ case FRXPoolAddress:
302
+ return new FRXETHPool(this.dexKey, this.dexHelper);
297
303
  case EURSPoolAddress:
298
304
  return new EURSPool(this.dexKey, this.dexHelper);
299
305
  case DUSDPoolAddress:
@@ -8,7 +8,6 @@ import { DeepReadonly } from 'ts-essentials';
8
8
  import { PoolState as BasepoolState } from './curve-pool';
9
9
  import { ThreePool } from './3pool';
10
10
  import { BlockHeader } from 'web3-eth';
11
- // import { getManyPoolStates } from './getstate-multicall';
12
11
 
13
12
  import { BN_0, BN_600, BN_POWS } from '../../../bignumber-constants';
14
13
  import { IDexHelper } from '../../../dex-helper';
@@ -18,6 +18,10 @@ export interface PoolState {
18
18
  admin_fee: BigNumber;
19
19
  supply: BigNumber;
20
20
  balances: BigNumber[];
21
+ stored_rates?: BigNumber[];
22
+ admin_balances?: BigNumber[];
23
+ eth_balance?: BigNumber;
24
+ token_balance?: BigNumber;
21
25
  }
22
26
 
23
27
  export abstract class CurvePool extends StatefulEventSubscriber<PoolState> {
@@ -26,6 +30,8 @@ export abstract class CurvePool extends StatefulEventSubscriber<PoolState> {
26
30
  protected LENDING_PRECISION: BigNumber = BN_POWS[18];
27
31
  protected PRECISION: BigNumber = BN_POWS[18];
28
32
 
33
+ public isAdminBalancesSupported: boolean = false;
34
+
29
35
  public handlers: {
30
36
  [event: string]: (event: any, state: PoolState, log: Log) => PoolState;
31
37
  } = {};
@@ -0,0 +1,38 @@
1
+ import { Address } from '../../../types';
2
+ import { IDexHelper } from '../../../dex-helper';
3
+ import { bigNumberify } from '../../../utils';
4
+ import StableSwapFRXETH from '../../../abi/curve-v1/StableSwapFRXETH.json';
5
+ import { ThreePool } from './3pool';
6
+
7
+ const pool = 'frxETH';
8
+ export const address: Address =
9
+ '0xa1f8a6807c402e4a15ef4eba36528a3fed24e577'.toLowerCase();
10
+ const tokenAddress: Address = '0xf43211935c781d5ca1a41d2041f397b8a7366c7a';
11
+ const N_COINS: number = 2;
12
+ const PRECISION_MUL = ['1', '1'].map(bigNumberify);
13
+ const USE_LENDING = [false, false];
14
+ const COINS = [
15
+ '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
16
+ '0x5e8422345238f34275888049021821e8e08caa1f',
17
+ ];
18
+ const trackCoins = true;
19
+
20
+ export class FRXETHPool extends ThreePool {
21
+ constructor(parentName: string, dexHelper: IDexHelper) {
22
+ super(
23
+ parentName,
24
+ dexHelper,
25
+ pool,
26
+ address,
27
+ tokenAddress,
28
+ trackCoins,
29
+ StableSwapFRXETH,
30
+ N_COINS,
31
+ PRECISION_MUL,
32
+ USE_LENDING,
33
+ COINS,
34
+ 'FRXETHPool',
35
+ );
36
+ }
37
+ }
38
+
@@ -3,12 +3,14 @@ import { CurvePool, PoolState } from './curve-pool';
3
3
  import _ from 'lodash';
4
4
  import { erc20Iface } from '../../../lib/utils-interfaces';
5
5
  import { bigNumberify, stringify } from '../../../utils';
6
+ import { uin256DecodeToBigNumber } from '../../../lib/decoders';
7
+ import { Contract } from 'web3-eth-contract';
6
8
 
7
9
  const strbnify = (val: any) => bigNumberify(stringify(val));
8
10
 
9
11
  async function _getManyPoolStates(
10
12
  pools: (CurvePool | CurveMetapool)[],
11
- multi: any,
13
+ multi: Contract,
12
14
  blockNumber: number | 'latest' = 'latest',
13
15
  ): Promise<(PoolState | Partial<MetapoolState>)[]> {
14
16
  const calldata = _(pools)
@@ -51,6 +53,31 @@ async function _getManyPoolStates(
51
53
  },
52
54
  ]
53
55
  : null,
56
+ (pool as CurvePool).isAdminBalancesSupported === true
57
+ ? [
58
+ {
59
+ target: pool.address,
60
+ callData: pool.poolIface.encodeFunctionData('stored_rates', []),
61
+ },
62
+ {
63
+ target: multi.options.address,
64
+ callData: multi.methods
65
+ .getEthBalance(pool.address.toLowerCase())
66
+ .encodeABI(),
67
+ },
68
+ {
69
+ target: pool.COINS[1].toLowerCase(),
70
+ callData: erc20Iface.encodeFunctionData('balanceOf', [
71
+ pool.address,
72
+ ]),
73
+ },
74
+ ].concat(
75
+ _.range(0, pool.N_COINS).map(poolIndex => ({
76
+ target: pool.address,
77
+ callData: pool.poolIface.encodeFunctionData('admin_balances', [poolIndex]),
78
+ }))
79
+ )
80
+ : null,
54
81
  ])
55
82
  .flattenDeep()
56
83
  .filter(a => !!a)
@@ -85,7 +112,8 @@ async function _getManyPoolStates(
85
112
  ),
86
113
  ),
87
114
  };
88
- return (pool as CurveMetapool).basepool
115
+
116
+ const state = (pool as CurveMetapool).basepool
89
117
  ? {
90
118
  ..._state,
91
119
  base_cache_updated: strbnify(
@@ -102,6 +130,29 @@ async function _getManyPoolStates(
102
130
  ),
103
131
  }
104
132
  : _state;
133
+
134
+
135
+ const stateWithBalances =
136
+ (pool as CurvePool).isAdminBalancesSupported === true
137
+ ? {
138
+ ...state,
139
+ stored_rates: pool.poolIface
140
+ .decodeFunctionResult('stored_rates', data.returnData[p++])[0]
141
+ .map(strbnify),
142
+ eth_balance: uin256DecodeToBigNumber(data.returnData[p++]),
143
+ token_balance: strbnify(erc20Iface.decodeFunctionResult('balanceOf', data.returnData[p++])[0]),
144
+ admin_balances: _.range(0, pool.N_COINS).map(i =>
145
+ strbnify(
146
+ pool.poolIface.decodeFunctionResult(
147
+ 'admin_balances',
148
+ data.returnData[p++],
149
+ )[0],
150
+ ),
151
+ ),
152
+ }
153
+ : state;
154
+
155
+ return stateWithBalances;
105
156
  });
106
157
  }
107
158