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