Skip to content

Commit

Permalink
Support both account layout and start extension instructions (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorisleiva authored Sep 13, 2024
1 parent d58a00d commit 5cc850a
Show file tree
Hide file tree
Showing 51 changed files with 1,594 additions and 507 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ runs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
cache: 'pnpm'

- name: Install Dependencies
Expand Down
8 changes: 2 additions & 6 deletions clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@
},
"license": "Apache-2.0",
"peerDependencies": {
"@solana/web3.js": "2.0.0-rc.0"
"@solana/web3.js": "2.0.0-rc.1"
},
"devDependencies": {
"@ava/typescript": "^4.1.0",
"@solana-program/system": "^0.4.1",
"@solana/eslint-config-solana": "^3.0.3",
"@solana/web3.js": "2.0.0-rc.0",
"@solana/webcrypto-ed25519-polyfill": "2.0.0-rc.0",
"@solana/web3.js": "2.0.0-rc.1",
"@types/node": "^20",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@typescript-eslint/parser": "^7.16.1",
Expand All @@ -58,9 +57,6 @@
"nodeArguments": [
"--no-warnings"
],
"require": [
"@solana/webcrypto-ed25519-polyfill"
],
"typescript": {
"compile": false,
"rewritePaths": {
Expand Down
531 changes: 262 additions & 269 deletions clients/js/pnpm-lock.yaml

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions clients/js/src/generated/accounts/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export type Mint = {
/** Optional authority to freeze token accounts. */
freezeAuthority: Option<Address>;
/** The extensions activated on the mint account. */
extensions: Array<Extension>;
extensions: Option<Array<Extension>>;
};

export type MintArgs = {
Expand All @@ -89,7 +89,7 @@ export type MintArgs = {
/** Optional authority to freeze token accounts. */
freezeAuthority: OptionOrNullable<Address>;
/** The extensions activated on the mint account. */
extensions: Array<ExtensionArgs>;
extensions: OptionOrNullable<Array<ExtensionArgs>>;
};

export function getMintEncoder(): Encoder<MintArgs> {
Expand All @@ -113,9 +113,12 @@ export function getMintEncoder(): Encoder<MintArgs> {
],
[
'extensions',
getHiddenPrefixEncoder(
getArrayEncoder(getExtensionEncoder(), { size: 'remainder' }),
[getConstantEncoder(padLeftEncoder(getU8Encoder(), 83).encode(1))]
getOptionEncoder(
getHiddenPrefixEncoder(
getArrayEncoder(getExtensionEncoder(), { size: 'remainder' }),
[getConstantEncoder(padLeftEncoder(getU8Encoder(), 83).encode(1))]
),
{ prefix: null }
),
],
]);
Expand All @@ -142,9 +145,12 @@ export function getMintDecoder(): Decoder<Mint> {
],
[
'extensions',
getHiddenPrefixDecoder(
getArrayDecoder(getExtensionDecoder(), { size: 'remainder' }),
[getConstantDecoder(padLeftEncoder(getU8Encoder(), 83).encode(1))]
getOptionDecoder(
getHiddenPrefixDecoder(
getArrayDecoder(getExtensionDecoder(), { size: 'remainder' }),
[getConstantDecoder(padLeftEncoder(getU8Encoder(), 83).encode(1))]
),
{ prefix: null }
),
],
]);
Expand Down
22 changes: 14 additions & 8 deletions clients/js/src/generated/accounts/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export type Token = {
/** Optional authority to close the account. */
closeAuthority: Option<Address>;
/** The extensions activated on the token account. */
extensions: Array<Extension>;
extensions: Option<Array<Extension>>;
};

export type TokenArgs = {
Expand Down Expand Up @@ -109,7 +109,7 @@ export type TokenArgs = {
/** Optional authority to close the account. */
closeAuthority: OptionOrNullable<Address>;
/** The extensions activated on the token account. */
extensions: Array<ExtensionArgs>;
extensions: OptionOrNullable<Array<ExtensionArgs>>;
};

export function getTokenEncoder(): Encoder<TokenArgs> {
Expand Down Expand Up @@ -142,9 +142,12 @@ export function getTokenEncoder(): Encoder<TokenArgs> {
],
[
'extensions',
getHiddenPrefixEncoder(
getArrayEncoder(getExtensionEncoder(), { size: 'remainder' }),
[getConstantEncoder(getU8Encoder().encode(2))]
getOptionEncoder(
getHiddenPrefixEncoder(
getArrayEncoder(getExtensionEncoder(), { size: 'remainder' }),
[getConstantEncoder(getU8Encoder().encode(2))]
),
{ prefix: null }
),
],
]);
Expand Down Expand Up @@ -180,9 +183,12 @@ export function getTokenDecoder(): Decoder<Token> {
],
[
'extensions',
getHiddenPrefixDecoder(
getArrayDecoder(getExtensionDecoder(), { size: 'remainder' }),
[getConstantDecoder(getU8Encoder().encode(2))]
getOptionDecoder(
getHiddenPrefixDecoder(
getArrayDecoder(getExtensionDecoder(), { size: 'remainder' }),
[getConstantDecoder(getU8Encoder().encode(2))]
),
{ prefix: null }
),
],
]);
Expand Down
8 changes: 7 additions & 1 deletion clients/js/src/generated/instructions/amountToUiAmount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ import {
import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const AMOUNT_TO_UI_AMOUNT_DISCRIMINATOR = 23;

export function getAmountToUiAmountDiscriminatorBytes() {
return getU8Encoder().encode(AMOUNT_TO_UI_AMOUNT_DISCRIMINATOR);
}

export type AmountToUiAmountInstruction<
TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS,
TAccountMint extends string | IAccountMeta<string> = string,
Expand Down Expand Up @@ -60,7 +66,7 @@ export function getAmountToUiAmountInstructionDataEncoder(): Encoder<AmountToUiA
['discriminator', getU8Encoder()],
['amount', getU64Encoder()],
]),
(value) => ({ ...value, discriminator: 23 })
(value) => ({ ...value, discriminator: AMOUNT_TO_UI_AMOUNT_DISCRIMINATOR })
);
}

