@dhedge/v2-sdk 2.1.8 → 2.2.0

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 (91) hide show
  1. package/README.md +400 -53
  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/oneInch/index.d.ts +1 -1
  8. package/dist/services/toros/easySwapper.d.ts +14 -0
  9. package/dist/services/toros/swapData.d.ts +5 -5
  10. package/dist/services/uniswap/V3Liquidity.d.ts +2 -2
  11. package/dist/services/velodrome/liquidity.d.ts +3 -0
  12. package/dist/test/constants.d.ts +48 -3
  13. package/dist/test/utils/testingHelper.d.ts +4 -0
  14. package/dist/types.d.ts +19 -4
  15. package/dist/utils/contract.d.ts +20 -0
  16. package/dist/v2-sdk.cjs.development.js +4996 -6742
  17. package/dist/v2-sdk.cjs.development.js.map +1 -1
  18. package/dist/v2-sdk.cjs.production.min.js +1 -1
  19. package/dist/v2-sdk.cjs.production.min.js.map +1 -1
  20. package/dist/v2-sdk.esm.js +5001 -6742
  21. package/dist/v2-sdk.esm.js.map +1 -1
  22. package/package.json +1 -1
  23. package/src/abi/PoolFactory.json +414 -204
  24. package/src/abi/PoolLogic.json +160 -134
  25. package/src/config.ts +13 -8
  26. package/src/entities/pool.ts +46 -253
  27. package/src/entities/utils.ts +15 -0
  28. package/src/services/hyperliquid/index.ts +22 -0
  29. package/src/services/kyberSwap/index.ts +5 -3
  30. package/src/services/oneInch/index.ts +5 -4
  31. package/src/services/toros/completeWithdrawal.ts +57 -40
  32. package/src/services/toros/easySwapper.ts +15 -1
  33. package/src/services/toros/initWithdrawal.ts +39 -31
  34. package/src/services/toros/swapData.ts +45 -131
  35. package/src/services/uniswap/V3Liquidity.ts +3 -24
  36. package/src/services/velodrome/liquidity.ts +3 -0
  37. package/src/test/aave.test.ts +99 -70
  38. package/src/test/aerodrome.test.ts +53 -24
  39. package/src/test/aerodromeCL.test.ts +64 -30
  40. package/src/test/arrakis.test.ts +23 -35
  41. package/src/test/balancer.test.ts +114 -106
  42. package/src/test/compoundV3.test.ts +45 -29
  43. package/src/test/constants.ts +56 -11
  44. package/src/test/cowswap.test.ts +33 -35
  45. package/src/test/dhedge.test.ts +45 -12
  46. package/src/test/flatmoney.test.ts +25 -39
  47. package/src/test/fluid.test.ts +33 -24
  48. package/src/test/hyperliquid.onchain.test.ts +131 -0
  49. package/src/test/kyberSwap.test.ts +37 -16
  50. package/src/test/lyra.test.ts +159 -150
  51. package/src/test/odos.test.ts +2 -2
  52. package/src/test/oneInch.test.ts +36 -22
  53. package/src/test/pancakeCL.test.ts +72 -31
  54. package/src/test/pendle.test.ts +94 -54
  55. package/src/test/{pendleMint.test.ts → pendleMint.onchain.test.ts} +22 -8
  56. package/src/test/pool.test.ts +152 -95
  57. package/src/test/toros.onchain.test.ts +92 -0
  58. package/src/test/toros.test.ts +74 -20
  59. package/src/test/torosLimitOrder.test.ts +87 -42
  60. package/src/test/uniswap.test.ts +77 -128
  61. package/src/test/utils/testingHelper.ts +120 -0
  62. package/src/test/velodrome.test.ts +126 -92
  63. package/src/test/velodromeCL.test.ts +43 -31
  64. package/src/test/velodromeV2.test.ts +153 -95
  65. package/src/types.ts +20 -5
  66. package/src/utils/contract.ts +20 -0
  67. package/dist/services/futures/constants.d.ts +0 -1
  68. package/dist/services/futures/index.d.ts +0 -2
  69. package/dist/services/futures/margin.d.ts +0 -2
  70. package/dist/services/futures/trade.d.ts +0 -3
  71. package/dist/services/ramses/vesting.d.ts +0 -4
  72. package/dist/services/uniswap/V3Trade.d.ts +0 -3
  73. package/dist/test/utils/futures.d.ts +0 -2
  74. package/src/abi/IRamsesNonfungiblePositionManager.json +0 -486
  75. package/src/abi/ISynthetiXFuturesMarketV2.json +0 -531
  76. package/src/abi/ISynthetix.json +0 -139
  77. package/src/abi/IUniswapV3Quoter.json +0 -195
  78. package/src/abi/IUniswapV3Router.json +0 -221
  79. package/src/abi/IXRam.json +0 -99
  80. package/src/services/futures/constants.ts +0 -1
  81. package/src/services/futures/index.ts +0 -2
  82. package/src/services/futures/margin.ts +0 -10
  83. package/src/services/futures/trade.ts +0 -32
  84. package/src/services/ramses/vesting.ts +0 -24
  85. package/src/services/uniswap/V3Trade.ts +0 -46
  86. package/src/test/futures.test.ts +0 -51
  87. package/src/test/hyperliquid.test.ts +0 -107
  88. package/src/test/ramses.test.ts +0 -190
  89. package/src/test/ramsesCL.test.ts +0 -155
  90. package/src/test/synthetix.test.ts +0 -36
  91. package/src/test/utils/futures.ts +0 -14
