@gainsnetwork/sdk 0.1.27-rc3 → 0.2.0-rc1

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 (94) hide show
  1. package/lib/constants.d.ts +1 -5
  2. package/lib/constants.js +3 -6
  3. package/lib/contracts/addresses.json +8 -44
  4. package/lib/contracts/index.js +1 -4
  5. package/lib/contracts/types/generated/GNSMultiCollatDiamond.d.ts +4608 -1133
  6. package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.d.ts +190 -43
  7. package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.js +9988 -1722
  8. package/lib/contracts/types/generated/factories/index.d.ts +0 -7
  9. package/lib/contracts/types/generated/factories/index.js +1 -15
  10. package/lib/contracts/types/generated/index.d.ts +0 -14
  11. package/lib/contracts/types/generated/index.js +1 -15
  12. package/lib/contracts/types/index.d.ts +2 -10
  13. package/lib/contracts/utils/borrowingFees.d.ts +4 -4
  14. package/lib/contracts/utils/borrowingFees.js +9 -5
  15. package/lib/contracts/utils/index.d.ts +0 -1
  16. package/lib/contracts/utils/index.js +0 -1
  17. package/lib/contracts/utils/openTrades.d.ts +1 -1
  18. package/lib/contracts/utils/openTrades.js +330 -138
  19. package/lib/contracts/utils/pairs.d.ts +1 -1
  20. package/lib/contracts/utils/pairs.js +27 -20
  21. package/lib/trade/fees/borrowing/converter.d.ts +12 -10
  22. package/lib/trade/fees/borrowing/converter.js +18 -24
  23. package/lib/trade/fees/borrowing/index.d.ts +3 -4
  24. package/lib/trade/fees/borrowing/index.js +12 -18
  25. package/lib/trade/fees/borrowing/types.d.ts +14 -20
  26. package/lib/trade/fees/index.js +2 -2
  27. package/lib/trade/index.d.ts +0 -1
  28. package/lib/trade/index.js +0 -1
  29. package/lib/trade/liquidation.d.ts +3 -3
  30. package/lib/trade/liquidation.js +4 -5
  31. package/lib/trade/pnl.js +12 -12
  32. package/lib/trade/types.d.ts +33 -66
  33. package/lib/trade/types.js +9 -13
  34. package/package.json +1 -1
  35. package/lib/contracts/types/generated/GFarmTradingStorageV5.d.ts +0 -1911
  36. package/lib/contracts/types/generated/GFarmTradingStorageV5.js +0 -2
  37. package/lib/contracts/types/generated/GNSBorrowingFees.d.ts +0 -1067
  38. package/lib/contracts/types/generated/GNSBorrowingFees.js +0 -2
  39. package/lib/contracts/types/generated/GNSBorrowingFeesV6_3_2.d.ts +0 -979
  40. package/lib/contracts/types/generated/GNSBorrowingFeesV6_3_2.js +0 -2
  41. package/lib/contracts/types/generated/GNSBorrowingFeesV6_4.d.ts +0 -1058
  42. package/lib/contracts/types/generated/GNSBorrowingFeesV6_4.js +0 -2
  43. package/lib/contracts/types/generated/GNSNftRewardsV6.d.ts +0 -533
  44. package/lib/contracts/types/generated/GNSNftRewardsV6.js +0 -2
  45. package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.d.ts +0 -613
  46. package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.js +0 -2
  47. package/lib/contracts/types/generated/GNSPairInfosV6_1.d.ts +0 -911
  48. package/lib/contracts/types/generated/GNSPairInfosV6_1.js +0 -2
  49. package/lib/contracts/types/generated/GNSPairsStorageV6.d.ts +0 -660
  50. package/lib/contracts/types/generated/GNSPairsStorageV6.js +0 -2
  51. package/lib/contracts/types/generated/GNSTrading.d.ts +0 -758
  52. package/lib/contracts/types/generated/GNSTrading.js +0 -2
  53. package/lib/contracts/types/generated/GNSTradingCallbacks.d.ts +0 -875
  54. package/lib/contracts/types/generated/GNSTradingCallbacks.js +0 -2
  55. package/lib/contracts/types/generated/GNSTradingCallbacksV6_3_2.d.ts +0 -806
  56. package/lib/contracts/types/generated/GNSTradingCallbacksV6_3_2.js +0 -2
  57. package/lib/contracts/types/generated/GNSTradingCallbacksV6_4.d.ts +0 -821
  58. package/lib/contracts/types/generated/GNSTradingCallbacksV6_4.js +0 -2
  59. package/lib/contracts/types/generated/GNSTradingStorage.d.ts +0 -1387
  60. package/lib/contracts/types/generated/GNSTradingStorage.js +0 -2
  61. package/lib/contracts/types/generated/GTokenV6_3_2.d.ts +0 -1838
  62. package/lib/contracts/types/generated/GTokenV6_3_2.js +0 -2
  63. package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.d.ts +0 -83
  64. package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.js +0 -2691
  65. package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_3_2__factory.d.ts +0 -88
  66. package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_3_2__factory.js +0 -1654
  67. package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_4__factory.d.ts +0 -113
  68. package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_4__factory.js +0 -1742
  69. package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.d.ts +0 -124
  70. package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.js +0 -1784
  71. package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.d.ts +0 -100
  72. package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.js +0 -1116
  73. package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.d.ts +0 -100
  74. package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.js +0 -1003
  75. package/lib/contracts/types/generated/factories/GNSPairInfosV6_1__factory.d.ts +0 -98
  76. package/lib/contracts/types/generated/factories/GNSPairInfosV6_1__factory.js +0 -1485
  77. package/lib/contracts/types/generated/factories/GNSPairsStorageV6__factory.d.ts +0 -117
  78. package/lib/contracts/types/generated/factories/GNSPairsStorageV6__factory.js +0 -1265
  79. package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_3_2__factory.d.ts +0 -82
  80. package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_3_2__factory.js +0 -1273
  81. package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_4__factory.d.ts +0 -82
  82. package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_4__factory.js +0 -1326
  83. package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.d.ts +0 -113
  84. package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.js +0 -1428
  85. package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.d.ts +0 -96
  86. package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.js +0 -2241
  87. package/lib/contracts/types/generated/factories/GNSTrading__factory.d.ts +0 -95
  88. package/lib/contracts/types/generated/factories/GNSTrading__factory.js +0 -1071
  89. package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.d.ts +0 -110
  90. package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.js +0 -2682
  91. package/lib/contracts/utils/openLimitOrders.d.ts +0 -8
  92. package/lib/contracts/utils/openLimitOrders.js +0 -88
  93. package/lib/trade/openLimitOrder.d.ts +0 -2
  94. package/lib/trade/openLimitOrder.js +0 -23
