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

contracts: wrapped resources #1704

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

contracts: wrapped resources #1704

wants to merge 12 commits into from

Conversation

credence0x
Copy link
Collaborator

@credence0x credence0x commented Sep 23, 2024

resolves #1150

  • created a game bridge where any regular ERC20 token can be deposited and withdrawn for a fee
  • made provisions for fee split between velords, client and season pool and bank

Copy link

vercel bot commented Sep 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
eternum ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 27, 2024 0:03am

Copy link

Preparing PR description...

Copy link

Preparing review...

Copy link

@mentatbot mentatbot bot left a comment

Choose a reason for hiding this comment

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

The implementation of the resource bridge system is well-structured and covers the main functionalities required for depositing and withdrawing ERC20 tokens. The code includes proper checks for pausing deposits/withdrawals, whitelisting tokens, and fee calculations. However, there are a few areas where the code could be improved:

  1. Additional checks for zero-value transactions could be added to prevent potential issues.
  2. Error handling or logging for precision loss during token-resource conversions could be beneficial.
  3. The fee calculation logic is duplicated and could be abstracted into a separate function.
  4. Some error messages could be more descriptive to aid in debugging.

Overall, the implementation is solid, but these small improvements could enhance its robustness and maintainability.

Thanks for using MentatBot. Give comments a 👍 or 👎 to help me improve!


// take fees from deposit
let total_fees = InternalBridgeImpl::send_fees_on_deposit(world, token, client_fee_recipient, amount);
assert!(total_fees.is_non_zero(), "Bridge: deposit amount too small");
Copy link

Choose a reason for hiding this comment

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

Consider adding a check to ensure the amount is greater than zero to prevent potential issues with zero-value deposits.

return relative_amount;
}

fn send_fees_on_deposit(
Copy link

Choose a reason for hiding this comment

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

Consider adding error handling or logging for cases where the conversion might result in a loss of precision.

let fee_split_config = get!(world, WORLD_CONFIG_ID, ResourceBridgeFeeSplitConfig);
let velords_fee_amount = (amount * fee_split_config.velords_fee_on_dpt_percent.into())
/ PercentageValueImpl::_100().into();
let season_pool_fee_amount = (amount * fee_split_config.season_pool_fee_on_dpt_percent.into())
Copy link

Choose a reason for hiding this comment

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

Similar to the previous comment, consider adding error handling or logging for potential precision loss during conversion.

Comment on lines 174 to 175
/ PercentageValueImpl::_100().into();

Copy link

Choose a reason for hiding this comment

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

The fee calculation logic is repeated in both deposit and withdrawal functions. Consider abstracting this into a separate function to reduce code duplication.

Suggested change
/ PercentageValueImpl::_100().into();
let client_fee_amount = Self::calculate_fee(amount, fee_split_config.client_fee_on_dpt_percent);

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.

[lords] Create erc20 wrapper and unwrapper contract
2 participants