@t2000/sdk 0.20.0 → 0.20.2
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/index.cjs +66 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +78 -1
- package/dist/index.d.ts +78 -1
- package/dist/index.js +40 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -118,10 +118,10 @@ var volo_exports = {};
|
|
|
118
118
|
__export(volo_exports, {
|
|
119
119
|
MIN_STAKE_MIST: () => MIN_STAKE_MIST,
|
|
120
120
|
SUI_SYSTEM_STATE: () => SUI_SYSTEM_STATE,
|
|
121
|
-
VOLO_METADATA: () => VOLO_METADATA,
|
|
122
|
-
VOLO_PKG: () => VOLO_PKG,
|
|
123
|
-
VOLO_POOL: () => VOLO_POOL,
|
|
124
|
-
VSUI_TYPE: () => VSUI_TYPE,
|
|
121
|
+
VOLO_METADATA: () => exports.VOLO_METADATA,
|
|
122
|
+
VOLO_PKG: () => exports.VOLO_PKG,
|
|
123
|
+
VOLO_POOL: () => exports.VOLO_POOL,
|
|
124
|
+
VSUI_TYPE: () => exports.VSUI_TYPE,
|
|
125
125
|
buildStakeVSuiTx: () => buildStakeVSuiTx,
|
|
126
126
|
buildUnstakeVSuiTx: () => buildUnstakeVSuiTx,
|
|
127
127
|
getVoloStats: () => getVoloStats
|
|
@@ -149,10 +149,10 @@ async function buildStakeVSuiTx(_client, address, amountMist) {
|
|
|
149
149
|
tx.setSender(address);
|
|
150
150
|
const [suiCoin] = tx.splitCoins(tx.gas, [amountMist]);
|
|
151
151
|
const [vSuiCoin] = tx.moveCall({
|
|
152
|
-
target: `${VOLO_PKG}::stake_pool::stake`,
|
|
152
|
+
target: `${exports.VOLO_PKG}::stake_pool::stake`,
|
|
153
153
|
arguments: [
|
|
154
|
-
tx.object(VOLO_POOL),
|
|
155
|
-
tx.object(VOLO_METADATA),
|
|
154
|
+
tx.object(exports.VOLO_POOL),
|
|
155
|
+
tx.object(exports.VOLO_METADATA),
|
|
156
156
|
tx.object(SUI_SYSTEM_STATE),
|
|
157
157
|
suiCoin
|
|
158
158
|
]
|
|
@@ -178,10 +178,10 @@ async function buildUnstakeVSuiTx(client, address, amountMist) {
|
|
|
178
178
|
[vSuiCoin] = tx.splitCoins(primary, [amountMist]);
|
|
179
179
|
}
|
|
180
180
|
const [suiCoin] = tx.moveCall({
|
|
181
|
-
target: `${VOLO_PKG}::stake_pool::unstake`,
|
|
181
|
+
target: `${exports.VOLO_PKG}::stake_pool::unstake`,
|
|
182
182
|
arguments: [
|
|
183
|
-
tx.object(VOLO_POOL),
|
|
184
|
-
tx.object(VOLO_METADATA),
|
|
183
|
+
tx.object(exports.VOLO_POOL),
|
|
184
|
+
tx.object(exports.VOLO_METADATA),
|
|
185
185
|
tx.object(SUI_SYSTEM_STATE),
|
|
186
186
|
vSuiCoin
|
|
187
187
|
]
|
|
@@ -196,7 +196,7 @@ async function fetchVSuiCoins(client, address) {
|
|
|
196
196
|
while (hasNext) {
|
|
197
197
|
const page = await client.getCoins({
|
|
198
198
|
owner: address,
|
|
199
|
-
coinType: VSUI_TYPE,
|
|
199
|
+
coinType: exports.VSUI_TYPE,
|
|
200
200
|
cursor: cursor ?? void 0
|
|
201
201
|
});
|
|
202
202
|
all.push(...page.data.map((c) => ({ coinObjectId: c.coinObjectId, balance: c.balance })));
|
|
@@ -205,13 +205,13 @@ async function fetchVSuiCoins(client, address) {
|
|
|
205
205
|
}
|
|
206
206
|
return all;
|
|
207
207
|
}
|
|
208
|
-
|
|
208
|
+
exports.VOLO_PKG = void 0; exports.VOLO_POOL = void 0; exports.VOLO_METADATA = void 0; exports.VSUI_TYPE = void 0; var SUI_SYSTEM_STATE, MIN_STAKE_MIST, VOLO_STATS_URL;
|
|
209
209
|
var init_volo = __esm({
|
|
210
210
|
"src/protocols/volo.ts"() {
|
|
211
|
-
VOLO_PKG = "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20";
|
|
212
|
-
VOLO_POOL = "0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5";
|
|
213
|
-
VOLO_METADATA = "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60";
|
|
214
|
-
VSUI_TYPE = "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT";
|
|
211
|
+
exports.VOLO_PKG = "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20";
|
|
212
|
+
exports.VOLO_POOL = "0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5";
|
|
213
|
+
exports.VOLO_METADATA = "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60";
|
|
214
|
+
exports.VSUI_TYPE = "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT";
|
|
215
215
|
SUI_SYSTEM_STATE = "0x05";
|
|
216
216
|
MIN_STAKE_MIST = 1000000000n;
|
|
217
217
|
VOLO_STATS_URL = "https://open-api.naviprotocol.io/api/volo/stats";
|
|
@@ -221,7 +221,7 @@ var init_volo = __esm({
|
|
|
221
221
|
// src/protocols/cetus-swap.ts
|
|
222
222
|
var cetus_swap_exports = {};
|
|
223
223
|
__export(cetus_swap_exports, {
|
|
224
|
-
TOKEN_MAP: () => TOKEN_MAP,
|
|
224
|
+
TOKEN_MAP: () => exports.TOKEN_MAP,
|
|
225
225
|
buildSwapTx: () => buildSwapTx,
|
|
226
226
|
findSwapRoute: () => findSwapRoute,
|
|
227
227
|
resolveTokenType: () => resolveTokenType,
|
|
@@ -290,13 +290,13 @@ async function simulateSwap(params) {
|
|
|
290
290
|
}
|
|
291
291
|
function resolveTokenType(nameOrType) {
|
|
292
292
|
if (nameOrType.includes("::")) return nameOrType;
|
|
293
|
-
return TOKEN_MAP[nameOrType.toUpperCase()] ?? null;
|
|
293
|
+
return exports.TOKEN_MAP[nameOrType.toUpperCase()] ?? null;
|
|
294
294
|
}
|
|
295
|
-
var clientInstance
|
|
295
|
+
var clientInstance; exports.TOKEN_MAP = void 0;
|
|
296
296
|
var init_cetus_swap = __esm({
|
|
297
297
|
"src/protocols/cetus-swap.ts"() {
|
|
298
298
|
clientInstance = null;
|
|
299
|
-
TOKEN_MAP = {
|
|
299
|
+
exports.TOKEN_MAP = {
|
|
300
300
|
SUI: "0x2::sui::SUI",
|
|
301
301
|
USDC: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
|
|
302
302
|
USDT: "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT",
|
|
@@ -3169,6 +3169,45 @@ function parseMoveAbort(errorStr) {
|
|
|
3169
3169
|
return { reason: errorStr };
|
|
3170
3170
|
}
|
|
3171
3171
|
|
|
3172
|
+
// src/swap-quote.ts
|
|
3173
|
+
async function getSwapQuote(params) {
|
|
3174
|
+
const { findSwapRoute: findSwapRoute2, resolveTokenType: resolveTokenType2, TOKEN_MAP: TOKEN_MAP2 } = await Promise.resolve().then(() => (init_cetus_swap(), cetus_swap_exports));
|
|
3175
|
+
const fromType = resolveTokenType2(params.from);
|
|
3176
|
+
const toType = resolveTokenType2(params.to);
|
|
3177
|
+
if (!fromType) throw new Error(`Unknown token: ${params.from}. Provide the full coin type.`);
|
|
3178
|
+
if (!toType) throw new Error(`Unknown token: ${params.to}. Provide the full coin type.`);
|
|
3179
|
+
const byAmountIn = params.byAmountIn ?? true;
|
|
3180
|
+
const fromEntry = Object.values(TOKEN_MAP2).includes(fromType) ? Object.entries(SUPPORTED_ASSETS).find(([, v]) => v.type === fromType) : null;
|
|
3181
|
+
const fromDecimals = fromEntry ? fromEntry[1].decimals : fromType === "0x2::sui::SUI" ? 9 : 6;
|
|
3182
|
+
const rawAmount = BigInt(Math.floor(params.amount * 10 ** fromDecimals));
|
|
3183
|
+
const route = await findSwapRoute2({
|
|
3184
|
+
walletAddress: params.walletAddress,
|
|
3185
|
+
from: fromType,
|
|
3186
|
+
to: toType,
|
|
3187
|
+
amount: rawAmount,
|
|
3188
|
+
byAmountIn
|
|
3189
|
+
});
|
|
3190
|
+
if (!route) throw new Error(`No swap route found for ${params.from} -> ${params.to}.`);
|
|
3191
|
+
if (route.insufficientLiquidity) throw new Error(`Insufficient liquidity for ${params.from} -> ${params.to}.`);
|
|
3192
|
+
const toEntry = Object.entries(SUPPORTED_ASSETS).find(([, v]) => v.type === toType);
|
|
3193
|
+
const toDecimals = toEntry ? toEntry[1].decimals : toType === "0x2::sui::SUI" ? 9 : 6;
|
|
3194
|
+
const fromAmount = Number(route.amountIn) / 10 ** fromDecimals;
|
|
3195
|
+
const toAmount = Number(route.amountOut) / 10 ** toDecimals;
|
|
3196
|
+
const routeDesc = route.routerData.paths?.map((p) => p.provider).filter(Boolean).slice(0, 3).join(" + ") ?? "Cetus Aggregator";
|
|
3197
|
+
return {
|
|
3198
|
+
fromToken: params.from,
|
|
3199
|
+
toToken: params.to,
|
|
3200
|
+
fromAmount,
|
|
3201
|
+
toAmount,
|
|
3202
|
+
priceImpact: route.priceImpact,
|
|
3203
|
+
route: routeDesc
|
|
3204
|
+
};
|
|
3205
|
+
}
|
|
3206
|
+
|
|
3207
|
+
// src/index.ts
|
|
3208
|
+
init_cetus_swap();
|
|
3209
|
+
init_volo();
|
|
3210
|
+
|
|
3172
3211
|
exports.BPS_DENOMINATOR = BPS_DENOMINATOR;
|
|
3173
3212
|
exports.CETUS_USDC_SUI_POOL = CETUS_USDC_SUI_POOL;
|
|
3174
3213
|
exports.CLOCK_ID = CLOCK_ID;
|
|
@@ -3191,10 +3230,14 @@ exports.USDC_DECIMALS = USDC_DECIMALS;
|
|
|
3191
3230
|
exports.ZkLoginSigner = ZkLoginSigner;
|
|
3192
3231
|
exports.addCollectFeeToTx = addCollectFeeToTx;
|
|
3193
3232
|
exports.allDescriptors = allDescriptors;
|
|
3233
|
+
exports.buildStakeVSuiTx = buildStakeVSuiTx;
|
|
3234
|
+
exports.buildSwapTx = buildSwapTx;
|
|
3235
|
+
exports.buildUnstakeVSuiTx = buildUnstakeVSuiTx;
|
|
3194
3236
|
exports.calculateFee = calculateFee;
|
|
3195
3237
|
exports.executeAutoTopUp = executeAutoTopUp;
|
|
3196
3238
|
exports.executeWithGas = executeWithGas;
|
|
3197
3239
|
exports.exportPrivateKey = exportPrivateKey;
|
|
3240
|
+
exports.findSwapRoute = findSwapRoute;
|
|
3198
3241
|
exports.formatAssetAmount = formatAssetAmount;
|
|
3199
3242
|
exports.formatSui = formatSui;
|
|
3200
3243
|
exports.formatUsd = formatUsd;
|
|
@@ -3203,6 +3246,8 @@ exports.getAddress = getAddress;
|
|
|
3203
3246
|
exports.getDecimals = getDecimals;
|
|
3204
3247
|
exports.getGasStatus = getGasStatus;
|
|
3205
3248
|
exports.getRates = getRates;
|
|
3249
|
+
exports.getSwapQuote = getSwapQuote;
|
|
3250
|
+
exports.getVoloStats = getVoloStats;
|
|
3206
3251
|
exports.keypairFromPrivateKey = keypairFromPrivateKey;
|
|
3207
3252
|
exports.loadKey = loadKey;
|
|
3208
3253
|
exports.mapMoveAbortCode = mapMoveAbortCode;
|
|
@@ -3211,6 +3256,7 @@ exports.mistToSui = mistToSui;
|
|
|
3211
3256
|
exports.naviDescriptor = naviDescriptor;
|
|
3212
3257
|
exports.rawToStable = rawToStable;
|
|
3213
3258
|
exports.rawToUsdc = rawToUsdc;
|
|
3259
|
+
exports.resolveTokenType = resolveTokenType;
|
|
3214
3260
|
exports.saveKey = saveKey;
|
|
3215
3261
|
exports.shouldAutoTopUp = shouldAutoTopUp;
|
|
3216
3262
|
exports.simulateTransaction = simulateTransaction;
|