Swaplace
  • About Swaplace
    • Manifesto
    • Overview
    • Roadmap
    • Tokenomics (🚧)
    • Start swaping with Swaplace
    • Marketplace
    • Call for contributors
      • ✧ How to start
      • ✧ Incentives
    • Community & Links
  • Developers
    • Guides
      • ✧ Overview
      • ✧ Setting up your local environment
      • ✧ Preparing
        • Encode config
        • Encode ERC1155 Asset
        • Make Swap
      • ✧ Creating
        • ERC20/ERC721
        • ERC1155
        • Native Ether
      • ✧ Accepting
      • ✧ Canceling
    • Technical Reference
      • ✧ Overview
      • ✧ Swaplace
      • ✧ SwapFactory
      • ✧ Interfaces
        • ✧ IERC165
        • ✧ IErrors
        • ✧ ISwap
        • ✧ ISwapFactory
        • ✧ ISwaplace
    • Deployments
Powered by GitBook
On this page
  • SwapCreated
  • SwapAccepted
  • SwapCanceled
  • createSwap
  • acceptSwap
  • cancelSwap
  • getSwap
  1. Developers
  2. Technical Reference
  3. ✧ Interfaces

✧ ISwaplace

Previous✧ ISwapFactoryNextDeployments

Last updated 12 months ago

Interface of the {Swaplace} implementation.

SwapCreated

event SwapCreated(uint256 swapId, address owner, address allowed)

Emitted when a new Swap is created.

SwapAccepted

event SwapAccepted(uint256 swapId, address owner, address allowed)

Emitted when a Swap is accepted.

SwapCanceled

event SwapCanceled(uint256 swapId, address owner)

Emitted when a Swap is canceled.

createSwap

function createSwap(struct ISwap.Swap Swap) external payable returns (uint256)

Requirements:

Allow users to create a Swap. Each new Swap self-increments its ID by one.

  • owner must be the caller's address.

  • expiry should be bigger than the timestamp.

  • biding and asking must not be empty.

Emits a {SwapCreated} event.

acceptSwap

function acceptSwap(uint256 swapId, address receiver) external payable returns (bool)

Accepts a Swap. Once the Swap is accepted, the expiry is set to zero to avoid reutilization.

Requirements:

  • allowed must be the zero address or match the caller's address.

  • expiry must be bigger than the timestamp.

  • biding assets must be allowed to transfer.

  • asking assets must be allowed to transfer.

Emits a {SwapAccepted} event.

NOTE

The expiry is set to 0, because if the Swap is expired it will revert, preventing reentrancy attacks.

cancelSwap

function cancelSwap(uint256 swapId) external

Cancels an active Swap by setting the expiry to zero.

Expiry with 0 seconds means that the Swap doesn't exist or is already canceled.

Requirements:

  • owner must be the caller's address.

  • expiry must be bigger than the timestamp.

Emits a {SwapCanceled} event.

getSwap

function getSwap(uint256 swapId) external view returns (struct ISwap.Swap)

Retrieves the details of a Swap based on the swapId provided.

NOTE

If the Swaps don't exist, the values will be defaulted to 0. You can check if a Swap exists by checking if the owner is a zero address. If the owner is a zero address, then the Swap doesn't exist.

Source Code