-
Notifications
You must be signed in to change notification settings - Fork 378
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
refactor: GRC20 #2314
refactor: GRC20 #2314
Conversation
Interesting discussion point: #2316 |
Opening up for reviews - grc20 package, foo20, wugnot & grc20 factory realms have been refactored, need to fix up some other stuff that is failing due to the changed API, awaiting a reply from @moul |
@tbruyelle I think both have valid use cases. People can choose to use the factory, or simply write their own realm importing the GRC20 package. |
ApprovalEvent = "Approval" | ||
) | ||
|
||
func NewGRC20Token(name, symbol string, decimals uint8) *Token { |
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.
func NewGRC20Token(name, symbol string, decimals uint8) *Token { | |
func NewToken(name, symbol string, decimals uint8) *Token { |
grc20 is the package name.
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.
i think we should not have a NewToken
helper, but only a NewBanker
one.
"gno.land/p/demo/ufmt" | ||
) | ||
|
||
type Token struct { |
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.
This looks good, but you need to have a type Banker interface { Token /* embedded */, Mint() }
which is what you initializes first.
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.
the banker should also have all the "admin" helpers, such as ways to call Transfer() and specifying a custom from
.
} | ||
|
||
func (t *Token) BalanceOf(owner std.Address) (balance uint64) { | ||
mustBeValid(owner) |
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.
we can remove this one.
return rawAllowance.(uint64) | ||
} | ||
|
||
func (t *Token) Mint(account std.Address, amount uint64) { |
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.
func (t *Token) Mint(account std.Address, amount uint64) { | |
func (t *Banker) Mint(account std.Address, amount uint64) { |
panic(err) | ||
} | ||
|
||
t.totalSupply = sum |
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.
shouldn't you also mint the tokens to the to
address?
o = ownable.New() | ||
o.TransferOwnership("g125em6arxsnj49vx35f0n0z34putv5ty3376fg5") // @admin |
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.
Let's remove the token owner completely and expose a "Faucet" function for the demonstration.
See #2388 for an example.
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.
I prefer if you keep this file as a test, or else, please implement it completely using standard unit tests.
if err != nil { | ||
panic(err) | ||
} | ||
wugnot.Approve(users.Resolve(spender), amount) |
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.
why removing the panic?
return ufmt.Sprintf("%d\n", balance) | ||
case c == 2 && parts[0] == "balance": // pkgpath:balance/address_or_username | ||
owner := pusers.AddressOrName(parts[1]) | ||
return ufmt.Sprintf("%d\n", wugnot.BalanceOf(users.Resolve(owner))) |
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.
return ufmt.Sprintf("%d\n", wugnot.BalanceOf(users.Resolve(owner))) | |
balance := wugnot.BalanceOf(users.Resolve(owner)) | |
return ufmt.Sprintf("%d\n", balance) |
func (t *Token) spendAllowance(owner, spender std.Address, value uint64) { | ||
currentAllowance := t.Allowance(owner, spender) | ||
|
||
if currentAllowance != math.MaxUint64 { |
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.
This exception should be documented. If I'm not mistaken, you consider a MaxUint64 allowance to be equivalent to an infinite allowance, correct?
unknown := std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // valid but never used. | ||
|
||
admin := testutils.TestAddress("admin") // g1v9kxjcm9ta047h6lta047h6lta047h6lzd40gh | ||
manfred := testutils.TestAddress("manfred") // g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm |
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.
manfred := testutils.TestAddress("manfred") // g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm | |
alice := testutils.TestAddress("alice") // xxx |
let's keep "manfred" when it's really my address.
t := tokenWithAdmin{ | ||
token: newToken, | ||
admin: admin, | ||
fauceted: false, // faucet disabled by default |
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.
If disabled by default, please register one or two tokens in init()
that will be fauceted as true by default, so this package can be easily tested.
```go // Package bar20 is similar to foo20 but exposes a safe-object that can be used // by `maketx run`, another contract importing foo20, and in the future when // we'll support `maketx call Token.XXX`. ``` This package currently has limited functionality, but it should become more useful in the future. I'm using it to demonstrate the rationale for having two implementations in the `grc20` package - one with a banker, and one with a safe object. Related with #2314 --------- Signed-off-by: moul <[email protected]>
Main changes: - rename `AdminToken` -> `Banker` - rename `GRC20` -> `Token` - remove unused helpers - remove vault (temporarily, will be reimplemented) - remove the returner ˋerror` when unnecessary - use `std.Emit` - use uassert for testing - better file naming and organization for improved readability Fixes #2294 Replaces #2314 (h/t @leohhhn) ~Depends on #2534~ BREAKING CHANGE --------- Signed-off-by: moul <[email protected]> Co-authored-by: Leon Hudak <[email protected]>
```go // Package bar20 is similar to foo20 but exposes a safe-object that can be used // by `maketx run`, another contract importing foo20, and in the future when // we'll support `maketx call Token.XXX`. ``` This package currently has limited functionality, but it should become more useful in the future. I'm using it to demonstrate the rationale for having two implementations in the `grc20` package - one with a banker, and one with a safe object. Related with gnolang#2314 --------- Signed-off-by: moul <[email protected]>
Main changes: - rename `AdminToken` -> `Banker` - rename `GRC20` -> `Token` - remove unused helpers - remove vault (temporarily, will be reimplemented) - remove the returner ˋerror` when unnecessary - use `std.Emit` - use uassert for testing - better file naming and organization for improved readability Fixes gnolang#2294 Replaces gnolang#2314 (h/t @leohhhn) ~Depends on gnolang#2534~ BREAKING CHANGE --------- Signed-off-by: moul <[email protected]> Co-authored-by: Leon Hudak <[email protected]>
This PR is stale because it has been open 3 months with no activity. Remove stale label or comment or this will be closed in 3 months. |
Clsoing this in favor of @moul's refactor. |
Description
Closes: #2294
This PR refactors the GRC20 folder to follow the ERC20 spec as close as possibly.
Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description