-
Notifications
You must be signed in to change notification settings - Fork 43
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
improve: simulate relay gas fees for messages #862
Merged
james-a-morris
merged 26 commits into
master
from
james/acx-1571-estimate-fill-gas-costs-with-non-empty-message-fields
Oct 26, 2023
Merged
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
c9dc866
chore: add vercel as dev dep
james-a-morris 403499e
improve: simulate relay gas fees
james-a-morris b3efc79
chore: revert for another PR
james-a-morris 80cb76f
improve: throw error if recipient is not a contract
james-a-morris bb5925e
improve: change constructor imports
james-a-morris 2ae0db4
chore: bump sdk
james-a-morris 1abe39e
improve: ready for changes
james-a-morris 8ab4e64
chore: wrap error
james-a-morris 856bf67
chore: resolve check for hex string at first
james-a-morris e0ca8d2
improve: doc representation
james-a-morris a8e7c84
improve: error message
james-a-morris 703312b
improve: add token caching
james-a-morris 1d77eb5
chore: merge branch
james-a-morris bc6c8f7
chore: remove blockTag
james-a-morris 6821268
improve: use dummy address
james-a-morris fef8c7a
improve: remove blocktag reference. Always "latest"
james-a-morris 5b79022
chore: fix bug
james-a-morris 351f102
improve: remove account balance
james-a-morris aba05f7
improve: use recipient ZERO_ADDRESS
james-a-morris ac085a4
chore: change out comment
james-a-morris fd5dc96
improve: modify UI call
james-a-morris 1d6d0e6
chore: target block lag
james-a-morris b16d52d
chore: revise item
james-a-morris 572ce1e
improve: use optional param
james-a-morris 70bea1d
chore: revert optional params
james-a-morris 11c8552
fix: invalid signature call
james-a-morris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { VercelResponse } from "@vercel/node"; | ||
import { assert, Infer, type, string } from "superstruct"; | ||
import { TypedVercelRequest } from "./_types"; | ||
import { | ||
getBalance, | ||
getLogger, | ||
handleErrorCondition, | ||
validAddress, | ||
} from "./_utils"; | ||
|
||
const AccountBalanceQueryParamsSchema = type({ | ||
token: validAddress(), | ||
account: validAddress(), | ||
chainId: string(), | ||
}); | ||
|
||
type AccountBalanceQueryParams = Infer<typeof AccountBalanceQueryParamsSchema>; | ||
|
||
const handler = async ( | ||
{ query }: TypedVercelRequest<AccountBalanceQueryParams>, | ||
response: VercelResponse | ||
) => { | ||
const logger = getLogger(); | ||
logger.debug({ | ||
at: "AccountBalance", | ||
message: "Query data", | ||
query, | ||
}); | ||
try { | ||
// Validate the query parameters | ||
assert(query, AccountBalanceQueryParamsSchema); | ||
// Deconstruct the query parameters | ||
let { token, account, chainId } = query; | ||
// Rely on the utils to query the balance of either the native | ||
james-a-morris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// token or an ERC20 token. | ||
const balance = await getBalance(chainId, account, token); | ||
// Package the response | ||
const result = { | ||
balance: balance.toString(), | ||
account: account, | ||
token: token, | ||
}; | ||
// Log the response | ||
logger.debug({ | ||
at: "AccountBalance", | ||
message: "Response data", | ||
responseJson: result, | ||
}); | ||
// Set the caching headers that will be used by the CDN. | ||
response.setHeader( | ||
"Cache-Control", | ||
"s-maxage=150, stale-while-revalidate=150" | ||
); | ||
// Return the response | ||
response.status(200).json(result); | ||
} catch (error: unknown) { | ||
return handleErrorCondition("account-balance", response, logger, error); | ||
} | ||
}; | ||
|
||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this address hardcoded somewhere in the SDK?
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 see it is and you use the sdk constants in suggested-fees. In that case, why not make this a required param?
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 only usage of
constants
in the SDK is for the RelayerAddress. This is the recipient & it was added so that we only had to specify the dummy address in one location.I'm not sure adding a recipient address to the
/limits
would benefit the endpoint as this recipient is just needed to resolve the minimum deposit for a dummy fill request.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.
Resolved offline ^