@t2000/sdk 0.17.14 → 0.17.16
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 +279 -3
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.js +279 -3
- package/dist/adapters/index.js.map +1 -1
- package/dist/{index-D4cFY__D.d.cts → index-xQEri-Eu.d.cts} +31 -1
- package/dist/{index-D4cFY__D.d.ts → index-xQEri-Eu.d.ts} +31 -1
- package/dist/index.cjs +327 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +327 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as InvestmentTrade, S as StrategyDefinition, A as AutoInvestSchedule, a as AutoInvestStatus, T as T2000Options, b as SendResult, B as BalanceResponse, c as TransactionRecord, D as DepositInfo, L as LendingAdapter, d as SwapAdapter, e as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, f as BorrowResult, R as RepayResult, g as MaxBorrowResult, H as HealthFactorResult, h as SwapResult, i as InvestResult, j as InvestEarnResult, k as StrategyBuyResult, l as StrategySellResult, m as StrategyRebalanceResult, n as StrategyStatusResult, o as AutoInvestRunResult,
|
|
2
|
-
export {
|
|
1
|
+
import { I as InvestmentTrade, S as StrategyDefinition, A as AutoInvestSchedule, a as AutoInvestStatus, T as T2000Options, b as SendResult, B as BalanceResponse, c as TransactionRecord, D as DepositInfo, L as LendingAdapter, d as SwapAdapter, e as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, f as BorrowResult, R as RepayResult, g as MaxBorrowResult, H as HealthFactorResult, h as SwapResult, i as InvestResult, j as InvestEarnResult, P as PendingReward, C as ClaimRewardsResult, k as StrategyBuyResult, l as StrategySellResult, m as StrategyRebalanceResult, n as StrategyStatusResult, o as AutoInvestRunResult, p as PortfolioResult, q as InvestmentPosition, r as PositionsResult, s as RatesResult, t as LendingRates, u as RebalanceResult, E as EarningsResult, F as FundStatusResult, v as SentinelAgent, w as SentinelAttackResult, G as GasMethod } from './index-xQEri-Eu.cjs';
|
|
2
|
+
export { x as AdapterCapability, y as AdapterPositions, z as AdapterTxResult, J as AssetRates, K as CetusAdapter, N as GasReserve, O as HealthInfo, Q as NaviAdapter, U as PerpsAdapter, V as PerpsPosition, X as PositionEntry, Y as PositionSide, Z as ProtocolDescriptor, _ as ProtocolRegistry, $ as RebalanceStep, a0 as SentinelVerdict, a1 as SuilendAdapter, a2 as SwapQuote, a3 as TradePositionsResult, a4 as TradeResult, a5 as allDescriptors, a6 as cetusDescriptor, a7 as getSentinelInfo, a8 as listSentinels, a9 as naviDescriptor, aa as requestAttack, ab as sentinelAttack, ac as sentinelDescriptor, ad as settleAttack, ae as submitPrompt, af as suilendDescriptor } from './index-xQEri-Eu.cjs';
|
|
3
3
|
import { EventEmitter } from 'eventemitter3';
|
|
4
4
|
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
5
5
|
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
@@ -461,6 +461,8 @@ declare class T2000 extends EventEmitter<T2000Events> {
|
|
|
461
461
|
investUnearn(params: {
|
|
462
462
|
asset: InvestmentAsset;
|
|
463
463
|
}): Promise<InvestEarnResult>;
|
|
464
|
+
getPendingRewards(): Promise<PendingReward[]>;
|
|
465
|
+
claimRewards(): Promise<ClaimRewardsResult>;
|
|
464
466
|
investStrategy(params: {
|
|
465
467
|
strategy: string;
|
|
466
468
|
usdAmount: number;
|
|
@@ -643,4 +645,4 @@ interface GasStatusResponse {
|
|
|
643
645
|
}
|
|
644
646
|
declare function getGasStatus(address?: string): Promise<GasStatusResponse>;
|
|
645
647
|
|
|
646
|
-
export { AutoInvestManager, AutoInvestRunResult, AutoInvestSchedule, AutoInvestStatus, type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CLOCK_ID, type Contact, ContactManager, type ContactMap, DEFAULT_MAX_LEVERAGE, DEFAULT_MAX_POSITION_SIZE, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DEFAULT_STRATEGIES, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, GAS_RESERVE_MIN, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, INVESTMENT_ASSETS, InvestEarnResult, InvestResult, type InvestmentAsset, InvestmentPosition, InvestmentTrade, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, OUTBOUND_OPS, PERPS_MARKETS, type PerpsMarket, PortfolioManager, PortfolioResult, PositionsResult, type ProtocolFeeInfo, RatesResult, RebalanceResult, RepayResult, SENTINEL, STABLE_ASSETS, SUI_DECIMALS, SUPPORTED_ASSETS, type SafeguardConfig, SafeguardEnforcer, SafeguardError, type SafeguardErrorDetails, type SafeguardRule, SaveResult, SendResult, SentinelAgent, SentinelAttackResult, type SimulationResult, type StableAsset, StrategyBuyResult, StrategyDefinition, StrategyManager, StrategyRebalanceResult, StrategySellResult, StrategyStatusResult, type SupportedAsset, SwapAdapter, SwapResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TransactionRecord, type TxMetadata, USDC_DECIMALS, WithdrawResult, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getPoolPrice, getRates, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
|
648
|
+
export { AutoInvestManager, AutoInvestRunResult, AutoInvestSchedule, AutoInvestStatus, type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CLOCK_ID, ClaimRewardsResult, type Contact, ContactManager, type ContactMap, DEFAULT_MAX_LEVERAGE, DEFAULT_MAX_POSITION_SIZE, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DEFAULT_STRATEGIES, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, GAS_RESERVE_MIN, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, INVESTMENT_ASSETS, InvestEarnResult, InvestResult, type InvestmentAsset, InvestmentPosition, InvestmentTrade, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, OUTBOUND_OPS, PERPS_MARKETS, PendingReward, type PerpsMarket, PortfolioManager, PortfolioResult, PositionsResult, type ProtocolFeeInfo, RatesResult, RebalanceResult, RepayResult, SENTINEL, STABLE_ASSETS, SUI_DECIMALS, SUPPORTED_ASSETS, type SafeguardConfig, SafeguardEnforcer, SafeguardError, type SafeguardErrorDetails, type SafeguardRule, SaveResult, SendResult, SentinelAgent, SentinelAttackResult, type SimulationResult, type StableAsset, StrategyBuyResult, StrategyDefinition, StrategyManager, StrategyRebalanceResult, StrategySellResult, StrategyStatusResult, type SupportedAsset, SwapAdapter, SwapResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TransactionRecord, type TxMetadata, USDC_DECIMALS, WithdrawResult, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getPoolPrice, getRates, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as InvestmentTrade, S as StrategyDefinition, A as AutoInvestSchedule, a as AutoInvestStatus, T as T2000Options, b as SendResult, B as BalanceResponse, c as TransactionRecord, D as DepositInfo, L as LendingAdapter, d as SwapAdapter, e as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, f as BorrowResult, R as RepayResult, g as MaxBorrowResult, H as HealthFactorResult, h as SwapResult, i as InvestResult, j as InvestEarnResult, k as StrategyBuyResult, l as StrategySellResult, m as StrategyRebalanceResult, n as StrategyStatusResult, o as AutoInvestRunResult,
|
|
2
|
-
export {
|
|
1
|
+
import { I as InvestmentTrade, S as StrategyDefinition, A as AutoInvestSchedule, a as AutoInvestStatus, T as T2000Options, b as SendResult, B as BalanceResponse, c as TransactionRecord, D as DepositInfo, L as LendingAdapter, d as SwapAdapter, e as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, f as BorrowResult, R as RepayResult, g as MaxBorrowResult, H as HealthFactorResult, h as SwapResult, i as InvestResult, j as InvestEarnResult, P as PendingReward, C as ClaimRewardsResult, k as StrategyBuyResult, l as StrategySellResult, m as StrategyRebalanceResult, n as StrategyStatusResult, o as AutoInvestRunResult, p as PortfolioResult, q as InvestmentPosition, r as PositionsResult, s as RatesResult, t as LendingRates, u as RebalanceResult, E as EarningsResult, F as FundStatusResult, v as SentinelAgent, w as SentinelAttackResult, G as GasMethod } from './index-xQEri-Eu.js';
|
|
2
|
+
export { x as AdapterCapability, y as AdapterPositions, z as AdapterTxResult, J as AssetRates, K as CetusAdapter, N as GasReserve, O as HealthInfo, Q as NaviAdapter, U as PerpsAdapter, V as PerpsPosition, X as PositionEntry, Y as PositionSide, Z as ProtocolDescriptor, _ as ProtocolRegistry, $ as RebalanceStep, a0 as SentinelVerdict, a1 as SuilendAdapter, a2 as SwapQuote, a3 as TradePositionsResult, a4 as TradeResult, a5 as allDescriptors, a6 as cetusDescriptor, a7 as getSentinelInfo, a8 as listSentinels, a9 as naviDescriptor, aa as requestAttack, ab as sentinelAttack, ac as sentinelDescriptor, ad as settleAttack, ae as submitPrompt, af as suilendDescriptor } from './index-xQEri-Eu.js';
|
|
3
3
|
import { EventEmitter } from 'eventemitter3';
|
|
4
4
|
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
5
5
|
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
@@ -461,6 +461,8 @@ declare class T2000 extends EventEmitter<T2000Events> {
|
|
|
461
461
|
investUnearn(params: {
|
|
462
462
|
asset: InvestmentAsset;
|
|
463
463
|
}): Promise<InvestEarnResult>;
|
|
464
|
+
getPendingRewards(): Promise<PendingReward[]>;
|
|
465
|
+
claimRewards(): Promise<ClaimRewardsResult>;
|
|
464
466
|
investStrategy(params: {
|
|
465
467
|
strategy: string;
|
|
466
468
|
usdAmount: number;
|
|
@@ -643,4 +645,4 @@ interface GasStatusResponse {
|
|
|
643
645
|
}
|
|
644
646
|
declare function getGasStatus(address?: string): Promise<GasStatusResponse>;
|
|
645
647
|
|
|
646
|
-
export { AutoInvestManager, AutoInvestRunResult, AutoInvestSchedule, AutoInvestStatus, type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CLOCK_ID, type Contact, ContactManager, type ContactMap, DEFAULT_MAX_LEVERAGE, DEFAULT_MAX_POSITION_SIZE, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DEFAULT_STRATEGIES, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, GAS_RESERVE_MIN, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, INVESTMENT_ASSETS, InvestEarnResult, InvestResult, type InvestmentAsset, InvestmentPosition, InvestmentTrade, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, OUTBOUND_OPS, PERPS_MARKETS, type PerpsMarket, PortfolioManager, PortfolioResult, PositionsResult, type ProtocolFeeInfo, RatesResult, RebalanceResult, RepayResult, SENTINEL, STABLE_ASSETS, SUI_DECIMALS, SUPPORTED_ASSETS, type SafeguardConfig, SafeguardEnforcer, SafeguardError, type SafeguardErrorDetails, type SafeguardRule, SaveResult, SendResult, SentinelAgent, SentinelAttackResult, type SimulationResult, type StableAsset, StrategyBuyResult, StrategyDefinition, StrategyManager, StrategyRebalanceResult, StrategySellResult, StrategyStatusResult, type SupportedAsset, SwapAdapter, SwapResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TransactionRecord, type TxMetadata, USDC_DECIMALS, WithdrawResult, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getPoolPrice, getRates, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
|
648
|
+
export { AutoInvestManager, AutoInvestRunResult, AutoInvestSchedule, AutoInvestStatus, type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CLOCK_ID, ClaimRewardsResult, type Contact, ContactManager, type ContactMap, DEFAULT_MAX_LEVERAGE, DEFAULT_MAX_POSITION_SIZE, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DEFAULT_STRATEGIES, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, GAS_RESERVE_MIN, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, INVESTMENT_ASSETS, InvestEarnResult, InvestResult, type InvestmentAsset, InvestmentPosition, InvestmentTrade, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, OUTBOUND_OPS, PERPS_MARKETS, PendingReward, type PerpsMarket, PortfolioManager, PortfolioResult, PositionsResult, type ProtocolFeeInfo, RatesResult, RebalanceResult, RepayResult, SENTINEL, STABLE_ASSETS, SUI_DECIMALS, SUPPORTED_ASSETS, type SafeguardConfig, SafeguardEnforcer, SafeguardError, type SafeguardErrorDetails, type SafeguardRule, SaveResult, SendResult, SentinelAgent, SentinelAttackResult, type SimulationResult, type StableAsset, StrategyBuyResult, StrategyDefinition, StrategyManager, StrategyRebalanceResult, StrategySellResult, StrategyStatusResult, type SupportedAsset, SwapAdapter, SwapResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TransactionRecord, type TxMetadata, USDC_DECIMALS, WithdrawResult, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getPoolPrice, getRates, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
package/dist/index.js
CHANGED
|
@@ -493,6 +493,7 @@ async function queryBalance(client, address) {
|
|
|
493
493
|
debt: 0,
|
|
494
494
|
investment: 0,
|
|
495
495
|
investmentPnL: 0,
|
|
496
|
+
pendingRewards: 0,
|
|
496
497
|
gasReserve: {
|
|
497
498
|
sui: suiAmount,
|
|
498
499
|
usdEquiv
|
|
@@ -1176,6 +1177,172 @@ async function maxBorrowAmount(client, addressOrKeypair) {
|
|
|
1176
1177
|
const maxAmount = Math.max(0, hf.supplied * ltv / MIN_HEALTH_FACTOR - hf.borrowed);
|
|
1177
1178
|
return { maxAmount, healthFactorAfter: MIN_HEALTH_FACTOR, currentHF: hf.healthFactor };
|
|
1178
1179
|
}
|
|
1180
|
+
var CERT_TYPE = "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT";
|
|
1181
|
+
var DEEP_TYPE = "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP";
|
|
1182
|
+
var REWARD_FUNDS = {
|
|
1183
|
+
[CERT_TYPE]: "0x7093cf7549d5e5b35bfde2177223d1050f71655c7f676a5e610ee70eb4d93b5c",
|
|
1184
|
+
[DEEP_TYPE]: "0xc889d78b634f954979e80e622a2ae0fece824c0f6d9590044378a2563035f32f"
|
|
1185
|
+
};
|
|
1186
|
+
var REWARD_SYMBOLS = {
|
|
1187
|
+
[CERT_TYPE]: "vSUI",
|
|
1188
|
+
[DEEP_TYPE]: "DEEP"
|
|
1189
|
+
};
|
|
1190
|
+
var incentiveRulesCache = null;
|
|
1191
|
+
async function getIncentiveRules(client) {
|
|
1192
|
+
if (incentiveRulesCache && Date.now() - incentiveRulesCache.ts < CACHE_TTL) {
|
|
1193
|
+
return incentiveRulesCache.data;
|
|
1194
|
+
}
|
|
1195
|
+
const [pools, obj] = await Promise.all([
|
|
1196
|
+
getPools(),
|
|
1197
|
+
client.getObject({
|
|
1198
|
+
id: "0x62982dad27fb10bb314b3384d5de8d2ac2d72ab2dbeae5d801dbdb9efa816c80",
|
|
1199
|
+
options: { showContent: true }
|
|
1200
|
+
})
|
|
1201
|
+
]);
|
|
1202
|
+
const rewardCoinMap = /* @__PURE__ */ new Map();
|
|
1203
|
+
for (const pool of pools) {
|
|
1204
|
+
const ct = (pool.suiCoinType || pool.coinType || "").toLowerCase();
|
|
1205
|
+
const suffix = ct.split("::").slice(1).join("::");
|
|
1206
|
+
const coins = pool.supplyIncentiveApyInfo?.rewardCoin;
|
|
1207
|
+
if (Array.isArray(coins) && coins.length > 0) {
|
|
1208
|
+
rewardCoinMap.set(suffix, coins[0]);
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
const result = /* @__PURE__ */ new Map();
|
|
1212
|
+
if (obj.data?.content?.dataType !== "moveObject") {
|
|
1213
|
+
incentiveRulesCache = { data: result, ts: Date.now() };
|
|
1214
|
+
return result;
|
|
1215
|
+
}
|
|
1216
|
+
const fields = obj.data.content.fields;
|
|
1217
|
+
const poolsObj = fields.pools;
|
|
1218
|
+
const entries = poolsObj?.fields?.contents;
|
|
1219
|
+
if (!Array.isArray(entries)) {
|
|
1220
|
+
incentiveRulesCache = { data: result, ts: Date.now() };
|
|
1221
|
+
return result;
|
|
1222
|
+
}
|
|
1223
|
+
for (const entry of entries) {
|
|
1224
|
+
const ef = entry?.fields;
|
|
1225
|
+
if (!ef) continue;
|
|
1226
|
+
const key = String(ef.key ?? "");
|
|
1227
|
+
const value = ef.value;
|
|
1228
|
+
const rules = value?.fields?.rules;
|
|
1229
|
+
const ruleEntries = rules?.fields?.contents;
|
|
1230
|
+
if (!Array.isArray(ruleEntries)) continue;
|
|
1231
|
+
const ruleIds = ruleEntries.map((re) => {
|
|
1232
|
+
const rf = re?.fields;
|
|
1233
|
+
return String(rf?.key ?? "");
|
|
1234
|
+
}).filter(Boolean);
|
|
1235
|
+
const suffix = key.split("::").slice(1).join("::").toLowerCase();
|
|
1236
|
+
const full = key.toLowerCase();
|
|
1237
|
+
const rewardCoin = rewardCoinMap.get(suffix) ?? rewardCoinMap.get(full) ?? null;
|
|
1238
|
+
result.set(key, { ruleIds, rewardCoinType: rewardCoin });
|
|
1239
|
+
}
|
|
1240
|
+
incentiveRulesCache = { data: result, ts: Date.now() };
|
|
1241
|
+
return result;
|
|
1242
|
+
}
|
|
1243
|
+
function stripPrefix(coinType) {
|
|
1244
|
+
return coinType.replace(/^0x0*/, "");
|
|
1245
|
+
}
|
|
1246
|
+
async function getPendingRewards(client, address) {
|
|
1247
|
+
const [pools, states, rules] = await Promise.all([
|
|
1248
|
+
getPools(),
|
|
1249
|
+
getUserState(client, address),
|
|
1250
|
+
getIncentiveRules(client)
|
|
1251
|
+
]);
|
|
1252
|
+
const rewards = [];
|
|
1253
|
+
const deposited = states.filter((s) => s.supplyBalance > 0n);
|
|
1254
|
+
if (deposited.length === 0) return rewards;
|
|
1255
|
+
const rewardTotals = /* @__PURE__ */ new Map();
|
|
1256
|
+
for (const state of deposited) {
|
|
1257
|
+
const pool = pools.find((p) => p.id === state.assetId);
|
|
1258
|
+
if (!pool) continue;
|
|
1259
|
+
const boostedApr = parseFloat(pool.supplyIncentiveApyInfo?.boostedApr ?? "0");
|
|
1260
|
+
if (boostedApr <= 0) continue;
|
|
1261
|
+
const rewardCoins = pool.supplyIncentiveApyInfo?.rewardCoin;
|
|
1262
|
+
if (!Array.isArray(rewardCoins) || rewardCoins.length === 0) continue;
|
|
1263
|
+
const rewardType = rewardCoins[0];
|
|
1264
|
+
const supplyBal = compoundBalance(state.supplyBalance, pool.currentSupplyIndex, pool);
|
|
1265
|
+
const price = pool.token?.price ?? 0;
|
|
1266
|
+
const depositUsd = supplyBal * price;
|
|
1267
|
+
const annualRewardUsd = depositUsd * (boostedApr / 100);
|
|
1268
|
+
const estimatedUsd = annualRewardUsd / 365;
|
|
1269
|
+
rewardTotals.set(rewardType, (rewardTotals.get(rewardType) ?? 0) + estimatedUsd);
|
|
1270
|
+
}
|
|
1271
|
+
for (const [coinType, dailyUsd] of rewardTotals) {
|
|
1272
|
+
rewards.push({
|
|
1273
|
+
protocol: "navi",
|
|
1274
|
+
coinType,
|
|
1275
|
+
symbol: REWARD_SYMBOLS[coinType] ?? coinType.split("::").pop() ?? "UNKNOWN",
|
|
1276
|
+
amount: 0,
|
|
1277
|
+
estimatedValueUsd: dailyUsd
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
return rewards;
|
|
1281
|
+
}
|
|
1282
|
+
async function addClaimRewardsToTx(tx, client, address) {
|
|
1283
|
+
const [config, pools, states, rules] = await Promise.all([
|
|
1284
|
+
getConfig(),
|
|
1285
|
+
getPools(),
|
|
1286
|
+
getUserState(client, address),
|
|
1287
|
+
getIncentiveRules(client)
|
|
1288
|
+
]);
|
|
1289
|
+
const deposited = states.filter((s) => s.supplyBalance > 0n);
|
|
1290
|
+
if (deposited.length === 0) return [];
|
|
1291
|
+
const claimGroups = /* @__PURE__ */ new Map();
|
|
1292
|
+
for (const state of deposited) {
|
|
1293
|
+
const pool = pools.find((p) => p.id === state.assetId);
|
|
1294
|
+
if (!pool) continue;
|
|
1295
|
+
const boostedApr = parseFloat(pool.supplyIncentiveApyInfo?.boostedApr ?? "0");
|
|
1296
|
+
if (boostedApr <= 0) continue;
|
|
1297
|
+
const rewardCoins = pool.supplyIncentiveApyInfo?.rewardCoin;
|
|
1298
|
+
if (!Array.isArray(rewardCoins) || rewardCoins.length === 0) continue;
|
|
1299
|
+
const rewardType = rewardCoins[0];
|
|
1300
|
+
const fundId = REWARD_FUNDS[rewardType];
|
|
1301
|
+
if (!fundId) continue;
|
|
1302
|
+
const coinType = pool.suiCoinType || pool.coinType || "";
|
|
1303
|
+
const strippedType = stripPrefix(coinType);
|
|
1304
|
+
const ruleData = Array.from(rules.entries()).find(
|
|
1305
|
+
([key]) => stripPrefix(key) === strippedType || key.split("::").slice(1).join("::").toLowerCase() === coinType.split("::").slice(1).join("::").toLowerCase()
|
|
1306
|
+
);
|
|
1307
|
+
if (!ruleData || ruleData[1].ruleIds.length === 0) continue;
|
|
1308
|
+
const group = claimGroups.get(rewardType) ?? { assets: [], ruleIds: [] };
|
|
1309
|
+
for (const ruleId of ruleData[1].ruleIds) {
|
|
1310
|
+
group.assets.push(strippedType);
|
|
1311
|
+
group.ruleIds.push(ruleId);
|
|
1312
|
+
}
|
|
1313
|
+
claimGroups.set(rewardType, group);
|
|
1314
|
+
}
|
|
1315
|
+
const claimed = [];
|
|
1316
|
+
for (const [rewardType, { assets, ruleIds }] of claimGroups) {
|
|
1317
|
+
const fundId = REWARD_FUNDS[rewardType];
|
|
1318
|
+
const [balance] = tx.moveCall({
|
|
1319
|
+
target: `${config.package}::incentive_v3::claim_reward`,
|
|
1320
|
+
typeArguments: [rewardType],
|
|
1321
|
+
arguments: [
|
|
1322
|
+
tx.object(CLOCK),
|
|
1323
|
+
tx.object(config.incentiveV3),
|
|
1324
|
+
tx.object(config.storage),
|
|
1325
|
+
tx.object(fundId),
|
|
1326
|
+
tx.pure(bcs.vector(bcs.string()).serialize(assets)),
|
|
1327
|
+
tx.pure(bcs.vector(bcs.Address).serialize(ruleIds))
|
|
1328
|
+
]
|
|
1329
|
+
});
|
|
1330
|
+
const [coin] = tx.moveCall({
|
|
1331
|
+
target: "0x2::coin::from_balance",
|
|
1332
|
+
typeArguments: [rewardType],
|
|
1333
|
+
arguments: [balance]
|
|
1334
|
+
});
|
|
1335
|
+
tx.transferObjects([coin], address);
|
|
1336
|
+
claimed.push({
|
|
1337
|
+
protocol: "navi",
|
|
1338
|
+
coinType: rewardType,
|
|
1339
|
+
symbol: REWARD_SYMBOLS[rewardType] ?? "UNKNOWN",
|
|
1340
|
+
amount: 0,
|
|
1341
|
+
estimatedValueUsd: 0
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
return claimed;
|
|
1345
|
+
}
|
|
1179
1346
|
|
|
1180
1347
|
// src/protocols/yieldTracker.ts
|
|
1181
1348
|
async function getEarnings(client, keypair) {
|
|
@@ -1623,6 +1790,12 @@ var NaviAdapter = class {
|
|
|
1623
1790
|
const normalized = normalizeAsset(asset);
|
|
1624
1791
|
return addRepayToTx(tx, this.client, address, coin, { asset: normalized });
|
|
1625
1792
|
}
|
|
1793
|
+
async getPendingRewards(address) {
|
|
1794
|
+
return getPendingRewards(this.client, address);
|
|
1795
|
+
}
|
|
1796
|
+
async addClaimRewardsToTx(tx, address) {
|
|
1797
|
+
return addClaimRewardsToTx(tx, this.client, address);
|
|
1798
|
+
}
|
|
1626
1799
|
};
|
|
1627
1800
|
var DEFAULT_SLIPPAGE_BPS = 300;
|
|
1628
1801
|
function createAggregatorClient(client, signer) {
|
|
@@ -1948,15 +2121,17 @@ function parseReserve(raw, index) {
|
|
|
1948
2121
|
const dMgr = f(r.deposits_pool_reward_manager);
|
|
1949
2122
|
const rawRewards = Array.isArray(dMgr?.pool_rewards) ? dMgr.pool_rewards : [];
|
|
1950
2123
|
const now = Date.now();
|
|
1951
|
-
const depositPoolRewards = rawRewards.
|
|
2124
|
+
const depositPoolRewards = rawRewards.map((rw, idx) => {
|
|
2125
|
+
if (rw === null) return null;
|
|
1952
2126
|
const rwf = f(rw);
|
|
1953
2127
|
return {
|
|
1954
2128
|
coinType: str(f(rwf.coin_type)?.name),
|
|
1955
2129
|
totalRewards: num(rwf.total_rewards),
|
|
1956
2130
|
startTimeMs: num(rwf.start_time_ms),
|
|
1957
|
-
endTimeMs: num(rwf.end_time_ms)
|
|
2131
|
+
endTimeMs: num(rwf.end_time_ms),
|
|
2132
|
+
rewardIndex: idx
|
|
1958
2133
|
};
|
|
1959
|
-
}).filter((rw) => rw.endTimeMs > now && rw.totalRewards > 0);
|
|
2134
|
+
}).filter((rw) => rw !== null && rw.endTimeMs > now && rw.totalRewards > 0);
|
|
1960
2135
|
return {
|
|
1961
2136
|
coinType: str(coinTypeField?.name),
|
|
1962
2137
|
mintDecimals: num(r.mint_decimals),
|
|
@@ -2507,6 +2682,108 @@ var SuilendAdapter = class {
|
|
|
2507
2682
|
}
|
|
2508
2683
|
return all;
|
|
2509
2684
|
}
|
|
2685
|
+
// -- Claim Rewards --------------------------------------------------------
|
|
2686
|
+
isClaimableReward(coinType) {
|
|
2687
|
+
const ct = coinType.toLowerCase();
|
|
2688
|
+
return ct.includes("spring_sui") || ct.includes("deep::deep") || ct.includes("cert::cert");
|
|
2689
|
+
}
|
|
2690
|
+
async getPendingRewards(address) {
|
|
2691
|
+
const caps = await this.fetchObligationCaps(address);
|
|
2692
|
+
if (caps.length === 0) return [];
|
|
2693
|
+
const [reserves, obligation] = await Promise.all([
|
|
2694
|
+
this.loadReserves(true),
|
|
2695
|
+
this.fetchObligation(caps[0].obligationId)
|
|
2696
|
+
]);
|
|
2697
|
+
const rewards = [];
|
|
2698
|
+
const rewardEstimates = /* @__PURE__ */ new Map();
|
|
2699
|
+
for (const dep of obligation.deposits) {
|
|
2700
|
+
const reserve = reserves[dep.reserveIdx];
|
|
2701
|
+
if (!reserve) continue;
|
|
2702
|
+
const ratio = cTokenRatio(reserve);
|
|
2703
|
+
const amount = dep.ctokenAmount * ratio / 10 ** reserve.mintDecimals;
|
|
2704
|
+
const price = reserve.price;
|
|
2705
|
+
const depositUsd = amount * price;
|
|
2706
|
+
for (const rw of reserve.depositPoolRewards) {
|
|
2707
|
+
if (!this.isClaimableReward(rw.coinType)) continue;
|
|
2708
|
+
const rewardReserve = reserves.find((r) => {
|
|
2709
|
+
try {
|
|
2710
|
+
return normalizeStructTag(r.coinType) === normalizeStructTag(rw.coinType);
|
|
2711
|
+
} catch {
|
|
2712
|
+
return false;
|
|
2713
|
+
}
|
|
2714
|
+
});
|
|
2715
|
+
const rewardPrice = rewardReserve?.price ?? 0;
|
|
2716
|
+
const rewardDecimals = rewardReserve?.mintDecimals ?? 9;
|
|
2717
|
+
const durationMs = rw.endTimeMs - rw.startTimeMs;
|
|
2718
|
+
if (durationMs <= 0) continue;
|
|
2719
|
+
const annualTokens = rw.totalRewards / 10 ** rewardDecimals * (MS_PER_YEAR / durationMs);
|
|
2720
|
+
const totalDepositValue = reserve.depositTotalShares / 10 ** reserve.mintDecimals * price;
|
|
2721
|
+
if (totalDepositValue <= 0) continue;
|
|
2722
|
+
const userShare = depositUsd / totalDepositValue;
|
|
2723
|
+
const dailyRewardUsd = annualTokens * rewardPrice / 365 * userShare;
|
|
2724
|
+
rewardEstimates.set(rw.coinType, (rewardEstimates.get(rw.coinType) ?? 0) + dailyRewardUsd);
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2727
|
+
for (const [coinType, dailyUsd] of rewardEstimates) {
|
|
2728
|
+
const symbol = coinType.includes("spring_sui") ? "SPRING_SUI" : coinType.includes("deep::") ? "DEEP" : coinType.split("::").pop() ?? "UNKNOWN";
|
|
2729
|
+
rewards.push({
|
|
2730
|
+
protocol: "suilend",
|
|
2731
|
+
coinType,
|
|
2732
|
+
symbol,
|
|
2733
|
+
amount: 0,
|
|
2734
|
+
estimatedValueUsd: dailyUsd
|
|
2735
|
+
});
|
|
2736
|
+
}
|
|
2737
|
+
return rewards;
|
|
2738
|
+
}
|
|
2739
|
+
async addClaimRewardsToTx(tx, address) {
|
|
2740
|
+
const caps = await this.fetchObligationCaps(address);
|
|
2741
|
+
if (caps.length === 0) return [];
|
|
2742
|
+
const [pkg, reserves, obligation] = await Promise.all([
|
|
2743
|
+
this.resolvePackage(),
|
|
2744
|
+
this.loadReserves(true),
|
|
2745
|
+
this.fetchObligation(caps[0].obligationId)
|
|
2746
|
+
]);
|
|
2747
|
+
const claimsByToken = /* @__PURE__ */ new Map();
|
|
2748
|
+
const claimed = [];
|
|
2749
|
+
for (const dep of obligation.deposits) {
|
|
2750
|
+
const reserve = reserves[dep.reserveIdx];
|
|
2751
|
+
if (!reserve) continue;
|
|
2752
|
+
for (const rw of reserve.depositPoolRewards) {
|
|
2753
|
+
if (!this.isClaimableReward(rw.coinType)) continue;
|
|
2754
|
+
const [coin] = tx.moveCall({
|
|
2755
|
+
target: `${pkg}::lending_market::claim_rewards`,
|
|
2756
|
+
typeArguments: [LENDING_MARKET_TYPE, rw.coinType],
|
|
2757
|
+
arguments: [
|
|
2758
|
+
tx.object(LENDING_MARKET_ID),
|
|
2759
|
+
tx.object(caps[0].id),
|
|
2760
|
+
tx.object(CLOCK2),
|
|
2761
|
+
tx.pure.u64(reserve.arrayIndex),
|
|
2762
|
+
tx.pure.u64(rw.rewardIndex),
|
|
2763
|
+
tx.pure.bool(true)
|
|
2764
|
+
]
|
|
2765
|
+
});
|
|
2766
|
+
const existing = claimsByToken.get(rw.coinType) ?? [];
|
|
2767
|
+
existing.push(coin);
|
|
2768
|
+
claimsByToken.set(rw.coinType, existing);
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
for (const [coinType, coins] of claimsByToken) {
|
|
2772
|
+
if (coins.length > 1) {
|
|
2773
|
+
tx.mergeCoins(coins[0], coins.slice(1));
|
|
2774
|
+
}
|
|
2775
|
+
tx.transferObjects([coins[0]], address);
|
|
2776
|
+
const symbol = coinType.includes("spring_sui") ? "SPRING_SUI" : coinType.includes("deep::") ? "DEEP" : coinType.split("::").pop() ?? "UNKNOWN";
|
|
2777
|
+
claimed.push({
|
|
2778
|
+
protocol: "suilend",
|
|
2779
|
+
coinType,
|
|
2780
|
+
symbol,
|
|
2781
|
+
amount: 0,
|
|
2782
|
+
estimatedValueUsd: 0
|
|
2783
|
+
});
|
|
2784
|
+
}
|
|
2785
|
+
return claimed;
|
|
2786
|
+
}
|
|
2510
2787
|
};
|
|
2511
2788
|
function hasLeadingZeroBits(hash, bits) {
|
|
2512
2789
|
const fullBytes = Math.floor(bits / 8);
|
|
@@ -3632,6 +3909,12 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3632
3909
|
bal.investment = 0;
|
|
3633
3910
|
bal.investmentPnL = 0;
|
|
3634
3911
|
}
|
|
3912
|
+
try {
|
|
3913
|
+
const pendingRewards = await this.getPendingRewards();
|
|
3914
|
+
bal.pendingRewards = pendingRewards.reduce((s, r) => s + r.estimatedValueUsd, 0);
|
|
3915
|
+
} catch {
|
|
3916
|
+
bal.pendingRewards = 0;
|
|
3917
|
+
}
|
|
3635
3918
|
bal.total = bal.available + bal.savings - bal.debt + bal.investment + bal.gasReserve.usdEquiv;
|
|
3636
3919
|
return bal;
|
|
3637
3920
|
}
|
|
@@ -4581,6 +4864,47 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
4581
4864
|
gasMethod: gasResult.gasMethod
|
|
4582
4865
|
};
|
|
4583
4866
|
}
|
|
4867
|
+
// -- Claim Rewards --
|
|
4868
|
+
async getPendingRewards() {
|
|
4869
|
+
const adapters = this.registry.listLending();
|
|
4870
|
+
const results = await Promise.allSettled(
|
|
4871
|
+
adapters.filter((a) => a.getPendingRewards).map((a) => a.getPendingRewards(this._address))
|
|
4872
|
+
);
|
|
4873
|
+
const all = [];
|
|
4874
|
+
for (const r of results) {
|
|
4875
|
+
if (r.status === "fulfilled") all.push(...r.value);
|
|
4876
|
+
}
|
|
4877
|
+
return all;
|
|
4878
|
+
}
|
|
4879
|
+
async claimRewards() {
|
|
4880
|
+
this.enforcer.assertNotLocked();
|
|
4881
|
+
const adapters = this.registry.listLending().filter((a) => a.addClaimRewardsToTx);
|
|
4882
|
+
if (adapters.length === 0) {
|
|
4883
|
+
return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0, gasMethod: "none" };
|
|
4884
|
+
}
|
|
4885
|
+
const tx = new Transaction();
|
|
4886
|
+
tx.setSender(this._address);
|
|
4887
|
+
const allRewards = [];
|
|
4888
|
+
for (const adapter of adapters) {
|
|
4889
|
+
try {
|
|
4890
|
+
const claimed = await adapter.addClaimRewardsToTx(tx, this._address);
|
|
4891
|
+
allRewards.push(...claimed);
|
|
4892
|
+
} catch {
|
|
4893
|
+
}
|
|
4894
|
+
}
|
|
4895
|
+
if (allRewards.length === 0) {
|
|
4896
|
+
return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0, gasMethod: "none" };
|
|
4897
|
+
}
|
|
4898
|
+
const gasResult = await executeWithGas(this.client, this.keypair, async () => tx);
|
|
4899
|
+
return {
|
|
4900
|
+
success: true,
|
|
4901
|
+
tx: gasResult.digest,
|
|
4902
|
+
rewards: allRewards,
|
|
4903
|
+
totalValueUsd: allRewards.reduce((s, r) => s + r.estimatedValueUsd, 0),
|
|
4904
|
+
gasCost: gasResult.gasCostSui,
|
|
4905
|
+
gasMethod: gasResult.gasMethod
|
|
4906
|
+
};
|
|
4907
|
+
}
|
|
4584
4908
|
// -- Strategies --
|
|
4585
4909
|
async investStrategy(params) {
|
|
4586
4910
|
this.enforcer.assertNotLocked();
|