@dhedge/v2-sdk 1.9.5 → 1.9.7
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/README.md +213 -76
- package/dist/entities/pool.d.ts +88 -45
- package/dist/test/constants.d.ts +22 -0
- package/dist/test/utils/testingHelper.d.ts +1 -0
- package/dist/utils/contract.d.ts +2 -1
- package/dist/v2-sdk.cjs.development.js +1109 -477
- package/dist/v2-sdk.cjs.development.js.map +1 -1
- package/dist/v2-sdk.cjs.production.min.js +1 -1
- package/dist/v2-sdk.cjs.production.min.js.map +1 -1
- package/dist/v2-sdk.esm.js +1109 -477
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/PoolLogic.json +349 -63
- package/src/config.ts +1 -1
- package/src/entities/pool.ts +380 -228
- package/src/test/arrakis.test.ts +119 -75
- package/src/test/constants.ts +32 -4
- package/src/test/oneInch.test.ts +34 -2
- package/src/test/uniswap.test.ts +101 -72
- package/src/test/utils/testingHelper.ts +4 -0
- package/src/utils/contract.ts +17 -1
- package/dist/utils/index.d.ts +0 -7
- package/dist/utils/merkle.d.ts +0 -22
- package/src/utils/index.ts +0 -38
- package/src/utils/merkle.ts +0 -172
package/src/entities/pool.ts
CHANGED
|
@@ -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;
|
|
@@ -118,14 +119,19 @@ export class Pool {
|
|
|
118
119
|
* @param {string} nasset Address of deposit asset
|
|
119
120
|
* @param {BigNumber | string} amount Amount to be approved
|
|
120
121
|
* @param {any} options Transaction options
|
|
122
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
121
123
|
* @returns {Promise<any>} Transaction
|
|
122
124
|
*/
|
|
123
125
|
async approveDeposit(
|
|
124
126
|
asset: string,
|
|
125
127
|
amount: BigNumber | string,
|
|
126
|
-
options: any = null
|
|
128
|
+
options: any = null,
|
|
129
|
+
estimateGas = false
|
|
127
130
|
): Promise<any> {
|
|
128
131
|
const iERC20 = new ethers.Contract(asset, IERC20.abi, this.signer);
|
|
132
|
+
if (estimateGas) {
|
|
133
|
+
return await iERC20.estimateGas.approve(this.address, amount, options);
|
|
134
|
+
}
|
|
129
135
|
const tx = await iERC20.approve(this.address, amount, options);
|
|
130
136
|
return tx;
|
|
131
137
|
}
|
|
@@ -135,13 +141,18 @@ export class Pool {
|
|
|
135
141
|
* @param {string} asset Address of asset
|
|
136
142
|
* @param {BigNumber | string} amount Amount to be deposited
|
|
137
143
|
* @param {any} options Transaction options
|
|
144
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
138
145
|
* @returns {Promise<any>} Transaction
|
|
139
146
|
*/
|
|
140
147
|
async deposit(
|
|
141
148
|
asset: string,
|
|
142
149
|
amount: string | BigNumber,
|
|
143
|
-
options: any = null
|
|
150
|
+
options: any = null,
|
|
151
|
+
estimateGas = false
|
|
144
152
|
): Promise<any> {
|
|
153
|
+
if (estimateGas) {
|
|
154
|
+
return await this.poolLogic.estimateGas.deposit(asset, amount, options);
|
|
155
|
+
}
|
|
145
156
|
const tx = await this.poolLogic.deposit(asset, amount, options);
|
|
146
157
|
return tx;
|
|
147
158
|
}
|
|
@@ -150,12 +161,20 @@ export class Pool {
|
|
|
150
161
|
* Withdraw assets from a pool
|
|
151
162
|
* @param fundTokenAmount Amount of pool tokens to be withdrawn
|
|
152
163
|
* @param {any} options Transaction options
|
|
164
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
153
165
|
* @returns {Promise<any>} Transaction
|
|
154
166
|
*/
|
|
155
167
|
async withdraw(
|
|
156
168
|
fundTokenAmount: string | BigNumber,
|
|
157
|
-
options: any = null
|
|
169
|
+
options: any = null,
|
|
170
|
+
estimateGas = false
|
|
158
171
|
): Promise<any> {
|
|
172
|
+
if (estimateGas) {
|
|
173
|
+
return await this.poolLogic.estimateGas.withdraw(
|
|
174
|
+
fundTokenAmount,
|
|
175
|
+
options
|
|
176
|
+
);
|
|
177
|
+
}
|
|
159
178
|
const tx = await this.poolLogic.withdraw(fundTokenAmount, options);
|
|
160
179
|
return tx;
|
|
161
180
|
}
|
|
@@ -166,25 +185,27 @@ export class Pool {
|
|
|
166
185
|
* Approve the asset for trading and providing liquidity
|
|
167
186
|
* @param {Dapp} dapp Platform like Sushiswap or Uniswap
|
|
168
187
|
* @param {string} asset Address of asset
|
|
169
|
-
* @param
|
|
188
|
+
* @param {BigNumber | string} Amount to be approved
|
|
170
189
|
* @param {any} options Transaction options
|
|
190
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
171
191
|
* @returns {Promise<any>} Transaction
|
|
172
192
|
*/
|
|
173
193
|
async approve(
|
|
174
194
|
dapp: Dapp,
|
|
175
195
|
asset: string,
|
|
176
196
|
amount: BigNumber | string,
|
|
177
|
-
options: any = null
|
|
197
|
+
options: any = null,
|
|
198
|
+
estimateGas = false
|
|
178
199
|
): Promise<any> {
|
|
179
200
|
const iERC20 = new ethers.utils.Interface(IERC20.abi);
|
|
180
201
|
const approveTxData = iERC20.encodeFunctionData("approve", [
|
|
181
202
|
routerAddress[this.network][dapp],
|
|
182
203
|
amount
|
|
183
204
|
]);
|
|
184
|
-
const tx = await
|
|
185
|
-
|
|
186
|
-
approveTxData,
|
|
187
|
-
|
|
205
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
206
|
+
this,
|
|
207
|
+
[asset, approveTxData, options],
|
|
208
|
+
estimateGas
|
|
188
209
|
);
|
|
189
210
|
return tx;
|
|
190
211
|
}
|
|
@@ -195,23 +216,25 @@ export class Pool {
|
|
|
195
216
|
* @param {string} asset Address of liquidity pool token
|
|
196
217
|
* @param {BigNumber | string} amount Aamount to be approved
|
|
197
218
|
* @param {any} options Transaction options
|
|
219
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
198
220
|
* @returns {Promise<any>} Transaction
|
|
199
221
|
*/
|
|
200
222
|
async approveStaking(
|
|
201
223
|
dapp: Dapp,
|
|
202
224
|
asset: string,
|
|
203
225
|
amount: BigNumber | string,
|
|
204
|
-
options: any = null
|
|
226
|
+
options: any = null,
|
|
227
|
+
estimateGas = false
|
|
205
228
|
): Promise<any> {
|
|
206
229
|
const iERC20 = new ethers.utils.Interface(IERC20.abi);
|
|
207
230
|
const approveTxData = iERC20.encodeFunctionData("approve", [
|
|
208
231
|
stakingAddress[this.network][dapp],
|
|
209
232
|
amount
|
|
210
233
|
]);
|
|
211
|
-
const tx = await
|
|
212
|
-
|
|
213
|
-
approveTxData,
|
|
214
|
-
|
|
234
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
235
|
+
this,
|
|
236
|
+
[asset, approveTxData, options],
|
|
237
|
+
estimateGas
|
|
215
238
|
);
|
|
216
239
|
return tx;
|
|
217
240
|
}
|
|
@@ -222,22 +245,24 @@ export class Pool {
|
|
|
222
245
|
* @param {string} asset Address of liquidity pool token
|
|
223
246
|
* @param {BigNumber | string} amount Aamount to be approved
|
|
224
247
|
* @param {any} options Transaction options
|
|
248
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
225
249
|
* @returns {Promise<any>} Transaction
|
|
226
250
|
*/
|
|
227
251
|
async approveUniswapV3Liquidity(
|
|
228
252
|
asset: string,
|
|
229
253
|
amount: BigNumber | string,
|
|
230
|
-
options: any = null
|
|
254
|
+
options: any = null,
|
|
255
|
+
estimateGas = false
|
|
231
256
|
): Promise<any> {
|
|
232
257
|
const iERC20 = new ethers.utils.Interface(IERC20.abi);
|
|
233
258
|
const approveTxData = iERC20.encodeFunctionData("approve", [
|
|
234
259
|
nonfungiblePositionManagerAddress[this.network],
|
|
235
260
|
amount
|
|
236
261
|
]);
|
|
237
|
-
const tx = await
|
|
238
|
-
|
|
239
|
-
approveTxData,
|
|
240
|
-
|
|
262
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
263
|
+
this,
|
|
264
|
+
[asset, approveTxData, options],
|
|
265
|
+
estimateGas
|
|
241
266
|
);
|
|
242
267
|
return tx;
|
|
243
268
|
}
|
|
@@ -248,23 +273,25 @@ export class Pool {
|
|
|
248
273
|
* @param {string} asset Address of asset
|
|
249
274
|
* @param {BigNumber | string} amount to be approved
|
|
250
275
|
* @param {any} options Transaction options
|
|
276
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
251
277
|
* @returns {Promise<any>} Transaction
|
|
252
278
|
*/
|
|
253
279
|
async approveSpender(
|
|
254
280
|
spender: string,
|
|
255
281
|
asset: string,
|
|
256
282
|
amount: BigNumber | string,
|
|
257
|
-
options: any = null
|
|
283
|
+
options: any = null,
|
|
284
|
+
estimateGas = false
|
|
258
285
|
): Promise<any> {
|
|
259
286
|
const iERC20 = new ethers.utils.Interface(IERC20.abi);
|
|
260
287
|
const approveTxData = iERC20.encodeFunctionData("approve", [
|
|
261
288
|
spender,
|
|
262
289
|
amount
|
|
263
290
|
]);
|
|
264
|
-
const tx = await
|
|
265
|
-
|
|
266
|
-
approveTxData,
|
|
267
|
-
|
|
291
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
292
|
+
this,
|
|
293
|
+
[asset, approveTxData, options],
|
|
294
|
+
estimateGas
|
|
268
295
|
);
|
|
269
296
|
return tx;
|
|
270
297
|
}
|
|
@@ -277,6 +304,7 @@ export class Pool {
|
|
|
277
304
|
* @param {BigNumber | string} amountIn Amount
|
|
278
305
|
* @param {number} slippage Slippage tolerance in %
|
|
279
306
|
* @param {any} options Transaction options
|
|
307
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
280
308
|
* @returns {Promise<any>} Transaction
|
|
281
309
|
*/
|
|
282
310
|
async trade(
|
|
@@ -285,7 +313,8 @@ export class Pool {
|
|
|
285
313
|
assetTo: string,
|
|
286
314
|
amountIn: BigNumber | string,
|
|
287
315
|
slippage = 0.5,
|
|
288
|
-
options: any = null
|
|
316
|
+
options: any = null,
|
|
317
|
+
estimateGas = false
|
|
289
318
|
): Promise<any> {
|
|
290
319
|
let swapTxData: string;
|
|
291
320
|
switch (dapp) {
|
|
@@ -359,10 +388,10 @@ export class Pool {
|
|
|
359
388
|
await getDeadline(this)
|
|
360
389
|
]);
|
|
361
390
|
}
|
|
362
|
-
const tx = await
|
|
363
|
-
|
|
364
|
-
swapTxData,
|
|
365
|
-
|
|
391
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
392
|
+
this,
|
|
393
|
+
[routerAddress[this.network][dapp], swapTxData, options],
|
|
394
|
+
estimateGas
|
|
366
395
|
);
|
|
367
396
|
return tx;
|
|
368
397
|
}
|
|
@@ -375,6 +404,7 @@ export class Pool {
|
|
|
375
404
|
* @param {BigNumber | string} amountA Amount first asset
|
|
376
405
|
* @param {BigNumber | string} amountB Amount second asset
|
|
377
406
|
* @param {any} options Transaction options
|
|
407
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
378
408
|
* @returns {Promise<any>} Transaction
|
|
379
409
|
*/
|
|
380
410
|
async addLiquidity(
|
|
@@ -383,7 +413,8 @@ export class Pool {
|
|
|
383
413
|
assetB: string,
|
|
384
414
|
amountA: BigNumber | string,
|
|
385
415
|
amountB: BigNumber | string,
|
|
386
|
-
options: any = null
|
|
416
|
+
options: any = null,
|
|
417
|
+
estimateGas = false
|
|
387
418
|
): Promise<any> {
|
|
388
419
|
const iUniswapV2Router = new ethers.utils.Interface(IUniswapV2Router.abi);
|
|
389
420
|
const addLiquidityTxData = iUniswapV2Router.encodeFunctionData(
|
|
@@ -399,10 +430,10 @@ export class Pool {
|
|
|
399
430
|
await getDeadline(this)
|
|
400
431
|
]
|
|
401
432
|
);
|
|
402
|
-
const tx = await
|
|
403
|
-
|
|
404
|
-
addLiquidityTxData,
|
|
405
|
-
|
|
433
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
434
|
+
this,
|
|
435
|
+
[routerAddress[this.network][dapp], addLiquidityTxData, options],
|
|
436
|
+
estimateGas
|
|
406
437
|
);
|
|
407
438
|
return tx;
|
|
408
439
|
}
|
|
@@ -414,6 +445,7 @@ export class Pool {
|
|
|
414
445
|
* @param {string} assetB Second asset
|
|
415
446
|
* @param {BigNumber | string} amount Amount of liquidity pool tokens
|
|
416
447
|
* @param {any} options Transaction options
|
|
448
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
417
449
|
* @returns {Promise<any>} Transaction
|
|
418
450
|
*/
|
|
419
451
|
async removeLiquidity(
|
|
@@ -421,17 +453,18 @@ export class Pool {
|
|
|
421
453
|
assetA: string,
|
|
422
454
|
assetB: string,
|
|
423
455
|
amount: string | BigNumber,
|
|
424
|
-
options: any = null
|
|
456
|
+
options: any = null,
|
|
457
|
+
estimateGas = false
|
|
425
458
|
): Promise<any> {
|
|
426
459
|
const iUniswapV2Router = new ethers.utils.Interface(IUniswapV2Router.abi);
|
|
427
460
|
const removeLiquidityTxData = iUniswapV2Router.encodeFunctionData(
|
|
428
461
|
Transaction.REMOVE_LIQUIDITY,
|
|
429
462
|
[assetA, assetB, amount, 0, 0, this.address, await getDeadline(this)]
|
|
430
463
|
);
|
|
431
|
-
const tx = await
|
|
432
|
-
|
|
433
|
-
removeLiquidityTxData,
|
|
434
|
-
|
|
464
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
465
|
+
this,
|
|
466
|
+
[routerAddress[this.network][dapp], removeLiquidityTxData, options],
|
|
467
|
+
estimateGas
|
|
435
468
|
);
|
|
436
469
|
return tx;
|
|
437
470
|
}
|
|
@@ -442,13 +475,15 @@ export class Pool {
|
|
|
442
475
|
* @param {string} asset Liquidity pool token
|
|
443
476
|
* @param {BigNumber | string} amount Amount of liquidity pool tokens
|
|
444
477
|
* @param {any} options Transaction options
|
|
478
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
445
479
|
* @returns {Promise<any>} Transaction
|
|
446
480
|
*/
|
|
447
481
|
async stake(
|
|
448
482
|
dapp: Dapp,
|
|
449
483
|
asset: string,
|
|
450
484
|
amount: BigNumber | string,
|
|
451
|
-
options: any = null
|
|
485
|
+
options: any = null,
|
|
486
|
+
estimateGas = false
|
|
452
487
|
): Promise<any> {
|
|
453
488
|
const iMiniChefV2 = new ethers.utils.Interface(IMiniChefV2.abi);
|
|
454
489
|
const poolId = await this.utils.getLpPoolId(dapp, asset);
|
|
@@ -457,10 +492,10 @@ export class Pool {
|
|
|
457
492
|
amount,
|
|
458
493
|
this.address
|
|
459
494
|
]);
|
|
460
|
-
const tx = await
|
|
461
|
-
|
|
462
|
-
stakeTxData,
|
|
463
|
-
|
|
495
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
496
|
+
this,
|
|
497
|
+
[stakingAddress[this.network][dapp], stakeTxData, options],
|
|
498
|
+
estimateGas
|
|
464
499
|
);
|
|
465
500
|
return tx;
|
|
466
501
|
}
|
|
@@ -471,13 +506,15 @@ export class Pool {
|
|
|
471
506
|
* @param {string} gauge Gauge contract address
|
|
472
507
|
* @param {BigNumber | string} amount Amount of liquidity pool tokens
|
|
473
508
|
* @param {any} options Transaction options
|
|
509
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
474
510
|
* @returns {Promise<any>} Transaction
|
|
475
511
|
*/
|
|
476
512
|
async stakeInGauge(
|
|
477
513
|
dapp: Dapp,
|
|
478
514
|
gauge: string,
|
|
479
515
|
amount: BigNumber | string,
|
|
480
|
-
options: any = null
|
|
516
|
+
options: any = null,
|
|
517
|
+
estimateGas = false
|
|
481
518
|
): Promise<any> {
|
|
482
519
|
let stakeTxData;
|
|
483
520
|
switch (dapp) {
|
|
@@ -499,10 +536,10 @@ export class Pool {
|
|
|
499
536
|
default:
|
|
500
537
|
throw new Error("dapp not supported");
|
|
501
538
|
}
|
|
502
|
-
const tx = await
|
|
503
|
-
|
|
504
|
-
stakeTxData,
|
|
505
|
-
|
|
539
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
540
|
+
this,
|
|
541
|
+
[gauge, stakeTxData, options],
|
|
542
|
+
estimateGas
|
|
506
543
|
);
|
|
507
544
|
return tx;
|
|
508
545
|
}
|
|
@@ -513,13 +550,15 @@ export class Pool {
|
|
|
513
550
|
* @param {string} asset Liquidity pool token
|
|
514
551
|
* @param {BigNumber | string} amount Amount of liquidity pool tokens
|
|
515
552
|
* @param {any} options Transaction options
|
|
553
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
516
554
|
* @returns {Promise<any>} Transaction
|
|
517
555
|
*/
|
|
518
556
|
async unStake(
|
|
519
557
|
dapp: Dapp,
|
|
520
558
|
asset: string,
|
|
521
559
|
amount: BigNumber | string,
|
|
522
|
-
options: any = null
|
|
560
|
+
options: any = null,
|
|
561
|
+
estimateGas = false
|
|
523
562
|
): Promise<any> {
|
|
524
563
|
const iMiniChefV2 = new ethers.utils.Interface(IMiniChefV2.abi);
|
|
525
564
|
const poolId = await this.utils.getLpPoolId(dapp, asset);
|
|
@@ -528,10 +567,10 @@ export class Pool {
|
|
|
528
567
|
amount,
|
|
529
568
|
this.address
|
|
530
569
|
]);
|
|
531
|
-
const tx = await
|
|
532
|
-
|
|
533
|
-
unStakeTxData,
|
|
534
|
-
|
|
570
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
571
|
+
this,
|
|
572
|
+
[stakingAddress[this.network][dapp], unStakeTxData, options],
|
|
573
|
+
estimateGas
|
|
535
574
|
);
|
|
536
575
|
return tx;
|
|
537
576
|
}
|
|
@@ -541,21 +580,23 @@ export class Pool {
|
|
|
541
580
|
* @param {string} gauge Gauge contract address
|
|
542
581
|
* @param {BigNumber | string} amount Amount of liquidity pool tokens
|
|
543
582
|
* @param {any} options Transaction options
|
|
583
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
544
584
|
* @returns {Promise<any>} Transaction
|
|
545
585
|
*/
|
|
546
586
|
async unstakeFromGauge(
|
|
547
587
|
gauge: string,
|
|
548
588
|
amount: BigNumber | string,
|
|
549
|
-
options: any = null
|
|
589
|
+
options: any = null,
|
|
590
|
+
estimateGas = false
|
|
550
591
|
): Promise<any> {
|
|
551
592
|
const rewardsGauge = new ethers.utils.Interface(IBalancerRewardsGauge.abi);
|
|
552
593
|
const unstakeTxData = rewardsGauge.encodeFunctionData("withdraw(uint256)", [
|
|
553
594
|
amount
|
|
554
595
|
]);
|
|
555
|
-
const tx = await
|
|
556
|
-
|
|
557
|
-
unstakeTxData,
|
|
558
|
-
|
|
596
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
597
|
+
this,
|
|
598
|
+
[gauge, unstakeTxData, options],
|
|
599
|
+
estimateGas
|
|
559
600
|
);
|
|
560
601
|
return tx;
|
|
561
602
|
}
|
|
@@ -567,6 +608,7 @@ export class Pool {
|
|
|
567
608
|
* @param {BigNumber | string} amount Amount of asset to lend
|
|
568
609
|
* @param {number} referralCode Code from Aave referral program
|
|
569
610
|
* @param {any} options Transaction options
|
|
611
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
570
612
|
* @returns {Promise<any>} Transaction
|
|
571
613
|
*/
|
|
572
614
|
async lend(
|
|
@@ -574,7 +616,8 @@ export class Pool {
|
|
|
574
616
|
asset: string,
|
|
575
617
|
amount: BigNumber | string,
|
|
576
618
|
referralCode = 0,
|
|
577
|
-
options: any = null
|
|
619
|
+
options: any = null,
|
|
620
|
+
estimateGas = false
|
|
578
621
|
): Promise<any> {
|
|
579
622
|
const iLendingPool = new ethers.utils.Interface(ILendingPool.abi);
|
|
580
623
|
const depositTxData = iLendingPool.encodeFunctionData(Transaction.DEPOSIT, [
|
|
@@ -583,10 +626,10 @@ export class Pool {
|
|
|
583
626
|
this.address,
|
|
584
627
|
referralCode
|
|
585
628
|
]);
|
|
586
|
-
const tx = await
|
|
587
|
-
|
|
588
|
-
depositTxData,
|
|
589
|
-
|
|
629
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
630
|
+
this,
|
|
631
|
+
[routerAddress[this.network][dapp], depositTxData, options],
|
|
632
|
+
estimateGas
|
|
590
633
|
);
|
|
591
634
|
return tx;
|
|
592
635
|
}
|
|
@@ -597,23 +640,25 @@ export class Pool {
|
|
|
597
640
|
* @param {string} asset Asset
|
|
598
641
|
* @param {BigNumber | string} amount Amount of asset to lend
|
|
599
642
|
* @param {any} options Transaction options
|
|
643
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
600
644
|
* @returns {Promise<any>} Transaction
|
|
601
645
|
*/
|
|
602
646
|
async withdrawDeposit(
|
|
603
647
|
dapp: Dapp,
|
|
604
648
|
asset: string,
|
|
605
649
|
amount: BigNumber | string,
|
|
606
|
-
options: any = null
|
|
650
|
+
options: any = null,
|
|
651
|
+
estimateGas = false
|
|
607
652
|
): Promise<any> {
|
|
608
653
|
const iLendingPool = new ethers.utils.Interface(ILendingPool.abi);
|
|
609
654
|
const withdrawTxData = iLendingPool.encodeFunctionData(
|
|
610
655
|
Transaction.WITHDRAW,
|
|
611
656
|
[asset, amount, this.address]
|
|
612
657
|
);
|
|
613
|
-
const tx = await
|
|
614
|
-
|
|
615
|
-
withdrawTxData,
|
|
616
|
-
|
|
658
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
659
|
+
this,
|
|
660
|
+
[routerAddress[this.network][dapp], withdrawTxData, options],
|
|
661
|
+
estimateGas
|
|
617
662
|
);
|
|
618
663
|
return tx;
|
|
619
664
|
}
|
|
@@ -625,6 +670,7 @@ export class Pool {
|
|
|
625
670
|
* @param {BigNumber | string} amount Amount of asset to lend
|
|
626
671
|
* @param {number} referralCode Code from Aave referral program
|
|
627
672
|
* @param {any} options Transaction options
|
|
673
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
628
674
|
* @returns {Promise<any>} Transaction
|
|
629
675
|
*/
|
|
630
676
|
async borrow(
|
|
@@ -632,7 +678,8 @@ export class Pool {
|
|
|
632
678
|
asset: string,
|
|
633
679
|
amount: BigNumber | string,
|
|
634
680
|
referralCode = 0,
|
|
635
|
-
options: any = null
|
|
681
|
+
options: any = null,
|
|
682
|
+
estimateGas = false
|
|
636
683
|
): Promise<any> {
|
|
637
684
|
const iLendingPool = new ethers.utils.Interface(ILendingPool.abi);
|
|
638
685
|
const borrowTxData = iLendingPool.encodeFunctionData(Transaction.BORROW, [
|
|
@@ -642,10 +689,10 @@ export class Pool {
|
|
|
642
689
|
referralCode,
|
|
643
690
|
this.address
|
|
644
691
|
]);
|
|
645
|
-
const tx = await
|
|
646
|
-
|
|
647
|
-
borrowTxData,
|
|
648
|
-
|
|
692
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
693
|
+
this,
|
|
694
|
+
[routerAddress[this.network][dapp], borrowTxData, options],
|
|
695
|
+
estimateGas
|
|
649
696
|
);
|
|
650
697
|
return tx;
|
|
651
698
|
}
|
|
@@ -656,13 +703,15 @@ export class Pool {
|
|
|
656
703
|
* @param {string} asset Asset
|
|
657
704
|
* @param {BigNumber | string} amount Amount of asset to lend
|
|
658
705
|
* @param {any} options Transaction options
|
|
706
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
659
707
|
* @returns {Promise<any>} Transaction
|
|
660
708
|
*/
|
|
661
709
|
async repay(
|
|
662
710
|
dapp: Dapp,
|
|
663
711
|
asset: string,
|
|
664
712
|
amount: BigNumber | string,
|
|
665
|
-
options: any = null
|
|
713
|
+
options: any = null,
|
|
714
|
+
estimateGas = false
|
|
666
715
|
): Promise<any> {
|
|
667
716
|
const iLendingPool = new ethers.utils.Interface(ILendingPool.abi);
|
|
668
717
|
const repayTxData = iLendingPool.encodeFunctionData(Transaction.REPAY, [
|
|
@@ -671,10 +720,10 @@ export class Pool {
|
|
|
671
720
|
2,
|
|
672
721
|
this.address
|
|
673
722
|
]);
|
|
674
|
-
const tx = await
|
|
675
|
-
|
|
676
|
-
repayTxData,
|
|
677
|
-
|
|
723
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
724
|
+
this,
|
|
725
|
+
[routerAddress[this.network][dapp], repayTxData, options],
|
|
726
|
+
estimateGas
|
|
678
727
|
);
|
|
679
728
|
return tx;
|
|
680
729
|
}
|
|
@@ -683,13 +732,15 @@ export class Pool {
|
|
|
683
732
|
* Claim rewards of staked liquidity pool tokens
|
|
684
733
|
* @param {Dapp} dapp Platform like Sushiswap or Uniswap
|
|
685
734
|
* @param {string} asset Liquidity pool token
|
|
686
|
-
* @param {any} options Transaction
|
|
735
|
+
* @param {any} options Transaction option
|
|
736
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
687
737
|
* @returns {Promise<any>} Transaction
|
|
688
738
|
*/
|
|
689
739
|
async harvestRewards(
|
|
690
740
|
dapp: Dapp,
|
|
691
741
|
asset: string,
|
|
692
|
-
options: any = null
|
|
742
|
+
options: any = null,
|
|
743
|
+
estimateGas = false
|
|
693
744
|
): Promise<any> {
|
|
694
745
|
const iMiniChefV2 = new ethers.utils.Interface(IMiniChefV2.abi);
|
|
695
746
|
const poolId = await this.utils.getLpPoolId(dapp, asset);
|
|
@@ -697,10 +748,10 @@ export class Pool {
|
|
|
697
748
|
poolId,
|
|
698
749
|
this.address
|
|
699
750
|
]);
|
|
700
|
-
const tx = await
|
|
701
|
-
|
|
702
|
-
harvestTxData,
|
|
703
|
-
|
|
751
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
752
|
+
this,
|
|
753
|
+
[stakingAddress[this.network][dapp], harvestTxData, options],
|
|
754
|
+
estimateGas
|
|
704
755
|
);
|
|
705
756
|
return tx;
|
|
706
757
|
}
|
|
@@ -709,11 +760,13 @@ export class Pool {
|
|
|
709
760
|
* Change enabled pool assets
|
|
710
761
|
* @param {AssetEnabled[]} assets New pool assets
|
|
711
762
|
* @param {any} options Transaction options
|
|
763
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
712
764
|
* @returns {Promise<any>} Transaction
|
|
713
765
|
*/
|
|
714
766
|
public async changeAssets(
|
|
715
767
|
assets: AssetEnabled[],
|
|
716
|
-
options: any = null
|
|
768
|
+
options: any = null,
|
|
769
|
+
estimateGas = false
|
|
717
770
|
): Promise<any> {
|
|
718
771
|
const currentAssetsEnabled = await this.getComposition();
|
|
719
772
|
const currentAssets = currentAssetsEnabled.map(e =>
|
|
@@ -722,6 +775,14 @@ export class Pool {
|
|
|
722
775
|
const newAssets = assets.map(e => e.asset.toLocaleLowerCase());
|
|
723
776
|
const removedAssets = currentAssets.filter(e => !newAssets.includes(e));
|
|
724
777
|
const changedAssets = assets.map(e => [e.asset, e.isDeposit]);
|
|
778
|
+
|
|
779
|
+
if (estimateGas) {
|
|
780
|
+
return await this.managerLogic.estimateGas.changeAssets(
|
|
781
|
+
changedAssets,
|
|
782
|
+
removedAssets,
|
|
783
|
+
options
|
|
784
|
+
);
|
|
785
|
+
}
|
|
725
786
|
const tx = await this.managerLogic.changeAssets(
|
|
726
787
|
changedAssets,
|
|
727
788
|
removedAssets,
|
|
@@ -734,9 +795,17 @@ export class Pool {
|
|
|
734
795
|
* Set a new trader with trading permissions
|
|
735
796
|
* @param {string} trader Address trader account
|
|
736
797
|
* @param {any} options Transaction options
|
|
798
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
737
799
|
* @returns {Promise<any>} Transaction
|
|
738
800
|
*/
|
|
739
|
-
async setTrader(
|
|
801
|
+
async setTrader(
|
|
802
|
+
trader: string,
|
|
803
|
+
options: any = null,
|
|
804
|
+
estimateGas = false
|
|
805
|
+
): Promise<any> {
|
|
806
|
+
if (estimateGas) {
|
|
807
|
+
return await this.managerLogic.estimateGas.setTrader(trader, options);
|
|
808
|
+
}
|
|
740
809
|
const tx = await this.managerLogic.setTrader(trader, options);
|
|
741
810
|
return tx;
|
|
742
811
|
}
|
|
@@ -747,13 +816,15 @@ export class Pool {
|
|
|
747
816
|
* @param {string[] | } assetsIn Array of balancer pool assets
|
|
748
817
|
* @param {BigNumber[] | string[]} amountsIn Array of maximum amounts to provide to pool
|
|
749
818
|
* @param {any} options Transaction options
|
|
819
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
750
820
|
* @returns {Promise<any>} Transaction
|
|
751
821
|
*/
|
|
752
822
|
async joinBalancerPool(
|
|
753
823
|
poolId: string,
|
|
754
824
|
assets: string[],
|
|
755
825
|
amountsIn: string[] | BigNumber[],
|
|
756
|
-
options: any = null
|
|
826
|
+
options: any = null,
|
|
827
|
+
estimateGas = false
|
|
757
828
|
): Promise<any> {
|
|
758
829
|
const joinPoolTxData = this.utils.getBalancerJoinPoolTx(
|
|
759
830
|
this,
|
|
@@ -761,10 +832,10 @@ export class Pool {
|
|
|
761
832
|
assets,
|
|
762
833
|
amountsIn
|
|
763
834
|
);
|
|
764
|
-
const tx = await
|
|
765
|
-
|
|
766
|
-
joinPoolTxData,
|
|
767
|
-
|
|
835
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
836
|
+
this,
|
|
837
|
+
[routerAddress[this.network][Dapp.BALANCER], joinPoolTxData, options],
|
|
838
|
+
estimateGas
|
|
768
839
|
);
|
|
769
840
|
return tx;
|
|
770
841
|
}
|
|
@@ -776,6 +847,7 @@ export class Pool {
|
|
|
776
847
|
* @param {BigNumber | string } amount Amount of pool tokens to withdraw
|
|
777
848
|
* @param { null | number } singleExitAssetIndex Index of asset to withdraw to
|
|
778
849
|
* @param {any} options Transaction options
|
|
850
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
779
851
|
* @returns {Promise<any>} Transaction
|
|
780
852
|
*/
|
|
781
853
|
async exitBalancerPool(
|
|
@@ -783,7 +855,8 @@ export class Pool {
|
|
|
783
855
|
assets: string[],
|
|
784
856
|
amount: string | BigNumber,
|
|
785
857
|
singleExitAssetIndex: number | null = null,
|
|
786
|
-
options: any = null
|
|
858
|
+
options: any = null,
|
|
859
|
+
estimateGas = false
|
|
787
860
|
): Promise<any> {
|
|
788
861
|
const exitPoolTxData = this.utils.getBalancerExitPoolTx(
|
|
789
862
|
this,
|
|
@@ -792,10 +865,10 @@ export class Pool {
|
|
|
792
865
|
singleExitAssetIndex,
|
|
793
866
|
amount
|
|
794
867
|
);
|
|
795
|
-
const tx = await
|
|
796
|
-
|
|
797
|
-
exitPoolTxData,
|
|
798
|
-
|
|
868
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
869
|
+
this,
|
|
870
|
+
[routerAddress[this.network][Dapp.BALANCER], exitPoolTxData, options],
|
|
871
|
+
estimateGas
|
|
799
872
|
);
|
|
800
873
|
return tx;
|
|
801
874
|
}
|
|
@@ -804,11 +877,13 @@ export class Pool {
|
|
|
804
877
|
* Claim rewards from Aave platform
|
|
805
878
|
* @param {string[]} assets Aave tokens (deposit/debt) hold by pool
|
|
806
879
|
* @param {any} options Transaction options
|
|
880
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
807
881
|
* @returns {Promise<any>} Transaction
|
|
808
882
|
*/
|
|
809
883
|
async harvestAaveRewards(
|
|
810
884
|
assets: string[],
|
|
811
|
-
options: any = null
|
|
885
|
+
options: any = null,
|
|
886
|
+
estimateGas = false
|
|
812
887
|
): Promise<any> {
|
|
813
888
|
const aaveIncentivesAddress = stakingAddress[this.network][
|
|
814
889
|
Dapp.AAVE
|
|
@@ -828,10 +903,10 @@ export class Pool {
|
|
|
828
903
|
Transaction.CLAIM_REWARDS,
|
|
829
904
|
[assets, amount, this.address]
|
|
830
905
|
);
|
|
831
|
-
const tx = await
|
|
832
|
-
|
|
833
|
-
claimTxData,
|
|
834
|
-
|
|
906
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
907
|
+
this,
|
|
908
|
+
[aaveIncentivesAddress, claimTxData, options],
|
|
909
|
+
estimateGas
|
|
835
910
|
);
|
|
836
911
|
return tx;
|
|
837
912
|
}
|
|
@@ -841,18 +916,24 @@ export class Pool {
|
|
|
841
916
|
* @param {string[]} assets Assets invested in Aave
|
|
842
917
|
* @param {string} rewardAssets Reward token address
|
|
843
918
|
* @param {any} options Transaction options
|
|
919
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
844
920
|
* @returns {Promise<any>} Transaction
|
|
845
921
|
*/
|
|
846
922
|
async harvestAaveV3Rewards(
|
|
847
923
|
assets: string[],
|
|
848
924
|
rewardAsset: string,
|
|
849
|
-
options: any = null
|
|
925
|
+
options: any = null,
|
|
926
|
+
estimateGas = false
|
|
850
927
|
): Promise<any> {
|
|
851
928
|
const claimTxData = await getAaveV3ClaimTxData(this, assets, rewardAsset);
|
|
852
|
-
const tx = await
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
929
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
930
|
+
this,
|
|
931
|
+
[
|
|
932
|
+
stakingAddress[this.network][Dapp.AAVEV3] as string,
|
|
933
|
+
claimTxData,
|
|
934
|
+
options
|
|
935
|
+
],
|
|
936
|
+
estimateGas
|
|
856
937
|
);
|
|
857
938
|
return tx;
|
|
858
939
|
}
|
|
@@ -869,6 +950,7 @@ export class Pool {
|
|
|
869
950
|
* @param { number } maxTick Upper tick range
|
|
870
951
|
* @param { FeeAmount } feeAmount Fee tier (Low 0.05%, Medium 0.3%, High 1%)
|
|
871
952
|
* @param {any} options Transaction options
|
|
953
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
872
954
|
* @returns {Promise<any>} Transaction
|
|
873
955
|
*/
|
|
874
956
|
async addLiquidityUniswapV3(
|
|
@@ -881,7 +963,8 @@ export class Pool {
|
|
|
881
963
|
minTick: number | null,
|
|
882
964
|
maxTick: number | null,
|
|
883
965
|
feeAmount: FeeAmount,
|
|
884
|
-
options: any = null
|
|
966
|
+
options: any = null,
|
|
967
|
+
estimateGas = false
|
|
885
968
|
): Promise<any> {
|
|
886
969
|
if (
|
|
887
970
|
(minPrice === null || maxPrice === null) &&
|
|
@@ -909,10 +992,10 @@ export class Pool {
|
|
|
909
992
|
Transaction.MINT,
|
|
910
993
|
[mintTxParams]
|
|
911
994
|
);
|
|
912
|
-
const tx = await
|
|
913
|
-
|
|
914
|
-
mintTxData,
|
|
915
|
-
|
|
995
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
996
|
+
this,
|
|
997
|
+
[nonfungiblePositionManagerAddress[this.network], mintTxData, options],
|
|
998
|
+
estimateGas
|
|
916
999
|
);
|
|
917
1000
|
return tx;
|
|
918
1001
|
}
|
|
@@ -923,13 +1006,15 @@ export class Pool {
|
|
|
923
1006
|
* @param {string} tokenId Token Id of UniswapV3 position
|
|
924
1007
|
* @param {number} amount Amount in percent of assets to be removed
|
|
925
1008
|
* @param {any} options Transaction options
|
|
1009
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
926
1010
|
* @returns {Promise<any>} Transaction
|
|
927
1011
|
*/
|
|
928
1012
|
async decreaseLiquidity(
|
|
929
1013
|
dapp: Dapp,
|
|
930
1014
|
tokenId: string,
|
|
931
1015
|
amount = 100,
|
|
932
|
-
options: any = null
|
|
1016
|
+
options: any = null,
|
|
1017
|
+
estimateGas = false
|
|
933
1018
|
): Promise<any> {
|
|
934
1019
|
let txData;
|
|
935
1020
|
let dappAddress;
|
|
@@ -972,11 +1057,10 @@ export class Pool {
|
|
|
972
1057
|
} else {
|
|
973
1058
|
throw new Error("dapp not supported");
|
|
974
1059
|
}
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
dappAddress,
|
|
978
|
-
|
|
979
|
-
options
|
|
1060
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
1061
|
+
this,
|
|
1062
|
+
[dappAddress, txData, options],
|
|
1063
|
+
estimateGas
|
|
980
1064
|
);
|
|
981
1065
|
return tx;
|
|
982
1066
|
}
|
|
@@ -988,6 +1072,7 @@ export class Pool {
|
|
|
988
1072
|
* @param {BigNumber | string} amountA Amount first asset
|
|
989
1073
|
* @param {BigNumber | string} amountB Amount second asset
|
|
990
1074
|
* @param {any} options Transaction options
|
|
1075
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
991
1076
|
* @returns {Promise<any>} Transaction
|
|
992
1077
|
*/
|
|
993
1078
|
async increaseLiquidity(
|
|
@@ -995,7 +1080,8 @@ export class Pool {
|
|
|
995
1080
|
tokenId: string,
|
|
996
1081
|
amountA: BigNumber | string,
|
|
997
1082
|
amountB: BigNumber | string,
|
|
998
|
-
options: any = null
|
|
1083
|
+
options: any = null,
|
|
1084
|
+
estimateGas = false
|
|
999
1085
|
): Promise<any> {
|
|
1000
1086
|
let txData;
|
|
1001
1087
|
let dappAddress;
|
|
@@ -1020,11 +1106,10 @@ export class Pool {
|
|
|
1020
1106
|
} else {
|
|
1021
1107
|
throw new Error("dapp not supported");
|
|
1022
1108
|
}
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
dappAddress,
|
|
1026
|
-
|
|
1027
|
-
options
|
|
1109
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
1110
|
+
this,
|
|
1111
|
+
[dappAddress, txData, options],
|
|
1112
|
+
estimateGas
|
|
1028
1113
|
);
|
|
1029
1114
|
return tx;
|
|
1030
1115
|
}
|
|
@@ -1034,12 +1119,14 @@ export class Pool {
|
|
|
1034
1119
|
* @param {Dapp} dapp Platform either UniswapV3 or Arrakis
|
|
1035
1120
|
* @param {string} tokenId Token Id of UniswapV3 or Gauge address
|
|
1036
1121
|
* @param {any} options Transaction option
|
|
1122
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1037
1123
|
* @returns {Promise<any>} Transaction
|
|
1038
1124
|
*/
|
|
1039
1125
|
async claimFees(
|
|
1040
1126
|
dapp: Dapp,
|
|
1041
1127
|
tokenId: string,
|
|
1042
|
-
options: any = null
|
|
1128
|
+
options: any = null,
|
|
1129
|
+
estimateGas = false
|
|
1043
1130
|
): Promise<any> {
|
|
1044
1131
|
let txData;
|
|
1045
1132
|
let contractAddress;
|
|
@@ -1072,10 +1159,10 @@ export class Pool {
|
|
|
1072
1159
|
default:
|
|
1073
1160
|
throw new Error("dapp not supported");
|
|
1074
1161
|
}
|
|
1075
|
-
const tx = await
|
|
1076
|
-
|
|
1077
|
-
txData,
|
|
1078
|
-
|
|
1162
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
1163
|
+
this,
|
|
1164
|
+
[contractAddress, txData, options],
|
|
1165
|
+
estimateGas
|
|
1079
1166
|
);
|
|
1080
1167
|
return tx;
|
|
1081
1168
|
}
|
|
@@ -1089,6 +1176,7 @@ export class Pool {
|
|
|
1089
1176
|
* @param { FeeAmount } feeAmount Fee tier (Low 0.05%, Medium 0.3%, High 1%)
|
|
1090
1177
|
* @param {number} slippage Slippage tolerance in %
|
|
1091
1178
|
* @param {any} options Transaction options
|
|
1179
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1092
1180
|
* @returns {Promise<any>} Transaction
|
|
1093
1181
|
*/
|
|
1094
1182
|
async tradeUniswapV3(
|
|
@@ -1097,7 +1185,8 @@ export class Pool {
|
|
|
1097
1185
|
amountIn: BigNumber | string,
|
|
1098
1186
|
feeAmount: FeeAmount,
|
|
1099
1187
|
slippage = 0.5,
|
|
1100
|
-
options: any = null
|
|
1188
|
+
options: any = null,
|
|
1189
|
+
estimateGas = false
|
|
1101
1190
|
): Promise<any> {
|
|
1102
1191
|
const swapxData = await getUniswapV3SwapTxData(
|
|
1103
1192
|
this,
|
|
@@ -1107,10 +1196,10 @@ export class Pool {
|
|
|
1107
1196
|
slippage,
|
|
1108
1197
|
feeAmount
|
|
1109
1198
|
);
|
|
1110
|
-
const tx = await
|
|
1111
|
-
|
|
1112
|
-
swapxData,
|
|
1113
|
-
|
|
1199
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
1200
|
+
this,
|
|
1201
|
+
[routerAddress[this.network][Dapp.UNISWAPV3], swapxData, options],
|
|
1202
|
+
estimateGas
|
|
1114
1203
|
);
|
|
1115
1204
|
return tx;
|
|
1116
1205
|
}
|
|
@@ -1123,6 +1212,7 @@ export class Pool {
|
|
|
1123
1212
|
* @param {BigNumber | string} amountB Amount second asset
|
|
1124
1213
|
* @param { boolean } isStable Is stable pool
|
|
1125
1214
|
* @param {any} options Transaction options
|
|
1215
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1126
1216
|
* @returns {Promise<any>} Transaction
|
|
1127
1217
|
*/
|
|
1128
1218
|
async addLiquidityVelodrome(
|
|
@@ -1131,19 +1221,24 @@ export class Pool {
|
|
|
1131
1221
|
amountA: BigNumber | string,
|
|
1132
1222
|
amountB: BigNumber | string,
|
|
1133
1223
|
isStable: boolean,
|
|
1134
|
-
options: any = null
|
|
1224
|
+
options: any = null,
|
|
1225
|
+
estimateGas = false
|
|
1135
1226
|
): Promise<any> {
|
|
1136
|
-
const tx = await
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
this,
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1227
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
1228
|
+
this,
|
|
1229
|
+
[
|
|
1230
|
+
routerAddress[this.network][Dapp.VELODROME],
|
|
1231
|
+
await getVelodromeAddLiquidityTxData(
|
|
1232
|
+
this,
|
|
1233
|
+
assetA,
|
|
1234
|
+
assetB,
|
|
1235
|
+
amountA,
|
|
1236
|
+
amountB,
|
|
1237
|
+
isStable
|
|
1238
|
+
),
|
|
1239
|
+
options
|
|
1240
|
+
],
|
|
1241
|
+
estimateGas
|
|
1147
1242
|
);
|
|
1148
1243
|
return tx;
|
|
1149
1244
|
}
|
|
@@ -1155,6 +1250,7 @@ export class Pool {
|
|
|
1155
1250
|
* @param {BigNumber | string} amount Amount of LP tokens
|
|
1156
1251
|
* @param { boolean } isStable Is stable pool
|
|
1157
1252
|
* @param {any} options Transaction options
|
|
1253
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1158
1254
|
* @returns {Promise<any>} Transaction
|
|
1159
1255
|
*/
|
|
1160
1256
|
async removeLiquidityVelodrome(
|
|
@@ -1162,18 +1258,23 @@ export class Pool {
|
|
|
1162
1258
|
assetB: string,
|
|
1163
1259
|
amount: BigNumber | string,
|
|
1164
1260
|
isStable: boolean,
|
|
1165
|
-
options: any = null
|
|
1261
|
+
options: any = null,
|
|
1262
|
+
estimateGas = false
|
|
1166
1263
|
): Promise<any> {
|
|
1167
|
-
const tx = await
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
this,
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1264
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
1265
|
+
this,
|
|
1266
|
+
[
|
|
1267
|
+
routerAddress[this.network][Dapp.VELODROME],
|
|
1268
|
+
await getVelodromeRemoveLiquidityTxData(
|
|
1269
|
+
this,
|
|
1270
|
+
assetA,
|
|
1271
|
+
assetB,
|
|
1272
|
+
amount,
|
|
1273
|
+
isStable
|
|
1274
|
+
),
|
|
1275
|
+
options
|
|
1276
|
+
],
|
|
1277
|
+
estimateGas
|
|
1177
1278
|
);
|
|
1178
1279
|
return tx;
|
|
1179
1280
|
}
|
|
@@ -1186,6 +1287,7 @@ export class Pool {
|
|
|
1186
1287
|
* @param {BigNumber | string} amountB Amount second asset
|
|
1187
1288
|
* @param { boolean } isStable Is stable pool
|
|
1188
1289
|
* @param {any} options Transaction options
|
|
1290
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1189
1291
|
* @returns {Promise<any>} Transaction
|
|
1190
1292
|
*/
|
|
1191
1293
|
async addLiquidityVelodromeV2(
|
|
@@ -1194,19 +1296,24 @@ export class Pool {
|
|
|
1194
1296
|
amountA: BigNumber | string,
|
|
1195
1297
|
amountB: BigNumber | string,
|
|
1196
1298
|
isStable: boolean,
|
|
1197
|
-
options: any = null
|
|
1299
|
+
options: any = null,
|
|
1300
|
+
estimateGas = false
|
|
1198
1301
|
): Promise<any> {
|
|
1199
|
-
const tx = await
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
this,
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1302
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
1303
|
+
this,
|
|
1304
|
+
[
|
|
1305
|
+
routerAddress[this.network][Dapp.VELODROMEV2],
|
|
1306
|
+
await getVelodromeAddLiquidityTxData(
|
|
1307
|
+
this,
|
|
1308
|
+
assetA,
|
|
1309
|
+
assetB,
|
|
1310
|
+
amountA,
|
|
1311
|
+
amountB,
|
|
1312
|
+
isStable
|
|
1313
|
+
),
|
|
1314
|
+
options
|
|
1315
|
+
],
|
|
1316
|
+
estimateGas
|
|
1210
1317
|
);
|
|
1211
1318
|
return tx;
|
|
1212
1319
|
}
|
|
@@ -1218,6 +1325,7 @@ export class Pool {
|
|
|
1218
1325
|
* @param {BigNumber | string} amount Amount of LP tokens
|
|
1219
1326
|
* @param { boolean } isStable Is stable pool
|
|
1220
1327
|
* @param {any} options Transaction options
|
|
1328
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1221
1329
|
* @returns {Promise<any>} Transaction
|
|
1222
1330
|
*/
|
|
1223
1331
|
async removeLiquidityVelodromeV2(
|
|
@@ -1225,18 +1333,23 @@ export class Pool {
|
|
|
1225
1333
|
assetB: string,
|
|
1226
1334
|
amount: BigNumber | string,
|
|
1227
1335
|
isStable: boolean,
|
|
1228
|
-
options: any = null
|
|
1336
|
+
options: any = null,
|
|
1337
|
+
estimateGas = false
|
|
1229
1338
|
): Promise<any> {
|
|
1230
|
-
const tx = await
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
this,
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1339
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
1340
|
+
this,
|
|
1341
|
+
[
|
|
1342
|
+
routerAddress[this.network][Dapp.VELODROMEV2],
|
|
1343
|
+
await getVelodromeRemoveLiquidityTxData(
|
|
1344
|
+
this,
|
|
1345
|
+
assetA,
|
|
1346
|
+
assetB,
|
|
1347
|
+
amount,
|
|
1348
|
+
isStable
|
|
1349
|
+
),
|
|
1350
|
+
options
|
|
1351
|
+
],
|
|
1352
|
+
estimateGas
|
|
1240
1353
|
);
|
|
1241
1354
|
return tx;
|
|
1242
1355
|
}
|
|
@@ -1250,6 +1363,7 @@ export class Pool {
|
|
|
1250
1363
|
* @param {BigNumber | string} amountB Amount second asset
|
|
1251
1364
|
* @param { boolean } isStable Is stable pool
|
|
1252
1365
|
* @param {any} options Transaction options
|
|
1366
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1253
1367
|
* @returns {Promise<any>} Transaction
|
|
1254
1368
|
*/
|
|
1255
1369
|
async addLiquidityV2(
|
|
@@ -1259,19 +1373,24 @@ export class Pool {
|
|
|
1259
1373
|
amountA: BigNumber | string,
|
|
1260
1374
|
amountB: BigNumber | string,
|
|
1261
1375
|
isStable: boolean,
|
|
1262
|
-
options: any = null
|
|
1376
|
+
options: any = null,
|
|
1377
|
+
estimateGas = false
|
|
1263
1378
|
): Promise<any> {
|
|
1264
|
-
const tx = await
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
this,
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1379
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
1380
|
+
this,
|
|
1381
|
+
[
|
|
1382
|
+
routerAddress[this.network][dapp],
|
|
1383
|
+
await getVelodromeAddLiquidityTxData(
|
|
1384
|
+
this,
|
|
1385
|
+
assetA,
|
|
1386
|
+
assetB,
|
|
1387
|
+
amountA,
|
|
1388
|
+
amountB,
|
|
1389
|
+
isStable
|
|
1390
|
+
),
|
|
1391
|
+
options
|
|
1392
|
+
],
|
|
1393
|
+
estimateGas
|
|
1275
1394
|
);
|
|
1276
1395
|
return tx;
|
|
1277
1396
|
}
|
|
@@ -1284,6 +1403,7 @@ export class Pool {
|
|
|
1284
1403
|
* @param {BigNumber | string} amount Amount of LP tokens
|
|
1285
1404
|
* @param { boolean } isStable Is stable pool
|
|
1286
1405
|
* @param {any} options Transaction options
|
|
1406
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1287
1407
|
* @returns {Promise<any>} Transaction
|
|
1288
1408
|
*/
|
|
1289
1409
|
async removeLiquidityV2(
|
|
@@ -1292,18 +1412,23 @@ export class Pool {
|
|
|
1292
1412
|
assetB: string,
|
|
1293
1413
|
amount: BigNumber | string,
|
|
1294
1414
|
isStable: boolean,
|
|
1295
|
-
options: any = null
|
|
1415
|
+
options: any = null,
|
|
1416
|
+
estimateGas = false
|
|
1296
1417
|
): Promise<any> {
|
|
1297
|
-
const tx = await
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
this,
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1418
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
1419
|
+
this,
|
|
1420
|
+
[
|
|
1421
|
+
routerAddress[this.network][dapp],
|
|
1422
|
+
await getVelodromeRemoveLiquidityTxData(
|
|
1423
|
+
this,
|
|
1424
|
+
assetA,
|
|
1425
|
+
assetB,
|
|
1426
|
+
amount,
|
|
1427
|
+
isStable
|
|
1428
|
+
),
|
|
1429
|
+
options
|
|
1430
|
+
],
|
|
1431
|
+
estimateGas
|
|
1307
1432
|
);
|
|
1308
1433
|
return tx;
|
|
1309
1434
|
}
|
|
@@ -1320,6 +1445,7 @@ export class Pool {
|
|
|
1320
1445
|
* @param {BigNumber | string } collateralChangeAmount Collateral amount to add when shorting options and to remove when covering shorts
|
|
1321
1446
|
* @param {boolean} isCoveredCall Selling covered call options
|
|
1322
1447
|
* @param {any} options Transaction options
|
|
1448
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1323
1449
|
* @returns {Promise<any>} Transaction
|
|
1324
1450
|
*/
|
|
1325
1451
|
async tradeLyraOption(
|
|
@@ -1332,7 +1458,8 @@ export class Pool {
|
|
|
1332
1458
|
assetIn: string,
|
|
1333
1459
|
collateralChangeAmount: BigNumber | string = "0",
|
|
1334
1460
|
isCoveredCall = false,
|
|
1335
|
-
options: any = null
|
|
1461
|
+
options: any = null,
|
|
1462
|
+
estimateGas = false
|
|
1336
1463
|
): Promise<any> {
|
|
1337
1464
|
const swapxData = await getLyraOptionTxData(
|
|
1338
1465
|
this,
|
|
@@ -1346,10 +1473,10 @@ export class Pool {
|
|
|
1346
1473
|
BigNumber.from(collateralChangeAmount),
|
|
1347
1474
|
isCoveredCall
|
|
1348
1475
|
);
|
|
1349
|
-
const tx = await
|
|
1350
|
-
|
|
1351
|
-
swapxData,
|
|
1352
|
-
|
|
1476
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
1477
|
+
this,
|
|
1478
|
+
[routerAddress[this.network][Dapp.LYRA], swapxData, options],
|
|
1479
|
+
estimateGas
|
|
1353
1480
|
);
|
|
1354
1481
|
return tx;
|
|
1355
1482
|
}
|
|
@@ -1367,17 +1494,19 @@ export class Pool {
|
|
|
1367
1494
|
* @param {string} market Address of futures market
|
|
1368
1495
|
* @param {BigNumber | string } changeAmount Amount to increase/decrease margin
|
|
1369
1496
|
* @param {any} options Transaction options
|
|
1497
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1370
1498
|
* @returns {Promise<any>} Transaction
|
|
1371
1499
|
*/
|
|
1372
1500
|
async changeFuturesMargin(
|
|
1373
1501
|
market: string,
|
|
1374
1502
|
changeAmount: BigNumber | string,
|
|
1375
|
-
options: any = null
|
|
1503
|
+
options: any = null,
|
|
1504
|
+
estimateGas = false
|
|
1376
1505
|
): Promise<any> {
|
|
1377
|
-
const tx = await
|
|
1378
|
-
|
|
1379
|
-
getFuturesChangeMarginTxData(changeAmount),
|
|
1380
|
-
|
|
1506
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
1507
|
+
this,
|
|
1508
|
+
[market, getFuturesChangeMarginTxData(changeAmount), options],
|
|
1509
|
+
estimateGas
|
|
1381
1510
|
);
|
|
1382
1511
|
return tx;
|
|
1383
1512
|
}
|
|
@@ -1387,19 +1516,25 @@ export class Pool {
|
|
|
1387
1516
|
* @param {string} market Address of futures market
|
|
1388
1517
|
* @param {BigNumber | string } changeAmount Negative for short, positive for long
|
|
1389
1518
|
* @param {any} options Transaction options
|
|
1519
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1390
1520
|
* @returns {Promise<any>} Transaction
|
|
1391
1521
|
*/
|
|
1392
1522
|
async changeFuturesPosition(
|
|
1393
1523
|
market: string,
|
|
1394
1524
|
changeAmount: BigNumber | string,
|
|
1395
|
-
options: any = null
|
|
1525
|
+
options: any = null,
|
|
1526
|
+
estimateGas = false
|
|
1396
1527
|
): Promise<any> {
|
|
1397
1528
|
const txData = await getFuturesChangePositionTxData(
|
|
1398
1529
|
changeAmount,
|
|
1399
1530
|
market,
|
|
1400
1531
|
this
|
|
1401
1532
|
);
|
|
1402
|
-
const tx = await
|
|
1533
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
1534
|
+
this,
|
|
1535
|
+
[market, txData, options],
|
|
1536
|
+
estimateGas
|
|
1537
|
+
);
|
|
1403
1538
|
return tx;
|
|
1404
1539
|
}
|
|
1405
1540
|
|
|
@@ -1407,20 +1542,33 @@ export class Pool {
|
|
|
1407
1542
|
*
|
|
1408
1543
|
* @param {string} market Address of futures market
|
|
1409
1544
|
* @param {any} options Transaction options
|
|
1545
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1410
1546
|
* @returns {Promise<any>} Transaction
|
|
1411
1547
|
*/
|
|
1412
|
-
async cancelFuturesOrder(
|
|
1548
|
+
async cancelFuturesOrder(
|
|
1549
|
+
market: string,
|
|
1550
|
+
options: any = null,
|
|
1551
|
+
estimateGas = false
|
|
1552
|
+
): Promise<any> {
|
|
1413
1553
|
const txData = await getFuturesCancelOrderTxData(this);
|
|
1414
|
-
const tx = await
|
|
1554
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
1555
|
+
this,
|
|
1556
|
+
[market, txData, options],
|
|
1557
|
+
estimateGas
|
|
1558
|
+
);
|
|
1415
1559
|
return tx;
|
|
1416
1560
|
}
|
|
1417
1561
|
|
|
1418
1562
|
/**
|
|
1419
1563
|
* mintManagerFee
|
|
1420
1564
|
* @param {any} options Transaction options
|
|
1565
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1421
1566
|
* @returns {Promise<any>} Transaction
|
|
1422
1567
|
*/
|
|
1423
|
-
async mintManagerFee(options: any = null): Promise<any> {
|
|
1568
|
+
async mintManagerFee(options: any = null, estimateGas = false): Promise<any> {
|
|
1569
|
+
if (estimateGas) {
|
|
1570
|
+
return await this.poolLogic.estimateGas.mintManagerFee(options);
|
|
1571
|
+
}
|
|
1424
1572
|
const tx = await this.poolLogic.mintManagerFee(options);
|
|
1425
1573
|
return tx;
|
|
1426
1574
|
}
|
|
@@ -1439,18 +1587,20 @@ export class Pool {
|
|
|
1439
1587
|
* @param {string} tokenAddress Address of the token to vest
|
|
1440
1588
|
* @param {BigNumber | string } changeAmount Negative for short, positive for long
|
|
1441
1589
|
* @param {any} options Transaction options
|
|
1590
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1442
1591
|
* @returns {Promise<any>} Transaction
|
|
1443
1592
|
*/
|
|
1444
1593
|
async vestTokens(
|
|
1445
1594
|
tokenAddress: string,
|
|
1446
1595
|
amount: BigNumber | string,
|
|
1447
|
-
options: any = null
|
|
1596
|
+
options: any = null,
|
|
1597
|
+
estimateGas = false
|
|
1448
1598
|
): Promise<any> {
|
|
1449
1599
|
const txData = await getCreateVestTxData(amount);
|
|
1450
|
-
const tx = await
|
|
1451
|
-
|
|
1452
|
-
txData,
|
|
1453
|
-
|
|
1600
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
1601
|
+
this,
|
|
1602
|
+
[tokenAddress, txData, options],
|
|
1603
|
+
estimateGas
|
|
1454
1604
|
);
|
|
1455
1605
|
return tx;
|
|
1456
1606
|
}
|
|
@@ -1460,18 +1610,20 @@ export class Pool {
|
|
|
1460
1610
|
* @param {string} tokenAddress Address of the token to vest
|
|
1461
1611
|
* @param {number } id position Id of the vested tokens
|
|
1462
1612
|
* @param {any} options Transaction options
|
|
1613
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1463
1614
|
* @returns {Promise<any>} Transaction
|
|
1464
1615
|
*/
|
|
1465
1616
|
async exitVestedToken(
|
|
1466
1617
|
tokenAddress: string,
|
|
1467
1618
|
id: number,
|
|
1468
|
-
options: any = null
|
|
1619
|
+
options: any = null,
|
|
1620
|
+
estimateGas = false
|
|
1469
1621
|
): Promise<any> {
|
|
1470
1622
|
const txData = await getExitVestTxData(id);
|
|
1471
|
-
const tx = await
|
|
1472
|
-
|
|
1473
|
-
txData,
|
|
1474
|
-
|
|
1623
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
1624
|
+
this,
|
|
1625
|
+
[tokenAddress, txData, options],
|
|
1626
|
+
estimateGas
|
|
1475
1627
|
);
|
|
1476
1628
|
return tx;
|
|
1477
1629
|
}
|