Skip to content

Commit

Permalink
feat(sealevel): read / write igp gas oracle config (#2705)
Browse files Browse the repository at this point in the history
### Description
Tooling to get / set gas oracle data for sealevel, part of
hyperlane-xyz/issues#568

The PR adds two IGP oracle commands. If the values to be set are
specified, then the command performs a write using the key configured.
Otherwise, it performs a read. Unsure whether this is the best UX, happy
to change it.

Usage example:
```bash
# Get gas values
cargo run --bin hyperlane-sealevel-client igp destination-gas-overhead --environments-dir ./sealevel/environments --environment testnet3 --chain-name solanadevnet --remote-domain 88002

# Set gas values. Note the added `--gas-overhead 159736` flag
cargo run --bin hyperlane-sealevel-client igp destination-gas-overhead --environments-dir ./sealevel/environments --environment testnet3 --chain-name solanadevnet --remote-domain 88002 --gas-overhead 159736
```

There's also a small warp route util added to read the destination gas:
```bash
 cargo run --bin hyperlane-sealevel-client warp-route destination-gas --program-id 84DAG9VX5CvefQrBUGh9Gp66kmkat2voaM4MB2YwpGW1 --destination-domain 88002
 ```

<!--
What's included in this PR?
-->

### Drive-by changes

<!--
Are there any minor or drive-by changes also included?
-->

### Related issues

<!--
- Fixes #[issue number here]
-->

### Backward compatibility

<!--
Are these changes backward compatible? Are there any infrastructure implications, e.g. changes that would prohibit deploying older commits using this infra tooling?

Yes/No
-->

### Testing
Manual
<!--
What kind of testing have these changes undergone?

None/Manual/Unit Tests
-->
  • Loading branch information
daniel-savu authored Sep 7, 2023
1 parent 556efdb commit 4a5209d
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 1 deletion.
165 changes: 164 additions & 1 deletion rust/sealevel/client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ use account_utils::DiscriminatorEncode;
use hyperlane_core::{Encode, HyperlaneMessage, H160, H256};
use hyperlane_sealevel_connection_client::router::RemoteRouterConfig;
use hyperlane_sealevel_igp::{
accounts::{InterchainGasPaymasterType, OverheadIgpAccount},
accounts::{
GasOracle, IgpAccount, InterchainGasPaymasterType, OverheadIgpAccount, RemoteGasData,
},
igp_gas_payment_pda_seeds, igp_program_data_pda_seeds,
instruction::{GasOracleConfig, GasOverheadConfig},
};
use hyperlane_sealevel_mailbox::{
accounts::{InboxAccount, OutboxAccount},
Expand Down Expand Up @@ -118,6 +121,7 @@ pub(crate) struct WarpRouteCmd {
#[derive(Subcommand)]
pub(crate) enum WarpRouteSubCmd {
Deploy(WarpRouteDeploy),
DestinationGas(DestinationGasArgs),
}

#[derive(Args)]
Expand All @@ -138,6 +142,14 @@ pub(crate) struct WarpRouteDeploy {
ata_payer_funding_amount: Option<u64>,
}

#[derive(Args)]
struct DestinationGasArgs {
#[arg(long)]
program_id: Pubkey,
#[arg(long)]
destination_domain: u32,
}

#[derive(Args)]
struct CoreCmd {
#[command(subcommand)]
Expand Down Expand Up @@ -342,6 +354,8 @@ struct IgpCmd {
#[derive(Subcommand)]
enum IgpSubCmd {
PayForGas(PayForGasArgs),
GasOracleConfig(GasOracleConfigArgs),
DestinationGasOverhead(DestinationGasOverheadArgs),
TransferIgpOwnership(TransferIgpOwnership),
TransferOverheadIgpOwnership(TransferIgpOwnership),
}
Expand All @@ -363,6 +377,62 @@ struct PayForGasArgs {
message_id: String,
}

#[derive(Args)]
struct GasOracleConfigArgs {
#[arg(long)]
environment: String,
#[arg(long)]
environments_dir: PathBuf,
#[arg(long)]
chain_name: String,
#[arg(long)]
remote_domain: u32,
#[command(subcommand)]
cmd: GasOracleSubCmd,
}

#[derive(Subcommand)]
enum GasOracleSubCmd {
Set(SetGasOracleArgs),
Get,
}

#[derive(Args)]
struct SetGasOracleArgs {
#[arg(long)]
token_exchange_rate: u128,
#[arg(long)]
gas_price: u128,
#[arg(long)]
token_decimals: u8,
}

#[derive(Args)]
struct DestinationGasOverheadArgs {
#[arg(long)]
environment: String,
#[arg(long)]
environments_dir: PathBuf,
#[arg(long)]
chain_name: String,
#[arg(long)]
remote_domain: u32,
#[command(subcommand)]
cmd: GasOverheadSubCmd,
}

#[derive(Subcommand)]
enum GasOverheadSubCmd {
Set(SetGasOverheadArgs),
Get,
}

#[derive(Args)]
struct SetGasOverheadArgs {
#[arg(long)]
gas_overhead: u64,
}

#[derive(Args)]
struct ValidatorAnnounceCmd {
#[command(subcommand)]
Expand Down Expand Up @@ -1256,6 +1326,99 @@ fn process_igp_cmd(ctx: Context, cmd: IgpCmd) {
payment_details.message_id, gas_payment_data_account
);
}
IgpSubCmd::GasOracleConfig(args) => {
let core_program_ids =
read_core_program_ids(&args.environments_dir, &args.environment, &args.chain_name);
match args.cmd {
GasOracleSubCmd::Set(set_args) => {
let remote_gas_data = RemoteGasData {
token_exchange_rate: set_args.token_exchange_rate,
gas_price: set_args.gas_price,
token_decimals: set_args.token_decimals,
};
let gas_oracle_config = GasOracleConfig {
domain: args.remote_domain,
gas_oracle: Some(GasOracle::RemoteGasData(remote_gas_data)),
};
let instruction =
hyperlane_sealevel_igp::instruction::set_gas_oracle_configs_instruction(
core_program_ids.igp_program_id,
core_program_ids.igp_account,
ctx.payer_pubkey,
vec![gas_oracle_config],
)
.unwrap();
ctx.new_txn().add(instruction).send_with_payer();
println!("Set gas oracle for remote domain {:?}", args.remote_domain);
}
GasOracleSubCmd::Get => {
// Read the gas oracle config
let igp_account = ctx
.client
.get_account_with_commitment(&core_program_ids.igp_account, ctx.commitment)
.unwrap()
.value
.expect(
"IGP account not found. Make sure you are connected to the right RPC.",
);

let igp_account = IgpAccount::fetch(&mut &igp_account.data[..])
.unwrap()
.into_inner();

println!(
"IGP account gas oracle: {:#?}",
igp_account.gas_oracles.get(&args.remote_domain)
);
}
}
}
IgpSubCmd::DestinationGasOverhead(args) => {
let core_program_ids =
read_core_program_ids(&args.environments_dir, &args.environment, &args.chain_name);
match args.cmd {
GasOverheadSubCmd::Get => {
// Read the gas overhead config
let overhead_igp_account = ctx
.client
.get_account_with_commitment(
&core_program_ids.overhead_igp_account,
ctx.commitment,
)
.unwrap()
.value
.expect("Overhead IGP account not found. Make sure you are connected to the right RPC.");
let overhead_igp_account =
OverheadIgpAccount::fetch(&mut &overhead_igp_account.data[..])
.unwrap()
.into_inner();
println!(
"Overhead IGP account gas oracle: {:#?}",
overhead_igp_account.gas_overheads.get(&args.remote_domain)
);
}
GasOverheadSubCmd::Set(set_args) => {
let overhead_config = GasOverheadConfig {
destination_domain: args.remote_domain,
gas_overhead: Some(set_args.gas_overhead),
};
// Set the gas overhead config
let instruction =
hyperlane_sealevel_igp::instruction::set_destination_gas_overheads(
core_program_ids.igp_program_id,
core_program_ids.overhead_igp_account,
ctx.payer_pubkey,
vec![overhead_config],
)
.unwrap();
ctx.new_txn().add(instruction).send_with_payer();
println!(
"Set gas overheads for remote domain {:?}",
args.remote_domain
)
}
}
}
IgpSubCmd::TransferIgpOwnership(ref transfer_ownership)
| IgpSubCmd::TransferOverheadIgpOwnership(ref transfer_ownership) => {
let igp_account_type = match cmd.cmd {
Expand Down
7 changes: 7 additions & 0 deletions rust/sealevel/client/src/warp_route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,13 @@ pub(crate) fn process_warp_route_cmd(mut ctx: Context, cmd: WarpRouteCmd) {
.collect::<HashMap<String, H256>>();
write_program_ids(&warp_route_dir, &routers_by_name);
}
WarpRouteSubCmd::DestinationGas(args) => {
let destination_gas = get_destination_gas(&ctx.client, &args.program_id).unwrap();
println!(
"Destination gas: {:?}",
destination_gas[&args.destination_domain]
);
}
}
}

Expand Down

0 comments on commit 4a5209d

Please sign in to comment.