@gainsnetwork/sdk 0.2.67-rc6 → 0.2.67-rc8

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 (147) hide show
  1. package/lib/backend/globalTrades/index.d.ts +11 -0
  2. package/lib/backend/globalTrades/index.js +69 -0
  3. package/lib/backend/index.d.ts +3 -0
  4. package/lib/backend/index.js +28 -0
  5. package/lib/backend/tradingVariables/backend.types.d.ts +312 -0
  6. package/lib/backend/tradingVariables/backend.types.js +2 -0
  7. package/lib/backend/tradingVariables/converter.d.ts +31 -0
  8. package/lib/backend/tradingVariables/converter.js +330 -0
  9. package/lib/backend/tradingVariables/index.d.ts +5 -0
  10. package/lib/backend/tradingVariables/index.js +95 -0
  11. package/lib/backend/tradingVariables/types.d.ts +109 -0
  12. package/lib/backend/tradingVariables/types.js +14 -0
  13. package/lib/constants.js +2 -3
  14. package/lib/contracts/types/generated/GFarmTradingStorageV5.d.ts +1911 -0
  15. package/lib/contracts/types/generated/GFarmTradingStorageV5.js +2 -0
  16. package/lib/contracts/types/generated/GNSBorrowingFees.d.ts +1067 -0
  17. package/lib/contracts/types/generated/GNSBorrowingFees.js +2 -0
  18. package/lib/contracts/types/generated/GNSMultiCollatDiamond.d.ts +2140 -286
  19. package/lib/contracts/types/generated/GNSNftRewardsV6.d.ts +533 -0
  20. package/lib/contracts/types/generated/GNSNftRewardsV6.js +2 -0
  21. package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.d.ts +613 -0
  22. package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.js +2 -0
  23. package/lib/contracts/types/generated/GNSTrading.d.ts +758 -0
  24. package/lib/contracts/types/generated/GNSTrading.js +2 -0
  25. package/lib/contracts/types/generated/GNSTradingCallbacks.d.ts +875 -0
  26. package/lib/contracts/types/generated/GNSTradingCallbacks.js +2 -0
  27. package/lib/contracts/types/generated/GNSTradingStorage.d.ts +1387 -0
  28. package/lib/contracts/types/generated/GNSTradingStorage.js +2 -0
  29. package/lib/contracts/types/generated/GToken.d.ts +78 -107
  30. package/lib/contracts/types/generated/GTokenV6_3_2.d.ts +1838 -0
  31. package/lib/contracts/types/generated/GTokenV6_3_2.js +2 -0
  32. package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.d.ts +83 -0
  33. package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.js +2691 -0
  34. package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.d.ts +124 -0
  35. package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.js +1784 -0
  36. package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.d.ts +90 -53
  37. package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.js +4502 -427
  38. package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.d.ts +100 -0
  39. package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.js +1116 -0
  40. package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.d.ts +100 -0
  41. package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.js +1003 -0
  42. package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.d.ts +113 -0
  43. package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.js +1428 -0
  44. package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.d.ts +96 -0
  45. package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.js +2241 -0
  46. package/lib/contracts/types/generated/factories/GNSTrading__factory.d.ts +95 -0
  47. package/lib/contracts/types/generated/factories/GNSTrading__factory.js +1071 -0
  48. package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.d.ts +110 -0
  49. package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.js +2682 -0
  50. package/lib/contracts/types/generated/factories/GToken__factory.js +65 -142
  51. package/lib/contracts/utils/openLimitOrders.d.ts +8 -0
  52. package/lib/contracts/utils/openLimitOrders.js +88 -0
  53. package/lib/markets/collateral/converter.d.ts +5 -0
  54. package/lib/markets/collateral/converter.js +11 -0
  55. package/lib/markets/collateral/index.d.ts +1 -0
  56. package/lib/markets/collateral/index.js +17 -0
  57. package/lib/markets/collateral/types.d.ts +7 -0
  58. package/lib/markets/collateral/types.js +2 -0
  59. package/lib/markets/oi/converter.d.ts +63 -0
  60. package/lib/markets/oi/converter.js +103 -0
  61. package/lib/markets/oi/fetcher.d.ts +58 -0
  62. package/lib/markets/oi/fetcher.js +181 -0
  63. package/lib/markets/oi/index.d.ts +10 -0
  64. package/lib/markets/oi/index.js +37 -0
  65. package/lib/markets/oi/types.d.ts +82 -0
  66. package/lib/markets/oi/types.js +6 -0
  67. package/lib/markets/oi/validation.d.ts +80 -0
  68. package/lib/markets/oi/validation.js +172 -0
  69. package/lib/trade/fees/borrowing/builder.d.ts +14 -0
  70. package/lib/trade/fees/borrowing/builder.js +33 -0
  71. package/lib/trade/fees/borrowingV2/builder.d.ts +6 -0
  72. package/lib/trade/fees/borrowingV2/builder.js +24 -0
  73. package/lib/trade/fees/borrowingV2/converter.d.ts +75 -0
  74. package/lib/trade/fees/borrowingV2/converter.js +132 -0
  75. package/lib/trade/fees/borrowingV2/fetcher.d.ts +75 -0
  76. package/lib/trade/fees/borrowingV2/fetcher.js +185 -0
  77. package/lib/trade/fees/borrowingV2/index.d.ts +48 -0
  78. package/lib/trade/fees/borrowingV2/index.js +112 -0
  79. package/lib/trade/fees/borrowingV2/types.d.ts +95 -0
  80. package/lib/trade/fees/borrowingV2/types.js +5 -0
  81. package/lib/trade/fees/converter.d.ts +48 -0
  82. package/lib/trade/fees/converter.js +110 -0
  83. package/lib/trade/fees/fundingFees/builder.d.ts +9 -0
  84. package/lib/trade/fees/fundingFees/builder.js +35 -0
  85. package/lib/trade/fees/fundingFees/converter.d.ts +102 -0
  86. package/lib/trade/fees/fundingFees/converter.js +196 -0
  87. package/lib/trade/fees/fundingFees/fetcher.d.ts +66 -0
  88. package/lib/trade/fees/fundingFees/fetcher.js +150 -0
  89. package/lib/trade/fees/fundingFees/index.d.ts +146 -0
  90. package/lib/trade/fees/fundingFees/index.js +346 -0
  91. package/lib/trade/fees/fundingFees/pairContext.d.ts +33 -0
  92. package/lib/trade/fees/fundingFees/pairContext.js +17 -0
  93. package/lib/trade/fees/fundingFees/types.d.ts +77 -0
  94. package/lib/trade/fees/fundingFees/types.js +5 -0
  95. package/lib/trade/fees/tiers/converter.d.ts +54 -0
  96. package/lib/trade/fees/tiers/converter.js +81 -0
  97. package/lib/trade/fees/trading/builder.d.ts +18 -0
  98. package/lib/trade/fees/trading/builder.js +20 -0
  99. package/lib/trade/fees/trading/converter.d.ts +30 -0
  100. package/lib/trade/fees/trading/converter.js +43 -0
  101. package/lib/trade/fees/trading/index.d.ts +62 -0
  102. package/lib/trade/fees/trading/index.js +155 -0
  103. package/lib/trade/fees/trading/types.d.ts +48 -0
  104. package/lib/trade/fees/trading/types.js +5 -0
  105. package/lib/trade/liquidation/builder.d.ts +25 -0
  106. package/lib/trade/liquidation/builder.js +59 -0
  107. package/lib/trade/liquidation/converter.d.ts +23 -0
  108. package/lib/trade/liquidation/converter.js +46 -0
  109. package/lib/trade/liquidation/index.d.ts +26 -0
  110. package/lib/trade/liquidation/index.js +142 -0
  111. package/lib/trade/liquidation/types.d.ts +59 -0
  112. package/lib/trade/liquidation/types.js +2 -0
  113. package/lib/trade/openLimitOrder.d.ts +2 -0
  114. package/lib/trade/openLimitOrder.js +23 -0
  115. package/lib/trade/pnl/builder.d.ts +16 -0
  116. package/lib/trade/pnl/builder.js +44 -0
  117. package/lib/trade/pnl/converter.d.ts +47 -0
  118. package/lib/trade/pnl/converter.js +72 -0
  119. package/lib/trade/pnl/index.d.ts +77 -0
  120. package/lib/trade/pnl/index.js +270 -0
  121. package/lib/trade/pnl/types.d.ts +114 -0
  122. package/lib/trade/pnl/types.js +5 -0
  123. package/lib/trade/priceImpact/close/index.d.ts +21 -0
  124. package/lib/trade/priceImpact/close/index.js +131 -0
  125. package/lib/trade/priceImpact/close/types.d.ts +43 -0
  126. package/lib/trade/priceImpact/close/types.js +5 -0
  127. package/lib/trade/priceImpact/cumulVol/converter.d.ts +31 -0
  128. package/lib/trade/priceImpact/cumulVol/converter.js +59 -0
  129. package/lib/trade/priceImpact/cumulVol/index.d.ts +107 -0
  130. package/lib/trade/priceImpact/cumulVol/index.js +228 -0
  131. package/lib/trade/priceImpact/index.d.ts +12 -0
  132. package/lib/trade/priceImpact/index.js +59 -0
  133. package/lib/trade/priceImpact/open/index.d.ts +22 -0
  134. package/lib/trade/priceImpact/open/index.js +76 -0
  135. package/lib/trade/priceImpact/open/types.d.ts +41 -0
  136. package/lib/trade/priceImpact/open/types.js +5 -0
  137. package/lib/trade/priceImpact/skew/converter.d.ts +77 -0
  138. package/lib/trade/priceImpact/skew/converter.js +171 -0
  139. package/lib/trade/priceImpact/skew/fetcher.d.ts +63 -0
  140. package/lib/trade/priceImpact/skew/fetcher.js +168 -0
  141. package/lib/trade/priceImpact/skew/index.d.ts +58 -0
  142. package/lib/trade/priceImpact/skew/index.js +179 -0
  143. package/lib/trade/priceImpact/skew/types.d.ts +55 -0
  144. package/lib/trade/priceImpact/skew/types.js +5 -0
  145. package/lib/trade/utils.d.ts +18 -0
  146. package/lib/trade/utils.js +30 -0
  147. package/package.json +1 -1
