diff --git a/QRC20X.sol b/QRC20X.sol index 8e76e87..36e23b5 100644 --- a/QRC20X.sol +++ b/QRC20X.sol @@ -150,22 +150,21 @@ contract QRC20 { return true; } /** - * This function sends tokens to an address on another chain by creating an external transaction (ETX). - - * This function uses opETX which constructs an external transaction and adds it to the block. - - * The ETX will make its way over to the destination and automatically execute when the given base fee is correct. - - * `to` must be an address on a different chain. The chain of a given address is determined by the first byte of the address. - - * gasLimit, minerTip and basefee are for executing the transaction on the destination chain. Choose these carefully. - - * The base fee and miner tip are in Wei and may not be the same as they are on your current chain. - - * If the base fee or miner tip are too low, the ETX will wait in the destination chain until they are high enough to be added in a block. - - * You must send a value with the function call equal to the following amount: (baseFee + minerTip) * gasLimit - */ + * @dev This function sends tokens to an address on another chain by creating an external transaction (ETX). It uses opETX + * which constructs an external transaction and adds it to the block. The ETX will make its way over to the destination and + * automatically execute when the given base fee is correct. The `to` must be an address on a different chain. The chain of a + * given address is determined by the first byte of the address. gasLimit, minerTip and basefee are for executing the + * transaction on the destination chain. Choose these carefully. The base fee and miner tip are in Wei and may not be the + * same as they are on your current chain. If the base fee or miner tip are too low, the ETX will wait in the destination + * chain until they are high enough to be added in a block. You must send a value with the function call equal to the + * following amount: (baseFee + minerTip) * gasLimit + * + * @param to The address of the recipient on the destination chain + * @param amount The amount of tokens to send + * @param gasLimit The amount of gas for execution + * @param minerTip The tip paid to the miner for execution + * @param baseFee The base fee + */ function crossChainTransfer(address to, uint256 amount, uint256 gasLimit, uint256 minerTip, uint256 baseFee) public payable { bool isInternal; assembly { @@ -487,28 +486,12 @@ contract QRC20 { ) internal {} /** - * This function allows the deployer to add an external address for the token contract on a different chain. + * @dev This function allows the deployer to add external addresses for the token contract on different chains. * Note that the deployer can only add one address per chain and this address cannot be changed afterwards. - * Be very careful when adding an address here. - */ - function AddApprovedAddress(uint8 chain, address addr) public { - bool isInternal; - assembly { - isInternal := isaddrinternal(addr) - } - require(!isInternal, "Address is not external"); - require(msg.sender == _deployer, "Sender is not deployer"); - require(chain < 9, "Max 9 zones"); - require(ApprovedAddresses[chain] == address(0), "The approved address for this zone already exists"); - ApprovedAddresses[chain] = addr; - } - - /** - * This function allows the deployer to add external addresses for the token contract on different chains. - * Note that the deployer can only add one address per chain and this address cannot be changed afterwards. - * In comparison to AddApprovedAddress, this function allows the address(es) to be internal so that the same - * approved list can be used for every instance of the contract on each chain. * Be very careful when adding addresses here. + * + * @param chain uint8 array of the chain indexes (i.e. cyprus 1 = 0, cyprus 2 = 1) + * @param addr array of the addresses to add as approved */ function AddApprovedAddresses(uint8[] calldata chain, address[] calldata addr) external { require(msg.sender == _deployer, "Sender is not deployer"); @@ -520,7 +503,11 @@ contract QRC20 { } } - // This function uses the stored prefix list to determine an address's location based on its first byte. + /** + * @dev This function uses the stored prefix list to determine an address's location based on its first byte. + * + * @param addr address to check location of + */ function getAddressLocation(address addr) public view returns (uint8) { uint8 prefix = uint8(toBytes(addr)[0]); if (ValidPrefixes[prefix]) { @@ -529,10 +516,20 @@ contract QRC20 { revert("Invalid Location"); } + /** + * @dev This function uses `abi.encodePacked` to encode the address into a bytes format. + * + * @param a The address to be converted to bytes. + */ function toBytes(address a) public pure returns (bytes memory) { return abi.encodePacked(a); } + /** + * @notice Converts an unsigned integer to its decimal string representation. + * + * @param _i The unsigned integer to convert to a string. + */ function uint2str(uint _i) internal pure returns (string memory _uintAsString) { if (_i == 0) { return "0"; @@ -554,4 +551,4 @@ contract QRC20 { } return string(bstr); } -} +} \ No newline at end of file diff --git a/QRC721X.sol b/QRC721X.sol index bdd35a1..c8aad0d 100644 --- a/QRC721X.sol +++ b/QRC721X.sol @@ -98,12 +98,19 @@ contract QRC721 is IERC721Errors { // Token symbol string private _symbol; + // Address of the contract deployer address private _deployer; + // Base URI for token metadata + string public baseURI; + // List of external token contracts that can send tokens to users on this chain address[12] public ApprovedAddresses; + // Mapping of address prefix to chain location mapping(uint8 => uint8) public PrefixToLocation; + + // Mapping of valid address prefixes mapping(uint8 => bool) public ValidPrefixes; mapping(uint256 /*tokenId*/ => address) private _owners; @@ -134,9 +141,10 @@ contract QRC721 is IERC721Errors { /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ - constructor() { - _name = "Quai Cross-Chain NFT"; - _symbol = "QXC"; + constructor(string memory name_, string memory symbol_, string memory baseURI_) { + _name = name_; + _symbol = symbol_; + baseURI = baseURI_; _deployer = msg.sender; PrefixToLocation[0] = 0; // zone 0-0 // cyprus1 PrefixToLocation[1] = 1; // zone 0-1 // cyprus2 @@ -211,7 +219,7 @@ contract QRC721 is IERC721Errors { * by default, can be overridden in child contracts. */ function _baseURI() internal pure returns (string memory) { - return "https://qu.ai/nft/"; + return _baseURI; } /** @@ -633,28 +641,12 @@ contract QRC721 is IERC721Errors { } /** - * This function allows the deployer to add an external address for the token contract on a different chain. - * Note that the deployer can only add one address per chain and this address cannot be changed afterwards. - * Be very careful when adding an address here. - */ - function AddApprovedAddress(uint8 chain, address addr) public { - bool isInternal; - assembly { - isInternal := isaddrinternal(addr) - } - require(!isInternal, "Address is not external"); - require(msg.sender == _deployer, "Sender is not deployer"); - require(chain < 9, "Max 9 zones"); - require(ApprovedAddresses[chain] == address(0), "The approved address for this zone already exists"); - ApprovedAddresses[chain] = addr; - } - - /** - * This function allows the deployer to add external addresses for the token contract on different chains. - * Note that the deployer can only add one address per chain and this address cannot be changed afterwards. - * In comparison to AddApprovedAddress, this function allows the address(es) to be internal so that the same - * approved list can be used for every instance of the contract on each chain. + * @dev This function allows the deployer to add external addresses for the token contract on different chains. + * Note that the deployer can only add one address per shard and this address cannot be changed afterwards. * Be very careful when adding addresses here. + * + * @param chain uint8 array of the chain indexes (i.e. cyprus 1 = 0, cyprus 2 = 1) + * @param addr array of the addresses to add as approved */ function AddApprovedAddresses(uint8[] calldata chain, address[] calldata addr) external { @@ -674,7 +666,11 @@ contract QRC721 is IERC721Errors { } - // This function uses the stored prefix list to determine an address's location based on its first byte. + /** + * @dev This function uses the stored prefix list to determine an address's location based on its first byte. + * + * @param addr address to check location of + */ function getAddressLocation(address addr) public view returns (uint8) { uint8 prefix = uint8(toBytes(addr)[0]); if (ValidPrefixes[prefix]) { @@ -683,11 +679,19 @@ contract QRC721 is IERC721Errors { revert("Invalid Location"); } + /** + * @dev This function uses `abi.encodePacked` to encode the address into a bytes format. + * + * @param a The address to be converted to bytes. + */ function toBytes(address a) public pure returns (bytes memory) { return abi.encodePacked(a); } + /** - * @dev Converts a `uint256` to its ASCII `string` decimal representation. + * @notice Converts an unsigned integer to its decimal string representation. + * + * @param value The unsigned integer to convert to a string. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { @@ -713,6 +717,8 @@ contract QRC721 is IERC721Errors { /** * @dev Return the log in base 10 of a positive value rounded towards zero. * Returns 0 if given 0. + * + * @param value The unsigned integer perform the log on */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; @@ -747,4 +753,4 @@ contract QRC721 is IERC721Errors { } return result; } -} +} \ No newline at end of file