Expand Down
8 changes: 7 additions & 1 deletion clients/js/src/generated/instructions/approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ import {
import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const APPROVE_DISCRIMINATOR = 4;

export function getApproveDiscriminatorBytes() {
return getU8Encoder().encode(APPROVE_DISCRIMINATOR);
}

export type ApproveInstruction<
TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS,
TAccountSource extends string | IAccountMeta<string> = string,
Expand Down Expand Up @@ -73,7 +79,7 @@ export function getApproveInstructionDataEncoder(): Encoder<ApproveInstructionDa
['discriminator', getU8Encoder()],
['amount', getU64Encoder()],
]),
(value) => ({ ...value, discriminator: 4 })
(value) => ({ ...value, discriminator: APPROVE_DISCRIMINATOR })
);
}

Expand Down
8 changes: 7 additions & 1 deletion clients/js/src/generated/instructions/approveChecked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ import {
import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const APPROVE_CHECKED_DISCRIMINATOR = 13;

export function getApproveCheckedDiscriminatorBytes() {
return getU8Encoder().encode(APPROVE_CHECKED_DISCRIMINATOR);
}

export type ApproveCheckedInstruction<
TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS,
TAccountSource extends string | IAccountMeta<string> = string,
Expand Down Expand Up @@ -82,7 +88,7 @@ export function getApproveCheckedInstructionDataEncoder(): Encoder<ApproveChecke
['amount', getU64Encoder()],
['decimals', getU8Encoder()],
]),
(value) => ({ ...value, discriminator: 13 })
(value) => ({ ...value, discriminator: APPROVE_CHECKED_DISCRIMINATOR })
);
}

