@t2000/sdk 1.22.1 → 1.23.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.
- package/dist/adapters/index.cjs +53 -29
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.js +53 -29
- package/dist/adapters/index.js.map +1 -1
- package/dist/index.cjs +74 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -5
- package/dist/index.d.ts +36 -5
- package/dist/index.js +74 -33
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5665,53 +5665,77 @@ async function maxBorrowAmount(client, address) {
|
|
|
5665
5665
|
return { maxAmount, healthFactorAfter: MIN_HEALTH_FACTOR, currentHF: hf.healthFactor };
|
|
5666
5666
|
}
|
|
5667
5667
|
async function getPendingRewards(client, address) {
|
|
5668
|
+
let rewards;
|
|
5668
5669
|
try {
|
|
5669
|
-
|
|
5670
|
+
rewards = await vt(address, {
|
|
5670
5671
|
...sdkOptions(client),
|
|
5671
5672
|
markets: ["main"]
|
|
5672
5673
|
});
|
|
5673
|
-
|
|
5674
|
-
const
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
5682
|
-
|
|
5683
|
-
|
|
5684
|
-
|
|
5685
|
-
|
|
5686
|
-
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
|
|
5674
|
+
} catch (err) {
|
|
5675
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
5676
|
+
throw new exports.T2000Error(
|
|
5677
|
+
"PROTOCOL_UNAVAILABLE",
|
|
5678
|
+
`NAVI rewards lookup failed: ${msg}`,
|
|
5679
|
+
{ source: "navi-rewards-read" },
|
|
5680
|
+
true
|
|
5681
|
+
);
|
|
5682
|
+
}
|
|
5683
|
+
if (!rewards || rewards.length === 0) return [];
|
|
5684
|
+
const summary = wt(rewards);
|
|
5685
|
+
const result = [];
|
|
5686
|
+
for (const s of summary) {
|
|
5687
|
+
for (const rw of s.rewards) {
|
|
5688
|
+
const available = Number(rw.available);
|
|
5689
|
+
if (available <= 0) continue;
|
|
5690
|
+
const symbol = rw.coinType.split("::").pop() ?? "UNKNOWN";
|
|
5691
|
+
result.push({
|
|
5692
|
+
protocol: "navi",
|
|
5693
|
+
asset: String(s.assetId),
|
|
5694
|
+
coinType: rw.coinType,
|
|
5695
|
+
symbol,
|
|
5696
|
+
amount: available,
|
|
5697
|
+
estimatedValueUsd: 0
|
|
5698
|
+
});
|
|
5690
5699
|
}
|
|
5691
|
-
return result;
|
|
5692
|
-
} catch {
|
|
5693
|
-
return [];
|
|
5694
5700
|
}
|
|
5701
|
+
return result;
|
|
5695
5702
|
}
|
|
5696
5703
|
async function addClaimRewardsToTx(tx, client, address) {
|
|
5704
|
+
let rewards;
|
|
5697
5705
|
try {
|
|
5698
|
-
|
|
5706
|
+
rewards = await vt(address, {
|
|
5699
5707
|
...sdkOptions(client),
|
|
5700
5708
|
markets: ["main"]
|
|
5701
5709
|
});
|
|
5702
|
-
|
|
5703
|
-
const
|
|
5704
|
-
|
|
5710
|
+
} catch (err) {
|
|
5711
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
5712
|
+
throw new exports.T2000Error(
|
|
5713
|
+
"PROTOCOL_UNAVAILABLE",
|
|
5714
|
+
`NAVI rewards lookup failed: ${msg}`,
|
|
5715
|
+
{ source: "navi-rewards-claim-prelude" },
|
|
5716
|
+
true
|
|
5705
5717
|
);
|
|
5706
|
-
|
|
5718
|
+
}
|
|
5719
|
+
if (!rewards || rewards.length === 0) return [];
|
|
5720
|
+
const claimable = rewards.filter(
|
|
5721
|
+
(r) => Number(r.userClaimableReward) > 0
|
|
5722
|
+
);
|
|
5723
|
+
if (claimable.length === 0) return [];
|
|
5724
|
+
try {
|
|
5707
5725
|
await Ct(tx, claimable, {
|
|
5708
5726
|
env: "prod",
|
|
5709
5727
|
customCoinReceive: { type: "transfer", transfer: address }
|
|
5710
5728
|
});
|
|
5711
|
-
|
|
5712
|
-
|
|
5713
|
-
|
|
5729
|
+
} catch (err) {
|
|
5730
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
5731
|
+
throw new exports.T2000Error(
|
|
5732
|
+
"PROTOCOL_UNAVAILABLE",
|
|
5733
|
+
`NAVI claim PTB build failed: ${msg}`,
|
|
5734
|
+
{ source: "navi-rewards-claim-ptb" },
|
|
5735
|
+
true
|
|
5736
|
+
);
|
|
5714
5737
|
}
|
|
5738
|
+
return aggregateClaimableRewards(claimable);
|
|
5715
5739
|
}
|
|
5716
5740
|
async function buildClaimRewardsTx(client, address) {
|
|
5717
5741
|
const tx = new transactions.Transaction();
|
|
@@ -7175,13 +7199,20 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7175
7199
|
}
|
|
7176
7200
|
// -- Claim Rewards --
|
|
7177
7201
|
async getPendingRewards() {
|
|
7178
|
-
const adapters = this.registry.listLending();
|
|
7202
|
+
const adapters = this.registry.listLending().filter((a) => a.getPendingRewards);
|
|
7203
|
+
if (adapters.length === 0) return [];
|
|
7179
7204
|
const results = await Promise.allSettled(
|
|
7180
|
-
adapters.
|
|
7205
|
+
adapters.map((a) => a.getPendingRewards(this._address))
|
|
7181
7206
|
);
|
|
7182
7207
|
const all = [];
|
|
7208
|
+
const errors = [];
|
|
7183
7209
|
for (const r of results) {
|
|
7184
7210
|
if (r.status === "fulfilled") all.push(...r.value);
|
|
7211
|
+
else errors.push(r.reason);
|
|
7212
|
+
}
|
|
7213
|
+
if (all.length === 0 && errors.length === adapters.length) {
|
|
7214
|
+
const first = errors[0];
|
|
7215
|
+
throw first instanceof Error ? first : new Error(String(first));
|
|
7185
7216
|
}
|
|
7186
7217
|
return all;
|
|
7187
7218
|
}
|
|
@@ -7194,13 +7225,19 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7194
7225
|
const tx = new transactions.Transaction();
|
|
7195
7226
|
tx.setSender(this._address);
|
|
7196
7227
|
const allRewards = [];
|
|
7228
|
+
const errors = [];
|
|
7197
7229
|
for (const adapter of adapters) {
|
|
7198
7230
|
try {
|
|
7199
7231
|
const claimed = await adapter.addClaimRewardsToTx(tx, this._address);
|
|
7200
7232
|
allRewards.push(...claimed);
|
|
7201
|
-
} catch {
|
|
7233
|
+
} catch (err) {
|
|
7234
|
+
errors.push(err);
|
|
7202
7235
|
}
|
|
7203
7236
|
}
|
|
7237
|
+
if (allRewards.length === 0 && errors.length === adapters.length) {
|
|
7238
|
+
const first = errors[0];
|
|
7239
|
+
throw first instanceof Error ? first : new Error(String(first));
|
|
7240
|
+
}
|
|
7204
7241
|
if (allRewards.length === 0) {
|
|
7205
7242
|
return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0 };
|
|
7206
7243
|
}
|
|
@@ -8054,6 +8091,10 @@ function buildRevokeLeafTx(suinsClient, { label }) {
|
|
|
8054
8091
|
function fullHandle(label) {
|
|
8055
8092
|
return `${label}.${AUDRIC_PARENT_NAME}`;
|
|
8056
8093
|
}
|
|
8094
|
+
function displayHandle(label) {
|
|
8095
|
+
const parentDisplay = AUDRIC_PARENT_NAME.replace(/\.sui$/, "");
|
|
8096
|
+
return `${label}@${parentDisplay}`;
|
|
8097
|
+
}
|
|
8057
8098
|
/*! Bundled license information:
|
|
8058
8099
|
|
|
8059
8100
|
@scure/base/index.js:
|
|
@@ -8112,6 +8153,7 @@ exports.classifyLabel = classifyLabel;
|
|
|
8112
8153
|
exports.classifyTransaction = classifyTransaction;
|
|
8113
8154
|
exports.composeTx = composeTx;
|
|
8114
8155
|
exports.deriveAllowedAddressesFromPtb = deriveAllowedAddressesFromPtb;
|
|
8156
|
+
exports.displayHandle = displayHandle;
|
|
8115
8157
|
exports.exportPrivateKey = exportPrivateKey;
|
|
8116
8158
|
exports.extractTransferDetails = extractTransferDetails;
|
|
8117
8159
|
exports.extractTxCommands = extractTxCommands;
|