@dhedge/v2-sdk 2.1.8 → 2.2.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/README.md +404 -54
- package/dist/config.d.ts +13 -2
- package/dist/entities/pool.d.ts +25 -86
- package/dist/entities/utils.d.ts +15 -0
- package/dist/services/hyperliquid/index.d.ts +22 -0
- package/dist/services/kyberSwap/index.d.ts +1 -1
- package/dist/services/ondo/index.d.ts +5 -0
- package/dist/services/oneInch/index.d.ts +1 -1
- package/dist/services/toros/easySwapper.d.ts +14 -0
- package/dist/services/toros/swapData.d.ts +5 -5
- package/dist/services/uniswap/V3Liquidity.d.ts +2 -2
- package/dist/services/velodrome/liquidity.d.ts +3 -0
- package/dist/test/constants.d.ts +48 -3
- package/dist/test/utils/testingHelper.d.ts +4 -0
- package/dist/types.d.ts +21 -5
- package/dist/utils/contract.d.ts +20 -0
- package/dist/v2-sdk.cjs.development.js +5133 -6641
- 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 +5138 -6641
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/PoolFactory.json +414 -204
- package/src/abi/PoolLogic.json +160 -134
- package/src/abi/ondo/IOndoGMSwap.json +30 -0
- package/src/config.ts +15 -9
- package/src/entities/pool.ts +56 -253
- package/src/entities/utils.ts +15 -0
- package/src/services/hyperliquid/index.ts +22 -0
- package/src/services/kyberSwap/index.ts +5 -3
- package/src/services/ondo/index.ts +142 -0
- package/src/services/oneInch/index.ts +5 -4
- package/src/services/toros/completeWithdrawal.ts +57 -40
- package/src/services/toros/easySwapper.ts +15 -1
- package/src/services/toros/initWithdrawal.ts +39 -31
- package/src/services/toros/swapData.ts +45 -131
- package/src/services/uniswap/V3Liquidity.ts +3 -24
- package/src/services/velodrome/liquidity.ts +3 -0
- package/src/test/aave.test.ts +99 -70
- package/src/test/aerodrome.test.ts +53 -24
- package/src/test/aerodromeCL.test.ts +64 -30
- package/src/test/arrakis.test.ts +23 -35
- package/src/test/balancer.test.ts +114 -106
- package/src/test/compoundV3.test.ts +45 -29
- package/src/test/constants.ts +56 -11
- package/src/test/cowswap.test.ts +33 -35
- package/src/test/dhedge.test.ts +45 -12
- package/src/test/flatmoney.test.ts +25 -39
- package/src/test/fluid.test.ts +33 -24
- package/src/test/hyperliquid.onchain.test.ts +131 -0
- package/src/test/kyberSwap.test.ts +37 -16
- package/src/test/lyra.test.ts +159 -150
- package/src/test/odos.test.ts +2 -2
- package/src/test/ondo.onchain.test.ts +132 -0
- package/src/test/oneInch.test.ts +36 -22
- package/src/test/pancakeCL.test.ts +72 -31
- package/src/test/pendle.test.ts +94 -54
- package/src/test/{pendleMint.test.ts → pendleMint.onchain.test.ts} +22 -8
- package/src/test/pool.test.ts +152 -95
- package/src/test/toros.onchain.test.ts +92 -0
- package/src/test/toros.test.ts +74 -20
- package/src/test/torosLimitOrder.test.ts +87 -42
- package/src/test/uniswap.test.ts +77 -128
- package/src/test/utils/testingHelper.ts +120 -0
- package/src/test/velodrome.test.ts +126 -92
- package/src/test/velodromeCL.test.ts +43 -31
- package/src/test/velodromeV2.test.ts +153 -95
- package/src/types.ts +22 -6
- package/src/utils/contract.ts +20 -0
- package/dist/services/futures/constants.d.ts +0 -1
- package/dist/services/futures/index.d.ts +0 -2
- package/dist/services/futures/margin.d.ts +0 -2
- package/dist/services/futures/trade.d.ts +0 -3
- package/dist/services/ramses/vesting.d.ts +0 -4
- package/dist/services/uniswap/V3Trade.d.ts +0 -3
- package/dist/test/utils/futures.d.ts +0 -2
- package/src/abi/IRamsesNonfungiblePositionManager.json +0 -486
- package/src/abi/ISynthetiXFuturesMarketV2.json +0 -531
- package/src/abi/ISynthetix.json +0 -139
- package/src/abi/IUniswapV3Quoter.json +0 -195
- package/src/abi/IUniswapV3Router.json +0 -221
- package/src/abi/IXRam.json +0 -99
- package/src/services/futures/constants.ts +0 -1
- package/src/services/futures/index.ts +0 -2
- package/src/services/futures/margin.ts +0 -10
- package/src/services/futures/trade.ts +0 -32
- package/src/services/ramses/vesting.ts +0 -24
- package/src/services/uniswap/V3Trade.ts +0 -46
- package/src/test/futures.test.ts +0 -51
- package/src/test/hyperliquid.test.ts +0 -107
- package/src/test/ramses.test.ts +0 -190
- package/src/test/ramsesCL.test.ts +0 -155
- package/src/test/synthetix.test.ts +0 -36
- package/src/test/utils/futures.ts +0 -14
package/src/entities/pool.ts
CHANGED
|
@@ -7,7 +7,7 @@ import IERC20 from "../abi/IERC20.json";
|
|
|
7
7
|
import IERC721 from "../abi/IERC721.json";
|
|
8
8
|
import IMiniChefV2 from "../abi/IMiniChefV2.json";
|
|
9
9
|
import ILendingPool from "../abi/ILendingPool.json";
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
import IUniswapV2Router from "../abi/IUniswapV2Router.json";
|
|
12
12
|
import INonfungiblePositionManager from "../abi/INonfungiblePositionManager.json";
|
|
13
13
|
import IAaveIncentivesController from "../abi/IAaveIncentivesController.json";
|
|
@@ -20,7 +20,6 @@ import {
|
|
|
20
20
|
routerAddress,
|
|
21
21
|
gpv2SettlementAddress,
|
|
22
22
|
stakingAddress,
|
|
23
|
-
SYNTHETIX_TRACKING_CODE,
|
|
24
23
|
limitOrderAddress
|
|
25
24
|
} from "../config";
|
|
26
25
|
import {
|
|
@@ -43,7 +42,7 @@ import {
|
|
|
43
42
|
getIncreaseLiquidityTxData,
|
|
44
43
|
getUniswapV3MintTxData
|
|
45
44
|
} from "../services/uniswap/V3Liquidity";
|
|
46
|
-
|
|
45
|
+
|
|
47
46
|
import { getEasySwapperTxData } from "../services/toros/easySwapper";
|
|
48
47
|
import { getAaveV3ClaimTxData } from "../services/aave/incentives";
|
|
49
48
|
import {
|
|
@@ -59,17 +58,7 @@ import {
|
|
|
59
58
|
import { getLyraOptionTxData } from "../services/lyra/trade";
|
|
60
59
|
import { getOptionPositions } from "../services/lyra/positions";
|
|
61
60
|
import { getDeadline } from "../utils/deadline";
|
|
62
|
-
import {
|
|
63
|
-
getFuturesChangeMarginTxData,
|
|
64
|
-
getFuturesChangePositionTxData
|
|
65
|
-
} from "../services/futures";
|
|
66
|
-
import { getFuturesCancelOrderTxData } from "../services/futures/trade";
|
|
67
61
|
import { getOneInchSwapTxData } from "../services/oneInch";
|
|
68
|
-
import {
|
|
69
|
-
getCreateVestTxData,
|
|
70
|
-
getExitVestTxData,
|
|
71
|
-
getRewardsTxDta
|
|
72
|
-
} from "../services/ramses/vesting";
|
|
73
62
|
import { getPoolTxOrGasEstimate, isSdkOptionsBoolean } from "../utils/contract";
|
|
74
63
|
import {
|
|
75
64
|
cancelOrderViaFlatMoney,
|
|
@@ -98,6 +87,7 @@ import {
|
|
|
98
87
|
} from "../services/toros/limitOrder";
|
|
99
88
|
import { getKyberSwapTxData } from "../services/kyberSwap";
|
|
100
89
|
import { getCowSwapTxData } from "../services/cowSwap";
|
|
90
|
+
import { getOndoSwapTxData } from "../services/ondo";
|
|
101
91
|
import {
|
|
102
92
|
getClosePositionHyperliquidTxData,
|
|
103
93
|
getDepositHyperliquidTxData,
|
|
@@ -164,7 +154,7 @@ export class Pool {
|
|
|
164
154
|
|
|
165
155
|
/**
|
|
166
156
|
* Approve the asset that can be deposited into a pool
|
|
167
|
-
* @param {string}
|
|
157
|
+
* @param {string} asset Address of deposit asset
|
|
168
158
|
* @param {BigNumber | string} amount Amount to be approved
|
|
169
159
|
* @param {any} options Transaction options
|
|
170
160
|
* @param {boolean} estimateGas Simulate/estimate gas
|
|
@@ -264,7 +254,7 @@ export class Pool {
|
|
|
264
254
|
* Approve the liquidity pool token for staking
|
|
265
255
|
* @param {Dapp} dapp Platform like Sushiswap or Uniswap
|
|
266
256
|
* @param {string} asset Address of liquidity pool token
|
|
267
|
-
* @param {BigNumber | string} amount
|
|
257
|
+
* @param {BigNumber | string} amount Amount to be approved
|
|
268
258
|
* @param {any} options Transaction options
|
|
269
259
|
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
270
260
|
* @returns {Promise<any>} Transaction
|
|
@@ -292,10 +282,10 @@ export class Pool {
|
|
|
292
282
|
}
|
|
293
283
|
|
|
294
284
|
/**
|
|
295
|
-
* Approve
|
|
296
|
-
*
|
|
297
|
-
* @param {string} asset Address of
|
|
298
|
-
* @param {BigNumber | string} amount
|
|
285
|
+
* Approve an asset for the Uniswap V3 NonfungiblePositionManager
|
|
286
|
+
* (used before mint/increase liquidity calls)
|
|
287
|
+
* @param {string} asset Address of asset to approve
|
|
288
|
+
* @param {BigNumber | string} amount Amount to be approved
|
|
299
289
|
* @param {any} options Transaction options
|
|
300
290
|
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
301
291
|
* @returns {Promise<any>} Transaction
|
|
@@ -426,20 +416,6 @@ export class Pool {
|
|
|
426
416
|
slippage
|
|
427
417
|
);
|
|
428
418
|
break;
|
|
429
|
-
case Dapp.SYNTHETIX:
|
|
430
|
-
const iSynthetix = new ethers.utils.Interface(ISynthetix.abi);
|
|
431
|
-
const assets = [assetFrom, assetTo].map(asset =>
|
|
432
|
-
ethers.utils.formatBytes32String(asset)
|
|
433
|
-
);
|
|
434
|
-
const daoAddress = await this.factory.owner();
|
|
435
|
-
swapTxData = iSynthetix.encodeFunctionData(Transaction.SWAP_SYNTHS, [
|
|
436
|
-
assets[0],
|
|
437
|
-
amountIn,
|
|
438
|
-
assets[1],
|
|
439
|
-
daoAddress,
|
|
440
|
-
SYNTHETIX_TRACKING_CODE
|
|
441
|
-
]);
|
|
442
|
-
break;
|
|
443
419
|
case Dapp.TOROS:
|
|
444
420
|
swapTxData = await getEasySwapperTxData(
|
|
445
421
|
this,
|
|
@@ -476,6 +452,15 @@ export class Pool {
|
|
|
476
452
|
slippage
|
|
477
453
|
));
|
|
478
454
|
break;
|
|
455
|
+
case Dapp.ONDO:
|
|
456
|
+
({ swapTxData, minAmountOut } = await getOndoSwapTxData(
|
|
457
|
+
this,
|
|
458
|
+
assetFrom,
|
|
459
|
+
assetTo,
|
|
460
|
+
amountIn.toString(),
|
|
461
|
+
slippage
|
|
462
|
+
));
|
|
463
|
+
break;
|
|
479
464
|
case Dapp.COWSWAP: {
|
|
480
465
|
const cowSwapEstimateGas = isSdkOptionsBoolean(sdkOptions)
|
|
481
466
|
? sdkOptions
|
|
@@ -696,7 +681,6 @@ export class Pool {
|
|
|
696
681
|
]);
|
|
697
682
|
break;
|
|
698
683
|
case Dapp.VELODROME:
|
|
699
|
-
case Dapp.RAMSES:
|
|
700
684
|
stakeTxData = getVelodromeStakeTxData(amount, false);
|
|
701
685
|
break;
|
|
702
686
|
case Dapp.VELODROMEV2:
|
|
@@ -862,7 +846,7 @@ export class Pool {
|
|
|
862
846
|
}
|
|
863
847
|
|
|
864
848
|
/**
|
|
865
|
-
*
|
|
849
|
+
* Withdraw asset from a lending pool
|
|
866
850
|
* @param {Dapp} dapp Platform like Aave
|
|
867
851
|
* @param {string} asset Asset
|
|
868
852
|
* @param {BigNumber | string} amount Amount of asset to lend
|
|
@@ -894,7 +878,7 @@ export class Pool {
|
|
|
894
878
|
}
|
|
895
879
|
|
|
896
880
|
/**
|
|
897
|
-
*
|
|
881
|
+
* Withdraw asset from a Compound V3 or Fluid lending pool
|
|
898
882
|
* @param {string} market Address of cToken or fToken
|
|
899
883
|
* @param {string} asset Asset
|
|
900
884
|
* @param {BigNumber | string} amount Amount of asset to withdraw
|
|
@@ -1042,9 +1026,25 @@ export class Pool {
|
|
|
1042
1026
|
e.asset.toLocaleLowerCase()
|
|
1043
1027
|
);
|
|
1044
1028
|
const newAssets = assets.map(e => e.asset.toLocaleLowerCase());
|
|
1045
|
-
const
|
|
1029
|
+
const candidateRemovals = currentAssets.filter(e => !newAssets.includes(e));
|
|
1046
1030
|
const changedAssets = assets.map(e => [e.asset, e.isDeposit]);
|
|
1047
1031
|
|
|
1032
|
+
// Simulate each removal to filter out assets that can't be removed
|
|
1033
|
+
// (non-zero balance, guard dependency, active order, etc.)
|
|
1034
|
+
const removedAssets: string[] = [];
|
|
1035
|
+
for (const asset of candidateRemovals) {
|
|
1036
|
+
try {
|
|
1037
|
+
await this.managerLogic.callStatic.changeAssets([], [asset]);
|
|
1038
|
+
removedAssets.push(asset);
|
|
1039
|
+
} catch (err) {
|
|
1040
|
+
console.warn(
|
|
1041
|
+
`changeAssets: skipping removal of ${asset} — ${
|
|
1042
|
+
(err as Error).message
|
|
1043
|
+
}`
|
|
1044
|
+
);
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
1048
|
if (estimateGas) {
|
|
1049
1049
|
return await this.managerLogic.estimateGas.changeAssets(
|
|
1050
1050
|
changedAssets,
|
|
@@ -1159,11 +1159,11 @@ export class Pool {
|
|
|
1159
1159
|
}
|
|
1160
1160
|
|
|
1161
1161
|
/**
|
|
1162
|
-
*
|
|
1162
|
+
* Exit a Balancer pool
|
|
1163
1163
|
* @param {string} poolId Balancer pool id
|
|
1164
|
-
* @param {string[]
|
|
1165
|
-
* @param {BigNumber | string
|
|
1166
|
-
* @param {
|
|
1164
|
+
* @param {string[]} assets Array of balancer pool assets
|
|
1165
|
+
* @param {BigNumber | string} amount Amount of pool tokens to withdraw
|
|
1166
|
+
* @param {null | number} singleExitAssetIndex Index of asset to withdraw to
|
|
1167
1167
|
* @param {any} options Transaction options
|
|
1168
1168
|
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
1169
1169
|
* @returns {Promise<any>} Transaction
|
|
@@ -1306,12 +1306,7 @@ export class Pool {
|
|
|
1306
1306
|
* @returns {Promise<any>} Transaction
|
|
1307
1307
|
*/
|
|
1308
1308
|
async addLiquidityUniswapV3(
|
|
1309
|
-
dapp:
|
|
1310
|
-
| Dapp.UNISWAPV3
|
|
1311
|
-
| Dapp.VELODROMECL
|
|
1312
|
-
| Dapp.AERODROMECL
|
|
1313
|
-
| Dapp.RAMSESCL
|
|
1314
|
-
| Dapp.PANCAKECL,
|
|
1309
|
+
dapp: Dapp.UNISWAPV3 | Dapp.VELODROMECL | Dapp.AERODROMECL | Dapp.PANCAKECL,
|
|
1315
1310
|
assetA: string,
|
|
1316
1311
|
assetB: string,
|
|
1317
1312
|
amountA: BigNumber | string,
|
|
@@ -1383,7 +1378,6 @@ export class Pool {
|
|
|
1383
1378
|
let txData;
|
|
1384
1379
|
switch (dapp) {
|
|
1385
1380
|
case Dapp.UNISWAPV3:
|
|
1386
|
-
case Dapp.RAMSESCL:
|
|
1387
1381
|
dappAddress = nonfungiblePositionManagerAddress[this.network][dapp];
|
|
1388
1382
|
break;
|
|
1389
1383
|
case Dapp.VELODROMECL:
|
|
@@ -1450,7 +1444,6 @@ export class Pool {
|
|
|
1450
1444
|
let txData;
|
|
1451
1445
|
switch (dapp) {
|
|
1452
1446
|
case Dapp.UNISWAPV3:
|
|
1453
|
-
case Dapp.RAMSESCL:
|
|
1454
1447
|
dappAddress = nonfungiblePositionManagerAddress[this.network][dapp];
|
|
1455
1448
|
break;
|
|
1456
1449
|
case Dapp.VELODROMECL:
|
|
@@ -1516,7 +1509,6 @@ export class Pool {
|
|
|
1516
1509
|
);
|
|
1517
1510
|
switch (dapp) {
|
|
1518
1511
|
case Dapp.UNISWAPV3:
|
|
1519
|
-
case Dapp.RAMSESCL:
|
|
1520
1512
|
contractAddress = nonfungiblePositionManagerAddress[this.network][dapp];
|
|
1521
1513
|
txData = iNonfungiblePositionManager.encodeFunctionData(
|
|
1522
1514
|
Transaction.COLLECT,
|
|
@@ -1530,7 +1522,6 @@ export class Pool {
|
|
|
1530
1522
|
txData = abi.encodeFunctionData("claim_rewards()", []);
|
|
1531
1523
|
break;
|
|
1532
1524
|
case Dapp.VELODROME:
|
|
1533
|
-
case Dapp.RAMSES:
|
|
1534
1525
|
contractAddress = tokenId;
|
|
1535
1526
|
txData = getVelodromeClaimTxData(this, tokenId, false);
|
|
1536
1527
|
break;
|
|
@@ -1571,75 +1562,6 @@ export class Pool {
|
|
|
1571
1562
|
return tx;
|
|
1572
1563
|
}
|
|
1573
1564
|
|
|
1574
|
-
/**
|
|
1575
|
-
* Get rewards of an NFT position
|
|
1576
|
-
* @param {Dapp} dapp Platform e.g. Ramses CL
|
|
1577
|
-
* @param {string} tokenId Token Id
|
|
1578
|
-
* @param {string[]} rewards Reward tokens
|
|
1579
|
-
* @param {any} options Transaction option
|
|
1580
|
-
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
1581
|
-
* @returns {Promise<any>} Transaction
|
|
1582
|
-
*/
|
|
1583
|
-
async getRewards(
|
|
1584
|
-
dapp: Dapp,
|
|
1585
|
-
tokenId: string,
|
|
1586
|
-
rewards: string[],
|
|
1587
|
-
options: any = null,
|
|
1588
|
-
sdkOptions: SDKOptions = {
|
|
1589
|
-
estimateGas: false
|
|
1590
|
-
}
|
|
1591
|
-
): Promise<any> {
|
|
1592
|
-
const tx = await getPoolTxOrGasEstimate(
|
|
1593
|
-
this,
|
|
1594
|
-
[
|
|
1595
|
-
nonfungiblePositionManagerAddress[this.network][dapp],
|
|
1596
|
-
getRewardsTxDta(tokenId, rewards),
|
|
1597
|
-
options
|
|
1598
|
-
],
|
|
1599
|
-
sdkOptions
|
|
1600
|
-
);
|
|
1601
|
-
return tx;
|
|
1602
|
-
}
|
|
1603
|
-
|
|
1604
|
-
/**
|
|
1605
|
-
* Trade an asset into another asset
|
|
1606
|
-
* @param {Dapp} dapp Platform like Sushiswap or Uniswap
|
|
1607
|
-
* @param {string} assetFrom Asset to trade from
|
|
1608
|
-
* @param {string} assetTo Asset to trade into
|
|
1609
|
-
* @param {BigNumber | string} amountIn Amount
|
|
1610
|
-
* @param { FeeAmount } feeAmount Fee tier (Low 0.05%, Medium 0.3%, High 1%)
|
|
1611
|
-
* @param {number} slippage Slippage tolerance in %
|
|
1612
|
-
* @param {any} options Transaction options
|
|
1613
|
-
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
1614
|
-
* @returns {Promise<any>} Transaction
|
|
1615
|
-
*/
|
|
1616
|
-
async tradeUniswapV3(
|
|
1617
|
-
assetFrom: string,
|
|
1618
|
-
assetTo: string,
|
|
1619
|
-
amountIn: BigNumber | string,
|
|
1620
|
-
feeAmount: number,
|
|
1621
|
-
slippage = 0.5,
|
|
1622
|
-
options: any = null,
|
|
1623
|
-
sdkOptions: SDKOptions = {
|
|
1624
|
-
estimateGas: false
|
|
1625
|
-
}
|
|
1626
|
-
): Promise<any> {
|
|
1627
|
-
const swapxData = await getUniswapV3SwapTxData(
|
|
1628
|
-
this,
|
|
1629
|
-
assetFrom,
|
|
1630
|
-
assetTo,
|
|
1631
|
-
amountIn,
|
|
1632
|
-
slippage,
|
|
1633
|
-
feeAmount
|
|
1634
|
-
);
|
|
1635
|
-
const tx = await getPoolTxOrGasEstimate(
|
|
1636
|
-
this,
|
|
1637
|
-
[routerAddress[this.network][Dapp.UNISWAPV3], swapxData, options],
|
|
1638
|
-
sdkOptions
|
|
1639
|
-
);
|
|
1640
|
-
return tx;
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
1565
|
/**
|
|
1644
1566
|
* Add liquidity to Velodrome pool
|
|
1645
1567
|
* @param {string} assetA First asset
|
|
@@ -1799,8 +1721,8 @@ export class Pool {
|
|
|
1799
1721
|
}
|
|
1800
1722
|
|
|
1801
1723
|
/**
|
|
1802
|
-
* Add liquidity to Velodrome V2 or
|
|
1803
|
-
* @param {Dapp} dapp VelodromeV2
|
|
1724
|
+
* Add liquidity to Velodrome V2 or Aerodrome pool
|
|
1725
|
+
* @param {Dapp} dapp VelodromeV2 or Aerodrome
|
|
1804
1726
|
* @param {string} assetA First asset
|
|
1805
1727
|
* @param {string} assetB Second asset
|
|
1806
1728
|
* @param {BigNumber | string} amountA Amount first asset
|
|
@@ -1811,7 +1733,7 @@ export class Pool {
|
|
|
1811
1733
|
* @returns {Promise<any>} Transaction
|
|
1812
1734
|
*/
|
|
1813
1735
|
async addLiquidityV2(
|
|
1814
|
-
dapp: Dapp.VELODROMEV2 | Dapp.
|
|
1736
|
+
dapp: Dapp.VELODROMEV2 | Dapp.AERODROME,
|
|
1815
1737
|
assetA: string,
|
|
1816
1738
|
assetB: string,
|
|
1817
1739
|
amountA: BigNumber | string,
|
|
@@ -1842,8 +1764,8 @@ export class Pool {
|
|
|
1842
1764
|
}
|
|
1843
1765
|
|
|
1844
1766
|
/**
|
|
1845
|
-
* Remove liquidity from Velodrome V2 or
|
|
1846
|
-
* @param {Dapp} dapp VelodromeV2
|
|
1767
|
+
* Remove liquidity from Velodrome V2 or Aerodrome pool
|
|
1768
|
+
* @param {Dapp} dapp VelodromeV2 or Aerodrome
|
|
1847
1769
|
* @param {string} assetA First asset
|
|
1848
1770
|
* @param {string} assetB Second asset
|
|
1849
1771
|
* @param {BigNumber | string} amount Amount of LP tokens
|
|
@@ -1853,7 +1775,7 @@ export class Pool {
|
|
|
1853
1775
|
* @returns {Promise<any>} Transaction
|
|
1854
1776
|
*/
|
|
1855
1777
|
async removeLiquidityV2(
|
|
1856
|
-
dapp: Dapp.VELODROMEV2 | Dapp.
|
|
1778
|
+
dapp: Dapp.VELODROMEV2 | Dapp.AERODROME,
|
|
1857
1779
|
assetA: string,
|
|
1858
1780
|
assetB: string,
|
|
1859
1781
|
amount: BigNumber | string,
|
|
@@ -1939,82 +1861,6 @@ export class Pool {
|
|
|
1939
1861
|
return await getOptionPositions(this, market);
|
|
1940
1862
|
}
|
|
1941
1863
|
|
|
1942
|
-
/** Deposit or withdraws (negative amount) asset for Synthetix future margin trading
|
|
1943
|
-
*
|
|
1944
|
-
* @param {string} market Address of futures market
|
|
1945
|
-
* @param {BigNumber | string } changeAmount Amount to increase/decrease margin
|
|
1946
|
-
* @param {any} options Transaction options
|
|
1947
|
-
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
1948
|
-
* @returns {Promise<any>} Transaction
|
|
1949
|
-
*/
|
|
1950
|
-
async changeFuturesMargin(
|
|
1951
|
-
market: string,
|
|
1952
|
-
changeAmount: BigNumber | string,
|
|
1953
|
-
options: any = null,
|
|
1954
|
-
sdkOptions: SDKOptions = {
|
|
1955
|
-
estimateGas: false
|
|
1956
|
-
}
|
|
1957
|
-
): Promise<any> {
|
|
1958
|
-
const tx = await getPoolTxOrGasEstimate(
|
|
1959
|
-
this,
|
|
1960
|
-
[market, getFuturesChangeMarginTxData(changeAmount), options],
|
|
1961
|
-
sdkOptions
|
|
1962
|
-
);
|
|
1963
|
-
return tx;
|
|
1964
|
-
}
|
|
1965
|
-
|
|
1966
|
-
/** Change position in Synthetix futures market (long/short)
|
|
1967
|
-
*
|
|
1968
|
-
* @param {string} market Address of futures market
|
|
1969
|
-
* @param {BigNumber | string } changeAmount Negative for short, positive for long
|
|
1970
|
-
* @param {any} options Transaction options
|
|
1971
|
-
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
1972
|
-
* @returns {Promise<any>} Transaction
|
|
1973
|
-
*/
|
|
1974
|
-
async changeFuturesPosition(
|
|
1975
|
-
market: string,
|
|
1976
|
-
changeAmount: BigNumber | string,
|
|
1977
|
-
options: any = null,
|
|
1978
|
-
sdkOptions: SDKOptions = {
|
|
1979
|
-
estimateGas: false
|
|
1980
|
-
}
|
|
1981
|
-
): Promise<any> {
|
|
1982
|
-
const txData = await getFuturesChangePositionTxData(
|
|
1983
|
-
changeAmount,
|
|
1984
|
-
market,
|
|
1985
|
-
this
|
|
1986
|
-
);
|
|
1987
|
-
const tx = await getPoolTxOrGasEstimate(
|
|
1988
|
-
this,
|
|
1989
|
-
[market, txData, options],
|
|
1990
|
-
sdkOptions
|
|
1991
|
-
);
|
|
1992
|
-
return tx;
|
|
1993
|
-
}
|
|
1994
|
-
|
|
1995
|
-
/** Cancels an open oder on Synthetix futures market
|
|
1996
|
-
*
|
|
1997
|
-
* @param {string} market Address of futures market
|
|
1998
|
-
* @param {any} options Transaction options
|
|
1999
|
-
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
2000
|
-
* @returns {Promise<any>} Transaction
|
|
2001
|
-
*/
|
|
2002
|
-
async cancelFuturesOrder(
|
|
2003
|
-
market: string,
|
|
2004
|
-
options: any = null,
|
|
2005
|
-
sdkOptions: SDKOptions = {
|
|
2006
|
-
estimateGas: false
|
|
2007
|
-
}
|
|
2008
|
-
): Promise<any> {
|
|
2009
|
-
const txData = await getFuturesCancelOrderTxData(this);
|
|
2010
|
-
const tx = await getPoolTxOrGasEstimate(
|
|
2011
|
-
this,
|
|
2012
|
-
[market, txData, options],
|
|
2013
|
-
sdkOptions
|
|
2014
|
-
);
|
|
2015
|
-
return tx;
|
|
2016
|
-
}
|
|
2017
|
-
|
|
2018
1864
|
/**
|
|
2019
1865
|
* mintManagerFee
|
|
2020
1866
|
* @param {any} options Transaction options
|
|
@@ -2034,60 +1880,11 @@ export class Pool {
|
|
|
2034
1880
|
* @returns {Promise<BigNumber>} fee
|
|
2035
1881
|
*/
|
|
2036
1882
|
async getAvailableManagerFee(): Promise<BigNumber> {
|
|
2037
|
-
const
|
|
1883
|
+
const fundValue = await this.managerLogic.totalFundValue();
|
|
1884
|
+
const fee = await this.poolLogic.calculateAvailableManagerFee(fundValue);
|
|
2038
1885
|
return BigNumber.from(fee);
|
|
2039
1886
|
}
|
|
2040
1887
|
|
|
2041
|
-
/** Vest tokens (e.g. Ramses xoRAM)
|
|
2042
|
-
*
|
|
2043
|
-
* @param {string} tokenAddress Address of the token to vest
|
|
2044
|
-
* @param {BigNumber | string } changeAmount Negative for short, positive for long
|
|
2045
|
-
* @param {any} options Transaction options
|
|
2046
|
-
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
2047
|
-
* @returns {Promise<any>} Transaction
|
|
2048
|
-
*/
|
|
2049
|
-
async vestTokens(
|
|
2050
|
-
tokenAddress: string,
|
|
2051
|
-
amount: BigNumber | string,
|
|
2052
|
-
options: any = null,
|
|
2053
|
-
sdkOptions: SDKOptions = {
|
|
2054
|
-
estimateGas: false
|
|
2055
|
-
}
|
|
2056
|
-
): Promise<any> {
|
|
2057
|
-
const txData = await getCreateVestTxData(amount);
|
|
2058
|
-
const tx = await getPoolTxOrGasEstimate(
|
|
2059
|
-
this,
|
|
2060
|
-
[tokenAddress, txData, options],
|
|
2061
|
-
sdkOptions
|
|
2062
|
-
);
|
|
2063
|
-
return tx;
|
|
2064
|
-
}
|
|
2065
|
-
|
|
2066
|
-
/** Exit position of vested tokens (e.g. Ramses xoRAM)
|
|
2067
|
-
*
|
|
2068
|
-
* @param {string} tokenAddress Address of the token to vest
|
|
2069
|
-
* @param {number } id position Id of the vested tokens
|
|
2070
|
-
* @param {any} options Transaction options
|
|
2071
|
-
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
2072
|
-
* @returns {Promise<any>} Transaction
|
|
2073
|
-
*/
|
|
2074
|
-
async exitVestedToken(
|
|
2075
|
-
tokenAddress: string,
|
|
2076
|
-
id: number,
|
|
2077
|
-
options: any = null,
|
|
2078
|
-
sdkOptions: SDKOptions = {
|
|
2079
|
-
estimateGas: false
|
|
2080
|
-
}
|
|
2081
|
-
): Promise<any> {
|
|
2082
|
-
const txData = await getExitVestTxData(id);
|
|
2083
|
-
const tx = await getPoolTxOrGasEstimate(
|
|
2084
|
-
this,
|
|
2085
|
-
[tokenAddress, txData, options],
|
|
2086
|
-
sdkOptions
|
|
2087
|
-
);
|
|
2088
|
-
return tx;
|
|
2089
|
-
}
|
|
2090
|
-
|
|
2091
1888
|
/** deposit rETH to mint UNIT via the Flat Money protocol
|
|
2092
1889
|
*
|
|
2093
1890
|
* @param { BigNumber | string } depositAmount Amount of rETH to deposit
|
|
@@ -2146,6 +1943,12 @@ export class Pool {
|
|
|
2146
1943
|
return tx;
|
|
2147
1944
|
}
|
|
2148
1945
|
|
|
1946
|
+
/**
|
|
1947
|
+
* Cancel a previously announced FlatMoney order (mint/redeem UNIT) before it executes
|
|
1948
|
+
* @param {any} options Transaction options
|
|
1949
|
+
* @param {boolean} estimateGas Simulate/estimate gas instead of sending
|
|
1950
|
+
* @returns {Promise<any>} Transaction
|
|
1951
|
+
*/
|
|
2149
1952
|
async cancelOrderViaFlatMoney(
|
|
2150
1953
|
options: any = null,
|
|
2151
1954
|
estimateGas = false
|
package/src/entities/utils.ts
CHANGED
|
@@ -199,6 +199,11 @@ export class Utils {
|
|
|
199
199
|
);
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Build calldata for a Balancer swap. Routes through the Balancer SOR — picks
|
|
204
|
+
* a single `swap` for direct hops or `batchSwap` for multi-hop routes.
|
|
205
|
+
* `slippage` is in % (e.g. 0.5 = 0.5%).
|
|
206
|
+
*/
|
|
202
207
|
async getBalancerSwapTx(
|
|
203
208
|
pool: Pool,
|
|
204
209
|
assetFrom: string,
|
|
@@ -275,6 +280,7 @@ export class Utils {
|
|
|
275
280
|
}
|
|
276
281
|
}
|
|
277
282
|
|
|
283
|
+
/** Build calldata to join a Balancer pool by depositing the given asset amounts. */
|
|
278
284
|
async getBalancerJoinPoolTx(
|
|
279
285
|
pool: Pool,
|
|
280
286
|
balancerPoolId: string,
|
|
@@ -307,6 +313,11 @@ export class Utils {
|
|
|
307
313
|
return joinPoolTx;
|
|
308
314
|
}
|
|
309
315
|
|
|
316
|
+
/**
|
|
317
|
+
* Build calldata to exit a Balancer pool. If `singleExitAssetIndex` is null
|
|
318
|
+
* the exit is proportional across all `assets`; otherwise the BPT is redeemed
|
|
319
|
+
* into the single asset at that index.
|
|
320
|
+
*/
|
|
310
321
|
async getBalancerExitPoolTx(
|
|
311
322
|
pool: Pool,
|
|
312
323
|
balancerPoolId: string,
|
|
@@ -339,10 +350,12 @@ export class Utils {
|
|
|
339
350
|
return exitPoolTx;
|
|
340
351
|
}
|
|
341
352
|
|
|
353
|
+
/** List available expiry timestamps for a Lyra option market. */
|
|
342
354
|
async getLyraOptionExpiries(market: LyraOptionMarket): Promise<number[]> {
|
|
343
355
|
return await getExpiries(this.network, market);
|
|
344
356
|
}
|
|
345
357
|
|
|
358
|
+
/** List available strikes for a Lyra option market at a given expiry. */
|
|
346
359
|
async getLyraOptionStrikes(
|
|
347
360
|
market: LyraOptionMarket,
|
|
348
361
|
expiry: number
|
|
@@ -350,6 +363,7 @@ export class Utils {
|
|
|
350
363
|
return await getStrikes(this.network, market, expiry);
|
|
351
364
|
}
|
|
352
365
|
|
|
366
|
+
/** Resolve a single Lyra strike by its strike price for a market/expiry. */
|
|
353
367
|
async getLyraOptionStrike(
|
|
354
368
|
market: LyraOptionMarket,
|
|
355
369
|
expiry: number,
|
|
@@ -358,6 +372,7 @@ export class Utils {
|
|
|
358
372
|
return await getStrike(this.network, market, expiry, strike);
|
|
359
373
|
}
|
|
360
374
|
|
|
375
|
+
/** Get a Lyra option quote (premium, fees, slippage) for a strike/type/size. */
|
|
361
376
|
async getLyraOptionQuote(
|
|
362
377
|
strike: Strike,
|
|
363
378
|
type: LyraOptionType,
|
|
@@ -24,6 +24,7 @@ import { getPositionSize } from "./positionData";
|
|
|
24
24
|
const depositWallet = new ethers.utils.Interface(ICoreDepositWalletAbi);
|
|
25
25
|
const coreWriter = new ethers.utils.Interface(ICoreWriterAbi);
|
|
26
26
|
|
|
27
|
+
/** Encode `deposit(amount, dexId)` on the Hyperliquid CoreDepositWallet to bridge USDC into HyperCore. */
|
|
27
28
|
export const getDepositHyperliquidTxData = (
|
|
28
29
|
dexId: number,
|
|
29
30
|
amount: ethers.BigNumber | string
|
|
@@ -31,6 +32,11 @@ export const getDepositHyperliquidTxData = (
|
|
|
31
32
|
return depositWallet.encodeFunctionData("deposit", [amount, dexId]);
|
|
32
33
|
};
|
|
33
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Encode a CoreWriter `sendRawAction` for SPOT_SEND that bridges USDC from the
|
|
37
|
+
* HyperCore Spot wallet back to EVM. Amount is supplied in 6 decimals (EVM USDC) and
|
|
38
|
+
* scaled up by 100 for HyperCore's 8-decimal USDC.
|
|
39
|
+
*/
|
|
34
40
|
export const getWithdrawSpotHyperliquidTxData = (
|
|
35
41
|
amount: ethers.BigNumber | string
|
|
36
42
|
): string => {
|
|
@@ -49,6 +55,11 @@ export const getWithdrawSpotHyperliquidTxData = (
|
|
|
49
55
|
);
|
|
50
56
|
return coreWriter.encodeFunctionData("sendRawAction", [rawTXData]);
|
|
51
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* Encode a CoreWriter `sendRawAction` for SEND_ASSET that moves USDC between
|
|
60
|
+
* HyperCore dexes (perp/spot/xyz). Amount is supplied in 6 decimals (EVM USDC) and
|
|
61
|
+
* scaled to HyperCore's 8 decimals.
|
|
62
|
+
*/
|
|
52
63
|
export const getSendAssetHyperliquidTxData = (
|
|
53
64
|
sourceDex: number,
|
|
54
65
|
destinationDex: number,
|
|
@@ -80,6 +91,11 @@ export const getSendAssetHyperliquidTxData = (
|
|
|
80
91
|
return coreWriter.encodeFunctionData("sendRawAction", [rawTXData]);
|
|
81
92
|
};
|
|
82
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Encode a CoreWriter `sendRawAction` for an IOC limit order on a Hyperliquid asset.
|
|
96
|
+
* Auto-flips side and sets `reduceOnly` when `changeAmount` is negative (perp close).
|
|
97
|
+
* Price is offset by `slippage`% from the current mid in the direction of execution.
|
|
98
|
+
*/
|
|
83
99
|
export const getLimitOrderHyperliquidTxData = async (
|
|
84
100
|
assetId: number,
|
|
85
101
|
isLong: boolean,
|
|
@@ -128,6 +144,12 @@ export const getLimitOrderHyperliquidTxData = async (
|
|
|
128
144
|
return coreWriter.encodeFunctionData("sendRawAction", [rawTXData]);
|
|
129
145
|
};
|
|
130
146
|
|
|
147
|
+
/**
|
|
148
|
+
* Encode a CoreWriter `sendRawAction` for an IOC limit order that closes
|
|
149
|
+
* `percentageToClose`% of the pool's current Hyperliquid position. Reads the
|
|
150
|
+
* existing position size on-chain to determine the side (buy to close shorts,
|
|
151
|
+
* sell to close longs).
|
|
152
|
+
*/
|
|
131
153
|
export const getClosePositionHyperliquidTxData = async (
|
|
132
154
|
assetId: number,
|
|
133
155
|
percentageToClose: number,
|
|
@@ -9,7 +9,9 @@ export async function getKyberSwapTxData(
|
|
|
9
9
|
tokenIn: string,
|
|
10
10
|
tokenOut: string,
|
|
11
11
|
amountIn: ethers.BigNumber | string,
|
|
12
|
-
slippage: number
|
|
12
|
+
slippage: number,
|
|
13
|
+
sender?: string,
|
|
14
|
+
receiver?: string
|
|
13
15
|
): Promise<{ swapTxData: string; minAmountOut: string }> {
|
|
14
16
|
const params = {
|
|
15
17
|
tokenIn,
|
|
@@ -29,8 +31,8 @@ export async function getKyberSwapTxData(
|
|
|
29
31
|
|
|
30
32
|
const buildParams = {
|
|
31
33
|
routeSummary: quoteResult.data.data.routeSummary,
|
|
32
|
-
sender: pool.address,
|
|
33
|
-
recipient: pool.address,
|
|
34
|
+
sender: sender || pool.address,
|
|
35
|
+
recipient: receiver || pool.address,
|
|
34
36
|
slippageTolerance: slippage * 100 // in basis points
|
|
35
37
|
};
|
|
36
38
|
|