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

En 7630/esdt burn mint freeze #2328

Merged
merged 8 commits into from
Sep 29, 2020

Conversation

sasurobert
Copy link
Contributor

First PR of implementing the new functions in the system smart contract.

@@ -439,6 +439,21 @@ const BuiltInFunctionSaveKeyValue = "SaveKeyValue"
// BuiltInFunctionESDTTransfer is the key for the elrond standard digital token transfer built-in function
const BuiltInFunctionESDTTransfer = "ESDTTransfer"

// BuiltInFunctionESDTFreeze is the key for the elrond standard digital token freeze built-in function
const BuiltInFunctionESDTFreeze = "ESDTFreeze"
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want function names to start with uppercase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we already have it for ESDTTransfer - we might change them - it will need change in transaction generator testing component as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would use esdtFreeze style for all, but we can change this later

@@ -136,6 +136,11 @@ func (host *vmContext) GetBalance(addr []byte) *big.Int {
return account.GetBalance()
}

// TransferToAll handles transfering an information to all the shards
func (host *vmContext) TransferToAll(sender []byte, input []byte) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would require a different name since it looks like it has something to do with the value transfer function below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed to SendGlobalSettingToAll

@@ -101,19 +103,23 @@ func (e *esdt) Execute(args *vmcommon.ContractCallInput) vmcommon.ReturnCode {
case "mint":
return e.mint(args)
case "freeze":
return e.freeze(args)
return e.freezeUnFreeze(args, core.BuiltInFunctionESDTFreeze)
Copy link
Contributor

Choose a reason for hiding this comment

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

toggleFreeze and togglePause?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

optionalArg := string(arg)
switch optionalArg {
case burnable:
token.Burnable = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we also unset a property?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}
burntValue := big.NewInt(0).SetBytes(args.Arguments[1])
if burntValue.Cmp(big.NewInt(0)) <= 0 {
e.eei.AddReturnMessage(vm.ErrNegativeOrZeroInitialSupply.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add another error, this would be a bit misleading

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

e.eei.AddReturnMessage("token is not burnable")
return vmcommon.UserError
}
token.BurntValue.Add(token.BurntValue, burntValue)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we actually transfer this value to the burn address from the caller's balance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this value is actually transferred to the meta and deleted here - full implementation is not done. This is only a part. Any sender can BURN separately tokens through sending to burn address.

return vmcommon.UserError
}
if !token.Mintable {
e.eei.AddReturnMessage("token is not burnable")
Copy link
Contributor

Choose a reason for hiding this comment

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

"token is not mintable"

//TODO: implement me
return vmcommon.Ok
func (e *esdt) basicOwnerChecks(args *vmcommon.ContractCallInput) (*ESDTData, vmcommon.ReturnCode) {
if args.CallValue.Cmp(zero) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this check should be in basicOwnershipChecks. Or better so we don't have to figure out how to refactor, we can rename this method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@@ -136,6 +136,11 @@ func (host *vmContext) GetBalance(addr []byte) *big.Int {
return account.GetBalance()
}

// TransferToAll handles transfering an information to all the shards
func (host *vmContext) TransferToAll(sender []byte, input []byte) {

Copy link
Contributor

Choose a reason for hiding this comment

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

Missing implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes. Next PRs.

vm/systemSmartContracts/esdt.go Outdated Show resolved Hide resolved
vm/systemSmartContracts/esdt.go Show resolved Hide resolved
vm/systemSmartContracts/esdt.go Outdated Show resolved Hide resolved
e.eei.AddReturnMessage("destination address of invalid length")
return vmcommon.UserError
}
destination = args.Arguments[2]
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need the argument for the destination? Why not mint function should always sent tokens on the args.CallerAddr directly since it is the owner of the esdt token?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You might want to send to a new contract or to a new investor.

vm/systemSmartContracts/esdt.go Outdated Show resolved Hide resolved
vm/systemSmartContracts/esdt.go Outdated Show resolved Hide resolved
vm/systemSmartContracts/esdt.go Outdated Show resolved Hide resolved
vm/systemSmartContracts/esdt.go Outdated Show resolved Hide resolved
func (e *esdt) burn(_ *vmcommon.ContractCallInput) vmcommon.ReturnCode {
//TODO: implement me
return vmcommon.Ok
func (e *esdt) upgradeProperties(token *ESDTData, args [][]byte) {
Copy link
Contributor

Choose a reason for hiding this comment

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

unit tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will come in next PRs. Want to write full implementation and happy path integration test first.

@sasurobert sasurobert changed the base branch from development to feat/ESDT-new-arwen September 29, 2020 09:57
}

func checkAndGetSetting(arg string) (bool, error) {
if arg == "true" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Might use something like:

if strings.ToLower(arg) == "true" {.....

if strings.ToLower(arg) == "false" {.

as to work regardless how the caps were used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wouldn't change it - it has to be strict.

case upgradable:
token.Upgradable = true
token.Upgradable = val
Copy link
Contributor

Choose a reason for hiding this comment

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

This has to be treated cautiously by the the owner of the esdt token. He/she might wrongly set upgradable = false with some unwanted settings that will then become impossible to be changed in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the same with upgradable contract. by default upgradable is true.

@sasurobert sasurobert merged commit 32150a5 into feat/ESDT-new-arwen Sep 29, 2020
@sasurobert sasurobert deleted the EN-7630/ESDT-burn-mint-freeze branch September 29, 2020 14:41
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.

None yet

3 participants