@dhedge/v2-sdk 1.9.2 → 1.9.4
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 +50 -0
- package/dist/services/ramses/vesting.d.ts +3 -0
- package/dist/test/constants.d.ts +4 -0
- package/dist/test/utils/testingHelper.d.ts +7 -0
- package/dist/test/wallet.d.ts +4 -1
- package/dist/types.d.ts +2 -1
- package/dist/v2-sdk.cjs.development.js +455 -59
- 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 +455 -59
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/IXRam.json +99 -0
- package/src/config.ts +2 -1
- package/src/entities/pool.ts +134 -0
- package/src/services/ramses/vesting.ts +13 -0
- package/src/test/constants.ts +5 -1
- package/src/test/pool.test.ts +90 -46
- package/src/test/ramses.test.ts +190 -0
- package/src/test/utils/testingHelper.ts +25 -3
- package/src/test/utils.test.ts +70 -49
- package/src/test/wallet.ts +10 -2
- package/src/types.ts +4 -3
package/package.json
CHANGED
|
@@ -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
|
@@ -48,7 +48,8 @@ export const routerAddress: AddressDappNetworkMap = {
|
|
|
48
48
|
[Dapp.ONEINCH]: "0x1111111254EEB25477B68fb85Ed929f73A960582",
|
|
49
49
|
[Dapp.UNISWAPV3]: "0xe592427a0aece92de3edee1f18e0157c05861564",
|
|
50
50
|
[Dapp.AAVEV3]: "0x794a61358D6845594F94dc1DB02A252b5b4814aD",
|
|
51
|
-
[Dapp.BALANCER]: "0xBA12222222228d8Ba445958a75a0704d566BF2C8"
|
|
51
|
+
[Dapp.BALANCER]: "0xBA12222222228d8Ba445958a75a0704d566BF2C8",
|
|
52
|
+
[Dapp.RAMSES]: "0xaaa87963efeb6f7e0a2711f397663105acb1805e"
|
|
52
53
|
}
|
|
53
54
|
};
|
|
54
55
|
|
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
|
|
@@ -1341,4 +1414,65 @@ export class Pool {
|
|
|
1341
1414
|
const tx = await this.poolLogic.execTransaction(market, txData, options);
|
|
1342
1415
|
return tx;
|
|
1343
1416
|
}
|
|
1417
|
+
|
|
1418
|
+
/**
|
|
1419
|
+
* mintManagerFee
|
|
1420
|
+
* @param {any} options Transaction options
|
|
1421
|
+
* @returns {Promise<any>} Transaction
|
|
1422
|
+
*/
|
|
1423
|
+
async mintManagerFee(options: any = null): Promise<any> {
|
|
1424
|
+
const tx = await this.poolLogic.mintManagerFee(options);
|
|
1425
|
+
return tx;
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
/**
|
|
1429
|
+
* getAvailableManagerFee
|
|
1430
|
+
* @returns {Promise<BigNumber>} fee
|
|
1431
|
+
*/
|
|
1432
|
+
async getAvailableManagerFee(): Promise<BigNumber> {
|
|
1433
|
+
const fee = await this.poolLogic.availableManagerFee();
|
|
1434
|
+
return BigNumber.from(fee);
|
|
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
|
+
}
|
|
1344
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
|
@@ -47,6 +47,7 @@ export const TEST_POOL = {
|
|
|
47
47
|
export const CONTRACT_ADDRESS = {
|
|
48
48
|
[Network.POLYGON]: {
|
|
49
49
|
USDC: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
|
|
50
|
+
SWETH: "",
|
|
50
51
|
WETH: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
|
|
51
52
|
WBTC: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
|
|
52
53
|
ARRAKIS_USDC_WETH_GAUGE: "0x33d1ad9Cd88A509397CD924C2d7613C285602C20",
|
|
@@ -55,11 +56,14 @@ export const CONTRACT_ADDRESS = {
|
|
|
55
56
|
[Network.OPTIMISM]: {
|
|
56
57
|
USDC: "0x7F5c764cBc14f9669B88837ca1490cCa17c31607",
|
|
57
58
|
SUSD: "0x8c6f28f2f1a3c87f0f938b96d27520d9751ec8d9",
|
|
59
|
+
SWETH: "",
|
|
58
60
|
WETH: "0x4200000000000000000000000000000000000006",
|
|
61
|
+
WBTC: "0x68f180fcCe6836688e9084f035309E29Bf0A2095",
|
|
59
62
|
KWENTA_ETH_PERP_V2: "0x2b3bb4c683bfc5239b029131eef3b1d214478d93"
|
|
60
63
|
},
|
|
61
64
|
[Network.ARBITRUM]: {
|
|
62
|
-
USDC: "
|
|
65
|
+
USDC: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
66
|
+
SWETH: "0xbc011A12Da28e8F0f528d9eE5E7039E22F91cf18",
|
|
63
67
|
WETH: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
|
|
64
68
|
WBTC: "0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f",
|
|
65
69
|
WSTETH: "0x5979d7b546e38e414f7e9822514be443a4800529",
|
package/src/test/pool.test.ts
CHANGED
|
@@ -1,60 +1,104 @@
|
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
1
2
|
import { Dhedge, ethers, Pool } from "..";
|
|
2
3
|
import { AssetEnabled, Network } from "../types";
|
|
3
4
|
import { CONTRACT_ADDRESS, TEST_POOL } from "./constants";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
beforeAfterReset,
|
|
8
|
+
testingHelper,
|
|
9
|
+
TestingRunParams
|
|
10
|
+
} from "./utils/testingHelper";
|
|
4
11
|
import { allowanceDelta, balanceDelta } from "./utils/token";
|
|
5
|
-
import { wallet } from "./wallet";
|
|
6
12
|
|
|
7
|
-
|
|
8
|
-
let
|
|
13
|
+
const testPool = ({ wallet, network, provider }: TestingRunParams) => {
|
|
14
|
+
let dhedge: Dhedge;
|
|
15
|
+
let pool: Pool;
|
|
9
16
|
|
|
10
|
-
jest.setTimeout(
|
|
17
|
+
jest.setTimeout(200000);
|
|
11
18
|
|
|
12
|
-
|
|
19
|
+
describe(`pool on ${network}`, () => {
|
|
20
|
+
beforeAll(async () => {
|
|
21
|
+
dhedge = new Dhedge(wallet, network);
|
|
22
|
+
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
23
|
+
});
|
|
24
|
+
beforeAfterReset({ beforeAll, afterAll, provider });
|
|
13
25
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
});
|
|
26
|
+
it("checks fund composition", async () => {
|
|
27
|
+
const result = await pool.getComposition();
|
|
28
|
+
expect(result.length).toBeGreaterThan(0);
|
|
29
|
+
});
|
|
19
30
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
it("approves USDC balance of User for Deposit", async () => {
|
|
32
|
+
await pool.approveDeposit(
|
|
33
|
+
CONTRACT_ADDRESS[network].USDC,
|
|
34
|
+
ethers.constants.MaxUint256
|
|
35
|
+
);
|
|
36
|
+
const UsdcAllowanceDelta = await allowanceDelta(
|
|
37
|
+
pool.signer.address,
|
|
38
|
+
CONTRACT_ADDRESS[network].USDC,
|
|
39
|
+
pool.address,
|
|
40
|
+
pool.signer
|
|
41
|
+
);
|
|
42
|
+
expect(UsdcAllowanceDelta.gt(0));
|
|
43
|
+
});
|
|
24
44
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
pool.signer
|
|
35
|
-
);
|
|
36
|
-
expect(UsdcAllowanceDelta.gt(0));
|
|
37
|
-
});
|
|
45
|
+
it("deposits 1 USDC into Pool", async () => {
|
|
46
|
+
await pool.deposit(CONTRACT_ADDRESS[network].USDC, (1e6).toString());
|
|
47
|
+
const poolTokenDelta = await balanceDelta(
|
|
48
|
+
pool.signer.address,
|
|
49
|
+
pool.address,
|
|
50
|
+
pool.signer
|
|
51
|
+
);
|
|
52
|
+
expect(poolTokenDelta.gt(0));
|
|
53
|
+
});
|
|
38
54
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const poolTokenDelta = await balanceDelta(
|
|
42
|
-
pool.signer.address,
|
|
43
|
-
pool.address,
|
|
44
|
-
pool.signer
|
|
45
|
-
);
|
|
46
|
-
expect(poolTokenDelta.gt(0));
|
|
47
|
-
});
|
|
55
|
+
it("adds WBTC to enabled assets", async () => {
|
|
56
|
+
const assetsBefore = await pool.getComposition();
|
|
48
57
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
const newAssets: AssetEnabled[] = [
|
|
59
|
+
{ asset: CONTRACT_ADDRESS[network].USDC, isDeposit: true },
|
|
60
|
+
{ asset: CONTRACT_ADDRESS[network].WETH, isDeposit: false },
|
|
61
|
+
{ asset: CONTRACT_ADDRESS[network].WBTC, isDeposit: false }
|
|
62
|
+
];
|
|
63
|
+
await pool.changeAssets(newAssets);
|
|
64
|
+
const assetsAfter = await pool.getComposition();
|
|
65
|
+
if (assetsBefore.length < newAssets.length) {
|
|
66
|
+
expect(assetsAfter.length).toBeGreaterThan(assetsBefore.length);
|
|
67
|
+
} else {
|
|
68
|
+
expect(assetsAfter.length).toBeLessThanOrEqual(assetsBefore.length);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("get available Manager Fee", async () => {
|
|
73
|
+
const result = await pool.getAvailableManagerFee();
|
|
74
|
+
expect(result).toBeInstanceOf(BigNumber);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("mintManagerFee; should not revert", async () => {
|
|
78
|
+
const tx = await pool.mintManagerFee();
|
|
79
|
+
expect(tx).toHaveProperty("wait");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("withdraw 0.1 pool token into Pool", async () => {
|
|
83
|
+
await provider.send("evm_increaseTime", [24 * 60 * 60]);
|
|
84
|
+
await provider.send("evm_mine", []);
|
|
85
|
+
await pool.withdraw((0.1 * 1e18).toString());
|
|
86
|
+
const poolTokenDelta = await balanceDelta(
|
|
87
|
+
pool.signer.address,
|
|
88
|
+
pool.address,
|
|
89
|
+
pool.signer
|
|
90
|
+
);
|
|
91
|
+
expect(poolTokenDelta.lt(0));
|
|
92
|
+
});
|
|
59
93
|
});
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
testingHelper({
|
|
97
|
+
network: Network.POLYGON,
|
|
98
|
+
testingRun: testPool
|
|
60
99
|
});
|
|
100
|
+
|
|
101
|
+
// testingHelper({
|
|
102
|
+
// network: Network.OPTIMISM,
|
|
103
|
+
// testingRun: testPool
|
|
104
|
+
// });
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
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
|
+
beforeAfterReset,
|
|
10
|
+
testingHelper
|
|
11
|
+
} from "./utils/testingHelper";
|
|
12
|
+
import { allowanceDelta, balanceDelta } from "./utils/token";
|
|
13
|
+
import { getWalletData } from "./wallet";
|
|
14
|
+
|
|
15
|
+
const testRamses = ({ network, provider }: TestingRunParams) => {
|
|
16
|
+
const USDC_swETH_Lp = "0xf1a5444a7ed5f24962a118512b076a015b0e6c0b";
|
|
17
|
+
const USDC_swETH_Gauge = "0x9765cdaec6395b04737edc22c5b3e7d85677328a";
|
|
18
|
+
const RAM = "0xaaa6c1e32c55a7bfa8066a6fae9b42650f262418";
|
|
19
|
+
const xoRAM = "0xaaa1ee8dc1864ae49185c368e8c64dd780a50fb7";
|
|
20
|
+
|
|
21
|
+
const USDC = CONTRACT_ADDRESS[network].USDC;
|
|
22
|
+
const SWETH = CONTRACT_ADDRESS[network].SWETH;
|
|
23
|
+
|
|
24
|
+
let dhedge: Dhedge;
|
|
25
|
+
let pool: Pool;
|
|
26
|
+
jest.setTimeout(100000);
|
|
27
|
+
|
|
28
|
+
describe(`[${network}] ramses tests`, () => {
|
|
29
|
+
beforeAll(async () => {
|
|
30
|
+
const { wallet } = getWalletData(network);
|
|
31
|
+
// top up ETH (gas)
|
|
32
|
+
await provider.send("hardhat_setBalance", [
|
|
33
|
+
wallet.address,
|
|
34
|
+
"0x100000000000000"
|
|
35
|
+
]);
|
|
36
|
+
dhedge = new Dhedge(wallet, network);
|
|
37
|
+
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
38
|
+
await pool.trade(Dapp.ONEINCH, USDC, SWETH, (5 * 1e6).toString());
|
|
39
|
+
});
|
|
40
|
+
beforeAfterReset({ beforeAll, afterAll, provider });
|
|
41
|
+
|
|
42
|
+
it("approves unlimited USDC and swETH on for Ramses", async () => {
|
|
43
|
+
await pool.approve(Dapp.RAMSES, USDC, MAX_AMOUNT);
|
|
44
|
+
await pool.approve(Dapp.RAMSES, SWETH, MAX_AMOUNT);
|
|
45
|
+
const UsdcAllowanceDelta = await allowanceDelta(
|
|
46
|
+
pool.address,
|
|
47
|
+
USDC,
|
|
48
|
+
routerAddress[network].ramses!,
|
|
49
|
+
pool.signer
|
|
50
|
+
);
|
|
51
|
+
await expect(UsdcAllowanceDelta.gt(0));
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("adds USDC and swETH to a Ramses volatile pool", async () => {
|
|
55
|
+
const usdcBalance = await pool.utils.getBalance(USDC, pool.address);
|
|
56
|
+
const swethBalance = await pool.utils.getBalance(SWETH, pool.address);
|
|
57
|
+
await pool.addLiquidityV2(
|
|
58
|
+
Dapp.RAMSES,
|
|
59
|
+
USDC,
|
|
60
|
+
SWETH,
|
|
61
|
+
usdcBalance,
|
|
62
|
+
swethBalance,
|
|
63
|
+
false
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const lpTokenDelta = await balanceDelta(
|
|
67
|
+
pool.address,
|
|
68
|
+
USDC_swETH_Lp,
|
|
69
|
+
pool.signer
|
|
70
|
+
);
|
|
71
|
+
expect(lpTokenDelta.gt(0));
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("should stake USDC-swETH LP in a gauge", async () => {
|
|
75
|
+
const balance = await dhedge.utils.getBalance(
|
|
76
|
+
USDC_swETH_Lp,
|
|
77
|
+
pool.address
|
|
78
|
+
);
|
|
79
|
+
await pool.approveSpender(USDC_swETH_Gauge, USDC_swETH_Lp, MAX_AMOUNT);
|
|
80
|
+
await pool.stakeInGauge(Dapp.RAMSES, USDC_swETH_Gauge, balance);
|
|
81
|
+
const gaugeBalance = await balanceDelta(
|
|
82
|
+
pool.address,
|
|
83
|
+
USDC_swETH_Gauge,
|
|
84
|
+
pool.signer
|
|
85
|
+
);
|
|
86
|
+
expect(gaugeBalance.gt(0));
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("should claim rewards from Gauge", async () => {
|
|
90
|
+
await provider.send("evm_increaseTime", [24 * 60 * 60]); // 1 day
|
|
91
|
+
await provider.send("evm_mine", []);
|
|
92
|
+
const claimTx = await pool.claimFees(Dapp.RAMSES, USDC_swETH_Gauge);
|
|
93
|
+
expect(claimTx).not.toBe(null);
|
|
94
|
+
const ramBalanceDelta = await balanceDelta(
|
|
95
|
+
pool.address,
|
|
96
|
+
RAM,
|
|
97
|
+
pool.signer
|
|
98
|
+
);
|
|
99
|
+
const xoRamBalanceDelta = await balanceDelta(
|
|
100
|
+
pool.address,
|
|
101
|
+
xoRAM,
|
|
102
|
+
pool.signer
|
|
103
|
+
);
|
|
104
|
+
expect(ramBalanceDelta.gt(0));
|
|
105
|
+
expect(xoRamBalanceDelta.gt(0));
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("createVest for xoRAM", async () => {
|
|
109
|
+
const xoRAMBalanceBefore = await dhedge.utils.getBalance(
|
|
110
|
+
xoRAM,
|
|
111
|
+
pool.address
|
|
112
|
+
);
|
|
113
|
+
expect(xoRAMBalanceBefore.gt(0));
|
|
114
|
+
const vestTx = await pool.vestTokens(xoRAM, xoRAMBalanceBefore);
|
|
115
|
+
expect(vestTx).not.toBe(null);
|
|
116
|
+
const xoRAMBalanceAfter = await dhedge.utils.getBalance(
|
|
117
|
+
xoRAM,
|
|
118
|
+
pool.address
|
|
119
|
+
);
|
|
120
|
+
expect(xoRAMBalanceAfter.eq(0));
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("exitVest for xoRAM", async () => {
|
|
124
|
+
await provider.send("evm_increaseTime", [3600 * 24 * 90]); // 90 days
|
|
125
|
+
await provider.send("evm_mine", []);
|
|
126
|
+
|
|
127
|
+
const ramBalanceBefore = await dhedge.utils.getBalance(RAM, pool.address);
|
|
128
|
+
|
|
129
|
+
const exitvestTx = await pool.exitVestedToken(xoRAM, 0);
|
|
130
|
+
const xoRAMBalanceAfter = await dhedge.utils.getBalance(
|
|
131
|
+
USDC_swETH_Gauge,
|
|
132
|
+
pool.address
|
|
133
|
+
);
|
|
134
|
+
expect(exitvestTx).not.toBe(null);
|
|
135
|
+
const ramBalanceAfter = await dhedge.utils.getBalance(RAM, pool.address);
|
|
136
|
+
expect(xoRAMBalanceAfter.eq(0));
|
|
137
|
+
expect(ramBalanceAfter.gt(ramBalanceBefore));
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("should unStake USDC-swETH LP from a gauge", async () => {
|
|
141
|
+
const gaugeBalance = await dhedge.utils.getBalance(
|
|
142
|
+
USDC_swETH_Gauge,
|
|
143
|
+
pool.address
|
|
144
|
+
);
|
|
145
|
+
await pool.unstakeFromGauge(USDC_swETH_Gauge, gaugeBalance);
|
|
146
|
+
const lpTokenDelta = await balanceDelta(
|
|
147
|
+
pool.address,
|
|
148
|
+
USDC_swETH_Lp,
|
|
149
|
+
pool.signer
|
|
150
|
+
);
|
|
151
|
+
expect(lpTokenDelta.gt(0));
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("approves unlimited USDC/swETH LP for Ramses", async () => {
|
|
155
|
+
await pool.approve(Dapp.RAMSES, USDC_swETH_Lp, MAX_AMOUNT);
|
|
156
|
+
const lpAllowanceDelta = await allowanceDelta(
|
|
157
|
+
pool.address,
|
|
158
|
+
USDC_swETH_Lp,
|
|
159
|
+
routerAddress[network].ramses!,
|
|
160
|
+
pool.signer
|
|
161
|
+
);
|
|
162
|
+
expect(lpAllowanceDelta.gt(0));
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("should remove all liquidity from an existing pool ", async () => {
|
|
166
|
+
const balance = await dhedge.utils.getBalance(
|
|
167
|
+
USDC_swETH_Lp,
|
|
168
|
+
pool.address
|
|
169
|
+
);
|
|
170
|
+
await pool.removeLiquidityV2(Dapp.RAMSES, USDC, SWETH, balance, false);
|
|
171
|
+
const usdcBalanceDelta = await balanceDelta(
|
|
172
|
+
pool.address,
|
|
173
|
+
USDC,
|
|
174
|
+
pool.signer
|
|
175
|
+
);
|
|
176
|
+
const swETHBalanceDelta = await balanceDelta(
|
|
177
|
+
pool.address,
|
|
178
|
+
SWETH,
|
|
179
|
+
pool.signer
|
|
180
|
+
);
|
|
181
|
+
expect(usdcBalanceDelta.gt(0));
|
|
182
|
+
expect(swETHBalanceDelta.gt(0));
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
testingHelper({
|
|
188
|
+
network: Network.ARBITRUM,
|
|
189
|
+
testingRun: testRamses
|
|
190
|
+
});
|