Smart Contract Implementation details
This part of the documentation is more technical, it explains how the smart contracts work
Direct Debit
The base contract is defined as an Abstract contract that needs to be implemented by Accounts.
It provides the Interface to create directly debitable Smart Contract Accounts
/**
A function that allows direct debit with a reusable proof
N times to M address with L max amount that can be withdrawn
The proof and public inputs are the PaymentIntent
@param proof contains the zkSnark
@param hashes are [0] = paymentIntent [1] = commitment
@param payee is the account recieving the payment
@param debit[4] are [0] = max debit amount, [1] = debitTimes, [2] = debitInterval, [3] = payment amount.
Last param is not used in the circuit but it must be smaller than the max debit amount
By using a separate max debit amount and a payment amount we can create dynamic subscriptions, where the final price varies
but can't be bigger than the allowed amount!
This function can be paused by the owner to disable it!
*/
function directdebit(
uint256[8] calldata proof,
bytes32[2] calldata hashes,
address payee,
uint256[4] calldata debit
) external nonReentrant whenNotPaused {
_verifyPaymentIntent(proof, hashes, payee, debit);
_processPaymentIntent(hashes, payee, debit);
}Account contracts that allow direct debit must have this direct debit function that accepts the zkSnark proof, and parameters for it.
Cancel Payment Intent
There must be a cancelPaymentIntent function that allows nullifying a payment intent by the related parties. (Customer or Merchant)
The Direct Debit contract also contains an owner fee, it's ownable and the direct debit can be paused by the owner.
The account balances must be fetched using the getAccount function as the connected wallet's balance implementation differs from virtual accounts.
Child contracts implement these hooks to modify how the direct debit transfer withdraw is implemented:
Virtual Accounts
One of the account types DebitLlama implements is Virtual Debit Accounts. They are inspired by Virtual Credit Cards. They are smart contract accounts that need to be manually topped up to contain balance and they support both native tokens ETH and ERC-20 tokens.
Deposit ETH or native tokens using this function.
The function takes the commitment and the encrypted note and the balance that is deposited must be transferred
Deposit Tokens:
Top up balance
Withdrawing balance
To withdraw the balance the Account creator EOA needs to initiate the transaction.
Connected Wallets
Connected wallet smart contract lets you directly connect an EOA. It is powered by ERC-20 allowances. The connected wallet debitable balance is the approved amount.
Disconnect wallet
Last updated
