@0dotxyz/p0-ts-sdk 2.8.0-alpha.4 → 2.8.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +103 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -2
- package/dist/index.d.ts +17 -2
- package/dist/index.js +102 -22
- package/dist/index.js.map +1 -1
- package/dist/instructions.cjs +6 -1
- package/dist/instructions.cjs.map +1 -1
- package/dist/instructions.d.cts +11 -1
- package/dist/instructions.d.ts +11 -1
- package/dist/instructions.js +6 -1
- package/dist/instructions.js.map +1 -1
- package/dist/vendor.cjs +37 -19
- package/dist/vendor.cjs.map +1 -1
- package/dist/vendor.d.cts +1 -1
- package/dist/vendor.d.ts +1 -1
- package/dist/vendor.js +29 -11
- package/dist/vendor.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -21837,7 +21837,11 @@ async function makeLendingPoolConfigureBankOracleIx(mfProgram, accounts, args, r
|
|
|
21837
21837
|
}
|
|
21838
21838
|
async function makeLendingPoolConfigureBankOracleScopeIx(mfProgram, accounts, args) {
|
|
21839
21839
|
const { bank, ...optionalAccounts } = accounts;
|
|
21840
|
-
return mfProgram.methods.lendingPoolConfigureBankOracleScope(args.oracle, args.entryIndex).accounts({ bank }).accountsPartial(optionalAccounts).instruction();
|
|
21840
|
+
return mfProgram.methods.lendingPoolConfigureBankOracleScope(args.oracle, args.entryIndex).accounts({ bank }).accountsPartial(optionalAccounts).remainingAccounts([{ pubkey: args.oracle, isSigner: false, isWritable: false }]).instruction();
|
|
21841
|
+
}
|
|
21842
|
+
async function makeLendingPoolSetOraclePriceIx(mfProgram, accounts, args, remainingAccounts = []) {
|
|
21843
|
+
const { bank, ...optionalAccounts } = accounts;
|
|
21844
|
+
return mfProgram.methods.lendingPoolSetOraclePrice(args.price, args.setup).accounts({ bank }).accountsPartial(optionalAccounts).remainingAccounts(remainingAccounts).instruction();
|
|
21841
21845
|
}
|
|
21842
21846
|
async function makePoolAddPermissionlessStakedBankIx(mfProgram, accounts, remainingAccounts = [], args) {
|
|
21843
21847
|
const {
|
|
@@ -21912,6 +21916,7 @@ var instructions = {
|
|
|
21912
21916
|
makePoolAddPermissionlessStakedBankIx,
|
|
21913
21917
|
makeLendingPoolConfigureBankOracleIx,
|
|
21914
21918
|
makeLendingPoolConfigureBankOracleScopeIx,
|
|
21919
|
+
makeLendingPoolSetOraclePriceIx,
|
|
21915
21920
|
makePulseHealthIx
|
|
21916
21921
|
};
|
|
21917
21922
|
var instructions_default = instructions;
|
|
@@ -22646,7 +22651,7 @@ function dtoToBankConfig(bankConfigDto) {
|
|
|
22646
22651
|
interestRateConfig: dtoToInterestRateConfig(bankConfigDto.interestRateConfig),
|
|
22647
22652
|
oracleMaxConfidence: bankConfigDto.oracleMaxConfidence,
|
|
22648
22653
|
fixedPrice: new BigNumber3__default.default(bankConfigDto.fixedPrice),
|
|
22649
|
-
scopeEntryIndex: bankConfigDto.scopeEntryIndex
|
|
22654
|
+
scopeEntryIndex: bankConfigDto.scopeEntryIndex
|
|
22650
22655
|
};
|
|
22651
22656
|
}
|
|
22652
22657
|
function dtoToInterestRateConfig(interestRateConfigDto) {
|
|
@@ -22760,7 +22765,7 @@ function dtoToBankConfigRaw(bankConfigDto) {
|
|
|
22760
22765
|
interestRateConfig: bankConfigDto.interestRateConfig,
|
|
22761
22766
|
oracleMaxConfidence: bankConfigDto.oracleMaxConfidence,
|
|
22762
22767
|
fixedPrice: bankConfigDto.fixedPrice,
|
|
22763
|
-
scopeEntryIndex: bankConfigDto.scopeEntryIndex
|
|
22768
|
+
scopeEntryIndex: bankConfigDto.scopeEntryIndex
|
|
22764
22769
|
};
|
|
22765
22770
|
}
|
|
22766
22771
|
function parseBankConfigRaw(bankConfigRaw) {
|
|
@@ -22800,7 +22805,7 @@ function parseBankConfigRaw(bankConfigRaw) {
|
|
|
22800
22805
|
};
|
|
22801
22806
|
const oracleMaxConfidence = bankConfigRaw.oracleMaxConfidence;
|
|
22802
22807
|
const fixedPrice = wrappedI80F48toBigNumber(bankConfigRaw.fixedPrice);
|
|
22803
|
-
const scopeEntryIndex = bankConfigRaw.scopeEntryIndex
|
|
22808
|
+
const scopeEntryIndex = bankConfigRaw.scopeEntryIndex;
|
|
22804
22809
|
return {
|
|
22805
22810
|
assetWeightInit,
|
|
22806
22811
|
assetWeightMaint,
|
|
@@ -52611,7 +52616,8 @@ function makeLendingPoolConfigureBankOracleScopeIx2(programId, accounts, args) {
|
|
|
52611
52616
|
const keys = [
|
|
52612
52617
|
{ pubkey: accounts.group, isSigner: false, isWritable: false },
|
|
52613
52618
|
{ pubkey: accounts.admin, isSigner: true, isWritable: false },
|
|
52614
|
-
{ pubkey: accounts.bank, isSigner: false, isWritable: true }
|
|
52619
|
+
{ pubkey: accounts.bank, isSigner: false, isWritable: true },
|
|
52620
|
+
{ pubkey: args.oracle, isSigner: false, isWritable: false }
|
|
52615
52621
|
];
|
|
52616
52622
|
const data = Buffer.concat([
|
|
52617
52623
|
DISCRIMINATORS.LENDING_POOL_CONFIGURE_BANK_ORACLE_SCOPE,
|
|
@@ -75371,10 +75377,15 @@ function decodeScopePriceAtIndex(data, entryIndex) {
|
|
|
75371
75377
|
}
|
|
75372
75378
|
new web3_js.PublicKey("MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD");
|
|
75373
75379
|
var MARINADE_STATE_DISCRIMINATOR = Buffer.from([216, 146, 107, 94, 104, 75, 182, 177]);
|
|
75374
|
-
var
|
|
75375
|
-
var
|
|
75376
|
-
var
|
|
75377
|
-
var
|
|
75380
|
+
var DELAYED_UNSTAKE_COOLING_DOWN_OFFSET = 226;
|
|
75381
|
+
var TOTAL_ACTIVE_BALANCE_OFFSET = 376;
|
|
75382
|
+
var AVAILABLE_RESERVE_BALANCE_OFFSET = 496;
|
|
75383
|
+
var MSOL_SUPPLY_OFFSET = 504;
|
|
75384
|
+
var CIRCULATING_TICKET_BALANCE_OFFSET = 528;
|
|
75385
|
+
var EMERGENCY_COOLING_DOWN_OFFSET = 568;
|
|
75386
|
+
var MARINADE_STATE_MIN_SIZE = EMERGENCY_COOLING_DOWN_OFFSET + 8;
|
|
75387
|
+
var U64_MAX = (1n << 64n) - 1n;
|
|
75388
|
+
var MAX_MSOL_SOL_RATE = 3;
|
|
75378
75389
|
function decodeMarinadeState(data) {
|
|
75379
75390
|
if (data.length < MARINADE_STATE_MIN_SIZE) {
|
|
75380
75391
|
throw new Error(`Invalid Marinade State account size: ${data.length}`);
|
|
@@ -75382,8 +75393,21 @@ function decodeMarinadeState(data) {
|
|
|
75382
75393
|
if (!data.subarray(0, 8).equals(MARINADE_STATE_DISCRIMINATOR)) {
|
|
75383
75394
|
throw new Error("Invalid Marinade State discriminator");
|
|
75384
75395
|
}
|
|
75385
|
-
const
|
|
75386
|
-
const
|
|
75396
|
+
const delayedUnstakeCoolingDown = data.readBigUInt64LE(DELAYED_UNSTAKE_COOLING_DOWN_OFFSET);
|
|
75397
|
+
const totalActiveBalance = data.readBigUInt64LE(TOTAL_ACTIVE_BALANCE_OFFSET);
|
|
75398
|
+
const availableReserveBalance = data.readBigUInt64LE(AVAILABLE_RESERVE_BALANCE_OFFSET);
|
|
75399
|
+
const msolSupply = data.readBigUInt64LE(MSOL_SUPPLY_OFFSET);
|
|
75400
|
+
const circulatingTicketBalance = data.readBigUInt64LE(CIRCULATING_TICKET_BALANCE_OFFSET);
|
|
75401
|
+
const emergencyCoolingDown = data.readBigUInt64LE(EMERGENCY_COOLING_DOWN_OFFSET);
|
|
75402
|
+
if (msolSupply === 0n) {
|
|
75403
|
+
throw new Error("Marinade State has zero mSOL supply");
|
|
75404
|
+
}
|
|
75405
|
+
const underControl = totalActiveBalance + delayedUnstakeCoolingDown + emergencyCoolingDown + availableReserveBalance;
|
|
75406
|
+
if (underControl > U64_MAX) {
|
|
75407
|
+
throw new Error("Marinade virtual staked balance overflow");
|
|
75408
|
+
}
|
|
75409
|
+
const totalVirtualStakedLamports = underControl > circulatingTicketBalance ? underControl - circulatingTicketBalance : 0n;
|
|
75410
|
+
const msolPrice = new BigNumber3__default.default(totalVirtualStakedLamports.toString()).div(msolSupply.toString());
|
|
75387
75411
|
if (!msolPrice.gt(0) || msolPrice.gte(MAX_MSOL_SOL_RATE)) {
|
|
75388
75412
|
throw new Error(`Marinade mSOL/SOL rate out of bounds: ${msolPrice.toString()}`);
|
|
75389
75413
|
}
|
|
@@ -75402,7 +75426,7 @@ var ACCOUNT_TYPE_STAKE_POOL = 1;
|
|
|
75402
75426
|
var TOTAL_LAMPORTS_OFFSET = 258;
|
|
75403
75427
|
var POOL_TOKEN_SUPPLY_OFFSET = 266;
|
|
75404
75428
|
var LAST_UPDATE_EPOCH_OFFSET = 274;
|
|
75405
|
-
var MAX_LST_SOL_RATE =
|
|
75429
|
+
var MAX_LST_SOL_RATE = 3;
|
|
75406
75430
|
function decodeStakePool(data) {
|
|
75407
75431
|
if (data.length < LAST_UPDATE_EPOCH_OFFSET + 8) {
|
|
75408
75432
|
throw new Error(`Invalid StakePool account size: ${data.length}`);
|
|
@@ -81356,7 +81380,8 @@ async function fetchSingleCrossbarChunk(endpoint, swbFeedIdsChunk, isPrimary) {
|
|
|
81356
81380
|
}
|
|
81357
81381
|
var scopeRequestKey = (bank) => {
|
|
81358
81382
|
const oracleKey = bank.config.oracleKeys[0]?.toBase58();
|
|
81359
|
-
|
|
81383
|
+
const entryIndex = bank.config.scopeEntryIndex;
|
|
81384
|
+
return oracleKey && entryIndex !== void 0 ? `${oracleKey}:${entryIndex}` : void 0;
|
|
81360
81385
|
};
|
|
81361
81386
|
var fetchScopeOracleData = async (banks, opts) => {
|
|
81362
81387
|
const scopeBanks = banks.filter((bank) => getOracleSourceFromBank(bank).key === "scope");
|
|
@@ -81376,8 +81401,12 @@ var fetchScopeOracleData = async (banks, opts) => {
|
|
|
81376
81401
|
const uniqueRequestKeys = Array.from(
|
|
81377
81402
|
new Set(scopeBanks.map(scopeRequestKey).filter((key) => key !== void 0))
|
|
81378
81403
|
);
|
|
81379
|
-
let oraclePrices;
|
|
81380
|
-
if (
|
|
81404
|
+
let oraclePrices = {};
|
|
81405
|
+
if (!uniqueRequestKeys.length) {
|
|
81406
|
+
console.warn(
|
|
81407
|
+
"fetchScopeOracleData: no scope bank carries a scopeEntryIndex; all priced at zero"
|
|
81408
|
+
);
|
|
81409
|
+
} else if (opts.mode === "api") {
|
|
81381
81410
|
oraclePrices = await fetchScopeOraclePricesFromAPI(
|
|
81382
81411
|
uniqueRequestKeys,
|
|
81383
81412
|
opts.scopeOnchainData.endpoint,
|
|
@@ -82040,13 +82069,13 @@ var fetchMultipleBanks = async (program, opts) => {
|
|
|
82040
82069
|
}
|
|
82041
82070
|
return bankDatas;
|
|
82042
82071
|
};
|
|
82043
|
-
var
|
|
82072
|
+
var U64_MAX2 = new BigNumber3__default.default("18446744073709551615");
|
|
82044
82073
|
var DRIFT_SCALED_BALANCE_DECIMALS = 9;
|
|
82045
82074
|
function isDepositLimitActive(bank) {
|
|
82046
|
-
return !bank.config.depositLimit.eq(
|
|
82075
|
+
return !bank.config.depositLimit.eq(U64_MAX2);
|
|
82047
82076
|
}
|
|
82048
82077
|
function isBorrowLimitActive(bank) {
|
|
82049
|
-
return !bank.config.borrowLimit.eq(
|
|
82078
|
+
return !bank.config.borrowLimit.eq(U64_MAX2);
|
|
82050
82079
|
}
|
|
82051
82080
|
function getEffectiveDepositLimit(bank) {
|
|
82052
82081
|
const limit = bank.config.depositLimit;
|
|
@@ -82160,12 +82189,12 @@ function computeRemainingCapacity(bank) {
|
|
|
82160
82189
|
const remainingCapacity = isDepositLimitActive(bank) ? BigNumber3__default.default.max(
|
|
82161
82190
|
0,
|
|
82162
82191
|
getEffectiveDepositLimit(bank).minus(totalDeposits).minus(1).integerValue(BigNumber3__default.default.ROUND_FLOOR)
|
|
82163
|
-
) :
|
|
82192
|
+
) : U64_MAX2;
|
|
82164
82193
|
const totalBorrows = getTotalLiabilityQuantity(bank);
|
|
82165
82194
|
const remainingBorrowCapacity = isBorrowLimitActive(bank) ? BigNumber3__default.default.max(
|
|
82166
82195
|
0,
|
|
82167
82196
|
bank.config.borrowLimit.minus(totalBorrows).minus(1).integerValue(BigNumber3__default.default.ROUND_FLOOR)
|
|
82168
|
-
) :
|
|
82197
|
+
) : U64_MAX2;
|
|
82169
82198
|
const projectionSeconds = computeAccrualProjectionSeconds(bank);
|
|
82170
82199
|
const { lendingRate, borrowingRate } = computeInterestRates(bank);
|
|
82171
82200
|
const projectedLendingInterest = lendingRate.times(projectionSeconds).dividedBy(SECONDS_PER_YEAR).times(totalDeposits);
|
|
@@ -82414,10 +82443,26 @@ async function addOracleToBanksIx({
|
|
|
82414
82443
|
bankAddress,
|
|
82415
82444
|
feedId,
|
|
82416
82445
|
oracleKey,
|
|
82446
|
+
oracleAccounts,
|
|
82417
82447
|
setup,
|
|
82418
82448
|
groupAddress,
|
|
82419
82449
|
adminAddress
|
|
82420
82450
|
}) {
|
|
82451
|
+
if (setup === "Scope" /* Scope */ || setup === "PTPyth" /* PTPyth */ || setup === "PTFixed" /* PTFixed */ || setup === "Fixed" /* Fixed */ || setup === "FixedKamino" /* FixedKamino */ || setup === "FixedDrift" /* FixedDrift */ || setup === "FixedJuplend" /* FixedJuplend */) {
|
|
82452
|
+
throw new Error(
|
|
82453
|
+
`${setup} must be configured with ${setup === "Scope" /* Scope */ ? "configureScopeOracleIx" : "setOraclePriceIx"}`
|
|
82454
|
+
);
|
|
82455
|
+
}
|
|
82456
|
+
const resolvedOracleAccounts = oracleAccounts ?? (oracleKey ? [oracleKey] : []);
|
|
82457
|
+
const expectedAccountCount = setup === "PythMSOL" /* PythMSOL */ || setup === "PythLST" /* PythLST */ ? 2 : setup === "KaminoMSOL" /* KaminoMSOL */ || setup === "JuplendMSOL" /* JuplendMSOL */ || setup === "KaminoLST" /* KaminoLST */ || setup === "JuplendLST" /* JuplendLST */ ? 3 : void 0;
|
|
82458
|
+
if (expectedAccountCount !== void 0 && resolvedOracleAccounts.length !== expectedAccountCount) {
|
|
82459
|
+
throw new Error(`${setup} requires ${expectedAccountCount} ordered oracle accounts`);
|
|
82460
|
+
}
|
|
82461
|
+
if (expectedAccountCount !== void 0 && !resolvedOracleAccounts[0].equals(feedId)) {
|
|
82462
|
+
throw new Error(
|
|
82463
|
+
`${setup} requires oracleAccounts[0] to be the primary feed ${feedId.toBase58()}`
|
|
82464
|
+
);
|
|
82465
|
+
}
|
|
82421
82466
|
const ix = await instructions_default.makeLendingPoolConfigureBankOracleIx(
|
|
82422
82467
|
program,
|
|
82423
82468
|
{
|
|
@@ -82429,7 +82474,42 @@ async function addOracleToBanksIx({
|
|
|
82429
82474
|
setup: serializeOracleSetupToIndex(setup),
|
|
82430
82475
|
feedId
|
|
82431
82476
|
},
|
|
82432
|
-
|
|
82477
|
+
resolvedOracleAccounts.map((pubkey) => ({
|
|
82478
|
+
isSigner: false,
|
|
82479
|
+
isWritable: false,
|
|
82480
|
+
pubkey
|
|
82481
|
+
}))
|
|
82482
|
+
);
|
|
82483
|
+
return {
|
|
82484
|
+
instructions: [ix],
|
|
82485
|
+
keys: []
|
|
82486
|
+
};
|
|
82487
|
+
}
|
|
82488
|
+
async function setOraclePriceIx({
|
|
82489
|
+
program,
|
|
82490
|
+
bankAddress,
|
|
82491
|
+
price,
|
|
82492
|
+
setup,
|
|
82493
|
+
oracleAccounts = [],
|
|
82494
|
+
groupAddress,
|
|
82495
|
+
adminAddress
|
|
82496
|
+
}) {
|
|
82497
|
+
const expectedAccountCount = setup === "PTPyth" /* PTPyth */ ? 2 : setup === "PTFixed" /* PTFixed */ ? 1 : void 0;
|
|
82498
|
+
if (expectedAccountCount !== void 0 && oracleAccounts.length !== expectedAccountCount) {
|
|
82499
|
+
throw new Error(`${setup} requires ${expectedAccountCount} ordered oracle accounts`);
|
|
82500
|
+
}
|
|
82501
|
+
const ix = await instructions_default.makeLendingPoolSetOraclePriceIx(
|
|
82502
|
+
program,
|
|
82503
|
+
{
|
|
82504
|
+
bank: bankAddress,
|
|
82505
|
+
group: groupAddress,
|
|
82506
|
+
admin: adminAddress
|
|
82507
|
+
},
|
|
82508
|
+
{
|
|
82509
|
+
price: bigNumberToWrappedI80F48(price),
|
|
82510
|
+
setup: serializeOracleSetupToIndex(setup)
|
|
82511
|
+
},
|
|
82512
|
+
oracleAccounts.map((pubkey) => ({ isSigner: false, isWritable: false, pubkey }))
|
|
82433
82513
|
);
|
|
82434
82514
|
return {
|
|
82435
82515
|
instructions: [ix],
|
|
@@ -85778,7 +85858,7 @@ exports.TransactionBuildingError = TransactionBuildingError;
|
|
|
85778
85858
|
exports.TransactionBuildingErrorCode = TransactionBuildingErrorCode;
|
|
85779
85859
|
exports.TransactionConfigMap = TransactionConfigMap;
|
|
85780
85860
|
exports.TransactionType = TransactionType;
|
|
85781
|
-
exports.U64_MAX =
|
|
85861
|
+
exports.U64_MAX = U64_MAX2;
|
|
85782
85862
|
exports.USDC_DECIMALS = USDC_DECIMALS;
|
|
85783
85863
|
exports.USDC_MINT = USDC_MINT;
|
|
85784
85864
|
exports.USDT_MINT = USDT_MINT;
|
|
@@ -86142,6 +86222,7 @@ exports.serializeOracleSetupToIndex = serializeOracleSetupToIndex;
|
|
|
86142
86222
|
exports.serializeRiskTier = serializeRiskTier;
|
|
86143
86223
|
exports.serializeSwapEngineRequest = serializeSwapEngineRequest;
|
|
86144
86224
|
exports.serializeSwapEngineResult = serializeSwapEngineResult;
|
|
86225
|
+
exports.setOraclePriceIx = setOraclePriceIx;
|
|
86145
86226
|
exports.sharedBridgeLegContext = sharedBridgeLegContext;
|
|
86146
86227
|
exports.shortenAddress = shortenAddress;
|
|
86147
86228
|
exports.simulateAccountHealthCache = simulateAccountHealthCache;
|