Expand Down
8 changes: 7 additions & 1 deletion clients/js/src/generated/instructions/burn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ import {
import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const BURN_DISCRIMINATOR = 8;

export function getBurnDiscriminatorBytes() {
return getU8Encoder().encode(BURN_DISCRIMINATOR);
}

export type BurnInstruction<
TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS,
TAccountAccount extends string | IAccountMeta<string> = string,
Expand Down Expand Up @@ -70,7 +76,7 @@ export function getBurnInstructionDataEncoder(): Encoder<BurnInstructionDataArgs
['discriminator', getU8Encoder()],
['amount', getU64Encoder()],
]),
(value) => ({ ...value, discriminator: 8 })
(value) => ({ ...value, discriminator: BURN_DISCRIMINATOR })
);
}

Expand Down
8 changes: 7 additions & 1 deletion clients/js/src/generated/instructions/burnChecked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ import {
import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const BURN_CHECKED_DISCRIMINATOR = 15;

export function getBurnCheckedDiscriminatorBytes() {
return getU8Encoder().encode(BURN_CHECKED_DISCRIMINATOR);
}

export type BurnCheckedInstruction<
TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS,
TAccountAccount extends string | IAccountMeta<string> = string,
Expand Down Expand Up @@ -78,7 +84,7 @@ export function getBurnCheckedInstructionDataEncoder(): Encoder<BurnCheckedInstr
['amount', getU64Encoder()],
['decimals', getU8Encoder()],
]),
(value) => ({ ...value, discriminator: 15 })
(value) => ({ ...value, discriminator: BURN_CHECKED_DISCRIMINATOR })
);
}

