Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions finance/betting-market/anchor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ division floors each share, leaving at most a few minor units of dust in the vau

- `initialize_config` - anyone (the signer becomes admin). One-time setup: sets admin, stake
token, fee, fee recipient.
- `create_event` - admin. Opens a market and creates its vault.
- `initialize_event` - admin. Opens a market and creates its vault.
- `add_outcome` - admin. Adds a possible result. Only before any bet is placed.
- `place_bet` - bettor. Stakes tokens on one outcome; updates the pools and adds the Bet to the
user's index (rejected with `TooManyBets` if all `MAX_BETS_PER_USER` slots hold open positions).
Expand Down Expand Up @@ -121,7 +121,7 @@ anchor test

### How does a prediction market work on Solana?

This example uses the parimutuel (pooled) model: an admin opens an event with `create_event` and `add_outcome`, and bettors stake tokens on an outcome with `place_bet`. Every stake goes into one pool; after `settle_event` names the winning outcome, winners call `claim_winnings` to split the losing stakes, minus a protocol fee, in proportion to their own stake.
This example uses the parimutuel (pooled) model: an admin opens an event with `initialize_event` and `add_outcome`, and bettors stake tokens on an outcome with `place_bet`. Every stake goes into one pool; after `settle_event` names the winning outcome, winners call `claim_winnings` to split the losing stakes, minus a protocol fee, in proportion to their own stake.

### How are the odds set?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub const MAX_DESCRIPTION_LEN: usize = 200;

#[derive(Accounts)]
#[instruction(event_id: u64)]
pub struct CreateEventAccountConstraints<'info> {
pub struct InitializeEventAccountConstraints<'info> {
#[account(mut)]
pub admin: Signer<'info>,

Expand Down Expand Up @@ -50,8 +50,8 @@ pub struct CreateEventAccountConstraints<'info> {
pub system_program: Program<'info, System>,
}

pub fn handle_create_event(
context: Context<CreateEventAccountConstraints>,
pub fn handle_initialize_event(
context: Context<InitializeEventAccountConstraints>,
event_id: u64,
description: String,
) -> Result<()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod cancel_event;
pub mod claim_refund;
pub mod claim_winnings;
pub mod close_losing_bet;
pub mod create_event;
pub mod initialize_event;
pub mod initialize_config;
pub mod place_bet;
pub mod settle_event;
Expand All @@ -14,7 +14,7 @@ pub use cancel_event::*;
pub use claim_refund::*;
pub use claim_winnings::*;
pub use close_losing_bet::*;
pub use create_event::*;
pub use initialize_event::*;
pub use initialize_config::*;
pub use place_bet::*;
pub use settle_event::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ pub mod betting_market {
}

// Admin opens a new market and creates its pool vault.
pub fn create_event(
context: Context<CreateEventAccountConstraints>,
pub fn initialize_event(
context: Context<InitializeEventAccountConstraints>,
event_id: u64,
description: String,
) -> Result<()> {
instructions::create_event::handle_create_event(context, event_id, description)
instructions::initialize_event::handle_initialize_event(context, event_id, description)
}

// Admin adds a possible result. Only allowed before betting starts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ fn initialize_config_ix(admin: Pubkey, mint: Pubkey, fee_recipient: Pubkey) -> I
)
}

