Verify recipient's token address for solana token payments
This commit is contained in:
parent
4e34ea442a
commit
52de3df7da
@ -9,10 +9,8 @@ NEXT_PUBLIC_SOLANA_TOKEN_MINT_ADDRESS=71Jvq4Epe2FCJ7JFSF7jLXdNk1Wy4Bhqd9iL6bEFEL
|
||||
NEXT_PUBLIC_SOLANA_TOKEN_RECIPIENT_ADDRESS=FFDx3SdAEeXrp6BTmStB4BDHpctGsaasZq4FFcowRobY
|
||||
NEXT_PUBLIC_SOLANA_TOKEN_SYMBOL=GOR
|
||||
NEXT_PUBLIC_MIN_SOLANA_PAYMENT_AMOUNT=400000000 # Approx. 5 USD
|
||||
NEXT_PUBLIC_MIN
|
||||
|
||||
# UI Configuration (optional)
|
||||
NEXT_PUBLIC_DOMAIN_SUFFIX=apps.vaasl.io
|
||||
# UI Configuration
|
||||
NEXT_PUBLIC_EXAMPLE_URL=https://git.vdb.to/cerc-io/test-progressive-web-app
|
||||
|
||||
# Server-side environment variables
|
||||
@ -28,3 +26,4 @@ REGISTRY_GAS_PRICE=0.001
|
||||
|
||||
# Application Configuration
|
||||
DEPLOYER_LRN=
|
||||
NEXT_PUBLIC_DOMAIN_SUFFIX=
|
||||
|
@ -7,6 +7,7 @@ import {
|
||||
createAssociatedTokenAccountInstruction,
|
||||
ASSOCIATED_TOKEN_PROGRAM_ID
|
||||
} from '@solana/spl-token';
|
||||
|
||||
import { SolanaPaymentResult, SolanaWalletType, SolanaWalletState } from '../types';
|
||||
|
||||
assert(process.env.NEXT_PUBLIC_SOLANA_TOKEN_MINT_ADDRESS, 'SOLANA_TOKEN_MINT_ADDRESS is required');
|
||||
|
@ -69,4 +69,4 @@ export interface LaconicTransferResult {
|
||||
success: boolean;
|
||||
transactionHash?: string;
|
||||
error?: string;
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import assert from 'assert';
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { Connection } from '@solana/web3.js';
|
||||
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
||||
import { Connection, PublicKey } from '@solana/web3.js';
|
||||
import { getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
||||
|
||||
// Simplified transaction info extraction following reference implementation
|
||||
const extractTxInfo = async (connection: Connection, transactionSignature: string): Promise<{ authority: string; amount: string }> => {
|
||||
@ -87,6 +87,11 @@ export const verifyUnusedSolanaPayment = async (
|
||||
};
|
||||
}
|
||||
|
||||
const expectedTokenAccount = getAssociatedTokenAddressSync(
|
||||
new PublicKey(process.env.NEXT_PUBLIC_SOLANA_TOKEN_MINT_ADDRESS!),
|
||||
new PublicKey(process.env.NEXT_PUBLIC_SOLANA_TOKEN_RECIPIENT_ADDRESS!)
|
||||
);
|
||||
|
||||
// Verify recipient address by checking the transaction instructions
|
||||
let foundValidTransfer = false;
|
||||
|
||||
@ -94,9 +99,8 @@ export const verifyUnusedSolanaPayment = async (
|
||||
if ('parsed' in instruction && instruction.programId.equals(TOKEN_PROGRAM_ID)) {
|
||||
const parsed = instruction.parsed;
|
||||
if (parsed.type === 'transferChecked' || parsed.type === 'transfer') {
|
||||
// TODO: Check recipient address
|
||||
// Verify amount
|
||||
if (parsed.info.amount === amount ) {
|
||||
// Verify amount and recipient's associated token address
|
||||
if (parsed.info.amount === amount && parsed.info.destination === expectedTokenAccount.toBase58() ) {
|
||||
foundValidTransfer = true;
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user