@haneullabs/deepbook 0.1.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/CHANGELOG.md +974 -0
- package/README.md +11 -0
- package/dist/cjs/client.d.ts +198 -0
- package/dist/cjs/client.js +630 -0
- package/dist/cjs/client.js.map +7 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/package.json +4 -0
- package/dist/cjs/types/bcs.d.ts +11 -0
- package/dist/cjs/types/bcs.js +36 -0
- package/dist/cjs/types/bcs.js.map +7 -0
- package/dist/cjs/types/index.d.ts +51 -0
- package/dist/cjs/types/index.js +38 -0
- package/dist/cjs/types/index.js.map +7 -0
- package/dist/cjs/utils/constants.d.ts +7 -0
- package/dist/cjs/utils/constants.js +38 -0
- package/dist/cjs/utils/constants.js.map +7 -0
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.js +19 -0
- package/dist/cjs/utils/index.js.map +7 -0
- package/dist/esm/client.d.ts +198 -0
- package/dist/esm/client.js +623 -0
- package/dist/esm/client.js.map +7 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/package.json +4 -0
- package/dist/esm/types/bcs.d.ts +11 -0
- package/dist/esm/types/bcs.js +16 -0
- package/dist/esm/types/bcs.js.map +7 -0
- package/dist/esm/types/index.d.ts +51 -0
- package/dist/esm/types/index.js +17 -0
- package/dist/esm/types/index.js.map +7 -0
- package/dist/esm/utils/constants.d.ts +7 -0
- package/dist/esm/utils/constants.js +18 -0
- package/dist/esm/utils/constants.js.map +7 -0
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.js +2 -0
- package/dist/esm/utils/index.js.map +7 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +56 -0
- package/src/client.ts +786 -0
- package/src/index.ts +4 -0
- package/src/types/bcs.ts +16 -0
- package/src/types/index.ts +71 -0
- package/src/utils/constants.ts +18 -0
- package/src/utils/index.ts +4 -0
package/README.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import type { OrderArguments, PaginatedEvents, PaginationArguments } from '@haneullabs/haneul/client';
|
|
2
|
+
import { HaneulClient } from '@haneullabs/haneul/client';
|
|
3
|
+
import type { Argument, TransactionObjectInput, TransactionResult } from '@haneullabs/haneul/transactions';
|
|
4
|
+
import { Transaction } from '@haneullabs/haneul/transactions';
|
|
5
|
+
import type { Level2BookStatusPoint, MarketPrice, Order, PaginatedPoolSummary, PoolSummary, UserPosition } from './types/index.js';
|
|
6
|
+
import { LimitOrderType, SelfMatchingPreventionStyle } from './types/index.js';
|
|
7
|
+
export declare class DeepBookClient {
|
|
8
|
+
#private;
|
|
9
|
+
haneulClient: HaneulClient;
|
|
10
|
+
accountCap: string | undefined;
|
|
11
|
+
currentAddress: string;
|
|
12
|
+
private clientOrderId;
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param haneulClient connection to fullnode
|
|
16
|
+
* @param accountCap (optional) only required for wrting operations
|
|
17
|
+
* @param currentAddress (optional) address of the current user (default: DUMMY_ADDRESS)
|
|
18
|
+
*/
|
|
19
|
+
constructor(haneulClient?: HaneulClient, accountCap?: string | undefined, currentAddress?: string, clientOrderId?: number);
|
|
20
|
+
/**
|
|
21
|
+
* @param cap set the account cap for interacting with DeepBook
|
|
22
|
+
*/
|
|
23
|
+
setAccountCap(cap: string): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* @description Create pool for trading pair
|
|
26
|
+
* @param baseAssetType Full coin type of the base asset, eg: "0x3d0d0ce17dcd3b40c2d839d96ce66871ffb40e1154a8dd99af72292b3d10d7fc::wbtc::WBTC"
|
|
27
|
+
* @param quoteAssetType Full coin type of quote asset, eg: "0x3d0d0ce17dcd3b40c2d839d96ce66871ffb40e1154a8dd99af72292b3d10d7fc::usdt::USDT"
|
|
28
|
+
* @param tickSize Minimal Price Change Accuracy of this pool, eg: 10000000. The number must be an integer float scaled by `FLOAT_SCALING_FACTOR`.
|
|
29
|
+
* @param lotSize Minimal Lot Change Accuracy of this pool, eg: 10000.
|
|
30
|
+
*/
|
|
31
|
+
createPool(baseAssetType: string, quoteAssetType: string, tickSize: bigint, lotSize: bigint): Transaction;
|
|
32
|
+
/**
|
|
33
|
+
* @description Create pool for trading pair
|
|
34
|
+
* @param baseAssetType Full coin type of the base asset, eg: "0x3d0d0ce17dcd3b40c2d839d96ce66871ffb40e1154a8dd99af72292b3d10d7fc::wbtc::WBTC"
|
|
35
|
+
* @param quoteAssetType Full coin type of quote asset, eg: "0x3d0d0ce17dcd3b40c2d839d96ce66871ffb40e1154a8dd99af72292b3d10d7fc::usdt::USDT"
|
|
36
|
+
* @param tickSize Minimal Price Change Accuracy of this pool, eg: 10000000. The number must be an interger float scaled by `FLOAT_SCALING_FACTOR`.
|
|
37
|
+
* @param lotSize Minimal Lot Change Accuracy of this pool, eg: 10000.
|
|
38
|
+
* @param takerFeeRate Customized taker fee rate, float scaled by `FLOAT_SCALING_FACTOR`, Taker_fee_rate of 0.25% should be 2_500_000 for example
|
|
39
|
+
* @param makerRebateRate Customized maker rebate rate, float scaled by `FLOAT_SCALING_FACTOR`, should be less than or equal to the taker_rebate_rate
|
|
40
|
+
*/
|
|
41
|
+
createCustomizedPool(baseAssetType: string, quoteAssetType: string, tickSize: bigint, lotSize: bigint, takerFeeRate: bigint, makerRebateRate: bigint): Transaction;
|
|
42
|
+
/**
|
|
43
|
+
* @description Create Account Cap
|
|
44
|
+
* @param tx
|
|
45
|
+
*/
|
|
46
|
+
createAccountCap(tx: Transaction): {
|
|
47
|
+
$kind: "NestedResult";
|
|
48
|
+
NestedResult: [number, number];
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* @description Create and Transfer custodian account to user
|
|
52
|
+
* @param currentAddress current address of the user
|
|
53
|
+
* @param tx
|
|
54
|
+
*/
|
|
55
|
+
createAccount(currentAddress?: string, tx?: Transaction): Transaction;
|
|
56
|
+
/**
|
|
57
|
+
* @description Create and Transfer custodian account to user
|
|
58
|
+
* @param currentAddress: current user address, eg: "0xbddc9d4961b46a130c2e1f38585bbc6fa8077ce54bcb206b26874ac08d607966"
|
|
59
|
+
* @param accountCap: Object id of Account Capacity under user address, created after invoking createAccount, eg: "0x6f699fef193723277559c8f499ca3706121a65ac96d273151b8e52deb29135d3"
|
|
60
|
+
*/
|
|
61
|
+
createChildAccountCap(currentAddress?: string, accountCap?: string | undefined): Transaction;
|
|
62
|
+
/**
|
|
63
|
+
* @description construct transaction for depositing asset into a pool.
|
|
64
|
+
* @param poolId the pool id for the deposit
|
|
65
|
+
* @param coinId the coin used for the deposit. You can omit this argument if you are depositing SUI, in which case
|
|
66
|
+
* gas coin will be used
|
|
67
|
+
* @param amount the amount of coin to deposit. If omitted, the entire balance of the coin will be deposited
|
|
68
|
+
*/
|
|
69
|
+
deposit(poolId: string, coinId?: string | undefined, quantity?: bigint | undefined): Promise<Transaction>;
|
|
70
|
+
/**
|
|
71
|
+
* @description construct transaction for withdrawing asset from a pool.
|
|
72
|
+
* @param poolId the pool id for the withdraw
|
|
73
|
+
* @param amount the amount of coin to withdraw
|
|
74
|
+
* @param assetType Base or Quote
|
|
75
|
+
* @param recipientAddress the address to receive the withdrawn asset. If omitted, `this.currentAddress` will be used. The function
|
|
76
|
+
* will throw if the `recipientAddress === DUMMY_ADDRESS`
|
|
77
|
+
*/
|
|
78
|
+
withdraw(poolId: string, quantity: bigint, assetType: 'base' | 'quote', recipientAddress?: string): Promise<Transaction>;
|
|
79
|
+
/**
|
|
80
|
+
* @description place a limit order
|
|
81
|
+
* @param poolId Object id of pool, created after invoking createPool, eg: "0xcaee8e1c046b58e55196105f1436a2337dcaa0c340a7a8c8baf65e4afb8823a4"
|
|
82
|
+
* @param price: price of the limit order. The number must be an interger float scaled by `FLOAT_SCALING_FACTOR`.
|
|
83
|
+
* @param quantity: quantity of the limit order in BASE ASSET, eg: 100000000.
|
|
84
|
+
* @param orderType: bid for buying base with quote, ask for selling base for quote
|
|
85
|
+
* @param expirationTimestamp: expiration timestamp of the limit order in ms, eg: 1620000000000. If omitted, the order will expire in 1 day
|
|
86
|
+
* from the time this function is called(not the time the transaction is executed)
|
|
87
|
+
* @param restriction restrictions on limit orders, explain in doc for more details, eg: 0
|
|
88
|
+
* @param clientOrderId a client side defined order number for bookkeeping purpose, e.g., "1", "2", etc. If omitted, the sdk will
|
|
89
|
+
* assign a increasing number starting from 0. But this number might be duplicated if you are using multiple sdk instances
|
|
90
|
+
* @param selfMatchingPrevention: Options for self-match prevention. Right now only support `CANCEL_OLDEST`
|
|
91
|
+
*/
|
|
92
|
+
placeLimitOrder(poolId: string, price: bigint, quantity: bigint, orderType: 'bid' | 'ask', expirationTimestamp?: number, restriction?: LimitOrderType, clientOrderId?: string | undefined, selfMatchingPrevention?: SelfMatchingPreventionStyle): Promise<Transaction>;
|
|
93
|
+
/**
|
|
94
|
+
* @description place a market order
|
|
95
|
+
* @param poolId Object id of pool, created after invoking createPool, eg: "0xcaee8e1c046b58e55196105f1436a2337dcaa0c340a7a8c8baf65e4afb8823a4"
|
|
96
|
+
* @param quantity Amount of quote asset to swap in base asset
|
|
97
|
+
* @param orderType bid for buying base with quote, ask for selling base for quote
|
|
98
|
+
* @param baseCoin the objectId or the coin object of the base coin
|
|
99
|
+
* @param quoteCoin the objectId or the coin object of the quote coin
|
|
100
|
+
* @param clientOrderId a client side defined order id for bookkeeping purpose. eg: "1" , "2", ... If omitted, the sdk will
|
|
101
|
+
* assign an increasing number starting from 0. But this number might be duplicated if you are using multiple sdk instances
|
|
102
|
+
* @param accountCap
|
|
103
|
+
* @param recipientAddress the address to receive the swapped asset. If omitted, `this.currentAddress` will be used. The function
|
|
104
|
+
* @param tx
|
|
105
|
+
*/
|
|
106
|
+
placeMarketOrder(accountCap: string | Extract<Argument, {
|
|
107
|
+
$kind: 'NestedResult';
|
|
108
|
+
}>, poolId: string, quantity: bigint, orderType: 'bid' | 'ask', baseCoin?: TransactionResult | string | undefined, quoteCoin?: TransactionResult | string | undefined, clientOrderId?: string | undefined, recipientAddress?: string | undefined, tx?: Transaction): Promise<Transaction>;
|
|
109
|
+
/**
|
|
110
|
+
* @description swap exact quote for base
|
|
111
|
+
* @param poolId Object id of pool, created after invoking createPool, eg: "0xcaee8e1c046b58e55196105f1436a2337dcaa0c340a7a8c8baf65e4afb8823a4"
|
|
112
|
+
* @param tokenObjectIn Object id of the token to swap: eg: "0x6e566fec4c388eeb78a7dab832c9f0212eb2ac7e8699500e203def5b41b9c70d"
|
|
113
|
+
* @param amountIn amount of token to buy or sell, eg: 10000000.
|
|
114
|
+
* @param currentAddress current user address, eg: "0xbddc9d4961b46a130c2e1f38585bbc6fa8077ce54bcb206b26874ac08d607966"
|
|
115
|
+
* @param clientOrderId a client side defined order id for bookkeeping purpose, eg: "1" , "2", ... If omitted, the sdk will
|
|
116
|
+
* assign an increasing number starting from 0. But this number might be duplicated if you are using multiple sdk instances
|
|
117
|
+
* @param tx
|
|
118
|
+
*/
|
|
119
|
+
swapExactQuoteForBase(poolId: string, tokenObjectIn: TransactionObjectInput, amountIn: bigint, // quantity of USDC
|
|
120
|
+
currentAddress: string, clientOrderId?: string, tx?: Transaction): Promise<Transaction>;
|
|
121
|
+
/**
|
|
122
|
+
* @description swap exact base for quote
|
|
123
|
+
* @param poolId Object id of pool, created after invoking createPool, eg: "0xcaee8e1c046b58e55196105f1436a2337dcaa0c340a7a8c8baf65e4afb8823a4"
|
|
124
|
+
* @param tokenObjectIn Object id of the token to swap: eg: "0x6e566fec4c388eeb78a7dab832c9f0212eb2ac7e8699500e203def5b41b9c70d"
|
|
125
|
+
* @param amountIn amount of token to buy or sell, eg: 10000000
|
|
126
|
+
* @param currentAddress current user address, eg: "0xbddc9d4961b46a130c2e1f38585bbc6fa8077ce54bcb206b26874ac08d607966"
|
|
127
|
+
* @param clientOrderId a client side defined order number for bookkeeping purpose. eg: "1" , "2", ...
|
|
128
|
+
*/
|
|
129
|
+
swapExactBaseForQuote(poolId: string, tokenObjectIn: string, amountIn: bigint, currentAddress: string, clientOrderId?: string | undefined): Promise<Transaction>;
|
|
130
|
+
/**
|
|
131
|
+
* @description cancel an order
|
|
132
|
+
* @param poolId Object id of pool, created after invoking createPool, eg: "0xcaee8e1c046b58e55196105f1436a2337dcaa0c340a7a8c8baf65e4afb8823a4"
|
|
133
|
+
* @param orderId orderId of a limit order, you can find them through function query.list_open_orders eg: "0"
|
|
134
|
+
*/
|
|
135
|
+
cancelOrder(poolId: string, orderId: string): Promise<Transaction>;
|
|
136
|
+
/**
|
|
137
|
+
* @description Cancel all limit orders under a certain account capacity
|
|
138
|
+
* @param poolId Object id of pool, created after invoking createPool, eg: "0xcaee8e1c046b58e55196105f1436a2337dcaa0c340a7a8c8baf65e4afb8823a4"
|
|
139
|
+
*/
|
|
140
|
+
cancelAllOrders(poolId: string): Promise<Transaction>;
|
|
141
|
+
/**
|
|
142
|
+
* @description batch cancel order
|
|
143
|
+
* @param poolId Object id of pool, created after invoking createPool, eg: "0xcaee8e1c046b58e55196105f1436a2337dcaa0c340a7a8c8baf65e4afb8823a4"
|
|
144
|
+
* @param orderIds array of order ids you want to cancel, you can find your open orders by query.list_open_orders eg: ["0", "1", "2"]
|
|
145
|
+
*/
|
|
146
|
+
batchCancelOrder(poolId: string, orderIds: string[]): Promise<Transaction>;
|
|
147
|
+
/**
|
|
148
|
+
* @param poolId Object id of pool, created after invoking createPool, eg: "0xcaee8e1c046b58e55196105f1436a2337dcaa0c340a7a8c8baf65e4afb8823a4"
|
|
149
|
+
* @param orderIds array of expired order ids to clean, eg: ["0", "1", "2"]
|
|
150
|
+
* @param orderOwners array of Order owners, should be the owner addresses from the account capacities which placed the orders
|
|
151
|
+
*/
|
|
152
|
+
cleanUpExpiredOrders(poolId: string, orderIds: string[], orderOwners: string[]): Promise<Transaction>;
|
|
153
|
+
/**
|
|
154
|
+
* @description returns paginated list of pools created in DeepBook by querying for the
|
|
155
|
+
* `PoolCreated` event. Warning: this method can return incomplete results if the upstream data source
|
|
156
|
+
* is pruned.
|
|
157
|
+
*/
|
|
158
|
+
getAllPools(input: PaginationArguments<PaginatedEvents['nextCursor']> & OrderArguments): Promise<PaginatedPoolSummary>;
|
|
159
|
+
/**
|
|
160
|
+
* @description Fetch metadata for a pool
|
|
161
|
+
* @param poolId object id of the pool
|
|
162
|
+
* @returns Metadata for the Pool
|
|
163
|
+
*/
|
|
164
|
+
getPoolInfo(poolId: string): Promise<PoolSummary>;
|
|
165
|
+
getPoolTypeArgs(poolId: string): Promise<string[]>;
|
|
166
|
+
/**
|
|
167
|
+
* @description get the order status
|
|
168
|
+
* @param poolId: the pool id, eg: 0xcaee8e1c046b58e55196105f1436a2337dcaa0c340a7a8c8baf65e4afb8823a4
|
|
169
|
+
* @param orderId the order id, eg: "1"
|
|
170
|
+
*/
|
|
171
|
+
getOrderStatus(poolId: string, orderId: string, accountCap?: string | undefined): Promise<Order | undefined>;
|
|
172
|
+
/**
|
|
173
|
+
* @description get the base and quote token in custodian account
|
|
174
|
+
* @param poolId the pool id, eg: 0xcaee8e1c046b58e55196105f1436a2337dcaa0c340a7a8c8baf65e4afb8823a4
|
|
175
|
+
* @param accountCap your accountCap, eg: 0x6f699fef193723277559c8f499ca3706121a65ac96d273151b8e52deb29135d3. If not provided, `this.accountCap` will be used.
|
|
176
|
+
*/
|
|
177
|
+
getUserPosition(poolId: string, accountCap?: string | undefined): Promise<UserPosition>;
|
|
178
|
+
/**
|
|
179
|
+
* @description get the open orders of the current user
|
|
180
|
+
* @param poolId the pool id, eg: 0xcaee8e1c046b58e55196105f1436a2337dcaa0c340a7a8c8baf65e4afb8823a4
|
|
181
|
+
* @param accountCap your accountCap, eg: 0x6f699fef193723277559c8f499ca3706121a65ac96d273151b8e52deb29135d3. If not provided, `this.accountCap` will be used.
|
|
182
|
+
*/
|
|
183
|
+
listOpenOrders(poolId: string, accountCap?: string | undefined): Promise<Order[]>;
|
|
184
|
+
/**
|
|
185
|
+
* @description get the market price {bestBidPrice, bestAskPrice}
|
|
186
|
+
* @param poolId the pool id, eg: 0xcaee8e1c046b58e55196105f1436a2337dcaa0c340a7a8c8baf65e4afb8823a4
|
|
187
|
+
*/
|
|
188
|
+
getMarketPrice(poolId: string): Promise<MarketPrice>;
|
|
189
|
+
/**
|
|
190
|
+
* @description get level2 book status
|
|
191
|
+
* @param poolId the pool id, eg: 0xcaee8e1c046b58e55196105f1436a2337dcaa0c340a7a8c8baf65e4afb8823a4
|
|
192
|
+
* @param lowerPrice lower price you want to query in the level2 book, eg: 18000000000. The number must be an integer float scaled by `FLOAT_SCALING_FACTOR`.
|
|
193
|
+
* @param higherPrice higher price you want to query in the level2 book, eg: 20000000000. The number must be an integer float scaled by `FLOAT_SCALING_FACTOR`.
|
|
194
|
+
* @param side { 'bid' | 'ask' | 'both' } bid or ask or both sides.
|
|
195
|
+
*/
|
|
196
|
+
getLevel2BookStatus(poolId: string, lowerPrice: bigint, higherPrice: bigint, side: 'bid' | 'ask' | 'both'): Promise<Level2BookStatusPoint[] | Level2BookStatusPoint[][]>;
|
|
197
|
+
getCoinType(coinId: string): Promise<string | null>;
|
|
198
|
+
}
|