@1delta/margin-fetcher-sol 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -8792,260 +8792,842 @@ function createJupiterLendApi(opts = {}) {
8792
8792
  };
8793
8793
  }
8794
8794
 
8795
- // src/lending/public-data/jupiter-lend/convertPublic.ts
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
8795
+ // src/lending/public-data/jupiter-lend/onchain.ts
8796
+ import {
8797
+ decodeBase58 as decodeBase583,
8798
+ decodeIdlAccount as decodeIdlAccount3,
8799
+ findProgramAddress as findProgramAddress3,
8800
+ fromBase64 as fromBase643
8801
+ } from "@1delta/svm-kit";
8802
+
8803
+ // src/lending/public-data/jupiter-lend/idl/vaults-accounts.json
8804
+ var vaults_accounts_default = {
8805
+ address: "jupr81YtYssSyPt8jbnGuiWon5f6x9TcDEFxYe3Bdzi",
8806
+ metadata: {
8807
+ name: "vaults",
8808
+ version: "0.1.5",
8809
+ spec: "0.1.0",
8810
+ 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."
8811
+ },
8812
+ instructions: [],
8813
+ accounts: [
8814
+ {
8815
+ name: "Dex",
8816
+ discriminator: [
8817
+ 236,
8818
+ 30,
8819
+ 181,
8820
+ 80,
8821
+ 209,
8822
+ 217,
8823
+ 25,
8824
+ 163
8825
+ ]
8999
8826
  },
9000
- loan: {
9001
- assets: [{ underlying: bor.address, decimals: bor.decimals }],
9002
- dex: null,
9003
- perShare: null
8827
+ {
8828
+ name: "TokenReserve",
8829
+ discriminator: [
8830
+ 21,
8831
+ 18,
8832
+ 59,
8833
+ 135,
8834
+ 120,
8835
+ 20,
8836
+ 31,
8837
+ 12
8838
+ ]
8839
+ },
8840
+ {
8841
+ name: "UserBorrowPosition",
8842
+ discriminator: [
8843
+ 73,
8844
+ 126,
8845
+ 65,
8846
+ 123,
8847
+ 220,
8848
+ 126,
8849
+ 197,
8850
+ 24
8851
+ ]
8852
+ },
8853
+ {
8854
+ name: "UserSupplyPosition",
8855
+ discriminator: [
8856
+ 202,
8857
+ 219,
8858
+ 136,
8859
+ 118,
8860
+ 61,
8861
+ 177,
8862
+ 21,
8863
+ 146
8864
+ ]
8865
+ },
8866
+ {
8867
+ name: "VaultAdmin",
8868
+ discriminator: [
8869
+ 88,
8870
+ 97,
8871
+ 160,
8872
+ 117,
8873
+ 102,
8874
+ 39,
8875
+ 103,
8876
+ 44
8877
+ ]
8878
+ },
8879
+ {
8880
+ name: "VaultConfig",
8881
+ discriminator: [
8882
+ 99,
8883
+ 86,
8884
+ 43,
8885
+ 216,
8886
+ 184,
8887
+ 102,
8888
+ 119,
8889
+ 77
8890
+ ]
8891
+ },
8892
+ {
8893
+ name: "VaultState",
8894
+ discriminator: [
8895
+ 228,
8896
+ 196,
8897
+ 82,
8898
+ 165,
8899
+ 98,
8900
+ 210,
8901
+ 235,
8902
+ 152
8903
+ ]
8904
+ },
8905
+ {
8906
+ name: "Oracle",
8907
+ discriminator: [
8908
+ 139,
8909
+ 194,
8910
+ 131,
8911
+ 179,
8912
+ 140,
8913
+ 179,
8914
+ 229,
8915
+ 244
8916
+ ]
9004
8917
  }
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
- }
8918
+ ],
8919
+ types: [
8920
+ {
8921
+ name: "Dex",
8922
+ docs: [
8923
+ "Core DEX pool state. One per trading pair.",
8924
+ "Uses zero_copy for efficient access without deserialization overhead."
8925
+ ],
8926
+ serialization: "bytemuck",
8927
+ repr: {
8928
+ kind: "c",
8929
+ packed: true
8930
+ },
8931
+ type: {
8932
+ kind: "struct",
8933
+ fields: [
8934
+ {
8935
+ name: "dex_id",
8936
+ type: "u16"
8937
+ },
8938
+ {
8939
+ name: "re_entrancy",
8940
+ type: "u8"
8941
+ },
8942
+ {
8943
+ name: "token_0",
8944
+ type: "pubkey"
8945
+ },
8946
+ {
8947
+ name: "token_1",
8948
+ type: "pubkey"
8949
+ },
8950
+ {
8951
+ name: "token_0_decimals",
8952
+ type: "u8"
8953
+ },
8954
+ {
8955
+ name: "token_1_decimals",
8956
+ type: "u8"
8957
+ },
8958
+ {
8959
+ name: "last_to_last_stored_price",
8960
+ type: "u128"
8961
+ },
8962
+ {
8963
+ name: "last_stored_price",
8964
+ type: "u128"
8965
+ },
8966
+ {
8967
+ name: "center_price",
8968
+ type: "u128"
8969
+ },
8970
+ {
8971
+ name: "last_update_timestamp",
8972
+ type: "u64"
8973
+ },
8974
+ {
8975
+ name: "last_update_slot",
8976
+ type: "u64"
8977
+ },
8978
+ {
8979
+ name: "is_smart_collateral_enabled",
8980
+ type: "u8"
8981
+ },
8982
+ {
8983
+ name: "is_smart_debt_enabled",
8984
+ type: "u8"
8985
+ },
8986
+ {
8987
+ name: "fee",
8988
+ type: "u32"
8989
+ },
8990
+ {
8991
+ name: "revenue_cut",
8992
+ type: "u8"
8993
+ },
8994
+ {
8995
+ name: "percent_change_active",
8996
+ type: "u8"
8997
+ },
8998
+ {
8999
+ name: "upper_percent",
9000
+ type: "u32"
9001
+ },
9002
+ {
9003
+ name: "lower_percent",
9004
+ type: "u32"
9005
+ },
9006
+ {
9007
+ name: "threshold_change_active",
9008
+ type: "u8"
9009
+ },
9010
+ {
9011
+ name: "upper_shift_threshold_percent",
9012
+ type: "u16"
9013
+ },
9014
+ {
9015
+ name: "lower_shift_threshold_percent",
9016
+ type: "u16"
9017
+ },
9018
+ {
9019
+ name: "shifting_time",
9020
+ type: "u32"
9021
+ },
9022
+ {
9023
+ name: "center_price_address",
9024
+ type: "pubkey"
9025
+ },
9026
+ {
9027
+ name: "max_center_price",
9028
+ type: "u64"
9029
+ },
9030
+ {
9031
+ name: "min_center_price",
9032
+ type: "u64"
9033
+ },
9034
+ {
9035
+ name: "token_0_max_utilization",
9036
+ type: "u16"
9037
+ },
9038
+ {
9039
+ name: "token_1_max_utilization",
9040
+ type: "u16"
9041
+ },
9042
+ {
9043
+ name: "is_center_price_shift_active",
9044
+ type: "u8"
9045
+ },
9046
+ {
9047
+ name: "swap_and_arbitrage_paused",
9048
+ type: "u8"
9049
+ },
9050
+ {
9051
+ name: "total_supply_shares",
9052
+ type: "u64"
9053
+ },
9054
+ {
9055
+ name: "max_supply_shares",
9056
+ type: "u64"
9057
+ },
9058
+ {
9059
+ name: "total_borrow_shares",
9060
+ type: "u64"
9061
+ },
9062
+ {
9063
+ name: "max_borrow_shares",
9064
+ type: "u64"
9065
+ },
9066
+ {
9067
+ name: "range_old_upper_shift",
9068
+ type: "u32"
9069
+ },
9070
+ {
9071
+ name: "range_old_lower_shift",
9072
+ type: "u32"
9073
+ },
9074
+ {
9075
+ name: "range_shift_duration",
9076
+ type: "u32"
9077
+ },
9078
+ {
9079
+ name: "range_shift_start_timestamp",
9080
+ type: "u32"
9081
+ },
9082
+ {
9083
+ name: "threshold_old_upper_shift",
9084
+ type: "u16"
9085
+ },
9086
+ {
9087
+ name: "threshold_old_lower_shift",
9088
+ type: "u16"
9089
+ },
9090
+ {
9091
+ name: "threshold_shift_duration",
9092
+ type: "u32"
9093
+ },
9094
+ {
9095
+ name: "threshold_shift_start_timestamp",
9096
+ type: "u32"
9097
+ },
9098
+ {
9099
+ name: "threshold_shift_old_timestamp",
9100
+ type: "u32"
9101
+ },
9102
+ {
9103
+ name: "center_price_shift_start_timestamp",
9104
+ type: "u32"
9105
+ },
9106
+ {
9107
+ name: "center_price_shift_percent",
9108
+ type: "u32"
9109
+ },
9110
+ {
9111
+ name: "center_price_shift_time",
9112
+ type: "u32"
9113
+ },
9114
+ {
9115
+ name: "_reserved",
9116
+ type: {
9117
+ array: [
9118
+ "u8",
9119
+ 32
9120
+ ]
9121
+ }
9122
+ },
9123
+ {
9124
+ name: "bump",
9125
+ type: "u8"
9126
+ }
9127
+ ]
9128
+ }
9129
+ },
9130
+ {
9131
+ name: "TokenReserve",
9132
+ docs: [
9133
+ "Token configuration and exchange prices"
9134
+ ],
9135
+ serialization: "bytemuck",
9136
+ repr: {
9137
+ kind: "c",
9138
+ packed: true
9139
+ },
9140
+ type: {
9141
+ kind: "struct",
9142
+ fields: [
9143
+ {
9144
+ name: "mint",
9145
+ type: "pubkey"
9146
+ },
9147
+ {
9148
+ name: "vault",
9149
+ type: "pubkey"
9150
+ },
9151
+ {
9152
+ name: "borrow_rate",
9153
+ type: "u16"
9154
+ },
9155
+ {
9156
+ name: "fee_on_interest",
9157
+ type: "u16"
9158
+ },
9159
+ {
9160
+ name: "last_utilization",
9161
+ type: "u16"
9162
+ },
9163
+ {
9164
+ name: "last_update_timestamp",
9165
+ type: "u64"
9166
+ },
9167
+ {
9168
+ name: "supply_exchange_price",
9169
+ type: "u64"
9170
+ },
9171
+ {
9172
+ name: "borrow_exchange_price",
9173
+ type: "u64"
9174
+ },
9175
+ {
9176
+ name: "max_utilization",
9177
+ type: "u16"
9178
+ },
9179
+ {
9180
+ name: "total_supply_with_interest",
9181
+ type: "u64"
9182
+ },
9183
+ {
9184
+ name: "total_supply_interest_free",
9185
+ type: "u64"
9186
+ },
9187
+ {
9188
+ name: "total_borrow_with_interest",
9189
+ type: "u64"
9190
+ },
9191
+ {
9192
+ name: "total_borrow_interest_free",
9193
+ type: "u64"
9194
+ },
9195
+ {
9196
+ name: "total_claim_amount",
9197
+ type: "u64"
9198
+ },
9199
+ {
9200
+ name: "interacting_protocol",
9201
+ type: "pubkey"
9202
+ },
9203
+ {
9204
+ name: "interacting_timestamp",
9205
+ type: "u64"
9206
+ },
9207
+ {
9208
+ name: "interacting_balance",
9209
+ type: "u64"
9210
+ }
9211
+ ]
9212
+ }
9213
+ },
9214
+ {
9215
+ name: "UserBorrowPosition",
9216
+ docs: [
9217
+ "User borrow position"
9218
+ ],
9219
+ serialization: "bytemuck",
9220
+ repr: {
9221
+ kind: "c",
9222
+ packed: true
9223
+ },
9224
+ type: {
9225
+ kind: "struct",
9226
+ fields: [
9227
+ {
9228
+ name: "protocol",
9229
+ type: "pubkey"
9230
+ },
9231
+ {
9232
+ name: "mint",
9233
+ type: "pubkey"
9234
+ },
9235
+ {
9236
+ name: "with_interest",
9237
+ type: "u8"
9238
+ },
9239
+ {
9240
+ name: "amount",
9241
+ type: "u64"
9242
+ },
9243
+ {
9244
+ name: "debt_ceiling",
9245
+ type: "u64"
9246
+ },
9247
+ {
9248
+ name: "last_update",
9249
+ type: "u64"
9250
+ },
9251
+ {
9252
+ name: "expand_pct",
9253
+ type: "u16"
9254
+ },
9255
+ {
9256
+ name: "expand_duration",
9257
+ type: "u32"
9258
+ },
9259
+ {
9260
+ name: "base_debt_ceiling",
9261
+ type: "u64"
9262
+ },
9263
+ {
9264
+ name: "max_debt_ceiling",
9265
+ type: "u64"
9266
+ },
9267
+ {
9268
+ name: "status",
9269
+ type: "u8"
9270
+ }
9271
+ ]
9272
+ }
9273
+ },
9274
+ {
9275
+ name: "UserSupplyPosition",
9276
+ docs: [
9277
+ "User supply position"
9278
+ ],
9279
+ serialization: "bytemuck",
9280
+ repr: {
9281
+ kind: "c",
9282
+ packed: true
9283
+ },
9284
+ type: {
9285
+ kind: "struct",
9286
+ fields: [
9287
+ {
9288
+ name: "protocol",
9289
+ type: "pubkey"
9290
+ },
9291
+ {
9292
+ name: "mint",
9293
+ type: "pubkey"
9294
+ },
9295
+ {
9296
+ name: "with_interest",
9297
+ type: "u8"
9298
+ },
9299
+ {
9300
+ name: "amount",
9301
+ type: "u64"
9302
+ },
9303
+ {
9304
+ name: "withdrawal_limit",
9305
+ type: "u64"
9306
+ },
9307
+ {
9308
+ name: "decay_amount",
9309
+ type: "u64"
9310
+ },
9311
+ {
9312
+ name: "last_update",
9313
+ type: "u64"
9314
+ },
9315
+ {
9316
+ name: "expand_pct",
9317
+ type: "u16"
9318
+ },
9319
+ {
9320
+ name: "expand_duration",
9321
+ type: "u32"
9322
+ },
9323
+ {
9324
+ name: "decay_duration",
9325
+ type: "u32"
9326
+ },
9327
+ {
9328
+ name: "base_withdrawal_limit",
9329
+ type: "u64"
9330
+ },
9331
+ {
9332
+ name: "status",
9333
+ type: "u8"
9334
+ }
9335
+ ]
9336
+ }
9337
+ },
9338
+ {
9339
+ name: "VaultAdmin",
9340
+ type: {
9341
+ kind: "struct",
9342
+ fields: [
9343
+ {
9344
+ name: "authority",
9345
+ type: "pubkey"
9346
+ },
9347
+ {
9348
+ name: "liquidity_program",
9349
+ type: "pubkey"
9350
+ },
9351
+ {
9352
+ name: "next_vault_id",
9353
+ type: "u16"
9354
+ },
9355
+ {
9356
+ name: "auths",
9357
+ type: {
9358
+ vec: "pubkey"
9359
+ }
9360
+ },
9361
+ {
9362
+ name: "bump",
9363
+ type: "u8"
9364
+ }
9365
+ ]
9366
+ }
9367
+ },
9368
+ {
9369
+ name: "VaultConfig",
9370
+ serialization: "bytemuck",
9371
+ repr: {
9372
+ kind: "c",
9373
+ packed: true
9374
+ },
9375
+ type: {
9376
+ kind: "struct",
9377
+ fields: [
9378
+ {
9379
+ name: "vault_id",
9380
+ type: "u16"
9381
+ },
9382
+ {
9383
+ name: "supply_rate_magnifier",
9384
+ type: "i16"
9385
+ },
9386
+ {
9387
+ name: "borrow_rate_magnifier",
9388
+ type: "i16"
9389
+ },
9390
+ {
9391
+ name: "collateral_factor",
9392
+ type: "u16"
9393
+ },
9394
+ {
9395
+ name: "liquidation_threshold",
9396
+ type: "u16"
9397
+ },
9398
+ {
9399
+ name: "liquidation_max_limit",
9400
+ type: "u16"
9401
+ },
9402
+ {
9403
+ name: "withdraw_gap",
9404
+ type: "u16"
9405
+ },
9406
+ {
9407
+ name: "liquidation_penalty",
9408
+ type: "u16"
9409
+ },
9410
+ {
9411
+ name: "borrow_fee",
9412
+ type: "u8"
9413
+ },
9414
+ {
9415
+ name: "vault_type",
9416
+ type: "u8"
9417
+ },
9418
+ {
9419
+ name: "oracle",
9420
+ type: "pubkey"
9421
+ },
9422
+ {
9423
+ name: "rebalancer",
9424
+ type: "pubkey"
9425
+ },
9426
+ {
9427
+ name: "liquidity_program",
9428
+ type: "pubkey"
9429
+ },
9430
+ {
9431
+ name: "oracle_program",
9432
+ type: "pubkey"
9433
+ },
9434
+ {
9435
+ name: "supply_token",
9436
+ type: "pubkey"
9437
+ },
9438
+ {
9439
+ name: "borrow_token",
9440
+ type: "pubkey"
9441
+ },
9442
+ {
9443
+ name: "bump",
9444
+ type: "u8"
9445
+ }
9446
+ ]
9447
+ }
9448
+ },
9449
+ {
9450
+ name: "VaultState",
9451
+ serialization: "bytemuck",
9452
+ repr: {
9453
+ kind: "c",
9454
+ packed: true
9455
+ },
9456
+ type: {
9457
+ kind: "struct",
9458
+ fields: [
9459
+ {
9460
+ name: "vault_id",
9461
+ type: "u16"
9462
+ },
9463
+ {
9464
+ name: "branch_liquidated",
9465
+ type: "u8"
9466
+ },
9467
+ {
9468
+ name: "topmost_tick",
9469
+ type: "i32"
9470
+ },
9471
+ {
9472
+ name: "current_branch_id",
9473
+ type: "u32"
9474
+ },
9475
+ {
9476
+ name: "total_branch_id",
9477
+ type: "u32"
9478
+ },
9479
+ {
9480
+ name: "total_supply",
9481
+ type: "u64"
9482
+ },
9483
+ {
9484
+ name: "total_borrow",
9485
+ type: "u64"
9486
+ },
9487
+ {
9488
+ name: "total_positions",
9489
+ type: "u32"
9490
+ },
9491
+ {
9492
+ name: "absorbed_debt_amount",
9493
+ type: "u128"
9494
+ },
9495
+ {
9496
+ name: "absorbed_col_amount",
9497
+ type: "u128"
9498
+ },
9499
+ {
9500
+ name: "absorbed_dust_debt",
9501
+ type: "u64"
9502
+ },
9503
+ {
9504
+ name: "liquidity_supply_exchange_price",
9505
+ type: "u64"
9506
+ },
9507
+ {
9508
+ name: "liquidity_borrow_exchange_price",
9509
+ type: "u64"
9510
+ },
9511
+ {
9512
+ name: "vault_supply_exchange_price",
9513
+ type: "u64"
9514
+ },
9515
+ {
9516
+ name: "vault_borrow_exchange_price",
9517
+ type: "u64"
9518
+ },
9519
+ {
9520
+ name: "next_position_id",
9521
+ type: "u32"
9522
+ },
9523
+ {
9524
+ name: "last_update_timestamp",
9525
+ type: "u64"
9526
+ }
9527
+ ]
9528
+ }
9529
+ },
9530
+ {
9531
+ name: "Oracle",
9532
+ type: {
9533
+ kind: "struct",
9534
+ fields: [
9535
+ {
9536
+ name: "nonce",
9537
+ type: "u16"
9538
+ },
9539
+ {
9540
+ name: "sources",
9541
+ type: {
9542
+ vec: {
9543
+ defined: {
9544
+ name: "Sources"
9545
+ }
9546
+ }
9547
+ }
9548
+ },
9549
+ {
9550
+ name: "bump",
9551
+ type: "u8"
9552
+ }
9553
+ ]
9554
+ }
9555
+ },
9556
+ {
9557
+ name: "Sources",
9558
+ type: {
9559
+ kind: "struct",
9560
+ fields: [
9561
+ {
9562
+ name: "source",
9563
+ type: "pubkey"
9564
+ },
9565
+ {
9566
+ name: "invert",
9567
+ type: "bool"
9568
+ },
9569
+ {
9570
+ name: "multiplier",
9571
+ type: "u128"
9572
+ },
9573
+ {
9574
+ name: "divisor",
9575
+ type: "u128"
9576
+ },
9577
+ {
9578
+ name: "source_type",
9579
+ type: {
9580
+ defined: {
9581
+ name: "SourceType"
9582
+ }
9583
+ }
9584
+ }
9585
+ ]
9586
+ }
9587
+ },
9588
+ {
9589
+ name: "SourceType",
9590
+ type: {
9591
+ kind: "enum",
9592
+ variants: [
9593
+ {
9594
+ name: "Pyth"
9595
+ },
9596
+ {
9597
+ name: "StakePool"
9598
+ },
9599
+ {
9600
+ name: "MsolPool"
9601
+ },
9602
+ {
9603
+ name: "Redstone"
9604
+ },
9605
+ {
9606
+ name: "Chainlink"
9607
+ },
9608
+ {
9609
+ name: "SinglePool"
9610
+ },
9611
+ {
9612
+ name: "JupLend"
9613
+ },
9614
+ {
9615
+ name: "ChainlinkDataStreams"
9616
+ },
9617
+ {
9618
+ name: "PstPool"
9619
+ },
9620
+ {
9621
+ name: "DexSmartColPegOracle"
9622
+ },
9623
+ {
9624
+ name: "DexSmartDebtPegOracle"
9625
+ }
9626
+ ]
9627
+ }
9628
+ }
9629
+ ]
9630
+ };
9049
9631
 
9050
9632
  // src/lending/public-data/jupiter-lend/flashloan.ts
