Skip to content
Closed
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
1 change: 1 addition & 0 deletions js/cli/example-configs/match/createMatch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"winOracle": null,
"matchState": { "started": true },
"winOracleCooldown": 10,
"resize": 300,
"space": 300,
"minimumAllowedEntryTime": null,
"tokenEntryValidation": [
Expand Down
28 changes: 28 additions & 0 deletions js/cli/example-configs/match/createMatchResize.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"winOracle": null,
"matchState": { "started": true },
"winOracleCooldown": 0,
"space": 150,
"resize": 300,
"minimumAllowedEntryTime": null,
"tokenEntryValidation": null,
"authority": "CMVfmxKAK1VQMFAQifnpsmTmg2JEdLtw5MkmqqHm9wCY",
"leaveAllowed": true,
"joinAllowedDuringStart": true,
"oracleState": {
"seed": "8A2vFzJbq1vAR6HrY3J8uoqowK93hW7LXdyjnUtf2nre",
"authority": "CMVfmxKAK1VQMFAQifnpsmTmg2JEdLtw5MkmqqHm9wCY",
"finalized": false,
"tokenTransferRoot": null,
"tokenTransfers": [ ]
},
"tokensToJoin": [
{
"mint": "HQaQJG6d1CsmaosGY7HTV4UTN1ShpeqjNKZhj1rFSShn",
"amount": 1,
"sourceType": 1,
"index": 0,
"validationProgram": "nameAxQRRBnd4kLfsVoZBBXfrByZdZTkh8mULLxLyqV"
}
]
}
1 change: 1 addition & 0 deletions js/cli/src/matches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ programCommand("create_or_update_oracle")
tokenTransferRoot: config.oracleState.tokenTransferRoot,
tokenTransfers: config.oracleState.tokenTransfers,
space: config.space ? new BN(config.space) : new BN(150),
resize: config.resize ? new BN(config.resize) : new BN(150),
finalized: config.oracleState.finalized,
});
});
Expand Down
2,760 changes: 0 additions & 2,760 deletions js/cli/yarn.lock

This file was deleted.

1 change: 1 addition & 0 deletions js/lib/src/contract/matches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export interface CreateMatchAdditionalArgs {
export interface CreateOrUpdateOracleArgs {
seed: string;
authority: web3.PublicKey;
resize: BN,
space: BN;
finalized: boolean;
tokenTransferRoot: null;
Expand Down
52 changes: 52 additions & 0 deletions rust/matches/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ pub struct CreateOrUpdateOracleArgs {
finalized: bool,
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone)]
pub struct ResizeOracleArgs {
resize: u64,
}
#[derive(AnchorSerialize, AnchorDeserialize, Clone)]
pub struct DrainOracleArgs {
seed: Pubkey,
Expand Down Expand Up @@ -95,6 +99,41 @@ pub mod matches {

use super::*;

pub fn resize_oracle<'a, 'b, 'c, 'info>(
ctx: Context<'a, 'b, 'c, 'info, ReizeOracle<'info>>,
args: ResizeOracleArgs,
) -> Result<()> {

let win_oracle = &mut ctx.accounts.oracle;

let win_oracle_account = win_oracle.to_account_info();

if args.resize as usize > win_oracle_account.data.borrow().len() {
let system_program = &ctx.accounts.system_program;
let payer = &ctx.accounts.payer;
let payer_account = payer.to_account_info();
let new_size = args.resize as usize;

let rent = Rent::get()?;
let new_minimum_balance = rent.minimum_balance(new_size);

let lamports_diff = new_minimum_balance.saturating_sub(win_oracle_account.lamports());
invoke(
&system_instruction::transfer(payer_account.key, win_oracle_account.key, lamports_diff),
&[
payer_account.clone(),
win_oracle_account.clone(),
system_program.to_account_info().clone(),
],
)?;

win_oracle_account.realloc(new_size, false)?;

}

Ok(())
}

pub fn create_or_update_oracle<'a, 'b, 'c, 'info>(
ctx: Context<'a, 'b, 'c, 'info, CreateOrUpdateOracle<'info>>,
args: CreateOrUpdateOracleArgs,
Expand All @@ -121,6 +160,7 @@ pub mod matches {

win_oracle.finalized = finalized;
win_oracle.token_transfer_root = token_transfer_root.clone();

win_oracle.token_transfers = token_transfers.clone();

return Ok(());
Expand Down Expand Up @@ -755,6 +795,18 @@ pub struct LeaveMatch<'info> {
token_program: Program<'info, Token>,
}

// https://github.com/raindrops-protocol/raindrops/pull/27

#[derive(Accounts)]
#[instruction(args: ResizeOracleArgs)]
pub struct ResizeOracle<'info> {
#[account(mut, seeds=[PREFIX.as_bytes(), payer.key().as_ref(), args.seed.as_ref()])]
oracle: Account<'info, WinOracle>,
#[account(mut)]
payer: Signer<'info>,
system_program: Program<'info, System>,
rent: Sysvar<'info, Rent>,
}
/// While not required to be an account owned by this program, we provide an easy
/// set of endpoitns to create oracles using the program if you don't want to do it yourself.
#[derive(Accounts)]
Expand Down
Loading