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

Create idea.md #742

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Create idea.md #742

wants to merge 1 commit into from

Conversation

aggre
Copy link
Member

@aggre aggre commented Aug 22, 2024

<<DON'T MARGE THIS PR. IT'S JUST FOR DISCUSSION>>


/*
*/
const released = released_tokens_of_user.get(token).get(user);
Copy link
Member Author

Choose a reason for hiding this comment

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

It is this variable released that is important to prevent double payments. The contract needs to copy/increase released from sender to recipient.

total_released_tokens.get(token) + payment
);

+ last_balance_of_user_for_tokens[token][user] = user_balance;
Copy link
Member Author

Choose a reason for hiding this comment

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

At the end of withdraw transaction, the user's token balance is recorded here. This value will always be referenced inwithdraw transaction to detect any change in the balance.

const Withdraw = Withdraw(Registry(registry).registries('Withdraw'));

function updateReleasedTokens(token, user, current_balance) {
if (last_balance_of_user_for_tokens[token][user] === current_balance) {
Copy link
Member Author

Choose a reason for hiding this comment

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

If the recorded balance and the latest balance match, nothing is done.

updateReleasedTokens(token, history.from, Property.balanceOf(history.from));

const released_tokens = released_tokens_of_user.get(token).get(history.from);
const part_of_released = released_tokens * history.preBalanceOfSender / history.amount;
Copy link
Member Author

Choose a reason for hiding this comment

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

To copy the sender's released to the recipient, calculate part_of_released .

const part_of_released = released_tokens * history.preBalanceOfSender / history.amount;
released_tokens_of_user.get(token).set(
user,
part_of_released + released_tokens_of_user.get(token).get(user)
Copy link
Member Author

Choose a reason for hiding this comment

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

Add part_of_released to the recipient's released.


i = i - 1;
calculated = calculated + history.amount;
done = last_balance_of_user_for_tokens[token][user] + calculated === current_balance;
Copy link
Member Author

Choose a reason for hiding this comment

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

If the calculated transfers + recorded balance matches the user's latest balance, the loop ends.

history.amount = current_balance - history.preBalanceOfRecipient;
}

updateReleasedTokens(token, history.from, Property.balanceOf(history.from));
Copy link
Member

Choose a reason for hiding this comment

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

We are making recursive call here which will re-trigger the loop from the beginning without updating the released_tokens_of_user state. So, base case might get skipped and it can get stuck in infinite loop?

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.

2 participants