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
  • makeAsset( )
  • make1155Asset( )
  • makeSwap( )
  • encodeAsset( )
  • decodeAsset( )
  • encodeConfig( )
  • decodeConfig( )
  1. Developers
  2. Technical Reference
  3. ✧ Interfaces

✧ ISwapFactory

Previous✧ ISwapNext✧ ISwaplace

Last updated 11 months ago

Interface of the {SwapFactory} implementation.

makeAsset( )

function makeAsset(address addr, uint256 amountOrId) external pure returns (struct ISwap.Asset)

Make an {ISwap-Asset} struct to work with token standards.

Parameters

Name
Type
Description

addr

address

is the address of the token asset.

amountOrId

uint256

is the amount of tokens or the ID of the NFT.

make1155Asset( )

function make1155Asset(address addr, uint120 tokenId, uint120 tokenAmount) external pure returns (struct ISwap.Asset)

Make an {ISwap-Asset} struct to work with token standards.

NOTE Different from the {makeAsset} function, this function is used to encode the token ID and token amount into a single uint256. This is made to work with the ERC1155 standard.

Parameters

Name
Type
Description

addr

address

is the address of the token asset.

tokenId

uint120

is the ID of the ERC1155 token.

tokenAmount

uint120

is the amount of the ERC1155 token.

makeSwap( )

function makeSwap(address owner, address allowed, uint32 expiry, uint8 recipient, uint56 value, struct ISwap.Asset[] assets, struct ISwap.Asset[] asking) external view returns (struct ISwap.Swap)

Build a swap struct to use in the {Swaplace-createSwap} function.

Requirements:

  • expiry cannot be in the past.

Parameters

Name
Type
Description

owner

address

is the address that created the Swap.

allowed

address

is the address that can accept the Swap. If the allowed address is the zero address, then anyone can accept the Swap.

expiry

uint32

is the timestamp that the Swap will be available to accept.

recipient

uint8

is the address that will receive the ETH. 0 for the acceptee and 1<>255 for the owner.

value

uint56

is the amount of ETH that the recipient will receive. Maximum of 6 decimals (0.000001 ETH). The contract will fill the value up to 18 decimals.

assets

struct ISwap.Asset[]

asking

struct ISwap.Asset[]

encodeAsset( )

function encodeAsset(uint120 tokenId, uint120 tokenAmount) external pure returns (uint256 amountAndId)

Encode tokenId and tokenAmount into a single uint256 while adding a flag to indicate that it's an ERC1155 token.

NOTE The flag is set to 0xFFFFFFFF.

Parameters

Name
Type
Description

tokenId

uint120

is the ID of the ERC1155 token.

tokenAmount

uint120

is the amount of the ERC1155 token.

decodeAsset( )

function decodeAsset(uint256 amountAndId) external pure returns (uint16 tokenType, uint256 tokenId, uint256 tokenAmount)

Decode amountOrId returning the first 4 bytes to try match with 0xFFFFFFFF. If the flag is set to 0xFFFFFFFF, then it's an ERC1155 standard, otherwise it's assumed to be an ERC20 or ERC721.

NOTE If it's an ERC1155 token, then the next 120 bits are the token ID and the next 120 bits are the token amount.

WARNING

Swaplace cannot handle ERC1155 tokens where the ID or the amount is greater than 120 bits.

Parameters

Name
Type
Description

amountAndId

uint256

is the amount of tokens and the ID of the ERC1155 token.

Return Values

Name
Type
Description

tokenType

uint16

is the flag to indicate the token standard.

tokenId

uint256

is the ID of the ERC1155 token.

tokenAmount

uint256

is the amount of the ERC1155 token.

encodeConfig( )

function encodeConfig(address allowed, uint32 expiry, uint8 recipient, uint56 value) external pure returns (uint256 config)

This function uses bitwise to return an encoded uint256 of the following parameters.

Parameters

Name
Type
Description

allowed

address

address is the address that can accept the Swap. If the allowed address is the zero address, then anyone can accept the Swap.

expiry

uint32

date is the timestamp that the Swap will be available to accept.

recipient

uint8

is the address that will receive the ETH as type uint8. If the recipient is equals to 0, the acceptee will receive the ETH. If the recipient is between 1<>255 then the recipient will be the owner of the Swap.

value

uint56

is the amount of ETH that the recipient will receive with a maximum of 6 decimals (0.000001 ETH). The contract will fill the value up to 18 decimals.

decodeConfig( )

function decodeConfig(uint256 config) external pure returns (address allowed, uint32 expiry, uint8 recipient, uint56 value)

Decode config into their respective variables.

Parameters

Name
Type
Description

config

uint256

is the encoded uint256 configuration of the Swap.

Source Code