fix : able to send transaction with priority fee

This commit is contained in:
shivaji43
2025-01-10 15:21:28 +05:30
parent 53ee654202
commit be3f158aaa
4 changed files with 193 additions and 271 deletions

193
pnpm-lock.yaml generated
View File

@@ -1002,8 +1002,13 @@ packages:
'@shikijs/vscode-textmate@10.0.1':
resolution: {integrity: sha512-fTIQwLF+Qhuws31iw7Ncl1R3HUDtGwIipiJ9iU+UsDUwMhegFcQKQHd51nZjb7CArq0MvON8rbgCGQYWHUKAdg==}
'@shikijs/vscode-textmate@9.3.1':
resolution: {integrity: sha512-79QfK1393x9Ho60QFyLti+QfdJzRQCVLFb97kOIV7Eo9vQU/roINgk7m24uv0a7AUvN//RDH36FLjjK48v0s9g==}
'@sindresorhus/is@4.6.0':
resolution: {integrity: sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==}
engines: {node: '>=10'}
'@sindresorhus/is@4.6.0':
resolution: {integrity: sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==}
engines: {node: '>=10'}
'@solana/buffer-layout-utils@0.2.0':
resolution: {integrity: sha512-szG4sxgJGktbuZYDg2FfNmkMi0DYQoVjN2h7ta1W1hPrwzarcFLBq9UpX1UjNXsNpT9dn+chgprtWGioUAr4/g==}
@@ -1182,9 +1187,13 @@ packages:
'@solana/web3.js@1.98.0':
resolution: {integrity: sha512-nz3Q5OeyGFpFCR+erX2f6JPt3sKhzhYcSycBCSPkWjzSVDh/Rr1FqTVMRe58FKO16/ivTUcuJjeS5MyBvpkbzA==}
'@sqds/multisig@2.1.3':
resolution: {integrity: sha512-WOiL7La+RSiJsz7jVO85yhSiiSvNMUthiWuLPeWVOoD6IYa34BEAzanF1RdXRWGglSbRFYCTkyr+Ay1WmXmSRQ==}
engines: {node: '>=14'}
'@supercharge/promise-pool@3.2.0':
resolution: {integrity: sha512-pj0cAALblTZBPtMltWOlZTQSLT07jIaFNeM8TWoJD1cQMgDB9mcMlVMoetiB35OzNJpqQ2b+QEtwiR9f20mADg==}
engines: {node: '>=8'}
'@supercharge/promise-pool@3.2.0':
resolution: {integrity: sha512-pj0cAALblTZBPtMltWOlZTQSLT07jIaFNeM8TWoJD1cQMgDB9mcMlVMoetiB35OzNJpqQ2b+QEtwiR9f20mADg==}
engines: {node: '>=8'}
'@swc/helpers@0.5.15':
resolution: {integrity: sha512-JQ5TuMi45Owi4/BIMAJBoSQoOJu12oOk/gADqlcUL9JEdHB8vyjUSsxqeNXnmXHjYKMi2WcYtezGEEhqUI/E2g==}
@@ -2442,8 +2451,9 @@ packages:
resolution: {integrity: sha512-M1WuAmb7pn9zdFRtQYk26ZBoY043Sse0wVDdk4Bppr+JOXyQYybdtvK+l9wUibhtjdjvtoiNy8tk+EgsYIUqKg==}
engines: {node: '>=12.0.0'}
invariant@2.2.4:
resolution: {integrity: sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==}
inquirer@8.2.6:
resolution: {integrity: sha512-M1WuAmb7pn9zdFRtQYk26ZBoY043Sse0wVDdk4Bppr+JOXyQYybdtvK+l9wUibhtjdjvtoiNy8tk+EgsYIUqKg==}
engines: {node: '>=12.0.0'}
ipaddr.js@1.9.1:
resolution: {integrity: sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==}
@@ -3217,15 +3227,32 @@ packages:
regex-utilities@2.3.0:
resolution: {integrity: sha512-8VhliFJAWRaUiVvREIiW2NXXTmHs4vMNnSzuJVhscgmGav3g9VDxLrQndI3dZZVVdp0ZO/5v0xmX516/7M9cng==}
regex@5.0.2:
resolution: {integrity: sha512-/pczGbKIQgfTMRV0XjABvc5RzLqQmwqxLHdQao2RTXPk+pmTXB2P0IaUHYdYyk412YLwUIkaeMd5T+RzVgTqnQ==}
regex@5.1.1:
resolution: {integrity: sha512-dN5I359AVGPnwzJm2jN1k0W9LPZ+ePvoOeVMMfqIMFz53sSwXkxaJoxr50ptnsC771lK95BnTrVSZxq0b9yCGw==}
resolve-alpn@1.2.1:
resolution: {integrity: sha512-0a1F4l73/ZFZOakJnQ3FvkJ2+gSTQWz/r2KE5OdDY0TxPm5h4GkqkWWfM47T7HsbnOtcJVEF4epCVy6u7Q3K+g==}
resolve-alpn@1.2.1:
resolution: {integrity: sha512-0a1F4l73/ZFZOakJnQ3FvkJ2+gSTQWz/r2KE5OdDY0TxPm5h4GkqkWWfM47T7HsbnOtcJVEF4epCVy6u7Q3K+g==}
resolve-from@4.0.0:
resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==}
engines: {node: '>=4'}
resolve-pkg-maps@1.0.0:
resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==}
responselike@2.0.1:
resolution: {integrity: sha512-4gl03wn3hj1HP3yzgdI7d3lCkF95F21Pz4BPGvKHinyQzALR5CapwC8yIi0Rh58DEMQ/SguC03wFj2k0M/mHhw==}
restore-cursor@3.1.0:
resolution: {integrity: sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==}
engines: {node: '>=8'}
responselike@2.0.1:
resolution: {integrity: sha512-4gl03wn3hj1HP3yzgdI7d3lCkF95F21Pz4BPGvKHinyQzALR5CapwC8yIi0Rh58DEMQ/SguC03wFj2k0M/mHhw==}
restore-cursor@3.1.0:
resolution: {integrity: sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==}
engines: {node: '>=8'}
restore-cursor@5.1.0:
resolution: {integrity: sha512-oMA2dcrw6u0YfxJQXm342bFKX/E4sG9rbTzO9ptUcR/e8A33cHuvStiYOwH7fszkZlZ1z/ta9AAoPk2F4qIOHA==}
@@ -3898,8 +3925,8 @@ snapshots:
dependencies:
'@aptos-labs/aptos-cli': 1.0.2
'@aptos-labs/aptos-client': 0.1.1
'@noble/curves': 1.7.0
'@noble/hashes': 1.6.1
'@noble/curves': 1.8.0
'@noble/hashes': 1.7.0
'@scure/bip32': 1.4.0
'@scure/bip39': 1.3.0
eventemitter3: 5.0.1
@@ -4376,7 +4403,7 @@ snapshots:
dependencies:
'@ethersproject/logger': 5.7.0
'@ethersproject/providers@5.7.2(bufferutil@4.0.8)(utf-8-validate@5.0.10)':
'@ethersproject/providers@5.7.2(bufferutil@4.0.9)(utf-8-validate@5.0.10)':
dependencies:
'@ethersproject/abstract-provider': 5.7.0
'@ethersproject/abstract-signer': 5.7.0
@@ -4397,7 +4424,7 @@ snapshots:
'@ethersproject/transactions': 5.7.0
'@ethersproject/web': 5.7.1
bech32: 1.1.4
ws: 7.4.6(bufferutil@4.0.8)(utf-8-validate@5.0.10)
ws: 7.4.6(bufferutil@4.0.9)(utf-8-validate@5.0.10)
transitivePeerDependencies:
- bufferutil
- utf-8-validate
@@ -4574,22 +4601,22 @@ snapshots:
transitivePeerDependencies:
- debug
'@irys/sdk@0.2.11(arweave@1.15.5)(bufferutil@4.0.8)(utf-8-validate@5.0.10)':
'@irys/sdk@0.2.11(arweave@1.15.5)(bufferutil@4.0.9)(utf-8-validate@5.0.10)':
dependencies:
'@aptos-labs/ts-sdk': 1.33.1
'@ethersproject/bignumber': 5.7.0
'@ethersproject/contracts': 5.7.0
'@ethersproject/providers': 5.7.2(bufferutil@4.0.8)(utf-8-validate@5.0.10)
'@ethersproject/providers': 5.7.2(bufferutil@4.0.9)(utf-8-validate@5.0.10)
'@ethersproject/wallet': 5.7.0
'@irys/query': 0.0.8
'@near-js/crypto': 0.0.3
'@near-js/keystores-browser': 0.0.3
'@near-js/providers': 0.0.4
'@near-js/transactions': 0.1.1
'@solana/web3.js': 1.98.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)
'@solana/web3.js': 1.98.0(bufferutil@4.0.9)(utf-8-validate@5.0.10)
'@supercharge/promise-pool': 3.2.0
algosdk: 1.24.1
arbundles: 0.11.2(arweave@1.15.5)(bufferutil@4.0.8)(utf-8-validate@5.0.10)
arbundles: 0.11.2(arweave@1.15.5)(bufferutil@4.0.9)(utf-8-validate@5.0.10)
async-retry: 1.3.3
axios: 1.7.9
base64url: 3.0.1
@@ -5133,7 +5160,11 @@ snapshots:
'@noble/curves@1.7.0':
dependencies:
'@noble/hashes': 1.6.0
'@noble/hashes': 1.7.0
'@noble/ed25519@1.7.3': {}
'@noble/ed25519@1.7.3': {}
'@noble/hashes@1.4.0': {}
@@ -5259,7 +5290,15 @@ snapshots:
'@randlabs/communication-bridge': 1.0.1
optional: true
'@raydium-io/raydium-sdk-v2@0.1.95-alpha(bufferutil@4.0.8)(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.7.2)(utf-8-validate@5.0.10)':
'@randlabs/communication-bridge@1.0.1':
optional: true
'@randlabs/myalgo-connect@1.4.2':
dependencies:
'@randlabs/communication-bridge': 1.0.1
optional: true
'@raydium-io/raydium-sdk-v2@0.1.95-alpha(bufferutil@4.0.9)(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.7.2)(utf-8-validate@5.0.10)':
dependencies:
'@solana/buffer-layout': 4.0.1
'@solana/spl-token': 0.4.9(@solana/web3.js@1.98.0(bufferutil@4.0.8)(utf-8-validate@5.0.10))(bufferutil@4.0.8)(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.7.2)(utf-8-validate@5.0.10)
@@ -5350,7 +5389,7 @@ snapshots:
'@shikijs/vscode-textmate@10.0.1': {}
'@shikijs/vscode-textmate@9.3.1': {}
'@sindresorhus/is@4.6.0': {}
'@sindresorhus/is@4.6.0': {}
@@ -5815,25 +5854,9 @@ snapshots:
- encoding
- utf-8-validate
'@sqds/multisig@2.1.3(bufferutil@4.0.8)(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.7.2)(utf-8-validate@5.0.10)':
dependencies:
'@metaplex-foundation/beet': 0.7.1
'@metaplex-foundation/beet-solana': 0.4.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)
'@metaplex-foundation/cusper': 0.0.2
'@solana/spl-token': 0.3.11(@solana/web3.js@1.98.0(bufferutil@4.0.8)(utf-8-validate@5.0.10))(bufferutil@4.0.8)(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.7.2)(utf-8-validate@5.0.10)
'@solana/web3.js': 1.98.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)
'@types/bn.js': 5.1.6
assert: 2.1.0
bn.js: 5.2.1
buffer: 6.0.3
invariant: 2.2.4
transitivePeerDependencies:
- bufferutil
- encoding
- fastestsmallesttextencoderdecoder
- supports-color
- typescript
- utf-8-validate
'@supercharge/promise-pool@3.2.0': {}
'@supercharge/promise-pool@3.2.0': {}
'@swc/helpers@0.5.15':
dependencies:
@@ -5843,7 +5866,11 @@ snapshots:
dependencies:
defer-to-connect: 2.0.1
'@tensor-hq/tensor-common@8.3.1(bufferutil@4.0.8)(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.7.2)(utf-8-validate@5.0.10)':
'@szmarczak/http-timer@4.0.6':
dependencies:
defer-to-connect: 2.0.1
'@tensor-hq/tensor-common@8.3.1(bufferutil@4.0.9)(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.7.2)(utf-8-validate@5.0.10)':
dependencies:
'@coral-xyz/anchor': 0.26.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)
'@metaplex-foundation/mpl-auction-house': 2.5.1(bufferutil@4.0.8)(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.7.2)(utf-8-validate@5.0.10)
@@ -6187,7 +6214,7 @@ snapshots:
dependencies:
algo-msgpack-with-bigint: 2.1.1
buffer: 6.0.3
cross-fetch: 3.1.8
cross-fetch: 3.2.0
hi-base32: 0.5.1
js-sha256: 0.9.0
js-sha3: 0.8.0
@@ -6241,11 +6268,43 @@ snapshots:
ansicolors@0.3.2: {}
arbundles@0.11.2(arweave@1.15.5)(bufferutil@4.0.8)(utf-8-validate@5.0.10):
arbundles@0.11.2(arweave@1.15.5)(bufferutil@4.0.9)(utf-8-validate@5.0.10):
dependencies:
'@ethersproject/bytes': 5.7.0
'@ethersproject/hash': 5.7.0
'@ethersproject/providers': 5.7.2(bufferutil@4.0.8)(utf-8-validate@5.0.10)
'@ethersproject/providers': 5.7.2(bufferutil@4.0.9)(utf-8-validate@5.0.10)
'@ethersproject/signing-key': 5.7.0
'@ethersproject/transactions': 5.7.0
'@ethersproject/wallet': 5.7.0
'@irys/arweave': 0.0.2
'@noble/ed25519': 1.7.3
base64url: 3.0.1
bs58: 4.0.1
keccak: 3.0.4
secp256k1: 5.0.1
optionalDependencies:
'@randlabs/myalgo-connect': 1.4.2
algosdk: 1.24.1
arweave-stream-tx: 1.2.2(arweave@1.15.5)
multistream: 4.1.0
tmp-promise: 3.0.3
transitivePeerDependencies:
- arweave
- bufferutil
- debug
- encoding
- utf-8-validate
arconnect@0.4.2:
dependencies:
arweave: 1.15.5
optional: true
arbundles@0.11.2(arweave@1.15.5)(bufferutil@4.0.9)(utf-8-validate@5.0.10):
dependencies:
'@ethersproject/bytes': 5.7.0
'@ethersproject/hash': 5.7.0
'@ethersproject/providers': 5.7.2(bufferutil@4.0.9)(utf-8-validate@5.0.10)
'@ethersproject/signing-key': 5.7.0
'@ethersproject/transactions': 5.7.0
'@ethersproject/wallet': 5.7.0
@@ -6295,7 +6354,7 @@ snapshots:
asn1.js@5.4.1:
dependencies:
bn.js: 4.12.1
bn.js: 4.11.6
inherits: 2.0.4
minimalistic-assert: 1.0.1
safer-buffer: 2.1.2
@@ -6316,7 +6375,7 @@ snapshots:
asn1.js@5.4.1:
dependencies:
bn.js: 4.12.1
bn.js: 4.11.6
inherits: 2.0.4
minimalistic-assert: 1.0.1
safer-buffer: 2.1.2
@@ -7254,6 +7313,15 @@ snapshots:
hasown: 2.0.2
math-intrinsics: 1.1.0
get-proto@1.0.1:
dependencies:
dunder-proto: 1.0.1
es-object-atoms: 1.0.0
get-stream@5.2.0:
dependencies:
pump: 3.0.2
get-stream@5.2.0:
dependencies:
pump: 3.0.2
@@ -7486,7 +7554,7 @@ snapshots:
through: 2.3.8
wrap-ansi: 6.2.0
invariant@2.2.4:
inquirer@8.2.6:
dependencies:
loose-envify: 1.4.0
@@ -8209,7 +8277,23 @@ snapshots:
resolve-from@4.0.0: {}
resolve-pkg-maps@1.0.0: {}
responselike@2.0.1:
dependencies:
lowercase-keys: 2.0.0
restore-cursor@3.1.0:
dependencies:
onetime: 5.1.2
signal-exit: 3.0.7
responselike@2.0.1:
dependencies:
lowercase-keys: 2.0.0
restore-cursor@3.1.0:
dependencies:
onetime: 5.1.2
signal-exit: 3.0.7
restore-cursor@5.1.0:
dependencies:
@@ -8789,12 +8873,17 @@ snapshots:
wrappy@1.0.2: {}
ws@7.4.6(bufferutil@4.0.8)(utf-8-validate@5.0.10):
ws@7.4.6(bufferutil@4.0.9)(utf-8-validate@5.0.10):
optionalDependencies:
bufferutil: 4.0.8
bufferutil: 4.0.9
utf-8-validate: 5.0.10
ws@7.5.10(bufferutil@4.0.8)(utf-8-validate@5.0.10):
ws@7.4.6(bufferutil@4.0.9)(utf-8-validate@5.0.10):
optionalDependencies:
bufferutil: 4.0.9
utf-8-validate: 5.0.10
ws@7.5.10(bufferutil@4.0.9)(utf-8-validate@5.0.10):
optionalDependencies:
bufferutil: 4.0.8
utf-8-validate: 5.0.10

