Skip to content
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

feat(modules): standalone erc20 with own store #3087

Open
wants to merge 54 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
26100d2
add package
TamaraRingas Aug 28, 2024
7889451
update gitignore
TamaraRingas Aug 28, 2024
6a305d1
update README
TamaraRingas Aug 28, 2024
a12c8ce
add tables to config
TamaraRingas Aug 28, 2024
0ce58bc
add event & error interfaces
TamaraRingas Aug 28, 2024
51f8629
constructor, view & store functions
TamaraRingas Aug 28, 2024
d0aebeb
rm old gas-report
TamaraRingas Aug 28, 2024
6e8d675
add dist/
TamaraRingas Aug 28, 2024
7a3d91a
update package.json
TamaraRingas Aug 28, 2024
9bcf408
update lockfile
TamaraRingas Aug 28, 2024
7070f43
tablegen
TamaraRingas Aug 28, 2024
d48134c
comments
TamaraRingas Aug 28, 2024
64a8ed9
natspec
TamaraRingas Aug 28, 2024
1293538
transfer functions
TamaraRingas Aug 28, 2024
56bcd40
implement _spendAllowance()
TamaraRingas Aug 28, 2024
83af90f
implement _update() function
TamaraRingas Aug 28, 2024
4463f2c
format
TamaraRingas Aug 28, 2024
947d8b8
implement transferFrom()
TamaraRingas Aug 28, 2024
0f64286
implement _burn()
TamaraRingas Aug 28, 2024
1d6ab4b
implement _mint() function
TamaraRingas Aug 28, 2024
d9bc309
reorder functions
TamaraRingas Aug 28, 2024
13b9273
add mint test
TamaraRingas Aug 28, 2024
d2a1968
add burn test
TamaraRingas Aug 28, 2024
d485af9
update imports
TamaraRingas Aug 28, 2024
e97d283
comments
TamaraRingas Aug 28, 2024
ab4e0a4
update approve() implementation
TamaraRingas Aug 28, 2024
94cb254
add Transfer() test
TamaraRingas Aug 28, 2024
9f5b2c3
make mint & burn external
TamaraRingas Aug 28, 2024
150ee12
add GasReporter to tests
TamaraRingas Aug 28, 2024
32c87b3
reorder brackets in _update()
TamaraRingas Aug 28, 2024
9ce92f9
add GasReporter to tests
TamaraRingas Aug 29, 2024
2f43d48
add charlie address
TamaraRingas Aug 29, 2024
1f18db5
set Store address
TamaraRingas Aug 29, 2024
36958a0
add owner to Token
TamaraRingas Aug 29, 2024
b1d2790
add owner to constructor
TamaraRingas Aug 29, 2024
46e6047
add owner to Token
TamaraRingas Aug 29, 2024
5243007
add owner to constructor
TamaraRingas Aug 29, 2024
938be58
add fuzz tests
TamaraRingas Aug 29, 2024
914b0d5
update natspec
TamaraRingas Aug 29, 2024
1ba9cca
rename MUDERC20 to ERC20
TamaraRingas Aug 29, 2024
31d4192
add gas report
TamaraRingas Aug 29, 2024
2f84632
bump pragma
TamaraRingas Aug 29, 2024
3332e1e
add changeset
TamaraRingas Aug 29, 2024
281a554
add changeset
TamaraRingas Aug 29, 2024
a41870a
rm table directory from codegen
TamaraRingas Aug 29, 2024
d512f84
update gasReport() implementation
TamaraRingas Aug 29, 2024
5cefafb
update gas-report.json
TamaraRingas Aug 29, 2024
92b0b40
Merge branch 'main' of https://github.com/latticexyz/mud into tr/erc2…
TamaraRingas Aug 29, 2024
b081cc5
Update package.json
TamaraRingas Aug 29, 2024
6b4c925
Update package.json
TamaraRingas Aug 29, 2024
41971c7
Update package.json
TamaraRingas Aug 29, 2024
43c37b6
update lockfile
TamaraRingas Aug 29, 2024
a6534e5
Merge branch 'main' of https://github.com/latticexyz/mud into tr/erc2…
TamaraRingas Aug 29, 2024
3561447
Merge branch 'main' into tr/erc20-own-store
TamaraRingas Aug 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/world-module-erc20-own-store/.changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions packages/world-module-erc20-own-store/.changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/world-module-erc20-own-store": major
---

