PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, July 28, 2022

[FIXED] How to create a staking smart contract?

 July 28, 2022     blockchain, smartcontracts, solana     No comments   

Issue

I'm a novice in a smartcontracts but want to create a simple stake contract in Solana. But can't understand when I need to update a reward counter per user? Because contracts interact with accounts for write, only when user paid for this. But in all staking protocols, we can see rewards count after staking. How this can work? And how I can change APY in a time?

I invented only one method - save counters in off chain program but think it's not right way


Solution

A lot of this is more down to design, but a few suggestions:

But can't understand when I need to update a reward counter per user?

You don't necessarily need to update all the time. In fact, many staking protocols keep track of the last time a user's rewards were paid out, but don't actually change the value until the user tries to withdraw. For frontends, you just need to do a dynamic calculation based on the user's position.

You may find more interesting information by looking at the protocols' source code. For example, Orca's contract is based on token-swap from the SPL: https://github.com/solana-labs/solana-program-library/tree/master/token-swap

Otherwise, there's more general-purpose clients and code that might be interesting at https://github.com/solana-labs/solana-program-library/tree/master/farms



Answered By - Jon C
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing