@defisaver/sdk 0.2.13 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/sdk",
3
- "version": "0.2.13",
3
+ "version": "0.3.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -23,9 +23,9 @@
23
23
  },
24
24
  "devDependencies": {
25
25
  "chai": "^4.2.0",
26
+ "dotenv": "^10.0.0",
26
27
  "jsdoc-to-markdown": "^6.0.1",
27
28
  "mocha": "^8.2.1",
28
- "web3": "^1.3.4",
29
- "dotenv": "^10.0.0"
29
+ "web3": "^1.3.4"
30
30
  }
31
31
  }
@@ -2,48 +2,78 @@ const { getAssetInfo } = require('@defisaver/tokens');
2
2
  const Action = require('../../Action');
3
3
  const { requireAddress } = require('../../utils/general');
4
4
  const { getAddr } = require('../../addresses');
5
+ const { poolInfo, makeFlags } = require('../../utils/curve-utils');
5
6
 
6
7
  class CurveDepositAction extends Action {
7
8
 
8
9
  /**
9
10
  * @param {EthAddress} sender
10
11
  * @param {EthAddress} receiver
11
- * @param {EthAddress} depositTarget
12
- * @param {EthAddress} lpToken
13
- * @param {bytes4} sig
12
+ * @param {EthAddress} poolAddr
14
13
  * @param {string} minMintAmount
14
+ * @param {bool} useUnderlying
15
15
  * @param {Array<string>} amounts
16
- * @param {Array<EthAddress>} tokens
17
- * @param {boolean} useUnderlying
18
16
  */
19
17
  constructor(
20
18
  sender,
21
19
  receiver,
22
- depositTarget,
23
- lpToken,
24
- sig,
20
+ poolAddr,
25
21
  minMintAmount,
22
+ useUnderlying,
26
23
  amounts = [],
27
- tokens = [],
28
- useUnderlying
29
24
  ) {
30
25
  requireAddress(sender);
31
26
  requireAddress(receiver);
27
+
28
+ let depositTarget;
29
+ let depositTargetType = 0;
30
+ let explicitUnderlying = false;
31
+ let tokensForApproval;
32
+
33
+ const pool = poolInfo.find((e) => e.swapAddr.toLowerCase() === poolAddr.toLowerCase());
34
+ if (useUnderlying) {
35
+ if (pool.depositContract) {
36
+ depositTarget = pool.depositContract;
37
+ depositTargetType = pool.zapType + 1;
38
+ } else {
39
+ depositTarget = pool.swapAddr;
40
+ explicitUnderlying = pool.underlyingFlag;
41
+ if (!explicitUnderlying) throw error('pool has no underlying deposit mechanism');
42
+ }
43
+ tokensForApproval = pool.underlyingCoins;
44
+ } else {
45
+ depositTarget = pool.swapAddr;
46
+ tokensForApproval = pool.coins;
47
+ }
48
+
32
49
  super('CurveDeposit',
33
50
  getAddr('CurveDeposit'),
34
- ['address', 'address', 'address', 'address', 'bytes4', 'uint256', 'uint256[]', 'address[]', 'bool'],
35
- [...arguments]);
51
+ ['address', 'address', 'address', 'uint256', 'uint8', 'uint256[]'],
52
+ [
53
+ sender,
54
+ receiver,
55
+ depositTarget,
56
+ minMintAmount,
57
+ makeFlags(depositTargetType, explicitUnderlying, 0),
58
+ amounts,
59
+ ],
60
+ ).tokensForApproval = tokensForApproval;
36
61
 
37
62
  this.mappableArgs = [
38
63
  this.args[0],
39
64
  this.args[1],
40
- this.args[5],
41
- ...this.args[6],
65
+ this.args[2],
66
+ this.args[3],
67
+ this.args[4],
68
+ ...this.args[5],
42
69
  ];
43
70
  }
44
71
 