Implement ERC20 Module with own Store
3 changes: 3 additions & 0 deletions packages/world-module-erc20-own-store/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cache
out
src/codegen/world/
8 changes: 8 additions & 0 deletions packages/world-module-erc20-own-store/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "solhint:recommended",
"rules": {
"compiler-version": ["error", ">=0.8.0"],
"avoid-low-level-calls": "off",
"func-visibility": ["warn", { "ignoreConstructors": true }]
}
}
5 changes: 5 additions & 0 deletions packages/world-module-erc20-own-store/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Standalone ERC20 Module with own Store

This is an `ERC20` token template that is compatible with the MUD framework. The logic of the token contract is near native and resides within the token contract, while its storage makes use of `Store` and is reflected in corresponding tables.

The `OpenZeppelin` implementation of ERC20 is used as reference but tests are written in `Solidity`.
15 changes: 15 additions & 0 deletions packages/world-module-erc20-own-store/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[profile.default]
solc = "0.8.24"
ffi = false
fuzz_runs = 256
optimizer = true
optimizer_runs = 3000
verbosity = 2
allow_paths = ["../../node_modules", "../"]
src = "src"
out = "out"
bytecode_hash = "none"
extra_output_files = [
"abi",
"evm.bytecode"
]
170 changes: 170 additions & 0 deletions packages/world-module-erc20-own-store/gas-report.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
[
{
"file": "test/ERC20.t.sol",
"test": "testApprove",
"name": "token constructor",
"gasUsed": 7686226
},
{
"file": "test/ERC20.t.sol",
"test": "testApprove",
"name": "token approve",
"gasUsed": 64807
},
{
"file": "test/ERC20.t.sol",
"test": "testBalanceOf",
"name": "token constructor",
"gasUsed": 7686226
},
{
"file": "test/ERC20.t.sol",
"test": "testBalanceOf",
"name": "token constructor",
"gasUsed": 7686226
},
{
"file": "test/ERC20.t.sol",
"test": "testBalanceOf",
"name": "token constructor",
"gasUsed": 7686226
},
{
"file": "test/ERC20.t.sol",
"test": "testBalanceOf",
"name": "token constructor",
"gasUsed": 7686226
},
{
"file": "test/ERC20.t.sol",
"test": "testBalanceOf",
"name": "token constructor",
"gasUsed": 7686226
},
{
"file": "test/ERC20.t.sol",
"test": "testTokenBurn",
"name": "token constructor",
"gasUsed": 7686226
},
{
"file": "test/ERC20.t.sol",
"test": "testTokenBurn",
"name": "token burn",
"gasUsed": 63648
},
{
"file": "test/ERC20.t.sol",
"test": "testTokenBurnInvalidCaller",
"name": "token constructor",
"gasUsed": 7686226
},
{
"file": "test/ERC20.t.sol",
"test": "testTokenBurnInvalidCaller",
"name": "token burn invalid caller",
"gasUsed": 32388
},
{
"file": "test/ERC20.t.sol",
"test": "testTokenBurnZeroAddress",
"name": "token constructor",
"gasUsed": 7686226
},
{
"file": "test/ERC20.t.sol",
"test": "testTokenBurnZeroAddress",
"name": "token burn zero address",
"gasUsed": 32309
},
{
"file": "test/ERC20.t.sol",
"test": "testTokenMint",
"name": "token constructor",
"gasUsed": 7686226
},
{
"file": "test/ERC20.t.sol",
"test": "testTokenMint",
"name": "token mint",
"gasUsed": 85313
},
{
"file": "test/ERC20.t.sol",
"test": "testTokenMintInvalidCaller",
"name": "token constructor",
"gasUsed": 7686226
},
{
"file": "test/ERC20.t.sol",
"test": "testTokenMintInvalidCaller",
"name": "token mint invalid caller",
"gasUsed": 32410
},
{
"file": "test/ERC20.t.sol",
"test": "testTokenMintToZeroAddress",
"name": "token constructor",
"gasUsed": 7686226
},
{
"file": "test/ERC20.t.sol",
"test": "testTokenMintToZeroAddress",
"name": "token mint to zero address",
"gasUsed": 32331
},
{
"file": "test/ERC20.t.sol",
"test": "testTokenSetUp",
"name": "token constructor",
"gasUsed": 7686226
},
{
"file": "test/ERC20.t.sol",
"test": "testTokenTransfer",
"name": "token constructor",
"gasUsed": 7686226
},
{
"file": "test/ERC20.t.sol",
"test": "testTokenTransfer",
"name": "token transfer",
"gasUsed": 74442
},
{
"file": "test/ERC20.t.sol",
"test": "testTokenTransferInsufficientBalance",
"name": "token constructor",
"gasUsed": 7686226
},
{
"file": "test/ERC20.t.sol",
"test": "testTokenTransferInsufficientBalance",
"name": "token transfer insufficient balance",
"gasUsed": 30032
},
{
"file": "test/ERC20.t.sol",
"test": "testTransferFrom",
"name": "token constructor",
"gasUsed": 7686226
},
{
"file": "test/ERC20.t.sol",
"test": "testTransferFrom",
"name": "token transferFrom",
"gasUsed": 86297
},
{
"file": "test/ERC20.t.sol",
"test": "testTransferFromInsufficientAllowance",
"name": "token constructor",
"gasUsed": 7686226
},
{
"file": "test/ERC20.t.sol",
"test": "testTransferFromInsufficientAllowance",
"name": "token transferFrom insufficient allowance",
"gasUsed": 32482
}
]
32 changes: 32 additions & 0 deletions packages/world-module-erc20-own-store/mud.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { defineWorld } from "@latticexyz/world";

