-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clients: Add client generation (#18)
* Use individual dependencies * Rearrange dependencies * Add client generation * Tweak formatting * Add shank dependency * Update codama configuration * Bump codama version * Update generated clients * Add trait overrides * Add stake account * Update generated clients * Fix account removal * Rename stake state account * Fix name conflict * Add caret * Fix typo * Remove shank dependency * Remove skip formatting
- Loading branch information
Showing
78 changed files
with
6,453 additions
and
2,273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* This code was AUTOGENERATED using the codama library. | ||
* Please DO NOT EDIT THIS FILE, instead use visitors | ||
* to add features, then rerun codama to update it. | ||
* | ||
* @see https://github.com/codama-idl/codama | ||
*/ | ||
|
||
export * from './stakeStateAccount'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/** | ||
* This code was AUTOGENERATED using the codama library. | ||
* Please DO NOT EDIT THIS FILE, instead use visitors | ||
* to add features, then rerun codama to update it. | ||
* | ||
* @see https://github.com/codama-idl/codama | ||
*/ | ||
|
||
import { | ||
assertAccountExists, | ||
assertAccountsExist, | ||
combineCodec, | ||
decodeAccount, | ||
fetchEncodedAccount, | ||
fetchEncodedAccounts, | ||
getStructDecoder, | ||
getStructEncoder, | ||
type Account, | ||
type Address, | ||
type Codec, | ||
type Decoder, | ||
type EncodedAccount, | ||
type Encoder, | ||
type FetchAccountConfig, | ||
type FetchAccountsConfig, | ||
type MaybeAccount, | ||
type MaybeEncodedAccount, | ||
} from '@solana/web3.js'; | ||
import { | ||
getStakeStateV2Decoder, | ||
getStakeStateV2Encoder, | ||
type StakeStateV2, | ||
type StakeStateV2Args, | ||
} from '../types'; | ||
|
||
export type StakeStateAccount = { state: StakeStateV2 }; | ||
|
||
export type StakeStateAccountArgs = { state: StakeStateV2Args }; | ||
|
||
export function getStakeStateAccountEncoder(): Encoder<StakeStateAccountArgs> { | ||
return getStructEncoder([['state', getStakeStateV2Encoder()]]); | ||
} | ||
|
||
export function getStakeStateAccountDecoder(): Decoder<StakeStateAccount> { | ||
return getStructDecoder([['state', getStakeStateV2Decoder()]]); | ||
} | ||
|
||
export function getStakeStateAccountCodec(): Codec< | ||
StakeStateAccountArgs, | ||
StakeStateAccount | ||
> { | ||
return combineCodec( | ||
getStakeStateAccountEncoder(), | ||
getStakeStateAccountDecoder() | ||
); | ||
} | ||
|
||
export function decodeStakeStateAccount<TAddress extends string = string>( | ||
encodedAccount: EncodedAccount<TAddress> | ||
): Account<StakeStateAccount, TAddress>; | ||
export function decodeStakeStateAccount<TAddress extends string = string>( | ||
encodedAccount: MaybeEncodedAccount<TAddress> | ||
): MaybeAccount<StakeStateAccount, TAddress>; | ||
export function decodeStakeStateAccount<TAddress extends string = string>( | ||
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress> | ||
): | ||
| Account<StakeStateAccount, TAddress> | ||
| MaybeAccount<StakeStateAccount, TAddress> { | ||
return decodeAccount( | ||
encodedAccount as MaybeEncodedAccount<TAddress>, | ||
getStakeStateAccountDecoder() | ||
); | ||
} | ||
|
||
export async function fetchStakeStateAccount<TAddress extends string = string>( | ||
rpc: Parameters<typeof fetchEncodedAccount>[0], | ||
address: Address<TAddress>, | ||
config?: FetchAccountConfig | ||
): Promise<Account<StakeStateAccount, TAddress>> { | ||
const maybeAccount = await fetchMaybeStakeStateAccount(rpc, address, config); | ||
assertAccountExists(maybeAccount); | ||
return maybeAccount; | ||
} | ||
|
||
export async function fetchMaybeStakeStateAccount< | ||
TAddress extends string = string, | ||
>( | ||
rpc: Parameters<typeof fetchEncodedAccount>[0], | ||
address: Address<TAddress>, | ||
config?: FetchAccountConfig | ||
): Promise<MaybeAccount<StakeStateAccount, TAddress>> { | ||
const maybeAccount = await fetchEncodedAccount(rpc, address, config); | ||
return decodeStakeStateAccount(maybeAccount); | ||
} | ||
|
||
export async function fetchAllStakeStateAccount( | ||
rpc: Parameters<typeof fetchEncodedAccounts>[0], | ||
addresses: Array<Address>, | ||
config?: FetchAccountsConfig | ||
): Promise<Account<StakeStateAccount>[]> { | ||
const maybeAccounts = await fetchAllMaybeStakeStateAccount( | ||
rpc, | ||
addresses, | ||
config | ||
); | ||
assertAccountsExist(maybeAccounts); | ||
return maybeAccounts; | ||
} | ||
|
||
export async function fetchAllMaybeStakeStateAccount( | ||
rpc: Parameters<typeof fetchEncodedAccounts>[0], | ||
addresses: Array<Address>, | ||
config?: FetchAccountsConfig | ||
): Promise<MaybeAccount<StakeStateAccount>[]> { | ||
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); | ||
return maybeAccounts.map((maybeAccount) => | ||
decodeStakeStateAccount(maybeAccount) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* This code was AUTOGENERATED using the codama library. | ||
* Please DO NOT EDIT THIS FILE, instead use visitors | ||
* to add features, then rerun codama to update it. | ||
* | ||
* @see https://github.com/codama-idl/codama | ||
*/ | ||
|
||
export * from './stake'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/** | ||
* This code was AUTOGENERATED using the codama library. | ||
* Please DO NOT EDIT THIS FILE, instead use visitors | ||
* to add features, then rerun codama to update it. | ||
* | ||
* @see https://github.com/codama-idl/codama | ||
*/ | ||
|
||
import { | ||
isProgramError, | ||
type Address, | ||
type SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM, | ||
type SolanaError, | ||
} from '@solana/web3.js'; | ||
import { STAKE_PROGRAM_ADDRESS } from '../programs'; | ||
|
||
export const STAKE_ERROR__NO_CREDITS_TO_REDEEM = 0x0; // 0 | ||
|
||
export const STAKE_ERROR__LOCKUP_IN_FORCE = 0x1; // 1 | ||
|
||
export const STAKE_ERROR__ALREADY_DEACTIVATED = 0x2; // 2 | ||
|
||
export const STAKE_ERROR__TOO_SOON_TO_REDELEGATE = 0x3; // 3 | ||
|
||
export const STAKE_ERROR__INSUFFICIENT_STAKE = 0x4; // 4 | ||
|
||
export const STAKE_ERROR__MERGE_TRANSIENT_STAKE = 0x5; // 5 | ||
|
||
export const STAKE_ERROR__MERGE_MISMATCH = 0x6; // 6 | ||
|
||
export const STAKE_ERROR__CUSTODIAN_MISSING = 0x7; // 7 | ||
|
||
export const STAKE_ERROR__CUSTODIAN_SIGNATURE_MISSING = 0x8; // 8 | ||
|
||
export const STAKE_ERROR__INSUFFICIENT_REFERENCE_VOTES = 0x9; // 9 | ||
|
||
export const STAKE_ERROR__VOTE_ADDRESS_MISMATCH = 0xa; // 10 | ||
|
||
export const STAKE_ERROR__MINIMUM_DELINQUENT_EPOCHS_FOR_DEACTIVATION_NOT_MET = 0xb; // 11 | ||
|
||
export const STAKE_ERROR__INSUFFICIENT_DELEGATION = 0xc; // 12 | ||
|
||
export const STAKE_ERROR__REDELEGATE_TRANSIENT_OR_INACTIVE_STAKE = 0xd; // 13 | ||
|
||
export const STAKE_ERROR__REDELEGATE_TO_SAME_VOTE_ACCOUNT = 0xe; // 14 | ||
|
||
export const STAKE_ERROR__REDELEGATED_STAKE_MUST_FULLY_ACTIVATE_BEFORE_DEACTIVATION_IS_PERMITTED = 0xf; // 15 | ||
|
||
export const STAKE_ERROR__EPOCH_REWARDS_ACTIVE = 0x10; // 16 | ||
|
||
export type StakeError = | ||
| typeof STAKE_ERROR__ALREADY_DEACTIVATED | ||
| typeof STAKE_ERROR__CUSTODIAN_MISSING | ||
| typeof STAKE_ERROR__CUSTODIAN_SIGNATURE_MISSING | ||
| typeof STAKE_ERROR__EPOCH_REWARDS_ACTIVE | ||
| typeof STAKE_ERROR__INSUFFICIENT_DELEGATION | ||
| typeof STAKE_ERROR__INSUFFICIENT_REFERENCE_VOTES | ||
| typeof STAKE_ERROR__INSUFFICIENT_STAKE | ||
| typeof STAKE_ERROR__LOCKUP_IN_FORCE | ||
| typeof STAKE_ERROR__MERGE_MISMATCH | ||
| typeof STAKE_ERROR__MERGE_TRANSIENT_STAKE | ||
| typeof STAKE_ERROR__MINIMUM_DELINQUENT_EPOCHS_FOR_DEACTIVATION_NOT_MET | ||
| typeof STAKE_ERROR__NO_CREDITS_TO_REDEEM | ||
| typeof STAKE_ERROR__REDELEGATED_STAKE_MUST_FULLY_ACTIVATE_BEFORE_DEACTIVATION_IS_PERMITTED | ||
| typeof STAKE_ERROR__REDELEGATE_TO_SAME_VOTE_ACCOUNT | ||
| typeof STAKE_ERROR__REDELEGATE_TRANSIENT_OR_INACTIVE_STAKE | ||
| typeof STAKE_ERROR__TOO_SOON_TO_REDELEGATE | ||
| typeof STAKE_ERROR__VOTE_ADDRESS_MISMATCH; | ||
|
||
let stakeErrorMessages: Record<StakeError, string> | undefined; | ||
if (process.env.NODE_ENV !== 'production') { | ||
stakeErrorMessages = { | ||
[STAKE_ERROR__ALREADY_DEACTIVATED]: `Stake already deactivated`, | ||
[STAKE_ERROR__CUSTODIAN_MISSING]: `Custodian address not present`, | ||
[STAKE_ERROR__CUSTODIAN_SIGNATURE_MISSING]: `Custodian signature not present`, | ||
[STAKE_ERROR__EPOCH_REWARDS_ACTIVE]: `Stake action is not permitted while the epoch rewards period is active`, | ||
[STAKE_ERROR__INSUFFICIENT_DELEGATION]: `Delegation amount is less than the minimum`, | ||
[STAKE_ERROR__INSUFFICIENT_REFERENCE_VOTES]: `Insufficient voting activity in the reference vote account`, | ||
[STAKE_ERROR__INSUFFICIENT_STAKE]: `Split amount is more than is staked`, | ||
[STAKE_ERROR__LOCKUP_IN_FORCE]: `Lockup has not yet expired`, | ||
[STAKE_ERROR__MERGE_MISMATCH]: `Stake account merge failed due to different authority, lockups or state`, | ||
[STAKE_ERROR__MERGE_TRANSIENT_STAKE]: `Stake account with transient stake cannot be merged`, | ||
[STAKE_ERROR__MINIMUM_DELINQUENT_EPOCHS_FOR_DEACTIVATION_NOT_MET]: `Stake account has not been delinquent for the minimum epochs required for deactivation`, | ||
[STAKE_ERROR__NO_CREDITS_TO_REDEEM]: `Not enough credits to redeem`, | ||
[STAKE_ERROR__REDELEGATED_STAKE_MUST_FULLY_ACTIVATE_BEFORE_DEACTIVATION_IS_PERMITTED]: `Redelegated stake must be fully activated before deactivation`, | ||
[STAKE_ERROR__REDELEGATE_TO_SAME_VOTE_ACCOUNT]: `Stake redelegation to the same vote account is not permitted`, | ||
[STAKE_ERROR__REDELEGATE_TRANSIENT_OR_INACTIVE_STAKE]: `Stake account with transient or inactive stake cannot be redelegated`, | ||
[STAKE_ERROR__TOO_SOON_TO_REDELEGATE]: `One re-delegation permitted per epoch`, | ||
[STAKE_ERROR__VOTE_ADDRESS_MISMATCH]: `Stake account is not delegated to the provided vote account`, | ||
}; | ||
} | ||
|
||
export function getStakeErrorMessage(code: StakeError): string { | ||
if (process.env.NODE_ENV !== 'production') { | ||
return (stakeErrorMessages as Record<StakeError, string>)[code]; | ||
} | ||
|
||
return 'Error message not available in production bundles.'; | ||
} | ||
|
||
export function isStakeError<TProgramErrorCode extends StakeError>( | ||
error: unknown, | ||
transactionMessage: { | ||
instructions: Record<number, { programAddress: Address }>; | ||
}, | ||
code?: TProgramErrorCode | ||
): error is SolanaError<typeof SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM> & | ||
Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> { | ||
return isProgramError<TProgramErrorCode>( | ||
error, | ||
transactionMessage, | ||
STAKE_PROGRAM_ADDRESS, | ||
code | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.