@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.
- package/dist/adapters/index.cjs +81 -60
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.js +81 -60
- package/dist/adapters/index.js.map +1 -1
- package/dist/index.cjs +64 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +57 -5
- package/dist/index.d.ts +57 -5
- package/dist/index.js +62 -64
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5101,35 +5101,6 @@ async function vt(e, n) {
|
|
|
5101
5101
|
);
|
|
5102
5102
|
return await De(e, t, n);
|
|
5103
5103
|
}
|
|
5104
|
-
function wt(e) {
|
|
5105
|
-
const n = /* @__PURE__ */ new Map();
|
|
5106
|
-
e.forEach((r) => {
|
|
5107
|
-
const t = r.assetId, a = r.option, s = `${t}-${a}-${r.rewardCoinType}-${r.market}`;
|
|
5108
|
-
n.has(s) ? n.get(s).total += r.userClaimableReward : n.set(s, {
|
|
5109
|
-
assetId: t,
|
|
5110
|
-
rewardType: a,
|
|
5111
|
-
coinType: r.rewardCoinType,
|
|
5112
|
-
total: Number(r.userClaimableReward),
|
|
5113
|
-
market: r.market
|
|
5114
|
-
});
|
|
5115
|
-
});
|
|
5116
|
-
const o = /* @__PURE__ */ new Map();
|
|
5117
|
-
for (const { assetId: r, rewardType: t, coinType: a, total: s, market: i } of n.values()) {
|
|
5118
|
-
const c = `${r}-${t}-${i}`;
|
|
5119
|
-
o.has(c) || o.set(c, { assetId: r, rewardType: t, market: i, rewards: /* @__PURE__ */ new Map() });
|
|
5120
|
-
const u = o.get(c);
|
|
5121
|
-
u.rewards.set(a, (u.rewards.get(a) || 0) + s);
|
|
5122
|
-
}
|
|
5123
|
-
return Array.from(o.values()).map((r) => ({
|
|
5124
|
-
assetId: r.assetId,
|
|
5125
|
-
rewardType: r.rewardType,
|
|
5126
|
-
market: r.market,
|
|
5127
|
-
rewards: Array.from(r.rewards.entries()).map(([t, a]) => ({
|
|
5128
|
-
coinType: t,
|
|
5129
|
-
available: a.toFixed(6)
|
|
5130
|
-
}))
|
|
5131
|
-
}));
|
|
5132
|
-
}
|
|
5133
5104
|
async function Ct(e, n, o) {
|
|
5134
5105
|
const r = await R({
|
|
5135
5106
|
...o,
|
|
@@ -5307,6 +5278,7 @@ async function Ct(e, n, o) {
|
|
|
5307
5278
|
|
|
5308
5279
|
// src/protocols/navi.ts
|
|
5309
5280
|
init_errors();
|
|
5281
|
+
init_token_registry();
|
|
5310
5282
|
var MIN_HEALTH_FACTOR = 1.5;
|
|
5311
5283
|
function sdkOptions(client) {
|
|
5312
5284
|
return { env: "prod", client, cacheTime: 0, disableCache: true };
|
|
@@ -5665,53 +5637,61 @@ async function maxBorrowAmount(client, address) {
|
|
|
5665
5637
|
return { maxAmount, healthFactorAfter: MIN_HEALTH_FACTOR, currentHF: hf.healthFactor };
|
|
5666
5638
|
}
|
|
5667
5639
|
async function getPendingRewards(client, address) {
|
|
5640
|
+
let rewards;
|
|
5668
5641
|
try {
|
|
5669
|
-
|
|
5642
|
+
rewards = await vt(address, {
|
|
5670
5643
|
...sdkOptions(client),
|
|
5671
5644
|
markets: ["main"]
|
|
5672
5645
|
});
|
|
5673
|
-
|
|
5674
|
-
const
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
result.push({
|
|
5682
|
-
protocol: "navi",
|
|
5683
|
-
asset: String(s.assetId),
|
|
5684
|
-
coinType: rw.coinType,
|
|
5685
|
-
symbol,
|
|
5686
|
-
amount: available,
|
|
5687
|
-
estimatedValueUsd: 0
|
|
5688
|
-
});
|
|
5689
|
-
}
|
|
5690
|
-
}
|
|
5691
|
-
return result;
|
|
5692
|
-
} catch {
|
|
5693
|
-
return [];
|
|
5646
|
+
} catch (err) {
|
|
5647
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
5648
|
+
throw new exports.T2000Error(
|
|
5649
|
+
"PROTOCOL_UNAVAILABLE",
|
|
5650
|
+
`NAVI rewards lookup failed: ${msg}`,
|
|
5651
|
+
{ source: "navi-rewards-read" },
|
|
5652
|
+
true
|
|
5653
|
+
);
|
|
5694
5654
|
}
|
|
5655
|
+
if (!rewards || rewards.length === 0) return [];
|
|
5656
|
+
const claimable = rewards.filter((r) => Number(r.userClaimableReward) > 0);
|
|
5657
|
+
return aggregateClaimableRewards(claimable);
|
|
5695
5658
|
}
|
|
5696
5659
|
async function addClaimRewardsToTx(tx, client, address) {
|
|
5660
|
+
let rewards;
|
|
5697
5661
|
try {
|
|
5698
|
-
|
|
5662
|
+
rewards = await vt(address, {
|
|
5699
5663
|
...sdkOptions(client),
|
|
5700
5664
|
markets: ["main"]
|
|
5701
5665
|
});
|
|
5702
|
-
|
|
5703
|
-
const
|
|
5704
|
-
|
|
5666
|
+
} catch (err) {
|
|
5667
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
5668
|
+
throw new exports.T2000Error(
|
|
5669
|
+
"PROTOCOL_UNAVAILABLE",
|
|
5670
|
+
`NAVI rewards lookup failed: ${msg}`,
|
|
5671
|
+
{ source: "navi-rewards-claim-prelude" },
|
|
5672
|
+
true
|
|
5705
5673
|
);
|
|
5706
|
-
|
|
5674
|
+
}
|
|
5675
|
+
if (!rewards || rewards.length === 0) return [];
|
|
5676
|
+
const claimable = rewards.filter(
|
|
5677
|
+
(r) => Number(r.userClaimableReward) > 0
|
|
5678
|
+
);
|
|
5679
|
+
if (claimable.length === 0) return [];
|
|
5680
|
+
try {
|
|
5707
5681
|
await Ct(tx, claimable, {
|
|
5708
5682
|
env: "prod",
|
|
5709
5683
|
customCoinReceive: { type: "transfer", transfer: address }
|
|
5710
5684
|
});
|
|
5711
|
-
|
|
5712
|
-
|
|
5713
|
-
|
|
5685
|
+
} catch (err) {
|
|
5686
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
5687
|
+
throw new exports.T2000Error(
|
|
5688
|
+
"PROTOCOL_UNAVAILABLE",
|
|
5689
|
+
`NAVI claim PTB build failed: ${msg}`,
|
|
5690
|
+
{ source: "navi-rewards-claim-ptb" },
|
|
5691
|
+
true
|
|
5692
|
+
);
|
|
5714
5693
|
}
|
|
5694
|
+
return aggregateClaimableRewards(claimable);
|
|
5715
5695
|
}
|
|
5716
5696
|
async function buildClaimRewardsTx(client, address) {
|
|
5717
5697
|
const tx = new transactions.Transaction();
|
|
@@ -5724,7 +5704,8 @@ function aggregateClaimableRewards(claimable) {
|
|
|
5724
5704
|
for (const c of claimable) {
|
|
5725
5705
|
const coinType = c.rewardCoinType;
|
|
5726
5706
|
if (!coinType) continue;
|
|
5727
|
-
const
|
|
5707
|
+
const meta = getCoinMeta(coinType);
|
|
5708
|
+
const symbol = meta?.symbol ?? coinType.split("::").pop() ?? "REWARD";
|
|
5728
5709
|
const amount = Number(c.userClaimableReward);
|
|
5729
5710
|
if (!Number.isFinite(amount) || amount <= 0) continue;
|
|
5730
5711
|
const existing = aggregated.get(coinType);
|
|
@@ -7175,13 +7156,20 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7175
7156
|
}
|
|
7176
7157
|
// -- Claim Rewards --
|
|
7177
7158
|
async getPendingRewards() {
|
|
7178
|
-
const adapters = this.registry.listLending();
|
|
7159
|
+
const adapters = this.registry.listLending().filter((a) => a.getPendingRewards);
|
|
7160
|
+
if (adapters.length === 0) return [];
|
|
7179
7161
|
const results = await Promise.allSettled(
|
|
7180
|
-
adapters.
|
|
7162
|
+
adapters.map((a) => a.getPendingRewards(this._address))
|
|
7181
7163
|
);
|
|
7182
7164
|
const all = [];
|
|
7165
|
+
const errors = [];
|
|
7183
7166
|
for (const r of results) {
|
|
7184
7167
|
if (r.status === "fulfilled") all.push(...r.value);
|
|
7168
|
+
else errors.push(r.reason);
|
|
7169
|
+
}
|
|
7170
|
+
if (all.length === 0 && errors.length === adapters.length) {
|
|
7171
|
+
const first = errors[0];
|
|
7172
|
+
throw first instanceof Error ? first : new Error(String(first));
|
|
7185
7173
|
}
|
|
7186
7174
|
return all;
|
|
7187
7175
|
}
|
|
@@ -7194,13 +7182,19 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7194
7182
|
const tx = new transactions.Transaction();
|
|
7195
7183
|
tx.setSender(this._address);
|
|
7196
7184
|
const allRewards = [];
|
|
7185
|
+
const errors = [];
|
|
7197
7186
|
for (const adapter of adapters) {
|
|
7198
7187
|
try {
|
|
7199
7188
|
const claimed = await adapter.addClaimRewardsToTx(tx, this._address);
|
|
7200
7189
|
allRewards.push(...claimed);
|
|
7201
|
-
} catch {
|
|
7190
|
+
} catch (err) {
|
|
7191
|
+
errors.push(err);
|
|
7202
7192
|
}
|
|
7203
7193
|
}
|
|
7194
|
+
if (allRewards.length === 0 && errors.length === adapters.length) {
|
|
7195
|
+
const first = errors[0];
|
|
7196
|
+
throw first instanceof Error ? first : new Error(String(first));
|
|
7197
|
+
}
|
|
7204
7198
|
if (allRewards.length === 0) {
|
|
7205
7199
|
return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0 };
|
|
7206
7200
|
}
|
|
@@ -8054,6 +8048,10 @@ function buildRevokeLeafTx(suinsClient, { label }) {
|
|
|
8054
8048
|
function fullHandle(label) {
|
|
8055
8049
|
return `${label}.${AUDRIC_PARENT_NAME}`;
|
|
8056
8050
|
}
|
|
8051
|
+
function displayHandle(label) {
|
|
8052
|
+
const parentDisplay = AUDRIC_PARENT_NAME.replace(/\.sui$/, "");
|
|
8053
|
+
return `${label}@${parentDisplay}`;
|
|
8054
|
+
}
|
|
8057
8055
|
/*! Bundled license information:
|
|
8058
8056
|
|
|
8059
8057
|
@scure/base/index.js:
|
|
@@ -8092,11 +8090,13 @@ exports.T2000_OVERLAY_FEE_WALLET = T2000_OVERLAY_FEE_WALLET;
|
|
|
8092
8090
|
exports.USDC_DECIMALS = USDC_DECIMALS;
|
|
8093
8091
|
exports.WRITE_APPENDER_REGISTRY = WRITE_APPENDER_REGISTRY;
|
|
8094
8092
|
exports.ZkLoginSigner = ZkLoginSigner;
|
|
8093
|
+
exports.addClaimRewardsToTx = addClaimRewardsToTx;
|
|
8095
8094
|
exports.addFeeTransfer = addFeeTransfer;
|
|
8096
8095
|
exports.addSendToTx = addSendToTx;
|
|
8097
8096
|
exports.addStakeVSuiToTx = addStakeVSuiToTx;
|
|
8098
8097
|
exports.addSwapToTx = addSwapToTx;
|
|
8099
8098
|
exports.addUnstakeVSuiToTx = addUnstakeVSuiToTx;
|
|
8099
|
+
exports.aggregateClaimableRewards = aggregateClaimableRewards;
|
|
8100
8100
|
exports.allDescriptors = allDescriptors;
|
|
8101
8101
|
exports.assertAllowedAsset = assertAllowedAsset;
|
|
8102
8102
|
exports.buildAddLeafTx = buildAddLeafTx;
|
|
@@ -8112,6 +8112,7 @@ exports.classifyLabel = classifyLabel;
|
|
|
8112
8112
|
exports.classifyTransaction = classifyTransaction;
|
|
8113
8113
|
exports.composeTx = composeTx;
|
|
8114
8114
|
exports.deriveAllowedAddressesFromPtb = deriveAllowedAddressesFromPtb;
|
|
8115
|
+
exports.displayHandle = displayHandle;
|
|
8115
8116
|
exports.exportPrivateKey = exportPrivateKey;
|
|
8116
8117
|
exports.extractTransferDetails = extractTransferDetails;
|
|
8117
8118
|
exports.extractTxCommands = extractTxCommands;
|