@dhedge/v2-sdk 1.0.0 → 1.2.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 (46) hide show
  1. package/README.md +69 -3
  2. package/dist/config.d.ts +4 -0
  3. package/dist/entities/dhedge.d.ts +2 -1
  4. package/dist/entities/pool.d.ts +94 -13
  5. package/dist/entities/utils.d.ts +15 -0
  6. package/dist/services/claim-balancer/claim.service.d.ts +21 -0
  7. package/dist/services/claim-balancer/claim.worker.d.ts +4 -0
  8. package/dist/services/claim-balancer/ipfs.service.d.ts +4 -0
  9. package/dist/services/claim-balancer/types.d.ts +54 -0
  10. package/dist/test/constants.d.ts +12 -0
  11. package/dist/types.d.ts +17 -3
  12. package/dist/utils/contract.d.ts +14 -0
  13. package/dist/utils/index.d.ts +7 -0
  14. package/dist/utils/merkle.d.ts +22 -0
  15. package/dist/v2-sdk.cjs.development.js +5066 -669
  16. package/dist/v2-sdk.cjs.development.js.map +1 -1
  17. package/dist/v2-sdk.cjs.production.min.js +1 -1
  18. package/dist/v2-sdk.cjs.production.min.js.map +1 -1
  19. package/dist/v2-sdk.esm.js +5065 -670
  20. package/dist/v2-sdk.esm.js.map +1 -1
  21. package/package.json +11 -2
  22. package/src/abi/IAaveIncentivesController.json +50 -0
  23. package/src/abi/IBalancerMerkleOrchard.json +353 -0
  24. package/src/abi/IBalancertV2Vault.json +938 -0
  25. package/src/abi/ILendingPool.json +807 -0
  26. package/src/config.ts +26 -3
  27. package/src/entities/dhedge.ts +7 -3
  28. package/src/entities/pool.ts +360 -35
  29. package/src/entities/utils.ts +201 -1
  30. package/src/services/claim-balancer/MultiTokenClaim.json +115 -0
  31. package/src/services/claim-balancer/claim.service.ts +324 -0
  32. package/src/services/claim-balancer/claim.worker.ts +32 -0
  33. package/src/services/claim-balancer/ipfs.service.ts +12 -0
  34. package/src/services/claim-balancer/types.ts +66 -0
  35. package/src/test/aave.test.ts +73 -0
  36. package/src/test/balancer.test.ts +109 -0
  37. package/src/test/constants.ts +13 -0
  38. package/src/test/dhedge.test.ts +20 -8
  39. package/src/test/oneInch.test.ts +56 -0
  40. package/src/test/pool.test.ts +11 -168
  41. package/src/test/sushi.test.ts +173 -0
  42. package/src/test/utils.test.ts +43 -17
  43. package/src/types.ts +18 -3
  44. package/src/utils/contract.ts +95 -0
  45. package/src/utils/index.ts +38 -0
  46. package/src/utils/merkle.ts +172 -0
package/src/config.ts CHANGED
@@ -4,25 +4,48 @@ import {
4
4
  Network,
5
5
  AddressDappNetworkMap
6
6
  } from "./types";
7
+ import { ChainId } from "@sushiswap/sdk";
8
+ import { NetworkChainIdMap } from ".";
7
9
 
8
10
  export const factoryAddress: AddressNetworkMap = {
9
11
  [Network.POLYGON]: "0xfdc7b8bFe0DD3513Cc669bB8d601Cb83e2F69cB0"
12
+ //[Network.POLYGON]: "0xDd87eCdB10cFF7004276AAbAbd30e7a08F69bb53"
10
13
  };
11
14
 
12
15
  export const routerAddress: AddressDappNetworkMap = {
13
16
  [Network.POLYGON]: {
14
- [Dapp.SUSHISWAP]: "0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506"
17
+ [Dapp.SUSHISWAP]: "0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506",
18
+ [Dapp.AAVE]: "0x8dFf5E27EA6b7AC08EbFdf9eB090F32ee9a30fcf",
19
+ [Dapp.ONEINCH]: "0x1111111254fb6c44bac0bed2854e76f90643097d",
20
+ [Dapp.QUICKSWAP]: "0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff",
21
+ [Dapp.BALANCER]: "0xBA12222222228d8Ba445958a75a0704d566BF2C8"
15
22
  }
16
23
  };
