@dhedge/v2-sdk 1.10.11 → 1.10.13

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/src/config.ts CHANGED
@@ -17,7 +17,8 @@ export const factoryAddress: AddressNetworkMap = {
17
17
  : "0xfdc7b8bFe0DD3513Cc669bB8d601Cb83e2F69cB0",
18
18
  [Network.OPTIMISM]: "0x5e61a079A178f0E5784107a4963baAe0c5a680c6",
19
19
  [Network.ARBITRUM]: "0xfffb5fb14606eb3a548c113026355020ddf27535",
20
- [Network.BASE]: "0x49Afe3abCf66CF09Fab86cb1139D8811C8afe56F"
20
+ [Network.BASE]: "0x49Afe3abCf66CF09Fab86cb1139D8811C8afe56F",
21
+ [Network.SONIC]: ""
21
22
  };
22
23
 
23
24
  export const routerAddress: AddressDappNetworkMap = {
@@ -31,7 +32,6 @@ export const routerAddress: AddressDappNetworkMap = {
31
32
  [Dapp.UNISWAPV3]: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
32
33
  [Dapp.ARRAKIS]: "0xc73fb100a995b33f9fa181d420f4c8d74506df66",
33
34
  [Dapp.TOROS]: "0x45b90480D6F643dE2f128db091A357C3c90399f2",
34
- [Dapp.ZEROEX]: "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
35
35
  [Dapp.ODOS]: "0x4e3288c9ca110bcc82bf38f09a7b425c095d92bf"
36
36
  },
37
37
  [Network.OPTIMISM]: {
@@ -44,7 +44,6 @@ export const routerAddress: AddressDappNetworkMap = {
44
44
  [Dapp.VELODROMEV2]: "0xa062ae8a9c5e11aaa026fc2670b0d65ccc8b2858",
45
45
  [Dapp.LYRA]: "0xCCE7819d65f348c64B7Beb205BA367b3fE33763B",
46
46
  [Dapp.ARRAKIS]: "0x9ce88a56d120300061593eF7AD074A1B710094d5",
47
- [Dapp.ZEROEX]: "0xdef1abe32c034e558cdd535791643c58a13acc10",
48
47
  [Dapp.ODOS]: "0xca423977156bb05b13a2ba3b76bc5419e2fe9680"
49
48
  },
50
49
  [Network.ARBITRUM]: {
@@ -53,17 +52,19 @@ export const routerAddress: AddressDappNetworkMap = {
53
52
  [Dapp.AAVEV3]: "0x794a61358D6845594F94dc1DB02A252b5b4814aD",
54
53
  [Dapp.BALANCER]: "0xBA12222222228d8Ba445958a75a0704d566BF2C8",
55
54
  [Dapp.RAMSES]: "0xaaa87963efeb6f7e0a2711f397663105acb1805e",
56
- [Dapp.ZEROEX]: "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
57
55
  [Dapp.TOROS]: "0xA5679C4272A056Bb83f039961fae7D99C48529F5",
58
56
  [Dapp.ODOS]: "0xa669e7A0d4b3e4Fa48af2dE86BD4CD7126Be4e13"
59
57
  },
60
58
  [Network.BASE]: {
61
59
  [Dapp.ONEINCH]: "0x111111125421ca6dc452d289314280a0f8842a65",
62
- [Dapp.ZEROEX]: "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
63
60
  [Dapp.AERODROME]: "0xcF77a3Ba9A5CA399B7c97c74d54e5b1Beb874E43",
64
61
  [Dapp.AAVEV3]: "0xA238Dd80C259a72e81d7e4664a9801593F98d1c5",
65
62
  [Dapp.TOROS]: "0xf067575Eb60c7587C11e867907AA7284833704d1",
66
63
  [Dapp.ODOS]: "0x19cEeAd7105607Cd444F5ad10dd51356436095a1"
64
+ },
65
+ [Network.SONIC]: {
66
+ [Dapp.AAVEV3]: "0x5362dBb1e601abF3a4c14c22ffEdA64042E5eAA3",
67
+ [Dapp.ODOS]: "0xaC041Df48dF9791B0654f1Dbbf2CC8450C5f2e9D"
67
68
  }
68
69
  };
69
70
 
@@ -74,7 +75,8 @@ export const dappFactoryAddress: AddressDappNetworkMap = {
74
75
  },
75
76
  [Network.OPTIMISM]: {},
76
77
  [Network.ARBITRUM]: {},
77
- [Network.BASE]: {}
78
+ [Network.BASE]: {},
79
+ [Network.SONIC]: {}
78
80
  };
79
81
 
80
82
  export const stakingAddress: AddressDappNetworkMap = {
@@ -94,7 +96,8 @@ export const stakingAddress: AddressDappNetworkMap = {
94
96
  },
95
97
  [Network.BASE]: {
96
98
  [Dapp.PANCAKECL]: "0xC6A2Db661D5a5690172d8eB0a7DEA2d3008665A3"
97
- }
99
+ },
100
+ [Network.SONIC]: {}
98
101
  };
