Skip to content

Add Cross-Contract Transfer-Out Call in withdraw_to_replace Before Deleting Custody Record #308

@Oluwaseyi89

Description

@Oluwaseyi89

Summary

Update the buffer_pool contract so that the withdraw_to_replace function performs a cross-contract transfer-out call to the relevant asset contract before deleting the custody record, ensuring atomicity and traceability of asset movement.

Social Media Link

Let's collaborate on Discord. And ensure to star our repo.

Technical Context

  • Motivation: Currently, custody records may be deleted before the actual asset transfer is confirmed, risking asset loss or inconsistent state. Performing the transfer-out as a cross-contract call before deletion ensures that assets are safely moved and the custody record is only removed upon successful transfer.
  • Current State: The withdraw_to_replace function deletes the custody record without first performing a cross-contract transfer-out, which can lead to state inconsistencies or asset loss if the transfer fails.

Requirements

Contract Changes

  • Refactor withdraw_to_replace to:
    • Initiate a cross-contract transfer-out call to the asset contract for the specified token/amount.
    • Only delete the custody record after the transfer-out call returns success.
  • Ensure error handling is robust: if the transfer fails, the custody record must remain intact and no state is lost.
  • Emit events for both the transfer-out action and the custody record deletion for off-chain traceability.

Acceptance Criteria

  • Custody records are only deleted after a successful cross-contract transfer-out.
  • All error paths leave custody records intact.
  • Events are emitted for transfer-out and deletion.
  • Unit tests cover:
    • Successful transfer-out and custody deletion
    • Failed transfer-out with custody record retention
    • Event emission and off-chain traceability

Definition of Done

  • PR with contract code changes and tests
  • Documentation updated to describe the new transfer-out flow
  • Team review completed

Working Directory:

stellar-core/carbon-asset-factory/contracts/buffer_pool


Metadata

Metadata

Assignees

Labels

RustThis issue is to be implemented with Rust programming language.SorobanThis issue is to be implemented with Soroban SDKStellar WaveIssues in the Stellar wave program

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions