Hodler.sol
Below the overview of all state changing functions in the smart contract.
#State changing functions
function initialize(address _asset, uint256 _amount, uint256 _min, uint256 _max) public;
function deposit(uint256 amount) public lock;
function withdraw(uint256 token_amount) public lock;
State changing functions overview
initialize is called by the factory when creating the new game. It can only be called once.
require(initialized == false, "Hodler_initialize: already initialized");
deposit is called by the participant to deposit assets. It can only be called before the game started and at max 2 times the start amount.
require(amount > 0, "Hodler_Deposit: zero asset deposit");
require(ended == false, "Hodler_Deposit: game ended");
require(started == false, "Hodler_Deposit: game started");
require(totalSupply.add(amount) < start_amount.mul(2), "Hodler_Deposit: final deposit out of range");
withdraw is called by the participant to withdraw assets. It can always be called before the end of the game (all funds withdrawn). When the game has started the asset amount to withdraw is calculated by calculateAssetOut.
require(token_amount > 0, "Hodler_withdraw: zero token withdraw");
require(ended == false, "Hodler_withdraw: game ended");
require(asset_withdraw > 0, "Hodler_withdraw: zero asset withdraw");
Bonding curve implementation
calculateAssetOut calculates the amount of assets to withdraw based on the linear bonding curve. It does this in multiple steps:
1. Calculate the old and new percentage of total assets withdrawn (based on previous total withdraw and total withdraw + new withdraw amount)
2. Calculate the mean of the difference between the old and new percentage of assets withdrawn
3. Finally calculate the assets to withdraw
Last updated
Was this helpful?