Skip to content

Commit

Permalink
Make a gas payment when deploying
Browse files Browse the repository at this point in the history
  • Loading branch information
tkporter authored and daniel-savu committed Aug 2, 2023
1 parent 1fb6dbd commit d778607
Show file tree
Hide file tree
Showing 9 changed files with 474 additions and 9 deletions.
1 change: 1 addition & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions rust/sealevel/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ solana-sdk.workspace = true
account-utils = { path = "../libraries/account-utils" }
hyperlane-core = { path = "../../hyperlane-core" }
hyperlane-sealevel-connection-client = { path = "../libraries/hyperlane-sealevel-connection-client" }
hyperlane-sealevel-mailbox = { path = "../programs/mailbox", features = ["no-entrypoint"] }
hyperlane-sealevel-multisig-ism-message-id = { path = "../programs/ism/multisig-ism-message-id", features = ["no-entrypoint"] }
hyperlane-sealevel-token = { path = "../programs/hyperlane-sealevel-token", features = ["no-entrypoint"] }
hyperlane-sealevel-token-collateral = { path = "../programs/hyperlane-sealevel-token-collateral", features = ["no-entrypoint"] }
hyperlane-sealevel-mailbox = { path = "../programs/mailbox" }
hyperlane-sealevel-multisig-ism-message-id = { path = "../programs/ism/multisig-ism-message-id" }
hyperlane-sealevel-token = { path = "../programs/hyperlane-sealevel-token" }
hyperlane-sealevel-igp = { path = "../programs/interchain-gas-paymaster" }
hyperlane-sealevel-token-collateral = { path = "../programs/hyperlane-sealevel-token-collateral" }
hyperlane-sealevel-token-lib = { path = "../libraries/hyperlane-sealevel-token" }
hyperlane-sealevel-token-native = { path = "../programs/hyperlane-sealevel-token-native", features = ["no-entrypoint"] }
hyperlane-sealevel-validator-announce = { path = "../programs/validator-announce", features = ["no-entrypoint"] }
139 changes: 138 additions & 1 deletion rust/sealevel/client/src/core.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use serde::{Deserialize, Serialize};

use solana_program::pubkey::Pubkey;
use solana_sdk::signature::Signer;
use solana_sdk::{signature::Signer, signer::keypair::Keypair};

use std::{fs::File, io::Write, path::Path, str::FromStr};

use crate::{
cmd_utils::{create_and_write_keypair, create_new_directory, create_new_file, deploy_program},
Context, CoreCmd, CoreSubCmd,
};
use hyperlane_core::H256;

pub(crate) fn process_core_cmd(mut ctx: Context, cmd: CoreCmd) {
match cmd.cmd {
Expand Down Expand Up @@ -47,10 +48,21 @@ pub(crate) fn process_core_cmd(mut ctx: Context, cmd: CoreCmd) {
core.local_domain,
);

let (igp_program_id, igp_program_data, igp_account) = deploy_igp(
&mut ctx,
core.use_existing_keys,
&key_dir,
&core.built_so_dir,
&log_file,
);

let program_ids = CoreProgramIds {
mailbox: mailbox_program_id,
validator_announce: validator_announce_program_id,
multisig_ism_message_id: ism_program_id,
igp_program_id,
igp_program_data,
igp_account,
};
write_program_ids(&core_dir, program_ids);
}
Expand Down Expand Up @@ -197,11 +209,127 @@ fn deploy_validator_announce(
program_id
}

fn deploy_igp(
ctx: &mut Context,
use_existing_key: bool,
key_dir: &Path,
built_so_dir: &Path,
log_file: impl AsRef<Path>,
) -> (Pubkey, Pubkey, Pubkey) {
let (keypair, keypair_path) = create_and_write_keypair(
key_dir,
"hyperlane_sealevel_igp-keypair.json",
use_existing_key,
);
let program_id = keypair.pubkey();

deploy_program(
&ctx.payer_path,
keypair_path.to_str().unwrap(),
built_so_dir
.join("hyperlane_sealevel_igp.so")
.to_str()
.unwrap(),
&ctx.client.url(),
log_file,
);

println!("Deployed IGP at program ID {}", program_id);

// Initialize the program data
let instruction =
hyperlane_sealevel_igp::instruction::init_instruction(program_id, ctx.payer.pubkey())
.unwrap();

ctx.instructions.push(instruction);
ctx.send_transaction(&[&ctx.payer]);
ctx.instructions.clear();

let (program_data_account, _program_data_bump) = Pubkey::find_program_address(
hyperlane_sealevel_igp::igp_program_data_pda_seeds!(),
&program_id,
);
println!("Initialized IGP program data {}", program_data_account);

// Initialize IGP with salt zero
let salt = H256::zero();
let instruction = hyperlane_sealevel_igp::instruction::init_igp_instruction(
program_id,
ctx.payer.pubkey(),
salt,
Some(ctx.payer.pubkey()),
ctx.payer.pubkey(),
)
.unwrap();
ctx.instructions.push(instruction);
ctx.send_transaction(&[&ctx.payer]);
ctx.instructions.clear();

let (igp_account, _igp_account_bump) =
Pubkey::find_program_address(hyperlane_sealevel_igp::igp_pda_seeds!(salt), &program_id);
println!("Initialized IGP account {}", igp_account);

// Set gas oracle for remote domain 13376
let instruction = hyperlane_sealevel_igp::instruction::set_gas_oracle_configs_instruction(
program_id,
igp_account,
ctx.payer.pubkey(),
vec![hyperlane_sealevel_igp::instruction::GasOracleConfig {
domain: 13376,
gas_oracle: Some(hyperlane_sealevel_igp::accounts::GasOracle::RemoteGasData(
hyperlane_sealevel_igp::accounts::RemoteGasData {
token_exchange_rate:
hyperlane_sealevel_igp::accounts::TOKEN_EXCHANGE_RATE_SCALE,
gas_price: 1u128,
token_decimals: hyperlane_sealevel_igp::accounts::SOL_DECIMALS,
},
)),
}],
)
.unwrap();

ctx.instructions.push(instruction);
ctx.send_transaction(&[&ctx.payer]);
ctx.instructions.clear();

println!("Set gas oracle for remote domain 13376");

// Now make a gas payment for a message ID
let message_id =
H256::from_str("0x6969000000000000000000000000000000000000000000000000000000006969")
.unwrap();
let unique_gas_payment_keypair = Keypair::new();
let (instruction, gas_payment_data_account) =
hyperlane_sealevel_igp::instruction::pay_for_gas_instruction(
program_id,
ctx.payer.pubkey(),
igp_account,
unique_gas_payment_keypair.pubkey(),
message_id,
13376,
100000,
)
.unwrap();
ctx.instructions.push(instruction);
ctx.send_transaction(&[&ctx.payer, &unique_gas_payment_keypair]);
ctx.instructions.clear();

println!(
"Made a payment for message {} with gas payment data account {}",
message_id, gas_payment_data_account
);

(program_id, program_data_account, igp_account)
}

#[derive(Debug)]
pub(crate) struct CoreProgramIds {
pub mailbox: Pubkey,
pub validator_announce: Pubkey,
pub multisig_ism_message_id: Pubkey,
pub igp_program_id: Pubkey,
pub igp_program_data: Pubkey,
pub igp_account: Pubkey,
}

impl From<PrettyCoreProgramIds> for CoreProgramIds {
Expand All @@ -211,6 +339,9 @@ impl From<PrettyCoreProgramIds> for CoreProgramIds {
validator_announce: Pubkey::from_str(program_ids.validator_announce.as_str()).unwrap(),
multisig_ism_message_id: Pubkey::from_str(program_ids.multisig_ism_message_id.as_str())
.unwrap(),
igp_program_id: Pubkey::from_str(program_ids.igp_program_id.as_str()).unwrap(),
igp_program_data: Pubkey::from_str(program_ids.igp_program_data.as_str()).unwrap(),
igp_account: Pubkey::from_str(program_ids.igp_account.as_str()).unwrap(),
}
}
}
Expand All @@ -220,6 +351,9 @@ struct PrettyCoreProgramIds {
mailbox: String,
validator_announce: String,
multisig_ism_message_id: String,
igp_program_id: String,
igp_program_data: String,
igp_account: String,
}

