aftermath-ts-sdk 1.3.23-cleanup → 1.3.23-perps.1

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 (112) hide show
  1. package/dist/general/apiHelpers/transactionsApiHelpers.d.ts +3 -0
  2. package/dist/general/apiHelpers/transactionsApiHelpers.d.ts.map +1 -1
  3. package/dist/general/apiHelpers/transactionsApiHelpers.js +12 -0
  4. package/dist/general/providers/aftermath.d.ts +0 -5
  5. package/dist/general/providers/aftermath.d.ts.map +1 -1
  6. package/dist/general/providers/aftermath.js +1 -6
  7. package/dist/general/providers/aftermathApi.d.ts +0 -5
  8. package/dist/general/providers/aftermathApi.d.ts.map +1 -1
  9. package/dist/general/providers/aftermathApi.js +0 -5
  10. package/dist/general/types/configTypes.d.ts +0 -10
  11. package/dist/general/types/configTypes.d.ts.map +1 -1
  12. package/dist/general/types/generalTypes.d.ts +4 -0
  13. package/dist/general/types/generalTypes.d.ts.map +1 -1
  14. package/dist/general/types/moveErrorsInterface.d.ts +1 -1
  15. package/dist/general/types/moveErrorsInterface.d.ts.map +1 -1
  16. package/dist/general/utils/caller.d.ts +17 -2
  17. package/dist/general/utils/caller.d.ts.map +1 -1
  18. package/dist/general/utils/caller.js +35 -2
  19. package/dist/general/utils/casting.d.ts +4 -5
  20. package/dist/general/utils/casting.d.ts.map +1 -1
  21. package/dist/general/utils/casting.js +4 -5
  22. package/dist/general/utils/helpers.d.ts +1 -0
  23. package/dist/general/utils/helpers.d.ts.map +1 -1
  24. package/dist/general/utils/helpers.js +35 -6
  25. package/dist/general/wallet/wallet.d.ts +1 -1
  26. package/dist/general/wallet/wallet.d.ts.map +1 -1
  27. package/dist/packages/coin/coin.d.ts +1 -1
  28. package/dist/packages/coin/coin.d.ts.map +1 -1
  29. package/dist/packages/coin/coin.js +3 -1
  30. package/dist/packages/farms/farms.d.ts +1 -1
  31. package/dist/packages/farms/farms.d.ts.map +1 -1
  32. package/dist/packages/farms/farmsStakedPosition.d.ts +1 -1
  33. package/dist/packages/farms/farmsStakedPosition.d.ts.map +1 -1
  34. package/dist/packages/farms/farmsStakingPool.d.ts +1 -1
  35. package/dist/packages/farms/farmsStakingPool.d.ts.map +1 -1
  36. package/dist/packages/faucet/api/faucetApi.d.ts +9 -17
  37. package/dist/packages/faucet/api/faucetApi.d.ts.map +1 -1
  38. package/dist/packages/faucet/api/faucetApi.js +44 -49
  39. package/dist/packages/faucet/api/faucetApiCasting.d.ts.map +1 -1
  40. package/dist/packages/faucet/api/faucetApiCasting.js +8 -5
  41. package/dist/packages/faucet/api/faucetApiCastingTypes.d.ts +1 -4
  42. package/dist/packages/faucet/api/faucetApiCastingTypes.d.ts.map +1 -1
  43. package/dist/packages/faucet/faucet.d.ts +1 -1
  44. package/dist/packages/faucet/faucet.d.ts.map +1 -1
  45. package/dist/packages/faucet/faucet.js +1 -1
  46. package/dist/packages/faucet/faucetTypes.d.ts +2 -3
  47. package/dist/packages/faucet/faucetTypes.d.ts.map +1 -1
  48. package/dist/packages/multisig/multisig.d.ts +1 -1
  49. package/dist/packages/multisig/multisig.d.ts.map +1 -1
  50. package/dist/packages/nftAmm/nftAmm.d.ts +1 -1
  51. package/dist/packages/nftAmm/nftAmm.d.ts.map +1 -1
  52. package/dist/packages/perpetuals/api/perpetualsApi.d.ts +11 -203
  53. package/dist/packages/perpetuals/api/perpetualsApi.d.ts.map +1 -1
  54. package/dist/packages/perpetuals/api/perpetualsApi.js +924 -615
  55. package/dist/packages/perpetuals/api/perpetualsApiCasting.d.ts +10 -21
  56. package/dist/packages/perpetuals/api/perpetualsApiCasting.d.ts.map +1 -1
  57. package/dist/packages/perpetuals/api/perpetualsApiCasting.js +243 -221
  58. package/dist/packages/perpetuals/index.d.ts +1 -0
  59. package/dist/packages/perpetuals/index.d.ts.map +1 -1
  60. package/dist/packages/perpetuals/index.js +1 -0
  61. package/dist/packages/perpetuals/perpetuals.d.ts +83 -14
  62. package/dist/packages/perpetuals/perpetuals.d.ts.map +1 -1
  63. package/dist/packages/perpetuals/perpetuals.js +158 -59
  64. package/dist/packages/perpetuals/perpetualsAccount.d.ts +158 -86
  65. package/dist/packages/perpetuals/perpetualsAccount.d.ts.map +1 -1
  66. package/dist/packages/perpetuals/perpetualsAccount.js +481 -141
  67. package/dist/packages/perpetuals/perpetualsCastingTypes.d.ts +82 -149
  68. package/dist/packages/perpetuals/perpetualsCastingTypes.d.ts.map +1 -1
  69. package/dist/packages/perpetuals/perpetualsMarket.d.ts +55 -20
  70. package/dist/packages/perpetuals/perpetualsMarket.d.ts.map +1 -1
  71. package/dist/packages/perpetuals/perpetualsMarket.js +110 -55
  72. package/dist/packages/perpetuals/perpetualsTypes.d.ts +586 -280
  73. package/dist/packages/perpetuals/perpetualsTypes.d.ts.map +1 -1
  74. package/dist/packages/perpetuals/perpetualsTypes.js +17 -81
  75. package/dist/packages/perpetuals/perpetualsVault.d.ts +109 -0
  76. package/dist/packages/perpetuals/perpetualsVault.d.ts.map +1 -0
  77. package/dist/packages/perpetuals/perpetualsVault.js +290 -0
  78. package/dist/packages/pools/pool.d.ts +1 -1
  79. package/dist/packages/pools/pool.d.ts.map +1 -1
  80. package/dist/packages/pools/pools.d.ts +1 -1
  81. package/dist/packages/pools/pools.d.ts.map +1 -1
  82. package/dist/packages/referralVault/referralVault.d.ts +1 -1
  83. package/dist/packages/referralVault/referralVault.d.ts.map +1 -1
  84. package/dist/packages/staking/staking.d.ts +1 -1
  85. package/dist/packages/staking/staking.d.ts.map +1 -1
  86. package/dist/packages/sui/sui.d.ts +1 -1
  87. package/dist/packages/sui/sui.d.ts.map +1 -1
  88. package/dist/packages/suiFrens/stakedSuiFren.d.ts +1 -1
  89. package/dist/packages/suiFrens/stakedSuiFren.d.ts.map +1 -1
  90. package/dist/packages/suiFrens/suiFren.d.ts +1 -1
  91. package/dist/packages/suiFrens/suiFren.d.ts.map +1 -1
  92. package/dist/packages/suiFrens/suiFrens.d.ts +1 -1
  93. package/dist/packages/suiFrens/suiFrens.d.ts.map +1 -1
  94. package/dist/types.d.ts +0 -1
  95. package/dist/types.d.ts.map +1 -1
  96. package/dist/types.js +0 -1
  97. package/package.json +1 -1
  98. package/dist/packages/oracle/api/oracleApi.d.ts +0 -21
  99. package/dist/packages/oracle/api/oracleApi.d.ts.map +0 -1
  100. package/dist/packages/oracle/api/oracleApi.js +0 -76
  101. package/dist/packages/oracle/api/oracleApiCasting.d.ts +0 -6
  102. package/dist/packages/oracle/api/oracleApiCasting.d.ts.map +0 -1
  103. package/dist/packages/oracle/api/oracleApiCasting.js +0 -25
  104. package/dist/packages/oracle/oracle.d.ts +0 -15
  105. package/dist/packages/oracle/oracle.d.ts.map +0 -1
  106. package/dist/packages/oracle/oracle.js +0 -46
  107. package/dist/packages/oracle/oracleCastingTypes.d.ts +0 -11
  108. package/dist/packages/oracle/oracleCastingTypes.d.ts.map +0 -1
  109. package/dist/packages/oracle/oracleCastingTypes.js +0 -2
  110. package/dist/packages/oracle/oracleTypes.d.ts +0 -10
  111. package/dist/packages/oracle/oracleTypes.d.ts.map +0 -1
  112. package/dist/packages/oracle/oracleTypes.js +0 -2
