aftermath-ts-sdk 1.3.23-perps.21 → 1.3.23-wc-0.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 (120) hide show
  1. package/dist/general/apiHelpers/transactionsApiHelpers.d.ts +0 -3
  2. package/dist/general/apiHelpers/transactionsApiHelpers.d.ts.map +1 -1
  3. package/dist/general/apiHelpers/transactionsApiHelpers.js +0 -12
  4. package/dist/general/providers/aftermath.d.ts +5 -0
  5. package/dist/general/providers/aftermath.d.ts.map +1 -1
  6. package/dist/general/providers/aftermath.js +6 -1
  7. package/dist/general/providers/aftermathApi.d.ts +5 -0
  8. package/dist/general/providers/aftermathApi.d.ts.map +1 -1
  9. package/dist/general/providers/aftermathApi.js +5 -0
  10. package/dist/general/types/castingTypes.d.ts +2 -2
  11. package/dist/general/types/castingTypes.d.ts.map +1 -1
  12. package/dist/general/types/configTypes.d.ts +10 -0
  13. package/dist/general/types/configTypes.d.ts.map +1 -1
  14. package/dist/general/types/generalTypes.d.ts +0 -4
  15. package/dist/general/types/generalTypes.d.ts.map +1 -1
  16. package/dist/general/types/moveErrorsInterface.d.ts +1 -1
  17. package/dist/general/types/moveErrorsInterface.d.ts.map +1 -1
  18. package/dist/general/utils/caller.d.ts +2 -17
  19. package/dist/general/utils/caller.d.ts.map +1 -1
  20. package/dist/general/utils/caller.js +2 -35
  21. package/dist/general/utils/casting.d.ts +5 -4
  22. package/dist/general/utils/casting.d.ts.map +1 -1
  23. package/dist/general/utils/casting.js +5 -4
  24. package/dist/general/utils/helpers.d.ts +0 -1
  25. package/dist/general/utils/helpers.d.ts.map +1 -1
  26. package/dist/general/utils/helpers.js +6 -35
  27. package/dist/general/wallet/wallet.d.ts +1 -1
  28. package/dist/general/wallet/wallet.d.ts.map +1 -1
  29. package/dist/packages/coin/coin.d.ts +1 -1
  30. package/dist/packages/coin/coin.d.ts.map +1 -1
  31. package/dist/packages/coin/coin.js +1 -3
  32. package/dist/packages/farms/api/farmsApiCasting.js +27 -27
  33. package/dist/packages/farms/farms.d.ts +1 -1
  34. package/dist/packages/farms/farms.d.ts.map +1 -1
  35. package/dist/packages/farms/farmsStakedPosition.d.ts +1 -1
  36. package/dist/packages/farms/farmsStakedPosition.d.ts.map +1 -1
  37. package/dist/packages/farms/farmsStakingPool.d.ts +1 -1
  38. package/dist/packages/farms/farmsStakingPool.d.ts.map +1 -1
  39. package/dist/packages/faucet/api/faucetApi.d.ts +17 -9
  40. package/dist/packages/faucet/api/faucetApi.d.ts.map +1 -1
  41. package/dist/packages/faucet/api/faucetApi.js +49 -44
  42. package/dist/packages/faucet/api/faucetApiCasting.d.ts.map +1 -1
  43. package/dist/packages/faucet/api/faucetApiCasting.js +7 -10
  44. package/dist/packages/faucet/api/faucetApiCastingTypes.d.ts +4 -1
  45. package/dist/packages/faucet/api/faucetApiCastingTypes.d.ts.map +1 -1
  46. package/dist/packages/faucet/faucet.d.ts +1 -1
  47. package/dist/packages/faucet/faucet.d.ts.map +1 -1
  48. package/dist/packages/faucet/faucet.js +1 -1
  49. package/dist/packages/faucet/faucetTypes.d.ts +3 -2
  50. package/dist/packages/faucet/faucetTypes.d.ts.map +1 -1
  51. package/dist/packages/leveragedStaking/api/leveragedStakingApiCasting.js +3 -3
  52. package/dist/packages/multisig/multisig.d.ts +1 -1
  53. package/dist/packages/multisig/multisig.d.ts.map +1 -1
  54. package/dist/packages/nftAmm/nftAmm.d.ts +1 -1
  55. package/dist/packages/nftAmm/nftAmm.d.ts.map +1 -1
  56. package/dist/packages/oracle/api/oracleApi.d.ts +21 -0
  57. package/dist/packages/oracle/api/oracleApi.d.ts.map +1 -0
  58. package/dist/packages/oracle/api/oracleApi.js +76 -0
  59. package/dist/packages/oracle/api/oracleApiCasting.d.ts +6 -0
  60. package/dist/packages/oracle/api/oracleApiCasting.d.ts.map +1 -0
  61. package/dist/packages/oracle/api/oracleApiCasting.js +25 -0
  62. package/dist/packages/oracle/oracle.d.ts +15 -0
  63. package/dist/packages/oracle/oracle.d.ts.map +1 -0
  64. package/dist/packages/oracle/oracle.js +46 -0
  65. package/dist/packages/oracle/oracleCastingTypes.d.ts +11 -0
  66. package/dist/packages/oracle/oracleCastingTypes.d.ts.map +1 -0
  67. package/dist/packages/oracle/oracleCastingTypes.js +2 -0
  68. package/dist/packages/oracle/oracleTypes.d.ts +10 -0
  69. package/dist/packages/oracle/oracleTypes.d.ts.map +1 -0
  70. package/dist/packages/oracle/oracleTypes.js +2 -0
  71. package/dist/packages/perpetuals/api/perpetualsApi.d.ts +203 -11
  72. package/dist/packages/perpetuals/api/perpetualsApi.d.ts.map +1 -1
  73. package/dist/packages/perpetuals/api/perpetualsApi.js +615 -924
  74. package/dist/packages/perpetuals/api/perpetualsApiCasting.d.ts +21 -10
  75. package/dist/packages/perpetuals/api/perpetualsApiCasting.d.ts.map +1 -1
  76. package/dist/packages/perpetuals/api/perpetualsApiCasting.js +238 -260
  77. package/dist/packages/perpetuals/index.d.ts +0 -1
  78. package/dist/packages/perpetuals/index.d.ts.map +1 -1
  79. package/dist/packages/perpetuals/index.js +0 -1
  80. package/dist/packages/perpetuals/perpetuals.d.ts +14 -83
  81. package/dist/packages/perpetuals/perpetuals.d.ts.map +1 -1
  82. package/dist/packages/perpetuals/perpetuals.js +59 -158
  83. package/dist/packages/perpetuals/perpetualsAccount.d.ts +86 -158
  84. package/dist/packages/perpetuals/perpetualsAccount.d.ts.map +1 -1
  85. package/dist/packages/perpetuals/perpetualsAccount.js +141 -481
  86. package/dist/packages/perpetuals/perpetualsCastingTypes.d.ts +149 -82
  87. package/dist/packages/perpetuals/perpetualsCastingTypes.d.ts.map +1 -1
  88. package/dist/packages/perpetuals/perpetualsMarket.d.ts +20 -55
  89. package/dist/packages/perpetuals/perpetualsMarket.d.ts.map +1 -1
  90. package/dist/packages/perpetuals/perpetualsMarket.js +57 -114
  91. package/dist/packages/perpetuals/perpetualsTypes.d.ts +280 -586
  92. package/dist/packages/perpetuals/perpetualsTypes.d.ts.map +1 -1
  93. package/dist/packages/perpetuals/perpetualsTypes.js +81 -17
  94. package/dist/packages/pools/api/poolsApiCasting.js +3 -3
  95. package/dist/packages/pools/pool.d.ts +1 -1
  96. package/dist/packages/pools/pool.d.ts.map +1 -1
  97. package/dist/packages/pools/pools.d.ts +1 -1
  98. package/dist/packages/pools/pools.d.ts.map +1 -1
  99. package/dist/packages/referralVault/referralVault.d.ts +1 -1
  100. package/dist/packages/referralVault/referralVault.d.ts.map +1 -1
  101. package/dist/packages/router/api/routerApiCasting.js +1 -1
  102. package/dist/packages/staking/api/stakingApiCasting.js +3 -3
  103. package/dist/packages/staking/staking.d.ts +1 -1
  104. package/dist/packages/staking/staking.d.ts.map +1 -1
  105. package/dist/packages/sui/sui.d.ts +1 -1
  106. package/dist/packages/sui/sui.d.ts.map +1 -1
  107. package/dist/packages/suiFrens/api/suiFrensApiCasting.js +4 -4
  108. package/dist/packages/suiFrens/stakedSuiFren.d.ts +1 -1
  109. package/dist/packages/suiFrens/stakedSuiFren.d.ts.map +1 -1
  110. package/dist/packages/suiFrens/suiFren.d.ts +1 -1
  111. package/dist/packages/suiFrens/suiFren.d.ts.map +1 -1
  112. package/dist/packages/suiFrens/suiFrens.d.ts +1 -1
  113. package/dist/packages/suiFrens/suiFrens.d.ts.map +1 -1
  114. package/dist/types.d.ts +1 -0
  115. package/dist/types.d.ts.map +1 -1
  116. package/dist/types.js +1 -0
  117. package/package.json +2 -2
  118. package/dist/packages/perpetuals/perpetualsVault.d.ts +0 -109
  119. package/dist/packages/perpetuals/perpetualsVault.d.ts.map +0 -1
  120. package/dist/packages/perpetuals/perpetualsVault.js +0 -290
@@ -1,7 +1,32 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
2
22
  Object.defineProperty(exports, "__esModule", { value: true });
3
23
  exports.PerpetualsApi = void 0;
24
+ const transactions_1 = require("@mysten/sui/transactions");
25
+ const utils_1 = require("../../../general/utils");
26
+ const sui_1 = require("../../sui");
4
27
  const eventsApiHelpers_1 = require("../../../general/apiHelpers/eventsApiHelpers");