impl From<CoreProgramIds> for PrettyCoreProgramIds {
Expand All @@ -228,6 +362,9 @@ impl From<CoreProgramIds> for PrettyCoreProgramIds {
mailbox: program_ids.mailbox.to_string(),
validator_announce: program_ids.validator_announce.to_string(),
multisig_ism_message_id: program_ids.multisig_ism_message_id.to_string(),
igp_program_id: program_ids.igp_program_id.to_string(),
igp_program_data: program_ids.igp_program_data.to_string(),
igp_account: program_ids.igp_account.to_string(),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[134,213,157,143,154,178,76,237,127,55,106,87,207,201,112,195,174,29,19,170,52,199,100,115,102,42,118,82,225,6,249,137,236,199,107,157,79,247,91,219,151,212,248,27,201,224,51,4,188,80,88,44,193,240,200,144,174,68,126,194,114,54,29,85]
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"mailbox": "692KZJaoe2KRcD6uhCQDLLXnLNA5ZLnfvdqjE4aX9iu1",
"validator_announce": "DH43ae1LwemXAboWwSh8zc9pG8j72gKUEXNi57w8fEnn",
"multisig_ism_message_id": "2YjtZDiUoptoSsA5eVrDCcX6wxNK6YoEVW7y82x5Z2fw"
"multisig_ism_message_id": "2YjtZDiUoptoSsA5eVrDCcX6wxNK6YoEVW7y82x5Z2fw",
"igp_program_id": "GwHaw8ewMyzZn9vvrZEnTEAAYpLdkGYs195XWcLDCN4U",
"igp_program_data": "HBB1MxTeuRGb3C4bfXLQbu9z2Pn2LTXVQX53Hy7uyeof",
"igp_account": "DrFtxirPPsfdY4HQiNZj2A9o4Ux7JaL3gELANgAoihhp"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[86,251,114,232,180,241,250,134,177,246,42,46,186,189,49,90,89,204,100,125,155,25,147,101,214,199,217,85,206,213,35,196,210,137,243,172,88,191,74,240,37,103,187,105,166,208,57,17,183,226,207,228,64,84,242,235,243,87,113,31,26,49,57,214]
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"mailbox": "9tCUWNjpqcf3NUSrtp7vquYVCwbEByvLjZUrhG5dgvhj",
"validator_announce": "3Uo5j2Bti9aZtrDqJmAyuwiFaJFPFoNL5yxTpVCNcUhb",
"multisig_ism_message_id": "4RSV6iyqW9X66Xq3RDCVsKJ7hMba5uv6XP8ttgxjVUB1"
"multisig_ism_message_id": "4RSV6iyqW9X66Xq3RDCVsKJ7hMba5uv6XP8ttgxjVUB1",
"igp_program_id": "FArd4tEikwz2fk3MB7S9kC82NGhkgT6f9aXi3C5cw1E5",
"igp_program_data": "EX9kjV5nejw5N6YXybXcbyL2Bp7ZDaT4jjKHWd7AajLY",
"igp_account": "G5rGigZBL8NmxCaukK2CAKr9Jq4SUfAhsjzeri7GUraK"
}
Loading

0 comments on commit d778607

Please sign in to comment.