Skip to content

Commit

Permalink
Merge pull request #147 from mindrunner/develop
Browse files Browse the repository at this point in the history
Big Cleanup / Maintenance
  • Loading branch information
mindrunner authored Apr 18, 2024
2 parents 3179bc2 + 7b653a8 commit 954527e
Show file tree
Hide file tree
Showing 58 changed files with 4,361 additions and 5,885 deletions.
8,199 changes: 3,727 additions & 4,472 deletions package-lock.json

Large diffs are not rendered by default.

117 changes: 55 additions & 62 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,64 +1,57 @@
{
"name": "@staratlas/factory",
"version": "0.6.0",
"description": "Star Atlas Factory for constructing Transactions targeting Solana on-chain programs",
"repository": {
"type": "git",
"url": "git+https://github.com/staratlasmeta/factory.git"
},
"author": "ATMTA, Inc.",
"license": "ISC",
"bugs": {
"url": "https://github.com/staratlasmeta/factory/issues"
},
"homepage": "https://github.com/staratlasmeta/factory#readme",
"main": "dist/index.js",
"source": "src/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"clean": "rm -rf dist",
"prepare": "npm run build",
"lint": "eslint src --max-warnings=0",
"lint:fix": "npm run lint -- --fix",
"test": "jest --detectOpenHandles --no-cache --silent",
"start": "tsc --watch",
"docs": "npx typedoc --out docs src",
"ts-node": "ts-node"
},
"dependencies": {
"@project-serum/anchor": "^0.24.2",
"@saberhq/anchor-contrib": "^1.12.64",
"@solana/spl-token": "^0.1.8",
"@solana/web3.js": "^1.15.0",
"@types/big.js": "^6.1.5",
"big.js": "^6.2.1",
"bn.js": "^5.1.3",
"js-sha3": "^0.8.0",
"mobx": "^6.3.13",
"mobx-utils": "^6.0.5"
},
"devDependencies": {
"@types/big.js": "^6.1.5",
"@types/bs58": "^4.0.1",
"@types/jest": "^27.0.2",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"babel-eslint": "^10.1.0",
"borsh": "^0.4.0",
"bs58": "^4.0.1",
"cross-env": "^7.0.3",
"eslint": "^7.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^27.0.6",
"prettier": "^2.7.1",
"ts-jest": "^27.0.2",
"typedoc": "^0.22.10",
"typescript": "^4.3.2"
},
"files": [
"dist"
]
"name": "@staratlas/factory",
"version": "0.6.0",
"description": "Star Atlas Factory for constructing Transactions targeting Solana on-chain programs",
"repository": {
"type": "git",
"url": "git+https://github.com/staratlasmeta/factory.git"
},
"author": "ATMTA, Inc.",
"license": "ISC",
"bugs": {
"url": "https://github.com/staratlasmeta/factory/issues"
},
"homepage": "https://github.com/staratlasmeta/factory#readme",
"main": "dist/index.js",
"source": "src/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"clean": "rm -rf dist",
"prepare": "npm run build",
"lint": "eslint src --max-warnings=0",
"lint:fix": "npm run lint -- --fix",
"test": "jest --detectOpenHandles --no-cache --silent",
"start": "tsc --watch",
"docs": "npx typedoc --out docs src",
"ts-node": "ts-node"
},
"dependencies": {
"@coral-xyz/anchor": "^0.29.0",
"@solana/spl-token": "^0.4.1",
"@solana/web3.js": "^1.91.1",
"big.js": "^6.2.1",
"lodash": "^4.17.21",
"mobx": "^6.12.0",
"mobx-utils": "^6.0.8"
},
"devDependencies": {
"@types/big.js": "^6.2.2",
"@types/jest": "^29.5.12",
"@types/bn.js": "^5.1.5",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"ts-jest": "^29.1.2",
"typedoc": "^0.25.12",
"typescript": "^5.4.2"
},
"files": [
"dist"
]
}
48 changes: 20 additions & 28 deletions src/anchor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import type {
Context as AnchorContext,
Program as AProgram,
ProgramAccount,
StateClient,
} from '@project-serum/anchor';
} from '@coral-xyz/anchor';
import type {
Idl,
IdlAccountItem,
Expand All @@ -26,7 +25,7 @@ import type {
IdlType,
IdlTypeDef,
IdlTypeDefTyStruct,
} from '@project-serum/anchor/dist/esm/idl';
} from '@coral-xyz/anchor/dist/esm/idl';
import type {
AccountMeta,
PublicKey,
Expand Down Expand Up @@ -58,7 +57,7 @@ type Context<A extends IdlAccountItem[]> = Omit<AnchorContext, 'accounts'> & {
type MakeInstructionsNamespace<
R extends InstructionsParsed,
Ret,
Mk extends { [M in keyof R]: unknown } = { [M in keyof R]: unknown }
Mk extends { [M in keyof R]: unknown } = { [M in keyof R]: unknown },
> = {
[M in keyof R]: ((
...args: [...R[M]['args'], Context<R[M]['accounts']>]
Expand Down Expand Up @@ -132,18 +131,18 @@ type TypeMap = {
type DecodeType<T extends IdlType, Defined> = T extends keyof TypeMap
? TypeMap[T]
: T extends { defined: keyof Defined }
? Defined[T['defined']]
: T extends { option: { defined: keyof Defined } }
? Defined[T['option']['defined']] | null
: T extends { option: keyof TypeMap }
? TypeMap[T['option']] | null
: T extends { vec: { defined: keyof Defined } }
? Defined[T['vec']['defined']][]
: T extends { vec: keyof TypeMap }
? TypeMap[T['vec']][]
: T extends { array: [idlType: keyof TypeMap, size: number] }
? TypeMap[T['array'][0]][]
: unknown;
? Defined[T['defined']]
: T extends { option: { defined: keyof Defined } }
? Defined[T['option']['defined']] | null
: T extends { option: keyof TypeMap }
? TypeMap[T['option']] | null
: T extends { vec: { defined: keyof Defined } }
? Defined[T['vec']['defined']][]
: T extends { vec: keyof TypeMap }
? TypeMap[T['vec']][]
: T extends { array: [idlType: keyof TypeMap, size: number] }
? TypeMap[T['array'][0]][]
: unknown;

type MakeArgs<A extends IdlField[], Defined> = {
[K in keyof A]: A[K] extends IdlField
Expand Down Expand Up @@ -175,15 +174,14 @@ export type AnchorProgram<
Defined
> = MakeInstructions<IDL['instructions'], Defined>,
Methods extends MakeInstructions<
NonNullable<IDL['state']>['methods'],
NonNullable<IDL['instructions']>,
Defined
> = MakeInstructions<NonNullable<IDL['state']>['methods'], Defined>
> = MakeInstructions<NonNullable<IDL['instructions']>, Defined>,
> = Omit<
AProgram,
'rpc' | 'state' | 'account' | 'transaction' | 'instruction'
> & {
rpc: RpcNamespace<RPCInstructions>;
state: StateClient<IDL>;
account: AccountsNamespace<A>;
transaction: TransactionNamespace<RPCInstructions & Methods>;
instruction: InstructionNamespace<RPCInstructions & Methods>;
Expand All @@ -210,32 +208,26 @@ type AnchorTypeDefs<T extends IdlTypeDef[], Defined> = {

export type AnchorDefined<
T extends Idl,
D = Record<string, never>
D = Record<string, never>,
> = AnchorTypeDefs<NonNullable<T['types']>, D>;

export type AnchorAccounts<T extends Idl, Defined> = AnchorTypeDefs<
NonNullable<T['accounts']>,
Defined
>;

export type AnchorState<T extends Idl, Defined> = AnchorTypeDef<
NonNullable<T['state']>['struct'],
Defined
>;

export type AnchorTypes<
T extends Idl,
AccountMap = Record<string, never>,
D = Record<string, never>,
DEF = AnchorDefined<T, D>
DEF = AnchorDefined<T, D>,
> = {
Defined: DEF;
Accounts: AnchorAccounts<T, DEF>;
State: AnchorState<T, DEF>;
Error: AnchorError<T>;
Program: AnchorProgram<T, AccountMap, DEF>;
Instructions: MakeInstructions<T['instructions'], DEF>;
Methods: MakeInstructions<NonNullable<T['state']>['methods'], DEF>;
Methods: MakeInstructions<NonNullable<T['instructions']>, DEF>;
Events: AnchorEvents<NonNullable<T['events']>[number], DEF>;
AccountMap: AccountMap;
IDL: T;
Expand Down
2 changes: 1 addition & 1 deletion src/atlas-staking/instruction_builders/baseParams.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { web3 } from '@project-serum/anchor';
import { web3 } from '@coral-xyz/anchor';

/**
* Base parameters for all instructions
Expand Down
2 changes: 1 addition & 1 deletion src/atlas-staking/instruction_builders/cancelUnstake.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { web3 } from '@project-serum/anchor';
import { web3 } from '@coral-xyz/anchor';
import { FactoryReturn } from '../../types';
import { getStakingProgram } from '../utils';
import { BaseStakingParams } from './baseParams';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { web3 } from '@project-serum/anchor';
import { web3 } from '@coral-xyz/anchor';
import { FactoryReturn } from '../../types';
import { getStakingProgram } from '../utils';
import { BaseStakingParams } from './baseParams';
Expand Down
4 changes: 2 additions & 2 deletions src/atlas-staking/instruction_builders/harvestRewards.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { web3 } from '@project-serum/anchor';
import { associatedAddress } from '@project-serum/anchor/dist/cjs/utils/token';
import { web3 } from '@coral-xyz/anchor';
import { associatedAddress } from '@coral-xyz/anchor/dist/cjs/utils/token';
import { FactoryReturn } from '../../types';
import { getTokenAccount } from '../../util';
import { getStakingProgram } from '../utils';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { web3 } from '@project-serum/anchor';
import { web3 } from '@coral-xyz/anchor';
import { FactoryReturn } from '../../types';
import { getStakingProgram } from '../utils';
import { BaseStakingParams } from './baseParams';
Expand Down
6 changes: 3 additions & 3 deletions src/atlas-staking/instruction_builders/registerStake.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BN, web3 } from '@project-serum/anchor';
import { associatedAddress } from '@project-serum/anchor/dist/cjs/utils/token';
import { BN, web3 } from '@coral-xyz/anchor';
import { associatedAddress } from '@coral-xyz/anchor/dist/cjs/utils/token';
import { FactoryReturn } from '../../types';
import { getRegisteredStake } from '../pda_getters';
import { getStakingProgram } from '../utils';
Expand Down Expand Up @@ -40,7 +40,7 @@ export async function registerStakeInstruction({
programId,
authority,
stakeMint,
rewardMint
rewardMint,
);
const rewardAta = await associatedAddress({
owner: registeredStake,
Expand Down
2 changes: 1 addition & 1 deletion src/atlas-staking/instruction_builders/settle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { web3 } from '@project-serum/anchor';
import { web3 } from '@coral-xyz/anchor';
import { FactoryReturn } from '../../types';
import { getStakingProgram } from '../utils';
import { BaseStakingParams } from './baseParams';
Expand Down
4 changes: 2 additions & 2 deletions src/atlas-staking/instruction_builders/stakeTokens.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BN, web3 } from '@project-serum/anchor';
import { associatedAddress } from '@project-serum/anchor/dist/cjs/utils/token';
import { BN, web3 } from '@coral-xyz/anchor';
import { associatedAddress } from '@coral-xyz/anchor/dist/cjs/utils/token';
import { FactoryReturn } from '../../types';
import { getStakingProgram } from '../utils';
import { BaseStakingParams } from './baseParams';
Expand Down
6 changes: 3 additions & 3 deletions src/atlas-staking/instruction_builders/unstakeTokens.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { web3 } from '@project-serum/anchor';
import { associatedAddress } from '@project-serum/anchor/dist/cjs/utils/token';
import { web3 } from '@coral-xyz/anchor';
import { associatedAddress } from '@coral-xyz/anchor/dist/cjs/utils/token';
import { FactoryReturn } from '../../types';
import { getTokenAccount } from '../../util';
import { getRegisteredStakeAccountInfo } from '../pda_getters';
Expand Down Expand Up @@ -39,7 +39,7 @@ export async function unstakeTokensInstruction({
const registeredStakeInfo = await getRegisteredStakeAccountInfo(
connection,
registeredStake,
programId
programId,
);
const rewardMint = registeredStakeInfo.rewardMint;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BN, web3 } from '@project-serum/anchor';
import { BN, web3 } from '@coral-xyz/anchor';
import { FactoryReturn } from '../../types';
import { getStakingProgram } from '../utils';
import { BaseStakingParams } from './baseParams';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BN, web3 } from '@project-serum/anchor';
import { BN, web3 } from '@coral-xyz/anchor';
import { FactoryReturn } from '../../types';
import { getStakingProgram } from '../utils';
import { BaseStakingParams } from './baseParams';
Expand Down
4 changes: 2 additions & 2 deletions src/atlas-staking/instruction_builders/withdrawTokens.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseStakingParams } from './baseParams';
import { web3 } from '@project-serum/anchor';
import { associatedAddress } from '@project-serum/anchor/dist/cjs/utils/token';
import { web3 } from '@coral-xyz/anchor';
import { associatedAddress } from '@coral-xyz/anchor/dist/cjs/utils/token';
import { getStakingProgram } from '../utils';
import { FactoryReturn } from '../../types';
import { getTokenAccount } from '../../util';
Expand Down
Loading

0 comments on commit 954527e

Please sign in to comment.