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