Skip to content

Implement Place Order Function with Validation and Storage #6

@onlydustapp

Description

@onlydustapp

📚 Overview

Implement the place_order() function to handle order creation, validation, and storage within the SwapTrade Contract. This function should generate a unique order ID, validate the token addresses and amounts, and store the order in the orderbook.

🛠️ Key Requirements

  • Create an Order struct that includes at least the following fields:

    • Unique Order ID (using uuid library or equivalent unique ID generation logic)
    • token_in, token_out, amount_in, min_amount_out
    • Additional fields as necessary
  • Implement the place_order() function that:

    1. Accepts token_in, token_out, amount_in, and min_amount_out as inputs
    2. Generates a unique order ID for every new order
    3. Validates the provided amounts and token addresses
    4. Stores the order within the orderbook storage
  • Write at least 3 unit tests to cover the following scenarios:

    1. Successful order creation with valid inputs
    2. Handling of invalid token addresses
    3. Insufficient or invalid amounts

🔍 Technical Considerations

  • Utilize the uuid library for generating unique IDs or implement an equivalent logic.
  • Ensure that error handling is robust, particularly for invalid input cases.
  • Follow the current project's smart contract and testing guidelines as referenced in the README.

✅ Acceptance Criteria

  • The Order struct is defined with the necessary fields.
  • The place_order() function generates a unique order ID and validates inputs correctly.
  • The new order is added to the orderbook storage as expected.
  • 3+ unit tests are provided to verify functionality and edge cases.

Let's ensure the implementation adheres to the project's guidelines and best practices. 🚀

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions