@gainsnetwork/sdk 0.2.67-rc8 → 0.2.69

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 (136) hide show
  1. package/lib/contracts/addresses.json +20 -0
  2. package/lib/{trade/fees/borrowingV2/fetcher.d.ts → contracts/fetch/fees/borrowingFeesV2.d.ts} +3 -2
  3. package/lib/{trade/fees/borrowingV2/fetcher.js → contracts/fetch/fees/borrowingFeesV2.js} +14 -6
  4. package/lib/{trade/fees/fundingFees/fetcher.d.ts → contracts/fetch/fees/fundingFees.d.ts} +2 -2
  5. package/lib/{trade/priceImpact/skew/fetcher.d.ts → contracts/fetch/priceImpact/skew.d.ts} +2 -2
  6. package/lib/{trade/priceImpact/skew/fetcher.js → contracts/fetch/priceImpact/skew.js} +6 -6
  7. package/lib/contracts/index.js +3 -1
  8. package/lib/contracts/types/generated/GNSMultiCollatDiamond.d.ts +258 -2112
  9. package/lib/contracts/types/generated/GToken.d.ts +107 -78
  10. package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.d.ts +53 -90
  11. package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.js +421 -4496
  12. package/lib/contracts/types/generated/factories/GToken__factory.js +142 -65
  13. package/lib/contracts/types/index.d.ts +2 -1
  14. package/lib/contracts/types/index.js +1 -0
  15. package/lib/trade/fees/borrowingV2/converter.d.ts +3 -12
  16. package/lib/trade/fees/borrowingV2/converter.js +18 -29
  17. package/lib/trade/fees/borrowingV2/index.d.ts +17 -6
  18. package/lib/trade/fees/borrowingV2/index.js +37 -10
  19. package/lib/trade/fees/borrowingV2/types.d.ts +6 -22
  20. package/lib/trade/fees/fundingFees/index.d.ts +2 -13
  21. package/lib/trade/fees/fundingFees/index.js +3 -27
  22. package/lib/trade/fees/trading/index.d.ts +2 -30
  23. package/lib/trade/fees/trading/index.js +1 -52
  24. package/lib/trade/fees/trading/types.d.ts +0 -9
  25. package/lib/trade/priceImpact/index.d.ts +2 -6
  26. package/lib/trade/priceImpact/index.js +3 -30
  27. package/lib/trade/priceImpact/skew/index.d.ts +0 -1
  28. package/lib/trade/priceImpact/skew/index.js +0 -4
  29. package/package.json +1 -1
  30. package/lib/backend/globalTrades/index.d.ts +0 -11
  31. package/lib/backend/globalTrades/index.js +0 -69
  32. package/lib/backend/index.d.ts +0 -3
  33. package/lib/backend/index.js +0 -28
  34. package/lib/backend/tradingVariables/backend.types.d.ts +0 -312
  35. package/lib/backend/tradingVariables/backend.types.js +0 -2
  36. package/lib/backend/tradingVariables/converter.d.ts +0 -31
  37. package/lib/backend/tradingVariables/converter.js +0 -330
  38. package/lib/backend/tradingVariables/index.d.ts +0 -5
  39. package/lib/backend/tradingVariables/index.js +0 -95
  40. package/lib/backend/tradingVariables/types.d.ts +0 -109
  41. package/lib/backend/tradingVariables/types.js +0 -14
  42. package/lib/contracts/types/generated/GFarmTradingStorageV5.d.ts +0 -1911
  43. package/lib/contracts/types/generated/GFarmTradingStorageV5.js +0 -2
  44. package/lib/contracts/types/generated/GNSBorrowingFees.d.ts +0 -1067
  45. package/lib/contracts/types/generated/GNSBorrowingFees.js +0 -2
  46. package/lib/contracts/types/generated/GNSNftRewardsV6.d.ts +0 -533
  47. package/lib/contracts/types/generated/GNSNftRewardsV6.js +0 -2
  48. package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.d.ts +0 -613
  49. package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.js +0 -2
  50. package/lib/contracts/types/generated/GNSTrading.d.ts +0 -758
  51. package/lib/contracts/types/generated/GNSTrading.js +0 -2
  52. package/lib/contracts/types/generated/GNSTradingCallbacks.d.ts +0 -875
  53. package/lib/contracts/types/generated/GNSTradingCallbacks.js +0 -2
  54. package/lib/contracts/types/generated/GNSTradingStorage.d.ts +0 -1387
  55. package/lib/contracts/types/generated/GNSTradingStorage.js +0 -2
  56. package/lib/contracts/types/generated/GTokenV6_3_2.d.ts +0 -1838
  57. package/lib/contracts/types/generated/GTokenV6_3_2.js +0 -2
  58. package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.d.ts +0 -83
  59. package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.js +0 -2691
  60. package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.d.ts +0 -124
  61. package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.js +0 -1784
  62. package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.d.ts +0 -100
  63. package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.js +0 -1116
  64. package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.d.ts +0 -100
  65. package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.js +0 -1003
  66. package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.d.ts +0 -113
  67. package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.js +0 -1428
  68. package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.d.ts +0 -96
  69. package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.js +0 -2241
  70. package/lib/contracts/types/generated/factories/GNSTrading__factory.d.ts +0 -95
  71. package/lib/contracts/types/generated/factories/GNSTrading__factory.js +0 -1071
  72. package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.d.ts +0 -110
  73. package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.js +0 -2682
  74. package/lib/contracts/utils/openLimitOrders.d.ts +0 -8
  75. package/lib/contracts/utils/openLimitOrders.js +0 -88
  76. package/lib/markets/collateral/converter.d.ts +0 -5
  77. package/lib/markets/collateral/converter.js +0 -11
  78. package/lib/markets/collateral/index.d.ts +0 -1
  79. package/lib/markets/collateral/index.js +0 -17
  80. package/lib/markets/collateral/types.d.ts +0 -7
  81. package/lib/markets/collateral/types.js +0 -2
  82. package/lib/markets/oi/converter.d.ts +0 -63
  83. package/lib/markets/oi/converter.js +0 -103
  84. package/lib/markets/oi/fetcher.d.ts +0 -58
  85. package/lib/markets/oi/fetcher.js +0 -181
  86. package/lib/markets/oi/index.d.ts +0 -10
  87. package/lib/markets/oi/index.js +0 -37
  88. package/lib/markets/oi/types.d.ts +0 -82
  89. package/lib/markets/oi/types.js +0 -6
  90. package/lib/markets/oi/validation.d.ts +0 -80
  91. package/lib/markets/oi/validation.js +0 -172
  92. package/lib/trade/fees/borrowing/builder.d.ts +0 -14
  93. package/lib/trade/fees/borrowing/builder.js +0 -33
  94. package/lib/trade/fees/borrowingV2/builder.d.ts +0 -6
  95. package/lib/trade/fees/borrowingV2/builder.js +0 -24
  96. package/lib/trade/fees/converter.d.ts +0 -48
  97. package/lib/trade/fees/converter.js +0 -110
  98. package/lib/trade/fees/fundingFees/builder.d.ts +0 -9
  99. package/lib/trade/fees/fundingFees/builder.js +0 -35
  100. package/lib/trade/fees/fundingFees/pairContext.d.ts +0 -33
  101. package/lib/trade/fees/fundingFees/pairContext.js +0 -17
  102. package/lib/trade/fees/tiers/converter.d.ts +0 -54
  103. package/lib/trade/fees/tiers/converter.js +0 -81
  104. package/lib/trade/fees/trading/builder.d.ts +0 -18
  105. package/lib/trade/fees/trading/builder.js +0 -20
  106. package/lib/trade/liquidation/builder.d.ts +0 -25
  107. package/lib/trade/liquidation/builder.js +0 -59
  108. package/lib/trade/liquidation/converter.d.ts +0 -23
  109. package/lib/trade/liquidation/converter.js +0 -46
  110. package/lib/trade/liquidation/index.d.ts +0 -26
  111. package/lib/trade/liquidation/index.js +0 -142
  112. package/lib/trade/liquidation/types.d.ts +0 -59
  113. package/lib/trade/liquidation/types.js +0 -2
  114. package/lib/trade/openLimitOrder.d.ts +0 -2
  115. package/lib/trade/openLimitOrder.js +0 -23
  116. package/lib/trade/pnl/builder.d.ts +0 -16
  117. package/lib/trade/pnl/builder.js +0 -44
  118. package/lib/trade/pnl/converter.d.ts +0 -47
  119. package/lib/trade/pnl/converter.js +0 -72
  120. package/lib/trade/pnl/index.d.ts +0 -77
  121. package/lib/trade/pnl/index.js +0 -270
  122. package/lib/trade/pnl/types.d.ts +0 -114
  123. package/lib/trade/pnl/types.js +0 -5
  124. package/lib/trade/priceImpact/close/index.d.ts +0 -21
  125. package/lib/trade/priceImpact/close/index.js +0 -131
  126. package/lib/trade/priceImpact/close/types.d.ts +0 -43
  127. package/lib/trade/priceImpact/close/types.js +0 -5
  128. package/lib/trade/priceImpact/cumulVol/converter.d.ts +0 -31
  129. package/lib/trade/priceImpact/cumulVol/converter.js +0 -59
  130. package/lib/trade/priceImpact/cumulVol/index.d.ts +0 -107
  131. package/lib/trade/priceImpact/cumulVol/index.js +0 -228
  132. package/lib/trade/priceImpact/open/index.d.ts +0 -22
  133. package/lib/trade/priceImpact/open/index.js +0 -76
  134. package/lib/trade/priceImpact/open/types.d.ts +0 -41
  135. package/lib/trade/priceImpact/open/types.js +0 -5
  136. /package/lib/{trade/fees/fundingFees/fetcher.js → contracts/fetch/fees/fundingFees.js} +0 -0