9051
9633
  import {
@@ -9672,38 +10254,885 @@ function decodeJupFlashloanAdmin(data) {
9672
10254
  activeAmount: BigInt(a.active_flashloan_amount)
9673
10255
  };
9674
10256
  }
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]));
10257
+ async function readJupFlashloanAdmin(rpc, market = "main") {
10258
+ const address = await jupFlashloanAdmin(market);
10259
+ const { accounts } = await rpc.readAccounts([address], { encoding: "base64" });
10260
+ const a = accounts[0];
10261
+ if (!a || a.owner !== JUP_FLASHLOAN_PROGRAMS[market]) return null;
10262
+ return decodeJupFlashloanAdmin(fromBase642(a.data[0]));
10263
+ }
10264
+ async function readJupFlashAssets(rpc, market = "main") {
10265
+ const admin = await jupFlashloanAdmin(market);
10266
+ const rows = await rpc.call(
10267
+ "getProgramAccounts",
10268
+ [
10269
+ JUP_LIQUIDITY_PROGRAMS[market],
10270
+ {
10271
+ encoding: "base64",
10272
+ dataSlice: { offset: 40, length: 32 },
10273
+ filters: [{ memcmp: { offset: 8, bytes: admin } }]
10274
+ }
10275
+ ],
10276
+ { accounts: 1 }
10277
+ );
10278
+ const mints = /* @__PURE__ */ new Set();
10279
+ for (const r of rows) mints.add(encodeBase582(fromBase642(r.account.data[0])));
10280
+ return [...mints];
10281
+ }
10282
+ async function readJupFlashAvailable(rpc, mint, tokenProgram, market = "main") {
10283
+ const vault = await jupLiquidityVault(mint, tokenProgram, market);
10284
+ const r = await rpc.call(
10285
+ "getTokenAccountBalance",
10286
+ [vault]
10287
+ );
10288
+ return BigInt(r.value.amount);
10289
+ }
10290
+
10291
+ // src/lending/public-data/jupiter-lend/onchain.ts
10292
+ var JL_VAULTS_ACCOUNTS_IDL = vaults_accounts_default;
10293
+ var JUP_VAULTS_PROGRAMS = {
10294
+ main: "jupr81YtYssSyPt8jbnGuiWon5f6x9TcDEFxYe3Bdzi",
10295
+ ethena: "jupo974WCqAUMD3RtpayTap1me7StQCWtEkBbDb6Ba3"
10296
+ };
10297
+ var JUP_DEX_PROGRAM = "jupZ4m2GqUCJ5iueMfzQf8khFfH31d4XAQt3RzCT9Vd";
10298
+ var JL_EXCHANGE_PRICES_PRECISION = 10n ** 12n;
10299
+ var RATE_OUTPUT = 10n ** 18n;
10300
+ var SCALE_FACTOR = 10n ** 18n;
10301
+ var FOUR_DECIMALS = 10000n;
10302
+ var SECONDS_PER_YEAR = 31536000n;
10303
+ var DEFAULT_MAX_UTILIZATION = 9500n;
10304
+ var JL_VAULT_AMOUNT_DECIMALS = 9;
10305
+ var isJlSmartCol = (t) => t === 2 || t === 4;
10306
+ var isJlSmartDebt = (t) => t === 3 || t === 4;
10307
+ var utf83 = (s) => new TextEncoder().encode(s);
10308
+ var u16le = (n) => new Uint8Array([n & 255, n >> 8 & 255]);
10309
+ var big = (v) => BigInt(v ?? 0);
10310
+ var maxB = (a, b) => a > b ? a : b;
10311
+ var minB = (a, b) => a < b ? a : b;
10312
+ var jlVaultConfigPda = async (vaultId, market = "main") => (await findProgramAddress3(
10313
+ [utf83("vault_config"), u16le(vaultId)],
10314
+ JUP_VAULTS_PROGRAMS[market]
10315
+ )).address;
10316
+ var jlVaultStatePda = async (vaultId, market = "main") => (await findProgramAddress3(
10317
+ [utf83("vault_state"), u16le(vaultId)],
10318
+ JUP_VAULTS_PROGRAMS[market]
10319
+ )).address;
10320
+ var jlVaultAdminPda = async (market = "main") => (await findProgramAddress3([utf83("vault_admin")], JUP_VAULTS_PROGRAMS[market])).address;
10321
+ var liq = async (seeds, market) => (await findProgramAddress3(seeds, JUP_LIQUIDITY_PROGRAMS[market])).address;
10322
+ var pk3 = async (a) => {
10323
+ const b = decodeBase583(a);
10324
+ if (!b || b.length !== 32) throw new Error(`not a pubkey: ${a}`);
10325
+ return b;
10326
+ };
10327
+ var dec = (name, data) => decodeIdlAccount3(JL_VAULTS_ACCOUNTS_IDL, name, fromBase643(data));
10328
+ var ratio = (withInterest, free) => {
10329
+ if (withInterest > free) return [free * FOUR_DECIMALS / withInterest, false];
10330
+ if (withInterest < free) return [withInterest * FOUR_DECIMALS / free, true];
10331
+ return [withInterest > 0n ? FOUR_DECIMALS : 0n, false];
10332
+ };
10333
+ function jlLiquidityExchangePrices(r, now) {
10334
+ let supplyEx = big(r.supply_exchange_price);
10335
+ let borrowEx = big(r.borrow_exchange_price);
10336
+ const borrowRate = BigInt(r.borrow_rate);
10337
+ const dt = now - big(r.last_update_timestamp);
10338
+ if (supplyEx === 0n || borrowEx === 0n || dt <= 0n || borrowRate === 0n)
10339
+ return { supplyEx, borrowEx };
10340
+ borrowEx += borrowEx * borrowRate * dt / (SECONDS_PER_YEAR * FOUR_DECIMALS);
10341
+ const [supplyRatio, supplyInverse] = ratio(
10342
+ big(r.total_supply_with_interest),
10343
+ big(r.total_supply_interest_free)
10344
+ );
10345
+ const [borrowRatio, borrowInverse] = ratio(
10346
+ big(r.total_borrow_with_interest),
10347
+ big(r.total_borrow_interest_free)
10348
+ );
10349
+ if (borrowRatio === 1n) return { supplyEx, borrowEx };
10350
+ if (supplyInverse && supplyRatio === 0n) return { supplyEx, borrowEx };
10351
+ const util = BigInt(r.last_utilization);
10352
+ let ratioSupplyYield = supplyInverse ? util * (RATE_OUTPUT + RATE_OUTPUT * FOUR_DECIMALS / supplyRatio) / FOUR_DECIMALS : util * RATE_OUTPUT * (FOUR_DECIMALS + supplyRatio) / (FOUR_DECIMALS * FOUR_DECIMALS);
10353
+ const adjBorrowRatio = borrowInverse ? borrowRatio * RATE_OUTPUT / (FOUR_DECIMALS + borrowRatio) : RATE_OUTPUT - borrowRatio * RATE_OUTPUT / (FOUR_DECIMALS + borrowRatio);
10354
+ ratioSupplyYield = ratioSupplyYield * adjBorrowRatio * FOUR_DECIMALS / RATE_OUTPUT / RATE_OUTPUT;
10355
+ const supplyRate = borrowRate * ratioSupplyYield * (FOUR_DECIMALS - BigInt(r.fee_on_interest));
10356
+ supplyEx += supplyEx * supplyRate * dt / (SECONDS_PER_YEAR * FOUR_DECIMALS) / (FOUR_DECIMALS * FOUR_DECIMALS);
10357
+ return { supplyEx, borrowEx };
10358
+ }
10359
+ function jlOverallTokenData(r, now) {
10360
+ const { supplyEx, borrowEx } = jlLiquidityExchangePrices(r, now);
10361
+ const supplyRaw = big(r.total_supply_with_interest);
10362
+ const borrowRaw = big(r.total_borrow_with_interest);
10363
+ const totalSupply = supplyRaw * supplyEx / JL_EXCHANGE_PRICES_PRECISION + big(r.total_supply_interest_free);
10364
+ const totalBorrow = borrowRaw * borrowEx / JL_EXCHANGE_PRICES_PRECISION + big(r.total_borrow_interest_free);
10365
+ let supplyRate = 0n;
10366
+ if (supplyRaw > 0n) {
10367
+ const b = borrowRaw * big(r.borrow_exchange_price) / JL_EXCHANGE_PRICES_PRECISION;
10368
+ const s = supplyRaw * big(r.supply_exchange_price) / JL_EXCHANGE_PRICES_PRECISION;
10369
+ if (s > 0n)
10370
+ supplyRate = BigInt(r.borrow_rate) * (FOUR_DECIMALS - BigInt(r.fee_on_interest)) * b / (s * FOUR_DECIMALS);
10371
+ }
10372
+ const maxUtil = BigInt(r.max_utilization) || DEFAULT_MAX_UTILIZATION;
10373
+ return {
10374
+ supplyEx,
10375
+ borrowEx,
10376
+ totalSupply,
10377
+ totalBorrow,
10378
+ supplyRate,
10379
+ borrowRate: BigInt(r.borrow_rate),
10380
+ maxUtilization: maxUtil
10381
+ };
10382
+ }
10383
+ function jlUserSupplyData(u, o, balance, now) {
10384
+ const z = {
10385
+ modeWithInterest: false,
10386
+ supply: 0n,
10387
+ withdrawalLimit: 0n,
10388
+ lastUpdateTimestamp: 0n,
10389
+ expandPercent: 0n,
10390
+ expandDuration: 0n,
10391
+ baseWithdrawalLimit: 0n,
10392
+ withdrawableUntilLimit: 0n,
10393
+ withdrawable: 0n,
10394
+ decayAmount: 0n,
10395
+ decayEndTimestamp: 0n
10396
+ };
10397
+ if (!u) return z;
10398
+ const amount = big(u.amount);
10399
+ const expandPct = BigInt(u.expand_pct);
10400
+ const expandDuration = BigInt(u.expand_duration);
10401
+ const last = big(u.last_update);
10402
+ let limit = 0n;
10403
+ const lastLimit = big(u.withdrawal_limit);
10404
+ if (lastLimit > 0n) {
10405
+ const maxWithdrawable = amount * expandPct / FOUR_DECIMALS;
10406
+ const expanded = expandDuration > 0n ? maxWithdrawable * (now - last) / expandDuration : maxWithdrawable;
10407
+ limit = lastLimit > expanded ? lastLimit - expanded : 0n;
10408
+ const floor = amount - maxWithdrawable;
10409
+ if (floor > limit) limit = floor;
10410
+ }
10411
+ let decay = big(u.decay_amount);
10412
+ let decayEnd = now;
10413
+ const decayDuration = BigInt(u.decay_duration);
10414
+ if (decay > 0n && decayDuration > 0n) {
10415
+ const elapsed = now - last;
10416
+ if (elapsed < decayDuration) {
10417
+ decay -= decay * elapsed / decayDuration;
10418
+ decayEnd = last + decayDuration;
10419
+ } else decay = 0n;
10420
+ }
10421
+ const withInterest = !!u.with_interest;
10422
+ const ex = (v) => withInterest ? v * o.supplyEx / JL_EXCHANGE_PRICES_PRECISION : v;
10423
+ const supply = ex(amount);
10424
+ let withdrawalLimit = ex(limit);
10425
+ const untilLimit = supply > withdrawalLimit ? supply - withdrawalLimit : 0n;
10426
+ if (withdrawalLimit === 0n) withdrawalLimit = supply;
10427
+ return {
10428
+ modeWithInterest: withInterest,
10429
+ supply,
10430
+ withdrawalLimit,
10431
+ lastUpdateTimestamp: last,
10432
+ expandPercent: expandPct,
10433
+ expandDuration,
10434
+ baseWithdrawalLimit: ex(big(u.base_withdrawal_limit)),
10435
+ withdrawableUntilLimit: untilLimit,
10436
+ withdrawable: minB(balance, untilLimit),
10437
+ decayAmount: ex(decay),
10438
+ decayEndTimestamp: decayEnd
10439
+ };
10440
+ }
10441
+ function jlUserBorrowData(u, o, balance, now) {
10442
+ const z = {
10443
+ modeWithInterest: false,
10444
+ borrow: 0n,
10445
+ borrowLimit: 0n,
10446
+ lastUpdateTimestamp: 0n,
10447
+ expandPercent: 0n,
10448
+ expandDuration: 0n,
10449
+ baseBorrowLimit: 0n,
10450
+ maxBorrowLimit: 0n,
10451
+ borrowLimitUtilization: 0n,
10452
+ borrowableUntilLimit: 0n,
10453
+ borrowable: 0n
10454
+ };
10455
+ if (!u) return z;
10456
+ const amount = big(u.amount);
10457
+ const expandPct = BigInt(u.expand_pct);
10458
+ const expandDuration = BigInt(u.expand_duration);
10459
+ const last = big(u.last_update);
10460
+ const base = big(u.base_debt_ceiling);
10461
+ const maxCeil = big(u.max_debt_ceiling);
10462
+ let limit;
10463
+ if (now < last || expandDuration === 0n) limit = base;
10464
+ else {
10465
+ const maxExpansion = amount * expandPct / FOUR_DECIMALS;
10466
+ limit = maxExpansion * (now - last) / expandDuration + big(u.debt_ceiling);
10467
+ limit = minB(limit, amount + maxExpansion);
10468
+ limit = maxB(limit, base);
10469
+ limit = minB(limit, maxCeil);
10470
+ }
10471
+ const withInterest = !!u.with_interest;
10472
+ const ex = (v) => withInterest ? v * o.borrowEx / JL_EXCHANGE_PRICES_PRECISION : v;
10473
+ const borrow = ex(amount);
10474
+ const borrowLimit = ex(limit);
10475
+ const borrowLimitUtilization = o.maxUtilization * o.totalSupply / FOUR_DECIMALS;
10476
+ const untilUtil = borrowLimitUtilization > o.totalBorrow ? borrowLimitUtilization - o.totalBorrow : 0n;
10477
+ const untilLimit = borrowLimit > borrow ? borrowLimit - borrow : 0n;
10478
+ const borrowableUntilLimit = minB(untilLimit, untilUtil);
10479
+ return {
10480
+ modeWithInterest: withInterest,
10481
+ borrow,
10482
+ borrowLimit,
10483
+ lastUpdateTimestamp: last,
10484
+ expandPercent: expandPct,
10485
+ expandDuration,
10486
+ baseBorrowLimit: ex(base),
10487
+ maxBorrowLimit: ex(maxCeil),
10488
+ borrowLimitUtilization,
10489
+ borrowableUntilLimit,
10490
+ borrowable: minB(balance, borrowableUntilLimit)
10491
+ };
10492
+ }
10493
+ function jlVaultExchangePrices(s, c, liqSupplyEx, liqBorrowEx, now) {
10494
+ const oldLs = big(s.liquidity_supply_exchange_price);
10495
+ const oldLb = big(s.liquidity_borrow_exchange_price);
10496
+ const vs = big(s.vault_supply_exchange_price);
10497
+ const vb = big(s.vault_borrow_exchange_price);
10498
+ if (liqSupplyEx < oldLs || liqBorrowEx < oldLb || oldLs === 0n || oldLb === 0n)
10499
+ return { supplyEx: vs, borrowEx: vb };
10500
+ const dt = maxB(0n, now - big(s.last_update_timestamp));
10501
+ let supplyEx = vs * (liqSupplyEx * SCALE_FACTOR / oldLs) / SCALE_FACTOR;
10502
+ const sm = BigInt(c.supply_rate_magnifier);
10503
+ if (sm !== 0n) {
10504
+ const ch = vs * dt * (sm < 0n ? -sm : sm) / FOUR_DECIMALS / SECONDS_PER_YEAR;
10505
+ supplyEx = sm > 0n ? supplyEx + ch : supplyEx - ch;
10506
+ }
10507
+ const prod = vb * (liqBorrowEx * SCALE_FACTOR / oldLb);
10508
+ let borrowEx = (prod + SCALE_FACTOR - 1n) / SCALE_FACTOR;
10509
+ const bm = BigInt(c.borrow_rate_magnifier);
10510
+ if (bm !== 0n) {
10511
+ const ch = vb * dt * (bm < 0n ? -bm : bm) / FOUR_DECIMALS / SECONDS_PER_YEAR;
10512
+ borrowEx = bm > 0n ? borrowEx + ch : borrowEx - ch;
10513
+ }
10514
+ return { supplyEx, borrowEx };
10515
+ }
10516
+ 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);
10517
+ async function read(rpc, keys) {
10518
+ const uniq = [...new Set(keys)];
10519
+ const { accounts, slot } = await rpc.readAccounts(uniq, {
10520
+ encoding: "base64"
10521
+ });
10522
+ const m = /* @__PURE__ */ new Map();
10523
+ uniq.forEach((k, i) => m.set(k, accounts[i] ?? null));
10524
+ return { m, slot };
10525
+ }
10526
+ async function readJlNextVaultId(rpc, market = "main") {
10527
+ const admin = await jlVaultAdminPda(market);
10528
+ const { m } = await read(rpc, [admin]);
10529
+ const a = m.get(admin);
10530
+ if (!a || a.owner !== JUP_VAULTS_PROGRAMS[market]) return void 0;
10531
+ return Number(
10532
+ dec("VaultAdmin", a.data[0]).next_vault_id
10533
+ );
9681
10534
  }
