@dhedge/v2-sdk 1.5.4 → 1.7.1
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/config.d.ts +2 -1
- package/dist/entities/pool.d.ts +21 -1
- package/dist/entities/utils.d.ts +7 -2
- package/dist/services/lyra/markets.d.ts +6 -0
- package/dist/services/lyra/positions.d.ts +2 -0
- package/dist/services/lyra/quote.d.ts +4 -0
- package/dist/services/lyra/trade.d.ts +4 -0
- package/dist/services/lyra/tradeOptionType.d.ts +3 -0
- package/dist/test/constants.d.ts +3 -12
- package/dist/types.d.ts +20 -1
- package/dist/v2-sdk.cjs.development.js +4202 -12
- 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 +4200 -11
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +6 -2
- package/src/abi/IOptionMArketWrapper.json +1038 -0
- package/src/abi/IOptionMarket.json +1473 -0
- package/src/abi/IOptionToken.json +1671 -0
- package/src/config.ts +11 -5
- package/src/entities/pool.ts +61 -1
- package/src/entities/utils.ts +45 -2
- package/src/services/lyra/markets.ts +52 -0
- package/src/services/lyra/positions.ts +19 -0
- package/src/services/lyra/quote.ts +12 -0
- package/src/services/lyra/trade.ts +101 -0
- package/src/services/lyra/tradeOptionType.ts +19 -0
- package/src/test/arrakis.test.ts +65 -52
- package/src/test/constants.ts +17 -14
- package/src/test/lyra.test.ts +163 -0
- package/src/test/pool.test.ts +1 -1
- package/src/test/toros.test.ts +1 -1
- package/src/test/txOptions.ts +1 -1
- package/src/test/uniswap.test.ts +1 -1
- package/src/test/velodrome.test.ts +1 -1
- package/src/test/wallet.ts +8 -0
- package/src/types.ts +20 -1
- package/src/test/sushi.test.ts +0 -173
package/src/config.ts
CHANGED
|
@@ -2,9 +2,11 @@ import {
|
|
|
2
2
|
Dapp,
|
|
3
3
|
AddressNetworkMap,
|
|
4
4
|
Network,
|
|
5
|
-
AddressDappNetworkMap
|
|
5
|
+
AddressDappNetworkMap,
|
|
6
|
+
LyraNetworkMap
|
|
6
7
|
} from "./types";
|
|
7
8
|
import { NetworkChainIdMap } from ".";
|
|
9
|
+
import { Deployment } from "@lyrafinance/lyra-js";
|
|
8
10
|
|
|
9
11
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
10
12
|
require("dotenv").config();
|
|
@@ -34,7 +36,9 @@ export const routerAddress: AddressDappNetworkMap = {
|
|
|
34
36
|
[Dapp.AAVEV3]: "0x794a61358D6845594F94dc1DB02A252b5b4814aD",
|
|
35
37
|
[Dapp.ONEINCH]: "0x1111111254760F7ab3F16433eea9304126DCd199",
|
|
36
38
|
[Dapp.TOROS]: "0xf8C62BD5f2fEf9E1a329c197F32E77AD6866B022",
|
|
37
|
-
[Dapp.VELODROME]: "0x9c12939390052919aF3155f41Bf4160Fd3666A6f"
|
|
39
|
+
[Dapp.VELODROME]: "0x9c12939390052919aF3155f41Bf4160Fd3666A6f",
|
|
40
|
+
[Dapp.LYRA]: "0xCCE7819d65f348c64B7Beb205BA367b3fE33763B",
|
|
41
|
+
[Dapp.ARRAKIS]: "0x86d62a8ad19998e315e6242b63eb73f391d4674b"
|
|
38
42
|
}
|
|
39
43
|
};
|
|
40
44
|
|
|
@@ -53,9 +57,7 @@ export const stakingAddress: AddressDappNetworkMap = {
|
|
|
53
57
|
[Dapp.AAVE]: "0x357D51124f59836DeD84c8a1730D72B749d8BC23",
|
|
54
58
|
[Dapp.AAVEV3]: "0x929EC64c34a17401F460460D4B9390518E5B473e"
|
|
55
59
|
},
|
|
56
|
-
[Network.OPTIMISM]: {
|
|
57
|
-
[Dapp.AAVEV3]: "0x929EC64c34a17401F460460D4B9390518E5B473e"
|
|
58
|
-
}
|
|
60
|
+
[Network.OPTIMISM]: {}
|
|
59
61
|
};
|
|
60
62
|
|
|
61
63
|
export const aaveAddressProvider: AddressDappNetworkMap = {
|
|
@@ -88,6 +90,10 @@ export const multiCallAddress: AddressNetworkMap = {
|
|
|
88
90
|
[Network.OPTIMISM]: ""
|
|
89
91
|
};
|
|
90
92
|
|
|
93
|
+
export const lyraNetworkMap: LyraNetworkMap = {
|
|
94
|
+
[Network.OPTIMISM]: Deployment.Mainnet
|
|
95
|
+
};
|
|
96
|
+
|
|
91
97
|
export const deadline = Math.floor(Date.now() / 1000) + 60 * 20;
|
|
92
98
|
export const MaxUint128 = "0xffffffffffffffffffffffffffffffff";
|
|
93
99
|
export const UNISWAPV3_QUOTER_ADDRESS =
|
package/src/entities/pool.ts
CHANGED
|
@@ -29,7 +29,11 @@ import {
|
|
|
29
29
|
Transaction,
|
|
30
30
|
FundComposition,
|
|
31
31
|
AssetEnabled,
|
|
32
|
-
Network
|
|
32
|
+
Network,
|
|
33
|
+
LyraOptionMarket,
|
|
34
|
+
LyraOptionType,
|
|
35
|
+
LyraTradeType,
|
|
36
|
+
LyraPosition
|
|
33
37
|
} from "../types";
|
|
34
38
|
|
|
35
39
|
import { Utils } from "./utils";
|
|
@@ -51,6 +55,8 @@ import {
|
|
|
51
55
|
getVelodromeClaimTxData,
|
|
52
56
|
getVelodromeStakeTxData
|
|
53
57
|
} from "../services/velodrome/staking";
|
|
58
|
+
import { getLyraOptionTxData } from "../services/lyra/trade";
|
|
59
|
+
import { getOptionPositions } from "../services/lyra/positions";
|
|
54
60
|
|
|
55
61
|
export class Pool {
|
|
56
62
|
public readonly poolLogic: Contract;
|
|
@@ -1165,4 +1171,58 @@ export class Pool {
|
|
|
1165
1171
|
);
|
|
1166
1172
|
return tx;
|
|
1167
1173
|
}
|
|
1174
|
+
|
|
1175
|
+
/**
|
|
1176
|
+
* Trade options on lyra
|
|
1177
|
+
* @param {LyraOptionMarket} market Underlying market e.g. eth
|
|
1178
|
+
* @param {number} expiry Expiry timestamp
|
|
1179
|
+
* @param { number} strike Strike price
|
|
1180
|
+
* @param {LyraOptionType} optionType Call or put
|
|
1181
|
+
* @param { LyraTradeType} tradeType By or sell
|
|
1182
|
+
* @param {BigNumber | string } optionAmount Option amount
|
|
1183
|
+
* @param {string } assetIn Asset to invest
|
|
1184
|
+
* @param {BigNumber | string } collateralChangeAmount Collateral amount to add when shorting options and to remove when covering shorts
|
|
1185
|
+
* @param {boolean} isCoveredCall Selling covered call options
|
|
1186
|
+
* @param {any} options Transaction options
|
|
1187
|
+
* @returns {Promise<any>} Transaction
|
|
1188
|
+
*/
|
|
1189
|
+
async tradeLyraOption(
|
|
1190
|
+
market: LyraOptionMarket,
|
|
1191
|
+
expiry: number,
|
|
1192
|
+
strike: number,
|
|
1193
|
+
optionType: LyraOptionType,
|
|
1194
|
+
tradeType: LyraTradeType,
|
|
1195
|
+
optionAmount: BigNumber | string,
|
|
1196
|
+
assetIn: string,
|
|
1197
|
+
collateralChangeAmount: BigNumber | string = "0",
|
|
1198
|
+
isCoveredCall = false,
|
|
1199
|
+
options: any = null
|
|
1200
|
+
): Promise<any> {
|
|
1201
|
+
const swapxData = await getLyraOptionTxData(
|
|
1202
|
+
this,
|
|
1203
|
+
market,
|
|
1204
|
+
optionType,
|
|
1205
|
+
expiry,
|
|
1206
|
+
strike,
|
|
1207
|
+
tradeType,
|
|
1208
|
+
optionAmount,
|
|
1209
|
+
assetIn,
|
|
1210
|
+
BigNumber.from(collateralChangeAmount),
|
|
1211
|
+
isCoveredCall
|
|
1212
|
+
);
|
|
1213
|
+
const tx = await this.poolLogic.execTransaction(
|
|
1214
|
+
routerAddress[this.network][Dapp.LYRA],
|
|
1215
|
+
swapxData,
|
|
1216
|
+
options
|
|
1217
|
+
);
|
|
1218
|
+
return tx;
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
/**
|
|
1222
|
+
* Gets Lyra option positions
|
|
1223
|
+
* @returns {Promise<Position>} Transaction
|
|
1224
|
+
*/
|
|
1225
|
+
async getLyraPositions(market: LyraOptionMarket): Promise<LyraPosition[]> {
|
|
1226
|
+
return await getOptionPositions(this, market);
|
|
1227
|
+
}
|
|
1168
1228
|
}
|
package/src/entities/utils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Contract, ethers, Wallet } from "ethers";
|
|
1
|
+
import { BigNumber, Contract, ethers, Wallet } from "ethers";
|
|
2
2
|
import {
|
|
3
3
|
Token,
|
|
4
4
|
TokenAmount,
|
|
@@ -22,8 +22,18 @@ import {
|
|
|
22
22
|
networkChainIdMap,
|
|
23
23
|
stakingAddress
|
|
24
24
|
} from "../config";
|
|
25
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
Dapp,
|
|
27
|
+
LyraOptionMarket,
|
|
28
|
+
LyraOptionType,
|
|
29
|
+
LyraTradeType,
|
|
30
|
+
Network,
|
|
31
|
+
Reserves
|
|
32
|
+
} from "../types";
|
|
26
33
|
import { Pool } from ".";
|
|
34
|
+
import { getExpiries, getStrike, getStrikes } from "../services/lyra/markets";
|
|
35
|
+
import { Quote, Strike } from "@lyrafinance/lyra-js";
|
|
36
|
+
import { getQuote } from "../services/lyra/quote";
|
|
27
37
|
|
|
28
38
|
export class Utils {
|
|
29
39
|
network: Network;
|
|
@@ -328,4 +338,37 @@ export class Utils {
|
|
|
328
338
|
const exitPoolTx = iBalancerV2Vault.encodeFunctionData("exitPool", txData);
|
|
329
339
|
return exitPoolTx;
|
|
330
340
|
}
|
|
341
|
+
|
|
342
|
+
async getLyraOptionExpiries(market: LyraOptionMarket): Promise<number[]> {
|
|
343
|
+
return await getExpiries(this.network, market);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
async getLyraOptionStrikes(
|
|
347
|
+
market: LyraOptionMarket,
|
|
348
|
+
expiry: number
|
|
349
|
+
): Promise<Strike[]> {
|
|
350
|
+
return await getStrikes(this.network, market, expiry);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
async getLyraOptionStrike(
|
|
354
|
+
market: LyraOptionMarket,
|
|
355
|
+
expiry: number,
|
|
356
|
+
strike: number
|
|
357
|
+
): Promise<Strike> {
|
|
358
|
+
return await getStrike(this.network, market, expiry, strike);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
async getLyraOptionQuote(
|
|
362
|
+
strike: Strike,
|
|
363
|
+
type: LyraOptionType,
|
|
364
|
+
tradeType: LyraTradeType,
|
|
365
|
+
amount: BigNumber | string
|
|
366
|
+
): Promise<Quote> {
|
|
367
|
+
return await getQuote(
|
|
368
|
+
strike,
|
|
369
|
+
type,
|
|
370
|
+
tradeType,
|
|
371
|
+
ethers.BigNumber.from(amount)
|
|
372
|
+
);
|
|
373
|
+
}
|
|
331
374
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { ethers, LyraOptionMarket, Network } from "../..";
|
|
3
|
+
import { lyraNetworkMap } from "../../config";
|
|
4
|
+
import Lyra, { Board, Strike } from "@lyrafinance/lyra-js";
|
|
5
|
+
|
|
6
|
+
export async function getBoard(
|
|
7
|
+
network: Network,
|
|
8
|
+
market: LyraOptionMarket,
|
|
9
|
+
expiry: number
|
|
10
|
+
): Promise<Board> {
|
|
11
|
+
const lyra = new Lyra(lyraNetworkMap[network]);
|
|
12
|
+
const optionMarket = await lyra.market(market);
|
|
13
|
+
const filteredBoards = optionMarket
|
|
14
|
+
.liveBoards()
|
|
15
|
+
.filter(e => e.expiryTimestamp === expiry);
|
|
16
|
+
if (filteredBoards.length === 0) throw new Error("no lyra board for expiry");
|
|
17
|
+
return filteredBoards[0];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function getExpiries(
|
|
21
|
+
network: Network,
|
|
22
|
+
market: LyraOptionMarket
|
|
23
|
+
): Promise<number[]> {
|
|
24
|
+
const lyra = new Lyra(lyraNetworkMap[network]);
|
|
25
|
+
const optionMarket = await lyra.market(market);
|
|
26
|
+
return optionMarket.liveBoards().map(e => e.expiryTimestamp);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function getStrikes(
|
|
30
|
+
network: Network,
|
|
31
|
+
market: LyraOptionMarket,
|
|
32
|
+
expiry: number
|
|
33
|
+
): Promise<Strike[]> {
|
|
34
|
+
return (await getBoard(network, market, expiry)).strikes();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function getStrike(
|
|
38
|
+
network: Network,
|
|
39
|
+
market: LyraOptionMarket,
|
|
40
|
+
expiry: number,
|
|
41
|
+
strike: number
|
|
42
|
+
): Promise<Strike> {
|
|
43
|
+
const strikes = await getStrikes(network, market, expiry);
|
|
44
|
+
const filteredStrike = strikes.filter(
|
|
45
|
+
(e: Strike) =>
|
|
46
|
+
parseFloat(ethers.utils.formatEther(e.strikePrice)) === strike
|
|
47
|
+
);
|
|
48
|
+
if (filteredStrike.length === 0)
|
|
49
|
+
throw new Error("no option found for strike price");
|
|
50
|
+
|
|
51
|
+
return filteredStrike[0];
|
|
52
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { ethers, LyraOptionMarket, LyraPosition, Pool } from "../..";
|
|
3
|
+
import Lyra from "@lyrafinance/lyra-js";
|
|
4
|
+
import IOptionToken from "../../abi/IOptionToken.json";
|
|
5
|
+
|
|
6
|
+
export async function getOptionPositions(
|
|
7
|
+
pool: Pool,
|
|
8
|
+
market: LyraOptionMarket
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
+
): Promise<LyraPosition[]> {
|
|
11
|
+
const lyra = new Lyra();
|
|
12
|
+
const optionMarket = await lyra.market(market);
|
|
13
|
+
const iOptionToken = new ethers.Contract(
|
|
14
|
+
optionMarket.__marketData.marketAddresses.optionToken,
|
|
15
|
+
IOptionToken.abi,
|
|
16
|
+
pool.signer
|
|
17
|
+
);
|
|
18
|
+
return await iOptionToken.getOwnerPositions(pool.address);
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Quote, Strike } from "@lyrafinance/lyra-js";
|
|
2
|
+
import { ethers } from "ethers";
|
|
3
|
+
import { LyraOptionType, LyraTradeType } from "../../types";
|
|
4
|
+
|
|
5
|
+
export async function getQuote(
|
|
6
|
+
strike: Strike,
|
|
7
|
+
type: LyraOptionType,
|
|
8
|
+
tradeType: LyraTradeType,
|
|
9
|
+
amount: ethers.BigNumber
|
|
10
|
+
): Promise<Quote> {
|
|
11
|
+
return await strike.quote(type === "call", tradeType === "buy", amount);
|
|
12
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { BigNumber, ethers } from "ethers";
|
|
3
|
+
import { Pool } from "../..";
|
|
4
|
+
import { LyraOptionMarket, LyraOptionType, LyraTradeType } from "../../types";
|
|
5
|
+
import { getStrike } from "./markets";
|
|
6
|
+
import IOptionMarketWrapper from "../../abi/IOptionMarketWrapper.json";
|
|
7
|
+
import { getLyraTradeOptionType, isCall, isLong } from "./tradeOptionType";
|
|
8
|
+
import { getOptionPositions } from "./positions";
|
|
9
|
+
import { getQuote } from "./quote";
|
|
10
|
+
|
|
11
|
+
export async function getLyraOptionTxData(
|
|
12
|
+
pool: Pool,
|
|
13
|
+
market: LyraOptionMarket,
|
|
14
|
+
optionType: LyraOptionType,
|
|
15
|
+
expiry: number,
|
|
16
|
+
strikePrice: number,
|
|
17
|
+
tradeType: LyraTradeType,
|
|
18
|
+
optionAmount: BigNumber | string,
|
|
19
|
+
assetIn: string,
|
|
20
|
+
collateralAmount: BigNumber,
|
|
21
|
+
isCoveredCall: boolean
|
|
22
|
+
): Promise<string> {
|
|
23
|
+
const strike = await getStrike(pool.network, market, expiry, strikePrice);
|
|
24
|
+
const strikeId = strike.id;
|
|
25
|
+
|
|
26
|
+
const positions = await getOptionPositions(pool, market);
|
|
27
|
+
const filteredPosition = positions.filter(
|
|
28
|
+
e =>
|
|
29
|
+
e.strikeId.toNumber() === strikeId &&
|
|
30
|
+
isCall(e.optionType) == (optionType === "call") &&
|
|
31
|
+
e.state === 1
|
|
32
|
+
);
|
|
33
|
+
const positionId =
|
|
34
|
+
filteredPosition.length > 0 ? filteredPosition[0].positionId : 0;
|
|
35
|
+
|
|
36
|
+
let lyraOptionType = getLyraTradeOptionType(
|
|
37
|
+
optionType === "call",
|
|
38
|
+
tradeType === "buy",
|
|
39
|
+
isCoveredCall
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const amountIn = BigNumber.from(optionAmount);
|
|
43
|
+
const quote = await getQuote(strike, optionType, tradeType, amountIn);
|
|
44
|
+
const netPremiun =
|
|
45
|
+
tradeType === "buy"
|
|
46
|
+
? quote.premium.add(quote.fee)
|
|
47
|
+
: quote.premium.sub(quote.fee);
|
|
48
|
+
|
|
49
|
+
let txFunction = "openPosition";
|
|
50
|
+
let inputAmount = tradeType === "buy" ? netPremiun : collateralAmount;
|
|
51
|
+
let currentCollateral = BigNumber.from(0);
|
|
52
|
+
let setCollateral = collateralAmount;
|
|
53
|
+
if (filteredPosition.length > 0) {
|
|
54
|
+
currentCollateral = filteredPosition[0].collateral ?? BigNumber.from(0);
|
|
55
|
+
setCollateral = currentCollateral.add(collateralAmount);
|
|
56
|
+
if (
|
|
57
|
+
//sell long positions
|
|
58
|
+
(tradeType === "sell" && isLong(filteredPosition[0].optionType)) ||
|
|
59
|
+
//cover short positions
|
|
60
|
+
(tradeType === "buy" && !isLong(filteredPosition[0].optionType))
|
|
61
|
+
) {
|
|
62
|
+
lyraOptionType = filteredPosition[0].optionType;
|
|
63
|
+
txFunction = "closePosition";
|
|
64
|
+
setCollateral = currentCollateral.sub(collateralAmount);
|
|
65
|
+
//cover short
|
|
66
|
+
if (
|
|
67
|
+
!isLong(filteredPosition[0].optionType) &&
|
|
68
|
+
!isCoveredCall &&
|
|
69
|
+
collateralAmount.gt(netPremiun)
|
|
70
|
+
) {
|
|
71
|
+
inputAmount = netPremiun.sub(collateralAmount);
|
|
72
|
+
} else if (!isLong(filteredPosition[0].optionType) && isCoveredCall) {
|
|
73
|
+
inputAmount = netPremiun;
|
|
74
|
+
} else {
|
|
75
|
+
inputAmount = BigNumber.from(0);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const iOptionMarketWrapper = new ethers.utils.Interface(
|
|
81
|
+
IOptionMarketWrapper.abi
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const tradeTx = iOptionMarketWrapper.encodeFunctionData(txFunction, [
|
|
85
|
+
[
|
|
86
|
+
strike.market().contractAddresses.optionMarket,
|
|
87
|
+
strikeId, // strike Id
|
|
88
|
+
positionId, // position Id
|
|
89
|
+
1, // iteration
|
|
90
|
+
setCollateral, // set collateral to
|
|
91
|
+
currentCollateral, // current collateral
|
|
92
|
+
lyraOptionType, // optionType
|
|
93
|
+
amountIn, // amount
|
|
94
|
+
tradeType === "sell" ? netPremiun : 0, // min cost
|
|
95
|
+
tradeType === "buy" ? netPremiun : ethers.constants.MaxUint256, // max cost
|
|
96
|
+
inputAmount,
|
|
97
|
+
assetIn // input asset
|
|
98
|
+
]
|
|
99
|
+
]);
|
|
100
|
+
return tradeTx;
|
|
101
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function getLyraTradeOptionType(
|
|
2
|
+
isCall: boolean,
|
|
3
|
+
isLong: boolean,
|
|
4
|
+
isCoveredCall: boolean
|
|
5
|
+
): number {
|
|
6
|
+
if (isCall) {
|
|
7
|
+
return isLong ? 0 : isCoveredCall ? 2 : 3;
|
|
8
|
+
} else {
|
|
9
|
+
return isLong ? 1 : 4;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function isCall(optionType: number): boolean {
|
|
14
|
+
return [0, 2, 3].includes(optionType);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function isLong(optionType: number): boolean {
|
|
18
|
+
return optionType === 0 || optionType === 1;
|
|
19
|
+
}
|
package/src/test/arrakis.test.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { Dhedge } from "..";
|
|
2
|
+
import { Dhedge, ethers } from "..";
|
|
3
3
|
import { Dapp, Network } from "../types";
|
|
4
|
-
import { ARRAKIS_USDC_WETH_GAUGE, TEST_POOL } from "./constants";
|
|
4
|
+
import { ARRAKIS_USDC_WETH_GAUGE, TEST_POOL, USDC, WETH } from "./constants";
|
|
5
5
|
import { getTxOptions } from "./txOptions";
|
|
6
|
-
//import { getTxOptions } from "./txOptions";
|
|
7
6
|
|
|
8
7
|
import { wallet } from "./wallet";
|
|
9
8
|
|
|
@@ -13,67 +12,81 @@ jest.setTimeout(100000);
|
|
|
13
12
|
|
|
14
13
|
describe("pool", () => {
|
|
15
14
|
beforeAll(async () => {
|
|
16
|
-
dhedge = new Dhedge(wallet, Network.
|
|
17
|
-
options = await getTxOptions(Network.
|
|
15
|
+
dhedge = new Dhedge(wallet, Network.OPTIMISM);
|
|
16
|
+
options = await getTxOptions(Network.OPTIMISM);
|
|
18
17
|
});
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// console.log(result);
|
|
31
|
-
// } catch (e) {
|
|
32
|
-
// console.log(e);
|
|
33
|
-
// }
|
|
34
|
-
// expect(result).not.toBe(null);
|
|
35
|
-
// });
|
|
19
|
+
it("approves unlimited USDC on Arrakis", async () => {
|
|
20
|
+
const pool = await dhedge.loadPool(TEST_POOL);
|
|
21
|
+
const result = await pool.approve(
|
|
22
|
+
Dapp.ARRAKIS,
|
|
23
|
+
USDC,
|
|
24
|
+
ethers.constants.MaxInt256,
|
|
25
|
+
options
|
|
26
|
+
);
|
|
27
|
+
expect(result).not.toBe(null);
|
|
28
|
+
});
|
|
36
29
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// });
|
|
30
|
+
it("approves unlimited WETH on Arrakis", async () => {
|
|
31
|
+
const pool = await dhedge.loadPool(TEST_POOL);
|
|
32
|
+
const result = await pool.approve(
|
|
33
|
+
Dapp.ARRAKIS,
|
|
34
|
+
WETH,
|
|
35
|
+
ethers.constants.MaxInt256,
|
|
36
|
+
options
|
|
37
|
+
);
|
|
38
|
+
console.log(result);
|
|
39
|
+
expect(result).not.toBe(null);
|
|
40
|
+
});
|
|
49
41
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
42
|
+
it("should add liquidity and stake in an WETH/USDC Arrakis pool", async () => {
|
|
43
|
+
const pool = await dhedge.loadPool(TEST_POOL);
|
|
44
|
+
const wethBalance = await pool.utils.getBalance(WETH, pool.address);
|
|
45
|
+
const uasdBalance = await pool.utils.getBalance(USDC, pool.address);
|
|
46
|
+
const lpBalance = await pool.utils.getBalance(
|
|
47
|
+
ARRAKIS_USDC_WETH_GAUGE,
|
|
48
|
+
pool.address
|
|
49
|
+
);
|
|
50
|
+
const result = await pool.increaseLiquidity(
|
|
51
|
+
Dapp.ARRAKIS,
|
|
52
|
+
ARRAKIS_USDC_WETH_GAUGE,
|
|
53
|
+
uasdBalance,
|
|
54
|
+
wethBalance,
|
|
55
|
+
options
|
|
56
|
+
);
|
|
57
|
+
result.wait(1);
|
|
58
|
+
const lpBalanceAfter = await pool.utils.getBalance(
|
|
59
|
+
ARRAKIS_USDC_WETH_GAUGE,
|
|
60
|
+
pool.address
|
|
61
|
+
);
|
|
62
|
+
expect(lpBalanceAfter.gt(lpBalance));
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("approves unlimited LP staking Token before on Arrakis", async () => {
|
|
66
|
+
const pool = await dhedge.loadPool(TEST_POOL);
|
|
67
|
+
const result = await pool.approve(
|
|
68
|
+
Dapp.ARRAKIS,
|
|
69
|
+
ARRAKIS_USDC_WETH_GAUGE,
|
|
70
|
+
ethers.constants.MaxInt256,
|
|
71
|
+
options
|
|
72
|
+
);
|
|
73
|
+
expect(result).not.toBe(null);
|
|
74
|
+
});
|
|
66
75
|
|
|
67
76
|
it("should remove liquidity from an existing pool ", async () => {
|
|
68
77
|
const pool = await dhedge.loadPool(TEST_POOL);
|
|
69
78
|
const result = await pool.decreaseLiquidity(
|
|
70
79
|
Dapp.ARRAKIS,
|
|
71
80
|
ARRAKIS_USDC_WETH_GAUGE,
|
|
72
|
-
|
|
81
|
+
100,
|
|
73
82
|
options
|
|
74
83
|
);
|
|
75
|
-
|
|
76
|
-
|
|
84
|
+
result.wait(1);
|
|
85
|
+
const lpBalanceAfter = await pool.utils.getBalance(
|
|
86
|
+
ARRAKIS_USDC_WETH_GAUGE,
|
|
87
|
+
pool.address
|
|
88
|
+
);
|
|
89
|
+
expect(lpBalanceAfter.eq(0));
|
|
77
90
|
});
|
|
78
91
|
|
|
79
92
|
// it("should claim fees an existing pool", async () => {
|
package/src/test/constants.ts
CHANGED
|
@@ -5,19 +5,19 @@
|
|
|
5
5
|
// export const DAI = "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063";
|
|
6
6
|
// export const TUSD = "0x2e1ad108ff1d8c782fcbbb89aad783ac49586756";
|
|
7
7
|
// export const WBTC = "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6";
|
|
8
|
-
export const SUSHI = "0x0b3f868e0be5597d5db7feb59e1cadbb0fdda50a";
|
|
9
|
-
export const WMATIC = "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270";
|
|
10
|
-
export const BAL = "0x9a71012B13CA4d3D0Cdc72A177DF3ef03b0E76A3";
|
|
11
|
-
export const AMUSDC = "0x1a13f4ca1d028320a707d99520abfefca3998b7f";
|
|
12
|
-
export const VDEBTWETH = "0xede17e9d79fc6f9ff9250d9eefbdb88cc18038b5";
|
|
13
|
-
export const ARRAKIS_USDC_WETH_GAUGE =
|
|
14
|
-
|
|
15
|
-
export const STMATIC = "0x3A58a54C066FdC0f2D55FC9C89F0415C92eBf3C4";
|
|
16
|
-
export const WMATIC_STMATIC_LP = "0xaF5E0B5425dE1F5a630A8cB5AA9D97B8141C908D";
|
|
17
|
-
export const AARAKIS_WNATIC_STMATIC_GAUGE =
|
|
18
|
-
|
|
19
|
-
export const ETHBULL3X = "0x460b60565cb73845d56564384ab84bf84c13e47d";
|
|
20
|
-
export const BTCBEAR2X = "0x3dbce2c8303609c17aa23b69ebe83c2f5c510ada";
|
|
8
|
+
// export const SUSHI = "0x0b3f868e0be5597d5db7feb59e1cadbb0fdda50a";
|
|
9
|
+
// export const WMATIC = "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270";
|
|
10
|
+
// export const BAL = "0x9a71012B13CA4d3D0Cdc72A177DF3ef03b0E76A3";
|
|
11
|
+
// export const AMUSDC = "0x1a13f4ca1d028320a707d99520abfefca3998b7f";
|
|
12
|
+
// export const VDEBTWETH = "0xede17e9d79fc6f9ff9250d9eefbdb88cc18038b5";
|
|
13
|
+
// export const ARRAKIS_USDC_WETH_GAUGE =
|
|
14
|
+
// "0x33d1ad9Cd88A509397CD924C2d7613C285602C20";
|
|
15
|
+
// export const STMATIC = "0x3A58a54C066FdC0f2D55FC9C89F0415C92eBf3C4";
|
|
16
|
+
// export const WMATIC_STMATIC_LP = "0xaF5E0B5425dE1F5a630A8cB5AA9D97B8141C908D";
|
|
17
|
+
// export const AARAKIS_WNATIC_STMATIC_GAUGE =
|
|
18
|
+
// "0x9928340f9E1aaAd7dF1D95E27bd9A5c715202a56";
|
|
19
|
+
// export const ETHBULL3X = "0x460b60565cb73845d56564384ab84bf84c13e47d";
|
|
20
|
+
// export const BTCBEAR2X = "0x3dbce2c8303609c17aa23b69ebe83c2f5c510ada";
|
|
21
21
|
|
|
22
22
|
//Optimism
|
|
23
23
|
export const WETH = "0x4200000000000000000000000000000000000006";
|
|
@@ -28,5 +28,8 @@ export const WBTC = "0x68f180fcCe6836688e9084f035309E29Bf0A2095";
|
|
|
28
28
|
export const OP = "4200000000000000000000000000000000000042";
|
|
29
29
|
export const WSTETH = "0x1F32b1c2345538c0c6f582fCB022739c4A194Ebb";
|
|
30
30
|
export const VEL = "0x3c8B650257cFb5f272f799F5e2b4e65093a11a05";
|
|
31
|
+
export const SUSD = "0x8c6f28f2f1a3c87f0f938b96d27520d9751ec8d9";
|
|
32
|
+
export const ARRAKIS_USDC_WETH_GAUGE =
|
|
33
|
+
"0xb8888ea29e2f70ad62a3b69b1a1342720612a00d";
|
|
31
34
|
|
|
32
|
-
export const TEST_POOL = "
|
|
35
|
+
export const TEST_POOL = "0x3d45e539df0f9fa6015106a968d732a8f6c2a40b";
|