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

Contract: Bridge fees collection and claiming implementation #60

Merged
merged 7 commits into from
Dec 12, 2023

Conversation

keyleu
Copy link
Collaborator

@keyleu keyleu commented Dec 8, 2023

Description

  • Implemented fee collection and claiming for all tokens.
    How it works: Every time a user sends a token it will collect fees into the contract (part of the amount). The truncated amount counts towards the fee (so that users can choose what they want to receive on the other side).
    For claiming, any relayer can claim when ever he wants and the fees will be proportionally distributed to all of them.

Reviewers checklist:

  • Try to write more meaningful comments with clear actions to be taken.
  • Nit-picking should be unblocking. Focus on core issues.

Authors checklist

  • Provide a concise and meaningful description
  • Review the code yourself first, before making the PR.
  • Annotate your PR in places that require explanation.
  • Think and try to split the PR to smaller PR if it is big.

This change is Reviewable

@keyleu keyleu requested a review from a team as a code owner December 8, 2023 11:25
@keyleu keyleu requested review from dzmitryhil, miladz68, ysv and wojtek-coreum and removed request for a team December 8, 2023 11:25
@keyleu keyleu force-pushed the keyne/bridge-fees-implementation branch from 5bd0347 to 615ca88 Compare December 8, 2023 16:19
miladz68
miladz68 previously approved these changes Dec 11, 2023
Copy link
Contributor

@miladz68 miladz68 left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 34 files at r1, 28 of 28 files at r2, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @dzmitryhil, @wojtek-coreum, and @ysv)

Copy link
Contributor

@dzmitryhil dzmitryhil left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @keyleu, @wojtek-coreum, and @ysv)


contract/src/contract.rs line 63 at r2 (raw file):

const XRP_DEFAULT_MAX_HOLDING_AMOUNT: u128 =
    10u128.pow(16 - XRP_DEFAULT_SENDING_PRECISION as u32 + XRP_DECIMALS);
const XRP_DEFAULT_FEE: Uint128 = Uint128::zero();

Add please the TODO to update it.


contract/src/contract.rs line 433 at r2 (raw file):

                    amount_after_fees(amount_truncated, token.bridging_fee, truncated_portion)?;

                if amount_to_send

We should include the fees for the MaximumBridgedAmount as well


contract/src/contract.rs line 1003 at r2 (raw file):

    let truncated_amount =
        amount_to_send.checked_mul(Uint128::new(10u128.pow(exponent.unsigned_abs())))?;
    let truncated = amount.checked_sub(truncated_amount)?;

Probably call it truncation_remainder or remainder, same for the placed where you use it?

Copy link
Collaborator Author

@keyleu keyleu left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @dzmitryhil, @wojtek-coreum, and @ysv)


contract/src/contract.rs line 63 at r2 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

Add please the TODO to update it.

Added it.


contract/src/contract.rs line 433 at r2 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

We should include the fees for the MaximumBridgedAmount as well

Right,
But actually there was a bigger problem and was different (and more important one that I did not consider and that my tests did not detect).
I was only minting the amount to send to the user and not the fees, and since I only claimed at the end of the tests I didn't realize that I was taking the amount that was being bridged back (and not confirmed).

I added the minting for the fees into the contract and also modified tests to detect this.


contract/src/contract.rs line 1003 at r2 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

Probably call it truncation_remainder or remainder, same for the placed where you use it?

Sure, no problem. Changed it.

@keyleu keyleu requested a review from dzmitryhil December 11, 2023 12:29
@dzmitryhil dzmitryhil requested a review from miladz68 December 11, 2023 13:04
Copy link
Contributor

@dzmitryhil dzmitryhil left a comment

Choose a reason for hiding this comment

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

Reviewable status: 6 of 34 files reviewed, 1 unresolved discussion (waiting on @miladz68, @wojtek-coreum, and @ysv)

Copy link
Contributor

@miladz68 miladz68 left a comment

Choose a reason for hiding this comment

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

Reviewed 28 of 28 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @wojtek-coreum and @ysv)

@keyleu keyleu merged commit b196cec into master Dec 12, 2023
4 checks passed
@keyleu keyleu deleted the keyne/bridge-fees-implementation branch January 10, 2024 09:04
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