Skip to content

Commit

Permalink
modify and add tx-priority-fee arg to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Nagaprasadvr committed Mar 20, 2024
1 parent 3fae875 commit b76c376
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 8 deletions.
8 changes: 8 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
Expand Down
9 changes: 8 additions & 1 deletion packages/cli/src/cvg.ts
Original file line number Diff line number Diff line change
@@ -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<Convergence> => {
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;
Expand Down
31 changes: 31 additions & 0 deletions packages/cli/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
PsyoptionsEuropeanInstrument,
LegInstrument,
FixedSize,
TransactionPriority,
} from '@convergence-rfq/sdk';
import { Command } from 'commander';

Expand Down Expand Up @@ -52,6 +53,11 @@ export const formatInstrument = (instrument: Instrument): string => {
export const addDefaultArgs = (cmd: any) => {
cmd.option('--rpc-endpoint <string>', 'RPC endpoint', DEFAULT_RPC_ENDPOINT);
cmd.option('--skip-preflight', 'skip preflight', false);
cmd.option(
'--tx-priority-fee <string>',
'transaction priority fee can be [none : 0 mcLamports , normal : 1 mcLamports, high : 10 mcLamports, turbo : 100 mcLamports, custom : <number> mcLamports]',
'none'
);
cmd.option('--keypair-file <string>', 'keypair file', DEFAULT_KEYPAIR_FILE);
cmd.option('--verbose <boolean>', 'verbose', false);
return cmd;
Expand Down Expand Up @@ -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';
}
}
};
6 changes: 6 additions & 0 deletions packages/js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/js/package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
11 changes: 8 additions & 3 deletions packages/js/src/utils/TransactionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,16 @@ export class TransactionBuilder<C extends object = object> {
}

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: [],
});
Expand Down
2 changes: 1 addition & 1 deletion packages/js/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export type Option<T> = T | null;

export type Opaque<T, K> = T & { __opaque__: K };

export type TransactionPriority = 'none' | 'normal' | 'high' | 'turbo';
export type TransactionPriority = 'none' | 'normal' | 'high' | 'turbo' | number;

0 comments on commit b76c376

Please sign in to comment.