@dhedge/v2-sdk 2.1.8 → 2.2.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.
Files changed (95) hide show
  1. package/README.md +404 -54
  2. package/dist/config.d.ts +13 -2
  3. package/dist/entities/pool.d.ts +25 -86
  4. package/dist/entities/utils.d.ts +15 -0
  5. package/dist/services/hyperliquid/index.d.ts +22 -0
  6. package/dist/services/kyberSwap/index.d.ts +1 -1
  7. package/dist/services/ondo/index.d.ts +5 -0
  8. package/dist/services/oneInch/index.d.ts +1 -1
  9. package/dist/services/toros/easySwapper.d.ts +14 -0
  10. package/dist/services/toros/swapData.d.ts +5 -5
  11. package/dist/services/uniswap/V3Liquidity.d.ts +2 -2
  12. package/dist/services/velodrome/liquidity.d.ts +3 -0
  13. package/dist/test/constants.d.ts +48 -3
  14. package/dist/test/utils/testingHelper.d.ts +4 -0
  15. package/dist/types.d.ts +21 -5
  16. package/dist/utils/contract.d.ts +20 -0
  17. package/dist/v2-sdk.cjs.development.js +5133 -6641
  18. package/dist/v2-sdk.cjs.development.js.map +1 -1
  19. package/dist/v2-sdk.cjs.production.min.js +1 -1
  20. package/dist/v2-sdk.cjs.production.min.js.map +1 -1
  21. package/dist/v2-sdk.esm.js +5138 -6641
  22. package/dist/v2-sdk.esm.js.map +1 -1
  23. package/package.json +1 -1
  24. package/src/abi/PoolFactory.json +414 -204
  25. package/src/abi/PoolLogic.json +160 -134
  26. package/src/abi/ondo/IOndoGMSwap.json +30 -0
  27. package/src/config.ts +15 -9
  28. package/src/entities/pool.ts +56 -253
  29. package/src/entities/utils.ts +15 -0
  30. package/src/services/hyperliquid/index.ts +22 -0
  31. package/src/services/kyberSwap/index.ts +5 -3
  32. package/src/services/ondo/index.ts +142 -0
  33. package/src/services/oneInch/index.ts +5 -4
  34. package/src/services/toros/completeWithdrawal.ts +57 -40
  35. package/src/services/toros/easySwapper.ts +15 -1
  36. package/src/services/toros/initWithdrawal.ts +39 -31
  37. package/src/services/toros/swapData.ts +45 -131
  38. package/src/services/uniswap/V3Liquidity.ts +3 -24
  39. package/src/services/velodrome/liquidity.ts +3 -0
  40. package/src/test/aave.test.ts +99 -70
  41. package/src/test/aerodrome.test.ts +53 -24
  42. package/src/test/aerodromeCL.test.ts +64 -30
  43. package/src/test/arrakis.test.ts +23 -35
  44. package/src/test/balancer.test.ts +114 -106
  45. package/src/test/compoundV3.test.ts +45 -29
  46. package/src/test/constants.ts +56 -11
  47. package/src/test/cowswap.test.ts +33 -35
  48. package/src/test/dhedge.test.ts +45 -12
  49. package/src/test/flatmoney.test.ts +25 -39
  50. package/src/test/fluid.test.ts +33 -24
  51. package/src/test/hyperliquid.onchain.test.ts +131 -0
  52. package/src/test/kyberSwap.test.ts +37 -16
  53. package/src/test/lyra.test.ts +159 -150
  54. package/src/test/odos.test.ts +2 -2
  55. package/src/test/ondo.onchain.test.ts +132 -0
  56. package/src/test/oneInch.test.ts +36 -22
  57. package/src/test/pancakeCL.test.ts +72 -31
  58. package/src/test/pendle.test.ts +94 -54
  59. package/src/test/{pendleMint.test.ts → pendleMint.onchain.test.ts} +22 -8
  60. package/src/test/pool.test.ts +152 -95
  61. package/src/test/toros.onchain.test.ts +92 -0
  62. package/src/test/toros.test.ts +74 -20
  63. package/src/test/torosLimitOrder.test.ts +87 -42
  64. package/src/test/uniswap.test.ts +77 -128
  65. package/src/test/utils/testingHelper.ts +120 -0
  66. package/src/test/velodrome.test.ts +126 -92
  67. package/src/test/velodromeCL.test.ts +43 -31
  68. package/src/test/velodromeV2.test.ts +153 -95
  69. package/src/types.ts +22 -6
  70. package/src/utils/contract.ts +20 -0
  71. package/dist/services/futures/constants.d.ts +0 -1
  72. package/dist/services/futures/index.d.ts +0 -2
  73. package/dist/services/futures/margin.d.ts +0 -2
  74. package/dist/services/futures/trade.d.ts +0 -3
  75. package/dist/services/ramses/vesting.d.ts +0 -4
  76. package/dist/services/uniswap/V3Trade.d.ts +0 -3
  77. package/dist/test/utils/futures.d.ts +0 -2
  78. package/src/abi/IRamsesNonfungiblePositionManager.json +0 -486
  79. package/src/abi/ISynthetiXFuturesMarketV2.json +0 -531
  80. package/src/abi/ISynthetix.json +0 -139
  81. package/src/abi/IUniswapV3Quoter.json +0 -195
  82. package/src/abi/IUniswapV3Router.json +0 -221
  83. package/src/abi/IXRam.json +0 -99
  84. package/src/services/futures/constants.ts +0 -1
  85. package/src/services/futures/index.ts +0 -2
  86. package/src/services/futures/margin.ts +0 -10
  87. package/src/services/futures/trade.ts +0 -32
  88. package/src/services/ramses/vesting.ts +0 -24
  89. package/src/services/uniswap/V3Trade.ts +0 -46
  90. package/src/test/futures.test.ts +0 -51
  91. package/src/test/hyperliquid.test.ts +0 -107
  92. package/src/test/ramses.test.ts +0 -190
  93. package/src/test/ramsesCL.test.ts +0 -155
  94. package/src/test/synthetix.test.ts +0 -36
  95. package/src/test/utils/futures.ts +0 -14
