@t2000/sdk 0.16.30 → 0.17.1

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/dist/index.cjs CHANGED
@@ -70,6 +70,12 @@ var SUPPORTED_ASSETS = {
70
70
  decimals: 8,
71
71
  symbol: "ETH",
72
72
  displayName: "Ethereum"
73
+ },
74
+ GOLD: {
75
+ type: "0x9d297676e7a4b771ab023291377b2adfaa4938fb9080b8d12430e4b108b836a9::xaum::XAUM",
76
+ decimals: 9,
77
+ symbol: "GOLD",
78
+ displayName: "Gold"
73
79
  }
74
80
  };
75
81
  var STABLE_ASSETS = ["USDC", "USDT", "USDe", "USDsui"];
@@ -85,7 +91,8 @@ var CETUS_PACKAGE = "0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35
85
91
  var INVESTMENT_ASSETS = {
86
92
  SUI: SUPPORTED_ASSETS.SUI,
87
93
  BTC: SUPPORTED_ASSETS.BTC,
88
- ETH: SUPPORTED_ASSETS.ETH
94
+ ETH: SUPPORTED_ASSETS.ETH,
95
+ GOLD: SUPPORTED_ASSETS.GOLD
89
96
  };
90
97
  var DEFAULT_STRATEGIES = {
91
98
  bluechip: {
@@ -105,6 +112,18 @@ var DEFAULT_STRATEGIES = {
105
112
  allocations: { BTC: 20, ETH: 20, SUI: 60 },
106
113
  description: "Sui-weighted portfolio",
107
114
  custom: false
115
+ },
116
+ "all-weather": {
117
+ name: "All-Weather Portfolio",
118
+ allocations: { BTC: 30, ETH: 20, SUI: 20, GOLD: 30 },
119
+ description: "Crypto and commodities",
120
+ custom: false
121
+ },
122
+ "safe-haven": {
123
+ name: "Safe Haven",
124
+ allocations: { BTC: 50, GOLD: 50 },
125
+ description: "Store-of-value assets",
126
+ custom: false
108
127
  }
109
128
  };
110
129
  var PERPS_MARKETS = ["SUI-PERP"];
@@ -351,6 +370,7 @@ function formatSui(amount) {
351
370
  }
352
371
  function formatAssetAmount(amount, asset) {
353
372
  if (asset === "BTC") return amount.toFixed(8);
373
+ if (asset === "GOLD") return amount.toFixed(6);
354
374
  if (asset === "ETH") return amount.toFixed(6);
355
375
  return amount.toFixed(4);
356
376
  }
@@ -571,7 +591,9 @@ SUPPORTED_ASSETS.USDC.type;
571
591
  var RATE_DECIMALS = 27;
572
592
  var LTV_DECIMALS = 27;
573
593
  var MIN_HEALTH_FACTOR = 1.5;
574
- var WITHDRAW_DUST_BUFFER = 1e-3;
594
+ function withdrawDustBuffer(decimals) {
595
+ return 1e3 / 10 ** decimals;
596
+ }
575
597
  var CLOCK = "0x06";
576
598
  var SUI_SYSTEM_STATE = "0x05";
577
599
  var NAVI_BALANCE_DECIMALS = 9;
@@ -694,6 +716,16 @@ function rateToApy(rawRate) {
694
716
  if (!rawRate || rawRate === "0") return 0;
695
717
  return Number(BigInt(rawRate)) / 10 ** RATE_DECIMALS * 100;
696
718
  }
719
+ function poolSaveApy(pool) {
720
+ const incentive = parseFloat(pool.supplyIncentiveApyInfo?.apy ?? "0");
721
+ if (incentive > 0) return incentive;
722
+ return rateToApy(pool.currentSupplyRate);
723
+ }
724
+ function poolBorrowApy(pool) {
725
+ const incentive = parseFloat(pool.borrowIncentiveApyInfo?.apy ?? "0");
726
+ if (incentive > 0) return incentive;
727
+ return rateToApy(pool.currentBorrowRate);
728
+ }
697
729
  function parseLtv(rawLtv) {
698
730
  if (!rawLtv || rawLtv === "0") return 0.75;
699
731
  return Number(BigInt(rawLtv)) / 10 ** LTV_DECIMALS;
@@ -803,7 +835,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
803
835
  ]);
804
836
  const assetState = states.find((s) => s.assetId === pool.id);
805
837
  const deposited = assetState ? compoundBalance(assetState.supplyBalance, pool.currentSupplyIndex, pool) : 0;
806
- const effectiveAmount = Math.min(amount, Math.max(0, deposited - WITHDRAW_DUST_BUFFER));
838
+ const effectiveAmount = Math.min(amount, Math.max(0, deposited - withdrawDustBuffer(assetInfo.decimals)));
807
839
  if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
808
840
  const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
809
841
  if (rawAmount <= 0) {
@@ -846,7 +878,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
846
878
  ]);
