@typus/typus-perp-sdk 1.0.22 → 1.0.24
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/src/user/history.js
CHANGED
|
@@ -46,6 +46,22 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
46
46
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
50
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
51
|
+
if (!m) return o;
|
|
52
|
+
var i = m.call(o), r, ar = [], e;
|
|
53
|
+
try {
|
|
54
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
55
|
+
}
|
|
56
|
+
catch (error) { e = { error: error }; }
|
|
57
|
+
finally {
|
|
58
|
+
try {
|
|
59
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
60
|
+
}
|
|
61
|
+
finally { if (e) throw e.error; }
|
|
62
|
+
}
|
|
63
|
+
return ar;
|
|
64
|
+
};
|
|
49
65
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
66
|
exports.parseUserHistory = parseUserHistory;
|
|
51
67
|
exports.getGraphQLEvents = getGraphQLEvents;
|
|
@@ -56,6 +72,7 @@ var structs_1 = require("../typus_perp/position/structs");
|
|
|
56
72
|
var structs_2 = require("../typus_perp/trading/structs");
|
|
57
73
|
var structs_3 = require("../../src/typus_perp/lp-pool/structs");
|
|
58
74
|
var sentio_1 = require("../../src/api/sentio");
|
|
75
|
+
var src_1 = require("../../src");
|
|
59
76
|
function parseUserHistory(raw_events) {
|
|
60
77
|
return __awaiter(this, void 0, void 0, function () {
|
|
61
78
|
var events;
|
|
@@ -74,9 +91,10 @@ function parseUserHistory(raw_events) {
|
|
|
74
91
|
// console.log(tx_digest);
|
|
75
92
|
// console.log(json);
|
|
76
93
|
// console.log(timestamp);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
case structs_2.
|
|
94
|
+
var _c = __read(type.split("::"), 3), pkg = _c[0], mod = _c[1], name = _c[2];
|
|
95
|
+
switch (name) {
|
|
96
|
+
case structs_2.CreateTradingOrderEvent.name:
|
|
97
|
+
case structs_2.CreateTradingOrderWithBidReceiptsEvent.name:
|
|
80
98
|
var base_token = (0, constants_1.typeArgToAsset)(json.base_token.name);
|
|
81
99
|
var collateral_token = (0, constants_1.typeArgToAsset)(json.collateral_token.name);
|
|
82
100
|
var market = "".concat(base_token, "/USD");
|
|
@@ -119,7 +137,7 @@ function parseUserHistory(raw_events) {
|
|
|
119
137
|
};
|
|
120
138
|
events.push(e);
|
|
121
139
|
break;
|
|
122
|
-
case structs_1.OrderFilledEvent
|
|
140
|
+
case structs_1.OrderFilledEvent.name:
|
|
123
141
|
var base_token = (0, constants_1.typeArgToAsset)(json.symbol.base_token.name);
|
|
124
142
|
var collateral_token = (0, constants_1.typeArgToAsset)(json.collateral_token.name);
|
|
125
143
|
var market = "".concat(base_token, "/USD");
|
|
@@ -159,7 +177,7 @@ function parseUserHistory(raw_events) {
|
|
|
159
177
|
};
|
|
160
178
|
events.push(e);
|
|
161
179
|
break;
|
|
162
|
-
case structs_1.RealizeFundingEvent
|
|
180
|
+
case structs_1.RealizeFundingEvent.name:
|
|
163
181
|
// same tx with order filled
|
|
164
182
|
var index = events.findLastIndex(function (e) { return e.tx_digest == tx_digest; });
|
|
165
183
|
// console.log(index);
|
|
@@ -169,7 +187,7 @@ function parseUserHistory(raw_events) {
|
|
|
169
187
|
events[index] = __assign(__assign({}, events[index]), { realized_pnl: ((_b = events[index].realized_pnl) !== null && _b !== void 0 ? _b : 0) - x });
|
|
170
188
|
}
|
|
171
189
|
break;
|
|
172
|
-
case structs_2.CancelTradingOrderEvent
|
|
190
|
+
case structs_2.CancelTradingOrderEvent.name:
|
|
173
191
|
var base_token = (0, constants_1.typeArgToAsset)(json.base_token.name);
|
|
174
192
|
var collateral_token = (0, constants_1.typeArgToAsset)(json.collateral_token.name);
|
|
175
193
|
var market = "".concat(base_token, "/USD");
|
|
@@ -193,8 +211,8 @@ function parseUserHistory(raw_events) {
|
|
|
193
211
|
};
|
|
194
212
|
events.push(e);
|
|
195
213
|
break;
|
|
196
|
-
case structs_2.IncreaseCollateralEvent
|
|
197
|
-
case structs_2.ReleaseCollateralEvent
|
|
214
|
+
case structs_2.IncreaseCollateralEvent.name:
|
|
215
|
+
case structs_2.ReleaseCollateralEvent.name:
|
|
198
216
|
var base_token = (0, constants_1.typeArgToAsset)(json.base_token.name);
|
|
199
217
|
var collateral_token = (0, constants_1.typeArgToAsset)(json.collateral_token.name);
|
|
200
218
|
var market = "".concat(base_token, "/USD");
|
|
@@ -225,7 +243,7 @@ function parseUserHistory(raw_events) {
|
|
|
225
243
|
};
|
|
226
244
|
events.push(e);
|
|
227
245
|
break;
|
|
228
|
-
case structs_3.SwapEvent
|
|
246
|
+
case structs_3.SwapEvent.name:
|
|
229
247
|
var from_token = (0, constants_1.typeArgToAsset)(json.from_token_type.name);
|
|
230
248
|
var to_token = (0, constants_1.typeArgToAsset)(json.to_token_type.name);
|
|
231
249
|
var from_price = Number(json.oracle_price_from_token);
|
|
@@ -270,7 +288,7 @@ function getGraphQLEvents(module_1, sender_1) {
|
|
|
270
288
|
graphql = JSON.stringify({
|
|
271
289
|
query: "\n {\n events(\n last: 50,\n ".concat(before, "\n filter: {\n eventType: \"").concat(module, "\",\n sender: \"").concat(sender, "\"\n }\n ) {\n pageInfo {\n hasPreviousPage\n hasNextPage\n startCursor\n endCursor\n }\n edges { cursor }\n nodes {\n transactionBlock { digest }\n sendingModule {\n name\n package { digest }\n }\n sender { address }\n timestamp\n contents {\n type { repr }\n json\n }\n }\n }}\n "),
|
|
272
290
|
});
|
|
273
|
-
return [4 /*yield*/, fetch("https://sui-
|
|
291
|
+
return [4 /*yield*/, fetch("https://sui-".concat(src_1.NETWORK.toLowerCase(), ".mystenlabs.com/graphql"), {
|
|
274
292
|
method: "POST",
|
|
275
293
|
headers: { "Content-Type": "application/json" },
|
|
276
294
|
body: graphql,
|
|
@@ -8,8 +8,8 @@ export declare function createTradingOrderWithBidReceipt(config: TypusConfig, tx
|
|
|
8
8
|
user: string;
|
|
9
9
|
index: string;
|
|
10
10
|
bToken: TOKEN;
|
|
11
|
-
|
|
12
|
-
share
|
|
11
|
+
bidReceipts: string[];
|
|
12
|
+
share?: string;
|
|
13
13
|
}): Promise<Transaction>;
|
|
14
14
|
export declare function reduceOptionCollateralPositionSize(config: TypusConfig, tx: Transaction, pythClient: PythClient, input: {
|
|
15
15
|
cToken: TOKEN;
|
|
@@ -80,17 +80,12 @@ function createTradingOrderWithBidReceipt(config, tx, pythClient, input) {
|
|
|
80
80
|
}
|
|
81
81
|
finally { if (e_1) throw e_1.error; }
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
collateralBidReceipt = input.bidReceipt;
|
|
93
|
-
}
|
|
83
|
+
collateralBidReceipt = (0, typus_dov_single_v2_1.getSplitBidReceiptTx)(config, tx, {
|
|
84
|
+
index: input.index,
|
|
85
|
+
receipts: input.bidReceipts,
|
|
86
|
+
share: input.share, // if undefined, merge all receipts
|
|
87
|
+
recipient: input.user,
|
|
88
|
+
});
|
|
94
89
|
cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
|
|
95
90
|
bToken = constants_1.tokenType[__1.NETWORK][input.bToken];
|
|
96
91
|
baseToken = constants_1.tokenType[__1.NETWORK][BASE_TOKEN];
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typus/typus-perp-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.24",
|
|
4
4
|
"repository": "https://github.com/Typus-Lab/typus-perp-sdk.git",
|
|
5
5
|
"author": "Typus",
|
|
6
6
|
"description": "typus perp sdk",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@typus/typus-sdk": "1.6.4-
|
|
9
|
+
"@typus/typus-sdk": "1.6.4-tk9"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@types/bs58": "^4.0.1",
|