@typus/typus-perp-sdk 1.1.3 → 1.1.5-pnl

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.
@@ -0,0 +1,448 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || (function () {
30
+ var ownKeys = function(o) {
31
+ ownKeys = Object.getOwnPropertyNames || function (o) {
32
+ var ar = [];
33
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34
+ return ar;
35
+ };
36
+ return ownKeys(o);
37
+ };
38
+ return function (mod) {
39
+ if (mod && mod.__esModule) return mod;
40
+ var result = {};
41
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
42
+ __setModuleDefault(result, mod);
43
+ return result;
44
+ };
45
+ })();
46
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
47
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
48
+ return new (P || (P = Promise))(function (resolve, reject) {
49
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
50
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
51
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
52
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
53
+ });
54
+ };
55
+ var __generator = (this && this.__generator) || function (thisArg, body) {
56
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
57
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
58
+ function verb(n) { return function (v) { return step([n, v]); }; }
59
+ function step(op) {
60
+ if (f) throw new TypeError("Generator is already executing.");
61
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
62
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
63
+ if (y = 0, t) op = [op[0] & 2, t.value];
64
+ switch (op[0]) {
65
+ case 0: case 1: t = op; break;
66
+ case 4: _.label++; return { value: op[1], done: false };
67
+ case 5: _.label++; y = op[1]; op = [0]; continue;
68
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
69
+ default:
70
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
71
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
72
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
73
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
74
+ if (t[2]) _.ops.pop();
75
+ _.trys.pop(); continue;
76
+ }
77
+ op = body.call(thisArg, _);
78
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
79
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
80
+ }
81
+ };
82
+ var __read = (this && this.__read) || function (o, n) {
83
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
84
+ if (!m) return o;
85
+ var i = m.call(o), r, ar = [], e;
86
+ try {
87
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
88
+ }
89
+ catch (error) { e = { error: error }; }
90
+ finally {
91
+ try {
92
+ if (r && !r.done && (m = i["return"])) m.call(i);
93
+ }
94
+ finally { if (e) throw e.error; }
95
+ }
96
+ return ar;
97
+ };
98
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
99
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
100
+ if (ar || !(i in from)) {
101
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
102
+ ar[i] = from[i];
103
+ }
104
+ }
105
+ return to.concat(ar || Array.prototype.slice.call(from));
106
+ };
107
+ Object.defineProperty(exports, "__esModule", { value: true });
108
+ exports.UserAccountCap = exports.UserAccount = void 0;
109
+ exports.isUserAccount = isUserAccount;
110
+ exports.isUserAccountCap = isUserAccountCap;
111
+ var reified = __importStar(require("../../_framework/reified"));
112
+ var structs_1 = require("../../_dependencies/source/0x1/type-name/structs");
113
+ var structs_2 = require("../../_dependencies/source/0x2/object/structs");
114
+ var reified_1 = require("../../_framework/reified");
115
+ var util_1 = require("../../_framework/util");
116
+ var index_1 = require("../index");
117
+ var bcs_1 = require("@mysten/sui/bcs");
118
+ var utils_1 = require("@mysten/sui/utils");
119
+ /* ============================== UserAccount =============================== */
120
+ function isUserAccount(type) {
121
+ type = (0, util_1.compressSuiType)(type);
122
+ return type === "".concat(index_1.PKG_V1, "::user_account::UserAccount");
123
+ }
124
+ var UserAccount = /** @class */ (function () {
125
+ function UserAccount(typeArgs, fields) {
126
+ this.__StructClass = true;
127
+ this.$typeName = UserAccount.$typeName;
128
+ this.$isPhantom = UserAccount.$isPhantom;
129
+ this.$fullTypeName = util_1.composeSuiType.apply(void 0, __spreadArray([UserAccount.$typeName], __read(typeArgs), false));
130
+ this.$typeArgs = typeArgs;
131
+ this.id = fields.id;
132
+ this.owner = fields.owner;
133
+ this.delegateUser = fields.delegateUser;
134
+ this.symbols = fields.symbols;
135
+ this.u64Padding = fields.u64Padding;
136
+ }
137
+ UserAccount.reified = function () {
138
+ var _this = this;
139
+ return {
140
+ typeName: UserAccount.$typeName,
141
+ fullTypeName: util_1.composeSuiType.apply(void 0, __spreadArray([UserAccount.$typeName], [], false)),
142
+ typeArgs: [],
143
+ isPhantom: UserAccount.$isPhantom,
144
+ reifiedTypeArgs: [],
145
+ fromFields: function (fields) { return UserAccount.fromFields(fields); },
146
+ fromFieldsWithTypes: function (item) { return UserAccount.fromFieldsWithTypes(item); },
147
+ fromBcs: function (data) { return UserAccount.fromBcs(data); },
148
+ bcs: UserAccount.bcs,
149
+ fromJSONField: function (field) { return UserAccount.fromJSONField(field); },
150
+ fromJSON: function (json) { return UserAccount.fromJSON(json); },
151
+ fromSuiParsedData: function (content) { return UserAccount.fromSuiParsedData(content); },
152
+ fromSuiObjectData: function (content) { return UserAccount.fromSuiObjectData(content); },
153
+ fetch: function (client, id) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
154
+ return [2 /*return*/, UserAccount.fetch(client, id)];
155
+ }); }); },
156
+ new: function (fields) {
157
+ return new UserAccount([], fields);
158
+ },
159
+ kind: "StructClassReified",
160
+ };
161
+ };
162
+ Object.defineProperty(UserAccount, "r", {
163
+ get: function () {
164
+ return UserAccount.reified();
165
+ },
166
+ enumerable: false,
167
+ configurable: true
168
+ });
169
+ UserAccount.phantom = function () {
170
+ return (0, reified_1.phantom)(UserAccount.reified());
171
+ };
172
+ Object.defineProperty(UserAccount, "p", {
173
+ get: function () {
174
+ return UserAccount.phantom();
175
+ },
176
+ enumerable: false,
177
+ configurable: true
178
+ });
179
+ Object.defineProperty(UserAccount, "bcs", {
180
+ get: function () {
181
+ return bcs_1.bcs.struct("UserAccount", {
182
+ id: structs_2.UID.bcs,
183
+ owner: bcs_1.bcs.bytes(32).transform({ input: function (val) { return (0, utils_1.fromHEX)(val); }, output: function (val) { return (0, utils_1.toHEX)(val); } }),
184
+ delegate_user: bcs_1.bcs.vector(bcs_1.bcs.bytes(32).transform({ input: function (val) { return (0, utils_1.fromHEX)(val); }, output: function (val) { return (0, utils_1.toHEX)(val); } })),
185
+ symbols: bcs_1.bcs.vector(structs_1.TypeName.bcs),
186
+ u64_padding: bcs_1.bcs.vector(bcs_1.bcs.u64()),
187
+ });
188
+ },
189
+ enumerable: false,
190
+ configurable: true
191
+ });
192
+ UserAccount.fromFields = function (fields) {
193
+ return UserAccount.reified().new({
194
+ id: (0, reified_1.decodeFromFields)(structs_2.UID.reified(), fields.id),
195
+ owner: (0, reified_1.decodeFromFields)("address", fields.owner),
196
+ delegateUser: (0, reified_1.decodeFromFields)(reified.vector("address"), fields.delegate_user),
197
+ symbols: (0, reified_1.decodeFromFields)(reified.vector(structs_1.TypeName.reified()), fields.symbols),
198
+ u64Padding: (0, reified_1.decodeFromFields)(reified.vector("u64"), fields.u64_padding),
199
+ });
200
+ };
201
+ UserAccount.fromFieldsWithTypes = function (item) {
202
+ if (!isUserAccount(item.type)) {
203
+ throw new Error("not a UserAccount type");
204
+ }
205
+ return UserAccount.reified().new({
206
+ id: (0, reified_1.decodeFromFieldsWithTypes)(structs_2.UID.reified(), item.fields.id),
207
+ owner: (0, reified_1.decodeFromFieldsWithTypes)("address", item.fields.owner),
208
+ delegateUser: (0, reified_1.decodeFromFieldsWithTypes)(reified.vector("address"), item.fields.delegate_user),
209
+ symbols: (0, reified_1.decodeFromFieldsWithTypes)(reified.vector(structs_1.TypeName.reified()), item.fields.symbols),
210
+ u64Padding: (0, reified_1.decodeFromFieldsWithTypes)(reified.vector("u64"), item.fields.u64_padding),
211
+ });
212
+ };
213
+ UserAccount.fromBcs = function (data) {
214
+ return UserAccount.fromFields(UserAccount.bcs.parse(data));
215
+ };
216
+ UserAccount.prototype.toJSONField = function () {
217
+ return {
218
+ id: this.id,
219
+ owner: this.owner,
220
+ delegateUser: (0, reified_1.fieldToJSON)("vector<address>", this.delegateUser),
221
+ symbols: (0, reified_1.fieldToJSON)("vector<".concat(structs_1.TypeName.$typeName, ">"), this.symbols),
222
+ u64Padding: (0, reified_1.fieldToJSON)("vector<u64>", this.u64Padding),
223
+ };
224
+ };
225
+ UserAccount.prototype.toJSON = function () {
226
+ return __assign({ $typeName: this.$typeName, $typeArgs: this.$typeArgs }, this.toJSONField());
227
+ };
228
+ UserAccount.fromJSONField = function (field) {
229
+ return UserAccount.reified().new({
230
+ id: (0, reified_1.decodeFromJSONField)(structs_2.UID.reified(), field.id),
231
+ owner: (0, reified_1.decodeFromJSONField)("address", field.owner),
232
+ delegateUser: (0, reified_1.decodeFromJSONField)(reified.vector("address"), field.delegateUser),
233
+ symbols: (0, reified_1.decodeFromJSONField)(reified.vector(structs_1.TypeName.reified()), field.symbols),
234
+ u64Padding: (0, reified_1.decodeFromJSONField)(reified.vector("u64"), field.u64Padding),
235
+ });
236
+ };
237
+ UserAccount.fromJSON = function (json) {
238
+ if (json.$typeName !== UserAccount.$typeName) {
239
+ throw new Error("not a WithTwoGenerics json object");
240
+ }
241
+ return UserAccount.fromJSONField(json);
242
+ };
243
+ UserAccount.fromSuiParsedData = function (content) {
244
+ if (content.dataType !== "moveObject") {
245
+ throw new Error("not an object");
246
+ }
247
+ if (!isUserAccount(content.type)) {
248
+ throw new Error("object at ".concat(content.fields.id, " is not a UserAccount object"));
249
+ }
250
+ return UserAccount.fromFieldsWithTypes(content);
251
+ };
252
+ UserAccount.fromSuiObjectData = function (data) {
253
+ if (data.bcs) {
254
+ if (data.bcs.dataType !== "moveObject" || !isUserAccount(data.bcs.type)) {
255
+ throw new Error("object at is not a UserAccount object");
256
+ }
257
+ return UserAccount.fromBcs((0, utils_1.fromB64)(data.bcs.bcsBytes));
258
+ }
259
+ if (data.content) {
260
+ return UserAccount.fromSuiParsedData(data.content);
261
+ }
262
+ throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
263
+ };
264
+ UserAccount.fetch = function (client, id) {
265
+ return __awaiter(this, void 0, void 0, function () {
266
+ var res;
267
+ var _a, _b;
268
+ return __generator(this, function (_c) {
269
+ switch (_c.label) {
270
+ case 0: return [4 /*yield*/, client.getObject({ id: id, options: { showBcs: true } })];
271
+ case 1:
272
+ res = _c.sent();
273
+ if (res.error) {
274
+ throw new Error("error fetching UserAccount object at id ".concat(id, ": ").concat(res.error.code));
275
+ }
276
+ if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" || !isUserAccount(res.data.bcs.type)) {
277
+ throw new Error("object at id ".concat(id, " is not a UserAccount object"));
278
+ }
279
+ return [2 /*return*/, UserAccount.fromSuiObjectData(res.data)];
280
+ }
281
+ });
282
+ });
283
+ };
284
+ UserAccount.$typeName = "".concat(index_1.PKG_V1, "::user_account::UserAccount");
285
+ UserAccount.$numTypeParams = 0;
286
+ UserAccount.$isPhantom = [];
287
+ return UserAccount;
288
+ }());
289
+ exports.UserAccount = UserAccount;
290
+ /* ============================== UserAccountCap =============================== */
291
+ function isUserAccountCap(type) {
292
+ type = (0, util_1.compressSuiType)(type);
293
+ return type === "".concat(index_1.PKG_V1, "::user_account::UserAccountCap");
294
+ }
295
+ var UserAccountCap = /** @class */ (function () {
296
+ function UserAccountCap(typeArgs, fields) {
297
+ this.__StructClass = true;
298
+ this.$typeName = UserAccountCap.$typeName;
299
+ this.$isPhantom = UserAccountCap.$isPhantom;
300
+ this.$fullTypeName = util_1.composeSuiType.apply(void 0, __spreadArray([UserAccountCap.$typeName], __read(typeArgs), false));
301
+ this.$typeArgs = typeArgs;
302
+ this.id = fields.id;
303
+ this.owner = fields.owner;
304
+ this.userAccountId = fields.userAccountId;
305
+ }
306
+ UserAccountCap.reified = function () {
307
+ var _this = this;
308
+ return {
309
+ typeName: UserAccountCap.$typeName,
310
+ fullTypeName: util_1.composeSuiType.apply(void 0, __spreadArray([UserAccountCap.$typeName], [], false)),
311
+ typeArgs: [],
312
+ isPhantom: UserAccountCap.$isPhantom,
313
+ reifiedTypeArgs: [],
314
+ fromFields: function (fields) { return UserAccountCap.fromFields(fields); },
315
+ fromFieldsWithTypes: function (item) { return UserAccountCap.fromFieldsWithTypes(item); },
316
+ fromBcs: function (data) { return UserAccountCap.fromBcs(data); },
317
+ bcs: UserAccountCap.bcs,
318
+ fromJSONField: function (field) { return UserAccountCap.fromJSONField(field); },
319
+ fromJSON: function (json) { return UserAccountCap.fromJSON(json); },
320
+ fromSuiParsedData: function (content) { return UserAccountCap.fromSuiParsedData(content); },
321
+ fromSuiObjectData: function (content) { return UserAccountCap.fromSuiObjectData(content); },
322
+ fetch: function (client, id) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
323
+ return [2 /*return*/, UserAccountCap.fetch(client, id)];
324
+ }); }); },
325
+ new: function (fields) {
326
+ return new UserAccountCap([], fields);
327
+ },
328
+ kind: "StructClassReified",
329
+ };
330
+ };
331
+ Object.defineProperty(UserAccountCap, "r", {
332
+ get: function () {
333
+ return UserAccountCap.reified();
334
+ },
335
+ enumerable: false,
336
+ configurable: true
337
+ });
338
+ UserAccountCap.phantom = function () {
339
+ return (0, reified_1.phantom)(UserAccountCap.reified());
340
+ };
341
+ Object.defineProperty(UserAccountCap, "p", {
342
+ get: function () {
343
+ return UserAccountCap.phantom();
344
+ },
345
+ enumerable: false,
346
+ configurable: true
347
+ });
348
+ Object.defineProperty(UserAccountCap, "bcs", {
349
+ get: function () {
350
+ return bcs_1.bcs.struct("UserAccountCap", {
351
+ id: structs_2.UID.bcs,
352
+ owner: bcs_1.bcs.bytes(32).transform({ input: function (val) { return (0, utils_1.fromHEX)(val); }, output: function (val) { return (0, utils_1.toHEX)(val); } }),
353
+ user_account_id: structs_2.ID.bcs,
354
+ });
355
+ },
356
+ enumerable: false,
357
+ configurable: true
358
+ });
359
+ UserAccountCap.fromFields = function (fields) {
360
+ return UserAccountCap.reified().new({
361
+ id: (0, reified_1.decodeFromFields)(structs_2.UID.reified(), fields.id),
362
+ owner: (0, reified_1.decodeFromFields)("address", fields.owner),
363
+ userAccountId: (0, reified_1.decodeFromFields)(structs_2.ID.reified(), fields.user_account_id),
364
+ });
365
+ };
366
+ UserAccountCap.fromFieldsWithTypes = function (item) {
367
+ if (!isUserAccountCap(item.type)) {
368
+ throw new Error("not a UserAccountCap type");
369
+ }
370
+ return UserAccountCap.reified().new({
371
+ id: (0, reified_1.decodeFromFieldsWithTypes)(structs_2.UID.reified(), item.fields.id),
372
+ owner: (0, reified_1.decodeFromFieldsWithTypes)("address", item.fields.owner),
373
+ userAccountId: (0, reified_1.decodeFromFieldsWithTypes)(structs_2.ID.reified(), item.fields.user_account_id),
374
+ });
375
+ };
376
+ UserAccountCap.fromBcs = function (data) {
377
+ return UserAccountCap.fromFields(UserAccountCap.bcs.parse(data));
378
+ };
379
+ UserAccountCap.prototype.toJSONField = function () {
380
+ return {
381
+ id: this.id,
382
+ owner: this.owner,
383
+ userAccountId: this.userAccountId,
384
+ };
385
+ };
386
+ UserAccountCap.prototype.toJSON = function () {
387
+ return __assign({ $typeName: this.$typeName, $typeArgs: this.$typeArgs }, this.toJSONField());
388
+ };
389
+ UserAccountCap.fromJSONField = function (field) {
390
+ return UserAccountCap.reified().new({
391
+ id: (0, reified_1.decodeFromJSONField)(structs_2.UID.reified(), field.id),
392
+ owner: (0, reified_1.decodeFromJSONField)("address", field.owner),
393
+ userAccountId: (0, reified_1.decodeFromJSONField)(structs_2.ID.reified(), field.userAccountId),
394
+ });
395
+ };
396
+ UserAccountCap.fromJSON = function (json) {
397
+ if (json.$typeName !== UserAccountCap.$typeName) {
398
+ throw new Error("not a WithTwoGenerics json object");
399
+ }
400
+ return UserAccountCap.fromJSONField(json);
401
+ };
402
+ UserAccountCap.fromSuiParsedData = function (content) {
403
+ if (content.dataType !== "moveObject") {
404
+ throw new Error("not an object");
405
+ }
406
+ if (!isUserAccountCap(content.type)) {
407
+ throw new Error("object at ".concat(content.fields.id, " is not a UserAccountCap object"));
408
+ }
409
+ return UserAccountCap.fromFieldsWithTypes(content);
410
+ };
411
+ UserAccountCap.fromSuiObjectData = function (data) {
412
+ if (data.bcs) {
413
+ if (data.bcs.dataType !== "moveObject" || !isUserAccountCap(data.bcs.type)) {
414
+ throw new Error("object at is not a UserAccountCap object");
415
+ }
416
+ return UserAccountCap.fromBcs((0, utils_1.fromB64)(data.bcs.bcsBytes));
417
+ }
418
+ if (data.content) {
419
+ return UserAccountCap.fromSuiParsedData(data.content);
420
+ }
421
+ throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
422
+ };
423
+ UserAccountCap.fetch = function (client, id) {
424
+ return __awaiter(this, void 0, void 0, function () {
425
+ var res;
426
+ var _a, _b;
427
+ return __generator(this, function (_c) {
428
+ switch (_c.label) {
429
+ case 0: return [4 /*yield*/, client.getObject({ id: id, options: { showBcs: true } })];
430
+ case 1:
431
+ res = _c.sent();
432
+ if (res.error) {
433
+ throw new Error("error fetching UserAccountCap object at id ".concat(id, ": ").concat(res.error.code));
434
+ }
435
+ if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" || !isUserAccountCap(res.data.bcs.type)) {
436
+ throw new Error("object at id ".concat(id, " is not a UserAccountCap object"));
437
+ }
438
+ return [2 /*return*/, UserAccountCap.fromSuiObjectData(res.data)];
439
+ }
440
+ });
441
+ });
442
+ };
443
+ UserAccountCap.$typeName = "".concat(index_1.PKG_V1, "::user_account::UserAccountCap");
444
+ UserAccountCap.$numTypeParams = 0;
445
+ UserAccountCap.$isPhantom = [];
446
+ return UserAccountCap;
447
+ }());
448
+ exports.UserAccountCap = UserAccountCap;
@@ -1,5 +1,5 @@
1
1
  import { TOKEN } from "@typus/typus-sdk/dist/src/constants";
