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(interchain-token-service): add flow limit #130

Merged
merged 8 commits into from
Jan 14, 2025

Conversation

AttissNgo
Copy link
Contributor

@AttissNgo AttissNgo commented Jan 9, 2025

- implement flow limit for interchain transfers
- add Operatable trait and change constructor
- update golden files (tests generate different contract addresses due to updated constructor)
- minor changes to test helper functions
@AttissNgo AttissNgo requested a review from a team as a code owner January 9, 2025 02:29
@codecov-commenter
Copy link

codecov-commenter commented Jan 9, 2025

Codecov Report

Attention: Patch coverage is 99.27536% with 1 line in your changes missing coverage. Please review.

Project coverage is 94.84%. Comparing base (7adc13d) to head (f4a549a).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ntracts/interchain-token-service/src/flow_limit.rs 99.04% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #130      +/-   ##
==========================================
+ Coverage   94.63%   94.84%   +0.20%     
==========================================
  Files          52       53       +1     
  Lines        3130     3276     +146     
==========================================
+ Hits         2962     3107     +145     
- Misses        168      169       +1     

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

contracts/interchain-token-service/src/flow_limit.rs Outdated Show resolved Hide resolved
contracts/interchain-token-service/src/storage_types.rs Outdated Show resolved Hide resolved
contracts/interchain-token-service/src/interface.rs Outdated Show resolved Hide resolved
contracts/interchain-token-service/src/event.rs Outdated Show resolved Hide resolved
contracts/interchain-token-service/src/flow_limit.rs Outdated Show resolved Hide resolved
contracts/interchain-token-service/src/flow_limit.rs Outdated Show resolved Hide resolved
contracts/interchain-token-service/tests/flow_limit.rs Outdated Show resolved Hide resolved
- Add docstrings to entrypoints
- Create FlowKey struct for better organization of storage keys
- Move flow logic into FlowDirection impl
- Organize imports and group public functions
- Allow zero flow limit to 'freeze' token
contracts/interchain-token-service/src/contract.rs Outdated Show resolved Hide resolved
contracts/interchain-token-service/src/contract.rs Outdated Show resolved Hide resolved
contracts/interchain-token-service/src/contract.rs Outdated Show resolved Hide resolved
contracts/interchain-token-service/src/contract.rs Outdated Show resolved Hide resolved
contracts/interchain-token-service/src/event.rs Outdated Show resolved Hide resolved
contracts/interchain-token-service/src/contract.rs Outdated Show resolved Hide resolved
packages/axelar-soroban-std/src/events.rs Show resolved Hide resolved
contracts/interchain-token-service/src/flow_limit.rs Outdated Show resolved Hide resolved
contracts/interchain-token-service/src/flow_limit.rs Outdated Show resolved Hide resolved
AttissNgo and others added 2 commits January 13, 2025 11:29
- encapsulate add flow logic in Flow Direction enum
- add comments/docstring where necessary
- move entrypoint docstring from contract to interface
- refactor imports
contracts/interchain-token-service/src/interface.rs Outdated Show resolved Hide resolved
contracts/interchain-token-service/src/interface.rs Outdated Show resolved Hide resolved
contracts/interchain-token-service/src/interface.rs Outdated Show resolved Hide resolved
contracts/interchain-token-service/src/flow_limit.rs Outdated Show resolved Hide resolved
contracts/interchain-token-service/src/flow_limit.rs Outdated Show resolved Hide resolved
contracts/interchain-token-service/src/flow_limit.rs Outdated Show resolved Hide resolved
- improve docstring describing flow direction
- remove unneeded variables in add_flow
@AttissNgo AttissNgo merged commit 7da3677 into main Jan 14, 2025
5 checks passed
@AttissNgo AttissNgo deleted the feat/its-add-flow-limit branch January 14, 2025 02:32
const TEST_FLOW_LIMIT: Option<i128> = Some(1000);
const EPOCH_TIME: u64 = 6 * 60 * 60;

fn setup_flow_limit(env: &Env, client: &InterchainTokenServiceClient) -> (BytesN<32>, Address) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fn setup_flow_limit(env: &Env, client: &InterchainTokenServiceClient) -> (BytesN<32>, Address) {
fn setup(env: &Env, client: &InterchainTokenServiceClient) -> (BytesN<32>, Address) {

perhaps

client: &InterchainTokenServiceClient,
token_id: &BytesN<32>,
amount: i128,
) -> (String, String, String, Bytes, Vec<GatewayMessage>) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
) -> (String, String, String, Bytes, Vec<GatewayMessage>) {
) -> TestMessage {

create a struct

(token_id, deployer)
}

fn create_interchain_transfer_message(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fn create_interchain_transfer_message(
fn execute_its_transfer(

perhaps. It can approve and execute ITS in the helper itself to reduce duplication

payload_hash,
},
];

Copy link
Member

Choose a reason for hiding this comment

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

call approve gateway within this method to reduce duplication

let recipient = Address::generate(env).to_xdr(env);
let source_chain = client.its_hub_chain_name();
let source_address = Address::generate(env).to_string();

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let message_id = Address::generate(env).to_string();

let gas_token = setup_gas_token(&env, &sender);

let amount = 1000;
let destination_chain = String::from_str(&env, "ethereum");
Copy link
Member

Choose a reason for hiding this comment

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

create a helper for these dummy values

.mock_all_auths()
.set_trusted_chain(&destination_chain);

client.mock_all_auths().interchain_transfer(
Copy link
Member

Choose a reason for hiding this comment

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

same comment on hard to tell which call panicked, so use assert_auth_ok here

let (token_id, sender) = setup_flow_limit(&env, &client);
let gas_token = setup_gas_token(&env, &sender);

client
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
client
let flow_limit = i128::MAX - 50;
client

.mock_all_auths()
.set_flow_limit(&token_id, &Some(i128::MAX - 50));

let high_amount = i128::MAX - 100;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let high_amount = i128::MAX - 100;
let high_amount = flow_limit - 1;

reuse value

approve_gateway_messages(&env, &gateway_client, signers, messages);
client.execute(&source_chain, &message_id, &source_address, &payload);

let small_amount = 100;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let small_amount = 100;
let small_amount = 2;

Copy link
Member

Choose a reason for hiding this comment

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

I recommend creating a vector of flow in + flow out test cases, and running the test logic here in a loop over them to try different scenarios

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.

4 participants