Skip to content

Commit

Permalink
fix: provide channel and port id when calling get_denom_address (#1299
Browse files Browse the repository at this point in the history
)

- Updates the Zerg config to accept port which is used when calling
`get_denom_address`
- Updates ucli to require channel and port ID when querying ucs01
balances
  • Loading branch information
PoisonPhang authored Feb 7, 2024
2 parents cc4a92d + 7eae9d9 commit 5ddef39
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ucli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ pub enum EvmQuery {
denom: String,
#[arg(long)]
address: H160,
#[arg(long)]
channel_id: String,
#[arg(long)]
port_id: String,
},
Erc20Balance {
#[arg(long)]
Expand Down
18 changes: 16 additions & 2 deletions ucli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,17 @@ async fn main() {
contract_address,
denom,
address,
channel_id,
port_id,
} => match config.evm {
cli::EvmChainConfig::Mainnet(config) => {
handle_ucs_balance::<Mainnet>(
Evm::new(config).await.unwrap(),
contract_address.into(),
denom,
address.into(),
channel_id,
port_id,
)
.await
}
Expand All @@ -86,6 +90,8 @@ async fn main() {
contract_address.into(),
denom,
address.into(),
channel_id,
port_id,
)
.await
}
Expand Down Expand Up @@ -137,14 +143,19 @@ async fn handle_ucs_balance<C: ChainSpec>(
contract_address: Address,
denom: String,
address: Address,
channel_id: String,
port_id: String,
) {
let signer_middleware = Arc::new(SignerMiddleware::new(
evm.provider.clone(),
evm.wallet.clone(),
));
let relay = UCS01Relay::new(contract_address, signer_middleware.clone());

let denom = relay.get_denom_address(denom).await.unwrap();
let denom = relay
.get_denom_address(port_id, channel_id, denom)
.await
.unwrap();
println!("Corresponding ERC20 address: {}", denom);

let erc_contract = erc20::ERC20::new(denom, signer_middleware.clone());
Expand Down Expand Up @@ -183,7 +194,10 @@ async fn handle_transfer<C: ChainSpec>(
));
let relay = UCS01Relay::new(relay_address, signer_middleware.clone());

let denom = relay.get_denom_address(denom).await.unwrap();
let denom = relay
.get_denom_address(port_id.clone(), channel_id.clone(), denom)
.await
.unwrap();
println!("Address is: {}", denom);

let erc_contract = erc20::ERC20::new(denom, signer_middleware.clone());
Expand Down
1 change: 1 addition & 0 deletions zerg-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
"union_contract": "union14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s3e9fe2",
"evm_contract": "0xF8F7758FbcEfd546eAEff7dE24AFf666B6228e73",
"channel": "channel-2",
"port": "0",
"rush_blocks": 2
}
1 change: 1 addition & 0 deletions zerg/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ pub struct Config {
pub union_contract: String,
pub evm_contract: H160,
pub channel: String,
pub port: String,
pub rush_blocks: u64,
}
6 changes: 5 additions & 1 deletion zerg/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ impl Context {
"wasm.{}/{}/{}",
zerg_config.union_contract, zerg_config.channel, zerg_config.union.fee_denom
);
let denom_address = ucs01_relay.get_denom_address(denom).call().await.unwrap();
let denom_address = ucs01_relay
.get_denom_address(zerg_config.port.clone(), zerg_config.channel.clone(), denom)
.call()
.await
.unwrap();
tracing::debug!("Fetched denom address.");

for signer in zerg_config.clone().evm.signers.into_iter() {
Expand Down

0 comments on commit 5ddef39

Please sign in to comment.