@dhedge/v2-sdk 1.9.3 → 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/dist/entities/pool.d.ts +39 -0
- package/dist/services/ramses/vesting.d.ts +3 -0
- package/dist/test/constants.d.ts +16 -0
- package/dist/test/utils/testingHelper.d.ts +13 -0
- package/dist/test/wallet.d.ts +1 -0
- package/dist/types.d.ts +4 -2
- package/dist/v2-sdk.cjs.development.js +405 -85
- package/dist/v2-sdk.cjs.development.js.map +1 -1
- package/dist/v2-sdk.cjs.production.min.js +1 -1
- package/dist/v2-sdk.cjs.production.min.js.map +1 -1
- package/dist/v2-sdk.esm.js +405 -85
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +3 -2
- package/src/abi/IXRam.json +99 -0
- package/src/config.ts +25 -8
- package/src/entities/pool.ts +115 -0
- package/src/services/ramses/vesting.ts +13 -0
- package/src/test/constants.ts +19 -2
- package/src/test/lyra.test.ts +7 -6
- package/src/test/oneInch.test.ts +34 -3
- package/src/test/ramses.test.ts +190 -0
- package/src/test/synthetix.test.ts +3 -1
- package/src/test/uniswap.test.ts +180 -148
- package/src/test/utils/testingHelper.ts +51 -1
- package/src/test/wallet.ts +2 -1
- package/src/test/zeroEx.test.ts +40 -4
- package/src/types.ts +4 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhedge/v2-sdk",
|
|
3
|
-
"version": "1.9.
|
|
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": {
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{ "abi": [
|
|
2
|
+
{
|
|
3
|
+
"inputs": [
|
|
4
|
+
{
|
|
5
|
+
"internalType": "uint256",
|
|
6
|
+
"name": "_amount",
|
|
7
|
+
"type": "uint256"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
10
|
+
"name": "createVest",
|
|
11
|
+
"outputs": [],
|
|
12
|
+
"stateMutability": "nonpayable",
|
|
13
|
+
"type": "function"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"inputs": [
|
|
17
|
+
{
|
|
18
|
+
"internalType": "uint256",
|
|
19
|
+
"name": "_vestID",
|
|
20
|
+
"type": "uint256"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"internalType": "bool",
|
|
24
|
+
"name": "_ve",
|
|
25
|
+
"type": "bool"
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"name": "exitVest",
|
|
29
|
+
"outputs": [
|
|
30
|
+
{
|
|
31
|
+
"internalType": "bool",
|
|
32
|
+
"name": "",
|
|
33
|
+
"type": "bool"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"stateMutability": "nonpayable",
|
|
37
|
+
"type": "function"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"inputs": [
|
|
41
|
+
{
|
|
42
|
+
"internalType": "address",
|
|
43
|
+
"name": "_user",
|
|
44
|
+
"type": "address"
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"name": "usersTotalVests",
|
|
48
|
+
"outputs": [
|
|
49
|
+
{
|
|
50
|
+
"internalType": "uint256",
|
|
51
|
+
"name": "",
|
|
52
|
+
"type": "uint256"
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
"stateMutability": "view",
|
|
56
|
+
"type": "function"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"inputs": [
|
|
60
|
+
{
|
|
61
|
+
"internalType": "address",
|
|
62
|
+
"name": "user",
|
|
63
|
+
"type": "address"
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
"name": "vestInfo",
|
|
67
|
+
"outputs": [
|
|
68
|
+
{
|
|
69
|
+
"components": [
|
|
70
|
+
{
|
|
71
|
+
"internalType": "uint256",
|
|
72
|
+
"name": "amount",
|
|
73
|
+
"type": "uint256"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"internalType": "uint256",
|
|
77
|
+
"name": "start",
|
|
78
|
+
"type": "uint256"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"internalType": "uint256",
|
|
82
|
+
"name": "maxEnd",
|
|
83
|
+
"type": "uint256"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"internalType": "uint256",
|
|
87
|
+
"name": "vestID",
|
|
88
|
+
"type": "uint256"
|
|
89
|
+
}
|
|
90
|
+
],
|
|
91
|
+
"internalType": "struct IXRam.VestPosition[]",
|
|
92
|
+
"name": "",
|
|
93
|
+
"type": "tuple[]"
|
|
94
|
+
}
|
|
95
|
+
],
|
|
96
|
+
"stateMutability": "view",
|
|
97
|
+
"type": "function"
|
|
98
|
+
}
|
|
99
|
+
]}
|
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 = {
|
|
@@ -48,7 +49,12 @@ export const routerAddress: AddressDappNetworkMap = {
|
|
|
48
49
|
[Dapp.ONEINCH]: "0x1111111254EEB25477B68fb85Ed929f73A960582",
|
|
49
50
|
[Dapp.UNISWAPV3]: "0xe592427a0aece92de3edee1f18e0157c05861564",
|
|
50
51
|
[Dapp.AAVEV3]: "0x794a61358D6845594F94dc1DB02A252b5b4814aD",
|
|
51
|
-
[Dapp.BALANCER]: "0xBA12222222228d8Ba445958a75a0704d566BF2C8"
|
|
52
|
+
[Dapp.BALANCER]: "0xBA12222222228d8Ba445958a75a0704d566BF2C8",
|
|
53
|
+
[Dapp.RAMSES]: "0xaaa87963efeb6f7e0a2711f397663105acb1805e"
|
|
54
|
+
},
|
|
55
|
+
[Network.BASE]: {
|
|
56
|
+
[Dapp.ONEINCH]: "0x1111111254EEB25477B68fb85Ed929f73A960582",
|
|
57
|
+
[Dapp.ZEROEX]: "0xdef1c0ded9bec7f1a1670819833240f027b25eff"
|
|
52
58
|
}
|
|
53
59
|
};
|
|
54
60
|
|
|
@@ -58,7 +64,8 @@ export const dappFactoryAddress: AddressDappNetworkMap = {
|
|
|
58
64
|
[Dapp.QUICKSWAP]: "0x5757371414417b8C6CAad45bAeF941aBc7d3Ab32"
|
|
59
65
|
},
|
|
60
66
|
[Network.OPTIMISM]: {},
|
|
61
|
-
[Network.ARBITRUM]: {}
|
|
67
|
+
[Network.ARBITRUM]: {},
|
|
68
|
+
[Network.BASE]: {}
|
|
62
69
|
};
|
|
63
70
|
|
|
64
71
|
export const stakingAddress: AddressDappNetworkMap = {
|
|
@@ -69,7 +76,8 @@ export const stakingAddress: AddressDappNetworkMap = {
|
|
|
69
76
|
[Dapp.AAVEV3]: "0x929EC64c34a17401F460460D4B9390518E5B473e"
|
|
70
77
|
},
|
|
71
78
|
[Network.OPTIMISM]: {},
|
|
72
|
-
[Network.ARBITRUM]: {}
|
|
79
|
+
[Network.ARBITRUM]: {},
|
|
80
|
+
[Network.BASE]: {}
|
|
73
81
|
};
|
|
74
82
|
|
|
75
83
|
export const aaveAddressProvider: AddressDappNetworkMap = {
|
|
@@ -82,31 +90,40 @@ export const aaveAddressProvider: AddressDappNetworkMap = {
|
|
|
82
90
|
},
|
|
83
91
|
[Network.ARBITRUM]: {
|
|
84
92
|
[Dapp.AAVEV3]: "0xa97684ead0e402dc232d5a977953df7ecbab3cdb"
|
|
93
|
+
},
|
|
94
|
+
[Network.BASE]: {
|
|
95
|
+
// https://docs.aave.com/developers/deployed-contracts/v3-mainnet/base
|
|
96
|
+
[Dapp.AAVEV3]: "0xe20fCBdBfFC4Dd138cE8b2E6FBb6CB49777ad64D"
|
|
85
97
|
}
|
|
86
98
|
};
|
|
87
99
|
export const nonfungiblePositionManagerAddress: AddressNetworkMap = {
|
|
88
100
|
[Network.POLYGON]: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88",
|
|
89
101
|
[Network.OPTIMISM]: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88",
|
|
90
|
-
[Network.ARBITRUM]: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88"
|
|
102
|
+
[Network.ARBITRUM]: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88",
|
|
103
|
+
// https://docs.uniswap.org/contracts/v3/reference/deployments
|
|
104
|
+
[Network.BASE]: "0x03a520b32C04BF3bEEf7BEb72E919cf822Ed34f1"
|
|
91
105
|
};
|
|
92
106
|
|
|
93
107
|
export const networkChainIdMap: NetworkChainIdMap = {
|
|
94
108
|
[Network.POLYGON]: 137,
|
|
95
109
|
[Network.OPTIMISM]: 10,
|
|
96
|
-
[Network.ARBITRUM]: 42161
|
|
110
|
+
[Network.ARBITRUM]: 42161,
|
|
111
|
+
[Network.BASE]: 8453
|
|
97
112
|
};
|
|
98
113
|
|
|
99
114
|
export const balancerSubgraph: AddressNetworkMap = {
|
|
100
115
|
[Network.POLYGON]:
|
|
101
116
|
"https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-polygon-v2",
|
|
102
117
|
[Network.OPTIMISM]: "",
|
|
103
|
-
[Network.ARBITRUM]: ""
|
|
118
|
+
[Network.ARBITRUM]: "",
|
|
119
|
+
[Network.BASE]: ""
|
|
104
120
|
};
|
|
105
121
|
|
|
106
122
|
export const multiCallAddress: AddressNetworkMap = {
|
|
107
123
|
[Network.POLYGON]: "0x275617327c958bD06b5D6b871E7f491D76113dd8",
|
|
108
124
|
[Network.OPTIMISM]: "",
|
|
109
|
-
[Network.ARBITRUM]: ""
|
|
125
|
+
[Network.ARBITRUM]: "",
|
|
126
|
+
[Network.BASE]: ""
|
|
110
127
|
};
|
|
111
128
|
|
|
112
129
|
export const lyraNetworkMap: LyraNetworkMap = {
|
package/src/entities/pool.ts
CHANGED
|
@@ -59,6 +59,10 @@ import {
|
|
|
59
59
|
import { getFuturesCancelOrderTxData } from "../services/futures/trade";
|
|
60
60
|
import { getZeroExTradeTxData } from "../services/zeroEx/zeroExTrade";
|
|
61
61
|
import { getOneInchSwapTxData } from "../services/oneInch";
|
|
62
|
+
import {
|
|
63
|
+
getCreateVestTxData,
|
|
64
|
+
getExitVestTxData
|
|
65
|
+
} from "../services/ramses/vesting";
|
|
62
66
|
|
|
63
67
|
export class Pool {
|
|
64
68
|
public readonly poolLogic: Contract;
|
|
@@ -486,6 +490,7 @@ export class Pool {
|
|
|
486
490
|
]);
|
|
487
491
|
break;
|
|
488
492
|
case Dapp.VELODROME:
|
|
493
|
+
case Dapp.RAMSES:
|
|
489
494
|
stakeTxData = getVelodromeStakeTxData(amount, false);
|
|
490
495
|
break;
|
|
491
496
|
case Dapp.VELODROMEV2:
|
|
@@ -1056,6 +1061,7 @@ export class Pool {
|
|
|
1056
1061
|
txData = abi.encodeFunctionData("claim_rewards()", []);
|
|
1057
1062
|
break;
|
|
1058
1063
|
case Dapp.VELODROME:
|
|
1064
|
+
case Dapp.RAMSES:
|
|
1059
1065
|
contractAddress = tokenId;
|
|
1060
1066
|
txData = getVelodromeClaimTxData(this, tokenId, false);
|
|
1061
1067
|
break;
|
|
@@ -1235,6 +1241,73 @@ export class Pool {
|
|
|
1235
1241
|
return tx;
|
|
1236
1242
|
}
|
|
1237
1243
|
|
|
1244
|
+
/**
|
|
1245
|
+
* Add liquidity to Velodrome V2 or Ramses pool
|
|
1246
|
+
* @param {Dapp} dapp VelodromeV2 or Ramses
|
|
1247
|
+
* @param {string} assetA First asset
|
|
1248
|
+
* @param {string} assetB Second asset
|
|
1249
|
+
* @param {BigNumber | string} amountA Amount first asset
|
|
1250
|
+
* @param {BigNumber | string} amountB Amount second asset
|
|
1251
|
+
* @param { boolean } isStable Is stable pool
|
|
1252
|
+
* @param {any} options Transaction options
|
|
1253
|
+
* @returns {Promise<any>} Transaction
|
|
1254
|
+
*/
|
|
1255
|
+
async addLiquidityV2(
|
|
1256
|
+
dapp: Dapp.VELODROMEV2 | Dapp.RAMSES,
|
|
1257
|
+
assetA: string,
|
|
1258
|
+
assetB: string,
|
|
1259
|
+
amountA: BigNumber | string,
|
|
1260
|
+
amountB: BigNumber | string,
|
|
1261
|
+
isStable: boolean,
|
|
1262
|
+
options: any = null
|
|
1263
|
+
): Promise<any> {
|
|
1264
|
+
const tx = await this.poolLogic.execTransaction(
|
|
1265
|
+
routerAddress[this.network][dapp],
|
|
1266
|
+
await getVelodromeAddLiquidityTxData(
|
|
1267
|
+
this,
|
|
1268
|
+
assetA,
|
|
1269
|
+
assetB,
|
|
1270
|
+
amountA,
|
|
1271
|
+
amountB,
|
|
1272
|
+
isStable
|
|
1273
|
+
),
|
|
1274
|
+
options
|
|
1275
|
+
);
|
|
1276
|
+
return tx;
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
/**
|
|
1280
|
+
* Remove liquidity from Velodrome V2 or Ramses pool
|
|
1281
|
+
* @param {Dapp} dapp VelodromeV2 or Ramses
|
|
1282
|
+
* @param {string} assetA First asset
|
|
1283
|
+
* @param {string} assetB Second asset
|
|
1284
|
+
* @param {BigNumber | string} amount Amount of LP tokens
|
|
1285
|
+
* @param { boolean } isStable Is stable pool
|
|
1286
|
+
* @param {any} options Transaction options
|
|
1287
|
+
* @returns {Promise<any>} Transaction
|
|
1288
|
+
*/
|
|
1289
|
+
async removeLiquidityV2(
|
|
1290
|
+
dapp: Dapp.VELODROMEV2 | Dapp.RAMSES,
|
|
1291
|
+
assetA: string,
|
|
1292
|
+
assetB: string,
|
|
1293
|
+
amount: BigNumber | string,
|
|
1294
|
+
isStable: boolean,
|
|
1295
|
+
options: any = null
|
|
1296
|
+
): Promise<any> {
|
|
1297
|
+
const tx = await this.poolLogic.execTransaction(
|
|
1298
|
+
routerAddress[this.network][dapp],
|
|
1299
|
+
await getVelodromeRemoveLiquidityTxData(
|
|
1300
|
+
this,
|
|
1301
|
+
assetA,
|
|
1302
|
+
assetB,
|
|
1303
|
+
amount,
|
|
1304
|
+
isStable
|
|
1305
|
+
),
|
|
1306
|
+
options
|
|
1307
|
+
);
|
|
1308
|
+
return tx;
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1238
1311
|
/**
|
|
1239
1312
|
* Trade options on lyra
|
|
1240
1313
|
* @param {LyraOptionMarket} market Underlying market e.g. eth
|
|
@@ -1360,4 +1433,46 @@ export class Pool {
|
|
|
1360
1433
|
const fee = await this.poolLogic.availableManagerFee();
|
|
1361
1434
|
return BigNumber.from(fee);
|
|
1362
1435
|
}
|
|
1436
|
+
|
|
1437
|
+
/** Vest tokens (e.g. Ramses xoRAM)
|
|
1438
|
+
*
|
|
1439
|
+
* @param {string} tokenAddress Address of the token to vest
|
|
1440
|
+
* @param {BigNumber | string } changeAmount Negative for short, positive for long
|
|
1441
|
+
* @param {any} options Transaction options
|
|
1442
|
+
* @returns {Promise<any>} Transaction
|
|
1443
|
+
*/
|
|
1444
|
+
async vestTokens(
|
|
1445
|
+
tokenAddress: string,
|
|
1446
|
+
amount: BigNumber | string,
|
|
1447
|
+
options: any = null
|
|
1448
|
+
): Promise<any> {
|
|
1449
|
+
const txData = await getCreateVestTxData(amount);
|
|
1450
|
+
const tx = await this.poolLogic.execTransaction(
|
|
1451
|
+
tokenAddress,
|
|
1452
|
+
txData,
|
|
1453
|
+
options
|
|
1454
|
+
);
|
|
1455
|
+
return tx;
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
/** Exit position of vested tokens (e.g. Ramses xoRAM)
|
|
1459
|
+
*
|
|
1460
|
+
* @param {string} tokenAddress Address of the token to vest
|
|
1461
|
+
* @param {number } id position Id of the vested tokens
|
|
1462
|
+
* @param {any} options Transaction options
|
|
1463
|
+
* @returns {Promise<any>} Transaction
|
|
1464
|
+
*/
|
|
1465
|
+
async exitVestedToken(
|
|
1466
|
+
tokenAddress: string,
|
|
1467
|
+
id: number,
|
|
1468
|
+
options: any = null
|
|
1469
|
+
): Promise<any> {
|
|
1470
|
+
const txData = await getExitVestTxData(id);
|
|
1471
|
+
const tx = await this.poolLogic.execTransaction(
|
|
1472
|
+
tokenAddress,
|
|
1473
|
+
txData,
|
|
1474
|
+
options
|
|
1475
|
+
);
|
|
1476
|
+
return tx;
|
|
1477
|
+
}
|
|
1363
1478
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { BigNumber, ethers } from "ethers";
|
|
3
|
+
import IXRam from "../../abi/IXRam.json";
|
|
4
|
+
|
|
5
|
+
const iXRam = new ethers.utils.Interface(IXRam.abi);
|
|
6
|
+
|
|
7
|
+
export function getCreateVestTxData(amount: BigNumber | string): string {
|
|
8
|
+
return iXRam.encodeFunctionData("createVest", [amount]);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function getExitVestTxData(vestId: number): string {
|
|
12
|
+
return iXRam.encodeFunctionData("exitVest", [vestId, false]);
|
|
13
|
+
}
|
package/src/test/constants.ts
CHANGED
|
@@ -41,12 +41,14 @@ 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 = {
|
|
48
49
|
[Network.POLYGON]: {
|
|
49
50
|
USDC: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
|
|
51
|
+
SWETH: "",
|
|
50
52
|
WETH: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
|
|
51
53
|
WBTC: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
|
|
52
54
|
ARRAKIS_USDC_WETH_GAUGE: "0x33d1ad9Cd88A509397CD924C2d7613C285602C20",
|
|
@@ -55,18 +57,33 @@ export const CONTRACT_ADDRESS = {
|
|
|
55
57
|
[Network.OPTIMISM]: {
|
|
56
58
|
USDC: "0x7F5c764cBc14f9669B88837ca1490cCa17c31607",
|
|
57
59
|
SUSD: "0x8c6f28f2f1a3c87f0f938b96d27520d9751ec8d9",
|
|
60
|
+
SWETH: "",
|
|
58
61
|
WETH: "0x4200000000000000000000000000000000000006",
|
|
59
62
|
WBTC: "0x68f180fcCe6836688e9084f035309E29Bf0A2095",
|
|
60
63
|
KWENTA_ETH_PERP_V2: "0x2b3bb4c683bfc5239b029131eef3b1d214478d93"
|
|
61
64
|
},
|
|
62
65
|
[Network.ARBITRUM]: {
|
|
63
|
-
USDC: "
|
|
66
|
+
USDC: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
67
|
+
SWETH: "0xbc011A12Da28e8F0f528d9eE5E7039E22F91cf18",
|
|
64
68
|
WETH: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
|
|
65
69
|
WBTC: "0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f",
|
|
66
70
|
WSTETH: "0x5979d7b546e38e414f7e9822514be443a4800529",
|
|
67
71
|
BALANCER_WSTETH_WETH_POOL: "0x36bf227d6bac96e2ab1ebb5492ecec69c691943f",
|
|
68
72
|
BALANCER_WSTETH_WETH_GAUGE: "0x251e51b25afa40f2b6b9f05aaf1bc7eaa0551771"
|
|
73
|
+
},
|
|
74
|
+
[Network.BASE]: {
|
|
75
|
+
USDC: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
|
|
76
|
+
WETH: "0x4200000000000000000000000000000000000006",
|
|
77
|
+
WBTC: "",
|
|
78
|
+
SWETH: ""
|
|
69
79
|
}
|
|
70
80
|
};
|
|
71
81
|
|
|
72
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
|
+
};
|
package/src/test/lyra.test.ts
CHANGED
|
@@ -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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
142
|
+
const pool = await dhedge.loadPool(TEST_POOL_OP);
|
|
142
143
|
try {
|
|
143
144
|
result = await pool.tradeLyraOption(
|
|
144
145
|
"eth",
|
package/src/test/oneInch.test.ts
CHANGED
|
@@ -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 {
|
|
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(
|
|
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
|
+
});
|