export default defineWorld({
namespace: "erc20-store",
tables: {
Token: {
schema: {
decimals: "uint8",
totalSupply: "uint256",
owner: "address",
name: "string",
symbol: "string",
},
key: [], // Singleton table
},
Balances: {
schema: {
account: "address",
balance: "uint256",
},
key: ["account"],
},
Allowances: {
schema: {
account: "address",
spender: "address",
approval: "uint256",
},
key: ["account", "spender"],
},
},
});
63 changes: 63 additions & 0 deletions packages/world-module-erc20-own-store/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "@latticexyz/world-module-erc20-own-store",
"version": "2.1.1",
"description": "ERC20 World Module with Own Store",
"repository": {
"type": "git",
"url": "https://github.com/latticexyz/mud.git",
"directory": "packages/world-module-erc20-own-store"
},
"license": "MIT",
"type": "module",
"exports": {
"./mud.config": "./dist/mud.config.js",
"./out/*": "./out/*"
},
"typesVersions": {
"*": {
"mud.config": [
"./dist/mud.config.d.ts"
]
}
},
"files": [
"dist",
"out",
"src"
],
"scripts": {
"build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:abi-ts && pnpm run build:js",
"build:abi": "forge build",
"build:abi-ts": "abi-ts",
"build:js": "tsup",
"build:mud": "tsx ./ts/build.ts",
"clean": "pnpm run clean:abi && pnpm run clean:js && pnpm run clean:mud",
"clean:abi": "forge clean",
"clean:js": "rimraf dist",
"clean:mud": "rimraf src/**/codegen",
TamaraRingas marked this conversation as resolved.
Show resolved Hide resolved
"dev": "tsup --watch",
TamaraRingas marked this conversation as resolved.
Show resolved Hide resolved
"gas-report": "gas-report --save gas-report.json",
"lint": "solhint --config ./.solhint.json 'src/**/*.sol'",
"test": "forge test",
"test:ci": "pnpm run test"
},
"dependencies": {
"@latticexyz/schema-type": "workspace:*",
"@latticexyz/store": "workspace:*",
"@latticexyz/world": "workspace:*"
},
"devDependencies": {
"@latticexyz/abi-ts": "workspace:*",
TamaraRingas marked this conversation as resolved.
Show resolved Hide resolved
"@latticexyz/gas-report": "workspace:*",
"@types/node": "^18.15.11",
"ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0",
"forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1",
"solhint": "^3.3.7",
"tsup": "^6.7.0",
"tsx": "^3.12.6",
"vitest": "0.34.6"
},
"publishConfig": {
"access": "public"
}
}
3 changes: 3 additions & 0 deletions packages/world-module-erc20-own-store/remappings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ds-test/=node_modules/ds-test/src/
forge-std/=node_modules/forge-std/src/
@latticexyz/=node_modules/@latticexyz/
Loading
Loading