@@ -260,6 +260,12 @@ 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
+ },
263
269
  ],
264
270
  name: "AssetsReceived",
265
271
  type: "event",
@@ -308,31 +314,6 @@ const _abi = [
308
314
  name: "DailyAccPnlDeltaReset",
309
315
  type: "event",
310
316
  },
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
- },
336
317
  {
337
318
  anonymous: false,
338
319
  inputs: [
@@ -933,32 +914,6 @@ const _abi = [
933
914
  stateMutability: "view",
934
915
  type: "function",
935
916
  },
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
- },
962
917
  {
963
918
  inputs: [],
964
919
  name: "accPnlPerToken",
@@ -1454,6 +1409,60 @@ const _abi = [
1454
1409
  stateMutability: "view",
1455
1410
  type: "function",
1456
1411
  },
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
+ },
1457
1466
  {
1458
1467
  inputs: [],
1459
1468
  name: "gnsPriceProvider",
@@ -2213,6 +2222,11 @@ const _abi = [
2213
2222
  name: "user",
2214
2223
  type: "address",
2215
2224
  },
2225
+ {
2226
+ internalType: "bool",
2227
+ name: "_burn",
2228
+ type: "bool",
2229
+ },
2216
2230
  ],
2217
2231
  name: "receiveAssets",
2218
2232
  outputs: [],
@@ -2338,32 +2352,6 @@ const _abi = [
2338
2352
  stateMutability: "view",
2339
2353
  type: "function",
2340
2354
  },
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
- },
2367
2355
  {
2368
2356
  inputs: [],
2369
2357
  name: "totalDeposited",
@@ -2377,19 +2365,6 @@ const _abi = [
2377
2365
  stateMutability: "view",
2378
2366
  type: "function",
2379
2367
  },
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
- },
2393
2368
  {
2394
2369
  inputs: [],
2395
2370
  name: "totalLiability",
@@ -2403,45 +2378,6 @@ const _abi = [
2403
2378
  stateMutability: "view",
2404
2379
  type: "function",
2405
2380
  },
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
- },
2445
2381
  {
2446
2382
  inputs: [],
2447
2383
  name: "totalRewards",
@@ -2642,19 +2578,6 @@ const _abi = [
2642
2578
  stateMutability: "nonpayable",
2643
2579
  type: "function",
2644
2580
  },
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
- },
2658
2581
  {
2659
2582
  inputs: [
2660
2583
  {
@@ -0,0 +1,8 @@
1
+ import { LimitOrder } from "@/trade/types";
2
+ import { BlockTag, Contracts } from "../types";
3
+ export type FetchOpenLimitOrdersOverrides = {
4
+ blockTag?: BlockTag;
5
+ useMulticall?: boolean;
6
+ };
7
+ export declare const fetchOpenLimitOrders: (contracts: Contracts, overrides?: FetchOpenLimitOrdersOverrides) => Promise<LimitOrder[]>;
8
+ export declare const fetchOpenLimitOrdersRaw: (contracts: Contracts, overrides?: FetchOpenLimitOrdersOverrides) => Promise<any[]>;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
3
+ /* eslint-disable @typescript-eslint/no-unsafe-return */
4
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
5
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.fetchOpenLimitOrdersRaw = exports.fetchOpenLimitOrders = void 0;
16
+ const ethcall_1 = require("ethcall");
17
+ const fetchOpenLimitOrders = (contracts, overrides = {}) => __awaiter(void 0, void 0, void 0, function* () {
18
+ const openLimitOrdersRaw = yield (0, exports.fetchOpenLimitOrdersRaw)(contracts, overrides);
19
+ return openLimitOrdersRaw.map((order) => ({
20
+ block: parseInt(order.block.toString()),
21
+ buy: order.buy,
22
+ index: parseInt(order.index.toString()),
23
+ leverage: parseInt(order.leverage.toString()),
24
+ maxPrice: parseFloat(order.maxPrice.toString()) / 1e10,
25
+ minPrice: parseFloat(order.minPrice.toString()) / 1e10,
26
+ pairIndex: parseInt(order.pairIndex.toString()),
27
+ positionSize: parseFloat(order.positionSize.toString()) / 1e18,
28
+ sl: parseFloat(order.sl.toString()) / 1e10,
29
+ spreadReductionP: parseInt(order.spreadReductionP.toString()) / 100,
30
+ tp: parseFloat(order.tp.toString()) / 1e10,
31
+ trader: order.trader,
32
+ type: parseInt(order.type.toString()),
33
+ maxSlippageP: parseFloat(order.maxSlippageP.toString()) / 1e10,
34
+ }));
35
+ });
36
+ exports.fetchOpenLimitOrders = fetchOpenLimitOrders;
37
+ const fetchOpenLimitOrdersRaw = (contracts, overrides = {}) => __awaiter(void 0, void 0, void 0, function* () {
38
+ if (!contracts) {
39
+ return [];
40
+ }
41
+ console.time("fetchOpenLimitOrdersRaw");
42
+ const { useMulticall = false, blockTag = "latest" } = overrides;
43
+ const { gfarmTradingStorageV5: storageContract, gnsNftRewards: nftRewards, gnsTradingCallbacks: callbacks, } = contracts;
44
+ const openLimitOrders = yield storageContract.getOpenLimitOrders({
45
+ blockTag,
46
+ });
47
+ let openLimitOrderTypes = [];
48
+ let openLimitOrderTradeData = [];
49
+ if (useMulticall) {
50
+ const multicallProvider = new ethcall_1.Provider();
51
+ yield multicallProvider.init(storageContract.provider);
52
+ const nftRewardsContractMulticall = new ethcall_1.Contract(nftRewards.address, [
53
+ ...nftRewards.interface.fragments,
54
+ ]);
55
+ const callbacksContractMulticall = new ethcall_1.Contract(callbacks.address, [
56
+ ...callbacks.interface.fragments,
57
+ ]);
58
+ openLimitOrderTypes = yield multicallProvider.all(openLimitOrders.map(order => nftRewardsContractMulticall.openLimitOrderTypes(order.trader, order.pairIndex, order.index)), blockTag);
59
+ openLimitOrderTradeData = yield multicallProvider.all(openLimitOrders.map(order => callbacksContractMulticall.tradeData(order.trader, order.pairIndex, order.index, 1)), blockTag);
60
+ }
61
+ else {
62
+ openLimitOrderTypes = yield Promise.all(openLimitOrders.map(order => nftRewards.openLimitOrderTypes(order.trader, order.pairIndex, order.index, { blockTag })));
63
+ openLimitOrderTradeData = yield Promise.all(openLimitOrders.map(order => callbacks.tradeData(order.trader, order.pairIndex, order.index, 1, {
64
+ blockTag,
65
+ })));
66
+ }
67
+ return openLimitOrderTypes.map((openLimitOrderType, index) => {
68
+ const openLimitOrder = openLimitOrders[index];
69
+ const tradeData = openLimitOrderTradeData[index];
70
+ return {
71
+ trader: openLimitOrder.trader,
72
+ pairIndex: openLimitOrder.pairIndex,
73
+ index: openLimitOrder.index,
74
+ positionSize: openLimitOrder.positionSize,
75
+ spreadReductionP: openLimitOrder.spreadReductionP,
76
+ buy: openLimitOrder.buy,
77
+ leverage: openLimitOrder.leverage,
78
+ tp: openLimitOrder.tp,
79
+ sl: openLimitOrder.sl,
80
+ minPrice: openLimitOrder.minPrice,
81
+ maxPrice: openLimitOrder.maxPrice,
82
+ block: openLimitOrder.block,
83
+ type: openLimitOrderType,
84
+ maxSlippageP: tradeData.maxSlippageP,
85
+ };
86
+ });
87
+ });
88
+ exports.fetchOpenLimitOrdersRaw = fetchOpenLimitOrdersRaw;
@@ -0,0 +1,5 @@
1
+ import { ITradingStorage } from "src/contracts/types/generated/GNSMultiCollatDiamond";
2
+ import { CollateralConfig } from "./types";
3
+ export declare const convertCollateralConfig: (collateral: ITradingStorage.CollateralStructOutput & {
4
+ decimals: number;
5
+ }) => CollateralConfig;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertCollateralConfig = void 0;
4
+ const convertCollateralConfig = (collateral) => ({
5
+ collateral: collateral.collateral,
6
+ isActive: collateral.isActive,
7
+ precision: Number(collateral.precision),
8
+ precisionDelta: Number(collateral.precisionDelta),
9
+ decimals: collateral.decimals,
10
+ });
11
+ exports.convertCollateralConfig = convertCollateralConfig;
@@ -0,0 +1 @@
1
+ export * from "./types";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,7 @@
1
+ export type CollateralConfig = {
2
+ collateral: string;
3
+ isActive: boolean;
4
+ precision: number;
5
+ precisionDelta: number;
6
+ decimals?: number;
7
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @dev Converters for OI data between contract and SDK formats
3
+ * @dev Handles the three OI storage systems and precision conversions
4
+ */
5
+ import { IBorrowingFees, IPriceImpact } from "../../contracts/types/generated/GNSMultiCollatDiamond";
6
+ import { UnifiedPairOi, ComputedOi } from "./types";
7
+ /**
8
+ * @dev Converts pre-v10 OI from contract format
9
+ * @param contractOi Contract OpenInterest struct from BorrowingFeesStorage
10
+ * @param precision Collateral precision for conversion
11
+ * @returns Normalized OI with long/short values
12
+ */
13
+ export declare const convertBeforeV10Collateral: (contractOi: IBorrowingFees.OpenInterestStructOutput, precision: number) => {
14
+ long: number;
15
+ short: number;
16
+ };
17
+ /**
18
+ * @dev Converts post-v10 collateral OI from contract format
19
+ * @param contractOi Contract PairOiCollateral struct
20
+ * @param precision Collateral precision for conversion
21
+ * @returns Normalized OI with long/short values
22
+ */
23
+ export declare const convertCollateralOi: (contractOi: IPriceImpact.PairOiCollateralStructOutput, precision: number) => {
24
+ long: number;
25
+ short: number;
26
+ };
27
+ /**
28
+ * @dev Converts post-v10 token OI from contract format
29
+ * @param contractOi Contract PairOiToken struct
30
+ * @returns Normalized OI with long/short values (1e18 precision)
31
+ */
32
+ export declare const convertTokenOi: (contractOi: IPriceImpact.PairOiTokenStructOutput) => {
33
+ long: number;
34
+ short: number;
35
+ };
36
+ /**
37
+ * @dev Converts all OI data for a pair into unified structure
38
+ * @param beforeV10 Pre-v10 OI from BorrowingFeesStorage
39
+ * @param afterV10Collateral Post-v10 collateral OI from PriceImpactStorage
40
+ * @param afterV10Token Post-v10 token OI from PriceImpactStorage
41
+ * @param maxOi Maximum OI allowed (from BorrowingFeesStorage)
42
+ * @param collateralPrecision Precision for collateral conversions
43
+ * @returns Unified PairOi structure
44
+ */
45
+ export declare const convertPairOi: (beforeV10: IBorrowingFees.OpenInterestStructOutput, afterV10Collateral: IPriceImpact.PairOiCollateralStructOutput, afterV10Token: IPriceImpact.PairOiTokenStructOutput, collateralPrecision: number) => UnifiedPairOi;
46
+ /**
47
+ * @dev Batch converter for multiple pairs
48
+ * @param pairs Array of OI data for multiple pairs
49
+ * @param collateralPrecision Precision for collateral conversions
50
+ * @returns Array of unified PairOi structures
51
+ */
52
+ export declare const convertPairOiArray: (pairs: Array<{
53
+ beforeV10: IBorrowingFees.OpenInterestStructOutput;
54
+ collateral: IPriceImpact.PairOiCollateralStructOutput;
55
+ token: IPriceImpact.PairOiTokenStructOutput;
56
+ }>, collateralPrecision: number) => UnifiedPairOi[];
57
+ /**
58
+ * @dev Computes derived OI values from unified structure
59
+ * @param pairOi Unified pair OI data
60
+ * @param tokenPriceCollateral Current token price in collateral units
61
+ * @returns Computed values including total OI and skew
62
+ */
63
+ export declare const computeOiValues: (pairOi: UnifiedPairOi, tokenPriceCollateral: number) => ComputedOi;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ /**
3
+ * @dev Converters for OI data between contract and SDK formats
4
+ * @dev Handles the three OI storage systems and precision conversions
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.computeOiValues = exports.convertPairOiArray = exports.convertPairOi = exports.convertTokenOi = exports.convertCollateralOi = exports.convertBeforeV10Collateral = void 0;
8
+ /**
9
+ * @dev Converts pre-v10 OI from contract format
10
+ * @param contractOi Contract OpenInterest struct from BorrowingFeesStorage
11
+ * @param precision Collateral precision for conversion
12
+ * @returns Normalized OI with long/short values
13
+ */
14
+ const convertBeforeV10Collateral = (contractOi, precision) => {
15
+ return {
16
+ long: Number(contractOi.long) / precision,
17
+ short: Number(contractOi.short) / precision,
18
+ };
19
+ };
20
+ exports.convertBeforeV10Collateral = convertBeforeV10Collateral;
21
+ /**
22
+ * @dev Converts post-v10 collateral OI from contract format
23
+ * @param contractOi Contract PairOiCollateral struct
24
+ * @param precision Collateral precision for conversion
25
+ * @returns Normalized OI with long/short values
26
+ */
27
+ const convertCollateralOi = (contractOi, precision) => {
28
+ return {
29
+ long: Number(contractOi.oiLongCollateral) / precision,
30
+ short: Number(contractOi.oiShortCollateral) / precision,
31
+ };
32
+ };
33
+ exports.convertCollateralOi = convertCollateralOi;
34
+ /**
35
+ * @dev Converts post-v10 token OI from contract format
36
+ * @param contractOi Contract PairOiToken struct
37
+ * @returns Normalized OI with long/short values (1e18 precision)
38
+ */
39
+ const convertTokenOi = (contractOi) => {
40
+ return {
41
+ long: Number(contractOi.oiLongToken) / 1e18,
42
+ short: Number(contractOi.oiShortToken) / 1e18,
43
+ };
44
+ };
45
+ exports.convertTokenOi = convertTokenOi;
46
+ /**
47
+ * @dev Converts all OI data for a pair into unified structure
48
+ * @param beforeV10 Pre-v10 OI from BorrowingFeesStorage
49
+ * @param afterV10Collateral Post-v10 collateral OI from PriceImpactStorage
50
+ * @param afterV10Token Post-v10 token OI from PriceImpactStorage
51
+ * @param maxOi Maximum OI allowed (from BorrowingFeesStorage)
52
+ * @param collateralPrecision Precision for collateral conversions
53
+ * @returns Unified PairOi structure
54
+ */
55
+ const convertPairOi = (beforeV10, afterV10Collateral, afterV10Token, collateralPrecision) => {
56
+ return {
57
+ maxCollateral: Number(beforeV10.max) / collateralPrecision,
58
+ beforeV10Collateral: (0, exports.convertBeforeV10Collateral)(beforeV10, collateralPrecision),
59
+ collateral: (0, exports.convertCollateralOi)(afterV10Collateral, collateralPrecision),
60
+ token: (0, exports.convertTokenOi)(afterV10Token),
61
+ };
62
+ };
63
+ exports.convertPairOi = convertPairOi;
64
+ /**
65
+ * @dev Batch converter for multiple pairs
66
+ * @param pairs Array of OI data for multiple pairs
67
+ * @param collateralPrecision Precision for collateral conversions
68
+ * @returns Array of unified PairOi structures
69
+ */
70
+ const convertPairOiArray = (pairs, collateralPrecision) => {
71
+ return pairs.map(p => (0, exports.convertPairOi)(p.beforeV10, p.collateral, p.token, collateralPrecision));
72
+ };
73
+ exports.convertPairOiArray = convertPairOiArray;
74
+ /**
75
+ * @dev Computes derived OI values from unified structure
76
+ * @param pairOi Unified pair OI data
77
+ * @param tokenPriceCollateral Current token price in collateral units
78
+ * @returns Computed values including total OI and skew
79
+ */
80
+ const computeOiValues = (pairOi, tokenPriceCollateral) => {
81
+ // Static total (used for admin operations)
82
+ const totalStaticLong = pairOi.beforeV10Collateral.long + pairOi.collateral.long;
83
+ const totalStaticShort = pairOi.beforeV10Collateral.short + pairOi.collateral.short;
84
+ // Dynamic total (used for real-time calculations)
85
+ const tokenLongCollateral = pairOi.token.long * tokenPriceCollateral;
86
+ const tokenShortCollateral = pairOi.token.short * tokenPriceCollateral;
87
+ const totalDynamicLong = pairOi.beforeV10Collateral.long + tokenLongCollateral;
88
+ const totalDynamicShort = pairOi.beforeV10Collateral.short + tokenShortCollateral;
89
+ // Skew (v10+ only, in tokens)
90
+ const skewToken = pairOi.token.long - pairOi.token.short;
91
+ return {
92
+ totalStaticCollateral: {
93
+ long: totalStaticLong,
94
+ short: totalStaticShort,
95
+ },
96
+ totalDynamicCollateral: {
97
+ long: totalDynamicLong,
98
+ short: totalDynamicShort,
99
+ },
100
+ skewToken,
101
+ };
102
+ };
103
+ exports.computeOiValues = computeOiValues;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @dev Fetchers for retrieving OI data from contracts
3
+ * @dev Consolidates the three OI storage systems into unified format
4
+ */
5
+ import { ethers } from "ethers";
6
+ import { ChainId } from "../../contracts/types";
7
+ import { UnifiedPairOi } from "./types";
8
+ /**
9
+ * @dev Fetches all OI data for a single pair
10
+ * @param chainId Target chain
11
+ * @param collateralIndex Collateral type
12
+ * @param pairIndex Trading pair
13
+ * @param signer Ethers signer
14
+ * @returns Unified PairOi structure with all OI data
15
+ */
16
+ export declare function fetchPairOi(chainId: ChainId, collateralIndex: number, pairIndex: number, signer: ethers.Signer): Promise<UnifiedPairOi>;
17
+ /**
18
+ * @dev Fetches OI data for multiple pairs efficiently
19
+ * @param chainId Target chain
20
+ * @param collateralIndex Collateral type
21
+ * @param pairIndices Array of trading pairs
22
+ * @param signer Ethers signer
23
+ * @returns Array of unified PairOi structures
24
+ */
25
+ export declare function fetchMultiplePairOi(chainId: ChainId, collateralIndex: number, pairIndices: number[], signer: ethers.Signer): Promise<UnifiedPairOi[]>;
26
+ /**
27
+ * @dev Creates OI context for fee calculations
28
+ * @param chainId Target chain
29
+ * @param collateralIndex Collateral type
30
+ * @param pairIndex Trading pair
31
+ * @param signer Ethers signer
32
+ * @returns OI data formatted for SDK calculations
33
+ */
34
+ export declare function createOiContext(chainId: ChainId, collateralIndex: number, pairIndex: number, signer: ethers.Signer): Promise<{
35
+ pairOi: UnifiedPairOi;
36
+ currentPrice: number;
37
+ computed: {
38
+ totalDynamicOi: {
39
+ long: number;
40
+ short: number;
41
+ };
42
+ totalStaticOi: {
43
+ long: number;
44
+ short: number;
45
+ };
46
+ skew: number;
47
+ };
48
+ }>;
49
+ /**
50
+ * @dev Fetches only the OI data needed for specific use cases
51
+ * @param chainId Target chain
52
+ * @param collateralIndex Collateral type
53
+ * @param pairIndex Trading pair
54
+ * @param useCase Which OI systems to fetch
55
+ * @param signer Ethers signer
56
+ * @returns Partial OI data based on use case
57
+ */
58
+ export declare function fetchOiForUseCase(chainId: ChainId, collateralIndex: number, pairIndex: number, useCase: "skew" | "funding" | "borrowingV1" | "limits", signer: ethers.Signer): Promise<Partial<UnifiedPairOi>>;