Constructed a smart contract enabling automatic subscription renewals at regular intervals, demonstrating a real-world application for recurring payments. This smart contract is designed as a self-custodial wallet capable of autonomously extracting funds in predefined intervals. Unlike traditional methods, users are not obligated to actively engage each time to initiate and push payments on the blockchain. The contract streamlines the process, offering a hands-free approach to managing recurring payments.
Defines functions for interacting with ERC20 tokens (e.g., allowance, transfer, transferFrom).
ERC20 tokens are built on top of the Ethereum blockchain. They leverage its features like security, decentralization, and smart contract execution. So, in that sense, ERC20 tokens inherently rely on Ethereum and wouldn't exist without it.
Manages subscriptions, payments, and related data.
Subscription Struct: Stores details about a subscription (customer, payee, allowance, token address, name, description, last execution date, subscription period, active status).
SubscriptionReceipt Struct: Stores subscription details for receipts (customer, payee, allowance, token address, name, description, creation date, role).
- Creates a new subscription and executes initial payment.
- Allows a customer to establish a new subscription.
- Checks for existing active subscriptions, sufficient token balance, and a positive subscription period.
- Calculates the actual subscription period based on the specified frequency.
- Creates subscription records and emits relevant events.
- Transfers tokens from the customer to the payee for the initial subscription payment.
- Allows either the customer or payee to cancel an active subscription.
- Initiates payment for a subscription by the payee.
- Allows the payee to execute a subscription payment.
- Checks if the payee has the authority, the subscription is active, and the payment for the period hasn't been executed yet.
- Updates the last execution date and transfers tokens from the customer to the payee.
- Checks whether a subscription has been paid for the current period.
- Retrieves subscription details for a given customer and payee.
- Returns a customer's subscription receipts.
- Calculates time until a subscription's next payment.
- Internal function to check if a subscription has been paid for the current period.