-
Notifications
You must be signed in to change notification settings - Fork 192
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
Initial version of js sdk for express relay #1281
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Ignored Deployments
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
express_relay/sdk/js/src/index.ts
Outdated
* @param bid_info Bid amount and valid until timestamp | ||
* @param privateKey Private key to sign the bid with | ||
*/ | ||
async signOpporunityBid( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo here: signOpportunityBid
throw new Error("No opportunities found"); | ||
} | ||
return opportunities.data.flatMap((opportunity) => { | ||
if (opportunity.version != "v1") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems odd to me that the version is a string "v1" and not a number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree that v prefix is odd, but it will become something similar to SemVer later on.
express_relay/sdk/js/src/index.ts
Outdated
/** | ||
* All the parameters necessary to represent a liquidation opportunity | ||
*/ | ||
export type OpportunityParams = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo Opportunity
would be a better name here. The current name sounds like the configuration parameters that you use to filter opportunities or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original rational here was to keep the names similar to the openapi schema names which reflects the backend structs. But I agree that Opportunity
is cleaner and users shouldn't see all the details we see in the backend :D
express_relay/sdk/js/src/index.ts
Outdated
/** | ||
* Unix timestamp for when the bid is no longer valid in seconds | ||
*/ | ||
valid_until: bigint; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these names intentionally in snake_case
? I think we usually use camelCase for everything in typescript
express_relay/sdk/js/src/index.ts
Outdated
* Fetches liquidation opportunities | ||
* @param chain_id Chain id to fetch opportunities for. e.g: sepolia | ||
*/ | ||
async getOpportunities(chain_id?: string): Promise<OpportunityParams[]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chain_id should be camelCase also
/** | ||
* This file was auto-generated by openapi-typescript. | ||
* Do not make direct changes to the file. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how did you generate this file? Can you put instructions for how to regenerate this (and when it's necessary) into the README?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may also be worthwhile to do the same thing for the ABI. Use cast inspect abi
on the contract and import that as a json file.
const opportunities = await client.getOpportunities(argv.chainId); | ||
console.log(`Fetched ${opportunities.length} opportunities`); | ||
for (const opportunity of opportunities) { | ||
const bid = BigInt(argv.bid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this probably shouldn't be an argument, since it depends on the details of the opportunity itself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just a knob that someone can play with when starting to test the scripts. I added a comment that this is not for production purposes
const bid = BigInt(argv.bid); | ||
const bidInfo = { | ||
amount: bid, | ||
valid_until: BigInt(Math.round(Date.now() / 1000 + 60 * 60 * 24)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe make this a variable outside of this object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Date.now() should be calculated each time, I refactored the constant part.
try { | ||
await client.submitOpportunityBid(opportunityBid); | ||
console.log( | ||
`Successful bid ${bid} on opportunity ${opportunity.opportunity_id}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've been thinking--we should also think about how to return to the searcher whether their transaction was included in a bundle and whether it succeeded. maybe some websocket on the auction server that broadcasts generally when a bundle is constructed and submitted and when it lands on chain, and broadcasts to specific searchers when their tx is included in a bundle (and privately relays their tx fulfillment back to them). not a note for this pr specifically but more generally
No description provided.