Skip to content

Commit

Permalink
refactor(experimental): graphql: token-2022 extensions: reallocate (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Jun 14, 2024
1 parent ad5e9e2 commit 1c3a24a
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 1 deletion.
35 changes: 34 additions & 1 deletion packages/rpc-graphql/src/__tests__/__setup__.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2713,7 +2713,40 @@ export const mockTransactionToken2022AllExtensions = {
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
// TODO (more) ...
{
parsed: {
info: {
account: '6muXBR8kTs1UEbATDkFzEf61HPeEHrCvdBNciVoxic8d',
extensionTypes: ['transferFeeAmount', 'memoTransfer'],
owner: '2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
payer: '2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
systemProgram: '11111111111111111111111111111111',
},
type: 'reallocate',
},
program: 'spl-token',
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
{
parsed: {
info: {
account: '6muXBR8kTs1UEbATDkFzEf61HPeEHrCvdBNciVoxic8d',
extensionTypes: ['transferFeeAmount', 'memoTransfer'],
payer: '2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
systemProgram: '11111111111111111111111111111111',
signers: [
'2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
'2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
],
multisigOwner: 'Sysvar1nstructions1111111111111111111111111',
},
type: 'reallocate',
},
program: 'spl-token',
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
],
recentBlockhash: '6vRS7MoToVccMqfQecdVC6UbmARaT5mha91zhreqnce9',
},
Expand Down
81 changes: 81 additions & 0 deletions packages/rpc-graphql/src/__tests__/transaction-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3791,6 +3791,87 @@ describe('transaction', () => {
},
});
});

