aftermath-ts-sdk 1.3.23-perps.21 → 1.3.23-wc-0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/general/apiHelpers/transactionsApiHelpers.d.ts +0 -3
- package/dist/general/apiHelpers/transactionsApiHelpers.d.ts.map +1 -1
- package/dist/general/apiHelpers/transactionsApiHelpers.js +0 -12
- package/dist/general/providers/aftermath.d.ts +5 -0
- package/dist/general/providers/aftermath.d.ts.map +1 -1
- package/dist/general/providers/aftermath.js +6 -1
- package/dist/general/providers/aftermathApi.d.ts +5 -0
- package/dist/general/providers/aftermathApi.d.ts.map +1 -1
- package/dist/general/providers/aftermathApi.js +5 -0
- package/dist/general/types/castingTypes.d.ts +2 -2
- package/dist/general/types/castingTypes.d.ts.map +1 -1
- package/dist/general/types/configTypes.d.ts +10 -0
- package/dist/general/types/configTypes.d.ts.map +1 -1
- package/dist/general/types/generalTypes.d.ts +0 -4
- package/dist/general/types/generalTypes.d.ts.map +1 -1
- package/dist/general/types/moveErrorsInterface.d.ts +1 -1
- package/dist/general/types/moveErrorsInterface.d.ts.map +1 -1
- package/dist/general/utils/caller.d.ts +2 -17
- package/dist/general/utils/caller.d.ts.map +1 -1
- package/dist/general/utils/caller.js +2 -35
- package/dist/general/utils/casting.d.ts +5 -4
- package/dist/general/utils/casting.d.ts.map +1 -1
- package/dist/general/utils/casting.js +5 -4
- package/dist/general/utils/helpers.d.ts +0 -1
- package/dist/general/utils/helpers.d.ts.map +1 -1
- package/dist/general/utils/helpers.js +6 -35
- package/dist/general/wallet/wallet.d.ts +1 -1
- package/dist/general/wallet/wallet.d.ts.map +1 -1
- package/dist/packages/coin/coin.d.ts +1 -1
- package/dist/packages/coin/coin.d.ts.map +1 -1
- package/dist/packages/coin/coin.js +1 -3
- package/dist/packages/farms/api/farmsApiCasting.js +27 -27
- package/dist/packages/farms/farms.d.ts +1 -1
- package/dist/packages/farms/farms.d.ts.map +1 -1
- package/dist/packages/farms/farmsStakedPosition.d.ts +1 -1
- package/dist/packages/farms/farmsStakedPosition.d.ts.map +1 -1
- package/dist/packages/farms/farmsStakingPool.d.ts +1 -1
- package/dist/packages/farms/farmsStakingPool.d.ts.map +1 -1
- package/dist/packages/faucet/api/faucetApi.d.ts +17 -9
- package/dist/packages/faucet/api/faucetApi.d.ts.map +1 -1
- package/dist/packages/faucet/api/faucetApi.js +49 -44
- package/dist/packages/faucet/api/faucetApiCasting.d.ts.map +1 -1
- package/dist/packages/faucet/api/faucetApiCasting.js +7 -10
- package/dist/packages/faucet/api/faucetApiCastingTypes.d.ts +4 -1
- package/dist/packages/faucet/api/faucetApiCastingTypes.d.ts.map +1 -1
- package/dist/packages/faucet/faucet.d.ts +1 -1
- package/dist/packages/faucet/faucet.d.ts.map +1 -1
- package/dist/packages/faucet/faucet.js +1 -1
- package/dist/packages/faucet/faucetTypes.d.ts +3 -2
- package/dist/packages/faucet/faucetTypes.d.ts.map +1 -1
- package/dist/packages/leveragedStaking/api/leveragedStakingApiCasting.js +3 -3
- package/dist/packages/multisig/multisig.d.ts +1 -1
- package/dist/packages/multisig/multisig.d.ts.map +1 -1
- package/dist/packages/nftAmm/nftAmm.d.ts +1 -1
- package/dist/packages/nftAmm/nftAmm.d.ts.map +1 -1
- package/dist/packages/oracle/api/oracleApi.d.ts +21 -0
- package/dist/packages/oracle/api/oracleApi.d.ts.map +1 -0
- package/dist/packages/oracle/api/oracleApi.js +76 -0
- package/dist/packages/oracle/api/oracleApiCasting.d.ts +6 -0
- package/dist/packages/oracle/api/oracleApiCasting.d.ts.map +1 -0
- package/dist/packages/oracle/api/oracleApiCasting.js +25 -0
- package/dist/packages/oracle/oracle.d.ts +15 -0
- package/dist/packages/oracle/oracle.d.ts.map +1 -0
- package/dist/packages/oracle/oracle.js +46 -0
- package/dist/packages/oracle/oracleCastingTypes.d.ts +11 -0
- package/dist/packages/oracle/oracleCastingTypes.d.ts.map +1 -0
- package/dist/packages/oracle/oracleCastingTypes.js +2 -0
- package/dist/packages/oracle/oracleTypes.d.ts +10 -0
- package/dist/packages/oracle/oracleTypes.d.ts.map +1 -0
- package/dist/packages/oracle/oracleTypes.js +2 -0
- package/dist/packages/perpetuals/api/perpetualsApi.d.ts +203 -11
- package/dist/packages/perpetuals/api/perpetualsApi.d.ts.map +1 -1
- package/dist/packages/perpetuals/api/perpetualsApi.js +615 -924
- package/dist/packages/perpetuals/api/perpetualsApiCasting.d.ts +21 -10
- package/dist/packages/perpetuals/api/perpetualsApiCasting.d.ts.map +1 -1
- package/dist/packages/perpetuals/api/perpetualsApiCasting.js +238 -260
- package/dist/packages/perpetuals/index.d.ts +0 -1
- package/dist/packages/perpetuals/index.d.ts.map +1 -1
- package/dist/packages/perpetuals/index.js +0 -1
- package/dist/packages/perpetuals/perpetuals.d.ts +14 -83
- package/dist/packages/perpetuals/perpetuals.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetuals.js +59 -158
- package/dist/packages/perpetuals/perpetualsAccount.d.ts +86 -158
- package/dist/packages/perpetuals/perpetualsAccount.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsAccount.js +141 -481
- package/dist/packages/perpetuals/perpetualsCastingTypes.d.ts +149 -82
- package/dist/packages/perpetuals/perpetualsCastingTypes.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsMarket.d.ts +20 -55
- package/dist/packages/perpetuals/perpetualsMarket.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsMarket.js +57 -114
- package/dist/packages/perpetuals/perpetualsTypes.d.ts +280 -586
- package/dist/packages/perpetuals/perpetualsTypes.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsTypes.js +81 -17
- package/dist/packages/pools/api/poolsApiCasting.js +3 -3
- package/dist/packages/pools/pool.d.ts +1 -1
- package/dist/packages/pools/pool.d.ts.map +1 -1
- package/dist/packages/pools/pools.d.ts +1 -1
- package/dist/packages/pools/pools.d.ts.map +1 -1
- package/dist/packages/referralVault/referralVault.d.ts +1 -1
- package/dist/packages/referralVault/referralVault.d.ts.map +1 -1
- package/dist/packages/router/api/routerApiCasting.js +1 -1
- package/dist/packages/staking/api/stakingApiCasting.js +3 -3
- package/dist/packages/staking/staking.d.ts +1 -1
- package/dist/packages/staking/staking.d.ts.map +1 -1
- package/dist/packages/sui/sui.d.ts +1 -1
- package/dist/packages/sui/sui.d.ts.map +1 -1
- package/dist/packages/suiFrens/api/suiFrensApiCasting.js +4 -4
- package/dist/packages/suiFrens/stakedSuiFren.d.ts +1 -1
- package/dist/packages/suiFrens/stakedSuiFren.d.ts.map +1 -1
- package/dist/packages/suiFrens/suiFren.d.ts +1 -1
- package/dist/packages/suiFrens/suiFren.d.ts.map +1 -1
- package/dist/packages/suiFrens/suiFrens.d.ts +1 -1
- package/dist/packages/suiFrens/suiFrens.d.ts.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/package.json +2 -2
- package/dist/packages/perpetuals/perpetualsVault.d.ts +0 -109
- package/dist/packages/perpetuals/perpetualsVault.d.ts.map +0 -1
- package/dist/packages/perpetuals/perpetualsVault.js +0 -290
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import { Caller } from "../../general/utils/caller";
|
|
2
|
-
import { PerpetualsMarketId,
|
|
2
|
+
import { ApiPerpetualsCreateAccountBody, PerpetualsMarketId, ApiPerpetualsAccountsBody, PerpetualsOrderSide, CoinType, PerpetualsOrderId, FilledTakerOrderEvent, PerpetualsOrderPrice, Timestamp, ApiPerpetualsHistoricalMarketDataResponse, PerpetualsAccountCap, IFixed, CallerConfig } from "../../types";
|
|
3
3
|
import { PerpetualsMarket } from "./perpetualsMarket";
|
|
4
4
|
import { PerpetualsAccount } from "./perpetualsAccount";
|
|
5
5
|
import { PerpetualsOrderUtils } from "./utils";
|
|
6
|
-
import { AftermathApi } from "../../general/providers";
|
|
7
|
-
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
8
|
-
import { PerpetualsVault } from "./perpetualsVault";
|
|
9
6
|
export declare class Perpetuals extends Caller {
|
|
10
|
-
readonly Provider?: AftermathApi | undefined;
|
|
11
7
|
static readonly OrderUtils: typeof PerpetualsOrderUtils;
|
|
12
|
-
|
|
13
|
-
stopOrderGasCostSUI: bigint;
|
|
14
|
-
};
|
|
15
|
-
constructor(config?: CallerConfig, Provider?: AftermathApi | undefined);
|
|
8
|
+
constructor(config?: CallerConfig);
|
|
16
9
|
getAllMarkets(inputs: {
|
|
17
10
|
collateralCoinType: CoinType;
|
|
18
11
|
}): Promise<PerpetualsMarket[]>;
|
|
@@ -24,104 +17,42 @@ export declare class Perpetuals extends Caller {
|
|
|
24
17
|
marketIds: PerpetualsMarketId[];
|
|
25
18
|
collateralCoinType: CoinType;
|
|
26
19
|
}): Promise<PerpetualsMarket[]>;
|
|
27
|
-
getAllVaults(): Promise<PerpetualsVault[]>;
|
|
28
|
-
getVault(inputs: {
|
|
29
|
-
marketId: ObjectId;
|
|
30
|
-
}): Promise<PerpetualsVault>;
|
|
31
|
-
getVaults(inputs: {
|
|
32
|
-
vaultIds: ObjectId[];
|
|
33
|
-
}): Promise<PerpetualsVault[]>;
|
|
34
20
|
getAccount(inputs: {
|
|
35
|
-
accountCap: PerpetualsAccountCap
|
|
36
|
-
marketIds?: PerpetualsMarketId[];
|
|
21
|
+
accountCap: PerpetualsAccountCap;
|
|
37
22
|
}): Promise<PerpetualsAccount>;
|
|
38
|
-
|
|
39
|
-
accountCaps: (PerpetualsAccountCap | PerpetualsVaultCapExtended)[];
|
|
40
|
-
marketIds?: PerpetualsMarketId[];
|
|
41
|
-
}): Promise<PerpetualsAccount[]>;
|
|
42
|
-
getAccountObjects(inputs: {
|
|
43
|
-
accountIds: PerpetualsAccountId[];
|
|
23
|
+
getUserAccountCaps(inputs: ApiPerpetualsAccountsBody & {
|
|
44
24
|
collateralCoinType: CoinType;
|
|
45
|
-
marketIds?: PerpetualsMarketId[];
|
|
46
|
-
}): Promise<PerpetualsAccountObject[]>;
|
|
47
|
-
getOwnedAccountCaps(inputs: ApiPerpetualsOwnedAccountCapsBody & {
|
|
48
|
-
collateralCoinTypes?: CoinType[];
|
|
49
25
|
}): Promise<PerpetualsAccountCap[]>;
|
|
50
|
-
getOwnedVaultCaps(inputs: ApiPerpetualsOwnedAccountCapsBody): Promise<PerpetualsVaultCap[]>;
|
|
51
|
-
getOwnedWithdrawRequests(inputs: {
|
|
52
|
-
walletAddress: SuiAddress;
|
|
53
|
-
}): Promise<PerpetualsVaultWithdrawRequest[]>;
|
|
54
|
-
getAccountCaps(inputs: ApiPerpetualsAccountCapsBody): Promise<PerpetualsAccountCap[]>;
|
|
55
26
|
getMarketHistoricalData(inputs: {
|
|
27
|
+
collateralCoinType: CoinType;
|
|
56
28
|
marketId: PerpetualsMarketId;
|
|
57
29
|
fromTimestamp: Timestamp;
|
|
58
30
|
toTimestamp: Timestamp;
|
|
59
31
|
intervalMs: number;
|
|
60
32
|
}): Promise<ApiPerpetualsHistoricalMarketDataResponse>;
|
|
61
|
-
|
|
62
|
-
marketIds: PerpetualsMarketId[];
|
|
63
|
-
}): Promise<ApiPerpetualsMarkets24hrStatsResponse>;
|
|
64
|
-
getPrices(inputs: {
|
|
65
|
-
marketIds: ObjectId[];
|
|
66
|
-
}): Promise<{
|
|
67
|
-
basePrice: number;
|
|
68
|
-
collateralPrice: number;
|
|
69
|
-
}[]>;
|
|
70
|
-
getLpCoinPrices(inputs: {
|
|
71
|
-
vaultIds: ObjectId[];
|
|
72
|
-
}): Promise<number[]>;
|
|
73
|
-
getCreateAccountTx(inputs: {
|
|
74
|
-
walletAddress: SuiAddress;
|
|
75
|
-
collateralCoinType: CoinType;
|
|
76
|
-
tx?: Transaction;
|
|
77
|
-
}): Promise<Omit<ApiTransactionResponse, "txKind"> & {
|
|
78
|
-
tx: Transaction;
|
|
79
|
-
}>;
|
|
80
|
-
getCreateVaultTx(inputs: {
|
|
81
|
-
walletAddress: SuiAddress;
|
|
82
|
-
collateralCoinType: CoinType;
|
|
83
|
-
lockPeriodMs: number;
|
|
84
|
-
ownerFeePercentage: Percentage;
|
|
85
|
-
forceWithdrawDelayMs: number;
|
|
86
|
-
lpCoinMetadata: {
|
|
87
|
-
symbol: string;
|
|
88
|
-
description: string;
|
|
89
|
-
name: string;
|
|
90
|
-
iconUrl?: string;
|
|
91
|
-
};
|
|
92
|
-
tx?: Transaction;
|
|
93
|
-
} & ({
|
|
94
|
-
initialDepositAmount?: Balance;
|
|
95
|
-
} | {
|
|
96
|
-
initialDepositCoinArg: TransactionObjectArgument;
|
|
97
|
-
})): Promise<Omit<ApiTransactionResponse, "txKind"> & {
|
|
98
|
-
tx: Transaction;
|
|
99
|
-
}>;
|
|
33
|
+
getCreateAccountTx(inputs: ApiPerpetualsCreateAccountBody): Promise<import("@mysten/sui/transactions").Transaction>;
|
|
100
34
|
static positionSide(inputs: {
|
|
101
|
-
baseAssetAmount:
|
|
35
|
+
baseAssetAmount: IFixed;
|
|
102
36
|
}): PerpetualsOrderSide;
|
|
103
|
-
static
|
|
37
|
+
static orderPrice(inputs: {
|
|
104
38
|
orderEvent: FilledTakerOrderEvent;
|
|
105
39
|
}): number;
|
|
106
|
-
static orderPriceFromOrderId(inputs: {
|
|
107
|
-
orderId: PerpetualsOrderId;
|
|
108
|
-
}): number;
|
|
109
40
|
static priceToOrderPrice: (inputs: {
|
|
110
41
|
price: number;
|
|
42
|
+
lotSize: number | bigint;
|
|
43
|
+
tickSize: number | bigint;
|
|
111
44
|
}) => PerpetualsOrderPrice;
|
|
112
45
|
static orderPriceToPrice: (inputs: {
|
|
113
46
|
orderPrice: PerpetualsOrderPrice;
|
|
47
|
+
lotSize: number | bigint;
|
|
48
|
+
tickSize: number | bigint;
|
|
114
49
|
}) => number;
|
|
115
50
|
static lotOrTickSizeToNumber(lotOrTickSize: bigint): number;
|
|
116
51
|
static lotOrTickSizeToBigInt(lotOrTickSize: number): bigint;
|
|
117
52
|
static orderIdToSide: (orderId: PerpetualsOrderId) => PerpetualsOrderSide;
|
|
118
|
-
static eventTypeForCollateral: (inputs: {
|
|
119
|
-
eventType: string;
|
|
120
|
-
collateralCoinType: CoinType;
|
|
121
|
-
}) => string;
|
|
122
53
|
static calcEntryPrice(inputs: {
|
|
123
|
-
baseAssetAmount:
|
|
124
|
-
quoteAssetNotionalAmount:
|
|
54
|
+
baseAssetAmount: IFixed;
|
|
55
|
+
quoteAssetNotionalAmount: IFixed;
|
|
125
56
|
}): number;
|
|
126
57
|
}
|
|
127
58
|
//# sourceMappingURL=perpetuals.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perpetuals.d.ts","sourceRoot":"","sources":["../../../src/packages/perpetuals/perpetuals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,
|
|
1
|
+
{"version":3,"file":"perpetuals.d.ts","sourceRoot":"","sources":["../../../src/packages/perpetuals/perpetuals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EACN,8BAA8B,EAM9B,kBAAkB,EAClB,yBAAyB,EAEzB,mBAAmB,EAEnB,QAAQ,EACR,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,SAAS,EAET,yCAAyC,EACzC,oBAAoB,EAGpB,MAAM,EAEN,YAAY,EACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAIxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE/C,qBAAa,UAAW,SAAQ,MAAM;IAKrC,gBAAuB,UAAU,8BAAwB;gBAM7C,MAAM,CAAC,EAAE,YAAY;IAQpB,aAAa,CAAC,MAAM,EAAE;QAClC,kBAAkB,EAAE,QAAQ,CAAC;KAC7B,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAUlB,SAAS,CAAC,MAAM,EAAE;QAC9B,QAAQ,EAAE,kBAAkB,CAAC;QAC7B,kBAAkB,EAAE,QAAQ,CAAC;KAC7B,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAOhB,UAAU,CAAC,MAAM,EAAE;QAC/B,SAAS,EAAE,kBAAkB,EAAE,CAAC;QAChC,kBAAkB,EAAE,QAAQ,CAAC;KAC7B,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAYlB,UAAU,CAAC,MAAM,EAAE;QAC/B,UAAU,EAAE,oBAAoB,CAAC;KACjC,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAQjB,kBAAkB,CAC9B,MAAM,EAAE,yBAAyB,GAAG;QACnC,kBAAkB,EAAE,QAAQ,CAAC;KAC7B,GACC,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAc3B,uBAAuB,CAAC,MAAM,EAAE;QACtC,kBAAkB,EAAE,QAAQ,CAAC;QAC7B,QAAQ,EAAE,kBAAkB,CAAC;QAC7B,aAAa,EAAE,SAAS,CAAC;QACzB,WAAW,EAAE,SAAS,CAAC;QACvB,UAAU,EAAE,MAAM,CAAC;KACnB;IAiBY,kBAAkB,CAAC,MAAM,EAAE,8BAA8B;WAexD,YAAY,CAAC,MAAM,EAAE;QAClC,eAAe,EAAE,MAAM,CAAC;KACxB,GAAG,mBAAmB;WAQT,UAAU,CAAC,MAAM,EAAE;QAChC,UAAU,EAAE,qBAAqB,CAAC;KAClC,GAAG,MAAM;IAQV,OAAc,iBAAiB,GAAI,QAAQ;QAC1C,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;QACzB,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;KAC1B,KAAG,oBAAoB,CAqBtB;IAEF,OAAc,iBAAiB,GAAI,QAAQ;QAC1C,UAAU,EAAE,oBAAoB,CAAC;QACjC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;QACzB,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;KAC1B,KAAG,MAAM,CAgBR;WAEY,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM;WAIpD,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM;IAIlE,OAAc,aAAa,GAC1B,SAAS,iBAAiB,KACxB,mBAAmB,CAIpB;WAMY,cAAc,CAAC,MAAM,EAAE;QACpC,eAAe,EAAE,MAAM,CAAC;QACxB,wBAAwB,EAAE,MAAM,CAAC;KACjC,GAAG,MAAM;CAWV"}
|
|
@@ -8,190 +8,77 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var _a;
|
|
11
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
13
|
exports.Perpetuals = void 0;
|
|
13
14
|
const caller_1 = require("../../general/utils/caller");
|
|
14
15
|
const types_1 = require("../../types");
|
|
15
16
|
const perpetualsMarket_1 = require("./perpetualsMarket");
|
|
16
17
|
const perpetualsAccount_1 = require("./perpetualsAccount");
|
|
18
|
+
const iFixedUtils_1 = require("../../general/utils/iFixedUtils");
|
|
17
19
|
const fixedUtils_1 = require("../../general/utils/fixedUtils");
|
|
18
|
-
const utils_1 = require("
|
|
19
|
-
const
|
|
20
|
+
const utils_1 = require("../../general/utils");
|
|
21
|
+
const utils_2 = require("./utils");
|
|
20
22
|
class Perpetuals extends caller_1.Caller {
|
|
21
23
|
// =========================================================================
|
|
22
24
|
// Constructor
|
|
23
25
|
// =========================================================================
|
|
24
|
-
constructor(config
|
|
26
|
+
constructor(config) {
|
|
25
27
|
super(config, "perpetuals");
|
|
26
|
-
this.Provider = Provider;
|
|
27
28
|
}
|
|
28
29
|
// =========================================================================
|
|
29
30
|
// Class Objects
|
|
30
31
|
// =========================================================================
|
|
31
32
|
getAllMarkets(inputs) {
|
|
32
33
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
const
|
|
34
|
+
const { collateralCoinType } = inputs;
|
|
35
|
+
const marketDatas = yield this.fetchApi(`${collateralCoinType}/markets`);
|
|
34
36
|
return marketDatas.map((marketData) => new perpetualsMarket_1.PerpetualsMarket(marketData, this.config));
|
|
35
37
|
});
|
|
36
38
|
}
|
|
37
39
|
getMarket(inputs) {
|
|
38
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
collateralCoinType: inputs.collateralCoinType,
|
|
42
|
-
});
|
|
43
|
-
return markets[0];
|
|
41
|
+
const marketData = yield this.fetchApi(`${inputs.collateralCoinType}/markets/${inputs.marketId}`);
|
|
42
|
+
return new perpetualsMarket_1.PerpetualsMarket(marketData, this.config);
|
|
44
43
|
});
|
|
45
44
|
}
|
|
46
45
|
getMarkets(inputs) {
|
|
47
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
const
|
|
49
|
-
return
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
getAllVaults() {
|
|
55
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
const vaultObjects = yield this.fetchApi("vaults", {});
|
|
57
|
-
return vaultObjects.map((vaultObject) => new perpetualsVault_1.PerpetualsVault(vaultObject, this.config));
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
getVault(inputs) {
|
|
61
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
const vaults = yield this.getVaults({
|
|
63
|
-
vaultIds: [inputs.marketId],
|
|
64
|
-
});
|
|
65
|
-
return vaults[0];
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
getVaults(inputs) {
|
|
69
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
const vaultObjects = yield this.fetchApi("vaults", inputs);
|
|
71
|
-
return vaultObjects.map((vaultObject) => new perpetualsVault_1.PerpetualsVault(vaultObject, this.config));
|
|
47
|
+
const { collateralCoinType } = inputs;
|
|
48
|
+
return Promise.all(inputs.marketIds.map((marketId) => this.getMarket({
|
|
49
|
+
marketId,
|
|
50
|
+
collateralCoinType,
|
|
51
|
+
})));
|
|
72
52
|
});
|
|
73
53
|
}
|
|
74
|
-
// TODO: merge this with `getAccountObjects` as an option ?
|
|
75
54
|
getAccount(inputs) {
|
|
76
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
const { accountCap
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
marketIds,
|
|
81
|
-
}))[0];
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
// TODO: make account fetching get positions and account cap data all at once ?
|
|
85
|
-
getAccounts(inputs) {
|
|
86
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
const { accountCaps, marketIds } = inputs;
|
|
88
|
-
if (accountCaps.length <= 0)
|
|
89
|
-
return [];
|
|
90
|
-
// TODO: handle different collateral coin types
|
|
91
|
-
const accountObjects = yield this.getAccountObjects({
|
|
92
|
-
accountIds: accountCaps.map((accountCap) => accountCap.accountId),
|
|
93
|
-
collateralCoinType: accountCaps[0].collateralCoinType,
|
|
94
|
-
marketIds,
|
|
95
|
-
});
|
|
96
|
-
return accountObjects.map((account, index) => new perpetualsAccount_1.PerpetualsAccount(account, accountCaps[index], this.config, this.Provider));
|
|
56
|
+
const { accountCap } = inputs;
|
|
57
|
+
const account = yield this.fetchApi(`${accountCap.collateralCoinType}/accounts/${accountCap.accountId}`);
|
|
58
|
+
return new perpetualsAccount_1.PerpetualsAccount(account, accountCap, this.config);
|
|
97
59
|
});
|
|
98
60
|
}
|
|
99
|
-
|
|
100
|
-
getAccountObjects(inputs) {
|
|
61
|
+
getUserAccountCaps(inputs) {
|
|
101
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
const {
|
|
103
|
-
|
|
104
|
-
return [];
|
|
105
|
-
return this.fetchApi("accounts/positions", {
|
|
106
|
-
accountIds,
|
|
107
|
-
collateralCoinType,
|
|
108
|
-
marketIds,
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
getOwnedAccountCaps(inputs) {
|
|
113
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
const { walletAddress, collateralCoinTypes } = inputs;
|
|
115
|
-
return this.fetchApi("accounts/owned", {
|
|
63
|
+
const { collateralCoinType, walletAddress } = inputs;
|
|
64
|
+
return this.fetchApi(`${collateralCoinType}/accounts`, {
|
|
116
65
|
walletAddress,
|
|
117
|
-
collateralCoinTypes,
|
|
118
66
|
});
|
|
119
67
|
});
|
|
120
68
|
}
|
|
121
|
-
getOwnedVaultCaps(inputs) {
|
|
122
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
-
return this.fetchApi("vaults/owned-vault-caps", inputs);
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
getOwnedWithdrawRequests(inputs) {
|
|
127
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
return this.fetchApi("vaults/owned-withdraw-requests", Object.assign({}, inputs));
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
getAccountCaps(inputs) {
|
|
132
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
-
return this.fetchApi("accounts", inputs);
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
69
|
// =========================================================================
|
|
137
70
|
// Data
|
|
138
71
|
// =========================================================================
|
|
139
72
|
getMarketHistoricalData(inputs) {
|
|
140
|
-
const { marketId, fromTimestamp, toTimestamp, intervalMs } = inputs;
|
|
141
|
-
return this.fetchApi(
|
|
142
|
-
marketId,
|
|
143
|
-
fromTimestamp,
|
|
144
|
-
toTimestamp,
|
|
145
|
-
intervalMs,
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
getMarkets24hrStats(inputs) {
|
|
149
|
-
return this.fetchApi("markets/24hr-stats", inputs);
|
|
150
|
-
}
|
|
151
|
-
// =========================================================================
|
|
152
|
-
// Prices
|
|
153
|
-
// =========================================================================
|
|
154
|
-
getPrices(inputs) {
|
|
155
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
-
if (inputs.marketIds.length <= 0)
|
|
157
|
-
return [];
|
|
158
|
-
return this.fetchApi("markets/prices", inputs);
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
getLpCoinPrices(inputs) {
|
|
162
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
163
|
-
if (inputs.vaultIds.length <= 0)
|
|
164
|
-
return [];
|
|
165
|
-
return this.fetchApi("vaults/lp-coin-prices", inputs);
|
|
166
|
-
});
|
|
73
|
+
const { collateralCoinType, marketId, fromTimestamp, toTimestamp, intervalMs, } = inputs;
|
|
74
|
+
return this.fetchApi(`${collateralCoinType}/markets/${marketId}/historical-data/${fromTimestamp}/${toTimestamp}/${intervalMs}`);
|
|
167
75
|
}
|
|
168
76
|
// =========================================================================
|
|
169
77
|
// Transactions
|
|
170
78
|
// =========================================================================
|
|
171
79
|
getCreateAccountTx(inputs) {
|
|
172
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
-
|
|
174
|
-
const { walletAddress, collateralCoinType, tx } = inputs;
|
|
175
|
-
return this.fetchApiTxObject("transactions/create-account", {
|
|
176
|
-
walletAddress,
|
|
177
|
-
collateralCoinType,
|
|
178
|
-
txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })),
|
|
179
|
-
}, undefined, {
|
|
180
|
-
txKind: true,
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
getCreateVaultTx(inputs) {
|
|
185
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
-
var _a;
|
|
187
|
-
const { walletAddress, collateralCoinType, tx } = inputs;
|
|
188
|
-
return this.fetchApiTxObject("transactions/create-vault", {
|
|
189
|
-
walletAddress,
|
|
190
|
-
collateralCoinType,
|
|
191
|
-
txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })),
|
|
192
|
-
}, undefined, {
|
|
193
|
-
txKind: true,
|
|
194
|
-
});
|
|
81
|
+
return this.fetchApiTransaction("transactions/create-account", inputs);
|
|
195
82
|
});
|
|
196
83
|
}
|
|
197
84
|
// =========================================================================
|
|
@@ -201,19 +88,15 @@ class Perpetuals extends caller_1.Caller {
|
|
|
201
88
|
// Helpers
|
|
202
89
|
// =========================================================================
|
|
203
90
|
static positionSide(inputs) {
|
|
204
|
-
const baseAmount = inputs.baseAssetAmount;
|
|
91
|
+
const baseAmount = iFixedUtils_1.IFixedUtils.numberFromIFixed(inputs.baseAssetAmount);
|
|
205
92
|
const isLong = Math.sign(baseAmount);
|
|
206
93
|
const side = isLong >= 0 ? types_1.PerpetualsOrderSide.Bid : types_1.PerpetualsOrderSide.Ask;
|
|
207
94
|
return side;
|
|
208
95
|
}
|
|
209
|
-
static
|
|
96
|
+
static orderPrice(inputs) {
|
|
210
97
|
const { orderEvent } = inputs;
|
|
211
|
-
return orderEvent.quoteAssetDelta /
|
|
212
|
-
|
|
213
|
-
static orderPriceFromOrderId(inputs) {
|
|
214
|
-
const { orderId } = inputs;
|
|
215
|
-
const orderPrice = utils_1.PerpetualsOrderUtils.price(orderId);
|
|
216
|
-
return this.orderPriceToPrice({ orderPrice });
|
|
98
|
+
return (iFixedUtils_1.IFixedUtils.numberFromIFixed(orderEvent.quoteAssetDelta) /
|
|
99
|
+
iFixedUtils_1.IFixedUtils.numberFromIFixed(orderEvent.baseAssetDelta));
|
|
217
100
|
}
|
|
218
101
|
static lotOrTickSizeToNumber(lotOrTickSize) {
|
|
219
102
|
return Number(lotOrTickSize) / fixedUtils_1.FixedUtils.fixedOneN9;
|
|
@@ -226,33 +109,51 @@ class Perpetuals extends caller_1.Caller {
|
|
|
226
109
|
// =========================================================================
|
|
227
110
|
static calcEntryPrice(inputs) {
|
|
228
111
|
const { baseAssetAmount, quoteAssetNotionalAmount } = inputs;
|
|
229
|
-
const denominator = baseAssetAmount;
|
|
112
|
+
const denominator = utils_1.Casting.IFixed.numberFromIFixed(baseAssetAmount);
|
|
230
113
|
if (!denominator)
|
|
231
114
|
return 0;
|
|
232
|
-
return Math.abs(quoteAssetNotionalAmount /
|
|
115
|
+
return Math.abs(utils_1.Casting.IFixed.numberFromIFixed(quoteAssetNotionalAmount) /
|
|
116
|
+
denominator);
|
|
233
117
|
}
|
|
234
118
|
}
|
|
235
119
|
exports.Perpetuals = Perpetuals;
|
|
120
|
+
_a = Perpetuals;
|
|
236
121
|
// =========================================================================
|
|
237
122
|
// Constants
|
|
238
123
|
// =========================================================================
|
|
239
|
-
Perpetuals.OrderUtils =
|
|
240
|
-
Perpetuals.constants = {
|
|
241
|
-
stopOrderGasCostSUI: BigInt(15000000), // 0.15 SUI
|
|
242
|
-
};
|
|
124
|
+
Perpetuals.OrderUtils = utils_2.PerpetualsOrderUtils;
|
|
243
125
|
Perpetuals.priceToOrderPrice = (inputs) => {
|
|
244
|
-
const { price } = inputs;
|
|
245
|
-
|
|
126
|
+
const { price, lotSize, tickSize } = inputs;
|
|
127
|
+
const priceFixed = fixedUtils_1.FixedUtils.directUncast(price);
|
|
128
|
+
// convert f18 to b9 (assuming the former is positive)
|
|
129
|
+
const price9 = priceFixed / fixedUtils_1.FixedUtils.fixedOneB9;
|
|
130
|
+
const denominator = fixedUtils_1.FixedUtils.fixedOneB9 /
|
|
131
|
+
(typeof lotSize === "number"
|
|
132
|
+
? _a.lotOrTickSizeToBigInt(lotSize)
|
|
133
|
+
: lotSize);
|
|
134
|
+
if (denominator <= BigInt(0))
|
|
135
|
+
return BigInt(0);
|
|
136
|
+
return (price9 /
|
|
137
|
+
(typeof tickSize === "number"
|
|
138
|
+
? _a.lotOrTickSizeToBigInt(tickSize)
|
|
139
|
+
: tickSize) /
|
|
140
|
+
denominator);
|
|
246
141
|
};
|
|
247
142
|
Perpetuals.orderPriceToPrice = (inputs) => {
|
|
248
|
-
const { orderPrice } = inputs;
|
|
249
|
-
|
|
143
|
+
const { orderPrice, lotSize, tickSize } = inputs;
|
|
144
|
+
const temp = fixedUtils_1.FixedUtils.fixedOneB9 /
|
|
145
|
+
(typeof lotSize === "number"
|
|
146
|
+
? _a.lotOrTickSizeToBigInt(lotSize)
|
|
147
|
+
: lotSize);
|
|
148
|
+
return fixedUtils_1.FixedUtils.directCast(orderPrice *
|
|
149
|
+
(typeof tickSize === "number"
|
|
150
|
+
? _a.lotOrTickSizeToBigInt(tickSize)
|
|
151
|
+
: tickSize) *
|
|
152
|
+
temp *
|
|
153
|
+
fixedUtils_1.FixedUtils.fixedOneB9);
|
|
250
154
|
};
|
|
251
155
|
Perpetuals.orderIdToSide = (orderId) => {
|
|
252
|
-
return
|
|
156
|
+
return _a.OrderUtils.isAsk(orderId)
|
|
253
157
|
? types_1.PerpetualsOrderSide.Ask
|
|
254
158
|
: types_1.PerpetualsOrderSide.Bid;
|
|
255
159
|
};
|
|
256
|
-
Perpetuals.eventTypeForCollateral = (inputs) => {
|
|
257
|
-
return `${inputs.eventType}<${inputs.collateralCoinType}>`;
|
|
258
|
-
};
|