Skip to content
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

Fix Token Factory Inflow Tracking #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rate-limiter"
version = "0.1.0"
version = "0.1.1"
authors = ["Nicolas Lara <[email protected]>"]
edition = "2021"

Expand Down
2 changes: 1 addition & 1 deletion schema/rate-limiter.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "rate-limiter",
"contract_version": "0.1.0",
"contract_version": "0.1.1",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down
15 changes: 13 additions & 2 deletions src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ impl Packet {
.strip_prefix(&format!("transfer/{}/", self.source_channel))
.unwrap_or_default();
let split: Vec<&str> = unprefixed.split('/').collect();
if split[0] == unprefixed {
// This is a native token. Return the unprefixed token
if split[0] == unprefixed || split[0] == "factory" {
// This is a native token or a tokenfactory token. Return the unprefixed token
unprefixed.to_string()
} else {
// This is a non-native that was sent to the counterparty.
Expand Down Expand Up @@ -266,6 +266,17 @@ pub mod tests {
);
assert_eq!(packet.local_denom(&FlowType::In), "uosmo");
}
#[test]
fn receive_tokenfactory_token() {
// The counterparty chain sends us back our native token that they had wrapped
let packet = Packet::mock(
"channel-42-counterparty".to_string(), // The counterparty's channel is the source here
"channel-17-local".to_string(), // Our channel is the dest channel
"transfer/channel-42-counterparty/factory/osmo1em6xs47hd82806f5cxgyufguxrrc7l0aqx7nzzptjuqgswczk8csavdxek/alloyed/allUSDT".to_string(),
0_u128.into(),
);
assert_eq!(packet.local_denom(&FlowType::In), "factory/osmo1em6xs47hd82806f5cxgyufguxrrc7l0aqx7nzzptjuqgswczk8csavdxek/alloyed/allUSDT");
}

// Let's assume we have two chains A and B (local and counterparty) connected in the following way:
//
Expand Down