forked from MetaMask/test-dapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
2,257 additions
and
1,365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { compile } from '@parity/revive'; | ||
import { readFileSync, writeFileSync } from 'fs'; | ||
import { join } from 'path'; | ||
|
||
console.log('Compiling contracts...'); | ||
|
||
let json = JSON.parse(readFileSync('src/constants.json', 'utf8')); | ||
const input = [ | ||
{ file: 'ERC20.sol', contract: 'MyToken', keypath: 'hst' }, | ||
{ file: 'Piggybank.sol', contract: 'PiggyBank', keypath: 'piggybank' }, | ||
{ file: 'ERC721.sol', contract: 'MyToken', keypath: 'nfts' }, | ||
{ | ||
file: 'FailingContract.sol', | ||
contract: 'MMCheck', | ||
keypath: 'failingContract', | ||
}, | ||
{ | ||
file: 'MultisigWallet.sol', | ||
contract: 'MultiSigWallet', | ||
keypath: 'multisig', | ||
}, | ||
{ | ||
file: 'ERC1155Example.sol', | ||
contract: 'ERC1155Example', | ||
keypath: 'erc1155', | ||
}, | ||
]; | ||
|
||
for (const { keypath, contract, file } of input) { | ||
console.log(`Compile ${file}`); | ||
const out = await compile({ | ||
[file]: { content: readFileSync(join('contracts', file), 'utf8') }, | ||
}); | ||
|
||
const entry = out.contracts[file][contract]; | ||
json[`${keypath}Abi`] = entry.abi; | ||
json[`${keypath}bytecode`] = entry.evm.bytecode.object; | ||
} | ||
writeFileSync('src/constants.json', JSON.stringify(json, null, 2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
// Compatible with OpenZeppelin Contracts ^5.0.0 | ||
pragma solidity ^0.8.22; | ||
|
||
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "@openzeppelin/contracts/utils/Strings.sol"; | ||
|
||
contract ERC1155Example is ERC1155, Ownable { | ||
string public constant name = "ERC1155"; | ||
constructor(address initialOwner) ERC1155("ipfs://bafybeidxfmwycgzcp4v2togflpqh2gnibuexjy4m4qqwxp7nh3jx5zlh4y/") Ownable(initialOwner) {} | ||
|
||
constructor() ERC1155("ipfs://bafybeidxfmwycgzcp4v2togflpqh2gnibuexjy4m4qqwxp7nh3jx5zlh4y/") { | ||
function setURI(string memory newuri) public onlyOwner { | ||
_setURI(newuri); | ||
} | ||
|
||
function uri(uint256 _tokenid) override public view returns (string memory) { | ||
return string(abi.encodePacked(super.uri(_tokenid), Strings.toString(_tokenid), ".json")); | ||
function mint(address account, uint256 id, uint256 amount, bytes memory data) | ||
public | ||
onlyOwner | ||
{ | ||
_mint(account, id, amount, data); | ||
} | ||
|
||
|
||
function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) public onlyOwner{ | ||
function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) | ||
public | ||
onlyOwner | ||
{ | ||
_mintBatch(to, ids, amounts, data); | ||
} | ||
} | ||
|
||
|
||
function setURI(string memory newuri) public onlyOwner { | ||
_setURI(newuri); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.9; | ||
// Compatible with OpenZeppelin Contracts ^5.0.0 | ||
pragma solidity ^0.8.22; | ||
|
||
import "@openzeppelin/contracts@4.8.2/token/ERC20/ERC20.sol"; | ||
import "@openzeppelin/contracts@4.8.2/access/Ownable.sol"; | ||
import "@openzeppelin/contracts@4.8.2/token/ERC20/extensions/draft-ERC20Permit.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol"; | ||
|
||
contract MyToken is ERC20, Ownable, ERC20Permit { | ||
|
||
constructor(uint256 initialAmount, string memory tokenName, uint8 decimalUnits, string memory tokenSymbol) ERC20(tokenName, tokenSymbol, decimalUnits) ERC20Permit(tokenName) { | ||
_mint(msg.sender, initialAmount * 10 ** decimals); | ||
} | ||
constructor(address initialOwner) | ||
ERC20("MyToken", "MTK") | ||
Ownable(initialOwner) | ||
ERC20Permit("MyToken") | ||
{ | ||
_mint(msg.sender, 100 * 10 ** decimals()); | ||
} | ||
|
||
function mint(address to, uint256 amount) public onlyOwner { | ||
_mint(to, amount); | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Compatible with OpenZeppelin Contracts ^5.0.0 | ||
pragma solidity ^0.8.22; | ||
|
||
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | ||
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; | ||
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
contract MyToken is ERC721, ERC721Enumerable, ERC721URIStorage, Ownable { | ||
uint256 private _nextTokenId; | ||
|
||
constructor(address initialOwner) | ||
ERC721("MyToken", "MTK") | ||
Ownable(initialOwner) | ||
{} | ||
|
||
function safeMint(address to, string memory uri) public onlyOwner { | ||
uint256 tokenId = _nextTokenId++; | ||
_safeMint(to, tokenId); | ||
_setTokenURI(tokenId, uri); | ||
} | ||
|
||
// The following functions are overrides required by Solidity. | ||
|
||
function _update(address to, uint256 tokenId, address auth) | ||
internal | ||
override(ERC721, ERC721Enumerable) | ||
returns (address) | ||
{ | ||
return super._update(to, tokenId, auth); | ||
} | ||
|
||
function _increaseBalance(address account, uint128 value) | ||
internal | ||
override(ERC721, ERC721Enumerable) | ||
{ | ||
super._increaseBalance(account, value); | ||
} | ||
|
||
function tokenURI(uint256 tokenId) | ||
public | ||
view | ||
override(ERC721, ERC721URIStorage) | ||
returns (string memory) | ||
{ | ||
return super.tokenURI(tokenId); | ||
} | ||
|
||
function supportsInterface(bytes4 interfaceId) | ||
public | ||
view | ||
override(ERC721, ERC721Enumerable, ERC721URIStorage) | ||
returns (bool) | ||
{ | ||
return super.supportsInterface(interfaceId); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
contract MMCheck { | ||
|
||
receive() external payable { | ||
require(msg.value > 0xfff, "Insufficient amount"); | ||
(bool success, ) = msg.sender.call{value: msg.value}(""); | ||
require(success, "Transfer failed"); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.