9682
- async function readJupFlashAssets(rpc, market = "main") {
9683
- const admin = await jupFlashloanAdmin(market);
9684
- const rows = await rpc.call(
9685
- "getProgramAccounts",
9686
- [
9687
- JUP_LIQUIDITY_PROGRAMS[market],
9688
- {
9689
- encoding: "base64",
9690
- dataSlice: { offset: 40, length: 32 },
9691
- filters: [{ memcmp: { offset: 8, bytes: admin } }]
9692
- }
9693
- ],
9694
- { accounts: 1 }
10535
+ var sourceTypeName = (t) => {
10536
+ if (typeof t === "string") return t;
10537
+ if (t && typeof t === "object") return Object.keys(t)[0] ?? "unknown";
10538
+ return String(t);
10539
+ };
10540
+ var lowerFirst = (s) => s.charAt(0).toLowerCase() + s.slice(1);
10541
+ async function readJupiterLendVaultsOnchain(rpc, market, vaultIds, opts = {}) {
10542
+ if (!vaultIds.length) return [];
10543
+ const now = BigInt(opts.now ?? Math.floor(Date.now() / 1e3));
10544
+ const program = JUP_VAULTS_PROGRAMS[market];
10545
+ const cfgKeys = await Promise.all(
10546
+ vaultIds.map((i) => jlVaultConfigPda(i, market))
10547
+ );
10548
+ const stateKeys = await Promise.all(
10549
+ vaultIds.map((i) => jlVaultStatePda(i, market))
9695
10550
  );
10551
+ const r1 = await read(rpc, [...cfgKeys, ...stateKeys]);
10552
+ const items = [];
10553
+ vaultIds.forEach((id, k) => {
10554
+ const ca = r1.m.get(cfgKeys[k]);
10555
+ const sa = r1.m.get(stateKeys[k]);
10556
+ if (!ca || !sa || ca.owner !== program || sa.owner !== program) return;
10557
+ try {
10558
+ const c = dec("VaultConfig", ca.data[0]);
10559
+ const s = dec("VaultState", sa.data[0]);
10560
+ const t = Number(c.vault_type);
10561
+ items.push({
10562
+ id,
10563
+ configKey: cfgKeys[k],
10564
+ c,
10565
+ s,
10566
+ smartCol: isJlSmartCol(t),
10567
+ smartDebt: isJlSmartDebt(t)
10568
+ });
10569
+ } catch (e) {
10570
+ console.warn(
10571
+ `[jupiter-lend] vault ${market}_${id}: ${e.message}`
10572
+ );
10573
+ }
10574
+ });
10575
+ if (!items.length) return [];
9696
10576
  const mints = /* @__PURE__ */ new Set();
9697
- for (const r of rows) mints.add(encodeBase582(fromBase642(r.account.data[0])));
9698
- return [...mints];
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]
10577
+ const dexes = /* @__PURE__ */ new Set();
10578
+ const r2Keys = [];
10579
+ const reserveOf = /* @__PURE__ */ new Map();
10580
+ const supplyPosOf = /* @__PURE__ */ new Map();
10581
+ const borrowPosOf = /* @__PURE__ */ new Map();
10582
+ for (const it of items) {
10583
+ r2Keys.push(it.c.oracle);
10584
+ const sides = [
10585
+ [it.c.supply_token, it.smartCol, "supply"],
10586
+ [it.c.borrow_token, it.smartDebt, "borrow"]
10587
+ ];
10588
+ for (const [token, smart, side] of sides) {
10589
+ if (smart) {
10590
+ dexes.add(token);
10591
+ continue;
10592
+ }
10593
+ mints.add(token);
10594
+ if (!reserveOf.has(token))
10595
+ reserveOf.set(
10596
+ token,
10597
+ await liq([utf83("reserve"), await pk3(token)], market)
10598
+ );
10599
+ const pos = await liq(
10600
+ [
10601
+ utf83(
10602
+ side === "supply" ? "user_supply_position" : "user_borrow_position"
10603
+ ),
10604
+ await pk3(token),
10605
+ await pk3(it.configKey)
10606
+ ],
10607
+ market
10608
+ );
10609
+ (side === "supply" ? supplyPosOf : borrowPosOf).set(
10610
+ `${it.id}:${token}`,
10611
+ pos
10612
+ );
10613
+ }
10614
+ }
10615
+ r2Keys.push(
10616
+ ...mints,
10617
+ ...dexes,
10618
+ ...reserveOf.values(),
10619
+ ...supplyPosOf.values(),
10620
+ ...borrowPosOf.values()
9705
10621
  );
9706
- return BigInt(r.value.amount);
10622
+ const r2 = await read(rpc, r2Keys);
10623
+ const decimalsOf = /* @__PURE__ */ new Map();
10624
+ for (const mint of mints) {
10625
+ const a = r2.m.get(mint);
10626
+ if (!a) continue;
10627
+ const b = fromBase643(a.data[0]);
10628
+ if (b.length >= 45) decimalsOf.set(mint, b[44]);
10629
+ }
10630
+ const reserves = /* @__PURE__ */ new Map();
10631
+ for (const [mint, key2] of reserveOf) {
10632
+ const a = r2.m.get(key2);
10633
+ if (!a) continue;
10634
+ try {
10635
+ reserves.set(mint, dec("TokenReserve", a.data[0]));
10636
+ } catch (e) {
10637
+ console.warn(`[jupiter-lend] reserve ${mint}: ${e.message}`);
10638
+ }
10639
+ }
10640
+ const vaultOf = /* @__PURE__ */ new Map();
10641
+ for (const [mint, r] of reserves) vaultOf.set(mint, r.vault);
10642
+ const r3 = vaultOf.size ? await read(rpc, [...vaultOf.values()]) : { m: /* @__PURE__ */ new Map(), slot: r2.slot };
10643
+ const balanceOf = (mint) => {
10644
+ const a = r3.m.get(vaultOf.get(mint) ?? "");
10645
+ if (!a) return 0n;
10646
+ const b = fromBase643(a.data[0]);
10647
+ return b.length >= 72 ? new DataView(b.buffer, b.byteOffset, b.byteLength).getBigUint64(
10648
+ 64,
10649
+ true
10650
+ ) : 0n;
10651
+ };
10652
+ const overall = /* @__PURE__ */ new Map();
10653
+ for (const [mint, r] of reserves)
10654
+ overall.set(mint, jlOverallTokenData(r, now));
10655
+ const dexOf = (address) => {
10656
+ const a = r2.m.get(address);
10657
+ if (!a) return void 0;
10658
+ try {
10659
+ const d2 = dec("Dex", a.data[0]);
10660
+ return { address, token0: d2.token_0, token1: d2.token_1 };
10661
+ } catch {
10662
+ return void 0;
10663
+ }
10664
+ };
10665
+ const tokenFact = (mint, decimals) => {
10666
+ const known = opts.tokens?.[mint];
10667
+ if (known) return known;
10668
+ const l = opts.tokenList?.[mint];
10669
+ const sym = l?.symbol ?? mint.slice(0, 4);
10670
+ return {
10671
+ address: mint,
10672
+ chainId: "solana",
10673
+ name: l?.name ?? sym,
10674
+ symbol: sym,
10675
+ uiSymbol: sym,
10676
+ decimals: l?.decimals ?? decimals,
10677
+ ...typeof l?.logoURI === "string" ? { logoUrl: l.logoURI } : {},
10678
+ // unpriced: the converter's USD figures read 0 — say so on the bundle, never invent
10679
+ price: "0"
10680
+ };
10681
+ };
10682
+ const dexToken = (d2, address) => {
10683
+ const s = (m) => opts.tokens?.[m]?.uiSymbol ?? opts.tokenList?.[m]?.symbol ?? m.slice(0, 4);
10684
+ const sym = d2 ? `${s(d2.token0)}-${s(d2.token1)} DEX` : `DEX ${address.slice(0, 4)}`;
10685
+ return {
10686
+ address,
10687
+ chainId: "solana",
10688
+ name: `Jupiter Lend ${sym} shares`,
10689
+ symbol: sym,
10690
+ uiSymbol: sym,
10691
+ decimals: JL_VAULT_AMOUNT_DECIMALS,
10692
+ price: "0"
10693
+ };
10694
+ };
10695
+ const out = [];
10696
+ for (const it of items) {
10697
+ const { c, s } = it;
10698
+ const supTok = c.supply_token;
10699
+ const borTok = c.borrow_token;
10700
+ const supO = it.smartCol ? void 0 : overall.get(supTok);
10701
+ const borO = it.smartDebt ? void 0 : overall.get(borTok);
10702
+ if (!it.smartCol && !supO || !it.smartDebt && !borO) {
10703
+ console.warn(
10704
+ `[jupiter-lend] vault ${market}_${it.id}: layer reserve not readable, skipped`
10705
+ );
10706
+ continue;
10707
+ }
10708
+ const supDec = it.smartCol ? JL_VAULT_AMOUNT_DECIMALS : decimalsOf.get(supTok) ?? 9;
10709
+ const borDec = it.smartDebt ? JL_VAULT_AMOUNT_DECIMALS : decimalsOf.get(borTok) ?? 9;
10710
+ const zero = {
10711
+ supplyEx: JL_EXCHANGE_PRICES_PRECISION,
10712
+ borrowEx: JL_EXCHANGE_PRICES_PRECISION,
10713
+ totalSupply: 0n,
10714
+ totalBorrow: 0n,
10715
+ supplyRate: 0n,
10716
+ borrowRate: 0n,
10717
+ maxUtilization: DEFAULT_MAX_UTILIZATION
10718
+ };
10719
+ const so = supO ?? zero;
10720
+ const bo = borO ?? zero;
10721
+ const supBal = it.smartCol ? 0n : balanceOf(supTok);
10722
+ const borBal = it.smartDebt ? 0n : balanceOf(borTok);
10723
+ const us = (() => {
10724
+ const a = r2.m.get(supplyPosOf.get(`${it.id}:${supTok}`) ?? "");
10725
+ return a ? dec("UserSupplyPosition", a.data[0]) : void 0;
10726
+ })();
10727
+ const ub = (() => {
10728
+ const a = r2.m.get(borrowPosOf.get(`${it.id}:${borTok}`) ?? "");
10729
+ return a ? dec("UserBorrowPosition", a.data[0]) : void 0;
10730
+ })();
10731
+ const sup = jlUserSupplyData(it.smartCol ? void 0 : us, so, supBal, now);
10732
+ const bor = jlUserBorrowData(it.smartDebt ? void 0 : ub, bo, borBal, now);
10733
+ const ex = jlVaultExchangePrices(
10734
+ s,
10735
+ c,
10736
+ it.smartCol ? JL_EXCHANGE_PRICES_PRECISION : so.supplyEx,
10737
+ it.smartDebt ? JL_EXCHANGE_PRICES_PRECISION : bo.borrowEx,
10738
+ now
10739
+ );
10740
+ const supplyEx = it.smartCol ? big(s.vault_supply_exchange_price) : ex.supplyEx;
10741
+ const borrowEx = it.smartDebt ? big(s.vault_borrow_exchange_price) : ex.borrowEx;
10742
+ const P = JL_EXCHANGE_PRICES_PRECISION;
10743
+ const totalSupply = jlVaultToRaw(
10744
+ big(s.total_supply) * supplyEx / P,
10745
+ supDec
10746
+ );
10747
+ const totalBorrow = jlVaultToRaw(
10748
+ big(s.total_borrow) * borrowEx / P,
10749
+ borDec
10750
+ );
10751
+ const absorbedSupply = jlVaultToRaw(
10752
+ big(s.absorbed_col_amount) * supplyEx / P,
10753
+ supDec
10754
+ );
10755
+ const absorbedBorrow = jlVaultToRaw(
10756
+ big(s.absorbed_debt_amount) * borrowEx / P,
10757
+ borDec
10758
+ );
10759
+ let withdrawLimit = 0n;
10760
+ let withdrawableUntilLimit = 0n;
10761
+ let withdrawable = 0n;
10762
+ if (sup.supply > 0n) {
10763
+ withdrawLimit = sup.withdrawalLimit;
10764
+ const gap = sup.supply * BigInt(c.withdraw_gap) / 1000n;
10765
+ withdrawableUntilLimit = sup.withdrawableUntilLimit > gap ? (sup.withdrawableUntilLimit - gap) * 999999n / 1000000n : 0n;
10766
+ withdrawable = minB(supBal, withdrawableUntilLimit);
10767
+ }
10768
+ let borrowLimit = 0n;
10769
+ let borrowLimitUtilization = 0n;
10770
+ let borrowableUntilLimit = 0n;
10771
+ let borrowable = 0n;
10772
+ if (bor.borrow > 0n) {
10773
+ borrowLimit = bor.borrowLimit;
10774
+ borrowLimitUtilization = bor.borrowLimitUtilization;
10775
+ borrowableUntilLimit = bor.borrowableUntilLimit * 999999n / 1000000n;
10776
+ borrowable = minB(borBal, borrowableUntilLimit);
10777
+ }
10778
+ const minimumBorrowing = jlVaultToRaw(10001n * borrowEx / P, borDec);
10779
+ const supplyRateLiq = it.smartCol ? 0n : so.supplyRate;
10780
+ const borrowRateLiq = it.smartDebt ? 0n : bo.borrowRate;
10781
+ const supplyRate = supplyRateLiq + BigInt(c.supply_rate_magnifier);
10782
+ const borrowRate = borrowRateLiq + BigInt(c.borrow_rate_magnifier);
10783
+ const supplyDex = it.smartCol ? dexOf(supTok) : void 0;
10784
+ const borrowDex = it.smartDebt ? dexOf(borTok) : void 0;
10785
+ const supplyToken = it.smartCol ? dexToken(supplyDex, supTok) : tokenFact(supTok, supDec);
10786
+ const borrowToken = it.smartDebt ? dexToken(borrowDex, borTok) : tokenFact(borTok, borDec);
10787
+ let oracleSources = [];
10788
+ const oa = r2.m.get(c.oracle);
10789
+ if (oa)
10790
+ try {
10791
+ oracleSources = dec("Oracle", oa.data[0]).sources.map(
10792
+ (x) => ({
10793
+ source: x.source,
10794
+ invert: x.invert,
10795
+ multiplier: String(x.multiplier),
10796
+ divisor: String(x.divisor),
10797
+ sourceType: { [lowerFirst(sourceTypeName(x.source_type))]: {} }
10798
+ })
10799
+ );
10800
+ } catch {
10801
+ }
10802
+ const vault = {
10803
+ id: it.id,
10804
+ address: it.configKey,
10805
+ type: Number(c.vault_type),
10806
+ supplyToken,
10807
+ borrowToken,
10808
+ totalSupply: totalSupply.toString(),
10809
+ totalSupplyLiquidity: sup.supply.toString(),
10810
+ totalBorrow: totalBorrow.toString(),
10811
+ totalBorrowLiquidity: bor.borrow.toString(),
10812
+ absorbedSupply: absorbedSupply.toString(),
10813
+ absorbedBorrow: absorbedBorrow.toString(),
10814
+ supplyRateMagnifier: String(c.supply_rate_magnifier),
10815
+ borrowRateMagnifier: String(c.borrow_rate_magnifier),
10816
+ borrowFee: String(c.borrow_fee),
10817
+ collateralFactor: String(c.collateral_factor),
10818
+ liquidationThreshold: String(c.liquidation_threshold),
10819
+ liquidationMaxLimit: String(c.liquidation_max_limit),
10820
+ liquidationPenalty: String(c.liquidation_penalty),
10821
+ withdrawalGap: String(c.withdraw_gap),
10822
+ supplyRate: supplyRate.toString(),
10823
+ supplyRateLiquidity: supplyRateLiq.toString(),
10824
+ borrowRate: borrowRate.toString(),
10825
+ borrowRateLiquidity: borrowRateLiq.toString(),
10826
+ withdrawLimit: withdrawLimit.toString(),
10827
+ withdrawableUntilLimit: withdrawableUntilLimit.toString(),
10828
+ withdrawable: withdrawable.toString(),
10829
+ borrowLimit: borrowLimit.toString(),
10830
+ borrowableUntilLimit: borrowableUntilLimit.toString(),
10831
+ borrowable: borrowable.toString(),
10832
+ borrowLimitUtilization: borrowLimitUtilization.toString(),
10833
+ minimumBorrowing: minimumBorrowing.toString(),
10834
+ totalPositions: Number(s.total_positions),
10835
+ oracle: c.oracle,
10836
+ oraclePrice: "",
10837
+ oraclePriceOperate: "",
10838
+ oraclePriceLiquidate: "",
10839
+ oracleSources,
10840
+ oracleTimestamp: 0,
10841
+ liquiditySupplyData: {
10842
+ modeWithInterest: sup.modeWithInterest,
10843
+ supply: sup.supply.toString(),
10844
+ withdrawalLimit: sup.withdrawalLimit.toString(),
10845
+ lastUpdateTimestamp: sup.lastUpdateTimestamp.toString(),
10846
+ expandPercent: sup.expandPercent.toString(),
10847
+ expandDuration: sup.expandDuration.toString(),
10848
+ baseWithdrawalLimit: sup.baseWithdrawalLimit.toString(),
10849
+ withdrawableUntilLimit: sup.withdrawableUntilLimit.toString(),
10850
+ withdrawable: sup.withdrawable.toString(),
10851
+ decayAmount: sup.decayAmount.toString(),
10852
+ decayEndTimestamp: sup.decayEndTimestamp.toString()
10853
+ },
10854
+ liquidityBorrowData: {
10855
+ modeWithInterest: bor.modeWithInterest,
10856
+ borrow: bor.borrow.toString(),
10857
+ borrowLimit: bor.borrowLimit.toString(),
10858
+ lastUpdateTimestamp: bor.lastUpdateTimestamp.toString(),
10859
+ expandPercent: bor.expandPercent.toString(),
10860
+ expandDuration: bor.expandDuration.toString(),
10861
+ baseBorrowLimit: bor.baseBorrowLimit.toString(),
10862
+ maxBorrowLimit: bor.maxBorrowLimit.toString(),
10863
+ borrowLimitUtilization: bor.borrowLimitUtilization.toString(),
10864
+ borrowableUntilLimit: bor.borrowableUntilLimit.toString(),
10865
+ borrowable: bor.borrowable.toString()
10866
+ },
10867
+ rewards: [],
10868
+ topTick: Number(s.topmost_tick),
10869
+ metadata: { maxLeverage: false, nativeStake: false, pegged: false }
10870
+ };
10871
+ out.push({
10872
+ vault,
10873
+ smartCol: it.smartCol,
10874
+ smartDebt: it.smartDebt,
10875
+ supplyDex,
10876
+ borrowDex,
10877
+ slot: r2.slot
10878
+ });
10879
+ }
10880
+ return out;
10881
+ }
10882
+
10883
+ // src/lending/public-data/jupiter-lend/convertPublic.ts
10884
+ var JL_FACTOR_SCALE = 1e3;
10885
+ var JL_BPS = 1e4;
10886
+ var JL_ORACLE_DECIMALS = 15;
10887
+ var JL_ORACLE_SCALE = 10 ** JL_ORACLE_DECIMALS;
10888
+ var FLUID_ORACLE_DECIMALS = 27;
10889
+ var FLUID_VAULT_TYPE_T1 = 1e4;
10890
+ var bpsToPercent = (v) => num(v) / 100;
10891
+ var jlOraclePriceInBorrow = (raw2) => num(raw2) / JL_ORACLE_SCALE;
10892
+ function jlOracleToFluidRaw(raw2, colDecimals, debtDecimals) {
10893
+ if (typeof raw2 !== "string" || !/^\d+$/.test(raw2)) return void 0;
10894
+ const exp = FLUID_ORACLE_DECIMALS - JL_ORACLE_DECIMALS + debtDecimals - colDecimals;
10895
+ const v = BigInt(raw2);
10896
+ return (exp >= 0 ? v * 10n ** BigInt(exp) : v / 10n ** BigInt(-exp)).toString();
10897
+ }
10898
+ function formatRawUnits(raw2, decimals) {
10899
+ let v;
10900
+ try {
10901
+ v = BigInt(raw2 ?? 0);
10902
+ } catch {
10903
+ return "0";
10904
+ }
10905
+ const neg = v < 0n;
10906
+ if (neg) v = -v;
10907
+ const base = 10n ** BigInt(decimals);
10908
+ const whole = v / base;
10909
+ const frac = (v % base).toString().padStart(decimals, "0").replace(/0+$/, "");
10910
+ return `${neg ? "-" : ""}${whole}${frac ? `.${frac}` : ""}`;
10911
+ }
10912
+ function deriveLayerTotals(vaults, earn) {
10913
+ const t = {};
10914
+ const slot = (mint, decimals) => t[mint] ??= { supply: 0n, borrow: 0n, decimals };
10915
+ for (const e of earn)
10916
+ slot(e.assetAddress, e.asset.decimals).supply += BigInt(
10917
+ e.liquiditySupplyData.supply || "0"
10918
+ );
10919
+ for (const v of vaults) {
10920
+ slot(v.supplyToken.address, v.supplyToken.decimals).supply += BigInt(
10921
+ v.liquiditySupplyData.supply || "0"
10922
+ );
10923
+ slot(v.borrowToken.address, v.borrowToken.decimals).borrow += BigInt(
10924
+ v.liquidityBorrowData.borrow || "0"
10925
+ );
10926
+ }
10927
+ return t;
10928
+ }
10929
+ var fmt = (raw2, decimals) => Number(raw2) / 10 ** decimals;
10930
+ var jupiterLendCurrency = (t, listed3) => {
10931
+ const base = listed3 ?? {
10932
+ chainId: SOLANA_CHAIN_ID,
10933
+ address: t.address,
10934
+ symbol: t.uiSymbol ?? t.symbol,
10935
+ name: t.name,
10936
+ decimals: t.decimals
10937
+ };
10938
+ return { ...base, assetGroup: base.assetGroup || `solana-${t.address}` };
10939
+ };
10940
+ function convertJupiterLendVault(market, v, opts = {}) {
10941
+ const lenderKey = jupiterLendVaultKey(market, v.id);
10942
+ const sup = v.supplyToken;
10943
+ const bor = v.borrowToken;
10944
+ const supPrice = num(sup.price);
10945
+ const borPrice = num(bor.price);
10946
+ const ltv = num(v.collateralFactor) / JL_FACTOR_SCALE;
10947
+ const lt = num(v.liquidationThreshold) / JL_FACTOR_SCALE;
10948
+ const penalty = num(v.liquidationPenalty) / JL_BPS;
10949
+ const supAsset = jupiterLendCurrency(sup, opts.tokenList?.[sup.address]);
10950
+ const borAsset = jupiterLendCurrency(bor, opts.tokenList?.[bor.address]);
10951
+ const supSym = supAsset.symbol ?? sup.symbol;
10952
+ const borSym = borAsset.symbol ?? bor.symbol;
10953
+ const label = `${supSym} / ${borSym} \xB7 vault #${v.id}`;
10954
+ const intrinsic = (a) => opts.intrinsicYields?.[a.assetGroup] ?? 0;
10955
+ const layerOf = (mint) => {
10956
+ const l = opts.layer?.[mint];
10957
+ if (!l || l.supply === 0n) return { utilization: 0 };
10958
+ return {
10959
+ utilization: Number(l.borrow * 10000n / l.supply) / 1e4,
10960
+ irmTotalDeposits: fmt(l.supply, l.decimals),
10961
+ irmTotalDebt: fmt(l.borrow, l.decimals)
10962
+ };
10963
+ };
10964
+ const totalSupply = BigInt(v.totalSupply || "0");
10965
+ const withdrawLimit = BigInt(v.withdrawLimit || "0");
10966
+ const lockupRatio = totalSupply > 0n ? Number(withdrawLimit * 10000n / totalSupply) / 1e4 : 0;
10967
+ const supplyDeposits = fmt(v.totalSupply, sup.decimals);
10968
+ const borrowDebt = fmt(v.totalBorrow, bor.decimals);
10969
+ const borrowable = fmt(v.borrowable, bor.decimals);
10970
+ const collateralConfig = {
10971
+ category: 0,
10972
+ label,
10973
+ borrowCollateralFactor: ltv,
10974
+ collateralFactor: lt,
10975
+ borrowFactor: 1,
10976
+ liquidationPenalty: penalty,
10977
+ closeFactor: 1,
10978
+ collateralDisabled: false,
10979
+ debtDisabled: true
10980
+ };
10981
+ const debtConfig = {
10982
+ category: 0,
10983
+ label,
10984
+ borrowCollateralFactor: 0,
10985
+ collateralFactor: 0,
10986
+ borrowFactor: 1,
10987
+ liquidationPenalty: 0,
10988
+ closeFactor: 1,
10989
+ collateralDisabled: true,
10990
+ debtDisabled: false
10991
+ };
10992
+ const common = {
10993
+ totalDebtStable: "0",
10994
+ totalDebtStableUSD: 0,
10995
+ stableBorrowRate: 0,
10996
+ hasStable: false,
10997
+ isActive: true,
10998
+ isFrozen: false,
10999
+ debtCeiling: "0",
11000
+ closeFactor: 1,
11001
+ lockupRatio,
11002
+ rewards: []
11003
+ };
11004
+ const colUid = createMarketUid(SOLANA_CHAIN_ID, lenderKey, sup.address);
11005
+ const debtUid = createMarketUid(SOLANA_CHAIN_ID, lenderKey, bor.address);
11006
+ const collateralLeg = {
11007
+ ...common,
11008
+ marketUid: colUid,
11009
+ name: `Collateral ${supSym}`,
11010
+ poolId: sup.address,
11011
+ underlying: sup.address,
11012
+ asset: supAsset,
11013
+ decimals: sup.decimals,
11014
+ totalDeposits: formatRawUnits(v.totalSupply, sup.decimals),
11015
+ totalDebt: "0",
11016
+ totalLiquidity: supplyDeposits,
11017
+ borrowLiquidity: 0,
11018
+ totalDepositsUSD: supplyDeposits * supPrice,
11019
+ totalDebtUSD: 0,
11020
+ totalLiquidityUSD: supplyDeposits * supPrice,
11021
+ borrowLiquidityUSD: 0,
11022
+ ...layerOf(sup.address),
11023
+ depositRate: bpsToPercent(v.supplyRate),
11024
+ variableBorrowRate: 0,
11025
+ intrinsicYield: intrinsic(supAsset),
11026
+ liquidationBonus: penalty,
11027
+ config: { "0": collateralConfig },
11028
+ collateralActive: true,
11029
+ borrowingEnabled: false,
11030
+ depositsEnabled: true
11031
+ };
11032
+ const debtLeg = {
11033
+ ...common,
11034
+ marketUid: debtUid,
11035
+ name: `Loan ${borSym}`,
11036
+ poolId: bor.address,
11037
+ underlying: bor.address,
11038
+ asset: borAsset,
11039
+ decimals: bor.decimals,
11040
+ totalDeposits: "0",
11041
+ totalDebt: formatRawUnits(v.totalBorrow, bor.decimals),
11042
+ totalLiquidity: borrowable,
11043
+ borrowLiquidity: borrowable,
11044
+ totalDepositsUSD: 0,
11045
+ totalDebtUSD: borrowDebt * borPrice,
11046
+ totalLiquidityUSD: borrowable * borPrice,
11047
+ borrowLiquidityUSD: borrowable * borPrice,
11048
+ ...layerOf(bor.address),
11049
+ depositRate: 0,
11050
+ variableBorrowRate: bpsToPercent(v.borrowRate),
11051
+ intrinsicYield: intrinsic(borAsset),
11052
+ liquidationBonus: 0,
11053
+ originationFee: num(v.borrowFee) / 100,
11054
+ config: { "0": debtConfig },
11055
+ collateralActive: false,
11056
+ borrowingEnabled: true,
11057
+ depositsEnabled: false
11058
+ };
11059
+ const vault = {
11060
+ vaultAddress: v.address,
11061
+ vaultId: v.id,
11062
+ collateralAddress: sup.address,
11063
+ loanAddress: bor.address,
11064
+ collateralDecimals: sup.decimals,
11065
+ loanDecimals: bor.decimals,
11066
+ oracle: v.oracle,
11067
+ ltv,
11068
+ liquidationThreshold: lt,
11069
+ liquidationPenalty: penalty,
11070
+ oraclePriceOperate: jlOracleToFluidRaw(
11071
+ v.oraclePriceOperate,
11072
+ sup.decimals,
11073
+ bor.decimals
11074
+ ),
11075
+ oraclePriceLiquidate: jlOracleToFluidRaw(
11076
+ v.oraclePriceLiquidate,
11077
+ sup.decimals,
11078
+ bor.decimals
11079
+ ),
11080
+ isSmartCol: isJlSmartCol(v.type),
11081
+ isSmartDebt: isJlSmartDebt(v.type),
11082
+ vaultType: v.type <= 1 ? FLUID_VAULT_TYPE_T1 : FLUID_VAULT_TYPE_T1 * Math.min(4, v.type),
11083
+ collateral: {
11084
+ assets: [{ underlying: sup.address, decimals: sup.decimals }],
11085
+ dex: null,
11086
+ perShare: null
11087
+ },
11088
+ loan: {
11089
+ assets: [{ underlying: bor.address, decimals: bor.decimals }],
11090
+ dex: null,
11091
+ perShare: null
11092
+ }
11093
+ };
11094
+ const jupiterLendVault = {
11095
+ market,
11096
+ vaultId: v.id,
11097
+ address: v.address,
11098
+ type: v.type,
11099
+ supplyToken: sup.address,
11100
+ borrowToken: bor.address,
11101
+ supplyDecimals: sup.decimals,
11102
+ borrowDecimals: bor.decimals,
11103
+ collateralFactor: num(v.collateralFactor),
11104
+ liquidationThreshold: num(v.liquidationThreshold),
11105
+ liquidationMaxLimit: num(v.liquidationMaxLimit),
11106
+ withdrawalGap: num(v.withdrawalGap),
11107
+ liquidationPenalty: num(v.liquidationPenalty),
11108
+ borrowFee: num(v.borrowFee),
11109
+ supplyRateMagnifier: num(v.supplyRateMagnifier),
11110
+ borrowRateMagnifier: num(v.borrowRateMagnifier),
11111
+ supplyRateLiquidity: num(v.supplyRateLiquidity),
11112
+ borrowRateLiquidity: num(v.borrowRateLiquidity),
11113
+ minimumBorrowing: v.minimumBorrowing,
11114
+ totalPositions: v.totalPositions,
11115
+ borrowLimit: v.borrowLimit,
11116
+ borrowable: v.borrowable,
11117
+ withdrawLimit: v.withdrawLimit,
11118
+ withdrawable: v.withdrawable,
11119
+ oracle: v.oracle,
11120
+ oraclePrice: v.oraclePrice,
11121
+ oraclePriceOperate: v.oraclePriceOperate,
11122
+ oraclePriceLiquidate: v.oraclePriceLiquidate,
11123
+ oracleSources: v.oracleSources,
11124
+ oracleTimestamp: v.oracleTimestamp,
11125
+ liquiditySupplyData: v.liquiditySupplyData,
11126
+ liquidityBorrowData: v.liquidityBorrowData,
11127
+ topTick: v.topTick,
11128
+ metadata: v.metadata
11129
+ };
11130
+ return {
11131
+ lenderKey,
11132
+ chainId: SOLANA_CHAIN_ID,
11133
+ data: { [colUid]: collateralLeg, [debtUid]: debtLeg },
11134
+ params: { vault, jupiterLendVault }
11135
+ };
9707
11136
  }
9708
11137
 
9709
11138
  // src/lending/public-data/jupiter-lend/fetchPublic.ts
@@ -9717,8 +11146,37 @@ async function fetchJupiterLendPublic(opts = {}) {
9717
11146
  api.vaults(market),
9718
11147
  api.earnTokens(market)
9719
11148
  ]);
9720
- const layer = deriveLayerTotals(vaults, earn);
9721
11149
  const only = opts.vaultIds?.[market];
11150
+ let chain = [];
11151
+ if (opts.rpc && opts.enumerateOnchain !== false) {
11152
+ try {
11153
+ const next = await readJlNextVaultId(opts.rpc, market);
11154
+ const listed3 = new Set(vaults.map((v) => v.id));
11155
+ const ids = [];
11156
+ for (let id = 1; next && id < next; id++)
11157
+ if (!listed3.has(id) && (!only || only.includes(id))) ids.push(id);
11158
+ if (ids.length) {
11159
+ const tokens = {};
11160
+ for (const v of vaults) {
11161
+ tokens[v.supplyToken.address] ??= v.supplyToken;
11162
+ tokens[v.borrowToken.address] ??= v.borrowToken;
11163
+ }
11164
+ for (const e of earn) tokens[e.assetAddress] ??= e.asset;
11165
+ chain = await readJupiterLendVaultsOnchain(opts.rpc, market, ids, {
11166
+ tokens,
11167
+ tokenList: opts.tokenList
11168
+ });
11169
+ }
11170
+ } catch (e) {
11171
+ console.warn(
11172
+ `[jupiter-lend] on-chain enumeration of ${market} failed, serving the API's vaults only: ${e.message}`
11173
+ );
11174
+ }
11175
+ }
11176
+ const layer = deriveLayerTotals(
11177
+ [...vaults, ...chain.map((c) => c.vault)],
11178
+ earn
11179
+ );
9722
11180
  let flash;
9723
11181
  if (opts.rpc) {
9724
11182
  try {
@@ -9738,13 +11196,39 @@ async function fetchJupiterLendPublic(opts = {}) {
9738
11196
  );
9739
11197
  }
9740
11198
  }
