Skip to content

Commit a08be17

Browse files
authored
chore: improve landing rate in examples (#2162)
* do it * need to update readme * go * go
1 parent f6ea5c2 commit a08be17

File tree

6 files changed

+38
-15
lines changed

6 files changed

+38
-15
lines changed

target_chains/solana/sdk/js/pyth_solana_receiver/README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Instantiate it with a Solana web3 `Connection` and anchor `Wallet`:
6565
import { PythSolanaReceiver } from "@pythnetwork/pyth-solana-receiver";
6666
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
6767
import { Wallet } from "@coral-xyz/anchor";
68+
import { sendTransactions } from "@pythnetwork/solana-utils";
6869

6970
const connection = new Connection("https://api.mainnet-beta.solana.com");
7071
const wallet = new Wallet(
@@ -101,10 +102,15 @@ await transactionBuilder.addPriceConsumerInstructions(
101102

102103
// Send the instructions in the builder in 1 or more transactions.
103104
// The builder will pack the instructions into transactions automatically.
104-
await pythSolanaReceiver.provider.sendAll(
105+
// We use some custom transaction dispatch logic instead of the simple `provider.sendAll` to increase landing rate,
106+
// feel free to use your own optimized logic.
107+
sendTransactions(
105108
await transactionBuilder.buildVersionedTransactions({
106109
computeUnitPriceMicroLamports: 100000,
107-
})
110+
tightComputeBudget: true,
111+
}),
112+
pythSolanaReceiver.connection,
113+
pythSolanaReceiver.wallet
108114
);
109115
```
110116

@@ -137,10 +143,15 @@ await transactionBuilder.addPriceConsumerInstructions(
137143

138144
// Send the instructions in the builder in 1 or more transactions.
139145
// The builder will pack the instructions into transactions automatically.
140-
await pythSolanaReceiver.provider.sendAll(
146+
// We use some custom transaction dispatch logic instead of the simple `provider.sendAll` to increase landing rate,
147+
// feel free to use your own optimized logic.
148+
sendTransactions(
141149
await transactionBuilder.buildVersionedTransactions({
142150
computeUnitPriceMicroLamports: 100000,
143-
})
151+
tightComputeBudget: true,
152+
}),
153+
pythSolanaReceiver.connection,
154+
pythSolanaReceiver.wallet
144155
);
145156
```
146157

target_chains/solana/sdk/js/pyth_solana_receiver/examples/post_price_update.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Wallet } from "@coral-xyz/anchor";
44
import fs from "fs";
55
import os from "os";
66
import { HermesClient } from "@pythnetwork/hermes-client";
7+
import { sendTransactions } from "@pythnetwork/solana-utils";
78

89
// Get price feed ids from https://pyth.network/developers/price-feed-ids#pyth-evm-stable
910
const SOL_PRICE_FEED_ID =
@@ -57,11 +58,13 @@ async function main() {
5758

5859
// Send the instructions in the builder in 1 or more transactions.
5960
// The builder will pack the instructions into transactions automatically.
60-
await pythSolanaReceiver.provider.sendAll(
61+
sendTransactions(
6162
await transactionBuilder.buildVersionedTransactions({
6263
computeUnitPriceMicroLamports: 100000,
64+
tightComputeBudget: true,
6365
}),
64-
{ preflightCommitment: "processed" }
66+
pythSolanaReceiver.connection,
67+
pythSolanaReceiver.wallet
6568
);
6669
}
6770

target_chains/solana/sdk/js/pyth_solana_receiver/examples/post_price_update_from_benchmarks.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { InstructionWithEphemeralSigners, PythSolanaReceiver } from "../";
44
import { Wallet } from "@coral-xyz/anchor";
55
import fs from "fs";
66
import os from "os";
7+
import { sendTransactions } from "@pythnetwork/solana-utils";
78

89
// Get price feed ids from https://pyth.network/developers/price-feed-ids#pyth-evm-stable
910
const SOL_PRICE_FEED_ID =
@@ -55,11 +56,13 @@ async function main() {
5556

5657
// Send the instructions in the builder in 1 or more transactions.
5758
// The builder will pack the instructions into transactions automatically.
58-
await pythSolanaReceiver.provider.sendAll(
59+
sendTransactions(
5960
await transactionBuilder.buildVersionedTransactions({
6061
computeUnitPriceMicroLamports: 100000,
62+
tightComputeBudget: true,
6163
}),
62-
{ preflightCommitment: "processed" }
64+
pythSolanaReceiver.connection,
65+
pythSolanaReceiver.wallet
6366
);
6467
}
6568

target_chains/solana/sdk/js/pyth_solana_receiver/examples/post_price_update_instructions.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Wallet } from "@coral-xyz/anchor";
44
import fs from "fs";
55
import os from "os";
66
import { HermesClient } from "@pythnetwork/hermes-client";
7+
import { sendTransactions } from "@pythnetwork/solana-utils";
78

89
// Get price feed ids from https://pyth.network/developers/price-feed-ids#pyth-evm-stable
910
const SOL_PRICE_FEED_ID =
@@ -49,11 +50,13 @@ async function main() {
4950

5051
const transactions = await pythSolanaReceiver.batchIntoVersionedTransactions(
5152
[...postInstructions, ...consumerInstructions, ...closeInstructions],
52-
{ computeUnitPriceMicroLamports: 100000 }
53+
{ computeUnitPriceMicroLamports: 100000, tightComputeBudget: true }
5354
); // Put all the instructions together
54-
await pythSolanaReceiver.provider.sendAll(transactions, {
55-
preflightCommitment: "processed",
56-
});
55+
await sendTransactions(
56+
transactions,
57+
pythSolanaReceiver.connection,
58+
pythSolanaReceiver.wallet
59+
);
5760
}
5861

5962
// Fetch price update data from Hermes

target_chains/solana/sdk/js/pyth_solana_receiver/examples/update_price_feed.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Wallet } from "@coral-xyz/anchor";
44
import fs from "fs";
55
import os from "os";
66
import { HermesClient } from "@pythnetwork/hermes-client";
7+
import { sendTransactions } from "@pythnetwork/solana-utils";
78

89
// Get price feed ids from https://pyth.network/developers/price-feed-ids#pyth-evm-stable
910
const SOL_PRICE_FEED_ID =
@@ -57,11 +58,13 @@ async function main() {
5758

5859
// Send the instructions in the builder in 1 or more transactions.
5960
// The builder will pack the instructions into transactions automatically.
60-
await pythSolanaReceiver.provider.sendAll(
61+
sendTransactions(
6162
await transactionBuilder.buildVersionedTransactions({
6263
computeUnitPriceMicroLamports: 100000,
64+
tightComputeBudget: true,
6365
}),
64-
{ preflightCommitment: "processed" }
66+
pythSolanaReceiver.connection,
67+
pythSolanaReceiver.wallet
6568
);
6669
}
6770

target_chains/solana/sdk/js/pyth_solana_receiver/src/PythSolanaReceiver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export type PythTransactionBuilderConfig = {
9191
* console.log("The SOL/USD price update will get posted to:", transactionBuilder.getPriceUpdateAccount(SOL_PRICE_FEED_ID).toBase58())
9292
* await transactionBuilder.addPriceConsumerInstructions(...)
9393
*
94-
* await pythSolanaReceiver.provider.sendAll(await transactionBuilder.buildVersionedTransactions({computeUnitPriceMicroLamports:100000}))
94+
* await pythSolanaReceiver.provider.sendAll(await transactionBuilder.buildVersionedTransactions({computeUnitPriceMicroLamports:100000, tightComputeBudget: true}))
9595
* ```
9696
*/
9797
export class PythTransactionBuilder extends TransactionBuilder {

0 commit comments

Comments
 (0)