2
- export type actionType = "Place Order" | "Cancel Order" | "Order Filled (Open Position)" | "Order Filled (Close Position)" | "Realized PnL" | "Modify Collateral" | "Exercise Position" | "Liquidation" | "Force Close Position" | "Swap";
2
+ export type actionType = "Place Order" | "Cancel Order" | "Order Filled (Open Position)" | "Order Filled (Close Position)" | "Realized PnL" | "Modify Collateral" | "Exercise Position" | "Liquidation" | "Force Close Position" | "Swap" | "Realized Funding";
3
3
  export type sideType = "Long" | "Short";
4
4
  export type orderType = "Market" | "Limit" | "Take Profit" | "Stop Loss";
5
5
  export type statusType = "Open" | "Filled" | "Canceled";
@@ -81,7 +81,7 @@ function parseUserHistory(raw_events) {
81
81
  return __generator(this, function (_a) {
82
82
  events = [];
83
83
  raw_events.forEach(function (event) {
84
- var _a, _b;
84
+ var _a;
85
85
  var type = event.contents.type.repr;
86
86
  if (type.endsWith("PythPrice")) {
87
87
  return;
@@ -93,7 +93,7 @@ function parseUserHistory(raw_events) {
93
93
  // console.log(tx_digest);
94
94
  // console.log(json);
95
95
  // console.log(timestamp);
96
- var _c = __read(type.split("::"), 3), pkg = _c[0], mod = _c[1], name = _c[2];
96
+ var _b = __read(type.split("::"), 3), pkg = _b[0], mod = _b[1], name = _b[2];
97
97
  switch (name) {
98
98
  case structs_2.CreateTradingOrderEvent.$typeName.split("::")[2]:
99
99
  case structs_2.CreateTradingOrderWithBidReceiptsEvent.$typeName.split("::")[2]:
@@ -186,16 +186,61 @@ function parseUserHistory(raw_events) {
186
186
  };
187
187
  events.push(e);
188
188
  break;
189
- case structs_1.RealizeFundingEvent.$typeName.split("::")[2]:
189
+ case structs_1.RemovePositionEvent.$typeName.split("::")[2]:
190
190
  // same tx with order filled
191
- var index = events.findLastIndex(function (e) { return e.tx_digest == tx_digest; });
191
+ var index = events.findLastIndex(function (e) { return e.tx_digest == tx_digest && e.action == "Order Filled (Close Position)"; });
192
192
  // console.log(index);
193
193
  if (index !== -1) {
194
194
  // true => user paid to pool
195
- var x = json.realized_funding_sign ? json.realized_funding_fee_usd / Math.pow(10, 9) : -json.realized_funding_fee_usd / Math.pow(10, 9);
196
- events[index] = __assign(__assign({}, events[index]), { realized_pnl: ((_b = events[index].realized_pnl) !== null && _b !== void 0 ? _b : 0) - x });
195
+ var remaining_collateral_amount = json.remaining_collateral_amount / Math.pow(10, (0, constants_1.assetToDecimal)(events[index].collateral_token));
196
+ events[index] = __assign(__assign({}, events[index]), { collateral: remaining_collateral_amount + Math.max(0, events[index].realized_pnl) });
197
197
  }
198
198
  break;
199
+ case structs_1.RealizeFundingEvent.$typeName.split("::")[2]:
200
+ // // same tx with order filled
201
+ // var index = events.findLastIndex((e) => e.tx_digest == tx_digest);
202
+ // // console.log(index);
203
+ // if (index !== -1) {
204
+ // // true => user paid to pool
205
+ // let x = json.realized_funding_sign ? json.realized_funding_fee_usd / 10 ** 9 : -json.realized_funding_fee_usd / 10 ** 9;
206
+ // events[index] = {
207
+ // ...events[index],
208
+ // realized_pnl: (events[index].realized_pnl ?? 0) - x,
209
+ // };
210
+ // }
211
+ var base_token = (0, constants_1.typeArgToAsset)(json.symbol.base_token.name);
212
+ var collateral_token = (0, constants_1.typeArgToAsset)(json.collateral_token.name);
213
+ var market = "".concat(base_token, "/USD");
214
+ var related = events.find(function (e) { return e.position_id === json.position_id && e.market === market; });
215
+ // if realized_funding_sign is true, user pays to pool
216
+ var realized_funding_fee = json.realized_funding_sign
217
+ ? -json.realized_funding_fee / Math.pow(10, (0, constants_1.assetToDecimal)(collateral_token))
218
+ : json.realized_funding_fee / Math.pow(10, (0, constants_1.assetToDecimal)(collateral_token));
219
+ var realized_funding_fee_usd = json.realized_funding_sign
220
+ ? -json.realized_funding_fee_usd / Math.pow(10, 9)
221
+ : json.realized_funding_fee_usd / Math.pow(10, 9);
222
+ var e = {
223
+ action: "Realized Funding",
224
+ typeName: name,
225
+ order_id: undefined,
226
+ position_id: json.position_id,
227
+ market: market,
228
+ side: related === null || related === void 0 ? void 0 : related.side,
229
+ order_type: related === null || related === void 0 ? void 0 : related.order_type,
230
+ status: "Filled",
231
+ size: related === null || related === void 0 ? void 0 : related.size,
232
+ base_token: base_token,
233
+ collateral: realized_funding_fee,
234
+ collateral_token: collateral_token,
235
+ price: undefined,
236
+ realized_pnl: realized_funding_fee_usd,
237
+ timestamp: timestamp,
238
+ tx_digest: tx_digest,
239
+ dov_index: related === null || related === void 0 ? void 0 : related.dov_index,
240
+ sender: "user",
241
+ };
242
+ events.push(e);
243
+ break;
199
244
  case structs_2.CancelTradingOrderEvent.$typeName.split("::")[2]:
200
245
  var base_token = (0, constants_1.typeArgToAsset)(json.base_token.name);
201
246
  var collateral_token = (0, constants_1.typeArgToAsset)(json.collateral_token.name);
@@ -1,6 +1,17 @@
1
1
  import { Transaction } from "@mysten/sui/transactions";
2
2
  import { PythClient, TypusConfig } from "@typus/typus-sdk/dist/src/utils";
3
3
  import { TOKEN } from "@typus/typus-sdk/dist/src/constants";
4
+ export declare function createTradingOrderWithBidReceiptByAutoBid(config: TypusConfig, tx: Transaction, pythClient: PythClient, input: {
5
+ cToken: TOKEN;
6
+ tradingToken: TOKEN;
7
+ isLong: boolean;
8
+ user: string;
9
+ index: string;
10
+ bToken: TOKEN;
11
+ signalIndex: string;
12
+ strategyIndex: string;
13
+ suiCoins?: string[];
14
+ }): Promise<Transaction>;
4
15
  export declare function createTradingOrderWithBidReceipt(config: TypusConfig, tx: Transaction, pythClient: PythClient, input: {
5
16
  cToken: TOKEN;
6
17
  tradingToken: TOKEN;