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

feat: Script for interacting with SpokePools #854

Merged
merged 28 commits into from
Sep 4, 2023
Merged

Conversation

pxrl
Copy link
Contributor

@pxrl pxrl commented Aug 7, 2023

This is useful for various SpokePool-related activities:

  • Make a deposit
  • Retrieve information about deposit(s) and/or fill(s) from a transaction.
  • Dump basic SpokePool configuration information.

This is especially handy with the new zkSync SpokePool, because zkSync's block explorer doesn't yet support making transactions via proxy contracts, and doesn't decode Across SpokePool events properly either.

Example:

# Deposit .001 WETH on Ethereum Görli, destined for zkSync era Görli. 
$ yarn ts-node ./scripts/spokepool.ts deposit --wallet mnemonic --from 5 --to 280 --token weth --amount 0.001

This is useful for making deposits to the zkSync SpokePool(s) because
zkSync's block explorer doesn't yet support making transactions via
proxy contracts.
@pxrl pxrl force-pushed the pxrl/depositScript branch from 692477b to 4b1bb8a Compare August 7, 2023 12:33
@pxrl
Copy link
Contributor Author

pxrl commented Aug 7, 2023

Example output:

Submitting deposit on chain ID 5
        originChainId       : 5
        destinationChainId  : 280
        depositor           : 0x9A8f92a830A5cB89a3816e3D267CB7791c16b04D
        recipient           : 0x9A8f92a830A5cB89a3816e3D267CB7791c16b04D
        relayerFeePct       : 0
        quoteTimestamp      : 1691411700

Submitted deposit:
        depositId           : 100019
        transactionHash     : 0x1fa909fea87e41c865555559719ff25a5e6c3cd4e1af61da7d4ed02c6f3f3322

Done in 25.11s.

Copy link
Contributor

@james-a-morris james-a-morris left a comment

Choose a reason for hiding this comment

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

Left a few nits

scripts/spokepool.ts Outdated Show resolved Hide resolved
scripts/spokepool.ts Show resolved Hide resolved
scripts/spokepool.ts Show resolved Hide resolved
Copy link
Member

@nicholaspai nicholaspai left a comment

Choose a reason for hiding this comment

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

High level comment: can we make this script's name more clear (or do you intend to add other helper SpokePool related functions in here?) or add a helpful comment at the top explaining why this would be used?

@pxrl
Copy link
Contributor Author

pxrl commented Aug 7, 2023

High level comment: can we make this script's name more clear (or do you intend to add other helper SpokePool related functions in here?) or add a helpful comment at the top explaining why this would be used?

Generally yes - I'd like to support something like the following:

spokepool.ts deposit <deposit-args>
spokepool.ts fill --origin <chainId> --hash <depositHash>
spokepool.ts request-refund <refund-args>

I left a placeholder in the code for adding fill support, but I didn't want to spend any time on actually implementing it now given other priorities: https://github.com/across-protocol/relayer-v2/blob/4b1bb8a633f87a6f34ee2602cf217d3a80a29c45/scripts/spokepool.ts#L165

As general background, it's occurred to me that I miss a good set of cmdline utilities for interacting with our contracts, since it should be possible to execute (or query) standard operations against them without a block explorer (a la zkSync at the moment), and without having to modify code or .env configs.

@nicholaspai
Copy link
Member

High level comment: can we make this script's name more clear (or do you intend to add other helper SpokePool related functions in here?) or add a helpful comment at the top explaining why this would be used?

Generally yes - I'd like to support something like the following:

spokepool.ts deposit <deposit-args> spokepool.ts fill --origin <chainId> --hash <depositHash> spokepool.ts request-refund <refund-args>

I left a placeholder in the code for adding fill support, but I didn't want to spend any time on actually implementing it now given other priorities:

https://github.com/across-protocol/relayer-v2/blob/4b1bb8a633f87a6f34ee2602cf217d3a80a29c45/scripts/spokepool.ts#L165

As general background, it's occurred to me that I miss a good set of cmdline utilities for interacting with our contracts, since it should be possible to execute (or query) standard operations against them without a block explorer (a la zkSync at the moment), and without having to modify code or .env configs.

This would be a good interface yes

@pxrl pxrl requested a review from james-a-morris August 7, 2023 20:40
Copy link
Contributor

@james-a-morris james-a-morris left a comment

Choose a reason for hiding this comment

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

Two more comments

scripts/spokepool.ts Show resolved Hide resolved
scripts/spokepool.ts Outdated Show resolved Hide resolved
pxrl added 2 commits August 16, 2023 16:07
Not all tokens are defined on all chains, so don't try to drop case
unless the token actually exists on a chain.
Currently limitations:
 - Does not display updated values (i.e. after a speed-up).
 - Does not display message data.
 - Should normalise from the token decimals for better readability.
 - Does not gracefully handle when the txnHash is not found.
@pxrl pxrl changed the title feat: Script for automating SpokePool deposits feat: Script for interacting with SpokePools Aug 16, 2023
nicholaspai and others added 7 commits August 22, 2023 10:03
Copy link
Contributor

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

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

Great place to start! Always todos and things to add/change, but this is great!

const padLeft = 20;
const padRight = 25;

function formatAddress(address: string, maxWidth = 18): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just display full addresses?

Copy link
Contributor Author

@pxrl pxrl Sep 4, 2023

Choose a reason for hiding this comment

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

Maybe this is just my OCD, but it looks really awkward to have a long address alongside a bunch of significantly shorter values. Some of the values look best right-justified (especially fields with a numerical relationship to each other - i.e. relayerFeePct and amount). Making these right-justified alongside the address means that the values end up very far away from the keys/field names, and that can make it difficult to visually connect them.

I was thinking about adding a -v flag to allow the caller to force the address to be displayed in full.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ended up scrapping the custom formatting and reverted to "raw" dumping of the event. This removes some of the (imo) nice features like grouping related fields, which the SpokePool event data doesn't always do. However, it's very simple and generic, and ensures that all the fields are dumped. Maybe in future I'll introduce a way of ordering the fields, but that's not worth prioritising now.

caccd7b

Comment on lines 133 to 137
const depositor = await signer.getAddress();
const fromChainId = Number(args.from);
const toChainId = Number(args.to);
const recipient = args.recipient ?? depositor;
const baseAmount = Number(args.amount);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we validate args here and throw if they aren't provided as expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented: ea24ac1

scripts/spokepool.ts Show resolved Hide resolved
@pxrl pxrl merged commit 87a704c into master Sep 4, 2023
2 checks passed
@pxrl pxrl deleted the pxrl/depositScript branch September 4, 2023 15:58
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.

4 participants