@1delta/margin-fetcher-sol 0.0.2 → 0.0.4
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/index.d.mts +344 -217
- package/dist/index.d.ts +344 -217
- package/dist/index.js +274 -143
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +135 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -309,6 +309,7 @@ __export(index_exports, {
|
|
|
309
309
|
decodeHumaPoolConfig: () => decodeHumaPoolConfig,
|
|
310
310
|
decodeHumaPoolState: () => decodeHumaPoolState,
|
|
311
311
|
decodeHumaRedemptionRequest: () => decodeHumaRedemptionRequest,
|
|
312
|
+
decodeJlRateModel: () => decodeJlRateModel,
|
|
312
313
|
decodeJuniorUnlockShare: () => decodeJuniorUnlockShare,
|
|
313
314
|
decodeJupFlashloanAdmin: () => decodeJupFlashloanAdmin,
|
|
314
315
|
decodeKaminoObligation: () => decodeKaminoObligation,
|
|
@@ -508,6 +509,7 @@ __export(index_exports, {
|
|
|
508
509
|
readHumaChainState: () => readHumaChainState,
|
|
509
510
|
readHumaLenderState: () => readHumaLenderState,
|
|
510
511
|
readHumaRedemptionRequests: () => readHumaRedemptionRequests,
|
|
512
|
+
readJlLayerIrms: () => readJlLayerIrms,
|
|
511
513
|
readJlNextVaultId: () => readJlNextVaultId,
|
|
512
514
|
readJupFlashAssets: () => readJupFlashAssets,
|
|
513
515
|
readJupFlashAvailable: () => readJupFlashAvailable,
|
|
@@ -8397,6 +8399,8 @@ var RESERVE = {
|
|
|
8397
8399
|
maxLiquidationBonusBps: 4876,
|
|
8398
8400
|
originationFeeSf: 4896,
|
|
8399
8401
|
flashLoanFeeSf: 4904,
|
|
8402
|
+
// config.borrowRateCurve — 11 × CurvePoint { utilizationRateBps u32, borrowRateBps u32 }, after fees' 8 padding bytes
|
|
8403
|
+
borrowRateCurve: 4920,
|
|
8400
8404
|
borrowFactorPct: 5008,
|
|
8401
8405
|
depositLimit: 5016,
|
|
8402
8406
|
borrowLimit: 5024,
|
|
@@ -8539,6 +8543,14 @@ function readKlendReserveChain(reserve, data) {
|
|
|
8539
8543
|
debtWithdrawalCap: withdrawalCap(data, RESERVE.debtWithdrawalCap),
|
|
8540
8544
|
disableUsageAsCollOutsideEmode: data[RESERVE.disableUsageAsCollOutsideEmode] !== 0,
|
|
8541
8545
|
utilizationLimitBlockBorrowingAbovePct: data[RESERVE.utilizationLimitBlockBorrowingAbovePct],
|
|
8546
|
+
borrowRateCurve: Array.from({ length: 11 }, (_, i) => {
|
|
8547
|
+
const v = new DataView(data.buffer, data.byteOffset);
|
|
8548
|
+
const off = RESERVE.borrowRateCurve + 8 * i;
|
|
8549
|
+
return [
|
|
8550
|
+
v.getUint32(off, true) / 1e4,
|
|
8551
|
+
v.getUint32(off + 4, true) / 1e4
|
|
8552
|
+
];
|
|
8553
|
+
}),
|
|
8542
8554
|
borrowLimitOutsideElevationGroup: u64(
|
|
8543
8555
|
data,
|
|
8544
8556
|
RESERVE.borrowLimitOutsideElevationGroup
|
|
@@ -9035,6 +9047,15 @@ function exchangeRateOf(inp) {
|
|
|
9035
9047
|
if (!t || !s || t.num <= 0n || s.num <= 0n) return { num: 1n, den: 1n };
|
|
9036
9048
|
return { num: t.num * s.den, den: t.den * s.num };
|
|
9037
9049
|
}
|
|
9050
|
+
function dedupeKnots(knots) {
|
|
9051
|
+
const out = [];
|
|
9052
|
+
for (const k of knots) {
|
|
9053
|
+
const last = out[out.length - 1];
|
|
9054
|
+
if (last && last[0] === k[0] && last[1] === k[1]) continue;
|
|
9055
|
+
out.push(k);
|
|
9056
|
+
}
|
|
9057
|
+
return out;
|
|
9058
|
+
}
|
|
9038
9059
|
function convertKaminoReserve(inp, ctx) {
|
|
9039
9060
|
const { stats, metrics, detail, chain } = inp;
|
|
9040
9061
|
const mint = chain?.mint ?? stats.token;
|
|
@@ -9132,7 +9153,12 @@ function convertKaminoReserve(inp, ctx) {
|
|
|
9132
9153
|
interestRateBasis: stats.interestRateBasis,
|
|
9133
9154
|
protocolTakeRatePct: stats.protocolTakeRatePct,
|
|
9134
9155
|
hostFixedInterestRateBps: stats.hostFixedInterestRateBps,
|
|
9135
|
-
borrowCurve: detail.borrowCurve,
|
|
9156
|
+
borrowCurve: chain ? dedupeKnots(chain.borrowRateCurve) : detail.borrowCurve,
|
|
9157
|
+
borrowCurveSource: chain ? "chain" : "api",
|
|
9158
|
+
...stats.interestRateBasis === "legacy" && ctx.slotSeconds ? { slotSeconds: ctx.slotSeconds } : {},
|
|
9159
|
+
...chain ? {
|
|
9160
|
+
utilizationLimitBlockBorrowingAbovePct: chain.utilizationLimitBlockBorrowingAbovePct
|
|
9161
|
+
} : {},
|
|
9136
9162
|
autoDeleverage: stats.autoDeleverage,
|
|
9137
9163
|
source: chain ? "chain" : "api",
|
|
9138
9164
|
maxLiquidationBonus: chain ? chain.maxLiquidationBonusBps / 1e4 : num(detail.maxLiquidationBonus),
|
|
@@ -9178,6 +9204,7 @@ function convertKaminoMarket(inp) {
|
|
|
9178
9204
|
closeFactor,
|
|
9179
9205
|
chainMarket: inp.chainMarket,
|
|
9180
9206
|
slot: inp.slot,
|
|
9207
|
+
slotSeconds: inp.slotSeconds,
|
|
9181
9208
|
tokenList: inp.tokenList
|
|
9182
9209
|
});
|
|
9183
9210
|
data[row.marketUid] = row;
|
|
@@ -9193,6 +9220,7 @@ function convertKaminoMarket(inp) {
|
|
|
9193
9220
|
}
|
|
9194
9221
|
|
|
9195
9222
|
// src/lending/public-data/kamino/fetchPublic.ts
|
|
9223
|
+
var import_svm_kit2 = require("@1delta/svm-kit");
|
|
9196
9224
|
async function fetchKaminoPublic(opts = {}) {
|
|
9197
9225
|
const api = createKaminoApi(opts);
|
|
9198
9226
|
const { markets, metricsByMarket } = await listServedMarkets(api, opts);
|
|
@@ -9259,6 +9287,7 @@ async function fetchKaminoPublic(opts = {}) {
|
|
|
9259
9287
|
return false;
|
|
9260
9288
|
});
|
|
9261
9289
|
const rpc = opts.rpc;
|
|
9290
|
+
const slotSeconds = opts.slotSeconds ?? (rpc ? await (0, import_svm_kit2.measureSlotSeconds)(rpc) : void 0);
|
|
9262
9291
|
const chainReads = await Promise.all(
|
|
9263
9292
|
served.map(async (mr) => {
|
|
9264
9293
|
if (!rpc) return void 0;
|
|
@@ -9291,7 +9320,8 @@ async function fetchKaminoPublic(opts = {}) {
|
|
|
9291
9320
|
reserves,
|
|
9292
9321
|
...chain?.market ? { chainMarket: chain.market, slot: chain.slot } : {},
|
|
9293
9322
|
leveragePairs: mr.leveragePairs,
|
|
9294
|
-
tokenList: opts.tokenList
|
|
9323
|
+
tokenList: opts.tokenList,
|
|
9324
|
+
slotSeconds
|
|
9295
9325
|
});
|
|
9296
9326
|
out[conv.lenderKey] = {
|
|
9297
9327
|
chainId: conv.chainId,
|
|
@@ -9345,7 +9375,7 @@ init_types();
|
|
|
9345
9375
|
init_lenders();
|
|
9346
9376
|
|
|
9347
9377
|
// src/lending/public-data/jupiter-lend/onchain.ts
|
|
9348
|
-
var
|
|
9378
|
+
var import_svm_kit4 = require("@1delta/svm-kit");
|
|
9349
9379
|
|
|
9350
9380
|
// src/lending/public-data/jupiter-lend/idl/vaults-accounts.json
|
|
9351
9381
|
var vaults_accounts_default = {
|
|
@@ -10177,7 +10207,7 @@ var vaults_accounts_default = {
|
|
|
10177
10207
|
};
|
|
10178
10208
|
|
|
10179
10209
|
// src/lending/public-data/jupiter-lend/flashloan.ts
|
|
10180
|
-
var
|
|
10210
|
+
var import_svm_kit3 = require("@1delta/svm-kit");
|
|
10181
10211
|
|
|
10182
10212
|
// src/lending/public-data/jupiter-lend/idl/flashloan.json
|
|
10183
10213
|
var flashloan_default = {
|
|
@@ -10753,27 +10783,27 @@ var JUP_LIQUIDITY_PROGRAMS = {
|
|
|
10753
10783
|
};
|
|
10754
10784
|
var utf82 = (s) => new TextEncoder().encode(s);
|
|
10755
10785
|
var pk2 = (address) => {
|
|
10756
|
-
const b = (0,
|
|
10786
|
+
const b = (0, import_svm_kit3.decodeBase58)(address);
|
|
10757
10787
|
if (!b || b.length !== 32) throw new Error(`not a pubkey: ${address}`);
|
|
10758
10788
|
return b;
|
|
10759
10789
|
};
|
|
10760
|
-
var jupFlashloanAdmin = async (market = "main") => (await (0,
|
|
10790
|
+
var jupFlashloanAdmin = async (market = "main") => (await (0, import_svm_kit3.findProgramAddress)(
|
|
10761
10791
|
[utf82("flashloan_admin")],
|
|
10762
10792
|
JUP_FLASHLOAN_PROGRAMS[market]
|
|
10763
10793
|
)).address;
|
|
10764
|
-
var jupLiquidity = async (market = "main") => (await (0,
|
|
10794
|
+
var jupLiquidity = async (market = "main") => (await (0, import_svm_kit3.findProgramAddress)(
|
|
10765
10795
|
[utf82("liquidity")],
|
|
10766
10796
|
JUP_LIQUIDITY_PROGRAMS[market]
|
|
10767
10797
|
)).address;
|
|
10768
|
-
var jupLiquidityReserve = async (mint, market = "main") => (await (0,
|
|
10798
|
+
var jupLiquidityReserve = async (mint, market = "main") => (await (0, import_svm_kit3.findProgramAddress)(
|
|
10769
10799
|
[utf82("reserve"), pk2(mint)],
|
|
10770
10800
|
JUP_LIQUIDITY_PROGRAMS[market]
|
|
10771
10801
|
)).address;
|
|
10772
|
-
var jupRateModel = async (mint, market = "main") => (await (0,
|
|
10802
|
+
var jupRateModel = async (mint, market = "main") => (await (0, import_svm_kit3.findProgramAddress)(
|
|
10773
10803
|
[utf82("rate_model"), pk2(mint)],
|
|
10774
10804
|
JUP_LIQUIDITY_PROGRAMS[market]
|
|
10775
10805
|
)).address;
|
|
10776
|
-
var jupFlashBorrowPosition = async (mint, market = "main") => (await (0,
|
|
10806
|
+
var jupFlashBorrowPosition = async (mint, market = "main") => (await (0, import_svm_kit3.findProgramAddress)(
|
|
10777
10807
|
[
|
|
10778
10808
|
utf82("user_borrow_position"),
|
|
10779
10809
|
pk2(mint),
|
|
@@ -10781,9 +10811,9 @@ var jupFlashBorrowPosition = async (mint, market = "main") => (await (0, import_
|
|
|
10781
10811
|
],
|
|
10782
10812
|
JUP_LIQUIDITY_PROGRAMS[market]
|
|
10783
10813
|
)).address;
|
|
10784
|
-
var jupLiquidityVault = async (mint, tokenProgram, market = "main") => (0,
|
|
10814
|
+
var jupLiquidityVault = async (mint, tokenProgram, market = "main") => (0, import_svm_kit3.getAssociatedTokenAddress)(await jupLiquidity(market), mint, tokenProgram);
|
|
10785
10815
|
function decodeJupFlashloanAdmin(data) {
|
|
10786
|
-
const a = (0,
|
|
10816
|
+
const a = (0, import_svm_kit3.decodeIdlAccount)(JUP_FLASHLOAN_IDL, "FlashloanAdmin", data);
|
|
10787
10817
|
return {
|
|
10788
10818
|
authority: a.authority,
|
|
10789
10819
|
liquidityProgram: a.liquidity_program,
|
|
@@ -10799,7 +10829,7 @@ async function readJupFlashloanAdmin(rpc, market = "main") {
|
|
|
10799
10829
|
const { accounts } = await rpc.readAccounts([address], { encoding: "base64" });
|
|
10800
10830
|
const a = accounts[0];
|
|
10801
10831
|
if (!a || a.owner !== JUP_FLASHLOAN_PROGRAMS[market]) return null;
|
|
10802
|
-
return decodeJupFlashloanAdmin((0,
|
|
10832
|
+
return decodeJupFlashloanAdmin((0, import_svm_kit3.fromBase64)(a.data[0]));
|
|
10803
10833
|
}
|
|
10804
10834
|
async function readJupFlashAssets(rpc, market = "main") {
|
|
10805
10835
|
const admin = await jupFlashloanAdmin(market);
|
|
@@ -10816,7 +10846,7 @@ async function readJupFlashAssets(rpc, market = "main") {
|
|
|
10816
10846
|
{ accounts: 1 }
|
|
10817
10847
|
);
|
|
10818
10848
|
const mints = /* @__PURE__ */ new Set();
|
|
10819
|
-
for (const r of rows) mints.add((0,
|
|
10849
|
+
for (const r of rows) mints.add((0, import_svm_kit3.encodeBase58)((0, import_svm_kit3.fromBase64)(r.account.data[0])));
|
|
10820
10850
|
return [...mints];
|
|
10821
10851
|
}
|
|
10822
10852
|
async function readJupFlashAvailable(rpc, mint, tokenProgram, market = "main") {
|
|
@@ -10849,22 +10879,22 @@ var u16le = (n) => new Uint8Array([n & 255, n >> 8 & 255]);
|
|
|
10849
10879
|
var big = (v) => BigInt(v ?? 0);
|
|
10850
10880
|
var maxB = (a, b) => a > b ? a : b;
|
|
10851
10881
|
var minB = (a, b) => a < b ? a : b;
|
|
10852
|
-
var jlVaultConfigPda = async (vaultId, market = "main") => (await (0,
|
|
10882
|
+
var jlVaultConfigPda = async (vaultId, market = "main") => (await (0, import_svm_kit4.findProgramAddress)(
|
|
10853
10883
|
[utf83("vault_config"), u16le(vaultId)],
|
|
10854
10884
|
JUP_VAULTS_PROGRAMS[market]
|
|
10855
10885
|
)).address;
|
|
10856
|
-
var jlVaultStatePda = async (vaultId, market = "main") => (await (0,
|
|
10886
|
+
var jlVaultStatePda = async (vaultId, market = "main") => (await (0, import_svm_kit4.findProgramAddress)(
|
|
10857
10887
|
[utf83("vault_state"), u16le(vaultId)],
|
|
10858
10888
|
JUP_VAULTS_PROGRAMS[market]
|
|
10859
10889
|
)).address;
|
|
10860
|
-
var jlVaultAdminPda = async (market = "main") => (await (0,
|
|
10861
|
-
var liq = async (seeds, market) => (await (0,
|
|
10890
|
+
var jlVaultAdminPda = async (market = "main") => (await (0, import_svm_kit4.findProgramAddress)([utf83("vault_admin")], JUP_VAULTS_PROGRAMS[market])).address;
|
|
10891
|
+
var liq = async (seeds, market) => (await (0, import_svm_kit4.findProgramAddress)(seeds, JUP_LIQUIDITY_PROGRAMS[market])).address;
|
|
10862
10892
|
var pk3 = async (a) => {
|
|
10863
|
-
const b = (0,
|
|
10893
|
+
const b = (0, import_svm_kit4.decodeBase58)(a);
|
|
10864
10894
|
if (!b || b.length !== 32) throw new Error(`not a pubkey: ${a}`);
|
|
10865
10895
|
return b;
|
|
10866
10896
|
};
|
|
10867
|
-
var dec = (name, data) => (0,
|
|
10897
|
+
var dec = (name, data) => (0, import_svm_kit4.decodeIdlAccount)(JL_VAULTS_ACCOUNTS_IDL, name, (0, import_svm_kit4.fromBase64)(data));
|
|
10868
10898
|
var ratio = (withInterest, free) => {
|
|
10869
10899
|
if (withInterest > free) return [free * FOUR_DECIMALS / withInterest, false];
|
|
10870
10900
|
if (withInterest < free) return [withInterest * FOUR_DECIMALS / free, true];
|
|
@@ -11164,7 +11194,7 @@ async function readJupiterLendVaultsOnchain(rpc, market, vaultIds, opts = {}) {
|
|
|
11164
11194
|
for (const mint of mints) {
|
|
11165
11195
|
const a = r2.m.get(mint);
|
|
11166
11196
|
if (!a) continue;
|
|
11167
|
-
const b = (0,
|
|
11197
|
+
const b = (0, import_svm_kit4.fromBase64)(a.data[0]);
|
|
11168
11198
|
if (b.length >= 45) decimalsOf.set(mint, b[44]);
|
|
11169
11199
|
}
|
|
11170
11200
|
const reserves = /* @__PURE__ */ new Map();
|
|
@@ -11183,7 +11213,7 @@ async function readJupiterLendVaultsOnchain(rpc, market, vaultIds, opts = {}) {
|
|
|
11183
11213
|
const balanceOf = (mint) => {
|
|
11184
11214
|
const a = r3.m.get(vaultOf.get(mint) ?? "");
|
|
11185
11215
|
if (!a) return 0n;
|
|
11186
|
-
const b = (0,
|
|
11216
|
+
const b = (0, import_svm_kit4.fromBase64)(a.data[0]);
|
|
11187
11217
|
return b.length >= 72 ? new DataView(b.buffer, b.byteOffset, b.byteLength).getBigUint64(
|
|
11188
11218
|
64,
|
|
11189
11219
|
true
|
|
@@ -11419,6 +11449,68 @@ async function readJupiterLendVaultsOnchain(rpc, market, vaultIds, opts = {}) {
|
|
|
11419
11449
|
}
|
|
11420
11450
|
return out;
|
|
11421
11451
|
}
|
|
11452
|
+
function decodeJlRateModel(data) {
|
|
11453
|
+
if (data.length < 53)
|
|
11454
|
+
throw new Error(`RateModel is ${data.length} bytes, expected 53`);
|
|
11455
|
+
const v = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
11456
|
+
const u16 = (o) => v.getUint16(o, true);
|
|
11457
|
+
const version = data[40];
|
|
11458
|
+
if (version !== 1 && version !== 2)
|
|
11459
|
+
throw new Error(`RateModel version ${version} not supported`);
|
|
11460
|
+
return {
|
|
11461
|
+
version,
|
|
11462
|
+
rateAtZero: u16(41),
|
|
11463
|
+
kink1: u16(43),
|
|
11464
|
+
rateAtKink1: u16(45),
|
|
11465
|
+
rateAtMax: u16(47),
|
|
11466
|
+
...version === 2 ? { kink2: u16(49), rateAtKink2: u16(51) } : {}
|
|
11467
|
+
};
|
|
11468
|
+
}
|
|
11469
|
+
async function readJlLayerIrms(rpc, market, mints, now = BigInt(Math.floor(Date.now() / 1e3))) {
|
|
11470
|
+
const uniq = [...new Set(mints)];
|
|
11471
|
+
const keys = await Promise.all(
|
|
11472
|
+
uniq.map(async (m2) => ({
|
|
11473
|
+
mint: m2,
|
|
11474
|
+
model: await liq([utf83("rate_model"), await pk3(m2)], market),
|
|
11475
|
+
reserve: await liq([utf83("reserve"), await pk3(m2)], market)
|
|
11476
|
+
}))
|
|
11477
|
+
);
|
|
11478
|
+
const { m } = await read(
|
|
11479
|
+
rpc,
|
|
11480
|
+
keys.flatMap((k) => [k.model, k.reserve])
|
|
11481
|
+
);
|
|
11482
|
+
const out = /* @__PURE__ */ new Map();
|
|
11483
|
+
for (const k of keys) {
|
|
11484
|
+
const ma = m.get(k.model);
|
|
11485
|
+
const ra = m.get(k.reserve);
|
|
11486
|
+
if (!ma || !ra) continue;
|
|
11487
|
+
try {
|
|
11488
|
+
const model = decodeJlRateModel((0, import_svm_kit4.fromBase64)(ma.data[0]));
|
|
11489
|
+
const r = dec("TokenReserve", ra.data[0]);
|
|
11490
|
+
const o = jlOverallTokenData(r, now);
|
|
11491
|
+
const P = JL_EXCHANGE_PRICES_PRECISION;
|
|
11492
|
+
const bWi = Number(big(r.total_borrow_with_interest) * o.borrowEx / P);
|
|
11493
|
+
const sWi = Number(big(r.total_supply_with_interest) * o.supplyEx / P);
|
|
11494
|
+
const tb = Number(o.totalBorrow);
|
|
11495
|
+
const ts = Number(o.totalSupply);
|
|
11496
|
+
const u = ts > 0 ? tb / ts : 0;
|
|
11497
|
+
const ratio2 = u > 0 && sWi > 0 ? bWi / sWi / u : 1;
|
|
11498
|
+
out.set(k.mint, {
|
|
11499
|
+
...model,
|
|
11500
|
+
feeOnInterest: Number(r.fee_on_interest),
|
|
11501
|
+
maxUtilization: Number(o.maxUtilization),
|
|
11502
|
+
supplyWithInterestRatio: Number.isFinite(ratio2) ? ratio2 : 1,
|
|
11503
|
+
lastUtilization: Number(r.last_utilization),
|
|
11504
|
+
borrowRate: Number(r.borrow_rate)
|
|
11505
|
+
});
|
|
11506
|
+
} catch (e) {
|
|
11507
|
+
console.warn(
|
|
11508
|
+
`[jupiter-lend] rate model for ${k.mint} not read: ${e.message}`
|
|
11509
|
+
);
|
|
11510
|
+
}
|
|
11511
|
+
}
|
|
11512
|
+
return out;
|
|
11513
|
+
}
|
|
11422
11514
|
|
|
11423
11515
|
// src/lending/public-data/jupiter-lend/convertPublic.ts
|
|
11424
11516
|
var JL_FACTOR_SCALE = 1e3;
|
|
@@ -11737,6 +11829,22 @@ async function fetchJupiterLendPublic(opts = {}) {
|
|
|
11737
11829
|
}
|
|
11738
11830
|
}
|
|
11739
11831
|
const fromChain = new Map(chain.map((c) => [c.vault.id, c]));
|
|
11832
|
+
let irms = /* @__PURE__ */ new Map();
|
|
11833
|
+
if (opts.rpc) {
|
|
11834
|
+
const mints = /* @__PURE__ */ new Set();
|
|
11835
|
+
for (const v of [...vaults, ...chain.map((c) => c.vault)]) {
|
|
11836
|
+
const cv = fromChain.get(v.id);
|
|
11837
|
+
if (!cv?.smartCol) mints.add(v.supplyToken.address);
|
|
11838
|
+
if (!cv?.smartDebt) mints.add(v.borrowToken.address);
|
|
11839
|
+
}
|
|
11840
|
+
try {
|
|
11841
|
+
irms = await readJlLayerIrms(opts.rpc, market, [...mints]);
|
|
11842
|
+
} catch (e) {
|
|
11843
|
+
console.warn(
|
|
11844
|
+
`[jupiter-lend] layer rate models for ${market} not read: ${e.message}`
|
|
11845
|
+
);
|
|
11846
|
+
}
|
|
11847
|
+
}
|
|
11740
11848
|
for (const v of [...vaults, ...chain.map((c) => c.vault)]) {
|
|
11741
11849
|
if (only && !only.includes(v.id)) continue;
|
|
11742
11850
|
const conv = convertJupiterLendVault(market, v, {
|
|
@@ -11745,6 +11853,15 @@ async function fetchJupiterLendPublic(opts = {}) {
|
|
|
11745
11853
|
layer
|
|
11746
11854
|
});
|
|
11747
11855
|
const cv = fromChain.get(v.id);
|
|
11856
|
+
const mags = {
|
|
11857
|
+
supplyMagnifier: Number(v.supplyRateMagnifier) || 0,
|
|
11858
|
+
borrowMagnifier: Number(v.borrowRateMagnifier) || 0
|
|
11859
|
+
};
|
|
11860
|
+
for (const row of Object.values(conv.data)) {
|
|
11861
|
+
const smart = row.underlying === v.supplyToken.address ? cv?.smartCol : cv?.smartDebt;
|
|
11862
|
+
const irm = smart ? void 0 : irms.get(row.underlying);
|
|
11863
|
+
if (irm) row.jupiterLend = { irm: { ...irm, ...mags } };
|
|
11864
|
+
}
|
|
11748
11865
|
const meta = conv.params.jupiterLendVault;
|
|
11749
11866
|
meta.source = cv ? "chain" : "api";
|
|
11750
11867
|
if (cv) {
|
|
@@ -11796,7 +11913,7 @@ var SAVE_API_BASE = "https://api.save.finance";
|
|
|
11796
11913
|
var SAVE_WAD = 10n ** 18n;
|
|
11797
11914
|
var SAVE_U64_MAX = "18446744073709551615";
|
|
11798
11915
|
var SAVE_SLOTS_PER_YEAR = 63072e3;
|
|
11799
|
-
var SAVE_DEFAULT_AVG_SLOT_SECONDS = 0.
|
|
11916
|
+
var SAVE_DEFAULT_AVG_SLOT_SECONDS = 0.2665;
|
|
11800
11917
|
var SAVE_LIQUIDATION_CLOSE_FACTOR = 0.2;
|
|
11801
11918
|
var SAVE_MAX_LIQUIDATABLE_VALUE_USD = 5e5;
|
|
11802
11919
|
var SAVE_FULL_LIQUIDATION_VALUE_USD = 1;
|
|
@@ -12336,7 +12453,7 @@ function createPacer(intervalMs) {
|
|
|
12336
12453
|
}
|
|
12337
12454
|
|
|
12338
12455
|
// src/lending/public-data/loopscale/markets.ts
|
|
12339
|
-
var
|
|
12456
|
+
var import_svm_kit5 = require("@1delta/svm-kit");
|
|
12340
12457
|
async function buildLoopscaleRoster(vaults, loops, opts = {}) {
|
|
12341
12458
|
const byKey = /* @__PURE__ */ new Map();
|
|
12342
12459
|
const key2 = (p, c) => `${p}_${c}`;
|
|
@@ -12440,7 +12557,7 @@ async function buildLoopscaleRoster(vaults, loops, opts = {}) {
|
|
|
12440
12557
|
];
|
|
12441
12558
|
const unresolved = [];
|
|
12442
12559
|
if (toProbe.length && opts.rpc) {
|
|
12443
|
-
const mints = await (0,
|
|
12560
|
+
const mints = await (0, import_svm_kit5.getMints)(opts.rpc, toProbe);
|
|
12444
12561
|
const dec2 = /* @__PURE__ */ new Map();
|
|
12445
12562
|
mints.forEach((m, i) => m && dec2.set(toProbe[i], m.decimals));
|
|
12446
12563
|
for (const pair of byKey.values()) {
|
|
@@ -12747,7 +12864,12 @@ function convertLoopscalePair(pair, opts) {
|
|
|
12747
12864
|
termId: t.termId,
|
|
12748
12865
|
durationDays: t.durationDays,
|
|
12749
12866
|
durationSecs: t.durationDays * 86400,
|
|
12750
|
-
apr: t.apr
|
|
12867
|
+
apr: t.apr,
|
|
12868
|
+
ladder: t.ladder.map((l) => ({
|
|
12869
|
+
apr: l.apr,
|
|
12870
|
+
assets: fmt2(l.sum, pDec),
|
|
12871
|
+
fill: "single"
|
|
12872
|
+
}))
|
|
12751
12873
|
}));
|
|
12752
12874
|
const common = {
|
|
12753
12875
|
totalDebtStable: "0",
|
|
@@ -12887,11 +13009,11 @@ function convertLoopscalePair(pair, opts) {
|
|
|
12887
13009
|
}
|
|
12888
13010
|
|
|
12889
13011
|
// src/lending/public-data/loopscale/fetchPublic.ts
|
|
12890
|
-
var
|
|
13012
|
+
var import_svm_kit7 = require("@1delta/svm-kit");
|
|
12891
13013
|
init_lenders();
|
|
12892
13014
|
|
|
12893
13015
|
// src/lending/public-data/loopscale/accounts.ts
|
|
12894
|
-
var
|
|
13016
|
+
var import_svm_kit6 = require("@1delta/svm-kit");
|
|
12895
13017
|
|
|
12896
13018
|
// src/lending/public-data/loopscale/idl/loopscale.json
|
|
12897
13019
|
var loopscale_default = {
|
|
@@ -19874,8 +19996,8 @@ var podDecimalToNumber = (p) => Number(podToBigInt(p)) / 1e18;
|
|
|
19874
19996
|
var podBool = (p) => bytesOf(p)[0] !== 0;
|
|
19875
19997
|
var raw = (v) => v;
|
|
19876
19998
|
function decodeLoopscaleLoan(data) {
|
|
19877
|
-
const r = raw((0,
|
|
19878
|
-
const zero = (0,
|
|
19999
|
+
const r = raw((0, import_svm_kit6.decodeIdlAccount)(LOOPSCALE_IDL, "Loan", data));
|
|
20000
|
+
const zero = (0, import_svm_kit6.encodeBase58)(new Uint8Array(32));
|
|
19879
20001
|
const ledgers = r.ledgers.map(
|
|
19880
20002
|
(l) => ({
|
|
19881
20003
|
status: l.status,
|
|
@@ -19919,7 +20041,7 @@ function decodeLoopscaleLoan(data) {
|
|
|
19919
20041
|
};
|
|
19920
20042
|
}
|
|
19921
20043
|
function decodeLoopscaleStrategy(data) {
|
|
19922
|
-
const r = raw((0,
|
|
20044
|
+
const r = raw((0, import_svm_kit6.decodeIdlAccount)(LOOPSCALE_IDL, "Strategy", data));
|
|
19923
20045
|
return {
|
|
19924
20046
|
version: r.version,
|
|
19925
20047
|
nonce: r.nonce,
|
|
@@ -19956,13 +20078,13 @@ async function readLoopscaleLoans(rpc, loanAddresses) {
|
|
|
19956
20078
|
return {
|
|
19957
20079
|
slot,
|
|
19958
20080
|
loans: accounts.map(
|
|
19959
|
-
(a) => a && a.owner === LOOPSCALE_PROGRAM_ID ? decodeLoopscaleLoan((0,
|
|
20081
|
+
(a) => a && a.owner === LOOPSCALE_PROGRAM_ID ? decodeLoopscaleLoan((0, import_svm_kit6.fromBase64)(a.data[0])) : null
|
|
19960
20082
|
)
|
|
19961
20083
|
};
|
|
19962
20084
|
}
|
|
19963
20085
|
function decodeLoopscaleMarketInformation(data) {
|
|
19964
|
-
const r = raw((0,
|
|
19965
|
-
const zero = (0,
|
|
20086
|
+
const r = raw((0, import_svm_kit6.decodeIdlAccount)(LOOPSCALE_IDL, "MarketInformation", data));
|
|
20087
|
+
const zero = (0, import_svm_kit6.encodeBase58)(new Uint8Array(32));
|
|
19966
20088
|
const caps = (c) => ({
|
|
19967
20089
|
max1hr: podToBigInt(c.max_1hr).toString(),
|
|
19968
20090
|
max24hr: podToBigInt(c.max_24hr).toString(),
|
|
@@ -20011,7 +20133,7 @@ async function readLoopscaleMarketInformation(rpc, addresses) {
|
|
|
20011
20133
|
try {
|
|
20012
20134
|
out.set(
|
|
20013
20135
|
unique[i],
|
|
20014
|
-
decodeLoopscaleMarketInformation((0,
|
|
20136
|
+
decodeLoopscaleMarketInformation((0, import_svm_kit6.fromBase64)(a.data[0]))
|
|
20015
20137
|
);
|
|
20016
20138
|
} catch (e) {
|
|
20017
20139
|
console.warn(
|
|
@@ -20204,7 +20326,7 @@ async function fetchLoopscalePublic(opts = {}) {
|
|
|
20204
20326
|
opts.vaults ?? api.vaults(),
|
|
20205
20327
|
opts.loops ?? api.loops()
|
|
20206
20328
|
]);
|
|
20207
|
-
const rpc = opts.rpc ?? (0,
|
|
20329
|
+
const rpc = opts.rpc ?? (0, import_svm_kit7.createSvmRpc)();
|
|
20208
20330
|
const { pairs, unresolved } = await buildLoopscaleRoster(vaults, loops, {
|
|
20209
20331
|
...opts,
|
|
20210
20332
|
rpc
|
|
@@ -20365,7 +20487,7 @@ function deriveLoopscalePrices(vaults, loops, pairs, tokenList, loanBook) {
|
|
|
20365
20487
|
}
|
|
20366
20488
|
|
|
20367
20489
|
// src/prices/pythPush.ts
|
|
20368
|
-
var
|
|
20490
|
+
var import_svm_kit8 = require("@1delta/svm-kit");
|
|
20369
20491
|
var PYTH_RECEIVER_PROGRAM = "rec2HHDDnjLfj4kE7VyEtFA1HPGQLK33259532cRyHp";
|
|
20370
20492
|
var PYTH_PRICE_UPDATE_V2_DISCRIMINATOR = [
|
|
20371
20493
|
34,
|
|
@@ -20378,7 +20500,7 @@ var PYTH_PRICE_UPDATE_V2_DISCRIMINATOR = [
|
|
|
20378
20500
|
205
|
|
20379
20501
|
];
|
|
20380
20502
|
function decodePythPriceUpdate(data) {
|
|
20381
|
-
const b = typeof data === "string" ? (0,
|
|
20503
|
+
const b = typeof data === "string" ? (0, import_svm_kit8.fromBase64)(data) : data;
|
|
20382
20504
|
for (let i = 0; i < 8; i++)
|
|
20383
20505
|
if (b[i] !== PYTH_PRICE_UPDATE_V2_DISCRIMINATOR[i])
|
|
20384
20506
|
throw new Error("pyth: account is not a PriceUpdateV2");
|
|
@@ -20512,7 +20634,7 @@ function createP0Api(opts = {}) {
|
|
|
20512
20634
|
}
|
|
20513
20635
|
|
|
20514
20636
|
// src/lending/public-data/project0/accounts.ts
|
|
20515
|
-
var
|
|
20637
|
+
var import_svm_kit9 = require("@1delta/svm-kit");
|
|
20516
20638
|
|
|
20517
20639
|
// src/lending/public-data/project0/idl/marginfi.json
|
|
20518
20640
|
var marginfi_default = {
|
|
@@ -35378,7 +35500,7 @@ function decimalStringToI80F48(s) {
|
|
|
35378
35500
|
}
|
|
35379
35501
|
var utf84 = (s) => new TextEncoder().encode(s);
|
|
35380
35502
|
var pk4 = (address) => {
|
|
35381
|
-
const b = (0,
|
|
35503
|
+
const b = (0, import_svm_kit9.decodeBase58)(address);
|
|
35382
35504
|
if (!b || b.length !== 32)
|
|
35383
35505
|
throw new Error(`project0: not a 32-byte pubkey: ${address}`);
|
|
35384
35506
|
return b;
|
|
@@ -35388,16 +35510,16 @@ var u16le2 = (n) => {
|
|
|
35388
35510
|
throw new Error(`project0: u16 out of range: ${n}`);
|
|
35389
35511
|
return new Uint8Array([n & 255, n >> 8]);
|
|
35390
35512
|
};
|
|
35391
|
-
var p0LiquidityVaultAuthority = async (bank, programId = P0_PROGRAM_ID) => (await (0,
|
|
35513
|
+
var p0LiquidityVaultAuthority = async (bank, programId = P0_PROGRAM_ID) => (await (0, import_svm_kit9.findProgramAddress)(
|
|
35392
35514
|
[utf84(P0_SEEDS.liquidityVaultAuthority), pk4(bank)],
|
|
35393
35515
|
programId
|
|
35394
35516
|
)).address;
|
|
35395
|
-
var p0LiquidityVault = async (bank, programId = P0_PROGRAM_ID) => (await (0,
|
|
35517
|
+
var p0LiquidityVault = async (bank, programId = P0_PROGRAM_ID) => (await (0, import_svm_kit9.findProgramAddress)(
|
|
35396
35518
|
[utf84(P0_SEEDS.liquidityVault), pk4(bank)],
|
|
35397
35519
|
programId
|
|
35398
35520
|
)).address;
|
|
35399
|
-
var p0FeeState = async (programId = P0_PROGRAM_ID) => (await (0,
|
|
35400
|
-
var p0MarginfiAccountPda = async (authority, accountIndex = 0, opts = {}) => (await (0,
|
|
35521
|
+
var p0FeeState = async (programId = P0_PROGRAM_ID) => (await (0, import_svm_kit9.findProgramAddress)([utf84(P0_SEEDS.feeState)], programId)).address;
|
|
35522
|
+
var p0MarginfiAccountPda = async (authority, accountIndex = 0, opts = {}) => (await (0, import_svm_kit9.findProgramAddress)(
|
|
35401
35523
|
[
|
|
35402
35524
|
utf84(P0_SEEDS.marginfiAccount),
|
|
35403
35525
|
pk4(opts.group ?? P0_MAIN_GROUP),
|
|
@@ -35487,8 +35609,8 @@ var bankConfig = (c) => ({
|
|
|
35487
35609
|
cbEmaAlphaBps: c.cb_ema_alpha_bps
|
|
35488
35610
|
});
|
|
35489
35611
|
function decodeP0Bank(address, data, tokenSymbol) {
|
|
35490
|
-
const bytes2 = typeof data === "string" ? (0,
|
|
35491
|
-
const r = (0,
|
|
35612
|
+
const bytes2 = typeof data === "string" ? (0, import_svm_kit9.fromBase64)(data) : data;
|
|
35613
|
+
const r = (0, import_svm_kit9.decodeIdlAccount)(P0_IDL, "Bank", bytes2);
|
|
35492
35614
|
const entries = r.emode.emode_config.entries.filter((e) => e.collateral_bank_emode_tag !== 0).map((e) => ({
|
|
35493
35615
|
collateralBankEmodeTag: e.collateral_bank_emode_tag,
|
|
35494
35616
|
flags: e.flags,
|
|
@@ -35713,8 +35835,8 @@ var u32ToBasis = (v) => v / 4294967295 * 100;
|
|
|
35713
35835
|
var P0_PAUSE_DURATION_SECONDS = 6 * 60 * 60;
|
|
35714
35836
|
var p0GroupPausedAt = (g, now) => !!g?.panic.pausedFlag && (now < g.panic.pauseStartTimestamp || now - g.panic.pauseStartTimestamp < P0_PAUSE_DURATION_SECONDS);
|
|
35715
35837
|
function decodeP0Group(address, data) {
|
|
35716
|
-
const bytes2 = typeof data === "string" ? (0,
|
|
35717
|
-
const r = (0,
|
|
35838
|
+
const bytes2 = typeof data === "string" ? (0, import_svm_kit9.fromBase64)(data) : data;
|
|
35839
|
+
const r = (0, import_svm_kit9.decodeIdlAccount)(P0_IDL, "MarginfiGroup", bytes2);
|
|
35718
35840
|
return {
|
|
35719
35841
|
address,
|
|
35720
35842
|
admin: r.admin,
|
|
@@ -35747,8 +35869,8 @@ function decodeP0Group(address, data) {
|
|
|
35747
35869
|
};
|
|
35748
35870
|
}
|
|
35749
35871
|
function decodeP0MarginfiAccount(address, data) {
|
|
35750
|
-
const bytes2 = typeof data === "string" ? (0,
|
|
35751
|
-
const r = (0,
|
|
35872
|
+
const bytes2 = typeof data === "string" ? (0, import_svm_kit9.fromBase64)(data) : data;
|
|
35873
|
+
const r = (0, import_svm_kit9.decodeIdlAccount)(
|
|
35752
35874
|
P0_IDL,
|
|
35753
35875
|
"MarginfiAccount",
|
|
35754
35876
|
bytes2
|
|
@@ -35803,10 +35925,10 @@ var P0_GROUP_SIZE = 9256;
|
|
|
35803
35925
|
var P0_ACCOUNT_GROUP_OFFSET = 8;
|
|
35804
35926
|
var P0_ACCOUNT_AUTHORITY_OFFSET = 8 + 32;
|
|
35805
35927
|
var P0_BANK_GROUP_OFFSET = 8 + 32 + 1;
|
|
35806
|
-
var p0BankMetadataPda = async (bank, programId = P0_PROGRAM_ID) => (await (0,
|
|
35928
|
+
var p0BankMetadataPda = async (bank, programId = P0_PROGRAM_ID) => (await (0, import_svm_kit9.findProgramAddress)([utf84("metadata"), pk4(bank)], programId)).address;
|
|
35807
35929
|
function decodeP0BankMetadata(data) {
|
|
35808
|
-
const bytes2 = typeof data === "string" ? (0,
|
|
35809
|
-
const r = (0,
|
|
35930
|
+
const bytes2 = typeof data === "string" ? (0, import_svm_kit9.fromBase64)(data) : data;
|
|
35931
|
+
const r = (0, import_svm_kit9.decodeIdlAccount)(P0_IDL, "BankMetadata", bytes2);
|
|
35810
35932
|
const td = new TextDecoder();
|
|
35811
35933
|
const ticker = td.decode(r.ticker.subarray(0, r.end_ticker_byte)).trim();
|
|
35812
35934
|
const description = td.decode(r.description.subarray(0, r.end_description_byte)).trim();
|
|
@@ -35956,7 +36078,7 @@ function p0CurveKnots(c) {
|
|
|
35956
36078
|
}
|
|
35957
36079
|
|
|
35958
36080
|
// src/vaults/lst/stakePool.ts
|
|
35959
|
-
var
|
|
36081
|
+
var import_svm_kit10 = require("@1delta/svm-kit");
|
|
35960
36082
|
var SPL_STAKE_POOL_PROGRAM = "SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy";
|
|
35961
36083
|
var OFFSET_RESERVE_STAKE = 130;
|
|
35962
36084
|
var OFFSET_POOL_MINT = 162;
|
|
@@ -35985,8 +36107,8 @@ function decodeStakePool(data) {
|
|
|
35985
36107
|
`stake-pool: account is ${data.byteLength} bytes, need \u2265 ${OFFSET_LAST_UPDATE_EPOCH + 8}`
|
|
35986
36108
|
);
|
|
35987
36109
|
const out = {
|
|
35988
|
-
poolMint: (0,
|
|
35989
|
-
reserveStake: (0,
|
|
36110
|
+
poolMint: (0, import_svm_kit10.encodeBase58)(data.slice(OFFSET_POOL_MINT, OFFSET_POOL_MINT + 32)),
|
|
36111
|
+
reserveStake: (0, import_svm_kit10.encodeBase58)(
|
|
35990
36112
|
data.slice(OFFSET_RESERVE_STAKE, OFFSET_RESERVE_STAKE + 32)
|
|
35991
36113
|
),
|
|
35992
36114
|
totalLamports: u642(data, OFFSET_TOTAL_LAMPORTS),
|
|
@@ -35994,7 +36116,7 @@ function decodeStakePool(data) {
|
|
|
35994
36116
|
lastUpdateEpoch: u642(data, OFFSET_LAST_UPDATE_EPOCH)
|
|
35995
36117
|
};
|
|
35996
36118
|
try {
|
|
35997
|
-
const r = new
|
|
36119
|
+
const r = new import_svm_kit10.BorshReader(data);
|
|
35998
36120
|
r.skip(OFFSET_TAIL);
|
|
35999
36121
|
r.skip(8 + 8 + 32);
|
|
36000
36122
|
const epoch = readFee(r);
|
|
@@ -36032,7 +36154,7 @@ async function readStakePools(rpc, stakePools, opts = {}) {
|
|
|
36032
36154
|
const pools = accounts.map((a) => {
|
|
36033
36155
|
if (!a || a.owner !== program) return null;
|
|
36034
36156
|
try {
|
|
36035
|
-
return decodeStakePool((0,
|
|
36157
|
+
return decodeStakePool((0, import_svm_kit10.fromBase64)(a.data[0]));
|
|
36036
36158
|
} catch {
|
|
36037
36159
|
return null;
|
|
36038
36160
|
}
|
|
@@ -36084,10 +36206,10 @@ async function readEpochClock(rpc) {
|
|
|
36084
36206
|
}
|
|
36085
36207
|
|
|
36086
36208
|
// src/lending/public-data/project0/prices.ts
|
|
36087
|
-
var
|
|
36209
|
+
var import_svm_kit12 = require("@1delta/svm-kit");
|
|
36088
36210
|
|
|
36089
36211
|
// src/prices/oracleAccounts.ts
|
|
36090
|
-
var
|
|
36212
|
+
var import_svm_kit11 = require("@1delta/svm-kit");
|
|
36091
36213
|
var PYTH_PRICE_UPDATE_OWNERS = /* @__PURE__ */ new Set([
|
|
36092
36214
|
"rec5EKMGg6MxZYaMdyBfgwp4d5rB9T1VQH5pJv5LtFJ",
|
|
36093
36215
|
"rec2HHDDnjLfj4kE7VyEtFA1HPGQLK33259532cRyHp"
|
|
@@ -36097,7 +36219,7 @@ var SWITCHBOARD_ON_DEMAND_PROGRAM = "SBondMDrcV3K4kxZR1HNVT7osZxAHVHgYXL5Ze1oMUv
|
|
|
36097
36219
|
var SWITCHBOARD_V2_PROGRAM = "SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f";
|
|
36098
36220
|
var SCOPE_PROGRAM = "HFn8GnPADiny6XqUoWE8uRPPxb29ikn4yTuPa9MF2fWJ";
|
|
36099
36221
|
var MARINADE_PROGRAM = "MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD";
|
|
36100
|
-
var bytes = (data) => typeof data === "string" ? (0,
|
|
36222
|
+
var bytes = (data) => typeof data === "string" ? (0, import_svm_kit11.fromBase64)(data) : data;
|
|
36101
36223
|
var view = (b) => new DataView(b.buffer, b.byteOffset, b.byteLength);
|
|
36102
36224
|
var i128 = (b, o) => {
|
|
36103
36225
|
const dv = view(b);
|
|
@@ -36292,9 +36414,9 @@ async function resolveP0Prices(rpc, banks, opts = {}) {
|
|
|
36292
36414
|
if (r > 0) msolRate[key2] = r;
|
|
36293
36415
|
}
|
|
36294
36416
|
} else if (scopeKeys.has(key2)) {
|
|
36295
|
-
if (a.owner === SCOPE_PROGRAM) scopeData[key2] = (0,
|
|
36417
|
+
if (a.owner === SCOPE_PROGRAM) scopeData[key2] = (0, import_svm_kit12.fromBase64)(a.data[0]);
|
|
36296
36418
|
} else if (P0_STAKE_POOL_PROGRAMS.has(a.owner)) {
|
|
36297
|
-
const p = decodeStakePool((0,
|
|
36419
|
+
const p = decodeStakePool((0, import_svm_kit12.fromBase64)(a.data[0]));
|
|
36298
36420
|
if (p.poolTokenSupply > 0n)
|
|
36299
36421
|
poolRate[key2] = Number(p.totalLamports) / Number(p.poolTokenSupply);
|
|
36300
36422
|
}
|
|
@@ -36822,13 +36944,13 @@ function deriveP0Mode(liabilityTags, roster) {
|
|
|
36822
36944
|
}
|
|
36823
36945
|
|
|
36824
36946
|
// src/lending/public-data/project0/fetchPublic.ts
|
|
36825
|
-
var
|
|
36947
|
+
var import_svm_kit13 = require("@1delta/svm-kit");
|
|
36826
36948
|
async function fetchProject0Public(opts = {}) {
|
|
36827
36949
|
const api = createP0Api(opts);
|
|
36828
36950
|
const groups = opts.groups?.length ? opts.groups : [P0_MAIN_GROUP];
|
|
36829
36951
|
const source = opts.source ?? "chain";
|
|
36830
36952
|
const roster = opts.roster ?? "scan";
|
|
36831
|
-
const rpc = source === "chain" || roster === "scan" || !opts.prices?.cacheOnly ? opts.rpc ?? (0,
|
|
36953
|
+
const rpc = source === "chain" || roster === "scan" || !opts.prices?.cacheOnly ? opts.rpc ?? (0, import_svm_kit13.createSvmRpc)() : opts.rpc;
|
|
36832
36954
|
const out = {};
|
|
36833
36955
|
for (const group of groups) {
|
|
36834
36956
|
let banks = [];
|
|
@@ -36943,6 +37065,7 @@ async function getLenderPublicData(chainId, opts = {}) {
|
|
|
36943
37065
|
}
|
|
36944
37066
|
|
|
36945
37067
|
// src/lending/public-data/getLenderPublicDataAll.ts
|
|
37068
|
+
var import_svm_kit14 = require("@1delta/svm-kit");
|
|
36946
37069
|
init_types();
|
|
36947
37070
|
init_lenders();
|
|
36948
37071
|
|
|
@@ -37067,12 +37190,15 @@ async function getLenderPublicDataAll(chainId, lenders, opts = {}) {
|
|
|
37067
37190
|
if (chainId !== SOLANA_CHAIN_ID)
|
|
37068
37191
|
throw new Error(`getLenderPublicDataAll: unsupported chain ${chainId}`);
|
|
37069
37192
|
const out = {};
|
|
37193
|
+
const needsSlot = opts.rpc && (lenders.some(import_lender_registry2.isSave) && opts.save?.avgSlotSeconds === void 0 || lenders.some(import_lender_registry2.isKamino) && opts.kamino?.slotSeconds === void 0);
|
|
37194
|
+
const slotSeconds = needsSlot ? await (0, import_svm_kit14.measureSlotSeconds)(opts.rpc) : void 0;
|
|
37070
37195
|
const kaminoKeys = lenders.filter(import_lender_registry2.isKamino);
|
|
37071
37196
|
if (kaminoKeys.length) {
|
|
37072
37197
|
const explicit = kaminoKeys.map(import_lender_registry2.kaminoMarketFromKey).filter((m) => !!m);
|
|
37073
37198
|
const wantsAll = kaminoKeys.some((k) => !(0, import_lender_registry2.kaminoMarketFromKey)(k));
|
|
37074
37199
|
const res = await fetchKaminoPublic({
|
|
37075
37200
|
...opts.kamino,
|
|
37201
|
+
slotSeconds: opts.kamino?.slotSeconds ?? slotSeconds,
|
|
37076
37202
|
rpc: opts.kamino?.rpc ?? opts.rpc,
|
|
37077
37203
|
tokenList: opts.tokenList ?? opts.kamino?.tokenList,
|
|
37078
37204
|
...wantsAll ? {} : { markets: explicit }
|
|
@@ -37112,6 +37238,7 @@ async function getLenderPublicDataAll(chainId, lenders, opts = {}) {
|
|
|
37112
37238
|
const wantsAll = saveKeys.some((k) => !(0, import_lender_registry2.saveMarketFromKey)(k));
|
|
37113
37239
|
const res = await fetchSavePublic({
|
|
37114
37240
|
...opts.save,
|
|
37241
|
+
avgSlotSeconds: opts.save?.avgSlotSeconds ?? slotSeconds,
|
|
37115
37242
|
tokenList: opts.tokenList ?? opts.save?.tokenList,
|
|
37116
37243
|
...wantsAll ? {} : { markets: explicit }
|
|
37117
37244
|
});
|
|
@@ -37414,6 +37541,8 @@ async function fetchJupiterPrices(mints, tokenList = {}, opts = {}) {
|
|
|
37414
37541
|
for (const [mint, r] of Object.entries(res ?? {})) {
|
|
37415
37542
|
const p = num(r?.usdPrice);
|
|
37416
37543
|
if (!(p > 0)) continue;
|
|
37544
|
+
if (opts.minLiquidityUsd !== void 0 && !(num(r?.liquidity) >= opts.minLiquidityUsd))
|
|
37545
|
+
continue;
|
|
37417
37546
|
byMint[mint] = p;
|
|
37418
37547
|
const stock = num(r?.stockData?.price);
|
|
37419
37548
|
if (stock > 0) stockPriceByMint[mint] = stock;
|
|
@@ -37578,7 +37707,7 @@ async function fetchExponentPtMarkets(opts = {}) {
|
|
|
37578
37707
|
}
|
|
37579
37708
|
|
|
37580
37709
|
// src/vaults/solstice/accounts.ts
|
|
37581
|
-
var
|
|
37710
|
+
var import_svm_kit15 = require("@1delta/svm-kit");
|
|
37582
37711
|
|
|
37583
37712
|
// src/vaults/solstice/idl/yield_strategy.json
|
|
37584
37713
|
var yield_strategy_default = {
|
|
@@ -48249,12 +48378,12 @@ var SOLSTICE_DECIMALS = 6;
|
|
|
48249
48378
|
var SOLSTICE_PRICE_DECIMALS = 6;
|
|
48250
48379
|
var utf85 = (s) => new TextEncoder().encode(s);
|
|
48251
48380
|
var pk5 = (address) => {
|
|
48252
|
-
const b = (0,
|
|
48381
|
+
const b = (0, import_svm_kit15.decodeBase58)(address);
|
|
48253
48382
|
if (!b || b.length !== 32)
|
|
48254
48383
|
throw new Error(`solstice: not a 32-byte pubkey: ${address}`);
|
|
48255
48384
|
return b;
|
|
48256
48385
|
};
|
|
48257
|
-
var pda = async (seeds, programId) => (await (0,
|
|
48386
|
+
var pda = async (seeds, programId) => (await (0, import_svm_kit15.findProgramAddress)(seeds, programId)).address;
|
|
48258
48387
|
async function yieldVaultPdas(programId = SOLSTICE_PROGRAMS.yieldVault) {
|
|
48259
48388
|
const [controller, yieldPool, vestingSchedule, shareMint, assetVault] = await Promise.all(
|
|
48260
48389
|
[
|
|
@@ -48338,20 +48467,20 @@ var oracleCanonicalPda = (feedId, programId = SOLSTICE_PROGRAMS.oracle) => pda([
|
|
|
48338
48467
|
var strategyNameOf = (raw2) => new TextDecoder().decode(raw2).replace(/\0+$/, "");
|
|
48339
48468
|
var YV = SOLSTICE_YIELD_VAULT_IDL;
|
|
48340
48469
|
var YS = SOLSTICE_YIELD_STRATEGY_IDL;
|
|
48341
|
-
var decodeController = (d2) => (0,
|
|
48342
|
-
var decodeYieldPool = (d2) => (0,
|
|
48343
|
-
var decodeVestingSchedule = (d2) => (0,
|
|
48344
|
-
var decodeCooldownEscrow = (d2) => (0,
|
|
48345
|
-
var decodeStrategyController = (d2) => (0,
|
|
48346
|
-
var decodeStrategy = (d2) => (0,
|
|
48347
|
-
var decodeAccountingState = (d2) => (0,
|
|
48348
|
-
var decodeSettlementBatch = (d2) => (0,
|
|
48349
|
-
var decodeJuniorUnlockShare = (d2) => (0,
|
|
48350
|
-
var decodeSeniorUnlockCooldown = (d2) => (0,
|
|
48470
|
+
var decodeController = (d2) => (0, import_svm_kit15.decodeIdlAccount)(YV, "Controller", d2);
|
|
48471
|
+
var decodeYieldPool = (d2) => (0, import_svm_kit15.decodeIdlAccount)(YV, "YieldPool", d2);
|
|
48472
|
+
var decodeVestingSchedule = (d2) => (0, import_svm_kit15.decodeIdlAccount)(YV, "VestingSchedule", d2);
|
|
48473
|
+
var decodeCooldownEscrow = (d2) => (0, import_svm_kit15.decodeIdlAccount)(YV, "CooldownEscrow", d2);
|
|
48474
|
+
var decodeStrategyController = (d2) => (0, import_svm_kit15.decodeIdlAccount)(YS, "Controller", d2);
|
|
48475
|
+
var decodeStrategy = (d2) => (0, import_svm_kit15.decodeIdlAccount)(YS, "Strategy", d2);
|
|
48476
|
+
var decodeAccountingState = (d2) => (0, import_svm_kit15.decodeIdlAccount)(YS, "AccountingState", d2);
|
|
48477
|
+
var decodeSettlementBatch = (d2) => (0, import_svm_kit15.decodeIdlAccount)(YS, "SettlementBatch", d2);
|
|
48478
|
+
var decodeJuniorUnlockShare = (d2) => (0, import_svm_kit15.decodeIdlAccount)(YS, "JuniorUnlockShare", d2);
|
|
48479
|
+
var decodeSeniorUnlockCooldown = (d2) => (0, import_svm_kit15.decodeIdlAccount)(YS, "SeniorUnlockCooldown", d2);
|
|
48351
48480
|
function accountDiscriminator(idl, name) {
|
|
48352
48481
|
const a = idl.accounts.find((x) => x.name === name);
|
|
48353
48482
|
if (!a) throw new Error(`idl ${idl.metadata?.name}: no account ${name}`);
|
|
48354
|
-
return (0,
|
|
48483
|
+
return (0, import_svm_kit15.encodeBase58)(Uint8Array.from(a.discriminator));
|
|
48355
48484
|
}
|
|
48356
48485
|
var SETTLEMENT_BATCH_SIZE = 309;
|
|
48357
48486
|
var ORACLE_CANONICAL_SIZE = 365;
|
|
@@ -48394,7 +48523,7 @@ function tokenAmount(data) {
|
|
|
48394
48523
|
}
|
|
48395
48524
|
var need = (a, what) => {
|
|
48396
48525
|
if (!a) throw new Error(`solstice: ${what} account is missing`);
|
|
48397
|
-
return (0,
|
|
48526
|
+
return (0, import_svm_kit15.fromBase64)(a.data[0]);
|
|
48398
48527
|
};
|
|
48399
48528
|
async function readSolsticeChainState(rpc, opts = {}) {
|
|
48400
48529
|
const programs = { ...SOLSTICE_PROGRAMS, ...opts.programs };
|
|
@@ -48459,7 +48588,7 @@ async function readSolsticeChainState(rpc, opts = {}) {
|
|
|
48459
48588
|
const raw2 = r.accounts[j++];
|
|
48460
48589
|
s.oracleAccount = feeds[i];
|
|
48461
48590
|
if (raw2)
|
|
48462
|
-
s.oracle = decodeOracleCanonical((0,
|
|
48591
|
+
s.oracle = decodeOracleCanonical((0, import_svm_kit15.fromBase64)(raw2.data[0])) ?? void 0;
|
|
48463
48592
|
});
|
|
48464
48593
|
}
|
|
48465
48594
|
return { slot, yieldVault, strategies };
|
|
@@ -48572,12 +48701,12 @@ function strategyMode(s, oraclePriceUsd, priceDecimals = 6) {
|
|
|
48572
48701
|
|
|
48573
48702
|
// src/vaults/solstice/fetchPublic.ts
|
|
48574
48703
|
init_types();
|
|
48575
|
-
var
|
|
48704
|
+
var import_svm_kit16 = require("@1delta/svm-kit");
|
|
48576
48705
|
var SCALE = 10 ** SOLSTICE_DECIMALS;
|
|
48577
48706
|
var fmt3 = (raw2) => Number(raw2) / SCALE;
|
|
48578
48707
|
var BATCH_STATUS = ["active", "cancelled", "settled"];
|
|
48579
48708
|
async function fetchSolsticeSettlementBatches(rpc, strategyName, juniorQueueTimeSeconds, programId = SOLSTICE_PROGRAMS.yieldStrategy) {
|
|
48580
|
-
const fetchers = (0,
|
|
48709
|
+
const fetchers = (0, import_svm_kit16.createSvmFetchers)(rpc);
|
|
48581
48710
|
const rows = await fetchers.indexed.scanProgram(
|
|
48582
48711
|
programId,
|
|
48583
48712
|
[
|
|
@@ -48595,7 +48724,7 @@ async function fetchSolsticeSettlementBatches(rpc, strategyName, juniorQueueTime
|
|
|
48595
48724
|
);
|
|
48596
48725
|
const out = [];
|
|
48597
48726
|
for (const r of rows) {
|
|
48598
|
-
const b = decodeSettlementBatch((0,
|
|
48727
|
+
const b = decodeSettlementBatch((0, import_svm_kit16.fromBase64)(r.account.data[0]));
|
|
48599
48728
|
if (strategyNameOf(b.strategy_name) !== strategyName) continue;
|
|
48600
48729
|
const settlementTime = Number(b.settlement_time);
|
|
48601
48730
|
out.push({
|
|
@@ -48861,7 +48990,7 @@ function buildSolsticeVaults(state, ctx) {
|
|
|
48861
48990
|
return out;
|
|
48862
48991
|
}
|
|
48863
48992
|
async function fetchSolsticeVaults(opts = {}) {
|
|
48864
|
-
const rpc = opts.rpc ?? (0,
|
|
48993
|
+
const rpc = opts.rpc ?? (0, import_svm_kit16.createSvmRpc)();
|
|
48865
48994
|
const nowSecs = opts.nowSecs ?? Math.floor(Date.now() / 1e3);
|
|
48866
48995
|
const tokenList = opts.tokenList ?? {};
|
|
48867
48996
|
const state = await readSolsticeChainState(rpc, {
|
|
@@ -48900,15 +49029,15 @@ async function fetchSolsticeVaults(opts = {}) {
|
|
|
48900
49029
|
|
|
48901
49030
|
// src/vaults/solstice/fetchUser.ts
|
|
48902
49031
|
init_types();
|
|
48903
|
-
var
|
|
49032
|
+
var import_svm_kit17 = require("@1delta/svm-kit");
|
|
48904
49033
|
async function fetchSolsticeUser(account, opts = {}) {
|
|
48905
|
-
const rpc = opts.rpc ?? (0,
|
|
49034
|
+
const rpc = opts.rpc ?? (0, import_svm_kit17.createSvmRpc)();
|
|
48906
49035
|
const vaults = opts.vaults ?? await fetchSolsticeVaults({ ...opts, rpc });
|
|
48907
49036
|
const rows = Object.values(vaults);
|
|
48908
49037
|
const nowSecs = opts.nowSecs ?? Math.floor(Date.now() / 1e3);
|
|
48909
49038
|
const atas = await Promise.all(
|
|
48910
49039
|
rows.map(
|
|
48911
|
-
(r) => (0,
|
|
49040
|
+
(r) => (0, import_svm_kit17.getAssociatedTokenAddress)(account, r.address, import_svm_kit17.TOKEN_PROGRAM)
|
|
48912
49041
|
)
|
|
48913
49042
|
);
|
|
48914
49043
|
const eusx = rows.find((r) => r.kind === "yield-vault");
|
|
@@ -48938,7 +49067,7 @@ async function fetchSolsticeUser(account, opts = {}) {
|
|
|
48938
49067
|
const { slot, accounts } = await rpc.readAccounts(keys);
|
|
48939
49068
|
let i = 0;
|
|
48940
49069
|
const next = () => accounts[i++] ?? null;
|
|
48941
|
-
const bytes2 = (a) => a ? (0,
|
|
49070
|
+
const bytes2 = (a) => a ? (0, import_svm_kit17.fromBase64)(a.data[0]) : void 0;
|
|
48942
49071
|
const holdings = [];
|
|
48943
49072
|
rows.forEach((r, k) => {
|
|
48944
49073
|
const d2 = bytes2(next());
|
|
@@ -65101,7 +65230,7 @@ var HUMA_SEEDS = {
|
|
|
65101
65230
|
};
|
|
65102
65231
|
|
|
65103
65232
|
// src/vaults/huma/accounts.ts
|
|
65104
|
-
var
|
|
65233
|
+
var import_svm_kit18 = require("@1delta/svm-kit");
|
|
65105
65234
|
var HUMA_POOL = {
|
|
65106
65235
|
poolConfig: "28hFhD21Nka3stL27a8zZ4nRLgaDVxRYwJgeEVgeakzS",
|
|
65107
65236
|
poolId: "sFp7QFGknaW37xRFfdRwbC4QhM1n7Y9sJkYL4vnqXRn",
|
|
@@ -65116,11 +65245,11 @@ var HUMA_CLASSIC_MODE_ID = "Fr2BGzmFkufAUXNWSWk79juyWrHVCj8AbyzbbvZzhwgz";
|
|
|
65116
65245
|
var HUMA_DECIMALS = 6;
|
|
65117
65246
|
var utf86 = (s) => new TextEncoder().encode(s);
|
|
65118
65247
|
var pk6 = (address) => {
|
|
65119
|
-
const b = (0,
|
|
65248
|
+
const b = (0, import_svm_kit18.decodeBase58)(address);
|
|
65120
65249
|
if (!b || b.length !== 32) throw new Error(`huma: bad pubkey ${address}`);
|
|
65121
65250
|
return b;
|
|
65122
65251
|
};
|
|
65123
|
-
var pda2 = (seeds) => (0,
|
|
65252
|
+
var pda2 = (seeds) => (0, import_svm_kit18.findProgramAddress)(seeds, HUMA_PROGRAM).then((r) => r.address);
|
|
65124
65253
|
var humaPoolConfigPda = () => pda2([utf86("pool_config"), pk6(HUMA_POOL.poolId)]);
|
|
65125
65254
|
var humaPoolStatePda = () => pda2([utf86("pool_state"), pk6(HUMA_POOL.poolConfig)]);
|
|
65126
65255
|
var humaPoolAuthorityPda = () => pda2([utf86("pool_authority"), pk6(HUMA_POOL.poolConfig)]);
|
|
@@ -65136,11 +65265,11 @@ var u128be = (v) => {
|
|
|
65136
65265
|
out[15 - i] = Number(v >> BigInt(8 * i) & 0xffn);
|
|
65137
65266
|
return out;
|
|
65138
65267
|
};
|
|
65139
|
-
var decodeHumaPoolState = (d2) => (0,
|
|
65140
|
-
var decodeHumaModeConfig = (d2) => (0,
|
|
65141
|
-
var decodeHumaPoolConfig = (d2) => (0,
|
|
65142
|
-
var decodeHumaLenderState = (d2) => (0,
|
|
65143
|
-
var decodeHumaRedemptionRequest = (d2) => (0,
|
|
65268
|
+
var decodeHumaPoolState = (d2) => (0, import_svm_kit18.decodeIdlAccount)(HUMA_IDL, "PoolState", d2);
|
|
65269
|
+
var decodeHumaModeConfig = (d2) => (0, import_svm_kit18.decodeIdlAccount)(HUMA_IDL, "ModeConfig", d2);
|
|
65270
|
+
var decodeHumaPoolConfig = (d2) => (0, import_svm_kit18.decodeIdlAccount)(HUMA_IDL, "PoolConfig", d2);
|
|
65271
|
+
var decodeHumaLenderState = (d2) => (0, import_svm_kit18.decodeIdlAccount)(HUMA_IDL, "LenderState", d2);
|
|
65272
|
+
var decodeHumaRedemptionRequest = (d2) => (0, import_svm_kit18.decodeIdlAccount)(HUMA_IDL, "RedemptionRequest", d2);
|
|
65144
65273
|
function mintSupply2(data) {
|
|
65145
65274
|
if (data.length < 44) throw new Error("huma: mint account too short");
|
|
65146
65275
|
return data.slice(36, 44).reduce((a, b, i) => a | BigInt(b) << BigInt(8 * i), 0n);
|
|
@@ -65154,23 +65283,23 @@ var need2 = (a, what) => {
|
|
|
65154
65283
|
return a;
|
|
65155
65284
|
};
|
|
65156
65285
|
async function readHumaChainState(rpc, pool = HUMA_POOL) {
|
|
65157
|
-
const poolUnderlyingToken = await (0,
|
|
65286
|
+
const poolUnderlyingToken = await (0, import_svm_kit18.getAssociatedTokenAddress)(
|
|
65158
65287
|
await humaPoolAuthorityPda(),
|
|
65159
65288
|
pool.underlyingMint,
|
|
65160
|
-
|
|
65289
|
+
import_svm_kit18.TOKEN_PROGRAM
|
|
65161
65290
|
);
|
|
65162
65291
|
const { slot, accounts: first } = await rpc.readAccounts(
|
|
65163
65292
|
[pool.poolState, pool.poolConfig, poolUnderlyingToken],
|
|
65164
65293
|
{ encoding: "base64" }
|
|
65165
65294
|
);
|
|
65166
65295
|
const state = decodeHumaPoolState(
|
|
65167
|
-
(0,
|
|
65296
|
+
(0, import_svm_kit18.fromBase64)(need2(first[0], "pool_state").data[0])
|
|
65168
65297
|
);
|
|
65169
65298
|
const config = decodeHumaPoolConfig(
|
|
65170
|
-
(0,
|
|
65299
|
+
(0, import_svm_kit18.fromBase64)(need2(first[1], "pool_config").data[0])
|
|
65171
65300
|
);
|
|
65172
65301
|
const poolCash = tokenAmount2(
|
|
65173
|
-
first[2] ? (0,
|
|
65302
|
+
first[2] ? (0, import_svm_kit18.fromBase64)(first[2].data[0]) : void 0
|
|
65174
65303
|
);
|
|
65175
65304
|
const modeMints = await Promise.all(
|
|
65176
65305
|
state.mode_config_keys.map((k) => humaModeMintPda(k))
|
|
@@ -65185,9 +65314,9 @@ async function readHumaChainState(rpc, pool = HUMA_POOL) {
|
|
|
65185
65314
|
{ encoding: "base64" }
|
|
65186
65315
|
);
|
|
65187
65316
|
const modeConfig = decodeHumaModeConfig(
|
|
65188
|
-
(0,
|
|
65317
|
+
(0, import_svm_kit18.fromBase64)(need2(modeAcct, "mode_config").data[0])
|
|
65189
65318
|
);
|
|
65190
|
-
const mintData = (0,
|
|
65319
|
+
const mintData = (0, import_svm_kit18.fromBase64)(need2(mintAcct, "pst_mint").data[0]);
|
|
65191
65320
|
const next = state.redemption.next_request_id;
|
|
65192
65321
|
const last = state.redemption.last_request_id;
|
|
65193
65322
|
const gate = state.redemption.global_redemption_gating;
|
|
@@ -65244,7 +65373,7 @@ async function readHumaLenderState(rpc, modeConfig, wallet) {
|
|
|
65244
65373
|
const a = accounts[0];
|
|
65245
65374
|
return {
|
|
65246
65375
|
address,
|
|
65247
|
-
state: a ? decodeHumaLenderState((0,
|
|
65376
|
+
state: a ? decodeHumaLenderState((0, import_svm_kit18.fromBase64)(a.data[0])) : null
|
|
65248
65377
|
};
|
|
65249
65378
|
}
|
|
65250
65379
|
var HUMA_REDEMPTION_REQUEST_SIZE = 273;
|
|
@@ -65260,12 +65389,12 @@ async function readHumaRedemptionRequests(fetchers, wallet) {
|
|
|
65260
65389
|
);
|
|
65261
65390
|
return rows.map((r) => ({
|
|
65262
65391
|
address: r.pubkey,
|
|
65263
|
-
...decodeHumaRedemptionRequest((0,
|
|
65392
|
+
...decodeHumaRedemptionRequest((0, import_svm_kit18.fromBase64)(r.account.data[0]))
|
|
65264
65393
|
})).sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
65265
65394
|
}
|
|
65266
65395
|
|
|
65267
65396
|
// src/vaults/huma/fetchPublic.ts
|
|
65268
|
-
var
|
|
65397
|
+
var import_svm_kit19 = require("@1delta/svm-kit");
|
|
65269
65398
|
var SCALE2 = 10 ** HUMA_DECIMALS;
|
|
65270
65399
|
var fmt4 = (raw2) => Number(raw2) / SCALE2;
|
|
65271
65400
|
var HUMA_REDEMPTION_SLA_SECONDS = 7 * 86400;
|
|
@@ -65350,7 +65479,7 @@ function convertHumaPst(s, ctx) {
|
|
|
65350
65479
|
}
|
|
65351
65480
|
async function fetchHumaPstVaults(rpcOrOpts = {}) {
|
|
65352
65481
|
const opts = "readAccounts" in rpcOrOpts ? { rpc: rpcOrOpts } : rpcOrOpts;
|
|
65353
|
-
const rpc = opts.rpc ?? (0,
|
|
65482
|
+
const rpc = opts.rpc ?? (0, import_svm_kit19.createSvmRpc)();
|
|
65354
65483
|
const s = await readHumaChainState(rpc);
|
|
65355
65484
|
let priceUsd = opts.priceUsd;
|
|
65356
65485
|
if (priceUsd === void 0 && opts.fetchPrices !== false) {
|
|
@@ -65671,7 +65800,7 @@ async function fetchKaminoKvaults(opts = {}) {
|
|
|
65671
65800
|
|
|
65672
65801
|
// src/vaults/lst/fetchPublic.ts
|
|
65673
65802
|
init_types();
|
|
65674
|
-
var
|
|
65803
|
+
var import_svm_kit20 = require("@1delta/svm-kit");
|
|
65675
65804
|
var LAMPORTS_PER_SOL = 10 ** 9;
|
|
65676
65805
|
var TOKEN_SCALE = 10 ** 9;
|
|
65677
65806
|
var SPL_STAKE_POOL_LSTS = [
|
|
@@ -65734,7 +65863,7 @@ function convertLst(entry, pool, ctx, stakePoolAddress, programId, slot) {
|
|
|
65734
65863
|
provider: "lst",
|
|
65735
65864
|
chainId: SOLANA_CHAIN_ID,
|
|
65736
65865
|
address: pool.poolMint,
|
|
65737
|
-
underlying:
|
|
65866
|
+
underlying: import_svm_kit20.WRAPPED_SOL,
|
|
65738
65867
|
symbol: share.symbol ?? entry.symbol,
|
|
65739
65868
|
name: share.name ?? entry.name,
|
|
65740
65869
|
displayName: `${entry.curatorName} ${entry.symbol}`,
|
|
@@ -65798,7 +65927,7 @@ function convertLst(entry, pool, ctx, stakePoolAddress, programId, slot) {
|
|
|
65798
65927
|
};
|
|
65799
65928
|
}
|
|
65800
65929
|
async function fetchLstVaults(opts = {}) {
|
|
65801
|
-
const rpc = opts.rpc ?? (0,
|
|
65930
|
+
const rpc = opts.rpc ?? (0, import_svm_kit20.createSvmRpc)();
|
|
65802
65931
|
const entries = opts.entries ?? SPL_STAKE_POOL_LSTS;
|
|
65803
65932
|
const tokenList = opts.tokenList ?? {};
|
|
65804
65933
|
const { slot, pools } = await readStakePools(
|
|
@@ -65808,10 +65937,10 @@ async function fetchLstVaults(opts = {}) {
|
|
|
65808
65937
|
let solPriceUsd = opts.solPriceUsd;
|
|
65809
65938
|
if (solPriceUsd === void 0 && opts.fetchPrices !== false) {
|
|
65810
65939
|
solPriceUsd = await fetchJupiterPrices(
|
|
65811
|
-
[
|
|
65940
|
+
[import_svm_kit20.WRAPPED_SOL],
|
|
65812
65941
|
tokenList,
|
|
65813
65942
|
opts.priceApi
|
|
65814
|
-
).then((p) => p.byMint[
|
|
65943
|
+
).then((p) => p.byMint[import_svm_kit20.WRAPPED_SOL]).catch(() => void 0);
|
|
65815
65944
|
}
|
|
65816
65945
|
const found = pools.filter((p) => !!p);
|
|
65817
65946
|
const [epoch, reserves] = await Promise.all([
|
|
@@ -66268,7 +66397,7 @@ async function fetchJupiterLendOracleEntries(opts = {}) {
|
|
|
66268
66397
|
}
|
|
66269
66398
|
|
|
66270
66399
|
// src/prices/oracle-prices/fetchers/save.ts
|
|
66271
|
-
var
|
|
66400
|
+
var import_svm_kit21 = require("@1delta/svm-kit");
|
|
66272
66401
|
async function fetchSaveOracleEntries(opts = {}) {
|
|
66273
66402
|
const res = opts.publicData ?? await fetchSavePublic(opts);
|
|
66274
66403
|
const feeds = /* @__PURE__ */ new Set();
|
|
@@ -66280,7 +66409,7 @@ async function fetchSaveOracleEntries(opts = {}) {
|
|
|
66280
66409
|
const readings = /* @__PURE__ */ new Map();
|
|
66281
66410
|
if (opts.live !== false && feeds.size) {
|
|
66282
66411
|
try {
|
|
66283
|
-
const rpc = opts.rpc ?? (0,
|
|
66412
|
+
const rpc = opts.rpc ?? (0, import_svm_kit21.createSvmRpc)();
|
|
66284
66413
|
const keys = [...feeds];
|
|
66285
66414
|
const { accounts } = await rpc.readAccounts(keys, { encoding: "base64" });
|
|
66286
66415
|
accounts.forEach((a, i) => {
|
|
@@ -66711,7 +66840,7 @@ async function mintToReserve(api, market) {
|
|
|
66711
66840
|
|
|
66712
66841
|
// src/lending/user-data/kamino/onchain.ts
|
|
66713
66842
|
init_types();
|
|
66714
|
-
var
|
|
66843
|
+
var import_svm_kit22 = require("@1delta/svm-kit");
|
|
66715
66844
|
init_lenders();
|
|
66716
66845
|
var KLEND_OBLIGATION_SIZE = 3344;
|
|
66717
66846
|
var KLEND_OBLIGATION_DISCRIMINATOR = [
|
|
@@ -66730,7 +66859,7 @@ var SF = 60n;
|
|
|
66730
66859
|
var bsf = (b) => b.value.reduce((a, w, i) => a + (BigInt(w) << 64n * BigInt(i)), 0n);
|
|
66731
66860
|
var sfToNumber = (x) => Number(x >> 30n) / 2 ** 30;
|
|
66732
66861
|
function decodeKaminoObligation(address, data) {
|
|
66733
|
-
const o = (0,
|
|
66862
|
+
const o = (0, import_svm_kit22.decodeIdlAccount)(KLEND_IDL, "Obligation", data);
|
|
66734
66863
|
return {
|
|
66735
66864
|
address,
|
|
66736
66865
|
owner: o.owner,
|
|
@@ -66758,7 +66887,7 @@ function decodeKaminoObligation(address, data) {
|
|
|
66758
66887
|
};
|
|
66759
66888
|
}
|
|
66760
66889
|
function decodeKaminoReserveState(reserve, data) {
|
|
66761
|
-
const r = (0,
|
|
66890
|
+
const r = (0, import_svm_kit22.decodeIdlAccount)(KLEND_IDL, "Reserve", data);
|
|
66762
66891
|
const l = r.liquidity;
|
|
66763
66892
|
const totalSf = klendTotalSupplySf({
|
|
66764
66893
|
availableAmount: BigInt(l.totalAvailableAmount),
|
|
@@ -66931,15 +67060,15 @@ function valueKaminoObligations(account, obligations, reserves, groups = {}, acc
|
|
|
66931
67060
|
};
|
|
66932
67061
|
}
|
|
66933
67062
|
async function fetchKaminoUserOnchain(account, opts = {}) {
|
|
66934
|
-
const rpc = opts.rpc ?? (0,
|
|
66935
|
-
const hits = await (0,
|
|
67063
|
+
const rpc = opts.rpc ?? (0, import_svm_kit22.createSvmRpc)();
|
|
67064
|
+
const hits = await (0, import_svm_kit22.createSvmFetchers)(rpc).indexed.scanProgram(
|
|
66936
67065
|
KLEND_PROGRAM_ID,
|
|
66937
67066
|
[
|
|
66938
67067
|
{ dataSize: KLEND_OBLIGATION_SIZE },
|
|
66939
67068
|
{
|
|
66940
67069
|
memcmp: {
|
|
66941
67070
|
offset: 0,
|
|
66942
|
-
bytes: (0,
|
|
67071
|
+
bytes: (0, import_svm_kit22.encodeBase58)(Uint8Array.from(KLEND_OBLIGATION_DISCRIMINATOR))
|
|
66943
67072
|
}
|
|
66944
67073
|
},
|
|
66945
67074
|
{ memcmp: { offset: KLEND_OBLIGATION_OWNER_OFFSET, bytes: account } }
|
|
@@ -66950,7 +67079,7 @@ async function fetchKaminoUserOnchain(account, opts = {}) {
|
|
|
66950
67079
|
}
|
|
66951
67080
|
);
|
|
66952
67081
|
const markets = opts.markets && new Set(opts.markets);
|
|
66953
|
-
const obligations = hits.map((h) => decodeKaminoObligation(h.pubkey, (0,
|
|
67082
|
+
const obligations = hits.map((h) => decodeKaminoObligation(h.pubkey, (0, import_svm_kit22.fromBase64)(h.account.data[0]))).filter((o) => !markets || markets.has(o.market));
|
|
66954
67083
|
const reserves = { ...opts.reserves };
|
|
66955
67084
|
const need3 = [
|
|
66956
67085
|
...new Set(
|
|
@@ -66973,8 +67102,8 @@ async function fetchKaminoUserOnchain(account, opts = {}) {
|
|
|
66973
67102
|
const a = accounts2[i];
|
|
66974
67103
|
if (!a || a.owner !== KLEND_PROGRAM_ID) return;
|
|
66975
67104
|
if (i < need3.length)
|
|
66976
|
-
reserves[k] = decodeKaminoReserveState(k, (0,
|
|
66977
|
-
else groups[k] = readKlendElevationGroups((0,
|
|
67105
|
+
reserves[k] = decodeKaminoReserveState(k, (0, import_svm_kit22.fromBase64)(a.data[0]));
|
|
67106
|
+
else groups[k] = readKlendElevationGroups((0, import_svm_kit22.fromBase64)(a.data[0]));
|
|
66978
67107
|
});
|
|
66979
67108
|
}
|
|
66980
67109
|
const accounts = {};
|
|
@@ -67136,13 +67265,13 @@ async function fetchJupiterLendUser(account, opts = {}) {
|
|
|
67136
67265
|
}
|
|
67137
67266
|
|
|
67138
67267
|
// src/lending/user-data/save/obligation.ts
|
|
67139
|
-
var
|
|
67268
|
+
var import_svm_kit23 = require("@1delta/svm-kit");
|
|
67140
67269
|
function decodeSaveObligation(address, data) {
|
|
67141
67270
|
if (data.length !== SAVE_OBLIGATION_SIZE)
|
|
67142
67271
|
throw new Error(
|
|
67143
67272
|
`save obligation ${address}: ${data.length} bytes, expected ${SAVE_OBLIGATION_SIZE}`
|
|
67144
67273
|
);
|
|
67145
|
-
const r = new
|
|
67274
|
+
const r = new import_svm_kit23.BorshReader(data);
|
|
67146
67275
|
const version = r.u8();
|
|
67147
67276
|
const lastUpdateSlot = r.u64();
|
|
67148
67277
|
const stale = r.bool();
|
|
@@ -67207,8 +67336,8 @@ function saveObligationSeed(lendingMarket, index = 0) {
|
|
|
67207
67336
|
}
|
|
67208
67337
|
var sha256 = async (bytes2) => new Uint8Array(await crypto.subtle.digest("SHA-256", bytes2));
|
|
67209
67338
|
async function createWithSeed(base, seed, programId) {
|
|
67210
|
-
const b = (0,
|
|
67211
|
-
const p = (0,
|
|
67339
|
+
const b = (0, import_svm_kit23.decodeBase58)(base);
|
|
67340
|
+
const p = (0, import_svm_kit23.decodeBase58)(programId);
|
|
67212
67341
|
if (!b || b.length !== 32) throw new Error(`not a pubkey: ${base}`);
|
|
67213
67342
|
if (!p || p.length !== 32) throw new Error(`not a pubkey: ${programId}`);
|
|
67214
67343
|
const s = new TextEncoder().encode(seed);
|
|
@@ -67217,25 +67346,25 @@ async function createWithSeed(base, seed, programId) {
|
|
|
67217
67346
|
buf.set(b, 0);
|
|
67218
67347
|
buf.set(s, 32);
|
|
67219
67348
|
buf.set(p, 32 + s.length);
|
|
67220
|
-
return (0,
|
|
67349
|
+
return (0, import_svm_kit23.encodeBase58)(await sha256(buf));
|
|
67221
67350
|
}
|
|
67222
67351
|
var saveObligationAddress = (wallet, lendingMarket, index = 0, programId = SAVE_PROGRAM_ID) => createWithSeed(wallet, saveObligationSeed(lendingMarket, index), programId);
|
|
67223
67352
|
|
|
67224
67353
|
// src/lending/user-data/save/fetchUser.ts
|
|
67225
67354
|
init_types();
|
|
67226
|
-
var
|
|
67355
|
+
var import_svm_kit24 = require("@1delta/svm-kit");
|
|
67227
67356
|
init_lenders();
|
|
67228
67357
|
var SAVE_WALLET_POS_ID = "wallet";
|
|
67229
67358
|
var readTokenAmount = (bytes2, mint) => {
|
|
67230
67359
|
if (bytes2.length < 72) return void 0;
|
|
67231
|
-
if ((0,
|
|
67360
|
+
if ((0, import_svm_kit24.encodeBase58)(bytes2.subarray(0, 32)) !== mint) return void 0;
|
|
67232
67361
|
let v = 0n;
|
|
67233
67362
|
for (let i = 71; i >= 64; i--) v = v << 8n | BigInt(bytes2[i]);
|
|
67234
67363
|
return v;
|
|
67235
67364
|
};
|
|
67236
67365
|
async function fetchSaveUser(account, opts = {}) {
|
|
67237
67366
|
const api = createSaveApi(opts);
|
|
67238
|
-
const rpc = opts.rpc ?? (0,
|
|
67367
|
+
const rpc = opts.rpc ?? (0, import_svm_kit24.createSvmRpc)();
|
|
67239
67368
|
const configs = opts.configs ?? await api.marketConfigs();
|
|
67240
67369
|
const markets = selectSaveMarkets(configs, opts);
|
|
67241
67370
|
const step = Math.min(
|
|
@@ -67267,10 +67396,10 @@ async function fetchSaveUser(account, opts = {}) {
|
|
|
67267
67396
|
reserve,
|
|
67268
67397
|
market: c.market,
|
|
67269
67398
|
cTokenMint: c.collateralMint,
|
|
67270
|
-
address: await (0,
|
|
67399
|
+
address: await (0, import_svm_kit24.getAssociatedTokenAddress)(
|
|
67271
67400
|
account,
|
|
67272
67401
|
c.collateralMint,
|
|
67273
|
-
|
|
67402
|
+
import_svm_kit24.TOKEN_PROGRAM
|
|
67274
67403
|
)
|
|
67275
67404
|
}))
|
|
67276
67405
|
);
|
|
@@ -67291,7 +67420,7 @@ async function fetchSaveUser(account, opts = {}) {
|
|
|
67291
67420
|
const exists = !!a && a.owner === SAVE_PROGRAM_ID && typeof a.data?.[0] === "string";
|
|
67292
67421
|
(probed[key2] ??= []).push({ index: c.index, address: c.address, exists });
|
|
67293
67422
|
if (!exists) return;
|
|
67294
|
-
const bytes2 = (0,
|
|
67423
|
+
const bytes2 = (0, import_svm_kit24.fromBase64)(a.data[0]);
|
|
67295
67424
|
if (bytes2.length !== SAVE_OBLIGATION_SIZE) return;
|
|
67296
67425
|
found.push({ c, ob: decodeSaveObligation(c.address, bytes2) });
|
|
67297
67426
|
});
|
|
@@ -67312,9 +67441,9 @@ async function fetchSaveUser(account, opts = {}) {
|
|
|
67312
67441
|
const wallet = [];
|
|
67313
67442
|
ataCands.forEach((c, i) => {
|
|
67314
67443
|
const a = ataAccounts[i];
|
|
67315
|
-
if (!a || a.owner !==
|
|
67444
|
+
if (!a || a.owner !== import_svm_kit24.TOKEN_PROGRAM || typeof a.data?.[0] !== "string")
|
|
67316
67445
|
return;
|
|
67317
|
-
const amount = readTokenAmount((0,
|
|
67446
|
+
const amount = readTokenAmount((0, import_svm_kit24.fromBase64)(a.data[0]), c.cTokenMint);
|
|
67318
67447
|
if (amount && amount > 0n) wallet.push({ c, cTokens: amount });
|
|
67319
67448
|
});
|
|
67320
67449
|
const reserveIds = [
|
|
@@ -67594,7 +67723,7 @@ async function fetchSaveUser(account, opts = {}) {
|
|
|
67594
67723
|
}
|
|
67595
67724
|
|
|
67596
67725
|
// src/lending/user-data/loopscale/fetchUser.ts
|
|
67597
|
-
var
|
|
67726
|
+
var import_svm_kit25 = require("@1delta/svm-kit");
|
|
67598
67727
|
init_types();
|
|
67599
67728
|
var shortAddr = (a) => `${a.slice(0, 4)}\u2026${a.slice(-4)}`;
|
|
67600
67729
|
function convertLoopscaleUser(account, items, opts) {
|
|
@@ -67793,7 +67922,7 @@ async function fetchLoopscaleUser(account, opts = {}) {
|
|
|
67793
67922
|
];
|
|
67794
67923
|
if (unknown.length) {
|
|
67795
67924
|
try {
|
|
67796
|
-
const mints = await (0,
|
|
67925
|
+
const mints = await (0, import_svm_kit25.getMints)(opts.rpc ?? (0, import_svm_kit25.createSvmRpc)(), unknown);
|
|
67797
67926
|
mints.forEach((m, i) => {
|
|
67798
67927
|
if (m) decimals[unknown[i]] = m.decimals;
|
|
67799
67928
|
});
|
|
@@ -67813,17 +67942,17 @@ async function fetchLoopscaleUser(account, opts = {}) {
|
|
|
67813
67942
|
|
|
67814
67943
|
// src/lending/user-data/project0/fetchUser.ts
|
|
67815
67944
|
init_types();
|
|
67816
|
-
var
|
|
67945
|
+
var import_svm_kit26 = require("@1delta/svm-kit");
|
|
67817
67946
|
init_lenders();
|
|
67818
67947
|
var flagOn = (flags, bit) => (BigInt(flags) & bit) !== 0n;
|
|
67819
67948
|
async function fetchProject0User(account, opts = {}) {
|
|
67820
|
-
const rpc = opts.rpc ?? (0,
|
|
67949
|
+
const rpc = opts.rpc ?? (0, import_svm_kit26.createSvmRpc)();
|
|
67821
67950
|
const groups = opts.groups?.length ? opts.groups : [P0_MAIN_GROUP];
|
|
67822
67951
|
const pub = opts.publicData ?? await fetchProject0Public({ ...opts, rpc, groups });
|
|
67823
67952
|
const found = [];
|
|
67824
67953
|
let discovery = opts.discovery ?? "scan";
|
|
67825
67954
|
let readSlot = 0;
|
|
67826
|
-
const f = (0,
|
|
67955
|
+
const f = (0, import_svm_kit26.createSvmFetchers)(rpc);
|
|
67827
67956
|
for (const group of groups) {
|
|
67828
67957
|
if (discovery === "scan") {
|
|
67829
67958
|
try {
|
|
@@ -67833,7 +67962,7 @@ async function fetchProject0User(account, opts = {}) {
|
|
|
67833
67962
|
{
|
|
67834
67963
|
memcmp: {
|
|
67835
67964
|
offset: 0,
|
|
67836
|
-
bytes: (0,
|
|
67965
|
+
bytes: (0, import_svm_kit26.encodeBase58)(
|
|
67837
67966
|
Uint8Array.from(P0_MARGINFI_ACCOUNT_DISCRIMINATOR)
|
|
67838
67967
|
)
|
|
67839
67968
|
}
|
|
@@ -69437,6 +69566,7 @@ function project0TermAdapter(row, group) {
|
|
|
69437
69566
|
decodeHumaPoolConfig,
|
|
69438
69567
|
decodeHumaPoolState,
|
|
69439
69568
|
decodeHumaRedemptionRequest,
|
|
69569
|
+
decodeJlRateModel,
|
|
69440
69570
|
decodeJuniorUnlockShare,
|
|
69441
69571
|
decodeJupFlashloanAdmin,
|
|
69442
69572
|
decodeKaminoObligation,
|
|
@@ -69636,6 +69766,7 @@ function project0TermAdapter(row, group) {
|
|
|
69636
69766
|
readHumaChainState,
|
|
69637
69767
|
readHumaLenderState,
|
|
69638
69768
|
readHumaRedemptionRequests,
|
|
69769
|
+
readJlLayerIrms,
|
|
69639
69770
|
readJlNextVaultId,
|
|
69640
69771
|
readJupFlashAssets,
|
|
69641
69772
|
readJupFlashAvailable,
|