@pyron-finance/pyron-client 1.0.6 → 1.0.9-pre.0
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-B23MHZHG.cjs} +5 -4
- package/dist/{common-BtUtEjzZ.mjs → common-CsZ-YSuW.js} +7 -6
- package/dist/common-CsZ-YSuW.js.map +1 -0
- package/dist/{index-BAC0ffmc.d.mts → index-Bi6sw5qC.d.cts} +117 -69
- package/dist/index-Bi6sw5qC.d.cts.map +1 -0
- package/dist/{index-Bx-zRXFQ.d.ts → index-DcGyKuPI.d.ts} +132 -88
- package/dist/index-DcGyKuPI.d.ts.map +1 -0
- package/dist/{index.mjs → index.cjs} +1079 -735
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +861 -958
- 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,21 @@
|
|
|
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-CsZ-YSuW.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 * as z$1 from "zod/v4-mini";
|
|
12
|
+
import { z } from "zod/v4-mini";
|
|
13
|
+
import { findMetadataPda, mplTokenMetadata, safeFetchAllMetadata } from "@metaplex-foundation/mpl-token-metadata";
|
|
14
|
+
import { publicKey } from "@metaplex-foundation/umi";
|
|
15
|
+
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
|
|
16
|
+
import * as borsh$1 from "borsh";
|
|
17
|
+
import * as borsh from "@coral-xyz/borsh";
|
|
18
|
+
import Big from "big.js";
|
|
13
19
|
|
|
14
20
|
//#region src/logger.ts
|
|
15
21
|
var NoopLogger = class {
|
|
@@ -51,19 +57,80 @@ var DataFetcher = class {
|
|
|
51
57
|
};
|
|
52
58
|
|
|
53
59
|
//#endregion
|
|
54
|
-
//#region src/services/metadata/
|
|
55
|
-
|
|
56
|
-
name
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
//#region src/services/metadata/dummy.ts
|
|
61
|
+
var DummyMetadataFetcher = class {
|
|
62
|
+
name = "DummyMetadataFetcher";
|
|
63
|
+
async fetch(mints) {
|
|
64
|
+
return mints.reduce((prev, mint) => {
|
|
65
|
+
prev[mint] = {
|
|
66
|
+
name: shortenAddress(mint),
|
|
67
|
+
symbol: mint.slice(0, 4),
|
|
68
|
+
image: ""
|
|
69
|
+
};
|
|
70
|
+
return prev;
|
|
71
|
+
}, {});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/services/metadata/metaplex.ts
|
|
77
|
+
const imageEndpointSchema = z$1.object({ image: z$1.string() });
|
|
78
|
+
var MetaplexMetadataFetcher = class {
|
|
79
|
+
name = "MetaplexMetadataFetcher";
|
|
80
|
+
_umi;
|
|
81
|
+
constructor(rpcEndpoint) {
|
|
82
|
+
this._umi = createUmi(rpcEndpoint).use(mplTokenMetadata());
|
|
83
|
+
}
|
|
84
|
+
async fetch(mints) {
|
|
85
|
+
const pdaList = mints.map((mint) => findMetadataPda(this._umi, { mint: publicKey(mint) }));
|
|
86
|
+
const fetched = await safeFetchAllMetadata(this._umi, pdaList);
|
|
87
|
+
const metas = await Promise.all(fetched.map(async (meta) => {
|
|
88
|
+
return {
|
|
89
|
+
mint: meta.mint,
|
|
90
|
+
data: {
|
|
91
|
+
name: meta.name,
|
|
92
|
+
symbol: meta.symbol,
|
|
93
|
+
image: await this._getImage(meta),
|
|
94
|
+
uri: meta.uri
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}));
|
|
98
|
+
const result = {};
|
|
99
|
+
for (const { mint, data } of metas) {
|
|
100
|
+
result[mint] = data;
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
async _getImage(metadata$2) {
|
|
105
|
+
try {
|
|
106
|
+
const result = await fetch(metadata$2.uri).then((r) => r.json());
|
|
107
|
+
const parsed = await imageEndpointSchema.parseAsync(result);
|
|
108
|
+
return parsed.image;
|
|
109
|
+
} catch (_) {
|
|
110
|
+
return "";
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/services/metadata/service.ts
|
|
117
|
+
const metadataSchema = z$1.object({
|
|
118
|
+
name: z$1.string(),
|
|
119
|
+
symbol: z$1.string(),
|
|
120
|
+
image: z$1.string(),
|
|
121
|
+
uri: z$1.optional(z$1.string())
|
|
59
122
|
});
|
|
60
|
-
var
|
|
123
|
+
var MetadataService = class {
|
|
61
124
|
/** NOTE: record key is base58 of mint public key */
|
|
62
125
|
overrides;
|
|
63
126
|
_storage;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
127
|
+
_fetchers;
|
|
128
|
+
_logger;
|
|
129
|
+
constructor({ storage, logger, fetchers, overrides }) {
|
|
130
|
+
this._storage = prefixStorage(storage, "banks:metadata");
|
|
131
|
+
this.overrides = overrides ?? {};
|
|
132
|
+
this._fetchers = fetchers;
|
|
133
|
+
this._logger = logger;
|
|
67
134
|
}
|
|
68
135
|
async forMints(mints) {
|
|
69
136
|
if (mints.length === 0) return {};
|
|
@@ -85,7 +152,8 @@ var IMetadataService = class {
|
|
|
85
152
|
const meta = {
|
|
86
153
|
name: override?.name ?? fetched[key].name,
|
|
87
154
|
symbol: override?.symbol ?? fetched[key].symbol,
|
|
88
|
-
image: override?.logoURI ?? fetched[key].image
|
|
155
|
+
image: override?.logoURI ?? fetched[key].image,
|
|
156
|
+
uri: fetched[key].uri
|
|
89
157
|
};
|
|
90
158
|
metas[key] = meta;
|
|
91
159
|
await this._storage.set(key, meta);
|
|
@@ -110,13 +178,42 @@ var IMetadataService = class {
|
|
|
110
178
|
});
|
|
111
179
|
return meta;
|
|
112
180
|
}
|
|
181
|
+
async _fetch(mints) {
|
|
182
|
+
const meta = {};
|
|
183
|
+
let remaining = [...mints];
|
|
184
|
+
for (const fetcher of this._fetchers) {
|
|
185
|
+
if (remaining.length === 0) break;
|
|
186
|
+
try {
|
|
187
|
+
const fetched = await fetcher.fetch(remaining);
|
|
188
|
+
for (const key in fetched) {
|
|
189
|
+
meta[key] = fetched[key];
|
|
190
|
+
}
|
|
191
|
+
remaining = remaining.filter((key) => !Object.hasOwn(fetched, key));
|
|
192
|
+
} catch (err) {
|
|
193
|
+
this._logger.debug({
|
|
194
|
+
err,
|
|
195
|
+
remaining,
|
|
196
|
+
mints,
|
|
197
|
+
fetcher: fetcher.name
|
|
198
|
+
}, "failed to fetch metadata");
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (remaining.length > 0) {
|
|
202
|
+
this._logger.warn({
|
|
203
|
+
remaining,
|
|
204
|
+
mints
|
|
205
|
+
}, "failed to fetch metadata for some mints");
|
|
206
|
+
}
|
|
207
|
+
return meta;
|
|
208
|
+
}
|
|
113
209
|
};
|
|
114
210
|
|
|
115
211
|
//#endregion
|
|
116
212
|
//#region src/services/metadata/fogo.ts
|
|
117
|
-
const endpointSchema =
|
|
118
|
-
var
|
|
119
|
-
|
|
213
|
+
const endpointSchema = z.record(z.string(), metadataSchema);
|
|
214
|
+
var FogoMetadataFetcher = class {
|
|
215
|
+
name = "FogoMetadataFetcher";
|
|
216
|
+
async fetch(mints) {
|
|
120
217
|
if (mints.length === 0) {
|
|
121
218
|
return {};
|
|
122
219
|
}
|
|
@@ -134,9 +231,9 @@ var FogoMetadataService = class extends IMetadataService {
|
|
|
134
231
|
function getConfig({ environment = "production", overrides } = {}) {
|
|
135
232
|
return {
|
|
136
233
|
environment,
|
|
137
|
-
cluster: overrides?.cluster ??
|
|
138
|
-
programId: overrides?.programId ??
|
|
139
|
-
groupPk: overrides?.groupPk ??
|
|
234
|
+
cluster: overrides?.cluster ?? DEFAULT_CLUSTER,
|
|
235
|
+
programId: overrides?.programId ?? PROGRAM_ID,
|
|
236
|
+
groupPk: overrides?.groupPk ?? GROUP_PK
|
|
140
237
|
};
|
|
141
238
|
}
|
|
142
239
|
|
|
@@ -6166,7 +6263,7 @@ function parseCustomProgramError(logs, ldrProgramId) {
|
|
|
6166
6263
|
};
|
|
6167
6264
|
}
|
|
6168
6265
|
}
|
|
6169
|
-
errorMsg =
|
|
6266
|
+
errorMsg = LangErrorMessage.get(error.code);
|
|
6170
6267
|
if (errorMsg !== undefined) {
|
|
6171
6268
|
return {
|
|
6172
6269
|
code: error.code,
|
|
@@ -6276,7 +6373,7 @@ const JupiterErrorCodeMap = new Map([
|
|
|
6276
6373
|
[JupiterErrorCode.ExactOutAmountNotMatched, "Exact out amount doesn't match"],
|
|
6277
6374
|
[JupiterErrorCode.SourceAndDestinationMintCannotBeTheSame, "Source mint and destination mint cannot the same"]
|
|
6278
6375
|
]);
|
|
6279
|
-
const ERROR_CODE_MAPS = new Map([[
|
|
6376
|
+
const ERROR_CODE_MAPS = new Map([[TOKEN_PROGRAM_ID.toBase58(), TokenErrorCodeMap], [JUPITER_V6_PROGRAM.toBase58(), JupiterErrorCodeMap]]);
|
|
6280
6377
|
|
|
6281
6378
|
//#endregion
|
|
6282
6379
|
//#region src/idl/idl.utils.ts
|
|
@@ -6450,8 +6547,8 @@ async function makeLendingPoolConfigureBankOracleIx(ldProgram, accounts$2, args,
|
|
|
6450
6547
|
* @param args - Optional arguments for this instruction
|
|
6451
6548
|
*/
|
|
6452
6549
|
async function makePoolAddPermissionlessStakedBankIx(ldProgram, accounts$2, remainingAccounts = [], args) {
|
|
6453
|
-
const { stakedSettings, feePayer, bankMint, solPool, stakePool, tokenProgram =
|
|
6454
|
-
return ldProgram.methods.lendingPoolAddBankPermissionless(args.seed ?? new
|
|
6550
|
+
const { stakedSettings, feePayer, bankMint, solPool, stakePool, tokenProgram = TOKEN_PROGRAM_ID,...optionalAccounts } = accounts$2;
|
|
6551
|
+
return ldProgram.methods.lendingPoolAddBankPermissionless(args.seed ?? new BN$1(0)).accounts({
|
|
6455
6552
|
stakedSettings,
|
|
6456
6553
|
feePayer,
|
|
6457
6554
|
bankMint,
|
|
@@ -6625,13 +6722,13 @@ var HealthCache = class HealthCache {
|
|
|
6625
6722
|
this.simulationFailed = simulationFailed;
|
|
6626
6723
|
}
|
|
6627
6724
|
static from(healthCacheRaw) {
|
|
6628
|
-
const assetValue =
|
|
6629
|
-
const liabilityValue =
|
|
6630
|
-
const assetValueMaint =
|
|
6631
|
-
const liabilityValueMaint =
|
|
6632
|
-
const assetValueEquity =
|
|
6633
|
-
const liabilityValueEquity =
|
|
6634
|
-
const timestamp =
|
|
6725
|
+
const assetValue = wrappedI80F48toBigNumber(healthCacheRaw.assetValue);
|
|
6726
|
+
const liabilityValue = wrappedI80F48toBigNumber(healthCacheRaw.liabilityValue);
|
|
6727
|
+
const assetValueMaint = wrappedI80F48toBigNumber(healthCacheRaw.assetValueMaint);
|
|
6728
|
+
const liabilityValueMaint = wrappedI80F48toBigNumber(healthCacheRaw.liabilityValueMaint);
|
|
6729
|
+
const assetValueEquity = wrappedI80F48toBigNumber(healthCacheRaw.assetValueEquity);
|
|
6730
|
+
const liabilityValueEquity = wrappedI80F48toBigNumber(healthCacheRaw.liabilityValueEquity);
|
|
6731
|
+
const timestamp = toBigNumber(healthCacheRaw.timestamp);
|
|
6635
6732
|
const flags = getActiveHealthCacheFlags(healthCacheRaw.flags);
|
|
6636
6733
|
const prices = healthCacheRaw.prices;
|
|
6637
6734
|
return new HealthCache(assetValue, liabilityValue, assetValueMaint, liabilityValueMaint, assetValueEquity, liabilityValueEquity, timestamp, flags, prices);
|
|
@@ -8959,9 +9056,9 @@ const PYTH_SOLANA_RECEIVER_PROGRAM_IDL = {
|
|
|
8959
9056
|
|
|
8960
9057
|
//#endregion
|
|
8961
9058
|
//#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
|
|
9059
|
+
const DEFAULT_RECEIVER_PROGRAM_ID = new PublicKey("rec5EKMGg6MxZYaMdyBfgwp4d5rB9T1VQH5pJv5LtFJ");
|
|
9060
|
+
const DEFAULT_WORMHOLE_PROGRAM_ID = new PublicKey("HDwcJBJXjL9FpJ7UBsYBtaDjsBUhuLCUYoz3zr8SWWaQ");
|
|
9061
|
+
const DEFAULT_PUSH_ORACLE_PROGRAM_ID = new PublicKey("pythWSnswVUd12oZpeFP8e9CVaEqJg25g1Vtc2biRsT");
|
|
8965
9062
|
const ACCUMULATOR_MAGIC = "504e4155";
|
|
8966
9063
|
const MAJOR_VERSION = 1;
|
|
8967
9064
|
const MINOR_VERSION = 0;
|
|
@@ -9075,7 +9172,7 @@ async function buildPostEncodedVaaInstructions(wormhole, vaa) {
|
|
|
9075
9172
|
};
|
|
9076
9173
|
}
|
|
9077
9174
|
async function generateVaaInstructionGroups(wormhole, vaa) {
|
|
9078
|
-
const encodedVaaKeypair = new
|
|
9175
|
+
const encodedVaaKeypair = new Keypair();
|
|
9079
9176
|
const initInstructions = [await buildEncodedVaaCreateInstruction(wormhole, vaa, encodedVaaKeypair), {
|
|
9080
9177
|
instruction: await wormhole.methods.initEncodedVaa().accounts({ encodedVaa: encodedVaaKeypair.publicKey }).instruction(),
|
|
9081
9178
|
signers: [],
|
|
@@ -9135,7 +9232,7 @@ async function buildEncodedVaaCreateInstruction(wormhole, vaa, encodedVaaKeypair
|
|
|
9135
9232
|
const getGuardianSetPda = (guardianSetIndex, wormholeProgramId) => {
|
|
9136
9233
|
const guardianSetIndexBuf = Buffer.alloc(4);
|
|
9137
9234
|
guardianSetIndexBuf.writeUInt32BE(guardianSetIndex, 0);
|
|
9138
|
-
return
|
|
9235
|
+
return PublicKey.findProgramAddressSync([Buffer.from("GuardianSet"), guardianSetIndexBuf], wormholeProgramId)[0];
|
|
9139
9236
|
};
|
|
9140
9237
|
function parsePriceFeedMessage(message) {
|
|
9141
9238
|
let cursor = 0;
|
|
@@ -9146,19 +9243,19 @@ function parsePriceFeedMessage(message) {
|
|
|
9146
9243
|
cursor += 1;
|
|
9147
9244
|
const feedId = message.subarray(cursor, cursor + 32);
|
|
9148
9245
|
cursor += 32;
|
|
9149
|
-
const price = new
|
|
9246
|
+
const price = new BN$1(message.subarray(cursor, cursor + 8), "be");
|
|
9150
9247
|
cursor += 8;
|
|
9151
|
-
const confidence = new
|
|
9248
|
+
const confidence = new BN$1(message.subarray(cursor, cursor + 8), "be");
|
|
9152
9249
|
cursor += 8;
|
|
9153
9250
|
const exponent = message.readInt32BE(cursor);
|
|
9154
9251
|
cursor += 4;
|
|
9155
|
-
const publishTime = new
|
|
9252
|
+
const publishTime = new BN$1(message.subarray(cursor, cursor + 8), "be");
|
|
9156
9253
|
cursor += 8;
|
|
9157
|
-
const prevPublishTime = new
|
|
9254
|
+
const prevPublishTime = new BN$1(message.subarray(cursor, cursor + 8), "be");
|
|
9158
9255
|
cursor += 8;
|
|
9159
|
-
const emaPrice = new
|
|
9256
|
+
const emaPrice = new BN$1(message.subarray(cursor, cursor + 8), "be");
|
|
9160
9257
|
cursor += 8;
|
|
9161
|
-
const emaConf = new
|
|
9258
|
+
const emaConf = new BN$1(message.subarray(cursor, cursor + 8), "be");
|
|
9162
9259
|
cursor += 8;
|
|
9163
9260
|
return {
|
|
9164
9261
|
feedId,
|
|
@@ -9220,7 +9317,7 @@ function readBigUInt64LE(buffer, offset = 0) {
|
|
|
9220
9317
|
/** Number of slots that can pass before a publisher's price is no longer included in the aggregate. */
|
|
9221
9318
|
const MAX_SLOT_DIFFERENCE = 25;
|
|
9222
9319
|
const empty32Buffer = Buffer.alloc(32);
|
|
9223
|
-
const PKorNull = (data) => data.equals(empty32Buffer) ? null : new
|
|
9320
|
+
const PKorNull = (data) => data.equals(empty32Buffer) ? null : new PublicKey(data);
|
|
9224
9321
|
let PriceStatus = /* @__PURE__ */ function(PriceStatus$1) {
|
|
9225
9322
|
PriceStatus$1[PriceStatus$1["Unknown"] = 0] = "Unknown";
|
|
9226
9323
|
PriceStatus$1[PriceStatus$1["Trading"] = 1] = "Trading";
|
|
@@ -9283,7 +9380,7 @@ const parsePriceData = (data, currentSlot) => {
|
|
|
9283
9380
|
const drv2 = data.readInt8(105);
|
|
9284
9381
|
const drv3 = data.readInt16LE(106);
|
|
9285
9382
|
const drv4 = data.readInt32LE(108);
|
|
9286
|
-
const productAccountKey = new
|
|
9383
|
+
const productAccountKey = new PublicKey(data.slice(112, 144));
|
|
9287
9384
|
const nextPriceAccountKey = PKorNull(data.slice(144, 176));
|
|
9288
9385
|
const previousSlot = readBigUInt64LE(data, 176);
|
|
9289
9386
|
const previousPriceComponent = readBigInt64LE(data, 184);
|
|
@@ -9307,7 +9404,7 @@ const parsePriceData = (data, currentSlot) => {
|
|
|
9307
9404
|
const priceComponents = [];
|
|
9308
9405
|
let offset = 240;
|
|
9309
9406
|
while (priceComponents.length < numComponentPrices) {
|
|
9310
|
-
const publisher = new
|
|
9407
|
+
const publisher = new PublicKey(data.slice(offset, offset + 32));
|
|
9311
9408
|
offset += 32;
|
|
9312
9409
|
const componentAggregate = parsePriceInfo$1(data.slice(offset, offset + 32), exponent);
|
|
9313
9410
|
offset += 32;
|
|
@@ -9389,12 +9486,12 @@ const priceUpdateV2Schema = { struct: {
|
|
|
9389
9486
|
postedSlot: "u64"
|
|
9390
9487
|
} };
|
|
9391
9488
|
const parsePriceInfo = (data) => {
|
|
9392
|
-
const decoded = borsh.deserialize(priceUpdateV2Schema, data);
|
|
9489
|
+
const decoded = borsh$1.deserialize(priceUpdateV2Schema, data);
|
|
9393
9490
|
return decoded;
|
|
9394
9491
|
};
|
|
9395
9492
|
function capConfidenceInterval$1(price, confidence, maxConfidence) {
|
|
9396
9493
|
const maxConfidenceInterval = price.times(maxConfidence);
|
|
9397
|
-
return
|
|
9494
|
+
return BigNumber.min(confidence, maxConfidenceInterval);
|
|
9398
9495
|
}
|
|
9399
9496
|
|
|
9400
9497
|
//#endregion
|
|
@@ -9407,9 +9504,9 @@ var Account = class {
|
|
|
9407
9504
|
* @param program SwitchboardProgram
|
|
9408
9505
|
* @param publicKey PublicKey of the on-chain resource
|
|
9409
9506
|
*/
|
|
9410
|
-
constructor(program, publicKey) {
|
|
9507
|
+
constructor(program, publicKey$1) {
|
|
9411
9508
|
this.program = program;
|
|
9412
|
-
this.publicKey = typeof publicKey === "string" ? new
|
|
9509
|
+
this.publicKey = typeof publicKey$1 === "string" ? new anchor.web3.PublicKey(publicKey$1) : publicKey$1;
|
|
9413
9510
|
}
|
|
9414
9511
|
};
|
|
9415
9512
|
const BUFFER_DISCRIMINATOR = Buffer.from([
|
|
@@ -9484,7 +9581,7 @@ function fromJSON(obj) {
|
|
|
9484
9581
|
}
|
|
9485
9582
|
}
|
|
9486
9583
|
function layout(property) {
|
|
9487
|
-
const ret =
|
|
9584
|
+
const ret = borsh.rustEnum([borsh.struct([], "ModeRoundResolution"), borsh.struct([], "ModeSlidingResolution")]);
|
|
9488
9585
|
if (property !== undefined) {
|
|
9489
9586
|
return ret.replicate(property);
|
|
9490
9587
|
}
|
|
@@ -9506,7 +9603,7 @@ var SwitchboardDecimal = class SwitchboardDecimal {
|
|
|
9506
9603
|
this.scale = fields.scale;
|
|
9507
9604
|
}
|
|
9508
9605
|
static layout(property) {
|
|
9509
|
-
return
|
|
9606
|
+
return borsh.struct([borsh.i128("mantissa"), borsh.u32("scale")], property);
|
|
9510
9607
|
}
|
|
9511
9608
|
static fromDecoded(obj) {
|
|
9512
9609
|
return new SwitchboardDecimal({
|
|
@@ -9528,7 +9625,7 @@ var SwitchboardDecimal = class SwitchboardDecimal {
|
|
|
9528
9625
|
}
|
|
9529
9626
|
static fromJSON(obj) {
|
|
9530
9627
|
return new SwitchboardDecimal({
|
|
9531
|
-
mantissa: new
|
|
9628
|
+
mantissa: new BN$1(obj.mantissa),
|
|
9532
9629
|
scale: obj.scale
|
|
9533
9630
|
});
|
|
9534
9631
|
}
|
|
@@ -9539,7 +9636,7 @@ var SwitchboardDecimal = class SwitchboardDecimal {
|
|
|
9539
9636
|
*/
|
|
9540
9637
|
static from(obj) {
|
|
9541
9638
|
return new SwitchboardDecimal({
|
|
9542
|
-
mantissa: new
|
|
9639
|
+
mantissa: new BN$1(obj.mantissa),
|
|
9543
9640
|
scale: obj.scale
|
|
9544
9641
|
});
|
|
9545
9642
|
}
|
|
@@ -9550,10 +9647,10 @@ var SwitchboardDecimal = class SwitchboardDecimal {
|
|
|
9550
9647
|
*/
|
|
9551
9648
|
static fromBig(big) {
|
|
9552
9649
|
big = big.round(20);
|
|
9553
|
-
let mantissa = new
|
|
9650
|
+
let mantissa = new BN$1(big.c.join(""), 10);
|
|
9554
9651
|
let scale = big.c.slice(1).length - big.e;
|
|
9555
9652
|
if (scale < 0) {
|
|
9556
|
-
mantissa = mantissa.mul(new
|
|
9653
|
+
mantissa = mantissa.mul(new BN$1(10, 10).pow(new BN$1(Math.abs(scale), 10)));
|
|
9557
9654
|
scale = 0;
|
|
9558
9655
|
}
|
|
9559
9656
|
if (scale < 0) {
|
|
@@ -9562,7 +9659,7 @@ var SwitchboardDecimal = class SwitchboardDecimal {
|
|
|
9562
9659
|
if (scale >= 28) {
|
|
9563
9660
|
throw new Error("SwitchboardDecimalExcessiveScaleError");
|
|
9564
9661
|
}
|
|
9565
|
-
mantissa = mantissa.mul(new
|
|
9662
|
+
mantissa = mantissa.mul(new BN$1(big.s, 10));
|
|
9566
9663
|
const result = new SwitchboardDecimal({
|
|
9567
9664
|
mantissa,
|
|
9568
9665
|
scale
|
|
@@ -9582,11 +9679,11 @@ var SwitchboardDecimal = class SwitchboardDecimal {
|
|
|
9582
9679
|
* @return Big representation
|
|
9583
9680
|
*/
|
|
9584
9681
|
toBig() {
|
|
9585
|
-
let mantissa = new
|
|
9682
|
+
let mantissa = new BN$1(this.mantissa, 10);
|
|
9586
9683
|
let s = 1;
|
|
9587
9684
|
const c = [];
|
|
9588
|
-
const ZERO = new
|
|
9589
|
-
const TEN = new
|
|
9685
|
+
const ZERO = new BN$1(0, 10);
|
|
9686
|
+
const TEN = new BN$1(10, 10);
|
|
9590
9687
|
if (mantissa.lt(ZERO)) {
|
|
9591
9688
|
s = -1;
|
|
9592
9689
|
mantissa = mantissa.abs();
|
|
@@ -9596,7 +9693,7 @@ var SwitchboardDecimal = class SwitchboardDecimal {
|
|
|
9596
9693
|
mantissa = mantissa.div(TEN);
|
|
9597
9694
|
}
|
|
9598
9695
|
const e = c.length - this.scale - 1;
|
|
9599
|
-
const result = new
|
|
9696
|
+
const result = new Big(0);
|
|
9600
9697
|
if (c.length === 0) {
|
|
9601
9698
|
return result;
|
|
9602
9699
|
}
|
|
@@ -9658,21 +9755,21 @@ var AggregatorRound = class AggregatorRound {
|
|
|
9658
9755
|
this.errorsFulfilled = fields.errorsFulfilled;
|
|
9659
9756
|
}
|
|
9660
9757
|
static layout(property) {
|
|
9661
|
-
return
|
|
9662
|
-
|
|
9663
|
-
|
|
9664
|
-
|
|
9665
|
-
|
|
9666
|
-
|
|
9758
|
+
return borsh.struct([
|
|
9759
|
+
borsh.u32("numSuccess"),
|
|
9760
|
+
borsh.u32("numError"),
|
|
9761
|
+
borsh.bool("isClosed"),
|
|
9762
|
+
borsh.u64("roundOpenSlot"),
|
|
9763
|
+
borsh.i64("roundOpenTimestamp"),
|
|
9667
9764
|
SwitchboardDecimal.layout("result"),
|
|
9668
9765
|
SwitchboardDecimal.layout("stdDeviation"),
|
|
9669
9766
|
SwitchboardDecimal.layout("minResponse"),
|
|
9670
9767
|
SwitchboardDecimal.layout("maxResponse"),
|
|
9671
|
-
|
|
9672
|
-
|
|
9673
|
-
|
|
9674
|
-
|
|
9675
|
-
|
|
9768
|
+
borsh.array(borsh.publicKey(), 16, "oraclePubkeysData"),
|
|
9769
|
+
borsh.array(SwitchboardDecimal.layout({}), 16, "mediansData"),
|
|
9770
|
+
borsh.array(borsh.i64(), 16, "currentPayout"),
|
|
9771
|
+
borsh.array(borsh.bool(), 16, "mediansFulfilled"),
|
|
9772
|
+
borsh.array(borsh.bool(), 16, "errorsFulfilled")
|
|
9676
9773
|
], property);
|
|
9677
9774
|
}
|
|
9678
9775
|
static fromDecoded(obj) {
|
|
@@ -9734,15 +9831,15 @@ var AggregatorRound = class AggregatorRound {
|
|
|
9734
9831
|
numSuccess: obj.numSuccess,
|
|
9735
9832
|
numError: obj.numError,
|
|
9736
9833
|
isClosed: obj.isClosed,
|
|
9737
|
-
roundOpenSlot: new
|
|
9738
|
-
roundOpenTimestamp: new
|
|
9834
|
+
roundOpenSlot: new BN$1(obj.roundOpenSlot),
|
|
9835
|
+
roundOpenTimestamp: new BN$1(obj.roundOpenTimestamp),
|
|
9739
9836
|
result: SwitchboardDecimal.fromJSON(obj.result),
|
|
9740
9837
|
stdDeviation: SwitchboardDecimal.fromJSON(obj.stdDeviation),
|
|
9741
9838
|
minResponse: SwitchboardDecimal.fromJSON(obj.minResponse),
|
|
9742
9839
|
maxResponse: SwitchboardDecimal.fromJSON(obj.maxResponse),
|
|
9743
|
-
oraclePubkeysData: obj.oraclePubkeysData.map((item) => new
|
|
9840
|
+
oraclePubkeysData: obj.oraclePubkeysData.map((item) => new PublicKey(item)),
|
|
9744
9841
|
mediansData: obj.mediansData.map((item) => SwitchboardDecimal.fromJSON(item)),
|
|
9745
|
-
currentPayout: obj.currentPayout.map((item) => new
|
|
9842
|
+
currentPayout: obj.currentPayout.map((item) => new BN$1(item)),
|
|
9746
9843
|
mediansFulfilled: obj.mediansFulfilled,
|
|
9747
9844
|
errorsFulfilled: obj.errorsFulfilled
|
|
9748
9845
|
});
|
|
@@ -9761,7 +9858,7 @@ var Hash = class Hash {
|
|
|
9761
9858
|
this.data = fields.data;
|
|
9762
9859
|
}
|
|
9763
9860
|
static layout(property) {
|
|
9764
|
-
return
|
|
9861
|
+
return borsh.struct([borsh.array(borsh.u8(), 32, "data")], property);
|
|
9765
9862
|
}
|
|
9766
9863
|
static fromDecoded(obj) {
|
|
9767
9864
|
return new Hash({ data: obj.data });
|
|
@@ -9865,42 +9962,42 @@ var AggregatorAccountData = class AggregatorAccountData {
|
|
|
9865
9962
|
27,
|
|
9866
9963
|
125
|
|
9867
9964
|
]);
|
|
9868
|
-
static layout =
|
|
9869
|
-
|
|
9870
|
-
|
|
9871
|
-
|
|
9872
|
-
|
|
9873
|
-
|
|
9874
|
-
|
|
9875
|
-
|
|
9876
|
-
|
|
9877
|
-
|
|
9965
|
+
static layout = borsh.struct([
|
|
9966
|
+
borsh.array(borsh.u8(), 32, "name"),
|
|
9967
|
+
borsh.array(borsh.u8(), 128, "metadata"),
|
|
9968
|
+
borsh.array(borsh.u8(), 32, "reserved1"),
|
|
9969
|
+
borsh.publicKey("queuePubkey"),
|
|
9970
|
+
borsh.u32("oracleRequestBatchSize"),
|
|
9971
|
+
borsh.u32("minOracleResults"),
|
|
9972
|
+
borsh.u32("minJobResults"),
|
|
9973
|
+
borsh.u32("minUpdateDelaySeconds"),
|
|
9974
|
+
borsh.i64("startAfter"),
|
|
9878
9975
|
SwitchboardDecimal.layout("varianceThreshold"),
|
|
9879
|
-
|
|
9880
|
-
|
|
9881
|
-
|
|
9882
|
-
|
|
9883
|
-
|
|
9884
|
-
|
|
9976
|
+
borsh.i64("forceReportPeriod"),
|
|
9977
|
+
borsh.i64("expiration"),
|
|
9978
|
+
borsh.u64("consecutiveFailureCount"),
|
|
9979
|
+
borsh.i64("nextAllowedUpdateTime"),
|
|
9980
|
+
borsh.bool("isLocked"),
|
|
9981
|
+
borsh.publicKey("crankPubkey"),
|
|
9885
9982
|
AggregatorRound.layout("latestConfirmedRound"),
|
|
9886
9983
|
AggregatorRound.layout("currentRound"),
|
|
9887
|
-
|
|
9888
|
-
|
|
9889
|
-
|
|
9890
|
-
|
|
9891
|
-
|
|
9892
|
-
|
|
9984
|
+
borsh.array(borsh.publicKey(), 16, "jobPubkeysData"),
|
|
9985
|
+
borsh.array(Hash.layout({}), 16, "jobHashes"),
|
|
9986
|
+
borsh.u32("jobPubkeysSize"),
|
|
9987
|
+
borsh.array(borsh.u8(), 32, "jobsChecksum"),
|
|
9988
|
+
borsh.publicKey("authority"),
|
|
9989
|
+
borsh.publicKey("historyBuffer"),
|
|
9893
9990
|
SwitchboardDecimal.layout("previousConfirmedRoundResult"),
|
|
9894
|
-
|
|
9895
|
-
|
|
9896
|
-
|
|
9897
|
-
|
|
9991
|
+
borsh.u64("previousConfirmedRoundSlot"),
|
|
9992
|
+
borsh.bool("disableCrank"),
|
|
9993
|
+
borsh.array(borsh.u8(), 16, "jobWeights"),
|
|
9994
|
+
borsh.i64("creationTimestamp"),
|
|
9898
9995
|
layout("resolutionMode"),
|
|
9899
|
-
|
|
9900
|
-
|
|
9901
|
-
|
|
9902
|
-
|
|
9903
|
-
|
|
9996
|
+
borsh.u32("basePriorityFee"),
|
|
9997
|
+
borsh.u32("priorityFeeBump"),
|
|
9998
|
+
borsh.u32("priorityFeeBumpPeriod"),
|
|
9999
|
+
borsh.u32("maxPriorityFeeMultiplier"),
|
|
10000
|
+
borsh.array(borsh.u8(), 122, "ebuf")
|
|
9904
10001
|
]);
|
|
9905
10002
|
constructor(fields) {
|
|
9906
10003
|
this.name = fields.name;
|
|
@@ -13650,9 +13747,9 @@ var idl_default = {
|
|
|
13650
13747
|
//#endregion
|
|
13651
13748
|
//#region src/vendor/switchboard_pull/index.ts
|
|
13652
13749
|
const SWITCHBOARD_ONDEMANDE_PRICE_PRECISION = 18;
|
|
13653
|
-
const switchboardAccountCoder = new
|
|
13750
|
+
const switchboardAccountCoder = new BorshCoder(idl_default);
|
|
13654
13751
|
function getSwitchboardProgram(provider) {
|
|
13655
|
-
return new
|
|
13752
|
+
return new Program(idl_default, provider);
|
|
13656
13753
|
}
|
|
13657
13754
|
function decodeSwitchboardPullFeedData(data) {
|
|
13658
13755
|
const pullFeedDAta = switchboardAccountCoder.accounts.decode("PullFeedAccountData", data);
|
|
@@ -13674,7 +13771,17 @@ function getPrice(oraclePrice, priceBias = PriceBias.None, weightedPrice = false
|
|
|
13674
13771
|
}
|
|
13675
13772
|
function capConfidenceInterval(price, confidence, maxConfidence) {
|
|
13676
13773
|
const maxConfidenceInterval = price.times(maxConfidence);
|
|
13677
|
-
return
|
|
13774
|
+
return BigNumber.min(confidence, maxConfidenceInterval);
|
|
13775
|
+
}
|
|
13776
|
+
const supportedOracleSetups = [
|
|
13777
|
+
OracleSetup.PythLegacy,
|
|
13778
|
+
OracleSetup.PythPushOracle,
|
|
13779
|
+
OracleSetup.StakedWithPythPush,
|
|
13780
|
+
OracleSetup.SwitchboardV2,
|
|
13781
|
+
OracleSetup.SwitchboardPull
|
|
13782
|
+
];
|
|
13783
|
+
function isOracleSetupSupported(oracleSetup) {
|
|
13784
|
+
return supportedOracleSetups.includes(oracleSetup);
|
|
13678
13785
|
}
|
|
13679
13786
|
function parseOraclePriceData(oracleSetup, rawData, logger = new NoopLogger(), shardId) {
|
|
13680
13787
|
switch (oracleSetup) {
|
|
@@ -13688,14 +13795,14 @@ function parseOraclePriceData(oracleSetup, rawData, logger = new NoopLogger(), s
|
|
|
13688
13795
|
if (confidenceData === undefined) {
|
|
13689
13796
|
confidenceData = pythPriceData.previousConfidence;
|
|
13690
13797
|
}
|
|
13691
|
-
const pythPriceRealtime = new
|
|
13692
|
-
const pythConfidenceRealtime = new
|
|
13693
|
-
const pythConfidenceRealtimeCapped = capConfidenceInterval(pythPriceRealtime, pythConfidenceRealtime,
|
|
13798
|
+
const pythPriceRealtime = new BigNumber(priceData);
|
|
13799
|
+
const pythConfidenceRealtime = new BigNumber(confidenceData).times(PYTH_PRICE_CONF_INTERVALS);
|
|
13800
|
+
const pythConfidenceRealtimeCapped = capConfidenceInterval(pythPriceRealtime, pythConfidenceRealtime, PYTH_PRICE_CONF_INTERVALS);
|
|
13694
13801
|
const pythLowestPriceRealtime = pythPriceRealtime.minus(pythConfidenceRealtimeCapped);
|
|
13695
13802
|
const pythHighestPriceRealtime = pythPriceRealtime.plus(pythConfidenceRealtimeCapped);
|
|
13696
|
-
const pythPriceWeighted = new
|
|
13697
|
-
const pythConfIntervalWeighted = new
|
|
13698
|
-
const pythConfIntervalWeightedCapped = capConfidenceInterval(pythPriceWeighted, pythConfIntervalWeighted,
|
|
13803
|
+
const pythPriceWeighted = new BigNumber(pythPriceData.emaPrice.value);
|
|
13804
|
+
const pythConfIntervalWeighted = new BigNumber(pythPriceData.emaConfidence.value).times(PYTH_PRICE_CONF_INTERVALS);
|
|
13805
|
+
const pythConfIntervalWeightedCapped = capConfidenceInterval(pythPriceWeighted, pythConfIntervalWeighted, PYTH_PRICE_CONF_INTERVALS);
|
|
13699
13806
|
const pythLowestPrice = pythPriceWeighted.minus(pythConfIntervalWeightedCapped);
|
|
13700
13807
|
const pythHighestPrice = pythPriceWeighted.plus(pythConfIntervalWeightedCapped);
|
|
13701
13808
|
logger.debug({
|
|
@@ -13717,7 +13824,7 @@ function parseOraclePriceData(oracleSetup, rawData, logger = new NoopLogger(), s
|
|
|
13717
13824
|
lowestPrice: pythLowestPrice,
|
|
13718
13825
|
highestPrice: pythHighestPrice
|
|
13719
13826
|
},
|
|
13720
|
-
timestamp: new
|
|
13827
|
+
timestamp: new BigNumber(Number(pythPriceData.timestamp)),
|
|
13721
13828
|
pythShardId: shardId
|
|
13722
13829
|
};
|
|
13723
13830
|
}
|
|
@@ -13725,15 +13832,15 @@ function parseOraclePriceData(oracleSetup, rawData, logger = new NoopLogger(), s
|
|
|
13725
13832
|
case OracleSetup.StakedWithPythPush: {
|
|
13726
13833
|
const bytesWithoutDiscriminator = rawData.slice(8);
|
|
13727
13834
|
const data = parsePriceInfo(bytesWithoutDiscriminator);
|
|
13728
|
-
const exponent = new
|
|
13729
|
-
const priceRealTime = new
|
|
13730
|
-
const confidenceRealTime = new
|
|
13731
|
-
const cappedConfidenceRealTime = capConfidenceInterval(priceRealTime, confidenceRealTime,
|
|
13835
|
+
const exponent = new BigNumber(10 ** data.priceMessage.exponent);
|
|
13836
|
+
const priceRealTime = new BigNumber(Number(data.priceMessage.price)).times(exponent);
|
|
13837
|
+
const confidenceRealTime = new BigNumber(Number(data.priceMessage.conf)).times(exponent).times(PYTH_PRICE_CONF_INTERVALS);
|
|
13838
|
+
const cappedConfidenceRealTime = capConfidenceInterval(priceRealTime, confidenceRealTime, MAX_CONFIDENCE_INTERVAL_RATIO);
|
|
13732
13839
|
const lowestPriceRealTime = priceRealTime.minus(cappedConfidenceRealTime);
|
|
13733
13840
|
const highestPriceRealTime = priceRealTime.plus(cappedConfidenceRealTime);
|
|
13734
|
-
const priceTimeWeighted = new
|
|
13735
|
-
const confidenceTimeWeighted = new
|
|
13736
|
-
const cappedConfidenceWeighted = capConfidenceInterval(priceTimeWeighted, confidenceTimeWeighted,
|
|
13841
|
+
const priceTimeWeighted = new BigNumber(Number(data.priceMessage.emaPrice)).times(exponent);
|
|
13842
|
+
const confidenceTimeWeighted = new BigNumber(Number(data.priceMessage.emaConf)).times(exponent).times(PYTH_PRICE_CONF_INTERVALS);
|
|
13843
|
+
const cappedConfidenceWeighted = capConfidenceInterval(priceTimeWeighted, confidenceTimeWeighted, MAX_CONFIDENCE_INTERVAL_RATIO);
|
|
13737
13844
|
const lowestPriceWeighted = priceTimeWeighted.minus(cappedConfidenceWeighted);
|
|
13738
13845
|
const highestPriceWeighted = priceTimeWeighted.plus(cappedConfidenceWeighted);
|
|
13739
13846
|
return {
|
|
@@ -13749,15 +13856,15 @@ function parseOraclePriceData(oracleSetup, rawData, logger = new NoopLogger(), s
|
|
|
13749
13856
|
lowestPrice: lowestPriceWeighted,
|
|
13750
13857
|
highestPrice: highestPriceWeighted
|
|
13751
13858
|
},
|
|
13752
|
-
timestamp: new
|
|
13859
|
+
timestamp: new BigNumber(Number(data.priceMessage.publishTime)),
|
|
13753
13860
|
pythShardId: shardId
|
|
13754
13861
|
};
|
|
13755
13862
|
}
|
|
13756
13863
|
case OracleSetup.SwitchboardV2: {
|
|
13757
13864
|
const aggData = AggregatorAccountData.decode(rawData);
|
|
13758
|
-
const swbPrice = new
|
|
13759
|
-
const swbConfidence = new
|
|
13760
|
-
const swbConfidenceCapped = capConfidenceInterval(swbPrice, swbConfidence,
|
|
13865
|
+
const swbPrice = new BigNumber(AggregatorAccount.decodeLatestValue(aggData).toString());
|
|
13866
|
+
const swbConfidence = new BigNumber(aggData.latestConfirmedRound.stdDeviation.toBig().toString()).times(SWB_PRICE_CONF_INTERVALS);
|
|
13867
|
+
const swbConfidenceCapped = capConfidenceInterval(swbPrice, swbConfidence, MAX_CONFIDENCE_INTERVAL_RATIO);
|
|
13761
13868
|
const swbLowestPrice = swbPrice.minus(swbConfidenceCapped);
|
|
13762
13869
|
const swbHighestPrice = swbPrice.plus(swbConfidenceCapped);
|
|
13763
13870
|
logger.debug({
|
|
@@ -13777,14 +13884,14 @@ function parseOraclePriceData(oracleSetup, rawData, logger = new NoopLogger(), s
|
|
|
13777
13884
|
lowestPrice: swbLowestPrice,
|
|
13778
13885
|
highestPrice: swbHighestPrice
|
|
13779
13886
|
},
|
|
13780
|
-
timestamp: new
|
|
13887
|
+
timestamp: new BigNumber(aggData.latestConfirmedRound.roundOpenTimestamp)
|
|
13781
13888
|
};
|
|
13782
13889
|
}
|
|
13783
13890
|
case OracleSetup.SwitchboardPull: {
|
|
13784
13891
|
const pullFeedDAta = decodeSwitchboardPullFeedData(rawData);
|
|
13785
|
-
const swbPrice = new
|
|
13786
|
-
const swbConfidence = new
|
|
13787
|
-
const swbConfidenceCapped = capConfidenceInterval(swbPrice, swbConfidence,
|
|
13892
|
+
const swbPrice = new BigNumber(pullFeedDAta.result.value.toString()).div(10 ** SWITCHBOARD_ONDEMANDE_PRICE_PRECISION);
|
|
13893
|
+
const swbConfidence = new BigNumber(pullFeedDAta.result.std_dev.toString()).times(SWB_PRICE_CONF_INTERVALS);
|
|
13894
|
+
const swbConfidenceCapped = capConfidenceInterval(swbPrice, swbConfidence, MAX_CONFIDENCE_INTERVAL_RATIO);
|
|
13788
13895
|
const swbLowestPrice = swbPrice.minus(swbConfidenceCapped);
|
|
13789
13896
|
const swbHighestPrice = swbPrice.plus(swbConfidenceCapped);
|
|
13790
13897
|
logger.debug({
|
|
@@ -13804,7 +13911,7 @@ function parseOraclePriceData(oracleSetup, rawData, logger = new NoopLogger(), s
|
|
|
13804
13911
|
lowestPrice: swbLowestPrice,
|
|
13805
13912
|
highestPrice: swbHighestPrice
|
|
13806
13913
|
},
|
|
13807
|
-
timestamp: new
|
|
13914
|
+
timestamp: new BigNumber(pullFeedDAta.last_update_timestamp.toString())
|
|
13808
13915
|
};
|
|
13809
13916
|
}
|
|
13810
13917
|
default:
|
|
@@ -13818,18 +13925,18 @@ function parseOraclePriceData(oracleSetup, rawData, logger = new NoopLogger(), s
|
|
|
13818
13925
|
function dtoToOraclePrice(dto) {
|
|
13819
13926
|
return {
|
|
13820
13927
|
priceRealtime: {
|
|
13821
|
-
price: new
|
|
13822
|
-
confidence: new
|
|
13823
|
-
lowestPrice: new
|
|
13824
|
-
highestPrice: new
|
|
13928
|
+
price: new BigNumber(dto.priceRealtime.price),
|
|
13929
|
+
confidence: new BigNumber(dto.priceRealtime.confidence),
|
|
13930
|
+
lowestPrice: new BigNumber(dto.priceRealtime.lowestPrice),
|
|
13931
|
+
highestPrice: new BigNumber(dto.priceRealtime.highestPrice)
|
|
13825
13932
|
},
|
|
13826
13933
|
priceWeighted: {
|
|
13827
|
-
price: new
|
|
13828
|
-
confidence: new
|
|
13829
|
-
lowestPrice: new
|
|
13830
|
-
highestPrice: new
|
|
13934
|
+
price: new BigNumber(dto.priceWeighted.price),
|
|
13935
|
+
confidence: new BigNumber(dto.priceWeighted.confidence),
|
|
13936
|
+
lowestPrice: new BigNumber(dto.priceWeighted.lowestPrice),
|
|
13937
|
+
highestPrice: new BigNumber(dto.priceWeighted.highestPrice)
|
|
13831
13938
|
},
|
|
13832
|
-
timestamp: new
|
|
13939
|
+
timestamp: new BigNumber(dto.timestamp),
|
|
13833
13940
|
pythShardId: dto.pythShardId
|
|
13834
13941
|
};
|
|
13835
13942
|
}
|
|
@@ -13868,7 +13975,7 @@ const fetchPythDataViaAPI = async (pythPushBanks, voteAccMintTuples) => {
|
|
|
13868
13975
|
const pythFeedMap = new Map();
|
|
13869
13976
|
Object.entries(pythFeedMapJson).forEach(([feedId, { feedId: feedIdStr, shardId }]) => {
|
|
13870
13977
|
pythFeedMap.set(feedId, {
|
|
13871
|
-
feedId: new
|
|
13978
|
+
feedId: new PublicKey(feedIdStr),
|
|
13872
13979
|
shardId
|
|
13873
13980
|
});
|
|
13874
13981
|
});
|
|
@@ -13926,18 +14033,18 @@ const fetchPythOraclePricesViaAPI = async (pythOracleKeys) => {
|
|
|
13926
14033
|
const responseBody = await response.json();
|
|
13927
14034
|
return Object.fromEntries(Object.entries(responseBody).map(([key, oraclePrice]) => [key, {
|
|
13928
14035
|
priceRealtime: {
|
|
13929
|
-
price: (
|
|
13930
|
-
confidence: (
|
|
13931
|
-
lowestPrice: (
|
|
13932
|
-
highestPrice: (
|
|
14036
|
+
price: BigNumber(oraclePrice.priceRealtime.price),
|
|
14037
|
+
confidence: BigNumber(oraclePrice.priceRealtime.confidence),
|
|
14038
|
+
lowestPrice: BigNumber(oraclePrice.priceRealtime.lowestPrice),
|
|
14039
|
+
highestPrice: BigNumber(oraclePrice.priceRealtime.highestPrice)
|
|
13933
14040
|
},
|
|
13934
14041
|
priceWeighted: {
|
|
13935
|
-
price: (
|
|
13936
|
-
confidence: (
|
|
13937
|
-
lowestPrice: (
|
|
13938
|
-
highestPrice: (
|
|
14042
|
+
price: BigNumber(oraclePrice.priceWeighted.price),
|
|
14043
|
+
confidence: BigNumber(oraclePrice.priceWeighted.confidence),
|
|
14044
|
+
lowestPrice: BigNumber(oraclePrice.priceWeighted.lowestPrice),
|
|
14045
|
+
highestPrice: BigNumber(oraclePrice.priceWeighted.highestPrice)
|
|
13939
14046
|
},
|
|
13940
|
-
timestamp: oraclePrice.timestamp ? (
|
|
14047
|
+
timestamp: oraclePrice.timestamp ? BigNumber(oraclePrice.timestamp) : null,
|
|
13941
14048
|
pythShardId: oraclePrice.pythShardId
|
|
13942
14049
|
}]));
|
|
13943
14050
|
};
|
|
@@ -14056,18 +14163,18 @@ const fetchSwbOraclePricesViaAPI = async (swbFeedIds) => {
|
|
|
14056
14163
|
const responseBody = await response.json();
|
|
14057
14164
|
return Object.fromEntries(Object.entries(responseBody).map(([key, oraclePrice]) => [key, {
|
|
14058
14165
|
priceRealtime: {
|
|
14059
|
-
price: (
|
|
14060
|
-
confidence: (
|
|
14061
|
-
lowestPrice: (
|
|
14062
|
-
highestPrice: (
|
|
14166
|
+
price: BigNumber(oraclePrice.priceRealtime.price),
|
|
14167
|
+
confidence: BigNumber(oraclePrice.priceRealtime.confidence),
|
|
14168
|
+
lowestPrice: BigNumber(oraclePrice.priceRealtime.lowestPrice),
|
|
14169
|
+
highestPrice: BigNumber(oraclePrice.priceRealtime.highestPrice)
|
|
14063
14170
|
},
|
|
14064
14171
|
priceWeighted: {
|
|
14065
|
-
price: (
|
|
14066
|
-
confidence: (
|
|
14067
|
-
lowestPrice: (
|
|
14068
|
-
highestPrice: (
|
|
14172
|
+
price: BigNumber(oraclePrice.priceWeighted.price),
|
|
14173
|
+
confidence: BigNumber(oraclePrice.priceWeighted.confidence),
|
|
14174
|
+
lowestPrice: BigNumber(oraclePrice.priceWeighted.lowestPrice),
|
|
14175
|
+
highestPrice: BigNumber(oraclePrice.priceWeighted.highestPrice)
|
|
14069
14176
|
},
|
|
14070
|
-
timestamp: oraclePrice.timestamp ? (
|
|
14177
|
+
timestamp: oraclePrice.timestamp ? BigNumber(oraclePrice.timestamp) : null
|
|
14071
14178
|
}]));
|
|
14072
14179
|
};
|
|
14073
14180
|
/**
|
|
@@ -14106,18 +14213,18 @@ const fetchOracleData = async (banks, bankMetadataMap, connection, opts) => {
|
|
|
14106
14213
|
console.error(`Bank ${bank.address.toBase58()} is missing an oracle price`);
|
|
14107
14214
|
bankOraclePriceMap.set(bank.address.toBase58(), {
|
|
14108
14215
|
priceRealtime: {
|
|
14109
|
-
price: (0
|
|
14110
|
-
confidence: (0
|
|
14111
|
-
lowestPrice: (0
|
|
14112
|
-
highestPrice: (0
|
|
14216
|
+
price: BigNumber(0),
|
|
14217
|
+
confidence: BigNumber(0),
|
|
14218
|
+
lowestPrice: BigNumber(0),
|
|
14219
|
+
highestPrice: BigNumber(0)
|
|
14113
14220
|
},
|
|
14114
14221
|
priceWeighted: {
|
|
14115
|
-
price: (0
|
|
14116
|
-
confidence: (0
|
|
14117
|
-
lowestPrice: (0
|
|
14118
|
-
highestPrice: (0
|
|
14222
|
+
price: BigNumber(0),
|
|
14223
|
+
confidence: BigNumber(0),
|
|
14224
|
+
lowestPrice: BigNumber(0),
|
|
14225
|
+
highestPrice: BigNumber(0)
|
|
14119
14226
|
},
|
|
14120
|
-
timestamp: (0
|
|
14227
|
+
timestamp: BigNumber(0)
|
|
14121
14228
|
});
|
|
14122
14229
|
}
|
|
14123
14230
|
});
|
|
@@ -14161,7 +14268,7 @@ function computeMaxLeverage(depositBank, borrowBank, opts) {
|
|
|
14161
14268
|
};
|
|
14162
14269
|
}
|
|
14163
14270
|
function computeLoopingParams(principal, targetLeverage, depositBank, borrowBank, depositOracleInfo, borrowOracleInfo) {
|
|
14164
|
-
const initialCollateral =
|
|
14271
|
+
const initialCollateral = toBigNumber(principal);
|
|
14165
14272
|
const { maxLeverage } = computeMaxLeverage(depositBank, borrowBank);
|
|
14166
14273
|
if (targetLeverage < 1) {
|
|
14167
14274
|
throw Error(`Target leverage ${targetLeverage} needs to be greater than 1`);
|
|
@@ -14169,7 +14276,7 @@ function computeLoopingParams(principal, targetLeverage, depositBank, borrowBank
|
|
|
14169
14276
|
if (targetLeverage > maxLeverage) {
|
|
14170
14277
|
throw Error(`Target leverage ${targetLeverage} exceeds max leverage for banks ${maxLeverage}`);
|
|
14171
14278
|
}
|
|
14172
|
-
const totalDepositAmount = initialCollateral.times(new
|
|
14279
|
+
const totalDepositAmount = initialCollateral.times(new BigNumber(targetLeverage));
|
|
14173
14280
|
const additionalDepositAmount = totalDepositAmount.minus(initialCollateral);
|
|
14174
14281
|
const borrowAmount = additionalDepositAmount.times(depositOracleInfo.priceWeighted.lowestPrice).div(borrowOracleInfo.priceWeighted.highestPrice);
|
|
14175
14282
|
return {
|
|
@@ -14210,7 +14317,7 @@ function getAssetWeight(bank, lendrRequirementType, oraclePrice, opts) {
|
|
|
14210
14317
|
}
|
|
14211
14318
|
}
|
|
14212
14319
|
case LendrRequirementType.Maintenance: return bank.config.assetWeightMaint;
|
|
14213
|
-
case LendrRequirementType.Equity: return new
|
|
14320
|
+
case LendrRequirementType.Equity: return new BigNumber(1);
|
|
14214
14321
|
default: throw new Error("Invalid lendr requirement type");
|
|
14215
14322
|
}
|
|
14216
14323
|
}
|
|
@@ -14218,7 +14325,7 @@ function getLiabilityWeight(config, lendrRequirementType) {
|
|
|
14218
14325
|
switch (lendrRequirementType) {
|
|
14219
14326
|
case LendrRequirementType.Initial: return config.liabilityWeightInit;
|
|
14220
14327
|
case LendrRequirementType.Maintenance: return config.liabilityWeightMaint;
|
|
14221
|
-
case LendrRequirementType.Equity: return new
|
|
14328
|
+
case LendrRequirementType.Equity: return new BigNumber(1);
|
|
14222
14329
|
default: throw new Error("Invalid lendr requirement type");
|
|
14223
14330
|
}
|
|
14224
14331
|
}
|
|
@@ -14249,7 +14356,7 @@ function computeInterestRates(bank) {
|
|
|
14249
14356
|
const baseInterestRate = computeBaseInterestRate(bank);
|
|
14250
14357
|
const utilizationRate = computeUtilizationRate(bank);
|
|
14251
14358
|
const lendingRate = baseInterestRate.times(utilizationRate);
|
|
14252
|
-
const borrowingRate = baseInterestRate.times(new
|
|
14359
|
+
const borrowingRate = baseInterestRate.times(new BigNumber(1).plus(rateFee)).plus(fixedFee);
|
|
14253
14360
|
return {
|
|
14254
14361
|
lendingRate,
|
|
14255
14362
|
borrowingRate
|
|
@@ -14261,22 +14368,22 @@ function computeBaseInterestRate(bank) {
|
|
|
14261
14368
|
if (utilizationRate.lte(optimalUtilizationRate)) {
|
|
14262
14369
|
return utilizationRate.times(plateauInterestRate).div(optimalUtilizationRate);
|
|
14263
14370
|
} else {
|
|
14264
|
-
return utilizationRate.minus(optimalUtilizationRate).div(new
|
|
14371
|
+
return utilizationRate.minus(optimalUtilizationRate).div(new BigNumber(1).minus(optimalUtilizationRate)).times(maxInterestRate.minus(plateauInterestRate)).plus(plateauInterestRate);
|
|
14265
14372
|
}
|
|
14266
14373
|
}
|
|
14267
14374
|
function computeUtilizationRate(bank) {
|
|
14268
14375
|
const assets = getTotalAssetQuantity(bank);
|
|
14269
14376
|
const liabilities = getTotalLiabilityQuantity(bank);
|
|
14270
|
-
if (assets.isZero()) return new
|
|
14377
|
+
if (assets.isZero()) return new BigNumber(0);
|
|
14271
14378
|
return liabilities.div(assets);
|
|
14272
14379
|
}
|
|
14273
14380
|
const SECONDS_PER_DAY$1 = 24 * 60 * 60;
|
|
14274
14381
|
const SECONDS_PER_YEAR$1 = SECONDS_PER_DAY$1 * 365.25;
|
|
14275
14382
|
function computeRemainingCapacity(bank) {
|
|
14276
14383
|
const totalDeposits = getTotalAssetQuantity(bank);
|
|
14277
|
-
const remainingCapacity =
|
|
14384
|
+
const remainingCapacity = BigNumber.max(0, bank.config.depositLimit.minus(totalDeposits));
|
|
14278
14385
|
const totalBorrows = getTotalLiabilityQuantity(bank);
|
|
14279
|
-
const remainingBorrowCapacity =
|
|
14386
|
+
const remainingBorrowCapacity = BigNumber.max(0, bank.config.borrowLimit.minus(totalBorrows));
|
|
14280
14387
|
const durationSinceLastAccrual = Date.now() / 1e3 - bank.lastUpdate;
|
|
14281
14388
|
const { lendingRate, borrowingRate } = computeInterestRates(bank);
|
|
14282
14389
|
const outstandingLendingInterest = lendingRate.times(durationSinceLastAccrual).dividedBy(SECONDS_PER_YEAR$1).times(totalDeposits);
|
|
@@ -14299,7 +14406,7 @@ const fetchMultipleBanks = async (program, opts) => {
|
|
|
14299
14406
|
data.forEach((d, idx) => {
|
|
14300
14407
|
if (d) {
|
|
14301
14408
|
bankDatas.push({
|
|
14302
|
-
address: new
|
|
14409
|
+
address: new PublicKey(addresses[idx]),
|
|
14303
14410
|
data: d
|
|
14304
14411
|
});
|
|
14305
14412
|
} else {
|
|
@@ -14323,8 +14430,8 @@ const fetchMultipleBanks = async (program, opts) => {
|
|
|
14323
14430
|
//#endregion
|
|
14324
14431
|
//#region src/services/bank/utils/serialize.utils.ts
|
|
14325
14432
|
function serializeBankConfigOpt(bankConfigOpt) {
|
|
14326
|
-
const toWrappedI80F48 = (value) => value &&
|
|
14327
|
-
const toBN = (value) => value && new
|
|
14433
|
+
const toWrappedI80F48 = (value) => value && bigNumberToWrappedI80F48(value);
|
|
14434
|
+
const toBN = (value) => value && new BN$1(value.toString());
|
|
14328
14435
|
return {
|
|
14329
14436
|
assetWeightInit: toWrappedI80F48(bankConfigOpt.assetWeightInit),
|
|
14330
14437
|
assetWeightMaint: toWrappedI80F48(bankConfigOpt.assetWeightMaint),
|
|
@@ -14594,20 +14701,20 @@ function getPriceFeedAccountForProgram(shardId, priceFeedId, pushOracleProgramId
|
|
|
14594
14701
|
}
|
|
14595
14702
|
const shardBuffer = Buffer.alloc(2);
|
|
14596
14703
|
shardBuffer.writeUint16LE(shardId, 0);
|
|
14597
|
-
return
|
|
14704
|
+
return PublicKey.findProgramAddressSync([shardBuffer, priceFeedId], pushOracleProgramId ?? DEFAULT_PUSH_ORACLE_PROGRAM_ID)[0];
|
|
14598
14705
|
}
|
|
14599
14706
|
const getTreasuryPda = (treasuryId, receiverProgramId) => {
|
|
14600
|
-
return
|
|
14707
|
+
return PublicKey.findProgramAddressSync([Buffer.from("treasury"), Buffer.from([treasuryId])], receiverProgramId)[0];
|
|
14601
14708
|
};
|
|
14602
14709
|
const getConfigPda = (receiverProgramId) => {
|
|
14603
|
-
return
|
|
14710
|
+
return PublicKey.findProgramAddressSync([Buffer.from("config")], receiverProgramId)[0];
|
|
14604
14711
|
};
|
|
14605
14712
|
async function crankPythOracleIx(oracles, provider) {
|
|
14606
14713
|
const feedIdsByShardId = {};
|
|
14607
|
-
const wormholeProgram = new
|
|
14608
|
-
const pushOracleProgram = new
|
|
14609
|
-
const receiverProgram = new
|
|
14610
|
-
const addressLookupTableAccount = new
|
|
14714
|
+
const wormholeProgram = new Program(PYTH_WORMHOLE_IDL, provider);
|
|
14715
|
+
const pushOracleProgram = new Program(PYTH_PUSH_ORACLE_IDL, provider);
|
|
14716
|
+
const receiverProgram = new Program(PYTH_SOLANA_RECEIVER_PROGRAM_IDL, provider);
|
|
14717
|
+
const addressLookupTableAccount = new PublicKey("5DNCErWQFBdvCxWQXaC1mrEFsvL3ftrzZ2gVZWNybaSX");
|
|
14611
14718
|
const lookupTableAccount = (await provider.connection.getAddressLookupTable(addressLookupTableAccount)).value;
|
|
14612
14719
|
const buildURL = (endpoint) => {
|
|
14613
14720
|
return new URL(`./v2/${endpoint}`, `https://hermes.pyth.network/`);
|
|
@@ -14648,7 +14755,7 @@ async function crankPythOracleIx(oracles, provider) {
|
|
|
14648
14755
|
priceFeedAccount: getPriceFeedAccountForProgram(Number(shardId), feedId, pushOracleProgram.programId),
|
|
14649
14756
|
treasury: getTreasuryPda(treasuryId, receiverProgram.programId),
|
|
14650
14757
|
config: getConfigPda(receiverProgram.programId),
|
|
14651
|
-
systemProgram:
|
|
14758
|
+
systemProgram: SYSTEM_PROGRAM_ID
|
|
14652
14759
|
}).instruction(),
|
|
14653
14760
|
signers: [],
|
|
14654
14761
|
computeUnits: UPDATE_PRICE_FEED_COMPUTE_BUDGET
|
|
@@ -14720,7 +14827,7 @@ async function sendTransactionAsBundle(connection, base58Txs, throwError = false
|
|
|
14720
14827
|
throw new SendBundleError(`${API_ERROR_TAG} ${sendBundleResult.error.message}`);
|
|
14721
14828
|
}
|
|
14722
14829
|
const bundleId = sendBundleResult.result;
|
|
14723
|
-
await
|
|
14830
|
+
await sleep(500);
|
|
14724
14831
|
for (let attempt = 0; attempt < 10; attempt++) {
|
|
14725
14832
|
const getBundleStatusResponse = await fetch("https://mainnet.block-engine.jito.wtf/api/v1/bundles", {
|
|
14726
14833
|
method: "POST",
|
|
@@ -14753,7 +14860,7 @@ async function sendTransactionAsBundle(connection, base58Txs, throwError = false
|
|
|
14753
14860
|
await confirmBundle(connection, bundleId);
|
|
14754
14861
|
return bundleId;
|
|
14755
14862
|
}
|
|
14756
|
-
await
|
|
14863
|
+
await sleep(1e3);
|
|
14757
14864
|
}
|
|
14758
14865
|
} catch (error) {
|
|
14759
14866
|
if (throwError) {
|
|
@@ -14767,7 +14874,7 @@ async function confirmBundle(connection, bundleId, commitment = "confirmed") {
|
|
|
14767
14874
|
let attempts = 0;
|
|
14768
14875
|
const maxAttempts = 5;
|
|
14769
14876
|
while (attempts < maxAttempts) {
|
|
14770
|
-
await
|
|
14877
|
+
await sleep(2e3);
|
|
14771
14878
|
attempts += 1;
|
|
14772
14879
|
const getBundleStatus = await fetch("https://mainnet.block-engine.jito.wtf/api/v1/bundles", {
|
|
14773
14880
|
method: "POST",
|
|
@@ -14793,7 +14900,7 @@ async function confirmBundle(connection, bundleId, commitment = "confirmed") {
|
|
|
14793
14900
|
console.log("❌ Transaction failed to confirm in time.");
|
|
14794
14901
|
throw new Error("Transaction failed to confirm in time.");
|
|
14795
14902
|
};
|
|
14796
|
-
const result = await Promise.race([getStatus(),
|
|
14903
|
+
const result = await Promise.race([getStatus(), setTimeoutPromise(2e4, `Transaction failed to confirm in time.`)]);
|
|
14797
14904
|
if (result instanceof Error) {
|
|
14798
14905
|
throw result;
|
|
14799
14906
|
}
|
|
@@ -14829,7 +14936,7 @@ async function simulateBundle(rpcEndpoint, transactions, includeAccounts) {
|
|
|
14829
14936
|
const result = await executeBundleSimulation(rpcEndpoint, encodedTransactions, config);
|
|
14830
14937
|
return result;
|
|
14831
14938
|
} catch (error) {
|
|
14832
|
-
if (error instanceof
|
|
14939
|
+
if (error instanceof SolanaJSONRPCError || error instanceof BundleSimulationError) {
|
|
14833
14940
|
throw error;
|
|
14834
14941
|
} else {
|
|
14835
14942
|
throw new BundleSimulationError("Failed to execute bundle simulation", undefined, error);
|
|
@@ -14935,7 +15042,7 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
14935
15042
|
...DEFAULT_PROCESS_TX_OPTS,
|
|
14936
15043
|
...processOptsArgs
|
|
14937
15044
|
};
|
|
14938
|
-
const commitment = connection.commitment ??
|
|
15045
|
+
const commitment = connection.commitment ?? DEFAULT_CONFIRM_OPTS.commitment;
|
|
14939
15046
|
if (processOpts?.broadcastType === "BUNDLE" && processOpts?.bundleTipUi === 0) {
|
|
14940
15047
|
throw new Error("A bundle tip is required for a bundled transactions");
|
|
14941
15048
|
}
|
|
@@ -14971,7 +15078,7 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
14971
15078
|
lastValidBlockHeight = getLatestBlockhashAndContext.value.lastValidBlockHeight;
|
|
14972
15079
|
} catch (error) {
|
|
14973
15080
|
console.error("Failed to get latest blockhash and context", error);
|
|
14974
|
-
if (error instanceof
|
|
15081
|
+
if (error instanceof SolanaJSONRPCError) {
|
|
14975
15082
|
throw error;
|
|
14976
15083
|
}
|
|
14977
15084
|
throw new ProcessTransactionError({
|
|
@@ -14981,7 +15088,7 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
14981
15088
|
});
|
|
14982
15089
|
}
|
|
14983
15090
|
const mergedOpts = {
|
|
14984
|
-
...
|
|
15091
|
+
...DEFAULT_CONFIRM_OPTS,
|
|
14985
15092
|
commitment,
|
|
14986
15093
|
preflightCommitment: commitment,
|
|
14987
15094
|
minContextSlot,
|
|
@@ -14994,7 +15101,7 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
14994
15101
|
blockhash
|
|
14995
15102
|
});
|
|
14996
15103
|
const unitsConsumed = isSimulatedTransactionResponse(simulationResult) ? [simulationResult.unitsConsumed] : simulationResult.map((tx) => tx.unitsConsumed ? Number(tx.unitsConsumed) : undefined);
|
|
14997
|
-
updatedTransactions = transactions.map((tx, idx) =>
|
|
15104
|
+
updatedTransactions = transactions.map((tx, idx) => addTransactionMetadata(tx, {
|
|
14998
15105
|
...tx,
|
|
14999
15106
|
unitsConsumed: unitsConsumed[idx]
|
|
15000
15107
|
}));
|
|
@@ -15007,8 +15114,8 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
15007
15114
|
console.log(`💸 Bundle tip: ${maxCapUi ? Math.min(processOpts.bundleTipUi ?? 0, maxCapUi) : processOpts.bundleTipUi} SOL`);
|
|
15008
15115
|
} else {
|
|
15009
15116
|
updatedTransactions.forEach((tx, idx) => {
|
|
15010
|
-
const cu = tx.unitsConsumed ? Math.min(tx.unitsConsumed + 5e4, 14e5) :
|
|
15011
|
-
const priorityFeeUi = maxCapUi ? Math.min(processOpts.priorityFeeMicro ?
|
|
15117
|
+
const cu = tx.unitsConsumed ? Math.min(tx.unitsConsumed + 5e4, 14e5) : getComputeBudgetUnits(tx);
|
|
15118
|
+
const priorityFeeUi = maxCapUi ? Math.min(processOpts.priorityFeeMicro ? microLamportsToUi(processOpts.priorityFeeMicro, cu) : 0, maxCapUi) : processOpts.priorityFeeMicro ? microLamportsToUi(processOpts.priorityFeeMicro, cu) : 0;
|
|
15012
15119
|
console.log(`💸 Priority fee for tx ${idx}: ${priorityFeeUi} SOL`);
|
|
15013
15120
|
});
|
|
15014
15121
|
}
|
|
@@ -15028,11 +15135,11 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
15028
15135
|
let base58Txs = [];
|
|
15029
15136
|
if (wallet.signAllTransactions) {
|
|
15030
15137
|
versionedTransactions = await wallet.signAllTransactions(versionedTransactions);
|
|
15031
|
-
base58Txs = versionedTransactions.map((signedTx) => bs58.
|
|
15138
|
+
base58Txs = versionedTransactions.map((signedTx) => bs58.encode(signedTx.serialize()));
|
|
15032
15139
|
} else {
|
|
15033
15140
|
for (let i = 0; i < versionedTransactions.length; i++) {
|
|
15034
15141
|
const signedTx = await wallet.signTransaction(versionedTransactions[i]);
|
|
15035
|
-
const base58Tx = bs58.
|
|
15142
|
+
const base58Tx = bs58.encode(signedTx.serialize());
|
|
15036
15143
|
base58Txs.push(base58Tx);
|
|
15037
15144
|
versionedTransactions[i] = signedTx;
|
|
15038
15145
|
}
|
|
@@ -15044,7 +15151,7 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
15044
15151
|
processOpts.callback?.(undefined, true);
|
|
15045
15152
|
}
|
|
15046
15153
|
let simulateTxs = null;
|
|
15047
|
-
if (!
|
|
15154
|
+
if (!SKIP_SIMULATION) {
|
|
15048
15155
|
simulateTxs = async () => await simulateTransactions(processOpts, connection, versionedTransactions, mergedOpts);
|
|
15049
15156
|
}
|
|
15050
15157
|
const sendTxBundleGrpc = async (throwError) => await sendTransactionAsGrpcBundle(connection, base58Txs, throwError);
|
|
@@ -15064,7 +15171,7 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
15064
15171
|
});
|
|
15065
15172
|
for (const [idx, method] of finalFallbackMethod.entries()) {
|
|
15066
15173
|
const isLast = idx === finalFallbackMethod.length - 1;
|
|
15067
|
-
if (idx === 0 && simulateTxs && !
|
|
15174
|
+
if (idx === 0 && simulateTxs && !SKIP_SIMULATION) {
|
|
15068
15175
|
await simulateTxs();
|
|
15069
15176
|
}
|
|
15070
15177
|
let temporaryBundleSignature;
|
|
@@ -15116,7 +15223,7 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
15116
15223
|
}
|
|
15117
15224
|
} catch (error) {
|
|
15118
15225
|
const failedTxs = transactions.splice(signatures.length);
|
|
15119
|
-
if (error instanceof
|
|
15226
|
+
if (error instanceof SolanaJSONRPCError) {
|
|
15120
15227
|
throw error;
|
|
15121
15228
|
}
|
|
15122
15229
|
if (error instanceof ProcessTransactionError) {
|
|
@@ -15126,12 +15233,12 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
15126
15233
|
throw new ProcessTransactionError({
|
|
15127
15234
|
message: error.message,
|
|
15128
15235
|
type: ProcessTransactionErrorType.TransactionSendingError,
|
|
15129
|
-
programId:
|
|
15236
|
+
programId: PROGRAM_ID.toBase58(),
|
|
15130
15237
|
failedTxs,
|
|
15131
15238
|
_error: error
|
|
15132
15239
|
});
|
|
15133
15240
|
}
|
|
15134
|
-
const parsedError = parseTransactionError(error, processOpts?.programId ??
|
|
15241
|
+
const parsedError = parseTransactionError(error, processOpts?.programId ?? PROGRAM_ID);
|
|
15135
15242
|
if (error?.logs?.length > 0) {
|
|
15136
15243
|
console.log("------ Logs 👇 ------");
|
|
15137
15244
|
console.log(error.logs.join("\n"));
|
|
@@ -15157,7 +15264,7 @@ async function processTransactions({ transactions, connection, wallet, processOp
|
|
|
15157
15264
|
}
|
|
15158
15265
|
}
|
|
15159
15266
|
const simulateTransactions = async (processOpts, connection, solanaTransactions, confirmOpts, txOpts) => {
|
|
15160
|
-
const v0Txs = solanaTransactions.map((tx) =>
|
|
15267
|
+
const v0Txs = solanaTransactions.map((tx) => isV0Tx(tx) ? tx : legacyTxToV0Tx(tx, txOpts));
|
|
15161
15268
|
try {
|
|
15162
15269
|
if (v0Txs.length > 1) {
|
|
15163
15270
|
const response = await simulateBundle(processOpts?.bundleSimRpcEndpoint ?? connection.rpcEndpoint, v0Txs);
|
|
@@ -15171,7 +15278,7 @@ const simulateTransactions = async (processOpts, connection, solanaTransactions,
|
|
|
15171
15278
|
});
|
|
15172
15279
|
if (response.value.err) {
|
|
15173
15280
|
const error = response.value.err;
|
|
15174
|
-
const parsedError = parseTransactionError(error, processOpts?.programId ??
|
|
15281
|
+
const parsedError = parseTransactionError(error, processOpts?.programId ?? PROGRAM_ID);
|
|
15175
15282
|
throw new ProcessTransactionError({
|
|
15176
15283
|
message: parsedError.description ?? JSON.stringify(response.value.err),
|
|
15177
15284
|
type: ProcessTransactionErrorType.SimulationError,
|
|
@@ -15183,7 +15290,7 @@ const simulateTransactions = async (processOpts, connection, solanaTransactions,
|
|
|
15183
15290
|
}
|
|
15184
15291
|
} catch (error) {
|
|
15185
15292
|
if (error instanceof BundleSimulationError) {
|
|
15186
|
-
const parsedError = parseTransactionError(error, processOpts?.programId ??
|
|
15293
|
+
const parsedError = parseTransactionError(error, processOpts?.programId ?? PROGRAM_ID);
|
|
15187
15294
|
throw new ProcessTransactionError({
|
|
15188
15295
|
message: parsedError.description,
|
|
15189
15296
|
type: ProcessTransactionErrorType.SimulationError,
|
|
@@ -15245,12 +15352,12 @@ async function confirmTransaction(connection, signature, commitment = "confirmed
|
|
|
15245
15352
|
}
|
|
15246
15353
|
}
|
|
15247
15354
|
console.log("🔄 Waiting for confirmation...");
|
|
15248
|
-
await
|
|
15355
|
+
await sleep(2e3);
|
|
15249
15356
|
}
|
|
15250
15357
|
console.log("❌ Transaction failed to confirm in time.");
|
|
15251
15358
|
throw new Error("Transaction failed to confirm in time.");
|
|
15252
15359
|
};
|
|
15253
|
-
const result = await Promise.race([getStatus(),
|
|
15360
|
+
const result = await Promise.race([getStatus(), setTimeoutPromise(2e4, `Transaction failed to confirm in time.`)]);
|
|
15254
15361
|
if (result instanceof Error) {
|
|
15255
15362
|
throw result;
|
|
15256
15363
|
}
|
|
@@ -15337,14 +15444,14 @@ const MAX_TX_SIZE$1 = 1232;
|
|
|
15337
15444
|
const BUNDLE_TX_SIZE$1 = 81;
|
|
15338
15445
|
const PRIORITY_TX_SIZE$1 = 44;
|
|
15339
15446
|
function isFlashloan(tx) {
|
|
15340
|
-
if (
|
|
15447
|
+
if (isV0Tx(tx)) {
|
|
15341
15448
|
const addressLookupTableAccounts = tx.addressLookupTables ?? [];
|
|
15342
|
-
const message =
|
|
15449
|
+
const message = decompileV0Transaction(tx, addressLookupTableAccounts);
|
|
15343
15450
|
const idl = {
|
|
15344
15451
|
...LENDR_IDL,
|
|
15345
|
-
address: new
|
|
15452
|
+
address: new PublicKey(0)
|
|
15346
15453
|
};
|
|
15347
|
-
const decoded = message.instructions.map((ix) =>
|
|
15454
|
+
const decoded = message.instructions.map((ix) => decodeInstruction(idl, ix.data));
|
|
15348
15455
|
return decoded.some((ix) => ix?.name.toLowerCase().includes("flashloan"));
|
|
15349
15456
|
}
|
|
15350
15457
|
return false;
|
|
@@ -15373,25 +15480,25 @@ function formatTransactions(transactionsArg, broadcastType, blockhash, feeSettin
|
|
|
15373
15480
|
const { priorityFeeMicro, bundleTipUi, feePayer, maxCapUi } = feeSettings;
|
|
15374
15481
|
const flashloanIndex = getFlashloanIndex(transactionsArg);
|
|
15375
15482
|
transactionsArg.forEach((tx) => {
|
|
15376
|
-
if (!
|
|
15483
|
+
if (!isV0Tx(tx)) {
|
|
15377
15484
|
tx.recentBlockhash = blockhash;
|
|
15378
15485
|
tx.feePayer = feePayer;
|
|
15379
15486
|
}
|
|
15380
15487
|
});
|
|
15381
15488
|
const transactions = addTransactionTags ? addTransactionTxTags(transactionsArg) : transactionsArg;
|
|
15382
|
-
const txSizes = transactions.map((tx) =>
|
|
15489
|
+
const txSizes = transactions.map((tx) => getTxSize(tx));
|
|
15383
15490
|
const dummyPriorityFeeIx = makePriorityFeeMicroIx(1);
|
|
15384
15491
|
const priorityIxs = [];
|
|
15385
15492
|
const cuLimitIxs = [];
|
|
15386
15493
|
transactions.forEach((tx, idx) => {
|
|
15387
|
-
const cu = tx.unitsConsumed ? Math.min(tx.unitsConsumed + 5e4, 14e5) :
|
|
15388
|
-
const priorityFeeUi = maxCapUi ? Math.min(
|
|
15389
|
-
let updatedFees =
|
|
15494
|
+
const cu = tx.unitsConsumed ? Math.min(tx.unitsConsumed + 5e4, 14e5) : getComputeBudgetUnits(tx);
|
|
15495
|
+
const priorityFeeUi = maxCapUi ? Math.min(microLamportsToUi(priorityFeeMicro, cu), maxCapUi) : microLamportsToUi(priorityFeeMicro, cu);
|
|
15496
|
+
let updatedFees = uiToMicroLamports(priorityFeeUi, cu);
|
|
15390
15497
|
if (priorityFeeUi > .1) {
|
|
15391
|
-
updatedFees =
|
|
15498
|
+
updatedFees = uiToMicroLamports(.1, cu);
|
|
15392
15499
|
}
|
|
15393
15500
|
priorityIxs.push(broadcastType === "BUNDLE" ? dummyPriorityFeeIx : makePriorityFeeMicroIx(updatedFees));
|
|
15394
|
-
cuLimitIxs.push(cu ?
|
|
15501
|
+
cuLimitIxs.push(cu ? ComputeBudgetProgram.setComputeUnitLimit({ units: cu }) : undefined);
|
|
15395
15502
|
});
|
|
15396
15503
|
const { bundleTipIx } = makeTxPriorityIx(feePayer, maxCapUi ? Math.min(bundleTipUi, maxCapUi) : bundleTipUi, broadcastType);
|
|
15397
15504
|
let bundleTipIndex = broadcastType === "BUNDLE" ? -1 : null;
|
|
@@ -15409,12 +15516,12 @@ function formatTransactions(transactionsArg, broadcastType, blockhash, feeSettin
|
|
|
15409
15516
|
}
|
|
15410
15517
|
}
|
|
15411
15518
|
if (bundleTipIndex === -1 && bundleTipIx) {
|
|
15412
|
-
const bundleTipMessage = new
|
|
15519
|
+
const bundleTipMessage = new TransactionMessage({
|
|
15413
15520
|
instructions: [bundleTipIx],
|
|
15414
15521
|
payerKey: feePayer,
|
|
15415
15522
|
recentBlockhash: blockhash
|
|
15416
15523
|
});
|
|
15417
|
-
formattedTransactions.push(new
|
|
15524
|
+
formattedTransactions.push(new VersionedTransaction(bundleTipMessage.compileToV0Message()));
|
|
15418
15525
|
}
|
|
15419
15526
|
for (const [index, transaction] of transactions.entries()) {
|
|
15420
15527
|
const hasFlashloan = flashloanIndex !== null;
|
|
@@ -15427,15 +15534,15 @@ function formatTransactions(transactionsArg, broadcastType, blockhash, feeSettin
|
|
|
15427
15534
|
...cuLimitIxs[index] ? [cuLimitIxs[index]] : []
|
|
15428
15535
|
];
|
|
15429
15536
|
let newTransaction;
|
|
15430
|
-
if (
|
|
15431
|
-
newTransaction =
|
|
15537
|
+
if (isV0Tx(transaction)) {
|
|
15538
|
+
newTransaction = updateV0Tx(transaction, {
|
|
15432
15539
|
addressLookupTables,
|
|
15433
15540
|
additionalIxs: requiredIxs,
|
|
15434
15541
|
blockhash,
|
|
15435
15542
|
replaceOnly: isTxFlashloan
|
|
15436
15543
|
});
|
|
15437
15544
|
} else {
|
|
15438
|
-
newTransaction =
|
|
15545
|
+
newTransaction = legacyTxToV0Tx(transaction, {
|
|
15439
15546
|
addressLookupTables,
|
|
15440
15547
|
additionalIxs: requiredIxs,
|
|
15441
15548
|
blockhash,
|
|
@@ -15451,18 +15558,18 @@ function addTransactionTxTags(transactions) {
|
|
|
15451
15558
|
const txWithTags = [];
|
|
15452
15559
|
for (const [_, tx] of transactions.entries()) {
|
|
15453
15560
|
let solanaTx = tx;
|
|
15454
|
-
const arenaKey =
|
|
15561
|
+
const arenaKey = TransactionArenaKeyMap[tx.type];
|
|
15455
15562
|
if (arenaKey) {
|
|
15456
|
-
if (
|
|
15563
|
+
if (isV0Tx(solanaTx)) {
|
|
15457
15564
|
console.log("tx", solanaTx);
|
|
15458
15565
|
const addressLookupTableAccounts = solanaTx.addressLookupTables ?? [];
|
|
15459
|
-
const message =
|
|
15566
|
+
const message = decompileV0Transaction(solanaTx, addressLookupTableAccounts);
|
|
15460
15567
|
message.instructions[0].keys.push({
|
|
15461
15568
|
pubkey: arenaKey,
|
|
15462
15569
|
isSigner: false,
|
|
15463
15570
|
isWritable: false
|
|
15464
15571
|
});
|
|
15465
|
-
solanaTx =
|
|
15572
|
+
solanaTx = addTransactionMetadata(new VersionedTransaction(message.compileToV0Message(tx.addressLookupTables)), {
|
|
15466
15573
|
signers: solanaTx.signers,
|
|
15467
15574
|
addressLookupTables: solanaTx.addressLookupTables,
|
|
15468
15575
|
type: solanaTx.type,
|
|
@@ -15500,7 +15607,7 @@ const SinglePoolInstruction = {
|
|
|
15500
15607
|
const mint = findPoolMintAddress(pool);
|
|
15501
15608
|
const stakeAuthority = findPoolStakeAuthorityAddress(pool);
|
|
15502
15609
|
const mintAuthority = findPoolMintAuthorityAddress(pool);
|
|
15503
|
-
return createTransactionInstruction(
|
|
15610
|
+
return createTransactionInstruction(SINGLE_POOL_PROGRAM_ID, [
|
|
15504
15611
|
{
|
|
15505
15612
|
pubkey: voteAccount,
|
|
15506
15613
|
isSigner: false,
|
|
@@ -15532,37 +15639,37 @@ const SinglePoolInstruction = {
|
|
|
15532
15639
|
isWritable: false
|
|
15533
15640
|
},
|
|
15534
15641
|
{
|
|
15535
|
-
pubkey:
|
|
15642
|
+
pubkey: SYSVAR_RENT_ID,
|
|
15536
15643
|
isSigner: false,
|
|
15537
15644
|
isWritable: false
|
|
15538
15645
|
},
|
|
15539
15646
|
{
|
|
15540
|
-
pubkey:
|
|
15647
|
+
pubkey: SYSVAR_CLOCK_ID,
|
|
15541
15648
|
isSigner: false,
|
|
15542
15649
|
isWritable: false
|
|
15543
15650
|
},
|
|
15544
15651
|
{
|
|
15545
|
-
pubkey:
|
|
15652
|
+
pubkey: SYSVAR_STAKE_HISTORY_ID,
|
|
15546
15653
|
isSigner: false,
|
|
15547
15654
|
isWritable: false
|
|
15548
15655
|
},
|
|
15549
15656
|
{
|
|
15550
|
-
pubkey:
|
|
15657
|
+
pubkey: STAKE_CONFIG_ID$1,
|
|
15551
15658
|
isSigner: false,
|
|
15552
15659
|
isWritable: false
|
|
15553
15660
|
},
|
|
15554
15661
|
{
|
|
15555
|
-
pubkey:
|
|
15662
|
+
pubkey: SYSTEM_PROGRAM_ID,
|
|
15556
15663
|
isSigner: false,
|
|
15557
15664
|
isWritable: false
|
|
15558
15665
|
},
|
|
15559
15666
|
{
|
|
15560
|
-
pubkey:
|
|
15667
|
+
pubkey: TOKEN_PROGRAM_ID,
|
|
15561
15668
|
isSigner: false,
|
|
15562
15669
|
isWritable: false
|
|
15563
15670
|
},
|
|
15564
15671
|
{
|
|
15565
|
-
pubkey:
|
|
15672
|
+
pubkey: STAKE_PROGRAM_ID,
|
|
15566
15673
|
isSigner: false,
|
|
15567
15674
|
isWritable: false
|
|
15568
15675
|
}
|
|
@@ -15571,7 +15678,7 @@ const SinglePoolInstruction = {
|
|
|
15571
15678
|
initializeOnRamp: (pool) => {
|
|
15572
15679
|
const onRamp = findPoolOnRampAddress(pool);
|
|
15573
15680
|
const stakeAuthority = findPoolStakeAuthorityAddress(pool);
|
|
15574
|
-
return createTransactionInstruction(
|
|
15681
|
+
return createTransactionInstruction(SINGLE_POOL_PROGRAM_ID, [
|
|
15575
15682
|
{
|
|
15576
15683
|
pubkey: pool,
|
|
15577
15684
|
isSigner: false,
|
|
@@ -15588,17 +15695,17 @@ const SinglePoolInstruction = {
|
|
|
15588
15695
|
isWritable: false
|
|
15589
15696
|
},
|
|
15590
15697
|
{
|
|
15591
|
-
pubkey:
|
|
15698
|
+
pubkey: SYSVAR_RENT_ID,
|
|
15592
15699
|
isSigner: false,
|
|
15593
15700
|
isWritable: false
|
|
15594
15701
|
},
|
|
15595
15702
|
{
|
|
15596
|
-
pubkey:
|
|
15703
|
+
pubkey: SYSTEM_PROGRAM_ID,
|
|
15597
15704
|
isSigner: false,
|
|
15598
15705
|
isWritable: false
|
|
15599
15706
|
},
|
|
15600
15707
|
{
|
|
15601
|
-
pubkey:
|
|
15708
|
+
pubkey: STAKE_PROGRAM_ID,
|
|
15602
15709
|
isSigner: false,
|
|
15603
15710
|
isWritable: false
|
|
15604
15711
|
}
|
|
@@ -15609,7 +15716,7 @@ const SinglePoolInstruction = {
|
|
|
15609
15716
|
const mint = findPoolMintAddress(pool);
|
|
15610
15717
|
const stakeAuthority = findPoolStakeAuthorityAddress(pool);
|
|
15611
15718
|
const mintAuthority = findPoolMintAuthorityAddress(pool);
|
|
15612
|
-
return createTransactionInstruction(
|
|
15719
|
+
return createTransactionInstruction(SINGLE_POOL_PROGRAM_ID, [
|
|
15613
15720
|
{
|
|
15614
15721
|
pubkey: pool,
|
|
15615
15722
|
isSigner: false,
|
|
@@ -15651,22 +15758,22 @@ const SinglePoolInstruction = {
|
|
|
15651
15758
|
isWritable: true
|
|
15652
15759
|
},
|
|
15653
15760
|
{
|
|
15654
|
-
pubkey:
|
|
15761
|
+
pubkey: SYSVAR_CLOCK_ID,
|
|
15655
15762
|
isSigner: false,
|
|
15656
15763
|
isWritable: false
|
|
15657
15764
|
},
|
|
15658
15765
|
{
|
|
15659
|
-
pubkey:
|
|
15766
|
+
pubkey: SYSVAR_STAKE_HISTORY_ID,
|
|
15660
15767
|
isSigner: false,
|
|
15661
15768
|
isWritable: false
|
|
15662
15769
|
},
|
|
15663
15770
|
{
|
|
15664
|
-
pubkey:
|
|
15771
|
+
pubkey: TOKEN_PROGRAM_ID,
|
|
15665
15772
|
isSigner: false,
|
|
15666
15773
|
isWritable: false
|
|
15667
15774
|
},
|
|
15668
15775
|
{
|
|
15669
|
-
pubkey:
|
|
15776
|
+
pubkey: STAKE_PROGRAM_ID,
|
|
15670
15777
|
isSigner: false,
|
|
15671
15778
|
isWritable: false
|
|
15672
15779
|
}
|
|
@@ -15681,9 +15788,9 @@ const SinglePoolInstruction = {
|
|
|
15681
15788
|
const data = Buffer.concat([
|
|
15682
15789
|
Buffer.from([SinglePoolInstructionType.WithdrawStake]),
|
|
15683
15790
|
userStakeAuthority.toBuffer(),
|
|
15684
|
-
Buffer.from(new
|
|
15791
|
+
Buffer.from(new BN(rawAmount.toString()).toArray("le", 8))
|
|
15685
15792
|
]);
|
|
15686
|
-
return createTransactionInstruction(
|
|
15793
|
+
return createTransactionInstruction(SINGLE_POOL_PROGRAM_ID, [
|
|
15687
15794
|
{
|
|
15688
15795
|
pubkey: pool,
|
|
15689
15796
|
isSigner: false,
|
|
@@ -15720,17 +15827,17 @@ const SinglePoolInstruction = {
|
|
|
15720
15827
|
isWritable: true
|
|
15721
15828
|
},
|
|
15722
15829
|
{
|
|
15723
|
-
pubkey:
|
|
15830
|
+
pubkey: SYSVAR_CLOCK_ID,
|
|
15724
15831
|
isSigner: false,
|
|
15725
15832
|
isWritable: false
|
|
15726
15833
|
},
|
|
15727
15834
|
{
|
|
15728
|
-
pubkey:
|
|
15835
|
+
pubkey: TOKEN_PROGRAM_ID,
|
|
15729
15836
|
isSigner: false,
|
|
15730
15837
|
isWritable: false
|
|
15731
15838
|
},
|
|
15732
15839
|
{
|
|
15733
|
-
pubkey:
|
|
15840
|
+
pubkey: STAKE_PROGRAM_ID,
|
|
15734
15841
|
isSigner: false,
|
|
15735
15842
|
isWritable: false
|
|
15736
15843
|
}
|
|
@@ -15743,7 +15850,7 @@ const SinglePoolInstruction = {
|
|
|
15743
15850
|
findPoolMplAuthorityAddress(pool),
|
|
15744
15851
|
findMplMetadataAddress(mint)
|
|
15745
15852
|
]);
|
|
15746
|
-
return createTransactionInstruction(
|
|
15853
|
+
return createTransactionInstruction(SINGLE_POOL_PROGRAM_ID, [
|
|
15747
15854
|
{
|
|
15748
15855
|
pubkey: pool,
|
|
15749
15856
|
isSigner: false,
|
|
@@ -15775,12 +15882,12 @@ const SinglePoolInstruction = {
|
|
|
15775
15882
|
isWritable: true
|
|
15776
15883
|
},
|
|
15777
15884
|
{
|
|
15778
|
-
pubkey:
|
|
15885
|
+
pubkey: MPL_METADATA_PROGRAM_ID,
|
|
15779
15886
|
isSigner: false,
|
|
15780
15887
|
isWritable: false
|
|
15781
15888
|
},
|
|
15782
15889
|
{
|
|
15783
|
-
pubkey:
|
|
15890
|
+
pubkey: SYSTEM_PROGRAM_ID,
|
|
15784
15891
|
isSigner: false,
|
|
15785
15892
|
isWritable: false
|
|
15786
15893
|
}
|
|
@@ -15808,7 +15915,7 @@ const SinglePoolInstruction = {
|
|
|
15808
15915
|
Buffer.from(new Uint32Array([tokenUri.length]).buffer),
|
|
15809
15916
|
Buffer.from(tokenUri)
|
|
15810
15917
|
]);
|
|
15811
|
-
return createTransactionInstruction(
|
|
15918
|
+
return createTransactionInstruction(SINGLE_POOL_PROGRAM_ID, [
|
|
15812
15919
|
{
|
|
15813
15920
|
pubkey: voteAccount,
|
|
15814
15921
|
isSigner: false,
|
|
@@ -15835,7 +15942,7 @@ const SinglePoolInstruction = {
|
|
|
15835
15942
|
isWritable: true
|
|
15836
15943
|
},
|
|
15837
15944
|
{
|
|
15838
|
-
pubkey:
|
|
15945
|
+
pubkey: MPL_METADATA_PROGRAM_ID,
|
|
15839
15946
|
isSigner: false,
|
|
15840
15947
|
isWritable: false
|
|
15841
15948
|
}
|
|
@@ -15849,8 +15956,8 @@ const createTransactionInstruction = (programId, keys, data) => {
|
|
|
15849
15956
|
data
|
|
15850
15957
|
};
|
|
15851
15958
|
};
|
|
15852
|
-
const findPda = (baseAddress, prefix, programId =
|
|
15853
|
-
const [pda] =
|
|
15959
|
+
const findPda = (baseAddress, prefix, programId = SINGLE_POOL_PROGRAM_ID) => {
|
|
15960
|
+
const [pda] = PublicKey.findProgramAddressSync([Buffer.from(prefix), baseAddress.toBuffer()], programId);
|
|
15854
15961
|
return pda;
|
|
15855
15962
|
};
|
|
15856
15963
|
const findPoolMintAddressByVoteAccount = (voteAccountAddress) => findPda(findPoolAddress(voteAccountAddress), "mint");
|
|
@@ -15862,11 +15969,11 @@ const findPoolMintAuthorityAddress = (poolAddress) => findPda(poolAddress, "mint
|
|
|
15862
15969
|
const findPoolMplAuthorityAddress = (poolAddress) => findPda(poolAddress, "mpl_authority");
|
|
15863
15970
|
const findPoolOnRampAddress = (poolAddress) => findPda(poolAddress, "onramp");
|
|
15864
15971
|
const findMplMetadataAddress = async (poolMintAddress) => {
|
|
15865
|
-
const [pda] =
|
|
15972
|
+
const [pda] = PublicKey.findProgramAddressSync([
|
|
15866
15973
|
Buffer.from("metadata"),
|
|
15867
|
-
|
|
15974
|
+
MPL_METADATA_PROGRAM_ID.toBuffer(),
|
|
15868
15975
|
poolMintAddress.toBuffer()
|
|
15869
|
-
],
|
|
15976
|
+
], MPL_METADATA_PROGRAM_ID);
|
|
15870
15977
|
return pda;
|
|
15871
15978
|
};
|
|
15872
15979
|
const SINGLE_POOL_ACCOUNT_SIZE = BigInt(33);
|
|
@@ -15874,7 +15981,7 @@ const STAKE_ACCOUNT_SIZE = BigInt(200);
|
|
|
15874
15981
|
const MINT_SIZE = BigInt(82);
|
|
15875
15982
|
async function initializeStakedPoolTx(connection, payer, voteAccountAddress) {
|
|
15876
15983
|
const instructions$3 = await initializeStakedPoolIxs(connection, payer, voteAccountAddress);
|
|
15877
|
-
const tx = new
|
|
15984
|
+
const tx = new Transaction().add(...instructions$3);
|
|
15878
15985
|
return tx;
|
|
15879
15986
|
}
|
|
15880
15987
|
async function initializeStakedPoolIxs(connection, payer, voteAccountAddress) {
|
|
@@ -15890,22 +15997,22 @@ async function initializeStakedPoolIxs(connection, payer, voteAccountAddress) {
|
|
|
15890
15997
|
]);
|
|
15891
15998
|
const minimumDelegation = minimumDelegationObj.value;
|
|
15892
15999
|
const instructions$3 = [];
|
|
15893
|
-
instructions$3.push(
|
|
16000
|
+
instructions$3.push(SystemProgram.transfer({
|
|
15894
16001
|
fromPubkey: payer,
|
|
15895
16002
|
toPubkey: poolAddress,
|
|
15896
16003
|
lamports: poolRent
|
|
15897
16004
|
}));
|
|
15898
|
-
instructions$3.push(
|
|
16005
|
+
instructions$3.push(SystemProgram.transfer({
|
|
15899
16006
|
fromPubkey: payer,
|
|
15900
16007
|
toPubkey: stakeAddress,
|
|
15901
|
-
lamports: stakeRent + minimumDelegation +
|
|
16008
|
+
lamports: stakeRent + minimumDelegation + LAMPORTS_PER_SOL * 1
|
|
15902
16009
|
}));
|
|
15903
|
-
instructions$3.push(
|
|
16010
|
+
instructions$3.push(SystemProgram.transfer({
|
|
15904
16011
|
fromPubkey: payer,
|
|
15905
16012
|
toPubkey: onRampAddress,
|
|
15906
16013
|
lamports: stakeRent
|
|
15907
16014
|
}));
|
|
15908
|
-
instructions$3.push(
|
|
16015
|
+
instructions$3.push(SystemProgram.transfer({
|
|
15909
16016
|
fromPubkey: payer,
|
|
15910
16017
|
toPubkey: mintAddress,
|
|
15911
16018
|
lamports: mintRent
|
|
@@ -15918,8 +16025,8 @@ async function initializeStakedPoolIxs(connection, payer, voteAccountAddress) {
|
|
|
15918
16025
|
const createAccountIx = (from, newAccount, lamports, space, programAddress) => {
|
|
15919
16026
|
const data = Buffer.concat([
|
|
15920
16027
|
Buffer.from([0]),
|
|
15921
|
-
Buffer.from(new
|
|
15922
|
-
Buffer.from(new
|
|
16028
|
+
Buffer.from(new BN(lamports).toArray("le", 8)),
|
|
16029
|
+
Buffer.from(new BN(space).toArray("le", 8)),
|
|
15923
16030
|
programAddress.toBuffer()
|
|
15924
16031
|
]);
|
|
15925
16032
|
const accounts$2 = [{
|
|
@@ -15931,7 +16038,7 @@ const createAccountIx = (from, newAccount, lamports, space, programAddress) => {
|
|
|
15931
16038
|
isSigner: true,
|
|
15932
16039
|
isWritable: true
|
|
15933
16040
|
}];
|
|
15934
|
-
return createTransactionInstruction(
|
|
16041
|
+
return createTransactionInstruction(SYSTEM_PROGRAM_ID, accounts$2, data);
|
|
15935
16042
|
};
|
|
15936
16043
|
const createPoolOnrampIx = (voteAccount) => {
|
|
15937
16044
|
const poolAccount = findPoolAddress(voteAccount);
|
|
@@ -15954,25 +16061,25 @@ const createPoolOnrampIx = (voteAccount) => {
|
|
|
15954
16061
|
isWritable: false
|
|
15955
16062
|
},
|
|
15956
16063
|
{
|
|
15957
|
-
pubkey:
|
|
16064
|
+
pubkey: SYSVAR_RENT_PUBKEY,
|
|
15958
16065
|
isSigner: false,
|
|
15959
16066
|
isWritable: false
|
|
15960
16067
|
},
|
|
15961
16068
|
{
|
|
15962
|
-
pubkey:
|
|
16069
|
+
pubkey: SystemProgram.programId,
|
|
15963
16070
|
isSigner: false,
|
|
15964
16071
|
isWritable: false
|
|
15965
16072
|
},
|
|
15966
16073
|
{
|
|
15967
|
-
pubkey:
|
|
16074
|
+
pubkey: StakeProgram.programId,
|
|
15968
16075
|
isSigner: false,
|
|
15969
16076
|
isWritable: false
|
|
15970
16077
|
}
|
|
15971
16078
|
];
|
|
15972
16079
|
const data = Buffer.from(Uint8Array.of(6));
|
|
15973
|
-
return new
|
|
16080
|
+
return new TransactionInstruction({
|
|
15974
16081
|
keys,
|
|
15975
|
-
programId:
|
|
16082
|
+
programId: SINGLE_POOL_PROGRAM_ID,
|
|
15976
16083
|
data
|
|
15977
16084
|
});
|
|
15978
16085
|
};
|
|
@@ -16008,28 +16115,28 @@ const replenishPoolIx = (voteAccount) => {
|
|
|
16008
16115
|
isWritable: false
|
|
16009
16116
|
},
|
|
16010
16117
|
{
|
|
16011
|
-
pubkey:
|
|
16118
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
16012
16119
|
isSigner: false,
|
|
16013
16120
|
isWritable: false
|
|
16014
16121
|
},
|
|
16015
16122
|
{
|
|
16016
|
-
pubkey:
|
|
16123
|
+
pubkey: SYSVAR_STAKE_HISTORY_ID,
|
|
16017
16124
|
isSigner: false,
|
|
16018
16125
|
isWritable: false
|
|
16019
16126
|
},
|
|
16020
16127
|
{
|
|
16021
|
-
pubkey:
|
|
16128
|
+
pubkey: STAKE_CONFIG_ID$1,
|
|
16022
16129
|
isSigner: false,
|
|
16023
16130
|
isWritable: false
|
|
16024
16131
|
},
|
|
16025
16132
|
{
|
|
16026
|
-
pubkey:
|
|
16133
|
+
pubkey: StakeProgram.programId,
|
|
16027
16134
|
isSigner: false,
|
|
16028
16135
|
isWritable: false
|
|
16029
16136
|
}
|
|
16030
16137
|
];
|
|
16031
16138
|
const data = Buffer.from(Uint8Array.of(1));
|
|
16032
|
-
return createTransactionInstruction(
|
|
16139
|
+
return createTransactionInstruction(SINGLE_POOL_PROGRAM_ID, keys, data);
|
|
16033
16140
|
};
|
|
16034
16141
|
|
|
16035
16142
|
//#endregion
|
|
@@ -16042,13 +16149,13 @@ function computeFreeCollateral(lendrAccount, opts) {
|
|
|
16042
16149
|
const _clamped = opts?.clamped ?? true;
|
|
16043
16150
|
const { assets, liabilities } = computeHealthComponents(lendrAccount, LendrRequirementType.Initial);
|
|
16044
16151
|
const signedFreeCollateral = assets.minus(liabilities);
|
|
16045
|
-
return _clamped ?
|
|
16152
|
+
return _clamped ? BigNumber.max(0, signedFreeCollateral) : signedFreeCollateral;
|
|
16046
16153
|
}
|
|
16047
16154
|
function computeFreeCollateralLegacy(activeBalances, banks, oraclePrices, opts) {
|
|
16048
16155
|
const _clamped = opts?.clamped ?? true;
|
|
16049
16156
|
const { assets, liabilities } = computeHealthComponentsLegacy(activeBalances, banks, oraclePrices, LendrRequirementType.Initial, []);
|
|
16050
16157
|
const signedFreeCollateral = assets.minus(liabilities);
|
|
16051
|
-
return _clamped ?
|
|
16158
|
+
return _clamped ? BigNumber.max(0, signedFreeCollateral) : signedFreeCollateral;
|
|
16052
16159
|
}
|
|
16053
16160
|
function computeHealthComponents(lendrAccount, lendrReqType) {
|
|
16054
16161
|
switch (lendrReqType) {
|
|
@@ -16071,19 +16178,19 @@ function computeHealthComponentsLegacy(activeBalances, banks, oraclePrices, lend
|
|
|
16071
16178
|
const [assets, liabilities] = filteredBalances.map((accountBalance) => {
|
|
16072
16179
|
const bank = banks.get(accountBalance.bankPk.toBase58());
|
|
16073
16180
|
if (!bank) {
|
|
16074
|
-
console.warn(`Bank ${
|
|
16075
|
-
return [new
|
|
16181
|
+
console.warn(`Bank ${shortenAddress(accountBalance.bankPk)} not found, excluding from health computation`);
|
|
16182
|
+
return [new BigNumber(0), new BigNumber(0)];
|
|
16076
16183
|
}
|
|
16077
16184
|
const priceInfo = oraclePrices.get(accountBalance.bankPk.toBase58());
|
|
16078
16185
|
if (!priceInfo) {
|
|
16079
|
-
console.warn(`Price info for bank ${
|
|
16080
|
-
return [new
|
|
16186
|
+
console.warn(`Price info for bank ${shortenAddress(accountBalance.bankPk)} not found, excluding from health computation`);
|
|
16187
|
+
return [new BigNumber(0), new BigNumber(0)];
|
|
16081
16188
|
}
|
|
16082
16189
|
const { assets: assets$1, liabilities: liabilities$1 } = getBalanceUsdValueWithPriceBias(accountBalance, bank, priceInfo, lendrReqType);
|
|
16083
16190
|
return [assets$1, liabilities$1];
|
|
16084
16191
|
}).reduce(([asset, liability], [d, l]) => {
|
|
16085
16192
|
return [asset.plus(d), liability.plus(l)];
|
|
16086
|
-
}, [new
|
|
16193
|
+
}, [new BigNumber(0), new BigNumber(0)]);
|
|
16087
16194
|
return {
|
|
16088
16195
|
assets,
|
|
16089
16196
|
liabilities
|
|
@@ -16093,19 +16200,19 @@ function computeHealthComponentsWithoutBiasLegacy(activeBalances, banks, oracleP
|
|
|
16093
16200
|
const [assets, liabilities] = activeBalances.map((accountBalance) => {
|
|
16094
16201
|
const bank = banks.get(accountBalance.bankPk.toBase58());
|
|
16095
16202
|
if (!bank) {
|
|
16096
|
-
console.warn(`Bank ${
|
|
16097
|
-
return [new
|
|
16203
|
+
console.warn(`Bank ${shortenAddress(accountBalance.bankPk)} not found, excluding from health computation`);
|
|
16204
|
+
return [new BigNumber(0), new BigNumber(0)];
|
|
16098
16205
|
}
|
|
16099
16206
|
const priceInfo = oraclePrices.get(accountBalance.bankPk.toBase58());
|
|
16100
16207
|
if (!priceInfo) {
|
|
16101
|
-
console.warn(`Price info for bank ${
|
|
16102
|
-
return [new
|
|
16208
|
+
console.warn(`Price info for bank ${shortenAddress(accountBalance.bankPk)} not found, excluding from health computation`);
|
|
16209
|
+
return [new BigNumber(0), new BigNumber(0)];
|
|
16103
16210
|
}
|
|
16104
16211
|
const { assets: assets$1, liabilities: liabilities$1 } = computeBalanceUsdValue(accountBalance, bank, priceInfo, lendrReqType);
|
|
16105
16212
|
return [assets$1, liabilities$1];
|
|
16106
16213
|
}).reduce(([asset, liability], [d, l]) => {
|
|
16107
16214
|
return [asset.plus(d), liability.plus(l)];
|
|
16108
|
-
}, [new
|
|
16215
|
+
}, [new BigNumber(0), new BigNumber(0)]);
|
|
16109
16216
|
return {
|
|
16110
16217
|
assets,
|
|
16111
16218
|
liabilities
|
|
@@ -16121,17 +16228,17 @@ function computeNetApy(lendrAccount, activeBalances, banks, oraclePrices) {
|
|
|
16121
16228
|
const apr = activeBalances.reduce((weightedApr, balance) => {
|
|
16122
16229
|
const bank = banks.get(balance.bankPk.toBase58());
|
|
16123
16230
|
if (!bank) {
|
|
16124
|
-
console.warn(`Bank ${
|
|
16231
|
+
console.warn(`Bank ${shortenAddress(balance.bankPk)} not found, excluding from APY computation`);
|
|
16125
16232
|
return weightedApr;
|
|
16126
16233
|
}
|
|
16127
16234
|
const priceInfo = oraclePrices.get(balance.bankPk.toBase58());
|
|
16128
16235
|
if (!priceInfo) {
|
|
16129
|
-
console.warn(`Price info for bank ${
|
|
16236
|
+
console.warn(`Price info for bank ${shortenAddress(balance.bankPk)} not found, excluding from APY computation`);
|
|
16130
16237
|
return weightedApr;
|
|
16131
16238
|
}
|
|
16132
16239
|
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
|
|
16240
|
+
}, new BigNumber(0)).toNumber();
|
|
16241
|
+
return aprToApy(apr);
|
|
16135
16242
|
}
|
|
16136
16243
|
/**
|
|
16137
16244
|
* Lendr Balance Computes
|
|
@@ -16162,8 +16269,8 @@ function computeQuantity(balance, bank) {
|
|
|
16162
16269
|
};
|
|
16163
16270
|
}
|
|
16164
16271
|
function computeQuantityUi(balance, bank) {
|
|
16165
|
-
const assetsQuantity = new
|
|
16166
|
-
const liabilitiesQuantity = new
|
|
16272
|
+
const assetsQuantity = new BigNumber(nativeToUi(getAssetQuantity(bank, balance.assetShares), bank.mintDecimals));
|
|
16273
|
+
const liabilitiesQuantity = new BigNumber(nativeToUi(getLiabilityQuantity(bank, balance.liabilityShares), bank.mintDecimals));
|
|
16167
16274
|
return {
|
|
16168
16275
|
assets: assetsQuantity,
|
|
16169
16276
|
liabilities: liabilitiesQuantity
|
|
@@ -16181,13 +16288,13 @@ function computeClaimedEmissions(balance, bank, currentTimestamp) {
|
|
|
16181
16288
|
}
|
|
16182
16289
|
if (balanceAmount) {
|
|
16183
16290
|
const lastUpdate = balance.lastUpdate;
|
|
16184
|
-
const period = new
|
|
16185
|
-
const emissionsRate = new
|
|
16291
|
+
const period = new BigNumber(currentTimestamp - lastUpdate);
|
|
16292
|
+
const emissionsRate = new BigNumber(bank.emissionsRate);
|
|
16186
16293
|
const emissions = period.times(balanceAmount).times(emissionsRate).div(31536e3 * 10 ** bank.mintDecimals);
|
|
16187
|
-
const emissionsReal =
|
|
16294
|
+
const emissionsReal = BigNumber.min(emissions, new BigNumber(bank.emissionsRemaining));
|
|
16188
16295
|
return emissionsReal;
|
|
16189
16296
|
}
|
|
16190
|
-
return new
|
|
16297
|
+
return new BigNumber(0);
|
|
16191
16298
|
}
|
|
16192
16299
|
function computeTotalOutstandingEmissions(balance, bank) {
|
|
16193
16300
|
const claimedEmissions = balance.emissionsOutstanding;
|
|
@@ -16225,7 +16332,7 @@ function computeHealthCheckAccounts(balances, banks, mandatoryBanks = [], exclud
|
|
|
16225
16332
|
return projectedActiveBanks;
|
|
16226
16333
|
}
|
|
16227
16334
|
function computeHealthAccountMetas(banksToInclude, bankMetadataMap, enableSorting = true, bankExtendedMetadata) {
|
|
16228
|
-
const wrapperFn = enableSorting ?
|
|
16335
|
+
const wrapperFn = enableSorting ? composeRemainingAccounts : (banksAndOracles) => banksAndOracles.flat();
|
|
16229
16336
|
const accounts$2 = wrapperFn(banksToInclude.map((bank) => {
|
|
16230
16337
|
const keys = [bank.address, bank.oracleKey];
|
|
16231
16338
|
if (bank.config.assetTag === 2) {
|
|
@@ -16237,7 +16344,7 @@ function computeHealthAccountMetas(banksToInclude, bankMetadataMap, enableSortin
|
|
|
16237
16344
|
if (!validatorVoteAccount) {
|
|
16238
16345
|
throw Error(`no validatorVoteAccount on Bank metadata: ${bank.address.toBase58()}`);
|
|
16239
16346
|
}
|
|
16240
|
-
const pool = findPoolAddress(new
|
|
16347
|
+
const pool = findPoolAddress(new PublicKey(validatorVoteAccount));
|
|
16241
16348
|
const solPool = findPoolStakeAddress(pool);
|
|
16242
16349
|
const lstMint = findPoolMintAddress(pool);
|
|
16243
16350
|
keys.push(lstMint, solPool);
|
|
@@ -16266,7 +16373,7 @@ var Balance = class Balance {
|
|
|
16266
16373
|
return new Balance(balance.active, balance.bankPk, balance.assetShares, balance.liabilityShares, balance.emissionsOutstanding, balance.lastUpdate);
|
|
16267
16374
|
}
|
|
16268
16375
|
static createEmpty(bankPk) {
|
|
16269
|
-
return new Balance(false, bankPk, new
|
|
16376
|
+
return new Balance(false, bankPk, new BigNumber(0), new BigNumber(0), new BigNumber(0), 0);
|
|
16270
16377
|
}
|
|
16271
16378
|
computeUsdValue(bank, oraclePrice, lendrRequirementType = LendrRequirementType.Equity) {
|
|
16272
16379
|
return computeBalanceUsdValue(this, bank, oraclePrice, lendrRequirementType);
|
|
@@ -16350,15 +16457,15 @@ let AccountFlags = /* @__PURE__ */ function(AccountFlags$1) {
|
|
|
16350
16457
|
//#endregion
|
|
16351
16458
|
//#region src/services/account/utils/deserialize.utils.ts
|
|
16352
16459
|
function decodeAccountRaw(encoded, idl) {
|
|
16353
|
-
const coder = new
|
|
16460
|
+
const coder = new BorshCoder(idl);
|
|
16354
16461
|
return coder.accounts.decode(AccountType.LendrAccount, encoded);
|
|
16355
16462
|
}
|
|
16356
16463
|
function parseBalanceRaw(balanceRaw) {
|
|
16357
16464
|
const active = typeof balanceRaw.active === "number" ? balanceRaw.active === 1 : balanceRaw.active;
|
|
16358
16465
|
const bankPk = balanceRaw.bankPk;
|
|
16359
|
-
const assetShares =
|
|
16360
|
-
const liabilityShares =
|
|
16361
|
-
const emissionsOutstanding =
|
|
16466
|
+
const assetShares = wrappedI80F48toBigNumber(balanceRaw.assetShares);
|
|
16467
|
+
const liabilityShares = wrappedI80F48toBigNumber(balanceRaw.liabilityShares);
|
|
16468
|
+
const emissionsOutstanding = wrappedI80F48toBigNumber(balanceRaw.emissionsOutstanding);
|
|
16362
16469
|
const lastUpdate = balanceRaw.lastUpdate.toNumber();
|
|
16363
16470
|
return {
|
|
16364
16471
|
active,
|
|
@@ -16404,7 +16511,7 @@ function getActiveAccountFlags(flags) {
|
|
|
16404
16511
|
* Check if an account flag is set
|
|
16405
16512
|
*/
|
|
16406
16513
|
function hasAccountFlag(flags, flag) {
|
|
16407
|
-
return !flags.and(new
|
|
16514
|
+
return !flags.and(new BN$1(flag)).isZero();
|
|
16408
16515
|
}
|
|
16409
16516
|
/**
|
|
16410
16517
|
* Convert on-chain health cache flags (BN) to an array of HealthCacheFlags enum values
|
|
@@ -16454,34 +16561,34 @@ function getHealthCacheStatusDescription(flags) {
|
|
|
16454
16561
|
}
|
|
16455
16562
|
function dtoToLendrAccount(lendrAccountDto) {
|
|
16456
16563
|
return {
|
|
16457
|
-
address: new
|
|
16458
|
-
group: new
|
|
16459
|
-
authority: new
|
|
16564
|
+
address: new PublicKey(lendrAccountDto.address),
|
|
16565
|
+
group: new PublicKey(lendrAccountDto.group),
|
|
16566
|
+
authority: new PublicKey(lendrAccountDto.authority),
|
|
16460
16567
|
balances: lendrAccountDto.balances.map(dtoToBalance),
|
|
16461
16568
|
accountFlags: lendrAccountDto.accountFlags,
|
|
16462
|
-
emissionsDestinationAccount: new
|
|
16569
|
+
emissionsDestinationAccount: new PublicKey(lendrAccountDto.emissionsDestinationAccount),
|
|
16463
16570
|
healthCache: dtoToHealthCache(lendrAccountDto.healthCache)
|
|
16464
16571
|
};
|
|
16465
16572
|
}
|
|
16466
16573
|
function dtoToBalance(balanceDto) {
|
|
16467
16574
|
return {
|
|
16468
16575
|
active: balanceDto.active,
|
|
16469
|
-
bankPk: new
|
|
16470
|
-
assetShares: new
|
|
16471
|
-
liabilityShares: new
|
|
16472
|
-
emissionsOutstanding: new
|
|
16576
|
+
bankPk: new PublicKey(balanceDto.bankPk),
|
|
16577
|
+
assetShares: new BigNumber(balanceDto.assetShares),
|
|
16578
|
+
liabilityShares: new BigNumber(balanceDto.liabilityShares),
|
|
16579
|
+
emissionsOutstanding: new BigNumber(balanceDto.emissionsOutstanding),
|
|
16473
16580
|
lastUpdate: balanceDto.lastUpdate
|
|
16474
16581
|
};
|
|
16475
16582
|
}
|
|
16476
16583
|
function dtoToHealthCache(healthCacheDto) {
|
|
16477
16584
|
return {
|
|
16478
|
-
assetValue: new
|
|
16479
|
-
liabilityValue: new
|
|
16480
|
-
assetValueMaint: new
|
|
16481
|
-
liabilityValueMaint: new
|
|
16482
|
-
assetValueEquity: new
|
|
16483
|
-
liabilityValueEquity: new
|
|
16484
|
-
timestamp: new
|
|
16585
|
+
assetValue: new BigNumber(healthCacheDto.assetValue),
|
|
16586
|
+
liabilityValue: new BigNumber(healthCacheDto.liabilityValue),
|
|
16587
|
+
assetValueMaint: new BigNumber(healthCacheDto.assetValueMaint),
|
|
16588
|
+
liabilityValueMaint: new BigNumber(healthCacheDto.liabilityValueMaint),
|
|
16589
|
+
assetValueEquity: new BigNumber(healthCacheDto.assetValueEquity),
|
|
16590
|
+
liabilityValueEquity: new BigNumber(healthCacheDto.liabilityValueEquity),
|
|
16591
|
+
timestamp: new BigNumber(healthCacheDto.timestamp),
|
|
16485
16592
|
flags: healthCacheDto.flags,
|
|
16486
16593
|
prices: healthCacheDto.prices,
|
|
16487
16594
|
simulationFailed: healthCacheDto.simulationFailed
|
|
@@ -16668,7 +16775,7 @@ const fetchLendrAccountData = async (program, lendrAccountPk, bankMap, oraclePri
|
|
|
16668
16775
|
* Convert numeric flag to BN for Solana compatibility
|
|
16669
16776
|
*/
|
|
16670
16777
|
function accountFlagToBN(flag) {
|
|
16671
|
-
return new
|
|
16778
|
+
return new BN$1(flag);
|
|
16672
16779
|
}
|
|
16673
16780
|
function lendrAccountToDto(lendrAccount) {
|
|
16674
16781
|
return {
|
|
@@ -16737,14 +16844,14 @@ async function simulateAccountHealthCacheWithFallback(props) {
|
|
|
16737
16844
|
balances: props.balances,
|
|
16738
16845
|
bankMetadataMap: props.bankMetadataMap
|
|
16739
16846
|
});
|
|
16740
|
-
simulatedAccount.healthCache.assetValueEquity =
|
|
16741
|
-
simulatedAccount.healthCache.liabilityValueEquity =
|
|
16847
|
+
simulatedAccount.healthCache.assetValueEquity = bigNumberToWrappedI80F48(assetValueEquity);
|
|
16848
|
+
simulatedAccount.healthCache.liabilityValueEquity = bigNumberToWrappedI80F48(liabilityValueEquity);
|
|
16742
16849
|
lendrAccount = LendrAccount.fromAccountParsed(props.lendrAccount.address, simulatedAccount);
|
|
16743
16850
|
} catch (e) {
|
|
16744
16851
|
console.log("e", e);
|
|
16745
16852
|
const { assets: assetValueMaint, liabilities: liabilityValueMaint } = computeHealthComponentsLegacy(activeBalances, props.bankMap, props.oraclePrices, LendrRequirementType.Maintenance);
|
|
16746
16853
|
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
|
|
16854
|
+
lendrAccount.setHealthCache(new HealthCache(assetValueInitial, liabilityValueInitial, assetValueMaint, liabilityValueMaint, assetValueEquity, liabilityValueEquity, new BigNumber(0), [], [], true));
|
|
16748
16855
|
if (e instanceof HealthCacheSimulationError) {
|
|
16749
16856
|
return {
|
|
16750
16857
|
lendrAccount,
|
|
@@ -16758,10 +16865,10 @@ async function simulateAccountHealthCache(props) {
|
|
|
16758
16865
|
const { program, bankMap, oraclePrices, lendrAccountPk, balances, bankMetadataMap } = props;
|
|
16759
16866
|
const activeBalances = balances.filter((b) => b.active);
|
|
16760
16867
|
const { stalePythFeeds, staleSwbOracles } = getActiveStaleBanks(activeBalances, bankMap, [], oraclePrices, 30);
|
|
16761
|
-
const computeIx =
|
|
16868
|
+
const computeIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 14e5 });
|
|
16762
16869
|
const blockhash = (await program.provider.connection.getLatestBlockhash("confirmed")).blockhash;
|
|
16763
|
-
const fundAccountIx =
|
|
16764
|
-
fromPubkey: new
|
|
16870
|
+
const fundAccountIx = SystemProgram.transfer({
|
|
16871
|
+
fromPubkey: new PublicKey("DD3AeAssFvjqTvRTrRAtpfjkBF8FpVKnFuwnMLN9haXD"),
|
|
16765
16872
|
toPubkey: program.provider.publicKey,
|
|
16766
16873
|
lamports: 1e8
|
|
16767
16874
|
});
|
|
@@ -16782,7 +16889,7 @@ async function simulateAccountHealthCache(props) {
|
|
|
16782
16889
|
const pythLut = crankPythIxs.lut ? [crankPythIxs.lut] : [];
|
|
16783
16890
|
const txs = [];
|
|
16784
16891
|
if (crankPythIxs.postInstructions.length > 0) {
|
|
16785
|
-
txs.push(...
|
|
16892
|
+
txs.push(...splitInstructionsToFitTransactions([computeIx], [
|
|
16786
16893
|
fundAccountIx,
|
|
16787
16894
|
...crankPythIxs.postInstructions.map((ix) => ix.instruction),
|
|
16788
16895
|
...crankPythIxs.closeInstructions.map((ix) => ix.instruction)
|
|
@@ -16792,19 +16899,19 @@ async function simulateAccountHealthCache(props) {
|
|
|
16792
16899
|
luts: [...crankSwbIxs.luts, ...pythLut]
|
|
16793
16900
|
}));
|
|
16794
16901
|
}
|
|
16795
|
-
const messageV0 = new
|
|
16902
|
+
const messageV0 = new TransactionMessage({
|
|
16796
16903
|
payerKey: program.provider.publicKey,
|
|
16797
16904
|
recentBlockhash: blockhash,
|
|
16798
16905
|
instructions: [...crankSwbIxs.instructions]
|
|
16799
16906
|
}).compileToV0Message([...crankSwbIxs.luts]);
|
|
16800
|
-
const swbTx = new
|
|
16907
|
+
const swbTx = new VersionedTransaction(messageV0);
|
|
16801
16908
|
txs.push(swbTx);
|
|
16802
|
-
const healthTx = new
|
|
16909
|
+
const healthTx = new TransactionMessage({
|
|
16803
16910
|
payerKey: program.provider.publicKey,
|
|
16804
16911
|
recentBlockhash: blockhash,
|
|
16805
16912
|
instructions: [...healthPulseIxs.instructions]
|
|
16806
16913
|
}).compileToV0Message([]);
|
|
16807
|
-
const healthTxV0 = new
|
|
16914
|
+
const healthTxV0 = new VersionedTransaction(healthTx);
|
|
16808
16915
|
txs.push(healthTxV0);
|
|
16809
16916
|
if (txs.length > 5) {
|
|
16810
16917
|
console.error("Too many transactions", txs.length);
|
|
@@ -16821,12 +16928,12 @@ async function simulateAccountHealthCache(props) {
|
|
|
16821
16928
|
console.log("LendrAccountPost healthCache internalErr", lendrAccountPost.healthCache.internalErr);
|
|
16822
16929
|
console.log("LendrAccountPost healthCache lndrErr", lendrAccountPost.healthCache.lendrErr);
|
|
16823
16930
|
if (lendrAccountPost.healthCache.lendrErr === 6009) {
|
|
16824
|
-
const assetValue = !
|
|
16825
|
-
const liabilityValue = !
|
|
16826
|
-
const assetValueEquity = !
|
|
16827
|
-
const liabilityValueEquity = !
|
|
16828
|
-
const assetValueMaint = !
|
|
16829
|
-
const liabilityValueMaint = !
|
|
16931
|
+
const assetValue = !wrappedI80F48toBigNumber(lendrAccountPost.healthCache.assetValue).isZero();
|
|
16932
|
+
const liabilityValue = !wrappedI80F48toBigNumber(lendrAccountPost.healthCache.liabilityValue).isZero();
|
|
16933
|
+
const assetValueEquity = !wrappedI80F48toBigNumber(lendrAccountPost.healthCache.assetValueEquity).isZero();
|
|
16934
|
+
const liabilityValueEquity = !wrappedI80F48toBigNumber(lendrAccountPost.healthCache.liabilityValueEquity).isZero();
|
|
16935
|
+
const assetValueMaint = !wrappedI80F48toBigNumber(lendrAccountPost.healthCache.assetValueMaint).isZero();
|
|
16936
|
+
const liabilityValueMaint = !wrappedI80F48toBigNumber(lendrAccountPost.healthCache.liabilityValueMaint).isZero();
|
|
16830
16937
|
if (assetValue && liabilityValue && assetValueEquity && liabilityValueEquity && assetValueMaint && liabilityValueMaint) {
|
|
16831
16938
|
return lendrAccountPost;
|
|
16832
16939
|
}
|
|
@@ -16862,15 +16969,15 @@ async function createUpdateFeedIx(props) {
|
|
|
16862
16969
|
*/
|
|
16863
16970
|
async function createLendrAccountTx(props) {
|
|
16864
16971
|
const authority = props.lendrAccount?.authority ?? props.lendrClient.provider.publicKey;
|
|
16865
|
-
const lendrAccountKeypair =
|
|
16866
|
-
const dummyWrappedI80F48 =
|
|
16972
|
+
const lendrAccountKeypair = Keypair.generate();
|
|
16973
|
+
const dummyWrappedI80F48 = bigNumberToWrappedI80F48(new BigNumber(0));
|
|
16867
16974
|
const dummyBalances = Array(15).fill({
|
|
16868
16975
|
active: false,
|
|
16869
|
-
bankPk: new
|
|
16976
|
+
bankPk: new PublicKey("11111111111111111111111111111111"),
|
|
16870
16977
|
assetShares: dummyWrappedI80F48,
|
|
16871
16978
|
liabilityShares: dummyWrappedI80F48,
|
|
16872
16979
|
emissionsOutstanding: dummyWrappedI80F48,
|
|
16873
|
-
lastUpdate: new
|
|
16980
|
+
lastUpdate: new BN$1(0)
|
|
16874
16981
|
});
|
|
16875
16982
|
const rawAccount = {
|
|
16876
16983
|
group: props.lendrClient.group.address,
|
|
@@ -16913,21 +17020,21 @@ async function createLendrAccountTx(props) {
|
|
|
16913
17020
|
0,
|
|
16914
17021
|
0
|
|
16915
17022
|
] },
|
|
16916
|
-
timestamp: new
|
|
17023
|
+
timestamp: new BN$1(0),
|
|
16917
17024
|
flags: 0,
|
|
16918
17025
|
prices: [],
|
|
16919
|
-
assetValueMaint:
|
|
16920
|
-
liabilityValueMaint:
|
|
16921
|
-
assetValueEquity:
|
|
16922
|
-
liabilityValueEquity:
|
|
17026
|
+
assetValueMaint: bigNumberToWrappedI80F48(new BigNumber(0)),
|
|
17027
|
+
liabilityValueMaint: bigNumberToWrappedI80F48(new BigNumber(0)),
|
|
17028
|
+
assetValueEquity: bigNumberToWrappedI80F48(new BigNumber(0)),
|
|
17029
|
+
liabilityValueEquity: bigNumberToWrappedI80F48(new BigNumber(0)),
|
|
16923
17030
|
errIndex: 0,
|
|
16924
17031
|
internalErr: 0,
|
|
16925
17032
|
internalBankruptcyErr: 0,
|
|
16926
17033
|
internalLiqErr: 0,
|
|
16927
17034
|
lendrErr: 0
|
|
16928
17035
|
},
|
|
16929
|
-
emissionsDestinationAccount: new
|
|
16930
|
-
accountFlags: new
|
|
17036
|
+
emissionsDestinationAccount: new PublicKey("11111111111111111111111111111111"),
|
|
17037
|
+
accountFlags: new BN$1([
|
|
16931
17038
|
0,
|
|
16932
17039
|
0,
|
|
16933
17040
|
0
|
|
@@ -16995,28 +17102,28 @@ function getActiveStaleBanks(balances, banks, additionalBanks, oraclePrices, max
|
|
|
16995
17102
|
//#endregion
|
|
16996
17103
|
//#region src/services/group/group.service.ts
|
|
16997
17104
|
async function makeEnableFlashLoanForAccountIx(program, lendrAccountAddress) {
|
|
16998
|
-
const ix = await instructions_default.makeSetAccountFlagIx(program, { lendrAccount: lendrAccountAddress }, { flag: new
|
|
17105
|
+
const ix = await instructions_default.makeSetAccountFlagIx(program, { lendrAccount: lendrAccountAddress }, { flag: new BN$1(FLASHLOAN_ENABLED_FLAG) });
|
|
16999
17106
|
return {
|
|
17000
17107
|
instructions: [ix],
|
|
17001
17108
|
keys: []
|
|
17002
17109
|
};
|
|
17003
17110
|
}
|
|
17004
17111
|
async function makeDisableFlashLoanForAccountIx(program, lendrAccountAddress) {
|
|
17005
|
-
const ix = await instructions_default.makeUnsetAccountFlagIx(program, { lendrAccount: lendrAccountAddress }, { flag: new
|
|
17112
|
+
const ix = await instructions_default.makeUnsetAccountFlagIx(program, { lendrAccount: lendrAccountAddress }, { flag: new BN$1(FLASHLOAN_ENABLED_FLAG) });
|
|
17006
17113
|
return {
|
|
17007
17114
|
instructions: [ix],
|
|
17008
17115
|
keys: []
|
|
17009
17116
|
};
|
|
17010
17117
|
}
|
|
17011
17118
|
async function makeEnableAccountTransferForAccountIx(program, lendrAccountAddress) {
|
|
17012
|
-
const ix = await instructions_default.makeSetAccountFlagIx(program, { lendrAccount: lendrAccountAddress }, { flag: new
|
|
17119
|
+
const ix = await instructions_default.makeSetAccountFlagIx(program, { lendrAccount: lendrAccountAddress }, { flag: new BN$1(TRANSFER_ACCOUNT_AUTHORITY_FLAG) });
|
|
17013
17120
|
return {
|
|
17014
17121
|
instructions: [ix],
|
|
17015
17122
|
keys: []
|
|
17016
17123
|
};
|
|
17017
17124
|
}
|
|
17018
17125
|
async function makeDisableAccountTransferForAccountIx(program, lendrAccountAddress) {
|
|
17019
|
-
const ix = await instructions_default.makeUnsetAccountFlagIx(program, { lendrAccount: lendrAccountAddress }, { flag: new
|
|
17126
|
+
const ix = await instructions_default.makeUnsetAccountFlagIx(program, { lendrAccount: lendrAccountAddress }, { flag: new BN$1(TRANSFER_ACCOUNT_AUTHORITY_FLAG) });
|
|
17020
17127
|
return {
|
|
17021
17128
|
instructions: [ix],
|
|
17022
17129
|
keys: []
|
|
@@ -17030,7 +17137,7 @@ async function makePoolConfigureBankIx(program, bank, args) {
|
|
|
17030
17137
|
};
|
|
17031
17138
|
}
|
|
17032
17139
|
async function makeAddPermissionlessStakedBankIx(program, group, voteAccountAddress, feePayer, pythOracle) {
|
|
17033
|
-
const [settingsKey] =
|
|
17140
|
+
const [settingsKey] = PublicKey.findProgramAddressSync([Buffer.from("staked_settings", "utf-8"), group.toBuffer()], program.programId);
|
|
17034
17141
|
const poolAddress = findPoolAddress(voteAccountAddress);
|
|
17035
17142
|
const solPool = findPoolStakeAddress(poolAddress);
|
|
17036
17143
|
const lstMint = findPoolMintAddress(poolAddress);
|
|
@@ -17052,25 +17159,25 @@ async function makeAddPermissionlessStakedBankIx(program, group, voteAccountAddr
|
|
|
17052
17159
|
isWritable: false
|
|
17053
17160
|
},
|
|
17054
17161
|
{
|
|
17055
|
-
pubkey:
|
|
17162
|
+
pubkey: SYSVAR_RENT_PUBKEY,
|
|
17056
17163
|
isSigner: false,
|
|
17057
17164
|
isWritable: false
|
|
17058
17165
|
},
|
|
17059
17166
|
{
|
|
17060
|
-
pubkey:
|
|
17167
|
+
pubkey: SystemProgram.programId,
|
|
17061
17168
|
isSigner: false,
|
|
17062
17169
|
isWritable: false
|
|
17063
17170
|
},
|
|
17064
17171
|
{
|
|
17065
|
-
pubkey:
|
|
17172
|
+
pubkey: StakeProgram.programId,
|
|
17066
17173
|
isSigner: false,
|
|
17067
17174
|
isWritable: false
|
|
17068
17175
|
}
|
|
17069
17176
|
];
|
|
17070
17177
|
const data = Buffer.from(Uint8Array.of(6));
|
|
17071
|
-
const onrampIx = new
|
|
17178
|
+
const onrampIx = new TransactionInstruction({
|
|
17072
17179
|
keys,
|
|
17073
|
-
programId:
|
|
17180
|
+
programId: SINGLE_POOL_PROGRAM_ID,
|
|
17074
17181
|
data
|
|
17075
17182
|
});
|
|
17076
17183
|
const remainingKeys = [
|
|
@@ -17088,13 +17195,13 @@ async function makeAddPermissionlessStakedBankIx(program, group, voteAccountAddr
|
|
|
17088
17195
|
pubkey: key,
|
|
17089
17196
|
isSigner: false,
|
|
17090
17197
|
isWritable: false
|
|
17091
|
-
})), { seed: new
|
|
17198
|
+
})), { seed: new BN$1(0) });
|
|
17092
17199
|
return {
|
|
17093
17200
|
instructions: [ix],
|
|
17094
17201
|
keys: []
|
|
17095
17202
|
};
|
|
17096
17203
|
}
|
|
17097
|
-
async function makePoolAddBankIx(program, group, bank, feePayer, bankMint, bankConfig, tokenProgram =
|
|
17204
|
+
async function makePoolAddBankIx(program, group, bank, feePayer, bankMint, bankConfig, tokenProgram = TOKEN_PROGRAM_ID, overrideOpt = {}) {
|
|
17098
17205
|
const rawBankConfig = serializeBankConfigOpt(bankConfig);
|
|
17099
17206
|
const rawBankConfigCompact = {
|
|
17100
17207
|
...rawBankConfig,
|
|
@@ -17120,8 +17227,8 @@ async function makePoolAddBankIx(program, group, bank, feePayer, bankMint, bankC
|
|
|
17120
17227
|
//#region src/services/group/utils/deserialize.utils.ts
|
|
17121
17228
|
function dtoToGroup(groupDto) {
|
|
17122
17229
|
return {
|
|
17123
|
-
admin: new
|
|
17124
|
-
address: new
|
|
17230
|
+
admin: new PublicKey(groupDto.admin),
|
|
17231
|
+
address: new PublicKey(groupDto.address)
|
|
17125
17232
|
};
|
|
17126
17233
|
}
|
|
17127
17234
|
|
|
@@ -17138,16 +17245,16 @@ function groupToDto(group) {
|
|
|
17138
17245
|
//#region src/services/native-stake/utils/deserialize.utils.ts
|
|
17139
17246
|
function dtoToValidatorStakeGroup(validatorStakeGroupDto) {
|
|
17140
17247
|
return {
|
|
17141
|
-
validator: new
|
|
17142
|
-
poolKey: new
|
|
17143
|
-
poolMintKey: new
|
|
17248
|
+
validator: new PublicKey(validatorStakeGroupDto.validator),
|
|
17249
|
+
poolKey: new PublicKey(validatorStakeGroupDto.poolKey),
|
|
17250
|
+
poolMintKey: new PublicKey(validatorStakeGroupDto.poolMintKey),
|
|
17144
17251
|
totalStake: validatorStakeGroupDto.totalStake,
|
|
17145
17252
|
selectedAccount: {
|
|
17146
|
-
pubkey: new
|
|
17253
|
+
pubkey: new PublicKey(validatorStakeGroupDto.selectedAccount.pubkey),
|
|
17147
17254
|
amount: validatorStakeGroupDto.selectedAccount.amount
|
|
17148
17255
|
},
|
|
17149
17256
|
accounts: validatorStakeGroupDto.accounts.map((account) => ({
|
|
17150
|
-
pubkey: new
|
|
17257
|
+
pubkey: new PublicKey(account.pubkey),
|
|
17151
17258
|
amount: account.amount
|
|
17152
17259
|
}))
|
|
17153
17260
|
};
|
|
@@ -17165,26 +17272,26 @@ function dtoToValidatorStakeGroup(validatorStakeGroupDto) {
|
|
|
17165
17272
|
* @param opts - Options for filtering inactive stake accounts
|
|
17166
17273
|
* @returns {Promise<ValidatorStakeGroup[]>} An array of validator stake groups
|
|
17167
17274
|
*/
|
|
17168
|
-
const fetchNativeStakeAccounts = async (connection, publicKey, opts = { filterInactive: true }) => {
|
|
17169
|
-
if (!connection || !publicKey) {
|
|
17275
|
+
const fetchNativeStakeAccounts = async (connection, publicKey$1, opts = { filterInactive: true }) => {
|
|
17276
|
+
if (!connection || !publicKey$1) {
|
|
17170
17277
|
throw new Error("Invalid connection or public key");
|
|
17171
17278
|
}
|
|
17172
17279
|
try {
|
|
17173
17280
|
const epochInfo = await connection.getEpochInfo();
|
|
17174
|
-
const accounts$2 = await connection.getParsedProgramAccounts(
|
|
17281
|
+
const accounts$2 = await connection.getParsedProgramAccounts(StakeProgram.programId, { filters: [{ memcmp: {
|
|
17175
17282
|
offset: 12,
|
|
17176
|
-
bytes: publicKey.toBase58()
|
|
17283
|
+
bytes: publicKey$1.toBase58()
|
|
17177
17284
|
} }] });
|
|
17178
17285
|
const validatorMap = new Map();
|
|
17179
17286
|
await Promise.all(accounts$2.map(async (acc) => {
|
|
17180
17287
|
const parsedAccount = acc.account.data;
|
|
17181
17288
|
const stakeInfo = parsedAccount.parsed.info;
|
|
17182
|
-
if (!stakeInfo.stake?.delegation || opts.filterInactive && (Number(stakeInfo.stake.delegation.activationEpoch) >= epochInfo.epoch || stakeInfo.stake.delegation.deactivationEpoch !==
|
|
17289
|
+
if (!stakeInfo.stake?.delegation || opts.filterInactive && (Number(stakeInfo.stake.delegation.activationEpoch) >= epochInfo.epoch || stakeInfo.stake.delegation.deactivationEpoch !== MAX_U64)) {
|
|
17183
17290
|
return;
|
|
17184
17291
|
}
|
|
17185
17292
|
const validatorAddress = stakeInfo.stake.delegation.voter;
|
|
17186
17293
|
const accountPubkey = acc.pubkey;
|
|
17187
|
-
const amount = Number(stakeInfo.stake.delegation.stake) /
|
|
17294
|
+
const amount = Number(stakeInfo.stake.delegation.stake) / LAMPORTS_PER_SOL;
|
|
17188
17295
|
const existingAccounts = validatorMap.get(validatorAddress) || [];
|
|
17189
17296
|
validatorMap.set(validatorAddress, [...existingAccounts, {
|
|
17190
17297
|
pubkey: accountPubkey,
|
|
@@ -17192,7 +17299,7 @@ const fetchNativeStakeAccounts = async (connection, publicKey, opts = { filterIn
|
|
|
17192
17299
|
}]);
|
|
17193
17300
|
}));
|
|
17194
17301
|
return Promise.all(Array.from(validatorMap.entries()).map(async ([validatorAddress, accounts$3]) => {
|
|
17195
|
-
const poolKey = findPoolAddress(new
|
|
17302
|
+
const poolKey = findPoolAddress(new PublicKey(validatorAddress));
|
|
17196
17303
|
const poolMintKey = findPoolMintAddress(poolKey);
|
|
17197
17304
|
const totalStake = accounts$3.reduce((acc, curr) => acc + curr.amount, 0);
|
|
17198
17305
|
const largestAccount = accounts$3.reduce((acc, curr) => acc.amount > curr.amount ? acc : curr);
|
|
@@ -17201,7 +17308,7 @@ const fetchNativeStakeAccounts = async (connection, publicKey, opts = { filterIn
|
|
|
17201
17308
|
sortedAccounts.unshift(sortedAccounts.splice(sortedAccounts.indexOf(largestAccount), 1)[0]);
|
|
17202
17309
|
}
|
|
17203
17310
|
return {
|
|
17204
|
-
validator: new
|
|
17311
|
+
validator: new PublicKey(validatorAddress),
|
|
17205
17312
|
poolKey,
|
|
17206
17313
|
poolMintKey,
|
|
17207
17314
|
accounts: sortedAccounts,
|
|
@@ -17234,7 +17341,7 @@ const fetchStakePoolActiveStates = async (connection, validatorVoteAccounts) =>
|
|
|
17234
17341
|
poolStakeAddressRecord[poolStakeAddress.toBase58()] = validatorVoteAccount;
|
|
17235
17342
|
});
|
|
17236
17343
|
const poolStakeAddressKeys = Object.keys(poolStakeAddressRecord);
|
|
17237
|
-
const poolStakeAccounts = Object.fromEntries((await
|
|
17344
|
+
const poolStakeAccounts = Object.fromEntries((await chunkedGetRawMultipleAccountInfoOrdered(connection, poolStakeAddressKeys)).map((ai, index) => [poolStakeAddressRecord[poolStakeAddressKeys[index]], ai?.data || null]));
|
|
17238
17345
|
validatorVoteAccounts.map((validatorVoteAccount) => {
|
|
17239
17346
|
const stakeAccount = fetchStakeAccount(poolStakeAccounts[validatorVoteAccount.toBase58()]);
|
|
17240
17347
|
const poolMintAddress = poolMintAddressRecord[validatorVoteAccount.toBase58()];
|
|
@@ -17264,17 +17371,17 @@ const fetchStakeAccount = (data) => {
|
|
|
17264
17371
|
offset += 4;
|
|
17265
17372
|
const rentExemptReserve = data.readBigUInt64LE(offset);
|
|
17266
17373
|
offset += 8;
|
|
17267
|
-
const staker = new
|
|
17374
|
+
const staker = new PublicKey(data.subarray(offset, offset + 32));
|
|
17268
17375
|
offset += 32;
|
|
17269
|
-
const withdrawer = new
|
|
17376
|
+
const withdrawer = new PublicKey(data.subarray(offset, offset + 32));
|
|
17270
17377
|
offset += 32;
|
|
17271
17378
|
const unixTimestamp = data.readBigUInt64LE(offset);
|
|
17272
17379
|
offset += 8;
|
|
17273
17380
|
const epoch = data.readBigUInt64LE(offset);
|
|
17274
17381
|
offset += 8;
|
|
17275
|
-
const custodian = new
|
|
17382
|
+
const custodian = new PublicKey(data.subarray(offset, offset + 32));
|
|
17276
17383
|
offset += 32;
|
|
17277
|
-
const voterPubkey = new
|
|
17384
|
+
const voterPubkey = new PublicKey(data.subarray(offset, offset + 32));
|
|
17278
17385
|
offset += 32;
|
|
17279
17386
|
const stake = data.readBigUInt64LE(offset);
|
|
17280
17387
|
offset += 8;
|
|
@@ -17324,7 +17431,7 @@ const fetchStakePoolMev = async (connection, validatorVoteAccounts) => {
|
|
|
17324
17431
|
const poolStakeAddresses = validatorVoteAccounts.map((validatorVoteAccount) => poolStakeAddressRecord[validatorVoteAccount.toBase58()]);
|
|
17325
17432
|
const onRampAddresses = validatorVoteAccounts.map((validatorVoteAccount) => onRampAddressRecord[validatorVoteAccount.toBase58()]);
|
|
17326
17433
|
const allAddresses = [...poolStakeAddresses, ...onRampAddresses].map((address$2) => address$2.toBase58());
|
|
17327
|
-
return
|
|
17434
|
+
return chunkedGetRawMultipleAccountInfoOrdered(connection, allAddresses).then((accountInfos) => {
|
|
17328
17435
|
const poolStakeInfos = accountInfos.slice(0, poolStakeAddresses.length);
|
|
17329
17436
|
const onRampInfos = accountInfos.slice(poolStakeAddresses.length);
|
|
17330
17437
|
const rent = 2282280;
|
|
@@ -17386,8 +17493,8 @@ var EmodeSettings = class EmodeSettings {
|
|
|
17386
17493
|
return {
|
|
17387
17494
|
collateralBankEmodeTag: parseEmodeTag(entry.collateralBankEmodeTag),
|
|
17388
17495
|
flags: getActiveEmodeEntryFlags(entry.flags),
|
|
17389
|
-
assetWeightInit:
|
|
17390
|
-
assetWeightMaint:
|
|
17496
|
+
assetWeightInit: wrappedI80F48toBigNumber(entry.assetWeightInit),
|
|
17497
|
+
assetWeightMaint: wrappedI80F48toBigNumber(entry.assetWeightMaint)
|
|
17391
17498
|
};
|
|
17392
17499
|
});
|
|
17393
17500
|
return new EmodeSettings(emodeTag, timestamp, flags, emodeEntries);
|
|
@@ -17397,7 +17504,7 @@ var EmodeSettings = class EmodeSettings {
|
|
|
17397
17504
|
//#endregion
|
|
17398
17505
|
//#region src/services/bank/utils/deserialize.utils.ts
|
|
17399
17506
|
function decodeBankRaw(encoded, idl) {
|
|
17400
|
-
const coder = new
|
|
17507
|
+
const coder = new BorshCoder(idl);
|
|
17401
17508
|
return coder.accounts.decode(AccountType.Bank, encoded);
|
|
17402
17509
|
}
|
|
17403
17510
|
function parseBankRaw(address$2, accountParsed, feedIdMap, bankMetadata) {
|
|
@@ -17405,28 +17512,28 @@ function parseBankRaw(address$2, accountParsed, feedIdMap, bankMetadata) {
|
|
|
17405
17512
|
const mint = accountParsed.mint;
|
|
17406
17513
|
const mintDecimals = accountParsed.mintDecimals;
|
|
17407
17514
|
const group = accountParsed.group;
|
|
17408
|
-
const assetShareValue =
|
|
17409
|
-
const liabilityShareValue =
|
|
17515
|
+
const assetShareValue = wrappedI80F48toBigNumber(accountParsed.assetShareValue);
|
|
17516
|
+
const liabilityShareValue = wrappedI80F48toBigNumber(accountParsed.liabilityShareValue);
|
|
17410
17517
|
const liquidityVault = accountParsed.liquidityVault;
|
|
17411
17518
|
const liquidityVaultBump = accountParsed.liquidityVaultBump;
|
|
17412
17519
|
const liquidityVaultAuthorityBump = accountParsed.liquidityVaultAuthorityBump;
|
|
17413
17520
|
const insuranceVault = accountParsed.insuranceVault;
|
|
17414
17521
|
const insuranceVaultBump = accountParsed.insuranceVaultBump;
|
|
17415
17522
|
const insuranceVaultAuthorityBump = accountParsed.insuranceVaultAuthorityBump;
|
|
17416
|
-
const collectedInsuranceFeesOutstanding =
|
|
17523
|
+
const collectedInsuranceFeesOutstanding = wrappedI80F48toBigNumber(accountParsed.collectedInsuranceFeesOutstanding);
|
|
17417
17524
|
const feeVault = accountParsed.feeVault;
|
|
17418
17525
|
const feeVaultBump = accountParsed.feeVaultBump;
|
|
17419
17526
|
const feeVaultAuthorityBump = accountParsed.feeVaultAuthorityBump;
|
|
17420
|
-
const collectedGroupFeesOutstanding =
|
|
17527
|
+
const collectedGroupFeesOutstanding = wrappedI80F48toBigNumber(accountParsed.collectedGroupFeesOutstanding);
|
|
17421
17528
|
const config = parseBankConfigRaw(accountParsed.config);
|
|
17422
17529
|
const lastUpdate = accountParsed.lastUpdate.toNumber();
|
|
17423
|
-
const totalAssetShares =
|
|
17424
|
-
const totalLiabilityShares =
|
|
17530
|
+
const totalAssetShares = wrappedI80F48toBigNumber(accountParsed.totalAssetShares);
|
|
17531
|
+
const totalLiabilityShares = wrappedI80F48toBigNumber(accountParsed.totalLiabilityShares);
|
|
17425
17532
|
const emissionsActiveBorrowing = (flags & 1) > 0;
|
|
17426
17533
|
const emissionsActiveLending = (flags & 2) > 0;
|
|
17427
17534
|
const emissionsRate = accountParsed.emissionsRate.toNumber();
|
|
17428
17535
|
const emissionsMint = accountParsed.emissionsMint;
|
|
17429
|
-
const emissionsRemaining = accountParsed.emissionsRemaining ?
|
|
17536
|
+
const emissionsRemaining = accountParsed.emissionsRemaining ? wrappedI80F48toBigNumber(accountParsed.emissionsRemaining) : new BigNumber(0);
|
|
17430
17537
|
const { oracleKey, shardId: pythShardId } = feedIdMap ? findOracleKey(config, feedIdMap) : { oracleKey: config.oracleKeys[0] };
|
|
17431
17538
|
const emode = EmodeSettings.from(accountParsed.emode);
|
|
17432
17539
|
const tokenSymbol = bankMetadata?.tokenSymbol;
|
|
@@ -17465,33 +17572,33 @@ function parseBankRaw(address$2, accountParsed, feedIdMap, bankMetadata) {
|
|
|
17465
17572
|
}
|
|
17466
17573
|
function dtoToBank(bankDto) {
|
|
17467
17574
|
return {
|
|
17468
|
-
address: new
|
|
17469
|
-
group: new
|
|
17470
|
-
mint: new
|
|
17575
|
+
address: new PublicKey(bankDto.address),
|
|
17576
|
+
group: new PublicKey(bankDto.group),
|
|
17577
|
+
mint: new PublicKey(bankDto.mint),
|
|
17471
17578
|
mintDecimals: bankDto.mintDecimals,
|
|
17472
|
-
assetShareValue: new
|
|
17473
|
-
liabilityShareValue: new
|
|
17474
|
-
liquidityVault: new
|
|
17579
|
+
assetShareValue: new BigNumber(bankDto.assetShareValue),
|
|
17580
|
+
liabilityShareValue: new BigNumber(bankDto.liabilityShareValue),
|
|
17581
|
+
liquidityVault: new PublicKey(bankDto.liquidityVault),
|
|
17475
17582
|
liquidityVaultBump: bankDto.liquidityVaultBump,
|
|
17476
17583
|
liquidityVaultAuthorityBump: bankDto.liquidityVaultAuthorityBump,
|
|
17477
|
-
insuranceVault: new
|
|
17584
|
+
insuranceVault: new PublicKey(bankDto.insuranceVault),
|
|
17478
17585
|
insuranceVaultBump: bankDto.insuranceVaultBump,
|
|
17479
17586
|
insuranceVaultAuthorityBump: bankDto.insuranceVaultAuthorityBump,
|
|
17480
|
-
collectedInsuranceFeesOutstanding: new
|
|
17481
|
-
feeVault: new
|
|
17587
|
+
collectedInsuranceFeesOutstanding: new BigNumber(bankDto.collectedInsuranceFeesOutstanding),
|
|
17588
|
+
feeVault: new PublicKey(bankDto.feeVault),
|
|
17482
17589
|
feeVaultBump: bankDto.feeVaultBump,
|
|
17483
17590
|
feeVaultAuthorityBump: bankDto.feeVaultAuthorityBump,
|
|
17484
|
-
collectedGroupFeesOutstanding: new
|
|
17591
|
+
collectedGroupFeesOutstanding: new BigNumber(bankDto.collectedGroupFeesOutstanding),
|
|
17485
17592
|
lastUpdate: bankDto.lastUpdate,
|
|
17486
17593
|
config: dtoToBankConfig(bankDto.config),
|
|
17487
|
-
totalAssetShares: new
|
|
17488
|
-
totalLiabilityShares: new
|
|
17594
|
+
totalAssetShares: new BigNumber(bankDto.totalAssetShares),
|
|
17595
|
+
totalLiabilityShares: new BigNumber(bankDto.totalLiabilityShares),
|
|
17489
17596
|
emissionsActiveBorrowing: bankDto.emissionsActiveBorrowing,
|
|
17490
17597
|
emissionsActiveLending: bankDto.emissionsActiveLending,
|
|
17491
17598
|
emissionsRate: bankDto.emissionsRate,
|
|
17492
|
-
emissionsMint: new
|
|
17493
|
-
emissionsRemaining: new
|
|
17494
|
-
oracleKey: new
|
|
17599
|
+
emissionsMint: new PublicKey(bankDto.emissionsMint),
|
|
17600
|
+
emissionsRemaining: new BigNumber(bankDto.emissionsRemaining),
|
|
17601
|
+
oracleKey: new PublicKey(bankDto.oracleKey),
|
|
17495
17602
|
pythShardId: bankDto.pythShardId,
|
|
17496
17603
|
emode: dtoToEmodeSettings(bankDto.emode),
|
|
17497
17604
|
tokenSymbol: bankDto.tokenSymbol
|
|
@@ -17506,76 +17613,76 @@ function dtoToEmodeSettings(emodeSettingsDto) {
|
|
|
17506
17613
|
return {
|
|
17507
17614
|
collateralBankEmodeTag: entry.collateralBankEmodeTag,
|
|
17508
17615
|
flags: entry.flags,
|
|
17509
|
-
assetWeightInit: new
|
|
17510
|
-
assetWeightMaint: new
|
|
17616
|
+
assetWeightInit: new BigNumber(entry.assetWeightInit),
|
|
17617
|
+
assetWeightMaint: new BigNumber(entry.assetWeightMaint)
|
|
17511
17618
|
};
|
|
17512
17619
|
})
|
|
17513
17620
|
};
|
|
17514
17621
|
}
|
|
17515
17622
|
function dtoToBankConfig(bankConfigDto) {
|
|
17516
17623
|
return {
|
|
17517
|
-
assetWeightInit: new
|
|
17518
|
-
assetWeightMaint: new
|
|
17519
|
-
liabilityWeightInit: new
|
|
17520
|
-
liabilityWeightMaint: new
|
|
17521
|
-
depositLimit: new
|
|
17522
|
-
borrowLimit: new
|
|
17624
|
+
assetWeightInit: new BigNumber(bankConfigDto.assetWeightInit),
|
|
17625
|
+
assetWeightMaint: new BigNumber(bankConfigDto.assetWeightMaint),
|
|
17626
|
+
liabilityWeightInit: new BigNumber(bankConfigDto.liabilityWeightInit),
|
|
17627
|
+
liabilityWeightMaint: new BigNumber(bankConfigDto.liabilityWeightMaint),
|
|
17628
|
+
depositLimit: new BigNumber(bankConfigDto.depositLimit),
|
|
17629
|
+
borrowLimit: new BigNumber(bankConfigDto.borrowLimit),
|
|
17523
17630
|
riskTier: bankConfigDto.riskTier,
|
|
17524
17631
|
operationalState: bankConfigDto.operationalState,
|
|
17525
|
-
totalAssetValueInitLimit: new
|
|
17632
|
+
totalAssetValueInitLimit: new BigNumber(bankConfigDto.totalAssetValueInitLimit),
|
|
17526
17633
|
assetTag: bankConfigDto.assetTag,
|
|
17527
17634
|
oracleSetup: bankConfigDto.oracleSetup,
|
|
17528
|
-
oracleKeys: bankConfigDto.oracleKeys.map((key) => new
|
|
17635
|
+
oracleKeys: bankConfigDto.oracleKeys.map((key) => new PublicKey(key)),
|
|
17529
17636
|
oracleMaxAge: bankConfigDto.oracleMaxAge,
|
|
17530
17637
|
interestRateConfig: dtoToInterestRateConfig(bankConfigDto.interestRateConfig)
|
|
17531
17638
|
};
|
|
17532
17639
|
}
|
|
17533
17640
|
function dtoToInterestRateConfig(interestRateConfigDto) {
|
|
17534
17641
|
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
|
|
17642
|
+
optimalUtilizationRate: new BigNumber(interestRateConfigDto.optimalUtilizationRate),
|
|
17643
|
+
plateauInterestRate: new BigNumber(interestRateConfigDto.plateauInterestRate),
|
|
17644
|
+
maxInterestRate: new BigNumber(interestRateConfigDto.maxInterestRate),
|
|
17645
|
+
insuranceFeeFixedApr: new BigNumber(interestRateConfigDto.insuranceFeeFixedApr),
|
|
17646
|
+
insuranceIrFee: new BigNumber(interestRateConfigDto.insuranceIrFee),
|
|
17647
|
+
protocolFixedFeeApr: new BigNumber(interestRateConfigDto.protocolFixedFeeApr),
|
|
17648
|
+
protocolIrFee: new BigNumber(interestRateConfigDto.protocolIrFee),
|
|
17649
|
+
protocolOriginationFee: new BigNumber(interestRateConfigDto.protocolOriginationFee)
|
|
17543
17650
|
};
|
|
17544
17651
|
}
|
|
17545
17652
|
function dtoToBankRaw(bankDto) {
|
|
17546
17653
|
return {
|
|
17547
|
-
group: new
|
|
17548
|
-
mint: new
|
|
17654
|
+
group: new PublicKey(bankDto.group),
|
|
17655
|
+
mint: new PublicKey(bankDto.mint),
|
|
17549
17656
|
mintDecimals: bankDto.mintDecimals,
|
|
17550
17657
|
assetShareValue: bankDto.assetShareValue,
|
|
17551
17658
|
liabilityShareValue: bankDto.liabilityShareValue,
|
|
17552
|
-
liquidityVault: new
|
|
17659
|
+
liquidityVault: new PublicKey(bankDto.liquidityVault),
|
|
17553
17660
|
liquidityVaultBump: bankDto.liquidityVaultBump,
|
|
17554
17661
|
liquidityVaultAuthorityBump: bankDto.liquidityVaultAuthorityBump,
|
|
17555
|
-
insuranceVault: new
|
|
17662
|
+
insuranceVault: new PublicKey(bankDto.insuranceVault),
|
|
17556
17663
|
insuranceVaultBump: bankDto.insuranceVaultBump,
|
|
17557
17664
|
insuranceVaultAuthorityBump: bankDto.insuranceVaultAuthorityBump,
|
|
17558
17665
|
collectedInsuranceFeesOutstanding: bankDto.collectedInsuranceFeesOutstanding,
|
|
17559
|
-
feeVault: new
|
|
17666
|
+
feeVault: new PublicKey(bankDto.feeVault),
|
|
17560
17667
|
feeVaultBump: bankDto.feeVaultBump,
|
|
17561
17668
|
feeVaultAuthorityBump: bankDto.feeVaultAuthorityBump,
|
|
17562
17669
|
collectedGroupFeesOutstanding: bankDto.collectedGroupFeesOutstanding,
|
|
17563
|
-
lastUpdate: new
|
|
17670
|
+
lastUpdate: new BN$1(bankDto.lastUpdate),
|
|
17564
17671
|
config: dtoToBankConfigRaw(bankDto.config),
|
|
17565
17672
|
totalAssetShares: bankDto.totalAssetShares,
|
|
17566
17673
|
totalLiabilityShares: bankDto.totalLiabilityShares,
|
|
17567
|
-
flags: new
|
|
17568
|
-
emissionsRate: new
|
|
17674
|
+
flags: new BN$1(bankDto.flags),
|
|
17675
|
+
emissionsRate: new BN$1(bankDto.emissionsRate),
|
|
17569
17676
|
emissionsRemaining: bankDto.emissionsRemaining,
|
|
17570
|
-
emissionsMint: new
|
|
17677
|
+
emissionsMint: new PublicKey(bankDto.emissionsMint),
|
|
17571
17678
|
emode: dtoToEmodeSettingsRaw(bankDto.emode)
|
|
17572
17679
|
};
|
|
17573
17680
|
}
|
|
17574
17681
|
function dtoToEmodeSettingsRaw(emodeSettingsDto) {
|
|
17575
17682
|
return {
|
|
17576
17683
|
emodeTag: emodeSettingsDto.emodeTag,
|
|
17577
|
-
timestamp: new
|
|
17578
|
-
flags: new
|
|
17684
|
+
timestamp: new BN$1(emodeSettingsDto.timestamp),
|
|
17685
|
+
flags: new BN$1(emodeSettingsDto.flags),
|
|
17579
17686
|
emodeConfig: { entries: emodeSettingsDto.emodeConfig.entries.map((entry) => {
|
|
17580
17687
|
return {
|
|
17581
17688
|
collateralBankEmodeTag: entry.collateralBankEmodeTag,
|
|
@@ -17592,41 +17699,41 @@ function dtoToBankConfigRaw(bankConfigDto) {
|
|
|
17592
17699
|
assetWeightMaint: bankConfigDto.assetWeightMaint,
|
|
17593
17700
|
liabilityWeightInit: bankConfigDto.liabilityWeightInit,
|
|
17594
17701
|
liabilityWeightMaint: bankConfigDto.liabilityWeightMaint,
|
|
17595
|
-
depositLimit: new
|
|
17596
|
-
borrowLimit: new
|
|
17702
|
+
depositLimit: new BN$1(bankConfigDto.depositLimit),
|
|
17703
|
+
borrowLimit: new BN$1(bankConfigDto.borrowLimit),
|
|
17597
17704
|
riskTier: bankConfigDto.riskTier,
|
|
17598
17705
|
operationalState: bankConfigDto.operationalState,
|
|
17599
|
-
totalAssetValueInitLimit: new
|
|
17706
|
+
totalAssetValueInitLimit: new BN$1(bankConfigDto.totalAssetValueInitLimit),
|
|
17600
17707
|
assetTag: bankConfigDto.assetTag,
|
|
17601
17708
|
oracleSetup: bankConfigDto.oracleSetup,
|
|
17602
|
-
oracleKeys: bankConfigDto.oracleKeys.map((key) => new
|
|
17709
|
+
oracleKeys: bankConfigDto.oracleKeys.map((key) => new PublicKey(key)),
|
|
17603
17710
|
oracleMaxAge: bankConfigDto.oracleMaxAge,
|
|
17604
17711
|
interestRateConfig: bankConfigDto.interestRateConfig
|
|
17605
17712
|
};
|
|
17606
17713
|
}
|
|
17607
17714
|
function parseBankConfigRaw(bankConfigRaw) {
|
|
17608
|
-
const assetWeightInit =
|
|
17609
|
-
const assetWeightMaint =
|
|
17610
|
-
const liabilityWeightInit =
|
|
17611
|
-
const liabilityWeightMaint =
|
|
17612
|
-
const depositLimit = (
|
|
17613
|
-
const borrowLimit = (
|
|
17715
|
+
const assetWeightInit = wrappedI80F48toBigNumber(bankConfigRaw.assetWeightInit);
|
|
17716
|
+
const assetWeightMaint = wrappedI80F48toBigNumber(bankConfigRaw.assetWeightMaint);
|
|
17717
|
+
const liabilityWeightInit = wrappedI80F48toBigNumber(bankConfigRaw.liabilityWeightInit);
|
|
17718
|
+
const liabilityWeightMaint = wrappedI80F48toBigNumber(bankConfigRaw.liabilityWeightMaint);
|
|
17719
|
+
const depositLimit = BigNumber(bankConfigRaw.depositLimit.toString());
|
|
17720
|
+
const borrowLimit = BigNumber(bankConfigRaw.borrowLimit.toString());
|
|
17614
17721
|
const riskTier = parseRiskTier(bankConfigRaw.riskTier);
|
|
17615
17722
|
const operationalState = parseOperationalState(bankConfigRaw.operationalState);
|
|
17616
|
-
const totalAssetValueInitLimit = (
|
|
17723
|
+
const totalAssetValueInitLimit = BigNumber(bankConfigRaw.totalAssetValueInitLimit.toString());
|
|
17617
17724
|
const assetTag = bankConfigRaw.assetTag;
|
|
17618
17725
|
const oracleSetup = parseOracleSetup(bankConfigRaw.oracleSetup);
|
|
17619
17726
|
const oracleKeys = bankConfigRaw.oracleKeys;
|
|
17620
|
-
const oracleMaxAge = bankConfigRaw.oracleMaxAge === 0 ?
|
|
17727
|
+
const oracleMaxAge = bankConfigRaw.oracleMaxAge === 0 ? DEFAULT_ORACLE_MAX_AGE : bankConfigRaw.oracleMaxAge;
|
|
17621
17728
|
const interestRateConfig = {
|
|
17622
|
-
insuranceFeeFixedApr:
|
|
17623
|
-
maxInterestRate:
|
|
17624
|
-
insuranceIrFee:
|
|
17625
|
-
optimalUtilizationRate:
|
|
17626
|
-
plateauInterestRate:
|
|
17627
|
-
protocolFixedFeeApr:
|
|
17628
|
-
protocolIrFee:
|
|
17629
|
-
protocolOriginationFee:
|
|
17729
|
+
insuranceFeeFixedApr: wrappedI80F48toBigNumber(bankConfigRaw.interestRateConfig.insuranceFeeFixedApr),
|
|
17730
|
+
maxInterestRate: wrappedI80F48toBigNumber(bankConfigRaw.interestRateConfig.maxInterestRate),
|
|
17731
|
+
insuranceIrFee: wrappedI80F48toBigNumber(bankConfigRaw.interestRateConfig.insuranceIrFee),
|
|
17732
|
+
optimalUtilizationRate: wrappedI80F48toBigNumber(bankConfigRaw.interestRateConfig.optimalUtilizationRate),
|
|
17733
|
+
plateauInterestRate: wrappedI80F48toBigNumber(bankConfigRaw.interestRateConfig.plateauInterestRate),
|
|
17734
|
+
protocolFixedFeeApr: wrappedI80F48toBigNumber(bankConfigRaw.interestRateConfig.protocolFixedFeeApr),
|
|
17735
|
+
protocolIrFee: wrappedI80F48toBigNumber(bankConfigRaw.interestRateConfig.protocolIrFee),
|
|
17736
|
+
protocolOriginationFee: wrappedI80F48toBigNumber(bankConfigRaw.interestRateConfig.protocolOriginationFee)
|
|
17630
17737
|
};
|
|
17631
17738
|
return {
|
|
17632
17739
|
assetWeightInit,
|
|
@@ -17689,7 +17796,7 @@ function getActiveEmodeFlags(flags) {
|
|
|
17689
17796
|
* Check if a specific EMode flag is set
|
|
17690
17797
|
*/
|
|
17691
17798
|
function hasEmodeFlag(flags, flag) {
|
|
17692
|
-
return !flags.and(new
|
|
17799
|
+
return !flags.and(new BN$1(flag)).isZero();
|
|
17693
17800
|
}
|
|
17694
17801
|
/**
|
|
17695
17802
|
* Get all active EMode entry flags as an array of flag names
|
|
@@ -17736,17 +17843,17 @@ const getStakeAccount = (data) => {
|
|
|
17736
17843
|
offset += 4;
|
|
17737
17844
|
const rentExemptReserve = data.readBigUInt64LE(offset);
|
|
17738
17845
|
offset += 8;
|
|
17739
|
-
const staker = new
|
|
17846
|
+
const staker = new PublicKey(data.subarray(offset, offset + 32));
|
|
17740
17847
|
offset += 32;
|
|
17741
|
-
const withdrawer = new
|
|
17848
|
+
const withdrawer = new PublicKey(data.subarray(offset, offset + 32));
|
|
17742
17849
|
offset += 32;
|
|
17743
17850
|
const unixTimestamp = data.readBigUInt64LE(offset);
|
|
17744
17851
|
offset += 8;
|
|
17745
17852
|
const epoch = data.readBigUInt64LE(offset);
|
|
17746
17853
|
offset += 8;
|
|
17747
|
-
const custodian = new
|
|
17854
|
+
const custodian = new PublicKey(data.subarray(offset, offset + 32));
|
|
17748
17855
|
offset += 32;
|
|
17749
|
-
const voterPubkey = new
|
|
17856
|
+
const voterPubkey = new PublicKey(data.subarray(offset, offset + 32));
|
|
17750
17857
|
offset += 32;
|
|
17751
17858
|
const stake = data.readBigUInt64LE(offset);
|
|
17752
17859
|
offset += 8;
|
|
@@ -17784,7 +17891,7 @@ const getStakeAccount = (data) => {
|
|
|
17784
17891
|
//#endregion
|
|
17785
17892
|
//#region src/vendor/index.ts
|
|
17786
17893
|
var vendor_exports = {};
|
|
17787
|
-
|
|
17894
|
+
__export(vendor_exports, {
|
|
17788
17895
|
AccountType: () => AccountType$1,
|
|
17789
17896
|
AggregatorAccount: () => AggregatorAccount,
|
|
17790
17897
|
AggregatorAccountData: () => AggregatorAccountData,
|
|
@@ -17820,17 +17927,17 @@ require_common.__export(vendor_exports, {
|
|
|
17820
17927
|
//#region src/utils.ts
|
|
17821
17928
|
function getBankVaultSeeds(type) {
|
|
17822
17929
|
switch (type) {
|
|
17823
|
-
case BankVaultType.LiquidityVault: return
|
|
17824
|
-
case BankVaultType.InsuranceVault: return
|
|
17825
|
-
case BankVaultType.FeeVault: return
|
|
17930
|
+
case BankVaultType.LiquidityVault: return PDA_BANK_LIQUIDITY_VAULT_SEED;
|
|
17931
|
+
case BankVaultType.InsuranceVault: return PDA_BANK_INSURANCE_VAULT_SEED;
|
|
17932
|
+
case BankVaultType.FeeVault: return PDA_BANK_FEE_VAULT_SEED;
|
|
17826
17933
|
default: throw Error(`Unknown vault type ${type}`);
|
|
17827
17934
|
}
|
|
17828
17935
|
}
|
|
17829
17936
|
function getBankVaultAuthoritySeeds(type) {
|
|
17830
17937
|
switch (type) {
|
|
17831
|
-
case BankVaultType.LiquidityVault: return
|
|
17832
|
-
case BankVaultType.InsuranceVault: return
|
|
17833
|
-
case BankVaultType.FeeVault: return
|
|
17938
|
+
case BankVaultType.LiquidityVault: return PDA_BANK_LIQUIDITY_VAULT_AUTH_SEED;
|
|
17939
|
+
case BankVaultType.InsuranceVault: return PDA_BANK_INSURANCE_VAULT_AUTH_SEED;
|
|
17940
|
+
case BankVaultType.FeeVault: return PDA_BANK_FEE_VAULT_AUTH_SEED;
|
|
17834
17941
|
default: throw Error(`Unknown vault type ${type}`);
|
|
17835
17942
|
}
|
|
17836
17943
|
}
|
|
@@ -17838,33 +17945,33 @@ function getBankVaultAuthoritySeeds(type) {
|
|
|
17838
17945
|
* Compute authority PDA for a specific lendr group bank vault
|
|
17839
17946
|
*/
|
|
17840
17947
|
function getBankVaultAuthority(bankVaultType, bankPk, programId) {
|
|
17841
|
-
return
|
|
17948
|
+
return PublicKey.findProgramAddressSync([getBankVaultAuthoritySeeds(bankVaultType), bankPk.toBuffer()], programId);
|
|
17842
17949
|
}
|
|
17843
17950
|
function makeWrapSolIxs(walletAddress, amount) {
|
|
17844
|
-
const address$2 =
|
|
17845
|
-
const ixs = [
|
|
17951
|
+
const address$2 = getAssociatedTokenAddressSync(NATIVE_MINT, walletAddress, true);
|
|
17952
|
+
const ixs = [createAssociatedTokenAccountIdempotentInstruction(walletAddress, address$2, walletAddress, NATIVE_MINT)];
|
|
17846
17953
|
if (amount.gt(0)) {
|
|
17847
|
-
const nativeAmount =
|
|
17848
|
-
ixs.push(
|
|
17954
|
+
const nativeAmount = uiToNative(amount, 9).toNumber() + 1e4;
|
|
17955
|
+
ixs.push(SystemProgram.transfer({
|
|
17849
17956
|
fromPubkey: walletAddress,
|
|
17850
17957
|
toPubkey: address$2,
|
|
17851
17958
|
lamports: nativeAmount
|
|
17852
|
-
}),
|
|
17959
|
+
}), createSyncNativeInstruction(address$2));
|
|
17853
17960
|
}
|
|
17854
17961
|
return ixs;
|
|
17855
17962
|
}
|
|
17856
17963
|
function makeUnwrapSolIx(walletAddress) {
|
|
17857
|
-
const address$2 =
|
|
17858
|
-
return
|
|
17964
|
+
const address$2 = getAssociatedTokenAddressSync(NATIVE_MINT, walletAddress, true);
|
|
17965
|
+
return createCloseAccountInstruction(address$2, walletAddress, walletAddress);
|
|
17859
17966
|
}
|
|
17860
17967
|
async function makeVersionedTransaction(blockhash, transaction, payer, addressLookupTables) {
|
|
17861
|
-
const message = new
|
|
17968
|
+
const message = new TransactionMessage({
|
|
17862
17969
|
instructions: transaction.instructions,
|
|
17863
17970
|
payerKey: payer,
|
|
17864
17971
|
recentBlockhash: blockhash
|
|
17865
17972
|
});
|
|
17866
17973
|
const versionedMessage = addressLookupTables ? message.compileToV0Message(addressLookupTables) : message.compileToLegacyMessage();
|
|
17867
|
-
return new
|
|
17974
|
+
return new VersionedTransaction(versionedMessage);
|
|
17868
17975
|
}
|
|
17869
17976
|
/**
|
|
17870
17977
|
* Creates a compute budget instruction to set the priority fee for a transaction.
|
|
@@ -17874,7 +17981,7 @@ async function makeVersionedTransaction(blockhash, transaction, payer, addressLo
|
|
|
17874
17981
|
* @returns A compute budget instruction with the specified priority fee
|
|
17875
17982
|
*/
|
|
17876
17983
|
function makePriorityFeeMicroIx(priorityFeeMicro) {
|
|
17877
|
-
return
|
|
17984
|
+
return ComputeBudgetProgram.setComputeUnitPrice({ microLamports: Math.floor(priorityFeeMicro ?? 1) });
|
|
17878
17985
|
}
|
|
17879
17986
|
function makePriorityFeeIx(priorityFeeUi, computeUnitsLimit) {
|
|
17880
17987
|
const priorityFeeIx = [];
|
|
@@ -17883,11 +17990,11 @@ function makePriorityFeeIx(priorityFeeUi, computeUnitsLimit) {
|
|
|
17883
17990
|
if (priorityFeeUi) {
|
|
17884
17991
|
const isAbsurdPriorityFee = priorityFeeUi > .1;
|
|
17885
17992
|
if (!isAbsurdPriorityFee) {
|
|
17886
|
-
const priorityFeeMicroLamports = priorityFeeUi *
|
|
17993
|
+
const priorityFeeMicroLamports = priorityFeeUi * LAMPORTS_PER_SOL * 1e6;
|
|
17887
17994
|
microLamports = Math.round(priorityFeeMicroLamports / limit);
|
|
17888
17995
|
}
|
|
17889
17996
|
}
|
|
17890
|
-
priorityFeeIx.push(
|
|
17997
|
+
priorityFeeIx.push(ComputeBudgetProgram.setComputeUnitPrice({ microLamports }));
|
|
17891
17998
|
return priorityFeeIx;
|
|
17892
17999
|
}
|
|
17893
18000
|
function feedIdToString(feedId) {
|
|
@@ -17899,7 +18006,7 @@ async function buildFeedIdMap(bankConfigs, connection) {
|
|
|
17899
18006
|
const feedId = bankConfig.oracleKeys[0].toBuffer();
|
|
17900
18007
|
return {
|
|
17901
18008
|
feedId,
|
|
17902
|
-
addresses: [findPythPushOracleAddress(feedId,
|
|
18009
|
+
addresses: [findPythPushOracleAddress(feedId, PYTH_PUSH_ORACLE_ID, PYTH_SPONSORED_SHARD_ID), findPythPushOracleAddress(feedId, PYTH_PUSH_ORACLE_ID, LENDR_SPONSORED_SHARD_ID)]
|
|
17903
18010
|
};
|
|
17904
18011
|
});
|
|
17905
18012
|
const addressess = feedIdsWithAddresses.flatMap((feedIdWithAddress) => feedIdWithAddress.addresses);
|
|
@@ -17975,7 +18082,7 @@ const PYTH_SPONSORED_SHARD_ID = 0;
|
|
|
17975
18082
|
const LENDR_SPONSORED_SHARD_ID = 3301;
|
|
17976
18083
|
function findPythPushOracleAddress(feedId, programId, shardId) {
|
|
17977
18084
|
const shardBytes = u16ToArrayBufferLE(shardId);
|
|
17978
|
-
return
|
|
18085
|
+
return PublicKey.findProgramAddressSync([shardBytes, feedId], programId)[0];
|
|
17979
18086
|
}
|
|
17980
18087
|
function u16ToArrayBufferLE(value) {
|
|
17981
18088
|
const buffer = new ArrayBuffer(2);
|
|
@@ -18042,8 +18149,8 @@ var Bank = class Bank {
|
|
|
18042
18149
|
const newBank = Object.create(Bank.prototype);
|
|
18043
18150
|
Object.assign(newBank, bank);
|
|
18044
18151
|
newBank.config = Object.assign({}, bank.config);
|
|
18045
|
-
newBank.config.assetWeightInit =
|
|
18046
|
-
newBank.config.assetWeightMaint =
|
|
18152
|
+
newBank.config.assetWeightInit = BigNumber.max(bank.config.assetWeightInit, emodeWeights.assetWeightInit);
|
|
18153
|
+
newBank.config.assetWeightMaint = BigNumber.max(bank.config.assetWeightMaint, emodeWeights.assetWeightMaint);
|
|
18047
18154
|
return newBank;
|
|
18048
18155
|
}
|
|
18049
18156
|
static getPrice(oraclePrice, priceBias = PriceBias.None, weightedPrice = false) {
|
|
@@ -18109,8 +18216,8 @@ var Bank = class Bank {
|
|
|
18109
18216
|
Bank address: ${this.address.toBase58()}
|
|
18110
18217
|
Mint: ${this.mint.toBase58()}, decimals: ${this.mintDecimals}
|
|
18111
18218
|
|
|
18112
|
-
Total deposits: ${
|
|
18113
|
-
Total borrows: ${
|
|
18219
|
+
Total deposits: ${nativeToUi(this.getTotalAssetQuantity(), this.mintDecimals)}
|
|
18220
|
+
Total borrows: ${nativeToUi(this.getTotalLiabilityQuantity(), this.mintDecimals)}
|
|
18114
18221
|
|
|
18115
18222
|
Total assets (USD value): ${this.computeAssetUsdValue(oraclePrice, this.totalAssetShares, LendrRequirementType.Equity, PriceBias.None)}
|
|
18116
18223
|
Total liabilities (USD value): ${this.computeLiabilityUsdValue(oraclePrice, this.totalLiabilityShares, LendrRequirementType.Equity, PriceBias.None)}
|
|
@@ -18128,8 +18235,8 @@ Config:
|
|
|
18128
18235
|
- Borrow limit: ${this.config.borrowLimit}
|
|
18129
18236
|
|
|
18130
18237
|
LTVs:
|
|
18131
|
-
- Initial: ${new
|
|
18132
|
-
- Maintenance: ${new
|
|
18238
|
+
- Initial: ${new BigNumber(1).div(this.config.liabilityWeightInit).times(100).toFixed(2)}%
|
|
18239
|
+
- Maintenance: ${new BigNumber(1).div(this.config.liabilityWeightMaint).times(100).toFixed(2)}%
|
|
18133
18240
|
`;
|
|
18134
18241
|
}
|
|
18135
18242
|
};
|
|
@@ -18295,7 +18402,7 @@ var LendrAccount = class LendrAccount {
|
|
|
18295
18402
|
const useCache = false;
|
|
18296
18403
|
const freeCollateral = useCache ? this.computeFreeCollateral().times(_volatilityFactor) : this.computeFreeCollateralLegacy(banks, oraclePrices);
|
|
18297
18404
|
logger.debug({ freeCollateral: freeCollateral.toFixed(6) }, "[lendr:computeMaxBorrowForBank] Free collateral");
|
|
18298
|
-
const untiedCollateralForBank =
|
|
18405
|
+
const untiedCollateralForBank = BigNumber.min(bank.computeAssetUsdValue(priceInfo, balance.assetShares, LendrRequirementType.Initial, PriceBias.Lowest), freeCollateral);
|
|
18299
18406
|
const priceLowestBias = getPrice(priceInfo, PriceBias.Lowest, true);
|
|
18300
18407
|
const priceHighestBias = getPrice(priceInfo, PriceBias.Highest, true);
|
|
18301
18408
|
const assetWeight = bank.getAssetWeight(LendrRequirementType.Initial, priceInfo);
|
|
@@ -18323,7 +18430,7 @@ var LendrAccount = class LendrAccount {
|
|
|
18323
18430
|
const { liabilities: liabilitiesInit } = this.computeHealthComponents(LendrRequirementType.Initial);
|
|
18324
18431
|
if (bank.config.riskTier === RiskTier.Isolated || initAssetWeight.isZero() && maintAssetWeight.isZero()) {
|
|
18325
18432
|
if (freeCollateral.isZero() && !liabilitiesInit.isZero()) {
|
|
18326
|
-
return new
|
|
18433
|
+
return new BigNumber(0);
|
|
18327
18434
|
} else {
|
|
18328
18435
|
return entireBalance;
|
|
18329
18436
|
}
|
|
@@ -18332,7 +18439,7 @@ var LendrAccount = class LendrAccount {
|
|
|
18332
18439
|
if (liabilitiesInit.eq(0)) {
|
|
18333
18440
|
return entireBalance;
|
|
18334
18441
|
} else if (freeCollateral.isZero()) {
|
|
18335
|
-
return new
|
|
18442
|
+
return new BigNumber(0);
|
|
18336
18443
|
} else {
|
|
18337
18444
|
const { liabilities: maintLiabilities, assets: maintAssets } = this.computeHealthComponents(LendrRequirementType.Maintenance);
|
|
18338
18445
|
const maintUntiedCollateral = maintAssets.minus(maintLiabilities);
|
|
@@ -18422,7 +18529,7 @@ var LendrAccount = class LendrAccount {
|
|
|
18422
18529
|
const { assets: assetsAccount, liabilities: liabilitiesAccount } = this.computeHealthComponents(LendrRequirementType.Maintenance);
|
|
18423
18530
|
const assets = assetsAccount.minus(assetBank);
|
|
18424
18531
|
const liabilities = liabilitiesAccount.minus(liabilitiesBank);
|
|
18425
|
-
const amountBn = new
|
|
18532
|
+
const amountBn = new BigNumber(amount);
|
|
18426
18533
|
let liquidationPrice;
|
|
18427
18534
|
if (isLending) {
|
|
18428
18535
|
if (liabilities.eq(0)) return null;
|
|
@@ -18451,7 +18558,7 @@ var LendrAccount = class LendrAccount {
|
|
|
18451
18558
|
const priceAssetLower = getPrice(assetPriceInfo, PriceBias.Lowest, false);
|
|
18452
18559
|
const priceAssetMarket = getPrice(assetPriceInfo, PriceBias.None, false);
|
|
18453
18560
|
const assetMaintWeight = assetBank.config.assetWeightMaint;
|
|
18454
|
-
const liquidationDiscount = new
|
|
18561
|
+
const liquidationDiscount = new BigNumber(.95);
|
|
18455
18562
|
const priceLiabHighest = getPrice(liabilityPriceInfo, PriceBias.Highest, false);
|
|
18456
18563
|
const priceLiabMarket = getPrice(liabilityPriceInfo, PriceBias.None, false);
|
|
18457
18564
|
const liabMaintWeight = liabilityBank.config.liabilityWeightMaint;
|
|
@@ -18477,7 +18584,7 @@ var LendrAccount = class LendrAccount {
|
|
|
18477
18584
|
priceLiabMarket: priceLiabMarket.toFixed(6),
|
|
18478
18585
|
liabUsdValue: liabUsdValue.toFixed(6)
|
|
18479
18586
|
}, "[lendr:getMaxLiquidatableAssetAmount]");
|
|
18480
|
-
const maxLiquidatableUsdValue =
|
|
18587
|
+
const maxLiquidatableUsdValue = BigNumber.min(assetsUsdValue, underwaterMaintUsdValue, liabUsdValue);
|
|
18481
18588
|
logger.debug({ maxLiquidatableUsdValue: maxLiquidatableUsdValue.toFixed(6) }, "[lendr:getMaxLiquidatableAssetAmount] Max liquidatable usd value");
|
|
18482
18589
|
return maxLiquidatableUsdValue.div(priceAssetLower);
|
|
18483
18590
|
}
|
|
@@ -18520,21 +18627,21 @@ var LendrAccount = class LendrAccount {
|
|
|
18520
18627
|
if (!mintData) throw Error(`Mint for bank ${bankAddress.toBase58()} not found`);
|
|
18521
18628
|
const wrapAndUnwrapSol = opts.wrapAndUnwrapSol ?? true;
|
|
18522
18629
|
const wSolBalanceUi = opts.wSolBalanceUi ?? 0;
|
|
18523
|
-
const userTokenAtaPk =
|
|
18524
|
-
const remainingAccounts = mintData.tokenProgram.equals(
|
|
18630
|
+
const userTokenAtaPk = getAssociatedTokenAddressSync(bank.mint, this.authority, true, mintData.tokenProgram);
|
|
18631
|
+
const remainingAccounts = mintData.tokenProgram.equals(TOKEN_2022_PROGRAM_ID) ? [{
|
|
18525
18632
|
pubkey: mintData.mint,
|
|
18526
18633
|
isSigner: false,
|
|
18527
18634
|
isWritable: false
|
|
18528
18635
|
}] : [];
|
|
18529
18636
|
const depositIxs = [];
|
|
18530
|
-
if (bank.mint.equals(
|
|
18531
|
-
depositIxs.push(...makeWrapSolIxs(this.authority, new
|
|
18637
|
+
if (bank.mint.equals(NATIVE_MINT) && wrapAndUnwrapSol) {
|
|
18638
|
+
depositIxs.push(...makeWrapSolIxs(this.authority, new BigNumber(amount).minus(wSolBalanceUi)));
|
|
18532
18639
|
}
|
|
18533
18640
|
return {
|
|
18534
18641
|
depositIxs,
|
|
18535
18642
|
userTokenAtaPk,
|
|
18536
18643
|
mintData,
|
|
18537
|
-
ixArguments: { amount:
|
|
18644
|
+
ixArguments: { amount: uiToNative(amount, bank.mintDecimals) },
|
|
18538
18645
|
remainingAccounts
|
|
18539
18646
|
};
|
|
18540
18647
|
}
|
|
@@ -18581,23 +18688,23 @@ var LendrAccount = class LendrAccount {
|
|
|
18581
18688
|
const wrapAndUnwrapSol = opts.wrapAndUnwrapSol ?? true;
|
|
18582
18689
|
const wSolBalanceUi = opts.wSolBalanceUi ?? 0;
|
|
18583
18690
|
const repayIxs = [];
|
|
18584
|
-
if (repayAll && !bank.emissionsMint.equals(
|
|
18691
|
+
if (repayAll && !bank.emissionsMint.equals(PublicKey.default)) {
|
|
18585
18692
|
repayIxs.push(...(await this.makeWithdrawEmissionsIx(program, banks, mintDatas, bankAddress)).instructions);
|
|
18586
18693
|
}
|
|
18587
|
-
const userAta =
|
|
18694
|
+
const userAta = getAssociatedTokenAddressSync(bank.mint, this.authority, true, mintData.tokenProgram);
|
|
18588
18695
|
const remainingAccounts = [];
|
|
18589
|
-
if (mintData.tokenProgram.equals(
|
|
18696
|
+
if (mintData.tokenProgram.equals(TOKEN_2022_PROGRAM_ID)) {
|
|
18590
18697
|
remainingAccounts.push(mintData.mint);
|
|
18591
18698
|
}
|
|
18592
|
-
if (bank.mint.equals(
|
|
18593
|
-
repayIxs.push(...makeWrapSolIxs(this.authority, new
|
|
18699
|
+
if (bank.mint.equals(NATIVE_MINT) && wrapAndUnwrapSol) {
|
|
18700
|
+
repayIxs.push(...makeWrapSolIxs(this.authority, new BigNumber(amount).minus(wSolBalanceUi)));
|
|
18594
18701
|
}
|
|
18595
18702
|
return {
|
|
18596
18703
|
repayIxs,
|
|
18597
18704
|
mintData,
|
|
18598
18705
|
userAta,
|
|
18599
18706
|
ixArguments: {
|
|
18600
|
-
amount:
|
|
18707
|
+
amount: uiToNative(amount, bank.mintDecimals),
|
|
18601
18708
|
repayAll
|
|
18602
18709
|
},
|
|
18603
18710
|
remainingAccounts
|
|
@@ -18653,17 +18760,17 @@ var LendrAccount = class LendrAccount {
|
|
|
18653
18760
|
const wrapAndUnwrapSol = withdrawOpts.wrapAndUnwrapSol ?? true;
|
|
18654
18761
|
const createAtas = withdrawOpts.createAtas ?? true;
|
|
18655
18762
|
const withdrawIxs = [];
|
|
18656
|
-
if (withdrawAll && !bank.emissionsMint.equals(
|
|
18763
|
+
if (withdrawAll && !bank.emissionsMint.equals(PublicKey.default) && mintData.emissionTokenProgram) {
|
|
18657
18764
|
withdrawIxs.push(...(await this.makeWithdrawEmissionsIx(program, bankMap, mintDatas, bankAddress)).instructions);
|
|
18658
18765
|
}
|
|
18659
|
-
const userAta =
|
|
18766
|
+
const userAta = getAssociatedTokenAddressSync(bank.mint, this.authority, true, mintData.tokenProgram);
|
|
18660
18767
|
if (createAtas) {
|
|
18661
|
-
const createAtaIdempotentIx =
|
|
18768
|
+
const createAtaIdempotentIx = createAssociatedTokenAccountIdempotentInstruction(withdrawOpts?.createAtaPayer ?? this.authority, userAta, this.authority, bank.mint, mintData.tokenProgram);
|
|
18662
18769
|
withdrawIxs.push(createAtaIdempotentIx);
|
|
18663
18770
|
}
|
|
18664
18771
|
const healthAccounts = withdrawAll ? this.getHealthCheckAccounts(bankMap, [], [bankAddress]) : this.getHealthCheckAccounts(bankMap, [bankAddress], []);
|
|
18665
18772
|
const remainingAccounts = [];
|
|
18666
|
-
if (mintData.tokenProgram.equals(
|
|
18773
|
+
if (mintData.tokenProgram.equals(TOKEN_2022_PROGRAM_ID)) {
|
|
18667
18774
|
remainingAccounts.push(mintData.mint);
|
|
18668
18775
|
}
|
|
18669
18776
|
if (withdrawOpts.observationBanksOverride) {
|
|
@@ -18695,11 +18802,11 @@ var LendrAccount = class LendrAccount {
|
|
|
18695
18802
|
authority: withdrawOpts.overrideInferAccounts?.authority,
|
|
18696
18803
|
group: withdrawOpts.overrideInferAccounts?.group
|
|
18697
18804
|
}, {
|
|
18698
|
-
amount:
|
|
18805
|
+
amount: uiToNative(amount, bank.mintDecimals),
|
|
18699
18806
|
withdrawAll
|
|
18700
18807
|
}, remainingAccounts);
|
|
18701
18808
|
withdrawIxs.push(withdrawIx);
|
|
18702
|
-
if (wrapAndUnwrapSol && bank.mint.equals(
|
|
18809
|
+
if (wrapAndUnwrapSol && bank.mint.equals(NATIVE_MINT)) {
|
|
18703
18810
|
withdrawIxs.push(makeUnwrapSolIx(this.authority));
|
|
18704
18811
|
}
|
|
18705
18812
|
return {
|
|
@@ -18720,11 +18827,11 @@ var LendrAccount = class LendrAccount {
|
|
|
18720
18827
|
tokenProgram: mintData.tokenProgram,
|
|
18721
18828
|
group: withdrawOpts.overrideInferAccounts?.group
|
|
18722
18829
|
}, {
|
|
18723
|
-
amount:
|
|
18830
|
+
amount: uiToNative(amount, bank.mintDecimals),
|
|
18724
18831
|
withdrawAll
|
|
18725
18832
|
}, remainingAccounts);
|
|
18726
18833
|
withdrawIxs.push(withdrawIx);
|
|
18727
|
-
if (wrapAndUnwrapSol && bank.mint.equals(
|
|
18834
|
+
if (wrapAndUnwrapSol && bank.mint.equals(NATIVE_MINT)) {
|
|
18728
18835
|
withdrawIxs.push(makeUnwrapSolIx(this.authority));
|
|
18729
18836
|
}
|
|
18730
18837
|
return {
|
|
@@ -18740,14 +18847,14 @@ var LendrAccount = class LendrAccount {
|
|
|
18740
18847
|
const wrapAndUnwrapSol = borrowOpts.wrapAndUnwrapSol ?? true;
|
|
18741
18848
|
const createAtas = borrowOpts.createAtas ?? true;
|
|
18742
18849
|
const borrowIxs = [];
|
|
18743
|
-
const userAta =
|
|
18850
|
+
const userAta = getAssociatedTokenAddressSync(bank.mint, this.authority, true, mintData.tokenProgram);
|
|
18744
18851
|
if (createAtas) {
|
|
18745
|
-
const createAtaIdempotentIx =
|
|
18852
|
+
const createAtaIdempotentIx = createAssociatedTokenAccountIdempotentInstruction(borrowOpts?.createAtaPayer ?? this.authority, userAta, this.authority, bank.mint, mintData.tokenProgram);
|
|
18746
18853
|
borrowIxs.push(createAtaIdempotentIx);
|
|
18747
18854
|
}
|
|
18748
18855
|
const healthAccounts = this.getHealthCheckAccounts(bankMap, [bankAddress], []);
|
|
18749
18856
|
const remainingAccounts = [];
|
|
18750
|
-
if (mintData.tokenProgram.equals(
|
|
18857
|
+
if (mintData.tokenProgram.equals(TOKEN_2022_PROGRAM_ID)) {
|
|
18751
18858
|
remainingAccounts.push(mintData.mint);
|
|
18752
18859
|
}
|
|
18753
18860
|
if (borrowOpts?.observationBanksOverride) {
|
|
@@ -18778,9 +18885,9 @@ var LendrAccount = class LendrAccount {
|
|
|
18778
18885
|
tokenProgram: mintData.tokenProgram,
|
|
18779
18886
|
authority: borrowOpts?.overrideInferAccounts?.authority,
|
|
18780
18887
|
group: borrowOpts?.overrideInferAccounts?.group
|
|
18781
|
-
}, { amount:
|
|
18888
|
+
}, { amount: uiToNative(amount, bank.mintDecimals) }, remainingAccounts);
|
|
18782
18889
|
borrowIxs.push(borrowIx);
|
|
18783
|
-
if (bank.mint.equals(
|
|
18890
|
+
if (bank.mint.equals(NATIVE_MINT) && wrapAndUnwrapSol) {
|
|
18784
18891
|
borrowIxs.push(makeUnwrapSolIx(this.authority));
|
|
18785
18892
|
}
|
|
18786
18893
|
return {
|
|
@@ -18800,9 +18907,9 @@ var LendrAccount = class LendrAccount {
|
|
|
18800
18907
|
destinationTokenAccount: userAta,
|
|
18801
18908
|
tokenProgram: mintData.tokenProgram,
|
|
18802
18909
|
group: borrowOpts?.overrideInferAccounts?.group
|
|
18803
|
-
}, { amount:
|
|
18910
|
+
}, { amount: uiToNative(amount, bank.mintDecimals) }, remainingAccounts);
|
|
18804
18911
|
borrowIxs.push(borrowIx);
|
|
18805
|
-
if (bank.mint.equals(
|
|
18912
|
+
if (bank.mint.equals(NATIVE_MINT) && wrapAndUnwrapSol) {
|
|
18806
18913
|
borrowIxs.push(makeUnwrapSolIx(this.authority));
|
|
18807
18914
|
}
|
|
18808
18915
|
return {
|
|
@@ -18819,8 +18926,8 @@ var LendrAccount = class LendrAccount {
|
|
|
18819
18926
|
throw Error(`Emission token program not found for bank ${bankAddress.toBase58()}`);
|
|
18820
18927
|
}
|
|
18821
18928
|
const ixs = [];
|
|
18822
|
-
const userAta =
|
|
18823
|
-
const createAtaIdempotentIx =
|
|
18929
|
+
const userAta = getAssociatedTokenAddressSync(bank.emissionsMint, this.authority, true, mintData.emissionTokenProgram);
|
|
18930
|
+
const createAtaIdempotentIx = createAssociatedTokenAccountIdempotentInstruction(this.authority, userAta, this.authority, bank.emissionsMint, mintData.emissionTokenProgram);
|
|
18824
18931
|
ixs.push(createAtaIdempotentIx);
|
|
18825
18932
|
const withdrawEmissionsIx = await instructions_default.makelendingAccountWithdrawEmissionIx(program, {
|
|
18826
18933
|
lendrAccount: this.address,
|
|
@@ -18844,19 +18951,19 @@ var LendrAccount = class LendrAccount {
|
|
|
18844
18951
|
const ixs = [];
|
|
18845
18952
|
const healthAccounts = [...this.getHealthCheckAccounts(bankMap, [liabilityBankAddress, assetBankAddress], []), ...liquidateeLendrAccount.getHealthCheckAccounts(bankMap, [], [])];
|
|
18846
18953
|
const remainingAccounts = [];
|
|
18847
|
-
if (liabilityMintData.tokenProgram.equals(
|
|
18954
|
+
if (liabilityMintData.tokenProgram.equals(TOKEN_2022_PROGRAM_ID)) {
|
|
18848
18955
|
remainingAccounts.push(liabilityMintData.mint);
|
|
18849
18956
|
}
|
|
18850
18957
|
const accountMetas = computeHealthAccountMetas(healthAccounts, bankMetadataMap);
|
|
18851
18958
|
remainingAccounts.push(...accountMetas);
|
|
18852
|
-
ixs.push(
|
|
18959
|
+
ixs.push(ComputeBudgetProgram.setComputeUnitLimit({ units: 14e5 }));
|
|
18853
18960
|
const liquidateIx = await instructions_default.makeLendingAccountLiquidateIx(program, {
|
|
18854
18961
|
assetBank: assetBankAddress,
|
|
18855
18962
|
liabBank: liabilityBankAddress,
|
|
18856
18963
|
liquidatorLendrAccount: this.address,
|
|
18857
18964
|
liquidateeLendrAccount: liquidateeLendrAccount.address,
|
|
18858
18965
|
tokenProgram: liabilityMintData.tokenProgram
|
|
18859
|
-
}, { assetAmount:
|
|
18966
|
+
}, { assetAmount: uiToNative(assetQuantityUi, assetBank.mintDecimals) }, remainingAccounts.map((account) => ({
|
|
18860
18967
|
pubkey: account,
|
|
18861
18968
|
isSigner: false,
|
|
18862
18969
|
isWritable: false
|
|
@@ -18868,7 +18975,7 @@ var LendrAccount = class LendrAccount {
|
|
|
18868
18975
|
};
|
|
18869
18976
|
}
|
|
18870
18977
|
async makeBeginFlashLoanIx(program, endIndex) {
|
|
18871
|
-
const ix = await instructions_default.makeBeginFlashLoanIx(program, { lendrAccount: this.address }, { endIndex: new
|
|
18978
|
+
const ix = await instructions_default.makeBeginFlashLoanIx(program, { lendrAccount: this.address }, { endIndex: new BN$1(endIndex) });
|
|
18872
18979
|
return {
|
|
18873
18980
|
instructions: [ix],
|
|
18874
18981
|
keys: []
|
|
@@ -18923,12 +19030,12 @@ var LendrAccount = class LendrAccount {
|
|
|
18923
19030
|
for (let index = 0; index < instructions$3.length; index++) {
|
|
18924
19031
|
const ix = instructions$3[index];
|
|
18925
19032
|
if (!ix.programId.equals(program.programId)) continue;
|
|
18926
|
-
const borshCoder = new
|
|
19033
|
+
const borshCoder = new BorshInstructionCoder(program.idl);
|
|
18927
19034
|
const decoded = borshCoder.decode(ix.data, "base58");
|
|
18928
19035
|
if (!decoded) continue;
|
|
18929
19036
|
const ixArgs = decoded.data;
|
|
18930
19037
|
if (decoded.name === "lendingAccountBorrow" || decoded.name === "lendingAccountDeposit") {
|
|
18931
|
-
const targetBank = new
|
|
19038
|
+
const targetBank = new PublicKey(ix.keys[3].pubkey);
|
|
18932
19039
|
const targetBalance = projectedBalances.find((b) => b.bankPk.equals(targetBank));
|
|
18933
19040
|
if (!targetBalance) {
|
|
18934
19041
|
const firstInactiveBalanceIndex = projectedBalances.findIndex((b) => !b.active);
|
|
@@ -18941,22 +19048,22 @@ var LendrAccount = class LendrAccount {
|
|
|
18941
19048
|
continue;
|
|
18942
19049
|
}
|
|
18943
19050
|
if (decoded.name === "lendingAccountRepay" || decoded.name === "lendingAccountWithdraw") {
|
|
18944
|
-
const targetBank = new
|
|
19051
|
+
const targetBank = new PublicKey(ix.keys[3].pubkey);
|
|
18945
19052
|
const targetBalance = projectedBalances.find((b) => b.bankPk.equals(targetBank));
|
|
18946
19053
|
if (!targetBalance) {
|
|
18947
19054
|
throw Error(`Balance for bank ${targetBank.toBase58()} should be projected active at this point (ix ${index}: ${decoded.name}))`);
|
|
18948
19055
|
}
|
|
18949
19056
|
if (ixArgs.repayAll || ixArgs.withdrawAll) {
|
|
18950
19057
|
targetBalance.active = false;
|
|
18951
|
-
targetBalance.bankPk =
|
|
19058
|
+
targetBalance.bankPk = PublicKey.default;
|
|
18952
19059
|
}
|
|
18953
19060
|
}
|
|
18954
19061
|
}
|
|
18955
19062
|
return projectedBalances.filter((b) => b.active).map((b) => b.bankPk);
|
|
18956
19063
|
}
|
|
18957
|
-
wrapInstructionForWSol(ix, amount = new
|
|
19064
|
+
wrapInstructionForWSol(ix, amount = new BigNumber(0)) {
|
|
18958
19065
|
return [
|
|
18959
|
-
...makeWrapSolIxs(this.authority, new
|
|
19066
|
+
...makeWrapSolIxs(this.authority, new BigNumber(amount)),
|
|
18960
19067
|
ix,
|
|
18961
19068
|
makeUnwrapSolIx(this.authority)
|
|
18962
19069
|
];
|
|
@@ -19007,7 +19114,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19007
19114
|
}
|
|
19008
19115
|
static async fetch(lendrAccountPk, client, commitment) {
|
|
19009
19116
|
const { config, program } = client;
|
|
19010
|
-
const _lendrAccountPk =
|
|
19117
|
+
const _lendrAccountPk = translateAddress(lendrAccountPk);
|
|
19011
19118
|
const accountData = await LendrAccountWrapper._fetchAccountData(_lendrAccountPk, config, program, commitment);
|
|
19012
19119
|
const lendrAccount = LendrAccount.fromAccountParsed(_lendrAccountPk, accountData);
|
|
19013
19120
|
const lendrAccountProxy = new LendrAccountWrapper(_lendrAccountPk, client, lendrAccount);
|
|
@@ -19016,7 +19123,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19016
19123
|
}
|
|
19017
19124
|
static fromAccountParsed(lendrAccountPk, client, accountData) {
|
|
19018
19125
|
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 =
|
|
19126
|
+
const _lendrAccountPk = translateAddress(lendrAccountPk);
|
|
19020
19127
|
const lendrAccount = LendrAccount.fromAccountParsed(_lendrAccountPk, accountData);
|
|
19021
19128
|
return new LendrAccountWrapper(_lendrAccountPk, client, lendrAccount);
|
|
19022
19129
|
}
|
|
@@ -19097,7 +19204,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19097
19204
|
return this._lendrAccount.computeActiveEmodePairs(emodePairs);
|
|
19098
19205
|
}
|
|
19099
19206
|
computeEmodeImpacts(emodePairs) {
|
|
19100
|
-
return this._lendrAccount.computeEmodeImpacts(emodePairs, Array.from(this.client.banks.keys()).map((b) => new
|
|
19207
|
+
return this._lendrAccount.computeEmodeImpacts(emodePairs, Array.from(this.client.banks.keys()).map((b) => new PublicKey(b)));
|
|
19101
19208
|
}
|
|
19102
19209
|
computeMaxBorrowForBank(bankAddress, opts) {
|
|
19103
19210
|
return this._lendrAccount.computeMaxBorrowForBank(this.client.banks, this.client.oraclePrices, bankAddress, opts, this.client.logger);
|
|
@@ -19133,7 +19240,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19133
19240
|
const cuRequestIxs = [];
|
|
19134
19241
|
const activeBalances = this.balances.filter((b) => b.active);
|
|
19135
19242
|
if (activeBalances.length >= 4) {
|
|
19136
|
-
cuRequestIxs.push(
|
|
19243
|
+
cuRequestIxs.push(ComputeBudgetProgram.setComputeUnitLimit({ units: 1e6 }));
|
|
19137
19244
|
}
|
|
19138
19245
|
return cuRequestIxs;
|
|
19139
19246
|
}
|
|
@@ -19147,7 +19254,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19147
19254
|
const bank = this.client.bankMetadataMap[bankAddress.toBase58()];
|
|
19148
19255
|
const mintData = this.client.mintDatas.get(bankAddress.toBase58());
|
|
19149
19256
|
if (!mintData) throw Error(`Token data for ${bank.tokenAddress} not found`);
|
|
19150
|
-
return
|
|
19257
|
+
return getAssociatedTokenAddressSync(new PublicKey(bank.tokenAddress), this.authority, true, mintData.tokenProgram.equals(TOKEN_2022_PROGRAM_ID) ? TOKEN_2022_PROGRAM_ID : undefined);
|
|
19151
19258
|
});
|
|
19152
19259
|
const ixs = [];
|
|
19153
19260
|
const userAtaAis = await this._program.provider.connection.getMultipleAccountsInfo(userAtas);
|
|
@@ -19157,7 +19264,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19157
19264
|
const bank = this.client.bankMetadataMap[bankAddress.toBase58()];
|
|
19158
19265
|
const mintData = this.client.mintDatas.get(bankAddress.toBase58());
|
|
19159
19266
|
if (!mintData) throw Error(`Token data for ${bank.tokenAddress} not found`);
|
|
19160
|
-
ixs.push(
|
|
19267
|
+
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
19268
|
}
|
|
19162
19269
|
}
|
|
19163
19270
|
return ixs;
|
|
@@ -19197,32 +19304,32 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19197
19304
|
const { value: { blockhash } } = await this._program.provider.connection.getLatestBlockhashAndContext("confirmed");
|
|
19198
19305
|
const feedCrankTxs = [];
|
|
19199
19306
|
if (updateFeedIxs.length > 0) {
|
|
19200
|
-
feedCrankTxs.push(
|
|
19307
|
+
feedCrankTxs.push(addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
19201
19308
|
instructions: [...updateFeedIxs],
|
|
19202
19309
|
payerKey: this.authority,
|
|
19203
19310
|
recentBlockhash: blockhash
|
|
19204
19311
|
}).compileToV0Message(feedLuts)), {
|
|
19205
19312
|
addressLookupTables: feedLuts,
|
|
19206
|
-
type:
|
|
19313
|
+
type: TransactionType.CRANK
|
|
19207
19314
|
}));
|
|
19208
19315
|
}
|
|
19209
19316
|
const lookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
19210
|
-
const withdrawTx =
|
|
19317
|
+
const withdrawTx = addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
19211
19318
|
instructions: [...cuRequestIxs, ...withdrawIxs.instructions],
|
|
19212
19319
|
payerKey: this.authority,
|
|
19213
19320
|
recentBlockhash: blockhash
|
|
19214
19321
|
}).compileToV0Message(lookupTables)), {
|
|
19215
19322
|
signers: withdrawIxs.keys,
|
|
19216
19323
|
addressLookupTables: lookupTables,
|
|
19217
|
-
type:
|
|
19324
|
+
type: TransactionType.MOVE_POSITION_WITHDRAW
|
|
19218
19325
|
});
|
|
19219
19326
|
const destinationAccount = await LendrAccountWrapper.fetch(destinationAccountPk, this.client);
|
|
19220
19327
|
const depositIx = await destinationAccount.makeDepositIx(amount, bankAddress);
|
|
19221
|
-
const tx = new
|
|
19222
|
-
const depositTx =
|
|
19328
|
+
const tx = new Transaction().add(...depositIx.instructions);
|
|
19329
|
+
const depositTx = addTransactionMetadata(tx, {
|
|
19223
19330
|
signers: depositIx.keys,
|
|
19224
19331
|
addressLookupTables: lookupTables,
|
|
19225
|
-
type:
|
|
19332
|
+
type: TransactionType.MOVE_POSITION_DEPOSIT
|
|
19226
19333
|
});
|
|
19227
19334
|
const transactions = [
|
|
19228
19335
|
...feedCrankTxs,
|
|
@@ -19287,7 +19394,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19287
19394
|
async makeRepayWithCollatTxV2({ repayAmount, withdrawAmount, borrowBankAddress, depositBankAddress, withdrawAll = false, repayAll = false, swap, blockhash: blockhashArg }) {
|
|
19288
19395
|
const blockhash = blockhashArg ?? (await this._program.provider.connection.getLatestBlockhash("confirmed")).blockhash;
|
|
19289
19396
|
const setupIxs = await this.makeSetupIx([borrowBankAddress, depositBankAddress]);
|
|
19290
|
-
const cuRequestIxs = this.makeComputeBudgetIx().length > 0 ? this.makeComputeBudgetIx() : [
|
|
19397
|
+
const cuRequestIxs = this.makeComputeBudgetIx().length > 0 ? this.makeComputeBudgetIx() : [ComputeBudgetProgram.setComputeUnitLimit({ units: 1e6 })];
|
|
19291
19398
|
const [priorityFeeIx] = makePriorityFeeIx(1e-5);
|
|
19292
19399
|
const withdrawIxs = await this.makeWithdrawIx(withdrawAmount, depositBankAddress, withdrawAll, {
|
|
19293
19400
|
createAtas: false,
|
|
@@ -19300,22 +19407,22 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19300
19407
|
let flashloanTx;
|
|
19301
19408
|
let txOverflown = false;
|
|
19302
19409
|
if (setupIxs.length > 0) {
|
|
19303
|
-
const message = new
|
|
19410
|
+
const message = new TransactionMessage({
|
|
19304
19411
|
payerKey: this.client.wallet.publicKey,
|
|
19305
19412
|
recentBlockhash: blockhash,
|
|
19306
19413
|
instructions: setupIxs
|
|
19307
19414
|
}).compileToLegacyMessage();
|
|
19308
|
-
additionalTxs.push(
|
|
19415
|
+
additionalTxs.push(addTransactionMetadata(new VersionedTransaction(message), { type: TransactionType.CREATE_ATA }));
|
|
19309
19416
|
}
|
|
19310
19417
|
if (updateFeedIxs.length > 0) {
|
|
19311
|
-
const message = new
|
|
19418
|
+
const message = new TransactionMessage({
|
|
19312
19419
|
payerKey: this.client.wallet.publicKey,
|
|
19313
19420
|
recentBlockhash: blockhash,
|
|
19314
19421
|
instructions: updateFeedIxs
|
|
19315
19422
|
}).compileToV0Message(feedLuts);
|
|
19316
|
-
additionalTxs.push(
|
|
19423
|
+
additionalTxs.push(addTransactionMetadata(new VersionedTransaction(message), {
|
|
19317
19424
|
addressLookupTables: feedLuts,
|
|
19318
|
-
type:
|
|
19425
|
+
type: TransactionType.CRANK
|
|
19319
19426
|
}));
|
|
19320
19427
|
}
|
|
19321
19428
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
@@ -19331,11 +19438,11 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19331
19438
|
addressLookupTableAccounts,
|
|
19332
19439
|
blockhash
|
|
19333
19440
|
});
|
|
19334
|
-
const txSize =
|
|
19335
|
-
const accountKeys =
|
|
19336
|
-
const txToManyKeys = accountKeys >
|
|
19337
|
-
const txToBig = txSize >
|
|
19338
|
-
const canBeDownsized = txToManyKeys && txToBig && txSize -
|
|
19441
|
+
const txSize = getTxSize(flashloanTx);
|
|
19442
|
+
const accountKeys = getAccountKeys(flashloanTx, addressLookupTableAccounts);
|
|
19443
|
+
const txToManyKeys = accountKeys > MAX_ACCOUNT_KEYS;
|
|
19444
|
+
const txToBig = txSize > MAX_TX_SIZE;
|
|
19445
|
+
const canBeDownsized = txToManyKeys && txToBig && txSize - PRIORITY_TX_SIZE <= MAX_TX_SIZE;
|
|
19339
19446
|
if (canBeDownsized) {
|
|
19340
19447
|
flashloanTx = await this.buildFlashLoanTx({
|
|
19341
19448
|
ixs: [
|
|
@@ -19347,16 +19454,16 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19347
19454
|
addressLookupTableAccounts,
|
|
19348
19455
|
blockhash
|
|
19349
19456
|
});
|
|
19350
|
-
const txSize$1 =
|
|
19351
|
-
const txToBig$1 = txSize$1 >
|
|
19457
|
+
const txSize$1 = getTxSize(flashloanTx);
|
|
19458
|
+
const txToBig$1 = txSize$1 > MAX_TX_SIZE;
|
|
19352
19459
|
if (txToBig$1) {
|
|
19353
19460
|
txOverflown = true;
|
|
19354
19461
|
}
|
|
19355
19462
|
} else if (txToBig || txToManyKeys) {
|
|
19356
19463
|
txOverflown = true;
|
|
19357
19464
|
}
|
|
19358
|
-
flashloanTx =
|
|
19359
|
-
type:
|
|
19465
|
+
flashloanTx = addTransactionMetadata(flashloanTx, {
|
|
19466
|
+
type: TransactionType.REPAY_COLLAT,
|
|
19360
19467
|
addressLookupTables: flashloanTx.addressLookupTables
|
|
19361
19468
|
});
|
|
19362
19469
|
const transactions = [...additionalTxs, flashloanTx];
|
|
@@ -19394,7 +19501,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19394
19501
|
if (!borrowBank) throw Error("Borrow bank not found");
|
|
19395
19502
|
const blockhash = blockhashArg ?? (await this._program.provider.connection.getLatestBlockhash("confirmed")).blockhash;
|
|
19396
19503
|
const setupIxs = await this.makeSetupIx(setupBankAddresses ?? [borrowBankAddress, depositBankAddress]);
|
|
19397
|
-
const cuRequestIxs = this.makeComputeBudgetIx().length > 0 ? this.makeComputeBudgetIx() : [
|
|
19504
|
+
const cuRequestIxs = this.makeComputeBudgetIx().length > 0 ? this.makeComputeBudgetIx() : [ComputeBudgetProgram.setComputeUnitLimit({ units: 5e5 })];
|
|
19398
19505
|
const [priorityFeeIx] = makePriorityFeeIx(1e-5);
|
|
19399
19506
|
const borrowIxs = await this.makeBorrowIx(borrowAmount, borrowBankAddress, {
|
|
19400
19507
|
createAtas: false,
|
|
@@ -19410,26 +19517,26 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19410
19517
|
const additionalTxs = [];
|
|
19411
19518
|
let flashloanTx;
|
|
19412
19519
|
let txOverflown = false;
|
|
19413
|
-
if (depositBank.mint.equals(
|
|
19414
|
-
setupIxs.push(...makeWrapSolIxs(this.authority, new
|
|
19520
|
+
if (depositBank.mint.equals(NATIVE_MINT) && inputDepositAmount) {
|
|
19521
|
+
setupIxs.push(...makeWrapSolIxs(this.authority, new BigNumber(inputDepositAmount)));
|
|
19415
19522
|
}
|
|
19416
19523
|
if (setupIxs.length > 0) {
|
|
19417
|
-
const message = new
|
|
19524
|
+
const message = new TransactionMessage({
|
|
19418
19525
|
payerKey: this.client.wallet.publicKey,
|
|
19419
19526
|
recentBlockhash: blockhash,
|
|
19420
19527
|
instructions: setupIxs
|
|
19421
19528
|
}).compileToLegacyMessage();
|
|
19422
|
-
additionalTxs.push(
|
|
19529
|
+
additionalTxs.push(addTransactionMetadata(new VersionedTransaction(message), { type: TransactionType.CREATE_ATA }));
|
|
19423
19530
|
}
|
|
19424
19531
|
if (updateFeedIxs.length > 0) {
|
|
19425
|
-
const message = new
|
|
19532
|
+
const message = new TransactionMessage({
|
|
19426
19533
|
payerKey: this.client.wallet.publicKey,
|
|
19427
19534
|
recentBlockhash: blockhash,
|
|
19428
19535
|
instructions: updateFeedIxs
|
|
19429
19536
|
}).compileToV0Message(feedLuts);
|
|
19430
|
-
additionalTxs.push(
|
|
19537
|
+
additionalTxs.push(addTransactionMetadata(new VersionedTransaction(message), {
|
|
19431
19538
|
addressLookupTables: feedLuts,
|
|
19432
|
-
type:
|
|
19539
|
+
type: TransactionType.CRANK
|
|
19433
19540
|
}));
|
|
19434
19541
|
}
|
|
19435
19542
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
@@ -19445,11 +19552,11 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19445
19552
|
addressLookupTableAccounts,
|
|
19446
19553
|
blockhash
|
|
19447
19554
|
});
|
|
19448
|
-
const txSize =
|
|
19449
|
-
const accountKeys =
|
|
19450
|
-
const txToManyKeys = accountKeys >
|
|
19451
|
-
const txToBig = txSize >
|
|
19452
|
-
const canBeDownsized = txToManyKeys && txToBig && txSize -
|
|
19555
|
+
const txSize = getTxSize(flashloanTx);
|
|
19556
|
+
const accountKeys = getAccountKeys(flashloanTx, addressLookupTableAccounts);
|
|
19557
|
+
const txToManyKeys = accountKeys > MAX_ACCOUNT_KEYS;
|
|
19558
|
+
const txToBig = txSize > MAX_TX_SIZE;
|
|
19559
|
+
const canBeDownsized = txToManyKeys && txToBig && txSize - PRIORITY_TX_SIZE <= MAX_TX_SIZE;
|
|
19453
19560
|
if (canBeDownsized) {
|
|
19454
19561
|
flashloanTx = await this.buildFlashLoanTx({
|
|
19455
19562
|
ixs: [
|
|
@@ -19461,16 +19568,16 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19461
19568
|
addressLookupTableAccounts,
|
|
19462
19569
|
blockhash
|
|
19463
19570
|
});
|
|
19464
|
-
const txSize$1 =
|
|
19465
|
-
const txToBig$1 = txSize$1 >
|
|
19571
|
+
const txSize$1 = getTxSize(flashloanTx);
|
|
19572
|
+
const txToBig$1 = txSize$1 > MAX_TX_SIZE;
|
|
19466
19573
|
if (txToBig$1) {
|
|
19467
19574
|
txOverflown = true;
|
|
19468
19575
|
}
|
|
19469
19576
|
} else if (txToBig || txToManyKeys) {
|
|
19470
19577
|
txOverflown = true;
|
|
19471
19578
|
}
|
|
19472
|
-
flashloanTx =
|
|
19473
|
-
type:
|
|
19579
|
+
flashloanTx = addTransactionMetadata(flashloanTx, {
|
|
19580
|
+
type: TransactionType.LOOP,
|
|
19474
19581
|
addressLookupTables: flashloanTx.addressLookupTables
|
|
19475
19582
|
});
|
|
19476
19583
|
const transactions = [...additionalTxs, flashloanTx];
|
|
@@ -19517,12 +19624,12 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19517
19624
|
*/
|
|
19518
19625
|
async makeCloseAccountTx() {
|
|
19519
19626
|
const ix = await this.makeCloseAccountIx();
|
|
19520
|
-
const tx = new
|
|
19627
|
+
const tx = new Transaction().add(...ix.instructions);
|
|
19521
19628
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
19522
|
-
return
|
|
19629
|
+
return addTransactionMetadata(tx, {
|
|
19523
19630
|
signers: ix.keys,
|
|
19524
19631
|
addressLookupTables: clientLookupTables,
|
|
19525
|
-
type:
|
|
19632
|
+
type: TransactionType.CLOSE_ACCOUNT
|
|
19526
19633
|
});
|
|
19527
19634
|
}
|
|
19528
19635
|
/**
|
|
@@ -19558,17 +19665,17 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19558
19665
|
const poolStakeAddress = findPoolStakeAddress(pool);
|
|
19559
19666
|
const lstMint = findPoolMintAddress(pool);
|
|
19560
19667
|
const auth = findPoolStakeAuthorityAddress(pool);
|
|
19561
|
-
const lstAta =
|
|
19668
|
+
const lstAta = getAssociatedTokenAddressSync(lstMint, this.authority);
|
|
19562
19669
|
const [lstAccInfo, stakeAccountInfo, stakeAccInfoParsed] = await Promise.all([
|
|
19563
19670
|
this.client.provider.connection.getAccountInfo(lstAta),
|
|
19564
19671
|
this._program.provider.connection.getAccountInfo(stakeAccountPk),
|
|
19565
19672
|
this._program.provider.connection.getParsedAccountInfo(stakeAccountPk)
|
|
19566
19673
|
]);
|
|
19567
19674
|
const stakeAccParsed = stakeAccInfoParsed?.value?.data;
|
|
19568
|
-
const [rentExemptReserve, minimumDelegation] = await Promise.all([this._program.provider.connection.getMinimumBalanceForRentExemption(
|
|
19569
|
-
return Math.max(res.value,
|
|
19675
|
+
const [rentExemptReserve, minimumDelegation] = await Promise.all([this._program.provider.connection.getMinimumBalanceForRentExemption(StakeProgram.space), this._program.provider.connection.getStakeMinimumDelegation().then((res) => {
|
|
19676
|
+
return Math.max(res.value, LAMPORTS_PER_SOL);
|
|
19570
19677
|
})]);
|
|
19571
|
-
const amountLamports = Math.round(Number(amount) *
|
|
19678
|
+
const amountLamports = Math.round(Number(amount) * LAMPORTS_PER_SOL);
|
|
19572
19679
|
const stakeAccLamports = Number(stakeAccParsed.parsed.info.stake?.delegation?.stake ?? 0);
|
|
19573
19680
|
const isFullStake = amountLamports >= stakeAccLamports;
|
|
19574
19681
|
const poolStakeAccLamports = (await this._program.provider.connection.getAccountInfo(poolStakeAddress))?.lamports ?? 0;
|
|
@@ -19582,14 +19689,14 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19582
19689
|
const instructions$3 = [];
|
|
19583
19690
|
const signers = [];
|
|
19584
19691
|
if (!lstAccInfo) {
|
|
19585
|
-
instructions$3.push(
|
|
19692
|
+
instructions$3.push(createAssociatedTokenAccountInstruction(this.authority, lstAta, this.authority, lstMint));
|
|
19586
19693
|
}
|
|
19587
19694
|
let targetStakePubkey;
|
|
19588
19695
|
if (!isFullStake) {
|
|
19589
|
-
const splitStakeAccount =
|
|
19696
|
+
const splitStakeAccount = Keypair.generate();
|
|
19590
19697
|
signers.push(splitStakeAccount);
|
|
19591
19698
|
targetStakePubkey = splitStakeAccount.publicKey;
|
|
19592
|
-
instructions$3.push(...
|
|
19699
|
+
instructions$3.push(...StakeProgram.split({
|
|
19593
19700
|
stakePubkey: stakeAccountPk,
|
|
19594
19701
|
authorizedPubkey: this.authority,
|
|
19595
19702
|
splitStakePubkey: splitStakeAccount.publicKey,
|
|
@@ -19598,44 +19705,44 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19598
19705
|
} else {
|
|
19599
19706
|
targetStakePubkey = stakeAccountPk;
|
|
19600
19707
|
}
|
|
19601
|
-
const [authorizeStakerIx, authorizeWithdrawIx] = await Promise.all([
|
|
19708
|
+
const [authorizeStakerIx, authorizeWithdrawIx] = await Promise.all([StakeProgram.authorize({
|
|
19602
19709
|
stakePubkey: targetStakePubkey,
|
|
19603
19710
|
authorizedPubkey: this.authority,
|
|
19604
19711
|
newAuthorizedPubkey: auth,
|
|
19605
|
-
stakeAuthorizationType:
|
|
19606
|
-
}).instructions,
|
|
19712
|
+
stakeAuthorizationType: StakeAuthorizationLayout.Staker
|
|
19713
|
+
}).instructions, StakeProgram.authorize({
|
|
19607
19714
|
stakePubkey: targetStakePubkey,
|
|
19608
19715
|
authorizedPubkey: this.authority,
|
|
19609
19716
|
newAuthorizedPubkey: auth,
|
|
19610
|
-
stakeAuthorizationType:
|
|
19717
|
+
stakeAuthorizationType: StakeAuthorizationLayout.Withdrawer
|
|
19611
19718
|
}).instructions]);
|
|
19612
19719
|
[authorizeStakerIx[0], authorizeWithdrawIx[0]].forEach((ix) => {
|
|
19613
19720
|
ix.keys = ix.keys.map((key) => ({
|
|
19614
19721
|
...key,
|
|
19615
|
-
isWritable: key.pubkey.equals(
|
|
19722
|
+
isWritable: key.pubkey.equals(SYSVAR_CLOCK_ID) ? false : key.isWritable
|
|
19616
19723
|
}));
|
|
19617
19724
|
});
|
|
19618
19725
|
instructions$3.push(...authorizeStakerIx, ...authorizeWithdrawIx);
|
|
19619
19726
|
const depositStakeIx = await SinglePoolInstruction.depositStake(pool, targetStakePubkey, lstAta, this.authority);
|
|
19620
19727
|
const lendrDepositIxs = await this.makeDepositIx(newPoolTokens / 1e9, bankAddress, depositOpts);
|
|
19621
19728
|
instructions$3.push(depositStakeIx, ...lendrDepositIxs.instructions);
|
|
19622
|
-
const transaction = new
|
|
19623
|
-
return
|
|
19624
|
-
type:
|
|
19729
|
+
const transaction = new Transaction().add(...instructions$3);
|
|
19730
|
+
return addTransactionMetadata(transaction, {
|
|
19731
|
+
type: TransactionType.DEPOSIT_STAKE,
|
|
19625
19732
|
signers: [...signers, ...lendrDepositIxs.keys],
|
|
19626
19733
|
addressLookupTables: this.client.addressLookupTables
|
|
19627
19734
|
});
|
|
19628
19735
|
}
|
|
19629
19736
|
async makeMergeStakeAccountsTx(stakeAccountSrc, stakeAccountDest) {
|
|
19630
|
-
const mergeInstruction =
|
|
19737
|
+
const mergeInstruction = StakeProgram.merge({
|
|
19631
19738
|
stakePubkey: stakeAccountDest,
|
|
19632
19739
|
sourceStakePubKey: stakeAccountSrc,
|
|
19633
19740
|
authorizedPubkey: this.authority
|
|
19634
19741
|
});
|
|
19635
|
-
const transaction = new
|
|
19742
|
+
const transaction = new Transaction().add(mergeInstruction);
|
|
19636
19743
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
19637
|
-
return
|
|
19638
|
-
type:
|
|
19744
|
+
return addTransactionMetadata(transaction, {
|
|
19745
|
+
type: TransactionType.MERGE_STAKE_ACCOUNTS,
|
|
19639
19746
|
signers: [],
|
|
19640
19747
|
addressLookupTables: clientLookupTables
|
|
19641
19748
|
});
|
|
@@ -19689,10 +19796,10 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19689
19796
|
*/
|
|
19690
19797
|
async makeDepositTx(amount, bankAddress, depositOpts = {}) {
|
|
19691
19798
|
const ixs = await this.makeDepositIx(amount, bankAddress, depositOpts);
|
|
19692
|
-
const tx = new
|
|
19799
|
+
const tx = new Transaction().add(...ixs.instructions);
|
|
19693
19800
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
19694
|
-
const solanaTx =
|
|
19695
|
-
type:
|
|
19801
|
+
const solanaTx = addTransactionMetadata(tx, {
|
|
19802
|
+
type: TransactionType.DEPOSIT,
|
|
19696
19803
|
signers: ixs.keys,
|
|
19697
19804
|
addressLookupTables: clientLookupTables
|
|
19698
19805
|
});
|
|
@@ -19700,10 +19807,10 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19700
19807
|
}
|
|
19701
19808
|
async makeDepositWithSessionTx(amount, bankAddress, sessionKey, depositOpts = {}) {
|
|
19702
19809
|
const ixs = await this.makeDepositWithSessionIx(amount, bankAddress, sessionKey, depositOpts);
|
|
19703
|
-
const tx = new
|
|
19810
|
+
const tx = new Transaction().add(...ixs.instructions);
|
|
19704
19811
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
19705
|
-
const solanaTx =
|
|
19706
|
-
type:
|
|
19812
|
+
const solanaTx = addTransactionMetadata(tx, {
|
|
19813
|
+
type: TransactionType.DEPOSIT,
|
|
19707
19814
|
signers: ixs.keys,
|
|
19708
19815
|
addressLookupTables: clientLookupTables
|
|
19709
19816
|
});
|
|
@@ -19721,11 +19828,11 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19721
19828
|
async simulateBorrowLendTransaction(txs, banksToInspect, healthSimOptions) {
|
|
19722
19829
|
const additionalTxs = [];
|
|
19723
19830
|
if (healthSimOptions?.enabled) {
|
|
19724
|
-
const computeIx =
|
|
19831
|
+
const computeIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 14e5 });
|
|
19725
19832
|
const updateFeedIx = await this.makeUpdateFeedIx(healthSimOptions.mandatoryBanks);
|
|
19726
19833
|
const healthPulseIx = await this.makePulseHealthIx(healthSimOptions.mandatoryBanks, healthSimOptions.excludedBanks);
|
|
19727
19834
|
const blockhash = (await this.client.provider.connection.getLatestBlockhash("confirmed")).blockhash;
|
|
19728
|
-
const tx = new
|
|
19835
|
+
const tx = new VersionedTransaction(new TransactionMessage({
|
|
19729
19836
|
instructions: [
|
|
19730
19837
|
computeIx,
|
|
19731
19838
|
...updateFeedIx.instructions,
|
|
@@ -19859,10 +19966,10 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19859
19966
|
*/
|
|
19860
19967
|
async makeRepayTx(amount, bankAddress, repayAll = false, repayOpts = {}) {
|
|
19861
19968
|
const ixs = await this.makeRepayIx(amount, bankAddress, repayAll, repayOpts);
|
|
19862
|
-
const tx = new
|
|
19969
|
+
const tx = new Transaction().add(...ixs.instructions);
|
|
19863
19970
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
19864
|
-
const solanaTx =
|
|
19865
|
-
type:
|
|
19971
|
+
const solanaTx = addTransactionMetadata(tx, {
|
|
19972
|
+
type: TransactionType.REPAY,
|
|
19866
19973
|
signers: ixs.keys,
|
|
19867
19974
|
addressLookupTables: clientLookupTables
|
|
19868
19975
|
});
|
|
@@ -19879,10 +19986,10 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19879
19986
|
*/
|
|
19880
19987
|
async makeRepayWithSessionTx(amount, bankAddress, sessionKey, repayAll = false, repayOpts = {}) {
|
|
19881
19988
|
const ixs = await this.makeRepayWithSessionIx(amount, bankAddress, sessionKey, repayAll, repayOpts);
|
|
19882
|
-
const tx = new
|
|
19989
|
+
const tx = new Transaction().add(...ixs.instructions);
|
|
19883
19990
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
19884
|
-
const solanaTx =
|
|
19885
|
-
type:
|
|
19991
|
+
const solanaTx = addTransactionMetadata(tx, {
|
|
19992
|
+
type: TransactionType.REPAY,
|
|
19886
19993
|
signers: ixs.keys,
|
|
19887
19994
|
addressLookupTables: clientLookupTables
|
|
19888
19995
|
});
|
|
@@ -19933,7 +20040,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19933
20040
|
*/
|
|
19934
20041
|
async makeWithdrawStakedTx(amount, bankAddress, isWholePosition) {
|
|
19935
20042
|
const bank = this.client.getBankByPk(bankAddress);
|
|
19936
|
-
const solBank = this.client.getBankByMint(
|
|
20043
|
+
const solBank = this.client.getBankByMint(WSOL_MINT);
|
|
19937
20044
|
const bankMetadata = this.client.bankMetadataMap[bankAddress.toBase58()];
|
|
19938
20045
|
if (!bank || !solBank) {
|
|
19939
20046
|
throw new Error("Banks not found");
|
|
@@ -19941,38 +20048,38 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19941
20048
|
if (!bankMetadata.validatorVoteAccount) {
|
|
19942
20049
|
throw new Error("Validator vote account not found");
|
|
19943
20050
|
}
|
|
19944
|
-
const pool = findPoolAddress(new
|
|
20051
|
+
const pool = findPoolAddress(new PublicKey(bankMetadata.validatorVoteAccount));
|
|
19945
20052
|
const lstMint = findPoolMintAddress(pool);
|
|
19946
20053
|
const mintAuthority = findPoolMintAuthorityAddress(pool);
|
|
19947
|
-
const lstAta =
|
|
20054
|
+
const lstAta = getAssociatedTokenAddressSync(lstMint, this.authority);
|
|
19948
20055
|
const rentExemption = await this._program.provider.connection.getMinimumBalanceForRentExemption(200);
|
|
19949
|
-
const stakeAmount = new
|
|
20056
|
+
const stakeAmount = new BigNumber(new BigNumber(amount).toString());
|
|
19950
20057
|
const withdrawIxs = await this.makeWithdrawIx(amount, bankAddress, isWholePosition, {
|
|
19951
20058
|
createAtas: true,
|
|
19952
20059
|
wrapAndUnwrapSol: true
|
|
19953
20060
|
});
|
|
19954
|
-
const stakeAccount =
|
|
19955
|
-
const createStakeAccountIx =
|
|
20061
|
+
const stakeAccount = Keypair.generate();
|
|
20062
|
+
const createStakeAccountIx = SystemProgram.createAccount({
|
|
19956
20063
|
fromPubkey: this.authority,
|
|
19957
20064
|
newAccountPubkey: stakeAccount.publicKey,
|
|
19958
20065
|
lamports: rentExemption,
|
|
19959
20066
|
space: 200,
|
|
19960
|
-
programId:
|
|
20067
|
+
programId: STAKE_PROGRAM_ID
|
|
19961
20068
|
});
|
|
19962
|
-
const approveAccountAuthorityIx =
|
|
20069
|
+
const approveAccountAuthorityIx = createApproveInstruction(lstAta, mintAuthority, this.authority, stakeAmount.multipliedBy(1e9).toNumber(), [], TOKEN_PROGRAM_ID);
|
|
19963
20070
|
const withdrawStakeIx = await SinglePoolInstruction.withdrawStake(pool, stakeAccount.publicKey, this.authority, lstAta, stakeAmount);
|
|
19964
20071
|
const { value: { blockhash } } = await this._program.provider.connection.getLatestBlockhashAndContext("confirmed");
|
|
19965
|
-
const withdrawMessage = new
|
|
20072
|
+
const withdrawMessage = new TransactionMessage({
|
|
19966
20073
|
payerKey: this.client.wallet.publicKey,
|
|
19967
20074
|
recentBlockhash: blockhash,
|
|
19968
20075
|
instructions: [...withdrawIxs.instructions]
|
|
19969
20076
|
}).compileToV0Message(this.client.addressLookupTables);
|
|
19970
|
-
const withdrawTxn =
|
|
20077
|
+
const withdrawTxn = addTransactionMetadata(new VersionedTransaction(withdrawMessage), {
|
|
19971
20078
|
signers: withdrawIxs.keys,
|
|
19972
20079
|
addressLookupTables: this.client.addressLookupTables,
|
|
19973
|
-
type:
|
|
20080
|
+
type: TransactionType.WITHDRAW
|
|
19974
20081
|
});
|
|
19975
|
-
const stakeMessage = new
|
|
20082
|
+
const stakeMessage = new TransactionMessage({
|
|
19976
20083
|
payerKey: this.client.wallet.publicKey,
|
|
19977
20084
|
recentBlockhash: blockhash,
|
|
19978
20085
|
instructions: [
|
|
@@ -19981,10 +20088,10 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
19981
20088
|
withdrawStakeIx
|
|
19982
20089
|
]
|
|
19983
20090
|
}).compileToV0Message(this.client.addressLookupTables);
|
|
19984
|
-
const stakeTxn =
|
|
20091
|
+
const stakeTxn = addTransactionMetadata(new VersionedTransaction(stakeMessage), {
|
|
19985
20092
|
signers: [stakeAccount],
|
|
19986
20093
|
addressLookupTables: this.client.addressLookupTables,
|
|
19987
|
-
type:
|
|
20094
|
+
type: TransactionType.WITHDRAW_STAKE
|
|
19988
20095
|
});
|
|
19989
20096
|
return {
|
|
19990
20097
|
transactions: [withdrawTxn, stakeTxn],
|
|
@@ -20020,12 +20127,12 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20020
20127
|
const cuRequestIxs = this.makeComputeBudgetIx();
|
|
20021
20128
|
const withdrawIxs = withdrawIxsWrapped.flatMap((ix) => ix.instructions);
|
|
20022
20129
|
const filteredSigners = withdrawIxsWrapped.flatMap((ix) => ix.keys).filter((key, index, self) => index === self.findIndex((k) => k.publicKey.equals(key.publicKey)));
|
|
20023
|
-
const tx = new
|
|
20130
|
+
const tx = new Transaction().add(...cuRequestIxs, ...withdrawIxs);
|
|
20024
20131
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
20025
|
-
const solanaTx =
|
|
20132
|
+
const solanaTx = addTransactionMetadata(tx, {
|
|
20026
20133
|
signers: filteredSigners,
|
|
20027
20134
|
addressLookupTables: clientLookupTables,
|
|
20028
|
-
type:
|
|
20135
|
+
type: TransactionType.WITHDRAW_ALL
|
|
20029
20136
|
});
|
|
20030
20137
|
return solanaTx;
|
|
20031
20138
|
}
|
|
@@ -20092,24 +20199,24 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20092
20199
|
const { value: { blockhash } } = await this._program.provider.connection.getLatestBlockhashAndContext("confirmed");
|
|
20093
20200
|
const feedCrankTxs = [];
|
|
20094
20201
|
if (updateFeedIxs.length > 0) {
|
|
20095
|
-
feedCrankTxs.push(
|
|
20202
|
+
feedCrankTxs.push(addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
20096
20203
|
instructions: [...updateFeedIxs],
|
|
20097
20204
|
payerKey: this.authority,
|
|
20098
20205
|
recentBlockhash: blockhash
|
|
20099
20206
|
}).compileToV0Message(feedLuts)), {
|
|
20100
20207
|
addressLookupTables: feedLuts,
|
|
20101
|
-
type:
|
|
20208
|
+
type: TransactionType.CRANK
|
|
20102
20209
|
}));
|
|
20103
20210
|
}
|
|
20104
20211
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
20105
|
-
const withdrawTx =
|
|
20212
|
+
const withdrawTx = addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
20106
20213
|
instructions: [...cuRequestIxs, ...withdrawIxs.instructions],
|
|
20107
20214
|
payerKey: this.authority,
|
|
20108
20215
|
recentBlockhash: blockhash
|
|
20109
20216
|
}).compileToV0Message(clientLookupTables)), {
|
|
20110
20217
|
signers: withdrawIxs.keys,
|
|
20111
20218
|
addressLookupTables: clientLookupTables,
|
|
20112
|
-
type:
|
|
20219
|
+
type: TransactionType.WITHDRAW
|
|
20113
20220
|
});
|
|
20114
20221
|
const transactions = [...feedCrankTxs, withdrawTx];
|
|
20115
20222
|
return {
|
|
@@ -20134,24 +20241,24 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20134
20241
|
const { value: { blockhash } } = await this._program.provider.connection.getLatestBlockhashAndContext("confirmed");
|
|
20135
20242
|
const feedCrankTxs = [];
|
|
20136
20243
|
if (updateFeedIxs.length > 0) {
|
|
20137
|
-
feedCrankTxs.push(
|
|
20244
|
+
feedCrankTxs.push(addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
20138
20245
|
instructions: [...updateFeedIxs],
|
|
20139
20246
|
payerKey: this.authority,
|
|
20140
20247
|
recentBlockhash: blockhash
|
|
20141
20248
|
}).compileToV0Message(feedLuts)), {
|
|
20142
20249
|
addressLookupTables: feedLuts,
|
|
20143
|
-
type:
|
|
20250
|
+
type: TransactionType.CRANK
|
|
20144
20251
|
}));
|
|
20145
20252
|
}
|
|
20146
20253
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
20147
|
-
const withdrawTx =
|
|
20254
|
+
const withdrawTx = addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
20148
20255
|
instructions: [...cuRequestIxs, ...withdrawIxs.instructions],
|
|
20149
20256
|
payerKey: this.authority,
|
|
20150
20257
|
recentBlockhash: blockhash
|
|
20151
20258
|
}).compileToV0Message(clientLookupTables)), {
|
|
20152
20259
|
signers: withdrawIxs.keys,
|
|
20153
20260
|
addressLookupTables: clientLookupTables,
|
|
20154
|
-
type:
|
|
20261
|
+
type: TransactionType.WITHDRAW
|
|
20155
20262
|
});
|
|
20156
20263
|
const transactions = [...feedCrankTxs, withdrawTx];
|
|
20157
20264
|
return {
|
|
@@ -20254,23 +20361,23 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20254
20361
|
const { value: { blockhash } } = await this._program.provider.connection.getLatestBlockhashAndContext("confirmed");
|
|
20255
20362
|
const feedCrankTxs = [];
|
|
20256
20363
|
if (updateFeedIxs.length > 0) {
|
|
20257
|
-
feedCrankTxs.push(
|
|
20364
|
+
feedCrankTxs.push(addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
20258
20365
|
instructions: updateFeedIxs,
|
|
20259
20366
|
payerKey: this.authority,
|
|
20260
20367
|
recentBlockhash: blockhash
|
|
20261
20368
|
}).compileToV0Message(feedLuts)), {
|
|
20262
|
-
type:
|
|
20369
|
+
type: TransactionType.CRANK,
|
|
20263
20370
|
addressLookupTables: feedLuts
|
|
20264
20371
|
}));
|
|
20265
20372
|
}
|
|
20266
20373
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
20267
|
-
const borrowTx =
|
|
20374
|
+
const borrowTx = addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
20268
20375
|
instructions: [...cuRequestIxs, ...borrowIxs.instructions],
|
|
20269
20376
|
payerKey: this.authority,
|
|
20270
20377
|
recentBlockhash: blockhash
|
|
20271
20378
|
}).compileToV0Message(clientLookupTables)), {
|
|
20272
20379
|
signers: borrowIxs.keys,
|
|
20273
|
-
type:
|
|
20380
|
+
type: TransactionType.BORROW,
|
|
20274
20381
|
addressLookupTables: clientLookupTables
|
|
20275
20382
|
});
|
|
20276
20383
|
const transactions = [...feedCrankTxs, borrowTx];
|
|
@@ -20295,23 +20402,23 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20295
20402
|
const { value: { blockhash } } = await this._program.provider.connection.getLatestBlockhashAndContext("confirmed");
|
|
20296
20403
|
const feedCrankTxs = [];
|
|
20297
20404
|
if (updateFeedIxs.length > 0) {
|
|
20298
|
-
feedCrankTxs.push(
|
|
20405
|
+
feedCrankTxs.push(addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
20299
20406
|
instructions: updateFeedIxs,
|
|
20300
20407
|
payerKey: this.authority,
|
|
20301
20408
|
recentBlockhash: blockhash
|
|
20302
20409
|
}).compileToV0Message(feedLuts)), {
|
|
20303
|
-
type:
|
|
20410
|
+
type: TransactionType.CRANK,
|
|
20304
20411
|
addressLookupTables: feedLuts
|
|
20305
20412
|
}));
|
|
20306
20413
|
}
|
|
20307
20414
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
20308
|
-
const borrowTx =
|
|
20415
|
+
const borrowTx = addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
20309
20416
|
instructions: [...cuRequestIxs, ...borrowIxs.instructions],
|
|
20310
20417
|
payerKey: this.authority,
|
|
20311
20418
|
recentBlockhash: blockhash
|
|
20312
20419
|
}).compileToV0Message(clientLookupTables)), {
|
|
20313
20420
|
signers: borrowIxs.keys,
|
|
20314
|
-
type:
|
|
20421
|
+
type: TransactionType.BORROW,
|
|
20315
20422
|
addressLookupTables: clientLookupTables
|
|
20316
20423
|
});
|
|
20317
20424
|
const transactions = [...feedCrankTxs, borrowTx];
|
|
@@ -20349,13 +20456,13 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20349
20456
|
withdrawEmissionsIxs.push(ix);
|
|
20350
20457
|
}));
|
|
20351
20458
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
20352
|
-
const emissionsTx =
|
|
20459
|
+
const emissionsTx = addTransactionMetadata(new VersionedTransaction(new TransactionMessage({
|
|
20353
20460
|
instructions: withdrawEmissionsIxs.flatMap((ix) => ix.instructions),
|
|
20354
20461
|
payerKey: this.authority,
|
|
20355
20462
|
recentBlockhash: blockhash
|
|
20356
20463
|
}).compileToV0Message(clientLookupTables)), {
|
|
20357
20464
|
signers: withdrawEmissionsIxs.flatMap((ix) => ix.keys),
|
|
20358
|
-
type:
|
|
20465
|
+
type: TransactionType.WITHDRAW_EMISSIONS,
|
|
20359
20466
|
addressLookupTables: clientLookupTables
|
|
20360
20467
|
});
|
|
20361
20468
|
return emissionsTx;
|
|
@@ -20413,12 +20520,12 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20413
20520
|
liquidateeLendrAccount: liquidateeLendrAccount.address.toBase58()
|
|
20414
20521
|
}, "[lendr:lendr-account:liquidation] Liquidating lendr account");
|
|
20415
20522
|
const liquidationIxs = await this.makeLendingAccountLiquidateIx(liquidateeLendrAccount, assetBankAddress, assetQuantityUi, liabBankAddress);
|
|
20416
|
-
const tx = new
|
|
20523
|
+
const tx = new Transaction().add(...liquidationIxs.instructions);
|
|
20417
20524
|
const clientLookupTables = await getClientAddressLookupTableAccounts(this.client);
|
|
20418
|
-
const solanaTx =
|
|
20525
|
+
const solanaTx = addTransactionMetadata(tx, {
|
|
20419
20526
|
signers: liquidationIxs.keys,
|
|
20420
20527
|
addressLookupTables: clientLookupTables,
|
|
20421
|
-
type:
|
|
20528
|
+
type: TransactionType.LIQUIDATE_ACCOUNT
|
|
20422
20529
|
});
|
|
20423
20530
|
const sig = await this.client.processTransaction(solanaTx, processOpts, txOpts);
|
|
20424
20531
|
this.client.logger.debug({
|
|
@@ -20468,14 +20575,14 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20468
20575
|
];
|
|
20469
20576
|
const totalLookupTables = [...lookupTables ?? [], ...args.addressLookupTableAccounts ?? []];
|
|
20470
20577
|
const blockhash = args.blockhash ?? (await this._program.provider.connection.getLatestBlockhash("confirmed")).blockhash;
|
|
20471
|
-
const message = new
|
|
20578
|
+
const message = new TransactionMessage({
|
|
20472
20579
|
payerKey: this.client.wallet.publicKey,
|
|
20473
20580
|
recentBlockhash: blockhash,
|
|
20474
20581
|
instructions: flashloanIxs
|
|
20475
20582
|
}).compileToV0Message(totalLookupTables);
|
|
20476
|
-
const tx =
|
|
20583
|
+
const tx = addTransactionMetadata(new VersionedTransaction(message), {
|
|
20477
20584
|
addressLookupTables: totalLookupTables,
|
|
20478
|
-
type:
|
|
20585
|
+
type: TransactionType.FLASHLOAN
|
|
20479
20586
|
});
|
|
20480
20587
|
if (args.signers) {
|
|
20481
20588
|
tx.sign(args.signers);
|
|
@@ -20491,8 +20598,8 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20491
20598
|
to: newAccountAuthority.toBase58()
|
|
20492
20599
|
}, "[lendr:lendr-account:transfer-authority] Transferring account");
|
|
20493
20600
|
const ixs = await this.makeTransferAccountAuthorityIx(newAccountAuthority);
|
|
20494
|
-
const tx = new
|
|
20495
|
-
const solanaTx =
|
|
20601
|
+
const tx = new Transaction().add(...ixs.instructions);
|
|
20602
|
+
const solanaTx = addTransactionMetadata(tx, { type: TransactionType.TRANSFER_AUTH });
|
|
20496
20603
|
const sig = await this.client.processTransaction(solanaTx, processOpts, txOpts);
|
|
20497
20604
|
this.client.logger.debug({ sig }, "[lendr:lendr-account:transfer-authority] Transfer successful");
|
|
20498
20605
|
return sig;
|
|
@@ -20510,13 +20617,13 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20510
20617
|
return this._lendrAccount.makePulseHealthIx(this._program, this.client.banks, mandatoryBanks, excludedBanks, this.client.bankMetadataMap || {});
|
|
20511
20618
|
}
|
|
20512
20619
|
static async _fetchAccountData(accountAddress, config, program, commitment) {
|
|
20513
|
-
const mergedCommitment = commitment ?? program.provider.connection.commitment ??
|
|
20620
|
+
const mergedCommitment = commitment ?? program.provider.connection.commitment ?? DEFAULT_COMMITMENT;
|
|
20514
20621
|
const data = await program.account.lendrAccount.fetch(accountAddress, mergedCommitment);
|
|
20515
20622
|
if (!data.group.equals(config.groupPk)) throw Error(`Lendr account tied to group ${data.group.toBase58()}. Expected: ${config.groupPk.toBase58()}`);
|
|
20516
20623
|
return data;
|
|
20517
20624
|
}
|
|
20518
20625
|
static async encode(decoded, idl) {
|
|
20519
|
-
const coder = new
|
|
20626
|
+
const coder = new BorshCoder(idl);
|
|
20520
20627
|
return await coder.accounts.encode(AccountType.LendrAccount, decoded);
|
|
20521
20628
|
}
|
|
20522
20629
|
async reload() {
|
|
@@ -20538,7 +20645,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20538
20645
|
*/
|
|
20539
20646
|
async simulateDeposit(amount, bankAddress) {
|
|
20540
20647
|
const ixs = await this.makeDepositIx(amount, bankAddress);
|
|
20541
|
-
const tx = new
|
|
20648
|
+
const tx = new Transaction().add(...ixs.instructions);
|
|
20542
20649
|
try {
|
|
20543
20650
|
return this.simulateBorrowLendTransaction([tx], [bankAddress]);
|
|
20544
20651
|
} catch (e) {
|
|
@@ -20570,7 +20677,7 @@ var LendrAccountWrapper = class LendrAccountWrapper {
|
|
|
20570
20677
|
*/
|
|
20571
20678
|
async simulateRepay(amount, bankAddress, repayAll = false) {
|
|
20572
20679
|
const ixs = await this.makeRepayIx(amount, bankAddress, repayAll);
|
|
20573
|
-
const tx = new
|
|
20680
|
+
const tx = new Transaction().add(...ixs.instructions);
|
|
20574
20681
|
try {
|
|
20575
20682
|
return this.simulateBorrowLendTransaction([tx], [bankAddress]);
|
|
20576
20683
|
} catch (e) {
|
|
@@ -20585,7 +20692,7 @@ function makeTxPriorityIx(feePayer, feeUi = 0, broadcastType = "BUNDLE", compute
|
|
|
20585
20692
|
let bundleTipIx;
|
|
20586
20693
|
let priorityFeeIx = makePriorityFeeIx()[0];
|
|
20587
20694
|
if (broadcastType === "BUNDLE") {
|
|
20588
|
-
bundleTipIx = makeBundleTipIx(feePayer, Math.trunc(feeUi *
|
|
20695
|
+
bundleTipIx = makeBundleTipIx(feePayer, Math.trunc(feeUi * LAMPORTS_PER_SOL));
|
|
20589
20696
|
} else {
|
|
20590
20697
|
priorityFeeIx = makePriorityFeeIx(feeUi, computeUnitsLimit)[0];
|
|
20591
20698
|
}
|
|
@@ -20620,9 +20727,9 @@ function makeBundleTipIx(feePayer, bundleTip = 1e5) {
|
|
|
20620
20727
|
"3AVi9Tg9Uo68tJfuvoKvqKNWKkC5wPdSSdeBnizKZ6jT"
|
|
20621
20728
|
];
|
|
20622
20729
|
const randomTipAccount = tipAccounts[Math.floor(Math.random() * tipAccounts.length)];
|
|
20623
|
-
return
|
|
20730
|
+
return SystemProgram.transfer({
|
|
20624
20731
|
fromPubkey: feePayer,
|
|
20625
|
-
toPubkey: new
|
|
20732
|
+
toPubkey: new PublicKey(randomTipAccount),
|
|
20626
20733
|
lamports: bundleTip
|
|
20627
20734
|
});
|
|
20628
20735
|
}
|
|
@@ -20656,11 +20763,11 @@ var LendrGroup = class LendrGroup {
|
|
|
20656
20763
|
return LendrGroup.fromAccountParsed(address$2, data);
|
|
20657
20764
|
}
|
|
20658
20765
|
static decode(encoded, idl) {
|
|
20659
|
-
const coder = new
|
|
20766
|
+
const coder = new BorshCoder(idl);
|
|
20660
20767
|
return coder.accounts.decode(AccountType.LendrGroup, encoded);
|
|
20661
20768
|
}
|
|
20662
20769
|
static async encode(decoded, idl) {
|
|
20663
|
-
const coder = new
|
|
20770
|
+
const coder = new BorshCoder(idl);
|
|
20664
20771
|
return await coder.accounts.encode(AccountType.LendrGroup, decoded);
|
|
20665
20772
|
}
|
|
20666
20773
|
async makeEnableFlashLoanForAccountIx(program, lendrAccountAddress) {
|
|
@@ -20730,7 +20837,7 @@ var LendrClient = class LendrClient {
|
|
|
20730
20837
|
this.bankMetadataMap = bankMetadataMap;
|
|
20731
20838
|
this.overrideBankAddresses = overrideBankAddresses;
|
|
20732
20839
|
this.overrideBanksMetadata = overrideBanksMetadata;
|
|
20733
|
-
this.storage = storage ??
|
|
20840
|
+
this.storage = storage ?? createStorage();
|
|
20734
20841
|
this.metadataService = metadataService;
|
|
20735
20842
|
this.dataFetcher = dataFetcher ?? new DataFetcher();
|
|
20736
20843
|
}
|
|
@@ -20746,7 +20853,11 @@ var LendrClient = class LendrClient {
|
|
|
20746
20853
|
* @returns LendrClient instance
|
|
20747
20854
|
*/
|
|
20748
20855
|
static async fetch({ wallet, connection, clientOptions = {}, config = getConfig() }) {
|
|
20749
|
-
const { logger = new NoopLogger(), confirmOpts = {}, readOnly = false, storage =
|
|
20856
|
+
const { logger = new NoopLogger(), confirmOpts = {}, readOnly = false, storage = createStorage(), dataFetcher = new DataFetcher(), overrideBankAddresses, overrideBanksMetadata, metadataFetchers = [
|
|
20857
|
+
new FogoMetadataFetcher(),
|
|
20858
|
+
new MetaplexMetadataFetcher(connection.rpcEndpoint),
|
|
20859
|
+
new DummyMetadataFetcher()
|
|
20860
|
+
], addressLookupTableAddresses } = clientOptions;
|
|
20750
20861
|
logger.debug({
|
|
20751
20862
|
programId: config.programId.toBase58(),
|
|
20752
20863
|
env: config.environment,
|
|
@@ -20754,16 +20865,22 @@ var LendrClient = class LendrClient {
|
|
|
20754
20865
|
url: connection?.rpcEndpoint
|
|
20755
20866
|
}, "[lendr:client] Loading Lendr Client");
|
|
20756
20867
|
const programIdl = fetchLatestIdl();
|
|
20757
|
-
const provider = new
|
|
20758
|
-
...
|
|
20759
|
-
commitment: connection.commitment ??
|
|
20868
|
+
const provider = new AnchorProvider(connection, wallet, {
|
|
20869
|
+
...AnchorProvider.defaultOptions(),
|
|
20870
|
+
commitment: connection.commitment ?? AnchorProvider.defaultOptions().commitment,
|
|
20760
20871
|
...confirmOpts
|
|
20761
20872
|
});
|
|
20762
20873
|
const idl = {
|
|
20763
20874
|
...programIdl,
|
|
20764
20875
|
address: config.programId.toBase58()
|
|
20765
20876
|
};
|
|
20766
|
-
const program = new
|
|
20877
|
+
const program = new Program(idl, provider);
|
|
20878
|
+
const metadataService = new MetadataService({
|
|
20879
|
+
storage,
|
|
20880
|
+
overrides: overrideBanksMetadata,
|
|
20881
|
+
fetchers: metadataFetchers,
|
|
20882
|
+
logger
|
|
20883
|
+
});
|
|
20767
20884
|
const { lendrGroup, banks, priceInfos, tokensData, feedIdMap, banksExtendedMetadata } = await LendrClient.fetchGroupData({
|
|
20768
20885
|
connection,
|
|
20769
20886
|
program,
|
|
@@ -20841,12 +20958,12 @@ var LendrClient = class LendrClient {
|
|
|
20841
20958
|
const oracleKeys = [];
|
|
20842
20959
|
for (const bank of banksRawData) {
|
|
20843
20960
|
mintKeys.push(bank.data.mint);
|
|
20844
|
-
if (!bank.data.emissionsMint.equals(
|
|
20961
|
+
if (!bank.data.emissionsMint.equals(PublicKey.default)) {
|
|
20845
20962
|
emissionMintKeys.push(bank.data.emissionsMint);
|
|
20846
20963
|
}
|
|
20847
20964
|
oracleKeys.push(findOracleKey(BankConfig.fromAccountParsed(bank.data.config), feedIdMap).oracleKey);
|
|
20848
20965
|
}
|
|
20849
|
-
const allAccountInfos = await
|
|
20966
|
+
const allAccountInfos = await chunkedGetRawMultipleAccountInfoOrdered(program.provider.connection, [
|
|
20850
20967
|
groupAddress.toBase58(),
|
|
20851
20968
|
...oracleKeys.map((pk) => pk.toBase58()),
|
|
20852
20969
|
...mintKeys.map((pk) => pk.toBase58()),
|
|
@@ -20860,7 +20977,7 @@ var LendrClient = class LendrClient {
|
|
|
20860
20977
|
const mintAccountInfos = allAccountInfos.splice(0, mintKeys.length);
|
|
20861
20978
|
const emissionMintAccountInfos = allAccountInfos.splice(0);
|
|
20862
20979
|
const lendrGroup = LendrGroup.fromBuffer(groupAddress, groupAccountInfo.data, program.idl);
|
|
20863
|
-
const banksExtendedMetadata = await
|
|
20980
|
+
const banksExtendedMetadata = await fetchBanksExtendedMetadata({
|
|
20864
20981
|
mintsWithOwner: mintKeys.map((mint, idx) => ({
|
|
20865
20982
|
mint,
|
|
20866
20983
|
owner: mintAccountInfos[idx].owner
|
|
@@ -20879,6 +20996,14 @@ var LendrClient = class LendrClient {
|
|
|
20879
20996
|
banksRawData.forEach(({ address: address$2, data }, index) => {
|
|
20880
20997
|
const bankAddressStr = address$2.toBase58();
|
|
20881
20998
|
const metadata$2 = banksExtendedMetadata.get(data.mint.toBase58());
|
|
20999
|
+
const oracleSetup = parseOracleSetup(data.config.oracleSetup);
|
|
21000
|
+
if (!isOracleSetupSupported(oracleSetup)) {
|
|
21001
|
+
logger.warn({
|
|
21002
|
+
oracleSetup,
|
|
21003
|
+
bank: bankAddressStr
|
|
21004
|
+
}, "unsupported oracle setup");
|
|
21005
|
+
return;
|
|
21006
|
+
}
|
|
20882
21007
|
const mintDataRaw = mintAccountInfos[index];
|
|
20883
21008
|
if (!mintDataRaw) {
|
|
20884
21009
|
throw new Error(`Failed to fetch mint account for bank ${bankAddressStr}`);
|
|
@@ -20890,7 +21015,7 @@ var LendrClient = class LendrClient {
|
|
|
20890
21015
|
const bank = Bank.fromAccountParsed(address$2, data, feedIdMap, metadata$2, mintDataRaw.owner);
|
|
20891
21016
|
banks.set(bankAddressStr, bank);
|
|
20892
21017
|
let emissionTokenProgram = null;
|
|
20893
|
-
if (!data.emissionsMint.equals(
|
|
21018
|
+
if (!data.emissionsMint.equals(PublicKey.default)) {
|
|
20894
21019
|
const emissionMintDataRawIndex = emissionMintKeys.findIndex((pk) => pk.equals(data.emissionsMint));
|
|
20895
21020
|
emissionTokenProgram = emissionMintDataRawIndex >= 0 ? emissionMintAccountInfos[emissionMintDataRawIndex].owner : null;
|
|
20896
21021
|
}
|
|
@@ -20900,14 +21025,13 @@ var LendrClient = class LendrClient {
|
|
|
20900
21025
|
feeBps: 0,
|
|
20901
21026
|
emissionTokenProgram
|
|
20902
21027
|
});
|
|
20903
|
-
const oracleSetup = parseOracleSetup(data.config.oracleSetup);
|
|
20904
21028
|
priceInfos.set(bankAddressStr, parseOraclePriceData(oracleSetup, priceDataRaw.data, logger));
|
|
20905
21029
|
if (oracleSetup === OracleSetup.StakedWithPythPush && metadata$2?.validatorVoteAccount) {
|
|
20906
|
-
const [poolAddress] =
|
|
20907
|
-
const [stakePoolAddress] =
|
|
21030
|
+
const [poolAddress] = PublicKey.findProgramAddressSync([Buffer.from("pool"), new PublicKey(metadata$2.validatorVoteAccount).toBuffer()], SINGLE_POOL_PROGRAM_ID);
|
|
21031
|
+
const [stakePoolAddress] = PublicKey.findProgramAddressSync([Buffer.from("stake"), poolAddress.toBuffer()], SINGLE_POOL_PROGRAM_ID);
|
|
20908
21032
|
stakedCollatMap[address$2.toBase58()] = {
|
|
20909
21033
|
bankAddress: address$2,
|
|
20910
|
-
mint: new
|
|
21034
|
+
mint: new PublicKey(metadata$2.mint),
|
|
20911
21035
|
stakePoolAddress,
|
|
20912
21036
|
poolAddress
|
|
20913
21037
|
};
|
|
@@ -20915,9 +21039,9 @@ var LendrClient = class LendrClient {
|
|
|
20915
21039
|
mints.push(metadata$2.mint);
|
|
20916
21040
|
}
|
|
20917
21041
|
});
|
|
20918
|
-
const dataAis = await
|
|
21042
|
+
const dataAis = await chunkedGetRawMultipleAccountInfoOrdered(program.provider.connection, [...mints, ...solPools]);
|
|
20919
21043
|
const stakePoolsAis = dataAis.slice(mints.length).map((ai) => getStakeAccount(ai.data));
|
|
20920
|
-
const lstMintsAis = dataAis.slice(0, mints.length).map((mintAi) =>
|
|
21044
|
+
const lstMintsAis = dataAis.slice(0, mints.length).map((mintAi) => MintLayout.decode(mintAi.data));
|
|
20921
21045
|
const lstMintRecord = Object.fromEntries(mints.map((mint, i) => [mint, lstMintsAis[i]]));
|
|
20922
21046
|
const solPoolsRecord = Object.fromEntries(solPools.map((poolKey, i) => [poolKey, stakePoolsAis[i]]));
|
|
20923
21047
|
for (const index in stakedCollatMap) {
|
|
@@ -20928,7 +21052,7 @@ var LendrClient = class LendrClient {
|
|
|
20928
21052
|
const oracle = priceInfos.get(bankAddress.toBase58());
|
|
20929
21053
|
if (oracle) {
|
|
20930
21054
|
const adjustPrice = (price, stakeActual$1, tokenSupply$1) => {
|
|
20931
|
-
return Number(tokenSupply$1) === 0 ? price : new
|
|
21055
|
+
return Number(tokenSupply$1) === 0 ? price : new BigNumber(price.toNumber() * (stakeActual$1 - LAMPORTS_PER_SOL) / Number(tokenSupply$1));
|
|
20932
21056
|
};
|
|
20933
21057
|
const adjustPriceComponent$1 = (priceComponent, stakeActual$1, tokenSupply$1) => ({
|
|
20934
21058
|
price: adjustPrice(priceComponent.price, stakeActual$1, tokenSupply$1),
|
|
@@ -21040,7 +21164,7 @@ var LendrClient = class LendrClient {
|
|
|
21040
21164
|
offset: 8
|
|
21041
21165
|
} }, { memcmp: {
|
|
21042
21166
|
offset: 0,
|
|
21043
|
-
bytes: bs58.
|
|
21167
|
+
bytes: bs58.encode(new BorshAccountsCoder(this.program.idl).accountDiscriminator(AccountType.LendrAccount))
|
|
21044
21168
|
} }]
|
|
21045
21169
|
})).map((a) => a.pubkey);
|
|
21046
21170
|
}
|
|
@@ -21050,7 +21174,7 @@ var LendrClient = class LendrClient {
|
|
|
21050
21174
|
* @returns LendrAccount instances
|
|
21051
21175
|
*/
|
|
21052
21176
|
async getLendrAccountsForAuthority(authority) {
|
|
21053
|
-
const _authority = authority ?
|
|
21177
|
+
const _authority = authority ? translateAddress(authority) : this.provider.wallet.publicKey;
|
|
21054
21178
|
const lendrAccounts = (await this.program.account.lendrAccount.all([{ memcmp: {
|
|
21055
21179
|
bytes: this.groupAddress.toBase58(),
|
|
21056
21180
|
offset: 8
|
|
@@ -21080,16 +21204,16 @@ var LendrClient = class LendrClient {
|
|
|
21080
21204
|
},
|
|
21081
21205
|
filters: [{ memcmp: {
|
|
21082
21206
|
offset: 0,
|
|
21083
|
-
bytes: bs58.
|
|
21207
|
+
bytes: bs58.encode(new BorshAccountsCoder(this.program.idl).accountDiscriminator(AccountType.LendrAccount))
|
|
21084
21208
|
} }]
|
|
21085
21209
|
})).map((a) => a.pubkey);
|
|
21086
21210
|
}
|
|
21087
21211
|
getBankByPk(bankAddress) {
|
|
21088
|
-
const _bankAddress =
|
|
21212
|
+
const _bankAddress = translateAddress(bankAddress);
|
|
21089
21213
|
return this.banks.get(_bankAddress.toString()) ?? null;
|
|
21090
21214
|
}
|
|
21091
21215
|
getBankByMint(mint) {
|
|
21092
|
-
const _mint =
|
|
21216
|
+
const _mint = translateAddress(mint);
|
|
21093
21217
|
return [...this.banks.values()].find((bank) => bank.mint.equals(_mint)) ?? null;
|
|
21094
21218
|
}
|
|
21095
21219
|
getBankByTokenSymbol(tokenSymbol) {
|
|
@@ -21097,7 +21221,7 @@ var LendrClient = class LendrClient {
|
|
|
21097
21221
|
return [...this.banks.values()].find((bank) => bank.tokenSymbol === tokenSymbol) ?? null;
|
|
21098
21222
|
}
|
|
21099
21223
|
getOraclePriceByBank(bankAddress) {
|
|
21100
|
-
const _bankAddress =
|
|
21224
|
+
const _bankAddress = translateAddress(bankAddress);
|
|
21101
21225
|
return this.oraclePrices.get(_bankAddress.toString()) ?? null;
|
|
21102
21226
|
}
|
|
21103
21227
|
/**
|
|
@@ -21142,7 +21266,7 @@ var LendrClient = class LendrClient {
|
|
|
21142
21266
|
* @returns Object containing the transaction signature and the created LendrAccount instance
|
|
21143
21267
|
*/
|
|
21144
21268
|
async createLendrAccount(createOpts, processOpts, txOpts) {
|
|
21145
|
-
const accountKeypair =
|
|
21269
|
+
const accountKeypair = Keypair.generate();
|
|
21146
21270
|
const newAccountKey = createOpts?.newAccountKey ?? accountKeypair.publicKey;
|
|
21147
21271
|
const solanaTx = await this.createLendrAccountTx({ accountKeypair });
|
|
21148
21272
|
const sig = await this.processTransaction(solanaTx, processOpts, txOpts);
|
|
@@ -21159,11 +21283,11 @@ var LendrClient = class LendrClient {
|
|
|
21159
21283
|
* @returns Object containing the transaction signature and the created LendrAccount instance
|
|
21160
21284
|
*/
|
|
21161
21285
|
async createLendrAccountWithSession(session, commitment, customAccountSeed) {
|
|
21162
|
-
const accountSeed = new
|
|
21163
|
-
const tx = await this.createLendrAccountWithSessionTx(session, new
|
|
21286
|
+
const accountSeed = new BN$1(customAccountSeed ?? 0);
|
|
21287
|
+
const tx = await this.createLendrAccountWithSessionTx(session, new BN$1(accountSeed ?? 0));
|
|
21164
21288
|
const txResult = await session.sendTransaction(tx);
|
|
21165
21289
|
this.logger.debug({ txResult }, "Created Lendr account (using session)");
|
|
21166
|
-
const [accountPublicKey] =
|
|
21290
|
+
const [accountPublicKey] = PublicKey.findProgramAddressSync([
|
|
21167
21291
|
Buffer.from("pyroners"),
|
|
21168
21292
|
session.walletPublicKey.toBuffer(),
|
|
21169
21293
|
this.groupAddress.toBuffer(),
|
|
@@ -21192,15 +21316,15 @@ var LendrClient = class LendrClient {
|
|
|
21192
21316
|
* @returns Transaction that can be used to create a new lendr account
|
|
21193
21317
|
*/
|
|
21194
21318
|
async createLendrAccountTx(createOpts) {
|
|
21195
|
-
const accountKeypair = createOpts?.accountKeypair ??
|
|
21319
|
+
const accountKeypair = createOpts?.accountKeypair ?? Keypair.generate();
|
|
21196
21320
|
const ixs = await this.makeCreateLendrAccountIx(accountKeypair.publicKey);
|
|
21197
21321
|
const signers = [...ixs.keys];
|
|
21198
21322
|
signers.push(accountKeypair);
|
|
21199
|
-
const tx = new
|
|
21200
|
-
const solanaTx =
|
|
21323
|
+
const tx = new Transaction().add(...ixs.instructions);
|
|
21324
|
+
const solanaTx = addTransactionMetadata(tx, {
|
|
21201
21325
|
signers,
|
|
21202
21326
|
addressLookupTables: this.addressLookupTables,
|
|
21203
|
-
type:
|
|
21327
|
+
type: TransactionType.CREATE_ACCOUNT
|
|
21204
21328
|
});
|
|
21205
21329
|
return solanaTx;
|
|
21206
21330
|
}
|
|
@@ -21208,29 +21332,29 @@ var LendrClient = class LendrClient {
|
|
|
21208
21332
|
try {
|
|
21209
21333
|
return (await this.provider.connection.getLatestBlockhashAndContext("confirmed")).value.blockhash;
|
|
21210
21334
|
} catch (ex) {
|
|
21211
|
-
const connection = new
|
|
21335
|
+
const connection = new Connection(this.provider.connection.rpcEndpoint, this.provider.opts);
|
|
21212
21336
|
return (await connection.getLatestBlockhashAndContext("confirmed")).value.blockhash;
|
|
21213
21337
|
}
|
|
21214
21338
|
}
|
|
21215
21339
|
async createVersionTransaction(instructions$3, payerKey, signers, extraMetaData) {
|
|
21216
21340
|
const blockhash = await this.getLatestBlockHashForSure();
|
|
21217
|
-
const versionedMessage = new
|
|
21341
|
+
const versionedMessage = new TransactionMessage({
|
|
21218
21342
|
instructions: instructions$3,
|
|
21219
21343
|
payerKey,
|
|
21220
21344
|
recentBlockhash: blockhash
|
|
21221
21345
|
});
|
|
21222
|
-
const tx = new
|
|
21346
|
+
const tx = new VersionedTransaction(this.addressLookupTables ? versionedMessage.compileToV0Message(this.addressLookupTables) : versionedMessage.compileToLegacyMessage());
|
|
21223
21347
|
if (signers?.length) {
|
|
21224
21348
|
tx.sign(signers);
|
|
21225
21349
|
}
|
|
21226
21350
|
if (extraMetaData && Object.keys(extraMetaData)?.length) {
|
|
21227
|
-
return
|
|
21351
|
+
return addTransactionMetadata(tx, extraMetaData);
|
|
21228
21352
|
}
|
|
21229
21353
|
return tx;
|
|
21230
21354
|
}
|
|
21231
21355
|
async createLendrAccountWithSessionTx(session, accountSeed) {
|
|
21232
21356
|
const ixs = await this.makeCreateLendrAccountWithSessionIx(session, accountSeed);
|
|
21233
|
-
return this.createVersionTransaction(ixs.instructions, session.payer, [...ixs.keys], { type:
|
|
21357
|
+
return this.createVersionTransaction(ixs.instructions, session.payer, [...ixs.keys], { type: TransactionType.CREATE_ACCOUNT });
|
|
21234
21358
|
}
|
|
21235
21359
|
/**
|
|
21236
21360
|
* Create transaction instruction to initialize a new group.
|
|
@@ -21263,14 +21387,14 @@ var LendrClient = class LendrClient {
|
|
|
21263
21387
|
* @returns {Promise<TransactionSignature>} A promise that resolves to the transaction signature as a string.
|
|
21264
21388
|
*/
|
|
21265
21389
|
async createPermissionlessBank({ mint, bankConfig, group, admin, seed, txOpts, processOpts }) {
|
|
21266
|
-
const keypair = seed ??
|
|
21390
|
+
const keypair = seed ?? Keypair.generate();
|
|
21267
21391
|
const bankIxs = await this.group.makePoolAddBankIx(this.program, keypair.publicKey, mint, bankConfig, admin);
|
|
21268
21392
|
const signers = [...bankIxs.keys, keypair];
|
|
21269
|
-
const tx = new
|
|
21270
|
-
const solanaTx =
|
|
21393
|
+
const tx = new Transaction().add(...bankIxs.instructions);
|
|
21394
|
+
const solanaTx = addTransactionMetadata(tx, {
|
|
21271
21395
|
signers,
|
|
21272
21396
|
addressLookupTables: this.addressLookupTables,
|
|
21273
|
-
type:
|
|
21397
|
+
type: TransactionType.CREATE_PERM_BANK
|
|
21274
21398
|
});
|
|
21275
21399
|
const sig = await this.processTransaction(solanaTx, processOpts, txOpts);
|
|
21276
21400
|
this.logger.debug({ sig }, "Created Lendr group");
|
|
@@ -21286,14 +21410,14 @@ var LendrClient = class LendrClient {
|
|
|
21286
21410
|
* @returns The public key of the newly created lendr group.
|
|
21287
21411
|
*/
|
|
21288
21412
|
async createLendrGroup(seed, additionalIxs, processOpts, txOpts) {
|
|
21289
|
-
const accountKeypair = seed ??
|
|
21413
|
+
const accountKeypair = seed ?? Keypair.generate();
|
|
21290
21414
|
const ixs = await this.makeCreateLendrGroupIx(accountKeypair.publicKey);
|
|
21291
21415
|
const signers = [...ixs.keys, accountKeypair];
|
|
21292
|
-
const tx = new
|
|
21293
|
-
const solanaTx =
|
|
21416
|
+
const tx = new Transaction().add(...ixs.instructions, ...additionalIxs ?? []);
|
|
21417
|
+
const solanaTx = addTransactionMetadata(tx, {
|
|
21294
21418
|
signers,
|
|
21295
21419
|
addressLookupTables: this.addressLookupTables,
|
|
21296
|
-
type:
|
|
21420
|
+
type: TransactionType.CREATE_GROUP
|
|
21297
21421
|
});
|
|
21298
21422
|
const sig = await this.processTransaction(solanaTx, processOpts, txOpts);
|
|
21299
21423
|
this.logger.debug({ sig }, "Created Lendr group");
|
|
@@ -21310,14 +21434,14 @@ var LendrClient = class LendrClient {
|
|
|
21310
21434
|
* @returns The bank's public key and the transaction signature
|
|
21311
21435
|
*/
|
|
21312
21436
|
async createLendingPool(bankMint, bankConfig, seed, processOpts, txOpts) {
|
|
21313
|
-
const bankKeypair = seed ??
|
|
21437
|
+
const bankKeypair = seed ?? Keypair.generate();
|
|
21314
21438
|
const ixs = await this.group.makePoolAddBankIx(this.program, bankKeypair.publicKey, bankMint, bankConfig);
|
|
21315
21439
|
const signers = [...ixs.keys, bankKeypair];
|
|
21316
|
-
const tx = new
|
|
21317
|
-
const solanaTx =
|
|
21440
|
+
const tx = new Transaction().add(...ixs.instructions);
|
|
21441
|
+
const solanaTx = addTransactionMetadata(tx, {
|
|
21318
21442
|
signers,
|
|
21319
21443
|
addressLookupTables: this.addressLookupTables,
|
|
21320
|
-
type:
|
|
21444
|
+
type: TransactionType.CREATE_PERM_BANK
|
|
21321
21445
|
});
|
|
21322
21446
|
const sig = await this.processTransaction(solanaTx, processOpts, txOpts);
|
|
21323
21447
|
this.logger.debug({ sig }, "Created new lending pool");
|
|
@@ -21386,21 +21510,21 @@ var LendrClient = class LendrClient {
|
|
|
21386
21510
|
}
|
|
21387
21511
|
async simulateTransactions(transactions, accountsToInspect) {
|
|
21388
21512
|
const versionedTransactions = [];
|
|
21389
|
-
const connection = new
|
|
21513
|
+
const connection = new Connection(this.provider.connection.rpcEndpoint, this.provider.opts);
|
|
21390
21514
|
let blockhash;
|
|
21391
21515
|
try {
|
|
21392
21516
|
const getLatestBlockhashAndContext = await connection.getLatestBlockhashAndContext("confirmed");
|
|
21393
21517
|
blockhash = getLatestBlockhashAndContext.value.blockhash;
|
|
21394
21518
|
for (const transaction of transactions) {
|
|
21395
|
-
if (
|
|
21519
|
+
if (isV0Tx(transaction)) {
|
|
21396
21520
|
versionedTransactions.push(transaction);
|
|
21397
21521
|
} else {
|
|
21398
|
-
const versionedMessage = new
|
|
21522
|
+
const versionedMessage = new TransactionMessage({
|
|
21399
21523
|
instructions: transaction.instructions,
|
|
21400
21524
|
payerKey: this.provider.publicKey,
|
|
21401
21525
|
recentBlockhash: blockhash
|
|
21402
21526
|
});
|
|
21403
|
-
versionedTransactions.push(new
|
|
21527
|
+
versionedTransactions.push(new VersionedTransaction(versionedMessage.compileToV0Message(this.addressLookupTables)));
|
|
21404
21528
|
}
|
|
21405
21529
|
}
|
|
21406
21530
|
} catch (error) {
|
|
@@ -21476,226 +21600,5 @@ var LendrClient = class LendrClient {
|
|
|
21476
21600
|
var client_default = LendrClient;
|
|
21477
21601
|
|
|
21478
21602
|
//#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
|
-
});
|
|
21603
|
+
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, DummyMetadataFetcher, EmodeEntryFlags, EmodeFlags, EmodeImpactStatus, EmodeSettings, EmodeTag, FLASHLOAN_ENABLED_FLAG, GROUP_PK, HOURS_PER_YEAR, HealthCache, HealthCacheFlags, HealthCacheSimulationError, 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, MetadataService, MetaplexMetadataFetcher, 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, isOracleSetupSupported, 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, supportedOracleSetups, toBankConfigDto, toBankDto, toEmodeSettingsDto, toInterestRateConfigDto, validatorStakeGroupToDto, vendor_exports as vendor };
|
|
21604
|
+
//# sourceMappingURL=index.js.map
|