remove token / bridge related ops commands
Change-Id: Id97efe4b5e89a89fbc9d9373af906ecbd9d9f122
This commit is contained in:
parent
a330c89d1a
commit
84c47797ed
|
@ -68,7 +68,6 @@ fn command_deploy_bridge(
|
|||
initial_guardian,
|
||||
&BridgeConfig {
|
||||
guardian_set_expiration_time: 200000000,
|
||||
token_program: spl_token::id(),
|
||||
},
|
||||
)?;
|
||||
println!("bridge: {}, ", ix.accounts[2].pubkey.to_string());
|
||||
|
@ -85,145 +84,6 @@ fn command_deploy_bridge(
|
|||
Ok(Some(transaction))
|
||||
}
|
||||
|
||||
fn command_create_wrapped(
|
||||
config: &Config,
|
||||
bridge: &Pubkey,
|
||||
address: ForeignAddress,
|
||||
chain: u8,
|
||||
decimals: u8,
|
||||
) -> CommmandResult {
|
||||
println!("Creating wrapped asset");
|
||||
|
||||
let minimum_balance_for_rent_exemption = config
|
||||
.rpc_client
|
||||
.get_minimum_balance_for_rent_exemption(size_of::<Mint>())?;
|
||||
|
||||
let ix = create_wrapped(
|
||||
bridge,
|
||||
&config.owner.pubkey(),
|
||||
AssetMeta {
|
||||
address,
|
||||
chain,
|
||||
decimals,
|
||||
},
|
||||
)?;
|
||||
println!(
|
||||
"Wrapped Mint address: {}",
|
||||
ix.accounts[5].pubkey.to_string()
|
||||
);
|
||||
let mut transaction = Transaction::new_with_payer(&[ix], Some(&config.fee_payer.pubkey()));
|
||||
|
||||
let (recent_blockhash, fee_calculator) = config.rpc_client.get_recent_blockhash()?;
|
||||
check_fee_payer_balance(
|
||||
config,
|
||||
minimum_balance_for_rent_exemption
|
||||
+ fee_calculator.calculate_fee(&transaction.message()),
|
||||
)?;
|
||||
transaction.sign(&[&config.fee_payer, &config.owner], recent_blockhash);
|
||||
Ok(Some(transaction))
|
||||
}
|
||||
|
||||
fn command_poke_proposal(config: &Config, bridge: &Pubkey, proposal: &Pubkey) -> CommmandResult {
|
||||
println!("Poking lockup");
|
||||
|
||||
let ix = poke_proposal(bridge, proposal)?;
|
||||
let mut transaction = Transaction::new_with_payer(&[ix], Some(&config.fee_payer.pubkey()));
|
||||
|
||||
let (recent_blockhash, fee_calculator) = config.rpc_client.get_recent_blockhash()?;
|
||||
check_fee_payer_balance(
|
||||
config,
|
||||
fee_calculator.calculate_fee(&transaction.message()),
|
||||
)?;
|
||||
transaction.sign(&[&config.fee_payer, &config.owner], recent_blockhash);
|
||||
Ok(Some(transaction))
|
||||
}
|
||||
|
||||
fn command_lock_tokens(
|
||||
config: &Config,
|
||||
bridge: &Pubkey,
|
||||
account: Pubkey,
|
||||
token: Pubkey,
|
||||
amount: u64,
|
||||
to_chain: u8,
|
||||
target: ForeignAddress,
|
||||
nonce: u32,
|
||||
) -> CommmandResult {
|
||||
println!("Initiating transfer to foreign chain");
|
||||
|
||||
let minimum_balance_for_rent_exemption = config
|
||||
.rpc_client
|
||||
.get_minimum_balance_for_rent_exemption(size_of::<Mint>())?;
|
||||
|
||||
let bridge_key = Bridge::derive_bridge_id(bridge)?;
|
||||
|
||||
// Fetch token balance to get decimals.
|
||||
let balance = config
|
||||
.rpc_client
|
||||
.get_token_account_balance_with_commitment(&account, config.commitment_config)?
|
||||
.value;
|
||||
|
||||
// Check whether we can find wrapped asset meta for the given token
|
||||
let wrapped_key = Bridge::derive_wrapped_meta_id(bridge, &bridge_key, &token)?;
|
||||
let asset_meta = match config.rpc_client.get_account(&wrapped_key) {
|
||||
Ok(v) => {
|
||||
let wrapped_meta: &WrappedAssetMeta =
|
||||
Bridge::unpack_unchecked_immutable(v.data.as_slice())?;
|
||||
AssetMeta {
|
||||
address: wrapped_meta.address,
|
||||
chain: wrapped_meta.chain,
|
||||
decimals: balance.decimals,
|
||||
}
|
||||
}
|
||||
Err(_e) => AssetMeta {
|
||||
address: token.to_bytes(),
|
||||
chain: CHAIN_ID_SOLANA,
|
||||
decimals: 0,
|
||||
},
|
||||
};
|
||||
|
||||
let instructions = vec![
|
||||
approve(
|
||||
&spl_token::id(),
|
||||
&account,
|
||||
&bridge_key,
|
||||
&config.owner.pubkey(),
|
||||
&[],
|
||||
amount,
|
||||
)?,
|
||||
system_instruction::transfer(&config.owner.pubkey(), &bridge_key, Bridge::transfer_fee()),
|
||||
transfer_out(
|
||||
bridge,
|
||||
&config.owner.pubkey(),
|
||||
&account,
|
||||
&token,
|
||||
&TransferOutPayload {
|
||||
amount: U256::from(amount),
|
||||
chain_id: to_chain,
|
||||
asset: asset_meta,
|
||||
target,
|
||||
nonce,
|
||||
},
|
||||
)?,
|
||||
];
|
||||
|
||||
println!(
|
||||
"custody: {}, ",
|
||||
instructions[2].accounts[8].pubkey.to_string()
|
||||
);
|
||||
|
||||
let mut transaction =
|
||||
Transaction::new_with_payer(&instructions.as_slice(), Some(&config.fee_payer.pubkey()));
|
||||
|
||||
let (recent_blockhash, fee_calculator) = config.rpc_client.get_recent_blockhash()?;
|
||||
check_fee_payer_balance(
|
||||
config,
|
||||
minimum_balance_for_rent_exemption
|
||||
+ fee_calculator.calculate_fee(&transaction.message()),
|
||||
)?;
|
||||
transaction.sign(&[&config.fee_payer, &config.owner], recent_blockhash);
|
||||
Ok(Some(transaction))
|
||||
}
|
||||
|
||||
fn check_fee_payer_balance(config: &Config, required_balance: u64) -> Result<(), Error> {
|
||||
let balance = config.rpc_client.get_balance(&config.fee_payer.pubkey())?;
|
||||
if balance < required_balance {
|
||||
|
@ -947,215 +807,6 @@ fn main() {
|
|||
.required(true)
|
||||
.help("Address of the initial guardian"),
|
||||
))
|
||||
.subcommand(
|
||||
SubCommand::with_name("lock")
|
||||
.about("Transfer tokens to another chain")
|
||||
.arg(
|
||||
Arg::with_name("bridge")
|
||||
.long("bridge")
|
||||
.value_name("BRIDGE_KEY")
|
||||
.validator(is_pubkey_or_keypair)
|
||||
.takes_value(true)
|
||||
.index(1)
|
||||
.required(true)
|
||||
.help(
|
||||
"Specify the bridge program address"
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("sender")
|
||||
.validator(is_pubkey_or_keypair)
|
||||
.value_name("SENDER_TOKEN_ACCOUNT_ADDRESS")
|
||||
.takes_value(true)
|
||||
.index(2)
|
||||
.required(true)
|
||||
.help("The token account address of the sender"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("token")
|
||||
.validator(is_pubkey_or_keypair)
|
||||
.value_name("TOKEN_ADDRESS")
|
||||
.takes_value(true)
|
||||
.index(3)
|
||||
.required(true)
|
||||
.help("The mint address"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("amount")
|
||||
.validator(is_amount)
|
||||
.value_name("AMOUNT")
|
||||
.takes_value(true)
|
||||
.index(4)
|
||||
.required(true)
|
||||
.help("Amount to transfer out"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("chain")
|
||||
.validator(is_u8)
|
||||
.value_name("CHAIN")
|
||||
.takes_value(true)
|
||||
.index(5)
|
||||
.required(true)
|
||||
.help("Chain to transfer to"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("nonce")
|
||||
.validator(is_u32)
|
||||
.value_name("NONCE")
|
||||
.takes_value(true)
|
||||
.index(6)
|
||||
.required(true)
|
||||
.help("Nonce of the transfer"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("recipient")
|
||||
.validator(is_hex)
|
||||
.value_name("RECIPIENT_ADDRESS")
|
||||
.takes_value(true)
|
||||
.index(7)
|
||||
.required(true)
|
||||
.help("Address of the recipient (hex)"),
|
||||
)
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("postvaa")
|
||||
.about("Submit a VAA to the chain")
|
||||
.arg(
|
||||
Arg::with_name("bridge")
|
||||
.long("bridge")
|
||||
.value_name("BRIDGE_KEY")
|
||||
.validator(is_pubkey_or_keypair)
|
||||
.takes_value(true)
|
||||
.index(1)
|
||||
.required(true)
|
||||
.help(
|
||||
"Specify the bridge program address"
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("vaa")
|
||||
.validator(is_hex)
|
||||
.value_name("HEX_VAA")
|
||||
.takes_value(true)
|
||||
.index(2)
|
||||
.required(true)
|
||||
.help("The vaa to be posted"),
|
||||
)
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("poke")
|
||||
.about("Poke a proposal so it's retried")
|
||||
.arg(
|
||||
Arg::with_name("bridge")
|
||||
.long("bridge")
|
||||
.value_name("BRIDGE_KEY")
|
||||
.validator(is_pubkey_or_keypair)
|
||||
.takes_value(true)
|
||||
.index(1)
|
||||
.required(true)
|
||||
.help(
|
||||
"Specify the bridge program address"
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("proposal")
|
||||
.long("proposal")
|
||||
.value_name("PROPOSAL_KEY")
|
||||
.validator(is_pubkey_or_keypair)
|
||||
.takes_value(true)
|
||||
.index(2)
|
||||
.required(true)
|
||||
.help(
|
||||
"Specify the transfer proposal to poke"
|
||||
),
|
||||
)
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("wrapped-address")
|
||||
.about("Derive wrapped asset address")
|
||||
.arg(
|
||||
Arg::with_name("bridge")
|
||||
.long("bridge")
|
||||
.value_name("BRIDGE_KEY")
|
||||
.validator(is_pubkey_or_keypair)
|
||||
.takes_value(true)
|
||||
.index(1)
|
||||
.required(true)
|
||||
.help(
|
||||
"Specify the bridge program address"
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("chain")
|
||||
.validator(is_u8)
|
||||
.value_name("CHAIN")
|
||||
.takes_value(true)
|
||||
.index(2)
|
||||
.required(true)
|
||||
.help("Chain ID of the asset"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("decimals")
|
||||
.validator(is_u8)
|
||||
.value_name("DECIMALS")
|
||||
.takes_value(true)
|
||||
.index(3)
|
||||
.required(true)
|
||||
.help("Decimals of the asset"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("token")
|
||||
.validator(is_hex)
|
||||
.value_name("TOKEN_ADDRESS")
|
||||
.takes_value(true)
|
||||
.index(4)
|
||||
.required(true)
|
||||
.help("Token address of the asset"),
|
||||
)
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("create-wrapped")
|
||||
.about("Create a new wrapped asset Mint")
|
||||
.arg(
|
||||
Arg::with_name("bridge")
|
||||
.long("bridge")
|
||||
.value_name("BRIDGE_KEY")
|
||||
.validator(is_pubkey_or_keypair)
|
||||
.takes_value(true)
|
||||
.index(1)
|
||||
.required(true)
|
||||
.help(
|
||||
"Specify the bridge program address"
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("chain")
|
||||
.validator(is_u8)
|
||||
.value_name("CHAIN")
|
||||
.takes_value(true)
|
||||
.index(2)
|
||||
.required(true)
|
||||
.help("Chain ID of the asset"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("decimals")
|
||||
.validator(is_u8)
|
||||
.value_name("DECIMALS")
|
||||
.takes_value(true)
|
||||
.index(3)
|
||||
.required(true)
|
||||
.help("Decimals of the asset"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("token")
|
||||
.validator(is_hex)
|
||||
.value_name("TOKEN_ADDRESS")
|
||||
.takes_value(true)
|
||||
.index(4)
|
||||
.required(true)
|
||||
.help("Token address of the asset"),
|
||||
)
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let config = {
|
||||
|
@ -1258,60 +909,6 @@ fn main() {
|
|||
guardian.copy_from_slice(&initial_data);
|
||||
command_deploy_bridge(&config, &bridge, vec![guardian])
|
||||
}
|
||||
("lock", Some(arg_matches)) => {
|
||||
let bridge = pubkey_of(arg_matches, "bridge").unwrap();
|
||||
let account = pubkey_of(arg_matches, "sender").unwrap();
|
||||
let amount = value_t_or_exit!(arg_matches, "amount", u64);
|
||||
let nonce = value_t_or_exit!(arg_matches, "nonce", u32);
|
||||
let chain = value_t_or_exit!(arg_matches, "chain", u8);
|
||||
let token = pubkey_of(arg_matches, "token").unwrap();
|
||||
let recipient_string: String = value_of(arg_matches, "recipient").unwrap();
|
||||
let mut recipient_data = hex::decode(recipient_string).unwrap();
|
||||
// Pad to 32 bytes
|
||||
while recipient_data.len() < 32 {
|
||||
recipient_data.insert(0, 0u8)
|
||||
}
|
||||
|
||||
let mut recipient = [0u8; 32];
|
||||
recipient.copy_from_slice(&recipient_data);
|
||||
command_lock_tokens(
|
||||
&config, &bridge, account, token, amount, chain, recipient, nonce,
|
||||
)
|
||||
}
|
||||
("poke", Some(arg_matches)) => {
|
||||
let bridge = pubkey_of(arg_matches, "bridge").unwrap();
|
||||
let proposal = pubkey_of(arg_matches, "proposal").unwrap();
|
||||
command_poke_proposal(&config, &bridge, &proposal)
|
||||
}
|
||||
("create-wrapped", Some(arg_matches)) => {
|
||||
let bridge = pubkey_of(arg_matches, "bridge").unwrap();
|
||||
let chain = value_t_or_exit!(arg_matches, "chain", u8);
|
||||
let decimals = value_t_or_exit!(arg_matches, "decimals", u8);
|
||||
let addr_string: String = value_of(arg_matches, "token").unwrap();
|
||||
let addr_data = hex::decode(addr_string).unwrap();
|
||||
|
||||
let mut token_addr = [0u8; 32];
|
||||
token_addr.copy_from_slice(addr_data.as_slice());
|
||||
|
||||
command_create_wrapped(&config, &bridge, token_addr, chain, decimals)
|
||||
}
|
||||
("wrapped-address", Some(arg_matches)) => {
|
||||
let bridge = pubkey_of(arg_matches, "bridge").unwrap();
|
||||
let chain = value_t_or_exit!(arg_matches, "chain", u8);
|
||||
let decimals = value_t_or_exit!(arg_matches, "decimals", u8);
|
||||
let addr_string: String = value_of(arg_matches, "token").unwrap();
|
||||
let addr_data = hex::decode(addr_string).unwrap();
|
||||
|
||||
let mut token_addr = [0u8; 32];
|
||||
token_addr.copy_from_slice(addr_data.as_slice());
|
||||
|
||||
let bridge_key = Bridge::derive_bridge_id(&bridge).unwrap();
|
||||
let wrapped_key =
|
||||
Bridge::derive_wrapped_asset_id(&bridge, &bridge_key, chain, decimals, token_addr)
|
||||
.unwrap();
|
||||
println!("Wrapped address: {}", wrapped_key);
|
||||
return;
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
.and_then(|transaction| {
|
||||
|
|
Loading…
Reference in New Issue