@dhedge/v2-sdk 2.1.7 → 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.
Files changed (93) hide show
  1. package/README.md +400 -53
  2. package/dist/config.d.ts +14 -2
  3. package/dist/entities/pool.d.ts +25 -86
  4. package/dist/entities/utils.d.ts +15 -0
  5. package/dist/services/cowSwap/index.d.ts +10 -0
  6. package/dist/services/hyperliquid/index.d.ts +22 -0
  7. package/dist/services/kyberSwap/index.d.ts +1 -1
  8. package/dist/services/oneInch/index.d.ts +1 -1
  9. package/dist/services/toros/easySwapper.d.ts +14 -0
  10. package/dist/services/toros/swapData.d.ts +5 -5
  11. package/dist/services/uniswap/V3Liquidity.d.ts +2 -2
  12. package/dist/services/velodrome/liquidity.d.ts +3 -0
  13. package/dist/test/constants.d.ts +48 -3
  14. package/dist/test/utils/testingHelper.d.ts +4 -0
  15. package/dist/types.d.ts +21 -5
  16. package/dist/utils/contract.d.ts +20 -0
  17. package/dist/v2-sdk.cjs.development.js +5193 -6711
  18. package/dist/v2-sdk.cjs.development.js.map +1 -1
  19. package/dist/v2-sdk.cjs.production.min.js +1 -1
  20. package/dist/v2-sdk.cjs.production.min.js.map +1 -1
  21. package/dist/v2-sdk.esm.js +5198 -6711
  22. package/dist/v2-sdk.esm.js.map +1 -1
  23. package/package.json +1 -1
  24. package/src/abi/PoolFactory.json +414 -204
  25. package/src/abi/PoolLogic.json +160 -134
  26. package/src/config.ts +19 -9
  27. package/src/entities/pool.ts +103 -254
  28. package/src/entities/utils.ts +15 -0
  29. package/src/services/cowSwap/index.ts +281 -0
  30. package/src/services/hyperliquid/index.ts +22 -0
  31. package/src/services/kyberSwap/index.ts +5 -3
  32. package/src/services/oneInch/index.ts +5 -4
  33. package/src/services/toros/completeWithdrawal.ts +57 -40
  34. package/src/services/toros/easySwapper.ts +15 -1
  35. package/src/services/toros/initWithdrawal.ts +39 -31
  36. package/src/services/toros/swapData.ts +45 -131
  37. package/src/services/uniswap/V3Liquidity.ts +3 -24
  38. package/src/services/velodrome/liquidity.ts +3 -0
  39. package/src/test/aave.test.ts +99 -70
  40. package/src/test/aerodrome.test.ts +53 -24
  41. package/src/test/aerodromeCL.test.ts +64 -30
  42. package/src/test/arrakis.test.ts +23 -35
  43. package/src/test/balancer.test.ts +114 -106
  44. package/src/test/compoundV3.test.ts +45 -29
  45. package/src/test/constants.ts +57 -12
  46. package/src/test/cowswap.test.ts +79 -0
  47. package/src/test/dhedge.test.ts +45 -12
  48. package/src/test/flatmoney.test.ts +25 -39
  49. package/src/test/fluid.test.ts +33 -24
  50. package/src/test/hyperliquid.onchain.test.ts +131 -0
  51. package/src/test/kyberSwap.test.ts +37 -16
  52. package/src/test/lyra.test.ts +159 -150
  53. package/src/test/odos.test.ts +2 -2
  54. package/src/test/oneInch.test.ts +36 -22
  55. package/src/test/pancakeCL.test.ts +72 -31
  56. package/src/test/pendle.test.ts +94 -54
  57. package/src/test/{pendleMint.test.ts → pendleMint.onchain.test.ts} +22 -8
  58. package/src/test/pool.test.ts +152 -95
  59. package/src/test/toros.onchain.test.ts +92 -0
  60. package/src/test/toros.test.ts +74 -20
  61. package/src/test/torosLimitOrder.test.ts +87 -42
  62. package/src/test/uniswap.test.ts +77 -128
  63. package/src/test/utils/testingHelper.ts +120 -0
  64. package/src/test/velodrome.test.ts +126 -92
  65. package/src/test/velodromeCL.test.ts +43 -31
  66. package/src/test/velodromeV2.test.ts +153 -95
  67. package/src/types.ts +22 -6
  68. package/src/utils/contract.ts +20 -0
  69. package/dist/services/futures/constants.d.ts +0 -1
  70. package/dist/services/futures/index.d.ts +0 -2
  71. package/dist/services/futures/margin.d.ts +0 -2
  72. package/dist/services/futures/trade.d.ts +0 -3
  73. package/dist/services/ramses/vesting.d.ts +0 -4
  74. package/dist/services/uniswap/V3Trade.d.ts +0 -3
  75. package/dist/test/utils/futures.d.ts +0 -2
  76. package/src/abi/IRamsesNonfungiblePositionManager.json +0 -486
  77. package/src/abi/ISynthetiXFuturesMarketV2.json +0 -531
  78. package/src/abi/ISynthetix.json +0 -139
  79. package/src/abi/IUniswapV3Quoter.json +0 -195
  80. package/src/abi/IUniswapV3Router.json +0 -221
  81. package/src/abi/IXRam.json +0 -99
  82. package/src/services/futures/constants.ts +0 -1
  83. package/src/services/futures/index.ts +0 -2
  84. package/src/services/futures/margin.ts +0 -10
  85. package/src/services/futures/trade.ts +0 -32
  86. package/src/services/ramses/vesting.ts +0 -24
  87. package/src/services/uniswap/V3Trade.ts +0 -46
  88. package/src/test/futures.test.ts +0 -51
  89. package/src/test/hyperliquid.test.ts +0 -107
  90. package/src/test/ramses.test.ts +0 -190
  91. package/src/test/ramsesCL.test.ts +0 -155
  92. package/src/test/synthetix.test.ts +0 -36
  93. package/src/test/utils/futures.ts +0 -14
