@t2000/sdk 0.17.14 → 0.17.15
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 +281 -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 +281 -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 +329 -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 +329 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { x as AdapterCapability, y as AdapterPositions, z as AdapterTxResult, K as CetusAdapter, O as HealthInfo, L as LendingAdapter, t as LendingRates, Q as NaviAdapter, U as PerpsAdapter, Z as ProtocolDescriptor, _ as ProtocolRegistry, a1 as SuilendAdapter, d as SwapAdapter, a2 as SwapQuote, a5 as allDescriptors, a6 as cetusDescriptor, a9 as naviDescriptor, ac as sentinelDescriptor, af as suilendDescriptor } from '../index-xQEri-Eu.cjs';
|
|
2
2
|
import '@mysten/sui/transactions';
|
|
3
3
|
import '@mysten/sui/jsonRpc';
|
|
4
4
|
import '@mysten/sui/keypairs/ed25519';
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { x as AdapterCapability, y as AdapterPositions, z as AdapterTxResult, K as CetusAdapter, O as HealthInfo, L as LendingAdapter, t as LendingRates, Q as NaviAdapter, U as PerpsAdapter, Z as ProtocolDescriptor, _ as ProtocolRegistry, a1 as SuilendAdapter, d as SwapAdapter, a2 as SwapQuote, a5 as allDescriptors, a6 as cetusDescriptor, a9 as naviDescriptor, ac as sentinelDescriptor, af as suilendDescriptor } from '../index-xQEri-Eu.js';
|
|
2
2
|
import '@mysten/sui/transactions';
|
|
3
3
|
import '@mysten/sui/jsonRpc';
|
|
4
4
|
import '@mysten/sui/keypairs/ed25519';
|
package/dist/adapters/index.js
CHANGED
|
@@ -865,6 +865,173 @@ async function maxBorrowAmount(client, addressOrKeypair) {
|
|
|
865
865
|
const maxAmount = Math.max(0, hf.supplied * ltv / MIN_HEALTH_FACTOR - hf.borrowed);
|
|
866
866
|
return { maxAmount, healthFactorAfter: MIN_HEALTH_FACTOR, currentHF: hf.healthFactor };
|
|
867
867
|
}
|
|
868
|
+
var CERT_TYPE = "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT";
|
|
869
|
+
var DEEP_TYPE = "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP";
|
|
870
|
+
var REWARD_FUNDS = {
|
|
871
|
+
[CERT_TYPE]: "0x7093cf7549d5e5b35bfde2177223d1050f71655c7f676a5e610ee70eb4d93b5c",
|
|
872
|
+
[DEEP_TYPE]: "0xc889d78b634f954979e80e622a2ae0fece824c0f6d9590044378a2563035f32f"
|
|
873
|
+
};
|
|
874
|
+
var REWARD_SYMBOLS = {
|
|
875
|
+
[CERT_TYPE]: "vSUI",
|
|
876
|
+
[DEEP_TYPE]: "DEEP"
|
|
877
|
+
};
|
|
878
|
+
var incentiveRulesCache = null;
|
|
879
|
+
async function getIncentiveRules(client) {
|
|
880
|
+
if (incentiveRulesCache && Date.now() - incentiveRulesCache.ts < CACHE_TTL) {
|
|
881
|
+
return incentiveRulesCache.data;
|
|
882
|
+
}
|
|
883
|
+
const [pools, obj] = await Promise.all([
|
|
884
|
+
getPools(),
|
|
885
|
+
client.getObject({
|
|
886
|
+
id: "0x62982dad27fb10bb314b3384d5de8d2ac2d72ab2dbeae5d801dbdb9efa816c80",
|
|
887
|
+
options: { showContent: true }
|
|
888
|
+
})
|
|
889
|
+
]);
|
|
890
|
+
const rewardCoinMap = /* @__PURE__ */ new Map();
|
|
891
|
+
for (const pool of pools) {
|
|
892
|
+
const ct = (pool.suiCoinType || pool.coinType || "").toLowerCase();
|
|
893
|
+
const suffix = ct.split("::").slice(1).join("::");
|
|
894
|
+
const coins = pool.supplyIncentiveApyInfo?.rewardCoin;
|
|
895
|
+
if (Array.isArray(coins) && coins.length > 0) {
|
|
896
|
+
rewardCoinMap.set(suffix, coins[0]);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
const result = /* @__PURE__ */ new Map();
|
|
900
|
+
if (obj.data?.content?.dataType !== "moveObject") {
|
|
901
|
+
incentiveRulesCache = { data: result, ts: Date.now() };
|
|
902
|
+
return result;
|
|
903
|
+
}
|
|
904
|
+
const fields = obj.data.content.fields;
|
|
905
|
+
const poolsObj = fields.pools;
|
|
906
|
+
const entries = poolsObj?.fields?.contents;
|
|
907
|
+
if (!Array.isArray(entries)) {
|
|
908
|
+
incentiveRulesCache = { data: result, ts: Date.now() };
|
|
909
|
+
return result;
|
|
910
|
+
}
|
|
911
|
+
for (const entry of entries) {
|
|
912
|
+
const ef = entry?.fields;
|
|
913
|
+
if (!ef) continue;
|
|
914
|
+
const key = String(ef.key ?? "");
|
|
915
|
+
const value = ef.value;
|
|
916
|
+
const rules = value?.fields?.rules;
|
|
917
|
+
const ruleEntries = rules?.fields?.contents;
|
|
918
|
+
if (!Array.isArray(ruleEntries)) continue;
|
|
919
|
+
const ruleIds = ruleEntries.map((re) => {
|
|
920
|
+
const rf = re?.fields;
|
|
921
|
+
return String(rf?.key ?? "");
|
|
922
|
+
}).filter(Boolean);
|
|
923
|
+
const suffix = key.split("::").slice(1).join("::").toLowerCase();
|
|
924
|
+
const full = key.toLowerCase();
|
|
925
|
+
const rewardCoin = rewardCoinMap.get(suffix) ?? rewardCoinMap.get(full) ?? null;
|
|
926
|
+
result.set(key, { ruleIds, rewardCoinType: rewardCoin });
|
|
927
|
+
}
|
|
928
|
+
incentiveRulesCache = { data: result, ts: Date.now() };
|
|
929
|
+
return result;
|
|
930
|
+
}
|
|
931
|
+
function stripPrefix(coinType) {
|
|
932
|
+
return coinType.replace(/^0x0*/, "");
|
|
933
|
+
}
|
|
934
|
+
async function getPendingRewards(client, address) {
|
|
935
|
+
const [pools, states, rules] = await Promise.all([
|
|
936
|
+
getPools(),
|
|
937
|
+
getUserState(client, address),
|
|
938
|
+
getIncentiveRules(client)
|
|
939
|
+
]);
|
|
940
|
+
const rewards = [];
|
|
941
|
+
const deposited = states.filter((s) => s.supplyBalance > 0n);
|
|
942
|
+
if (deposited.length === 0) return rewards;
|
|
943
|
+
const rewardTotals = /* @__PURE__ */ new Map();
|
|
944
|
+
for (const state of deposited) {
|
|
945
|
+
const pool = pools.find((p) => p.id === state.assetId);
|
|
946
|
+
if (!pool) continue;
|
|
947
|
+
const boostedApr = parseFloat(pool.supplyIncentiveApyInfo?.boostedApr ?? "0");
|
|
948
|
+
if (boostedApr <= 0) continue;
|
|
949
|
+
const rewardCoins = pool.supplyIncentiveApyInfo?.rewardCoin;
|
|
950
|
+
if (!Array.isArray(rewardCoins) || rewardCoins.length === 0) continue;
|
|
951
|
+
const rewardType = rewardCoins[0];
|
|
952
|
+
const supplyBal = compoundBalance(state.supplyBalance, pool.currentSupplyIndex, pool);
|
|
953
|
+
const price = pool.token?.price ?? 0;
|
|
954
|
+
const depositUsd = supplyBal * price;
|
|
955
|
+
const annualRewardUsd = depositUsd * (boostedApr / 100);
|
|
956
|
+
const estimatedUsd = annualRewardUsd / 365;
|
|
957
|
+
rewardTotals.set(rewardType, (rewardTotals.get(rewardType) ?? 0) + estimatedUsd);
|
|
958
|
+
}
|
|
959
|
+
for (const [coinType, dailyUsd] of rewardTotals) {
|
|
960
|
+
if (dailyUsd < 1e-3) continue;
|
|
961
|
+
rewards.push({
|
|
962
|
+
protocol: "navi",
|
|
963
|
+
coinType,
|
|
964
|
+
symbol: REWARD_SYMBOLS[coinType] ?? coinType.split("::").pop() ?? "UNKNOWN",
|
|
965
|
+
amount: 0,
|
|
966
|
+
estimatedValueUsd: dailyUsd
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
return rewards;
|
|
970
|
+
}
|
|
971
|
+
async function addClaimRewardsToTx(tx, client, address) {
|
|
972
|
+
const [config, pools, states, rules] = await Promise.all([
|
|
973
|
+
getConfig(),
|
|
974
|
+
getPools(),
|
|
975
|
+
getUserState(client, address),
|
|
976
|
+
getIncentiveRules(client)
|
|
977
|
+
]);
|
|
978
|
+
const deposited = states.filter((s) => s.supplyBalance > 0n);
|
|
979
|
+
if (deposited.length === 0) return [];
|
|
980
|
+
const claimGroups = /* @__PURE__ */ new Map();
|
|
981
|
+
for (const state of deposited) {
|
|
982
|
+
const pool = pools.find((p) => p.id === state.assetId);
|
|
983
|
+
if (!pool) continue;
|
|
984
|
+
const boostedApr = parseFloat(pool.supplyIncentiveApyInfo?.boostedApr ?? "0");
|
|
985
|
+
if (boostedApr <= 0) continue;
|
|
986
|
+
const rewardCoins = pool.supplyIncentiveApyInfo?.rewardCoin;
|
|
987
|
+
if (!Array.isArray(rewardCoins) || rewardCoins.length === 0) continue;
|
|
988
|
+
const rewardType = rewardCoins[0];
|
|
989
|
+
const fundId = REWARD_FUNDS[rewardType];
|
|
990
|
+
if (!fundId) continue;
|
|
991
|
+
const coinType = pool.suiCoinType || pool.coinType || "";
|
|
992
|
+
const strippedType = stripPrefix(coinType);
|
|
993
|
+
const ruleData = Array.from(rules.entries()).find(
|
|
994
|
+
([key]) => stripPrefix(key) === strippedType || key.split("::").slice(1).join("::").toLowerCase() === coinType.split("::").slice(1).join("::").toLowerCase()
|
|
995
|
+
);
|
|
996
|
+
if (!ruleData || ruleData[1].ruleIds.length === 0) continue;
|
|
997
|
+
const group = claimGroups.get(rewardType) ?? { assets: [], ruleIds: [] };
|
|
998
|
+
for (const ruleId of ruleData[1].ruleIds) {
|
|
999
|
+
group.assets.push(strippedType);
|
|
1000
|
+
group.ruleIds.push(ruleId);
|
|
1001
|
+
}
|
|
1002
|
+
claimGroups.set(rewardType, group);
|
|
1003
|
+
}
|
|
1004
|
+
const claimed = [];
|
|
1005
|
+
for (const [rewardType, { assets, ruleIds }] of claimGroups) {
|
|
1006
|
+
const fundId = REWARD_FUNDS[rewardType];
|
|
1007
|
+
const [balance] = tx.moveCall({
|
|
1008
|
+
target: `${config.package}::incentive_v3::claim_reward`,
|
|
1009
|
+
typeArguments: [rewardType],
|
|
1010
|
+
arguments: [
|
|
1011
|
+
tx.object(CLOCK),
|
|
1012
|
+
tx.object(config.incentiveV3),
|
|
1013
|
+
tx.object(config.storage),
|
|
1014
|
+
tx.object(fundId),
|
|
1015
|
+
tx.pure(bcs.vector(bcs.string()).serialize(assets)),
|
|
1016
|
+
tx.pure(bcs.vector(bcs.Address).serialize(ruleIds))
|
|
1017
|
+
]
|
|
1018
|
+
});
|
|
1019
|
+
const [coin] = tx.moveCall({
|
|
1020
|
+
target: "0x2::coin::from_balance",
|
|
1021
|
+
typeArguments: [rewardType],
|
|
1022
|
+
arguments: [balance]
|
|
1023
|
+
});
|
|
1024
|
+
tx.transferObjects([coin], address);
|
|
1025
|
+
claimed.push({
|
|
1026
|
+
protocol: "navi",
|
|
1027
|
+
coinType: rewardType,
|
|
1028
|
+
symbol: REWARD_SYMBOLS[rewardType] ?? "UNKNOWN",
|
|
1029
|
+
amount: 0,
|
|
1030
|
+
estimatedValueUsd: 0
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
return claimed;
|
|
1034
|
+
}
|
|
868
1035
|
|
|
869
1036
|
// src/adapters/navi.ts
|
|
870
1037
|
var descriptor = {
|
|
@@ -952,6 +1119,12 @@ var NaviAdapter = class {
|
|
|
952
1119
|
const normalized = normalizeAsset(asset);
|
|
953
1120
|
return addRepayToTx(tx, this.client, address, coin, { asset: normalized });
|
|
954
1121
|
}
|
|
1122
|
+
async getPendingRewards(address) {
|
|
1123
|
+
return getPendingRewards(this.client, address);
|
|
1124
|
+
}
|
|
1125
|
+
async addClaimRewardsToTx(tx, address) {
|
|
1126
|
+
return addClaimRewardsToTx(tx, this.client, address);
|
|
1127
|
+
}
|
|
955
1128
|
};
|
|
956
1129
|
var DEFAULT_SLIPPAGE_BPS = 300;
|
|
957
1130
|
function createAggregatorClient(client, signer) {
|
|
@@ -1276,15 +1449,17 @@ function parseReserve(raw, index) {
|
|
|
1276
1449
|
const dMgr = f(r.deposits_pool_reward_manager);
|
|
1277
1450
|
const rawRewards = Array.isArray(dMgr?.pool_rewards) ? dMgr.pool_rewards : [];
|
|
1278
1451
|
const now = Date.now();
|
|
1279
|
-
const depositPoolRewards = rawRewards.
|
|
1452
|
+
const depositPoolRewards = rawRewards.map((rw, idx) => {
|
|
1453
|
+
if (rw === null) return null;
|
|
1280
1454
|
const rwf = f(rw);
|
|
1281
1455
|
return {
|
|
1282
1456
|
coinType: str(f(rwf.coin_type)?.name),
|
|
1283
1457
|
totalRewards: num(rwf.total_rewards),
|
|
1284
1458
|
startTimeMs: num(rwf.start_time_ms),
|
|
1285
|
-
endTimeMs: num(rwf.end_time_ms)
|
|
1459
|
+
endTimeMs: num(rwf.end_time_ms),
|
|
1460
|
+
rewardIndex: idx
|
|
1286
1461
|
};
|
|
1287
|
-
}).filter((rw) => rw.endTimeMs > now && rw.totalRewards > 0);
|
|
1462
|
+
}).filter((rw) => rw !== null && rw.endTimeMs > now && rw.totalRewards > 0);
|
|
1288
1463
|
return {
|
|
1289
1464
|
coinType: str(coinTypeField?.name),
|
|
1290
1465
|
mintDecimals: num(r.mint_decimals),
|
|
@@ -1835,6 +2010,109 @@ var SuilendAdapter = class {
|
|
|
1835
2010
|
}
|
|
1836
2011
|
return all;
|
|
1837
2012
|
}
|
|
2013
|
+
// -- Claim Rewards --------------------------------------------------------
|
|
2014
|
+
isClaimableReward(coinType) {
|
|
2015
|
+
const ct = coinType.toLowerCase();
|
|
2016
|
+
return ct.includes("spring_sui") || ct.includes("deep::deep") || ct.includes("cert::cert");
|
|
2017
|
+
}
|
|
2018
|
+
async getPendingRewards(address) {
|
|
2019
|
+
const caps = await this.fetchObligationCaps(address);
|
|
2020
|
+
if (caps.length === 0) return [];
|
|
2021
|
+
const [reserves, obligation] = await Promise.all([
|
|
2022
|
+
this.loadReserves(true),
|
|
2023
|
+
this.fetchObligation(caps[0].obligationId)
|
|
2024
|
+
]);
|
|
2025
|
+
const rewards = [];
|
|
2026
|
+
const rewardEstimates = /* @__PURE__ */ new Map();
|
|
2027
|
+
for (const dep of obligation.deposits) {
|
|
2028
|
+
const reserve = reserves[dep.reserveIdx];
|
|
2029
|
+
if (!reserve) continue;
|
|
2030
|
+
const ratio = cTokenRatio(reserve);
|
|
2031
|
+
const amount = dep.ctokenAmount * ratio / 10 ** reserve.mintDecimals;
|
|
2032
|
+
const price = reserve.price;
|
|
2033
|
+
const depositUsd = amount * price;
|
|
2034
|
+
for (const rw of reserve.depositPoolRewards) {
|
|
2035
|
+
if (!this.isClaimableReward(rw.coinType)) continue;
|
|
2036
|
+
const rewardReserve = reserves.find((r) => {
|
|
2037
|
+
try {
|
|
2038
|
+
return normalizeStructTag(r.coinType) === normalizeStructTag(rw.coinType);
|
|
2039
|
+
} catch {
|
|
2040
|
+
return false;
|
|
2041
|
+
}
|
|
2042
|
+
});
|
|
2043
|
+
const rewardPrice = rewardReserve?.price ?? 0;
|
|
2044
|
+
const rewardDecimals = rewardReserve?.mintDecimals ?? 9;
|
|
2045
|
+
const durationMs = rw.endTimeMs - rw.startTimeMs;
|
|
2046
|
+
if (durationMs <= 0) continue;
|
|
2047
|
+
const annualTokens = rw.totalRewards / 10 ** rewardDecimals * (MS_PER_YEAR / durationMs);
|
|
2048
|
+
const totalDepositValue = reserve.depositTotalShares / 10 ** reserve.mintDecimals * price;
|
|
2049
|
+
if (totalDepositValue <= 0) continue;
|
|
2050
|
+
const userShare = depositUsd / totalDepositValue;
|
|
2051
|
+
const dailyRewardUsd = annualTokens * rewardPrice / 365 * userShare;
|
|
2052
|
+
rewardEstimates.set(rw.coinType, (rewardEstimates.get(rw.coinType) ?? 0) + dailyRewardUsd);
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
for (const [coinType, dailyUsd] of rewardEstimates) {
|
|
2056
|
+
if (dailyUsd < 1e-3) continue;
|
|
2057
|
+
const symbol = coinType.includes("spring_sui") ? "SPRING_SUI" : coinType.includes("deep::") ? "DEEP" : coinType.split("::").pop() ?? "UNKNOWN";
|
|
2058
|
+
rewards.push({
|
|
2059
|
+
protocol: "suilend",
|
|
2060
|
+
coinType,
|
|
2061
|
+
symbol,
|
|
2062
|
+
amount: 0,
|
|
2063
|
+
estimatedValueUsd: dailyUsd
|
|
2064
|
+
});
|
|
2065
|
+
}
|
|
2066
|
+
return rewards;
|
|
2067
|
+
}
|
|
2068
|
+
async addClaimRewardsToTx(tx, address) {
|
|
2069
|
+
const caps = await this.fetchObligationCaps(address);
|
|
2070
|
+
if (caps.length === 0) return [];
|
|
2071
|
+
const [pkg, reserves, obligation] = await Promise.all([
|
|
2072
|
+
this.resolvePackage(),
|
|
2073
|
+
this.loadReserves(true),
|
|
2074
|
+
this.fetchObligation(caps[0].obligationId)
|
|
2075
|
+
]);
|
|
2076
|
+
const claimsByToken = /* @__PURE__ */ new Map();
|
|
2077
|
+
const claimed = [];
|
|
2078
|
+
for (const dep of obligation.deposits) {
|
|
2079
|
+
const reserve = reserves[dep.reserveIdx];
|
|
2080
|
+
if (!reserve) continue;
|
|
2081
|
+
for (const rw of reserve.depositPoolRewards) {
|
|
2082
|
+
if (!this.isClaimableReward(rw.coinType)) continue;
|
|
2083
|
+
const [coin] = tx.moveCall({
|
|
2084
|
+
target: `${pkg}::lending_market::claim_rewards`,
|
|
2085
|
+
typeArguments: [LENDING_MARKET_TYPE, rw.coinType],
|
|
2086
|
+
arguments: [
|
|
2087
|
+
tx.object(LENDING_MARKET_ID),
|
|
2088
|
+
tx.object(caps[0].id),
|
|
2089
|
+
tx.object(CLOCK2),
|
|
2090
|
+
tx.pure.u64(reserve.arrayIndex),
|
|
2091
|
+
tx.pure.u64(rw.rewardIndex),
|
|
2092
|
+
tx.pure.bool(true)
|
|
2093
|
+
]
|
|
2094
|
+
});
|
|
2095
|
+
const existing = claimsByToken.get(rw.coinType) ?? [];
|
|
2096
|
+
existing.push(coin);
|
|
2097
|
+
claimsByToken.set(rw.coinType, existing);
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
for (const [coinType, coins] of claimsByToken) {
|
|
2101
|
+
if (coins.length > 1) {
|
|
2102
|
+
tx.mergeCoins(coins[0], coins.slice(1));
|
|
2103
|
+
}
|
|
2104
|
+
tx.transferObjects([coins[0]], address);
|
|
2105
|
+
const symbol = coinType.includes("spring_sui") ? "SPRING_SUI" : coinType.includes("deep::") ? "DEEP" : coinType.split("::").pop() ?? "UNKNOWN";
|
|
2106
|
+
claimed.push({
|
|
2107
|
+
protocol: "suilend",
|
|
2108
|
+
coinType,
|
|
2109
|
+
symbol,
|
|
2110
|
+
amount: 0,
|
|
2111
|
+
estimatedValueUsd: 0
|
|
2112
|
+
});
|
|
2113
|
+
}
|
|
2114
|
+
return claimed;
|
|
2115
|
+
}
|
|
1838
2116
|
};
|
|
1839
2117
|
var descriptor4 = {
|
|
1840
2118
|
id: "sentinel",
|