@dhedge/v2-sdk 1.9.4 → 1.9.5

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.9.4",
3
+ "version": "1.9.5",
4
4
  "license": "MIT",
5
5
  "description": "🛠 An SDK for building applications on top of dHEDGE V2",
6
6
  "main": "dist/index.js",
@@ -22,7 +22,8 @@
22
22
  "analyze": "size-limit --why",
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
- "fork:arbitrum": "hardhat node --port 8540 --fork $(grep ARBITRUM_URL .env | cut -d '=' -f2)"
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
27
  },
27
28
  "husky": {
28
29
  "hooks": {
package/src/config.ts CHANGED
@@ -16,7 +16,8 @@ export const factoryAddress: AddressNetworkMap = {
16
16
  ? "0xDd87eCdB10cFF7004276AAbAbd30e7a08F69bb53"
17
17
  : "0xfdc7b8bFe0DD3513Cc669bB8d601Cb83e2F69cB0",
18
18
  [Network.OPTIMISM]: "0x5e61a079A178f0E5784107a4963baAe0c5a680c6",
19
- [Network.ARBITRUM]: "0xfffb5fb14606eb3a548c113026355020ddf27535"
19
+ [Network.ARBITRUM]: "0xfffb5fb14606eb3a548c113026355020ddf27535",
20
+ [Network.BASE]: "0x49Afe3abCf66CF09Fab86cb1139D8811C8afe56F"
20
21
  };
21
22
 
22
23
  export const routerAddress: AddressDappNetworkMap = {
@@ -50,6 +51,10 @@ export const routerAddress: AddressDappNetworkMap = {
50
51
  [Dapp.AAVEV3]: "0x794a61358D6845594F94dc1DB02A252b5b4814aD",
51
52
  [Dapp.BALANCER]: "0xBA12222222228d8Ba445958a75a0704d566BF2C8",
52
53
  [Dapp.RAMSES]: "0xaaa87963efeb6f7e0a2711f397663105acb1805e"
54
+ },
55
+ [Network.BASE]: {
56
+ [Dapp.ONEINCH]: "0x1111111254EEB25477B68fb85Ed929f73A960582",
57
+ [Dapp.ZEROEX]: "0xdef1c0ded9bec7f1a1670819833240f027b25eff"
53
58
  }
54
59
  };
55
60
 
@@ -59,7 +64,8 @@ export const dappFactoryAddress: AddressDappNetworkMap = {
59
64
  [Dapp.QUICKSWAP]: "0x5757371414417b8C6CAad45bAeF941aBc7d3Ab32"
60
65
  },
61
66
  [Network.OPTIMISM]: {},
62
- [Network.ARBITRUM]: {}
67
+ [Network.ARBITRUM]: {},
68
+ [Network.BASE]: {}
63
69
  };
64
70
 
65
71
  export const stakingAddress: AddressDappNetworkMap = {
@@ -70,7 +76,8 @@ export const stakingAddress: AddressDappNetworkMap = {
70
76
  [Dapp.AAVEV3]: "0x929EC64c34a17401F460460D4B9390518E5B473e"
71
77
  },
72
78
  [Network.OPTIMISM]: {},
73
- [Network.ARBITRUM]: {}
79
+ [Network.ARBITRUM]: {},
80
+ [Network.BASE]: {}
74
81
  };
75
82
 
76
83
  export const aaveAddressProvider: AddressDappNetworkMap = {
@@ -83,31 +90,40 @@ export const aaveAddressProvider: AddressDappNetworkMap = {
83
90
  },
84
91
  [Network.ARBITRUM]: {
85
92
  [Dapp.AAVEV3]: "0xa97684ead0e402dc232d5a977953df7ecbab3cdb"
93
+ },
94
+ [Network.BASE]: {
95
+ // https://docs.aave.com/developers/deployed-contracts/v3-mainnet/base
96
+ [Dapp.AAVEV3]: "0xe20fCBdBfFC4Dd138cE8b2E6FBb6CB49777ad64D"
86
97
  }
87
98
  };
88
99
  export const nonfungiblePositionManagerAddress: AddressNetworkMap = {
89
100
  [Network.POLYGON]: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88",
90
101
  [Network.OPTIMISM]: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88",
91
- [Network.ARBITRUM]: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88"
102
+ [Network.ARBITRUM]: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88",
103
+ // https://docs.uniswap.org/contracts/v3/reference/deployments
104
+ [Network.BASE]: "0x03a520b32C04BF3bEEf7BEb72E919cf822Ed34f1"
92
105
  };
93
106
 
94
107
  export const networkChainIdMap: NetworkChainIdMap = {
95
108
  [Network.POLYGON]: 137,
96
109
  [Network.OPTIMISM]: 10,
97
- [Network.ARBITRUM]: 42161
110
+ [Network.ARBITRUM]: 42161,
111
+ [Network.BASE]: 8453
98
112
  };
99
113
 
100
114
  export const balancerSubgraph: AddressNetworkMap = {
101
115
  [Network.POLYGON]:
102
116
  "https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-polygon-v2",
103
117
  [Network.OPTIMISM]: "",
104
- [Network.ARBITRUM]: ""
118
+ [Network.ARBITRUM]: "",
119
+ [Network.BASE]: ""
105
120
  };
106
121
 
107
122
  export const multiCallAddress: AddressNetworkMap = {
108
123
  [Network.POLYGON]: "0x275617327c958bD06b5D6b871E7f491D76113dd8",
109
124
  [Network.OPTIMISM]: "",
110
- [Network.ARBITRUM]: ""
125
+ [Network.ARBITRUM]: "",
126
+ [Network.BASE]: ""
111
127
  };
112
128
 
113
129
  export const lyraNetworkMap: LyraNetworkMap = {
@@ -41,7 +41,8 @@ export const KWENTA_ETH_PERP_V2 = "0x2b3bb4c683bfc5239b029131eef3b1d214478d93";
41
41
  export const TEST_POOL = {
42
42
  [Network.POLYGON]: "0x699fd4d6eadb216704c7e355cfa0a12f51813163",
43
43
  [Network.OPTIMISM]: "0x12573bfdf764ab9d52aca20e2827497a66829716",
44
- [Network.ARBITRUM]: "0x2dc2f936c8b6619facc69355d65dd93d2f4cc2bd"
44
+ [Network.ARBITRUM]: "0x2dc2f936c8b6619facc69355d65dd93d2f4cc2bd",
45
+ [Network.BASE]: "0x4842b42F68524383F609aa46eAfc18c1459cE3cD"
45
46
  };
46
47
 
47
48
  export const CONTRACT_ADDRESS = {
@@ -69,7 +70,20 @@ export const CONTRACT_ADDRESS = {
69
70
  WSTETH: "0x5979d7b546e38e414f7e9822514be443a4800529",
70
71
  BALANCER_WSTETH_WETH_POOL: "0x36bf227d6bac96e2ab1ebb5492ecec69c691943f",
71
72
  BALANCER_WSTETH_WETH_GAUGE: "0x251e51b25afa40f2b6b9f05aaf1bc7eaa0551771"
73
+ },
74
+ [Network.BASE]: {
75
+ USDC: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
76
+ WETH: "0x4200000000000000000000000000000000000006",
77
+ WBTC: "",
78
+ SWETH: ""
72
79
  }
73
80
  };
74
81
 
75
82
  export const MAX_AMOUNT = ethers.constants.MaxUint256;
83
+
84
+ export const USDC_BALANCEOF_SLOT = {
85
+ [Network.OPTIMISM]: 0,
86
+ [Network.ARBITRUM]: 9,
87
+ [Network.POLYGON]: 0,
88
+ [Network.BASE]: 9
89
+ };
@@ -6,6 +6,7 @@ import { getTxOptions } from "./txOptions";
6
6
  import { wallet } from "./wallet";
7
7
 
8
8
  jest.setTimeout(100000);
9
+ const TEST_POOL_OP = TEST_POOL.optimism;
9
10
 
10
11
  describe("pool", () => {
11
12
  let dhedge: Dhedge;
@@ -16,7 +17,7 @@ describe("pool", () => {
16
17
 
17
18
  it("buys 0.1 1400 calls with expiry October 28th", async () => {
18
19
  let result;
19
- const pool = await dhedge.loadPool(TEST_POOL);
20
+ const pool = await dhedge.loadPool(TEST_POOL_OP);
20
21
  try {
21
22
  result = await pool.tradeLyraOption(
22
23
  "eth",
@@ -37,7 +38,7 @@ describe("pool", () => {
37
38
 
38
39
  it("adds 0.05 1400 calls with expiry October 28th", async () => {
39
40
  let result;
40
- const pool = await dhedge.loadPool(TEST_POOL);
41
+ const pool = await dhedge.loadPool(TEST_POOL_OP);
41
42
  try {
42
43
  result = await pool.tradeLyraOption(
43
44
  "eth",
@@ -61,7 +62,7 @@ describe("pool", () => {
61
62
 
62
63
  it("sells 0.1 1300 Covered Call with expiry October 28th", async () => {
63
64
  let result;
64
- const pool = await dhedge.loadPool(TEST_POOL);
65
+ const pool = await dhedge.loadPool(TEST_POOL_OP);
65
66
  try {
66
67
  result = await pool.tradeLyraOption(
67
68
  "eth",
@@ -86,7 +87,7 @@ describe("pool", () => {
86
87
 
87
88
  it("adds 0.05 1300 Covered Call with expiry October 28th", async () => {
88
89
  let result;
89
- const pool = await dhedge.loadPool(TEST_POOL);
90
+ const pool = await dhedge.loadPool(TEST_POOL_OP);
90
91
  try {
91
92
  result = await pool.tradeLyraOption(
92
93
  "eth",
@@ -113,7 +114,7 @@ describe("pool", () => {
113
114
 
114
115
  it("closes all 0.15 1300 Covered Call with expiry October 28th", async () => {
115
116
  let result;
116
- const pool = await dhedge.loadPool(TEST_POOL);
117
+ const pool = await dhedge.loadPool(TEST_POOL_OP);
117
118
  try {
118
119
  result = await pool.tradeLyraOption(
119
120
  "eth",
@@ -138,7 +139,7 @@ describe("pool", () => {
138
139
 
139
140
  it("closes all 0.15 1400 Calls with expiry October 28th", async () => {
140
141
  let result;
141
- const pool = await dhedge.loadPool(TEST_POOL);
142
+ const pool = await dhedge.loadPool(TEST_POOL_OP);
142
143
  try {
143
144
  result = await pool.tradeLyraOption(
144
145
  "eth",
@@ -1,12 +1,18 @@
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
6
  import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
6
- import { TestingRunParams, testingHelper } from "./utils/testingHelper";
7
+ import {
8
+ TestingRunParams,
9
+ setUSDCAmount,
10
+ testingHelper
11
+ } from "./utils/testingHelper";
7
12
  import { allowanceDelta, balanceDelta } from "./utils/token";
13
+ import { getTxOptions } from "./txOptions";
8
14
 
9
- const testOneInch = ({ wallet, network }: TestingRunParams) => {
15
+ const testOneInch = ({ wallet, network, provider }: TestingRunParams) => {
10
16
  const USDC = CONTRACT_ADDRESS[network].USDC;
11
17
  const WETH = CONTRACT_ADDRESS[network].WETH;
12
18
 
@@ -18,6 +24,19 @@ const testOneInch = ({ wallet, network }: TestingRunParams) => {
18
24
  beforeAll(async () => {
19
25
  dhedge = new Dhedge(wallet, network);
20
26
  pool = await dhedge.loadPool(TEST_POOL[network]);
27
+ // top up gas
28
+ await provider.send("hardhat_setBalance", [
29
+ wallet.address,
30
+ "0x10000000000000000"
31
+ ]);
32
+ await provider.send("evm_mine", []);
33
+ // top up USDC
34
+ await setUSDCAmount({
35
+ amount: new BigNumber(100).times(1e18).toFixed(0),
36
+ userAddress: pool.address,
37
+ network,
38
+ provider
39
+ });
21
40
  });
22
41
 
23
42
  it("approves unlimited USDC on 1Inch", async () => {
@@ -32,7 +51,14 @@ const testOneInch = ({ wallet, network }: TestingRunParams) => {
32
51
  });
33
52
 
34
53
  it("trades 2 USDC into WETH on 1Inch", async () => {
35
- await pool.trade(Dapp.ONEINCH, USDC, WETH, "2000000", 0.5);
54
+ await pool.trade(
55
+ Dapp.ONEINCH,
56
+ USDC,
57
+ WETH,
58
+ "2000000",
59
+ 0.5,
60
+ await getTxOptions(network)
61
+ );
36
62
  const wethBalanceDelta = await balanceDelta(
37
63
  pool.address,
38
64
  WETH,
@@ -52,3 +78,8 @@ testingHelper({
52
78
  network: Network.POLYGON,
53
79
  testingRun: testOneInch
54
80
  });
81
+
82
+ testingHelper({
83
+ network: Network.BASE,
84
+ testingRun: testOneInch
85
+ });
@@ -6,6 +6,8 @@ import { TEST_POOL } from "./constants";
6
6
 
7
7
  import { wallet } from "./wallet";
8
8
 
9
+ const TEST_POOL_OP = TEST_POOL.optimism;
10
+
9
11
  let dhedge: Dhedge;
10
12
  let options: any;
11
13
  jest.setTimeout(100000);
@@ -18,7 +20,7 @@ describe("pool", () => {
18
20
  });
19
21
 
20
22
  it("should swap sETH into sUSD on Synthetix", async () => {
21
- const pool = await dhedge.loadPool(TEST_POOL);
23
+ const pool = await dhedge.loadPool(TEST_POOL_OP);
22
24
  const result = await pool.trade(
23
25
  Dapp.SYNTHETIX,
24
26
  "sETH",
@@ -5,156 +5,188 @@ import { routerAddress } from "../config";
5
5
  import { Dapp, Network } from "../types";
6
6
  import { CONTRACT_ADDRESS, TEST_POOL } from "./constants";
7
7
  import { allowanceDelta, balanceDelta } from "./utils/token";
8
-
9
- import { wallet } from "./wallet";
10
-
11
- let dhedge: Dhedge;
12
- let pool: Pool;
13
- jest.setTimeout(100000);
14
-
15
- const network = Network.POLYGON;
16
-
17
- describe("pool", () => {
18
- beforeAll(async () => {
19
- dhedge = new Dhedge(wallet, network);
20
- pool = await dhedge.loadPool(TEST_POOL[network]);
8
+ import {
9
+ setUSDCAmount,
10
+ testingHelper,
11
+ TestingRunParams
12
+ } from "./utils/testingHelper";
13
+ import BigNumber from "bignumber.js";
14
+
15
+ const testUniswapV3 = ({ wallet, network, provider }: TestingRunParams) => {
16
+ let dhedge: Dhedge;
17
+ let pool: Pool;
18
+
19
+ jest.setTimeout(100000);
20
+ describe(`testUniswapV3 on ${network}`, () => {
21
+ beforeAll(async () => {
22
+ dhedge = new Dhedge(wallet, network);
23
+ pool = await dhedge.loadPool(TEST_POOL[network]);
24
+
25
+ // top up gas
26
+ await provider.send("hardhat_setBalance", [
27
+ wallet.address,
28
+ "0x10000000000000000"
29
+ ]);
30
+ await provider.send("evm_mine", []);
31
+ await setUSDCAmount({
32
+ amount: new BigNumber(100).times(1e18).toFixed(0),
33
+ userAddress: pool.address,
34
+ network,
35
+ provider
36
+ });
37
+ });
38
+
39
+ it("approves unlimited USDC on for trading on UniswapV3", async () => {
40
+ await pool.approve(
41
+ Dapp.UNISWAPV3,
42
+ CONTRACT_ADDRESS[network].USDC,
43
+ ethers.constants.MaxUint256
44
+ );
45
+ const UsdcAllowanceDelta = await allowanceDelta(
46
+ pool.address,
47
+ CONTRACT_ADDRESS[network].USDC,
48
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
49
+ routerAddress[network].uniswapV3!,
50
+ pool.signer
51
+ );
52
+ expect(UsdcAllowanceDelta.gte(0));
53
+ });
54
+
55
+ it("should swap 5 USDC into WETH on UniswapV3", async () => {
56
+ await pool.tradeUniswapV3(
57
+ CONTRACT_ADDRESS[network].USDC,
58
+ CONTRACT_ADDRESS[network].WETH,
59
+ "5000000",
60
+ FeeAmount.LOW,
61
+ 0.5
62
+ );
63
+
64
+ const wethAllowanceDelta = await balanceDelta(
65
+ pool.address,
66
+ CONTRACT_ADDRESS[network].WETH,
67
+ pool.signer
68
+ );
69
+ expect(wethAllowanceDelta.gt(0));
70
+ });
71
+
72
+ // it("approves unlimited WETH on for UniswapV3 LP", async () => {
73
+ // await pool.approveUniswapV3Liquidity(
74
+ // CONTRACT_ADDRESS[network].USDC,
75
+ // ethers.constants.MaxInt256
76
+ // );
77
+ // const UsdcAllowanceDelta = await allowanceDelta(
78
+ // pool.address,
79
+ // CONTRACT_ADDRESS[network].USDC,
80
+ // pool.address,
81
+ // pool.signer
82
+ // );
83
+
84
+ // expect(result).not.toBe(null);
85
+ // });
86
+
87
+ // it("adds WETH and WBTC to a new V3 pool", async () => {
88
+ // let result;
89
+ // const pool = await dhedge.loadPool(TEST_POOL);
90
+ // const usdcBalance = await dhedge.utils.getBalance(USDC, pool.address);
91
+ // const wethBalance = await dhedge.utils.getBalance(WETH, pool.address);
92
+
93
+ // try {
94
+ // result = await pool.addLiquidityUniswapV3(
95
+ // USDC,
96
+ // WETH,
97
+ // usdcBalance,
98
+ // wethBalance,
99
+ // 0.0003,
100
+ // 0.0004,
101
+ // null,
102
+ // null,
103
+ // FeeAmount.LOW,
104
+ // options
105
+ // );
106
+ // console.log(result);
107
+ // } catch (e) {
108
+ // console.log(e);
109
+ // }
110
+ // expect(result).not.toBe(null);
111
+ // });
112
+
113
+ // it("should remove liquidity from an existing pool ", async () => {
114
+ // const pool = await dhedge.loadPool(TEST_POOL);
115
+ // const result = await pool.decreaseLiquidity(
116
+ // Dapp.UNISWAPV3,
117
+ // "110507",
118
+ // 100,
119
+ // options
120
+ // );
121
+ // console.log("result", result);
122
+ // expect(result).not.toBe(null);
123
+ // });
124
+
125
+ // it("should increase liquidity in an existing pool WETH/WBTC pool", async () => {
126
+ // const pool = await dhedge.loadPool(TEST_POOL);
127
+ // const result = await pool.increaseLiquidity(
128
+ // Dapp.UNISWAPV3,
129
+ // "110507",
130
+ // "244838",
131
+ // "258300000000000",
132
+ // options
133
+ // );
134
+ // console.log("result", result);
135
+ // expect(result).not.toBe(null);
136
+ // });
137
+
138
+ // it("should claim fees an existing pool", async () => {
139
+ // const pool = await dhedge.loadPool(TEST_POOL);
140
+ // const result = await pool.claimFeesUniswapV3("54929", options);
141
+ // console.log("result", result);
142
+ // expect(result).not.toBe(null);
143
+ // });
144
+
145
+ // it("approves unlimited USDC to swap on UniswapV3", async () => {
146
+ // let result;
147
+ // const pool = await dhedge.loadPool(TEST_POOL);
148
+ // try {
149
+ // result = await pool.approve(
150
+ // Dapp.UNISWAPV3,
151
+ // USDC,
152
+ // ethers.constants.MaxInt256,
153
+ // options
154
+ // );
155
+ // console.log(result);
156
+ // } catch (e) {
157
+ // console.log(e);
158
+ // }
159
+ // expect(result).not.toBe(null);
160
+ // });
161
+
162
+ // it("should swap USDC into WETH on UniswapV3 pool", async () => {
163
+ // const pool = await dhedge.loadPool(TEST_POOL);
164
+ // const result = await pool.tradeUniswapV3(
165
+ // USDC,
166
+ // WETH,
167
+ // "1000000",
168
+ // FeeAmount.LOW,
169
+ // 1,
170
+ // options
171
+ // );
172
+
173
+ // console.log(result);
174
+ // expect(result).not.toBe(null);
175
+ // });
21
176
  });
177
+ };
22
178
 
23
- it("approves unlimited USDC on for trading on UniswapV3", async () => {
24
- await pool.approve(
25
- Dapp.UNISWAPV3,
26
- CONTRACT_ADDRESS[network].USDC,
27
- ethers.constants.MaxUint256
28
- );
29
- const UsdcAllowanceDelta = await allowanceDelta(
30
- pool.address,
31
- CONTRACT_ADDRESS[network].USDC,
32
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
33
- routerAddress[network].uniswapV3!,
34
- pool.signer
35
- );
36
- expect(UsdcAllowanceDelta.gte(0));
37
- });
179
+ testingHelper({
180
+ network: Network.OPTIMISM,
181
+ testingRun: testUniswapV3
182
+ });
38
183
 
39
- it("should swap 5 USDC into WETH on UniswapV3", async () => {
40
- await pool.tradeUniswapV3(
41
- CONTRACT_ADDRESS[network].USDC,
42
- CONTRACT_ADDRESS[network].WETH,
43
- "5000000",
44
- FeeAmount.LOW,
45
- 0.5
46
- );
47
-
48
- const wethAllowanceDelta = await balanceDelta(
49
- pool.address,
50
- CONTRACT_ADDRESS[network].WETH,
51
- pool.signer
52
- );
53
- expect(wethAllowanceDelta.gt(0));
54
- });
184
+ testingHelper({
185
+ network: Network.POLYGON,
186
+ testingRun: testUniswapV3
187
+ });
55
188
 
56
- // it("approves unlimited WETH on for UniswapV3 LP", async () => {
57
- // await pool.approveUniswapV3Liquidity(
58
- // CONTRACT_ADDRESS[network].USDC,
59
- // ethers.constants.MaxInt256
60
- // );
61
- // const UsdcAllowanceDelta = await allowanceDelta(
62
- // pool.address,
63
- // CONTRACT_ADDRESS[network].USDC,
64
- // pool.address,
65
- // pool.signer
66
- // );
67
-
68
- // expect(result).not.toBe(null);
69
- // });
70
-
71
- // it("adds WETH and WBTC to a new V3 pool", async () => {
72
- // let result;
73
- // const pool = await dhedge.loadPool(TEST_POOL);
74
- // const usdcBalance = await dhedge.utils.getBalance(USDC, pool.address);
75
- // const wethBalance = await dhedge.utils.getBalance(WETH, pool.address);
76
-
77
- // try {
78
- // result = await pool.addLiquidityUniswapV3(
79
- // USDC,
80
- // WETH,
81
- // usdcBalance,
82
- // wethBalance,
83
- // 0.0003,
84
- // 0.0004,
85
- // null,
86
- // null,
87
- // FeeAmount.LOW,
88
- // options
89
- // );
90
- // console.log(result);
91
- // } catch (e) {
92
- // console.log(e);
93
- // }
94
- // expect(result).not.toBe(null);
95
- // });
96
-
97
- // it("should remove liquidity from an existing pool ", async () => {
98
- // const pool = await dhedge.loadPool(TEST_POOL);
99
- // const result = await pool.decreaseLiquidity(
100
- // Dapp.UNISWAPV3,
101
- // "110507",
102
- // 100,
103
- // options
104
- // );
105
- // console.log("result", result);
106
- // expect(result).not.toBe(null);
107
- // });
108
-
109
- // it("should increase liquidity in an existing pool WETH/WBTC pool", async () => {
110
- // const pool = await dhedge.loadPool(TEST_POOL);
111
- // const result = await pool.increaseLiquidity(
112
- // Dapp.UNISWAPV3,
113
- // "110507",
114
- // "244838",
115
- // "258300000000000",
116
- // options
117
- // );
118
- // console.log("result", result);
119
- // expect(result).not.toBe(null);
120
- // });
121
-
122
- // it("should claim fees an existing pool", async () => {
123
- // const pool = await dhedge.loadPool(TEST_POOL);
124
- // const result = await pool.claimFeesUniswapV3("54929", options);
125
- // console.log("result", result);
126
- // expect(result).not.toBe(null);
127
- // });
128
-
129
- // it("approves unlimited USDC to swap on UniswapV3", async () => {
130
- // let result;
131
- // const pool = await dhedge.loadPool(TEST_POOL);
132
- // try {
133
- // result = await pool.approve(
134
- // Dapp.UNISWAPV3,
135
- // USDC,
136
- // ethers.constants.MaxInt256,
137
- // options
138
- // );
139
- // console.log(result);
140
- // } catch (e) {
141
- // console.log(e);
142
- // }
143
- // expect(result).not.toBe(null);
144
- // });
145
-
146
- // it("should swap USDC into WETH on UniswapV3 pool", async () => {
147
- // const pool = await dhedge.loadPool(TEST_POOL);
148
- // const result = await pool.tradeUniswapV3(
149
- // USDC,
150
- // WETH,
151
- // "1000000",
152
- // FeeAmount.LOW,
153
- // 1,
154
- // options
155
- // );
156
-
157
- // console.log(result);
158
- // expect(result).not.toBe(null);
159
- // });
189
+ testingHelper({
190
+ network: Network.BASE,
191
+ testingRun: testUniswapV3
160
192
  });
@@ -1,6 +1,7 @@
1
- import { ethers } from "ethers";
1
+ import { BigNumber, ethers } from "ethers";
2
2
  import { Network } from "../../types";
3
3
  import { getWalletData } from "../wallet";
4
+ import { CONTRACT_ADDRESS, USDC_BALANCEOF_SLOT } from "../constants";
4
5
 
5
6
  export type TestingRunParams = {
6
7
  network: Network;
@@ -40,3 +41,52 @@ export const beforeAfterReset = ({
40
41
  await provider.send("evm_mine", []);
41
42
  });
42
43
  };
44
+
45
+ export const setTokenAmount = async ({
46
+ amount,
47
+ userAddress,
48
+ tokenAddress,
49
+ slot,
50
+ provider
51
+ }: {
52
+ amount: string;
53
+ userAddress: string;
54
+ tokenAddress: string;
55
+ slot: number;
56
+ provider: ethers.providers.JsonRpcProvider;
57
+ }): Promise<void> => {
58
+ const toBytes32 = (bn: string) => {
59
+ return ethers.utils.hexlify(
60
+ ethers.utils.zeroPad(BigNumber.from(bn).toHexString(), 32)
61
+ );
62
+ };
63
+ const index = ethers.utils.solidityKeccak256(
64
+ ["uint256", "uint256"],
65
+ [userAddress, slot] // key, slot
66
+ );
67
+ await provider.send("hardhat_setStorageAt", [
68
+ tokenAddress,
69
+ index,
70
+ toBytes32(amount).toString()
71
+ ]);
72
+ await provider.send("evm_mine", []);
73
+ };
74
+ export const setUSDCAmount = async ({
75
+ provider,
76
+ userAddress,
77
+ amount,
78
+ network
79
+ }: {
80
+ amount: string;
81
+ userAddress: string;
82
+ provider: ethers.providers.JsonRpcProvider;
83
+ network: Network;
84
+ }): Promise<void> => {
85
+ await setTokenAmount({
86
+ amount,
87
+ userAddress,
88
+ provider,
89
+ tokenAddress: CONTRACT_ADDRESS[network].USDC,
90
+ slot: USDC_BALANCEOF_SLOT[network]
91
+ });
92
+ };
@@ -29,7 +29,8 @@ export const wallet = new ethers.Wallet(
29
29
  export const networkPortMap = {
30
30
  [Network.POLYGON]: 8542,
31
31
  [Network.OPTIMISM]: 8544,
32
- [Network.ARBITRUM]: 8540
32
+ [Network.ARBITRUM]: 8540,
33
+ [Network.BASE]: 8546
33
34
  };
34
35
 
35
36
  export const getWalletData = (