@0dotxyz/p0-ts-sdk 2.2.3-alpha.0 → 2.2.3-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 CHANGED
@@ -15629,12 +15629,20 @@ function makeEndFlashLoanIx(mfiProgram, accounts, remainingAccounts = []) {
15629
15629
  }).accountsPartial(optionalAccounts).remainingAccounts(remainingAccounts).instruction();
15630
15630
  }
15631
15631
  async function makeAccountTransferToNewAccountIx(mfProgram, accounts) {
15632
- const { oldMarginfiAccount, newMarginfiAccount, newAuthority, feePayer, ...optionalAccounts } = accounts;
15632
+ const {
15633
+ oldMarginfiAccount,
15634
+ newMarginfiAccount,
15635
+ newAuthority,
15636
+ globalFeeWallet,
15637
+ feePayer,
15638
+ ...optionalAccounts
15639
+ } = accounts;
15633
15640
  return mfProgram.methods.transferToNewAccount().accounts({
15634
15641
  oldMarginfiAccount,
15635
15642
  newMarginfiAccount,
15636
15643
  newAuthority,
15637
- globalFeeWallet: feePayer
15644
+ globalFeeWallet,
15645
+ feePayer
15638
15646
  }).accountsPartial(optionalAccounts).instruction();
15639
15647
  }
