Skip to content

Commit

Permalink
Merge pull request #33 from superform-xyz/tokenInfo
Browse files Browse the repository at this point in the history
feat: add name and symbol to ERC1155A
  • Loading branch information
sujithsomraaj authored Jan 23, 2024
2 parents f46fa54 + 57efc39 commit 05e5421
Show file tree
Hide file tree
Showing 10 changed files with 367 additions and 15 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MUMBAI_RPC_URL=
142 changes: 142 additions & 0 deletions broadcast/DeployTestERC1155A.s.sol/80001/deploy-latest.json

Large diffs are not rendered by default.

142 changes: 142 additions & 0 deletions broadcast/DeployTestERC1155A.s.sol/80001/run-1706004511.json

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions script/DeployTestERC1155A.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import { Script } from "forge-std/Script.sol";

import "forge-std/console.sol";

import "src/test/mocks/MockERC1155A.sol";

contract DeployTestERC1155A is Script {
address public deployedContract;

function deploy() external {
vm.startBroadcast();
MockERC1155A erc1155a = new MockERC1155A("Example", "EXM");
erc1155a.mint(0x48aB8AdF869Ba9902Ad483FB1Ca2eFDAb6eabe92, 1, 100, "" "");
deployedContract = address(erc1155a);
vm.stopBroadcast();
console.log("Deployed contract at: %s", deployedContract);
}
}
6 changes: 6 additions & 0 deletions script/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

# Read the RPC URL
source .env

