@dhedge/v2-sdk 1.10.4 → 1.10.6
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 +29 -0
- package/dist/entities/pool.d.ts +21 -2
- package/dist/services/oneInch/index.d.ts +4 -1
- package/dist/services/ramses/vesting.d.ts +1 -0
- package/dist/services/toros/easySwapper.d.ts +2 -1
- package/dist/services/uniswap/V3Liquidity.d.ts +2 -2
- package/dist/test/constants.d.ts +7 -0
- package/dist/test/utils/testingHelper.d.ts +0 -1
- package/dist/types.d.ts +2 -1
- package/dist/v2-sdk.cjs.development.js +1748 -1988
- 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 +1748 -1988
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/IDhedgeEasySwapper.json +184 -303
- package/src/abi/IRamsesNonfungiblePositionManager.json +486 -0
- package/src/config.ts +8 -5
- package/src/entities/pool.ts +68 -6
- package/src/services/oneInch/index.ts +9 -6
- package/src/services/ramses/vesting.ts +11 -0
- package/src/services/toros/easySwapper.ts +64 -22
- package/src/services/uniswap/V3Liquidity.ts +14 -4
- package/src/test/constants.ts +12 -5
- package/src/test/ramsesCL.test.ts +155 -0
- package/src/test/toros.test.ts +81 -53
- package/src/test/utils/testingHelper.ts +3 -2
- package/src/types.ts +2 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import axios from "axios";
|
|
3
3
|
import { ApiError, ethers } from "../..";
|
|
4
|
-
import { networkChainIdMap } from "../../config";
|
|
4
|
+
import { networkChainIdMap, routerAddress } from "../../config";
|
|
5
5
|
import { Pool } from "../../entities";
|
|
6
6
|
|
|
7
7
|
const oneInchBaseUrl = "https://api.1inch.dev/swap/v6.0/";
|
|
@@ -11,8 +11,9 @@ export async function getOneInchSwapTxData(
|
|
|
11
11
|
assetFrom: string,
|
|
12
12
|
assetTo: string,
|
|
13
13
|
amountIn: ethers.BigNumber | string,
|
|
14
|
-
slippage: number
|
|
15
|
-
|
|
14
|
+
slippage: number,
|
|
15
|
+
forEasySwapper = false
|
|
16
|
+
): Promise<{ swapTxData: string; dstAmount: string }> {
|
|
16
17
|
if (!process.env.ONEINCH_API_KEY)
|
|
17
18
|
throw new Error("ONEINCH_API_KEY not configured in .env file");
|
|
18
19
|
|
|
@@ -22,8 +23,8 @@ export async function getOneInchSwapTxData(
|
|
|
22
23
|
src: assetFrom,
|
|
23
24
|
dst: assetTo,
|
|
24
25
|
amount: amountIn.toString(),
|
|
25
|
-
from: pool.address,
|
|
26
|
-
|
|
26
|
+
from: forEasySwapper ? routerAddress[pool.network].toros : pool.address,
|
|
27
|
+
receiver: forEasySwapper ? routerAddress[pool.network].toros : pool.address,
|
|
27
28
|
slippage: slippage,
|
|
28
29
|
disableEstimate: true,
|
|
29
30
|
usePermit2: false
|
|
@@ -35,7 +36,9 @@ export async function getOneInchSwapTxData(
|
|
|
35
36
|
},
|
|
36
37
|
params
|
|
37
38
|
});
|
|
38
|
-
|
|
39
|
+
const swapTxData = response.data.tx.data;
|
|
40
|
+
const dstAmount = response.data.dstAmount;
|
|
41
|
+
return { swapTxData, dstAmount };
|
|
39
42
|
} catch (e) {
|
|
40
43
|
throw new ApiError("Swap api request of 1inch failed");
|
|
41
44
|
}
|
|
@@ -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
|
+
}
|
|
@@ -5,6 +5,8 @@ import IDhedgeEasySwapper from "../../abi/IDhedgeEasySwapper.json";
|
|
|
5
5
|
import { routerAddress } from "../../config";
|
|
6
6
|
import { getChainlinkPriceInUsd } from "../chainLink/price";
|
|
7
7
|
import { isPool, loadPool } from "./pool";
|
|
8
|
+
import { getOneInchSwapTxData } from "../oneInch";
|
|
9
|
+
import { wait } from "../../test/utils/testingHelper";
|
|
8
10
|
|
|
9
11
|
export async function getPoolDepositAsset(
|
|
10
12
|
pool: Pool,
|
|
@@ -33,22 +35,15 @@ export async function getEasySwapperDepositQuote(
|
|
|
33
35
|
pool: Pool,
|
|
34
36
|
torosAsset: string,
|
|
35
37
|
investAsset: string,
|
|
36
|
-
depositAsset: string,
|
|
37
38
|
amountIn: ethers.BigNumber
|
|
38
39
|
): Promise<ethers.BigNumber> {
|
|
39
40
|
const easySwapper = new ethers.Contract(
|
|
40
41
|
routerAddress[pool.network][Dapp.TOROS] as string,
|
|
41
|
-
IDhedgeEasySwapper
|
|
42
|
+
IDhedgeEasySwapper,
|
|
42
43
|
pool.signer
|
|
43
44
|
);
|
|
44
45
|
|
|
45
|
-
return await easySwapper.depositQuote(
|
|
46
|
-
torosAsset,
|
|
47
|
-
investAsset,
|
|
48
|
-
amountIn,
|
|
49
|
-
depositAsset,
|
|
50
|
-
true
|
|
51
|
-
);
|
|
46
|
+
return await easySwapper.depositQuote(torosAsset, investAsset, amountIn);
|
|
52
47
|
}
|
|
53
48
|
|
|
54
49
|
export async function getEasySwapperWithdrawalQuote(
|
|
@@ -82,19 +77,12 @@ export async function getEasySwapperTxData(
|
|
|
82
77
|
const [torosAsset, investAsset] = isWithdrawal
|
|
83
78
|
? [assetFrom, assetTo]
|
|
84
79
|
: [assetTo, assetFrom];
|
|
85
|
-
const iDhedgeEasySwapper = new ethers.utils.Interface(IDhedgeEasySwapper
|
|
80
|
+
const iDhedgeEasySwapper = new ethers.utils.Interface(IDhedgeEasySwapper);
|
|
86
81
|
if (isWithdrawal) {
|
|
87
|
-
|
|
88
|
-
pool,
|
|
89
|
-
torosAsset,
|
|
90
|
-
investAsset,
|
|
91
|
-
amountIn
|
|
92
|
-
);
|
|
93
|
-
return iDhedgeEasySwapper.encodeFunctionData("withdraw", [
|
|
82
|
+
return iDhedgeEasySwapper.encodeFunctionData("initWithdrawal", [
|
|
94
83
|
torosAsset,
|
|
95
84
|
amountIn,
|
|
96
|
-
|
|
97
|
-
minAmountOut.mul(10000 - slippage * 100).div(10000)
|
|
85
|
+
slippage * 100
|
|
98
86
|
]);
|
|
99
87
|
} else {
|
|
100
88
|
const depositAsset = await getPoolDepositAsset(
|
|
@@ -103,19 +91,73 @@ export async function getEasySwapperTxData(
|
|
|
103
91
|
investAsset
|
|
104
92
|
);
|
|
105
93
|
if (!depositAsset) throw new Error("no deposit assets");
|
|
94
|
+
if (depositAsset.toLowerCase() !== investAsset.toLowerCase())
|
|
95
|
+
throw new Error("can only trade deposit asset");
|
|
106
96
|
const minAmountOut = await getEasySwapperDepositQuote(
|
|
107
97
|
pool,
|
|
108
98
|
torosAsset,
|
|
109
99
|
investAsset,
|
|
110
|
-
depositAsset,
|
|
111
100
|
amountIn
|
|
112
101
|
);
|
|
113
102
|
return iDhedgeEasySwapper.encodeFunctionData("depositWithCustomCooldown", [
|
|
114
103
|
torosAsset,
|
|
115
|
-
investAsset,
|
|
116
|
-
amountIn,
|
|
117
104
|
depositAsset,
|
|
105
|
+
amountIn,
|
|
118
106
|
minAmountOut.mul(10000 - slippage * 100).div(10000)
|
|
119
107
|
]);
|
|
120
108
|
}
|
|
121
109
|
}
|
|
110
|
+
|
|
111
|
+
export async function getCompleteWithdrawalTxData(
|
|
112
|
+
pool: Pool,
|
|
113
|
+
destToken: string,
|
|
114
|
+
slippage: number
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
116
|
+
): Promise<string> {
|
|
117
|
+
const easySwapper = new ethers.Contract(
|
|
118
|
+
routerAddress[pool.network][Dapp.TOROS] as string,
|
|
119
|
+
IDhedgeEasySwapper,
|
|
120
|
+
pool.signer
|
|
121
|
+
);
|
|
122
|
+
const trackedAssets: {
|
|
123
|
+
token: string;
|
|
124
|
+
balance: ethers.BigNumber;
|
|
125
|
+
}[] = await easySwapper.getTrackedAssets(pool.address);
|
|
126
|
+
const trackedAssetsExcludingDestToken = trackedAssets.filter(
|
|
127
|
+
({ token }) => token.toLowerCase() !== destToken.toLowerCase()
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const srcData = [];
|
|
131
|
+
let minDestAmount = ethers.BigNumber.from(0);
|
|
132
|
+
for (const { token, balance } of trackedAssetsExcludingDestToken) {
|
|
133
|
+
const { swapTxData, dstAmount } = await getOneInchSwapTxData(
|
|
134
|
+
pool,
|
|
135
|
+
token,
|
|
136
|
+
destToken,
|
|
137
|
+
balance,
|
|
138
|
+
slippage,
|
|
139
|
+
true
|
|
140
|
+
);
|
|
141
|
+
srcData.push({
|
|
142
|
+
token,
|
|
143
|
+
amount: balance,
|
|
144
|
+
aggregatorData: {
|
|
145
|
+
routerKey: ethers.utils.formatBytes32String("ONE_INCH"),
|
|
146
|
+
swapData: swapTxData
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
minDestAmount = minDestAmount.add(dstAmount);
|
|
150
|
+
await wait(2);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return easySwapper.interface.encodeFunctionData("completeWithdrawal", [
|
|
154
|
+
{
|
|
155
|
+
srcData,
|
|
156
|
+
destData: {
|
|
157
|
+
destToken,
|
|
158
|
+
minDestAmount
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
minDestAmount.mul(10000 - slippage * 100).div(10000)
|
|
162
|
+
]);
|
|
163
|
+
}
|
|
@@ -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))
|
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
|
|
|
@@ -49,6 +49,7 @@ export const CONTRACT_ADDRESS = {
|
|
|
49
49
|
[Network.POLYGON]: {
|
|
50
50
|
USDC: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
|
|
51
51
|
USDT: "",
|
|
52
|
+
SUSD: "",
|
|
52
53
|
SWETH: "",
|
|
53
54
|
WETH: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
|
|
54
55
|
WBTC: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
|
|
@@ -60,7 +61,8 @@ export const CONTRACT_ADDRESS = {
|
|
|
60
61
|
},
|
|
61
62
|
VELODROME_CL_USDC_WETH_GAUGE: "",
|
|
62
63
|
VELO: "",
|
|
63
|
-
COMPOUNDV3_WETH: ""
|
|
64
|
+
COMPOUNDV3_WETH: "",
|
|
65
|
+
TOROS: ""
|
|
64
66
|
},
|
|
65
67
|
|
|
66
68
|
[Network.OPTIMISM]: {
|
|
@@ -81,11 +83,13 @@ export const CONTRACT_ADDRESS = {
|
|
|
81
83
|
ARRAKIS_USDC_WETH_LP: "",
|
|
82
84
|
VELODROME_CL_USDC_WETH_GAUGE: "0xa75127121d28a9BF848F3B70e7Eea26570aa7700",
|
|
83
85
|
VELO: "0x9560e827aF36c94D2Ac33a39bCE1Fe78631088Db",
|
|
84
|
-
COMPOUNDV3_WETH: ""
|
|
86
|
+
COMPOUNDV3_WETH: "",
|
|
87
|
+
TOROS: "0x49bf093277bf4dde49c48c6aa55a3bda3eedef68" //USDmny
|
|
85
88
|
},
|
|
86
89
|
[Network.ARBITRUM]: {
|
|
87
90
|
USDC: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
88
91
|
USDT: "",
|
|
92
|
+
SUSD: "",
|
|
89
93
|
SWETH: "0xbc011A12Da28e8F0f528d9eE5E7039E22F91cf18",
|
|
90
94
|
WETH: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
|
|
91
95
|
WBTC: "0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f",
|
|
@@ -103,11 +107,13 @@ export const CONTRACT_ADDRESS = {
|
|
|
103
107
|
WMATIC: "",
|
|
104
108
|
VELODROME_CL_USDC_WETH_GAUGE: "",
|
|
105
109
|
VELO: "",
|
|
106
|
-
COMPOUNDV3_WETH: "0x6f7D514bbD4aFf3BcD1140B7344b32f063dEe486"
|
|
110
|
+
COMPOUNDV3_WETH: "0x6f7D514bbD4aFf3BcD1140B7344b32f063dEe486",
|
|
111
|
+
TOROS: ""
|
|
107
112
|
},
|
|
108
113
|
[Network.BASE]: {
|
|
109
114
|
USDC: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
|
|
110
115
|
USDT: "0xfde4c96c8593536e31f229ea8f37b2ada2699bb2",
|
|
116
|
+
SUSD: "",
|
|
111
117
|
WETH: "0x4200000000000000000000000000000000000006",
|
|
112
118
|
WBTC: "",
|
|
113
119
|
SWETH: "",
|
|
@@ -120,7 +126,8 @@ export const CONTRACT_ADDRESS = {
|
|
|
120
126
|
WMATIC: "",
|
|
121
127
|
VELODROME_CL_USDC_WETH_GAUGE: "0xF33a96b5932D9E9B9A0eDA447AbD8C9d48d2e0c8",
|
|
122
128
|
VELO: "0x940181a94A35A4569E4529A3CDfB74e38FD98631",
|
|
123
|
-
COMPOUNDV3_WETH: ""
|
|
129
|
+
COMPOUNDV3_WETH: "",
|
|
130
|
+
TOROS: ""
|
|
124
131
|
}
|
|
125
132
|
};
|
|
126
133
|
|
|
@@ -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
|
+
});
|
package/src/test/toros.test.ts
CHANGED
|
@@ -1,69 +1,97 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import { Dhedge, Pool } from "..";
|
|
4
4
|
import { routerAddress } from "../config";
|
|
5
|
+
|
|
5
6
|
import { Dapp, Network } from "../types";
|
|
6
7
|
import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
|
|
8
|
+
import {
|
|
9
|
+
TestingRunParams,
|
|
10
|
+
setChainlinkTimeout,
|
|
11
|
+
setUSDCAmount,
|
|
12
|
+
testingHelper
|
|
13
|
+
} from "./utils/testingHelper";
|
|
7
14
|
import { allowanceDelta, balanceDelta } from "./utils/token";
|
|
15
|
+
import BigNumber from "bignumber.js";
|
|
8
16
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const network = Network.OPTIMISM;
|
|
13
|
-
const SUSD = CONTRACT_ADDRESS[network].SUSD;
|
|
17
|
+
const testToros = ({ wallet, network, provider }: TestingRunParams) => {
|
|
18
|
+
const USDC = CONTRACT_ADDRESS[network].USDC;
|
|
19
|
+
const TOROS = CONTRACT_ADDRESS[network].TOROS;
|
|
14
20
|
|
|
15
|
-
let dhedge: Dhedge;
|
|
16
|
-
let pool: Pool;
|
|
17
|
-
jest.setTimeout(100000);
|
|
21
|
+
let dhedge: Dhedge;
|
|
22
|
+
let pool: Pool;
|
|
23
|
+
jest.setTimeout(100000);
|
|
18
24
|
|
|
19
|
-
describe(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
describe(`pool on ${network}`, () => {
|
|
26
|
+
beforeAll(async () => {
|
|
27
|
+
dhedge = new Dhedge(wallet, network);
|
|
28
|
+
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
29
|
+
await setChainlinkTimeout({ pool, provider }, 86400 * 365);
|
|
30
|
+
// top up gas
|
|
31
|
+
await provider.send("hardhat_setBalance", [
|
|
32
|
+
wallet.address,
|
|
33
|
+
"0x10000000000000000"
|
|
34
|
+
]);
|
|
35
|
+
await provider.send("evm_mine", []);
|
|
36
|
+
// top up USDC
|
|
37
|
+
const amount = new BigNumber(1000).times(1e6).toFixed(0);
|
|
38
|
+
await setUSDCAmount({
|
|
39
|
+
amount,
|
|
40
|
+
userAddress: pool.address,
|
|
41
|
+
network,
|
|
42
|
+
provider
|
|
43
|
+
});
|
|
44
|
+
});
|
|
24
45
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
46
|
+
it("approves unlimited USDC on Toros", async () => {
|
|
47
|
+
await pool.approve(Dapp.TOROS, USDC, MAX_AMOUNT);
|
|
48
|
+
const usdcAllowanceDelta = await allowanceDelta(
|
|
49
|
+
pool.address,
|
|
50
|
+
USDC,
|
|
51
|
+
routerAddress[network].toros!,
|
|
52
|
+
pool.signer
|
|
53
|
+
);
|
|
54
|
+
await expect(usdcAllowanceDelta.gt(0));
|
|
55
|
+
});
|
|
35
56
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
57
|
+
it("trades USDC balance into Toros Token", async () => {
|
|
58
|
+
const usdcBalance = await pool.utils.getBalance(USDC, pool.address);
|
|
59
|
+
await pool.trade(Dapp.TOROS, USDC, TOROS, usdcBalance, 1);
|
|
60
|
+
const torosBalanceDelta = await balanceDelta(
|
|
61
|
+
pool.address,
|
|
62
|
+
TOROS,
|
|
63
|
+
pool.signer
|
|
64
|
+
);
|
|
65
|
+
expect(torosBalanceDelta.gt(0));
|
|
66
|
+
});
|
|
46
67
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
pool.address
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
68
|
+
it("init Toros Token for withdrawal", async () => {
|
|
69
|
+
await provider.send("evm_increaseTime", [86400]);
|
|
70
|
+
await provider.send("evm_mine", []);
|
|
71
|
+
const torosBalance = await pool.utils.getBalance(TOROS, pool.address);
|
|
72
|
+
await pool.approve(Dapp.TOROS, TOROS, MAX_AMOUNT);
|
|
73
|
+
await pool.trade(Dapp.TOROS, TOROS, USDC, torosBalance, 1);
|
|
74
|
+
const torosBalanceDelta = await balanceDelta(
|
|
75
|
+
pool.address,
|
|
76
|
+
TOROS,
|
|
77
|
+
pool.signer
|
|
78
|
+
);
|
|
79
|
+
expect(torosBalanceDelta.lt(0));
|
|
80
|
+
});
|
|
57
81
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
82
|
+
it("complete withdrawal from Toros asset", async () => {
|
|
83
|
+
await pool.completeTorosWithdrawal(USDC, 1);
|
|
84
|
+
const usdcBalanceDelta = await balanceDelta(
|
|
85
|
+
pool.address,
|
|
86
|
+
USDC,
|
|
87
|
+
pool.signer
|
|
88
|
+
);
|
|
89
|
+
expect(usdcBalanceDelta.gt(0));
|
|
61
90
|
});
|
|
62
|
-
const ETHyBalanceDelta = await balanceDelta(
|
|
63
|
-
pool.address,
|
|
64
|
-
ETHy,
|
|
65
|
-
pool.signer
|
|
66
|
-
);
|
|
67
|
-
expect(ETHyBalanceDelta.gt(0));
|
|
68
91
|
});
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
testingHelper({
|
|
95
|
+
network: Network.OPTIMISM,
|
|
96
|
+
testingRun: testToros
|
|
69
97
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
2
|
import { BigNumber, Contract, ethers } from "ethers";
|
|
2
3
|
import { Network } from "../../types";
|
|
3
4
|
import { getWalletData } from "../wallet";
|
|
@@ -34,8 +35,8 @@ export const beforeAfterReset = ({
|
|
|
34
35
|
afterAll,
|
|
35
36
|
provider
|
|
36
37
|
}: {
|
|
37
|
-
beforeAll:
|
|
38
|
-
afterAll:
|
|
38
|
+
beforeAll: any;
|
|
39
|
+
afterAll: any;
|
|
39
40
|
provider: ethers.providers.JsonRpcProvider;
|
|
40
41
|
}): void => {
|
|
41
42
|
let snapshot = "";
|