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: ergonomic IGP configuration in CLI #4635

Merged
merged 7 commits into from
Oct 28, 2024
Merged

feat: ergonomic IGP configuration in CLI #4635

merged 7 commits into from
Oct 28, 2024

Conversation

paulbalaji
Copy link
Contributor

@paulbalaji paulbalaji commented Oct 7, 2024

Description

Re-adding the ability to generate IGP hook configs using the CLI, but repurposing logic found in infra to make the configuration experience more ergonomic. Logic still behind the --advanced flag.

Enabling this allows IGP configuration in any place that supports hook config e.g. core/warp/hook init with --advanced.

We will use metadata in registry to:

  1. fetch price from Coingecko (prompt user if unable to find)
  2. fetch current gas prices via the default RPCs
  3. request user to enter an IGP margin in %
  4. Calculate the gasPrice + tokenExchangeRate for you

Note that it still sets overhead to some preexisting default.

? Select hook type interchainGasPaymaster
Creating interchainGasPaymaster...
? Detected owner address as 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 from signer, is this
correct? yes
? Use this same address for the beneficiary? yes
? Select network type Mainnet
? Select local chain for IGP hook bitlayer
? Select remote destination chains for IGP hook alephzero, ancient8
? Enter overhead for alephzero (e.g., 75000) for IGP hook 75000
? Enter overhead for ancient8 (e.g., 75000) for IGP hook 75000
Getting gas token prices for all chains from Coingecko...
Gas price for alephzero is 40.0
Gas token price for alephzero is $0.393347
Gas price for ancient8 is 0.001000252
Gas token price for ancient8 is $2356.71
Gas price for bitlayer is 0.050000007
Gas token price for bitlayer is $60576
? Enter IGP margin percentage (e.g. 10 for 10%) 100
Created interchainGasPaymaster!
Core config is valid, writing to file ./configs/core-config.yaml:

    owner: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
    defaultIsm:
      type: trustedRelayerIsm
      relayer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
    defaultHook:
      type: aggregationHook
      hooks:
        - type: merkleTreeHook
        - owner: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
          type: interchainGasPaymaster
          beneficiary: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
          oracleKey: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
          overhead:
            alephzero: 75000
            ancient8: 75000
          oracleConfig:
            alephzero:
              gasPrice: "40000000000"
              tokenExchangeRate: "129868"
            ancient8:
              gasPrice: "1000253"
              tokenExchangeRate: "778100236"
    requiredHook:
      owner: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
      type: protocolFee
      beneficiary: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
      maxProtocolFee: "1000000000000000000"
      protocolFee: "0"

✅ Successfully created new core deployment config.

Drive-by changes

Moving reusable infra logic into the SDK, and refactoring CLI+Infra to reuse the underlying logic. For example:

  • fetching token prices from coingecko
  • fetching gas prices using a chain's RPC

Related issues

Most recently, hyperlane-xyz/hyperlane-registry#236 (comment). But there have been numerous occasions where it would be nice for users to be self-sufficient in configuring and deploying an IGP hook for their PI deployments/relayer.

Backward compatibility

yes

Testing

  • creating igp config with hyperlane core init --advanced
  • making sure infra print-token-prices.ts still works
  • making sure infra print-gas-prices.ts still works

Copy link

changeset-bot bot commented Oct 7, 2024

🦋 Changeset detected

Latest commit: 093fc13

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@hyperlane-xyz/cli Minor
@hyperlane-xyz/sdk Minor
@hyperlane-xyz/helloworld Minor
@hyperlane-xyz/infra Minor
@hyperlane-xyz/widgets Minor
@hyperlane-xyz/ccip-server Minor
@hyperlane-xyz/github-proxy Minor
@hyperlane-xyz/utils Minor
@hyperlane-xyz/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@paulbalaji paulbalaji marked this pull request as ready for review October 7, 2024 17:32
Copy link

codecov bot commented Oct 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.97%. Comparing base (e104cf6) to head (093fc13).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4635   +/-   ##
=======================================
  Coverage   73.97%   73.97%           
=======================================
  Files         101      101           
  Lines        1460     1460           
  Branches      191      191           
