Smart Contract
List of hPAL smart contract methods.
ERC20 basic methods:
This contract inherits the basic ERC20 methods:
Read-only:
name()
symbol()
decimals()
balanceOf()
totalSupply()
allowance()
Write:
approve()
increaseAllowance()
decreaseAllowance()
transfer()
transferFrom()
And emit the basic ERC20 Events.
Read-Only methods:
Structs:
UserLock
Lock of an user
type | name | desc |
---|---|---|
uint128 | amount | Amount of locked balance |
uint48 | startTimestamp | Start of the Lock |
uint48 | duration | Duration of the Lock |
uint32 | fromBlock | BlockNumber for the Lock |
TotalLock
Struct tracking the total amount locked
type | name | desc |
---|---|---|
uint224 | total | Total locked Supply |
uint32 | fromBlock | BlockNumber for the last update |
Checkpoint
Checkpoints for users votes
type | name | desc |
---|---|---|
uint32 | fromBlock | BlockNumber for the last update |
uint224 | votes | Amount of vote of the user |
DelegateCheckpoint
Checkpoints for users Delegates
type | name | desc |
---|---|---|
uint32 | fromBlock | BlockNumber for the last update |
address | delegate | Address of the delegate |
Constants:
WEEK
uint256 public constant WEEK = 604800;
Seconds in a Week
MONTH
uint256 public constant MONTH = 2629800;
Seconds in a Month
ONE_YEAR
uint256 public constant ONE_YEAR = 31557600;
Seconds in a Year
UNIT
uint256 public constant UNIT = 1e18;
1e18 scale
MAX_BPS
uint256 public constant MAX_BPS = 10000;
Max BPS value (100%)
COOLDOWN_PERIOD
uint256 public constant COOLDOWN_PERIOD = 864000; // 10 days
Period to wait before unstaking tokens
UNSTAKE_PERIOD
uint256 public constant UNSTAKE_PERIOD = 172800; // 2 days
Duration of the unstaking period. After that period, unstaking cooldown is expired
UNLOCK_DELAY
uint256 public constant UNLOCK_DELAY = 1209600; // 2 weeks
Period to unlock/re-lock tokens without possibility of punishement
MIN_LOCK_DURATION
uint256 public constant MIN_LOCK_DURATION = 7889400; // 3 months
Minimum duration of a Lock
MAX_LOCK_DURATION
uint256 public constant MAX_LOCK_DURATION = 63115200; // 2 years
Maximum duration of a Lock
Immutables:
pal
IERC20 pal
Address of the PAL token
rewardsVault
address rewardsVault
Address of the vault holding the PAL rewards
startDropPerSecond
uint256 startDropPerSecond
Amount of rewards distributed per second at the start
dropDecreaseDuration
uint256 dropDecreaseDuration
Duration (in seconds) of the DropPerSecond decrease period
startDropTimestamp
uint256 startDropTimestamp
Timestamp: start of the DropPerSecond decrease period
baseLockBonusRatio
uint256 baseLockBonusRatio
Base reward multiplier for lock
minLockBonusRatio
uint256 minLockBonusRatio
Minimum reward multiplier for minimum lock duration
maxLockBonusRatio
uint256 maxLockBonusRatio
Maximum reward multiplier for maximum duration
Storage:
userLocks
mapping(address => UserLock[]) userLocks
Array of all user Locks, ordered from oldest to newest (only the las Lock is the one active)
currentTotalLocked
uint256 currentTotalLocked
Current Total locked Supply
totalLocks
TotalLock[] totalLocks
List of TotalLocks, ordered from oldest to newest
cooldowns
mapping(address => uint256) cooldowns
User Cooldowns
delegates
mapping(address => address) delegates
mapping tracking the Delegator for each Delegatee
checkpoints
mapping(address => Checkpoint[]) checkpoints
List of Vote checkpoints for each user
delegateCheckpoints
mapping(address => DelegateCheckpoint[]) delegateCheckpoints
List of Delegate checkpoints for each user
kickRatioPerWeek
uint256 kickRatioPerWeek
Ratio (in BPS) of locked balance applied of penalty for each week over lock end
bonusLockVoteRatio
uint256 bonusLockVoteRatio
Ratio of bonus votes applied on user locked balance
emergency
bool emergency
Allow emergency withdraws
rewardIndex
uint256 rewardIndex
Global reward index
lastRewardUpdate
uint256 lastRewardUpdate
Timestamp of last update for global reward index
endDropPerSecond
uint256 endDropPerSecond
Amount of rewards distributed per second at the end of the decrease duration
currentDropPerSecond
uint256 currentDropPerSecond
Current amount of rewards distributed per second
lastDropUpdate
uint256 lastDropUpdate
Timestamp of last update for currentDropPerSecond
userRewardIndex
mapping(address => uint256) userRewardIndex
Last reward index for each user
claimableRewards
mapping(address => uint256) claimableRewards
Current amount of rewards claimable for the user
rewardsLastUpdate
mapping(address => uint256) rewardsLastUpdate
Timestamp of last update for user rewards
userCurrentBonusRatio
mapping(address => uint256) userCurrentBonusRatio
Last updated Bonus Ratio for rewards
userBonusRatioDecrease
mapping(address => uint256) userBonusRatioDecrease
Value by which user Bonus Ratio decrease each second
View methods:
getNewReceiverCooldown
function getNewReceiverCooldown(address sender, address receiver, uint256 amount) external view returns(uint256)
Estimates the new Cooldown for the receiver, based on sender & amount of transfer
getUserLockCount
function getUserLockCount(address user) external view returns(uint256)
Get the total number of Locks for an user
getUserLock
function getUserLock(address user) external view returns(UserLock memory)
Get the current user Lock
getUserPastLock
function getUserPastLock(address user, uint256 blockNumber) external view returns(UserLock memory)
Get the user Lock at a given block (returns empty Lock if not existing / block number too old)
getTotalLockLength
function getTotalLockLength() external view returns(uint256)
Get the total count of TotalLock
getCurrentTotalLock
function getCurrentTotalLock() external view returns(TotalLock memory)
Get the latest TotalLock
getPastTotalLock
function getPastTotalLock(uint256 blockNumber) external view returns(TotalLock memory)
Get the TotalLock at a given block
availableBalanceOf
function availableBalanceOf(address user) external view returns(uint256)
Get the user available balance (available = staked - locked)
allBalancesOf
function allBalancesOf(address user) external view returns( uint256 staked, uint256 locked, uint256 available )
Get all balances for a given user:
staked : staked balance
locked : locked balance
available : available balance (staked - locked)
estimateClaimableRewards
function estimateClaimableRewards(address user) external view returns(uint256)
Get the estimated current amount of rewards claimable by the user
numCheckpoints
function numCheckpoints(address account) external view virtual returns (uint256)
Current number of vote checkpoints for the user
getCurrentVotes
function getCurrentVotes(address user) external view returns (uint256)
Get the user current voting power (with bonus voting power from the Lock)
getPastVotes
function getPastVotes(address user, uint256 blockNumber) external view returns(uint256)
Get the user voting power for a given block (with bonus voting power from the Lock)
getPastDelegate
function getPastDelegate(address account, uint256 blockNumber) public view returns (address)
Get the user delegate at a given block
Write methods:
stake
function stake(uint256 amount) external returns(uint256)
Deposits PAL & mints hPAL tokens
Parameters :
name | type | desc |
amount | uint256 | Amount to stake (in wei) |
Returns : uint256 : amount of hPAL minted
cooldown
function cooldown() external
Updates the Cooldown for the caller
unstake
function unstake(uint256 amount, address receiver) external returns(uint256)
Burns hPAL & withdraws PAL
Parameters :
name | type | desc |
amount | uint256 | Amount to withdraw (in wei) |
receiver | address | address to receive the withdrawn PAL |
Returns : uint256 : amount withdrawn
lock
function lock(uint256 amount, uint256 duration) external
Locks hPAL for a given duration
Parameters :
name | type | desc |
amount | uint256 | Amount of the hPAL balance to lock (in wei) |
duration | uint256 | duration of the Lock (in seconds) |
increaseLockDuration
function increaseLockDuration(uint256 duration) external
Increase the user current Lock duration (& restarts the Lock)
Parameters :
name | type | desc |
duration | uint256 | new duration for the Lock (in seconds) |
increaseLock
function increaseLock(uint256 amount) external
Increase the amount of hPAL locked for the user
Parameters :
name | type | desc |
amount | uint256 | new amount of hPAL to be locked (in total) (in wei) |
unlock
function unlock() external
Registers a new user wanting to sell its delegation
kick
function kick(address user) external
Removes an user Lock if too long after expiry, and applies a penalty
Parameters :
name | type | desc |
user | address | address of the user to kick out of a Lock |
stakeAndLock
function stakeAndLock(uint256 amount, uint256 duration) external returns(uint256)
Staked PAL to get hPAL, and locks it for the given duration
Parameters :
name | type | desc |
amount | uint256 | amount of PAL to stake and lock (in wei) |
duration | uint256 | duration of the Lock (in seconds) |
Returns : uint256 : amount of hPAL minted
stakeAndIncreaseLock
function stakeAndIncreaseLock(uint256 amount, uint256 duration) external returns(uint256)
Stake more PAL into hPAL & add them to the current user Lock
Parameters :
name | type | desc |
amount | uint256 | amount of PAL to stake and lock (in wei) |
duration | uint256 | duration of the Lock (in seconds) |
Returns : uint256 : amount of hPAL minted
delegate
function delegate(address delegatee) external
Delegates the caller voting power to another address
Parameters :
name | type | desc |
delegatee | address | address to delegate to |
claim
function claim(uint256 amount) external
Claim the given amount of rewards for the caller
Parameters :
name | type | desc |
amount | uint256 | amount to claim (in wei) |
updateRewardState
function updateRewardState() external
Updates the global Reward State for the contract
updateUserRewardState
function updateUserRewardState(address user) external
Updates the given user Reward State
Parameters :
name | type | desc |
user | address | address of the user to update |
emergencyWithdraw
function emergencyWithdraw(uint256 amount, address receiver) external returns(uint256)
Allow to withdraw with override of the lock & cooldown in case of emergency
Parameters :
name | type | desc |
amount | uint256 | amount to withdraw (in wei) |
receiver | address | address to receive the withdrawn funds |
Returns : uint256 : amount withdrawn
Events
Stake
event Stake(address indexed user, uint256 amount);
Emitted when an user stake PAL in the contract
Unstake
event Unstake(address indexed user, uint256 amount);
Emitted when an user burns hPAL to withdraw PAL
Cooldown
event Cooldown(address indexed user);
Emitted when an user triggers the cooldown period
Lock
event Lock(address indexed user, uint256 amount, uint256 indexed startTimestamp, uint256 indexed duration, uint256 totalLocked);
Emitted when an user creates or update its Lock
Unlock
event Unlock(address indexed user, uint256 amount, uint256 totalLocked);
Emitted when an user exits the Lock
Kick
event Kick(address indexed user, address indexed kicker, uint256 amount, uint256 penalty, uint256 totalLocked);
Emitted when an user is kicked out of the Lock
ClaimRewards
event ClaimRewards(address indexed user, uint256 amount);
Emitted when an user claim the rewards
DelegateChanged
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
Emitted when the delegate of an address changes
DelegateVotesChanged
event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance);
Emitted when the votes of a delegate is updated
EmergencyUnstake
event EmergencyUnstake(address indexed user, uint256 amount);
Emitted when un user withdraw through the emergency method
Last updated