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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Conversation

baitcode
Copy link

@baitcode baitcode commented Dec 10, 2024

Added library for Unsigned FixedPoint calculations. UFixedPoint supports basic mathematical operations.

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_seconds_per_total_staked: UFixedPoint
}

and in storage

staking_log: 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
…support Q128.128 FP.

Added cumulative seconds per total staked history value, and getter for that value
Added method that allows to calculate how much staked seconds would staked token amount generate
in between 2 timestamps: `calculate_staked_seconds_for_amount_between`
Added tiny amount of tests
* removed staked seconds calculation
* added seconds per total staked test and added logic for calculation of that value when nothing is staked
@baitcode baitcode marked this pull request as ready for review December 14, 2024 22:54
@baitcode
Copy link
Author

@moodysalem Could you, please, review?

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