Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
trestinlsd committed Oct 25, 2024
1 parent c7dc3ad commit ecbb71c
Show file tree
Hide file tree
Showing 21 changed files with 235 additions and 208 deletions.
20 changes: 10 additions & 10 deletions precompiles/avs/IAVSManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ IAVSManager constant AVSMANAGER_CONTRACT = IAVSManager(
/// @dev The interface through which solidity contracts will interact with AVS-Manager
/// @custom:address 0x0000000000000000000000000000000000000901
interface IAVSManager {
event AVSRegistered(address indexed sender, string avsName);
event AVSUpdated(address indexed sender, string avsName);
event AVSDeregistered(address indexed sender, string avsName);
event OperatorJoined(address indexed sender);
event OperatorOuted(address indexed sender);
event TaskCreated(address indexed sender,uint64 taskId,address indexed taskContractAddress,string name,bytes hash,
event AVSRegistered(address indexed avsAddr, string sender, string avsName);
event AVSUpdated(address indexed avsAddr, string sender, string avsName);
event AVSDeregistered(address indexed avsAddr, string sender, string avsName);
event OperatorJoined(address indexed avsAddr,string sender);
event OperatorOuted(address indexed avsAddr,string sender);
event TaskCreated(string sender,uint64 taskId,address indexed taskContractAddress,string name,bytes hash,
uint64 taskResponsePeriod,uint64 taskChallengePeriod,uint64 thresholdPercentage,uint64 taskStatisticalPeriod
);
event ChallengeInitiated(address indexed sender, bytes taskHash, uint64 taskID, bytes taskResponseHash,
event ChallengeInitiated(string sender, bytes taskHash, uint64 taskID, bytes taskResponseHash,
string operatorAddress);
event PublicKeyRegistered(address indexed sender, string name);
event TaskSubmittedByOperator(address indexed sender, uint64 taskID, bytes taskResponse,
event PublicKeyRegistered(string sender, string name);
event TaskSubmittedByOperator(string sender, uint64 taskID, bytes taskResponse,
bytes blsSignature, address indexed taskContractAddress, uint8 phase);


Expand Down Expand Up @@ -199,7 +199,7 @@ interface IAVSManager {
string memory operatorAddr
) external view returns (uint256 amount);

/// @dev getAVSInfo is a function to query Avs info.
/// @dev getAVSInfo is a function to query Avs epochIdentifier info.
/// @param avsAddr The address of the avs
function getAVSInfo(
address avsAddr
Expand Down
64 changes: 47 additions & 17 deletions precompiles/avs/abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
{
"indexed": true,
"internalType": "address",
"name": "sender",
"name": "avsAddr",
"type": "address"
},
{
"indexed": false,
"internalType": "string",
"name": "sender",
"type": "string"
},
{
"indexed": false,
"internalType": "string",
Expand All @@ -24,9 +30,15 @@
{
"indexed": true,
"internalType": "address",
"name": "sender",
"name": "avsAddr",
"type": "address"
},
{
"indexed": false,
"internalType": "string",
"name": "sender",
"type": "string"
},
{
"indexed": false,
"internalType": "string",
Expand All @@ -43,9 +55,15 @@
{
"indexed": true,
"internalType": "address",
"name": "sender",
"name": "avsAddr",
"type": "address"
},
{
"indexed": false,
"internalType": "string",
"name": "sender",
"type": "string"
},
{
"indexed": false,
"internalType": "string",
Expand All @@ -60,10 +78,10 @@
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"indexed": false,
"internalType": "string",
"name": "sender",
"type": "address"
"type": "string"
},
{
"indexed": false,
Expand Down Expand Up @@ -99,8 +117,14 @@
{
"indexed": true,
"internalType": "address",
"name": "sender",
"name": "avsAddr",
"type": "address"
},
{
"indexed": false,
"internalType": "string",
"name": "sender",
"type": "string"
}
],
"name": "OperatorJoined",
Expand All @@ -112,8 +136,14 @@
{
"indexed": true,
"internalType": "address",
"name": "sender",
"name": "avsAddr",
"type": "address"
},
{
"indexed": false,
"internalType": "string",
"name": "sender",
"type": "string"
}
],
"name": "OperatorOuted",
Expand All @@ -123,10 +153,10 @@
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"indexed": false,
"internalType": "string",
"name": "sender",
"type": "address"
"type": "string"
},
{
"indexed": false,
Expand All @@ -142,10 +172,10 @@
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"indexed": false,
"internalType": "string",
"name": "sender",
"type": "address"
"type": "string"
},
{
"indexed": false,
Expand Down Expand Up @@ -203,10 +233,10 @@
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"indexed": false,
"internalType": "string",
"name": "sender",
"type": "address"
"type": "string"
},
{
"indexed": false,
Expand Down
6 changes: 3 additions & 3 deletions precompiles/avs/avs.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (p Precompile) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz [
bz, err = p.GetOptedInOperatorAccAddrs(ctx, contract, method, args)
if err != nil {
ctx.Logger().Error("internal error when calling avs precompile", "module", "avs precompile", "method", method.Name, "err", err)
bz, err = method.Outputs.Pack([]string(nil))
bz, err = method.Outputs.Pack([]string{})
}
case MethodGetAVSInfo:
bz, err = p.GetAVSInfo(ctx, contract, method, args)
Expand All @@ -147,7 +147,7 @@ func (p Precompile) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz [
bz, err = p.GetTaskInfo(ctx, contract, method, args)
if err != nil {
ctx.Logger().Error("internal error when calling avs precompile", "module", "avs precompile", "method", method.Name, "err", err)
bz, err = method.Outputs.Pack([]uint64(nil))
bz, err = method.Outputs.Pack([]uint64{})
}
case MethodIsOperator:
bz, err = p.IsOperator(ctx, contract, method, args)
Expand All @@ -167,7 +167,7 @@ func (p Precompile) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz [
bz, err = p.GetRegisteredPubkey(ctx, contract, method, args)
if err != nil {
ctx.Logger().Error("internal error when calling avs precompile", "module", "avs precompile", "method", method.Name, "err", err)
bz, err = method.Outputs.Pack([]byte(nil))
bz, err = method.Outputs.Pack([]byte{})
}
case MethodGetOperatorOptedUSDValue:
bz, err = p.GetOperatorOptedUSDValue(ctx, contract, method, args)
Expand Down
10 changes: 5 additions & 5 deletions precompiles/avs/avs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ func (suite *AVSManagerPrecompileSuite) TestDeregisterAVS() {
MinStakeAmount: minStakeAmount,
MinOptInOperators: params[0],
MinTotalStakeAmount: params[1],
AvsReward: sdk.MustNewDecFromStr(strconv.FormatUint(params[1], 10)),
AvsSlash: sdk.MustNewDecFromStr(strconv.FormatUint(params[2], 10)),
AvsReward: sdk.MustNewDecFromStr(strconv.Itoa(int(params[1]))),
AvsSlash: sdk.MustNewDecFromStr(strconv.Itoa(int(params[2]))),
}

err := suite.App.AVSManagerKeeper.SetAVSInfo(suite.Ctx, avs)
Expand Down Expand Up @@ -391,8 +391,8 @@ func (suite *AVSManagerPrecompileSuite) TestUpdateAVS() {
MinStakeAmount: minStakeAmount,
MinOptInOperators: params[0],
MinTotalStakeAmount: params[1],
AvsReward: sdk.MustNewDecFromStr(strconv.FormatUint(params[1], 10)),
AvsSlash: sdk.MustNewDecFromStr(strconv.FormatUint(params[2], 10)),
AvsReward: sdk.MustNewDecFromStr(strconv.Itoa(int(params[1]))),
AvsSlash: sdk.MustNewDecFromStr(strconv.Itoa(int(params[2]))),
}

err := suite.App.AVSManagerKeeper.SetAVSInfo(suite.Ctx, avs)
Expand Down Expand Up @@ -536,7 +536,7 @@ func (suite *AVSManagerPrecompileSuite) TestRegisterOperatorToAVS() {
_, defaultAssetID := assetstypes.GetStakerIDAndAssetIDFromStr(asset.LayerZeroChainID, "", asset.Address)
err = suite.App.AVSManagerKeeper.UpdateAVSInfo(suite.Ctx, &types.AVSRegisterOrDeregisterParams{
Action: types.UpdateAction,
AvsAddress: avsAddr.String(),
AvsAddress: avsAddr,
AssetID: []string{defaultAssetID},
})
suite.NoError(err)
Expand Down
25 changes: 15 additions & 10 deletions precompiles/avs/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,42 +54,47 @@ func (p Precompile) emitEvent(ctx sdk.Context, stateDB vm.StateDB, eventName str
func (p Precompile) EmitAVSRegistered(ctx sdk.Context, stateDB vm.StateDB, avs *avstypes.AVSRegisterOrDeregisterParams) error {
arguments := p.ABI.Events[EventTypeAVSRegistered].Inputs
return p.emitEvent(ctx, stateDB, EventTypeAVSRegistered, arguments,
common.HexToAddress(avs.CallerAddress),
avs.AvsAddress,
avs.CallerAddress.String(),
avs.AvsName)
}

func (p Precompile) EmitAVSUpdated(ctx sdk.Context, stateDB vm.StateDB, avs *avstypes.AVSRegisterOrDeregisterParams) error {
arguments := p.ABI.Events[EventTypeAVSUpdated].Inputs
return p.emitEvent(ctx, stateDB, EventTypeAVSUpdated, arguments,
common.HexToAddress(avs.CallerAddress),
avs.AvsAddress,
avs.CallerAddress.String(),
avs.AvsName)
}

func (p Precompile) EmitAVSDeregistered(ctx sdk.Context, stateDB vm.StateDB, avs *avstypes.AVSRegisterOrDeregisterParams) error {
arguments := p.ABI.Events[EventTypeAVSDeregistered].Inputs
return p.emitEvent(ctx, stateDB, EventTypeAVSDeregistered, arguments,
common.HexToAddress(avs.CallerAddress),
avs.AvsAddress,
avs.CallerAddress.String(),
avs.AvsName)
}

func (p Precompile) EmitOperatorJoined(ctx sdk.Context, stateDB vm.StateDB, params *avstypes.OperatorOptParams) error {
arguments := p.ABI.Events[EventTypeOperatorJoined].Inputs
return p.emitEvent(ctx, stateDB, EventTypeOperatorJoined, arguments,
common.HexToAddress(params.OperatorAddress))
params.AvsAddress,
params.OperatorAddress.String())
}

func (p Precompile) EmitOperatorOuted(ctx sdk.Context, stateDB vm.StateDB, params *avstypes.OperatorOptParams) error {
arguments := p.ABI.Events[EventTypeOperatorOuted].Inputs
return p.emitEvent(ctx, stateDB, EventTypeOperatorOuted, arguments,
common.HexToAddress(params.OperatorAddress))
params.AvsAddress,
params.OperatorAddress.String())
}

func (p Precompile) EmitTaskCreated(ctx sdk.Context, stateDB vm.StateDB, task *avstypes.TaskInfoParams) error {
arguments := p.ABI.Events[EventTypeTaskCreated].Inputs
return p.emitEvent(ctx, stateDB, EventTypeTaskCreated, arguments,
common.HexToAddress(task.CallerAddress),
task.CallerAddress.String(),
task.TaskID,
common.HexToAddress(task.TaskContractAddress),
task.TaskContractAddress,
task.TaskName,
task.Hash,
task.TaskResponsePeriod,
Expand All @@ -101,7 +106,7 @@ func (p Precompile) EmitTaskCreated(ctx sdk.Context, stateDB vm.StateDB, task *a
func (p Precompile) EmitChallengeInitiated(ctx sdk.Context, stateDB vm.StateDB, params *avstypes.ChallengeParams) error {
arguments := p.ABI.Events[EventTypeChallengeInitiated].Inputs
return p.emitEvent(ctx, stateDB, EventTypeChallengeInitiated, arguments,
common.HexToAddress(params.CallerAddress),
params.CallerAddress.String(),
params.TaskHash,
params.TaskID,
params.TaskResponseHash,
Expand All @@ -111,14 +116,14 @@ func (p Precompile) EmitChallengeInitiated(ctx sdk.Context, stateDB vm.StateDB,
func (p Precompile) EmitPublicKeyRegistered(ctx sdk.Context, stateDB vm.StateDB, params *avstypes.BlsParams) error {
arguments := p.ABI.Events[EventTypePublicKeyRegistered].Inputs
return p.emitEvent(ctx, stateDB, EventTypePublicKeyRegistered, arguments,
common.HexToAddress(params.Operator),
params.Operator.String(),
params.Name)
}

func (p Precompile) EmitTaskSubmittedByOperator(ctx sdk.Context, stateDB vm.StateDB, params *avstypes.TaskResultParams) error {
arguments := p.ABI.Events[EventTypeTaskSubmittedByOperator].Inputs
return p.emitEvent(ctx, stateDB, EventTypeTaskSubmittedByOperator, arguments,
common.HexToAddress(params.CallerAddress),
params.CallerAddress.String(),
params.TaskID,
params.TaskResponse,
params.BlsSignature,
Expand Down
16 changes: 11 additions & 5 deletions precompiles/avs/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@ func (p Precompile) GetRegisteredPubkey(
if len(args) != len(p.ABI.Methods[MethodGetRegisteredPubkey].Inputs) {
return nil, fmt.Errorf(cmn.ErrInvalidNumberOfArgs, len(p.ABI.Methods[MethodGetRegisteredPubkey].Inputs), len(args))
}
// the key is set using the operator's acc address so the same logic should apply here
addr, ok := args[0].(string)
if !ok {
return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 0, "string", addr)
}
blsPubkeyInfo, err := p.avsKeeper.GetOperatorPubKey(ctx, addr)
blsPubKeyInfo, err := p.avsKeeper.GetOperatorPubKey(ctx, addr)
if err != nil {
if errors.Is(err, avstype.ErrNoKeyInTheStore) {
return method.Outputs.Pack([]byte{})
}
return nil, err
}
return method.Outputs.Pack(blsPubkeyInfo.PubKey)
return method.Outputs.Pack(blsPubKeyInfo.PubKey)
}

func (p Precompile) GetOptedInOperatorAccAddrs(
Expand Down Expand Up @@ -85,6 +87,9 @@ func (p Precompile) GetAVSUSDValue(
}
amount, err := p.avsKeeper.GetOperatorKeeper().GetAVSUSDValue(ctx, addr.String())
if err != nil {
if errors.Is(err, avstype.ErrNoKeyInTheStore) {
return method.Outputs.Pack(common.Big0)
}
return nil, err
}
return method.Outputs.Pack(amount.BigInt())
Expand All @@ -110,6 +115,9 @@ func (p Precompile) GetOperatorOptedUSDValue(
}
amount, err := p.avsKeeper.GetOperatorKeeper().GetOperatorOptedUSDValue(ctx, avsAddr.String(), operatorAddr)
if err != nil {
if errors.Is(err, avstype.ErrNoKeyInTheStore) {
return method.Outputs.Pack(common.Big0)
}
return nil, err
}
return method.Outputs.Pack(amount.ActiveUSDValue.BigInt())
Expand All @@ -124,7 +132,6 @@ func (p Precompile) GetAVSInfo(
if len(args) != len(p.ABI.Methods[MethodGetAVSInfo].Inputs) {
return nil, fmt.Errorf(cmn.ErrInvalidNumberOfArgs, len(p.ABI.Methods[MethodGetAVSInfo].Inputs), len(args))
}
// the key is set using the operator's acc address so the same logic should apply here
addr, ok := args[0].(common.Address)
if !ok {
return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 0, "common.Address", addr)
Expand Down Expand Up @@ -174,7 +181,6 @@ func (p Precompile) GetTaskInfo(
if len(args) != len(p.ABI.Methods[MethodGetTaskInfo].Inputs) {
return nil, fmt.Errorf(cmn.ErrInvalidNumberOfArgs, len(p.ABI.Methods[MethodGetTaskInfo].Inputs), len(args))
}
// the key is set using the operator's acc address so the same logic should apply here
addr, ok := args[0].(common.Address)
if !ok {
return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 0, "common.Address", addr)
Expand Down
Loading

0 comments on commit ecbb71c

Please sign in to comment.