@solana/instructions
Advanced tools
Comparing version 2.0.0-experimental.743e0a6 to 2.0.0-experimental.784f248
@@ -38,1 +38,3 @@ // src/roles.ts | ||
export { AccountRole, downgradeRoleToNonSigner, downgradeRoleToReadonly, isSignerRole, isWritableRole, mergeRoles, upgradeRoleToSigner, upgradeRoleToWritable }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.node.js.map |
{ | ||
"name": "@solana/instructions", | ||
"version": "2.0.0-experimental.743e0a6", | ||
"version": "2.0.0-experimental.784f248", | ||
"description": "Helpers for creating transaction instructions", | ||
@@ -49,12 +49,12 @@ "exports": { | ||
"devDependencies": { | ||
"@solana/eslint-config-solana": "^1.0.0", | ||
"@solana/eslint-config-solana": "^1.0.2", | ||
"@swc/core": "^1.3.18", | ||
"@swc/jest": "^0.2.23", | ||
"@types/jest": "^29.5.0", | ||
"@typescript-eslint/eslint-plugin": "^5.57.1", | ||
"@typescript-eslint/parser": "^5.57.1", | ||
"@types/jest": "^29.5.3", | ||
"@typescript-eslint/eslint-plugin": "^6.0.0", | ||
"@typescript-eslint/parser": "^6.0.0", | ||
"agadoo": "^3.0.0", | ||
"eslint": "^8.37.0", | ||
"eslint": "^8.45.0", | ||
"eslint-plugin-sort-keys-fix": "^1.1.2", | ||
"jest": "^29.5.0", | ||
"jest": "^29.6.1", | ||
"jest-runner-eslint": "^2.0.0", | ||
@@ -66,5 +66,5 @@ "jest-runner-prettier": "^1.0.0", | ||
"tsup": "6.7.0", | ||
"typescript": "^5.0.3", | ||
"typescript": "^5.1.6", | ||
"version-from-git": "^1.1.1", | ||
"@solana/keys": "2.0.0-development", | ||
"@solana/keys": "2.0.0-experimental.784f248", | ||
"build-scripts": "0.0.0", | ||
@@ -71,0 +71,0 @@ "test-config": "0.0.0", |
126
README.md
@@ -21,2 +21,13 @@ [![npm][npm-image]][npm-url] | ||
### `AccountRole` | ||
The purpose for which an account participates in a transaction is described by the `AccountRole` type. Every account that participates in a transaction can be read from, but only ones that you mark as writable may be written to, and only ones that you indicate must sign the transaction will gain the privileges associated with signers at runtime. | ||
| | `isSigner` | `isWritable` | | ||
| ----------------------------- | ---------- | ------------ | | ||
| `AccountRole.READONLY` | ❌ | ❌ | | ||
| `AccountRole.WRITABLE` | ❌ | ✅ | | ||
| `AccountRole.READONLY_SIGNER` | ✅ | ❌ | | ||
| `AccountRole.WRITABLE_SIGNER` | ✅ | ✅ | | ||
### `IAccountMeta<TAddress>` | ||
@@ -28,8 +39,8 @@ | ||
| | `isSigner` | `isWritable` | | ||
| --------------------------------- | ---------- | ------------ | | ||
| `ReadonlyAccount<TAddress>` | ❌ | ❌ | | ||
| `WritableAccount<TAddress>` | ❌ | ✅ | | ||
| `ReadonlySignerAccount<TAddress>` | ✅ | ❌ | | ||
| `WritableSignerAccount<TAddress>` | ✅ | ✅ | | ||
| | `role` | `isSigner` | `isWritable` | | ||
| --------------------------------- | ----------------------------- | ---------- | ------------ | | ||
| `ReadonlyAccount<TAddress>` | `AccountRole.READONLY` | ❌ | ❌ | | ||
| `WritableAccount<TAddress>` | `AccountRole.WRITABLE` | ❌ | ✅ | | ||
| `ReadonlySignerAccount<TAddress>` | `AccountRole.READONLY_SIGNER` | ✅ | ❌ | | ||
| `WritableSignerAccount<TAddress>` | `AccountRole.WRITABLE_SIGNER` | ✅ | ✅ | | ||
@@ -42,20 +53,99 @@ For example, you could type the rent sysvar account like this: | ||
### `Instruction<TProgramAddress, TAccounts, TData>` | ||
### `IAccountLookupMeta<TAddress, TLookupTableAddress>` | ||
Use this to define the structure of a transaction instruction. | ||
This type represents a lookup of the account's address in an address lookup table. It specifies which lookup table account in which to perform the lookup, the index of the desired account address in that table, and metadata about its mutability. Notably, account addresses obtained via lookups may not act as signers. | ||
Typically, you will use one of its subtypes. | ||
| | `role` | `isSigner` | `isWritable` | | ||
| ------------------------------------------------------ | ---------------------- | ---------- | ------------ | | ||
| `ReadonlyLookupAccount<TAddress, TLookupTableAddress>` | `AccountRole.READONLY` | ❌ | ❌ | | ||
| `WritableLookupAccount<TAddress, TLookupTableAddress>` | `AccountRole.WRITABLE` | ❌ | ✅ | | ||
For example, you could type the rent sysvar account that you looked up in a lookup table like this: | ||
```ts | ||
type InitializeStakeInstruction = Instruction< | ||
// Program address | ||
'StakeConfig11111111111111111111111111111111', | ||
// Accounts | ||
type RentSysvar = ReadonlyLookupAccount< | ||
'SysvarRent111111111111111111111111111111111', | ||
'MyLookupTable111111111111111111111111111111' | ||
>; | ||
``` | ||
### `IInstruction<TProgramAddress>` | ||
Use this to specify an instruction destined for a given program. | ||
```ts | ||
type StakeProgramInstruction = IInstruction<'StakeConfig11111111111111111111111111111111'>; | ||
``` | ||
### `IInstructionWithAccounts<TAccounts>` | ||
Use this type to specify an instruction that contains certain accounts. | ||
```ts | ||
type InstructionWithTwoAccounts = IInstructionWithAccounts< | ||
[ | ||
WritableAccount, // Stake account | ||
RentSysvar | ||
], | ||
// Data | ||
InitializeStakeInstructionData | ||
WritableAccount, // First account | ||
RentSysvar // Second account | ||
] | ||
>; | ||
``` | ||
Instructions that do not require data may omit the `TData` type parameter. | ||
### `IInstructionWithData<TData>` | ||
Use this type to specify an instruction whose data conforms to a certain type. This is most useful when you have a branded `Uint8Array` that represents a particular instruction. | ||
For example, here is how the `AdvanceNonce` instruction is typed. | ||
```ts | ||
type AdvanceNonceAccountInstruction< | ||
TNonceAccountAddress extends string = string, | ||
TNonceAuthorityAddress extends string = string | ||
> = IInstruction<'11111111111111111111111111111111'> & | ||
IInstructionWithAccounts< | ||
[ | ||
WritableAccount<TNonceAccountAddress>, | ||
ReadonlyAccount<'SysvarRecentB1ockHashes11111111111111111111'>, | ||
ReadonlySignerAccount<TNonceAuthorityAddress> | ||
] | ||
> & | ||
IInstructionWithData<AdvanceNonceAccountInstructionData>; | ||
``` | ||
## Functions | ||
### `isSignerRole(role: AccountRole)` | ||
Returns `true` if the `AccountRole` given represents that of a signer. Also refines the TypeScript type of the supplied role. | ||
### `isWritable(role: AccountRole)` | ||
Returns `true` if the `AccountRole` given represents that of a writable account. Also refines the TypeScript type of the supplied role. | ||
### `mergeRoles(roleA: AccountRole, roleB: AccountRole)` | ||
Given two `AccountRoles`, will return the `AccountRole` that grants the highest privileges of both. | ||
Example: | ||
```ts | ||
// Returns `AccountRole.WRITABLE_SIGNER` | ||
mergeRoles(AccountRole.READONLY_SIGNER, AccountRole.WRITABLE); | ||
``` | ||
### `downgradeRoleToNonSigner(role: AccountRole)` | ||
Returns an `AccountRole` representing the non-signer variant of the supplied role. | ||
### `downgradeRoleToReadonly(role: AccountRole)` | ||
Returns an `AccountRole` representing the non-writable variant of the supplied role. | ||
### `upgradeRoleToSigner(role: AccountRole)` | ||
Returns an `AccountRole` representing the signer variant of the supplied role. | ||
### `upgradeRoleToWritable(role: AccountRole)` | ||
Returns an `AccountRole` representing the writable variant of the supplied role. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57075
149
386