@t2000/sdk 1.0.1 → 1.1.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/README.md +15 -15
- package/dist/adapters/descriptors.d.cts +1 -1
- package/dist/adapters/descriptors.d.ts +1 -1
- package/dist/adapters/index.cjs +28 -42
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +7 -9
- package/dist/adapters/index.d.ts +7 -9
- package/dist/adapters/index.js +28 -42
- package/dist/adapters/index.js.map +1 -1
- package/dist/browser.cjs +192 -77
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +2 -1
- package/dist/browser.d.ts +2 -1
- package/dist/browser.js +184 -74
- package/dist/browser.js.map +1 -1
- package/dist/{descriptors-CDVXo3BM.d.cts → descriptors-BnbL3xN8.d.cts} +11 -7
- package/dist/{descriptors-CDVXo3BM.d.ts → descriptors-BnbL3xN8.d.ts} +11 -7
- package/dist/index.cjs +94 -94
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -52
- package/dist/index.d.ts +8 -52
- package/dist/index.js +91 -94
- package/dist/index.js.map +1 -1
- package/dist/{token-registry-CoTPqCbS.d.ts → types-BhiUiiNs.d.ts} +162 -45
- package/dist/{token-registry-DAHghHh2.d.cts → types-CMVkJNFp.d.cts} +162 -45
- package/package.json +2 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as LendingAdapter, a as LendingRates, b as AdapterPositions, A as AdapterCapability, H as HealthInfo, c as AdapterTxResult, P as PendingReward } from '../descriptors-
|
|
2
|
-
export { d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from '../descriptors-
|
|
1
|
+
import { L as LendingAdapter, a as LendingRates, b as AdapterPositions, A as AdapterCapability, H as HealthInfo, c as AdapterTxResult, P as PendingReward } from '../descriptors-BnbL3xN8.cjs';
|
|
2
|
+
export { d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from '../descriptors-BnbL3xN8.cjs';
|
|
3
3
|
import { b as MaxWithdrawResult, M as MaxBorrowResult } from '../types-jAD-e7Pq.cjs';
|
|
4
4
|
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
5
5
|
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
@@ -55,16 +55,13 @@ declare class NaviAdapter implements LendingAdapter {
|
|
|
55
55
|
getRates(asset: string): Promise<LendingRates>;
|
|
56
56
|
getPositions(address: string): Promise<AdapterPositions>;
|
|
57
57
|
getHealth(address: string): Promise<HealthInfo>;
|
|
58
|
-
buildSaveTx(address: string, amount: number, asset: string
|
|
59
|
-
collectFee?: boolean;
|
|
60
|
-
}): Promise<AdapterTxResult>;
|
|
58
|
+
buildSaveTx(address: string, amount: number, asset: string): Promise<AdapterTxResult>;
|
|
61
59
|
buildWithdrawTx(address: string, amount: number, asset: string, options?: {
|
|
62
60
|
skipPythUpdate?: boolean;
|
|
63
61
|
}): Promise<AdapterTxResult & {
|
|
64
62
|
effectiveAmount: number;
|
|
65
63
|
}>;
|
|
66
64
|
buildBorrowTx(address: string, amount: number, asset: string, options?: {
|
|
67
|
-
collectFee?: boolean;
|
|
68
65
|
skipPythUpdate?: boolean;
|
|
69
66
|
}): Promise<AdapterTxResult>;
|
|
70
67
|
buildRepayTx(address: string, amount: number, asset: string, options?: {
|
|
@@ -79,9 +76,10 @@ declare class NaviAdapter implements LendingAdapter {
|
|
|
79
76
|
coin: TransactionObjectArgument;
|
|
80
77
|
effectiveAmount: number;
|
|
81
78
|
}>;
|
|
82
|
-
addSaveToTx(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
addSaveToTx(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string): Promise<void>;
|
|
80
|
+
addBorrowToTx(tx: Transaction, address: string, amount: number, asset: string, options?: {
|
|
81
|
+
skipPythUpdate?: boolean;
|
|
82
|
+
}): Promise<TransactionObjectArgument>;
|
|
85
83
|
addRepayToTx(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string, options?: {
|
|
86
84
|
skipPythUpdate?: boolean;
|
|
87
85
|
}): Promise<void>;
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as LendingAdapter, a as LendingRates, b as AdapterPositions, A as AdapterCapability, H as HealthInfo, c as AdapterTxResult, P as PendingReward } from '../descriptors-
|
|
2
|
-
export { d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from '../descriptors-
|
|
1
|
+
import { L as LendingAdapter, a as LendingRates, b as AdapterPositions, A as AdapterCapability, H as HealthInfo, c as AdapterTxResult, P as PendingReward } from '../descriptors-BnbL3xN8.js';
|
|
2
|
+
export { d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from '../descriptors-BnbL3xN8.js';
|
|
3
3
|
import { b as MaxWithdrawResult, M as MaxBorrowResult } from '../types-jAD-e7Pq.js';
|
|
4
4
|
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
5
5
|
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
@@ -55,16 +55,13 @@ declare class NaviAdapter implements LendingAdapter {
|
|
|
55
55
|
getRates(asset: string): Promise<LendingRates>;
|
|
56
56
|
getPositions(address: string): Promise<AdapterPositions>;
|
|
57
57
|
getHealth(address: string): Promise<HealthInfo>;
|
|
58
|
-
buildSaveTx(address: string, amount: number, asset: string
|
|
59
|
-
collectFee?: boolean;
|
|
60
|
-
}): Promise<AdapterTxResult>;
|
|
58
|
+
buildSaveTx(address: string, amount: number, asset: string): Promise<AdapterTxResult>;
|
|
61
59
|
buildWithdrawTx(address: string, amount: number, asset: string, options?: {
|
|
62
60
|
skipPythUpdate?: boolean;
|
|
63
61
|
}): Promise<AdapterTxResult & {
|
|
64
62
|
effectiveAmount: number;
|
|
65
63
|
}>;
|
|
66
64
|
buildBorrowTx(address: string, amount: number, asset: string, options?: {
|
|
67
|
-
collectFee?: boolean;
|
|
68
65
|
skipPythUpdate?: boolean;
|
|
69
66
|
}): Promise<AdapterTxResult>;
|
|
70
67
|
buildRepayTx(address: string, amount: number, asset: string, options?: {
|
|
@@ -79,9 +76,10 @@ declare class NaviAdapter implements LendingAdapter {
|
|
|
79
76
|
coin: TransactionObjectArgument;
|
|
80
77
|
effectiveAmount: number;
|
|
81
78
|
}>;
|
|
82
|
-
addSaveToTx(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
addSaveToTx(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string): Promise<void>;
|
|
80
|
+
addBorrowToTx(tx: Transaction, address: string, amount: number, asset: string, options?: {
|
|
81
|
+
skipPythUpdate?: boolean;
|
|
82
|
+
}): Promise<TransactionObjectArgument>;
|
|
85
83
|
addRepayToTx(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string, options?: {
|
|
86
84
|
skipPythUpdate?: boolean;
|
|
87
85
|
}): Promise<void>;
|
package/dist/adapters/index.js
CHANGED
|
@@ -430,8 +430,6 @@ var T2000Error = class extends Error {
|
|
|
430
430
|
};
|
|
431
431
|
|
|
432
432
|
// src/constants.ts
|
|
433
|
-
var SAVE_FEE_BPS = 10n;
|
|
434
|
-
var BORROW_FEE_BPS = 5n;
|
|
435
433
|
var SUPPORTED_ASSETS = {
|
|
436
434
|
USDC: {
|
|
437
435
|
type: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
|
|
@@ -490,9 +488,7 @@ var SUPPORTED_ASSETS = {
|
|
|
490
488
|
};
|
|
491
489
|
var STABLE_ASSETS = ["USDC"];
|
|
492
490
|
var ALL_NAVI_ASSETS = Object.keys(SUPPORTED_ASSETS);
|
|
493
|
-
|
|
494
|
-
var T2000_CONFIG_ID = process.env.T2000_CONFIG_ID ?? "0x08ba26f0d260b5edf6a19c71492b3eb914906a7419baf2df1426765157e5862a";
|
|
495
|
-
var T2000_TREASURY_ID = process.env.T2000_TREASURY_ID ?? "0xf420ec0dcad44433042fb56e1413fb88d3ff65be94fcf425ef9ff750164590e8";
|
|
491
|
+
process.env.T2000_OVERLAY_FEE_WALLET ?? "0x5366efbf2b4fe5767fe2e78eb197aa5f5d138d88ac3333fbf3f80a1927da473a";
|
|
496
492
|
process.env.T2000_API_URL ?? "https://api.t2000.ai";
|
|
497
493
|
|
|
498
494
|
// src/adapters/registry.ts
|
|
@@ -4229,30 +4225,6 @@ async function Ct(e, n, o) {
|
|
|
4229
4225
|
return a;
|
|
4230
4226
|
}
|
|
4231
4227
|
|
|
4232
|
-
// src/protocols/protocolFee.ts
|
|
4233
|
-
var FEE_RATES = {
|
|
4234
|
-
save: SAVE_FEE_BPS,
|
|
4235
|
-
borrow: BORROW_FEE_BPS
|
|
4236
|
-
};
|
|
4237
|
-
var OP_CODES = {
|
|
4238
|
-
save: 0,
|
|
4239
|
-
borrow: 2
|
|
4240
|
-
};
|
|
4241
|
-
function addCollectFeeToTx(tx, paymentCoin, operation) {
|
|
4242
|
-
const bps = FEE_RATES[operation];
|
|
4243
|
-
if (bps <= 0n) return;
|
|
4244
|
-
tx.moveCall({
|
|
4245
|
-
target: `${T2000_PACKAGE_ID}::treasury::collect_fee`,
|
|
4246
|
-
typeArguments: [SUPPORTED_ASSETS.USDC.type],
|
|
4247
|
-
arguments: [
|
|
4248
|
-
tx.object(T2000_TREASURY_ID),
|
|
4249
|
-
tx.object(T2000_CONFIG_ID),
|
|
4250
|
-
paymentCoin,
|
|
4251
|
-
tx.pure.u8(OP_CODES[operation])
|
|
4252
|
-
]
|
|
4253
|
-
});
|
|
4254
|
-
}
|
|
4255
|
-
|
|
4256
4228
|
// src/protocols/navi.ts
|
|
4257
4229
|
var MIN_HEALTH_FACTOR = 1.5;
|
|
4258
4230
|
function sdkOptions(client) {
|
|
@@ -4433,9 +4405,6 @@ async function buildSaveTx(client, address, amount, options = {}) {
|
|
|
4433
4405
|
const tx = new Transaction();
|
|
4434
4406
|
tx.setSender(address);
|
|
4435
4407
|
const coinObj = mergeCoins(tx, coins);
|
|
4436
|
-
if (options.collectFee) {
|
|
4437
|
-
addCollectFeeToTx(tx, coinObj, "save");
|
|
4438
|
-
}
|
|
4439
4408
|
const rawAmount = Math.min(Number(stableToRaw(amount, assetInfo.decimals)), Number(totalBalance));
|
|
4440
4409
|
try {
|
|
4441
4410
|
await Ce(tx, assetInfo.type, coinObj, {
|
|
@@ -4506,9 +4475,6 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
|
4506
4475
|
async function addSaveToTx(tx, _client, _address, coin, options = {}) {
|
|
4507
4476
|
const asset = options.asset ?? "USDC";
|
|
4508
4477
|
const assetInfo = resolveAssetInfo(asset);
|
|
4509
|
-
if (options.collectFee) {
|
|
4510
|
-
addCollectFeeToTx(tx, coin, "save");
|
|
4511
|
-
}
|
|
4512
4478
|
try {
|
|
4513
4479
|
await Ce(tx, assetInfo.type, coin, { env: "prod" });
|
|
4514
4480
|
} catch (err) {
|
|
@@ -4539,9 +4505,6 @@ async function buildBorrowTx(client, address, amount, options = {}) {
|
|
|
4539
4505
|
await refreshOracle(tx, client, address, { skipPythUpdate: options.skipPythUpdate });
|
|
4540
4506
|
try {
|
|
4541
4507
|
const borrowedCoin = await Xe(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
4542
|
-
if (options.collectFee) {
|
|
4543
|
-
addCollectFeeToTx(tx, borrowedCoin, "borrow");
|
|
4544
|
-
}
|
|
4545
4508
|
tx.transferObjects([borrowedCoin], address);
|
|
4546
4509
|
} catch (err) {
|
|
4547
4510
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -4549,6 +4512,22 @@ async function buildBorrowTx(client, address, amount, options = {}) {
|
|
|
4549
4512
|
}
|
|
4550
4513
|
return tx;
|
|
4551
4514
|
}
|
|
4515
|
+
async function addBorrowToTx(tx, client, address, amount, options = {}) {
|
|
4516
|
+
if (!amount || amount <= 0 || !Number.isFinite(amount)) {
|
|
4517
|
+
throw new T2000Error("INVALID_AMOUNT", "Borrow amount must be a positive number");
|
|
4518
|
+
}
|
|
4519
|
+
const asset = options.asset ?? "USDC";
|
|
4520
|
+
const assetInfo = resolveAssetInfo(asset);
|
|
4521
|
+
const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
|
|
4522
|
+
await refreshOracle(tx, client, address, { skipPythUpdate: options.skipPythUpdate });
|
|
4523
|
+
try {
|
|
4524
|
+
const borrowedCoin = await Xe(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
4525
|
+
return borrowedCoin;
|
|
4526
|
+
} catch (err) {
|
|
4527
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
4528
|
+
throw new T2000Error("PROTOCOL_UNAVAILABLE", `NAVI borrow failed: ${msg}`);
|
|
4529
|
+
}
|
|
4530
|
+
}
|
|
4552
4531
|
async function buildRepayTx(client, address, amount, options = {}) {
|
|
4553
4532
|
if (!amount || amount <= 0 || !Number.isFinite(amount)) {
|
|
4554
4533
|
throw new T2000Error("INVALID_AMOUNT", "Repay amount must be a positive number");
|
|
@@ -4728,9 +4707,9 @@ var NaviAdapter = class {
|
|
|
4728
4707
|
async getHealth(address) {
|
|
4729
4708
|
return getHealthFactor(this.client, address);
|
|
4730
4709
|
}
|
|
4731
|
-
async buildSaveTx(address, amount, asset
|
|
4710
|
+
async buildSaveTx(address, amount, asset) {
|
|
4732
4711
|
const normalized = normalizeAsset(asset);
|
|
4733
|
-
const tx = await buildSaveTx(this.client, address, amount, {
|
|
4712
|
+
const tx = await buildSaveTx(this.client, address, amount, { asset: normalized });
|
|
4734
4713
|
return { tx };
|
|
4735
4714
|
}
|
|
4736
4715
|
async buildWithdrawTx(address, amount, asset, options) {
|
|
@@ -4768,9 +4747,16 @@ var NaviAdapter = class {
|
|
|
4768
4747
|
skipPythUpdate: options?.skipPythUpdate
|
|
4769
4748
|
});
|
|
4770
4749
|
}
|
|
4771
|
-
async addSaveToTx(tx, address, coin, asset
|
|
4750
|
+
async addSaveToTx(tx, address, coin, asset) {
|
|
4751
|
+
const normalized = normalizeAsset(asset);
|
|
4752
|
+
return addSaveToTx(tx, this.client, address, coin, { asset: normalized });
|
|
4753
|
+
}
|
|
4754
|
+
async addBorrowToTx(tx, address, amount, asset, options) {
|
|
4772
4755
|
const normalized = normalizeAsset(asset);
|
|
4773
|
-
return
|
|
4756
|
+
return addBorrowToTx(tx, this.client, address, amount, {
|
|
4757
|
+
asset: normalized,
|
|
4758
|
+
skipPythUpdate: options?.skipPythUpdate
|
|
4759
|
+
});
|
|
4774
4760
|
}
|
|
4775
4761
|
async addRepayToTx(tx, address, coin, asset, options) {
|
|
4776
4762
|
const normalized = normalizeAsset(asset);
|