From 211fde6f95b354206f66f5136ffc70ff7f6fff45 Mon Sep 17 00:00:00 2001 From: Hrushikesh Date: Fri, 10 May 2024 00:13:00 +0530 Subject: [PATCH] Extension Account: confidentialTransferAccount (#2699) --- .../rpc-graphql/src/__tests__/account-test.ts | 56 +++++++++++++++++++ packages/rpc-graphql/src/resolvers/account.ts | 3 + packages/rpc-graphql/src/schema/account.ts | 19 +++++++ 3 files changed, 78 insertions(+) diff --git a/packages/rpc-graphql/src/__tests__/account-test.ts b/packages/rpc-graphql/src/__tests__/account-test.ts index c2b19bd85ba1..1719dc2ba569 100644 --- a/packages/rpc-graphql/src/__tests__/account-test.ts +++ b/packages/rpc-graphql/src/__tests__/account-test.ts @@ -1293,6 +1293,8 @@ describe('account', () => { const megaMintAddress = '5gSwsLGzyCwgwPJSnxjsQCaFeE19ZFaibHMLky9TDFim'; // See scripts/fixtures/spl-token-22-mint-mega-token-member.json const megaMemberAddress = 'CXZDzjSrQ5jPaBgk6ckTQrLPTnUURiY2GnAgVCS9Fggz'; + // See scripts/fixtures/spl-token-22-account-mega-token-member.json + const megaAccountAddress = 'aUg6iJ3p43hTJsxHrQ1KfqMQYStoFvqcSJRcc51cYzK'; it('mint-close-authority', async () => { expect.assertions(1); const source = /* GraphQL */ ` @@ -1903,6 +1905,60 @@ describe('account', () => { }, }); }); + + it('confidential-transfer-account', async () => { + expect.assertions(1); + const source = /* GraphQL */ ` + query testQuery($address: Address!) { + account(address: $address) { + ... on TokenAccount { + extensions { + ... on SplTokenExtensionConfidentialTransferAccount { + actualPendingBalanceCreditCounter + allowConfidentialCredits + allowNonConfidentialCredits + approved + availableBalance + decryptableAvailableBalance + elgamalPubkey + expectedPendingBalanceCreditCounter + maximumPendingBalanceCreditCounter + pendingBalanceCreditCounter + pendingBalanceHi + pendingBalanceLo + extension + } + } + } + } + } + `; + + const result = await rpcGraphQL.query(source, { address: megaAccountAddress }); + expect(result).toMatchObject({ + data: { + account: { + extensions: expect.arrayContaining([ + { + actualPendingBalanceCreditCounter: null, + allowConfidentialCredits: expect.any(Boolean), + allowNonConfidentialCredits: expect.any(Boolean), + approved: expect.any(Boolean), + availableBalance: expect.any(String), + decryptableAvailableBalance: expect.any(String), + elgamalPubkey: expect.any(String), + expectedPendingBalanceCreditCounter: null, + extension: 'confidentialTransferAccount', + maximumPendingBalanceCreditCounter: null, + pendingBalanceCreditCounter: null, + pendingBalanceHi: expect.any(String), + pendingBalanceLo: expect.any(String), + }, + ]), + }, + }, + }); + }); }); }); }); diff --git a/packages/rpc-graphql/src/resolvers/account.ts b/packages/rpc-graphql/src/resolvers/account.ts index a1cb06c11fee..da3ab0bf7875 100644 --- a/packages/rpc-graphql/src/resolvers/account.ts +++ b/packages/rpc-graphql/src/resolvers/account.ts @@ -267,6 +267,9 @@ function resolveTokenExtensionType(extensionResult: Token2022ExtensionResult) { if (extensionResult.extension === 'transferHook') { return 'SplTokenExtensionTransferHook'; } + if (extensionResult.extension === 'confidentialTransferAccount') { + return 'SplTokenExtensionConfidentialTransferAccount'; + } } export const accountResolvers = { diff --git a/packages/rpc-graphql/src/schema/account.ts b/packages/rpc-graphql/src/schema/account.ts index e2b6ac05dfb6..27146568ba4c 100644 --- a/packages/rpc-graphql/src/schema/account.ts +++ b/packages/rpc-graphql/src/schema/account.ts @@ -161,6 +161,25 @@ export const accountTypeDefs = /* GraphQL */ ` hookProgramId: Account } + """ + Token-2022 Extension: ConfidentialTransferAccount + """ + type SplTokenExtensionConfidentialTransferAccount implements SplTokenExtension { + extension: String + actualPendingBalanceCreditCounter: Int + allowConfidentialCredits: Boolean + allowNonConfidentialCredits: Boolean + approved: Boolean + availableBalance: String + decryptableAvailableBalance: String + elgamalPubkey: String + expectedPendingBalanceCreditCounter: Int + maximumPendingBalanceCreditCounter: Int + pendingBalanceCreditCounter: Int + pendingBalanceHi: String + pendingBalanceLo: String + } + """ Account interface """