Giter VIP home page Giter VIP logo

anchor-coin-flip's Introduction

anchor-coin-flip

anchor-coin-flip's People

Contributors

chaindev931105 avatar ohaddahan avatar

Watchers

 avatar

Forkers

btcltc

anchor-coin-flip's Issues

execute wallet

In the 2 txn flow, the core should store the pubkey of the executer , the wallet than can run the 2nd txn.
We don't want it to be the admin since the private key of the executer will need to be in the backend, so we don't want to expose it.

Admin/Operator setup

We need to define a new type of user Operator.

Admin:

  • Creates core.
  • Defines fee of fee , and in each bet, the fee is split between admin and operator.

Operator:

  • Defines fee.
  • Register mint.
  • Can deposit.
  • Can withdraw.

Merge?

#[derive(AnchorSerialize, AnchorDeserialize)]
pub struct BetSolArgs {
pub core_state_nonce: u8,
pub amount: u64,
pub bet_side: bool, // true = Head, false = Tail
}
#[derive(AnchorSerialize, AnchorDeserialize)]
pub struct BetSplArgs {
pub core_state_nonce: u8,
pub amount: u64,
pub bet_side: bool, // true = Head, false = Tail
pub token_mint: Pubkey,
}

Can use wrapped sol, then we have only one type of these.

https://github.com/metaplex-foundation/metaplex-program-library/blob/11be56b934b93ebb2066eefabbf7f4f2adbbe04e/auction-house/program/src/lib.rs#L80

https://github.com/metaplex-foundation/metaplex-program-library/blob/11be56b934b93ebb2066eefabbf7f4f2adbbe04e/auction-house/program/src/lib.rs#L95-L127

seperate

let mut hasher = DefaultHasher::new();
[clock, core_state.flip_counter].hash(&mut hasher);
let hash = hasher.finish();
if ((hash == 0) ^ args.bet_side) {
let vault_auth_seeds = [
VAULT_AUTH_SEED.as_bytes(),
core_state.admin.as_ref(),
&[core_state.vault_auth_nonce],
];
if !is_native {
utils::assert_is_ata(&user_token_account, &user.key(), &token_mint.key())?;
anchor_lang::solana_program::program::invoke_signed(
&spl_token::instruction::transfer(
&token_program.key(),
&vault_token_account.key(),
&user_token_account.key(),
&vault_authority.key(),
&[],
2 * args.amount - args.fee,
)?,
&[
vault_token_account.to_account_info(),
user_token_account.to_account_info(),
token_program.to_account_info(),
vault_authority.to_account_info(),
],
&[&vault_auth_seeds],
)?;
} else {
utils::assert_keys_equal(user_token_account.key(), user.key())?;
utils::assert_keys_equal(vault_token_account.key(), vault_authority.key())?;
anchor_lang::solana_program::program::invoke_signed(
&anchor_lang::solana_program::system_instruction::transfer(
&vault_token_account.key(),
&user_token_account.key(),
2 * args.amount - args.fee,
),
&[
vault_token_account.to_account_info(),
user_token_account.to_account_info(),
system_program.to_account_info(),
user.to_account_info(),
],
&[&vault_auth_seeds],
)?;
}
msg!("Congratulations, You won!");
}

need to move this part to a separate method, we want to avoid users being able to see the instruction that says who won.

close core/vault

Incase we update the struct we need to also be able to close the existing accounts or it will not let us create with the updated form.

Also, upon closer, all funds in core/vault should be sent to the admin.

withdraw destination should be in core and mint too

pub struct CoreState {
pub core_state_nonce: u8,
pub vault_auth_nonce: u8,
pub admin: Pubkey, // admin public key
pub flip_counter: u64,
}

we want to make each core use a specific mint, to avoid a mess of people trying to bet with various unrelated mints.

the withdraw destination should be predefined doing creation, to ensure more security
=> can add an update instruction to all of these for flexibility

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.