9741
- for (const v of vaults) {
11199
+ const fromChain = new Map(chain.map((c) => [c.vault.id, c]));
11200
+ for (const v of [...vaults, ...chain.map((c) => c.vault)]) {
9742
11201
  if (only && !only.includes(v.id)) continue;
9743
11202
  const conv = convertJupiterLendVault(market, v, {
9744
11203
  tokenList: opts.tokenList,
9745
11204
  intrinsicYields: opts.intrinsicYields,
9746
11205
  layer
9747
11206
  });
11207
+ const cv = fromChain.get(v.id);
11208
+ const meta = conv.params.jupiterLendVault;
11209
+ meta.source = cv ? "chain" : "api";
11210
+ if (cv) {
11211
+ meta.slot = cv.slot;
11212
+ if (cv.smartCol || cv.smartDebt)
11213
+ meta.smart = {
11214
+ ...cv.smartCol ? {
11215
+ col: {
11216
+ dex: v.supplyToken.address,
11217
+ token0: cv.supplyDex?.token0,
11218
+ token1: cv.supplyDex?.token1
11219
+ }
11220
+ } : {},
11221
+ ...cv.smartDebt ? {
11222
+ debt: {
11223
+ dex: v.borrowToken.address,
11224
+ token0: cv.borrowDex?.token0,
11225
+ token1: cv.borrowDex?.token1
11226
+ }
11227
+ } : {}
11228
+ };
11229
+ const unpriced = [v.supplyToken, v.borrowToken].filter((t) => !(Number(t.price) > 0)).map((t) => t.address);
11230
+ if (unpriced.length) meta.unpriced = unpriced;
11231
+ }
9748
11232
  if (flash)
9749
11233
  conv.params.jupiterLendVault.flashloan = {
9750
11234
  feeBps: flash.feeBps,
@@ -10208,7 +11692,7 @@ var LS_NO_ACCOUNT = "11111111111111111111111111111111";
10208
11692
  var LS_U64_MAX = "18446744073709551615";
10209
11693
  var isUncapped = (v) => v === void 0 || v === null || String(v) === LS_U64_MAX;
10210
11694
  var capOrUndefined = (v) => isUncapped(v) ? void 0 : String(v);
10211
- var SECONDS_PER_YEAR = 31536e3;
11695
+ var SECONDS_PER_YEAR2 = 31536e3;
10212
11696
  var LS_TENORS = [
10213
11697
  { id: "1d", duration: { duration: 1, durationType: 0 }, days: 1 },
10214
11698
  { id: "1w", duration: { duration: 1, durationType: 1 }, days: 7 },
@@ -10364,6 +11848,8 @@ async function buildLoopscaleRoster(vaults, loops, opts = {}) {
10364
11848
  strategy: s.address,
10365
11849
  name: v.vaultMetadata?.name ?? v.vault.address,
10366
11850
  curator: v.vaultMetadata?.managerName ?? "",
11851
+ manager: v.vault.manager,
11852
+ managerImage: v.vaultMetadata?.managerImage ?? void 0,
10367
11853
  interestFee: Number(s.interestFee),
10368
11854
  originationFee: Number(s.originationFee),
10369
11855
  originationsEnabled: s.originationsEnabled,
@@ -10413,20 +11899,20 @@ async function buildLoopscaleRoster(vaults, loops, opts = {}) {
10413
11899
  const unresolved = [];
10414
11900
  if (toProbe.length && opts.rpc) {
10415
11901
  const mints = await getMints(opts.rpc, toProbe);
10416
- const dec = /* @__PURE__ */ new Map();
10417
- mints.forEach((m, i) => m && dec.set(toProbe[i], m.decimals));
11902
+ const dec2 = /* @__PURE__ */ new Map();
11903
+ mints.forEach((m, i) => m && dec2.set(toProbe[i], m.decimals));
10418
11904
  for (const pair of byKey.values()) {
10419
11905
  const c = pair.collateralIdentifier;
10420
- if (pair.assetType === -1 && dec.has(c)) {
11906
+ if (pair.assetType === -1 && dec2.has(c)) {
10421
11907
  pair.assetType = 0;
10422
11908
  pair.collateralMint = c;
10423
11909
  }
10424
11910
  if (pair.collateralMint && pair.collateralDecimals === void 0)
10425
- pair.collateralDecimals = dec.get(pair.collateralMint);
11911
+ pair.collateralDecimals = dec2.get(pair.collateralMint);
10426
11912
  if (pair.principalDecimals === void 0)
10427
- pair.principalDecimals = dec.get(pair.principalMint);
11913
+ pair.principalDecimals = dec2.get(pair.principalMint);
10428
11914
  }
10429
- for (const c of unknown) if (!dec.has(c)) unresolved.push(c);
11915
+ for (const c of unknown) if (!dec2.has(c)) unresolved.push(c);
10430
11916
  } else unresolved.push(...unknown);
10431
11917
  const pairs = [...byKey.values()].filter(
10432
11918
  (p) => (p.assetType === 0 || opts.includeUnresolvedCollateral) && (want ? want.has(key2(p.principalMint, p.collateralIdentifier)) : true)
@@ -10861,9 +12347,9 @@ import { createSvmRpc } from "@1delta/svm-kit";
10861
12347
 
10862
12348
  // src/lending/public-data/loopscale/accounts.ts
10863
12349
  import {
10864
- decodeIdlAccount as decodeIdlAccount3,
12350
+ decodeIdlAccount as decodeIdlAccount4,
10865
12351
  encodeBase58 as encodeBase583,
10866
- fromBase64 as fromBase643
12352
+ fromBase64 as fromBase644
10867
12353
  } from "@1delta/svm-kit";
10868
12354
 
10869
12355
  // src/lending/public-data/loopscale/idl/loopscale.json
@@ -17847,7 +19333,7 @@ var podDecimalToNumber = (p) => Number(podToBigInt(p)) / 1e18;
17847
19333
  var podBool = (p) => bytesOf(p)[0] !== 0;
17848
19334
  var raw = (v) => v;
17849
19335
  function decodeLoopscaleLoan(data) {
17850
- const r = raw(decodeIdlAccount3(LOOPSCALE_IDL, "Loan", data));
19336
+ const r = raw(decodeIdlAccount4(LOOPSCALE_IDL, "Loan", data));
17851
19337
  const zero = encodeBase583(new Uint8Array(32));
17852
19338
  const ledgers = r.ledgers.map(
17853
19339
  (l) => ({
@@ -17892,7 +19378,7 @@ function decodeLoopscaleLoan(data) {
17892
19378
  };
17893
19379
  }
17894
19380
  function decodeLoopscaleStrategy(data) {
17895
- const r = raw(decodeIdlAccount3(LOOPSCALE_IDL, "Strategy", data));
19381
+ const r = raw(decodeIdlAccount4(LOOPSCALE_IDL, "Strategy", data));
17896
19382
  return {
17897
19383
  version: r.version,
17898
19384
  nonce: r.nonce,
@@ -17929,12 +19415,12 @@ async function readLoopscaleLoans(rpc, loanAddresses) {
17929
19415
  return {
17930
19416
  slot,
17931
19417
  loans: accounts.map(
17932
- (a) => a && a.owner === LOOPSCALE_PROGRAM_ID ? decodeLoopscaleLoan(fromBase643(a.data[0])) : null
19418
+ (a) => a && a.owner === LOOPSCALE_PROGRAM_ID ? decodeLoopscaleLoan(fromBase644(a.data[0])) : null
17933
19419
  )
17934
19420
  };
17935
19421
  }
17936
19422
  function decodeLoopscaleMarketInformation(data) {
17937
- const r = raw(decodeIdlAccount3(LOOPSCALE_IDL, "MarketInformation", data));
19423
+ const r = raw(decodeIdlAccount4(LOOPSCALE_IDL, "MarketInformation", data));
17938
19424
  const zero = encodeBase583(new Uint8Array(32));
17939
19425
  const caps = (c) => ({
17940
19426
  max1hr: podToBigInt(c.max_1hr).toString(),
@@ -17984,7 +19470,7 @@ async function readLoopscaleMarketInformation(rpc, addresses) {
17984
19470
  try {
17985
19471
  out.set(
17986
19472
  unique[i],
17987
- decodeLoopscaleMarketInformation(fromBase643(a.data[0]))
19473
+ decodeLoopscaleMarketInformation(fromBase644(a.data[0]))
17988
19474
  );
17989
19475
  } catch (e) {
17990
19476
  console.warn(
@@ -18295,18 +19781,18 @@ function tenorsToQuote(pair, all) {
18295
19781
  return out;
18296
19782
  }
18297
19783
  function deriveLoopscalePrices(vaults, loops, pairs, tokenList, loanBook) {
18298
- const dec = /* @__PURE__ */ new Map();
18299
- for (const [m, t] of Object.entries(tokenList ?? {})) dec.set(m, t.decimals);
19784
+ const dec2 = /* @__PURE__ */ new Map();
19785
+ for (const [m, t] of Object.entries(tokenList ?? {})) dec2.set(m, t.decimals);
18300
19786
  for (const p of pairs) {
18301
19787
  if (p.principalDecimals !== void 0)
18302
- dec.set(p.principalMint, p.principalDecimals);
19788
+ dec2.set(p.principalMint, p.principalDecimals);
18303
19789
  if (p.collateralMint && p.collateralDecimals !== void 0)
18304
- dec.set(p.collateralMint, p.collateralDecimals);
19790
+ dec2.set(p.collateralMint, p.collateralDecimals);
18305
19791
  }
18306
19792
  const out = {};
18307
19793
  const best = /* @__PURE__ */ new Map();
18308
19794
  const offer = (mint, usd, raw2) => {
18309
- const d2 = dec.get(mint);
19795
+ const d2 = dec2.get(mint);
18310
19796
  if (d2 === void 0 || !usd || !(raw2 > 0)) return;
18311
19797
  if ((best.get(mint) ?? 0) < usd) {
18312
19798
  best.set(mint, usd);
@@ -18337,7 +19823,7 @@ function deriveLoopscalePrices(vaults, loops, pairs, tokenList, loanBook) {
18337
19823
  }
18338
19824
 
18339
19825
  // src/prices/pythPush.ts
18340
- import { fromBase64 as fromBase644 } from "@1delta/svm-kit";
19826
+ import { fromBase64 as fromBase645 } from "@1delta/svm-kit";
18341
19827
  var PYTH_RECEIVER_PROGRAM = "rec2HHDDnjLfj4kE7VyEtFA1HPGQLK33259532cRyHp";
18342
19828
  var PYTH_PRICE_UPDATE_V2_DISCRIMINATOR = [
18343
19829
  34,
@@ -18350,7 +19836,7 @@ var PYTH_PRICE_UPDATE_V2_DISCRIMINATOR = [
18350
19836
  205
18351
19837
  ];
18352
19838
  function decodePythPriceUpdate(data) {
18353
- const b = typeof data === "string" ? fromBase644(data) : data;
19839
+ const b = typeof data === "string" ? fromBase645(data) : data;
18354
19840
  for (let i = 0; i < 8; i++)
18355
19841
  if (b[i] !== PYTH_PRICE_UPDATE_V2_DISCRIMINATOR[i])
18356
19842
  throw new Error("pyth: account is not a PriceUpdateV2");
@@ -18485,10 +19971,10 @@ function createP0Api(opts = {}) {
18485
19971
 
18486
19972
  // src/lending/public-data/project0/accounts.ts
18487
19973
  import {
18488
- decodeBase58 as decodeBase583,
18489
- decodeIdlAccount as decodeIdlAccount4,
18490
- findProgramAddress as findProgramAddress3,
18491
- fromBase64 as fromBase645
19974
+ decodeBase58 as decodeBase584,
19975
+ decodeIdlAccount as decodeIdlAccount5,
19976
+ findProgramAddress as findProgramAddress4,
19977
+ fromBase64 as fromBase646
18492
19978
  } from "@1delta/svm-kit";
18493
19979
 
18494
19980
  // src/lending/public-data/project0/idl/marginfi.json
@@ -33353,34 +34839,34 @@ function decimalStringToI80F48(s) {
33353
34839
  for (let i = 0; i < 16; i++) out[i] = Number(u >> BigInt(8 * i) & 0xffn);
33354
34840
  return out;
33355
34841
  }
33356
- var utf83 = (s) => new TextEncoder().encode(s);
33357
- var pk3 = (address) => {
33358
- const b = decodeBase583(address);
34842
+ var utf84 = (s) => new TextEncoder().encode(s);
34843
+ var pk4 = (address) => {
34844
+ const b = decodeBase584(address);
33359
34845
  if (!b || b.length !== 32)
33360
34846
  throw new Error(`project0: not a 32-byte pubkey: ${address}`);
33361
34847
  return b;
33362
34848
  };
33363
- var u16le = (n) => {
34849
+ var u16le2 = (n) => {
33364
34850
  if (!Number.isInteger(n) || n < 0 || n > 65535)
33365
34851
  throw new Error(`project0: u16 out of range: ${n}`);
33366
34852
  return new Uint8Array([n & 255, n >> 8]);
33367
34853
  };
33368
- var p0LiquidityVaultAuthority = async (bank, programId = P0_PROGRAM_ID) => (await findProgramAddress3(
33369
- [utf83(P0_SEEDS.liquidityVaultAuthority), pk3(bank)],
34854
+ var p0LiquidityVaultAuthority = async (bank, programId = P0_PROGRAM_ID) => (await findProgramAddress4(
34855
+ [utf84(P0_SEEDS.liquidityVaultAuthority), pk4(bank)],
33370
34856
  programId
33371
34857
  )).address;
33372
- var p0LiquidityVault = async (bank, programId = P0_PROGRAM_ID) => (await findProgramAddress3(
33373
- [utf83(P0_SEEDS.liquidityVault), pk3(bank)],
34858
+ var p0LiquidityVault = async (bank, programId = P0_PROGRAM_ID) => (await findProgramAddress4(
34859
+ [utf84(P0_SEEDS.liquidityVault), pk4(bank)],
33374
34860
  programId
33375
34861
  )).address;
33376
- var p0FeeState = async (programId = P0_PROGRAM_ID) => (await findProgramAddress3([utf83(P0_SEEDS.feeState)], programId)).address;
33377
- var p0MarginfiAccountPda = async (authority, accountIndex = 0, opts = {}) => (await findProgramAddress3(
34862
+ var p0FeeState = async (programId = P0_PROGRAM_ID) => (await findProgramAddress4([utf84(P0_SEEDS.feeState)], programId)).address;
34863
+ var p0MarginfiAccountPda = async (authority, accountIndex = 0, opts = {}) => (await findProgramAddress4(
33378
34864
  [
33379
- utf83(P0_SEEDS.marginfiAccount),
33380
- pk3(opts.group ?? P0_MAIN_GROUP),
33381
- pk3(authority),
33382
- u16le(accountIndex),
33383
- u16le(opts.thirdPartyId ?? 0)
34865
+ utf84(P0_SEEDS.marginfiAccount),
34866
+ pk4(opts.group ?? P0_MAIN_GROUP),
34867
+ pk4(authority),
34868
+ u16le2(accountIndex),
34869
+ u16le2(opts.thirdPartyId ?? 0)
33384
34870
  ],
33385
34871
  opts.programId ?? P0_PROGRAM_ID
33386
34872
  )).address;
@@ -33464,8 +34950,8 @@ var bankConfig = (c) => ({
33464
34950
  cbEmaAlphaBps: c.cb_ema_alpha_bps
33465
34951
  });
33466
34952
  function decodeP0Bank(address, data, tokenSymbol) {
33467
- const bytes = typeof data === "string" ? fromBase645(data) : data;
33468
- const r = decodeIdlAccount4(P0_IDL, "Bank", bytes);
34953
+ const bytes2 = typeof data === "string" ? fromBase646(data) : data;
34954
+ const r = decodeIdlAccount5(P0_IDL, "Bank", bytes2);
33469
34955
  const entries = r.emode.emode_config.entries.filter((e) => e.collateral_bank_emode_tag !== 0).map((e) => ({
33470
34956
  collateralBankEmodeTag: e.collateral_bank_emode_tag,
33471
34957
  flags: e.flags,
@@ -33690,8 +35176,8 @@ var u32ToBasis = (v) => v / 4294967295 * 100;
33690
35176
  var P0_PAUSE_DURATION_SECONDS = 6 * 60 * 60;
33691
35177
  var p0GroupPausedAt = (g, now) => !!g?.panic.pausedFlag && (now < g.panic.pauseStartTimestamp || now - g.panic.pauseStartTimestamp < P0_PAUSE_DURATION_SECONDS);
33692
35178
  function decodeP0Group(address, data) {
33693
- const bytes = typeof data === "string" ? fromBase645(data) : data;
33694
- const r = decodeIdlAccount4(P0_IDL, "MarginfiGroup", bytes);
35179
+ const bytes2 = typeof data === "string" ? fromBase646(data) : data;
35180
+ const r = decodeIdlAccount5(P0_IDL, "MarginfiGroup", bytes2);
33695
35181
  return {
33696
35182
  address,
33697
35183
  admin: r.admin,
@@ -33724,11 +35210,11 @@ function decodeP0Group(address, data) {
33724
35210
  };
33725
35211
  }
33726
35212
  function decodeP0MarginfiAccount(address, data) {
33727
- const bytes = typeof data === "string" ? fromBase645(data) : data;
33728
- const r = decodeIdlAccount4(
35213
+ const bytes2 = typeof data === "string" ? fromBase646(data) : data;
35214
+ const r = decodeIdlAccount5(
33729
35215
  P0_IDL,
33730
35216
  "MarginfiAccount",
33731
- bytes
35217
+ bytes2
33732
35218
  );
33733
35219
  const h = r.health_cache;
33734
35220
  return {
@@ -33780,10 +35266,10 @@ var P0_GROUP_SIZE = 9256;
33780
35266
  var P0_ACCOUNT_GROUP_OFFSET = 8;
33781
35267
  var P0_ACCOUNT_AUTHORITY_OFFSET = 8 + 32;
33782
35268
  var P0_BANK_GROUP_OFFSET = 8 + 32 + 1;
33783
- var p0BankMetadataPda = async (bank, programId = P0_PROGRAM_ID) => (await findProgramAddress3([utf83("metadata"), pk3(bank)], programId)).address;
35269
+ var p0BankMetadataPda = async (bank, programId = P0_PROGRAM_ID) => (await findProgramAddress4([utf84("metadata"), pk4(bank)], programId)).address;
33784
35270
  function decodeP0BankMetadata(data) {
33785
- const bytes = typeof data === "string" ? fromBase645(data) : data;
33786
- const r = decodeIdlAccount4(P0_IDL, "BankMetadata", bytes);
35271
+ const bytes2 = typeof data === "string" ? fromBase646(data) : data;
35272
+ const r = decodeIdlAccount5(P0_IDL, "BankMetadata", bytes2);
33787
35273
  const td = new TextDecoder();
33788
35274
  const ticker = td.decode(r.ticker.subarray(0, r.end_ticker_byte)).trim();
33789
35275
  const description = td.decode(r.description.subarray(0, r.end_description_byte)).trim();
@@ -33933,7 +35419,7 @@ function p0CurveKnots(c) {
33933
35419
  }
33934
35420
 
33935
35421
  // src/vaults/lst/stakePool.ts
33936
- import { BorshReader, encodeBase58 as encodeBase584, fromBase64 as fromBase646 } from "@1delta/svm-kit";
35422
+ import { BorshReader, encodeBase58 as encodeBase584, fromBase64 as fromBase647 } from "@1delta/svm-kit";
33937
35423
  var SPL_STAKE_POOL_PROGRAM = "SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy";
33938
35424
  var OFFSET_RESERVE_STAKE = 130;
33939
35425
  var OFFSET_POOL_MINT = 162;
@@ -34009,7 +35495,7 @@ async function readStakePools(rpc, stakePools, opts = {}) {
34009
35495
  const pools = accounts.map((a) => {
34010
35496
  if (!a || a.owner !== program) return null;
34011
35497
  try {
34012
- return decodeStakePool(fromBase646(a.data[0]));
35498
+ return decodeStakePool(fromBase647(a.data[0]));
34013
35499
  } catch {
34014
35500
  return null;
34015
35501
  }
@@ -34061,7 +35547,127 @@ async function readEpochClock(rpc) {
34061
35547
  }
34062
35548
 
34063
35549
  // src/lending/public-data/project0/prices.ts
34064
- import { fromBase64 as fromBase647 } from "@1delta/svm-kit";
35550
+ import { fromBase64 as fromBase649 } from "@1delta/svm-kit";
35551
+
35552
+ // src/prices/oracleAccounts.ts
35553
+ import { fromBase64 as fromBase648 } from "@1delta/svm-kit";
35554
+ var PYTH_PRICE_UPDATE_OWNERS = /* @__PURE__ */ new Set([
35555
+ "rec5EKMGg6MxZYaMdyBfgwp4d5rB9T1VQH5pJv5LtFJ",
35556
+ "rec2HHDDnjLfj4kE7VyEtFA1HPGQLK33259532cRyHp"
35557
+ ]);
35558
+ var PYTH_LEGACY_PROGRAM = "FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epH";
35559
+ var SWITCHBOARD_ON_DEMAND_PROGRAM = "SBondMDrcV3K4kxZR1HNVT7osZxAHVHgYXL5Ze1oMUv";
35560
+ var SWITCHBOARD_V2_PROGRAM = "SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f";
35561
+ var SCOPE_PROGRAM = "HFn8GnPADiny6XqUoWE8uRPPxb29ikn4yTuPa9MF2fWJ";
35562
+ var MARINADE_PROGRAM = "MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD";
35563
+ var bytes = (data) => typeof data === "string" ? fromBase648(data) : data;
35564
+ var view = (b) => new DataView(b.buffer, b.byteOffset, b.byteLength);
35565
+ var i128 = (b, o) => {
35566
+ const dv = view(b);
35567
+ const lo = dv.getBigUint64(o, true);
35568
+ const hi = dv.getBigInt64(o + 8, true);
35569
+ return (hi << 64n) + lo;
35570
+ };
35571
+ var disc = (b, d2) => d2.every((x, i) => b[i] === x);
35572
+ var SB_PULL_FEED_DISCRIMINATOR = [196, 27, 108, 196, 10, 215, 219, 40];
35573
+ var SB_V2_AGGREGATOR_DISCRIMINATOR = [
35574
+ 217,
35575
+ 230,
35576
+ 65,
35577
+ 101,
35578
+ 201,
35579
+ 162,
35580
+ 27,
35581
+ 125
35582
+ ];
35583
+ var PYTH_LEGACY_MAGIC = 2712847316;
35584
+ function decodeSwitchboardPullFeed(data) {
35585
+ const b = bytes(data);
35586
+ if (!disc(b, SB_PULL_FEED_DISCRIMINATOR) || b.length < 2392)
35587
+ throw new Error("switchboard: account is not a PullFeedAccountData");
35588
+ const dv = view(b);
35589
+ const value = i128(b, 2264);
35590
+ return {
35591
+ kind: "switchboard-on-demand",
35592
+ price: Number(value) / 1e18,
35593
+ updatedAt: Number(dv.getBigInt64(2216, true)),
35594
+ slot: Number(dv.getBigUint64(2368, true)),
35595
+ name: new TextDecoder().decode(b.subarray(2180, 2212)).replace(/\0+$/, "")
35596
+ };
35597
+ }
35598
+ function decodeSwitchboardV2Aggregator(data) {
35599
+ const b = bytes(data);
35600
+ if (!disc(b, SB_V2_AGGREGATOR_DISCRIMINATOR) || b.length < 386)
35601
+ throw new Error("switchboard: account is not an AggregatorAccountData");
35602
+ const dv = view(b);
35603
+ const mantissa = i128(b, 366);
35604
+ const scale = dv.getUint32(382, true);
35605
+ return {
35606
+ kind: "switchboard-v2",
35607
+ price: Number(mantissa) / 10 ** scale,
35608
+ updatedAt: Number(dv.getBigInt64(358, true)),
35609
+ slot: Number(dv.getBigUint64(350, true)),
35610
+ name: new TextDecoder().decode(b.subarray(8, 40)).replace(/\0+$/, "")
35611
+ };
35612
+ }
35613
+ function decodePythLegacyPrice(data) {
35614
+ const b = bytes(data);
35615
+ const dv = view(b);
35616
+ if (b.length < 240 || dv.getUint32(0, true) !== PYTH_LEGACY_MAGIC)
35617
+ throw new Error("pyth: account is not a legacy price account");
35618
+ if (dv.getUint32(8, true) !== 3)
35619
+ throw new Error("pyth: legacy account is not a PRICE account");
35620
+ const expo = dv.getInt32(20, true);
35621
+ return {
35622
+ kind: "pyth-legacy",
35623
+ price: Number(dv.getBigInt64(208, true)) * 10 ** expo,
35624
+ updatedAt: Number(dv.getBigInt64(96, true)),
35625
+ slot: Number(dv.getBigUint64(232, true)),
35626
+ status: dv.getUint32(224, true)
35627
+ };
35628
+ }
35629
+ var SCOPE_PRICES_LEN = 512;
35630
+ function decodeScopePrice(data, index) {
35631
+ const b = bytes(data);
35632
+ if (!Number.isInteger(index) || index < 0 || index >= SCOPE_PRICES_LEN)
35633
+ throw new Error(`scope: entry index ${index} out of range`);
35634
+ const o = 8 + 32 + index * 56;
35635
+ if (b.length < o + 32) throw new Error("scope: account too short");
35636
+ const dv = view(b);
35637
+ const value = dv.getBigUint64(o, true);
35638
+ const exp = Number(dv.getBigUint64(o + 8, true));
35639
+ return {
35640
+ kind: "scope",
35641
+ price: Number(value) / 10 ** exp,
35642
+ updatedAt: Number(dv.getBigUint64(o + 24, true)),
35643
+ slot: Number(dv.getBigUint64(o + 16, true))
35644
+ };
35645
+ }
35646
+ function decodeMarinadeMsolPrice(data) {
35647
+ const b = bytes(data);
35648
+ if (b.length < 520) throw new Error("marinade: account too short");
35649
+ return Number(view(b).getBigUint64(512, true)) / 2 ** 32;
35650
+ }
35651
+ function decodeOracleFeed(account) {
35652
+ const b = bytes(account.data);
35653
+ if (PYTH_PRICE_UPDATE_OWNERS.has(account.owner) && disc(b, PYTH_PRICE_UPDATE_V2_DISCRIMINATOR)) {
35654
+ const p = decodePythPriceUpdate(b);
35655
+ return {
35656
+ kind: "pyth-push",
35657
+ price: p.priceUsd,
35658
+ updatedAt: p.publishTime,
35659
+ slot: p.postedSlot
35660
+ };
35661
+ }
35662
+ if (account.owner === SWITCHBOARD_ON_DEMAND_PROGRAM)
35663
+ return decodeSwitchboardPullFeed(b);
35664
+ if (account.owner === SWITCHBOARD_V2_PROGRAM)
35665
+ return decodeSwitchboardV2Aggregator(b);
35666
+ if (account.owner === PYTH_LEGACY_PROGRAM) return decodePythLegacyPrice(b);
35667
+ return void 0;
35668
+ }
35669
+
35670
+ // src/lending/public-data/project0/prices.ts
34065
35671
  var P0_PYTH_PUSH_SETUPS = /* @__PURE__ */ new Set([
34066
35672
  "PythPushOracle",
34067
35673
  "StakedWithPythPush",
@@ -34099,6 +35705,7 @@ var stakePoolKeyOf = (b) => {
34099
35705
  return void 0;
34100
35706
  }
34101
35707
  };
35708
+ var marinadeKeyOf = (b) => b.config.oracleSetup === "PythMSOL" ? b.config.oracleKeys[1] : void 0;
34102
35709
  var isP0FixedSetup = (setup) => setup.startsWith("Fixed");
34103
35710
  var P0_STAKE_POOL_PROGRAMS = /* @__PURE__ */ new Set([
34104
35711
  SPL_STAKE_POOL_PROGRAM,
@@ -34109,6 +35716,8 @@ var DRIFT_SCALED_BALANCE_DECIMALS = 9;
34109
35716
  async function resolveP0Prices(rpc, banks, opts = {}) {
34110
35717
  const pythKeys = /* @__PURE__ */ new Set();
34111
35718
  const poolKeys = /* @__PURE__ */ new Set();
35719
+ const marinadeKeys = /* @__PURE__ */ new Set();
35720
+ const scopeKeys = /* @__PURE__ */ new Set();
34112
35721
  if (!opts.cacheOnly && rpc)
34113
35722
  for (const b of banks) {
34114
35723
  if (P0_PYTH_PUSH_SETUPS.has(b.config.oracleSetup)) {
@@ -34117,12 +35726,20 @@ async function resolveP0Prices(rpc, banks, opts = {}) {
34117
35726
  }
34118
35727
  const pool = stakePoolKeyOf(b);
34119
35728
  if (!isNullKey(pool)) poolKeys.add(pool);
35729
+ const msol = marinadeKeyOf(b);
35730
+ if (!isNullKey(msol)) marinadeKeys.add(msol);
35731
+ if (b.config.oracleSetup === "Scope") {
35732
+ const k = b.config.oracleKeys[0];
35733
+ if (!isNullKey(k)) scopeKeys.add(k);
35734
+ }
34120
35735
  }
34121
35736
  const pyth = {};
34122
35737
  const poolRate = {};
35738
+ const msolRate = {};
35739
+ const scopeData = {};
34123
35740
  let slot = 0;
34124
- if (pythKeys.size || poolKeys.size) {
34125
- const keys = [...pythKeys, ...poolKeys];
35741
+ if (pythKeys.size || poolKeys.size || marinadeKeys.size || scopeKeys.size) {
35742
+ const keys = [...pythKeys, ...poolKeys, ...marinadeKeys, ...scopeKeys];
34126
35743
  const res = await rpc.readAccounts(keys, { encoding: "base64" });
34127
35744
  slot = res.slot;
34128
35745
  res.accounts.forEach((a, i) => {
@@ -34132,8 +35749,15 @@ async function resolveP0Prices(rpc, banks, opts = {}) {
34132
35749
  if (pythKeys.has(key2)) {
34133
35750
  if (a.owner === PYTH_RECEIVER_PROGRAM)
34134
35751
  pyth[key2] = decodePythPriceUpdate(a.data[0]);
35752
+ } else if (marinadeKeys.has(key2)) {
35753
+ if (a.owner === MARINADE_PROGRAM) {
35754
+ const r = decodeMarinadeMsolPrice(a.data[0]);
35755
+ if (r > 0) msolRate[key2] = r;
35756
+ }
35757
+ } else if (scopeKeys.has(key2)) {
35758
+ if (a.owner === SCOPE_PROGRAM) scopeData[key2] = fromBase649(a.data[0]);
34135
35759
  } else if (P0_STAKE_POOL_PROGRAMS.has(a.owner)) {
34136
- const p = decodeStakePool(fromBase647(a.data[0]));
35760
+ const p = decodeStakePool(fromBase649(a.data[0]));
34137
35761
  if (p.poolTokenSupply > 0n)
34138
35762
  poolRate[key2] = Number(p.totalLamports) / Number(p.poolTokenSupply);
34139
35763
  }
@@ -34160,8 +35784,15 @@ async function resolveP0Prices(rpc, banks, opts = {}) {
34160
35784
  }
34161
35785
  const feed = b.config.oracleKeys[0];
34162
35786
  const live = feed && !isNullKey(feed) ? pyth[feed] : void 0;
34163
- const pool = stakePoolKeyOf(b);
34164
- const liveRate = pool ? poolRate[pool] : void 0;
35787
+ const pool = stakePoolKeyOf(b) ?? marinadeKeyOf(b);
35788
+ const liveRate = pool ? poolRate[pool] ?? msolRate[pool] : void 0;
35789
+ let scope;
35790
+ if (setup === "Scope" && feed && scopeData[feed])
35791
+ try {
35792
+ scope = decodeScopePrice(scopeData[feed], b.config.scopeEntryIndex);
35793
+ } catch (e) {
35794
+ console.warn(`[project0] scope ${feed}: ${e.message}`);
35795
+ }
34165
35796
  let liveMult = 1;
34166
35797
  let liveMultNote = "";
34167
35798
  if (P0_CACHED_PRICE_MULTIPLIER_SETUPS.has(setup)) {
@@ -34169,7 +35800,7 @@ async function resolveP0Prices(rpc, banks, opts = {}) {
34169
35800
  liveMultNote = `cached SVSP rate ${cacheMult?.toFixed(6)} as of ${cacheTs}`;
34170
35801
  } else if (P0_ADJUSTED_CACHE_SETUPS.has(setup)) {
34171
35802
  liveMult = liveRate ?? null;
34172
- liveMultNote = liveRate ? `SPL stake pool ${pool} rate ${liveRate.toFixed(6)}` : "";
35803
+ liveMultNote = liveRate ? `${msolRate[pool] ? "Marinade state" : "SPL stake pool"} ${pool} rate ${liveRate.toFixed(6)}` : "";
34173
35804
  }
34174
35805
  let out;
34175
35806
  if (isP0FixedSetup(setup)) {
@@ -34186,6 +35817,15 @@ async function resolveP0Prices(rpc, banks, opts = {}) {
34186
35817
  multiplier: 1,
34187
35818
  description: `admin-set fixed price (${setup})`
34188
35819
  };
35820
+ } else if (scope && scope.price > 0) {
35821
+ out = {
35822
+ priceUsd: scope.price,
35823
+ source: "scope",
35824
+ updatedAt: scope.updatedAt || void 0,
35825
+ multiplier: 1,
35826
+ feed,
35827
+ description: `Scope ${feed} entry ${b.config.scopeEntryIndex} (${setup})`
35828
+ };
34189
35829
  } else if (live && liveMult !== null && liveMult > 0) {
34190
35830
  out = {
34191
35831
  priceUsd: live.priceUsd * liveMult,
@@ -35103,9 +36743,9 @@ function liquidityRatio(liquidity, totalAssets) {
35103
36743
  // src/vaults/jupiter-lend/index.ts
35104
36744
  function convertJupiterLendEarnToken(market, t, tokenList) {
35105
36745
  const price = num(t.asset.price);
35106
- const dec = t.asset.decimals;
35107
- const totalAssetsFormatted = Number(t.totalAssets) / 10 ** dec;
35108
- const liquidityFormatted = Number(t.liquiditySupplyData.withdrawable) / 10 ** dec;
36746
+ const dec2 = t.asset.decimals;
36747
+ const totalAssetsFormatted = Number(t.totalAssets) / 10 ** dec2;
36748
+ const liquidityFormatted = Number(t.liquiditySupplyData.withdrawable) / 10 ** dec2;
35109
36749
  const sharePrice = Number(t.convertToAssets) / 10 ** t.decimals;
35110
36750
  const supplyRate = bpsToPercent(t.supplyRate);
35111
36751
  const rewardsRate = bpsToPercent(t.rewardsRate);
@@ -35114,7 +36754,7 @@ function convertJupiterLendEarnToken(market, t, tokenList) {
35114
36754
  address: t.assetAddress,
35115
36755
  symbol: t.asset.uiSymbol,
35116
36756
  name: t.asset.name,
35117
- decimals: dec,
36757
+ decimals: dec2,
35118
36758
  ...t.asset.logoUrl ? { logoURI: t.asset.logoUrl } : {}
35119
36759
  };
35120
36760
  return {
@@ -35129,7 +36769,7 @@ function convertJupiterLendEarnToken(market, t, tokenList) {
35129
36769
  displayName: `Jupiter Lend ${t.asset.uiSymbol}`,
35130
36770
  curatorName: "Jupiter",
35131
36771
  decimals: t.decimals,
35132
- assetDecimals: dec,
36772
+ assetDecimals: dec2,
35133
36773
  totalAssets: t.totalAssets,
35134
36774
  totalSupply: t.totalSupply,
35135
36775
  convertToShares: t.convertToShares,
@@ -35388,11 +37028,11 @@ async function fetchExponentPtMarkets(opts = {}) {
35388
37028
 
35389
37029
  // src/vaults/solstice/accounts.ts
35390
37030
  import {
35391
- decodeBase58 as decodeBase584,
35392
- decodeIdlAccount as decodeIdlAccount5,
37031
+ decodeBase58 as decodeBase585,
37032
+ decodeIdlAccount as decodeIdlAccount6,
35393
37033
  encodeBase58 as encodeBase585,
35394
- findProgramAddress as findProgramAddress4,
35395
- fromBase64 as fromBase648
37034
+ findProgramAddress as findProgramAddress5,
37035
+ fromBase64 as fromBase6410
35396
37036
  } from "@1delta/svm-kit";
35397
37037
 
35398
37038
  // src/vaults/solstice/idl/yield_strategy.json
@@ -46062,14 +47702,14 @@ var SOLSTICE_MINTS = {
46062
47702
  var SOLSTICE_STRATEGIES = ["STRC-USX"];
46063
47703
  var SOLSTICE_DECIMALS = 6;
46064
47704
  var SOLSTICE_PRICE_DECIMALS = 6;
46065
- var utf84 = (s) => new TextEncoder().encode(s);
46066
- var pk4 = (address) => {
46067
- const b = decodeBase584(address);
47705
+ var utf85 = (s) => new TextEncoder().encode(s);
47706
+ var pk5 = (address) => {
47707
+ const b = decodeBase585(address);
46068
47708
  if (!b || b.length !== 32)
46069
47709
  throw new Error(`solstice: not a 32-byte pubkey: ${address}`);
46070
47710
  return b;
46071
47711
  };
46072
- var pda = async (seeds, programId) => (await findProgramAddress4(seeds, programId)).address;
47712
+ var pda = async (seeds, programId) => (await findProgramAddress5(seeds, programId)).address;
46073
47713
  async function yieldVaultPdas(programId = SOLSTICE_PROGRAMS.yieldVault) {
46074
47714
  const [controller, yieldPool, vestingSchedule, shareMint, assetVault] = await Promise.all(
46075
47715
  [
@@ -46078,19 +47718,19 @@ async function yieldVaultPdas(programId = SOLSTICE_PROGRAMS.yieldVault) {
46078
47718
  "VESTING_SCHEDULE",
46079
47719
  "SHARE_MINT",
46080
47720
  "ASSET_VAULT"
46081
- ].map((s) => pda([utf84(s)], programId))
47721
+ ].map((s) => pda([utf85(s)], programId))
46082
47722
  );
46083
47723
  return { controller, yieldPool, vestingSchedule, shareMint, assetVault };
46084
47724
  }
46085
47725
  async function yieldVaultCooldownPdas(user, programId = SOLSTICE_PROGRAMS.yieldVault) {
46086
47726
  const [escrow, escrowVault] = await Promise.all([
46087
- pda([utf84("COOLDOWN_ESCROW"), pk4(user)], programId),
46088
- pda([utf84("COOLDOWN_ESCROW_VAULT"), pk4(user)], programId)
47727
+ pda([utf85("COOLDOWN_ESCROW"), pk5(user)], programId),
47728
+ pda([utf85("COOLDOWN_ESCROW_VAULT"), pk5(user)], programId)
46089
47729
  ]);
46090
47730
  return { escrow, escrowVault };
46091
47731
  }
46092
47732
  async function strategyPdas(name, programId = SOLSTICE_PROGRAMS.yieldStrategy) {
46093
- const n = utf84(name);
47733
+ const n = utf85(name);
46094
47734
  if (n.length < 1 || n.length > 32)
46095
47735
  throw new Error(`solstice: strategy name must be 1..=32 bytes: ${name}`);
46096
47736
  const [
@@ -46102,13 +47742,13 @@ async function strategyPdas(name, programId = SOLSTICE_PROGRAMS.yieldStrategy) {
46102
47742
  assetVault,
46103
47743
  feeVault
46104
47744
  ] = await Promise.all([
46105
- pda([utf84("CONTROLLER")], programId),
46106
- pda([utf84("STRATEGY"), n], programId),
46107
- pda([utf84("ACCOUNTING"), n], programId),
46108
- pda([utf84("JUNIOR_MINT"), n], programId),
46109
- pda([utf84("SENIOR_MINT"), n], programId),
46110
- pda([utf84("ASSET_VAULT"), n], programId),
46111
- pda([utf84("FEE_VAULT"), n], programId)
47745
+ pda([utf85("CONTROLLER")], programId),
47746
+ pda([utf85("STRATEGY"), n], programId),
47747
+ pda([utf85("ACCOUNTING"), n], programId),
47748
+ pda([utf85("JUNIOR_MINT"), n], programId),
47749
+ pda([utf85("SENIOR_MINT"), n], programId),
47750
+ pda([utf85("ASSET_VAULT"), n], programId),
47751
+ pda([utf85("FEE_VAULT"), n], programId)
46112
47752
  ]);
46113
47753
  return {
46114
47754
  name,
@@ -46123,10 +47763,10 @@ async function strategyPdas(name, programId = SOLSTICE_PROGRAMS.yieldStrategy) {
46123
47763
  }
46124
47764
  async function settlementBatchPdas(strategyName, batchName, programId = SOLSTICE_PROGRAMS.yieldStrategy) {
46125
47765
  const seeds = (tag) => [
46126
- utf84(tag),
46127
- utf84(strategyName),
47766
+ utf85(tag),
47767
+ utf85(strategyName),
46128
47768
  Uint8Array.of(0),
46129
- utf84(batchName)
47769
+ utf85(batchName)
46130
47770
  ];
46131
47771
  const [batch, shareVault, assetVault] = await Promise.all([
46132
47772
  pda(seeds("SETTLEMENT_BATCH"), programId),
@@ -46135,34 +47775,34 @@ async function settlementBatchPdas(strategyName, batchName, programId = SOLSTICE
46135
47775
  ]);
46136
47776
  return { batch, shareVault, assetVault };
46137
47777
  }
46138
- var juniorUnlockSharePda = (batch, user, programId = SOLSTICE_PROGRAMS.yieldStrategy) => pda([utf84("JUNIOR_UNLOCK_SHARE"), pk4(batch), pk4(user)], programId);
47778
+ var juniorUnlockSharePda = (batch, user, programId = SOLSTICE_PROGRAMS.yieldStrategy) => pda([utf85("JUNIOR_UNLOCK_SHARE"), pk5(batch), pk5(user)], programId);
46139
47779
  async function seniorCooldownPdas(strategyName, user, programId = SOLSTICE_PROGRAMS.yieldStrategy) {
46140
47780
  const [cooldown, cooldownVault] = await Promise.all([
46141
47781
  pda(
46142
- [utf84("SENIOR_UNLOCK_COOLDOWN"), utf84(strategyName), pk4(user)],
47782
+ [utf85("SENIOR_UNLOCK_COOLDOWN"), utf85(strategyName), pk5(user)],
46143
47783
  programId
46144
47784
  ),
46145
47785
  pda(
46146
- [utf84("SENIOR_COOLDOWN_VAULT"), utf84(strategyName), pk4(user)],
47786
+ [utf85("SENIOR_COOLDOWN_VAULT"), utf85(strategyName), pk5(user)],
46147
47787
  programId
46148
47788
  )
46149
47789
  ]);
46150
47790
  return { cooldown, cooldownVault };
46151
47791
  }
46152
- var oracleCanonicalPda = (feedId, programId = SOLSTICE_PROGRAMS.oracle) => pda([utf84("CANONICAL"), utf84(feedId)], programId);
47792
+ var oracleCanonicalPda = (feedId, programId = SOLSTICE_PROGRAMS.oracle) => pda([utf85("CANONICAL"), utf85(feedId)], programId);
46153
47793
  var strategyNameOf = (raw2) => new TextDecoder().decode(raw2).replace(/\0+$/, "");
46154
47794
  var YV = SOLSTICE_YIELD_VAULT_IDL;
46155
47795
  var YS = SOLSTICE_YIELD_STRATEGY_IDL;
46156
- var decodeController = (d2) => decodeIdlAccount5(YV, "Controller", d2);
46157
- var decodeYieldPool = (d2) => decodeIdlAccount5(YV, "YieldPool", d2);
46158
- var decodeVestingSchedule = (d2) => decodeIdlAccount5(YV, "VestingSchedule", d2);
46159
- var decodeCooldownEscrow = (d2) => decodeIdlAccount5(YV, "CooldownEscrow", d2);
46160
- var decodeStrategyController = (d2) => decodeIdlAccount5(YS, "Controller", d2);
46161
- var decodeStrategy = (d2) => decodeIdlAccount5(YS, "Strategy", d2);
46162
- var decodeAccountingState = (d2) => decodeIdlAccount5(YS, "AccountingState", d2);
46163
- var decodeSettlementBatch = (d2) => decodeIdlAccount5(YS, "SettlementBatch", d2);
46164
- var decodeJuniorUnlockShare = (d2) => decodeIdlAccount5(YS, "JuniorUnlockShare", d2);
46165
- var decodeSeniorUnlockCooldown = (d2) => decodeIdlAccount5(YS, "SeniorUnlockCooldown", d2);
47796
+ var decodeController = (d2) => decodeIdlAccount6(YV, "Controller", d2);
47797
+ var decodeYieldPool = (d2) => decodeIdlAccount6(YV, "YieldPool", d2);
47798
+ var decodeVestingSchedule = (d2) => decodeIdlAccount6(YV, "VestingSchedule", d2);
47799
+ var decodeCooldownEscrow = (d2) => decodeIdlAccount6(YV, "CooldownEscrow", d2);
47800
+ var decodeStrategyController = (d2) => decodeIdlAccount6(YS, "Controller", d2);
47801
+ var decodeStrategy = (d2) => decodeIdlAccount6(YS, "Strategy", d2);
47802
+ var decodeAccountingState = (d2) => decodeIdlAccount6(YS, "AccountingState", d2);
47803
+ var decodeSettlementBatch = (d2) => decodeIdlAccount6(YS, "SettlementBatch", d2);
47804
+ var decodeJuniorUnlockShare = (d2) => decodeIdlAccount6(YS, "JuniorUnlockShare", d2);
47805
+ var decodeSeniorUnlockCooldown = (d2) => decodeIdlAccount6(YS, "SeniorUnlockCooldown", d2);
46166
47806
  function accountDiscriminator(idl, name) {
46167
47807
  const a = idl.accounts.find((x) => x.name === name);
46168
47808
  if (!a) throw new Error(`idl ${idl.metadata?.name}: no account ${name}`);
@@ -46209,7 +47849,7 @@ function tokenAmount(data) {
46209
47849
  }
46210
47850
  var need = (a, what) => {
46211
47851
  if (!a) throw new Error(`solstice: ${what} account is missing`);
46212
- return fromBase648(a.data[0]);
47852
+ return fromBase6410(a.data[0]);
46213
47853
  };
46214
47854
  async function readSolsticeChainState(rpc, opts = {}) {
46215
47855
  const programs = { ...SOLSTICE_PROGRAMS, ...opts.programs };
@@ -46274,7 +47914,7 @@ async function readSolsticeChainState(rpc, opts = {}) {
46274
47914
  const raw2 = r.accounts[j++];
46275
47915
  s.oracleAccount = feeds[i];
46276
47916
  if (raw2)
46277
- s.oracle = decodeOracleCanonical(fromBase648(raw2.data[0])) ?? void 0;
47917
+ s.oracle = decodeOracleCanonical(fromBase6410(raw2.data[0])) ?? void 0;
46278
47918
  });
46279
47919
  }
46280
47920
  return { slot, yieldVault, strategies };
@@ -46291,7 +47931,7 @@ function createSolsticeAppApi(opts = {}) {
46291
47931
  }
46292
47932
 
46293
47933
  // src/vaults/solstice/math.ts
46294
- var SECONDS_PER_YEAR2 = 31536000n;
47934
+ var SECONDS_PER_YEAR3 = 31536000n;
46295
47935
  var bigMax0 = (v) => v > 0n ? v : 0n;
46296
47936
  function unvestedAt(amount, start, end, now) {
46297
47937
  if (start === 0n && end === 0n) return 0n;
@@ -46330,7 +47970,7 @@ function eusxAssetsToShares(assets, r) {
46330
47970
  function epochRatePercent(vesting, assetsIncludingVesting, epochSeconds) {
46331
47971
  const principal = assetsIncludingVesting - vesting;
46332
47972
  if (vesting < 0n || principal <= 0n || epochSeconds <= 0n) return void 0;
46333
- const perYear = Number(SECONDS_PER_YEAR2) / Number(epochSeconds);
47973
+ const perYear = Number(SECONDS_PER_YEAR3) / Number(epochSeconds);
46334
47974
  return Number(vesting) / Number(principal) * perYear * 100;
46335
47975
  }
46336
47976
  var eusxEpochRatePercent = (pool, vesting) => epochRatePercent(
@@ -46389,7 +48029,7 @@ function strategyMode(s, oraclePriceUsd, priceDecimals = 6) {
46389
48029
  import {
46390
48030
  createSvmFetchers,
46391
48031
  createSvmRpc as createSvmRpc3,
46392
- fromBase64 as fromBase649
48032
+ fromBase64 as fromBase6411
46393
48033
  } from "@1delta/svm-kit";
46394
48034
  var SCALE = 10 ** SOLSTICE_DECIMALS;
46395
48035
  var fmt3 = (raw2) => Number(raw2) / SCALE;
@@ -46413,7 +48053,7 @@ async function fetchSolsticeSettlementBatches(rpc, strategyName, juniorQueueTime
46413
48053
  );
46414
48054
  const out = [];
46415
48055
  for (const r of rows) {
46416
- const b = decodeSettlementBatch(fromBase649(r.account.data[0]));
48056
+ const b = decodeSettlementBatch(fromBase6411(r.account.data[0]));
46417
48057
  if (strategyNameOf(b.strategy_name) !== strategyName) continue;
46418
48058
  const settlementTime = Number(b.settlement_time);
46419
48059
  out.push({
@@ -46719,7 +48359,7 @@ async function fetchSolsticeVaults(opts = {}) {
46719
48359
  // src/vaults/solstice/fetchUser.ts
46720
48360
  import {
46721
48361
  createSvmRpc as createSvmRpc4,
46722
- fromBase64 as fromBase6410,
48362
+ fromBase64 as fromBase6412,
46723
48363
  getAssociatedTokenAddress as getAssociatedTokenAddress2,
46724
48364
  TOKEN_PROGRAM
46725
48365
  } from "@1delta/svm-kit";
@@ -46760,10 +48400,10 @@ async function fetchSolsticeUser(account, opts = {}) {
46760
48400
  const { slot, accounts } = await rpc.readAccounts(keys);
46761
48401
  let i = 0;
46762
48402
  const next = () => accounts[i++] ?? null;
46763
- const bytes = (a) => a ? fromBase6410(a.data[0]) : void 0;
48403
+ const bytes2 = (a) => a ? fromBase6412(a.data[0]) : void 0;
46764
48404
  const holdings = [];
46765
48405
  rows.forEach((r, k) => {
46766
- const d2 = bytes(next());
48406
+ const d2 = bytes2(next());
46767
48407
  if (!d2) return;
46768
48408
  const shares = tokenAmount(d2);
46769
48409
  if (shares === 0n) return;
@@ -46785,7 +48425,7 @@ async function fetchSolsticeUser(account, opts = {}) {
46785
48425
  const pending = [];
46786
48426
  const usd = (raw2, r) => Number(raw2) / 10 ** r.assetDecimals * (r.priceUsd ?? 0);
46787
48427
  if (eusx && escrow) {
46788
- const d2 = bytes(next());
48428
+ const d2 = bytes2(next());
46789
48429
  if (d2) {
46790
48430
  const e = decodeCooldownEscrow(d2);
46791
48431
  if (e.asset_amount > 0n)
@@ -46803,7 +48443,7 @@ async function fetchSolsticeUser(account, opts = {}) {
46803
48443
  }
46804
48444
  }
46805
48445
  seniors.forEach((r, k) => {
46806
- const d2 = bytes(next());
48446
+ const d2 = bytes2(next());
46807
48447
  if (!d2) return;
46808
48448
  const c = decodeSeniorUnlockCooldown(d2);
46809
48449
  if (c.assets_pending === 0n) return;
@@ -46823,7 +48463,7 @@ async function fetchSolsticeUser(account, opts = {}) {
46823
48463
  });
46824
48464
  });
46825
48465
  for (const j of juniorRecords) {
46826
- const d2 = bytes(next());
48466
+ const d2 = bytes2(next());
46827
48467
  if (!d2) continue;
46828
48468
  const u = decodeJuniorUnlockShare(d2);
46829
48469
  if (u.shares === 0n) continue;
@@ -62924,10 +64564,10 @@ var HUMA_SEEDS = {
62924
64564
 
62925
64565
  // src/vaults/huma/accounts.ts
62926
64566
  import {
62927
- decodeBase58 as decodeBase585,
62928
- decodeIdlAccount as decodeIdlAccount6,
62929
- findProgramAddress as findProgramAddress5,
62930
- fromBase64 as fromBase6411,
64567
+ decodeBase58 as decodeBase586,
64568
+ decodeIdlAccount as decodeIdlAccount7,
64569
+ findProgramAddress as findProgramAddress6,
64570
+ fromBase64 as fromBase6413,
62931
64571
  getAssociatedTokenAddress as getAssociatedTokenAddress3,
62932
64572
  TOKEN_PROGRAM as TOKEN_PROGRAM2
62933
64573
  } from "@1delta/svm-kit";
@@ -62943,21 +64583,21 @@ var HUMA_POOL = {
62943
64583
  var HUMA_MPST_MINT = "HUPfpnsaJtJGpJxAPNX1vXah7BgYiQYt1c2JMgMumvPs";
62944
64584
  var HUMA_CLASSIC_MODE_ID = "Fr2BGzmFkufAUXNWSWk79juyWrHVCj8AbyzbbvZzhwgz";
62945
64585
  var HUMA_DECIMALS = 6;
62946
- var utf85 = (s) => new TextEncoder().encode(s);
62947
- var pk5 = (address) => {
62948
- const b = decodeBase585(address);
64586
+ var utf86 = (s) => new TextEncoder().encode(s);
64587
+ var pk6 = (address) => {
64588
+ const b = decodeBase586(address);
62949
64589
  if (!b || b.length !== 32) throw new Error(`huma: bad pubkey ${address}`);
62950
64590
  return b;
62951
64591
  };
62952
- var pda2 = (seeds) => findProgramAddress5(seeds, HUMA_PROGRAM).then((r) => r.address);
62953
- var humaPoolConfigPda = () => pda2([utf85("pool_config"), pk5(HUMA_POOL.poolId)]);
62954
- var humaPoolStatePda = () => pda2([utf85("pool_state"), pk5(HUMA_POOL.poolConfig)]);
62955
- var humaPoolAuthorityPda = () => pda2([utf85("pool_authority"), pk5(HUMA_POOL.poolConfig)]);
62956
- var humaModeConfigPda = (modeId) => pda2([utf85("mode_config"), pk5(HUMA_POOL.poolConfig), pk5(modeId)]);
62957
- var humaModeMintPda = (modeConfig) => pda2([utf85("mode_mint"), pk5(HUMA_POOL.poolConfig), pk5(modeConfig)]);
62958
- var humaLenderStatePda = (modeConfig, lender) => pda2([utf85("lender_state"), pk5(modeConfig), pk5(lender)]);
62959
- var humaDeploymentStatePda = (deploymentConfig) => pda2([utf85("deployment_state"), pk5(deploymentConfig)]);
62960
- var humaRedemptionRequestPda = (id, poolConfig) => pda2([utf85("redemption_request"), u128be(id), pk5(poolConfig)]);
64592
+ var pda2 = (seeds) => findProgramAddress6(seeds, HUMA_PROGRAM).then((r) => r.address);
64593
+ var humaPoolConfigPda = () => pda2([utf86("pool_config"), pk6(HUMA_POOL.poolId)]);
64594
+ var humaPoolStatePda = () => pda2([utf86("pool_state"), pk6(HUMA_POOL.poolConfig)]);
64595
+ var humaPoolAuthorityPda = () => pda2([utf86("pool_authority"), pk6(HUMA_POOL.poolConfig)]);
64596
+ var humaModeConfigPda = (modeId) => pda2([utf86("mode_config"), pk6(HUMA_POOL.poolConfig), pk6(modeId)]);
64597
+ var humaModeMintPda = (modeConfig) => pda2([utf86("mode_mint"), pk6(HUMA_POOL.poolConfig), pk6(modeConfig)]);
64598
+ var humaLenderStatePda = (modeConfig, lender) => pda2([utf86("lender_state"), pk6(modeConfig), pk6(lender)]);
64599
+ var humaDeploymentStatePda = (deploymentConfig) => pda2([utf86("deployment_state"), pk6(deploymentConfig)]);
64600
+ var humaRedemptionRequestPda = (id, poolConfig) => pda2([utf86("redemption_request"), u128be(id), pk6(poolConfig)]);
62961
64601
  var u128be = (v) => {
62962
64602
  if (v < 0n || v >= 1n << 128n) throw new Error(`huma: id out of u128: ${v}`);
62963
64603
  const out = new Uint8Array(16);
@@ -62965,11 +64605,11 @@ var u128be = (v) => {
62965
64605
  out[15 - i] = Number(v >> BigInt(8 * i) & 0xffn);
62966
64606
  return out;
62967
64607
  };
62968
- var decodeHumaPoolState = (d2) => decodeIdlAccount6(HUMA_IDL, "PoolState", d2);
62969
- var decodeHumaModeConfig = (d2) => decodeIdlAccount6(HUMA_IDL, "ModeConfig", d2);
62970
- var decodeHumaPoolConfig = (d2) => decodeIdlAccount6(HUMA_IDL, "PoolConfig", d2);
62971
- var decodeHumaLenderState = (d2) => decodeIdlAccount6(HUMA_IDL, "LenderState", d2);
62972
- var decodeHumaRedemptionRequest = (d2) => decodeIdlAccount6(HUMA_IDL, "RedemptionRequest", d2);
64608
+ var decodeHumaPoolState = (d2) => decodeIdlAccount7(HUMA_IDL, "PoolState", d2);
64609
+ var decodeHumaModeConfig = (d2) => decodeIdlAccount7(HUMA_IDL, "ModeConfig", d2);
64610
+ var decodeHumaPoolConfig = (d2) => decodeIdlAccount7(HUMA_IDL, "PoolConfig", d2);
64611
+ var decodeHumaLenderState = (d2) => decodeIdlAccount7(HUMA_IDL, "LenderState", d2);
64612
+ var decodeHumaRedemptionRequest = (d2) => decodeIdlAccount7(HUMA_IDL, "RedemptionRequest", d2);
62973
64613
  function mintSupply2(data) {
62974
64614
  if (data.length < 44) throw new Error("huma: mint account too short");
62975
64615
  return data.slice(36, 44).reduce((a, b, i) => a | BigInt(b) << BigInt(8 * i), 0n);
@@ -62993,13 +64633,13 @@ async function readHumaChainState(rpc, pool = HUMA_POOL) {
62993
64633
  { encoding: "base64" }
62994
64634
  );
62995
64635
  const state = decodeHumaPoolState(
62996
- fromBase6411(need2(first[0], "pool_state").data[0])
64636
+ fromBase6413(need2(first[0], "pool_state").data[0])
62997
64637
  );
62998
64638
  const config = decodeHumaPoolConfig(
62999
- fromBase6411(need2(first[1], "pool_config").data[0])
64639
+ fromBase6413(need2(first[1], "pool_config").data[0])
63000
64640
  );
63001
64641
  const poolCash = tokenAmount2(
63002
- first[2] ? fromBase6411(first[2].data[0]) : void 0
64642
+ first[2] ? fromBase6413(first[2].data[0]) : void 0
63003
64643
  );
63004
64644
  const modeMints = await Promise.all(
63005
64645
  state.mode_config_keys.map((k) => humaModeMintPda(k))
@@ -63014,9 +64654,9 @@ async function readHumaChainState(rpc, pool = HUMA_POOL) {
63014
64654
  { encoding: "base64" }
63015
64655
  );
63016
64656
  const modeConfig = decodeHumaModeConfig(
63017
- fromBase6411(need2(modeAcct, "mode_config").data[0])
64657
+ fromBase6413(need2(modeAcct, "mode_config").data[0])
63018
64658
  );
63019
- const mintData = fromBase6411(need2(mintAcct, "pst_mint").data[0]);
64659
+ const mintData = fromBase6413(need2(mintAcct, "pst_mint").data[0]);
63020
64660
  const next = state.redemption.next_request_id;
63021
64661
  const last = state.redemption.last_request_id;
63022
64662
  const gate = state.redemption.global_redemption_gating;
@@ -63073,7 +64713,7 @@ async function readHumaLenderState(rpc, modeConfig, wallet) {
63073
64713
  const a = accounts[0];
63074
64714
  return {
63075
64715
  address,
63076
- state: a ? decodeHumaLenderState(fromBase6411(a.data[0])) : null
64716
+ state: a ? decodeHumaLenderState(fromBase6413(a.data[0])) : null
63077
64717
  };
63078
64718
  }
63079
64719
  var HUMA_REDEMPTION_REQUEST_SIZE = 273;
@@ -63089,7 +64729,7 @@ async function readHumaRedemptionRequests(fetchers, wallet) {
63089
64729
  );
63090
64730
  return rows.map((r) => ({
63091
64731
  address: r.pubkey,
63092
- ...decodeHumaRedemptionRequest(fromBase6411(r.account.data[0]))
64732
+ ...decodeHumaRedemptionRequest(fromBase6413(r.account.data[0]))
63093
64733
  })).sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
63094
64734
  }
63095
64735
 
@@ -63209,16 +64849,16 @@ var nowSec = () => Math.floor(Date.now() / 1e3);
63209
64849
  function convertLoopscaleVault(v, opts = {}) {
63210
64850
  const s = v.vaultStrategy.strategy;
63211
64851
  const listed3 = opts.tokenList?.[s.principalMint];
63212
- const dec = opts.decimals ?? listed3?.decimals;
63213
- if (dec === void 0) return void 0;
64852
+ const dec2 = opts.decimals ?? listed3?.decimals;
64853
+ if (dec2 === void 0) return void 0;
63214
64854
  const tvlRaw = strategyTvlRaw(s);
63215
- const tvl = tvlRaw / 10 ** dec;
64855
+ const tvl = tvlRaw / 10 ** dec2;
63216
64856
  const extAmount = Number(s.externalYieldAmount);
63217
64857
  const deployed = Number(s.currentDeployedAmount);
63218
64858
  const idle = Number(s.tokenBalance);
63219
64859
  const ext = v.vaultStrategy.externalYieldInfo;
63220
64860
  const extApr = ext ? cbpsToFraction(ext.apy) : 0;
63221
- const grossAnnual = Number(s.interestPerSecond) * SECONDS_PER_YEAR + extApr * extAmount;
64861
+ const grossAnnual = Number(s.interestPerSecond) * SECONDS_PER_YEAR2 + extApr * extAmount;
63222
64862
  const gross = tvlRaw > 0 ? grossAnnual / tvlRaw * 100 : 0;
63223
64863
  const feeFrac = cbpsToFraction(s.interestFee);
63224
64864
  const supplyRate = gross * (1 - feeFrac);
@@ -63235,7 +64875,7 @@ function convertLoopscaleVault(v, opts = {}) {
63235
64875
  const rDec = mint ? opts.tokenList?.[mint]?.decimals : void 0;
63236
64876
  if (!p || rDec === void 0 || !priceUsd || tvl <= 0) continue;
63237
64877
  const perSec = Number(r.emissionsPerSecond ?? 0) / 10 ** rDec;
63238
- rewardsRate += perSec * SECONDS_PER_YEAR * p / (tvl * priceUsd) * 100;
64878
+ rewardsRate += perSec * SECONDS_PER_YEAR2 * p / (tvl * priceUsd) * 100;
63239
64879
  }
63240
64880
  const lp = Number(v.vault.lpSupply);
63241
64881
  const earlyFee = Number(v.vault.maxEarlyUnstakeFee);
@@ -63255,13 +64895,15 @@ function convertLoopscaleVault(v, opts = {}) {
63255
64895
  name: meta?.name ?? v.vault.address,
63256
64896
  displayName: meta?.name ? `Loopscale ${meta.name}` : `Loopscale ${sym}`,
63257
64897
  curatorName: meta?.managerName ?? "Loopscale",
63258
- decimals: dec,
63259
- assetDecimals: dec,
64898
+ manager: v.vault.manager,
64899
+ managerImage: meta?.managerImage ?? void 0,
64900
+ decimals: dec2,
64901
+ assetDecimals: dec2,
63260
64902
  totalAssets: String(tvlRaw),
63261
64903
  totalSupply: String(lp),
63262
- convertToAssets: String(Math.round(sharePrice * 10 ** dec)),
64904
+ convertToAssets: String(Math.round(sharePrice * 10 ** dec2)),
63263
64905
  convertToShares: String(
63264
- sharePrice > 0 ? Math.round(1 / sharePrice * 10 ** dec) : 0
64906
+ sharePrice > 0 ? Math.round(1 / sharePrice * 10 ** dec2) : 0
63265
64907
  ),
63266
64908
  grossRate: gross,
63267
64909
  supplyRate,
@@ -63273,8 +64915,8 @@ function convertLoopscaleVault(v, opts = {}) {
63273
64915
  totalAssetsFormatted: tvl,
63274
64916
  totalAssetsUsd: sum?.totalSupplyUsd ?? tvl * (priceUsd ?? 0),
63275
64917
  liquidity: String(idle),
63276
- liquidityFormatted: idle / 10 ** dec,
63277
- liquidityUsd: idle / 10 ** dec * (priceUsd ?? 0),
64918
+ liquidityFormatted: idle / 10 ** dec2,
64919
+ liquidityUsd: idle / 10 ** dec2 * (priceUsd ?? 0),
63278
64920
  sharePrice,
63279
64921
  sharePriceUsd: sharePrice * (priceUsd ?? 0),
63280
64922
  yieldProfile: "yield-bearing",
@@ -63342,6 +64984,158 @@ async function fetchLoopscaleEarnVaults(opts = {}) {
63342
64984
  return out;
63343
64985
  }
63344
64986
 
64987
+ // src/vaults/kamino-kvault/api.ts
64988
+ var KVAULT_PROGRAM_ID = "KvauGMspG5k6rtzrqqn7WNn3oZdyKqLKwK2XWQ8FLjd";
64989
+ function createKaminoKvaultApi(opts = {}) {
64990
+ const base = (opts.baseUrl ?? KAMINO_API_BASE).replace(/\/$/, "");
64991
+ const limit = createLimiter(opts.maxInFlight ?? 4);
64992
+ const get = (path) => limit(() => getJson(`${base}${path}`, opts));
64993
+ return {
64994
+ vaults: () => get("/kvaults/vaults"),
64995
+ /** Every page of the batch metrics. A page that fails fails the call — a partial metrics set would read as vaults with no APY. */
64996
+ metrics: async () => {
64997
+ const out = [];
64998
+ let token;
64999
+ const maxPages = opts.maxPages ?? 20;
65000
+ for (let page = 0; page < maxPages; page++) {
65001
+ const res = await get(
65002
+ `/kvaults/vaults/metrics${token ? `?paginationToken=${encodeURIComponent(token)}` : ""}`
65003
+ );
65004
+ out.push(...res.result ?? []);
65005
+ token = res.paginationToken ?? void 0;
65006
+ if (!token || !res.result?.length) return out;
65007
+ }
65008
+ throw new Error(
65009
+ `kvault metrics: still paging after ${maxPages} pages (${out.length} rows)`
65010
+ );
65011
+ },
65012
+ vaultMetrics: (vault) => get(`/kvaults/vaults/${vault}/metrics`)
65013
+ };
65014
+ }
65015
+
65016
+ // src/vaults/kamino-kvault/fetchPublic.ts
65017
+ function decimalStringToRaw(s, decimals) {
65018
+ if (s === void 0 || s === null) return void 0;
65019
+ const t = String(s).trim();
65020
+ const m = /^(-?)(\d*)(?:\.(\d*))?$/.exec(t);
65021
+ if (!m || !m[2] && !m[3]) return void 0;
65022
+ const frac = (m[3] ?? "").slice(0, decimals).padEnd(decimals, "0");
65023
+ const v = BigInt((m[2] || "0") + frac);
65024
+ return m[1] ? -v : v;
65025
+ }
65026
+ function convertKaminoKvault(v, m, opts = {}) {
65027
+ if (!m) return void 0;
65028
+ const s = v.state;
65029
+ const dec2 = s.tokenMintDecimals;
65030
+ const shareDec = s.sharesMintDecimals;
65031
+ const listed3 = opts.tokenList?.[s.tokenMint];
65032
+ const listedShare = opts.tokenList?.[s.sharesMint];
65033
+ const sym = listed3?.symbol ?? s.tokenMint.slice(0, 4);
65034
+ const perShare = num(m.tokensPerShare, 1);
65035
+ const shares = BigInt(s.sharesIssued || "0");
65036
+ const perShareRaw = decimalStringToRaw(m.tokensPerShare, dec2) ?? 10n ** BigInt(dec2);
65037
+ const totalAssetsRaw = shares * perShareRaw / 10n ** BigInt(shareDec);
65038
+ const totalAssetsFormatted = Number(totalAssetsRaw) / 10 ** dec2;
65039
+ const idleRaw = BigInt(s.tokenAvailable || "0");
65040
+ const idle = Number(idleRaw) / 10 ** dec2;
65041
+ const price = num(m.tokenPrice);
65042
+ const priced = price > 0;
65043
+ const apy = {
65044
+ current: num(m.apy),
65045
+ actual: num(m.apyActual),
65046
+ d1: num(m.apy24h),
65047
+ d7: num(m.apy7d),
65048
+ d30: num(m.apy30d),
65049
+ d90: num(m.apy90d),
65050
+ farmRewards: num(m.apyFarmRewards),
65051
+ incentives: num(m.apyIncentives),
65052
+ reservesIncentives: num(m.apyReservesIncentives)
65053
+ };
65054
+ const supplyRate = apyFractionToAprPercent(apy.current);
65055
+ const rewardsRate = apyFractionToAprPercent(apy.farmRewards + apy.incentives);
65056
+ const name = s.name?.trim() || listedShare?.name || `Kamino Vault ${sym}`;
65057
+ return {
65058
+ provider: "kamino-kvault",
65059
+ originProvider: "kamino-kvault",
65060
+ chainId: SOLANA_CHAIN_ID,
65061
+ address: v.address,
65062
+ shareMint: s.sharesMint,
65063
+ underlying: s.tokenMint,
65064
+ symbol: listedShare?.symbol ?? `kv${sym}`,
65065
+ name,
65066
+ displayName: name.toLowerCase().includes("kamino") ? name : `Kamino ${name}`,
65067
+ curatorName: s.vaultAdminAuthority,
65068
+ manager: s.vaultAdminAuthority,
65069
+ allocationAdmin: s.allocationAdmin,
65070
+ decimals: shareDec,
65071
+ assetDecimals: dec2,
65072
+ totalAssets: totalAssetsRaw.toString(),
65073
+ totalSupply: shares.toString(),
65074
+ convertToAssets: perShareRaw.toString(),
65075
+ convertToShares: perShare > 0 ? String(Math.round(1 / perShare * 10 ** shareDec)) : "0",
65076
+ supplyRate,
65077
+ rewardsRate,
65078
+ depositRate: supplyRate + rewardsRate,
65079
+ asset: listed3,
65080
+ priceUsd: priced ? price : void 0,
65081
+ totalAssetsFormatted,
65082
+ totalAssetsUsd: priced ? totalAssetsFormatted * price : 0,
65083
+ liquidity: idleRaw.toString(),
65084
+ liquidityFormatted: idle,
65085
+ liquidityUsd: priced ? idle * price : 0,
65086
+ sharePrice: perShare,
65087
+ sharePriceUsd: priced ? num(m.sharePrice, perShare * price) : 0,
65088
+ yieldProfile: "yield-bearing",
65089
+ denomination: denominationOf({
65090
+ symbol: listed3?.symbol,
65091
+ props: listed3?.props
65092
+ }),
65093
+ logoURI: listedShare?.logoURI ?? listed3?.logoURI,
65094
+ fee: s.performanceFeeBps / 100,
65095
+ managementFeePct: s.managementFeeBps / 100,
65096
+ withdrawalMode: "instant-capped",
65097
+ instantLiquidityRatio: totalAssetsRaw > 0n ? Math.min(1, Number(idleRaw * 1000000n / totalAssetsRaw) / 1e6) : 1,
65098
+ apy,
65099
+ holders: m.numberOfHolders ?? 0,
65100
+ vaultFarm: s.vaultFarm && s.vaultFarm !== "11111111111111111111111111111111" ? s.vaultFarm : void 0,
65101
+ allocations: (s.vaultAllocationStrategy ?? []).filter((a) => a.reserve !== "11111111111111111111111111111111").map((a) => ({
65102
+ reserve: a.reserve,
65103
+ weight: a.targetAllocationWeight,
65104
+ ctokenAllocation: a.ctokenAllocation
65105
+ })),
65106
+ createdAt: s.creationTimestamp,
65107
+ minDepositAmount: s.minDepositAmount
65108
+ };
65109
+ }
65110
+ async function fetchKaminoKvaults(opts = {}) {
65111
+ const api = createKaminoKvaultApi(opts);
65112
+ const [vaults, metrics] = await Promise.all([
65113
+ opts.vaults ?? api.vaults(),
65114
+ opts.metrics ?? api.metrics()
65115
+ ]);
65116
+ const byVault = /* @__PURE__ */ new Map();
65117
+ for (const m of metrics) if (m.kvault) byVault.set(m.kvault, m);
65118
+ const out = [];
65119
+ const skipped = [];
65120
+ for (const v of vaults) {
65121
+ if (!opts.includeEmpty && BigInt(v.state.sharesIssued || "0") === 0n)
65122
+ continue;
65123
+ const row = convertKaminoKvault(v, byVault.get(v.address), {
65124
+ tokenList: opts.tokenList
65125
+ });
65126
+ if (!row) {
65127
+ skipped.push(v.address);
65128
+ continue;
65129
+ }
65130
+ out.push(row);
65131
+ }
65132
+ if (skipped.length)
65133
+ console.warn(
65134
+ `[kamino-kvault] ${skipped.length} vault(s) skipped \u2014 no metrics row: ${skipped.join(", ")}`
65135
+ );
65136
+ return out;
65137
+ }
65138
+
63345
65139
  // src/vaults/lst/fetchPublic.ts
63346
65140
  import { createSvmRpc as createSvmRpc6, WRAPPED_SOL } from "@1delta/svm-kit";
63347
65141
  var LAMPORTS_PER_SOL = 10 ** 9;
@@ -63360,7 +65154,7 @@ var SPL_STAKE_POOL_LSTS = [
63360
65154
  curatorName: "SolBlaze"
63361
65155
  }
63362
65156
  ];
63363
- var SECONDS_PER_YEAR3 = 365.25 * 86400;
65157
+ var SECONDS_PER_YEAR4 = 365.25 * 86400;
63364
65158
  function epochRealizedApr(pool, epochSeconds) {
63365
65159
  if (pool.lastEpochTotalLamports === void 0 || !pool.lastEpochPoolTokenSupply || pool.poolTokenSupply === 0n || epochSeconds <= 0)
63366
65160
  return void 0;
@@ -63370,7 +65164,7 @@ function epochRealizedApr(pool, epochSeconds) {
63370
65164
  const epochRate = now / last - 1;
63371
65165
  return {
63372
65166
  epochRatePercent: epochRate * 100,
63373
- aprPercent: epochRate * (SECONDS_PER_YEAR3 / epochSeconds) * 100,
65167
+ aprPercent: epochRate * (SECONDS_PER_YEAR4 / epochSeconds) * 100,
63374
65168
  lastEpochExchangeRate: last
63375
65169
  };
63376
65170
  }
@@ -63657,6 +65451,9 @@ function loopscaleOriginRow(r) {
63657
65451
  meta: {
63658
65452
  vaultAccount: r.vaultAccount,
63659
65453
  strategy: r.strategy,
65454
+ manager: r.manager,
65455
+ managerName: r.curatorName,
65456
+ managerImage: r.managerImage,
63660
65457
  grossRate: r.grossRate,
63661
65458
  venueApy: r.venueApy,
63662
65459
  interestFee: r.fees.interest,
@@ -63681,6 +65478,42 @@ function loopscaleOriginRow(r) {
63681
65478
  }
63682
65479
  };
63683
65480
  }
65481
+ function kaminoKvaultOriginRow(r) {
65482
+ return {
65483
+ ...common4626(r, "kamino-kvault", "sync"),
65484
+ // kvaults publish no curator NAME: `r.curatorName` is the admin address,
65485
+ // and a brand column holding a base58 key would read as the desk's name on
65486
+ // /earn. The address travels as `meta.manager`; a label layer keyed by it
65487
+ // (lender-metadata curator-labels.json → curator_metadata) names it.
65488
+ curatorName: void 0,
65489
+ provider: "kamino-kvault",
65490
+ fee: r.fee,
65491
+ shareAsset: {
65492
+ chainId: r.chainId,
65493
+ address: r.shareMint,
65494
+ symbol: r.symbol,
65495
+ name: r.name,
65496
+ decimals: r.decimals
65497
+ },
65498
+ metaTable: "vault_kamino_kvault_meta",
65499
+ meta: {
65500
+ shareMint: r.shareMint,
65501
+ manager: r.manager,
65502
+ allocationAdmin: r.allocationAdmin,
65503
+ managementFeePct: r.managementFeePct,
65504
+ convertToAssets: r.convertToAssets,
65505
+ convertToShares: r.convertToShares,
65506
+ withdrawalMode: r.withdrawalMode,
65507
+ instantLiquidityRatio: r.instantLiquidityRatio,
65508
+ apy: r.apy,
65509
+ holders: r.holders,
65510
+ vaultFarm: r.vaultFarm,
65511
+ allocations: r.allocations,
65512
+ createdAt: r.createdAt,
65513
+ minDepositAmount: r.minDepositAmount
65514
+ }
65515
+ };
65516
+ }
63684
65517
  function exponentOriginRow(r) {
63685
65518
  return {
63686
65519
  provider: "exponent",
@@ -63728,6 +65561,8 @@ function toOriginVaultRow(r) {
63728
65561
  return jupiterLendOriginRow(r);
63729
65562
  case "loopscale":
63730
65563
  return loopscaleOriginRow(r);
65564
+ case "kamino-kvault":
65565
+ return kaminoKvaultOriginRow(r);
63731
65566
  }
63732
65567
  }
63733
65568
 
@@ -63893,21 +65728,66 @@ async function fetchJupiterLendOracleEntries(opts = {}) {
63893
65728
  }
63894
65729
 
63895
65730
  // src/prices/oracle-prices/fetchers/save.ts
65731
+ import { createSvmRpc as createSvmRpc7 } from "@1delta/svm-kit";
63896
65732
  async function fetchSaveOracleEntries(opts = {}) {
63897
65733
  const res = opts.publicData ?? await fetchSavePublic(opts);
65734
+ const feeds = /* @__PURE__ */ new Set();
65735
+ for (const bundle of Object.values(res))
65736
+ for (const row of Object.values(bundle.data)) {
65737
+ if (row.save.pythOracle) feeds.add(row.save.pythOracle);
65738
+ if (row.save.switchboardOracle) feeds.add(row.save.switchboardOracle);
65739
+ }
65740
+ const readings = /* @__PURE__ */ new Map();
65741
+ if (opts.live !== false && feeds.size) {
65742
+ try {
65743
+ const rpc = opts.rpc ?? createSvmRpc7();
65744
+ const keys = [...feeds];
65745
+ const { accounts } = await rpc.readAccounts(keys, { encoding: "base64" });
65746
+ accounts.forEach((a, i) => {
65747
+ if (!a) return;
65748
+ try {
65749
+ const r = decodeOracleFeed({ owner: a.owner, data: a.data[0] });
65750
+ if (r && Number.isFinite(r.price) && r.price > 0)
65751
+ readings.set(keys[i], r);
65752
+ } catch (e) {
65753
+ console.warn(`[save] feed ${keys[i]}: ${e.message}`);
65754
+ }
65755
+ });
65756
+ } catch (e) {
65757
+ console.warn(
65758
+ `[save] live feeds not read, serving stored reserve prices: ${e.message}`
65759
+ );
65760
+ }
65761
+ }
63898
65762
  const out = {};
63899
65763
  for (const [lender, bundle] of Object.entries(res)) {
63900
65764
  out[lender] = Object.entries(bundle.data).map(([marketUid, row]) => {
63901
65765
  const s = row.save;
65766
+ const bps = s.scaledPriceOffsetBps;
65767
+ const dial = bps !== 0 ? ` \xD7 (1 + ${bps} bps dial)` : "";
65768
+ 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);
65769
+ const pick = candidates[0];
65770
+ if (pick) {
65771
+ const price = pick.r.price * (1 + bps / 1e4);
65772
+ return {
65773
+ asset: row.underlying,
65774
+ price,
65775
+ priceUSD: price,
65776
+ marketUid,
65777
+ description: `Save reserve oracle \xB7 ${pick.r.kind}${dial} (live feed read)`,
65778
+ derivation: dial ? "derived" : "direct",
65779
+ feedSource: pick.feed,
65780
+ feedUpdatedAt: pick.r.updatedAt > 0 ? pick.r.updatedAt : void 0
65781
+ };
65782
+ }
63902
65783
  const feed = s.pythOracle ?? s.switchboardOracle ?? s.extraOracle;
63903
65784
  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
65785
  return {
63906
65786
  asset: row.underlying,
63907
65787
  price: s.priceUsd,
63908
65788
  priceUSD: s.priceUsd,
63909
65789
  marketUid,
63910
- description: `Save reserve price \xB7 ${kind}${dial} \xB7 slot ${s.lastUpdateSlot}${s.stale ? " (stale)" : ""}`,
65790
+ description: `Save reserve price (stored) \xB7 ${kind}${dial} \xB7 slot ${s.lastUpdateSlot}${s.stale ? " (stale)" : ""}`,
63911
65791
  derivation: dial ? "derived" : "direct",
63912
65792
  feedSource: feed
63913
65793
  };
@@ -63967,16 +65847,19 @@ async function fetchProject0OracleEntries(opts = {}) {
63967
65847
  for (const [lender, bundle] of Object.entries(res)) {
63968
65848
  out[lender] = Object.entries(bundle.data).filter(([, row]) => row.p0.price.source !== "none").map(([marketUid, row]) => {
63969
65849
  const p = row.p0.price;
63970
- return {
65850
+ const fixed = p.source === "fixed";
65851
+ const entry = {
63971
65852
  asset: row.underlying,
63972
65853
  price: p.priceUsd,
63973
65854
  priceUSD: p.priceUsd,
63974
65855
  marketUid,
63975
65856
  description: `Project 0 \xB7 ${p.description ?? p.source}`,
63976
- derivation: p.source === "pyth-push" ? "direct" : p.source === "fixed" ? "direct" : "derived",
65857
+ derivation: p.source === "pyth-push" || p.source === "scope" || fixed ? "direct" : "derived",
63977
65858
  feedSource: p.feed,
63978
65859
  feedUpdatedAt: p.updatedAt
63979
65860
  };
65861
+ if (fixed) entry.staticBase = true;
65862
+ return entry;
63980
65863
  });
63981
65864
  }
63982
65865
  return out;
@@ -63987,14 +65870,15 @@ async function fetchOraclePrices(chainIds, opts = {}) {
63987
65870
  const FETCHERS = {
63988
65871
  kamino: (chainId) => chainId === SOLANA_CHAIN_ID ? fetchKaminoOracleEntries(opts.overrides, opts) : Promise.resolve({}),
63989
65872
  "jupiter-lend": (chainId) => chainId === SOLANA_CHAIN_ID ? fetchJupiterLendOracleEntries(opts) : Promise.resolve({}),
63990
- save: (chainId) => chainId === SOLANA_CHAIN_ID ? fetchSaveOracleEntries({ timeoutMs: opts.timeoutMs }) : Promise.resolve({}),
65873
+ save: (chainId) => chainId === SOLANA_CHAIN_ID ? fetchSaveOracleEntries({ timeoutMs: opts.timeoutMs, rpc: opts.rpc }) : Promise.resolve({}),
63991
65874
  loopscale: (chainId) => chainId === SOLANA_CHAIN_ID ? fetchLoopscaleOracleEntries({
63992
65875
  timeoutMs: opts.timeoutMs,
63993
65876
  tokenList: opts.tokenList
63994
65877
  }) : Promise.resolve({}),
63995
65878
  project0: (chainId) => chainId === SOLANA_CHAIN_ID ? fetchProject0OracleEntries({
63996
65879
  timeoutMs: opts.timeoutMs,
63997
- tokenList: opts.tokenList
65880
+ tokenList: opts.tokenList,
65881
+ ...opts.rpc ? { rpc: opts.rpc } : {}
63998
65882
  }) : Promise.resolve({})
63999
65883
  };
64000
65884
  const names = opts.onlyFetchers?.length ? opts.onlyFetchers : Object.keys(FETCHERS);
@@ -64275,10 +66159,10 @@ async function mintToReserve(api, market) {
64275
66159
  // src/lending/user-data/kamino/onchain.ts
64276
66160
  import {
64277
66161
  createSvmFetchers as createSvmFetchers2,
64278
- createSvmRpc as createSvmRpc7,
64279
- decodeIdlAccount as decodeIdlAccount7,
66162
+ createSvmRpc as createSvmRpc8,
66163
+ decodeIdlAccount as decodeIdlAccount8,
64280
66164
  encodeBase58 as encodeBase586,
64281
- fromBase64 as fromBase6412
66165
+ fromBase64 as fromBase6414
64282
66166
  } from "@1delta/svm-kit";
64283
66167
  var KLEND_OBLIGATION_SIZE = 3344;
64284
66168
  var KLEND_OBLIGATION_DISCRIMINATOR = [
@@ -64297,7 +66181,7 @@ var SF = 60n;
64297
66181
  var bsf = (b) => b.value.reduce((a, w, i) => a + (BigInt(w) << 64n * BigInt(i)), 0n);
64298
66182
  var sfToNumber = (x) => Number(x >> 30n) / 2 ** 30;
64299
66183
  function decodeKaminoObligation(address, data) {
64300
- const o = decodeIdlAccount7(KLEND_IDL, "Obligation", data);
66184
+ const o = decodeIdlAccount8(KLEND_IDL, "Obligation", data);
64301
66185
  return {
64302
66186
  address,
64303
66187
  owner: o.owner,
@@ -64325,7 +66209,7 @@ function decodeKaminoObligation(address, data) {
64325
66209
  };
64326
66210
  }
64327
66211
  function decodeKaminoReserveState(reserve, data) {
64328
- const r = decodeIdlAccount7(KLEND_IDL, "Reserve", data);
66212
+ const r = decodeIdlAccount8(KLEND_IDL, "Reserve", data);
64329
66213
  const l = r.liquidity;
64330
66214
  const totalSf = klendTotalSupplySf({
64331
66215
  availableAmount: BigInt(l.totalAvailableAmount),
@@ -64394,7 +66278,7 @@ function valueKaminoObligations(account, obligations, reserves, groups = {}, acc
64394
66278
  obligation: o.address,
64395
66279
  reason: `elevation group ${o.elevationGroup} terms not read \u2014 health uses the reserves' own LT`
64396
66280
  });
64397
- const view = {
66281
+ const view2 = {
64398
66282
  address: o.address,
64399
66283
  market: o.market,
64400
66284
  lenderKey,
@@ -64425,7 +66309,7 @@ function valueKaminoObligations(account, obligations, reserves, groups = {}, acc
64425
66309
  const units = depositUnits(d2.cTokens, s);
64426
66310
  const amount = Number(units);
64427
66311
  const uid = createMarketUid(SOLANA_CHAIN_ID, lenderKey, d2.reserve);
64428
- view.deposits.push({
66312
+ view2.deposits.push({
64429
66313
  reserve: d2.reserve,
64430
66314
  marketUid: uid,
64431
66315
  mint: s.mint,
@@ -64433,10 +66317,10 @@ function valueKaminoObligations(account, obligations, reserves, groups = {}, acc
64433
66317
  amount,
64434
66318
  amountUsd: amount * s.priceUsd
64435
66319
  });
64436
- view.asOfSlot = Math.min(view.asOfSlot, s.lastUpdateSlot);
64437
- view.depositedValueUsd += amount * s.priceUsd;
66320
+ view2.asOfSlot = Math.min(view2.asOfSlot, s.lastUpdateSlot);
66321
+ view2.depositedValueUsd += amount * s.priceUsd;
64438
66322
  const lt = group?.liquidationThreshold ?? s.liquidationThresholdPct;
64439
- view.unhealthyBorrowValueUsd += amount * s.priceUsd * lt / 100;
66323
+ view2.unhealthyBorrowValueUsd += amount * s.priceUsd * lt / 100;
64440
66324
  const p = leg(uid);
64441
66325
  p.deposits = units;
64442
66326
  p.depositsUSD = amount * s.priceUsd;
@@ -64459,7 +66343,7 @@ function valueKaminoObligations(account, obligations, reserves, groups = {}, acc
64459
66343
  const units = debtUnits(debtSf, s);
64460
66344
  const amount = Number(units);
64461
66345
  const uid = createMarketUid(SOLANA_CHAIN_ID, lenderKey, b.reserve);
64462
- view.borrows.push({
66346
+ view2.borrows.push({
64463
66347
  reserve: b.reserve,
64464
66348
  marketUid: uid,
64465
66349
  mint: s.mint,
@@ -64467,17 +66351,17 @@ function valueKaminoObligations(account, obligations, reserves, groups = {}, acc
64467
66351
  amount,
64468
66352
  amountUsd: amount * s.priceUsd
64469
66353
  });
64470
- view.asOfSlot = Math.min(view.asOfSlot, s.lastUpdateSlot);
64471
- view.bfAdjustedDebtUsd += amount * s.priceUsd * (o.elevationGroup ? 100 : Math.max(100, s.borrowFactorPct)) / 100;
66354
+ view2.asOfSlot = Math.min(view2.asOfSlot, s.lastUpdateSlot);
66355
+ view2.bfAdjustedDebtUsd += amount * s.priceUsd * (o.elevationGroup ? 100 : Math.max(100, s.borrowFactorPct)) / 100;
64472
66356
  const p = leg(uid);
64473
66357
  p.debt = units;
64474
66358
  p.debtUSD = amount * s.priceUsd;
64475
66359
  p.debtUSDOracle = amount * s.priceUsd;
64476
66360
  }
64477
- if (view.asOfSlot === Infinity) view.asOfSlot = o.lastUpdateSlot;
64478
- if (view.bfAdjustedDebtUsd > 0)
64479
- view.healthFactor = view.unhealthyBorrowValueUsd / view.bfAdjustedDebtUsd;
64480
- views.push(view);
66361
+ if (view2.asOfSlot === Infinity) view2.asOfSlot = o.lastUpdateSlot;
66362
+ if (view2.bfAdjustedDebtUsd > 0)
66363
+ view2.healthFactor = view2.unhealthyBorrowValueUsd / view2.bfAdjustedDebtUsd;
66364
+ views.push(view2);
64481
66365
  bucket.lendingPositions[o.address] = legs;
64482
66366
  bucket.modes[o.address] = String(o.elevationGroup);
64483
66367
  bucket.accounts[o.address] = accounts[o.address] ?? {
@@ -64498,7 +66382,7 @@ function valueKaminoObligations(account, obligations, reserves, groups = {}, acc
64498
66382
  };
64499
66383
  }
64500
66384
  async function fetchKaminoUserOnchain(account, opts = {}) {
64501
- const rpc = opts.rpc ?? createSvmRpc7();
66385
+ const rpc = opts.rpc ?? createSvmRpc8();
64502
66386
  const hits = await createSvmFetchers2(rpc).indexed.scanProgram(
64503
66387
  KLEND_PROGRAM_ID,
64504
66388
  [
@@ -64517,7 +66401,7 @@ async function fetchKaminoUserOnchain(account, opts = {}) {
64517
66401
  }
64518
66402
  );
64519
66403
  const markets = opts.markets && new Set(opts.markets);
64520
- const obligations = hits.map((h) => decodeKaminoObligation(h.pubkey, fromBase6412(h.account.data[0]))).filter((o) => !markets || markets.has(o.market));
66404
+ const obligations = hits.map((h) => decodeKaminoObligation(h.pubkey, fromBase6414(h.account.data[0]))).filter((o) => !markets || markets.has(o.market));
64521
66405
  const reserves = { ...opts.reserves };
64522
66406
  const need3 = [
64523
66407
  ...new Set(
@@ -64540,8 +66424,8 @@ async function fetchKaminoUserOnchain(account, opts = {}) {
64540
66424
  const a = accounts2[i];
64541
66425
  if (!a || a.owner !== KLEND_PROGRAM_ID) return;
64542
66426
  if (i < need3.length)
64543
- reserves[k] = decodeKaminoReserveState(k, fromBase6412(a.data[0]));
64544
- else groups[k] = readKlendElevationGroups(fromBase6412(a.data[0]));
66427
+ reserves[k] = decodeKaminoReserveState(k, fromBase6414(a.data[0]));
66428
+ else groups[k] = readKlendElevationGroups(fromBase6414(a.data[0]));
64545
66429
  });
64546
66430
  }
64547
66431
  const accounts = {};
@@ -64569,7 +66453,7 @@ async function fetchKaminoUserOnchain(account, opts = {}) {
64569
66453
 
64570
66454
  // src/lending/user-data/jupiter-lend/fetchUser.ts
64571
66455
  var isPositionId = (id) => typeof id === "number" && Number.isSafeInteger(id) && id > 0;
64572
- var big = (v) => {
66456
+ var big2 = (v) => {
64573
66457
  try {
64574
66458
  return BigInt(v ?? 0);
64575
66459
  } catch {
@@ -64589,8 +66473,8 @@ function convertJupiterLendUserPositions(account, market, positions, vaults = /*
64589
66473
  skip("liquidated");
64590
66474
  continue;
64591
66475
  }
64592
- const supplyRaw = big(p.supply);
64593
- const borrowRaw = big(p.borrow) + big(p.dustBorrow);
66476
+ const supplyRaw = big2(p.supply);
66477
+ const borrowRaw = big2(p.borrow) + big2(p.dustBorrow);
64594
66478
  if (supplyRaw === 0n && borrowRaw === 0n) {
64595
66479
  skip("empty");
64596
66480
  continue;
@@ -64684,7 +66568,7 @@ async function fetchJupiterLendUser(account, opts = {}) {
64684
66568
  ext.borrowPositions[market] = borrows;
64685
66569
  ext.earnPositions[market] = earns;
64686
66570
  const needsRoster = borrows.some(
64687
- (p) => !p.isLiquidated && (big(p.supply) > 0n || big(p.borrow) + big(p.dustBorrow) > 0n) && !(p.vault && p.vault.id === p.vaultId)
66571
+ (p) => !p.isLiquidated && (big2(p.supply) > 0n || big2(p.borrow) + big2(p.dustBorrow) > 0n) && !(p.vault && p.vault.id === p.vaultId)
64688
66572
  );
64689
66573
  const roster = needsRoster ? new Map((await api.vaults(market)).map((v) => [v.id, v])) : void 0;
64690
66574
  const conv = convertJupiterLendUserPositions(
@@ -64701,7 +66585,7 @@ async function fetchJupiterLendUser(account, opts = {}) {
64701
66585
  }
64702
66586
 
64703
66587
  // src/lending/user-data/save/obligation.ts
64704
- import { BorshReader as BorshReader2, decodeBase58 as decodeBase586, encodeBase58 as encodeBase587 } from "@1delta/svm-kit";
66588
+ import { BorshReader as BorshReader2, decodeBase58 as decodeBase587, encodeBase58 as encodeBase587 } from "@1delta/svm-kit";
64705
66589
  function decodeSaveObligation(address, data) {
64706
66590
  if (data.length !== SAVE_OBLIGATION_SIZE)
64707
66591
  throw new Error(
@@ -64770,10 +66654,10 @@ function saveObligationSeed(lendingMarket, index = 0) {
64770
66654
  throw new Error(`save obligation index out of range: ${index}`);
64771
66655
  return lendingMarket.slice(0, 24) + String(index).padStart(6, "0") + "m";
64772
66656
  }
64773
- var sha256 = async (bytes) => new Uint8Array(await crypto.subtle.digest("SHA-256", bytes));
66657
+ var sha256 = async (bytes2) => new Uint8Array(await crypto.subtle.digest("SHA-256", bytes2));
64774
66658
  async function createWithSeed(base, seed, programId) {
64775
- const b = decodeBase586(base);
64776
- const p = decodeBase586(programId);
66659
+ const b = decodeBase587(base);
66660
+ const p = decodeBase587(programId);
64777
66661
  if (!b || b.length !== 32) throw new Error(`not a pubkey: ${base}`);
64778
66662
  if (!p || p.length !== 32) throw new Error(`not a pubkey: ${programId}`);
64779
66663
  const s = new TextEncoder().encode(seed);
@@ -64788,23 +66672,23 @@ var saveObligationAddress = (wallet, lendingMarket, index = 0, programId = SAVE_
64788
66672
 
64789
66673
  // src/lending/user-data/save/fetchUser.ts
64790
66674
  import {
64791
- createSvmRpc as createSvmRpc8,
66675
+ createSvmRpc as createSvmRpc9,
64792
66676
  encodeBase58 as encodeBase588,
64793
- fromBase64 as fromBase6413,
66677
+ fromBase64 as fromBase6415,
64794
66678
  getAssociatedTokenAddress as getAssociatedTokenAddress4,
64795
66679
  TOKEN_PROGRAM as TOKEN_PROGRAM3
64796
66680
  } from "@1delta/svm-kit";
64797
66681
  var SAVE_WALLET_POS_ID = "wallet";
64798
- var readTokenAmount = (bytes, mint) => {
64799
- if (bytes.length < 72) return void 0;
64800
- if (encodeBase588(bytes.subarray(0, 32)) !== mint) return void 0;
66682
+ var readTokenAmount = (bytes2, mint) => {
66683
+ if (bytes2.length < 72) return void 0;
66684
+ if (encodeBase588(bytes2.subarray(0, 32)) !== mint) return void 0;
64801
66685
  let v = 0n;
64802
- for (let i = 71; i >= 64; i--) v = v << 8n | BigInt(bytes[i]);
66686
+ for (let i = 71; i >= 64; i--) v = v << 8n | BigInt(bytes2[i]);
64803
66687
  return v;
64804
66688
  };
64805
66689
  async function fetchSaveUser(account, opts = {}) {
64806
66690
  const api = createSaveApi(opts);
64807
- const rpc = opts.rpc ?? createSvmRpc8();
66691
+ const rpc = opts.rpc ?? createSvmRpc9();
64808
66692
  const configs = opts.configs ?? await api.marketConfigs();
64809
66693
  const markets = selectSaveMarkets(configs, opts);
64810
66694
  const step = Math.min(
@@ -64860,9 +66744,9 @@ async function fetchSaveUser(account, opts = {}) {
64860
66744
  const exists = !!a && a.owner === SAVE_PROGRAM_ID && typeof a.data?.[0] === "string";
64861
66745
  (probed[key2] ??= []).push({ index: c.index, address: c.address, exists });
64862
66746
  if (!exists) return;
64863
- const bytes = fromBase6413(a.data[0]);
64864
- if (bytes.length !== SAVE_OBLIGATION_SIZE) return;
64865
- found.push({ c, ob: decodeSaveObligation(c.address, bytes) });
66747
+ const bytes2 = fromBase6415(a.data[0]);
66748
+ if (bytes2.length !== SAVE_OBLIGATION_SIZE) return;
66749
+ found.push({ c, ob: decodeSaveObligation(c.address, bytes2) });
64866
66750
  });
64867
66751
  if (extend)
64868
66752
  for (const c of pending) {
@@ -64883,7 +66767,7 @@ async function fetchSaveUser(account, opts = {}) {
64883
66767
  const a = ataAccounts[i];
64884
66768
  if (!a || a.owner !== TOKEN_PROGRAM3 || typeof a.data?.[0] !== "string")
64885
66769
  return;
64886
- const amount = readTokenAmount(fromBase6413(a.data[0]), c.cTokenMint);
66770
+ const amount = readTokenAmount(fromBase6415(a.data[0]), c.cTokenMint);
64887
66771
  if (amount && amount > 0n) wallet.push({ c, cTokens: amount });
64888
66772
  });
64889
66773
  const reserveIds = [
@@ -64951,7 +66835,7 @@ async function fetchSaveUser(account, opts = {}) {
64951
66835
  address: ob.address,
64952
66836
  label: `#${c.index}`
64953
66837
  };
64954
- const view = {
66838
+ const view2 = {
64955
66839
  address: ob.address,
64956
66840
  market: c.market.address,
64957
66841
  lenderKey,
@@ -64994,13 +66878,13 @@ async function fetchSaveUser(account, opts = {}) {
64994
66878
  });
64995
66879
  continue;
64996
66880
  }
64997
- const dec = s.reserve.liquidity.mintDecimals;
66881
+ const dec2 = s.reserve.liquidity.mintDecimals;
64998
66882
  const raw2 = d2.depositedAmount * saveExchangeRateWad(s.reserve) / SAVE_WAD;
64999
- const amountStr = scaledToDecimal(raw2, dec);
66883
+ const amountStr = scaledToDecimal(raw2, dec2);
65000
66884
  const amount = Number(amountStr);
65001
66885
  const price = wadToNumber(s.reserve.liquidity.marketPrice);
65002
66886
  const usd = amount * price;
65003
- view.deposits.push({
66887
+ view2.deposits.push({
65004
66888
  reserve: d2.reserve,
65005
66889
  marketUid: uid,
65006
66890
  mint: s.reserve.liquidity.mintPubkey,
@@ -65009,10 +66893,10 @@ async function fetchSaveUser(account, opts = {}) {
65009
66893
  amountUsd: usd,
65010
66894
  served: !reason
65011
66895
  });
65012
- view.depositedValueUsd += usd;
65013
- view.allowedBorrowValueUsd += usd * (s.reserve.config.loanToValueRatio / 100);
65014
- view.unhealthyBorrowValueUsd += usd * (s.reserve.config.liquidationThreshold / 100);
65015
- view.superUnhealthyBorrowValueUsd += usd * (s.reserve.config.maxLiquidationThreshold / 100);
66896
+ view2.depositedValueUsd += usd;
66897
+ view2.allowedBorrowValueUsd += usd * (s.reserve.config.loanToValueRatio / 100);
66898
+ view2.unhealthyBorrowValueUsd += usd * (s.reserve.config.liquidationThreshold / 100);
66899
+ view2.superUnhealthyBorrowValueUsd += usd * (s.reserve.config.maxLiquidationThreshold / 100);
65016
66900
  if (reason) {
65017
66901
  unserved.push({
65018
66902
  lenderKey,
@@ -65052,18 +66936,18 @@ async function fetchSaveUser(account, opts = {}) {
65052
66936
  });
65053
66937
  continue;
65054
66938
  }
65055
- const dec = s.reserve.liquidity.mintDecimals;
66939
+ const dec2 = s.reserve.liquidity.mintDecimals;
65056
66940
  const price = wadToNumber(s.reserve.liquidity.marketPrice);
65057
66941
  const reserveIdx = BigInt(s.reserve.liquidity.cumulativeBorrowRateWads);
65058
66942
  const legIdx = b.cumulativeBorrowRateWads;
65059
66943
  const wads = legIdx > 0n ? b.borrowedAmountWads * reserveIdx / legIdx : b.borrowedAmountWads;
65060
- const amountStr = scaledToDecimal(wads, 18 + dec);
66944
+ const amountStr = scaledToDecimal(wads, 18 + dec2);
65061
66945
  const amount = Number(amountStr);
65062
- const atTouch = wadToNumber(b.borrowedAmountWads.toString()) / 10 ** dec;
66946
+ const atTouch = wadToNumber(b.borrowedAmountWads.toString()) / 10 ** dec2;
65063
66947
  const usd = amount * price;
65064
66948
  const addedBps = s.reserve.config.addedBorrowWeightBPS;
65065
66949
  const weight = 1 + Number(addedBps) / 1e4;
65066
- view.borrows.push({
66950
+ view2.borrows.push({
65067
66951
  reserve: b.reserve,
65068
66952
  marketUid: uid,
65069
66953
  mint: s.reserve.liquidity.mintPubkey,
@@ -65073,8 +66957,8 @@ async function fetchSaveUser(account, opts = {}) {
65073
66957
  borrowWeight: weight,
65074
66958
  served: !reason
65075
66959
  });
65076
- if (weight > 1e9 && wads > 0n) view.unboundedWeightDebt = true;
65077
- view.weightedBorrowValueUsd += usd * weight;
66960
+ if (weight > 1e9 && wads > 0n) view2.unboundedWeightDebt = true;
66961
+ view2.weightedBorrowValueUsd += usd * weight;
65078
66962
  if (reason) {
65079
66963
  unserved.push({
65080
66964
  lenderKey,
@@ -65095,8 +66979,8 @@ async function fetchSaveUser(account, opts = {}) {
65095
66979
  debtUSDOracle: usd
65096
66980
  });
65097
66981
  }
65098
- view.healthFactor = view.weightedBorrowValueUsd > 0 ? view.unhealthyBorrowValueUsd / view.weightedBorrowValueUsd : Infinity;
65099
- views.push(view);
66982
+ view2.healthFactor = view2.weightedBorrowValueUsd > 0 ? view2.unhealthyBorrowValueUsd / view2.weightedBorrowValueUsd : Infinity;
66983
+ views.push(view2);
65100
66984
  }
65101
66985
  const walletViews = [];
65102
66986
  for (const { c, cTokens } of wallet) {
@@ -65104,10 +66988,10 @@ async function fetchSaveUser(account, opts = {}) {
65104
66988
  const uid = createMarketUid(SOLANA_CHAIN_ID, lenderKey, c.reserve);
65105
66989
  const s = states[c.reserve];
65106
66990
  const reason = servedReason(c.reserve);
65107
- const dec = s?.reserve.liquidity.mintDecimals ?? 0;
66991
+ const dec2 = s?.reserve.liquidity.mintDecimals ?? 0;
65108
66992
  const amountStr = s ? scaledToDecimal(
65109
66993
  cTokens * saveExchangeRateWad(s.reserve) / SAVE_WAD,
65110
- dec
66994
+ dec2
65111
66995
  ) : "0";
65112
66996
  const usd = s ? Number(amountStr) * wadToNumber(s.reserve.liquidity.marketPrice) : 0;
65113
66997
  walletViews.push({
@@ -65163,11 +67047,11 @@ async function fetchSaveUser(account, opts = {}) {
65163
67047
  }
65164
67048
 
65165
67049
  // src/lending/user-data/loopscale/fetchUser.ts
65166
- import { createSvmRpc as createSvmRpc9, getMints as getMints2 } from "@1delta/svm-kit";
67050
+ import { createSvmRpc as createSvmRpc10, getMints as getMints2 } from "@1delta/svm-kit";
65167
67051
  var shortAddr = (a) => `${a.slice(0, 4)}\u2026${a.slice(-4)}`;
65168
67052
  function convertLoopscaleUser(account, items, opts) {
65169
67053
  const now = opts.now ?? Math.floor(Date.now() / 1e3);
65170
- const dec = (mint) => opts.decimals[mint];
67054
+ const dec2 = (mint) => opts.decimals[mint];
65171
67055
  const positions = {};
65172
67056
  const loans = [];
65173
67057
  const skipped = [];
@@ -65178,7 +67062,7 @@ function convertLoopscaleUser(account, items, opts) {
65178
67062
  ...it.ledgers.map((l) => l.principalMint),
65179
67063
  ...it.collateral.map((c) => c.assetMint)
65180
67064
  ]);
65181
- const missing = [...mints].filter((m) => dec(m) === void 0);
67065
+ const missing = [...mints].filter((m) => dec2(m) === void 0);
65182
67066
  if (missing.length) {
65183
67067
  if (!it.loan.closed)
65184
67068
  skipped.push({
@@ -65187,7 +67071,7 @@ function convertLoopscaleUser(account, items, opts) {
65187
67071
  });
65188
67072
  continue;
65189
67073
  }
65190
- const tok = (raw2, mint) => raw2 / 10 ** dec(mint);
67074
+ const tok = (raw2, mint) => raw2 / 10 ** dec2(mint);
65191
67075
  const ledgers = it.ledgers.map((l) => {
65192
67076
  const d2 = { duration: l.duration, durationType: l.durationType };
65193
67077
  const toMaturity = ledgerInterestAt(
@@ -65361,7 +67245,7 @@ async function fetchLoopscaleUser(account, opts = {}) {
65361
67245
  ];
65362
67246
  if (unknown.length) {
65363
67247
  try {
65364
- const mints = await getMints2(opts.rpc ?? createSvmRpc9(), unknown);
67248
+ const mints = await getMints2(opts.rpc ?? createSvmRpc10(), unknown);
65365
67249
  mints.forEach((m, i) => {
65366
67250
  if (m) decimals[unknown[i]] = m.decimals;
65367
67251
  });
@@ -65382,12 +67266,12 @@ async function fetchLoopscaleUser(account, opts = {}) {
65382
67266
  // src/lending/user-data/project0/fetchUser.ts
65383
67267
  import {
65384
67268
  createSvmFetchers as createSvmFetchers3,
65385
- createSvmRpc as createSvmRpc10,
67269
+ createSvmRpc as createSvmRpc11,
65386
67270
  encodeBase58 as encodeBase589
65387
67271
  } from "@1delta/svm-kit";
65388
67272
  var flagOn = (flags, bit) => (BigInt(flags) & bit) !== 0n;
65389
67273
  async function fetchProject0User(account, opts = {}) {
65390
- const rpc = opts.rpc ?? createSvmRpc10();
67274
+ const rpc = opts.rpc ?? createSvmRpc11();
65391
67275
  const groups = opts.groups?.length ? opts.groups : [P0_MAIN_GROUP];
65392
67276
  const pub = opts.publicData ?? await fetchProject0Public({ ...opts, rpc, groups });
65393
67277
  const found = [];
@@ -65495,7 +67379,7 @@ async function fetchProject0User(account, opts = {}) {
65495
67379
  }).catch(() => void 0) === acc.address;
65496
67380
  const label = isPda ? `#${acc.accountIndex}${acc.thirdPartyIndex ? ` \xB7 third party ${acc.thirdPartyIndex}` : ""}` : `keypair ${acc.address.slice(0, 4)}\u2026${acc.address.slice(-4)}`;
65497
67381
  const emodeActive = /* @__PURE__ */ new Set();
65498
- const view = {
67382
+ const view2 = {
65499
67383
  address: acc.address,
65500
67384
  group,
65501
67385
  lenderKey,
@@ -65527,7 +67411,7 @@ async function fetchProject0User(account, opts = {}) {
65527
67411
  for (const b of active) {
65528
67412
  const hit = rowsByBank.get(b.bank);
65529
67413
  if (!hit) {
65530
- view.incomplete = true;
67414
+ view2.incomplete = true;
65531
67415
  unserved.push({
65532
67416
  account: acc.address,
65533
67417
  bank: b.bank,
@@ -65536,7 +67420,7 @@ async function fetchProject0User(account, opts = {}) {
65536
67420
  liabilityShares: b.liabilityShares,
65537
67421
  reason: !bundle ? "group not served" : meta?.droppedBanks.find((d2) => d2.bank === b.bank)?.reason ?? "not in the group roster"
65538
67422
  });
65539
- view.balances.push({
67423
+ view2.balances.push({
65540
67424
  bank: b.bank,
65541
67425
  mint: meta?.banks[b.bank]?.mint ?? "",
65542
67426
  symbol: meta?.banks[b.bank]?.symbol ?? b.bank.slice(0, 4),
@@ -65580,7 +67464,7 @@ async function fetchProject0User(account, opts = {}) {
65580
67464
  const lwMaint = p0.liabilityWeightMaint;
65581
67465
  const depUsd = deposited * price;
65582
67466
  const borUsd = borrowed * price;
65583
- view.balances.push({
67467
+ view2.balances.push({
65584
67468
  bank: b.bank,
65585
67469
  marketUid: uid,
65586
67470
  mint: row.underlying,
@@ -65599,10 +67483,10 @@ async function fetchProject0User(account, opts = {}) {
65599
67483
  emissionsOutstanding: b.emissionsOutstanding,
65600
67484
  unpriced: p0.price.source === "none"
65601
67485
  });
65602
- view.assetValueInitUsd += depUsd * awInit;
65603
- view.assetValueMaintUsd += depUsd * awMaint;
65604
- view.liabilityValueInitUsd += borUsd * lwInit;
65605
- view.liabilityValueMaintUsd += borUsd * lwMaint;
67486
+ view2.assetValueInitUsd += depUsd * awInit;
67487
+ view2.assetValueMaintUsd += depUsd * awMaint;
67488
+ view2.liabilityValueInitUsd += borUsd * lwInit;
67489
+ view2.liabilityValueMaintUsd += borUsd * lwMaint;
65606
67490
  legs[uid] = {
65607
67491
  marketUid: uid,
65608
67492
  deposits: p0DecimalString(deposited, row.decimals),
@@ -65616,13 +67500,13 @@ async function fetchProject0User(account, opts = {}) {
65616
67500
  claimableRewards: 0
65617
67501
  };
65618
67502
  }
65619
- view.healthFactor = view.liabilityValueMaintUsd > 0 ? view.assetValueMaintUsd / view.liabilityValueMaintUsd : Infinity;
65620
- view.freeCollateralUsd = Math.max(
67503
+ view2.healthFactor = view2.liabilityValueMaintUsd > 0 ? view2.assetValueMaintUsd / view2.liabilityValueMaintUsd : Infinity;
67504
+ view2.freeCollateralUsd = Math.max(
65621
67505
  0,
65622
- view.assetValueInitUsd - view.liabilityValueInitUsd
67506
+ view2.assetValueInitUsd - view2.liabilityValueInitUsd
65623
67507
  );
65624
- view.emodeActive = [...emodeActive];
65625
- views.push(view);
67508
+ view2.emodeActive = [...emodeActive];
67509
+ views.push(view2);
65626
67510
  if (!active.length) continue;
65627
67511
  const out = positions[lenderKey] ??= {
65628
67512
  chainId: SOLANA_CHAIN_ID,
@@ -65855,7 +67739,7 @@ function kaminoTermAdapter(row, market) {
65855
67739
  if (row.originationFee === void 0)
65856
67740
  pending["borrow.fees"] = "origination and flash-loan fees are in the reserve account, which was not read";
65857
67741
  for (const p of market?.pending ?? []) pending[`market: ${p}`] = p;
65858
- const liq = market?.liquidation;
67742
+ const liq2 = market?.liquidation;
65859
67743
  return {
65860
67744
  profileId: KAMINO_PROFILE_ID,
65861
67745
  borrow: {
@@ -65929,14 +67813,14 @@ function kaminoTermAdapter(row, market) {
65929
67813
  debtWithdrawalCap: capExt(k.debtWithdrawalCap),
65930
67814
  // remaining new debt outside any elevation group (`borrowLimitOutsideElevationGroup − tracked`)
65931
67815
  debtCapacityOutsideGroups: base.debtCapacity,
65932
- ...liq ? {
67816
+ ...liq2 ? {
65933
67817
  fullLiquidation: {
65934
67818
  // obligation LTV above which the close factor is 100 %
65935
- aboveLtv: liq.insolvencyRiskUnhealthyLtvPct / 100,
67819
+ aboveLtv: liq2.insolvencyRiskUnhealthyLtvPct / 100,
65936
67820
  // a debt leg worth less than this is liquidated whole
65937
- belowDebtValueUsd: liq.minFullLiquidationValueThresholdUsd,
67821
+ belowDebtValueUsd: liq2.minFullLiquidationValueThresholdUsd,
65938
67822
  // one liquidation repays at most this
65939
- maxPerLiquidationUsd: liq.maxLiquidatableDebtMarketValueAtOnceUsd
67823
+ maxPerLiquidationUsd: liq2.maxLiquidatableDebtMarketValueAtOnceUsd
65940
67824
  }
65941
67825
  } : {},
65942
67826
  ...k.pairIncentives.length ? { pairIncentives: k.pairIncentives } : {}
@@ -66801,9 +68685,12 @@ export {
66801
68685
  HUMA_SEEDS,
66802
68686
  HttpError,
66803
68687
  JL_BPS,
68688
+ JL_EXCHANGE_PRICES_PRECISION,
66804
68689
  JL_FACTOR_SCALE,
66805
68690
  JL_ORACLE_DECIMALS,
66806
68691
  JL_ORACLE_SCALE,
68692
+ JL_VAULTS_ACCOUNTS_IDL,
68693
+ JL_VAULT_AMOUNT_DECIMALS,
66807
68694
  JUPITER_LEND_API_BASE,
66808
68695
  JUPITER_LEND_KEYED_API_BASE,
66809
68696
  JUPITER_LEND_KEY_PREFIX,
@@ -66812,9 +68699,11 @@ export {
66812
68699
  JUPITER_LEND_PROGRAMS,
66813
68700
  JUPITER_PRICE_API_BASE,
66814
68701
  JUPITER_PRICE_KEYED_API_BASE,
68702
+ JUP_DEX_PROGRAM,
66815
68703
  JUP_FLASHLOAN_IDL,
66816
68704
  JUP_FLASHLOAN_PROGRAMS,
66817
68705
  JUP_LIQUIDITY_PROGRAMS,
68706
+ JUP_VAULTS_PROGRAMS,
66818
68707
  KAMINO_API_BASE,
66819
68708
  KAMINO_KEY_PREFIX,
66820
68709
  KAMINO_MAIN_MARKET,
@@ -66834,6 +68723,7 @@ export {
66834
68723
  KLEND_RESERVE_SIZE,
66835
68724
  KLEND_RESERVE_SLICE,
66836
68725
  KLEND_U64_MAX,
68726
+ KVAULT_PROGRAM_ID,
66837
68727
  LENDER_BRAND_NAMES,
66838
68728
  LOANS_PAGE,
66839
68729
  LOOPSCALE_ACCOUNT_DISCRIMINATORS,
@@ -66921,7 +68811,7 @@ export {
66921
68811
  SAVE_UNBORROWABLE_BORROW_FACTOR,
66922
68812
  SAVE_WAD,
66923
68813
  SAVE_WALLET_POS_ID,
66924
- SECONDS_PER_YEAR,
68814
+ SECONDS_PER_YEAR2 as SECONDS_PER_YEAR,
66925
68815
  SETTLEMENT_BATCH_SIZE,
66926
68816
  SOLANA_CHAIN_ID,
66927
68817
  SOLSTICE_APP_API_BASE,
@@ -66964,6 +68854,7 @@ export {
66964
68854
  convertJupiterLendOracleEntries,
66965
68855
  convertJupiterLendUserPositions,
66966
68856
  convertJupiterLendVault,
68857
+ convertKaminoKvault,
66967
68858
  convertKaminoLoans,
66968
68859
  convertKaminoMarket,
66969
68860
  convertKaminoOraclePrices,
@@ -66980,6 +68871,7 @@ export {
66980
68871
  createExponentApi,
66981
68872
  createJupiterLendApi,
66982
68873
  createKaminoApi,
68874
+ createKaminoKvaultApi,
66983
68875
  createLimiter,
66984
68876
  createLoopscaleApi,
66985
68877
  createMarketUid,
@@ -66989,6 +68881,7 @@ export {
66989
68881
  createSolsticeAppApi,
66990
68882
  createWithSeed,
66991
68883
  decimalStringToI80F48,
68884
+ decimalStringToRaw,
66992
68885
  decodeAccountingState,
66993
68886
  decodeController,
66994
68887
  decodeCooldownEscrow,
@@ -67041,6 +68934,7 @@ export {
67041
68934
  fetchJupiterLendPublic,
67042
68935
  fetchJupiterLendUser,
67043
68936
  fetchJupiterPrices,
68937
+ fetchKaminoKvaults,
67044
68938
  fetchKaminoOracleEntries,
67045
68939
  fetchKaminoOraclePrices,
67046
68940
  fetchKaminoPublic,
@@ -67083,6 +68977,8 @@ export {
67083
68977
  i80f48ToNumber,
67084
68978
  isBorrowable,
67085
68979
  isEvmChainId,
68980
+ isJlSmartCol,
68981
+ isJlSmartDebt,
67086
68982
  isJupiterLend,
67087
68983
  isKamino,
67088
68984
  isLenderBrand,
@@ -67102,8 +68998,17 @@ export {
67102
68998
  isSyntheticQuoteMint,
67103
68999
  isU64Max,
67104
69000
  isUncapped,
69001
+ jlLiquidityExchangePrices,
67105
69002
  jlOraclePriceInBorrow,
67106
69003
  jlOracleToFluidRaw,
69004
+ jlOverallTokenData,
69005
+ jlUserBorrowData,
69006
+ jlUserSupplyData,
69007
+ jlVaultAdminPda,
69008
+ jlVaultConfigPda,
69009
+ jlVaultExchangePrices,
69010
+ jlVaultStatePda,
69011
+ jlVaultToRaw,
67107
69012
  joinableBatch,
67108
69013
  juniorUnlockSharePda,
67109
69014
  jupFlashBorrowPosition,
@@ -67122,6 +69027,7 @@ export {
67122
69027
  kaminoCloseFactor,
67123
69028
  kaminoDefaultEntry,
67124
69029
  kaminoGroupLabel,
69030
+ kaminoKvaultOriginRow,
67125
69031
  kaminoMarketFromKey,
67126
69032
  kaminoMarketKey,
67127
69033
  kaminoOracleEntriesFromMarkets,
@@ -67183,9 +69089,11 @@ export {
67183
69089
  readHumaChainState,
67184
69090
  readHumaLenderState,
67185
69091
  readHumaRedemptionRequests,
69092
+ readJlNextVaultId,
67186
69093
  readJupFlashAssets,
67187
69094
  readJupFlashAvailable,
67188
69095
  readJupFlashloanAdmin,
69096
+ readJupiterLendVaultsOnchain,
67189
69097
  readKlendElevationGroups,
67190
69098
  readKlendFlashFacts,
67191
69099
  readKlendLendingMarket,