You can reference this Solana Program script to develope the prediction market
- Initialize Program: Admin sets the configuration status of the program.
- Create Market: Users can create a new market.
- Add Liquidity: Users can add liquidity to an existing market.
- Withdraw Liquidity: Users can remove their liquidity from the market.
- Swap SOL for Token: Users can swap SOL for tokens within the market.
- Resolution: When the market closes, the winner receives the reward.
Install Rust, Solana, and AVM: https://solana.com/docs/intro/installation Remember to install anchor v0.30.1.
[provider]
cluster = "<DEVNET_RPC>"
anchor build
anchor deploy
function programCommand(name: string) {
return program
.command(name)
.option(
// mainnet-beta, testnet, devnet
"-e, --env <string>",
"Solana cluster env name",
"devnet"
)
.option(
"-r, --rpc <string>",
"Solana cluster RPC name",
"devnet rpc url"
)
.option(
"-k, --keypair <string>",
"Solana wallet Keypair Path",
"./keys/*.json" //*.json: Your Keypair.json
);
}
Initialize program: Admin sets the configuration status of the program.
yarn script config
Create market: Users can create a new market.
yarn script market
Add liquidity: Users can add liquidity to an existing market.
yarn script addlp -y <TOKEN_YES_MINT_Addy> -n <TOKEN_NO_MINT_Addy> -a <SOL_LAMPORT_AMOUNT>
TOKEN_YES_MINT_Addy: Yes token address
TOKEN_NO_MINT_Addy: No token address
SOL_LAMPORT_AMOUNT: SOL_AMOUNT * LAMPORTS_PER_SOL
Withdraw liquidity: Users can remove their liquidity from the market.
yarn script withdraw -y <TOKEN_YES_MINT_Addy> -n <TOKEN_NO_MINT_Addy> -a <SOL_LAMPORT_AMOUNT>
TOKEN_YES_MINT_Addy: Yes token address
TOKEN_NO_MINT_Addy: No token address
SOL_LAMPORT_AMOUNT: SOL_AMOUNT * LAMPORTS_PER_SOL
Swap SOL for token: Users can swap SOL for tokens within the market.
yarn script swap -y <TOKEN_YES_MINT_Addy> -n <TOKEN_NO_MINT_Addy> -a <SOL_LAMPORT_AMOUNT> -s <SWAP_DIRECTION> -t <TOKEN_TYPE>
TOKEN_YES_MINT_Addy: Yes token address
TOKEN_NO_MINT_Addy: No token address
SOL_LAMPORT_AMOUNT: SOL_AMOUNT * LAMPORTS_PER_SOL
SWAP_DIRECTION: if 0 for buy and if 1 for sell
TOKEN_TYPE: if 0 for No and if 1 for Yes.
Resolution: When the market closes, the winner receives the reward.
yarn script resolution -y <TOKEN_YES_MINT_Addy> -n <TOKEN_NO_MINT_Addy>
TOKEN_YES_MINT_Addy: Yes token address
TOKEN_NO_MINT_Addy: No token address
Users can add liquidity to the specific market before the market resolution. Each liquidity provider can get the fees based on his share in each market.
The platform gets 1.2% as a transaction fee in each market when users trade.
Here 1% goes to the treasury wallet, and 0.2% of the transaction fee will go to liquidity providers in proportion to the yield they’re providing.(The user can get fees from 0.2% of trade fees according to his share.)
Users can withdraw their liquidity at any time they want. This operation must be done before the market resolution
When the market is closed, the winner receives the reward. The formula to calculate the rewards is like the following
Rewards = WIN_TOKEN(YES TOKEN or NO TOKEN) balance * 0.01 SOL