Payxn Anchor is a Solana program built using the Anchor framework (version 0.30.1) that facilitates USDC payments between customers and business owners while deducting an admin fee.
This program allows customers to make USDC payments to business owners. During the transaction, a small admin fee is deducted and sent to an admin account.
- Rust 1.70.0 or later
- Solana CLI 1.16.0 or later
- Anchor CLI 0.30.1
- Node.js 14.0.0 or later
- Yarn 1.22.0 or later
-
Clone the repository:
git clone https://github.com/your-username/payxn-anchor.git cd payxn-anchor
-
Install dependencies:
yarn install OR npm install
-
Build the program:
anchor build
The program consists of two main parts:
- Rust program (
programs/payxn-anchor/src/lib.rs
): This contains the core logic for processing payments. - TypeScript tests (
tests/payxn-anchor.ts
): These tests verify the program's functionality.
The main function in the Rust program is process_payment
, which:
- Calculates the admin fee based on the payment amount and fee percentage params.
- Transfers the fee to the admin account.
- Transfers the remaining amount to the business owner's account.
The ProcessPayment
struct defines the accounts required for the payment transaction:
customer
: The account initiating the payment (signer).customer_usdc
: The customer's USDC token account.business_owner_usdc
: The business owner's USDC token account.admin_usdc
: The admin's USDC token account for receiving fees.token_program
: The SPL Token program.
To use this program:
- Deploy the program to a Solana cluster (devnet, testnet, or mainnet).
- Initialize the necessary token accounts (customer, business owner, and admin).
- Call the
process_payment
instruction with the required accounts and parameters.
The test file (tests/payxn-anchor.ts
) sets up a simulated environment and tests the payment process. It:
- Creates a USDC mint.
- Sets up token accounts for the customer, business owner, and admin.
- Mints USDC to the customer's account.
- Executes the payment process.
- Verifies the resulting balances.
To run the tests:
anchor test