@@ -260,12 +260,6 @@ const _abi = [
260
260
  name: "assetsLessDeplete",
261
261
  type: "uint256",
262
262
  },
263
- {
264
- indexed: false,
265
- internalType: "bool",
266
- name: "burn",
267
- type: "bool",
268
- },
269
263
  ],
270
264
  name: "AssetsReceived",
271
265
  type: "event",
@@ -314,6 +308,31 @@ const _abi = [
314
308
  name: "DailyAccPnlDeltaReset",
315
309
  type: "event",
316
310
  },
311
+ {
312
+ anonymous: false,
313
+ inputs: [
314
+ {
315
+ indexed: true,
316
+ internalType: "address",
317
+ name: "asset",
318
+ type: "address",
319
+ },
320
+ {
321
+ indexed: true,
322
+ internalType: "address",
323
+ name: "delegatee",
324
+ type: "address",
325
+ },
326
+ {
327
+ indexed: false,
328
+ internalType: "bool",
329
+ name: "success",
330
+ type: "bool",
331
+ },
332
+ ],
333
+ name: "Delegated",
334
+ type: "event",
335
+ },
317
336
  {
318
337
  anonymous: false,
319
338
  inputs: [
@@ -914,6 +933,32 @@ const _abi = [
914
933
  stateMutability: "view",
915
934
  type: "function",
916
935
  },
936
+ {
937
+ inputs: [],
938
+ name: "accBlockWeightedMarketCap",
939
+ outputs: [
940
+ {
941
+ internalType: "uint256",
942
+ name: "",
943
+ type: "uint256",
944
+ },
945
+ ],
946
+ stateMutability: "view",
947
+ type: "function",
948
+ },
949
+ {
950
+ inputs: [],
951
+ name: "accBlockWeightedMarketCapLastStored",
952
+ outputs: [
953
+ {
954
+ internalType: "uint256",
955
+ name: "",
956
+ type: "uint256",
957
+ },
958
+ ],
959
+ stateMutability: "view",
960
+ type: "function",
961
+ },
917
962
  {
918
963
  inputs: [],
919
964
  name: "accPnlPerToken",
@@ -1409,60 +1454,6 @@ const _abi = [
1409
1454
  stateMutability: "view",
1410
1455
  type: "function",
1411
1456
  },
1412
- {
1413
- inputs: [],
1414
- name: "getTotalDepleted",
1415
- outputs: [
1416
- {
1417
- internalType: "uint256",
1418
- name: "assets",
1419
- type: "uint256",
1420
- },
1421
- {
1422
- internalType: "uint256",
1423
- name: "gns",
1424
- type: "uint256",
1425
- },
1426
- ],
1427
- stateMutability: "view",
1428
- type: "function",
1429
- },
1430
- {
1431
- inputs: [],
1432
- name: "getTotalDiscounts",
1433
- outputs: [
1434
- {
1435
- internalType: "uint256",
1436
- name: "unlocked",
1437
- type: "uint256",
1438
- },
1439
- {
1440
- internalType: "uint256",
1441
- name: "locked",
1442
- type: "uint256",
1443
- },
1444
- ],
1445
- stateMutability: "view",
1446
- type: "function",
1447
- },
1448
- {
1449
- inputs: [],
1450
- name: "getTotalRefilled",
1451
- outputs: [
1452
- {
1453
- internalType: "uint256",
1454
- name: "assets",
1455
- type: "uint256",
1456
- },
1457
- {
1458
- internalType: "uint256",
1459
- name: "gns",
1460
- type: "uint256",
1461
- },
1462
- ],
1463
- stateMutability: "view",
1464
- type: "function",
1465
- },
1466
1457
  {
1467
1458
  inputs: [],
1468
1459
  name: "gnsPriceProvider",
@@ -2222,11 +2213,6 @@ const _abi = [
2222
2213
  name: "user",
2223
2214
  type: "address",
2224
2215
  },
2225
- {
2226
- internalType: "bool",
2227
- name: "_burn",
2228
- type: "bool",
2229
- },
2230
2216
  ],
2231
2217
  name: "receiveAssets",
2232
2218
  outputs: [],
@@ -2352,6 +2338,32 @@ const _abi = [
2352
2338
  stateMutability: "view",
2353
2339
  type: "function",
2354
2340
  },
2341
+ {
2342
+ inputs: [],
2343
+ name: "totalDepleted",
2344
+ outputs: [
2345
+ {
2346
+ internalType: "uint256",
2347
+ name: "",
2348
+ type: "uint256",
2349
+ },
2350
+ ],
2351
+ stateMutability: "view",
2352
+ type: "function",
2353
+ },
2354
+ {
2355
+ inputs: [],
2356
+ name: "totalDepletedGns",
2357
+ outputs: [
2358
+ {
2359
+ internalType: "uint256",
2360
+ name: "",
2361
+ type: "uint256",
2362
+ },
2363
+ ],
2364
+ stateMutability: "view",
2365
+ type: "function",
2366
+ },
2355
2367
  {
2356
2368
  inputs: [],
2357
2369
  name: "totalDeposited",
@@ -2365,6 +2377,19 @@ const _abi = [
2365
2377
  stateMutability: "view",
2366
2378
  type: "function",
2367
2379
  },
2380
+ {
2381
+ inputs: [],
2382
+ name: "totalDiscounts",
2383
+ outputs: [
2384
+ {
2385
+ internalType: "uint256",
2386
+ name: "",
2387
+ type: "uint256",
2388
+ },
2389
+ ],
2390
+ stateMutability: "view",
2391
+ type: "function",
2392
+ },
2368
2393
  {
2369
2394
  inputs: [],
2370
2395
  name: "totalLiability",
@@ -2378,6 +2403,45 @@ const _abi = [
2378
2403
  stateMutability: "view",
2379
2404
  type: "function",
2380
2405
  },
2406
+ {
2407
+ inputs: [],
2408
+ name: "totalLockedDiscounts",
2409
+ outputs: [
2410
+ {
2411
+ internalType: "uint256",
2412
+ name: "",
2413
+ type: "uint256",
2414
+ },
2415
+ ],
2416
+ stateMutability: "view",
2417
+ type: "function",
2418
+ },
2419
+ {
2420
+ inputs: [],
2421
+ name: "totalRefilled",
2422
+ outputs: [
2423
+ {
2424
+ internalType: "uint256",
2425
+ name: "",
2426
+ type: "uint256",
2427
+ },
2428
+ ],
2429
+ stateMutability: "view",
2430
+ type: "function",
2431
+ },
2432
+ {
2433
+ inputs: [],
2434
+ name: "totalRefilledGns",
2435
+ outputs: [
2436
+ {
2437
+ internalType: "uint256",
2438
+ name: "",
2439
+ type: "uint256",
2440
+ },
2441
+ ],
2442
+ stateMutability: "view",
2443
+ type: "function",
2444
+ },
2381
2445
  {
2382
2446
  inputs: [],
2383
2447
  name: "totalRewards",
@@ -2578,6 +2642,19 @@ const _abi = [
2578
2642
  stateMutability: "nonpayable",
2579
2643
  type: "function",
2580
2644
  },
2645
+ {
2646
+ inputs: [
2647
+ {
2648
+ internalType: "address",
2649
+ name: "_delegatee",
2650
+ type: "address",
2651
+ },
2652
+ ],
2653
+ name: "updateDelegatee",
2654
+ outputs: [],
2655
+ stateMutability: "nonpayable",
2656
+ type: "function",
2657
+ },
2581
2658
  {
2582
2659
  inputs: [
2583
2660
  {
@@ -16,7 +16,8 @@ export declare enum CollateralTypes {
16
16
  ARB = "ARB",
17
17
  USDC = "USDC",
18
18
  APE = "APE",
19
- GNS = "GNS"
19
+ GNS = "GNS",
20
+ BTCUSD = "BTCUSD"
20
21
  }
21
22
  export declare enum ContractsVersion {
22
23
  BEFORE_V9_2 = 0,
@@ -9,6 +9,7 @@ var CollateralTypes;
9
9
  CollateralTypes["USDC"] = "USDC";
10
10
  CollateralTypes["APE"] = "APE";
11
11
  CollateralTypes["GNS"] = "GNS";
12
+ CollateralTypes["BTCUSD"] = "BTCUSD";
12
13
  })(CollateralTypes = exports.CollateralTypes || (exports.CollateralTypes = {}));
13
14
  var ContractsVersion;
14
15
  (function (ContractsVersion) {
@@ -38,13 +38,14 @@ export declare const convertTradeInitialAccFees: (contractTradeData: IFundingFee
38
38
  export declare const convertTradeInitialAccFeesArray: (contractTradeDataArray: IFundingFees.TradeFeesDataStructOutput[]) => BorrowingFeeV2.TradeInitialAccFees[];
39
39
  /**
40
40
  * @dev Creates a context object from contract data arrays
41
+ * @param collateralIndices Array of collateral indices
41
42
  * @param pairIndices Array of pair indices
42
43
  * @param borrowingParams Array of borrowing fee params from contract
43
44
  * @param borrowingData Array of pair borrowing fee data from contract
44
45
  * @param currentTimestamp Optional current timestamp
45
- * @returns Complete SDK context for borrowing v2 calculations (collateral-scoped)
46
+ * @returns Complete SDK context for borrowing v2 calculations
46
47
  */
47
- export declare const createBorrowingV2Context: (pairIndices: number[], borrowingParams: IFundingFees.BorrowingFeeParamsStructOutput[], borrowingData: IFundingFees.PairBorrowingFeeDataStructOutput[], currentTimestamp?: number) => BorrowingFeeV2.GetBorrowingFeeV2Context;
48
+ export declare const createBorrowingV2Context: (collateralIndices: number[], pairIndices: number[], borrowingParams: IFundingFees.BorrowingFeeParamsStructOutput[], borrowingData: IFundingFees.PairBorrowingFeeDataStructOutput[], currentTimestamp?: number) => BorrowingFeeV2.GetBorrowingFeeV2Context;
48
49
  /**
49
50
  * @dev Helper function to validate borrowing rate per second
50
51
  * @param borrowingRatePerSecondP Borrowing rate per second (normalized float)
@@ -63,13 +64,3 @@ export declare const borrowingRateToAPR: (borrowingRatePerSecondP: number) => nu
63
64
  * @returns Borrowing rate per second (normalized float)
64
65
  */
65
66
  export declare const aprToBorrowingRate: (aprPercentage: number) => number;
66
- /**
67
- * @dev Creates a collateral-scoped context from frontend data structure
68
- * @param collateralBorrowingData Data structure from frontend (params and data arrays)
69
- * @param currentTimestamp Optional current timestamp
70
- * @returns Collateral-scoped borrowing fee v2 context
71
- */
72
- export declare const createCollateralScopedBorrowingContext: (collateralBorrowingData: {
73
- params: BorrowingFeeV2.BorrowingFeeParams[];
74
- data: BorrowingFeeV2.PairBorrowingFeeData[];
75
- }, currentTimestamp?: number) => BorrowingFeeV2.GetBorrowingFeeV2Context;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createCollateralScopedBorrowingContext = exports.aprToBorrowingRate = exports.borrowingRateToAPR = exports.isValidBorrowingRate = exports.createBorrowingV2Context = exports.convertTradeInitialAccFeesArray = exports.convertTradeInitialAccFees = exports.convertPairBorrowingFeeDataArray = exports.convertPairBorrowingFeeData = exports.convertBorrowingFeeParamsArray = exports.convertBorrowingFeeParams = void 0;
3
+ exports.aprToBorrowingRate = exports.borrowingRateToAPR = exports.isValidBorrowingRate = exports.createBorrowingV2Context = exports.convertTradeInitialAccFeesArray = exports.convertTradeInitialAccFees = exports.convertPairBorrowingFeeDataArray = exports.convertPairBorrowingFeeData = exports.convertBorrowingFeeParamsArray = exports.convertBorrowingFeeParams = void 0;
4
4
  const index_1 = require("./index");
5
5
  /**
6
6
  * @dev Converts contract BorrowingFeeParams to SDK type
@@ -56,24 +56,35 @@ const convertTradeInitialAccFeesArray = (contractTradeDataArray) => contractTrad
56
56
  exports.convertTradeInitialAccFeesArray = convertTradeInitialAccFeesArray;
57
57
  /**
58
58
  * @dev Creates a context object from contract data arrays
59
+ * @param collateralIndices Array of collateral indices
59
60
  * @param pairIndices Array of pair indices
60
61
  * @param borrowingParams Array of borrowing fee params from contract
61
62
  * @param borrowingData Array of pair borrowing fee data from contract
62
63
  * @param currentTimestamp Optional current timestamp
63
- * @returns Complete SDK context for borrowing v2 calculations (collateral-scoped)
64
+ * @returns Complete SDK context for borrowing v2 calculations
64
65
  */
65
- const createBorrowingV2Context = (pairIndices, borrowingParams, borrowingData, currentTimestamp) => {
66
+ const createBorrowingV2Context = (collateralIndices, pairIndices, borrowingParams, borrowingData, currentTimestamp) => {
66
67
  const context = {
67
68
  currentTimestamp,
68
69
  borrowingParams: {},
69
70
  borrowingData: {},
70
71
  };
71
- // Build objects indexed by pairIndex
72
- for (let i = 0; i < pairIndices.length; i++) {
72
+ // Build nested objects indexed by collateralIndex and pairIndex
73
+ for (let i = 0; i < collateralIndices.length; i++) {
74
+ const collateralIndex = collateralIndices[i];
73
75
  const pairIndex = pairIndices[i];
76
+ // Initialize collateral index objects if they don't exist
77
+ if (!context.borrowingParams[collateralIndex]) {
78
+ context.borrowingParams[collateralIndex] = {};
79
+ }
80
+ if (!context.borrowingData[collateralIndex]) {
81
+ context.borrowingData[collateralIndex] = {};
82
+ }
74
83
  // Store converted data
75
- context.borrowingParams[pairIndex] = (0, exports.convertBorrowingFeeParams)(borrowingParams[i]);
76
- context.borrowingData[pairIndex] = (0, exports.convertPairBorrowingFeeData)(borrowingData[i]);
84
+ context.borrowingParams[collateralIndex][pairIndex] =
85
+ (0, exports.convertBorrowingFeeParams)(borrowingParams[i]);
86
+ context.borrowingData[collateralIndex][pairIndex] =
87
+ (0, exports.convertPairBorrowingFeeData)(borrowingData[i]);
77
88
  }
78
89
  return context;
79
90
  };
@@ -108,25 +119,3 @@ const aprToBorrowingRate = (aprPercentage) => {
108
119
  return aprPercentage / SECONDS_PER_YEAR;
109
120
  };
110
121
  exports.aprToBorrowingRate = aprToBorrowingRate;
111
- /**
112
- * @dev Creates a collateral-scoped context from frontend data structure
113
- * @param collateralBorrowingData Data structure from frontend (params and data arrays)
114
- * @param currentTimestamp Optional current timestamp
115
- * @returns Collateral-scoped borrowing fee v2 context
116
- */
117
- const createCollateralScopedBorrowingContext = (collateralBorrowingData, currentTimestamp) => {
118
- const context = {
119
- currentTimestamp: currentTimestamp !== null && currentTimestamp !== void 0 ? currentTimestamp : Math.floor(Date.now() / 1000),
120
- borrowingParams: {},
121
- borrowingData: {},
122
- };
123
- // Map arrays to objects indexed by array position (pairIndex)
124
- collateralBorrowingData.params.forEach((param, index) => {
125
- context.borrowingParams[index] = param;
126
- });
127
- collateralBorrowingData.data.forEach((data, index) => {
128
- context.borrowingData[index] = data;
129
- });
130
- return context;
131
- };
132
- exports.createCollateralScopedBorrowingContext = createCollateralScopedBorrowingContext;
@@ -22,11 +22,23 @@ export declare const BORROWING_V2_PRECISION: {
22
22
  export declare const getPairPendingAccBorrowingFees: (params: BorrowingFeeV2.BorrowingFeeParams, data: BorrowingFeeV2.PairBorrowingFeeData, currentPairPrice: number, currentTimestamp?: number) => number;
23
23
  /**
24
24
  * @dev Calculates borrowing fees owed by a specific trade
25
- * @param input Trade borrowing fee calculation input (without pairIndex)
26
- * @param context Pair-specific borrowing context
25
+ * @param input Trade borrowing fee calculation input
26
+ * @param context Context containing borrowing parameters and data
27
+ * @returns Borrowing fees in collateral tokens
28
+ */
29
+ export declare const getTradeBorrowingFeesCollateral: (input: BorrowingFeeV2.TradeBorrowingFeeInput, context: BorrowingFeeV2.GetBorrowingFeeV2Context) => number;
30
+ /**
31
+ * @dev Convenience function to calculate borrowing fees for a trade using individual parameters
32
+ * @param positionSizeCollateral Position size in collateral tokens
33
+ * @param pairIndex Index of the trading pair
34
+ * @param collateralIndex Index of the collateral
35
+ * @param openPrice Price at which the trade was opened
36
+ * @param currentPairPrice Current price of the trading pair
37
+ * @param initialAccBorrowingFeeP Initial accumulated borrowing fee when trade was opened
38
+ * @param context Context containing borrowing parameters and data
27
39
  * @returns Borrowing fees in collateral tokens
28
40
  */
29
- export declare const getTradeBorrowingFeesCollateral: (input: Omit<BorrowingFeeV2.TradeBorrowingFeeInput, "pairIndex">, context: BorrowingFeeV2.GetPairBorrowingFeeV2Context) => number;
41
+ export declare const getBorrowingFee: (positionSizeCollateral: number, pairIndex: number, collateralIndex: number, openPrice: number, currentPairPrice: number, initialAccBorrowingFeeP: number, context: BorrowingFeeV2.GetBorrowingFeeV2Context) => number;
30
42
  /**
31
43
  * @dev Utility function to get pending accumulated borrowing fees for a pair using context
32
44
  * @param input Pair borrowing fee calculation input
@@ -39,10 +51,9 @@ export declare const getPairBorrowingFees: (input: BorrowingFeeV2.PairBorrowingF
39
51
  */
40
52
  export declare const borrowingFeeV2Utils: {
41
53
  getPairPendingAccBorrowingFees: (params: BorrowingFeeV2.BorrowingFeeParams, data: BorrowingFeeV2.PairBorrowingFeeData, currentPairPrice: number, currentTimestamp?: number) => number;
42
- getTradeBorrowingFeesCollateral: (input: Omit<BorrowingFeeV2.TradeBorrowingFeeInput, "pairIndex">, context: BorrowingFeeV2.GetPairBorrowingFeeV2Context) => number;
54
+ getTradeBorrowingFeesCollateral: (input: BorrowingFeeV2.TradeBorrowingFeeInput, context: BorrowingFeeV2.GetBorrowingFeeV2Context) => number;
43
55
  getPairBorrowingFees: (input: BorrowingFeeV2.PairBorrowingFeeInput, context: BorrowingFeeV2.GetBorrowingFeeV2Context) => number;
56
+ getBorrowingFee: (positionSizeCollateral: number, pairIndex: number, collateralIndex: number, openPrice: number, currentPairPrice: number, initialAccBorrowingFeeP: number, context: BorrowingFeeV2.GetBorrowingFeeV2Context) => number;
44
57
  };
45
58
  export * as BorrowingFeeV2 from "./types";
46
- export { GetPairBorrowingFeeV2Context } from "./types";
47
59
  export * from "./converter";
48
- export * from "./fetcher";
@@ -26,7 +26,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.BorrowingFeeV2 = exports.borrowingFeeV2Utils = exports.getPairBorrowingFees = exports.getTradeBorrowingFeesCollateral = exports.getPairPendingAccBorrowingFees = exports.BORROWING_V2_PRECISION = exports.MAX_BORROWING_RATE_PER_SECOND = void 0;
29
+ exports.BorrowingFeeV2 = exports.borrowingFeeV2Utils = exports.getPairBorrowingFees = exports.getBorrowingFee = exports.getTradeBorrowingFeesCollateral = exports.getPairPendingAccBorrowingFees = exports.BORROWING_V2_PRECISION = exports.MAX_BORROWING_RATE_PER_SECOND = void 0;
30
30
  /**
31
31
  * @dev Maximum borrowing rate per second (1,000% APR)
32
32
  */
@@ -63,18 +63,21 @@ const getPairPendingAccBorrowingFees = (params, data, currentPairPrice, currentT
63
63
  exports.getPairPendingAccBorrowingFees = getPairPendingAccBorrowingFees;
64
64
  /**
65
65
  * @dev Calculates borrowing fees owed by a specific trade
66
- * @param input Trade borrowing fee calculation input (without pairIndex)
67
- * @param context Pair-specific borrowing context
66
+ * @param input Trade borrowing fee calculation input
67
+ * @param context Context containing borrowing parameters and data
68
68
  * @returns Borrowing fees in collateral tokens
69
69
  */
70
70
  const getTradeBorrowingFeesCollateral = (input, context) => {
71
- const { positionSizeCollateral, openPrice, currentPairPrice, initialAccBorrowingFeeP, currentTimestamp, } = input;
72
- const { params, data } = context;
71
+ var _a, _b;
72
+ const { positionSizeCollateral, openPrice, collateralIndex, pairIndex, currentPairPrice, initialAccBorrowingFeeP, currentTimestamp, } = input;
73
+ // Get borrowing parameters and data for the pair
74
+ const params = (_a = context.borrowingParams[collateralIndex]) === null || _a === void 0 ? void 0 : _a[pairIndex];
75
+ const data = (_b = context.borrowingData[collateralIndex]) === null || _b === void 0 ? void 0 : _b[pairIndex];
73
76
  if (!params || !data) {
74
77
  return 0;
75
78
  }
76
79
  // Calculate current accumulated borrowing fees
77
- const currentAccBorrowingFeeP = (0, exports.getPairPendingAccBorrowingFees)(params, data, currentPairPrice, currentTimestamp !== null && currentTimestamp !== void 0 ? currentTimestamp : context.currentTimestamp);
80
+ const currentAccBorrowingFeeP = (0, exports.getPairPendingAccBorrowingFees)(params, data, currentPairPrice, currentTimestamp);
78
81
  // Calculate borrowing fees for this trade
79
82
  // Formula: (positionSizeCollateral * (currentAccFee - initialAccFee)) / openPrice / 100
80
83
  const feeDeltaP = currentAccBorrowingFeeP - initialAccBorrowingFeeP;
@@ -83,6 +86,29 @@ const getTradeBorrowingFeesCollateral = (input, context) => {
83
86
  exports.BORROWING_V2_PRECISION.PERCENTAGE);
84
87
  };
85
88
  exports.getTradeBorrowingFeesCollateral = getTradeBorrowingFeesCollateral;
89
+ /**
90
+ * @dev Convenience function to calculate borrowing fees for a trade using individual parameters
91
+ * @param positionSizeCollateral Position size in collateral tokens
92
+ * @param pairIndex Index of the trading pair
93
+ * @param collateralIndex Index of the collateral
94
+ * @param openPrice Price at which the trade was opened
95
+ * @param currentPairPrice Current price of the trading pair
96
+ * @param initialAccBorrowingFeeP Initial accumulated borrowing fee when trade was opened
97
+ * @param context Context containing borrowing parameters and data
98
+ * @returns Borrowing fees in collateral tokens
99
+ */
100
+ const getBorrowingFee = (positionSizeCollateral, pairIndex, collateralIndex, openPrice, currentPairPrice, initialAccBorrowingFeeP, context) => {
101
+ return (0, exports.getTradeBorrowingFeesCollateral)({
102
+ positionSizeCollateral,
103
+ openPrice,
104
+ collateralIndex,
105
+ pairIndex,
106
+ currentPairPrice,
107
+ initialAccBorrowingFeeP,
108
+ currentTimestamp: context.currentTimestamp,
109
+ }, context);
110
+ };
111
+ exports.getBorrowingFee = getBorrowingFee;
86
112
  /**
87
113
  * @dev Utility function to get pending accumulated borrowing fees for a pair using context
88
114
  * @param input Pair borrowing fee calculation input
@@ -90,9 +116,10 @@ exports.getTradeBorrowingFeesCollateral = getTradeBorrowingFeesCollateral;
90
116
  * @returns Updated accumulated borrowing fee (1e20 precision)
91
117
  */
92
118
  const getPairBorrowingFees = (input, context) => {
93
- const { pairIndex, currentPairPrice, currentTimestamp } = input;
94
- const params = context.borrowingParams[pairIndex];
95
- const data = context.borrowingData[pairIndex];
119
+ var _a, _b;
120
+ const { collateralIndex, pairIndex, currentPairPrice, currentTimestamp } = input;
121
+ const params = (_a = context.borrowingParams[collateralIndex]) === null || _a === void 0 ? void 0 : _a[pairIndex];
122
+ const data = (_b = context.borrowingData[collateralIndex]) === null || _b === void 0 ? void 0 : _b[pairIndex];
96
123
  if (!params || !data) {
97
124
  return 0;
98
125
  }
@@ -106,7 +133,7 @@ exports.borrowingFeeV2Utils = {
106
133
  getPairPendingAccBorrowingFees: exports.getPairPendingAccBorrowingFees,
107
134
  getTradeBorrowingFeesCollateral: exports.getTradeBorrowingFeesCollateral,
108
135
  getPairBorrowingFees: exports.getPairBorrowingFees,
136
+ getBorrowingFee: exports.getBorrowingFee,
109
137
  };
110
138
  exports.BorrowingFeeV2 = __importStar(require("./types"));
111
139
  __exportStar(require("./converter"), exports);
112
- __exportStar(require("./fetcher"), exports);
@@ -39,7 +39,6 @@ export type TradeInitialAccFees = {
39
39
  };
40
40
  /**
41
41
  * @dev Context required for borrowing v2 fee calculations
42
- * @dev Context is already scoped to a specific collateral
43
42
  */
44
43
  export type GetBorrowingFeeV2Context = {
45
44
  /**
@@ -48,36 +47,20 @@ export type GetBorrowingFeeV2Context = {
48
47
  currentTimestamp?: number;
49
48
  /**
50
49
  * @dev Borrowing fee parameters for pairs
51
- * @dev Indexed by: params[pairIndex]
50
+ * @dev Indexed by: params[collateralIndex][pairIndex]
52
51
  */
53
- borrowingParams: Record<number, BorrowingFeeParams>;
52
+ borrowingParams: Record<number, Record<number, BorrowingFeeParams>>;
54
53
  /**
55
54
  * @dev Borrowing fee data for pairs
56
- * @dev Indexed by: data[pairIndex]
55
+ * @dev Indexed by: data[collateralIndex][pairIndex]
57
56
  */
58
- borrowingData: Record<number, PairBorrowingFeeData>;
59
- };
60
- /**
61
- * @dev Context for pair-specific borrowing v2 fee calculations
62
- */
63
- export type GetPairBorrowingFeeV2Context = {
64
- /**
65
- * @dev Current timestamp (defaults to Date.now() / 1000)
66
- */
67
- currentTimestamp?: number;
68
- /**
69
- * @dev Borrowing fee parameters for this specific pair
70
- */
71
- params: BorrowingFeeParams;
72
- /**
73
- * @dev Borrowing fee data for this specific pair
74
- */
75
- data: PairBorrowingFeeData;
57
+ borrowingData: Record<number, Record<number, PairBorrowingFeeData>>;
76
58
  };
77
59
  /**
78
60
  * @dev Input for calculating pending borrowing fees for a pair
79
61
  */
80
62
  export type PairBorrowingFeeInput = {
63
+ collateralIndex: number;
81
64
  pairIndex: number;
82
65
  currentPairPrice: number;
83
66
  currentTimestamp?: number;
@@ -88,6 +71,7 @@ export type PairBorrowingFeeInput = {
88
71
  export type TradeBorrowingFeeInput = {
89
72
  positionSizeCollateral: number;
90
73
  openPrice: number;
74
+ collateralIndex: number;
91
75
  pairIndex: number;
92
76
  currentPairPrice: number;
93
77
  initialAccBorrowingFeeP: number;
@@ -62,7 +62,7 @@ export declare const getPairPendingAccFundingFees: (params: FundingFeeParams, da
62
62
  * @param tradeInfo Trade info (contracts version)
63
63
  * @param tradeFeesData Trade fees data containing initial acc funding fee
64
64
  * @param currentPairPrice Current pair price
65
- * @param context Optional context with funding fee data (full or pair-specific)
65
+ * @param context Optional context with funding fee data (if not provided, uses simple calculation)
66
66
  * @returns Funding fee in collateral tokens
67
67
  */
68
68
  export declare const getTradeFundingFeesCollateral: (trade: {
@@ -92,14 +92,7 @@ export declare const getTradeFundingFeesCollateral: (trade: {
92
92
  [pairIndex: number]: number;
93
93
  };
94
94
  } | undefined;
95
- }) | {
96
- currentTimestamp: number;
97
- params: FundingFeeParams;
98
- data: PairFundingFeeData;
99
- pairOi?: PairOiAfterV10 | undefined;
100
- netExposureToken?: number | undefined;
101
- netExposureUsd?: number | undefined;
102
- } | undefined) => number;
95
+ }) | undefined) => number;
103
96
  /**
104
97
  * @dev Main function to calculate funding fees for a trade within context
105
98
  * @param context Funding fee context with params and data
@@ -140,7 +133,3 @@ export declare const getTradeFundingFeesCollateralSimple: (trade: {
140
133
  }, initialAccFundingFeeP: number, currentAccFundingFeeP: number) => number;
141
134
  export * as FundingFees from "./types";
142
135
  export type { FundingFeeParams, PairFundingFeeData, PairGlobalParams, TradeInitialAccFundingFees, PairOiAfterV10, FundingRateCalculation, GetFundingFeeContext, TradeFundingFeeResult, PairPendingAccFundingFeesResult, PairAccumulatedFees, TradeInitialAccFees, } from "./types";
143
- export type { GetPairFundingFeeContext } from "./pairContext";
144
- export * from "./fetcher";
145
- export * from "./pairContext";
146
- export * from "./builder";
@@ -26,9 +26,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
26
26
  __setModuleDefault(result, mod);
27
27
  return result;
28
28
  };
29
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
30
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
31
- };
32
29
  Object.defineProperty(exports, "__esModule", { value: true });
33
30
  exports.FundingFees = exports.getTradeFundingFeesCollateralSimple = exports.getTradeFundingFees = exports.getTradeFundingFeesCollateral = exports.getPairPendingAccFundingFees = exports.getLongShortAprMultiplier = exports.getAvgFundingRatePerSecondP = exports.getSecondsToReachZeroRate = exports.getCurrentFundingVelocityPerYear = void 0;
34
31
  // Constants from contract
@@ -230,7 +227,7 @@ exports.getPairPendingAccFundingFees = getPairPendingAccFundingFees;
230
227
  * @param tradeInfo Trade info (contracts version)
231
228
  * @param tradeFeesData Trade fees data containing initial acc funding fee
232
229
  * @param currentPairPrice Current pair price
233
- * @param context Optional context with funding fee data (full or pair-specific)
230
+ * @param context Optional context with funding fee data (if not provided, uses simple calculation)
234
231
  * @returns Funding fee in collateral tokens
235
232
  */
236
233
  const getTradeFundingFeesCollateral = (trade, tradeInfo, tradeFeesData, currentPairPrice, context) => {
@@ -240,26 +237,8 @@ const getTradeFundingFeesCollateral = (trade, tradeInfo, tradeFeesData, currentP
240
237
  return 0;
241
238
  }
242
239
  const positionSizeCollateral = trade.collateralAmount * trade.leverage;
243
- if (!context) {
244
- return 0; // Cannot calculate without context
245
- }
246
- // Check if we have a pair-specific context
247
- if ("params" in context && "data" in context) {
248
- // Pair-specific context
249
- const { params, data, pairOi, netExposureToken, netExposureUsd } = context;
250
- if (!params.fundingFeesEnabled) {
251
- return 0;
252
- }
253
- // Calculate pending accumulated fees
254
- const { accFundingFeeLongP, accFundingFeeShortP } = (0, exports.getPairPendingAccFundingFees)(params, data, currentPairPrice, pairOi || { oiLongToken: 0, oiShortToken: 0 }, netExposureToken || 0, netExposureUsd || 0, context.currentTimestamp);
255
- const currentAccFundingFeeP = trade.long
256
- ? accFundingFeeLongP
257
- : accFundingFeeShortP;
258
- const fundingFeeDelta = currentAccFundingFeeP - tradeFeesData.initialAccFundingFeeP;
259
- return (positionSizeCollateral * fundingFeeDelta) / trade.openPrice;
260
- }
261
- // Full context - original logic
262
- if ("fundingParams" in context &&
240
+ // If we have full context, calculate current accumulated funding fee
241
+ if (context &&
263
242
  trade.collateralIndex !== undefined &&
264
243
  trade.pairIndex !== undefined) {
265
244
  const params = (_a = context.fundingParams[trade.collateralIndex]) === null || _a === void 0 ? void 0 : _a[trade.pairIndex];
@@ -341,6 +320,3 @@ const getTradeFundingFeesCollateralSimple = (trade, tradeInfo, initialAccFunding
341
320
  exports.getTradeFundingFeesCollateralSimple = getTradeFundingFeesCollateralSimple;
342
321
  // Export namespace for types
343
322
  exports.FundingFees = __importStar(require("./types"));
344
- __exportStar(require("./fetcher"), exports);
345
- __exportStar(require("./pairContext"), exports);
346
- __exportStar(require("./builder"), exports);