@@ -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
- import ISynthetix from "../abi/ISynthetix.json";
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";
@@ -18,8 +18,8 @@ import {
18
18
  MaxUint128,
19
19
  nonfungiblePositionManagerAddress,
20
20
  routerAddress,
21
+ gpv2SettlementAddress,
21
22
  stakingAddress,
22
- SYNTHETIX_TRACKING_CODE,
23
23
  limitOrderAddress
24
24
  } from "../config";
25
25
  import {
@@ -42,7 +42,7 @@ import {
42
42
  getIncreaseLiquidityTxData,
43
43
  getUniswapV3MintTxData
44
44
  } from "../services/uniswap/V3Liquidity";
45
- import { getUniswapV3SwapTxData } from "../services/uniswap/V3Trade";
45
+
46
46
  import { getEasySwapperTxData } from "../services/toros/easySwapper";
47
47
  import { getAaveV3ClaimTxData } from "../services/aave/incentives";
48
48
  import {
@@ -58,18 +58,8 @@ import {
58
58
  import { getLyraOptionTxData } from "../services/lyra/trade";
59
59
  import { getOptionPositions } from "../services/lyra/positions";
60
60
  import { getDeadline } from "../utils/deadline";
61
- import {
62
- getFuturesChangeMarginTxData,
63
- getFuturesChangePositionTxData
64
- } from "../services/futures";
65
- import { getFuturesCancelOrderTxData } from "../services/futures/trade";
66
61
  import { getOneInchSwapTxData } from "../services/oneInch";
67
- import {
68
- getCreateVestTxData,
69
- getExitVestTxData,
70
- getRewardsTxDta
71
- } from "../services/ramses/vesting";
72
- import { getPoolTxOrGasEstimate } from "../utils/contract";
62
+ import { getPoolTxOrGasEstimate, isSdkOptionsBoolean } from "../utils/contract";
73
63
  import {
74
64
  cancelOrderViaFlatMoney,
75
65
  mintUnitViaFlatMoney,
@@ -96,6 +86,7 @@ import {
96
86
  hasActiveTorosLimitOrder
97
87
  } from "../services/toros/limitOrder";
98
88
  import { getKyberSwapTxData } from "../services/kyberSwap";
89
+ import { getCowSwapTxData } from "../services/cowSwap";
99
90
  import {
100
91
  getClosePositionHyperliquidTxData,
101
92
  getDepositHyperliquidTxData,
@@ -162,7 +153,7 @@ export class Pool {
162
153
 
163
154
  /**
164
155
  * Approve the asset that can be deposited into a pool
165
- * @param {string} nasset Address of deposit asset
156
+ * @param {string} asset Address of deposit asset
166
157
  * @param {BigNumber | string} amount Amount to be approved
167
158
  * @param {any} options Transaction options
168
159
  * @param {boolean} estimateGas Simulate/estimate gas
@@ -262,7 +253,7 @@ export class Pool {
262
253
  * Approve the liquidity pool token for staking
263
254
  * @param {Dapp} dapp Platform like Sushiswap or Uniswap
264
255
  * @param {string} asset Address of liquidity pool token
265
- * @param {BigNumber | string} amount Aamount to be approved
256
+ * @param {BigNumber | string} amount Amount to be approved
266
257
  * @param {any} options Transaction options
267
258
  * @param {SDKOptions} sdkOptions SDK options including estimateGas
268
259
  * @returns {Promise<any>} Transaction
@@ -290,10 +281,10 @@ export class Pool {
290
281
  }
291
282
 
292
283
  /**
293
- * Approve the liquidity pool token for staking
294
- * @param {Dapp} dapp Platform like Sushiswap or Uniswap
295
- * @param {string} asset Address of liquidity pool token
296
- * @param {BigNumber | string} amount Aamount to be approved
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
297
288
  * @param {any} options Transaction options
298
289
  * @param {SDKOptions} sdkOptions SDK options including estimateGas
299
290
  * @returns {Promise<any>} Transaction
@@ -424,20 +415,6 @@ export class Pool {
424
415
  slippage
425
416
  );
426
417
  break;
427
- case Dapp.SYNTHETIX:
428
- const iSynthetix = new ethers.utils.Interface(ISynthetix.abi);
429
- const assets = [assetFrom, assetTo].map(asset =>
430
- ethers.utils.formatBytes32String(asset)
431
- );
432
- const daoAddress = await this.factory.owner();
433
- swapTxData = iSynthetix.encodeFunctionData(Transaction.SWAP_SYNTHS, [
434
- assets[0],
435
- amountIn,
436
- assets[1],
437
- daoAddress,
438
- SYNTHETIX_TRACKING_CODE
439
- ]);
440
- break;
441
418
  case Dapp.TOROS:
442
419
  swapTxData = await getEasySwapperTxData(
443
420
  this,
@@ -474,6 +451,60 @@ export class Pool {
474
451
  slippage
475
452
  ));
476
453
  break;
454
+ case Dapp.COWSWAP: {
455
+ const cowSwapEstimateGas = isSdkOptionsBoolean(sdkOptions)
456
+ ? sdkOptions
457
+ : sdkOptions.estimateGas;
458
+ if (
459
+ cowSwapEstimateGas ||
460
+ (!isSdkOptionsBoolean(sdkOptions) && sdkOptions.onlyGetTxData)
461
+ ) {
462
+ throw new Error(
463
+ "CowSwap requires two sequential transactions (submit + preSign) and does not support estimateGas or onlyGetTxData"
464
+ );
465
+ }
466
+ const {
467
+ encodedTypedData,
468
+ preSignTxData,
469
+ minAmountOut: cowMinOut
470
+ } = await getCowSwapTxData(
471
+ this,
472
+ assetFrom,
473
+ assetTo,
474
+ amountIn,
475
+ slippage
476
+ );
477
+ // Tx 1: manager calls submit() directly on TypedStructuredDataValidator (not via pool.execTransaction)
478
+ const validatorContract = new Contract(
479
+ routerAddress[this.network][dapp] as string,
480
+ [
481
+ "function submit(address _poolLogic, uint8 _dataType, bytes memory _structuredData) external"
482
+ ],
483
+ this.signer
484
+ );
485
+ const submitTx = await validatorContract.submit(
486
+ this.address,
487
+ 1 /* COWSWAP_ORDER */,
488
+ encodedTypedData,
489
+ ...(options ? [options] : [])
490
+ );
491
+ const submitReceipt = await submitTx.wait(3);
492
+ if (submitReceipt.status === 0) {
493
+ return submitReceipt;
494
+ }
495
+
496
+ // Tx 2: pool.execTransaction → setPreSignature() on GPv2Settlement — guard checks stored digest, solvers execute
497
+ return getPoolTxOrGasEstimate(
498
+ this,
499
+ [
500
+ gpv2SettlementAddress[this.network],
501
+ preSignTxData,
502
+ options,
503
+ cowMinOut
504
+ ],
505
+ sdkOptions
506
+ );
507
+ }
477
508
  default:
478
509
  const iUniswapV2Router = new ethers.utils.Interface(
479
510
  IUniswapV2Router.abi
@@ -640,7 +671,6 @@ export class Pool {
640
671
  ]);
641
672
  break;
642
673
  case Dapp.VELODROME:
643
- case Dapp.RAMSES:
644
674
  stakeTxData = getVelodromeStakeTxData(amount, false);
645
675
  break;
646
676
  case Dapp.VELODROMEV2:
@@ -806,7 +836,7 @@ export class Pool {
806
836
  }
807
837
 
808
838
  /**
809
- * Witdraw asset from a lending pool
839
+ * Withdraw asset from a lending pool
810
840
  * @param {Dapp} dapp Platform like Aave
811
841
  * @param {string} asset Asset
812
842
  * @param {BigNumber | string} amount Amount of asset to lend
@@ -838,7 +868,7 @@ export class Pool {
838
868
  }
839
869
 
840
870
  /**
841
- * Witdraw asset from a Compound V3 or Fluid lending pool
871
+ * Withdraw asset from a Compound V3 or Fluid lending pool
842
872
  * @param {string} market Address of cToken or fToken
843
873
  * @param {string} asset Asset
844
874
  * @param {BigNumber | string} amount Amount of asset to withdraw
@@ -986,9 +1016,25 @@ export class Pool {
986
1016
  e.asset.toLocaleLowerCase()
987
1017
  );
988
1018
  const newAssets = assets.map(e => e.asset.toLocaleLowerCase());
989
- const removedAssets = currentAssets.filter(e => !newAssets.includes(e));
1019
+ const candidateRemovals = currentAssets.filter(e => !newAssets.includes(e));
990
1020
  const changedAssets = assets.map(e => [e.asset, e.isDeposit]);
991
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
+
992
1038
  if (estimateGas) {
993
1039
  return await this.managerLogic.estimateGas.changeAssets(
994
1040
  changedAssets,
@@ -1103,11 +1149,11 @@ export class Pool {
1103
1149
  }
1104
1150
 
1105
1151
  /**
1106
- * Invest into a Balancer pool
1152
+ * Exit a Balancer pool
1107
1153
  * @param {string} poolId Balancer pool id
1108
- * @param {string[] | } assets Array of balancer pool assets
1109
- * @param {BigNumber | string } amount Amount of pool tokens to withdraw
1110
- * @param { null | number } singleExitAssetIndex Index of asset to withdraw to
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
1111
1157
  * @param {any} options Transaction options
1112
1158
  * @param {SDKOptions} sdkOptions SDK options including estimateGas
1113
1159
  * @returns {Promise<any>} Transaction
@@ -1250,12 +1296,7 @@ export class Pool {
1250
1296
  * @returns {Promise<any>} Transaction
1251
1297
  */
1252
1298
  async addLiquidityUniswapV3(
1253
- dapp:
1254
- | Dapp.UNISWAPV3
1255
- | Dapp.VELODROMECL
1256
- | Dapp.AERODROMECL
1257
- | Dapp.RAMSESCL
1258
- | Dapp.PANCAKECL,
1299
+ dapp: Dapp.UNISWAPV3 | Dapp.VELODROMECL | Dapp.AERODROMECL | Dapp.PANCAKECL,
1259
1300
  assetA: string,
1260
1301
  assetB: string,
1261
1302
  amountA: BigNumber | string,
@@ -1327,7 +1368,6 @@ export class Pool {
1327
1368
  let txData;
1328
1369
  switch (dapp) {
1329
1370
  case Dapp.UNISWAPV3:
1330
- case Dapp.RAMSESCL:
1331
1371
  dappAddress = nonfungiblePositionManagerAddress[this.network][dapp];
1332
1372
  break;
1333
1373
  case Dapp.VELODROMECL:
@@ -1394,7 +1434,6 @@ export class Pool {
1394
1434
  let txData;
1395
1435
  switch (dapp) {
1396
1436
  case Dapp.UNISWAPV3:
1397
- case Dapp.RAMSESCL:
1398
1437
  dappAddress = nonfungiblePositionManagerAddress[this.network][dapp];
1399
1438
  break;
1400
1439
  case Dapp.VELODROMECL:
@@ -1460,7 +1499,6 @@ export class Pool {
1460
1499
  );
1461
1500
  switch (dapp) {
1462
1501
  case Dapp.UNISWAPV3:
1463
- case Dapp.RAMSESCL:
1464
1502
  contractAddress = nonfungiblePositionManagerAddress[this.network][dapp];
1465
1503
  txData = iNonfungiblePositionManager.encodeFunctionData(
1466
1504
  Transaction.COLLECT,
@@ -1474,7 +1512,6 @@ export class Pool {
1474
1512
  txData = abi.encodeFunctionData("claim_rewards()", []);
1475
1513
  break;
1476
1514
  case Dapp.VELODROME:
1477
- case Dapp.RAMSES:
1478
1515
  contractAddress = tokenId;
1479
1516
  txData = getVelodromeClaimTxData(this, tokenId, false);
1480
1517
  break;
@@ -1515,75 +1552,6 @@ export class Pool {
1515
1552
  return tx;
1516
1553
  }
1517
1554
 
1518
- /**
1519
- * Get rewards of an NFT position
1520
- * @param {Dapp} dapp Platform e.g. Ramses CL
1521
- * @param {string} tokenId Token Id
1522
- * @param {string[]} rewards Reward tokens
1523
- * @param {any} options Transaction option
1524
- * @param {SDKOptions} sdkOptions SDK options including estimateGas
1525
- * @returns {Promise<any>} Transaction
1526
- */
1527
- async getRewards(
1528
- dapp: Dapp,
1529
- tokenId: string,
1530
- rewards: string[],
1531
- options: any = null,
1532
- sdkOptions: SDKOptions = {
1533
- estimateGas: false
1534
- }
1535
- ): Promise<any> {
1536
- const tx = await getPoolTxOrGasEstimate(
1537
- this,
1538
- [
1539
- nonfungiblePositionManagerAddress[this.network][dapp],
1540
- getRewardsTxDta(tokenId, rewards),
1541
- options
1542
- ],
1543
- sdkOptions
1544
- );
1545
- return tx;
1546
- }
1547
-
1548
- /**
1549
- * Trade an asset into another asset
1550
- * @param {Dapp} dapp Platform like Sushiswap or Uniswap
1551
- * @param {string} assetFrom Asset to trade from
1552
- * @param {string} assetTo Asset to trade into
1553
- * @param {BigNumber | string} amountIn Amount
1554
- * @param { FeeAmount } feeAmount Fee tier (Low 0.05%, Medium 0.3%, High 1%)
1555
- * @param {number} slippage Slippage tolerance in %
1556
- * @param {any} options Transaction options
1557
- * @param {SDKOptions} sdkOptions SDK options including estimateGas
1558
- * @returns {Promise<any>} Transaction
1559
- */
1560
- async tradeUniswapV3(
1561
- assetFrom: string,
1562
- assetTo: string,
1563
- amountIn: BigNumber | string,
1564
- feeAmount: number,
1565
- slippage = 0.5,
1566
- options: any = null,
1567
- sdkOptions: SDKOptions = {
1568
- estimateGas: false
1569
- }
1570
- ): Promise<any> {
1571
- const swapxData = await getUniswapV3SwapTxData(
1572
- this,
1573
- assetFrom,
1574
- assetTo,
1575
- amountIn,
1576
- slippage,
1577
- feeAmount
1578
- );
1579
- const tx = await getPoolTxOrGasEstimate(
1580
- this,
1581
- [routerAddress[this.network][Dapp.UNISWAPV3], swapxData, options],
1582
- sdkOptions
1583
- );
1584
- return tx;
1585
- }
1586
-
1587
1555
  /**
1588
1556
  * Add liquidity to Velodrome pool
1589
1557
  * @param {string} assetA First asset
@@ -1743,8 +1711,8 @@ export class Pool {
1743
1711
  }
1744
1712
 
1745
1713
  /**
1746
- * Add liquidity to Velodrome V2 or Ramses pool
1747
- * @param {Dapp} dapp VelodromeV2, Ramses or Aerodrome
1714
+ * Add liquidity to Velodrome V2 or Aerodrome pool
1715
+ * @param {Dapp} dapp VelodromeV2 or Aerodrome
1748
1716
  * @param {string} assetA First asset
1749
1717
  * @param {string} assetB Second asset
1750
1718
  * @param {BigNumber | string} amountA Amount first asset
@@ -1755,7 +1723,7 @@ export class Pool {
1755
1723
  * @returns {Promise<any>} Transaction
1756
1724
  */
1757
1725
  async addLiquidityV2(
1758
- dapp: Dapp.VELODROMEV2 | Dapp.RAMSES | Dapp.AERODROME,
1726
+ dapp: Dapp.VELODROMEV2 | Dapp.AERODROME,
1759
1727
  assetA: string,
1760
1728
  assetB: string,
1761
1729
  amountA: BigNumber | string,
@@ -1786,8 +1754,8 @@ export class Pool {
1786
1754
  }
1787
1755
 
1788
1756
  /**
1789
- * Remove liquidity from Velodrome V2 or Ramses pool
1790
- * @param {Dapp} dapp VelodromeV2, Ramses or Aerodrome
1757
+ * Remove liquidity from Velodrome V2 or Aerodrome pool
1758
+ * @param {Dapp} dapp VelodromeV2 or Aerodrome
1791
1759
  * @param {string} assetA First asset
1792
1760
  * @param {string} assetB Second asset
1793
1761
  * @param {BigNumber | string} amount Amount of LP tokens
@@ -1797,7 +1765,7 @@ export class Pool {
1797
1765
  * @returns {Promise<any>} Transaction
1798
1766
  */
1799
1767
  async removeLiquidityV2(
1800
- dapp: Dapp.VELODROMEV2 | Dapp.RAMSES | Dapp.AERODROME,
1768
+ dapp: Dapp.VELODROMEV2 | Dapp.AERODROME,
1801
1769
  assetA: string,
1802
1770
  assetB: string,
1803
1771
  amount: BigNumber | string,
@@ -1883,82 +1851,6 @@ export class Pool {
1883
1851
  return await getOptionPositions(this, market);
1884
1852
  }
1885
1853
 
1886
- /** Deposit or withdraws (negative amount) asset for Synthetix future margin trading
1887
- *
1888
- * @param {string} market Address of futures market
1889
- * @param {BigNumber | string } changeAmount Amount to increase/decrease margin
1890
- * @param {any} options Transaction options
1891
- * @param {SDKOptions} sdkOptions SDK options including estimateGas
1892
- * @returns {Promise<any>} Transaction
1893
- */
1894
- async changeFuturesMargin(
1895
- market: string,
1896
- changeAmount: BigNumber | string,
1897
- options: any = null,
1898
- sdkOptions: SDKOptions = {
1899
- estimateGas: false
1900
- }
1901
- ): Promise<any> {
1902
- const tx = await getPoolTxOrGasEstimate(
1903
- this,
1904
- [market, getFuturesChangeMarginTxData(changeAmount), options],
1905
- sdkOptions
1906
- );
1907
- return tx;
1908
- }
1909
-
1910
- /** Change position in Synthetix futures market (long/short)
1911
- *
1912
- * @param {string} market Address of futures market
1913
- * @param {BigNumber | string } changeAmount Negative for short, positive for long
1914
- * @param {any} options Transaction options
1915
- * @param {SDKOptions} sdkOptions SDK options including estimateGas
1916
- * @returns {Promise<any>} Transaction
1917
- */
1918
- async changeFuturesPosition(
1919
- market: string,
1920
- changeAmount: BigNumber | string,
1921
- options: any = null,
1922
- sdkOptions: SDKOptions = {
1923
- estimateGas: false
1924
- }
1925
- ): Promise<any> {
1926
- const txData = await getFuturesChangePositionTxData(
1927
- changeAmount,
1928
- market,
1929
- this
1930
- );
1931
- const tx = await getPoolTxOrGasEstimate(
1932
- this,
1933
- [market, txData, options],
1934
- sdkOptions
1935
- );
1936
- return tx;
1937
- }
1938
-
1939
- /** Cancels an open oder on Synthetix futures market
1940
- *
1941
- * @param {string} market Address of futures market
1942
- * @param {any} options Transaction options
1943
- * @param {SDKOptions} sdkOptions SDK options including estimateGas
1944
- * @returns {Promise<any>} Transaction
1945
- */
1946
- async cancelFuturesOrder(
1947
- market: string,
1948
- options: any = null,
1949
- sdkOptions: SDKOptions = {
1950
- estimateGas: false
1951
- }
1952
- ): Promise<any> {
1953
- const txData = await getFuturesCancelOrderTxData(this);
1954
- const tx = await getPoolTxOrGasEstimate(
1955
- this,
1956
- [market, txData, options],
1957
- sdkOptions
1958
- );
1959
- return tx;
1960
- }
1961
-
1962
1854
  /**
1963
1855
  * mintManagerFee
1964
1856
  * @param {any} options Transaction options
@@ -1978,60 +1870,11 @@ export class Pool {
1978
1870
  * @returns {Promise<BigNumber>} fee
1979
1871
  */
1980
1872
  async getAvailableManagerFee(): Promise<BigNumber> {
1981
- const fee = await this.poolLogic.availableManagerFee();
1873
+ const fundValue = await this.managerLogic.totalFundValue();
1874
+ const fee = await this.poolLogic.calculateAvailableManagerFee(fundValue);
1982
1875
  return BigNumber.from(fee);
1983
1876
  }
1984
1877
 
1985
- /** Vest tokens (e.g. Ramses xoRAM)
1986
- *
1987
- * @param {string} tokenAddress Address of the token to vest
1988
- * @param {BigNumber | string } changeAmount Negative for short, positive for long
1989
- * @param {any} options Transaction options
1990
- * @param {SDKOptions} sdkOptions SDK options including estimateGas
1991
- * @returns {Promise<any>} Transaction
1992
- */
1993
- async vestTokens(
1994
- tokenAddress: string,
1995
- amount: BigNumber | string,
1996
- options: any = null,
1997
- sdkOptions: SDKOptions = {
1998
- estimateGas: false
1999
- }
2000
- ): Promise<any> {
2001
- const txData = await getCreateVestTxData(amount);
2002
- const tx = await getPoolTxOrGasEstimate(
2003
- this,
2004
- [tokenAddress, txData, options],
2005
- sdkOptions
2006
- );
2007
- return tx;
2008
- }
2009
-
2010
- /** Exit position of vested tokens (e.g. Ramses xoRAM)
2011
- *
2012
- * @param {string} tokenAddress Address of the token to vest
2013
- * @param {number } id position Id of the vested tokens
2014
- * @param {any} options Transaction options
2015
- * @param {SDKOptions} sdkOptions SDK options including estimateGas
2016
- * @returns {Promise<any>} Transaction
2017
- */
2018
- async exitVestedToken(
2019
- tokenAddress: string,
2020
- id: number,
2021
- options: any = null,
2022
- sdkOptions: SDKOptions = {
2023
- estimateGas: false
2024
- }
2025
- ): Promise<any> {
2026
- const txData = await getExitVestTxData(id);
2027
- const tx = await getPoolTxOrGasEstimate(
2028
- this,
2029
- [tokenAddress, txData, options],
2030
- sdkOptions
2031
- );
2032
- return tx;
2033
- }
2034
-
2035
1878
  /** deposit rETH to mint UNIT via the Flat Money protocol
2036
1879
  *
2037
1880
  * @param { BigNumber | string } depositAmount Amount of rETH to deposit
@@ -2090,6 +1933,12 @@ export class Pool {
2090
1933
  return tx;
2091
1934
  }
2092
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
+ */
2093
1942
  async cancelOrderViaFlatMoney(
2094
1943
  options: any = null,
2095
1944
  estimateGas = false
@@ -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,