99
102
 
100
103
  export const aaveAddressProvider: AddressDappNetworkMap = {
@@ -111,6 +114,9 @@ export const aaveAddressProvider: AddressDappNetworkMap = {
111
114
  [Network.BASE]: {
112
115
  // https://docs.aave.com/developers/deployed-contracts/v3-mainnet/base
113
116
  [Dapp.AAVEV3]: "0xe20fCBdBfFC4Dd138cE8b2E6FBb6CB49777ad64D"
117
+ },
118
+ [Network.SONIC]: {
119
+ [Dapp.AAVEV3]: "0x5C2e738F6E27bCE0F7558051Bf90605dD6176900"
114
120
  }
115
121
  };
116
122
  export const nonfungiblePositionManagerAddress: AddressDappNetworkMap = {
@@ -130,6 +136,9 @@ export const nonfungiblePositionManagerAddress: AddressDappNetworkMap = {
130
136
  [Dapp.UNISWAPV3]: "0x03a520b32C04BF3bEEf7BEb72E919cf822Ed34f1",
131
137
  [Dapp.AERODROMECL]: "0x827922686190790b37229fd06084350e74485b72",
132
138
  [Dapp.PANCAKECL]: "0x46A15B0b27311cedF172AB29E4f4766fbE7F4364"
139
+ },
140
+ [Network.SONIC]: {
141
+ [Dapp.SHADOWCL]: "0x12e66c8f215ddd5d48d150c8f46ad0c6fb0f4406"
133
142
  }
134
143
  };
135
144
 
@@ -137,7 +146,8 @@ export const networkChainIdMap: NetworkChainIdMap = {
137
146
  [Network.POLYGON]: 137,
138
147
  [Network.OPTIMISM]: 10,
139
148
  [Network.ARBITRUM]: 42161,
140
- [Network.BASE]: 8453
149
+ [Network.BASE]: 8453,
150
+ [Network.SONIC]: 146
141
151
  };
142
152
 
143
153
  export const balancerSubgraph: AddressNetworkMap = {
@@ -145,14 +155,16 @@ export const balancerSubgraph: AddressNetworkMap = {
145
155
  "https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-polygon-v2",
146
156
  [Network.OPTIMISM]: "",
147
157
  [Network.ARBITRUM]: "",
148
- [Network.BASE]: ""
158
+ [Network.BASE]: "",
159
+ [Network.SONIC]: ""
149
160
  };
150
161
 
151
162
  export const multiCallAddress: AddressNetworkMap = {
152
163
  [Network.POLYGON]: "0x275617327c958bD06b5D6b871E7f491D76113dd8",
153
164
  [Network.OPTIMISM]: "",
154
165
  [Network.ARBITRUM]: "",
155
- [Network.BASE]: ""
166
+ [Network.BASE]: "",
167
+ [Network.SONIC]: ""
156
168
  };
157
169
 
158
170
  export const lyraNetworkMap: LyraNetworkMap = {
@@ -63,7 +63,6 @@ import {
63
63
  getFuturesChangeMarginTxData
64
64
  } from "../services/futures";
65
65
  import { getFuturesCancelOrderTxData } from "../services/futures/trade";
66
- import { getZeroExTradeTxData } from "../services/zeroEx/zeroExTrade";
67
66
  import { getOneInchSwapTxData } from "../services/oneInch";
68
67
  import {
69
68
  getCreateVestTxData,
@@ -373,16 +372,6 @@ export class Pool {
373
372
  ): Promise<any> {
374
373
  let swapTxData: string;
375
374
  switch (dapp) {
376
- case Dapp.ZEROEX:
377
- swapTxData = await getZeroExTradeTxData(
378
- this.network,
379
- assetFrom,
380
- assetTo,
381
- amountIn,
382
- slippage,
383
- this.address
384
- );
385
- break;
386
375
  case Dapp.ONEINCH:
387
376
  ({ swapTxData } = await getOneInchSwapTxData(
388
377
  this,
@@ -1121,7 +1110,8 @@ export class Pool {
1121
1110
  | Dapp.VELODROMECL
1122
1111
  | Dapp.AERODROMECL
1123
1112
  | Dapp.RAMSESCL
1124
- | Dapp.PANCAKECL,
1113
+ | Dapp.PANCAKECL
1114
+ | Dapp.SHADOWCL,
1125
1115
  assetA: string,
1126
1116
  assetB: string,
1127
1117
  amountA: BigNumber | string,
@@ -1190,6 +1180,7 @@ export class Pool {
1190
1180
  switch (dapp) {
1191
1181
  case Dapp.UNISWAPV3:
1192
1182
  case Dapp.RAMSESCL:
1183
+ case Dapp.SHADOWCL:
1193
1184
  dappAddress = nonfungiblePositionManagerAddress[this.network][dapp];
1194
1185
  break;
1195
1186
  case Dapp.VELODROMECL:
@@ -1255,6 +1246,7 @@ export class Pool {
1255
1246
  switch (dapp) {
1256
1247
  case Dapp.UNISWAPV3:
1257
1248
  case Dapp.RAMSESCL:
1249
+ case Dapp.SHADOWCL:
1258
1250
  dappAddress = nonfungiblePositionManagerAddress[this.network][dapp];
1259
1251
  break;
1260
1252
  case Dapp.VELODROMECL:
@@ -1319,6 +1311,7 @@ export class Pool {
1319
1311
  switch (dapp) {
1320
1312
  case Dapp.UNISWAPV3:
1321
1313
  case Dapp.RAMSESCL:
1314
+ case Dapp.SHADOWCL:
1322
1315
  contractAddress = nonfungiblePositionManagerAddress[this.network][dapp];
1323
1316
  txData = iNonfungiblePositionManager.encodeFunctionData(
1324
1317
  Transaction.COLLECT,
@@ -19,6 +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 IShadowNonfungiblePositionManager from "../../abi/IShadowNonfungiblePositionManager.json";
22
23
  import IRamsesPositionManager from "../../abi/IRamsesNonfungiblePositionManager.json";
23
24
  import IArrakisV1RouterStaking from "../../abi/IArrakisV1RouterStaking.json";
24
25
  import IPancakeMasterChef from "../../abi/IPancakeMasterChefV3.json";
@@ -77,7 +78,8 @@ export async function getUniswapV3MintTxData(
77
78
  | Dapp.VELODROMECL
78
79
  | Dapp.AERODROMECL
79
80
  | Dapp.RAMSESCL
80
- | Dapp.PANCAKECL,
81
+ | Dapp.PANCAKECL
82
+ | Dapp.SHADOWCL,
81
83
  pool: Pool,
82
84
  assetA: string,
83
85
  assetB: string,
@@ -168,6 +170,12 @@ export async function getUniswapV3MintTxData(
168
170
  mintParams.push(0);
169
171
  }
170
172
 
173
+ if (dapp === Dapp.SHADOWCL) {
174
+ iNonfungiblePositionManager = new ethers.utils.Interface(
175
+ IShadowNonfungiblePositionManager
176
+ );
177
+ }
178
+
171
179
  return iNonfungiblePositionManager.encodeFunctionData(Transaction.MINT, [
172
180
  mintParams
173
181
  ]);
@@ -188,7 +196,9 @@ export async function getUniswapV3Liquidity(
188
196
  const iNonfungiblePositionManager = new ethers.Contract(
189
197
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
190
198
  nonfungiblePositionManagerAddress[pool.network][dapp]!,
191
- INonfungiblePositionManager.abi,
199
+ dapp === Dapp.SHADOWCL
200
+ ? IShadowNonfungiblePositionManager
201
+ : INonfungiblePositionManager.abi,
192
202
  pool.signer
193
203
  );
194
204
  const result = await iNonfungiblePositionManager.positions(tokenId);
@@ -208,7 +218,8 @@ export async function getIncreaseLiquidityTxData(
208
218
  dapp === Dapp.VELODROMECL ||
209
219
  dapp === Dapp.AERODROMECL ||
210
220
  dapp === Dapp.RAMSESCL ||
211
- dapp === Dapp.PANCAKECL
221
+ dapp === Dapp.PANCAKECL ||
222
+ dapp === Dapp.SHADOWCL
212
223
  ) {
213
224
  const abi = new ethers.utils.Interface(INonfungiblePositionManager.abi);
214
225
  txData = abi.encodeFunctionData(Transaction.INCREASE_LIQUIDITY, [
@@ -245,7 +256,8 @@ export async function getDecreaseLiquidityTxData(
245
256
  dapp === Dapp.VELODROMECL ||
246
257
  dapp === Dapp.AERODROMECL ||
247
258
  dapp === Dapp.RAMSESCL ||
248
- dapp === Dapp.PANCAKECL
259
+ dapp === Dapp.PANCAKECL ||
260
+ dapp === Dapp.SHADOWCL
249
261
  ) {
250
262
  const abi = new ethers.utils.Interface(INonfungiblePositionManager.abi);
251
263
  const liquidity = (await getUniswapV3Liquidity(dapp, tokenId, pool))
@@ -133,6 +133,25 @@ export const CONTRACT_ADDRESS = {
133
133
  VELO: "0x940181a94A35A4569E4529A3CDfB74e38FD98631",
134
134
  COMPOUNDV3_WETH: "",
135
135
  TOROS: ""
136
+ },
137
+ [Network.SONIC]: {
138
+ USDC: "0x29219dd400f2bf60e5a23d13be72b486d4038894",
139
+ USDT: "",
140
+ SUSD: "",
141
+ WETH: "0x50c42deacd8fc9773493ed674b675be577f2634b",
142
+ WBTC: "",
143
+ SWETH: "",
144
+ uniswapV3: {
145
+ nonfungiblePositionManager: ""
146
+ },
147
+ //
148
+ ARRAKIS_USDC_WETH_GAUGE: "",
149
+ ARRAKIS_USDC_WETH_LP: "",
150
+ WMATIC: "",
151
+ VELODROME_CL_USDC_WETH_GAUGE: "",
152
+ VELO: "",
153
+ COMPOUNDV3_WETH: "",
154
+ TOROS: ""
136
155
  }
137
156
  };
138
157
 
@@ -142,12 +161,14 @@ export const USDC_BALANCEOF_SLOT = {
142
161
  [Network.OPTIMISM]: 9,
143
162
  [Network.ARBITRUM]: 9,
144
163
  [Network.POLYGON]: 0,
145
- [Network.BASE]: 9
164
+ [Network.BASE]: 9,
165
+ [Network.SONIC]: 9
146
166
  };
147
167
 
148
168
  export const WETH_BALANCEOF_SLOT = {
149
169
  [Network.OPTIMISM]: 3,
150
170
  [Network.ARBITRUM]: 51,
151
171
  [Network.POLYGON]: 0,
152
- [Network.BASE]: 0
172
+ [Network.BASE]: 0,
173
+ [Network.SONIC]: 0
153
174
  };
@@ -7,7 +7,8 @@ export const networkPortMap = {
7
7
  [Network.POLYGON]: 8542,
8
8
  [Network.OPTIMISM]: 8544,
9
9
  [Network.ARBITRUM]: 8540,
10
- [Network.BASE]: 8546
10
+ [Network.BASE]: 8546,
11
+ [Network.SONIC]: 8547
11
12
  };
12
13
 
13
14
  export const getWalletData = (
package/src/types.ts CHANGED
@@ -5,7 +5,8 @@ export enum Network {
5
5
  POLYGON = "polygon",
6
6
  OPTIMISM = "optimism",
7
7
  ARBITRUM = "arbitrum",
8
- BASE = "base"
8
+ BASE = "base",
9
+ SONIC = "sonic"
9
10
  }
10
11
 
11
12
  export enum Dapp {
@@ -23,14 +24,14 @@ export enum Dapp {
23
24
  VELODROMEV2 = "velodromeV2",
24
25
  VELODROMECL = "velodromeCL",
25
26
  LYRA = "lyra",
26
- ZEROEX = "0x",
27
27
  RAMSES = "ramses",
28
28
  AERODROME = "aerodrome",
29
29
  AERODROMECL = "aerodromeCL",
30
30
  RAMSESCL = "ramsesCL",
31
31
  PANCAKECL = "pancakeCL",
32
32
  COMPOUNDV3 = "compoundV3",
33
- ODOS = "odos"
33
+ ODOS = "odos",
34
+ SHADOWCL = "shadowCL"
34
35
  }
35
36
 
36
37
  export enum Transaction {
@@ -1,3 +0,0 @@
1
- import { BigNumber } from "ethers";
2
- import { Network } from "../../types";
3
- export declare const getZeroExTradeTxData: (network: Network, assetFrom: string, assetTo: string, amountIn: BigNumber | string, slippage: number | undefined, takerAddress: string) => Promise<string>;
@@ -1,52 +0,0 @@
1
- import axios from "axios";
2
- import { BigNumber } from "ethers";
3
- import { Network } from "../../types";
4
- import { ApiError } from "../../errors";
5
-
6
- // slippage of 0x is different from that of 1Inch
7
- // in 0x, e.g. 0.03 for 3% slippage allowed
8
- // 1inch slippage 0.5% represented by 0.5
9
- // 0x slippage 0.5% represented by 0.005
10
- const getZeroExSlippage = (slippage: number): number => {
11
- return Number(slippage) / 100;
12
- };
13
-
14
- export const getZeroExTradeTxData = async (
15
- network: Network,
16
- assetFrom: string,
17
- assetTo: string,
18
- amountIn: BigNumber | string,
19
- slippage = 0.5,
20
- takerAddress: string
21
- ): Promise<string> => {
22
- if (!process.env.ZEROEX_API_KEY)
23
- throw new Error("ZEROEX_API_KEY not configured in .env file");
24
- try {
25
- const slippagePercentage = getZeroExSlippage(slippage);
26
- const params = {
27
- buyToken: assetTo,
28
- sellToken: assetFrom,
29
- sellAmount: amountIn.toString(),
30
- // necessary to skip quote validation is that in which the takerAddress refers to a smart contract
31
- skipValidation: true,
32
- // Used to enable RFQ-T liquidity
33
- intentOnFilling: true,
34
- takerAddress,
35
- slippagePercentage
36
- // excludedSourcesParam
37
- };
38
- const response = await axios.get(
39
- `https://${network}.api.0x.org/swap/v1/quote`,
40
- {
41
- params,
42
- headers: {
43
- "0x-api-key": process.env.ZEROEX_API_KEY
44
- }
45
- }
46
- );
47
-
48
- return response.data.data;
49
- } catch (e) {
50
- throw new ApiError("Swap api request of 0x failed");
51
- }
52
- };
@@ -1,95 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
- import BigNumber from "bignumber.js";
3
- import { Dhedge, Pool } from "..";
4
- import { routerAddress } from "../config";
5
- import { Dapp, Network } from "../types";
6
- import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
7
- import {
8
- TestingRunParams,
9
- setUSDCAmount,
10
- testingHelper
11
- } from "./utils/testingHelper";
12
- import { allowanceDelta, balanceDelta } from "./utils/token";
13
- import { getTxOptions } from "./txOptions";
14
-
15
- const testZeroEx = ({ wallet, network, provider }: TestingRunParams) => {
16
- const USDC = CONTRACT_ADDRESS[network].USDC;
17
- const WETH = CONTRACT_ADDRESS[network].WETH;
18
-
19
- let dhedge: Dhedge;
20
- let pool: Pool;
21
- jest.setTimeout(100000);
22
-
23
- describe(`[${network}] 0x trade`, () => {
24
- beforeAll(async () => {
25
- dhedge = new Dhedge(wallet, network);
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
- });
40
- });
41
-
42
- it("approves unlimited USDC on 0x", async () => {
43
- await pool.approve(
44
- Dapp.ZEROEX,
45
- USDC,
46
- MAX_AMOUNT,
47
- await getTxOptions(network)
48
- );
49
- const usdcAllowanceDelta = await allowanceDelta(
50
- pool.address,
51
- USDC,
52
- routerAddress[network]["0x"]!,
53
- pool.signer
54
- );
55
- await expect(usdcAllowanceDelta.gt(0));
56
- });
57
-
58
- it("trades 2 USDC into WETH on 0x", async () => {
59
- await pool.trade(
60
- Dapp.ZEROEX,
61
- USDC,
62
- WETH,
63
- "2000000",
64
- 0.5,
65
- await getTxOptions(network)
66
- );
67
- const wethBalanceDelta = await balanceDelta(
68
- pool.address,
69
- WETH,
70
- pool.signer
71
- );
72
- expect(wethBalanceDelta.gt(0));
73
- });
74
- });
75
- };
76
-
77
- testingHelper({
78
- network: Network.OPTIMISM,
79
- testingRun: testZeroEx
80
- });
81
-
82
- testingHelper({
83
- network: Network.POLYGON,
84
- testingRun: testZeroEx
85
- });
86
-
87
- testingHelper({
88
- network: Network.BASE,
89
- testingRun: testZeroEx
90
- });
91
-
92
- testingHelper({
93
- network: Network.ARBITRUM,
94
- testingRun: testZeroEx
95
- });