@dhedge/v2-sdk 1.7.2 → 1.8.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 +0 -1
- package/dist/entities/pool.d.ts +16 -7
- package/dist/services/futures/constants.d.ts +3 -0
- package/dist/services/futures/index.d.ts +2 -0
- package/dist/services/futures/margin.d.ts +2 -0
- package/dist/services/futures/trade.d.ts +2 -0
- package/dist/services/velodrome/liquidity.d.ts +2 -2
- package/dist/test/constants.d.ts +24 -2
- package/dist/test/utils/token.d.ts +3 -0
- package/dist/utils/deadline.d.ts +2 -0
- package/dist/v2-sdk.cjs.development.js +4540 -5103
- 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 +7341 -7904
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +5 -2
- package/src/abi/IDhedgeEasySwapper.json +99 -239
- package/src/abi/ISynthetiXFuturesMarketV2.json +531 -0
- package/src/config.ts +4 -5
- package/src/entities/pool.ts +68 -44
- package/src/services/futures/constants.ts +4 -0
- package/src/services/futures/index.ts +2 -0
- package/src/services/futures/margin.ts +10 -0
- package/src/services/futures/trade.ts +15 -0
- package/src/services/oneInch/protocols.ts +3 -4
- package/src/services/toros/easySwapper.ts +3 -2
- package/src/services/uniswap/V3Liquidity.ts +2 -3
- package/src/services/velodrome/liquidity.ts +7 -7
- package/src/test/constants.ts +27 -2
- package/src/test/futures.test.ts +48 -0
- package/src/test/oneInch.test.ts +32 -36
- package/src/test/pool.test.ts +42 -85
- package/src/test/toros.test.ts +50 -98
- package/src/test/uniswap.test.ts +65 -30
- package/src/test/utils/token.ts +31 -0
- package/src/test/velodrome.test.ts +74 -101
- package/src/test/wallet.ts +5 -3
- package/src/utils/deadline.ts +6 -0
- package/dist/services/claim-balancer/claim.service.d.ts +0 -17
- package/dist/services/claim-balancer/claim.worker.d.ts +0 -4
- package/dist/services/claim-balancer/ipfs.service.d.ts +0 -4
- package/dist/services/claim-balancer/types.d.ts +0 -54
- package/src/services/claim-balancer/MultiTokenClaim.json +0 -115
- package/src/services/claim-balancer/claim.service.ts +0 -262
- package/src/services/claim-balancer/claim.worker.ts +0 -32
- package/src/services/claim-balancer/ipfs.service.ts +0 -12
- package/src/services/claim-balancer/types.ts +0 -66
- package/src/test/1inch.test.ts +0 -54
package/src/entities/pool.ts
CHANGED
|
@@ -9,14 +9,12 @@ import ILendingPool from "../abi/ILendingPool.json";
|
|
|
9
9
|
import ISynthetix from "../abi/ISynthetix.json";
|
|
10
10
|
import IUniswapV2Router from "../abi/IUniswapV2Router.json";
|
|
11
11
|
import INonfungiblePositionManager from "../abi/INonfungiblePositionManager.json";
|
|
12
|
-
import IBalancerMerkleOrchard from "../abi/IBalancerMerkleOrchard.json";
|
|
13
12
|
import IAaveIncentivesController from "../abi/IAaveIncentivesController.json";
|
|
14
13
|
import IArrakisV1RouterStaking from "../abi/IArrakisV1RouterStaking.json";
|
|
15
14
|
import ILiquidityGaugeV4 from "../abi/ILiquidityGaugeV4.json";
|
|
16
15
|
import IBalancerRewardsGauge from "../abi/IBalancerRewardsGauge.json";
|
|
17
16
|
|
|
18
17
|
import {
|
|
19
|
-
deadline,
|
|
20
18
|
MaxUint128,
|
|
21
19
|
networkChainIdMap,
|
|
22
20
|
nonfungiblePositionManagerAddress,
|
|
@@ -37,7 +35,6 @@ import {
|
|
|
37
35
|
} from "../types";
|
|
38
36
|
|
|
39
37
|
import { Utils } from "./utils";
|
|
40
|
-
import { ClaimService } from "../services/claim-balancer/claim.service";
|
|
41
38
|
import {
|
|
42
39
|
getUniswapV3Liquidity,
|
|
43
40
|
getUniswapV3MintParams
|
|
@@ -57,6 +54,11 @@ import {
|
|
|
57
54
|
} from "../services/velodrome/staking";
|
|
58
55
|
import { getLyraOptionTxData } from "../services/lyra/trade";
|
|
59
56
|
import { getOptionPositions } from "../services/lyra/positions";
|
|
57
|
+
import { getDeadline } from "../utils/deadline";
|
|
58
|
+
import {
|
|
59
|
+
getFuturesChangePositionTxData,
|
|
60
|
+
getFuturesChangeMarginTxData
|
|
61
|
+
} from "../services/futures";
|
|
60
62
|
|
|
61
63
|
export class Pool {
|
|
62
64
|
public readonly poolLogic: Contract;
|
|
@@ -286,7 +288,7 @@ export class Pool {
|
|
|
286
288
|
case Dapp.ONEINCH:
|
|
287
289
|
const chainId = networkChainIdMap[this.network];
|
|
288
290
|
const protocols = await getOneInchProtocols(chainId);
|
|
289
|
-
const apiUrl = `https://api.1inch.exchange/
|
|
291
|
+
const apiUrl = `https://api.1inch.exchange/v5.0/${chainId}/swap?fromTokenAddress=${assetFrom}&toTokenAddress=${assetTo}&amount=${amountIn.toString()}&fromAddress=${
|
|
290
292
|
this.address
|
|
291
293
|
}&destReceiver=${
|
|
292
294
|
this.address
|
|
@@ -342,7 +344,7 @@ export class Pool {
|
|
|
342
344
|
minAmountOut,
|
|
343
345
|
[assetFrom, assetTo],
|
|
344
346
|
this.address,
|
|
345
|
-
|
|
347
|
+
await getDeadline(this)
|
|
346
348
|
]);
|
|
347
349
|
}
|
|
348
350
|
const tx = await this.poolLogic.execTransaction(
|
|
@@ -374,7 +376,16 @@ export class Pool {
|
|
|
374
376
|
const iUniswapV2Router = new ethers.utils.Interface(IUniswapV2Router.abi);
|
|
375
377
|
const addLiquidityTxData = iUniswapV2Router.encodeFunctionData(
|
|
376
378
|
Transaction.ADD_LIQUIDITY,
|
|
377
|
-
[
|
|
379
|
+
[
|
|
380
|
+
assetA,
|
|
381
|
+
assetB,
|
|
382
|
+
amountA,
|
|
383
|
+
amountB,
|
|
384
|
+
0,
|
|
385
|
+
0,
|
|
386
|
+
this.address,
|
|
387
|
+
await getDeadline(this)
|
|
388
|
+
]
|
|
378
389
|
);
|
|
379
390
|
const tx = await this.poolLogic.execTransaction(
|
|
380
391
|
routerAddress[this.network][dapp],
|
|
@@ -403,7 +414,7 @@ export class Pool {
|
|
|
403
414
|
const iUniswapV2Router = new ethers.utils.Interface(IUniswapV2Router.abi);
|
|
404
415
|
const removeLiquidityTxData = iUniswapV2Router.encodeFunctionData(
|
|
405
416
|
Transaction.REMOVE_LIQUIDITY,
|
|
406
|
-
[assetA, assetB, amount, 0, 0, this.address,
|
|
417
|
+
[assetA, assetB, amount, 0, 0, this.address, await getDeadline(this)]
|
|
407
418
|
);
|
|
408
419
|
const tx = await this.poolLogic.execTransaction(
|
|
409
420
|
routerAddress[this.network][dapp],
|
|
@@ -773,39 +784,6 @@ export class Pool {
|
|
|
773
784
|
return tx;
|
|
774
785
|
}
|
|
775
786
|
|
|
776
|
-
/**
|
|
777
|
-
* Claim rewards from Balancer pools
|
|
778
|
-
* @param {string[]} assets Array of tokens being claimed
|
|
779
|
-
* @param {any} options Transaction options
|
|
780
|
-
* @returns {Promise<any>} Transaction
|
|
781
|
-
*/
|
|
782
|
-
async harvestBalancerRewards(options: any = null): Promise<any> {
|
|
783
|
-
const claimService = new ClaimService(this.network, this.signer);
|
|
784
|
-
const multiTokenPendingClaims = await claimService.getMultiTokensPendingClaims(
|
|
785
|
-
this.address
|
|
786
|
-
);
|
|
787
|
-
const tokens = multiTokenPendingClaims.map(
|
|
788
|
-
tokenPendingClaims => tokenPendingClaims.tokenClaimInfo.token
|
|
789
|
-
);
|
|
790
|
-
const claims = await claimService.multiTokenClaimRewards(
|
|
791
|
-
this.address,
|
|
792
|
-
multiTokenPendingClaims
|
|
793
|
-
);
|
|
794
|
-
const iBalancerMerkleOrchard = new ethers.utils.Interface(
|
|
795
|
-
IBalancerMerkleOrchard.abi
|
|
796
|
-
);
|
|
797
|
-
const harvestTxData = iBalancerMerkleOrchard.encodeFunctionData(
|
|
798
|
-
Transaction.CLAIM_DISTRIBIUTIONS,
|
|
799
|
-
[this.address, claims, tokens]
|
|
800
|
-
);
|
|
801
|
-
const tx = await this.poolLogic.execTransaction(
|
|
802
|
-
stakingAddress[this.network][Dapp.BALANCER],
|
|
803
|
-
harvestTxData,
|
|
804
|
-
options
|
|
805
|
-
);
|
|
806
|
-
return tx;
|
|
807
|
-
}
|
|
808
|
-
|
|
809
787
|
/**
|
|
810
788
|
* Claim rewards from Aave platform
|
|
811
789
|
* @param {string[]} assets Aave tokens (deposit/debt) hold by pool
|
|
@@ -947,7 +925,7 @@ export class Pool {
|
|
|
947
925
|
.div(1e6);
|
|
948
926
|
const decreaseLiquidityTxData = abi.encodeFunctionData(
|
|
949
927
|
Transaction.DECREASE_LIQUIDITY,
|
|
950
|
-
[[tokenId, liquidity, 0, 0,
|
|
928
|
+
[[tokenId, liquidity, 0, 0, await getDeadline(this)]]
|
|
951
929
|
);
|
|
952
930
|
const collectTxData = abi.encodeFunctionData(Transaction.COLLECT, [
|
|
953
931
|
[tokenId, this.address, MaxUint128, MaxUint128]
|
|
@@ -1009,7 +987,7 @@ export class Pool {
|
|
|
1009
987
|
dappAddress = nonfungiblePositionManagerAddress[this.network];
|
|
1010
988
|
const abi = new ethers.utils.Interface(INonfungiblePositionManager.abi);
|
|
1011
989
|
txData = abi.encodeFunctionData(Transaction.INCREASE_LIQUIDITY, [
|
|
1012
|
-
[tokenId, amountA, amountB, 0, 0,
|
|
990
|
+
[tokenId, amountA, amountB, 0, 0, await getDeadline(this)]
|
|
1013
991
|
]);
|
|
1014
992
|
} else if (dapp === Dapp.ARRAKIS) {
|
|
1015
993
|
dappAddress = routerAddress[this.network][dapp];
|
|
@@ -1135,7 +1113,7 @@ export class Pool {
|
|
|
1135
1113
|
): Promise<any> {
|
|
1136
1114
|
const tx = await this.poolLogic.execTransaction(
|
|
1137
1115
|
routerAddress[this.network][Dapp.VELODROME],
|
|
1138
|
-
getVelodromeAddLiquidityTxData(
|
|
1116
|
+
await getVelodromeAddLiquidityTxData(
|
|
1139
1117
|
this,
|
|
1140
1118
|
assetA,
|
|
1141
1119
|
assetB,
|
|
@@ -1166,7 +1144,13 @@ export class Pool {
|
|
|
1166
1144
|
): Promise<any> {
|
|
1167
1145
|
const tx = await this.poolLogic.execTransaction(
|
|
1168
1146
|
routerAddress[this.network][Dapp.VELODROME],
|
|
1169
|
-
getVelodromeRemoveLiquidityTxData(
|
|
1147
|
+
await getVelodromeRemoveLiquidityTxData(
|
|
1148
|
+
this,
|
|
1149
|
+
assetA,
|
|
1150
|
+
assetB,
|
|
1151
|
+
amount,
|
|
1152
|
+
isStable
|
|
1153
|
+
),
|
|
1170
1154
|
options
|
|
1171
1155
|
);
|
|
1172
1156
|
return tx;
|
|
@@ -1225,4 +1209,44 @@ export class Pool {
|
|
|
1225
1209
|
async getLyraPositions(market: LyraOptionMarket): Promise<LyraPosition[]> {
|
|
1226
1210
|
return await getOptionPositions(this, market);
|
|
1227
1211
|
}
|
|
1212
|
+
|
|
1213
|
+
/** Deposit or withdraws (negative amount) asset for Synthetix future margin trading
|
|
1214
|
+
*
|
|
1215
|
+
* @param {string} market Address of futures market
|
|
1216
|
+
* @param {BigNumber | string } changeAmount Amount to increase/decrease margin
|
|
1217
|
+
* @param {any} options Transaction options
|
|
1218
|
+
* @returns {Promise<any>} Transaction
|
|
1219
|
+
*/
|
|
1220
|
+
async changeFuturesMargin(
|
|
1221
|
+
market: string,
|
|
1222
|
+
changeAmount: BigNumber | string,
|
|
1223
|
+
options: any = null
|
|
1224
|
+
): Promise<any> {
|
|
1225
|
+
const tx = await this.poolLogic.execTransaction(
|
|
1226
|
+
market,
|
|
1227
|
+
getFuturesChangeMarginTxData(changeAmount),
|
|
1228
|
+
options
|
|
1229
|
+
);
|
|
1230
|
+
return tx;
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
/** Change position in Synthetix futures market (long/short)
|
|
1234
|
+
*
|
|
1235
|
+
* @param {string} market Address of futures market
|
|
1236
|
+
* @param {BigNumber | string } changeAmount Negative for short, positive for long
|
|
1237
|
+
* @param {any} options Transaction options
|
|
1238
|
+
* @returns {Promise<any>} Transaction
|
|
1239
|
+
*/
|
|
1240
|
+
async changeFuturesPosition(
|
|
1241
|
+
market: string,
|
|
1242
|
+
changeAmount: BigNumber | string,
|
|
1243
|
+
options: any = null
|
|
1244
|
+
): Promise<any> {
|
|
1245
|
+
const tx = await this.poolLogic.execTransaction(
|
|
1246
|
+
market,
|
|
1247
|
+
getFuturesChangePositionTxData(changeAmount),
|
|
1248
|
+
options
|
|
1249
|
+
);
|
|
1250
|
+
return tx;
|
|
1251
|
+
}
|
|
1228
1252
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ethers } from "../..";
|
|
2
|
+
import ISynthetixFuturesMarketV2 from "../../abi/ISynthetixFuturesMarketV2.json";
|
|
3
|
+
|
|
4
|
+
export function getFuturesChangeMarginTxData(
|
|
5
|
+
amount: ethers.BigNumber | string
|
|
6
|
+
): string {
|
|
7
|
+
return new ethers.utils.Interface(
|
|
8
|
+
ISynthetixFuturesMarketV2.abi
|
|
9
|
+
).encodeFunctionData("transferMargin", [amount]);
|
|
10
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ethers } from "../..";
|
|
2
|
+
import { FUTURES_TRACKING, PRICE_IMPACT_DELTA } from "./constants";
|
|
3
|
+
import ISynthetixFuturesMarketV2 from "../../abi/ISynthetixFuturesMarketV2.json";
|
|
4
|
+
|
|
5
|
+
export function getFuturesChangePositionTxData(
|
|
6
|
+
amount: ethers.BigNumber | string
|
|
7
|
+
): string {
|
|
8
|
+
return new ethers.utils.Interface(
|
|
9
|
+
ISynthetixFuturesMarketV2.abi
|
|
10
|
+
).encodeFunctionData("submitOffchainDelayedOrderWithTracking", [
|
|
11
|
+
amount,
|
|
12
|
+
PRICE_IMPACT_DELTA,
|
|
13
|
+
ethers.utils.formatBytes32String(FUTURES_TRACKING)
|
|
14
|
+
]);
|
|
15
|
+
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
|
|
3
|
-
const excludedProtocols = ["OPTIMISM_PMM6"]; //Clipper
|
|
4
|
-
|
|
5
3
|
export async function getOneInchProtocols(chainId: number): Promise<string> {
|
|
6
4
|
try {
|
|
7
5
|
const response = await axios.get(
|
|
8
|
-
`https://api.1inch.io/
|
|
6
|
+
`https://api.1inch.io/v5.0/${chainId}/liquidity-sources`
|
|
9
7
|
);
|
|
10
8
|
const protocols = response.data.protocols.map((e: { id: string }) => e.id);
|
|
11
9
|
const filteredProtocols = protocols.filter(
|
|
12
|
-
(e: string) => !
|
|
10
|
+
(e: string) => !e.includes("PMM")
|
|
13
11
|
);
|
|
12
|
+
|
|
14
13
|
return `&protocols=${filteredProtocols.join(",")}`;
|
|
15
14
|
} catch {
|
|
16
15
|
return "";
|
|
@@ -46,7 +46,8 @@ export async function getEasySwapperDepositQuote(
|
|
|
46
46
|
torosAsset,
|
|
47
47
|
investAsset,
|
|
48
48
|
amountIn,
|
|
49
|
-
depositAsset
|
|
49
|
+
depositAsset,
|
|
50
|
+
true
|
|
50
51
|
);
|
|
51
52
|
}
|
|
52
53
|
|
|
@@ -109,7 +110,7 @@ export async function getEasySwapperTxData(
|
|
|
109
110
|
depositAsset,
|
|
110
111
|
amountIn
|
|
111
112
|
);
|
|
112
|
-
return iDhedgeEasySwapper.encodeFunctionData("
|
|
113
|
+
return iDhedgeEasySwapper.encodeFunctionData("depositWithCustomCooldown", [
|
|
113
114
|
torosAsset,
|
|
114
115
|
investAsset,
|
|
115
116
|
amountIn,
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
} from "../../config";
|
|
17
17
|
import { UniswapV3MintParams } from "./types";
|
|
18
18
|
import INonfungiblePositionManager from "../../abi/INonfungiblePositionManager.json";
|
|
19
|
+
import { getDeadline } from "../../utils/deadline";
|
|
19
20
|
|
|
20
21
|
export function tryParsePrice(
|
|
21
22
|
baseToken: Token,
|
|
@@ -103,8 +104,6 @@ export async function getUniswapV3MintParams(
|
|
|
103
104
|
? [amountB, amountA]
|
|
104
105
|
: [amountA, amountB];
|
|
105
106
|
|
|
106
|
-
const deadline = Math.floor(Date.now() / 1000) + 60 * 20;
|
|
107
|
-
|
|
108
107
|
return [
|
|
109
108
|
token0.address,
|
|
110
109
|
token1.address,
|
|
@@ -116,7 +115,7 @@ export async function getUniswapV3MintParams(
|
|
|
116
115
|
"0",
|
|
117
116
|
"0",
|
|
118
117
|
pool.address,
|
|
119
|
-
|
|
118
|
+
await getDeadline(pool)
|
|
120
119
|
];
|
|
121
120
|
}
|
|
122
121
|
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import { BigNumber, ethers } from "ethers";
|
|
3
3
|
import IVelodromeRouter from "../../abi/IVeldodromeRouter.json";
|
|
4
|
-
import { deadline } from "../../config";
|
|
5
4
|
import { Pool } from "../../entities";
|
|
6
5
|
import { Transaction } from "../../types";
|
|
6
|
+
import { getDeadline } from "../../utils/deadline";
|
|
7
7
|
|
|
8
|
-
export function getVelodromeAddLiquidityTxData(
|
|
8
|
+
export async function getVelodromeAddLiquidityTxData(
|
|
9
9
|
pool: Pool,
|
|
10
10
|
assetA: string,
|
|
11
11
|
assetB: string,
|
|
12
12
|
amountA: BigNumber | string,
|
|
13
13
|
amountB: BigNumber | string,
|
|
14
14
|
isStable: boolean
|
|
15
|
-
): any {
|
|
15
|
+
): Promise<any> {
|
|
16
16
|
const iVelodromeRouter = new ethers.utils.Interface(IVelodromeRouter.abi);
|
|
17
17
|
return iVelodromeRouter.encodeFunctionData(Transaction.ADD_LIQUIDITY, [
|
|
18
18
|
assetA,
|
|
@@ -23,17 +23,17 @@ export function getVelodromeAddLiquidityTxData(
|
|
|
23
23
|
"0",
|
|
24
24
|
"0",
|
|
25
25
|
pool.address,
|
|
26
|
-
|
|
26
|
+
await getDeadline(pool)
|
|
27
27
|
]);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export function getVelodromeRemoveLiquidityTxData(
|
|
30
|
+
export async function getVelodromeRemoveLiquidityTxData(
|
|
31
31
|
pool: Pool,
|
|
32
32
|
assetA: string,
|
|
33
33
|
assetB: string,
|
|
34
34
|
amount: BigNumber | string,
|
|
35
35
|
isStable: boolean
|
|
36
|
-
): any {
|
|
36
|
+
): Promise<any> {
|
|
37
37
|
const iVelodromeRouter = new ethers.utils.Interface(IVelodromeRouter.abi);
|
|
38
38
|
return iVelodromeRouter.encodeFunctionData(Transaction.REMOVE_LIQUIDITY, [
|
|
39
39
|
assetA,
|
|
@@ -43,6 +43,6 @@ export function getVelodromeRemoveLiquidityTxData(
|
|
|
43
43
|
"0",
|
|
44
44
|
"0",
|
|
45
45
|
pool.address,
|
|
46
|
-
|
|
46
|
+
await getDeadline(pool)
|
|
47
47
|
]);
|
|
48
48
|
}
|
package/src/test/constants.ts
CHANGED
|
@@ -19,17 +19,42 @@
|
|
|
19
19
|
// export const ETHBULL3X = "0x460b60565cb73845d56564384ab84bf84c13e47d";
|
|
20
20
|
// export const BTCBEAR2X = "0x3dbce2c8303609c17aa23b69ebe83c2f5c510ada";
|
|
21
21
|
|
|
22
|
+
import { ethers } from "ethers";
|
|
23
|
+
import { Network } from "../types";
|
|
24
|
+
|
|
22
25
|
//Optimism
|
|
23
26
|
export const WETH = "0x4200000000000000000000000000000000000006";
|
|
24
27
|
export const USDC = "0x7F5c764cBc14f9669B88837ca1490cCa17c31607";
|
|
25
28
|
export const DAI = "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1";
|
|
26
29
|
export const USDy = "0x1ec50880101022c11530a069690f5446d1464592";
|
|
27
30
|
export const WBTC = "0x68f180fcCe6836688e9084f035309E29Bf0A2095";
|
|
28
|
-
export const OP = "
|
|
31
|
+
export const OP = "0x4200000000000000000000000000000000000042";
|
|
29
32
|
export const WSTETH = "0x1F32b1c2345538c0c6f582fCB022739c4A194Ebb";
|
|
30
33
|
export const VEL = "0x3c8B650257cFb5f272f799F5e2b4e65093a11a05";
|
|
31
34
|
export const SUSD = "0x8c6f28f2f1a3c87f0f938b96d27520d9751ec8d9";
|
|
35
|
+
export const SETH = "0xE405de8F52ba7559f9df3C368500B6E6ae6Cee49";
|
|
32
36
|
export const ARRAKIS_USDC_WETH_GAUGE =
|
|
33
37
|
"0xb8888ea29e2f70ad62a3b69b1a1342720612a00d";
|
|
38
|
+
export const KWENTA_ETH_PERP = "0xf86048dff23cf130107dfb4e6386f574231a5c65";
|
|
39
|
+
export const KWENTA_ETH_PERP_V2 = "0x2b3bb4c683bfc5239b029131eef3b1d214478d93";
|
|
40
|
+
|
|
41
|
+
export const TEST_POOL = {
|
|
42
|
+
[Network.POLYGON]: "0x699fd4d6eadb216704c7e355cfa0a12f51813163",
|
|
43
|
+
[Network.OPTIMISM]: "0x12573bfdf764ab9d52aca20e2827497a66829716"
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const CONTRACT_ADDRESS = {
|
|
47
|
+
[Network.POLYGON]: {
|
|
48
|
+
USDC: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
|
|
49
|
+
WETH: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
|
|
50
|
+
WBTC: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6"
|
|
51
|
+
},
|
|
52
|
+
[Network.OPTIMISM]: {
|
|
53
|
+
USDC: "0x7F5c764cBc14f9669B88837ca1490cCa17c31607",
|
|
54
|
+
SUSD: "0x8c6f28f2f1a3c87f0f938b96d27520d9751ec8d9",
|
|
55
|
+
WETH: "0x4200000000000000000000000000000000000006",
|
|
56
|
+
KWENTA_ETH_PERP_V2: "0x2b3bb4c683bfc5239b029131eef3b1d214478d93"
|
|
57
|
+
}
|
|
58
|
+
};
|
|
34
59
|
|
|
35
|
-
export const
|
|
60
|
+
export const MAX_AMOUNT = ethers.constants.MaxUint256;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Dhedge, Pool } from "..";
|
|
2
|
+
import { Network } from "../types";
|
|
3
|
+
import { CONTRACT_ADDRESS, TEST_POOL } from "./constants";
|
|
4
|
+
import { balanceDelta } from "./utils/token";
|
|
5
|
+
import { wallet } from "./wallet";
|
|
6
|
+
|
|
7
|
+
jest.setTimeout(100000);
|
|
8
|
+
|
|
9
|
+
const network = Network.OPTIMISM;
|
|
10
|
+
const perp = CONTRACT_ADDRESS[network].KWENTA_ETH_PERP_V2;
|
|
11
|
+
|
|
12
|
+
describe("pool", () => {
|
|
13
|
+
let dhedge: Dhedge;
|
|
14
|
+
let pool: Pool;
|
|
15
|
+
beforeAll(async () => {
|
|
16
|
+
dhedge = new Dhedge(wallet, network);
|
|
17
|
+
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("deposits 50 sUSD margin into ETH future market", async () => {
|
|
21
|
+
const depositAmount = (50 * 1e18).toString();
|
|
22
|
+
await pool.changeFuturesMargin(perp, depositAmount);
|
|
23
|
+
|
|
24
|
+
const sUSDBalanceDelta = await balanceDelta(
|
|
25
|
+
pool.address,
|
|
26
|
+
CONTRACT_ADDRESS[network].SUSD,
|
|
27
|
+
pool.signer
|
|
28
|
+
);
|
|
29
|
+
expect(sUSDBalanceDelta.abs().toString()).toBe(depositAmount);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("goes long ETH-PERP about 3x leverage", async () => {
|
|
33
|
+
//size 50*3/1600 (margin * leverage / price)
|
|
34
|
+
const size = (0.09 * 1e18).toString();
|
|
35
|
+
const tx = await pool.changeFuturesPosition(perp, size);
|
|
36
|
+
expect(tx).not.toBe(null);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("removes 20 sUSD margin from ETH future market", async () => {
|
|
40
|
+
await pool.changeFuturesMargin(perp, (-20 * 1e18).toString());
|
|
41
|
+
const sUSDBalanceDelta = await balanceDelta(
|
|
42
|
+
pool.address,
|
|
43
|
+
CONTRACT_ADDRESS[network].SUSD,
|
|
44
|
+
pool.signer
|
|
45
|
+
);
|
|
46
|
+
expect(sUSDBalanceDelta.gt(0));
|
|
47
|
+
});
|
|
48
|
+
});
|
package/src/test/oneInch.test.ts
CHANGED
|
@@ -1,49 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
|
+
import { Dhedge, Pool } from "..";
|
|
3
|
+
import { routerAddress } from "../config";
|
|
2
4
|
import { Dapp, Network } from "../types";
|
|
3
|
-
import {
|
|
5
|
+
import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
|
|
6
|
+
import { allowanceDelta, balanceDelta } from "./utils/token";
|
|
4
7
|
|
|
5
8
|
import { wallet } from "./wallet";
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
// const network = Network.OPTIMISM;
|
|
11
|
+
const network = Network.POLYGON;
|
|
12
|
+
const USDC = CONTRACT_ADDRESS[network].USDC;
|
|
13
|
+
const WETH = CONTRACT_ADDRESS[network].WETH;
|
|
8
14
|
|
|
15
|
+
let dhedge: Dhedge;
|
|
16
|
+
let pool: Pool;
|
|
9
17
|
jest.setTimeout(100000);
|
|
10
18
|
|
|
11
|
-
// const options = {
|
|
12
|
-
// gasLimit: 5000000,
|
|
13
|
-
// gasPrice: ethers.utils.parseUnits("35", "gwei")
|
|
14
|
-
// };
|
|
15
|
-
|
|
16
19
|
describe("pool", () => {
|
|
17
|
-
beforeAll(() => {
|
|
18
|
-
dhedge = new Dhedge(wallet,
|
|
20
|
+
beforeAll(async () => {
|
|
21
|
+
dhedge = new Dhedge(wallet, network);
|
|
22
|
+
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
19
23
|
});
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// } catch (e) {
|
|
32
|
-
// console.log(e);
|
|
33
|
-
// }
|
|
34
|
-
// expect(result).not.toBe(null);
|
|
35
|
-
// });
|
|
25
|
+
it("approves unlimited USDC on 1Inch", async () => {
|
|
26
|
+
await pool.approve(Dapp.ONEINCH, USDC, MAX_AMOUNT);
|
|
27
|
+
const usdcAllowanceDelta = await allowanceDelta(
|
|
28
|
+
pool.address,
|
|
29
|
+
USDC,
|
|
30
|
+
routerAddress[network]["1inch"]!,
|
|
31
|
+
pool.signer
|
|
32
|
+
);
|
|
33
|
+
await expect(usdcAllowanceDelta.gt(0));
|
|
34
|
+
});
|
|
36
35
|
|
|
37
|
-
it("trades
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
console.log(e);
|
|
46
|
-
}
|
|
47
|
-
expect(result).not.toBe(null);
|
|
36
|
+
it("trades 5 USDC into WETH on 1Inch", async () => {
|
|
37
|
+
await pool.trade(Dapp.ONEINCH, USDC, WETH, "5000000", 0.5);
|
|
38
|
+
const wethBalanceDelta = await balanceDelta(
|
|
39
|
+
pool.address,
|
|
40
|
+
WETH,
|
|
41
|
+
pool.signer
|
|
42
|
+
);
|
|
43
|
+
expect(wethBalanceDelta.gt(0));
|
|
48
44
|
});
|
|
49
45
|
});
|