forge script script/DeployTestERC1155A.s.sol:DeployTestERC1155A --sig "deploy()" --rpc-url $MUMBAI_RPC_URL --broadcast --slow --account defaultKey --sender 0x48aB8AdF869Ba9902Ad483FB1Ca2eFDAb6eabe92
17 changes: 17 additions & 0 deletions src/ERC1155A.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ abstract contract ERC1155A is IERC1155A, IERC1155Errors {
/// @dev mapping of token ids to aErc20 token addresses
mapping(uint256 id => address aErc20Token) public aErc20TokenId;

/// @dev ERC1155A name
string public name;
/// @dev ERC1155A symbol
string public symbol;

//////////////////////////////////////////////////////////////
// CONSTRUCTOR //
//////////////////////////////////////////////////////////////

/// @dev Initializes ERC1155A
/// @param name_ ERC1155A name
/// @param symbol_ ERC1155A symbol
constructor(string memory name_, string memory symbol_) {
name = name_;
symbol = symbol_;
}

//////////////////////////////////////////////////////////////
// EXTERNAL VIEW FUNCTIONS //
//////////////////////////////////////////////////////////////
Expand Down
41 changes: 29 additions & 12 deletions src/interfaces/IERC1155A.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { IERC1155 } from "openzeppelin-contracts/contracts/token/ERC1155/IERC115
/// @author Zeropoint Labs
/// @dev Single/range based id approve capability with conversion to ERC20s
interface IERC1155A is IERC1155 {

//////////////////////////////////////////////////////////////
// EVENTS //
//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -57,12 +56,12 @@ interface IERC1155A is IERC1155 {
//////////////////////////////////////////////////////////////

/// @notice Public getter for existing single id total supply
/// @param id id of the ERC1155
/// @param id id of the ERC1155
function totalSupply(uint256 id) external view returns (uint256);

/// @notice Public getter to know if a token id exists
/// @dev determines based on total supply for the id
/// @param id id of the ERC1155
/// @param id id of the ERC1155
function exists(uint256 id) external view returns (bool);

/// @notice Public getter for existing single id approval
Expand All @@ -72,7 +71,7 @@ interface IERC1155A is IERC1155 {
function allowance(address owner, address spender, uint256 id) external returns (uint256);

/// @notice handy helper to check if a AERC20 is registered
/// @param id id of the ERC1155
/// @param id id of the ERC1155
function aERC20Exists(uint256 id) external view returns (bool);

/// @notice Public getter for the address of the aErc20 token for a given ERC1155 id
Expand All @@ -81,9 +80,15 @@ interface IERC1155A is IERC1155 {
function getERC20TokenAddress(uint256 id) external view returns (address aERC20);

/// @notice Compute return string from baseURI set for this contract and unique vaultId
/// @param id id of the ERC1155
/// @param id id of the ERC1155
function uri(uint256 id) external view returns (string memory);

/// @notice ERC1155A name
function name() external view returns (string memory);

/// @notice ERC1155A symbol
function symbol() external view returns (string memory);

//////////////////////////////////////////////////////////////
// EXTERNAL WRITE FUNCTIONS //
//////////////////////////////////////////////////////////////
Expand All @@ -106,21 +111,21 @@ interface IERC1155A is IERC1155 {
/// @dev Re-adapted from ERC20
/// @param spender address of the contract to approve
/// @param id id of the ERC1155A to approve
/// @param addedValue amount of the allowance to increase by
/// @param addedValue amount of the allowance to increase by
function increaseAllowance(address spender, uint256 id, uint256 addedValue) external returns (bool);

/// @notice Public function for decreasing single id approval amount
/// @dev Re-adapted from ERC20
/// @param spender address of the contract to approve
/// @param id id of the ERC1155A to approve
/// @param subtractedValue amount of the allowance to decrease by
/// @param subtractedValue amount of the allowance to decrease by
function decreaseAllowance(address spender, uint256 id, uint256 subtractedValue) external returns (bool);

/// @notice Public function for increasing multiple id approval amount at once
/// @dev extension of single id increase allowance
/// @param spender address of the contract to approve
/// @param ids ids of the ERC1155A to approve
/// @param addedValues amounts of the allowance to increase by
/// @param addedValues amounts of the allowance to increase by
function increaseAllowanceForMany(
address spender,
uint256[] memory ids,
Expand All @@ -133,7 +138,7 @@ interface IERC1155A is IERC1155 {
/// @dev extension of single id decrease allowance
/// @param spender address of the contract to approve
/// @param ids ids of the ERC1155A to approve
/// @param subtractedValues amounts of the allowance to decrease by
/// @param subtractedValues amounts of the allowance to decrease by
function decreaseAllowanceForMany(
address spender,
uint256[] memory ids,
Expand All @@ -150,7 +155,7 @@ interface IERC1155A is IERC1155 {
/// @param receiver address of the user to receive the aERC20 token
function transmuteToERC20(address owner, uint256 id, uint256 amount, address receiver) external;

/// @notice Turn aERC20 into an ERC1155A id
/// @notice Turn aERC20 into an ERC1155A id
/// @dev allows owner to send ERC20 as an ERC1155A id to receiver
/// @param owner address of the user on whose behalf this transmutation is happening
/// @param id id of the ERC20s to transmute to erc1155
Expand All @@ -164,15 +169,27 @@ interface IERC1155A is IERC1155 {
/// @param ids ids of the ERC1155A to transmute
/// @param amounts amounts of the ERC1155A to transmute
/// @param receiver address of the user to receive the aERC20 tokens
function transmuteBatchToERC20(address owner, uint256[] memory ids, uint256[] memory amounts, address receiver) external;
function transmuteBatchToERC20(
address owner,
uint256[] memory ids,
uint256[] memory amounts,
address receiver
)
external;

/// @notice Turn aERC20s into ERC1155A ids
/// @dev allows owner to send aERC20s as ERC1155A ids to receiver
/// @param owner address of the user on whose behalf this transmutation is happening
/// @param ids ids of the ERC20 to transmute
/// @param amounts amounts of the ERC20 to transmute
/// @param receiver address of the user to receive the ERC1155 token ids
function transmuteBatchToERC1155A(address owner, uint256[] memory ids, uint256[] memory amounts, address receiver) external;
function transmuteBatchToERC1155A(
address owner,
uint256[] memory ids,
uint256[] memory amounts,
address receiver
)
external;

/// @notice payable to allow any implementing cross-chain protocol to be paid for fees for broadcasting
/// @dev should emit any required events inside _registerAERC20 internal function
Expand Down
8 changes: 6 additions & 2 deletions src/test/ERC1155.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { MockERC1155A } from "./mocks/MockERC1155A.sol";
* original by @author - solmate
* forked by @author - ZeroPointLabs
*/

contract ERC1155Recipient is ERC1155TokenReceiver {
address public operator;
address public from;
Expand Down Expand Up @@ -148,7 +147,12 @@ contract ERC1155Test is DSTestPlus, ERC1155TokenReceiver {
mapping(address => mapping(uint256 => uint256)) public userTransferOrBurnAmounts;

function setUp() public {
token = new MockERC1155A();
token = new MockERC1155A("example", "exm");
}

function test_name_symbol() public {
assertEq(token.name(), "example");
assertEq(token.symbol(), "exm");
}

function testMintToEOA() public {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ERC1155_A.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract ERC1155ATest is Test {
address public bob = address(0x0997);

function setUp() public {
MockedERC1155A = new MockERC1155A();
MockedERC1155A = new MockERC1155A("example", "EXM");
MockedERC1155A.mint(alice, 1, THOUSAND_E18, "");
MockedERC1155A.mint(alice, 2, THOUSAND_E18, "");
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/mocks/MockERC1155A.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Strings } from "openzeppelin-contracts/contracts/utils/Strings.sol";

/// @notice For test purpouses we open mint()/burn() functions of ERC1155A
contract MockERC1155A is ERC1155A {
constructor(string memory name_, string memory symbol_) ERC1155A(name_, symbol_) { }

/// @dev See ../ERC1155A.sol
function uri(uint256 id) public pure override returns (string memory) {
return string(abi.encodePacked(_baseURI(), Strings.toString(id)));
Expand Down

0 comments on commit 05e5421

Please sign in to comment.