Skip to content

Commit

Permalink
chore: upgrade all world-chain-contracts v1 packages to MUD version 2…
Browse files Browse the repository at this point in the history
….2.3 (#181)

A large overhaul for all V1 contracts to catch-up to the latest version
of MUD:

- all @latticexyz packages upgraded to version `2.2.3`
- implemented` intialMsgSender()` context capture as a customWorld
contract named `WorldWithEntryContext.sol`
- all relevant contract/test/config changes to accommodate the above
updates
  - adding the term `System` to the end of all systems
  - `mud.config `updates for table declarations and custom world
- deploying `/core` `DelegationControlSystem` and `ForwarderSystem` into
a non-root namespace
- updating unit tests to use `MudTest.sol` instead of the basic forge
`Test.sol`
- cleanup and standardise unit tests
- removed `tableId` parameters from Table calls 
- adjusted System-to-System APPROVED access logic to be configurable per
System
- update the `InventoryAccess.s.sol` script to accommodate access logic
changes

---------

Co-authored-by: CCP Legolas <[email protected]>
  • Loading branch information
ccp-tezza and 0xxlegolas authored Sep 21, 2024
1 parent cd5efa2 commit eb7eb3d
Show file tree
Hide file tree
Showing 217 changed files with 9,022 additions and 11,972 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
**/dist
# Worlds.json
**/worlds.json
.mud

.nx/cache
.DS_Store
Expand Down
Binary file added EVEFrontierCover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# World Chain Contracts

![Project Awakening cover logo](./ProjectAwakeningCover.png)
![EVE Frontier cover logo](./EVEFrontierCover.png)

This repository contains the smart contract code supporting Project Awakening and targeted for deployment to the world chain. It contains of two separate code paths. The standard contracts are plain solidity contracts intended as support structure. The mud contracts are the functionality or *business logic* itself.
This repository contains the smart contract code supporting EVE Frontier and targeted for deployment to the world chain. It contains of two separate code paths. The standard contracts are plain solidity contracts intended as support structure. The mud contracts are the functionality or *business logic* itself.

# Quickstart

Expand Down Expand Up @@ -32,7 +32,7 @@ In the example above the method being invoked belongs to a system in the root na

# Running with docker

You can also run a deployer image for the Awakening world against a local node to replicate the world in a local environment.
You can also run a deployer image for the EVE Frontier world against a local node to replicate the world in a local environment.

Pull the latest released docker image: Current version [0.0.7](https://github.com/projectawakening/world-chain-contracts/pkgs/container/world-chain-deployer-image/220295954?tag=0.0.7)
```bash
Expand Down
2 changes: 1 addition & 1 deletion end-to-end-tests-v2/.env.local
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
RPC_URL=http://127.0.0.1:8545


WORLD_ADDRESS=0x036a9e1e4c46449ffd9e7b9d0321395b9096be0c
WORLD_ADDRESS=

16 changes: 8 additions & 8 deletions end-to-end-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@
"@eveworld/smart-object-framework": "link:../mud-contracts/smart-object-framework",
"@eveworld/world": "link:../mud-contracts/world",
"@eveworld/world-core": "link:../mud-contracts/core",
"@latticexyz/cli": "2.0.0-transaction-context-98ef570f",
"@latticexyz/gas-report": "2.0.0-transaction-context-98ef570f",
"@latticexyz/schema-type": "2.0.0-transaction-context-98ef570f",
"@latticexyz/store": "2.0.0-transaction-context-98ef570f",
"@latticexyz/world": "2.0.0-transaction-context-98ef570f",
"@latticexyz/world-modules": "2.0.0-transaction-context-98ef570f"
"@latticexyz/cli": "2.2.3",
"@latticexyz/gas-report": "2.2.3",
"@latticexyz/schema-type": "2.2.3",
"@latticexyz/store": "2.2.3",
"@latticexyz/world": "2.2.3",
"@latticexyz/world-modules": "2.2.3"
},
"devDependencies": {
"@types/debug": "4.1.7",
Expand All @@ -70,7 +70,7 @@
"prettier": "^2.6.2",
"prettier-plugin-solidity": "1.1.3",
"solhint": "^3.3.7",
"solhint-config-mud": "2.0.0-transaction-context-98ef570f",
"solhint-plugin-mud": "2.0.0-transaction-context-98ef570f"
"solhint-config-mud": "2.2.3",
"solhint-plugin-mud": "2.2.3"
}
}
7 changes: 2 additions & 5 deletions end-to-end-tests/script/BringOnline.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ contract BringOnline is Script {
uint256 smartObjectId = uint256(keccak256(abi.encode("item:<tenant_id>-<db_id>-2345")));

// check global state and resume if needed
if (GlobalDeployableState.getIsPaused(FRONTIER_WORLD_DEPLOYMENT_NAMESPACE.globalStateTableId()) == false) {
if (GlobalDeployableState.getIsPaused() == false) {
smartDeployable.globalResume();
}

// check fuel and add fuel if needed
DeployableFuelBalanceData memory data = DeployableFuelBalance.get(
FRONTIER_WORLD_DEPLOYMENT_NAMESPACE.deployableFuelBalanceTableId(),
smartObjectId
);
DeployableFuelBalanceData memory data = DeployableFuelBalance.get(smartObjectId);
uint256 FUEL_DECIMALS = 18;
if (data.fuelAmount < 10 ** FUEL_DECIMALS) {
smartDeployable.depositFuel(smartObjectId, 200000);
Expand Down
2 changes: 1 addition & 1 deletion end-to-end-tests/script/ConfigureSmartGate.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ contract ConfigureSmartGate is Script {
);

// check global state and resume if needed
if (GlobalDeployableState.getIsPaused(FRONTIER_WORLD_DEPLOYMENT_NAMESPACE.globalStateTableId()) == false) {
if (GlobalDeployableState.getIsPaused() == false) {
smartDeployable.globalResume();
}

Expand Down
18 changes: 12 additions & 6 deletions end-to-end-tests/script/ConfigureSmartTurret.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.8.20;
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 { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol";
import { IBaseWorld } from "@eveworld/world/src/codegen/world/IWorld.sol";
import { RESOURCE_SYSTEM } from "@latticexyz/world/src/worldResourceTypes.sol";
import { System } from "@latticexyz/world/src/System.sol";
Expand All @@ -22,6 +22,7 @@ contract ConfigureSmartTurret is Script {
using SmartTurretLib for SmartTurretLib.World;
using SmartDeployableLib for SmartDeployableLib.World;
using SmartDeployableUtils for bytes14;
using WorldResourceIdInstance for ResourceId;

function run(address worldAddress) public {
StoreSwitch.setStoreAddress(worldAddress);
Expand Down Expand Up @@ -55,7 +56,7 @@ contract ConfigureSmartTurret is Script {
);

// check global state and resume if needed
if (GlobalDeployableState.getIsPaused(FRONTIER_WORLD_DEPLOYMENT_NAMESPACE.globalStateTableId()) == false) {
if (GlobalDeployableState.getIsPaused() == false) {
smartDeployable.globalResume();
}

Expand All @@ -65,16 +66,19 @@ contract ConfigureSmartTurret is Script {
//Derploy the Mock contract and configure the smart turret to use it
IBaseWorld world = IBaseWorld(worldAddress);
SmartTurretTestSystem smartTurretTestSystem = new SmartTurretTestSystem();
ResourceId smartTurretTestSystemId = ResourceId.wrap(
(bytes32(abi.encodePacked(RESOURCE_SYSTEM, FRONTIER_WORLD_DEPLOYMENT_NAMESPACE, "SmartTurretTestS")))
);
ResourceId smartTurretTestSystemId = WorldResourceIdLib.encode({
typeId: RESOURCE_SYSTEM,
namespace: "testnamespace",
name: "SmartTurretTestS"
});

// register the smart turret system
world.registerNamespace(smartTurretTestSystemId.getNamespaceId());
world.registerSystem(smartTurretTestSystemId, smartTurretTestSystem, true);
//register the function selector
world.registerFunctionSelector(
smartTurretTestSystemId,
"inProximity(uint256, TargetPriority[],Turret,SmartTurretTarget)"
"inProximity(uint256,uint256,((uint256,uint256,uint256,uint256,uint256,uint256),uint256)[],(uint256,uint256,uint256),(uint256,uint256,uint256,uint256,uint256,uint256))"
);
smartTurret.configureSmartTurret(smartObjectId, smartTurretTestSystemId);

Expand Down Expand Up @@ -111,6 +115,7 @@ contract ConfigureSmartTurret is Script {
contract SmartTurretTestSystem is System {
function inProximity(
uint256 smartTurretId,
uint256 turretOwnerCharacterId,
TargetPriority[] memory priorityQueue,
Turret memory turret,
SmartTurretTarget memory turretTarget
Expand All @@ -121,6 +126,7 @@ contract SmartTurretTestSystem is System {

function aggression(
uint256 smartTurretId,
uint256 turretOwnerCharacterId,
TargetPriority[] memory priorityQueue,
Turret memory turret,
SmartTurretTarget memory aggressor,
Expand Down
2 changes: 0 additions & 2 deletions end-to-end-tests/script/CreateAndDeposit.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ contract CreateAndDeposit is Script {
vm.startBroadcast(ownerPrivateKey);
// check if SSU has any items to transfer and if not create them with SmartStorageUnit.createAndDepositItemsToInventory
InventoryItemTableData memory invItemToTransfer = InventoryItemTable.get(
DEPLOYMENT_NAMESPACE.inventoryItemTableId(),
smartObjectId,
invItems[0].inventoryItemId
);
Expand All @@ -83,7 +82,6 @@ contract CreateAndDeposit is Script {
}
// check if EPH INV has items to transfer and if not create them with SmartStorageUnit.createAndDepositItemsToEphemeralInventory(
EphemeralInvItemTableData memory ephInvItemToTransfer = EphemeralInvItemTable.get(
DEPLOYMENT_NAMESPACE.ephemeralInventoryItemTableId(),
smartObjectId,
ephInvItems[0].inventoryItemId,
ephemeralOwner
Expand Down
7 changes: 1 addition & 6 deletions end-to-end-tests/script/Transfer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,10 @@ contract Transfer is Script {
// SSU owner should have 1 ephInvItem after transfer
// Ephermeral owner should have 1 invItem after transfer

InventoryItemTableData memory ephItemInInv = InventoryItemTable.get(
DEPLOYMENT_NAMESPACE.inventoryItemTableId(),
smartObjectId,
ephInvItems[0].inventoryItemId
);
InventoryItemTableData memory ephItemInInv = InventoryItemTable.get(smartObjectId, ephInvItems[0].inventoryItemId);
console.log(ephItemInInv.quantity); //1

EphemeralInvItemTableData memory itemInEphInv = EphemeralInvItemTable.get(
DEPLOYMENT_NAMESPACE.ephemeralInventoryItemTableId(),
smartObjectId,
invItems[0].inventoryItemId,
ephemeralOwner
Expand Down
1 change: 0 additions & 1 deletion end-to-end-tests/script/WithdrawFromEphemeral.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ contract WithdrawFromEphemeral is Script {
inventory.withdrawFromEphemeralInventory(smartObjectId, ephemeralOwner2, items);

EphemeralInvItemTableData memory invItem = EphemeralInvItemTable.get(
FRONTIER_WORLD_DEPLOYMENT_NAMESPACE.ephemeralInventoryItemTableId(),
smartObjectId,
items[0].inventoryItemId,
ephemeralOwner2
Expand Down
18 changes: 3 additions & 15 deletions end-to-end-tests/script/WithdrawFromInventory.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,11 @@ contract WithdrawFromInventory is Script {

inventory.withdrawFromInventory(smartObjectId, items);

InventoryItemTableData memory inventoryItem1 = InventoryItemTable.get(
FRONTIER_WORLD_DEPLOYMENT_NAMESPACE.inventoryItemTableId(),
smartObjectId,
items[0].inventoryItemId
);
InventoryItemTableData memory inventoryItem2 = InventoryItemTable.get(
FRONTIER_WORLD_DEPLOYMENT_NAMESPACE.inventoryItemTableId(),
smartObjectId,
items[1].inventoryItemId
);
InventoryItemTableData memory inventoryItem1 = InventoryItemTable.get(smartObjectId, items[0].inventoryItemId);
InventoryItemTableData memory inventoryItem2 = InventoryItemTable.get(smartObjectId, items[1].inventoryItemId);

console.log(inventoryItem1.quantity);
InventoryItemTableData memory inventoryItem3 = InventoryItemTable.get(
FRONTIER_WORLD_DEPLOYMENT_NAMESPACE.inventoryItemTableId(),
smartObjectId,
items[2].inventoryItemId
);
InventoryItemTableData memory inventoryItem3 = InventoryItemTable.get(smartObjectId, items[2].inventoryItemId);

console.log(inventoryItem1.quantity);
console.log(inventoryItem2.quantity);
Expand Down
10 changes: 5 additions & 5 deletions mud-contracts/common/constants/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"version": "0.0.12",
"license": "MIT",
"dependencies": {
"@latticexyz/cli": "2.0.0-transaction-context-98ef570f",
"@latticexyz/schema-type": "2.0.0-transaction-context-98ef570f",
"@latticexyz/store": "2.0.0-transaction-context-98ef570f",
"@latticexyz/world": "2.0.0-transaction-context-98ef570f",
"@latticexyz/world-modules": "2.0.0-transaction-context-98ef570f"
"@latticexyz/cli": "2.2.3",
"@latticexyz/schema-type": "2.2.3",
"@latticexyz/store": "2.2.3",
"@latticexyz/world": "2.2.3",
"@latticexyz/world-modules": "2.2.3"
}
}
26 changes: 13 additions & 13 deletions mud-contracts/common/constants/src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
"KILL_MAIL_DEPLOYMENT": "eveworld"
},
"systemName": {
"ENTITY_CORE": "EntityCore",
"MODULE_CORE": "ModuleCore",
"HOOK_CORE": "HookCore",
"STATIC_DATA": "StaticData",
"ENTITY_RECORD": "EntityRecord",
"LOCATION": "Location",
"SMART_CHARACTER": "SmartCharacter",
"SMART_DEPLOYABLE": "SmartDeployable",
"ENTITY_SYSTEM": "EntitySystem",
"MODULE_SYSTEM": "ModuleSystem",
"HOOK_SYSTEM": "HookSystem",
"STATIC_DATA": "StaticDataSystem",
"ENTITY_RECORD": "EntityRecordSyst",
"LOCATION": "LocationSystem",
"SMART_CHARACTER": "SmartCharacterSy",
"SMART_DEPLOYABLE": "SmartDeployableS",
"SMART_STORAGE_UNIT": "SmartStorageUnit",
"INVENTORY": "Inventory",
"EPHEMERAL_INVENTORY": "EphemeralInv",
"INVENTORY": "InventorySystem",
"EPHEMERAL_INVENTORY": "EphemeralInvSyst",
"INVENTORY_INTERACT": "InventoryInterac",
"SMART_TURRET": "SmartTurret",
"SMART_GATE": "SmartGate",
"KILL_MAIL": "KillMail",
"SMART_TURRET": "SmartTurretSyste",
"SMART_GATE": "SmartGateSystem",
"KILL_MAIL": "KillMailSystem",
"ACCESS": "AccessSystem"
}
}
25 changes: 12 additions & 13 deletions mud-contracts/common/constants/src/constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,21 @@ bytes14 constant SMART_STORAGE_UNIT_DEPLOYMENT_NAMESPACE = "eveworld";
bytes14 constant SMART_TURRET_DEPLOYMENT_NAMESPACE = "eveworld";
bytes14 constant SMART_GATE_DEPLOYMENT_NAMESPACE = "eveworld";

bytes16 constant ENTITY_CORE_SYSTEM_NAME = "EntityCore";
bytes16 constant MODULE_CORE_SYSTEM_NAME = "ModuleCore";
bytes16 constant HOOK_CORE_SYSTEM_NAME = "HookCore";
bytes16 constant STATIC_DATA_SYSTEM_NAME = "StaticData";
bytes16 constant ENTITY_RECORD_SYSTEM_NAME = "EntityRecord";
bytes16 constant LOCATION_SYSTEM_NAME = "Location";
bytes16 constant SMART_CHARACTER_SYSTEM_NAME = "SmartCharacter";
bytes16 constant ENTITY_SYSTEM_NAME = "EntitySystem";
bytes16 constant MODULE_SYSTEM_NAME = "ModuleSystem";
bytes16 constant HOOK_SYSTEM_NAME = "HookSystem";
bytes16 constant STATIC_DATA_SYSTEM_NAME = "StaticDataSystem";
bytes16 constant ENTITY_RECORD_SYSTEM_NAME = "EntityRecordSyst";
bytes16 constant LOCATION_SYSTEM_NAME = "LocationSystem";
bytes16 constant SMART_CHARACTER_SYSTEM_NAME = "SmartCharacterSy";
bytes16 constant ERC721_SYSTEM_NAME = "ERC721System";
bytes16 constant SMART_DEPLOYABLE_SYSTEM_NAME = "SmartDeployable";
bytes16 constant SMART_DEPLOYABLE_SYSTEM_NAME = "SmartDeployableS";
bytes16 constant SMART_STORAGE_UNIT_SYSTEM_NAME = "SmartStorageUnit";
bytes16 constant INVENTORY_SYSTEM_NAME = "Inventory";
bytes16 constant EPHEMERAL_INVENTORY_SYSTEM_NAME = "EphemeralInv";
bytes16 constant INVENTORY_SYSTEM_NAME = "InventorySystem";
bytes16 constant EPHEMERAL_INVENTORY_SYSTEM_NAME = "EphemeralInvSyst";
bytes16 constant INVENTORY_INTERACT_SYSTEM_NAME = "InventoryInterac";
bytes16 constant SMART_TURRET_SYSTEM_NAME = "SmartTurret";
bytes16 constant SMART_GATE_SYSTEM_NAME = "SmartGate";
bytes16 constant ACCESS_CONTROL_SYSTEM_NAME = "AccessControlSys";
bytes16 constant SMART_TURRET_SYSTEM_NAME = "SmartTurretSyste";
bytes16 constant SMART_GATE_SYSTEM_NAME = "SmartGateSystem";
bytes16 constant ACCESS_SYSTEM_NAME = "AccessSystem";

//Constants for Entity
Expand Down
1 change: 1 addition & 0 deletions mud-contracts/core/.solhintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/src/WorldWithEntryContext.sol
32 changes: 26 additions & 6 deletions mud-contracts/core/mud.config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
import { mudConfig } from "@latticexyz/world/register";
import { defineWorld } from "@latticexyz/world";
import constants = require("./node_modules/@eveworld/common-constants/src/constants.json");

export default mudConfig({
export default defineWorld({
namespace: constants.namespace.FRONTIER_WORLD_DEPLOYMENT,
deploy: {
customWorld: {
sourcePath: "src/WorldWithEntryContext.sol",
name: "WorldWithEntryContext",
},
},
systems: {
DelegationControlSystem: {
name: "DelegationContro",
openAccess: true,
},
ForwarderSystem: {
name: "ForwarderSystem",
openAccess: true,
},
},
tables: {
GlobalStaticData: {
keySchema: {
schema: {
trustedForwarder: "address",
value: "bool",
},
valueSchema: "bool",
key: ["trustedForwarder"],
},
Role: {
keySchema: {
schema: {
role: "bytes32",
value: "address",
},
valueSchema: "address",
key: ["role"],
},
},
});
20 changes: 10 additions & 10 deletions mud-contracts/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
"test": "tsc --noEmit && mud test"
},
"dependencies": {
"@latticexyz/cli": "2.0.0-transaction-context-98ef570f",
"@latticexyz/schema-type": "2.0.0-transaction-context-98ef570f",
"@latticexyz/store": "2.0.0-transaction-context-98ef570f",
"@latticexyz/world": "2.0.0-transaction-context-98ef570f",
"@latticexyz/world-modules": "2.0.0-transaction-context-98ef570f",
"@latticexyz/cli": "2.2.3",
"@latticexyz/schema-type": "2.2.3",
"@latticexyz/store": "2.2.3",
"@latticexyz/world": "2.2.3",
"@latticexyz/world-modules": "2.2.3",
"@eveworld/common-constants": "link:../common/constants",
"@eveworld/smart-object-framework": "link:../smart-object-framework",
"@eveworld/world": "link:../world"
Expand All @@ -33,11 +33,11 @@
"@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",
"prettier": "^2.6.2",
"prettier-plugin-solidity": "1.1.3",
"prettier": "3.2.5",
"prettier-plugin-solidity": "1.3.1",
"solhint": "^3.3.7",
"solhint-config-mud": "2.0.0-transaction-context-98ef570f",
"solhint-plugin-mud": "2.0.0-transaction-context-98ef570f",
"solhint-config-mud": "2.2.3",
"solhint-plugin-mud": "2.2.3",
"typescript": "^5.4.5"
}
}
}
Loading

0 comments on commit eb7eb3d

Please sign in to comment.