-
Notifications
You must be signed in to change notification settings - Fork 18
feat(x/erc20): add allowance state #90
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
base: feat/remove-authz-from-precompiles
Are you sure you want to change the base?
feat(x/erc20): add allowance state #90
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cloudgray
Thanks for the draft — I’ve left a few comments that might be helpful as you continue working on this.
x/erc20/genesis.go
Outdated
owner = common.HexToAddress(allowance.Owner) | ||
spender = common.HexToAddress(allowance.Spender) | ||
value = allowance.Value.BigInt() | ||
k.SetAllowance(ctx, erc20, owner, spender, value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cloudgray
Could you add error handling here? If SetAllowance returns an error, we should panic to prevent inconsistent state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
applied in 80036a6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cloudgray
It looks like disabled token pairs never get their allowances stored during InitGenesis
, because SetAllowance
calls checkTokenPair
and returns an error if the token is disabled. However, InitGenesis
is supposed to restore all state from the genesis file — including allowances for disabled pairs.
Right now, we simply continue when types.ErrERC20TokenPairDisabled
is encountered, so those allowances don’t actually get written to the KVStore. If the module logic requires that disabled pairs still have their allowances recorded at genesis (so they might be re-enabled later or at least remain consistent with the imported state), we’ll need to revise this flow. One potential fix is to skip the checkTokenPair
check during genesis, or handle the “disabled” error as a non-fatal condition that still writes the allowance. Otherwise, we lose a piece of state that was originally present in the genesis file.
@zsystm I added deleteAllowances method and let it called by DeleteTokenPair method. It is not likely to happen that TokenPair for erc20 precompile is deleted and it really does not happen in cosmos/evm. So, I thought that all allowances that share same erc20 address are deleted when TokenPair is deleted. I applied this change in 80036a6. |
@cloudgray |
@cloudgray |
Description
Allowance
state in x/erc20 moduleCloses: #70
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
main
branchReviewers Checklist
All items are required.
Please add a note if the item is not applicable
and please add your handle next to the items reviewed
if you only reviewed selected items.
I have...
Unreleased
section inCHANGELOG.md