diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 01c680a43..33656adb3 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -1,5 +1,53 @@ # @convergence-rfq/cli +## 6.6.24 + +### Patch Changes + +- add lastValidBlockhash to revertSettlementPreparation txs +- Updated dependencies + - @convergence-rfq/sdk@6.6.24 + +## 6.6.23 + +### Patch Changes + +- split txs for revertPrepareSettlement +- Updated dependencies + - @convergence-rfq/sdk@6.6.23 + +## 6.6.22 + +### Patch Changes + +- add updateMarkPriceIx to unlockHxroCollatera fn +- Updated dependencies + - @convergence-rfq/sdk@6.6.22 + +## 6.6.21 + +### Patch Changes + +- add logs to check unlockhxroCollateralTxSize +- Updated dependencies + - @convergence-rfq/sdk@6.6.21 + +## 6.6.20 + +### Patch Changes + +- fix tx size overflow for unlockHxroCollateralTx +- Updated dependencies + - @convergence-rfq/sdk@6.6.20 + +## 6.6.19 + +### Patch Changes + +- modify unclockHxroCollateral and add markPriceUpdate ixs +- Updated dependencies + - @convergence-rfq/sdk@6.6.19 + ## 6.6.18 ### Patch Changes diff --git a/packages/cli/package.json b/packages/cli/package.json index 4e3f5e1ee..78332c4b8 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,7 +1,7 @@ { "name": "@convergence-rfq/cli", "description": "Official Convergence CLI", - "version": "6.6.18", + "version": "6.6.24", "license": "MIT", "publishConfig": { "access": "public" @@ -47,7 +47,7 @@ "cli": "ts-node src/index.ts" }, "dependencies": { - "@convergence-rfq/sdk": "6.6.18", + "@convergence-rfq/sdk": "6.6.24", "@solana/web3.js": "^1.87.6", "@types/cookie": "^0.5.1", "commander": "^10.0.0" diff --git a/packages/js/CHANGELOG.md b/packages/js/CHANGELOG.md index db94e16b0..90bfa4cb6 100644 --- a/packages/js/CHANGELOG.md +++ b/packages/js/CHANGELOG.md @@ -1,5 +1,41 @@ # @convergence-rfq/sdk +## 6.6.24 + +### Patch Changes + +- add lastValidBlockhash to revertSettlementPreparation txs + +## 6.6.23 + +### Patch Changes + +- split txs for revertPrepareSettlement + +## 6.6.22 + +### Patch Changes + +- add updateMarkPriceIx to unlockHxroCollatera fn + +## 6.6.21 + +### Patch Changes + +- add logs to check unlockhxroCollateralTxSize + +## 6.6.20 + +### Patch Changes + +- fix tx size overflow for unlockHxroCollateralTx + +## 6.6.19 + +### Patch Changes + +- modify unclockHxroCollateral and add markPriceUpdate ixs + ## 6.6.18 ### Patch Changes diff --git a/packages/js/package.json b/packages/js/package.json index 5a8fea300..0d6ae327c 100644 --- a/packages/js/package.json +++ b/packages/js/package.json @@ -1,7 +1,7 @@ { "name": "@convergence-rfq/sdk", "description": "Official Convergence RFQ SDK", - "version": "6.6.18", + "version": "6.6.24", "license": "MIT", "publishConfig": { "access": "public" diff --git a/packages/js/src/plugins/hxroPrintTradeProviderModule/operations/unlockHxroCollateralByRecord.ts b/packages/js/src/plugins/hxroPrintTradeProviderModule/operations/unlockHxroCollateralByRecord.ts index 88fed30bc..899e56be8 100644 --- a/packages/js/src/plugins/hxroPrintTradeProviderModule/operations/unlockHxroCollateralByRecord.ts +++ b/packages/js/src/plugins/hxroPrintTradeProviderModule/operations/unlockHxroCollateralByRecord.ts @@ -6,6 +6,8 @@ import { import dexterity from '@hxronetwork/dexterity-ts'; import BN from 'bn.js'; +import { Transaction } from '@solana/web3.js'; +import * as solana from '@solana/web3.js'; import { getHxroProgramFromIDL } from '../program'; import { fetchValidHxroMpg } from '../helpers'; import { hxroManifestCache } from '../cache'; @@ -18,8 +20,8 @@ import { PublicKey, useOperation, } from '@/types'; -import { TransactionBuilder, TransactionBuilderOptions } from '@/utils'; -import { SendAndConfirmTransactionResponse } from '@/plugins/rpcModule'; +import { TransactionBuilder, TransactionBuilderOptions, sleep } from '@/utils'; +import { isLocalEnv } from '@/utils/helpers'; const Key = 'unlockHxroCollateralByRecord' as const; @@ -51,8 +53,7 @@ export type UnlockHxroCollateralByRecordInput = { * @category Outputs */ export type UnlockHxroCollateralByRecordOutput = - SendAndConfirmTransactionResponse; - + solana.RpcResponseAndContext; /** * @group Operations * @category Handlers @@ -67,7 +68,7 @@ export const unlockHxroCollateralByRecordOperationHandler: OperationHandler; if ('publicKey' in lockRecord) { lockRecordData = lockRecord; @@ -79,9 +80,13 @@ export const unlockHxroCollateralByRecordOperationHandler: OperationHandler ix.keys.map((k) => k.pubkey)) + .flat(); + + if (addressLookupTableAcc && addressLookupTableAcc.isActive()) { + const remainingAddresses: PublicKey[] = []; + const addressesArray = addressLookupTableAcc.state.addresses.map((a) => + a.toBase58() + ); + for (const addr of unlockHxroCollateralAccouts) { + if (!addressesArray.includes(addr.toBase58())) { + remainingAddresses.push(addr); + break; + } + } + if (remainingAddresses.length > 0) { + const extendInstruction = + solana.AddressLookupTableProgram.extendLookupTable({ + payer: payer.publicKey, + authority: payer.publicKey, + lookupTable: lookupTableAddress, + addresses: remainingAddresses, + }); + const extendLookupTx = new Transaction().add(extendInstruction); + extendLookupTx.feePayer = payer.publicKey; + extendLookupTx.recentBlockhash = lastValidBlockHeight.blockhash; + extendLookupTx.lastValidBlockHeight = + lastValidBlockHeight.lastValidBlockHeight; + lookUpTxs.push(extendLookupTx); + } + } else { + const lookUpCreateTx = new Transaction().add(lookupTableInst); + lookUpCreateTx.feePayer = payer.publicKey; + lookUpCreateTx.recentBlockhash = lastValidBlockHeight.blockhash; + lookUpCreateTx.lastValidBlockHeight = + lastValidBlockHeight.lastValidBlockHeight; + lookUpTxs.push(lookUpCreateTx); + + const extendInstruction = + solana.AddressLookupTableProgram.extendLookupTable({ + payer: payer.publicKey, + authority: payer.publicKey, + lookupTable: lookupTableAddress, + addresses: unlockHxroCollateralAccouts, + }); + const extendLookupTx = new Transaction().add(extendInstruction); + extendLookupTx.feePayer = payer.publicKey; + extendLookupTx.recentBlockhash = lastValidBlockHeight.blockhash; + extendLookupTx.lastValidBlockHeight = + lastValidBlockHeight.lastValidBlockHeight; + lookUpTxs.push(extendLookupTx); + } + + if (lookUpTxs.length > 0) { + const signedLookUpTxs = await cvg + .identity() + .signAllTransactions(lookUpTxs); + for (const tx of signedLookUpTxs) { + await cvg.rpc().serializeAndSendTransaction(tx); + } + } + + const txs: Transaction[] = []; + + if (action == 'unlock' || action == 'unlock-and-remove-record') { + txs.push( + unlockHxroCollateralTxBuilder.toTransaction(lastValidBlockHeight) + ); + } + if (action == 'remove-record' || action == 'unlock-and-remove-record') { + txs.push( + removeRecordCollateralTxBuilder.toTransaction(lastValidBlockHeight) + ); + } + + if (txs.length === 0) { + throw new Error('No transactions to send'); + } + const signedTxs = await cvg.identity().signAllTransactions(txs); + let txResponse: solana.RpcResponseAndContext | null = + null; + + const newlookUpTable = await cvg.connection.getAddressLookupTable( + lookupTableAddress + ); + const newAddressLookupTableAcc = newlookUpTable.value; + if (!newAddressLookupTableAcc) { + throw new Error('No lookup table'); + } + const txMessages = signedTxs.map((tx) => + new solana.TransactionMessage({ + payerKey: payer.publicKey, + recentBlockhash: lastValidBlockHeight.blockhash, + instructions: tx.instructions.map((ix) => ix), + }).compileToV0Message([newAddressLookupTableAcc]) + ); + + const versionedTxs = txMessages.map( + (msg) => new solana.VersionedTransaction(msg) + ); + await sleep(1); + for (const tx of versionedTxs) { + tx.sign([cvg.identity() as solana.Signer]); + const sig = await cvg.connection.sendTransaction(tx); + txResponse = await cvg.connection.confirmTransaction(sig); + } + if (!txResponse) { + throw new Error('No transaction response'); + } + return txResponse; }, }; @@ -197,11 +325,26 @@ export const unlockHxroCollateralBuilder = async ( ]) .instruction(); - return TransactionBuilder.make<{}>() + const txBuilder = TransactionBuilder.make<{}>() .setFeePayer(payer) .add({ instruction, signers: [payer], key: 'unlockHxroCollateral', }); + + if (!isLocalEnv(cvg)) { + const trader = new dexterity.Trader(manifest, lockRecord.trg, true); + + await trader.connect(null, null); + const updateMarkPriceIx = trader.getUpdateMarkPricesIx(); + updateMarkPriceIx.keys[0].pubkey = payer.publicKey; + + txBuilder.prepend({ + instruction: updateMarkPriceIx, + signers: [payer], + key: 'updateMarkPrices', + }); + } + return txBuilder; }; diff --git a/packages/js/src/plugins/rfqModule/operations/revertSettlementPreparation.ts b/packages/js/src/plugins/rfqModule/operations/revertSettlementPreparation.ts index cdbadd3cf..b748e7134 100644 --- a/packages/js/src/plugins/rfqModule/operations/revertSettlementPreparation.ts +++ b/packages/js/src/plugins/rfqModule/operations/revertSettlementPreparation.ts @@ -105,11 +105,29 @@ export const revertSettlementPreparationOperationHandler: OperationHandler b.toTransaction(latestBlockhash)); + const signedTxs = await convergence.identity().signAllTransactions(txs); + let output: SendAndConfirmTransactionResponse | undefined; + for (const signedTx of signedTxs) { + output = await convergence + .rpc() + .serializeAndSendTransaction(signedTx, latestBlockhash); + } + if (!output) { + throw new Error('No transaction was sent'); + } + return { response: output }; }, };