Skip to content

Commit

Permalink
modify cosmwasm gateway contracts to invoke a configured hook address…
Browse files Browse the repository at this point in the history
… when calling the hyperlane mailbox
  • Loading branch information
Dennis Fang committed Oct 29, 2024
1 parent 92eebe5 commit 639ed27
Show file tree
Hide file tree
Showing 16 changed files with 631 additions and 14 deletions.
1 change: 1 addition & 0 deletions cosmwasm/contracts/fast-transfer-gateway/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub fn instantiate(
token_denom: msg.token_denom,
address_prefix: msg.address_prefix,
mailbox_addr: msg.mailbox_addr,
hook_addr: msg.hook_addr,
};

CONFIG.save(deps.storage, &config)?;
Expand Down
10 changes: 3 additions & 7 deletions cosmwasm/contracts/fast-transfer-gateway/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cosmwasm_std::{
};
use cw_ownable::assert_owner;
use go_fast::{gateway::Config, FastTransferOrder};
use hyperlane::mailbox::{get_default_hook, DispatchMsg, ExecuteMsg as MailboxExecuteMsg};
use hyperlane::mailbox::{DispatchMsg, ExecuteMsg as MailboxExecuteMsg};

use crate::{
error::{ContractError, ContractResponse},
Expand Down Expand Up @@ -114,8 +114,6 @@ pub fn initiate_settlement(

let remote_contract_address = remote_contract_address.unwrap();

let default_hook = get_default_hook(deps.as_ref(), config.mailbox_addr.clone())?;

let settle_orders_message = SettleOrdersMessage {
repayment_address,
order_ids,
Expand All @@ -127,7 +125,7 @@ pub fn initiate_settlement(
dest_domain: source_domain,
recipient_addr: remote_contract_address.clone(),
msg_body: settle_orders_message.encode(),
hook: Some(default_hook),
hook: Some(config.hook_addr.clone()),
metadata: None,
}))?,
funds: info.funds,
Expand Down Expand Up @@ -169,8 +167,6 @@ pub fn initiate_timeout(

let remote_contract_address = remote_contract_address.unwrap();

let default_hook = get_default_hook(deps.as_ref(), config.mailbox_addr.clone())?;

let timeout_orders_message = TimeoutOrdersMessage { order_ids };

let msg = WasmMsg::Execute {
Expand All @@ -179,7 +175,7 @@ pub fn initiate_timeout(
dest_domain: source_domain,
recipient_addr: remote_contract_address.clone(),
msg_body: timeout_orders_message.encode(),
hook: Some(default_hook),
hook: Some(config.hook_addr.clone()),
metadata: None,
}))?,
funds: info.funds,
Expand Down
6 changes: 2 additions & 4 deletions cosmwasm/contracts/fast-transfer-gateway/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_std::{Addr, Coin, Deps, HexBinary, Order, StdError, StdResult};
use go_fast::gateway::{Config, OrderFill, RemoteDomain};
use hyperlane::mailbox::{get_default_hook, quote_dispatch, DispatchMsg};
use hyperlane::mailbox::{quote_dispatch, DispatchMsg};

use crate::{
helpers::encode_settle_order_data,
Expand Down Expand Up @@ -64,13 +64,11 @@ pub fn quote_initiate_settlement(

let remote_contract_address = remote_contract_address.unwrap();

let default_hook = get_default_hook(deps, config.mailbox_addr.clone())?;

let dispatch_msg = DispatchMsg {
dest_domain: source_domain,
recipient_addr: remote_contract_address.clone(),
msg_body: encode_settle_order_data(repayment_address, order_ids),
hook: Some(default_hook),
hook: Some(config.hook_addr.clone()),
metadata: None,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub fn default_instantiate() -> (OwnedDeps<MemoryStorage, MockApi, MockQuerier>,
token_denom: "uusdc".to_string(),
address_prefix: "osmo".to_string(),
mailbox_addr: "mailbox_contract_address".into(),
hook_addr: "hook_contract_address".into(),
},
)
.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn test_initiate_settlement() {
)
.unwrap(),
hook: Some(
"osmo12pvc4v625ewl34uqqgm3ezw76durxlky5j4guz8kvhal7em3e5wqz7cnla".into()
"hook_contract_address".into()
),
metadata: None
}))
Expand Down Expand Up @@ -129,7 +129,7 @@ fn test_initiate_settlement_multiple_orders() {
)
.unwrap(),
hook: Some(
"osmo12pvc4v625ewl34uqqgm3ezw76durxlky5j4guz8kvhal7em3e5wqz7cnla".into()
"hook_contract_address".into()
),
metadata: None
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn test_initiate_timeout() {
)
.unwrap(),
hook: Some(
"osmo12pvc4v625ewl34uqqgm3ezw76durxlky5j4guz8kvhal7em3e5wqz7cnla".into()
"hook_contract_address".into()
),
metadata: None
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn test_instantiate() {
token_denom: "uusdc".to_string(),
address_prefix: "osmo".to_string(),
mailbox_addr: "mailbox_contract_address".into(),
hook_addr: "hook_contract_address".into(),
local_domain: 1,
};

Expand All @@ -31,6 +32,7 @@ fn test_instantiate() {
assert_eq!(config.token_denom, instantiate_msg.token_denom);
assert_eq!(config.address_prefix, instantiate_msg.address_prefix);
assert_eq!(config.mailbox_addr, instantiate_msg.mailbox_addr);
assert_eq!(config.hook_addr, instantiate_msg.hook_addr);

let local_domain = LOCAL_DOMAIN.load(deps.as_ref().storage).unwrap();
assert_eq!(local_domain, 1);
Expand Down
Loading

0 comments on commit 639ed27

Please sign in to comment.