@t2000/sdk 1.0.1 → 1.1.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.
@@ -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-CDVXo3BM.cjs';
2
- export { d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from '../descriptors-CDVXo3BM.cjs';
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, options?: {
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, options?: {
83
- collectFee?: boolean;
84
- }): Promise<void>;
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>;
@@ -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-CDVXo3BM.js';
2
- export { d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from '../descriptors-CDVXo3BM.js';
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, options?: {
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, options?: {
83
- collectFee?: boolean;
84
- }): Promise<void>;
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>;
@@ -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,9 @@ var SUPPORTED_ASSETS = {
490
488
  };
491
489
  var STABLE_ASSETS = ["USDC"];
492
490
  var ALL_NAVI_ASSETS = Object.keys(SUPPORTED_ASSETS);
493
- var T2000_PACKAGE_ID = process.env.T2000_PACKAGE_ID ?? "0xd775fcc66eae26797654d435d751dea56b82eeb999de51fd285348e573b968ad";
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_PACKAGE_ID ?? "0xd775fcc66eae26797654d435d751dea56b82eeb999de51fd285348e573b968ad";
492
+ process.env.T2000_CONFIG_ID ?? "0x08ba26f0d260b5edf6a19c71492b3eb914906a7419baf2df1426765157e5862a";
493
+ process.env.T2000_OVERLAY_FEE_WALLET ?? "0x5366efbf2b4fe5767fe2e78eb197aa5f5d138d88ac3333fbf3f80a1927da473a";
496
494
  process.env.T2000_API_URL ?? "https://api.t2000.ai";
497
495
 
498
496
  // src/adapters/registry.ts
@@ -4229,30 +4227,6 @@ async function Ct(e, n, o) {
4229
4227
  return a;
4230
4228
  }
4231
4229
 
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
4230
  // src/protocols/navi.ts
4257
4231
  var MIN_HEALTH_FACTOR = 1.5;
4258
4232
  function sdkOptions(client) {
@@ -4433,9 +4407,6 @@ async function buildSaveTx(client, address, amount, options = {}) {
4433
4407
  const tx = new Transaction();
4434
4408
  tx.setSender(address);
4435
4409
  const coinObj = mergeCoins(tx, coins);
4436
- if (options.collectFee) {
4437
- addCollectFeeToTx(tx, coinObj, "save");
4438
- }
4439
4410
  const rawAmount = Math.min(Number(stableToRaw(amount, assetInfo.decimals)), Number(totalBalance));
4440
4411
  try {
4441
4412
  await Ce(tx, assetInfo.type, coinObj, {
@@ -4506,9 +4477,6 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
4506
4477
  async function addSaveToTx(tx, _client, _address, coin, options = {}) {
4507
4478
  const asset = options.asset ?? "USDC";
4508
4479
  const assetInfo = resolveAssetInfo(asset);
4509
- if (options.collectFee) {
4510
- addCollectFeeToTx(tx, coin, "save");
4511
- }
4512
4480
  try {
4513
4481
  await Ce(tx, assetInfo.type, coin, { env: "prod" });
4514
4482
  } catch (err) {
@@ -4539,9 +4507,6 @@ async function buildBorrowTx(client, address, amount, options = {}) {
4539
4507
  await refreshOracle(tx, client, address, { skipPythUpdate: options.skipPythUpdate });
4540
4508
  try {
4541
4509
  const borrowedCoin = await Xe(tx, assetInfo.type, rawAmount, sdkOptions(client));
4542
- if (options.collectFee) {
4543
- addCollectFeeToTx(tx, borrowedCoin, "borrow");
4544
- }
4545
4510
  tx.transferObjects([borrowedCoin], address);
4546
4511
  } catch (err) {
4547
4512
  const msg = err instanceof Error ? err.message : String(err);
@@ -4549,6 +4514,22 @@ async function buildBorrowTx(client, address, amount, options = {}) {
4549
4514
  }
4550
4515
  return tx;
4551
4516
  }
4517
+ async function addBorrowToTx(tx, client, address, amount, options = {}) {
4518
+ if (!amount || amount <= 0 || !Number.isFinite(amount)) {
4519
+ throw new T2000Error("INVALID_AMOUNT", "Borrow amount must be a positive number");
4520
+ }
4521
+ const asset = options.asset ?? "USDC";
4522
+ const assetInfo = resolveAssetInfo(asset);
4523
+ const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
4524
+ await refreshOracle(tx, client, address, { skipPythUpdate: options.skipPythUpdate });
4525
+ try {
4526
+ const borrowedCoin = await Xe(tx, assetInfo.type, rawAmount, sdkOptions(client));
4527
+ return borrowedCoin;
4528
+ } catch (err) {
4529
+ const msg = err instanceof Error ? err.message : String(err);
4530
+ throw new T2000Error("PROTOCOL_UNAVAILABLE", `NAVI borrow failed: ${msg}`);
4531
+ }
4532
+ }
4552
4533
  async function buildRepayTx(client, address, amount, options = {}) {
4553
4534
  if (!amount || amount <= 0 || !Number.isFinite(amount)) {
4554
4535
  throw new T2000Error("INVALID_AMOUNT", "Repay amount must be a positive number");
@@ -4728,9 +4709,9 @@ var NaviAdapter = class {
4728
4709
  async getHealth(address) {
4729
4710
  return getHealthFactor(this.client, address);
4730
4711
  }
4731
- async buildSaveTx(address, amount, asset, options) {
4712
+ async buildSaveTx(address, amount, asset) {
4732
4713
  const normalized = normalizeAsset(asset);
4733
- const tx = await buildSaveTx(this.client, address, amount, { ...options, asset: normalized });
4714
+ const tx = await buildSaveTx(this.client, address, amount, { asset: normalized });
4734
4715
  return { tx };
4735
4716
  }
4736
4717
  async buildWithdrawTx(address, amount, asset, options) {
@@ -4768,9 +4749,16 @@ var NaviAdapter = class {
4768
4749
  skipPythUpdate: options?.skipPythUpdate
4769
4750
  });
4770
4751
  }
4771
- async addSaveToTx(tx, address, coin, asset, options) {
4752
+ async addSaveToTx(tx, address, coin, asset) {
4753
+ const normalized = normalizeAsset(asset);
4754
+ return addSaveToTx(tx, this.client, address, coin, { asset: normalized });
4755
+ }
4756
+ async addBorrowToTx(tx, address, amount, asset, options) {
4772
4757
  const normalized = normalizeAsset(asset);
4773
- return addSaveToTx(tx, this.client, address, coin, { ...options, asset: normalized });
4758
+ return addBorrowToTx(tx, this.client, address, amount, {
4759
+ asset: normalized,
4760
+ skipPythUpdate: options?.skipPythUpdate
4761
+ });
4774
4762
  }
4775
4763
  async addRepayToTx(tx, address, coin, asset, options) {
4776
4764
  const normalized = normalizeAsset(asset);