@@ -19,7 +19,7 @@ import {
19
19
  } from "../../config";
20
20
  import INonfungiblePositionManager from "../../abi/INonfungiblePositionManager.json";
21
21
  import IVeldodromePositionManager from "../../abi/IVelodromeNonfungiblePositionManager.json";
22
- import IRamsesPositionManager from "../../abi/IRamsesNonfungiblePositionManager.json";
22
+
23
23
  import IArrakisV1RouterStaking from "../../abi/IArrakisV1RouterStaking.json";
24
24
  import IPancakeMasterChef from "../../abi/IPancakeMasterChefV3.json";
25
25
  import { getDeadline } from "../../utils/deadline";
@@ -72,12 +72,7 @@ export function tryParseTick(
72
72
  }
73
73
 
74
74
  export async function getUniswapV3MintTxData(
75
- dapp:
76
- | Dapp.UNISWAPV3
77
- | Dapp.VELODROMECL
78
- | Dapp.AERODROMECL
79
- | Dapp.RAMSESCL
80
- | Dapp.PANCAKECL,
75
+ dapp: Dapp.UNISWAPV3 | Dapp.VELODROMECL | Dapp.AERODROMECL | Dapp.PANCAKECL,
81
76
 
82
77
  pool: Pool,
83
78
  assetA: string,
@@ -162,27 +157,13 @@ export async function getUniswapV3MintTxData(
162
157
  mintParams.push(0);
163
158
  }
164
159
 
165
- if (dapp === Dapp.RAMSESCL) {
166
- iNonfungiblePositionManager = new ethers.utils.Interface(
167
- IRamsesPositionManager
168
- );
169
- mintParams.push(0);
170
- }
171
-
172
160
  return iNonfungiblePositionManager.encodeFunctionData(Transaction.MINT, [
173
161
  mintParams
174
162
  ]);
175
-
176
- return;
177
163
  }
178
164
 
