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.
- package/dist/general/apiHelpers/transactionsApiHelpers.d.ts +0 -3
- package/dist/general/apiHelpers/transactionsApiHelpers.d.ts.map +1 -1
- package/dist/general/apiHelpers/transactionsApiHelpers.js +0 -12
- package/dist/general/providers/aftermath.d.ts +5 -0
- package/dist/general/providers/aftermath.d.ts.map +1 -1
- package/dist/general/providers/aftermath.js +6 -1
- package/dist/general/providers/aftermathApi.d.ts +5 -0
- package/dist/general/providers/aftermathApi.d.ts.map +1 -1
- package/dist/general/providers/aftermathApi.js +5 -0
- package/dist/general/types/castingTypes.d.ts +2 -2
- package/dist/general/types/castingTypes.d.ts.map +1 -1
- package/dist/general/types/configTypes.d.ts +10 -0
- package/dist/general/types/configTypes.d.ts.map +1 -1
- package/dist/general/types/generalTypes.d.ts +0 -4
- package/dist/general/types/generalTypes.d.ts.map +1 -1
- package/dist/general/types/moveErrorsInterface.d.ts +1 -1
- package/dist/general/types/moveErrorsInterface.d.ts.map +1 -1
- package/dist/general/utils/caller.d.ts +2 -17
- package/dist/general/utils/caller.d.ts.map +1 -1
- package/dist/general/utils/caller.js +2 -35
- package/dist/general/utils/casting.d.ts +5 -4
- package/dist/general/utils/casting.d.ts.map +1 -1
- package/dist/general/utils/casting.js +5 -4
- package/dist/general/utils/helpers.d.ts +0 -1
- package/dist/general/utils/helpers.d.ts.map +1 -1
- package/dist/general/utils/helpers.js +6 -35
- package/dist/general/wallet/wallet.d.ts +1 -1
- package/dist/general/wallet/wallet.d.ts.map +1 -1
- package/dist/packages/coin/coin.d.ts +1 -1
- package/dist/packages/coin/coin.d.ts.map +1 -1
- package/dist/packages/coin/coin.js +1 -3
- package/dist/packages/farms/api/farmsApiCasting.js +27 -27
- package/dist/packages/farms/farms.d.ts +1 -1
- package/dist/packages/farms/farms.d.ts.map +1 -1
- package/dist/packages/farms/farmsStakedPosition.d.ts +1 -1
- package/dist/packages/farms/farmsStakedPosition.d.ts.map +1 -1
- package/dist/packages/farms/farmsStakingPool.d.ts +1 -1
- package/dist/packages/farms/farmsStakingPool.d.ts.map +1 -1
- package/dist/packages/faucet/api/faucetApi.d.ts +17 -9
- package/dist/packages/faucet/api/faucetApi.d.ts.map +1 -1
- package/dist/packages/faucet/api/faucetApi.js +49 -44
- package/dist/packages/faucet/api/faucetApiCasting.d.ts.map +1 -1
- package/dist/packages/faucet/api/faucetApiCasting.js +7 -10
- package/dist/packages/faucet/api/faucetApiCastingTypes.d.ts +4 -1
- package/dist/packages/faucet/api/faucetApiCastingTypes.d.ts.map +1 -1
- package/dist/packages/faucet/faucet.d.ts +1 -1
- package/dist/packages/faucet/faucet.d.ts.map +1 -1
- package/dist/packages/faucet/faucet.js +1 -1
- package/dist/packages/faucet/faucetTypes.d.ts +3 -2
- package/dist/packages/faucet/faucetTypes.d.ts.map +1 -1
- package/dist/packages/leveragedStaking/api/leveragedStakingApiCasting.js +3 -3
- package/dist/packages/multisig/multisig.d.ts +1 -1
- package/dist/packages/multisig/multisig.d.ts.map +1 -1
- package/dist/packages/nftAmm/nftAmm.d.ts +1 -1
- package/dist/packages/nftAmm/nftAmm.d.ts.map +1 -1
- package/dist/packages/oracle/api/oracleApi.d.ts +21 -0
- package/dist/packages/oracle/api/oracleApi.d.ts.map +1 -0
- package/dist/packages/oracle/api/oracleApi.js +76 -0
- package/dist/packages/oracle/api/oracleApiCasting.d.ts +6 -0
- package/dist/packages/oracle/api/oracleApiCasting.d.ts.map +1 -0
- package/dist/packages/oracle/api/oracleApiCasting.js +25 -0
- package/dist/packages/oracle/oracle.d.ts +15 -0
- package/dist/packages/oracle/oracle.d.ts.map +1 -0
- package/dist/packages/oracle/oracle.js +46 -0
- package/dist/packages/oracle/oracleCastingTypes.d.ts +11 -0
- package/dist/packages/oracle/oracleCastingTypes.d.ts.map +1 -0
- package/dist/packages/oracle/oracleCastingTypes.js +2 -0
- package/dist/packages/oracle/oracleTypes.d.ts +10 -0
- package/dist/packages/oracle/oracleTypes.d.ts.map +1 -0
- package/dist/packages/oracle/oracleTypes.js +2 -0
- package/dist/packages/perpetuals/api/perpetualsApi.d.ts +203 -11
- package/dist/packages/perpetuals/api/perpetualsApi.d.ts.map +1 -1
- package/dist/packages/perpetuals/api/perpetualsApi.js +615 -924
- package/dist/packages/perpetuals/api/perpetualsApiCasting.d.ts +21 -10
- package/dist/packages/perpetuals/api/perpetualsApiCasting.d.ts.map +1 -1
- package/dist/packages/perpetuals/api/perpetualsApiCasting.js +238 -260
- package/dist/packages/perpetuals/index.d.ts +0 -1
- package/dist/packages/perpetuals/index.d.ts.map +1 -1
- package/dist/packages/perpetuals/index.js +0 -1
- package/dist/packages/perpetuals/perpetuals.d.ts +14 -83
- package/dist/packages/perpetuals/perpetuals.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetuals.js +59 -158
- package/dist/packages/perpetuals/perpetualsAccount.d.ts +86 -158
- package/dist/packages/perpetuals/perpetualsAccount.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsAccount.js +141 -481
- package/dist/packages/perpetuals/perpetualsCastingTypes.d.ts +149 -82
- package/dist/packages/perpetuals/perpetualsCastingTypes.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsMarket.d.ts +20 -55
- package/dist/packages/perpetuals/perpetualsMarket.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsMarket.js +57 -114
- package/dist/packages/perpetuals/perpetualsTypes.d.ts +280 -586
- package/dist/packages/perpetuals/perpetualsTypes.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsTypes.js +81 -17
- package/dist/packages/pools/api/poolsApiCasting.js +3 -3
- package/dist/packages/pools/pool.d.ts +1 -1
- package/dist/packages/pools/pool.d.ts.map +1 -1
- package/dist/packages/pools/pools.d.ts +1 -1
- package/dist/packages/pools/pools.d.ts.map +1 -1
- package/dist/packages/referralVault/referralVault.d.ts +1 -1
- package/dist/packages/referralVault/referralVault.d.ts.map +1 -1
- package/dist/packages/router/api/routerApiCasting.js +1 -1
- package/dist/packages/staking/api/stakingApiCasting.js +3 -3
- package/dist/packages/staking/staking.d.ts +1 -1
- package/dist/packages/staking/staking.d.ts.map +1 -1
- package/dist/packages/sui/sui.d.ts +1 -1
- package/dist/packages/sui/sui.d.ts.map +1 -1
- package/dist/packages/suiFrens/api/suiFrensApiCasting.js +4 -4
- package/dist/packages/suiFrens/stakedSuiFren.d.ts +1 -1
- package/dist/packages/suiFrens/stakedSuiFren.d.ts.map +1 -1
- package/dist/packages/suiFrens/suiFren.d.ts +1 -1
- package/dist/packages/suiFrens/suiFren.d.ts.map +1 -1
- package/dist/packages/suiFrens/suiFrens.d.ts +1 -1
- package/dist/packages/suiFrens/suiFrens.d.ts.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/package.json +2 -2
- package/dist/packages/perpetuals/perpetualsVault.d.ts +0 -109
- package/dist/packages/perpetuals/perpetualsVault.d.ts.map +0 -1
- 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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
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
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
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
|
|
1239
|
-
|
|
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 =
|
|
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
|
-
|
|
997
|
+
postedOrder: this.eventType("PostedOrder"),
|
|
1258
998
|
filledMakerOrder: this.eventType("FilledMakerOrder"),
|
|
1259
999
|
filledTakerOrder: this.eventType("FilledTakerOrder"),
|
|
1260
1000
|
reducedOrder: this.eventType("ReducedOrder"),
|
|
1261
|
-
|
|
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
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
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
|
}
|