@t2000/sdk 1.22.2 → 1.23.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.
@@ -4021,35 +4021,6 @@ async function vt(e, n) {
4021
4021
  );
4022
4022
  return await De(e, t, n);
4023
4023
  }
4024
- function wt(e) {
4025
- const n = /* @__PURE__ */ new Map();
4026
- e.forEach((r) => {
4027
- const t = r.assetId, a = r.option, s = `${t}-${a}-${r.rewardCoinType}-${r.market}`;
4028
- n.has(s) ? n.get(s).total += r.userClaimableReward : n.set(s, {
4029
- assetId: t,
4030
- rewardType: a,
4031
- coinType: r.rewardCoinType,
4032
- total: Number(r.userClaimableReward),
4033
- market: r.market
4034
- });
4035
- });
4036
- const o = /* @__PURE__ */ new Map();
4037
- for (const { assetId: r, rewardType: t, coinType: a, total: s, market: i } of n.values()) {
4038
- const c = `${r}-${t}-${i}`;
4039
- o.has(c) || o.set(c, { assetId: r, rewardType: t, market: i, rewards: /* @__PURE__ */ new Map() });
4040
- const u = o.get(c);
4041
- u.rewards.set(a, (u.rewards.get(a) || 0) + s);
4042
- }
4043
- return Array.from(o.values()).map((r) => ({
4044
- assetId: r.assetId,
4045
- rewardType: r.rewardType,
4046
- market: r.market,
4047
- rewards: Array.from(r.rewards.entries()).map(([t, a]) => ({
4048
- coinType: t,
4049
- available: a.toFixed(6)
4050
- }))
4051
- }));
4052
- }
4053
4024
  async function Ct(e, n, o) {
4054
4025
  const r = await R({
4055
4026
  ...o,
@@ -4225,6 +4196,47 @@ async function Ct(e, n, o) {
4225
4196
  return a;
4226
4197
  }
4227
4198
 
4199
+ // src/token-registry.ts
4200
+ var COIN_REGISTRY = {
4201
+ // ── Tier 1 — Financial layer ──────────────────────────────────────────
4202
+ USDC: { type: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC", decimals: 6, symbol: "USDC", tier: 1 },
4203
+ // ── Tier 2 — Swap assets (15 tokens) ──────────────────────────────────
4204
+ SUI: { type: "0x2::sui::SUI", decimals: 9, symbol: "SUI", tier: 2 },
4205
+ wBTC: { type: "0x0041f9f9344cac094454cd574e333c4fdb132d7bcc9379bcd4aab485b2a63942::wbtc::WBTC", decimals: 8, symbol: "wBTC", tier: 2 },
4206
+ ETH: { type: "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH", decimals: 8, symbol: "ETH", tier: 2 },
4207
+ GOLD: { type: "0x9d297676e7a4b771ab023291377b2adfaa4938fb9080b8d12430e4b108b836a9::xaum::XAUM", decimals: 9, symbol: "GOLD", tier: 2 },
4208
+ DEEP: { type: "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP", decimals: 6, symbol: "DEEP", tier: 2 },
4209
+ WAL: { type: "0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL", decimals: 9, symbol: "WAL", tier: 2 },
4210
+ NS: { type: "0x5145494a5f5100e645e4b0aa950fa6b68f614e8c59e17bc5ded3495123a79178::ns::NS", decimals: 6, symbol: "NS", tier: 2 },
4211
+ IKA: { type: "0x7262fb2f7a3a14c888c438a3cd9b912469a58cf60f367352c46584262e8299aa::ika::IKA", decimals: 9, symbol: "IKA", tier: 2 },
4212
+ CETUS: { type: "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS", decimals: 9, symbol: "CETUS", tier: 2 },
4213
+ NAVX: { type: "0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX", decimals: 9, symbol: "NAVX", tier: 2 },
4214
+ vSUI: { type: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", decimals: 9, symbol: "vSUI", tier: 2 },
4215
+ haSUI: { type: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI", decimals: 9, symbol: "haSUI", tier: 2 },
4216
+ afSUI: { type: "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI", decimals: 9, symbol: "afSUI", tier: 2 },
4217
+ LOFI: { type: "0xf22da9a24ad027cccb5f2d496cbe91de953d363513db08a3a734d361c7c17503::LOFI::LOFI", decimals: 9, symbol: "LOFI", tier: 2 },
4218
+ MANIFEST: { type: "0xc466c28d87b3d5cd34f3d5c088751532d71a38d93a8aae4551dd56272cfb4355::manifest::MANIFEST", decimals: 9, symbol: "MANIFEST", tier: 2 },
4219
+ // ── Legacy — no tier, kept for display accuracy on existing positions ──
4220
+ USDT: { type: "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT", decimals: 6, symbol: "USDT" },
4221
+ USDe: { type: "0x41d587e5336f1c86cad50d38a7136db99333bb9bda91cea4ba69115defeb1402::sui_usde::SUI_USDE", decimals: 6, symbol: "USDe" },
4222
+ USDSUI: { type: "0x44f838219cf67b058f3b37907b655f226153c18e33dfcd0da559a844fea9b1c1::usdsui::USDSUI", decimals: 6, symbol: "USDsui" }
4223
+ };
4224
+ var BY_TYPE = /* @__PURE__ */ new Map();
4225
+ for (const meta of Object.values(COIN_REGISTRY)) {
4226
+ BY_TYPE.set(meta.type, meta);
4227
+ }
4228
+ function getCoinMeta(coinType) {
4229
+ return BY_TYPE.get(coinType);
4230
+ }
4231
+ (() => {
4232
+ const map2 = {};
4233
+ for (const [name, meta] of Object.entries(COIN_REGISTRY)) {
4234
+ map2[name] = meta.type;
4235
+ map2[name.toUpperCase()] = meta.type;
4236
+ }
4237
+ return map2;
4238
+ })();
4239
+
4228
4240
  // src/protocols/navi.ts
4229
4241
  var MIN_HEALTH_FACTOR = 1.5;
4230
4242
  function sdkOptions(client) {
@@ -4584,60 +4596,69 @@ async function maxBorrowAmount(client, address) {
4584
4596
  return { maxAmount, healthFactorAfter: MIN_HEALTH_FACTOR, currentHF: hf.healthFactor };
4585
4597
  }
4586
4598
  async function getPendingRewards(client, address) {
4599
+ let rewards;
4587
4600
  try {
4588
- const rewards = await vt(address, {
4601
+ rewards = await vt(address, {
4589
4602
  ...sdkOptions(client),
4590
4603
  markets: ["main"]
4591
4604
  });
4592
- if (!rewards || rewards.length === 0) return [];
4593
- const summary = wt(rewards);
4594
- const result = [];
4595
- for (const s of summary) {
4596
- for (const rw of s.rewards) {
4597
- const available = Number(rw.available);
4598
- if (available <= 0) continue;
4599
- const symbol = rw.coinType.split("::").pop() ?? "UNKNOWN";
4600
- result.push({
4601
- protocol: "navi",
4602
- asset: String(s.assetId),
4603
- coinType: rw.coinType,
4604
- symbol,
4605
- amount: available,
4606
- estimatedValueUsd: 0
4607
- });
4608
- }
4609
- }
4610
- return result;
4611
- } catch {
4612
- return [];
4605
+ } catch (err) {
4606
+ const msg = err instanceof Error ? err.message : String(err);
4607
+ throw new T2000Error(
4608
+ "PROTOCOL_UNAVAILABLE",
4609
+ `NAVI rewards lookup failed: ${msg}`,
4610
+ { source: "navi-rewards-read" },
4611
+ true
4612
+ );
4613
4613
  }
4614
+ if (!rewards || rewards.length === 0) return [];
4615
+ const claimable = rewards.filter((r) => Number(r.userClaimableReward) > 0);
4616
+ return aggregateClaimableRewards(claimable);
4614
4617
  }
4615
4618
  async function addClaimRewardsToTx(tx, client, address) {
4619
+ let rewards;
4616
4620
  try {
4617
- const rewards = await vt(address, {
4621
+ rewards = await vt(address, {
4618
4622
  ...sdkOptions(client),
4619
4623
  markets: ["main"]
4620
4624
  });
4621
- if (!rewards || rewards.length === 0) return [];
4622
- const claimable = rewards.filter(
4623
- (r) => Number(r.userClaimableReward) > 0
4625
+ } catch (err) {
4626
+ const msg = err instanceof Error ? err.message : String(err);
4627
+ throw new T2000Error(
4628
+ "PROTOCOL_UNAVAILABLE",
4629
+ `NAVI rewards lookup failed: ${msg}`,
4630
+ { source: "navi-rewards-claim-prelude" },
4631
+ true
4624
4632
  );
4625
- if (claimable.length === 0) return [];
4633
+ }
4634
+ if (!rewards || rewards.length === 0) return [];
4635
+ const claimable = rewards.filter(
4636
+ (r) => Number(r.userClaimableReward) > 0
4637
+ );
4638
+ if (claimable.length === 0) return [];
4639
+ try {
4626
4640
  await Ct(tx, claimable, {
4627
4641
  env: "prod",
4628
4642
  customCoinReceive: { type: "transfer", transfer: address }
4629
4643
  });
4630
- return aggregateClaimableRewards(claimable);
4631
- } catch {
4632
- return [];
4644
+ } catch (err) {
4645
+ const msg = err instanceof Error ? err.message : String(err);
4646
+ throw new T2000Error(
4647
+ "PROTOCOL_UNAVAILABLE",
4648
+ `NAVI claim PTB build failed: ${msg}`,
4649
+ { source: "navi-rewards-claim-ptb" },
4650
+ true
4651
+ );
4633
4652
  }
4653
+ return aggregateClaimableRewards(claimable);
4634
4654
  }
4635
4655
  function aggregateClaimableRewards(claimable) {
4636
4656
  const aggregated = /* @__PURE__ */ new Map();
4637
4657
  for (const c of claimable) {
4638
4658
  const coinType = c.rewardCoinType;
4639
4659
  if (!coinType) continue;
4640
- const symbol = coinType.split("::").pop() ?? "REWARD";
4660
+ const meta = getCoinMeta(coinType);
4661
+ const symbol = meta?.symbol ?? coinType.split("::").pop() ?? "REWARD";
4641
4662
  const amount = Number(c.userClaimableReward);
4642
4663
  if (!Number.isFinite(amount) || amount <= 0) continue;
4643
4664
  const existing = aggregated.get(coinType);