@dhedge/v2-sdk 1.10.3 → 1.10.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/README.md +9 -0
- package/dist/entities/pool.d.ts +32 -2
- package/dist/services/compound/lending.d.ts +3 -0
- package/dist/services/ramses/vesting.d.ts +1 -0
- package/dist/services/uniswap/V3Liquidity.d.ts +2 -2
- package/dist/test/constants.d.ts +4 -0
- package/dist/types.d.ts +2 -1
- package/dist/v2-sdk.cjs.development.js +1158 -447
- 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 +1158 -447
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/IRamsesNonfungiblePositionManager.json +486 -0
- package/src/abi/compound/ICompoundV3Comet.json +51 -0
- package/src/config.ts +2 -1
- package/src/entities/pool.ts +93 -3
- package/src/services/compound/lending.ts +20 -0
- package/src/services/ramses/vesting.ts +11 -0
- package/src/services/uniswap/V3Liquidity.ts +14 -4
- package/src/test/compoundV3.test.ts +90 -0
- package/src/test/constants.ts +9 -5
- package/src/test/ramsesCL.test.ts +155 -0
- package/src/types.ts +2 -1
package/src/entities/pool.ts
CHANGED
|
@@ -64,7 +64,8 @@ import { getZeroExTradeTxData } from "../services/zeroEx/zeroExTrade";
|
|
|
64
64
|
import { getOneInchSwapTxData } from "../services/oneInch";
|
|
65
65
|
import {
|
|
66
66
|
getCreateVestTxData,
|
|
67
|
-
getExitVestTxData
|
|
67
|
+
getExitVestTxData,
|
|
68
|
+
getRewardsTxDta
|
|
68
69
|
} from "../services/ramses/vesting";
|
|
69
70
|
import { getPoolTxOrGasEstimate } from "../utils/contract";
|
|
70
71
|
import {
|
|
@@ -72,6 +73,10 @@ import {
|
|
|
72
73
|
mintUnitViaFlatMoney,
|
|
73
74
|
redeemUnitViaFlatMoney
|
|
74
75
|
} from "../services/flatmoney/stableLp";
|
|
76
|
+
import {
|
|
77
|
+
getCompoundV3LendTxData,
|
|
78
|
+
getCompoundV3WithdrawTxData
|
|
79
|
+
} from "../services/compound/lending";
|
|
75
80
|
|
|
76
81
|
export class Pool {
|
|
77
82
|
public readonly poolLogic: Contract;
|
|
@@ -666,6 +671,7 @@ export class Pool {
|
|
|
666
671
|
this.address,
|
|
667
672
|
referralCode
|
|
668
673
|
]);
|
|
674
|
+
|
|
669
675
|
const tx = await getPoolTxOrGasEstimate(
|
|
670
676
|
this,
|
|
671
677
|
[routerAddress[this.network][dapp], depositTxData, options],
|
|
@@ -674,6 +680,32 @@ export class Pool {
|
|
|
674
680
|
return tx;
|
|
675
681
|
}
|
|
676
682
|
|
|
683
|
+
/**
|
|
684
|
+
* Lend asset to a Compound V3 style lending pool
|
|
685
|
+
* @param {string} market Address of market e.g cUSDCv3 address
|
|
686
|
+
* @param {string} asset Asset
|
|
687
|
+
* @param {BigNumber | string} amount Amount of asset to lend
|
|
688
|
+
* @param {any} options Transaction options
|
|
689
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
690
|
+
* @returns {Promise<any>} Transaction
|
|
691
|
+
*/
|
|
692
|
+
async lendCompoundV3(
|
|
693
|
+
market: string,
|
|
694
|
+
asset: string,
|
|
695
|
+
amount: BigNumber | string,
|
|
696
|
+
options: any = null,
|
|
697
|
+
estimateGas = false
|
|
698
|
+
): Promise<any> {
|
|
699
|
+
const supplyTxData = getCompoundV3LendTxData(asset, amount);
|
|
700
|
+
|
|
701
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
702
|
+
this,
|
|
703
|
+
[market, supplyTxData, options],
|
|
704
|
+
estimateGas
|
|
705
|
+
);
|
|
706
|
+
return tx;
|
|
707
|
+
}
|
|
708
|
+
|
|
677
709
|
/**
|
|
678
710
|
* Witdraw asset from a lending pool
|
|
679
711
|
* @param {Dapp} dapp Platform like Aave
|
|
@@ -695,6 +727,7 @@ export class Pool {
|
|
|
695
727
|
Transaction.WITHDRAW,
|
|
696
728
|
[asset, amount, this.address]
|
|
697
729
|
);
|
|
730
|
+
|
|
698
731
|
const tx = await getPoolTxOrGasEstimate(
|
|
699
732
|
this,
|
|
700
733
|
[routerAddress[this.network][dapp], withdrawTxData, options],
|
|
@@ -703,6 +736,32 @@ export class Pool {
|
|
|
703
736
|
return tx;
|
|
704
737
|
}
|
|
705
738
|
|
|
739
|
+
/**
|
|
740
|
+
* Witdraw asset from a COmpound V3 style lending pool
|
|
741
|
+
* @param {string} market Address of market e.g cUSDCv3 address
|
|
742
|
+
* @param {string} asset Asset
|
|
743
|
+
* @param {BigNumber | string} amount Amount of asset to withdraw
|
|
744
|
+
* @param {any} options Transaction options
|
|
745
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
746
|
+
* @returns {Promise<any>} Transaction
|
|
747
|
+
*/
|
|
748
|
+
async withdrawCompoundV3(
|
|
749
|
+
market: string,
|
|
750
|
+
asset: string,
|
|
751
|
+
amount: BigNumber | string,
|
|
752
|
+
options: any = null,
|
|
753
|
+
estimateGas = false
|
|
754
|
+
): Promise<any> {
|
|
755
|
+
const withdrawTxData = getCompoundV3WithdrawTxData(asset, amount);
|
|
756
|
+
|
|
757
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
758
|
+
this,
|
|
759
|
+
[market, withdrawTxData, options],
|
|
760
|
+
estimateGas
|
|
761
|
+
);
|
|
762
|
+
return tx;
|
|
763
|
+
}
|
|
764
|
+
|
|
706
765
|
/**
|
|
707
766
|
* Borrow asset from a lending pool
|
|
708
767
|
* @param {Dapp} dapp Platform like Aave
|
|
@@ -980,7 +1039,7 @@ export class Pool {
|
|
|
980
1039
|
|
|
981
1040
|
/**
|
|
982
1041
|
* Create UniswapV3 liquidity pool
|
|
983
|
-
* @param {dapp} Platform UniswapV3, VelodromeCL or
|
|
1042
|
+
* @param {dapp} Platform UniswapV3, VelodromeCL, AerodromeCL or RamesesCL
|
|
984
1043
|
* @param {string} assetA First asset
|
|
985
1044
|
* @param {string} assetB Second asset
|
|
986
1045
|
* @param {BigNumber | string} amountA Amount first asset
|
|
@@ -995,7 +1054,7 @@ export class Pool {
|
|
|
995
1054
|
* @returns {Promise<any>} Transaction
|
|
996
1055
|
*/
|
|
997
1056
|
async addLiquidityUniswapV3(
|
|
998
|
-
dapp: Dapp.UNISWAPV3 | Dapp.VELODROMECL | Dapp.AERODROMECL,
|
|
1057
|
+
dapp: Dapp.UNISWAPV3 | Dapp.VELODROMECL | Dapp.AERODROMECL | Dapp.RAMSESCL,
|
|
999
1058
|
assetA: string,
|
|
1000
1059
|
assetB: string,
|
|
1001
1060
|
amountA: BigNumber | string,
|
|
@@ -1063,6 +1122,7 @@ export class Pool {
|
|
|
1063
1122
|
let txData;
|
|
1064
1123
|
switch (dapp) {
|
|
1065
1124
|
case Dapp.UNISWAPV3:
|
|
1125
|
+
case Dapp.RAMSESCL:
|
|
1066
1126
|
dappAddress = nonfungiblePositionManagerAddress[this.network][dapp];
|
|
1067
1127
|
break;
|
|
1068
1128
|
case Dapp.VELODROMECL:
|
|
@@ -1120,6 +1180,7 @@ export class Pool {
|
|
|
1120
1180
|
let txData;
|
|
1121
1181
|
switch (dapp) {
|
|
1122
1182
|
case Dapp.UNISWAPV3:
|
|
1183
|
+
case Dapp.RAMSESCL:
|
|
1123
1184
|
dappAddress = nonfungiblePositionManagerAddress[this.network][dapp];
|
|
1124
1185
|
break;
|
|
1125
1186
|
case Dapp.VELODROMECL:
|
|
@@ -1181,6 +1242,7 @@ export class Pool {
|
|
|
1181
1242
|
);
|
|
1182
1243
|
switch (dapp) {
|
|
1183
1244
|
case Dapp.UNISWAPV3:
|
|
1245
|
+
case Dapp.RAMSESCL:
|
|
1184
1246
|
contractAddress = nonfungiblePositionManagerAddress[this.network][dapp];
|
|
1185
1247
|
txData = iNonfungiblePositionManager.encodeFunctionData(
|
|
1186
1248
|
Transaction.COLLECT,
|
|
@@ -1230,6 +1292,34 @@ export class Pool {
|
|
|
1230
1292
|
return tx;
|
|
1231
1293
|
}
|
|
1232
1294
|
|
|
1295
|
+
/**
|
|
1296
|
+
* Get rewards of an NFT position
|
|
1297
|
+
* @param {Dapp} dapp Platform e.g. Ramses CL
|
|
1298
|
+
* @param {string} tokenId Token Id
|
|
1299
|
+
* @param {string[]} rewards Reward tokens
|
|
1300
|
+
* @param {any} options Transaction option
|
|
1301
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1302
|
+
* @returns {Promise<any>} Transaction
|
|
1303
|
+
*/
|
|
1304
|
+
async getRewards(
|
|
1305
|
+
dapp: Dapp,
|
|
1306
|
+
tokenId: string,
|
|
1307
|
+
rewards: string[],
|
|
1308
|
+
options: any = null,
|
|
1309
|
+
estimateGas = false
|
|
1310
|
+
): Promise<any> {
|
|
1311
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
1312
|
+
this,
|
|
1313
|
+
[
|
|
1314
|
+
nonfungiblePositionManagerAddress[this.network][dapp],
|
|
1315
|
+
getRewardsTxDta(tokenId, rewards),
|
|
1316
|
+
options
|
|
1317
|
+
],
|
|
1318
|
+
estimateGas
|
|
1319
|
+
);
|
|
1320
|
+
return tx;
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1233
1323
|
/**
|
|
1234
1324
|
* Trade an asset into another asset
|
|
1235
1325
|
* @param {Dapp} dapp Platform like Sushiswap or Uniswap
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ethers } from "../..";
|
|
2
|
+
import ICompoundV3Comet from "../../abi/compound/ICompoundV3Comet.json";
|
|
3
|
+
|
|
4
|
+
export function getCompoundV3LendTxData(
|
|
5
|
+
asset: string,
|
|
6
|
+
amount: ethers.BigNumber | string
|
|
7
|
+
): string {
|
|
8
|
+
return new ethers.utils.Interface(
|
|
9
|
+
ICompoundV3Comet
|
|
10
|
+
).encodeFunctionData("supply", [asset, amount]);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getCompoundV3WithdrawTxData(
|
|
14
|
+
asset: string,
|
|
15
|
+
amount: ethers.BigNumber | string
|
|
16
|
+
): string {
|
|
17
|
+
return new ethers.utils.Interface(
|
|
18
|
+
ICompoundV3Comet
|
|
19
|
+
).encodeFunctionData("withdraw", [asset, amount]);
|
|
20
|
+
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import { BigNumber, ethers } from "ethers";
|
|
3
3
|
import IXRam from "../../abi/IXRam.json";
|
|
4
|
+
import IRamsesNonfungiblePositionManager from "../../abi/IRamsesNonfungiblePositionManager.json";
|
|
4
5
|
|
|
5
6
|
const iXRam = new ethers.utils.Interface(IXRam.abi);
|
|
7
|
+
const iRamsesNonfungiblePositionManager = new ethers.utils.Interface(
|
|
8
|
+
IRamsesNonfungiblePositionManager
|
|
9
|
+
);
|
|
6
10
|
|
|
7
11
|
export function getCreateVestTxData(amount: BigNumber | string): string {
|
|
8
12
|
return iXRam.encodeFunctionData("createVest", [amount]);
|
|
@@ -11,3 +15,10 @@ export function getCreateVestTxData(amount: BigNumber | string): string {
|
|
|
11
15
|
export function getExitVestTxData(vestId: number): string {
|
|
12
16
|
return iXRam.encodeFunctionData("exitVest", [vestId, false]);
|
|
13
17
|
}
|
|
18
|
+
|
|
19
|
+
export function getRewardsTxDta(tokenId: string, rewards: string[]): string {
|
|
20
|
+
return iRamsesNonfungiblePositionManager.encodeFunctionData("getReward", [
|
|
21
|
+
tokenId,
|
|
22
|
+
rewards
|
|
23
|
+
]);
|
|
24
|
+
}
|
|
@@ -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 IRamsesPositionManager from "../../abi/IRamsesNonfungiblePositionManager.json";
|
|
22
23
|
import IArrakisV1RouterStaking from "../../abi/IArrakisV1RouterStaking.json";
|
|
23
24
|
import { getDeadline } from "../../utils/deadline";
|
|
24
25
|
import BigNumber from "bignumber.js";
|
|
@@ -70,7 +71,7 @@ export function tryParseTick(
|
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
export async function getUniswapV3MintTxData(
|
|
73
|
-
dapp: Dapp.UNISWAPV3 | Dapp.VELODROMECL | Dapp.AERODROMECL,
|
|
74
|
+
dapp: Dapp.UNISWAPV3 | Dapp.VELODROMECL | Dapp.AERODROMECL | Dapp.RAMSESCL,
|
|
74
75
|
pool: Pool,
|
|
75
76
|
assetA: string,
|
|
76
77
|
assetB: string,
|
|
@@ -154,6 +155,13 @@ export async function getUniswapV3MintTxData(
|
|
|
154
155
|
mintParams.push(0);
|
|
155
156
|
}
|
|
156
157
|
|
|
158
|
+
if (dapp === Dapp.RAMSESCL) {
|
|
159
|
+
iNonfungiblePositionManager = new ethers.utils.Interface(
|
|
160
|
+
IRamsesPositionManager
|
|
161
|
+
);
|
|
162
|
+
mintParams.push(0);
|
|
163
|
+
}
|
|
164
|
+
|
|
157
165
|
return iNonfungiblePositionManager.encodeFunctionData(Transaction.MINT, [
|
|
158
166
|
mintParams
|
|
159
167
|
]);
|
|
@@ -162,7 +170,7 @@ export async function getUniswapV3MintTxData(
|
|
|
162
170
|
}
|
|
163
171
|
|
|
164
172
|
export async function getUniswapV3Liquidity(
|
|
165
|
-
dapp: Dapp.UNISWAPV3 | Dapp.VELODROMECL | Dapp.AERODROMECL,
|
|
173
|
+
dapp: Dapp.UNISWAPV3 | Dapp.VELODROMECL | Dapp.AERODROMECL | Dapp.RAMSESCL,
|
|
166
174
|
tokenId: string,
|
|
167
175
|
pool: Pool
|
|
168
176
|
): Promise<BigNumber> {
|
|
@@ -187,7 +195,8 @@ export async function getIncreaseLiquidityTxData(
|
|
|
187
195
|
if (
|
|
188
196
|
dapp === Dapp.UNISWAPV3 ||
|
|
189
197
|
dapp === Dapp.VELODROMECL ||
|
|
190
|
-
dapp === Dapp.AERODROMECL
|
|
198
|
+
dapp === Dapp.AERODROMECL ||
|
|
199
|
+
dapp === Dapp.RAMSESCL
|
|
191
200
|
) {
|
|
192
201
|
const abi = new ethers.utils.Interface(INonfungiblePositionManager.abi);
|
|
193
202
|
txData = abi.encodeFunctionData(Transaction.INCREASE_LIQUIDITY, [
|
|
@@ -221,7 +230,8 @@ export async function getDecreaseLiquidityTxData(
|
|
|
221
230
|
if (
|
|
222
231
|
dapp === Dapp.UNISWAPV3 ||
|
|
223
232
|
dapp === Dapp.VELODROMECL ||
|
|
224
|
-
dapp === Dapp.AERODROMECL
|
|
233
|
+
dapp === Dapp.AERODROMECL ||
|
|
234
|
+
dapp === Dapp.RAMSESCL
|
|
225
235
|
) {
|
|
226
236
|
const abi = new ethers.utils.Interface(INonfungiblePositionManager.abi);
|
|
227
237
|
const liquidity = (await getUniswapV3Liquidity(dapp, tokenId, pool))
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
4
|
+
import { Dhedge, Pool } from "..";
|
|
5
|
+
import { AssetEnabled, Network } from "../types";
|
|
6
|
+
import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
|
|
7
|
+
import {
|
|
8
|
+
TestingRunParams,
|
|
9
|
+
beforeAfterReset,
|
|
10
|
+
setWETHAmount,
|
|
11
|
+
testingHelper
|
|
12
|
+
} from "./utils/testingHelper";
|
|
13
|
+
import { allowanceDelta, balanceDelta } from "./utils/token";
|
|
14
|
+
import { getWalletData } from "./wallet";
|
|
15
|
+
|
|
16
|
+
const testCompoundV3 = ({ network, provider }: TestingRunParams) => {
|
|
17
|
+
const WETH = CONTRACT_ADDRESS[network].WETH;
|
|
18
|
+
const COMPOUNDV3_WETH = CONTRACT_ADDRESS[network].COMPOUNDV3_WETH;
|
|
19
|
+
|
|
20
|
+
let dhedge: Dhedge;
|
|
21
|
+
let pool: Pool;
|
|
22
|
+
jest.setTimeout(100000);
|
|
23
|
+
|
|
24
|
+
describe(`[${network}] compound V3 tests`, () => {
|
|
25
|
+
beforeAll(async () => {
|
|
26
|
+
const { wallet } = getWalletData(network);
|
|
27
|
+
// top up ETH (gas)
|
|
28
|
+
await provider.send("hardhat_setBalance", [
|
|
29
|
+
wallet.address,
|
|
30
|
+
"0x100000000000000"
|
|
31
|
+
]);
|
|
32
|
+
dhedge = new Dhedge(wallet, network);
|
|
33
|
+
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
34
|
+
await setWETHAmount({
|
|
35
|
+
amount: new BigNumber(1e18).toFixed(0),
|
|
36
|
+
userAddress: pool.address,
|
|
37
|
+
network,
|
|
38
|
+
provider
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const newAssets: AssetEnabled[] = [
|
|
42
|
+
{ asset: WETH, isDeposit: true },
|
|
43
|
+
{
|
|
44
|
+
asset: COMPOUNDV3_WETH,
|
|
45
|
+
isDeposit: false
|
|
46
|
+
}
|
|
47
|
+
];
|
|
48
|
+
await pool.managerLogic.changeAssets(newAssets, []);
|
|
49
|
+
});
|
|
50
|
+
beforeAfterReset({ beforeAll, afterAll, provider });
|
|
51
|
+
|
|
52
|
+
it("approves unlimited WETH for cWETHv3 market", async () => {
|
|
53
|
+
await pool.approveSpender(COMPOUNDV3_WETH, WETH, MAX_AMOUNT);
|
|
54
|
+
const UsdcAllowanceDelta = await allowanceDelta(
|
|
55
|
+
pool.address,
|
|
56
|
+
WETH,
|
|
57
|
+
COMPOUNDV3_WETH,
|
|
58
|
+
pool.signer
|
|
59
|
+
);
|
|
60
|
+
await expect(UsdcAllowanceDelta.gt(0));
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("lends WETH to CompundV3 WETH market", async () => {
|
|
64
|
+
const wethBalance = await pool.utils.getBalance(WETH, pool.address);
|
|
65
|
+
await pool.lendCompoundV3(COMPOUNDV3_WETH, WETH, wethBalance);
|
|
66
|
+
|
|
67
|
+
const cWETHTokenDelta = await balanceDelta(
|
|
68
|
+
pool.address,
|
|
69
|
+
COMPOUNDV3_WETH,
|
|
70
|
+
pool.signer
|
|
71
|
+
);
|
|
72
|
+
expect(cWETHTokenDelta.gt(0));
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("withdraw WETH from CompundV3 WETH market", async () => {
|
|
76
|
+
const cWETHBalance = await pool.utils.getBalance(
|
|
77
|
+
COMPOUNDV3_WETH,
|
|
78
|
+
pool.address
|
|
79
|
+
);
|
|
80
|
+
await pool.withdrawCompoundV3(COMPOUNDV3_WETH, WETH, cWETHBalance);
|
|
81
|
+
const wethBalance = await balanceDelta(pool.address, WETH, pool.signer);
|
|
82
|
+
expect(wethBalance.gt(0));
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
testingHelper({
|
|
88
|
+
network: Network.ARBITRUM,
|
|
89
|
+
testingRun: testCompoundV3
|
|
90
|
+
});
|
package/src/test/constants.ts
CHANGED
|
@@ -41,7 +41,7 @@ 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]: "
|
|
44
|
+
[Network.ARBITRUM]: "0x0b5f6591c8eb23e5a68102d3d39ebbb464ee5c14",
|
|
45
45
|
[Network.BASE]: "0x4842b42F68524383F609aa46eAfc18c1459cE3cD"
|
|
46
46
|
};
|
|
47
47
|
|
|
@@ -59,7 +59,8 @@ export const CONTRACT_ADDRESS = {
|
|
|
59
59
|
nonfungiblePositionManager: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88"
|
|
60
60
|
},
|
|
61
61
|
VELODROME_CL_USDC_WETH_GAUGE: "",
|
|
62
|
-
VELO: ""
|
|
62
|
+
VELO: "",
|
|
63
|
+
COMPOUNDV3_WETH: ""
|
|
63
64
|
},
|
|
64
65
|
|
|
65
66
|
[Network.OPTIMISM]: {
|
|
@@ -79,7 +80,8 @@ export const CONTRACT_ADDRESS = {
|
|
|
79
80
|
ARRAKIS_USDC_WETH_GAUGE: "",
|
|
80
81
|
ARRAKIS_USDC_WETH_LP: "",
|
|
81
82
|
VELODROME_CL_USDC_WETH_GAUGE: "0xa75127121d28a9BF848F3B70e7Eea26570aa7700",
|
|
82
|
-
VELO: "0x9560e827aF36c94D2Ac33a39bCE1Fe78631088Db"
|
|
83
|
+
VELO: "0x9560e827aF36c94D2Ac33a39bCE1Fe78631088Db",
|
|
84
|
+
COMPOUNDV3_WETH: ""
|
|
83
85
|
},
|
|
84
86
|
[Network.ARBITRUM]: {
|
|
85
87
|
USDC: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
@@ -100,7 +102,8 @@ export const CONTRACT_ADDRESS = {
|
|
|
100
102
|
ARRAKIS_USDC_WETH_LP: "",
|
|
101
103
|
WMATIC: "",
|
|
102
104
|
VELODROME_CL_USDC_WETH_GAUGE: "",
|
|
103
|
-
VELO: ""
|
|
105
|
+
VELO: "",
|
|
106
|
+
COMPOUNDV3_WETH: "0x6f7D514bbD4aFf3BcD1140B7344b32f063dEe486"
|
|
104
107
|
},
|
|
105
108
|
[Network.BASE]: {
|
|
106
109
|
USDC: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
|
|
@@ -116,7 +119,8 @@ export const CONTRACT_ADDRESS = {
|
|
|
116
119
|
ARRAKIS_USDC_WETH_LP: "",
|
|
117
120
|
WMATIC: "",
|
|
118
121
|
VELODROME_CL_USDC_WETH_GAUGE: "0xF33a96b5932D9E9B9A0eDA447AbD8C9d48d2e0c8",
|
|
119
|
-
VELO: "0x940181a94A35A4569E4529A3CDfB74e38FD98631"
|
|
122
|
+
VELO: "0x940181a94A35A4569E4529A3CDfB74e38FD98631",
|
|
123
|
+
COMPOUNDV3_WETH: ""
|
|
120
124
|
}
|
|
121
125
|
};
|
|
122
126
|
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Dhedge, Pool, ethers } from "..";
|
|
2
|
+
|
|
3
|
+
import { nonfungiblePositionManagerAddress } from "../config";
|
|
4
|
+
import { AssetEnabled, Dapp, Network } from "../types";
|
|
5
|
+
import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
|
|
6
|
+
import {
|
|
7
|
+
TestingRunParams,
|
|
8
|
+
beforeAfterReset,
|
|
9
|
+
setChainlinkTimeout,
|
|
10
|
+
testingHelper
|
|
11
|
+
} from "./utils/testingHelper";
|
|
12
|
+
import { allowanceDelta, balanceDelta } from "./utils/token";
|
|
13
|
+
import INonfungiblePositionManager from "../abi/INonfungiblePositionManager.json";
|
|
14
|
+
|
|
15
|
+
const testRamsesCL = ({ wallet, network, provider }: TestingRunParams) => {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
17
|
+
const RAMSES_POSITION_MANGER = nonfungiblePositionManagerAddress[network][
|
|
18
|
+
Dapp.RAMSESCL
|
|
19
|
+
]!;
|
|
20
|
+
|
|
21
|
+
const USDC = CONTRACT_ADDRESS[network].USDC;
|
|
22
|
+
const WETH = CONTRACT_ADDRESS[network].WETH;
|
|
23
|
+
//if other chains then define per network
|
|
24
|
+
const RAM = "0xaaa6c1e32c55a7bfa8066a6fae9b42650f262418";
|
|
25
|
+
const ARB = "0x912ce59144191c1204e64559fe8253a0e49e6548";
|
|
26
|
+
|
|
27
|
+
let dhedge: Dhedge;
|
|
28
|
+
let pool: Pool;
|
|
29
|
+
let ramsesPositionManager: ethers.Contract;
|
|
30
|
+
let tokenId: string;
|
|
31
|
+
jest.setTimeout(100000);
|
|
32
|
+
|
|
33
|
+
describe(`[${network}] Ramses CL tests`, () => {
|
|
34
|
+
beforeAll(async () => {
|
|
35
|
+
// top up ETH (gas)
|
|
36
|
+
await provider.send("hardhat_setBalance", [
|
|
37
|
+
wallet.address,
|
|
38
|
+
"0x100000000000000"
|
|
39
|
+
]);
|
|
40
|
+
dhedge = new Dhedge(wallet, network);
|
|
41
|
+
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
42
|
+
|
|
43
|
+
// setChainlinkTimeout
|
|
44
|
+
await setChainlinkTimeout({ pool, provider }, 86400 * 365);
|
|
45
|
+
|
|
46
|
+
const newAssets: AssetEnabled[] = [
|
|
47
|
+
{ asset: USDC, isDeposit: true },
|
|
48
|
+
{ asset: WETH, isDeposit: true },
|
|
49
|
+
{
|
|
50
|
+
asset: RAMSES_POSITION_MANGER,
|
|
51
|
+
isDeposit: false
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
asset: ARB,
|
|
55
|
+
isDeposit: false
|
|
56
|
+
}
|
|
57
|
+
];
|
|
58
|
+
await pool.changeAssets(newAssets);
|
|
59
|
+
await pool.approve(Dapp.ONEINCH, USDC, MAX_AMOUNT);
|
|
60
|
+
await pool.trade(Dapp.ONEINCH, USDC, WETH, (2.5 * 1e6).toString());
|
|
61
|
+
|
|
62
|
+
ramsesPositionManager = new ethers.Contract(
|
|
63
|
+
RAMSES_POSITION_MANGER,
|
|
64
|
+
INonfungiblePositionManager.abi,
|
|
65
|
+
pool.signer
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
beforeAfterReset({ beforeAll, afterAll, provider });
|
|
70
|
+
|
|
71
|
+
describe("Liquidity", () => {
|
|
72
|
+
it("approves unlimited USDC and WETH on for Velodrome CL", async () => {
|
|
73
|
+
await pool.approveSpender(RAMSES_POSITION_MANGER, USDC, MAX_AMOUNT);
|
|
74
|
+
await pool.approveSpender(RAMSES_POSITION_MANGER, WETH, MAX_AMOUNT);
|
|
75
|
+
const UsdcAllowanceDelta = await allowanceDelta(
|
|
76
|
+
pool.address,
|
|
77
|
+
USDC,
|
|
78
|
+
RAMSES_POSITION_MANGER,
|
|
79
|
+
pool.signer
|
|
80
|
+
);
|
|
81
|
+
await expect(UsdcAllowanceDelta.gt(0));
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("adds USDC and WETH to a Velodrome CL (mint position)", async () => {
|
|
85
|
+
const usdcBalance = await pool.utils.getBalance(USDC, pool.address);
|
|
86
|
+
const wethBalance = await pool.utils.getBalance(WETH, pool.address);
|
|
87
|
+
await pool.addLiquidityUniswapV3(
|
|
88
|
+
Dapp.RAMSESCL,
|
|
89
|
+
WETH,
|
|
90
|
+
USDC,
|
|
91
|
+
usdcBalance.div(2),
|
|
92
|
+
wethBalance.div(2),
|
|
93
|
+
null,
|
|
94
|
+
null,
|
|
95
|
+
-204460,
|
|
96
|
+
-193470,
|
|
97
|
+
500
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
tokenId = (
|
|
101
|
+
await ramsesPositionManager.tokenOfOwnerByIndex(pool.address, 0)
|
|
102
|
+
).toString();
|
|
103
|
+
expect(tokenId).not.toBe(null);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("increases liquidity in a CL position", async () => {
|
|
107
|
+
const usdcBalance = await pool.utils.getBalance(USDC, pool.address);
|
|
108
|
+
const wethBalance = await pool.utils.getBalance(WETH, pool.address);
|
|
109
|
+
const positionBefore = await ramsesPositionManager.positions(tokenId);
|
|
110
|
+
await pool.increaseLiquidity(
|
|
111
|
+
Dapp.RAMSESCL,
|
|
112
|
+
tokenId,
|
|
113
|
+
usdcBalance.div(2),
|
|
114
|
+
wethBalance.div(2)
|
|
115
|
+
);
|
|
116
|
+
const positionAfter = await ramsesPositionManager.positions(tokenId);
|
|
117
|
+
expect(positionAfter.liquidity.gt(positionBefore.liquidity));
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("decreases liquidity from a CL position", async () => {
|
|
121
|
+
const positionBefore = await ramsesPositionManager.positions(tokenId);
|
|
122
|
+
await pool.decreaseLiquidity(Dapp.RAMSESCL, tokenId, 50);
|
|
123
|
+
const positionAfter = await ramsesPositionManager.positions(tokenId);
|
|
124
|
+
expect(positionAfter.liquidity.lt(positionBefore.liquidity));
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("collects fess of a CL position", async () => {
|
|
128
|
+
await provider.send("evm_increaseTime", [24 * 3600 * 3]); // 1 day
|
|
129
|
+
await provider.send("evm_mine", []);
|
|
130
|
+
await pool.claimFees(Dapp.RAMSESCL, tokenId);
|
|
131
|
+
expect((await balanceDelta(pool.address, USDC, pool.signer)).gt(0));
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("get rewards of a CL position", async () => {
|
|
135
|
+
await provider.send("evm_increaseTime", [24 * 3600 * 3]); // 1 day
|
|
136
|
+
await provider.send("evm_mine", []);
|
|
137
|
+
await pool.getRewards(Dapp.RAMSESCL, tokenId, [RAM]);
|
|
138
|
+
expect((await balanceDelta(pool.address, RAM, pool.signer)).gt(0));
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("decreases 100% liquidity and burns a CL position", async () => {
|
|
142
|
+
await pool.decreaseLiquidity(Dapp.RAMSESCL, tokenId, 100);
|
|
143
|
+
const positionAfter = await ramsesPositionManager.balanceOf(
|
|
144
|
+
pool.address
|
|
145
|
+
);
|
|
146
|
+
expect(positionAfter.eq(0));
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
testingHelper({
|
|
153
|
+
network: Network.ARBITRUM,
|
|
154
|
+
testingRun: testRamsesCL
|
|
155
|
+
});
|