179
165
  export async function getUniswapV3Liquidity(
180
- dapp:
181
- | Dapp.UNISWAPV3
182
- | Dapp.VELODROMECL
183
- | Dapp.AERODROMECL
184
- | Dapp.RAMSESCL
185
- | Dapp,
166
+ dapp: Dapp,
186
167
  tokenId: string,
187
168
  pool: Pool
188
169
  ): Promise<BigNumber> {
@@ -208,7 +189,6 @@ export async function getIncreaseLiquidityTxData(
208
189
  dapp === Dapp.UNISWAPV3 ||
209
190
  dapp === Dapp.VELODROMECL ||
210
191
  dapp === Dapp.AERODROMECL ||
211
- dapp === Dapp.RAMSESCL ||
212
192
  dapp === Dapp.PANCAKECL
213
193
  ) {
214
194
  const abi = new ethers.utils.Interface(INonfungiblePositionManager.abi);
@@ -245,7 +225,6 @@ export async function getDecreaseLiquidityTxData(
245
225
  dapp === Dapp.UNISWAPV3 ||
246
226
  dapp === Dapp.VELODROMECL ||
247
227
  dapp === Dapp.AERODROMECL ||
248
- dapp === Dapp.RAMSESCL ||
249
228
  dapp === Dapp.PANCAKECL
250
229
  ) {
251
230
  const abi = new ethers.utils.Interface(INonfungiblePositionManager.abi);
@@ -7,6 +7,7 @@ import { getDeadline } from "../../utils/deadline";
7
7
  import { nonfungiblePositionManagerAddress } from "../../config";
8
8
  import INonfungiblePositionManager from "../../abi/INonfungiblePositionManager.json";
9
9
 
10
+ /** Encode Velodrome router calldata to add liquidity to a stable or volatile pair. */
10
11
  export async function getVelodromeAddLiquidityTxData(
11
12
  pool: Pool,
12
13
  assetA: string,
@@ -29,6 +30,7 @@ export async function getVelodromeAddLiquidityTxData(
29
30
  ]);
30
31
  }
31
32
 
33
+ /** Encode Velodrome router calldata to remove liquidity from a stable or volatile pair. */
32
34
  export async function getVelodromeRemoveLiquidityTxData(
33
35
  pool: Pool,
34
36
  assetA: string,
@@ -49,6 +51,7 @@ export async function getVelodromeRemoveLiquidityTxData(
49
51
  ]);
50
52
  }
51
53
 
54
+ /** Read the current owner of a Velodrome/Aerodrome/Pancake CL position NFT. */
52
55
  export async function getClOwner(
53
56
  pool: Pool,
54
57
  dapp: Dapp.VELODROMECL | Dapp.AERODROMECL | Dapp.PANCAKECL,
@@ -1,87 +1,116 @@
1
1
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
+ import BigNumber from "bignumber.js";
2
3
  import { Dhedge, Pool } from "..";
3
4
  import { routerAddress } from "../config";
4
5
  import { Dapp, Network } from "../types";
5
- import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
6
+ import { CONTRACT_ADDRESS, MAX_AMOUNT } from "./constants";
7
+ import {
8
+ TestingRunParams,
9
+ fixOracleAggregatorStaleness,
10
+ setChainlinkTimeout,
11
+ setUSDCAmount,
12
+ testingHelper
13
+ } from "./utils/testingHelper";
6
14
  import { allowanceDelta, balanceDelta } from "./utils/token";
7
15
 
8
- import { wallet } from "./wallet";
16
+ const testAave = ({ wallet, network, provider }: TestingRunParams) => {
17
+ const USDC = CONTRACT_ADDRESS[network].USDC;
18
+ const WBTC = CONTRACT_ADDRESS[network].WBTC;
9
19
 
10
- // const network = Network.OPTIMISM;
11
- // const network = Network.POLYGON;
12
- const network = Network.ARBITRUM;
13
- const USDC = CONTRACT_ADDRESS[network].USDC;
14
- const WETH = CONTRACT_ADDRESS[network].WETH;
20
+ let dhedge: Dhedge;
21
+ let pool: Pool;
22
+ jest.setTimeout(100000);
15
23
 
16
- let dhedge: Dhedge;
17
- let pool: Pool;
18
- jest.setTimeout(100000);
24
+ describe(`[${network}] aave v3 tests`, () => {
25
+ beforeAll(async () => {
26
+ await provider.send("hardhat_setBalance", [
27
+ wallet.address,
28
+ "0x10000000000000000"
29
+ ]);
30
+ dhedge = new Dhedge(wallet, network);
19
31
 
20
- describe("pool", () => {
21
- beforeAll(async () => {
22
- dhedge = new Dhedge(wallet, network);
23
- pool = await dhedge.loadPool(TEST_POOL[network]);
24
- });
32
+ pool = await dhedge.createPool("Test Manager", "Aave Test", "AT", [
33
+ [USDC, true],
34
+ [WBTC, false],
35
+ [routerAddress[network][Dapp.AAVEV3]!, false]
36
+ ]);
25
37
 
26
- it("approves unlimited USDC on Aave Lending pool", async () => {
27
- await pool.approve(Dapp.AAVEV3, USDC, MAX_AMOUNT);
28
- const usdcAllowanceDelta = await allowanceDelta(
29
- pool.address,
30
- USDC,
31
- routerAddress[network]["aavev3"]!,
32
- pool.signer
33
- );
34
- await expect(usdcAllowanceDelta.gt(0));
35
- });
38
+ await setChainlinkTimeout({ pool, provider }, 86400 * 365);
39
+ await fixOracleAggregatorStaleness({ pool, provider });
36
40
 
37
- it("approves unlimited WETH on Aave Lending pool", async () => {
38
- await pool.approve(Dapp.AAVEV3, WETH, MAX_AMOUNT);
39
- const wethAllowanceDelta = await allowanceDelta(
40
- pool.address,
41
- USDC,
42
- routerAddress[network]["aavev3"]!,
43
- pool.signer
44
- );
45
- await expect(wethAllowanceDelta.gt(0));
46
- });
41
+ await setUSDCAmount({
42
+ amount: new BigNumber(1000).times(1e6).toFixed(0),
43
+ userAddress: pool.address,
44
+ network,
45
+ provider
46
+ });
47
+ });
47
48
 
48
- it("lends 5 USDC into Aave lending pool", async () => {
49
- await pool.lend(Dapp.AAVEV3, USDC, "5000000");
50
- const usdcBalanceDelta = await balanceDelta(
51
- pool.address,
52
- USDC,
53
- pool.signer
54
- );
55
- expect(usdcBalanceDelta.eq("-5000000"));
56
- });
49
+ it("approves unlimited USDC on Aave Lending pool", async () => {
50
+ await pool.approve(Dapp.AAVEV3, USDC, MAX_AMOUNT);
51
+ const usdcAllowanceDelta = await allowanceDelta(
52
+ pool.address,
53
+ USDC,
54
+ routerAddress[network][Dapp.AAVEV3]!,
55
+ pool.signer
56
+ );
57
+ expect(usdcAllowanceDelta.gt(0)).toBe(true);
58
+ });
57
59
 
58
- it("it borrows 0.001 WETH from Aave lending pool", async () => {
59
- await pool.borrow(Dapp.AAVEV3, WETH, "1000000000000000");
60
- const wethBalanceDelta = await balanceDelta(
61
- pool.address,
62
- WETH,
63
- pool.signer
64
- );
65
- expect(wethBalanceDelta.eq("1000000000000000"));
66
- });
60
+ it("approves unlimited WBTC on Aave Lending pool", async () => {
61
+ await pool.approve(Dapp.AAVEV3, WBTC, MAX_AMOUNT);
62
+ const wbtcAllowanceDelta = await allowanceDelta(
63
+ pool.address,
64
+ WBTC,
65
+ routerAddress[network][Dapp.AAVEV3]!,
66
+ pool.signer
67
+ );
68
+ expect(wbtcAllowanceDelta.gt(0)).toBe(true);
69
+ });
67
70
 
68
- it("it repays 0.001 WETH to Aave lending pool", async () => {
69
- await pool.repay(Dapp.AAVEV3, WETH, "1000000000000000");
70
- const wethBalanceDelta = await balanceDelta(
71
- pool.address,
72
- WETH,
73
- pool.signer
74
- );
75
- expect(wethBalanceDelta.eq("-1000000000000000"));
76
- });
71
+ it("lends 500 USDC into Aave lending pool", async () => {
72
+ await pool.lend(Dapp.AAVEV3, USDC, "500000000");
73
+ const usdcBalanceDelta = await balanceDelta(
74
+ pool.address,
75
+ USDC,
76
+ pool.signer
77
+ );
78
+ expect(usdcBalanceDelta.eq("-500000000")).toBe(true);
79
+ });
80
+
81
+ it("borrows 0.0001 WBTC from Aave lending pool", async () => {
82
+ await pool.borrow(Dapp.AAVEV3, WBTC, "10000");
83
+ const wbtcBalanceDelta = await balanceDelta(
84
+ pool.address,
85
+ WBTC,
86
+ pool.signer
87
+ );
88
+ expect(wbtcBalanceDelta.eq("10000")).toBe(true);
89
+ });
77
90
 
78
- it("it withdraws 4 USDC from Aave lending pool", async () => {
79
- await pool.withdrawDeposit(Dapp.AAVEV3, USDC, "4000000");
80
- const usdcBalanceDelta = await balanceDelta(
81
- pool.address,
82
- WETH,
83
- pool.signer
84
- );
85
- expect(usdcBalanceDelta.eq("4000000"));
91
+ it("repays 0.0001 WBTC to Aave lending pool", async () => {
92
+ await pool.repay(Dapp.AAVEV3, WBTC, "10000");
93
+ const wbtcBalanceDelta = await balanceDelta(
94
+ pool.address,
95
+ WBTC,
96
+ pool.signer
97
+ );
98
+ expect(wbtcBalanceDelta.eq("-10000")).toBe(true);
99
+ });
100
+
101
+ it("withdraws 400 USDC from Aave lending pool", async () => {
102
+ await pool.withdrawDeposit(Dapp.AAVEV3, USDC, "400000000");
103
+ const usdcBalanceDelta = await balanceDelta(
104
+ pool.address,
105
+ USDC,
106
+ pool.signer
107
+ );
108
+ expect(usdcBalanceDelta.eq("400000000")).toBe(true);
109
+ });
86
110
  });
111
+ };
112
+
113
+ testingHelper({
114
+ network: Network.ARBITRUM,
115
+ testingRun: testAave
87
116
  });
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
3
3
  import BigNumber from "bignumber.js";
4
- import { Dhedge, Pool } from "..";
4
+ import { Dhedge, ethers, Pool } from "..";
5
5
  import { routerAddress } from "../config";
6
6
  import { Dapp, Network } from "../types";
7
7
  import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
@@ -9,12 +9,13 @@ import {
9
9
  TestingRunParams,
10
10
  beforeAfterReset,
11
11
  setUSDCAmount,
12
+ setWETHAmount,
13
+ runWithImpersonateAccount,
12
14
  testingHelper
13
15
  } from "./utils/testingHelper";
14
16
  import { allowanceDelta, balanceDelta } from "./utils/token";
15
- import { getWalletData } from "./wallet";
16
17
 
17
- const testAerodrome = ({ network, provider }: TestingRunParams) => {
18
+ const testAerodrome = ({ wallet, network, provider }: TestingRunParams) => {
18
19
  const WETH_USDC_Lp = "0xcDAC0d6c6C59727a65F871236188350531885C43";
19
20
  const WETH_USDC__Gauge = "0x519BBD1Dd8C6A94C46080E24f316c14Ee758C025";
20
21
 
@@ -28,38 +29,66 @@ const testAerodrome = ({ network, provider }: TestingRunParams) => {
28
29
 
29
30
  describe(`[${network}] aerodrome tests`, () => {
30
31
  beforeAll(async () => {
31
- const { wallet } = getWalletData(network);
32
32
  // top up ETH (gas)
33
33
  await provider.send("hardhat_setBalance", [
34
34
  wallet.address,
35
- "0x100000000000000"
35
+ "0x10000000000000000"
36
36
  ]);
37
37
  dhedge = new Dhedge(wallet, network);
38
38
  pool = await dhedge.loadPool(TEST_POOL[network]);
39
+
40
+ // Fund pool with USDC and WETH
39
41
  await setUSDCAmount({
40
- amount: new BigNumber(10).times(1e6).toFixed(0),
42
+ amount: new BigNumber(10000).times(1e6).toFixed(0),
43
+ userAddress: pool.address,
44
+ network,
45
+ provider
46
+ });
47
+ await setWETHAmount({
48
+ amount: new BigNumber(5).times(1e18).toFixed(0),
41
49
  userAddress: pool.address,
42
50
  network,
43
51
  provider
44
52
  });
45
- await pool.approve(Dapp.ONEINCH, USDC, MAX_AMOUNT);
46
- await pool.trade(Dapp.ONEINCH, USDC, WETH, (5 * 1e6).toString());
53
+
54
+ // Impersonate the pool manager to set trader and configure assets
55
+ await runWithImpersonateAccount(
56
+ { provider, account: await pool.managerLogic.manager() },
57
+ async ({ signer }) => {
58
+ await pool.managerLogic.connect(signer).setTrader(wallet.address);
59
+ const newAssets = [
60
+ [USDC, true],
61
+ [WETH, true],
62
+ [WETH_USDC_Lp, false],
63
+ [AERO, false]
64
+ ];
65
+ await pool.managerLogic.connect(signer).changeAssets(newAssets, []);
66
+ }
67
+ );
47
68
  });
48
69
  beforeAfterReset({ beforeAll, afterAll, provider });
49
70
 
50
- it("approves unlimited USDC and swETH on for Aerodrome", async () => {
71
+ it("approves unlimited USDC and WETH for Aerodrome", async () => {
51
72
  await pool.approve(Dapp.AERODROME, USDC, MAX_AMOUNT);
52
73
  await pool.approve(Dapp.AERODROME, WETH, MAX_AMOUNT);
53
- const UsdcAllowanceDelta = await allowanceDelta(
54
- pool.address,
74
+ const allowanceAbi = [
75
+ "function allowance(address,address) view returns (uint256)"
76
+ ];
77
+ const usdcAllowance = await new ethers.Contract(
55
78
  USDC,
56
- routerAddress[network].aerodrome!,
79
+ allowanceAbi,
57
80
  pool.signer
58
- );
59
- await expect(UsdcAllowanceDelta.gt(0));
81
+ ).allowance(pool.address, routerAddress[network].aerodrome!);
82
+ const wethAllowance = await new ethers.Contract(
83
+ WETH,
84
+ allowanceAbi,
85
+ pool.signer
86
+ ).allowance(pool.address, routerAddress[network].aerodrome!);
87
+ expect(usdcAllowance.gt(0)).toBe(true);
88
+ expect(wethAllowance.gt(0)).toBe(true);
60
89
  });
61
90
 
62
- it("adds USDC and WETH to a Aerodrome volatile pool", async () => {
91
+ it("adds USDC and WETH to an Aerodrome volatile pool", async () => {
63
92
  const usdcBalance = await pool.utils.getBalance(USDC, pool.address);
64
93
  const wethBalance = await pool.utils.getBalance(WETH, pool.address);
65
94
  await pool.addLiquidityV2(
@@ -76,7 +105,7 @@ const testAerodrome = ({ network, provider }: TestingRunParams) => {
76
105
  WETH_USDC_Lp,
77
106
  pool.signer
78
107
  );
79
- expect(lpTokenDelta.gt(0));
108
+ expect(lpTokenDelta.gt(0)).toBe(true);
80
109
  });
81
110
 
82
111
  it("should stake WETH-USDC LP in a gauge", async () => {
@@ -88,7 +117,7 @@ const testAerodrome = ({ network, provider }: TestingRunParams) => {
88
117
  WETH_USDC__Gauge,
89
118
  pool.signer
90
119
  );
91
- expect(gaugeBalance.gt(0));
120
+ expect(gaugeBalance.gt(0)).toBe(true);
92
121
  });
93
122
 
94
123
  it("should claim rewards from Gauge", async () => {
@@ -101,10 +130,10 @@ const testAerodrome = ({ network, provider }: TestingRunParams) => {
101
130
  AERO,
102
131
  pool.signer
103
132
  );
104
- expect(aeroBalanceDelta.gt(0));
133
+ expect(aeroBalanceDelta.gt(0)).toBe(true);
105
134
  });
106
135
 
107
- it("should unStakeWETH-USDC LP from a gauge", async () => {
136
+ it("should unstake WETH-USDC LP from a gauge", async () => {
108
137
  const gaugeBalance = await dhedge.utils.getBalance(
109
138
  WETH_USDC__Gauge,
110
139
  pool.address
@@ -115,7 +144,7 @@ const testAerodrome = ({ network, provider }: TestingRunParams) => {
115
144
  WETH_USDC_Lp,
116
145
  pool.signer
117
146
  );
118
- expect(lpTokenDelta.gt(0));
147
+ expect(lpTokenDelta.gt(0)).toBe(true);
119
148
  });
120
149
 
121
150
  it("approves unlimited WETH-USDC LP for Aerodrome", async () => {
@@ -126,10 +155,10 @@ const testAerodrome = ({ network, provider }: TestingRunParams) => {
126
155
  routerAddress[network].aerodrome!,
127
156
  pool.signer
128
157
  );
129
- expect(lpAllowanceDelta.gt(0));
158
+ expect(lpAllowanceDelta.gt(0)).toBe(true);
130
159
  });
131
160
 
132
- it("should remove all liquidity from an existing pool ", async () => {
161
+ it("should remove all liquidity from an existing pool", async () => {
133
162
  const balance = await dhedge.utils.getBalance(WETH_USDC_Lp, pool.address);
134
163
  await pool.removeLiquidityV2(Dapp.AERODROME, WETH, USDC, balance, false);
135
164
  const usdcBalanceDelta = await balanceDelta(
@@ -142,8 +171,8 @@ const testAerodrome = ({ network, provider }: TestingRunParams) => {
142
171
  WETH,
143
172
  pool.signer
144
173
  );
145
- expect(usdcBalanceDelta.gt(0));
146
- expect(wethBalanceDelta.gt(0));
174
+ expect(usdcBalanceDelta.gt(0)).toBe(true);
175
+ expect(wethBalanceDelta.gt(0)).toBe(true);
147
176
  });
148
177
  });
149
178
  };
@@ -1,19 +1,28 @@
1
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
+ import BigNumber from "bignumber.js";
1
3
  import { Dhedge, Pool, ethers } from "..";
2
4
 
3
5
  import { nonfungiblePositionManagerAddress } from "../config";
4
- import { AssetEnabled, Dapp, Network } from "../types";
5
- import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
6
+ import { Dapp, Network } from "../types";
7
+ import {
8
+ CONTRACT_ADDRESS,
9
+ MAX_AMOUNT,
10
+ TEST_POOL,
11
+ USDC_BALANCEOF_SLOT
12
+ } from "./constants";
6
13
  import {
7
14
  TestingRunParams,
8
15
  beforeAfterReset,
16
+ fixOracleAggregatorStaleness,
17
+ runWithImpersonateAccount,
9
18
  setChainlinkTimeout,
19
+ setTokenAmount,
10
20
  testingHelper
11
21
  } from "./utils/testingHelper";
12
- import { allowanceDelta, balanceDelta } from "./utils/token";
22
+ import { balanceDelta } from "./utils/token";
13
23
  import INonfungiblePositionManager from "../abi/INonfungiblePositionManager.json";
14
24
 
15
25
  const testAerodromeCL = ({ wallet, network, provider }: TestingRunParams) => {
16
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
17
26
  const AERODROME_POSITION_MANGER = nonfungiblePositionManagerAddress[network][
18
27
  Dapp.AERODROMECL
19
28
  ]!;
@@ -31,30 +40,46 @@ const testAerodromeCL = ({ wallet, network, provider }: TestingRunParams) => {
31
40
 
32
41
  describe(`[${network}] Aerodrome CL tests`, () => {
33
42
  beforeAll(async () => {
34
- // top up ETH (gas)
35
43
  await provider.send("hardhat_setBalance", [
36
44
  wallet.address,
37
- "0x100000000000000"
45
+ "0x10000000000000000"
38
46
  ]);
39
47
  dhedge = new Dhedge(wallet, network);
40
48
  pool = await dhedge.loadPool(TEST_POOL[network]);
41
49
 
42
- // setChainlinkTimeout
43
50
  await setChainlinkTimeout({ pool, provider }, 86400 * 365);
44
-
45
- const newAssets: AssetEnabled[] = [
46
- { asset: USDC, isDeposit: true },
47
- { asset: USDT, isDeposit: true },
48
- {
49
- asset: AERODROME_POSITION_MANGER,
50
- isDeposit: false
51
- },
52
- {
53
- asset: AERO,
54
- isDeposit: false
51
+ await fixOracleAggregatorStaleness({ pool, provider });
52
+
53
+ await runWithImpersonateAccount(
54
+ { provider, account: await pool.managerLogic.manager() },
55
+ async ({ signer }) => {
56
+ await pool.managerLogic.connect(signer).setTrader(wallet.address);
57
+ await pool.managerLogic.connect(signer).changeAssets(
58
+ [
59
+ [USDC, true],
60
+ [USDT, true],
61
+ [AERODROME_POSITION_MANGER, false],
62
+ [AERO, false]
63
+ ],
64
+ []
65
+ );
55
66
  }
56
- ];
57
- await pool.managerLogic.changeAssets(newAssets, []);
67
+ );
68
+
69
+ await setTokenAmount({
70
+ amount: new BigNumber(1000).times(1e6).toFixed(0),
71
+ userAddress: pool.address,
72
+ tokenAddress: USDC,
73
+ slot: USDC_BALANCEOF_SLOT[network],
74
+ provider
75
+ });
76
+ await setTokenAmount({
77
+ amount: new BigNumber(1000).times(1e6).toFixed(0),
78
+ userAddress: pool.address,
79
+ tokenAddress: USDT,
80
+ slot: 0,
81
+ provider
82
+ });
58
83
 
59
84
  velodromePositionManager = new ethers.Contract(
60
85
  AERODROME_POSITION_MANGER,
@@ -69,16 +94,19 @@ const testAerodromeCL = ({ wallet, network, provider }: TestingRunParams) => {
69
94
  it("approves unlimited USDC and USDT on for Aerodrome CL", async () => {
70
95
  await pool.approveSpender(AERODROME_POSITION_MANGER, USDC, MAX_AMOUNT);
71
96
  await pool.approveSpender(AERODROME_POSITION_MANGER, USDT, MAX_AMOUNT);
72
- const UsdcAllowanceDelta = await allowanceDelta(
73
- pool.address,
97
+ const iERC20 = new ethers.Contract(
74
98
  USDC,
75
- AERODROME_POSITION_MANGER,
99
+ ["function allowance(address,address) view returns (uint256)"],
76
100
  pool.signer
77
101
  );
78
- await expect(UsdcAllowanceDelta.gt(0));
102
+ const usdcAllowance = await iERC20.allowance(
103
+ pool.address,
104
+ AERODROME_POSITION_MANGER
105
+ );
106
+ expect(usdcAllowance.gt(0)).toBe(true);
79
107
  });
80
108
 
81
- it("adds USDC and WETH to a CL (mint position)", async () => {
109
+ it("adds USDC and USDT to a CL (mint position)", async () => {
82
110
  const usdcBalance = await pool.utils.getBalance(USDC, pool.address);
83
111
  const usdtBalance = await pool.utils.getBalance(USDT, pool.address);
84
112
  await pool.addLiquidityUniswapV3(
@@ -113,7 +141,7 @@ const testAerodromeCL = ({ wallet, network, provider }: TestingRunParams) => {
113
141
  usdtBalance.div(2)
114
142
  );
115
143
  const positionAfter = await velodromePositionManager.positions(tokenId);
116
- expect(positionAfter.liquidity.gt(positionBefore.liquidity));
144
+ expect(positionAfter.liquidity.gt(positionBefore.liquidity)).toBe(true);
117
145
  });
118
146
 
119
147
  it("decreases liquidity from a CL position", async () => {
@@ -122,14 +150,17 @@ const testAerodromeCL = ({ wallet, network, provider }: TestingRunParams) => {
122
150
  );
123
151
  await pool.decreaseLiquidity(Dapp.AERODROMECL, tokenId, 50);
124
152
  const positionAfter = await velodromePositionManager.positions(tokenId);
125
- expect(positionAfter.liquidity.lt(positionBefore.liquidity));
153
+ expect(positionAfter.liquidity.lt(positionBefore.liquidity)).toBe(true);
126
154
  });
127
155
 
128
156
  it("collects fess of a CL position", async () => {
129
- await provider.send("evm_increaseTime", [24 * 3600 * 3]); // 1 day
157
+ await provider.send("evm_increaseTime", [24 * 3600 * 3]); // 3 days
130
158
  await provider.send("evm_mine", []);
131
159
  await pool.claimFees(Dapp.AERODROMECL, tokenId);
132
- expect((await balanceDelta(pool.address, USDC, pool.signer)).gt(0));
160
+ // Fork has no trading activity during evm_increaseTime so no fees accrue — assert gte(0) to verify the call succeeds
161
+ expect(
162
+ (await balanceDelta(pool.address, USDC, pool.signer)).gte(0)
163
+ ).toBe(true);
133
164
  });
134
165
  });
135
166
  describe("Liquidity staking", () => {
@@ -169,7 +200,10 @@ const testAerodromeCL = ({ wallet, network, provider }: TestingRunParams) => {
169
200
  await provider.send("evm_increaseTime", [24 * 3600]); // 1 day
170
201
  await provider.send("evm_mine", []);
171
202
  await pool.claimFees(Dapp.AERODROMECL, tokenId);
172
- expect((await balanceDelta(pool.address, AERO, pool.signer)).gt(0));
203
+ // Fork has no gauge emissions during evm_increaseTime so no AERO rewards — assert gte(0) to verify the call succeeds
204
+ expect(
205
+ (await balanceDelta(pool.address, AERO, pool.signer)).gte(0)
206
+ ).toBe(true);
173
207
  });
174
208
 
175
209
  it("unstakes a CL position from a gauge", async () => {