@0dotxyz/p0-ts-sdk 2.9.0-alpha.0 → 2.9.0-alpha.1
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 +61 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -7
- package/dist/index.d.ts +58 -7
- package/dist/index.js +59 -16
- package/dist/index.js.map +1 -1
- package/dist/instructions.d.cts +1 -1
- package/dist/instructions.d.ts +1 -1
- package/dist/{types-CvvHQs7G.d.cts → types-B5hbKbQJ.d.cts} +7 -1
- package/dist/{types-Auh-s318.d.ts → types-C3ArshQA.d.ts} +7 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -539,7 +539,7 @@ function percentToMaxSlippageU32(percent) {
|
|
|
539
539
|
`Max slippage percent must be in (0, ${MAX_ORDER_SLIPPAGE_PERCENT}], got ${percent}`
|
|
540
540
|
);
|
|
541
541
|
}
|
|
542
|
-
return Math.
|
|
542
|
+
return Math.floor(percent / 100 * U32_MAX);
|
|
543
543
|
}
|
|
544
544
|
function maxSlippageU32ToPercent(maxSlippage) {
|
|
545
545
|
return maxSlippage / U32_MAX * 100;
|
|
@@ -22696,6 +22696,10 @@ var AccountFlags = /* @__PURE__ */ ((AccountFlags2) => {
|
|
|
22696
22696
|
AccountFlags2[AccountFlags2["ACCOUNT_IN_FLASHLOAN"] = 2] = "ACCOUNT_IN_FLASHLOAN";
|
|
22697
22697
|
AccountFlags2[AccountFlags2["ACCOUNT_FLAG_DEPRECATED"] = 4] = "ACCOUNT_FLAG_DEPRECATED";
|
|
22698
22698
|
AccountFlags2[AccountFlags2["ACCOUNT_TRANSFER_AUTHORITY_ALLOWED"] = 8] = "ACCOUNT_TRANSFER_AUTHORITY_ALLOWED";
|
|
22699
|
+
AccountFlags2[AccountFlags2["ACCOUNT_IN_RECEIVERSHIP"] = 16] = "ACCOUNT_IN_RECEIVERSHIP";
|
|
22700
|
+
AccountFlags2[AccountFlags2["ACCOUNT_IN_DELEVERAGE"] = 32] = "ACCOUNT_IN_DELEVERAGE";
|
|
22701
|
+
AccountFlags2[AccountFlags2["ACCOUNT_FROZEN"] = 64] = "ACCOUNT_FROZEN";
|
|
22702
|
+
AccountFlags2[AccountFlags2["ACCOUNT_IN_ORDER_EXECUTION"] = 128] = "ACCOUNT_IN_ORDER_EXECUTION";
|
|
22699
22703
|
return AccountFlags2;
|
|
22700
22704
|
})(AccountFlags || {});
|
|
22701
22705
|
var MarginRequirementType = /* @__PURE__ */ ((MarginRequirementType5) => {
|
|
@@ -72253,7 +72257,8 @@ function parseMarginfiAccountRaw(marginfiAccountPk, accountData) {
|
|
|
72253
72257
|
balances,
|
|
72254
72258
|
accountFlags,
|
|
72255
72259
|
emissionsDestinationAccount,
|
|
72256
|
-
healthCache
|
|
72260
|
+
healthCache,
|
|
72261
|
+
activeOrders: accountData.activeOrders
|
|
72257
72262
|
};
|
|
72258
72263
|
}
|
|
72259
72264
|
function getActiveAccountFlags(flags) {
|
|
@@ -72309,7 +72314,8 @@ function dtoToMarginfiAccount(marginfiAccountDto) {
|
|
|
72309
72314
|
balances: marginfiAccountDto.balances.map(dtoToBalance),
|
|
72310
72315
|
accountFlags: marginfiAccountDto.accountFlags,
|
|
72311
72316
|
emissionsDestinationAccount: new web3_js.PublicKey(marginfiAccountDto.emissionsDestinationAccount),
|
|
72312
|
-
healthCache: dtoToHealthCache(marginfiAccountDto.healthCache)
|
|
72317
|
+
healthCache: dtoToHealthCache(marginfiAccountDto.healthCache),
|
|
72318
|
+
activeOrders: marginfiAccountDto.activeOrders ?? 0
|
|
72313
72319
|
};
|
|
72314
72320
|
}
|
|
72315
72321
|
function dtoToBalance(balanceDto) {
|
|
@@ -72348,7 +72354,8 @@ function marginfiAccountToDto(marginfiAccount) {
|
|
|
72348
72354
|
balances: marginfiAccount.balances.map(balanceToDto),
|
|
72349
72355
|
accountFlags: marginfiAccount.accountFlags,
|
|
72350
72356
|
emissionsDestinationAccount: marginfiAccount.emissionsDestinationAccount.toBase58(),
|
|
72351
|
-
healthCache: healthCacheToDto(marginfiAccount.healthCache)
|
|
72357
|
+
healthCache: healthCacheToDto(marginfiAccount.healthCache),
|
|
72358
|
+
activeOrders: marginfiAccount.activeOrders
|
|
72352
72359
|
};
|
|
72353
72360
|
}
|
|
72354
72361
|
function balanceToDto(balance) {
|
|
@@ -72664,6 +72671,23 @@ function getBalanceUsdValueWithPriceBias(params) {
|
|
|
72664
72671
|
});
|
|
72665
72672
|
return { assets: assetsValue, liabilities: liabilitiesValue };
|
|
72666
72673
|
}
|
|
72674
|
+
function computeOrderPairNetValue(params) {
|
|
72675
|
+
const { collateral, debt } = params;
|
|
72676
|
+
const { assets: collateralUsd } = getBalanceUsdValueWithPriceBias({
|
|
72677
|
+
balance: collateral.balance,
|
|
72678
|
+
bank: collateral.bank,
|
|
72679
|
+
oraclePrice: collateral.oraclePrice,
|
|
72680
|
+
marginRequirement: 2 /* Equity */,
|
|
72681
|
+
assetShareValueMultiplier: collateral.assetShareValueMultiplier
|
|
72682
|
+
});
|
|
72683
|
+
const { liabilities: debtUsd } = getBalanceUsdValueWithPriceBias({
|
|
72684
|
+
balance: debt.balance,
|
|
72685
|
+
bank: debt.bank,
|
|
72686
|
+
oraclePrice: debt.oraclePrice,
|
|
72687
|
+
marginRequirement: 2 /* Equity */
|
|
72688
|
+
});
|
|
72689
|
+
return { collateralUsd, debtUsd, netUsd: collateralUsd.minus(debtUsd) };
|
|
72690
|
+
}
|
|
72667
72691
|
function computeQuantity(balance, bank) {
|
|
72668
72692
|
const assetsQuantity = getAssetQuantity(bank, balance.assetShares);
|
|
72669
72693
|
const liabilitiesQuantity = getLiabilityQuantity(bank, balance.liabilityShares);
|
|
@@ -73467,18 +73491,31 @@ var fetchOrdersForAccount = async (program, marginfiAccount) => {
|
|
|
73467
73491
|
]);
|
|
73468
73492
|
return orders.map(({ publicKey: publicKey5, account }) => parseOrderRaw(publicKey5, account));
|
|
73469
73493
|
};
|
|
73470
|
-
var
|
|
73494
|
+
var resolveOrderLegs = (marginfiAccount, order) => {
|
|
73471
73495
|
const taggedBalances = marginfiAccount.balances.filter(
|
|
73472
|
-
(balance) => balance.tag !== 0 && order.tags.includes(balance.tag)
|
|
73496
|
+
(balance) => balance.active && balance.tag !== 0 && order.tags.includes(balance.tag)
|
|
73473
73497
|
);
|
|
73474
|
-
|
|
73475
|
-
|
|
73476
|
-
|
|
73498
|
+
return {
|
|
73499
|
+
collateralBank: taggedBalances.find((balance) => balance.assetShares.gt(0))?.bankPk ?? null,
|
|
73500
|
+
debtBank: taggedBalances.find((balance) => balance.liabilityShares.gt(0))?.bankPk ?? null
|
|
73501
|
+
};
|
|
73502
|
+
};
|
|
73503
|
+
var resolveOrderBanks = (marginfiAccount, order) => {
|
|
73504
|
+
const { collateralBank, debtBank } = resolveOrderLegs(marginfiAccount, order);
|
|
73505
|
+
if (!collateralBank || !debtBank) {
|
|
73477
73506
|
throw new Error(
|
|
73478
73507
|
`Could not resolve banks for order ${order.address.toBase58()}: tagged balances are missing or closed`
|
|
73479
73508
|
);
|
|
73480
73509
|
}
|
|
73481
|
-
return { collateralBank
|
|
73510
|
+
return { collateralBank, debtBank };
|
|
73511
|
+
};
|
|
73512
|
+
var fetchOrderFees = async (program) => {
|
|
73513
|
+
const [feeStateAddress] = deriveFeeState(program.programId);
|
|
73514
|
+
const feeState = await program.account.feeState.fetch(feeStateAddress);
|
|
73515
|
+
return {
|
|
73516
|
+
placementFeeLamports: feeState.orderInitFlatSolFee,
|
|
73517
|
+
executionMaxFee: wrappedI80F48toBigNumber(feeState.orderExecutionMaxFee)
|
|
73518
|
+
};
|
|
73482
73519
|
};
|
|
73483
73520
|
function randomDistinctIndices(count, maxExclusive) {
|
|
73484
73521
|
const chosen = /* @__PURE__ */ new Set();
|
|
@@ -78235,7 +78272,9 @@ function generateDummyAccount(group, authority, accountKey) {
|
|
|
78235
78272
|
mrgnErr: 0
|
|
78236
78273
|
},
|
|
78237
78274
|
emissionsDestinationAccount: new web3_js.PublicKey("11111111111111111111111111111111"),
|
|
78238
|
-
accountFlags: new BN8__default.default([0, 0, 0])
|
|
78275
|
+
accountFlags: new BN8__default.default([0, 0, 0]),
|
|
78276
|
+
activeOrders: 0
|
|
78277
|
+
};
|
|
78239
78278
|
return parseMarginfiAccountRaw(accountKey, rawAccount);
|
|
78240
78279
|
}
|
|
78241
78280
|
|
|
@@ -78346,7 +78385,7 @@ var HealthCache = class _HealthCache {
|
|
|
78346
78385
|
|
|
78347
78386
|
// src/models/account.ts
|
|
78348
78387
|
var MarginfiAccount = class _MarginfiAccount {
|
|
78349
|
-
constructor(address, group, authority, balances, accountFlags, emissionsDestinationAccount, healthCache) {
|
|
78388
|
+
constructor(address, group, authority, balances, accountFlags, emissionsDestinationAccount, healthCache, activeOrders = 0) {
|
|
78350
78389
|
this.address = address;
|
|
78351
78390
|
this.group = group;
|
|
78352
78391
|
this.authority = authority;
|
|
@@ -78354,6 +78393,7 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
78354
78393
|
this.accountFlags = accountFlags;
|
|
78355
78394
|
this.emissionsDestinationAccount = emissionsDestinationAccount;
|
|
78356
78395
|
this.healthCache = healthCache;
|
|
78396
|
+
this.activeOrders = activeOrders;
|
|
78357
78397
|
}
|
|
78358
78398
|
/**
|
|
78359
78399
|
* Fetches a marginfi account from on-chain data.
|
|
@@ -78378,7 +78418,8 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
78378
78418
|
account.balances.map((b) => Balance.fromBalanceType(b)),
|
|
78379
78419
|
account.accountFlags,
|
|
78380
78420
|
account.emissionsDestinationAccount,
|
|
78381
|
-
account.healthCache
|
|
78421
|
+
account.healthCache,
|
|
78422
|
+
account.activeOrders
|
|
78382
78423
|
);
|
|
78383
78424
|
}
|
|
78384
78425
|
/**
|
|
@@ -78398,7 +78439,8 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
78398
78439
|
props.balances.map((b) => Balance.fromBalanceType(b)),
|
|
78399
78440
|
props.accountFlags,
|
|
78400
78441
|
props.emissionsDestinationAccount,
|
|
78401
|
-
HealthCache.fromHealthCacheType(props.healthCache)
|
|
78442
|
+
HealthCache.fromHealthCacheType(props.healthCache),
|
|
78443
|
+
props.activeOrders
|
|
78402
78444
|
);
|
|
78403
78445
|
}
|
|
78404
78446
|
/**
|
|
@@ -79426,7 +79468,8 @@ function projectAccountAfterFirstLeg(account, firstLegFlashloanTxs, program, ban
|
|
|
79426
79468
|
projectedBalances.map((b) => Balance.fromBalanceType(b)),
|
|
79427
79469
|
account.accountFlags,
|
|
79428
79470
|
account.emissionsDestinationAccount,
|
|
79429
|
-
account.healthCache
|
|
79471
|
+
account.healthCache,
|
|
79472
|
+
account.activeOrders
|
|
79430
79473
|
);
|
|
79431
79474
|
}
|
|
79432
79475
|
function composeBundle(firstLegTxs, secondLegTxs, payer, blockhash, maxBundleTxs) {
|
|
@@ -85682,6 +85725,7 @@ exports.computeMaxWithdrawForBank = computeMaxWithdrawForBank;
|
|
|
85682
85725
|
exports.computeNetApy = computeNetApy;
|
|
85683
85726
|
exports.computeOracleMultiplier = computeOracleMultiplier;
|
|
85684
85727
|
exports.computeOracleMultipliers = computeOracleMultipliers;
|
|
85728
|
+
exports.computeOrderPairNetValue = computeOrderPairNetValue;
|
|
85685
85729
|
exports.computeProjectedActiveBalancesNoCpi = computeProjectedActiveBalancesNoCpi;
|
|
85686
85730
|
exports.computeProjectedActiveBanksNoCpi = computeProjectedActiveBanksNoCpi;
|
|
85687
85731
|
exports.computePtMultiplier = computePtMultiplier;
|
|
@@ -85757,6 +85801,7 @@ exports.fetchOracleMultipliers = fetchOracleMultipliers;
|
|
|
85757
85801
|
exports.fetchOracleMultipliersFromAPI = fetchOracleMultipliersFromAPI;
|
|
85758
85802
|
exports.fetchOracleMultipliersFromChain = fetchOracleMultipliersFromChain;
|
|
85759
85803
|
exports.fetchOrder = fetchOrder;
|
|
85804
|
+
exports.fetchOrderFees = fetchOrderFees;
|
|
85760
85805
|
exports.fetchOrdersForAccount = fetchOrdersForAccount;
|
|
85761
85806
|
exports.fetchProgramForMints = fetchProgramForMints;
|
|
85762
85807
|
exports.fetchPythOracleData = fetchPythOracleData;
|
|
@@ -85947,6 +85992,7 @@ exports.requireTokenProgram = requireTokenProgram;
|
|
|
85947
85992
|
exports.resolveAmount = resolveAmount;
|
|
85948
85993
|
exports.resolveBridgeCandidateBanks = resolveBridgeCandidateBanks;
|
|
85949
85994
|
exports.resolveOrderBanks = resolveOrderBanks;
|
|
85995
|
+
exports.resolveOrderLegs = resolveOrderLegs;
|
|
85950
85996
|
exports.resolvePinnedSwapRoute = resolvePinnedSwapRoute;
|
|
85951
85997
|
exports.resolveTokenProgramForMint = resolveTokenProgramForMint;
|
|
85952
85998
|
exports.resolveVaultTokenProgram = resolveVaultTokenProgram;
|