@0dotxyz/p0-ts-sdk 2.3.2 → 2.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +87 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +83 -4
- package/dist/index.d.ts +83 -4
- package/dist/index.js +81 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -231,6 +231,15 @@ var TransactionBuildingError = class _TransactionBuildingError extends Error {
|
|
|
231
231
|
return new _TransactionBuildingError(code, message, details);
|
|
232
232
|
}
|
|
233
233
|
};
|
|
234
|
+
var DECOMPOSABLE_SWAP_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
235
|
+
"SWAP_SIZE_EXCEEDED_LOOP" /* SWAP_SIZE_EXCEEDED_LOOP */,
|
|
236
|
+
"SWAP_SIZE_EXCEEDED_REPAY" /* SWAP_SIZE_EXCEEDED_REPAY */,
|
|
237
|
+
"SWAP_SIZE_EXCEEDED_POSITION_SWAP" /* SWAP_SIZE_EXCEEDED_POSITION_SWAP */,
|
|
238
|
+
"SWAP_QUOTE_FAILED" /* SWAP_QUOTE_FAILED */
|
|
239
|
+
]);
|
|
240
|
+
function isDecomposableSwapError(e) {
|
|
241
|
+
return e instanceof TransactionBuildingError && DECOMPOSABLE_SWAP_ERROR_CODES.has(e.code);
|
|
242
|
+
}
|
|
234
243
|
var PDA_BANK_LIQUIDITY_VAULT_AUTH_SEED = Buffer.from("liquidity_vault_auth");
|
|
235
244
|
var PDA_BANK_INSURANCE_VAULT_AUTH_SEED = Buffer.from("insurance_vault_auth");
|
|
236
245
|
var PDA_BANK_FEE_VAULT_AUTH_SEED = Buffer.from("fee_vault_auth");
|
|
@@ -62187,6 +62196,7 @@ async function buildRepayWithCollatFlashloanTx({
|
|
|
62187
62196
|
// src/services/account/utils/flashloan-size.utils.ts
|
|
62188
62197
|
var SWAP_MERGE_OVERHEAD = 150;
|
|
62189
62198
|
var FL_IX_OVERHEAD = 52;
|
|
62199
|
+
var OVERSIZED_TX_SENTINEL = MAX_TX_SIZE * 4;
|
|
62190
62200
|
function compactU16Size(n) {
|
|
62191
62201
|
return n < 128 ? 1 : n < 16384 ? 2 : 3;
|
|
62192
62202
|
}
|
|
@@ -62343,7 +62353,13 @@ function compileFlashloanPrecheck({
|
|
|
62343
62353
|
recentBlockhash: web3_js.PublicKey.default.toBase58(),
|
|
62344
62354
|
instructions: allIxs
|
|
62345
62355
|
}).compileToV0Message(luts);
|
|
62346
|
-
|
|
62356
|
+
let rawSize;
|
|
62357
|
+
try {
|
|
62358
|
+
rawSize = new web3_js.VersionedTransaction(msg).serialize().length;
|
|
62359
|
+
} catch (e) {
|
|
62360
|
+
if (!(e instanceof RangeError)) throw e;
|
|
62361
|
+
rawSize = OVERSIZED_TX_SENTINEL;
|
|
62362
|
+
}
|
|
62347
62363
|
const fullTxSize = rawSize + FL_IX_OVERHEAD;
|
|
62348
62364
|
const overshoot = fullTxSize - MAX_TX_SIZE;
|
|
62349
62365
|
const { header, staticAccountKeys, addressTableLookups } = msg;
|
|
@@ -65343,7 +65359,7 @@ function composeBundle(firstLegTxs, secondLegTxs, payer, blockhash, maxBundleTxs
|
|
|
65343
65359
|
if (result.length > maxBundleTxs) return null;
|
|
65344
65360
|
return result;
|
|
65345
65361
|
}
|
|
65346
|
-
function
|
|
65362
|
+
function compoundQuoteRisk(firstLeg, secondLeg) {
|
|
65347
65363
|
const compound = (a, b) => {
|
|
65348
65364
|
if (a == null && b == null) return void 0;
|
|
65349
65365
|
const x = Number(a ?? 0);
|
|
@@ -65351,13 +65367,36 @@ function mergeBridgeQuotes(firstLeg, secondLeg) {
|
|
|
65351
65367
|
return String(1 - (1 - x) * (1 - y));
|
|
65352
65368
|
};
|
|
65353
65369
|
return {
|
|
65354
|
-
inAmount: firstLeg.inAmount,
|
|
65355
|
-
outAmount: secondLeg.outAmount,
|
|
65356
|
-
otherAmountThreshold: secondLeg.otherAmountThreshold,
|
|
65357
65370
|
slippageBps: Math.round(
|
|
65358
65371
|
(1 - (1 - firstLeg.slippageBps / 1e4) * (1 - secondLeg.slippageBps / 1e4)) * 1e4
|
|
65359
65372
|
),
|
|
65360
|
-
priceImpactPct: compound(firstLeg.priceImpactPct, secondLeg.priceImpactPct)
|
|
65373
|
+
priceImpactPct: compound(firstLeg.priceImpactPct, secondLeg.priceImpactPct)
|
|
65374
|
+
};
|
|
65375
|
+
}
|
|
65376
|
+
function mergeBridgeQuotes(firstLeg, secondLeg) {
|
|
65377
|
+
return {
|
|
65378
|
+
inAmount: firstLeg.inAmount,
|
|
65379
|
+
outAmount: secondLeg.outAmount,
|
|
65380
|
+
otherAmountThreshold: secondLeg.otherAmountThreshold,
|
|
65381
|
+
...compoundQuoteRisk(firstLeg, secondLeg),
|
|
65382
|
+
provider: firstLeg.provider
|
|
65383
|
+
};
|
|
65384
|
+
}
|
|
65385
|
+
function mergeBridgeQuotesDebt(firstLeg, secondLeg) {
|
|
65386
|
+
return {
|
|
65387
|
+
inAmount: firstLeg.outAmount,
|
|
65388
|
+
outAmount: secondLeg.inAmount,
|
|
65389
|
+
otherAmountThreshold: secondLeg.inAmount,
|
|
65390
|
+
...compoundQuoteRisk(firstLeg, secondLeg),
|
|
65391
|
+
provider: firstLeg.provider
|
|
65392
|
+
};
|
|
65393
|
+
}
|
|
65394
|
+
function mergeBridgeQuotesLoop(firstLeg, secondLeg) {
|
|
65395
|
+
return {
|
|
65396
|
+
inAmount: secondLeg.inAmount,
|
|
65397
|
+
outAmount: firstLeg.outAmount,
|
|
65398
|
+
otherAmountThreshold: firstLeg.otherAmountThreshold,
|
|
65399
|
+
...compoundQuoteRisk(firstLeg, secondLeg),
|
|
65361
65400
|
provider: firstLeg.provider
|
|
65362
65401
|
};
|
|
65363
65402
|
}
|
|
@@ -66146,6 +66185,33 @@ function patchDepositAmount(ix, amountNative) {
|
|
|
66146
66185
|
amountNative.toArrayLike(Buffer, "le", 8).copy(ix.data, DEPOSIT_AMOUNT_OFFSET);
|
|
66147
66186
|
}
|
|
66148
66187
|
|
|
66188
|
+
// src/services/account/utils/bridge.utils.ts
|
|
66189
|
+
function accountConflictsWithBridge(account, bankPk, side) {
|
|
66190
|
+
const balance = account.balances.find((b) => b.active && b.bankPk.equals(bankPk));
|
|
66191
|
+
if (!balance) return false;
|
|
66192
|
+
return side === "deposit" ? balance.liabilityShares.gt(0) : balance.assetShares.gt(0);
|
|
66193
|
+
}
|
|
66194
|
+
function resolveBridgeBanks(params) {
|
|
66195
|
+
const { orderedBridgeMints, banks, marginfiAccount, side } = params;
|
|
66196
|
+
const passesSideFilter = side === "borrow" ? isStandardBorrowable : isStandardDepositable;
|
|
66197
|
+
const bridges = [];
|
|
66198
|
+
const conflicts = [];
|
|
66199
|
+
const seenMints = /* @__PURE__ */ new Set();
|
|
66200
|
+
for (const mint of orderedBridgeMints) {
|
|
66201
|
+
const mintKey = mint.toBase58();
|
|
66202
|
+
if (seenMints.has(mintKey)) continue;
|
|
66203
|
+
seenMints.add(mintKey);
|
|
66204
|
+
const bank = banks.find((b) => b.mint.equals(mint) && passesSideFilter(b));
|
|
66205
|
+
if (!bank) continue;
|
|
66206
|
+
if (accountConflictsWithBridge(marginfiAccount, bank.address, side)) {
|
|
66207
|
+
conflicts.push(bank);
|
|
66208
|
+
} else {
|
|
66209
|
+
bridges.push(bank);
|
|
66210
|
+
}
|
|
66211
|
+
}
|
|
66212
|
+
return { bridges, conflicts };
|
|
66213
|
+
}
|
|
66214
|
+
|
|
66149
66215
|
// src/services/price/utils/smart-crank.utils.ts
|
|
66150
66216
|
async function computeSmartCrank({
|
|
66151
66217
|
marginfiAccount,
|
|
@@ -67646,6 +67712,14 @@ function computeRemainingCapacity(bank) {
|
|
|
67646
67712
|
}
|
|
67647
67713
|
|
|
67648
67714
|
// src/services/bank/utils/bank-metrics.utils.ts
|
|
67715
|
+
function isStandardBorrowable(bank) {
|
|
67716
|
+
const { assetTag, operationalState, borrowLimit } = bank.config;
|
|
67717
|
+
return (assetTag === 0 /* DEFAULT */ || assetTag === 1 /* SOL */) && operationalState === "Operational" /* Operational */ && borrowLimit.gt(0);
|
|
67718
|
+
}
|
|
67719
|
+
function isStandardDepositable(bank) {
|
|
67720
|
+
const { assetTag, operationalState } = bank.config;
|
|
67721
|
+
return (assetTag === 0 /* DEFAULT */ || assetTag === 1 /* SOL */) && operationalState === "Operational" /* Operational */;
|
|
67722
|
+
}
|
|
67649
67723
|
function computeBankTotalDeposits(bank, assetShareValueMultiplier) {
|
|
67650
67724
|
const totalAssets = getTotalAssetQuantity(bank).times(
|
|
67651
67725
|
assetShareValueMultiplier ?? 1
|
|
@@ -70676,6 +70750,7 @@ exports.USDC_DECIMALS = USDC_DECIMALS;
|
|
|
70676
70750
|
exports.USDC_MINT = USDC_MINT;
|
|
70677
70751
|
exports.WSOL_MINT = WSOL_MINT;
|
|
70678
70752
|
exports.ZERO_ORACLE_KEY = ZERO_ORACLE_KEY;
|
|
70753
|
+
exports.accountConflictsWithBridge = accountConflictsWithBridge;
|
|
70679
70754
|
exports.accountFlagToBN = accountFlagToBN;
|
|
70680
70755
|
exports.addOracleToBanksIx = addOracleToBanksIx;
|
|
70681
70756
|
exports.addTransactionMetadata = addTransactionMetadata;
|
|
@@ -70876,8 +70951,11 @@ exports.hasEmodeEntryFlag = hasEmodeEntryFlag;
|
|
|
70876
70951
|
exports.hasEmodeFlag = hasEmodeFlag;
|
|
70877
70952
|
exports.hasHealthCacheFlag = hasHealthCacheFlag;
|
|
70878
70953
|
exports.healthCacheToDto = healthCacheToDto;
|
|
70954
|
+
exports.isDecomposableSwapError = isDecomposableSwapError;
|
|
70879
70955
|
exports.isDepositIx = isDepositIx;
|
|
70880
70956
|
exports.isFlashloan = isFlashloan;
|
|
70957
|
+
exports.isStandardBorrowable = isStandardBorrowable;
|
|
70958
|
+
exports.isStandardDepositable = isStandardDepositable;
|
|
70881
70959
|
exports.isV0Tx = isV0Tx;
|
|
70882
70960
|
exports.isWeightedPrice = isWeightedPrice;
|
|
70883
70961
|
exports.isWholePosition = isWholePosition;
|
|
@@ -70946,6 +71024,8 @@ exports.mapPythBanksToOraclePrices = mapPythBanksToOraclePrices;
|
|
|
70946
71024
|
exports.mapSwbBanksToOraclePrices = mapSwbBanksToOraclePrices;
|
|
70947
71025
|
exports.marginfiAccountToDto = marginfiAccountToDto;
|
|
70948
71026
|
exports.mergeBridgeQuotes = mergeBridgeQuotes;
|
|
71027
|
+
exports.mergeBridgeQuotesDebt = mergeBridgeQuotesDebt;
|
|
71028
|
+
exports.mergeBridgeQuotesLoop = mergeBridgeQuotesLoop;
|
|
70949
71029
|
exports.nativeToUi = nativeToUi;
|
|
70950
71030
|
exports.oraclePriceToDto = oraclePriceToDto;
|
|
70951
71031
|
exports.parseBalanceRaw = parseBalanceRaw;
|
|
@@ -70965,6 +71045,7 @@ exports.parseSwbOraclePriceData = parseSwbOraclePriceData;
|
|
|
70965
71045
|
exports.partitionBanksByCrankability = partitionBanksByCrankability;
|
|
70966
71046
|
exports.patchDepositAmount = patchDepositAmount;
|
|
70967
71047
|
exports.resolveAmount = resolveAmount;
|
|
71048
|
+
exports.resolveBridgeBanks = resolveBridgeBanks;
|
|
70968
71049
|
exports.runSwapEngine = runSwapEngine;
|
|
70969
71050
|
exports.selectLutsForAccountAction = selectLutsForAccountAction;
|
|
70970
71051
|
exports.selectLutsForBanks = selectLutsForBanks;
|