Skip to content
New issue

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

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

Already on GitHub? # to your account

Use native Anchor code generation #489

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion .yarn/sdks/eslint/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint",
"version": "8.13.0-sdk",
"version": "8.14.0-sdk",
"main": "./lib/api.js",
"type": "commonjs"
}
33 changes: 17 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@
"devDependencies": {
"@project-serum/anchor": "^0.24.2",
"@rushstack/eslint-patch": "^1.1.3",
"@saberhq/anchor-contrib": "^1.12.61",
"@saberhq/chai-solana": "^1.12.61",
"@saberhq/eslint-config": "^1.12.61",
"@saberhq/solana-contrib": "^1.12.61",
"@saberhq/token-utils": "^1.12.61",
"@saberhq/tsconfig": "^1.12.61",
"@solana/web3.js": "^1.39.1",
"@saberhq/anchor-contrib": "^1.12.67",
"@saberhq/chai-solana": "^1.12.67",
"@saberhq/eslint-config": "^1.12.67",
"@saberhq/solana-contrib": "^1.12.67",
"@saberhq/token-utils": "^1.12.67",
"@saberhq/tsconfig": "^1.12.67",
"@solana/web3.js": "^1.41.1",
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.1",
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.24",
"@types/mocha": "^9.1.1",
"@types/node": "^17.0.29",
"@types/prettier": "^2.6.0",
"bn.js": "^5.2.0",
"chai": "=4.3.4",
"eslint": "^8.13.0",
"eslint": "^8.14.0",
"eslint-import-resolver-node": "^0.3.6",
"eslint-plugin-import": "^2.26.0",
"husky": "^7.0.4",
"jsbi": "^4.2.1",
"lint-staged": "^12.3.8",
"jsbi": "^4.3.0",
"lint-staged": "^12.4.1",
"mocha": "^9.2.2",
"prettier": "^2.6.2",
"ts-node": "^10.7.0",
Expand Down Expand Up @@ -85,7 +85,7 @@
"dependencies": {
"superstruct": "^0.15.4",
"tiny-invariant": "^1.2.0",
"tslib": "^2.3.1"
"tslib": "^2.4.0"
},
"packageManager": "yarn@3.2.0"
}
9 changes: 1 addition & 8 deletions programs/quarry-merge-mine/src/account_validators.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
//! Account validators

use anchor_lang::prelude::*;
use vipers::prelude::*;

use crate::{
ClaimRewards, InitMergeMiner, InitMiner, NewPool, QuarryStake, QuarryStakePrimary,
QuarryStakeReplica, WithdrawTokens,
};
use anchor_lang::Key;
use crate::*;

// --------------------------------
// Instruction account validators
Expand Down
20 changes: 8 additions & 12 deletions scripts/generate-idl-types.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ shopt -s extglob
cd $(dirname $0)/..

generate_declaration_file() {
PROGRAM_SO=$1
PROGRAM_TS=$1
OUT_DIR=$2

prog="$(basename $PROGRAM_SO .json)"
prog="$(basename $PROGRAM_TS .ts)"
OUT_PATH="$OUT_DIR/$prog.ts"
if [ ! $(which gsed) ]; then
PREFIX=$(echo $prog | sed -E 's/(^|_)([a-z])/\U\2/g')
Expand All @@ -18,17 +18,13 @@ generate_declaration_file() {
typename="${PREFIX}IDL"
rawName="${PREFIX}JSON"

# types
echo "export type $typename =" >>$OUT_PATH
cat $PROGRAM_SO >>$OUT_PATH
echo ";" >>$OUT_PATH
cat $PROGRAM_TS >"$OUT_DIR/$prog.raw.ts"

cat artifacts/idl/$prog.ts | sed -E "s/${PREFIX}/Anchor${PREFIX}/" | sed -E "s/IDL: /Anchor${PREFIX}IDL: /" >>$OUT_PATH
# types
echo "import type { $PREFIX as $typename } from './$prog.raw';" >>$OUT_PATH
echo "import { IDL as $rawName } from './$prog.raw';" >>$OUT_PATH

# raw json
echo "export const $rawName: $typename =" >>$OUT_PATH
cat $PROGRAM_SO >>$OUT_PATH
echo ";" >>$OUT_PATH
echo "export { $typename, $rawName };" >>$OUT_PATH

# error type
echo "import { generateErrorMap } from '@saberhq/anchor-contrib';" >>$OUT_PATH
Expand Down Expand Up @@ -57,4 +53,4 @@ generate_sdk_idls() {
fi
}

generate_sdk_idls ./src/idls 'artifacts/idl/*.json'
generate_sdk_idls ./src/idls 'artifacts/idl/*.ts'
18 changes: 9 additions & 9 deletions src/programs/mine.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import type { Program } from "@project-serum/anchor";
import type { IdlAccounts, Program } from "@project-serum/anchor";
import type { AnchorTypes } from "@saberhq/anchor-contrib";

import type { AnchorQuarryMine } from "../idls/quarry_mine";
import type { QuarryMineIDL } from "../idls/quarry_mine";

export * from "../idls/quarry_mine";

export type MineTypes = AnchorTypes<
AnchorQuarryMine,
QuarryMineIDL,
{
rewarder: RewarderData;
quarry: QuarryData;
miner: MinerData;
}
>;

type Accounts = MineTypes["Accounts"];
export type RewarderData = Accounts["rewarder"];
export type QuarryData = Accounts["quarry"];
export type MinerData = Accounts["miner"];
type MineAccounts = IdlAccounts<QuarryMineIDL>;

export type RewarderData = MineAccounts["rewarder"];
export type QuarryData = MineAccounts["quarry"];
export type MinerData = MineAccounts["miner"];

export type MineError = MineTypes["Error"];
export type MineEvents = MineTypes["Events"];
export type MineProgram = Omit<Program<AnchorQuarryMine>, "account"> &
MineTypes["Program"];
export type MineProgram = Program<QuarryMineIDL>;

export type ClaimEvent = MineEvents["ClaimEvent"];
export type StakeEvent = MineEvents["StakeEvent"];
Expand Down
7 changes: 4 additions & 3 deletions src/programs/mintWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Program } from "@project-serum/anchor";
import type { AnchorTypes } from "@saberhq/anchor-contrib";

import type { QuarryMintWrapperIDL } from "../idls/quarry_mint_wrapper";
Expand All @@ -14,9 +15,9 @@ export type MintWrapperTypes = AnchorTypes<

type Accounts = MintWrapperTypes["Accounts"];

export type MintWrapperData = Accounts["MintWrapper"];
export type MinterData = Accounts["Minter"];
export type MintWrapperData = Accounts["mintWrapper"];
export type MinterData = Accounts["minter"];

export type MintWrapperError = MintWrapperTypes["Error"];

export type MintWrapperProgram = MintWrapperTypes["Program"];
export type MintWrapperProgram = Program<QuarryMintWrapperIDL>;
5 changes: 3 additions & 2 deletions src/programs/operator.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Program } from "@project-serum/anchor";
import type { AnchorTypes } from "@saberhq/anchor-contrib";