Expand Down
8 changes: 7 additions & 1 deletion clients/js/src/generated/instructions/closeAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ import {
import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const CLOSE_ACCOUNT_DISCRIMINATOR = 9;

export function getCloseAccountDiscriminatorBytes() {
return getU8Encoder().encode(CLOSE_ACCOUNT_DISCRIMINATOR);
}

export type CloseAccountInstruction<
TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS,
TAccountAccount extends string | IAccountMeta<string> = string,
Expand Down Expand Up @@ -61,7 +67,7 @@ export type CloseAccountInstructionDataArgs = {};
export function getCloseAccountInstructionDataEncoder(): Encoder<CloseAccountInstructionDataArgs> {
return transformEncoder(
getStructEncoder([['discriminator', getU8Encoder()]]),
(value) => ({ ...value, discriminator: 9 })
(value) => ({ ...value, discriminator: CLOSE_ACCOUNT_DISCRIMINATOR })
);
}

Expand Down
17 changes: 13 additions & 4 deletions clients/js/src/generated/instructions/createAssociatedToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ import {
type ResolvedAccount,
} from '../shared';

export const CREATE_ASSOCIATED_TOKEN_DISCRIMINATOR = 0;

export function getCreateAssociatedTokenDiscriminatorBytes() {
return getU8Encoder().encode(CREATE_ASSOCIATED_TOKEN_DISCRIMINATOR);
}

export type CreateAssociatedTokenInstruction<
TProgram extends string = typeof ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
TAccountPayer extends string | IAccountMeta<string> = string,
Expand All @@ -46,7 +52,7 @@ export type CreateAssociatedTokenInstruction<
| IAccountMeta<string> = '11111111111111111111111111111111',
TAccountTokenProgram extends
| string
| IAccountMeta<string> = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
| IAccountMeta<string> = 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
Expand Down Expand Up @@ -80,7 +86,10 @@ export type CreateAssociatedTokenInstructionDataArgs = {};
export function getCreateAssociatedTokenInstructionDataEncoder(): Encoder<CreateAssociatedTokenInstructionDataArgs> {
return transformEncoder(
getStructEncoder([['discriminator', getU8Encoder()]]),
(value) => ({ ...value, discriminator: 0 })
(value) => ({
...value,
discriminator: CREATE_ASSOCIATED_TOKEN_DISCRIMINATOR,
})
);
}

Expand Down Expand Up @@ -167,7 +176,7 @@ export async function getCreateAssociatedTokenInstructionAsync<
// Resolve default values.
if (!accounts.tokenProgram.value) {
accounts.tokenProgram.value =
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>;
'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb' as Address<'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb'>;
}
if (!accounts.ata.value) {
accounts.ata.value = await findAssociatedTokenPda({
Expand Down Expand Up @@ -273,7 +282,7 @@ export function getCreateAssociatedTokenInstruction<
// Resolve default values.
if (!accounts.tokenProgram.value) {
accounts.tokenProgram.value =
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>;
'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb' as Address<'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb'>;
}
if (!accounts.systemProgram.value) {
accounts.systemProgram.value =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ import {
type ResolvedAccount,
} from '../shared';

export const CREATE_ASSOCIATED_TOKEN_IDEMPOTENT_DISCRIMINATOR = 1;

export function getCreateAssociatedTokenIdempotentDiscriminatorBytes() {
return getU8Encoder().encode(
CREATE_ASSOCIATED_TOKEN_IDEMPOTENT_DISCRIMINATOR
);
}

export type CreateAssociatedTokenIdempotentInstruction<
TProgram extends string = typeof ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
TAccountPayer extends string | IAccountMeta<string> = string,
Expand All @@ -46,7 +54,7 @@ export type CreateAssociatedTokenIdempotentInstruction<
| IAccountMeta<string> = '11111111111111111111111111111111',
TAccountTokenProgram extends
| string
| IAccountMeta<string> = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
| IAccountMeta<string> = 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
Expand Down Expand Up @@ -82,7 +90,10 @@ export type CreateAssociatedTokenIdempotentInstructionDataArgs = {};
export function getCreateAssociatedTokenIdempotentInstructionDataEncoder(): Encoder<CreateAssociatedTokenIdempotentInstructionDataArgs> {
return transformEncoder(
getStructEncoder([['discriminator', getU8Encoder()]]),
(value) => ({ ...value, discriminator: 1 })
(value) => ({
...value,
discriminator: CREATE_ASSOCIATED_TOKEN_IDEMPOTENT_DISCRIMINATOR,
})
);
}

Expand Down Expand Up @@ -169,7 +180,7 @@ export async function getCreateAssociatedTokenIdempotentInstructionAsync<
// Resolve default values.
if (!accounts.tokenProgram.value) {
accounts.tokenProgram.value =
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>;
'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb' as Address<'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb'>;
}
if (!accounts.ata.value) {
accounts.ata.value = await findAssociatedTokenPda({
Expand Down Expand Up @@ -275,7 +286,7 @@ export function getCreateAssociatedTokenIdempotentInstruction<
// Resolve default values.
if (!accounts.tokenProgram.value) {
accounts.tokenProgram.value =
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>;
'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb' as Address<'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb'>;
}
if (!accounts.systemProgram.value) {
accounts.systemProgram.value =
Expand Down
8 changes: 7 additions & 1 deletion clients/js/src/generated/instructions/freezeAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ import {
import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const FREEZE_ACCOUNT_DISCRIMINATOR = 10;

export function getFreezeAccountDiscriminatorBytes() {
return getU8Encoder().encode(FREEZE_ACCOUNT_DISCRIMINATOR);
}

export type FreezeAccountInstruction<
TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS,
TAccountAccount extends string | IAccountMeta<string> = string,
Expand Down Expand Up @@ -61,7 +67,7 @@ export type FreezeAccountInstructionDataArgs = {};
export function getFreezeAccountInstructionDataEncoder(): Encoder<FreezeAccountInstructionDataArgs> {
return transformEncoder(
getStructEncoder([['discriminator', getU8Encoder()]]),
(value) => ({ ...value, discriminator: 10 })
(value) => ({ ...value, discriminator: FREEZE_ACCOUNT_DISCRIMINATOR })
);
}

Expand Down
Loading

0 comments on commit 5cc850a

Please sign in to comment.