847
879
  const assetState = states.find((s) => s.assetId === pool.id);
848
880
  const deposited = assetState ? compoundBalance(assetState.supplyBalance, pool.currentSupplyIndex, pool) : 0;
849
- const effectiveAmount = Math.min(amount, Math.max(0, deposited - WITHDRAW_DUST_BUFFER));
881
+ const effectiveAmount = Math.min(amount, Math.max(0, deposited - withdrawDustBuffer(assetInfo.decimals)));
850
882
  if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
851
883
  const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
852
884
  if (rawAmount <= 0) {
@@ -1075,7 +1107,7 @@ async function getHealthFactor(client, addressOrKeypair) {
1075
1107
  liquidationThreshold: liqThreshold
1076
1108
  };
1077
1109
  }
1078
- var NAVI_SUPPORTED_ASSETS = [...STABLE_ASSETS, "SUI", "ETH"];
1110
+ var NAVI_SUPPORTED_ASSETS = [...STABLE_ASSETS, "SUI", "ETH", "GOLD"];
1079
1111
  async function getRates(client) {
1080
1112
  try {
1081
1113
  const pools = await getPools();
@@ -1084,10 +1116,10 @@ async function getRates(client) {
1084
1116
  const targetType = SUPPORTED_ASSETS[asset].type;
1085
1117
  const pool = pools.find((p) => matchesCoinType(p.suiCoinType || p.coinType || "", targetType));
1086
1118
  if (!pool) continue;
1087
- let saveApy = rateToApy(pool.currentSupplyRate);
1088
- let borrowApy = rateToApy(pool.currentBorrowRate);
1089
- if (saveApy <= 0 || saveApy > 100) saveApy = 0;
1090
- if (borrowApy <= 0 || borrowApy > 100) borrowApy = 0;
1119
+ let saveApy = poolSaveApy(pool);
1120
+ let borrowApy = poolBorrowApy(pool);
1121
+ if (saveApy <= 0 || saveApy > 200) saveApy = 0;
1122
+ if (borrowApy <= 0 || borrowApy > 200) borrowApy = 0;
1091
1123
  result[asset] = { saveApy, borrowApy };
1092
1124
  }
1093
1125
  if (!result.USDC) result.USDC = { saveApy: 4, borrowApy: 6 };
@@ -1112,7 +1144,7 @@ async function getPositions(client, addressOrKeypair) {
1112
1144
  asset: symbol,
1113
1145
  type: "save",
1114
1146
  amount: supplyBal,
1115
- apy: rateToApy(pool.currentSupplyRate)
1147
+ apy: poolSaveApy(pool)
1116
1148
  });
1117
1149
  }
1118
1150
  if (borrowBal > 1e-4) {
@@ -1121,7 +1153,7 @@ async function getPositions(client, addressOrKeypair) {
1121
1153
  asset: symbol,
1122
1154
  type: "borrow",
1123
1155
  amount: borrowBal,
1124
- apy: rateToApy(pool.currentBorrowRate)
1156
+ apy: poolBorrowApy(pool)
1125
1157
  });
1126
1158
  }
1127
1159
  }
@@ -1529,7 +1561,7 @@ var NaviAdapter = class {
1529
1561
  name = "NAVI Protocol";
1530
1562
  version = "1.0.0";
1531
1563
  capabilities = ["save", "withdraw", "borrow", "repay"];
1532
- supportedAssets = [...STABLE_ASSETS, "SUI", "ETH"];
1564
+ supportedAssets = [...STABLE_ASSETS, "SUI", "ETH", "GOLD"];
1533
1565
  supportsSameAssetBorrow = true;
1534
1566
  client;
1535
1567
  async init(client) {
@@ -1936,7 +1968,7 @@ var SuilendAdapter = class {
1936
1968
  name = "Suilend";
1937
1969
  version = "2.0.0";
1938
1970
  capabilities = ["save", "withdraw", "borrow", "repay"];
1939
- supportedAssets = [...STABLE_ASSETS, "SUI", "ETH", "BTC"];
1971
+ supportedAssets = [...STABLE_ASSETS, "SUI", "ETH", "BTC", "GOLD"];
1940
1972
  supportsSameAssetBorrow = false;
1941
1973
  client;
1942
1974
  publishedAt = null;
@@ -5392,6 +5424,7 @@ exports.PERPS_MARKETS = PERPS_MARKETS;
5392
5424
  exports.PortfolioManager = PortfolioManager;
5393
5425
  exports.ProtocolRegistry = ProtocolRegistry;
5394
5426
  exports.SENTINEL = SENTINEL;
5427
+ exports.STABLE_ASSETS = STABLE_ASSETS;
5395
5428
  exports.SUI_DECIMALS = SUI_DECIMALS;
5396
5429
  exports.SUPPORTED_ASSETS = SUPPORTED_ASSETS;
5397
5430
  exports.SafeguardEnforcer = SafeguardEnforcer;