45
72
  async getAssetsToApprove() {
46
- return this.args[7].map(_asset => Object({ asset: _asset, owner: this.args[0] }));
73
+ return this.tokensForApproval.map((e) => Object({
74
+ asset: e.toLowerCase() !== getAssetInfo('ETH').address.toLowerCase() ? e : getAssetInfo('WETH').address,
75
+ owner: this.args[0],
76
+ }));
47
77
  }
48
78
  }
49
79
 
@@ -2,51 +2,74 @@ const { getAssetInfo } = require('@defisaver/tokens');
2
2
  const Action = require('../../Action');
3
3
  const { requireAddress } = require('../../utils/general');
4
4
  const { getAddr } = require('../../addresses');
5
+ const { poolInfo, makeFlags } = require('../../utils/curve-utils');
5
6
 
6
7
  class CurveWithdrawAction extends Action {
7
8
 
8
9
  /**
9
- *
10
10
  * @param {EthAddress} sender
11
11
  * @param {EthAddress} receiver
12
- * @param {EthAddress} depositTarget
13
- * @param {EthAddress} lpToken
14
- * @param {bytes4} sig
12
+ * @param {EthAddress} poolAddr
15
13
  * @param {string} burnAmount
16
- * @param {Array<string>} minAmounts
17
- * @param {Array<EthAddress>} tokens
18
- * @param {boolean} withdrawExact
19
14
  * @param {boolean} useUnderlying
15
+ * @param {boolean} withdrawExact
16
+ * @param {Array<string>} minAmounts
20
17
  */
21
18
  constructor(
22
19
  sender,
23
20
  receiver,
24
- depositTarget,
25
- lpToken,
26
- sig,
21
+ poolAddr,
27
22
  burnAmount,
28
- minAmounts = [],
29
- tokens = [],
23
+ useUnderlying,
30
24
  withdrawExact,
31
- useUnderlying
25
+ minAmounts = [],
32
26
  ) {
33
27
  requireAddress(sender);
34
28
  requireAddress(receiver);
35
- super('CurveWithdrawAction',
36
- getAddr('CurveWithdrawAction'),
37
- ['address', 'address', 'address', 'address', 'bytes4', 'uint256', 'uint256[]', 'address[]', 'bool', 'bool'],
38
- [...arguments]);
29
+
30
+ let depositTarget;
31
+ let depositTargetType = 0;
32
+ let explicitUnderlying = false;
33
+
34
+ const pool = poolInfo.find((e) => e.swapAddr.toLowerCase() === poolAddr.toLowerCase());
35
+ if (useUnderlying) {
36
+ if (pool.depositContract) {
37
+ depositTarget = pool.depositContract;
38
+ depositTargetType = pool.zapType + 1;
39
+ } else {
40
+ depositTarget = pool.swapAddr;
41
+ explicitUnderlying = pool.underlyingFlag;
42
+ if (!explicitUnderlying) throw error('pool has no underlying deposit mechanism');
43
+ }
44
+ } else {
45
+ depositTarget = pool.swapAddr;
46
+ }
47
+
48
+ super('CurveWithdraw',
49
+ getAddr('CurveWithdraw'),
50
+ ['address', 'address', 'address', 'uint256', 'uint8', 'uint256[]'],
51
+ [
52
+ sender,
53
+ receiver,
54
+ depositTarget,
55
+ burnAmount,
56
+ makeFlags(depositTargetType, explicitUnderlying, withdrawExact),
57
+ minAmounts,
58
+ ],
59
+ ).lpToken = pool.lpToken;
39
60
 
40
61
  this.mappableArgs = [
41
62
  this.args[0],
42
63
  this.args[1],
43
- this.args[5],
44
- ...this.args[6],
64
+ this.args[2],
65
+ this.args[3],
66
+ this.args[4],
67
+ ...this.args[5],
45
68
  ];
46
69
  }
47
70
 
48
71
  async getAssetsToApprove() {
49
- return { asset: this.args[3], owner: this.args[0] };
72
+ return [{ asset: this.lpToken, owner: this.args[0] }];
50
73
  }
51
74
  }
52
75
 
