@dhedge/v2-sdk 1.10.16 → 1.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhedge/v2-sdk",
3
- "version": "1.10.16",
3
+ "version": "1.11.1",
4
4
  "license": "MIT",
5
5
  "description": "🛠 An SDK for building applications on top of dHEDGE V2",
6
6
  "main": "dist/index.js",
@@ -23,7 +23,8 @@
23
23
  "fork:polygon": "hardhat node --port 8542 --fork $(grep POLYGON_URL .env | cut -d '=' -f2)",
24
24
  "fork:optimism": "hardhat node --port 8544 --fork $(grep OPTIMISM_URL .env | cut -d '=' -f2)",
25
25
  "fork:arbitrum": "hardhat node --port 8540 --fork $(grep ARBITRUM_URL .env | cut -d '=' -f2)",
26
- "fork:base": "hardhat node --port 8546 --fork $(grep BASE_URL .env | cut -d '=' -f2)"
26
+ "fork:base": "hardhat node --port 8546 --fork $(grep BASE_URL .env | cut -d '=' -f2)",
27
+ "fork:ethereum": "hardhat node --port 8547 --fork $(grep ETHEREUM_URL .env | cut -d '=' -f2)"
27
28
  },
28
29
  "husky": {
29
30
  "hooks": {
@@ -0,0 +1,27 @@
1
+ [
2
+ {
3
+ "inputs": [
4
+ { "internalType": "uint256", "name": "assets_", "type": "uint256" },
5
+ { "internalType": "address", "name": "receiver_", "type": "address" }
6
+ ],
7
+ "name": "deposit",
8
+ "outputs": [
9
+ { "internalType": "uint256", "name": "shares_", "type": "uint256" }
10
+ ],
11
+ "stateMutability": "nonpayable",
12
+ "type": "function"
13
+ },
14
+ {
15
+ "inputs": [
16
+ { "internalType": "uint256", "name": "shares_", "type": "uint256" },
17
+ { "internalType": "address", "name": "receiver_", "type": "address" },
18
+ { "internalType": "address", "name": "owner_", "type": "address" }
19
+ ],
20
+ "name": "redeem",
21
+ "outputs": [
22
+ { "internalType": "uint256", "name": "assets_", "type": "uint256" }
23
+ ],
24
+ "stateMutability": "nonpayable",
25
+ "type": "function"
26
+ }
27
+ ]
package/src/config.ts CHANGED
@@ -18,7 +18,7 @@ export const factoryAddress: AddressNetworkMap = {
18
18
  [Network.OPTIMISM]: "0x5e61a079A178f0E5784107a4963baAe0c5a680c6",
19
19
  [Network.ARBITRUM]: "0xfffb5fb14606eb3a548c113026355020ddf27535",
20
20
  [Network.BASE]: "0x49Afe3abCf66CF09Fab86cb1139D8811C8afe56F",
21
- [Network.SONIC]: ""
21
+ [Network.ETHEREUM]: "0x96D33bCF84DdE326014248E2896F79bbb9c13D6d"
22
22
  };
23
23
 
24
24
  export const routerAddress: AddressDappNetworkMap = {
@@ -65,10 +65,11 @@ export const routerAddress: AddressDappNetworkMap = {
65
65
  [Dapp.ODOS]: "0x19cEeAd7105607Cd444F5ad10dd51356436095a1",
66
66
  [Dapp.PENDLE]: "0x888888888889758F76e7103c6CbF23ABbF58F946"
67
67
  },
68
- [Network.SONIC]: {
69
- [Dapp.AAVEV3]: "0x5362dBb1e601abF3a4c14c22ffEdA64042E5eAA3",
70
- [Dapp.ODOS]: "0xaC041Df48dF9791B0654f1Dbbf2CC8450C5f2e9D",
71
- [Dapp.PENDLE]: "0x888888888889758F76e7103c6CbF23ABbF58F946"
68
+ [Network.ETHEREUM]: {
69
+ [Dapp.AAVEV3]: "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2",
70
+ [Dapp.ODOS]: "0xCf5540fFFCdC3d510B18bFcA6d2b9987b0772559",
71
+ [Dapp.PENDLE]: "0x888888888889758F76e7103c6CbF23ABbF58F946",
72
+ [Dapp.ONEINCH]: "0x111111125421ca6dc452d289314280a0f8842a65"
72
73
  }
73
74
  };
74
75
 
@@ -80,7 +81,7 @@ export const dappFactoryAddress: AddressDappNetworkMap = {
80
81
  [Network.OPTIMISM]: {},
81
82
  [Network.ARBITRUM]: {},
82
83
  [Network.BASE]: {},
83
- [Network.SONIC]: {}
84
+ [Network.ETHEREUM]: {}
84
85
  };
85
86
 
86
87
  export const stakingAddress: AddressDappNetworkMap = {
@@ -101,9 +102,7 @@ export const stakingAddress: AddressDappNetworkMap = {
101
102
  [Network.BASE]: {
102
103
  [Dapp.PANCAKECL]: "0xC6A2Db661D5a5690172d8eB0a7DEA2d3008665A3"
103
104
  },
104
- [Network.SONIC]: {
105
- [Dapp.SHADOWCL]: "0xe879d0E44e6873cf4ab71686055a4f6817685f02" //specific for wS/USDC CL
106
- }
105
+ [Network.ETHEREUM]: {}
107
106
  };
108
107
 
109
108
  export const aaveAddressProvider: AddressDappNetworkMap = {
@@ -121,8 +120,8 @@ export const aaveAddressProvider: AddressDappNetworkMap = {
121
120
  // https://docs.aave.com/developers/deployed-contracts/v3-mainnet/base
122
121
  [Dapp.AAVEV3]: "0xe20fCBdBfFC4Dd138cE8b2E6FBb6CB49777ad64D"
123
122
  },
124
- [Network.SONIC]: {
125
- [Dapp.AAVEV3]: "0x5C2e738F6E27bCE0F7558051Bf90605dD6176900"
123
+ [Network.ETHEREUM]: {
124
+ [Dapp.AAVEV3]: "0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e"
126
125
  }
127
126
  };
128
127
  export const nonfungiblePositionManagerAddress: AddressDappNetworkMap = {
@@ -143,9 +142,7 @@ export const nonfungiblePositionManagerAddress: AddressDappNetworkMap = {
143
142
  [Dapp.AERODROMECL]: "0x827922686190790b37229fd06084350e74485b72",
144
143
  [Dapp.PANCAKECL]: "0x46A15B0b27311cedF172AB29E4f4766fbE7F4364"
145
144
  },
146
- [Network.SONIC]: {
147
- [Dapp.SHADOWCL]: "0x12e66c8f215ddd5d48d150c8f46ad0c6fb0f4406"
148
- }
145
+ [Network.ETHEREUM]: {}
149
146
  };
150
147
 
151
148
  export const networkChainIdMap: NetworkChainIdMap = {
@@ -153,7 +150,7 @@ export const networkChainIdMap: NetworkChainIdMap = {
153
150
  [Network.OPTIMISM]: 10,
154
151
  [Network.ARBITRUM]: 42161,
155
152
  [Network.BASE]: 8453,
156
- [Network.SONIC]: 146
153
+ [Network.ETHEREUM]: 1
157
154
  };
158
155
 
159
156
  export const balancerSubgraph: AddressNetworkMap = {
@@ -162,7 +159,7 @@ export const balancerSubgraph: AddressNetworkMap = {
162
159
  [Network.OPTIMISM]: "",
163
160
  [Network.ARBITRUM]: "",
164
161
  [Network.BASE]: "",
165
- [Network.SONIC]: ""
162
+ [Network.ETHEREUM]: ""
166
163
  };
167
164
 
168
165
  export const multiCallAddress: AddressNetworkMap = {
@@ -170,7 +167,7 @@ export const multiCallAddress: AddressNetworkMap = {
170
167
  [Network.OPTIMISM]: "",
171
168
  [Network.ARBITRUM]: "",
172
169
  [Network.BASE]: "",
173
- [Network.SONIC]: ""
170
+ [Network.ETHEREUM]: ""
174
171
  };
175
172
 
176
173
  export const lyraNetworkMap: LyraNetworkMap = {
@@ -19,7 +19,7 @@ import {
19
19
  nonfungiblePositionManagerAddress,
20
20
  routerAddress,
21
21
  stakingAddress,
22
- SYNTHETIX_TRACKING_CODE,
22
+ SYNTHETIX_TRACKING_CODE
23
23
  } from "../config";
24
24
  import {
25
25
  Dapp,
@@ -30,60 +30,60 @@ import {
30
30
  LyraOptionMarket,
31
31
  LyraOptionType,
32
32
  LyraTradeType,
33
- LyraPosition,
33
+ LyraPosition
34
34
  } from "../types";
35
35
 
36
36
  import { Utils } from "./utils";
37
37
  import {
38
38
  getDecreaseLiquidityTxData,
39
39
  getIncreaseLiquidityTxData,
40
- getUniswapV3MintTxData,
40
+ getUniswapV3MintTxData
41
41
  } from "../services/uniswap/V3Liquidity";
42
42
  import { getUniswapV3SwapTxData } from "../services/uniswap/V3Trade";
43
43
  import {
44
44
  getCompleteWithdrawalTxData,
45
- getEasySwapperTxData,
45
+ getEasySwapperTxData
46
46
  } from "../services/toros/easySwapper";
47
47
  import { getAaveV3ClaimTxData } from "../services/aave/incentives";
48
48
  import {
49
49
  getClOwner,
50
50
  getVelodromeAddLiquidityTxData,
51
- getVelodromeRemoveLiquidityTxData,
51
+ getVelodromeRemoveLiquidityTxData
52
52
  } from "../services/velodrome/liquidity";
53
53
  import {
54
54
  getVelodromeClaimTxData,
55
55
  getVelodromeCLClaimTxData,
56
- getVelodromeStakeTxData,
56
+ getVelodromeStakeTxData
57
57
  } from "../services/velodrome/staking";
58
58
  import { getLyraOptionTxData } from "../services/lyra/trade";
59
59
  import { getOptionPositions } from "../services/lyra/positions";
60
60
  import { getDeadline } from "../utils/deadline";
61
61
  import {
62
62
  getFuturesChangePositionTxData,
63
- getFuturesChangeMarginTxData,
63
+ getFuturesChangeMarginTxData
64
64
  } from "../services/futures";
65
65
  import { getFuturesCancelOrderTxData } from "../services/futures/trade";
66
66
  import { getOneInchSwapTxData } from "../services/oneInch";
67
67
  import {
68
68
  getCreateVestTxData,
69
69
  getExitVestTxData,
70
- getRewardsTxDta,
70
+ getRewardsTxDta
71
71
  } from "../services/ramses/vesting";
72
72
  import { getPoolTxOrGasEstimate } from "../utils/contract";
73
73
  import {
74
74
  cancelOrderViaFlatMoney,
75
75
  mintUnitViaFlatMoney,
76
- redeemUnitViaFlatMoney,
76
+ redeemUnitViaFlatMoney
77
77
  } from "../services/flatmoney/stableLp";
78
78
  import {
79
79
  getCompoundV3LendTxData,
80
- getCompoundV3WithdrawTxData,
80
+ getCompoundV3WithdrawTxData
81
81
  } from "../services/compound/lending";
82
82
  import { getCompoundV3ClaimTxData } from "../services/compound/rewards";
83
83
  import {
84
84
  getPancakeHarvestClaimTxData,
85
85
  getPancakeStakeTxData,
86
- getPancakeUnStakeTxData,
86
+ getPancakeUnStakeTxData
87
87
  } from "../services/pancake/staking";
88
88
  import { getOdosSwapTxData } from "../services/odos";
89
89
  import { getPendleSwapTxData } from "../services/pendle";
@@ -131,7 +131,7 @@ export class Pool {
131
131
  asset: asset,
132
132
  isDeposit: isDeposit,
133
133
  balance: result[1][index],
134
- rate: result[2][index],
134
+ rate: result[2][index]
135
135
  };
136
136
  }
137
137
  );
@@ -226,7 +226,7 @@ export class Pool {
226
226
  const iERC20 = new ethers.utils.Interface(IERC20.abi);
227
227
  const approveTxData = iERC20.encodeFunctionData("approve", [
228
228
  routerAddress[this.network][dapp],
229
- amount,
229
+ amount
230
230
  ]);
231
231
  const tx = await getPoolTxOrGasEstimate(
232
232
  this,
@@ -255,7 +255,7 @@ export class Pool {
255
255
  const iERC20 = new ethers.utils.Interface(IERC20.abi);
256
256
  const approveTxData = iERC20.encodeFunctionData("approve", [
257
257
  stakingAddress[this.network][dapp],
258
- amount,
258
+ amount
259
259
  ]);
260
260
  const tx = await getPoolTxOrGasEstimate(
261
261
  this,
@@ -283,7 +283,7 @@ export class Pool {
283
283
  const iERC20 = new ethers.utils.Interface(IERC20.abi);
284
284
  const approveTxData = iERC20.encodeFunctionData("approve", [
285
285
  nonfungiblePositionManagerAddress[this.network][Dapp.UNISWAPV3],
286
- amount,
286
+ amount
287
287
  ]);
288
288
  const tx = await getPoolTxOrGasEstimate(
289
289
  this,
@@ -312,7 +312,7 @@ export class Pool {
312
312
  const iERC20 = new ethers.utils.Interface(IERC20.abi);
313
313
  const approveTxData = iERC20.encodeFunctionData("approve", [
314
314
  spender,
315
- amount,
315
+ amount
316
316
  ]);
317
317
  const tx = await getPoolTxOrGasEstimate(
318
318
  this,
@@ -341,7 +341,7 @@ export class Pool {
341
341
  const iERC721 = new ethers.utils.Interface(IERC721.abi);
342
342
  const approveTxData = iERC721.encodeFunctionData("approve", [
343
343
  spender,
344
- tokenId,
344
+ tokenId
345
345
  ]);
346
346
  const tx = await getPoolTxOrGasEstimate(
347
347
  this,
@@ -393,7 +393,7 @@ export class Pool {
393
393
  break;
394
394
  case Dapp.SYNTHETIX:
395
395
  const iSynthetix = new ethers.utils.Interface(ISynthetix.abi);
396
- const assets = [assetFrom, assetTo].map((asset) =>
396
+ const assets = [assetFrom, assetTo].map(asset =>
397
397
  ethers.utils.formatBytes32String(asset)
398
398
  );
399
399
  const daoAddress = await this.factory.owner();
@@ -402,7 +402,7 @@ export class Pool {
402
402
  amountIn,
403
403
  assets[1],
404
404
  daoAddress,
405
- SYNTHETIX_TRACKING_CODE,
405
+ SYNTHETIX_TRACKING_CODE
406
406
  ]);
407
407
  break;
408
408
  case Dapp.TOROS:
@@ -448,7 +448,7 @@ export class Pool {
448
448
  minAmountOut,
449
449
  [assetFrom, assetTo],
450
450
  this.address,
451
- await getDeadline(this),
451
+ await getDeadline(this)
452
452
  ]);
453
453
  }
454
454
  const tx = await getPoolTxOrGasEstimate(
@@ -490,7 +490,7 @@ export class Pool {
490
490
  0,
491
491
  0,
492
492
  this.address,
493
- await getDeadline(this),
493
+ await getDeadline(this)
494
494
  ]
495
495
  );
496
496
  const tx = await getPoolTxOrGasEstimate(
@@ -553,7 +553,7 @@ export class Pool {
553
553
  const stakeTxData = iMiniChefV2.encodeFunctionData(Transaction.DEPOSIT, [
554
554
  poolId,
555
555
  amount,
556
- this.address,
556
+ this.address
557
557
  ]);
558
558
  const tx = await getPoolTxOrGasEstimate(
559
559
  this,
@@ -586,7 +586,7 @@ export class Pool {
586
586
  IBalancerRewardsGauge.abi
587
587
  );
588
588
  stakeTxData = rewardsGauge.encodeFunctionData("deposit(uint256)", [
589
- amount,
589
+ amount
590
590
  ]);
591
591
  break;
592
592
  case Dapp.VELODROME:
@@ -638,7 +638,7 @@ export class Pool {
638
638
  const unStakeTxData = iMiniChefV2.encodeFunctionData(Transaction.WITHDRAW, [
639
639
  poolId,
640
640
  amount,
641
- this.address,
641
+ this.address
642
642
  ]);
643
643
  const tx = await getPoolTxOrGasEstimate(
644
644
  this,
@@ -671,7 +671,7 @@ export class Pool {
671
671
  unstakeTxData = getPancakeUnStakeTxData(this, amount.toString());
672
672
  } else {
673
673
  unstakeTxData = rewardsGauge.encodeFunctionData("withdraw(uint256)", [
674
- amount,
674
+ amount
675
675
  ]);
676
676
  }
677
677
  const tx = await getPoolTxOrGasEstimate(
@@ -705,7 +705,7 @@ export class Pool {
705
705
  asset,
706
706
  amount,
707
707
  this.address,
708
- referralCode,
708
+ referralCode
709
709
  ]);
710
710
 
711
711
  const tx = await getPoolTxOrGasEstimate(
@@ -717,8 +717,8 @@ export class Pool {
717
717
  }
718
718
 
719
719
  /**
720
- * Lend asset to a Compound V3 style lending pool
721
- * @param {string} market Address of market e.g cUSDCv3 address
720
+ * Lend asset to a Compound V3 or Fluid lending pool
721
+ * @param {string} market Address of cToken or fToken
722
722
  * @param {string} asset Asset
723
723
  * @param {BigNumber | string} amount Amount of asset to lend
724
724
  * @param {any} options Transaction options
@@ -732,7 +732,12 @@ export class Pool {
732
732
  options: any = null,
733
733
  estimateGas = false
734
734
  ): Promise<any> {
735
- const supplyTxData = getCompoundV3LendTxData(asset, amount);
735
+ const supplyTxData = await getCompoundV3LendTxData(
736
+ this,
737
+ market,
738
+ asset,
739
+ amount
740
+ );
736
741
 
737
742
  const tx = await getPoolTxOrGasEstimate(
738
743
  this,
@@ -773,8 +778,8 @@ export class Pool {
773
778
  }
774
779
 
775
780
  /**
776
- * Witdraw asset from a COmpound V3 style lending pool
777
- * @param {string} market Address of market e.g cUSDCv3 address
781
+ * Witdraw asset from a Compound V3 or Fluid lending pool
782
+ * @param {string} market Address of cToken or fToken
778
783
  * @param {string} asset Asset
779
784
  * @param {BigNumber | string} amount Amount of asset to withdraw
780
785
  * @param {any} options Transaction options
@@ -788,7 +793,12 @@ export class Pool {
788
793
  options: any = null,
789
794
  estimateGas = false
790
795
  ): Promise<any> {
791
- const withdrawTxData = getCompoundV3WithdrawTxData(asset, amount);
796
+ const withdrawTxData = await getCompoundV3WithdrawTxData(
797
+ this,
798
+ market,
799
+ asset,
800
+ amount
801
+ );
792
802
 
793
803
  const tx = await getPoolTxOrGasEstimate(
794
804
  this,
@@ -822,7 +832,7 @@ export class Pool {
822
832
  amount,
823
833
  2,
824
834
  referralCode,
825
- this.address,
835
+ this.address
826
836
  ]);
827
837
  const tx = await getPoolTxOrGasEstimate(
828
838
  this,
@@ -853,7 +863,7 @@ export class Pool {
853
863
  asset,
854
864
  amount,
855
865
  2,
856
- this.address,
866
+ this.address
857
867
  ]);
858
868
  const tx = await getPoolTxOrGasEstimate(
859
869
  this,
@@ -881,7 +891,7 @@ export class Pool {
881
891
  const poolId = await this.utils.getLpPoolId(dapp, asset);
882
892
  const harvestTxData = iMiniChefV2.encodeFunctionData(Transaction.HARVEST, [
883
893
  poolId,
884
- this.address,
894
+ this.address
885
895
  ]);
886
896
  const tx = await getPoolTxOrGasEstimate(
887
897
  this,
@@ -904,12 +914,12 @@ export class Pool {
904
914
  estimateGas = false
905
915
  ): Promise<any> {
906
916
  const currentAssetsEnabled = await this.getComposition();
907
- const currentAssets = currentAssetsEnabled.map((e) =>
917
+ const currentAssets = currentAssetsEnabled.map(e =>
908
918
  e.asset.toLocaleLowerCase()
909
919
  );
910
- const newAssets = assets.map((e) => e.asset.toLocaleLowerCase());
911
- const removedAssets = currentAssets.filter((e) => !newAssets.includes(e));
912
- const changedAssets = assets.map((e) => [e.asset, e.isDeposit]);
920
+ const newAssets = assets.map(e => e.asset.toLocaleLowerCase());
921
+ const removedAssets = currentAssets.filter(e => !newAssets.includes(e));
922
+ const changedAssets = assets.map(e => [e.asset, e.isDeposit]);
913
923
 
914
924
  if (estimateGas) {
915
925
  return await this.managerLogic.estimateGas.changeAssets(
@@ -1066,7 +1076,7 @@ export class Pool {
1066
1076
  [
1067
1077
  stakingAddress[this.network][Dapp.AAVEV3] as string,
1068
1078
  claimTxData,
1069
- options,
1079
+ options
1070
1080
  ],
1071
1081
  estimateGas
1072
1082
  );
@@ -1091,7 +1101,7 @@ export class Pool {
1091
1101
  [
1092
1102
  stakingAddress[this.network][Dapp.COMPOUNDV3] as string,
1093
1103
  claimTxData,
1094
- options,
1104
+ options
1095
1105
  ],
1096
1106
  estimateGas
1097
1107
  );
@@ -1120,8 +1130,7 @@ export class Pool {
1120
1130
  | Dapp.VELODROMECL
1121
1131
  | Dapp.AERODROMECL
1122
1132
  | Dapp.RAMSESCL
1123
- | Dapp.PANCAKECL
1124
- | Dapp.SHADOWCL,
1133
+ | Dapp.PANCAKECL,
1125
1134
  assetA: string,
1126
1135
  assetB: string,
1127
1136
  amountA: BigNumber | string,
@@ -1161,7 +1170,7 @@ export class Pool {
1161
1170
  [
1162
1171
  nonfungiblePositionManagerAddress[this.network][dapp],
1163
1172
  mintTxData,
1164
- options,
1173
+ options
1165
1174
  ],
1166
1175
  estimateGas
1167
1176
  );
@@ -1190,7 +1199,6 @@ export class Pool {
1190
1199
  switch (dapp) {
1191
1200
  case Dapp.UNISWAPV3:
1192
1201
  case Dapp.RAMSESCL:
1193
- case Dapp.SHADOWCL:
1194
1202
  dappAddress = nonfungiblePositionManagerAddress[this.network][dapp];
1195
1203
  break;
1196
1204
  case Dapp.VELODROMECL:
@@ -1256,7 +1264,6 @@ export class Pool {
1256
1264
  switch (dapp) {
1257
1265
  case Dapp.UNISWAPV3:
1258
1266
  case Dapp.RAMSESCL:
1259
- case Dapp.SHADOWCL:
1260
1267
  dappAddress = nonfungiblePositionManagerAddress[this.network][dapp];
1261
1268
  break;
1262
1269
  case Dapp.VELODROMECL:
@@ -1321,7 +1328,6 @@ export class Pool {
1321
1328
  switch (dapp) {
1322
1329
  case Dapp.UNISWAPV3:
1323
1330
  case Dapp.RAMSESCL:
1324
- case Dapp.SHADOWCL:
1325
1331
  contractAddress = nonfungiblePositionManagerAddress[this.network][dapp];
1326
1332
  txData = iNonfungiblePositionManager.encodeFunctionData(
1327
1333
  Transaction.COLLECT,
@@ -1392,13 +1398,13 @@ export class Pool {
1392
1398
  options: any = null,
1393
1399
  estimateGas = false
1394
1400
  ): Promise<any> {
1395
- const claimAddress =
1396
- dapp === Dapp.SHADOWCL
1397
- ? stakingAddress[this.network][dapp] //specific for wS/USDC CL
1398
- : nonfungiblePositionManagerAddress[this.network][dapp];
1399
1401
  const tx = await getPoolTxOrGasEstimate(
1400
1402
  this,
1401
- [claimAddress, getRewardsTxDta(tokenId, rewards), options],
1403
+ [
1404
+ nonfungiblePositionManagerAddress[this.network][dapp],
1405
+ getRewardsTxDta(tokenId, rewards),
1406
+ options
1407
+ ],
1402
1408
  estimateGas
1403
1409
  );
1404
1410
  return tx;
@@ -1473,7 +1479,7 @@ export class Pool {
1473
1479
  amountB,
1474
1480
  isStable
1475
1481
  ),
1476
- options,
1482
+ options
1477
1483
  ],
1478
1484
  estimateGas
1479
1485
  );
@@ -1509,7 +1515,7 @@ export class Pool {
1509
1515
  amount,
1510
1516
  isStable
1511
1517
  ),
1512
- options,
1518
+ options
1513
1519
  ],
1514
1520
  estimateGas
1515
1521
  );
@@ -1548,7 +1554,7 @@ export class Pool {
1548
1554
  amountB,
1549
1555
  isStable
1550
1556
  ),
1551
- options,
1557
+ options
1552
1558
  ],
1553
1559
  estimateGas
1554
1560
  );
@@ -1584,7 +1590,7 @@ export class Pool {
1584
1590
  amount,
1585
1591
  isStable
1586
1592
  ),
1587
- options,
1593
+ options
1588
1594
  ],
1589
1595
  estimateGas
1590
1596
  );
@@ -1625,7 +1631,7 @@ export class Pool {
1625
1631
  amountB,
1626
1632
  isStable
1627
1633
  ),
1628
- options,
1634
+ options
1629
1635
  ],
1630
1636
  estimateGas
1631
1637
  );
@@ -1663,7 +1669,7 @@ export class Pool {
1663
1669
  amount,
1664
1670
  isStable
1665
1671
  ),
1666
- options,
1672
+ options
1667
1673
  ],
1668
1674
  estimateGas
1669
1675
  );
@@ -1,20 +1,59 @@
1
- import { ethers } from "../..";
1
+ import { ethers, Pool } from "../..";
2
2
  import ICompoundV3Comet from "../../abi/compound/ICompoundV3Comet.json";
3
+ import IFToken from "../../abi/fluid/IFToken.json";
3
4
 
4
- export function getCompoundV3LendTxData(
5
+ export async function getCompoundV3LendTxData(
6
+ pool: Pool,
7
+ market: string,
5
8
  asset: string,
6
9
  amount: ethers.BigNumber | string
7
- ): string {
8
- return new ethers.utils.Interface(
9
- ICompoundV3Comet
10
- ).encodeFunctionData("supply", [asset, amount]);
10
+ ): Promise<string> {
11
+ if (await isCompoundV3Market(pool, market)) {
12
+ return new ethers.utils.Interface(
13
+ ICompoundV3Comet
14
+ ).encodeFunctionData("supply", [asset, amount]);
15
+ } else {
16
+ //Fluid lending
17
+ return new ethers.utils.Interface(IFToken).encodeFunctionData("deposit", [
18
+ amount,
19
+ pool.address
20
+ ]);
21
+ }
11
22
  }
12
23
 
13
- export function getCompoundV3WithdrawTxData(
24
+ export async function getCompoundV3WithdrawTxData(
25
+ pool: Pool,
26
+ market: string,
14
27
  asset: string,
15
28
  amount: ethers.BigNumber | string
16
- ): string {
17
- return new ethers.utils.Interface(
18
- ICompoundV3Comet
19
- ).encodeFunctionData("withdraw", [asset, amount]);
29
+ ): Promise<string> {
30
+ if (await isCompoundV3Market(pool, market)) {
31
+ return new ethers.utils.Interface(
32
+ ICompoundV3Comet
33
+ ).encodeFunctionData("withdraw", [asset, amount]);
34
+ } else {
35
+ //Fluid withdrawal
36
+ return new ethers.utils.Interface(IFToken).encodeFunctionData("redeem", [
37
+ amount,
38
+ pool.address,
39
+ pool.address
40
+ ]);
41
+ }
42
+ }
43
+
44
+ export async function isCompoundV3Market(
45
+ pool: Pool,
46
+ market: string
47
+ ): Promise<boolean> {
48
+ const marketContract = new ethers.Contract(
49
+ market,
50
+ ICompoundV3Comet,
51
+ pool.signer
52
+ );
53
+ try {
54
+ await marketContract.baseToken();
55
+ return true;
56
+ } catch (error) {
57
+ return false;
58
+ }
20
59
  }