Giter VIP home page Giter VIP logo

cw-frosty's Introduction

Frosty Staking Contract

Frosty is a staking contract with special features designed to allow users to stake CW20 tokens with a desired unbonding duration and receive rewards based on their staked amount and duration.

Design

Instantiation

Anyone can instantiate the contract by sending an InstantiateContract transaction. The message must include the following information: stake_token_address, reward_token_address, admin, force_claim_ratio, fee_collector, and max_bond_duration.

Reward Funding

Rewards can only be funded by the contract's admin. The contract expects a RewardUpdate message from the CW20 reward contract, which must include a reward_end_date as a Timestamp.

At each RewardUpdate, the contract sets total_rewards as the sum of incoming rewards and remaining rewards. It also sets reward_end_date as the msg.reward_end_date and start_time as the current time.

Bonding

Users can bond CW20 tokens to the contract by sending a Bond message. The message must include an unbonding_duration_as_days, which must be between 1 and max_bond_duration. When bonded, the user weight is calculated as shown below:

$$ \text{position weight} = \sqrt{{\texttt{duration}}} \times {\text{amount}} $$

Reward Distribution

Rewards will be calculated depending on the weight of the position. At each update_index call the contract calculates how much reward is to be distubuted as follows

$$ {new Dist Balance = { {now-last Updated} \over {reward End Time-reward Start Time}}*total Reward Supply} $$

$$ {global index = {last Global Index + {new Dist Balance \over total Weight}}} $$

At update_staker_rewards call the contract will calculate rewards for every position of the user(e.g. A user staked for two positions as 10 days and 30 days). Calculation is made as follows

$$ {new Rewards = {global Index-user Index} * position Weight } $$

$$ {pending Rewards += new Rewards }$$

Receive Rewards

Users can receive their rewards by sending a ReceiveRewards message to the contract.

Unbonding

Users can unbond their staked tokens at any time by sending an UnbondStake transaction. The user must select which position to unbond by including the duration_as_days in the message.

Upon receiving the UnbondStake transaction. The rewards for the corresponding staking position will be updated and sent to the user. The contract will create a claim for bonded tokens to be claimed by user. This claim will not be claimable until the unbonding duration has elapsed. During the unbonding duration, the user will not receive any rewards.

Force Claim

Users can claim their bonded_tokens before the unbonding duration elapsed by paying extra fee. The fee calculation is as follows

$$ {fee = {{release At - now \over release At-unbond At}*force Claim Ratio}*amount} $$

cw-frosty's People

Contributors

ninjatosba avatar mightofoaks avatar orkunkl avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.