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

Liquid staking manager #3375

Merged
merged 8 commits into from Aug 25, 2021
Merged

Conversation

sasurobert
Copy link
Contributor

Liquid staking manager contract

return returnCode
}
if len(args.Arguments) != 3 {
d.eei.AddReturnMessage("not enough arguments")
Copy link
Contributor

Choose a reason for hiding this comment

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

invalid number of arguments

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


d.eei.Finish(totalRewards.Bytes())
return vmcommon.UserError
Copy link
Contributor

Choose a reason for hiding this comment

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

return vmcommon.Ok

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


func (d *delegation) unDelegateViaLiquidStaking(args *vmcommon.ContractCallInput) vmcommon.ReturnCode {
returnCode := d.returnViaLiquidStaking(args)
if returnCode != vmcommon.UserError {
Copy link
Contributor

Choose a reason for hiding this comment

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

if returnCode != vmcommon.Ok ?

Copy link
Contributor Author

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")
Copy link
Contributor

Choose a reason for hiding this comment

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

invalid number of arguments

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

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")
Copy link
Contributor

Choose a reason for hiding this comment

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

"not enough arguments" ?

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

return 0, err
}
if len(vmOutput.ReturnData) != 1 {
return 0, vm.ErrNotEnoughReturnData
Copy link
Contributor

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 ?

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

}

return nil
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

useless else

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

destSCAddress []byte,
valueAsBytes []byte,
) (uint64, *big.Int, vmcommon.ReturnCode) {
if len(destSCAddress) != len(l.liquidStakingSCAddress) || bytes.Equal(destSCAddress, l.liquidStakingSCAddress) {
Copy link
Contributor

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?

Copy link
Contributor Author

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(
Copy link
Contributor

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.

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

RewardsCheckpoint: rewardsCheckpoint,
}

marshalledData, err := l.marshalizer.Marshal(attributes)
Copy link
Contributor

Choose a reason for hiding this comment

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

marshaledData *

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

}

func (l *liquidStaking) createNewNFT(value *big.Int) (uint64, error) {
valuePlusOne := big.NewInt(0).Add(value, big.NewInt(1))
Copy link
Contributor

Choose a reason for hiding this comment

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

why plus one?

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 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

iulianpascalau
iulianpascalau previously approved these changes Aug 25, 2021
}
}

err := d.addValueToFund(delegator.ActiveFund, delegateValue)
Copy link
Contributor

Choose a reason for hiding this comment

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

...or return directly

@sasurobert sasurobert merged commit 337b911 into feat/liquid-staking Aug 25, 2021
@sasurobert sasurobert deleted the liquid-staking-manager branch August 25, 2021 14:16
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