@@ -1,8 +0,0 @@
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[]>;
@@ -1,88 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- import { LimitOrder, Pair, PairDepth, OiWindowsSettings, OiWindows } from "./types";
2
- export declare const getFulfillmentPrice: (order: LimitOrder, pair: Pair, pairDepth: PairDepth, oiWindowsSettings?: OiWindowsSettings, oiWindows?: OiWindows) => number;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFulfillmentPrice = void 0;
4
- const spread_1 = require("./spread");
5
- const types_1 = require("./types");
6
- const getFulfillmentPrice = (order, pair, pairDepth, oiWindowsSettings, oiWindows) => {
7
- if (!order || !pair) {
8
- return 0;
9
- }
10
- // Get spread percentage
11
- const spreadWithPriceImpactP = (0, spread_1.getSpreadWithPriceImpactP)(pair.spreadP, order.buy, order.positionSize, order.leverage, pairDepth, oiWindowsSettings, oiWindows);
12
- if (spreadWithPriceImpactP === 0) {
13
- return 0;
14
- }
15
- const askingPrice = (order.buy && order.type === types_1.OpenLimitOrderType.REVERSAL) ||
16
- (!order.buy && order.type === types_1.OpenLimitOrderType.MOMENTUM)
17
- ? order.maxPrice
18
- : order.minPrice;
19
- return order.buy
20
- ? askingPrice * (1 + spreadWithPriceImpactP)
21
- : askingPrice * (1 - spreadWithPriceImpactP);
22
- };
23
- exports.getFulfillmentPrice = getFulfillmentPrice;