28
+ const transactionsApiHelpers_1 = require("../../../general/apiHelpers/transactionsApiHelpers");
29
+ const bcs_1 = require("@mysten/sui/bcs");
5
30
  class PerpetualsApi {
6
31
  // =========================================================================
7
32
  // Constructor
@@ -9,434 +34,205 @@ class PerpetualsApi {
9
34
  constructor(Provider) {
10
35
  this.Provider = Provider;
11
36
  // =========================================================================
12
- // Objects
13
- // =========================================================================
14
- // public fetchMarket = async (inputs: {
15
- // marketId: PerpetualsMarketId;
16
- // collateralCoinType: CoinType;
17
- // }): Promise<PerpetualsMarketData> => {
18
- // const { collateralCoinType } = inputs;
19
- // return this.Provider.Objects().fetchCastObject({
20
- // objectId: inputs.marketId,
21
- // objectFromSuiObjectResponse: (data) =>
22
- // Casting.perpetuals.clearingHouseFromOnChain(
23
- // data,
24
- // collateralCoinType
25
- // ),
26
- // });
27
- // };
28
- // =========================================================================
29
- // Inspections
30
- // =========================================================================
31
- // public fetchOrderbookPrice = async (inputs: {
32
- // collateralCoinType: ObjectId;
33
- // marketId: PerpetualsMarketId;
34
- // // marketInitialSharedVersion: ObjectVersion;
35
- // }): Promise<number> => {
36
- // const {
37
- // collateralCoinType,
38
- // marketId,
39
- // // marketInitialSharedVersion
40
- // } = inputs;
41
- // const tx = new Transaction();
42
- // this.getBookPriceTx({
43
- // tx,
44
- // marketId,
45
- // collateralCoinType,
46
- // // marketInitialSharedVersion,
47
- // });
48
- // const bytes =
49
- // await this.Provider.Inspections().fetchFirstBytesFromTxOutput({
50
- // tx,
51
- // });
52
- // return PerpetualsApiCasting.orderbookPriceFromBytes(bytes);
53
- // };
54
- // public fetchAllMarketIds = async (inputs: {
55
- // collateralCoinType: CoinType;
56
- // }): Promise<PerpetualsMarketId[]> => {
57
- // const { collateralCoinType } = inputs;
58
- // const marketIdsData = await this.Provider.indexerCaller.fetchIndexer<
59
- // {
60
- // marketId: ObjectId;
61
- // }[]
62
- // >(
63
- // `perpetuals/markets/${Helpers.addLeadingZeroesToType(
64
- // collateralCoinType
65
- // )}`
66
- // );
67
- // return marketIdsData.map((data) =>
68
- // Helpers.addLeadingZeroesToType(data.marketId)
69
- // );
70
- // };
71
- // =========================================================================
72
37
  // Transaction Commands
73
38
  // =========================================================================
74
- // public depositCollateralTx = (
75
- // inputs: {
76
- // tx: Transaction;
77
- // collateralCoinType: CoinType;
78
- // accountCapId: ObjectId | TransactionArgument;
79
- // } & (
80
- // | {
81
- // coinId: ObjectId | TransactionArgument;
82
- // }
83
- // | {
84
- // coinBytes: Uint8Array;
85
- // }
86
- // )
87
- // ) => {
88
- // const { tx, collateralCoinType, accountCapId } = inputs;
89
- // return tx.moveCall({
90
- // target: Helpers.transactions.createTxTarget(
91
- // this.addresses.packages.perpetuals,
92
- // PerpetualsApi.constants.moduleNames.interface,
93
- // "deposit_collateral"
94
- // ),
95
- // typeArguments: [collateralCoinType],
96
- // arguments: [
97
- // typeof accountCapId === "string"
98
- // ? tx.object(accountCapId)
99
- // : accountCapId,
100
- // "coinBytes" in inputs
101
- // ? tx.pure(inputs.coinBytes)
102
- // : typeof inputs.coinId === "string"
103
- // ? tx.object(inputs.coinId)
104
- // : inputs.coinId,
105
- // ],
106
- // });
107
- // };
108
- // public allocateCollateralTx = (inputs: {
109
- // tx: Transaction;
110
- // packageId: PackageId;
111
- // collateralCoinType: CoinType;
112
- // accountCapId: ObjectId | TransactionArgument;
113
- // marketId: PerpetualsMarketId;
114
- // marketInitialSharedVersion: ObjectVersion;
115
- // amount: Balance;
116
- // }) => {
117
- // const { tx, collateralCoinType, accountCapId, marketId, amount } =
118
- // inputs;
119
- // return tx.moveCall({
120
- // target: Helpers.transactions.createTxTarget(
121
- // inputs.packageId,
122
- // PerpetualsApi.constants.moduleNames.interface,
123
- // "allocate_collateral"
124
- // ),
125
- // typeArguments: [collateralCoinType],
126
- // arguments: [
127
- // tx.sharedObjectRef({
128
- // objectId: marketId,
129
- // initialSharedVersion: inputs.marketInitialSharedVersion,
130
- // mutable: true,
131
- // }),
132
- // typeof accountCapId === "string"
133
- // ? tx.object(accountCapId)
134
- // : accountCapId,
135
- // tx.pure.u64(amount),
136
- // ],
137
- // });
138
- // };
139
- // public deallocateCollateralTx = (inputs: {
140
- // tx: Transaction;
141
- // packageId: PackageId;
142
- // collateralCoinType: CoinType;
143
- // accountCapId: ObjectId;
144
- // basePriceFeedId: ObjectId;
145
- // collateralPriceFeedId: ObjectId;
146
- // marketId: PerpetualsMarketId;
147
- // marketInitialSharedVersion: ObjectVersion;
148
- // amount: Balance;
149
- // }) => {
150
- // const { tx, collateralCoinType, accountCapId, marketId, amount } =
151
- // inputs;
152
- // return tx.moveCall({
153
- // target: Helpers.transactions.createTxTarget(
154
- // inputs.packageId,
155
- // PerpetualsApi.constants.moduleNames.interface,
156
- // "deallocate_collateral"
157
- // ),
158
- // typeArguments: [collateralCoinType],
159
- // arguments: [
160
- // tx.sharedObjectRef({
161
- // objectId: marketId,
162
- // initialSharedVersion: inputs.marketInitialSharedVersion,
163
- // mutable: true,
164
- // }),
165
- // tx.object(accountCapId),
166
- // tx.object(inputs.basePriceFeedId),
167
- // tx.object(inputs.collateralPriceFeedId),
168
- // tx.object(Sui.constants.addresses.suiClockId),
169
- // tx.pure.u64(amount),
170
- // ],
171
- // });
172
- // };
173
- // public createMarketPositionTx = (inputs: {
174
- // tx: Transaction;
175
- // packageId: PackageId;
176
- // collateralCoinType: CoinType;
177
- // accountCapId: ObjectId | TransactionArgument;
178
- // marketId: PerpetualsMarketId;
179
- // marketInitialSharedVersion: ObjectVersion;
180
- // }) => {
181
- // const { tx, collateralCoinType, accountCapId, marketId } = inputs;
182
- // return tx.moveCall({
183
- // target: Helpers.transactions.createTxTarget(
184
- // inputs.packageId,
185
- // PerpetualsApi.constants.moduleNames.interface,
186
- // "create_market_position"
187
- // ),
188
- // typeArguments: [collateralCoinType],
189
- // arguments: [
190
- // tx.sharedObjectRef({
191
- // objectId: marketId,
192
- // initialSharedVersion: inputs.marketInitialSharedVersion,
193
- // mutable: true,
194
- // }),
195
- // typeof accountCapId === "string"
196
- // ? tx.object(accountCapId)
197
- // : accountCapId,
198
- // ],
199
- // });
200
- // };
201
- // public shareClearingHouseTx = (inputs: {
202
- // tx: Transaction;
203
- // packageId: PackageId;
204
- // collateralCoinType: CoinType;
205
- // marketId: PerpetualsMarketId | TransactionArgument;
206
- // }) => {
207
- // const { tx, collateralCoinType, marketId } = inputs;
208
- // return tx.moveCall({
209
- // target: Helpers.transactions.createTxTarget(
210
- // inputs.packageId,
211
- // PerpetualsApi.constants.moduleNames.interface,
212
- // "share_clearing_house"
213
- // ),
214
- // typeArguments: [collateralCoinType],
215
- // arguments: [
216
- // typeof marketId === "string" ? tx.object(marketId) : marketId,
217
- // ],
218
- // });
219
- // };
220
- // public startSessionTx = (inputs: {
221
- // tx: Transaction;
222
- // packageId: PackageId;
223
- // collateralCoinType: CoinType;
224
- // accountCapId: ObjectId | TransactionArgument;
225
- // basePriceFeedId: ObjectId;
226
- // collateralPriceFeedId: ObjectId;
227
- // marketId: PerpetualsMarketId;
228
- // marketInitialSharedVersion: ObjectVersion;
229
- // }) /* SessionHotPotato<T> */ => {
230
- // const { tx, collateralCoinType, accountCapId, marketId } = inputs;
231
- // return tx.moveCall({
232
- // target: Helpers.transactions.createTxTarget(
233
- // inputs.packageId,
234
- // PerpetualsApi.constants.moduleNames.interface,
235
- // "start_session"
236
- // ),
237
- // typeArguments: [collateralCoinType],
238
- // arguments: [
239
- // tx.sharedObjectRef({
240
- // objectId: marketId,
241
- // initialSharedVersion: inputs.marketInitialSharedVersion,
242
- // mutable: true,
243
- // }),
244
- // typeof accountCapId === "string"
245
- // ? tx.object(accountCapId)
246
- // : accountCapId,
247
- // tx.object(inputs.basePriceFeedId),
248
- // tx.object(inputs.collateralPriceFeedId),
249
- // tx.object(Sui.constants.addresses.suiClockId),
250
- // ],
251
- // });
252
- // };
253
- // public endSessionTx = (inputs: {
254
- // tx: Transaction;
255
- // packageId: PackageId;
256
- // collateralCoinType: CoinType;
257
- // sessionPotatoId: ObjectId | TransactionArgument;
258
- // }) /* ClearingHouse<T> */ => {
259
- // const { tx, collateralCoinType, sessionPotatoId } = inputs;
260
- // return tx.moveCall({
261
- // target: Helpers.transactions.createTxTarget(
262
- // inputs.packageId,
263
- // PerpetualsApi.constants.moduleNames.interface,
264
- // "end_session"
265
- // ),
266
- // typeArguments: [collateralCoinType],
267
- // arguments: [
268
- // typeof sessionPotatoId === "string"
269
- // ? tx.object(sessionPotatoId)
270
- // : sessionPotatoId,
271
- // ],
272
- // });
273
- // };
274
- // public placeMarketOrderTx = (inputs: {
275
- // tx: Transaction;
276
- // packageId: PackageId;
277
- // collateralCoinType: CoinType;
278
- // sessionPotatoId: ObjectId | TransactionArgument;
279
- // side: PerpetualsOrderSide;
280
- // size: bigint;
281
- // }) => {
282
- // const { tx, collateralCoinType, sessionPotatoId, side, size } = inputs;
283
- // return tx.moveCall({
284
- // target: Helpers.transactions.createTxTarget(
285
- // inputs.packageId,
286
- // PerpetualsApi.constants.moduleNames.interface,
287
- // "place_market_order"
288
- // ),
289
- // typeArguments: [collateralCoinType],
290
- // arguments: [
291
- // typeof sessionPotatoId === "string"
292
- // ? tx.object(sessionPotatoId)
293
- // : sessionPotatoId,
294
- // tx.pure.bool(Boolean(side)),
295
- // tx.pure.u64(size),
296
- // ],
297
- // });
298
- // };
299
- // public placeLimitOrderTx = (inputs: {
300
- // tx: Transaction;
301
- // packageId: PackageId;
302
- // collateralCoinType: CoinType;
303
- // sessionPotatoId: ObjectId | TransactionArgument;
304
- // side: PerpetualsOrderSide;
305
- // size: bigint;
306
- // price: bigint;
307
- // orderType: PerpetualsOrderType;
308
- // }) => {
309
- // const {
310
- // tx,
311
- // collateralCoinType,
312
- // sessionPotatoId,
313
- // side,
314
- // size,
315
- // price,
316
- // orderType,
317
- // } = inputs;
318
- // return tx.moveCall({
319
- // target: Helpers.transactions.createTxTarget(
320
- // inputs.packageId,
321
- // PerpetualsApi.constants.moduleNames.interface,
322
- // "place_limit_order"
323
- // ),
324
- // typeArguments: [collateralCoinType],
325
- // arguments: [
326
- // typeof sessionPotatoId === "string"
327
- // ? tx.object(sessionPotatoId)
328
- // : sessionPotatoId,
329
- // tx.pure.bool(Boolean(side)),
330
- // tx.pure.u64(size),
331
- // tx.pure.u64(price),
332
- // tx.pure.u64(BigInt(orderType)),
333
- // ],
334
- // });
335
- // };
336
- // public cancelOrdersTx = (inputs: {
337
- // tx: Transaction;
338
- // packageId: PackageId;
339
- // collateralCoinType: CoinType;
340
- // accountCapId: ObjectId;
341
- // marketId: PerpetualsMarketId;
342
- // marketInitialSharedVersion: ObjectVersion;
343
- // orderIds: PerpetualsOrderId[];
344
- // }) => {
345
- // const { tx, collateralCoinType, accountCapId, marketId, orderIds } =
346
- // inputs;
347
- // return tx.moveCall({
348
- // target: Helpers.transactions.createTxTarget(
349
- // inputs.packageId,
350
- // PerpetualsApi.constants.moduleNames.interface,
351
- // "cancel_orders"
352
- // ),
353
- // typeArguments: [collateralCoinType],
354
- // arguments: [
355
- // tx.sharedObjectRef({
356
- // objectId: marketId,
357
- // initialSharedVersion: inputs.marketInitialSharedVersion,
358
- // mutable: true,
359
- // }),
360
- // tx.object(accountCapId),
361
- // tx.pure(bcs.vector(bcs.u128()).serialize(orderIds)),
362
- // ],
363
- // });
364
- // };
365
- // public reduceOrdersTx = (inputs: {
366
- // tx: Transaction;
367
- // packageId: PackageId;
368
- // collateralCoinType: CoinType;
369
- // accountCapId: ObjectId;
370
- // marketId: PerpetualsMarketId;
371
- // marketInitialSharedVersion: ObjectVersion;
372
- // orderIds: PerpetualsOrderId[];
373
- // sizesToSubtract: bigint[];
374
- // }) => {
375
- // const {
376
- // tx,
377
- // packageId,
378
- // collateralCoinType,
379
- // accountCapId,
380
- // marketId,
381
- // orderIds,
382
- // sizesToSubtract,
383
- // } = inputs;
384
- // return tx.moveCall({
385
- // target: Helpers.transactions.createTxTarget(
386
- // packageId,
387
- // PerpetualsApi.constants.moduleNames.interface,
388
- // "reduce_orders"
389
- // ),
390
- // typeArguments: [collateralCoinType],
391
- // arguments: [
392
- // tx.sharedObjectRef({
393
- // objectId: marketId,
394
- // initialSharedVersion: inputs.marketInitialSharedVersion,
395
- // mutable: true,
396
- // }),
397
- // tx.object(accountCapId),
398
- // tx.pure(bcs.vector(bcs.u128()).serialize(orderIds)),
399
- // tx.pure(bcs.vector(bcs.u64()).serialize(sizesToSubtract)),
400
- // ],
401
- // });
402
- // };
403
- // public withdrawCollateralTx = (inputs: {
404
- // tx: Transaction;
405
- // collateralCoinType: CoinType;
406
- // accountCapId: ObjectId | TransactionArgument;
407
- // amount: Balance;
408
- // }): TransactionArgument => {
409
- // const { tx, collateralCoinType, accountCapId, amount } = inputs;
410
- // return tx.moveCall({
411
- // target: Helpers.transactions.createTxTarget(
412
- // this.addresses.packages.perpetuals,
413
- // PerpetualsApi.constants.moduleNames.interface,
414
- // "withdraw_collateral"
415
- // ),
416
- // typeArguments: [collateralCoinType],
417
- // arguments: [
418
- // typeof accountCapId === "string"
419
- // ? tx.object(accountCapId)
420
- // : accountCapId,
421
- // tx.pure.u64(amount),
422
- // ],
423
- // });
424
- // };
425
- // public createAccountTx = (inputs: {
426
- // tx: Transaction;
427
- // collateralCoinType: CoinType;
428
- // }) /* Account<T> */ => {
429
- // const { tx, collateralCoinType } = inputs;
430
- // return tx.moveCall({
431
- // target: Helpers.transactions.createTxTarget(
432
- // this.addresses.packages.perpetuals,
433
- // PerpetualsApi.constants.moduleNames.interface,
434
- // "create_account"
435
- // ),
436
- // typeArguments: [collateralCoinType],
437
- // arguments: [tx.object(this.addresses.objects.registry)],
438
- // });
439
- // };
39
+ this.depositCollateralTx = (inputs) => {
40
+ const { tx, collateralCoinType, accountCapId } = inputs;
41
+ return tx.moveCall({
42
+ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.perpetuals.packages.perpetuals, PerpetualsApi.constants.moduleNames.interface, "deposit_collateral"),
43
+ typeArguments: [collateralCoinType],
44
+ arguments: [
45
+ typeof accountCapId === "string"
46
+ ? tx.object(accountCapId)
47
+ : accountCapId,
48
+ "coinBytes" in inputs
49
+ ? tx.pure(inputs.coinBytes)
50
+ : typeof inputs.coinId === "string"
51
+ ? tx.object(inputs.coinId)
52
+ : inputs.coinId,
53
+ ],
54
+ });
55
+ };
56
+ this.allocateCollateralTx = (inputs) => {
57
+ const { tx, collateralCoinType, accountCapId, marketId, amount } = inputs;
58
+ return tx.moveCall({
59
+ target: utils_1.Helpers.transactions.createTxTarget(inputs.packageId, PerpetualsApi.constants.moduleNames.interface, "allocate_collateral"),
60
+ typeArguments: [collateralCoinType],
61
+ arguments: [
62
+ tx.sharedObjectRef({
63
+ objectId: marketId,
64
+ initialSharedVersion: inputs.marketInitialSharedVersion,
65
+ mutable: true,
66
+ }),
67
+ typeof accountCapId === "string"
68
+ ? tx.object(accountCapId)
69
+ : accountCapId,
70
+ tx.pure.u64(amount),
71
+ ],
72
+ });
73
+ };
74
+ this.deallocateCollateralTx = (inputs) => {
75
+ const { tx, collateralCoinType, accountCapId, marketId, amount } = inputs;
76
+ return tx.moveCall({
77
+ target: utils_1.Helpers.transactions.createTxTarget(inputs.packageId, PerpetualsApi.constants.moduleNames.interface, "deallocate_collateral"),
78
+ typeArguments: [collateralCoinType],
79
+ arguments: [
80
+ tx.sharedObjectRef({
81
+ objectId: marketId,
82
+ initialSharedVersion: inputs.marketInitialSharedVersion,
83
+ mutable: true,
84
+ }),
85
+ tx.object(accountCapId),
86
+ tx.object(inputs.basePriceFeedId),
87
+ tx.object(inputs.collateralPriceFeedId),
88
+ tx.object(sui_1.Sui.constants.addresses.suiClockId),
89
+ tx.pure.u64(amount),
90
+ ],
91
+ });
92
+ };
93
+ this.createMarketPositionTx = (inputs) => {
94
+ const { tx, collateralCoinType, accountCapId, marketId } = inputs;
95
+ return tx.moveCall({
96
+ target: utils_1.Helpers.transactions.createTxTarget(inputs.packageId, PerpetualsApi.constants.moduleNames.interface, "create_market_position"),
97
+ typeArguments: [collateralCoinType],
98
+ arguments: [
99
+ tx.sharedObjectRef({
100
+ objectId: marketId,
101
+ initialSharedVersion: inputs.marketInitialSharedVersion,
102
+ mutable: true,
103
+ }),
104
+ typeof accountCapId === "string"
105
+ ? tx.object(accountCapId)
106
+ : accountCapId,
107
+ ],
108
+ });
109
+ };
110
+ this.shareClearingHouseTx = (inputs) => {
111
+ const { tx, collateralCoinType, marketId } = inputs;
112
+ return tx.moveCall({
113
+ target: utils_1.Helpers.transactions.createTxTarget(inputs.packageId, PerpetualsApi.constants.moduleNames.interface, "share_clearing_house"),
114
+ typeArguments: [collateralCoinType],
115
+ arguments: [
116
+ typeof marketId === "string" ? tx.object(marketId) : marketId,
117
+ ],
118
+ });
119
+ };
120
+ this.startSessionTx = (inputs) => {
121
+ const { tx, collateralCoinType, accountCapId, marketId } = inputs;
122
+ return tx.moveCall({
123
+ target: utils_1.Helpers.transactions.createTxTarget(inputs.packageId, PerpetualsApi.constants.moduleNames.interface, "start_session"),
124
+ typeArguments: [collateralCoinType],
125
+ arguments: [
126
+ tx.sharedObjectRef({
127
+ objectId: marketId,
128
+ initialSharedVersion: inputs.marketInitialSharedVersion,
129
+ mutable: true,
130
+ }),
131
+ typeof accountCapId === "string"
132
+ ? tx.object(accountCapId)
133
+ : accountCapId,
134
+ tx.object(inputs.basePriceFeedId),
135
+ tx.object(inputs.collateralPriceFeedId),
136
+ tx.object(sui_1.Sui.constants.addresses.suiClockId),
137
+ ],
138
+ });
139
+ };
140
+ this.endSessionTx = (inputs) => {
141
+ const { tx, collateralCoinType, sessionPotatoId } = inputs;
142
+ return tx.moveCall({
143
+ target: utils_1.Helpers.transactions.createTxTarget(inputs.packageId, PerpetualsApi.constants.moduleNames.interface, "end_session"),
144
+ typeArguments: [collateralCoinType],
145
+ arguments: [
146
+ typeof sessionPotatoId === "string"
147
+ ? tx.object(sessionPotatoId)
148
+ : sessionPotatoId,
149
+ ],
150
+ });
151
+ };
152
+ this.placeMarketOrderTx = (inputs) => {
153
+ const { tx, collateralCoinType, sessionPotatoId, side, size } = inputs;
154
+ return tx.moveCall({
155
+ target: utils_1.Helpers.transactions.createTxTarget(inputs.packageId, PerpetualsApi.constants.moduleNames.interface, "place_market_order"),
156
+ typeArguments: [collateralCoinType],
157
+ arguments: [
158
+ typeof sessionPotatoId === "string"
159
+ ? tx.object(sessionPotatoId)
160
+ : sessionPotatoId,
161
+ tx.pure.bool(Boolean(side)),
162
+ tx.pure.u64(size),
163
+ ],
164
+ });
165
+ };
166
+ this.placeLimitOrderTx = (inputs) => {
167
+ const { tx, collateralCoinType, sessionPotatoId, side, size, price, orderType, } = inputs;
168
+ return tx.moveCall({
169
+ target: utils_1.Helpers.transactions.createTxTarget(inputs.packageId, PerpetualsApi.constants.moduleNames.interface, "place_limit_order"),
170
+ typeArguments: [collateralCoinType],
171
+ arguments: [
172
+ typeof sessionPotatoId === "string"
173
+ ? tx.object(sessionPotatoId)
174
+ : sessionPotatoId,
175
+ tx.pure.bool(Boolean(side)),
176
+ tx.pure.u64(size),
177
+ tx.pure.u64(price),
178
+ tx.pure.u64(BigInt(orderType)),
179
+ ],
180
+ });
181
+ };
182
+ this.cancelOrdersTx = (inputs) => {
183
+ const { tx, collateralCoinType, accountCapId, marketId, orderIds } = inputs;
184
+ return tx.moveCall({
185
+ target: utils_1.Helpers.transactions.createTxTarget(inputs.packageId, PerpetualsApi.constants.moduleNames.interface, "cancel_orders"),
186
+ typeArguments: [collateralCoinType],
187
+ arguments: [
188
+ tx.sharedObjectRef({
189
+ objectId: marketId,
190
+ initialSharedVersion: inputs.marketInitialSharedVersion,
191
+ mutable: true,
192
+ }),
193
+ tx.object(accountCapId),
194
+ tx.pure(bcs_1.bcs.vector(bcs_1.bcs.u128()).serialize(orderIds)),
195
+ ],
196
+ });
197
+ };
198
+ this.reduceOrdersTx = (inputs) => {
199
+ const { tx, packageId, collateralCoinType, accountCapId, marketId, orderIds, sizesToSubtract, } = inputs;
200
+ return tx.moveCall({
201
+ target: utils_1.Helpers.transactions.createTxTarget(packageId, PerpetualsApi.constants.moduleNames.interface, "reduce_orders"),
202
+ typeArguments: [collateralCoinType],
203
+ arguments: [
204
+ tx.sharedObjectRef({
205
+ objectId: marketId,
206
+ initialSharedVersion: inputs.marketInitialSharedVersion,
207
+ mutable: true,
208
+ }),
209
+ tx.object(accountCapId),
210
+ tx.pure(bcs_1.bcs.vector(bcs_1.bcs.u128()).serialize(orderIds)),
211
+ tx.pure(bcs_1.bcs.vector(bcs_1.bcs.u64()).serialize(sizesToSubtract)),
212
+ ],
213
+ });
214
+ };
215
+ this.withdrawCollateralTx = (inputs) => {
216
+ const { tx, collateralCoinType, accountCapId, amount } = inputs;
217
+ return tx.moveCall({
218
+ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.perpetuals.packages.perpetuals, PerpetualsApi.constants.moduleNames.interface, "withdraw_collateral"),
219
+ typeArguments: [collateralCoinType],
220
+ arguments: [
221
+ typeof accountCapId === "string"
222
+ ? tx.object(accountCapId)
223
+ : accountCapId,
224
+ tx.pure.u64(amount),
225
+ ],
226
+ });
227
+ };
228
+ this.createAccountTx = (inputs) => {
229
+ const { tx, collateralCoinType } = inputs;
230
+ return tx.moveCall({
231
+ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.perpetuals.packages.perpetuals, PerpetualsApi.constants.moduleNames.interface, "create_account"),
232
+ typeArguments: [collateralCoinType],
233
+ arguments: [tx.object(this.addresses.perpetuals.objects.registry)],
234
+ });
235
+ };
440
236
  // public getHotPotatoFieldsTx = (
