@0dotxyz/p0-ts-sdk 2.2.3-alpha.1 → 2.2.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 +71 -148
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -37
- package/dist/index.d.ts +3 -37
- package/dist/index.js +72 -148
- package/dist/index.js.map +1 -1
- package/dist/instructions.cjs +2 -10
- package/dist/instructions.cjs.map +1 -1
- package/dist/instructions.d.cts +0 -1
- package/dist/instructions.d.ts +0 -1
- package/dist/instructions.js +2 -10
- package/dist/instructions.js.map +1 -1
- package/dist/vendor.cjs +2834 -0
- package/dist/vendor.cjs.map +1 -1
- package/dist/vendor.d.cts +2835 -1
- package/dist/vendor.d.ts +2835 -1
- package/dist/vendor.js +2834 -1
- package/dist/vendor.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -15629,20 +15629,12 @@ function makeEndFlashLoanIx(mfiProgram, accounts, remainingAccounts = []) {
|
|
|
15629
15629
|
}).accountsPartial(optionalAccounts).remainingAccounts(remainingAccounts).instruction();
|
|
15630
15630
|
}
|
|
15631
15631
|
async function makeAccountTransferToNewAccountIx(mfProgram, accounts) {
|
|
15632
|
-
const {
|
|
15633
|
-
oldMarginfiAccount,
|
|
15634
|
-
newMarginfiAccount,
|
|
15635
|
-
newAuthority,
|
|
15636
|
-
globalFeeWallet,
|
|
15637
|
-
feePayer,
|
|
15638
|
-
...optionalAccounts
|
|
15639
|
-
} = accounts;
|
|
15632
|
+
const { oldMarginfiAccount, newMarginfiAccount, newAuthority, feePayer, ...optionalAccounts } = accounts;
|
|
15640
15633
|
return mfProgram.methods.transferToNewAccount().accounts({
|
|
15641
15634
|
oldMarginfiAccount,
|
|
15642
15635
|
newMarginfiAccount,
|
|
15643
15636
|
newAuthority,
|
|
15644
|
-
globalFeeWallet
|
|
15645
|
-
feePayer
|
|
15637
|
+
globalFeeWallet: feePayer
|
|
15646
15638
|
}).accountsPartial(optionalAccounts).instruction();
|
|
15647
15639
|
}
|
|
15648
15640
|
async function makeGroupInitIx(mfProgram, accounts) {
|
|
@@ -20536,77 +20528,16 @@ function createActiveEmodePairFromPairs(pairs) {
|
|
|
20536
20528
|
assetWeightInit: bestPair.assetWeightInit
|
|
20537
20529
|
};
|
|
20538
20530
|
}
|
|
20539
|
-
function indexConfiguredPairs(emodePairs) {
|
|
20540
|
-
const configured = [];
|
|
20541
|
-
const liabTagByBank = /* @__PURE__ */ new Map();
|
|
20542
|
-
for (const p of emodePairs) {
|
|
20543
|
-
if (p.collateralBankTag === 0 /* UNSET */ || p.liabilityBankTag === 0 /* UNSET */) {
|
|
20544
|
-
continue;
|
|
20545
|
-
}
|
|
20546
|
-
const liabStr = p.liabilityBank.toBase58();
|
|
20547
|
-
const liabTagStr = p.liabilityBankTag.toString();
|
|
20548
|
-
configured.push({
|
|
20549
|
-
orig: p,
|
|
20550
|
-
liabStr,
|
|
20551
|
-
liabTagStr,
|
|
20552
|
-
collTagStr: p.collateralBankTag.toString(),
|
|
20553
|
-
collStrs: p.collateralBanks.map((b) => b.toBase58())
|
|
20554
|
-
});
|
|
20555
|
-
liabTagByBank.set(liabStr, liabTagStr);
|
|
20556
|
-
}
|
|
20557
|
-
return { configured, liabTagByBank };
|
|
20558
|
-
}
|
|
20559
|
-
function activePairsFromIndex(configured, liabTagByBank, liabSet, collSet) {
|
|
20560
|
-
const requiredTags = /* @__PURE__ */ new Set();
|
|
20561
|
-
for (const liab of liabSet) {
|
|
20562
|
-
const tag = liabTagByBank.get(liab);
|
|
20563
|
-
if (!tag) return [];
|
|
20564
|
-
requiredTags.add(tag);
|
|
20565
|
-
}
|
|
20566
|
-
const possible = configured.filter(
|
|
20567
|
-
(p) => liabSet.has(p.liabStr) && p.collStrs.some((c) => collSet.has(c))
|
|
20568
|
-
);
|
|
20569
|
-
if (possible.length === 0) return [];
|
|
20570
|
-
const byCollTag = {};
|
|
20571
|
-
for (const p of possible) {
|
|
20572
|
-
(byCollTag[p.collTagStr] ||= []).push(p);
|
|
20573
|
-
}
|
|
20574
|
-
const validGroups = [];
|
|
20575
|
-
for (const group of Object.values(byCollTag)) {
|
|
20576
|
-
const supports = new Set(group.map((p) => p.liabTagStr));
|
|
20577
|
-
let coversAll = true;
|
|
20578
|
-
for (const rt of requiredTags) {
|
|
20579
|
-
if (!supports.has(rt)) {
|
|
20580
|
-
coversAll = false;
|
|
20581
|
-
break;
|
|
20582
|
-
}
|
|
20583
|
-
}
|
|
20584
|
-
if (coversAll) validGroups.push(group);
|
|
20585
|
-
}
|
|
20586
|
-
if (validGroups.length === 0) return [];
|
|
20587
|
-
return validGroups.flat().map((p) => p.orig);
|
|
20588
|
-
}
|
|
20589
20531
|
function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, allBanks) {
|
|
20590
|
-
const
|
|
20591
|
-
const
|
|
20592
|
-
const
|
|
20593
|
-
const
|
|
20594
|
-
for (const p of emodePairs) {
|
|
20595
|
-
liabTagMapAll.set(p.liabilityBank.toBase58(), p.liabilityBankTag.toString());
|
|
20596
|
-
}
|
|
20597
|
-
const allCollateralBankStrs = /* @__PURE__ */ new Set();
|
|
20532
|
+
const toKey = (k) => k.toBase58();
|
|
20533
|
+
const basePairs = computeActiveEmodePairs(emodePairs, activeLiabilities, activeCollateral);
|
|
20534
|
+
const baseOn = basePairs.length > 0;
|
|
20535
|
+
const liabTagMap = /* @__PURE__ */ new Map();
|
|
20598
20536
|
for (const p of emodePairs) {
|
|
20599
|
-
|
|
20537
|
+
liabTagMap.set(p.liabilityBank.toBase58(), p.liabilityBankTag.toString());
|
|
20600
20538
|
}
|
|
20601
|
-
const basePairs = activePairsFromIndex(
|
|
20602
|
-
configured,
|
|
20603
|
-
liabTagByBank,
|
|
20604
|
-
activeLiabilitiesSet,
|
|
20605
|
-
activeCollateralSet
|
|
20606
|
-
);
|
|
20607
|
-
const baseOn = basePairs.length > 0;
|
|
20608
20539
|
const existingTags = new Set(
|
|
20609
|
-
|
|
20540
|
+
activeLiabilities.map((l) => liabTagMap.get(l.toBase58())).filter((t) => !!t)
|
|
20610
20541
|
);
|
|
20611
20542
|
function minWeight(ps) {
|
|
20612
20543
|
let m = ps[0].assetWeightInit;
|
|
@@ -20623,26 +20554,27 @@ function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, al
|
|
|
20623
20554
|
if (aMin.lt(bMin)) return 3 /* ReduceEmode */;
|
|
20624
20555
|
return 1 /* ExtendEmode */;
|
|
20625
20556
|
}
|
|
20626
|
-
function simulate(
|
|
20627
|
-
|
|
20557
|
+
function simulate(bank, action) {
|
|
20558
|
+
bank.equals(new web3_js.PublicKey("CCKtUs6Cgwo4aaQUmBPmyoApH2gUDErxNZCAntD6LYGh"));
|
|
20559
|
+
let L = [...activeLiabilities], C = [...activeCollateral];
|
|
20628
20560
|
switch (action) {
|
|
20629
20561
|
case "borrow":
|
|
20630
|
-
L.
|
|
20562
|
+
if (!L.some((x) => x.equals(bank))) L.push(bank);
|
|
20631
20563
|
break;
|
|
20632
20564
|
case "repay":
|
|
20633
|
-
L.
|
|
20565
|
+
L = L.filter((x) => !x.equals(bank));
|
|
20634
20566
|
break;
|
|
20635
20567
|
case "supply":
|
|
20636
|
-
C.
|
|
20568
|
+
if (!C.some((x) => x.equals(bank))) C.push(bank);
|
|
20637
20569
|
break;
|
|
20638
20570
|
case "withdraw":
|
|
20639
|
-
C.
|
|
20571
|
+
C = C.filter((x) => !x.equals(bank));
|
|
20640
20572
|
break;
|
|
20641
20573
|
}
|
|
20642
|
-
const after =
|
|
20574
|
+
const after = computeActiveEmodePairs(emodePairs, L, C);
|
|
20643
20575
|
let status = diffState(basePairs, after);
|
|
20644
20576
|
if (action === "borrow") {
|
|
20645
|
-
const tag =
|
|
20577
|
+
const tag = liabTagMap.get(bank.toBase58());
|
|
20646
20578
|
if (!tag) {
|
|
20647
20579
|
status = baseOn ? 4 /* RemoveEmode */ : 5 /* InactiveEmode */;
|
|
20648
20580
|
} else if (baseOn) {
|
|
@@ -20678,29 +20610,66 @@ function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, al
|
|
|
20678
20610
|
}
|
|
20679
20611
|
const result = {};
|
|
20680
20612
|
for (const bank of allBanks) {
|
|
20681
|
-
const key = bank
|
|
20613
|
+
const key = toKey(bank);
|
|
20682
20614
|
const impact = {};
|
|
20683
|
-
if (!
|
|
20684
|
-
impact.borrowImpact = simulate(
|
|
20615
|
+
if (!activeCollateral.some((x) => x.equals(bank))) {
|
|
20616
|
+
impact.borrowImpact = simulate(bank, "borrow");
|
|
20685
20617
|
}
|
|
20686
|
-
|
|
20687
|
-
|
|
20618
|
+
const collSet = new Set(emodePairs.flatMap((p) => p.collateralBanks.map((c) => c.toBase58())));
|
|
20619
|
+
if (collSet.has(key) && !activeCollateral.some((x) => x.equals(bank)) && !activeLiabilities.some((x) => x.equals(bank))) {
|
|
20620
|
+
impact.supplyImpact = simulate(bank, "supply");
|
|
20688
20621
|
}
|
|
20689
|
-
if (
|
|
20690
|
-
impact.repayAllImpact = simulate(
|
|
20622
|
+
if (activeLiabilities.some((x) => x.equals(bank))) {
|
|
20623
|
+
impact.repayAllImpact = simulate(bank, "repay");
|
|
20691
20624
|
}
|
|
20692
|
-
if (
|
|
20693
|
-
impact.withdrawAllImpact = simulate(
|
|
20625
|
+
if (activeCollateral.some((x) => x.equals(bank))) {
|
|
20626
|
+
impact.withdrawAllImpact = simulate(bank, "withdraw");
|
|
20694
20627
|
}
|
|
20695
20628
|
result[key] = impact;
|
|
20696
20629
|
}
|
|
20697
20630
|
return result;
|
|
20698
20631
|
}
|
|
20699
20632
|
function computeActiveEmodePairs(emodePairs, activeLiabilities, activeCollateral) {
|
|
20700
|
-
const
|
|
20701
|
-
|
|
20702
|
-
|
|
20703
|
-
|
|
20633
|
+
const configured = emodePairs.filter(
|
|
20634
|
+
(p) => p.collateralBankTag !== 0 /* UNSET */ && p.liabilityBankTag !== 0 /* UNSET */
|
|
20635
|
+
);
|
|
20636
|
+
const liabTagByBank = /* @__PURE__ */ new Map();
|
|
20637
|
+
for (const p of configured) {
|
|
20638
|
+
liabTagByBank.set(p.liabilityBank.toBase58(), p.liabilityBankTag.toString());
|
|
20639
|
+
}
|
|
20640
|
+
const requiredTags = /* @__PURE__ */ new Set();
|
|
20641
|
+
for (const liab of activeLiabilities) {
|
|
20642
|
+
const tag = liabTagByBank.get(liab.toBase58());
|
|
20643
|
+
if (!tag) {
|
|
20644
|
+
return [];
|
|
20645
|
+
}
|
|
20646
|
+
requiredTags.add(tag);
|
|
20647
|
+
}
|
|
20648
|
+
const possible = configured.filter(
|
|
20649
|
+
(p) => activeLiabilities.some((l) => l.equals(p.liabilityBank)) && p.collateralBanks.some((c) => activeCollateral.some((a) => a.equals(c)))
|
|
20650
|
+
);
|
|
20651
|
+
if (possible.length === 0) return [];
|
|
20652
|
+
const byCollTag = {};
|
|
20653
|
+
for (const p of possible) {
|
|
20654
|
+
const ct = p.collateralBankTag.toString();
|
|
20655
|
+
(byCollTag[ct] ||= []).push(p);
|
|
20656
|
+
}
|
|
20657
|
+
const validGroups = [];
|
|
20658
|
+
for (const group of Object.values(byCollTag)) {
|
|
20659
|
+
const supports = new Set(group.map((p) => p.liabilityBankTag.toString()));
|
|
20660
|
+
let coversAll = true;
|
|
20661
|
+
for (const rt of requiredTags) {
|
|
20662
|
+
if (!supports.has(rt)) {
|
|
20663
|
+
coversAll = false;
|
|
20664
|
+
break;
|
|
20665
|
+
}
|
|
20666
|
+
}
|
|
20667
|
+
if (coversAll) {
|
|
20668
|
+
validGroups.push(group);
|
|
20669
|
+
}
|
|
20670
|
+
}
|
|
20671
|
+
if (validGroups.length === 0) return [];
|
|
20672
|
+
return validGroups.flat();
|
|
20704
20673
|
}
|
|
20705
20674
|
function computeBalanceUsdValue(params) {
|
|
20706
20675
|
const {
|
|
@@ -36119,48 +36088,6 @@ async function makeCloseMarginfiAccountTx({
|
|
|
36119
36088
|
);
|
|
36120
36089
|
return closeTx;
|
|
36121
36090
|
}
|
|
36122
|
-
async function makeAccountTransferToNewAccountTx({
|
|
36123
|
-
connection,
|
|
36124
|
-
program,
|
|
36125
|
-
marginfiAccount,
|
|
36126
|
-
newMarginfiAccount,
|
|
36127
|
-
newAuthority,
|
|
36128
|
-
feePayer,
|
|
36129
|
-
feePayerKeypair
|
|
36130
|
-
}) {
|
|
36131
|
-
const [feeStateKey] = web3_js.PublicKey.findProgramAddressSync(
|
|
36132
|
-
[Buffer.from("feestate", "utf-8")],
|
|
36133
|
-
program.programId
|
|
36134
|
-
);
|
|
36135
|
-
const feeState = await program.account.feeState.fetch(feeStateKey);
|
|
36136
|
-
const transferIx = await instructions_default.makeAccountTransferToNewAccountIx(program, {
|
|
36137
|
-
oldMarginfiAccount: marginfiAccount.address,
|
|
36138
|
-
newMarginfiAccount: newMarginfiAccount.publicKey,
|
|
36139
|
-
newAuthority,
|
|
36140
|
-
globalFeeWallet: feeState.globalFeeWallet,
|
|
36141
|
-
feePayer
|
|
36142
|
-
});
|
|
36143
|
-
const {
|
|
36144
|
-
value: { blockhash }
|
|
36145
|
-
} = await connection.getLatestBlockhashAndContext("confirmed");
|
|
36146
|
-
const signers = [newMarginfiAccount];
|
|
36147
|
-
if (feePayerKeypair) signers.push(feePayerKeypair);
|
|
36148
|
-
const transferTx = addTransactionMetadata(
|
|
36149
|
-
new web3_js.VersionedTransaction(
|
|
36150
|
-
new web3_js.TransactionMessage({
|
|
36151
|
-
instructions: [transferIx],
|
|
36152
|
-
payerKey: feePayer,
|
|
36153
|
-
recentBlockhash: blockhash
|
|
36154
|
-
}).compileToV0Message([])
|
|
36155
|
-
),
|
|
36156
|
-
{
|
|
36157
|
-
signers,
|
|
36158
|
-
addressLookupTables: [],
|
|
36159
|
-
type: "TRANSFER_AUTH" /* TRANSFER_AUTH */
|
|
36160
|
-
}
|
|
36161
|
-
);
|
|
36162
|
-
return transferTx;
|
|
36163
|
-
}
|
|
36164
36091
|
async function makeCreateAccountTxWithProjection(props) {
|
|
36165
36092
|
const [marginfiAccountAddress] = deriveMarginfiAccount(
|
|
36166
36093
|
props.program.programId,
|
|
@@ -54151,15 +54078,14 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
54151
54078
|
*
|
|
54152
54079
|
* @see {@link makeAccountTransferToNewAccountIx} for implementation
|
|
54153
54080
|
*/
|
|
54154
|
-
async makeAccountTransferToNewAccountIx(program, newMarginfiAccount, newAuthority
|
|
54081
|
+
async makeAccountTransferToNewAccountIx(program, newMarginfiAccount, newAuthority) {
|
|
54155
54082
|
const accountTransferToNewAccountIx = await instructions_default.makeAccountTransferToNewAccountIx(
|
|
54156
54083
|
program,
|
|
54157
54084
|
{
|
|
54158
54085
|
oldMarginfiAccount: this.address,
|
|
54159
54086
|
newMarginfiAccount,
|
|
54160
54087
|
newAuthority,
|
|
54161
|
-
|
|
54162
|
-
feePayer
|
|
54088
|
+
feePayer: this.authority
|
|
54163
54089
|
}
|
|
54164
54090
|
);
|
|
54165
54091
|
return { instructions: [accountTransferToNewAccountIx], keys: [] };
|
|
@@ -54815,13 +54741,11 @@ var MarginfiAccountWrapper = class {
|
|
|
54815
54741
|
* @param newMarginfiAccount - New account public key
|
|
54816
54742
|
* @param newAuthority - New authority public key
|
|
54817
54743
|
*/
|
|
54818
|
-
async makeAccountTransferToNewAccountIx(newMarginfiAccount, newAuthority
|
|
54744
|
+
async makeAccountTransferToNewAccountIx(newMarginfiAccount, newAuthority) {
|
|
54819
54745
|
return this.account.makeAccountTransferToNewAccountIx(
|
|
54820
54746
|
this.client.program,
|
|
54821
54747
|
newMarginfiAccount,
|
|
54822
|
-
newAuthority
|
|
54823
|
-
globalFeeWallet,
|
|
54824
|
-
feePayer
|
|
54748
|
+
newAuthority
|
|
54825
54749
|
);
|
|
54826
54750
|
}
|
|
54827
54751
|
/**
|
|
@@ -55888,7 +55812,6 @@ exports.isFlashloan = isFlashloan;
|
|
|
55888
55812
|
exports.isV0Tx = isV0Tx;
|
|
55889
55813
|
exports.isWeightedPrice = isWeightedPrice;
|
|
55890
55814
|
exports.isWholePosition = isWholePosition;
|
|
55891
|
-
exports.makeAccountTransferToNewAccountTx = makeAccountTransferToNewAccountTx;
|
|
55892
55815
|
exports.makeAddPermissionlessStakedBankIx = makeAddPermissionlessStakedBankIx;
|
|
55893
55816
|
exports.makeBeginFlashLoanIx = makeBeginFlashLoanIx3;
|
|
55894
55817
|
exports.makeBorrowIx = makeBorrowIx3;
|