=======================================
  Hits         1080     1080           
  Misses        359      359           
  Partials       21       21           
Components Coverage Δ
core 84.61% <ø> (ø)
hooks 75.71% <ø> (ø)
isms 77.58% <ø> (ø)
token 89.01% <ø> (ø)
middlewares 77.39% <ø> (ø)

typescript/sdk/src/gas/utils.ts Outdated Show resolved Hide resolved
typescript/cli/src/config/hooks.ts Outdated Show resolved Hide resolved
typescript/cli/src/config/hooks.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@xeno097 xeno097 left a comment

Choose a reason for hiding this comment

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

🔥

@paulbalaji paulbalaji enabled auto-merge October 28, 2024 17:47
@paulbalaji paulbalaji added this pull request to the merge queue Oct 28, 2024
Merged via the queue into main with commit 956ff75 Oct 28, 2024
34 checks passed
@paulbalaji paulbalaji deleted the pb/cli-igp-config branch October 28, 2024 18:47
paulbalaji added a commit that referenced this pull request Oct 29, 2024
### Description

Re-adding the ability to generate IGP hook configs using the CLI, but
repurposing logic found in infra to make the configuration experience
more ergonomic. Logic still behind the `--advanced` flag.

> Enabling this allows IGP configuration in any place that supports hook
config e.g. `core`/`warp`/`hook` init with `--advanced`.

We will use metadata in registry to:
1. fetch price from Coingecko (prompt user if unable to find)
1. fetch current gas prices via the default RPCs
1. request user to enter an IGP margin in %
1. Calculate the `gasPrice` + `tokenExchangeRate` for you

Note that it still sets `overhead` to some preexisting default. 

```sh
? Select hook type interchainGasPaymaster
Creating interchainGasPaymaster...
? Detected owner address as 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 from signer, is this
correct? yes
? Use this same address for the beneficiary? yes
? Select network type Mainnet
? Select local chain for IGP hook bitlayer
? Select remote destination chains for IGP hook alephzero, ancient8
? Enter overhead for alephzero (e.g., 75000) for IGP hook 75000
? Enter overhead for ancient8 (e.g., 75000) for IGP hook 75000
Getting gas token prices for all chains from Coingecko...
Gas price for alephzero is 40.0
Gas token price for alephzero is $0.393347
Gas price for ancient8 is 0.001000252
Gas token price for ancient8 is $2356.71
Gas price for bitlayer is 0.050000007
Gas token price for bitlayer is $60576
? Enter IGP margin percentage (e.g. 10 for 10%) 100
Created interchainGasPaymaster!
```
```sh
Core config is valid, writing to file ./configs/core-config.yaml:

    owner: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
    defaultIsm:
      type: trustedRelayerIsm
      relayer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
    defaultHook:
      type: aggregationHook
      hooks:
        - type: merkleTreeHook
        - owner: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
          type: interchainGasPaymaster
          beneficiary: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
          oracleKey: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
          overhead:
            alephzero: 75000
            ancient8: 75000
          oracleConfig:
            alephzero:
              gasPrice: "40000000000"
              tokenExchangeRate: "129868"
            ancient8:
              gasPrice: "1000253"
              tokenExchangeRate: "778100236"
    requiredHook:
      owner: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
      type: protocolFee
      beneficiary: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
      maxProtocolFee: "1000000000000000000"
      protocolFee: "0"

✅ Successfully created new core deployment config.
```

### Drive-by changes

Moving reusable infra logic into the SDK, and refactoring CLI+Infra to
reuse the underlying logic. For example:
- fetching token prices from coingecko
- fetching gas prices using a chain's RPC

### Related issues

Most recently,
hyperlane-xyz/hyperlane-registry#236 (comment).
But there have been numerous occasions where it would be nice for users
to be self-sufficient in configuring and deploying an IGP hook for their
PI deployments/relayer.

### Backward compatibility

yes

### Testing

- creating igp config with `hyperlane core init --advanced`
- making sure infra print-token-prices.ts still works
- making sure infra print-gas-prices.ts still works
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.

2 participants