441
237
  // inputs: {
442
238
  // tx: Transaction;
@@ -481,372 +277,313 @@ class PerpetualsApi {
481
277
  // ],
482
278
  // });
483
279
  // };
484
- // public getPositionTx = (inputs: {
485
- // tx: Transaction;
486
- // packageId: PackageId;
487
- // collateralCoinType: CoinType;
488
- // accountId: PerpetualsAccountId;
489
- // marketId: PerpetualsMarketId;
490
- // marketInitialSharedVersion: ObjectVersion;
491
- // }) /* Position */ => {
492
- // const { tx, marketId, collateralCoinType } = inputs;
493
- // return tx.moveCall({
494
- // target: Helpers.transactions.createTxTarget(
495
- // inputs.packageId,
496
- // PerpetualsApi.constants.moduleNames.clearingHouse,
497
- // "get_position"
498
- // ),
499
- // typeArguments: [collateralCoinType],
500
- // arguments: [
501
- // tx.sharedObjectRef({
502
- // objectId: marketId,
503
- // initialSharedVersion: inputs.marketInitialSharedVersion,
504
- // mutable: false,
505
- // }),
506
- // tx.pure.u64(inputs.accountId),
507
- // ],
508
- // });
509
- // };
510
- // public getOrderbookTx = (inputs: {
511
- // tx: Transaction;
512
- // packageId: PackageId;
513
- // collateralCoinType: CoinType;
514
- // marketId: PerpetualsMarketId;
515
- // }) /* Orderbook */ => {
516
- // const { tx, collateralCoinType } = inputs;
517
- // return tx.moveCall({
518
- // target: Helpers.transactions.createTxTarget(
519
- // inputs.packageId,
520
- // PerpetualsApi.constants.moduleNames.clearingHouse,
521
- // "get_orderbook"
522
- // ),
523
- // typeArguments: [collateralCoinType],
524
- // arguments: [tx.object(inputs.marketId)],
525
- // });
526
- // };
527
- // public getBookPriceTx = (inputs: {
528
- // tx: Transaction;
529
- // packageId: PackageId;
530
- // marketId: PerpetualsMarketId;
531
- // // marketInitialSharedVersion: ObjectVersion;
532
- // collateralCoinType: CoinType;
533
- // }) /* Option<u256> */ => {
534
- // const { tx, marketId, collateralCoinType } = inputs;
535
- // return tx.moveCall({
536
- // target: Helpers.transactions.createTxTarget(
537
- // inputs.packageId,
538
- // PerpetualsApi.constants.moduleNames.clearingHouse,
539
- // "get_book_price"
540
- // ),
541
- // typeArguments: [collateralCoinType],
542
- // arguments: [
543
- // tx.object(marketId),
544
- // // tx.sharedObjectRef({
545
- // // objectId: marketId,
546
- // // initialSharedVersion: inputs.marketInitialSharedVersion,
547
- // // mutable: false,
548
- // // }),
549
- // ],
550
- // });
551
- // };
552
- // public getBestPriceTx = (inputs: {
553
- // tx: Transaction;
554
- // packageId: PackageId;
555
- // marketId: PerpetualsMarketId;
556
- // marketInitialSharedVersion: ObjectVersion;
557
- // side: PerpetualsOrderSide;
558
- // collateralCoinType: CoinType;
559
- // }) /* Option<u256> */ => {
560
- // const { tx, marketId, collateralCoinType } = inputs;
561
- // return tx.moveCall({
562
- // target: Helpers.transactions.createTxTarget(
563
- // inputs.packageId,
564
- // PerpetualsApi.constants.moduleNames.clearingHouse,
565
- // "get_best_price"
566
- // ),
567
- // typeArguments: [collateralCoinType],
568
- // arguments: [
569
- // tx.sharedObjectRef({
570
- // objectId: marketId,
571
- // initialSharedVersion: inputs.marketInitialSharedVersion,
572
- // mutable: false,
573
- // }), // ClearingHouse
574
- // tx.pure.bool(Boolean(inputs.side)), // side
575
- // ],
576
- // });
577
- // };
578
- // public inspectOrdersTx = (inputs: {
579
- // tx: Transaction;
580
- // packageId: PackageId;
581
- // orderbookId: ObjectId | TransactionArgument;
582
- // side: PerpetualsOrderSide;
583
- // fromPrice: number;
584
- // toPrice: number;
585
- // }) /* vector<OrderInfo> */ => {
586
- // const { tx, orderbookId } = inputs;
587
- // return tx.moveCall({
588
- // target: Helpers.transactions.createTxTarget(
589
- // inputs.packageId,
590
- // PerpetualsApi.constants.moduleNames.orderbook,
591
- // "inspect_orders"
592
- // ),
593
- // typeArguments: [],
594
- // arguments: [
595
- // typeof orderbookId === "string"
596
- // ? tx.object(orderbookId)
597
- // : orderbookId, // Orderbook
598
- // tx.pure.bool(Boolean(inputs.side)), // side
599
- // tx.pure.u64(inputs.fromPrice), // price_from
600
- // tx.pure.u64(inputs.toPrice), // price_to
601
- // ],
602
- // });
603
- // };
604
- // public getOrderSizeTx = (inputs: {
605
- // tx: Transaction;
606
- // packageId: PackageId;
607
- // orderbookId: ObjectId | TransactionArgument;
608
- // orderId: PerpetualsOrderId;
609
- // }) /* u64 */ => {
610
- // const { tx, orderbookId } = inputs;
611
- // return tx.moveCall({
612
- // target: Helpers.transactions.createTxTarget(
613
- // inputs.packageId,
614
- // PerpetualsApi.constants.moduleNames.orderbook,
615
- // "get_order_size"
616
- // ),
617
- // typeArguments: [],
618
- // arguments: [
619
- // typeof orderbookId === "string"
620
- // ? tx.object(orderbookId)
621
- // : orderbookId, // Orderbook
622
- // tx.pure.u128(inputs.orderId), // order_id
623
- // ],
624
- // });
625
- // };
280
+ this.placeSLTPOrderTx = (inputs) => {
281
+ throw new Error("TODO");
282
+ // const { tx } = inputs;
283
+ // if ("price" in inputs) {
284
+ // this.placeLimitOrderTx({ ...inputs, tx });
285
+ // } else {
286
+ // this.placeMarketOrderTx({ ...inputs, tx });
287
+ // }
288
+ // const orderType = PerpetualsOrderType.PostOnly;
289
+ // const side =
290
+ // inputs.side === PerpetualsOrderSide.Ask
291
+ // ? PerpetualsOrderSide.Bid
292
+ // : PerpetualsOrderSide.Ask;
293
+ // const orderPrice =
294
+ // "price" in inputs ? inputs.price : inputs.marketPrice;
295
+ // if (
296
+ // "slPrice" in inputs &&
297
+ // ((inputs.side === PerpetualsOrderSide.Ask &&
298
+ // inputs.slPrice > orderPrice) ||
299
+ // (inputs.side === PerpetualsOrderSide.Bid &&
300
+ // inputs.slPrice < orderPrice))
301
+ // ) {
302
+ // this.placeLimitOrderTx({
303
+ // ...inputs,
304
+ // tx,
305
+ // orderType,
306
+ // side,
307
+ // price: inputs.slPrice,
308
+ // });
309
+ // }
310
+ // if (
311
+ // "tpPrice" in inputs &&
312
+ // ((inputs.side === PerpetualsOrderSide.Ask &&
313
+ // inputs.tpPrice < orderPrice) ||
314
+ // (inputs.side === PerpetualsOrderSide.Bid &&
315
+ // inputs.tpPrice > orderPrice))
316
+ // ) {
317
+ // this.placeLimitOrderTx({
318
+ // ...inputs,
319
+ // tx,
320
+ // orderType,
321
+ // side,
322
+ // price: inputs.tpPrice,
323
+ // });
324
+ // }
325
+ };
326
+ this.getPositionTx = (inputs) => {
327
+ const { tx, marketId, collateralCoinType } = inputs;
328
+ return tx.moveCall({
329
+ target: utils_1.Helpers.transactions.createTxTarget(inputs.packageId, PerpetualsApi.constants.moduleNames.clearingHouse, "get_position"),
330
+ typeArguments: [collateralCoinType],
331
+ arguments: [
332
+ tx.sharedObjectRef({
333
+ objectId: marketId,
334
+ initialSharedVersion: inputs.marketInitialSharedVersion,
335
+ mutable: false,
336
+ }),
337
+ tx.pure.u64(inputs.accountId),
338
+ ],
339
+ });
340
+ };
341
+ this.getOrderbookTx = (inputs) => {
342
+ const { tx, collateralCoinType } = inputs;
343
+ return tx.moveCall({
344
+ target: utils_1.Helpers.transactions.createTxTarget(inputs.packageId, PerpetualsApi.constants.moduleNames.clearingHouse, "get_orderbook"),
345
+ typeArguments: [collateralCoinType],
346
+ arguments: [tx.object(inputs.marketId)],
347
+ });
348
+ };
349
+ this.getBookPriceTx = (inputs) => {
350
+ const { tx, marketId, collateralCoinType } = inputs;
351
+ return tx.moveCall({
352
+ target: utils_1.Helpers.transactions.createTxTarget(inputs.packageId, PerpetualsApi.constants.moduleNames.clearingHouse, "get_book_price"),
353
+ typeArguments: [collateralCoinType],
354
+ arguments: [
355
+ tx.object(marketId),
356
+ // tx.sharedObjectRef({
357
+ // objectId: marketId,
358
+ // initialSharedVersion: inputs.marketInitialSharedVersion,
359
+ // mutable: false,
360
+ // }),
361
+ ],
362
+ });
363
+ };
364
+ this.getBestPriceTx = (inputs) => {
365
+ const { tx, marketId, collateralCoinType } = inputs;
366
+ return tx.moveCall({
367
+ target: utils_1.Helpers.transactions.createTxTarget(inputs.packageId, PerpetualsApi.constants.moduleNames.clearingHouse, "get_best_price"),
368
+ typeArguments: [collateralCoinType],
369
+ arguments: [
370
+ tx.sharedObjectRef({
371
+ objectId: marketId,
372
+ initialSharedVersion: inputs.marketInitialSharedVersion,
373
+ mutable: false,
374
+ }), // ClearingHouse
375
+ tx.pure.bool(Boolean(inputs.side)), // side
376
+ ],
377
+ });
378
+ };
379
+ this.inspectOrdersTx = (inputs) => {
380
+ const { tx, orderbookId } = inputs;
381
+ return tx.moveCall({
382
+ target: utils_1.Helpers.transactions.createTxTarget(inputs.packageId, PerpetualsApi.constants.moduleNames.orderbook, "inspect_orders"),
383
+ typeArguments: [],
384
+ arguments: [
385
+ typeof orderbookId === "string"
386
+ ? tx.object(orderbookId)
387
+ : orderbookId, // Orderbook
388
+ tx.pure.bool(Boolean(inputs.side)), // side
389
+ tx.pure.u64(inputs.fromPrice), // price_from
390
+ tx.pure.u64(inputs.toPrice), // price_to
391
+ ],
392
+ });
393
+ };
394
+ this.getOrderSizeTx = (inputs) => {
395
+ const { tx, orderbookId } = inputs;
396
+ return tx.moveCall({
397
+ target: utils_1.Helpers.transactions.createTxTarget(inputs.packageId, PerpetualsApi.constants.moduleNames.orderbook, "get_order_size"),
398
+ typeArguments: [],
399
+ arguments: [
400
+ typeof orderbookId === "string"
401
+ ? tx.object(orderbookId)
402
+ : orderbookId, // Orderbook
403
+ tx.pure.u128(inputs.orderId), // order_id
404
+ ],
405
+ });
406
+ };
626
407
  // =========================================================================
627
408
  // Transaction Builders
628
409
  // =========================================================================
629
- // public fetchBuildDepositCollateralTx = async (
630
- // inputs: ApiPerpetualsDepositCollateralBody
631
- // ): Promise<Transaction> => {
632
- // const tx = new Transaction();
633
- // tx.setSender(inputs.walletAddress);
634
- // const { walletAddress, collateralCoinType, amount } = inputs;
635
- // const coinId = await this.Provider.Coin().fetchCoinWithAmountTx({
636
- // tx,
637
- // walletAddress,
638
- // coinType: collateralCoinType,
639
- // coinAmount: amount,
640
- // });
641
- // this.depositCollateralTx({
642
- // tx,
643
- // coinId,
644
- // ...inputs,
645
- // });
646
- // return tx;
647
- // };
648
- // public buildCancelOrderTx = (
649
- // inputs: ApiPerpetualsCancelOrderBody
650
- // ): Transaction => {
651
- // const {
652
- // packageId,
653
- // orderId,
654
- // marketId,
655
- // marketInitialSharedVersion,
656
- // collateralChange,
657
- // basePriceFeedId,
658
- // collateralPriceFeedId,
659
- // ...otherInputs
660
- // } = inputs;
661
- // return this.buildCancelOrdersTx({
662
- // ...otherInputs,
663
- // orderDatas: [
664
- // {
665
- // packageId,
666
- // orderId,
667
- // marketId,
668
- // marketInitialSharedVersion,
669
- // collateralChange,
670
- // basePriceFeedId,
671
- // collateralPriceFeedId,
672
- // },
673
- // ],
674
- // });
675
- // };
676
- // public buildCancelOrdersTx = (
677
- // inputs: ApiPerpetualsCancelOrdersBody
678
- // ): Transaction => {
679
- // const { orderDatas, collateralCoinType, accountCapId } = inputs;
680
- // if (orderDatas.length <= 0)
681
- // throw new Error("cannot have order datas of length zero");
682
- // const tx = new Transaction();
683
- // tx.setSender(inputs.walletAddress);
684
- // const marketIdToOrderIds = orderDatas.reduce(
685
- // (acc, order) => {
686
- // if (order.marketId in acc) {
687
- // return {
688
- // ...acc,
689
- // [order.marketId]: [...acc[order.marketId], order],
690
- // };
691
- // }
692
- // return {
693
- // ...acc,
694
- // [order.marketId]: [order],
695
- // };
696
- // },
697
- // {} as Record<
698
- // PerpetualsMarketId,
699
- // {
700
- // packageId: PackageId;
701
- // orderId: PerpetualsOrderId;
702
- // marketId: PerpetualsMarketId;
703
- // marketInitialSharedVersion: ObjectVersion;
704
- // collateralChange: Balance;
705
- // basePriceFeedId: ObjectId;
706
- // collateralPriceFeedId: ObjectId;
707
- // }[]
708
- // >
709
- // );
710
- // for (const [marketId, orders] of Object.entries(marketIdToOrderIds)) {
711
- // if (orders.length <= 0) continue;
712
- // const marketInitialSharedVersion =
713
- // orders[0].marketInitialSharedVersion;
714
- // const packageId = orders[0].packageId;
715
- // this.cancelOrdersTx({
716
- // tx,
717
- // collateralCoinType,
718
- // accountCapId,
719
- // marketId,
720
- // marketInitialSharedVersion,
721
- // packageId,
722
- // orderIds: orders.map((order) => order.orderId),
723
- // });
724
- // const netCollateralChange = Helpers.sumBigInt(
725
- // orders.map((order) => order.collateralChange)
726
- // );
727
- // if (netCollateralChange < BigInt(0)) {
728
- // this.deallocateCollateralTx({
729
- // tx,
730
- // accountCapId,
731
- // collateralCoinType,
732
- // marketId,
733
- // marketInitialSharedVersion,
734
- // packageId,
735
- // amount: Helpers.absBigInt(netCollateralChange),
736
- // basePriceFeedId: orders[0].basePriceFeedId,
737
- // collateralPriceFeedId: orders[0].collateralPriceFeedId,
738
- // });
739
- // } else if (netCollateralChange > BigInt(0)) {
740
- // this.allocateCollateralTx({
741
- // tx,
742
- // accountCapId,
743
- // collateralCoinType,
744
- // marketId,
745
- // marketInitialSharedVersion,
746
- // packageId,
747
- // amount: netCollateralChange,
748
- // });
749
- // } else {
750
- // // no collateral change
751
- // }
752
- // }
753
- // return tx;
754
- // };
755
- // public buildTransferCollateralTx = (inputs: {
756
- // walletAddress: SuiAddress;
757
- // collateralCoinType: CoinType;
758
- // fromAccountCapId: ObjectId | TransactionArgument;
759
- // toAccountCapId: ObjectId | TransactionArgument;
760
- // amount: Balance;
761
- // }): Transaction => {
762
- // const {
763
- // walletAddress,
764
- // collateralCoinType,
765
- // fromAccountCapId,
766
- // toAccountCapId,
767
- // amount,
768
- // } = inputs;
769
- // const tx = new Transaction();
770
- // tx.setSender(walletAddress);
771
- // const coinId = this.withdrawCollateralTx({
772
- // tx,
773
- // collateralCoinType,
774
- // amount,
775
- // accountCapId: fromAccountCapId,
776
- // });
777
- // this.depositCollateralTx({
778
- // tx,
779
- // collateralCoinType,
780
- // coinId,
781
- // accountCapId: toAccountCapId,
782
- // });
783
- // return tx;
784
- // };
785
- // public buildAllocateCollateralTx = TransactionsApiHelpers.createBuildTxFunc(
786
- // this.allocateCollateralTx
787
- // );
788
- // public buildDeallocateCollateralTx =
789
- // TransactionsApiHelpers.createBuildTxFunc(this.deallocateCollateralTx);
790
- // public buildReduceOrdersTx = (
791
- // inputs: ApiPerpetualsReduceOrdersBody
792
- // ): Transaction => {
793
- // const {
794
- // walletAddress,
795
- // collateralChange,
796
- // accountCapId,
797
- // collateralCoinType,
798
- // marketId,
799
- // marketInitialSharedVersion,
800
- // packageId,
801
- // basePriceFeedId,
802
- // collateralPriceFeedId,
803
- // orderIds,
804
- // sizesToSubtract,
805
- // } = inputs;
806
- // const tx = new Transaction();
807
- // tx.setSender(walletAddress);
808
- // this.reduceOrdersTx({
809
- // tx,
810
- // packageId,
811
- // collateralCoinType,
812
- // accountCapId,
813
- // marketId,
814
- // marketInitialSharedVersion,
815
- // orderIds,
816
- // sizesToSubtract,
817
- // });
818
- // if (collateralChange < BigInt(0)) {
819
- // this.deallocateCollateralTx({
820
- // tx,
821
- // accountCapId,
822
- // collateralCoinType,
823
- // marketId,
824
- // marketInitialSharedVersion,
825
- // packageId,
826
- // basePriceFeedId,
827
- // collateralPriceFeedId,
828
- // amount: Helpers.absBigInt(collateralChange),
829
- // });
830
- // } else if (collateralChange > BigInt(0)) {
831
- // this.allocateCollateralTx({
832
- // tx,
833
- // accountCapId,
834
- // collateralCoinType,
835
- // marketId,
836
- // marketInitialSharedVersion,
837
- // packageId,
838
- // amount: collateralChange,
839
- // });
840
- // } else {
841
- // // no collateral change
842
- // }
843
- // return tx;
844
- // };
410
+ this.fetchBuildDepositCollateralTx = (inputs) => __awaiter(this, void 0, void 0, function* () {
411
+ const tx = new transactions_1.Transaction();
412
+ tx.setSender(inputs.walletAddress);
413
+ const { walletAddress, collateralCoinType, amount } = inputs;
414
+ const coinId = yield this.Provider.Coin().fetchCoinWithAmountTx({
415
+ tx,
416
+ walletAddress,
417
+ coinType: collateralCoinType,
418
+ coinAmount: amount,
419
+ });
420
+ this.depositCollateralTx(Object.assign({ tx,
421
+ coinId }, inputs));
422
+ return tx;
423
+ });
424
+ this.buildCancelOrderTx = (inputs) => {
425
+ const { packageId, orderId, marketId, marketInitialSharedVersion, collateralChange, basePriceFeedId, collateralPriceFeedId } = inputs, otherInputs = __rest(inputs, ["packageId", "orderId", "marketId", "marketInitialSharedVersion", "collateralChange", "basePriceFeedId", "collateralPriceFeedId"]);
426
+ return this.buildCancelOrdersTx(Object.assign(Object.assign({}, otherInputs), { orderDatas: [
427
+ {
428
+ packageId,
429
+ orderId,
430
+ marketId,
431
+ marketInitialSharedVersion,
432
+ collateralChange,
433
+ basePriceFeedId,
434
+ collateralPriceFeedId,
435
+ },
436
+ ] }));
437
+ };
438
+ this.buildCancelOrdersTx = (inputs) => {
439
+ const { orderDatas, collateralCoinType, accountCapId } = inputs;
440
+ if (orderDatas.length <= 0)
441
+ throw new Error("cannot have order datas of length zero");
442
+ const tx = new transactions_1.Transaction();
443
+ tx.setSender(inputs.walletAddress);
444
+ const marketIdToOrderIds = orderDatas.reduce((acc, order) => {
445
+ if (order.marketId in acc) {
446
+ return Object.assign(Object.assign({}, acc), { [order.marketId]: [...acc[order.marketId], order] });
447
+ }
448
+ return Object.assign(Object.assign({}, acc), { [order.marketId]: [order] });
449
+ }, {});
450
+ for (const [marketId, orders] of Object.entries(marketIdToOrderIds)) {
451
+ if (orders.length <= 0)
452
+ continue;
453
+ const marketInitialSharedVersion = orders[0].marketInitialSharedVersion;
454
+ const packageId = orders[0].packageId;
455
+ this.cancelOrdersTx({
456
+ tx,
457
+ collateralCoinType,
458
+ accountCapId,
459
+ marketId,
460
+ marketInitialSharedVersion,
461
+ packageId,
462
+ orderIds: orders.map((order) => order.orderId),
463
+ });
464
+ const netCollateralChange = utils_1.Helpers.sumBigInt(orders.map((order) => order.collateralChange));
465
+ if (netCollateralChange < BigInt(0)) {
466
+ this.deallocateCollateralTx({
467
+ tx,
468
+ accountCapId,
469
+ collateralCoinType,
470
+ marketId,
471
+ marketInitialSharedVersion,
472
+ packageId,
473
+ amount: utils_1.Helpers.absBigInt(netCollateralChange),
474
+ basePriceFeedId: orders[0].basePriceFeedId,
475
+ collateralPriceFeedId: orders[0].collateralPriceFeedId,
476
+ });
477
+ }
478
+ else if (netCollateralChange > BigInt(0)) {
479
+ this.allocateCollateralTx({
480
+ tx,
481
+ accountCapId,
482
+ collateralCoinType,
483
+ marketId,
484
+ marketInitialSharedVersion,
485
+ packageId,
486
+ amount: netCollateralChange,
487
+ });
488
+ }
489
+ else {
490
+ // no collateral change
491
+ }
492
+ }
493
+ return tx;
494
+ };
495
+ this.buildWithdrawCollateralTx = (inputs) => {
496
+ const tx = new transactions_1.Transaction();
497
+ tx.setSender(inputs.walletAddress);
498
+ const coin = this.withdrawCollateralTx(Object.assign({ tx }, inputs));
499
+ tx.transferObjects([coin], inputs.walletAddress);
500
+ return tx;
501
+ };
502
+ this.buildCreateAccountTx = (inputs) => {
503
+ const tx = new transactions_1.Transaction();
504
+ tx.setSender(inputs.walletAddress);
505
+ const accountCap = this.createAccountTx(Object.assign({ tx }, inputs));
506
+ tx.transferObjects([accountCap], inputs.walletAddress);
507
+ return tx;
508
+ };
509
+ this.fetchBuildPlaceSLTPOrderTx = (inputs) => {
510
+ throw new Error("TODO");
511
+ // const { tx, sessionPotatoId } = this.createTxAndStartSession(inputs);
512
+ // this.placeSLTPOrderTx({
513
+ // ...inputs,
514
+ // tx,
515
+ // sessionPotatoId,
516
+ // });
517
+ // return tx;
518
+ };
519
+ this.buildTransferCollateralTx = (inputs) => {
520
+ const { walletAddress, collateralCoinType, fromAccountCapId, toAccountCapId, amount, } = inputs;
521
+ const tx = new transactions_1.Transaction();
522
+ tx.setSender(walletAddress);
523
+ const coinId = this.withdrawCollateralTx({
524
+ tx,
525
+ collateralCoinType,
526
+ amount,
527
+ accountCapId: fromAccountCapId,
528
+ });
529
+ this.depositCollateralTx({
530
+ tx,
531
+ collateralCoinType,
532
+ coinId,
533
+ accountCapId: toAccountCapId,
534
+ });
535
+ return tx;
536
+ };
537
+ this.buildAllocateCollateralTx = transactionsApiHelpers_1.TransactionsApiHelpers.createBuildTxFunc(this.allocateCollateralTx);
538
+ this.buildDeallocateCollateralTx = transactionsApiHelpers_1.TransactionsApiHelpers.createBuildTxFunc(this.deallocateCollateralTx);
539
+ this.buildReduceOrdersTx = (inputs) => {
540
+ const { walletAddress, collateralChange, accountCapId, collateralCoinType, marketId, marketInitialSharedVersion, packageId, basePriceFeedId, collateralPriceFeedId, orderIds, sizesToSubtract, } = inputs;
541
+ const tx = new transactions_1.Transaction();
542
+ tx.setSender(walletAddress);
543
+ this.reduceOrdersTx({
544
+ tx,
545
+ packageId,
546
+ collateralCoinType,
547
+ accountCapId,
548
+ marketId,
549
+ marketInitialSharedVersion,
550
+ orderIds,
551
+ sizesToSubtract,
552
+ });
553
+ if (collateralChange < BigInt(0)) {
554
+ this.deallocateCollateralTx({
555
+ tx,
556
+ accountCapId,
557
+ collateralCoinType,
558
+ marketId,
559
+ marketInitialSharedVersion,
560
+ packageId,
561
+ basePriceFeedId,
562
+ collateralPriceFeedId,
563
+ amount: utils_1.Helpers.absBigInt(collateralChange),
564
+ });
565
+ }
566
+ else if (collateralChange > BigInt(0)) {
567
+ this.allocateCollateralTx({
568
+ tx,
569
+ accountCapId,
570
+ collateralCoinType,
571
+ marketId,
572
+ marketInitialSharedVersion,
573
+ packageId,
574
+ amount: collateralChange,
575
+ });
576
+ }
577
+ else {
578
+ // no collateral change
579
+ }
580
+ return tx;
581
+ };
845
582
  // =========================================================================
846
583
  // Helpers
847
584
  // =========================================================================
848
585
  this.getAccountCapType = (inputs) => {
849
- return `${this.addresses.packages.events}::${PerpetualsApi.constants.moduleNames.account}::Account<${inputs.collateralCoinType}>`;
586
+ return `${this.addresses.perpetuals.packages.events}::${PerpetualsApi.constants.moduleNames.account}::Account<${inputs.collateralCoinType}>`;
850
587
  };
851
588
  // =========================================================================
852
589
  // Private Helpers
@@ -1234,11 +971,15 @@ class PerpetualsApi {
1234
971
  // =========================================================================
1235
972
  // Event Types
1236
973
  // =========================================================================
1237
- this.eventType = (eventName) => eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.packages.events, PerpetualsApi.constants.moduleNames.events, eventName);
1238
- const addresses = this.Provider.addresses.perpetuals;
1239
- if (!addresses)
974
+ this.eventType = (eventName) => eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.perpetuals.packages.events, PerpetualsApi.constants.moduleNames.events, eventName);
975
+ const perpetuals = this.Provider.addresses.perpetuals;
976
+ const oracle = this.Provider.addresses.oracle;
977
+ if (!perpetuals || !oracle)
1240
978
  throw new Error("not all required addresses have been set in provider");
