@dhedge/v2-sdk 2.1.8 → 2.2.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 +400 -53
- 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/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 +19 -4
- package/dist/utils/contract.d.ts +20 -0
- package/dist/v2-sdk.cjs.development.js +4996 -6742
- 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 +5001 -6742
- 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/config.ts +13 -8
- package/src/entities/pool.ts +46 -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/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/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 +20 -5
- 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,
|
|
@@ -164,7 +153,7 @@ export class Pool {
|
|
|
164
153
|
|
|
165
154
|
/**
|
|
166
155
|
* Approve the asset that can be deposited into a pool
|
|
167
|
-
* @param {string}
|
|
156
|
+
* @param {string} asset Address of deposit asset
|
|
168
157
|
* @param {BigNumber | string} amount Amount to be approved
|
|
169
158
|
* @param {any} options Transaction options
|
|
170
159
|
* @param {boolean} estimateGas Simulate/estimate gas
|
|
@@ -264,7 +253,7 @@ export class Pool {
|
|
|
264
253
|
* Approve the liquidity pool token for staking
|
|
265
254
|
* @param {Dapp} dapp Platform like Sushiswap or Uniswap
|
|
266
255
|
* @param {string} asset Address of liquidity pool token
|
|
267
|
-
* @param {BigNumber | string} amount
|
|
256
|
+
* @param {BigNumber | string} amount Amount to be approved
|
|
268
257
|
* @param {any} options Transaction options
|
|
269
258
|
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
270
259
|
* @returns {Promise<any>} Transaction
|
|
@@ -292,10 +281,10 @@ export class Pool {
|
|
|
292
281
|
}
|
|
293
282
|
|
|
294
283
|
/**
|
|
295
|
-
* Approve
|
|
296
|
-
*
|
|
297
|
-
* @param {string} asset Address of
|
|
298
|
-
* @param {BigNumber | string} amount
|
|
284
|
+
* Approve an asset for the Uniswap V3 NonfungiblePositionManager
|
|
285
|
+
* (used before mint/increase liquidity calls)
|
|
286
|
+
* @param {string} asset Address of asset to approve
|
|
287
|
+
* @param {BigNumber | string} amount Amount to be approved
|
|
299
288
|
* @param {any} options Transaction options
|
|
300
289
|
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
301
290
|
* @returns {Promise<any>} Transaction
|
|
@@ -426,20 +415,6 @@ export class Pool {
|
|
|
426
415
|
slippage
|
|
427
416
|
);
|
|
428
417
|
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
418
|
case Dapp.TOROS:
|
|
444
419
|
swapTxData = await getEasySwapperTxData(
|
|
445
420
|
this,
|
|
@@ -696,7 +671,6 @@ export class Pool {
|
|
|
696
671
|
]);
|
|
697
672
|
break;
|
|
698
673
|
case Dapp.VELODROME:
|
|
699
|
-
case Dapp.RAMSES:
|
|
700
674
|
stakeTxData = getVelodromeStakeTxData(amount, false);
|
|
701
675
|
break;
|
|
702
676
|
case Dapp.VELODROMEV2:
|
|
@@ -862,7 +836,7 @@ export class Pool {
|
|
|
862
836
|
}
|
|
863
837
|
|
|
864
838
|
/**
|
|
865
|
-
*
|
|
839
|
+
* Withdraw asset from a lending pool
|
|
866
840
|
* @param {Dapp} dapp Platform like Aave
|
|
867
841
|
* @param {string} asset Asset
|
|
868
842
|
* @param {BigNumber | string} amount Amount of asset to lend
|
|
@@ -894,7 +868,7 @@ export class Pool {
|
|
|
894
868
|
}
|
|
895
869
|
|
|
896
870
|
/**
|
|
897
|
-
*
|
|
871
|
+
* Withdraw asset from a Compound V3 or Fluid lending pool
|
|
898
872
|
* @param {string} market Address of cToken or fToken
|
|
899
873
|
* @param {string} asset Asset
|
|
900
874
|
* @param {BigNumber | string} amount Amount of asset to withdraw
|
|
@@ -1042,9 +1016,25 @@ export class Pool {
|
|
|
1042
1016
|
e.asset.toLocaleLowerCase()
|
|
1043
1017
|
);
|
|
1044
1018
|
const newAssets = assets.map(e => e.asset.toLocaleLowerCase());
|
|
1045
|
-
const
|
|
1019
|
+
const candidateRemovals = currentAssets.filter(e => !newAssets.includes(e));
|
|
1046
1020
|
const changedAssets = assets.map(e => [e.asset, e.isDeposit]);
|
|
1047
1021
|
|
|
1022
|
+
// Simulate each removal to filter out assets that can't be removed
|
|
1023
|
+
// (non-zero balance, guard dependency, active order, etc.)
|
|
1024
|
+
const removedAssets: string[] = [];
|
|
1025
|
+
for (const asset of candidateRemovals) {
|
|
1026
|
+
try {
|
|
1027
|
+
await this.managerLogic.callStatic.changeAssets([], [asset]);
|
|
1028
|
+
removedAssets.push(asset);
|
|
1029
|
+
} catch (err) {
|
|
1030
|
+
console.warn(
|
|
1031
|
+
`changeAssets: skipping removal of ${asset} — ${
|
|
1032
|
+
(err as Error).message
|
|
1033
|
+
}`
|
|
1034
|
+
);
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1048
1038
|
if (estimateGas) {
|
|
1049
1039
|
return await this.managerLogic.estimateGas.changeAssets(
|
|
1050
1040
|
changedAssets,
|
|
@@ -1159,11 +1149,11 @@ export class Pool {
|
|
|
1159
1149
|
}
|
|
1160
1150
|
|
|
1161
1151
|
/**
|
|
1162
|
-
*
|
|
1152
|
+
* Exit a Balancer pool
|
|
1163
1153
|
* @param {string} poolId Balancer pool id
|
|
1164
|
-
* @param {string[]
|
|
1165
|
-
* @param {BigNumber | string
|
|
1166
|
-
* @param {
|
|
1154
|
+
* @param {string[]} assets Array of balancer pool assets
|
|
1155
|
+
* @param {BigNumber | string} amount Amount of pool tokens to withdraw
|
|
1156
|
+
* @param {null | number} singleExitAssetIndex Index of asset to withdraw to
|
|
1167
1157
|
* @param {any} options Transaction options
|
|
1168
1158
|
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
1169
1159
|
* @returns {Promise<any>} Transaction
|
|
@@ -1306,12 +1296,7 @@ export class Pool {
|
|
|
1306
1296
|
* @returns {Promise<any>} Transaction
|
|
1307
1297
|
*/
|
|
1308
1298
|
async addLiquidityUniswapV3(
|
|
1309
|
-
dapp:
|
|
1310
|
-
| Dapp.UNISWAPV3
|
|
1311
|
-
| Dapp.VELODROMECL
|
|
1312
|
-
| Dapp.AERODROMECL
|
|
1313
|
-
| Dapp.RAMSESCL
|
|
1314
|
-
| Dapp.PANCAKECL,
|
|
1299
|
+
dapp: Dapp.UNISWAPV3 | Dapp.VELODROMECL | Dapp.AERODROMECL | Dapp.PANCAKECL,
|
|
1315
1300
|
assetA: string,
|
|
1316
1301
|
assetB: string,
|
|
1317
1302
|
amountA: BigNumber | string,
|
|
@@ -1383,7 +1368,6 @@ export class Pool {
|
|
|
1383
1368
|
let txData;
|
|
1384
1369
|
switch (dapp) {
|
|
1385
1370
|
case Dapp.UNISWAPV3:
|
|
1386
|
-
case Dapp.RAMSESCL:
|
|
1387
1371
|
dappAddress = nonfungiblePositionManagerAddress[this.network][dapp];
|
|
1388
1372
|
break;
|
|
1389
1373
|
case Dapp.VELODROMECL:
|
|
@@ -1450,7 +1434,6 @@ export class Pool {
|
|
|
1450
1434
|
let txData;
|
|
1451
1435
|
switch (dapp) {
|
|
1452
1436
|
case Dapp.UNISWAPV3:
|
|
1453
|
-
case Dapp.RAMSESCL:
|
|
1454
1437
|
dappAddress = nonfungiblePositionManagerAddress[this.network][dapp];
|
|
1455
1438
|
break;
|
|
1456
1439
|
case Dapp.VELODROMECL:
|
|
@@ -1516,7 +1499,6 @@ export class Pool {
|
|
|
1516
1499
|
);
|
|
1517
1500
|
switch (dapp) {
|
|
1518
1501
|
case Dapp.UNISWAPV3:
|
|
1519
|
-
case Dapp.RAMSESCL:
|
|
1520
1502
|
contractAddress = nonfungiblePositionManagerAddress[this.network][dapp];
|
|
1521
1503
|
txData = iNonfungiblePositionManager.encodeFunctionData(
|
|
1522
1504
|
Transaction.COLLECT,
|
|
@@ -1530,7 +1512,6 @@ export class Pool {
|
|
|
1530
1512
|
txData = abi.encodeFunctionData("claim_rewards()", []);
|
|
1531
1513
|
break;
|
|
1532
1514
|
case Dapp.VELODROME:
|
|
1533
|
-
case Dapp.RAMSES:
|
|
1534
1515
|
contractAddress = tokenId;
|
|
1535
1516
|
txData = getVelodromeClaimTxData(this, tokenId, false);
|
|
1536
1517
|
break;
|
|
@@ -1571,75 +1552,6 @@ export class Pool {
|
|
|
1571
1552
|
return tx;
|
|
1572
1553
|
}
|
|
1573
1554
|
|
|
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
1555
|
/**
|
|
1644
1556
|
* Add liquidity to Velodrome pool
|
|
1645
1557
|
* @param {string} assetA First asset
|
|
@@ -1799,8 +1711,8 @@ export class Pool {
|
|
|
1799
1711
|
}
|
|
1800
1712
|
|
|
1801
1713
|
/**
|
|
1802
|
-
* Add liquidity to Velodrome V2 or
|
|
1803
|
-
* @param {Dapp} dapp VelodromeV2
|
|
1714
|
+
* Add liquidity to Velodrome V2 or Aerodrome pool
|
|
1715
|
+
* @param {Dapp} dapp VelodromeV2 or Aerodrome
|
|
1804
1716
|
* @param {string} assetA First asset
|
|
1805
1717
|
* @param {string} assetB Second asset
|
|
1806
1718
|
* @param {BigNumber | string} amountA Amount first asset
|
|
@@ -1811,7 +1723,7 @@ export class Pool {
|
|
|
1811
1723
|
* @returns {Promise<any>} Transaction
|
|
1812
1724
|
*/
|
|
1813
1725
|
async addLiquidityV2(
|
|
1814
|
-
dapp: Dapp.VELODROMEV2 | Dapp.
|
|
1726
|
+
dapp: Dapp.VELODROMEV2 | Dapp.AERODROME,
|
|
1815
1727
|
assetA: string,
|
|
1816
1728
|
assetB: string,
|
|
1817
1729
|
amountA: BigNumber | string,
|
|
@@ -1842,8 +1754,8 @@ export class Pool {
|
|
|
1842
1754
|
}
|
|
1843
1755
|
|
|
1844
1756
|
/**
|
|
1845
|
-
* Remove liquidity from Velodrome V2 or
|
|
1846
|
-
* @param {Dapp} dapp VelodromeV2
|
|
1757
|
+
* Remove liquidity from Velodrome V2 or Aerodrome pool
|
|
1758
|
+
* @param {Dapp} dapp VelodromeV2 or Aerodrome
|
|
1847
1759
|
* @param {string} assetA First asset
|
|
1848
1760
|
* @param {string} assetB Second asset
|
|
1849
1761
|
* @param {BigNumber | string} amount Amount of LP tokens
|
|
@@ -1853,7 +1765,7 @@ export class Pool {
|
|
|
1853
1765
|
* @returns {Promise<any>} Transaction
|
|
1854
1766
|
*/
|
|
1855
1767
|
async removeLiquidityV2(
|
|
1856
|
-
dapp: Dapp.VELODROMEV2 | Dapp.
|
|
1768
|
+
dapp: Dapp.VELODROMEV2 | Dapp.AERODROME,
|
|
1857
1769
|
assetA: string,
|
|
1858
1770
|
assetB: string,
|
|
1859
1771
|
amount: BigNumber | string,
|
|
@@ -1939,82 +1851,6 @@ export class Pool {
|
|
|
1939
1851
|
return await getOptionPositions(this, market);
|
|
1940
1852
|
}
|
|
1941
1853
|
|
|
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
1854
|
/**
|
|
2019
1855
|
* mintManagerFee
|
|
2020
1856
|
* @param {any} options Transaction options
|
|
@@ -2034,60 +1870,11 @@ export class Pool {
|
|
|
2034
1870
|
* @returns {Promise<BigNumber>} fee
|
|
2035
1871
|
*/
|
|
2036
1872
|
async getAvailableManagerFee(): Promise<BigNumber> {
|
|
2037
|
-
const
|
|
1873
|
+
const fundValue = await this.managerLogic.totalFundValue();
|
|
1874
|
+
const fee = await this.poolLogic.calculateAvailableManagerFee(fundValue);
|
|
2038
1875
|
return BigNumber.from(fee);
|
|
2039
1876
|
}
|
|
2040
1877
|
|
|
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
1878
|
/** deposit rETH to mint UNIT via the Flat Money protocol
|
|
2092
1879
|
*
|
|
2093
1880
|
* @param { BigNumber | string } depositAmount Amount of rETH to deposit
|
|
@@ -2146,6 +1933,12 @@ export class Pool {
|
|
|
2146
1933
|
return tx;
|
|
2147
1934
|
}
|
|
2148
1935
|
|
|
1936
|
+
/**
|
|
1937
|
+
* Cancel a previously announced FlatMoney order (mint/redeem UNIT) before it executes
|
|
1938
|
+
* @param {any} options Transaction options
|
|
1939
|
+
* @param {boolean} estimateGas Simulate/estimate gas instead of sending
|
|
1940
|
+
* @returns {Promise<any>} Transaction
|
|
1941
|
+
*/
|
|
2149
1942
|
async cancelOrderViaFlatMoney(
|
|
2150
1943
|
options: any = null,
|
|
2151
1944
|
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
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import axios from "axios";
|
|
3
3
|
import { ApiError, ethers } from "../..";
|
|
4
|
-
import { networkChainIdMap
|
|
4
|
+
import { networkChainIdMap } from "../../config";
|
|
5
5
|
import { Pool } from "../../entities";
|
|
6
6
|
|
|
7
7
|
const oneInchBaseUrl = "https://api.1inch.dev/swap/v6.0/";
|
|
@@ -12,7 +12,8 @@ export async function getOneInchSwapTxData(
|
|
|
12
12
|
assetTo: string,
|
|
13
13
|
amountIn: ethers.BigNumber | string,
|
|
14
14
|
slippage: number,
|
|
15
|
-
|
|
15
|
+
sender?: string,
|
|
16
|
+
receiver?: string
|
|
16
17
|
): Promise<{ swapTxData: string; dstAmount: string }> {
|
|
17
18
|
if (!process.env.ONEINCH_API_KEY)
|
|
18
19
|
throw new Error("ONEINCH_API_KEY not configured in .env file");
|
|
@@ -23,8 +24,8 @@ export async function getOneInchSwapTxData(
|
|
|
23
24
|
src: assetFrom,
|
|
24
25
|
dst: assetTo,
|
|
25
26
|
amount: amountIn.toString(),
|
|
26
|
-
from:
|
|
27
|
-
receiver:
|
|
27
|
+
from: sender || pool.address,
|
|
28
|
+
receiver: receiver || pool.address,
|
|
28
29
|
slippage: slippage,
|
|
29
30
|
disableEstimate: true,
|
|
30
31
|
usePermit2: false
|