@dhedge/v2-sdk 1.10.4 → 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 +12 -2
- package/dist/services/ramses/vesting.d.ts +1 -0
- package/dist/services/uniswap/V3Liquidity.d.ts +2 -2
- package/dist/types.d.ts +2 -1
- package/dist/v2-sdk.cjs.development.js +772 -223
- 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 +772 -223
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/IRamsesNonfungiblePositionManager.json +486 -0
- package/src/config.ts +2 -1
- package/src/entities/pool.ts +35 -3
- package/src/services/ramses/vesting.ts +11 -0
- package/src/services/uniswap/V3Liquidity.ts +14 -4
- package/src/test/constants.ts +1 -1
- package/src/test/ramsesCL.test.ts +155 -0
- package/src/types.ts +2 -1
|
@@ -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
|
+
});
|