Skip to content

Commit

Permalink
fix:fix issues in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
trestinlsd committed May 30, 2024
1 parent 3df137e commit 63c0fe0
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 123 deletions.
2 changes: 1 addition & 1 deletion precompiles/avs/abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
{
"internalType": "uint64",
"name": "minimumDelegation",
"name": "minSelfDelegation",
"type": "uint64"
},
{
Expand Down
6 changes: 3 additions & 3 deletions precompiles/avs/avs.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (p Precompile) RequiredGas(input []byte) uint64 {
return p.Precompile.RequiredGas(input, p.IsTransaction(method.Name))
}

// Run executes the precompiled contract AVSInfoRegisterOrDeregister methods defined in the ABI.
// Run executes the precompiled contract RegisterOrDeregisterAVSInfo methods defined in the ABI.
func (p Precompile) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz []byte, err error) {
ctx, stateDB, method, initialGas, args, err := p.RunSetup(evm, contract, readOnly, p.IsTransaction)
if err != nil {
Expand All @@ -86,9 +86,9 @@ func (p Precompile) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz [

switch method.Name {
case MethodAVSAction:
bz, err = p.AVSInfoRegisterOrDeregister(ctx, evm.Origin, contract, stateDB, method, args)
bz, err = p.RegisterOrDeregisterAVSInfo(ctx, evm.Origin, contract, stateDB, method, args)
case MethodOperatorAction:
bz, err = p.OperatorBindingAvs(ctx, evm.Origin, contract, stateDB, method, args)
bz, err = p.BindOperatorToAVS(ctx, evm.Origin, contract, stateDB, method, args)
}

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion precompiles/avs/avs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface IAVSManager {
string memory slashContractAddr,
string[] memory assetID,
uint64 action,
uint64 minimumDelegation,
uint64 minSelfDelegation,
uint64 unbondingPeriod
) external returns (bool success);

Expand Down
18 changes: 9 additions & 9 deletions precompiles/avs/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

exocmn "github.com/ExocoreNetwork/exocore/precompiles/common"
util "github.com/ExocoreNetwork/exocore/utils"
avstypes "github.com/ExocoreNetwork/exocore/x/avs/keeper"
avskeep "github.com/ExocoreNetwork/exocore/x/avs/keeper"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -23,7 +23,7 @@ const (
)

// AVSInfoRegister register the avs related information and change the state in avs keeper module.
func (p Precompile) AVSInfoRegisterOrDeregister(
func (p Precompile) RegisterOrDeregisterAVSInfo(
ctx sdk.Context,
_ common.Address,
contract *vm.Contract,
Expand All @@ -36,12 +36,12 @@ func (p Precompile) AVSInfoRegisterOrDeregister(
if err != nil {
return nil, errorsmod.Wrap(err, "parse args error")
}
avsAddress, err := util.ProcessAvsAddress(contract.Address().String())
avsAddress, err := util.ProcessAddress(contract.Address().String())
if err != nil {
return nil, errorsmod.Wrap(err, "parse avsAddress error")
}

callerAddress, err := util.ProcessAvsAddress(contract.CallerAddress.String())
callerAddress, err := util.ProcessAddress(contract.CallerAddress.String())
if err != nil {
return nil, errorsmod.Wrap(err, "parse callerAddress error")
}
Expand All @@ -61,7 +61,7 @@ func (p Precompile) AVSInfoRegisterOrDeregister(
return method.Outputs.Pack(true)
}

func (p Precompile) OperatorBindingAvs(
func (p Precompile) BindOperatorToAVS(
ctx sdk.Context,
_ common.Address,
contract *vm.Contract,
Expand All @@ -72,21 +72,21 @@ func (p Precompile) OperatorBindingAvs(
if len(args) != 2 {
return nil, fmt.Errorf(cmn.ErrInvalidNumberOfArgs, 2, len(args))
}
operatorParams := &avstypes.OperatorOptParams{}
operatorParams := &avskeep.OperatorOptParams{}
action, ok := args[0].(uint64)
if !ok || (action != avstypes.RegisterAction && action != avstypes.DeRegisterAction) {
if !ok || (action != avskeep.RegisterAction && action != avskeep.DeRegisterAction) {
return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 0, "uint64", action)
}
operatorParams.Action = action

callerAddress, err := util.ProcessAvsAddress(contract.CallerAddress.String())
callerAddress, err := util.ProcessAddress(contract.CallerAddress.String())
if err != nil {
return nil, errorsmod.Wrap(err, "parse callerAddress error")
}

operatorParams.OperatorAddress = callerAddress

avsAddress, err := util.ProcessAvsAddress(contract.Address().String())
avsAddress, err := util.ProcessAddress(contract.Address().String())
if err != nil {
return nil, errorsmod.Wrap(err, "parse avsAddress error")
}
Expand Down
10 changes: 5 additions & 5 deletions precompiles/avs/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (p Precompile) GetAVSParamsFromInputs(_ sdk.Context, args []interface{}) (*
exoAddresses := make([]string, len(avsOwnerAddress))
var err error
for i, addr := range avsOwnerAddress {
exoAddresses[i], err = util.ProcessAvsAddress(addr)
exoAddresses[i], err = util.ProcessAddress(addr)
if err != nil {
return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 0, "[]string", avsOwnerAddress)
}
Expand All @@ -41,7 +41,7 @@ func (p Precompile) GetAVSParamsFromInputs(_ sdk.Context, args []interface{}) (*
return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 2, "string", slashContractAddr)
}

slashContractAddr, err = util.ProcessAvsAddress(slashContractAddr)
slashContractAddr, err = util.ProcessAddress(slashContractAddr)
if err != nil {
return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 2, "string", slashContractAddr)
}
Expand All @@ -59,11 +59,11 @@ func (p Precompile) GetAVSParamsFromInputs(_ sdk.Context, args []interface{}) (*
}
avsParams.Action = action

minimumDelegation, ok := args[5].(uint64)
minSelfDelegation, ok := args[5].(uint64)
if !ok || (action != avstypes.RegisterAction && action != avstypes.DeRegisterAction) {
return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 5, "uint64", minimumDelegation)
return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 5, "uint64", minSelfDelegation)
}
avsParams.MinimumDelegation = minimumDelegation
avsParams.MinSelfDelegation = minSelfDelegation

unbondingPeriod, ok := args[6].(uint64)
if !ok || (action != avstypes.RegisterAction && action != avstypes.DeRegisterAction) {
Expand Down
2 changes: 1 addition & 1 deletion precompiles/avsTask/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (p Precompile) RequiredGas(input []byte) uint64 {
return p.Precompile.RequiredGas(input, p.IsTransaction(method.Name))
}

// Run executes the precompiled contract AVSInfoRegisterOrDeregister methods defined in the ABI.
// Run executes the precompiled contract RegisterOrDeregisterAVSInfo methods defined in the ABI.
func (p Precompile) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz []byte, err error) {
ctx, stateDB, method, initialGas, args, err := p.RunSetup(evm, contract, readOnly, p.IsTransaction)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion precompiles/avsTask/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (s *TaskPrecompileTestSuite) TestRunRegTaskinfo() {
AvsOwnerAddress: avsOwnerAddress,
AssetId: assetID,
AvsUnbondingPeriod: uint32(7),
MinimumDelegation: sdk.NewIntFromUint64(10),
MinSelfDelegation: sdk.NewIntFromUint64(10),
AvsEpoch: nil,
OperatorAddress: nil,
}
Expand Down
2 changes: 1 addition & 1 deletion proto/exocore/avs/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ message AVSInfo {
// unbonding duration of avs.
uint32 avs_unbonding_period = 6;
// the operator minimum delegation amount.
string minimum_delegation = 7
string min_self_delegation = 7
[
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
Expand Down
2 changes: 1 addition & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func DecodeHexString(hexString string) ([]byte, error) {
return hex.DecodeString(hexString)
}

func ProcessAvsAddress(address string) (string, error) {
func ProcessAddress(address string) (string, error) {
switch {
case strings.HasPrefix(address, "0x"):
avsAddressHex, err := DecodeHexString(address)
Expand Down
10 changes: 3 additions & 7 deletions x/avs/keeper/avs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (k *Keeper) GetAVSSupportedAssets(ctx sdk.Context, avsAddr string) ([]strin
func (k *Keeper) GetAVSSlashContract(ctx sdk.Context, avsAddr string) (string, error) {
avsInfo, err := k.GetAVSInfo(ctx, avsAddr)
if err != nil {
return "", errorsmod.Wrap(err, fmt.Sprintf("GetAVSSupportedAssets: key is %s", avsAddr))
return "", errorsmod.Wrap(err, fmt.Sprintf("GetAVSSlashContract: key is %s", avsAddr))
}

return avsInfo.Info.SlashAddr, nil
Expand All @@ -32,15 +32,11 @@ func (k *Keeper) GetAVSSlashContract(ctx sdk.Context, avsAddr string) (string, e
func (k *Keeper) GetAVSMinimumSelfDelegation(ctx sdk.Context, avsAddr string) (sdkmath.LegacyDec, error) {
avsInfo, err := k.GetAVSInfo(ctx, avsAddr)
if err != nil {
return sdkmath.LegacyNewDec(0), errorsmod.Wrap(err, fmt.Sprintf("GetAVSSupportedAssets: key is %s", avsAddr))
return sdkmath.LegacyNewDec(0), errorsmod.Wrap(err, fmt.Sprintf("GetAVSMinimumSelfDelegation: key is %s", avsAddr))
}

return sdkmath.LegacyNewDec(avsInfo.Info.MinimumDelegation.Int64()), nil
return sdkmath.LegacyNewDec(avsInfo.Info.MinSelfDelegation.Int64()), nil
}

// GetEpochEndAVSs returns the AVS list where the current block marks the end of their epoch.
// func (k *Keeper) GetEpochEndAVSs(ctx sdk.Context) ([]string, error) {

// GetHeightForVotingPower retrieves the height of the last block in the epoch
// where the voting power used at the current height resides
// func (k *Keeper) GetHeightForVotingPower(ctx sdk.Context, avsAddr string, height int64) (int64, error)
8 changes: 4 additions & 4 deletions x/avs/keeper/avs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (suite *AVSTestSuite) TestAVS() {
AvsOwnerAddress: avsOwnerAddress,
AssetId: assetID,
AvsUnbondingPeriod: uint32(7),
MinimumDelegation: sdk.NewIntFromUint64(10),
MinSelfDelegation: sdk.NewIntFromUint64(10),
AvsEpoch: nil,
OperatorAddress: nil,
}
Expand All @@ -47,7 +47,7 @@ func (suite *AVSTestSuite) TestAVSInfoUpdate_Register() {
Action: avstypes.RegisterAction,
AvsOwnerAddress: avsOwnerAddress,
AssetID: assetID,
MinimumDelegation: uint64(10),
MinSelfDelegation: uint64(10),
UnbondingPeriod: uint64(7),
SlashContractAddr: slashAddress,
OperatorAddress: nil,
Expand Down Expand Up @@ -78,7 +78,7 @@ func (suite *AVSTestSuite) TestAVSInfoUpdate_DeRegister() {
Action: avstypes.DeRegisterAction,
AvsOwnerAddress: avsOwnerAddress,
AssetID: assetID,
MinimumDelegation: uint64(10),
MinSelfDelegation: uint64(10),
UnbondingPeriod: uint64(7),
SlashContractAddr: slashAddress,
OperatorAddress: nil,
Expand Down Expand Up @@ -146,7 +146,7 @@ func (suite *AVSTestSuite) TestAVSInfoUpdateWithOperator_Register() {
Action: avstypes.RegisterAction,
AvsOwnerAddress: avsOwnerAddress,
AssetID: assetID,
MinimumDelegation: uint64(10),
MinSelfDelegation: uint64(10),
UnbondingPeriod: uint64(7),
SlashContractAddr: slashAddress,
OperatorAddress: nil,
Expand Down
58 changes: 29 additions & 29 deletions x/avs/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,34 +50,35 @@ func (k Keeper) AVSInfoUpdate(ctx sdk.Context, params *AVSRegisterOrDeregisterPa

action := params.Action

if action == RegisterAction && avsInfo != nil {
return errorsmod.Wrap(types.ErrAlreadyRegistered, fmt.Sprintf("the error input arg is:%s", params.AvsAddress))
}

avs := &types.AVSInfo{
Name: params.AvsName,
AvsAddress: params.AvsAddress,
SlashAddr: params.SlashContractAddr,
AvsOwnerAddress: params.AvsOwnerAddress,
AssetId: params.AssetID,
MinimumDelegation: sdk.NewIntFromUint64(params.MinimumDelegation),
AvsUnbondingPeriod: uint32(params.UnbondingPeriod),
AvsEpoch: nil,
OperatorAddress: nil,
}
if action == RegisterAction && avsInfo == nil {
switch action {
case RegisterAction:
if avsInfo != nil {
return errorsmod.Wrap(types.ErrAlreadyRegistered, fmt.Sprintf("the avsaddress is :%s", params.AvsAddress))
}
avs := &types.AVSInfo{
Name: params.AvsName,
AvsAddress: params.AvsAddress,
SlashAddr: params.SlashContractAddr,
AvsOwnerAddress: params.AvsOwnerAddress,
AssetId: params.AssetID,
MinSelfDelegation: sdk.NewIntFromUint64(params.MinSelfDelegation),
AvsUnbondingPeriod: uint32(params.UnbondingPeriod),
AvsEpoch: nil,
OperatorAddress: nil,
}
return k.SetAVSInfo(ctx, avs)
case DeRegisterAction:
if avsInfo == nil {
return errorsmod.Wrap(types.ErrUnregisterNonExistent, fmt.Sprintf("the avsaddress is :%s", params.AvsAddress))
}
//TODO:if avs DeRegisterAction check UnbondingPeriod
// if avsInfo.Info.AvsUnbondingPeriod < currenUnbondingPeriod - regUnbondingPeriod {
// return errorsmod.Wrap(err, fmt.Sprintf("not qualified to deregister %s", avsInfo))
//}
return k.DeleteAVSInfo(ctx, params.AvsAddress)
default:
return errorsmod.Wrap(types.ErrInvalidAction, fmt.Sprintf("Invalid action: %d", action))
}

if avsInfo == nil {
return errorsmod.Wrap(types.ErrUnregisterNonExistent, fmt.Sprintf("the error input arg is:%s", avsInfo))
}

//TODO:if avs DeRegisterAction check UnbondingPeriod
// if avsInfo.Info.AvsUnbondingPeriod < currenUnbondingPeriod - regUnbondingPeriod {
// return errorsmod.Wrap(err, fmt.Sprintf("not qualified to deregister %s", avsInfo))
//}
return k.DeleteAVSInfo(ctx, params.AvsAddress)
}

func (k Keeper) AVSInfoUpdateWithOperator(ctx sdk.Context, params *OperatorOptParams) error {
Expand All @@ -90,7 +91,7 @@ func (k Keeper) AVSInfoUpdateWithOperator(ctx sdk.Context, params *OperatorOptPa
return errorsmod.Wrap(delegationtypes.ErrOperatorNotExist, fmt.Sprintf("AVSInfoUpdate: invalid operator address:%s", operatorAddress))
}
avsInfo, err := k.GetAVSInfo(ctx, params.AvsAddress)
if err != nil || avsInfo.GetInfo() == nil {
if err != nil || avsInfo == nil {
return errorsmod.Wrap(err, fmt.Sprintf("error occurred when get avs info %s", avsInfo))
}
avs := avsInfo.GetInfo()
Expand Down Expand Up @@ -120,8 +121,7 @@ func (k Keeper) SetAVSInfo(ctx sdk.Context, avs *types.AVSInfo) (err error) {
}
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixAVSInfo)

AVSInfo := avs
bz := k.cdc.MustMarshal(AVSInfo)
bz := k.cdc.MustMarshal(avs)
store.Set(avsAddr, bz)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion x/avs/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type AVSRegisterOrDeregisterParams struct {
AvsOwnerAddress []string
AssetID []string

MinimumDelegation uint64
MinSelfDelegation uint64
UnbondingPeriod uint64
SlashContractAddr string
OperatorAddress []string
Expand Down
5 changes: 5 additions & 0 deletions x/avs/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ var (
ModuleName, 2,
"Error: No available avs to DeRegisterAction",
)

ErrInvalidAction = errorsmod.Register(
ModuleName, 3,
"Error: Undefined action",
)
)
Loading

0 comments on commit 63c0fe0

Please sign in to comment.