@t2000/sdk 1.0.0 → 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-3YmGYl63.cjs';
2
- export { d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from '../descriptors-3YmGYl63.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,28 +55,34 @@ 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>;
61
- buildWithdrawTx(address: string, amount: number, asset: string): Promise<AdapterTxResult & {
58
+ buildSaveTx(address: string, amount: number, asset: string): Promise<AdapterTxResult>;
59
+ buildWithdrawTx(address: string, amount: number, asset: string, options?: {
60
+ skipPythUpdate?: boolean;
61
+ }): Promise<AdapterTxResult & {
62
62
  effectiveAmount: number;
63
63
  }>;
64
64
  buildBorrowTx(address: string, amount: number, asset: string, options?: {
65
- collectFee?: boolean;
65
+ skipPythUpdate?: boolean;
66
66
  }): Promise<AdapterTxResult>;
67
67
  buildRepayTx(address: string, amount: number, asset: string, options?: {
68
68
  skipOracle?: boolean;
69
+ skipPythUpdate?: boolean;
69
70
  }): Promise<AdapterTxResult>;
70
71
  maxWithdraw(address: string, _asset: string): Promise<MaxWithdrawResult>;
71
72
  maxBorrow(address: string, _asset: string): Promise<MaxBorrowResult>;
72
- addWithdrawToTx(tx: Transaction, address: string, amount: number, asset: string): Promise<{
73
+ addWithdrawToTx(tx: Transaction, address: string, amount: number, asset: string, options?: {
74
+ skipPythUpdate?: boolean;
75
+ }): Promise<{
73
76
  coin: TransactionObjectArgument;
74
77
  effectiveAmount: number;
75
78
  }>;
76
- addSaveToTx(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string, options?: {
77
- collectFee?: boolean;
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>;
83
+ addRepayToTx(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string, options?: {
84
+ skipPythUpdate?: boolean;
78
85
  }): Promise<void>;
79
- addRepayToTx(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string): Promise<void>;
80
86
  getPendingRewards(address: string): Promise<PendingReward[]>;
81
87
  addClaimRewardsToTx(tx: Transaction, address: string): Promise<PendingReward[]>;
82
88
  }
@@ -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-3YmGYl63.js';
2
- export { d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from '../descriptors-3YmGYl63.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,28 +55,34 @@ 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>;
61
- buildWithdrawTx(address: string, amount: number, asset: string): Promise<AdapterTxResult & {
58
+ buildSaveTx(address: string, amount: number, asset: string): Promise<AdapterTxResult>;
59
+ buildWithdrawTx(address: string, amount: number, asset: string, options?: {
60
+ skipPythUpdate?: boolean;
61
+ }): Promise<AdapterTxResult & {
62
62
  effectiveAmount: number;
63
63
  }>;
64
64
  buildBorrowTx(address: string, amount: number, asset: string, options?: {
65
- collectFee?: boolean;
65
+ skipPythUpdate?: boolean;
66
66
  }): Promise<AdapterTxResult>;
67
67
  buildRepayTx(address: string, amount: number, asset: string, options?: {
68
68
  skipOracle?: boolean;
69
+ skipPythUpdate?: boolean;
69
70
  }): Promise<AdapterTxResult>;
70
71
  maxWithdraw(address: string, _asset: string): Promise<MaxWithdrawResult>;
71
72
  maxBorrow(address: string, _asset: string): Promise<MaxBorrowResult>;
72
- addWithdrawToTx(tx: Transaction, address: string, amount: number, asset: string): Promise<{
73
+ addWithdrawToTx(tx: Transaction, address: string, amount: number, asset: string, options?: {
74
+ skipPythUpdate?: boolean;
75
+ }): Promise<{
73
76
  coin: TransactionObjectArgument;
74
77
  effectiveAmount: number;
75
78
  }>;
76
- addSaveToTx(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string, options?: {
77
- collectFee?: boolean;
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>;
83
+ addRepayToTx(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string, options?: {
84
+ skipPythUpdate?: boolean;
78
85
  }): Promise<void>;
79
- addRepayToTx(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string): Promise<void>;
80
86
  getPendingRewards(address: string): Promise<PendingReward[]>;
81
87
  addClaimRewardsToTx(tx: Transaction, address: string): Promise<PendingReward[]>;
82
88
  }
@@ -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, {
@@ -4465,7 +4436,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
4465
4436
  }
4466
4437
  const tx = new Transaction();
4467
4438
  tx.setSender(address);
4468
- await refreshOracle(tx, client, address);
4439
+ await refreshOracle(tx, client, address, { skipPythUpdate: options.skipPythUpdate });
4469
4440
  try {
4470
4441
  const coin = await Qe(tx, assetInfo.type, rawAmount, sdkOptions(client));
4471
4442
  tx.transferObjects([coin], address);
@@ -4494,7 +4465,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
4494
4465
  });
4495
4466
  return { coin, effectiveAmount: 0 };
4496
4467
  }
4497
- await refreshOracle(tx, client, address);
4468
+ await refreshOracle(tx, client, address, { skipPythUpdate: options.skipPythUpdate });
4498
4469
  try {
4499
4470
  const coin = await Qe(tx, assetInfo.type, rawAmount, sdkOptions(client));
4500
4471
  return { coin, effectiveAmount };
@@ -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) {
@@ -4519,7 +4487,7 @@ async function addSaveToTx(tx, _client, _address, coin, options = {}) {
4519
4487
  async function addRepayToTx(tx, client, address, coin, options = {}) {
4520
4488
  const asset = options.asset ?? "USDC";
4521
4489
  const assetInfo = resolveAssetInfo(asset);
4522
- await refreshOracle(tx, client, address);
4490
+ await refreshOracle(tx, client, address, { skipPythUpdate: options.skipPythUpdate });
4523
4491
  try {
4524
4492
  await xe(tx, assetInfo.type, coin, { env: "prod" });
4525
4493
  } catch (err) {
@@ -4536,12 +4504,9 @@ async function buildBorrowTx(client, address, amount, options = {}) {
4536
4504
  const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
4537
4505
  const tx = new Transaction();
4538
4506
  tx.setSender(address);
4539
- await refreshOracle(tx, client, address);
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");
@@ -4567,7 +4548,10 @@ async function buildRepayTx(client, address, amount, options = {}) {
4567
4548
  const coinObj = mergeCoins(tx, coins);
4568
4549
  const rawAmount = Math.min(rawRequested, Number(totalBalance));
4569
4550
  const [repayCoin] = tx.splitCoins(coinObj, [rawAmount]);
4570
- await refreshOracle(tx, client, address, { skipOracle: options.skipOracle });
4551
+ await refreshOracle(tx, client, address, {
4552
+ skipOracle: options.skipOracle,
4553
+ skipPythUpdate: options.skipPythUpdate
4554
+ });
4571
4555
  try {
4572
4556
  await xe(tx, assetInfo.type, repayCoin, {
4573
4557
  ...sdkOptions(client),
@@ -4725,14 +4709,17 @@ var NaviAdapter = class {
4725
4709
  async getHealth(address) {
4726
4710
  return getHealthFactor(this.client, address);
4727
4711
  }
4728
- async buildSaveTx(address, amount, asset, options) {
4712
+ async buildSaveTx(address, amount, asset) {
4729
4713
  const normalized = normalizeAsset(asset);
4730
- const tx = await buildSaveTx(this.client, address, amount, { ...options, asset: normalized });
4714
+ const tx = await buildSaveTx(this.client, address, amount, { asset: normalized });
4731
4715
  return { tx };
4732
4716
  }
4733
- async buildWithdrawTx(address, amount, asset) {
4717
+ async buildWithdrawTx(address, amount, asset, options) {
4734
4718
  const normalized = normalizeAsset(asset);
4735
- const result = await buildWithdrawTx(this.client, address, amount, { asset: normalized });
4719
+ const result = await buildWithdrawTx(this.client, address, amount, {
4720
+ asset: normalized,
4721
+ skipPythUpdate: options?.skipPythUpdate
4722
+ });
4736
4723
  return { tx: result.tx, effectiveAmount: result.effectiveAmount };
4737
4724
  }
4738
4725
  async buildBorrowTx(address, amount, asset, options) {
@@ -4744,7 +4731,8 @@ var NaviAdapter = class {
4744
4731
  const normalized = normalizeAsset(asset);
4745
4732
  const tx = await buildRepayTx(this.client, address, amount, {
4746
4733
  asset: normalized,
4747
- skipOracle: options?.skipOracle
4734
+ skipOracle: options?.skipOracle,
4735
+ skipPythUpdate: options?.skipPythUpdate
4748
4736
  });
4749
4737
  return { tx };
4750
4738
  }
@@ -4754,17 +4742,30 @@ var NaviAdapter = class {
4754
4742
  async maxBorrow(address, _asset) {
4755
4743
  return maxBorrowAmount(this.client, address);
4756
4744
  }
4757
- async addWithdrawToTx(tx, address, amount, asset) {
4745
+ async addWithdrawToTx(tx, address, amount, asset, options) {
4758
4746
  const normalized = normalizeAsset(asset);
4759
- return addWithdrawToTx(tx, this.client, address, amount, { asset: normalized });
4747
+ return addWithdrawToTx(tx, this.client, address, amount, {
4748
+ asset: normalized,
4749
+ skipPythUpdate: options?.skipPythUpdate
4750
+ });
4751
+ }
4752
+ async addSaveToTx(tx, address, coin, asset) {
4753
+ const normalized = normalizeAsset(asset);
4754
+ return addSaveToTx(tx, this.client, address, coin, { asset: normalized });
4760
4755
  }
4761
- async addSaveToTx(tx, address, coin, asset, options) {
4756
+ async addBorrowToTx(tx, address, amount, asset, options) {
4762
4757
  const normalized = normalizeAsset(asset);
4763
- 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
+ });
4764
4762
  }
4765
- async addRepayToTx(tx, address, coin, asset) {
4763
+ async addRepayToTx(tx, address, coin, asset, options) {
4766
4764
  const normalized = normalizeAsset(asset);
4767
- return addRepayToTx(tx, this.client, address, coin, { asset: normalized });
4765
+ return addRepayToTx(tx, this.client, address, coin, {
4766
+ asset: normalized,
4767
+ skipPythUpdate: options?.skipPythUpdate
4768
+ });
4768
4769
  }
4769
4770
  async getPendingRewards(address) {
4770
4771
  return getPendingRewards(this.client, address);