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

[WIP] Feat staker v2 #63

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft

Conversation

baitcode
Copy link

@baitcode baitcode commented Dec 10, 2024

Added new method to staker interface:

fn get_staked_seconds_at(self: @TContractState, staker: ContractAddress, timestamp: u64) -> u128;

Allows to calculate staked amount. If address staked 100 tokens for 10 seconds, that would be 1000 staked seconds. Fractions of a second are rounded down. Only full seconds count. Added additional data structure:

#[derive(Drop, Serde, starknet::Store)]
struct StakingLogRecord {
    timestamp: u64,
    total_staked: u128,
    cumulative_staked_per_second: u128
}

and in storage

staking_log: Map<ContractAddress, Vec<StakingLogRecord>>

and population logic into stake and withdraw methods. All searches in those logs are binary.

Closes: #61

@baitcode baitcode marked this pull request as draft December 10, 2024 21:04
@baitcode baitcode marked this pull request as ready for review December 11, 2024 21:28
@baitcode baitcode marked this pull request as draft December 11, 2024 21:46
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.

staker v2: track historical total staked and historical seconds/staked
1 participant