@1delta/margin-fetcher-sol 0.0.2 → 0.0.3
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 +338 -217
- package/dist/index.d.ts +338 -217
- package/dist/index.js +272 -143
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +133 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
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
|
});
|
|
@@ -37578,7 +37705,7 @@ async function fetchExponentPtMarkets(opts = {}) {
|
|
|
37578
37705
|
}
|
|
37579
37706
|
|
|
37580
37707
|
// src/vaults/solstice/accounts.ts
|
|
37581
|
-
var
|
|
37708
|
+
var import_svm_kit15 = require("@1delta/svm-kit");
|
|
37582
37709
|
|
|
37583
37710
|
// src/vaults/solstice/idl/yield_strategy.json
|
|
37584
37711
|
var yield_strategy_default = {
|
|
@@ -48249,12 +48376,12 @@ var SOLSTICE_DECIMALS = 6;
|
|
|
48249
48376
|
var SOLSTICE_PRICE_DECIMALS = 6;
|
|
48250
48377
|
var utf85 = (s) => new TextEncoder().encode(s);
|
|
48251
48378
|
var pk5 = (address) => {
|
|
48252
|
-
const b = (0,
|
|
48379
|
+
const b = (0, import_svm_kit15.decodeBase58)(address);
|
|
48253
48380
|
if (!b || b.length !== 32)
|
|
48254
48381
|
throw new Error(`solstice: not a 32-byte pubkey: ${address}`);
|
|
48255
48382
|
return b;
|
|
48256
48383
|
};
|
|
48257
|
-
var pda = async (seeds, programId) => (await (0,
|
|
48384
|
+
var pda = async (seeds, programId) => (await (0, import_svm_kit15.findProgramAddress)(seeds, programId)).address;
|
|
48258
48385
|
async function yieldVaultPdas(programId = SOLSTICE_PROGRAMS.yieldVault) {
|
|
48259
48386
|
const [controller, yieldPool, vestingSchedule, shareMint, assetVault] = await Promise.all(
|
|
48260
48387
|
[
|
|
@@ -48338,20 +48465,20 @@ var oracleCanonicalPda = (feedId, programId = SOLSTICE_PROGRAMS.oracle) => pda([
|
|
|
48338
48465
|
var strategyNameOf = (raw2) => new TextDecoder().decode(raw2).replace(/\0+$/, "");
|
|
48339
48466
|
var YV = SOLSTICE_YIELD_VAULT_IDL;
|
|
48340
48467
|
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,
|
|
48468
|
+
var decodeController = (d2) => (0, import_svm_kit15.decodeIdlAccount)(YV, "Controller", d2);
|
|
48469
|
+
var decodeYieldPool = (d2) => (0, import_svm_kit15.decodeIdlAccount)(YV, "YieldPool", d2);
|
|
48470
|
+
var decodeVestingSchedule = (d2) => (0, import_svm_kit15.decodeIdlAccount)(YV, "VestingSchedule", d2);
|
|
48471
|
+
var decodeCooldownEscrow = (d2) => (0, import_svm_kit15.decodeIdlAccount)(YV, "CooldownEscrow", d2);
|
|
48472
|
+
var decodeStrategyController = (d2) => (0, import_svm_kit15.decodeIdlAccount)(YS, "Controller", d2);
|
|
48473
|
+
var decodeStrategy = (d2) => (0, import_svm_kit15.decodeIdlAccount)(YS, "Strategy", d2);
|
|
48474
|
+
var decodeAccountingState = (d2) => (0, import_svm_kit15.decodeIdlAccount)(YS, "AccountingState", d2);
|
|
48475
|
+
var decodeSettlementBatch = (d2) => (0, import_svm_kit15.decodeIdlAccount)(YS, "SettlementBatch", d2);
|
|
48476
|
+
var decodeJuniorUnlockShare = (d2) => (0, import_svm_kit15.decodeIdlAccount)(YS, "JuniorUnlockShare", d2);
|
|
48477
|
+
var decodeSeniorUnlockCooldown = (d2) => (0, import_svm_kit15.decodeIdlAccount)(YS, "SeniorUnlockCooldown", d2);
|
|
48351
48478
|
function accountDiscriminator(idl, name) {
|
|
48352
48479
|
const a = idl.accounts.find((x) => x.name === name);
|
|
48353
48480
|
if (!a) throw new Error(`idl ${idl.metadata?.name}: no account ${name}`);
|
|
48354
|
-
return (0,
|
|
48481
|
+
return (0, import_svm_kit15.encodeBase58)(Uint8Array.from(a.discriminator));
|
|
48355
48482
|
}
|
|
48356
48483
|
var SETTLEMENT_BATCH_SIZE = 309;
|
|
48357
48484
|
var ORACLE_CANONICAL_SIZE = 365;
|
|
@@ -48394,7 +48521,7 @@ function tokenAmount(data) {
|
|
|
48394
48521
|
}
|
|
48395
48522
|
var need = (a, what) => {
|
|
48396
48523
|
if (!a) throw new Error(`solstice: ${what} account is missing`);
|
|
48397
|
-
return (0,
|
|
48524
|
+
return (0, import_svm_kit15.fromBase64)(a.data[0]);
|
|
48398
48525
|
};
|
|
48399
48526
|
async function readSolsticeChainState(rpc, opts = {}) {
|
|
48400
48527
|
const programs = { ...SOLSTICE_PROGRAMS, ...opts.programs };
|
|
@@ -48459,7 +48586,7 @@ async function readSolsticeChainState(rpc, opts = {}) {
|
|
|
48459
48586
|
const raw2 = r.accounts[j++];
|
|
48460
48587
|
s.oracleAccount = feeds[i];
|
|
48461
48588
|
if (raw2)
|
|
48462
|
-
s.oracle = decodeOracleCanonical((0,
|
|
48589
|
+
s.oracle = decodeOracleCanonical((0, import_svm_kit15.fromBase64)(raw2.data[0])) ?? void 0;
|
|
48463
48590
|
});
|
|
48464
48591
|
}
|
|
48465
48592
|
return { slot, yieldVault, strategies };
|
|
@@ -48572,12 +48699,12 @@ function strategyMode(s, oraclePriceUsd, priceDecimals = 6) {
|
|
|
48572
48699
|
|
|
48573
48700
|
// src/vaults/solstice/fetchPublic.ts
|
|
48574
48701
|
init_types();
|
|
48575
|
-
var
|
|
48702
|
+
var import_svm_kit16 = require("@1delta/svm-kit");
|
|
48576
48703
|
var SCALE = 10 ** SOLSTICE_DECIMALS;
|
|
48577
48704
|
var fmt3 = (raw2) => Number(raw2) / SCALE;
|
|
48578
48705
|
var BATCH_STATUS = ["active", "cancelled", "settled"];
|
|
48579
48706
|
async function fetchSolsticeSettlementBatches(rpc, strategyName, juniorQueueTimeSeconds, programId = SOLSTICE_PROGRAMS.yieldStrategy) {
|
|
48580
|
-
const fetchers = (0,
|
|
48707
|
+
const fetchers = (0, import_svm_kit16.createSvmFetchers)(rpc);
|
|
48581
48708
|
const rows = await fetchers.indexed.scanProgram(
|
|
48582
48709
|
programId,
|
|
48583
48710
|
[
|
|
@@ -48595,7 +48722,7 @@ async function fetchSolsticeSettlementBatches(rpc, strategyName, juniorQueueTime
|
|
|
48595
48722
|
);
|
|
48596
48723
|
const out = [];
|
|
48597
48724
|
for (const r of rows) {
|
|
48598
|
-
const b = decodeSettlementBatch((0,
|
|
48725
|
+
const b = decodeSettlementBatch((0, import_svm_kit16.fromBase64)(r.account.data[0]));
|
|
48599
48726
|
if (strategyNameOf(b.strategy_name) !== strategyName) continue;
|
|
48600
48727
|
const settlementTime = Number(b.settlement_time);
|
|
48601
48728
|
out.push({
|
|
@@ -48861,7 +48988,7 @@ function buildSolsticeVaults(state, ctx) {
|
|
|
48861
48988
|
return out;
|
|
48862
48989
|
}
|
|
48863
48990
|
async function fetchSolsticeVaults(opts = {}) {
|
|
48864
|
-
const rpc = opts.rpc ?? (0,
|
|
48991
|
+
const rpc = opts.rpc ?? (0, import_svm_kit16.createSvmRpc)();
|
|
48865
48992
|
const nowSecs = opts.nowSecs ?? Math.floor(Date.now() / 1e3);
|
|
48866
48993
|
const tokenList = opts.tokenList ?? {};
|
|
48867
48994
|
const state = await readSolsticeChainState(rpc, {
|
|
@@ -48900,15 +49027,15 @@ async function fetchSolsticeVaults(opts = {}) {
|
|
|
48900
49027
|
|
|
48901
49028
|
// src/vaults/solstice/fetchUser.ts
|
|
48902
49029
|
init_types();
|
|
48903
|
-
var
|
|
49030
|
+
var import_svm_kit17 = require("@1delta/svm-kit");
|
|
48904
49031
|
async function fetchSolsticeUser(account, opts = {}) {
|
|
48905
|
-
const rpc = opts.rpc ?? (0,
|
|
49032
|
+
const rpc = opts.rpc ?? (0, import_svm_kit17.createSvmRpc)();
|
|
48906
49033
|
const vaults = opts.vaults ?? await fetchSolsticeVaults({ ...opts, rpc });
|
|
48907
49034
|
const rows = Object.values(vaults);
|
|
48908
49035
|
const nowSecs = opts.nowSecs ?? Math.floor(Date.now() / 1e3);
|
|
48909
49036
|
const atas = await Promise.all(
|
|
48910
49037
|
rows.map(
|
|
48911
|
-
(r) => (0,
|
|
49038
|
+
(r) => (0, import_svm_kit17.getAssociatedTokenAddress)(account, r.address, import_svm_kit17.TOKEN_PROGRAM)
|
|
48912
49039
|
)
|
|
48913
49040
|
);
|
|
48914
49041
|
const eusx = rows.find((r) => r.kind === "yield-vault");
|
|
@@ -48938,7 +49065,7 @@ async function fetchSolsticeUser(account, opts = {}) {
|
|
|
48938
49065
|
const { slot, accounts } = await rpc.readAccounts(keys);
|
|
48939
49066
|
let i = 0;
|
|
48940
49067
|
const next = () => accounts[i++] ?? null;
|
|
48941
|
-
const bytes2 = (a) => a ? (0,
|
|
49068
|
+
const bytes2 = (a) => a ? (0, import_svm_kit17.fromBase64)(a.data[0]) : void 0;
|
|
48942
49069
|
const holdings = [];
|
|
48943
49070
|
rows.forEach((r, k) => {
|
|
48944
49071
|
const d2 = bytes2(next());
|
|
@@ -65101,7 +65228,7 @@ var HUMA_SEEDS = {
|
|
|
65101
65228
|
};
|
|
65102
65229
|
|
|
65103
65230
|
// src/vaults/huma/accounts.ts
|
|
65104
|
-
var
|
|
65231
|
+
var import_svm_kit18 = require("@1delta/svm-kit");
|
|
65105
65232
|
var HUMA_POOL = {
|
|
65106
65233
|
poolConfig: "28hFhD21Nka3stL27a8zZ4nRLgaDVxRYwJgeEVgeakzS",
|
|
65107
65234
|
poolId: "sFp7QFGknaW37xRFfdRwbC4QhM1n7Y9sJkYL4vnqXRn",
|
|
@@ -65116,11 +65243,11 @@ var HUMA_CLASSIC_MODE_ID = "Fr2BGzmFkufAUXNWSWk79juyWrHVCj8AbyzbbvZzhwgz";
|
|
|
65116
65243
|
var HUMA_DECIMALS = 6;
|
|
65117
65244
|
var utf86 = (s) => new TextEncoder().encode(s);
|
|
65118
65245
|
var pk6 = (address) => {
|
|
65119
|
-
const b = (0,
|
|
65246
|
+
const b = (0, import_svm_kit18.decodeBase58)(address);
|
|
65120
65247
|
if (!b || b.length !== 32) throw new Error(`huma: bad pubkey ${address}`);
|
|
65121
65248
|
return b;
|
|
65122
65249
|
};
|
|
65123
|
-
var pda2 = (seeds) => (0,
|
|
65250
|
+
var pda2 = (seeds) => (0, import_svm_kit18.findProgramAddress)(seeds, HUMA_PROGRAM).then((r) => r.address);
|
|
65124
65251
|
var humaPoolConfigPda = () => pda2([utf86("pool_config"), pk6(HUMA_POOL.poolId)]);
|
|
65125
65252
|
var humaPoolStatePda = () => pda2([utf86("pool_state"), pk6(HUMA_POOL.poolConfig)]);
|
|
65126
65253
|
var humaPoolAuthorityPda = () => pda2([utf86("pool_authority"), pk6(HUMA_POOL.poolConfig)]);
|
|
@@ -65136,11 +65263,11 @@ var u128be = (v) => {
|
|
|
65136
65263
|
out[15 - i] = Number(v >> BigInt(8 * i) & 0xffn);
|
|
65137
65264
|
return out;
|
|
65138
65265
|
};
|
|
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,
|
|
65266
|
+
var decodeHumaPoolState = (d2) => (0, import_svm_kit18.decodeIdlAccount)(HUMA_IDL, "PoolState", d2);
|
|
65267
|
+
var decodeHumaModeConfig = (d2) => (0, import_svm_kit18.decodeIdlAccount)(HUMA_IDL, "ModeConfig", d2);
|
|
65268
|
+
var decodeHumaPoolConfig = (d2) => (0, import_svm_kit18.decodeIdlAccount)(HUMA_IDL, "PoolConfig", d2);
|
|
65269
|
+
var decodeHumaLenderState = (d2) => (0, import_svm_kit18.decodeIdlAccount)(HUMA_IDL, "LenderState", d2);
|
|
65270
|
+
var decodeHumaRedemptionRequest = (d2) => (0, import_svm_kit18.decodeIdlAccount)(HUMA_IDL, "RedemptionRequest", d2);
|
|
65144
65271
|
function mintSupply2(data) {
|
|
65145
65272
|
if (data.length < 44) throw new Error("huma: mint account too short");
|
|
65146
65273
|
return data.slice(36, 44).reduce((a, b, i) => a | BigInt(b) << BigInt(8 * i), 0n);
|
|
@@ -65154,23 +65281,23 @@ var need2 = (a, what) => {
|
|
|
65154
65281
|
return a;
|
|
65155
65282
|
};
|
|
65156
65283
|
async function readHumaChainState(rpc, pool = HUMA_POOL) {
|
|
65157
|
-
const poolUnderlyingToken = await (0,
|
|
65284
|
+
const poolUnderlyingToken = await (0, import_svm_kit18.getAssociatedTokenAddress)(
|
|
65158
65285
|
await humaPoolAuthorityPda(),
|
|
65159
65286
|
pool.underlyingMint,
|
|
65160
|
-
|
|
65287
|
+
import_svm_kit18.TOKEN_PROGRAM
|
|
65161
65288
|
);
|
|
65162
65289
|
const { slot, accounts: first } = await rpc.readAccounts(
|
|
65163
65290
|
[pool.poolState, pool.poolConfig, poolUnderlyingToken],
|
|
65164
65291
|
{ encoding: "base64" }
|
|
65165
65292
|
);
|
|
65166
65293
|
const state = decodeHumaPoolState(
|
|
65167
|
-
(0,
|
|
65294
|
+
(0, import_svm_kit18.fromBase64)(need2(first[0], "pool_state").data[0])
|
|
65168
65295
|
);
|
|
65169
65296
|
const config = decodeHumaPoolConfig(
|
|
65170
|
-
(0,
|
|
65297
|
+
(0, import_svm_kit18.fromBase64)(need2(first[1], "pool_config").data[0])
|
|
65171
65298
|
);
|
|
65172
65299
|
const poolCash = tokenAmount2(
|
|
65173
|
-
first[2] ? (0,
|
|
65300
|
+
first[2] ? (0, import_svm_kit18.fromBase64)(first[2].data[0]) : void 0
|
|
65174
65301
|
);
|
|
65175
65302
|
const modeMints = await Promise.all(
|
|
65176
65303
|
state.mode_config_keys.map((k) => humaModeMintPda(k))
|
|
@@ -65185,9 +65312,9 @@ async function readHumaChainState(rpc, pool = HUMA_POOL) {
|
|
|
65185
65312
|
{ encoding: "base64" }
|
|
65186
65313
|
);
|
|
65187
65314
|
const modeConfig = decodeHumaModeConfig(
|
|
65188
|
-
(0,
|
|
65315
|
+
(0, import_svm_kit18.fromBase64)(need2(modeAcct, "mode_config").data[0])
|
|
65189
65316
|
);
|
|
65190
|
-
const mintData = (0,
|
|
65317
|
+
const mintData = (0, import_svm_kit18.fromBase64)(need2(mintAcct, "pst_mint").data[0]);
|
|
65191
65318
|
const next = state.redemption.next_request_id;
|
|
65192
65319
|
const last = state.redemption.last_request_id;
|
|
65193
65320
|
const gate = state.redemption.global_redemption_gating;
|
|
@@ -65244,7 +65371,7 @@ async function readHumaLenderState(rpc, modeConfig, wallet) {
|
|
|
65244
65371
|
const a = accounts[0];
|
|
65245
65372
|
return {
|
|
65246
65373
|
address,
|
|
65247
|
-
state: a ? decodeHumaLenderState((0,
|
|
65374
|
+
state: a ? decodeHumaLenderState((0, import_svm_kit18.fromBase64)(a.data[0])) : null
|
|
65248
65375
|
};
|
|
65249
65376
|
}
|
|
65250
65377
|
var HUMA_REDEMPTION_REQUEST_SIZE = 273;
|
|
@@ -65260,12 +65387,12 @@ async function readHumaRedemptionRequests(fetchers, wallet) {
|
|
|
65260
65387
|
);
|
|
65261
65388
|
return rows.map((r) => ({
|
|
65262
65389
|
address: r.pubkey,
|
|
65263
|
-
...decodeHumaRedemptionRequest((0,
|
|
65390
|
+
...decodeHumaRedemptionRequest((0, import_svm_kit18.fromBase64)(r.account.data[0]))
|
|
65264
65391
|
})).sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
65265
65392
|
}
|
|
65266
65393
|
|
|
65267
65394
|
// src/vaults/huma/fetchPublic.ts
|
|
65268
|
-
var
|
|
65395
|
+
var import_svm_kit19 = require("@1delta/svm-kit");
|
|
65269
65396
|
var SCALE2 = 10 ** HUMA_DECIMALS;
|
|
65270
65397
|
var fmt4 = (raw2) => Number(raw2) / SCALE2;
|
|
65271
65398
|
var HUMA_REDEMPTION_SLA_SECONDS = 7 * 86400;
|
|
@@ -65350,7 +65477,7 @@ function convertHumaPst(s, ctx) {
|
|
|
65350
65477
|
}
|
|
65351
65478
|
async function fetchHumaPstVaults(rpcOrOpts = {}) {
|
|
65352
65479
|
const opts = "readAccounts" in rpcOrOpts ? { rpc: rpcOrOpts } : rpcOrOpts;
|
|
65353
|
-
const rpc = opts.rpc ?? (0,
|
|
65480
|
+
const rpc = opts.rpc ?? (0, import_svm_kit19.createSvmRpc)();
|
|
65354
65481
|
const s = await readHumaChainState(rpc);
|
|
65355
65482
|
let priceUsd = opts.priceUsd;
|
|
65356
65483
|
if (priceUsd === void 0 && opts.fetchPrices !== false) {
|
|
@@ -65671,7 +65798,7 @@ async function fetchKaminoKvaults(opts = {}) {
|
|
|
65671
65798
|
|
|
65672
65799
|
// src/vaults/lst/fetchPublic.ts
|
|
65673
65800
|
init_types();
|
|
65674
|
-
var
|
|
65801
|
+
var import_svm_kit20 = require("@1delta/svm-kit");
|
|
65675
65802
|
var LAMPORTS_PER_SOL = 10 ** 9;
|
|
65676
65803
|
var TOKEN_SCALE = 10 ** 9;
|
|
65677
65804
|
var SPL_STAKE_POOL_LSTS = [
|
|
@@ -65734,7 +65861,7 @@ function convertLst(entry, pool, ctx, stakePoolAddress, programId, slot) {
|
|
|
65734
65861
|
provider: "lst",
|
|
65735
65862
|
chainId: SOLANA_CHAIN_ID,
|
|
65736
65863
|
address: pool.poolMint,
|
|
65737
|
-
underlying:
|
|
65864
|
+
underlying: import_svm_kit20.WRAPPED_SOL,
|
|
65738
65865
|
symbol: share.symbol ?? entry.symbol,
|
|
65739
65866
|
name: share.name ?? entry.name,
|
|
65740
65867
|
displayName: `${entry.curatorName} ${entry.symbol}`,
|
|
@@ -65798,7 +65925,7 @@ function convertLst(entry, pool, ctx, stakePoolAddress, programId, slot) {
|
|
|
65798
65925
|
};
|
|
65799
65926
|
}
|
|
65800
65927
|
async function fetchLstVaults(opts = {}) {
|
|
65801
|
-
const rpc = opts.rpc ?? (0,
|
|
65928
|
+
const rpc = opts.rpc ?? (0, import_svm_kit20.createSvmRpc)();
|
|
65802
65929
|
const entries = opts.entries ?? SPL_STAKE_POOL_LSTS;
|
|
65803
65930
|
const tokenList = opts.tokenList ?? {};
|
|
65804
65931
|
const { slot, pools } = await readStakePools(
|
|
@@ -65808,10 +65935,10 @@ async function fetchLstVaults(opts = {}) {
|
|
|
65808
65935
|
let solPriceUsd = opts.solPriceUsd;
|
|
65809
65936
|
if (solPriceUsd === void 0 && opts.fetchPrices !== false) {
|
|
65810
65937
|
solPriceUsd = await fetchJupiterPrices(
|
|
65811
|
-
[
|
|
65938
|
+
[import_svm_kit20.WRAPPED_SOL],
|
|
65812
65939
|
tokenList,
|
|
65813
65940
|
opts.priceApi
|
|
65814
|
-
).then((p) => p.byMint[
|
|
65941
|
+
).then((p) => p.byMint[import_svm_kit20.WRAPPED_SOL]).catch(() => void 0);
|
|
65815
65942
|
}
|
|
65816
65943
|
const found = pools.filter((p) => !!p);
|
|
65817
65944
|
const [epoch, reserves] = await Promise.all([
|
|
@@ -66268,7 +66395,7 @@ async function fetchJupiterLendOracleEntries(opts = {}) {
|
|
|
66268
66395
|
}
|
|
66269
66396
|
|
|
66270
66397
|
// src/prices/oracle-prices/fetchers/save.ts
|
|
66271
|
-
var
|
|
66398
|
+
var import_svm_kit21 = require("@1delta/svm-kit");
|
|
66272
66399
|
async function fetchSaveOracleEntries(opts = {}) {
|
|
66273
66400
|
const res = opts.publicData ?? await fetchSavePublic(opts);
|
|
66274
66401
|
const feeds = /* @__PURE__ */ new Set();
|
|
@@ -66280,7 +66407,7 @@ async function fetchSaveOracleEntries(opts = {}) {
|
|
|
66280
66407
|
const readings = /* @__PURE__ */ new Map();
|
|
66281
66408
|
if (opts.live !== false && feeds.size) {
|
|
66282
66409
|
try {
|
|
66283
|
-
const rpc = opts.rpc ?? (0,
|
|
66410
|
+
const rpc = opts.rpc ?? (0, import_svm_kit21.createSvmRpc)();
|
|
66284
66411
|
const keys = [...feeds];
|
|
66285
66412
|
const { accounts } = await rpc.readAccounts(keys, { encoding: "base64" });
|
|
66286
66413
|
accounts.forEach((a, i) => {
|
|
@@ -66711,7 +66838,7 @@ async function mintToReserve(api, market) {
|
|
|
66711
66838
|
|
|
66712
66839
|
// src/lending/user-data/kamino/onchain.ts
|
|
66713
66840
|
init_types();
|
|
66714
|
-
var
|
|
66841
|
+
var import_svm_kit22 = require("@1delta/svm-kit");
|
|
66715
66842
|
init_lenders();
|
|
66716
66843
|
var KLEND_OBLIGATION_SIZE = 3344;
|
|
66717
66844
|
var KLEND_OBLIGATION_DISCRIMINATOR = [
|
|
@@ -66730,7 +66857,7 @@ var SF = 60n;
|
|
|
66730
66857
|
var bsf = (b) => b.value.reduce((a, w, i) => a + (BigInt(w) << 64n * BigInt(i)), 0n);
|
|
66731
66858
|
var sfToNumber = (x) => Number(x >> 30n) / 2 ** 30;
|
|
66732
66859
|
function decodeKaminoObligation(address, data) {
|
|
66733
|
-
const o = (0,
|
|
66860
|
+
const o = (0, import_svm_kit22.decodeIdlAccount)(KLEND_IDL, "Obligation", data);
|
|
66734
66861
|
return {
|
|
66735
66862
|
address,
|
|
66736
66863
|
owner: o.owner,
|
|
@@ -66758,7 +66885,7 @@ function decodeKaminoObligation(address, data) {
|
|
|
66758
66885
|
};
|
|
66759
66886
|
}
|
|
66760
66887
|
function decodeKaminoReserveState(reserve, data) {
|
|
66761
|
-
const r = (0,
|
|
66888
|
+
const r = (0, import_svm_kit22.decodeIdlAccount)(KLEND_IDL, "Reserve", data);
|
|
66762
66889
|
const l = r.liquidity;
|
|
66763
66890
|
const totalSf = klendTotalSupplySf({
|
|
66764
66891
|
availableAmount: BigInt(l.totalAvailableAmount),
|
|
@@ -66931,15 +67058,15 @@ function valueKaminoObligations(account, obligations, reserves, groups = {}, acc
|
|
|
66931
67058
|
};
|
|
66932
67059
|
}
|
|
66933
67060
|
async function fetchKaminoUserOnchain(account, opts = {}) {
|
|
66934
|
-
const rpc = opts.rpc ?? (0,
|
|
66935
|
-
const hits = await (0,
|
|
67061
|
+
const rpc = opts.rpc ?? (0, import_svm_kit22.createSvmRpc)();
|
|
67062
|
+
const hits = await (0, import_svm_kit22.createSvmFetchers)(rpc).indexed.scanProgram(
|
|
66936
67063
|
KLEND_PROGRAM_ID,
|
|
66937
67064
|
[
|
|
66938
67065
|
{ dataSize: KLEND_OBLIGATION_SIZE },
|
|
66939
67066
|
{
|
|
66940
67067
|
memcmp: {
|
|
66941
67068
|
offset: 0,
|
|
66942
|
-
bytes: (0,
|
|
67069
|
+
bytes: (0, import_svm_kit22.encodeBase58)(Uint8Array.from(KLEND_OBLIGATION_DISCRIMINATOR))
|
|
66943
67070
|
}
|
|
66944
67071
|
},
|
|
66945
67072
|
{ memcmp: { offset: KLEND_OBLIGATION_OWNER_OFFSET, bytes: account } }
|
|
@@ -66950,7 +67077,7 @@ async function fetchKaminoUserOnchain(account, opts = {}) {
|
|
|
66950
67077
|
}
|
|
66951
67078
|
);
|
|
66952
67079
|
const markets = opts.markets && new Set(opts.markets);
|
|
66953
|
-
const obligations = hits.map((h) => decodeKaminoObligation(h.pubkey, (0,
|
|
67080
|
+
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
67081
|
const reserves = { ...opts.reserves };
|
|
66955
67082
|
const need3 = [
|
|
66956
67083
|
...new Set(
|
|
@@ -66973,8 +67100,8 @@ async function fetchKaminoUserOnchain(account, opts = {}) {
|
|
|
66973
67100
|
const a = accounts2[i];
|
|
66974
67101
|
if (!a || a.owner !== KLEND_PROGRAM_ID) return;
|
|
66975
67102
|
if (i < need3.length)
|
|
66976
|
-
reserves[k] = decodeKaminoReserveState(k, (0,
|
|
66977
|
-
else groups[k] = readKlendElevationGroups((0,
|
|
67103
|
+
reserves[k] = decodeKaminoReserveState(k, (0, import_svm_kit22.fromBase64)(a.data[0]));
|
|
67104
|
+
else groups[k] = readKlendElevationGroups((0, import_svm_kit22.fromBase64)(a.data[0]));
|
|
66978
67105
|
});
|
|
66979
67106
|
}
|
|
66980
67107
|
const accounts = {};
|
|
@@ -67136,13 +67263,13 @@ async function fetchJupiterLendUser(account, opts = {}) {
|
|
|
67136
67263
|
}
|
|
67137
67264
|
|
|
67138
67265
|
// src/lending/user-data/save/obligation.ts
|
|
67139
|
-
var
|
|
67266
|
+
var import_svm_kit23 = require("@1delta/svm-kit");
|
|
67140
67267
|
function decodeSaveObligation(address, data) {
|
|
67141
67268
|
if (data.length !== SAVE_OBLIGATION_SIZE)
|
|
67142
67269
|
throw new Error(
|
|
67143
67270
|
`save obligation ${address}: ${data.length} bytes, expected ${SAVE_OBLIGATION_SIZE}`
|
|
67144
67271
|
);
|
|
67145
|
-
const r = new
|
|
67272
|
+
const r = new import_svm_kit23.BorshReader(data);
|
|
67146
67273
|
const version = r.u8();
|
|
67147
67274
|
const lastUpdateSlot = r.u64();
|
|
67148
67275
|
const stale = r.bool();
|
|
@@ -67207,8 +67334,8 @@ function saveObligationSeed(lendingMarket, index = 0) {
|
|
|
67207
67334
|
}
|
|
67208
67335
|
var sha256 = async (bytes2) => new Uint8Array(await crypto.subtle.digest("SHA-256", bytes2));
|
|
67209
67336
|
async function createWithSeed(base, seed, programId) {
|
|
67210
|
-
const b = (0,
|
|
67211
|
-
const p = (0,
|
|
67337
|
+
const b = (0, import_svm_kit23.decodeBase58)(base);
|
|
67338
|
+
const p = (0, import_svm_kit23.decodeBase58)(programId);
|
|
67212
67339
|
if (!b || b.length !== 32) throw new Error(`not a pubkey: ${base}`);
|
|
67213
67340
|
if (!p || p.length !== 32) throw new Error(`not a pubkey: ${programId}`);
|
|
67214
67341
|
const s = new TextEncoder().encode(seed);
|
|
@@ -67217,25 +67344,25 @@ async function createWithSeed(base, seed, programId) {
|
|
|
67217
67344
|
buf.set(b, 0);
|
|
67218
67345
|
buf.set(s, 32);
|
|
67219
67346
|
buf.set(p, 32 + s.length);
|
|
67220
|
-
return (0,
|
|
67347
|
+
return (0, import_svm_kit23.encodeBase58)(await sha256(buf));
|
|
67221
67348
|
}
|
|
67222
67349
|
var saveObligationAddress = (wallet, lendingMarket, index = 0, programId = SAVE_PROGRAM_ID) => createWithSeed(wallet, saveObligationSeed(lendingMarket, index), programId);
|
|
67223
67350
|
|
|
67224
67351
|
// src/lending/user-data/save/fetchUser.ts
|
|
67225
67352
|
init_types();
|
|
67226
|
-
var
|
|
67353
|
+
var import_svm_kit24 = require("@1delta/svm-kit");
|
|
67227
67354
|
init_lenders();
|
|
67228
67355
|
var SAVE_WALLET_POS_ID = "wallet";
|
|
67229
67356
|
var readTokenAmount = (bytes2, mint) => {
|
|
67230
67357
|
if (bytes2.length < 72) return void 0;
|
|
67231
|
-
if ((0,
|
|
67358
|
+
if ((0, import_svm_kit24.encodeBase58)(bytes2.subarray(0, 32)) !== mint) return void 0;
|
|
67232
67359
|
let v = 0n;
|
|
67233
67360
|
for (let i = 71; i >= 64; i--) v = v << 8n | BigInt(bytes2[i]);
|
|
67234
67361
|
return v;
|
|
67235
67362
|
};
|
|
67236
67363
|
async function fetchSaveUser(account, opts = {}) {
|
|
67237
67364
|
const api = createSaveApi(opts);
|
|
67238
|
-
const rpc = opts.rpc ?? (0,
|
|
67365
|
+
const rpc = opts.rpc ?? (0, import_svm_kit24.createSvmRpc)();
|
|
67239
67366
|
const configs = opts.configs ?? await api.marketConfigs();
|
|
67240
67367
|
const markets = selectSaveMarkets(configs, opts);
|
|
67241
67368
|
const step = Math.min(
|
|
@@ -67267,10 +67394,10 @@ async function fetchSaveUser(account, opts = {}) {
|
|
|
67267
67394
|
reserve,
|
|
67268
67395
|
market: c.market,
|
|
67269
67396
|
cTokenMint: c.collateralMint,
|
|
67270
|
-
address: await (0,
|
|
67397
|
+
address: await (0, import_svm_kit24.getAssociatedTokenAddress)(
|
|
67271
67398
|
account,
|
|
67272
67399
|
c.collateralMint,
|
|
67273
|
-
|
|
67400
|
+
import_svm_kit24.TOKEN_PROGRAM
|
|
67274
67401
|
)
|
|
67275
67402
|
}))
|
|
67276
67403
|
);
|
|
@@ -67291,7 +67418,7 @@ async function fetchSaveUser(account, opts = {}) {
|
|
|
67291
67418
|
const exists = !!a && a.owner === SAVE_PROGRAM_ID && typeof a.data?.[0] === "string";
|
|
67292
67419
|
(probed[key2] ??= []).push({ index: c.index, address: c.address, exists });
|
|
67293
67420
|
if (!exists) return;
|
|
67294
|
-
const bytes2 = (0,
|
|
67421
|
+
const bytes2 = (0, import_svm_kit24.fromBase64)(a.data[0]);
|
|
67295
67422
|
if (bytes2.length !== SAVE_OBLIGATION_SIZE) return;
|
|
67296
67423
|
found.push({ c, ob: decodeSaveObligation(c.address, bytes2) });
|
|
67297
67424
|
});
|
|
@@ -67312,9 +67439,9 @@ async function fetchSaveUser(account, opts = {}) {
|
|
|
67312
67439
|
const wallet = [];
|
|
67313
67440
|
ataCands.forEach((c, i) => {
|
|
67314
67441
|
const a = ataAccounts[i];
|
|
67315
|
-
if (!a || a.owner !==
|
|
67442
|
+
if (!a || a.owner !== import_svm_kit24.TOKEN_PROGRAM || typeof a.data?.[0] !== "string")
|
|
67316
67443
|
return;
|
|
67317
|
-
const amount = readTokenAmount((0,
|
|
67444
|
+
const amount = readTokenAmount((0, import_svm_kit24.fromBase64)(a.data[0]), c.cTokenMint);
|
|
67318
67445
|
if (amount && amount > 0n) wallet.push({ c, cTokens: amount });
|
|
67319
67446
|
});
|
|
67320
67447
|
const reserveIds = [
|
|
@@ -67594,7 +67721,7 @@ async function fetchSaveUser(account, opts = {}) {
|
|
|
67594
67721
|
}
|
|
67595
67722
|
|
|
67596
67723
|
// src/lending/user-data/loopscale/fetchUser.ts
|
|
67597
|
-
var
|
|
67724
|
+
var import_svm_kit25 = require("@1delta/svm-kit");
|
|
67598
67725
|
init_types();
|
|
67599
67726
|
var shortAddr = (a) => `${a.slice(0, 4)}\u2026${a.slice(-4)}`;
|
|
67600
67727
|
function convertLoopscaleUser(account, items, opts) {
|
|
@@ -67793,7 +67920,7 @@ async function fetchLoopscaleUser(account, opts = {}) {
|
|
|
67793
67920
|
];
|
|
67794
67921
|
if (unknown.length) {
|
|
67795
67922
|
try {
|
|
67796
|
-
const mints = await (0,
|
|
67923
|
+
const mints = await (0, import_svm_kit25.getMints)(opts.rpc ?? (0, import_svm_kit25.createSvmRpc)(), unknown);
|
|
67797
67924
|
mints.forEach((m, i) => {
|
|
67798
67925
|
if (m) decimals[unknown[i]] = m.decimals;
|
|
67799
67926
|
});
|
|
@@ -67813,17 +67940,17 @@ async function fetchLoopscaleUser(account, opts = {}) {
|
|
|
67813
67940
|
|
|
67814
67941
|
// src/lending/user-data/project0/fetchUser.ts
|
|
67815
67942
|
init_types();
|
|
67816
|
-
var
|
|
67943
|
+
var import_svm_kit26 = require("@1delta/svm-kit");
|
|
67817
67944
|
init_lenders();
|
|
67818
67945
|
var flagOn = (flags, bit) => (BigInt(flags) & bit) !== 0n;
|
|
67819
67946
|
async function fetchProject0User(account, opts = {}) {
|
|
67820
|
-
const rpc = opts.rpc ?? (0,
|
|
67947
|
+
const rpc = opts.rpc ?? (0, import_svm_kit26.createSvmRpc)();
|
|
67821
67948
|
const groups = opts.groups?.length ? opts.groups : [P0_MAIN_GROUP];
|
|
67822
67949
|
const pub = opts.publicData ?? await fetchProject0Public({ ...opts, rpc, groups });
|
|
67823
67950
|
const found = [];
|
|
67824
67951
|
let discovery = opts.discovery ?? "scan";
|
|
67825
67952
|
let readSlot = 0;
|
|
67826
|
-
const f = (0,
|
|
67953
|
+
const f = (0, import_svm_kit26.createSvmFetchers)(rpc);
|
|
67827
67954
|
for (const group of groups) {
|
|
67828
67955
|
if (discovery === "scan") {
|
|
67829
67956
|
try {
|
|
@@ -67833,7 +67960,7 @@ async function fetchProject0User(account, opts = {}) {
|
|
|
67833
67960
|
{
|
|
67834
67961
|
memcmp: {
|
|
67835
67962
|
offset: 0,
|
|
67836
|
-
bytes: (0,
|
|
67963
|
+
bytes: (0, import_svm_kit26.encodeBase58)(
|
|
67837
67964
|
Uint8Array.from(P0_MARGINFI_ACCOUNT_DISCRIMINATOR)
|
|
67838
67965
|
)
|
|
67839
67966
|
}
|
|
@@ -69437,6 +69564,7 @@ function project0TermAdapter(row, group) {
|
|
|
69437
69564
|
decodeHumaPoolConfig,
|
|
69438
69565
|
decodeHumaPoolState,
|
|
69439
69566
|
decodeHumaRedemptionRequest,
|
|
69567
|
+
decodeJlRateModel,
|
|
69440
69568
|
decodeJuniorUnlockShare,
|
|
69441
69569
|
decodeJupFlashloanAdmin,
|
|
69442
69570
|
decodeKaminoObligation,
|
|
@@ -69636,6 +69764,7 @@ function project0TermAdapter(row, group) {
|
|
|
69636
69764
|
readHumaChainState,
|
|
69637
69765
|
readHumaLenderState,
|
|
69638
69766
|
readHumaRedemptionRequests,
|
|
69767
|
+
readJlLayerIrms,
|
|
69639
69768
|
readJlNextVaultId,
|
|
69640
69769
|
readJupFlashAssets,
|
|
69641
69770
|
readJupFlashAvailable,
|