@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.
- package/LICENSE +201 -0
- package/README.md +52 -0
- package/dist/index.cjs +836 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +371 -0
- package/dist/index.d.ts +371 -0
- package/dist/index.js +815 -0
- package/dist/index.js.map +1 -0
- package/package.json +85 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,836 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
+
|
|
22
|
+
// src/index.ts
|
|
23
|
+
var index_exports = {};
|
|
24
|
+
__export(index_exports, {
|
|
25
|
+
AssetPairStruct: () => AssetPairStruct,
|
|
26
|
+
AssetPairsResponsePaginatedStruct: () => AssetPairsResponsePaginatedStruct,
|
|
27
|
+
AssetPairsResponseStruct: () => AssetPairsResponseStruct,
|
|
28
|
+
BaseLiquidityResponseStruct: () => BaseLiquidityResponseStruct,
|
|
29
|
+
BcsAddressType: () => BcsAddressType,
|
|
30
|
+
BoltSuiClient: () => BoltSuiClient,
|
|
31
|
+
GetFeesResponseStruct: () => GetFeesResponseStruct,
|
|
32
|
+
GetPoolInfoResponseStruct: () => GetPoolInfoResponseStruct,
|
|
33
|
+
MarketResponseStruct: () => MarketResponseStruct,
|
|
34
|
+
MarketStruct: () => MarketStruct,
|
|
35
|
+
MarketsResponsePaginatedStruct: () => MarketsResponsePaginatedStruct,
|
|
36
|
+
MarketsResponseStruct: () => MarketsResponseStruct,
|
|
37
|
+
OracleConfigStruct: () => OracleConfigStruct,
|
|
38
|
+
PaginationStruct: () => PaginationStruct,
|
|
39
|
+
PriceDataStruct: () => PriceDataStruct,
|
|
40
|
+
PriceResponseStruct: () => PriceResponseStruct,
|
|
41
|
+
PricesResponsePaginatedStruct: () => PricesResponsePaginatedStruct,
|
|
42
|
+
RouterConfigStruct: () => RouterConfigStruct
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(index_exports);
|
|
45
|
+
|
|
46
|
+
// src/lib/client.ts
|
|
47
|
+
var import_core5 = require("@bolt-liquidity-hq/core");
|
|
48
|
+
var import_client = require("@mysten/sui/client");
|
|
49
|
+
|
|
50
|
+
// src/config/mainnet.ts
|
|
51
|
+
var MainnetChainConfig = {
|
|
52
|
+
name: "Sui",
|
|
53
|
+
id: "101",
|
|
54
|
+
rpcEndpoint: "https://fullnode.mainnet.sui.io:443"
|
|
55
|
+
};
|
|
56
|
+
var MainnetContracts = {
|
|
57
|
+
oracle: "0x...",
|
|
58
|
+
router: "0x..."
|
|
59
|
+
};
|
|
60
|
+
var MainnetPackageId = "0x...";
|
|
61
|
+
var MainnetAssets = {
|
|
62
|
+
"0x2::sui::SUI": {
|
|
63
|
+
symbol: "SUI",
|
|
64
|
+
name: "Sui",
|
|
65
|
+
chainId: "101",
|
|
66
|
+
denom: "0x2::sui::SUI",
|
|
67
|
+
decimals: 9,
|
|
68
|
+
logo: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/sui/info/logo.png",
|
|
69
|
+
coingeckoId: "sui"
|
|
70
|
+
},
|
|
71
|
+
"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC": {
|
|
72
|
+
symbol: "USDC",
|
|
73
|
+
name: "Circle USDC",
|
|
74
|
+
chainId: "101",
|
|
75
|
+
denom: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
|
|
76
|
+
decimals: 6,
|
|
77
|
+
logo: "https://raw.githubusercontent.com/cosmos/chain-registry/master/noble/images/USDCoin.png",
|
|
78
|
+
coingeckoId: "usd-coin"
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// src/config/testnet.ts
|
|
83
|
+
var TestnetChainConfig = {
|
|
84
|
+
name: "Sui Testnet",
|
|
85
|
+
id: "103",
|
|
86
|
+
rpcEndpoint: "https://fullnode.testnet.sui.io:443"
|
|
87
|
+
};
|
|
88
|
+
var TestnetContracts = {
|
|
89
|
+
oracle: "0xecece01cfb23b5439e04b18fe656eaf2746b9087cf68f1d48797c8f71a3dd93b",
|
|
90
|
+
router: "0x3881fdcb4a7fbcda8edc230e6f92eb57b24c0be6b44af0b5e1d0b45564f3ed00"
|
|
91
|
+
};
|
|
92
|
+
var TestnetPackageId = "0x22384b1841229e2be878bb7e88833c03e23ff5dc39accd050fb932120602f85e";
|
|
93
|
+
var TestnetAssets = {
|
|
94
|
+
"0x2::sui::SUI": {
|
|
95
|
+
symbol: "SUI",
|
|
96
|
+
name: "Sui",
|
|
97
|
+
chainId: "103",
|
|
98
|
+
denom: "0x2::sui::SUI",
|
|
99
|
+
decimals: 9,
|
|
100
|
+
logo: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/sui/info/logo.png",
|
|
101
|
+
coingeckoId: "sui"
|
|
102
|
+
},
|
|
103
|
+
"0xa1ec7fc00a6f40db9693ad1415d0c193ad3906494428cf252621037bd7117e29::usdc::USDC": {
|
|
104
|
+
symbol: "USDC",
|
|
105
|
+
name: "Circle USDC",
|
|
106
|
+
chainId: "103",
|
|
107
|
+
denom: "0xa1ec7fc00a6f40db9693ad1415d0c193ad3906494428cf252621037bd7117e29::usdc::USDC",
|
|
108
|
+
decimals: 6,
|
|
109
|
+
logo: "https://raw.githubusercontent.com/cosmos/chain-registry/master/noble/images/USDCoin.png",
|
|
110
|
+
coingeckoId: "usd-coin"
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// src/lib/oracle/get-asset-pairs.ts
|
|
115
|
+
var import_bcs9 = require("@mysten/bcs");
|
|
116
|
+
|
|
117
|
+
// src/lib/constants/defaults.ts
|
|
118
|
+
var DEFAULT_PAGINATION_LIMIT = 50;
|
|
119
|
+
|
|
120
|
+
// src/lib/constants/sui-objects.ts
|
|
121
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
122
|
+
var PRICE_ORACLE_MODULE = "price_oracle";
|
|
123
|
+
var ROUTER_MODULE = "router";
|
|
124
|
+
var POOL_MODULE = "settlement";
|
|
125
|
+
|
|
126
|
+
// src/lib/helpers/bcs-parse.ts
|
|
127
|
+
var import_core = require("@bolt-liquidity-hq/core");
|
|
128
|
+
var import_bcs = require("@mysten/bcs");
|
|
129
|
+
var extractBytes = (result, resultIndex = 0, returnValueIndex = 0) => {
|
|
130
|
+
const returnValues = result.results?.[resultIndex]?.returnValues;
|
|
131
|
+
if (!returnValues || !returnValues[returnValueIndex]) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const [bytes] = returnValues[returnValueIndex];
|
|
135
|
+
return new Uint8Array(bytes);
|
|
136
|
+
};
|
|
137
|
+
var parseDevInspectResult = (result, bcsType, resultIndex = 0, returnValueIndex = 0) => {
|
|
138
|
+
const bytes = extractBytes(result, resultIndex, returnValueIndex);
|
|
139
|
+
if (!bytes) {
|
|
140
|
+
throw new import_core.InvalidObjectError("When trying to parse result, no bytes found", {
|
|
141
|
+
bcsType,
|
|
142
|
+
resultIndex,
|
|
143
|
+
returnValueIndex
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
return bcsType.parse(bytes);
|
|
148
|
+
} catch (error) {
|
|
149
|
+
throw new import_core.ParseError("DevInspectResult", "from bcs to a typescript type", {
|
|
150
|
+
error,
|
|
151
|
+
result,
|
|
152
|
+
bcsType,
|
|
153
|
+
resultIndex,
|
|
154
|
+
returnValueIndex
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
var parseMultipleResults = (info, schema) => {
|
|
159
|
+
return schema.map((bcsType, index) => parseDevInspectResult(info, bcsType, 0, index));
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// src/lib/helpers/queries.ts
|
|
163
|
+
var import_core2 = require("@bolt-liquidity-hq/core");
|
|
164
|
+
var import_transactions = require("@mysten/sui/transactions");
|
|
165
|
+
var queryDevInspect = async (suiClient, target, args, typeArguments, senderAddress) => {
|
|
166
|
+
const tx = new import_transactions.Transaction();
|
|
167
|
+
const targetString = Array.isArray(target) ? `${target[0]}::${target[1]}::${target[2]}` : target;
|
|
168
|
+
const txArgs = args?.map(
|
|
169
|
+
(item) => typeof item === "string" ? tx.object(item) : tx.pure(item.toBytes())
|
|
170
|
+
);
|
|
171
|
+
tx.moveCall({
|
|
172
|
+
target: targetString,
|
|
173
|
+
arguments: txArgs,
|
|
174
|
+
typeArguments
|
|
175
|
+
});
|
|
176
|
+
try {
|
|
177
|
+
const result = await suiClient.devInspectTransactionBlock({
|
|
178
|
+
transactionBlock: tx,
|
|
179
|
+
sender: senderAddress ?? ZERO_ADDRESS
|
|
180
|
+
});
|
|
181
|
+
if (result.effects.status.status === "success") {
|
|
182
|
+
return result;
|
|
183
|
+
} else {
|
|
184
|
+
throw new import_core2.TransactionFailedError("N/A", "Failed to query smart contract", { result });
|
|
185
|
+
}
|
|
186
|
+
} catch (error) {
|
|
187
|
+
throw import_core2.UnexpectedError.from(error, "Failed to query smart contract", {
|
|
188
|
+
target: targetString,
|
|
189
|
+
args,
|
|
190
|
+
typeArguments
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// src/lib/oracle/parsers.ts
|
|
196
|
+
var import_core3 = require("@bolt-liquidity-hq/core");
|
|
197
|
+
var import_bignumber = require("bignumber.js");
|
|
198
|
+
var parseOracleConfigStructOutput = (output) => {
|
|
199
|
+
return {
|
|
200
|
+
admin: output.admin,
|
|
201
|
+
priceThresholdRatio: output.price_threshold_ratio,
|
|
202
|
+
priceExpireTime: {
|
|
203
|
+
secs: Number(output.default_price_expiry_seconds),
|
|
204
|
+
nanos: 0
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
var parseAssetPairStructOutput = (output) => {
|
|
209
|
+
return {
|
|
210
|
+
base: {
|
|
211
|
+
name: output.base_symbol,
|
|
212
|
+
symbol: output.base_symbol,
|
|
213
|
+
precision: output.base_precision
|
|
214
|
+
},
|
|
215
|
+
quote: {
|
|
216
|
+
name: output.quote_symbol,
|
|
217
|
+
symbol: output.quote_symbol,
|
|
218
|
+
precision: output.quote_precision
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
var parsePriceDataStructOutput = (response, baseDenom, quoteDenom) => {
|
|
223
|
+
return {
|
|
224
|
+
assetPair: `${baseDenom}:${quoteDenom}`,
|
|
225
|
+
price: response.price,
|
|
226
|
+
expiryTime: (0, import_bignumber.BigNumber)(response.expiry_time_ms).times(1e6).toFixed(),
|
|
227
|
+
isInverse: false
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
var parsePriceResponseStructOutput = (response, baseDenom, quoteDenom) => {
|
|
231
|
+
if (!response.pair_data) {
|
|
232
|
+
throw new import_core3.InvalidObjectError("Can't find pair data price");
|
|
233
|
+
}
|
|
234
|
+
return parsePriceDataStructOutput(response.pair_data, baseDenom, quoteDenom);
|
|
235
|
+
};
|
|
236
|
+
var parseAssetPairsResponsePaginatedStructOutput = (output) => {
|
|
237
|
+
return output.asset_pairs.map((item) => parseAssetPairStructOutput(item));
|
|
238
|
+
};
|
|
239
|
+
var parsePricesResponsePaginatedStructOutput = (output) => {
|
|
240
|
+
return output.prices.map((item) => parsePriceDataStructOutput(item, "", ""));
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
// src/types/bcs.ts
|
|
244
|
+
var import_bcs2 = require("@mysten/bcs");
|
|
245
|
+
var PaginationStruct = {
|
|
246
|
+
total_count: import_bcs2.bcs.u64(),
|
|
247
|
+
has_next_page: import_bcs2.bcs.bool(),
|
|
248
|
+
next_cursor: import_bcs2.bcs.option(import_bcs2.bcs.string())
|
|
249
|
+
};
|
|
250
|
+
var BcsAddressType = new import_bcs2.BcsType({
|
|
251
|
+
name: "address",
|
|
252
|
+
read(reader) {
|
|
253
|
+
const bytes = new Uint8Array(32);
|
|
254
|
+
for (let i = 0; i < 32; i++) {
|
|
255
|
+
bytes[i] = reader.read8();
|
|
256
|
+
}
|
|
257
|
+
return "0x" + Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
258
|
+
},
|
|
259
|
+
write(value, writer) {
|
|
260
|
+
const hex = value.startsWith("0x") ? value.slice(2) : value;
|
|
261
|
+
const paddedHex = hex.padStart(64, "0");
|
|
262
|
+
for (let i = 0; i < 32; i++) {
|
|
263
|
+
const byte = parseInt(paddedHex.substr(i * 2, 2), 16);
|
|
264
|
+
writer.write8(byte);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
// src/types/oracle.ts
|
|
270
|
+
var import_bcs3 = require("@mysten/bcs");
|
|
271
|
+
var OracleConfigStruct = import_bcs3.bcs.struct("Config", {
|
|
272
|
+
admin: BcsAddressType,
|
|
273
|
+
price_threshold_ratio: import_bcs3.bcs.u64(),
|
|
274
|
+
default_price_expiry_seconds: import_bcs3.bcs.u64()
|
|
275
|
+
});
|
|
276
|
+
var AssetPairStruct = import_bcs3.bcs.struct("AssetPair", {
|
|
277
|
+
base_symbol: import_bcs3.bcs.string(),
|
|
278
|
+
quote_symbol: import_bcs3.bcs.string(),
|
|
279
|
+
base_precision: import_bcs3.bcs.u8(),
|
|
280
|
+
quote_precision: import_bcs3.bcs.u8()
|
|
281
|
+
});
|
|
282
|
+
var AssetPairsResponseStruct = import_bcs3.bcs.struct("AssetPairsResponse", {
|
|
283
|
+
asset_pairs: import_bcs3.bcs.vector(AssetPairStruct)
|
|
284
|
+
});
|
|
285
|
+
var AssetPairsResponsePaginatedStruct = import_bcs3.bcs.struct("AssetPairsResponsePaginated", {
|
|
286
|
+
asset_pairs: import_bcs3.bcs.vector(AssetPairStruct),
|
|
287
|
+
...PaginationStruct
|
|
288
|
+
});
|
|
289
|
+
var PriceDataStruct = import_bcs3.bcs.struct("PriceData", {
|
|
290
|
+
price: import_bcs3.bcs.u128(),
|
|
291
|
+
expiry_time_ms: import_bcs3.bcs.u64(),
|
|
292
|
+
last_updated_ms: import_bcs3.bcs.u64(),
|
|
293
|
+
updater: BcsAddressType
|
|
294
|
+
});
|
|
295
|
+
var PriceResponseStruct = import_bcs3.bcs.struct("PriceResponse", {
|
|
296
|
+
pair_data: import_bcs3.bcs.option(PriceDataStruct)
|
|
297
|
+
});
|
|
298
|
+
var PricesResponsePaginatedStruct = import_bcs3.bcs.struct("PricesResponsePaginated", {
|
|
299
|
+
prices: import_bcs3.bcs.vector(PriceDataStruct),
|
|
300
|
+
...PaginationStruct
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
// src/types/router.ts
|
|
304
|
+
var import_bcs5 = require("@mysten/bcs");
|
|
305
|
+
var RouterConfigStruct = import_bcs5.bcs.struct("Config", {
|
|
306
|
+
admin: BcsAddressType,
|
|
307
|
+
default_price_oracle_contract: BcsAddressType,
|
|
308
|
+
default_protocol_fee_recipient: BcsAddressType,
|
|
309
|
+
default_protocol_fee: import_bcs5.bcs.u64(),
|
|
310
|
+
default_lp_fee: import_bcs5.bcs.u64()
|
|
311
|
+
});
|
|
312
|
+
var MarketStruct = import_bcs5.bcs.struct("Market", {
|
|
313
|
+
base_asset_symbol: import_bcs5.bcs.string(),
|
|
314
|
+
quote_assets_symbols: import_bcs5.bcs.vector(import_bcs5.bcs.string()),
|
|
315
|
+
market_address: import_bcs5.bcs.string(),
|
|
316
|
+
is_permissioned: import_bcs5.bcs.bool(),
|
|
317
|
+
created_at_ms: import_bcs5.bcs.u64()
|
|
318
|
+
});
|
|
319
|
+
var MarketResponseStruct = import_bcs5.bcs.struct("MarketResponse", {
|
|
320
|
+
market: import_bcs5.bcs.option(MarketStruct)
|
|
321
|
+
});
|
|
322
|
+
var MarketsResponseStruct = import_bcs5.bcs.struct("MarketsResponse", {
|
|
323
|
+
markets: import_bcs5.bcs.vector(MarketStruct)
|
|
324
|
+
});
|
|
325
|
+
var MarketsResponsePaginatedStruct = import_bcs5.bcs.struct("MarketsResponsePaginated", {
|
|
326
|
+
markets: import_bcs5.bcs.vector(MarketStruct),
|
|
327
|
+
...PaginationStruct
|
|
328
|
+
});
|
|
329
|
+
var BaseLiquidityResponseStruct = import_bcs5.bcs.struct("BaseLiquidityResponse", {
|
|
330
|
+
base_assets: import_bcs5.bcs.vector(import_bcs5.bcs.string()),
|
|
331
|
+
...PaginationStruct
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
// src/types/pool.ts
|
|
335
|
+
var import_bcs7 = require("@mysten/bcs");
|
|
336
|
+
var GetPoolInfoResponseStruct = [
|
|
337
|
+
import_bcs7.bcs.u64(),
|
|
338
|
+
import_bcs7.bcs.u128(),
|
|
339
|
+
BcsAddressType,
|
|
340
|
+
import_bcs7.bcs.bool()
|
|
341
|
+
];
|
|
342
|
+
var GetFeesResponseStruct = [import_bcs7.bcs.u64(), import_bcs7.bcs.u64(), import_bcs7.bcs.u64()];
|
|
343
|
+
|
|
344
|
+
// src/lib/oracle/get-asset-pairs.ts
|
|
345
|
+
var getAssetPairs = async (client) => {
|
|
346
|
+
const ASSET_PAIRS_PAGINATED_FUNCTION = "asset_pairs_paginated";
|
|
347
|
+
const result = [];
|
|
348
|
+
let currentCursor = null;
|
|
349
|
+
let hasNextPage = true;
|
|
350
|
+
while (hasNextPage) {
|
|
351
|
+
const response = await queryDevInspect(
|
|
352
|
+
client.suiClient,
|
|
353
|
+
[client.packageId, PRICE_ORACLE_MODULE, ASSET_PAIRS_PAGINATED_FUNCTION],
|
|
354
|
+
[
|
|
355
|
+
client.contracts.oracle,
|
|
356
|
+
import_bcs9.bcs.option(import_bcs9.bcs.u64()).serialize(DEFAULT_PAGINATION_LIMIT),
|
|
357
|
+
import_bcs9.bcs.option(import_bcs9.bcs.string()).serialize(currentCursor)
|
|
358
|
+
]
|
|
359
|
+
);
|
|
360
|
+
const output = parseDevInspectResult(response, AssetPairsResponsePaginatedStruct);
|
|
361
|
+
const assetPairs = parseAssetPairsResponsePaginatedStructOutput(output);
|
|
362
|
+
result.push(...assetPairs);
|
|
363
|
+
currentCursor = output.next_cursor;
|
|
364
|
+
hasNextPage = output.has_next_page;
|
|
365
|
+
}
|
|
366
|
+
return result;
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
// src/lib/oracle/get-assets.ts
|
|
370
|
+
var getAssets = async (client) => {
|
|
371
|
+
const assetPairs = await client.getAllOracleAssetPairs();
|
|
372
|
+
const uniqueOracleAssets = {};
|
|
373
|
+
for (const item of assetPairs) {
|
|
374
|
+
uniqueOracleAssets[item.base.symbol] = item.base;
|
|
375
|
+
uniqueOracleAssets[item.quote.symbol] = item.quote;
|
|
376
|
+
}
|
|
377
|
+
return Object.values(uniqueOracleAssets).map(
|
|
378
|
+
(item) => client.assetsConfig[item.symbol] ?? // Fallback to minimal asset data from oracle
|
|
379
|
+
{
|
|
380
|
+
symbol: item.name,
|
|
381
|
+
name: item.name,
|
|
382
|
+
chainId: client.chainConfig.id,
|
|
383
|
+
denom: item.symbol,
|
|
384
|
+
decimals: item.precision,
|
|
385
|
+
logo: void 0,
|
|
386
|
+
coingeckoId: void 0
|
|
387
|
+
}
|
|
388
|
+
);
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
// src/lib/oracle/get-oracle-config.ts
|
|
392
|
+
var getOracleConfig = async (client) => {
|
|
393
|
+
const CONFIG_FUNCTION = "config";
|
|
394
|
+
const response = await queryDevInspect(
|
|
395
|
+
client.suiClient,
|
|
396
|
+
[client.packageId, PRICE_ORACLE_MODULE, CONFIG_FUNCTION],
|
|
397
|
+
[client.contracts.oracle]
|
|
398
|
+
);
|
|
399
|
+
const output = parseDevInspectResult(response, OracleConfigStruct);
|
|
400
|
+
return parseOracleConfigStructOutput(output);
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
// src/lib/oracle/get-price.ts
|
|
404
|
+
var import_bcs10 = require("@mysten/bcs");
|
|
405
|
+
var import_utils = require("@mysten/sui/utils");
|
|
406
|
+
var getPrice = async (client, baseDenom, quoteDenom) => {
|
|
407
|
+
const GET_PRICE_FUNCTION = "get_price";
|
|
408
|
+
const response = await queryDevInspect(
|
|
409
|
+
client.suiClient,
|
|
410
|
+
[client.packageId, PRICE_ORACLE_MODULE, GET_PRICE_FUNCTION],
|
|
411
|
+
[
|
|
412
|
+
client.contracts.oracle,
|
|
413
|
+
import_bcs10.bcs.string().serialize(baseDenom),
|
|
414
|
+
import_bcs10.bcs.string().serialize(quoteDenom),
|
|
415
|
+
import_utils.SUI_CLOCK_OBJECT_ID
|
|
416
|
+
]
|
|
417
|
+
);
|
|
418
|
+
const output = parseDevInspectResult(response, PriceResponseStruct);
|
|
419
|
+
return parsePriceResponseStructOutput(output, baseDenom, quoteDenom);
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
// src/lib/oracle/get-prices.ts
|
|
423
|
+
var import_bcs11 = require("@mysten/bcs");
|
|
424
|
+
var getPrices = async (client) => {
|
|
425
|
+
const GET_PRICES_PAGINATED_FUNCTION = "get_prices_paginated";
|
|
426
|
+
const result = [];
|
|
427
|
+
let currentCursor = null;
|
|
428
|
+
let hasNextPage = true;
|
|
429
|
+
while (hasNextPage) {
|
|
430
|
+
const response = await queryDevInspect(
|
|
431
|
+
client.suiClient,
|
|
432
|
+
[client.packageId, PRICE_ORACLE_MODULE, GET_PRICES_PAGINATED_FUNCTION],
|
|
433
|
+
[
|
|
434
|
+
client.contracts.oracle,
|
|
435
|
+
import_bcs11.bcs.option(import_bcs11.bcs.u64()).serialize(DEFAULT_PAGINATION_LIMIT),
|
|
436
|
+
import_bcs11.bcs.option(import_bcs11.bcs.string()).serialize(currentCursor)
|
|
437
|
+
]
|
|
438
|
+
);
|
|
439
|
+
const output = parseDevInspectResult(response, PricesResponsePaginatedStruct);
|
|
440
|
+
const assetPairs = parsePricesResponsePaginatedStructOutput(output);
|
|
441
|
+
result.push(...assetPairs);
|
|
442
|
+
currentCursor = output.next_cursor;
|
|
443
|
+
hasNextPage = output.has_next_page;
|
|
444
|
+
}
|
|
445
|
+
return result;
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
// src/lib/router/get-all-base-liquidity.ts
|
|
449
|
+
var import_bcs12 = require("@mysten/bcs");
|
|
450
|
+
|
|
451
|
+
// src/lib/router/parsers.ts
|
|
452
|
+
var import_core4 = require("@bolt-liquidity-hq/core");
|
|
453
|
+
var parseMarketStructOutput = (output) => {
|
|
454
|
+
return {
|
|
455
|
+
poolAddress: output.market_address,
|
|
456
|
+
baseDenom: output.base_asset_symbol,
|
|
457
|
+
quoteDenoms: output.quote_assets_symbols
|
|
458
|
+
};
|
|
459
|
+
};
|
|
460
|
+
var parseMarketResponseStructOutput = (response) => {
|
|
461
|
+
if (!response.market) {
|
|
462
|
+
throw new import_core4.NotFoundError("Market", void 0, { response });
|
|
463
|
+
}
|
|
464
|
+
return parseMarketStructOutput(response.market);
|
|
465
|
+
};
|
|
466
|
+
var parseMarketsResponsePaginatedStructOutput = (response) => {
|
|
467
|
+
return response.markets.map((item) => parseMarketStructOutput(item));
|
|
468
|
+
};
|
|
469
|
+
var parseRouterConfigStructOutput = (output) => {
|
|
470
|
+
return {
|
|
471
|
+
admin: output.admin,
|
|
472
|
+
defaultPriceOracleContract: output.default_price_oracle_contract,
|
|
473
|
+
defaultProtocolFeeRecipient: output.default_protocol_fee_recipient,
|
|
474
|
+
defaultProtocolFee: output.default_protocol_fee,
|
|
475
|
+
defaultLpFee: output.default_lp_fee
|
|
476
|
+
};
|
|
477
|
+
};
|
|
478
|
+
var parseBaseLiquidityResponseStructOutput = (output) => {
|
|
479
|
+
return output.base_assets.map((item) => ({
|
|
480
|
+
baseLiquidity: {
|
|
481
|
+
denom: item,
|
|
482
|
+
amount: "10"
|
|
483
|
+
},
|
|
484
|
+
totalShares: "10"
|
|
485
|
+
}));
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
// src/lib/router/get-all-base-liquidity.ts
|
|
489
|
+
var getAllBaseLiquidity = async (client) => {
|
|
490
|
+
const BASE_LIQUIDITY_ALL_PAGINATED_FUNCTION = "base_liquidity_all_paginated";
|
|
491
|
+
const result = {};
|
|
492
|
+
let currentCursor = null;
|
|
493
|
+
let hasNextPage = true;
|
|
494
|
+
while (hasNextPage) {
|
|
495
|
+
const response = await queryDevInspect(
|
|
496
|
+
client.suiClient,
|
|
497
|
+
[client.packageId, ROUTER_MODULE, BASE_LIQUIDITY_ALL_PAGINATED_FUNCTION],
|
|
498
|
+
[
|
|
499
|
+
client.contracts.router,
|
|
500
|
+
import_bcs12.bcs.option(import_bcs12.bcs.u64()).serialize(DEFAULT_PAGINATION_LIMIT),
|
|
501
|
+
import_bcs12.bcs.option(import_bcs12.bcs.string()).serialize(currentCursor)
|
|
502
|
+
]
|
|
503
|
+
);
|
|
504
|
+
const output = parseDevInspectResult(response, BaseLiquidityResponseStruct);
|
|
505
|
+
const baseLiquidities = parseBaseLiquidityResponseStructOutput(output);
|
|
506
|
+
for (const item of baseLiquidities) {
|
|
507
|
+
result[item.baseLiquidity.denom] = item;
|
|
508
|
+
}
|
|
509
|
+
currentCursor = output.next_cursor;
|
|
510
|
+
hasNextPage = output.has_next_page;
|
|
511
|
+
}
|
|
512
|
+
return result;
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
// src/lib/router/get-all-quotes-for-user.ts
|
|
516
|
+
var import_bcs13 = require("@mysten/bcs");
|
|
517
|
+
var getAllQuotesForUser = async (client, lpAddress) => {
|
|
518
|
+
const QUOTES_FOR_USER_ALL_FUNCTION = "quotes_for_user_all";
|
|
519
|
+
const response = await queryDevInspect(
|
|
520
|
+
client.suiClient,
|
|
521
|
+
[client.packageId, ROUTER_MODULE, QUOTES_FOR_USER_ALL_FUNCTION],
|
|
522
|
+
[client.contracts.router, import_bcs13.bcs.string().serialize(lpAddress)]
|
|
523
|
+
);
|
|
524
|
+
console.log(response);
|
|
525
|
+
return {};
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
// src/lib/router/get-pool-for-base.ts
|
|
529
|
+
var import_bcs14 = require("@mysten/bcs");
|
|
530
|
+
var getPoolForBase = async (client, baseDenom) => {
|
|
531
|
+
const MARKET_FOR_BASE_FUNCTION = "market_for_base";
|
|
532
|
+
const response = await queryDevInspect(
|
|
533
|
+
client.suiClient,
|
|
534
|
+
[client.packageId, ROUTER_MODULE, MARKET_FOR_BASE_FUNCTION],
|
|
535
|
+
[client.contracts.router, import_bcs14.bcs.string().serialize(baseDenom)]
|
|
536
|
+
);
|
|
537
|
+
const output = parseDevInspectResult(response, MarketResponseStruct);
|
|
538
|
+
return parseMarketResponseStructOutput(output);
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
// src/lib/router/get-pools.ts
|
|
542
|
+
var import_bcs15 = require("@mysten/bcs");
|
|
543
|
+
var getPools = async (client) => {
|
|
544
|
+
const MARKETS_PAGINATED_FUNCTION = "markets_paginated";
|
|
545
|
+
const result = [];
|
|
546
|
+
let currentCursor = null;
|
|
547
|
+
let hasNextPage = true;
|
|
548
|
+
while (hasNextPage) {
|
|
549
|
+
const response = await queryDevInspect(
|
|
550
|
+
client.suiClient,
|
|
551
|
+
[client.packageId, ROUTER_MODULE, MARKETS_PAGINATED_FUNCTION],
|
|
552
|
+
[
|
|
553
|
+
client.contracts.router,
|
|
554
|
+
import_bcs15.bcs.option(import_bcs15.bcs.u64()).serialize(DEFAULT_PAGINATION_LIMIT),
|
|
555
|
+
import_bcs15.bcs.option(import_bcs15.bcs.string()).serialize(currentCursor)
|
|
556
|
+
]
|
|
557
|
+
);
|
|
558
|
+
const output = parseDevInspectResult(response, MarketsResponsePaginatedStruct);
|
|
559
|
+
const pools = parseMarketsResponsePaginatedStructOutput(output);
|
|
560
|
+
result.push(...pools);
|
|
561
|
+
currentCursor = output.next_cursor;
|
|
562
|
+
hasNextPage = output.has_next_page;
|
|
563
|
+
}
|
|
564
|
+
return result;
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
// src/lib/router/get-router-config.ts
|
|
568
|
+
var getRouterConfig = async (client) => {
|
|
569
|
+
const CONFIG_FUNCTION = "config";
|
|
570
|
+
const response = await queryDevInspect(
|
|
571
|
+
client.suiClient,
|
|
572
|
+
[client.packageId, ROUTER_MODULE, CONFIG_FUNCTION],
|
|
573
|
+
[client.contracts.router]
|
|
574
|
+
);
|
|
575
|
+
const output = parseDevInspectResult(response, RouterConfigStruct);
|
|
576
|
+
return parseRouterConfigStructOutput(output);
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
// src/lib/router/swap-exact-in.ts
|
|
580
|
+
var swapExactIn = async (client, signer, { assetIn, amountIn, assetOut, minimumAmountOut, receiver }) => {
|
|
581
|
+
console.log(client, signer, assetIn, amountIn, assetOut, minimumAmountOut, receiver);
|
|
582
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
583
|
+
return {};
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
// src/lib/settlement/get-pool-info.ts
|
|
587
|
+
var import_utils2 = require("@mysten/sui/utils");
|
|
588
|
+
|
|
589
|
+
// src/lib/settlement/parsers.ts
|
|
590
|
+
var parseSettlementConfigStructOutput = (_poolInfoOutput, feesOutput) => {
|
|
591
|
+
return {
|
|
592
|
+
priceOracleContract: "0x",
|
|
593
|
+
// Should come from poolInfoOutput
|
|
594
|
+
protocolFeeRecipient: "0x",
|
|
595
|
+
// Should be feesOutput[1]
|
|
596
|
+
protocolFee: feesOutput[0],
|
|
597
|
+
// Protocol fee percentage
|
|
598
|
+
lpFee: feesOutput[2],
|
|
599
|
+
// LP fee percentage
|
|
600
|
+
allowanceMode: "allow",
|
|
601
|
+
// Should come from poolInfoOutput
|
|
602
|
+
lps: ["0x"],
|
|
603
|
+
// Should come from poolInfoOutput
|
|
604
|
+
minBaseOut: "1"
|
|
605
|
+
// Should come from poolInfoOutput
|
|
606
|
+
};
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
// src/lib/settlement/get-pool-info.ts
|
|
610
|
+
var getPoolInfo = async (client, contractAddress) => {
|
|
611
|
+
const GET_POOL_INFO = "get_pool_info";
|
|
612
|
+
const GET_FEES_FUNCTION = "get_fees";
|
|
613
|
+
const [info, fees] = await Promise.all([
|
|
614
|
+
// Query pool information (LP configuration, allowance mode)
|
|
615
|
+
queryDevInspect(
|
|
616
|
+
client.suiClient,
|
|
617
|
+
[client.packageId, POOL_MODULE, GET_POOL_INFO],
|
|
618
|
+
[contractAddress],
|
|
619
|
+
// TODO: get the base token of the pool to pass it here instead of hardcoded SUI token
|
|
620
|
+
[import_utils2.SUI_TYPE_ARG]
|
|
621
|
+
),
|
|
622
|
+
// Query fee structure (protocol fee, LP fee, recipients)
|
|
623
|
+
queryDevInspect(
|
|
624
|
+
client.suiClient,
|
|
625
|
+
[client.packageId, POOL_MODULE, GET_FEES_FUNCTION],
|
|
626
|
+
[contractAddress],
|
|
627
|
+
// TODO: get the base token of the pool to pass it here instead of hardcoded SUI token
|
|
628
|
+
[import_utils2.SUI_TYPE_ARG]
|
|
629
|
+
)
|
|
630
|
+
]);
|
|
631
|
+
const infoOutput = parseMultipleResults(info, GetPoolInfoResponseStruct);
|
|
632
|
+
const feesOutput = parseMultipleResults(fees, GetFeesResponseStruct);
|
|
633
|
+
return parseSettlementConfigStructOutput(infoOutput, feesOutput);
|
|
634
|
+
};
|
|
635
|
+
|
|
636
|
+
// src/tests/constants/sui-objects.ts
|
|
637
|
+
var TEST_POOL = "0xdd05c1caea7b6725da3f67e30e99872033fc5d3a610a4f72ac1c434bc81c3c0d";
|
|
638
|
+
|
|
639
|
+
// src/lib/settlement/get-pool-info-for-base.ts
|
|
640
|
+
var getPoolInfoForBase = async (client, baseDenom) => {
|
|
641
|
+
const pool = await getPoolForBase(client, baseDenom && "SUI");
|
|
642
|
+
return await getPoolInfo(client, pool.poolAddress || TEST_POOL);
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
// src/lib/client.ts
|
|
646
|
+
var BoltSuiClient = class extends import_core5.BaseClient {
|
|
647
|
+
/**
|
|
648
|
+
* Creates a new instance of the BoltSuiClient.
|
|
649
|
+
*
|
|
650
|
+
* The client automatically configures itself based on the specified chain and environment,
|
|
651
|
+
* loading the appropriate contract addresses, chain configuration, and assets from configuration files.
|
|
652
|
+
*
|
|
653
|
+
* @param config - (Optional) Configuration for the client
|
|
654
|
+
* @param config.environment - (Optional) The deployment environment ('mainnet' or 'testnet'). Defaults to 'mainnet'
|
|
655
|
+
* @param config.customOverride - (Optional) Custom overrides for chain configuration, contracts, and assets
|
|
656
|
+
* @param config.customOverride.chainConfig - (Optional) Override chain configuration
|
|
657
|
+
* @param config.customOverride.chainConfig.id - (Optional) Custom chain ID
|
|
658
|
+
* @param config.customOverride.chainConfig.name - (Optional) Custom chain name
|
|
659
|
+
* @param config.customOverride.chainConfig.rpcEndpoint - (Optional) Custom RPC endpoint URL
|
|
660
|
+
* @param config.customOverride.packageId - (Optional) Custom package ID for Bolt contracts
|
|
661
|
+
* @param config.customOverride.contracts - (Optional) Override contract addresses
|
|
662
|
+
* @param config.customOverride.contracts.oracle - (Optional) Custom oracle contract address
|
|
663
|
+
* @param config.customOverride.contracts.router - (Optional) Custom router contract address
|
|
664
|
+
* @param config.customOverride.assetsConfig - (Optional) Custom asset configurations indexed by denom
|
|
665
|
+
* @param config.suiClient - (Optional) Pre-existing SuiClient to use for blockchain queries
|
|
666
|
+
*
|
|
667
|
+
* @throws {InvalidObjectError} Thrown when required configuration fields are missing
|
|
668
|
+
*
|
|
669
|
+
* @example
|
|
670
|
+
* ```typescript
|
|
671
|
+
* // Use default configuration (Sui mainnet)
|
|
672
|
+
* const client = new BoltSuiClient();
|
|
673
|
+
*
|
|
674
|
+
* // Use testnet configuration
|
|
675
|
+
* const testnetClient = new BoltSuiClient({
|
|
676
|
+
* environment: 'testnet'
|
|
677
|
+
* });
|
|
678
|
+
*
|
|
679
|
+
* // Use custom chain configuration
|
|
680
|
+
* const customClient = new BoltSuiClient({
|
|
681
|
+
* customOverride: {
|
|
682
|
+
* chainConfig: {
|
|
683
|
+
* id: 'sui-custom',
|
|
684
|
+
* name: 'Sui Custom',
|
|
685
|
+
* rpcEndpoint: 'https://custom-rpc.example.com'
|
|
686
|
+
* },
|
|
687
|
+
* packageId: '0xcustom_package_id...',
|
|
688
|
+
* contracts: {
|
|
689
|
+
* oracle: '0xcustom_oracle...',
|
|
690
|
+
* router: '0xcustom_router...'
|
|
691
|
+
* },
|
|
692
|
+
* assetsConfig: {
|
|
693
|
+
* '0x2::sui::SUI': {
|
|
694
|
+
* symbol: 'SUI',
|
|
695
|
+
* name: 'Sui',
|
|
696
|
+
* chainId: 'sui-custom',
|
|
697
|
+
* denom: '0x2::sui::SUI',
|
|
698
|
+
* decimals: 9,
|
|
699
|
+
* logo: 'https://example.com/sui.png',
|
|
700
|
+
* coingeckoId: 'sui'
|
|
701
|
+
* }
|
|
702
|
+
* }
|
|
703
|
+
* }
|
|
704
|
+
* });
|
|
705
|
+
*
|
|
706
|
+
* // Use pre-existing Sui client
|
|
707
|
+
* const clientWithCustomClient = new BoltSuiClient({
|
|
708
|
+
* suiClient: mySuiClient
|
|
709
|
+
* });
|
|
710
|
+
* ```
|
|
711
|
+
*/
|
|
712
|
+
constructor(config) {
|
|
713
|
+
const { environment = "mainnet", customOverride, suiClient } = config ?? {};
|
|
714
|
+
const defaultChainConfig = environment === "mainnet" ? MainnetChainConfig : TestnetChainConfig;
|
|
715
|
+
const defaultContracts = environment === "mainnet" ? MainnetContracts : TestnetContracts;
|
|
716
|
+
const defaultPackageId = environment === "mainnet" ? MainnetPackageId : TestnetPackageId;
|
|
717
|
+
const assetsConfig = environment === "mainnet" ? MainnetAssets : TestnetAssets;
|
|
718
|
+
const chainConfig = {
|
|
719
|
+
id: customOverride?.chainConfig?.id ?? defaultChainConfig.id,
|
|
720
|
+
name: customOverride?.chainConfig?.name ?? defaultChainConfig.name,
|
|
721
|
+
rpcEndpoint: customOverride?.chainConfig?.rpcEndpoint ?? defaultChainConfig.rpcEndpoint
|
|
722
|
+
};
|
|
723
|
+
const packageId = customOverride?.packageId ?? defaultPackageId;
|
|
724
|
+
const contracts = {
|
|
725
|
+
oracle: customOverride?.contracts?.oracle ?? defaultContracts.oracle,
|
|
726
|
+
router: customOverride?.contracts?.router ?? defaultContracts.router
|
|
727
|
+
};
|
|
728
|
+
for (const item of Object.values(customOverride?.assetsConfig ?? {})) {
|
|
729
|
+
assetsConfig[item.denom] = item;
|
|
730
|
+
}
|
|
731
|
+
super({
|
|
732
|
+
customOverride: {
|
|
733
|
+
chainConfig,
|
|
734
|
+
contracts,
|
|
735
|
+
assetsConfig
|
|
736
|
+
}
|
|
737
|
+
});
|
|
738
|
+
/**
|
|
739
|
+
* The Sui-specific chain configuration including RPC endpoint
|
|
740
|
+
*/
|
|
741
|
+
__publicField(this, "chainConfig");
|
|
742
|
+
/**
|
|
743
|
+
* Package Id for the deployed Bolt contracts on Sui
|
|
744
|
+
*/
|
|
745
|
+
__publicField(this, "packageId");
|
|
746
|
+
/**
|
|
747
|
+
* Instance of the Sui client to interact with the blockchain
|
|
748
|
+
*/
|
|
749
|
+
__publicField(this, "suiClient");
|
|
750
|
+
this.chainConfig = chainConfig;
|
|
751
|
+
this.packageId = packageId;
|
|
752
|
+
this.suiClient = suiClient ?? new import_client.SuiClient({ url: chainConfig.rpcEndpoint });
|
|
753
|
+
}
|
|
754
|
+
// The following methods inherit their documentation from BaseClient
|
|
755
|
+
// Only add documentation here if you need to override or add implementation-specific details
|
|
756
|
+
/** @inheritdoc */
|
|
757
|
+
async getOracleConfig() {
|
|
758
|
+
return await getOracleConfig(this);
|
|
759
|
+
}
|
|
760
|
+
/** @inheritdoc */
|
|
761
|
+
async getAllOracleAssetPairs() {
|
|
762
|
+
return await getAssetPairs(this);
|
|
763
|
+
}
|
|
764
|
+
/** @inheritdoc */
|
|
765
|
+
async getPrice(baseDenom, quoteDenom) {
|
|
766
|
+
return await getPrice(this, baseDenom, quoteDenom);
|
|
767
|
+
}
|
|
768
|
+
/** @inheritdoc */
|
|
769
|
+
async getAllPrices() {
|
|
770
|
+
return await getPrices(this);
|
|
771
|
+
}
|
|
772
|
+
/** @inheritdoc */
|
|
773
|
+
async getRouterConfig() {
|
|
774
|
+
return await getRouterConfig(this);
|
|
775
|
+
}
|
|
776
|
+
/** @inheritdoc */
|
|
777
|
+
async getAllBaseAssetsLiquidity() {
|
|
778
|
+
return await getAllBaseLiquidity(this);
|
|
779
|
+
}
|
|
780
|
+
/** @inheritdoc */
|
|
781
|
+
async getAllQuotesByUser(address) {
|
|
782
|
+
return await getAllQuotesForUser(this, address);
|
|
783
|
+
}
|
|
784
|
+
/** @inheritdoc */
|
|
785
|
+
async getPoolByBaseAsset(baseDenom) {
|
|
786
|
+
return await getPoolForBase(this, baseDenom);
|
|
787
|
+
}
|
|
788
|
+
/** @inheritdoc */
|
|
789
|
+
async getAllPools() {
|
|
790
|
+
return await getPools(this);
|
|
791
|
+
}
|
|
792
|
+
// Satisfy the base class requirement
|
|
793
|
+
async getPoolConfig(poolContractAddress) {
|
|
794
|
+
return await getPoolInfo(this, poolContractAddress);
|
|
795
|
+
}
|
|
796
|
+
/** @inheritdoc */
|
|
797
|
+
async getAssets() {
|
|
798
|
+
return await getAssets(this);
|
|
799
|
+
}
|
|
800
|
+
/** @inheritdoc */
|
|
801
|
+
async getPoolConfigByBaseAsset(baseDenom) {
|
|
802
|
+
return await getPoolInfoForBase(this, baseDenom);
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* @inheritdoc
|
|
806
|
+
*
|
|
807
|
+
* @example
|
|
808
|
+
* ```typescript
|
|
809
|
+
* // Get signer from wallet (e.g., Sui Wallet, Suiet, etc.)
|
|
810
|
+
* const signer = // ... obtain signer from wallet
|
|
811
|
+
*
|
|
812
|
+
* // Execute swap: 1 SUI for USDC
|
|
813
|
+
* const result = await client.swap(signer, {
|
|
814
|
+
* assetIn: "0x2::sui::SUI",
|
|
815
|
+
* amountIn: "1000000000", // 1 SUI (9 decimals)
|
|
816
|
+
* assetOut: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN", // USDC address
|
|
817
|
+
* minimumAmountOut: "1950000", // Minimum 1.95 USDC expected (6 decimals)
|
|
818
|
+
* receiver: "0x..." // Optional custom receiver address
|
|
819
|
+
* });
|
|
820
|
+
*
|
|
821
|
+
* console.log(`Swap successful!`);
|
|
822
|
+
* console.log(`Transaction digest: ${result.txHash}`);
|
|
823
|
+
* console.log(`Received: ${result.amountOut} ${result.assetOut}`);
|
|
824
|
+
* console.log(`Gas cost: ${result.txOutput.effects.gasUsed.computationCost}`);
|
|
825
|
+
* console.log(`Status: ${result.txOutput.effects.status.status}`);
|
|
826
|
+
* ```
|
|
827
|
+
*
|
|
828
|
+
* @remarks
|
|
829
|
+
* This implementation returns a SuiTransactionBlockResponse as the transaction output,
|
|
830
|
+
* which includes details like gas costs, transaction effects, object changes, and events.
|
|
831
|
+
*/
|
|
832
|
+
async swap(signer, params) {
|
|
833
|
+
return await swapExactIn(this, signer, params);
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
//# sourceMappingURL=index.cjs.map
|