🍯This is one kind of 💲Lottery system💲.🍯 Here's how it works:
- Players pay an entry fee of 0.05 💲SOL for a golden ticket.
- 0.01 💲SOL is taken from this fee and deposited into the community treasury
- Players stake their golden ticket for the duration of the Pot.
- When the Pot ends, the wallet containing the winning ticket receives the contents of the pot.
- 10% of every pot is deposited into the community treasury. There are daily, weekly, and monthly pots.
- Over time, we will add pots with different ticket prices, time limits, and rules for entry
- Install
node
andyarn
- Install
ts-node
as global command - Confirm the solana wallet preparation:
/home/fury/.config/solana/id.json
in test case
- $ solana --version // solana-cli 1.8.16 (src:23af37fe; feat:1886190546)
- $ anchor --version // anchor-cli 0.20.1 //use avm to install and use desired version: Refer here
cargo install --git https://github.com/project-serum/anchor avm --locked --force
- $ node --version // v16.14.0
- $ yarn --version // 1.22.17 // use
npm install --global yarn@1.22.17
- $ cargo --version // cargo 1.59.0 (49d8809dc 2022-02-10)//
rustup install 1.59.0
and then if neededrustup override set 1.59.0
- Main script source for all functionality is here:
/cli/script.ts
- Program account types are declared here:
/cli/types.ts
- Idl to make the JS binding easy is here:
/cli/honey_pot.json
Able to test the script functions working in this way.
- Change commands properly in the main functions of the
script.ts
file to call the other functions - Confirm the
ANCHOR_WALLET
environment variable of thets-node
script inpackage.json
- Run
yarn ts-node
First of all, you have to git clone in your PC.
In the folder Lottery_DAO/honey_pot
, in the terminal
yarn
anchor build
In the last sentence you can see:
To deploy this program:
$ solana program deploy /home/ubuntu/apollo/Lottery_DAO/honey_pot/target/deploy/honey_pot.so
The program address will default to this keypair (override with --program-id):
/home/ubuntu/apollo/Lottery_DAO/honey_pot/target/deploy/honey_pot-keypair.json
solana-keygen pubkey /home/ubuntu/apollo/Lottery_DAO/honey_pot/target/deploy/honey_pot-keypair.json
- You can get the pubkey of the program ID : ex."CKy...Q98F"
- Please add this pubkey to the lib.rs
line 15: declare_id!("CKy...Q98F");
- Please add this pubkey to the Achor.toml
line 2: upgrade = "CKy...Q98F"
- Please add this pubkey to the init.ts
line 36: const PROGRAM_ID = "CKy...Q98F";
anchor build
againsolana program deploy /home/ubuntu/apollo/Lottery_DAO/honey_pot/target/deploy/honey_pot.so
- In the scripts.ts code,
line 39
, check the network.(devnet
ormainnet-beta
) - In the scripts.ts code,
line 71
, de-commentawait initProject(payer.publicKey);
yarn ts-node
- If this error comes -
Error: Provider local is not available on browser.
,export BRWOSER=
yarn ts-node
Then, you can enjoy this program with new program_id.
For the first time use, the Smart Contract Owner should initialize
the Smart Contract for global account allocation.
/**
* @dev Before use this program, the accounts have to be initialized
* @param userAddress : The caller who want to init the project
* @returns
*/
export const initProject = async (
userAddress: PublicKey,
)
All users can buy tickets by calling the functions with amount of tickets.
/**
* @dev Buy daily tickets function
* @param userAddress The caller of this function- the player of the game
* @param amount The amount of tickets that the caller bought
*/
export const buyTicket = async (
userAddress: PublicKey,
amount: number
)
before buyTicket
, initialze the userPool.
/**
* @dev Create account of users with the identifier, timestamp, seed
* @param userAddress The caller of this function - the player of the game
* @param identifier The count of the dailyPot
* @param timestamp The startTime of the dailyPot
*/
export const initIdPool = async (
userAddress: PublicKey,
identifier: number,
timestamp: number,
)
After the lottery ends, they can reveal the winner by calling function.
/**
* @dev The function which can reveal the winner of the daily_pot
* @param userAddress The caller address
*/
export const revealWinner = async (
userAddress: PublicKey,
): Promise<PublicKey>
Then, the winner can claim reward from the reward pool by calling funciton.
/**
* @dev The claim funtion that can claim the winner Prize from the daily_pot
* @param userAddress The caller address to claim reward from the rewardVault
*/
export const claim = async (
userAddress: PublicKey,
)
Above 3 functions are implemented for 3 pots- daily, weekly, and monthly pots.
- Buyfunction
/**
* @dev Buy Weekly tickets function
* @param userAddress The caller of this function- the player of the game
* @param amount The amount of tickets that the caller bought
*/
export const buyWeeklyTicket = async (
userAddress: PublicKey,
amount: number
)
/**
* @dev Buy Monthly tickets function
* @param userAddress The caller of this function- the player of the game
* @param amount The amount of tickets that the caller bought
*/
export const buyMonthlyTicket = async (
userAddress: PublicKey,
amount: number
)
- RevealFunction
/**
* @dev The function which can reveal the winner of the weekly_pot
* @param userAddress The caller address
*/
export const revealWeeklyWinner = async (
userAddress: PublicKey,
): Promise<PublicKey>
/**
* @dev The function which can reveal the winner of the monthly_pot
* @param userAddress The caller address
*/
export const revealMonthlyWinner = async (
userAddress: PublicKey,
): Promise<PublicKey>
- ClaimFunction
/**
* @dev The claim funtion that can claim the winner Prize from the weekly_pot
* @param userAddress The caller address to claim reward from the rewardVault
*/
export const claimWeekly = async (
userAddress: PublicKey,
)
/**
* @dev The claim funtion that can claim the winner Prize from the weekly_pot
* @param userAddress The caller address to claim reward from the rewardVault
*/
export const claimWeekly = async (
userAddress: PublicKey,
)