-
Notifications
You must be signed in to change notification settings - Fork 3
ws-miniwallet-v0.1 MiniWallet Functionality #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4132c59
83e51d1
e493ae3
6a00b8e
07b9ee2
f82d812
7ef7989
357dec7
b0267e6
9b66e2e
f2060a7
dc54f9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| [ | ||
| { | ||
| "inputs": [ | ||
| { | ||
| "internalType": "address", | ||
| "name": "_logic", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "internalType": "bytes", | ||
| "name": "_data", | ||
| "type": "bytes" | ||
| } | ||
| ], | ||
| "stateMutability": "payable", | ||
| "type": "constructor" | ||
| }, | ||
| { | ||
| "anonymous": false, | ||
| "inputs": [ | ||
| { | ||
| "indexed": false, | ||
| "internalType": "address", | ||
| "name": "previousAdmin", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "indexed": false, | ||
| "internalType": "address", | ||
| "name": "newAdmin", | ||
| "type": "address" | ||
| } | ||
| ], | ||
| "name": "AdminChanged", | ||
| "type": "event" | ||
| }, | ||
| { | ||
| "anonymous": false, | ||
| "inputs": [ | ||
| { | ||
| "indexed": true, | ||
| "internalType": "address", | ||
| "name": "beacon", | ||
| "type": "address" | ||
| } | ||
| ], | ||
| "name": "BeaconUpgraded", | ||
| "type": "event" | ||
| }, | ||
| { | ||
| "anonymous": false, | ||
| "inputs": [ | ||
| { | ||
| "indexed": true, | ||
| "internalType": "address", | ||
| "name": "implementation", | ||
| "type": "address" | ||
| } | ||
| ], | ||
| "name": "Upgraded", | ||
| "type": "event" | ||
| }, | ||
| { | ||
| "stateMutability": "payable", | ||
| "type": "fallback" | ||
| }, | ||
| { | ||
| "inputs": [], | ||
| "name": "implementation", | ||
| "outputs": [ | ||
| { | ||
| "internalType": "address", | ||
| "name": "impl", | ||
| "type": "address" | ||
| } | ||
| ], | ||
| "stateMutability": "view", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "stateMutability": "payable", | ||
| "type": "receive" | ||
| } | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1043,4 +1043,4 @@ | |
| "stateMutability": "nonpayable", | ||
| "type": "function" | ||
| } | ||
| ], | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,10 +4,26 @@ import 'dotenv/config' | |
| export default { | ||
| mainnet: { | ||
| miniWallet: { | ||
| initialOperatorThreshold: process.env.MINIWALLET_INITIAL_OPERATOR_THRESHOLD, | ||
| initialOperatorThreshold: process.env.MINIWALLET_INITIAL_OPERATOR_THRESHOLD || '100', | ||
| initialOperators: JSON.parse(process.env.MINIWALLET_INITIAL_OPERATORS || '[]'), | ||
| initialUserLimit: ethers.utils.parseEther(process.env.MINIWALLET_INIITIAL_USER_LIMIT || '1000000'), | ||
| initialAuthLimit: ethers.utils.parseEther(process.env.MINIWALLET_INIITIAL_AUTH_LIMIT || '100000') | ||
| } | ||
| }, | ||
| ethlocal: { | ||
| miniWallet: { | ||
| initialOperatorThreshold: process.env.ETH_LOCAL_MINIWALLET_INITIAL_OPERATOR_THRESHOLD || '10', | ||
| initialOperators: JSON.parse(process.env.ETH_LOCAL_MINIWALLET_INITIAL_OPERATORS || '[]'), | ||
| initialUserLimit: ethers.utils.parseEther(process.env.ETH_LOCAL_MINIWALLET_INIITIAL_USER_LIMIT || '1000'), | ||
| initialAuthLimit: ethers.utils.parseEther(process.env.ETH_LOCAL_MINIWALLET_INIITIAL_AUTH_LIMIT || '100') | ||
| } | ||
| }, | ||
| hardhat: { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the difference between ethLocal and hardhat config?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ethLocal is used for end to end testing. It is part or the local testing environment documented here specifically using ganache as documented here hardhat config is used by the following commands
Note the tags are populated in each of the test scripts |
||
| miniWallet: { | ||
| initialOperatorThreshold: process.env.HARDHAT_MINIWALLET_INITIAL_OPERATOR_THRESHOLD || '10', | ||
| initialOperators: JSON.parse(process.env.HARDHAT_MINIWALLET_INITIAL_OPERATORS || '[]'), | ||
| initialUserLimit: ethers.utils.parseEther(process.env.HARDHAT_MINIWALLET_INIITIAL_USER_LIMIT || '1000'), | ||
| initialAuthLimit: ethers.utils.parseEther(process.env.HARDHAT_MINIWALLET_INIITIAL_AUTH_LIMIT || '100') | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| pragma solidity ^0.8.4; | ||
|
|
||
| import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; | ||
| import "@openzeppelin/contracts/access/AccessControl.sol"; | ||
|
|
||
| /// @custom:security-contact dev@modulo.so | ||
| contract TestERC1155 is ERC1155, AccessControl { | ||
| bytes32 public constant URI_SETTER_ROLE = keccak256("URI_SETTER_ROLE"); | ||
| bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); | ||
|
|
||
| constructor(uint256[] memory tokenIds, uint256[] memory amounts) | ||
| ERC1155("") | ||
| { | ||
| _grantRole(DEFAULT_ADMIN_ROLE, msg.sender); | ||
| _grantRole(URI_SETTER_ROLE, msg.sender); | ||
| _grantRole(MINTER_ROLE, msg.sender); | ||
| for (uint32 i = 0; i < tokenIds.length; i++) { | ||
| mint(msg.sender, tokenIds[i], amounts[i], ""); | ||
| } | ||
| } | ||
|
|
||
| function setURI(string memory newuri) public onlyRole(URI_SETTER_ROLE) { | ||
| _setURI(newuri); | ||
| } | ||
|
|
||
| function mint( | ||
| address account, | ||
| uint256 id, | ||
| uint256 amount, | ||
| bytes memory data | ||
| ) public onlyRole(MINTER_ROLE) { | ||
| _mint(account, id, amount, data); | ||
| } | ||
|
|
||
| function mintBatch( | ||
| address to, | ||
| uint256[] memory ids, | ||
| uint256[] memory amounts, | ||
| bytes memory data | ||
| ) public onlyRole(MINTER_ROLE) { | ||
| _mintBatch(to, ids, amounts, data); | ||
| } | ||
|
|
||
| // The following functions are overrides required by Solidity. | ||
|
|
||
| function supportsInterface(bytes4 interfaceId) | ||
| public | ||
| view | ||
| override(ERC1155, AccessControl) | ||
| returns (bool) | ||
| { | ||
| return (ERC1155.supportsInterface(interfaceId) || | ||
| AccessControl.supportsInterface(interfaceId)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| pragma solidity ^0.8.4; | ||
|
|
||
| import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
| import "@openzeppelin/contracts/access/AccessControl.sol"; | ||
|
|
||
| /// @custom:security-contact dev@modulo.so | ||
| contract TestERC20 is ERC20, AccessControl { | ||
| bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); | ||
|
|
||
| constructor(uint256 _amount) ERC20("TestERC20", "T20") { | ||
| _mint(msg.sender, _amount * 10**decimals()); | ||
| _grantRole(DEFAULT_ADMIN_ROLE, msg.sender); | ||
| _grantRole(MINTER_ROLE, msg.sender); | ||
| } | ||
|
|
||
| function mint(address to, uint256 amount) public onlyRole(MINTER_ROLE) { | ||
| _mint(to, amount); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| pragma solidity ^0.8.4; | ||
|
|
||
| import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | ||
| import "@openzeppelin/contracts/access/AccessControl.sol"; | ||
| import "@openzeppelin/contracts/utils/Counters.sol"; | ||
|
|
||
| /// @custom:security-contact dev@modulo.so | ||
| contract TestERC721 is ERC721, AccessControl { | ||
| using Counters for Counters.Counter; | ||
|
|
||
| bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); | ||
| Counters.Counter private _tokenIdCounter; | ||
|
|
||
| constructor(uint256 _amount) ERC721("TestERC721", "T721") { | ||
| _grantRole(DEFAULT_ADMIN_ROLE, msg.sender); | ||
| _grantRole(MINTER_ROLE, msg.sender); | ||
| for (uint32 i = 0; i < _amount; i++) { | ||
| safeMint(msg.sender); | ||
| } | ||
| } | ||
|
|
||
| function _baseURI() internal pure override returns (string memory) { | ||
| return ""; | ||
| } | ||
|
|
||
| function safeMint(address to) public onlyRole(MINTER_ROLE) { | ||
| uint256 tokenId = _tokenIdCounter.current(); | ||
| _tokenIdCounter.increment(); | ||
| _safeMint(to, tokenId); | ||
| } | ||
|
|
||
| // The following functions are overrides required by Solidity. | ||
|
|
||
| function supportsInterface(bytes4 interfaceId) | ||
| public | ||
| view | ||
| override(ERC721, AccessControl) | ||
| returns (bool) | ||
| { | ||
| return (ERC721.supportsInterface(interfaceId) || | ||
| AccessControl.supportsInterface(interfaceId)); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should use type 2 transactions instead of arbitrary numbers, or manually set base fee in emulating local eth blockchain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good Point 🙏
An example of how to
use type 2 transactionswould be usefulInitial google shows these EIPS
Will investigate further.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Further Investigation
Gives this code example
Also debugging
eth_estimateGasimplies that we are using type2 transactions"type":"0x2",Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now I've updated
prepareExecuteto retrieve thegasPriceconst gasPrice = await provider.getGasPrice()This introduces an additional rpc call on each transaction
Note this uses getGasPrice there is also estimateGas which may give a more accurate estimate.
@polymorpher let me know your thoughts on this and whether the additional rpc call is to burdensome, and if you'd prefer to use estimateGas
Also assumption is that this works on all evm compatible chains (Including Harmony) however this has only been tested on hardhat and ganache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's fine, type 2 is not supported on all chains, including ganache