@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
|
@@ -1,7 +1,38 @@
|
|
|
1
1
|
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
2
2
|
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
3
|
+
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
3
4
|
|
|
4
5
|
type AdapterCapability = 'save' | 'withdraw' | 'borrow' | 'repay' | 'swap';
|
|
6
|
+
/**
|
|
7
|
+
* Describes a protocol for indexer event classification.
|
|
8
|
+
* Each adapter exports one of these so the server can auto-build
|
|
9
|
+
* detection rules without manual sync.
|
|
10
|
+
*
|
|
11
|
+
* To add a new protocol: export a `descriptor` from your adapter file.
|
|
12
|
+
*/
|
|
13
|
+
interface ProtocolDescriptor {
|
|
14
|
+
/** Unique protocol ID — must match the adapter's `id` field */
|
|
15
|
+
id: string;
|
|
16
|
+
/** Human-readable name */
|
|
17
|
+
name: string;
|
|
18
|
+
/**
|
|
19
|
+
* On-chain package IDs that identify this protocol's transactions.
|
|
20
|
+
* For protocols with upgradeable packages, list the original/base package.
|
|
21
|
+
*/
|
|
22
|
+
packages: string[];
|
|
23
|
+
/**
|
|
24
|
+
* Maps `module::function` patterns to action types.
|
|
25
|
+
* The indexer matches Move call targets against these patterns.
|
|
26
|
+
* For dynamic package IDs (e.g. NAVI), matching is done on module::function only.
|
|
27
|
+
*/
|
|
28
|
+
actionMap: Record<string, string>;
|
|
29
|
+
/**
|
|
30
|
+
* If true, the indexer matches by module::function suffix only,
|
|
31
|
+
* ignoring the package ID prefix. Use for protocols with frequently
|
|
32
|
+
* upgraded (dynamic) package IDs.
|
|
33
|
+
*/
|
|
34
|
+
dynamicPackageId?: boolean;
|
|
35
|
+
}
|
|
5
36
|
interface AdapterTxResult {
|
|
6
37
|
tx: Transaction;
|
|
7
38
|
feeCoin?: TransactionObjectArgument;
|
|
@@ -292,6 +323,7 @@ declare class ProtocolRegistry {
|
|
|
292
323
|
listSwap(): SwapAdapter[];
|
|
293
324
|
}
|
|
294
325
|
|
|
326
|
+
declare const descriptor$3: ProtocolDescriptor;
|
|
295
327
|
declare class NaviAdapter implements LendingAdapter {
|
|
296
328
|
readonly id = "navi";
|
|
297
329
|
readonly name = "NAVI Protocol";
|
|
@@ -319,6 +351,7 @@ declare class NaviAdapter implements LendingAdapter {
|
|
|
319
351
|
maxBorrow(address: string, _asset: string): Promise<MaxBorrowResult>;
|
|
320
352
|
}
|
|
321
353
|
|
|
354
|
+
declare const descriptor$2: ProtocolDescriptor;
|
|
322
355
|
declare class CetusAdapter implements SwapAdapter {
|
|
323
356
|
readonly id = "cetus";
|
|
324
357
|
readonly name = "Cetus";
|
|
@@ -339,6 +372,7 @@ declare class CetusAdapter implements SwapAdapter {
|
|
|
339
372
|
getPoolPrice(): Promise<number>;
|
|
340
373
|
}
|
|
341
374
|
|
|
375
|
+
declare const descriptor$1: ProtocolDescriptor;
|
|
342
376
|
/**
|
|
343
377
|
* Suilend adapter — contract-first, no SDK dependency.
|
|
344
378
|
* Interacts directly with Suilend Move contracts via RPC + PTB moveCall.
|
|
@@ -387,4 +421,21 @@ declare class SuilendAdapter implements LendingAdapter {
|
|
|
387
421
|
private fetchAllCoins;
|
|
388
422
|
}
|
|
389
423
|
|
|
390
|
-
|
|
424
|
+
declare const descriptor: ProtocolDescriptor;
|
|
425
|
+
declare function listSentinels(): Promise<SentinelAgent[]>;
|
|
426
|
+
declare function getSentinelInfo(client: SuiJsonRpcClient, sentinelObjectId: string): Promise<SentinelAgent>;
|
|
427
|
+
declare function requestAttack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelObjectId: string, feeMist: bigint): Promise<{
|
|
428
|
+
attackObjectId: string;
|
|
429
|
+
digest: string;
|
|
430
|
+
}>;
|
|
431
|
+
declare function submitPrompt(agentId: string, attackObjectId: string, prompt: string): Promise<SentinelVerdict>;
|
|
432
|
+
declare function settleAttack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelObjectId: string, attackObjectId: string, prompt: string, verdict: SentinelVerdict): Promise<{
|
|
433
|
+
digest: string;
|
|
434
|
+
success: boolean;
|
|
435
|
+
}>;
|
|
436
|
+
declare function attack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelId: string, prompt: string, feeMist?: bigint): Promise<SentinelAttackResult>;
|
|
437
|
+
|
|
438
|
+
/** All registered protocol descriptors — used by the indexer for event classification */
|
|
439
|
+
declare const allDescriptors: ProtocolDescriptor[];
|
|
440
|
+
|
|
441
|
+
export { type AdapterCapability as A, type BalanceResponse as B, CetusAdapter as C, type DepositInfo as D, type EarningsResult as E, type FundStatusResult as F, type GasMethod as G, type HealthFactorResult as H, attack as I, descriptor as J, settleAttack as K, type LendingAdapter as L, type MaxWithdrawResult as M, NaviAdapter as N, submitPrompt as O, type PositionsResult as P, descriptor$1 as Q, type RepayResult as R, type SendResult as S, type T2000Options as T, type WithdrawResult as W, type TransactionRecord as a, type SwapAdapter as b, type SaveResult as c, type BorrowResult as d, type MaxBorrowResult as e, type SwapResult as f, type RatesResult as g, type LendingRates as h, type SentinelAgent as i, type SentinelAttackResult as j, type AdapterPositions as k, type AdapterTxResult as l, type GasReserve as m, type HealthInfo as n, type PositionEntry as o, type ProtocolDescriptor as p, ProtocolRegistry as q, type SentinelVerdict as r, SuilendAdapter as s, type SwapQuote as t, allDescriptors as u, descriptor$2 as v, getSentinelInfo as w, listSentinels as x, descriptor$3 as y, requestAttack as z };
|
|
@@ -1,7 +1,38 @@
|
|
|
1
1
|
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
2
2
|
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
3
|
+
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
3
4
|
|
|
4
5
|
type AdapterCapability = 'save' | 'withdraw' | 'borrow' | 'repay' | 'swap';
|
|
6
|
+
/**
|
|
7
|
+
* Describes a protocol for indexer event classification.
|
|
8
|
+
* Each adapter exports one of these so the server can auto-build
|
|
9
|
+
* detection rules without manual sync.
|
|
10
|
+
*
|
|
11
|
+
* To add a new protocol: export a `descriptor` from your adapter file.
|
|
12
|
+
*/
|
|
13
|
+
interface ProtocolDescriptor {
|
|
14
|
+
/** Unique protocol ID — must match the adapter's `id` field */
|
|
15
|
+
id: string;
|
|
16
|
+
/** Human-readable name */
|
|
17
|
+
name: string;
|
|
18
|
+
/**
|
|
19
|
+
* On-chain package IDs that identify this protocol's transactions.
|
|
20
|
+
* For protocols with upgradeable packages, list the original/base package.
|
|
21
|
+
*/
|
|
22
|
+
packages: string[];
|
|
23
|
+
/**
|
|
24
|
+
* Maps `module::function` patterns to action types.
|
|
25
|
+
* The indexer matches Move call targets against these patterns.
|
|
26
|
+
* For dynamic package IDs (e.g. NAVI), matching is done on module::function only.
|
|
27
|
+
*/
|
|
28
|
+
actionMap: Record<string, string>;
|
|
29
|
+
/**
|
|
30
|
+
* If true, the indexer matches by module::function suffix only,
|
|
31
|
+
* ignoring the package ID prefix. Use for protocols with frequently
|
|
32
|
+
* upgraded (dynamic) package IDs.
|
|
33
|
+
*/
|
|
34
|
+
dynamicPackageId?: boolean;
|
|
35
|
+
}
|
|
5
36
|
interface AdapterTxResult {
|
|
6
37
|
tx: Transaction;
|
|
7
38
|
feeCoin?: TransactionObjectArgument;
|
|
@@ -292,6 +323,7 @@ declare class ProtocolRegistry {
|
|
|
292
323
|
listSwap(): SwapAdapter[];
|
|
293
324
|
}
|
|
294
325
|
|
|
326
|
+
declare const descriptor$3: ProtocolDescriptor;
|
|
295
327
|
declare class NaviAdapter implements LendingAdapter {
|
|
296
328
|
readonly id = "navi";
|
|
297
329
|
readonly name = "NAVI Protocol";
|
|
@@ -319,6 +351,7 @@ declare class NaviAdapter implements LendingAdapter {
|
|
|
319
351
|
maxBorrow(address: string, _asset: string): Promise<MaxBorrowResult>;
|
|
320
352
|
}
|
|
321
353
|
|
|
354
|
+
declare const descriptor$2: ProtocolDescriptor;
|
|
322
355
|
declare class CetusAdapter implements SwapAdapter {
|
|
323
356
|
readonly id = "cetus";
|
|
324
357
|
readonly name = "Cetus";
|
|
@@ -339,6 +372,7 @@ declare class CetusAdapter implements SwapAdapter {
|
|
|
339
372
|
getPoolPrice(): Promise<number>;
|
|
340
373
|
}
|
|
341
374
|
|
|
375
|
+
declare const descriptor$1: ProtocolDescriptor;
|
|
342
376
|
/**
|
|
343
377
|
* Suilend adapter — contract-first, no SDK dependency.
|
|
344
378
|
* Interacts directly with Suilend Move contracts via RPC + PTB moveCall.
|
|
@@ -387,4 +421,21 @@ declare class SuilendAdapter implements LendingAdapter {
|
|
|
387
421
|
private fetchAllCoins;
|
|
388
422
|
}
|
|
389
423
|
|
|
390
|
-
|
|
424
|
+
declare const descriptor: ProtocolDescriptor;
|
|
425
|
+
declare function listSentinels(): Promise<SentinelAgent[]>;
|
|
426
|
+
declare function getSentinelInfo(client: SuiJsonRpcClient, sentinelObjectId: string): Promise<SentinelAgent>;
|
|
427
|
+
declare function requestAttack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelObjectId: string, feeMist: bigint): Promise<{
|
|
428
|
+
attackObjectId: string;
|
|
429
|
+
digest: string;
|
|
430
|
+
}>;
|
|
431
|
+
declare function submitPrompt(agentId: string, attackObjectId: string, prompt: string): Promise<SentinelVerdict>;
|
|
432
|
+
declare function settleAttack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelObjectId: string, attackObjectId: string, prompt: string, verdict: SentinelVerdict): Promise<{
|
|
433
|
+
digest: string;
|
|
434
|
+
success: boolean;
|
|
435
|
+
}>;
|
|
436
|
+
declare function attack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelId: string, prompt: string, feeMist?: bigint): Promise<SentinelAttackResult>;
|
|
437
|
+
|
|
438
|
+
/** All registered protocol descriptors — used by the indexer for event classification */
|
|
439
|
+
declare const allDescriptors: ProtocolDescriptor[];
|
|
440
|
+
|
|
441
|
+
export { type AdapterCapability as A, type BalanceResponse as B, CetusAdapter as C, type DepositInfo as D, type EarningsResult as E, type FundStatusResult as F, type GasMethod as G, type HealthFactorResult as H, attack as I, descriptor as J, settleAttack as K, type LendingAdapter as L, type MaxWithdrawResult as M, NaviAdapter as N, submitPrompt as O, type PositionsResult as P, descriptor$1 as Q, type RepayResult as R, type SendResult as S, type T2000Options as T, type WithdrawResult as W, type TransactionRecord as a, type SwapAdapter as b, type SaveResult as c, type BorrowResult as d, type MaxBorrowResult as e, type SwapResult as f, type RatesResult as g, type LendingRates as h, type SentinelAgent as i, type SentinelAttackResult as j, type AdapterPositions as k, type AdapterTxResult as l, type GasReserve as m, type HealthInfo as n, type PositionEntry as o, type ProtocolDescriptor as p, ProtocolRegistry as q, type SentinelVerdict as r, SuilendAdapter as s, type SwapQuote as t, allDescriptors as u, descriptor$2 as v, getSentinelInfo as w, listSentinels as x, descriptor$3 as y, requestAttack as z };
|
package/dist/index.cjs
CHANGED
|
@@ -47,6 +47,7 @@ var DEFAULT_RPC_URL = "https://fullnode.mainnet.sui.io:443";
|
|
|
47
47
|
var DEFAULT_KEY_PATH = "~/.t2000/wallet.key";
|
|
48
48
|
var API_BASE_URL = process.env.T2000_API_URL ?? "https://api.t2000.ai";
|
|
49
49
|
var CETUS_USDC_SUI_POOL = "0x51e883ba7c0b566a26cbc8a94cd33eb0abd418a77cc1e60ad22fd9b1f29cd2ab";
|
|
50
|
+
var CETUS_PACKAGE = "0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb";
|
|
50
51
|
var SENTINEL = {
|
|
51
52
|
PACKAGE: "0x88b83f36dafcd5f6dcdcf1d2cb5889b03f61264ab3cee9cae35db7aa940a21b7",
|
|
52
53
|
AGENT_REGISTRY: "0xc47564f5f14c12b31e0dfa1a3dc99a6380a1edf8929c28cb0eaa3359c8db36ac",
|
|
@@ -426,8 +427,6 @@ async function reportFee(agentAddress, operation, feeAmount, feeRate, txDigest)
|
|
|
426
427
|
} catch {
|
|
427
428
|
}
|
|
428
429
|
}
|
|
429
|
-
|
|
430
|
-
// src/protocols/navi.ts
|
|
431
430
|
var USDC_TYPE = SUPPORTED_ASSETS.USDC.type;
|
|
432
431
|
var RATE_DECIMALS = 27;
|
|
433
432
|
var LTV_DECIMALS = 27;
|
|
@@ -497,6 +496,24 @@ async function getUsdcPool() {
|
|
|
497
496
|
if (!usdc) throw new T2000Error("PROTOCOL_UNAVAILABLE", "USDC pool not found on NAVI");
|
|
498
497
|
return usdc;
|
|
499
498
|
}
|
|
499
|
+
function addOracleUpdate(tx, config, pool) {
|
|
500
|
+
const feed = config.oracle.feeds?.find((f2) => f2.assetId === pool.id);
|
|
501
|
+
if (!feed) {
|
|
502
|
+
throw new T2000Error("PROTOCOL_UNAVAILABLE", `Oracle feed not found for asset ${pool.token?.symbol ?? pool.id}`);
|
|
503
|
+
}
|
|
504
|
+
tx.moveCall({
|
|
505
|
+
target: `${config.oracle.packageId}::oracle_pro::update_single_price_v2`,
|
|
506
|
+
arguments: [
|
|
507
|
+
tx.object(CLOCK),
|
|
508
|
+
tx.object(config.oracle.oracleConfig),
|
|
509
|
+
tx.object(config.oracle.priceOracle),
|
|
510
|
+
tx.object(config.oracle.supraOracleHolder),
|
|
511
|
+
tx.object(feed.pythPriceInfoObject),
|
|
512
|
+
tx.object(config.oracle.switchboardAggregator),
|
|
513
|
+
tx.pure.address(feed.feedId)
|
|
514
|
+
]
|
|
515
|
+
});
|
|
516
|
+
}
|
|
500
517
|
function rateToApy(rawRate) {
|
|
501
518
|
if (!rawRate || rawRate === "0") return 0;
|
|
502
519
|
return Number(BigInt(rawRate)) / 10 ** RATE_DECIMALS * 100;
|
|
@@ -519,7 +536,7 @@ function compoundBalance(rawBalance, currentIndex) {
|
|
|
519
536
|
if (!rawBalance || !currentIndex || currentIndex === "0") return 0;
|
|
520
537
|
const scale = BigInt("1" + "0".repeat(RATE_DECIMALS));
|
|
521
538
|
const half = scale / 2n;
|
|
522
|
-
const result = (rawBalance *
|
|
539
|
+
const result = (rawBalance * BigInt(currentIndex) + half) / scale;
|
|
523
540
|
return Number(result) / 10 ** NAVI_BALANCE_DECIMALS;
|
|
524
541
|
}
|
|
525
542
|
async function getUserState(client, address) {
|
|
@@ -562,6 +579,9 @@ function mergeCoins(tx, coins) {
|
|
|
562
579
|
return primary;
|
|
563
580
|
}
|
|
564
581
|
async function buildSaveTx(client, address, amount, options = {}) {
|
|
582
|
+
if (!amount || amount <= 0 || !Number.isFinite(amount)) {
|
|
583
|
+
throw new T2000Error("INVALID_AMOUNT", "Save amount must be a positive number");
|
|
584
|
+
}
|
|
565
585
|
const rawAmount = Number(usdcToRaw(amount));
|
|
566
586
|
const [config, pool] = await Promise.all([getConfig(), getUsdcPool()]);
|
|
567
587
|
const coins = await fetchCoins(client, address, USDC_TYPE);
|
|
@@ -602,6 +622,7 @@ async function buildWithdrawTx(client, address, amount) {
|
|
|
602
622
|
const rawAmount = Number(usdcToRaw(effectiveAmount));
|
|
603
623
|
const tx = new transactions.Transaction();
|
|
604
624
|
tx.setSender(address);
|
|
625
|
+
addOracleUpdate(tx, config, pool);
|
|
605
626
|
const [balance] = tx.moveCall({
|
|
606
627
|
target: `${config.package}::incentive_v3::withdraw_v2`,
|
|
607
628
|
arguments: [
|
|
@@ -626,10 +647,14 @@ async function buildWithdrawTx(client, address, amount) {
|
|
|
626
647
|
return { tx, effectiveAmount };
|
|
627
648
|
}
|
|
628
649
|
async function buildBorrowTx(client, address, amount, options = {}) {
|
|
650
|
+
if (!amount || amount <= 0 || !Number.isFinite(amount)) {
|
|
651
|
+
throw new T2000Error("INVALID_AMOUNT", "Borrow amount must be a positive number");
|
|
652
|
+
}
|
|
629
653
|
const rawAmount = Number(usdcToRaw(amount));
|
|
630
654
|
const [config, pool] = await Promise.all([getConfig(), getUsdcPool()]);
|
|
631
655
|
const tx = new transactions.Transaction();
|
|
632
656
|
tx.setSender(address);
|
|
657
|
+
addOracleUpdate(tx, config, pool);
|
|
633
658
|
const [balance] = tx.moveCall({
|
|
634
659
|
target: `${config.package}::incentive_v3::borrow_v2`,
|
|
635
660
|
arguments: [
|
|
@@ -650,16 +675,23 @@ async function buildBorrowTx(client, address, amount, options = {}) {
|
|
|
650
675
|
arguments: [balance],
|
|
651
676
|
typeArguments: [pool.suiCoinType]
|
|
652
677
|
});
|
|
678
|
+
if (options.collectFee) {
|
|
679
|
+
addCollectFeeToTx(tx, borrowedCoin, "borrow");
|
|
680
|
+
}
|
|
653
681
|
tx.transferObjects([borrowedCoin], address);
|
|
654
682
|
return tx;
|
|
655
683
|
}
|
|
656
684
|
async function buildRepayTx(client, address, amount) {
|
|
685
|
+
if (!amount || amount <= 0 || !Number.isFinite(amount)) {
|
|
686
|
+
throw new T2000Error("INVALID_AMOUNT", "Repay amount must be a positive number");
|
|
687
|
+
}
|
|
657
688
|
const rawAmount = Number(usdcToRaw(amount));
|
|
658
689
|
const [config, pool] = await Promise.all([getConfig(), getUsdcPool()]);
|
|
659
690
|
const coins = await fetchCoins(client, address, USDC_TYPE);
|
|
660
691
|
if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", "No USDC coins to repay with");
|
|
661
692
|
const tx = new transactions.Transaction();
|
|
662
693
|
tx.setSender(address);
|
|
694
|
+
addOracleUpdate(tx, config, pool);
|
|
663
695
|
const coinObj = mergeCoins(tx, coins);
|
|
664
696
|
tx.moveCall({
|
|
665
697
|
target: `${config.package}::incentive_v3::entry_repay`,
|
|
@@ -823,6 +855,15 @@ async function getFundStatus(client, keypair) {
|
|
|
823
855
|
projectedMonthly: earnings.dailyEarning * 30
|
|
824
856
|
};
|
|
825
857
|
}
|
|
858
|
+
var descriptor = {
|
|
859
|
+
id: "sentinel",
|
|
860
|
+
name: "Sui Sentinel",
|
|
861
|
+
packages: [SENTINEL.PACKAGE],
|
|
862
|
+
actionMap: {
|
|
863
|
+
"sentinel::request_attack": "sentinel_attack",
|
|
864
|
+
"sentinel::consume_prompt": "sentinel_settle"
|
|
865
|
+
}
|
|
866
|
+
};
|
|
826
867
|
function mapAgent(raw) {
|
|
827
868
|
return {
|
|
828
869
|
id: raw.agent_id,
|
|
@@ -1030,7 +1071,7 @@ var ProtocolRegistry = class {
|
|
|
1030
1071
|
}
|
|
1031
1072
|
}
|
|
1032
1073
|
if (candidates.length === 0) {
|
|
1033
|
-
throw new
|
|
1074
|
+
throw new T2000Error("ASSET_NOT_SUPPORTED", `No lending adapter supports saving ${asset}`);
|
|
1034
1075
|
}
|
|
1035
1076
|
candidates.sort((a, b) => b.rate.saveApy - a.rate.saveApy);
|
|
1036
1077
|
return candidates[0];
|
|
@@ -1048,7 +1089,7 @@ var ProtocolRegistry = class {
|
|
|
1048
1089
|
}
|
|
1049
1090
|
}
|
|
1050
1091
|
if (candidates.length === 0) {
|
|
1051
|
-
throw new
|
|
1092
|
+
throw new T2000Error("ASSET_NOT_SUPPORTED", `No lending adapter supports borrowing ${asset}`);
|
|
1052
1093
|
}
|
|
1053
1094
|
candidates.sort((a, b) => a.rate.borrowApy - b.rate.borrowApy);
|
|
1054
1095
|
return candidates[0];
|
|
@@ -1065,7 +1106,7 @@ var ProtocolRegistry = class {
|
|
|
1065
1106
|
}
|
|
1066
1107
|
}
|
|
1067
1108
|
if (candidates.length === 0) {
|
|
1068
|
-
throw new
|
|
1109
|
+
throw new T2000Error("ASSET_NOT_SUPPORTED", `No swap adapter supports ${from} \u2192 ${to}`);
|
|
1069
1110
|
}
|
|
1070
1111
|
candidates.sort((a, b) => b.quote.expectedOutput - a.quote.expectedOutput);
|
|
1071
1112
|
return candidates[0];
|
|
@@ -1110,6 +1151,22 @@ var ProtocolRegistry = class {
|
|
|
1110
1151
|
};
|
|
1111
1152
|
|
|
1112
1153
|
// src/adapters/navi.ts
|
|
1154
|
+
var descriptor2 = {
|
|
1155
|
+
id: "navi",
|
|
1156
|
+
name: "NAVI Protocol",
|
|
1157
|
+
packages: [],
|
|
1158
|
+
dynamicPackageId: true,
|
|
1159
|
+
actionMap: {
|
|
1160
|
+
"incentive_v3::entry_deposit": "save",
|
|
1161
|
+
"incentive_v3::deposit": "save",
|
|
1162
|
+
"incentive_v3::withdraw_v2": "withdraw",
|
|
1163
|
+
"incentive_v3::entry_withdraw": "withdraw",
|
|
1164
|
+
"incentive_v3::borrow_v2": "borrow",
|
|
1165
|
+
"incentive_v3::entry_borrow": "borrow",
|
|
1166
|
+
"incentive_v3::entry_repay": "repay",
|
|
1167
|
+
"incentive_v3::repay": "repay"
|
|
1168
|
+
}
|
|
1169
|
+
};
|
|
1113
1170
|
var NaviAdapter = class {
|
|
1114
1171
|
id = "navi";
|
|
1115
1172
|
name = "NAVI Protocol";
|
|
@@ -1128,7 +1185,7 @@ var NaviAdapter = class {
|
|
|
1128
1185
|
const rates = await getRates(this.client);
|
|
1129
1186
|
const key = asset.toUpperCase();
|
|
1130
1187
|
const r = rates[key];
|
|
1131
|
-
if (!r) throw new
|
|
1188
|
+
if (!r) throw new T2000Error("ASSET_NOT_SUPPORTED", `NAVI does not support ${asset}`);
|
|
1132
1189
|
return { asset, saveApy: r.saveApy, borrowApy: r.borrowApy };
|
|
1133
1190
|
}
|
|
1134
1191
|
async getPositions(address) {
|
|
@@ -1254,6 +1311,18 @@ function fallbackQuote(fromAsset, amount, poolPrice) {
|
|
|
1254
1311
|
}
|
|
1255
1312
|
|
|
1256
1313
|
// src/adapters/cetus.ts
|
|
1314
|
+
var descriptor3 = {
|
|
1315
|
+
id: "cetus",
|
|
1316
|
+
name: "Cetus DEX",
|
|
1317
|
+
packages: [CETUS_PACKAGE],
|
|
1318
|
+
actionMap: {
|
|
1319
|
+
"router::swap": "swap",
|
|
1320
|
+
"router::swap_ab_bc": "swap",
|
|
1321
|
+
"router::swap_ab_cb": "swap",
|
|
1322
|
+
"router::swap_ba_bc": "swap",
|
|
1323
|
+
"router::swap_ba_cb": "swap"
|
|
1324
|
+
}
|
|
1325
|
+
};
|
|
1257
1326
|
var CetusAdapter = class {
|
|
1258
1327
|
id = "cetus";
|
|
1259
1328
|
name = "Cetus";
|
|
@@ -1308,6 +1377,20 @@ var LENDING_MARKET_TYPE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea3
|
|
|
1308
1377
|
var SUILEND_PACKAGE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf";
|
|
1309
1378
|
var UPGRADE_CAP_ID = "0x3d4ef1859c3ee9fc72858f588b56a09da5466e64f8cc4e90a7b3b909fba8a7ae";
|
|
1310
1379
|
var FALLBACK_PUBLISHED_AT = "0xd2a67633ccb8de063163e25bcfca242929caf5cf1a26c2929dab519ee0b8f331";
|
|
1380
|
+
var descriptor4 = {
|
|
1381
|
+
id: "suilend",
|
|
1382
|
+
name: "Suilend",
|
|
1383
|
+
packages: [SUILEND_PACKAGE],
|
|
1384
|
+
actionMap: {
|
|
1385
|
+
"lending_market::deposit_liquidity_and_mint_ctokens": "save",
|
|
1386
|
+
"lending_market::deposit_ctokens_into_obligation": "save",
|
|
1387
|
+
"lending_market::create_obligation": "save",
|
|
1388
|
+
"lending_market::withdraw_ctokens": "withdraw",
|
|
1389
|
+
"lending_market::redeem_ctokens_and_withdraw_liquidity": "withdraw",
|
|
1390
|
+
"lending_market::borrow": "borrow",
|
|
1391
|
+
"lending_market::repay": "repay"
|
|
1392
|
+
}
|
|
1393
|
+
};
|
|
1311
1394
|
function interpolateRate(utilBreakpoints, aprBreakpoints, utilizationPct) {
|
|
1312
1395
|
if (utilBreakpoints.length === 0) return 0;
|
|
1313
1396
|
if (utilizationPct <= utilBreakpoints[0]) return aprBreakpoints[0];
|
|
@@ -2331,7 +2414,10 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2331
2414
|
return { positions };
|
|
2332
2415
|
}
|
|
2333
2416
|
async rates() {
|
|
2334
|
-
|
|
2417
|
+
const allRatesResult = await this.registry.allRates("USDC");
|
|
2418
|
+
if (allRatesResult.length === 0) return { USDC: { saveApy: 0, borrowApy: 0 } };
|
|
2419
|
+
const best = allRatesResult.reduce((a, b) => b.rates.saveApy > a.rates.saveApy ? b : a);
|
|
2420
|
+
return { USDC: { saveApy: best.rates.saveApy, borrowApy: best.rates.borrowApy } };
|
|
2335
2421
|
}
|
|
2336
2422
|
async allRates(asset = "USDC") {
|
|
2337
2423
|
return this.registry.allRates(asset);
|
|
@@ -2483,6 +2569,14 @@ function parseMoveAbort(errorStr) {
|
|
|
2483
2569
|
return { reason: errorStr };
|
|
2484
2570
|
}
|
|
2485
2571
|
|
|
2572
|
+
// src/adapters/index.ts
|
|
2573
|
+
var allDescriptors = [
|
|
2574
|
+
descriptor2,
|
|
2575
|
+
descriptor4,
|
|
2576
|
+
descriptor3,
|
|
2577
|
+
descriptor
|
|
2578
|
+
];
|
|
2579
|
+
|
|
2486
2580
|
exports.BPS_DENOMINATOR = BPS_DENOMINATOR;
|
|
2487
2581
|
exports.CLOCK_ID = CLOCK_ID;
|
|
2488
2582
|
exports.CetusAdapter = CetusAdapter;
|
|
@@ -2498,7 +2592,9 @@ exports.T2000 = T2000;
|
|
|
2498
2592
|
exports.T2000Error = T2000Error;
|
|
2499
2593
|
exports.USDC_DECIMALS = USDC_DECIMALS;
|
|
2500
2594
|
exports.addCollectFeeToTx = addCollectFeeToTx;
|
|
2595
|
+
exports.allDescriptors = allDescriptors;
|
|
2501
2596
|
exports.calculateFee = calculateFee;
|
|
2597
|
+
exports.cetusDescriptor = descriptor3;
|
|
2502
2598
|
exports.executeAutoTopUp = executeAutoTopUp;
|
|
2503
2599
|
exports.executeWithGas = executeWithGas;
|
|
2504
2600
|
exports.exportPrivateKey = exportPrivateKey;
|
|
@@ -2517,16 +2613,19 @@ exports.loadKey = loadKey;
|
|
|
2517
2613
|
exports.mapMoveAbortCode = mapMoveAbortCode;
|
|
2518
2614
|
exports.mapWalletError = mapWalletError;
|
|
2519
2615
|
exports.mistToSui = mistToSui;
|
|
2616
|
+
exports.naviDescriptor = descriptor2;
|
|
2520
2617
|
exports.rawToUsdc = rawToUsdc;
|
|
2521
2618
|
exports.requestAttack = requestAttack;
|
|
2522
2619
|
exports.saveKey = saveKey;
|
|
2523
2620
|
exports.sentinelAttack = attack;
|
|
2621
|
+
exports.sentinelDescriptor = descriptor;
|
|
2524
2622
|
exports.settleAttack = settleAttack;
|
|
2525
2623
|
exports.shouldAutoTopUp = shouldAutoTopUp;
|
|
2526
2624
|
exports.simulateTransaction = simulateTransaction;
|
|
2527
2625
|
exports.solveHashcash = solveHashcash;
|
|
2528
2626
|
exports.submitPrompt = submitPrompt;
|
|
2529
2627
|
exports.suiToMist = suiToMist;
|
|
2628
|
+
exports.suilendDescriptor = descriptor4;
|
|
2530
2629
|
exports.throwIfSimulationFailed = throwIfSimulationFailed;
|
|
2531
2630
|
exports.truncateAddress = truncateAddress;
|
|
2532
2631
|
exports.usdcToRaw = usdcToRaw;
|