Skip to content

Latest commit

 

History

History
108 lines (79 loc) · 3.82 KB

File metadata and controls

108 lines (79 loc) · 3.82 KB

Bet CLI

A command-line interface for interacting with the Solana betting program.

Usage

Requires a cli section of Anchor.toml listing wallet names and paths, either in the working directory or one level up:

# The wallets available to the cli. Generate new ones like:
# solana-keygen new --no-bip39-passphrase -o keys/taker.json
[cli]
default = "~/.config/solana/id.json"
taker = "./keys/taker.json"
settle = "./keys/settle.json"

Then

cargo build --release && mv ../target/release/bet-cli ./b && ./b help

Local cluster

In one terminal, start a localnet Solana validator:

$ solana-test-validator --reset

In another

$ anchor deploy # deploy the contract
$ ./b init      # call the contract's 'initialize' fn

Add funds to the wallets. anchor deploy will have airdropped to the default wallet.

$ ./b transfer -t taker -a 5
$ ./b transfer -t settle -a 5
$ ./b show
--- Wallets ---
Name   	                                      Address	Balance
default	F5ZHFw5p7YMKHAp9WrU7np5X9CkKa9UVMCneXU4DiXXP	499999988.2037613
settle 	2fbHF2YTQJgBwVvTsAdnAhLUXoUXAntwapHMqsGtnHT2	5.0
taker  	EcWgKBpAd5VLqjagsFFRGAt6ph4zmEHdCEUhw4iDt1Zq	5.0

--- Bets ---
Index	Address                                      	Balance

Offer a bet with the default wallet as the maker

$ ./b offer \
  --condition "Will this contract resolve true?" \
  --maker-side "yes" \
  --win-amount 2.5 \
  --lose-amount 0.5 \
  --authority 2fbHF2YTQJgBwVvTsAdnAhLUXoUXAntwapHMqsGtnHT2

Bet escrow account now contains the maker's portion:

$ ./b show
--- Wallets ---
Name   	                                      Address	Balance
default	F5ZHFw5p7YMKHAp9WrU7np5X9CkKa9UVMCneXU4DiXXP	499999987.700
settle 	2fbHF2YTQJgBwVvTsAdnAhLUXoUXAntwapHMqsGtnHT2	5.000
taker  	EcWgKBpAd5VLqjagsFFRGAt6ph4zmEHdCEUhw4iDt1Zq	5.000

--- Bets ---
Index	Address                                      	            Bal	Condition
0	E7ZZYZ2PywSBnsK2Be36bZHi4Vu12FAsG8Xrf3HRgkVX	          0.504	Will this contract resolve true?

Take the bet from the taker wallet

$ ./b -w taker take -b E7ZZYZ2PywSBnsK2Be36bZHi4Vu12FAsG8Xrf3HRgkVX

Escrow now contains both:

$ ./b show
--- Wallets ---
Name   	                                      Address	Balance
default	F5ZHFw5p7YMKHAp9WrU7np5X9CkKa9UVMCneXU4DiXXP	499999987.700
settle 	2fbHF2YTQJgBwVvTsAdnAhLUXoUXAntwapHMqsGtnHT2	5.000
taker  	EcWgKBpAd5VLqjagsFFRGAt6ph4zmEHdCEUhw4iDt1Zq	2.500

--- Bets ---
Index	Address                                      	            Bal	Condition
0	E7ZZYZ2PywSBnsK2Be36bZHi4Vu12FAsG8Xrf3HRgkVX	          3.004	Will this contract resolve true?

Finally, settle the bet in favor of the taker and inspect balances

$ ./b -w settle settle -b E7ZZYZ2PywSBnsK2Be36bZHi4Vu12FAsG8Xrf3HRgkVX -o "no"

https://explorer.solana.com/tx/3tcd3mzJhWUKkjbwMRdUJiu4t547jL9oENQTSAY8xmqHUn4GAksfbYYLfnQNutt15QptNdS2gaM7B1wMcve26BgL?cluster=custom
[solana logs]
    Program 7WAP8m2BnEZH2LpoUhBtmjNhSgZA6mFaBVdPdVauV2n6 invoke [1]
    Program log: Instruction: SettleBet
    Program log: settlement date: 1747152976
    Program log: current time: 1747153404
    Program log: winner is taker; maker_bets_yes=true, outcome_is_yes=false
    Program 7WAP8m2BnEZH2LpoUhBtmjNhSgZA6mFaBVdPdVauV2n6 consumed 5505 of 200000 compute units
    Program 7WAP8m2BnEZH2LpoUhBtmjNhSgZA6mFaBVdPdVauV2n6 success

$ ./b show
--- Wallets ---
Name   	                                      Address	Balance
default	F5ZHFw5p7YMKHAp9WrU7np5X9CkKa9UVMCneXU4DiXXP	499999987.704
settle 	2fbHF2YTQJgBwVvTsAdnAhLUXoUXAntwapHMqsGtnHT2	5.000
taker  	EcWgKBpAd5VLqjagsFFRGAt6ph4zmEHdCEUhw4iDt1Zq	5.500

--- Bets ---
Index	Address                                      	            Bal	Condition