17
24
 
18
25
  export const dappFactoryAddress: AddressDappNetworkMap = {
19
26
  [Network.POLYGON]: {
20
- [Dapp.SUSHISWAP]: "0xc35DADB65012eC5796536bD9864eD8773aBc74C4"
27
+ [Dapp.SUSHISWAP]: "0xc35DADB65012eC5796536bD9864eD8773aBc74C4",
28
+ [Dapp.QUICKSWAP]: "0x5757371414417b8C6CAad45bAeF941aBc7d3Ab32"
21
29
  }
22
30
  };
23
31
 
24
32
  export const stakingAddress: AddressDappNetworkMap = {
25
33
  [Network.POLYGON]: {
26
- [Dapp.SUSHISWAP]: "0x0769fd68dFb93167989C6f7254cd0D766Fb2841F"
34
+ [Dapp.SUSHISWAP]: "0x0769fd68dFb93167989C6f7254cd0D766Fb2841F",
35
+ [Dapp.BALANCER]: "0x0F3e0c4218b7b0108a3643cFe9D3ec0d4F57c54e",
36
+ [Dapp.AAVE]: "0x357D51124f59836DeD84c8a1730D72B749d8BC23"
27
37
  }
28
38
  };
39
+
40
+ export const networkChainIdMap: NetworkChainIdMap = {
41
+ [Network.POLYGON]: ChainId.MATIC
42
+ };
43
+
44
+ export const balancerSubgraph: AddressNetworkMap = {
45
+ [Network.POLYGON]:
46
+ "https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-polygon-v2"
47
+ };
48
+
49
+ export const multiCallAddress: AddressNetworkMap = {
50
+ [Network.POLYGON]: "0x275617327c958bD06b5D6b871E7f491D76113dd8"
51
+ };
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1
2
  import { Contract, Wallet } from "ethers";
2
3
 
3
4
  import PoolFactory from "../abi/PoolFactory.json";