import type { QuarryOperatorIDL } from "../idls/quarry_operator";
Expand All @@ -12,7 +13,7 @@ export type QuarryOperatorTypes = AnchorTypes<
>;

type Accounts = QuarryOperatorTypes["Accounts"];
export type OperatorData = Accounts["Operator"];
export type OperatorData = Accounts["operator"];

export type QuarryOperatorError = QuarryOperatorTypes["Error"];
export type QuarryOperatorProgram = QuarryOperatorTypes["Program"];
export type QuarryOperatorProgram = Program<QuarryOperatorIDL>;
25 changes: 10 additions & 15 deletions src/programs/quarryMergeMine.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
import type { Program } from "@project-serum/anchor";
import type { IdlAccounts, Program } from "@project-serum/anchor";
import type { AllInstructionsMap } from "@project-serum/anchor/dist/esm/program/namespace/types";
import type { AnchorTypes } from "@saberhq/anchor-contrib";
import type { PublicKey } from "@solana/web3.js";

import type { AnchorQuarryMergeMine } from "../idls/quarry_merge_mine";
import type { QuarryMergeMineIDL } from "../idls/quarry_merge_mine";
import type { AccountMaps } from "../wrappers/mine/miner";

export * from "../idls/quarry_merge_mine";

export type QuarryMergeMineTypes = AnchorTypes<
AnchorQuarryMergeMine,
QuarryMergeMineIDL,
{
mergePool: MergePoolData;
mergeMiner: MergeMinerData;
}
>;

type Accounts = QuarryMergeMineTypes["Accounts"];
type Accounts = IdlAccounts<QuarryMergeMineIDL>;
export type MergePoolData = Accounts["mergePool"];
export type MergeMinerData = Accounts["mergeMiner"];

export type QuarryMergeMineError = QuarryMergeMineTypes["Error"];
export type QuarryMergeMineProgram = Omit<
Program<AnchorQuarryMergeMine>,
"account"
> &
QuarryMergeMineTypes["Program"];
export type QuarryMergeMineProgram = Program<QuarryMergeMineIDL>;

export type QuarryStakeAccounts = {
[A in keyof Parameters<
QuarryMergeMineProgram["instruction"]["stakePrimaryMiner"]["accounts"]
>[0]["stake"]]: PublicKey;
};
export type QuarryStakeAccounts = AccountMaps<
AllInstructionsMap<QuarryMergeMineIDL>["stakePrimaryMiner"]["accounts"][2]
>;
5 changes: 3 additions & 2 deletions src/programs/redeemer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Program } from "@project-serum/anchor";
import type { AnchorTypes } from "@saberhq/anchor-contrib";
import type { TransactionEnvelope } from "@saberhq/solana-contrib";
import type { u64 } from "@saberhq/token-utils";
Expand All @@ -15,11 +16,11 @@ export type RedeemerTypes = AnchorTypes<
>;

type Accounts = RedeemerTypes["Accounts"];
export type RedeemerData = Accounts["Redeemer"];
export type RedeemerData = Accounts["redeemer"];

export type RedeemerError = RedeemerTypes["Error"];
export type RedeemerEvents = RedeemerTypes["Events"];
export type RedeemerProgram = RedeemerTypes["Program"];
export type RedeemerProgram = Program<QuarryRedeemerIDL>;

export type PendingRedeemer = {
bump: number;
Expand Down
5 changes: 3 additions & 2 deletions src/programs/registry.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Program } from "@project-serum/anchor";
import type { AnchorTypes } from "@saberhq/anchor-contrib";

import type { QuarryRegistryIDL } from "../idls/quarry_registry";
Expand All @@ -13,8 +14,8 @@ export type RegistryTypes = AnchorTypes<

type Accounts = RegistryTypes["Accounts"];

export type RegistryData = Accounts["Registry"];
export type RegistryData = Accounts["registry"];

export type RegistryError = RegistryTypes["Error"];

export type RegistryProgram = RegistryTypes["Program"];
export type RegistryProgram = Program<QuarryRegistryIDL>;
Loading