@bolt-liquidity-hq/sui-client 0.1.0-beta.10

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.
@@ -0,0 +1,371 @@
1
+ import { ChainConfig, ClientConfig, BaseClient, OracleConfig, OracleAssetPair, InvertiblePrice, Price, RouterConfig, Address, BaseLiquidityDetails, Coin, Pool, PoolConfig, Asset, SwapParams, SwapResult } from '@bolt-liquidity-hq/core';
2
+ import { SuiClient, SuiTransactionBlockResponse } from '@mysten/sui/client';
3
+ import { Signer } from '@mysten/sui/cryptography';
4
+ import * as _mysten_bcs from '@mysten/bcs';
5
+ import { BcsType } from '@mysten/bcs';
6
+
7
+ declare const PaginationStruct: {
8
+ total_count: BcsType<string, string | number | bigint, "u64">;
9
+ has_next_page: BcsType<boolean, boolean, "bool">;
10
+ next_cursor: BcsType<string | null, string | null | undefined, "Option<string>">;
11
+ };
12
+ declare const BcsAddressType: BcsType<string, string, "address">;
13
+ type BcsParsed<T extends BcsType<any, any>> = ReturnType<T['parse']>;
14
+ type BcsParsedMultiple<T extends readonly BcsType<any>[]> = {
15
+ [K in keyof T]: BcsParsed<T[K]>;
16
+ };
17
+
18
+ type SuiChainConfig = ChainConfig;
19
+
20
+ type SuiClientConfig = ClientConfig<SuiChainConfig> & {
21
+ suiClient?: SuiClient;
22
+ customOverride?: ClientConfig<SuiChainConfig>['customOverride'] & {
23
+ packageId?: string;
24
+ };
25
+ };
26
+
27
+ declare const OracleConfigStruct: _mysten_bcs.BcsStruct<{
28
+ admin: _mysten_bcs.BcsType<string, string, "address">;
29
+ price_threshold_ratio: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
30
+ default_price_expiry_seconds: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
31
+ }, string>;
32
+ type OracleConfigStructOutput = BcsParsed<typeof OracleConfigStruct>;
33
+ declare const AssetPairStruct: _mysten_bcs.BcsStruct<{
34
+ base_symbol: _mysten_bcs.BcsType<string, string, "string">;
35
+ quote_symbol: _mysten_bcs.BcsType<string, string, "string">;
36
+ base_precision: _mysten_bcs.BcsType<number, number, "u8">;
37
+ quote_precision: _mysten_bcs.BcsType<number, number, "u8">;
38
+ }, string>;
39
+ type AssetPairStructOutput = BcsParsed<typeof AssetPairStruct>;
40
+ declare const AssetPairsResponseStruct: _mysten_bcs.BcsStruct<{
41
+ asset_pairs: _mysten_bcs.BcsType<{
42
+ base_symbol: string;
43
+ quote_symbol: string;
44
+ base_precision: number;
45
+ quote_precision: number;
46
+ }[], Iterable<{
47
+ base_symbol: string;
48
+ quote_symbol: string;
49
+ base_precision: number;
50
+ quote_precision: number;
51
+ }> & {
52
+ length: number;
53
+ }, string>;
54
+ }, string>;
55
+ type AssetPairsResponseStructOutput = BcsParsed<typeof AssetPairsResponseStruct>;
56
+ declare const AssetPairsResponsePaginatedStruct: _mysten_bcs.BcsStruct<{
57
+ total_count: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
58
+ has_next_page: _mysten_bcs.BcsType<boolean, boolean, "bool">;
59
+ next_cursor: _mysten_bcs.BcsType<string | null, string | null | undefined, "Option<string>">;
60
+ asset_pairs: _mysten_bcs.BcsType<{
61
+ base_symbol: string;
62
+ quote_symbol: string;
63
+ base_precision: number;
64
+ quote_precision: number;
65
+ }[], Iterable<{
66
+ base_symbol: string;
67
+ quote_symbol: string;
68
+ base_precision: number;
69
+ quote_precision: number;
70
+ }> & {
71
+ length: number;
72
+ }, string>;
73
+ }, string>;
74
+ type AssetPairsResponsePaginatedStructOutput = BcsParsed<typeof AssetPairsResponsePaginatedStruct>;
75
+ declare const PriceDataStruct: _mysten_bcs.BcsStruct<{
76
+ price: _mysten_bcs.BcsType<string, string | number | bigint, "u128">;
77
+ expiry_time_ms: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
78
+ last_updated_ms: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
79
+ updater: _mysten_bcs.BcsType<string, string, "address">;
80
+ }, string>;
81
+ type PriceDataStructOutput = BcsParsed<typeof PriceDataStruct>;
82
+ declare const PriceResponseStruct: _mysten_bcs.BcsStruct<{
83
+ pair_data: _mysten_bcs.BcsType<{
84
+ price: string;
85
+ expiry_time_ms: string;
86
+ last_updated_ms: string;
87
+ updater: string;
88
+ } | null, {
89
+ price: string | number | bigint;
90
+ expiry_time_ms: string | number | bigint;
91
+ last_updated_ms: string | number | bigint;
92
+ updater: string;
93
+ } | null | undefined, `Option<${string}>`>;
94
+ }, string>;
95
+ type PriceResponseStructOutput = BcsParsed<typeof PriceResponseStruct>;
96
+ declare const PricesResponsePaginatedStruct: _mysten_bcs.BcsStruct<{
97
+ total_count: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
98
+ has_next_page: _mysten_bcs.BcsType<boolean, boolean, "bool">;
99
+ next_cursor: _mysten_bcs.BcsType<string | null, string | null | undefined, "Option<string>">;
100
+ prices: _mysten_bcs.BcsType<{
101
+ price: string;
102
+ expiry_time_ms: string;
103
+ last_updated_ms: string;
104
+ updater: string;
105
+ }[], Iterable<{
106
+ price: string | number | bigint;
107
+ expiry_time_ms: string | number | bigint;
108
+ last_updated_ms: string | number | bigint;
109
+ updater: string;
110
+ }> & {
111
+ length: number;
112
+ }, string>;
113
+ }, string>;
114
+ type PricesResponsePaginatedStructOutput = BcsParsed<typeof PricesResponsePaginatedStruct>;
115
+
116
+ declare const RouterConfigStruct: _mysten_bcs.BcsStruct<{
117
+ admin: _mysten_bcs.BcsType<string, string, "address">;
118
+ default_price_oracle_contract: _mysten_bcs.BcsType<string, string, "address">;
119
+ default_protocol_fee_recipient: _mysten_bcs.BcsType<string, string, "address">;
120
+ default_protocol_fee: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
121
+ default_lp_fee: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
122
+ }, string>;
123
+ type RouterConfigStructOutput = BcsParsed<typeof RouterConfigStruct>;
124
+ declare const MarketStruct: _mysten_bcs.BcsStruct<{
125
+ base_asset_symbol: _mysten_bcs.BcsType<string, string, "string">;
126
+ quote_assets_symbols: _mysten_bcs.BcsType<string[], Iterable<string> & {
127
+ length: number;
128
+ }, string>;
129
+ market_address: _mysten_bcs.BcsType<string, string, "string">;
130
+ is_permissioned: _mysten_bcs.BcsType<boolean, boolean, "bool">;
131
+ created_at_ms: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
132
+ }, string>;
133
+ type MarketStructOutput = BcsParsed<typeof MarketStruct>;
134
+ declare const MarketResponseStruct: _mysten_bcs.BcsStruct<{
135
+ market: _mysten_bcs.BcsType<{
136
+ base_asset_symbol: string;
137
+ quote_assets_symbols: string[];
138
+ market_address: string;
139
+ is_permissioned: boolean;
140
+ created_at_ms: string;
141
+ } | null, {
142
+ base_asset_symbol: string;
143
+ quote_assets_symbols: Iterable<string> & {
144
+ length: number;
145
+ };
146
+ market_address: string;
147
+ is_permissioned: boolean;
148
+ created_at_ms: string | number | bigint;
149
+ } | null | undefined, `Option<${string}>`>;
150
+ }, string>;
151
+ type MarketResponseStructOutput = BcsParsed<typeof MarketResponseStruct>;
152
+ declare const MarketsResponseStruct: _mysten_bcs.BcsStruct<{
153
+ markets: _mysten_bcs.BcsType<{
154
+ base_asset_symbol: string;
155
+ quote_assets_symbols: string[];
156
+ market_address: string;
157
+ is_permissioned: boolean;
158
+ created_at_ms: string;
159
+ }[], Iterable<{
160
+ base_asset_symbol: string;
161
+ quote_assets_symbols: Iterable<string> & {
162
+ length: number;
163
+ };
164
+ market_address: string;
165
+ is_permissioned: boolean;
166
+ created_at_ms: string | number | bigint;
167
+ }> & {
168
+ length: number;
169
+ }, string>;
170
+ }, string>;
171
+ type MarketsResponseStructOutput = BcsParsed<typeof MarketsResponseStruct>;
172
+ declare const MarketsResponsePaginatedStruct: _mysten_bcs.BcsStruct<{
173
+ total_count: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
174
+ has_next_page: _mysten_bcs.BcsType<boolean, boolean, "bool">;
175
+ next_cursor: _mysten_bcs.BcsType<string | null, string | null | undefined, "Option<string>">;
176
+ markets: _mysten_bcs.BcsType<{
177
+ base_asset_symbol: string;
178
+ quote_assets_symbols: string[];
179
+ market_address: string;
180
+ is_permissioned: boolean;
181
+ created_at_ms: string;
182
+ }[], Iterable<{
183
+ base_asset_symbol: string;
184
+ quote_assets_symbols: Iterable<string> & {
185
+ length: number;
186
+ };
187
+ market_address: string;
188
+ is_permissioned: boolean;
189
+ created_at_ms: string | number | bigint;
190
+ }> & {
191
+ length: number;
192
+ }, string>;
193
+ }, string>;
194
+ type MarketsResponsePaginatedStructOutput = BcsParsed<typeof MarketsResponsePaginatedStruct>;
195
+ declare const BaseLiquidityResponseStruct: _mysten_bcs.BcsStruct<{
196
+ total_count: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
197
+ has_next_page: _mysten_bcs.BcsType<boolean, boolean, "bool">;
198
+ next_cursor: _mysten_bcs.BcsType<string | null, string | null | undefined, "Option<string>">;
199
+ base_assets: _mysten_bcs.BcsType<string[], Iterable<string> & {
200
+ length: number;
201
+ }, string>;
202
+ }, string>;
203
+ type BaseLiquidityResponseStructOutput = BcsParsed<typeof BaseLiquidityResponseStruct>;
204
+
205
+ declare const GetPoolInfoResponseStruct: readonly [_mysten_bcs.BcsType<string, string | number | bigint, "u64">, _mysten_bcs.BcsType<string, string | number | bigint, "u128">, _mysten_bcs.BcsType<string, string, "address">, _mysten_bcs.BcsType<boolean, boolean, "bool">];
206
+ type GetPoolInfoResponseStructOutput = BcsParsedMultiple<typeof GetPoolInfoResponseStruct>;
207
+ declare const GetFeesResponseStruct: readonly [_mysten_bcs.BcsType<string, string | number | bigint, "u64">, _mysten_bcs.BcsType<string, string | number | bigint, "u64">, _mysten_bcs.BcsType<string, string | number | bigint, "u64">];
208
+ type GetFeesResponseStructOutput = BcsParsedMultiple<typeof GetFeesResponseStruct>;
209
+
210
+ /**
211
+ * Client implementation for interacting with the Bolt Liquidity Outpost on Sui blockchain.
212
+ *
213
+ * This class extends the abstract {@link BaseClient} to provide Sui-specific functionality
214
+ * for querying and executing transactions on Bolt Protocol's oracle and router smart contracts.
215
+ * It uses SuiTransactionBlockResponse as the transaction output type, providing detailed transaction execution information.
216
+ *
217
+ * @extends {BaseClient<Signer, SuiTransactionBlockResponse>}
218
+ *
219
+ * @group Bolt API Clients
220
+ *
221
+ * @example
222
+ * ```typescript
223
+ * // Create a client for Sui mainnet
224
+ * const client = new BoltSuiClient();
225
+ *
226
+ * // Query oracle prices
227
+ * const price = await client.getPrice("0x2::sui::SUI", "0xusdcAddress...");
228
+ *
229
+ * // Execute a swap (requires signer)
230
+ * const signer = // ... get signer from wallet
231
+ * const result = await client.swap(signer, {
232
+ * assetIn: "0x2::sui::SUI",
233
+ * amountIn: "1000000000", // 1 SUI (9 decimals)
234
+ * assetOut: "0xusdcAddress..."
235
+ * });
236
+ * ```
237
+ */
238
+ declare class BoltSuiClient extends BaseClient<Signer, SuiTransactionBlockResponse> {
239
+ /**
240
+ * The Sui-specific chain configuration including RPC endpoint
241
+ */
242
+ chainConfig: SuiChainConfig;
243
+ /**
244
+ * Package Id for the deployed Bolt contracts on Sui
245
+ */
246
+ packageId: string;
247
+ /**
248
+ * Instance of the Sui client to interact with the blockchain
249
+ */
250
+ suiClient: SuiClient;
251
+ /**
252
+ * Creates a new instance of the BoltSuiClient.
253
+ *
254
+ * The client automatically configures itself based on the specified chain and environment,
255
+ * loading the appropriate contract addresses, chain configuration, and assets from configuration files.
256
+ *
257
+ * @param config - (Optional) Configuration for the client
258
+ * @param config.environment - (Optional) The deployment environment ('mainnet' or 'testnet'). Defaults to 'mainnet'
259
+ * @param config.customOverride - (Optional) Custom overrides for chain configuration, contracts, and assets
260
+ * @param config.customOverride.chainConfig - (Optional) Override chain configuration
261
+ * @param config.customOverride.chainConfig.id - (Optional) Custom chain ID
262
+ * @param config.customOverride.chainConfig.name - (Optional) Custom chain name
263
+ * @param config.customOverride.chainConfig.rpcEndpoint - (Optional) Custom RPC endpoint URL
264
+ * @param config.customOverride.packageId - (Optional) Custom package ID for Bolt contracts
265
+ * @param config.customOverride.contracts - (Optional) Override contract addresses
266
+ * @param config.customOverride.contracts.oracle - (Optional) Custom oracle contract address
267
+ * @param config.customOverride.contracts.router - (Optional) Custom router contract address
268
+ * @param config.customOverride.assetsConfig - (Optional) Custom asset configurations indexed by denom
269
+ * @param config.suiClient - (Optional) Pre-existing SuiClient to use for blockchain queries
270
+ *
271
+ * @throws {InvalidObjectError} Thrown when required configuration fields are missing
272
+ *
273
+ * @example
274
+ * ```typescript
275
+ * // Use default configuration (Sui mainnet)
276
+ * const client = new BoltSuiClient();
277
+ *
278
+ * // Use testnet configuration
279
+ * const testnetClient = new BoltSuiClient({
280
+ * environment: 'testnet'
281
+ * });
282
+ *
283
+ * // Use custom chain configuration
284
+ * const customClient = new BoltSuiClient({
285
+ * customOverride: {
286
+ * chainConfig: {
287
+ * id: 'sui-custom',
288
+ * name: 'Sui Custom',
289
+ * rpcEndpoint: 'https://custom-rpc.example.com'
290
+ * },
291
+ * packageId: '0xcustom_package_id...',
292
+ * contracts: {
293
+ * oracle: '0xcustom_oracle...',
294
+ * router: '0xcustom_router...'
295
+ * },
296
+ * assetsConfig: {
297
+ * '0x2::sui::SUI': {
298
+ * symbol: 'SUI',
299
+ * name: 'Sui',
300
+ * chainId: 'sui-custom',
301
+ * denom: '0x2::sui::SUI',
302
+ * decimals: 9,
303
+ * logo: 'https://example.com/sui.png',
304
+ * coingeckoId: 'sui'
305
+ * }
306
+ * }
307
+ * }
308
+ * });
309
+ *
310
+ * // Use pre-existing Sui client
311
+ * const clientWithCustomClient = new BoltSuiClient({
312
+ * suiClient: mySuiClient
313
+ * });
314
+ * ```
315
+ */
316
+ constructor(config?: SuiClientConfig);
317
+ /** @inheritdoc */
318
+ getOracleConfig(): Promise<OracleConfig>;
319
+ /** @inheritdoc */
320
+ getAllOracleAssetPairs(): Promise<OracleAssetPair[]>;
321
+ /** @inheritdoc */
322
+ getPrice(baseDenom: string, quoteDenom: string): Promise<InvertiblePrice>;
323
+ /** @inheritdoc */
324
+ getAllPrices(): Promise<Price[]>;
325
+ /** @inheritdoc */
326
+ getRouterConfig(): Promise<RouterConfig>;
327
+ /** @inheritdoc */
328
+ getAllBaseAssetsLiquidity(): Promise<Record<Address, BaseLiquidityDetails>>;
329
+ /** @inheritdoc */
330
+ getAllQuotesByUser(address: Address): Promise<Record<Address, Coin[]>>;
331
+ /** @inheritdoc */
332
+ getPoolByBaseAsset(baseDenom: string): Promise<Pool>;
333
+ /** @inheritdoc */
334
+ getAllPools(): Promise<Pool[]>;
335
+ getPoolConfig(poolContractAddress: string): Promise<PoolConfig>;
336
+ /** @inheritdoc */
337
+ getAssets(): Promise<Asset[]>;
338
+ /** @inheritdoc */
339
+ getPoolConfigByBaseAsset(baseDenom: string): Promise<PoolConfig>;
340
+ /**
341
+ * @inheritdoc
342
+ *
343
+ * @example
344
+ * ```typescript
345
+ * // Get signer from wallet (e.g., Sui Wallet, Suiet, etc.)
346
+ * const signer = // ... obtain signer from wallet
347
+ *
348
+ * // Execute swap: 1 SUI for USDC
349
+ * const result = await client.swap(signer, {
350
+ * assetIn: "0x2::sui::SUI",
351
+ * amountIn: "1000000000", // 1 SUI (9 decimals)
352
+ * assetOut: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN", // USDC address
353
+ * minimumAmountOut: "1950000", // Minimum 1.95 USDC expected (6 decimals)
354
+ * receiver: "0x..." // Optional custom receiver address
355
+ * });
356
+ *
357
+ * console.log(`Swap successful!`);
358
+ * console.log(`Transaction digest: ${result.txHash}`);
359
+ * console.log(`Received: ${result.amountOut} ${result.assetOut}`);
360
+ * console.log(`Gas cost: ${result.txOutput.effects.gasUsed.computationCost}`);
361
+ * console.log(`Status: ${result.txOutput.effects.status.status}`);
362
+ * ```
363
+ *
364
+ * @remarks
365
+ * This implementation returns a SuiTransactionBlockResponse as the transaction output,
366
+ * which includes details like gas costs, transaction effects, object changes, and events.
367
+ */
368
+ swap(signer: Signer, params: SwapParams): Promise<SwapResult<SuiTransactionBlockResponse>>;
369
+ }
370
+
371
+ export { AssetPairStruct, type AssetPairStructOutput, AssetPairsResponsePaginatedStruct, type AssetPairsResponsePaginatedStructOutput, AssetPairsResponseStruct, type AssetPairsResponseStructOutput, BaseLiquidityResponseStruct, type BaseLiquidityResponseStructOutput, BcsAddressType, type BcsParsed, type BcsParsedMultiple, BoltSuiClient, GetFeesResponseStruct, type GetFeesResponseStructOutput, GetPoolInfoResponseStruct, type GetPoolInfoResponseStructOutput, MarketResponseStruct, type MarketResponseStructOutput, MarketStruct, type MarketStructOutput, MarketsResponsePaginatedStruct, type MarketsResponsePaginatedStructOutput, MarketsResponseStruct, type MarketsResponseStructOutput, OracleConfigStruct, type OracleConfigStructOutput, PaginationStruct, PriceDataStruct, type PriceDataStructOutput, PriceResponseStruct, type PriceResponseStructOutput, PricesResponsePaginatedStruct, type PricesResponsePaginatedStructOutput, RouterConfigStruct, type RouterConfigStructOutput, type SuiChainConfig, type SuiClientConfig };