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

feat(token-manager): add token manager for ITS #215

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

milapsheth
Copy link
Member

@milapsheth milapsheth commented Jan 26, 2025

@milapsheth milapsheth requested a review from a team as a code owner January 26, 2025 11:52
@codecov-commenter
Copy link

codecov-commenter commented Jan 26, 2025

Codecov Report

Attention: Patch coverage is 90.56604% with 15 lines in your changes missing coverage. Please review.

Project coverage is 95.09%. Comparing base (03d1a48) to head (7ba8813).

Files with missing lines Patch % Lines
...llar-interchain-token-service/src/token_manager.rs 50.00% 12 Missing ⚠️
...llar-interchain-token-service/src/token_handler.rs 71.42% 2 Missing ⚠️
contracts/stellar-token-manager/src/contract.rs 95.45% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #215      +/-   ##
==========================================
- Coverage   95.17%   95.09%   -0.09%     
==========================================
  Files          61       65       +4     
  Lines        3423     3548     +125     
==========================================
+ Hits         3258     3374     +116     
- Misses        165      174       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

#[test]
fn execute_fails_unauthorized() {
let (env, client, target) = setup();
let unauthorized = Address::generate(&env);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let unauthorized = Address::generate(&env);
let unauthorized_user = Address::generate(&env);

or not_owner ?

let unauthorized = Address::generate(&env);

assert_auth_err!(
unauthorized,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unauthorized,
unauthorized_user,

@@ -35,6 +35,7 @@ const ITS_HUB_CHAIN_NAME: &str = "axelar";
const PREFIX_INTERCHAIN_TOKEN_ID: &str = "its-interchain-token-id";
const PREFIX_INTERCHAIN_TOKEN_SALT: &str = "interchain-token-salt";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const PREFIX_INTERCHAIN_TOKEN_SALT: &str = "interchain-token-salt";
const PREFIX_INTERCHAIN_TOKEN_SALT: &str = "its-interchain-token-salt";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -35,6 +35,7 @@ const ITS_HUB_CHAIN_NAME: &str = "axelar";
const PREFIX_INTERCHAIN_TOKEN_ID: &str = "its-interchain-token-id";
const PREFIX_INTERCHAIN_TOKEN_SALT: &str = "interchain-token-salt";
const PREFIX_CANONICAL_TOKEN_SALT: &str = "canonical-token-salt";
const PREFIX_TOKEN_MANAGER: &str = "token-manager-id";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to double check, in EVM the contract id looks like token-manager: https://github.com/axelarnetwork/interchain-token-service/blob/cc6ef7282e18c6b2842cbf1098b06161e38ea32e/contracts/token-manager/TokenManager.sol#L30

if we're going to use token-manager-id, then variable name could be PREFIX_TOKEN_MANAGER_ID for code readability

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike token id, there's no token manager id. Still I'm going to revisit the prefixes in a follow up PR

@@ -35,6 +35,7 @@ const ITS_HUB_CHAIN_NAME: &str = "axelar";
const PREFIX_INTERCHAIN_TOKEN_ID: &str = "its-interchain-token-id";
const PREFIX_INTERCHAIN_TOKEN_SALT: &str = "interchain-token-salt";
const PREFIX_CANONICAL_TOKEN_SALT: &str = "canonical-token-salt";
const PREFIX_TOKEN_MANAGER: &str = "token-manager-id";
const EXECUTE_WITH_TOKEN: &str = "execute_with_interchain_token";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EXECUTE_WITH_INTERCHAIN_TOKEN?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Self::set_token_id_config(
env,
token_id,
TokenIdConfigValue {
token_address: deployed_address,
token_address,
token_manager: token_manager_address,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
token_manager: token_manager_address,
token_manager_address,

Comment on lines 38 to 39
pub token_manager_address: Address,
pub token_address: Address,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub token_manager_address: Address,
pub token_address: Address,
pub token_address: Address,
pub token_manager_address: Address,

TokenManagerType::LockUnlock => {
token.transfer(sender, &env.current_contract_address(), &amount)
}
TokenManagerType::LockUnlock => token.transfer(sender, &token_manager, &amount),
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check unsupported token manager type? e.g.

_ => {
    return Err(ContractError::UnsupportedTokenManagerType);
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the enum is only defined for these two variants, so another option isn't possible

&env.current_contract_address(),
recipient,
&amount,
),
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question as above

let res: Val = env.invoke_contract(&contract, &func, args);

extend_instance_ttl(env);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to check, does event need to be emitted for the contract call?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, unnecessary gas cost for normal operations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants