diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 6cafbfb8a..1f42b04ca 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -1,5 +1,13 @@ # @convergence-rfq/cli +## 6.3.1 + +### Patch Changes + +- Add tx-priority-fee argument to cli and modify sdk txPriority to take custom values +- Updated dependencies + - @convergence-rfq/sdk@6.3.1 + ## 6.3.0 ### Minor Changes diff --git a/packages/cli/package.json b/packages/cli/package.json index fd62d1879..1dd398b8b 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.3.0", + "version": "6.3.1", "license": "MIT", "publishConfig": { "access": "public" @@ -47,7 +47,7 @@ "cli": "ts-node src/index.ts" }, "dependencies": { - "@convergence-rfq/sdk": "6.3.0", + "@convergence-rfq/sdk": "6.3.1", "@solana/web3.js": "^1.87.6", "@types/cookie": "^0.5.1", "commander": "^10.0.0" diff --git a/packages/cli/src/cvg.ts b/packages/cli/src/cvg.ts index d8c098764..e570dfd85 100644 --- a/packages/cli/src/cvg.ts +++ b/packages/cli/src/cvg.ts @@ -1,17 +1,24 @@ import { readFileSync } from 'fs'; import { Connection, Keypair } from '@solana/web3.js'; import { Convergence, keypairIdentity } from '@convergence-rfq/sdk'; +import { resolveTxPriorityArg } from './helpers'; export type Opts = any; export const createCvg = async (opts: Opts): Promise => { const buffer = JSON.parse(readFileSync(opts.keypairFile, 'utf8')); const user = Keypair.fromSecretKey(new Uint8Array(buffer)); + const txPriorityString: string = opts.txPriorityFee; + + const txPriority = resolveTxPriorityArg(txPriorityString); const cvg = new Convergence( new Connection(opts.rpcEndpoint, { commitment: 'confirmed', }), - { skipPreflight: opts.skipPreflight } + { + skipPreflight: opts.skipPreflight, + transactionPriority: txPriority, + } ); cvg.use(keypairIdentity(user)); return cvg; diff --git a/packages/cli/src/helpers.ts b/packages/cli/src/helpers.ts index b3ac1eb1f..38477be03 100644 --- a/packages/cli/src/helpers.ts +++ b/packages/cli/src/helpers.ts @@ -4,6 +4,7 @@ import { PsyoptionsEuropeanInstrument, LegInstrument, FixedSize, + TransactionPriority, } from '@convergence-rfq/sdk'; import { Command } from 'commander'; @@ -52,6 +53,11 @@ export const formatInstrument = (instrument: Instrument): string => { export const addDefaultArgs = (cmd: any) => { cmd.option('--rpc-endpoint ', 'RPC endpoint', DEFAULT_RPC_ENDPOINT); cmd.option('--skip-preflight', 'skip preflight', false); + cmd.option( + '--tx-priority-fee ', + 'transaction priority fee can be [none : 0 mcLamports , normal : 1 mcLamports, high : 10 mcLamports, turbo : 100 mcLamports, custom : mcLamports]', + 'none' + ); cmd.option('--keypair-file ', 'keypair file', DEFAULT_KEYPAIR_FILE); cmd.option('--verbose ', 'verbose', false); return cmd; @@ -144,3 +150,28 @@ export const fetchBirdeyeTokenPrice = async ( } return undefined; }; + +export const resolveTxPriorityArg = ( + txPriority: string +): TransactionPriority => { + switch (txPriority) { + case 'none': + return 'none'; + case 'normal': + return 'normal'; + case 'high': + return 'high'; + case 'turbo': + return 'turbo'; + default: + try { + const txPriorityInNumber = Number(txPriority); + if (isNaN(txPriorityInNumber) || txPriorityInNumber < 0) { + return 'none'; + } + return txPriorityInNumber; + } catch (e) { + return 'none'; + } + } +}; diff --git a/packages/js/CHANGELOG.md b/packages/js/CHANGELOG.md index 2a435541c..f6c34cfdc 100644 --- a/packages/js/CHANGELOG.md +++ b/packages/js/CHANGELOG.md @@ -1,5 +1,11 @@ # @convergence-rfq/sdk +## 6.3.1 + +### Patch Changes + +- Add tx-priority-fee argument to cli and modify sdk txPriority to take custom values + ## 6.3.0 ### Minor Changes diff --git a/packages/js/package.json b/packages/js/package.json index e33715f88..193a6c62c 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.3.0", + "version": "6.3.1", "license": "MIT", "publishConfig": { "access": "public" diff --git a/packages/js/src/utils/TransactionBuilder.ts b/packages/js/src/utils/TransactionBuilder.ts index 8994f7ef5..3fa577864 100644 --- a/packages/js/src/utils/TransactionBuilder.ts +++ b/packages/js/src/utils/TransactionBuilder.ts @@ -278,11 +278,16 @@ export class TransactionBuilder { } addTxPriorityFeeIx(convergence: Convergence) { + if (!convergence.transactionPriority) { + return this; + } + const txPriorityInMicroLamports = + typeof convergence.transactionPriority === 'number' + ? convergence.transactionPriority + : TRANSACTION_PRIORITY_FEE_MAP[convergence.transactionPriority]; return this.add({ instruction: ComputeBudgetProgram.setComputeUnitPrice({ - microLamports: - TRANSACTION_PRIORITY_FEE_MAP[convergence.transactionPriority] ?? - TRANSACTION_PRIORITY_FEE_MAP['none'], + microLamports: txPriorityInMicroLamports, }), signers: [], }); diff --git a/packages/js/src/utils/types.ts b/packages/js/src/utils/types.ts index 6428c921d..75084a54b 100644 --- a/packages/js/src/utils/types.ts +++ b/packages/js/src/utils/types.ts @@ -14,4 +14,4 @@ export type Option = T | null; export type Opaque = T & { __opaque__: K }; -export type TransactionPriority = 'none' | 'normal' | 'high' | 'turbo'; +export type TransactionPriority = 'none' | 'normal' | 'high' | 'turbo' | number;