View File

@@ -100,150 +100,6 @@ import {
SolanaGetAllAssetsByOwner,
} from "./index";
export class SolanaHeliusWebhookTool extends Tool {
name = "create_helius_webhook";
description = `Creates a Helius Webhook that listens to specified account addresses.
Inputs (input is a JSON string):
accountAddresses: string[] | string,
e.g. ["BVdNLvyG2DNiWAXBE9qAmc4MTQXymd5Bzfo9xrQSUzVP","Eo2ciguhMLmcTWXELuEQPdu7DWZt67LHXb2rdHZUbot7"]
or "BVdNLvyG2DNiWAXBE9qAmc4MTQXymd5Bzfo9xrQSUzVP,Eo2ciguhMLmcTWXELuEQPdu7DWZt67LHXb2rdHZUbot7"
webhookURL: string, e.g. "https://TestServer.test.repl.co/webhooks"`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
protected async _call(input: string): Promise<string> {
try {
const parsedInput = JSON.parse(input);
let accountAddresses: string[] = [];
if (!parsedInput.accountAddresses) {
throw new Error('Missing "accountAddresses" property in input JSON.');
}
if (Array.isArray(parsedInput.accountAddresses)) {
accountAddresses = parsedInput.accountAddresses.map((addr: string) =>
addr.trim(),
);
} else if (typeof parsedInput.accountAddresses === "string") {
accountAddresses = parsedInput.accountAddresses
.split(",")
.map((addr: string) => addr.trim());
} else {
throw new Error(
'Invalid type for "accountAddresses". Expected array or comma-separated string.',
);
}
const webhookURL = parsedInput.webhookURL;
if (!webhookURL) {
throw new Error(
'Invalid input. Expected a "webhookURL" property in the JSON.',
);
}
const result = await this.solanaKit.CreateWebhook(
accountAddresses,
webhookURL,
);
// Return success in JSON
return JSON.stringify({
status: "success",
message: "Helius Webhook created successfully",
webhookURL: result.webhookURL,
webhookID: result.webhookID,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
export class SolanaGetHeliusWebhookTool extends Tool {
name = "get_helius_webhook";
description = `Retrieves a Helius Webhook by its ID.
Inputs (input is a JSON string):
webhookID: string, e.g. "1ed4244d-a591-4854-ac31-cc28d40b8255"`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
protected async _call(input: string): Promise<string> {
try {
const parsedInput = JSON.parse(input);
const webhookID = parsedInput.webhookID;
if (!webhookID || typeof webhookID !== "string") {
throw new Error(
'Invalid input. Expected a "webhookID" property in the JSON.',
);
}
const result = await this.solanaKit.getWebhook(webhookID);
return JSON.stringify({
status: "success",
message: "Helius Webhook retrieved successfully",
wallet: result.wallet,
webhookURL: result.webhookURL,
transactionTypes: result.transactionTypes,
accountAddresses: result.accountAddresses,
webhookType: result.webhookType,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
export class SolanaDeleteHeliusWebhookTool extends Tool {
name = "delete_helius_webhook";
description = `Deletes a Helius Webhook by its ID.
Inputs (input is a JSON string):
webhookID: string, e.g. "1ed4244d-a591-4854-ac31-cc28d40b8255"`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
protected async _call(input: string): Promise<string> {
try {
const parsedInput = JSON.parse(input);
const webhookID = parsedInput.webhookID;
if (!webhookID || typeof webhookID !== "string") {
throw new Error(
'Invalid input. Expected a "webhookID" property in the JSON.',
);
}
const result = await this.solanaKit.deleteWebhook(webhookID);
return JSON.stringify({
status: "success",
message: "Helius Webhook deleted successfully",
data: result,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
export function createSolanaTools(solanaKit: SolanaAgentKit) {
return [
new SolanaBalanceTool(solanaKit),

View File

@@ -8,69 +8,17 @@ import {
LAMPORTS_PER_SOL,
} from "@solana/web3.js";
import bs58 from "bs58";
import { PriorityFeeTransaction } from "../types";
import { PriorityFeeTransaction, PriorityFeeResponse } from "../types";
/**
* Fetches an estimated priority fee (in microLamports) from Helius.
* Sends a transaction with an estimated priority fee using the provided SolanaAgentKit.
*
* @param agent An instance of SolanaAgentKit containing connection, wallet, etc.
* @param priorityLevel The priority level (e.g. "Min", "Low", "Medium", "High", "VeryHigh", or "UnsafeMax").
* @param transaction The (unsigned or partially-signed) Transaction you want to estimate fees for.
* @returns The numeric priority fee estimate in microLamports.
*/
export async function getPriorityFeeEstimate(
agent: SolanaAgentKit,
priorityLevel: string,
transaction: Transaction,
): Promise<number> {
const apiKey = agent.config.HELIUS_API_KEY;
if (!apiKey) {
throw new Error(
"HELIUS_API_KEY not found in agent.config or environment variables",
);
}
const url = `https://api.helius.xyz/v0/transactions/?api-key=${apiKey}`;
const payload = {
jsonrpc: "2.0",
id: "1",
method: "getPriorityFeeEstimate",
params: [
{
transaction: bs58.encode(transaction.serialize()),
options: { priorityLevel },
},
],
};
const response = await fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
if (!response.ok) {
throw new Error(`Helius request failed with status ${response.status}`);
}
const data = await response.json();
if (!data.result || data.result.priorityFeeEstimate === undefined) {
throw new Error(`Invalid response from Helius: ${JSON.stringify(data)}`);
}
return data.result.priorityFeeEstimate;
}
/**
* Sends a transaction with an optional priority fee using the provided SolanaAgentKit.
*
* @param agent An instance of SolanaAgentKit containing connection, wallet, etc.
* @param priorityLevel The priority level ("NONE", "Min", "Low", "Medium", "High", "VeryHigh", or "UnsafeMax").
* @param priorityLevel The priority level (e.g., "Min", "Low", "Medium", "High", "VeryHigh", or "UnsafeMax").
* @param amount The amount of SOL to send (in SOL, not lamports).
* @param to The recipient's PublicKey.
* @returns The transaction signature (string) once confirmed.
* @returns The transaction signature (string) once confirmed along with the fee used.
*/
export async function sendTransactionWithPriorityFee(
agent: SolanaAgentKit,
priorityLevel: string,
@@ -78,34 +26,53 @@ export async function sendTransactionWithPriorityFee(
to: PublicKey,
): Promise<PriorityFeeTransaction> {
const transaction = new Transaction();
const { blockhash, lastValidBlockHeight } =
await agent.connection.getLatestBlockhash();
transaction.recentBlockhash = blockhash;
transaction.lastValidBlockHeight = lastValidBlockHeight;
transaction.feePayer = agent.wallet_address;
const transferIx = SystemProgram.transfer({
fromPubkey: agent.wallet_address,
toPubkey: to,
lamports: amount * LAMPORTS_PER_SOL,
});
transaction.add(transferIx);
let feeEstimate = 0;
if (priorityLevel !== "NONE") {
feeEstimate = await getPriorityFeeEstimate(
agent,
priorityLevel,
transaction,
);
if (feeEstimate > 0) {
const computePriceIx = ComputeBudgetProgram.setComputeUnitPrice({
microLamports: feeEstimate,
});
transaction.add(computePriceIx);
}
}
transaction.recentBlockhash = (
await agent.connection.getLatestBlockhash()
).blockhash;
transaction.sign(agent.wallet);
const response = await fetch(
`https://mainnet.helius-rpc.com/?api-key=${agent.config.HELIUS_API_KEY}`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
jsonrpc: "2.0",
id: "1",
method: "getPriorityFeeEstimate",
params: [
{
transaction: bs58.encode(transaction.serialize()),
options: { priorityLevel: priorityLevel },
},
],
} as PriorityFeeResponse),
},
);
const data = await response.json();
if (data.error) {
throw new Error("Error fetching priority fee:");
}
const feeEstimate: number = data.result.priorityFeeEstimate;
// Set the priority fee if applicable
const computePriceIx = ComputeBudgetProgram.setComputeUnitPrice({
microLamports: feeEstimate,
});
transaction.add(computePriceIx);
// Send the transaction and confirm
const txSignature = await sendAndConfirmTransaction(
agent.connection,
transaction,

View File

@@ -255,3 +255,13 @@ export interface HeliusWebhookIdResponse {
accountAddresses: string[];
webhookType: string;
}
export interface PriorityFeeResponse {
jsonrpc: string;
id: string;
method: string;
params: Array<{
transaction: string;
options: { priorityLevel: string };
}>;
}