@@ -34,6 +35,7 @@ export class Dhedge {
34
35
  * @param {string} symbol Token symbol
35
36
  * @param {tuple[]} supportedAssets Enabled assets to trade
36
37
  * @param {number|BigNumber} managerFeeNumerator Manger fee in percent
38
+ * @param {any} options Transaction options
37
39
  * @returns {Pool} Created Pool
38
40
  */
39
41
  public async createPool(
@@ -41,7 +43,8 @@ export class Dhedge {
41
43
  poolName: string,
42
44
  symbol: string,
43
45
  supportedAssets: SupportedAsset[],
44
- managerFeeNumerator = 100
46
+ managerFeeNumerator = 20,
47
+ options: any = null
45
48
  ): Promise<Pool> {
46
49
  const pool = await this.factory.createFund(
47
50
  false,
@@ -49,8 +52,9 @@ export class Dhedge {
49
52
  managerName,
50
53
  poolName,
51
54
  symbol,
52
- managerFeeNumerator,
53
- supportedAssets
55
+ managerFeeNumerator * 100,
56
+ supportedAssets,
57
+ options
54
58
  );
55
59
  const receipt = await pool.wait(1);
56
60
 
@@ -1,9 +1,14 @@
1
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
1
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ import axios from "axios";
2
4
  import { Contract, ethers, Wallet, BigNumber } from "ethers";
3
5
 
4
6
  import IERC20 from "../abi/IERC20.json";
5
7
  import IMiniChefV2 from "../abi/IMiniChefV2.json";
8
+ import ILendingPool from "../abi/ILendingPool.json";
6
9
  import IUniswapV2Router from "../abi/IUniswapV2Router.json";
10
+ import IBalancerMerkleOrchard from "../abi/IBalancerMerkleOrchard.json";
11
+ import IAaveIncentivesController from "../abi/IAaveIncentivesController.json";
7
12
  import { routerAddress, stakingAddress } from "../config";
8
13
  import {
9
14
  Dapp,
@@ -14,6 +19,7 @@ import {
14
19
  } from "../types";
15
20
 
16
21
  import { Utils } from "./utils";
22
+ import { ClaimService } from "../services/claim-balancer/claim.service";
17
23
 
18
24
  export class Pool {
19
25
  public readonly poolLogic: Contract;
@@ -65,14 +71,16 @@ export class Pool {
65
71
  * Approve the asset that can be deposited into a pool
66
72
  * @param {string} nasset Address of deposit asset
67
73
  * @param {BigNumber | string} amount Amount to be approved
74
+ * @param {any} options Transaction options
68
75
  * @returns {Promise<any>} Transaction
69
76
  */
70
77
  async approveDeposit(
71
78
  asset: string,
72
- amount: BigNumber | string
79
+ amount: BigNumber | string,
80
+ options: any = null
73
81
  ): Promise<any> {
74
82
  const iERC20 = new ethers.Contract(asset, IERC20.abi, this.signer);
75
- const tx = await iERC20.approve(this.address, amount);
83
+ const tx = await iERC20.approve(this.address, amount, options);
76
84
  return tx;
77
85
  }
78
86
 
@@ -80,20 +88,29 @@ export class Pool {
80
88
  * Deposit asset into a pool
81
89
  * @param {string} asset Address of asset
82
90
  * @param {BigNumber | string} amount Amount to be deposited
91
+ * @param {any} options Transaction options
83
92
  * @returns {Promise<any>} Transaction
84
93
  */
85
- async deposit(asset: string, amount: string | BigNumber): Promise<any> {
86
- const tx = await this.poolLogic.deposit(asset, amount);
94
+ async deposit(
95
+ asset: string,
96
+ amount: string | BigNumber,
97
+ options: any = null
98
+ ): Promise<any> {
99
+ const tx = await this.poolLogic.deposit(asset, amount, options);
87
100
  return tx;
88
101
  }
89
102
 
90
103
  /**
91
104
  * Withdraw assets from a pool
92
105
  * @param fundTokenAmount Amount of pool tokens to be withdrawn
106
+ * @param {any} options Transaction options
93
107
  * @returns {Promise<any>} Transaction
94
108
  */
95
- async withdraw(fundTokenAmount: string | BigNumber): Promise<any> {
96
- const tx = await this.poolLogic.withdraw(fundTokenAmount);
109
+ async withdraw(
110
+ fundTokenAmount: string | BigNumber,
111
+ options: any = null
112
+ ): Promise<any> {
113
+ const tx = await this.poolLogic.withdraw(fundTokenAmount, options);
97
114
  return tx;
98
115
  }
99
116
 
@@ -104,19 +121,25 @@ export class Pool {
104
121
  * @param {Dapp} dapp Platform like Sushiswap or Uniswap
105
122
  * @param {string} asset Address of asset
106
123
  * @param @param {BigNumber | string} Amount to be approved
124
+ * @param {any} options Transaction options
107
125
  * @returns {Promise<any>} Transaction
108
126
  */
109
127
  async approve(
110
128
  dapp: Dapp,
111
129
  asset: string,
112
- amount: BigNumber | string
130
+ amount: BigNumber | string,
131
+ options: any = null
113
132
  ): Promise<any> {
114
133
  const iERC20 = new ethers.utils.Interface(IERC20.abi);
115
134
  const approveTxData = iERC20.encodeFunctionData("approve", [
116
135
  routerAddress[this.network][dapp],
117
136
  amount
118
137
  ]);
119
- const tx = await this.poolLogic.execTransaction(asset, approveTxData);
138
+ const tx = await this.poolLogic.execTransaction(
139
+ asset,
140
+ approveTxData,
141
+ options
142
+ );
120
143
  return tx;
121
144
  }
122
145
 
@@ -125,19 +148,25 @@ export class Pool {
125
148
  * @param {Dapp} dapp Platform like Sushiswap or Uniswap
126
149
  * @param {string} asset Address of liquidity pool token
127
150
  * @param {BigNumber | string} amount Aamount to be approved
151
+ * @param {any} options Transaction options
128
152
  * @returns {Promise<any>} Transaction
129
153
  */
130
154
  async approveStaking(
131
155
  dapp: Dapp,
132
156
  asset: string,
133
- amount: BigNumber | string
157
+ amount: BigNumber | string,
158
+ options: any = null
134
159
  ): Promise<any> {
135
160
  const iERC20 = new ethers.utils.Interface(IERC20.abi);
136
161
  const approveTxData = iERC20.encodeFunctionData("approve", [
137
162
  stakingAddress[this.network][dapp],
138
163
  amount
139
164
  ]);
140
- const tx = await this.poolLogic.execTransaction(asset, approveTxData);
165
+ const tx = await this.poolLogic.execTransaction(
166
+ asset,
167
+ approveTxData,
168
+ options
169
+ );
141
170
  return tx;
142
171
  }
143
172
 
@@ -148,6 +177,7 @@ export class Pool {
148
177
  * @param {string} assetTo Asset to trade into
149
178
  * @param {BigNumber | string} amountIn Amount
150
179
  * @param {BigNumber | string} minAmountOut Minumum amount to receive
180
+ * @param {any} options Transaction options
151
181
  * @returns {Promise<any>} Transaction
152
182
  */
153
183
  async trade(
@@ -155,19 +185,47 @@ export class Pool {
155
185
  assetFrom: string,
156
186
  assetTo: string,
157
187
  amountIn: BigNumber | string,
158
- minAmountOut: BigNumber | string
188
+ slippage = 0.5,
189
+ options: any = null
159
190
  ): Promise<any> {
160
- const iUniswapV2Router = new ethers.utils.Interface(IUniswapV2Router.abi);
161
- const swapTxData = iUniswapV2Router.encodeFunctionData(Transaction.SWAP, [
162
- amountIn,
163
- minAmountOut,
164
- [assetFrom, assetTo],
165
- this.address,
166
- Math.floor(Date.now() / 1000) + 60 * 20 // 20 minutes from the current Unix time
167
- ]);
191
+ let swapTxData: string;
192
+ if (dapp === Dapp.ONEINCH) {
193
+ const apiUrl = `https://api.1inch.exchange/v4.0/137/swap?fromTokenAddress=${assetFrom}&toTokenAddress=${assetTo}&amount=${amountIn.toString()}&fromAddress=${
194
+ this.address
195
+ }&destReceiver=${
196
+ this.address
197
+ }&slippage=${slippage.toString()}&disableEstimate=true`;
198
+ const response = await axios.get(apiUrl);
199
+ swapTxData = response.data.tx.data;
200
+ } else if (dapp === Dapp.BALANCER) {
201
+ swapTxData = await this.utils.getBalancerSwapTx(
202
+ this,
203
+ assetFrom,
204
+ assetTo,
205
+ amountIn,
206
+ slippage
207
+ );
208
+ } else {
209
+ const iUniswapV2Router = new ethers.utils.Interface(IUniswapV2Router.abi);
210
+ const minAmountOut = await this.utils.getMinAmountOut(
211
+ dapp,
212
+ assetFrom,
213
+ assetTo,
214
+ amountIn,
215
+ slippage
216
+ );
217
+ swapTxData = iUniswapV2Router.encodeFunctionData(Transaction.SWAP, [
218
+ amountIn,
219
+ minAmountOut,
220
+ [assetFrom, assetTo],
221
+ this.address,
222
+ Math.floor(Date.now() / 1000) + 60 * 20 // 20 minutes from the current Unix time
223
+ ]);
224
+ }
168
225
  const tx = await this.poolLogic.execTransaction(
169
226
  routerAddress[this.network][dapp],
170
- swapTxData
227
+ swapTxData,
228
+ options
171
229
  );
172
230
  return tx;
173
231
  }
@@ -179,6 +237,7 @@ export class Pool {
179
237
  * @param {string} assetB Second asset
180
238
  * @param {BigNumber | string} amountA Amount first asset
181
239
  * @param {BigNumber | string} amountB Amount second asset
240
+ * @param {any} options Transaction options
182
241
  * @returns {Promise<any>} Transaction
183
242
  */
184
243
  async addLiquidity(
@@ -186,7 +245,8 @@ export class Pool {
186
245
  assetA: string,
187
246
  assetB: string,
188
247
  amountA: BigNumber | string,
189
- amountB: BigNumber | string
248
+ amountB: BigNumber | string,
249
+ options: any = null
190
250
  ): Promise<any> {
191
251
  const iUniswapV2Router = new ethers.utils.Interface(IUniswapV2Router.abi);
192
252
  const addLiquidityTxData = iUniswapV2Router.encodeFunctionData(
@@ -204,7 +264,8 @@ export class Pool {
204
264
  );
205
265
  const tx = await this.poolLogic.execTransaction(
206
266
  routerAddress[this.network][dapp],
207
- addLiquidityTxData
267
+ addLiquidityTxData,
268
+ options
208
269
  );
209
270
  return tx;
210
271
  }
@@ -215,13 +276,15 @@ export class Pool {
215
276
  * @param {string} assetA First asset
216
277
  * @param {string} assetB Second asset
217
278
  * @param {BigNumber | string} amount Amount of liquidity pool tokens
279
+ * @param {any} options Transaction options
218
280
  * @returns {Promise<any>} Transaction
219
281
  */
220
282
  async removeLiquidity(
221
283
  dapp: Dapp,
222
284
  assetA: string,
223
285
  assetB: string,
224
- amount: string | BigNumber
286
+ amount: string | BigNumber,
287
+ options: any = null
225
288
  ): Promise<any> {
226
289
  const iUniswapV2Router = new ethers.utils.Interface(IUniswapV2Router.abi);
227
290
  const removeLiquidityTxData = iUniswapV2Router.encodeFunctionData(
@@ -238,7 +301,8 @@ export class Pool {
238
301
  );
239
302
  const tx = await this.poolLogic.execTransaction(
240
303
  routerAddress[this.network][dapp],
241
- removeLiquidityTxData
304
+ removeLiquidityTxData,
305
+ options
242
306
  );
243
307
  return tx;
244
308
  }
@@ -248,12 +312,14 @@ export class Pool {
248
312
  * @param {Dapp} dapp Platform like Sushiswap or Uniswap
249
313
  * @param {string} asset Liquidity pool token
250
314
  * @param {BigNumber | string} amount Amount of liquidity pool tokens
315
+ * @param {any} options Transaction options
251
316
  * @returns {Promise<any>} Transaction
252
317
  */
253
318
  async stake(
254
319
  dapp: Dapp,
255
320
  asset: string,
256
- amount: BigNumber | string
321
+ amount: BigNumber | string,
322
+ options: any = null
257
323
  ): Promise<any> {
258
324
  const iMiniChefV2 = new ethers.utils.Interface(IMiniChefV2.abi);
259
325
  const poolId = await this.utils.getLpPoolId(dapp, asset);
@@ -264,7 +330,8 @@ export class Pool {
264
330
  ]);
265
331
  const tx = await this.poolLogic.execTransaction(
266
332
  stakingAddress[this.network][dapp],
267
- stakeTxData
333
+ stakeTxData,
334
+ options
268
335
  );
269
336
 
270
337
  return tx;
@@ -275,23 +342,141 @@ export class Pool {
275
342
  * @param {Dapp} dapp Platform like Sushiswap or Uniswap
276
343
  * @param {string} asset Liquidity pool token
277
344
  * @param {BigNumber | string} amount Amount of liquidity pool tokens
345
+ * @param {any} options Transaction options
278
346
  * @returns {Promise<any>} Transaction
279
347
  */
280
348
  async unStake(
281
349
  dapp: Dapp,
282
350
  asset: string,
283
- amount: BigNumber | string
351
+ amount: BigNumber | string,
352
+ options: any = null
284
353
  ): Promise<any> {
285
354
  const iMiniChefV2 = new ethers.utils.Interface(IMiniChefV2.abi);
286
355
  const poolId = await this.utils.getLpPoolId(dapp, asset);
287
- const unStakeTxData = iMiniChefV2.encodeFunctionData(Transaction.UNSTAKE, [
356
+ const unStakeTxData = iMiniChefV2.encodeFunctionData(Transaction.WITHDRAW, [
288
357
  poolId,
289
358
  amount,
290
359
  this.address
291
360
  ]);
292
361
  const tx = await this.poolLogic.execTransaction(
293
362
  stakingAddress[this.network][dapp],
294
- unStakeTxData
363
+ unStakeTxData,
364
+ options
365
+ );
366
+ return tx;
367
+ }
368
+
369
+ /**
370
+ * Lend asset to a lending pool
371
+ * @param {Dapp} dapp Platform like Aave
372
+ * @param {string} asset Asset
373
+ * @param {BigNumber | string} amount Amount of asset to lend
374
+ * @param {any} options Transaction options
375
+ * @returns {Promise<any>} Transaction
376
+ */
377
+ async lend(
378
+ dapp: Dapp,
379
+ asset: string,
380
+ amount: BigNumber | string,
381
+ options: any = null
382
+ ): Promise<any> {
383
+ const iLendingPool = new ethers.utils.Interface(ILendingPool.abi);
384
+ const depositTxData = iLendingPool.encodeFunctionData(Transaction.DEPOSIT, [
385
+ asset,
386
+ amount,
387
+ this.address,
388
+ 0
389
+ ]);
390
+ const tx = await this.poolLogic.execTransaction(
391
+ routerAddress[this.network][dapp],
392
+ depositTxData,
393
+ options
394
+ );
395
+ return tx;
396
+ }
397
+
398
+ /**
399
+ * Witdraw asset from a lending pool
400
+ * @param {Dapp} dapp Platform like Aave
401
+ * @param {string} asset Asset
402
+ * @param {BigNumber | string} amount Amount of asset to lend
403
+ * @param {any} options Transaction options
404
+ * @returns {Promise<any>} Transaction
405
+ */
406
+ async withdrawDeposit(
407
+ dapp: Dapp,
408
+ asset: string,
409
+ amount: BigNumber | string,
410
+ options: any = null
411
+ ): Promise<any> {
412
+ const iLendingPool = new ethers.utils.Interface(ILendingPool.abi);
413
+ const withdrawTxData = iLendingPool.encodeFunctionData(
414
+ Transaction.WITHDRAW,
415
+ [asset, amount, this.address]
416
+ );
417
+ const tx = await this.poolLogic.execTransaction(
418
+ routerAddress[this.network][dapp],
419
+ withdrawTxData,
420
+ options
421
+ );
422
+ return tx;
423
+ }
424
+
425
+ /**
426
+ * Borrow asset from a lending pool
427
+ * @param {Dapp} dapp Platform like Aave
428
+ * @param {string} asset Asset
429
+ * @param {BigNumber | string} amount Amount of asset to lend
430
+ * @param {any} options Transaction options
431
+ * @returns {Promise<any>} Transaction
432
+ */
433
+ async borrow(
434
+ dapp: Dapp,
435
+ asset: string,
436
+ amount: BigNumber | string,
437
+ options: any = null
438
+ ): Promise<any> {
439
+ const iLendingPool = new ethers.utils.Interface(ILendingPool.abi);
440
+ const borrowTxData = iLendingPool.encodeFunctionData(Transaction.BORROW, [
441
+ asset,
442
+ amount,
443
+ 2,
444
+ 0,
445
+ this.address
446
+ ]);
447
+ const tx = await this.poolLogic.execTransaction(
448
+ routerAddress[this.network][dapp],
449
+ borrowTxData,
450
+ options
451
+ );
452
+ return tx;
453
+ }
454
+
455
+ /**
456
+ * Repays borrowed asset to a lending pool
457
+ * @param {Dapp} dapp Platform like Aave
458
+ * @param {string} asset Asset
459
+ * @param {BigNumber | string} amount Amount of asset to lend
460
+ * @param {any} options Transaction options
461
+ * @returns {Promise<any>} Transaction
462
+ */
463
+ async repay(
464
+ dapp: Dapp,
465
+ asset: string,
466
+ amount: BigNumber | string,
467
+ options: any = null
468
+ ): Promise<any> {
469
+ const iLendingPool = new ethers.utils.Interface(ILendingPool.abi);
470
+ const repayTxData = iLendingPool.encodeFunctionData(Transaction.REPAY, [
471
+ asset,
472
+ amount,
473
+ 2,
474
+ this.address
475
+ ]);
476
+ const tx = await this.poolLogic.execTransaction(
477
+ routerAddress[this.network][dapp],
478
+ repayTxData,
479
+ options
295
480
  );
296
481
  return tx;
297
482
  }
@@ -300,9 +485,14 @@ export class Pool {
300
485
  * Claim rewards of staked liquidity pool tokens
301
486
  * @param {Dapp} dapp Platform like Sushiswap or Uniswap
302
487
  * @param {string} asset Liquidity pool token
488
+ * @param {any} options Transaction options
303
489
  * @returns {Promise<any>} Transaction
304
490
  */
305
- async harvestRewards(dapp: Dapp, asset: string): Promise<any> {
491
+ async harvestRewards(
492
+ dapp: Dapp,
493
+ asset: string,
494
+ options: any = null
495
+ ): Promise<any> {
306
496
  const iMiniChefV2 = new ethers.utils.Interface(IMiniChefV2.abi);
307
497
  const poolId = await this.utils.getLpPoolId(dapp, asset);
308
498
  const harvestTxData = iMiniChefV2.encodeFunctionData(Transaction.HARVEST, [
@@ -311,7 +501,8 @@ export class Pool {
311
501
  ]);
312
502
  const tx = await this.poolLogic.execTransaction(
313
503
  stakingAddress[this.network][dapp],
314
- harvestTxData
504
+ harvestTxData,
505
+ options
315
506
  );
316
507
  return tx;
317
508
  }
@@ -319,9 +510,13 @@ export class Pool {
319
510
  /**
320
511
  * Change enabled pool assets
321
512
  * @param {AssetEnabled[]} assets New pool assets
513
+ * @param {any} options Transaction options
322
514
  * @returns {Promise<any>} Transaction
323
515
  */
324
- public async changeAssets(assets: AssetEnabled[]): Promise<any> {
516
+ public async changeAssets(
517
+ assets: AssetEnabled[],
518
+ options: any = null
519
+ ): Promise<any> {
325
520
  const currentAssetsEnabled = await this.getComposition();
326
521
  const currentAssets = currentAssetsEnabled.map(e =>
327
522
  e.asset.toLocaleLowerCase()
@@ -331,7 +526,8 @@ export class Pool {
331
526
  const changedAssets = assets.map(e => [e.asset, e.isDeposit]);
332
527
  const tx = await this.managerLogic.changeAssets(
333
528
  changedAssets,
334
- removedAssets
529
+ removedAssets,
530
+ options
335
531
  );
336
532
  return tx;
337
533
  }
@@ -339,10 +535,139 @@ export class Pool {
339
535
  /**
340
536
  * Set a new trader with trading permissions
341
537
  * @param {string} trader Address trader account
538
+ * @param {any} options Transaction options
539
+ * @returns {Promise<any>} Transaction
540
+ */
541
+ async setTrader(trader: string, options: any = null): Promise<any> {
542
+ const tx = await this.managerLogic.setTrader(trader, options);
543
+ return tx;
544
+ }
545
+
546
+ /**
547
+ * Invest into a Balancer pool
548
+ * @param {string} poolId Balancer pool id
549
+ * @param {string[] | } assetsIn Array of balancer pool assets
550
+ * @param {BigNumber[] | string[]} amountsIn Array of maximum amounts to provide to pool
551
+ * @param {any} options Transaction options
552
+ * @returns {Promise<any>} Transaction
553
+ */
554
+ async joinBalancerPool(
555
+ poolId: string,
556
+ assets: string[],
557
+ amountsIn: string[] | BigNumber[],
558
+ options: any = null
559
+ ): Promise<any> {
560
+ const joinPoolTxData = this.utils.getBalancerJoinPoolTx(
561
+ this,
562
+ poolId,
563
+ assets,
564
+ amountsIn
565
+ );
566
+ const tx = await this.poolLogic.execTransaction(
567
+ routerAddress[this.network][Dapp.BALANCER],
568
+ joinPoolTxData,
569
+ options
570
+ );
571
+ return tx;
572
+ }
573
+
574
+ /**
575
+ * Invest into a Balancer pool
576
+ * @param {string} poolId Balancer pool id
577
+ * @param {string[] | } assets Array of balancer pool assets
578
+ * @param {BigNumber | string } amount Amount of pool tokens to withdraw
579
+ * @param {any} options Transaction options
580
+ * @returns {Promise<any>} Transaction
581
+ */
582
+ async exitBalancerPool(
583
+ poolId: string,
584
+ assets: string[],
585
+ amount: string | BigNumber,
586
+ options: any = null
587
+ ): Promise<any> {
588
+ const exitPoolTxData = this.utils.getBalancerExitPoolTx(
589
+ this,
590
+ poolId,
591
+ assets,
592
+ amount
593
+ );
594
+ const tx = await this.poolLogic.execTransaction(
595
+ routerAddress[this.network][Dapp.BALANCER],
596
+ exitPoolTxData,
597
+ options
598
+ );
599
+ return tx;
600
+ }
601
+
602
+ /**
603
+ * Claim rewards from Balancer pools
604
+ * @param {string[]} assets Array of tokens being claimed
605
+ * @param {any} options Transaction options
606
+ * @returns {Promise<any>} Transaction
607
+ */
608
+ async harvestBalancerRewards(options: any = null): Promise<any> {
609
+ const claimService = new ClaimService(this.network, this.signer);
610
+ const multiTokenPendingClaims = await claimService.getMultiTokensPendingClaims(
611
+ this.address
612
+ );
613
+ const tokens = multiTokenPendingClaims.map(
614
+ tokenPendingClaims => tokenPendingClaims.tokenClaimInfo.token
615
+ );
616
+ const claims = await claimService.multiTokenClaimRewards(
617
+ this.address,
618
+ multiTokenPendingClaims
619
+ );
620
+ const iBalancerMerkleOrchard = new ethers.utils.Interface(
621
+ IBalancerMerkleOrchard.abi
622
+ );
623
+ const harvestTxData = iBalancerMerkleOrchard.encodeFunctionData(
624
+ Transaction.CLAIM_DISTRIBIUTIONS,
625
+ [this.address, claims, tokens]
626
+ );
627
+ const tx = await this.poolLogic.execTransaction(
628
+ stakingAddress[this.network][Dapp.BALANCER],
629
+ harvestTxData,
630
+ options
631
+ );
632
+ return tx;
633
+ }
634
+
635
+ /**
636
+ * Claim rewards from Aave platform
637
+ * @param {string[]} assets Aave tokens (deposit/debt) hold by pool
638
+ * @param {any} options Transaction options
342
639
  * @returns {Promise<any>} Transaction
343
640
  */
344
- async setTrader(trader: string): Promise<any> {
345
- const tx = await this.managerLogic.setTrader(trader);
641
+ async harvestAaveRewards(
642
+ assets: string[],
643
+ options: any = null
644
+ ): Promise<any> {
645
+ const aaveIncentivesAddress = stakingAddress[this.network][
646
+ Dapp.AAVE
647
+ ] as string;
648
+ const iAaveIncentivesController = new ethers.utils.Interface(
649
+ IAaveIncentivesController.abi
650
+ );
651
+ const aaveIncentivesController = new ethers.Contract(
652
+ aaveIncentivesAddress,
653
+ iAaveIncentivesController,
654
+ this.signer
655
+ );
656
+
657
+ const amount = await aaveIncentivesController.getUserUnclaimedRewards(
658
+ this.address
659
+ );
660
+
661
+ const claimTxData = iAaveIncentivesController.encodeFunctionData(
662
+ Transaction.CLAIM_REWARDS,
663
+ [assets, amount, this.address]
664
+ );
665
+
666
+ const tx = await this.poolLogic.execTransaction(
667
+ aaveIncentivesAddress,
668
+ claimTxData,
669
+ options
670
+ );
346
671
  return tx;
347
672
  }
348
673
  }