1241
- this.addresses = addresses;
979
+ this.addresses = {
980
+ perpetuals,
981
+ oracle,
982
+ };
1242
983
  this.eventTypes = {
1243
984
  // Collateral
1244
985
  withdrewCollateral: this.eventType("WithdrewCollateral"),
@@ -1249,16 +990,16 @@ class PerpetualsApi {
1249
990
  // Liquidation
1250
991
  liquidated: this.eventType("LiquidatedPosition"),
1251
992
  filledTakerOrderLiquidator: this.eventType("FilledTakerOrderLiquidator"),
1252
- performedLiquidation: this.eventType("PerformedLiquidation"),
1253
993
  // Account
1254
994
  createdAccount: this.eventType("CreatedAccount"),
1255
995
  // Order
1256
996
  canceledOrder: this.eventType("CanceledOrder"),
1257
- filledMakerOrders: this.eventType("FilledMakerOrders"),
997
+ postedOrder: this.eventType("PostedOrder"),
1258
998
  filledMakerOrder: this.eventType("FilledMakerOrder"),
1259
999
  filledTakerOrder: this.eventType("FilledTakerOrder"),
1260
1000
  reducedOrder: this.eventType("ReducedOrder"),
1261
- postedOrder: this.eventType("PostedOrder"),
1001
+ // Order Receipts
1002
+ postedOrderReceipt: this.eventType("OrderbookPostReceipt"),
1262
1003
  // Twap
1263
1004
  updatedPremiumTwap: this.eventType("UpdatedPremiumTwap"),
1264
1005
  updatedSpreadTwap: this.eventType("UpdatedSpreadTwap"),
@@ -1266,140 +1007,90 @@ class PerpetualsApi {
1266
1007
  updatedFunding: this.eventType("UpdatedFunding"),
1267
1008
  // Version
1268
1009
  updatedMarketVersion: this.eventType("UpdatedClearingHouseVersion"),
1269
- // Stop Order
1270
- createdStopOrderTicket: this.eventType("CreatedStopOrderTicket"),
1271
- deletedStopOrderTicket: this.eventType("DeletedStopOrderTicket"),
1272
- editedStopOrderTicketExecutor: this.eventType("EditedStopOrderTicketExecutor"),
1273
- addedStopOrderTicketCollateral: this.eventType("AddedStopOrderTicketCollateral"),
1274
- removedStopOrderTicketCollateral: this.eventType("RemovedStopOrderTicketCollateral"),
1275
- editedStopOrderTicketDetails: this.eventType("EditedStopOrderTicketDetails"),
1276
- executedStopOrderTicket: this.eventType("ExecutedStopOrderTicket"),
1277
1010
  };
1278
1011
  this.moveErrors = {
1279
- // TODO: add support for this back in some way ?
1280
- // [this.addresses.packages.perpetuals]: {
1281
- // ["ANY"]: {
1282
- // // ClearingHouse
1283
- // /// Cannot deposit/withdraw zero coins to/from the account's collateral.
1284
- // 0: "Deposit Or Withdraw Amount Zero",
1285
- // /// Orderbook size or price are invalid values
1286
- // 1: "Invalid Size Or Price",
1287
- // /// Index price returned from oracle is 0 or invalid value
1288
- // 2: "Bad Index Price",
1289
- // /// Order value in USD is too low
1290
- // 4: "Order Usd Value Too Low",
1291
- // /// Passed a vector of invalid order ids to perform force cancellation during liquidation
1292
- // 5: "Invalid Force Cancel Ids",
1293
- // /// Liquidate must be the first operation of the session, if performed.
1294
- // 6: "Liquidate Not First Operation",
1295
- // /// Passed a vector of invalid order ids to cancel
1296
- // 7: "Invalid Cancel Order Ids",
1297
- // /// Ticket has already passed `expire_timestamp` and can only be cancelled
1298
- // 8: "Stop Order Ticket Expired",
1299
- // /// Index price is not at correct value to satisfy stop order conditions
1300
- // 9: "Stop Order Conditions Violated",
1301
- // /// Index price is not at correct value to satisfy stop order conditions
1302
- // 10: "Wrong Order Details",
1303
- // /// Invalid base price feed storage for the clearing house
1304
- // 11: "Invalid Base Price Feed Storage",
1305
- // /// Same liquidator and liqee account ids
1306
- // 12: "Self Liquidation",
1307
- // /// User trying to access the subaccount is not the one specified by parent
1308
- // 13: "Invalid Sub Account User",
1309
- // /// The parent `Account` trying to delete the subaccount is not the correct one.
1310
- // 14: "Wrong Parent For Sub Account",
1311
- // /// Raised when trying to delete a subaccount still containing collateral.
1312
- // 15: "Sub Account Contains Collateral",
1313
- // /// Raised when trying to call a function with the wrong package's version
1314
- // 16: "Wrong Version",
1315
- // /// Raised when trying to have a session composed by only `start_session` and `end_session`
1316
- // 17: "Empty Session",
1317
- // /// Market already registered in the registry
1318
- // 18: "Market Already Registered",
1319
- // /// Collateral is not registered in the registry
1320
- // 19: "Collateral Is Not Registered",
1321
- // /// Market is not registered in the registry
1322
- // 20: "Market Is Not Registered",
1323
- // /// Invalid collateral price feed storage for the clearing house
1324
- // 21: "Invalid Collateral Price Feed Storage",
1325
- // /// Fees accrued are negative
1326
- // 22: "Negative Fees Accrued",
1327
- // /// Reduce-only conditions are not respected for stop order execution
1328
- // 23: "Not Reduce Only Stop Order",
1329
- // /// Stop order gas cost provided is not enough
1330
- // 24: "Not Enough Gas For Stop Order",
1331
- // /// Stop order collateral to allocate provided is not enough
1332
- // 25: "Not Enough Collateral To Allocate For Stop Order",
1333
- // /// Invalid account trying to perform an action on a StopOrderTicket
1334
- // 26: "Invalid Account For Stop Order",
1335
- // /// Invalid executor trying to execute the StopOrderTicket
1336
- // 27: "Invalid Executor For Stop Order",
1337
- // /// Raised when the market's max open interest is surpassed as a result of the session's actions
1338
- // 28: "Max Open Interest Surpassed",
1339
- // /// Raised when a position would get a base amount higher than the allowed percentage of open interest
1340
- // 29: "Max Open Interest Position Percent Surpassed",
1341
- // // Market
1342
- // /// While creating ordered map with invalid parameters, or changing them improperly for an existent map.
1343
- // 1000: "Invalid Market Parameters",
1344
- // /// Tried to call `update_funding` before enough time has passed since the last update.
1345
- // 1001: "Updating Funding Too Early",
1346
- // /// Margin-ratio update proposal already exists for market
1347
- // 1002: "Proposal Already Exists",
1348
- // /// Margin-ratio update proposal cannot be committed too early
1349
- // 1003: "Premature Proposal",
1350
- // /// Margin-ratio update proposal delay is outside the valid range
1351
- // 1004: "Invalid Proposal Delay",
1352
- // /// Margin-ratio update proposal does not exist for market
1353
- // 1005: "Proposal Does Not Exist",
1354
- // /// Exchange has no available fees to withdraw
1355
- // 1006: "No Fees Accrued",
1356
- // /// Tried to withdraw more insurance funds than the allowed amount
1357
- // 1007: "Insufficient Insurance Surplus",
1358
- // /// Cannot create a market for which a price feed does not exist
1359
- // 1008: "No Price Feed For Market",
1360
- // /// Cannot delete a proposal that already matured. It can only be committed.
1361
- // 1009: "Proposal Already Matured",
1362
- // // Position
1363
- // /// Tried placing a new pending order when the position already has the maximum allowed number of pending orders.
1364
- // 2000: "Max Pending Orders Exceeded",
1365
- // /// Used for checking both liqee and liqor positions during liquidation
1366
- // 2001: "Position Below IMR",
1367
- // ///When leaving liqee's position with a margin ratio above tolerance,
1368
- // /// meaning that liqor has overbought position
1369
- // 2002: "Position Above Tolerance",
1370
- // /// An operation brought an account below initial margin requirements.
1371
- // 2003: "Initial Margin Requirement Violated",
1372
- // /// Position is above MMR, so can't be liquidated.
1373
- // 2004: "Position Above MMR",
1374
- // /// Cannot realize bad debt via means other than calling 'liquidate'.
1375
- // 2005: "Position Bad Debt",
1376
- // /// Cannot withdraw more than the account's free collateral.
1377
- // 2006: "Insufficient Free Collateral",
1378
- // /// Cannot have more than 1 position in a market.
1379
- // 2007: "Position Already Exists",
1380
- // /// Cannot compute deallocate amount for a target MR < IMR.
1381
- // 2008: "Deallocate Target MR Too Low",
1382
- // // Orderbook & OrderedMap
1383
- // /// While creating ordered map with wrong parameters.
1384
- // 3000: "Invalid Map Parameters",
1385
- // /// While searching for a key, but it doesn't exist.
1386
- // 3001: "Key Not Exist",
1387
- // /// While inserting already existing key.
1388
- // 3002: "Key Already Exists",
1389
- // /// When attempting to destroy a non-empty map
1390
- // 3003: "Destroy Not Empty",
1391
- // /// Invalid user tries to modify an order
1392
- // 3004: "Invalid User For Order",
1393
- // /// Orderbook flag requirements violated
1394
- // 3005: "Flag Requirements Violated",
1395
- // /// Minimum size matched not reached
1396
- // 3006: "Not Enough Liquidity",
1397
- // /// When trying to change a map configuration, but the map has length less than 4
1398
- // 3007: "Map Too Small",
1399
- // /// When taker matches its own order
1400
- // 3008: "Self Trading",
1401
- // },
1402
- // },
1012
+ [this.addresses.perpetuals.packages.perpetuals]: {
1013
+ // Clearing House
1014
+ // Cannot deposit/withdraw zero coins to/from the account's collateral.
1015
+ 0: "Deposit Or Withdraw Amount Zero",
1016
+ // Orderbook size or price are invalid values
1017
+ 1: "Invalid Size Or Price",
1018
+ // When trying to access a particular insurance fund, but it does not exist.
1019
+ 2: "Invalid Insurance Fund Id",
1020
+ // Index price returned from oracle is 0 or invalid value
1021
+ 3: "Bad Index Price",
1022
+ // Registry already contains the specified collateral type
1023
+ 4: "Invalid Collateral Type",
1024
+ // Order value in USD is too low
1025
+ 5: "Order Usd Value Too Low",
1026
+ // Wrong number of sizes passed to liquidation.
1027
+ // It must match the number of liqee's positions.
1028
+ 6: "Invalid Number Of Sizes",
1029
+ // MarketManager
1030
+ // Tried to create a new market with invalid parameters.
1031
+ 1000: "Invalid Market Parameters",
1032
+ // Tried to call `update_funding` before enough time has passed since the
1033
+ // last update.
1034
+ 1001: "Updating Funding Too Early",
1035
+ // Margin ratio update proposal already exists for market
1036
+ 1002: "Proposal Already Exists",
1037
+ // Margin ratio update proposal cannot be commited too early
1038
+ 1003: "Premature Proposal",
1039
+ // Margin ratio update proposal delay is outside the valid range
1040
+ 1004: "Invalid Proposal Delay",
1041
+ // Market does not exist
1042
+ 1005: "Market Does Not Exist",
1043
+ // Tried to update a config with a value outside of the allowed range
1044
+ 1006: "Value Out Of Range",
1045
+ // Margin ratio update proposal does not exist for market
1046
+ 1007: "Proposal Does Not Exist",
1047
+ // Exchange has no available fees to withdraw
1048
+ 1008: "No Fees Accrued",
1049
+ // Tried to withdraw more insurance funds than the allowed amount
1050
+ 1009: "Insufficient Insurance Surplus",
1051
+ // Cannot create a market for which a price feed does not exist
1052
+ 1010: "No Price Feed For Market",
1053
+ // Account Manager
1054
+ // Tried accessing a nonexistent account.
1055
+ 2000: "Account Not Found",
1056
+ // Tried accessing a nonexistent account position.
1057
+ 2001: "Position Not Found",
1058
+ // Tried creating a new position when the account already has the maximum
1059
+ // allowed number of open positions.
1060
+ 2002: "Max Positions Exceeded",
1061
+ // An operation brought an account below initial margin requirements.
1062
+ // 2003: "Initial Margin Requirement Violated",
1063
+ 2003: "Margin Requirements Violated, Try Lowering Size",
1064
+ // Account is above MMR, so can't be liquidated.
1065
+ 2004: "Account Above MMR",
1066
+ // Cannot realize bad debt via means other than calling 'liquidate'.
1067
+ 2005: "Account Bad Debt",
1068
+ // Cannot withdraw more than the account's free collateral.
1069
+ 2006: "Insufficient Free Collateral",
1070
+ // Cannot delete a position that is not worthless
1071
+ 2007: "Position Not Null",
1072
+ // Tried placing a new pending order when the position already has the maximum
1073
+ // allowed number of pending orders.
1074
+ 2008: "Max Pending Orders Exceeded",
1075
+ // Used for checking both liqee and liqor positions during liquidation
1076
+ 2009: "Account Below IMR",
1077
+ // When leaving liqee's account with a margin ratio above tolerance,
1078
+ // meaning that liqor has overbought position
1079
+ 2010: "Account Above Tolerance",
1080
+ // Orderbook & OrderedMap
1081
+ // While searching for a key, but it doesn't exist.
1082
+ 3000: "Key Does Not Exist",
1083
+ // While inserting already existing key.
1084
+ 3001: "Key Already Exists",
1085
+ // When attempting to destroy a non-empty map
1086
+ 3002: "Destroying Not Empty Map",
1087
+ // Invalid user tries to modify an order
1088
+ 3003: "Invalid User For Order",
1089
+ // Orderbook flag requirements violated
1090
+ 3004: "Flag Requirements Violated",
1091
+ // Minimum size matched not reached
1092
+ 3005: "Not Enough Liquidity",
1093
+ },
1403
1094
  };
1404
1095
  }
1405
1096
  }