-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Cross Chain Rates Recipient #671
Changes from 4 commits
d94100e
55a94a9
da74efe
bb2eb6c
bf33106
c95f460
471f6f4
040cdfe
aabea26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,14 +1,17 @@ | ||||||||||||
use crate::{ | ||||||||||||
ado_contract::ADOContract, | ||||||||||||
amp::{AndrAddr, Recipient}, | ||||||||||||
amp::{ | ||||||||||||
messages::{AMPMsg, AMPMsgConfig}, | ||||||||||||
AndrAddr, Recipient, | ||||||||||||
}, | ||||||||||||
common::{deduct_funds, denom::validate_native_denom, Funds}, | ||||||||||||
error::ContractError, | ||||||||||||
os::{adodb::ADOVersion, aos_querier::AOSQuerier}, | ||||||||||||
}; | ||||||||||||
use cosmwasm_schema::cw_serde; | ||||||||||||
use cosmwasm_std::{ | ||||||||||||
ensure, has_coins, to_json_binary, Coin, Decimal, Deps, Event, Fraction, QueryRequest, SubMsg, | ||||||||||||
WasmQuery, | ||||||||||||
ensure, has_coins, to_json_binary, Addr, Coin, Decimal, Deps, Event, Fraction, QueryRequest, | ||||||||||||
ReplyOn, SubMsg, WasmMsg, WasmQuery, | ||||||||||||
}; | ||||||||||||
use cw20::{Cw20Coin, Cw20QueryMsg, TokenInfoResponse}; | ||||||||||||
|
||||||||||||
|
@@ -160,24 +163,53 @@ impl LocalRate { | |||||||||||
event = event.add_attribute( | ||||||||||||
"payment", | ||||||||||||
PaymentAttribute { | ||||||||||||
receiver: self.recipient.address.get_raw_address(&deps)?.to_string(), | ||||||||||||
receiver: self | ||||||||||||
.recipient | ||||||||||||
.address | ||||||||||||
.get_raw_address(&deps) | ||||||||||||
.unwrap_or(Addr::unchecked(self.recipient.address.to_string())) | ||||||||||||
.to_string(), | ||||||||||||
Comment on lines
+195
to
+197
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle potential errors when retrieving recipient's raw address Using Apply this diff to handle the error properly: - .get_raw_address(&deps)
- .unwrap_or(Addr::unchecked(self.recipient.address.to_string()))
- .to_string(),
+ .get_raw_address(&deps)?
+ .to_string(), This change will propagate any errors from 📝 Committable suggestion
Suggested change
|
||||||||||||
amount: fee.clone(), | ||||||||||||
} | ||||||||||||
.to_string(), | ||||||||||||
); | ||||||||||||
|
||||||||||||
let msg = if is_native { | ||||||||||||
self.recipient | ||||||||||||
.generate_direct_msg(&deps, vec![fee.clone()])? | ||||||||||||
} else { | ||||||||||||
self.recipient.generate_msg_cw20( | ||||||||||||
&deps, | ||||||||||||
Cw20Coin { | ||||||||||||
amount: fee.amount, | ||||||||||||
address: fee.denom.to_string(), | ||||||||||||
let msg = if self.recipient.is_cross_chain() { | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should ensure cw20 isn't used for cross-chain here, maybe at the point of creating the rates recipient we validate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would work when the |
||||||||||||
// Create a cross chain message to be sent to the kernel | ||||||||||||
let kernel_address = ADOContract::default().get_kernel_address(deps.storage)?; | ||||||||||||
let kernel_msg = crate::os::kernel::ExecuteMsg::Send { | ||||||||||||
message: AMPMsg { | ||||||||||||
recipient: self.recipient.address.clone(), | ||||||||||||
message: self.recipient.msg.clone().unwrap_or_default(), | ||||||||||||
funds: vec![fee.clone()], | ||||||||||||
config: AMPMsgConfig { | ||||||||||||
reply_on: ReplyOn::Always, | ||||||||||||
exit_at_error: false, | ||||||||||||
gas_limit: None, | ||||||||||||
direct: true, | ||||||||||||
ibc_config: None, | ||||||||||||
}, | ||||||||||||
}, | ||||||||||||
)? | ||||||||||||
}; | ||||||||||||
SubMsg::new(WasmMsg::Execute { | ||||||||||||
contract_addr: kernel_address.to_string(), | ||||||||||||
msg: to_json_binary(&kernel_msg)?, | ||||||||||||
funds: vec![fee.clone()], | ||||||||||||
}) | ||||||||||||
} else { | ||||||||||||
if is_native { | ||||||||||||
self.recipient | ||||||||||||
.generate_direct_msg(&deps, vec![fee.clone()])? | ||||||||||||
} else { | ||||||||||||
self.recipient.generate_msg_cw20( | ||||||||||||
&deps, | ||||||||||||
Cw20Coin { | ||||||||||||
amount: fee.amount, | ||||||||||||
address: fee.denom.to_string(), | ||||||||||||
}, | ||||||||||||
)? | ||||||||||||
} | ||||||||||||
}; | ||||||||||||
|
||||||||||||
msgs.push(msg); | ||||||||||||
|
||||||||||||
events.push(event); | ||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,14 @@ impl Recipient { | |
self.msg.clone() | ||
} | ||
|
||
pub fn is_cross_chain(&self) -> bool { | ||
let protocol = self.address.get_protocol(); | ||
match protocol { | ||
Some("ibc") => true, | ||
_ => false, | ||
} | ||
} | ||
Comment on lines
+61
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add test coverage for The new method lacks test coverage. Please add tests to verify:
#[test]
fn test_is_cross_chain() {
// IBC address should return true
let recipient = Recipient::from_string("ibc/transfer/channel-0/uatom");
assert!(recipient.is_cross_chain());
// Non-IBC protocol should return false
let recipient = Recipient::from_string("wasm/contract0x123");
assert!(!recipient.is_cross_chain());
// Local address should return false
let recipient = Recipient::from_string("local_address");
assert!(!recipient.is_cross_chain());
} |
||
|
||
/// Generates a direct sub message for the given recipient. | ||
pub fn generate_direct_msg( | ||
&self, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason to generate unchecked
Addr
in caseget_raw_address
failed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming if it fails then it's a cross-chain address. Maybe we should account for that possibility in
get_raw_address
itself? Feels like a topic worth discussing.@crnbarr93