Skip to content
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

Merged
merged 3 commits into from
Feb 8, 2024
Merged

Conversation

m30m
Copy link
Collaborator

@m30m m30m commented Feb 7, 2024

No description provided.

Copy link

vercel bot commented Feb 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
example-oracle-amm ⬜️ Ignored (Inspect) Visit Preview Feb 8, 2024 9:46am
xc-admin-frontend ⬜️ Ignored (Inspect) Visit Preview Feb 8, 2024 9:46am

Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

* @param bid_info Bid amount and valid until timestamp
* @param privateKey Private key to sign the bid with
*/
async signOpporunityBid(
Copy link
Contributor

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") {
Copy link
Contributor

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

Copy link
Collaborator Author

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.

/**
* All the parameters necessary to represent a liquidation opportunity
*/
export type OpportunityParams = {
Copy link
Contributor

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.

Copy link
Collaborator Author

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

/**
* Unix timestamp for when the bid is no longer valid in seconds
*/
valid_until: bigint;
Copy link
Contributor

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

* Fetches liquidation opportunities
* @param chain_id Chain id to fetch opportunities for. e.g: sepolia
*/
async getOpportunities(chain_id?: string): Promise<OpportunityParams[]> {
Copy link
Contributor

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.
*/
Copy link
Contributor

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?

Copy link
Contributor

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);
Copy link
Contributor

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

Copy link
Collaborator Author

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)),
Copy link
Contributor

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

Copy link
Collaborator Author

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}`
Copy link
Contributor

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

@m30m m30m merged commit 5c8e372 into main Feb 8, 2024
5 checks passed
@m30m m30m deleted the express-relay-js-sdk branch February 8, 2024 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants