@t2000/sdk 0.6.0 → 0.7.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/README.md +6 -6
- package/dist/adapters/index.cjs +127 -27
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +2 -1
- package/dist/adapters/index.d.ts +2 -1
- package/dist/adapters/index.js +123 -28
- package/dist/adapters/index.js.map +1 -1
- package/dist/{index-DMDq8uxe.d.cts → index-rT0oHn8M.d.cts} +52 -1
- package/dist/{index-DMDq8uxe.d.ts → index-rT0oHn8M.d.ts} +52 -1
- package/dist/index.cjs +107 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -16
- package/dist/index.d.ts +3 -16
- package/dist/index.js +103 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { EventEmitter } from 'eventemitter3';
|
|
2
2
|
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
3
3
|
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
4
|
-
import { T as T2000Options, S as SendResult, B as BalanceResponse, a as TransactionRecord, D as DepositInfo, L as LendingAdapter, b as SwapAdapter, c as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, d as BorrowResult, R as RepayResult, e as MaxBorrowResult, H as HealthFactorResult, f as SwapResult, P as PositionsResult, g as RatesResult, h as LendingRates, E as EarningsResult, F as FundStatusResult, i as SentinelAgent, j as SentinelAttackResult,
|
|
5
|
-
export { A as AdapterCapability,
|
|
4
|
+
import { T as T2000Options, S as SendResult, B as BalanceResponse, a as TransactionRecord, D as DepositInfo, L as LendingAdapter, b as SwapAdapter, c as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, d as BorrowResult, R as RepayResult, e as MaxBorrowResult, H as HealthFactorResult, f as SwapResult, P as PositionsResult, g as RatesResult, h as LendingRates, E as EarningsResult, F as FundStatusResult, i as SentinelAgent, j as SentinelAttackResult, G as GasMethod } from './index-rT0oHn8M.cjs';
|
|
5
|
+
export { A as AdapterCapability, k as AdapterPositions, l as AdapterTxResult, C as CetusAdapter, m as GasReserve, n as HealthInfo, N as NaviAdapter, o as PositionEntry, p as ProtocolDescriptor, q as ProtocolRegistry, r as SentinelVerdict, s as SuilendAdapter, t as SwapQuote, u as allDescriptors, v as cetusDescriptor, w as getSentinelInfo, x as listSentinels, y as naviDescriptor, z as requestAttack, I as sentinelAttack, J as sentinelDescriptor, K as settleAttack, O as submitPrompt, Q as suilendDescriptor } from './index-rT0oHn8M.cjs';
|
|
6
6
|
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
7
7
|
|
|
8
8
|
type T2000ErrorCode = 'INSUFFICIENT_BALANCE' | 'INSUFFICIENT_GAS' | 'INVALID_ADDRESS' | 'INVALID_AMOUNT' | 'WALLET_NOT_FOUND' | 'WALLET_LOCKED' | 'WALLET_EXISTS' | 'SPONSOR_FAILED' | 'SPONSOR_RATE_LIMITED' | 'GAS_STATION_UNAVAILABLE' | 'GAS_FEE_EXCEEDED' | 'SIMULATION_FAILED' | 'TRANSACTION_FAILED' | 'ASSET_NOT_SUPPORTED' | 'SLIPPAGE_EXCEEDED' | 'HEALTH_FACTOR_TOO_LOW' | 'WITHDRAW_WOULD_LIQUIDATE' | 'NO_COLLATERAL' | 'PROTOCOL_PAUSED' | 'PROTOCOL_UNAVAILABLE' | 'RPC_ERROR' | 'RPC_UNREACHABLE' | 'SPONSOR_UNAVAILABLE' | 'AUTO_TOPUP_FAILED' | 'PRICE_EXCEEDS_LIMIT' | 'UNSUPPORTED_NETWORK' | 'PAYMENT_EXPIRED' | 'DUPLICATE_PAYMENT' | 'FACILITATOR_REJECTION' | 'FACILITATOR_TIMEOUT' | 'SENTINEL_API_ERROR' | 'SENTINEL_NOT_FOUND' | 'SENTINEL_TX_FAILED' | 'SENTINEL_TEE_ERROR' | 'UNKNOWN';
|
|
@@ -247,19 +247,6 @@ declare function getSwapQuote(client: SuiJsonRpcClient, fromAsset: 'USDC' | 'SUI
|
|
|
247
247
|
|
|
248
248
|
declare function getRates(client: SuiJsonRpcClient): Promise<RatesResult>;
|
|
249
249
|
|
|
250
|
-
declare function listSentinels(): Promise<SentinelAgent[]>;
|
|
251
|
-
declare function getSentinelInfo(client: SuiJsonRpcClient, sentinelObjectId: string): Promise<SentinelAgent>;
|
|
252
|
-
declare function requestAttack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelObjectId: string, feeMist: bigint): Promise<{
|
|
253
|
-
attackObjectId: string;
|
|
254
|
-
digest: string;
|
|
255
|
-
}>;
|
|
256
|
-
declare function submitPrompt(agentId: string, attackObjectId: string, prompt: string): Promise<SentinelVerdict>;
|
|
257
|
-
declare function settleAttack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelObjectId: string, attackObjectId: string, prompt: string, verdict: SentinelVerdict): Promise<{
|
|
258
|
-
digest: string;
|
|
259
|
-
success: boolean;
|
|
260
|
-
}>;
|
|
261
|
-
declare function attack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelId: string, prompt: string, feeMist?: bigint): Promise<SentinelAttackResult>;
|
|
262
|
-
|
|
263
250
|
interface GasExecutionResult {
|
|
264
251
|
digest: string;
|
|
265
252
|
effects: unknown;
|
|
@@ -299,4 +286,4 @@ interface GasStatusResponse {
|
|
|
299
286
|
}
|
|
300
287
|
declare function getGasStatus(address?: string): Promise<GasStatusResponse>;
|
|
301
288
|
|
|
302
|
-
export { type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CLOCK_ID, DEFAULT_NETWORK, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, PositionsResult, type ProtocolFeeInfo, RatesResult, RepayResult, SENTINEL, SUI_DECIMALS, SUPPORTED_ASSETS, SaveResult, SendResult, SentinelAgent, SentinelAttackResult,
|
|
289
|
+
export { type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CLOCK_ID, DEFAULT_NETWORK, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, PositionsResult, type ProtocolFeeInfo, RatesResult, RepayResult, SENTINEL, SUI_DECIMALS, SUPPORTED_ASSETS, SaveResult, SendResult, SentinelAgent, SentinelAttackResult, type SimulationResult, type SupportedAsset, SwapAdapter, SwapResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TransactionRecord, USDC_DECIMALS, WithdrawResult, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatSui, formatUsd, generateKeypair, getAddress, getGasStatus, getPoolPrice, getRates, getSwapQuote, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { EventEmitter } from 'eventemitter3';
|
|
2
2
|
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
3
3
|
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
4
|
-
import { T as T2000Options, S as SendResult, B as BalanceResponse, a as TransactionRecord, D as DepositInfo, L as LendingAdapter, b as SwapAdapter, c as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, d as BorrowResult, R as RepayResult, e as MaxBorrowResult, H as HealthFactorResult, f as SwapResult, P as PositionsResult, g as RatesResult, h as LendingRates, E as EarningsResult, F as FundStatusResult, i as SentinelAgent, j as SentinelAttackResult,
|
|
5
|
-
export { A as AdapterCapability,
|
|
4
|
+
import { T as T2000Options, S as SendResult, B as BalanceResponse, a as TransactionRecord, D as DepositInfo, L as LendingAdapter, b as SwapAdapter, c as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, d as BorrowResult, R as RepayResult, e as MaxBorrowResult, H as HealthFactorResult, f as SwapResult, P as PositionsResult, g as RatesResult, h as LendingRates, E as EarningsResult, F as FundStatusResult, i as SentinelAgent, j as SentinelAttackResult, G as GasMethod } from './index-rT0oHn8M.js';
|
|
5
|
+
export { A as AdapterCapability, k as AdapterPositions, l as AdapterTxResult, C as CetusAdapter, m as GasReserve, n as HealthInfo, N as NaviAdapter, o as PositionEntry, p as ProtocolDescriptor, q as ProtocolRegistry, r as SentinelVerdict, s as SuilendAdapter, t as SwapQuote, u as allDescriptors, v as cetusDescriptor, w as getSentinelInfo, x as listSentinels, y as naviDescriptor, z as requestAttack, I as sentinelAttack, J as sentinelDescriptor, K as settleAttack, O as submitPrompt, Q as suilendDescriptor } from './index-rT0oHn8M.js';
|
|
6
6
|
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
7
7
|
|
|
8
8
|
type T2000ErrorCode = 'INSUFFICIENT_BALANCE' | 'INSUFFICIENT_GAS' | 'INVALID_ADDRESS' | 'INVALID_AMOUNT' | 'WALLET_NOT_FOUND' | 'WALLET_LOCKED' | 'WALLET_EXISTS' | 'SPONSOR_FAILED' | 'SPONSOR_RATE_LIMITED' | 'GAS_STATION_UNAVAILABLE' | 'GAS_FEE_EXCEEDED' | 'SIMULATION_FAILED' | 'TRANSACTION_FAILED' | 'ASSET_NOT_SUPPORTED' | 'SLIPPAGE_EXCEEDED' | 'HEALTH_FACTOR_TOO_LOW' | 'WITHDRAW_WOULD_LIQUIDATE' | 'NO_COLLATERAL' | 'PROTOCOL_PAUSED' | 'PROTOCOL_UNAVAILABLE' | 'RPC_ERROR' | 'RPC_UNREACHABLE' | 'SPONSOR_UNAVAILABLE' | 'AUTO_TOPUP_FAILED' | 'PRICE_EXCEEDS_LIMIT' | 'UNSUPPORTED_NETWORK' | 'PAYMENT_EXPIRED' | 'DUPLICATE_PAYMENT' | 'FACILITATOR_REJECTION' | 'FACILITATOR_TIMEOUT' | 'SENTINEL_API_ERROR' | 'SENTINEL_NOT_FOUND' | 'SENTINEL_TX_FAILED' | 'SENTINEL_TEE_ERROR' | 'UNKNOWN';
|
|
@@ -247,19 +247,6 @@ declare function getSwapQuote(client: SuiJsonRpcClient, fromAsset: 'USDC' | 'SUI
|
|
|
247
247
|
|
|
248
248
|
declare function getRates(client: SuiJsonRpcClient): Promise<RatesResult>;
|
|
249
249
|
|
|
250
|
-
declare function listSentinels(): Promise<SentinelAgent[]>;
|
|
251
|
-
declare function getSentinelInfo(client: SuiJsonRpcClient, sentinelObjectId: string): Promise<SentinelAgent>;
|
|
252
|
-
declare function requestAttack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelObjectId: string, feeMist: bigint): Promise<{
|
|
253
|
-
attackObjectId: string;
|
|
254
|
-
digest: string;
|
|
255
|
-
}>;
|
|
256
|
-
declare function submitPrompt(agentId: string, attackObjectId: string, prompt: string): Promise<SentinelVerdict>;
|
|
257
|
-
declare function settleAttack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelObjectId: string, attackObjectId: string, prompt: string, verdict: SentinelVerdict): Promise<{
|
|
258
|
-
digest: string;
|
|
259
|
-
success: boolean;
|
|
260
|
-
}>;
|
|
261
|
-
declare function attack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelId: string, prompt: string, feeMist?: bigint): Promise<SentinelAttackResult>;
|
|
262
|
-
|
|
263
250
|
interface GasExecutionResult {
|
|
264
251
|
digest: string;
|
|
265
252
|
effects: unknown;
|
|
@@ -299,4 +286,4 @@ interface GasStatusResponse {
|
|
|
299
286
|
}
|
|
300
287
|
declare function getGasStatus(address?: string): Promise<GasStatusResponse>;
|
|
301
288
|
|
|
302
|
-
export { type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CLOCK_ID, DEFAULT_NETWORK, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, PositionsResult, type ProtocolFeeInfo, RatesResult, RepayResult, SENTINEL, SUI_DECIMALS, SUPPORTED_ASSETS, SaveResult, SendResult, SentinelAgent, SentinelAttackResult,
|
|
289
|
+
export { type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CLOCK_ID, DEFAULT_NETWORK, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, PositionsResult, type ProtocolFeeInfo, RatesResult, RepayResult, SENTINEL, SUI_DECIMALS, SUPPORTED_ASSETS, SaveResult, SendResult, SentinelAgent, SentinelAttackResult, type SimulationResult, type SupportedAsset, SwapAdapter, SwapResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TransactionRecord, USDC_DECIMALS, WithdrawResult, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatSui, formatUsd, generateKeypair, getAddress, getGasStatus, getPoolPrice, getRates, getSwapQuote, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
package/dist/index.js
CHANGED
|
@@ -45,6 +45,7 @@ var DEFAULT_RPC_URL = "https://fullnode.mainnet.sui.io:443";
|
|
|
45
45
|
var DEFAULT_KEY_PATH = "~/.t2000/wallet.key";
|
|
46
46
|
var API_BASE_URL = process.env.T2000_API_URL ?? "https://api.t2000.ai";
|
|
47
47
|
var CETUS_USDC_SUI_POOL = "0x51e883ba7c0b566a26cbc8a94cd33eb0abd418a77cc1e60ad22fd9b1f29cd2ab";
|
|
48
|
+
var CETUS_PACKAGE = "0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb";
|
|
48
49
|
var SENTINEL = {
|
|
49
50
|
PACKAGE: "0x88b83f36dafcd5f6dcdcf1d2cb5889b03f61264ab3cee9cae35db7aa940a21b7",
|
|
50
51
|
AGENT_REGISTRY: "0xc47564f5f14c12b31e0dfa1a3dc99a6380a1edf8929c28cb0eaa3359c8db36ac",
|
|
@@ -424,8 +425,6 @@ async function reportFee(agentAddress, operation, feeAmount, feeRate, txDigest)
|
|
|
424
425
|
} catch {
|
|
425
426
|
}
|
|
426
427
|
}
|
|
427
|
-
|
|
428
|
-
// src/protocols/navi.ts
|
|
429
428
|
var USDC_TYPE = SUPPORTED_ASSETS.USDC.type;
|
|
430
429
|
var RATE_DECIMALS = 27;
|
|
431
430
|
var LTV_DECIMALS = 27;
|
|
@@ -495,6 +494,24 @@ async function getUsdcPool() {
|
|
|
495
494
|
if (!usdc) throw new T2000Error("PROTOCOL_UNAVAILABLE", "USDC pool not found on NAVI");
|
|
496
495
|
return usdc;
|
|
497
496
|
}
|
|
497
|
+
function addOracleUpdate(tx, config, pool) {
|
|
498
|
+
const feed = config.oracle.feeds?.find((f2) => f2.assetId === pool.id);
|
|
499
|
+
if (!feed) {
|
|
500
|
+
throw new T2000Error("PROTOCOL_UNAVAILABLE", `Oracle feed not found for asset ${pool.token?.symbol ?? pool.id}`);
|
|
501
|
+
}
|
|
502
|
+
tx.moveCall({
|
|
503
|
+
target: `${config.oracle.packageId}::oracle_pro::update_single_price_v2`,
|
|
504
|
+
arguments: [
|
|
505
|
+
tx.object(CLOCK),
|
|
506
|
+
tx.object(config.oracle.oracleConfig),
|
|
507
|
+
tx.object(config.oracle.priceOracle),
|
|
508
|
+
tx.object(config.oracle.supraOracleHolder),
|
|
509
|
+
tx.object(feed.pythPriceInfoObject),
|
|
510
|
+
tx.object(config.oracle.switchboardAggregator),
|
|
511
|
+
tx.pure.address(feed.feedId)
|
|
512
|
+
]
|
|
513
|
+
});
|
|
514
|
+
}
|
|
498
515
|
function rateToApy(rawRate) {
|
|
499
516
|
if (!rawRate || rawRate === "0") return 0;
|
|
500
517
|
return Number(BigInt(rawRate)) / 10 ** RATE_DECIMALS * 100;
|
|
@@ -517,7 +534,7 @@ function compoundBalance(rawBalance, currentIndex) {
|
|
|
517
534
|
if (!rawBalance || !currentIndex || currentIndex === "0") return 0;
|
|
518
535
|
const scale = BigInt("1" + "0".repeat(RATE_DECIMALS));
|
|
519
536
|
const half = scale / 2n;
|
|
520
|
-
const result = (rawBalance *
|
|
537
|
+
const result = (rawBalance * BigInt(currentIndex) + half) / scale;
|
|
521
538
|
return Number(result) / 10 ** NAVI_BALANCE_DECIMALS;
|
|
522
539
|
}
|
|
523
540
|
async function getUserState(client, address) {
|
|
@@ -560,6 +577,9 @@ function mergeCoins(tx, coins) {
|
|
|
560
577
|
return primary;
|
|
561
578
|
}
|
|
562
579
|
async function buildSaveTx(client, address, amount, options = {}) {
|
|
580
|
+
if (!amount || amount <= 0 || !Number.isFinite(amount)) {
|
|
581
|
+
throw new T2000Error("INVALID_AMOUNT", "Save amount must be a positive number");
|
|
582
|
+
}
|
|
563
583
|
const rawAmount = Number(usdcToRaw(amount));
|
|
564
584
|
const [config, pool] = await Promise.all([getConfig(), getUsdcPool()]);
|
|
565
585
|
const coins = await fetchCoins(client, address, USDC_TYPE);
|
|
@@ -600,6 +620,7 @@ async function buildWithdrawTx(client, address, amount) {
|
|
|
600
620
|
const rawAmount = Number(usdcToRaw(effectiveAmount));
|
|
601
621
|
const tx = new Transaction();
|
|
602
622
|
tx.setSender(address);
|
|
623
|
+
addOracleUpdate(tx, config, pool);
|
|
603
624
|
const [balance] = tx.moveCall({
|
|
604
625
|
target: `${config.package}::incentive_v3::withdraw_v2`,
|
|
605
626
|
arguments: [
|
|
@@ -624,10 +645,14 @@ async function buildWithdrawTx(client, address, amount) {
|
|
|
624
645
|
return { tx, effectiveAmount };
|
|
625
646
|
}
|
|
626
647
|
async function buildBorrowTx(client, address, amount, options = {}) {
|
|
648
|
+
if (!amount || amount <= 0 || !Number.isFinite(amount)) {
|
|
649
|
+
throw new T2000Error("INVALID_AMOUNT", "Borrow amount must be a positive number");
|
|
650
|
+
}
|
|
627
651
|
const rawAmount = Number(usdcToRaw(amount));
|
|
628
652
|
const [config, pool] = await Promise.all([getConfig(), getUsdcPool()]);
|
|
629
653
|
const tx = new Transaction();
|
|
630
654
|
tx.setSender(address);
|
|
655
|
+
addOracleUpdate(tx, config, pool);
|
|
631
656
|
const [balance] = tx.moveCall({
|
|
632
657
|
target: `${config.package}::incentive_v3::borrow_v2`,
|
|
633
658
|
arguments: [
|
|
@@ -648,16 +673,23 @@ async function buildBorrowTx(client, address, amount, options = {}) {
|
|
|
648
673
|
arguments: [balance],
|
|
649
674
|
typeArguments: [pool.suiCoinType]
|
|
650
675
|
});
|
|
676
|
+
if (options.collectFee) {
|
|
677
|
+
addCollectFeeToTx(tx, borrowedCoin, "borrow");
|
|
678
|
+
}
|
|
651
679
|
tx.transferObjects([borrowedCoin], address);
|
|
652
680
|
return tx;
|
|
653
681
|
}
|
|
654
682
|
async function buildRepayTx(client, address, amount) {
|
|
683
|
+
if (!amount || amount <= 0 || !Number.isFinite(amount)) {
|
|
684
|
+
throw new T2000Error("INVALID_AMOUNT", "Repay amount must be a positive number");
|
|
685
|
+
}
|
|
655
686
|
const rawAmount = Number(usdcToRaw(amount));
|
|
656
687
|
const [config, pool] = await Promise.all([getConfig(), getUsdcPool()]);
|
|
657
688
|
const coins = await fetchCoins(client, address, USDC_TYPE);
|
|
658
689
|
if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", "No USDC coins to repay with");
|
|
659
690
|
const tx = new Transaction();
|
|
660
691
|
tx.setSender(address);
|
|
692
|
+
addOracleUpdate(tx, config, pool);
|
|
661
693
|
const coinObj = mergeCoins(tx, coins);
|
|
662
694
|
tx.moveCall({
|
|
663
695
|
target: `${config.package}::incentive_v3::entry_repay`,
|
|
@@ -821,6 +853,15 @@ async function getFundStatus(client, keypair) {
|
|
|
821
853
|
projectedMonthly: earnings.dailyEarning * 30
|
|
822
854
|
};
|
|
823
855
|
}
|
|
856
|
+
var descriptor = {
|
|
857
|
+
id: "sentinel",
|
|
858
|
+
name: "Sui Sentinel",
|
|
859
|
+
packages: [SENTINEL.PACKAGE],
|
|
860
|
+
actionMap: {
|
|
861
|
+
"sentinel::request_attack": "sentinel_attack",
|
|
862
|
+
"sentinel::consume_prompt": "sentinel_settle"
|
|
863
|
+
}
|
|
864
|
+
};
|
|
824
865
|
function mapAgent(raw) {
|
|
825
866
|
return {
|
|
826
867
|
id: raw.agent_id,
|
|
@@ -1028,7 +1069,7 @@ var ProtocolRegistry = class {
|
|
|
1028
1069
|
}
|
|
1029
1070
|
}
|
|
1030
1071
|
if (candidates.length === 0) {
|
|
1031
|
-
throw new
|
|
1072
|
+
throw new T2000Error("ASSET_NOT_SUPPORTED", `No lending adapter supports saving ${asset}`);
|
|
1032
1073
|
}
|
|
1033
1074
|
candidates.sort((a, b) => b.rate.saveApy - a.rate.saveApy);
|
|
1034
1075
|
return candidates[0];
|
|
@@ -1046,7 +1087,7 @@ var ProtocolRegistry = class {
|
|
|
1046
1087
|
}
|
|
1047
1088
|
}
|
|
1048
1089
|
if (candidates.length === 0) {
|
|
1049
|
-
throw new
|
|
1090
|
+
throw new T2000Error("ASSET_NOT_SUPPORTED", `No lending adapter supports borrowing ${asset}`);
|
|
1050
1091
|
}
|
|
1051
1092
|
candidates.sort((a, b) => a.rate.borrowApy - b.rate.borrowApy);
|
|
1052
1093
|
return candidates[0];
|
|
@@ -1063,7 +1104,7 @@ var ProtocolRegistry = class {
|
|
|
1063
1104
|
}
|
|
1064
1105
|
}
|
|
1065
1106
|
if (candidates.length === 0) {
|
|
1066
|
-
throw new
|
|
1107
|
+
throw new T2000Error("ASSET_NOT_SUPPORTED", `No swap adapter supports ${from} \u2192 ${to}`);
|
|
1067
1108
|
}
|
|
1068
1109
|
candidates.sort((a, b) => b.quote.expectedOutput - a.quote.expectedOutput);
|
|
1069
1110
|
return candidates[0];
|
|
@@ -1108,6 +1149,22 @@ var ProtocolRegistry = class {
|
|
|
1108
1149
|
};
|
|
1109
1150
|
|
|
1110
1151
|
// src/adapters/navi.ts
|
|
1152
|
+
var descriptor2 = {
|
|
1153
|
+
id: "navi",
|
|
1154
|
+
name: "NAVI Protocol",
|
|
1155
|
+
packages: [],
|
|
1156
|
+
dynamicPackageId: true,
|
|
1157
|
+
actionMap: {
|
|
1158
|
+
"incentive_v3::entry_deposit": "save",
|
|
1159
|
+
"incentive_v3::deposit": "save",
|
|
1160
|
+
"incentive_v3::withdraw_v2": "withdraw",
|
|
1161
|
+
"incentive_v3::entry_withdraw": "withdraw",
|
|
1162
|
+
"incentive_v3::borrow_v2": "borrow",
|
|
1163
|
+
"incentive_v3::entry_borrow": "borrow",
|
|
1164
|
+
"incentive_v3::entry_repay": "repay",
|
|
1165
|
+
"incentive_v3::repay": "repay"
|
|
1166
|
+
}
|
|
1167
|
+
};
|
|
1111
1168
|
var NaviAdapter = class {
|
|
1112
1169
|
id = "navi";
|
|
1113
1170
|
name = "NAVI Protocol";
|
|
@@ -1126,7 +1183,7 @@ var NaviAdapter = class {
|
|
|
1126
1183
|
const rates = await getRates(this.client);
|
|
1127
1184
|
const key = asset.toUpperCase();
|
|
1128
1185
|
const r = rates[key];
|
|
1129
|
-
if (!r) throw new
|
|
1186
|
+
if (!r) throw new T2000Error("ASSET_NOT_SUPPORTED", `NAVI does not support ${asset}`);
|
|
1130
1187
|
return { asset, saveApy: r.saveApy, borrowApy: r.borrowApy };
|
|
1131
1188
|
}
|
|
1132
1189
|
async getPositions(address) {
|
|
@@ -1252,6 +1309,18 @@ function fallbackQuote(fromAsset, amount, poolPrice) {
|
|
|
1252
1309
|
}
|
|
1253
1310
|
|
|
1254
1311
|
// src/adapters/cetus.ts
|
|
1312
|
+
var descriptor3 = {
|
|
1313
|
+
id: "cetus",
|
|
1314
|
+
name: "Cetus DEX",
|
|
1315
|
+
packages: [CETUS_PACKAGE],
|
|
1316
|
+
actionMap: {
|
|
1317
|
+
"router::swap": "swap",
|
|
1318
|
+
"router::swap_ab_bc": "swap",
|
|
1319
|
+
"router::swap_ab_cb": "swap",
|
|
1320
|
+
"router::swap_ba_bc": "swap",
|
|
1321
|
+
"router::swap_ba_cb": "swap"
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1255
1324
|
var CetusAdapter = class {
|
|
1256
1325
|
id = "cetus";
|
|
1257
1326
|
name = "Cetus";
|
|
@@ -1306,6 +1375,20 @@ var LENDING_MARKET_TYPE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea3
|
|
|
1306
1375
|
var SUILEND_PACKAGE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf";
|
|
1307
1376
|
var UPGRADE_CAP_ID = "0x3d4ef1859c3ee9fc72858f588b56a09da5466e64f8cc4e90a7b3b909fba8a7ae";
|
|
1308
1377
|
var FALLBACK_PUBLISHED_AT = "0xd2a67633ccb8de063163e25bcfca242929caf5cf1a26c2929dab519ee0b8f331";
|
|
1378
|
+
var descriptor4 = {
|
|
1379
|
+
id: "suilend",
|
|
1380
|
+
name: "Suilend",
|
|
1381
|
+
packages: [SUILEND_PACKAGE],
|
|
1382
|
+
actionMap: {
|
|
1383
|
+
"lending_market::deposit_liquidity_and_mint_ctokens": "save",
|
|
1384
|
+
"lending_market::deposit_ctokens_into_obligation": "save",
|
|
1385
|
+
"lending_market::create_obligation": "save",
|
|
1386
|
+
"lending_market::withdraw_ctokens": "withdraw",
|
|
1387
|
+
"lending_market::redeem_ctokens_and_withdraw_liquidity": "withdraw",
|
|
1388
|
+
"lending_market::borrow": "borrow",
|
|
1389
|
+
"lending_market::repay": "repay"
|
|
1390
|
+
}
|
|
1391
|
+
};
|
|
1309
1392
|
function interpolateRate(utilBreakpoints, aprBreakpoints, utilizationPct) {
|
|
1310
1393
|
if (utilBreakpoints.length === 0) return 0;
|
|
1311
1394
|
if (utilizationPct <= utilBreakpoints[0]) return aprBreakpoints[0];
|
|
@@ -2329,7 +2412,10 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
2329
2412
|
return { positions };
|
|
2330
2413
|
}
|
|
2331
2414
|
async rates() {
|
|
2332
|
-
|
|
2415
|
+
const allRatesResult = await this.registry.allRates("USDC");
|
|
2416
|
+
if (allRatesResult.length === 0) return { USDC: { saveApy: 0, borrowApy: 0 } };
|
|
2417
|
+
const best = allRatesResult.reduce((a, b) => b.rates.saveApy > a.rates.saveApy ? b : a);
|
|
2418
|
+
return { USDC: { saveApy: best.rates.saveApy, borrowApy: best.rates.borrowApy } };
|
|
2333
2419
|
}
|
|
2334
2420
|
async allRates(asset = "USDC") {
|
|
2335
2421
|
return this.registry.allRates(asset);
|
|
@@ -2481,6 +2567,14 @@ function parseMoveAbort(errorStr) {
|
|
|
2481
2567
|
return { reason: errorStr };
|
|
2482
2568
|
}
|
|
2483
2569
|
|
|
2484
|
-
|
|
2570
|
+
// src/adapters/index.ts
|
|
2571
|
+
var allDescriptors = [
|
|
2572
|
+
descriptor2,
|
|
2573
|
+
descriptor4,
|
|
2574
|
+
descriptor3,
|
|
2575
|
+
descriptor
|
|
2576
|
+
];
|
|
2577
|
+
|
|
2578
|
+
export { BPS_DENOMINATOR, CLOCK_ID, CetusAdapter, DEFAULT_NETWORK, MIST_PER_SUI, NaviAdapter, ProtocolRegistry, SENTINEL, SUI_DECIMALS, SUPPORTED_ASSETS, SuilendAdapter, T2000, T2000Error, USDC_DECIMALS, addCollectFeeToTx, allDescriptors, calculateFee, descriptor3 as cetusDescriptor, executeAutoTopUp, executeWithGas, exportPrivateKey, formatSui, formatUsd, generateKeypair, getAddress, getGasStatus, getPoolPrice, getRates, getSentinelInfo, getSwapQuote, keypairFromPrivateKey, listSentinels, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, descriptor2 as naviDescriptor, rawToUsdc, requestAttack, saveKey, attack as sentinelAttack, descriptor as sentinelDescriptor, settleAttack, shouldAutoTopUp, simulateTransaction, solveHashcash, submitPrompt, suiToMist, descriptor4 as suilendDescriptor, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
|
2485
2579
|
//# sourceMappingURL=index.js.map
|
|
2486
2580
|
//# sourceMappingURL=index.js.map
|