it('reallocate', async () => {
expect.assertions(1);
const source = /* GraphQL */ `
query testQuery($signature: Signature!) {
transaction(signature: $signature) {
message {
instructions {
programId
... on SplTokenReallocate {
account {
address
}
extensionTypes
owner {
address
}
payer {
address
}
systemProgram {
address
}
multisigOwner {
address
}
signers
}
}
}
}
}
`;
const result = await rpcGraphQL.query(source, { signature });
expect(result).toMatchObject({
data: {
transaction: {
message: {
instructions: expect.arrayContaining([
{
account: {
address: expect.any(String),
},
extensionTypes: expect.arrayContaining([expect.any(String)]),
multisigOwner: null,
owner: {
address: expect.any(String),
},
payer: {
address: expect.any(String),
},
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
signers: null,
systemProgram: {
address: expect.any(String),
},
},
{
account: {
address: expect.any(String),
},
extensionTypes: expect.arrayContaining([expect.any(String)]),
multisigOwner: {
address: expect.any(String),
},
owner: null,
payer: {
address: expect.any(String),
},
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
signers: expect.arrayContaining([expect.any(String)]),
systemProgram: {
address: expect.any(String),
},
},
]),
},
},
},
});
});
});
});
});
14 changes: 14 additions & 0 deletions packages/rpc-graphql/src/schema/type-defs/instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,20 @@ export const instructionTypeDefs = /* GraphQL */ `
withheldAmount: String
}
"""
SplToken-2022: Reallocate instruction
"""
type SplTokenReallocate implements TransactionInstruction {
programId: Address
account: Account
extensionTypes: [SplTokenExtensionType]
owner: Account
multisigOwner: Account
payer: Account
signers: [Address]
systemProgram: Account
}
"""
Spl Token Group: InitializeGroup instruction
"""
Expand Down
28 changes: 28 additions & 0 deletions packages/rpc-graphql/src/schema/type-defs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,34 @@ export const typeTypeDefs = /* GraphQL */ `
UNINITIALIZED
}
enum SplTokenExtensionType {
UNINITIALIZED
TRANSFER_FEE_CONFIG
TRANSFER_FEE_AMOUNT
MINT_CLOSE_AUTHORITY
CONFIDENTIAL_TRANSFER_MINT
CONFIDENTIAL_TRANSFER_ACCOUNT
DEFAULT_ACCOUNT_STATE
IMMUTABLE_OWNER
MEMO_TRANSFER
NON_TRANSFERABLE
INTEREST_BEARING_CONFIG
CPI_GUARD
PERMANENT_DELEGATE
NON_TRANSFERABLE_ACCOUNT
CONFIDENTIAL_TRANSFER_FEE_CONFIG
CONFIDENTIAL_TRANSFER_FEE_AMOUNT
TRANSFER_HOOK
TRANSFER_HOOK_ACCOUNT
METADATA_POINTER
TOKEN_METADATA
GROUP_POINTER
GROUP_MEMBER_POINTER
TOKEN_GROUP
TOKEN_GROUP_MEMBER
UNPARSEABLE_EXTENSION
}
type TokenAmount {
amount: BigInt
decimals: Int
Expand Down
10 changes: 10 additions & 0 deletions packages/rpc-graphql/src/schema/type-resolvers/instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,13 @@ export const instructionTypeResolvers = {
mintAuthority: resolveAccount('mintAuthority'),
multisigMintAuthority: resolveAccount('multisigMintAuthority'),
},
SplTokenReallocate: {
account: resolveAccount('account'),
multisigOwner: resolveAccount('multisigOwner'),
owner: resolveAccount('owner'),
payer: resolveAccount('payer'),
systemProgram: resolveAccount('systemProgram'),
},
SplTokenRevokeInstruction: {
multisigOwner: resolveAccount('multisigOwner'),
owner: resolveAccount('owner'),
Expand Down Expand Up @@ -953,6 +960,9 @@ export const instructionTypeResolvers = {
if (jsonParsedConfigs.instructionType === 'emitTokenMetadata') {
return 'SplTokenMetadataEmit';
}
if (jsonParsedConfigs?.instructionType === 'reallocate') {
return 'SplTokenReallocate';
}
}
if (jsonParsedConfigs.programName === 'stake') {
if (jsonParsedConfigs.instructionType === 'initialize') {
Expand Down
27 changes: 27 additions & 0 deletions packages/rpc-graphql/src/schema/type-resolvers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,33 @@ export const typeTypeResolvers = {
INITIALIZED: 'initialized',
UNINITIALIZED: 'uninitialized',
},
SplTokenExtensionType: {
CONFIDENTIAL_TRANSFER_ACCOUNT: 'confidentialTransferAccount',
CONFIDENTIAL_TRANSFER_FEE_AMOUNT: 'confidentialTransferFeeAmount',
CONFIDENTIAL_TRANSFER_FEE_CONFIG: 'confidentialTransferFeeConfig',
CONFIDENTIAL_TRANSFER_MINT: 'confidentialTransferMint',
CPI_GUARD: 'cpiGuard',
DEFAULT_ACCOUNT_STATE: 'defaultAccountState',
GROUP_MEMBER_POINTER: 'groupMemberPointer',
GROUP_POINTER: 'groupPointer',
IMMUTABLE_OWNER: 'immutableOwner',
INTEREST_BEARING_CONFIG: 'interestBearingConfig',
MEMO_TRANSFER: 'memoTransfer',
METADATA_POINTER: 'metadataPointer',
MINT_CLOSE_AUTHORITY: 'mintCloseAuthority',
NON_TRANSFERABLE: 'nonTransferable',
NON_TRANSFERABLE_ACCOUNT: 'nonTransferableAccount',
PERMANENT_DELEGATE: 'permanentDelegate',
TOKEN_GROUP: 'tokenGroup',
TOKEN_GROUP_MEMBER: 'tokenGroupMember',
TOKEN_METADATA: 'tokenMetadata',
TRANSFER_FEE_AMOUNT: 'transferFeeAmount',
TRANSFER_FEE_CONFIG: 'transferFeeConfig',
TRANSFER_HOOK: 'transferHook',
TRANSFER_HOOK_ACCOUNT: 'transferHookAccount',
UNINITIALIZED: 'uninitialized',
UNPARSEABLE_EXTENSION: 'unparseableExtension',
},
TokenBalance: {
mint: resolveAccount('mint'),
owner: resolveAccount('owner'),
Expand Down

0 comments on commit 1c3a24a

Please sign in to comment.