Skip to content

Commit 005706d

Browse files
committed
pass
1 parent 993c5f3 commit 005706d

File tree

2 files changed

+46
-35
lines changed

2 files changed

+46
-35
lines changed

pages/express-relay/integrate-as-searcher/evm.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ Pyth provides a Typescript SDK, which allows searchers to subscribe to opportuni
1717
```typescript
1818
import { Client, Opportunity } from "@pythnetwork/express-relay-js";
1919

20-
const handleOpporunity = async (opportunity: Opportunity) => {
20+
const handleOpportunity = async (opportunity: Opportunity) => {
2121
// Implement your opportunity handler here
2222
};
2323

2424
const client = new Client(
2525
{ baseUrl: "https://pyth-express-relay-mainnet.asymmetric.re" },
2626
undefined, // Default WebSocket options
27-
handleOpporunity
27+
handleOpportunity
2828
);
2929
await client.subscribeChains(["op_sepolia"]);
3030
```
@@ -175,7 +175,7 @@ Searchers can submit the constructed bids to Express Relay via the SDKs, an HTTP
175175
The code snippet below demonstrates how to submit a bid using the Typescript SDK:
176176

177177
```typescript {4} copy
178-
const handleOpporunity = async (opportunity: Opportunity) => {
178+
const handleOpportunity = async (opportunity: Opportunity) => {
179179
...
180180
const bid = await client.signBid(opportunity, {amount, nonce, deadline}, privateKey)
181181
await client.submitBid(bid)

pages/express-relay/integrate-as-searcher/svm.mdx

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -127,45 +127,48 @@ See the following examples of how to construct a bid object via the SDKs:
127127
Below is an excerpt of example code. See the full example in the [Typescript SDK](https://github.com/pyth-network/per/blob/4be711525948cf24c0ebd4ebab007dc7f51b7069/sdk/js/src/examples/simpleSearcherLimo.ts).
128128

129129
```typescript copy
130-
import { OpportunitySvm } from "../index";
131-
import { BidSvm } from "../types";
132-
133-
import * as anchor from "@coral-xyz/anchor";
134-
import * as limo from "@kamino-finance/limo-sdk";
135-
136-
/**
137-
* Generates a bid for a given opportunity. The transaction in this bid transfers assets from the searcher's wallet to fulfill the limit order.
138-
* @param opportunity The SVM opportunity to bid on
139-
* @returns The generated bid object
140-
*/
141-
async generateBid(opportunity: OpportunitySvm): Promise<BidSvm> {
130+
/**
131+
* Generates a bid for a given opportunity. The transaction in this bid transfers assets from the searcher's wallet to fulfill the limit order.
132+
* @param opportunity The SVM opportunity to bid on
133+
* @returns The generated bid object
134+
*/
135+
async generateBid(opportunity: OpportunitySvm): Promise<BidSvm> {
142136
const order = opportunity.order;
143137
const limoClient = new limo.LimoClient(
144138
this.connectionSvm,
145139
order.state.globalConfig
146140
);
147141

148142
const ixsTakeOrder = await this.generateTakeOrderIxs(limoClient, order);
149-
const txRaw = new anchor.web3.Transaction().add(...ixsTakeOrder);
143+
const feeInstruction = ComputeBudgetProgram.setComputeUnitPrice({
144+
microLamports:
145+
this.latestChainUpdate[this.chainId].latestPrioritizationFee,
146+
});
147+
const txRaw = new anchor.web3.Transaction().add(
148+
feeInstruction,
149+
...ixsTakeOrder
150+
);
150151

151-
const bidData = await this.getBidData(limoClient, order);
152+
const bidAmount = await this.getBidAmount(order);
152153

154+
const config = await this.getExpressRelayConfig();
153155
const bid = await this.client.constructSvmBid(
154156
txRaw,
155157
this.searcher.publicKey,
156-
bidData.router,
158+
getPdaAuthority(limoClient.getProgramID(), order.state.globalConfig),
157159
order.address,
158-
bidData.bidAmount,
160+
bidAmount,
159161
new anchor.BN(Math.round(Date.now() / 1000 + DAY_IN_SECONDS)),
160162
this.chainId,
161-
bidData.relayerSigner,
162-
bidData.relayerFeeReceiver
163+
config.relayerSigner,
164+
config.feeReceiverRelayer
163165
);
164166

165-
bid.transaction.recentBlockhash = this.recentBlockhash[this.chainId];
167+
bid.transaction.recentBlockhash =
168+
this.latestChainUpdate[this.chainId].blockhash;
166169
bid.transaction.sign(this.searcher);
167170
return bid;
168-
}
171+
}
169172
```
170173

171174
</Tabs.Tab>
@@ -193,24 +196,32 @@ async def assess_opportunity(self, opp: OpportunitySvm) -> BidSvm | None:
193196
A bid object if the opportunity is worth taking to be submitted to the Express Relay server, otherwise None.
194197
"""
195198
order: OrderStateAndAddress = {"address": opp.order_address, "state": opp.order}
199+
196200
ixs_take_order = await self.generate_take_order_ixs(order)
197-
bid_data = await self.get_bid_data(order)
201+
bid_amount = await self.get_bid_amount(order)
202+
router = self.limo_client.get_pda_authority(
203+
self.limo_client.get_program_id(), order["state"].global_config
204+
)
198205
199206
submit_bid_ix = self.client.get_svm_submit_bid_instruction(
200207
searcher=self.private_key.pubkey(),
201-
router=bid_data.router,
208+
router=router,
202209
permission_key=order["address"],
203-
bid_amount=bid_data.bid_amount,
210+
bid_amount=bid_amount,
204211
deadline=DEADLINE,
205212
chain_id=self.chain_id,
206-
fee_receiver_relayer=bid_data.relayer_fee_receiver,
207-
relayer_signer=bid_data.relayer_signer,
213+
fee_receiver_relayer=(await self.get_metadata()).fee_receiver_relayer,
214+
relayer_signer=(await self.get_metadata()).relayer_signer,
215+
)
216+
latest_chain_update = self.latest_chain_update[self.chain_id]
217+
fee_instruction = set_compute_unit_price(
218+
latest_chain_update.latest_prioritization_fee
208219
)
209220
transaction = Transaction.new_with_payer(
210-
[submit_bid_ix] + ixs_take_order, self.private_key.pubkey()
221+
[fee_instruction, submit_bid_ix] + ixs_take_order, self.private_key.pubkey()
211222
)
212223
transaction.partial_sign(
213-
[self.private_key], recent_blockhash=self.recent_blockhash[self.chain_id]
224+
[self.private_key], recent_blockhash=latest_chain_update.blockhash
214225
)
215226
bid = BidSvm(transaction=transaction, chain_id=self.chain_id)
216227
return bid
@@ -247,9 +258,9 @@ const generateBid = async (opportunity: OpportunitySvm, recentBlockhash: Blockha
247258
...
248259
}
249260
250-
const handleOpporunity = async (opportunity: Opportunity) => {
261+
const handleOpportunity = async (opportunity: Opportunity) => {
251262
...
252-
const bid = await generateBid(opportunity as OpportunitySvm, this.recentBlockhash[this.chainId]);
263+
const bid = await this.generateBid(opportunity as OpportunitySvm);
253264
await client.submitBid(bid);
254265
}
255266
```
@@ -266,7 +277,7 @@ async def generate_bid(opp: OpportunitySvm) -> BidSvm:
266277
...
267278
268279
def opportunity_callback(opportunity: Opportunity):
269-
bid = generate_bid(typing.cast(OpportunitySvm, opportunity))
280+
bid = await self.assess_opportunity(typing.cast(OpportunitySvm, opp))
270281
await client.submit_bid(bid, subscribe_to_updates=True)
271282
```
272283

@@ -278,7 +289,7 @@ Searchers can submit bids through an HTTP POST call to the [`/v1/bids`](https://
278289
curl -X POST https://pyth-express-relay-mainnet.asymmetric.re/v1/bids \
279290
-H "Content-Type: application/json" \
280291
-d '{
281-
"chain_id": "development-solana",
292+
"chain_id": "solana",
282293
"transaction": "SGVsbG8sIFdvcmxkIQ=="
283294
}'
284295
```
@@ -294,7 +305,7 @@ Searchers can submit bids via Websocket to avoid additional network round-trips
294305
"method": "post_bid",
295306
"params": {
296307
"bid": {
297-
"chain_id": "development-solana",
308+
"chain_id": "solana",
298309
"transaction": "SGVsbG8sIFdvcmxkIQ=="
299310
}
300311
}

0 commit comments

Comments
 (0)