IFAllocationMaster.sol
Launchpad allocation staking contract
This contract is responsible for giving allocation for staking tokens over time.
Users stake to specific tracks, where stake weight accrues. Stake weight increases over time proportional to stake amount. For each passing block, a user's stake weight increases by their staked amount the previous block (times a scaling constant).
A sale contract will calculate a user's allocation as their stake weight divided by the total stake weight (from a particular track).

Events

1
event AddTrack(string indexed name, address indexed token);
2
event DisableTrack(uint24 indexed trackId);
3
event ActiveRollOver(uint24 indexed trackId, address indexed user);
4
event BumpSaleCounter(uint24 indexed trackId, uint32 newCount);
5
event AddUserCheckpoint(uint24 indexed trackId, uint80 blockNumber);
6
event AddTrackCheckpoint(uint24 indexed trackId, uint80 blockNumber);
7
event Stake(uint24 indexed trackId, address indexed user, uint104 amount);
8
event Unstake(uint24 indexed trackId, address indexed user, uint104 amount);
Copied!

Public variables

trackFinishedSaleBlocks

1
mapping(uint24 => mapping(uint24 => uint80))
2
public trackFinishedSaleBlocks;
Copied!
The number of checkpoints of a track.
(track, finished sale count) => block number

trackActiveRollOvers

1
mapping(uint24 => mapping(address => mapping(uint24 => uint192)))
2
public trackActiveRollOvers;
Copied!
Stake weight each user actively rolls over for a given track and a finished sale count.
(track, user, finished sale count) => amount of stake weight

trackTotalActiveRollOvers

1
mapping(uint24 => mapping(uint24 => uint192))
2
public trackTotalActiveRollOvers;
Copied!
Total stake weight actively rolled over for a given track and a finished sale count.
(track, finished sale count) => total amount of stake weight

tracks

1
TrackInfo[] public tracks;
Copied!
Array of track information indexed by track number.

numTrackStakers

1
mapping(uint24 => uint256) public numTrackStakers;
Copied!
Number of unique stakers on a track.
(track) => staker count

trackStakers

1
mapping(uint24 => address[]) public trackStakers;
Copied!
Array of unique stakers on track.
(track) => address array

trackCheckpointCounts

1
mapping(uint24 => uint32) public trackCheckpointCounts;
Copied!
The number of checkpoints of a track.
(track) => checkpoint count

trackCheckpoints

1
mapping(uint24 => mapping(uint32 => TrackCheckpoint))
2
public trackCheckpoints;
Copied!
Track checkpoint mapping.
(track, checkpoint number) => TrackCheckpoint

userCheckpointCounts

1
mapping(uint24 => mapping(address => uint32))
2
public userCheckpointCounts;
Copied!
The number of checkpoints of a user for a track.
(track, user address) => checkpoint count

userCheckpoints

1
mapping(uint24 => mapping(address => mapping(uint32 => UserCheckpoint)))
2
public userCheckpoints;
Copied!
User checkpoint mapping.
(track, user address, checkpoint number) => UserCheckpoint

Functions

constructor

1
constructor() {}
Copied!
The constructor takes no parameters.

trackCount

1
function trackCount() external view returns (uint24)
Copied!
Gets the number of tracks.

addTrack

1
function addTrack(
2
string calldata name,
3
ERC20 stakeToken,
4
uint24 _weightAccrualRate,
5
uint64 _passiveRolloverRate,
6
uint64 _activeRolloverRate,
7
uint104 _maxTotalStake
8
) public onlyOwner
Copied!
Adds a new track.
Note: Weight accrual rate is essentially a scaling constant for calculating stake weights. Mathematically, for each block that passes, a user's stake weight increases as follows:
previous block staked amount * weight accrual rate / 10**18
The main purpose of weight accrual rate is for scaling precision, making sure even small staked amounts don't accrue 0 weight every block. Since weight accrual rate is uint24 (and it cannot be set to 0), stake weight increase per block is limited to the following range:
    Min: previous block staked amount / 10**18
    Max: previous block staked amount * 10**6
This is limited enough to allow weight accrual rate to increase precision without a big risk of causing overflow in stake weight.

bumpSaleCounter

1
function bumpSaleCounter(uint24 trackId) public onlyOwner
Copied!
Bumps a track's finished sale counter.

disableTrack

1
function disableTrack(uint24 trackId) public onlyOwner
Copied!
Disables a track.

activeRollOver

1
function activeRollOver(uint24 trackId) public
Copied!
Perform active rollover.

getUserStakeWeight

1
function getUserStakeWeight(
2
uint24 trackId,
3
address user,
4
uint80 blockNumber
5
) public view returns (uint104)
Copied!
Gets a user's stake weight within a track at a particular block number.

getTotalStakeWeight

1
function getTotalStakeWeight(uint24 trackId, uint80 blockNumber)
2
public
3
view
4
returns (uint104)
Copied!
Gets total stake weight within a track at a particular block number.

stake

1
function stake(uint24 trackId, uint104 amount) external
Copied!
Stakes on a track.

unstake

1
function unstake(uint24 trackId, uint104 amount) external
Copied!
Unstakes from a track.

Other useful notes

Getting user's stake amount in a track

This can be obtained with the following steps:
    1.
    Get the number of checkpoints for the user checkpointCount = userCheckpointCounts[track ID][user address]
    2.
    Get the user's latest checkpoint:latestCheckpoint = userCheckpoints[track ID][user address][checkpointPount-1]
    3.
    Get the user's current staked amount via the staked field on the latest checkpoint.
Last modified 1mo ago