package/src/addresses.js CHANGED
@@ -126,11 +126,14 @@ const actionAddresses = {
126
126
  McdRatioCheck: '0x3f09773e5e945C6Aa1bc8a8B3492f507620DE1e1',
127
127
  GasFeeTaker: '0x431F1E1A9859EF99953801dbdeB31d2846ADcc0d',
128
128
 
129
- CurveStethPoolDeposit: '0x5Ae5870dC0C780e9eb68bE7a223eCd7F3BDad12B', // REDEPLOY
130
- CurveStethPoolWithdraw: '0x4089731d843Ce52699Fe64F68556aBbD95D70D00', // REDEPLOY
129
+ CurveStethPoolDeposit: '0x5Ae5870dC0C780e9eb68bE7a223eCd7F3BDad12B',
130
+ CurveStethPoolWithdraw: '0x4089731d843Ce52699Fe64F68556aBbD95D70D00',
131
+
132
+ CurveDeposit: '0x160225c24300bD9fAA03Bc007D5e72bDbbcA9257',
133
+ CurveWithdraw: '0xA2A6D75417807ebAf8364613018D697f88021771',
131
134
  },
132
135
  [NETWORKS.optimism.chainId]: {
133
- DFSSell: '0xfA015aD97E25247c2144F1C89AeD449cc3Fd1FCB',
136
+ DFSSell: '0xBA0f6039b95CC0A02B5fc983eCf0FC4437BaacC7',
134
137
 
135
138
  // basic
136
139
  WrapEth: '0x6D735db054AC4a1F10f96b99f8550E9eefbC2AC5',
@@ -152,7 +155,7 @@ const actionAddresses = {
152
155
  FLAaveV3: '0x352D4a1622f2DC34c738F542934372855f219F05',
153
156
  },
154
157
  [NETWORKS.arbitrum.chainId]: {
155
- DFSSell: '0x49E1574Ba6b8134c29B1EbC010784A01D91b794F',
158
+ DFSSell: '0x77c02Bb7CbBb2F896c5Ea14e1b60D65f81e552db',
156
159
 
157
160
  // basic
158
161
  WrapEth: '0x35136b25bFA7CCC8f5b94E3181a16B61c06980F0',
@@ -189,6 +192,7 @@ const otherAddresses = {
189
192
  RaiWethUniV2LPToken : '0x8aE720a71622e824F576b4A8C03031066548A3B1',
190
193
  BalancerToken : '0xba100000625a3754423978a60c9317c58a424e3D',
191
194
  CrvToken: '0xD533a949740bb3306d119CC777fa900bA034cd52',
195
+ CvxToken: '0x4e3FBD56CD56c3e72c1403e103b45Db9da5B9D2B',
192
196
  DAI: '0x6b175474e89094c44da98b954eedeac495271d0f',
193
197
  Empty: '0x0000000000000000000000000000000000000000',
194
198
  },
@@ -226,8 +230,11 @@ const getAddr = (name, chainId) => {
226
230
  const actions = actionAddresses[_chainId];
227
231
  const other = otherAddresses[_chainId];
228
232
 
229
- if (!actions && !other) throw new Error(`Cannot find address for chainId: ${_chainId}.`);
230
- if (!actions[name] && !other[name]) throw new Error(`Cannot find address for name: ${name} (chainId: ${_chainId}).`);
233
+ // skip this check if we're in testing mode
234
+ if (!CONFIG.testingMode) {
235
+ if (!actions && !other) throw new Error(`Cannot find address for chainId: ${_chainId}.`);
236
+ if (!actions[name] && !other[name]) throw new Error(`Cannot find address for name: ${name} (chainId: ${_chainId}).`);
237
+ }
231
238
 
232
239
  return actions[name] || other[name];
233
240
  };
package/src/config.js CHANGED
@@ -45,6 +45,7 @@ const NETWORKS = {
45
45
  */
46
46
  const CONFIG = {
47
47
  chainId: NETWORKS.ethereum.chainId,
48
+ testingMode: false
48
49
  };
49
50
 
50
51
  /**
@@ -0,0 +1,14 @@
1
+ const poolInfo = require('./curvePoolInfo.json');
2
+
3
+ const makeFlags = (
4
+ depositTargetType,
5
+ explicitUnderlying,
6
+ withdrawExact,
7
+ ) => {
8
+ return depositTargetType | explicitUnderlying << 2 | withdrawExact << 3;
9
+ }
10
+
11
+ module.exports = {
12
+ poolInfo,
13
+ makeFlags,
14
+ };
@@ -0,0 +1,203 @@
1
+ [
2
+ {
3
+ "name": "susd",
4
+ "swapAddr": "0xA5407eAE9Ba41422680e2e00537571bcC53efBfD",
5
+ "depositContract": "0xFCBa3E75865d2d561BE8D220616520c171F12851",
6
+ "nCoins": 4,
7
+ "coins": [
8
+ "0x6B175474E89094C44Da98b954EedeAC495271d0F",
9
+ "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
10
+ "0xdAC17F958D2ee523a2206206994597C13D831ec7",
11
+ "0x57Ab1ec28D129707052df4dF418D58a2D46d5f51"
12
+ ],
13
+ "decimals": [
14
+ 18,
15
+ 6,
16
+ 6,
17
+ 18
18
+ ],
19
+ "underlyingCoins": [
20
+ "0x6B175474E89094C44Da98b954EedeAC495271d0F",
21
+ "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
22
+ "0xdAC17F958D2ee523a2206206994597C13D831ec7",
23
+ "0x57Ab1ec28D129707052df4dF418D58a2D46d5f51"
24
+ ],
25
+ "underlyingDecimals": [
26
+ 18,
27
+ 6,
28
+ 6,
29
+ 18
30
+ ],
31
+ "isMeta": false,
32
+ "lpToken": "0xC25a3A3b969415c80451098fa907EC722572917F",
33
+ "gauges": [
34
+ "0xA90996896660DEcC6E997655E065b23788857849"
35
+ ],
36
+ "gaugeTypes": [
37
+ 0
38
+ ],
39
+ "zapType": 1
40
+ },
41
+ {
42
+ "name": "compound",
43
+ "swapAddr": "0xA2B47E3D5c44877cca798226B7B8118F9BFb7A56",
44
+ "depositContract": "0xeB21209ae4C2c9FF2a86ACA31E123764A3B6Bc06",
45
+ "nCoins": 2,
46
+ "coins": [
47
+ "0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643",
48
+ "0x39AA39c021dfbaE8faC545936693aC917d5E7563"
49
+ ],
50
+ "decimals": [
51
+ 8,
52
+ 8
53
+ ],
54
+ "underlyingCoins": [
55
+ "0x6B175474E89094C44Da98b954EedeAC495271d0F",
56
+ "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
57
+ ],
58
+ "underlyingDecimals": [
59
+ 18,
60
+ 6
61
+ ],
62
+ "isMeta": false,
63
+ "lpToken": "0x845838DF265Dcd2c412A1Dc9e959c7d08537f8a2",
64
+ "gauges": [
65
+ "0x7ca5b0a2910B33e9759DC7dDB0413949071D7575"
66
+ ],
67
+ "gaugeTypes": [
68
+ 0
69
+ ],
70
+ "zapType": 1
71
+ },
72
+ {
73
+ "underlyingFlag": true,
74
+ "name": "aave",
75
+ "swapAddr": "0xDeBF20617708857ebe4F679508E7b7863a8A8EeE",
76
+ "nCoins": 3,
77
+ "coins": [
78
+ "0x028171bCA77440897B824Ca71D1c56caC55b68A3",
79
+ "0xBcca60bB61934080951369a648Fb03DF4F96263C",
80
+ "0x3Ed3B47Dd13EC9a98b44e6204A523E766B225811"
81
+ ],
82
+ "decimals": [
83
+ 18,
84
+ 6,
85
+ 6
86
+ ],
87
+ "underlyingCoins": [
88
+ "0x6B175474E89094C44Da98b954EedeAC495271d0F",
89
+ "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
90
+ "0xdAC17F958D2ee523a2206206994597C13D831ec7"
91
+ ],
92
+ "underlyingDecimals": [
93
+ 18,
94
+ 6,
95
+ 6
96
+ ],
97
+ "isMeta": false,
98
+ "lpToken": "0xFd2a8fA60Abd58Efe3EeE34dd494cD491dC14900",
99
+ "gauges": [
100
+ "0xd662908ADA2Ea1916B3318327A97eB18aD588b5d"
101
+ ],
102
+ "gaugeTypes": [
103
+ 0
104
+ ]
105
+ },
106
+ {
107
+ "name": "steth",
108
+ "swapAddr": "0xDC24316b9AE028F1497c275EB9192a3Ea0f67022",
109
+ "nCoins": 2,
110
+ "coins": [
111
+ "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
112
+ "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84"
113
+ ],
114
+ "decimals": [
115
+ 18,
116
+ 18
117
+ ],
118
+ "underlyingCoins": [
119
+ "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
120
+ "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84"
121
+ ],
122
+ "underlyingDecimals": [
123
+ 18,
124
+ 18
125
+ ],
126
+ "isMeta": false,
127
+ "lpToken": "0x06325440D014e39736583c165C2963BA99fAf14E",
128
+ "gauges": [
129
+ "0x182B723a58739a9c974cFDB385ceaDb237453c28"
130
+ ],
131
+ "gaugeTypes": [
132
+ 0
133
+ ]
134
+ },
135
+ {
136
+ "name": "3pool",
137
+ "swapAddr": "0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7",
138
+ "nCoins": 3,
139
+ "coins": [
140
+ "0x6B175474E89094C44Da98b954EedeAC495271d0F",
141
+ "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
142
+ "0xdAC17F958D2ee523a2206206994597C13D831ec7"
143
+ ],
144
+ "decimals": [
145
+ 18,
146
+ 6,
147
+ 6
148
+ ],
149
+ "underlyingCoins": [
150
+ "0x6B175474E89094C44Da98b954EedeAC495271d0F",
151
+ "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
152
+ "0xdAC17F958D2ee523a2206206994597C13D831ec7"
153
+ ],
154
+ "underlyingDecimals": [
155
+ 18,
156
+ 6,
157
+ 6
158
+ ],
159
+ "isMeta": false,
160
+ "lpToken": "0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490",
161
+ "gauges": [
162
+ "0xbFcF63294aD7105dEa65aA58F8AE5BE2D9d0952A"
163
+ ],
164
+ "gaugeTypes": [
165
+ 0
166
+ ]
167
+ },
168
+ {
169
+ "name": "musd",
170
+ "swapAddr": "0x8474DdbE98F5aA3179B3B3F5942D724aFcdec9f6",
171
+ "depositContract": "0x803A2B40c5a9BB2B86DD630B274Fa2A9202874C2",
172
+ "nCoins": 2,
173
+ "coins": [
174
+ "0xe2f2a5C287993345a840Db3B0845fbC70f5935a5",
175
+ "0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490"
176
+ ],
177
+ "decimals": [
178
+ 18,
179
+ 18
180
+ ],
181
+ "underlyingCoins": [
182
+ "0xe2f2a5C287993345a840Db3B0845fbC70f5935a5",
183
+ "0x6B175474E89094C44Da98b954EedeAC495271d0F",
184
+ "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
185
+ "0xdAC17F958D2ee523a2206206994597C13D831ec7"
186
+ ],
187
+ "underlyingDecimals": [
188
+ 18,
189
+ 18,
190
+ 6,
191
+ 6
192
+ ],
193
+ "isMeta": true,
194
+ "lpToken": "0x1AEf73d49Dedc4b1778d0706583995958Dc862e6",
195
+ "gauges": [
196
+ "0x5f626c30EC1215f4EdCc9982265E8b1F411D1352"
197
+ ],
198
+ "gaugeTypes": [
199
+ 0
200
+ ],
201
+ "zapType": 0
202
+ }
203
+ ]