Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't repeat simulateTransaction #123

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@
}
},
{
"_id": "e2c784fd4c9b57d1393ff5435469c698",
"_id": "0875a10313acc94fe3ab671e0fd7b894",
"_order": 0,
"cache": {},
"request": {
"bodySize": 432,
"bodySize": 416,
"cookies": [],
"headers": [
{
Expand All @@ -281,7 +281,7 @@
{
"_fromType": "array",
"name": "content-length",
"value": "432"
"value": "416"
},
{
"_fromType": "array",
Expand All @@ -304,7 +304,7 @@
"postData": {
"mimeType": "application/json",
"params": [],
"text": "{\"method\":\"simulateTransaction\",\"jsonrpc\":\"2.0\",\"params\":[\"AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQABAoQRxzJRFnXCoe6MBldnTlUf1q55/eUmCQ4F8R2+2mMoAwZGb+UhFzL/7K26csOb57yM5bvF9xJrLEObOkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIBAAkDF5cAAAAAAAABAAkDF5cAAAAAAAAA\",{\"replaceRecentBlockhash\":true,\"sigVerify\":false,\"encoding\":\"base64\"}],\"id\":\"68b1d6e0-4ef4-4be3-b649-20d4b22f009b\"}"
"text": "{\"method\":\"simulateTransaction\",\"jsonrpc\":\"2.0\",\"params\":[\"AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQABAoQRxzJRFnXCoe6MBldnTlUf1q55/eUmCQ4F8R2+2mMoAwZGb+UhFzL/7K26csOb57yM5bvF9xJrLEObOkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAAkDF5cAAAAAAAAA\",{\"replaceRecentBlockhash\":true,\"sigVerify\":false,\"encoding\":\"base64\"}],\"id\":\"3c3df6dd-e35b-41ed-af11-68882bb8fb00\"}"
},
"queryString": [],
"url": "https://alien-lingering-fire.solana-mainnet.quiknode.pro"
Expand All @@ -314,7 +314,7 @@
"content": {
"mimeType": "application/json",
"size": 221,
"text": "{\"jsonrpc\":\"2.0\",\"result\":{\"context\":{\"apiVersion\":\"1.17.26\",\"slot\":255150758},\"value\":{\"accounts\":null,\"err\":\"AccountNotFound\",\"logs\":[],\"returnData\":null,\"unitsConsumed\":0}},\"id\":\"68b1d6e0-4ef4-4be3-b649-20d4b22f009b\"}\n"
"text": "{\"jsonrpc\":\"2.0\",\"result\":{\"context\":{\"apiVersion\":\"1.17.26\",\"slot\":255238437},\"value\":{\"accounts\":null,\"err\":\"AccountNotFound\",\"logs\":[],\"returnData\":null,\"unitsConsumed\":0}},\"id\":\"3c3df6dd-e35b-41ed-af11-68882bb8fb00\"}\n"
},
"cookies": [],
"headers": [
Expand Down Expand Up @@ -344,15 +344,15 @@
},
{
"name": "x-host-id",
"value": "91451cb2e1d47651"
"value": "6f1b845d154ece71"
},
{
"name": "x-node-id",
"value": "solana_solana-mainnet_jfk"
},
{
"name": "date",
"value": "Tue, 19 Mar 2024 14:22:31 GMT"
"value": "Wed, 20 Mar 2024 00:37:00 GMT"
},
{
"name": "content-length",
Expand All @@ -365,16 +365,16 @@
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2024-03-19T14:22:31.297Z",
"time": 127,
"startedDateTime": "2024-03-20T00:36:59.488Z",
"time": 811,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 127
"wait": 811
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,11 @@
}
},
{
"_id": "52456b29349dfd0a6b81e7808606af48",
"_id": "220ca660d418a27720eee2415340c125",
"_order": 0,
"cache": {},
"request": {
"bodySize": 432,
"bodySize": 416,
"cookies": [],
"headers": [
{
Expand All @@ -403,7 +403,7 @@
{
"_fromType": "array",
"name": "content-length",
"value": "432"
"value": "416"
},
{
"_fromType": "array",
Expand All @@ -426,7 +426,7 @@
"postData": {
"mimeType": "application/json",
"params": [],
"text": "{\"method\":\"simulateTransaction\",\"jsonrpc\":\"2.0\",\"params\":[\"AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQABAoQRxzJRFnXCoe6MBldnTlUf1q55/eUmCQ4F8R2+2mMoAwZGb+UhFzL/7K26csOb57yM5bvF9xJrLEObOkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIBAAkDVZIAAAAAAAABAAkDVZIAAAAAAAAA\",{\"replaceRecentBlockhash\":true,\"sigVerify\":false,\"encoding\":\"base64\"}],\"id\":\"8a4c3a0f-8dad-4315-9764-966930cc4ba6\"}"
"text": "{\"method\":\"simulateTransaction\",\"jsonrpc\":\"2.0\",\"params\":[\"AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQABAoQRxzJRFnXCoe6MBldnTlUf1q55/eUmCQ4F8R2+2mMoAwZGb+UhFzL/7K26csOb57yM5bvF9xJrLEObOkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAAkDVZIAAAAAAAAA\",{\"replaceRecentBlockhash\":true,\"sigVerify\":false,\"encoding\":\"base64\"}],\"id\":\"e1e3d1a4-e828-41e7-983e-7855e576ae38\"}"
},
"queryString": [],
"url": "https://alien-lingering-fire.solana-mainnet.quiknode.pro"
Expand All @@ -436,7 +436,7 @@
"content": {
"mimeType": "application/json",
"size": 221,
"text": "{\"jsonrpc\":\"2.0\",\"result\":{\"context\":{\"apiVersion\":\"1.17.26\",\"slot\":255150812},\"value\":{\"accounts\":null,\"err\":\"AccountNotFound\",\"logs\":[],\"returnData\":null,\"unitsConsumed\":0}},\"id\":\"8a4c3a0f-8dad-4315-9764-966930cc4ba6\"}\n"
"text": "{\"jsonrpc\":\"2.0\",\"result\":{\"context\":{\"apiVersion\":\"1.17.26\",\"slot\":255238517},\"value\":{\"accounts\":null,\"err\":\"AccountNotFound\",\"logs\":[],\"returnData\":null,\"unitsConsumed\":0}},\"id\":\"e1e3d1a4-e828-41e7-983e-7855e576ae38\"}\n"
},
"cookies": [],
"headers": [
Expand Down Expand Up @@ -466,15 +466,15 @@
},
{
"name": "x-host-id",
"value": "5ff44affcb12501b"
"value": "6cd8c45b4aaa6609"
},
{
"name": "x-node-id",
"value": "solana_solana-mainnet_jfk"
},
{
"name": "date",
"value": "Tue, 19 Mar 2024 14:22:52 GMT"
"value": "Wed, 20 Mar 2024 00:37:33 GMT"
},
{
"name": "content-length",
Expand All @@ -487,16 +487,16 @@
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2024-03-19T14:22:52.133Z",
"time": 660,
"startedDateTime": "2024-03-20T00:37:32.998Z",
"time": 471,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 660
"wait": 471
}
}
],
Expand Down
18 changes: 5 additions & 13 deletions packages/libs/sdk/src/solana/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export class Solana {
*/
async prepareSmartTransaction(args: PrepareSmartTransactionArgs) {
const { transaction, payerPublicKey, feeLevel = 'medium' } = args;
// Need to fetch this ahead of time and add to transaction so it's in the transaction instructions
// for the simulation
const computeUnitPriceInstruction =
await this.createDynamicPriorityFeeInstruction(feeLevel);
const allInstructions = [
Expand All @@ -68,12 +70,7 @@ export class Solana {

// eslint-disable-next-line prefer-const
let [units, recentBlockhash] = await Promise.all([
this.getSimulationUnits(
this.connection,
allInstructions,
payerPublicKey,
feeLevel
),
this.getSimulationUnits(this.connection, allInstructions, payerPublicKey),
this.connection.getLatestBlockhash(),
]);

Expand Down Expand Up @@ -133,16 +130,11 @@ export class Solana {
private async getSimulationUnits(
connection: Connection,
instructions: TransactionInstruction[],
publicKey: PublicKey,
feeLevel: PriorityFeeLevels
publicKey: PublicKey
): Promise<number | undefined> {
const computeUnitPriceInstruction =
await this.createDynamicPriorityFeeInstruction(feeLevel);
const testInstructions = [...instructions, computeUnitPriceInstruction];

const testVersionedTxn = new VersionedTransaction(
new TransactionMessage({
instructions: testInstructions,
instructions: instructions,
payerKey: publicKey,
recentBlockhash: PublicKey.default.toString(), // just a placeholder
}).compileToV0Message()
Expand Down
Loading