@dhedge/v2-sdk 1.10.0 → 1.10.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.
@@ -1,21 +1,22 @@
1
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
3
1
  import BigNumber from "bignumber.js";
4
2
  import { Dhedge, Pool, ethers } from "..";
3
+
5
4
  import { nonfungiblePositionManagerAddress } from "../config";
6
5
  import { AssetEnabled, Dapp, Network } from "../types";
7
6
  import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
8
7
  import {
9
8
  TestingRunParams,
10
9
  beforeAfterReset,
10
+ setChainlinkTimeout,
11
11
  setUSDCAmount,
12
12
  setWETHAmount,
13
13
  testingHelper
14
14
  } from "./utils/testingHelper";
15
- import { balanceDelta } from "./utils/token";
15
+ import { allowanceDelta, balanceDelta } from "./utils/token";
16
16
  import INonfungiblePositionManager from "../abi/INonfungiblePositionManager.json";
17
17
 
18
18
  const testVelodromeCL = ({ wallet, network, provider }: TestingRunParams) => {
19
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
19
20
  const VELODROME_POSITION_MANGER = nonfungiblePositionManagerAddress[network][
20
21
  Dapp.VELODROMECL
21
22
  ]!;
@@ -41,6 +42,10 @@ const testVelodromeCL = ({ wallet, network, provider }: TestingRunParams) => {
41
42
  ]);
42
43
  dhedge = new Dhedge(wallet, network);
43
44
  pool = await dhedge.loadPool(TEST_POOL[network]);