15640
15648
  async function makeGroupInitIx(mfProgram, accounts) {
@@ -20579,8 +20587,8 @@ function activePairsFromIndex(configured, liabTagByBank, liabSet, collSet) {
20579
20587
  return validGroups.flat().map((p) => p.orig);
20580
20588
  }
20581
20589
  function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, allBanks) {
20582
- const liabBaseSet = new Set(activeLiabilities.map((b) => b.toBase58()));
20583
- const collBaseSet = new Set(activeCollateral.map((b) => b.toBase58()));
20590
+ const activeLiabilitiesSet = new Set(activeLiabilities.map((b) => b.toBase58()));
20591
+ const activeCollateralSet = new Set(activeCollateral.map((b) => b.toBase58()));
20584
20592
  const { configured, liabTagByBank } = indexConfiguredPairs(emodePairs);
20585
20593
  const liabTagMapAll = /* @__PURE__ */ new Map();
20586
20594
  for (const p of emodePairs) {
@@ -20590,10 +20598,15 @@ function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, al
20590
20598
  for (const p of emodePairs) {
20591
20599
  for (const c of p.collateralBanks) allCollateralBankStrs.add(c.toBase58());
20592
20600
  }
20593
- const basePairs = activePairsFromIndex(configured, liabTagByBank, liabBaseSet, collBaseSet);
20601
+ const basePairs = activePairsFromIndex(
20602
+ configured,
20603
+ liabTagByBank,
20604
+ activeLiabilitiesSet,
20605
+ activeCollateralSet
20606
+ );
20594
20607
  const baseOn = basePairs.length > 0;
20595
20608
  const existingTags = new Set(
20596
- Array.from(liabBaseSet).map((l) => liabTagMapAll.get(l)).filter((t) => !!t)
20609
+ Array.from(activeLiabilitiesSet).map((l) => liabTagMapAll.get(l)).filter((t) => !!t)
20597
20610
  );
20598
20611
  function minWeight(ps) {
20599
20612
  let m = ps[0].assetWeightInit;
@@ -20611,7 +20624,7 @@ function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, al
20611
20624
  return 1 /* ExtendEmode */;
20612
20625
  }
20613
20626
  function simulate(bankStr, action) {
20614
- const L = new Set(liabBaseSet), C = new Set(collBaseSet);
20627
+ const L = new Set(activeLiabilitiesSet), C = new Set(activeCollateralSet);
20615
20628
  switch (action) {
20616
20629
  case "borrow":
20617
20630
  L.add(bankStr);
@@ -20667,16 +20680,16 @@ function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, al
20667
20680
  for (const bank of allBanks) {
20668
20681
  const key = bank.toBase58();
20669
20682
  const impact = {};
20670
- if (!collBaseSet.has(key)) {
20683
+ if (!activeCollateralSet.has(key)) {
20671
20684
  impact.borrowImpact = simulate(key, "borrow");
20672
20685
  }
20673
- if (allCollateralBankStrs.has(key) && !collBaseSet.has(key) && !liabBaseSet.has(key)) {
20686
+ if (allCollateralBankStrs.has(key) && !activeCollateralSet.has(key) && !activeLiabilitiesSet.has(key)) {
20674
20687
  impact.supplyImpact = simulate(key, "supply");
20675
20688
  }
20676
- if (liabBaseSet.has(key)) {
20689
+ if (activeLiabilitiesSet.has(key)) {
20677
20690
  impact.repayAllImpact = simulate(key, "repay");
20678
20691
  }
20679
- if (collBaseSet.has(key)) {
20692
+ if (activeCollateralSet.has(key)) {
20680
20693
  impact.withdrawAllImpact = simulate(key, "withdraw");
20681
20694
  }
20682
20695
  result[key] = impact;
@@ -36106,6 +36119,48 @@ async function makeCloseMarginfiAccountTx({
36106
36119
  );
36107
36120
  return closeTx;
36108
36121
  }
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
+ }
36109
36164
  async function makeCreateAccountTxWithProjection(props) {
36110
36165
  const [marginfiAccountAddress] = deriveMarginfiAccount(
36111
36166
  props.program.programId,
@@ -54096,14 +54151,15 @@ var MarginfiAccount = class _MarginfiAccount {
54096
54151
  *
54097
54152
  * @see {@link makeAccountTransferToNewAccountIx} for implementation
54098
54153
  */
54099
- async makeAccountTransferToNewAccountIx(program, newMarginfiAccount, newAuthority) {
54154
+ async makeAccountTransferToNewAccountIx(program, newMarginfiAccount, newAuthority, globalFeeWallet, feePayer) {
54100
54155
  const accountTransferToNewAccountIx = await instructions_default.makeAccountTransferToNewAccountIx(
54101
54156
  program,
54102
54157
  {
54103
54158
  oldMarginfiAccount: this.address,
54104
54159
  newMarginfiAccount,
54105
54160
  newAuthority,
54106
- feePayer: this.authority
54161
+ globalFeeWallet,
54162
+ feePayer
54107
54163
  }
54108
54164
  );
54109
54165
  return { instructions: [accountTransferToNewAccountIx], keys: [] };
@@ -54759,11 +54815,13 @@ var MarginfiAccountWrapper = class {
54759
54815
  * @param newMarginfiAccount - New account public key
54760
54816
  * @param newAuthority - New authority public key
54761
54817
  */
54762
- async makeAccountTransferToNewAccountIx(newMarginfiAccount, newAuthority) {
54818
+ async makeAccountTransferToNewAccountIx(newMarginfiAccount, newAuthority, globalFeeWallet, feePayer) {
54763
54819
  return this.account.makeAccountTransferToNewAccountIx(
54764
54820
  this.client.program,
54765
54821
  newMarginfiAccount,
54766
- newAuthority
54822
+ newAuthority,
54823
+ globalFeeWallet,
54824
+ feePayer
54767
54825
  );
54768
54826
  }
54769
54827
  /**
@@ -55830,6 +55888,7 @@ exports.isFlashloan = isFlashloan;
55830
55888
  exports.isV0Tx = isV0Tx;
55831
55889
  exports.isWeightedPrice = isWeightedPrice;
55832
55890
  exports.isWholePosition = isWholePosition;
55891
+ exports.makeAccountTransferToNewAccountTx = makeAccountTransferToNewAccountTx;
55833
55892
  exports.makeAddPermissionlessStakedBankIx = makeAddPermissionlessStakedBankIx;
55834
55893
  exports.makeBeginFlashLoanIx = makeBeginFlashLoanIx3;
55835
55894
  exports.makeBorrowIx = makeBorrowIx3;