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
Liquid staking manager #3375
Liquid staking manager #3375
Conversation
# Conflicts: # vm/systemSmartContracts/esdt.go
return returnCode | ||
} | ||
if len(args.Arguments) != 3 { | ||
d.eei.AddReturnMessage("not enough arguments") |
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.
invalid number of arguments
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.
done
|
||
d.eei.Finish(totalRewards.Bytes()) | ||
return vmcommon.UserError |
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 vmcommon.Ok
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.
done
|
||
func (d *delegation) unDelegateViaLiquidStaking(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { | ||
returnCode := d.returnViaLiquidStaking(args) | ||
if returnCode != vmcommon.UserError { |
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 returnCode != vmcommon.Ok ?
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.
autocomplete :D
return returnCode | ||
} | ||
if len(args.Arguments) != 3 { | ||
d.eei.AddReturnMessage("not enough arguments") |
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.
invalid number of arguments
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.
done
numOfCalls := big.NewInt(0).SetBytes(args.Arguments[0]).Int64() | ||
minNumArguments := numOfCalls*2 + 1 | ||
if int64(len(args.Arguments)) < minNumArguments { | ||
l.eei.AddReturnMessage("invalid number of arguments") |
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.
"not enough arguments" ?
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.
done
return 0, err | ||
} | ||
if len(vmOutput.ReturnData) != 1 { | ||
return 0, vm.ErrNotEnoughReturnData |
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.
len(vmOutput.ReturnData) < 1 or ErrInvalidReturnData ?
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.
done
} | ||
|
||
return nil | ||
} else { |
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.
useless else
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.
done
destSCAddress []byte, | ||
valueAsBytes []byte, | ||
) (uint64, *big.Int, vmcommon.ReturnCode) { | ||
if len(destSCAddress) != len(l.liquidStakingSCAddress) || bytes.Equal(destSCAddress, l.liquidStakingSCAddress) { |
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.
can we have other "invalid addresses" like the validator/staking SC and such?
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.
it does not matter. as those system scs will error for the given input. would work with len check only.
return vmOutput.ReturnData, vmcommon.Ok | ||
} | ||
|
||
func (l *liquidStaking) createOrAddNFT( |
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.
createOrAddSFT ? Valid for all these xxxNFTxxx functions.
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.
done
RewardsCheckpoint: rewardsCheckpoint, | ||
} | ||
|
||
marshalledData, err := l.marshalizer.Marshal(attributes) |
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.
marshaledData *
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.
done
} | ||
|
||
func (l *liquidStaking) createNewNFT(value *big.Int) (uint64, error) { | ||
valuePlusOne := big.NewInt(0).Add(value, big.NewInt(1)) |
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 plus one?
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 a trick. You need to have at least 1 - in order to call AddQuantity - otherwise AddQuantity will fail. Thus we create one more and keep it in the contract.
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.
ok
} | ||
} | ||
|
||
err := d.addValueToFund(delegator.ActiveFund, delegateValue) |
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.
...or return directly
Liquid staking manager contract