Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
m30m committed Oct 9, 2024
1 parent 170d995 commit baf02f3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion express_relay/sdk/js/src/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export async function getSignature(
}

export async function signOpportunityBid(
opportunity: Opportunity & OpportunityEvm,
opportunity: OpportunityEvm,
bidParams: BidParams,
privateKey: Hex
): Promise<OpportunityBid> {
Expand Down
4 changes: 1 addition & 3 deletions express_relay/sdk/js/src/examples/simpleSearcherLimo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ class SimpleSearcherLimo {
}

async opportunityHandler(opportunity: Opportunity) {
if (!("order" in opportunity))
throw new Error("Not a valid SVM opportunity");
const bid = await this.generateBid(opportunity);
const bid = await this.generateBid(opportunity as OpportunitySvm);
try {
const bidId = await this.client.submitBid(bid);
console.log(
Expand Down
2 changes: 1 addition & 1 deletion express_relay/sdk/js/src/examples/simpleSearcherSvm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Program, AnchorProvider } from "@coral-xyz/anchor";
import { Keypair, PublicKey, Connection } from "@solana/web3.js";
import dummyIdl from "./idl/idlDummy.json";
import { Dummy } from "./dummyTypes";
import { getConfigRouterPda, getExpressRelayMetadataPda } from "../svmPda";
import { getConfigRouterPda, getExpressRelayMetadataPda } from "../svm";

const DAY_IN_SECONDS = 60 * 60 * 24;
const DUMMY_PIDS: Record<string, PublicKey> = {
Expand Down
14 changes: 7 additions & 7 deletions express_relay/sdk/js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
Opportunity,
OpportunityBid,
OpportunityEvm,
OpportunityParams,
OpportunityCreate,
TokenAmount,
} from "./types";
import {
Expand Down Expand Up @@ -256,7 +256,7 @@ export class Client {
* Submits an opportunity to be exposed to searchers
* @param opportunity Opportunity to submit
*/
async submitOpportunity(opportunity: OpportunityParams) {
async submitOpportunity(opportunity: OpportunityCreate) {
const client = createClient<paths>(this.clientOptions);
let body;
if ("order" in opportunity) {
Expand Down Expand Up @@ -439,22 +439,22 @@ export class Client {

/**
* Creates a signed opportunity bid for an opportunity
* @param opportunity Opportunity to bid on
* @param opportunity EVM Opportunity to bid on
* @param bidParams Bid amount and valid until timestamp
* @param privateKey Private key to sign the bid with
* @returns Signed opportunity bid
*/
async signOpportunityBid(
opportunity: Opportunity & OpportunityEvm,
opportunity: OpportunityEvm,
bidParams: BidParams,
privateKey: Hex
): Promise<OpportunityBid> {
return evm.signOpportunityBid(opportunity, bidParams, privateKey);
}

/**
* Creates a signed bid for an opportunity
* @param opportunity Opportunity to bid on
* Creates a signed bid for an EVM opportunity
* @param opportunity EVM Opportunity to bid on
* @param bidParams Bid amount, nonce, and deadline timestamp
* @param privateKey Private key to sign the bid with
* @returns Signed bid
Expand All @@ -469,7 +469,7 @@ export class Client {

/**
* Creates a signature for the bid and opportunity
* @param opportunity Opportunity to bid on
* @param opportunity EVM Opportunity to bid on
* @param bidParams Bid amount, nonce, and deadline timestamp
* @param privateKey Private key to sign the bid with
* @returns Signature for the bid and opportunity
Expand Down
21 changes: 16 additions & 5 deletions express_relay/sdk/js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ export type OpportunityEvm = {
* Tokens to receive after the opportunity is executed
*/
buyTokens: TokenAmount[];
/**
* Unique identifier for the opportunity
*/
opportunityId: string;
};

export type OpportunitySvm = {
Expand All @@ -102,18 +106,25 @@ export type OpportunitySvm = {
* The chain id where the opportunity will be executed.
*/
chainId: ChainId;
/**
* Slot where the opportunity was found
*/
slot: number;
/**
* Blockhash that can be used to sign transactions for this opportunity
*/
blockHash: Blockhash;
};

export type OpportunityParams = OpportunityEvm | OpportunitySvm;

export type Opportunity = OpportunityParams & {
/**
* Unique identifier for the opportunity
*/
opportunityId: string;
};

export type OpportunityCreate =
| Omit<OpportunityEvm, "opportunity_id">
| Omit<OpportunitySvm, "opportunity_id">;

export type Opportunity = OpportunityEvm | OpportunitySvm;
/**
* Represents a bid for an opportunity
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import asyncio
import logging
import typing
from decimal import Decimal

from solana.rpc.async_api import AsyncClient
Expand All @@ -18,7 +19,6 @@
BidStatusUpdate,
BidSvm,
Opportunity,
OpportunityEvm,
)
from express_relay.express_relay_svm_types import OpportunitySvm
from express_relay.svm.generated.express_relay.accounts import ExpressRelayMetadata
Expand Down Expand Up @@ -71,11 +71,7 @@ async def opportunity_callback(self, opp: Opportunity):
Args:
opp: An object representing a single opportunity.
"""

if isinstance(opp, OpportunityEvm):
raise ValueError("Opportunity is not an SVM opportunity")

bid = await self.assess_opportunity(opp)
bid = await self.assess_opportunity(typing.cast(OpportunitySvm, opp))

if bid:
try:
Expand Down

0 comments on commit baf02f3

Please sign in to comment.