@typus/typus-perp-sdk 1.1.3 → 1.1.5-funding-collect
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/api/sentio.js +1 -1
- package/dist/src/fetch.d.ts +10 -1
- package/dist/src/fetch.js +21 -8
- package/dist/src/index.js +1 -1
- package/dist/src/typus_perp/lp-pool/functions.d.ts +34 -0
- package/dist/src/typus_perp/lp-pool/functions.js +56 -0
- package/dist/src/typus_perp/lp-pool/structs.d.ts +774 -0
- package/dist/src/typus_perp/lp-pool/structs.js +1952 -498
- package/dist/src/typus_perp/trading/functions.d.ts +105 -10
- package/dist/src/typus_perp/trading/functions.js +152 -16
- package/dist/src/typus_perp/user-account/functions.d.ts +36 -0
- package/dist/src/typus_perp/user-account/functions.js +70 -0
- package/dist/src/typus_perp/user-account/structs.d.ts +168 -0
- package/dist/src/typus_perp/user-account/structs.js +448 -0
- package/dist/src/user/history.d.ts +1 -1
- package/dist/src/user/history.js +51 -6
- package/dist/src/user/order.d.ts +4 -0
- package/dist/src/user/order.js +48 -0
- package/dist/src/user/orderWithBidReceipt.d.ts +11 -0
- package/dist/src/user/orderWithBidReceipt.js +72 -8
- package/package.json +2 -2
package/dist/src/user/history.js
CHANGED
|
@@ -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
|
|
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
|
|
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.
|
|
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
|
|
196
|
-
events[index] = __assign(__assign({}, events[index]), {
|
|
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);
|
package/dist/src/user/order.d.ts
CHANGED
|
@@ -31,3 +31,7 @@ export declare function releaseCollateral(config: TypusConfig, tx: Transaction,
|
|
|
31
31
|
amount: string;
|
|
32
32
|
suiCoins?: string[];
|
|
33
33
|
}): Promise<Transaction>;
|
|
34
|
+
export declare function collectPositionFundingFee(config: TypusConfig, tx: Transaction, pythClient: PythClient, input: {
|
|
35
|
+
position: Position;
|
|
36
|
+
suiCoins?: string[];
|
|
37
|
+
}): Promise<Transaction>;
|
package/dist/src/user/order.js
CHANGED
|
@@ -68,6 +68,7 @@ exports.zeroCoin = zeroCoin;
|
|
|
68
68
|
exports.cancelTradingOrder = cancelTradingOrder;
|
|
69
69
|
exports.increaseCollateral = increaseCollateral;
|
|
70
70
|
exports.releaseCollateral = releaseCollateral;
|
|
71
|
+
exports.collectPositionFundingFee = collectPositionFundingFee;
|
|
71
72
|
var functions_1 = require("../typus_perp/trading/functions");
|
|
72
73
|
var __1 = require("..");
|
|
73
74
|
var utils_1 = require("@typus/typus-sdk/dist/src/utils");
|
|
@@ -271,3 +272,50 @@ function releaseCollateral(config, tx, pythClient, input) {
|
|
|
271
272
|
});
|
|
272
273
|
});
|
|
273
274
|
}
|
|
275
|
+
function collectPositionFundingFee(config, tx, pythClient, input) {
|
|
276
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
277
|
+
var TOKEN, BASE_TOKEN, tokens, suiCoin, tokens_4, tokens_4_1, token, cToken, baseToken;
|
|
278
|
+
var e_4, _a;
|
|
279
|
+
return __generator(this, function (_b) {
|
|
280
|
+
switch (_b.label) {
|
|
281
|
+
case 0:
|
|
282
|
+
TOKEN = (0, constants_1.typeArgToAsset)(input.position.collateralToken.name);
|
|
283
|
+
BASE_TOKEN = (0, constants_1.typeArgToAsset)(input.position.symbol.baseToken.name);
|
|
284
|
+
tokens = Array.from(new Set([TOKEN, BASE_TOKEN]));
|
|
285
|
+
if (config.sponsored) {
|
|
286
|
+
suiCoin = (0, utils_1.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), config.sponsored);
|
|
287
|
+
}
|
|
288
|
+
return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens, suiCoin)];
|
|
289
|
+
case 1:
|
|
290
|
+
_b.sent();
|
|
291
|
+
try {
|
|
292
|
+
for (tokens_4 = __values(tokens), tokens_4_1 = tokens_4.next(); !tokens_4_1.done; tokens_4_1 = tokens_4.next()) {
|
|
293
|
+
token = tokens_4_1.value;
|
|
294
|
+
(0, utils_1.updateOracleWithPythUsd)(pythClient, tx, config.package.oracle, token);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
298
|
+
finally {
|
|
299
|
+
try {
|
|
300
|
+
if (tokens_4_1 && !tokens_4_1.done && (_a = tokens_4.return)) _a.call(tokens_4);
|
|
301
|
+
}
|
|
302
|
+
finally { if (e_4) throw e_4.error; }
|
|
303
|
+
}
|
|
304
|
+
cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
|
|
305
|
+
baseToken = constants_1.tokenType[__1.NETWORK][BASE_TOKEN];
|
|
306
|
+
(0, functions_1.collectPositionFundingFee)(tx, [cToken, baseToken], {
|
|
307
|
+
version: __1.PERP_VERSION,
|
|
308
|
+
registry: __1.MARKET,
|
|
309
|
+
poolRegistry: __1.LP_POOL,
|
|
310
|
+
marketIndex: BigInt(0),
|
|
311
|
+
poolIndex: BigInt(0),
|
|
312
|
+
typusOracleCToken: constants_1.oracle[__1.NETWORK][TOKEN],
|
|
313
|
+
typusOracleTradingSymbol: constants_1.oracle[__1.NETWORK][BASE_TOKEN],
|
|
314
|
+
clock: constants_1.CLOCK,
|
|
315
|
+
positionId: BigInt(input.position.positionId),
|
|
316
|
+
});
|
|
317
|
+
return [2 /*return*/, tx];
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
}
|
|
@@ -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;
|
|
@@ -47,14 +47,16 @@ var __values = (this && this.__values) || function(o) {
|
|
|
47
47
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
48
|
};
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.createTradingOrderWithBidReceiptByAutoBid = createTradingOrderWithBidReceiptByAutoBid;
|
|
50
51
|
exports.createTradingOrderWithBidReceipt = createTradingOrderWithBidReceipt;
|
|
51
52
|
exports.reduceOptionCollateralPositionSize = reduceOptionCollateralPositionSize;
|
|
52
53
|
var functions_1 = require("../typus_perp/trading/functions");
|
|
53
54
|
var utils_1 = require("@typus/typus-sdk/dist/src/utils");
|
|
54
55
|
var constants_1 = require("@typus/typus-sdk/dist/src/constants");
|
|
55
56
|
var typus_dov_single_v2_1 = require("@typus/typus-sdk/dist/src/typus-dov-single-v2");
|
|
57
|
+
var user_entry_1 = require("@typus/typus-sdk/dist/src/auto-bid/user-entry");
|
|
56
58
|
var __1 = require("..");
|
|
57
|
-
function
|
|
59
|
+
function createTradingOrderWithBidReceiptByAutoBid(config, tx, pythClient, input) {
|
|
58
60
|
return __awaiter(this, void 0, void 0, function () {
|
|
59
61
|
var TOKEN, BASE_TOKEN, tokens, suiCoin, tokens_1, tokens_1_1, token, collateralBidReceipt, cToken, bToken, baseToken;
|
|
60
62
|
var e_1, _a;
|
|
@@ -83,11 +85,11 @@ function createTradingOrderWithBidReceipt(config, tx, pythClient, input) {
|
|
|
83
85
|
}
|
|
84
86
|
finally { if (e_1) throw e_1.error; }
|
|
85
87
|
}
|
|
86
|
-
collateralBidReceipt = (0,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
collateralBidReceipt = (0, user_entry_1.getWithdrawBidReceiptTx)(config, tx, {
|
|
89
|
+
vaultIndex: input.index,
|
|
90
|
+
signalIndex: input.signalIndex,
|
|
91
|
+
strategyIndex: input.strategyIndex,
|
|
92
|
+
user: input.user,
|
|
91
93
|
});
|
|
92
94
|
cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
|
|
93
95
|
bToken = constants_1.tokenType[__1.NETWORK][input.bToken];
|
|
@@ -116,9 +118,9 @@ function createTradingOrderWithBidReceipt(config, tx, pythClient, input) {
|
|
|
116
118
|
});
|
|
117
119
|
});
|
|
118
120
|
}
|
|
119
|
-
function
|
|
121
|
+
function createTradingOrderWithBidReceipt(config, tx, pythClient, input) {
|
|
120
122
|
return __awaiter(this, void 0, void 0, function () {
|
|
121
|
-
var TOKEN, BASE_TOKEN, tokens, suiCoin, tokens_2, tokens_2_1, token, cToken, bToken, baseToken;
|
|
123
|
+
var TOKEN, BASE_TOKEN, tokens, suiCoin, tokens_2, tokens_2_1, token, collateralBidReceipt, cToken, bToken, baseToken;
|
|
122
124
|
var e_2, _a;
|
|
123
125
|
return __generator(this, function (_b) {
|
|
124
126
|
switch (_b.label) {
|
|
@@ -145,6 +147,68 @@ function reduceOptionCollateralPositionSize(config, tx, pythClient, input) {
|
|
|
145
147
|
}
|
|
146
148
|
finally { if (e_2) throw e_2.error; }
|
|
147
149
|
}
|
|
150
|
+
collateralBidReceipt = (0, typus_dov_single_v2_1.getSplitBidReceiptTx)(config, tx, {
|
|
151
|
+
index: input.index,
|
|
152
|
+
receipts: input.bidReceipts,
|
|
153
|
+
share: input.share, // if undefined, merge all receipts
|
|
154
|
+
recipient: input.user,
|
|
155
|
+
});
|
|
156
|
+
cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
|
|
157
|
+
bToken = constants_1.tokenType[__1.NETWORK][input.bToken];
|
|
158
|
+
baseToken = constants_1.tokenType[__1.NETWORK][BASE_TOKEN];
|
|
159
|
+
(0, functions_1.createTradingOrderWithBidReceiptV2)(tx, [cToken, bToken, baseToken], {
|
|
160
|
+
version: __1.PERP_VERSION,
|
|
161
|
+
registry: __1.MARKET,
|
|
162
|
+
poolRegistry: __1.LP_POOL,
|
|
163
|
+
marketIndex: BigInt(0),
|
|
164
|
+
poolIndex: BigInt(0),
|
|
165
|
+
typusOracleCToken: constants_1.oracle[__1.NETWORK][TOKEN],
|
|
166
|
+
typusOracleTradingSymbol: constants_1.oracle[__1.NETWORK][BASE_TOKEN],
|
|
167
|
+
clock: constants_1.CLOCK,
|
|
168
|
+
typusEcosystemVersion: config.version.typus,
|
|
169
|
+
typusUserRegistry: config.registry.typus.user,
|
|
170
|
+
typusLeaderboardRegistry: config.registry.typus.leaderboard,
|
|
171
|
+
isLong: input.isLong,
|
|
172
|
+
dovRegistry: config.registry.dov.dovSingle,
|
|
173
|
+
collateralBidReceipt: collateralBidReceipt,
|
|
174
|
+
user: input.user,
|
|
175
|
+
tailsStakingRegistry: config.registry.typus.tailsStaking,
|
|
176
|
+
competitionConfig: __1.COMPETITION_CONFIG,
|
|
177
|
+
});
|
|
178
|
+
return [2 /*return*/, tx];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function reduceOptionCollateralPositionSize(config, tx, pythClient, input) {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
185
|
+
var TOKEN, BASE_TOKEN, tokens, suiCoin, tokens_3, tokens_3_1, token, cToken, bToken, baseToken;
|
|
186
|
+
var e_3, _a;
|
|
187
|
+
return __generator(this, function (_b) {
|
|
188
|
+
switch (_b.label) {
|
|
189
|
+
case 0:
|
|
190
|
+
TOKEN = input.cToken;
|
|
191
|
+
BASE_TOKEN = input.tradingToken;
|
|
192
|
+
tokens = Array.from(new Set([TOKEN, BASE_TOKEN]));
|
|
193
|
+
if (config.sponsored) {
|
|
194
|
+
suiCoin = (0, utils_1.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), config.sponsored);
|
|
195
|
+
}
|
|
196
|
+
return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens, suiCoin)];
|
|
197
|
+
case 1:
|
|
198
|
+
_b.sent();
|
|
199
|
+
try {
|
|
200
|
+
for (tokens_3 = __values(tokens), tokens_3_1 = tokens_3.next(); !tokens_3_1.done; tokens_3_1 = tokens_3.next()) {
|
|
201
|
+
token = tokens_3_1.value;
|
|
202
|
+
(0, utils_1.updateOracleWithPythUsd)(pythClient, tx, config.package.oracle, token);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
206
|
+
finally {
|
|
207
|
+
try {
|
|
208
|
+
if (tokens_3_1 && !tokens_3_1.done && (_a = tokens_3.return)) _a.call(tokens_3);
|
|
209
|
+
}
|
|
210
|
+
finally { if (e_3) throw e_3.error; }
|
|
211
|
+
}
|
|
148
212
|
cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
|
|
149
213
|
bToken = constants_1.tokenType[__1.NETWORK][input.bToken];
|
|
150
214
|
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.1.
|
|
3
|
+
"version": "1.1.5-funding-collect",
|
|
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.8.
|
|
9
|
+
"@typus/typus-sdk": "1.8.6"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@types/bs58": "^4.0.1",
|