aftermath-ts-sdk 1.3.12-perps.11 → 1.3.12-pools-creation-fix.2
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/configTypes.d.ts +10 -0
- package/dist/general/types/configTypes.d.ts.map +1 -1
- package/dist/general/types/generalTypes.d.ts +0 -1
- 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 +3 -5
- package/dist/general/utils/caller.d.ts.map +1 -1
- package/dist/general/utils/caller.js +1 -9
- 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 +5 -1
- package/dist/packages/coin/coin.d.ts.map +1 -1
- package/dist/packages/coin/coin.js +12 -3
- 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 +5 -8
- 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/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 +204 -11
- package/dist/packages/perpetuals/api/perpetualsApi.d.ts.map +1 -1
- package/dist/packages/perpetuals/api/perpetualsApi.js +614 -923
- package/dist/packages/perpetuals/api/perpetualsApiCasting.d.ts +18 -11
- package/dist/packages/perpetuals/api/perpetualsApiCasting.d.ts.map +1 -1
- package/dist/packages/perpetuals/api/perpetualsApiCasting.js +190 -199
- package/dist/packages/perpetuals/perpetuals.d.ts +5 -39
- package/dist/packages/perpetuals/perpetuals.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetuals.js +18 -99
- package/dist/packages/perpetuals/perpetualsAccount.d.ts +79 -108
- package/dist/packages/perpetuals/perpetualsAccount.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsAccount.js +119 -332
- package/dist/packages/perpetuals/perpetualsCastingTypes.d.ts +148 -78
- package/dist/packages/perpetuals/perpetualsCastingTypes.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsMarket.d.ts +6 -29
- package/dist/packages/perpetuals/perpetualsMarket.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsMarket.js +16 -78
- package/dist/packages/perpetuals/perpetualsTypes.d.ts +259 -340
- package/dist/packages/perpetuals/perpetualsTypes.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsTypes.js +77 -17
- 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/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/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 -1
|
@@ -27,24 +27,21 @@ const iFixedUtils_1 = require("../../general/utils/iFixedUtils");
|
|
|
27
27
|
const utils_1 = require("../../general/utils");
|
|
28
28
|
const perpetuals_1 = require("./perpetuals");
|
|
29
29
|
const __1 = require("..");
|
|
30
|
-
const transactions_1 = require("@mysten/sui/transactions");
|
|
31
|
-
// TODO: create refresh account positions function ?
|
|
32
30
|
class PerpetualsAccount extends caller_1.Caller {
|
|
33
31
|
// =========================================================================
|
|
34
32
|
// Constructor
|
|
35
33
|
// =========================================================================
|
|
36
|
-
constructor(account, accountCap, config
|
|
34
|
+
constructor(account, accountCap, config) {
|
|
37
35
|
super(config, "perpetuals");
|
|
38
36
|
this.account = account;
|
|
39
37
|
this.accountCap = accountCap;
|
|
40
|
-
this.Provider = Provider;
|
|
41
38
|
// =========================================================================
|
|
42
39
|
// Calculations
|
|
43
40
|
// =========================================================================
|
|
44
41
|
this.calcFreeCollateralForPosition = (inputs) => {
|
|
45
42
|
var _a, _b;
|
|
46
43
|
const marketId = inputs.market.marketId;
|
|
47
|
-
const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : inputs.market
|
|
44
|
+
const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : this.emptyPosition({ market: inputs.market });
|
|
48
45
|
const funding = this.calcUnrealizedFundingsForPosition(inputs);
|
|
49
46
|
const { pnl, minInitialMargin } = this.calcPnLAndMarginForPosition(inputs);
|
|
50
47
|
let collateralUsd = iFixedUtils_1.IFixedUtils.numberFromIFixed(position.collateral) *
|
|
@@ -67,7 +64,7 @@ class PerpetualsAccount extends caller_1.Caller {
|
|
|
67
64
|
var _a, _b;
|
|
68
65
|
const { market, indexPrice, collateralPrice } = inputs;
|
|
69
66
|
const marketId = market.marketId;
|
|
70
|
-
const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b :
|
|
67
|
+
const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : this.emptyPosition({ market });
|
|
71
68
|
const funding = this.calcUnrealizedFundingsForPosition({
|
|
72
69
|
market,
|
|
73
70
|
position,
|
|
@@ -99,7 +96,7 @@ class PerpetualsAccount extends caller_1.Caller {
|
|
|
99
96
|
this.calcUnrealizedFundingsForPosition = (inputs) => {
|
|
100
97
|
var _a, _b;
|
|
101
98
|
const marketId = inputs.market.marketId;
|
|
102
|
-
const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : inputs.market
|
|
99
|
+
const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : this.emptyPosition({ market: inputs.market });
|
|
103
100
|
const baseAmount = iFixedUtils_1.IFixedUtils.numberFromIFixed(position.baseAssetAmount);
|
|
104
101
|
const isLong = Math.sign(baseAmount);
|
|
105
102
|
if (isLong < 0) {
|
|
@@ -116,8 +113,8 @@ class PerpetualsAccount extends caller_1.Caller {
|
|
|
116
113
|
this.calcPnLAndMarginForPosition = (inputs) => {
|
|
117
114
|
var _a, _b;
|
|
118
115
|
const marketId = inputs.market.marketId;
|
|
119
|
-
const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : inputs.market
|
|
120
|
-
const marginRatioInitial = 1 /
|
|
116
|
+
const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : this.emptyPosition({ market: inputs.market });
|
|
117
|
+
const marginRatioInitial = 1 / position.leverage;
|
|
121
118
|
// const marginRatioInitial = inputs.market.initialMarginRatio();
|
|
122
119
|
const marginRatioMaintenance = iFixedUtils_1.IFixedUtils.numberFromIFixed(inputs.market.marketParams.marginRatioMaintenance);
|
|
123
120
|
const baseAssetAmount = iFixedUtils_1.IFixedUtils.numberFromIFixed(position.baseAssetAmount);
|
|
@@ -134,28 +131,29 @@ class PerpetualsAccount extends caller_1.Caller {
|
|
|
134
131
|
this.calcLiquidationPriceForPosition = (inputs) => {
|
|
135
132
|
var _a, _b;
|
|
136
133
|
const marketId = inputs.market.marketId;
|
|
137
|
-
const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : inputs.market
|
|
134
|
+
const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : this.emptyPosition({ market: inputs.market });
|
|
138
135
|
const funding = this.calcUnrealizedFundingsForPosition(inputs);
|
|
136
|
+
const collateralUsd = iFixedUtils_1.IFixedUtils.numberFromIFixed(position === null || position === void 0 ? void 0 : position.collateral) *
|
|
137
|
+
inputs.collateralPrice +
|
|
138
|
+
funding;
|
|
139
139
|
const baseAssetAmount = iFixedUtils_1.IFixedUtils.numberFromIFixed(position.baseAssetAmount);
|
|
140
140
|
const quoteAssetAmount = iFixedUtils_1.IFixedUtils.numberFromIFixed(position.quoteAssetNotionalAmount);
|
|
141
|
-
const numerator = iFixedUtils_1.IFixedUtils.numberFromIFixed(position.collateral) *
|
|
142
|
-
inputs.collateralPrice +
|
|
143
|
-
funding -
|
|
144
|
-
quoteAssetAmount;
|
|
145
141
|
const MMR = iFixedUtils_1.IFixedUtils.numberFromIFixed(inputs.market.marketParams.marginRatioMaintenance);
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
142
|
+
const numerator = collateralUsd - quoteAssetAmount;
|
|
143
|
+
const price = (() => {
|
|
144
|
+
if (baseAssetAmount > 0) {
|
|
145
|
+
return numerator / ((1 - MMR) * -baseAssetAmount);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
return numerator / ((1 + MMR) * -baseAssetAmount);
|
|
149
|
+
}
|
|
150
|
+
})();
|
|
151
|
+
return price < 0 ? 0 : price;
|
|
154
152
|
};
|
|
155
153
|
this.calcFreeMarginUsdForPosition = (inputs) => {
|
|
156
154
|
var _a, _b;
|
|
157
155
|
const marketId = inputs.market.marketId;
|
|
158
|
-
const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : inputs.market
|
|
156
|
+
const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : this.emptyPosition({ market: inputs.market });
|
|
159
157
|
const totalFunding = this.calcUnrealizedFundingsForPosition(inputs);
|
|
160
158
|
const { pnl, minInitialMargin } = this.calcPnLAndMarginForPosition(inputs);
|
|
161
159
|
let collateralUsd = iFixedUtils_1.IFixedUtils.numberFromIFixed(position.collateral) *
|
|
@@ -176,7 +174,7 @@ class PerpetualsAccount extends caller_1.Caller {
|
|
|
176
174
|
zipped.forEach(([market, indexPrice]) => {
|
|
177
175
|
var _a;
|
|
178
176
|
const marketId = market.marketId;
|
|
179
|
-
const position = (_a = this.positionForMarketId({ marketId })) !== null && _a !== void 0 ? _a :
|
|
177
|
+
const position = (_a = this.positionForMarketId({ marketId })) !== null && _a !== void 0 ? _a : this.emptyPosition({ market });
|
|
180
178
|
const funding = this.calcUnrealizedFundingsForPosition({
|
|
181
179
|
market,
|
|
182
180
|
position,
|
|
@@ -202,9 +200,9 @@ class PerpetualsAccount extends caller_1.Caller {
|
|
|
202
200
|
};
|
|
203
201
|
this.closePositionTxInputs = (inputs) => {
|
|
204
202
|
var _a;
|
|
205
|
-
const { size, market, orderDatas, collateralPrice } = inputs;
|
|
203
|
+
const { size, market, walletAddress, orderDatas, collateralPrice } = inputs;
|
|
206
204
|
const marketId = market.marketId;
|
|
207
|
-
const position = (_a = this.positionForMarketId({ marketId })) !== null && _a !== void 0 ? _a :
|
|
205
|
+
const position = (_a = this.positionForMarketId({ marketId })) !== null && _a !== void 0 ? _a : this.emptyPosition({ market });
|
|
208
206
|
// TODO: move conversion to helper function, since used often
|
|
209
207
|
const ordersCollateral = __1.Coin.normalizeBalance(utils_1.Helpers.sum(orderDatas
|
|
210
208
|
.filter((orderData) => orderData.marketId === market.marketId)
|
|
@@ -216,31 +214,37 @@ class PerpetualsAccount extends caller_1.Caller {
|
|
|
216
214
|
.closePositionMarginOfError))), BigInt(0)) * BigInt(-1);
|
|
217
215
|
const positionSize = BigInt(Math.round(Math.abs(utils_1.Casting.IFixed.numberFromIFixed(position.baseAssetAmount) /
|
|
218
216
|
market.lotSize())));
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
(Number(size) / Number(positionSize)))), this.collateralDecimals());
|
|
217
|
+
const collateralChange = BigInt(Math.round(Number(fullPositionCollateralChange) *
|
|
218
|
+
(Number(size) / Number(positionSize))));
|
|
222
219
|
const positionSide = perpetuals_1.Perpetuals.positionSide(position);
|
|
223
220
|
return {
|
|
224
221
|
size,
|
|
225
222
|
marketId,
|
|
223
|
+
walletAddress,
|
|
226
224
|
collateralChange,
|
|
227
|
-
// leverage: position.leverage || 1,
|
|
228
|
-
// leverage: undefined,
|
|
229
225
|
side: positionSide === types_1.PerpetualsOrderSide.Bid
|
|
230
226
|
? types_1.PerpetualsOrderSide.Ask
|
|
231
227
|
: types_1.PerpetualsOrderSide.Bid,
|
|
232
|
-
|
|
228
|
+
hasPosition: this.positionForMarketId({ marketId }) !== undefined,
|
|
233
229
|
};
|
|
234
230
|
};
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
231
|
+
this.emptyPosition = (inputs) => {
|
|
232
|
+
const { market } = inputs;
|
|
233
|
+
return {
|
|
234
|
+
marketId: market.marketId,
|
|
235
|
+
collateralCoinType: this.accountCap.collateralCoinType,
|
|
236
|
+
collateral: BigInt(0),
|
|
237
|
+
baseAssetAmount: BigInt(0),
|
|
238
|
+
quoteAssetNotionalAmount: BigInt(0),
|
|
239
|
+
cumFundingRateLong: market.marketState.cumFundingRateLong,
|
|
240
|
+
cumFundingRateShort: market.marketState.cumFundingRateShort,
|
|
241
|
+
asksQuantity: BigInt(0),
|
|
242
|
+
bidsQuantity: BigInt(0),
|
|
243
|
+
pendingOrders: [],
|
|
244
|
+
makerFee: BigInt(1000000000000000000), // 100%
|
|
245
|
+
takerFee: BigInt(1000000000000000000), // 100%
|
|
246
|
+
leverage: 1,
|
|
247
|
+
};
|
|
244
248
|
};
|
|
245
249
|
}
|
|
246
250
|
// =========================================================================
|
|
@@ -251,81 +255,29 @@ class PerpetualsAccount extends caller_1.Caller {
|
|
|
251
255
|
// =========================================================================
|
|
252
256
|
getDepositCollateralTx(inputs) {
|
|
253
257
|
return __awaiter(this, void 0, void 0, function* () {
|
|
254
|
-
|
|
255
|
-
const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
|
|
256
|
-
return this.fetchApiTransaction("transactions/deposit-collateral", Object.assign(Object.assign({}, otherInputs), { walletAddress: this.accountCap.walletAddress, collateralCoinType: this.accountCap.collateralCoinType, accountObjectId: this.accountCap.objectId, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
|
|
257
|
-
tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction(),
|
|
258
|
-
})) }), undefined, {
|
|
259
|
-
txKind: true,
|
|
260
|
-
});
|
|
258
|
+
return this.fetchApiTransaction("transactions/deposit-collateral", Object.assign(Object.assign({}, inputs), { collateralCoinType: this.accountCap.collateralCoinType, accountCapId: this.accountCap.objectId }));
|
|
261
259
|
});
|
|
262
260
|
}
|
|
263
261
|
getWithdrawCollateralTx(inputs) {
|
|
264
262
|
return __awaiter(this, void 0, void 0, function* () {
|
|
265
|
-
|
|
266
|
-
const { withdrawAmount, recipientAddress, tx: txFromInputs } = inputs;
|
|
267
|
-
const { txKind, coinOutArg } = yield this.fetchApi("transactions/withdraw-collateral", {
|
|
268
|
-
withdrawAmount,
|
|
269
|
-
recipientAddress,
|
|
270
|
-
walletAddress: this.accountCap.walletAddress,
|
|
271
|
-
collateralCoinType: this.accountCap.collateralCoinType,
|
|
272
|
-
accountObjectId: this.accountCap.objectId,
|
|
273
|
-
txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
|
|
274
|
-
tx: txFromInputs !== null && txFromInputs !== void 0 ? txFromInputs : new transactions_1.Transaction(),
|
|
275
|
-
})),
|
|
276
|
-
});
|
|
277
|
-
const tx = transactions_1.Transaction.fromKind(txKind);
|
|
278
|
-
tx.setSender(this.accountCap.walletAddress);
|
|
279
|
-
return {
|
|
280
|
-
tx,
|
|
281
|
-
coinOutArg,
|
|
282
|
-
};
|
|
263
|
+
return this.fetchApiTransaction("transactions/withdraw-collateral", Object.assign(Object.assign({}, inputs), { collateralCoinType: this.accountCap.collateralCoinType, accountCapId: this.accountCap.objectId }));
|
|
283
264
|
});
|
|
284
265
|
}
|
|
285
266
|
getAllocateCollateralTx(inputs) {
|
|
286
267
|
return __awaiter(this, void 0, void 0, function* () {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
return this.fetchApiTransaction("transactions/allocate-collateral", {
|
|
290
|
-
marketId,
|
|
291
|
-
allocateAmount,
|
|
292
|
-
accountObjectId: this.accountCap.objectId,
|
|
293
|
-
walletAddress: this.accountCap.walletAddress,
|
|
294
|
-
txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction() })),
|
|
295
|
-
}, undefined, {
|
|
296
|
-
txKind: true,
|
|
297
|
-
});
|
|
268
|
+
const { market } = inputs;
|
|
269
|
+
return this.fetchApiTransaction("transactions/allocate-collateral", Object.assign(Object.assign({}, inputs), { packageId: market.marketData.packageId, marketInitialSharedVersion: market.marketData.initialSharedVersion, marketId: market.marketId, collateralCoinType: this.accountCap.collateralCoinType, accountCapId: this.accountCap.objectId }));
|
|
298
270
|
});
|
|
299
271
|
}
|
|
300
272
|
getDeallocateCollateralTx(inputs) {
|
|
301
273
|
return __awaiter(this, void 0, void 0, function* () {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
return this.fetchApiTransaction("transactions/deallocate-collateral", {
|
|
305
|
-
marketId,
|
|
306
|
-
deallocateAmount,
|
|
307
|
-
accountObjectId: this.accountCap.objectId,
|
|
308
|
-
walletAddress: this.accountCap.walletAddress,
|
|
309
|
-
txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction() })),
|
|
310
|
-
}, undefined, {
|
|
311
|
-
txKind: true,
|
|
312
|
-
});
|
|
274
|
+
const { market } = inputs;
|
|
275
|
+
return this.fetchApiTransaction("transactions/deallocate-collateral", Object.assign(Object.assign({}, inputs), { packageId: market.marketData.packageId, marketInitialSharedVersion: market.marketData.initialSharedVersion, marketId: market.marketId, basePriceFeedId: market.marketParams.basePriceFeedId, collateralPriceFeedId: market.marketParams.collateralPriceFeedId, collateralCoinType: this.accountCap.collateralCoinType, accountCapId: this.accountCap.objectId }));
|
|
313
276
|
});
|
|
314
277
|
}
|
|
315
278
|
getTransferCollateralTx(inputs) {
|
|
316
279
|
return __awaiter(this, void 0, void 0, function* () {
|
|
317
|
-
|
|
318
|
-
const { transferAmount, toAccountObjectId, tx } = inputs;
|
|
319
|
-
return this.fetchApiTransaction("transactions/transfer-collateral", {
|
|
320
|
-
transferAmount,
|
|
321
|
-
toAccountObjectId,
|
|
322
|
-
walletAddress: this.accountCap.walletAddress,
|
|
323
|
-
collateralCoinType: this.accountCap.collateralCoinType,
|
|
324
|
-
fromAccountObjectId: this.accountCap.objectId,
|
|
325
|
-
txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction() })),
|
|
326
|
-
}, undefined, {
|
|
327
|
-
txKind: true,
|
|
328
|
-
});
|
|
280
|
+
return this.fetchApiTransaction("transactions/transfer-collateral", Object.assign(Object.assign({}, inputs), { collateralCoinType: this.accountCap.collateralCoinType, fromAccountCapId: this.accountCap.objectId }));
|
|
329
281
|
});
|
|
330
282
|
}
|
|
331
283
|
// =========================================================================
|
|
@@ -333,119 +285,33 @@ class PerpetualsAccount extends caller_1.Caller {
|
|
|
333
285
|
// =========================================================================
|
|
334
286
|
getPlaceMarketOrderTx(inputs) {
|
|
335
287
|
return __awaiter(this, void 0, void 0, function* () {
|
|
336
|
-
|
|
337
|
-
const { tx: txFromInputs, slTp } = inputs, otherInputs = __rest(inputs, ["tx", "slTp"]);
|
|
338
|
-
const tx = txFromInputs !== null && txFromInputs !== void 0 ? txFromInputs : new transactions_1.Transaction();
|
|
339
|
-
// tx.setSender(this.accountCap.walletAddress);
|
|
340
|
-
return this.fetchApiTransaction("transactions/place-market-order", Object.assign(Object.assign({}, otherInputs), { slTp: slTp
|
|
341
|
-
? Object.assign({ walletAddress: this.accountCap.walletAddress }, slTp) : undefined, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })), walletAddress: this.accountCap.walletAddress, accountObjectId: this.accountCap.objectId, hasPosition: this.positionForMarketId(otherInputs) !== undefined }), undefined, {
|
|
342
|
-
txKind: true,
|
|
343
|
-
});
|
|
288
|
+
return this.fetchApiTransaction("transactions/market-order", Object.assign(Object.assign({}, inputs), { accountObjectId: this.accountCap.objectId, accountObjectVersion: this.accountCap.objectVersion, accountObjectDigest: this.accountCap.objectDigest, hasPosition: this.positionForMarketId(inputs) !== undefined }));
|
|
344
289
|
});
|
|
345
290
|
}
|
|
346
291
|
getPlaceLimitOrderTx(inputs) {
|
|
347
292
|
return __awaiter(this, void 0, void 0, function* () {
|
|
348
|
-
|
|
349
|
-
const { tx: txFromInputs, slTp } = inputs, otherInputs = __rest(inputs, ["tx", "slTp"]);
|
|
350
|
-
const tx = txFromInputs !== null && txFromInputs !== void 0 ? txFromInputs : new transactions_1.Transaction();
|
|
351
|
-
// tx.setSender(this.accountCap.walletAddress);
|
|
352
|
-
return this.fetchApiTransaction("transactions/place-limit-order", Object.assign(Object.assign({}, otherInputs), { slTp: slTp
|
|
353
|
-
? Object.assign({ walletAddress: this.accountCap.walletAddress }, slTp) : undefined, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })), walletAddress: this.accountCap.walletAddress, accountObjectId: this.accountCap.objectId, hasPosition: this.positionForMarketId(otherInputs) !== undefined }), undefined, {
|
|
354
|
-
txKind: true,
|
|
355
|
-
});
|
|
293
|
+
return this.fetchApiTransaction("transactions/limit-order", Object.assign(Object.assign({}, inputs), { accountObjectId: this.accountCap.objectId, accountObjectVersion: this.accountCap.objectVersion, accountObjectDigest: this.accountCap.objectDigest, hasPosition: this.positionForMarketId(inputs) !== undefined }));
|
|
356
294
|
});
|
|
357
295
|
}
|
|
358
|
-
|
|
296
|
+
getPlaceSLTPOrder(inputs) {
|
|
359
297
|
return __awaiter(this, void 0, void 0, function* () {
|
|
360
|
-
|
|
361
|
-
const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
|
|
362
|
-
return this.fetchApiTransaction("transactions/cancel-orders", Object.assign(Object.assign({}, otherInputs), { txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })), walletAddress: this.accountCap.walletAddress, accountObjectId: this.accountCap.objectId }), undefined, {
|
|
363
|
-
txKind: true,
|
|
364
|
-
});
|
|
298
|
+
return this.fetchApiTransaction("transactions/sltp-order", Object.assign(Object.assign({}, inputs), { accountObjectId: this.accountCap.objectId, accountObjectVersion: this.accountCap.objectVersion, accountObjectDigest: this.accountCap.objectDigest }));
|
|
365
299
|
});
|
|
366
300
|
}
|
|
367
|
-
|
|
301
|
+
getCancelOrderTx(inputs) {
|
|
368
302
|
return __awaiter(this, void 0, void 0, function* () {
|
|
369
|
-
|
|
370
|
-
const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
|
|
371
|
-
return this.fetchApiTransaction("transactions/cancel-stop-orders", Object.assign(Object.assign({}, otherInputs), { txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })), walletAddress: this.accountCap.walletAddress, accountObjectId: this.accountCap.objectId }), undefined, {
|
|
372
|
-
txKind: true,
|
|
373
|
-
});
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
getPlaceStopOrdersTx(inputs) {
|
|
377
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
378
|
-
var _a;
|
|
379
|
-
const { tx: txFromInputs, isSponsoredTx, stopOrders, gasCoinArg, } = inputs;
|
|
380
|
-
const tx = txFromInputs !== null && txFromInputs !== void 0 ? txFromInputs : new transactions_1.Transaction();
|
|
381
|
-
// tx.setSender(this.accountCap.walletAddress);
|
|
382
|
-
return this.fetchApiTransaction("transactions/place-stop-orders", {
|
|
383
|
-
stopOrders,
|
|
384
|
-
gasCoinArg,
|
|
385
|
-
isSponsoredTx,
|
|
386
|
-
txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })),
|
|
387
|
-
walletAddress: this.accountCap.walletAddress,
|
|
388
|
-
accountObjectId: this.accountCap.objectId,
|
|
389
|
-
}, undefined, {
|
|
390
|
-
txKind: true,
|
|
391
|
-
});
|
|
303
|
+
return this.fetchApiTransaction("transactions/cancel-order", Object.assign(Object.assign({}, inputs), { collateralCoinType: this.accountCap.collateralCoinType, accountCapId: this.accountCap.objectId }));
|
|
392
304
|
});
|
|
393
305
|
}
|
|
394
|
-
|
|
395
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
396
|
-
var _a;
|
|
397
|
-
const { tx: txFromInputs, isSponsoredTx, marketId } = inputs, slTpInputs = __rest(inputs, ["tx", "isSponsoredTx", "marketId"]);
|
|
398
|
-
const position = this.positionForMarketId({ marketId });
|
|
399
|
-
if (!position)
|
|
400
|
-
throw new Error("you have no position for this market");
|
|
401
|
-
const tx = txFromInputs !== null && txFromInputs !== void 0 ? txFromInputs : new transactions_1.Transaction();
|
|
402
|
-
// tx.setSender(this.accountCap.walletAddress);
|
|
403
|
-
return this.fetchApiTransaction("transactions/place-sl-tp-orders", Object.assign(Object.assign({}, slTpInputs), { marketId, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })), walletAddress: this.accountCap.walletAddress, accountObjectId: this.accountCap.objectId, positionSide: perpetuals_1.Perpetuals.positionSide({
|
|
404
|
-
baseAssetAmount: position.baseAssetAmount,
|
|
405
|
-
}) }), undefined, {
|
|
406
|
-
txKind: true,
|
|
407
|
-
});
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
getEditStopOrdersTx(inputs) {
|
|
411
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
412
|
-
var _a;
|
|
413
|
-
const { tx: txFromInputs, stopOrders } = inputs;
|
|
414
|
-
const tx = txFromInputs !== null && txFromInputs !== void 0 ? txFromInputs : new transactions_1.Transaction();
|
|
415
|
-
// tx.setSender(this.accountCap.walletAddress);
|
|
416
|
-
return this.fetchApiTransaction("transactions/edit-stop-orders", {
|
|
417
|
-
stopOrders,
|
|
418
|
-
txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })),
|
|
419
|
-
walletAddress: this.accountCap.walletAddress,
|
|
420
|
-
accountObjectId: this.accountCap.objectId,
|
|
421
|
-
}, undefined, {
|
|
422
|
-
txKind: true,
|
|
423
|
-
});
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
getReduceOrderTx(inputs) {
|
|
306
|
+
getCancelOrdersTx(inputs) {
|
|
427
307
|
return __awaiter(this, void 0, void 0, function* () {
|
|
428
|
-
|
|
429
|
-
const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
|
|
430
|
-
return this.fetchApiTransaction("transactions/reduce-order", Object.assign(Object.assign({}, otherInputs), { txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })), walletAddress: this.accountCap.walletAddress, accountObjectId: this.accountCap.objectId }), undefined, {
|
|
431
|
-
txKind: true,
|
|
432
|
-
});
|
|
308
|
+
return this.fetchApiTransaction("transactions/cancel-orders", Object.assign(Object.assign({}, inputs), { collateralCoinType: this.accountCap.collateralCoinType, accountCapId: this.accountCap.objectId }));
|
|
433
309
|
});
|
|
434
310
|
}
|
|
435
|
-
|
|
311
|
+
getReduceOrdersTx(inputs) {
|
|
436
312
|
return __awaiter(this, void 0, void 0, function* () {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
return this.fetchApiTransaction("transactions/set-leverage", {
|
|
440
|
-
leverage,
|
|
441
|
-
marketId,
|
|
442
|
-
collateralChange,
|
|
443
|
-
txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })),
|
|
444
|
-
walletAddress: this.accountCap.walletAddress,
|
|
445
|
-
accountObjectId: this.accountCap.objectId,
|
|
446
|
-
}, undefined, {
|
|
447
|
-
txKind: true,
|
|
448
|
-
});
|
|
313
|
+
const { market, orderDatas } = inputs;
|
|
314
|
+
return this.fetchApiTransaction("transactions/reduce-orders", Object.assign(Object.assign({}, inputs), { orderIds: orderDatas.map((order) => order.orderId), sizesToSubtract: orderDatas.map((order) => order.sizeToSubtract), packageId: market.marketData.packageId, marketInitialSharedVersion: market.marketData.initialSharedVersion, marketId: market.marketId, basePriceFeedId: market.marketParams.basePriceFeedId, collateralPriceFeedId: market.marketParams.collateralPriceFeedId, collateralCoinType: this.accountCap.collateralCoinType, accountCapId: this.accountCap.objectId }));
|
|
449
315
|
});
|
|
450
316
|
}
|
|
451
317
|
// =========================================================================
|
|
@@ -453,52 +319,77 @@ class PerpetualsAccount extends caller_1.Caller {
|
|
|
453
319
|
// =========================================================================
|
|
454
320
|
getClosePositionTx(inputs) {
|
|
455
321
|
return __awaiter(this, void 0, void 0, function* () {
|
|
456
|
-
return this.getPlaceMarketOrderTx(
|
|
322
|
+
return this.getPlaceMarketOrderTx(this.closePositionTxInputs(inputs));
|
|
457
323
|
});
|
|
458
324
|
}
|
|
459
325
|
// =========================================================================
|
|
460
|
-
//
|
|
326
|
+
// Inspections
|
|
461
327
|
// =========================================================================
|
|
462
|
-
|
|
463
|
-
|
|
328
|
+
setPositionLeverage(inputs) {
|
|
329
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
330
|
+
return this.fetchApi(`${this.accountCap.collateralCoinType}/accounts/${this.accountCap.accountId}/set-position-leverage`, inputs);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
// public async getAllPositionLeverages(): Promise<
|
|
334
|
+
// {
|
|
335
|
+
// marketId: PerpetualsMarketId;
|
|
336
|
+
// leverage: number;
|
|
337
|
+
// }[]
|
|
338
|
+
// > {
|
|
339
|
+
// return this.fetchApi(
|
|
340
|
+
// `${this.accountCap.collateralCoinType}/accounts/${this.accountCap.accountId}/position-leverages`
|
|
341
|
+
// );
|
|
342
|
+
// }
|
|
343
|
+
getPositionLeverages(inputs) {
|
|
344
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
345
|
+
return this.fetchApi(`${this.accountCap.collateralCoinType}/accounts/${this.accountCap.accountId}/position-leverages/${JSON.stringify(inputs.marketIds)}`);
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
setPositionLeverageMessageToSign(inputs) {
|
|
464
349
|
return {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
.replaceAll("n", ""),
|
|
469
|
-
clearing_house_ids: (_a = inputs === null || inputs === void 0 ? void 0 : inputs.marketIds) !== null && _a !== void 0 ? _a : [],
|
|
350
|
+
account_id: Number(this.accountCap.accountId),
|
|
351
|
+
market_id: inputs.marketId,
|
|
352
|
+
leverage: inputs.leverage,
|
|
470
353
|
};
|
|
471
354
|
}
|
|
472
|
-
|
|
355
|
+
getOrderPreview(inputs, abortSignal) {
|
|
473
356
|
return __awaiter(this, void 0, void 0, function* () {
|
|
474
|
-
|
|
357
|
+
const response = yield this.fetchApi("preview-order", Object.assign(Object.assign({}, inputs), { accountId: this.accountCap.accountId, collateralCoinType: this.accountCap.collateralCoinType }), abortSignal);
|
|
358
|
+
if ("error" in response)
|
|
359
|
+
return response;
|
|
360
|
+
const { collateralChange } = response, remainingResponse = __rest(response, ["collateralChange"]);
|
|
361
|
+
return Object.assign(Object.assign({}, remainingResponse), { collateralChange: __1.Coin.normalizeBalance(collateralChange, this.collateralDecimals()) });
|
|
475
362
|
});
|
|
476
363
|
}
|
|
477
|
-
getCancelOrdersPreview(inputs
|
|
364
|
+
getCancelOrdersPreview(inputs) {
|
|
478
365
|
return __awaiter(this, void 0, void 0, function* () {
|
|
479
366
|
// NOTE: should this case return an error instead ?
|
|
480
367
|
if (Object.keys(inputs.marketIdsToData).length <= 0)
|
|
481
368
|
return {
|
|
482
|
-
collateralChange: 0,
|
|
369
|
+
collateralChange: BigInt(0),
|
|
483
370
|
marketIdsToPositionAfterCancelOrders: {},
|
|
484
371
|
};
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
372
|
+
const response = yield this.fetchApi("preview-cancel-orders", Object.assign(Object.assign({}, inputs), { accountId: this.accountCap.accountId, collateralCoinType: this.accountCap.collateralCoinType }));
|
|
373
|
+
if ("error" in response)
|
|
374
|
+
return response;
|
|
375
|
+
return {
|
|
376
|
+
marketIdsToPositionAfterCancelOrders: response.marketIdsToPositionAfterCancelOrders,
|
|
377
|
+
collateralChange: __1.Coin.normalizeBalance(response.collateralChange, this.collateralDecimals()),
|
|
378
|
+
};
|
|
491
379
|
});
|
|
492
380
|
}
|
|
493
|
-
|
|
381
|
+
getReduceOrdersPreview(inputs) {
|
|
494
382
|
return __awaiter(this, void 0, void 0, function* () {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
383
|
+
// NOTE: should this case not throw an error instead ?
|
|
384
|
+
if (Object.keys(inputs.orderDatas).length <= 0)
|
|
385
|
+
throw new Error("no orderDatas provided");
|
|
386
|
+
const response = yield this.fetchApi("preview-reduce-orders", Object.assign(Object.assign({}, inputs), { orderIds: inputs.orderDatas.map((order) => order.orderId), sizesToSubtract: inputs.orderDatas.map((order) => order.sizeToSubtract), accountId: this.accountCap.accountId, collateralCoinType: this.accountCap.collateralCoinType }));
|
|
387
|
+
if ("error" in response)
|
|
388
|
+
return response;
|
|
389
|
+
return {
|
|
390
|
+
positionAfterReduceOrders: response.positionAfterReduceOrders,
|
|
391
|
+
collateralChange: __1.Coin.normalizeBalance(response.collateralChange, this.collateralDecimals()),
|
|
392
|
+
};
|
|
502
393
|
});
|
|
503
394
|
}
|
|
504
395
|
getOrderDatas() {
|
|
@@ -512,40 +403,19 @@ class PerpetualsAccount extends caller_1.Caller {
|
|
|
512
403
|
], []);
|
|
513
404
|
if (orderDatas.length <= 0)
|
|
514
405
|
return [];
|
|
515
|
-
return this.fetchApi(
|
|
516
|
-
accountId: this.accountCap.accountId,
|
|
406
|
+
return this.fetchApi(`${this.accountCap.collateralCoinType}/accounts/${this.accountCap.accountId}/order-datas`, {
|
|
517
407
|
orderDatas,
|
|
518
408
|
});
|
|
519
409
|
});
|
|
520
410
|
}
|
|
521
|
-
getStopOrderDatas(inputs) {
|
|
522
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
523
|
-
const { bytes, signature, marketIds } = inputs;
|
|
524
|
-
return this.fetchApi("account/stop-order-datas", {
|
|
525
|
-
bytes,
|
|
526
|
-
signature,
|
|
527
|
-
accountId: this.accountCap.accountId,
|
|
528
|
-
walletAddress: this.accountCap.walletAddress,
|
|
529
|
-
marketIds: marketIds !== null && marketIds !== void 0 ? marketIds : [],
|
|
530
|
-
});
|
|
531
|
-
});
|
|
532
|
-
}
|
|
533
411
|
getCollateralHistory(inputs) {
|
|
534
412
|
return __awaiter(this, void 0, void 0, function* () {
|
|
535
|
-
return this.fetchApi(
|
|
413
|
+
return this.fetchApi(`${this.accountCap.collateralCoinType}/accounts/${this.accountCap.accountId}/collateral-history`, inputs);
|
|
536
414
|
});
|
|
537
415
|
}
|
|
538
416
|
getOrderHistory(inputs) {
|
|
539
417
|
return __awaiter(this, void 0, void 0, function* () {
|
|
540
|
-
return this.fetchApi(
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
getMarginHistory() {
|
|
544
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
545
|
-
return this.fetchApi("account/trade-history", {
|
|
546
|
-
accountId: this.accountCap.accountId,
|
|
547
|
-
collateralCoinType: this.accountCap.collateralCoinType,
|
|
548
|
-
});
|
|
418
|
+
return this.fetchApi(`${this.accountCap.collateralCoinType}/accounts/${this.accountCap.accountId}/order-history`, inputs);
|
|
549
419
|
});
|
|
550
420
|
}
|
|
551
421
|
// =========================================================================
|
|
@@ -559,91 +429,8 @@ class PerpetualsAccount extends caller_1.Caller {
|
|
|
559
429
|
return undefined;
|
|
560
430
|
}
|
|
561
431
|
}
|
|
562
|
-
nonSlTpStopOrderDatas(inputs) {
|
|
563
|
-
const { stopOrderDatas } = inputs;
|
|
564
|
-
const slTpOrders = this.slTpStopOrderDatas(inputs);
|
|
565
|
-
const stopOrders = stopOrderDatas.filter((stopOrder) => !(slTpOrders !== null && slTpOrders !== void 0 ? slTpOrders : [])
|
|
566
|
-
.map((slTpOrder) => JSON.stringify(slTpOrder))
|
|
567
|
-
.includes(JSON.stringify(stopOrder)));
|
|
568
|
-
return stopOrders.length <= 0 ? undefined : stopOrders;
|
|
569
|
-
}
|
|
570
|
-
slTpStopOrderDatas(inputs) {
|
|
571
|
-
const { stopOrderDatas } = inputs;
|
|
572
|
-
let slTpOrders = [];
|
|
573
|
-
for (const { marketId } of this.account.positions) {
|
|
574
|
-
const { fullSlOrder, fullTpOrder, partialSlOrders, partialTpOrders, } = this.slTpStopOrderDatasForMarketId({
|
|
575
|
-
marketId,
|
|
576
|
-
stopOrderDatas,
|
|
577
|
-
});
|
|
578
|
-
slTpOrders = [
|
|
579
|
-
...slTpOrders,
|
|
580
|
-
...(fullSlOrder ? [fullSlOrder] : []),
|
|
581
|
-
...(fullTpOrder ? [fullTpOrder] : []),
|
|
582
|
-
...(partialSlOrders !== null && partialSlOrders !== void 0 ? partialSlOrders : []),
|
|
583
|
-
...(partialTpOrders !== null && partialTpOrders !== void 0 ? partialTpOrders : []),
|
|
584
|
-
];
|
|
585
|
-
}
|
|
586
|
-
return slTpOrders.length <= 0 ? undefined : slTpOrders;
|
|
587
|
-
}
|
|
588
|
-
nonSlTpStopOrderDatasForMarketId(inputs) {
|
|
589
|
-
const { marketId, stopOrderDatas } = inputs;
|
|
590
|
-
const position = this.positionForMarketId({ marketId });
|
|
591
|
-
if (!position)
|
|
592
|
-
return undefined;
|
|
593
|
-
const { fullSlOrder, fullTpOrder, partialSlOrders, partialTpOrders } = this.slTpStopOrderDatasForMarketId(inputs);
|
|
594
|
-
const stopOrders = stopOrderDatas.filter((stopOrder) => ![
|
|
595
|
-
...(fullSlOrder ? [fullSlOrder] : []),
|
|
596
|
-
...(fullTpOrder ? [fullTpOrder] : []),
|
|
597
|
-
...(partialSlOrders !== null && partialSlOrders !== void 0 ? partialSlOrders : []),
|
|
598
|
-
...(partialTpOrders !== null && partialTpOrders !== void 0 ? partialTpOrders : []),
|
|
599
|
-
]
|
|
600
|
-
.map((slTpOrder) => JSON.stringify(slTpOrder))
|
|
601
|
-
.includes(JSON.stringify(stopOrder)));
|
|
602
|
-
return stopOrders.length <= 0 ? undefined : stopOrders;
|
|
603
|
-
}
|
|
604
|
-
slTpStopOrderDatasForMarketId(inputs) {
|
|
605
|
-
const { marketId, stopOrderDatas } = inputs;
|
|
606
|
-
const position = this.positionForMarketId({ marketId });
|
|
607
|
-
if (!position || position.baseAssetAmount === BigInt(0)) {
|
|
608
|
-
return {
|
|
609
|
-
fullSlOrder: undefined,
|
|
610
|
-
fullTpOrder: undefined,
|
|
611
|
-
partialSlOrders: undefined,
|
|
612
|
-
partialTpOrders: undefined,
|
|
613
|
-
};
|
|
614
|
-
}
|
|
615
|
-
const side = !position ? undefined : perpetuals_1.Perpetuals.positionSide(position);
|
|
616
|
-
// TODO: clean this up
|
|
617
|
-
const fullSlOrder = stopOrderDatas.find((order) => order.marketId === marketId &&
|
|
618
|
-
order.slTp &&
|
|
619
|
-
order.side !== side &&
|
|
620
|
-
order.slTp.isStopLoss &&
|
|
621
|
-
order.size >= utils_1.Casting.i64MaxBigInt);
|
|
622
|
-
const fullTpOrder = stopOrderDatas.find((order) => order.marketId === marketId &&
|
|
623
|
-
order.slTp &&
|
|
624
|
-
order.side !== side &&
|
|
625
|
-
!order.slTp.isStopLoss &&
|
|
626
|
-
order.size >= utils_1.Casting.i64MaxBigInt);
|
|
627
|
-
const partialSlOrders = stopOrderDatas.filter((order) => order.marketId === marketId &&
|
|
628
|
-
order.slTp &&
|
|
629
|
-
order.side !== side &&
|
|
630
|
-
order.slTp.isStopLoss &&
|
|
631
|
-
order.size < utils_1.Casting.i64MaxBigInt);
|
|
632
|
-
const partialTpOrders = stopOrderDatas.filter((order) => order.marketId === marketId &&
|
|
633
|
-
order.slTp &&
|
|
634
|
-
order.side !== side &&
|
|
635
|
-
!order.slTp.isStopLoss &&
|
|
636
|
-
order.size < utils_1.Casting.i64MaxBigInt);
|
|
637
|
-
return {
|
|
638
|
-
fullSlOrder,
|
|
639
|
-
fullTpOrder,
|
|
640
|
-
partialSlOrders: partialSlOrders.length <= 0 ? undefined : partialSlOrders,
|
|
641
|
-
partialTpOrders: partialTpOrders.length <= 0 ? undefined : partialTpOrders,
|
|
642
|
-
};
|
|
643
|
-
}
|
|
644
432
|
collateral() {
|
|
645
|
-
return
|
|
646
|
-
utils_1.Casting.IFixed.numberFromIFixed(this.accountCap.subAccount.collateral));
|
|
433
|
+
return utils_1.Casting.IFixed.numberFromIFixed(this.accountCap.collateral);
|
|
647
434
|
}
|
|
648
435
|
collateralDecimals() {
|
|
649
436
|
return this.accountCap.collateralDecimals;
|