@dhedge/v2-sdk 1.9.5 → 1.9.6

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.
@@ -63,6 +63,7 @@ import {
63
63
  getCreateVestTxData,
64
64
  getExitVestTxData
65
65
  } from "../services/ramses/vesting";
66
+ import { getPoolTxOrGasEstimate } from "../utils/contract";
66
67
 
67
68
  export class Pool {
68
69
  public readonly poolLogic: Contract;
@@ -166,25 +167,27 @@ export class Pool {
166
167
  * Approve the asset for trading and providing liquidity
167
168
  * @param {Dapp} dapp Platform like Sushiswap or Uniswap
168
169
  * @param {string} asset Address of asset
169
- * @param @param {BigNumber | string} Amount to be approved
170
+ * @param {BigNumber | string} Amount to be approved
170
171
  * @param {any} options Transaction options
172
+ * @param {boolean} estimateGas Simulate/estimate gas
171
173
  * @returns {Promise<any>} Transaction
172
174
  */
173
175
  async approve(
174
176
  dapp: Dapp,
175
177
  asset: string,
176
178
  amount: BigNumber | string,
177
- options: any = null
179
+ options: any = null,
180
+ estimateGas = false
178
181
  ): Promise<any> {
179
182
  const iERC20 = new ethers.utils.Interface(IERC20.abi);
180
183
  const approveTxData = iERC20.encodeFunctionData("approve", [
181
184
  routerAddress[this.network][dapp],
182
185
  amount
183
186
  ]);
184
- const tx = await this.poolLogic.execTransaction(
185
- asset,
186
- approveTxData,
187
- options
187
+ const tx = await getPoolTxOrGasEstimate(
188
+ this,
189
+ [asset, approveTxData, options],
190
+ estimateGas
188
191
  );
189
192
  return tx;
190
193
  }
@@ -195,23 +198,25 @@ export class Pool {
195
198
  * @param {string} asset Address of liquidity pool token
196
199
  * @param {BigNumber | string} amount Aamount to be approved
197
200
  * @param {any} options Transaction options
201
+ * @param {boolean} estimateGas Simulate/estimate gas
198
202
  * @returns {Promise<any>} Transaction
199
203
  */
200
204
  async approveStaking(
201
205
  dapp: Dapp,
202
206
  asset: string,
203
207
  amount: BigNumber | string,
204
- options: any = null
208
+ options: any = null,
209
+ estimateGas = false
205
210
  ): Promise<any> {
206
211
  const iERC20 = new ethers.utils.Interface(IERC20.abi);
207
212
  const approveTxData = iERC20.encodeFunctionData("approve", [
208
213
  stakingAddress[this.network][dapp],
209
214
  amount
210
215
  ]);
211
- const tx = await this.poolLogic.execTransaction(
212
- asset,
213
- approveTxData,
214
- options
216
+ const tx = await getPoolTxOrGasEstimate(
217
+ this,
218
+ [asset, approveTxData, options],
219
+ estimateGas
215
220
  );
216
221
  return tx;
217
222
  }
@@ -222,22 +227,24 @@ export class Pool {
222
227
  * @param {string} asset Address of liquidity pool token
223
228
  * @param {BigNumber | string} amount Aamount to be approved
224
229
  * @param {any} options Transaction options
230
+ * @param {boolean} estimateGas Simulate/estimate gas
225
231
  * @returns {Promise<any>} Transaction
226
232
  */
227
233
  async approveUniswapV3Liquidity(
228
234
  asset: string,
229
235
  amount: BigNumber | string,
230
- options: any = null
236
+ options: any = null,
237
+ estimateGas = false
231
238
  ): Promise<any> {
232
239
  const iERC20 = new ethers.utils.Interface(IERC20.abi);
233
240
  const approveTxData = iERC20.encodeFunctionData("approve", [
234
241
  nonfungiblePositionManagerAddress[this.network],
235
242
  amount
236
243
  ]);
237
- const tx = await this.poolLogic.execTransaction(
238
- asset,
239
- approveTxData,
240
- options
244
+ const tx = await getPoolTxOrGasEstimate(
245
+ this,
246
+ [asset, approveTxData, options],
247
+ estimateGas
241
248
  );
242
249
  return tx;
243
250
  }
@@ -248,23 +255,25 @@ export class Pool {
248
255
  * @param {string} asset Address of asset
249
256
  * @param {BigNumber | string} amount to be approved
250
257
  * @param {any} options Transaction options
258
+ * @param {boolean} estimateGas Simulate/estimate gas
251
259
  * @returns {Promise<any>} Transaction
252
260
  */
253
261
  async approveSpender(
254
262
  spender: string,
255
263
  asset: string,
256
264
  amount: BigNumber | string,
257
- options: any = null
265
+ options: any = null,
266
+ estimateGas = false
258
267
  ): Promise<any> {
259
268
  const iERC20 = new ethers.utils.Interface(IERC20.abi);
260
269
  const approveTxData = iERC20.encodeFunctionData("approve", [
261
270
  spender,
262
271
  amount
263
272
  ]);
264
- const tx = await this.poolLogic.execTransaction(
265
- asset,
266
- approveTxData,
267
- options
273
+ const tx = await getPoolTxOrGasEstimate(
274
+ this,
275
+ [asset, approveTxData, options],
276
+ estimateGas
268
277
  );
269
278
  return tx;
270
279
  }
@@ -277,6 +286,7 @@ export class Pool {
277
286
  * @param {BigNumber | string} amountIn Amount
278
287
  * @param {number} slippage Slippage tolerance in %
279
288
  * @param {any} options Transaction options
289
+ * @param {boolean} estimateGas Simulate/estimate gas
280
290
  * @returns {Promise<any>} Transaction
281
291
  */
282
292
  async trade(
@@ -285,7 +295,8 @@ export class Pool {
285
295
  assetTo: string,
286
296
  amountIn: BigNumber | string,
287
297
  slippage = 0.5,
288
- options: any = null
298
+ options: any = null,
299
+ estimateGas = false
289
300
  ): Promise<any> {
290
301
  let swapTxData: string;
291
302
  switch (dapp) {
@@ -359,10 +370,10 @@ export class Pool {
359
370
  await getDeadline(this)
360
371
  ]);
361
372
  }
362
- const tx = await this.poolLogic.execTransaction(
363
- routerAddress[this.network][dapp],
364
- swapTxData,
365
- options
373
+ const tx = await getPoolTxOrGasEstimate(
374
+ this,
375
+ [routerAddress[this.network][dapp], swapTxData, options],
376
+ estimateGas
366
377
  );
367
378
  return tx;
368
379
  }
@@ -375,6 +386,7 @@ export class Pool {
375
386
  * @param {BigNumber | string} amountA Amount first asset
376
387
  * @param {BigNumber | string} amountB Amount second asset
377
388
  * @param {any} options Transaction options
389
+ * @param {boolean} estimateGas Simulate/estimate gas
378
390
  * @returns {Promise<any>} Transaction
379
391
  */
380
392
  async addLiquidity(
@@ -383,7 +395,8 @@ export class Pool {
383
395
  assetB: string,
384
396
  amountA: BigNumber | string,
385
397
  amountB: BigNumber | string,
386
- options: any = null
398
+ options: any = null,
399
+ estimateGas = false
387
400
  ): Promise<any> {
388
401
  const iUniswapV2Router = new ethers.utils.Interface(IUniswapV2Router.abi);
389
402
  const addLiquidityTxData = iUniswapV2Router.encodeFunctionData(
@@ -399,10 +412,10 @@ export class Pool {
399
412
  await getDeadline(this)
400
413
  ]
401
414
  );
402
- const tx = await this.poolLogic.execTransaction(
403
- routerAddress[this.network][dapp],
404
- addLiquidityTxData,
405
- options
415
+ const tx = await getPoolTxOrGasEstimate(
416
+ this,
417
+ [routerAddress[this.network][dapp], addLiquidityTxData, options],
418
+ estimateGas
406
419
  );
407
420
  return tx;
408
421
  }
@@ -414,6 +427,7 @@ export class Pool {
414
427
  * @param {string} assetB Second asset
415
428
  * @param {BigNumber | string} amount Amount of liquidity pool tokens
416
429
  * @param {any} options Transaction options
430
+ * @param {boolean} estimateGas Simulate/estimate gas
417
431
  * @returns {Promise<any>} Transaction
418
432
  */
419
433
  async removeLiquidity(
@@ -421,17 +435,18 @@ export class Pool {
421
435
  assetA: string,
422
436
  assetB: string,
423
437
  amount: string | BigNumber,
424
- options: any = null
438
+ options: any = null,
439
+ estimateGas = false
425
440
  ): Promise<any> {
426
441
  const iUniswapV2Router = new ethers.utils.Interface(IUniswapV2Router.abi);
427
442
  const removeLiquidityTxData = iUniswapV2Router.encodeFunctionData(
428
443
  Transaction.REMOVE_LIQUIDITY,
429
444
  [assetA, assetB, amount, 0, 0, this.address, await getDeadline(this)]
430
445
  );
431
- const tx = await this.poolLogic.execTransaction(
432
- routerAddress[this.network][dapp],
433
- removeLiquidityTxData,
434
- options
446
+ const tx = await getPoolTxOrGasEstimate(
447
+ this,
448
+ [routerAddress[this.network][dapp], removeLiquidityTxData, options],
449
+ estimateGas
435
450
  );
436
451
  return tx;
437
452
  }
@@ -442,13 +457,15 @@ export class Pool {
442
457
  * @param {string} asset Liquidity pool token
443
458
  * @param {BigNumber | string} amount Amount of liquidity pool tokens
444
459
  * @param {any} options Transaction options
460
+ * @param {boolean} estimateGas Simulate/estimate gas
445
461
  * @returns {Promise<any>} Transaction
446
462
  */
447
463
  async stake(
448
464
  dapp: Dapp,
449
465
  asset: string,
450
466
  amount: BigNumber | string,
451
- options: any = null
467
+ options: any = null,
468
+ estimateGas = false
452
469
  ): Promise<any> {
453
470
  const iMiniChefV2 = new ethers.utils.Interface(IMiniChefV2.abi);
454
471
  const poolId = await this.utils.getLpPoolId(dapp, asset);
@@ -457,10 +474,10 @@ export class Pool {
457
474
  amount,
458
475
  this.address
459
476
  ]);
460
- const tx = await this.poolLogic.execTransaction(
461
- stakingAddress[this.network][dapp],
462
- stakeTxData,
463
- options
477
+ const tx = await getPoolTxOrGasEstimate(
478
+ this,
479
+ [stakingAddress[this.network][dapp], stakeTxData, options],
480
+ estimateGas
464
481
  );
465
482
  return tx;
466
483
  }
@@ -471,13 +488,15 @@ export class Pool {
471
488
  * @param {string} gauge Gauge contract address
472
489
  * @param {BigNumber | string} amount Amount of liquidity pool tokens
473
490
  * @param {any} options Transaction options
491
+ * @param {boolean} estimateGas Simulate/estimate gas
474
492
  * @returns {Promise<any>} Transaction
475
493
  */
476
494
  async stakeInGauge(
477
495
  dapp: Dapp,
478
496
  gauge: string,
479
497
  amount: BigNumber | string,
480
- options: any = null
498
+ options: any = null,
499
+ estimateGas = false
481
500
  ): Promise<any> {
482
501
  let stakeTxData;
483
502
  switch (dapp) {
@@ -499,10 +518,10 @@ export class Pool {
499
518
  default:
500
519
  throw new Error("dapp not supported");
501
520
  }
502
- const tx = await this.poolLogic.execTransaction(
503
- gauge,
504
- stakeTxData,
505
- options
521
+ const tx = await getPoolTxOrGasEstimate(
522
+ this,
523
+ [gauge, stakeTxData, options],
524
+ estimateGas
506
525
  );
507
526
  return tx;
508
527
  }
@@ -513,13 +532,15 @@ export class Pool {
513
532
  * @param {string} asset Liquidity pool token
514
533
  * @param {BigNumber | string} amount Amount of liquidity pool tokens
515
534
  * @param {any} options Transaction options
535
+ * @param {boolean} estimateGas Simulate/estimate gas
516
536
  * @returns {Promise<any>} Transaction
517
537
  */
518
538
  async unStake(
519
539
  dapp: Dapp,
520
540
  asset: string,
521
541
  amount: BigNumber | string,
522
- options: any = null
542
+ options: any = null,
543
+ estimateGas = false
523
544
  ): Promise<any> {
524
545
  const iMiniChefV2 = new ethers.utils.Interface(IMiniChefV2.abi);
525
546
  const poolId = await this.utils.getLpPoolId(dapp, asset);
@@ -528,10 +549,10 @@ export class Pool {
528
549
  amount,
529
550
  this.address
530
551
  ]);
531
- const tx = await this.poolLogic.execTransaction(
532
- stakingAddress[this.network][dapp],
533
- unStakeTxData,
534
- options
552
+ const tx = await getPoolTxOrGasEstimate(
553
+ this,
554
+ [stakingAddress[this.network][dapp], unStakeTxData, options],
555
+ estimateGas
535
556
  );
536
557
  return tx;
537
558
  }
@@ -541,21 +562,23 @@ export class Pool {
541
562
  * @param {string} gauge Gauge contract address
542
563
  * @param {BigNumber | string} amount Amount of liquidity pool tokens
543
564
  * @param {any} options Transaction options
565
+ * @param {boolean} estimateGas Simulate/estimate gas
544
566
  * @returns {Promise<any>} Transaction
545
567
  */
546
568
  async unstakeFromGauge(
547
569
  gauge: string,
548
570
  amount: BigNumber | string,
549
- options: any = null
571
+ options: any = null,
572
+ estimateGas = false
550
573
  ): Promise<any> {
551
574
  const rewardsGauge = new ethers.utils.Interface(IBalancerRewardsGauge.abi);
552
575
  const unstakeTxData = rewardsGauge.encodeFunctionData("withdraw(uint256)", [
553
576
  amount
554
577
  ]);
555
- const tx = await this.poolLogic.execTransaction(
556
- gauge,
557
- unstakeTxData,
558
- options
578
+ const tx = await getPoolTxOrGasEstimate(
579
+ this,
580
+ [gauge, unstakeTxData, options],
581
+ estimateGas
559
582
  );
560
583
  return tx;
561
584
  }
@@ -567,6 +590,7 @@ export class Pool {
567
590
  * @param {BigNumber | string} amount Amount of asset to lend
568
591
  * @param {number} referralCode Code from Aave referral program
569
592
  * @param {any} options Transaction options
593
+ * @param {boolean} estimateGas Simulate/estimate gas
570
594
  * @returns {Promise<any>} Transaction
571
595
  */
572
596
  async lend(
@@ -574,7 +598,8 @@ export class Pool {
574
598
  asset: string,
575
599
  amount: BigNumber | string,
576
600
  referralCode = 0,
577
- options: any = null
601
+ options: any = null,
602
+ estimateGas = false
578
603
  ): Promise<any> {
579
604
  const iLendingPool = new ethers.utils.Interface(ILendingPool.abi);
580
605
  const depositTxData = iLendingPool.encodeFunctionData(Transaction.DEPOSIT, [
@@ -583,10 +608,10 @@ export class Pool {
583
608
  this.address,
584
609
  referralCode
585
610
  ]);
586
- const tx = await this.poolLogic.execTransaction(
587
- routerAddress[this.network][dapp],
588
- depositTxData,
589
- options
611
+ const tx = await getPoolTxOrGasEstimate(
612
+ this,
613
+ [routerAddress[this.network][dapp], depositTxData, options],
614
+ estimateGas
590
615
  );
591
616
  return tx;
592
617
  }
@@ -597,23 +622,25 @@ export class Pool {
597
622
  * @param {string} asset Asset
598
623
  * @param {BigNumber | string} amount Amount of asset to lend
599
624
  * @param {any} options Transaction options
625
+ * @param {boolean} estimateGas Simulate/estimate gas
600
626
  * @returns {Promise<any>} Transaction
601
627
  */
602
628
  async withdrawDeposit(
603
629
  dapp: Dapp,
604
630
  asset: string,
605
631
  amount: BigNumber | string,
606
- options: any = null
632
+ options: any = null,
633
+ estimateGas = false
607
634
  ): Promise<any> {
608
635
  const iLendingPool = new ethers.utils.Interface(ILendingPool.abi);
609
636
  const withdrawTxData = iLendingPool.encodeFunctionData(
610
637
  Transaction.WITHDRAW,
611
638
  [asset, amount, this.address]
612
639
  );
613
- const tx = await this.poolLogic.execTransaction(
614
- routerAddress[this.network][dapp],
615
- withdrawTxData,
616
- options
640
+ const tx = await getPoolTxOrGasEstimate(
641
+ this,
642
+ [routerAddress[this.network][dapp], withdrawTxData, options],
643
+ estimateGas
617
644
  );
618
645
  return tx;
619
646
  }
@@ -625,6 +652,7 @@ export class Pool {
625
652
  * @param {BigNumber | string} amount Amount of asset to lend
626
653
  * @param {number} referralCode Code from Aave referral program
627
654
  * @param {any} options Transaction options
655
+ * @param {boolean} estimateGas Simulate/estimate gas
628
656
  * @returns {Promise<any>} Transaction
629
657
  */
630
658
  async borrow(
@@ -632,7 +660,8 @@ export class Pool {
632
660
  asset: string,
633
661
  amount: BigNumber | string,
634
662
  referralCode = 0,
635
- options: any = null
663
+ options: any = null,
664
+ estimateGas = false
636
665
  ): Promise<any> {
637
666
  const iLendingPool = new ethers.utils.Interface(ILendingPool.abi);
638
667
  const borrowTxData = iLendingPool.encodeFunctionData(Transaction.BORROW, [
@@ -642,10 +671,10 @@ export class Pool {
642
671
  referralCode,
643
672
  this.address
644
673
  ]);
645
- const tx = await this.poolLogic.execTransaction(
646
- routerAddress[this.network][dapp],
647
- borrowTxData,
648
- options
674
+ const tx = await getPoolTxOrGasEstimate(
675
+ this,
676
+ [routerAddress[this.network][dapp], borrowTxData, options],
677
+ estimateGas
649
678
  );
650
679
  return tx;
651
680
  }
@@ -656,13 +685,15 @@ export class Pool {
656
685
  * @param {string} asset Asset
657
686
  * @param {BigNumber | string} amount Amount of asset to lend
658
687
  * @param {any} options Transaction options
688
+ * @param {boolean} estimateGas Simulate/estimate gas
659
689
  * @returns {Promise<any>} Transaction
660
690
  */
661
691
  async repay(
662
692
  dapp: Dapp,
663
693
  asset: string,
664
694
  amount: BigNumber | string,
665
- options: any = null
695
+ options: any = null,
696
+ estimateGas = false
666
697
  ): Promise<any> {
667
698
  const iLendingPool = new ethers.utils.Interface(ILendingPool.abi);
668
699
  const repayTxData = iLendingPool.encodeFunctionData(Transaction.REPAY, [
@@ -671,10 +702,10 @@ export class Pool {
671
702
  2,
672
703
  this.address
673
704
  ]);
674
- const tx = await this.poolLogic.execTransaction(
675
- routerAddress[this.network][dapp],
676
- repayTxData,
677
- options
705
+ const tx = await getPoolTxOrGasEstimate(
706
+ this,
707
+ [routerAddress[this.network][dapp], repayTxData, options],
708
+ estimateGas
678
709
  );
679
710
  return tx;
680
711
  }
@@ -683,13 +714,15 @@ export class Pool {
683
714
  * Claim rewards of staked liquidity pool tokens
684
715
  * @param {Dapp} dapp Platform like Sushiswap or Uniswap
685
716
  * @param {string} asset Liquidity pool token
686
- * @param {any} options Transaction options
717
+ * @param {any} options Transaction option
718
+ * @param {boolean} estimateGas Simulate/estimate gas
687
719
  * @returns {Promise<any>} Transaction
688
720
  */
689
721
  async harvestRewards(
690
722
  dapp: Dapp,
691
723
  asset: string,
692
- options: any = null
724
+ options: any = null,
725
+ estimateGas = false
693
726
  ): Promise<any> {
694
727
  const iMiniChefV2 = new ethers.utils.Interface(IMiniChefV2.abi);
695
728
  const poolId = await this.utils.getLpPoolId(dapp, asset);
@@ -697,10 +730,10 @@ export class Pool {
697
730
  poolId,
698
731
  this.address
699
732
  ]);
700
- const tx = await this.poolLogic.execTransaction(
701
- stakingAddress[this.network][dapp],
702
- harvestTxData,
703
- options
733
+ const tx = await getPoolTxOrGasEstimate(
734
+ this,
735
+ [stakingAddress[this.network][dapp], harvestTxData, options],
736
+ estimateGas
704
737
  );
705
738
  return tx;
706
739
  }
@@ -747,13 +780,15 @@ export class Pool {
747
780
  * @param {string[] | } assetsIn Array of balancer pool assets
748
781
  * @param {BigNumber[] | string[]} amountsIn Array of maximum amounts to provide to pool
749
782
  * @param {any} options Transaction options
783
+ * @param {boolean} estimateGas Simulate/estimate gas
750
784
  * @returns {Promise<any>} Transaction
751
785
  */
752
786
  async joinBalancerPool(
753
787
  poolId: string,
754
788
  assets: string[],
755
789
  amountsIn: string[] | BigNumber[],
756
- options: any = null
790
+ options: any = null,
791
+ estimateGas = false
757
792
  ): Promise<any> {
758
793
  const joinPoolTxData = this.utils.getBalancerJoinPoolTx(
759
794
  this,
@@ -761,10 +796,10 @@ export class Pool {
761
796
  assets,
762
797
  amountsIn
763
798
  );
764
- const tx = await this.poolLogic.execTransaction(
765
- routerAddress[this.network][Dapp.BALANCER],
766
- joinPoolTxData,
767
- options
799
+ const tx = await getPoolTxOrGasEstimate(
800
+ this,
801
+ [routerAddress[this.network][Dapp.BALANCER], joinPoolTxData, options],
802
+ estimateGas
768
803
  );
769
804
  return tx;
770
805
  }
@@ -776,6 +811,7 @@ export class Pool {
776
811
  * @param {BigNumber | string } amount Amount of pool tokens to withdraw
777
812
  * @param { null | number } singleExitAssetIndex Index of asset to withdraw to
778
813
  * @param {any} options Transaction options
814
+ * @param {boolean} estimateGas Simulate/estimate gas
779
815
  * @returns {Promise<any>} Transaction
780
816
  */
781
817
  async exitBalancerPool(
@@ -783,7 +819,8 @@ export class Pool {
783
819
  assets: string[],
784
820
  amount: string | BigNumber,
785
821
  singleExitAssetIndex: number | null = null,
786
- options: any = null
822
+ options: any = null,
823
+ estimateGas = false
787
824
  ): Promise<any> {
788
825
  const exitPoolTxData = this.utils.getBalancerExitPoolTx(
789
826
  this,
@@ -792,10 +829,10 @@ export class Pool {
792
829
  singleExitAssetIndex,
793
830
  amount
794
831
  );
795
- const tx = await this.poolLogic.execTransaction(
796
- routerAddress[this.network][Dapp.BALANCER],
797
- exitPoolTxData,
798
- options
832
+ const tx = await getPoolTxOrGasEstimate(
833
+ this,
834
+ [routerAddress[this.network][Dapp.BALANCER], exitPoolTxData, options],
835
+ estimateGas
799
836
  );
800
837
  return tx;
801
838
  }
@@ -804,11 +841,13 @@ export class Pool {
804
841
  * Claim rewards from Aave platform
805
842
  * @param {string[]} assets Aave tokens (deposit/debt) hold by pool
806
843
  * @param {any} options Transaction options
844
+ * @param {boolean} estimateGas Simulate/estimate gas
807
845
  * @returns {Promise<any>} Transaction
808
846
  */
809
847
  async harvestAaveRewards(
810
848
  assets: string[],
811
- options: any = null
849
+ options: any = null,
850
+ estimateGas = false
812
851
  ): Promise<any> {
813
852
  const aaveIncentivesAddress = stakingAddress[this.network][
814
853
  Dapp.AAVE
@@ -828,10 +867,10 @@ export class Pool {
828
867
  Transaction.CLAIM_REWARDS,
829
868
  [assets, amount, this.address]
830
869
  );
831
- const tx = await this.poolLogic.execTransaction(
832
- aaveIncentivesAddress,
833
- claimTxData,
834
- options
870
+ const tx = await getPoolTxOrGasEstimate(
871
+ this,
872
+ [aaveIncentivesAddress, claimTxData, options],
873
+ estimateGas
835
874
  );
836
875
  return tx;
837
876
  }
@@ -841,18 +880,24 @@ export class Pool {
841
880
  * @param {string[]} assets Assets invested in Aave
842
881
  * @param {string} rewardAssets Reward token address
843
882
  * @param {any} options Transaction options
883
+ * @param {boolean} estimateGas Simulate/estimate gas
844
884
  * @returns {Promise<any>} Transaction
845
885
  */
846
886
  async harvestAaveV3Rewards(
847
887
  assets: string[],
848
888
  rewardAsset: string,
849
- options: any = null
889
+ options: any = null,
890
+ estimateGas = false
850
891
  ): Promise<any> {
851
892
  const claimTxData = await getAaveV3ClaimTxData(this, assets, rewardAsset);
852
- const tx = await this.poolLogic.execTransaction(
853
- stakingAddress[this.network][Dapp.AAVEV3] as string,
854
- claimTxData,
855
- options
893
+ const tx = await getPoolTxOrGasEstimate(
894
+ this,
895
+ [
896
+ stakingAddress[this.network][Dapp.AAVEV3] as string,
897
+ claimTxData,
898
+ options
899
+ ],
900
+ estimateGas
856
901
  );
857
902
  return tx;
858
903
  }
@@ -869,6 +914,7 @@ export class Pool {
869
914
  * @param { number } maxTick Upper tick range
870
915
  * @param { FeeAmount } feeAmount Fee tier (Low 0.05%, Medium 0.3%, High 1%)
871
916
  * @param {any} options Transaction options
917
+ * @param {boolean} estimateGas Simulate/estimate gas
872
918
  * @returns {Promise<any>} Transaction
873
919
  */
874
920
  async addLiquidityUniswapV3(
@@ -881,7 +927,8 @@ export class Pool {
881
927
  minTick: number | null,
882
928
  maxTick: number | null,
883
929
  feeAmount: FeeAmount,
884
- options: any = null
930
+ options: any = null,
931
+ estimateGas = false
885
932
  ): Promise<any> {
886
933
  if (
887
934
  (minPrice === null || maxPrice === null) &&
@@ -909,10 +956,10 @@ export class Pool {
909
956
  Transaction.MINT,
910
957
  [mintTxParams]
911
958
  );
912
- const tx = await this.poolLogic.execTransaction(
913
- nonfungiblePositionManagerAddress[this.network],
914
- mintTxData,
915
- options
959
+ const tx = await getPoolTxOrGasEstimate(
960
+ this,
961
+ [nonfungiblePositionManagerAddress[this.network], mintTxData, options],
962
+ estimateGas
916
963
  );
917
964
  return tx;
918
965
  }
@@ -923,13 +970,15 @@ export class Pool {
923
970
  * @param {string} tokenId Token Id of UniswapV3 position
924
971
  * @param {number} amount Amount in percent of assets to be removed
925
972
  * @param {any} options Transaction options
973
+ * @param {boolean} estimateGas Simulate/estimate gas
926
974
  * @returns {Promise<any>} Transaction
927
975
  */
928
976
  async decreaseLiquidity(
929
977
  dapp: Dapp,
930
978
  tokenId: string,
931
979
  amount = 100,
932
- options: any = null
980
+ options: any = null,
981
+ estimateGas = false
933
982
  ): Promise<any> {
934
983
  let txData;
935
984
  let dappAddress;
@@ -972,11 +1021,10 @@ export class Pool {
972
1021
  } else {
973
1022
  throw new Error("dapp not supported");
974
1023
  }
975
-
976
- const tx = await this.poolLogic.execTransaction(
977
- dappAddress,
978
- txData,
979
- options
1024
+ const tx = await getPoolTxOrGasEstimate(
1025
+ this,
1026
+ [dappAddress, txData, options],
1027
+ estimateGas
980
1028
  );
981
1029
  return tx;
982
1030
  }
@@ -988,6 +1036,7 @@ export class Pool {
988
1036
  * @param {BigNumber | string} amountA Amount first asset
989
1037
  * @param {BigNumber | string} amountB Amount second asset
990
1038
  * @param {any} options Transaction options
1039
+ * @param {boolean} estimateGas Simulate/estimate gas
991
1040
  * @returns {Promise<any>} Transaction
992
1041
  */
993
1042
  async increaseLiquidity(
@@ -995,7 +1044,8 @@ export class Pool {
995
1044
  tokenId: string,
996
1045
  amountA: BigNumber | string,
997
1046
  amountB: BigNumber | string,
998
- options: any = null
1047
+ options: any = null,
1048
+ estimateGas = false
999
1049
  ): Promise<any> {
1000
1050
  let txData;
1001
1051
  let dappAddress;
@@ -1020,11 +1070,10 @@ export class Pool {
1020
1070
  } else {
1021
1071
  throw new Error("dapp not supported");
1022
1072
  }
1023
-
1024
- const tx = await this.poolLogic.execTransaction(
1025
- dappAddress,
1026
- txData,
1027
- options
1073
+ const tx = await getPoolTxOrGasEstimate(
1074
+ this,
1075
+ [dappAddress, txData, options],
1076
+ estimateGas
1028
1077
  );
1029
1078
  return tx;
1030
1079
  }
@@ -1034,12 +1083,14 @@ export class Pool {
1034
1083
  * @param {Dapp} dapp Platform either UniswapV3 or Arrakis
1035
1084
  * @param {string} tokenId Token Id of UniswapV3 or Gauge address
1036
1085
  * @param {any} options Transaction option
1086
+ * @param {boolean} estimateGas Simulate/estimate gas
1037
1087
  * @returns {Promise<any>} Transaction
1038
1088
  */
1039
1089
  async claimFees(
1040
1090
  dapp: Dapp,
1041
1091
  tokenId: string,
1042
- options: any = null
1092
+ options: any = null,
1093
+ estimateGas = false
1043
1094
  ): Promise<any> {
1044
1095
  let txData;
1045
1096
  let contractAddress;
@@ -1072,10 +1123,10 @@ export class Pool {
1072
1123
  default:
1073
1124
  throw new Error("dapp not supported");
1074
1125
  }
1075
- const tx = await this.poolLogic.execTransaction(
1076
- contractAddress,
1077
- txData,
1078
- options
1126
+ const tx = await getPoolTxOrGasEstimate(
1127
+ this,
1128
+ [contractAddress, txData, options],
1129
+ estimateGas
1079
1130
  );
1080
1131
  return tx;
1081
1132
  }
@@ -1089,6 +1140,7 @@ export class Pool {
1089
1140
  * @param { FeeAmount } feeAmount Fee tier (Low 0.05%, Medium 0.3%, High 1%)
1090
1141
  * @param {number} slippage Slippage tolerance in %
1091
1142
  * @param {any} options Transaction options
1143
+ * @param {boolean} estimateGas Simulate/estimate gas
1092
1144
  * @returns {Promise<any>} Transaction
1093
1145
  */
1094
1146
  async tradeUniswapV3(
@@ -1097,7 +1149,8 @@ export class Pool {
1097
1149
  amountIn: BigNumber | string,
1098
1150
  feeAmount: FeeAmount,
1099
1151
  slippage = 0.5,
1100
- options: any = null
1152
+ options: any = null,
1153
+ estimateGas = false
1101
1154
  ): Promise<any> {
1102
1155
  const swapxData = await getUniswapV3SwapTxData(
1103
1156
  this,
@@ -1107,10 +1160,10 @@ export class Pool {
1107
1160
  slippage,
1108
1161
  feeAmount
1109
1162
  );
1110
- const tx = await this.poolLogic.execTransaction(
1111
- routerAddress[this.network][Dapp.UNISWAPV3],
1112
- swapxData,
1113
- options
1163
+ const tx = await getPoolTxOrGasEstimate(
1164
+ this,
1165
+ [routerAddress[this.network][Dapp.UNISWAPV3], swapxData, options],
1166
+ estimateGas
1114
1167
  );
1115
1168
  return tx;
1116
1169
  }
@@ -1123,6 +1176,7 @@ export class Pool {
1123
1176
  * @param {BigNumber | string} amountB Amount second asset
1124
1177
  * @param { boolean } isStable Is stable pool
1125
1178
  * @param {any} options Transaction options
1179
+ * @param {boolean} estimateGas Simulate/estimate gas
1126
1180
  * @returns {Promise<any>} Transaction
1127
1181
  */
1128
1182
  async addLiquidityVelodrome(
@@ -1131,19 +1185,24 @@ export class Pool {
1131
1185
  amountA: BigNumber | string,
1132
1186
  amountB: BigNumber | string,
1133
1187
  isStable: boolean,
1134
- options: any = null
1188
+ options: any = null,
1189
+ estimateGas = false
1135
1190
  ): Promise<any> {
1136
- const tx = await this.poolLogic.execTransaction(
1137
- routerAddress[this.network][Dapp.VELODROME],
1138
- await getVelodromeAddLiquidityTxData(
1139
- this,
1140
- assetA,
1141
- assetB,
1142
- amountA,
1143
- amountB,
1144
- isStable
1145
- ),
1146
- options
1191
+ const tx = await getPoolTxOrGasEstimate(
1192
+ this,
1193
+ [
1194
+ routerAddress[this.network][Dapp.VELODROME],
1195
+ await getVelodromeAddLiquidityTxData(
1196
+ this,
1197
+ assetA,
1198
+ assetB,
1199
+ amountA,
1200
+ amountB,
1201
+ isStable
1202
+ ),
1203
+ options
1204
+ ],
1205
+ estimateGas
1147
1206
  );
1148
1207
  return tx;
1149
1208
  }
@@ -1155,6 +1214,7 @@ export class Pool {
1155
1214
  * @param {BigNumber | string} amount Amount of LP tokens
1156
1215
  * @param { boolean } isStable Is stable pool
1157
1216
  * @param {any} options Transaction options
1217
+ * @param {boolean} estimateGas Simulate/estimate gas
1158
1218
  * @returns {Promise<any>} Transaction
1159
1219
  */
1160
1220
  async removeLiquidityVelodrome(
@@ -1162,18 +1222,23 @@ export class Pool {
1162
1222
  assetB: string,
1163
1223
  amount: BigNumber | string,
1164
1224
  isStable: boolean,
1165
- options: any = null
1225
+ options: any = null,
1226
+ estimateGas = false
1166
1227
  ): Promise<any> {
1167
- const tx = await this.poolLogic.execTransaction(
1168
- routerAddress[this.network][Dapp.VELODROME],
1169
- await getVelodromeRemoveLiquidityTxData(
1170
- this,
1171
- assetA,
1172
- assetB,
1173
- amount,
1174
- isStable
1175
- ),
1176
- options
1228
+ const tx = await getPoolTxOrGasEstimate(
1229
+ this,
1230
+ [
1231
+ routerAddress[this.network][Dapp.VELODROME],
1232
+ await getVelodromeRemoveLiquidityTxData(
1233
+ this,
1234
+ assetA,
1235
+ assetB,
1236
+ amount,
1237
+ isStable
1238
+ ),
1239
+ options
1240
+ ],
1241
+ estimateGas
1177
1242
  );
1178
1243
  return tx;
1179
1244
  }
@@ -1186,6 +1251,7 @@ export class Pool {
1186
1251
  * @param {BigNumber | string} amountB Amount second asset
1187
1252
  * @param { boolean } isStable Is stable pool
1188
1253
  * @param {any} options Transaction options
1254
+ * @param {boolean} estimateGas Simulate/estimate gas
1189
1255
  * @returns {Promise<any>} Transaction
1190
1256
  */
1191
1257
  async addLiquidityVelodromeV2(
@@ -1194,19 +1260,24 @@ export class Pool {
1194
1260
  amountA: BigNumber | string,
1195
1261
  amountB: BigNumber | string,
1196
1262
  isStable: boolean,
1197
- options: any = null
1263
+ options: any = null,
1264
+ estimateGas = false
1198
1265
  ): Promise<any> {
1199
- const tx = await this.poolLogic.execTransaction(
1200
- routerAddress[this.network][Dapp.VELODROMEV2],
1201
- await getVelodromeAddLiquidityTxData(
1202
- this,
1203
- assetA,
1204
- assetB,
1205
- amountA,
1206
- amountB,
1207
- isStable
1208
- ),
1209
- options
1266
+ const tx = await getPoolTxOrGasEstimate(
1267
+ this,
1268
+ [
1269
+ routerAddress[this.network][Dapp.VELODROMEV2],
1270
+ await getVelodromeAddLiquidityTxData(
1271
+ this,
1272
+ assetA,
1273
+ assetB,
1274
+ amountA,
1275
+ amountB,
1276
+ isStable
1277
+ ),
1278
+ options
1279
+ ],
1280
+ estimateGas
1210
1281
  );
1211
1282
  return tx;
1212
1283
  }
@@ -1218,6 +1289,7 @@ export class Pool {
1218
1289
  * @param {BigNumber | string} amount Amount of LP tokens
1219
1290
  * @param { boolean } isStable Is stable pool
1220
1291
  * @param {any} options Transaction options
1292
+ * @param {boolean} estimateGas Simulate/estimate gas
1221
1293
  * @returns {Promise<any>} Transaction
1222
1294
  */
1223
1295
  async removeLiquidityVelodromeV2(
@@ -1225,18 +1297,23 @@ export class Pool {
1225
1297
  assetB: string,
1226
1298
  amount: BigNumber | string,
1227
1299
  isStable: boolean,
1228
- options: any = null
1300
+ options: any = null,
1301
+ estimateGas = false
1229
1302
  ): Promise<any> {
1230
- const tx = await this.poolLogic.execTransaction(
1231
- routerAddress[this.network][Dapp.VELODROMEV2],
1232
- await getVelodromeRemoveLiquidityTxData(
1233
- this,
1234
- assetA,
1235
- assetB,
1236
- amount,
1237
- isStable
1238
- ),
1239
- options
1303
+ const tx = await getPoolTxOrGasEstimate(
1304
+ this,
1305
+ [
1306
+ routerAddress[this.network][Dapp.VELODROMEV2],
1307
+ await getVelodromeRemoveLiquidityTxData(
1308
+ this,
1309
+ assetA,
1310
+ assetB,
1311
+ amount,
1312
+ isStable
1313
+ ),
1314
+ options
1315
+ ],
1316
+ estimateGas
1240
1317
  );
1241
1318
  return tx;
1242
1319
  }
@@ -1250,6 +1327,7 @@ export class Pool {
1250
1327
  * @param {BigNumber | string} amountB Amount second asset
1251
1328
  * @param { boolean } isStable Is stable pool
1252
1329
  * @param {any} options Transaction options
1330
+ * @param {boolean} estimateGas Simulate/estimate gas
1253
1331
  * @returns {Promise<any>} Transaction
1254
1332
  */
1255
1333
  async addLiquidityV2(
@@ -1259,19 +1337,24 @@ export class Pool {
1259
1337
  amountA: BigNumber | string,
1260
1338
  amountB: BigNumber | string,
1261
1339
  isStable: boolean,
1262
- options: any = null
1340
+ options: any = null,
1341
+ estimateGas = false
1263
1342
  ): Promise<any> {
1264
- const tx = await this.poolLogic.execTransaction(
1265
- routerAddress[this.network][dapp],
1266
- await getVelodromeAddLiquidityTxData(
1267
- this,
1268
- assetA,
1269
- assetB,
1270
- amountA,
1271
- amountB,
1272
- isStable
1273
- ),
1274
- options
1343
+ const tx = await getPoolTxOrGasEstimate(
1344
+ this,
1345
+ [
1346
+ routerAddress[this.network][dapp],
1347
+ await getVelodromeAddLiquidityTxData(
1348
+ this,
1349
+ assetA,
1350
+ assetB,
1351
+ amountA,
1352
+ amountB,
1353
+ isStable
1354
+ ),
1355
+ options
1356
+ ],
1357
+ estimateGas
1275
1358
  );
1276
1359
  return tx;
1277
1360
  }
@@ -1284,6 +1367,7 @@ export class Pool {
1284
1367
  * @param {BigNumber | string} amount Amount of LP tokens
1285
1368
  * @param { boolean } isStable Is stable pool
1286
1369
  * @param {any} options Transaction options
1370
+ * @param {boolean} estimateGas Simulate/estimate gas
1287
1371
  * @returns {Promise<any>} Transaction
1288
1372
  */
1289
1373
  async removeLiquidityV2(
@@ -1292,18 +1376,23 @@ export class Pool {
1292
1376
  assetB: string,
1293
1377
  amount: BigNumber | string,
1294
1378
  isStable: boolean,
1295
- options: any = null
1379
+ options: any = null,
1380
+ estimateGas = false
1296
1381
  ): Promise<any> {
1297
- const tx = await this.poolLogic.execTransaction(
1298
- routerAddress[this.network][dapp],
1299
- await getVelodromeRemoveLiquidityTxData(
1300
- this,
1301
- assetA,
1302
- assetB,
1303
- amount,
1304
- isStable
1305
- ),
1306
- options
1382
+ const tx = await getPoolTxOrGasEstimate(
1383
+ this,
1384
+ [
1385
+ routerAddress[this.network][dapp],
1386
+ await getVelodromeRemoveLiquidityTxData(
1387
+ this,
1388
+ assetA,
1389
+ assetB,
1390
+ amount,
1391
+ isStable
1392
+ ),
1393
+ options
1394
+ ],
1395
+ estimateGas
1307
1396
  );
1308
1397
  return tx;
1309
1398
  }
@@ -1320,6 +1409,7 @@ export class Pool {
1320
1409
  * @param {BigNumber | string } collateralChangeAmount Collateral amount to add when shorting options and to remove when covering shorts
1321
1410
  * @param {boolean} isCoveredCall Selling covered call options
1322
1411
  * @param {any} options Transaction options
1412
+ * @param {boolean} estimateGas Simulate/estimate gas
1323
1413
  * @returns {Promise<any>} Transaction
1324
1414
  */
1325
1415
  async tradeLyraOption(
@@ -1332,7 +1422,8 @@ export class Pool {
1332
1422
  assetIn: string,
1333
1423
  collateralChangeAmount: BigNumber | string = "0",
1334
1424
  isCoveredCall = false,
1335
- options: any = null
1425
+ options: any = null,
1426
+ estimateGas = false
1336
1427
  ): Promise<any> {
1337
1428
  const swapxData = await getLyraOptionTxData(
1338
1429
  this,
@@ -1346,10 +1437,10 @@ export class Pool {
1346
1437
  BigNumber.from(collateralChangeAmount),
1347
1438
  isCoveredCall
1348
1439
  );
1349
- const tx = await this.poolLogic.execTransaction(
1350
- routerAddress[this.network][Dapp.LYRA],
1351
- swapxData,
1352
- options
1440
+ const tx = await getPoolTxOrGasEstimate(
1441
+ this,
1442
+ [routerAddress[this.network][Dapp.LYRA], swapxData, options],
1443
+ estimateGas
1353
1444
  );
1354
1445
  return tx;
1355
1446
  }
@@ -1367,17 +1458,19 @@ export class Pool {
1367
1458
  * @param {string} market Address of futures market
1368
1459
  * @param {BigNumber | string } changeAmount Amount to increase/decrease margin
1369
1460
  * @param {any} options Transaction options
1461
+ * @param {boolean} estimateGas Simulate/estimate gas
1370
1462
  * @returns {Promise<any>} Transaction
1371
1463
  */
1372
1464
  async changeFuturesMargin(
1373
1465
  market: string,
1374
1466
  changeAmount: BigNumber | string,
1375
- options: any = null
1467
+ options: any = null,
1468
+ estimateGas = false
1376
1469
  ): Promise<any> {
1377
- const tx = await this.poolLogic.execTransaction(
1378
- market,
1379
- getFuturesChangeMarginTxData(changeAmount),
1380
- options
1470
+ const tx = await getPoolTxOrGasEstimate(
1471
+ this,
1472
+ [market, getFuturesChangeMarginTxData(changeAmount), options],
1473
+ estimateGas
1381
1474
  );
1382
1475
  return tx;
1383
1476
  }
@@ -1387,19 +1480,25 @@ export class Pool {
1387
1480
  * @param {string} market Address of futures market
1388
1481
  * @param {BigNumber | string } changeAmount Negative for short, positive for long
1389
1482
  * @param {any} options Transaction options
1483
+ * @param {boolean} estimateGas Simulate/estimate gas
1390
1484
  * @returns {Promise<any>} Transaction
1391
1485
  */
1392
1486
  async changeFuturesPosition(
1393
1487
  market: string,
1394
1488
  changeAmount: BigNumber | string,
1395
- options: any = null
1489
+ options: any = null,
1490
+ estimateGas = false
1396
1491
  ): Promise<any> {
1397
1492
  const txData = await getFuturesChangePositionTxData(
1398
1493
  changeAmount,
1399
1494
  market,
1400
1495
  this
1401
1496
  );
1402
- const tx = await this.poolLogic.execTransaction(market, txData, options);
1497
+ const tx = await getPoolTxOrGasEstimate(
1498
+ this,
1499
+ [market, txData, options],
1500
+ estimateGas
1501
+ );
1403
1502
  return tx;
1404
1503
  }
1405
1504
 
@@ -1407,11 +1506,20 @@ export class Pool {
1407
1506
  *
1408
1507
  * @param {string} market Address of futures market
1409
1508
  * @param {any} options Transaction options
1509
+ * @param {boolean} estimateGas Simulate/estimate gas
1410
1510
  * @returns {Promise<any>} Transaction
1411
1511
  */
1412
- async cancelFuturesOrder(market: string, options: any = null): Promise<any> {
1512
+ async cancelFuturesOrder(
1513
+ market: string,
1514
+ options: any = null,
1515
+ estimateGas = false
1516
+ ): Promise<any> {
1413
1517
  const txData = await getFuturesCancelOrderTxData(this);
1414
- const tx = await this.poolLogic.execTransaction(market, txData, options);
1518
+ const tx = await getPoolTxOrGasEstimate(
1519
+ this,
1520
+ [market, txData, options],
1521
+ estimateGas
1522
+ );
1415
1523
  return tx;
1416
1524
  }
1417
1525
 
@@ -1439,18 +1547,20 @@ export class Pool {
1439
1547
  * @param {string} tokenAddress Address of the token to vest
1440
1548
  * @param {BigNumber | string } changeAmount Negative for short, positive for long
1441
1549
  * @param {any} options Transaction options
1550
+ * @param {boolean} estimateGas Simulate/estimate gas
1442
1551
  * @returns {Promise<any>} Transaction
1443
1552
  */
1444
1553
  async vestTokens(
1445
1554
  tokenAddress: string,
1446
1555
  amount: BigNumber | string,
1447
- options: any = null
1556
+ options: any = null,
1557
+ estimateGas = false
1448
1558
  ): Promise<any> {
1449
1559
  const txData = await getCreateVestTxData(amount);
1450
- const tx = await this.poolLogic.execTransaction(
1451
- tokenAddress,
1452
- txData,
1453
- options
1560
+ const tx = await getPoolTxOrGasEstimate(
1561
+ this,
1562
+ [tokenAddress, txData, options],
1563
+ estimateGas
1454
1564
  );
1455
1565
  return tx;
1456
1566
  }
@@ -1460,18 +1570,20 @@ export class Pool {
1460
1570
  * @param {string} tokenAddress Address of the token to vest
1461
1571
  * @param {number } id position Id of the vested tokens
1462
1572
  * @param {any} options Transaction options
1573
+ * @param {boolean} estimateGas Simulate/estimate gas
1463
1574
  * @returns {Promise<any>} Transaction
1464
1575
  */
1465
1576
  async exitVestedToken(
1466
1577
  tokenAddress: string,
1467
1578
  id: number,
1468
- options: any = null
1579
+ options: any = null,
1580
+ estimateGas = false
1469
1581
  ): Promise<any> {
1470
1582
  const txData = await getExitVestTxData(id);
1471
- const tx = await this.poolLogic.execTransaction(
1472
- tokenAddress,
1473
- txData,
1474
- options
1583
+ const tx = await getPoolTxOrGasEstimate(
1584
+ this,
1585
+ [tokenAddress, txData, options],
1586
+ estimateGas
1475
1587
  );
1476
1588
  return tx;
1477
1589
  }