Skip to content

Implement "Withdraw to Another Account" Functionality #69

@codebestia

Description

@codebestia

Description 📝

Implement functionality to allow the merchant to withdraw funds from their account contract directly to an arbitrary external address (another account). This provides flexibility for the merchant to transfer funds without first sending them to their primary registered wallet.

Proposed Steps 📝

  • Update Events:
    • Define WithdrawalTo event in contracts/account/src/events.rs (fields: token address, amount, merchant address, recipient address, timestamp).
  • Implement Functions:
    • withdraw_to(env: Env, token: Address, amount: i128, to: Address):
      • Retrieves the stored Merchant address.
      • Requires authentication from the merchant (merchant.require_auth()).
      • Checks if the account has enough balance of the specified token.
      • Performs a transfer of the amount from the current contract to the to (recipient) address using the token client.
      • Emits the WithdrawalTo event.
  • Interface: Update MerchantAccountTrait in contracts/account/src/interface.rs to expose the withdraw_to function.
  • Main Contract: Implement the method in contracts/account/src/contract.rs.

Acceptance Criteria ✅

  • withdraw_to successfully transfers tokens to the specified recipient.
  • Only the assigned merchant can call withdraw_to. Unauthorized calls must panic.
  • The function correctly checks for sufficient balance.
  • WithdrawalTo event is emitted upon success with correct data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions