@dhedge/v2-sdk 1.3.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/entities/dhedge.d.ts +0 -6
- package/dist/entities/pool.d.ts +42 -13
- package/dist/entities/utils.d.ts +1 -1
- package/dist/test/constants.d.ts +3 -11
- package/dist/test/txOptions.d.ts +2 -1
- package/dist/types.d.ts +7 -9
- package/dist/v2-sdk.cjs.development.js +1059 -347
- 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 +1057 -345
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/IArrakisV1RouterStaking.json +107 -0
- package/src/abi/IBalancerRewardsGauge.json +239 -0
- package/src/abi/ILiquidityGaugeV4.json +153 -0
- package/src/config.ts +6 -2
- package/src/entities/dhedge.ts +0 -11
- package/src/entities/pool.ts +193 -60
- package/src/entities/utils.ts +13 -9
- package/src/test/1inch.test.ts +54 -0
- package/src/test/aave.test.ts +53 -25
- package/src/test/arrakis.test.ts +89 -0
- package/src/test/balancer.test.ts +115 -10
- package/src/test/constants.ts +20 -14
- package/src/test/oneInch.test.ts +13 -20
- package/src/test/pool.test.ts +1 -1
- package/src/test/txOptions.ts +16 -10
- package/src/test/uniswap.test.ts +35 -37
- package/src/test/wallet.ts +5 -5
- package/src/types.ts +7 -9
package/src/entities/pool.ts
CHANGED
|
@@ -11,9 +11,14 @@ import IUniswapV2Router from "../abi/IUniswapV2Router.json";
|
|
|
11
11
|
import INonfungiblePositionManager from "../abi/INonfungiblePositionManager.json";
|
|
12
12
|
import IBalancerMerkleOrchard from "../abi/IBalancerMerkleOrchard.json";
|
|
13
13
|
import IAaveIncentivesController from "../abi/IAaveIncentivesController.json";
|
|
14
|
+
import IArrakisV1RouterStaking from "../abi/IArrakisV1RouterStaking.json";
|
|
15
|
+
import ILiquidityGaugeV4 from "../abi/ILiquidityGaugeV4.json";
|
|
16
|
+
import IBalancerRewardsGauge from "../abi/IBalancerRewardsGauge.json";
|
|
17
|
+
|
|
14
18
|
import {
|
|
15
19
|
deadline,
|
|
16
20
|
MaxUint128,
|
|
21
|
+
networkChainIdMap,
|
|
17
22
|
nonfungiblePositionManagerAddress,
|
|
18
23
|
routerAddress,
|
|
19
24
|
stakingAddress,
|
|
@@ -214,6 +219,33 @@ export class Pool {
|
|
|
214
219
|
return tx;
|
|
215
220
|
}
|
|
216
221
|
|
|
222
|
+
/**
|
|
223
|
+
* Approve the asset for provided spender address
|
|
224
|
+
* @param {string} spender Spender address
|
|
225
|
+
* @param {string} asset Address of asset
|
|
226
|
+
* @param {BigNumber | string} amount to be approved
|
|
227
|
+
* @param {any} options Transaction options
|
|
228
|
+
* @returns {Promise<any>} Transaction
|
|
229
|
+
*/
|
|
230
|
+
async approveSpender(
|
|
231
|
+
spender: string,
|
|
232
|
+
asset: string,
|
|
233
|
+
amount: BigNumber | string,
|
|
234
|
+
options: any = null
|
|
235
|
+
): Promise<any> {
|
|
236
|
+
const iERC20 = new ethers.utils.Interface(IERC20.abi);
|
|
237
|
+
const approveTxData = iERC20.encodeFunctionData("approve", [
|
|
238
|
+
spender,
|
|
239
|
+
amount
|
|
240
|
+
]);
|
|
241
|
+
const tx = await this.poolLogic.execTransaction(
|
|
242
|
+
asset,
|
|
243
|
+
approveTxData,
|
|
244
|
+
options
|
|
245
|
+
);
|
|
246
|
+
return tx;
|
|
247
|
+
}
|
|
248
|
+
|
|
217
249
|
/**
|
|
218
250
|
* Trade an asset into another asset
|
|
219
251
|
* @param {Dapp} dapp Platform like Sushiswap or Uniswap
|
|
@@ -234,7 +266,8 @@ export class Pool {
|
|
|
234
266
|
): Promise<any> {
|
|
235
267
|
let swapTxData: string;
|
|
236
268
|
if (dapp === Dapp.ONEINCH) {
|
|
237
|
-
const
|
|
269
|
+
const chainId = networkChainIdMap[this.network];
|
|
270
|
+
const apiUrl = `https://api.1inch.exchange/v4.0/${chainId}/swap?fromTokenAddress=${assetFrom}&toTokenAddress=${assetTo}&amount=${amountIn.toString()}&fromAddress=${
|
|
238
271
|
this.address
|
|
239
272
|
}&destReceiver=${
|
|
240
273
|
this.address
|
|
@@ -373,7 +406,30 @@ export class Pool {
|
|
|
373
406
|
stakeTxData,
|
|
374
407
|
options
|
|
375
408
|
);
|
|
409
|
+
return tx;
|
|
410
|
+
}
|
|
376
411
|
|
|
412
|
+
/**
|
|
413
|
+
* Stake liquidity pool tokens in gauge contract
|
|
414
|
+
* @param {string} gauge Gauge contract address
|
|
415
|
+
* @param {BigNumber | string} amount Amount of liquidity pool tokens
|
|
416
|
+
* @param {any} options Transaction options
|
|
417
|
+
* @returns {Promise<any>} Transaction
|
|
418
|
+
*/
|
|
419
|
+
async stakeInGauge(
|
|
420
|
+
gauge: string,
|
|
421
|
+
amount: BigNumber | string,
|
|
422
|
+
options: any = null
|
|
423
|
+
): Promise<any> {
|
|
424
|
+
const rewardsGauge = new ethers.utils.Interface(IBalancerRewardsGauge.abi);
|
|
425
|
+
const stakeTxData = rewardsGauge.encodeFunctionData("deposit(uint256)", [
|
|
426
|
+
amount
|
|
427
|
+
]);
|
|
428
|
+
const tx = await this.poolLogic.execTransaction(
|
|
429
|
+
gauge,
|
|
430
|
+
stakeTxData,
|
|
431
|
+
options
|
|
432
|
+
);
|
|
377
433
|
return tx;
|
|
378
434
|
}
|
|
379
435
|
|
|
@@ -406,12 +462,36 @@ export class Pool {
|
|
|
406
462
|
return tx;
|
|
407
463
|
}
|
|
408
464
|
|
|
465
|
+
/**
|
|
466
|
+
* Unstake liquidity pool tokens from gauge contract
|
|
467
|
+
* @param {string} gauge Gauge contract address
|
|
468
|
+
* @param {BigNumber | string} amount Amount of liquidity pool tokens
|
|
469
|
+
* @param {any} options Transaction options
|
|
470
|
+
* @returns {Promise<any>} Transaction
|
|
471
|
+
*/
|
|
472
|
+
async unstakeFromGauge(
|
|
473
|
+
gauge: string,
|
|
474
|
+
amount: BigNumber | string,
|
|
475
|
+
options: any = null
|
|
476
|
+
): Promise<any> {
|
|
477
|
+
const rewardsGauge = new ethers.utils.Interface(IBalancerRewardsGauge.abi);
|
|
478
|
+
const unstakeTxData = rewardsGauge.encodeFunctionData("withdraw(uint256)", [
|
|
479
|
+
amount
|
|
480
|
+
]);
|
|
481
|
+
const tx = await this.poolLogic.execTransaction(
|
|
482
|
+
gauge,
|
|
483
|
+
unstakeTxData,
|
|
484
|
+
options
|
|
485
|
+
);
|
|
486
|
+
return tx;
|
|
487
|
+
}
|
|
488
|
+
|
|
409
489
|
/**
|
|
410
490
|
* Lend asset to a lending pool
|
|
411
491
|
* @param {Dapp} dapp Platform like Aave
|
|
412
492
|
* @param {string} asset Asset
|
|
413
493
|
* @param {BigNumber | string} amount Amount of asset to lend
|
|
414
|
-
* @param {number}
|
|
494
|
+
* @param {number} referralCode Code from Aave referral program
|
|
415
495
|
* @param {any} options Transaction options
|
|
416
496
|
* @returns {Promise<any>} Transaction
|
|
417
497
|
*/
|
|
@@ -419,7 +499,7 @@ export class Pool {
|
|
|
419
499
|
dapp: Dapp,
|
|
420
500
|
asset: string,
|
|
421
501
|
amount: BigNumber | string,
|
|
422
|
-
|
|
502
|
+
referralCode = 0,
|
|
423
503
|
options: any = null
|
|
424
504
|
): Promise<any> {
|
|
425
505
|
const iLendingPool = new ethers.utils.Interface(ILendingPool.abi);
|
|
@@ -427,7 +507,7 @@ export class Pool {
|
|
|
427
507
|
asset,
|
|
428
508
|
amount,
|
|
429
509
|
this.address,
|
|
430
|
-
|
|
510
|
+
referralCode
|
|
431
511
|
]);
|
|
432
512
|
const tx = await this.poolLogic.execTransaction(
|
|
433
513
|
routerAddress[this.network][dapp],
|
|
@@ -469,7 +549,7 @@ export class Pool {
|
|
|
469
549
|
* @param {Dapp} dapp Platform like Aave
|
|
470
550
|
* @param {string} asset Asset
|
|
471
551
|
* @param {BigNumber | string} amount Amount of asset to lend
|
|
472
|
-
* @param {number}
|
|
552
|
+
* @param {number} referralCode Code from Aave referral program
|
|
473
553
|
* @param {any} options Transaction options
|
|
474
554
|
* @returns {Promise<any>} Transaction
|
|
475
555
|
*/
|
|
@@ -477,7 +557,7 @@ export class Pool {
|
|
|
477
557
|
dapp: Dapp,
|
|
478
558
|
asset: string,
|
|
479
559
|
amount: BigNumber | string,
|
|
480
|
-
|
|
560
|
+
referralCode = 0,
|
|
481
561
|
options: any = null
|
|
482
562
|
): Promise<any> {
|
|
483
563
|
const iLendingPool = new ethers.utils.Interface(ILendingPool.abi);
|
|
@@ -485,7 +565,7 @@ export class Pool {
|
|
|
485
565
|
asset,
|
|
486
566
|
amount,
|
|
487
567
|
2,
|
|
488
|
-
|
|
568
|
+
referralCode,
|
|
489
569
|
this.address
|
|
490
570
|
]);
|
|
491
571
|
const tx = await this.poolLogic.execTransaction(
|
|
@@ -620,6 +700,7 @@ export class Pool {
|
|
|
620
700
|
* @param {string} poolId Balancer pool id
|
|
621
701
|
* @param {string[] | } assets Array of balancer pool assets
|
|
622
702
|
* @param {BigNumber | string } amount Amount of pool tokens to withdraw
|
|
703
|
+
* @param { null | number } singleExitAssetIndex Index of asset to withdraw to
|
|
623
704
|
* @param {any} options Transaction options
|
|
624
705
|
* @returns {Promise<any>} Transaction
|
|
625
706
|
*/
|
|
@@ -627,12 +708,14 @@ export class Pool {
|
|
|
627
708
|
poolId: string,
|
|
628
709
|
assets: string[],
|
|
629
710
|
amount: string | BigNumber,
|
|
711
|
+
singleExitAssetIndex: number | null = null,
|
|
630
712
|
options: any = null
|
|
631
713
|
): Promise<any> {
|
|
632
714
|
const exitPoolTxData = this.utils.getBalancerExitPoolTx(
|
|
633
715
|
this,
|
|
634
716
|
poolId,
|
|
635
717
|
assets,
|
|
718
|
+
singleExitAssetIndex,
|
|
636
719
|
amount
|
|
637
720
|
);
|
|
638
721
|
const tx = await this.poolLogic.execTransaction(
|
|
@@ -770,99 +853,149 @@ export class Pool {
|
|
|
770
853
|
}
|
|
771
854
|
|
|
772
855
|
/**
|
|
773
|
-
* Remove liquidity from an UniswapV3 liquidity pool
|
|
856
|
+
* Remove liquidity from an UniswapV3 or Arrakis liquidity pool
|
|
857
|
+
* @param {Dapp} dapp Platform either UniswapV3 or Arrakis
|
|
774
858
|
* @param {string} tokenId Token Id of UniswapV3 position
|
|
775
859
|
* @param {number} amount Amount in percent of assets to be removed
|
|
776
860
|
* @param {any} options Transaction options
|
|
777
861
|
* @returns {Promise<any>} Transaction
|
|
778
862
|
*/
|
|
779
|
-
async
|
|
863
|
+
async decreaseLiquidity(
|
|
864
|
+
dapp: Dapp,
|
|
780
865
|
tokenId: string,
|
|
781
866
|
amount = 100,
|
|
782
867
|
options: any = null
|
|
783
868
|
): Promise<any> {
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
)
|
|
787
|
-
|
|
788
|
-
.
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
869
|
+
let txData;
|
|
870
|
+
let dappAddress;
|
|
871
|
+
if (dapp === Dapp.UNISWAPV3) {
|
|
872
|
+
dappAddress = nonfungiblePositionManagerAddress[this.network];
|
|
873
|
+
const abi = new ethers.utils.Interface(INonfungiblePositionManager.abi);
|
|
874
|
+
const liquidity = (await getUniswapV3Liquidity(tokenId, this))
|
|
875
|
+
.mul(amount)
|
|
876
|
+
.div(100);
|
|
877
|
+
const decreaseLiquidityTxData = abi.encodeFunctionData(
|
|
878
|
+
Transaction.DECREASE_LIQUIDITY,
|
|
879
|
+
[[tokenId, liquidity, 0, 0, deadline]]
|
|
880
|
+
);
|
|
881
|
+
const collectTxData = abi.encodeFunctionData(Transaction.COLLECT, [
|
|
882
|
+
[tokenId, this.address, MaxUint128, MaxUint128]
|
|
883
|
+
]);
|
|
798
884
|
|
|
799
|
-
|
|
885
|
+
const multicallParams = [decreaseLiquidityTxData, collectTxData];
|
|
800
886
|
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
887
|
+
if (amount === 100) {
|
|
888
|
+
const burnTxData = abi.encodeFunctionData(Transaction.BURN, [tokenId]);
|
|
889
|
+
multicallParams.push(burnTxData);
|
|
890
|
+
}
|
|
891
|
+
txData = abi.encodeFunctionData(Transaction.MULTI_CALL, [
|
|
892
|
+
multicallParams
|
|
893
|
+
]);
|
|
894
|
+
} else if (dapp === Dapp.ARRAKIS) {
|
|
895
|
+
dappAddress = routerAddress[this.network][dapp];
|
|
896
|
+
const abi = new ethers.utils.Interface(IArrakisV1RouterStaking.abi);
|
|
897
|
+
const liquidity = (await this.utils.getBalance(tokenId, this.address))
|
|
898
|
+
.mul(amount)
|
|
899
|
+
.div(100);
|
|
900
|
+
txData = abi.encodeFunctionData(Transaction.REMOVE_LIQUIDITY_UNSTAKE, [
|
|
901
|
+
tokenId,
|
|
902
|
+
liquidity,
|
|
903
|
+
0,
|
|
904
|
+
0,
|
|
905
|
+
this.address
|
|
906
|
+
]);
|
|
907
|
+
} else {
|
|
908
|
+
throw new Error("dapp not supported");
|
|
807
909
|
}
|
|
808
|
-
|
|
809
|
-
Transaction.MULTI_CALL,
|
|
810
|
-
[multicallParams]
|
|
811
|
-
);
|
|
910
|
+
|
|
812
911
|
const tx = await this.poolLogic.execTransaction(
|
|
813
|
-
|
|
814
|
-
|
|
912
|
+
dappAddress,
|
|
913
|
+
txData,
|
|
815
914
|
options
|
|
816
915
|
);
|
|
817
916
|
return tx;
|
|
818
917
|
}
|
|
819
918
|
|
|
820
919
|
/**
|
|
821
|
-
* Increase liquidity of an UniswapV3 liquidity pool
|
|
920
|
+
* Increase liquidity of an UniswapV3 or Arrakis liquidity pool
|
|
921
|
+
* @param {Dapp} dapp Platform either UniswapV3 or Arrakis
|
|
822
922
|
* @param {string} tokenId Token Id of UniswapV3 position
|
|
823
923
|
* @param {BigNumber | string} amountA Amount first asset
|
|
824
924
|
* @param {BigNumber | string} amountB Amount second asset
|
|
825
925
|
* @param {any} options Transaction options
|
|
826
926
|
* @returns {Promise<any>} Transaction
|
|
827
927
|
*/
|
|
828
|
-
async
|
|
928
|
+
async increaseLiquidity(
|
|
929
|
+
dapp: Dapp,
|
|
829
930
|
tokenId: string,
|
|
830
931
|
amountA: BigNumber | string,
|
|
831
932
|
amountB: BigNumber | string,
|
|
832
933
|
options: any = null
|
|
833
934
|
): Promise<any> {
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
)
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
935
|
+
let txData;
|
|
936
|
+
let dappAddress;
|
|
937
|
+
if (dapp === Dapp.UNISWAPV3) {
|
|
938
|
+
dappAddress = nonfungiblePositionManagerAddress[this.network];
|
|
939
|
+
const abi = new ethers.utils.Interface(INonfungiblePositionManager.abi);
|
|
940
|
+
txData = abi.encodeFunctionData(Transaction.INCREASE_LIQUIDITY, [
|
|
941
|
+
[tokenId, amountA, amountB, 0, 0, deadline]
|
|
942
|
+
]);
|
|
943
|
+
} else if (dapp === Dapp.ARRAKIS) {
|
|
944
|
+
dappAddress = routerAddress[this.network][dapp];
|
|
945
|
+
const abi = new ethers.utils.Interface(IArrakisV1RouterStaking.abi);
|
|
946
|
+
txData = abi.encodeFunctionData(Transaction.ADD_LIQUIDITY_STAKE, [
|
|
947
|
+
tokenId,
|
|
948
|
+
amountA,
|
|
949
|
+
amountB,
|
|
950
|
+
0,
|
|
951
|
+
0,
|
|
952
|
+
this.address
|
|
953
|
+
]);
|
|
954
|
+
} else {
|
|
955
|
+
throw new Error("dapp not supported");
|
|
956
|
+
}
|
|
957
|
+
|
|
841
958
|
const tx = await this.poolLogic.execTransaction(
|
|
842
|
-
|
|
843
|
-
|
|
959
|
+
dappAddress,
|
|
960
|
+
txData,
|
|
844
961
|
options
|
|
845
962
|
);
|
|
846
963
|
return tx;
|
|
847
964
|
}
|
|
848
965
|
|
|
849
966
|
/**
|
|
850
|
-
* Claim fees of an UniswapV3 liquidity pool
|
|
851
|
-
* @param {
|
|
852
|
-
* @param {
|
|
967
|
+
* Claim fees of an UniswapV3 liquidity or Arrakis pool
|
|
968
|
+
* @param {Dapp} dapp Platform either UniswapV3 or Arrakis
|
|
969
|
+
* @param {string} tokenId Token Id of UniswapV3 or Gauge address
|
|
970
|
+
* @param {any} options Transaction option
|
|
853
971
|
* @returns {Promise<any>} Transaction
|
|
854
972
|
*/
|
|
855
|
-
async
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
)
|
|
973
|
+
async claimFees(
|
|
974
|
+
dapp: Dapp,
|
|
975
|
+
tokenId: string,
|
|
976
|
+
options: any = null
|
|
977
|
+
): Promise<any> {
|
|
978
|
+
let txData;
|
|
979
|
+
let contractAddress;
|
|
980
|
+
if (dapp === Dapp.UNISWAPV3) {
|
|
981
|
+
contractAddress = nonfungiblePositionManagerAddress[this.network];
|
|
982
|
+
const iNonfungiblePositionManager = new ethers.utils.Interface(
|
|
983
|
+
INonfungiblePositionManager.abi
|
|
984
|
+
);
|
|
985
|
+
txData = iNonfungiblePositionManager.encodeFunctionData(
|
|
986
|
+
Transaction.COLLECT,
|
|
987
|
+
[[tokenId, this.address, MaxUint128, MaxUint128]]
|
|
988
|
+
);
|
|
989
|
+
} else if (dapp === Dapp.ARRAKIS || dapp === Dapp.BALANCER) {
|
|
990
|
+
contractAddress = tokenId;
|
|
991
|
+
const abi = new ethers.utils.Interface(ILiquidityGaugeV4.abi);
|
|
992
|
+
txData = abi.encodeFunctionData("claim_rewards()", []);
|
|
993
|
+
} else {
|
|
994
|
+
throw new Error("dapp not supported");
|
|
995
|
+
}
|
|
863
996
|
const tx = await this.poolLogic.execTransaction(
|
|
864
|
-
|
|
865
|
-
|
|
997
|
+
contractAddress,
|
|
998
|
+
txData,
|
|
866
999
|
options
|
|
867
1000
|
);
|
|
868
1001
|
return tx;
|
package/src/entities/utils.ts
CHANGED
|
@@ -295,25 +295,29 @@ export class Utils {
|
|
|
295
295
|
pool: Pool,
|
|
296
296
|
balancerPoolId: string,
|
|
297
297
|
assets: string[],
|
|
298
|
+
singleExitAssetIndex: null | number,
|
|
298
299
|
amount: string | ethers.BigNumber
|
|
299
300
|
|
|
300
301
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
301
302
|
): Promise<any> {
|
|
302
303
|
const minimumAmountOut = new Array(assets.length).fill(0);
|
|
303
304
|
const iBalancerV2Vault = new ethers.utils.Interface(IBalancerV2Vault.abi);
|
|
305
|
+
const userTxData =
|
|
306
|
+
singleExitAssetIndex === null
|
|
307
|
+
? ethers.utils.defaultAbiCoder.encode(
|
|
308
|
+
["uint256", "uint256"],
|
|
309
|
+
[1, amount]
|
|
310
|
+
)
|
|
311
|
+
: ethers.utils.defaultAbiCoder.encode(
|
|
312
|
+
["uint256", "uint256", "uint256"],
|
|
313
|
+
[0, amount, singleExitAssetIndex]
|
|
314
|
+
);
|
|
315
|
+
|
|
304
316
|
const txData = [
|
|
305
317
|
balancerPoolId,
|
|
306
318
|
pool.address,
|
|
307
319
|
pool.address,
|
|
308
|
-
[
|
|
309
|
-
assets,
|
|
310
|
-
minimumAmountOut,
|
|
311
|
-
ethers.utils.defaultAbiCoder.encode(
|
|
312
|
-
["uint256", "uint256"],
|
|
313
|
-
[1, amount]
|
|
314
|
-
),
|
|
315
|
-
false
|
|
316
|
-
]
|
|
320
|
+
[assets, minimumAmountOut, userTxData, false]
|
|
317
321
|
];
|
|
318
322
|
const exitPoolTx = iBalancerV2Vault.encodeFunctionData("exitPool", txData);
|
|
319
323
|
return exitPoolTx;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Dhedge } from "..";
|
|
2
|
+
import { Dapp, Network } from "../types";
|
|
3
|
+
import { TEST_POOL, USDC, WETH } from "./constants";
|
|
4
|
+
import { getTxOptions } from "./txOptions";
|
|
5
|
+
|
|
6
|
+
import { wallet } from "./wallet";
|
|
7
|
+
|
|
8
|
+
let dhedge: Dhedge;
|
|
9
|
+
let options: any;
|
|
10
|
+
|
|
11
|
+
jest.setTimeout(100000);
|
|
12
|
+
|
|
13
|
+
describe("pool", () => {
|
|
14
|
+
beforeAll(async () => {
|
|
15
|
+
dhedge = new Dhedge(wallet, Network.OPTIMISM);
|
|
16
|
+
options = await getTxOptions(Network.OPTIMISM);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// it("approves unlimited USDC on 1Inch", async () => {
|
|
20
|
+
// let result;
|
|
21
|
+
// const pool = await dhedge.loadPool(TEST_POOL);
|
|
22
|
+
// try {
|
|
23
|
+
// result = await pool.approve(
|
|
24
|
+
// Dapp.ONEINCH,
|
|
25
|
+
// USDC,
|
|
26
|
+
// ethers.constants.MaxInt256,
|
|
27
|
+
// options
|
|
28
|
+
// );
|
|
29
|
+
// console.log(result);
|
|
30
|
+
// } catch (e) {
|
|
31
|
+
// console.log(e);
|
|
32
|
+
// }
|
|
33
|
+
// expect(result).not.toBe(null);
|
|
34
|
+
// });
|
|
35
|
+
|
|
36
|
+
it("trades 1 USDC into WETH on 1Inch", async () => {
|
|
37
|
+
let result;
|
|
38
|
+
const pool = await dhedge.loadPool(TEST_POOL);
|
|
39
|
+
try {
|
|
40
|
+
result = await pool.trade(
|
|
41
|
+
Dapp.ONEINCH,
|
|
42
|
+
USDC,
|
|
43
|
+
WETH,
|
|
44
|
+
"1000000",
|
|
45
|
+
0.5,
|
|
46
|
+
options
|
|
47
|
+
);
|
|
48
|
+
console.log(result);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
console.log(e);
|
|
51
|
+
}
|
|
52
|
+
expect(result).not.toBe(null);
|
|
53
|
+
});
|
|
54
|
+
});
|
package/src/test/aave.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Dhedge
|
|
2
|
-
import { Network } from "../types";
|
|
3
|
-
import {
|
|
1
|
+
import { Dhedge } from "..";
|
|
2
|
+
import { Dapp, Network } from "../types";
|
|
3
|
+
import { TEST_POOL, WETH } from "./constants";
|
|
4
4
|
|
|
5
5
|
import { wallet } from "./wallet";
|
|
6
6
|
|
|
@@ -8,16 +8,32 @@ let dhedge: Dhedge;
|
|
|
8
8
|
|
|
9
9
|
jest.setTimeout(100000);
|
|
10
10
|
|
|
11
|
-
const options = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
11
|
+
// const options = {
|
|
12
|
+
// gasLimit: 5000000,
|
|
13
|
+
// gasPrice: ethers.utils.parseUnits("100", "gwei")
|
|
14
|
+
// };
|
|
15
15
|
|
|
16
16
|
describe("pool", () => {
|
|
17
17
|
beforeAll(() => {
|
|
18
|
-
dhedge = new Dhedge(wallet, Network.
|
|
18
|
+
dhedge = new Dhedge(wallet, Network.OPTIMISM);
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
+
// it("approves USDC to Aave", async () => {
|
|
22
|
+
// let result;
|
|
23
|
+
// const pool = await dhedge.loadPool(TEST_POOL);
|
|
24
|
+
// try {
|
|
25
|
+
// result = await pool.approve(
|
|
26
|
+
// Dapp.AAVEV3,
|
|
27
|
+
// USDC,
|
|
28
|
+
// ethers.constants.MaxUint256
|
|
29
|
+
// );
|
|
30
|
+
// console.log(result);
|
|
31
|
+
// } catch (e) {
|
|
32
|
+
// console.log(e);
|
|
33
|
+
// }
|
|
34
|
+
// expect(result).not.toBe(null);
|
|
35
|
+
// });
|
|
36
|
+
|
|
21
37
|
// it("withdraws 1 USDC from Aave lending pool", async () => {
|
|
22
38
|
// let result;
|
|
23
39
|
// const pool = await dhedge.loadPool(myPool);
|
|
@@ -35,11 +51,23 @@ describe("pool", () => {
|
|
|
35
51
|
// expect(result).not.toBe(null);
|
|
36
52
|
// });
|
|
37
53
|
|
|
38
|
-
|
|
54
|
+
it("borrows 0.001 WETH from Aave lending pool", async () => {
|
|
55
|
+
let result;
|
|
56
|
+
const pool = await dhedge.loadPool(TEST_POOL);
|
|
57
|
+
try {
|
|
58
|
+
result = await pool.borrow(Dapp.AAVEV3, WETH, "1000000000000000");
|
|
59
|
+
console.log(result);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
console.log(e);
|
|
62
|
+
}
|
|
63
|
+
expect(result).not.toBe(null);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// it("reapys 1USDC to Aave lending pool", async () => {
|
|
39
67
|
// let result;
|
|
40
|
-
// const pool = await dhedge.loadPool(
|
|
68
|
+
// const pool = await dhedge.loadPool(TEST_POOL);
|
|
41
69
|
// try {
|
|
42
|
-
// result = await pool.
|
|
70
|
+
// result = await pool.repay(Dapp.AAVEV3, USDC, "1380000");
|
|
43
71
|
// console.log(result);
|
|
44
72
|
// } catch (e) {
|
|
45
73
|
// console.log(e);
|
|
@@ -47,11 +75,11 @@ describe("pool", () => {
|
|
|
47
75
|
// expect(result).not.toBe(null);
|
|
48
76
|
// });
|
|
49
77
|
|
|
50
|
-
// it("
|
|
78
|
+
// it("claims rewards from Aave", async () => {
|
|
51
79
|
// let result;
|
|
52
|
-
// const pool = await dhedge.loadPool(
|
|
80
|
+
// const pool = await dhedge.loadPool(TEST_POOL);
|
|
53
81
|
// try {
|
|
54
|
-
// result = await pool.
|
|
82
|
+
// result = await pool.harvestAaveRewards([AMUSDC, VDEBTWETH], options);
|
|
55
83
|
// console.log(result);
|
|
56
84
|
// } catch (e) {
|
|
57
85
|
// console.log(e);
|
|
@@ -59,15 +87,15 @@ describe("pool", () => {
|
|
|
59
87
|
// expect(result).not.toBe(null);
|
|
60
88
|
// });
|
|
61
89
|
|
|
62
|
-
it("
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
90
|
+
// it("lends USDC to Aave", async () => {
|
|
91
|
+
// let result;
|
|
92
|
+
// const pool = await dhedge.loadPool(TEST_POOL);
|
|
93
|
+
// try {
|
|
94
|
+
// const balance = await dhedge.utils.getBalance(WETH, pool.address);
|
|
95
|
+
// result = await pool.lend(Dapp.AAVEV3, WETH, balance, 196);
|
|
96
|
+
// } catch (e) {
|
|
97
|
+
// console.log(e);
|
|
98
|
+
// }
|
|
99
|
+
// expect(result).not.toBe(null);
|
|
100
|
+
// });
|
|
73
101
|
});
|