Complete technical documentation for AegisPay's decentralized payment protocol and AI risk engine
Decentralized Payment & Settlement Protocol
The Settlement Ledger for Web3 Commerce - Bringing Visa-style "Auth & Capture" to Smart Contracts
aegispay-creWeb3 payments currently fail real-world commerce due to three critical limitations:
Traditional ERC20 approvals force users into a dangerous choice: either approve infinite amounts (risking complete wallet drainage if the merchant is exploited) or face constant transaction friction.
Dynamic pricing services require users to lock excessive upfront capital. Want a $15 Uber ride? Lock $100 "just in case" traffic hits. This creates terrible UX and capital inefficiency.
In standard ERC20, if an Uber ride is estimated at exactly 15 USDC, you approve() exactly 15 USDC. But if traffic hits and the ride costs 16 USDC, the transaction reverts. The merchant fails to capture funds, and the user experience breaks.
The Current Reality: Handling dynamic pricing in Web3 (like EV charging, ride-sharing, or AI agent services) forces merchants and users into suboptimal solutions that either compromise security or create friction.
AegisPay translates the proven TradFi "Auth & Capture" architecture to Web3, utilizing a secure, decentralized clearing ledger powered by AI risk management.
When you get your paycheck, you deposit it into your Bank of America checking account. You trust the bank. But when you swipe your debit card at a shady gas station, the gas station only gets authorization for the $40 of gas. They do not get access to your entire bank account.
userFreeBalances) - their secure "checking account"Key Security: This architecture isolates the user's primary capital from merchant-level exploits while enabling seamless dynamic pricing.
AegisPay uses a single, efficient contract to manage the complete payment lifecycle:
// Three-Tier Balance Separation
mapping(address => uint256) public userFreeBalances;
// User's available funds
mapping(address => mapping(address => uint256)) public authorizedHolds;
// Active merchant authorizations
mapping(address => uint256) public merchantSettledBalances;
// Captured funds ready for withdrawal
The registerMerchant function assigns risk profiles via the MerchantCategory enum:
enum MerchantCategory {
GENERIC, // Standard merchants
EV_CHARGER, // Electric vehicle charging stations
RIDE_SHARE, // Transportation services (Uber, Lyft)
RETAIL // Physical/digital goods
}
Each category enables different risk parameters and authorization limits in the AI engine.
Critical Security Feature: Both the authorize (signature verification) and _secureIncrement (dynamic pricing) functions are STRICTLY gated to the Chainlink CRE Forwarder. No one can bypass the off-chain AI Risk Engine.
function _secureIncrement(address user, address merchant, uint256 newAmount, string memory reason) internal {
// Only callable through Chainlink CRE verification
// All authorizations logged in off-chain data store
// This is the "AI Guard" for dynamic authorization increases
}
deposit(uint256 amount): Deposit USDC into user free balanceregisterMerchant(string name, MerchantCategory category): Register as a merchant with risk profileauthorize(...): Process user authorization signatures through CRE AI fraud assessment (CRE-gated)_secureIncrement(...): Dynamically increment authorization amounts via AI risk evaluation (CRE-gated)captureFunds(address user, uint256 amount): Capture authorized funds (merchant only)withdrawSettled(): Withdraw captured funds to merchant walletwithdrawFunds(uint256 amount): Withdraw available free balance to user walletaegispay-creThe smart contract layer integrates seamlessly with our off-chain Aegis CRE (Chainlink Runtime Environment) repository, which handles:
Learn More: AegisPay CRE Repository
# Clone the repository
git clone https://github.com/AegisPayments/aegispay-contracts.git
cd aegispay-contracts
# Install dependencies
forge install
# Build the contracts
forge build
# Run the test suite
forge test -vvv
Copy the environment template and configure your settings:
cp .env.example .env
Update .env with your configuration:
RPC_URL=https://sepolia.infura.io/v3/your-key
PRIVATE_KEY=0xYourPrivateKey
ETHERSCAN_API_KEY=YourEtherscanApiKey
The deployment script is located at script/deploy/AegisProtocol.s.sol.
Important: Before deploying to a different network, update the token and forwarder addresses in the deployment script:
// Current: Sepolia testnet
address usdcAddress = 0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238; // Sepolia USDC
address forwarderAddress = 0x15fC6ae953E024d975e77382eEeC56A9101f9F88; // CRE Forwarder
// For Mainnet, use:
// address usdcAddress = 0xA0b86a33E6Dd86BC78e47C65ACdd7EB7b2f3db24; // Mainnet USDC
Deploy the contract:
# Dry run
make deploy
# Live deployment
make deploy FLAGS=--broadcast
After deployment, test the full payment cycle:
make approve-deposit PROTOCOL=0xYourProtocolAddress AMOUNT=1000000 FLAGS=--broadcast
# Note: AMOUNT is in smallest units (1000000 = 1 USDC)
make register-merchant PROTOCOL=0xYourProtocolAddress MERCHANT_NAME="My Coffee Shop" MERCHANT_CATEGORY=3 FLAGS=--broadcast
# Categories: 0=GENERIC, 1=EV_CHARGER, 2=RIDE_SHARE, 3=RETAIL
After completing steps 1-2, you can test the AI-powered authorization and increment flow in the aegispay-cre repository, which simulates the entire process including signature generation, CRE evaluation, and on-chain interactions.
make capture-funds PROTOCOL=0xYourProtocolAddress USER_ADDRESS=0xUserAddress AMOUNT=500000 FLAGS=--broadcast
The captureFunds function automatically:
make withdraw-settled PROTOCOL=0xYourProtocolAddress FLAGS=--broadcast
Upon emission of Captured and FundsReleased events, CRE log triggers execute automatically, storing all events in Firestore for comprehensive end-to-end audit trails. This ensures complete transaction visibility and regulatory compliance.
โ
Security: Isolated user funds with AI-powered risk management
โ
UX: Seamless dynamic pricing without infinite approvals
โ
Capital Efficiency: No over-collateralization required
โ
Merchant Flexibility: Support for various business models
โ
Audit Trail: Complete transaction history and compliance
โ
Scalability: Single contract, optimized gas costs
git checkout -b feature/my-feature)git commit -m 'Add my feature')git push origin feature/my-feature)