45
+
46
+ // setChainlinkTimeout
47
+ await setChainlinkTimeout({ pool, provider }, 86400 * 365);
48
+
44
49
  await setUSDCAmount({
45
50
  amount: new BigNumber(10000).times(1e6).toFixed(0),
46
51
  userAddress: pool.address,
@@ -60,6 +65,10 @@ const testVelodromeCL = ({ wallet, network, provider }: TestingRunParams) => {
60
65
  {
61
66
  asset: VELODROME_POSITION_MANGER,
62
67
  isDeposit: false
68
+ },
69
+ {
70
+ asset: VELO,
71
+ isDeposit: false
63
72
  }
64
73
  ];
65
74
  await pool.changeAssets(newAssets);
@@ -73,77 +82,20 @@ const testVelodromeCL = ({ wallet, network, provider }: TestingRunParams) => {
73
82
 
74
83
  beforeAfterReset({ beforeAll, afterAll, provider });
75
84
 
76
- // describe("Liquidity", () => {
77
- // it("approves unlimited USDC and WETH on for Velodrome CL", async () => {
78
- // await pool.approveSpender(VELODROME_POSITION_MANGER, USDC, MAX_AMOUNT);
79
- // await pool.approveSpender(VELODROME_POSITION_MANGER, WETH, MAX_AMOUNT);
80
- // const UsdcAllowanceDelta = await allowanceDelta(
81
- // pool.address,
82
- // USDC,
83
- // VELODROME_POSITION_MANGER,
84
- // pool.signer
85
- // );
86
- // await expect(UsdcAllowanceDelta.gt(0));
87
- // });
88
-
89
- // it("adds USDC and WETH to a Velodrome CL (mint position)", async () => {
90
- // const usdcBalance = await pool.utils.getBalance(USDC, pool.address);
91
- // const wethBalance = await pool.utils.getBalance(WETH, pool.address);
92
- // await pool.addLiquidityUniswapV3(
93
- // Dapp.VELODROMECL,
94
- // USDC,
95
- // WETH,
96
- // usdcBalance.div(2),
97
- // wethBalance.div(2),
98
- // null,
99
- // null,
100
- // 193700,
101
- // 193900,
102
- // 100
103
- // );
104
-
105
- // tokenId = (
106
- // await velodromePositionManager.tokenOfOwnerByIndex(pool.address, 0)
107
- // ).toString();
108
- // expect(tokenId).not.toBe(null);
109
- // });
110
-
111
- // it("increases liquidity in a CL position", async () => {
112
- // const usdcBalance = await pool.utils.getBalance(USDC, pool.address);
113
- // const wethBalance = await pool.utils.getBalance(WETH, pool.address);
114
- // const positionBefore = await velodromePositionManager.positions(
115
- // tokenId
116
- // );
117
- // await pool.increaseLiquidity(
118
- // Dapp.VELODROMECL,
119
- // tokenId,
120
- // usdcBalance.div(2),
121
- // wethBalance.div(2)
122
- // );
123
- // const positionAfter = await velodromePositionManager.positions(tokenId);
124
- // expect(positionAfter.liquidity.gt(positionBefore.liquidity));
125
- // });
126
-
127
- // it("decreases liquidity from a CL position", async () => {
128
- // const positionBefore = await velodromePositionManager.positions(
129
- // tokenId
130
- // );
131
- // await pool.decreaseLiquidity(Dapp.VELODROMECL, tokenId, 50);
132
- // const positionAfter = await velodromePositionManager.positions(tokenId);
133
- // expect(positionAfter.liquidity.lt(positionBefore.liquidity));
134
- // });
135
-
136
- // it("collects fess of a CL position", async () => {
137
- // await provider.send("evm_increaseTime", [24 * 3600 * 3]); // 1 day
138
- // await provider.send("evm_mine", []);
139
- // await pool.claimFees(Dapp.VELODROMECL, tokenId);
140
- // expect((await balanceDelta(pool.address, USDC, pool.signer)).gt(0));
141
- // });
142
- // });
143
- describe("Liquidity staking", () => {
144
- it("stakes a CL position in gauge", async () => {
85
+ describe("Liquidity", () => {
86
+ it("approves unlimited USDC and WETH on for Velodrome CL", async () => {
145
87
  await pool.approveSpender(VELODROME_POSITION_MANGER, USDC, MAX_AMOUNT);
146
88
  await pool.approveSpender(VELODROME_POSITION_MANGER, WETH, MAX_AMOUNT);
89
+ const UsdcAllowanceDelta = await allowanceDelta(
90
+ pool.address,
91
+ USDC,
92
+ VELODROME_POSITION_MANGER,
93
+ pool.signer
94
+ );
95
+ await expect(UsdcAllowanceDelta.gt(0));
96
+ });
97
+
98
+ it("adds USDC and WETH to a Velodrome CL (mint position)", async () => {
147
99
  const usdcBalance = await pool.utils.getBalance(USDC, pool.address);
148
100
  const wethBalance = await pool.utils.getBalance(WETH, pool.address);
149
101
  await pool.addLiquidityUniswapV3(
@@ -162,18 +114,26 @@ const testVelodromeCL = ({ wallet, network, provider }: TestingRunParams) => {
162
114
  tokenId = (
163
115
  await velodromePositionManager.tokenOfOwnerByIndex(pool.address, 0)
164
116
  ).toString();
165
- await pool.approveSpenderNFT(
166
- USDC_WETH_CL_GAUGE,
167
- VELODROME_POSITION_MANGER,
117
+ expect(tokenId).not.toBe(null);
118
+ });
119
+
120
+ it("increases liquidity in a CL position", async () => {
121
+ const usdcBalance = await pool.utils.getBalance(USDC, pool.address);
122
+ const wethBalance = await pool.utils.getBalance(WETH, pool.address);
123
+ const positionBefore = await velodromePositionManager.positions(
168
124
  tokenId
169
125
  );
170
- await pool.stakeInGauge(Dapp.VELODROMECL, USDC_WETH_CL_GAUGE, tokenId);
171
- expect(await velodromePositionManager.ownerOf(tokenId)).toBe(
172
- USDC_WETH_CL_GAUGE
126
+ await pool.increaseLiquidity(
127
+ Dapp.VELODROMECL,
128
+ tokenId,
129
+ usdcBalance.div(2),
130
+ wethBalance.div(2)
173
131
  );
132
+ const positionAfter = await velodromePositionManager.positions(tokenId);
133
+ expect(positionAfter.liquidity.gt(positionBefore.liquidity));
174
134
  });
175
135
 
176
- it("decreases liquidity from a staked CL position", async () => {
136
+ it("decreases liquidity from a CL position", async () => {
177
137
  const positionBefore = await velodromePositionManager.positions(
178
138
  tokenId
179
139
  );
@@ -182,22 +142,44 @@ const testVelodromeCL = ({ wallet, network, provider }: TestingRunParams) => {
182
142
  expect(positionAfter.liquidity.lt(positionBefore.liquidity));
183
143
  });
184
144
 
185
- it("increases liquidity in a staked CL position", async () => {
145
+ it("collects fess of a CL position", async () => {
146
+ await provider.send("evm_increaseTime", [24 * 3600 * 3]); // 1 day
147
+ await provider.send("evm_mine", []);
148
+ await pool.claimFees(Dapp.VELODROMECL, tokenId);
149
+ expect((await balanceDelta(pool.address, USDC, pool.signer)).gt(0));
150
+ });
151
+ });
152
+ describe("Liquidity staking", () => {
153
+ it("stakes a CL position in gauge", async () => {
154
+ await pool.approveSpender(VELODROME_POSITION_MANGER, USDC, MAX_AMOUNT);
155
+ await pool.approveSpender(VELODROME_POSITION_MANGER, WETH, MAX_AMOUNT);
186
156
  const usdcBalance = await pool.utils.getBalance(USDC, pool.address);
187
157
  const wethBalance = await pool.utils.getBalance(WETH, pool.address);
188
- const positionBefore = await velodromePositionManager.positions(
189
- tokenId
190
- );
191
- await pool.approveSpender(USDC_WETH_CL_GAUGE, USDC, MAX_AMOUNT);
192
- await pool.approveSpender(USDC_WETH_CL_GAUGE, WETH, MAX_AMOUNT);
193
- await pool.increaseLiquidity(
158
+ await pool.addLiquidityUniswapV3(
194
159
  Dapp.VELODROMECL,
195
- tokenId,
160
+ USDC,
161
+ WETH,
196
162
  usdcBalance.div(2),
197
- wethBalance.div(2)
163
+ wethBalance.div(2),
164
+ null,
165
+ null,
166
+ 193700,
167
+ 193900,
168
+ 100
169
+ );
170
+
171
+ tokenId = (
172
+ await velodromePositionManager.tokenOfOwnerByIndex(pool.address, 0)
173
+ ).toString();
174
+ await pool.approveSpenderNFT(
175
+ USDC_WETH_CL_GAUGE,
176
+ VELODROME_POSITION_MANGER,
177
+ tokenId
178
+ );
179
+ await pool.stakeInGauge(Dapp.VELODROMECL, USDC_WETH_CL_GAUGE, tokenId);
180
+ expect(await velodromePositionManager.ownerOf(tokenId)).toBe(
181
+ USDC_WETH_CL_GAUGE
198
182
  );
199
- const positionAfter = await velodromePositionManager.positions(tokenId);
200
- expect(positionAfter.liquidity.gt(positionBefore.liquidity));
201
183
  });
202
184
 
203
185
  it("collects fess of a staked CL position", async () => {
@@ -3,29 +3,6 @@ import { Network } from "../types";
3
3
  // eslint-disable-next-line @typescript-eslint/no-var-requires
4
4
  require("dotenv").config();
5
5
 
6
- // const provider = new ethers.providers.JsonRpcProvider(
7
- // `https://opt-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_PROJECT_ID}`
8
- // );
9
-
10
- // const provider = new ethers.providers.JsonRpcProvider(
11
- // `https://opt-kovan.g.alchemy.com/v2/${process.env.ALCHEMY_PROJECT_ID}`
12
- // );
13
-
14
- // const provider = new ethers.providers.JsonRpcProvider(
15
- // `https://arb-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_PROJECT_ID}`
16
- // );
17
-
18
- // const provider = new ethers.providers.JsonRpcProvider(
19
- // `https://polygon-mainnet.infura.io/v3/${process.env.INFURA_PROJECT_ID}`
20
- // );
21
-
22
- const provider = new ethers.providers.JsonRpcProvider("http://127.0.0.1:8545/");
23
-
24
- export const wallet = new ethers.Wallet(
25
- process.env.PRIVATE_KEY as string,
26
- provider
27
- );
28
-
29
6
  export const networkPortMap = {
30
7
  [Network.POLYGON]: 8542,
31
8
  [Network.OPTIMISM]: 8544,
@@ -34,16 +11,17 @@ export const networkPortMap = {
34
11
  };
35
12
 
36
13
  export const getWalletData = (
37
- network: Network
14
+ network: Network,
15
+ onFork = true
38
16
  ): {
39
17
  wallet: ethers.Wallet;
40
18
  provider: ethers.providers.JsonRpcProvider;
41
19
  rpcUrl: string;
42
20
  } => {
43
- const provider = new ethers.providers.JsonRpcProvider(
44
- `http://127.0.0.1:${networkPortMap[network]}/`
45
- );
46
- const rpcUrl = process.env[`${network.toUpperCase()}_URL`] || "";
21
+ const rpcUrl = onFork
22
+ ? `http://127.0.0.1:${networkPortMap[network]}/`
23
+ : process.env[`${network.toUpperCase()}_URL`] || "";
24
+ const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
47
25
  return {
48
26
  wallet: new ethers.Wallet(process.env.PRIVATE_KEY as string, provider),
49
27
  provider,
@@ -88,3 +88,8 @@ testingHelper({
88
88
  network: Network.BASE,
89
89
  testingRun: testZeroEx
90
90
  });
91
+
92
+ testingHelper({
93
+ network: Network.ARBITRUM,
94
+ testingRun: testZeroEx
95
+ });