Table of contents
- Diagrams
- Staking contract
- Functions
- stake
- increase_stake
- unstake_intent
- unstake_action
- claim_rewards
- add_stake_from_pool
- remove_from_delegation_pool_intent
- remove_from_delegation_pool_action
- switch_staking_delegation_pool
- change_reward_address
- set_open_for_delegation
- claim_delegation_pool_rewards
- staker_info
- contract_parameters
- get_total_stake
- update_rewards
- declare_operational_address
- change_operational_address
- update_global_index_if_needed
- is_paused
- pause
- unpause
- Events
- Functions
- Delegation pool contract
- L2 Reward supplier contract
- Minting Curve Contract
- Errors
- STAKER_EXISTS
- STAKER_NOT_EXISTS
- OPERATIONAL_EXISTS
- AMOUNT_LESS_THAN_MIN_STAKE
- COMMISSION_OUT_OF_RANGE
- CONTRACT_IS_PAUSED
- UNSTAKE_IN_PROGRESS
- CALLER_CANNOT_INCREASE_STAKE
- MISSING_UNSTAKE_INTENT
- INTENT_WINDOW_NOT_FINISHED
- UNEXPECTED_BALANCE
- FINAL_STAKER_INDEX_ALREADY_SET
- CLAIM_REWARDS_FROM_UNAUTHORIZED_ADDRESS
- CALLER_IS_NOT_POOL_CONTRACT
- MISSING_POOL_CONTRACT
- AMOUNT_TOO_HIGH
- MISSMATCHED_DELEGATION_POOL
- MISSING_UNDELEGATE_INTENT
- STAKER_ALREADY_HAS_POOL
- STAKER_INACTIVE
- POOL_MEMBER_EXISTS
- AMOUNT_IS_ZERO
- POOL_MEMBER_DOES_NOT_EXIST
- UNDELEGATE_IN_PROGRESS
- CALLER_CANNOT_ADD_TO_POOL
- POOL_CLAIM_REWARDS_FROM_UNAUTHORIZED_ADDRESS
- CALLER_IS_NOT_STAKING_CONTRACT
- SWITCH_POOL_DATA_DESERIALIZATION_FAILED
- ONLY_SECURITY_AGENT
- ONLY_SECURITY_ADMIN
- INVALID_UNDELEGATE_INTENT_VALUE
- OPERATIONAL_NOT_ELIGIBLE
- Structs
classDiagram
class StakingContract{
map < staker_address, Option < StakerInfo >>
map < operational_address, staker_address >
global_index
global_index_last_update_timestamp
min_stake
total_stake
pool_contract_class_hash
map < UndelegateIntentKey, UndelegateIntentValue >
pool_contract_admin
is_paused
stake()
increase_stake()
unstake_intent()
unstake_action()
claim_rewards()
add_stake_from_pool()
remove_from_delegation_pool_intent()
remove_from_delegation_pool_action()
switch_staking_delegation_pool()
change_reward_address()
change_operational_address()
set_open_for_delegation()
claim_delegation_pool_rewards()
staker_info()
contract_parameters()
update_rewards()
get_total_stake()
}
class DelegationPoolContract{
map < pool_member_address, PoolMemberInfo >
staker_address
final_staker_index
map < ContractAddress, Option < PoolMemberInfo >>
commission
enter_delegation_pool()
add_to_delegation_pool()
exit_delegation_pool_intent()
exit_delegation_pool_action()
claim_rewards()
change_reward_address()
pool_member_info()
contract_parameters()
switch_delegation_pool()
enter_delegation_pool_from_staking_contract()
set_final_staker_index()
update_rewards()
}
class StakerInfo{
reward_address
operational_address
option < unstake_time >
amount_own
index
pooled_amount
unclaimed_rewards_own
pooled_unclaimed_rewards
option < StakerPoolInfo >
}
class StakerPoolInfo{
pool_contract
amount
unclaimed_rewards
commission
}
class PoolMemberInfo{
reward_address
amount
index
unclaimed_rewards
option < unpool_time >
}
class RewardSupplier {
last_timestamp,
unclaimed_rewards,
l1_pending_requested_amount,
base_mint_amount,
base_mint_msg,
minting_curve_dispatcher,
staking_contract,
erc20_dispatcher,
l1_staking_minter,
calculate_staking_rewards()
claim_rewards()
on_receive()
contract_parameters()
}
class MintingCurve {
staking_dispatcher,
total_supply,
l1_staking_minter_address,
yearly_mint()
}
StakingContract o-- StakerInfo
StakerInfo o-- StakerPoolInfo
DelegationPoolContract o-- PoolMemberInfo
StakingContract o-- RewardSupplier
RewardSupplier o-- MintingCurve
classDiagram
class RewardSupplier {
tick()
}
class MintManager {
mintRequest()
allowance()
approve()
increaseAllowance()
decreaseAllowance()
stopAllowance()
}
sequenceDiagram
actor staker
participant StakingContract
participant DelegationPoolContract
actor pool member
staker ->>+ StakingContract: stake<br/>(pool enabled = true)
StakingContract -->> DelegationPoolContract: deploy delegation pool contract
par
loop
staker ->> StakingContract: increase_stake
end
and
loop
pool member ->>+ DelegationPoolContract: enter_delegation_pool
DelegationPoolContract ->>- StakingContract: add_stake_from_pool
loop
pool member ->>+ DelegationPoolContract: add_to_delegation_pool
DelegationPoolContract ->>- StakingContract: add_stake_from_pool
end
end
end
sequenceDiagram
actor staker
participant StakingContract
participant DelegationPoolContract
actor pool member
opt Loop
pool member ->>+ DelegationPoolContract: exit_delegation_pool_intent
DelegationPoolContract ->>- StakingContract: remove_from_delegation_pool_intent
pool member ->>+ DelegationPoolContract: exit_delegation_pool_action
DelegationPoolContract ->>- StakingContract: remove_from_delegation_pool_action
end
staker ->> StakingContract: unstake_intent
staker ->> StakingContract: unstake_action
opt Loop
pool member ->>+ DelegationPoolContract: exit_delegation_pool_intent
DelegationPoolContract ->>- StakingContract: remove_from_delegation_pool_intent
pool member ->>+ DelegationPoolContract: exit_delegation_pool_action
DelegationPoolContract ->>- StakingContract: remove_from_delegation_pool_action
end
sequenceDiagram
actor staker
participant RewardSupplier
participant StakingContract
participant DelegationPoolContract
actor pool member
Loop
staker ->> StakingContract: claim_rewards
StakingContract ->>+ RewardSupplier: claim_rewards
RewardSupplier -->> StakingContract: Transfer
StakingContract -->> staker: Transfer
end
opt Loop
pool member ->>+ DelegationPoolContract: claim_rewards
DelegationPoolContract ->>+ StakingContract: claim_delegation_pool_rewards
StakingContract ->>+ RewardSupplier: claim_rewards
RewardSupplier -->> StakingContract: Transfer
StakingContract -->> DelegationPoolContract: Transfer
DelegationPoolContract -->> pool member: Transfer
end
sequenceDiagram
participant DelegationPoolContract B
participant StakingContract
participant DelegationPoolContract A
actor pool member
pool member ->>+ DelegationPoolContract A: exit_delegation_pool_intent
DelegationPoolContract A ->>- StakingContract: remove_from_delegation_pool_intent
pool member ->>+ DelegationPoolContract A: switch_delegation_pool
DelegationPoolContract A ->>+ StakingContract: switch_staking_delegation_pool
StakingContract ->>- DelegationPoolContract B: enter_delegation_pool_from_staking_contract
deactivate DelegationPoolContract A
loop
Note left of StakingContract: optional for switching some<br/> of the funds but keeping the rest<br/> with the original stakeror splitting<br/> between multiple stakers
pool member ->>+ DelegationPoolContract A: switch_delegation_pool
DelegationPoolContract A ->> StakingContract: switch_staking_delegation_pool
StakingContract ->> DelegationPoolContract B: enter_delegation_pool_from_staking_contract
deactivate DelegationPoolContract A
end
sequenceDiagram
actor anyAccount
participant RewardSupplier
participant MintingManager
participant STRK ERC20
participant StarkGate bridge
anyAccount ->>+ RewardSupplier: tick(tokensPerMintAmount, maxMessagesToProcess)
RewardSupplier ->>+ MintingManager: mintRequest(totalAmountToMint)
MintingManager ->>- STRK ERC20: mint
RewardSupplier ->>+ StarkGate bridge: depositWithMessage
deactivate RewardSupplier
sequenceDiagram
actor caller
participant Staking
participant RewardSupplier
participant MintingCurve
participant L1
caller ->>+ Staking: update_global_index
Staking ->>+ RewardSupplier: calculate_staking_rewards
RewardSupplier ->>+ MintingCurve: yearly_mint
MintingCurve ->> Staking: get_total_stake
MintingCurve -->>- RewardSupplier: return yearly amount
RewardSupplier ->>- L1: send mint request
deactivate Staking
fn stake(
ref self: TContractState,
reward_address: ContractAddress,
operational_address: ContractAddress,
amount: u128,
pool_enabled: bool,
commission: u16
)
Add a new staker to the stake.
- New Delegation Pool - if
pool_enabled
is true - New Staker
- Stake Balance Changed
- CONTRACT_IS_PAUSED
- STAKER_EXISTS
- OPERATIONAL_EXISTS
- AMOUNT_LESS_THAN_MIN_STAKE
- COMMISSION_OUT_OF_RANGE
- Staking contract is unpaused.
- Staker (caller) is not listed in the contract.
operational_address
is not listed in the contract.amount
is above the minimum amount for staking.commission
is not above the maximum commission for staking.
Only staker address.
- Transfer amount from staker to be locked in the contract.
- Create a new registry for the staker (caller).
- Set:
- Staker index = current global index.
- Unclaimed amount = 0.
- amount = given amount.
- If pool enabled then deploy a pool contract instance.
fn increase_stake(
ref self: ContractState,
staker_address: ContractAddress,
amount: u128
) -> u128
Increase the amount staked for an existing staker. Return the updated total amount.
- Staking contract is unpaused.
- Staker is listed in the contract.
- Staker is not in an exit window.
Only the staker address or rewards address for which the change is requested for.
- Update rewards.
- Increase staked amount.
fn unstake_intent(ref self: ContractState) -> u64
Inform of the intent to exit the stake. This will remove the funds from the stake, pausing rewards collection for the staker and it's pool members (if exist). This will also start the exit window timeout. Return the time in which the staker will be able to unstake.
- Staking contract is unpaused.
- Staker (caller) is listed in the contract.
- Staker (caller) is not in an exit window.
Only the staker address for which the operation is requested for.
- Update rewards.
- Set unstake time.
fn unstake_action(
ref self: ContractState,
staker_address: ContractAddress
) -> u128
Executes the intent to exit the stake if enough time have passed. Transfers the funds back to the staker. Return the amount of tokens transferred back to the staker.
- Staker Reward Claimed
- If pool exists: Rewards Supplied To Delegation Pool
- If pool exists: Final Index Set
- Delete Staker
- CONTRACT_IS_PAUSED
- STAKER_NOT_EXISTS
- MISSING_UNSTAKE_INTENT
- INTENT_WINDOW_NOT_FINISHED
- UNEXPECTED_BALANCE
- FINAL_STAKER_INDEX_ALREADY_SET
- Staking contract is unpaused.
- Staker exist and requested to unstake.
- Enough time have passed from the unstake intent call.
Any address can execute.
- Claim rewards.
- Remove funds and transfer to staker.
- Transfer pool unclaimed rewards and stake to delegation pool contract.
- Call set_final_staker_index on the delegation_pool_contract.
- Delete staker record.
fn claim_rewards(
ref self: ContractState,
staker_address: ContractAddress
) -> u128
Update rewards and transfer them to the reward address. Return the amount of tokens transferred to the reward address.
- Staking contract is unpaused.
- Staker is listed in the contract.
Only staker address or reward address can execute.
- Update rewards.
- Transfer unclaimed_rewards.
- Set unclaimed_rewards = 0.
fn add_stake_from_pool(
ref self: ContractState,
staker_address: ContractAddress,
amount: u128
) -> u128
Delegation pool contract's way to add funds to the staking pool.
index: u128 - updated index
- CONTRACT_IS_PAUSED
- STAKER_NOT_EXISTS
- UNSTAKE_IN_PROGRESS
- MISSING_POOL_CONTRACT
- CALLER_IS_NOT_POOL_CONTRACT
- Staking contract is unpaused.
- Staker is listed in the contract.
- Staker is not in an exit window.
- Staker has pool contract.
Only pool contract for the given staker can execute.
- Update rewards
- transfer funds from pool contract to staking contract.
- Add amount to staker's pooled amount
fn remove_from_delegation_pool_intent(
ref self: ContractState,
staker_address: ContractAddress,
identifier: felt252,
amount: u128,
) -> u64
Inform the staker that an amount will be reduced from the delegation pool. Return the time in which the pool member will be able to exit.
- CONTRACT_IS_PAUSED
- INVALID_UNDELEGATE_INTENT_VALUE
- STAKER_NOT_EXISTS
- MISSING_POOL_CONTRACT
- CALLER_IS_NOT_POOL_CONTRACT
- AMOUNT_TOO_HIGH
- Staking contract is unpaused.
- Staker is listed in the contract.
- Staker has pool contract.
- Pooled amount is greater or equal then amount requested to remove.
Only pool contract for the given staker can execute.
- Update rewards.
- Remove amount from staker's pooled amount.
- Register intent with given identifier, amount and unstake_time.
fn remove_from_delegation_pool_action(
ref self: ContractState,
identifier: felt252
)
Execute the intent to remove funds from pool if enough time have passed. Transfers the funds to the pool contract.
- Staking contract is unpaused.
- Removal intent request with the given
identifier
have been sent before. - Enough time have passed since the intent request.
Any address can execute.
- Transfer funds from staking contract to pool contract.
- Remove intent from staker's list.
fn switch_staking_delegation_pool(
ref self: ContractState,
to_staker: ContractAddress,
to_pool: ContractAddress,
switched_amount: u128,
data: Span<felt252>,
identifier: felt252
)
Execute a pool member request to move from one staker's delegation pool to another staker's delegation pool.
- CONTRACT_IS_PAUSED
- INVALID_UNDELEGATE_INTENT_VALUE
- MISSING_UNDELEGATE_INTENT
- AMOUNT_TOO_HIGH
- STAKER_NOT_EXISTS
- UNSTAKE_IN_PROGRESS
- MISSING_POOL_CONTRACT
- MISSMATCHED_DELEGATION_POOL
- Staking contract is unpaused.
switched_amount
is not zero.- Enough funds is in intent for switching.
to_staker
exist in the contract and is not in exit window.to_pool
is the delegation pool contract forto_staker
.
Only pool contract for the given staker can execute.
- Update rewards.
- Remove requested amount from the caller pool intent amount.
- Add requested amount to
to_staker
's pool with pool contract addressto_pool
. - Call
to_pool
's enter_delegation_pool_from_staking_contract function.
fn change_reward_address(
ref self: ContractState,
reward_address: ContractAddress
)
Change the reward address for a staker.
- Staking contract is unpaused.
- Staker (caller) exist in the contract.
Only staker address.
- Change registered
reward_address
for the staker.
fn set_open_for_delegation(
ref self: ContractState,
commission: u16
) -> ContractAddress
Creates a staking delegation pool for a staker that doesn't have one. Return the pool address.
- Staking contract is unpaused.
- Staker (caller) exist in the contract.
commission
is in valid range.- Staker has no pool.
Only staker address.
- Generate pool contract for staker.
- Register pool.
fn claim_delegation_pool_rewards(
ref self: ContractState,
staker_address: ContractAddress
) -> u64
Update rewards and transfer the delegation pool rewards to the delegation pool contract. Return the updated staker index.
Rewards Supplied To Delegation Pool
- CONTRACT_IS_PAUSED
- STAKER_NOT_EXISTS
- MISSING_POOL_CONTRACT
- CALLER_IS_NOT_POOL_CONTRACT
- AMOUNT_TOO_HIGH
- UNEXPECTED_BALANCE
- Staking contract is unpaused.
- Staker exist in the contract.
- Delegation pool exist for the staker.
Delegation pool contract of the given staker.
- Update rewards
- Transfer rewards to pool contract.
fn staker_info(
self: @ContractState,
staker_address: ContractAddress
) -> StakerInfo
Return StakerInfo of the given staker.
- Staker exist in the contract.
Any address can execute.
- Return Staker's info.
fn contract_parameters(self: @ContractState) -> StakingContractInfo
Return general parameters of the contract.
get_total_stake(self: @ContractState) -> u128
Return the total stake amount.
note: internal logic
fn update_rewards(
ref self: ContractState,
ref staker_info: StakerInfo
)
Update rewards, add amount to unclaimed_rewards, update index.
Internal function.
- If Staker is in an exit window, return false.
- Update index.
- Update rewards for
amount_own
. - Update rewards for
pool_info.amount
. - Update
unclaimed_rewards_own
with own rewards + pool rewards commission. - Update
pool_info.unclaimed_rewards
with pool rewards without commission.
fn declare_operational_address(
ref self: ContractState,
staker_address: ContractAddress
)
Allows staker_address
to use the caller's address in the future, in change_operational_address
.
- Staking contract is unpaused.
- Set the caller as an eligible operational address, associated with
staker_address
.
fn change_operational_address(
ref self: ContractState,
operational_address: ContractAddress
)
Change the operational address for a staker.
- Staking contract is unpaused.
- Staker (caller) exist in the contract.
Only staker address.
- Change registered
operational_address
for the staker.
fn update_global_index_if_needed(ref self: TContractState) -> bool
Update the global index if enough time has passed since the last update.
This function is called in every staking function that alter the state.
Return true
if the index has been updated.
- Staking contract is unpaused.
Any address can execute.
- Check if enough time has passed since the last update, if not, return
false
. - calculate_staking_rewards.
- get_total_stake.
- Update the global index.
fn is_paused(self: @TContractState) -> bool
Return true
if the staking contract is paused.
Any address can execute.
fn pause(ref self: TContractState)
Pause the staking contract.
Only security agent.
fn unpause(ref self: TContractState)
Unpause the staking contract.
Only security admin.
data | type | keyed |
---|---|---|
staker_address | address | ✅ |
old_self_stake | u128 | ❌ |
old_delegated_stake | u128 | ❌ |
new_self_stake | u128 | ❌ |
new_delegated_stake | u128 | ❌ |
data | type | keyed |
---|---|---|
staker_address | address | ✅ |
pool_contract | address | ✅ |
commission | u16 | ❌ |
data | type | keyed |
---|---|---|
staker_address | address | ✅ |
reward_address | address | ❌ |
operational_address | address | ❌ |
self_stake | u128 | ❌ |
data | type | keyed |
---|---|---|
staker | address | ✅ |
exit_at | time | ❌ |
data | type | keyed |
---|---|---|
staker_address | address | ✅ |
pool_address | address | ✅ |
amount | u128 | ❌ |
data | type | keyed |
---|---|---|
staker_address | address | ✅ |
reward_address | address | ❌ |
operational_address | address | ❌ |
pool_contract | Option | ❌ |
data | type | keyed |
---|---|---|
staker_address | address | ✅ |
reward_address | address | ❌ |
amount | u128 | ❌ |
data | type | keyed |
---|---|---|
staker_address | address | ✅ |
new_address | address | ❌ |
old_address | address | ❌ |
data | type | keyed |
---|---|---|
operational_address | address | ✅ |
staker_address | address | ✅ |
data | type | keyed |
---|---|---|
staker_address | address | ✅ |
new_address | address | ❌ |
old_address | address | ❌ |
data | type | keyed |
---|---|---|
old_index | u64 | ❌ |
new_index | u64 | ❌ |
global_index_last_update_timestamp | u64 | ❌ |
global_index_current_update_timestamp | u64 | ❌ |
data | type | keyed |
---|---|---|
account | address | ❌ |
data | type | keyed |
---|---|---|
account | address | ❌ |
fn enter_delegation_pool(
ref self: ContractState,
reward_address: ContractAddress,
amount: u128
)
Add a new pool member to the delegation pool.
- Staker is active and not in an exit window.
caller_address
is not listed in the contract as a pool member.amount
is not zero.caller_address
has enough funds.
Only a non-listed pool member address.
- Transfer funds from pool member to pool contract.
- Approve transferal from pool contract to staking contract.
- Call staking contract's add_stake_from_pool.
- Get current index from staking contract.
- Create entry for pool member.
fn add_to_delegation_pool(
ref self: ContractState,
pool_member: ContractAddress,
amount: u128
) -> u128
Increase the funds for an existing pool member. Return the updated total amount.
- Staker is active and not in an exit window.
pool_member
listed in the contract.pool_member
has enough funds.
Only the pool member address or rewards address for which the change is requested for.
- Transfer funds from caller to the contract.
- Call staking contract's add_stake_from_pool.
- Get current index from staking contract.
- Update rewards
- Update pool member entry with
- index
- amount
- unclaimed rewards
fn exit_delegation_pool_intent(
ref self: ContractState,
amount: u128
)
Inform of the intent to exit the stake. This will remove the funds from the stake, pausing rewards collection for the pool member. This will also start the exit window timeout.
- If staker is active: Rewards Supplied To Delegation Pool
- If staker is active: Stake Balance Changed
- Pool Member Exit Intent
- Pool member (caller) is listed in the contract.
amount
is lower or equal to the total amount of the pool member (caller).- Pool member (caller) is not in an exit window or staker is active.
- Staking contract is unpaused.
Only the pool member address for which the operation is requested for.
- Update rewards
- If staker is active, call remove from delegation pool intent
- If
amount
is zero, remove request for intent (if exist). - If
amount
is not zero, set exit window timeout.
fn exit_delegation_pool_action(
ref self: ContractState,
pool_member: ContractAddress
) -> u128
Executes the intent to exit the stake if enough time have passed. Transfers the funds back to the pool member. Return the amount of tokens transferred back to the pool member.
- Pool member exist and requested to unstake.
- Enough time have passed from the delegation pool exit intent call.
Any address can execute.
- Remove from delegation pool action.
- Transfer rewards to pool member.
- Transfer funds to pool member.
fn claim_rewards(
ref self: ContractState,
pool_member: ContractAddress
) -> u128
Update rewards and transfer them to the reward address. Return the amount transferred to the reward address.
- POOL_MEMBER_DOES_NOT_EXIST
- POOL_CLAIM_REWARDS_FROM_UNAUTHORIZED_ADDRESS
- CONTRACT_IS_PAUSED
- UNEXPECTED_BALANCE
- AMOUNT_TOO_HIGH
pool_member
is listed in the contract.
Only pool member address or reward address can execute.
- Update rewards.
- Transfer unclaimed_rewards
- Set unclaimed_rewards = 0.
fn switch_delegation_pool(
ref self: ContractState,
to_staker: ContractAddress,
to_pool: ContractAddress,
amount: u128
) -> u128
Request the staking contract to move a pool member to another pool contract. Return the amount left in exit window for the pool member in this pool.
- Delegation Pool Member Balance Changed
- If pool member amount and intent amount are zero: Delete Pool Member
- AMOUNT_IS_ZERO
- POOL_MEMBER_DOES_NOT_EXIST
- MISSING_UNDELEGATE_INTENT
- AMOUNT_TOO_HIGH
- CONTRACT_IS_PAUSED
- UNSTAKE_IN_PROGRESS
- MISSMATCHED_DELEGATION_POOL
amount
is not zero.- Pool member (caller) is in exit window.
- Pool member's amount is greater or equal to the amount requested.
to_staker
exist in the staking contract and is not in an exit window.to_pool
is the delegation pool contract forto_staker
.
Only pool member can execute.
- Compose and serialize data: pool member address and reward address.
- If pool member amount and intent amount are zero, transfer rewards to pool member and remove him from the pool.
- Call staking contract's switch delegation pool.
fn enter_delegation_pool_from_staking_contract(
ref self: ContractState,
amount: u128,
index: u64,
data: Span<felt252>
)
Entry point for staking contract to inform pool of a pool member being moved from another pool to this one. No funds need to be transferred since staking contract holds the pool funds.
amount
is not zero.pool_member
is not in an exit window.
Only staking contract can execute.
- Deserialize data, get
pool_member
andrewrad_address
. - If pool member is listed in the contract:
- Update rewards
- Update pool member entry
- Else
- Create an entry for the pool member.
fn set_final_staker_index(
ref self: ContractState,
final_staker_index: u64
)
Informs the delegation pool contract that the staker has left and the contract is now detached from the staking contract.
- Final staker index is not already set.
Only staking contract can execute.
- Set staker final index to the provided index.
fn change_reward_address(
ref self: ContractState,
reward_address: ContractAddress
)
Change the reward address for a pool member.
- Pool member exist in the contract.
Only pool member can execute.
- Change registered
reward_address
for the pool member.
fn pool_member_info(
self: @ContractState,
pool_member: ContractAddress
) -> PoolMemberInfo
Return PoolMemberInfo of the given pool member.
- Pool member exist in the contract.
Any address can execute.
- Return Pool member info.
fn contract_parameters(self: @ContractState) -> StakingContractInfo
Return PoolContractInfo of the contract.
fn update_rewards(
ref self: ContractState,
ref pool_member_info: PoolMemberInfo,
updated_index: u64
)
note: internal logic
Update rewards, add amount to unclaimed_rewards, update index.
internal function.
- Update index.
- Update rewards for
pool_member_info
. - Update
unclaimed_rewards
.
data | type | keyed |
---|---|---|
staker | address | ✅ |
pool_member | address | ✅ |
amount | u128 | ❌ |
data | type | keyed |
---|---|---|
pool_member | address | ✅ |
old_delegated_stake | u128 | ❌ |
new_delegated_stake | u128 | ❌ |
data | type | keyed |
---|---|---|
pool_member | address | ✅ |
exit_at | time | ❌ |
data | type | keyed |
---|---|---|
staker_address | address | ✅ |
final_staker_index | u64 | ❌ |
data | type | keyed |
---|---|---|
pool_member | address | ✅ |
staker_address | address | ✅ |
reward_address | address | ❌ |
amount | u128 | ❌ |
data | type | keyed |
---|---|---|
pool_member | address | ✅ |
reward_address | address | ❌ |
data | type | keyed |
---|---|---|
pool_member | address | ✅ |
reward_address | address | ✅ |
amount | u128 | ❌ |
data | type | keyed |
---|---|---|
pool_member | address | ✅ |
new_address | address | ❌ |
old_address | address | ❌ |
fn calculate_staking_rewards(ref self: TContractState) -> u128
Calculate the total amount of rewards owed to the stakers (based on total stake), since the previous time it was calculated.
rewards: u128 - the rewards owed to stakers, in FRI.
- Invoke the Minting Curve's yearly_mint to receive the theoretic yearly amount of rewards.
- From the theoretic yearly amount, deduce the rewards from the last timestamp.
- Request funds from L1 if needed.
Only staking contract.
fn claim_rewards(ref self: TContractState, amount: u128)
Transfers amount
FRI to staking contract
unclaimed_rewards >= amount
- Transfer
amount
FRI to staking contract and decrease it from unclaimed_rewards.
Only staking contract.
fn contract_parameters(self: @TContractState) -> RewardSupplierInfo
Return RewardSupplierInfo filled with the corresponding storage values.
Any address can execute.
fn on_receive(
ref self: TContractState,
l2_token: ContractAddress,
amount: u256,
depositor: EthAddress,
message: Span<felt252>
)
Get notified by StarkGate amount
was transferred from L1.
Return true upon success.
The function will fail only in the unlikely scenario where amount
is over 2**128 FRI.
- Decrease
amount
from l1_pending_requested_amount. If the expected result is negative, the variable is set to 0.
data | type | keyed |
---|---|---|
total_amount | u128 | ❌ |
num_msgs | u128 | ❌ |
fn yearly_mint(self: @TContractState) -> u128
Return the amount to be minted in a year given the current total stake in the staking contract.
- get_total_stake.
- Compute the yearly mint by using total_stake and total_supply.
Any address can execute.
data | type | keyed |
---|---|---|
old_total_supply | u128 | ❌ |
new_total_supply | u128 | ❌ |
"Staker already exists, use increase_stake instead."
"Staker does not exist."
"Operational address already exists."
"Amount is less than min stake - try again with enough funds."
"Commission is out of range, expected to be 0-10000."
"Contract is paused."
"Unstake is in progress, staker is in an exit window."
"Caller address should be staker address or reward address."
"Unstake intent is missing."
"Intent window is not finished."
"Unexpected balance."
"Final staker index already set."
"Claim rewards must be called from staker address or reward address."
"Caller is not pool contract."
"Staker does not have a pool contract."
"Amount is too high."
"to_pool is not the delegation pool contract for to_staker."
"Undelegate intent is missing."
"Staker already has a pool."
"Staker inactive."
"Pool member exists, use add_to_delegation_pool instead."
"Amount is zero."
"Pool member does not exist."
"Undelegate from pool in progress, pool member is in an exit window."
"Caller address should be pool member address or reward address."
"Claim rewards must be called from pool member address or reward address."
"Caller is not staking contract."
"Switch pool data deserialization failed."
"ONLY_SECURITY_AGENT"
"ONLY_SECURITY_ADMIN"
"Invalid undelegate intent value"
"Operational address had not been declared by staker"
name | type |
---|---|
pool_contract | address |
amount | u128 |
unclaimed_rewards | u128 |
commission | u16 |
name | type |
---|---|
reward_address | address |
operational_address | address |
unstake_time | Option |
amount_own | u128 |
index | u64 |
unclaimed_rewards_own | u128 |
pool_info | Option |
name | type |
---|---|
min_stake | u128 |
token_address | address |
global_index | u64 |
pool_contract_class_hash | ClassHash |
reward_supplier | address |
name | type |
---|---|
reward_address | address |
amount | u128 |
index | u64 |
unclaimed_rewards | u128 |
unpool_amount | u128 |
unpool_time | Option |
name | type |
---|---|
staker_address | address |
final_staker_index | Option |
staking_contract | address |
token_address | address |
commission | u16 |
name | type |
---|---|
last_timestamp | u64 |
unclaimed_rewards | u128 |
l1_pending_requested_amount | u128 |