@dhedge/v2-sdk 1.9.8 → 1.10.0
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 +34 -0
- package/dist/config.d.ts +8 -2
- package/dist/entities/pool.d.ts +39 -8
- package/dist/services/flatmoney/keeperFee.d.ts +6 -0
- package/dist/services/flatmoney/stableLp.d.ts +9 -0
- package/dist/services/flatmoney/stableModule.d.ts +4 -0
- package/dist/services/uniswap/V3Liquidity.d.ts +8 -7
- package/dist/services/uniswap/V3Trade.d.ts +1 -2
- package/dist/services/velodrome/liquidity.d.ts +7 -3
- package/dist/services/velodrome/staking.d.ts +1 -0
- package/dist/test/constants.d.ts +14 -0
- package/dist/test/utils/testingHelper.d.ts +8 -1
- package/dist/test/wallet.d.ts +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/v2-sdk.cjs.development.js +14286 -10087
- 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 +14292 -10093
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/abi/IERC721.json +217 -0
- package/src/abi/IVelodromeCLGauge.json +165 -0
- package/src/abi/IVelodromeNonfungiblePositionManager.json +408 -0
- package/src/abi/flatmoney/DelayedOrder.json +547 -0
- package/src/abi/flatmoney/IFlatcoinVault.json +570 -0
- package/src/abi/flatmoney/KeeperFee.json +364 -0
- package/src/abi/flatmoney/StableModule.json +770 -0
- package/src/config.ts +33 -6
- package/src/entities/pool.ts +208 -82
- package/src/services/flatmoney/keeperFee.ts +84 -0
- package/src/services/flatmoney/stableLp.ts +135 -0
- package/src/services/flatmoney/stableModule.ts +43 -0
- package/src/services/lyra/trade.ts +1 -1
- package/src/services/uniswap/V3Liquidity.ts +141 -18
- package/src/services/uniswap/V3Trade.ts +1 -2
- package/src/services/velodrome/liquidity.ts +77 -5
- package/src/services/velodrome/staking.ts +6 -0
- package/src/test/constants.ts +22 -6
- package/src/test/flatmoney.test.ts +164 -0
- package/src/test/uniswap.test.ts +24 -15
- package/src/test/utils/testingHelper.ts +29 -4
- package/src/test/velodromeCL.test.ts +223 -0
- package/src/test/wallet.ts +4 -1
- package/src/types.ts +1 -0
- package/dist/services/uniswap/types.d.ts +0 -3
- package/src/services/uniswap/types.ts +0 -16
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
import { Dhedge, Pool } from "../entities";
|
|
4
|
+
import { AssetEnabled, Network } from "../types";
|
|
5
|
+
import {
|
|
6
|
+
TestingRunParams,
|
|
7
|
+
setTokenAmount,
|
|
8
|
+
testingHelper
|
|
9
|
+
} from "./utils/testingHelper";
|
|
10
|
+
import { Contract, ethers } from "ethers";
|
|
11
|
+
import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
|
|
12
|
+
import { flatMoneyContractAddresses } from "../config";
|
|
13
|
+
import DelayedOrderAbi from "../abi/flatmoney/DelayedOrder.json";
|
|
14
|
+
import { allowanceDelta } from "./utils/token";
|
|
15
|
+
import { getKeeperFee } from "../services/flatmoney/keeperFee";
|
|
16
|
+
|
|
17
|
+
const RETH = "0xb6fe221fe9eef5aba221c348ba20a1bf5e73624c";
|
|
18
|
+
const RETH_SLOT = 0;
|
|
19
|
+
const UNIT = "0xb95fB324b8A2fAF8ec4f76e3dF46C718402736e2";
|
|
20
|
+
// https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/master/contracts/token/ERC20/ERC20Upgradeable.sol#L31
|
|
21
|
+
// https://eips.ethereum.org/EIPS/eip-7201
|
|
22
|
+
const UNIT_SLOT =
|
|
23
|
+
"0x52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace00";
|
|
24
|
+
|
|
25
|
+
const testFlatMoney = ({
|
|
26
|
+
wallet,
|
|
27
|
+
network,
|
|
28
|
+
provider,
|
|
29
|
+
rpcUrl
|
|
30
|
+
}: TestingRunParams) => {
|
|
31
|
+
let dhedge: Dhedge;
|
|
32
|
+
let pool: Pool;
|
|
33
|
+
let delayOrderContract: Contract;
|
|
34
|
+
jest.setTimeout(200000);
|
|
35
|
+
describe(`flatmoney on ${network}`, () => {
|
|
36
|
+
beforeAll(async () => {
|
|
37
|
+
dhedge = new Dhedge(wallet, network);
|
|
38
|
+
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
39
|
+
|
|
40
|
+
const flatMoneyContracts = flatMoneyContractAddresses[pool.network];
|
|
41
|
+
if (!flatMoneyContracts) {
|
|
42
|
+
throw new Error("testFlatMoney: network not supported");
|
|
43
|
+
}
|
|
44
|
+
delayOrderContract = new Contract(
|
|
45
|
+
flatMoneyContracts.DelayedOrder,
|
|
46
|
+
DelayedOrderAbi,
|
|
47
|
+
pool.signer
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
// top up gas
|
|
51
|
+
await provider.send("hardhat_setBalance", [
|
|
52
|
+
wallet.address,
|
|
53
|
+
"0x10000000000000000"
|
|
54
|
+
]);
|
|
55
|
+
await provider.send("evm_mine", []);
|
|
56
|
+
|
|
57
|
+
await setTokenAmount({
|
|
58
|
+
amount: new BigNumber(100).times(1e18).toString(),
|
|
59
|
+
provider,
|
|
60
|
+
tokenAddress: RETH,
|
|
61
|
+
slot: RETH_SLOT,
|
|
62
|
+
userAddress: pool.address
|
|
63
|
+
});
|
|
64
|
+
await setTokenAmount({
|
|
65
|
+
amount: new BigNumber(100).times(1e18).toString(),
|
|
66
|
+
provider,
|
|
67
|
+
tokenAddress: UNIT,
|
|
68
|
+
slot: UNIT_SLOT,
|
|
69
|
+
userAddress: pool.address
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const currentAssets: any[] = await pool.managerLogic.getSupportedAssets();
|
|
73
|
+
const exisitingAssets = currentAssets.map(item => {
|
|
74
|
+
return {
|
|
75
|
+
asset: item[0],
|
|
76
|
+
isDeposit: item[1]
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const newAssets: AssetEnabled[] = [
|
|
81
|
+
...exisitingAssets,
|
|
82
|
+
{ asset: CONTRACT_ADDRESS[network].USDC, isDeposit: true },
|
|
83
|
+
{ asset: CONTRACT_ADDRESS[network].WETH, isDeposit: true },
|
|
84
|
+
{
|
|
85
|
+
asset: UNIT,
|
|
86
|
+
isDeposit: false
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
asset: RETH,
|
|
90
|
+
isDeposit: false
|
|
91
|
+
}
|
|
92
|
+
];
|
|
93
|
+
await pool.changeAssets(newAssets);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("mint UNIT", async () => {
|
|
97
|
+
//approve
|
|
98
|
+
await pool.approveSpender(delayOrderContract.address, RETH, MAX_AMOUNT);
|
|
99
|
+
const collateralAllowanceDelta = await allowanceDelta(
|
|
100
|
+
pool.address,
|
|
101
|
+
RETH,
|
|
102
|
+
delayOrderContract.address,
|
|
103
|
+
pool.signer
|
|
104
|
+
);
|
|
105
|
+
await expect(collateralAllowanceDelta.gt(0));
|
|
106
|
+
|
|
107
|
+
const depositAmountStr = new BigNumber(1).times(1e18).toString();
|
|
108
|
+
const tx = await pool.mintUnitViaFlatMoney(
|
|
109
|
+
depositAmountStr,
|
|
110
|
+
0.5,
|
|
111
|
+
10, // set higher to tolerate high gasPrice returned by forked local chain
|
|
112
|
+
null,
|
|
113
|
+
false
|
|
114
|
+
);
|
|
115
|
+
expect(tx).not.toBe(null);
|
|
116
|
+
const existingOrder = await delayOrderContract.getAnnouncedOrder(
|
|
117
|
+
pool.address
|
|
118
|
+
);
|
|
119
|
+
expect(existingOrder.orderType).toBe(1);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("cancel order", async () => {
|
|
123
|
+
await provider.send("evm_increaseTime", [60 * 2]); // more than 1 min
|
|
124
|
+
await pool.cancelOrderViaFlatMoney();
|
|
125
|
+
const existingOrder = await delayOrderContract.getAnnouncedOrder(
|
|
126
|
+
pool.address
|
|
127
|
+
);
|
|
128
|
+
expect(existingOrder.orderType).toBe(0);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("redeem UNIT", async () => {
|
|
132
|
+
const withdrawAmountStr = new BigNumber(2).times(1e18).toString();
|
|
133
|
+
const tx = await pool.redeemUnitViaFlatMoney(
|
|
134
|
+
withdrawAmountStr,
|
|
135
|
+
0.5,
|
|
136
|
+
10, // set higher to tolerate high gasPrice returned by forked local chain
|
|
137
|
+
null,
|
|
138
|
+
false
|
|
139
|
+
);
|
|
140
|
+
expect(tx).not.toBe(null);
|
|
141
|
+
const existingOrder = await delayOrderContract.getAnnouncedOrder(
|
|
142
|
+
pool.address
|
|
143
|
+
);
|
|
144
|
+
expect(existingOrder.orderType).toBe(2);
|
|
145
|
+
|
|
146
|
+
await provider.send("evm_increaseTime", [60 * 2]); // more than 1 min
|
|
147
|
+
await pool.cancelOrderViaFlatMoney();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("keeperFee is small", async () => {
|
|
151
|
+
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
|
|
152
|
+
const walletOnChain = wallet.connect(provider);
|
|
153
|
+
const dhedge = new Dhedge(walletOnChain, network);
|
|
154
|
+
const pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
155
|
+
const keeperFee = await getKeeperFee(pool, 3);
|
|
156
|
+
expect(keeperFee).toBeTruthy();
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
testingHelper({
|
|
162
|
+
network: Network.BASE,
|
|
163
|
+
testingRun: testFlatMoney
|
|
164
|
+
});
|
package/src/test/uniswap.test.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { FeeAmount } from "@uniswap/v3-sdk";
|
|
3
2
|
import { Dhedge, ethers, Pool } from "..";
|
|
4
3
|
import { routerAddress } from "../config";
|
|
5
4
|
import { AssetEnabled, Dapp, Network } from "../types";
|
|
@@ -76,7 +75,7 @@ const testUniswapV3 = ({ wallet, network, provider }: TestingRunParams) => {
|
|
|
76
75
|
CONTRACT_ADDRESS[network].USDC,
|
|
77
76
|
CONTRACT_ADDRESS[network].WETH,
|
|
78
77
|
new BigNumber(5000).times(1e6).toFixed(0),
|
|
79
|
-
|
|
78
|
+
500,
|
|
80
79
|
0.5
|
|
81
80
|
);
|
|
82
81
|
|
|
@@ -121,15 +120,16 @@ const testUniswapV3 = ({ wallet, network, provider }: TestingRunParams) => {
|
|
|
121
120
|
|
|
122
121
|
try {
|
|
123
122
|
result = await pool.addLiquidityUniswapV3(
|
|
123
|
+
Dapp.UNISWAPV3,
|
|
124
124
|
CONTRACT_ADDRESS[network].WETH,
|
|
125
125
|
CONTRACT_ADDRESS[network].USDC,
|
|
126
126
|
wethBalance,
|
|
127
127
|
usdcBalance,
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
3500,
|
|
129
|
+
4000,
|
|
130
130
|
null,
|
|
131
131
|
null,
|
|
132
|
-
|
|
132
|
+
500
|
|
133
133
|
// options
|
|
134
134
|
);
|
|
135
135
|
await result.wait(1);
|
|
@@ -155,11 +155,20 @@ const testUniswapV3 = ({ wallet, network, provider }: TestingRunParams) => {
|
|
|
155
155
|
});
|
|
156
156
|
|
|
157
157
|
it("should increase liquidity in the existing WETH/USDC pool", async () => {
|
|
158
|
+
const usdcBalance = await dhedge.utils.getBalance(
|
|
159
|
+
CONTRACT_ADDRESS[network].USDC,
|
|
160
|
+
pool.address
|
|
161
|
+
);
|
|
162
|
+
const wethBalance = await dhedge.utils.getBalance(
|
|
163
|
+
CONTRACT_ADDRESS[network].WETH,
|
|
164
|
+
pool.address
|
|
165
|
+
);
|
|
166
|
+
|
|
158
167
|
const result = await pool.increaseLiquidity(
|
|
159
168
|
Dapp.UNISWAPV3,
|
|
160
169
|
tokenId.toString(),
|
|
161
|
-
|
|
162
|
-
|
|
170
|
+
wethBalance,
|
|
171
|
+
usdcBalance // eth
|
|
163
172
|
);
|
|
164
173
|
// console.log("result", result);
|
|
165
174
|
expect(result).not.toBe(null);
|
|
@@ -210,12 +219,12 @@ testingHelper({
|
|
|
210
219
|
testingRun: testUniswapV3
|
|
211
220
|
});
|
|
212
221
|
|
|
213
|
-
testingHelper({
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
});
|
|
222
|
+
// testingHelper({
|
|
223
|
+
// network: Network.POLYGON,
|
|
224
|
+
// testingRun: testUniswapV3
|
|
225
|
+
// });
|
|
217
226
|
|
|
218
|
-
testingHelper({
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
});
|
|
227
|
+
// testingHelper({
|
|
228
|
+
// network: Network.ARBITRUM,
|
|
229
|
+
// testingRun: testUniswapV3
|
|
230
|
+
// });
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { BigNumber, ethers } from "ethers";
|
|
2
2
|
import { Network } from "../../types";
|
|
3
3
|
import { getWalletData } from "../wallet";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
CONTRACT_ADDRESS,
|
|
6
|
+
USDC_BALANCEOF_SLOT,
|
|
7
|
+
WETH_BALANCEOF_SLOT
|
|
8
|
+
} from "../constants";
|
|
5
9
|
|
|
6
10
|
export type TestingRunParams = {
|
|
7
11
|
network: Network;
|
|
8
12
|
wallet: ethers.Wallet;
|
|
9
13
|
provider: ethers.providers.JsonRpcProvider;
|
|
14
|
+
rpcUrl: string;
|
|
10
15
|
};
|
|
11
16
|
|
|
12
17
|
type TestHelperParams = {
|
|
@@ -17,8 +22,8 @@ export const testingHelper = ({
|
|
|
17
22
|
network,
|
|
18
23
|
testingRun
|
|
19
24
|
}: TestHelperParams): void => {
|
|
20
|
-
const { wallet, provider } = getWalletData(network);
|
|
21
|
-
testingRun({ network, wallet, provider });
|
|
25
|
+
const { wallet, provider, rpcUrl } = getWalletData(network);
|
|
26
|
+
testingRun({ network, wallet, provider, rpcUrl });
|
|
22
27
|
};
|
|
23
28
|
|
|
24
29
|
export const beforeAfterReset = ({
|
|
@@ -52,7 +57,7 @@ export const setTokenAmount = async ({
|
|
|
52
57
|
amount: string;
|
|
53
58
|
userAddress: string;
|
|
54
59
|
tokenAddress: string;
|
|
55
|
-
slot: number;
|
|
60
|
+
slot: number | string;
|
|
56
61
|
provider: ethers.providers.JsonRpcProvider;
|
|
57
62
|
}): Promise<void> => {
|
|
58
63
|
const toBytes32 = (bn: string) => {
|
|
@@ -91,6 +96,26 @@ export const setUSDCAmount = async ({
|
|
|
91
96
|
});
|
|
92
97
|
};
|
|
93
98
|
|
|
99
|
+
export const setWETHAmount = async ({
|
|
100
|
+
provider,
|
|
101
|
+
userAddress,
|
|
102
|
+
amount,
|
|
103
|
+
network
|
|
104
|
+
}: {
|
|
105
|
+
amount: string;
|
|
106
|
+
userAddress: string;
|
|
107
|
+
provider: ethers.providers.JsonRpcProvider;
|
|
108
|
+
network: Network;
|
|
109
|
+
}): Promise<void> => {
|
|
110
|
+
await setTokenAmount({
|
|
111
|
+
amount,
|
|
112
|
+
userAddress,
|
|
113
|
+
provider,
|
|
114
|
+
tokenAddress: CONTRACT_ADDRESS[network].WETH,
|
|
115
|
+
slot: WETH_BALANCEOF_SLOT[network]
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
|
|
94
119
|
export const wait = (seconds: number): Promise<void> => {
|
|
95
120
|
return new Promise(resolve => setTimeout(resolve, seconds * 1000));
|
|
96
121
|
};
|
|
@@ -0,0 +1,223 @@
|
|
|
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, ethers } from "..";
|
|
5
|
+
import { nonfungiblePositionManagerAddress } from "../config";
|
|
6
|
+
import { AssetEnabled, Dapp, Network } from "../types";
|
|
7
|
+
import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
|
|
8
|
+
import {
|
|
9
|
+
TestingRunParams,
|
|
10
|
+
beforeAfterReset,
|
|
11
|
+
setUSDCAmount,
|
|
12
|
+
setWETHAmount,
|
|
13
|
+
testingHelper
|
|
14
|
+
} from "./utils/testingHelper";
|
|
15
|
+
import { balanceDelta } from "./utils/token";
|
|
16
|
+
import INonfungiblePositionManager from "../abi/INonfungiblePositionManager.json";
|
|
17
|
+
|
|
18
|
+
const testVelodromeCL = ({ wallet, network, provider }: TestingRunParams) => {
|
|
19
|
+
const VELODROME_POSITION_MANGER = nonfungiblePositionManagerAddress[network][
|
|
20
|
+
Dapp.VELODROMECL
|
|
21
|
+
]!;
|
|
22
|
+
|
|
23
|
+
const USDC = CONTRACT_ADDRESS[network].USDC;
|
|
24
|
+
const WETH = CONTRACT_ADDRESS[network].WETH;
|
|
25
|
+
const USDC_WETH_CL_GAUGE =
|
|
26
|
+
CONTRACT_ADDRESS[network].VELODROME_CL_USDC_WETH_GAUGE;
|
|
27
|
+
const VELO = CONTRACT_ADDRESS[network].VELO;
|
|
28
|
+
|
|
29
|
+
let dhedge: Dhedge;
|
|
30
|
+
let pool: Pool;
|
|
31
|
+
let velodromePositionManager: ethers.Contract;
|
|
32
|
+
let tokenId: string;
|
|
33
|
+
jest.setTimeout(100000);
|
|
34
|
+
|
|
35
|
+
describe(`[${network}] veldorome CL tests`, () => {
|
|
36
|
+
beforeAll(async () => {
|
|
37
|
+
// top up ETH (gas)
|
|
38
|
+
await provider.send("hardhat_setBalance", [
|
|
39
|
+
wallet.address,
|
|
40
|
+
"0x100000000000000"
|
|
41
|
+
]);
|
|
42
|
+
dhedge = new Dhedge(wallet, network);
|
|
43
|
+
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
44
|
+
await setUSDCAmount({
|
|
45
|
+
amount: new BigNumber(10000).times(1e6).toFixed(0),
|
|
46
|
+
userAddress: pool.address,
|
|
47
|
+
network,
|
|
48
|
+
provider
|
|
49
|
+
});
|
|
50
|
+
await setWETHAmount({
|
|
51
|
+
amount: new BigNumber(3).times(1e18).toFixed(0),
|
|
52
|
+
userAddress: pool.address,
|
|
53
|
+
network,
|
|
54
|
+
provider
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const newAssets: AssetEnabled[] = [
|
|
58
|
+
{ asset: USDC, isDeposit: true },
|
|
59
|
+
{ asset: WETH, isDeposit: true },
|
|
60
|
+
{
|
|
61
|
+
asset: VELODROME_POSITION_MANGER,
|
|
62
|
+
isDeposit: false
|
|
63
|
+
}
|
|
64
|
+
];
|
|
65
|
+
await pool.changeAssets(newAssets);
|
|
66
|
+
|
|
67
|
+
velodromePositionManager = new ethers.Contract(
|
|
68
|
+
VELODROME_POSITION_MANGER,
|
|
69
|
+
INonfungiblePositionManager.abi,
|
|
70
|
+
pool.signer
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
beforeAfterReset({ beforeAll, afterAll, provider });
|
|
75
|
+
|
|
76
|
+
// describe("Liquidity", () => {
|
|
77
|
+
// it("approves unlimited USDC and WETH on for Velodrome CL", async () => {
|
|
78
|
+
// await pool.approveSpender(VELODROME_POSITION_MANGER, USDC, MAX_AMOUNT);
|
|
79
|
+
// await pool.approveSpender(VELODROME_POSITION_MANGER, WETH, MAX_AMOUNT);
|
|
80
|
+
// const UsdcAllowanceDelta = await allowanceDelta(
|
|
81
|
+
// pool.address,
|
|
82
|
+
// USDC,
|
|
83
|
+
// VELODROME_POSITION_MANGER,
|
|
84
|
+
// pool.signer
|
|
85
|
+
// );
|
|
86
|
+
// await expect(UsdcAllowanceDelta.gt(0));
|
|
87
|
+
// });
|
|
88
|
+
|
|
89
|
+
// it("adds USDC and WETH to a Velodrome CL (mint position)", async () => {
|
|
90
|
+
// const usdcBalance = await pool.utils.getBalance(USDC, pool.address);
|
|
91
|
+
// const wethBalance = await pool.utils.getBalance(WETH, pool.address);
|
|
92
|
+
// await pool.addLiquidityUniswapV3(
|
|
93
|
+
// Dapp.VELODROMECL,
|
|
94
|
+
// USDC,
|
|
95
|
+
// WETH,
|
|
96
|
+
// usdcBalance.div(2),
|
|
97
|
+
// wethBalance.div(2),
|
|
98
|
+
// null,
|
|
99
|
+
// null,
|
|
100
|
+
// 193700,
|
|
101
|
+
// 193900,
|
|
102
|
+
// 100
|
|
103
|
+
// );
|
|
104
|
+
|
|
105
|
+
// tokenId = (
|
|
106
|
+
// await velodromePositionManager.tokenOfOwnerByIndex(pool.address, 0)
|
|
107
|
+
// ).toString();
|
|
108
|
+
// expect(tokenId).not.toBe(null);
|
|
109
|
+
// });
|
|
110
|
+
|
|
111
|
+
// it("increases liquidity in a CL position", async () => {
|
|
112
|
+
// const usdcBalance = await pool.utils.getBalance(USDC, pool.address);
|
|
113
|
+
// const wethBalance = await pool.utils.getBalance(WETH, pool.address);
|
|
114
|
+
// const positionBefore = await velodromePositionManager.positions(
|
|
115
|
+
// tokenId
|
|
116
|
+
// );
|
|
117
|
+
// await pool.increaseLiquidity(
|
|
118
|
+
// Dapp.VELODROMECL,
|
|
119
|
+
// tokenId,
|
|
120
|
+
// usdcBalance.div(2),
|
|
121
|
+
// wethBalance.div(2)
|
|
122
|
+
// );
|
|
123
|
+
// const positionAfter = await velodromePositionManager.positions(tokenId);
|
|
124
|
+
// expect(positionAfter.liquidity.gt(positionBefore.liquidity));
|
|
125
|
+
// });
|
|
126
|
+
|
|
127
|
+
// it("decreases liquidity from a CL position", async () => {
|
|
128
|
+
// const positionBefore = await velodromePositionManager.positions(
|
|
129
|
+
// tokenId
|
|
130
|
+
// );
|
|
131
|
+
// await pool.decreaseLiquidity(Dapp.VELODROMECL, tokenId, 50);
|
|
132
|
+
// const positionAfter = await velodromePositionManager.positions(tokenId);
|
|
133
|
+
// expect(positionAfter.liquidity.lt(positionBefore.liquidity));
|
|
134
|
+
// });
|
|
135
|
+
|
|
136
|
+
// it("collects fess of a CL position", async () => {
|
|
137
|
+
// await provider.send("evm_increaseTime", [24 * 3600 * 3]); // 1 day
|
|
138
|
+
// await provider.send("evm_mine", []);
|
|
139
|
+
// await pool.claimFees(Dapp.VELODROMECL, tokenId);
|
|
140
|
+
// expect((await balanceDelta(pool.address, USDC, pool.signer)).gt(0));
|
|
141
|
+
// });
|
|
142
|
+
// });
|
|
143
|
+
describe("Liquidity staking", () => {
|
|
144
|
+
it("stakes a CL position in gauge", async () => {
|
|
145
|
+
await pool.approveSpender(VELODROME_POSITION_MANGER, USDC, MAX_AMOUNT);
|
|
146
|
+
await pool.approveSpender(VELODROME_POSITION_MANGER, WETH, MAX_AMOUNT);
|
|
147
|
+
const usdcBalance = await pool.utils.getBalance(USDC, pool.address);
|
|
148
|
+
const wethBalance = await pool.utils.getBalance(WETH, pool.address);
|
|
149
|
+
await pool.addLiquidityUniswapV3(
|
|
150
|
+
Dapp.VELODROMECL,
|
|
151
|
+
USDC,
|
|
152
|
+
WETH,
|
|
153
|
+
usdcBalance.div(2),
|
|
154
|
+
wethBalance.div(2),
|
|
155
|
+
null,
|
|
156
|
+
null,
|
|
157
|
+
193700,
|
|
158
|
+
193900,
|
|
159
|
+
100
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
tokenId = (
|
|
163
|
+
await velodromePositionManager.tokenOfOwnerByIndex(pool.address, 0)
|
|
164
|
+
).toString();
|
|
165
|
+
await pool.approveSpenderNFT(
|
|
166
|
+
USDC_WETH_CL_GAUGE,
|
|
167
|
+
VELODROME_POSITION_MANGER,
|
|
168
|
+
tokenId
|
|
169
|
+
);
|
|
170
|
+
await pool.stakeInGauge(Dapp.VELODROMECL, USDC_WETH_CL_GAUGE, tokenId);
|
|
171
|
+
expect(await velodromePositionManager.ownerOf(tokenId)).toBe(
|
|
172
|
+
USDC_WETH_CL_GAUGE
|
|
173
|
+
);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it("decreases liquidity from a staked CL position", async () => {
|
|
177
|
+
const positionBefore = await velodromePositionManager.positions(
|
|
178
|
+
tokenId
|
|
179
|
+
);
|
|
180
|
+
await pool.decreaseLiquidity(Dapp.VELODROMECL, tokenId, 50);
|
|
181
|
+
const positionAfter = await velodromePositionManager.positions(tokenId);
|
|
182
|
+
expect(positionAfter.liquidity.lt(positionBefore.liquidity));
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("increases liquidity in a staked CL position", async () => {
|
|
186
|
+
const usdcBalance = await pool.utils.getBalance(USDC, pool.address);
|
|
187
|
+
const wethBalance = await pool.utils.getBalance(WETH, pool.address);
|
|
188
|
+
const positionBefore = await velodromePositionManager.positions(
|
|
189
|
+
tokenId
|
|
190
|
+
);
|
|
191
|
+
await pool.approveSpender(USDC_WETH_CL_GAUGE, USDC, MAX_AMOUNT);
|
|
192
|
+
await pool.approveSpender(USDC_WETH_CL_GAUGE, WETH, MAX_AMOUNT);
|
|
193
|
+
await pool.increaseLiquidity(
|
|
194
|
+
Dapp.VELODROMECL,
|
|
195
|
+
tokenId,
|
|
196
|
+
usdcBalance.div(2),
|
|
197
|
+
wethBalance.div(2)
|
|
198
|
+
);
|
|
199
|
+
const positionAfter = await velodromePositionManager.positions(tokenId);
|
|
200
|
+
expect(positionAfter.liquidity.gt(positionBefore.liquidity));
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("collects fess of a staked CL position", async () => {
|
|
204
|
+
await provider.send("evm_increaseTime", [24 * 3600]); // 1 day
|
|
205
|
+
await provider.send("evm_mine", []);
|
|
206
|
+
await pool.claimFees(Dapp.VELODROMECL, tokenId);
|
|
207
|
+
expect((await balanceDelta(pool.address, VELO, pool.signer)).gt(0));
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("unstakes a CL position from a gauge", async () => {
|
|
211
|
+
await pool.unstakeFromGauge(USDC_WETH_CL_GAUGE, tokenId);
|
|
212
|
+
expect(
|
|
213
|
+
(await velodromePositionManager.ownerOf(tokenId)).toLowerCase()
|
|
214
|
+
).toBe(pool.address.toLowerCase());
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
testingHelper({
|
|
221
|
+
network: Network.OPTIMISM,
|
|
222
|
+
testingRun: testVelodromeCL
|
|
223
|
+
});
|
package/src/test/wallet.ts
CHANGED
|
@@ -38,12 +38,15 @@ export const getWalletData = (
|
|
|
38
38
|
): {
|
|
39
39
|
wallet: ethers.Wallet;
|
|
40
40
|
provider: ethers.providers.JsonRpcProvider;
|
|
41
|
+
rpcUrl: string;
|
|
41
42
|
} => {
|
|
42
43
|
const provider = new ethers.providers.JsonRpcProvider(
|
|
43
44
|
`http://127.0.0.1:${networkPortMap[network]}/`
|
|
44
45
|
);
|
|
46
|
+
const rpcUrl = process.env[`${network.toUpperCase()}_URL`] || "";
|
|
45
47
|
return {
|
|
46
48
|
wallet: new ethers.Wallet(process.env.PRIVATE_KEY as string, provider),
|
|
47
|
-
provider
|
|
49
|
+
provider,
|
|
50
|
+
rpcUrl
|
|
48
51
|
};
|
|
49
52
|
};
|
package/src/types.ts
CHANGED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { FeeAmount } from "@uniswap/v3-sdk";
|
|
2
|
-
import { ethers } from "ethers";
|
|
3
|
-
export declare type UniswapV3MintParams = [string, string, FeeAmount, number, number, ethers.BigNumber | string, ethers.BigNumber | string, ethers.BigNumber | string, ethers.BigNumber | string, string, number];
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { FeeAmount } from "@uniswap/v3-sdk";
|
|
2
|
-
import { ethers } from "ethers";
|
|
3
|
-
|
|
4
|
-
export type UniswapV3MintParams = [
|
|
5
|
-
string,
|
|
6
|
-
string,
|
|
7
|
-
FeeAmount,
|
|
8
|
-
number,
|
|
9
|
-
number,
|
|
10
|
-
ethers.BigNumber | string,
|
|
11
|
-
ethers.BigNumber | string,
|
|
12
|
-
ethers.BigNumber | string,
|
|
13
|
-
ethers.BigNumber | string,
|
|
14
|
-
string,
|
|
15
|
-
number
|
|
16
|
-
];
|