fn create_event_ix(admin: Pubkey, mint: Pubkey, event_id: u64, description: &str) -> Instruction {
fn initialize_event_ix(admin: Pubkey, mint: Pubkey, event_id: u64, description: &str) -> Instruction {
let event = event_pda(event_id);
Instruction::new_with_bytes(
betting_market::id(),
&betting_market::instruction::CreateEvent {
&betting_market::instruction::InitializeEvent {
event_id,
description: description.to_string(),
}
.data(),
betting_market::accounts::CreateEventAccountConstraints {
betting_market::accounts::InitializeEventAccountConstraints {
admin,
config: config_pda(),
token_mint: mint,
Expand Down Expand Up @@ -348,7 +348,7 @@ fn test_full_lifecycle() {
send_transaction_from_instructions(
&mut market.svm,
vec![
create_event_ix(admin, mint, event_id, "Will it rain tomorrow?"),
initialize_event_ix(admin, mint, event_id, "Will it rain tomorrow?"),
add_outcome_ix(admin, event_id, 0, "Yes"),
add_outcome_ix(admin, event_id, 1, "No"),
],
Expand Down Expand Up @@ -456,15 +456,15 @@ fn test_full_lifecycle() {
}

#[test]
fn test_only_admin_can_create_event() {
fn test_only_admin_can_initialize_event() {
let mut market = setup();
init_config(&mut market);

let mint = market.mint;
let mallory = create_wallet(&mut market.svm, 10_000_000_000).unwrap();
let result = send_transaction_from_instructions(
&mut market.svm,
vec![create_event_ix(mallory.pubkey(), mint, 7, "Unauthorized event")],
vec![initialize_event_ix(mallory.pubkey(), mint, 7, "Unauthorized event")],
&[&mallory],
&mallory.pubkey(),
);
Expand All @@ -486,7 +486,7 @@ fn test_cannot_bet_after_settle() {
send_transaction_from_instructions(
&mut market.svm,
vec![
create_event_ix(admin, mint, event_id, "Coin flip"),
initialize_event_ix(admin, mint, event_id, "Coin flip"),
add_outcome_ix(admin, event_id, 0, "Heads"),
add_outcome_ix(admin, event_id, 1, "Tails"),
],
Expand Down Expand Up @@ -533,7 +533,7 @@ fn test_double_claim_fails() {
send_transaction_from_instructions(
&mut market.svm,
vec![
create_event_ix(admin, mint, event_id, "Match winner"),
initialize_event_ix(admin, mint, event_id, "Match winner"),
add_outcome_ix(admin, event_id, 0, "Home"),
add_outcome_ix(admin, event_id, 1, "Away"),
],
Expand Down Expand Up @@ -595,7 +595,7 @@ fn test_settle_outcome_without_bets_fails() {
send_transaction_from_instructions(
&mut market.svm,
vec![
create_event_ix(admin, mint, event_id, "Two horse race"),
initialize_event_ix(admin, mint, event_id, "Two horse race"),
add_outcome_ix(admin, event_id, 0, "Horse A"),
add_outcome_ix(admin, event_id, 1, "Horse B"),
],
Expand Down Expand Up @@ -634,7 +634,7 @@ fn test_cancel_and_refund() {
send_transaction_from_instructions(
&mut market.svm,
vec![
create_event_ix(admin, mint, event_id, "Voided event"),
initialize_event_ix(admin, mint, event_id, "Voided event"),
add_outcome_ix(admin, event_id, 0, "A"),
add_outcome_ix(admin, event_id, 1, "B"),
],
Expand Down Expand Up @@ -709,7 +709,7 @@ fn test_close_losing_bet_only_after_settle_and_only_for_losers() {
send_transaction_from_instructions(
&mut market.svm,
vec![
create_event_ix(admin, mint, event_id, "Derby winner"),
initialize_event_ix(admin, mint, event_id, "Derby winner"),
add_outcome_ix(admin, event_id, 0, "Red"),
add_outcome_ix(admin, event_id, 1, "Blue"),
],
Expand Down Expand Up @@ -793,7 +793,7 @@ fn test_closing_a_bet_frees_a_slot_for_a_new_bet() {

send_transaction_from_instructions(
&mut market.svm,
vec![create_event_ix(admin, mint, full_event_id, "Wide field")],
vec![initialize_event_ix(admin, mint, full_event_id, "Wide field")],
&[&market.admin],
&admin,
)
Expand All @@ -810,7 +810,7 @@ fn test_closing_a_bet_frees_a_slot_for_a_new_bet() {
send_transaction_from_instructions(
&mut market.svm,
vec![
create_event_ix(admin, mint, second_event_id, "Second market"),
initialize_event_ix(admin, mint, second_event_id, "Second market"),
add_outcome_ix(admin, second_event_id, 0, "Yes"),
add_outcome_ix(admin, second_event_id, 1, "No"),
],
Expand Down
2 changes: 1 addition & 1 deletion finance/betting-market/quasar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ the other side of your bet. Everyone's stake goes into one pool, and when the
result is known the winners divide the pool.

- The **admin** (whoever ran `initialize_config`) opens an event with
`create_event`, then lists each possible result with `add_outcome`. Outcomes
`initialize_event`, then lists each possible result with `add_outcome`. Outcomes
can only be added before the first bet, so the field of choices can't change
under bettors who have already staked.
- A **bettor** stakes the market's token on one outcome with `place_bet`. The
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::state::{

#[derive(Accounts)]
#[instruction(event_id: u64)]
pub struct CreateEventAccountConstraints {
pub struct InitializeEventAccountConstraints {
#[account(mut)]
pub admin: Signer,

Expand Down Expand Up @@ -41,11 +41,11 @@ pub struct CreateEventAccountConstraints {
}

#[inline(always)]
pub fn handle_create_event(
accounts: &mut CreateEventAccountConstraints,
pub fn handle_initialize_event(
accounts: &mut InitializeEventAccountConstraints,
event_id: u64,
description: &str,
bumps: &CreateEventAccountConstraintsBumps,
bumps: &InitializeEventAccountConstraintsBumps,
) -> Result<(), ProgramError> {
let description_bytes = description.as_bytes();
require!(
Expand Down
4 changes: 2 additions & 2 deletions finance/betting-market/quasar/src/instructions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod cancel_event;
pub mod claim_refund;
pub mod claim_winnings;
pub mod close_losing_bet;
pub mod create_event;
pub mod initialize_event;
pub mod initialize_config;
pub mod place_bet;
pub mod settle_event;
Expand All @@ -14,7 +14,7 @@ pub use cancel_event::*;
pub use claim_refund::*;
pub use claim_winnings::*;
pub use close_losing_bet::*;
pub use create_event::*;
pub use initialize_event::*;
pub use initialize_config::*;
pub use place_bet::*;
pub use settle_event::*;
Expand Down
6 changes: 3 additions & 3 deletions finance/betting-market/quasar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ mod quasar_betting_market {

/// Admin opens a new market and creates its pool vault.
#[instruction(discriminator = 1)]
pub fn create_event(
ctx: Ctx<CreateEventAccountConstraints>,
pub fn initialize_event(
ctx: Ctx<InitializeEventAccountConstraints>,
event_id: u64,
description: String<200>,
) -> Result<(), ProgramError> {
instructions::create_event::handle_create_event(
instructions::initialize_event::handle_initialize_event(
&mut ctx.accounts,
event_id,
description,
Expand Down
10 changes: 5 additions & 5 deletions finance/betting-market/quasar/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use {
crate::{
cpi::{
AddOutcomeInstruction, CancelEventInstruction, ClaimRefundInstruction,
ClaimWinningsInstruction, CloseLosingBetInstruction, CreateEventInstruction,
ClaimWinningsInstruction, CloseLosingBetInstruction, InitializeEventInstruction,
InitializeConfigInstruction, PlaceBetInstruction, SettleEventInstruction,
},
state::{Bet, Config, Event, EventStatus, EventVaultPda, Outcome, User},
Expand Down Expand Up @@ -94,7 +94,7 @@ fn full_lifecycle_settles_and_pays_the_winner(test: &mut Test) {
const FEE: u64 = 1; // floor(100 * 100 / 10000) = 1
const PAYOUT_B: u64 = STAKE_B + 99; // stake + winnings(99)

test.send(CreateEventInstruction {
test.send(InitializeEventInstruction {
admin: ADMIN,
token_mint: TOKEN_MINT,
event_id: EVENT_ID,
Expand Down Expand Up @@ -198,7 +198,7 @@ fn cancelled_event_refunds_the_exact_stake(test: &mut Test) {

const STAKE: u64 = 250;

test.send(CreateEventInstruction {
test.send(InitializeEventInstruction {
admin: ADMIN,
token_mint: TOKEN_MINT,
event_id: EVENT_ID,
Expand Down Expand Up @@ -247,11 +247,11 @@ fn cancelled_event_refunds_the_exact_stake(test: &mut Test) {

/// Only the config admin may open an event.
#[quasar_test]
fn create_event_rejects_a_non_admin_signer(test: &mut Test) {
fn initialize_event_rejects_a_non_admin_signer(test: &mut Test) {
base_world(test);
test.add(Wallet::new().at(ATTACKER));

test.send(CreateEventInstruction {
test.send(InitializeEventInstruction {
admin: ATTACKER,
token_mint: TOKEN_MINT,
event_id: EVENT_ID,
Expand Down
4 changes: 2 additions & 2 deletions finance/lending/anchor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ deposits or a borrower's collateral: there is no admin escape hatch over user fu

### Instruction handlers

Admin: `init_lending_market`, `init_reserve`, `update_reserve_config`, `set_price`,
Admin: `initialize_lending_market`, `initialize_reserve`, `update_reserve_config`, `set_price`,
`collect_protocol_fees`.
Supply side: `refresh_reserve`, `deposit_reserve_liquidity`,
`redeem_reserve_collateral`. Borrow side: `init_obligation`, `refresh_obligation`,
`redeem_reserve_collateral`. Borrow side: `initialize_obligation`, `refresh_obligation`,
`deposit_obligation_collateral`, `withdraw_obligation_collateral`,
`borrow_obligation_liquidity`, `repay_obligation_liquidity`, `liquidate_obligation`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use anchor_spl::token_interface::Mint;
use crate::constants::LENDING_MARKET_SEED;
use crate::state::LendingMarket;

pub fn handle_init_lending_market(
context: Context<InitLendingMarket>,
pub fn handle_initialize_lending_market(
context: Context<InitializeLendingMarket>,
market_id: u64,
) -> Result<()> {
let market = &mut context.accounts.lending_market;
Expand All @@ -18,7 +18,7 @@ pub fn handle_init_lending_market(

#[derive(Accounts)]
#[instruction(market_id: u64)]
pub struct InitLendingMarket<'info> {
pub struct InitializeLendingMarket<'info> {
// Seeded by `market_id` alone — the market is not identified by any
// individual's address. `owner` is stored as a field and used only for
// authorization (`has_one = owner`) on admin instructions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::constants::{
};
use crate::state::{LendingMarket, PriceFeed, Reserve, ReserveConfig};

pub fn handle_init_reserve(context: Context<InitReserve>, config: ReserveConfig) -> Result<()> {
pub fn handle_initialize_reserve(context: Context<InitializeReserve>, config: ReserveConfig) -> Result<()> {
config.validate()?;

let reserve = &mut context.accounts.reserve;
Expand All @@ -28,7 +28,7 @@ pub fn handle_init_reserve(context: Context<InitReserve>, config: ReserveConfig)
}

#[derive(Accounts)]
pub struct InitReserve<'info> {
pub struct InitializeReserve<'info> {
// The reserve PDA below is seeded by this market's address, so the market is
// pinned by that seed; we only need to prove the signer owns it.
#[account(has_one = owner)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
pub mod collect_protocol_fees;
pub mod init_lending_market;
pub mod init_reserve;
pub mod initialize_lending_market;
pub mod initialize_reserve;
pub mod set_price;
pub mod update_reserve_config;

pub use collect_protocol_fees::*;
pub use init_lending_market::*;
pub use init_reserve::*;
pub use initialize_lending_market::*;
pub use initialize_reserve::*;
pub use set_price::*;
pub use update_reserve_config::*;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anchor_lang::prelude::*;
use crate::constants::OBLIGATION_SEED;
use crate::state::{LendingMarket, Obligation};

pub fn handle_init_obligation(context: Context<InitObligation>) -> Result<()> {
pub fn handle_initialize_obligation(context: Context<InitializeObligation>) -> Result<()> {
let obligation = &mut context.accounts.obligation;
obligation.lending_market = context.accounts.lending_market.key();
obligation.owner = context.accounts.owner.key();
Expand All @@ -21,7 +21,7 @@ pub fn handle_init_obligation(context: Context<InitObligation>) -> Result<()> {
}

#[derive(Accounts)]
pub struct InitObligation<'info> {
pub struct InitializeObligation<'info> {
pub lending_market: Account<'info, LendingMarket>,

#[account(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub mod admin;
pub mod borrow_obligation_liquidity;
pub mod deposit_obligation_collateral;
pub mod deposit_reserve_liquidity;
pub mod init_obligation;
pub mod initialize_obligation;
pub mod liquidate_obligation;
pub mod redeem_reserve_collateral;
pub mod refresh_obligation;
Expand All @@ -14,7 +14,7 @@ pub use admin::*;
pub use borrow_obligation_liquidity::*;
pub use deposit_obligation_collateral::*;
pub use deposit_reserve_liquidity::*;
pub use init_obligation::*;
pub use initialize_obligation::*;
pub use liquidate_obligation::*;
pub use redeem_reserve_collateral::*;
pub use refresh_obligation::*;
Expand Down
Loading
Loading