@@ -12,26 +12,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.PerpetualsMarket = void 0;
13
13
  const __1 = require("../..");
14
14
  const caller_1 = require("../../general/utils/caller");
15
- const iFixedUtils_1 = require("../../general/utils/iFixedUtils");
16
15
  const perpetuals_1 = require("./perpetuals");
17
- const utils_1 = require("./utils");
18
16
  class PerpetualsMarket extends caller_1.Caller {
19
17
  // =========================================================================
20
18
  // Constructor
21
19
  // =========================================================================
22
- constructor(marketData, config) {
23
- super(config, `perpetuals/${marketData.collateralCoinType}/markets/${marketData.objectId}`);
20
+ constructor(marketData, config
21
+ // public readonly Provider?: AftermathApi
22
+ ) {
23
+ super(config, "perpetuals");
24
24
  this.marketData = marketData;
25
- this.getMaxOrderSizeUsd = (inputs) => __awaiter(this, void 0, void 0, function* () {
26
- const { side, price, account, indexPrice, leverage } = inputs;
27
- const maxSize = yield this.fetchApi("max-order-size", {
28
- accountId: account.accountCap.accountId,
29
- collateral: account.collateralBalance(),
25
+ // TODO: move/add to account ?
26
+ this.getMaxOrderSize = (inputs) => __awaiter(this, void 0, void 0, function* () {
27
+ const { side, price, accountId, leverage } = inputs;
28
+ return this.fetchApi("account/max-order-size", {
30
29
  side,
31
30
  price,
32
31
  leverage,
32
+ accountId,
33
+ marketId: this.marketId,
33
34
  });
34
- return Number(maxSize) * this.lotSize() * indexPrice;
35
35
  });
36
36
  // =========================================================================
37
37
  // Calculations
@@ -41,7 +41,7 @@ class PerpetualsMarket extends caller_1.Caller {
41
41
  };
42
42
  this.nextFundingTimeMs = () => {
43
43
  const fundingFrequencyMs = Number(this.marketParams.fundingFrequencyMs);
44
- const lastFundingIntervalNumber = Math.floor(this.marketState.fundingLastUpdateMs / fundingFrequencyMs);
44
+ const lastFundingIntervalNumber = Math.floor(this.marketState.fundingLastUpdateTimestamp / fundingFrequencyMs);
45
45
  return (lastFundingIntervalNumber + 1) * fundingFrequencyMs;
46
46
  };
47
47
  // The funding rate as the difference between book and index TWAPs relative to the index price,
@@ -51,35 +51,15 @@ class PerpetualsMarket extends caller_1.Caller {
51
51
  // To get the rate as a percentage, multiply the output by 100.
52
52
  this.estimatedFundingRate = (inputs) => {
53
53
  const { indexPrice } = inputs;
54
- const premiumTwap = iFixedUtils_1.IFixedUtils.numberFromIFixed(this.marketState.premiumTwap);
54
+ const premiumTwap = this.marketState.premiumTwap;
55
55
  const relativePremium = premiumTwap / indexPrice;
56
56
  const periodAdjustment = Number(this.marketParams.fundingFrequencyMs) /
57
57
  Number(this.marketParams.fundingPeriodMs);
58
58
  return relativePremium * periodAdjustment;
59
59
  };
60
- this.priceToOrderPrice = (inputs) => {
61
- const { price } = inputs;
62
- const lotSize = this.marketParams.lotSize;
63
- const tickSize = this.marketParams.tickSize;
64
- return perpetuals_1.Perpetuals.priceToOrderPrice({
65
- price,
66
- lotSize,
67
- tickSize,
68
- });
69
- };
70
- this.orderPriceToPrice = (inputs) => {
71
- const { orderPrice } = inputs;
72
- const lotSize = this.marketParams.lotSize;
73
- const tickSize = this.marketParams.tickSize;
74
- return perpetuals_1.Perpetuals.orderPriceToPrice({
75
- orderPrice,
76
- lotSize,
77
- tickSize,
78
- });
79
- };
80
60
  this.calcCollateralUsedForOrder = (inputs) => {
81
61
  const { leverage, orderData, indexPrice, collateralPrice } = inputs;
82
- const imr = 1 / leverage;
62
+ const imr = 1 / (leverage || 1);
83
63
  // const imr = this.initialMarginRatio();
84
64
  const collateralUsd = Number(orderData.initialSize - orderData.filledSize) *
85
65
  this.lotSize() *
@@ -91,8 +71,27 @@ class PerpetualsMarket extends caller_1.Caller {
91
71
  collateral,
92
72
  };
93
73
  };
74
+ // =========================================================================
75
+ // Helpers
76
+ // =========================================================================
94
77
  this.roundToValidPrice = (inputs) => {
95
- return Math.round(inputs.price / this.tickSize()) * this.tickSize();
78
+ const ticks = inputs.price / this.tickSize();
79
+ return ((inputs.floor
80
+ ? Math.floor(ticks)
81
+ : inputs.ceil
82
+ ? Math.ceil(ticks)
83
+ : Math.round(ticks)) * this.lotSize());
84
+ };
85
+ this.roundToValidPriceBigInt = (inputs) => {
86
+ const scaledPrice = Number(inputs.price * __1.Casting.Fixed.fixedOneN9);
87
+ // TODO: make sure this calc is safe
88
+ return ((BigInt(inputs.floor
89
+ ? Math.floor(scaledPrice)
90
+ : inputs.ceil
91
+ ? Math.ceil(scaledPrice)
92
+ : Math.round(scaledPrice)) /
93
+ this.marketParams.tickSize) *
94
+ this.marketParams.tickSize);
96
95
  };
97
96
  this.roundToValidSize = (inputs) => {
98
97
  const lots = inputs.size / this.lotSize();
@@ -102,7 +101,37 @@ class PerpetualsMarket extends caller_1.Caller {
102
101
  ? Math.ceil(lots)
103
102
  : Math.round(lots)) * this.lotSize());
104
103
  };
104
+ this.roundToValidSizeBigInt = (inputs) => {
105
+ const scaledSize = Number(inputs.size * __1.Casting.Fixed.fixedOneN9);
106
+ // TODO: make sure this calc is safe
107
+ return ((BigInt(inputs.floor
108
+ ? Math.floor(scaledSize)
109
+ : inputs.ceil
110
+ ? Math.ceil(scaledSize)
111
+ : Math.round(scaledSize)) /
112
+ this.marketParams.lotSize) *
113
+ this.marketParams.lotSize);
114
+ };
115
+ this.emptyPosition = () => {
116
+ return {
117
+ marketId: this.marketId,
118
+ collateralCoinType: this.marketData.collateralCoinType,
119
+ collateral: 0,
120
+ baseAssetAmount: 0,
121
+ quoteAssetNotionalAmount: 0,
122
+ cumFundingRateLong: this.marketData.marketState.cumFundingRateLong,
123
+ cumFundingRateShort: this.marketData.marketState.cumFundingRateShort,
124
+ asksQuantity: 0,
125
+ bidsQuantity: 0,
126
+ pendingOrders: [],
127
+ makerFee: 1, // 100%
128
+ takerFee: 1, // 100%
129
+ leverage: 1,
130
+ };
131
+ };
105
132
  this.marketId = marketData.objectId;
133
+ this.indexPrice = marketData.indexPrice;
134
+ this.collateralPrice = marketData.collateralPrice;
106
135
  this.collateralCoinType = marketData.collateralCoinType;
107
136
  this.marketParams = marketData.marketParams;
108
137
  this.marketState = marketData.marketState;
@@ -111,24 +140,59 @@ class PerpetualsMarket extends caller_1.Caller {
111
140
  // Inspections
112
141
  // =========================================================================
113
142
  // NOTE: should this be entirely removed since data already in orderbook function ?
114
- getOrderbookPrice() {
115
- return this.fetchApi("orderbook-price");
116
- }
117
- get24hrVolume() {
118
- return this.fetchApi("24hr-volume");
143
+ getOrderbookMidPrice() {
144
+ return this.fetchApi("market/orderbook-price", {
145
+ marketId: this.marketId,
146
+ });
119
147
  }
120
- getPrice24hrsAgo() {
121
- return this.fetchApi("price-24hrs-ago");
148
+ get24hrStats() {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ const stats = yield new perpetuals_1.Perpetuals(this.config).getMarkets24hrStats({
151
+ marketIds: [this.marketId],
152
+ });
153
+ return stats[0];
154
+ });
122
155
  }
123
156
  getOrderbook() {
124
- return this.fetchApi("orderbook");
157
+ return __awaiter(this, void 0, void 0, function* () {
158
+ // TODO: create own endpoint for just orderbook
159
+ // return this.fetchApi<PerpetualsOrderbook>("market/orderbook");
160
+ const marketDatas = yield this.fetchApi("markets", {
161
+ marketIds: [this.marketId],
162
+ collateralCoinType: this.collateralCoinType,
163
+ withOrderbook: true,
164
+ });
165
+ return marketDatas[0].orderbook;
166
+ });
167
+ }
168
+ getPlaceMarketOrderPreview(inputs, abortSignal) {
169
+ return __awaiter(this, void 0, void 0, function* () {
170
+ return this.fetchApi("previews/place-market-order", Object.assign(Object.assign({}, inputs), { collateralCoinType: this.collateralCoinType, accountId: undefined }), abortSignal);
171
+ });
172
+ }
173
+ getPlaceLimitOrderPreview(inputs, abortSignal) {
174
+ return __awaiter(this, void 0, void 0, function* () {
175
+ return this.fetchApi("previews/place-limit-order", Object.assign(Object.assign({}, inputs), { collateralCoinType: this.collateralCoinType, accountId: undefined }), abortSignal);
176
+ });
125
177
  }
126
178
  // =========================================================================
127
179
  // Trade History
128
180
  // =========================================================================
129
181
  getTradeHistory(inputs) {
130
182
  return __awaiter(this, void 0, void 0, function* () {
131
- return this.fetchApi(`trade-history`, inputs);
183
+ return this.fetchApi("market/trade-history", Object.assign(Object.assign({}, inputs), { marketId: this.marketId }));
184
+ });
185
+ }
186
+ // =========================================================================
187
+ // Prices
188
+ // =========================================================================
189
+ getPrices() {
190
+ return __awaiter(this, void 0, void 0, function* () {
191
+ return (yield new perpetuals_1.Perpetuals(this.config
192
+ // this.Provider
193
+ ).getPrices({
194
+ marketIds: [this.marketId],
195
+ }))[0];
132
196
  });
133
197
  }
134
198
  // =========================================================================
@@ -141,22 +205,13 @@ class PerpetualsMarket extends caller_1.Caller {
141
205
  return perpetuals_1.Perpetuals.lotOrTickSizeToNumber(this.marketParams.tickSize);
142
206
  }
143
207
  maxLeverage() {
144
- return (1 /
145
- __1.Casting.IFixed.numberFromIFixed(this.marketParams.marginRatioInitial));
208
+ return 1 / this.marketParams.marginRatioInitial;
146
209
  }
147
210
  initialMarginRatio() {
148
- return __1.Casting.IFixed.numberFromIFixed(this.marketParams.marginRatioInitial);
211
+ return this.marketParams.marginRatioInitial;
149
212
  }
150
213
  maintenanceMarginRatio() {
151
- return __1.Casting.IFixed.numberFromIFixed(this.marketParams.marginRatioMaintenance);
152
- }
153
- // =========================================================================
154
- // Helpers
155
- // =========================================================================
156
- orderPrice(inputs) {
157
- const { orderId } = inputs;
158
- const orderPrice = utils_1.PerpetualsOrderUtils.price(orderId);
159
- return this.orderPriceToPrice({ orderPrice });
214
+ return this.marketParams.marginRatioMaintenance;
160
215
  }
161
216
  }
162
217
  exports.PerpetualsMarket = PerpetualsMarket;