Skip to content

Commit

Permalink
add hooks, metadata optional values to transferRemote in cw20 and nat…
Browse files Browse the repository at this point in the history
…ive warps
  • Loading branch information
udit-gulati committed May 2, 2024
1 parent 25a3181 commit b86a6a8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ context/*.config.json
tmp/
dist/
node_modules/
wasm_codes.zip
16 changes: 12 additions & 4 deletions contracts/warp/cw20/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ pub fn execute(
dest_domain,
recipient,
amount,
} => transfer_remote(deps, env, info, dest_domain, recipient, amount),
hook,
metadata,
} => transfer_remote(deps, env, info, dest_domain, recipient, amount, hook, metadata),
}
}

Expand Down Expand Up @@ -177,6 +179,8 @@ fn transfer_remote(
dest_domain: u32,
recipient: HexBinary,
transfer_amount: Uint128,
hook: Option<String>,
metadata: Option<HexBinary>,
) -> Result<Response, ContractError> {
let token = TOKEN.load(deps.storage)?;
let mode = MODE.load(deps.storage)?;
Expand Down Expand Up @@ -218,8 +222,8 @@ fn transfer_remote(
metadata: HexBinary::default(),
}
.into(),
get_hook(deps.storage)?.map(|v| v.into()),
None,
hook.clone().or(get_hook(deps.storage)?.map(|v| v.into())),
metadata.clone(),
info.funds,
)?);

Expand All @@ -229,7 +233,9 @@ fn transfer_remote(
.add_attribute("dest_domain", dest_domain.to_string())
.add_attribute("recipient", recipient.to_hex())
.add_attribute("token", token)
.add_attribute("amount", transfer_amount),
.add_attribute("amount", transfer_amount)
.add_attribute("hook", hook.unwrap_or_default())
.add_attribute("metadata", metadata.unwrap_or_default().to_string()),
))
}

Expand Down Expand Up @@ -536,6 +542,8 @@ mod test {
dest_domain: domain,
recipient: recipient.clone(),
amount: Uint128::new(100),
hook: None,
metadata: None,
},
vec![],
);
Expand Down
16 changes: 12 additions & 4 deletions contracts/warp/native/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ pub fn execute(
dest_domain,
recipient,
amount,
} => transfer_remote(deps, env, info, dest_domain, recipient, amount),
hook,
metadata,
} => transfer_remote(deps, env, info, dest_domain, recipient, amount, hook, metadata),
}
}

Expand Down Expand Up @@ -190,6 +192,8 @@ fn transfer_remote(
dest_domain: u32,
recipient: HexBinary,
transfer_amount: Uint128,
hook: Option<String>,
metadata: Option<HexBinary>,
) -> Result<Response, ContractError> {
let token = TOKEN.load(deps.storage)?;
let mode = MODE.load(deps.storage)?;
Expand Down Expand Up @@ -232,8 +236,8 @@ fn transfer_remote(
dest_domain,
dest_router,
dispatch_payload.into(),
get_hook(deps.storage)?.map(|v| v.into()),
None,
hook.clone().or(get_hook(deps.storage)?.map(|v| v.into())),
metadata.clone(),
funds,
)?);

Expand All @@ -242,7 +246,9 @@ fn transfer_remote(
.add_attribute("sender", info.sender)
.add_attribute("recipient", recipient.to_hex())
.add_attribute("token", token)
.add_attribute("amount", transfer_amount.to_string()),
.add_attribute("amount", transfer_amount.to_string())
.add_attribute("hook", hook.unwrap_or_default())
.add_attribute("metadata", metadata.unwrap_or_default().to_string()),
))
}

Expand Down Expand Up @@ -540,6 +546,8 @@ mod test {
dest_domain,
recipient: dest_recipient.clone(),
amount: Uint128::new(50),
hook: None,
metadata: None,
},
funds.clone(),
);
Expand Down
2 changes: 2 additions & 0 deletions packages/interface/src/warp/cw20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub enum ExecuteMsg {
dest_domain: u32,
recipient: HexBinary,
amount: Uint128,
hook: Option<String>,
metadata: Option<HexBinary>,
},
}

Expand Down
2 changes: 2 additions & 0 deletions packages/interface/src/warp/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ pub enum ExecuteMsg {
dest_domain: u32,
recipient: HexBinary,
amount: Uint128,
hook: Option<String>,
metadata: Option<HexBinary>,
},
}

Expand Down

0 comments on commit b86a6a8

Please sign in to comment.