8000 Remove I prefixes before Instruction types by lorisleiva · Pull Request #488 · anza-xyz/kit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Remove I prefixes before Instruction types #488

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

Merged
merged 1 commit into from
May 14, 2025
Merged
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
9 changes: 9 additions & 0 deletions .changeset/weak-boxes-stay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@solana/transaction-messages': minor
'@solana/instructions': minor
'@solana/signers': minor
'@solana/compat': minor
'@solana/kit': minor
---

Remove the `I` prefix on the following types: `IInstruction`, `IInstructionWithAccounts`, `IInstructionWithData`, `IInstructionWithSigners`, `IAccountMeta`, `IAccountLookupMeta` and `IAccountSignerMeta`. The old names are kept as aliases but marked as deprecated.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ const stillNotNonceTransactionMessage = {
};

stillNotNonceTransactionMessage satisfies TransactionMessageWithDurableNonceLifetime;
// => 'readonly IInstruction<string>[]' is not assignable to type 'readonly [AdvanceNonceAccountInstruction<string, string>, ...IInstruction<string>[]]'
// => 'readonly Instruction<string>[]' is not assignable to type 'readonly [AdvanceNonceAccountInstruction<string, string>, ...Instruction<string>[]]'

const validNonceTransactionMessage = pipe(
createTransactionMessage({ version: 0 }),
Expand Down
2 changes: 1 addition & 1 deletion packages/compat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const transaction = fromVersionedTransaction(legacyVersionedTransaction);

### `fromLegacyTransactionInstruction()`

This can be used to convert a legacy `TransactionInstruction` object to a `IInstruction` object.
This can be used to convert a legacy `TransactionInstruction` object to a `Instruction` object.

```ts
import { fromLegacyTransactionInstruction } from '@solana/compat';
Expand Down
12 changes: 6 additions & 6 deletions packages/compat/src/__tests__/instruction-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import '@solana/test-matchers/toBeFrozenObject';
import { ImplicitArrayBuffer } from 'node:buffer';

import { address } from '@solana/addresses';
import { AccountRole, IInstruction } from '@solana/instructions';
import { AccountRole, Instruction } from '@solana/instructions';
import { PublicKey, TransactionInstruction } from '@solana/web3.js';

import { fromLegacyPublicKey } from '../address';
Expand Down Expand Up @@ -39,7 +39,7 @@ describe('fromLegacyTransactionInstruction', () => {

const converted = fromLegacyTransactionInstruction(instruction);

expect(converted).toStrictEqual<IInstruction>({
expect(converted).toStrictEqual<Instruction>({
accounts: [
{
address: address('7EqQdEULxWcraVx3mXKFjc84LhCkMGZCkRuDpvcMwJeK'),
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('fromLegacyTransactionInstruction', () => {

const converted = fromLegacyTransactionInstruction(instruction);

expect(converted).toStrictEqual<IInstruction>({
expect(converted).toStrictEqual<Instruction>({
data,
programAddress: fromLegacyPublicKey(new PublicKey(programId)),
});
Expand All @@ -155,7 +155,7 @@ describe('fromLegacyTransactionInstruction', () => {

const converted = fromLegacyTransactionInstruction(instruction);

expect(converted).toStrictEqual<IInstruction>({
expect(converted).toStrictEqual<Instruction>({
accounts: [
{
address: address('7EqQdEULxWcraVx3mXKFjc84LhCkMGZCkRuDpvcMwJeK'),
Expand Down Expand Up @@ -189,7 +189,7 @@ describe('fromLegacyTransactionInstruction', () => {

const converted = fromLegacyTransactionInstruction(instruction);

expect(converted).toStrictEqual<IInstruction>({
expect(converted).toStrictEqual<Instruction>({
accounts: [
{
address: address('F7Kzv7G6p1PvHXL1xXLPTm4myKWpLjnVphCV8ABZJfgT'),
Expand Down Expand Up @@ -217,7 +217,7 @@ describe('fromLegacyTransactionInstruction', () => {

const converted = fromLegacyTransactionInstruction(instruction);

expect(converted).toStrictEqual<IInstruction>({
expect(converted).toStrictEqual<Instruction>({
accounts: [
{
address: address('F7Kzv7G6p1PvHXL1xXLPTm4myKWpLjnVphCV8ABZJfgT'),
Expand Down
4 changes: 2 additions & 2 deletions packages/compat/src/__typetests__/instruction-typetest.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IInstruction } from '@solana/instructions';
import { Instruction } from '@solana/instructions';
import { TransactionInstruction } from '@solana/web3.js';

import { fromLegacyTransactionInstruction } from '../instruction';

const legacyInstruction = null as unknown as TransactionInstruction;

fromLegacyTransactionInstruction(legacyInstruction) satisfies IInstruction;
fromLegacyTransactionInstruction(legacyInstruction) satisfies Instruction;
6 changes: 3 additions & 3 deletions packages/compat/src/instruction.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AccountRole, IInstruction } from '@solana/instructions';
import { AccountRole, Instruction } from '@solana/instructions';
import { TransactionInstruction } from '@solana/web3.js';

import { fromLegacyPublicKey } from './address';

/**
* This can be used to convert a legacy [`TransactionInstruction`](https://solana-foundation.github.io/solana-web3.js/classes/TransactionInstruction.html)
* object to an {@link IInstruction}.
* object to an {@link Instruction}.
*
* @example
* ```ts
Expand All @@ -16,7 +16,7 @@ import { fromLegacyPublicKey } from './address';
* const instruction = fromLegacyTransactionInstruction(legacyInstruction);
* ```
*/
export function fromLegacyTransactionInstruction(legacyInstruction: TransactionInstruction): IInstruction {
export function fromLegacyTransactionInstruction(legacyInstruction: TransactionInstruction): Instruction {
const data = legacyInstruction.data?.byteLength > 0 ? Uint8Array.from(legacyInstruction.data) : undefined;
const accounts = legacyInstruction.keys.map(accountMeta =>
Object.freeze({
Expand Down
20 changes: 10 additions & 10 deletions packages/instructions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The purpose for which an account participates in a transaction is described by t
| `AccountRole.READONLY_SIGNER` | &#x2705; | &#x274c; |
| `AccountRole.WRITABLE_SIGNER` | &#x2705; | &#x2705; |

### `IAccountMeta<TAddress>`
### `AccountMeta<TAddress>`

This type represents an account's address and metadata about its mutability and whether it must be a signer of the transaction.

Expand All @@ -45,7 +45,7 @@ For example, you could type the rent sysvar account like this:
type RentSysvar = ReadonlyAccount<'SysvarRent111111111111111111111111111111111'>;
```

### `IAccountLookupMeta<TAddress, TLookupTableAddress>`
### `AccountLookupMeta<TAddress, TLookupTableAddress>`

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.

Expand All @@ -65,28 +65,28 @@ type RentSysvar = ReadonlyLookupAccount<
>;
```

### `IInstruction<TProgramAddress>`
### `Instruction<TProgramAddress>`

Use this to specify an instruction destined for a given program.

```ts
type StakeProgramInstruction = IInstruction<'StakeConfig11111111111111111111111111111111'>;
type StakeProgramInstruction = Instruction<'StakeConfig11111111111111111111111111111111'>;
```

### `IInstructionWithAccounts<TAccounts>`
### `InstructionWithAccounts<TAccounts>`

Use this type to specify an instruction that loads certain accounts.

```ts
type InstructionWithTwoAccounts = IInstructionWithAccounts<
type InstructionWithTwoAccounts = InstructionWithAccounts<
[
WritableAccount, // First account
RentSysvar, // Second account
]
>;
```

### `IInstructionWithData<TData>`
### `InstructionWithData<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's data.

Expand All @@ -96,15 +96,15 @@ For example, here is how the `AdvanceNonce` instruction is typed.
type AdvanceNonceAccountInstruction<
TNonceAccountAddress extends string = string,
TNonceAuthorityAddress extends string = string,
> = IInstruction<'11111111111111111111111111111111'> &
IInstructionWithAccounts<
> = Instruction<'11111111111111111111111111111111'> &
InstructionWithAccounts<
[
WritableAccount<TNonceAccountAddress>,
ReadonlyAccount<'SysvarRecentB1ockHashes11111111111111111111'>,
ReadonlySignerAccount<TNonceAuthorityAddress>,
]
> &
IInstructionWithData<AdvanceNonceAccountInstructionData>;
InstructionWithData<AdvanceNonceAccountInstructionData>;
```

## Functions
Expand Down
34 changes: 17 additions & 17 deletions packages/instructions/src/__tests__/instruction-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
assertIsInstructionForProgram,
assertIsInstructionWithAccounts,
assertIsInstructionWithData,
IInstruction,
Instruction,
isInstructionForProgram,
isInstructionWithAccounts,
isInstructionWithData,
Expand All @@ -16,14 +16,14 @@ const programAddress = 'address' as Address;

describe('isInstructionForProgram', () => {
it('returns true when the instruction has the given program address', () => {
const instruction: IInstruction = {
const instruction: Instruction = {
programAddress,
};
expect(isInstructionForProgram(instruction, programAddress)).toBe(true);
});

it('returns false when the instruction does not have the given program address', () => {
const instruction: IInstruction = {
const instruction: Instruction = {
programAddress,
};
const address = 'abc' as Address;
Expand All @@ -33,15 +33,15 @@ describe('isInstructionForProgram', () => {

describe('assertIsInstructionForProgram', () => {
it('does not throw when the instruction has the given program address', () => {
const instruction: IInstruction = {
const instruction: Instruction = {
programAddress,
};
const assert = () => assertIsInstructionForProgram(instruction, programAddress);
expect(assert).not.toThrow();
});

it('throws when the instruction does not have the given program address', () => {
const instruction: IInstruction = {
const instruction: Instruction = {
programAddress,
};
const address = 'abc' as Address;
Expand All @@ -52,7 +52,7 @@ describe('assertIsInstructionForProgram', () => {

describe('isInstructionWithAccounts', () => {
it('returns true when the instruction has an array of accounts', () => {
const instruction: IInstruction = {
const instruction: Instruction = {
accounts: [
{
address: 'abc' as Address,
Expand All @@ -65,15 +65,15 @@ describe('isInstructionWithAccounts', () => {
});

it('returns true when the instruction has an empty array of accounts', () => {
const instruction: IInstruction = {
const instruction: Instruction = {
accounts: [],
programAddress,
};
expect(isInstructionWithAccounts(instruction)).toBe(true);
});

it('returns false when the instruction does not have accounts defined', () => {
const instruction: IInstruction = {
const instruction: Instruction = {
programAddress,
};
expect(isInstructionWithAccounts(instruction)).toBe(false);
Expand All @@ -82,7 +82,7 @@ describe('isInstructionWithAccounts', () => {

describe('assertIsInstructionWithAccounts', () => {
it('does not throw when the instruction has an array of accounts', () => {
const instruction: IInstruction = {
const instruction: Instruction = {
accounts: [
{
address: 'abc' as Address,
Expand All @@ -96,7 +96,7 @@ describe('assertIsInstructionWithAccounts', () => {
});

it('does not throw when the instruction has an empty array of accounts', () => {
const instruction: IInstruction = {
const instruction: Instruction = {
accounts: [],
programAddress,
};
Expand All @@ -105,7 +105,7 @@ describe('assertIsInstructionWithAccounts', () => {
});

it('throws when the instruction does not have accounts defined', () => {
const instruction: IInstruction = {
const instruction: Instruction = {
programAddress,
};
const assert = () => assertIsInstructionWithAccounts(instruction);
Expand All @@ -115,23 +115,23 @@ describe('assertIsInstructionWithAccounts', () => {

describe('isInstructionWithData', () => {
it('returns true when the instruction has a non-empty data', () => {
const instruction: IInstruction = {
const instruction: Instruction = {
data: new Uint8Array([1, 2, 3, 4]),
programAddress,
};
expect(isInstructionWithData(instruction)).toBe(true);
});

it('returns true when the instruction has an empty data', () => {
const instruction: IInstruction = {
const instruction: Instruction = {
data: new Uint8Array([]),
programAddress,
};
expect(isInstructionWithData(instruction)).toBe(true);
});

it('returns false when the instruction does not have data defined', () => {
const instruction: IInstruction = {
const instruction: Instruction = {
programAddress,
};
expect(isInstructionWithData(instruction)).toBe(false);
Expand All @@ -140,7 +140,7 @@ describe('isInstructionWithData', () => {

describe('assertIsInstructionWithData', () => {
it('does not throw when the instruction has a non-empty data', () => {
const instruction: IInstruction = {
const instruction: Instruction = {
data: new Uint8Array([1, 2, 3, 4]),
programAddress,
};
Expand All @@ -149,7 +149,7 @@ describe('assertIsInstructionWithData', () => {
});

it('does not throw when the instruction has an empty data', () => {
const instruction: IInstruction = {
const instruction: Instruction = {
data: new Uint8Array([]),
programAddress,
};
Expand All @@ -158,7 +158,7 @@ describe('assertIsInstructionWithData', () => {
});

it('throws when the instruction does not have data defined', () => {
const instruction: IInstruction = {
const instruction: Instruction = {
programAddress,
};
const assert = () => assertIsInstructionWithData(instruction);
Expand Down
Loading
0