x/restaking
Last updated
Last updated
The following document specifies the restaking module.
This module contains the logic that allows users to restake their assets.
Assets can be restaked within a pool, towards an operator, or towards a specific Actively Validated Service (AVS).
In addition to managing the delegation, this module allows operators to start and stop securing an AVS, as well as AVS admins to determine which operator is authorized to secure their service and from which pool they may borrow security.
UnbondingID stores the ID of the latest unbonding operation. It enables creating unique IDs for unbonding operations, i.e., UnbondingID is incremented every time a new unbonding operation (pool undelegation, service undelegation and operator undelegation) is initiated.
Unbonding ID: 0x01 -> uint64
UnbondingIndex
maintains indexes used to acquire the key of a UnbondingDelegation
based on its unique identifier,UnbondingID
.
UnbondingIndex: 0x02 | UnbondingID -> UnbondingDelegationKey
UnbondingType represents the type of UnbondingDelegation
, indicating to which entity (pool, operator, or service) the
unbonding delegation is related. This information can be used to determine the appropriate actions to take when aUnbondingDelegation
has completed and the funds should be returned to the user's account.
UnbondingType: 0x03 | UnbondingID -> TargetID
OperatorJoinedServices maintains a record of the services that an operator has joined.
OperatorJoinedServices: collections.NewIndexedMap(0x13)
ServiceOperatorsAllowList stores which operators are allowed to join a service. It enables the creation of a whitelist of operators that can join a service.
ServiceOperatorsAllowList: collections.KeySet(0x14)
ServiceSecuringPools stores from which pools a service is borrowing security.
ServiceSecuringPools: collections.KeySet(0x15)
ServiceJoinedByOperator: indexes.NewReversePair(0x16)
PoolDelegation stores the delegation made by a user toward a pool. It allows to obtain all the user's delegation toward a pool and to quick check if a user has delegated toward a specific pool.
PoolDelegation: 0xa1 | UserAddr | PoolID -> ProtocolBuffer(Delegation)
PoolDelegationsByPoolID: 0xa2 | PoolID | UserAddr -> []byte{}
PoolUnbondingDelegation stores the pools unbonding delegation made by a user. It allows to obtain a user's pool unbonding delegation.
PoolUnbondingDelegation: 0xa3 | UserAddr | PoolID -> ProtocolBuffer(UnbondingDelegation)
OperatorDelegation stores the delegation made by a user toward an operator. It allows to obtain all the user's delegation toward an operator and to quick check if a user has delegated toward a specific operator.
OperatorDelegation: 0xb1 | UserAddr | OperatorID -> ProtocolBuffer(Delegation)
OperatorDelegationsByOperatorID: 0xb2 | OperatorID | UserAddr -> []byte{}
OperatorUnbondingDelegation stores the users' unbonding delegation that are related to an operator. It allows to obtain a user's operator unbonding delegation.
OperatorUnbondingDelegation: 0xb3 | UserAddr | OperatorID -> ProtocolBuffer(UnbondingDelegation)
ServiceDelegation stores the delegation made by a user toward a service. It allows to obtain all the user's delegation toward a service and to quick check if a user has delegated toward a specific service.
ServiceDelegation: 0xc1 | UserAddr | ServiceID -> ProtocolBuffer(Delegation)
ServiceDelegationsByServiceID: 0xc2 | ServiceID | UserAddr -> []byte{}
ServiceUnbondingDelegation stores the users' unbonding delegation that are related to a service. It allows to obtain a user's service unbonding delegation.
ServiceUnbondingDelegation: 0xc3 | UserAddr | ServiceID -> ProtocolBuffer(UnbondingDelegation)
UnbondingQueue stores the timestamp at which a list of UnbodingDelegation
completes and the delegated funds should
return to the user's account.
UnbondingQueue: 0xd1 | Timestamp -> ProtocolBuffer(DTDataList)
UserPreferences stores the users' preferences.
UserPreferences: collections.NewMap[string, UserPreferences](0xe1)
When a delegation occurs the target object is affected together with the internal state of the module. The target object
can be a Pool
, Operator
or Service
.
determine the delegators shares based on the tokens delegated and the total amount of tokens delegated toward the target
creates a new Delegation
or update an existing one with the computed shares
move the tokens from the delegator account to the target's account
store the Delegation
object in the target's delegation store (PoolDelegation
, OperatorDelegation
orServiceDelegation
)
store the index to perform the inverse look of all the delegations given the target id (PoolDelegationByUser
,OperatorDelegationByUser
or ServiceDelegationByUser
)
When a user perform an UndelegatePool
, UndelegateOperator
or UndelegateService
the following operations occur:
determine the shares based the amount of tokens that the user want to undelegate
subtract the computed shares from the Delegation
object. In case the final shares are 0 the Delegation
object will
be removed
subtract the undelegated tokens from the Target
total delegated tokens
computes the time when the undelegated tokens will be returned to the user
increments the UnbondingID
creates a new UnbondingDelegation
or obtain an existing UnbondingDelegation
in case the user was already
undelegating some tokens from the target
adds a new UnbondingDelegationEntry
to the UnbondingDelegation
stores the UnbondingDelegation
, this is stored in UserPoolUnbondingDelegation
for pools,UserOperatorUnbondingDelegation
for operators and UserServiceUnbondingDelegation
for services
stores an index to retrive the UnbondingDelegation
given an UnbondingID
stores in the UnbondingQueue
when the UnbondingDelegation
completes
When an UnbondingDelegationEntry
matures the following operations occur:
remove the index that associates the UnbondigID
with the UnbondingDelegation
object
transfer the unbonded tokens from the target to the user
removes the UnbondingDelegationEntry
from the UnbondingDelegation
object
store the updated UnbondingDelegation
or deletes in case the removed UnbondingDelegationEntry
was the last one
In this section we describe the processing of the restaking messages.
It allows the operator's admin to start securing a AVS.
This message is expected to fail if:
the sender
is not the Operator
admin
the service that the admin wants to join is no logger active
the operator is not in the service's operators allow list
It allows the operator's admin to stop securing an AVS.
This message is expected to fail if:
the sender
is not the Operator
admin
the Operator
didn't join the service
It allows the service admin to add an operator to the list of allowed operator to secure the service. If the service didn't have an allow list after adding the operator to the allow list all the operators not in the allow list will be stopped from securing the service.
This message is expected to fail if:
the sender
is not the Service
admin
the Operator
is already in the allow list
It allows the service admin to remove an operator to the list of allowed operator to secure the service. If the operator was securing the service will be stopped from securing it. When the last operator is removed from the allow list the service will allow all operators to join.
This message is expected to fail if:
the sender
is not the Service
admin
the Operator
is not in the Service
's allow list
It allows the service admin to add a pool to the list of pools from which the service has chosen to borrow security.
This message is expected to fail if:
the sender
is not the Service
admin
the Service
is inactive
the Service
is already secured by the provided Pool
It allows the service admin to remove a pool from the list of pools from which the service has chosen to borrow security.
This message is expected to fail if:
the sender
is not the Service
admin
the Service
is not secured by the provided Pool
It allows a user to put their assets into a restaking pool that will later be used to provide cryptoeconomic security to services that choose it.
This message is expected to fail if:
the denom of the coin that the user wants to delegate is not allowed
the sender
don't have the amount of coin that wants to delegate
It allows a user to undelegate their assets from a restaking pool.
This message is expected to fail if:
the user wants to undelegates an amount greater than the amount delegated
It allows a user to delegate their assets to an operator.
This message is expected to fail if:
don't exist an Operator
with the given id
the Operator
is not active
the denom of the coin that the user wants to delegate is not allowed
the sender
don't have the amount of coin that wants to delegate
It allows a user to undelegate their assets from a restaking operator.
This message is expected to fail if:
don't exist an Operator
with the given id
the user wants to undelegates an amount greater than the amount delegated toward that operator
It allows a user to delegate their assets to a service.
This message is expected to fail if:
don't exist a Service
with the given id
the denom of the coin that the user wants to delegate is not allowed
the sender
don't have the amount of coin that wants to delegate
It allows a user to undelegate their assets from a restaking service.
This message is expected to fail if:
don't exist a Service
with the given id
the user wants to undelegates an amount greater than the amount delegated toward that operator
It allows a user to set their preferences for the restaking module.
User preferences:
This message is expected to fail if:
one or more service specified in the preferences don't exist
one or more pool specified in the preferences don't exist
Allows to update the module parameters. The params are updated through a governance proposal where the signer is the gov module account address.
Params:
In this section we describe the operation that this modules executes during each abci end block call.
Complete the unbonding of all mature UnbondingDelegations.Entries
within the UnbondingQueue
with the following
procedure:
removes the index that associates the UnbondigID
with the UnbondingDelegation
object
transfer the unbonded tokens from the target to the user
removes the UnbondingDelegationEntry
from the UnbondingDelegation
object
store the updated UnbondingDelegation
or deletes in case the removed UnbondingDelegationEntry
was the last one
Other modules may register operations to execute when a certain event has occurred within the restaking module. The following hooks can be registered with restaking:
BeforePoolDelegationCreated(ctx context.Context, poolID uint32, delegator string) error
called before a new Delegation
object associated to a Pool
is created
BeforePoolDelegationSharesModified(ctx context.Context, poolID uint32, delegator string) error
called before the shares of Delegation
object associated a Pool
are modified
AfterPoolDelegationModified(ctx context.Context, poolID uint32, delegator string) error
called after a Delegation
object associated to a Pool
is modified
BeforePoolDelegationRemoved(ctx context.Context, poolID uint32, delegator string) error
called after a Delegation
object associated to a Pool
is removed
BeforeOperatorDelegationCreated(ctx context.Context, operatorID uint32, delegator string) error
called before a new Delegation
object associated to a Operator
is created
BeforeOperatorDelegationSharesModified(ctx context.Context, operatorID uint32, delegator string) error
called before the shares of Delegation
object associated a Operator
are modified
AfterOperatorDelegationModified(ctx context.Context, operatorID uint32, delegator string) error
called after a Delegation
object associated to a Operator
is modified
BeforeOperatorDelegationRemoved(ctx context.Context, operatorID uint32, delegator string) error
called after a Delegation
object associated to a Operator
is removed
BeforeServiceDelegationCreated(ctx context.Context, serviceID uint32, delegator string) error
called before a new Delegation
object associated to a Service
is created
BeforeServiceDelegationSharesModified(ctx context.Context, serviceID uint32, delegator string) error
called before the shares of Delegation
object associated a Service
are modified
AfterServiceDelegationModified(ctx context.Context, serviceID uint32, delegator string) error
called after a Delegation
object associated to a Service
is modified
BeforeServiceDelegationRemoved(ctx context.Context, serviceID uint32, delegator string) error
called after a Delegation
object associated to a Service
is removed
AfterUnbondingInitiated(ctx context.Context, unbondingDelegationID uint64) error
called after a new UnbondingDelegation
is created
AfterUserPreferencesModified(ctx context.Context, userAddress string, oldPreferences, newPreferences UserPreferences) error
called after a user's preferences are modified
The restaking module emits the following events:
complete_unbonding
amount
{totalUnbondingAmount}
complete_unbonding
unbonding_delegation
{unbondingDelegationTargetType}
complete_redelegation
target_id
{delegationTargetId}
complete_unbonding
delegator
{delegatorAddress}
join_service
operator_id
{operatorId}
join_service
service_id
{serviceId}
leave_service
operator_id
{operatorId}
leave_service
service_id
{serviceId}
allow_operator
operator_id
{operatorId}
allow_operator
service_id
{serviceId}
remove_allowed_operator
operator_id
{operatorId}
remove_allowed_operator
service_id
{serviceId}
borrow_pool_security
service_id
{serviceId}
borrow_pool_security
pool_id
{poolId}
cease_pool_security_borrow
service_id
{serviceId}
cease_pool_security_borrow
pool_id
{poolId}
delegate_pool
delegator
{delegatorAddress}
delegate_pool
amount
{delegationAmount}
delegate_pool
new_shares
{newShares}
unbond_pool
amount
{unbondAmount}
unbond_pool
delegator
{delegatorAddress}
unbond_pool
completion_time
{completionTime}
delegate_operator
delegator
{delegatorAddress}
delegate_operator
operator_id
{operatorID}
delegate_operator
amount
{delegationAmount}
delegate_operator
new_shares
{newShares}
unbond_operator
amount
{unbondAmount}
unbond_operator
delegator
{delegatorAddress}
unbond_operator
operator_id
{operatorID}
unbond_operator
completion_time
{completionTime}
delegate_service
delegator
{delegatorAddress}
delegate_service
service_id
{serviceID}
delegate_service
amount
{delegationAmount}
delegate_service
new_shares
{newShares}
unbond_service
amount
{unbondAmount}
unbond_service
delegator
{delegatorAddress}
unbond_service
service_id
{serviceID}
unbond_service
completion_time
{completionTime}
set_user_preferences
user
{userAddress}
The restaking module contains the following parameters:
UnbondingTime
string (time ns)
"259200000000000"
AllowedDenoms
[]string
{"utia", "uusdc"}
RestakingCap
sdkmath.LegacyDec
"259200000000000"
MaxEntries
uint32
7
ServiceJoinedByOperator stores the indexes to perform a reverse lookup of . It allows to obtain the list of operators that have joined a specific service.
PoolDelegation stores the delegations made toward a specific pool. It allows to perform a reverse lookup of .
OperatorDelegationsByOperatorID stores the delegations made toward a specific operator. It allows to perform a reverse lookup of .
ServiceDelegationsByServiceID stores the delegations made toward a specific service. It allows to perform a reverse lookup of .