From b7da67bc5c69706f8e69aaa649d5edfec4385be7 Mon Sep 17 00:00:00 2001 From: John Mitsch Date: Tue, 19 Mar 2024 21:48:38 -0300 Subject: [PATCH] Don't repeat simulateTransaction (#123) * Don't repeat simulateTransaction * update tests --- .../recording.har | 20 +++++++++---------- .../recording.har | 20 +++++++++---------- packages/libs/sdk/src/solana/solana.ts | 18 +++++------------ 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/packages/libs/sdk/spec/recordings/solana-client-prepareSmartTransaction_3623416322/recording.har b/packages/libs/sdk/spec/recordings/solana-client-prepareSmartTransaction_3623416322/recording.har index 97e8b0c1..31d6b12e 100644 --- a/packages/libs/sdk/spec/recordings/solana-client-prepareSmartTransaction_3623416322/recording.har +++ b/packages/libs/sdk/spec/recordings/solana-client-prepareSmartTransaction_3623416322/recording.har @@ -256,11 +256,11 @@ } }, { - "_id": "e2c784fd4c9b57d1393ff5435469c698", + "_id": "0875a10313acc94fe3ab671e0fd7b894", "_order": 0, "cache": {}, "request": { - "bodySize": 432, + "bodySize": 416, "cookies": [], "headers": [ { @@ -281,7 +281,7 @@ { "_fromType": "array", "name": "content-length", - "value": "432" + "value": "416" }, { "_fromType": "array", @@ -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" @@ -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": [ @@ -344,7 +344,7 @@ }, { "name": "x-host-id", - "value": "91451cb2e1d47651" + "value": "6f1b845d154ece71" }, { "name": "x-node-id", @@ -352,7 +352,7 @@ }, { "name": "date", - "value": "Tue, 19 Mar 2024 14:22:31 GMT" + "value": "Wed, 20 Mar 2024 00:37:00 GMT" }, { "name": "content-length", @@ -365,8 +365,8 @@ "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, @@ -374,7 +374,7 @@ "receive": 0, "send": 0, "ssl": -1, - "wait": 127 + "wait": 811 } } ], diff --git a/packages/libs/sdk/spec/recordings/solana-client-sendSmartTransaction_2450286823/recording.har b/packages/libs/sdk/spec/recordings/solana-client-sendSmartTransaction_2450286823/recording.har index 722befcb..7ebbd0c2 100644 --- a/packages/libs/sdk/spec/recordings/solana-client-sendSmartTransaction_2450286823/recording.har +++ b/packages/libs/sdk/spec/recordings/solana-client-sendSmartTransaction_2450286823/recording.har @@ -378,11 +378,11 @@ } }, { - "_id": "52456b29349dfd0a6b81e7808606af48", + "_id": "220ca660d418a27720eee2415340c125", "_order": 0, "cache": {}, "request": { - "bodySize": 432, + "bodySize": 416, "cookies": [], "headers": [ { @@ -403,7 +403,7 @@ { "_fromType": "array", "name": "content-length", - "value": "432" + "value": "416" }, { "_fromType": "array", @@ -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" @@ -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": [ @@ -466,7 +466,7 @@ }, { "name": "x-host-id", - "value": "5ff44affcb12501b" + "value": "6cd8c45b4aaa6609" }, { "name": "x-node-id", @@ -474,7 +474,7 @@ }, { "name": "date", - "value": "Tue, 19 Mar 2024 14:22:52 GMT" + "value": "Wed, 20 Mar 2024 00:37:33 GMT" }, { "name": "content-length", @@ -487,8 +487,8 @@ "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, @@ -496,7 +496,7 @@ "receive": 0, "send": 0, "ssl": -1, - "wait": 660 + "wait": 471 } } ], diff --git a/packages/libs/sdk/src/solana/solana.ts b/packages/libs/sdk/src/solana/solana.ts index 990ee518..6f002568 100644 --- a/packages/libs/sdk/src/solana/solana.ts +++ b/packages/libs/sdk/src/solana/solana.ts @@ -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 = [ @@ -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(), ]); @@ -133,16 +130,11 @@ export class Solana { private async getSimulationUnits( connection: Connection, instructions: TransactionInstruction[], - publicKey: PublicKey, - feeLevel: PriorityFeeLevels + publicKey: PublicKey ): Promise { - 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()