-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: smart character module v2 implementation (#133)
* adding erc20 eve token deployment as part of the world * refactor: adding ERC721 puppet contracts * removed erc721 puppet * adding erc721 deployments for smart character and smart deployable * refactor: modify functions to use a struct for parameters. - improves code readability and maintainability by reducing the number of parameters and ensuring all relevant data is passed together. * refactor: adding character tables and systems * refactor: adding erc721 code snippets from mud * refactor: adding tests for erc721 * refactor: modify static data table to match erc721 * test: add tests for erc721 * refactor: using utils to get systemId * refactor: refactoring static data to algin with erc721 * adding revert conditions * chore: creating a single interface for errors * refactor: added end-end-tests to createCharacter * fix: imports and merge conflicts * lint: fixing lint errors
- Loading branch information
1 parent
11e046b
commit 8e85ef3
Showing
55 changed files
with
5,351 additions
and
466 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,10 @@ | ||
# Enable debug logs for MUD CLI | ||
DEBUG=mud:* | ||
# | ||
# Anvil default private key: | ||
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 | ||
|
||
# Rpc url for devnet blockchain node | ||
RPC_URL=https://devnet-data-sync.nursery.reitnorf.com | ||
|
||
WORLD_ADDRESS=0xd4fC27377dd7a2C0F7DF5C8A67Dd555C0b8Bf5D8 |
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 @@ | ||
# Enable debug logs for MUD CLI | ||
DEBUG=mud:* | ||
# | ||
# Anvil default private key: | ||
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 | ||
|
||
# Rpc url for local blockchain node | ||
RPC_URL=http://127.0.0.1:8545 | ||
|
||
|
||
WORLD_ADDRESS=0x036a9e1e4c46449ffd9e7b9d0321395b9096be0c | ||
|
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,8 @@ | ||
{ | ||
"plugins": ["prettier-plugin-solidity"], | ||
"printWidth": 120, | ||
"semi": true, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"bracketSpacing": true | ||
} |
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,13 @@ | ||
{ | ||
"extends": ["solhint:recommended", "mud"], | ||
"plugins": ["mud"], | ||
"rules": { | ||
"compiler-version": ["error", ">=0.8.0"], | ||
"avoid-low-level-calls": "off", | ||
"no-inline-assembly": "off", | ||
"func-visibility": ["warn", { "ignoreConstructors": true }], | ||
"no-empty-blocks": "off", | ||
"func-name-mixedcase": "warn", | ||
"no-complex-fallback": "off" | ||
} | ||
} |
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,35 @@ | ||
# World end to end testing suite | ||
|
||
This package contains scripts intended to perform end to end tests for the game chain contracts. | ||
|
||
|
||
# How to test | ||
1. Make sure you have a blockchain node available pointing to a blockchain with the game chain contracts installed. | ||
2. Make sure enviornment values are set for your target environment. | ||
2.1. `.env.local` and `.env.devnet` are available in the root of this package. | ||
3. Run your tests by invoking npm scripts. | ||
|
||
|
||
The npm scripts follow a naming convention for a `<FUNCTIONALIT>:<ENVIRONMENT>` e.g. in order to create a smart character on local chain you can run: | ||
|
||
```bash | ||
pnpm run createSmartCharacter:local | ||
|
||
``` | ||
|
||
|
||
# Environment values | ||
Environment values are used for external values that we are dependant on the target environment. | ||
Test paramameters should should not be defined as environment variables for reproduceability purposes. | ||
## PRIVATE_KEY | ||
The `PRIVATE_KEY` variable should be a 32 bytes/256 bits data represented as a 64 hexadecimal character string. | ||
|
||
Note: The Externally owned account (EOA) for which this private key belongs to will become the owner of entities created by the test scripts. | ||
## RPC_URL | ||
|
||
A valid url for the RPC endpoint of the target environment. | ||
|
||
## WORLD_ADDRESS | ||
|
||
A hexadecimal string representing the EVM address of the Mud world smart contract entry point. | ||
|
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 @@ | ||
[profile.default] | ||
solc = "0.8.24" | ||
evm_version="cancun" | ||
ffi = false | ||
fuzz_runs = 256 | ||
optimizer = true | ||
optimizer_runs = 300 | ||
verbosity = 2 | ||
src = 'script' | ||
out = 'out' | ||
|
||
|
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,38 @@ | ||
{ | ||
"name": "end-to-end-tests-v2", | ||
"version": "0.0.0", | ||
"private": true, | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "forge build", | ||
"clean": "rm -rf src/codegen && rm -rf out && rm -rf cache", | ||
"createSmartCharacter:ci": "RPC_URL=$RPC_URL WORLD_ADDRESS=$WORLD_ADDRESS PRIVATE_KEY=$PRIVATE_KEY forge script script/CreateSmartCharacter.s.sol:CreateSmartCharacter --fork-url $RPC_URL --private-key $PRIVATE_KEY --broadcast --sig \"run(address)\" $WORLD_ADDRESS -vvv", | ||
"createSmartCharacter:local": "source ./.env.local && RPC_URL=$RPC_URL WORLD_ADDRESS=$WORLD_ADDRESS PRIVATE_KEY=$PRIVATE_KEY forge script script/CreateSmartCharacter.s.sol:CreateSmartCharacter --fork-url $RPC_URL --private-key $PRIVATE_KEY --broadcast --sig \"run(address)\" $WORLD_ADDRESS -vvv", | ||
"createSmartCharacter:devnet": "source ./.env.devnet && PRIVATE_KEY=$PRIVATE_KEY forge script script/CreateSmartCharacter.s.sol:CreateSmartCharacter --fork-url $RPC_URL --private-key $PRIVATE_KEY --broadcast --sig \"run(address)\" $WORLD_ADDRESS -vvv", | ||
"lint": "pnpm run prettier && pnpm run solhint", | ||
"prettier": "prettier '**/*.sol' --plugin=prettier-plugin-solidity --check", | ||
"fixFormat": "prettier '**/*.sol' --plugin=prettier-plugin-solidity --write", | ||
"solhint": "solhint --config ./.solhint.json 'src/**/*.sol'" | ||
}, | ||
"dependencies": { | ||
"@eveworld/world-v2": "link:../mud-contracts/world-v2", | ||
"@latticexyz/cli": "2.0.12", | ||
"@latticexyz/gas-report": "2.0.12", | ||
"@latticexyz/schema-type": "2.0.12", | ||
"@latticexyz/store": "2.0.12", | ||
"@latticexyz/world": "2.0.12", | ||
"@latticexyz/world-modules": "2.0.12" | ||
}, | ||
"devDependencies": { | ||
"@types/debug": "4.1.7", | ||
"@types/node": "^18.15.11", | ||
"@types/prettier": "2.7.2", | ||
"ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", | ||
"forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", | ||
"prettier": "^2.6.2", | ||
"prettier-plugin-solidity": "1.1.3", | ||
"solhint": "^3.3.7", | ||
"solhint-config-mud": "2.0.12", | ||
"solhint-plugin-mud": "2.0.12" | ||
} | ||
} |
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,5 @@ | ||
ds-test/=node_modules/ds-test/src/ | ||
forge-std/=node_modules/forge-std/src/ | ||
@latticexyz/=node_modules/@latticexyz/ | ||
@eveworld/=node_modules/@eveworld/ | ||
|
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,51 @@ | ||
pragma solidity >=0.8.24; | ||
|
||
import { Script } from "forge-std/Script.sol"; | ||
import { console } from "forge-std/console.sol"; | ||
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; | ||
import { ResourceId, WorldResourceIdLib } from "@latticexyz/world/src/WorldResourceId.sol"; | ||
import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol"; | ||
|
||
import { EntityRecordData, EntityMetadata } from "@eveworld/world-v2/src/systems/entity-record/types.sol"; | ||
import { SmartCharacterSystem } from "@eveworld/world-v2/src/systems/smart-character/SmartCharacterSystem.sol"; | ||
import { Utils as SmartCharacterUtils } from "@eveworld/world-v2/src/systems/smart-character/Utils.sol"; | ||
|
||
contract CreateSmartCharacter is Script { | ||
using SmartCharacterUtils for bytes14; | ||
|
||
function run(address worldAddress) public { | ||
StoreSwitch.setStoreAddress(worldAddress); | ||
// Load the private key from the `PRIVATE_KEY` environment variable (in .env) | ||
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
vm.startBroadcast(deployerPrivateKey); | ||
IBaseWorld world = IBaseWorld(worldAddress); | ||
|
||
// Test values for creating the smart character | ||
uint256 characterId = 123; | ||
address characterAddress = vm.addr(deployerPrivateKey); | ||
EntityRecordData memory entityRecord = EntityRecordData({ | ||
entityId: characterId, | ||
typeId: 123, | ||
itemId: 234, | ||
volume: 100 | ||
}); | ||
|
||
EntityMetadata memory entityRecordMetadata = EntityMetadata({ | ||
entityId: characterId, | ||
name: "name", | ||
dappURL: "dappURL", | ||
description: "description" | ||
}); | ||
|
||
ResourceId systemId = SmartCharacterUtils.smartCharacterSystemId(); | ||
world.call( | ||
systemId, | ||
abi.encodeCall( | ||
SmartCharacterSystem.createCharacter, | ||
(characterId, characterAddress, entityRecord, entityRecordMetadata) | ||
) | ||
); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -7,14 +7,14 @@ | |
"build": "mud build", | ||
"clean": "forge clean && rm -rf src/codegen && rm -rf out && rm -rf cache", | ||
"deploy:garnet": "mud deploy --profile=garnet", | ||
"deploy:local": "mud deploy", | ||
"deploy:local": "mud deploy --rpc $RPC_URL --alwaysRunPostDeploy", | ||
"deploy:redstone": "mud deploy --profile=redstone", | ||
"dev": "mud dev-contracts", | ||
"lint": "pnpm run prettier && pnpm run solhint", | ||
"prettier": "prettier 'src/**/*.sol' 'test/**/*.sol' './*.ts' --plugin=prettier-plugin-solidity --check", | ||
"fixFormat": "prettier 'src/**/*.sol' 'test/**/*' './*.ts' --plugin=prettier-plugin-solidity --write", | ||
"solhint": "solhint --config ./.solhint.json 'src/**/*.sol' --fix", | ||
"test": "tsc --noEmit && mud test" | ||
"test": "tsc --noEmit && mud test " | ||
}, | ||
"dependencies": { | ||
"@latticexyz/cli": "2.0.12", | ||
|
@@ -24,6 +24,7 @@ | |
"@latticexyz/world-modules": "2.0.12" | ||
}, | ||
"devDependencies": { | ||
"@latticexyz/gas-report": "2.0.12", | ||
"@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", | ||
|
@@ -42,4 +43,4 @@ | |
"[email protected]": ">=4.4.1" | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.