Skip to content

Commit

Permalink
Update contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Nov 7, 2024
1 parent 1fe6c49 commit 9ba8a7c
Show file tree
Hide file tree
Showing 10 changed files with 2,257 additions and 1,365 deletions.
39 changes: 39 additions & 0 deletions build_contracts.js
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));
28 changes: 16 additions & 12 deletions contracts/ERC1155Example.sol
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);
}
}
24 changes: 15 additions & 9 deletions contracts/ERC20.sol
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);
}
}
}


60 changes: 60 additions & 0 deletions contracts/ERC721.sol
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);
}
}


12 changes: 12 additions & 0 deletions contracts/FailingContract.sol
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");
}
}

9 changes: 6 additions & 3 deletions contracts/Piggybank.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
pragma solidity ^0.4.0;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract PiggyBank {

uint private balance;
address public owner;

function PiggyBank() public {
constructor() {
owner = msg.sender;
balance = 0;
}
Expand All @@ -19,7 +20,9 @@ contract PiggyBank {
require(msg.sender == owner);
balance -= withdrawAmount;

msg.sender.transfer(withdrawAmount);
// Use call to transfer Ether
(bool success, ) = payable(msg.sender).call{value: withdrawAmount}("");
require(success, "Transfer failed");

return balance;
}
Expand Down
13 changes: 7 additions & 6 deletions contracts/TestDappCollectibles.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import 'base64-sol/base64.sol';
import "base64-sol/base64.sol";

contract TestDappNFTs is ERC721 {

using Counters for Counters.Counter;
Counters.Counter private _tokenIds;

Expand All @@ -26,7 +26,7 @@ contract TestDappNFTs is ERC721 {
}

function tokenURI(uint tokenId) public pure override returns (string memory) {
string memory svg =
string memory svg =
'<svg height="350" width="350" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">'
'<defs>'
'<path id="MyPath" fill="none" stroke="red" '
Expand All @@ -42,11 +42,11 @@ contract TestDappNFTs is ERC721 {
string memory json = string(
abi.encodePacked(
'{"name": "Test Dapp NFTs #',
Strings.toString(tokenId),
Strings.toString(tokenId),
'", "description": "Test Dapp NFTs for testing.", "image": "data:image/svg+xml;base64,',
Base64.encode(bytes(svg)),
'", "attributes": [{"trait_type": "Token Id", "value": "',
Strings.toString(tokenId),
Strings.toString(tokenId),
'"}]}'
)
);
Expand All @@ -60,3 +60,4 @@ contract TestDappNFTs is ERC721 {
return uri;
}
}

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@metamask/test-dapp",
"version": "8.13.0",
"type": "module",
"description": "A simple dapp used in MetaMask e2e tests.",
"engines": {
"node": ">= 18.0.0"
Expand Down Expand Up @@ -34,7 +35,9 @@
"url": "https://github.com/MetaMask/test-dapp/issues"
},
"homepage": "https://metamask.github.io/test-dapp",
"dependencies": {},
"dependencies": {
"@parity/revive": "^0.0.4"
},
"devDependencies": {
"@lavamoat/allow-scripts": "^2.5.1",
"@lavamoat/preinstall-always-fail": "^2.0.0",
Expand All @@ -44,7 +47,7 @@
"@metamask/eth-sig-util": "^7.0.1",
"@metamask/onboarding": "^1.0.0",
"@metamask/sdk": "0.30.1",
"@openzeppelin/contracts": "4.9.6",
"@openzeppelin/contracts": "5.1.0",
"@walletconnect/modal": "^2.6.2",
"@web3modal/ethers5": "^3.2.0",
"assert": "^2.1.0",
Expand Down
1,214 changes: 920 additions & 294 deletions src/constants.json

Large diffs are not rendered by default.

Loading

0 comments on commit 9ba8a7c

Please sign in to comment.