@1delta/margin-fetcher-sol 0.0.1 → 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/README.md +63 -0
- package/dist/index.d.mts +718 -34
- package/dist/index.d.ts +718 -34
- package/dist/index.js +2835 -776
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2782 -745
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -7855,6 +7855,8 @@ var RESERVE = {
|
|
|
7855
7855
|
maxLiquidationBonusBps: 4876,
|
|
7856
7856
|
originationFeeSf: 4896,
|
|
7857
7857
|
flashLoanFeeSf: 4904,
|
|
7858
|
+
// config.borrowRateCurve — 11 × CurvePoint { utilizationRateBps u32, borrowRateBps u32 }, after fees' 8 padding bytes
|
|
7859
|
+
borrowRateCurve: 4920,
|
|
7858
7860
|
borrowFactorPct: 5008,
|
|
7859
7861
|
depositLimit: 5016,
|
|
7860
7862
|
borrowLimit: 5024,
|
|
@@ -7997,6 +7999,14 @@ function readKlendReserveChain(reserve, data) {
|
|
|
7997
7999
|
debtWithdrawalCap: withdrawalCap(data, RESERVE.debtWithdrawalCap),
|
|
7998
8000
|
disableUsageAsCollOutsideEmode: data[RESERVE.disableUsageAsCollOutsideEmode] !== 0,
|
|
7999
8001
|
utilizationLimitBlockBorrowingAbovePct: data[RESERVE.utilizationLimitBlockBorrowingAbovePct],
|
|
8002
|
+
borrowRateCurve: Array.from({ length: 11 }, (_, i) => {
|
|
8003
|
+
const v = new DataView(data.buffer, data.byteOffset);
|
|
8004
|
+
const off = RESERVE.borrowRateCurve + 8 * i;
|
|
8005
|
+
return [
|
|
8006
|
+
v.getUint32(off, true) / 1e4,
|
|
8007
|
+
v.getUint32(off + 4, true) / 1e4
|
|
8008
|
+
];
|
|
8009
|
+
}),
|
|
8000
8010
|
borrowLimitOutsideElevationGroup: u64(
|
|
8001
8011
|
data,
|
|
8002
8012
|
RESERVE.borrowLimitOutsideElevationGroup
|
|
@@ -8487,6 +8497,15 @@ function exchangeRateOf(inp) {
|
|
|
8487
8497
|
if (!t || !s || t.num <= 0n || s.num <= 0n) return { num: 1n, den: 1n };
|
|
8488
8498
|
return { num: t.num * s.den, den: t.den * s.num };
|
|
8489
8499
|
}
|
|
8500
|
+
function dedupeKnots(knots) {
|
|
8501
|
+
const out = [];
|
|
8502
|
+
for (const k of knots) {
|
|
8503
|
+
const last = out[out.length - 1];
|
|
8504
|
+
if (last && last[0] === k[0] && last[1] === k[1]) continue;
|
|
8505
|
+
out.push(k);
|
|
8506
|
+
}
|
|
8507
|
+
return out;
|
|
8508
|
+
}
|
|
8490
8509
|
function convertKaminoReserve(inp, ctx) {
|
|
8491
8510
|
const { stats, metrics, detail, chain } = inp;
|
|
8492
8511
|
const mint = chain?.mint ?? stats.token;
|
|
@@ -8584,7 +8603,12 @@ function convertKaminoReserve(inp, ctx) {
|
|
|
8584
8603
|
interestRateBasis: stats.interestRateBasis,
|
|
8585
8604
|
protocolTakeRatePct: stats.protocolTakeRatePct,
|
|
8586
8605
|
hostFixedInterestRateBps: stats.hostFixedInterestRateBps,
|
|
8587
|
-
borrowCurve: detail.borrowCurve,
|
|
8606
|
+
borrowCurve: chain ? dedupeKnots(chain.borrowRateCurve) : detail.borrowCurve,
|
|
8607
|
+
borrowCurveSource: chain ? "chain" : "api",
|
|
8608
|
+
...stats.interestRateBasis === "legacy" && ctx.slotSeconds ? { slotSeconds: ctx.slotSeconds } : {},
|
|
8609
|
+
...chain ? {
|
|
8610
|
+
utilizationLimitBlockBorrowingAbovePct: chain.utilizationLimitBlockBorrowingAbovePct
|
|
8611
|
+
} : {},
|
|
8588
8612
|
autoDeleverage: stats.autoDeleverage,
|
|
8589
8613
|
source: chain ? "chain" : "api",
|
|
8590
8614
|
maxLiquidationBonus: chain ? chain.maxLiquidationBonusBps / 1e4 : num(detail.maxLiquidationBonus),
|
|
@@ -8630,6 +8654,7 @@ function convertKaminoMarket(inp) {
|
|
|
8630
8654
|
closeFactor,
|
|
8631
8655
|
chainMarket: inp.chainMarket,
|
|
8632
8656
|
slot: inp.slot,
|
|
8657
|
+
slotSeconds: inp.slotSeconds,
|
|
8633
8658
|
tokenList: inp.tokenList
|
|
8634
8659
|
});
|
|
8635
8660
|
data[row.marketUid] = row;
|
|
@@ -8645,6 +8670,7 @@ function convertKaminoMarket(inp) {
|
|
|
8645
8670
|
}
|
|
8646
8671
|
|
|
8647
8672
|
// src/lending/public-data/kamino/fetchPublic.ts
|
|
8673
|
+
import { measureSlotSeconds } from "@1delta/svm-kit";
|
|
8648
8674
|
async function fetchKaminoPublic(opts = {}) {
|
|
8649
8675
|
const api = createKaminoApi(opts);
|
|
8650
8676
|
const { markets, metricsByMarket } = await listServedMarkets(api, opts);
|
|
@@ -8711,6 +8737,7 @@ async function fetchKaminoPublic(opts = {}) {
|
|
|
8711
8737
|
return false;
|
|
8712
8738
|
});
|
|
8713
8739
|
const rpc = opts.rpc;
|
|
8740
|
+
const slotSeconds = opts.slotSeconds ?? (rpc ? await measureSlotSeconds(rpc) : void 0);
|
|
8714
8741
|
const chainReads = await Promise.all(
|
|
8715
8742
|
served.map(async (mr) => {
|
|
8716
8743
|
if (!rpc) return void 0;
|
|
@@ -8743,7 +8770,8 @@ async function fetchKaminoPublic(opts = {}) {
|
|
|
8743
8770
|
reserves,
|
|
8744
8771
|
...chain?.market ? { chainMarket: chain.market, slot: chain.slot } : {},
|
|
8745
8772
|
leveragePairs: mr.leveragePairs,
|
|
8746
|
-
tokenList: opts.tokenList
|
|
8773
|
+
tokenList: opts.tokenList,
|
|
8774
|
+
slotSeconds
|
|
8747
8775
|
});
|
|
8748
8776
|
out[conv.lenderKey] = {
|
|
8749
8777
|
chainId: conv.chainId,
|
|
@@ -8792,494 +8820,1076 @@ function createJupiterLendApi(opts = {}) {
|
|
|
8792
8820
|
};
|
|
8793
8821
|
}
|
|
8794
8822
|
|
|
8795
|
-
// src/lending/public-data/jupiter-lend/
|
|
8796
|
-
var JL_FACTOR_SCALE = 1e3;
|
|
8797
|
-
var JL_BPS = 1e4;
|
|
8798
|
-
var JL_ORACLE_DECIMALS = 15;
|
|
8799
|
-
var JL_ORACLE_SCALE = 10 ** JL_ORACLE_DECIMALS;
|
|
8800
|
-
var FLUID_ORACLE_DECIMALS = 27;
|
|
8801
|
-
var FLUID_VAULT_TYPE_T1 = 1e4;
|
|
8802
|
-
var bpsToPercent = (v) => num(v) / 100;
|
|
8803
|
-
var jlOraclePriceInBorrow = (raw2) => num(raw2) / JL_ORACLE_SCALE;
|
|
8804
|
-
function jlOracleToFluidRaw(raw2, colDecimals, debtDecimals) {
|
|
8805
|
-
if (typeof raw2 !== "string" || !/^\d+$/.test(raw2)) return void 0;
|
|
8806
|
-
const exp = FLUID_ORACLE_DECIMALS - JL_ORACLE_DECIMALS + debtDecimals - colDecimals;
|
|
8807
|
-
const v = BigInt(raw2);
|
|
8808
|
-
return (exp >= 0 ? v * 10n ** BigInt(exp) : v / 10n ** BigInt(-exp)).toString();
|
|
8809
|
-
}
|
|
8810
|
-
function formatRawUnits(raw2, decimals) {
|
|
8811
|
-
let v;
|
|
8812
|
-
try {
|
|
8813
|
-
v = BigInt(raw2 ?? 0);
|
|
8814
|
-
} catch {
|
|
8815
|
-
return "0";
|
|
8816
|
-
}
|
|
8817
|
-
const neg = v < 0n;
|
|
8818
|
-
if (neg) v = -v;
|
|
8819
|
-
const base = 10n ** BigInt(decimals);
|
|
8820
|
-
const whole = v / base;
|
|
8821
|
-
const frac = (v % base).toString().padStart(decimals, "0").replace(/0+$/, "");
|
|
8822
|
-
return `${neg ? "-" : ""}${whole}${frac ? `.${frac}` : ""}`;
|
|
8823
|
-
}
|
|
8824
|
-
function deriveLayerTotals(vaults, earn) {
|
|
8825
|
-
const t = {};
|
|
8826
|
-
const slot = (mint, decimals) => t[mint] ??= { supply: 0n, borrow: 0n, decimals };
|
|
8827
|
-
for (const e of earn)
|
|
8828
|
-
slot(e.assetAddress, e.asset.decimals).supply += BigInt(
|
|
8829
|
-
e.liquiditySupplyData.supply || "0"
|
|
8830
|
-
);
|
|
8831
|
-
for (const v of vaults) {
|
|
8832
|
-
slot(v.supplyToken.address, v.supplyToken.decimals).supply += BigInt(
|
|
8833
|
-
v.liquiditySupplyData.supply || "0"
|
|
8834
|
-
);
|
|
8835
|
-
slot(v.borrowToken.address, v.borrowToken.decimals).borrow += BigInt(
|
|
8836
|
-
v.liquidityBorrowData.borrow || "0"
|
|
8837
|
-
);
|
|
8838
|
-
}
|
|
8839
|
-
return t;
|
|
8840
|
-
}
|
|
8841
|
-
var fmt = (raw2, decimals) => Number(raw2) / 10 ** decimals;
|
|
8842
|
-
var jupiterLendCurrency = (t, listed3) => {
|
|
8843
|
-
const base = listed3 ?? {
|
|
8844
|
-
chainId: SOLANA_CHAIN_ID,
|
|
8845
|
-
address: t.address,
|
|
8846
|
-
symbol: t.uiSymbol ?? t.symbol,
|
|
8847
|
-
name: t.name,
|
|
8848
|
-
decimals: t.decimals
|
|
8849
|
-
};
|
|
8850
|
-
return { ...base, assetGroup: base.assetGroup || `solana-${t.address}` };
|
|
8851
|
-
};
|
|
8852
|
-
function convertJupiterLendVault(market, v, opts = {}) {
|
|
8853
|
-
const lenderKey = jupiterLendVaultKey(market, v.id);
|
|
8854
|
-
const sup = v.supplyToken;
|
|
8855
|
-
const bor = v.borrowToken;
|
|
8856
|
-
const supPrice = num(sup.price);
|
|
8857
|
-
const borPrice = num(bor.price);
|
|
8858
|
-
const ltv = num(v.collateralFactor) / JL_FACTOR_SCALE;
|
|
8859
|
-
const lt = num(v.liquidationThreshold) / JL_FACTOR_SCALE;
|
|
8860
|
-
const penalty = num(v.liquidationPenalty) / JL_BPS;
|
|
8861
|
-
const supAsset = jupiterLendCurrency(sup, opts.tokenList?.[sup.address]);
|
|
8862
|
-
const borAsset = jupiterLendCurrency(bor, opts.tokenList?.[bor.address]);
|
|
8863
|
-
const supSym = supAsset.symbol ?? sup.symbol;
|
|
8864
|
-
const borSym = borAsset.symbol ?? bor.symbol;
|
|
8865
|
-
const label = `${supSym} / ${borSym} \xB7 vault #${v.id}`;
|
|
8866
|
-
const intrinsic = (a) => opts.intrinsicYields?.[a.assetGroup] ?? 0;
|
|
8867
|
-
const layerOf = (mint) => {
|
|
8868
|
-
const l = opts.layer?.[mint];
|
|
8869
|
-
if (!l || l.supply === 0n) return { utilization: 0 };
|
|
8870
|
-
return {
|
|
8871
|
-
utilization: Number(l.borrow * 10000n / l.supply) / 1e4,
|
|
8872
|
-
irmTotalDeposits: fmt(l.supply, l.decimals),
|
|
8873
|
-
irmTotalDebt: fmt(l.borrow, l.decimals)
|
|
8874
|
-
};
|
|
8875
|
-
};
|
|
8876
|
-
const totalSupply = BigInt(v.totalSupply || "0");
|
|
8877
|
-
const withdrawLimit = BigInt(v.withdrawLimit || "0");
|
|
8878
|
-
const lockupRatio = totalSupply > 0n ? Number(withdrawLimit * 10000n / totalSupply) / 1e4 : 0;
|
|
8879
|
-
const supplyDeposits = fmt(v.totalSupply, sup.decimals);
|
|
8880
|
-
const borrowDebt = fmt(v.totalBorrow, bor.decimals);
|
|
8881
|
-
const borrowable = fmt(v.borrowable, bor.decimals);
|
|
8882
|
-
const collateralConfig = {
|
|
8883
|
-
category: 0,
|
|
8884
|
-
label,
|
|
8885
|
-
borrowCollateralFactor: ltv,
|
|
8886
|
-
collateralFactor: lt,
|
|
8887
|
-
borrowFactor: 1,
|
|
8888
|
-
liquidationPenalty: penalty,
|
|
8889
|
-
closeFactor: 1,
|
|
8890
|
-
collateralDisabled: false,
|
|
8891
|
-
debtDisabled: true
|
|
8892
|
-
};
|
|
8893
|
-
const debtConfig = {
|
|
8894
|
-
category: 0,
|
|
8895
|
-
label,
|
|
8896
|
-
borrowCollateralFactor: 0,
|
|
8897
|
-
collateralFactor: 0,
|
|
8898
|
-
borrowFactor: 1,
|
|
8899
|
-
liquidationPenalty: 0,
|
|
8900
|
-
closeFactor: 1,
|
|
8901
|
-
collateralDisabled: true,
|
|
8902
|
-
debtDisabled: false
|
|
8903
|
-
};
|
|
8904
|
-
const common = {
|
|
8905
|
-
totalDebtStable: "0",
|
|
8906
|
-
totalDebtStableUSD: 0,
|
|
8907
|
-
stableBorrowRate: 0,
|
|
8908
|
-
hasStable: false,
|
|
8909
|
-
isActive: true,
|
|
8910
|
-
isFrozen: false,
|
|
8911
|
-
debtCeiling: "0",
|
|
8912
|
-
closeFactor: 1,
|
|
8913
|
-
lockupRatio,
|
|
8914
|
-
rewards: []
|
|
8915
|
-
};
|
|
8916
|
-
const colUid = createMarketUid(SOLANA_CHAIN_ID, lenderKey, sup.address);
|
|
8917
|
-
const debtUid = createMarketUid(SOLANA_CHAIN_ID, lenderKey, bor.address);
|
|
8918
|
-
const collateralLeg = {
|
|
8919
|
-
...common,
|
|
8920
|
-
marketUid: colUid,
|
|
8921
|
-
name: `Collateral ${supSym}`,
|
|
8922
|
-
poolId: sup.address,
|
|
8923
|
-
underlying: sup.address,
|
|
8924
|
-
asset: supAsset,
|
|
8925
|
-
decimals: sup.decimals,
|
|
8926
|
-
totalDeposits: formatRawUnits(v.totalSupply, sup.decimals),
|
|
8927
|
-
totalDebt: "0",
|
|
8928
|
-
totalLiquidity: supplyDeposits,
|
|
8929
|
-
borrowLiquidity: 0,
|
|
8930
|
-
totalDepositsUSD: supplyDeposits * supPrice,
|
|
8931
|
-
totalDebtUSD: 0,
|
|
8932
|
-
totalLiquidityUSD: supplyDeposits * supPrice,
|
|
8933
|
-
borrowLiquidityUSD: 0,
|
|
8934
|
-
...layerOf(sup.address),
|
|
8935
|
-
depositRate: bpsToPercent(v.supplyRate),
|
|
8936
|
-
variableBorrowRate: 0,
|
|
8937
|
-
intrinsicYield: intrinsic(supAsset),
|
|
8938
|
-
liquidationBonus: penalty,
|
|
8939
|
-
config: { "0": collateralConfig },
|
|
8940
|
-
collateralActive: true,
|
|
8941
|
-
borrowingEnabled: false,
|
|
8942
|
-
depositsEnabled: true
|
|
8943
|
-
};
|
|
8944
|
-
const debtLeg = {
|
|
8945
|
-
...common,
|
|
8946
|
-
marketUid: debtUid,
|
|
8947
|
-
name: `Loan ${borSym}`,
|
|
8948
|
-
poolId: bor.address,
|
|
8949
|
-
underlying: bor.address,
|
|
8950
|
-
asset: borAsset,
|
|
8951
|
-
decimals: bor.decimals,
|
|
8952
|
-
totalDeposits: "0",
|
|
8953
|
-
totalDebt: formatRawUnits(v.totalBorrow, bor.decimals),
|
|
8954
|
-
totalLiquidity: borrowable,
|
|
8955
|
-
borrowLiquidity: borrowable,
|
|
8956
|
-
totalDepositsUSD: 0,
|
|
8957
|
-
totalDebtUSD: borrowDebt * borPrice,
|
|
8958
|
-
totalLiquidityUSD: borrowable * borPrice,
|
|
8959
|
-
borrowLiquidityUSD: borrowable * borPrice,
|
|
8960
|
-
...layerOf(bor.address),
|
|
8961
|
-
depositRate: 0,
|
|
8962
|
-
variableBorrowRate: bpsToPercent(v.borrowRate),
|
|
8963
|
-
intrinsicYield: intrinsic(borAsset),
|
|
8964
|
-
liquidationBonus: 0,
|
|
8965
|
-
originationFee: num(v.borrowFee) / 100,
|
|
8966
|
-
config: { "0": debtConfig },
|
|
8967
|
-
collateralActive: false,
|
|
8968
|
-
borrowingEnabled: true,
|
|
8969
|
-
depositsEnabled: false
|
|
8970
|
-
};
|
|
8971
|
-
const vault = {
|
|
8972
|
-
vaultAddress: v.address,
|
|
8973
|
-
vaultId: v.id,
|
|
8974
|
-
collateralAddress: sup.address,
|
|
8975
|
-
loanAddress: bor.address,
|
|
8976
|
-
collateralDecimals: sup.decimals,
|
|
8977
|
-
loanDecimals: bor.decimals,
|
|
8978
|
-
oracle: v.oracle,
|
|
8979
|
-
ltv,
|
|
8980
|
-
liquidationThreshold: lt,
|
|
8981
|
-
liquidationPenalty: penalty,
|
|
8982
|
-
oraclePriceOperate: jlOracleToFluidRaw(
|
|
8983
|
-
v.oraclePriceOperate,
|
|
8984
|
-
sup.decimals,
|
|
8985
|
-
bor.decimals
|
|
8986
|
-
),
|
|
8987
|
-
oraclePriceLiquidate: jlOracleToFluidRaw(
|
|
8988
|
-
v.oraclePriceLiquidate,
|
|
8989
|
-
sup.decimals,
|
|
8990
|
-
bor.decimals
|
|
8991
|
-
),
|
|
8992
|
-
isSmartCol: false,
|
|
8993
|
-
isSmartDebt: false,
|
|
8994
|
-
vaultType: FLUID_VAULT_TYPE_T1,
|
|
8995
|
-
collateral: {
|
|
8996
|
-
assets: [{ underlying: sup.address, decimals: sup.decimals }],
|
|
8997
|
-
dex: null,
|
|
8998
|
-
perShare: null
|
|
8999
|
-
},
|
|
9000
|
-
loan: {
|
|
9001
|
-
assets: [{ underlying: bor.address, decimals: bor.decimals }],
|
|
9002
|
-
dex: null,
|
|
9003
|
-
perShare: null
|
|
9004
|
-
}
|
|
9005
|
-
};
|
|
9006
|
-
const jupiterLendVault = {
|
|
9007
|
-
market,
|
|
9008
|
-
vaultId: v.id,
|
|
9009
|
-
address: v.address,
|
|
9010
|
-
type: v.type,
|
|
9011
|
-
supplyToken: sup.address,
|
|
9012
|
-
borrowToken: bor.address,
|
|
9013
|
-
supplyDecimals: sup.decimals,
|
|
9014
|
-
borrowDecimals: bor.decimals,
|
|
9015
|
-
collateralFactor: num(v.collateralFactor),
|
|
9016
|
-
liquidationThreshold: num(v.liquidationThreshold),
|
|
9017
|
-
liquidationMaxLimit: num(v.liquidationMaxLimit),
|
|
9018
|
-
withdrawalGap: num(v.withdrawalGap),
|
|
9019
|
-
liquidationPenalty: num(v.liquidationPenalty),
|
|
9020
|
-
borrowFee: num(v.borrowFee),
|
|
9021
|
-
supplyRateMagnifier: num(v.supplyRateMagnifier),
|
|
9022
|
-
borrowRateMagnifier: num(v.borrowRateMagnifier),
|
|
9023
|
-
supplyRateLiquidity: num(v.supplyRateLiquidity),
|
|
9024
|
-
borrowRateLiquidity: num(v.borrowRateLiquidity),
|
|
9025
|
-
minimumBorrowing: v.minimumBorrowing,
|
|
9026
|
-
totalPositions: v.totalPositions,
|
|
9027
|
-
borrowLimit: v.borrowLimit,
|
|
9028
|
-
borrowable: v.borrowable,
|
|
9029
|
-
withdrawLimit: v.withdrawLimit,
|
|
9030
|
-
withdrawable: v.withdrawable,
|
|
9031
|
-
oracle: v.oracle,
|
|
9032
|
-
oraclePrice: v.oraclePrice,
|
|
9033
|
-
oraclePriceOperate: v.oraclePriceOperate,
|
|
9034
|
-
oraclePriceLiquidate: v.oraclePriceLiquidate,
|
|
9035
|
-
oracleSources: v.oracleSources,
|
|
9036
|
-
oracleTimestamp: v.oracleTimestamp,
|
|
9037
|
-
liquiditySupplyData: v.liquiditySupplyData,
|
|
9038
|
-
liquidityBorrowData: v.liquidityBorrowData,
|
|
9039
|
-
topTick: v.topTick,
|
|
9040
|
-
metadata: v.metadata
|
|
9041
|
-
};
|
|
9042
|
-
return {
|
|
9043
|
-
lenderKey,
|
|
9044
|
-
chainId: SOLANA_CHAIN_ID,
|
|
9045
|
-
data: { [colUid]: collateralLeg, [debtUid]: debtLeg },
|
|
9046
|
-
params: { vault, jupiterLendVault }
|
|
9047
|
-
};
|
|
9048
|
-
}
|
|
9049
|
-
|
|
9050
|
-
// src/lending/public-data/jupiter-lend/flashloan.ts
|
|
8823
|
+
// src/lending/public-data/jupiter-lend/onchain.ts
|
|
9051
8824
|
import {
|
|
9052
|
-
decodeBase58 as
|
|
9053
|
-
decodeIdlAccount as
|
|
9054
|
-
|
|
9055
|
-
|
|
9056
|
-
fromBase64 as fromBase642,
|
|
9057
|
-
getAssociatedTokenAddress
|
|
8825
|
+
decodeBase58 as decodeBase583,
|
|
8826
|
+
decodeIdlAccount as decodeIdlAccount3,
|
|
8827
|
+
findProgramAddress as findProgramAddress3,
|
|
8828
|
+
fromBase64 as fromBase643
|
|
9058
8829
|
} from "@1delta/svm-kit";
|
|
9059
8830
|
|
|
9060
|
-
// src/lending/public-data/jupiter-lend/idl/
|
|
9061
|
-
var
|
|
9062
|
-
address: "
|
|
8831
|
+
// src/lending/public-data/jupiter-lend/idl/vaults-accounts.json
|
|
8832
|
+
var vaults_accounts_default = {
|
|
8833
|
+
address: "jupr81YtYssSyPt8jbnGuiWon5f6x9TcDEFxYe3Bdzi",
|
|
9063
8834
|
metadata: {
|
|
9064
|
-
name: "
|
|
9065
|
-
version: "0.1.
|
|
8835
|
+
name: "vaults",
|
|
8836
|
+
version: "0.1.5",
|
|
9066
8837
|
spec: "0.1.0",
|
|
9067
|
-
description: "
|
|
8838
|
+
description: "Account layouts only, vendored from the vaults program IDL (pos-indexer apps/sol-indexer/src/events/idl/jupiter-lend/vaults.json, v0.1.5) for the on-chain vault enumeration."
|
|
9068
8839
|
},
|
|
9069
|
-
instructions: [
|
|
8840
|
+
instructions: [],
|
|
8841
|
+
accounts: [
|
|
9070
8842
|
{
|
|
9071
|
-
name: "
|
|
8843
|
+
name: "Dex",
|
|
9072
8844
|
discriminator: [
|
|
9073
|
-
|
|
9074
|
-
|
|
9075
|
-
|
|
9076
|
-
|
|
9077
|
-
|
|
9078
|
-
|
|
9079
|
-
|
|
9080
|
-
|
|
9081
|
-
]
|
|
9082
|
-
accounts: [
|
|
9083
|
-
{
|
|
9084
|
-
name: "authority",
|
|
9085
|
-
signer: true
|
|
9086
|
-
},
|
|
9087
|
-
{
|
|
9088
|
-
name: "flashloan_admin",
|
|
9089
|
-
writable: true
|
|
9090
|
-
}
|
|
9091
|
-
],
|
|
9092
|
-
args: []
|
|
8845
|
+
236,
|
|
8846
|
+
30,
|
|
8847
|
+
181,
|
|
8848
|
+
80,
|
|
8849
|
+
209,
|
|
8850
|
+
217,
|
|
8851
|
+
25,
|
|
8852
|
+
163
|
|
8853
|
+
]
|
|
9093
8854
|
},
|
|
9094
8855
|
{
|
|
9095
|
-
name: "
|
|
8856
|
+
name: "TokenReserve",
|
|
9096
8857
|
discriminator: [
|
|
9097
|
-
|
|
9098
|
-
|
|
9099
|
-
|
|
9100
|
-
24,
|
|
9101
|
-
240,
|
|
9102
|
-
9,
|
|
8858
|
+
21,
|
|
8859
|
+
18,
|
|
8860
|
+
59,
|
|
9103
8861
|
135,
|
|
9104
|
-
|
|
9105
|
-
|
|
9106
|
-
|
|
9107
|
-
|
|
9108
|
-
name: "signer",
|
|
9109
|
-
writable: true,
|
|
9110
|
-
signer: true
|
|
9111
|
-
},
|
|
9112
|
-
{
|
|
9113
|
-
name: "flashloan_admin",
|
|
9114
|
-
writable: true
|
|
9115
|
-
},
|
|
9116
|
-
{
|
|
9117
|
-
name: "signer_borrow_token_account",
|
|
9118
|
-
writable: true
|
|
9119
|
-
},
|
|
9120
|
-
{
|
|
9121
|
-
name: "mint"
|
|
9122
|
-
},
|
|
9123
|
-
{
|
|
9124
|
-
name: "flashloan_token_reserves_liquidity",
|
|
9125
|
-
writable: true
|
|
9126
|
-
},
|
|
9127
|
-
{
|
|
9128
|
-
name: "flashloan_borrow_position_on_liquidity",
|
|
9129
|
-
writable: true
|
|
9130
|
-
},
|
|
9131
|
-
{
|
|
9132
|
-
name: "rate_model"
|
|
9133
|
-
},
|
|
9134
|
-
{
|
|
9135
|
-
name: "vault",
|
|
9136
|
-
writable: true
|
|
9137
|
-
},
|
|
9138
|
-
{
|
|
9139
|
-
name: "liquidity"
|
|
9140
|
-
},
|
|
9141
|
-
{
|
|
9142
|
-
name: "liquidity_program",
|
|
9143
|
-
relations: [
|
|
9144
|
-
"flashloan_admin"
|
|
9145
|
-
]
|
|
9146
|
-
},
|
|
9147
|
-
{
|
|
9148
|
-
name: "token_program"
|
|
9149
|
-
},
|
|
9150
|
-
{
|
|
9151
|
-
name: "associated_token_program",
|
|
9152
|
-
optional: true,
|
|
9153
|
-
address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
|
|
9154
|
-
},
|
|
9155
|
-
{
|
|
9156
|
-
name: "system_program",
|
|
9157
|
-
address: "11111111111111111111111111111111"
|
|
9158
|
-
},
|
|
9159
|
-
{
|
|
9160
|
-
name: "instruction_sysvar",
|
|
9161
|
-
address: "Sysvar1nstructions1111111111111111111111111"
|
|
9162
|
-
}
|
|
9163
|
-
],
|
|
9164
|
-
args: [
|
|
9165
|
-
{
|
|
9166
|
-
name: "amount",
|
|
9167
|
-
type: "u64"
|
|
9168
|
-
}
|
|
8862
|
+
120,
|
|
8863
|
+
20,
|
|
8864
|
+
31,
|
|
8865
|
+
12
|
|
9169
8866
|
]
|
|
9170
8867
|
},
|
|
9171
8868
|
{
|
|
9172
|
-
name: "
|
|
8869
|
+
name: "UserBorrowPosition",
|
|
9173
8870
|
discriminator: [
|
|
9174
|
-
|
|
9175
|
-
|
|
9176
|
-
|
|
9177
|
-
|
|
9178
|
-
|
|
9179
|
-
|
|
9180
|
-
|
|
9181
|
-
|
|
9182
|
-
],
|
|
9183
|
-
accounts: [
|
|
9184
|
-
{
|
|
9185
|
-
name: "signer",
|
|
9186
|
-
writable: true,
|
|
9187
|
-
signer: true
|
|
9188
|
-
},
|
|
9189
|
-
{
|
|
9190
|
-
name: "flashloan_admin",
|
|
9191
|
-
writable: true
|
|
9192
|
-
},
|
|
9193
|
-
{
|
|
9194
|
-
name: "signer_borrow_token_account",
|
|
9195
|
-
writable: true
|
|
9196
|
-
},
|
|
9197
|
-
{
|
|
9198
|
-
name: "mint"
|
|
9199
|
-
},
|
|
9200
|
-
{
|
|
9201
|
-
name: "flashloan_token_reserves_liquidity",
|
|
9202
|
-
writable: true
|
|
9203
|
-
},
|
|
9204
|
-
{
|
|
9205
|
-
name: "flashloan_borrow_position_on_liquidity",
|
|
9206
|
-
writable: true
|
|
9207
|
-
},
|
|
9208
|
-
{
|
|
9209
|
-
name: "rate_model"
|
|
9210
|
-
},
|
|
9211
|
-
{
|
|
9212
|
-
name: "vault",
|
|
9213
|
-
writable: true
|
|
9214
|
-
},
|
|
9215
|
-
{
|
|
9216
|
-
name: "liquidity"
|
|
9217
|
-
},
|
|
9218
|
-
{
|
|
9219
|
-
name: "liquidity_program",
|
|
9220
|
-
relations: [
|
|
9221
|
-
"flashloan_admin"
|
|
9222
|
-
]
|
|
9223
|
-
},
|
|
9224
|
-
{
|
|
9225
|
-
name: "token_program"
|
|
9226
|
-
},
|
|
9227
|
-
{
|
|
9228
|
-
name: "associated_token_program",
|
|
9229
|
-
optional: true,
|
|
9230
|
-
address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
|
|
9231
|
-
},
|
|
9232
|
-
{
|
|
9233
|
-
name: "system_program",
|
|
9234
|
-
address: "11111111111111111111111111111111"
|
|
9235
|
-
},
|
|
9236
|
-
{
|
|
9237
|
-
name: "instruction_sysvar",
|
|
9238
|
-
address: "Sysvar1nstructions1111111111111111111111111"
|
|
9239
|
-
}
|
|
9240
|
-
],
|
|
9241
|
-
args: [
|
|
9242
|
-
{
|
|
9243
|
-
name: "amount",
|
|
9244
|
-
type: "u64"
|
|
9245
|
-
}
|
|
8871
|
+
73,
|
|
8872
|
+
126,
|
|
8873
|
+
65,
|
|
8874
|
+
123,
|
|
8875
|
+
220,
|
|
8876
|
+
126,
|
|
8877
|
+
197,
|
|
8878
|
+
24
|
|
9246
8879
|
]
|
|
9247
8880
|
},
|
|
9248
8881
|
{
|
|
9249
|
-
name: "
|
|
8882
|
+
name: "UserSupplyPosition",
|
|
9250
8883
|
discriminator: [
|
|
9251
|
-
|
|
8884
|
+
202,
|
|
8885
|
+
219,
|
|
8886
|
+
136,
|
|
8887
|
+
118,
|
|
8888
|
+
61,
|
|
8889
|
+
177,
|
|
8890
|
+
21,
|
|
8891
|
+
146
|
|
8892
|
+
]
|
|
8893
|
+
},
|
|
8894
|
+
{
|
|
8895
|
+
name: "VaultAdmin",
|
|
8896
|
+
discriminator: [
|
|
8897
|
+
88,
|
|
8898
|
+
97,
|
|
8899
|
+
160,
|
|
9252
8900
|
117,
|
|
9253
|
-
|
|
9254
|
-
|
|
9255
|
-
|
|
9256
|
-
|
|
9257
|
-
|
|
9258
|
-
|
|
9259
|
-
|
|
9260
|
-
|
|
9261
|
-
|
|
9262
|
-
|
|
9263
|
-
|
|
9264
|
-
|
|
9265
|
-
|
|
9266
|
-
|
|
9267
|
-
|
|
9268
|
-
|
|
9269
|
-
|
|
9270
|
-
|
|
9271
|
-
|
|
9272
|
-
|
|
9273
|
-
|
|
9274
|
-
|
|
9275
|
-
|
|
9276
|
-
|
|
9277
|
-
|
|
9278
|
-
|
|
9279
|
-
|
|
9280
|
-
|
|
9281
|
-
|
|
9282
|
-
|
|
8901
|
+
102,
|
|
8902
|
+
39,
|
|
8903
|
+
103,
|
|
8904
|
+
44
|
|
8905
|
+
]
|
|
8906
|
+
},
|
|
8907
|
+
{
|
|
8908
|
+
name: "VaultConfig",
|
|
8909
|
+
discriminator: [
|
|
8910
|
+
99,
|
|
8911
|
+
86,
|
|
8912
|
+
43,
|
|
8913
|
+
216,
|
|
8914
|
+
184,
|
|
8915
|
+
102,
|
|
8916
|
+
119,
|
|
8917
|
+
77
|
|
8918
|
+
]
|
|
8919
|
+
},
|
|
8920
|
+
{
|
|
8921
|
+
name: "VaultState",
|
|
8922
|
+
discriminator: [
|
|
8923
|
+
228,
|
|
8924
|
+
196,
|
|
8925
|
+
82,
|
|
8926
|
+
165,
|
|
8927
|
+
98,
|
|
8928
|
+
210,
|
|
8929
|
+
235,
|
|
8930
|
+
152
|
|
8931
|
+
]
|
|
8932
|
+
},
|
|
8933
|
+
{
|
|
8934
|
+
name: "Oracle",
|
|
8935
|
+
discriminator: [
|
|
8936
|
+
139,
|
|
8937
|
+
194,
|
|
8938
|
+
131,
|
|
8939
|
+
179,
|
|
8940
|
+
140,
|
|
8941
|
+
179,
|
|
8942
|
+
229,
|
|
8943
|
+
244
|
|
8944
|
+
]
|
|
8945
|
+
}
|
|
8946
|
+
],
|
|
8947
|
+
types: [
|
|
8948
|
+
{
|
|
8949
|
+
name: "Dex",
|
|
8950
|
+
docs: [
|
|
8951
|
+
"Core DEX pool state. One per trading pair.",
|
|
8952
|
+
"Uses zero_copy for efficient access without deserialization overhead."
|
|
8953
|
+
],
|
|
8954
|
+
serialization: "bytemuck",
|
|
8955
|
+
repr: {
|
|
8956
|
+
kind: "c",
|
|
8957
|
+
packed: true
|
|
8958
|
+
},
|
|
8959
|
+
type: {
|
|
8960
|
+
kind: "struct",
|
|
8961
|
+
fields: [
|
|
8962
|
+
{
|
|
8963
|
+
name: "dex_id",
|
|
8964
|
+
type: "u16"
|
|
8965
|
+
},
|
|
8966
|
+
{
|
|
8967
|
+
name: "re_entrancy",
|
|
8968
|
+
type: "u8"
|
|
8969
|
+
},
|
|
8970
|
+
{
|
|
8971
|
+
name: "token_0",
|
|
8972
|
+
type: "pubkey"
|
|
8973
|
+
},
|
|
8974
|
+
{
|
|
8975
|
+
name: "token_1",
|
|
8976
|
+
type: "pubkey"
|
|
8977
|
+
},
|
|
8978
|
+
{
|
|
8979
|
+
name: "token_0_decimals",
|
|
8980
|
+
type: "u8"
|
|
8981
|
+
},
|
|
8982
|
+
{
|
|
8983
|
+
name: "token_1_decimals",
|
|
8984
|
+
type: "u8"
|
|
8985
|
+
},
|
|
8986
|
+
{
|
|
8987
|
+
name: "last_to_last_stored_price",
|
|
8988
|
+
type: "u128"
|
|
8989
|
+
},
|
|
8990
|
+
{
|
|
8991
|
+
name: "last_stored_price",
|
|
8992
|
+
type: "u128"
|
|
8993
|
+
},
|
|
8994
|
+
{
|
|
8995
|
+
name: "center_price",
|
|
8996
|
+
type: "u128"
|
|
8997
|
+
},
|
|
8998
|
+
{
|
|
8999
|
+
name: "last_update_timestamp",
|
|
9000
|
+
type: "u64"
|
|
9001
|
+
},
|
|
9002
|
+
{
|
|
9003
|
+
name: "last_update_slot",
|
|
9004
|
+
type: "u64"
|
|
9005
|
+
},
|
|
9006
|
+
{
|
|
9007
|
+
name: "is_smart_collateral_enabled",
|
|
9008
|
+
type: "u8"
|
|
9009
|
+
},
|
|
9010
|
+
{
|
|
9011
|
+
name: "is_smart_debt_enabled",
|
|
9012
|
+
type: "u8"
|
|
9013
|
+
},
|
|
9014
|
+
{
|
|
9015
|
+
name: "fee",
|
|
9016
|
+
type: "u32"
|
|
9017
|
+
},
|
|
9018
|
+
{
|
|
9019
|
+
name: "revenue_cut",
|
|
9020
|
+
type: "u8"
|
|
9021
|
+
},
|
|
9022
|
+
{
|
|
9023
|
+
name: "percent_change_active",
|
|
9024
|
+
type: "u8"
|
|
9025
|
+
},
|
|
9026
|
+
{
|
|
9027
|
+
name: "upper_percent",
|
|
9028
|
+
type: "u32"
|
|
9029
|
+
},
|
|
9030
|
+
{
|
|
9031
|
+
name: "lower_percent",
|
|
9032
|
+
type: "u32"
|
|
9033
|
+
},
|
|
9034
|
+
{
|
|
9035
|
+
name: "threshold_change_active",
|
|
9036
|
+
type: "u8"
|
|
9037
|
+
},
|
|
9038
|
+
{
|
|
9039
|
+
name: "upper_shift_threshold_percent",
|
|
9040
|
+
type: "u16"
|
|
9041
|
+
},
|
|
9042
|
+
{
|
|
9043
|
+
name: "lower_shift_threshold_percent",
|
|
9044
|
+
type: "u16"
|
|
9045
|
+
},
|
|
9046
|
+
{
|
|
9047
|
+
name: "shifting_time",
|
|
9048
|
+
type: "u32"
|
|
9049
|
+
},
|
|
9050
|
+
{
|
|
9051
|
+
name: "center_price_address",
|
|
9052
|
+
type: "pubkey"
|
|
9053
|
+
},
|
|
9054
|
+
{
|
|
9055
|
+
name: "max_center_price",
|
|
9056
|
+
type: "u64"
|
|
9057
|
+
},
|
|
9058
|
+
{
|
|
9059
|
+
name: "min_center_price",
|
|
9060
|
+
type: "u64"
|
|
9061
|
+
},
|
|
9062
|
+
{
|
|
9063
|
+
name: "token_0_max_utilization",
|
|
9064
|
+
type: "u16"
|
|
9065
|
+
},
|
|
9066
|
+
{
|
|
9067
|
+
name: "token_1_max_utilization",
|
|
9068
|
+
type: "u16"
|
|
9069
|
+
},
|
|
9070
|
+
{
|
|
9071
|
+
name: "is_center_price_shift_active",
|
|
9072
|
+
type: "u8"
|
|
9073
|
+
},
|
|
9074
|
+
{
|
|
9075
|
+
name: "swap_and_arbitrage_paused",
|
|
9076
|
+
type: "u8"
|
|
9077
|
+
},
|
|
9078
|
+
{
|
|
9079
|
+
name: "total_supply_shares",
|
|
9080
|
+
type: "u64"
|
|
9081
|
+
},
|
|
9082
|
+
{
|
|
9083
|
+
name: "max_supply_shares",
|
|
9084
|
+
type: "u64"
|
|
9085
|
+
},
|
|
9086
|
+
{
|
|
9087
|
+
name: "total_borrow_shares",
|
|
9088
|
+
type: "u64"
|
|
9089
|
+
},
|
|
9090
|
+
{
|
|
9091
|
+
name: "max_borrow_shares",
|
|
9092
|
+
type: "u64"
|
|
9093
|
+
},
|
|
9094
|
+
{
|
|
9095
|
+
name: "range_old_upper_shift",
|
|
9096
|
+
type: "u32"
|
|
9097
|
+
},
|
|
9098
|
+
{
|
|
9099
|
+
name: "range_old_lower_shift",
|
|
9100
|
+
type: "u32"
|
|
9101
|
+
},
|
|
9102
|
+
{
|
|
9103
|
+
name: "range_shift_duration",
|
|
9104
|
+
type: "u32"
|
|
9105
|
+
},
|
|
9106
|
+
{
|
|
9107
|
+
name: "range_shift_start_timestamp",
|
|
9108
|
+
type: "u32"
|
|
9109
|
+
},
|
|
9110
|
+
{
|
|
9111
|
+
name: "threshold_old_upper_shift",
|
|
9112
|
+
type: "u16"
|
|
9113
|
+
},
|
|
9114
|
+
{
|
|
9115
|
+
name: "threshold_old_lower_shift",
|
|
9116
|
+
type: "u16"
|
|
9117
|
+
},
|
|
9118
|
+
{
|
|
9119
|
+
name: "threshold_shift_duration",
|
|
9120
|
+
type: "u32"
|
|
9121
|
+
},
|
|
9122
|
+
{
|
|
9123
|
+
name: "threshold_shift_start_timestamp",
|
|
9124
|
+
type: "u32"
|
|
9125
|
+
},
|
|
9126
|
+
{
|
|
9127
|
+
name: "threshold_shift_old_timestamp",
|
|
9128
|
+
type: "u32"
|
|
9129
|
+
},
|
|
9130
|
+
{
|
|
9131
|
+
name: "center_price_shift_start_timestamp",
|
|
9132
|
+
type: "u32"
|
|
9133
|
+
},
|
|
9134
|
+
{
|
|
9135
|
+
name: "center_price_shift_percent",
|
|
9136
|
+
type: "u32"
|
|
9137
|
+
},
|
|
9138
|
+
{
|
|
9139
|
+
name: "center_price_shift_time",
|
|
9140
|
+
type: "u32"
|
|
9141
|
+
},
|
|
9142
|
+
{
|
|
9143
|
+
name: "_reserved",
|
|
9144
|
+
type: {
|
|
9145
|
+
array: [
|
|
9146
|
+
"u8",
|
|
9147
|
+
32
|
|
9148
|
+
]
|
|
9149
|
+
}
|
|
9150
|
+
},
|
|
9151
|
+
{
|
|
9152
|
+
name: "bump",
|
|
9153
|
+
type: "u8"
|
|
9154
|
+
}
|
|
9155
|
+
]
|
|
9156
|
+
}
|
|
9157
|
+
},
|
|
9158
|
+
{
|
|
9159
|
+
name: "TokenReserve",
|
|
9160
|
+
docs: [
|
|
9161
|
+
"Token configuration and exchange prices"
|
|
9162
|
+
],
|
|
9163
|
+
serialization: "bytemuck",
|
|
9164
|
+
repr: {
|
|
9165
|
+
kind: "c",
|
|
9166
|
+
packed: true
|
|
9167
|
+
},
|
|
9168
|
+
type: {
|
|
9169
|
+
kind: "struct",
|
|
9170
|
+
fields: [
|
|
9171
|
+
{
|
|
9172
|
+
name: "mint",
|
|
9173
|
+
type: "pubkey"
|
|
9174
|
+
},
|
|
9175
|
+
{
|
|
9176
|
+
name: "vault",
|
|
9177
|
+
type: "pubkey"
|
|
9178
|
+
},
|
|
9179
|
+
{
|
|
9180
|
+
name: "borrow_rate",
|
|
9181
|
+
type: "u16"
|
|
9182
|
+
},
|
|
9183
|
+
{
|
|
9184
|
+
name: "fee_on_interest",
|
|
9185
|
+
type: "u16"
|
|
9186
|
+
},
|
|
9187
|
+
{
|
|
9188
|
+
name: "last_utilization",
|
|
9189
|
+
type: "u16"
|
|
9190
|
+
},
|
|
9191
|
+
{
|
|
9192
|
+
name: "last_update_timestamp",
|
|
9193
|
+
type: "u64"
|
|
9194
|
+
},
|
|
9195
|
+
{
|
|
9196
|
+
name: "supply_exchange_price",
|
|
9197
|
+
type: "u64"
|
|
9198
|
+
},
|
|
9199
|
+
{
|
|
9200
|
+
name: "borrow_exchange_price",
|
|
9201
|
+
type: "u64"
|
|
9202
|
+
},
|
|
9203
|
+
{
|
|
9204
|
+
name: "max_utilization",
|
|
9205
|
+
type: "u16"
|
|
9206
|
+
},
|
|
9207
|
+
{
|
|
9208
|
+
name: "total_supply_with_interest",
|
|
9209
|
+
type: "u64"
|
|
9210
|
+
},
|
|
9211
|
+
{
|
|
9212
|
+
name: "total_supply_interest_free",
|
|
9213
|
+
type: "u64"
|
|
9214
|
+
},
|
|
9215
|
+
{
|
|
9216
|
+
name: "total_borrow_with_interest",
|
|
9217
|
+
type: "u64"
|
|
9218
|
+
},
|
|
9219
|
+
{
|
|
9220
|
+
name: "total_borrow_interest_free",
|
|
9221
|
+
type: "u64"
|
|
9222
|
+
},
|
|
9223
|
+
{
|
|
9224
|
+
name: "total_claim_amount",
|
|
9225
|
+
type: "u64"
|
|
9226
|
+
},
|
|
9227
|
+
{
|
|
9228
|
+
name: "interacting_protocol",
|
|
9229
|
+
type: "pubkey"
|
|
9230
|
+
},
|
|
9231
|
+
{
|
|
9232
|
+
name: "interacting_timestamp",
|
|
9233
|
+
type: "u64"
|
|
9234
|
+
},
|
|
9235
|
+
{
|
|
9236
|
+
name: "interacting_balance",
|
|
9237
|
+
type: "u64"
|
|
9238
|
+
}
|
|
9239
|
+
]
|
|
9240
|
+
}
|
|
9241
|
+
},
|
|
9242
|
+
{
|
|
9243
|
+
name: "UserBorrowPosition",
|
|
9244
|
+
docs: [
|
|
9245
|
+
"User borrow position"
|
|
9246
|
+
],
|
|
9247
|
+
serialization: "bytemuck",
|
|
9248
|
+
repr: {
|
|
9249
|
+
kind: "c",
|
|
9250
|
+
packed: true
|
|
9251
|
+
},
|
|
9252
|
+
type: {
|
|
9253
|
+
kind: "struct",
|
|
9254
|
+
fields: [
|
|
9255
|
+
{
|
|
9256
|
+
name: "protocol",
|
|
9257
|
+
type: "pubkey"
|
|
9258
|
+
},
|
|
9259
|
+
{
|
|
9260
|
+
name: "mint",
|
|
9261
|
+
type: "pubkey"
|
|
9262
|
+
},
|
|
9263
|
+
{
|
|
9264
|
+
name: "with_interest",
|
|
9265
|
+
type: "u8"
|
|
9266
|
+
},
|
|
9267
|
+
{
|
|
9268
|
+
name: "amount",
|
|
9269
|
+
type: "u64"
|
|
9270
|
+
},
|
|
9271
|
+
{
|
|
9272
|
+
name: "debt_ceiling",
|
|
9273
|
+
type: "u64"
|
|
9274
|
+
},
|
|
9275
|
+
{
|
|
9276
|
+
name: "last_update",
|
|
9277
|
+
type: "u64"
|
|
9278
|
+
},
|
|
9279
|
+
{
|
|
9280
|
+
name: "expand_pct",
|
|
9281
|
+
type: "u16"
|
|
9282
|
+
},
|
|
9283
|
+
{
|
|
9284
|
+
name: "expand_duration",
|
|
9285
|
+
type: "u32"
|
|
9286
|
+
},
|
|
9287
|
+
{
|
|
9288
|
+
name: "base_debt_ceiling",
|
|
9289
|
+
type: "u64"
|
|
9290
|
+
},
|
|
9291
|
+
{
|
|
9292
|
+
name: "max_debt_ceiling",
|
|
9293
|
+
type: "u64"
|
|
9294
|
+
},
|
|
9295
|
+
{
|
|
9296
|
+
name: "status",
|
|
9297
|
+
type: "u8"
|
|
9298
|
+
}
|
|
9299
|
+
]
|
|
9300
|
+
}
|
|
9301
|
+
},
|
|
9302
|
+
{
|
|
9303
|
+
name: "UserSupplyPosition",
|
|
9304
|
+
docs: [
|
|
9305
|
+
"User supply position"
|
|
9306
|
+
],
|
|
9307
|
+
serialization: "bytemuck",
|
|
9308
|
+
repr: {
|
|
9309
|
+
kind: "c",
|
|
9310
|
+
packed: true
|
|
9311
|
+
},
|
|
9312
|
+
type: {
|
|
9313
|
+
kind: "struct",
|
|
9314
|
+
fields: [
|
|
9315
|
+
{
|
|
9316
|
+
name: "protocol",
|
|
9317
|
+
type: "pubkey"
|
|
9318
|
+
},
|
|
9319
|
+
{
|
|
9320
|
+
name: "mint",
|
|
9321
|
+
type: "pubkey"
|
|
9322
|
+
},
|
|
9323
|
+
{
|
|
9324
|
+
name: "with_interest",
|
|
9325
|
+
type: "u8"
|
|
9326
|
+
},
|
|
9327
|
+
{
|
|
9328
|
+
name: "amount",
|
|
9329
|
+
type: "u64"
|
|
9330
|
+
},
|
|
9331
|
+
{
|
|
9332
|
+
name: "withdrawal_limit",
|
|
9333
|
+
type: "u64"
|
|
9334
|
+
},
|
|
9335
|
+
{
|
|
9336
|
+
name: "decay_amount",
|
|
9337
|
+
type: "u64"
|
|
9338
|
+
},
|
|
9339
|
+
{
|
|
9340
|
+
name: "last_update",
|
|
9341
|
+
type: "u64"
|
|
9342
|
+
},
|
|
9343
|
+
{
|
|
9344
|
+
name: "expand_pct",
|
|
9345
|
+
type: "u16"
|
|
9346
|
+
},
|
|
9347
|
+
{
|
|
9348
|
+
name: "expand_duration",
|
|
9349
|
+
type: "u32"
|
|
9350
|
+
},
|
|
9351
|
+
{
|
|
9352
|
+
name: "decay_duration",
|
|
9353
|
+
type: "u32"
|
|
9354
|
+
},
|
|
9355
|
+
{
|
|
9356
|
+
name: "base_withdrawal_limit",
|
|
9357
|
+
type: "u64"
|
|
9358
|
+
},
|
|
9359
|
+
{
|
|
9360
|
+
name: "status",
|
|
9361
|
+
type: "u8"
|
|
9362
|
+
}
|
|
9363
|
+
]
|
|
9364
|
+
}
|
|
9365
|
+
},
|
|
9366
|
+
{
|
|
9367
|
+
name: "VaultAdmin",
|
|
9368
|
+
type: {
|
|
9369
|
+
kind: "struct",
|
|
9370
|
+
fields: [
|
|
9371
|
+
{
|
|
9372
|
+
name: "authority",
|
|
9373
|
+
type: "pubkey"
|
|
9374
|
+
},
|
|
9375
|
+
{
|
|
9376
|
+
name: "liquidity_program",
|
|
9377
|
+
type: "pubkey"
|
|
9378
|
+
},
|
|
9379
|
+
{
|
|
9380
|
+
name: "next_vault_id",
|
|
9381
|
+
type: "u16"
|
|
9382
|
+
},
|
|
9383
|
+
{
|
|
9384
|
+
name: "auths",
|
|
9385
|
+
type: {
|
|
9386
|
+
vec: "pubkey"
|
|
9387
|
+
}
|
|
9388
|
+
},
|
|
9389
|
+
{
|
|
9390
|
+
name: "bump",
|
|
9391
|
+
type: "u8"
|
|
9392
|
+
}
|
|
9393
|
+
]
|
|
9394
|
+
}
|
|
9395
|
+
},
|
|
9396
|
+
{
|
|
9397
|
+
name: "VaultConfig",
|
|
9398
|
+
serialization: "bytemuck",
|
|
9399
|
+
repr: {
|
|
9400
|
+
kind: "c",
|
|
9401
|
+
packed: true
|
|
9402
|
+
},
|
|
9403
|
+
type: {
|
|
9404
|
+
kind: "struct",
|
|
9405
|
+
fields: [
|
|
9406
|
+
{
|
|
9407
|
+
name: "vault_id",
|
|
9408
|
+
type: "u16"
|
|
9409
|
+
},
|
|
9410
|
+
{
|
|
9411
|
+
name: "supply_rate_magnifier",
|
|
9412
|
+
type: "i16"
|
|
9413
|
+
},
|
|
9414
|
+
{
|
|
9415
|
+
name: "borrow_rate_magnifier",
|
|
9416
|
+
type: "i16"
|
|
9417
|
+
},
|
|
9418
|
+
{
|
|
9419
|
+
name: "collateral_factor",
|
|
9420
|
+
type: "u16"
|
|
9421
|
+
},
|
|
9422
|
+
{
|
|
9423
|
+
name: "liquidation_threshold",
|
|
9424
|
+
type: "u16"
|
|
9425
|
+
},
|
|
9426
|
+
{
|
|
9427
|
+
name: "liquidation_max_limit",
|
|
9428
|
+
type: "u16"
|
|
9429
|
+
},
|
|
9430
|
+
{
|
|
9431
|
+
name: "withdraw_gap",
|
|
9432
|
+
type: "u16"
|
|
9433
|
+
},
|
|
9434
|
+
{
|
|
9435
|
+
name: "liquidation_penalty",
|
|
9436
|
+
type: "u16"
|
|
9437
|
+
},
|
|
9438
|
+
{
|
|
9439
|
+
name: "borrow_fee",
|
|
9440
|
+
type: "u8"
|
|
9441
|
+
},
|
|
9442
|
+
{
|
|
9443
|
+
name: "vault_type",
|
|
9444
|
+
type: "u8"
|
|
9445
|
+
},
|
|
9446
|
+
{
|
|
9447
|
+
name: "oracle",
|
|
9448
|
+
type: "pubkey"
|
|
9449
|
+
},
|
|
9450
|
+
{
|
|
9451
|
+
name: "rebalancer",
|
|
9452
|
+
type: "pubkey"
|
|
9453
|
+
},
|
|
9454
|
+
{
|
|
9455
|
+
name: "liquidity_program",
|
|
9456
|
+
type: "pubkey"
|
|
9457
|
+
},
|
|
9458
|
+
{
|
|
9459
|
+
name: "oracle_program",
|
|
9460
|
+
type: "pubkey"
|
|
9461
|
+
},
|
|
9462
|
+
{
|
|
9463
|
+
name: "supply_token",
|
|
9464
|
+
type: "pubkey"
|
|
9465
|
+
},
|
|
9466
|
+
{
|
|
9467
|
+
name: "borrow_token",
|
|
9468
|
+
type: "pubkey"
|
|
9469
|
+
},
|
|
9470
|
+
{
|
|
9471
|
+
name: "bump",
|
|
9472
|
+
type: "u8"
|
|
9473
|
+
}
|
|
9474
|
+
]
|
|
9475
|
+
}
|
|
9476
|
+
},
|
|
9477
|
+
{
|
|
9478
|
+
name: "VaultState",
|
|
9479
|
+
serialization: "bytemuck",
|
|
9480
|
+
repr: {
|
|
9481
|
+
kind: "c",
|
|
9482
|
+
packed: true
|
|
9483
|
+
},
|
|
9484
|
+
type: {
|
|
9485
|
+
kind: "struct",
|
|
9486
|
+
fields: [
|
|
9487
|
+
{
|
|
9488
|
+
name: "vault_id",
|
|
9489
|
+
type: "u16"
|
|
9490
|
+
},
|
|
9491
|
+
{
|
|
9492
|
+
name: "branch_liquidated",
|
|
9493
|
+
type: "u8"
|
|
9494
|
+
},
|
|
9495
|
+
{
|
|
9496
|
+
name: "topmost_tick",
|
|
9497
|
+
type: "i32"
|
|
9498
|
+
},
|
|
9499
|
+
{
|
|
9500
|
+
name: "current_branch_id",
|
|
9501
|
+
type: "u32"
|
|
9502
|
+
},
|
|
9503
|
+
{
|
|
9504
|
+
name: "total_branch_id",
|
|
9505
|
+
type: "u32"
|
|
9506
|
+
},
|
|
9507
|
+
{
|
|
9508
|
+
name: "total_supply",
|
|
9509
|
+
type: "u64"
|
|
9510
|
+
},
|
|
9511
|
+
{
|
|
9512
|
+
name: "total_borrow",
|
|
9513
|
+
type: "u64"
|
|
9514
|
+
},
|
|
9515
|
+
{
|
|
9516
|
+
name: "total_positions",
|
|
9517
|
+
type: "u32"
|
|
9518
|
+
},
|
|
9519
|
+
{
|
|
9520
|
+
name: "absorbed_debt_amount",
|
|
9521
|
+
type: "u128"
|
|
9522
|
+
},
|
|
9523
|
+
{
|
|
9524
|
+
name: "absorbed_col_amount",
|
|
9525
|
+
type: "u128"
|
|
9526
|
+
},
|
|
9527
|
+
{
|
|
9528
|
+
name: "absorbed_dust_debt",
|
|
9529
|
+
type: "u64"
|
|
9530
|
+
},
|
|
9531
|
+
{
|
|
9532
|
+
name: "liquidity_supply_exchange_price",
|
|
9533
|
+
type: "u64"
|
|
9534
|
+
},
|
|
9535
|
+
{
|
|
9536
|
+
name: "liquidity_borrow_exchange_price",
|
|
9537
|
+
type: "u64"
|
|
9538
|
+
},
|
|
9539
|
+
{
|
|
9540
|
+
name: "vault_supply_exchange_price",
|
|
9541
|
+
type: "u64"
|
|
9542
|
+
},
|
|
9543
|
+
{
|
|
9544
|
+
name: "vault_borrow_exchange_price",
|
|
9545
|
+
type: "u64"
|
|
9546
|
+
},
|
|
9547
|
+
{
|
|
9548
|
+
name: "next_position_id",
|
|
9549
|
+
type: "u32"
|
|
9550
|
+
},
|
|
9551
|
+
{
|
|
9552
|
+
name: "last_update_timestamp",
|
|
9553
|
+
type: "u64"
|
|
9554
|
+
}
|
|
9555
|
+
]
|
|
9556
|
+
}
|
|
9557
|
+
},
|
|
9558
|
+
{
|
|
9559
|
+
name: "Oracle",
|
|
9560
|
+
type: {
|
|
9561
|
+
kind: "struct",
|
|
9562
|
+
fields: [
|
|
9563
|
+
{
|
|
9564
|
+
name: "nonce",
|
|
9565
|
+
type: "u16"
|
|
9566
|
+
},
|
|
9567
|
+
{
|
|
9568
|
+
name: "sources",
|
|
9569
|
+
type: {
|
|
9570
|
+
vec: {
|
|
9571
|
+
defined: {
|
|
9572
|
+
name: "Sources"
|
|
9573
|
+
}
|
|
9574
|
+
}
|
|
9575
|
+
}
|
|
9576
|
+
},
|
|
9577
|
+
{
|
|
9578
|
+
name: "bump",
|
|
9579
|
+
type: "u8"
|
|
9580
|
+
}
|
|
9581
|
+
]
|
|
9582
|
+
}
|
|
9583
|
+
},
|
|
9584
|
+
{
|
|
9585
|
+
name: "Sources",
|
|
9586
|
+
type: {
|
|
9587
|
+
kind: "struct",
|
|
9588
|
+
fields: [
|
|
9589
|
+
{
|
|
9590
|
+
name: "source",
|
|
9591
|
+
type: "pubkey"
|
|
9592
|
+
},
|
|
9593
|
+
{
|
|
9594
|
+
name: "invert",
|
|
9595
|
+
type: "bool"
|
|
9596
|
+
},
|
|
9597
|
+
{
|
|
9598
|
+
name: "multiplier",
|
|
9599
|
+
type: "u128"
|
|
9600
|
+
},
|
|
9601
|
+
{
|
|
9602
|
+
name: "divisor",
|
|
9603
|
+
type: "u128"
|
|
9604
|
+
},
|
|
9605
|
+
{
|
|
9606
|
+
name: "source_type",
|
|
9607
|
+
type: {
|
|
9608
|
+
defined: {
|
|
9609
|
+
name: "SourceType"
|
|
9610
|
+
}
|
|
9611
|
+
}
|
|
9612
|
+
}
|
|
9613
|
+
]
|
|
9614
|
+
}
|
|
9615
|
+
},
|
|
9616
|
+
{
|
|
9617
|
+
name: "SourceType",
|
|
9618
|
+
type: {
|
|
9619
|
+
kind: "enum",
|
|
9620
|
+
variants: [
|
|
9621
|
+
{
|
|
9622
|
+
name: "Pyth"
|
|
9623
|
+
},
|
|
9624
|
+
{
|
|
9625
|
+
name: "StakePool"
|
|
9626
|
+
},
|
|
9627
|
+
{
|
|
9628
|
+
name: "MsolPool"
|
|
9629
|
+
},
|
|
9630
|
+
{
|
|
9631
|
+
name: "Redstone"
|
|
9632
|
+
},
|
|
9633
|
+
{
|
|
9634
|
+
name: "Chainlink"
|
|
9635
|
+
},
|
|
9636
|
+
{
|
|
9637
|
+
name: "SinglePool"
|
|
9638
|
+
},
|
|
9639
|
+
{
|
|
9640
|
+
name: "JupLend"
|
|
9641
|
+
},
|
|
9642
|
+
{
|
|
9643
|
+
name: "ChainlinkDataStreams"
|
|
9644
|
+
},
|
|
9645
|
+
{
|
|
9646
|
+
name: "PstPool"
|
|
9647
|
+
},
|
|
9648
|
+
{
|
|
9649
|
+
name: "DexSmartColPegOracle"
|
|
9650
|
+
},
|
|
9651
|
+
{
|
|
9652
|
+
name: "DexSmartDebtPegOracle"
|
|
9653
|
+
}
|
|
9654
|
+
]
|
|
9655
|
+
}
|
|
9656
|
+
}
|
|
9657
|
+
]
|
|
9658
|
+
};
|
|
9659
|
+
|
|
9660
|
+
// src/lending/public-data/jupiter-lend/flashloan.ts
|
|
9661
|
+
import {
|
|
9662
|
+
decodeBase58 as decodeBase582,
|
|
9663
|
+
decodeIdlAccount as decodeIdlAccount2,
|
|
9664
|
+
encodeBase58 as encodeBase582,
|
|
9665
|
+
findProgramAddress as findProgramAddress2,
|
|
9666
|
+
fromBase64 as fromBase642,
|
|
9667
|
+
getAssociatedTokenAddress
|
|
9668
|
+
} from "@1delta/svm-kit";
|
|
9669
|
+
|
|
9670
|
+
// src/lending/public-data/jupiter-lend/idl/flashloan.json
|
|
9671
|
+
var flashloan_default = {
|
|
9672
|
+
address: "jupgfSgfuAXv4B6R2Uxu85Z1qdzgju79s6MfZekN6XS",
|
|
9673
|
+
metadata: {
|
|
9674
|
+
name: "flashloan",
|
|
9675
|
+
version: "0.1.4",
|
|
9676
|
+
spec: "0.1.0",
|
|
9677
|
+
description: "Created with Anchor"
|
|
9678
|
+
},
|
|
9679
|
+
instructions: [
|
|
9680
|
+
{
|
|
9681
|
+
name: "activate_protocol",
|
|
9682
|
+
discriminator: [
|
|
9683
|
+
230,
|
|
9684
|
+
235,
|
|
9685
|
+
188,
|
|
9686
|
+
19,
|
|
9687
|
+
120,
|
|
9688
|
+
91,
|
|
9689
|
+
11,
|
|
9690
|
+
94
|
|
9691
|
+
],
|
|
9692
|
+
accounts: [
|
|
9693
|
+
{
|
|
9694
|
+
name: "authority",
|
|
9695
|
+
signer: true
|
|
9696
|
+
},
|
|
9697
|
+
{
|
|
9698
|
+
name: "flashloan_admin",
|
|
9699
|
+
writable: true
|
|
9700
|
+
}
|
|
9701
|
+
],
|
|
9702
|
+
args: []
|
|
9703
|
+
},
|
|
9704
|
+
{
|
|
9705
|
+
name: "flashloan_borrow",
|
|
9706
|
+
discriminator: [
|
|
9707
|
+
103,
|
|
9708
|
+
19,
|
|
9709
|
+
78,
|
|
9710
|
+
24,
|
|
9711
|
+
240,
|
|
9712
|
+
9,
|
|
9713
|
+
135,
|
|
9714
|
+
63
|
|
9715
|
+
],
|
|
9716
|
+
accounts: [
|
|
9717
|
+
{
|
|
9718
|
+
name: "signer",
|
|
9719
|
+
writable: true,
|
|
9720
|
+
signer: true
|
|
9721
|
+
},
|
|
9722
|
+
{
|
|
9723
|
+
name: "flashloan_admin",
|
|
9724
|
+
writable: true
|
|
9725
|
+
},
|
|
9726
|
+
{
|
|
9727
|
+
name: "signer_borrow_token_account",
|
|
9728
|
+
writable: true
|
|
9729
|
+
},
|
|
9730
|
+
{
|
|
9731
|
+
name: "mint"
|
|
9732
|
+
},
|
|
9733
|
+
{
|
|
9734
|
+
name: "flashloan_token_reserves_liquidity",
|
|
9735
|
+
writable: true
|
|
9736
|
+
},
|
|
9737
|
+
{
|
|
9738
|
+
name: "flashloan_borrow_position_on_liquidity",
|
|
9739
|
+
writable: true
|
|
9740
|
+
},
|
|
9741
|
+
{
|
|
9742
|
+
name: "rate_model"
|
|
9743
|
+
},
|
|
9744
|
+
{
|
|
9745
|
+
name: "vault",
|
|
9746
|
+
writable: true
|
|
9747
|
+
},
|
|
9748
|
+
{
|
|
9749
|
+
name: "liquidity"
|
|
9750
|
+
},
|
|
9751
|
+
{
|
|
9752
|
+
name: "liquidity_program",
|
|
9753
|
+
relations: [
|
|
9754
|
+
"flashloan_admin"
|
|
9755
|
+
]
|
|
9756
|
+
},
|
|
9757
|
+
{
|
|
9758
|
+
name: "token_program"
|
|
9759
|
+
},
|
|
9760
|
+
{
|
|
9761
|
+
name: "associated_token_program",
|
|
9762
|
+
optional: true,
|
|
9763
|
+
address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
|
|
9764
|
+
},
|
|
9765
|
+
{
|
|
9766
|
+
name: "system_program",
|
|
9767
|
+
address: "11111111111111111111111111111111"
|
|
9768
|
+
},
|
|
9769
|
+
{
|
|
9770
|
+
name: "instruction_sysvar",
|
|
9771
|
+
address: "Sysvar1nstructions1111111111111111111111111"
|
|
9772
|
+
}
|
|
9773
|
+
],
|
|
9774
|
+
args: [
|
|
9775
|
+
{
|
|
9776
|
+
name: "amount",
|
|
9777
|
+
type: "u64"
|
|
9778
|
+
}
|
|
9779
|
+
]
|
|
9780
|
+
},
|
|
9781
|
+
{
|
|
9782
|
+
name: "flashloan_payback",
|
|
9783
|
+
discriminator: [
|
|
9784
|
+
213,
|
|
9785
|
+
47,
|
|
9786
|
+
153,
|
|
9787
|
+
137,
|
|
9788
|
+
84,
|
|
9789
|
+
243,
|
|
9790
|
+
94,
|
|
9791
|
+
232
|
|
9792
|
+
],
|
|
9793
|
+
accounts: [
|
|
9794
|
+
{
|
|
9795
|
+
name: "signer",
|
|
9796
|
+
writable: true,
|
|
9797
|
+
signer: true
|
|
9798
|
+
},
|
|
9799
|
+
{
|
|
9800
|
+
name: "flashloan_admin",
|
|
9801
|
+
writable: true
|
|
9802
|
+
},
|
|
9803
|
+
{
|
|
9804
|
+
name: "signer_borrow_token_account",
|
|
9805
|
+
writable: true
|
|
9806
|
+
},
|
|
9807
|
+
{
|
|
9808
|
+
name: "mint"
|
|
9809
|
+
},
|
|
9810
|
+
{
|
|
9811
|
+
name: "flashloan_token_reserves_liquidity",
|
|
9812
|
+
writable: true
|
|
9813
|
+
},
|
|
9814
|
+
{
|
|
9815
|
+
name: "flashloan_borrow_position_on_liquidity",
|
|
9816
|
+
writable: true
|
|
9817
|
+
},
|
|
9818
|
+
{
|
|
9819
|
+
name: "rate_model"
|
|
9820
|
+
},
|
|
9821
|
+
{
|
|
9822
|
+
name: "vault",
|
|
9823
|
+
writable: true
|
|
9824
|
+
},
|
|
9825
|
+
{
|
|
9826
|
+
name: "liquidity"
|
|
9827
|
+
},
|
|
9828
|
+
{
|
|
9829
|
+
name: "liquidity_program",
|
|
9830
|
+
relations: [
|
|
9831
|
+
"flashloan_admin"
|
|
9832
|
+
]
|
|
9833
|
+
},
|
|
9834
|
+
{
|
|
9835
|
+
name: "token_program"
|
|
9836
|
+
},
|
|
9837
|
+
{
|
|
9838
|
+
name: "associated_token_program",
|
|
9839
|
+
optional: true,
|
|
9840
|
+
address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
|
|
9841
|
+
},
|
|
9842
|
+
{
|
|
9843
|
+
name: "system_program",
|
|
9844
|
+
address: "11111111111111111111111111111111"
|
|
9845
|
+
},
|
|
9846
|
+
{
|
|
9847
|
+
name: "instruction_sysvar",
|
|
9848
|
+
address: "Sysvar1nstructions1111111111111111111111111"
|
|
9849
|
+
}
|
|
9850
|
+
],
|
|
9851
|
+
args: [
|
|
9852
|
+
{
|
|
9853
|
+
name: "amount",
|
|
9854
|
+
type: "u64"
|
|
9855
|
+
}
|
|
9856
|
+
]
|
|
9857
|
+
},
|
|
9858
|
+
{
|
|
9859
|
+
name: "init_flashloan_admin",
|
|
9860
|
+
discriminator: [
|
|
9861
|
+
185,
|
|
9862
|
+
117,
|
|
9863
|
+
154,
|
|
9864
|
+
56,
|
|
9865
|
+
95,
|
|
9866
|
+
12,
|
|
9867
|
+
187,
|
|
9868
|
+
139
|
|
9869
|
+
],
|
|
9870
|
+
accounts: [
|
|
9871
|
+
{
|
|
9872
|
+
name: "signer",
|
|
9873
|
+
writable: true,
|
|
9874
|
+
signer: true
|
|
9875
|
+
},
|
|
9876
|
+
{
|
|
9877
|
+
name: "flashloan_admin",
|
|
9878
|
+
writable: true,
|
|
9879
|
+
pda: {
|
|
9880
|
+
seeds: [
|
|
9881
|
+
{
|
|
9882
|
+
kind: "const",
|
|
9883
|
+
value: [
|
|
9884
|
+
102,
|
|
9885
|
+
108,
|
|
9886
|
+
97,
|
|
9887
|
+
115,
|
|
9888
|
+
104,
|
|
9889
|
+
108,
|
|
9890
|
+
111,
|
|
9891
|
+
97,
|
|
9892
|
+
110,
|
|
9283
9893
|
95,
|
|
9284
9894
|
97,
|
|
9285
9895
|
100,
|
|
@@ -9672,38 +10282,947 @@ function decodeJupFlashloanAdmin(data) {
|
|
|
9672
10282
|
activeAmount: BigInt(a.active_flashloan_amount)
|
|
9673
10283
|
};
|
|
9674
10284
|
}
|
|
9675
|
-
async function readJupFlashloanAdmin(rpc, market = "main") {
|
|
9676
|
-
const address = await jupFlashloanAdmin(market);
|
|
9677
|
-
const { accounts } = await rpc.readAccounts([address], { encoding: "base64" });
|
|
9678
|
-
const a = accounts[0];
|
|
9679
|
-
if (!a || a.owner !== JUP_FLASHLOAN_PROGRAMS[market]) return null;
|
|
9680
|
-
return decodeJupFlashloanAdmin(fromBase642(a.data[0]));
|
|
10285
|
+
async function readJupFlashloanAdmin(rpc, market = "main") {
|
|
10286
|
+
const address = await jupFlashloanAdmin(market);
|
|
10287
|
+
const { accounts } = await rpc.readAccounts([address], { encoding: "base64" });
|
|
10288
|
+
const a = accounts[0];
|
|
10289
|
+
if (!a || a.owner !== JUP_FLASHLOAN_PROGRAMS[market]) return null;
|
|
10290
|
+
return decodeJupFlashloanAdmin(fromBase642(a.data[0]));
|
|
10291
|
+
}
|
|
10292
|
+
async function readJupFlashAssets(rpc, market = "main") {
|
|
10293
|
+
const admin = await jupFlashloanAdmin(market);
|
|
10294
|
+
const rows = await rpc.call(
|
|
10295
|
+
"getProgramAccounts",
|
|
10296
|
+
[
|
|
10297
|
+
JUP_LIQUIDITY_PROGRAMS[market],
|
|
10298
|
+
{
|
|
10299
|
+
encoding: "base64",
|
|
10300
|
+
dataSlice: { offset: 40, length: 32 },
|
|
10301
|
+
filters: [{ memcmp: { offset: 8, bytes: admin } }]
|
|
10302
|
+
}
|
|
10303
|
+
],
|
|
10304
|
+
{ accounts: 1 }
|
|
10305
|
+
);
|
|
10306
|
+
const mints = /* @__PURE__ */ new Set();
|
|
10307
|
+
for (const r of rows) mints.add(encodeBase582(fromBase642(r.account.data[0])));
|
|
10308
|
+
return [...mints];
|
|
10309
|
+
}
|
|
10310
|
+
async function readJupFlashAvailable(rpc, mint, tokenProgram, market = "main") {
|
|
10311
|
+
const vault = await jupLiquidityVault(mint, tokenProgram, market);
|
|
10312
|
+
const r = await rpc.call(
|
|
10313
|
+
"getTokenAccountBalance",
|
|
10314
|
+
[vault]
|
|
10315
|
+
);
|
|
10316
|
+
return BigInt(r.value.amount);
|
|
10317
|
+
}
|
|
10318
|
+
|
|
10319
|
+
// src/lending/public-data/jupiter-lend/onchain.ts
|
|
10320
|
+
var JL_VAULTS_ACCOUNTS_IDL = vaults_accounts_default;
|
|
10321
|
+
var JUP_VAULTS_PROGRAMS = {
|
|
10322
|
+
main: "jupr81YtYssSyPt8jbnGuiWon5f6x9TcDEFxYe3Bdzi",
|
|
10323
|
+
ethena: "jupo974WCqAUMD3RtpayTap1me7StQCWtEkBbDb6Ba3"
|
|
10324
|
+
};
|
|
10325
|
+
var JUP_DEX_PROGRAM = "jupZ4m2GqUCJ5iueMfzQf8khFfH31d4XAQt3RzCT9Vd";
|
|
10326
|
+
var JL_EXCHANGE_PRICES_PRECISION = 10n ** 12n;
|
|
10327
|
+
var RATE_OUTPUT = 10n ** 18n;
|
|
10328
|
+
var SCALE_FACTOR = 10n ** 18n;
|
|
10329
|
+
var FOUR_DECIMALS = 10000n;
|
|
10330
|
+
var SECONDS_PER_YEAR = 31536000n;
|
|
10331
|
+
var DEFAULT_MAX_UTILIZATION = 9500n;
|
|
10332
|
+
var JL_VAULT_AMOUNT_DECIMALS = 9;
|
|
10333
|
+
var isJlSmartCol = (t) => t === 2 || t === 4;
|
|
10334
|
+
var isJlSmartDebt = (t) => t === 3 || t === 4;
|
|
10335
|
+
var utf83 = (s) => new TextEncoder().encode(s);
|
|
10336
|
+
var u16le = (n) => new Uint8Array([n & 255, n >> 8 & 255]);
|
|
10337
|
+
var big = (v) => BigInt(v ?? 0);
|
|
10338
|
+
var maxB = (a, b) => a > b ? a : b;
|
|
10339
|
+
var minB = (a, b) => a < b ? a : b;
|
|
10340
|
+
var jlVaultConfigPda = async (vaultId, market = "main") => (await findProgramAddress3(
|
|
10341
|
+
[utf83("vault_config"), u16le(vaultId)],
|
|
10342
|
+
JUP_VAULTS_PROGRAMS[market]
|
|
10343
|
+
)).address;
|
|
10344
|
+
var jlVaultStatePda = async (vaultId, market = "main") => (await findProgramAddress3(
|
|
10345
|
+
[utf83("vault_state"), u16le(vaultId)],
|
|
10346
|
+
JUP_VAULTS_PROGRAMS[market]
|
|
10347
|
+
)).address;
|
|
10348
|
+
var jlVaultAdminPda = async (market = "main") => (await findProgramAddress3([utf83("vault_admin")], JUP_VAULTS_PROGRAMS[market])).address;
|
|
10349
|
+
var liq = async (seeds, market) => (await findProgramAddress3(seeds, JUP_LIQUIDITY_PROGRAMS[market])).address;
|
|
10350
|
+
var pk3 = async (a) => {
|
|
10351
|
+
const b = decodeBase583(a);
|
|
10352
|
+
if (!b || b.length !== 32) throw new Error(`not a pubkey: ${a}`);
|
|
10353
|
+
return b;
|
|
10354
|
+
};
|
|
10355
|
+
var dec = (name, data) => decodeIdlAccount3(JL_VAULTS_ACCOUNTS_IDL, name, fromBase643(data));
|
|
10356
|
+
var ratio = (withInterest, free) => {
|
|
10357
|
+
if (withInterest > free) return [free * FOUR_DECIMALS / withInterest, false];
|
|
10358
|
+
if (withInterest < free) return [withInterest * FOUR_DECIMALS / free, true];
|
|
10359
|
+
return [withInterest > 0n ? FOUR_DECIMALS : 0n, false];
|
|
10360
|
+
};
|
|
10361
|
+
function jlLiquidityExchangePrices(r, now) {
|
|
10362
|
+
let supplyEx = big(r.supply_exchange_price);
|
|
10363
|
+
let borrowEx = big(r.borrow_exchange_price);
|
|
10364
|
+
const borrowRate = BigInt(r.borrow_rate);
|
|
10365
|
+
const dt = now - big(r.last_update_timestamp);
|
|
10366
|
+
if (supplyEx === 0n || borrowEx === 0n || dt <= 0n || borrowRate === 0n)
|
|
10367
|
+
return { supplyEx, borrowEx };
|
|
10368
|
+
borrowEx += borrowEx * borrowRate * dt / (SECONDS_PER_YEAR * FOUR_DECIMALS);
|
|
10369
|
+
const [supplyRatio, supplyInverse] = ratio(
|
|
10370
|
+
big(r.total_supply_with_interest),
|
|
10371
|
+
big(r.total_supply_interest_free)
|
|
10372
|
+
);
|
|
10373
|
+
const [borrowRatio, borrowInverse] = ratio(
|
|
10374
|
+
big(r.total_borrow_with_interest),
|
|
10375
|
+
big(r.total_borrow_interest_free)
|
|
10376
|
+
);
|
|
10377
|
+
if (borrowRatio === 1n) return { supplyEx, borrowEx };
|
|
10378
|
+
if (supplyInverse && supplyRatio === 0n) return { supplyEx, borrowEx };
|
|
10379
|
+
const util = BigInt(r.last_utilization);
|
|
10380
|
+
let ratioSupplyYield = supplyInverse ? util * (RATE_OUTPUT + RATE_OUTPUT * FOUR_DECIMALS / supplyRatio) / FOUR_DECIMALS : util * RATE_OUTPUT * (FOUR_DECIMALS + supplyRatio) / (FOUR_DECIMALS * FOUR_DECIMALS);
|
|
10381
|
+
const adjBorrowRatio = borrowInverse ? borrowRatio * RATE_OUTPUT / (FOUR_DECIMALS + borrowRatio) : RATE_OUTPUT - borrowRatio * RATE_OUTPUT / (FOUR_DECIMALS + borrowRatio);
|
|
10382
|
+
ratioSupplyYield = ratioSupplyYield * adjBorrowRatio * FOUR_DECIMALS / RATE_OUTPUT / RATE_OUTPUT;
|
|
10383
|
+
const supplyRate = borrowRate * ratioSupplyYield * (FOUR_DECIMALS - BigInt(r.fee_on_interest));
|
|
10384
|
+
supplyEx += supplyEx * supplyRate * dt / (SECONDS_PER_YEAR * FOUR_DECIMALS) / (FOUR_DECIMALS * FOUR_DECIMALS);
|
|
10385
|
+
return { supplyEx, borrowEx };
|
|
10386
|
+
}
|
|
10387
|
+
function jlOverallTokenData(r, now) {
|
|
10388
|
+
const { supplyEx, borrowEx } = jlLiquidityExchangePrices(r, now);
|
|
10389
|
+
const supplyRaw = big(r.total_supply_with_interest);
|
|
10390
|
+
const borrowRaw = big(r.total_borrow_with_interest);
|
|
10391
|
+
const totalSupply = supplyRaw * supplyEx / JL_EXCHANGE_PRICES_PRECISION + big(r.total_supply_interest_free);
|
|
10392
|
+
const totalBorrow = borrowRaw * borrowEx / JL_EXCHANGE_PRICES_PRECISION + big(r.total_borrow_interest_free);
|
|
10393
|
+
let supplyRate = 0n;
|
|
10394
|
+
if (supplyRaw > 0n) {
|
|
10395
|
+
const b = borrowRaw * big(r.borrow_exchange_price) / JL_EXCHANGE_PRICES_PRECISION;
|
|
10396
|
+
const s = supplyRaw * big(r.supply_exchange_price) / JL_EXCHANGE_PRICES_PRECISION;
|
|
10397
|
+
if (s > 0n)
|
|
10398
|
+
supplyRate = BigInt(r.borrow_rate) * (FOUR_DECIMALS - BigInt(r.fee_on_interest)) * b / (s * FOUR_DECIMALS);
|
|
10399
|
+
}
|
|
10400
|
+
const maxUtil = BigInt(r.max_utilization) || DEFAULT_MAX_UTILIZATION;
|
|
10401
|
+
return {
|
|
10402
|
+
supplyEx,
|
|
10403
|
+
borrowEx,
|
|
10404
|
+
totalSupply,
|
|
10405
|
+
totalBorrow,
|
|
10406
|
+
supplyRate,
|
|
10407
|
+
borrowRate: BigInt(r.borrow_rate),
|
|
10408
|
+
maxUtilization: maxUtil
|
|
10409
|
+
};
|
|
10410
|
+
}
|
|
10411
|
+
function jlUserSupplyData(u, o, balance, now) {
|
|
10412
|
+
const z = {
|
|
10413
|
+
modeWithInterest: false,
|
|
10414
|
+
supply: 0n,
|
|
10415
|
+
withdrawalLimit: 0n,
|
|
10416
|
+
lastUpdateTimestamp: 0n,
|
|
10417
|
+
expandPercent: 0n,
|
|
10418
|
+
expandDuration: 0n,
|
|
10419
|
+
baseWithdrawalLimit: 0n,
|
|
10420
|
+
withdrawableUntilLimit: 0n,
|
|
10421
|
+
withdrawable: 0n,
|
|
10422
|
+
decayAmount: 0n,
|
|
10423
|
+
decayEndTimestamp: 0n
|
|
10424
|
+
};
|
|
10425
|
+
if (!u) return z;
|
|
10426
|
+
const amount = big(u.amount);
|
|
10427
|
+
const expandPct = BigInt(u.expand_pct);
|
|
10428
|
+
const expandDuration = BigInt(u.expand_duration);
|
|
10429
|
+
const last = big(u.last_update);
|
|
10430
|
+
let limit = 0n;
|
|
10431
|
+
const lastLimit = big(u.withdrawal_limit);
|
|
10432
|
+
if (lastLimit > 0n) {
|
|
10433
|
+
const maxWithdrawable = amount * expandPct / FOUR_DECIMALS;
|
|
10434
|
+
const expanded = expandDuration > 0n ? maxWithdrawable * (now - last) / expandDuration : maxWithdrawable;
|
|
10435
|
+
limit = lastLimit > expanded ? lastLimit - expanded : 0n;
|
|
10436
|
+
const floor = amount - maxWithdrawable;
|
|
10437
|
+
if (floor > limit) limit = floor;
|
|
10438
|
+
}
|
|
10439
|
+
let decay = big(u.decay_amount);
|
|
10440
|
+
let decayEnd = now;
|
|
10441
|
+
const decayDuration = BigInt(u.decay_duration);
|
|
10442
|
+
if (decay > 0n && decayDuration > 0n) {
|
|
10443
|
+
const elapsed = now - last;
|
|
10444
|
+
if (elapsed < decayDuration) {
|
|
10445
|
+
decay -= decay * elapsed / decayDuration;
|
|
10446
|
+
decayEnd = last + decayDuration;
|
|
10447
|
+
} else decay = 0n;
|
|
10448
|
+
}
|
|
10449
|
+
const withInterest = !!u.with_interest;
|
|
10450
|
+
const ex = (v) => withInterest ? v * o.supplyEx / JL_EXCHANGE_PRICES_PRECISION : v;
|
|
10451
|
+
const supply = ex(amount);
|
|
10452
|
+
let withdrawalLimit = ex(limit);
|
|
10453
|
+
const untilLimit = supply > withdrawalLimit ? supply - withdrawalLimit : 0n;
|
|
10454
|
+
if (withdrawalLimit === 0n) withdrawalLimit = supply;
|
|
10455
|
+
return {
|
|
10456
|
+
modeWithInterest: withInterest,
|
|
10457
|
+
supply,
|
|
10458
|
+
withdrawalLimit,
|
|
10459
|
+
lastUpdateTimestamp: last,
|
|
10460
|
+
expandPercent: expandPct,
|
|
10461
|
+
expandDuration,
|
|
10462
|
+
baseWithdrawalLimit: ex(big(u.base_withdrawal_limit)),
|
|
10463
|
+
withdrawableUntilLimit: untilLimit,
|
|
10464
|
+
withdrawable: minB(balance, untilLimit),
|
|
10465
|
+
decayAmount: ex(decay),
|
|
10466
|
+
decayEndTimestamp: decayEnd
|
|
10467
|
+
};
|
|
10468
|
+
}
|
|
10469
|
+
function jlUserBorrowData(u, o, balance, now) {
|
|
10470
|
+
const z = {
|
|
10471
|
+
modeWithInterest: false,
|
|
10472
|
+
borrow: 0n,
|
|
10473
|
+
borrowLimit: 0n,
|
|
10474
|
+
lastUpdateTimestamp: 0n,
|
|
10475
|
+
expandPercent: 0n,
|
|
10476
|
+
expandDuration: 0n,
|
|
10477
|
+
baseBorrowLimit: 0n,
|
|
10478
|
+
maxBorrowLimit: 0n,
|
|
10479
|
+
borrowLimitUtilization: 0n,
|
|
10480
|
+
borrowableUntilLimit: 0n,
|
|
10481
|
+
borrowable: 0n
|
|
10482
|
+
};
|
|
10483
|
+
if (!u) return z;
|
|
10484
|
+
const amount = big(u.amount);
|
|
10485
|
+
const expandPct = BigInt(u.expand_pct);
|
|
10486
|
+
const expandDuration = BigInt(u.expand_duration);
|
|
10487
|
+
const last = big(u.last_update);
|
|
10488
|
+
const base = big(u.base_debt_ceiling);
|
|
10489
|
+
const maxCeil = big(u.max_debt_ceiling);
|
|
10490
|
+
let limit;
|
|
10491
|
+
if (now < last || expandDuration === 0n) limit = base;
|
|
10492
|
+
else {
|
|
10493
|
+
const maxExpansion = amount * expandPct / FOUR_DECIMALS;
|
|
10494
|
+
limit = maxExpansion * (now - last) / expandDuration + big(u.debt_ceiling);
|
|
10495
|
+
limit = minB(limit, amount + maxExpansion);
|
|
10496
|
+
limit = maxB(limit, base);
|
|
10497
|
+
limit = minB(limit, maxCeil);
|
|
10498
|
+
}
|
|
10499
|
+
const withInterest = !!u.with_interest;
|
|
10500
|
+
const ex = (v) => withInterest ? v * o.borrowEx / JL_EXCHANGE_PRICES_PRECISION : v;
|
|
10501
|
+
const borrow = ex(amount);
|
|
10502
|
+
const borrowLimit = ex(limit);
|
|
10503
|
+
const borrowLimitUtilization = o.maxUtilization * o.totalSupply / FOUR_DECIMALS;
|
|
10504
|
+
const untilUtil = borrowLimitUtilization > o.totalBorrow ? borrowLimitUtilization - o.totalBorrow : 0n;
|
|
10505
|
+
const untilLimit = borrowLimit > borrow ? borrowLimit - borrow : 0n;
|
|
10506
|
+
const borrowableUntilLimit = minB(untilLimit, untilUtil);
|
|
10507
|
+
return {
|
|
10508
|
+
modeWithInterest: withInterest,
|
|
10509
|
+
borrow,
|
|
10510
|
+
borrowLimit,
|
|
10511
|
+
lastUpdateTimestamp: last,
|
|
10512
|
+
expandPercent: expandPct,
|
|
10513
|
+
expandDuration,
|
|
10514
|
+
baseBorrowLimit: ex(base),
|
|
10515
|
+
maxBorrowLimit: ex(maxCeil),
|
|
10516
|
+
borrowLimitUtilization,
|
|
10517
|
+
borrowableUntilLimit,
|
|
10518
|
+
borrowable: minB(balance, borrowableUntilLimit)
|
|
10519
|
+
};
|
|
10520
|
+
}
|
|
10521
|
+
function jlVaultExchangePrices(s, c, liqSupplyEx, liqBorrowEx, now) {
|
|
10522
|
+
const oldLs = big(s.liquidity_supply_exchange_price);
|
|
10523
|
+
const oldLb = big(s.liquidity_borrow_exchange_price);
|
|
10524
|
+
const vs = big(s.vault_supply_exchange_price);
|
|
10525
|
+
const vb = big(s.vault_borrow_exchange_price);
|
|
10526
|
+
if (liqSupplyEx < oldLs || liqBorrowEx < oldLb || oldLs === 0n || oldLb === 0n)
|
|
10527
|
+
return { supplyEx: vs, borrowEx: vb };
|
|
10528
|
+
const dt = maxB(0n, now - big(s.last_update_timestamp));
|
|
10529
|
+
let supplyEx = vs * (liqSupplyEx * SCALE_FACTOR / oldLs) / SCALE_FACTOR;
|
|
10530
|
+
const sm = BigInt(c.supply_rate_magnifier);
|
|
10531
|
+
if (sm !== 0n) {
|
|
10532
|
+
const ch = vs * dt * (sm < 0n ? -sm : sm) / FOUR_DECIMALS / SECONDS_PER_YEAR;
|
|
10533
|
+
supplyEx = sm > 0n ? supplyEx + ch : supplyEx - ch;
|
|
10534
|
+
}
|
|
10535
|
+
const prod = vb * (liqBorrowEx * SCALE_FACTOR / oldLb);
|
|
10536
|
+
let borrowEx = (prod + SCALE_FACTOR - 1n) / SCALE_FACTOR;
|
|
10537
|
+
const bm = BigInt(c.borrow_rate_magnifier);
|
|
10538
|
+
if (bm !== 0n) {
|
|
10539
|
+
const ch = vb * dt * (bm < 0n ? -bm : bm) / FOUR_DECIMALS / SECONDS_PER_YEAR;
|
|
10540
|
+
borrowEx = bm > 0n ? borrowEx + ch : borrowEx - ch;
|
|
10541
|
+
}
|
|
10542
|
+
return { supplyEx, borrowEx };
|
|
10543
|
+
}
|
|
10544
|
+
var jlVaultToRaw = (v, decimals) => decimals >= JL_VAULT_AMOUNT_DECIMALS ? v * 10n ** BigInt(decimals - JL_VAULT_AMOUNT_DECIMALS) : v / 10n ** BigInt(JL_VAULT_AMOUNT_DECIMALS - decimals);
|
|
10545
|
+
async function read(rpc, keys) {
|
|
10546
|
+
const uniq = [...new Set(keys)];
|
|
10547
|
+
const { accounts, slot } = await rpc.readAccounts(uniq, {
|
|
10548
|
+
encoding: "base64"
|
|
10549
|
+
});
|
|
10550
|
+
const m = /* @__PURE__ */ new Map();
|
|
10551
|
+
uniq.forEach((k, i) => m.set(k, accounts[i] ?? null));
|
|
10552
|
+
return { m, slot };
|
|
10553
|
+
}
|
|
10554
|
+
async function readJlNextVaultId(rpc, market = "main") {
|
|
10555
|
+
const admin = await jlVaultAdminPda(market);
|
|
10556
|
+
const { m } = await read(rpc, [admin]);
|
|
10557
|
+
const a = m.get(admin);
|
|
10558
|
+
if (!a || a.owner !== JUP_VAULTS_PROGRAMS[market]) return void 0;
|
|
10559
|
+
return Number(
|
|
10560
|
+
dec("VaultAdmin", a.data[0]).next_vault_id
|
|
10561
|
+
);
|
|
10562
|
+
}
|
|
10563
|
+
var sourceTypeName = (t) => {
|
|
10564
|
+
if (typeof t === "string") return t;
|
|
10565
|
+
if (t && typeof t === "object") return Object.keys(t)[0] ?? "unknown";
|
|
10566
|
+
return String(t);
|
|
10567
|
+
};
|
|
10568
|
+
var lowerFirst = (s) => s.charAt(0).toLowerCase() + s.slice(1);
|
|
10569
|
+
async function readJupiterLendVaultsOnchain(rpc, market, vaultIds, opts = {}) {
|
|
10570
|
+
if (!vaultIds.length) return [];
|
|
10571
|
+
const now = BigInt(opts.now ?? Math.floor(Date.now() / 1e3));
|
|
10572
|
+
const program = JUP_VAULTS_PROGRAMS[market];
|
|
10573
|
+
const cfgKeys = await Promise.all(
|
|
10574
|
+
vaultIds.map((i) => jlVaultConfigPda(i, market))
|
|
10575
|
+
);
|
|
10576
|
+
const stateKeys = await Promise.all(
|
|
10577
|
+
vaultIds.map((i) => jlVaultStatePda(i, market))
|
|
10578
|
+
);
|
|
10579
|
+
const r1 = await read(rpc, [...cfgKeys, ...stateKeys]);
|
|
10580
|
+
const items = [];
|
|
10581
|
+
vaultIds.forEach((id, k) => {
|
|
10582
|
+
const ca = r1.m.get(cfgKeys[k]);
|
|
10583
|
+
const sa = r1.m.get(stateKeys[k]);
|
|
10584
|
+
if (!ca || !sa || ca.owner !== program || sa.owner !== program) return;
|
|
10585
|
+
try {
|
|
10586
|
+
const c = dec("VaultConfig", ca.data[0]);
|
|
10587
|
+
const s = dec("VaultState", sa.data[0]);
|
|
10588
|
+
const t = Number(c.vault_type);
|
|
10589
|
+
items.push({
|
|
10590
|
+
id,
|
|
10591
|
+
configKey: cfgKeys[k],
|
|
10592
|
+
c,
|
|
10593
|
+
s,
|
|
10594
|
+
smartCol: isJlSmartCol(t),
|
|
10595
|
+
smartDebt: isJlSmartDebt(t)
|
|
10596
|
+
});
|
|
10597
|
+
} catch (e) {
|
|
10598
|
+
console.warn(
|
|
10599
|
+
`[jupiter-lend] vault ${market}_${id}: ${e.message}`
|
|
10600
|
+
);
|
|
10601
|
+
}
|
|
10602
|
+
});
|
|
10603
|
+
if (!items.length) return [];
|
|
10604
|
+
const mints = /* @__PURE__ */ new Set();
|
|
10605
|
+
const dexes = /* @__PURE__ */ new Set();
|
|
10606
|
+
const r2Keys = [];
|
|
10607
|
+
const reserveOf = /* @__PURE__ */ new Map();
|
|
10608
|
+
const supplyPosOf = /* @__PURE__ */ new Map();
|
|
10609
|
+
const borrowPosOf = /* @__PURE__ */ new Map();
|
|
10610
|
+
for (const it of items) {
|
|
10611
|
+
r2Keys.push(it.c.oracle);
|
|
10612
|
+
const sides = [
|
|
10613
|
+
[it.c.supply_token, it.smartCol, "supply"],
|
|
10614
|
+
[it.c.borrow_token, it.smartDebt, "borrow"]
|
|
10615
|
+
];
|
|
10616
|
+
for (const [token, smart, side] of sides) {
|
|
10617
|
+
if (smart) {
|
|
10618
|
+
dexes.add(token);
|
|
10619
|
+
continue;
|
|
10620
|
+
}
|
|
10621
|
+
mints.add(token);
|
|
10622
|
+
if (!reserveOf.has(token))
|
|
10623
|
+
reserveOf.set(
|
|
10624
|
+
token,
|
|
10625
|
+
await liq([utf83("reserve"), await pk3(token)], market)
|
|
10626
|
+
);
|
|
10627
|
+
const pos = await liq(
|
|
10628
|
+
[
|
|
10629
|
+
utf83(
|
|
10630
|
+
side === "supply" ? "user_supply_position" : "user_borrow_position"
|
|
10631
|
+
),
|
|
10632
|
+
await pk3(token),
|
|
10633
|
+
await pk3(it.configKey)
|
|
10634
|
+
],
|
|
10635
|
+
market
|
|
10636
|
+
);
|
|
10637
|
+
(side === "supply" ? supplyPosOf : borrowPosOf).set(
|
|
10638
|
+
`${it.id}:${token}`,
|
|
10639
|
+
pos
|
|
10640
|
+
);
|
|
10641
|
+
}
|
|
10642
|
+
}
|
|
10643
|
+
r2Keys.push(
|
|
10644
|
+
...mints,
|
|
10645
|
+
...dexes,
|
|
10646
|
+
...reserveOf.values(),
|
|
10647
|
+
...supplyPosOf.values(),
|
|
10648
|
+
...borrowPosOf.values()
|
|
10649
|
+
);
|
|
10650
|
+
const r2 = await read(rpc, r2Keys);
|
|
10651
|
+
const decimalsOf = /* @__PURE__ */ new Map();
|
|
10652
|
+
for (const mint of mints) {
|
|
10653
|
+
const a = r2.m.get(mint);
|
|
10654
|
+
if (!a) continue;
|
|
10655
|
+
const b = fromBase643(a.data[0]);
|
|
10656
|
+
if (b.length >= 45) decimalsOf.set(mint, b[44]);
|
|
10657
|
+
}
|
|
10658
|
+
const reserves = /* @__PURE__ */ new Map();
|
|
10659
|
+
for (const [mint, key2] of reserveOf) {
|
|
10660
|
+
const a = r2.m.get(key2);
|
|
10661
|
+
if (!a) continue;
|
|
10662
|
+
try {
|
|
10663
|
+
reserves.set(mint, dec("TokenReserve", a.data[0]));
|
|
10664
|
+
} catch (e) {
|
|
10665
|
+
console.warn(`[jupiter-lend] reserve ${mint}: ${e.message}`);
|
|
10666
|
+
}
|
|
10667
|
+
}
|
|
10668
|
+
const vaultOf = /* @__PURE__ */ new Map();
|
|
10669
|
+
for (const [mint, r] of reserves) vaultOf.set(mint, r.vault);
|
|
10670
|
+
const r3 = vaultOf.size ? await read(rpc, [...vaultOf.values()]) : { m: /* @__PURE__ */ new Map(), slot: r2.slot };
|
|
10671
|
+
const balanceOf = (mint) => {
|
|
10672
|
+
const a = r3.m.get(vaultOf.get(mint) ?? "");
|
|
10673
|
+
if (!a) return 0n;
|
|
10674
|
+
const b = fromBase643(a.data[0]);
|
|
10675
|
+
return b.length >= 72 ? new DataView(b.buffer, b.byteOffset, b.byteLength).getBigUint64(
|
|
10676
|
+
64,
|
|
10677
|
+
true
|
|
10678
|
+
) : 0n;
|
|
10679
|
+
};
|
|
10680
|
+
const overall = /* @__PURE__ */ new Map();
|
|
10681
|
+
for (const [mint, r] of reserves)
|
|
10682
|
+
overall.set(mint, jlOverallTokenData(r, now));
|
|
10683
|
+
const dexOf = (address) => {
|
|
10684
|
+
const a = r2.m.get(address);
|
|
10685
|
+
if (!a) return void 0;
|
|
10686
|
+
try {
|
|
10687
|
+
const d2 = dec("Dex", a.data[0]);
|
|
10688
|
+
return { address, token0: d2.token_0, token1: d2.token_1 };
|
|
10689
|
+
} catch {
|
|
10690
|
+
return void 0;
|
|
10691
|
+
}
|
|
10692
|
+
};
|
|
10693
|
+
const tokenFact = (mint, decimals) => {
|
|
10694
|
+
const known = opts.tokens?.[mint];
|
|
10695
|
+
if (known) return known;
|
|
10696
|
+
const l = opts.tokenList?.[mint];
|
|
10697
|
+
const sym = l?.symbol ?? mint.slice(0, 4);
|
|
10698
|
+
return {
|
|
10699
|
+
address: mint,
|
|
10700
|
+
chainId: "solana",
|
|
10701
|
+
name: l?.name ?? sym,
|
|
10702
|
+
symbol: sym,
|
|
10703
|
+
uiSymbol: sym,
|
|
10704
|
+
decimals: l?.decimals ?? decimals,
|
|
10705
|
+
...typeof l?.logoURI === "string" ? { logoUrl: l.logoURI } : {},
|
|
10706
|
+
// unpriced: the converter's USD figures read 0 — say so on the bundle, never invent
|
|
10707
|
+
price: "0"
|
|
10708
|
+
};
|
|
10709
|
+
};
|
|
10710
|
+
const dexToken = (d2, address) => {
|
|
10711
|
+
const s = (m) => opts.tokens?.[m]?.uiSymbol ?? opts.tokenList?.[m]?.symbol ?? m.slice(0, 4);
|
|
10712
|
+
const sym = d2 ? `${s(d2.token0)}-${s(d2.token1)} DEX` : `DEX ${address.slice(0, 4)}`;
|
|
10713
|
+
return {
|
|
10714
|
+
address,
|
|
10715
|
+
chainId: "solana",
|
|
10716
|
+
name: `Jupiter Lend ${sym} shares`,
|
|
10717
|
+
symbol: sym,
|
|
10718
|
+
uiSymbol: sym,
|
|
10719
|
+
decimals: JL_VAULT_AMOUNT_DECIMALS,
|
|
10720
|
+
price: "0"
|
|
10721
|
+
};
|
|
10722
|
+
};
|
|
10723
|
+
const out = [];
|
|
10724
|
+
for (const it of items) {
|
|
10725
|
+
const { c, s } = it;
|
|
10726
|
+
const supTok = c.supply_token;
|
|
10727
|
+
const borTok = c.borrow_token;
|
|
10728
|
+
const supO = it.smartCol ? void 0 : overall.get(supTok);
|
|
10729
|
+
const borO = it.smartDebt ? void 0 : overall.get(borTok);
|
|
10730
|
+
if (!it.smartCol && !supO || !it.smartDebt && !borO) {
|
|
10731
|
+
console.warn(
|
|
10732
|
+
`[jupiter-lend] vault ${market}_${it.id}: layer reserve not readable, skipped`
|
|
10733
|
+
);
|
|
10734
|
+
continue;
|
|
10735
|
+
}
|
|
10736
|
+
const supDec = it.smartCol ? JL_VAULT_AMOUNT_DECIMALS : decimalsOf.get(supTok) ?? 9;
|
|
10737
|
+
const borDec = it.smartDebt ? JL_VAULT_AMOUNT_DECIMALS : decimalsOf.get(borTok) ?? 9;
|
|
10738
|
+
const zero = {
|
|
10739
|
+
supplyEx: JL_EXCHANGE_PRICES_PRECISION,
|
|
10740
|
+
borrowEx: JL_EXCHANGE_PRICES_PRECISION,
|
|
10741
|
+
totalSupply: 0n,
|
|
10742
|
+
totalBorrow: 0n,
|
|
10743
|
+
supplyRate: 0n,
|
|
10744
|
+
borrowRate: 0n,
|
|
10745
|
+
maxUtilization: DEFAULT_MAX_UTILIZATION
|
|
10746
|
+
};
|
|
10747
|
+
const so = supO ?? zero;
|
|
10748
|
+
const bo = borO ?? zero;
|
|
10749
|
+
const supBal = it.smartCol ? 0n : balanceOf(supTok);
|
|
10750
|
+
const borBal = it.smartDebt ? 0n : balanceOf(borTok);
|
|
10751
|
+
const us = (() => {
|
|
10752
|
+
const a = r2.m.get(supplyPosOf.get(`${it.id}:${supTok}`) ?? "");
|
|
10753
|
+
return a ? dec("UserSupplyPosition", a.data[0]) : void 0;
|
|
10754
|
+
})();
|
|
10755
|
+
const ub = (() => {
|
|
10756
|
+
const a = r2.m.get(borrowPosOf.get(`${it.id}:${borTok}`) ?? "");
|
|
10757
|
+
return a ? dec("UserBorrowPosition", a.data[0]) : void 0;
|
|
10758
|
+
})();
|
|
10759
|
+
const sup = jlUserSupplyData(it.smartCol ? void 0 : us, so, supBal, now);
|
|
10760
|
+
const bor = jlUserBorrowData(it.smartDebt ? void 0 : ub, bo, borBal, now);
|
|
10761
|
+
const ex = jlVaultExchangePrices(
|
|
10762
|
+
s,
|
|
10763
|
+
c,
|
|
10764
|
+
it.smartCol ? JL_EXCHANGE_PRICES_PRECISION : so.supplyEx,
|
|
10765
|
+
it.smartDebt ? JL_EXCHANGE_PRICES_PRECISION : bo.borrowEx,
|
|
10766
|
+
now
|
|
10767
|
+
);
|
|
10768
|
+
const supplyEx = it.smartCol ? big(s.vault_supply_exchange_price) : ex.supplyEx;
|
|
10769
|
+
const borrowEx = it.smartDebt ? big(s.vault_borrow_exchange_price) : ex.borrowEx;
|
|
10770
|
+
const P = JL_EXCHANGE_PRICES_PRECISION;
|
|
10771
|
+
const totalSupply = jlVaultToRaw(
|
|
10772
|
+
big(s.total_supply) * supplyEx / P,
|
|
10773
|
+
supDec
|
|
10774
|
+
);
|
|
10775
|
+
const totalBorrow = jlVaultToRaw(
|
|
10776
|
+
big(s.total_borrow) * borrowEx / P,
|
|
10777
|
+
borDec
|
|
10778
|
+
);
|
|
10779
|
+
const absorbedSupply = jlVaultToRaw(
|
|
10780
|
+
big(s.absorbed_col_amount) * supplyEx / P,
|
|
10781
|
+
supDec
|
|
10782
|
+
);
|
|
10783
|
+
const absorbedBorrow = jlVaultToRaw(
|
|
10784
|
+
big(s.absorbed_debt_amount) * borrowEx / P,
|
|
10785
|
+
borDec
|
|
10786
|
+
);
|
|
10787
|
+
let withdrawLimit = 0n;
|
|
10788
|
+
let withdrawableUntilLimit = 0n;
|
|
10789
|
+
let withdrawable = 0n;
|
|
10790
|
+
if (sup.supply > 0n) {
|
|
10791
|
+
withdrawLimit = sup.withdrawalLimit;
|
|
10792
|
+
const gap = sup.supply * BigInt(c.withdraw_gap) / 1000n;
|
|
10793
|
+
withdrawableUntilLimit = sup.withdrawableUntilLimit > gap ? (sup.withdrawableUntilLimit - gap) * 999999n / 1000000n : 0n;
|
|
10794
|
+
withdrawable = minB(supBal, withdrawableUntilLimit);
|
|
10795
|
+
}
|
|
10796
|
+
let borrowLimit = 0n;
|
|
10797
|
+
let borrowLimitUtilization = 0n;
|
|
10798
|
+
let borrowableUntilLimit = 0n;
|
|
10799
|
+
let borrowable = 0n;
|
|
10800
|
+
if (bor.borrow > 0n) {
|
|
10801
|
+
borrowLimit = bor.borrowLimit;
|
|
10802
|
+
borrowLimitUtilization = bor.borrowLimitUtilization;
|
|
10803
|
+
borrowableUntilLimit = bor.borrowableUntilLimit * 999999n / 1000000n;
|
|
10804
|
+
borrowable = minB(borBal, borrowableUntilLimit);
|
|
10805
|
+
}
|
|
10806
|
+
const minimumBorrowing = jlVaultToRaw(10001n * borrowEx / P, borDec);
|
|
10807
|
+
const supplyRateLiq = it.smartCol ? 0n : so.supplyRate;
|
|
10808
|
+
const borrowRateLiq = it.smartDebt ? 0n : bo.borrowRate;
|
|
10809
|
+
const supplyRate = supplyRateLiq + BigInt(c.supply_rate_magnifier);
|
|
10810
|
+
const borrowRate = borrowRateLiq + BigInt(c.borrow_rate_magnifier);
|
|
10811
|
+
const supplyDex = it.smartCol ? dexOf(supTok) : void 0;
|
|
10812
|
+
const borrowDex = it.smartDebt ? dexOf(borTok) : void 0;
|
|
10813
|
+
const supplyToken = it.smartCol ? dexToken(supplyDex, supTok) : tokenFact(supTok, supDec);
|
|
10814
|
+
const borrowToken = it.smartDebt ? dexToken(borrowDex, borTok) : tokenFact(borTok, borDec);
|
|
10815
|
+
let oracleSources = [];
|
|
10816
|
+
const oa = r2.m.get(c.oracle);
|
|
10817
|
+
if (oa)
|
|
10818
|
+
try {
|
|
10819
|
+
oracleSources = dec("Oracle", oa.data[0]).sources.map(
|
|
10820
|
+
(x) => ({
|
|
10821
|
+
source: x.source,
|
|
10822
|
+
invert: x.invert,
|
|
10823
|
+
multiplier: String(x.multiplier),
|
|
10824
|
+
divisor: String(x.divisor),
|
|
10825
|
+
sourceType: { [lowerFirst(sourceTypeName(x.source_type))]: {} }
|
|
10826
|
+
})
|
|
10827
|
+
);
|
|
10828
|
+
} catch {
|
|
10829
|
+
}
|
|
10830
|
+
const vault = {
|
|
10831
|
+
id: it.id,
|
|
10832
|
+
address: it.configKey,
|
|
10833
|
+
type: Number(c.vault_type),
|
|
10834
|
+
supplyToken,
|
|
10835
|
+
borrowToken,
|
|
10836
|
+
totalSupply: totalSupply.toString(),
|
|
10837
|
+
totalSupplyLiquidity: sup.supply.toString(),
|
|
10838
|
+
totalBorrow: totalBorrow.toString(),
|
|
10839
|
+
totalBorrowLiquidity: bor.borrow.toString(),
|
|
10840
|
+
absorbedSupply: absorbedSupply.toString(),
|
|
10841
|
+
absorbedBorrow: absorbedBorrow.toString(),
|
|
10842
|
+
supplyRateMagnifier: String(c.supply_rate_magnifier),
|
|
10843
|
+
borrowRateMagnifier: String(c.borrow_rate_magnifier),
|
|
10844
|
+
borrowFee: String(c.borrow_fee),
|
|
10845
|
+
collateralFactor: String(c.collateral_factor),
|
|
10846
|
+
liquidationThreshold: String(c.liquidation_threshold),
|
|
10847
|
+
liquidationMaxLimit: String(c.liquidation_max_limit),
|
|
10848
|
+
liquidationPenalty: String(c.liquidation_penalty),
|
|
10849
|
+
withdrawalGap: String(c.withdraw_gap),
|
|
10850
|
+
supplyRate: supplyRate.toString(),
|
|
10851
|
+
supplyRateLiquidity: supplyRateLiq.toString(),
|
|
10852
|
+
borrowRate: borrowRate.toString(),
|
|
10853
|
+
borrowRateLiquidity: borrowRateLiq.toString(),
|
|
10854
|
+
withdrawLimit: withdrawLimit.toString(),
|
|
10855
|
+
withdrawableUntilLimit: withdrawableUntilLimit.toString(),
|
|
10856
|
+
withdrawable: withdrawable.toString(),
|
|
10857
|
+
borrowLimit: borrowLimit.toString(),
|
|
10858
|
+
borrowableUntilLimit: borrowableUntilLimit.toString(),
|
|
10859
|
+
borrowable: borrowable.toString(),
|
|
10860
|
+
borrowLimitUtilization: borrowLimitUtilization.toString(),
|
|
10861
|
+
minimumBorrowing: minimumBorrowing.toString(),
|
|
10862
|
+
totalPositions: Number(s.total_positions),
|
|
10863
|
+
oracle: c.oracle,
|
|
10864
|
+
oraclePrice: "",
|
|
10865
|
+
oraclePriceOperate: "",
|
|
10866
|
+
oraclePriceLiquidate: "",
|
|
10867
|
+
oracleSources,
|
|
10868
|
+
oracleTimestamp: 0,
|
|
10869
|
+
liquiditySupplyData: {
|
|
10870
|
+
modeWithInterest: sup.modeWithInterest,
|
|
10871
|
+
supply: sup.supply.toString(),
|
|
10872
|
+
withdrawalLimit: sup.withdrawalLimit.toString(),
|
|
10873
|
+
lastUpdateTimestamp: sup.lastUpdateTimestamp.toString(),
|
|
10874
|
+
expandPercent: sup.expandPercent.toString(),
|
|
10875
|
+
expandDuration: sup.expandDuration.toString(),
|
|
10876
|
+
baseWithdrawalLimit: sup.baseWithdrawalLimit.toString(),
|
|
10877
|
+
withdrawableUntilLimit: sup.withdrawableUntilLimit.toString(),
|
|
10878
|
+
withdrawable: sup.withdrawable.toString(),
|
|
10879
|
+
decayAmount: sup.decayAmount.toString(),
|
|
10880
|
+
decayEndTimestamp: sup.decayEndTimestamp.toString()
|
|
10881
|
+
},
|
|
10882
|
+
liquidityBorrowData: {
|
|
10883
|
+
modeWithInterest: bor.modeWithInterest,
|
|
10884
|
+
borrow: bor.borrow.toString(),
|
|
10885
|
+
borrowLimit: bor.borrowLimit.toString(),
|
|
10886
|
+
lastUpdateTimestamp: bor.lastUpdateTimestamp.toString(),
|
|
10887
|
+
expandPercent: bor.expandPercent.toString(),
|
|
10888
|
+
expandDuration: bor.expandDuration.toString(),
|
|
10889
|
+
baseBorrowLimit: bor.baseBorrowLimit.toString(),
|
|
10890
|
+
maxBorrowLimit: bor.maxBorrowLimit.toString(),
|
|
10891
|
+
borrowLimitUtilization: bor.borrowLimitUtilization.toString(),
|
|
10892
|
+
borrowableUntilLimit: bor.borrowableUntilLimit.toString(),
|
|
10893
|
+
borrowable: bor.borrowable.toString()
|
|
10894
|
+
},
|
|
10895
|
+
rewards: [],
|
|
10896
|
+
topTick: Number(s.topmost_tick),
|
|
10897
|
+
metadata: { maxLeverage: false, nativeStake: false, pegged: false }
|
|
10898
|
+
};
|
|
10899
|
+
out.push({
|
|
10900
|
+
vault,
|
|
10901
|
+
smartCol: it.smartCol,
|
|
10902
|
+
smartDebt: it.smartDebt,
|
|
10903
|
+
supplyDex,
|
|
10904
|
+
borrowDex,
|
|
10905
|
+
slot: r2.slot
|
|
10906
|
+
});
|
|
10907
|
+
}
|
|
10908
|
+
return out;
|
|
10909
|
+
}
|
|
10910
|
+
function decodeJlRateModel(data) {
|
|
10911
|
+
if (data.length < 53)
|
|
10912
|
+
throw new Error(`RateModel is ${data.length} bytes, expected 53`);
|
|
10913
|
+
const v = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
10914
|
+
const u16 = (o) => v.getUint16(o, true);
|
|
10915
|
+
const version = data[40];
|
|
10916
|
+
if (version !== 1 && version !== 2)
|
|
10917
|
+
throw new Error(`RateModel version ${version} not supported`);
|
|
10918
|
+
return {
|
|
10919
|
+
version,
|
|
10920
|
+
rateAtZero: u16(41),
|
|
10921
|
+
kink1: u16(43),
|
|
10922
|
+
rateAtKink1: u16(45),
|
|
10923
|
+
rateAtMax: u16(47),
|
|
10924
|
+
...version === 2 ? { kink2: u16(49), rateAtKink2: u16(51) } : {}
|
|
10925
|
+
};
|
|
9681
10926
|
}
|
|
9682
|
-
async function
|
|
9683
|
-
const
|
|
9684
|
-
const
|
|
9685
|
-
|
|
9686
|
-
|
|
9687
|
-
|
|
9688
|
-
|
|
9689
|
-
|
|
9690
|
-
dataSlice: { offset: 40, length: 32 },
|
|
9691
|
-
filters: [{ memcmp: { offset: 8, bytes: admin } }]
|
|
9692
|
-
}
|
|
9693
|
-
],
|
|
9694
|
-
{ accounts: 1 }
|
|
10927
|
+
async function readJlLayerIrms(rpc, market, mints, now = BigInt(Math.floor(Date.now() / 1e3))) {
|
|
10928
|
+
const uniq = [...new Set(mints)];
|
|
10929
|
+
const keys = await Promise.all(
|
|
10930
|
+
uniq.map(async (m2) => ({
|
|
10931
|
+
mint: m2,
|
|
10932
|
+
model: await liq([utf83("rate_model"), await pk3(m2)], market),
|
|
10933
|
+
reserve: await liq([utf83("reserve"), await pk3(m2)], market)
|
|
10934
|
+
}))
|
|
9695
10935
|
);
|
|
9696
|
-
const
|
|
9697
|
-
|
|
9698
|
-
|
|
9699
|
-
}
|
|
9700
|
-
async function readJupFlashAvailable(rpc, mint, tokenProgram, market = "main") {
|
|
9701
|
-
const vault = await jupLiquidityVault(mint, tokenProgram, market);
|
|
9702
|
-
const r = await rpc.call(
|
|
9703
|
-
"getTokenAccountBalance",
|
|
9704
|
-
[vault]
|
|
10936
|
+
const { m } = await read(
|
|
10937
|
+
rpc,
|
|
10938
|
+
keys.flatMap((k) => [k.model, k.reserve])
|
|
9705
10939
|
);
|
|
9706
|
-
|
|
10940
|
+
const out = /* @__PURE__ */ new Map();
|
|
10941
|
+
for (const k of keys) {
|
|
10942
|
+
const ma = m.get(k.model);
|
|
10943
|
+
const ra = m.get(k.reserve);
|
|
10944
|
+
if (!ma || !ra) continue;
|
|
10945
|
+
try {
|
|
10946
|
+
const model = decodeJlRateModel(fromBase643(ma.data[0]));
|
|
10947
|
+
const r = dec("TokenReserve", ra.data[0]);
|
|
10948
|
+
const o = jlOverallTokenData(r, now);
|
|
10949
|
+
const P = JL_EXCHANGE_PRICES_PRECISION;
|
|
10950
|
+
const bWi = Number(big(r.total_borrow_with_interest) * o.borrowEx / P);
|
|
10951
|
+
const sWi = Number(big(r.total_supply_with_interest) * o.supplyEx / P);
|
|
10952
|
+
const tb = Number(o.totalBorrow);
|
|
10953
|
+
const ts = Number(o.totalSupply);
|
|
10954
|
+
const u = ts > 0 ? tb / ts : 0;
|
|
10955
|
+
const ratio2 = u > 0 && sWi > 0 ? bWi / sWi / u : 1;
|
|
10956
|
+
out.set(k.mint, {
|
|
10957
|
+
...model,
|
|
10958
|
+
feeOnInterest: Number(r.fee_on_interest),
|
|
10959
|
+
maxUtilization: Number(o.maxUtilization),
|
|
10960
|
+
supplyWithInterestRatio: Number.isFinite(ratio2) ? ratio2 : 1,
|
|
10961
|
+
lastUtilization: Number(r.last_utilization),
|
|
10962
|
+
borrowRate: Number(r.borrow_rate)
|
|
10963
|
+
});
|
|
10964
|
+
} catch (e) {
|
|
10965
|
+
console.warn(
|
|
10966
|
+
`[jupiter-lend] rate model for ${k.mint} not read: ${e.message}`
|
|
10967
|
+
);
|
|
10968
|
+
}
|
|
10969
|
+
}
|
|
10970
|
+
return out;
|
|
10971
|
+
}
|
|
10972
|
+
|
|
10973
|
+
// src/lending/public-data/jupiter-lend/convertPublic.ts
|
|
10974
|
+
var JL_FACTOR_SCALE = 1e3;
|
|
10975
|
+
var JL_BPS = 1e4;
|
|
10976
|
+
var JL_ORACLE_DECIMALS = 15;
|
|
10977
|
+
var JL_ORACLE_SCALE = 10 ** JL_ORACLE_DECIMALS;
|
|
10978
|
+
var FLUID_ORACLE_DECIMALS = 27;
|
|
10979
|
+
var FLUID_VAULT_TYPE_T1 = 1e4;
|
|
10980
|
+
var bpsToPercent = (v) => num(v) / 100;
|
|
10981
|
+
var jlOraclePriceInBorrow = (raw2) => num(raw2) / JL_ORACLE_SCALE;
|
|
10982
|
+
function jlOracleToFluidRaw(raw2, colDecimals, debtDecimals) {
|
|
10983
|
+
if (typeof raw2 !== "string" || !/^\d+$/.test(raw2)) return void 0;
|
|
10984
|
+
const exp = FLUID_ORACLE_DECIMALS - JL_ORACLE_DECIMALS + debtDecimals - colDecimals;
|
|
10985
|
+
const v = BigInt(raw2);
|
|
10986
|
+
return (exp >= 0 ? v * 10n ** BigInt(exp) : v / 10n ** BigInt(-exp)).toString();
|
|
10987
|
+
}
|
|
10988
|
+
function formatRawUnits(raw2, decimals) {
|
|
10989
|
+
let v;
|
|
10990
|
+
try {
|
|
10991
|
+
v = BigInt(raw2 ?? 0);
|
|
10992
|
+
} catch {
|
|
10993
|
+
return "0";
|
|
10994
|
+
}
|
|
10995
|
+
const neg = v < 0n;
|
|
10996
|
+
if (neg) v = -v;
|
|
10997
|
+
const base = 10n ** BigInt(decimals);
|
|
10998
|
+
const whole = v / base;
|
|
10999
|
+
const frac = (v % base).toString().padStart(decimals, "0").replace(/0+$/, "");
|
|
11000
|
+
return `${neg ? "-" : ""}${whole}${frac ? `.${frac}` : ""}`;
|
|
11001
|
+
}
|
|
11002
|
+
function deriveLayerTotals(vaults, earn) {
|
|
11003
|
+
const t = {};
|
|
11004
|
+
const slot = (mint, decimals) => t[mint] ??= { supply: 0n, borrow: 0n, decimals };
|
|
11005
|
+
for (const e of earn)
|
|
11006
|
+
slot(e.assetAddress, e.asset.decimals).supply += BigInt(
|
|
11007
|
+
e.liquiditySupplyData.supply || "0"
|
|
11008
|
+
);
|
|
11009
|
+
for (const v of vaults) {
|
|
11010
|
+
slot(v.supplyToken.address, v.supplyToken.decimals).supply += BigInt(
|
|
11011
|
+
v.liquiditySupplyData.supply || "0"
|
|
11012
|
+
);
|
|
11013
|
+
slot(v.borrowToken.address, v.borrowToken.decimals).borrow += BigInt(
|
|
11014
|
+
v.liquidityBorrowData.borrow || "0"
|
|
11015
|
+
);
|
|
11016
|
+
}
|
|
11017
|
+
return t;
|
|
11018
|
+
}
|
|
11019
|
+
var fmt = (raw2, decimals) => Number(raw2) / 10 ** decimals;
|
|
11020
|
+
var jupiterLendCurrency = (t, listed3) => {
|
|
11021
|
+
const base = listed3 ?? {
|
|
11022
|
+
chainId: SOLANA_CHAIN_ID,
|
|
11023
|
+
address: t.address,
|
|
11024
|
+
symbol: t.uiSymbol ?? t.symbol,
|
|
11025
|
+
name: t.name,
|
|
11026
|
+
decimals: t.decimals
|
|
11027
|
+
};
|
|
11028
|
+
return { ...base, assetGroup: base.assetGroup || `solana-${t.address}` };
|
|
11029
|
+
};
|
|
11030
|
+
function convertJupiterLendVault(market, v, opts = {}) {
|
|
11031
|
+
const lenderKey = jupiterLendVaultKey(market, v.id);
|
|
11032
|
+
const sup = v.supplyToken;
|
|
11033
|
+
const bor = v.borrowToken;
|
|
11034
|
+
const supPrice = num(sup.price);
|
|
11035
|
+
const borPrice = num(bor.price);
|
|
11036
|
+
const ltv = num(v.collateralFactor) / JL_FACTOR_SCALE;
|
|
11037
|
+
const lt = num(v.liquidationThreshold) / JL_FACTOR_SCALE;
|
|
11038
|
+
const penalty = num(v.liquidationPenalty) / JL_BPS;
|
|
11039
|
+
const supAsset = jupiterLendCurrency(sup, opts.tokenList?.[sup.address]);
|
|
11040
|
+
const borAsset = jupiterLendCurrency(bor, opts.tokenList?.[bor.address]);
|
|
11041
|
+
const supSym = supAsset.symbol ?? sup.symbol;
|
|
11042
|
+
const borSym = borAsset.symbol ?? bor.symbol;
|
|
11043
|
+
const label = `${supSym} / ${borSym} \xB7 vault #${v.id}`;
|
|
11044
|
+
const intrinsic = (a) => opts.intrinsicYields?.[a.assetGroup] ?? 0;
|
|
11045
|
+
const layerOf = (mint) => {
|
|
11046
|
+
const l = opts.layer?.[mint];
|
|
11047
|
+
if (!l || l.supply === 0n) return { utilization: 0 };
|
|
11048
|
+
return {
|
|
11049
|
+
utilization: Number(l.borrow * 10000n / l.supply) / 1e4,
|
|
11050
|
+
irmTotalDeposits: fmt(l.supply, l.decimals),
|
|
11051
|
+
irmTotalDebt: fmt(l.borrow, l.decimals)
|
|
11052
|
+
};
|
|
11053
|
+
};
|
|
11054
|
+
const totalSupply = BigInt(v.totalSupply || "0");
|
|
11055
|
+
const withdrawLimit = BigInt(v.withdrawLimit || "0");
|
|
11056
|
+
const lockupRatio = totalSupply > 0n ? Number(withdrawLimit * 10000n / totalSupply) / 1e4 : 0;
|
|
11057
|
+
const supplyDeposits = fmt(v.totalSupply, sup.decimals);
|
|
11058
|
+
const borrowDebt = fmt(v.totalBorrow, bor.decimals);
|
|
11059
|
+
const borrowable = fmt(v.borrowable, bor.decimals);
|
|
11060
|
+
const collateralConfig = {
|
|
11061
|
+
category: 0,
|
|
11062
|
+
label,
|
|
11063
|
+
borrowCollateralFactor: ltv,
|
|
11064
|
+
collateralFactor: lt,
|
|
11065
|
+
borrowFactor: 1,
|
|
11066
|
+
liquidationPenalty: penalty,
|
|
11067
|
+
closeFactor: 1,
|
|
11068
|
+
collateralDisabled: false,
|
|
11069
|
+
debtDisabled: true
|
|
11070
|
+
};
|
|
11071
|
+
const debtConfig = {
|
|
11072
|
+
category: 0,
|
|
11073
|
+
label,
|
|
11074
|
+
borrowCollateralFactor: 0,
|
|
11075
|
+
collateralFactor: 0,
|
|
11076
|
+
borrowFactor: 1,
|
|
11077
|
+
liquidationPenalty: 0,
|
|
11078
|
+
closeFactor: 1,
|
|
11079
|
+
collateralDisabled: true,
|
|
11080
|
+
debtDisabled: false
|
|
11081
|
+
};
|
|
11082
|
+
const common = {
|
|
11083
|
+
totalDebtStable: "0",
|
|
11084
|
+
totalDebtStableUSD: 0,
|
|
11085
|
+
stableBorrowRate: 0,
|
|
11086
|
+
hasStable: false,
|
|
11087
|
+
isActive: true,
|
|
11088
|
+
isFrozen: false,
|
|
11089
|
+
debtCeiling: "0",
|
|
11090
|
+
closeFactor: 1,
|
|
11091
|
+
lockupRatio,
|
|
11092
|
+
rewards: []
|
|
11093
|
+
};
|
|
11094
|
+
const colUid = createMarketUid(SOLANA_CHAIN_ID, lenderKey, sup.address);
|
|
11095
|
+
const debtUid = createMarketUid(SOLANA_CHAIN_ID, lenderKey, bor.address);
|
|
11096
|
+
const collateralLeg = {
|
|
11097
|
+
...common,
|
|
11098
|
+
marketUid: colUid,
|
|
11099
|
+
name: `Collateral ${supSym}`,
|
|
11100
|
+
poolId: sup.address,
|
|
11101
|
+
underlying: sup.address,
|
|
11102
|
+
asset: supAsset,
|
|
11103
|
+
decimals: sup.decimals,
|
|
11104
|
+
totalDeposits: formatRawUnits(v.totalSupply, sup.decimals),
|
|
11105
|
+
totalDebt: "0",
|
|
11106
|
+
totalLiquidity: supplyDeposits,
|
|
11107
|
+
borrowLiquidity: 0,
|
|
11108
|
+
totalDepositsUSD: supplyDeposits * supPrice,
|
|
11109
|
+
totalDebtUSD: 0,
|
|
11110
|
+
totalLiquidityUSD: supplyDeposits * supPrice,
|
|
11111
|
+
borrowLiquidityUSD: 0,
|
|
11112
|
+
...layerOf(sup.address),
|
|
11113
|
+
depositRate: bpsToPercent(v.supplyRate),
|
|
11114
|
+
variableBorrowRate: 0,
|
|
11115
|
+
intrinsicYield: intrinsic(supAsset),
|
|
11116
|
+
liquidationBonus: penalty,
|
|
11117
|
+
config: { "0": collateralConfig },
|
|
11118
|
+
collateralActive: true,
|
|
11119
|
+
borrowingEnabled: false,
|
|
11120
|
+
depositsEnabled: true
|
|
11121
|
+
};
|
|
11122
|
+
const debtLeg = {
|
|
11123
|
+
...common,
|
|
11124
|
+
marketUid: debtUid,
|
|
11125
|
+
name: `Loan ${borSym}`,
|
|
11126
|
+
poolId: bor.address,
|
|
11127
|
+
underlying: bor.address,
|
|
11128
|
+
asset: borAsset,
|
|
11129
|
+
decimals: bor.decimals,
|
|
11130
|
+
totalDeposits: "0",
|
|
11131
|
+
totalDebt: formatRawUnits(v.totalBorrow, bor.decimals),
|
|
11132
|
+
totalLiquidity: borrowable,
|
|
11133
|
+
borrowLiquidity: borrowable,
|
|
11134
|
+
totalDepositsUSD: 0,
|
|
11135
|
+
totalDebtUSD: borrowDebt * borPrice,
|
|
11136
|
+
totalLiquidityUSD: borrowable * borPrice,
|
|
11137
|
+
borrowLiquidityUSD: borrowable * borPrice,
|
|
11138
|
+
...layerOf(bor.address),
|
|
11139
|
+
depositRate: 0,
|
|
11140
|
+
variableBorrowRate: bpsToPercent(v.borrowRate),
|
|
11141
|
+
intrinsicYield: intrinsic(borAsset),
|
|
11142
|
+
liquidationBonus: 0,
|
|
11143
|
+
originationFee: num(v.borrowFee) / 100,
|
|
11144
|
+
config: { "0": debtConfig },
|
|
11145
|
+
collateralActive: false,
|
|
11146
|
+
borrowingEnabled: true,
|
|
11147
|
+
depositsEnabled: false
|
|
11148
|
+
};
|
|
11149
|
+
const vault = {
|
|
11150
|
+
vaultAddress: v.address,
|
|
11151
|
+
vaultId: v.id,
|
|
11152
|
+
collateralAddress: sup.address,
|
|
11153
|
+
loanAddress: bor.address,
|
|
11154
|
+
collateralDecimals: sup.decimals,
|
|
11155
|
+
loanDecimals: bor.decimals,
|
|
11156
|
+
oracle: v.oracle,
|
|
11157
|
+
ltv,
|
|
11158
|
+
liquidationThreshold: lt,
|
|
11159
|
+
liquidationPenalty: penalty,
|
|
11160
|
+
oraclePriceOperate: jlOracleToFluidRaw(
|
|
11161
|
+
v.oraclePriceOperate,
|
|
11162
|
+
sup.decimals,
|
|
11163
|
+
bor.decimals
|
|
11164
|
+
),
|
|
11165
|
+
oraclePriceLiquidate: jlOracleToFluidRaw(
|
|
11166
|
+
v.oraclePriceLiquidate,
|
|
11167
|
+
sup.decimals,
|
|
11168
|
+
bor.decimals
|
|
11169
|
+
),
|
|
11170
|
+
isSmartCol: isJlSmartCol(v.type),
|
|
11171
|
+
isSmartDebt: isJlSmartDebt(v.type),
|
|
11172
|
+
vaultType: v.type <= 1 ? FLUID_VAULT_TYPE_T1 : FLUID_VAULT_TYPE_T1 * Math.min(4, v.type),
|
|
11173
|
+
collateral: {
|
|
11174
|
+
assets: [{ underlying: sup.address, decimals: sup.decimals }],
|
|
11175
|
+
dex: null,
|
|
11176
|
+
perShare: null
|
|
11177
|
+
},
|
|
11178
|
+
loan: {
|
|
11179
|
+
assets: [{ underlying: bor.address, decimals: bor.decimals }],
|
|
11180
|
+
dex: null,
|
|
11181
|
+
perShare: null
|
|
11182
|
+
}
|
|
11183
|
+
};
|
|
11184
|
+
const jupiterLendVault = {
|
|
11185
|
+
market,
|
|
11186
|
+
vaultId: v.id,
|
|
11187
|
+
address: v.address,
|
|
11188
|
+
type: v.type,
|
|
11189
|
+
supplyToken: sup.address,
|
|
11190
|
+
borrowToken: bor.address,
|
|
11191
|
+
supplyDecimals: sup.decimals,
|
|
11192
|
+
borrowDecimals: bor.decimals,
|
|
11193
|
+
collateralFactor: num(v.collateralFactor),
|
|
11194
|
+
liquidationThreshold: num(v.liquidationThreshold),
|
|
11195
|
+
liquidationMaxLimit: num(v.liquidationMaxLimit),
|
|
11196
|
+
withdrawalGap: num(v.withdrawalGap),
|
|
11197
|
+
liquidationPenalty: num(v.liquidationPenalty),
|
|
11198
|
+
borrowFee: num(v.borrowFee),
|
|
11199
|
+
supplyRateMagnifier: num(v.supplyRateMagnifier),
|
|
11200
|
+
borrowRateMagnifier: num(v.borrowRateMagnifier),
|
|
11201
|
+
supplyRateLiquidity: num(v.supplyRateLiquidity),
|
|
11202
|
+
borrowRateLiquidity: num(v.borrowRateLiquidity),
|
|
11203
|
+
minimumBorrowing: v.minimumBorrowing,
|
|
11204
|
+
totalPositions: v.totalPositions,
|
|
11205
|
+
borrowLimit: v.borrowLimit,
|
|
11206
|
+
borrowable: v.borrowable,
|
|
11207
|
+
withdrawLimit: v.withdrawLimit,
|
|
11208
|
+
withdrawable: v.withdrawable,
|
|
11209
|
+
oracle: v.oracle,
|
|
11210
|
+
oraclePrice: v.oraclePrice,
|
|
11211
|
+
oraclePriceOperate: v.oraclePriceOperate,
|
|
11212
|
+
oraclePriceLiquidate: v.oraclePriceLiquidate,
|
|
11213
|
+
oracleSources: v.oracleSources,
|
|
11214
|
+
oracleTimestamp: v.oracleTimestamp,
|
|
11215
|
+
liquiditySupplyData: v.liquiditySupplyData,
|
|
11216
|
+
liquidityBorrowData: v.liquidityBorrowData,
|
|
11217
|
+
topTick: v.topTick,
|
|
11218
|
+
metadata: v.metadata
|
|
11219
|
+
};
|
|
11220
|
+
return {
|
|
11221
|
+
lenderKey,
|
|
11222
|
+
chainId: SOLANA_CHAIN_ID,
|
|
11223
|
+
data: { [colUid]: collateralLeg, [debtUid]: debtLeg },
|
|
11224
|
+
params: { vault, jupiterLendVault }
|
|
11225
|
+
};
|
|
9707
11226
|
}
|
|
9708
11227
|
|
|
9709
11228
|
// src/lending/public-data/jupiter-lend/fetchPublic.ts
|
|
@@ -9717,8 +11236,37 @@ async function fetchJupiterLendPublic(opts = {}) {
|
|
|
9717
11236
|
api.vaults(market),
|
|
9718
11237
|
api.earnTokens(market)
|
|
9719
11238
|
]);
|
|
9720
|
-
const layer = deriveLayerTotals(vaults, earn);
|
|
9721
11239
|
const only = opts.vaultIds?.[market];
|
|
11240
|
+
let chain = [];
|
|
11241
|
+
if (opts.rpc && opts.enumerateOnchain !== false) {
|
|
11242
|
+
try {
|
|
11243
|
+
const next = await readJlNextVaultId(opts.rpc, market);
|
|
11244
|
+
const listed3 = new Set(vaults.map((v) => v.id));
|
|
11245
|
+
const ids = [];
|
|
11246
|
+
for (let id = 1; next && id < next; id++)
|
|
11247
|
+
if (!listed3.has(id) && (!only || only.includes(id))) ids.push(id);
|
|
11248
|
+
if (ids.length) {
|
|
11249
|
+
const tokens = {};
|
|
11250
|
+
for (const v of vaults) {
|
|
11251
|
+
tokens[v.supplyToken.address] ??= v.supplyToken;
|
|
11252
|
+
tokens[v.borrowToken.address] ??= v.borrowToken;
|
|
11253
|
+
}
|
|
11254
|
+
for (const e of earn) tokens[e.assetAddress] ??= e.asset;
|
|
11255
|
+
chain = await readJupiterLendVaultsOnchain(opts.rpc, market, ids, {
|
|
11256
|
+
tokens,
|
|
11257
|
+
tokenList: opts.tokenList
|
|
11258
|
+
});
|
|
11259
|
+
}
|
|
11260
|
+
} catch (e) {
|
|
11261
|
+
console.warn(
|
|
11262
|
+
`[jupiter-lend] on-chain enumeration of ${market} failed, serving the API's vaults only: ${e.message}`
|
|
11263
|
+
);
|
|
11264
|
+
}
|
|
11265
|
+
}
|
|
11266
|
+
const layer = deriveLayerTotals(
|
|
11267
|
+
[...vaults, ...chain.map((c) => c.vault)],
|
|
11268
|
+
earn
|
|
11269
|
+
);
|
|
9722
11270
|
let flash;
|
|
9723
11271
|
if (opts.rpc) {
|
|
9724
11272
|
try {
|
|
@@ -9738,13 +11286,64 @@ async function fetchJupiterLendPublic(opts = {}) {
|
|
|
9738
11286
|
);
|
|
9739
11287
|
}
|
|
9740
11288
|
}
|
|
9741
|
-
|
|
11289
|
+
const fromChain = new Map(chain.map((c) => [c.vault.id, c]));
|
|
11290
|
+
let irms = /* @__PURE__ */ new Map();
|
|
11291
|
+
if (opts.rpc) {
|
|
11292
|
+
const mints = /* @__PURE__ */ new Set();
|
|
11293
|
+
for (const v of [...vaults, ...chain.map((c) => c.vault)]) {
|
|
11294
|
+
const cv = fromChain.get(v.id);
|
|
11295
|
+
if (!cv?.smartCol) mints.add(v.supplyToken.address);
|
|
11296
|
+
if (!cv?.smartDebt) mints.add(v.borrowToken.address);
|
|
11297
|
+
}
|
|
11298
|
+
try {
|
|
11299
|
+
irms = await readJlLayerIrms(opts.rpc, market, [...mints]);
|
|
11300
|
+
} catch (e) {
|
|
11301
|
+
console.warn(
|
|
11302
|
+
`[jupiter-lend] layer rate models for ${market} not read: ${e.message}`
|
|
11303
|
+
);
|
|
11304
|
+
}
|
|
11305
|
+
}
|
|
11306
|
+
for (const v of [...vaults, ...chain.map((c) => c.vault)]) {
|
|
9742
11307
|
if (only && !only.includes(v.id)) continue;
|
|
9743
11308
|
const conv = convertJupiterLendVault(market, v, {
|
|
9744
11309
|
tokenList: opts.tokenList,
|
|
9745
11310
|
intrinsicYields: opts.intrinsicYields,
|
|
9746
11311
|
layer
|
|
9747
11312
|
});
|
|
11313
|
+
const cv = fromChain.get(v.id);
|
|
11314
|
+
const mags = {
|
|
11315
|
+
supplyMagnifier: Number(v.supplyRateMagnifier) || 0,
|
|
11316
|
+
borrowMagnifier: Number(v.borrowRateMagnifier) || 0
|
|
11317
|
+
};
|
|
11318
|
+
for (const row of Object.values(conv.data)) {
|
|
11319
|
+
const smart = row.underlying === v.supplyToken.address ? cv?.smartCol : cv?.smartDebt;
|
|
11320
|
+
const irm = smart ? void 0 : irms.get(row.underlying);
|
|
11321
|
+
if (irm) row.jupiterLend = { irm: { ...irm, ...mags } };
|
|
11322
|
+
}
|
|
11323
|
+
const meta = conv.params.jupiterLendVault;
|
|
11324
|
+
meta.source = cv ? "chain" : "api";
|
|
11325
|
+
if (cv) {
|
|
11326
|
+
meta.slot = cv.slot;
|
|
11327
|
+
if (cv.smartCol || cv.smartDebt)
|
|
11328
|
+
meta.smart = {
|
|
11329
|
+
...cv.smartCol ? {
|
|
11330
|
+
col: {
|
|
11331
|
+
dex: v.supplyToken.address,
|
|
11332
|
+
token0: cv.supplyDex?.token0,
|
|
11333
|
+
token1: cv.supplyDex?.token1
|
|
11334
|
+
}
|
|
11335
|
+
} : {},
|
|
11336
|
+
...cv.smartDebt ? {
|
|
11337
|
+
debt: {
|
|
11338
|
+
dex: v.borrowToken.address,
|
|
11339
|
+
token0: cv.borrowDex?.token0,
|
|
11340
|
+
token1: cv.borrowDex?.token1
|
|
11341
|
+
}
|
|
11342
|
+
} : {}
|
|
11343
|
+
};
|
|
11344
|
+
const unpriced = [v.supplyToken, v.borrowToken].filter((t) => !(Number(t.price) > 0)).map((t) => t.address);
|
|
11345
|
+
if (unpriced.length) meta.unpriced = unpriced;
|
|
11346
|
+
}
|
|
9748
11347
|
if (flash)
|
|
9749
11348
|
conv.params.jupiterLendVault.flashloan = {
|
|
9750
11349
|
feeBps: flash.feeBps,
|
|
@@ -9772,7 +11371,7 @@ var SAVE_API_BASE = "https://api.save.finance";
|
|
|
9772
11371
|
var SAVE_WAD = 10n ** 18n;
|
|
9773
11372
|
var SAVE_U64_MAX = "18446744073709551615";
|
|
9774
11373
|
var SAVE_SLOTS_PER_YEAR = 63072e3;
|
|
9775
|
-
var SAVE_DEFAULT_AVG_SLOT_SECONDS = 0.
|
|
11374
|
+
var SAVE_DEFAULT_AVG_SLOT_SECONDS = 0.2665;
|
|
9776
11375
|
var SAVE_LIQUIDATION_CLOSE_FACTOR = 0.2;
|
|
9777
11376
|
var SAVE_MAX_LIQUIDATABLE_VALUE_USD = 5e5;
|
|
9778
11377
|
var SAVE_FULL_LIQUIDATION_VALUE_USD = 1;
|
|
@@ -10208,7 +11807,7 @@ var LS_NO_ACCOUNT = "11111111111111111111111111111111";
|
|
|
10208
11807
|
var LS_U64_MAX = "18446744073709551615";
|
|
10209
11808
|
var isUncapped = (v) => v === void 0 || v === null || String(v) === LS_U64_MAX;
|
|
10210
11809
|
var capOrUndefined = (v) => isUncapped(v) ? void 0 : String(v);
|
|
10211
|
-
var
|
|
11810
|
+
var SECONDS_PER_YEAR2 = 31536e3;
|
|
10212
11811
|
var LS_TENORS = [
|
|
10213
11812
|
{ id: "1d", duration: { duration: 1, durationType: 0 }, days: 1 },
|
|
10214
11813
|
{ id: "1w", duration: { duration: 1, durationType: 1 }, days: 7 },
|
|
@@ -10364,6 +11963,8 @@ async function buildLoopscaleRoster(vaults, loops, opts = {}) {
|
|
|
10364
11963
|
strategy: s.address,
|
|
10365
11964
|
name: v.vaultMetadata?.name ?? v.vault.address,
|
|
10366
11965
|
curator: v.vaultMetadata?.managerName ?? "",
|
|
11966
|
+
manager: v.vault.manager,
|
|
11967
|
+
managerImage: v.vaultMetadata?.managerImage ?? void 0,
|
|
10367
11968
|
interestFee: Number(s.interestFee),
|
|
10368
11969
|
originationFee: Number(s.originationFee),
|
|
10369
11970
|
originationsEnabled: s.originationsEnabled,
|
|
@@ -10413,20 +12014,20 @@ async function buildLoopscaleRoster(vaults, loops, opts = {}) {
|
|
|
10413
12014
|
const unresolved = [];
|
|
10414
12015
|
if (toProbe.length && opts.rpc) {
|
|
10415
12016
|
const mints = await getMints(opts.rpc, toProbe);
|
|
10416
|
-
const
|
|
10417
|
-
mints.forEach((m, i) => m &&
|
|
12017
|
+
const dec2 = /* @__PURE__ */ new Map();
|
|
12018
|
+
mints.forEach((m, i) => m && dec2.set(toProbe[i], m.decimals));
|
|
10418
12019
|
for (const pair of byKey.values()) {
|
|
10419
12020
|
const c = pair.collateralIdentifier;
|
|
10420
|
-
if (pair.assetType === -1 &&
|
|
12021
|
+
if (pair.assetType === -1 && dec2.has(c)) {
|
|
10421
12022
|
pair.assetType = 0;
|
|
10422
12023
|
pair.collateralMint = c;
|
|
10423
12024
|
}
|
|
10424
12025
|
if (pair.collateralMint && pair.collateralDecimals === void 0)
|
|
10425
|
-
pair.collateralDecimals =
|
|
12026
|
+
pair.collateralDecimals = dec2.get(pair.collateralMint);
|
|
10426
12027
|
if (pair.principalDecimals === void 0)
|
|
10427
|
-
pair.principalDecimals =
|
|
12028
|
+
pair.principalDecimals = dec2.get(pair.principalMint);
|
|
10428
12029
|
}
|
|
10429
|
-
for (const c of unknown) if (!
|
|
12030
|
+
for (const c of unknown) if (!dec2.has(c)) unresolved.push(c);
|
|
10430
12031
|
} else unresolved.push(...unknown);
|
|
10431
12032
|
const pairs = [...byKey.values()].filter(
|
|
10432
12033
|
(p) => (p.assetType === 0 || opts.includeUnresolvedCollateral) && (want ? want.has(key2(p.principalMint, p.collateralIdentifier)) : true)
|
|
@@ -10717,7 +12318,12 @@ function convertLoopscalePair(pair, opts) {
|
|
|
10717
12318
|
termId: t.termId,
|
|
10718
12319
|
durationDays: t.durationDays,
|
|
10719
12320
|
durationSecs: t.durationDays * 86400,
|
|
10720
|
-
apr: t.apr
|
|
12321
|
+
apr: t.apr,
|
|
12322
|
+
ladder: t.ladder.map((l) => ({
|
|
12323
|
+
apr: l.apr,
|
|
12324
|
+
assets: fmt2(l.sum, pDec),
|
|
12325
|
+
fill: "single"
|
|
12326
|
+
}))
|
|
10721
12327
|
}));
|
|
10722
12328
|
const common = {
|
|
10723
12329
|
totalDebtStable: "0",
|
|
@@ -10861,9 +12467,9 @@ import { createSvmRpc } from "@1delta/svm-kit";
|
|
|
10861
12467
|
|
|
10862
12468
|
// src/lending/public-data/loopscale/accounts.ts
|
|
10863
12469
|
import {
|
|
10864
|
-
decodeIdlAccount as
|
|
12470
|
+
decodeIdlAccount as decodeIdlAccount4,
|
|
10865
12471
|
encodeBase58 as encodeBase583,
|
|
10866
|
-
fromBase64 as
|
|
12472
|
+
fromBase64 as fromBase644
|
|
10867
12473
|
} from "@1delta/svm-kit";
|
|
10868
12474
|
|
|
10869
12475
|
// src/lending/public-data/loopscale/idl/loopscale.json
|
|
@@ -17847,7 +19453,7 @@ var podDecimalToNumber = (p) => Number(podToBigInt(p)) / 1e18;
|
|
|
17847
19453
|
var podBool = (p) => bytesOf(p)[0] !== 0;
|
|
17848
19454
|
var raw = (v) => v;
|
|
17849
19455
|
function decodeLoopscaleLoan(data) {
|
|
17850
|
-
const r = raw(
|
|
19456
|
+
const r = raw(decodeIdlAccount4(LOOPSCALE_IDL, "Loan", data));
|
|
17851
19457
|
const zero = encodeBase583(new Uint8Array(32));
|
|
17852
19458
|
const ledgers = r.ledgers.map(
|
|
17853
19459
|
(l) => ({
|
|
@@ -17892,7 +19498,7 @@ function decodeLoopscaleLoan(data) {
|
|
|
17892
19498
|
};
|
|
17893
19499
|
}
|
|
17894
19500
|
function decodeLoopscaleStrategy(data) {
|
|
17895
|
-
const r = raw(
|
|
19501
|
+
const r = raw(decodeIdlAccount4(LOOPSCALE_IDL, "Strategy", data));
|
|
17896
19502
|
return {
|
|
17897
19503
|
version: r.version,
|
|
17898
19504
|
nonce: r.nonce,
|
|
@@ -17929,12 +19535,12 @@ async function readLoopscaleLoans(rpc, loanAddresses) {
|
|
|
17929
19535
|
return {
|
|
17930
19536
|
slot,
|
|
17931
19537
|
loans: accounts.map(
|
|
17932
|
-
(a) => a && a.owner === LOOPSCALE_PROGRAM_ID ? decodeLoopscaleLoan(
|
|
19538
|
+
(a) => a && a.owner === LOOPSCALE_PROGRAM_ID ? decodeLoopscaleLoan(fromBase644(a.data[0])) : null
|
|
17933
19539
|
)
|
|
17934
19540
|
};
|
|
17935
19541
|
}
|
|
17936
19542
|
function decodeLoopscaleMarketInformation(data) {
|
|
17937
|
-
const r = raw(
|
|
19543
|
+
const r = raw(decodeIdlAccount4(LOOPSCALE_IDL, "MarketInformation", data));
|
|
17938
19544
|
const zero = encodeBase583(new Uint8Array(32));
|
|
17939
19545
|
const caps = (c) => ({
|
|
17940
19546
|
max1hr: podToBigInt(c.max_1hr).toString(),
|
|
@@ -17984,7 +19590,7 @@ async function readLoopscaleMarketInformation(rpc, addresses) {
|
|
|
17984
19590
|
try {
|
|
17985
19591
|
out.set(
|
|
17986
19592
|
unique[i],
|
|
17987
|
-
decodeLoopscaleMarketInformation(
|
|
19593
|
+
decodeLoopscaleMarketInformation(fromBase644(a.data[0]))
|
|
17988
19594
|
);
|
|
17989
19595
|
} catch (e) {
|
|
17990
19596
|
console.warn(
|
|
@@ -18295,18 +19901,18 @@ function tenorsToQuote(pair, all) {
|
|
|
18295
19901
|
return out;
|
|
18296
19902
|
}
|
|
18297
19903
|
function deriveLoopscalePrices(vaults, loops, pairs, tokenList, loanBook) {
|
|
18298
|
-
const
|
|
18299
|
-
for (const [m, t] of Object.entries(tokenList ?? {}))
|
|
19904
|
+
const dec2 = /* @__PURE__ */ new Map();
|
|
19905
|
+
for (const [m, t] of Object.entries(tokenList ?? {})) dec2.set(m, t.decimals);
|
|
18300
19906
|
for (const p of pairs) {
|
|
18301
19907
|
if (p.principalDecimals !== void 0)
|
|
18302
|
-
|
|
19908
|
+
dec2.set(p.principalMint, p.principalDecimals);
|
|
18303
19909
|
if (p.collateralMint && p.collateralDecimals !== void 0)
|
|
18304
|
-
|
|
19910
|
+
dec2.set(p.collateralMint, p.collateralDecimals);
|
|
18305
19911
|
}
|
|
18306
19912
|
const out = {};
|
|
18307
19913
|
const best = /* @__PURE__ */ new Map();
|
|
18308
19914
|
const offer = (mint, usd, raw2) => {
|
|
18309
|
-
const d2 =
|
|
19915
|
+
const d2 = dec2.get(mint);
|
|
18310
19916
|
if (d2 === void 0 || !usd || !(raw2 > 0)) return;
|
|
18311
19917
|
if ((best.get(mint) ?? 0) < usd) {
|
|
18312
19918
|
best.set(mint, usd);
|
|
@@ -18337,7 +19943,7 @@ function deriveLoopscalePrices(vaults, loops, pairs, tokenList, loanBook) {
|
|
|
18337
19943
|
}
|
|
18338
19944
|
|
|
18339
19945
|
// src/prices/pythPush.ts
|
|
18340
|
-
import { fromBase64 as
|
|
19946
|
+
import { fromBase64 as fromBase645 } from "@1delta/svm-kit";
|
|
18341
19947
|
var PYTH_RECEIVER_PROGRAM = "rec2HHDDnjLfj4kE7VyEtFA1HPGQLK33259532cRyHp";
|
|
18342
19948
|
var PYTH_PRICE_UPDATE_V2_DISCRIMINATOR = [
|
|
18343
19949
|
34,
|
|
@@ -18350,7 +19956,7 @@ var PYTH_PRICE_UPDATE_V2_DISCRIMINATOR = [
|
|
|
18350
19956
|
205
|
|
18351
19957
|
];
|
|
18352
19958
|
function decodePythPriceUpdate(data) {
|
|
18353
|
-
const b = typeof data === "string" ?
|
|
19959
|
+
const b = typeof data === "string" ? fromBase645(data) : data;
|
|
18354
19960
|
for (let i = 0; i < 8; i++)
|
|
18355
19961
|
if (b[i] !== PYTH_PRICE_UPDATE_V2_DISCRIMINATOR[i])
|
|
18356
19962
|
throw new Error("pyth: account is not a PriceUpdateV2");
|
|
@@ -18485,10 +20091,10 @@ function createP0Api(opts = {}) {
|
|
|
18485
20091
|
|
|
18486
20092
|
// src/lending/public-data/project0/accounts.ts
|
|
18487
20093
|
import {
|
|
18488
|
-
decodeBase58 as
|
|
18489
|
-
decodeIdlAccount as
|
|
18490
|
-
findProgramAddress as
|
|
18491
|
-
fromBase64 as
|
|
20094
|
+
decodeBase58 as decodeBase584,
|
|
20095
|
+
decodeIdlAccount as decodeIdlAccount5,
|
|
20096
|
+
findProgramAddress as findProgramAddress4,
|
|
20097
|
+
fromBase64 as fromBase646
|
|
18492
20098
|
} from "@1delta/svm-kit";
|
|
18493
20099
|
|
|
18494
20100
|
// src/lending/public-data/project0/idl/marginfi.json
|
|
@@ -33353,34 +34959,34 @@ function decimalStringToI80F48(s) {
|
|
|
33353
34959
|
for (let i = 0; i < 16; i++) out[i] = Number(u >> BigInt(8 * i) & 0xffn);
|
|
33354
34960
|
return out;
|
|
33355
34961
|
}
|
|
33356
|
-
var
|
|
33357
|
-
var
|
|
33358
|
-
const b =
|
|
34962
|
+
var utf84 = (s) => new TextEncoder().encode(s);
|
|
34963
|
+
var pk4 = (address) => {
|
|
34964
|
+
const b = decodeBase584(address);
|
|
33359
34965
|
if (!b || b.length !== 32)
|
|
33360
34966
|
throw new Error(`project0: not a 32-byte pubkey: ${address}`);
|
|
33361
34967
|
return b;
|
|
33362
34968
|
};
|
|
33363
|
-
var
|
|
34969
|
+
var u16le2 = (n) => {
|
|
33364
34970
|
if (!Number.isInteger(n) || n < 0 || n > 65535)
|
|
33365
34971
|
throw new Error(`project0: u16 out of range: ${n}`);
|
|
33366
34972
|
return new Uint8Array([n & 255, n >> 8]);
|
|
33367
34973
|
};
|
|
33368
|
-
var p0LiquidityVaultAuthority = async (bank, programId = P0_PROGRAM_ID) => (await
|
|
33369
|
-
[
|
|
34974
|
+
var p0LiquidityVaultAuthority = async (bank, programId = P0_PROGRAM_ID) => (await findProgramAddress4(
|
|
34975
|
+
[utf84(P0_SEEDS.liquidityVaultAuthority), pk4(bank)],
|
|
33370
34976
|
programId
|
|
33371
34977
|
)).address;
|
|
33372
|
-
var p0LiquidityVault = async (bank, programId = P0_PROGRAM_ID) => (await
|
|
33373
|
-
[
|
|
34978
|
+
var p0LiquidityVault = async (bank, programId = P0_PROGRAM_ID) => (await findProgramAddress4(
|
|
34979
|
+
[utf84(P0_SEEDS.liquidityVault), pk4(bank)],
|
|
33374
34980
|
programId
|
|
33375
34981
|
)).address;
|
|
33376
|
-
var p0FeeState = async (programId = P0_PROGRAM_ID) => (await
|
|
33377
|
-
var p0MarginfiAccountPda = async (authority, accountIndex = 0, opts = {}) => (await
|
|
34982
|
+
var p0FeeState = async (programId = P0_PROGRAM_ID) => (await findProgramAddress4([utf84(P0_SEEDS.feeState)], programId)).address;
|
|
34983
|
+
var p0MarginfiAccountPda = async (authority, accountIndex = 0, opts = {}) => (await findProgramAddress4(
|
|
33378
34984
|
[
|
|
33379
|
-
|
|
33380
|
-
|
|
33381
|
-
|
|
33382
|
-
|
|
33383
|
-
|
|
34985
|
+
utf84(P0_SEEDS.marginfiAccount),
|
|
34986
|
+
pk4(opts.group ?? P0_MAIN_GROUP),
|
|
34987
|
+
pk4(authority),
|
|
34988
|
+
u16le2(accountIndex),
|
|
34989
|
+
u16le2(opts.thirdPartyId ?? 0)
|
|
33384
34990
|
],
|
|
33385
34991
|
opts.programId ?? P0_PROGRAM_ID
|
|
33386
34992
|
)).address;
|
|
@@ -33464,8 +35070,8 @@ var bankConfig = (c) => ({
|
|
|
33464
35070
|
cbEmaAlphaBps: c.cb_ema_alpha_bps
|
|
33465
35071
|
});
|
|
33466
35072
|
function decodeP0Bank(address, data, tokenSymbol) {
|
|
33467
|
-
const
|
|
33468
|
-
const r =
|
|
35073
|
+
const bytes2 = typeof data === "string" ? fromBase646(data) : data;
|
|
35074
|
+
const r = decodeIdlAccount5(P0_IDL, "Bank", bytes2);
|
|
33469
35075
|
const entries = r.emode.emode_config.entries.filter((e) => e.collateral_bank_emode_tag !== 0).map((e) => ({
|
|
33470
35076
|
collateralBankEmodeTag: e.collateral_bank_emode_tag,
|
|
33471
35077
|
flags: e.flags,
|
|
@@ -33690,8 +35296,8 @@ var u32ToBasis = (v) => v / 4294967295 * 100;
|
|
|
33690
35296
|
var P0_PAUSE_DURATION_SECONDS = 6 * 60 * 60;
|
|
33691
35297
|
var p0GroupPausedAt = (g, now) => !!g?.panic.pausedFlag && (now < g.panic.pauseStartTimestamp || now - g.panic.pauseStartTimestamp < P0_PAUSE_DURATION_SECONDS);
|
|
33692
35298
|
function decodeP0Group(address, data) {
|
|
33693
|
-
const
|
|
33694
|
-
const r =
|
|
35299
|
+
const bytes2 = typeof data === "string" ? fromBase646(data) : data;
|
|
35300
|
+
const r = decodeIdlAccount5(P0_IDL, "MarginfiGroup", bytes2);
|
|
33695
35301
|
return {
|
|
33696
35302
|
address,
|
|
33697
35303
|
admin: r.admin,
|
|
@@ -33724,11 +35330,11 @@ function decodeP0Group(address, data) {
|
|
|
33724
35330
|
};
|
|
33725
35331
|
}
|
|
33726
35332
|
function decodeP0MarginfiAccount(address, data) {
|
|
33727
|
-
const
|
|
33728
|
-
const r =
|
|
35333
|
+
const bytes2 = typeof data === "string" ? fromBase646(data) : data;
|
|
35334
|
+
const r = decodeIdlAccount5(
|
|
33729
35335
|
P0_IDL,
|
|
33730
35336
|
"MarginfiAccount",
|
|
33731
|
-
|
|
35337
|
+
bytes2
|
|
33732
35338
|
);
|
|
33733
35339
|
const h = r.health_cache;
|
|
33734
35340
|
return {
|
|
@@ -33780,10 +35386,10 @@ var P0_GROUP_SIZE = 9256;
|
|
|
33780
35386
|
var P0_ACCOUNT_GROUP_OFFSET = 8;
|
|
33781
35387
|
var P0_ACCOUNT_AUTHORITY_OFFSET = 8 + 32;
|
|
33782
35388
|
var P0_BANK_GROUP_OFFSET = 8 + 32 + 1;
|
|
33783
|
-
var p0BankMetadataPda = async (bank, programId = P0_PROGRAM_ID) => (await
|
|
35389
|
+
var p0BankMetadataPda = async (bank, programId = P0_PROGRAM_ID) => (await findProgramAddress4([utf84("metadata"), pk4(bank)], programId)).address;
|
|
33784
35390
|
function decodeP0BankMetadata(data) {
|
|
33785
|
-
const
|
|
33786
|
-
const r =
|
|
35391
|
+
const bytes2 = typeof data === "string" ? fromBase646(data) : data;
|
|
35392
|
+
const r = decodeIdlAccount5(P0_IDL, "BankMetadata", bytes2);
|
|
33787
35393
|
const td = new TextDecoder();
|
|
33788
35394
|
const ticker = td.decode(r.ticker.subarray(0, r.end_ticker_byte)).trim();
|
|
33789
35395
|
const description = td.decode(r.description.subarray(0, r.end_description_byte)).trim();
|
|
@@ -33933,7 +35539,7 @@ function p0CurveKnots(c) {
|
|
|
33933
35539
|
}
|
|
33934
35540
|
|
|
33935
35541
|
// src/vaults/lst/stakePool.ts
|
|
33936
|
-
import { BorshReader, encodeBase58 as encodeBase584, fromBase64 as
|
|
35542
|
+
import { BorshReader, encodeBase58 as encodeBase584, fromBase64 as fromBase647 } from "@1delta/svm-kit";
|
|
33937
35543
|
var SPL_STAKE_POOL_PROGRAM = "SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy";
|
|
33938
35544
|
var OFFSET_RESERVE_STAKE = 130;
|
|
33939
35545
|
var OFFSET_POOL_MINT = 162;
|
|
@@ -34009,7 +35615,7 @@ async function readStakePools(rpc, stakePools, opts = {}) {
|
|
|
34009
35615
|
const pools = accounts.map((a) => {
|
|
34010
35616
|
if (!a || a.owner !== program) return null;
|
|
34011
35617
|
try {
|
|
34012
|
-
return decodeStakePool(
|
|
35618
|
+
return decodeStakePool(fromBase647(a.data[0]));
|
|
34013
35619
|
} catch {
|
|
34014
35620
|
return null;
|
|
34015
35621
|
}
|
|
@@ -34061,7 +35667,127 @@ async function readEpochClock(rpc) {
|
|
|
34061
35667
|
}
|
|
34062
35668
|
|
|
34063
35669
|
// src/lending/public-data/project0/prices.ts
|
|
34064
|
-
import { fromBase64 as
|
|
35670
|
+
import { fromBase64 as fromBase649 } from "@1delta/svm-kit";
|
|
35671
|
+
|
|
35672
|
+
// src/prices/oracleAccounts.ts
|
|
35673
|
+
import { fromBase64 as fromBase648 } from "@1delta/svm-kit";
|
|
35674
|
+
var PYTH_PRICE_UPDATE_OWNERS = /* @__PURE__ */ new Set([
|
|
35675
|
+
"rec5EKMGg6MxZYaMdyBfgwp4d5rB9T1VQH5pJv5LtFJ",
|
|
35676
|
+
"rec2HHDDnjLfj4kE7VyEtFA1HPGQLK33259532cRyHp"
|
|
35677
|
+
]);
|
|
35678
|
+
var PYTH_LEGACY_PROGRAM = "FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epH";
|
|
35679
|
+
var SWITCHBOARD_ON_DEMAND_PROGRAM = "SBondMDrcV3K4kxZR1HNVT7osZxAHVHgYXL5Ze1oMUv";
|
|
35680
|
+
var SWITCHBOARD_V2_PROGRAM = "SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f";
|
|
35681
|
+
var SCOPE_PROGRAM = "HFn8GnPADiny6XqUoWE8uRPPxb29ikn4yTuPa9MF2fWJ";
|
|
35682
|
+
var MARINADE_PROGRAM = "MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD";
|
|
35683
|
+
var bytes = (data) => typeof data === "string" ? fromBase648(data) : data;
|
|
35684
|
+
var view = (b) => new DataView(b.buffer, b.byteOffset, b.byteLength);
|
|
35685
|
+
var i128 = (b, o) => {
|
|
35686
|
+
const dv = view(b);
|
|
35687
|
+
const lo = dv.getBigUint64(o, true);
|
|
35688
|
+
const hi = dv.getBigInt64(o + 8, true);
|
|
35689
|
+
return (hi << 64n) + lo;
|
|
35690
|
+
};
|
|
35691
|
+
var disc = (b, d2) => d2.every((x, i) => b[i] === x);
|
|
35692
|
+
var SB_PULL_FEED_DISCRIMINATOR = [196, 27, 108, 196, 10, 215, 219, 40];
|
|
35693
|
+
var SB_V2_AGGREGATOR_DISCRIMINATOR = [
|
|
35694
|
+
217,
|
|
35695
|
+
230,
|
|
35696
|
+
65,
|
|
35697
|
+
101,
|
|
35698
|
+
201,
|
|
35699
|
+
162,
|
|
35700
|
+
27,
|
|
35701
|
+
125
|
|
35702
|
+
];
|
|
35703
|
+
var PYTH_LEGACY_MAGIC = 2712847316;
|
|
35704
|
+
function decodeSwitchboardPullFeed(data) {
|
|
35705
|
+
const b = bytes(data);
|
|
35706
|
+
if (!disc(b, SB_PULL_FEED_DISCRIMINATOR) || b.length < 2392)
|
|
35707
|
+
throw new Error("switchboard: account is not a PullFeedAccountData");
|
|
35708
|
+
const dv = view(b);
|
|
35709
|
+
const value = i128(b, 2264);
|
|
35710
|
+
return {
|
|
35711
|
+
kind: "switchboard-on-demand",
|
|
35712
|
+
price: Number(value) / 1e18,
|
|
35713
|
+
updatedAt: Number(dv.getBigInt64(2216, true)),
|
|
35714
|
+
slot: Number(dv.getBigUint64(2368, true)),
|
|
35715
|
+
name: new TextDecoder().decode(b.subarray(2180, 2212)).replace(/\0+$/, "")
|
|
35716
|
+
};
|
|
35717
|
+
}
|
|
35718
|
+
function decodeSwitchboardV2Aggregator(data) {
|
|
35719
|
+
const b = bytes(data);
|
|
35720
|
+
if (!disc(b, SB_V2_AGGREGATOR_DISCRIMINATOR) || b.length < 386)
|
|
35721
|
+
throw new Error("switchboard: account is not an AggregatorAccountData");
|
|
35722
|
+
const dv = view(b);
|
|
35723
|
+
const mantissa = i128(b, 366);
|
|
35724
|
+
const scale = dv.getUint32(382, true);
|
|
35725
|
+
return {
|
|
35726
|
+
kind: "switchboard-v2",
|
|
35727
|
+
price: Number(mantissa) / 10 ** scale,
|
|
35728
|
+
updatedAt: Number(dv.getBigInt64(358, true)),
|
|
35729
|
+
slot: Number(dv.getBigUint64(350, true)),
|
|
35730
|
+
name: new TextDecoder().decode(b.subarray(8, 40)).replace(/\0+$/, "")
|
|
35731
|
+
};
|
|
35732
|
+
}
|
|
35733
|
+
function decodePythLegacyPrice(data) {
|
|
35734
|
+
const b = bytes(data);
|
|
35735
|
+
const dv = view(b);
|
|
35736
|
+
if (b.length < 240 || dv.getUint32(0, true) !== PYTH_LEGACY_MAGIC)
|
|
35737
|
+
throw new Error("pyth: account is not a legacy price account");
|
|
35738
|
+
if (dv.getUint32(8, true) !== 3)
|
|
35739
|
+
throw new Error("pyth: legacy account is not a PRICE account");
|
|
35740
|
+
const expo = dv.getInt32(20, true);
|
|
35741
|
+
return {
|
|
35742
|
+
kind: "pyth-legacy",
|
|
35743
|
+
price: Number(dv.getBigInt64(208, true)) * 10 ** expo,
|
|
35744
|
+
updatedAt: Number(dv.getBigInt64(96, true)),
|
|
35745
|
+
slot: Number(dv.getBigUint64(232, true)),
|
|
35746
|
+
status: dv.getUint32(224, true)
|
|
35747
|
+
};
|
|
35748
|
+
}
|
|
35749
|
+
var SCOPE_PRICES_LEN = 512;
|
|
35750
|
+
function decodeScopePrice(data, index) {
|
|
35751
|
+
const b = bytes(data);
|
|
35752
|
+
if (!Number.isInteger(index) || index < 0 || index >= SCOPE_PRICES_LEN)
|
|
35753
|
+
throw new Error(`scope: entry index ${index} out of range`);
|
|
35754
|
+
const o = 8 + 32 + index * 56;
|
|
35755
|
+
if (b.length < o + 32) throw new Error("scope: account too short");
|
|
35756
|
+
const dv = view(b);
|
|
35757
|
+
const value = dv.getBigUint64(o, true);
|
|
35758
|
+
const exp = Number(dv.getBigUint64(o + 8, true));
|
|
35759
|
+
return {
|
|
35760
|
+
kind: "scope",
|
|
35761
|
+
price: Number(value) / 10 ** exp,
|
|
35762
|
+
updatedAt: Number(dv.getBigUint64(o + 24, true)),
|
|
35763
|
+
slot: Number(dv.getBigUint64(o + 16, true))
|
|
35764
|
+
};
|
|
35765
|
+
}
|
|
35766
|
+
function decodeMarinadeMsolPrice(data) {
|
|
35767
|
+
const b = bytes(data);
|
|
35768
|
+
if (b.length < 520) throw new Error("marinade: account too short");
|
|
35769
|
+
return Number(view(b).getBigUint64(512, true)) / 2 ** 32;
|
|
35770
|
+
}
|
|
35771
|
+
function decodeOracleFeed(account) {
|
|
35772
|
+
const b = bytes(account.data);
|
|
35773
|
+
if (PYTH_PRICE_UPDATE_OWNERS.has(account.owner) && disc(b, PYTH_PRICE_UPDATE_V2_DISCRIMINATOR)) {
|
|
35774
|
+
const p = decodePythPriceUpdate(b);
|
|
35775
|
+
return {
|
|
35776
|
+
kind: "pyth-push",
|
|
35777
|
+
price: p.priceUsd,
|
|
35778
|
+
updatedAt: p.publishTime,
|
|
35779
|
+
slot: p.postedSlot
|
|
35780
|
+
};
|
|
35781
|
+
}
|
|
35782
|
+
if (account.owner === SWITCHBOARD_ON_DEMAND_PROGRAM)
|
|
35783
|
+
return decodeSwitchboardPullFeed(b);
|
|
35784
|
+
if (account.owner === SWITCHBOARD_V2_PROGRAM)
|
|
35785
|
+
return decodeSwitchboardV2Aggregator(b);
|
|
35786
|
+
if (account.owner === PYTH_LEGACY_PROGRAM) return decodePythLegacyPrice(b);
|
|
35787
|
+
return void 0;
|
|
35788
|
+
}
|
|
35789
|
+
|
|
35790
|
+
// src/lending/public-data/project0/prices.ts
|
|
34065
35791
|
var P0_PYTH_PUSH_SETUPS = /* @__PURE__ */ new Set([
|
|
34066
35792
|
"PythPushOracle",
|
|
34067
35793
|
"StakedWithPythPush",
|
|
@@ -34099,6 +35825,7 @@ var stakePoolKeyOf = (b) => {
|
|
|
34099
35825
|
return void 0;
|
|
34100
35826
|
}
|
|
34101
35827
|
};
|
|
35828
|
+
var marinadeKeyOf = (b) => b.config.oracleSetup === "PythMSOL" ? b.config.oracleKeys[1] : void 0;
|
|
34102
35829
|
var isP0FixedSetup = (setup) => setup.startsWith("Fixed");
|
|
34103
35830
|
var P0_STAKE_POOL_PROGRAMS = /* @__PURE__ */ new Set([
|
|
34104
35831
|
SPL_STAKE_POOL_PROGRAM,
|
|
@@ -34109,6 +35836,8 @@ var DRIFT_SCALED_BALANCE_DECIMALS = 9;
|
|
|
34109
35836
|
async function resolveP0Prices(rpc, banks, opts = {}) {
|
|
34110
35837
|
const pythKeys = /* @__PURE__ */ new Set();
|
|
34111
35838
|
const poolKeys = /* @__PURE__ */ new Set();
|
|
35839
|
+
const marinadeKeys = /* @__PURE__ */ new Set();
|
|
35840
|
+
const scopeKeys = /* @__PURE__ */ new Set();
|
|
34112
35841
|
if (!opts.cacheOnly && rpc)
|
|
34113
35842
|
for (const b of banks) {
|
|
34114
35843
|
if (P0_PYTH_PUSH_SETUPS.has(b.config.oracleSetup)) {
|
|
@@ -34117,12 +35846,20 @@ async function resolveP0Prices(rpc, banks, opts = {}) {
|
|
|
34117
35846
|
}
|
|
34118
35847
|
const pool = stakePoolKeyOf(b);
|
|
34119
35848
|
if (!isNullKey(pool)) poolKeys.add(pool);
|
|
35849
|
+
const msol = marinadeKeyOf(b);
|
|
35850
|
+
if (!isNullKey(msol)) marinadeKeys.add(msol);
|
|
35851
|
+
if (b.config.oracleSetup === "Scope") {
|
|
35852
|
+
const k = b.config.oracleKeys[0];
|
|
35853
|
+
if (!isNullKey(k)) scopeKeys.add(k);
|
|
35854
|
+
}
|
|
34120
35855
|
}
|
|
34121
35856
|
const pyth = {};
|
|
34122
35857
|
const poolRate = {};
|
|
35858
|
+
const msolRate = {};
|
|
35859
|
+
const scopeData = {};
|
|
34123
35860
|
let slot = 0;
|
|
34124
|
-
if (pythKeys.size || poolKeys.size) {
|
|
34125
|
-
const keys = [...pythKeys, ...poolKeys];
|
|
35861
|
+
if (pythKeys.size || poolKeys.size || marinadeKeys.size || scopeKeys.size) {
|
|
35862
|
+
const keys = [...pythKeys, ...poolKeys, ...marinadeKeys, ...scopeKeys];
|
|
34126
35863
|
const res = await rpc.readAccounts(keys, { encoding: "base64" });
|
|
34127
35864
|
slot = res.slot;
|
|
34128
35865
|
res.accounts.forEach((a, i) => {
|
|
@@ -34132,8 +35869,15 @@ async function resolveP0Prices(rpc, banks, opts = {}) {
|
|
|
34132
35869
|
if (pythKeys.has(key2)) {
|
|
34133
35870
|
if (a.owner === PYTH_RECEIVER_PROGRAM)
|
|
34134
35871
|
pyth[key2] = decodePythPriceUpdate(a.data[0]);
|
|
35872
|
+
} else if (marinadeKeys.has(key2)) {
|
|
35873
|
+
if (a.owner === MARINADE_PROGRAM) {
|
|
35874
|
+
const r = decodeMarinadeMsolPrice(a.data[0]);
|
|
35875
|
+
if (r > 0) msolRate[key2] = r;
|
|
35876
|
+
}
|
|
35877
|
+
} else if (scopeKeys.has(key2)) {
|
|
35878
|
+
if (a.owner === SCOPE_PROGRAM) scopeData[key2] = fromBase649(a.data[0]);
|
|
34135
35879
|
} else if (P0_STAKE_POOL_PROGRAMS.has(a.owner)) {
|
|
34136
|
-
const p = decodeStakePool(
|
|
35880
|
+
const p = decodeStakePool(fromBase649(a.data[0]));
|
|
34137
35881
|
if (p.poolTokenSupply > 0n)
|
|
34138
35882
|
poolRate[key2] = Number(p.totalLamports) / Number(p.poolTokenSupply);
|
|
34139
35883
|
}
|
|
@@ -34160,8 +35904,15 @@ async function resolveP0Prices(rpc, banks, opts = {}) {
|
|
|
34160
35904
|
}
|
|
34161
35905
|
const feed = b.config.oracleKeys[0];
|
|
34162
35906
|
const live = feed && !isNullKey(feed) ? pyth[feed] : void 0;
|
|
34163
|
-
const pool = stakePoolKeyOf(b);
|
|
34164
|
-
const liveRate = pool ? poolRate[pool] : void 0;
|
|
35907
|
+
const pool = stakePoolKeyOf(b) ?? marinadeKeyOf(b);
|
|
35908
|
+
const liveRate = pool ? poolRate[pool] ?? msolRate[pool] : void 0;
|
|
35909
|
+
let scope;
|
|
35910
|
+
if (setup === "Scope" && feed && scopeData[feed])
|
|
35911
|
+
try {
|
|
35912
|
+
scope = decodeScopePrice(scopeData[feed], b.config.scopeEntryIndex);
|
|
35913
|
+
} catch (e) {
|
|
35914
|
+
console.warn(`[project0] scope ${feed}: ${e.message}`);
|
|
35915
|
+
}
|
|
34165
35916
|
let liveMult = 1;
|
|
34166
35917
|
let liveMultNote = "";
|
|
34167
35918
|
if (P0_CACHED_PRICE_MULTIPLIER_SETUPS.has(setup)) {
|
|
@@ -34169,7 +35920,7 @@ async function resolveP0Prices(rpc, banks, opts = {}) {
|
|
|
34169
35920
|
liveMultNote = `cached SVSP rate ${cacheMult?.toFixed(6)} as of ${cacheTs}`;
|
|
34170
35921
|
} else if (P0_ADJUSTED_CACHE_SETUPS.has(setup)) {
|
|
34171
35922
|
liveMult = liveRate ?? null;
|
|
34172
|
-
liveMultNote = liveRate ?
|
|
35923
|
+
liveMultNote = liveRate ? `${msolRate[pool] ? "Marinade state" : "SPL stake pool"} ${pool} rate ${liveRate.toFixed(6)}` : "";
|
|
34173
35924
|
}
|
|
34174
35925
|
let out;
|
|
34175
35926
|
if (isP0FixedSetup(setup)) {
|
|
@@ -34186,6 +35937,15 @@ async function resolveP0Prices(rpc, banks, opts = {}) {
|
|
|
34186
35937
|
multiplier: 1,
|
|
34187
35938
|
description: `admin-set fixed price (${setup})`
|
|
34188
35939
|
};
|
|
35940
|
+
} else if (scope && scope.price > 0) {
|
|
35941
|
+
out = {
|
|
35942
|
+
priceUsd: scope.price,
|
|
35943
|
+
source: "scope",
|
|
35944
|
+
updatedAt: scope.updatedAt || void 0,
|
|
35945
|
+
multiplier: 1,
|
|
35946
|
+
feed,
|
|
35947
|
+
description: `Scope ${feed} entry ${b.config.scopeEntryIndex} (${setup})`
|
|
35948
|
+
};
|
|
34189
35949
|
} else if (live && liveMult !== null && liveMult > 0) {
|
|
34190
35950
|
out = {
|
|
34191
35951
|
priceUsd: live.priceUsd * liveMult,
|
|
@@ -34763,6 +36523,9 @@ async function getLenderPublicData(chainId, opts = {}) {
|
|
|
34763
36523
|
return Object.assign({}, ...parts);
|
|
34764
36524
|
}
|
|
34765
36525
|
|
|
36526
|
+
// src/lending/public-data/getLenderPublicDataAll.ts
|
|
36527
|
+
import { measureSlotSeconds as measureSlotSeconds2 } from "@1delta/svm-kit";
|
|
36528
|
+
|
|
34766
36529
|
// src/lending/public-data/basket.ts
|
|
34767
36530
|
function describeBasket(lenderKey, bundle) {
|
|
34768
36531
|
const brand = lenderBrandKey(lenderKey) ?? lenderKey;
|
|
@@ -34882,12 +36645,15 @@ async function getLenderPublicDataAll(chainId, lenders, opts = {}) {
|
|
|
34882
36645
|
if (chainId !== SOLANA_CHAIN_ID)
|
|
34883
36646
|
throw new Error(`getLenderPublicDataAll: unsupported chain ${chainId}`);
|
|
34884
36647
|
const out = {};
|
|
36648
|
+
const needsSlot = opts.rpc && (lenders.some(isSave) && opts.save?.avgSlotSeconds === void 0 || lenders.some(isKamino) && opts.kamino?.slotSeconds === void 0);
|
|
36649
|
+
const slotSeconds = needsSlot ? await measureSlotSeconds2(opts.rpc) : void 0;
|
|
34885
36650
|
const kaminoKeys = lenders.filter(isKamino);
|
|
34886
36651
|
if (kaminoKeys.length) {
|
|
34887
36652
|
const explicit = kaminoKeys.map(kaminoMarketFromKey).filter((m) => !!m);
|
|
34888
36653
|
const wantsAll = kaminoKeys.some((k) => !kaminoMarketFromKey(k));
|
|
34889
36654
|
const res = await fetchKaminoPublic({
|
|
34890
36655
|
...opts.kamino,
|
|
36656
|
+
slotSeconds: opts.kamino?.slotSeconds ?? slotSeconds,
|
|
34891
36657
|
rpc: opts.kamino?.rpc ?? opts.rpc,
|
|
34892
36658
|
tokenList: opts.tokenList ?? opts.kamino?.tokenList,
|
|
34893
36659
|
...wantsAll ? {} : { markets: explicit }
|
|
@@ -34927,6 +36693,7 @@ async function getLenderPublicDataAll(chainId, lenders, opts = {}) {
|
|
|
34927
36693
|
const wantsAll = saveKeys.some((k) => !saveMarketFromKey(k));
|
|
34928
36694
|
const res = await fetchSavePublic({
|
|
34929
36695
|
...opts.save,
|
|
36696
|
+
avgSlotSeconds: opts.save?.avgSlotSeconds ?? slotSeconds,
|
|
34930
36697
|
tokenList: opts.tokenList ?? opts.save?.tokenList,
|
|
34931
36698
|
...wantsAll ? {} : { markets: explicit }
|
|
34932
36699
|
});
|
|
@@ -35103,9 +36870,9 @@ function liquidityRatio(liquidity, totalAssets) {
|
|
|
35103
36870
|
// src/vaults/jupiter-lend/index.ts
|
|
35104
36871
|
function convertJupiterLendEarnToken(market, t, tokenList) {
|
|
35105
36872
|
const price = num(t.asset.price);
|
|
35106
|
-
const
|
|
35107
|
-
const totalAssetsFormatted = Number(t.totalAssets) / 10 **
|
|
35108
|
-
const liquidityFormatted = Number(t.liquiditySupplyData.withdrawable) / 10 **
|
|
36873
|
+
const dec2 = t.asset.decimals;
|
|
36874
|
+
const totalAssetsFormatted = Number(t.totalAssets) / 10 ** dec2;
|
|
36875
|
+
const liquidityFormatted = Number(t.liquiditySupplyData.withdrawable) / 10 ** dec2;
|
|
35109
36876
|
const sharePrice = Number(t.convertToAssets) / 10 ** t.decimals;
|
|
35110
36877
|
const supplyRate = bpsToPercent(t.supplyRate);
|
|
35111
36878
|
const rewardsRate = bpsToPercent(t.rewardsRate);
|
|
@@ -35114,7 +36881,7 @@ function convertJupiterLendEarnToken(market, t, tokenList) {
|
|
|
35114
36881
|
address: t.assetAddress,
|
|
35115
36882
|
symbol: t.asset.uiSymbol,
|
|
35116
36883
|
name: t.asset.name,
|
|
35117
|
-
decimals:
|
|
36884
|
+
decimals: dec2,
|
|
35118
36885
|
...t.asset.logoUrl ? { logoURI: t.asset.logoUrl } : {}
|
|
35119
36886
|
};
|
|
35120
36887
|
return {
|
|
@@ -35129,7 +36896,7 @@ function convertJupiterLendEarnToken(market, t, tokenList) {
|
|
|
35129
36896
|
displayName: `Jupiter Lend ${t.asset.uiSymbol}`,
|
|
35130
36897
|
curatorName: "Jupiter",
|
|
35131
36898
|
decimals: t.decimals,
|
|
35132
|
-
assetDecimals:
|
|
36899
|
+
assetDecimals: dec2,
|
|
35133
36900
|
totalAssets: t.totalAssets,
|
|
35134
36901
|
totalSupply: t.totalSupply,
|
|
35135
36902
|
convertToShares: t.convertToShares,
|
|
@@ -35388,11 +37155,11 @@ async function fetchExponentPtMarkets(opts = {}) {
|
|
|
35388
37155
|
|
|
35389
37156
|
// src/vaults/solstice/accounts.ts
|
|
35390
37157
|
import {
|
|
35391
|
-
decodeBase58 as
|
|
35392
|
-
decodeIdlAccount as
|
|
37158
|
+
decodeBase58 as decodeBase585,
|
|
37159
|
+
decodeIdlAccount as decodeIdlAccount6,
|
|
35393
37160
|
encodeBase58 as encodeBase585,
|
|
35394
|
-
findProgramAddress as
|
|
35395
|
-
fromBase64 as
|
|
37161
|
+
findProgramAddress as findProgramAddress5,
|
|
37162
|
+
fromBase64 as fromBase6410
|
|
35396
37163
|
} from "@1delta/svm-kit";
|
|
35397
37164
|
|
|
35398
37165
|
// src/vaults/solstice/idl/yield_strategy.json
|
|
@@ -46062,14 +47829,14 @@ var SOLSTICE_MINTS = {
|
|
|
46062
47829
|
var SOLSTICE_STRATEGIES = ["STRC-USX"];
|
|
46063
47830
|
var SOLSTICE_DECIMALS = 6;
|
|
46064
47831
|
var SOLSTICE_PRICE_DECIMALS = 6;
|
|
46065
|
-
var
|
|
46066
|
-
var
|
|
46067
|
-
const b =
|
|
47832
|
+
var utf85 = (s) => new TextEncoder().encode(s);
|
|
47833
|
+
var pk5 = (address) => {
|
|
47834
|
+
const b = decodeBase585(address);
|
|
46068
47835
|
if (!b || b.length !== 32)
|
|
46069
47836
|
throw new Error(`solstice: not a 32-byte pubkey: ${address}`);
|
|
46070
47837
|
return b;
|
|
46071
47838
|
};
|
|
46072
|
-
var pda = async (seeds, programId) => (await
|
|
47839
|
+
var pda = async (seeds, programId) => (await findProgramAddress5(seeds, programId)).address;
|
|
46073
47840
|
async function yieldVaultPdas(programId = SOLSTICE_PROGRAMS.yieldVault) {
|
|
46074
47841
|
const [controller, yieldPool, vestingSchedule, shareMint, assetVault] = await Promise.all(
|
|
46075
47842
|
[
|
|
@@ -46078,19 +47845,19 @@ async function yieldVaultPdas(programId = SOLSTICE_PROGRAMS.yieldVault) {
|
|
|
46078
47845
|
"VESTING_SCHEDULE",
|
|
46079
47846
|
"SHARE_MINT",
|
|
46080
47847
|
"ASSET_VAULT"
|
|
46081
|
-
].map((s) => pda([
|
|
47848
|
+
].map((s) => pda([utf85(s)], programId))
|
|
46082
47849
|
);
|
|
46083
47850
|
return { controller, yieldPool, vestingSchedule, shareMint, assetVault };
|
|
46084
47851
|
}
|
|
46085
47852
|
async function yieldVaultCooldownPdas(user, programId = SOLSTICE_PROGRAMS.yieldVault) {
|
|
46086
47853
|
const [escrow, escrowVault] = await Promise.all([
|
|
46087
|
-
pda([
|
|
46088
|
-
pda([
|
|
47854
|
+
pda([utf85("COOLDOWN_ESCROW"), pk5(user)], programId),
|
|
47855
|
+
pda([utf85("COOLDOWN_ESCROW_VAULT"), pk5(user)], programId)
|
|
46089
47856
|
]);
|
|
46090
47857
|
return { escrow, escrowVault };
|
|
46091
47858
|
}
|
|
46092
47859
|
async function strategyPdas(name, programId = SOLSTICE_PROGRAMS.yieldStrategy) {
|
|
46093
|
-
const n =
|
|
47860
|
+
const n = utf85(name);
|
|
46094
47861
|
if (n.length < 1 || n.length > 32)
|
|
46095
47862
|
throw new Error(`solstice: strategy name must be 1..=32 bytes: ${name}`);
|
|
46096
47863
|
const [
|
|
@@ -46102,13 +47869,13 @@ async function strategyPdas(name, programId = SOLSTICE_PROGRAMS.yieldStrategy) {
|
|
|
46102
47869
|
assetVault,
|
|
46103
47870
|
feeVault
|
|
46104
47871
|
] = await Promise.all([
|
|
46105
|
-
pda([
|
|
46106
|
-
pda([
|
|
46107
|
-
pda([
|
|
46108
|
-
pda([
|
|
46109
|
-
pda([
|
|
46110
|
-
pda([
|
|
46111
|
-
pda([
|
|
47872
|
+
pda([utf85("CONTROLLER")], programId),
|
|
47873
|
+
pda([utf85("STRATEGY"), n], programId),
|
|
47874
|
+
pda([utf85("ACCOUNTING"), n], programId),
|
|
47875
|
+
pda([utf85("JUNIOR_MINT"), n], programId),
|
|
47876
|
+
pda([utf85("SENIOR_MINT"), n], programId),
|
|
47877
|
+
pda([utf85("ASSET_VAULT"), n], programId),
|
|
47878
|
+
pda([utf85("FEE_VAULT"), n], programId)
|
|
46112
47879
|
]);
|
|
46113
47880
|
return {
|
|
46114
47881
|
name,
|
|
@@ -46123,10 +47890,10 @@ async function strategyPdas(name, programId = SOLSTICE_PROGRAMS.yieldStrategy) {
|
|
|
46123
47890
|
}
|
|
46124
47891
|
async function settlementBatchPdas(strategyName, batchName, programId = SOLSTICE_PROGRAMS.yieldStrategy) {
|
|
46125
47892
|
const seeds = (tag) => [
|
|
46126
|
-
|
|
46127
|
-
|
|
47893
|
+
utf85(tag),
|
|
47894
|
+
utf85(strategyName),
|
|
46128
47895
|
Uint8Array.of(0),
|
|
46129
|
-
|
|
47896
|
+
utf85(batchName)
|
|
46130
47897
|
];
|
|
46131
47898
|
const [batch, shareVault, assetVault] = await Promise.all([
|
|
46132
47899
|
pda(seeds("SETTLEMENT_BATCH"), programId),
|
|
@@ -46135,34 +47902,34 @@ async function settlementBatchPdas(strategyName, batchName, programId = SOLSTICE
|
|
|
46135
47902
|
]);
|
|
46136
47903
|
return { batch, shareVault, assetVault };
|
|
46137
47904
|
}
|
|
46138
|
-
var juniorUnlockSharePda = (batch, user, programId = SOLSTICE_PROGRAMS.yieldStrategy) => pda([
|
|
47905
|
+
var juniorUnlockSharePda = (batch, user, programId = SOLSTICE_PROGRAMS.yieldStrategy) => pda([utf85("JUNIOR_UNLOCK_SHARE"), pk5(batch), pk5(user)], programId);
|
|
46139
47906
|
async function seniorCooldownPdas(strategyName, user, programId = SOLSTICE_PROGRAMS.yieldStrategy) {
|
|
46140
47907
|
const [cooldown, cooldownVault] = await Promise.all([
|
|
46141
47908
|
pda(
|
|
46142
|
-
[
|
|
47909
|
+
[utf85("SENIOR_UNLOCK_COOLDOWN"), utf85(strategyName), pk5(user)],
|
|
46143
47910
|
programId
|
|
46144
47911
|
),
|
|
46145
47912
|
pda(
|
|
46146
|
-
[
|
|
47913
|
+
[utf85("SENIOR_COOLDOWN_VAULT"), utf85(strategyName), pk5(user)],
|
|
46147
47914
|
programId
|
|
46148
47915
|
)
|
|
46149
47916
|
]);
|
|
46150
47917
|
return { cooldown, cooldownVault };
|
|
46151
47918
|
}
|
|
46152
|
-
var oracleCanonicalPda = (feedId, programId = SOLSTICE_PROGRAMS.oracle) => pda([
|
|
47919
|
+
var oracleCanonicalPda = (feedId, programId = SOLSTICE_PROGRAMS.oracle) => pda([utf85("CANONICAL"), utf85(feedId)], programId);
|
|
46153
47920
|
var strategyNameOf = (raw2) => new TextDecoder().decode(raw2).replace(/\0+$/, "");
|
|
46154
47921
|
var YV = SOLSTICE_YIELD_VAULT_IDL;
|
|
46155
47922
|
var YS = SOLSTICE_YIELD_STRATEGY_IDL;
|
|
46156
|
-
var decodeController = (d2) =>
|
|
46157
|
-
var decodeYieldPool = (d2) =>
|
|
46158
|
-
var decodeVestingSchedule = (d2) =>
|
|
46159
|
-
var decodeCooldownEscrow = (d2) =>
|
|
46160
|
-
var decodeStrategyController = (d2) =>
|
|
46161
|
-
var decodeStrategy = (d2) =>
|
|
46162
|
-
var decodeAccountingState = (d2) =>
|
|
46163
|
-
var decodeSettlementBatch = (d2) =>
|
|
46164
|
-
var decodeJuniorUnlockShare = (d2) =>
|
|
46165
|
-
var decodeSeniorUnlockCooldown = (d2) =>
|
|
47923
|
+
var decodeController = (d2) => decodeIdlAccount6(YV, "Controller", d2);
|
|
47924
|
+
var decodeYieldPool = (d2) => decodeIdlAccount6(YV, "YieldPool", d2);
|
|
47925
|
+
var decodeVestingSchedule = (d2) => decodeIdlAccount6(YV, "VestingSchedule", d2);
|
|
47926
|
+
var decodeCooldownEscrow = (d2) => decodeIdlAccount6(YV, "CooldownEscrow", d2);
|
|
47927
|
+
var decodeStrategyController = (d2) => decodeIdlAccount6(YS, "Controller", d2);
|
|
47928
|
+
var decodeStrategy = (d2) => decodeIdlAccount6(YS, "Strategy", d2);
|
|
47929
|
+
var decodeAccountingState = (d2) => decodeIdlAccount6(YS, "AccountingState", d2);
|
|
47930
|
+
var decodeSettlementBatch = (d2) => decodeIdlAccount6(YS, "SettlementBatch", d2);
|
|
47931
|
+
var decodeJuniorUnlockShare = (d2) => decodeIdlAccount6(YS, "JuniorUnlockShare", d2);
|
|
47932
|
+
var decodeSeniorUnlockCooldown = (d2) => decodeIdlAccount6(YS, "SeniorUnlockCooldown", d2);
|
|
46166
47933
|
function accountDiscriminator(idl, name) {
|
|
46167
47934
|
const a = idl.accounts.find((x) => x.name === name);
|
|
46168
47935
|
if (!a) throw new Error(`idl ${idl.metadata?.name}: no account ${name}`);
|
|
@@ -46209,7 +47976,7 @@ function tokenAmount(data) {
|
|
|
46209
47976
|
}
|
|
46210
47977
|
var need = (a, what) => {
|
|
46211
47978
|
if (!a) throw new Error(`solstice: ${what} account is missing`);
|
|
46212
|
-
return
|
|
47979
|
+
return fromBase6410(a.data[0]);
|
|
46213
47980
|
};
|
|
46214
47981
|
async function readSolsticeChainState(rpc, opts = {}) {
|
|
46215
47982
|
const programs = { ...SOLSTICE_PROGRAMS, ...opts.programs };
|
|
@@ -46274,7 +48041,7 @@ async function readSolsticeChainState(rpc, opts = {}) {
|
|
|
46274
48041
|
const raw2 = r.accounts[j++];
|
|
46275
48042
|
s.oracleAccount = feeds[i];
|
|
46276
48043
|
if (raw2)
|
|
46277
|
-
s.oracle = decodeOracleCanonical(
|
|
48044
|
+
s.oracle = decodeOracleCanonical(fromBase6410(raw2.data[0])) ?? void 0;
|
|
46278
48045
|
});
|
|
46279
48046
|
}
|
|
46280
48047
|
return { slot, yieldVault, strategies };
|
|
@@ -46291,7 +48058,7 @@ function createSolsticeAppApi(opts = {}) {
|
|
|
46291
48058
|
}
|
|
46292
48059
|
|
|
46293
48060
|
// src/vaults/solstice/math.ts
|
|
46294
|
-
var
|
|
48061
|
+
var SECONDS_PER_YEAR3 = 31536000n;
|
|
46295
48062
|
var bigMax0 = (v) => v > 0n ? v : 0n;
|
|
46296
48063
|
function unvestedAt(amount, start, end, now) {
|
|
46297
48064
|
if (start === 0n && end === 0n) return 0n;
|
|
@@ -46330,7 +48097,7 @@ function eusxAssetsToShares(assets, r) {
|
|
|
46330
48097
|
function epochRatePercent(vesting, assetsIncludingVesting, epochSeconds) {
|
|
46331
48098
|
const principal = assetsIncludingVesting - vesting;
|
|
46332
48099
|
if (vesting < 0n || principal <= 0n || epochSeconds <= 0n) return void 0;
|
|
46333
|
-
const perYear = Number(
|
|
48100
|
+
const perYear = Number(SECONDS_PER_YEAR3) / Number(epochSeconds);
|
|
46334
48101
|
return Number(vesting) / Number(principal) * perYear * 100;
|
|
46335
48102
|
}
|
|
46336
48103
|
var eusxEpochRatePercent = (pool, vesting) => epochRatePercent(
|
|
@@ -46389,7 +48156,7 @@ function strategyMode(s, oraclePriceUsd, priceDecimals = 6) {
|
|
|
46389
48156
|
import {
|
|
46390
48157
|
createSvmFetchers,
|
|
46391
48158
|
createSvmRpc as createSvmRpc3,
|
|
46392
|
-
fromBase64 as
|
|
48159
|
+
fromBase64 as fromBase6411
|
|
46393
48160
|
} from "@1delta/svm-kit";
|
|
46394
48161
|
var SCALE = 10 ** SOLSTICE_DECIMALS;
|
|
46395
48162
|
var fmt3 = (raw2) => Number(raw2) / SCALE;
|
|
@@ -46413,7 +48180,7 @@ async function fetchSolsticeSettlementBatches(rpc, strategyName, juniorQueueTime
|
|
|
46413
48180
|
);
|
|
46414
48181
|
const out = [];
|
|
46415
48182
|
for (const r of rows) {
|
|
46416
|
-
const b = decodeSettlementBatch(
|
|
48183
|
+
const b = decodeSettlementBatch(fromBase6411(r.account.data[0]));
|
|
46417
48184
|
if (strategyNameOf(b.strategy_name) !== strategyName) continue;
|
|
46418
48185
|
const settlementTime = Number(b.settlement_time);
|
|
46419
48186
|
out.push({
|
|
@@ -46719,7 +48486,7 @@ async function fetchSolsticeVaults(opts = {}) {
|
|
|
46719
48486
|
// src/vaults/solstice/fetchUser.ts
|
|
46720
48487
|
import {
|
|
46721
48488
|
createSvmRpc as createSvmRpc4,
|
|
46722
|
-
fromBase64 as
|
|
48489
|
+
fromBase64 as fromBase6412,
|
|
46723
48490
|
getAssociatedTokenAddress as getAssociatedTokenAddress2,
|
|
46724
48491
|
TOKEN_PROGRAM
|
|
46725
48492
|
} from "@1delta/svm-kit";
|
|
@@ -46760,10 +48527,10 @@ async function fetchSolsticeUser(account, opts = {}) {
|
|
|
46760
48527
|
const { slot, accounts } = await rpc.readAccounts(keys);
|
|
46761
48528
|
let i = 0;
|
|
46762
48529
|
const next = () => accounts[i++] ?? null;
|
|
46763
|
-
const
|
|
48530
|
+
const bytes2 = (a) => a ? fromBase6412(a.data[0]) : void 0;
|
|
46764
48531
|
const holdings = [];
|
|
46765
48532
|
rows.forEach((r, k) => {
|
|
46766
|
-
const d2 =
|
|
48533
|
+
const d2 = bytes2(next());
|
|
46767
48534
|
if (!d2) return;
|
|
46768
48535
|
const shares = tokenAmount(d2);
|
|
46769
48536
|
if (shares === 0n) return;
|
|
@@ -46785,7 +48552,7 @@ async function fetchSolsticeUser(account, opts = {}) {
|
|
|
46785
48552
|
const pending = [];
|
|
46786
48553
|
const usd = (raw2, r) => Number(raw2) / 10 ** r.assetDecimals * (r.priceUsd ?? 0);
|
|
46787
48554
|
if (eusx && escrow) {
|
|
46788
|
-
const d2 =
|
|
48555
|
+
const d2 = bytes2(next());
|
|
46789
48556
|
if (d2) {
|
|
46790
48557
|
const e = decodeCooldownEscrow(d2);
|
|
46791
48558
|
if (e.asset_amount > 0n)
|
|
@@ -46803,7 +48570,7 @@ async function fetchSolsticeUser(account, opts = {}) {
|
|
|
46803
48570
|
}
|
|
46804
48571
|
}
|
|
46805
48572
|
seniors.forEach((r, k) => {
|
|
46806
|
-
const d2 =
|
|
48573
|
+
const d2 = bytes2(next());
|
|
46807
48574
|
if (!d2) return;
|
|
46808
48575
|
const c = decodeSeniorUnlockCooldown(d2);
|
|
46809
48576
|
if (c.assets_pending === 0n) return;
|
|
@@ -46823,7 +48590,7 @@ async function fetchSolsticeUser(account, opts = {}) {
|
|
|
46823
48590
|
});
|
|
46824
48591
|
});
|
|
46825
48592
|
for (const j of juniorRecords) {
|
|
46826
|
-
const d2 =
|
|
48593
|
+
const d2 = bytes2(next());
|
|
46827
48594
|
if (!d2) continue;
|
|
46828
48595
|
const u = decodeJuniorUnlockShare(d2);
|
|
46829
48596
|
if (u.shares === 0n) continue;
|
|
@@ -62924,10 +64691,10 @@ var HUMA_SEEDS = {
|
|
|
62924
64691
|
|
|
62925
64692
|
// src/vaults/huma/accounts.ts
|
|
62926
64693
|
import {
|
|
62927
|
-
decodeBase58 as
|
|
62928
|
-
decodeIdlAccount as
|
|
62929
|
-
findProgramAddress as
|
|
62930
|
-
fromBase64 as
|
|
64694
|
+
decodeBase58 as decodeBase586,
|
|
64695
|
+
decodeIdlAccount as decodeIdlAccount7,
|
|
64696
|
+
findProgramAddress as findProgramAddress6,
|
|
64697
|
+
fromBase64 as fromBase6413,
|
|
62931
64698
|
getAssociatedTokenAddress as getAssociatedTokenAddress3,
|
|
62932
64699
|
TOKEN_PROGRAM as TOKEN_PROGRAM2
|
|
62933
64700
|
} from "@1delta/svm-kit";
|
|
@@ -62943,21 +64710,21 @@ var HUMA_POOL = {
|
|
|
62943
64710
|
var HUMA_MPST_MINT = "HUPfpnsaJtJGpJxAPNX1vXah7BgYiQYt1c2JMgMumvPs";
|
|
62944
64711
|
var HUMA_CLASSIC_MODE_ID = "Fr2BGzmFkufAUXNWSWk79juyWrHVCj8AbyzbbvZzhwgz";
|
|
62945
64712
|
var HUMA_DECIMALS = 6;
|
|
62946
|
-
var
|
|
62947
|
-
var
|
|
62948
|
-
const b =
|
|
64713
|
+
var utf86 = (s) => new TextEncoder().encode(s);
|
|
64714
|
+
var pk6 = (address) => {
|
|
64715
|
+
const b = decodeBase586(address);
|
|
62949
64716
|
if (!b || b.length !== 32) throw new Error(`huma: bad pubkey ${address}`);
|
|
62950
64717
|
return b;
|
|
62951
64718
|
};
|
|
62952
|
-
var pda2 = (seeds) =>
|
|
62953
|
-
var humaPoolConfigPda = () => pda2([
|
|
62954
|
-
var humaPoolStatePda = () => pda2([
|
|
62955
|
-
var humaPoolAuthorityPda = () => pda2([
|
|
62956
|
-
var humaModeConfigPda = (modeId) => pda2([
|
|
62957
|
-
var humaModeMintPda = (modeConfig) => pda2([
|
|
62958
|
-
var humaLenderStatePda = (modeConfig, lender) => pda2([
|
|
62959
|
-
var humaDeploymentStatePda = (deploymentConfig) => pda2([
|
|
62960
|
-
var humaRedemptionRequestPda = (id, poolConfig) => pda2([
|
|
64719
|
+
var pda2 = (seeds) => findProgramAddress6(seeds, HUMA_PROGRAM).then((r) => r.address);
|
|
64720
|
+
var humaPoolConfigPda = () => pda2([utf86("pool_config"), pk6(HUMA_POOL.poolId)]);
|
|
64721
|
+
var humaPoolStatePda = () => pda2([utf86("pool_state"), pk6(HUMA_POOL.poolConfig)]);
|
|
64722
|
+
var humaPoolAuthorityPda = () => pda2([utf86("pool_authority"), pk6(HUMA_POOL.poolConfig)]);
|
|
64723
|
+
var humaModeConfigPda = (modeId) => pda2([utf86("mode_config"), pk6(HUMA_POOL.poolConfig), pk6(modeId)]);
|
|
64724
|
+
var humaModeMintPda = (modeConfig) => pda2([utf86("mode_mint"), pk6(HUMA_POOL.poolConfig), pk6(modeConfig)]);
|
|
64725
|
+
var humaLenderStatePda = (modeConfig, lender) => pda2([utf86("lender_state"), pk6(modeConfig), pk6(lender)]);
|
|
64726
|
+
var humaDeploymentStatePda = (deploymentConfig) => pda2([utf86("deployment_state"), pk6(deploymentConfig)]);
|
|
64727
|
+
var humaRedemptionRequestPda = (id, poolConfig) => pda2([utf86("redemption_request"), u128be(id), pk6(poolConfig)]);
|
|
62961
64728
|
var u128be = (v) => {
|
|
62962
64729
|
if (v < 0n || v >= 1n << 128n) throw new Error(`huma: id out of u128: ${v}`);
|
|
62963
64730
|
const out = new Uint8Array(16);
|
|
@@ -62965,11 +64732,11 @@ var u128be = (v) => {
|
|
|
62965
64732
|
out[15 - i] = Number(v >> BigInt(8 * i) & 0xffn);
|
|
62966
64733
|
return out;
|
|
62967
64734
|
};
|
|
62968
|
-
var decodeHumaPoolState = (d2) =>
|
|
62969
|
-
var decodeHumaModeConfig = (d2) =>
|
|
62970
|
-
var decodeHumaPoolConfig = (d2) =>
|
|
62971
|
-
var decodeHumaLenderState = (d2) =>
|
|
62972
|
-
var decodeHumaRedemptionRequest = (d2) =>
|
|
64735
|
+
var decodeHumaPoolState = (d2) => decodeIdlAccount7(HUMA_IDL, "PoolState", d2);
|
|
64736
|
+
var decodeHumaModeConfig = (d2) => decodeIdlAccount7(HUMA_IDL, "ModeConfig", d2);
|
|
64737
|
+
var decodeHumaPoolConfig = (d2) => decodeIdlAccount7(HUMA_IDL, "PoolConfig", d2);
|
|
64738
|
+
var decodeHumaLenderState = (d2) => decodeIdlAccount7(HUMA_IDL, "LenderState", d2);
|
|
64739
|
+
var decodeHumaRedemptionRequest = (d2) => decodeIdlAccount7(HUMA_IDL, "RedemptionRequest", d2);
|
|
62973
64740
|
function mintSupply2(data) {
|
|
62974
64741
|
if (data.length < 44) throw new Error("huma: mint account too short");
|
|
62975
64742
|
return data.slice(36, 44).reduce((a, b, i) => a | BigInt(b) << BigInt(8 * i), 0n);
|
|
@@ -62993,13 +64760,13 @@ async function readHumaChainState(rpc, pool = HUMA_POOL) {
|
|
|
62993
64760
|
{ encoding: "base64" }
|
|
62994
64761
|
);
|
|
62995
64762
|
const state = decodeHumaPoolState(
|
|
62996
|
-
|
|
64763
|
+
fromBase6413(need2(first[0], "pool_state").data[0])
|
|
62997
64764
|
);
|
|
62998
64765
|
const config = decodeHumaPoolConfig(
|
|
62999
|
-
|
|
64766
|
+
fromBase6413(need2(first[1], "pool_config").data[0])
|
|
63000
64767
|
);
|
|
63001
64768
|
const poolCash = tokenAmount2(
|
|
63002
|
-
first[2] ?
|
|
64769
|
+
first[2] ? fromBase6413(first[2].data[0]) : void 0
|
|
63003
64770
|
);
|
|
63004
64771
|
const modeMints = await Promise.all(
|
|
63005
64772
|
state.mode_config_keys.map((k) => humaModeMintPda(k))
|
|
@@ -63014,9 +64781,9 @@ async function readHumaChainState(rpc, pool = HUMA_POOL) {
|
|
|
63014
64781
|
{ encoding: "base64" }
|
|
63015
64782
|
);
|
|
63016
64783
|
const modeConfig = decodeHumaModeConfig(
|
|
63017
|
-
|
|
64784
|
+
fromBase6413(need2(modeAcct, "mode_config").data[0])
|
|
63018
64785
|
);
|
|
63019
|
-
const mintData =
|
|
64786
|
+
const mintData = fromBase6413(need2(mintAcct, "pst_mint").data[0]);
|
|
63020
64787
|
const next = state.redemption.next_request_id;
|
|
63021
64788
|
const last = state.redemption.last_request_id;
|
|
63022
64789
|
const gate = state.redemption.global_redemption_gating;
|
|
@@ -63073,7 +64840,7 @@ async function readHumaLenderState(rpc, modeConfig, wallet) {
|
|
|
63073
64840
|
const a = accounts[0];
|
|
63074
64841
|
return {
|
|
63075
64842
|
address,
|
|
63076
|
-
state: a ? decodeHumaLenderState(
|
|
64843
|
+
state: a ? decodeHumaLenderState(fromBase6413(a.data[0])) : null
|
|
63077
64844
|
};
|
|
63078
64845
|
}
|
|
63079
64846
|
var HUMA_REDEMPTION_REQUEST_SIZE = 273;
|
|
@@ -63089,7 +64856,7 @@ async function readHumaRedemptionRequests(fetchers, wallet) {
|
|
|
63089
64856
|
);
|
|
63090
64857
|
return rows.map((r) => ({
|
|
63091
64858
|
address: r.pubkey,
|
|
63092
|
-
...decodeHumaRedemptionRequest(
|
|
64859
|
+
...decodeHumaRedemptionRequest(fromBase6413(r.account.data[0]))
|
|
63093
64860
|
})).sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
63094
64861
|
}
|
|
63095
64862
|
|
|
@@ -63209,16 +64976,16 @@ var nowSec = () => Math.floor(Date.now() / 1e3);
|
|
|
63209
64976
|
function convertLoopscaleVault(v, opts = {}) {
|
|
63210
64977
|
const s = v.vaultStrategy.strategy;
|
|
63211
64978
|
const listed3 = opts.tokenList?.[s.principalMint];
|
|
63212
|
-
const
|
|
63213
|
-
if (
|
|
64979
|
+
const dec2 = opts.decimals ?? listed3?.decimals;
|
|
64980
|
+
if (dec2 === void 0) return void 0;
|
|
63214
64981
|
const tvlRaw = strategyTvlRaw(s);
|
|
63215
|
-
const tvl = tvlRaw / 10 **
|
|
64982
|
+
const tvl = tvlRaw / 10 ** dec2;
|
|
63216
64983
|
const extAmount = Number(s.externalYieldAmount);
|
|
63217
64984
|
const deployed = Number(s.currentDeployedAmount);
|
|
63218
64985
|
const idle = Number(s.tokenBalance);
|
|
63219
64986
|
const ext = v.vaultStrategy.externalYieldInfo;
|
|
63220
64987
|
const extApr = ext ? cbpsToFraction(ext.apy) : 0;
|
|
63221
|
-
const grossAnnual = Number(s.interestPerSecond) *
|
|
64988
|
+
const grossAnnual = Number(s.interestPerSecond) * SECONDS_PER_YEAR2 + extApr * extAmount;
|
|
63222
64989
|
const gross = tvlRaw > 0 ? grossAnnual / tvlRaw * 100 : 0;
|
|
63223
64990
|
const feeFrac = cbpsToFraction(s.interestFee);
|
|
63224
64991
|
const supplyRate = gross * (1 - feeFrac);
|
|
@@ -63235,7 +65002,7 @@ function convertLoopscaleVault(v, opts = {}) {
|
|
|
63235
65002
|
const rDec = mint ? opts.tokenList?.[mint]?.decimals : void 0;
|
|
63236
65003
|
if (!p || rDec === void 0 || !priceUsd || tvl <= 0) continue;
|
|
63237
65004
|
const perSec = Number(r.emissionsPerSecond ?? 0) / 10 ** rDec;
|
|
63238
|
-
rewardsRate += perSec *
|
|
65005
|
+
rewardsRate += perSec * SECONDS_PER_YEAR2 * p / (tvl * priceUsd) * 100;
|
|
63239
65006
|
}
|
|
63240
65007
|
const lp = Number(v.vault.lpSupply);
|
|
63241
65008
|
const earlyFee = Number(v.vault.maxEarlyUnstakeFee);
|
|
@@ -63255,13 +65022,15 @@ function convertLoopscaleVault(v, opts = {}) {
|
|
|
63255
65022
|
name: meta?.name ?? v.vault.address,
|
|
63256
65023
|
displayName: meta?.name ? `Loopscale ${meta.name}` : `Loopscale ${sym}`,
|
|
63257
65024
|
curatorName: meta?.managerName ?? "Loopscale",
|
|
63258
|
-
|
|
63259
|
-
|
|
65025
|
+
manager: v.vault.manager,
|
|
65026
|
+
managerImage: meta?.managerImage ?? void 0,
|
|
65027
|
+
decimals: dec2,
|
|
65028
|
+
assetDecimals: dec2,
|
|
63260
65029
|
totalAssets: String(tvlRaw),
|
|
63261
65030
|
totalSupply: String(lp),
|
|
63262
|
-
convertToAssets: String(Math.round(sharePrice * 10 **
|
|
65031
|
+
convertToAssets: String(Math.round(sharePrice * 10 ** dec2)),
|
|
63263
65032
|
convertToShares: String(
|
|
63264
|
-
sharePrice > 0 ? Math.round(1 / sharePrice * 10 **
|
|
65033
|
+
sharePrice > 0 ? Math.round(1 / sharePrice * 10 ** dec2) : 0
|
|
63265
65034
|
),
|
|
63266
65035
|
grossRate: gross,
|
|
63267
65036
|
supplyRate,
|
|
@@ -63273,8 +65042,8 @@ function convertLoopscaleVault(v, opts = {}) {
|
|
|
63273
65042
|
totalAssetsFormatted: tvl,
|
|
63274
65043
|
totalAssetsUsd: sum?.totalSupplyUsd ?? tvl * (priceUsd ?? 0),
|
|
63275
65044
|
liquidity: String(idle),
|
|
63276
|
-
liquidityFormatted: idle / 10 **
|
|
63277
|
-
liquidityUsd: idle / 10 **
|
|
65045
|
+
liquidityFormatted: idle / 10 ** dec2,
|
|
65046
|
+
liquidityUsd: idle / 10 ** dec2 * (priceUsd ?? 0),
|
|
63278
65047
|
sharePrice,
|
|
63279
65048
|
sharePriceUsd: sharePrice * (priceUsd ?? 0),
|
|
63280
65049
|
yieldProfile: "yield-bearing",
|
|
@@ -63342,6 +65111,158 @@ async function fetchLoopscaleEarnVaults(opts = {}) {
|
|
|
63342
65111
|
return out;
|
|
63343
65112
|
}
|
|
63344
65113
|
|
|
65114
|
+
// src/vaults/kamino-kvault/api.ts
|
|
65115
|
+
var KVAULT_PROGRAM_ID = "KvauGMspG5k6rtzrqqn7WNn3oZdyKqLKwK2XWQ8FLjd";
|
|
65116
|
+
function createKaminoKvaultApi(opts = {}) {
|
|
65117
|
+
const base = (opts.baseUrl ?? KAMINO_API_BASE).replace(/\/$/, "");
|
|
65118
|
+
const limit = createLimiter(opts.maxInFlight ?? 4);
|
|
65119
|
+
const get = (path) => limit(() => getJson(`${base}${path}`, opts));
|
|
65120
|
+
return {
|
|
65121
|
+
vaults: () => get("/kvaults/vaults"),
|
|
65122
|
+
/** Every page of the batch metrics. A page that fails fails the call — a partial metrics set would read as vaults with no APY. */
|
|
65123
|
+
metrics: async () => {
|
|
65124
|
+
const out = [];
|
|
65125
|
+
let token;
|
|
65126
|
+
const maxPages = opts.maxPages ?? 20;
|
|
65127
|
+
for (let page = 0; page < maxPages; page++) {
|
|
65128
|
+
const res = await get(
|
|
65129
|
+
`/kvaults/vaults/metrics${token ? `?paginationToken=${encodeURIComponent(token)}` : ""}`
|
|
65130
|
+
);
|
|
65131
|
+
out.push(...res.result ?? []);
|
|
65132
|
+
token = res.paginationToken ?? void 0;
|
|
65133
|
+
if (!token || !res.result?.length) return out;
|
|
65134
|
+
}
|
|
65135
|
+
throw new Error(
|
|
65136
|
+
`kvault metrics: still paging after ${maxPages} pages (${out.length} rows)`
|
|
65137
|
+
);
|
|
65138
|
+
},
|
|
65139
|
+
vaultMetrics: (vault) => get(`/kvaults/vaults/${vault}/metrics`)
|
|
65140
|
+
};
|
|
65141
|
+
}
|
|
65142
|
+
|
|
65143
|
+
// src/vaults/kamino-kvault/fetchPublic.ts
|
|
65144
|
+
function decimalStringToRaw(s, decimals) {
|
|
65145
|
+
if (s === void 0 || s === null) return void 0;
|
|
65146
|
+
const t = String(s).trim();
|
|
65147
|
+
const m = /^(-?)(\d*)(?:\.(\d*))?$/.exec(t);
|
|
65148
|
+
if (!m || !m[2] && !m[3]) return void 0;
|
|
65149
|
+
const frac = (m[3] ?? "").slice(0, decimals).padEnd(decimals, "0");
|
|
65150
|
+
const v = BigInt((m[2] || "0") + frac);
|
|
65151
|
+
return m[1] ? -v : v;
|
|
65152
|
+
}
|
|
65153
|
+
function convertKaminoKvault(v, m, opts = {}) {
|
|
65154
|
+
if (!m) return void 0;
|
|
65155
|
+
const s = v.state;
|
|
65156
|
+
const dec2 = s.tokenMintDecimals;
|
|
65157
|
+
const shareDec = s.sharesMintDecimals;
|
|
65158
|
+
const listed3 = opts.tokenList?.[s.tokenMint];
|
|
65159
|
+
const listedShare = opts.tokenList?.[s.sharesMint];
|
|
65160
|
+
const sym = listed3?.symbol ?? s.tokenMint.slice(0, 4);
|
|
65161
|
+
const perShare = num(m.tokensPerShare, 1);
|
|
65162
|
+
const shares = BigInt(s.sharesIssued || "0");
|
|
65163
|
+
const perShareRaw = decimalStringToRaw(m.tokensPerShare, dec2) ?? 10n ** BigInt(dec2);
|
|
65164
|
+
const totalAssetsRaw = shares * perShareRaw / 10n ** BigInt(shareDec);
|
|
65165
|
+
const totalAssetsFormatted = Number(totalAssetsRaw) / 10 ** dec2;
|
|
65166
|
+
const idleRaw = BigInt(s.tokenAvailable || "0");
|
|
65167
|
+
const idle = Number(idleRaw) / 10 ** dec2;
|
|
65168
|
+
const price = num(m.tokenPrice);
|
|
65169
|
+
const priced = price > 0;
|
|
65170
|
+
const apy = {
|
|
65171
|
+
current: num(m.apy),
|
|
65172
|
+
actual: num(m.apyActual),
|
|
65173
|
+
d1: num(m.apy24h),
|
|
65174
|
+
d7: num(m.apy7d),
|
|
65175
|
+
d30: num(m.apy30d),
|
|
65176
|
+
d90: num(m.apy90d),
|
|
65177
|
+
farmRewards: num(m.apyFarmRewards),
|
|
65178
|
+
incentives: num(m.apyIncentives),
|
|
65179
|
+
reservesIncentives: num(m.apyReservesIncentives)
|
|
65180
|
+
};
|
|
65181
|
+
const supplyRate = apyFractionToAprPercent(apy.current);
|
|
65182
|
+
const rewardsRate = apyFractionToAprPercent(apy.farmRewards + apy.incentives);
|
|
65183
|
+
const name = s.name?.trim() || listedShare?.name || `Kamino Vault ${sym}`;
|
|
65184
|
+
return {
|
|
65185
|
+
provider: "kamino-kvault",
|
|
65186
|
+
originProvider: "kamino-kvault",
|
|
65187
|
+
chainId: SOLANA_CHAIN_ID,
|
|
65188
|
+
address: v.address,
|
|
65189
|
+
shareMint: s.sharesMint,
|
|
65190
|
+
underlying: s.tokenMint,
|
|
65191
|
+
symbol: listedShare?.symbol ?? `kv${sym}`,
|
|
65192
|
+
name,
|
|
65193
|
+
displayName: name.toLowerCase().includes("kamino") ? name : `Kamino ${name}`,
|
|
65194
|
+
curatorName: s.vaultAdminAuthority,
|
|
65195
|
+
manager: s.vaultAdminAuthority,
|
|
65196
|
+
allocationAdmin: s.allocationAdmin,
|
|
65197
|
+
decimals: shareDec,
|
|
65198
|
+
assetDecimals: dec2,
|
|
65199
|
+
totalAssets: totalAssetsRaw.toString(),
|
|
65200
|
+
totalSupply: shares.toString(),
|
|
65201
|
+
convertToAssets: perShareRaw.toString(),
|
|
65202
|
+
convertToShares: perShare > 0 ? String(Math.round(1 / perShare * 10 ** shareDec)) : "0",
|
|
65203
|
+
supplyRate,
|
|
65204
|
+
rewardsRate,
|
|
65205
|
+
depositRate: supplyRate + rewardsRate,
|
|
65206
|
+
asset: listed3,
|
|
65207
|
+
priceUsd: priced ? price : void 0,
|
|
65208
|
+
totalAssetsFormatted,
|
|
65209
|
+
totalAssetsUsd: priced ? totalAssetsFormatted * price : 0,
|
|
65210
|
+
liquidity: idleRaw.toString(),
|
|
65211
|
+
liquidityFormatted: idle,
|
|
65212
|
+
liquidityUsd: priced ? idle * price : 0,
|
|
65213
|
+
sharePrice: perShare,
|
|
65214
|
+
sharePriceUsd: priced ? num(m.sharePrice, perShare * price) : 0,
|
|
65215
|
+
yieldProfile: "yield-bearing",
|
|
65216
|
+
denomination: denominationOf({
|
|
65217
|
+
symbol: listed3?.symbol,
|
|
65218
|
+
props: listed3?.props
|
|
65219
|
+
}),
|
|
65220
|
+
logoURI: listedShare?.logoURI ?? listed3?.logoURI,
|
|
65221
|
+
fee: s.performanceFeeBps / 100,
|
|
65222
|
+
managementFeePct: s.managementFeeBps / 100,
|
|
65223
|
+
withdrawalMode: "instant-capped",
|
|
65224
|
+
instantLiquidityRatio: totalAssetsRaw > 0n ? Math.min(1, Number(idleRaw * 1000000n / totalAssetsRaw) / 1e6) : 1,
|
|
65225
|
+
apy,
|
|
65226
|
+
holders: m.numberOfHolders ?? 0,
|
|
65227
|
+
vaultFarm: s.vaultFarm && s.vaultFarm !== "11111111111111111111111111111111" ? s.vaultFarm : void 0,
|
|
65228
|
+
allocations: (s.vaultAllocationStrategy ?? []).filter((a) => a.reserve !== "11111111111111111111111111111111").map((a) => ({
|
|
65229
|
+
reserve: a.reserve,
|
|
65230
|
+
weight: a.targetAllocationWeight,
|
|
65231
|
+
ctokenAllocation: a.ctokenAllocation
|
|
65232
|
+
})),
|
|
65233
|
+
createdAt: s.creationTimestamp,
|
|
65234
|
+
minDepositAmount: s.minDepositAmount
|
|
65235
|
+
};
|
|
65236
|
+
}
|
|
65237
|
+
async function fetchKaminoKvaults(opts = {}) {
|
|
65238
|
+
const api = createKaminoKvaultApi(opts);
|
|
65239
|
+
const [vaults, metrics] = await Promise.all([
|
|
65240
|
+
opts.vaults ?? api.vaults(),
|
|
65241
|
+
opts.metrics ?? api.metrics()
|
|
65242
|
+
]);
|
|
65243
|
+
const byVault = /* @__PURE__ */ new Map();
|
|
65244
|
+
for (const m of metrics) if (m.kvault) byVault.set(m.kvault, m);
|
|
65245
|
+
const out = [];
|
|
65246
|
+
const skipped = [];
|
|
65247
|
+
for (const v of vaults) {
|
|
65248
|
+
if (!opts.includeEmpty && BigInt(v.state.sharesIssued || "0") === 0n)
|
|
65249
|
+
continue;
|
|
65250
|
+
const row = convertKaminoKvault(v, byVault.get(v.address), {
|
|
65251
|
+
tokenList: opts.tokenList
|
|
65252
|
+
});
|
|
65253
|
+
if (!row) {
|
|
65254
|
+
skipped.push(v.address);
|
|
65255
|
+
continue;
|
|
65256
|
+
}
|
|
65257
|
+
out.push(row);
|
|
65258
|
+
}
|
|
65259
|
+
if (skipped.length)
|
|
65260
|
+
console.warn(
|
|
65261
|
+
`[kamino-kvault] ${skipped.length} vault(s) skipped \u2014 no metrics row: ${skipped.join(", ")}`
|
|
65262
|
+
);
|
|
65263
|
+
return out;
|
|
65264
|
+
}
|
|
65265
|
+
|
|
63345
65266
|
// src/vaults/lst/fetchPublic.ts
|
|
63346
65267
|
import { createSvmRpc as createSvmRpc6, WRAPPED_SOL } from "@1delta/svm-kit";
|
|
63347
65268
|
var LAMPORTS_PER_SOL = 10 ** 9;
|
|
@@ -63360,7 +65281,7 @@ var SPL_STAKE_POOL_LSTS = [
|
|
|
63360
65281
|
curatorName: "SolBlaze"
|
|
63361
65282
|
}
|
|
63362
65283
|
];
|
|
63363
|
-
var
|
|
65284
|
+
var SECONDS_PER_YEAR4 = 365.25 * 86400;
|
|
63364
65285
|
function epochRealizedApr(pool, epochSeconds) {
|
|
63365
65286
|
if (pool.lastEpochTotalLamports === void 0 || !pool.lastEpochPoolTokenSupply || pool.poolTokenSupply === 0n || epochSeconds <= 0)
|
|
63366
65287
|
return void 0;
|
|
@@ -63370,7 +65291,7 @@ function epochRealizedApr(pool, epochSeconds) {
|
|
|
63370
65291
|
const epochRate = now / last - 1;
|
|
63371
65292
|
return {
|
|
63372
65293
|
epochRatePercent: epochRate * 100,
|
|
63373
|
-
aprPercent: epochRate * (
|
|
65294
|
+
aprPercent: epochRate * (SECONDS_PER_YEAR4 / epochSeconds) * 100,
|
|
63374
65295
|
lastEpochExchangeRate: last
|
|
63375
65296
|
};
|
|
63376
65297
|
}
|
|
@@ -63657,6 +65578,9 @@ function loopscaleOriginRow(r) {
|
|
|
63657
65578
|
meta: {
|
|
63658
65579
|
vaultAccount: r.vaultAccount,
|
|
63659
65580
|
strategy: r.strategy,
|
|
65581
|
+
manager: r.manager,
|
|
65582
|
+
managerName: r.curatorName,
|
|
65583
|
+
managerImage: r.managerImage,
|
|
63660
65584
|
grossRate: r.grossRate,
|
|
63661
65585
|
venueApy: r.venueApy,
|
|
63662
65586
|
interestFee: r.fees.interest,
|
|
@@ -63681,6 +65605,42 @@ function loopscaleOriginRow(r) {
|
|
|
63681
65605
|
}
|
|
63682
65606
|
};
|
|
63683
65607
|
}
|
|
65608
|
+
function kaminoKvaultOriginRow(r) {
|
|
65609
|
+
return {
|
|
65610
|
+
...common4626(r, "kamino-kvault", "sync"),
|
|
65611
|
+
// kvaults publish no curator NAME: `r.curatorName` is the admin address,
|
|
65612
|
+
// and a brand column holding a base58 key would read as the desk's name on
|
|
65613
|
+
// /earn. The address travels as `meta.manager`; a label layer keyed by it
|
|
65614
|
+
// (lender-metadata curator-labels.json → curator_metadata) names it.
|
|
65615
|
+
curatorName: void 0,
|
|
65616
|
+
provider: "kamino-kvault",
|
|
65617
|
+
fee: r.fee,
|
|
65618
|
+
shareAsset: {
|
|
65619
|
+
chainId: r.chainId,
|
|
65620
|
+
address: r.shareMint,
|
|
65621
|
+
symbol: r.symbol,
|
|
65622
|
+
name: r.name,
|
|
65623
|
+
decimals: r.decimals
|
|
65624
|
+
},
|
|
65625
|
+
metaTable: "vault_kamino_kvault_meta",
|
|
65626
|
+
meta: {
|
|
65627
|
+
shareMint: r.shareMint,
|
|
65628
|
+
manager: r.manager,
|
|
65629
|
+
allocationAdmin: r.allocationAdmin,
|
|
65630
|
+
managementFeePct: r.managementFeePct,
|
|
65631
|
+
convertToAssets: r.convertToAssets,
|
|
65632
|
+
convertToShares: r.convertToShares,
|
|
65633
|
+
withdrawalMode: r.withdrawalMode,
|
|
65634
|
+
instantLiquidityRatio: r.instantLiquidityRatio,
|
|
65635
|
+
apy: r.apy,
|
|
65636
|
+
holders: r.holders,
|
|
65637
|
+
vaultFarm: r.vaultFarm,
|
|
65638
|
+
allocations: r.allocations,
|
|
65639
|
+
createdAt: r.createdAt,
|
|
65640
|
+
minDepositAmount: r.minDepositAmount
|
|
65641
|
+
}
|
|
65642
|
+
};
|
|
65643
|
+
}
|
|
63684
65644
|
function exponentOriginRow(r) {
|
|
63685
65645
|
return {
|
|
63686
65646
|
provider: "exponent",
|
|
@@ -63728,6 +65688,8 @@ function toOriginVaultRow(r) {
|
|
|
63728
65688
|
return jupiterLendOriginRow(r);
|
|
63729
65689
|
case "loopscale":
|
|
63730
65690
|
return loopscaleOriginRow(r);
|
|
65691
|
+
case "kamino-kvault":
|
|
65692
|
+
return kaminoKvaultOriginRow(r);
|
|
63731
65693
|
}
|
|
63732
65694
|
}
|
|
63733
65695
|
|
|
@@ -63893,21 +65855,66 @@ async function fetchJupiterLendOracleEntries(opts = {}) {
|
|
|
63893
65855
|
}
|
|
63894
65856
|
|
|
63895
65857
|
// src/prices/oracle-prices/fetchers/save.ts
|
|
65858
|
+
import { createSvmRpc as createSvmRpc7 } from "@1delta/svm-kit";
|
|
63896
65859
|
async function fetchSaveOracleEntries(opts = {}) {
|
|
63897
65860
|
const res = opts.publicData ?? await fetchSavePublic(opts);
|
|
65861
|
+
const feeds = /* @__PURE__ */ new Set();
|
|
65862
|
+
for (const bundle of Object.values(res))
|
|
65863
|
+
for (const row of Object.values(bundle.data)) {
|
|
65864
|
+
if (row.save.pythOracle) feeds.add(row.save.pythOracle);
|
|
65865
|
+
if (row.save.switchboardOracle) feeds.add(row.save.switchboardOracle);
|
|
65866
|
+
}
|
|
65867
|
+
const readings = /* @__PURE__ */ new Map();
|
|
65868
|
+
if (opts.live !== false && feeds.size) {
|
|
65869
|
+
try {
|
|
65870
|
+
const rpc = opts.rpc ?? createSvmRpc7();
|
|
65871
|
+
const keys = [...feeds];
|
|
65872
|
+
const { accounts } = await rpc.readAccounts(keys, { encoding: "base64" });
|
|
65873
|
+
accounts.forEach((a, i) => {
|
|
65874
|
+
if (!a) return;
|
|
65875
|
+
try {
|
|
65876
|
+
const r = decodeOracleFeed({ owner: a.owner, data: a.data[0] });
|
|
65877
|
+
if (r && Number.isFinite(r.price) && r.price > 0)
|
|
65878
|
+
readings.set(keys[i], r);
|
|
65879
|
+
} catch (e) {
|
|
65880
|
+
console.warn(`[save] feed ${keys[i]}: ${e.message}`);
|
|
65881
|
+
}
|
|
65882
|
+
});
|
|
65883
|
+
} catch (e) {
|
|
65884
|
+
console.warn(
|
|
65885
|
+
`[save] live feeds not read, serving stored reserve prices: ${e.message}`
|
|
65886
|
+
);
|
|
65887
|
+
}
|
|
65888
|
+
}
|
|
63898
65889
|
const out = {};
|
|
63899
65890
|
for (const [lender, bundle] of Object.entries(res)) {
|
|
63900
65891
|
out[lender] = Object.entries(bundle.data).map(([marketUid, row]) => {
|
|
63901
65892
|
const s = row.save;
|
|
65893
|
+
const bps = s.scaledPriceOffsetBps;
|
|
65894
|
+
const dial = bps !== 0 ? ` \xD7 (1 + ${bps} bps dial)` : "";
|
|
65895
|
+
const candidates = [s.pythOracle, s.switchboardOracle].filter((k) => !!k && readings.has(k)).map((k) => ({ feed: k, r: readings.get(k) })).sort((a, b) => b.r.updatedAt - a.r.updatedAt);
|
|
65896
|
+
const pick = candidates[0];
|
|
65897
|
+
if (pick) {
|
|
65898
|
+
const price = pick.r.price * (1 + bps / 1e4);
|
|
65899
|
+
return {
|
|
65900
|
+
asset: row.underlying,
|
|
65901
|
+
price,
|
|
65902
|
+
priceUSD: price,
|
|
65903
|
+
marketUid,
|
|
65904
|
+
description: `Save reserve oracle \xB7 ${pick.r.kind}${dial} (live feed read)`,
|
|
65905
|
+
derivation: dial ? "derived" : "direct",
|
|
65906
|
+
feedSource: pick.feed,
|
|
65907
|
+
feedUpdatedAt: pick.r.updatedAt > 0 ? pick.r.updatedAt : void 0
|
|
65908
|
+
};
|
|
65909
|
+
}
|
|
63902
65910
|
const feed = s.pythOracle ?? s.switchboardOracle ?? s.extraOracle;
|
|
63903
65911
|
const kind = s.pythOracle ? "pyth-pull" : s.switchboardOracle ? "switchboard-on-demand" : "extra";
|
|
63904
|
-
const dial = s.scaledPriceOffsetBps !== 0 ? ` \xD7 (1 + ${s.scaledPriceOffsetBps} bps dial)` : "";
|
|
63905
65912
|
return {
|
|
63906
65913
|
asset: row.underlying,
|
|
63907
65914
|
price: s.priceUsd,
|
|
63908
65915
|
priceUSD: s.priceUsd,
|
|
63909
65916
|
marketUid,
|
|
63910
|
-
description: `Save reserve price \xB7 ${kind}${dial} \xB7 slot ${s.lastUpdateSlot}${s.stale ? " (stale)" : ""}`,
|
|
65917
|
+
description: `Save reserve price (stored) \xB7 ${kind}${dial} \xB7 slot ${s.lastUpdateSlot}${s.stale ? " (stale)" : ""}`,
|
|
63911
65918
|
derivation: dial ? "derived" : "direct",
|
|
63912
65919
|
feedSource: feed
|
|
63913
65920
|
};
|
|
@@ -63967,16 +65974,19 @@ async function fetchProject0OracleEntries(opts = {}) {
|
|
|
63967
65974
|
for (const [lender, bundle] of Object.entries(res)) {
|
|
63968
65975
|
out[lender] = Object.entries(bundle.data).filter(([, row]) => row.p0.price.source !== "none").map(([marketUid, row]) => {
|
|
63969
65976
|
const p = row.p0.price;
|
|
63970
|
-
|
|
65977
|
+
const fixed = p.source === "fixed";
|
|
65978
|
+
const entry = {
|
|
63971
65979
|
asset: row.underlying,
|
|
63972
65980
|
price: p.priceUsd,
|
|
63973
65981
|
priceUSD: p.priceUsd,
|
|
63974
65982
|
marketUid,
|
|
63975
65983
|
description: `Project 0 \xB7 ${p.description ?? p.source}`,
|
|
63976
|
-
derivation: p.source === "pyth-push"
|
|
65984
|
+
derivation: p.source === "pyth-push" || p.source === "scope" || fixed ? "direct" : "derived",
|
|
63977
65985
|
feedSource: p.feed,
|
|
63978
65986
|
feedUpdatedAt: p.updatedAt
|
|
63979
65987
|
};
|
|
65988
|
+
if (fixed) entry.staticBase = true;
|
|
65989
|
+
return entry;
|
|
63980
65990
|
});
|
|
63981
65991
|
}
|
|
63982
65992
|
return out;
|
|
@@ -63987,14 +65997,15 @@ async function fetchOraclePrices(chainIds, opts = {}) {
|
|
|
63987
65997
|
const FETCHERS = {
|
|
63988
65998
|
kamino: (chainId) => chainId === SOLANA_CHAIN_ID ? fetchKaminoOracleEntries(opts.overrides, opts) : Promise.resolve({}),
|
|
63989
65999
|
"jupiter-lend": (chainId) => chainId === SOLANA_CHAIN_ID ? fetchJupiterLendOracleEntries(opts) : Promise.resolve({}),
|
|
63990
|
-
save: (chainId) => chainId === SOLANA_CHAIN_ID ? fetchSaveOracleEntries({ timeoutMs: opts.timeoutMs }) : Promise.resolve({}),
|
|
66000
|
+
save: (chainId) => chainId === SOLANA_CHAIN_ID ? fetchSaveOracleEntries({ timeoutMs: opts.timeoutMs, rpc: opts.rpc }) : Promise.resolve({}),
|
|
63991
66001
|
loopscale: (chainId) => chainId === SOLANA_CHAIN_ID ? fetchLoopscaleOracleEntries({
|
|
63992
66002
|
timeoutMs: opts.timeoutMs,
|
|
63993
66003
|
tokenList: opts.tokenList
|
|
63994
66004
|
}) : Promise.resolve({}),
|
|
63995
66005
|
project0: (chainId) => chainId === SOLANA_CHAIN_ID ? fetchProject0OracleEntries({
|
|
63996
66006
|
timeoutMs: opts.timeoutMs,
|
|
63997
|
-
tokenList: opts.tokenList
|
|
66007
|
+
tokenList: opts.tokenList,
|
|
66008
|
+
...opts.rpc ? { rpc: opts.rpc } : {}
|
|
63998
66009
|
}) : Promise.resolve({})
|
|
63999
66010
|
};
|
|
64000
66011
|
const names = opts.onlyFetchers?.length ? opts.onlyFetchers : Object.keys(FETCHERS);
|
|
@@ -64275,10 +66286,10 @@ async function mintToReserve(api, market) {
|
|
|
64275
66286
|
// src/lending/user-data/kamino/onchain.ts
|
|
64276
66287
|
import {
|
|
64277
66288
|
createSvmFetchers as createSvmFetchers2,
|
|
64278
|
-
createSvmRpc as
|
|
64279
|
-
decodeIdlAccount as
|
|
66289
|
+
createSvmRpc as createSvmRpc8,
|
|
66290
|
+
decodeIdlAccount as decodeIdlAccount8,
|
|
64280
66291
|
encodeBase58 as encodeBase586,
|
|
64281
|
-
fromBase64 as
|
|
66292
|
+
fromBase64 as fromBase6414
|
|
64282
66293
|
} from "@1delta/svm-kit";
|
|
64283
66294
|
var KLEND_OBLIGATION_SIZE = 3344;
|
|
64284
66295
|
var KLEND_OBLIGATION_DISCRIMINATOR = [
|
|
@@ -64297,7 +66308,7 @@ var SF = 60n;
|
|
|
64297
66308
|
var bsf = (b) => b.value.reduce((a, w, i) => a + (BigInt(w) << 64n * BigInt(i)), 0n);
|
|
64298
66309
|
var sfToNumber = (x) => Number(x >> 30n) / 2 ** 30;
|
|
64299
66310
|
function decodeKaminoObligation(address, data) {
|
|
64300
|
-
const o =
|
|
66311
|
+
const o = decodeIdlAccount8(KLEND_IDL, "Obligation", data);
|
|
64301
66312
|
return {
|
|
64302
66313
|
address,
|
|
64303
66314
|
owner: o.owner,
|
|
@@ -64325,7 +66336,7 @@ function decodeKaminoObligation(address, data) {
|
|
|
64325
66336
|
};
|
|
64326
66337
|
}
|
|
64327
66338
|
function decodeKaminoReserveState(reserve, data) {
|
|
64328
|
-
const r =
|
|
66339
|
+
const r = decodeIdlAccount8(KLEND_IDL, "Reserve", data);
|
|
64329
66340
|
const l = r.liquidity;
|
|
64330
66341
|
const totalSf = klendTotalSupplySf({
|
|
64331
66342
|
availableAmount: BigInt(l.totalAvailableAmount),
|
|
@@ -64394,7 +66405,7 @@ function valueKaminoObligations(account, obligations, reserves, groups = {}, acc
|
|
|
64394
66405
|
obligation: o.address,
|
|
64395
66406
|
reason: `elevation group ${o.elevationGroup} terms not read \u2014 health uses the reserves' own LT`
|
|
64396
66407
|
});
|
|
64397
|
-
const
|
|
66408
|
+
const view2 = {
|
|
64398
66409
|
address: o.address,
|
|
64399
66410
|
market: o.market,
|
|
64400
66411
|
lenderKey,
|
|
@@ -64425,7 +66436,7 @@ function valueKaminoObligations(account, obligations, reserves, groups = {}, acc
|
|
|
64425
66436
|
const units = depositUnits(d2.cTokens, s);
|
|
64426
66437
|
const amount = Number(units);
|
|
64427
66438
|
const uid = createMarketUid(SOLANA_CHAIN_ID, lenderKey, d2.reserve);
|
|
64428
|
-
|
|
66439
|
+
view2.deposits.push({
|
|
64429
66440
|
reserve: d2.reserve,
|
|
64430
66441
|
marketUid: uid,
|
|
64431
66442
|
mint: s.mint,
|
|
@@ -64433,10 +66444,10 @@ function valueKaminoObligations(account, obligations, reserves, groups = {}, acc
|
|
|
64433
66444
|
amount,
|
|
64434
66445
|
amountUsd: amount * s.priceUsd
|
|
64435
66446
|
});
|
|
64436
|
-
|
|
64437
|
-
|
|
66447
|
+
view2.asOfSlot = Math.min(view2.asOfSlot, s.lastUpdateSlot);
|
|
66448
|
+
view2.depositedValueUsd += amount * s.priceUsd;
|
|
64438
66449
|
const lt = group?.liquidationThreshold ?? s.liquidationThresholdPct;
|
|
64439
|
-
|
|
66450
|
+
view2.unhealthyBorrowValueUsd += amount * s.priceUsd * lt / 100;
|
|
64440
66451
|
const p = leg(uid);
|
|
64441
66452
|
p.deposits = units;
|
|
64442
66453
|
p.depositsUSD = amount * s.priceUsd;
|
|
@@ -64459,7 +66470,7 @@ function valueKaminoObligations(account, obligations, reserves, groups = {}, acc
|
|
|
64459
66470
|
const units = debtUnits(debtSf, s);
|
|
64460
66471
|
const amount = Number(units);
|
|
64461
66472
|
const uid = createMarketUid(SOLANA_CHAIN_ID, lenderKey, b.reserve);
|
|
64462
|
-
|
|
66473
|
+
view2.borrows.push({
|
|
64463
66474
|
reserve: b.reserve,
|
|
64464
66475
|
marketUid: uid,
|
|
64465
66476
|
mint: s.mint,
|
|
@@ -64467,17 +66478,17 @@ function valueKaminoObligations(account, obligations, reserves, groups = {}, acc
|
|
|
64467
66478
|
amount,
|
|
64468
66479
|
amountUsd: amount * s.priceUsd
|
|
64469
66480
|
});
|
|
64470
|
-
|
|
64471
|
-
|
|
66481
|
+
view2.asOfSlot = Math.min(view2.asOfSlot, s.lastUpdateSlot);
|
|
66482
|
+
view2.bfAdjustedDebtUsd += amount * s.priceUsd * (o.elevationGroup ? 100 : Math.max(100, s.borrowFactorPct)) / 100;
|
|
64472
66483
|
const p = leg(uid);
|
|
64473
66484
|
p.debt = units;
|
|
64474
66485
|
p.debtUSD = amount * s.priceUsd;
|
|
64475
66486
|
p.debtUSDOracle = amount * s.priceUsd;
|
|
64476
66487
|
}
|
|
64477
|
-
if (
|
|
64478
|
-
if (
|
|
64479
|
-
|
|
64480
|
-
views.push(
|
|
66488
|
+
if (view2.asOfSlot === Infinity) view2.asOfSlot = o.lastUpdateSlot;
|
|
66489
|
+
if (view2.bfAdjustedDebtUsd > 0)
|
|
66490
|
+
view2.healthFactor = view2.unhealthyBorrowValueUsd / view2.bfAdjustedDebtUsd;
|
|
66491
|
+
views.push(view2);
|
|
64481
66492
|
bucket.lendingPositions[o.address] = legs;
|
|
64482
66493
|
bucket.modes[o.address] = String(o.elevationGroup);
|
|
64483
66494
|
bucket.accounts[o.address] = accounts[o.address] ?? {
|
|
@@ -64498,7 +66509,7 @@ function valueKaminoObligations(account, obligations, reserves, groups = {}, acc
|
|
|
64498
66509
|
};
|
|
64499
66510
|
}
|
|
64500
66511
|
async function fetchKaminoUserOnchain(account, opts = {}) {
|
|
64501
|
-
const rpc = opts.rpc ??
|
|
66512
|
+
const rpc = opts.rpc ?? createSvmRpc8();
|
|
64502
66513
|
const hits = await createSvmFetchers2(rpc).indexed.scanProgram(
|
|
64503
66514
|
KLEND_PROGRAM_ID,
|
|
64504
66515
|
[
|
|
@@ -64517,7 +66528,7 @@ async function fetchKaminoUserOnchain(account, opts = {}) {
|
|
|
64517
66528
|
}
|
|
64518
66529
|
);
|
|
64519
66530
|
const markets = opts.markets && new Set(opts.markets);
|
|
64520
|
-
const obligations = hits.map((h) => decodeKaminoObligation(h.pubkey,
|
|
66531
|
+
const obligations = hits.map((h) => decodeKaminoObligation(h.pubkey, fromBase6414(h.account.data[0]))).filter((o) => !markets || markets.has(o.market));
|
|
64521
66532
|
const reserves = { ...opts.reserves };
|
|
64522
66533
|
const need3 = [
|
|
64523
66534
|
...new Set(
|
|
@@ -64540,8 +66551,8 @@ async function fetchKaminoUserOnchain(account, opts = {}) {
|
|
|
64540
66551
|
const a = accounts2[i];
|
|
64541
66552
|
if (!a || a.owner !== KLEND_PROGRAM_ID) return;
|
|
64542
66553
|
if (i < need3.length)
|
|
64543
|
-
reserves[k] = decodeKaminoReserveState(k,
|
|
64544
|
-
else groups[k] = readKlendElevationGroups(
|
|
66554
|
+
reserves[k] = decodeKaminoReserveState(k, fromBase6414(a.data[0]));
|
|
66555
|
+
else groups[k] = readKlendElevationGroups(fromBase6414(a.data[0]));
|
|
64545
66556
|
});
|
|
64546
66557
|
}
|
|
64547
66558
|
const accounts = {};
|
|
@@ -64569,7 +66580,7 @@ async function fetchKaminoUserOnchain(account, opts = {}) {
|
|
|
64569
66580
|
|
|
64570
66581
|
// src/lending/user-data/jupiter-lend/fetchUser.ts
|
|
64571
66582
|
var isPositionId = (id) => typeof id === "number" && Number.isSafeInteger(id) && id > 0;
|
|
64572
|
-
var
|
|
66583
|
+
var big2 = (v) => {
|
|
64573
66584
|
try {
|
|
64574
66585
|
return BigInt(v ?? 0);
|
|
64575
66586
|
} catch {
|
|
@@ -64589,8 +66600,8 @@ function convertJupiterLendUserPositions(account, market, positions, vaults = /*
|
|
|
64589
66600
|
skip("liquidated");
|
|
64590
66601
|
continue;
|
|
64591
66602
|
}
|
|
64592
|
-
const supplyRaw =
|
|
64593
|
-
const borrowRaw =
|
|
66603
|
+
const supplyRaw = big2(p.supply);
|
|
66604
|
+
const borrowRaw = big2(p.borrow) + big2(p.dustBorrow);
|
|
64594
66605
|
if (supplyRaw === 0n && borrowRaw === 0n) {
|
|
64595
66606
|
skip("empty");
|
|
64596
66607
|
continue;
|
|
@@ -64684,7 +66695,7 @@ async function fetchJupiterLendUser(account, opts = {}) {
|
|
|
64684
66695
|
ext.borrowPositions[market] = borrows;
|
|
64685
66696
|
ext.earnPositions[market] = earns;
|
|
64686
66697
|
const needsRoster = borrows.some(
|
|
64687
|
-
(p) => !p.isLiquidated && (
|
|
66698
|
+
(p) => !p.isLiquidated && (big2(p.supply) > 0n || big2(p.borrow) + big2(p.dustBorrow) > 0n) && !(p.vault && p.vault.id === p.vaultId)
|
|
64688
66699
|
);
|
|
64689
66700
|
const roster = needsRoster ? new Map((await api.vaults(market)).map((v) => [v.id, v])) : void 0;
|
|
64690
66701
|
const conv = convertJupiterLendUserPositions(
|
|
@@ -64701,7 +66712,7 @@ async function fetchJupiterLendUser(account, opts = {}) {
|
|
|
64701
66712
|
}
|
|
64702
66713
|
|
|
64703
66714
|
// src/lending/user-data/save/obligation.ts
|
|
64704
|
-
import { BorshReader as BorshReader2, decodeBase58 as
|
|
66715
|
+
import { BorshReader as BorshReader2, decodeBase58 as decodeBase587, encodeBase58 as encodeBase587 } from "@1delta/svm-kit";
|
|
64705
66716
|
function decodeSaveObligation(address, data) {
|
|
64706
66717
|
if (data.length !== SAVE_OBLIGATION_SIZE)
|
|
64707
66718
|
throw new Error(
|
|
@@ -64770,10 +66781,10 @@ function saveObligationSeed(lendingMarket, index = 0) {
|
|
|
64770
66781
|
throw new Error(`save obligation index out of range: ${index}`);
|
|
64771
66782
|
return lendingMarket.slice(0, 24) + String(index).padStart(6, "0") + "m";
|
|
64772
66783
|
}
|
|
64773
|
-
var sha256 = async (
|
|
66784
|
+
var sha256 = async (bytes2) => new Uint8Array(await crypto.subtle.digest("SHA-256", bytes2));
|
|
64774
66785
|
async function createWithSeed(base, seed, programId) {
|
|
64775
|
-
const b =
|
|
64776
|
-
const p =
|
|
66786
|
+
const b = decodeBase587(base);
|
|
66787
|
+
const p = decodeBase587(programId);
|
|
64777
66788
|
if (!b || b.length !== 32) throw new Error(`not a pubkey: ${base}`);
|
|
64778
66789
|
if (!p || p.length !== 32) throw new Error(`not a pubkey: ${programId}`);
|
|
64779
66790
|
const s = new TextEncoder().encode(seed);
|
|
@@ -64788,23 +66799,23 @@ var saveObligationAddress = (wallet, lendingMarket, index = 0, programId = SAVE_
|
|
|
64788
66799
|
|
|
64789
66800
|
// src/lending/user-data/save/fetchUser.ts
|
|
64790
66801
|
import {
|
|
64791
|
-
createSvmRpc as
|
|
66802
|
+
createSvmRpc as createSvmRpc9,
|
|
64792
66803
|
encodeBase58 as encodeBase588,
|
|
64793
|
-
fromBase64 as
|
|
66804
|
+
fromBase64 as fromBase6415,
|
|
64794
66805
|
getAssociatedTokenAddress as getAssociatedTokenAddress4,
|
|
64795
66806
|
TOKEN_PROGRAM as TOKEN_PROGRAM3
|
|
64796
66807
|
} from "@1delta/svm-kit";
|
|
64797
66808
|
var SAVE_WALLET_POS_ID = "wallet";
|
|
64798
|
-
var readTokenAmount = (
|
|
64799
|
-
if (
|
|
64800
|
-
if (encodeBase588(
|
|
66809
|
+
var readTokenAmount = (bytes2, mint) => {
|
|
66810
|
+
if (bytes2.length < 72) return void 0;
|
|
66811
|
+
if (encodeBase588(bytes2.subarray(0, 32)) !== mint) return void 0;
|
|
64801
66812
|
let v = 0n;
|
|
64802
|
-
for (let i = 71; i >= 64; i--) v = v << 8n | BigInt(
|
|
66813
|
+
for (let i = 71; i >= 64; i--) v = v << 8n | BigInt(bytes2[i]);
|
|
64803
66814
|
return v;
|
|
64804
66815
|
};
|
|
64805
66816
|
async function fetchSaveUser(account, opts = {}) {
|
|
64806
66817
|
const api = createSaveApi(opts);
|
|
64807
|
-
const rpc = opts.rpc ??
|
|
66818
|
+
const rpc = opts.rpc ?? createSvmRpc9();
|
|
64808
66819
|
const configs = opts.configs ?? await api.marketConfigs();
|
|
64809
66820
|
const markets = selectSaveMarkets(configs, opts);
|
|
64810
66821
|
const step = Math.min(
|
|
@@ -64860,9 +66871,9 @@ async function fetchSaveUser(account, opts = {}) {
|
|
|
64860
66871
|
const exists = !!a && a.owner === SAVE_PROGRAM_ID && typeof a.data?.[0] === "string";
|
|
64861
66872
|
(probed[key2] ??= []).push({ index: c.index, address: c.address, exists });
|
|
64862
66873
|
if (!exists) return;
|
|
64863
|
-
const
|
|
64864
|
-
if (
|
|
64865
|
-
found.push({ c, ob: decodeSaveObligation(c.address,
|
|
66874
|
+
const bytes2 = fromBase6415(a.data[0]);
|
|
66875
|
+
if (bytes2.length !== SAVE_OBLIGATION_SIZE) return;
|
|
66876
|
+
found.push({ c, ob: decodeSaveObligation(c.address, bytes2) });
|
|
64866
66877
|
});
|
|
64867
66878
|
if (extend)
|
|
64868
66879
|
for (const c of pending) {
|
|
@@ -64883,7 +66894,7 @@ async function fetchSaveUser(account, opts = {}) {
|
|
|
64883
66894
|
const a = ataAccounts[i];
|
|
64884
66895
|
if (!a || a.owner !== TOKEN_PROGRAM3 || typeof a.data?.[0] !== "string")
|
|
64885
66896
|
return;
|
|
64886
|
-
const amount = readTokenAmount(
|
|
66897
|
+
const amount = readTokenAmount(fromBase6415(a.data[0]), c.cTokenMint);
|
|
64887
66898
|
if (amount && amount > 0n) wallet.push({ c, cTokens: amount });
|
|
64888
66899
|
});
|
|
64889
66900
|
const reserveIds = [
|
|
@@ -64951,7 +66962,7 @@ async function fetchSaveUser(account, opts = {}) {
|
|
|
64951
66962
|
address: ob.address,
|
|
64952
66963
|
label: `#${c.index}`
|
|
64953
66964
|
};
|
|
64954
|
-
const
|
|
66965
|
+
const view2 = {
|
|
64955
66966
|
address: ob.address,
|
|
64956
66967
|
market: c.market.address,
|
|
64957
66968
|
lenderKey,
|
|
@@ -64994,13 +67005,13 @@ async function fetchSaveUser(account, opts = {}) {
|
|
|
64994
67005
|
});
|
|
64995
67006
|
continue;
|
|
64996
67007
|
}
|
|
64997
|
-
const
|
|
67008
|
+
const dec2 = s.reserve.liquidity.mintDecimals;
|
|
64998
67009
|
const raw2 = d2.depositedAmount * saveExchangeRateWad(s.reserve) / SAVE_WAD;
|
|
64999
|
-
const amountStr = scaledToDecimal(raw2,
|
|
67010
|
+
const amountStr = scaledToDecimal(raw2, dec2);
|
|
65000
67011
|
const amount = Number(amountStr);
|
|
65001
67012
|
const price = wadToNumber(s.reserve.liquidity.marketPrice);
|
|
65002
67013
|
const usd = amount * price;
|
|
65003
|
-
|
|
67014
|
+
view2.deposits.push({
|
|
65004
67015
|
reserve: d2.reserve,
|
|
65005
67016
|
marketUid: uid,
|
|
65006
67017
|
mint: s.reserve.liquidity.mintPubkey,
|
|
@@ -65009,10 +67020,10 @@ async function fetchSaveUser(account, opts = {}) {
|
|
|
65009
67020
|
amountUsd: usd,
|
|
65010
67021
|
served: !reason
|
|
65011
67022
|
});
|
|
65012
|
-
|
|
65013
|
-
|
|
65014
|
-
|
|
65015
|
-
|
|
67023
|
+
view2.depositedValueUsd += usd;
|
|
67024
|
+
view2.allowedBorrowValueUsd += usd * (s.reserve.config.loanToValueRatio / 100);
|
|
67025
|
+
view2.unhealthyBorrowValueUsd += usd * (s.reserve.config.liquidationThreshold / 100);
|
|
67026
|
+
view2.superUnhealthyBorrowValueUsd += usd * (s.reserve.config.maxLiquidationThreshold / 100);
|
|
65016
67027
|
if (reason) {
|
|
65017
67028
|
unserved.push({
|
|
65018
67029
|
lenderKey,
|
|
@@ -65052,18 +67063,18 @@ async function fetchSaveUser(account, opts = {}) {
|
|
|
65052
67063
|
});
|
|
65053
67064
|
continue;
|
|
65054
67065
|
}
|
|
65055
|
-
const
|
|
67066
|
+
const dec2 = s.reserve.liquidity.mintDecimals;
|
|
65056
67067
|
const price = wadToNumber(s.reserve.liquidity.marketPrice);
|
|
65057
67068
|
const reserveIdx = BigInt(s.reserve.liquidity.cumulativeBorrowRateWads);
|
|
65058
67069
|
const legIdx = b.cumulativeBorrowRateWads;
|
|
65059
67070
|
const wads = legIdx > 0n ? b.borrowedAmountWads * reserveIdx / legIdx : b.borrowedAmountWads;
|
|
65060
|
-
const amountStr = scaledToDecimal(wads, 18 +
|
|
67071
|
+
const amountStr = scaledToDecimal(wads, 18 + dec2);
|
|
65061
67072
|
const amount = Number(amountStr);
|
|
65062
|
-
const atTouch = wadToNumber(b.borrowedAmountWads.toString()) / 10 **
|
|
67073
|
+
const atTouch = wadToNumber(b.borrowedAmountWads.toString()) / 10 ** dec2;
|
|
65063
67074
|
const usd = amount * price;
|
|
65064
67075
|
const addedBps = s.reserve.config.addedBorrowWeightBPS;
|
|
65065
67076
|
const weight = 1 + Number(addedBps) / 1e4;
|
|
65066
|
-
|
|
67077
|
+
view2.borrows.push({
|
|
65067
67078
|
reserve: b.reserve,
|
|
65068
67079
|
marketUid: uid,
|
|
65069
67080
|
mint: s.reserve.liquidity.mintPubkey,
|
|
@@ -65073,8 +67084,8 @@ async function fetchSaveUser(account, opts = {}) {
|
|
|
65073
67084
|
borrowWeight: weight,
|
|
65074
67085
|
served: !reason
|
|
65075
67086
|
});
|
|
65076
|
-
if (weight > 1e9 && wads > 0n)
|
|
65077
|
-
|
|
67087
|
+
if (weight > 1e9 && wads > 0n) view2.unboundedWeightDebt = true;
|
|
67088
|
+
view2.weightedBorrowValueUsd += usd * weight;
|
|
65078
67089
|
if (reason) {
|
|
65079
67090
|
unserved.push({
|
|
65080
67091
|
lenderKey,
|
|
@@ -65095,8 +67106,8 @@ async function fetchSaveUser(account, opts = {}) {
|
|
|
65095
67106
|
debtUSDOracle: usd
|
|
65096
67107
|
});
|
|
65097
67108
|
}
|
|
65098
|
-
|
|
65099
|
-
views.push(
|
|
67109
|
+
view2.healthFactor = view2.weightedBorrowValueUsd > 0 ? view2.unhealthyBorrowValueUsd / view2.weightedBorrowValueUsd : Infinity;
|
|
67110
|
+
views.push(view2);
|
|
65100
67111
|
}
|
|
65101
67112
|
const walletViews = [];
|
|
65102
67113
|
for (const { c, cTokens } of wallet) {
|
|
@@ -65104,10 +67115,10 @@ async function fetchSaveUser(account, opts = {}) {
|
|
|
65104
67115
|
const uid = createMarketUid(SOLANA_CHAIN_ID, lenderKey, c.reserve);
|
|
65105
67116
|
const s = states[c.reserve];
|
|
65106
67117
|
const reason = servedReason(c.reserve);
|
|
65107
|
-
const
|
|
67118
|
+
const dec2 = s?.reserve.liquidity.mintDecimals ?? 0;
|
|
65108
67119
|
const amountStr = s ? scaledToDecimal(
|
|
65109
67120
|
cTokens * saveExchangeRateWad(s.reserve) / SAVE_WAD,
|
|
65110
|
-
|
|
67121
|
+
dec2
|
|
65111
67122
|
) : "0";
|
|
65112
67123
|
const usd = s ? Number(amountStr) * wadToNumber(s.reserve.liquidity.marketPrice) : 0;
|
|
65113
67124
|
walletViews.push({
|
|
@@ -65163,11 +67174,11 @@ async function fetchSaveUser(account, opts = {}) {
|
|
|
65163
67174
|
}
|
|
65164
67175
|
|
|
65165
67176
|
// src/lending/user-data/loopscale/fetchUser.ts
|
|
65166
|
-
import { createSvmRpc as
|
|
67177
|
+
import { createSvmRpc as createSvmRpc10, getMints as getMints2 } from "@1delta/svm-kit";
|
|
65167
67178
|
var shortAddr = (a) => `${a.slice(0, 4)}\u2026${a.slice(-4)}`;
|
|
65168
67179
|
function convertLoopscaleUser(account, items, opts) {
|
|
65169
67180
|
const now = opts.now ?? Math.floor(Date.now() / 1e3);
|
|
65170
|
-
const
|
|
67181
|
+
const dec2 = (mint) => opts.decimals[mint];
|
|
65171
67182
|
const positions = {};
|
|
65172
67183
|
const loans = [];
|
|
65173
67184
|
const skipped = [];
|
|
@@ -65178,7 +67189,7 @@ function convertLoopscaleUser(account, items, opts) {
|
|
|
65178
67189
|
...it.ledgers.map((l) => l.principalMint),
|
|
65179
67190
|
...it.collateral.map((c) => c.assetMint)
|
|
65180
67191
|
]);
|
|
65181
|
-
const missing = [...mints].filter((m) =>
|
|
67192
|
+
const missing = [...mints].filter((m) => dec2(m) === void 0);
|
|
65182
67193
|
if (missing.length) {
|
|
65183
67194
|
if (!it.loan.closed)
|
|
65184
67195
|
skipped.push({
|
|
@@ -65187,7 +67198,7 @@ function convertLoopscaleUser(account, items, opts) {
|
|
|
65187
67198
|
});
|
|
65188
67199
|
continue;
|
|
65189
67200
|
}
|
|
65190
|
-
const tok = (raw2, mint) => raw2 / 10 **
|
|
67201
|
+
const tok = (raw2, mint) => raw2 / 10 ** dec2(mint);
|
|
65191
67202
|
const ledgers = it.ledgers.map((l) => {
|
|
65192
67203
|
const d2 = { duration: l.duration, durationType: l.durationType };
|
|
65193
67204
|
const toMaturity = ledgerInterestAt(
|
|
@@ -65361,7 +67372,7 @@ async function fetchLoopscaleUser(account, opts = {}) {
|
|
|
65361
67372
|
];
|
|
65362
67373
|
if (unknown.length) {
|
|
65363
67374
|
try {
|
|
65364
|
-
const mints = await getMints2(opts.rpc ??
|
|
67375
|
+
const mints = await getMints2(opts.rpc ?? createSvmRpc10(), unknown);
|
|
65365
67376
|
mints.forEach((m, i) => {
|
|
65366
67377
|
if (m) decimals[unknown[i]] = m.decimals;
|
|
65367
67378
|
});
|
|
@@ -65382,12 +67393,12 @@ async function fetchLoopscaleUser(account, opts = {}) {
|
|
|
65382
67393
|
// src/lending/user-data/project0/fetchUser.ts
|
|
65383
67394
|
import {
|
|
65384
67395
|
createSvmFetchers as createSvmFetchers3,
|
|
65385
|
-
createSvmRpc as
|
|
67396
|
+
createSvmRpc as createSvmRpc11,
|
|
65386
67397
|
encodeBase58 as encodeBase589
|
|
65387
67398
|
} from "@1delta/svm-kit";
|
|
65388
67399
|
var flagOn = (flags, bit) => (BigInt(flags) & bit) !== 0n;
|
|
65389
67400
|
async function fetchProject0User(account, opts = {}) {
|
|
65390
|
-
const rpc = opts.rpc ??
|
|
67401
|
+
const rpc = opts.rpc ?? createSvmRpc11();
|
|
65391
67402
|
const groups = opts.groups?.length ? opts.groups : [P0_MAIN_GROUP];
|
|
65392
67403
|
const pub = opts.publicData ?? await fetchProject0Public({ ...opts, rpc, groups });
|
|
65393
67404
|
const found = [];
|
|
@@ -65495,7 +67506,7 @@ async function fetchProject0User(account, opts = {}) {
|
|
|
65495
67506
|
}).catch(() => void 0) === acc.address;
|
|
65496
67507
|
const label = isPda ? `#${acc.accountIndex}${acc.thirdPartyIndex ? ` \xB7 third party ${acc.thirdPartyIndex}` : ""}` : `keypair ${acc.address.slice(0, 4)}\u2026${acc.address.slice(-4)}`;
|
|
65497
67508
|
const emodeActive = /* @__PURE__ */ new Set();
|
|
65498
|
-
const
|
|
67509
|
+
const view2 = {
|
|
65499
67510
|
address: acc.address,
|
|
65500
67511
|
group,
|
|
65501
67512
|
lenderKey,
|
|
@@ -65527,7 +67538,7 @@ async function fetchProject0User(account, opts = {}) {
|
|
|
65527
67538
|
for (const b of active) {
|
|
65528
67539
|
const hit = rowsByBank.get(b.bank);
|
|
65529
67540
|
if (!hit) {
|
|
65530
|
-
|
|
67541
|
+
view2.incomplete = true;
|
|
65531
67542
|
unserved.push({
|
|
65532
67543
|
account: acc.address,
|
|
65533
67544
|
bank: b.bank,
|
|
@@ -65536,7 +67547,7 @@ async function fetchProject0User(account, opts = {}) {
|
|
|
65536
67547
|
liabilityShares: b.liabilityShares,
|
|
65537
67548
|
reason: !bundle ? "group not served" : meta?.droppedBanks.find((d2) => d2.bank === b.bank)?.reason ?? "not in the group roster"
|
|
65538
67549
|
});
|
|
65539
|
-
|
|
67550
|
+
view2.balances.push({
|
|
65540
67551
|
bank: b.bank,
|
|
65541
67552
|
mint: meta?.banks[b.bank]?.mint ?? "",
|
|
65542
67553
|
symbol: meta?.banks[b.bank]?.symbol ?? b.bank.slice(0, 4),
|
|
@@ -65580,7 +67591,7 @@ async function fetchProject0User(account, opts = {}) {
|
|
|
65580
67591
|
const lwMaint = p0.liabilityWeightMaint;
|
|
65581
67592
|
const depUsd = deposited * price;
|
|
65582
67593
|
const borUsd = borrowed * price;
|
|
65583
|
-
|
|
67594
|
+
view2.balances.push({
|
|
65584
67595
|
bank: b.bank,
|
|
65585
67596
|
marketUid: uid,
|
|
65586
67597
|
mint: row.underlying,
|
|
@@ -65599,10 +67610,10 @@ async function fetchProject0User(account, opts = {}) {
|
|
|
65599
67610
|
emissionsOutstanding: b.emissionsOutstanding,
|
|
65600
67611
|
unpriced: p0.price.source === "none"
|
|
65601
67612
|
});
|
|
65602
|
-
|
|
65603
|
-
|
|
65604
|
-
|
|
65605
|
-
|
|
67613
|
+
view2.assetValueInitUsd += depUsd * awInit;
|
|
67614
|
+
view2.assetValueMaintUsd += depUsd * awMaint;
|
|
67615
|
+
view2.liabilityValueInitUsd += borUsd * lwInit;
|
|
67616
|
+
view2.liabilityValueMaintUsd += borUsd * lwMaint;
|
|
65606
67617
|
legs[uid] = {
|
|
65607
67618
|
marketUid: uid,
|
|
65608
67619
|
deposits: p0DecimalString(deposited, row.decimals),
|
|
@@ -65616,13 +67627,13 @@ async function fetchProject0User(account, opts = {}) {
|
|
|
65616
67627
|
claimableRewards: 0
|
|
65617
67628
|
};
|
|
65618
67629
|
}
|
|
65619
|
-
|
|
65620
|
-
|
|
67630
|
+
view2.healthFactor = view2.liabilityValueMaintUsd > 0 ? view2.assetValueMaintUsd / view2.liabilityValueMaintUsd : Infinity;
|
|
67631
|
+
view2.freeCollateralUsd = Math.max(
|
|
65621
67632
|
0,
|
|
65622
|
-
|
|
67633
|
+
view2.assetValueInitUsd - view2.liabilityValueInitUsd
|
|
65623
67634
|
);
|
|
65624
|
-
|
|
65625
|
-
views.push(
|
|
67635
|
+
view2.emodeActive = [...emodeActive];
|
|
67636
|
+
views.push(view2);
|
|
65626
67637
|
if (!active.length) continue;
|
|
65627
67638
|
const out = positions[lenderKey] ??= {
|
|
65628
67639
|
chainId: SOLANA_CHAIN_ID,
|
|
@@ -65855,7 +67866,7 @@ function kaminoTermAdapter(row, market) {
|
|
|
65855
67866
|
if (row.originationFee === void 0)
|
|
65856
67867
|
pending["borrow.fees"] = "origination and flash-loan fees are in the reserve account, which was not read";
|
|
65857
67868
|
for (const p of market?.pending ?? []) pending[`market: ${p}`] = p;
|
|
65858
|
-
const
|
|
67869
|
+
const liq2 = market?.liquidation;
|
|
65859
67870
|
return {
|
|
65860
67871
|
profileId: KAMINO_PROFILE_ID,
|
|
65861
67872
|
borrow: {
|
|
@@ -65929,14 +67940,14 @@ function kaminoTermAdapter(row, market) {
|
|
|
65929
67940
|
debtWithdrawalCap: capExt(k.debtWithdrawalCap),
|
|
65930
67941
|
// remaining new debt outside any elevation group (`borrowLimitOutsideElevationGroup − tracked`)
|
|
65931
67942
|
debtCapacityOutsideGroups: base.debtCapacity,
|
|
65932
|
-
...
|
|
67943
|
+
...liq2 ? {
|
|
65933
67944
|
fullLiquidation: {
|
|
65934
67945
|
// obligation LTV above which the close factor is 100 %
|
|
65935
|
-
aboveLtv:
|
|
67946
|
+
aboveLtv: liq2.insolvencyRiskUnhealthyLtvPct / 100,
|
|
65936
67947
|
// a debt leg worth less than this is liquidated whole
|
|
65937
|
-
belowDebtValueUsd:
|
|
67948
|
+
belowDebtValueUsd: liq2.minFullLiquidationValueThresholdUsd,
|
|
65938
67949
|
// one liquidation repays at most this
|
|
65939
|
-
maxPerLiquidationUsd:
|
|
67950
|
+
maxPerLiquidationUsd: liq2.maxLiquidatableDebtMarketValueAtOnceUsd
|
|
65940
67951
|
}
|
|
65941
67952
|
} : {},
|
|
65942
67953
|
...k.pairIncentives.length ? { pairIncentives: k.pairIncentives } : {}
|
|
@@ -66801,9 +68812,12 @@ export {
|
|
|
66801
68812
|
HUMA_SEEDS,
|
|
66802
68813
|
HttpError,
|
|
66803
68814
|
JL_BPS,
|
|
68815
|
+
JL_EXCHANGE_PRICES_PRECISION,
|
|
66804
68816
|
JL_FACTOR_SCALE,
|
|
66805
68817
|
JL_ORACLE_DECIMALS,
|
|
66806
68818
|
JL_ORACLE_SCALE,
|
|
68819
|
+
JL_VAULTS_ACCOUNTS_IDL,
|
|
68820
|
+
JL_VAULT_AMOUNT_DECIMALS,
|
|
66807
68821
|
JUPITER_LEND_API_BASE,
|
|
66808
68822
|
JUPITER_LEND_KEYED_API_BASE,
|
|
66809
68823
|
JUPITER_LEND_KEY_PREFIX,
|
|
@@ -66812,9 +68826,11 @@ export {
|
|
|
66812
68826
|
JUPITER_LEND_PROGRAMS,
|
|
66813
68827
|
JUPITER_PRICE_API_BASE,
|
|
66814
68828
|
JUPITER_PRICE_KEYED_API_BASE,
|
|
68829
|
+
JUP_DEX_PROGRAM,
|
|
66815
68830
|
JUP_FLASHLOAN_IDL,
|
|
66816
68831
|
JUP_FLASHLOAN_PROGRAMS,
|
|
66817
68832
|
JUP_LIQUIDITY_PROGRAMS,
|
|
68833
|
+
JUP_VAULTS_PROGRAMS,
|
|
66818
68834
|
KAMINO_API_BASE,
|
|
66819
68835
|
KAMINO_KEY_PREFIX,
|
|
66820
68836
|
KAMINO_MAIN_MARKET,
|
|
@@ -66834,6 +68850,7 @@ export {
|
|
|
66834
68850
|
KLEND_RESERVE_SIZE,
|
|
66835
68851
|
KLEND_RESERVE_SLICE,
|
|
66836
68852
|
KLEND_U64_MAX,
|
|
68853
|
+
KVAULT_PROGRAM_ID,
|
|
66837
68854
|
LENDER_BRAND_NAMES,
|
|
66838
68855
|
LOANS_PAGE,
|
|
66839
68856
|
LOOPSCALE_ACCOUNT_DISCRIMINATORS,
|
|
@@ -66921,7 +68938,7 @@ export {
|
|
|
66921
68938
|
SAVE_UNBORROWABLE_BORROW_FACTOR,
|
|
66922
68939
|
SAVE_WAD,
|
|
66923
68940
|
SAVE_WALLET_POS_ID,
|
|
66924
|
-
SECONDS_PER_YEAR,
|
|
68941
|
+
SECONDS_PER_YEAR2 as SECONDS_PER_YEAR,
|
|
66925
68942
|
SETTLEMENT_BATCH_SIZE,
|
|
66926
68943
|
SOLANA_CHAIN_ID,
|
|
66927
68944
|
SOLSTICE_APP_API_BASE,
|
|
@@ -66964,6 +68981,7 @@ export {
|
|
|
66964
68981
|
convertJupiterLendOracleEntries,
|
|
66965
68982
|
convertJupiterLendUserPositions,
|
|
66966
68983
|
convertJupiterLendVault,
|
|
68984
|
+
convertKaminoKvault,
|
|
66967
68985
|
convertKaminoLoans,
|
|
66968
68986
|
convertKaminoMarket,
|
|
66969
68987
|
convertKaminoOraclePrices,
|
|
@@ -66980,6 +68998,7 @@ export {
|
|
|
66980
68998
|
createExponentApi,
|
|
66981
68999
|
createJupiterLendApi,
|
|
66982
69000
|
createKaminoApi,
|
|
69001
|
+
createKaminoKvaultApi,
|
|
66983
69002
|
createLimiter,
|
|
66984
69003
|
createLoopscaleApi,
|
|
66985
69004
|
createMarketUid,
|
|
@@ -66989,6 +69008,7 @@ export {
|
|
|
66989
69008
|
createSolsticeAppApi,
|
|
66990
69009
|
createWithSeed,
|
|
66991
69010
|
decimalStringToI80F48,
|
|
69011
|
+
decimalStringToRaw,
|
|
66992
69012
|
decodeAccountingState,
|
|
66993
69013
|
decodeController,
|
|
66994
69014
|
decodeCooldownEscrow,
|
|
@@ -66997,6 +69017,7 @@ export {
|
|
|
66997
69017
|
decodeHumaPoolConfig,
|
|
66998
69018
|
decodeHumaPoolState,
|
|
66999
69019
|
decodeHumaRedemptionRequest,
|
|
69020
|
+
decodeJlRateModel,
|
|
67000
69021
|
decodeJuniorUnlockShare,
|
|
67001
69022
|
decodeJupFlashloanAdmin,
|
|
67002
69023
|
decodeKaminoObligation,
|
|
@@ -67041,6 +69062,7 @@ export {
|
|
|
67041
69062
|
fetchJupiterLendPublic,
|
|
67042
69063
|
fetchJupiterLendUser,
|
|
67043
69064
|
fetchJupiterPrices,
|
|
69065
|
+
fetchKaminoKvaults,
|
|
67044
69066
|
fetchKaminoOracleEntries,
|
|
67045
69067
|
fetchKaminoOraclePrices,
|
|
67046
69068
|
fetchKaminoPublic,
|
|
@@ -67083,6 +69105,8 @@ export {
|
|
|
67083
69105
|
i80f48ToNumber,
|
|
67084
69106
|
isBorrowable,
|
|
67085
69107
|
isEvmChainId,
|
|
69108
|
+
isJlSmartCol,
|
|
69109
|
+
isJlSmartDebt,
|
|
67086
69110
|
isJupiterLend,
|
|
67087
69111
|
isKamino,
|
|
67088
69112
|
isLenderBrand,
|
|
@@ -67102,8 +69126,17 @@ export {
|
|
|
67102
69126
|
isSyntheticQuoteMint,
|
|
67103
69127
|
isU64Max,
|
|
67104
69128
|
isUncapped,
|
|
69129
|
+
jlLiquidityExchangePrices,
|
|
67105
69130
|
jlOraclePriceInBorrow,
|
|
67106
69131
|
jlOracleToFluidRaw,
|
|
69132
|
+
jlOverallTokenData,
|
|
69133
|
+
jlUserBorrowData,
|
|
69134
|
+
jlUserSupplyData,
|
|
69135
|
+
jlVaultAdminPda,
|
|
69136
|
+
jlVaultConfigPda,
|
|
69137
|
+
jlVaultExchangePrices,
|
|
69138
|
+
jlVaultStatePda,
|
|
69139
|
+
jlVaultToRaw,
|
|
67107
69140
|
joinableBatch,
|
|
67108
69141
|
juniorUnlockSharePda,
|
|
67109
69142
|
jupFlashBorrowPosition,
|
|
@@ -67122,6 +69155,7 @@ export {
|
|
|
67122
69155
|
kaminoCloseFactor,
|
|
67123
69156
|
kaminoDefaultEntry,
|
|
67124
69157
|
kaminoGroupLabel,
|
|
69158
|
+
kaminoKvaultOriginRow,
|
|
67125
69159
|
kaminoMarketFromKey,
|
|
67126
69160
|
kaminoMarketKey,
|
|
67127
69161
|
kaminoOracleEntriesFromMarkets,
|
|
@@ -67183,9 +69217,12 @@ export {
|
|
|
67183
69217
|
readHumaChainState,
|
|
67184
69218
|
readHumaLenderState,
|
|
67185
69219
|
readHumaRedemptionRequests,
|
|
69220
|
+
readJlLayerIrms,
|
|
69221
|
+
readJlNextVaultId,
|
|
67186
69222
|
readJupFlashAssets,
|
|
67187
69223
|
readJupFlashAvailable,
|
|
67188
69224
|
readJupFlashloanAdmin,
|
|
69225
|
+
readJupiterLendVaultsOnchain,
|
|
67189
69226
|
readKlendElevationGroups,
|
|
67190
69227
|
readKlendFlashFacts,
|
|
67191
69228
|
readKlendLendingMarket,
|