Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For much larger games the authority (or permissionless) oracle may want to be resized. #30

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This configuration file was automatically generated by Gitpod.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove gitpod config

# Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file)
# and commit this file to your remote git repository to share the goodness with others.

tasks:
- init: yarn install


30 changes: 29 additions & 1 deletion js/cli/src/matches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,35 @@ programCommand("drain_oracle")
);
});

programCommand("resize_oracle")
.requiredOption(
"-cp, --config-path <string>",
"JSON file with match settings"
)
.action(async (files: string[], cmd) => {
const { keypair, env, configPath, rpcUrl } = cmd.opts();

const walletKeyPair = loadWalletKey(keypair);
const anchorProgram = await getMatchesProgram(walletKeyPair, env, rpcUrl);

if (configPath === undefined) {
throw new Error("The configPath is undefined");
}
const configString = fs.readFileSync(configPath);

//@ts-ignore
const config = JSON.parse(configString);

await anchorProgram.resizeOracle({
authority: config.oracleState.authority
? new web3.PublicKey(config.oracleState.authority)
: walletKeyPair.publicKey,
seed: config.oracleState.seed,
resize: config.resize ? new BN(config.resize) : new BN(150),
staccDOTsol marked this conversation as resolved.
Show resolved Hide resolved

staccDOTsol marked this conversation as resolved.
Show resolved Hide resolved
});
});

programCommand("create_or_update_oracle")
.requiredOption(
"-cp, --config-path <string>",
Expand Down Expand Up @@ -430,7 +459,6 @@ 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
53 changes: 52 additions & 1 deletion js/lib/src/contract/matches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ export interface CreateMatchAdditionalArgs {
tokenTransferRoot: null;
tokenTransfers: null | AnchorTokenDelta[];
}

export interface ResizeOracleArgs {
seed: string;
authority: web3.PublicKey;
resize: BN;
}
export interface CreateOrUpdateOracleArgs {
seed: string;
authority: web3.PublicKey;
Expand Down Expand Up @@ -538,6 +542,37 @@ export class MatchesInstruction {
signers: [],
};
}

async resizeOracle(
args: ResizeOracleArgs,
_accounts = {},
_additionalArgs = {}
) {
const [oracle, _oracleBump] = await getOracle(
new web3.PublicKey(args.seed),
args.authority
);

const match = (await getMatch(oracle))[0];
Copy link
Collaborator

@long-banana long-banana Aug 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this to matchInstance, simplifies the accounts struct below.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget about this one


return {
instructions: [
await this.program.methods
.resizeOracle({
...args,
})
.accounts({
oracle,
matchInstance: match,
payer: (this.program.provider as AnchorProvider).wallet.publicKey,
systemProgram: SystemProgram.programId,
rent: web3.SYSVAR_RENT_PUBKEY,
})
.instruction(),
],
signers: [],
};
}
}

export class MatchesProgram {
Expand Down Expand Up @@ -745,6 +780,22 @@ export class MatchesProgram {
signers
);
}

async resizeOracle(
args: ResizeOracleArgs,
_accounts = {},
_additionalArgs = {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove _accounts and _additionalArgs as parameters.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you removed these ones from the resizeOracle instruction function, but still need to remove from here, on the program resizeOracle function

) {
const { instructions, signers } =
await this.instruction.resizeOracle(args);

await sendTransactionWithRetry(
(this.program.provider as AnchorProvider).connection,
(this.program.provider as AnchorProvider).wallet,
instructions,
signers
);
}
}

export async function getMatchesProgram(
Expand Down
10 changes: 5 additions & 5 deletions rust/matches/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub mod matches {
use super::*;

pub fn resize_oracle<'a, 'b, 'c, 'info>(
staccDOTsol marked this conversation as resolved.
Show resolved Hide resolved
ctx: Context<'a, 'b, 'c, 'info, ReizeOracle<'info>>,
ctx: Context<'a, 'b, 'c, 'info, ResizeOracle<'info>>,
args: ResizeOracleArgs,
) -> Result<()> {

Expand Down Expand Up @@ -795,13 +795,13 @@ 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(constraint=oracle.key() == match_instance.win_oracle)]
oracle: UncheckedAccount<'info>,
staccDOTsol marked this conversation as resolved.
Show resolved Hide resolved
#[account(mut, seeds=[PREFIX.as_bytes(), match_instance.win_oracle.as_ref()], bump=match_instance.bump)]
match_instance: Account<'info, Match>,
#[account(mut)]
payer: Signer<'info>,
system_program: Program<'info, System>,
Expand Down