Skip to content

Automated ERC20 Allowance-Based Deposits and Batch Account Abstraction #32

@RonTuretzky

Description

@RonTuretzky

WARNING DESC TAKEN FROM SAVING CIRLCES BUT APPLIES TO BREADFUNDS

Background

BreadchainCoop's Saving Circles platform provides a collaborative mechanism for users to save together. Currently, deposits must be initiated manually, which can limit automation and scalability, especially when interacting with ERC20 tokens and allowance mechanisms.

Motivation

To streamline the deposit process and enable more flexible participation, introducing automated deposit functions leveraging ERC20 allowances would:

  • Enable programmatic deposits for users who have pre-approved the contract.
  • Reduce manual intervention and make the system more scalable for DeFi integrations and account abstraction flows.
  • Support batch operations for DAOs or automated agents to move funds for multiple accounts at once.

Problem Statement

  • There is currently no method to automatically trigger a deposit for a user into a saving circle based on their ERC20 allowance.
  • There is no view method to enumerate all accounts eligible for such automatic deposits.
  • There is no batch function for account-abstracted deposit flows to handle multiple addresses in one transaction.

Proposed Solution

1. Automated Deposit Function

Implement a function, e.g., depositIfAllowed(address circle, address user), which:

  • Checks the user's ERC20 allowance for the saving circle contract.
  • If the allowance covers the deposit amount, transfers the required tokens and records the deposit.

2. View Method for Eligible Addresses

Add a view function, e.g., getEligibleAddressesForDeposit(), which:

  • Iterates through all saving circles and participants.
  • Returns a list of addresses where the ERC20 allowance meets or exceeds the required deposit amount.

3. Batch Deposit Function

Introduce a batch function, e.g., batchDepositIfAllowed(address circle, address[] users), which:

  • Loops through the provided user addresses.
  • For each, performs the allowance check and deposit as above.

Example Code Snippet

// Example for depositIfAllowed
function depositIfAllowed(address circle, address user) external {
    uint256 requiredAmount = getDepositAmount(circle, user);
    IERC20 token = getCircleToken(circle);
    uint256 allowance = token.allowance(user, address(this));
    require(allowance >= requiredAmount, "Insufficient allowance");
    token.transferFrom(user, address(this), requiredAmount);
    _recordDeposit(circle, user, requiredAmount);
}

// Example for view method
function getEligibleAddressesForDeposit() external view returns (address[] memory) {
    // Iterate circles and users, check allowance
}

// Example for batch
function batchDepositIfAllowed(address circle, address[] calldata users) external {
    for(uint i=0; i<users.length; i++) {
        // check allowance and deposit
    }
}

Mermaid Sequence Diagram

Automated Deposit Flow

sequenceDiagram
    participant User
    participant Contract
    participant ERC20
    User --> Contract: Initiate depositIfAllowed(circle, user)
    Contract --> ERC20: allowance(user, contract)
    ERC20 --> Contract: returns allowance
    Contract --> ERC20: transferFrom(user, contract, amount)
    ERC20 --> Contract: tokens transferred
    Contract --> Contract: record deposit
Loading

Batch Deposit Flow

sequenceDiagram
    participant Operator
    participant Contract
    participant ERC20
    Operator --> Contract: batchDepositIfAllowed(circle, users[])
    loop For each user
        Contract --> ERC20: allowance(user, contract)
        ERC20 --> Contract: returns allowance
        Contract --> ERC20: transferFrom(user, contract, amount)
        ERC20 --> Contract: tokens transferred
        Contract --> Contract: record deposit
    end
Loading

This feature would enable greater automation and scalability for Saving Circles users and integrators.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions