@bulletxyz/bullet-sdk 0.16.0-rc.3 → 0.16.1-rc.0
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/browser/index.js +2507 -230
- package/dist/browser/index.js.map +4 -4
- package/dist/node/index.js +2507 -230
- package/dist/node/index.js.map +4 -4
- package/dist/types/calc.d.ts +16 -15
- package/dist/types/client.d.ts +46 -45
- package/dist/types/types.d.ts +4 -3
- package/dist/types/utils.d.ts +1 -0
- package/dist/types/zod-types/index.d.ts +14 -3
- package/dist/types/zod-types/rest.d.ts +1517 -1517
- package/dist/types/zod-types/wasm.d.ts +6 -6
- package/dist/types/zod-types/ws.d.ts +16 -16
- package/package.json +2 -1
package/dist/types/calc.d.ts
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import { Asset, AssetId, Side } from "./types";
|
|
2
2
|
import { MarginConfig, OrderbookData, Pricing, UserAccount } from "./zod-types/rest";
|
|
3
3
|
import { EquityType, MarginType } from "./bullet-wasm";
|
|
4
|
-
|
|
5
|
-
export declare function
|
|
4
|
+
import Decimal from "decimal.js";
|
|
5
|
+
export declare function calculateOrderbookMidpoint(orderbook: OrderbookData): Decimal | undefined;
|
|
6
|
+
export declare function calculateEntryPrice(asset: Asset, userAccount: UserAccount): Decimal;
|
|
6
7
|
export interface MarginContext {
|
|
7
8
|
pricing: Pricing;
|
|
8
9
|
margin_config: MarginConfig;
|
|
9
10
|
}
|
|
10
|
-
export declare function calculateTotalPerpUnrealizedPnl(userAccount: UserAccount, marginContext: MarginContext):
|
|
11
|
-
export declare function calculateAccountEquity(equityType: EquityType, conservative: boolean, userAccount: UserAccount, marginContext: MarginContext):
|
|
12
|
-
export declare function calculateAccountLeverage(userAccount: UserAccount, marginContext: MarginContext):
|
|
13
|
-
export declare function calculateAvailableMargin(marginType: MarginType, conservative: boolean, userAccount: UserAccount, marginContext: MarginContext):
|
|
14
|
-
export declare function calculateUsedMargin(marginType: MarginType, userAccount: UserAccount, marginContext: MarginContext):
|
|
15
|
-
export declare function calculateWithdrawableAmountOfAsset(assetId: AssetId, userAccount: UserAccount, marginContext: MarginContext):
|
|
16
|
-
export declare function calculateEstimatedLiquidationPrice(assetId: AssetId, userAccount: UserAccount, marginContext: MarginContext):
|
|
17
|
-
export declare function calculateLiquidationRiskPercentage(userAccount: UserAccount, marginContext: MarginContext):
|
|
18
|
-
export declare function calculateMaxBorrowAmount(assetId: AssetId, userAccount: UserAccount, marginContext: MarginContext):
|
|
19
|
-
export declare function calculateMaxOrderSize(assetId: AssetId, side: Side, price:
|
|
20
|
-
export declare function simulateUsedMarginOnBorrow(assetId: AssetId, borrowAmount:
|
|
21
|
-
current:
|
|
22
|
-
new:
|
|
11
|
+
export declare function calculateTotalPerpUnrealizedPnl(userAccount: UserAccount, marginContext: MarginContext): Decimal;
|
|
12
|
+
export declare function calculateAccountEquity(equityType: EquityType, conservative: boolean, userAccount: UserAccount, marginContext: MarginContext): Decimal;
|
|
13
|
+
export declare function calculateAccountLeverage(userAccount: UserAccount, marginContext: MarginContext): Decimal;
|
|
14
|
+
export declare function calculateAvailableMargin(marginType: MarginType, conservative: boolean, userAccount: UserAccount, marginContext: MarginContext): Decimal;
|
|
15
|
+
export declare function calculateUsedMargin(marginType: MarginType, userAccount: UserAccount, marginContext: MarginContext): Decimal;
|
|
16
|
+
export declare function calculateWithdrawableAmountOfAsset(assetId: AssetId, userAccount: UserAccount, marginContext: MarginContext): Decimal;
|
|
17
|
+
export declare function calculateEstimatedLiquidationPrice(assetId: AssetId, userAccount: UserAccount, marginContext: MarginContext): Decimal;
|
|
18
|
+
export declare function calculateLiquidationRiskPercentage(userAccount: UserAccount, marginContext: MarginContext): Decimal;
|
|
19
|
+
export declare function calculateMaxBorrowAmount(assetId: AssetId, userAccount: UserAccount, marginContext: MarginContext): Decimal;
|
|
20
|
+
export declare function calculateMaxOrderSize(assetId: AssetId, side: Side, price: Decimal, reduceOnly: boolean, userAccount: UserAccount, marginContext: MarginContext, makerBook: OrderbookData, n_iterations?: number, error_tolerance?: Decimal): Decimal;
|
|
21
|
+
export declare function simulateUsedMarginOnBorrow(assetId: AssetId, borrowAmount: Decimal, userAccount: UserAccount, marginType: MarginType, marginContext: MarginContext): {
|
|
22
|
+
current: Decimal;
|
|
23
|
+
new: Decimal;
|
|
23
24
|
};
|
package/dist/types/client.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { ExchangeConnection } from "./exchange";
|
|
|
3
3
|
import { Side, Asset, Network, Address, TokenId, CallMessage, TpslOrder, OrderType } from "./types";
|
|
4
4
|
import { Wallet } from "./wallet";
|
|
5
5
|
import { Connection } from "./connection";
|
|
6
|
+
import Decimal from "decimal.js";
|
|
6
7
|
export interface TransactionOpts {
|
|
7
8
|
maxPriorityFeeBps: number;
|
|
8
9
|
maxFee: number;
|
|
@@ -26,55 +27,55 @@ export declare class Client {
|
|
|
26
27
|
usdc_ledger: {
|
|
27
28
|
ledger: {
|
|
28
29
|
weights: {
|
|
29
|
-
asset_weight:
|
|
30
|
-
initial_liability_weight:
|
|
31
|
-
maintenance_liability_weight:
|
|
30
|
+
asset_weight: Decimal;
|
|
31
|
+
initial_liability_weight: Decimal;
|
|
32
|
+
maintenance_liability_weight: Decimal;
|
|
32
33
|
};
|
|
33
|
-
asset:
|
|
34
|
-
liability:
|
|
34
|
+
asset: Decimal;
|
|
35
|
+
liability: Decimal;
|
|
35
36
|
};
|
|
36
|
-
unrealized_loss_borrow:
|
|
37
|
-
unsettled_perp_profit:
|
|
37
|
+
unrealized_loss_borrow: Decimal;
|
|
38
|
+
unsettled_perp_profit: Decimal;
|
|
38
39
|
};
|
|
39
|
-
spot_ledgers: Map<
|
|
40
|
+
spot_ledgers: Map<number, {
|
|
40
41
|
weights: {
|
|
41
|
-
asset_weight:
|
|
42
|
-
initial_liability_weight:
|
|
43
|
-
maintenance_liability_weight:
|
|
42
|
+
asset_weight: Decimal;
|
|
43
|
+
initial_liability_weight: Decimal;
|
|
44
|
+
maintenance_liability_weight: Decimal;
|
|
44
45
|
};
|
|
45
|
-
asset:
|
|
46
|
-
liability:
|
|
46
|
+
asset: Decimal;
|
|
47
|
+
liability: Decimal;
|
|
47
48
|
}>;
|
|
48
|
-
perp_ledgers: Map<
|
|
49
|
+
perp_ledgers: Map<number, {
|
|
49
50
|
orders: {
|
|
50
|
-
size:
|
|
51
|
-
price:
|
|
51
|
+
size: Decimal;
|
|
52
|
+
price: Decimal;
|
|
52
53
|
side: "Bid" | "Ask";
|
|
53
|
-
order_id:
|
|
54
|
+
order_id: bigint;
|
|
54
55
|
reduce_only: boolean;
|
|
55
56
|
}[];
|
|
56
57
|
position: {
|
|
57
|
-
size:
|
|
58
|
-
cost_of_trades:
|
|
59
|
-
realized_pnl:
|
|
60
|
-
cached_mark_price:
|
|
61
|
-
last_accum_funding_applied_per_lot: [
|
|
62
|
-
funding_payments_on_side:
|
|
63
|
-
funding_payments_on_position:
|
|
58
|
+
size: Decimal;
|
|
59
|
+
cost_of_trades: Decimal;
|
|
60
|
+
realized_pnl: Decimal;
|
|
61
|
+
cached_mark_price: Decimal;
|
|
62
|
+
last_accum_funding_applied_per_lot: [Decimal, bigint];
|
|
63
|
+
funding_payments_on_side: Decimal;
|
|
64
|
+
funding_payments_on_position: Decimal;
|
|
64
65
|
};
|
|
65
66
|
user_selected_max_leverage: number;
|
|
66
67
|
tpsls: {
|
|
67
68
|
side: "Bid" | "Ask";
|
|
68
|
-
tpsl_order_id:
|
|
69
|
-
order_price:
|
|
70
|
-
trigger_price:
|
|
69
|
+
tpsl_order_id: bigint;
|
|
70
|
+
order_price: Decimal;
|
|
71
|
+
trigger_price: Decimal;
|
|
71
72
|
trigger_direction: "GreaterThanOrEqual" | "LessThanOrEqual";
|
|
72
73
|
tpsl_price_condition: "Mark" | "Oracle" | "LastTrade";
|
|
73
|
-
active_size:
|
|
74
|
-
full_size:
|
|
74
|
+
active_size: Decimal;
|
|
75
|
+
full_size: Decimal;
|
|
75
76
|
order_type: "Limit" | "PostOnly" | "FillOrKill" | "ImmediateOrCancel" | "PostOnlySlide" | "PostOnlyFront";
|
|
76
|
-
linked_tpsl_order_ids:
|
|
77
|
-
parent_order_id?:
|
|
77
|
+
linked_tpsl_order_ids: bigint[];
|
|
78
|
+
parent_order_id?: bigint | undefined;
|
|
78
79
|
}[];
|
|
79
80
|
}>;
|
|
80
81
|
}>;
|
|
@@ -82,20 +83,20 @@ export declare class Client {
|
|
|
82
83
|
transfer(to: Address, amount: bigint, tokenId: TokenId): Promise<void | TransactionResult<Transaction<unknown>>>;
|
|
83
84
|
mint(to: Address, amount: bigint, tokenId: TokenId): Promise<void | TransactionResult<Transaction<unknown>>>;
|
|
84
85
|
setValue(value: number): Promise<void | TransactionResult<Transaction<unknown>>>;
|
|
85
|
-
deposit(asset: Asset, amount:
|
|
86
|
-
withdraw(asset: Asset, amount:
|
|
87
|
-
borrowSpot(asset: Asset, amount:
|
|
88
|
-
placeOrder(asset: Asset, price:
|
|
86
|
+
deposit(asset: Asset, amount: Decimal): Promise<void | TransactionResult<Transaction<unknown>>>;
|
|
87
|
+
withdraw(asset: Asset, amount: Decimal): Promise<void | TransactionResult<Transaction<unknown>>>;
|
|
88
|
+
borrowSpot(asset: Asset, amount: Decimal): Promise<void | TransactionResult<Transaction<unknown>>>;
|
|
89
|
+
placeOrder(asset: Asset, price: Decimal, size: Decimal, side: Side, orderType?: OrderType, reduceOnly?: boolean, tpslOrders?: TpslOrder[]): Promise<void | TransactionResult<Transaction<unknown>>>;
|
|
89
90
|
placeTpsls(asset: Asset, tpslOrders: TpslOrder[]): Promise<void | TransactionResult<Transaction<unknown>>>;
|
|
90
|
-
replaceOrder(
|
|
91
|
-
cancelTpsl(tpslOrderId:
|
|
92
|
-
cancelOrder(
|
|
91
|
+
replaceOrder(existingOrderId: string, asset: Asset, price: Decimal, size: Decimal, side: Side, orderType?: OrderType, reduceOnly?: boolean, tpslOrders?: TpslOrder[]): Promise<void | TransactionResult<Transaction<unknown>>>;
|
|
92
|
+
cancelTpsl(tpslOrderId: string): Promise<void | TransactionResult<Transaction<unknown>>>;
|
|
93
|
+
cancelOrder(orderId: string): Promise<void | TransactionResult<Transaction<unknown>>>;
|
|
93
94
|
cancelAllOrders(asset: Asset): Promise<void | TransactionResult<Transaction<unknown>>>;
|
|
94
95
|
updatePricing(pricing_updates: {
|
|
95
96
|
asset: Asset;
|
|
96
|
-
medianCexPrice:
|
|
97
|
-
oraclePrice:
|
|
98
|
-
diffEma:
|
|
97
|
+
medianCexPrice: Decimal;
|
|
98
|
+
oraclePrice: Decimal;
|
|
99
|
+
diffEma: Decimal;
|
|
99
100
|
}[], publishTimestamp?: number): Promise<void | TransactionResult<Transaction<unknown>>>;
|
|
100
101
|
updateAssetMaxLeverage(asset: Asset, maxLeverage: number): Promise<void | TransactionResult<Transaction<unknown>>>;
|
|
101
102
|
updatePremiumIndexes(assetIds: Asset[]): Promise<void | TransactionResult<Transaction<unknown>>>;
|
|
@@ -105,9 +106,9 @@ export declare class Client {
|
|
|
105
106
|
forceClosePositions(address: Address): Promise<void | TransactionResult<Transaction<unknown>>>;
|
|
106
107
|
liquidate(address: Address, positions?: {
|
|
107
108
|
asset: Asset;
|
|
108
|
-
size:
|
|
109
|
+
size: Decimal;
|
|
109
110
|
}[]): Promise<void | TransactionResult<Transaction<unknown>>>;
|
|
110
|
-
liquidateSpotLiability(address: Address, liabilityAssetId: Asset, collateralAssetId: Asset, liabilityAmount:
|
|
111
|
-
depositToUsdcPnlPool(amount:
|
|
112
|
-
depositToInsuranceFund(amount:
|
|
111
|
+
liquidateSpotLiability(address: Address, liabilityAssetId: Asset, collateralAssetId: Asset, liabilityAmount: Decimal): Promise<void | TransactionResult<Transaction<unknown>>>;
|
|
112
|
+
depositToUsdcPnlPool(amount: Decimal): Promise<void | TransactionResult<Transaction<unknown>>>;
|
|
113
|
+
depositToInsuranceFund(amount: Decimal): Promise<void | TransactionResult<Transaction<unknown>>>;
|
|
113
114
|
}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Decimal from "decimal.js";
|
|
1
2
|
import { MarginType } from "./bullet-wasm";
|
|
2
3
|
export { MarginType };
|
|
3
4
|
export type CallMessage = {
|
|
@@ -35,11 +36,11 @@ export type TpslPriceCondition = "Mark" | "Oracle" | "LastTrade";
|
|
|
35
36
|
export type OrderType = "Limit" | "PostOnly" | "FillOrKill" | "ImmediateOrCancel" | "PostOnlySlide" | "PostOnlyFront";
|
|
36
37
|
export type Network = "Localnet" | "Staging" | "Testnet" | "Mainnet";
|
|
37
38
|
export type TpslOrder = {
|
|
38
|
-
orderPrice:
|
|
39
|
-
triggerPrice:
|
|
39
|
+
orderPrice: Decimal;
|
|
40
|
+
triggerPrice: Decimal;
|
|
40
41
|
triggerDirection: TriggerDirection;
|
|
41
42
|
tpslPriceCondition: TpslPriceCondition;
|
|
42
|
-
size:
|
|
43
|
+
size: Decimal;
|
|
43
44
|
orderType: OrderType;
|
|
44
45
|
};
|
|
45
46
|
export declare class BulletError extends Error {
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export declare function base58ToBytes(base58: string): Uint8Array;
|
|
|
6
6
|
export declare function base58ToHex(base58: string): string;
|
|
7
7
|
export declare function sleep(ms: number): Promise<void>;
|
|
8
8
|
export declare function isNode(): boolean;
|
|
9
|
+
export declare function serialize<T>(value: T): T;
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
+
import Decimal from "decimal.js";
|
|
1
2
|
import { z } from "zod";
|
|
2
|
-
export declare const
|
|
3
|
+
export declare const I64Schema: z.ZodBigInt;
|
|
4
|
+
export declare const U16Schema: z.ZodNumber;
|
|
5
|
+
export declare const U32Schema: z.ZodNumber;
|
|
6
|
+
export declare const U64Schema: z.ZodBigInt;
|
|
7
|
+
export declare const U128Schema: z.ZodBigInt;
|
|
8
|
+
export declare const DecimalSchema: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, Decimal, string | number>;
|
|
9
|
+
export declare const Base58Address: z.ZodString;
|
|
3
10
|
export declare const AssetId: z.ZodNumber;
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
11
|
+
export declare const OrderId: z.ZodBigInt;
|
|
12
|
+
export declare const Amount: z.ZodBigInt;
|
|
13
|
+
export declare const UnixTimestampMillis: z.ZodBigInt;
|
|
14
|
+
type MapKeySchema = z.ZodString | z.ZodNumber | z.ZodUnknown;
|
|
15
|
+
export declare const createJsonMap: <K extends MapKeySchema, V extends z.ZodTypeAny>(keySchema: K, valueSchema: V) => z.ZodEffects<z.ZodRecord<z.ZodString, V>, Map<z.infer<K>, z.infer<V>>>;
|
|
16
|
+
export {};
|