Skip to content

Commit

Permalink
support ics20-transfer with compat address on sequencer
Browse files Browse the repository at this point in the history
  • Loading branch information
quasystaty1 committed Oct 14, 2024
1 parent acfd370 commit ad806ba
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions crates/astria-sequencer/src/ibc/ics20_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,14 @@ async fn receive_tokens<S: StateWrite>(mut state: S, packet: &Packet) -> Result<
.parse()
.wrap_err("failed to parse packet data amount to u128")?;

let recipient: Address = packet_data
.receiver
.parse()
.wrap_err("invalid recipient address")?;
let recipient = parse_address_on_sequencer(&state, &packet_data.receiver)
.await
.with_context(|| {
format!(
"failed parsing packet.receiver `{}` as the recipient address",
packet_data.receiver
)
})?;

let mut asset = parse_asset(&state, &packet_data.denom)
.await
Expand Down Expand Up @@ -521,7 +525,7 @@ async fn refund_tokens<S: StateWrite>(mut state: S, packet: &Packet) -> Result<(

// Since we are refunding tokens, packet_data.sender is an address on Astria:
// the packet was not commited on the counter party chain but returned as-is.
let receiver = parse_sender(&state, &packet_data.sender)
let receiver = parse_address_on_sequencer(&state, &packet_data.sender)
.await
.with_context(|| {
format!(
Expand Down Expand Up @@ -611,7 +615,7 @@ async fn parse_asset<S: StateRead>(state: S, input: &str) -> Result<denom::Trace
}

#[instrument(skip_all, fields(input), err)]
async fn parse_sender<S: StateRead>(state: &S, input: &str) -> Result<Address> {
async fn parse_address_on_sequencer<S: StateRead>(state: &S, input: &str) -> Result<Address> {
use futures::TryFutureExt as _;
let (base_prefix, compat_prefix) = match try_join!(
state
Expand Down Expand Up @@ -828,6 +832,11 @@ mod tests {

let recipient_address = astria_address(&[1; 20]);
let amount = 100;

state_tx.put_base_prefix(ASTRIA_PREFIX.to_string()).unwrap();
state_tx
.put_ibc_compat_prefix(ASTRIA_COMPAT_PREFIX.to_string())
.unwrap();
state_tx
.put_ibc_channel_balance(&packet().chan_on_b, &nria(), amount)
.unwrap();
Expand Down Expand Up @@ -868,6 +877,11 @@ mod tests {
let snapshot = storage.latest_snapshot();
let mut state_tx = StateDelta::new(snapshot.clone());

state_tx.put_base_prefix(ASTRIA_PREFIX.to_string()).unwrap();
state_tx
.put_ibc_compat_prefix(ASTRIA_COMPAT_PREFIX.to_string())
.unwrap();

let recipient_address = astria_address(&[1; 20]);
let amount = 100;

Expand Down Expand Up @@ -913,6 +927,10 @@ mod tests {
let bridge_address = astria_address(&[99; 20]);
let rollup_id = RollupId::from_unhashed_bytes(b"testchainid");

state_tx.put_base_prefix(ASTRIA_PREFIX.to_string()).unwrap();
state_tx
.put_ibc_compat_prefix(ASTRIA_COMPAT_PREFIX.to_string())
.unwrap();
state_tx.put_transaction_context(TransactionContext {
address_bytes: bridge_address.bytes(),
transaction_id: TransactionId::new([0; 32]),
Expand Down Expand Up @@ -991,6 +1009,10 @@ mod tests {
let bridge_address = astria_address(&[99; 20]);
let rollup_id = RollupId::from_unhashed_bytes(b"testchainid");

state_tx.put_base_prefix(ASTRIA_PREFIX.to_string()).unwrap();
state_tx
.put_ibc_compat_prefix(ASTRIA_COMPAT_PREFIX.to_string())
.unwrap();
state_tx.put_transaction_context(TransactionContext {
address_bytes: bridge_address.bytes(),
transaction_id: TransactionId::new([0; 32]),
Expand Down

0 comments on commit ad806ba

Please sign in to comment.