Functions
getPair(address _tokenA, uint256 _tokenAId, address _tokenB) -> address
Returns the address of the swap pair associated with the provided ERC1155 and ERC20 token details.
Parameters
_tokenA (address): Address of the ERC1155 token contract.
_tokenAId (uint256): The ERC1155 token ID.
_tokenB (address): Address of the ERC20 token.
Returns
address: The address of the swap pair associated with the provided token details. If no pair exists for the given details, the function will return the zero address.
Remarks
The function first computes a unique hash for _tokenA using its address and ID.
Using this hash, the function fetches and returns the address of the pair associated with _tokenB from the contract's storage.
This documentation provides a clear overview of the function's purpose, its input parameters, expected output, and the underlying logic.
allPairsLength() -> uint256
Returns the total number of swap pairs that have been created.
Returns
uint256: The total count of swap pairs.
Remarks
The function calculates the count by measuring the length of the self.allPairs list, which stores the addresses of all created swap pairs, as can be seen from its usage in the createPair function.
createPair(address _tokenA, uint256 _tokenAId, address _tokenB) -> address
Creates a new swap pair using a blueprint contract and returns its contract address.
Parameters
_tokenA (address): Address of the ERC1155 token contract.
_tokenAId (uint256): The ERC1155 token ID.
_tokenB (address): Address of the ERC20 token.
Returns
address: The address of the newly created swap pair.
Remarks
The function asserts that neither _tokenA nor _tokenB are the zero address.
The function computes a unique hash for _tokenA using its address and ID, then checks if a pair with the corresponding _tokenB already exists. If it does, an assertion error is thrown.
Using the computed hashes and other parameters, the function calculates a salt which is then used to create a new pair using the blueprint contract (i.e., self.exchangeTemplate).
Once the new pair is created, its address is saved in the contract's storage and the PairCreated event is logged.
Finally, the address of the new pair is returned.
Last updated