@@ -4,123 +4,131 @@ import { Dhedge, Pool } from "..";
4
4
  import { routerAddress } from "../config";
5
5
  import { Dapp, Network } from "../types";
6
6
  import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
7
+ import {
8
+ TestingRunParams,
9
+ testingHelper
10
+ } from "./utils/testingHelper";
7
11
  import { allowanceDelta, balanceDelta } from "./utils/token";
8
12
 
9
- import { wallet } from "./wallet";
13
+ const testBalancer = ({ wallet, network }: TestingRunParams) => {
14
+ const USDC = CONTRACT_ADDRESS[network].USDC;
15
+ const WETH = CONTRACT_ADDRESS[network].WETH;
16
+ const WSTETH = CONTRACT_ADDRESS[network].WSTETH;
17
+ const BALANCER_POOL = CONTRACT_ADDRESS[network].BALANCER_WSTETH_WETH_POOL;
18
+ const BLANCER_GAUGE = CONTRACT_ADDRESS[network].BALANCER_WSTETH_WETH_GAUGE;
10
19
 
11
- const network = Network.ARBITRUM;
12
- const USDC = CONTRACT_ADDRESS[network].USDC;
13
- const WETH = CONTRACT_ADDRESS[network].WETH;
14
- const WSTETH = CONTRACT_ADDRESS[network].WSTETH;
15
- const BALANCER_POOL = CONTRACT_ADDRESS[network].BALANCER_WSTETH_WETH_POOL;
16
- const BLANCER_GAUGE = CONTRACT_ADDRESS[network].BALANCER_WSTETH_WETH_GAUGE;
20
+ let dhedge: Dhedge;
21
+ let pool: Pool;
22
+ jest.setTimeout(100000);
17
23
 
18
- let dhedge: Dhedge;
19
- let pool: Pool;
20
- jest.setTimeout(100000);
24
+ describe(`pool on ${network}`, () => {
25
+ beforeAll(async () => {
26
+ dhedge = new Dhedge(wallet, network);
27
+ pool = await dhedge.loadPool(TEST_POOL[network]);
28
+ await pool.approve(Dapp.ONEINCH, USDC, MAX_AMOUNT);
29
+ await pool.trade(Dapp.ONEINCH, USDC, WETH, "1000000", 0.5);
30
+ await pool.trade(Dapp.ONEINCH, USDC, WSTETH, "1000000", 0.5);
31
+ });
21
32
 
22
- describe("pool", () => {
23
- beforeAll(async () => {
24
- dhedge = new Dhedge(wallet, network);
25
- pool = await dhedge.loadPool(TEST_POOL[network]);
26
- await pool.approve(Dapp.ONEINCH, USDC, MAX_AMOUNT);
27
- await pool.trade(Dapp.ONEINCH, USDC, WETH, "1000000", 0.5);
28
- await pool.trade(Dapp.ONEINCH, USDC, WSTETH, "1000000", 0.5);
29
- });
33
+ it("approves unlimited stWETH on Balancer", async () => {
34
+ await pool.approve(Dapp.BALANCER, WSTETH, MAX_AMOUNT);
35
+ const stWETHAllowanceDelta = await allowanceDelta(
36
+ pool.address,
37
+ WSTETH,
38
+ routerAddress[network].balancer!,
39
+ pool.signer
40
+ );
41
+ expect(stWETHAllowanceDelta.gt(0)).toBe(true);
42
+ });
30
43
 
31
- it("approves unlimited stWETH on Balancer", async () => {
32
- await pool.approve(Dapp.BALANCER, WSTETH, MAX_AMOUNT);
33
- const stWETHAllowanceDelta = await allowanceDelta(
34
- pool.address,
35
- WSTETH,
36
- routerAddress[network].balancer!,
37
- pool.signer
38
- );
39
- await expect(stWETHAllowanceDelta.gt(0));
40
- });
44
+ it("approves unlimited WETH on Balancer", async () => {
45
+ await pool.approve(Dapp.BALANCER, WETH, MAX_AMOUNT);
46
+ const wethAllowanceDelta = await allowanceDelta(
47
+ pool.address,
48
+ WETH,
49
+ routerAddress[network].balancer!,
50
+ pool.signer
51
+ );
52
+ expect(wethAllowanceDelta.gt(0)).toBe(true);
53
+ });
41
54
 
42
- it("approves unlimited WETH on Balancer", async () => {
43
- await pool.approve(Dapp.BALANCER, WETH, MAX_AMOUNT);
44
- const wethAllowanceDelta = await allowanceDelta(
45
- pool.address,
46
- WETH,
47
- routerAddress[network].balancer!,
48
- pool.signer
49
- );
50
- await expect(wethAllowanceDelta.gt(0));
51
- });
55
+ it("should add liquidity in a Balancer pool", async () => {
56
+ const wstETHBalance = await pool.utils.getBalance(WSTETH, pool.address);
57
+ const wethBalance = await pool.utils.getBalance(WETH, pool.address);
58
+ await pool.joinBalancerPool(
59
+ "0x36bf227d6bac96e2ab1ebb5492ecec69c691943f000200000000000000000316", //wstETH-WETH on Arbitrum
60
+ [WSTETH, WETH],
61
+ [wstETHBalance.toString(), wethBalance.toString()]
62
+ );
63
+ const lpBalanceDelta = await balanceDelta(
64
+ pool.address,
65
+ BALANCER_POOL,
66
+ pool.signer
67
+ );
68
+ expect(lpBalanceDelta.gt(0)).toBe(true);
69
+ });
52
70
 
53
- it("should add liquidity in a Balancer pool", async () => {
54
- const wstETHBalance = await pool.utils.getBalance(WSTETH, pool.address);
55
- const wethBalance = await pool.utils.getBalance(WETH, pool.address);
56
- await pool.joinBalancerPool(
57
- "0x36bf227d6bac96e2ab1ebb5492ecec69c691943f000200000000000000000316", //wstETH-WETH on Arbitrum
58
- [WSTETH, WETH],
59
- [wstETHBalance.toString(), wethBalance.toString()]
60
- );
61
- const lpBalanceDelta = await balanceDelta(
62
- pool.address,
63
- BALANCER_POOL,
64
- pool.signer
65
- );
66
- expect(lpBalanceDelta.gt(0));
67
- });
71
+ it("approves unlimited LP Token on Balancer Vault", async () => {
72
+ await pool.approveSpender(BLANCER_GAUGE, BALANCER_POOL, MAX_AMOUNT);
73
+ const gaugeAllowanceDelta = await allowanceDelta(
74
+ pool.address,
75
+ BALANCER_POOL,
76
+ BLANCER_GAUGE,
77
+ pool.signer
78
+ );
79
+ expect(gaugeAllowanceDelta.gt(0)).toBe(true);
80
+ });
68
81
 
69
- it("approves unlimited LP Token on Balancer Vault", async () => {
70
- await pool.approveSpender(BLANCER_GAUGE, BALANCER_POOL, MAX_AMOUNT);
71
- const gaugeAllowanceDelta = await allowanceDelta(
72
- pool.address,
73
- BALANCER_POOL,
74
- BLANCER_GAUGE,
75
- pool.signer
76
- );
77
- await expect(gaugeAllowanceDelta.gt(0));
78
- });
82
+ it("stakes LP tokens in Balancer vault", async () => {
83
+ const lpTokenBalance = await pool.utils.getBalance(
84
+ BALANCER_POOL,
85
+ pool.address
86
+ );
87
+ await pool.stakeInGauge(Dapp.BALANCER, BLANCER_GAUGE, lpTokenBalance);
88
+ const lpBalanceDelta = await balanceDelta(
89
+ pool.address,
90
+ BALANCER_POOL,
91
+ pool.signer
92
+ );
93
+ expect(lpBalanceDelta.lt(0)).toBe(true);
94
+ });
79
95
 
80
- it("stakes LP tokens in Balancer vault", async () => {
81
- const lpTokenBalance = await pool.utils.getBalance(
82
- BALANCER_POOL,
83
- pool.address
84
- );
85
- await pool.stakeInGauge(Dapp.BALANCER, BLANCER_GAUGE, lpTokenBalance);
86
- const lpBalanceDelta = await balanceDelta(
87
- pool.address,
88
- BALANCER_POOL,
89
- pool.signer
90
- );
91
- expect(lpBalanceDelta.lt(0));
92
- });
96
+ it("unstakes LP tokens from Balancer vault", async () => {
97
+ const vaultTokenBalance = await pool.utils.getBalance(
98
+ BLANCER_GAUGE,
99
+ pool.address
100
+ );
101
+ await pool.unstakeFromGauge(BLANCER_GAUGE, vaultTokenBalance);
102
+ const lpBalanceDelta = await balanceDelta(
103
+ pool.address,
104
+ BALANCER_POOL,
105
+ pool.signer
106
+ );
107
+ expect(lpBalanceDelta.gt(0)).toBe(true);
108
+ });
93
109
 
94
- it("unstakes LP tokens from Balancer vault", async () => {
95
- const vaultTokenBalance = await pool.utils.getBalance(
96
- BLANCER_GAUGE,
97
- pool.address
98
- );
99
- await pool.unstakeFromGauge(BLANCER_GAUGE, vaultTokenBalance);
100
- const lpBalanceDelta = await balanceDelta(
101
- pool.address,
102
- BALANCER_POOL,
103
- pool.signer
104
- );
105
- expect(lpBalanceDelta.gt(0));
110
+ it("should remove liquidity from an Balancer pool ", async () => {
111
+ const lpTokenBalance = await pool.utils.getBalance(
112
+ BALANCER_POOL,
113
+ pool.address
114
+ );
115
+ await pool.approve(Dapp.BALANCER, BALANCER_POOL, MAX_AMOUNT);
116
+ await pool.exitBalancerPool(
117
+ "0x36bf227d6bac96e2ab1ebb5492ecec69c691943f000200000000000000000316",
118
+ [WSTETH, WETH],
119
+ lpTokenBalance
120
+ );
121
+ const wethBalanceDelta = await balanceDelta(
122
+ pool.address,
123
+ WETH,
124
+ pool.signer
125
+ );
126
+ expect(wethBalanceDelta.gt(0)).toBe(true);
127
+ });
106
128
  });
129
+ };
107
130
 
108
- it("should remove liquidity from an Balancer pool ", async () => {
109
- const lpTokenBalance = await pool.utils.getBalance(
110
- BALANCER_POOL,
111
- pool.address
112
- );
113
- await pool.approve(Dapp.BALANCER, BALANCER_POOL, MAX_AMOUNT);
114
- await pool.exitBalancerPool(
115
- "0x36bf227d6bac96e2ab1ebb5492ecec69c691943f000200000000000000000316",
116
- [WSTETH, WETH],
117
- lpTokenBalance
118
- );
119
- const wethBalanceDelta = await balanceDelta(
120
- pool.address,
121
- CONTRACT_ADDRESS[network].WETH,
122
- pool.signer
123
- );
124
- expect(wethBalanceDelta.gt(0));
125
- });
131
+ testingHelper({
132
+ network: Network.ARBITRUM,
133
+ testingRun: testBalancer
126
134
  });
@@ -1,19 +1,22 @@
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 { ethers } from "ethers";
4
5
  import { Dhedge, Pool } from "..";
5
- import { AssetEnabled, Network } from "../types";
6
+ import { Network } from "../types";
6
7
  import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
7
8
  import {
8
9
  TestingRunParams,
9
10
  beforeAfterReset,
10
11
  setWETHAmount,
12
+ setChainlinkTimeout,
13
+ fixOracleAggregatorStaleness,
14
+ runWithImpersonateAccount,
11
15
  testingHelper
12
16
  } from "./utils/testingHelper";
13
- import { allowanceDelta, balanceDelta } from "./utils/token";
14
- import { getWalletData } from "./wallet";
17
+ import { balanceDelta } from "./utils/token";
15
18
 
16
- const testCompoundV3 = ({ network, provider }: TestingRunParams) => {
19
+ const testCompoundV3 = ({ wallet, network, provider }: TestingRunParams) => {
17
20
  const WETH = CONTRACT_ADDRESS[network].WETH;
18
21
  const COMPOUNDV3_WETH = CONTRACT_ADDRESS[network].COMPOUNDV3_WETH;
19
22
 
@@ -23,14 +26,13 @@ const testCompoundV3 = ({ network, provider }: TestingRunParams) => {
23
26
 
24
27
  describe(`[${network}] compound V3 tests`, () => {
25
28
  beforeAll(async () => {
26
- const { wallet } = getWalletData(network);
27
- // top up ETH (gas)
28
29
  await provider.send("hardhat_setBalance", [
29
30
  wallet.address,
30
- "0x100000000000000"
31
+ "0x10000000000000000"
31
32
  ]);
32
33
  dhedge = new Dhedge(wallet, network);
33
34
  pool = await dhedge.loadPool(TEST_POOL[network]);
35
+
34
36
  await setWETHAmount({
35
37
  amount: new BigNumber(1e18).toFixed(0),
36
38
  userAddress: pool.address,
@@ -38,29 +40,41 @@ const testCompoundV3 = ({ network, provider }: TestingRunParams) => {
38
40
  provider
39
41
  });
40
42
 
41
- const newAssets: AssetEnabled[] = [
42
- { asset: WETH, isDeposit: true },
43
- {
44
- asset: COMPOUNDV3_WETH,
45
- isDeposit: false
43
+ // Extend oracle timeouts so price feeds work on fork
44
+ await setChainlinkTimeout({ pool, provider }, 86400 * 365);
45
+ await fixOracleAggregatorStaleness({ pool, provider });
46
+
47
+ // Impersonate pool manager to set trader and configure assets
48
+ await runWithImpersonateAccount(
49
+ { provider, account: await pool.managerLogic.manager() },
50
+ async ({ signer }) => {
51
+ await pool.managerLogic.connect(signer).setTrader(wallet.address);
52
+ const newAssets = [
53
+ [WETH, true],
54
+ [COMPOUNDV3_WETH, false]
55
+ ];
56
+ await pool.managerLogic.connect(signer).changeAssets(newAssets, []);
46
57
  }
47
- ];
48
- await pool.managerLogic.changeAssets(newAssets, []);
58
+ );
49
59
  });
50
60
  beforeAfterReset({ beforeAll, afterAll, provider });
51
61
 
52
62
  it("approves unlimited WETH for cWETHv3 market", async () => {
53
- await pool.approveSpender(COMPOUNDV3_WETH, WETH, MAX_AMOUNT);
54
- const UsdcAllowanceDelta = await allowanceDelta(
55
- pool.address,
63
+ const tx = await pool.approveSpender(COMPOUNDV3_WETH, WETH, MAX_AMOUNT);
64
+ await tx.wait(1);
65
+ const iERC20 = new ethers.Contract(
56
66
  WETH,
57
- COMPOUNDV3_WETH,
67
+ ["function allowance(address,address) view returns (uint256)"],
58
68
  pool.signer
59
69
  );
60
- await expect(UsdcAllowanceDelta.gt(0));
70
+ const wethAllowance = await iERC20.allowance(
71
+ pool.address,
72
+ COMPOUNDV3_WETH
73
+ );
74
+ expect(wethAllowance.gt(0)).toBe(true);
61
75
  });
62
76
 
63
- it("lends WETH to CompundV3 WETH market", async () => {
77
+ it("lends WETH to CompoundV3 WETH market", async () => {
64
78
  const wethBalance = await pool.utils.getBalance(WETH, pool.address);
65
79
  await pool.lendCompoundV3(COMPOUNDV3_WETH, WETH, wethBalance);
66
80
 
@@ -69,20 +83,22 @@ const testCompoundV3 = ({ network, provider }: TestingRunParams) => {
69
83
  COMPOUNDV3_WETH,
70
84
  pool.signer
71
85
  );
72
- expect(cWETHTokenDelta.gt(0));
86
+ expect(cWETHTokenDelta.gt(0)).toBe(true);
73
87
  });
74
88
 
75
- it("withdraw WETH from CompundV3 WETH market", async () => {
76
- const cWETHBalance = await pool.utils.getBalance(
77
- COMPOUNDV3_WETH,
78
- pool.address
89
+ it("withdraws WETH from CompoundV3 WETH market", async () => {
90
+ // Withdraw half of the originally supplied amount
91
+ const halfWeth = new BigNumber(1e18).div(2).toFixed(0);
92
+ await pool.withdrawCompoundV3(COMPOUNDV3_WETH, WETH, halfWeth);
93
+ const wethBalanceDelta = await balanceDelta(
94
+ pool.address,
95
+ WETH,
96
+ pool.signer
79
97
  );
80
- await pool.withdrawCompoundV3(COMPOUNDV3_WETH, WETH, cWETHBalance);
81
- const wethBalance = await balanceDelta(pool.address, WETH, pool.signer);
82
- expect(wethBalance.gt(0));
98
+ expect(wethBalanceDelta.gt(0)).toBe(true);
83
99
  });
84
100
 
85
- it("harvests rewards from CompundV3", async () => {
101
+ it("harvests rewards from CompoundV3", async () => {
86
102
  await pool.harvestCompoundV3Rewards(COMPOUNDV3_WETH);
87
103
  });
88
104
  });
@@ -35,8 +35,6 @@ export const SUSD = "0x8c6f28f2f1a3c87f0f938b96d27520d9751ec8d9";
35
35
  export const SETH = "0xE405de8F52ba7559f9df3C368500B6E6ae6Cee49";
36
36
  export const ARRAKIS_USDC_WETH_GAUGE =
37
37
  "0xb8888ea29e2f70ad62a3b69b1a1342720612a00d";
38
- export const KWENTA_ETH_PERP = "0xf86048dff23cf130107dfb4e6386f574231a5c65";
39
- export const KWENTA_ETH_PERP_V2 = "0x2b3bb4c683bfc5239b029131eef3b1d214478d93";
40
38
 
41
39
  export const TEST_POOL = {
42
40
  [Network.POLYGON]: "0x699fd4d6eadb216704c7e355cfa0a12f51813163",
@@ -68,7 +66,10 @@ export const CONTRACT_ADDRESS = {
68
66
  COMPOUNDV3_WETH: "",
69
67
  FLUID_WETH: "",
70
68
  TOROS: "",
71
- UNIT: ""
69
+ UNIT: "",
70
+ WSTETH: "",
71
+ BALANCER_WSTETH_WETH_POOL: "",
72
+ BALANCER_WSTETH_WETH_GAUGE: ""
72
73
  },
73
74
 
74
75
  [Network.OPTIMISM]: {
@@ -79,7 +80,6 @@ export const CONTRACT_ADDRESS = {
79
80
  SUSD: "0x8c6f28f2f1a3c87f0f938b96d27520d9751ec8d9",
80
81
  WETH: "0x4200000000000000000000000000000000000006",
81
82
  WBTC: "0x68f180fcCe6836688e9084f035309E29Bf0A2095",
82
- KWENTA_ETH_PERP_V2: "0x2b3bb4c683bfc5239b029131eef3b1d214478d93",
83
83
  uniswapV3: {
84
84
  nonfungiblePositionManager: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88"
85
85
  },
@@ -93,7 +93,10 @@ export const CONTRACT_ADDRESS = {
93
93
  VELO: "0x9560e827aF36c94D2Ac33a39bCE1Fe78631088Db",
94
94
  COMPOUNDV3_WETH: "",
95
95
  FLUID_WETH: "",
96
- TOROS: "0xcacb5a722a36cff6baeb359e21c098a4acbffdfa" //ETHBEAR1X
96
+ TOROS: "0xcacb5a722a36cff6baeb359e21c098a4acbffdfa", //ETHBEAR1X
97
+ WSTETH: "",
98
+ BALANCER_WSTETH_WETH_POOL: "",
99
+ BALANCER_WSTETH_WETH_GAUGE: ""
97
100
  },
98
101
  [Network.ARBITRUM]: {
99
102
  USDC: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
@@ -121,7 +124,7 @@ export const CONTRACT_ADDRESS = {
121
124
  VELO: "",
122
125
  COMPOUNDV3_WETH: "0x6f7D514bbD4aFf3BcD1140B7344b32f063dEe486",
123
126
  FLUID_WETH: "0x45df0656f8adf017590009d2f1898eeca4f0a205",
124
- TOROS: ""
127
+ TOROS: "0xA6711f8a184E352c5A0714a48912cD33ca4a16A0" //DYTMT
125
128
  },
126
129
  [Network.BASE]: {
127
130
  USDC: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
@@ -143,7 +146,10 @@ export const CONTRACT_ADDRESS = {
143
146
  VELO: "0x940181a94A35A4569E4529A3CDfB74e38FD98631",
144
147
  COMPOUNDV3_WETH: "",
145
148
  FLUID_WETH: "",
146
- TOROS: ""
149
+ TOROS: "",
150
+ WSTETH: "",
151
+ BALANCER_WSTETH_WETH_POOL: "",
152
+ BALANCER_WSTETH_WETH_GAUGE: ""
147
153
  },
148
154
  [Network.ETHEREUM]: {
149
155
  USDC: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
@@ -165,17 +171,56 @@ export const CONTRACT_ADDRESS = {
165
171
  COMPOUNDV3_WETH: "",
166
172
  FLUID_WETH: "",
167
173
  TOROS: "",
168
- UNIT: ""
174
+ UNIT: "",
175
+ WSTETH: "",
176
+ BALANCER_WSTETH_WETH_POOL: "",
177
+ BALANCER_WSTETH_WETH_GAUGE: ""
169
178
  },
170
179
  [Network.PLASMA]: {
171
180
  USDC: "",
172
181
  WETH: "0x9895d81bb462a195b4922ed7de0e3acd007c32cb",
182
+ WBTC: "",
173
183
  USDT: "0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb",
174
- USDE: "0x5d3a1ff2b6bab83b63cd9ad0787074081a52ef34"
184
+ USDE: "0x5d3a1ff2b6bab83b63cd9ad0787074081a52ef34",
185
+ VELO: "",
186
+ uniswapV3: {
187
+ nonfungiblePositionManager: ""
188
+ },
189
+ COMPOUNDV3_WETH: "",
190
+ FLUID_WETH: "",
191
+ UNIT: "",
192
+ TOROS: "",
193
+ SUSD: "",
194
+ VELODROME_CL_USDC_WETH_GAUGE: "",
195
+ ARRAKIS_USDC_WETH_GAUGE: "",
196
+ ARRAKIS_USDC_WETH_LP: "",
197
+ WMATIC: "",
198
+ WSTETH: "",
199
+ BALANCER_WSTETH_WETH_POOL: "",
200
+ BALANCER_WSTETH_WETH_GAUGE: ""
175
201
  },
176
202
  [Network.HYPERLIQUID]: {
177
203
  USDC: "0xb88339cb7199b77e23db6e890353e22632ba630f",
178
- WETH: ""
204
+ USDT: "",
205
+ USDE: "",
206
+ WETH: "",
207
+ WBTC: "",
208
+ VELO: "",
209
+ uniswapV3: {
210
+ nonfungiblePositionManager: ""
211
+ },
212
+ COMPOUNDV3_WETH: "",
213
+ FLUID_WETH: "",
214
+ UNIT: "",
215
+ TOROS: "",
216
+ SUSD: "",
217
+ VELODROME_CL_USDC_WETH_GAUGE: "",
218
+ ARRAKIS_USDC_WETH_GAUGE: "",
219
+ ARRAKIS_USDC_WETH_LP: "",
220
+ WMATIC: "",
221
+ WSTETH: "",
222
+ BALANCER_WSTETH_WETH_POOL: "",
223
+ BALANCER_WSTETH_WETH_GAUGE: ""
179
224
  }
180
225
  };
181
226
 
@@ -195,7 +240,7 @@ export const WETH_BALANCEOF_SLOT = {
195
240
  [Network.OPTIMISM]: 3,
196
241
  [Network.ARBITRUM]: 51,
197
242
  [Network.POLYGON]: 0,
198
- [Network.BASE]: 0,
243
+ [Network.BASE]: 3,
199
244
  [Network.ETHEREUM]: 3,
200
245
  [Network.PLASMA]: 1,
201
246
  [Network.HYPERLIQUID]: 1
@@ -1,12 +1,26 @@
1
1
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
2
 
3
+ /**
4
+ * CowSwap tests require a live chain connection (onFork: false).
5
+ * CowSwap orders are settled off-chain by solvers, so they cannot
6
+ * be tested on a Hardhat fork. Run with a funded wallet and
7
+ * PRIVATE_KEY + POLYGON_URL set in .env.
8
+ *
9
+ * Flow: approve CoW vault relayer → trade
10
+ * Note: estimateGas and onlyGetTxData are not supported for CowSwap
11
+ * because it requires two sequential transactions (submit + preSign).
12
+ */
13
+
3
14
  import { Dhedge, Pool } from "..";
4
15
 
5
16
  import { Dapp, Network } from "../types";
6
- import { CONTRACT_ADDRESS, TEST_POOL } from "./constants";
17
+ import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
7
18
  import { getTxOptions } from "./txOptions";
8
19
  import { TestingRunParams, testingHelper } from "./utils/testingHelper";
9
- import { balanceDelta } from "./utils/token";
20
+ import { allowanceDelta, balanceDelta } from "./utils/token";
21
+
22
+ // CoW Protocol Vault Relayer — must be approved before CowSwap trades
23
+ const COWSWAP_VAULT_RELAYER = "0xC92E8bdf79f0507f65a392b0ab4667716BFE0110";
10
24
 
11
25
  const testCowswap = ({ wallet, network }: TestingRunParams) => {
12
26
  const USDC = CONTRACT_ADDRESS[network].USDC;
@@ -16,44 +30,27 @@ const testCowswap = ({ wallet, network }: TestingRunParams) => {
16
30
  let pool: Pool;
17
31
  jest.setTimeout(100000);
18
32
 
19
- describe(`pool on ${network}`, () => {
33
+ describe(`[${network}] cowswap tests`, () => {
20
34
  beforeAll(async () => {
21
35
  dhedge = new Dhedge(wallet, network);
22
36
  pool = await dhedge.loadPool(TEST_POOL[network]);
23
37
  });
24
38
 
25
- // it("approves unlimited USDC on Cowswap", async () => {
26
- // await pool.approveSpender(
27
- // "0xC92E8bdf79f0507f65a392b0ab4667716BFE0110", //Vault relayer
28
- // USDC,
29
- // MAX_AMOUNT,
30
- // await getTxOptions(network)
31
- // );
32
- // const usdcAllowanceDelta = await allowanceDelta(
33
- // pool.address,
34
- // USDC,
35
- // "0xC92E8bdf79f0507f65a392b0ab4667716BFE0110", //Vault relayer
36
- // pool.signer
37
- // );
38
- // await expect(usdcAllowanceDelta.gt(0).toBe(true));
39
- // });
40
-
41
- // it("gets gas estimation for 2 USDC into WETH on Cowswap", async () => {
42
- // const gasEstimate = await pool.trade(
43
- // Dapp.COWSWAP,
44
- // USDC,
45
- // WETH,
46
- // "2000000",
47
- // 1,
48
- // await getTxOptions(network),
49
- // true
50
- // );
51
- // console.log(
52
- // "Gas estimate for trading 2 USDC to WETH on Cowswap:",
53
- // gasEstimate
54
- // );
55
- // expect(gasEstimate.minAmountOut).not.toBeNull();
56
- // });
39
+ it("approves unlimited USDC on Cowswap vault relayer", async () => {
40
+ await pool.approveSpender(
41
+ COWSWAP_VAULT_RELAYER,
42
+ USDC,
43
+ MAX_AMOUNT,
44
+ await getTxOptions(network)
45
+ );
46
+ const usdcAllowanceDelta = await allowanceDelta(
47
+ pool.address,
48
+ USDC,
49
+ COWSWAP_VAULT_RELAYER,
50
+ pool.signer
51
+ );
52
+ expect(usdcAllowanceDelta.gt(0)).toBe(true);
53
+ });
57
54
 
58
55
  it("trades 2 USDC into WETH on Cowswap", async () => {
59
56
  await pool.trade(
@@ -74,6 +71,7 @@ const testCowswap = ({ wallet, network }: TestingRunParams) => {
74
71
  });
75
72
  };
76
73
 
74
+ // CowSwap requires live chain — cannot run on fork
77
75
  testingHelper({
78
76
  network: Network.POLYGON,
79
77
  testingRun: testCowswap,
@@ -1,32 +1,65 @@
1
1
  import { Dhedge } from "..";
2
2
  import { Network } from "../types";
3
+ import { CONTRACT_ADDRESS, TEST_POOL } from "./constants";
4
+ import {
5
+ testingHelper,
6
+ TestingRunParams,
7
+ beforeAfterReset
8
+ } from "./utils/testingHelper";
3
9
 
4
- import { testingHelper, TestingRunParams } from "./utils/testingHelper";
5
-
6
- const testDhedge = ({ wallet, network }: TestingRunParams) => {
10
+ const testDhedge = ({ wallet, network, provider }: TestingRunParams) => {
7
11
  let dhedge: Dhedge;
8
12
 
9
13
  jest.setTimeout(200000);
10
14
 
11
15
  describe(`dHEDGE on ${network}`, () => {
12
16
  beforeAll(async () => {
17
+ // Fund the test wallet with gas
18
+ await provider.send("hardhat_setBalance", [
19
+ wallet.address,
20
+ "0x10000000000000000"
21
+ ]);
13
22
  dhedge = new Dhedge(wallet, network);
14
23
  });
15
24
 
16
- it("create a pool", async () => {
17
- const pool = await dhedge.createPool("Test", "Test", "TEST", [
18
- ["0x5d3a1ff2b6bab83b63cd9ad0787074081a52ef34", true],
19
- ["0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb", false],
20
- ["0x925a2A7214Ed92428B5b1B090F80b25700095e12", false]
21
- ]);
22
- console.log(pool.address);
25
+ beforeAfterReset({ beforeAll, afterAll, provider });
26
+
27
+ it("creates a pool with USDC and WETH", async () => {
28
+ const pool = await dhedge.createPool(
29
+ "Test Manager",
30
+ "Test Fund",
31
+ "TEST",
32
+ [
33
+ [CONTRACT_ADDRESS[network].USDC, true],
34
+ [CONTRACT_ADDRESS[network].WETH, false]
35
+ ]
36
+ );
37
+ expect(pool.address).toBeDefined();
23
38
  expect(pool.poolLogic.address).toBe(pool.address);
24
39
  });
40
+
41
+ it("loads an existing pool", async () => {
42
+ const pool = await dhedge.loadPool(TEST_POOL[network]);
43
+ expect(pool.address).toBe(TEST_POOL[network]);
44
+ expect(pool.poolLogic.address).toBe(TEST_POOL[network]);
45
+ });
46
+
47
+ it("validates a real pool address", async () => {
48
+ const isValid = await dhedge.validatePool(TEST_POOL[network]);
49
+ expect(isValid).toBe(true);
50
+ });
51
+
52
+ it("rejects an invalid pool address", async () => {
53
+ const isValid = await dhedge.validatePool(
54
+ "0x0000000000000000000000000000000000000001"
55
+ );
56
+ expect(isValid).toBe(false);
57
+ });
25
58
  });
26
59
  };
27
60
 
28
61
  testingHelper({
29
- network: Network.PLASMA,
30
- onFork: false,
62
+ network: Network.ARBITRUM,
63
+ onFork: true,
31
64
  testingRun: testDhedge
32
65
  });