@pyron-finance/pyron-client 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/common/index.cjs +68 -0
- package/dist/common/{index.d.mts → index.d.cts} +1 -1
- package/dist/common/index.d.ts +1 -1
- package/dist/common/index.js +2 -67
- package/dist/{common-BDe3qLlR.js → common-70fo5HbS.cjs} +3 -2
- package/dist/{common-BtUtEjzZ.mjs → common-DSb1joUt.js} +5 -4
- package/dist/common-DSb1joUt.js.map +1 -0
- package/dist/{index-Bx-zRXFQ.d.ts → index-AiXygYKy.d.ts} +66 -68
- package/dist/index-AiXygYKy.d.ts.map +1 -0
- package/dist/{index-BAC0ffmc.d.mts → index-CMK6wLry.d.cts} +57 -55
- package/dist/index-CMK6wLry.d.cts.map +1 -0
- package/dist/{index.mjs → index.cjs} +947 -727
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +727 -946
- package/dist/index.js.map +1 -0
- package/package.json +28 -4
- package/dist/common/index.mjs +0 -3
- package/dist/common-BtUtEjzZ.mjs.map +0 -1
- package/dist/index-BAC0ffmc.d.mts.map +0 -1
- package/dist/index-Bx-zRXFQ.d.ts.map +0 -1
- package/dist/index.d.mts +0 -2
- package/dist/index.mjs.map +0 -1
- /package/dist/{chunk-B9dir_RE.mjs → chunk-Cl8Af3a2.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { __export } from "./chunk-Cl8Af3a2.js";
|
|
2
|
+
import { BUNDLE_TX_SIZE, DEFAULT_CLUSTER, DEFAULT_COMMITMENT, DEFAULT_CONFIRM_OPTS, DEFAULT_ORACLE_MAX_AGE, DEFAULT_SEND_OPTS, DISABLED_FLAG, DUMMY_USDC_MINT, FLASHLOAN_ENABLED_FLAG, GROUP_PK, HOURS_PER_YEAR, JUPITER_V6_PROGRAM, LENDR_PROGRAM, LST_MINT, LUT_PROGRAM_AUTHORITY_INDEX, MAX_ACCOUNT_KEYS, MAX_CONFIDENCE_INTERVAL_RATIO, MAX_TX_SIZE, MAX_U64, MPL_METADATA_PROGRAM_ID, PDA_BANK_FEE_VAULT_AUTH_SEED, PDA_BANK_FEE_VAULT_SEED, PDA_BANK_INSURANCE_VAULT_AUTH_SEED, PDA_BANK_INSURANCE_VAULT_SEED, PDA_BANK_LIQUIDITY_VAULT_AUTH_SEED, PDA_BANK_LIQUIDITY_VAULT_SEED, PRIORITY_TX_SIZE, PROGRAM_ID, PYTH_PRICE_CONF_INTERVALS, PYTH_PUSH_ORACLE_ID, SINGLE_POOL_PROGRAM_ID, SKIP_SIMULATION, STAKE_CONFIG_ID, STAKE_PROGRAM_ID, SWB_PRICE_CONF_INTERVALS, SYSTEM_PROGRAM_ID, SYSVAR_CLOCK_ID, SYSVAR_RENT_ID, SYSVAR_STAKE_HISTORY_ID, TRANSFER_ACCOUNT_AUTHORITY_FLAG, TransactionArenaKeyMap, TransactionType, USDC_DECIMALS, USDC_MINT, WSOL_EXTENDED_METADATA, WSOL_MINT, addTransactionMetadata, aprToApy, bigNumberToWrappedI80F48, chunkedGetRawMultipleAccountInfoOrdered, composeRemainingAccounts, decodeInstruction, decompileV0Transaction, fetchBanksExtendedMetadata, getAccountKeys, getComputeBudgetUnits, getTxSize, isV0Tx, legacyTxToV0Tx, microLamportsToUi, nativeToUi, setTimeoutPromise, shortenAddress, sleep, splitInstructionsToFitTransactions, toBigNumber, uiToMicroLamports, uiToNative, updateV0Tx, wrappedI80F48toBigNumber } from "./common-DSb1joUt.js";
|
|
3
|
+
import * as anchor from "@coral-xyz/anchor";
|
|
4
|
+
import { AnchorProvider, BorshAccountsCoder, BorshCoder, BorshInstructionCoder, LangErrorMessage, Program, translateAddress } from "@coral-xyz/anchor";
|
|
5
|
+
import { MintLayout, NATIVE_MINT, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, createApproveInstruction, createAssociatedTokenAccountIdempotentInstruction, createAssociatedTokenAccountInstruction, createCloseAccountInstruction, createSyncNativeInstruction, getAssociatedTokenAddressSync } from "@solana/spl-token";
|
|
6
|
+
import { ComputeBudgetProgram, Connection, Keypair, LAMPORTS_PER_SOL, PublicKey, STAKE_CONFIG_ID as STAKE_CONFIG_ID$1, SYSVAR_CLOCK_PUBKEY, SYSVAR_RENT_PUBKEY, SolanaJSONRPCError, StakeAuthorizationLayout, StakeProgram, SystemProgram, Transaction, TransactionInstruction, TransactionMessage, VersionedTransaction } from "@solana/web3.js";
|
|
7
|
+
import BigNumber from "bignumber.js";
|
|
8
|
+
import BN$1, { BN } from "bn.js";
|
|
9
|
+
import bs58 from "bs58";
|
|
10
|
+
import { createStorage, prefixStorage } from "unstorage";
|
|
11
|
+
import { z } from "zod/v4-mini";
|
|
12
|
+
import * as borsh$1 from "borsh";
|
|
13
|
+
import * as borsh from "@coral-xyz/borsh";
|
|
14
|
+
import Big from "big.js";
|
|
13
15
|
|
|
14
16
|
//#region src/logger.ts
|
|
15
17
|
var NoopLogger = class {
|
|
@@ -52,17 +54,17 @@ var DataFetcher = class {
|
|
|
52
54
|
|
|
53
55
|
//#endregion
|
|
54
56
|
//#region src/services/metadata/index.ts
|
|
55
|
-
const metadataSchema =
|
|
56
|
-
name:
|
|
57
|
-
symbol:
|
|
58
|
-
image:
|
|
57
|
+
const metadataSchema = z.object({
|
|
58
|
+
name: z.string(),
|
|
59
|
+
symbol: z.string(),
|
|
60
|
+
image: z.string()
|
|
59
61
|
});
|
|
60
62
|
var IMetadataService = class {
|
|
61
63
|
/** NOTE: record key is base58 of mint public key */
|
|
62
64
|
overrides;
|
|
63
65
|
_storage;
|
|
64
66
|
constructor(storage, overrides = {}) {
|
|
65
|
-
this._storage =
|
|
67
|
+
this._storage = prefixStorage(storage, "banks:metadata");
|
|
66
68
|
this.overrides = overrides;
|
|
67
69
|
}
|
|
68
70
|
async forMints(mints) {
|
|
@@ -114,7 +116,7 @@ var IMetadataService = class {
|
|
|
114
116
|
|
|
115
117
|
//#endregion
|
|
116
118
|
//#region src/services/metadata/fogo.ts
|
|
117
|
-
const endpointSchema =
|
|
119
|
+
const endpointSchema = z.record(z.string(), metadataSchema);
|
|
118
120
|
var FogoMetadataService = class extends IMetadataService {
|
|
119
121
|
async _fetch(mints) {
|
|
120
122
|
if (mints.length === 0) {
|
|
@@ -134,9 +136,9 @@ var FogoMetadataService = class extends IMetadataService {
|
|
|
134
136
|
function getConfig({ environment = "production", overrides } = {}) {
|
|
135
137
|
return {
|
|
136
138
|
environment,
|
|
137
|
-
cluster: overrides?.cluster ??
|
|
138
|
-
programId: overrides?.programId ??
|
|
139
|
-
groupPk: overrides?.groupPk ??
|
|
139
|
+
cluster: overrides?.cluster ?? DEFAULT_CLUSTER,
|
|
140
|
+
programId: overrides?.programId ?? PROGRAM_ID,
|
|
141
|
+
groupPk: overrides?.groupPk ?? GROUP_PK
|
|
140
142
|
};
|
|
141
143
|
}
|
|
142
144
|
|
|
@@ -6166,7 +6168,7 @@ function parseCustomProgramError(logs, ldrProgramId) {
|
|
|
6166
6168
|
};
|
|
6167
6169
|
}
|
|
6168
6170
|
}
|
|
6169
|
-
errorMsg =
|
|
6171
|
+
errorMsg = LangErrorMessage.get(error.code);
|
|
6170
6172
|
if (errorMsg !== undefined) {
|
|
6171
6173
|
return {
|
|
6172
6174
|
code: error.code,
|
|
@@ -6276,7 +6278,7 @@ const JupiterErrorCodeMap = new Map([
|
|
|
6276
6278
|
[JupiterErrorCode.ExactOutAmountNotMatched, "Exact out amount doesn't match"],
|
|
6277
6279
|
[JupiterErrorCode.SourceAndDestinationMintCannotBeTheSame, "Source mint and destination mint cannot the same"]
|
|
6278
6280
|
]);
|
|
6279
|
-
const ERROR_CODE_MAPS = new Map([[
|
|
6281
|
+
const ERROR_CODE_MAPS = new Map([[TOKEN_PROGRAM_ID.toBase58(), TokenErrorCodeMap], [JUPITER_V6_PROGRAM.toBase58(), JupiterErrorCodeMap]]);
|
|
6280
6282
|
|
|
6281
6283
|
//#endregion
|
|
6282
6284
|
//#region src/idl/idl.utils.ts
|
|
@@ -6450,8 +6452,8 @@ async function makeLendingPoolConfigureBankOracleIx(ldProgram, accounts$2, args,
|
|
|
6450
6452
|
* @param args - Optional arguments for this instruction
|
|
6451
6453
|
*/
|
|
6452
6454
|
async function makePoolAddPermissionlessStakedBankIx(ldProgram, accounts$2, remainingAccounts = [], args) {
|
|
6453
|
-
const { stakedSettings, feePayer, bankMint, solPool, stakePool, tokenProgram =
|
|
6454
|
-
return ldProgram.methods.lendingPoolAddBankPermissionless(args.seed ?? new
|
|
6455
|
+
const { stakedSettings, feePayer, bankMint, solPool, stakePool, tokenProgram = TOKEN_PROGRAM_ID,...optionalAccounts } = accounts$2;
|
|
6456
|
+
return ldProgram.methods.lendingPoolAddBankPermissionless(args.seed ?? new BN$1(0)).accounts({
|
|
6455
6457
|
stakedSettings,
|
|
6456
6458
|
feePayer,
|
|
6457
6459
|
bankMint,
|
|
@@ -6625,13 +6627,13 @@ var HealthCache = class HealthCache {
|
|
|
6625
6627
|
this.simulationFailed = simulationFailed;
|
|
6626
6628
|
}
|
|
6627
6629
|
static from(healthCacheRaw) {
|
|
6628
|
-
const assetValue =
|
|
6629
|
-
const liabilityValue =
|
|
6630
|
-
const assetValueMaint =
|
|
6631
|
-
const liabilityValueMaint =
|
|
6632
|
-
const assetValueEquity =
|
|
6633
|
-
const liabilityValueEquity =
|
|
6634
|
-
const timestamp =
|
|
6630
|
+
const assetValue = wrappedI80F48toBigNumber(healthCacheRaw.assetValue);
|
|
6631
|
+
const liabilityValue = wrappedI80F48toBigNumber(healthCacheRaw.liabilityValue);
|
|
6632
|
+
const assetValueMaint = wrappedI80F48toBigNumber(healthCacheRaw.assetValueMaint);
|
|
6633
|
+
const liabilityValueMaint = wrappedI80F48toBigNumber(healthCacheRaw.liabilityValueMaint);
|
|
6634
|
+
const assetValueEquity = wrappedI80F48toBigNumber(healthCacheRaw.assetValueEquity);
|
|
6635
|
+
const liabilityValueEquity = wrappedI80F48toBigNumber(healthCacheRaw.liabilityValueEquity);
|
|
6636
|
+
const timestamp = toBigNumber(healthCacheRaw.timestamp);
|
|
6635
6637
|
const flags = getActiveHealthCacheFlags(healthCacheRaw.flags);
|
|
6636
6638
|
const prices = healthCacheRaw.prices;
|
|
6637
6639
|
return new HealthCache(assetValue, liabilityValue, assetValueMaint, liabilityValueMaint, assetValueEquity, liabilityValueEquity, timestamp, flags, prices);
|
|
@@ -8959,9 +8961,9 @@ const PYTH_SOLANA_RECEIVER_PROGRAM_IDL = {
|
|
|
8959
8961
|
|
|
8960
8962
|
//#endregion
|
|
8961
8963
|
//#region src/vendor/pyth_crank/pyth.consts.ts
|
|
8962
|
-
const DEFAULT_RECEIVER_PROGRAM_ID = new
|
|
8963
|
-
const DEFAULT_WORMHOLE_PROGRAM_ID = new
|
|
8964
|
-
const DEFAULT_PUSH_ORACLE_PROGRAM_ID = new
|
|
8964
|
+
const DEFAULT_RECEIVER_PROGRAM_ID = new PublicKey("rec5EKMGg6MxZYaMdyBfgwp4d5rB9T1VQH5pJv5LtFJ");
|
|
8965
|
+
const DEFAULT_WORMHOLE_PROGRAM_ID = new PublicKey("HDwcJBJXjL9FpJ7UBsYBtaDjsBUhuLCUYoz3zr8SWWaQ");
|
|
8966
|
+
const DEFAULT_PUSH_ORACLE_PROGRAM_ID = new PublicKey("pythWSnswVUd12oZpeFP8e9CVaEqJg25g1Vtc2biRsT");
|
|
8965
8967
|
const ACCUMULATOR_MAGIC = "504e4155";
|
|
8966
8968
|
const MAJOR_VERSION = 1;
|
|
8967
8969
|
const MINOR_VERSION = 0;
|
|
@@ -9075,7 +9077,7 @@ async function buildPostEncodedVaaInstructions(wormhole, vaa) {
|
|
|
9075
9077
|
};
|
|
9076
9078
|
}
|
|
9077
9079
|
async function generateVaaInstructionGroups(wormhole, vaa) {
|
|
9078
|
-
const encodedVaaKeypair = new
|
|
9080
|
+
const encodedVaaKeypair = new Keypair();
|
|
9079
9081
|
const initInstructions = [await buildEncodedVaaCreateInstruction(wormhole, vaa, encodedVaaKeypair), {
|
|
9080
9082
|
instruction: await wormhole.methods.initEncodedVaa().accounts({ encodedVaa: encodedVaaKeypair.publicKey }).instruction(),
|
|
9081
9083
|
signers: [],
|
|
@@ -9135,7 +9137,7 @@ async function buildEncodedVaaCreateInstruction(wormhole, vaa, encodedVaaKeypair
|
|
|
9135
9137
|
const getGuardianSetPda = (guardianSetIndex, wormholeProgramId) => {
|
|
9136
9138
|
const guardianSetIndexBuf = Buffer.alloc(4);
|
|
9137
9139
|
guardianSetIndexBuf.writeUInt32BE(guardianSetIndex, 0);
|
|
9138
|
-
return
|
|
9140
|
+
return PublicKey.findProgramAddressSync([Buffer.from("GuardianSet"), guardianSetIndexBuf], wormholeProgramId)[0];
|
|
9139
9141
|
};
|
|
9140
9142
|
function parsePriceFeedMessage(message) {
|
|
9141
9143
|
let cursor = 0;
|
|
@@ -9146,19 +9148,19 @@ function parsePriceFeedMessage(message) {
|
|
|
9146
9148
|
cursor += 1;
|
|
9147
9149
|
const feedId = message.subarray(cursor, cursor + 32);
|
|
9148
9150
|
cursor += 32;
|
|
9149
|
-
const price = new
|
|
9151
|
+
const price = new BN$1(message.subarray(cursor, cursor + 8), "be");
|
|
9150
9152
|
cursor += 8;
|
|
9151
|
-
const confidence = new
|
|
9153
|
+
const confidence = new BN$1(message.subarray(cursor, cursor + 8), "be");
|
|
9152
9154
|
cursor += 8;
|
|
9153
9155
|
const exponent = message.readInt32BE(cursor);
|
|
9154
9156
|
cursor += 4;
|
|
9155
|
-
const publishTime = new
|
|
9157
|
+
const publishTime = new BN$1(message.subarray(cursor, cursor + 8), "be");
|
|
9156
9158
|
cursor += 8;
|
|
9157
|
-
const prevPublishTime = new
|
|
9159
|
+
const prevPublishTime = new BN$1(message.subarray(cursor, cursor + 8), "be");
|
|
9158
9160
|
cursor += 8;
|
|
9159
|
-
const emaPrice = new
|
|
9161
|
+
const emaPrice = new BN$1(message.subarray(cursor, cursor + 8), "be");
|
|
9160
9162
|
cursor += 8;
|
|
9161
|
-
const emaConf = new
|
|
9163
|
+
const emaConf = new BN$1(message.subarray(cursor, cursor + 8), "be");
|
|
9162
9164
|
cursor += 8;
|
|
9163
9165
|
return {
|
|
9164
9166
|
feedId,
|
|
@@ -9220,7 +9222,7 @@ function readBigUInt64LE(buffer, offset = 0) {
|
|
|
9220
9222
|
/** Number of slots that can pass before a publisher's price is no longer included in the aggregate. */
|
|
9221
9223
|
const MAX_SLOT_DIFFERENCE = 25;
|
|
9222
9224
|
const empty32Buffer = Buffer.alloc(32);
|
|
9223
|
-
const PKorNull = (data) => data.equals(empty32Buffer) ? null : new
|
|
9225
|
+
const PKorNull = (data) => data.equals(empty32Buffer) ? null : new PublicKey(data);
|
|
9224
9226
|
let PriceStatus = /* @__PURE__ */ function(PriceStatus$1) {
|
|
9225
9227
|
PriceStatus$1[PriceStatus$1["Unknown"] = 0] = "Unknown";
|
|
9226
9228
|
PriceStatus$1[PriceStatus$1["Trading"] = 1] = "Trading";
|
|
@@ -9283,7 +9285,7 @@ const parsePriceData = (data, currentSlot) => {
|
|
|
9283
9285
|
const drv2 = data.readInt8(105);
|
|
9284
9286
|
const drv3 = data.readInt16LE(106);
|
|
9285
9287
|
const drv4 = data.readInt32LE(108);
|
|
9286
|
-
const productAccountKey = new
|
|
9288
|
+
const productAccountKey = new PublicKey(data.slice(112, 144));
|
|
9287
9289
|
const nextPriceAccountKey = PKorNull(data.slice(144, 176));
|
|
9288
9290
|
const previousSlot = readBigUInt64LE(data, 176);
|
|
9289
9291
|
const previousPriceComponent = readBigInt64LE(data, 184);
|
|
@@ -9307,7 +9309,7 @@ const parsePriceData = (data, currentSlot) => {
|
|
|
9307
9309
|
const priceComponents = [];
|
|
9308
9310
|
let offset = 240;
|
|
9309
9311
|
while (priceComponents.length < numComponentPrices) {
|
|
9310
|
-
const publisher = new
|
|
9312
|
+
const publisher = new PublicKey(data.slice(offset, offset + 32));
|
|
9311
9313
|
offset += 32;
|
|
9312
9314
|
const componentAggregate = parsePriceInfo$1(data.slice(offset, offset + 32), exponent);
|
|
9313
9315
|
offset += 32;
|
|
@@ -9389,12 +9391,12 @@ const priceUpdateV2Schema = { struct: {
|
|
|
9389
9391
|
postedSlot: "u64"
|
|
9390
9392
|
} };
|
|
9391
9393
|
const parsePriceInfo = (data) => {
|
|
9392
|
-
const decoded = borsh.deserialize(priceUpdateV2Schema, data);
|
|
9394
|
+
const decoded = borsh$1.deserialize(priceUpdateV2Schema, data);
|
|
9393
9395
|
return decoded;
|
|
9394
9396
|
};
|
|
9395
9397
|
function capConfidenceInterval$1(price, confidence, maxConfidence) {
|
|
9396
9398
|
const maxConfidenceInterval = price.times(maxConfidence);
|
|
9397
|
-
return
|
|
9399
|
+
return BigNumber.min(confidence, maxConfidenceInterval);
|
|
9398
9400
|
}
|
|
9399
9401
|
|
|
9400
9402
|
//#endregion
|
|
@@ -9409,7 +9411,7 @@ var Account = class {
|
|
|
9409
9411
|
*/
|
|
9410
9412
|
constructor(program, publicKey) {
|
|
9411
9413
|
this.program = program;
|
|
9412
|
-
this.publicKey = typeof publicKey === "string" ? new
|
|
9414
|
+
this.publicKey = typeof publicKey === "string" ? new anchor.web3.PublicKey(publicKey) : publicKey;
|
|
9413
9415
|
}
|
|
9414
9416
|
};
|
|
9415
9417
|
const BUFFER_DISCRIMINATOR = Buffer.from([
|
|
@@ -9484,7 +9486,7 @@ function fromJSON(obj) {
|
|
|
9484
9486
|
}
|
|
9485
9487
|
}
|
|
9486
9488
|
function layout(property) {
|
|
9487
|
-
const ret =
|
|
9489
|
+
const ret = borsh.rustEnum([borsh.struct([], "ModeRoundResolution"), borsh.struct([], "ModeSlidingResolution")]);
|
|
9488
9490
|
if (property !== undefined) {
|
|
9489
9491
|
return ret.replicate(property);
|
|
9490
9492
|
}
|
|
@@ -9506,7 +9508,7 @@ var SwitchboardDecimal = class SwitchboardDecimal {
|
|
|
9506
9508
|
this.scale = fields.scale;
|
|
9507
9509
|
}
|
|
9508
9510
|
static layout(property) {
|
|
9509
|
-
return
|
|
9511
|
+
return borsh.struct([borsh.i128("mantissa"), borsh.u32("scale")], property);
|
|
9510
9512
|
}
|
|
9511
9513
|
static fromDecoded(obj) {
|
|
9512
9514
|
return new SwitchboardDecimal({
|
|
@@ -9528,7 +9530,7 @@ var SwitchboardDecimal = class SwitchboardDecimal {
|
|
|
9528
9530
|
}
|
|
9529
9531
|
static fromJSON(obj) {
|
|
9530
9532
|
return new SwitchboardDecimal({
|
|
9531
|
-
mantissa: new
|
|
9533
|
+
mantissa: new BN$1(obj.mantissa),
|
|
9532
9534
|
scale: obj.scale
|
|
9533
9535
|
});
|
|
9534
9536
|
}
|
|
@@ -9539,7 +9541,7 @@ var SwitchboardDecimal = class SwitchboardDecimal {
|
|
|
9539
9541
|
*/
|
|
9540
9542
|
static from(obj) {
|
|
9541
9543
|
return new SwitchboardDecimal({
|
|
9542
|
-
mantissa: new
|
|
9544
|
+
mantissa: new BN$1(obj.mantissa),
|
|
9543
9545
|
scale: obj.scale
|
|
9544
9546
|
});
|
|
9545
9547
|
}
|
|
@@ -9550,10 +9552,10 @@ var SwitchboardDecimal = class SwitchboardDecimal {
|
|
|
9550
9552
|
*/
|
|
9551
9553
|
static fromBig(big) {
|
|
9552
9554
|
big = big.round(20);
|
|
9553
|
-
let mantissa = new
|
|
9555
|
+
let mantissa = new BN$1(big.c.join(""), 10);
|
|
9554
9556
|
let scale = big.c.slice(1).length - big.e;
|
|
9555
9557
|
if (scale < 0) {
|
|
9556
|
-
mantissa = mantissa.mul(new
|
|
9558
|
+
mantissa = mantissa.mul(new BN$1(10, 10).pow(new BN$1(Math.abs(scale), 10)));
|
|
9557
9559
|
scale = 0;
|
|
9558
9560
|
}
|
|
9559
9561
|
if (scale < 0) {
|
|
@@ -9562,7 +9564,7 @@ var SwitchboardDecimal = class SwitchboardDecimal {
|
|
|
9562
9564
|
if (scale >= 28) {
|
|
9563
9565
|
throw new Error("SwitchboardDecimalExcessiveScaleError");
|
|
9564
9566
|
}
|
|
9565
|
-
mantissa = mantissa.mul(new
|
|
9567
|
+
mantissa = mantissa.mul(new BN$1(big.s, 10));
|
|
9566
9568
|
const result = new SwitchboardDecimal({
|
|
9567
9569
|
mantissa,
|
|
9568
9570
|
scale
|
|
@@ -9582,11 +9584,11 @@ var SwitchboardDecimal = class SwitchboardDecimal {
|
|
|
9582
9584
|
* @return Big representation
|
|
9583
9585
|
*/
|
|
9584
9586
|
toBig() {
|
|
9585
|
-
let mantissa = new
|
|
9587
|
+
let mantissa = new BN$1(this.mantissa, 10);
|
|
9586
9588
|
let s = 1;
|
|
9587
9589
|
const c = [];
|
|
9588
|
-
const ZERO = new
|
|
9589
|
-
const TEN = new
|
|
9590
|
+
const ZERO = new BN$1(0, 10);
|
|
9591
|
+
const TEN = new BN$1(10, 10);
|
|
9590
9592
|
if (mantissa.lt(ZERO)) {
|
|
9591
9593
|
s = -1;
|
|
9592
9594
|
mantissa = mantissa.abs();
|
|
@@ -9596,7 +9598,7 @@ var SwitchboardDecimal = class SwitchboardDecimal {
|
|
|
9596
9598
|
mantissa = mantissa.div(TEN);
|
|
9597
9599
|
}
|
|
9598
9600
|
const e = c.length - this.scale - 1;
|
|
9599
|
-
const result = new
|
|
9601
|
+
const result = new Big(0);
|
|
9600
9602
|
if (c.length === 0) {
|
|
9601
9603
|
return result;
|
|
9602
9604
|
}
|
|
@@ -9658,21 +9660,21 @@ var AggregatorRound = class AggregatorRound {
|
|
|
9658
9660
|
this.errorsFulfilled = fields.errorsFulfilled;
|
|
9659
9661
|
}
|
|
9660
9662
|
static layout(property) {
|
|
9661
|
-
return
|
|
9662
|
-
|
|
9663
|
-
|
|
9664
|
-
|
|
9665
|
-
|
|
9666
|
-
|
|
9663
|
+
return borsh.struct([
|
|
9664
|
+
borsh.u32("numSuccess"),
|
|
9665
|
+
borsh.u32("numError"),
|
|
9666
|
+
borsh.bool("isClosed"),
|
|
9667
|
+
borsh.u64("roundOpenSlot"),
|
|
9668
|
+
borsh.i64("roundOpenTimestamp"),
|
|
9667
9669
|
SwitchboardDecimal.layout("result"),
|
|
9668
9670
|
SwitchboardDecimal.layout("stdDeviation"),
|
|
9669
9671
|
SwitchboardDecimal.layout("minResponse"),
|
|
9670
9672
|
SwitchboardDecimal.layout("maxResponse"),
|
|
9671
|
-
|
|
9672
|
-
|
|
9673
|
-
|
|
9674
|
-
|
|
9675
|
-
|
|
9673
|
+
borsh.array(borsh.publicKey(), 16, "oraclePubkeysData"),
|
|
9674
|
+
borsh.array(SwitchboardDecimal.layout({}), 16, "mediansData"),
|
|
9675
|
+
borsh.array(borsh.i64(), 16, "currentPayout"),
|
|
9676
|
+
borsh.array(borsh.bool(), 16, "mediansFulfilled"),
|
|
9677
|
+
borsh.array(borsh.bool(), 16, "errorsFulfilled")
|
|
9676
9678
|
], property);
|
|
9677
9679
|
}
|
|
9678
9680
|
static fromDecoded(obj) {
|
|
@@ -9734,15 +9736,15 @@ var AggregatorRound = class AggregatorRound {
|
|
|
9734
9736
|
numSuccess: obj.numSuccess,
|
|
9735
9737
|
numError: obj.numError,
|
|
9736
9738
|
isClosed: obj.isClosed,
|
|
9737
|
-
roundOpenSlot: new
|
|
9738
|
-
roundOpenTimestamp: new
|
|
9739
|
+
roundOpenSlot: new BN$1(obj.roundOpenSlot),
|
|
9740
|
+
roundOpenTimestamp: new BN$1(obj.roundOpenTimestamp),
|
|
9739
9741
|
result: SwitchboardDecimal.fromJSON(obj.result),
|
|
9740
9742
|
stdDeviation: SwitchboardDecimal.fromJSON(obj.stdDeviation),
|
|
9741
9743
|
minResponse: SwitchboardDecimal.fromJSON(obj.minResponse),
|
|
9742
9744
|
maxResponse: SwitchboardDecimal.fromJSON(obj.maxResponse),
|
|
9743
|
-
oraclePubkeysData: obj.oraclePubkeysData.map((item) => new
|
|
9745
|
+
oraclePubkeysData: obj.oraclePubkeysData.map((item) => new PublicKey(item)),
|
|
9744
9746
|
mediansData: obj.mediansData.map((item) => SwitchboardDecimal.fromJSON(item)),
|
|
9745
|
-
currentPayout: obj.currentPayout.map((item) => new
|
|
9747
|
+
currentPayout: obj.currentPayout.map((item) => new BN$1(item)),
|
|
9746
9748
|
mediansFulfilled: obj.mediansFulfilled,
|
|
9747
9749
|
errorsFulfilled: obj.errorsFulfilled
|
|
9748
9750
|
});
|
|
@@ -9761,7 +9763,7 @@ var Hash = class Hash {
|
|
|
9761
9763
|
this.data = fields.data;
|
|
9762
9764
|
}
|
|
9763
9765
|
static layout(property) {
|
|
9764
|
-
return
|
|
9766
|
+
return borsh.struct([borsh.array(borsh.u8(), 32, "data")], property);
|
|
9765
9767
|
}
|
|
9766
9768
|
static fromDecoded(obj) {
|
|
9767
9769
|
return new Hash({ data: obj.data });
|
|
@@ -9865,42 +9867,42 @@ var AggregatorAccountData = class AggregatorAccountData {
|
|
|
9865
9867
|
27,
|
|
9866
9868
|
125
|
|
9867
9869
|
]);
|
|
9868
|
-
static layout =
|
|
9869
|
-
|
|
9870
|
-
|
|
9871
|
-
|
|
9872
|
-
|
|
9873
|
-
|
|
9874
|
-
|
|
9875
|
-
|
|
9876
|
-
|
|
9877
|
-
|
|
9870
|
+
static layout = borsh.struct([
|
|
9871
|
+
borsh.array(borsh.u8(), 32, "name"),
|
|
9872
|
+
borsh.array(borsh.u8(), 128, "metadata"),
|
|
9873
|
+
borsh.array(borsh.u8(), 32, "reserved1"),
|
|
9874
|
+
borsh.publicKey("queuePubkey"),
|
|
9875
|
+
borsh.u32("oracleRequestBatchSize"),
|
|
9876
|
+
borsh.u32("minOracleResults"),
|
|
9877
|
+
borsh.u32("minJobResults"),
|
|
9878
|
+
borsh.u32("minUpdateDelaySeconds"),
|
|
9879
|
+
borsh.i64("startAfter"),
|
|
9878
9880
|
SwitchboardDecimal.layout("varianceThreshold"),
|
|
9879
|
-
|
|
9880
|
-
|
|
9881
|
-
|
|
9882
|
-
|
|
9883
|
-
|
|
9884
|
-
|
|
9881
|
+
borsh.i64("forceReportPeriod"),
|
|
9882
|
+
borsh.i64("expiration"),
|
|
9883
|
+
borsh.u64("consecutiveFailureCount"),
|
|
9884
|
+
borsh.i64("nextAllowedUpdateTime"),
|
|
9885
|
+
borsh.bool("isLocked"),
|
|
9886
|
+
borsh.publicKey("crankPubkey"),
|
|
9885
9887
|
AggregatorRound.layout("latestConfirmedRound"),
|
|
9886
9888
|
AggregatorRound.layout("currentRound"),
|
|
9887
|
-
|
|
9888
|
-
|
|
9889
|
-
|
|
9890
|
-
|
|
9891
|
-
|
|
9892
|
-
|
|
9889
|
+
borsh.array(borsh.publicKey(), 16, "jobPubkeysData"),
|
|
9890
|
+
borsh.array(Hash.layout({}), 16, "jobHashes"),
|
|
9891
|
+
borsh.u32("jobPubkeysSize"),
|
|
9892
|
+
borsh.array(borsh.u8(), 32, "jobsChecksum"),
|
|
9893
|
+
borsh.publicKey("authority"),
|
|
9894
|
+
borsh.publicKey("historyBuffer"),
|
|
9893
9895
|
SwitchboardDecimal.layout("previousConfirmedRoundResult"),
|
|
9894
|
-
|
|
9895
|
-
|
|
9896
|
-
|
|
9897
|
-
|
|
9896
|
+
borsh.u64("previousConfirmedRoundSlot"),
|
|
9897
|
+
borsh.bool("disableCrank"),
|
|
9898
|
+
borsh.array(borsh.u8(), 16, "jobWeights"),
|
|
9899
|
+
borsh.i64("creationTimestamp"),
|
|
9898
9900
|
layout("resolutionMode"),
|
|
9899
|
-
|
|
9900
|
-
|
|
9901
|
-
|
|
9902
|
-
|
|
9903
|
-
|
|
9901
|
+
borsh.u32("basePriorityFee"),
|
|
9902
|
+
borsh.u32("priorityFeeBump"),
|
|
9903
|
+
borsh.u32("priorityFeeBumpPeriod"),
|
|
9904
|
+
borsh.u32("maxPriorityFeeMultiplier"),
|
|
9905
|
+
borsh.array(borsh.u8(), 122, "ebuf")
|
|
9904
9906
|
]);
|
|
9905
9907
|
constructor(fields) {
|
|
9906
9908
|
this.name = fields.name;
|
|
@@ -13650,9 +13652,9 @@ var idl_default = {
|
|
|
13650
13652
|
//#endregion
|
|
13651
13653
|
//#region src/vendor/switchboard_pull/index.ts
|
|
13652
13654
|
const SWITCHBOARD_ONDEMANDE_PRICE_PRECISION = 18;
|
|
13653
|
-
const switchboardAccountCoder = new
|
|
13655
|
+
const switchboardAccountCoder = new BorshCoder(idl_default);
|
|
13654
13656
|
function getSwitchboardProgram(provider) {
|
|
13655
|
-
return new
|
|
13657
|
+
return new Program(idl_default, provider);
|
|
13656
13658
|
}
|
|
13657
13659
|
function decodeSwitchboardPullFeedData(data) {
|
|
13658
13660
|
const pullFeedDAta = switchboardAccountCoder.accounts.decode("PullFeedAccountData", data);
|
|
@@ -13674,7 +13676,7 @@ function getPrice(oraclePrice, priceBias = PriceBias.None, weightedPrice = false
|
|
|
13674
13676
|
}
|
|
13675
13677
|
function capConfidenceInterval(price, confidence, maxConfidence) {
|
|
13676
13678
|
const maxConfidenceInterval = price.times(maxConfidence);
|
|
13677
|
-
return
|
|
13679
|
+
return BigNumber.min(confidence, maxConfidenceInterval);
|
|
13678
13680
|
}
|
|
13679
13681
|
function parseOraclePriceData(oracleSetup, rawData, logger = new NoopLogger(), shardId) {
|
|
13680
13682
|
switch (oracleSetup) {
|
|
@@ -13688,14 +13690,14 @@ function parseOraclePriceData(oracleSetup, rawData, logger = new NoopLogger(), s
|
|
|
13688
13690
|
if (confidenceData === undefined) {
|
|
13689
13691
|
confidenceData = pythPriceData.previousConfidence;
|
|
13690
13692
|
}
|
|
13691
|
-
const pythPriceRealtime = new
|
|
13692
|
-
const pythConfidenceRealtime = new
|
|
13693
|
-
const pythConfidenceRealtimeCapped = capConfidenceInterval(pythPriceRealtime, pythConfidenceRealtime,
|
|
13693
|
+
const pythPriceRealtime = new BigNumber(priceData);
|
|
13694
|
+
const pythConfidenceRealtime = new BigNumber(confidenceData).times(PYTH_PRICE_CONF_INTERVALS);
|
|
13695
|
+
const pythConfidenceRealtimeCapped = capConfidenceInterval(pythPriceRealtime, pythConfidenceRealtime, PYTH_PRICE_CONF_INTERVALS);
|
|
13694
13696
|
const pythLowestPriceRealtime = pythPriceRealtime.minus(pythConfidenceRealtimeCapped);
|
|
13695
13697
|
const pythHighestPriceRealtime = pythPriceRealtime.plus(pythConfidenceRealtimeCapped);
|
|
13696
|
-
const pythPriceWeighted = new
|
|
13697
|
-
const pythConfIntervalWeighted = new
|
|
13698
|
-
const pythConfIntervalWeightedCapped = capConfidenceInterval(pythPriceWeighted, pythConfIntervalWeighted,
|
|
13698
|
+
const pythPriceWeighted = new BigNumber(pythPriceData.emaPrice.value);
|
|
13699
|
+
const pythConfIntervalWeighted = new BigNumber(pythPriceData.emaConfidence.value).times(PYTH_PRICE_CONF_INTERVALS);
|
|
13700
|
+
const pythConfIntervalWeightedCapped = capConfidenceInterval(pythPriceWeighted, pythConfIntervalWeighted, PYTH_PRICE_CONF_INTERVALS);
|
|
13699
13701
|
const pythLowestPrice = pythPriceWeighted.minus(pythConfIntervalWeightedCapped);
|
|
13700
13702
|
const pythHighestPrice = pythPriceWeighted.plus(pythConfIntervalWeightedCapped);
|
|
13701
13703
|
logger.debug({
|
|
@@ -13717,7 +13719,7 @@ function parseOraclePriceData(oracleSetup, rawData, logger = new NoopLogger(), s
|
|
|
13717
13719
|
lowestPrice: pythLowestPrice,
|
|
13718
13720
|
highestPrice: pythHighestPrice
|
|
13719
13721
|
},
|
|
13720
|
-
timestamp: new
|
|
13722
|
+
timestamp: new BigNumber(Number(pythPriceData.timestamp)),
|
|
13721
13723
|
pythShardId: shardId
|
|
13722
13724
|
};
|
|
13723
13725
|
}
|
|
@@ -13725,15 +13727,15 @@ function parseOraclePriceData(oracleSetup, rawData, logger = new NoopLogger(), s
|
|
|
13725
13727
|
case OracleSetup.StakedWithPythPush: {
|
|
13726
13728
|
const bytesWithoutDiscriminator = rawData.slice(8);
|
|
13727
13729
|
const data = parsePriceInfo(bytesWithoutDiscriminator);
|
|
13728
|
-
const exponent = new
|
|
13729
|
-
const priceRealTime = new
|
|
13730
|
-
const confidenceRealTime = new
|
|
13731
|
-
const cappedConfidenceRealTime = capConfidenceInterval(priceRealTime, confidenceRealTime,
|
|
13730
|
+
const exponent = new BigNumber(10 ** data.priceMessage.exponent);
|
|
13731
|
+
const priceRealTime = new BigNumber(Number(data.priceMessage.price)).times(exponent);
|
|
13732
|
+
const confidenceRealTime = new BigNumber(Number(data.priceMessage.conf)).times(exponent).times(PYTH_PRICE_CONF_INTERVALS);
|
|
13733
|
+
const cappedConfidenceRealTime = capConfidenceInterval(priceRealTime, confidenceRealTime, MAX_CONFIDENCE_INTERVAL_RATIO);
|
|
13732
13734
|
const lowestPriceRealTime = priceRealTime.minus(cappedConfidenceRealTime);
|
|
13733
13735
|
const highestPriceRealTime = priceRealTime.plus(cappedConfidenceRealTime);
|
|
13734
|
-
const priceTimeWeighted = new
|
|
13735
|
-
const confidenceTimeWeighted = new
|
|
13736
|
-
const cappedConfidenceWeighted = capConfidenceInterval(priceTimeWeighted, confidenceTimeWeighted,
|
|
13736
|
+
const priceTimeWeighted = new BigNumber(Number(data.priceMessage.emaPrice)).times(exponent);
|
|
13737
|
+
const confidenceTimeWeighted = new BigNumber(Number(data.priceMessage.emaConf)).times(exponent).times(PYTH_PRICE_CONF_INTERVALS);
|
|
13738
|
+
const cappedConfidenceWeighted = capConfidenceInterval(priceTimeWeighted, confidenceTimeWeighted, MAX_CONFIDENCE_INTERVAL_RATIO);
|
|
13737
13739
|
const lowestPriceWeighted = priceTimeWeighted.minus(cappedConfidenceWeighted);
|
|
13738
13740
|
const highestPriceWeighted = priceTimeWeighted.plus(cappedConfidenceWeighted);
|
|
13739
13741
|
return {
|
|
@@ -13749,15 +13751,15 @@ function parseOraclePriceData(oracleSetup, rawData, logger = new NoopLogger(), s
|
|
|
13749
13751
|
lowestPrice: lowestPriceWeighted,
|
|
13750
13752
|
highestPrice: highestPriceWeighted
|
|
13751
13753
|
},
|
|
13752
|
-
timestamp: new
|
|
13754
|
+
timestamp: new BigNumber(Number(data.priceMessage.publishTime)),
|
|
13753
13755
|
pythShardId: shardId
|
|
13754
13756
|
};
|
|
13755
13757
|
}
|
|
13756
13758
|
case OracleSetup.SwitchboardV2: {
|
|
13757
13759
|
const aggData = AggregatorAccountData.decode(rawData);
|
|
13758
|
-
const swbPrice = new
|
|
13759
|
-
const swbConfidence = new
|
|
13760
|
-
const swbConfidenceCapped = capConfidenceInterval(swbPrice, swbConfidence,
|
|
13760
|
+
const swbPrice = new BigNumber(AggregatorAccount.decodeLatestValue(aggData).toString());
|
|
13761
|
+
const swbConfidence = new BigNumber(aggData.latestConfirmedRound.stdDeviation.toBig().toString()).times(SWB_PRICE_CONF_INTERVALS);
|
|
13762
|
+
const swbConfidenceCapped = capConfidenceInterval(swbPrice, swbConfidence, MAX_CONFIDENCE_INTERVAL_RATIO);
|
|
13761
13763
|
const swbLowestPrice = swbPrice.minus(swbConfidenceCapped);
|
|
13762
13764
|
const swbHighestPrice = swbPrice.plus(swbConfidenceCapped);
|
|
13763
13765
|
logger.debug({
|
|
@@ -13777,14 +13779,14 @@ function parseOraclePriceData(oracleSetup, rawData, logger = new NoopLogger(), s
|
|
|
13777
13779
|
lowestPrice: swbLowestPrice,
|
|
13778
13780
|
highestPrice: swbHighestPrice
|
|
13779
13781
|
},
|
|
13780
|
-
timestamp: new
|
|
13782
|
+
timestamp: new BigNumber(aggData.latestConfirmedRound.roundOpenTimestamp)
|
|
13781
13783
|
};
|
|
13782
13784
|
}
|
|
13783
13785
|
case OracleSetup.SwitchboardPull: {
|
|
13784
13786
|
const pullFeedDAta = decodeSwitchboardPullFeedData(rawData);
|
|
13785
|
-
const swbPrice = new
|
|
13786
|
-
const swbConfidence = new
|
|
13787
|
-
const swbConfidenceCapped = capConfidenceInterval(swbPrice, swbConfidence,
|
|
13787
|
+
const swbPrice = new BigNumber(pullFeedDAta.result.value.toString()).div(10 ** SWITCHBOARD_ONDEMANDE_PRICE_PRECISION);
|
|
13788
|
+
const swbConfidence = new BigNumber(pullFeedDAta.result.std_dev.toString()).times(SWB_PRICE_CONF_INTERVALS);
|
|
13789
|
+
const swbConfidenceCapped = capConfidenceInterval(swbPrice, swbConfidence, MAX_CONFIDENCE_INTERVAL_RATIO);
|
|
13788
13790
|
const swbLowestPrice = swbPrice.minus(swbConfidenceCapped);
|
|
13789
13791
|
const swbHighestPrice = swbPrice.plus(swbConfidenceCapped);
|
|
13790
13792
|
logger.debug({
|
|
@@ -13804,7 +13806,7 @@ function parseOraclePriceData(oracleSetup, rawData, logger = new NoopLogger(), s
|
|
|
13804
13806
|
lowestPrice: swbLowestPrice,
|
|
13805
13807
|
highestPrice: swbHighestPrice
|
|
13806
13808
|
},
|
|
13807
|
-
timestamp: new
|
|
13809
|
+
timestamp: new BigNumber(pullFeedDAta.last_update_timestamp.toString())
|
|
13808
13810
|
};
|
|
13809
13811
|
}
|
|
13810
13812
|
default:
|
|
@@ -13818,18 +13820,18 @@ function parseOraclePriceData(oracleSetup, rawData, logger = new NoopLogger(), s
|
|
|
13818
13820
|
function dtoToOraclePrice(dto) {
|
|
13819
13821
|
return {
|
|
13820
13822
|
priceRealtime: {
|
|
13821
|
-
price: new
|
|
13822
|
-
confidence: new
|
|
13823
|
-
lowestPrice: new
|
|
13824
|
-
highestPrice: new
|
|
13823
|
+
price: new BigNumber(dto.priceRealtime.price),
|
|
13824
|
+
confidence: new BigNumber(dto.priceRealtime.confidence),
|
|
13825
|
+
lowestPrice: new BigNumber(dto.priceRealtime.lowestPrice),
|
|
13826
|
+
highestPrice: new BigNumber(dto.priceRealtime.highestPrice)
|
|
13825
13827
|
},
|
|
13826
13828
|
priceWeighted: {
|
|
13827
|
-
price: new
|
|
13828
|
-
confidence: new
|
|
13829
|
-
lowestPrice: new
|
|
13830
|
-
highestPrice: new
|
|
13829
|
+
price: new BigNumber(dto.priceWeighted.price),
|
|
13830
|
+
confidence: new BigNumber(dto.priceWeighted.confidence),
|
|
13831
|
+
lowestPrice: new BigNumber(dto.priceWeighted.lowestPrice),
|
|
13832
|
+
highestPrice: new BigNumber(dto.priceWeighted.highestPrice)
|
|
13831
13833
|
},
|
|
13832
|
-
timestamp: new
|
|
13834
|
+
timestamp: new BigNumber(dto.timestamp),
|
|
13833
13835
|
pythShardId: dto.pythShardId
|
|
13834
13836
|
};
|
|
13835
13837
|
}
|
|
@@ -13868,7 +13870,7 @@ const fetchPythDataViaAPI = async (pythPushBanks, voteAccMintTuples) => {
|
|
|
13868
13870
|
const pythFeedMap = new Map();
|
|
13869
13871
|
Object.entries(pythFeedMapJson).forEach(([feedId, { feedId: feedIdStr, shardId }]) => {
|
|
13870
13872
|
pythFeedMap.set(feedId, {
|
|
13871
|
-
feedId: new
|
|
13873
|
+
feedId: new PublicKey(feedIdStr),
|
|
13872
13874
|
shardId
|
|
13873
13875
|
});
|
|
13874
13876
|
});
|
|
@@ -13926,18 +13928,18 @@ const fetchPythOraclePricesViaAPI = async (pythOracleKeys) => {
|
|
|
13926
13928
|
const responseBody = await response.json();
|
|
13927
13929
|
return Object.fromEntries(Object.entries(responseBody).map(([key, oraclePrice]) => [key, {
|
|
13928
13930
|
priceRealtime: {
|
|
13929
|
-
price: (
|
|
13930
|
-
confidence: (
|
|
13931
|
-
lowestPrice: (
|
|
13932
|
-
highestPrice: (
|
|
13931
|
+
price: BigNumber(oraclePrice.priceRealtime.price),
|
|
13932
|
+
confidence: BigNumber(oraclePrice.priceRealtime.confidence),
|
|
13933
|
+
lowestPrice: BigNumber(oraclePrice.priceRealtime.lowestPrice),
|
|
13934
|
+
highestPrice: BigNumber(oraclePrice.priceRealtime.highestPrice)
|
|
13933
13935
|
},
|
|
13934
13936
|
priceWeighted: {
|
|
13935
|
-
price: (
|
|
13936
|
-
confidence: (
|
|
13937
|
-
lowestPrice: (
|
|
13938
|
-
highestPrice: (
|
|
13937
|
+
price: BigNumber(oraclePrice.priceWeighted.price),
|
|
13938
|
+
confidence: BigNumber(oraclePrice.priceWeighted.confidence),
|
|
13939
|
+
lowestPrice: BigNumber(oraclePrice.priceWeighted.lowestPrice),
|
|
13940
|
+
highestPrice: BigNumber(oraclePrice.priceWeighted.highestPrice)
|
|
13939
13941
|
},
|
|
13940
|
-
timestamp: oraclePrice.timestamp ? (
|
|
13942
|
+
timestamp: oraclePrice.timestamp ? BigNumber(oraclePrice.timestamp) : null,
|
|
13941
13943
|
pythShardId: oraclePrice.pythShardId
|
|
13942
13944
|
}]));
|
|
13943
13945
|
};
|
|
@@ -14056,18 +14058,18 @@ const fetchSwbOraclePricesViaAPI = async (swbFeedIds) => {
|
|
|
14056
14058
|
const responseBody = await response.json();
|
|
14057
14059
|
return Object.fromEntries(Object.entries(responseBody).map(([key, oraclePrice]) => [key, {
|
|
14058
14060
|
priceRealtime: {
|
|
14059
|
-
price: (
|
|
14060
|
-
confidence: (
|
|
14061
|
-
lowestPrice: (
|
|
14062
|
-
highestPrice: (
|
|
14061
|
+
price: BigNumber(oraclePrice.priceRealtime.price),
|
|
14062
|
+
confidence: BigNumber(oraclePrice.priceRealtime.confidence),
|
|
14063
|
+
lowestPrice: BigNumber(oraclePrice.priceRealtime.lowestPrice),
|
|
14064
|
+
highestPrice: BigNumber(oraclePrice.priceRealtime.highestPrice)
|
|
14063
14065
|
},
|
|
14064
14066
|
priceWeighted: {
|
|
14065
|
-
price: (
|
|
14066
|
-
confidence: (
|
|
14067
|
-
lowestPrice: (
|
|
14068
|
-
highestPrice: (
|
|
14067
|
+
price: BigNumber(oraclePrice.priceWeighted.price),
|
|
14068
|
+
confidence: BigNumber(oraclePrice.priceWeighted.confidence),
|
|
14069
|
+
lowestPrice: BigNumber(oraclePrice.priceWeighted.lowestPrice),
|
|
14070
|
+
highestPrice: BigNumber(oraclePrice.priceWeighted.highestPrice)
|
|
14069
14071
|
},
|
|
14070
|
-
timestamp: oraclePrice.timestamp ? (
|
|
14072
|
+
timestamp: oraclePrice.timestamp ? BigNumber(oraclePrice.timestamp) : null
|
|
14071
14073
|
}]));
|
|
14072
14074
|
};
|
|
14073
14075
|
/**
|
|
@@ -14106,18 +14108,18 @@ const fetchOracleData = async (banks, bankMetadataMap, connection, opts) => {
|
|
|
14106
14108
|
console.error(`Bank ${bank.address.toBase58()} is missing an oracle price`);
|
|
14107
14109
|
bankOraclePriceMap.set(bank.address.toBase58(), {
|
|
14108
14110
|
priceRealtime: {
|
|
14109
|
-
price: (0
|
|
14110
|
-
confidence: (0
|
|
14111
|
-
lowestPrice: (0
|
|
14112
|
-
highestPrice: (0
|
|
14111
|
+
price: BigNumber(0),
|
|
14112
|
+
confidence: BigNumber(0),
|
|
14113
|
+
lowestPrice: BigNumber(0),
|
|
14114
|
+
highestPrice: BigNumber(0)
|
|
14113
14115
|
},
|
|
14114
14116
|
priceWeighted: {
|
|
14115
|
-
price: (0
|
|
14116
|
-
confidence: (0
|
|
14117
|
-
lowestPrice: (0
|
|
14118
|
-
highestPrice: (0
|
|
14117
|
+
price: BigNumber(0),
|
|
14118
|
+
confidence: BigNumber(0),
|
|
14119
|
+
lowestPrice: BigNumber(0),
|
|
14120
|
+
highestPrice: BigNumber(0)
|
|
14119
14121
|
},
|
|
14120
|
-
timestamp: (0
|
|
14122
|
+
timestamp: BigNumber(0)
|
|
14121
14123
|
});
|
|
14122
14124
|
}
|
|
14123
14125
|
});
|
|
@@ -14161,7 +14163,7 @@ function computeMaxLeverage(depositBank, borrowBank, opts) {
|
|
|
14161
14163
|
};
|
|
14162
14164
|
}
|
|
14163
14165
|
function computeLoopingParams(principal, targetLeverage, depositBank, borrowBank, depositOracleInfo, borrowOracleInfo) {
|
|
14164
|
-
const initialCollateral =
|
|
14166
|
+
const initialCollateral = toBigNumber(principal);
|
|
14165
14167
|
const { maxLeverage } = computeMaxLeverage(depositBank, borrowBank);
|
|
14166
14168
|
if (targetLeverage < 1) {
|
|
14167
14169
|
throw Error(`Target leverage ${targetLeverage} needs to be greater than 1`);
|
|
@@ -14169,7 +14171,7 @@ function computeLoopingParams(principal, targetLeverage, depositBank, borrowBank
|
|
|
14169
14171
|
if (targetLeverage > maxLeverage) {
|
|
14170
14172
|
throw Error(`Target leverage ${targetLeverage} exceeds max leverage for banks ${maxLeverage}`);
|
|
14171
14173
|
}
|
|
14172
|
-
const totalDepositAmount = initialCollateral.times(new
|
|
14174
|
+
const totalDepositAmount = initialCollateral.times(new BigNumber(targetLeverage));
|
|
14173
14175
|
const additionalDepositAmount = totalDepositAmount.minus(initialCollateral);
|
|
14174
14176
|
const borrowAmount = additionalDepositAmount.times(depositOracleInfo.priceWeighted.lowestPrice).div(borrowOracleInfo.priceWeighted.highestPrice);
|
|
14175
14177
|
return {
|
|
@@ -14210,7 +14212,7 @@ function getAssetWeight(bank, lendrRequirementType, oraclePrice, opts) {
|
|
|
14210
14212
|
}
|
|
14211
14213
|
}
|
|
14212
14214
|
case LendrRequirementType.Maintenance: return bank.config.assetWeightMaint;
|
|
14213
|
-
case LendrRequirementType.Equity: return new
|
|
14215
|
+
case LendrRequirementType.Equity: return new BigNumber(1);
|
|
14214
14216
|
default: throw new Error("Invalid lendr requirement type");
|
|
14215
14217
|
}
|
|
14216
14218
|
}
|
|
@@ -14218,7 +14220,7 @@ function getLiabilityWeight(config, lendrRequirementType) {
|
|
|
14218
14220
|
switch (lendrRequirementType) {
|
|
14219
14221
|
case LendrRequirementType.Initial: return config.liabilityWeightInit;
|
|
14220
14222
|
case LendrRequirementType.Maintenance: return config.liabilityWeightMaint;
|
|
14221
|
-
case LendrRequirementType.Equity: return new
|
|
14223
|
+
case LendrRequirementType.Equity: return new BigNumber(1);
|
|
14222
14224
|
default: throw new Error("Invalid lendr requirement type");
|
|
14223
14225
|
}
|
|
14224
14226
|
}
|
|
@@ -14249,7 +14251,7 @@ function computeInterestRates(bank) {
|
|
|
14249
14251
|
const baseInterestRate = computeBaseInterestRate(bank);
|
|
14250
14252
|
const utilizationRate = computeUtilizationRate(bank);
|
|
14251
14253
|
const lendingRate = baseInterestRate.times(utilizationRate);
|
|
14252
|
-
const borrowingRate = baseInterestRate.times(new
|
|
14254
|
+
const borrowingRate = baseInterestRate.times(new BigNumber(1).plus(rateFee)).plus(fixedFee);
|
|
14253
14255
|
return {
|
|
14254
14256
|
lendingRate,
|
|
14255
14257
|
borrowingRate
|
|
@@ -14261,22 +14263,22 @@ function computeBaseInterestRate(bank) {
|
|
|
14261
14263
|
if (utilizationRate.lte(optimalUtilizationRate)) {
|
|
14262
14264
|
return utilizationRate.times(plateauInterestRate).div(optimalUtilizationRate);
|
|
14263
14265
|
} else {
|
|
14264
|
-
return utilizationRate.minus(optimalUtilizationRate).div(new
|
|
14266
|
+
return utilizationRate.minus(optimalUtilizationRate).div(new BigNumber(1).minus(optimalUtilizationRate)).times(maxInterestRate.minus(plateauInterestRate)).plus(plateauInterestRate);
|
|
14265
14267
|
}
|
|
14266
14268
|
}
|
|
14267
14269
|
function computeUtilizationRate(bank) {
|
|
14268
14270
|
const assets = getTotalAssetQuantity(bank);
|
|
14269
14271
|
const liabilities = getTotalLiabilityQuantity(bank);
|
|
14270
|
-
if (assets.isZero()) return new
|
|
14272
|
+
if (assets.isZero()) return new BigNumber(0);
|
|
14271
14273
|
return liabilities.div(assets);
|
|
14272
14274
|
}
|
|
14273
14275
|
const SECONDS_PER_DAY$1 = 24 * 60 * 60;
|
|
14274
14276
|
const SECONDS_PER_YEAR$1 = SECONDS_PER_DAY$1 * 365.25;
|
|
14275
14277
|
function computeRemainingCapacity(bank) {
|
|
14276
14278
|
const totalDeposits = getTotalAssetQuantity(bank);
|
|
14277
|
-
const remainingCapacity =
|
|
14279
|
+
const remainingCapacity = BigNumber.max(0, bank.config.depositLimit.minus(totalDeposits));
|
|
14278
14280
|
const totalBorrows = getTotalLiabilityQuantity(bank);
|
|
14279
|
-
const remainingBorrowCapacity =
|
|
14281
|
+
const remainingBorrowCapacity = BigNumber.max(0, bank.config.borrowLimit.minus(totalBorrows));
|
|
14280
14282
|
const durationSinceLastAccrual = Date.now() / 1e3 - bank.lastUpdate;
|
|
14281
14283
|
const { lendingRate, borrowingRate } = computeInterestRates(bank);
|
|
14282
14284
|
const outstandingLendingInterest = lendingRate.times(durationSinceLastAccrual).dividedBy(SECONDS_PER_YEAR$1).times(totalDeposits);
|
|
@@ -14299,7 +14301,7 @@ const fetchMultipleBanks = async (program, opts) => {
|
|
|
14299
14301
|
data.forEach((d, idx) => {
|
|
14300
14302
|
if (d) {
|
|
14301
14303
|
bankDatas.push({
|
|
14302
|
-
address: new
|
|
14304
|
+
address: new PublicKey(addresses[idx]),
|
|
14303
14305
|
data: d
|
|
14304
14306
|
});
|
|
14305
14307
|
} else {
|
|
@@ -14323,8 +14325,8 @@ const fetchMultipleBanks = async (program, opts) => {
|
|
|
14323
14325
|
//#endregion
|
|
14324
14326
|
//#region src/services/bank/utils/serialize.utils.ts
|
|
14325
14327
|
function serializeBankConfigOpt(bankConfigOpt) {
|
|
14326
|
-
const toWrappedI80F48 = (value) => value &&
|
|
14327
|
-
const toBN = (value) => value && new
|
|
14328
|
+
const toWrappedI80F48 = (value) => value && bigNumberToWrappedI80F48(value);
|
|
14329
|
+
const toBN = (value) => value && new BN$1(value.toString());
|
|
14328
14330
|
return {
|
|
14329
14331
|
assetWeightInit: toWrappedI80F48(bankConfigOpt.assetWeightInit),
|
|
14330
14332
|
assetWeightMaint: toWrappedI80F48(bankConfigOpt.assetWeightMaint),
|
|
@@ -14594,20 +14596,20 @@ function getPriceFeedAccountForProgram(shardId, priceFeedId, pushOracleProgramId
|
|
|
14594
14596
|
}
|
|
14595
14597
|
const shardBuffer = Buffer.alloc(2);
|
|
14596
14598
|
shardBuffer.writeUint16LE(shardId, 0);
|
|
14597
|
-
return
|
|
14599
|
+
return PublicKey.findProgramAddressSync([shardBuffer, priceFeedId], pushOracleProgramId ?? DEFAULT_PUSH_ORACLE_PROGRAM_ID)[0];
|
|
14598
14600
|
}
|
|
14599
14601
|
const getTreasuryPda = (treasuryId, receiverProgramId) => {
|
|
14600
|
-
return
|
|
14602
|
+
return PublicKey.findProgramAddressSync([Buffer.from("treasury"), Buffer.from([treasuryId])], receiverProgramId)[0];
|
|
14601
14603
|
};
|
|
14602
14604
|
const getConfigPda = (receiverProgramId) => {
|
|
14603
|
-
return
|
|
14605
|
+
return PublicKey.findProgramAddressSync([Buffer.from("config")], receiverProgramId)[0];
|
|
14604
14606
|
};
|
|
14605
14607
|
async function crankPythOracleIx(oracles, provider) {
|
|
14606
14608
|
const feedIdsByShardId = {};
|
|
14607
|
-
const wormholeProgram = new
|
|
14608
|
-
const pushOracleProgram = new
|
|
14609
|
-
const receiverProgram = new
|
|
14610
|
-
const addressLookupTableAccount = new
|
|
14609
|
+
const wormholeProgram = new Program(PYTH_WORMHOLE_IDL, provider);
|
|
14610
|
+
const pushOracleProgram = new Program(PYTH_PUSH_ORACLE_IDL, provider);
|
|
14611
|
+
const receiverProgram = new Program(PYTH_SOLANA_RECEIVER_PROGRAM_IDL, provider);
|
|
14612
|
+
const addressLookupTableAccount = new PublicKey("5DNCErWQFBdvCxWQXaC1mrEFsvL3ftrzZ2gVZWNybaSX");
|
|
14611
14613
|
const lookupTableAccount = (await provider.connection.getAddressLookupTable(addressLookupTableAccount)).value;
|
|
14612
14614
|
const buildURL = (endpoint) => {
|
|
14613
14615
|
return new URL(`./v2/${endpoint}`, `https://hermes.pyth.network/`);
|
|
@@ -14648,7 +14650,7 @@ async function crankPythOracleIx(oracles, provider) {
|
|
|
14648
14650
|
priceFeedAccount: getPriceFeedAccountForProgram(Number(shardId), feedId, pushOracleProgram.programId),
|
|
14649
14651
|
treasury: getTreasuryPda(treasuryId, receiverProgram.programId),
|
|
14650
14652
|
config: getConfigPda(receiverProgram.programId),
|
|
14651
|
-
systemProgram:
|
|
14653
|
+
systemProgram: SYSTEM_PROGRAM_ID
|
|
14652
14654
|
}).instruction(),
|
|
14653
14655
|
signers: [],
|
|
14654
14656
|
computeUnits: UPDATE_PRICE_FEED_COMPUTE_BUDGET
|
|
@@ -14720,7 +14722,7 @@ async function sendTransactionAsBundle(connection, base58Txs, throwError = false
|
|
|
14720
14722
|
throw new SendBundleError(`${API_ERROR_TAG} ${sendBundleResult.error.message}`);
|
|
14721
14723
|
}
|
|
14722
14724
|
const bundleId = sendBundleResult.result;
|
|
14723
|
-
await
|
|
14725
|
+
await sleep(500);
|
|
14724
14726
|
for (let attempt = 0; attempt < 10; attempt++) {
|
|
14725
14727
|
const getBundleStatusResponse = await fetch("https://mainnet.block-engine.jito.wtf/api/v1/bundles", {
|
|
14726
14728
|
method: "POST",
|
|
@@ -14753,7 +14755,7 @@ async function sendTransactionAsBundle(connection, base58Txs, throwError = false
|
|
|
14753
14755
|
await confirmBundle(connection, bundleId);
|
|
14754
14756
|
return bundleId;
|
|
14755
14757
|
}
|
|
14756
|
-
await
|
|
14758
|
+
await sleep(1e3);
|
|
14757
14759
|
}
|
|
14758
14760
|
} catch (error) {
|
|
14759
14761
|
if (throwError) {
|
|
@@ -14767,7 +14769,7 @@ async function confirmBundle(connection, bundleId, commitment = "confirmed") {
|
|
|
14767
14769
|
let attempts = 0;
|
|
14768
14770
|
const maxAttempts = 5;
|
|
14769
14771
|
while (attempts < maxAttempts) {
|
|
14770
|
-
await
|
|
14772
|
+
await sleep(2e3);
|
|
14771
14773
|
attempts += 1;
|
|
14772
14774
|
const getBundleStatus = await fetch("https://mainnet.block-engine.jito.wtf/api/v1/bundles", {
|
|
14773
14775
|
method: "POST",
|
|
@@ -14793,7 +14795,7 @@ async function confirmBundle(connection, bundleId, commitment = "confirmed") {
|
|
|
14793
14795
|
console.log("❌ Transaction failed to confirm in time.");
|
|
14794
14796
|
throw new Error("Transaction failed to confirm in time.");
|
|
14795
14797
|
};
|
|
14796
|
-
const result = await Promise.race([getStatus(),
|
|
14798
|
+
const result = await Promise.race([getStatus(), setTimeoutPromise(2e4, `Transaction failed to confirm in time.`)]);
|
|
14797
14799
|
if (result instanceof Error) {
|
|
14798
14800
|
throw result;
|
|
14799
14801
|
}
|
|
@@ -14829,7 +14831,7 @@ async function simulateBundle(rpcEndpoint, transactions, includeAccounts) {
|
|
|
14829
14831
|
const result = await executeBundleSimulation(rpcEndpoint, encodedTransactions, config);
|
|
14830
14832
|
return result;
|
|
14831
14833
|
} catch (error) {
|
|
14832
|
-
if (error instanceof
|
|
14834
|
+
if (error instanceof SolanaJSONRPCError || error instanceof BundleSimulationError) {
|
|
14833
14835
|
throw error;
|
|
14834
14836
|
} else {
|
|
14835
14837
|
throw new BundleSimulationError("Failed to execute bundle simulation", undefined, error);
|
|
@@ -14935,7 +14937,7 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
14935
14937
|
...DEFAULT_PROCESS_TX_OPTS,
|
|
14936
14938
|
...processOptsArgs
|
|
14937
14939
|
};
|
|
14938
|
-
const commitment = connection.commitment ??
|
|
14940
|
+
const commitment = connection.commitment ?? DEFAULT_CONFIRM_OPTS.commitment;
|
|
14939
14941
|
if (processOpts?.broadcastType === "BUNDLE" && processOpts?.bundleTipUi === 0) {
|
|
14940
14942
|
throw new Error("A bundle tip is required for a bundled transactions");
|
|
14941
14943
|
}
|
|
@@ -14971,7 +14973,7 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
14971
14973
|
lastValidBlockHeight = getLatestBlockhashAndContext.value.lastValidBlockHeight;
|
|
14972
14974
|
} catch (error) {
|
|
14973
14975
|
console.error("Failed to get latest blockhash and context", error);
|
|
14974
|
-
if (error instanceof
|
|
14976
|
+
if (error instanceof SolanaJSONRPCError) {
|
|
14975
14977
|
throw error;
|
|
14976
14978
|
}
|
|
14977
14979
|
throw new ProcessTransactionError({
|
|
@@ -14981,7 +14983,7 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
14981
14983
|
});
|
|
14982
14984
|
}
|
|
14983
14985
|
const mergedOpts = {
|
|
14984
|
-
...
|
|
14986
|
+
...DEFAULT_CONFIRM_OPTS,
|
|
14985
14987
|
commitment,
|
|
14986
14988
|
preflightCommitment: commitment,
|
|
14987
14989
|
minContextSlot,
|
|
@@ -14994,7 +14996,7 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
14994
14996
|
blockhash
|
|
14995
14997
|
});
|
|
14996
14998
|
const unitsConsumed = isSimulatedTransactionResponse(simulationResult) ? [simulationResult.unitsConsumed] : simulationResult.map((tx) => tx.unitsConsumed ? Number(tx.unitsConsumed) : undefined);
|
|
14997
|
-
updatedTransactions = transactions.map((tx, idx) =>
|
|
14999
|
+
updatedTransactions = transactions.map((tx, idx) => addTransactionMetadata(tx, {
|
|
14998
15000
|
...tx,
|
|
14999
15001
|
unitsConsumed: unitsConsumed[idx]
|
|
15000
15002
|
}));
|
|
@@ -15007,8 +15009,8 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
15007
15009
|
console.log(`💸 Bundle tip: ${maxCapUi ? Math.min(processOpts.bundleTipUi ?? 0, maxCapUi) : processOpts.bundleTipUi} SOL`);
|
|
15008
15010
|
} else {
|
|
15009
15011
|
updatedTransactions.forEach((tx, idx) => {
|
|
15010
|
-
const cu = tx.unitsConsumed ? Math.min(tx.unitsConsumed + 5e4, 14e5) :
|
|
15011
|
-
const priorityFeeUi = maxCapUi ? Math.min(processOpts.priorityFeeMicro ?
|
|
15012
|
+
const cu = tx.unitsConsumed ? Math.min(tx.unitsConsumed + 5e4, 14e5) : getComputeBudgetUnits(tx);
|
|
15013
|
+
const priorityFeeUi = maxCapUi ? Math.min(processOpts.priorityFeeMicro ? microLamportsToUi(processOpts.priorityFeeMicro, cu) : 0, maxCapUi) : processOpts.priorityFeeMicro ? microLamportsToUi(processOpts.priorityFeeMicro, cu) : 0;
|
|
15012
15014
|
console.log(`💸 Priority fee for tx ${idx}: ${priorityFeeUi} SOL`);
|
|
15013
15015
|
});
|
|
15014
15016
|
}
|
|
@@ -15028,11 +15030,11 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
15028
15030
|
let base58Txs = [];
|
|
15029
15031
|
if (wallet.signAllTransactions) {
|
|
15030
15032
|
versionedTransactions = await wallet.signAllTransactions(versionedTransactions);
|
|
15031
|
-
base58Txs = versionedTransactions.map((signedTx) => bs58.
|
|
15033
|
+
base58Txs = versionedTransactions.map((signedTx) => bs58.encode(signedTx.serialize()));
|
|
15032
15034
|
} else {
|
|
15033
15035
|
for (let i = 0; i < versionedTransactions.length; i++) {
|
|
15034
15036
|
const signedTx = await wallet.signTransaction(versionedTransactions[i]);
|
|
15035
|
-
const base58Tx = bs58.
|
|
15037
|
+
const base58Tx = bs58.encode(signedTx.serialize());
|
|
15036
15038
|
base58Txs.push(base58Tx);
|
|
15037
15039
|
versionedTransactions[i] = signedTx;
|
|
15038
15040
|
}
|
|
@@ -15044,7 +15046,7 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
15044
15046
|
processOpts.callback?.(undefined, true);
|
|
15045
15047
|
}
|
|
15046
15048
|
let simulateTxs = null;
|
|
15047
|
-
if (!
|
|
15049
|
+
if (!SKIP_SIMULATION) {
|
|
15048
15050
|
simulateTxs = async () => await simulateTransactions(processOpts, connection, versionedTransactions, mergedOpts);
|
|
15049
15051
|
}
|
|
15050
15052
|
const sendTxBundleGrpc = async (throwError) => await sendTransactionAsGrpcBundle(connection, base58Txs, throwError);
|
|
@@ -15064,7 +15066,7 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
15064
15066
|
});
|
|
15065
15067
|
for (const [idx, method] of finalFallbackMethod.entries()) {
|
|
15066
15068
|
const isLast = idx === finalFallbackMethod.length - 1;
|
|
15067
|
-
if (idx === 0 && simulateTxs && !
|
|
15069
|
+
if (idx === 0 && simulateTxs && !SKIP_SIMULATION) {
|
|
15068
15070
|
await simulateTxs();
|
|
15069
15071
|
}
|
|
15070
15072
|
let temporaryBundleSignature;
|
|
@@ -15116,7 +15118,7 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
15116
15118
|
}
|
|
15117
15119
|
} catch (error) {
|
|
15118
15120
|
const failedTxs = transactions.splice(signatures.length);
|
|
15119
|
-
if (error instanceof
|
|
15121
|
+
if (error instanceof SolanaJSONRPCError) {
|
|
15120
15122
|
throw error;
|
|
15121
15123
|
}
|
|
15122
15124
|
if (error instanceof ProcessTransactionError) {
|
|
@@ -15126,12 +15128,12 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
15126
15128
|
throw new ProcessTransactionError({
|
|
15127
15129
|
message: error.message,
|
|
15128
15130
|
type: ProcessTransactionErrorType.TransactionSendingError,
|
|
15129
|
-
programId:
|
|
15131
|
+
programId: PROGRAM_ID.toBase58(),
|
|
15130
15132
|
failedTxs,
|
|
15131
15133
|
_error: error
|
|
15132
15134
|
});
|
|
15133
15135
|
}
|
|
15134
|
-
const parsedError = parseTransactionError(error, processOpts?.programId ??
|
|
15136
|
+
const parsedError = parseTransactionError(error, processOpts?.programId ?? PROGRAM_ID);
|
|
15135
15137
|
if (error?.logs?.length > 0) {
|
|
15136
15138
|
console.log("------ Logs 👇 ------");
|
|
15137
15139
|
console.log(error.logs.join("\n"));
|
|
@@ -15157,7 +15159,7 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
15157
15159
|
}
|
|
15158
15160
|
}
|
|
15159
15161
|
const simulateTransactions = async (processOpts, connection, solanaTransactions, confirmOpts, txOpts) => {
|
|
15160
|
-
const v0Txs = solanaTransactions.map((tx) =>
|
|
15162
|
+
const v0Txs = solanaTransactions.map((tx) => isV0Tx(tx) ? tx : legacyTxToV0Tx(tx, txOpts));
|
|
15161
15163
|
try {
|
|
15162
15164
|
if (v0Txs.length > 1) {
|
|
15163
15165
|
const response = await simulateBundle(processOpts?.bundleSimRpcEndpoint ?? connection.rpcEndpoint, v0Txs);
|
|
@@ -15171,7 +15173,7 @@ const simulateTransactions = async (processOpts, connection, solanaTransactions,
|
|
|
15171
15173
|
});
|
|
15172
15174
|
if (response.value.err) {
|
|
15173
15175
|
const error = response.value.err;
|
|
15174
|
-
const parsedError = parseTransactionError(error, processOpts?.programId ??
|
|
15176
|
+
const parsedError = parseTransactionError(error, processOpts?.programId ?? PROGRAM_ID);
|
|
15175
15177
|
throw new ProcessTransactionError({
|
|
15176
15178
|
message: parsedError.description ?? JSON.stringify(response.value.err),
|
|
15177
15179
|
type: ProcessTransactionErrorType.SimulationError,
|
|
@@ -15183,7 +15185,7 @@ const simulateTransactions = async (processOpts, connection, solanaTransactions,
|
|
|
15183
15185
|
}
|
|
15184
15186
|
} catch (error) {
|
|
15185
15187
|
if (error instanceof BundleSimulationError) {
|
|
15186
|
-
const parsedError = parseTransactionError(error, processOpts?.programId ??
|
|
15188
|
+
const parsedError = parseTransactionError(error, processOpts?.programId ?? PROGRAM_ID);
|
|
15187
15189
|
throw new ProcessTransactionError({
|
|
15188
15190
|
message: parsedError.description,
|
|
15189
15191
|
type: ProcessTransactionErrorType.SimulationError,
|
|
@@ -15245,12 +15247,12 @@ async function confirmTransaction(connection, signature, commitment = "confirmed
|
|
|
15245
15247
|
}
|
|
15246
15248
|
}
|
|
15247
15249
|
console.log("🔄 Waiting for confirmation...");
|
|
15248
|
-
await
|
|
15250
|
+
await sleep(2e3);
|
|
15249
15251
|
}
|
|
15250
15252
|
console.log("❌ Transaction failed to confirm in time.");
|
|
15251
15253
|
throw new Error("Transaction failed to confirm in time.");
|
|
15252
15254
|
};
|
|
15253
|
-
const result = await Promise.race([getStatus(),
|
|
15255
|
+
const result = await Promise.race([getStatus(), setTimeoutPromise(2e4, `Transaction failed to confirm in time.`)]);
|
|
15254
15256
|
if (result instanceof Error) {
|
|
15255
15257
|
throw result;
|
|
15256
15258
|
}
|
|
@@ -15337,14 +15339,14 @@ const MAX_TX_SIZE$1 = 1232;
|
|
|
15337
15339
|
const BUNDLE_TX_SIZE$1 = 81;
|
|
15338
15340
|
const PRIORITY_TX_SIZE$1 = 44;
|
|
15339
15341
|
function isFlashloan(tx) {
|
|
15340
|
-
if (
|
|
15342
|
+
if (isV0Tx(tx)) {
|
|
15341
15343
|
const addressLookupTableAccounts = tx.addressLookupTables ?? [];
|
|
15342
|
-
const message =
|
|
15344
|
+
const message = decompileV0Transaction(tx, addressLookupTableAccounts);
|
|
15343
15345
|
const idl = {
|
|
15344
15346
|
...LENDR_IDL,
|
|
15345
|
-
address: new
|
|
15347
|
+
address: new PublicKey(0)
|
|
15346
15348
|
};
|
|
15347
|
-
const decoded = message.instructions.map((ix) =>
|
|
15349
|
+
const decoded = message.instructions.map((ix) => decodeInstruction(idl, ix.data));
|
|
15348
15350
|
return decoded.some((ix) => ix?.name.toLowerCase().includes("flashloan"));
|
|
15349
15351
|
}
|
|
15350
15352
|
return false;
|
|
@@ -15373,25 +15375,25 @@ function formatTransactions(transactionsArg, broadcastType, blockhash, feeSettin
|
|
|
15373
15375
|
const { priorityFeeMicro, bundleTipUi, feePayer, maxCapUi } = feeSettings;
|
|
15374
15376
|
const flashloanIndex = getFlashloanIndex(transactionsArg);
|
|
15375
15377
|
transactionsArg.forEach((tx) => {
|
|
15376
|
-
if (!
|
|
15378
|
+
if (!isV0Tx(tx)) {
|
|
15377
15379
|
tx.recentBlockhash = blockhash;
|
|
15378
15380
|
tx.feePayer = feePayer;
|
|
15379
15381
|
}
|
|
15380
15382
|
});
|
|
15381
15383
|
const transactions = addTransactionTags ? addTransactionTxTags(transactionsArg) : transactionsArg;
|
|
15382
|
-
const txSizes = transactions.map((tx) =>
|
|
15384
|
+
const txSizes = transactions.map((tx) => getTxSize(tx));
|
|
15383
15385
|
const dummyPriorityFeeIx = makePriorityFeeMicroIx(1);
|
|
15384
15386
|
const priorityIxs = [];
|
|
15385
15387
|
const cuLimitIxs = [];
|
|
15386
15388
|
transactions.forEach((tx, idx) => {
|
|
15387
|
-
const cu = tx.unitsConsumed ? Math.min(tx.unitsConsumed + 5e4, 14e5) :
|
|
15388
|
-
const priorityFeeUi = maxCapUi ? Math.min(
|
|
15389
|
-
let updatedFees =
|
|
15389
|
+
const cu = tx.unitsConsumed ? Math.min(tx.unitsConsumed + 5e4, 14e5) : getComputeBudgetUnits(tx);
|
|
15390
|
+
const priorityFeeUi = maxCapUi ? Math.min(microLamportsToUi(priorityFeeMicro, cu), maxCapUi) : microLamportsToUi(priorityFeeMicro, cu);
|
|
15391
|
+
let updatedFees = uiToMicroLamports(priorityFeeUi, cu);
|
|
15390
15392
|
if (priorityFeeUi > .1) {
|
|
15391
|
-
updatedFees =
|
|
15393
|
+
updatedFees = uiToMicroLamports(.1, cu);
|
|
15392
15394
|
}
|
|
15393
15395
|
priorityIxs.push(broadcastType === "BUNDLE" ? dummyPriorityFeeIx : makePriorityFeeMicroIx(updatedFees));
|
|
15394
|
-
cuLimitIxs.push(cu ?
|
|
15396
|
+
cuLimitIxs.push(cu ? ComputeBudgetProgram.setComputeUnitLimit({ units: cu }) : undefined);
|
|
15395
15397
|
});
|
|
15396
15398
|
const { bundleTipIx } = makeTxPriorityIx(feePayer, maxCapUi ? Math.min(bundleTipUi, maxCapUi) : bundleTipUi, broadcastType);
|
|
15397
15399
|
let bundleTipIndex = broadcastType === "BUNDLE" ? -1 : null;
|
|
@@ -15409,12 +15411,12 @@ function formatTransactions(transactionsArg, broadcastType, blockhash, feeSettin
|
|
|
15409
15411
|
}
|
|
15410
15412
|
}
|
|
15411
15413
|
if (bundleTipIndex === -1 && bundleTipIx) {
|
|
15412
|
-
const bundleTipMessage = new
|
|
15414
|
+
const bundleTipMessage = new TransactionMessage({
|
|
15413
15415
|
instructions: [bundleTipIx],
|
|
15414
15416
|
payerKey: feePayer,
|
|
15415
15417
|
recentBlockhash: blockhash
|
|
15416
15418
|
});
|
|
15417
|
-
formattedTransactions.push(new
|
|
15419
|
+
formattedTransactions.push(new VersionedTransaction(bundleTipMessage.compileToV0Message()));
|
|
15418
15420
|
}
|
|
15419
15421
|
for (const [index, transaction] of transactions.entries()) {
|
|
15420
15422
|
const hasFlashloan = flashloanIndex !== null;
|
|
@@ -15427,15 +15429,15 @@ function formatTransactions(transactionsArg, broadcastType, blockhash, feeSettin
|
|
|
15427
15429
|
...cuLimitIxs[index] ? [cuLimitIxs[index]] : []
|
|
15428
15430
|
];
|
|
15429
15431
|
let newTransaction;
|
|
15430
|
-
if (
|
|
15431
|
-
newTransaction =
|
|
15432
|
+
if (isV0Tx(transaction)) {
|
|
15433
|
+
newTransaction = updateV0Tx(transaction, {
|
|
15432
15434
|
addressLookupTables,
|
|
15433
15435
|
additionalIxs: requiredIxs,
|
|
15434
15436
|
blockhash,
|
|
15435
15437
|
replaceOnly: isTxFlashloan
|
|
15436
15438
|
});
|
|
15437
15439
|
} else {
|
|
15438
|
-
newTransaction =
|
|
15440
|
+
newTransaction = legacyTxToV0Tx(transaction, {
|
|
15439
15441
|
addressLookupTables,
|
|
15440
15442
|
additionalIxs: requiredIxs,
|
|
15441
15443
|
blockhash,
|
|
@@ -15451,18 +15453,18 @@ function addTransactionTxTags(transactions) {
|
|
|
15451
15453
|
const txWithTags = [];
|
|
15452
15454
|
for (const [_, tx] of transactions.entries()) {
|
|
15453
15455
|
let solanaTx = tx;
|
|
15454
|
-
const arenaKey =
|
|
15456
|
+
const arenaKey = TransactionArenaKeyMap[tx.type];
|
|
15455
15457
|
if (arenaKey) {
|
|
15456
|
-
if (
|
|
15458
|
+
if (isV0Tx(solanaTx)) {
|
|
15457
15459
|
console.log("tx", solanaTx);
|
|
15458
15460
|
const addressLookupTableAccounts = solanaTx.addressLookupTables ?? [];
|
|
15459
|
-
const message =
|
|
15461
|
+
const message = decompileV0Transaction(solanaTx, addressLookupTableAccounts);
|
|
15460
15462
|
message.instructions[0].keys.push({
|
|
15461
15463
|
pubkey: arenaKey,
|
|
15462
15464
|
isSigner: false,
|
|
15463
15465
|
isWritable: false
|
|
15464
15466
|
});
|
|
15465
|
-
solanaTx =
|
|
15467
|
+
solanaTx = addTransactionMetadata(new VersionedTransaction(message.compileToV0Message(tx.addressLookupTables)), {
|
|
15466
15468
|
signers: solanaTx.signers,
|
|
15467
15469
|
addressLookupTables: solanaTx.addressLookupTables,
|
|
15468
15470
|
type: solanaTx.type,
|
|
@@ -15500,7 +15502,7 @@ const SinglePoolInstruction = {
|
|
|
15500
15502
|
const mint = findPoolMintAddress(pool);
|
|
15501
15503
|
const stakeAuthority = findPoolStakeAuthorityAddress(pool);
|
|
15502
15504
|
const mintAuthority = findPoolMintAuthorityAddress(pool);
|
|
15503
|
-
return createTransactionInstruction(
|
|
15505
|
+
return createTransactionInstruction(SINGLE_POOL_PROGRAM_ID, [
|
|
15504
15506
|
{
|
|
15505
15507
|
pubkey: voteAccount,
|
|
15506
15508
|
isSigner: false,
|
|
@@ -15532,37 +15534,37 @@ const SinglePoolInstruction = {
|
|
|
15532
15534
|
isWritable: false
|
|
15533
15535
|
},
|
|
15534
15536
|
{
|
|
15535
|
-
pubkey:
|
|
15537
|
+
pubkey: SYSVAR_RENT_ID,
|
|
15536
15538
|
isSigner: false,
|
|
15537
15539
|
isWritable: false
|
|
15538
15540
|
},
|
|
15539
15541
|
{
|
|
15540
|
-
pubkey:
|
|
15542
|
+
pubkey: SYSVAR_CLOCK_ID,
|
|
15541
15543
|
isSigner: false,
|
|
15542
15544
|
isWritable: false
|
|
15543
15545
|
},
|
|
15544
15546
|
{
|
|
15545
|
-
pubkey:
|
|
15547
|
+
pubkey: SYSVAR_STAKE_HISTORY_ID,
|
|
15546
15548
|
isSigner: false,
|
|
15547
15549
|
isWritable: false
|
|
15548
15550
|
},
|
|
15549
15551
|
{
|
|
15550
|
-
pubkey:
|
|
15552
|
+
pubkey: STAKE_CONFIG_ID$1,
|
|
15551
15553
|
isSigner: false,
|
|
15552
15554
|
isWritable: false
|
|
15553
15555
|
},
|
|
15554
15556
|
{
|
|
15555
|
-
pubkey:
|
|
15557
|
+
pubkey: SYSTEM_PROGRAM_ID,
|
|
15556
15558
|
isSigner: false,
|
|
15557
15559
|
isWritable: false
|
|
15558
15560
|
},
|
|
15559
15561
|
{
|
|
15560
|
-
pubkey:
|
|
15562
|
+
pubkey: TOKEN_PROGRAM_ID,
|
|
15561
15563
|
isSigner: false,
|
|
15562
15564
|
isWritable: false
|
|
15563
15565
|
},
|
|
15564
15566
|
{
|
|
15565
|
-
pubkey:
|
|
15567
|
+
pubkey: STAKE_PROGRAM_ID,
|
|
15566
15568
|
isSigner: false,
|
|
15567
15569
|
isWritable: false
|
|
15568
15570
|
}
|
|
@@ -15571,7 +15573,7 @@ const SinglePoolInstruction = {
|
|
|
15571
15573
|
initializeOnRamp: (pool) => {
|
|
15572
15574
|
const onRamp = findPoolOnRampAddress(pool);
|
|
15573
15575
|
const stakeAuthority = findPoolStakeAuthorityAddress(pool);
|
|
15574
|
-
return createTransactionInstruction(
|
|
15576
|
+
return createTransactionInstruction(SINGLE_POOL_PROGRAM_ID, [
|
|
15575
15577
|
{
|
|
15576
15578
|
pubkey: pool,
|
|
15577
15579
|
isSigner: false,
|
|
@@ -15588,17 +15590,17 @@ const SinglePoolInstruction = {
|
|
|
15588
15590
|
isWritable: false
|
|
15589
15591
|
},
|
|
15590
15592
|
{
|
|
15591
|
-
pubkey:
|
|
15593
|
+
pubkey: SYSVAR_RENT_ID,
|
|
15592
15594
|
isSigner: false,
|
|
15593
15595
|
isWritable: false
|
|
15594
15596
|
},
|
|
15595
15597
|
{
|
|
15596
|
-
pubkey:
|
|
15598
|
+
pubkey: SYSTEM_PROGRAM_ID,
|
|
15597
15599
|
isSigner: false,
|
|
15598
15600
|
isWritable: false
|
|
15599
15601
|
},
|
|
15600
15602
|
{
|
|
15601
|
-
pubkey:
|
|
15603
|
+
pubkey: STAKE_PROGRAM_ID,
|
|
15602
15604
|
isSigner: false,
|
|
15603
15605
|
isWritable: false
|
|
15604
15606
|
}
|
|
@@ -15609,7 +15611,7 @@ const SinglePoolInstruction = {
|
|
|
15609
15611
|
const mint = findPoolMintAddress(pool);
|
|
15610
15612
|
const stakeAuthority = findPoolStakeAuthorityAddress(pool);
|
|
15611
15613
|
const mintAuthority = findPoolMintAuthorityAddress(pool);
|
|
15612
|
-
return createTransactionInstruction(
|
|
15614
|
+
return createTransactionInstruction(SINGLE_POOL_PROGRAM_ID, [
|
|
15613
15615
|
{
|
|
15614
15616
|
pubkey: pool,
|
|
15615
15617
|
isSigner: false,
|
|
@@ -15651,22 +15653,22 @@ const SinglePoolInstruction = {
|
|
|
15651
15653
|
isWritable: true
|
|
15652
15654
|
},
|
|
15653
15655
|
{
|
|
15654
|
-
pubkey:
|
|
15656
|
+
pubkey: SYSVAR_CLOCK_ID,
|
|
15655
15657
|
isSigner: false,
|
|
15656
15658
|
isWritable: false
|
|
15657
15659
|
},
|
|
15658
15660
|
{
|
|
15659
|
-
pubkey:
|
|
15661
|
+
pubkey: SYSVAR_STAKE_HISTORY_ID,
|
|
15660
15662
|
isSigner: false,
|
|
15661
15663
|
isWritable: false
|
|
15662
15664
|
},
|
|
15663
15665
|
{
|
|
15664
|
-
pubkey:
|
|
15666
|
+
pubkey: TOKEN_PROGRAM_ID,
|
|
15665
15667
|
isSigner: false,
|
|
15666
15668
|
isWritable: false
|
|
15667
15669
|
},
|
|
15668
15670
|
{
|
|
15669
|
-
pubkey:
|
|
15671
|
+
pubkey: STAKE_PROGRAM_ID,
|
|
15670
15672
|
isSigner: false,
|
|
15671
15673
|
isWritable: false
|
|
15672
15674
|
}
|
|
@@ -15681,9 +15683,9 @@ const SinglePoolInstruction = {
|
|
|
15681
15683
|
const data = Buffer.concat([
|
|
15682
15684
|
Buffer.from([SinglePoolInstructionType.WithdrawStake]),
|
|
15683
15685
|
userStakeAuthority.toBuffer(),
|
|
15684
|
-
Buffer.from(new
|
|
15686
|
+
Buffer.from(new BN(rawAmount.toString()).toArray("le", 8))
|
|
15685
15687
|
]);
|
|
15686
|
-
return createTransactionInstruction(
|
|
15688
|
+
return createTransactionInstruction(SINGLE_POOL_PROGRAM_ID, [
|
|
15687
15689
|
{
|
|
15688
15690
|
pubkey: pool,
|
|
15689
15691
|
isSigner: false,
|
|
@@ -15720,17 +15722,17 @@ const SinglePoolInstruction = {
|
|
|
15720
15722
|
isWritable: true
|
|
15721
15723
|
},
|
|
15722
15724
|
{
|
|
15723
|
-
pubkey:
|
|
15725
|
+
pubkey: SYSVAR_CLOCK_ID,
|
|
15724
15726
|
isSigner: false,
|
|
15725
15727
|
isWritable: false
|
|
15726
15728
|
},
|
|
15727
15729
|
{
|
|
15728
|
-
pubkey:
|
|
15730
|
+
pubkey: TOKEN_PROGRAM_ID,
|
|
15729
15731
|
isSigner: false,
|
|
15730
15732
|
isWritable: false
|
|
15731
15733
|
},
|
|
15732
15734
|
{
|
|
15733
|
-
pubkey:
|
|
15735
|
+
pubkey: STAKE_PROGRAM_ID,
|
|
15734
15736
|
isSigner: false,
|
|
15735
15737
|
isWritable: false
|
|
15736
15738
|
}
|
|
@@ -15743,7 +15745,7 @@ const SinglePoolInstruction = {
|
|
|
15743
15745
|
findPoolMplAuthorityAddress(pool),
|
|
15744
15746
|
findMplMetadataAddress(mint)
|
|
15745
15747
|
]);
|
|
15746
|
-
return createTransactionInstruction(
|
|
15748
|
+
return createTransactionInstruction(SINGLE_POOL_PROGRAM_ID, [
|
|
15747
15749
|
{
|
|
15748
15750
|
pubkey: pool,
|
|
15749
15751
|
isSigner: false,
|
|
@@ -15775,12 +15777,12 @@ const SinglePoolInstruction = {
|
|
|
15775
15777
|
isWritable: true
|
|
15776
15778
|
},
|
|
15777
15779
|
{
|
|
15778
|
-
pubkey:
|
|
15780
|
+
pubkey: MPL_METADATA_PROGRAM_ID,
|
|
15779
15781
|
isSigner: false,
|
|
15780
15782
|
isWritable: false
|
|
15781
15783
|
},
|
|
15782
15784
|
{
|
|
15783
|
-
pubkey:
|
|
15785
|
+
pubkey: SYSTEM_PROGRAM_ID,
|
|
15784
15786
|
isSigner: false,
|
|
15785
15787
|
isWritable: false
|
|
15786
15788
|
}
|
|
@@ -15808,7 +15810,7 @@ const SinglePoolInstruction = {
|
|
|
15808
15810
|
Buffer.from(new Uint32Array([tokenUri.length]).buffer),
|
|
15809
15811
|
Buffer.from(tokenUri)
|
|
15810
15812
|
]);
|
|
15811
|
-
return createTransactionInstruction(
|
|
15813
|
+
return createTransactionInstruction(SINGLE_POOL_PROGRAM_ID, [
|
|
15812
15814
|
{
|
|
15813
15815
|
pubkey: voteAccount,
|
|
15814
15816
|
isSigner: false,
|
|
@@ -15835,7 +15837,7 @@ const SinglePoolInstruction = {
|
|
|
15835
15837
|
isWritable: true
|
|
15836
15838
|
},
|
|
15837
15839
|
{
|
|
15838
|
-
pubkey:
|
|
15840
|
+
pubkey: MPL_METADATA_PROGRAM_ID,
|
|
15839
15841
|
isSigner: false,
|
|
15840
15842
|
isWritable: false
|
|
15841
15843
|
}
|
|
@@ -15849,8 +15851,8 @@ const createTransactionInstruction = (programId, keys, data) => {
|
|
|
15849
15851
|
data
|
|
15850
15852
|
};
|
|
15851
15853
|
};
|
|
15852
|
-
const findPda = (baseAddress, prefix, programId =
|
|
15853
|
-
const [pda] =
|
|
15854
|
+
const findPda = (baseAddress, prefix, programId = SINGLE_POOL_PROGRAM_ID) => {
|
|
15855
|
+
const [pda] = PublicKey.findProgramAddressSync([Buffer.from(prefix), baseAddress.toBuffer()], programId);
|
|
15854
15856
|
return pda;
|
|
15855
15857
|
};
|
|
15856
15858
|
const findPoolMintAddressByVoteAccount = (voteAccountAddress) => findPda(findPoolAddress(voteAccountAddress), "mint");
|
|
@@ -15862,11 +15864,11 @@ const findPoolMintAuthorityAddress = (poolAddress) => findPda(poolAddress, "mint
|
|
|
15862
15864
|
const findPoolMplAuthorityAddress = (poolAddress) => findPda(poolAddress, "mpl_authority");
|
|
15863
15865
|
const findPoolOnRampAddress = (poolAddress) => findPda(poolAddress, "onramp");
|
|
15864
15866
|
const findMplMetadataAddress = async (poolMintAddress) => {
|
|
15865
|
-
const [pda] =
|
|
15867
|
+
const [pda] = PublicKey.findProgramAddressSync([
|
|
15866
15868
|
Buffer.from("metadata"),
|
|
15867
|
-
|
|
15869
|
+
MPL_METADATA_PROGRAM_ID.toBuffer(),
|
|
15868
15870
|
poolMintAddress.toBuffer()
|
|
15869
|
-
],
|
|
15871
|
+
], MPL_METADATA_PROGRAM_ID);
|
|
15870
15872
|
return pda;
|
|
15871
15873
|
};
|
|
15872
15874
|
const SINGLE_POOL_ACCOUNT_SIZE = BigInt(33);
|
|
@@ -15874,7 +15876,7 @@ const STAKE_ACCOUNT_SIZE = BigInt(200);
|
|
|
15874
15876
|
const MINT_SIZE = BigInt(82);
|
|
15875
15877
|
async function initializeStakedPoolTx(connection, payer, voteAccountAddress) {
|
|
15876
15878
|
const instructions$3 = await initializeStakedPoolIxs(connection, payer, voteAccountAddress);
|
|
15877
|
-
const tx = new
|
|
15879
|
+
const tx = new Transaction().add(...instructions$3);
|
|
15878
15880
|
return tx;
|
|
15879
15881
|
}
|
|
15880
15882
|
async function initializeStakedPoolIxs(connection, payer, voteAccountAddress) {
|
|
@@ -15890,22 +15892,22 @@ async function initializeStakedPoolIxs(connection, payer, voteAccountAddress) {
|
|
|
15890
15892
|
]);
|
|
15891
15893
|
const minimumDelegation = minimumDelegationObj.value;
|
|
15892
15894
|
const instructions$3 = [];
|
|
15893
|
-
instructions$3.push(
|
|
15895
|
+
instructions$3.push(SystemProgram.transfer({
|
|
15894
15896
|
fromPubkey: payer,
|
|
15895
15897
|
toPubkey: poolAddress,
|
|
15896
15898
|
lamports: poolRent
|
|
15897
15899
|
}));
|
|
15898
|
-
instructions$3.push(
|
|
15900
|
+
instructions$3.push(SystemProgram.transfer({
|
|
15899
15901
|
fromPubkey: payer,
|
|
15900
15902
|
toPubkey: stakeAddress,
|
|
15901
|
-
lamports: stakeRent + minimumDelegation +
|
|
15903
|
+
lamports: stakeRent + minimumDelegation + LAMPORTS_PER_SOL * 1
|
|
15902
15904
|
}));
|
|
15903
|
-
instructions$3.push(
|
|
15905
|
+
instructions$3.push(SystemProgram.transfer({
|
|
15904
15906
|
fromPubkey: payer,
|
|
15905
15907
|
toPubkey: onRampAddress,
|
|
15906
15908
|
lamports: stakeRent
|
|
15907
15909
|
}));
|
|
15908
|
-
instructions$3.push(
|
|
15910
|
+
instructions$3.push(SystemProgram.transfer({
|
|
15909
15911
|
fromPubkey: payer,
|
|
15910
15912
|
toPubkey: mintAddress,
|
|
15911
15913
|
lamports: mintRent
|
|
@@ -15918,8 +15920,8 @@ async function initializeStakedPoolIxs(connection, payer, voteAccountAddress) {
|
|
|
15918
15920
|
const createAccountIx = (from, newAccount, lamports, space, programAddress) => {
|
|
15919
15921
|
const data = Buffer.concat([
|
|
15920
15922
|
Buffer.from([0]),
|
|
15921
|
-
Buffer.from(new
|
|
15922
|
-
Buffer.from(new
|
|
15923
|
+
Buffer.from(new BN(lamports).toArray("le", 8)),
|
|
15924
|
+
Buffer.from(new BN(space).toArray("le", 8)),
|
|
15923
15925
|
programAddress.toBuffer()
|
|
15924
15926
|
]);
|
|
15925
15927
|
const accounts$2 = [{
|
|
@@ -15931,7 +15933,7 @@ const createAccountIx = (from, newAccount, lamports, space, programAddress) => {
|
|
|
15931
15933
|
isSigner: true,
|
|
15932
15934
|
isWritable: true
|
|
15933
15935
|
}];
|
|
15934
|
-
return createTransactionInstruction(
|
|
15936
|
+
return createTransactionInstruction(SYSTEM_PROGRAM_ID, accounts$2, data);
|
|
15935
15937
|
};
|
|
15936
15938
|
const createPoolOnrampIx = (voteAccount) => {
|
|
15937
15939
|
const poolAccount = findPoolAddress(voteAccount);
|
|
@@ -15954,25 +15956,25 @@ const createPoolOnrampIx = (voteAccount) => {
|
|
|
15954
15956
|
isWritable: false
|
|
15955
15957
|
},
|
|
15956
15958
|
{
|
|
15957
|
-
pubkey:
|
|
15959
|
+
pubkey: SYSVAR_RENT_PUBKEY,
|
|
15958
15960
|
isSigner: false,
|
|
15959
15961
|
isWritable: false
|
|
15960
15962
|
},
|
|
15961
15963
|
{
|
|
15962
|
-
pubkey:
|
|
15964
|
+
pubkey: SystemProgram.programId,
|
|
15963
15965
|
isSigner: false,
|
|
15964
15966
|
isWritable: false
|
|
15965
15967
|
},
|
|
15966
15968
|
{
|
|
15967
|
-
pubkey:
|
|
15969
|
+
pubkey: StakeProgram.programId,
|
|
15968
15970
|
isSigner: false,
|
|
15969
15971
|
isWritable: false
|
|
15970
15972
|
}
|
|
15971
15973
|
];
|
|
15972
15974
|
const data = Buffer.from(Uint8Array.of(6));
|
|
15973
|
-
return new
|
|
15975
|
+
return new TransactionInstruction({
|
|
15974
15976
|
keys,
|
|
15975
|
-
programId:
|
|
15977
|
+
programId: SINGLE_POOL_PROGRAM_ID,
|
|
15976
15978
|
data
|
|
15977
15979
|
});
|
|
15978
15980
|
};
|
|
@@ -16008,28 +16010,28 @@ const replenishPoolIx = (voteAccount) => {
|
|
|
16008
16010
|
isWritable: false
|
|
16009
16011
|
},
|
|
16010
16012
|
{
|
|
16011
|
-
pubkey:
|
|
16013
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
16012
16014
|
isSigner: false,
|
|
16013
16015
|
isWritable: false
|
|
16014
16016
|
},
|
|
16015
16017
|
{
|
|
16016
|
-
pubkey:
|
|
16018
|
+
pubkey: SYSVAR_STAKE_HISTORY_ID,
|
|
16017
16019
|
isSigner: false,
|
|
16018
16020
|
isWritable: false
|
|
16019
16021
|
},
|
|
16020
16022
|
{
|
|
16021
|
-
pubkey:
|
|
16023
|
+
pubkey: STAKE_CONFIG_ID$1,
|
|
16022
16024
|
isSigner: false,
|
|
16023
16025
|
isWritable: false
|
|
16024
16026
|
},
|
|
16025
16027
|
{
|
|
16026
|
-
pubkey:
|
|
16028
|
+
pubkey: StakeProgram.programId,
|
|
16027
16029
|
isSigner: false,
|
|
16028
16030
|
isWritable: false
|
|
16029
16031
|
}
|
|
16030
16032
|
];
|
|
16031
16033
|
const data = Buffer.from(Uint8Array.of(1));
|
|
16032
|
-
return createTransactionInstruction(
|
|
16034
|
+
return createTransactionInstruction(SINGLE_POOL_PROGRAM_ID, keys, data);
|
|
16033
16035
|
};
|
|
16034
16036
|
|
|
16035
16037
|
//#endregion
|
|
@@ -16042,13 +16044,13 @@ function computeFreeCollateral(lendrAccount, opts) {
|
|
|
16042
16044
|
const _clamped = opts?.clamped ?? true;
|
|
16043
16045
|
const { assets, liabilities } = computeHealthComponents(lendrAccount, LendrRequirementType.Initial);
|
|
16044
16046
|
const signedFreeCollateral = assets.minus(liabilities);
|
|
16045
|
-
return _clamped ?
|
|
16047
|
+
return _clamped ? BigNumber.max(0, signedFreeCollateral) : signedFreeCollateral;
|
|
16046
16048
|
}
|
|
16047
16049
|
function computeFreeCollateralLegacy(activeBalances, banks, oraclePrices, opts) {
|
|
16048
16050
|
const _clamped = opts?.clamped ?? true;
|
|
16049
16051
|
const { assets, liabilities } = computeHealthComponentsLegacy(activeBalances, banks, oraclePrices, LendrRequirementType.Initial, []);
|
|
16050
16052
|
const signedFreeCollateral = assets.minus(liabilities);
|
|
16051
|
-
return _clamped ?
|
|
16053
|
+
return _clamped ? BigNumber.max(0, signedFreeCollateral) : signedFreeCollateral;
|
|
16052
16054
|
}
|
|
16053
16055
|
function computeHealthComponents(lendrAccount, lendrReqType) {
|
|
16054
16056
|
switch (lendrReqType) {
|
|
@@ -16071,19 +16073,19 @@ function computeHealthComponentsLegacy(activeBalances, banks, oraclePrices, lend
|
|
|
16071
16073
|
const [assets, liabilities] = filteredBalances.map((accountBalance) => {
|
|
16072
16074
|
const bank = banks.get(accountBalance.bankPk.toBase58());
|
|
16073
16075
|
if (!bank) {
|
|
16074
|
-
console.warn(`Bank ${
|
|
16075
|
-
return [new
|
|
16076
|
+
console.warn(`Bank ${shortenAddress(accountBalance.bankPk)} not found, excluding from health computation`);
|
|
16077
|
+
return [new BigNumber(0), new BigNumber(0)];
|
|
16076
16078
|
}
|
|
16077
16079
|
const priceInfo = oraclePrices.get(accountBalance.bankPk.toBase58());
|
|
16078
16080
|
if (!priceInfo) {
|
|
16079
|
-
console.warn(`Price info for bank ${
|
|
16080
|
-
return [new
|
|
16081
|
+
console.warn(`Price info for bank ${shortenAddress(accountBalance.bankPk)} not found, excluding from health computation`);
|
|
16082
|
+
return [new BigNumber(0), new BigNumber(0)];
|
|
16081
16083
|
}
|
|
16082
16084
|
const { assets: assets$1, liabilities: liabilities$1 } = getBalanceUsdValueWithPriceBias(accountBalance, bank, priceInfo, lendrReqType);
|
|
16083
16085
|
return [assets$1, liabilities$1];
|
|
16084
16086
|
}).reduce(([asset, liability], [d, l]) => {
|
|
16085
16087
|
return [asset.plus(d), liability.plus(l)];
|
|
16086
|
-
}, [new
|
|
16088
|
+
}, [new BigNumber(0), new BigNumber(0)]);
|
|
16087
16089
|
return {
|
|
16088
16090
|
assets,
|
|
16089
16091
|
liabilities
|
|
@@ -16093,19 +16095,19 @@ function computeHealthComponentsWithoutBiasLegacy(activeBalances, banks, oracleP
|
|
|
16093
16095
|
const [assets, liabilities] = activeBalances.map((accountBalance) => {
|
|
16094
16096
|
const bank = banks.get(accountBalance.bankPk.toBase58());
|
|
16095
16097
|
if (!bank) {
|
|
16096
|
-
console.warn(`Bank ${
|
|
16097
|
-
return [new
|
|
16098
|
+
console.warn(`Bank ${shortenAddress(accountBalance.bankPk)} not found, excluding from health computation`);
|
|
16099
|
+
return [new BigNumber(0), new BigNumber(0)];
|
|
16098
16100
|
}
|
|
16099
16101
|
const priceInfo = oraclePrices.get(accountBalance.bankPk.toBase58());
|
|
16100
16102
|
if (!priceInfo) {
|
|
16101
|
-
console.warn(`Price info for bank ${
|
|
16102
|
-
return [new
|
|
16103
|
+
console.warn(`Price info for bank ${shortenAddress(accountBalance.bankPk)} not found, excluding from health computation`);
|
|
16104
|
+
return [new BigNumber(0), new BigNumber(0)];
|
|
16103
16105
|
}
|
|
16104
16106
|
const { assets: assets$1, liabilities: liabilities$1 } = computeBalanceUsdValue(accountBalance, bank, priceInfo, lendrReqType);
|
|
16105
16107
|
return [assets$1, liabilities$1];
|
|
16106
16108
|
}).reduce(([asset, liability], [d, l]) => {
|
|
16107
16109
|
return [asset.plus(d), liability.plus(l)];
|
|
16108
|
-
}, [new
|
|
16110
|
+
}, [new BigNumber(0), new BigNumber(0)]);
|
|
16109
16111
|
return {
|
|
16110
16112
|
assets,
|
|
16111
16113
|
liabilities
|
|
@@ -16121,17 +16123,17 @@ function computeNetApy(lendrAccount, activeBalances, banks, oraclePrices) {
|
|
|
16121
16123
|
const apr = activeBalances.reduce((weightedApr, balance) => {
|
|
16122
16124
|
const bank = banks.get(balance.bankPk.toBase58());
|
|
16123
16125
|
if (!bank) {
|
|
16124
|
-
console.warn(`Bank ${
|
|
16126
|
+
console.warn(`Bank ${shortenAddress(balance.bankPk)} not found, excluding from APY computation`);
|
|
16125
16127
|
return weightedApr;
|
|
16126
16128
|
}
|
|
16127
16129
|
const priceInfo = oraclePrices.get(balance.bankPk.toBase58());
|
|
16128
16130
|
if (!priceInfo) {
|
|
16129
|
-
console.warn(`Price info for bank ${
|
|
16131
|
+
console.warn(`Price info for bank ${shortenAddress(balance.bankPk)} not found, excluding from APY computation`);
|
|
16130
16132
|
return weightedApr;
|
|
16131
16133
|
}
|
|
16132
16134
|
return weightedApr.minus(computeInterestRates(bank).borrowingRate.times(computeBalanceUsdValue(balance, bank, priceInfo, LendrRequirementType.Equity).liabilities).div(totalUsdValue.isEqualTo(0) ? 1 : totalUsdValue)).plus(computeInterestRates(bank).lendingRate.times(computeBalanceUsdValue(balance, bank, priceInfo, LendrRequirementType.Equity).assets).div(totalUsdValue.isEqualTo(0) ? 1 : totalUsdValue));
|
|
16133
|
-
}, new
|
|
16134
|
-
return
|
|
16135
|
+
}, new BigNumber(0)).toNumber();
|
|
16136
|
+
return aprToApy(apr);
|
|
16135
16137
|
}
|
|
16136
16138
|
/**
|
|
16137
16139
|
* Lendr Balance Computes
|
|
@@ -16162,8 +16164,8 @@ function computeQuantity(balance, bank) {
|
|
|
16162
16164
|
};
|
|
16163
16165
|
}
|
|
16164
16166
|
function computeQuantityUi(balance, bank) {
|
|
16165
|
-
const assetsQuantity = new
|
|
16166
|
-
const liabilitiesQuantity = new
|
|
16167
|
+
const assetsQuantity = new BigNumber(nativeToUi(getAssetQuantity(bank, balance.assetShares), bank.mintDecimals));
|
|
16168
|
+
const liabilitiesQuantity = new BigNumber(nativeToUi(getLiabilityQuantity(bank, balance.liabilityShares), bank.mintDecimals));
|
|
16167
16169
|
return {
|
|
16168
16170
|
assets: assetsQuantity,
|
|
16169
16171
|
liabilities: liabilitiesQuantity
|
|
@@ -16181,13 +16183,13 @@ function computeClaimedEmissions(balance, bank, currentTimestamp) {
|
|
|
16181
16183
|
}
|
|
16182
16184
|
if (balanceAmount) {
|
|
16183
16185
|
const lastUpdate = balance.lastUpdate;
|
|
16184
|
-
const period = new
|
|
16185
|
-
const emissionsRate = new
|
|
16186
|
+
const period = new BigNumber(currentTimestamp - lastUpdate);
|
|
16187
|
+
const emissionsRate = new BigNumber(bank.emissionsRate);
|
|
16186
16188
|
const emissions = period.times(balanceAmount).times(emissionsRate).div(31536e3 * 10 ** bank.mintDecimals);
|
|
16187
|
-
const emissionsReal =
|
|
16189
|
+
const emissionsReal = BigNumber.min(emissions, new BigNumber(bank.emissionsRemaining));
|
|
16188
16190
|
return emissionsReal;
|
|
16189
16191
|
}
|
|
16190
|
-
return new
|
|
16192
|
+
return new BigNumber(0);
|
|
16191
16193
|
}
|
|
16192
16194
|
function computeTotalOutstandingEmissions(balance, bank) {
|
|
16193
16195
|
const claimedEmissions = balance.emissionsOutstanding;
|
|
@@ -16225,7 +16227,7 @@ function computeHealthCheckAccounts(balances, banks, mandatoryBanks = [], exclud
|
|
|
16225
16227
|
return projectedActiveBanks;
|
|
16226
16228
|
}
|
|
16227
16229
|
function computeHealthAccountMetas(banksToInclude, bankMetadataMap, enableSorting = true, bankExtendedMetadata) {
|
|
16228
|
-
const wrapperFn = enableSorting ?
|
|
16230
|
+
const wrapperFn = enableSorting ? composeRemainingAccounts : (banksAndOracles) => banksAndOracles.flat();
|
|
16229
16231
|
const accounts$2 = wrapperFn(banksToInclude.map((bank) => {
|
|
16230
16232
|
const keys = [bank.address, bank.oracleKey];
|
|
16231
16233
|
if (bank.config.assetTag === 2) {
|
|
@@ -16237,7 +16239,7 @@ function computeHealthAccountMetas(banksToInclude, bankMetadataMap, enableSortin
|
|
|
16237
16239
|
if (!validatorVoteAccount) {
|
|
16238
16240
|
throw Error(`no validatorVoteAccount on Bank metadata: ${bank.address.toBase58()}`);
|
|
16239
16241
|
}
|
|
16240
|
-
const pool = findPoolAddress(new
|
|
16242
|
+
const pool = findPoolAddress(new PublicKey(validatorVoteAccount));
|
|
16241
16243
|
const solPool = findPoolStakeAddress(pool);
|
|
16242
16244
|
const lstMint = findPoolMintAddress(pool);
|
|
16243
16245
|
keys.push(lstMint, solPool);
|
|
@@ -16266,7 +16268,7 @@ var Balance = class Balance {
|
|
|
16266
16268
|
return new Balance(balance.active, balance.bankPk, balance.assetShares, balance.liabilityShares, balance.emissionsOutstanding, balance.lastUpdate);
|
|
16267
16269
|
}
|
|
16268
16270
|
static createEmpty(bankPk) {
|
|
16269
|
-
return new Balance(false, bankPk, new
|
|
16271
|
+
return new Balance(false, bankPk, new BigNumber(0), new BigNumber(0), new BigNumber(0), 0);
|
|
16270
16272
|
}
|
|
16271
16273
|
computeUsdValue(bank, oraclePrice, lendrRequirementType = LendrRequirementType.Equity) {
|
|
16272
16274
|
return computeBalanceUsdValue(this, bank, oraclePrice, lendrRequirementType);
|
|
@@ -16350,15 +16352,15 @@ let AccountFlags = /* @__PURE__ */ function(AccountFlags$1) {
|
|
|
16350
16352
|
//#endregion
|
|
16351
16353
|
//#region src/services/account/utils/deserialize.utils.ts
|
|
16352
16354
|
function decodeAccountRaw(encoded, idl) {
|
|
16353
|
-
const coder = new
|
|
16355
|
+
const coder = new BorshCoder(idl);
|
|
16354
16356
|
return coder.accounts.decode(AccountType.LendrAccount, encoded);
|
|
16355
16357
|
}
|
|
16356
16358
|
function parseBalanceRaw(balanceRaw) {
|
|
16357
16359
|
const active = typeof balanceRaw.active === "number" ? balanceRaw.active === 1 : balanceRaw.active;
|
|
16358
16360
|
const bankPk = balanceRaw.bankPk;
|
|
16359
|
-
const assetShares =
|
|
16360
|
-
const liabilityShares =
|
|
16361
|
-
const emissionsOutstanding =
|
|
16361
|
+
const assetShares = wrappedI80F48toBigNumber(balanceRaw.assetShares);
|
|
16362
|
+
const liabilityShares = wrappedI80F48toBigNumber(balanceRaw.liabilityShares);
|
|
16363
|
+
const emissionsOutstanding = wrappedI80F48toBigNumber(balanceRaw.emissionsOutstanding);
|
|
16362
16364
|
const lastUpdate = balanceRaw.lastUpdate.toNumber();
|
|
16363
16365
|
return {
|
|
16364
16366
|
active,
|
|
@@ -16404,7 +16406,7 @@ function getActiveAccountFlags(flags) {
|
|
|
16404
16406
|
* Check if an account flag is set
|
|
16405
16407
|
*/
|
|
16406
16408
|
function hasAccountFlag(flags, flag) {
|
|
16407
|
-
return !flags.and(new
|
|
16409
|
+
return !flags.and(new BN$1(flag)).isZero();
|
|
16408
16410
|
}
|
|
16409
16411
|
/**
|
|
16410
16412
|
* Convert on-chain health cache flags (BN) to an array of HealthCacheFlags enum values
|
|
@@ -16454,34 +16456,34 @@ function getHealthCacheStatusDescription(flags) {
|
|
|
16454
16456
|
}
|
|
16455
16457
|
function dtoToLendrAccount(lendrAccountDto) {
|
|
16456
16458
|
return {
|
|
16457
|
-
address: new
|
|
16458
|
-
group: new
|
|
16459
|
-
authority: new
|
|
16459
|
+
address: new PublicKey(lendrAccountDto.address),
|
|
16460
|
+
group: new PublicKey(lendrAccountDto.group),
|
|
16461
|
+
authority: new PublicKey(lendrAccountDto.authority),
|
|
16460
16462
|
balances: lendrAccountDto.balances.map(dtoToBalance),
|
|
16461
16463
|
accountFlags: lendrAccountDto.accountFlags,
|
|
16462
|
-
emissionsDestinationAccount: new
|
|
16464
|
+
emissionsDestinationAccount: new PublicKey(lendrAccountDto.emissionsDestinationAccount),
|
|
16463
16465
|
healthCache: dtoToHealthCache(lendrAccountDto.healthCache)
|
|
16464
16466
|
};
|
|
16465
16467
|
}
|
|
16466
16468
|
function dtoToBalance(balanceDto) {
|
|
16467
16469
|
return {
|
|
16468
16470
|
active: balanceDto.active,
|
|
16469
|
-
bankPk: new
|
|
16470
|
-
assetShares: new
|
|
16471
|
-
liabilityShares: new
|
|
16472
|
-
emissionsOutstanding: new
|
|
16471
|
+
bankPk: new PublicKey(balanceDto.bankPk),
|
|
16472
|
+
assetShares: new BigNumber(balanceDto.assetShares),
|
|
16473
|
+
liabilityShares: new BigNumber(balanceDto.liabilityShares),
|
|
16474
|
+
emissionsOutstanding: new BigNumber(balanceDto.emissionsOutstanding),
|
|
16473
16475
|
lastUpdate: balanceDto.lastUpdate
|
|
16474
16476
|
};
|
|
16475
16477
|
}
|
|
16476
16478
|
function dtoToHealthCache(healthCacheDto) {
|
|
16477
16479
|
return {
|
|
16478
|
-
assetValue: new
|
|
16479
|
-
liabilityValue: new
|
|
16480
|
-
assetValueMaint: new
|
|
16481
|
-
liabilityValueMaint: new
|
|
16482
|
-
assetValueEquity: new
|
|
16483
|
-
liabilityValueEquity: new
|
|
16484
|
-
timestamp: new
|
|
16480
|
+
assetValue: new BigNumber(healthCacheDto.assetValue),
|
|
16481
|
+
liabilityValue: new BigNumber(healthCacheDto.liabilityValue),
|
|
16482
|
+
assetValueMaint: new BigNumber(healthCacheDto.assetValueMaint),
|
|
16483
|
+
liabilityValueMaint: new BigNumber(healthCacheDto.liabilityValueMaint),
|
|
16484
|
+
assetValueEquity: new BigNumber(healthCacheDto.assetValueEquity),
|
|
16485
|
+
liabilityValueEquity: new BigNumber(healthCacheDto.liabilityValueEquity),
|
|
16486
|
+
timestamp: new BigNumber(healthCacheDto.timestamp),
|
|
16485
16487
|
flags: healthCacheDto.flags,
|
|
16486
16488
|
prices: healthCacheDto.prices,
|
|
16487
16489
|
simulationFailed: healthCacheDto.simulationFailed
|
|
@@ -16668,7 +16670,7 @@ const fetchLendrAccountData = async (program, lendrAccountPk, bankMap, oraclePri
|
|
|
16668
16670
|
* Convert numeric flag to BN for Solana compatibility
|
|
16669
16671
|
*/
|
|
16670
16672
|
function accountFlagToBN(flag) {
|
|
16671
|
-
return new
|
|
16673
|
+
return new BN$1(flag);
|
|
16672
16674
|
}
|
|
16673
16675
|
function lendrAccountToDto(lendrAccount) {
|
|
16674
16676
|
return {
|
|
@@ -16737,14 +16739,14 @@ async function simulateAccountHealthCacheWithFallback(props) {
|
|
|
16737
16739
|
balances: props.balances,
|
|
16738
16740
|
bankMetadataMap: props.bankMetadataMap
|
|
16739
16741
|
});
|
|
16740
|
-
simulatedAccount.healthCache.assetValueEquity =
|
|
16741
|
-
simulatedAccount.healthCache.liabilityValueEquity =
|
|
16742
|
+
simulatedAccount.healthCache.assetValueEquity = bigNumberToWrappedI80F48(assetValueEquity);
|
|
16743
|
+
simulatedAccount.healthCache.liabilityValueEquity = bigNumberToWrappedI80F48(liabilityValueEquity);
|
|
16742
16744
|
lendrAccount = LendrAccount.fromAccountParsed(props.lendrAccount.address, simulatedAccount);
|
|
16743
16745
|
} catch (e) {
|
|
16744
16746
|
console.log("e", e);
|
|
16745
16747
|
const { assets: assetValueMaint, liabilities: liabilityValueMaint } = computeHealthComponentsLegacy(activeBalances, props.bankMap, props.oraclePrices, LendrRequirementType.Maintenance);
|
|
16746
16748
|
const { assets: assetValueInitial, liabilities: liabilityValueInitial } = computeHealthComponentsLegacy(activeBalances, props.bankMap, props.oraclePrices, LendrRequirementType.Initial);
|
|
16747
|
-
lendrAccount.setHealthCache(new HealthCache(assetValueInitial, liabilityValueInitial, assetValueMaint, liabilityValueMaint, assetValueEquity, liabilityValueEquity, new
|
|
16749
|
+
lendrAccount.setHealthCache(new HealthCache(assetValueInitial, liabilityValueInitial, assetValueMaint, liabilityValueMaint, assetValueEquity, liabilityValueEquity, new BigNumber(0), [], [], true));
|
|
16748
16750
|
if (e instanceof HealthCacheSimulationError) {
|
|
16749
16751
|
return {
|
|
16750
16752
|
lendrAccount,
|
|
@@ -16758,10 +16760,10 @@ async function simulateAccountHealthCache(props) {
|
|
|
16758
16760
|
const { program, bankMap, oraclePrices, lendrAccountPk, balances, bankMetadataMap } = props;
|
|
16759
16761
|
const activeBalances = balances.filter((b) => b.active);
|
|
16760
16762
|
const { stalePythFeeds, staleSwbOracles } = getActiveStaleBanks(activeBalances, bankMap, [], oraclePrices, 30);
|
|
16761
|
-
const computeIx =
|
|
16763
|
+
const computeIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 14e5 });
|
|
16762
16764
|
const blockhash = (await program.provider.connection.getLatestBlockhash("confirmed")).blockhash;
|
|
16763
|
-
const fundAccountIx =
|
|
16764
|
-
fromPubkey: new
|
|
16765
|
+
const fundAccountIx = SystemProgram.transfer({
|
|
16766
|
+
fromPubkey: new PublicKey("DD3AeAssFvjqTvRTrRAtpfjkBF8FpVKnFuwnMLN9haXD"),
|
|
16765
16767
|
toPubkey: program.provider.publicKey,
|
|
16766
16768
|
lamports: 1e8
|
|
16767
16769
|
});
|
|
@@ -16782,7 +16784,7 @@ async function simulateAccountHealthCache(props) {
|
|
|
16782
16784
|
const pythLut = crankPythIxs.lut ? [crankPythIxs.lut] : [];
|
|
16783
16785
|
const txs = [];
|
|
16784
16786
|
if (crankPythIxs.postInstructions.length > 0) {
|
|
16785
|
-
txs.push(...
|
|
16787
|
+
txs.push(...splitInstructionsToFitTransactions([computeIx], [
|
|
16786
16788
|
fundAccountIx,
|
|
16787
16789
|
...crankPythIxs.postInstructions.map((ix) => ix.instruction),
|
|
16788
16790
|
...crankPythIxs.closeInstructions.map((ix) => ix.instruction)
|
|
@@ -16792,19 +16794,19 @@ async function simulateAccountHealthCache(props) {
|
|
|
16792
16794
|
luts: [...crankSwbIxs.luts, ...pythLut]
|
|
16793
16795
|
}));
|
|
16794
16796
|
}
|
|
16795
|
-
const messageV0 = new
|
|
16797
|
+
const messageV0 = new TransactionMessage({
|
|
16796
16798
|
payerKey: program.provider.publicKey,
|
|
16797
16799
|
recentBlockhash: blockhash,
|
|
16798
16800
|
instructions: [...crankSwbIxs.instructions]
|
|
16799
16801
|
}).compileToV0Message([...crankSwbIxs.luts]);
|
|
16800
|
-
const swbTx = new
|
|
16802
|
+
const swbTx = new VersionedTransaction(messageV0);
|
|
16801
16803
|
txs.push(swbTx);
|
|
16802
|
-
const healthTx = new
|
|
16804
|
+
const healthTx = new TransactionMessage({
|
|
16803
16805
|
payerKey: program.provider.publicKey,
|
|
16804
16806
|
recentBlockhash: blockhash,
|
|
16805
16807
|
instructions: [...healthPulseIxs.instructions]
|
|
16806
16808
|
}).compileToV0Message([]);
|
|
16807
|
-
const healthTxV0 = new
|
|
16809
|
+
const healthTxV0 = new VersionedTransaction(healthTx);
|
|
16808
16810
|
txs.push(healthTxV0);
|
|
16809
16811
|
if (txs.length > 5) {
|
|
16810
16812
|
console.error("Too many transactions", txs.length);
|
|
@@ -16821,12 +16823,12 @@ async function simulateAccountHealthCache(props) {
|
|
|
16821
16823
|
console.log("LendrAccountPost healthCache internalErr", lendrAccountPost.healthCache.internalErr);
|
|
16822
16824
|
console.log("LendrAccountPost healthCache lndrErr", lendrAccountPost.healthCache.lendrErr);
|
|
16823
16825
|
if (lendrAccountPost.healthCache.lendrErr === 6009) {
|
|
16824
|
-
const assetValue = !
|
|
16825
|
-
const liabilityValue = !
|
|
16826
|
-
const assetValueEquity = !
|
|
16827
|
-
const liabilityValueEquity = !
|
|
16828
|
-
const assetValueMaint = !
|
|
16829
|
-
const liabilityValueMaint = !
|
|
16826
|
+
const assetValue = !wrappedI80F48toBigNumber(lendrAccountPost.healthCache.assetValue).isZero();
|
|
16827
|
+
const liabilityValue = !wrappedI80F48toBigNumber(lendrAccountPost.healthCache.liabilityValue).isZero();
|
|
16828
|
+
const assetValueEquity = !wrappedI80F48toBigNumber(lendrAccountPost.healthCache.assetValueEquity).isZero();
|
|
16829
|
+
const liabilityValueEquity = !wrappedI80F48toBigNumber(lendrAccountPost.healthCache.liabilityValueEquity).isZero();
|
|
16830
|
+
const assetValueMaint = !wrappedI80F48toBigNumber(lendrAccountPost.healthCache.assetValueMaint).isZero();
|
|
16831
|
+
const liabilityValueMaint = !wrappedI80F48toBigNumber(lendrAccountPost.healthCache.liabilityValueMaint).isZero();
|
|
16830
16832
|
if (assetValue && liabilityValue && assetValueEquity && liabilityValueEquity && assetValueMaint && liabilityValueMaint) {
|
|
16831
16833
|
return lendrAccountPost;
|
|
16832
16834
|
}
|
|
@@ -16862,15 +16864,15 @@ async function createUpdateFeedIx(props) {
|
|
|
16862
16864
|
*/
|
|
16863
16865
|
async function createLendrAccountTx(props) {
|
|
16864
16866
|
const authority = props.lendrAccount?.authority ?? props.lendrClient.provider.publicKey;
|
|
16865
|
-
const lendrAccountKeypair =
|
|
16866
|
-
const dummyWrappedI80F48 =
|
|
16867
|
+
const lendrAccountKeypair = Keypair.generate();
|
|
16868
|
+
const dummyWrappedI80F48 = bigNumberToWrappedI80F48(new BigNumber(0));
|
|
16867
16869
|
const dummyBalances = Array(15).fill({
|
|
16868
16870
|
active: false,
|
|
16869
|
-
bankPk: new
|
|
16871
|
+
bankPk: new PublicKey("11111111111111111111111111111111"),
|
|
16870
16872
|
assetShares: dummyWrappedI80F48,
|
|
16871
16873
|
liabilityShares: dummyWrappedI80F48,
|
|
16872
16874
|
emissionsOutstanding: dummyWrappedI80F48,
|
|
16873
|
-
lastUpdate: new
|
|
16875
|
+
lastUpdate: new BN$1(0)
|
|
16874
16876
|
});
|
|
16875
16877
|
const rawAccount = {
|
|
16876
16878
|
group: props.lendrClient.group.address,
|
|
@@ -16913,21 +16915,21 @@ async function createLendrAccountTx(props) {
|
|
|
16913
16915
|
0,
|
|
16914
16916
|
0
|
|
16915
16917
|
] },
|
|
16916
|
-
timestamp: new
|
|
16918
|
+
timestamp: new BN$1(0),
|
|
16917
16919
|
flags: 0,
|
|
16918
16920
|
prices: [],
|
|
16919
|
-
assetValueMaint:
|
|
16920
|
-
liabilityValueMaint:
|
|
16921
|
-
assetValueEquity:
|
|
16922
|
-
liabilityValueEquity:
|
|
16921
|
+
assetValueMaint: bigNumberToWrappedI80F48(new BigNumber(0)),
|
|
16922
|
+
liabilityValueMaint: bigNumberToWrappedI80F48(new BigNumber(0)),
|
|
16923
|
+
assetValueEquity: bigNumberToWrappedI80F48(new BigNumber(0)),
|
|
16924
|
+
liabilityValueEquity: bigNumberToWrappedI80F48(new BigNumber(0)),
|
|
16923
16925
|
errIndex: 0,
|
|
16924
16926
|
internalErr: 0,
|
|
16925
16927
|
internalBankruptcyErr: 0,
|
|
16926
16928
|
internalLiqErr: 0,
|
|
16927
16929
|
lendrErr: 0
|
|
16928
16930
|
},
|
|
16929
|
-
emissionsDestinationAccount: new
|
|
16930
|
-
accountFlags: new
|
|
16931
|
+
emissionsDestinationAccount: new PublicKey("11111111111111111111111111111111"),
|
|
16932
|
+
accountFlags: new BN$1([
|
|
16931
16933
|
0,
|
|
16932
16934
|
0,
|
|
16933
16935
|
0
|
|
@@ -16995,28 +16997,28 @@ function getActiveStaleBanks(balances, banks, additionalBanks, oraclePrices, max
|
|
|
16995
16997
|
//#endregion
|
|
16996
16998
|
//#region src/services/group/group.service.ts
|
|
16997
16999
|
async function makeEnableFlashLoanForAccountIx(program, lendrAccountAddress) {
|
|
16998
|
-
const ix = await instructions_default.makeSetAccountFlagIx(program, { lendrAccount: lendrAccountAddress }, { flag: new
|
|
17000
|
+
const ix = await instructions_default.makeSetAccountFlagIx(program, { lendrAccount: lendrAccountAddress }, { flag: new BN$1(FLASHLOAN_ENABLED_FLAG) });
|
|
16999
17001
|
return {
|
|
17000
17002
|
instructions: [ix],
|
|
17001
17003
|
keys: []
|
|
17002
17004
|
};
|
|
17003
17005
|
}
|
|
17004
17006
|
async function makeDisableFlashLoanForAccountIx(program, lendrAccountAddress) {
|
|
17005
|
-
const ix = await instructions_default.makeUnsetAccountFlagIx(program, { lendrAccount: lendrAccountAddress }, { flag: new
|
|
17007
|
+
const ix = await instructions_default.makeUnsetAccountFlagIx(program, { lendrAccount: lendrAccountAddress }, { flag: new BN$1(FLASHLOAN_ENABLED_FLAG) });
|
|
17006
17008
|
return {
|
|
17007
17009
|
instructions: [ix],
|
|
17008
17010
|
keys: []
|
|
17009
17011
|
};
|
|
17010
17012
|
}
|
|
17011
17013
|
async function makeEnableAccountTransferForAccountIx(program, lendrAccountAddress) {
|
|
17012
|
-
const ix = await instructions_default.makeSetAccountFlagIx(program, { lendrAccount: lendrAccountAddress }, { flag: new
|
|
17014
|
+
const ix = await instructions_default.makeSetAccountFlagIx(program, { lendrAccount: lendrAccountAddress }, { flag: new BN$1(TRANSFER_ACCOUNT_AUTHORITY_FLAG) });
|
|
17013
17015
|
return {
|
|
17014
17016
|
instructions: [ix],
|
|
17015
17017
|
keys: []
|
|
17016
17018
|
};
|
|
17017
17019
|
}
|
|
17018
17020
|
async function makeDisableAccountTransferForAccountIx(program, lendrAccountAddress) {
|
|
17019
|
-
const ix = await instructions_default.makeUnsetAccountFlagIx(program, { lendrAccount: lendrAccountAddress }, { flag: new
|
|
17021
|
+
const ix = await instructions_default.makeUnsetAccountFlagIx(program, { lendrAccount: lendrAccountAddress }, { flag: new BN$1(TRANSFER_ACCOUNT_AUTHORITY_FLAG) });
|
|
17020
17022
|
return {
|
|
17021
17023
|
instructions: [ix],
|
|
17022
17024
|
keys: []
|
|
@@ -17030,7 +17032,7 @@ async function makePoolConfigureBankIx(program, bank, args) {
|
|
|
17030
17032
|
};
|
|
17031
17033
|
}
|
|
17032
17034
|
async function makeAddPermissionlessStakedBankIx(program, group, voteAccountAddress, feePayer, pythOracle) {
|
|
17033
|
-
const [settingsKey] =
|
|
17035
|
+
const [settingsKey] = PublicKey.findProgramAddressSync([Buffer.from("staked_settings", "utf-8"), group.toBuffer()], program.programId);
|
|
17034
17036
|
const poolAddress = findPoolAddress(voteAccountAddress);
|
|
17035
17037
|
const solPool = findPoolStakeAddress(poolAddress);
|
|
17036
17038
|
const lstMint = findPoolMintAddress(poolAddress);
|
|
@@ -17052,25 +17054,25 @@ async function makeAddPermissionlessStakedBankIx(program, group, voteAccountAddr
|
|
|
17052
17054
|
isWritable: false
|
|
17053
17055
|
},
|
|
17054
17056
|
{
|
|
17055
|
-
pubkey:
|
|
17057
|
+
pubkey: SYSVAR_RENT_PUBKEY,
|
|
17056
17058
|
isSigner: false,
|
|
17057
17059
|
isWritable: false
|
|
17058
17060
|
},
|
|
17059
17061
|
{
|
|
17060
|
-
pubkey:
|
|
17062
|
+
pubkey: SystemProgram.programId,
|
|
17061
17063
|
isSigner: false,
|
|
17062
17064
|
isWritable: false
|
|
17063
17065
|
},
|
|
17064
17066
|
{
|
|
17065
|
-
pubkey:
|
|
17067
|
+
pubkey: StakeProgram.programId,
|
|
17066
17068
|
isSigner: false,
|
|
17067
17069
|
isWritable: false
|
|
17068
17070
|
}
|
|
17069
17071
|
];
|
|
17070
17072
|
const data = Buffer.from(Uint8Array.of(6));
|
|
17071
|
-
const onrampIx = new
|
|
17073
|
+
const onrampIx = new TransactionInstruction({
|
|
17072
17074
|
keys,
|
|
17073
|
-
programId:
|
|
17075
|
+
programId: SINGLE_POOL_PROGRAM_ID,
|
|
17074
17076
|
data
|
|
17075
17077
|
});
|
|
17076
17078
|
const remainingKeys = [
|
|
@@ -17088,13 +17090,13 @@ async function makeAddPermissionlessStakedBankIx(program, group, voteAccountAddr
|
|
|
17088
17090
|
pubkey: key,
|
|
17089
17091
|
isSigner: false,
|
|
17090
17092
|
isWritable: false
|
|
17091
|
-
})), { seed: new
|
|
17093
|
+
})), { seed: new BN$1(0) });
|
|
17092
17094
|
return {
|
|
17093
17095
|
instructions: [ix],
|
|
17094
17096
|
keys: []
|
|
17095
17097
|
};
|
|
17096
17098
|
}
|
|
17097
|
-
async function makePoolAddBankIx(program, group, bank, feePayer, bankMint, bankConfig, tokenProgram =
|
|
17099
|
+
async function makePoolAddBankIx(program, group, bank, feePayer, bankMint, bankConfig, tokenProgram = TOKEN_PROGRAM_ID, overrideOpt = {}) {
|
|
17098
17100
|
const rawBankConfig = serializeBankConfigOpt(bankConfig);
|
|
17099
17101
|
const rawBankConfigCompact = {
|
|
17100
17102
|
...rawBankConfig,
|
|
@@ -17120,8 +17122,8 @@ async function makePoolAddBankIx(program, group, bank, feePayer, bankMint, bankC
|
|
|
17120
17122
|
//#region src/services/group/utils/deserialize.utils.ts
|
|
17121
17123
|
function dtoToGroup(groupDto) {
|
|
17122
17124
|
return {
|
|
17123
|
-
admin: new
|
|
17124
|
-
address: new
|
|
17125
|
+
admin: new PublicKey(groupDto.admin),
|
|
17126
|
+
address: new PublicKey(groupDto.address)
|
|
17125
17127
|
};
|
|
17126
17128
|
}
|
|
17127
17129
|
|
|
@@ -17138,16 +17140,16 @@ function groupToDto(group) {
|
|
|
17138
17140
|
//#region src/services/native-stake/utils/deserialize.utils.ts
|
|
17139
17141
|
function dtoToValidatorStakeGroup(validatorStakeGroupDto) {
|
|
17140
17142
|
return {
|
|
17141
|
-
validator: new
|
|
17142
|
-
poolKey: new
|
|
17143
|
-
poolMintKey: new
|
|
17143
|
+
validator: new PublicKey(validatorStakeGroupDto.validator),
|
|
17144
|
+
poolKey: new PublicKey(validatorStakeGroupDto.poolKey),
|
|
17145
|
+
poolMintKey: new PublicKey(validatorStakeGroupDto.poolMintKey),
|
|
17144
17146
|
totalStake: validatorStakeGroupDto.totalStake,
|
|
17145
17147
|
selectedAccount: {
|
|
17146
|
-
pubkey: new
|
|
17148
|
+
pubkey: new PublicKey(validatorStakeGroupDto.selectedAccount.pubkey),
|
|
17147
17149
|
amount: validatorStakeGroupDto.selectedAccount.amount
|
|
17148
17150
|
},
|
|
17149
17151
|
accounts: validatorStakeGroupDto.accounts.map((account) => ({
|
|
17150
|
-
pubkey: new
|
|
17152
|
+
pubkey: new PublicKey(account.pubkey),
|
|
17151
17153
|
amount: account.amount
|
|
17152
17154
|
}))
|
|
17153
17155
|
};
|
|
@@ -17171,7 +17173,7 @@ const fetchNativeStakeAccounts = async (connection, publicKey, opts = { filterIn
|
|
|
17171
17173
|
}
|
|
17172
17174
|
try {
|
|
17173
17175
|
const epochInfo = await connection.getEpochInfo();
|
|
17174
|
-
const accounts$2 = await connection.getParsedProgramAccounts(
|
|
17176
|
+
const accounts$2 = await connection.getParsedProgramAccounts(StakeProgram.programId, { filters: [{ memcmp: {
|
|
17175
17177
|
offset: 12,
|
|
17176
17178
|
bytes: publicKey.toBase58()
|
|
17177
17179
|
} }] });
|
|
@@ -17179,12 +17181,12 @@ const fetchNativeStakeAccounts = async (connection, publicKey, opts = { filterIn
|
|
|
17179
17181
|
await Promise.all(accounts$2.map(async (acc) => {
|
|
17180
17182
|
const parsedAccount = acc.account.data;
|
|
17181
17183
|
const stakeInfo = parsedAccount.parsed.info;
|
|
17182
|
-
if (!stakeInfo.stake?.delegation || opts.filterInactive && (Number(stakeInfo.stake.delegation.activationEpoch) >= epochInfo.epoch || stakeInfo.stake.delegation.deactivationEpoch !==
|
|
17184
|
+
if (!stakeInfo.stake?.delegation || opts.filterInactive && (Number(stakeInfo.stake.delegation.activationEpoch) >= epochInfo.epoch || stakeInfo.stake.delegation.deactivationEpoch !== MAX_U64)) {
|
|
17183
17185
|
return;
|
|
17184
17186
|
}
|
|
17185
17187
|
const validatorAddress = stakeInfo.stake.delegation.voter;
|
|
17186
17188
|
const accountPubkey = acc.pubkey;
|
|
17187
|
-
const amount = Number(stakeInfo.stake.delegation.stake) /
|
|
17189
|
+
const amount = Number(stakeInfo.stake.delegation.stake) / LAMPORTS_PER_SOL;
|
|
17188
17190
|
const existingAccounts = validatorMap.get(validatorAddress) || [];
|
|
17189
17191
|
validatorMap.set(validatorAddress, [...existingAccounts, {
|
|
17190
17192
|
pubkey: accountPubkey,
|
|
@@ -17192,7 +17194,7 @@ const fetchNativeStakeAccounts = async (connection, publicKey, opts = { filterIn
|
|
|
17192
17194
|
}]);
|
|
17193
17195
|
}));
|
|
17194
17196
|
return Promise.all(Array.from(validatorMap.entries()).map(async ([validatorAddress, accounts$3]) => {
|
|
17195
|
-
const poolKey = findPoolAddress(new
|
|
17197
|
+
const poolKey = findPoolAddress(new PublicKey(validatorAddress));
|
|
17196
17198
|
const poolMintKey = findPoolMintAddress(poolKey);
|
|
17197
17199
|
const totalStake = accounts$3.reduce((acc, curr) => acc + curr.amount, 0);
|
|
17198
17200
|
const largestAccount = accounts$3.reduce((acc, curr) => acc.amount > curr.amount ? acc : curr);
|
|
@@ -17201,7 +17203,7 @@ const fetchNativeStakeAccounts = async (connection, publicKey, opts = { filterIn
|
|
|
17201
17203
|
sortedAccounts.unshift(sortedAccounts.splice(sortedAccounts.indexOf(largestAccount), 1)[0]);
|
|
17202
17204
|
}
|
|
17203
17205
|
return {
|
|
17204
|
-
validator: new
|
|
17206
|
+
validator: new PublicKey(validatorAddress),
|
|
17205
17207
|
poolKey,
|
|
17206
17208
|
poolMintKey,
|
|
17207
17209
|
accounts: sortedAccounts,
|
|
@@ -17234,7 +17236,7 @@ const fetchStakePoolActiveStates = async (connection, validatorVoteAccounts) =>
|
|
|
17234
17236
|
poolStakeAddressRecord[poolStakeAddress.toBase58()] = validatorVoteAccount;
|
|
17235
17237
|
});
|
|
17236
17238
|
const poolStakeAddressKeys = Object.keys(poolStakeAddressRecord);
|
|
17237
|
-
const poolStakeAccounts = Object.fromEntries((await
|
|
17239
|
+
const poolStakeAccounts = Object.fromEntries((await chunkedGetRawMultipleAccountInfoOrdered(connection, poolStakeAddressKeys)).map((ai, index) => [poolStakeAddressRecord[poolStakeAddressKeys[index]], ai?.data || null]));
|
|
17238
17240
|
validatorVoteAccounts.map((validatorVoteAccount) => {
|
|
17239
17241
|
const stakeAccount = fetchStakeAccount(poolStakeAccounts[validatorVoteAccount.toBase58()]);
|
|
17240
17242
|
const poolMintAddress = poolMintAddressRecord[validatorVoteAccount.toBase58()];
|
|
@@ -17264,17 +17266,17 @@ const fetchStakeAccount = (data) => {
|
|
|
17264
17266
|
offset += 4;
|
|
17265
17267
|
const rentExemptReserve = data.readBigUInt64LE(offset);
|
|
17266
17268
|
offset += 8;
|
|
17267
|
-
const staker = new
|
|
17269
|
+
const staker = new PublicKey(data.subarray(offset, offset + 32));
|
|
17268
17270
|
offset += 32;
|
|
17269
|
-
const withdrawer = new
|
|
17271
|
+
const withdrawer = new PublicKey(data.subarray(offset, offset + 32));
|
|
17270
17272
|
offset += 32;
|
|
17271
17273
|
const unixTimestamp = data.readBigUInt64LE(offset);
|
|
17272
17274
|
offset += 8;
|
|
17273
17275
|
const epoch = data.readBigUInt64LE(offset);
|
|
17274
17276
|
offset += 8;
|
|
17275
|
-
const custodian = new
|
|
17277
|
+
const custodian = new PublicKey(data.subarray(offset, offset + 32));
|
|
17276
17278
|
offset += 32;
|
|
17277
|
-
const voterPubkey = new
|
|
17279
|
+
const voterPubkey = new PublicKey(data.subarray(offset, offset + 32));
|
|
17278
17280
|
offset += 32;
|
|
17279
17281
|
const stake = data.readBigUInt64LE(offset);
|
|
17280
17282
|
offset += 8;
|
|
@@ -17324,7 +17326,7 @@ const fetchStakePoolMev = async (connection, validatorVoteAccounts) => {
|
|
|
17324
17326
|
const poolStakeAddresses = validatorVoteAccounts.map((validatorVoteAccount) => poolStakeAddressRecord[validatorVoteAccount.toBase58()]);
|
|
17325
17327
|
const onRampAddresses = validatorVoteAccounts.map((validatorVoteAccount) => onRampAddressRecord[validatorVoteAccount.toBase58()]);
|
|
17326
17328
|
const allAddresses = [...poolStakeAddresses, ...onRampAddresses].map((address$2) => address$2.toBase58());
|
|
17327
|
-
return
|
|
17329
|
+
return chunkedGetRawMultipleAccountInfoOrdered(connection, allAddresses).then((accountInfos) => {
|
|
17328
17330
|
const poolStakeInfos = accountInfos.slice(0, poolStakeAddresses.length);
|
|
17329
17331
|
const onRampInfos = accountInfos.slice(poolStakeAddresses.length);
|
|
17330
17332
|
const rent = 2282280;
|
|
@@ -17386,8 +17388,8 @@ var EmodeSettings = class EmodeSettings {
|
|
|
17386
17388
|
return {
|
|
17387
17389
|
collateralBankEmodeTag: parseEmodeTag(entry.collateralBankEmodeTag),
|
|
17388
17390
|
flags: getActiveEmodeEntryFlags(entry.flags),
|
|
17389
|
-
assetWeightInit:
|
|
17390
|
-
assetWeightMaint:
|
|
17391
|
+
assetWeightInit: wrappedI80F48toBigNumber(entry.assetWeightInit),
|
|
17392
|
+
assetWeightMaint: wrappedI80F48toBigNumber(entry.assetWeightMaint)
|
|
17391
17393
|
};
|
|
17392
17394
|
});
|
|
17393
17395
|
return new EmodeSettings(emodeTag, timestamp, flags, emodeEntries);
|
|
@@ -17397,7 +17399,7 @@ var EmodeSettings = class EmodeSettings {
|
|
|
17397
17399
|
//#endregion
|
|
17398
17400
|
//#region src/services/bank/utils/deserialize.utils.ts
|
|
17399
17401
|
function decodeBankRaw(encoded, idl) {
|
|
17400
|
-
const coder = new
|
|
17402
|
+
const coder = new BorshCoder(idl);
|
|
17401
17403
|
return coder.accounts.decode(AccountType.Bank, encoded);
|
|
17402
17404
|
}
|
|
17403
17405
|
function parseBankRaw(address$2, accountParsed, feedIdMap, bankMetadata) {
|
|
@@ -17405,28 +17407,28 @@ function parseBankRaw(address$2, accountParsed, feedIdMap, bankMetadata) {
|
|
|
17405
17407
|
const mint = accountParsed.mint;
|
|
17406
17408
|
const mintDecimals = accountParsed.mintDecimals;
|
|
17407
17409
|
const group = accountParsed.group;
|
|
17408
|
-
const assetShareValue =
|
|
17409
|
-
const liabilityShareValue =
|
|
17410
|
+
const assetShareValue = wrappedI80F48toBigNumber(accountParsed.assetShareValue);
|
|
17411
|
+
const liabilityShareValue = wrappedI80F48toBigNumber(accountParsed.liabilityShareValue);
|
|
17410
17412
|
const liquidityVault = accountParsed.liquidityVault;
|
|
17411
17413
|
const liquidityVaultBump = accountParsed.liquidityVaultBump;
|
|
17412
17414
|
const liquidityVaultAuthorityBump = accountParsed.liquidityVaultAuthorityBump;
|
|
17413
17415
|
const insuranceVault = accountParsed.insuranceVault;
|
|
17414
17416
|
const insuranceVaultBump = accountParsed.insuranceVaultBump;
|
|
17415
17417
|
const insuranceVaultAuthorityBump = accountParsed.insuranceVaultAuthorityBump;
|
|
17416
|
-
const collectedInsuranceFeesOutstanding =
|
|
17418
|
+
const collectedInsuranceFeesOutstanding = wrappedI80F48toBigNumber(accountParsed.collectedInsuranceFeesOutstanding);
|
|
17417
17419
|
const feeVault = accountParsed.feeVault;
|
|
17418
17420
|
const feeVaultBump = accountParsed.feeVaultBump;
|
|
17419
17421
|
const feeVaultAuthorityBump = accountParsed.feeVaultAuthorityBump;
|
|
17420
|
-
const collectedGroupFeesOutstanding =
|
|
17422
|
+
const collectedGroupFeesOutstanding = wrappedI80F48toBigNumber(accountParsed.collectedGroupFeesOutstanding);
|
|
17421
17423
|
const config = parseBankConfigRaw(accountParsed.config);
|
|
17422
17424
|
const lastUpdate = accountParsed.lastUpdate.toNumber();
|
|
17423
|
-
const totalAssetShares =
|
|
17424
|
-
const totalLiabilityShares =
|
|
17425
|
+
const totalAssetShares = wrappedI80F48toBigNumber(accountParsed.totalAssetShares);
|
|
17426
|
+
const totalLiabilityShares = wrappedI80F48toBigNumber(accountParsed.totalLiabilityShares);
|
|
17425
17427
|
const emissionsActiveBorrowing = (flags & 1) > 0;
|
|
17426
17428
|
const emissionsActiveLending = (flags & 2) > 0;
|
|
17427
17429
|
const emissionsRate = accountParsed.emissionsRate.toNumber();
|
|
17428
17430
|
const emissionsMint = accountParsed.emissionsMint;
|
|
17429
|
-
const emissionsRemaining = accountParsed.emissionsRemaining ?
|
|
17431
|
+
const emissionsRemaining = accountParsed.emissionsRemaining ? wrappedI80F48toBigNumber(accountParsed.emissionsRemaining) : new BigNumber(0);
|
|
17430
17432
|
const { oracleKey, shardId: pythShardId } = feedIdMap ? findOracleKey(config, feedIdMap) : { oracleKey: config.oracleKeys[0] };
|
|
17431
17433
|
const emode = EmodeSettings.from(accountParsed.emode);
|
|
17432
17434
|
const tokenSymbol = bankMetadata?.tokenSymbol;
|
|
@@ -17465,33 +17467,33 @@ function parseBankRaw(address$2, accountParsed, feedIdMap, bankMetadata) {
|
|
|
17465
17467
|
}
|
|
17466
17468
|
function dtoToBank(bankDto) {
|
|
17467
17469
|
return {
|
|
17468
|
-
address: new
|
|
17469
|
-
group: new
|
|
17470
|
-
mint: new
|
|
17470
|
+
address: new PublicKey(bankDto.address),
|
|
17471
|
+
group: new PublicKey(bankDto.group),
|
|
17472
|
+
mint: new PublicKey(bankDto.mint),
|
|
17471
17473
|
mintDecimals: bankDto.mintDecimals,
|
|
17472
|
-
assetShareValue: new
|
|
17473
|
-
liabilityShareValue: new
|
|
17474
|
-
liquidityVault: new
|
|
17474
|
+
assetShareValue: new BigNumber(bankDto.assetShareValue),
|
|
17475
|
+
liabilityShareValue: new BigNumber(bankDto.liabilityShareValue),
|
|
17476
|
+
liquidityVault: new PublicKey(bankDto.liquidityVault),
|
|
17475
17477
|
liquidityVaultBump: bankDto.liquidityVaultBump,
|
|
17476
17478
|
liquidityVaultAuthorityBump: bankDto.liquidityVaultAuthorityBump,
|
|
17477
|
-
insuranceVault: new
|
|
17479
|
+
insuranceVault: new PublicKey(bankDto.insuranceVault),
|
|
17478
17480
|
insuranceVaultBump: bankDto.insuranceVaultBump,
|
|
17479
17481
|
insuranceVaultAuthorityBump: bankDto.insuranceVaultAuthorityBump,
|
|
17480
|
-
collectedInsuranceFeesOutstanding: new
|
|
17481
|
-
feeVault: new
|
|
17482
|
+
collectedInsuranceFeesOutstanding: new BigNumber(bankDto.collectedInsuranceFeesOutstanding),
|
|
17483
|
+
feeVault: new PublicKey(bankDto.feeVault),
|
|
17482
17484
|
feeVaultBump: bankDto.feeVaultBump,
|
|
17483
17485
|
feeVaultAuthorityBump: bankDto.feeVaultAuthorityBump,
|
|
17484
|
-
collectedGroupFeesOutstanding: new
|
|
17486
|
+
collectedGroupFeesOutstanding: new BigNumber(bankDto.collectedGroupFeesOutstanding),
|
|
17485
17487
|
lastUpdate: bankDto.lastUpdate,
|
|
17486
17488
|
config: dtoToBankConfig(bankDto.config),
|
|
17487
|
-
totalAssetShares: new
|
|
17488
|
-
totalLiabilityShares: new
|
|
17489
|
+
totalAssetShares: new BigNumber(bankDto.totalAssetShares),
|
|
17490
|
+
totalLiabilityShares: new BigNumber(bankDto.totalLiabilityShares),
|
|
17489
17491
|
emissionsActiveBorrowing: bankDto.emissionsActiveBorrowing,
|
|
17490
17492
|
emissionsActiveLending: bankDto.emissionsActiveLending,
|
|
17491
17493
|
emissionsRate: bankDto.emissionsRate,
|
|
17492
|
-
emissionsMint: new
|
|
17493
|
-
emissionsRemaining: new
|
|
17494
|
-
oracleKey: new
|
|
17494
|
+
emissionsMint: new PublicKey(bankDto.emissionsMint),
|
|
17495
|
+
emissionsRemaining: new BigNumber(bankDto.emissionsRemaining),
|
|
17496
|
+
oracleKey: new PublicKey(bankDto.oracleKey),
|
|
17495
17497
|
pythShardId: bankDto.pythShardId,
|
|
17496
17498
|
emode: dtoToEmodeSettings(bankDto.emode),
|
|
17497
17499
|
tokenSymbol: bankDto.tokenSymbol
|
|
@@ -17506,76 +17508,76 @@ function dtoToEmodeSettings(emodeSettingsDto) {
|
|
|
17506
17508
|
return {
|
|
17507
17509
|
collateralBankEmodeTag: entry.collateralBankEmodeTag,
|
|
17508
17510
|
flags: entry.flags,
|
|
17509
|
-
assetWeightInit: new
|
|
17510
|
-
assetWeightMaint: new
|
|
17511
|
+
assetWeightInit: new BigNumber(entry.assetWeightInit),
|
|
17512
|
+
assetWeightMaint: new BigNumber(entry.assetWeightMaint)
|
|
17511
17513
|
};
|
|
17512
17514
|
})
|
|
17513
17515
|
};
|
|
17514
17516
|
}
|
|
17515
17517
|
function dtoToBankConfig(bankConfigDto) {
|
|
17516
17518
|
return {
|
|
17517
|
-
assetWeightInit: new
|
|
17518
|
-
assetWeightMaint: new
|
|
17519
|
-
liabilityWeightInit: new
|
|
17520
|
-
liabilityWeightMaint: new
|
|
17521
|
-
depositLimit: new
|
|
17522
|
-
borrowLimit: new
|
|
17519
|
+
assetWeightInit: new BigNumber(bankConfigDto.assetWeightInit),
|
|
17520
|
+
assetWeightMaint: new BigNumber(bankConfigDto.assetWeightMaint),
|
|
17521
|
+
liabilityWeightInit: new BigNumber(bankConfigDto.liabilityWeightInit),
|
|
17522
|
+
liabilityWeightMaint: new BigNumber(bankConfigDto.liabilityWeightMaint),
|
|
17523
|
+
depositLimit: new BigNumber(bankConfigDto.depositLimit),
|
|
17524
|
+
borrowLimit: new BigNumber(bankConfigDto.borrowLimit),
|
|
17523
17525
|
riskTier: bankConfigDto.riskTier,
|
|
17524
17526
|
operationalState: bankConfigDto.operationalState,
|
|
17525
|
-
totalAssetValueInitLimit: new
|
|
17527
|
+
totalAssetValueInitLimit: new BigNumber(bankConfigDto.totalAssetValueInitLimit),
|
|
17526
17528
|
assetTag: bankConfigDto.assetTag,
|
|
17527
17529
|
oracleSetup: bankConfigDto.oracleSetup,
|
|
17528
|
-
oracleKeys: bankConfigDto.oracleKeys.map((key) => new
|
|
17530
|
+
oracleKeys: bankConfigDto.oracleKeys.map((key) => new PublicKey(key)),
|
|
17529
17531
|
oracleMaxAge: bankConfigDto.oracleMaxAge,
|
|
17530
17532
|
interestRateConfig: dtoToInterestRateConfig(bankConfigDto.interestRateConfig)
|
|
17531
17533
|
};
|
|
17532
17534
|
}
|
|
17533
17535
|
function dtoToInterestRateConfig(interestRateConfigDto) {
|
|
17534
17536
|
return {
|
|
17535
|
-
optimalUtilizationRate: new
|
|
17536
|
-
plateauInterestRate: new
|
|
17537
|
-
maxInterestRate: new
|
|
17538
|
-
insuranceFeeFixedApr: new
|
|
17539
|
-
insuranceIrFee: new
|
|
17540
|
-
protocolFixedFeeApr: new
|
|
17541
|
-
protocolIrFee: new
|
|
17542
|
-
protocolOriginationFee: new
|
|
17537
|
+
optimalUtilizationRate: new BigNumber(interestRateConfigDto.optimalUtilizationRate),
|
|
17538
|
+
plateauInterestRate: new BigNumber(interestRateConfigDto.plateauInterestRate),
|
|
17539
|
+
maxInterestRate: new BigNumber(interestRateConfigDto.maxInterestRate),
|
|
17540
|
+
insuranceFeeFixedApr: new BigNumber(interestRateConfigDto.insuranceFeeFixedApr),
|
|
17541
|
+
insuranceIrFee: new BigNumber(interestRateConfigDto.insuranceIrFee),
|
|
17542
|
+
protocolFixedFeeApr: new BigNumber(interestRateConfigDto.protocolFixedFeeApr),
|
|
17543
|
+
protocolIrFee: new BigNumber(interestRateConfigDto.protocolIrFee),
|
|
17544
|
+
protocolOriginationFee: new BigNumber(interestRateConfigDto.protocolOriginationFee)
|
|
17543
17545
|
};
|
|
17544
17546
|
}
|
|
17545
17547
|
function dtoToBankRaw(bankDto) {
|
|
17546
17548
|
return {
|
|
17547
|
-
group: new
|
|
17548
|
-
mint: new
|
|
17549
|
+
group: new PublicKey(bankDto.group),
|
|
17550
|
+
mint: new PublicKey(bankDto.mint),
|
|
17549
17551
|
mintDecimals: bankDto.mintDecimals,
|
|
17550
17552
|
assetShareValue: bankDto.assetShareValue,
|
|
17551
17553
|
liabilityShareValue: bankDto.liabilityShareValue,
|
|
17552
|
-
liquidityVault: new
|
|
17554
|
+
liquidityVault: new PublicKey(bankDto.liquidityVault),
|
|
17553
17555
|
liquidityVaultBump: bankDto.liquidityVaultBump,
|
|
17554
17556
|
liquidityVaultAuthorityBump: bankDto.liquidityVaultAuthorityBump,
|
|
17555
|
-
insuranceVault: new
|
|
17557
|
+
insuranceVault: new PublicKey(bankDto.insuranceVault),
|
|
17556
17558
|
insuranceVaultBump: bankDto.insuranceVaultBump,
|
|
17557
17559
|
insuranceVaultAuthorityBump: bankDto.insuranceVaultAuthorityBump,
|
|
17558
17560
|
collectedInsuranceFeesOutstanding: bankDto.collectedInsuranceFeesOutstanding,
|
|
17559
|
-
feeVault: new
|
|
17561
|
+
feeVault: new PublicKey(bankDto.feeVault),
|
|
17560
17562
|
feeVaultBump: bankDto.feeVaultBump,
|
|
17561
17563
|
feeVaultAuthorityBump: bankDto.feeVaultAuthorityBump,
|
|
17562
17564
|
collectedGroupFeesOutstanding: bankDto.collectedGroupFeesOutstanding,
|
|
17563
|
-
lastUpdate: new
|
|
17565
|
+
lastUpdate: new BN$1(bankDto.lastUpdate),
|
|
17564
17566
|
config: dtoToBankConfigRaw(bankDto.config),
|
|
17565
17567
|
totalAssetShares: bankDto.totalAssetShares,
|
|
17566
17568
|
totalLiabilityShares: bankDto.totalLiabilityShares,
|
|
17567
|
-
flags: new
|
|
17568
|
-
emissionsRate: new
|
|
17569
|
+
flags: new BN$1(bankDto.flags),
|
|
17570
|
+
emissionsRate: new BN$1(bankDto.emissionsRate),
|
|
17569
17571
|
emissionsRemaining: bankDto.emissionsRemaining,
|
|
17570
|
-
emissionsMint: new
|
|
17572
|
+
emissionsMint: new PublicKey(bankDto.emissionsMint),
|
|
17571
17573
|
emode: dtoToEmodeSettingsRaw(bankDto.emode)
|
|
17572
17574
|
};
|
|
17573
17575
|
}
|
|
17574
17576
|
function dtoToEmodeSettingsRaw(emodeSettingsDto) {
|
|
17575
17577
|
return {
|
|
17576
17578
|
emodeTag: emodeSettingsDto.emodeTag,
|
|
17577
|
-
timestamp: new
|
|
17578
|
-
flags: new
|
|
17579
|
+
timestamp: new BN$1(emodeSettingsDto.timestamp),
|
|
17580
|
+
flags: new BN$1(emodeSettingsDto.flags),
|
|
17579
17581
|
emodeConfig: { entries: emodeSettingsDto.emodeConfig.entries.map((entry) => {
|
|
17580
17582
|
return {
|
|
17581
17583
|
collateralBankEmodeTag: entry.collateralBankEmodeTag,
|
|
@@ -17592,41 +17594,41 @@ function dtoToBankConfigRaw(bankConfigDto) {
|
|
|
17592
17594
|
assetWeightMaint: bankConfigDto.assetWeightMaint,
|
|
17593
17595
|
liabilityWeightInit: bankConfigDto.liabilityWeightInit,
|
|
17594
17596
|
liabilityWeightMaint: bankConfigDto.liabilityWeightMaint,
|
|
17595
|
-
depositLimit: new
|
|
17596
|
-
borrowLimit: new
|
|
17597
|
+
depositLimit: new BN$1(bankConfigDto.depositLimit),
|
|
17598
|
+
borrowLimit: new BN$1(bankConfigDto.borrowLimit),
|
|
17597
17599
|
riskTier: bankConfigDto.riskTier,
|
|
17598
17600
|
operationalState: bankConfigDto.operationalState,
|
|
17599
|
-
totalAssetValueInitLimit: new
|
|
17601
|
+
totalAssetValueInitLimit: new BN$1(bankConfigDto.totalAssetValueInitLimit),
|
|
17600
17602
|
assetTag: bankConfigDto.assetTag,
|
|
17601
17603
|
oracleSetup: bankConfigDto.oracleSetup,
|
|
17602
|
-
oracleKeys: bankConfigDto.oracleKeys.map((key) => new
|
|
17604
|
+
oracleKeys: bankConfigDto.oracleKeys.map((key) => new PublicKey(key)),
|
|
17603
17605
|
oracleMaxAge: bankConfigDto.oracleMaxAge,
|
|
17604
17606
|
interestRateConfig: bankConfigDto.interestRateConfig
|
|
17605
17607
|
};
|
|
17606
17608
|
}
|
|
17607
17609
|
function parseBankConfigRaw(bankConfigRaw) {
|
|
17608
|
-
const assetWeightInit =
|
|
17609
|
-
const assetWeightMaint =
|
|
17610
|
-
const liabilityWeightInit =
|
|
17611
|
-
const liabilityWeightMaint =
|
|
17612
|
-
const depositLimit = (
|
|
17613
|
-
const borrowLimit = (
|
|
17610
|
+
const assetWeightInit = wrappedI80F48toBigNumber(bankConfigRaw.assetWeightInit);
|
|
17611
|
+
const assetWeightMaint = wrappedI80F48toBigNumber(bankConfigRaw.assetWeightMaint);
|
|
17612
|
+
const liabilityWeightInit = wrappedI80F48toBigNumber(bankConfigRaw.liabilityWeightInit);
|
|
17613
|
+
const liabilityWeightMaint = wrappedI80F48toBigNumber(bankConfigRaw.liabilityWeightMaint);
|
|
17614
|
+
const depositLimit = BigNumber(bankConfigRaw.depositLimit.toString());
|
|
17615
|
+
const borrowLimit = BigNumber(bankConfigRaw.borrowLimit.toString());
|
|
17614
17616
|
const riskTier = parseRiskTier(bankConfigRaw.riskTier);
|
|
17615
17617
|
const operationalState = parseOperationalState(bankConfigRaw.operationalState);
|
|
17616
|
-
const totalAssetValueInitLimit = (
|
|
17618
|
+
const totalAssetValueInitLimit = BigNumber(bankConfigRaw.totalAssetValueInitLimit.toString());
|
|
17617
17619
|
const assetTag = bankConfigRaw.assetTag;
|
|
17618
17620
|
const oracleSetup = parseOracleSetup(bankConfigRaw.oracleSetup);
|
|
17619
17621
|
const oracleKeys = bankConfigRaw.oracleKeys;
|
|
17620
|
-
const oracleMaxAge = bankConfigRaw.oracleMaxAge === 0 ?
|
|
17622
|
+
const oracleMaxAge = bankConfigRaw.oracleMaxAge === 0 ? DEFAULT_ORACLE_MAX_AGE : bankConfigRaw.oracleMaxAge;
|
|
17621
17623
|
const interestRateConfig = {
|
|
17622
|
-
insuranceFeeFixedApr:
|
|
17623
|
-
maxInterestRate:
|
|
17624
|
-
insuranceIrFee:
|
|
17625
|
-
optimalUtilizationRate:
|
|
17626
|
-
plateauInterestRate:
|
|
17627
|
-
protocolFixedFeeApr:
|
|
17628
|
-
protocolIrFee:
|
|
17629
|
-
protocolOriginationFee:
|
|
17624
|
+
insuranceFeeFixedApr: wrappedI80F48toBigNumber(bankConfigRaw.interestRateConfig.insuranceFeeFixedApr),
|
|
17625
|
+
maxInterestRate: wrappedI80F48toBigNumber(bankConfigRaw.interestRateConfig.maxInterestRate),
|
|
17626
|
+
insuranceIrFee: wrappedI80F48toBigNumber(bankConfigRaw.interestRateConfig.insuranceIrFee),
|
|
17627
|
+
optimalUtilizationRate: wrappedI80F48toBigNumber(bankConfigRaw.interestRateConfig.optimalUtilizationRate),
|
|
17628
|
+
plateauInterestRate: wrappedI80F48toBigNumber(bankConfigRaw.interestRateConfig.plateauInterestRate),
|
|
17629
|
+
protocolFixedFeeApr: wrappedI80F48toBigNumber(bankConfigRaw.interestRateConfig.protocolFixedFeeApr),
|
|
17630
|
+
protocolIrFee: wrappedI80F48toBigNumber(bankConfigRaw.interestRateConfig.protocolIrFee),
|
|
17631
|
+
protocolOriginationFee: wrappedI80F48toBigNumber(bankConfigRaw.interestRateConfig.protocolOriginationFee)
|
|
17630
17632
|
};
|
|
17631
17633
|
return {
|
|
17632
17634
|
assetWeightInit,
|
|
@@ -17689,7 +17691,7 @@ function getActiveEmodeFlags(flags) {
|
|
|
17689
17691
|
* Check if a specific EMode flag is set
|
|
17690
17692
|
*/
|
|
17691
17693
|
function hasEmodeFlag(flags, flag) {
|
|
17692
|
-
return !flags.and(new
|
|
17694
|
+
return !flags.and(new BN$1(flag)).isZero();
|
|
17693
17695
|
}
|
|
17694
17696
|
/**
|
|
17695
17697
|
* Get all active EMode entry flags as an array of flag names
|
|
@@ -17736,17 +17738,17 @@ const getStakeAccount = (data) => {
|
|
|
17736
17738
|
offset += 4;
|
|
17737
17739
|
const rentExemptReserve = data.readBigUInt64LE(offset);
|
|
17738
17740
|
offset += 8;
|
|
17739
|
-
const staker = new
|
|
17741
|
+
const staker = new PublicKey(data.subarray(offset, offset + 32));
|
|
17740
17742
|
offset += 32;
|
|
17741
|
-
const withdrawer = new
|
|
17743
|
+
const withdrawer = new PublicKey(data.subarray(offset, offset + 32));
|
|
17742
17744
|
offset += 32;
|
|
17743
17745
|
const unixTimestamp = data.readBigUInt64LE(offset);
|
|
17744
17746
|
offset += 8;
|
|
17745
17747
|
const epoch = data.readBigUInt64LE(offset);
|
|
17746
17748
|
offset += 8;
|
|
17747
|
-
const custodian = new
|
|
17749
|
+
const custodian = new PublicKey(data.subarray(offset, offset + 32));
|
|
17748
17750
|
offset += 32;
|
|
17749
|
-
const voterPubkey = new
|
|
17751
|
+
const voterPubkey = new PublicKey(data.subarray(offset, offset + 32));
|
|
17750
17752
|
offset += 32;
|
|
17751
17753
|
const stake = data.readBigUInt64LE(offset);
|
|
17752
17754
|
offset += 8;
|
|
@@ -17784,7 +17786,7 @@ const getStakeAccount = (data) => {
|
|
|
17784
17786
|
//#endregion
|
|
17785
17787
|
//#region src/vendor/index.ts
|
|
17786
17788
|
var vendor_exports = {};
|
|
17787
|
-
|
|
17789
|
+
__export(vendor_exports, {
|
|
17788
17790
|
AccountType: () => AccountType$1,
|
|
17789
17791
|
AggregatorAccount: () => AggregatorAccount,
|
|
17790
17792
|
AggregatorAccountData: () => AggregatorAccountData,
|
|
@@ -17820,17 +17822,17 @@ require_common.__export(vendor_exports, {
|
|
|
17820
17822
|
//#region src/utils.ts
|
|
17821
17823
|
function getBankVaultSeeds(type) {
|
|
17822
17824
|
switch (type) {
|
|
17823
|
-
case BankVaultType.LiquidityVault: return
|
|
17824
|
-
case BankVaultType.InsuranceVault: return
|
|
17825
|
-
case BankVaultType.FeeVault: return
|
|
17825
|
+
case BankVaultType.LiquidityVault: return PDA_BANK_LIQUIDITY_VAULT_SEED;
|
|
17826
|
+
case BankVaultType.InsuranceVault: return PDA_BANK_INSURANCE_VAULT_SEED;
|
|
17827
|
+
case BankVaultType.FeeVault: return PDA_BANK_FEE_VAULT_SEED;
|
|
17826
17828
|
default: throw Error(`Unknown vault type ${type}`);
|
|
17827
17829
|
}
|
|
17828
17830
|
}
|
|
17829
17831
|
function getBankVaultAuthoritySeeds(type) {
|
|
17830
17832
|
switch (type) {
|
|
17831
|
-
case BankVaultType.LiquidityVault: return
|
|
17832
|
-
case BankVaultType.InsuranceVault: return
|
|
17833
|
-
case BankVaultType.FeeVault: return
|
|
17833
|
+
case BankVaultType.LiquidityVault: return PDA_BANK_LIQUIDITY_VAULT_AUTH_SEED;
|
|
17834
|
+
case BankVaultType.InsuranceVault: return PDA_BANK_INSURANCE_VAULT_AUTH_SEED;
|
|
17835
|
+
case BankVaultType.FeeVault: return PDA_BANK_FEE_VAULT_AUTH_SEED;
|
|
17834
17836
|
default: throw Error(`Unknown vault type ${type}`);
|
|
17835
17837
|
}
|
|
17836
17838
|
}
|
|
@@ -17838,33 +17840,33 @@ function getBankVaultAuthoritySeeds(type) {
|
|
|
17838
17840
|
* Compute authority PDA for a specific lendr group bank vault
|
|
17839
17841
|
*/
|
|
17840
17842
|
function getBankVaultAuthority(bankVaultType, bankPk, programId) {
|
|
17841
|
-
return
|
|
17843
|
+
return PublicKey.findProgramAddressSync([getBankVaultAuthoritySeeds(bankVaultType), bankPk.toBuffer()], programId);
|
|
17842
17844
|
}
|
|
17843
17845
|
function makeWrapSolIxs(walletAddress, amount) {
|
|
17844
|
-
const address$2 =
|
|
17845
|
-
const ixs = [
|
|
17846
|
+
const address$2 = getAssociatedTokenAddressSync(NATIVE_MINT, walletAddress, true);
|
|
17847
|
+
const ixs = [createAssociatedTokenAccountIdempotentInstruction(walletAddress, address$2, walletAddress, NATIVE_MINT)];
|
|
17846
17848
|
if (amount.gt(0)) {
|
|
17847
|
-
const nativeAmount =
|
|
17848
|
-
ixs.push(
|
|
17849
|
+
const nativeAmount = uiToNative(amount, 9).toNumber() + 1e4;
|
|
17850
|
+
ixs.push(SystemProgram.transfer({
|
|
17849
17851
|
fromPubkey: walletAddress,
|
|
17850
17852
|
toPubkey: address$2,
|
|
17851
17853
|
lamports: nativeAmount
|
|
17852
|
-
}),
|
|
17854
|
+
}), createSyncNativeInstruction(address$2));
|
|
17853
17855
|
}
|
|
17854
17856
|
return ixs;
|
|
17855
17857
|
}
|
|
17856
17858
|
function makeUnwrapSolIx(walletAddress) {
|
|
17857
|
-
const address$2 =
|
|
17858
|
-
return
|
|
17859
|
+
const address$2 = getAssociatedTokenAddressSync(NATIVE_MINT, walletAddress, true);
|
|
17860
|
+
return createCloseAccountInstruction(address$2, walletAddress, walletAddress);
|
|
17859
17861
|
}
|
|
17860
17862
|
async function makeVersionedTransaction(blockhash, transaction, payer, addressLookupTables) {
|
|
17861
|
-
const message = new
|
|
17863
|
+
const message = new TransactionMessage({
|
|
17862
17864
|
instructions: transaction.instructions,
|
|
17863
17865
|
payerKey: payer,
|
|
17864
17866
|
recentBlockhash: blockhash
|
|
17865
17867
|
});
|
|
17866
17868
|
const versionedMessage = addressLookupTables ? message.compileToV0Message(addressLookupTables) : message.compileToLegacyMessage();
|
|
17867
|
-
return new
|
|
17869
|
+
return new VersionedTransaction(versionedMessage);
|
|
17868
17870
|
}
|
|
17869
17871
|
/**
|
|
17870
17872
|
* Creates a compute budget instruction to set the priority fee for a transaction.
|
|
@@ -17874,7 +17876,7 @@ async function makeVersionedTransaction(blockhash, transaction, payer, addressLo
|
|
|
17874
17876
|
* @returns A compute budget instruction with the specified priority fee
|
|
17875
17877
|
*/
|
|
17876
17878
|
function makePriorityFeeMicroIx(priorityFeeMicro) {
|
|
17877
|
-
return
|
|
17879
|
+
return ComputeBudgetProgram.setComputeUnitPrice({ microLamports: Math.floor(priorityFeeMicro ?? 1) });
|
|
17878
17880
|
}
|
|
17879
17881
|
function makePriorityFeeIx(priorityFeeUi, computeUnitsLimit) {
|
|
17880
17882
|
const priorityFeeIx = [];
|
|
@@ -17883,11 +17885,11 @@ function makePriorityFeeIx(priorityFeeUi, computeUnitsLimit) {
|
|
|
17883
17885
|
if (priorityFeeUi) {
|
|
17884
17886
|
const isAbsurdPriorityFee = priorityFeeUi > .1;
|
|
17885
17887
|
if (!isAbsurdPriorityFee) {
|
|
17886
|
-
const priorityFeeMicroLamports = priorityFeeUi *
|
|
17888
|
+
const priorityFeeMicroLamports = priorityFeeUi * LAMPORTS_PER_SOL * 1e6;
|
|
17887
17889
|
microLamports = Math.round(priorityFeeMicroLamports / limit);
|
|
17888
17890
|
}
|
|
17889
17891
|
}
|
|
17890
|
-
priorityFeeIx.push(
|
|
17892
|
+
priorityFeeIx.push(ComputeBudgetProgram.setComputeUnitPrice({ microLamports }));
|
|
17891
17893
|
return priorityFeeIx;
|
|
17892
17894
|
}
|
|
17893
17895
|
function feedIdToString(feedId) {
|
|
@@ -17899,7 +17901,7 @@ async function buildFeedIdMap(bankConfigs, connection) {
|
|
|
17899
17901
|
const feedId = bankConfig.oracleKeys[0].toBuffer();
|
|
17900
17902
|
return {
|
|
17901
17903
|
feedId,
|
|
17902
|
-
addresses: [findPythPushOracleAddress(feedId,
|
|
17904
|
+
addresses: [findPythPushOracleAddress(feedId, PYTH_PUSH_ORACLE_ID, PYTH_SPONSORED_SHARD_ID), findPythPushOracleAddress(feedId, PYTH_PUSH_ORACLE_ID, LENDR_SPONSORED_SHARD_ID)]
|
|
17903
17905
|
};
|
|
17904
17906
|
});
|
|
17905
17907
|
const addressess = feedIdsWithAddresses.flatMap((feedIdWithAddress) => feedIdWithAddress.addresses);
|
|
@@ -17975,7 +17977,7 @@ const PYTH_SPONSORED_SHARD_ID = 0;
|
|
|
17975
17977
|
const LENDR_SPONSORED_SHARD_ID = 3301;
|
|
17976
17978
|
function findPythPushOracleAddress(feedId, programId, shardId) {
|
|
17977
17979
|
const shardBytes = u16ToArrayBufferLE(shardId);
|
|
17978
|
-
return
|
|
17980
|
+
return PublicKey.findProgramAddressSync([shardBytes, feedId], programId)[0];
|
|
17979
17981
|
}
|
|
17980
17982
|
function u16ToArrayBufferLE(value) {
|
|
17981
17983
|
const buffer = new ArrayBuffer(2);
|
|
@@ -18042,8 +18044,8 @@ var Bank = class Bank {
|
|
|
18042
18044
|
const newBank = Object.create(Bank.prototype);
|
|
18043
18045
|
Object.assign(newBank, bank);
|
|
18044
18046
|
newBank.config = Object.assign({}, bank.config);
|
|
18045
|
-
newBank.config.assetWeightInit =
|
|
18046
|
-
newBank.config.assetWeightMaint =
|
|
18047
|
+
newBank.config.assetWeightInit = BigNumber.max(bank.config.assetWeightInit, emodeWeights.assetWeightInit);
|
|
18048
|
+
newBank.config.assetWeightMaint = BigNumber.max(bank.config.assetWeightMaint, emodeWeights.assetWeightMaint);
|
|
18047
18049
|
return newBank;
|
|
18048
18050
|
}
|
|
18049
18051
|
static getPrice(oraclePrice, priceBias = PriceBias.None, weightedPrice = false) {
|
|
@@ -18109,8 +18111,8 @@ var Bank = class Bank {
|
|
|
18109
18111
|
Bank address: ${this.address.toBase58()}
|
|
18110
18112
|
Mint: ${this.mint.toBase58()}, decimals: ${this.mintDecimals}
|
|
18111
18113
|
|
|
18112
|
-
Total deposits: ${
|
|
18113
|
-
Total borrows: ${
|
|
18114
|
+
Total deposits: ${nativeToUi(this.getTotalAssetQuantity(), this.mintDecimals)}
|
|
18115
|
+
Total borrows: ${nativeToUi(this.getTotalLiabilityQuantity(), this.mintDecimals)}
|
|
18114
18116
|
|
|
18115
18117
|
Total assets (USD value): ${this.computeAssetUsdValue(oraclePrice, this.totalAssetShares, LendrRequirementType.Equity, PriceBias.None)}
|
|
18116
18118
|
Total liabilities (USD value): ${this.computeLiabilityUsdValue(oraclePrice, this.totalLiabilityShares, LendrRequirementType.Equity, PriceBias.None)}
|
|
@@ -18128,8 +18130,8 @@ Config:
|
|
|
18128
18130
|
- Borrow limit: ${this.config.borrowLimit}
|
|
18129
18131
|
|
|
18130
18132
|
LTVs:
|
|
18131
|
-
- Initial: ${new
|
|
18132
|
-
- Maintenance: ${new
|
|
18133
|
+
- Initial: ${new BigNumber(1).div(this.config.liabilityWeightInit).times(100).toFixed(2)}%
|
|
18134
|
+
- Maintenance: ${new BigNumber(1).div(this.config.liabilityWeightMaint).times(100).toFixed(2)}%
|
|
18133
18135
|
`;
|
|
18134
18136
|
}
|
|
18135
18137
|
};
|
|
@@ -18295,7 +18297,7 @@ var LendrAccount = class LendrAccount {
|
|
|
18295
18297
|
const useCache = false;
|
|
18296
18298
|
const freeCollateral = useCache ? this.computeFreeCollateral().times(_volatilityFactor) : this.computeFreeCollateralLegacy(banks, oraclePrices);
|
|
18297
18299
|
logger.debug({ freeCollateral: freeCollateral.toFixed(6) }, "[lendr:computeMaxBorrowForBank] Free collateral");
|
|
18298
|
-
const untiedCollateralForBank =
|
|
18300
|
+
const untiedCollateralForBank = BigNumber.min(bank.computeAssetUsdValue(priceInfo, balance.assetShares, LendrRequirementType.Initial, PriceBias.Lowest), freeCollateral);
|
|
18299
18301
|
const priceLowestBias = getPrice(priceInfo, PriceBias.Lowest, true);
|
|
18300
18302
|
const priceHighestBias = getPrice(priceInfo, PriceBias.Highest, true);
|
|
18301
18303
|
const assetWeight = bank.getAssetWeight(LendrRequirementType.Initial, priceInfo);
|
|
@@ -18323,7 +18325,7 @@ var LendrAccount = class LendrAccount {
|
|
|
18323
18325
|
const { liabilities: liabilitiesInit } = this.computeHealthComponents(LendrRequirementType.Initial);
|
|
18324
18326
|
if (bank.config.riskTier === RiskTier.Isolated || initAssetWeight.isZero() && maintAssetWeight.isZero()) {
|
|
18325
18327
|
if (freeCollateral.isZero() && !liabilitiesInit.isZero()) {
|
|
18326
|
-
return new
|
|
18328
|
+
return new BigNumber(0);
|
|
18327
18329
|
} else {
|
|
18328
18330
|
return entireBalance;
|
|
18329
18331
|
}
|
|
@@ -18332,7 +18334,7 @@ var LendrAccount = class LendrAccount {
|
|
|
18332
18334
|
if (liabilitiesInit.eq(0)) {
|
|
18333
18335
|
return entireBalance;
|
|
18334
18336
|
} else if (freeCollateral.isZero()) {
|
|
18335
|
-
return new
|
|
18337
|
+
return new BigNumber(0);
|
|
18336
18338
|
} else {
|
|
18337
18339
|
const { liabilities: maintLiabilities, assets: maintAssets } = this.computeHealthComponents(LendrRequirementType.Maintenance);
|
|
18338
18340
|
const maintUntiedCollateral = maintAssets.minus(maintLiabilities);
|
|
@@ -18422,7 +18424,7 @@ var LendrAccount = class LendrAccount {
|
|
|
18422
18424
|
const { assets: assetsAccount, liabilities: liabilitiesAccount } = this.computeHealthComponents(LendrRequirementType.Maintenance);
|
|
18423
18425
|
const assets = assetsAccount.minus(assetBank);
|
|
18424
18426
|
const liabilities = liabilitiesAccount.minus(liabilitiesBank);
|
|
18425
|
-
const amountBn = new
|
|
18427
|
+
const amountBn = new BigNumber(amount);
|
|
18426
18428
|
let liquidationPrice;
|
|
18427
18429
|
if (isLending) {
|
|
18428
18430
|
if (liabilities.eq(0)) return null;
|
|
@@ -18451,7 +18453,7 @@ var LendrAccount = class LendrAccount {
|
|
|
18451
18453
|
const priceAssetLower = getPrice(assetPriceInfo, PriceBias.Lowest, false);
|
|
18452
18454
|
const priceAssetMarket = getPrice(assetPriceInfo, PriceBias.None, false);
|
|
18453
18455
|
const assetMaintWeight = assetBank.config.assetWeightMaint;
|
|
18454
|
-
const liquidationDiscount = new
|
|
18456
|
+
const liquidationDiscount = new BigNumber(.95);
|
|
18455
18457
|
const priceLiabHighest = getPrice(liabilityPriceInfo, PriceBias.Highest, false);
|
|
18456
18458
|
const priceLiabMarket = getPrice(liabilityPriceInfo, PriceBias.None, false);
|
|
18457
18459
|
const liabMaintWeight = liabilityBank.config.liabilityWeightMaint;
|
|
@@ -18477,7 +18479,7 @@ var LendrAccount = class LendrAccount {
|
|
|
18477
18479
|
priceLiabMarket: priceLiabMarket.toFixed(6),
|
|
18478
18480
|
liabUsdValue: liabUsdValue.toFixed(6)
|
|
18479
18481
|
}, "[lendr:getMaxLiquidatableAssetAmount]");
|
|
18480
|
-
const maxLiquidatableUsdValue =
|
|
18482
|
+
const maxLiquidatableUsdValue = BigNumber.min(assetsUsdValue, underwaterMaintUsdValue, liabUsdValue);
|
|
18481
18483
|
logger.debug({ maxLiquidatableUsdValue: maxLiquidatableUsdValue.toFixed(6) }, "[lendr:getMaxLiquidatableAssetAmount] Max liquidatable usd value");
|
|
18482
18484
|
return maxLiquidatableUsdValue.div(priceAssetLower);
|
|
18483
18485
|
}
|
|
@@ -18520,21 +18522,21 @@ var LendrAccount = class LendrAccount {
|
|
|
18520
18522
|
if (!mintData) throw Error(`Mint for bank ${bankAddress.toBase58()} not found`);
|
|
18521
18523
|
const wrapAndUnwrapSol = opts.wrapAndUnwrapSol ?? true;
|
|
18522
18524
|
const wSolBalanceUi = opts.wSolBalanceUi ?? 0;
|
|
18523
|
-
const userTokenAtaPk =
|
|
18524
|
-
const remainingAccounts = mintData.tokenProgram.equals(
|
|
18525
|
+
const userTokenAtaPk = getAssociatedTokenAddressSync(bank.mint, this.authority, true, mintData.tokenProgram);
|
|
18526
|
+
const remainingAccounts = mintData.tokenProgram.equals(TOKEN_2022_PROGRAM_ID) ? [{
|
|
18525
18527
|
pubkey: mintData.mint,
|
|
18526
18528
|
isSigner: false,
|
|
18527
18529
|
isWritable: false
|
|
18528
18530
|
}] : [];
|
|
18529
18531
|
const depositIxs = [];
|
|
18530
|
-
if (bank.mint.equals(
|
|
18531
|
-
depositIxs.push(...makeWrapSolIxs(this.authority, new
|
|
18532
|
+
if (bank.mint.equals(NATIVE_MINT) && wrapAndUnwrapSol) {
|
|
18533
|
+
depositIxs.push(...makeWrapSolIxs(this.authority, new BigNumber(amount).minus(wSolBalanceUi)));
|
|
18532
18534
|
}
|
|
18533
18535
|
return {
|
|
18534
18536
|
depositIxs,
|
|
18535
18537
|
userTokenAtaPk,
|
|
18536
18538
|
mintData,
|
|
18537
|
-
ixArguments: { amount:
|
|
18539
|
+
ixArguments: { amount: uiToNative(amount, bank.mintDecimals) },
|
|
18538
18540
|
remainingAccounts
|
|
18539
18541
|
};
|
|
18540
18542
|
}
|
|
@@ -18581,23 +18583,23 @@ var LendrAccount = class LendrAccount {
|
|
|
18581
18583
|
const wrapAndUnwrapSol = opts.wrapAndUnwrapSol ?? true;
|
|
18582
18584
|
const wSolBalanceUi = opts.wSolBalanceUi ?? 0;
|
|
18583
18585
|
const repayIxs = [];
|
|
18584
|
-
if (repayAll && !bank.emissionsMint.equals(
|
|
18586
|
+
if (repayAll && !bank.emissionsMint.equals(PublicKey.default)) {
|
|
18585
18587
|
repayIxs.push(...(await this.makeWithdrawEmissionsIx(program, banks, mintDatas, bankAddress)).instructions);
|
|
18586
18588
|
}
|
|
18587
|
-
const userAta =
|
|
18589
|
+
const userAta = getAssociatedTokenAddressSync(bank.mint, this.authority, true, mintData.tokenProgram);
|
|
18588
18590
|
const remainingAccounts = [];
|
|
18589
|
-
if (mintData.tokenProgram.equals(
|
|
18591
|
+
if (mintData.tokenProgram.equals(TOKEN_2022_PROGRAM_ID)) {
|
|
18590
18592
|
remainingAccounts.push(mintData.mint);
|
|
18591
18593
|
}
|
|
18592
|
-
if (bank.mint.equals(
|
|
18593
|
-
repayIxs.push(...makeWrapSolIxs(this.authority, new
|
|
18594
|
+
if (bank.mint.equals(NATIVE_MINT) && wrapAndUnwrapSol) {
|
|
18595
|
+
repayIxs.push(...makeWrapSolIxs(this.authority, new BigNumber(amount).minus(wSolBalanceUi)));
|
|
18594
18596
|
}
|
|
18595
18597
|
return {
|
|
18596
18598
|
repayIxs,
|
|
18597
18599
|
mintData,
|
|
18598
18600
|
userAta,
|
|
18599
18601
|
ixArguments: {
|
|
18600
|
-
amount:
|
|
18602
|
+
amount: uiToNative(amount, bank.mintDecimals),
|
|
18601
18603
|
repayAll
|
|
18602
18604
|
},
|
|
18603
18605
|
remainingAccounts
|
|
@@ -18653,17 +18655,17 @@ var LendrAccount = class LendrAccount {
|
|
|
18653
18655
|
const wrapAndUnwrapSol = withdrawOpts.wrapAndUnwrapSol ?? true;
|
|
18654
18656
|
const createAtas = withdrawOpts.createAtas ?? true;
|
|
18655
18657
|
const withdrawIxs = [];
|
|
18656
|
-
if (withdrawAll && !bank.emissionsMint.equals(
|
|
18658
|
+
if (withdrawAll && !bank.emissionsMint.equals(PublicKey.default) && mintData.emissionTokenProgram) {
|
|
18657
18659
|
withdrawIxs.push(...(await this.makeWithdrawEmissionsIx(program, bankMap, mintDatas, bankAddress)).instructions);
|
|
18658
18660
|
}
|
|
18659
|
-
const userAta =
|
|
18661
|
+
const userAta = getAssociatedTokenAddressSync(bank.mint, this.authority, true, mintData.tokenProgram);
|
|
18660
18662
|
if (createAtas) {
|
|
18661
|
-
const createAtaIdempotentIx =
|
|
18663
|
+
const createAtaIdempotentIx = createAssociatedTokenAccountIdempotentInstruction(withdrawOpts?.createAtaPayer ?? this.authority, userAta, this.authority, bank.mint, mintData.tokenProgram);
|
|
18662
18664
|
withdrawIxs.push(createAtaIdempotentIx);
|
|
18663
18665
|
}
|
|
18664
18666
|
const healthAccounts = withdrawAll ? this.getHealthCheckAccounts(bankMap, [], [bankAddress]) : this.getHealthCheckAccounts(bankMap, [bankAddress], []);
|
|
18665
18667
|
const remainingAccounts = [];
|
|
18666
|
-
if (mintData.tokenProgram.equals(
|
|
18668
|
+
if (mintData.tokenProgram.equals(TOKEN_2022_PROGRAM_ID)) {
|
|
18667
18669
|
remainingAccounts.push(mintData.mint);
|
|
18668
18670
|
}
|
|
18669
18671
|
if (withdrawOpts.observationBanksOverride) {
|
|
@@ -18695,11 +18697,11 @@ var LendrAccount = class LendrAccount {
|
|
|
18695
18697
|
authority: withdrawOpts.overrideInferAccounts?.authority,
|
|
18696
18698
|
group: withdrawOpts.overrideInferAccounts?.group
|
|
18697
18699
|
}, {
|
|
18698
|
-
amount:
|
|
18700
|
+
amount: uiToNative(amount, bank.mintDecimals),
|
|
18699
18701
|
withdrawAll
|
|
18700
18702
|
}, remainingAccounts);
|
|
18701
18703
|
withdrawIxs.push(withdrawIx);
|
|
18702
|
-
if (wrapAndUnwrapSol && bank.mint.equals(
|
|
18704
|
+
if (wrapAndUnwrapSol && bank.mint.equals(NATIVE_MINT)) {
|
|
18703
18705
|
withdrawIxs.push(makeUnwrapSolIx(this.authority));
|
|
18704
18706
|
}
|
|
18705
18707
|
return {
|
|
@@ -18720,11 +18722,11 @@ var LendrAccount = class LendrAccount {
|
|
|
18720
18722
|
tokenProgram: mintData.tokenProgram,
|
|
18721
18723
|
group: withdrawOpts.overrideInferAccounts?.group
|
|
18722
18724
|
}, {
|
|
18723
|
-
amount:
|
|
18725
|
+
amount: uiToNative(amount, bank.mintDecimals),
|
|
18724
18726
|
withdrawAll
|
|
18725
18727
|
}, remainingAccounts);
|
|
18726
18728
|
withdrawIxs.push(withdrawIx);
|
|
18727
|
-
if (wrapAndUnwrapSol && bank.mint.equals(
|
|
18729
|
+
if (wrapAndUnwrapSol && bank.mint.equals(NATIVE_MINT)) {
|
|
18728
18730
|
withdrawIxs.push(makeUnwrapSolIx(this.authority));
|
|
18729
18731
|
}
|
|
18730
18732
|
return {
|
|
@@ -18740,14 +18742,14 @@ var LendrAccount = class LendrAccount {
|
|
|
18740
18742
|
const wrapAndUnwrapSol = borrowOpts.wrapAndUnwrapSol ?? true;
|
|
18741
18743
|
const createAtas = borrowOpts.createAtas ?? true;
|
|
18742
18744
|
const borrowIxs = [];
|
|
18743
|
-
const userAta =
|
|
18745
|
+
const userAta = getAssociatedTokenAddressSync(bank.mint, this.authority, true, mintData.tokenProgram);
|
|
18744
18746
|
if (createAtas) {
|
|
18745
|
-
const createAtaIdempotentIx =
|
|
18747
|
+
const createAtaIdempotentIx = createAssociatedTokenAccountIdempotentInstruction(borrowOpts?.createAtaPayer ?? this.authority, userAta, this.authority, bank.mint, mintData.tokenProgram);
|
|
18746
18748
|
borrowIxs.push(createAtaIdempotentIx);
|
|
18747
18749
|
}
|
|
18748
18750
|
const healthAccounts = this.getHealthCheckAccounts(bankMap, [bankAddress], []);
|
|
18749
18751
|
const remainingAccounts = [];
|
|
18750
|
-
if (mintData.tokenProgram.equals(
|
|
18752
|
+
if (mintData.tokenProgram.equals(TOKEN_2022_PROGRAM_ID)) {
|
|
18751
18753
|
remainingAccounts.push(mintData.mint);
|
|
18752
18754
|
}
|
|
18753
18755
|
if (borrowOpts?.observationBanksOverride) {
|
|
@@ -18778,9 +18780,9 @@ var LendrAccount = class LendrAccount {
|
|
|
18778
18780
|
tokenProgram: mintData.tokenProgram,
|
|
18779
18781
|
authority: borrowOpts?.overrideInferAccounts?.authority,
|
|
18780
18782
|
group: borrowOpts?.overrideInferAccounts?.group
|
|
18781
|
-
}, { amount:
|
|
18783
|
+
}, { amount: uiToNative(amount, bank.mintDecimals) }, remainingAccounts);
|
|
18782
18784
|
borrowIxs.push(borrowIx);
|
|
18783
|
-
if (bank.mint.equals(
|
|
18785
|
+
if (bank.mint.equals(NATIVE_MINT) && wrapAndUnwrapSol) {
|
|
18784
18786
|
borrowIxs.push(makeUnwrapSolIx(this.authority));
|
|
18785
18787
|
}
|
|
18786
18788
|
return {
|
|
@@ -18800,9 +18802,9 @@ var LendrAccount = class LendrAccount {
|
|
|
18800
18802
|
destinationTokenAccount: userAta,
|
|
18801
18803
|
tokenProgram: mintData.tokenProgram,
|
|
18802
18804
|
group: borrowOpts?.overrideInferAccounts?.group
|
|
18803
|
-
}, { amount:
|
|
18805
|
+
}, { amount: uiToNative(amount, bank.mintDecimals) }, remainingAccounts);
|
|
18804
18806
|
borrowIxs.push(borrowIx);
|
|
18805
|
-
if (bank.mint.equals(
|
|
18807
|
+
if (bank.mint.equals(NATIVE_MINT) && wrapAndUnwrapSol) {
|
|
18806
18808
|
borrowIxs.push(makeUnwrapSolIx(this.authority));
|
|
18807
18809
|
}
|
|
18808
18810
|
return {
|
|
@@ -18819,8 +18821,8 @@ var LendrAccount = class LendrAccount {
|
|
|
18819
18821
|
throw Error(`Emission token program not found for bank ${bankAddress.toBase58()}`);
|
|
18820
18822
|
}
|
|
18821
18823
|
const ixs = [];
|
|
18822
|
-
const userAta =
|
|
18823
|
-
const createAtaIdempotentIx =
|
|
18824
|
+
const userAta = getAssociatedTokenAddressSync(bank.emissionsMint, this.authority, true, mintData.emissionTokenProgram);
|
|
18825
|
+
const createAtaIdempotentIx = createAssociatedTokenAccountIdempotentInstruction(this.authority, userAta, this.authority, bank.emissionsMint, mintData.emissionTokenProgram);
|
|
18824
18826
|
ixs.push(createAtaIdempotentIx);
|
|
18825
18827
|
const withdrawEmissionsIx = await instructions_default.makelendingAccountWithdrawEmissionIx(program, {
|
|
18826
18828
|
lendrAccount: this.address,
|
|
@@ -18844,19 +18846,19 @@ var LendrAccount = class LendrAccount {
|
|
|
18844
18846
|
const ixs = [];
|
|
18845
18847
|
const healthAccounts = [...this.getHealthCheckAccounts(bankMap, [liabilityBankAddress, assetBankAddress], []), ...liquidateeLendrAccount.getHealthCheckAccounts(bankMap, [], [])];
|
|
18846
18848
|
const remainingAccounts = [];
|
|
18847
|
-
if (liabilityMintData.tokenProgram.equals(
|
|
18849
|
+
if (liabilityMintData.tokenProgram.equals(TOKEN_2022_PROGRAM_ID)) {
|
|
18848
18850
|
remainingAccounts.push(liabilityMintData.mint);
|
|
18849
18851
|
}
|
|
18850
18852
|
const accountMetas = computeHealthAccountMetas(healthAccounts, bankMetadataMap);
|
|
18851
18853
|
remainingAccounts.push(...accountMetas);
|
|
18852
|
-
ixs.push(
|
|
18854
|
+
ixs.push(ComputeBudgetProgram.setComputeUnitLimit({ units: 14e5 }));
|
|
18853
18855
|
const liquidateIx = await instructions_default.makeLendingAccountLiquidateIx(program, {
|
|
18854
18856
|
assetBank: assetBankAddress,
|
|
18855
18857
|
liabBank: liabilityBankAddress,
|
|
18856
18858
|
liquidatorLendrAccount: this.address,
|
|
18857
18859
|
liquidateeLendrAccount: liquidateeLendrAccount.address,
|
|
18858
18860
|
tokenProgram: liabilityMintData.tokenProgram
|
|
18859
|
-
}, { assetAmount:
|
|
18861
|
+
}, { assetAmount: uiToNative(assetQuantityUi, assetBank.mintDecimals) }, remainingAccounts.map((account) => ({
|
|
18860
18862
|
pubkey: account,
|
|
18861
18863
|
isSigner: false,
|
|
18862
18864
|
isWritable: false
|
|
@@ -18868,7 +18870,7 @@ var LendrAccount = class LendrAccount {
|
|
|
18868
18870
|
};
|
|
18869
18871
|
}
|
|
18870
18872
|
async makeBeginFlashLoanIx(program, endIndex) {
|
|
18871
|
-
const ix = await instructions_default.makeBeginFlashLoanIx(program, { lendrAccount: this.address }, { endIndex: new
|
|
18873
|
+
const ix = await instructions_default.makeBeginFlashLoanIx(program, { lendrAccount: this.address }, { endIndex: new BN$1(endIndex) });
|
|
18872
18874
|
return {
|
|
18873
18875
|
instructions: [ix],
|
|
18874
18876
|
keys: []
|
|
@@ -18923,12 +18925,12 @@ var LendrAccount = class LendrAccount {
|
|
|
18923
18925
|
for (let index = 0; index < instructions$3.length; index++) {
|
|
18924
18926
|
const ix = instructions$3[index];
|
|
18925
18927
|
if (!ix.programId.equals(program.programId)) continue;
|
|
18926
|
-
const borshCoder = new
|
|
18928
|
+
const borshCoder = new BorshInstructionCoder(program.idl);
|
|
18927
18929
|
const decoded = borshCoder.decode(ix.data, "base58");
|
|
18928
18930
|
if (!decoded) continue;
|
|
18929
18931
|
const ixArgs = decoded.data;
|
|
18930
18932
|
if (decoded.name === "lendingAccountBorrow" || decoded.name === "lendingAccountDeposit") {
|
|
18931
|
-
const targetBank = new
|
|
18933
|
+
const targetBank = new PublicKey(ix.keys[3].pubkey);
|
|
18932
18934
|
const targetBalance = projectedBalances.find((b) => b.bankPk.equals(targetBank));
|
|
18933
18935
|
if (!targetBalance) {
|
|
18934
18936
|
const firstInactiveBalanceIndex = projectedBalances.findIndex((b) => !b.active);
|
|
@@ -18941,22 +18943,22 @@ var LendrAccount = class LendrAccount {
|
|
|
18941
18943
|
continue;
|
|
18942
18944
|
}
|
|
18943
18945
|
if (decoded.name === "lendingAccountRepay" || decoded.name === "lendingAccountWithdraw") {
|
|
18944
|
-
const targetBank = new
|
|
18946
|
+
const targetBank = new PublicKey(ix.keys[3].pubkey);
|
|
18945
18947
|
const targetBalance = projectedBalances.find((b) => b.bankPk.equals(targetBank));
|
|
18946
18948
|
if (!targetBalance) {
|
|
18947
18949
|
throw Error(`Balance for bank ${targetBank.toBase58()} should be projected active at this point (ix ${index}: ${decoded.name}))`);
|
|
18948
18950
|
}
|
|
18949
18951
|
if (ixArgs.repayAll || ixArgs.withdrawAll) {
|
|
18950
18952
|
targetBalance.active = false;
|
|
18951
|
-
targetBalance.bankPk =
|
|
18953
|
+
targetBalance.bankPk = PublicKey.default;
|
|
18952
18954
|
}
|
|
18953
18955
|
}
|
|
18954
18956
|
}
|
|
18955
18957
|
return projectedBalances.filter((b) => b.active).map((b) => b.bankPk);
|
|
18956
18958
|
}
|
|
18957
|
-
wrapInstructionForWSol(ix, amount = new
|
|
18959
|
+
wrapInstructionForWSol(ix, amount = new BigNumber(0)) {
|
|
18958
18960
|
return [
|
|
18959
|
-
...makeWrapSolIxs(this.authority, new
|
|
18961
|
+
...makeWrapSolIxs(this.authority, new BigNumber(amount)),
|
|
18960
18962
|
ix,
|
|
18961
18963
|
makeUnwrapSolIx(this.authority)
|
|
18962
18964
|
];
|
|
@@ -19007,7 +19009,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19007
19009
|
}
|
|
19008
19010
|
static async fetch(lendrAccountPk, client, commitment) {
|
|
19009
19011
|
const { config, program } = client;
|
|
19010
|
-
const _lendrAccountPk =
|
|
19012
|
+
const _lendrAccountPk = translateAddress(lendrAccountPk);
|
|
19011
19013
|
const accountData = await LendrAccountWrapper._fetchAccountData(_lendrAccountPk, config, program, commitment);
|
|
19012
19014
|
const lendrAccount = LendrAccount.fromAccountParsed(_lendrAccountPk, accountData);
|
|
19013
19015
|
const lendrAccountProxy = new LendrAccountWrapper(_lendrAccountPk, client, lendrAccount);
|
|
@@ -19016,7 +19018,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19016
19018
|
}
|
|
19017
19019
|
static fromAccountParsed(lendrAccountPk, client, accountData) {
|
|
19018
19020
|
if (!accountData.group.equals(client.config.groupPk)) throw Error(`Lendr account tied to group ${accountData.group.toBase58()}. Expected: ${client.config.groupPk.toBase58()}`);
|
|
19019
|
-
const _lendrAccountPk =
|
|
19021
|
+
const _lendrAccountPk = translateAddress(lendrAccountPk);
|
|
19020
19022
|
const lendrAccount = LendrAccount.fromAccountParsed(_lendrAccountPk, accountData);
|
|
19021
19023
|
return new LendrAccountWrapper(_lendrAccountPk, client, lendrAccount);
|
|
19022
19024
|
}
|
|
@@ -19097,7 +19099,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19097
19099
|
return this._lendrAccount.computeActiveEmodePairs(emodePairs);
|
|
19098
19100
|
}
|
|
19099
19101
|
computeEmodeImpacts(emodePairs) {
|
|
19100
|
-
return this._lendrAccount.computeEmodeImpacts(emodePairs, Array.from(this.client.banks.keys()).map((b) => new
|
|
19102
|
+
return this._lendrAccount.computeEmodeImpacts(emodePairs, Array.from(this.client.banks.keys()).map((b) => new PublicKey(b)));
|
|
19101
19103
|
}
|
|
19102
19104
|
computeMaxBorrowForBank(bankAddress, opts) {
|
|
19103
19105
|
return this._lendrAccount.computeMaxBorrowForBank(this.client.banks, this.client.oraclePrices, bankAddress, opts, this.client.logger);
|
|
@@ -19133,7 +19135,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19133
19135
|
const cuRequestIxs = [];
|
|
19134
19136
|
const activeBalances = this.balances.filter((b) => b.active);
|
|
19135
19137
|
if (activeBalances.length >= 4) {
|
|
19136
|
-
cuRequestIxs.push(
|
|
19138
|
+
cuRequestIxs.push(ComputeBudgetProgram.setComputeUnitLimit({ units: 1e6 }));
|
|
19137
19139
|
}
|
|
19138
19140
|
return cuRequestIxs;
|
|
19139
19141
|
}
|
|
@@ -19147,7 +19149,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19147
19149
|
const bank = this.client.bankMetadataMap[bankAddress.toBase58()];
|
|
19148
19150
|
const mintData = this.client.mintDatas.get(bankAddress.toBase58());
|
|
19149
19151
|
if (!mintData) throw Error(`Token data for ${bank.tokenAddress} not found`);
|
|
19150
|
-
return
|
|
19152
|
+
return getAssociatedTokenAddressSync(new PublicKey(bank.tokenAddress), this.authority, true, mintData.tokenProgram.equals(TOKEN_2022_PROGRAM_ID) ? TOKEN_2022_PROGRAM_ID : undefined);
|
|
19151
19153
|
});
|
|
19152
19154
|
const ixs = [];
|
|
19153
19155
|
const userAtaAis = await this._program.provider.connection.getMultipleAccountsInfo(userAtas);
|
|
@@ -19157,7 +19159,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19157
19159
|
const bank = this.client.bankMetadataMap[bankAddress.toBase58()];
|
|
19158
19160
|
const mintData = this.client.mintDatas.get(bankAddress.toBase58());
|
|
19159
19161
|
if (!mintData) throw Error(`Token data for ${bank.tokenAddress} not found`);
|
|
19160
|
-
ixs.push(
|
|
19162
|
+
ixs.push(createAssociatedTokenAccountIdempotentInstruction(this.authority, userAtas[i], this.authority, new PublicKey(bank.tokenAddress), mintData.tokenProgram.equals(TOKEN_2022_PROGRAM_ID) ? TOKEN_2022_PROGRAM_ID : undefined));
|
|
19161
19163
|
}
|
|
19162
19164
|
}
|
|
19163
19165
|
return ixs;
|
|
@@ -19197,32 +19199,32 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19197
19199
|
const { value: { blockhash } } = await this._program.provider.connection.getLatestBlockhashAndContext("confirmed");
|
|
19198
19200
|
const feedCrankTxs = [];
|
|
19199
19201
|
if (updateFeedIxs.length > 0) {
|
|
19200
|
-
feedCrankTxs.push(
|
|
19202
|
+
feedCrankTxs.push(addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
19201
19203
|
instructions: [...updateFeedIxs],
|
|
19202
19204
|
payerKey: this.authority,
|
|
19203
19205
|
recentBlockhash: blockhash
|
|
19204
19206
|
}).compileToV0Message(feedLuts)), {
|
|
19205
19207
|
addressLookupTables: feedLuts,
|
|
19206
|
-
type:
|
|
19208
|
+
type: TransactionType.CRANK
|
|
19207
19209
|
}));
|
|
19208
19210
|
}
|
|
19209
19211
|
const lookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
19210
|
-
const withdrawTx =
|
|
19212
|
+
const withdrawTx = addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
19211
19213
|
instructions: [...cuRequestIxs, ...withdrawIxs.instructions],
|
|
19212
19214
|
payerKey: this.authority,
|
|
19213
19215
|
recentBlockhash: blockhash
|
|
19214
19216
|
}).compileToV0Message(lookupTables)), {
|
|
19215
19217
|
signers: withdrawIxs.keys,
|
|
19216
19218
|
addressLookupTables: lookupTables,
|
|
19217
|
-
type:
|
|
19219
|
+
type: TransactionType.MOVE_POSITION_WITHDRAW
|
|
19218
19220
|
});
|
|
19219
19221
|
const destinationAccount = await LendrAccountWrapper.fetch(destinationAccountPk, this.client);
|
|
19220
19222
|
const depositIx = await destinationAccount.makeDepositIx(amount, bankAddress);
|
|
19221
|
-
const tx = new
|
|
19222
|
-
const depositTx =
|
|
19223
|
+
const tx = new Transaction().add(...depositIx.instructions);
|
|
19224
|
+
const depositTx = addTransactionMetadata(tx, {
|
|
19223
19225
|
signers: depositIx.keys,
|
|
19224
19226
|
addressLookupTables: lookupTables,
|
|
19225
|
-
type:
|
|
19227
|
+
type: TransactionType.MOVE_POSITION_DEPOSIT
|
|
19226
19228
|
});
|
|
19227
19229
|
const transactions = [
|
|
19228
19230
|
...feedCrankTxs,
|
|
@@ -19287,7 +19289,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19287
19289
|
async makeRepayWithCollatTxV2({ repayAmount, withdrawAmount, borrowBankAddress, depositBankAddress, withdrawAll = false, repayAll = false, swap, blockhash: blockhashArg }) {
|
|
19288
19290
|
const blockhash = blockhashArg ?? (await this._program.provider.connection.getLatestBlockhash("confirmed")).blockhash;
|
|
19289
19291
|
const setupIxs = await this.makeSetupIx([borrowBankAddress, depositBankAddress]);
|
|
19290
|
-
const cuRequestIxs = this.makeComputeBudgetIx().length > 0 ? this.makeComputeBudgetIx() : [
|
|
19292
|
+
const cuRequestIxs = this.makeComputeBudgetIx().length > 0 ? this.makeComputeBudgetIx() : [ComputeBudgetProgram.setComputeUnitLimit({ units: 1e6 })];
|
|
19291
19293
|
const [priorityFeeIx] = makePriorityFeeIx(1e-5);
|
|
19292
19294
|
const withdrawIxs = await this.makeWithdrawIx(withdrawAmount, depositBankAddress, withdrawAll, {
|
|
19293
19295
|
createAtas: false,
|
|
@@ -19300,22 +19302,22 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19300
19302
|
let flashloanTx;
|
|
19301
19303
|
let txOverflown = false;
|
|
19302
19304
|
if (setupIxs.length > 0) {
|
|
19303
|
-
const message = new
|
|
19305
|
+
const message = new TransactionMessage({
|
|
19304
19306
|
payerKey: this.client.wallet.publicKey,
|
|
19305
19307
|
recentBlockhash: blockhash,
|
|
19306
19308
|
instructions: setupIxs
|
|
19307
19309
|
}).compileToLegacyMessage();
|
|
19308
|
-
additionalTxs.push(
|
|
19310
|
+
additionalTxs.push(addTransactionMetadata(new VersionedTransaction(message), { type: TransactionType.CREATE_ATA }));
|
|
19309
19311
|
}
|
|
19310
19312
|
if (updateFeedIxs.length > 0) {
|
|
19311
|
-
const message = new
|
|
19313
|
+
const message = new TransactionMessage({
|
|
19312
19314
|
payerKey: this.client.wallet.publicKey,
|
|
19313
19315
|
recentBlockhash: blockhash,
|
|
19314
19316
|
instructions: updateFeedIxs
|
|
19315
19317
|
}).compileToV0Message(feedLuts);
|
|
19316
|
-
additionalTxs.push(
|
|
19318
|
+
additionalTxs.push(addTransactionMetadata(new VersionedTransaction(message), {
|
|
19317
19319
|
addressLookupTables: feedLuts,
|
|
19318
|
-
type:
|
|
19320
|
+
type: TransactionType.CRANK
|
|
19319
19321
|
}));
|
|
19320
19322
|
}
|
|
19321
19323
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
@@ -19331,11 +19333,11 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19331
19333
|
addressLookupTableAccounts,
|
|
19332
19334
|
blockhash
|
|
19333
19335
|
});
|
|
19334
|
-
const txSize =
|
|
19335
|
-
const accountKeys =
|
|
19336
|
-
const txToManyKeys = accountKeys >
|
|
19337
|
-
const txToBig = txSize >
|
|
19338
|
-
const canBeDownsized = txToManyKeys && txToBig && txSize -
|
|
19336
|
+
const txSize = getTxSize(flashloanTx);
|
|
19337
|
+
const accountKeys = getAccountKeys(flashloanTx, addressLookupTableAccounts);
|
|
19338
|
+
const txToManyKeys = accountKeys > MAX_ACCOUNT_KEYS;
|
|
19339
|
+
const txToBig = txSize > MAX_TX_SIZE;
|
|
19340
|
+
const canBeDownsized = txToManyKeys && txToBig && txSize - PRIORITY_TX_SIZE <= MAX_TX_SIZE;
|
|
19339
19341
|
if (canBeDownsized) {
|
|
19340
19342
|
flashloanTx = await this.buildFlashLoanTx({
|
|
19341
19343
|
ixs: [
|
|
@@ -19347,16 +19349,16 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19347
19349
|
addressLookupTableAccounts,
|
|
19348
19350
|
blockhash
|
|
19349
19351
|
});
|
|
19350
|
-
const txSize$1 =
|
|
19351
|
-
const txToBig$1 = txSize$1 >
|
|
19352
|
+
const txSize$1 = getTxSize(flashloanTx);
|
|
19353
|
+
const txToBig$1 = txSize$1 > MAX_TX_SIZE;
|
|
19352
19354
|
if (txToBig$1) {
|
|
19353
19355
|
txOverflown = true;
|
|
19354
19356
|
}
|
|
19355
19357
|
} else if (txToBig || txToManyKeys) {
|
|
19356
19358
|
txOverflown = true;
|
|
19357
19359
|
}
|
|
19358
|
-
flashloanTx =
|
|
19359
|
-
type:
|
|
19360
|
+
flashloanTx = addTransactionMetadata(flashloanTx, {
|
|
19361
|
+
type: TransactionType.REPAY_COLLAT,
|
|
19360
19362
|
addressLookupTables: flashloanTx.addressLookupTables
|
|
19361
19363
|
});
|
|
19362
19364
|
const transactions = [...additionalTxs, flashloanTx];
|
|
@@ -19394,7 +19396,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19394
19396
|
if (!borrowBank) throw Error("Borrow bank not found");
|
|
19395
19397
|
const blockhash = blockhashArg ?? (await this._program.provider.connection.getLatestBlockhash("confirmed")).blockhash;
|
|
19396
19398
|
const setupIxs = await this.makeSetupIx(setupBankAddresses ?? [borrowBankAddress, depositBankAddress]);
|
|
19397
|
-
const cuRequestIxs = this.makeComputeBudgetIx().length > 0 ? this.makeComputeBudgetIx() : [
|
|
19399
|
+
const cuRequestIxs = this.makeComputeBudgetIx().length > 0 ? this.makeComputeBudgetIx() : [ComputeBudgetProgram.setComputeUnitLimit({ units: 5e5 })];
|
|
19398
19400
|
const [priorityFeeIx] = makePriorityFeeIx(1e-5);
|
|
19399
19401
|
const borrowIxs = await this.makeBorrowIx(borrowAmount, borrowBankAddress, {
|
|
19400
19402
|
createAtas: false,
|
|
@@ -19410,26 +19412,26 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19410
19412
|
const additionalTxs = [];
|
|
19411
19413
|
let flashloanTx;
|
|
19412
19414
|
let txOverflown = false;
|
|
19413
|
-
if (depositBank.mint.equals(
|
|
19414
|
-
setupIxs.push(...makeWrapSolIxs(this.authority, new
|
|
19415
|
+
if (depositBank.mint.equals(NATIVE_MINT) && inputDepositAmount) {
|
|
19416
|
+
setupIxs.push(...makeWrapSolIxs(this.authority, new BigNumber(inputDepositAmount)));
|
|
19415
19417
|
}
|
|
19416
19418
|
if (setupIxs.length > 0) {
|
|
19417
|
-
const message = new
|
|
19419
|
+
const message = new TransactionMessage({
|
|
19418
19420
|
payerKey: this.client.wallet.publicKey,
|
|
19419
19421
|
recentBlockhash: blockhash,
|
|
19420
19422
|
instructions: setupIxs
|
|
19421
19423
|
}).compileToLegacyMessage();
|
|
19422
|
-
additionalTxs.push(
|
|
19424
|
+
additionalTxs.push(addTransactionMetadata(new VersionedTransaction(message), { type: TransactionType.CREATE_ATA }));
|
|
19423
19425
|
}
|
|
19424
19426
|
if (updateFeedIxs.length > 0) {
|
|
19425
|
-
const message = new
|
|
19427
|
+
const message = new TransactionMessage({
|
|
19426
19428
|
payerKey: this.client.wallet.publicKey,
|
|
19427
19429
|
recentBlockhash: blockhash,
|
|
19428
19430
|
instructions: updateFeedIxs
|
|
19429
19431
|
}).compileToV0Message(feedLuts);
|
|
19430
|
-
additionalTxs.push(
|
|
19432
|
+
additionalTxs.push(addTransactionMetadata(new VersionedTransaction(message), {
|
|
19431
19433
|
addressLookupTables: feedLuts,
|
|
19432
|
-
type:
|
|
19434
|
+
type: TransactionType.CRANK
|
|
19433
19435
|
}));
|
|
19434
19436
|
}
|
|
19435
19437
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
@@ -19445,11 +19447,11 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19445
19447
|
addressLookupTableAccounts,
|
|
19446
19448
|
blockhash
|
|
19447
19449
|
});
|
|
19448
|
-
const txSize =
|
|
19449
|
-
const accountKeys =
|
|
19450
|
-
const txToManyKeys = accountKeys >
|
|
19451
|
-
const txToBig = txSize >
|
|
19452
|
-
const canBeDownsized = txToManyKeys && txToBig && txSize -
|
|
19450
|
+
const txSize = getTxSize(flashloanTx);
|
|
19451
|
+
const accountKeys = getAccountKeys(flashloanTx, addressLookupTableAccounts);
|
|
19452
|
+
const txToManyKeys = accountKeys > MAX_ACCOUNT_KEYS;
|
|
19453
|
+
const txToBig = txSize > MAX_TX_SIZE;
|
|
19454
|
+
const canBeDownsized = txToManyKeys && txToBig && txSize - PRIORITY_TX_SIZE <= MAX_TX_SIZE;
|
|
19453
19455
|
if (canBeDownsized) {
|
|
19454
19456
|
flashloanTx = await this.buildFlashLoanTx({
|
|
19455
19457
|
ixs: [
|
|
@@ -19461,16 +19463,16 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19461
19463
|
addressLookupTableAccounts,
|
|
19462
19464
|
blockhash
|
|
19463
19465
|
});
|
|
19464
|
-
const txSize$1 =
|
|
19465
|
-
const txToBig$1 = txSize$1 >
|
|
19466
|
+
const txSize$1 = getTxSize(flashloanTx);
|
|
19467
|
+
const txToBig$1 = txSize$1 > MAX_TX_SIZE;
|
|
19466
19468
|
if (txToBig$1) {
|
|
19467
19469
|
txOverflown = true;
|
|
19468
19470
|
}
|
|
19469
19471
|
} else if (txToBig || txToManyKeys) {
|
|
19470
19472
|
txOverflown = true;
|
|
19471
19473
|
}
|
|
19472
|
-
flashloanTx =
|
|
19473
|
-
type:
|
|
19474
|
+
flashloanTx = addTransactionMetadata(flashloanTx, {
|
|
19475
|
+
type: TransactionType.LOOP,
|
|
19474
19476
|
addressLookupTables: flashloanTx.addressLookupTables
|
|
19475
19477
|
});
|
|
19476
19478
|
const transactions = [...additionalTxs, flashloanTx];
|
|
@@ -19517,12 +19519,12 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19517
19519
|
*/
|
|
19518
19520
|
async makeCloseAccountTx() {
|
|
19519
19521
|
const ix = await this.makeCloseAccountIx();
|
|
19520
|
-
const tx = new
|
|
19522
|
+
const tx = new Transaction().add(...ix.instructions);
|
|
19521
19523
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
19522
|
-
return
|
|
19524
|
+
return addTransactionMetadata(tx, {
|
|
19523
19525
|
signers: ix.keys,
|
|
19524
19526
|
addressLookupTables: clientLookupTables,
|
|
19525
|
-
type:
|
|
19527
|
+
type: TransactionType.CLOSE_ACCOUNT
|
|
19526
19528
|
});
|
|
19527
19529
|
}
|
|
19528
19530
|
/**
|
|
@@ -19558,17 +19560,17 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19558
19560
|
const poolStakeAddress = findPoolStakeAddress(pool);
|
|
19559
19561
|
const lstMint = findPoolMintAddress(pool);
|
|
19560
19562
|
const auth = findPoolStakeAuthorityAddress(pool);
|
|
19561
|
-
const lstAta =
|
|
19563
|
+
const lstAta = getAssociatedTokenAddressSync(lstMint, this.authority);
|
|
19562
19564
|
const [lstAccInfo, stakeAccountInfo, stakeAccInfoParsed] = await Promise.all([
|
|
19563
19565
|
this.client.provider.connection.getAccountInfo(lstAta),
|
|
19564
19566
|
this._program.provider.connection.getAccountInfo(stakeAccountPk),
|
|
19565
19567
|
this._program.provider.connection.getParsedAccountInfo(stakeAccountPk)
|
|
19566
19568
|
]);
|
|
19567
19569
|
const stakeAccParsed = stakeAccInfoParsed?.value?.data;
|
|
19568
|
-
const [rentExemptReserve, minimumDelegation] = await Promise.all([this._program.provider.connection.getMinimumBalanceForRentExemption(
|
|
19569
|
-
return Math.max(res.value,
|
|
19570
|
+
const [rentExemptReserve, minimumDelegation] = await Promise.all([this._program.provider.connection.getMinimumBalanceForRentExemption(StakeProgram.space), this._program.provider.connection.getStakeMinimumDelegation().then((res) => {
|
|
19571
|
+
return Math.max(res.value, LAMPORTS_PER_SOL);
|
|
19570
19572
|
})]);
|
|
19571
|
-
const amountLamports = Math.round(Number(amount) *
|
|
19573
|
+
const amountLamports = Math.round(Number(amount) * LAMPORTS_PER_SOL);
|
|
19572
19574
|
const stakeAccLamports = Number(stakeAccParsed.parsed.info.stake?.delegation?.stake ?? 0);
|
|
19573
19575
|
const isFullStake = amountLamports >= stakeAccLamports;
|
|
19574
19576
|
const poolStakeAccLamports = (await this._program.provider.connection.getAccountInfo(poolStakeAddress))?.lamports ?? 0;
|
|
@@ -19582,14 +19584,14 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19582
19584
|
const instructions$3 = [];
|
|
19583
19585
|
const signers = [];
|
|
19584
19586
|
if (!lstAccInfo) {
|
|
19585
|
-
instructions$3.push(
|
|
19587
|
+
instructions$3.push(createAssociatedTokenAccountInstruction(this.authority, lstAta, this.authority, lstMint));
|
|
19586
19588
|
}
|
|
19587
19589
|
let targetStakePubkey;
|
|
19588
19590
|
if (!isFullStake) {
|
|
19589
|
-
const splitStakeAccount =
|
|
19591
|
+
const splitStakeAccount = Keypair.generate();
|
|
19590
19592
|
signers.push(splitStakeAccount);
|
|
19591
19593
|
targetStakePubkey = splitStakeAccount.publicKey;
|
|
19592
|
-
instructions$3.push(...
|
|
19594
|
+
instructions$3.push(...StakeProgram.split({
|
|
19593
19595
|
stakePubkey: stakeAccountPk,
|
|
19594
19596
|
authorizedPubkey: this.authority,
|
|
19595
19597
|
splitStakePubkey: splitStakeAccount.publicKey,
|
|
@@ -19598,44 +19600,44 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19598
19600
|
} else {
|
|
19599
19601
|
targetStakePubkey = stakeAccountPk;
|
|
19600
19602
|
}
|
|
19601
|
-
const [authorizeStakerIx, authorizeWithdrawIx] = await Promise.all([
|
|
19603
|
+
const [authorizeStakerIx, authorizeWithdrawIx] = await Promise.all([StakeProgram.authorize({
|
|
19602
19604
|
stakePubkey: targetStakePubkey,
|
|
19603
19605
|
authorizedPubkey: this.authority,
|
|
19604
19606
|
newAuthorizedPubkey: auth,
|
|
19605
|
-
stakeAuthorizationType:
|
|
19606
|
-
}).instructions,
|
|
19607
|
+
stakeAuthorizationType: StakeAuthorizationLayout.Staker
|
|
19608
|
+
}).instructions, StakeProgram.authorize({
|
|
19607
19609
|
stakePubkey: targetStakePubkey,
|
|
19608
19610
|
authorizedPubkey: this.authority,
|
|
19609
19611
|
newAuthorizedPubkey: auth,
|
|
19610
|
-
stakeAuthorizationType:
|
|
19612
|
+
stakeAuthorizationType: StakeAuthorizationLayout.Withdrawer
|
|
19611
19613
|
}).instructions]);
|
|
19612
19614
|
[authorizeStakerIx[0], authorizeWithdrawIx[0]].forEach((ix) => {
|
|
19613
19615
|
ix.keys = ix.keys.map((key) => ({
|
|
19614
19616
|
...key,
|
|
19615
|
-
isWritable: key.pubkey.equals(
|
|
19617
|
+
isWritable: key.pubkey.equals(SYSVAR_CLOCK_ID) ? false : key.isWritable
|
|
19616
19618
|
}));
|
|
19617
19619
|
});
|
|
19618
19620
|
instructions$3.push(...authorizeStakerIx, ...authorizeWithdrawIx);
|
|
19619
19621
|
const depositStakeIx = await SinglePoolInstruction.depositStake(pool, targetStakePubkey, lstAta, this.authority);
|
|
19620
19622
|
const lendrDepositIxs = await this.makeDepositIx(newPoolTokens / 1e9, bankAddress, depositOpts);
|
|
19621
19623
|
instructions$3.push(depositStakeIx, ...lendrDepositIxs.instructions);
|
|
19622
|
-
const transaction = new
|
|
19623
|
-
return
|
|
19624
|
-
type:
|
|
19624
|
+
const transaction = new Transaction().add(...instructions$3);
|
|
19625
|
+
return addTransactionMetadata(transaction, {
|
|
19626
|
+
type: TransactionType.DEPOSIT_STAKE,
|
|
19625
19627
|
signers: [...signers, ...lendrDepositIxs.keys],
|
|
19626
19628
|
addressLookupTables: this.client.addressLookupTables
|
|
19627
19629
|
});
|
|
19628
19630
|
}
|
|
19629
19631
|
async makeMergeStakeAccountsTx(stakeAccountSrc, stakeAccountDest) {
|
|
19630
|
-
const mergeInstruction =
|
|
19632
|
+
const mergeInstruction = StakeProgram.merge({
|
|
19631
19633
|
stakePubkey: stakeAccountDest,
|
|
19632
19634
|
sourceStakePubKey: stakeAccountSrc,
|
|
19633
19635
|
authorizedPubkey: this.authority
|
|
19634
19636
|
});
|
|
19635
|
-
const transaction = new
|
|
19637
|
+
const transaction = new Transaction().add(mergeInstruction);
|
|
19636
19638
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
19637
|
-
return
|
|
19638
|
-
type:
|
|
19639
|
+
return addTransactionMetadata(transaction, {
|
|
19640
|
+
type: TransactionType.MERGE_STAKE_ACCOUNTS,
|
|
19639
19641
|
signers: [],
|
|
19640
19642
|
addressLookupTables: clientLookupTables
|
|
19641
19643
|
});
|
|
@@ -19689,10 +19691,10 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19689
19691
|
*/
|
|
19690
19692
|
async makeDepositTx(amount, bankAddress, depositOpts = {}) {
|
|
19691
19693
|
const ixs = await this.makeDepositIx(amount, bankAddress, depositOpts);
|
|
19692
|
-
const tx = new
|
|
19694
|
+
const tx = new Transaction().add(...ixs.instructions);
|
|
19693
19695
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
19694
|
-
const solanaTx =
|
|
19695
|
-
type:
|
|
19696
|
+
const solanaTx = addTransactionMetadata(tx, {
|
|
19697
|
+
type: TransactionType.DEPOSIT,
|
|
19696
19698
|
signers: ixs.keys,
|
|
19697
19699
|
addressLookupTables: clientLookupTables
|
|
19698
19700
|
});
|
|
@@ -19700,10 +19702,10 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19700
19702
|
}
|
|
19701
19703
|
async makeDepositWithSessionTx(amount, bankAddress, sessionKey, depositOpts = {}) {
|
|
19702
19704
|
const ixs = await this.makeDepositWithSessionIx(amount, bankAddress, sessionKey, depositOpts);
|
|
19703
|
-
const tx = new
|
|
19705
|
+
const tx = new Transaction().add(...ixs.instructions);
|
|
19704
19706
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
19705
|
-
const solanaTx =
|
|
19706
|
-
type:
|
|
19707
|
+
const solanaTx = addTransactionMetadata(tx, {
|
|
19708
|
+
type: TransactionType.DEPOSIT,
|
|
19707
19709
|
signers: ixs.keys,
|
|
19708
19710
|
addressLookupTables: clientLookupTables
|
|
19709
19711
|
});
|
|
@@ -19721,11 +19723,11 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19721
19723
|
async simulateBorrowLendTransaction(txs, banksToInspect, healthSimOptions) {
|
|
19722
19724
|
const additionalTxs = [];
|
|
19723
19725
|
if (healthSimOptions?.enabled) {
|
|
19724
|
-
const computeIx =
|
|
19726
|
+
const computeIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 14e5 });
|
|
19725
19727
|
const updateFeedIx = await this.makeUpdateFeedIx(healthSimOptions.mandatoryBanks);
|
|
19726
19728
|
const healthPulseIx = await this.makePulseHealthIx(healthSimOptions.mandatoryBanks, healthSimOptions.excludedBanks);
|
|
19727
19729
|
const blockhash = (await this.client.provider.connection.getLatestBlockhash("confirmed")).blockhash;
|
|
19728
|
-
const tx = new
|
|
19730
|
+
const tx = new VersionedTransaction(new TransactionMessage({
|
|
19729
19731
|
instructions: [
|
|
19730
19732
|
computeIx,
|
|
19731
19733
|
...updateFeedIx.instructions,
|
|
@@ -19859,10 +19861,10 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19859
19861
|
*/
|
|
19860
19862
|
async makeRepayTx(amount, bankAddress, repayAll = false, repayOpts = {}) {
|
|
19861
19863
|
const ixs = await this.makeRepayIx(amount, bankAddress, repayAll, repayOpts);
|
|
19862
|
-
const tx = new
|
|
19864
|
+
const tx = new Transaction().add(...ixs.instructions);
|
|
19863
19865
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
19864
|
-
const solanaTx =
|
|
19865
|
-
type:
|
|
19866
|
+
const solanaTx = addTransactionMetadata(tx, {
|
|
19867
|
+
type: TransactionType.REPAY,
|
|
19866
19868
|
signers: ixs.keys,
|
|
19867
19869
|
addressLookupTables: clientLookupTables
|
|
19868
19870
|
});
|
|
@@ -19879,10 +19881,10 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19879
19881
|
*/
|
|
19880
19882
|
async makeRepayWithSessionTx(amount, bankAddress, sessionKey, repayAll = false, repayOpts = {}) {
|
|
19881
19883
|
const ixs = await this.makeRepayWithSessionIx(amount, bankAddress, sessionKey, repayAll, repayOpts);
|
|
19882
|
-
const tx = new
|
|
19884
|
+
const tx = new Transaction().add(...ixs.instructions);
|
|
19883
19885
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
19884
|
-
const solanaTx =
|
|
19885
|
-
type:
|
|
19886
|
+
const solanaTx = addTransactionMetadata(tx, {
|
|
19887
|
+
type: TransactionType.REPAY,
|
|
19886
19888
|
signers: ixs.keys,
|
|
19887
19889
|
addressLookupTables: clientLookupTables
|
|
19888
19890
|
});
|
|
@@ -19933,7 +19935,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19933
19935
|
*/
|
|
19934
19936
|
async makeWithdrawStakedTx(amount, bankAddress, isWholePosition) {
|
|
19935
19937
|
const bank = this.client.getBankByPk(bankAddress);
|
|
19936
|
-
const solBank = this.client.getBankByMint(
|
|
19938
|
+
const solBank = this.client.getBankByMint(WSOL_MINT);
|
|
19937
19939
|
const bankMetadata = this.client.bankMetadataMap[bankAddress.toBase58()];
|
|
19938
19940
|
if (!bank || !solBank) {
|
|
19939
19941
|
throw new Error("Banks not found");
|
|
@@ -19941,38 +19943,38 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19941
19943
|
if (!bankMetadata.validatorVoteAccount) {
|
|
19942
19944
|
throw new Error("Validator vote account not found");
|
|
19943
19945
|
}
|
|
19944
|
-
const pool = findPoolAddress(new
|
|
19946
|
+
const pool = findPoolAddress(new PublicKey(bankMetadata.validatorVoteAccount));
|
|
19945
19947
|
const lstMint = findPoolMintAddress(pool);
|
|
19946
19948
|
const mintAuthority = findPoolMintAuthorityAddress(pool);
|
|
19947
|
-
const lstAta =
|
|
19949
|
+
const lstAta = getAssociatedTokenAddressSync(lstMint, this.authority);
|
|
19948
19950
|
const rentExemption = await this._program.provider.connection.getMinimumBalanceForRentExemption(200);
|
|
19949
|
-
const stakeAmount = new
|
|
19951
|
+
const stakeAmount = new BigNumber(new BigNumber(amount).toString());
|
|
19950
19952
|
const withdrawIxs = await this.makeWithdrawIx(amount, bankAddress, isWholePosition, {
|
|
19951
19953
|
createAtas: true,
|
|
19952
19954
|
wrapAndUnwrapSol: true
|
|
19953
19955
|
});
|
|
19954
|
-
const stakeAccount =
|
|
19955
|
-
const createStakeAccountIx =
|
|
19956
|
+
const stakeAccount = Keypair.generate();
|
|
19957
|
+
const createStakeAccountIx = SystemProgram.createAccount({
|
|
19956
19958
|
fromPubkey: this.authority,
|
|
19957
19959
|
newAccountPubkey: stakeAccount.publicKey,
|
|
19958
19960
|
lamports: rentExemption,
|
|
19959
19961
|
space: 200,
|
|
19960
|
-
programId:
|
|
19962
|
+
programId: STAKE_PROGRAM_ID
|
|
19961
19963
|
});
|
|
19962
|
-
const approveAccountAuthorityIx =
|
|
19964
|
+
const approveAccountAuthorityIx = createApproveInstruction(lstAta, mintAuthority, this.authority, stakeAmount.multipliedBy(1e9).toNumber(), [], TOKEN_PROGRAM_ID);
|
|
19963
19965
|
const withdrawStakeIx = await SinglePoolInstruction.withdrawStake(pool, stakeAccount.publicKey, this.authority, lstAta, stakeAmount);
|
|
19964
19966
|
const { value: { blockhash } } = await this._program.provider.connection.getLatestBlockhashAndContext("confirmed");
|
|
19965
|
-
const withdrawMessage = new
|
|
19967
|
+
const withdrawMessage = new TransactionMessage({
|
|
19966
19968
|
payerKey: this.client.wallet.publicKey,
|
|
19967
19969
|
recentBlockhash: blockhash,
|
|
19968
19970
|
instructions: [...withdrawIxs.instructions]
|
|
19969
19971
|
}).compileToV0Message(this.client.addressLookupTables);
|
|
19970
|
-
const withdrawTxn =
|
|
19972
|
+
const withdrawTxn = addTransactionMetadata(new VersionedTransaction(withdrawMessage), {
|
|
19971
19973
|
signers: withdrawIxs.keys,
|
|
19972
19974
|
addressLookupTables: this.client.addressLookupTables,
|
|
19973
|
-
type:
|
|
19975
|
+
type: TransactionType.WITHDRAW
|
|
19974
19976
|
});
|
|
19975
|
-
const stakeMessage = new
|
|
19977
|
+
const stakeMessage = new TransactionMessage({
|
|
19976
19978
|
payerKey: this.client.wallet.publicKey,
|
|
19977
19979
|
recentBlockhash: blockhash,
|
|
19978
19980
|
instructions: [
|
|
@@ -19981,10 +19983,10 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19981
19983
|
withdrawStakeIx
|
|
19982
19984
|
]
|
|
19983
19985
|
}).compileToV0Message(this.client.addressLookupTables);
|
|
19984
|
-
const stakeTxn =
|
|
19986
|
+
const stakeTxn = addTransactionMetadata(new VersionedTransaction(stakeMessage), {
|
|
19985
19987
|
signers: [stakeAccount],
|
|
19986
19988
|
addressLookupTables: this.client.addressLookupTables,
|
|
19987
|
-
type:
|
|
19989
|
+
type: TransactionType.WITHDRAW_STAKE
|
|
19988
19990
|
});
|
|
19989
19991
|
return {
|
|
19990
19992
|
transactions: [withdrawTxn, stakeTxn],
|
|
@@ -20020,12 +20022,12 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20020
20022
|
const cuRequestIxs = this.makeComputeBudgetIx();
|
|
20021
20023
|
const withdrawIxs = withdrawIxsWrapped.flatMap((ix) => ix.instructions);
|
|
20022
20024
|
const filteredSigners = withdrawIxsWrapped.flatMap((ix) => ix.keys).filter((key, index, self) => index === self.findIndex((k) => k.publicKey.equals(key.publicKey)));
|
|
20023
|
-
const tx = new
|
|
20025
|
+
const tx = new Transaction().add(...cuRequestIxs, ...withdrawIxs);
|
|
20024
20026
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
20025
|
-
const solanaTx =
|
|
20027
|
+
const solanaTx = addTransactionMetadata(tx, {
|
|
20026
20028
|
signers: filteredSigners,
|
|
20027
20029
|
addressLookupTables: clientLookupTables,
|
|
20028
|
-
type:
|
|
20030
|
+
type: TransactionType.WITHDRAW_ALL
|
|
20029
20031
|
});
|
|
20030
20032
|
return solanaTx;
|
|
20031
20033
|
}
|
|
@@ -20092,24 +20094,24 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20092
20094
|
const { value: { blockhash } } = await this._program.provider.connection.getLatestBlockhashAndContext("confirmed");
|
|
20093
20095
|
const feedCrankTxs = [];
|
|
20094
20096
|
if (updateFeedIxs.length > 0) {
|
|
20095
|
-
feedCrankTxs.push(
|
|
20097
|
+
feedCrankTxs.push(addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
20096
20098
|
instructions: [...updateFeedIxs],
|
|
20097
20099
|
payerKey: this.authority,
|
|
20098
20100
|
recentBlockhash: blockhash
|
|
20099
20101
|
}).compileToV0Message(feedLuts)), {
|
|
20100
20102
|
addressLookupTables: feedLuts,
|
|
20101
|
-
type:
|
|
20103
|
+
type: TransactionType.CRANK
|
|
20102
20104
|
}));
|
|
20103
20105
|
}
|
|
20104
20106
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
20105
|
-
const withdrawTx =
|
|
20107
|
+
const withdrawTx = addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
20106
20108
|
instructions: [...cuRequestIxs, ...withdrawIxs.instructions],
|
|
20107
20109
|
payerKey: this.authority,
|
|
20108
20110
|
recentBlockhash: blockhash
|
|
20109
20111
|
}).compileToV0Message(clientLookupTables)), {
|
|
20110
20112
|
signers: withdrawIxs.keys,
|
|
20111
20113
|
addressLookupTables: clientLookupTables,
|
|
20112
|
-
type:
|
|
20114
|
+
type: TransactionType.WITHDRAW
|
|
20113
20115
|
});
|
|
20114
20116
|
const transactions = [...feedCrankTxs, withdrawTx];
|
|
20115
20117
|
return {
|
|
@@ -20134,24 +20136,24 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20134
20136
|
const { value: { blockhash } } = await this._program.provider.connection.getLatestBlockhashAndContext("confirmed");
|
|
20135
20137
|
const feedCrankTxs = [];
|
|
20136
20138
|
if (updateFeedIxs.length > 0) {
|
|
20137
|
-
feedCrankTxs.push(
|
|
20139
|
+
feedCrankTxs.push(addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
20138
20140
|
instructions: [...updateFeedIxs],
|
|
20139
20141
|
payerKey: this.authority,
|
|
20140
20142
|
recentBlockhash: blockhash
|
|
20141
20143
|
}).compileToV0Message(feedLuts)), {
|
|
20142
20144
|
addressLookupTables: feedLuts,
|
|
20143
|
-
type:
|
|
20145
|
+
type: TransactionType.CRANK
|
|
20144
20146
|
}));
|
|
20145
20147
|
}
|
|
20146
20148
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
20147
|
-
const withdrawTx =
|
|
20149
|
+
const withdrawTx = addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
20148
20150
|
instructions: [...cuRequestIxs, ...withdrawIxs.instructions],
|
|
20149
20151
|
payerKey: this.authority,
|
|
20150
20152
|
recentBlockhash: blockhash
|
|
20151
20153
|
}).compileToV0Message(clientLookupTables)), {
|
|
20152
20154
|
signers: withdrawIxs.keys,
|
|
20153
20155
|
addressLookupTables: clientLookupTables,
|
|
20154
|
-
type:
|
|
20156
|
+
type: TransactionType.WITHDRAW
|
|
20155
20157
|
});
|
|
20156
20158
|
const transactions = [...feedCrankTxs, withdrawTx];
|
|
20157
20159
|
return {
|
|
@@ -20254,23 +20256,23 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20254
20256
|
const { value: { blockhash } } = await this._program.provider.connection.getLatestBlockhashAndContext("confirmed");
|
|
20255
20257
|
const feedCrankTxs = [];
|
|
20256
20258
|
if (updateFeedIxs.length > 0) {
|
|
20257
|
-
feedCrankTxs.push(
|
|
20259
|
+
feedCrankTxs.push(addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
20258
20260
|
instructions: updateFeedIxs,
|
|
20259
20261
|
payerKey: this.authority,
|
|
20260
20262
|
recentBlockhash: blockhash
|
|
20261
20263
|
}).compileToV0Message(feedLuts)), {
|
|
20262
|
-
type:
|
|
20264
|
+
type: TransactionType.CRANK,
|
|
20263
20265
|
addressLookupTables: feedLuts
|
|
20264
20266
|
}));
|
|
20265
20267
|
}
|
|
20266
20268
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
20267
|
-
const borrowTx =
|
|
20269
|
+
const borrowTx = addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
20268
20270
|
instructions: [...cuRequestIxs, ...borrowIxs.instructions],
|
|
20269
20271
|
payerKey: this.authority,
|
|
20270
20272
|
recentBlockhash: blockhash
|
|
20271
20273
|
}).compileToV0Message(clientLookupTables)), {
|
|
20272
20274
|
signers: borrowIxs.keys,
|
|
20273
|
-
type:
|
|
20275
|
+
type: TransactionType.BORROW,
|
|
20274
20276
|
addressLookupTables: clientLookupTables
|
|
20275
20277
|
});
|
|
20276
20278
|
const transactions = [...feedCrankTxs, borrowTx];
|
|
@@ -20295,23 +20297,23 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20295
20297
|
const { value: { blockhash } } = await this._program.provider.connection.getLatestBlockhashAndContext("confirmed");
|
|
20296
20298
|
const feedCrankTxs = [];
|
|
20297
20299
|
if (updateFeedIxs.length > 0) {
|
|
20298
|
-
feedCrankTxs.push(
|
|
20300
|
+
feedCrankTxs.push(addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
20299
20301
|
instructions: updateFeedIxs,
|
|
20300
20302
|
payerKey: this.authority,
|
|
20301
20303
|
recentBlockhash: blockhash
|
|
20302
20304
|
}).compileToV0Message(feedLuts)), {
|
|
20303
|
-
type:
|
|
20305
|
+
type: TransactionType.CRANK,
|
|
20304
20306
|
addressLookupTables: feedLuts
|
|
20305
20307
|
}));
|
|
20306
20308
|
}
|
|
20307
20309
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
20308
|
-
const borrowTx =
|
|
20310
|
+
const borrowTx = addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
20309
20311
|
instructions: [...cuRequestIxs, ...borrowIxs.instructions],
|
|
20310
20312
|
payerKey: this.authority,
|
|
20311
20313
|
recentBlockhash: blockhash
|
|
20312
20314
|
}).compileToV0Message(clientLookupTables)), {
|
|
20313
20315
|
signers: borrowIxs.keys,
|
|
20314
|
-
type:
|
|
20316
|
+
type: TransactionType.BORROW,
|
|
20315
20317
|
addressLookupTables: clientLookupTables
|
|
20316
20318
|
});
|
|
20317
20319
|
const transactions = [...feedCrankTxs, borrowTx];
|
|
@@ -20349,13 +20351,13 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20349
20351
|
withdrawEmissionsIxs.push(ix);
|
|
20350
20352
|
}));
|
|
20351
20353
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
20352
|
-
const emissionsTx =
|
|
20354
|
+
const emissionsTx = addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
20353
20355
|
instructions: withdrawEmissionsIxs.flatMap((ix) => ix.instructions),
|
|
20354
20356
|
payerKey: this.authority,
|
|
20355
20357
|
recentBlockhash: blockhash
|
|
20356
20358
|
}).compileToV0Message(clientLookupTables)), {
|
|
20357
20359
|
signers: withdrawEmissionsIxs.flatMap((ix) => ix.keys),
|
|
20358
|
-
type:
|
|
20360
|
+
type: TransactionType.WITHDRAW_EMISSIONS,
|
|
20359
20361
|
addressLookupTables: clientLookupTables
|
|
20360
20362
|
});
|
|
20361
20363
|
return emissionsTx;
|
|
@@ -20413,12 +20415,12 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20413
20415
|
liquidateeLendrAccount: liquidateeLendrAccount.address.toBase58()
|
|
20414
20416
|
}, "[lendr:lendr-account:liquidation] Liquidating lendr account");
|
|
20415
20417
|
const liquidationIxs = await this.makeLendingAccountLiquidateIx(liquidateeLendrAccount, assetBankAddress, assetQuantityUi, liabBankAddress);
|
|
20416
|
-
const tx = new
|
|
20418
|
+
const tx = new Transaction().add(...liquidationIxs.instructions);
|
|
20417
20419
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
20418
|
-
const solanaTx =
|
|
20420
|
+
const solanaTx = addTransactionMetadata(tx, {
|
|
20419
20421
|
signers: liquidationIxs.keys,
|
|
20420
20422
|
addressLookupTables: clientLookupTables,
|
|
20421
|
-
type:
|
|
20423
|
+
type: TransactionType.LIQUIDATE_ACCOUNT
|
|
20422
20424
|
});
|
|
20423
20425
|
const sig = await this.client.processTransaction(solanaTx, processOpts, txOpts);
|
|
20424
20426
|
this.client.logger.debug({
|
|
@@ -20468,14 +20470,14 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20468
20470
|
];
|
|
20469
20471
|
const totalLookupTables = [...lookupTables ?? [], ...args.addressLookupTableAccounts ?? []];
|
|
20470
20472
|
const blockhash = args.blockhash ?? (await this._program.provider.connection.getLatestBlockhash("confirmed")).blockhash;
|
|
20471
|
-
const message = new
|
|
20473
|
+
const message = new TransactionMessage({
|
|
20472
20474
|
payerKey: this.client.wallet.publicKey,
|
|
20473
20475
|
recentBlockhash: blockhash,
|
|
20474
20476
|
instructions: flashloanIxs
|
|
20475
20477
|
}).compileToV0Message(totalLookupTables);
|
|
20476
|
-
const tx =
|
|
20478
|
+
const tx = addTransactionMetadata(new VersionedTransaction(message), {
|
|
20477
20479
|
addressLookupTables: totalLookupTables,
|
|
20478
|
-
type:
|
|
20480
|
+
type: TransactionType.FLASHLOAN
|
|
20479
20481
|
});
|
|
20480
20482
|
if (args.signers) {
|
|
20481
20483
|
tx.sign(args.signers);
|
|
@@ -20491,8 +20493,8 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20491
20493
|
to: newAccountAuthority.toBase58()
|
|
20492
20494
|
}, "[lendr:lendr-account:transfer-authority] Transferring account");
|
|
20493
20495
|
const ixs = await this.makeTransferAccountAuthorityIx(newAccountAuthority);
|
|
20494
|
-
const tx = new
|
|
20495
|
-
const solanaTx =
|
|
20496
|
+
const tx = new Transaction().add(...ixs.instructions);
|
|
20497
|
+
const solanaTx = addTransactionMetadata(tx, { type: TransactionType.TRANSFER_AUTH });
|
|
20496
20498
|
const sig = await this.client.processTransaction(solanaTx, processOpts, txOpts);
|
|
20497
20499
|
this.client.logger.debug({ sig }, "[lendr:lendr-account:transfer-authority] Transfer successful");
|
|
20498
20500
|
return sig;
|
|
@@ -20510,13 +20512,13 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20510
20512
|
return this._lendrAccount.makePulseHealthIx(this._program, this.client.banks, mandatoryBanks, excludedBanks, this.client.bankMetadataMap || {});
|
|
20511
20513
|
}
|
|
20512
20514
|
static async _fetchAccountData(accountAddress, config, program, commitment) {
|
|
20513
|
-
const mergedCommitment = commitment ?? program.provider.connection.commitment ??
|
|
20515
|
+
const mergedCommitment = commitment ?? program.provider.connection.commitment ?? DEFAULT_COMMITMENT;
|
|
20514
20516
|
const data = await program.account.lendrAccount.fetch(accountAddress, mergedCommitment);
|
|
20515
20517
|
if (!data.group.equals(config.groupPk)) throw Error(`Lendr account tied to group ${data.group.toBase58()}. Expected: ${config.groupPk.toBase58()}`);
|
|
20516
20518
|
return data;
|
|
20517
20519
|
}
|
|
20518
20520
|
static async encode(decoded, idl) {
|
|
20519
|
-
const coder = new
|
|
20521
|
+
const coder = new BorshCoder(idl);
|
|
20520
20522
|
return await coder.accounts.encode(AccountType.LendrAccount, decoded);
|
|
20521
20523
|
}
|
|
20522
20524
|
async reload() {
|
|
@@ -20538,7 +20540,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20538
20540
|
*/
|
|
20539
20541
|
async simulateDeposit(amount, bankAddress) {
|
|
20540
20542
|
const ixs = await this.makeDepositIx(amount, bankAddress);
|
|
20541
|
-
const tx = new
|
|
20543
|
+
const tx = new Transaction().add(...ixs.instructions);
|
|
20542
20544
|
try {
|
|
20543
20545
|
return this.simulateBorrowLendTransaction([tx], [bankAddress]);
|
|
20544
20546
|
} catch (e) {
|
|
@@ -20570,7 +20572,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20570
20572
|
*/
|
|
20571
20573
|
async simulateRepay(amount, bankAddress, repayAll = false) {
|
|
20572
20574
|
const ixs = await this.makeRepayIx(amount, bankAddress, repayAll);
|
|
20573
|
-
const tx = new
|
|
20575
|
+
const tx = new Transaction().add(...ixs.instructions);
|
|
20574
20576
|
try {
|
|
20575
20577
|
return this.simulateBorrowLendTransaction([tx], [bankAddress]);
|
|
20576
20578
|
} catch (e) {
|
|
@@ -20585,7 +20587,7 @@ function makeTxPriorityIx(feePayer, feeUi = 0, broadcastType = "BUNDLE", compute
|
|
|
20585
20587
|
let bundleTipIx;
|
|
20586
20588
|
let priorityFeeIx = makePriorityFeeIx()[0];
|
|
20587
20589
|
if (broadcastType === "BUNDLE") {
|
|
20588
|
-
bundleTipIx = makeBundleTipIx(feePayer, Math.trunc(feeUi *
|
|
20590
|
+
bundleTipIx = makeBundleTipIx(feePayer, Math.trunc(feeUi * LAMPORTS_PER_SOL));
|
|
20589
20591
|
} else {
|
|
20590
20592
|
priorityFeeIx = makePriorityFeeIx(feeUi, computeUnitsLimit)[0];
|
|
20591
20593
|
}
|
|
@@ -20620,9 +20622,9 @@ function makeBundleTipIx(feePayer, bundleTip = 1e5) {
|
|
|
20620
20622
|
"3AVi9Tg9Uo68tJfuvoKvqKNWKkC5wPdSSdeBnizKZ6jT"
|
|
20621
20623
|
];
|
|
20622
20624
|
const randomTipAccount = tipAccounts[Math.floor(Math.random() * tipAccounts.length)];
|
|
20623
|
-
return
|
|
20625
|
+
return SystemProgram.transfer({
|
|
20624
20626
|
fromPubkey: feePayer,
|
|
20625
|
-
toPubkey: new
|
|
20627
|
+
toPubkey: new PublicKey(randomTipAccount),
|
|
20626
20628
|
lamports: bundleTip
|
|
20627
20629
|
});
|
|
20628
20630
|
}
|
|
@@ -20656,11 +20658,11 @@ var LendrGroup = class LendrGroup {
|
|
|
20656
20658
|
return LendrGroup.fromAccountParsed(address$2, data);
|
|
20657
20659
|
}
|
|
20658
20660
|
static decode(encoded, idl) {
|
|
20659
|
-
const coder = new
|
|
20661
|
+
const coder = new BorshCoder(idl);
|
|
20660
20662
|
return coder.accounts.decode(AccountType.LendrGroup, encoded);
|
|
20661
20663
|
}
|
|
20662
20664
|
static async encode(decoded, idl) {
|
|
20663
|
-
const coder = new
|
|
20665
|
+
const coder = new BorshCoder(idl);
|
|
20664
20666
|
return await coder.accounts.encode(AccountType.LendrGroup, decoded);
|
|
20665
20667
|
}
|
|
20666
20668
|
async makeEnableFlashLoanForAccountIx(program, lendrAccountAddress) {
|
|
@@ -20730,7 +20732,7 @@ var LendrClient = class LendrClient {
|
|
|
20730
20732
|
this.bankMetadataMap = bankMetadataMap;
|
|
20731
20733
|
this.overrideBankAddresses = overrideBankAddresses;
|
|
20732
20734
|
this.overrideBanksMetadata = overrideBanksMetadata;
|
|
20733
|
-
this.storage = storage ??
|
|
20735
|
+
this.storage = storage ?? createStorage();
|
|
20734
20736
|
this.metadataService = metadataService;
|
|
20735
20737
|
this.dataFetcher = dataFetcher ?? new DataFetcher();
|
|
20736
20738
|
}
|
|
@@ -20746,7 +20748,7 @@ var LendrClient = class LendrClient {
|
|
|
20746
20748
|
* @returns LendrClient instance
|
|
20747
20749
|
*/
|
|
20748
20750
|
static async fetch({ wallet, connection, clientOptions = {}, config = getConfig() }) {
|
|
20749
|
-
const { logger = new NoopLogger(), confirmOpts = {}, readOnly = false, storage =
|
|
20751
|
+
const { logger = new NoopLogger(), confirmOpts = {}, readOnly = false, storage = createStorage(), dataFetcher = new DataFetcher(), overrideBankAddresses, overrideBanksMetadata, metadataService = new FogoMetadataService(storage, overrideBanksMetadata), addressLookupTableAddresses } = clientOptions;
|
|
20750
20752
|
logger.debug({
|
|
20751
20753
|
programId: config.programId.toBase58(),
|
|
20752
20754
|
env: config.environment,
|
|
@@ -20754,16 +20756,16 @@ var LendrClient = class LendrClient {
|
|
|
20754
20756
|
url: connection?.rpcEndpoint
|
|
20755
20757
|
}, "[lendr:client] Loading Lendr Client");
|
|
20756
20758
|
const programIdl = fetchLatestIdl();
|
|
20757
|
-
const provider = new
|
|
20758
|
-
...
|
|
20759
|
-
commitment: connection.commitment ??
|
|
20759
|
+
const provider = new AnchorProvider(connection, wallet, {
|
|
20760
|
+
...AnchorProvider.defaultOptions(),
|
|
20761
|
+
commitment: connection.commitment ?? AnchorProvider.defaultOptions().commitment,
|
|
20760
20762
|
...confirmOpts
|
|
20761
20763
|
});
|
|
20762
20764
|
const idl = {
|
|
20763
20765
|
...programIdl,
|
|
20764
20766
|
address: config.programId.toBase58()
|
|
20765
20767
|
};
|
|
20766
|
-
const program = new
|
|
20768
|
+
const program = new Program(idl, provider);
|
|
20767
20769
|
const { lendrGroup, banks, priceInfos, tokensData, feedIdMap, banksExtendedMetadata } = await LendrClient.fetchGroupData({
|
|
20768
20770
|
connection,
|
|
20769
20771
|
program,
|
|
@@ -20841,12 +20843,12 @@ var LendrClient = class LendrClient {
|
|
|
20841
20843
|
const oracleKeys = [];
|
|
20842
20844
|
for (const bank of banksRawData) {
|
|
20843
20845
|
mintKeys.push(bank.data.mint);
|
|
20844
|
-
if (!bank.data.emissionsMint.equals(
|
|
20846
|
+
if (!bank.data.emissionsMint.equals(PublicKey.default)) {
|
|
20845
20847
|
emissionMintKeys.push(bank.data.emissionsMint);
|
|
20846
20848
|
}
|
|
20847
20849
|
oracleKeys.push(findOracleKey(BankConfig.fromAccountParsed(bank.data.config), feedIdMap).oracleKey);
|
|
20848
20850
|
}
|
|
20849
|
-
const allAccountInfos = await
|
|
20851
|
+
const allAccountInfos = await chunkedGetRawMultipleAccountInfoOrdered(program.provider.connection, [
|
|
20850
20852
|
groupAddress.toBase58(),
|
|
20851
20853
|
...oracleKeys.map((pk) => pk.toBase58()),
|
|
20852
20854
|
...mintKeys.map((pk) => pk.toBase58()),
|
|
@@ -20860,7 +20862,7 @@ var LendrClient = class LendrClient {
|
|
|
20860
20862
|
const mintAccountInfos = allAccountInfos.splice(0, mintKeys.length);
|
|
20861
20863
|
const emissionMintAccountInfos = allAccountInfos.splice(0);
|
|
20862
20864
|
const lendrGroup = LendrGroup.fromBuffer(groupAddress, groupAccountInfo.data, program.idl);
|
|
20863
|
-
const banksExtendedMetadata = await
|
|
20865
|
+
const banksExtendedMetadata = await fetchBanksExtendedMetadata({
|
|
20864
20866
|
mintsWithOwner: mintKeys.map((mint, idx) => ({
|
|
20865
20867
|
mint,
|
|
20866
20868
|
owner: mintAccountInfos[idx].owner
|
|
@@ -20890,7 +20892,7 @@ var LendrClient = class LendrClient {
|
|
|
20890
20892
|
const bank = Bank.fromAccountParsed(address$2, data, feedIdMap, metadata$2, mintDataRaw.owner);
|
|
20891
20893
|
banks.set(bankAddressStr, bank);
|
|
20892
20894
|
let emissionTokenProgram = null;
|
|
20893
|
-
if (!data.emissionsMint.equals(
|
|
20895
|
+
if (!data.emissionsMint.equals(PublicKey.default)) {
|
|
20894
20896
|
const emissionMintDataRawIndex = emissionMintKeys.findIndex((pk) => pk.equals(data.emissionsMint));
|
|
20895
20897
|
emissionTokenProgram = emissionMintDataRawIndex >= 0 ? emissionMintAccountInfos[emissionMintDataRawIndex].owner : null;
|
|
20896
20898
|
}
|
|
@@ -20903,11 +20905,11 @@ var LendrClient = class LendrClient {
|
|
|
20903
20905
|
const oracleSetup = parseOracleSetup(data.config.oracleSetup);
|
|
20904
20906
|
priceInfos.set(bankAddressStr, parseOraclePriceData(oracleSetup, priceDataRaw.data, logger));
|
|
20905
20907
|
if (oracleSetup === OracleSetup.StakedWithPythPush && metadata$2?.validatorVoteAccount) {
|
|
20906
|
-
const [poolAddress] =
|
|
20907
|
-
const [stakePoolAddress] =
|
|
20908
|
+
const [poolAddress] = PublicKey.findProgramAddressSync([Buffer.from("pool"), new PublicKey(metadata$2.validatorVoteAccount).toBuffer()], SINGLE_POOL_PROGRAM_ID);
|
|
20909
|
+
const [stakePoolAddress] = PublicKey.findProgramAddressSync([Buffer.from("stake"), poolAddress.toBuffer()], SINGLE_POOL_PROGRAM_ID);
|
|
20908
20910
|
stakedCollatMap[address$2.toBase58()] = {
|
|
20909
20911
|
bankAddress: address$2,
|
|
20910
|
-
mint: new
|
|
20912
|
+
mint: new PublicKey(metadata$2.mint),
|
|
20911
20913
|
stakePoolAddress,
|
|
20912
20914
|
poolAddress
|
|
20913
20915
|
};
|
|
@@ -20915,9 +20917,9 @@ var LendrClient = class LendrClient {
|
|
|
20915
20917
|
mints.push(metadata$2.mint);
|
|
20916
20918
|
}
|
|
20917
20919
|
});
|
|
20918
|
-
const dataAis = await
|
|
20920
|
+
const dataAis = await chunkedGetRawMultipleAccountInfoOrdered(program.provider.connection, [...mints, ...solPools]);
|
|
20919
20921
|
const stakePoolsAis = dataAis.slice(mints.length).map((ai) => getStakeAccount(ai.data));
|
|
20920
|
-
const lstMintsAis = dataAis.slice(0, mints.length).map((mintAi) =>
|
|
20922
|
+
const lstMintsAis = dataAis.slice(0, mints.length).map((mintAi) => MintLayout.decode(mintAi.data));
|
|
20921
20923
|
const lstMintRecord = Object.fromEntries(mints.map((mint, i) => [mint, lstMintsAis[i]]));
|
|
20922
20924
|
const solPoolsRecord = Object.fromEntries(solPools.map((poolKey, i) => [poolKey, stakePoolsAis[i]]));
|
|
20923
20925
|
for (const index in stakedCollatMap) {
|
|
@@ -20928,7 +20930,7 @@ var LendrClient = class LendrClient {
|
|
|
20928
20930
|
const oracle = priceInfos.get(bankAddress.toBase58());
|
|
20929
20931
|
if (oracle) {
|
|
20930
20932
|
const adjustPrice = (price, stakeActual$1, tokenSupply$1) => {
|
|
20931
|
-
return Number(tokenSupply$1) === 0 ? price : new
|
|
20933
|
+
return Number(tokenSupply$1) === 0 ? price : new BigNumber(price.toNumber() * (stakeActual$1 - LAMPORTS_PER_SOL) / Number(tokenSupply$1));
|
|
20932
20934
|
};
|
|
20933
20935
|
const adjustPriceComponent$1 = (priceComponent, stakeActual$1, tokenSupply$1) => ({
|
|
20934
20936
|
price: adjustPrice(priceComponent.price, stakeActual$1, tokenSupply$1),
|
|
@@ -21040,7 +21042,7 @@ var LendrClient = class LendrClient {
|
|
|
21040
21042
|
offset: 8
|
|
21041
21043
|
} }, { memcmp: {
|
|
21042
21044
|
offset: 0,
|
|
21043
|
-
bytes: bs58.
|
|
21045
|
+
bytes: bs58.encode(new BorshAccountsCoder(this.program.idl).accountDiscriminator(AccountType.LendrAccount))
|
|
21044
21046
|
} }]
|
|
21045
21047
|
})).map((a) => a.pubkey);
|
|
21046
21048
|
}
|
|
@@ -21050,7 +21052,7 @@ var LendrClient = class LendrClient {
|
|
|
21050
21052
|
* @returns LendrAccount instances
|
|
21051
21053
|
*/
|
|
21052
21054
|
async getLendrAccountsForAuthority(authority) {
|
|
21053
|
-
const _authority = authority ?
|
|
21055
|
+
const _authority = authority ? translateAddress(authority) : this.provider.wallet.publicKey;
|
|
21054
21056
|
const lendrAccounts = (await this.program.account.lendrAccount.all([{ memcmp: {
|
|
21055
21057
|
bytes: this.groupAddress.toBase58(),
|
|
21056
21058
|
offset: 8
|
|
@@ -21080,16 +21082,16 @@ var LendrClient = class LendrClient {
|
|
|
21080
21082
|
},
|
|
21081
21083
|
filters: [{ memcmp: {
|
|
21082
21084
|
offset: 0,
|
|
21083
|
-
bytes: bs58.
|
|
21085
|
+
bytes: bs58.encode(new BorshAccountsCoder(this.program.idl).accountDiscriminator(AccountType.LendrAccount))
|
|
21084
21086
|
} }]
|
|
21085
21087
|
})).map((a) => a.pubkey);
|
|
21086
21088
|
}
|
|
21087
21089
|
getBankByPk(bankAddress) {
|
|
21088
|
-
const _bankAddress =
|
|
21090
|
+
const _bankAddress = translateAddress(bankAddress);
|
|
21089
21091
|
return this.banks.get(_bankAddress.toString()) ?? null;
|
|
21090
21092
|
}
|
|
21091
21093
|
getBankByMint(mint) {
|
|
21092
|
-
const _mint =
|
|
21094
|
+
const _mint = translateAddress(mint);
|
|
21093
21095
|
return [...this.banks.values()].find((bank) => bank.mint.equals(_mint)) ?? null;
|
|
21094
21096
|
}
|
|
21095
21097
|
getBankByTokenSymbol(tokenSymbol) {
|
|
@@ -21097,7 +21099,7 @@ var LendrClient = class LendrClient {
|
|
|
21097
21099
|
return [...this.banks.values()].find((bank) => bank.tokenSymbol === tokenSymbol) ?? null;
|
|
21098
21100
|
}
|
|
21099
21101
|
getOraclePriceByBank(bankAddress) {
|
|
21100
|
-
const _bankAddress =
|
|
21102
|
+
const _bankAddress = translateAddress(bankAddress);
|
|
21101
21103
|
return this.oraclePrices.get(_bankAddress.toString()) ?? null;
|
|
21102
21104
|
}
|
|
21103
21105
|
/**
|
|
@@ -21142,7 +21144,7 @@ var LendrClient = class LendrClient {
|
|
|
21142
21144
|
* @returns Object containing the transaction signature and the created LendrAccount instance
|
|
21143
21145
|
*/
|
|
21144
21146
|
async createLendrAccount(createOpts, processOpts, txOpts) {
|
|
21145
|
-
const accountKeypair =
|
|
21147
|
+
const accountKeypair = Keypair.generate();
|
|
21146
21148
|
const newAccountKey = createOpts?.newAccountKey ?? accountKeypair.publicKey;
|
|
21147
21149
|
const solanaTx = await this.createLendrAccountTx({ accountKeypair });
|
|
21148
21150
|
const sig = await this.processTransaction(solanaTx, processOpts, txOpts);
|
|
@@ -21159,11 +21161,11 @@ var LendrClient = class LendrClient {
|
|
|
21159
21161
|
* @returns Object containing the transaction signature and the created LendrAccount instance
|
|
21160
21162
|
*/
|
|
21161
21163
|
async createLendrAccountWithSession(session, commitment, customAccountSeed) {
|
|
21162
|
-
const accountSeed = new
|
|
21163
|
-
const tx = await this.createLendrAccountWithSessionTx(session, new
|
|
21164
|
+
const accountSeed = new BN$1(customAccountSeed ?? 0);
|
|
21165
|
+
const tx = await this.createLendrAccountWithSessionTx(session, new BN$1(accountSeed ?? 0));
|
|
21164
21166
|
const txResult = await session.sendTransaction(tx);
|
|
21165
21167
|
this.logger.debug({ txResult }, "Created Lendr account (using session)");
|
|
21166
|
-
const [accountPublicKey] =
|
|
21168
|
+
const [accountPublicKey] = PublicKey.findProgramAddressSync([
|
|
21167
21169
|
Buffer.from("pyroners"),
|
|
21168
21170
|
session.walletPublicKey.toBuffer(),
|
|
21169
21171
|
this.groupAddress.toBuffer(),
|
|
@@ -21192,15 +21194,15 @@ var LendrClient = class LendrClient {
|
|
|
21192
21194
|
* @returns Transaction that can be used to create a new lendr account
|
|
21193
21195
|
*/
|
|
21194
21196
|
async createLendrAccountTx(createOpts) {
|
|
21195
|
-
const accountKeypair = createOpts?.accountKeypair ??
|
|
21197
|
+
const accountKeypair = createOpts?.accountKeypair ?? Keypair.generate();
|
|
21196
21198
|
const ixs = await this.makeCreateLendrAccountIx(accountKeypair.publicKey);
|
|
21197
21199
|
const signers = [...ixs.keys];
|
|
21198
21200
|
signers.push(accountKeypair);
|
|
21199
|
-
const tx = new
|
|
21200
|
-
const solanaTx =
|
|
21201
|
+
const tx = new Transaction().add(...ixs.instructions);
|
|
21202
|
+
const solanaTx = addTransactionMetadata(tx, {
|
|
21201
21203
|
signers,
|
|
21202
21204
|
addressLookupTables: this.addressLookupTables,
|
|
21203
|
-
type:
|
|
21205
|
+
type: TransactionType.CREATE_ACCOUNT
|
|
21204
21206
|
});
|
|
21205
21207
|
return solanaTx;
|
|
21206
21208
|
}
|
|
@@ -21208,29 +21210,29 @@ var LendrClient = class LendrClient {
|
|
|
21208
21210
|
try {
|
|
21209
21211
|
return (await this.provider.connection.getLatestBlockhashAndContext("confirmed")).value.blockhash;
|
|
21210
21212
|
} catch (ex) {
|
|
21211
|
-
const connection = new
|
|
21213
|
+
const connection = new Connection(this.provider.connection.rpcEndpoint, this.provider.opts);
|
|
21212
21214
|
return (await connection.getLatestBlockhashAndContext("confirmed")).value.blockhash;
|
|
21213
21215
|
}
|
|
21214
21216
|
}
|
|
21215
21217
|
async createVersionTransaction(instructions$3, payerKey, signers, extraMetaData) {
|
|
21216
21218
|
const blockhash = await this.getLatestBlockHashForSure();
|
|
21217
|
-
const versionedMessage = new
|
|
21219
|
+
const versionedMessage = new TransactionMessage({
|
|
21218
21220
|
instructions: instructions$3,
|
|
21219
21221
|
payerKey,
|
|
21220
21222
|
recentBlockhash: blockhash
|
|
21221
21223
|
});
|
|
21222
|
-
const tx = new
|
|
21224
|
+
const tx = new VersionedTransaction(this.addressLookupTables ? versionedMessage.compileToV0Message(this.addressLookupTables) : versionedMessage.compileToLegacyMessage());
|
|
21223
21225
|
if (signers?.length) {
|
|
21224
21226
|
tx.sign(signers);
|
|
21225
21227
|
}
|
|
21226
21228
|
if (extraMetaData && Object.keys(extraMetaData)?.length) {
|
|
21227
|
-
return
|
|
21229
|
+
return addTransactionMetadata(tx, extraMetaData);
|
|
21228
21230
|
}
|
|
21229
21231
|
return tx;
|
|
21230
21232
|
}
|
|
21231
21233
|
async createLendrAccountWithSessionTx(session, accountSeed) {
|
|
21232
21234
|
const ixs = await this.makeCreateLendrAccountWithSessionIx(session, accountSeed);
|
|
21233
|
-
return this.createVersionTransaction(ixs.instructions, session.payer, [...ixs.keys], { type:
|
|
21235
|
+
return this.createVersionTransaction(ixs.instructions, session.payer, [...ixs.keys], { type: TransactionType.CREATE_ACCOUNT });
|
|
21234
21236
|
}
|
|
21235
21237
|
/**
|
|
21236
21238
|
* Create transaction instruction to initialize a new group.
|
|
@@ -21263,14 +21265,14 @@ var LendrClient = class LendrClient {
|
|
|
21263
21265
|
* @returns {Promise<TransactionSignature>} A promise that resolves to the transaction signature as a string.
|
|
21264
21266
|
*/
|
|
21265
21267
|
async createPermissionlessBank({ mint, bankConfig, group, admin, seed, txOpts, processOpts }) {
|
|
21266
|
-
const keypair = seed ??
|
|
21268
|
+
const keypair = seed ?? Keypair.generate();
|
|
21267
21269
|
const bankIxs = await this.group.makePoolAddBankIx(this.program, keypair.publicKey, mint, bankConfig, admin);
|
|
21268
21270
|
const signers = [...bankIxs.keys, keypair];
|
|
21269
|
-
const tx = new
|
|
21270
|
-
const solanaTx =
|
|
21271
|
+
const tx = new Transaction().add(...bankIxs.instructions);
|
|
21272
|
+
const solanaTx = addTransactionMetadata(tx, {
|
|
21271
21273
|
signers,
|
|
21272
21274
|
addressLookupTables: this.addressLookupTables,
|
|
21273
|
-
type:
|
|
21275
|
+
type: TransactionType.CREATE_PERM_BANK
|
|
21274
21276
|
});
|
|
21275
21277
|
const sig = await this.processTransaction(solanaTx, processOpts, txOpts);
|
|
21276
21278
|
this.logger.debug({ sig }, "Created Lendr group");
|
|
@@ -21286,14 +21288,14 @@ var LendrClient = class LendrClient {
|
|
|
21286
21288
|
* @returns The public key of the newly created lendr group.
|
|
21287
21289
|
*/
|
|
21288
21290
|
async createLendrGroup(seed, additionalIxs, processOpts, txOpts) {
|
|
21289
|
-
const accountKeypair = seed ??
|
|
21291
|
+
const accountKeypair = seed ?? Keypair.generate();
|
|
21290
21292
|
const ixs = await this.makeCreateLendrGroupIx(accountKeypair.publicKey);
|
|
21291
21293
|
const signers = [...ixs.keys, accountKeypair];
|
|
21292
|
-
const tx = new
|
|
21293
|
-
const solanaTx =
|
|
21294
|
+
const tx = new Transaction().add(...ixs.instructions, ...additionalIxs ?? []);
|
|
21295
|
+
const solanaTx = addTransactionMetadata(tx, {
|
|
21294
21296
|
signers,
|
|
21295
21297
|
addressLookupTables: this.addressLookupTables,
|
|
21296
|
-
type:
|
|
21298
|
+
type: TransactionType.CREATE_GROUP
|
|
21297
21299
|
});
|
|
21298
21300
|
const sig = await this.processTransaction(solanaTx, processOpts, txOpts);
|
|
21299
21301
|
this.logger.debug({ sig }, "Created Lendr group");
|
|
@@ -21310,14 +21312,14 @@ var LendrClient = class LendrClient {
|
|
|
21310
21312
|
* @returns The bank's public key and the transaction signature
|
|
21311
21313
|
*/
|
|
21312
21314
|
async createLendingPool(bankMint, bankConfig, seed, processOpts, txOpts) {
|
|
21313
|
-
const bankKeypair = seed ??
|
|
21315
|
+
const bankKeypair = seed ?? Keypair.generate();
|
|
21314
21316
|
const ixs = await this.group.makePoolAddBankIx(this.program, bankKeypair.publicKey, bankMint, bankConfig);
|
|
21315
21317
|
const signers = [...ixs.keys, bankKeypair];
|
|
21316
|
-
const tx = new
|
|
21317
|
-
const solanaTx =
|
|
21318
|
+
const tx = new Transaction().add(...ixs.instructions);
|
|
21319
|
+
const solanaTx = addTransactionMetadata(tx, {
|
|
21318
21320
|
signers,
|
|
21319
21321
|
addressLookupTables: this.addressLookupTables,
|
|
21320
|
-
type:
|
|
21322
|
+
type: TransactionType.CREATE_PERM_BANK
|
|
21321
21323
|
});
|
|
21322
21324
|
const sig = await this.processTransaction(solanaTx, processOpts, txOpts);
|
|
21323
21325
|
this.logger.debug({ sig }, "Created new lending pool");
|
|
@@ -21386,21 +21388,21 @@ var LendrClient = class LendrClient {
|
|
|
21386
21388
|
}
|
|
21387
21389
|
async simulateTransactions(transactions, accountsToInspect) {
|
|
21388
21390
|
const versionedTransactions = [];
|
|
21389
|
-
const connection = new
|
|
21391
|
+
const connection = new Connection(this.provider.connection.rpcEndpoint, this.provider.opts);
|
|
21390
21392
|
let blockhash;
|
|
21391
21393
|
try {
|
|
21392
21394
|
const getLatestBlockhashAndContext = await connection.getLatestBlockhashAndContext("confirmed");
|
|
21393
21395
|
blockhash = getLatestBlockhashAndContext.value.blockhash;
|
|
21394
21396
|
for (const transaction of transactions) {
|
|
21395
|
-
if (
|
|
21397
|
+
if (isV0Tx(transaction)) {
|
|
21396
21398
|
versionedTransactions.push(transaction);
|
|
21397
21399
|
} else {
|
|
21398
|
-
const versionedMessage = new
|
|
21400
|
+
const versionedMessage = new TransactionMessage({
|
|
21399
21401
|
instructions: transaction.instructions,
|
|
21400
21402
|
payerKey: this.provider.publicKey,
|
|
21401
21403
|
recentBlockhash: blockhash
|
|
21402
21404
|
});
|
|
21403
|
-
versionedTransactions.push(new
|
|
21405
|
+
versionedTransactions.push(new VersionedTransaction(versionedMessage.compileToV0Message(this.addressLookupTables)));
|
|
21404
21406
|
}
|
|
21405
21407
|
}
|
|
21406
21408
|
} catch (error) {
|
|
@@ -21476,226 +21478,5 @@ var LendrClient = class LendrClient {
|
|
|
21476
21478
|
var client_default = LendrClient;
|
|
21477
21479
|
|
|
21478
21480
|
//#endregion
|
|
21479
|
-
|
|
21480
|
-
|
|
21481
|
-
exports.AssetTag = AssetTag;
|
|
21482
|
-
exports.BUNDLE_TX_SIZE = require_common.BUNDLE_TX_SIZE;
|
|
21483
|
-
exports.Balance = Balance;
|
|
21484
|
-
exports.Bank = Bank;
|
|
21485
|
-
exports.BankConfig = BankConfig;
|
|
21486
|
-
exports.BankVaultType = BankVaultType;
|
|
21487
|
-
exports.DEFAULT_CLUSTER = require_common.DEFAULT_CLUSTER;
|
|
21488
|
-
exports.DEFAULT_COMMITMENT = require_common.DEFAULT_COMMITMENT;
|
|
21489
|
-
exports.DEFAULT_CONFIRM_OPTS = require_common.DEFAULT_CONFIRM_OPTS;
|
|
21490
|
-
exports.DEFAULT_ORACLE_MAX_AGE = require_common.DEFAULT_ORACLE_MAX_AGE;
|
|
21491
|
-
exports.DEFAULT_PROCESS_TX_OPTS = DEFAULT_PROCESS_TX_OPTS;
|
|
21492
|
-
exports.DEFAULT_PROCESS_TX_STRATEGY = DEFAULT_PROCESS_TX_STRATEGY;
|
|
21493
|
-
exports.DEFAULT_SEND_OPTS = require_common.DEFAULT_SEND_OPTS;
|
|
21494
|
-
exports.DISABLED_FLAG = require_common.DISABLED_FLAG;
|
|
21495
|
-
exports.DUMMY_USDC_MINT = require_common.DUMMY_USDC_MINT;
|
|
21496
|
-
exports.EmodeEntryFlags = EmodeEntryFlags;
|
|
21497
|
-
exports.EmodeFlags = EmodeFlags;
|
|
21498
|
-
exports.EmodeImpactStatus = EmodeImpactStatus;
|
|
21499
|
-
exports.EmodeSettings = EmodeSettings;
|
|
21500
|
-
exports.EmodeTag = EmodeTag;
|
|
21501
|
-
exports.FLASHLOAN_ENABLED_FLAG = require_common.FLASHLOAN_ENABLED_FLAG;
|
|
21502
|
-
exports.FogoMetadataService = FogoMetadataService;
|
|
21503
|
-
exports.GROUP_PK = require_common.GROUP_PK;
|
|
21504
|
-
exports.HOURS_PER_YEAR = require_common.HOURS_PER_YEAR;
|
|
21505
|
-
exports.HealthCache = HealthCache;
|
|
21506
|
-
exports.HealthCacheFlags = HealthCacheFlags;
|
|
21507
|
-
exports.HealthCacheSimulationError = HealthCacheSimulationError;
|
|
21508
|
-
exports.IMetadataService = IMetadataService;
|
|
21509
|
-
exports.JUPITER_V6_PROGRAM = require_common.JUPITER_V6_PROGRAM;
|
|
21510
|
-
exports.LENDR_IDL = LENDR_IDL;
|
|
21511
|
-
exports.LENDR_PROGRAM = require_common.LENDR_PROGRAM;
|
|
21512
|
-
exports.LENDR_SPONSORED_SHARD_ID = LENDR_SPONSORED_SHARD_ID;
|
|
21513
|
-
exports.LST_MINT = require_common.LST_MINT;
|
|
21514
|
-
exports.LUT_PROGRAM_AUTHORITY_INDEX = require_common.LUT_PROGRAM_AUTHORITY_INDEX;
|
|
21515
|
-
exports.LendrAccount = LendrAccount;
|
|
21516
|
-
exports.LendrAccountWrapper = LendrAccountWrapper;
|
|
21517
|
-
exports.LendrClient = client_default;
|
|
21518
|
-
exports.LendrGroup = LendrGroup;
|
|
21519
|
-
exports.LendrRequirementType = LendrRequirementType;
|
|
21520
|
-
exports.MAX_ACCOUNT_KEYS = require_common.MAX_ACCOUNT_KEYS;
|
|
21521
|
-
exports.MAX_CONFIDENCE_INTERVAL_RATIO = require_common.MAX_CONFIDENCE_INTERVAL_RATIO;
|
|
21522
|
-
exports.MAX_TX_SIZE = require_common.MAX_TX_SIZE;
|
|
21523
|
-
exports.MAX_U64 = require_common.MAX_U64;
|
|
21524
|
-
exports.MPL_METADATA_PROGRAM_ID = require_common.MPL_METADATA_PROGRAM_ID;
|
|
21525
|
-
exports.OperationalState = OperationalState;
|
|
21526
|
-
exports.OracleSetup = OracleSetup;
|
|
21527
|
-
exports.PDA_BANK_FEE_VAULT_AUTH_SEED = require_common.PDA_BANK_FEE_VAULT_AUTH_SEED;
|
|
21528
|
-
exports.PDA_BANK_FEE_VAULT_SEED = require_common.PDA_BANK_FEE_VAULT_SEED;
|
|
21529
|
-
exports.PDA_BANK_INSURANCE_VAULT_AUTH_SEED = require_common.PDA_BANK_INSURANCE_VAULT_AUTH_SEED;
|
|
21530
|
-
exports.PDA_BANK_INSURANCE_VAULT_SEED = require_common.PDA_BANK_INSURANCE_VAULT_SEED;
|
|
21531
|
-
exports.PDA_BANK_LIQUIDITY_VAULT_AUTH_SEED = require_common.PDA_BANK_LIQUIDITY_VAULT_AUTH_SEED;
|
|
21532
|
-
exports.PDA_BANK_LIQUIDITY_VAULT_SEED = require_common.PDA_BANK_LIQUIDITY_VAULT_SEED;
|
|
21533
|
-
exports.PRIORITY_TX_SIZE = require_common.PRIORITY_TX_SIZE;
|
|
21534
|
-
exports.PROGRAM_ID = require_common.PROGRAM_ID;
|
|
21535
|
-
exports.PYTH_PRICE_CONF_INTERVALS = require_common.PYTH_PRICE_CONF_INTERVALS;
|
|
21536
|
-
exports.PYTH_PUSH_ORACLE_ID = require_common.PYTH_PUSH_ORACLE_ID;
|
|
21537
|
-
exports.PYTH_SPONSORED_SHARD_ID = PYTH_SPONSORED_SHARD_ID;
|
|
21538
|
-
exports.PriceBias = PriceBias;
|
|
21539
|
-
exports.ProcessTransactionError = ProcessTransactionError;
|
|
21540
|
-
exports.ProcessTransactionErrorType = ProcessTransactionErrorType;
|
|
21541
|
-
exports.RiskTier = RiskTier;
|
|
21542
|
-
exports.SINGLE_POOL_PROGRAM_ID = require_common.SINGLE_POOL_PROGRAM_ID;
|
|
21543
|
-
exports.SKIP_SIMULATION = require_common.SKIP_SIMULATION;
|
|
21544
|
-
exports.STAKE_CONFIG_ID = require_common.STAKE_CONFIG_ID;
|
|
21545
|
-
exports.STAKE_PROGRAM_ID = require_common.STAKE_PROGRAM_ID;
|
|
21546
|
-
exports.SWB_PRICE_CONF_INTERVALS = require_common.SWB_PRICE_CONF_INTERVALS;
|
|
21547
|
-
exports.SYSTEM_PROGRAM_ID = require_common.SYSTEM_PROGRAM_ID;
|
|
21548
|
-
exports.SYSVAR_CLOCK_ID = require_common.SYSVAR_CLOCK_ID;
|
|
21549
|
-
exports.SYSVAR_RENT_ID = require_common.SYSVAR_RENT_ID;
|
|
21550
|
-
exports.SYSVAR_STAKE_HISTORY_ID = require_common.SYSVAR_STAKE_HISTORY_ID;
|
|
21551
|
-
exports.TRANSFER_ACCOUNT_AUTHORITY_FLAG = require_common.TRANSFER_ACCOUNT_AUTHORITY_FLAG;
|
|
21552
|
-
exports.USDC_DECIMALS = require_common.USDC_DECIMALS;
|
|
21553
|
-
exports.USDC_MINT = require_common.USDC_MINT;
|
|
21554
|
-
exports.WSOL_EXTENDED_METADATA = require_common.WSOL_EXTENDED_METADATA;
|
|
21555
|
-
exports.WSOL_MINT = require_common.WSOL_MINT;
|
|
21556
|
-
exports.accountFlagToBN = accountFlagToBN;
|
|
21557
|
-
exports.addOracleToBanksIx = addOracleToBanksIx;
|
|
21558
|
-
exports.balanceToDto = balanceToDto;
|
|
21559
|
-
exports.bankConfigRawToDto = bankConfigRawToDto;
|
|
21560
|
-
exports.bankRawToDto = bankRawToDto;
|
|
21561
|
-
exports.buildFeedIdMap = buildFeedIdMap;
|
|
21562
|
-
exports.computeAccountValue = computeAccountValue;
|
|
21563
|
-
exports.computeActiveEmodePairs = computeActiveEmodePairs;
|
|
21564
|
-
exports.computeAssetUsdValue = computeAssetUsdValue;
|
|
21565
|
-
exports.computeBalanceUsdValue = computeBalanceUsdValue;
|
|
21566
|
-
exports.computeBaseInterestRate = computeBaseInterestRate;
|
|
21567
|
-
exports.computeClaimedEmissions = computeClaimedEmissions;
|
|
21568
|
-
exports.computeEmodeImpacts = computeEmodeImpacts;
|
|
21569
|
-
exports.computeFreeCollateral = computeFreeCollateral;
|
|
21570
|
-
exports.computeFreeCollateralLegacy = computeFreeCollateralLegacy;
|
|
21571
|
-
exports.computeHealthAccountMetas = computeHealthAccountMetas;
|
|
21572
|
-
exports.computeHealthCheckAccounts = computeHealthCheckAccounts;
|
|
21573
|
-
exports.computeHealthComponents = computeHealthComponents;
|
|
21574
|
-
exports.computeHealthComponentsLegacy = computeHealthComponentsLegacy;
|
|
21575
|
-
exports.computeHealthComponentsWithoutBiasLegacy = computeHealthComponentsWithoutBiasLegacy;
|
|
21576
|
-
exports.computeInterestRates = computeInterestRates;
|
|
21577
|
-
exports.computeLiabilityUsdValue = computeLiabilityUsdValue;
|
|
21578
|
-
exports.computeLoopingParams = computeLoopingParams;
|
|
21579
|
-
exports.computeMaxLeverage = computeMaxLeverage;
|
|
21580
|
-
exports.computeNetApy = computeNetApy;
|
|
21581
|
-
exports.computeQuantity = computeQuantity;
|
|
21582
|
-
exports.computeQuantityUi = computeQuantityUi;
|
|
21583
|
-
exports.computeRemainingCapacity = computeRemainingCapacity;
|
|
21584
|
-
exports.computeTotalOutstandingEmissions = computeTotalOutstandingEmissions;
|
|
21585
|
-
exports.computeTvl = computeTvl;
|
|
21586
|
-
exports.computeUsdValue = computeUsdValue;
|
|
21587
|
-
exports.computeUtilizationRate = computeUtilizationRate;
|
|
21588
|
-
exports.confirmTransaction = confirmTransaction;
|
|
21589
|
-
exports.crankPythOracleIx = crankPythOracleIx;
|
|
21590
|
-
exports.createLendrAccountTx = createLendrAccountTx;
|
|
21591
|
-
exports.createUpdateFeedIx = createUpdateFeedIx;
|
|
21592
|
-
exports.decodeAccountRaw = decodeAccountRaw;
|
|
21593
|
-
exports.decodeBankRaw = decodeBankRaw;
|
|
21594
|
-
exports.dtoToBalance = dtoToBalance;
|
|
21595
|
-
exports.dtoToBank = dtoToBank;
|
|
21596
|
-
exports.dtoToBankConfig = dtoToBankConfig;
|
|
21597
|
-
exports.dtoToBankConfigRaw = dtoToBankConfigRaw;
|
|
21598
|
-
exports.dtoToBankRaw = dtoToBankRaw;
|
|
21599
|
-
exports.dtoToEmodeSettings = dtoToEmodeSettings;
|
|
21600
|
-
exports.dtoToEmodeSettingsRaw = dtoToEmodeSettingsRaw;
|
|
21601
|
-
exports.dtoToGroup = dtoToGroup;
|
|
21602
|
-
exports.dtoToHealthCache = dtoToHealthCache;
|
|
21603
|
-
exports.dtoToInterestRateConfig = dtoToInterestRateConfig;
|
|
21604
|
-
exports.dtoToLendrAccount = dtoToLendrAccount;
|
|
21605
|
-
exports.dtoToOraclePrice = dtoToOraclePrice;
|
|
21606
|
-
exports.dtoToValidatorStakeGroup = dtoToValidatorStakeGroup;
|
|
21607
|
-
exports.emodeSettingsRawToDto = emodeSettingsRawToDto;
|
|
21608
|
-
exports.feedIdToString = feedIdToString;
|
|
21609
|
-
exports.fetchLendrAccountAddresses = fetchLendrAccountAddresses;
|
|
21610
|
-
exports.fetchLendrAccountData = fetchLendrAccountData;
|
|
21611
|
-
exports.fetchMultipleBanks = fetchMultipleBanks;
|
|
21612
|
-
exports.fetchNativeStakeAccounts = fetchNativeStakeAccounts;
|
|
21613
|
-
exports.fetchOracleData = fetchOracleData;
|
|
21614
|
-
exports.fetchPythOracleData = fetchPythOracleData;
|
|
21615
|
-
exports.fetchStakeAccount = fetchStakeAccount;
|
|
21616
|
-
exports.fetchStakePoolActiveStates = fetchStakePoolActiveStates;
|
|
21617
|
-
exports.fetchStakePoolMev = fetchStakePoolMev;
|
|
21618
|
-
exports.fetchSwbOracleData = fetchSwbOracleData;
|
|
21619
|
-
exports.findOracleKey = findOracleKey;
|
|
21620
|
-
exports.findPythPushOracleAddress = findPythPushOracleAddress;
|
|
21621
|
-
exports.freezeBankConfigIx = freezeBankConfigIx;
|
|
21622
|
-
exports.getActiveAccountFlags = getActiveAccountFlags;
|
|
21623
|
-
exports.getActiveEmodeEntryFlags = getActiveEmodeEntryFlags;
|
|
21624
|
-
exports.getActiveEmodeFlags = getActiveEmodeFlags;
|
|
21625
|
-
exports.getActiveHealthCacheFlags = getActiveHealthCacheFlags;
|
|
21626
|
-
exports.getActiveStaleBanks = getActiveStaleBanks;
|
|
21627
|
-
exports.getAssetQuantity = getAssetQuantity;
|
|
21628
|
-
exports.getAssetShares = getAssetShares;
|
|
21629
|
-
exports.getAssetWeight = getAssetWeight;
|
|
21630
|
-
exports.getBalanceUsdValueWithPriceBias = getBalanceUsdValueWithPriceBias;
|
|
21631
|
-
exports.getBankVaultAuthority = getBankVaultAuthority;
|
|
21632
|
-
exports.getBankVaultSeeds = getBankVaultSeeds;
|
|
21633
|
-
exports.getConfig = getConfig;
|
|
21634
|
-
exports.getConfigPda = getConfigPda;
|
|
21635
|
-
exports.getHealthCacheStatusDescription = getHealthCacheStatusDescription;
|
|
21636
|
-
exports.getLiabilityQuantity = getLiabilityQuantity;
|
|
21637
|
-
exports.getLiabilityShares = getLiabilityShares;
|
|
21638
|
-
exports.getLiabilityWeight = getLiabilityWeight;
|
|
21639
|
-
exports.getPrice = getPrice;
|
|
21640
|
-
exports.getPriceFeedAccountForProgram = getPriceFeedAccountForProgram;
|
|
21641
|
-
exports.getPriceWithConfidence = getPriceWithConfidence;
|
|
21642
|
-
exports.getTotalAssetQuantity = getTotalAssetQuantity;
|
|
21643
|
-
exports.getTotalLiabilityQuantity = getTotalLiabilityQuantity;
|
|
21644
|
-
exports.getTreasuryPda = getTreasuryPda;
|
|
21645
|
-
exports.groupToDto = groupToDto;
|
|
21646
|
-
exports.hasAccountFlag = hasAccountFlag;
|
|
21647
|
-
exports.hasEmodeEntryFlag = hasEmodeEntryFlag;
|
|
21648
|
-
exports.hasEmodeFlag = hasEmodeFlag;
|
|
21649
|
-
exports.hasHealthCacheFlag = hasHealthCacheFlag;
|
|
21650
|
-
exports.healthCacheToDto = healthCacheToDto;
|
|
21651
|
-
exports.instructions = instructions_default;
|
|
21652
|
-
exports.isWeightedPrice = isWeightedPrice;
|
|
21653
|
-
exports.lendrAccountToDto = lendrAccountToDto;
|
|
21654
|
-
exports.makeAddPermissionlessStakedBankIx = makeAddPermissionlessStakedBankIx;
|
|
21655
|
-
exports.makeBundleTipIx = makeBundleTipIx;
|
|
21656
|
-
exports.makeDisableAccountTransferForAccountIx = makeDisableAccountTransferForAccountIx;
|
|
21657
|
-
exports.makeDisableFlashLoanForAccountIx = makeDisableFlashLoanForAccountIx;
|
|
21658
|
-
exports.makeEnableAccountTransferForAccountIx = makeEnableAccountTransferForAccountIx;
|
|
21659
|
-
exports.makeEnableFlashLoanForAccountIx = makeEnableFlashLoanForAccountIx;
|
|
21660
|
-
exports.makePoolAddBankIx = makePoolAddBankIx;
|
|
21661
|
-
exports.makePoolConfigureBankIx = makePoolConfigureBankIx;
|
|
21662
|
-
exports.makePriorityFeeIx = makePriorityFeeIx;
|
|
21663
|
-
exports.makePriorityFeeMicroIx = makePriorityFeeMicroIx;
|
|
21664
|
-
exports.makePulseHealthIx = makePulseHealthIx;
|
|
21665
|
-
exports.makeTxPriorityIx = makeTxPriorityIx;
|
|
21666
|
-
exports.makeUnwrapSolIx = makeUnwrapSolIx;
|
|
21667
|
-
exports.makeVersionedTransaction = makeVersionedTransaction;
|
|
21668
|
-
exports.makeWrapSolIxs = makeWrapSolIxs;
|
|
21669
|
-
exports.metadataSchema = metadataSchema;
|
|
21670
|
-
exports.oraclePriceToDto = oraclePriceToDto;
|
|
21671
|
-
exports.parseBalanceRaw = parseBalanceRaw;
|
|
21672
|
-
exports.parseBankConfigRaw = parseBankConfigRaw;
|
|
21673
|
-
exports.parseBankRaw = parseBankRaw;
|
|
21674
|
-
exports.parseEmodeTag = parseEmodeTag;
|
|
21675
|
-
exports.parseErrorFromLogs = parseErrorFromLogs;
|
|
21676
|
-
exports.parseLendrAccountRaw = parseLendrAccountRaw;
|
|
21677
|
-
exports.parseOperationalState = parseOperationalState;
|
|
21678
|
-
exports.parseOracleSetup = parseOracleSetup;
|
|
21679
|
-
exports.parsePriceInfo = parseOraclePriceData;
|
|
21680
|
-
exports.parseRiskTier = parseRiskTier;
|
|
21681
|
-
exports.parseTransactionError = parseTransactionError;
|
|
21682
|
-
exports.processTransactions = processTransactions;
|
|
21683
|
-
exports.serializeBankConfigOpt = serializeBankConfigOpt;
|
|
21684
|
-
exports.serializeOperationalState = serializeOperationalState;
|
|
21685
|
-
exports.serializeOracleSetup = serializeOracleSetup;
|
|
21686
|
-
exports.serializeOracleSetupToIndex = serializeOracleSetupToIndex;
|
|
21687
|
-
exports.serializeRiskTier = serializeRiskTier;
|
|
21688
|
-
exports.simulateAccountHealthCache = simulateAccountHealthCache;
|
|
21689
|
-
exports.simulateAccountHealthCacheWithFallback = simulateAccountHealthCacheWithFallback;
|
|
21690
|
-
exports.simulateTransactions = simulateTransactions;
|
|
21691
|
-
exports.toBankConfigDto = toBankConfigDto;
|
|
21692
|
-
exports.toBankDto = toBankDto;
|
|
21693
|
-
exports.toEmodeSettingsDto = toEmodeSettingsDto;
|
|
21694
|
-
exports.toInterestRateConfigDto = toInterestRateConfigDto;
|
|
21695
|
-
exports.validatorStakeGroupToDto = validatorStakeGroupToDto;
|
|
21696
|
-
Object.defineProperty(exports, 'vendor', {
|
|
21697
|
-
enumerable: true,
|
|
21698
|
-
get: function () {
|
|
21699
|
-
return vendor_exports;
|
|
21700
|
-
}
|
|
21701
|
-
});
|
|
21481
|
+
export { AccountFlags, AccountType, AssetTag, BUNDLE_TX_SIZE, Balance, Bank, BankConfig, BankVaultType, DEFAULT_CLUSTER, DEFAULT_COMMITMENT, DEFAULT_CONFIRM_OPTS, DEFAULT_ORACLE_MAX_AGE, DEFAULT_PROCESS_TX_OPTS, DEFAULT_PROCESS_TX_STRATEGY, DEFAULT_SEND_OPTS, DISABLED_FLAG, DUMMY_USDC_MINT, DataFetcher, EmodeEntryFlags, EmodeFlags, EmodeImpactStatus, EmodeSettings, EmodeTag, FLASHLOAN_ENABLED_FLAG, FogoMetadataService, GROUP_PK, HOURS_PER_YEAR, HealthCache, HealthCacheFlags, HealthCacheSimulationError, IMetadataService, JUPITER_V6_PROGRAM, LENDR_IDL, LENDR_PROGRAM, LENDR_SPONSORED_SHARD_ID, LST_MINT, LUT_PROGRAM_AUTHORITY_INDEX, LendrAccount, LendrAccountWrapper, client_default as LendrClient, LendrGroup, LendrRequirementType, MAX_ACCOUNT_KEYS, MAX_CONFIDENCE_INTERVAL_RATIO, MAX_TX_SIZE, MAX_U64, MPL_METADATA_PROGRAM_ID, OperationalState, OracleSetup, PDA_BANK_FEE_VAULT_AUTH_SEED, PDA_BANK_FEE_VAULT_SEED, PDA_BANK_INSURANCE_VAULT_AUTH_SEED, PDA_BANK_INSURANCE_VAULT_SEED, PDA_BANK_LIQUIDITY_VAULT_AUTH_SEED, PDA_BANK_LIQUIDITY_VAULT_SEED, PRIORITY_TX_SIZE, PROGRAM_ID, PYTH_PRICE_CONF_INTERVALS, PYTH_PUSH_ORACLE_ID, PYTH_SPONSORED_SHARD_ID, PriceBias, ProcessTransactionError, ProcessTransactionErrorType, RiskTier, SINGLE_POOL_PROGRAM_ID, SKIP_SIMULATION, STAKE_CONFIG_ID, STAKE_PROGRAM_ID, SWB_PRICE_CONF_INTERVALS, SYSTEM_PROGRAM_ID, SYSVAR_CLOCK_ID, SYSVAR_RENT_ID, SYSVAR_STAKE_HISTORY_ID, TRANSFER_ACCOUNT_AUTHORITY_FLAG, USDC_DECIMALS, USDC_MINT, WSOL_EXTENDED_METADATA, WSOL_MINT, accountFlagToBN, addOracleToBanksIx, balanceToDto, bankConfigRawToDto, bankRawToDto, buildFeedIdMap, computeAccountValue, computeActiveEmodePairs, computeAssetUsdValue, computeBalanceUsdValue, computeBaseInterestRate, computeClaimedEmissions, computeEmodeImpacts, computeFreeCollateral, computeFreeCollateralLegacy, computeHealthAccountMetas, computeHealthCheckAccounts, computeHealthComponents, computeHealthComponentsLegacy, computeHealthComponentsWithoutBiasLegacy, computeInterestRates, computeLiabilityUsdValue, computeLoopingParams, computeMaxLeverage, computeNetApy, computeQuantity, computeQuantityUi, computeRemainingCapacity, computeTotalOutstandingEmissions, computeTvl, computeUsdValue, computeUtilizationRate, confirmTransaction, crankPythOracleIx, createLendrAccountTx, createUpdateFeedIx, decodeAccountRaw, decodeBankRaw, dtoToBalance, dtoToBank, dtoToBankConfig, dtoToBankConfigRaw, dtoToBankRaw, dtoToEmodeSettings, dtoToEmodeSettingsRaw, dtoToGroup, dtoToHealthCache, dtoToInterestRateConfig, dtoToLendrAccount, dtoToOraclePrice, dtoToValidatorStakeGroup, emodeSettingsRawToDto, feedIdToString, fetchLendrAccountAddresses, fetchLendrAccountData, fetchMultipleBanks, fetchNativeStakeAccounts, fetchOracleData, fetchPythOracleData, fetchStakeAccount, fetchStakePoolActiveStates, fetchStakePoolMev, fetchSwbOracleData, findOracleKey, findPythPushOracleAddress, freezeBankConfigIx, getActiveAccountFlags, getActiveEmodeEntryFlags, getActiveEmodeFlags, getActiveHealthCacheFlags, getActiveStaleBanks, getAssetQuantity, getAssetShares, getAssetWeight, getBalanceUsdValueWithPriceBias, getBankVaultAuthority, getBankVaultSeeds, getConfig, getConfigPda, getHealthCacheStatusDescription, getLiabilityQuantity, getLiabilityShares, getLiabilityWeight, getPrice, getPriceFeedAccountForProgram, getPriceWithConfidence, getTotalAssetQuantity, getTotalLiabilityQuantity, getTreasuryPda, groupToDto, hasAccountFlag, hasEmodeEntryFlag, hasEmodeFlag, hasHealthCacheFlag, healthCacheToDto, instructions_default as instructions, isWeightedPrice, lendrAccountToDto, makeAddPermissionlessStakedBankIx, makeBundleTipIx, makeDisableAccountTransferForAccountIx, makeDisableFlashLoanForAccountIx, makeEnableAccountTransferForAccountIx, makeEnableFlashLoanForAccountIx, makePoolAddBankIx, makePoolConfigureBankIx, makePriorityFeeIx, makePriorityFeeMicroIx, makePulseHealthIx, makeTxPriorityIx, makeUnwrapSolIx, makeVersionedTransaction, makeWrapSolIxs, metadataSchema, oraclePriceToDto, parseBalanceRaw, parseBankConfigRaw, parseBankRaw, parseEmodeTag, parseErrorFromLogs, parseLendrAccountRaw, parseOperationalState, parseOracleSetup, parseOraclePriceData as parsePriceInfo, parseRiskTier, parseTransactionError, processTransactions, serializeBankConfigOpt, serializeOperationalState, serializeOracleSetup, serializeOracleSetupToIndex, serializeRiskTier, simulateAccountHealthCache, simulateAccountHealthCacheWithFallback, simulateTransactions, toBankConfigDto, toBankDto, toEmodeSettingsDto, toInterestRateConfigDto, validatorStakeGroupToDto, vendor_exports as vendor };
|
|
21482
|
+
//# sourceMappingURL=index.js.map
|