Skip to content

Commit

Permalink
fix: use hardhat as node (better logs) and make hardhat compatible wi…
Browse files Browse the repository at this point in the history
…th forge (#54)

* fix: wip

* chore: wip

* fix: add hardhat fork compatible with foundry deploy

* feat: with playerJoinFacet and persona

* fix: remove sketchy stuff

* fix: reset hardhat gas fee after deploying contracts with forge

* fix: self-review

* fix: self-review

Co-authored-by: Andy Cernera <kooshaba@gmail.com>
  • Loading branch information
alvrs and Kooshaba authored Jul 6, 2022
1 parent 781a42c commit 45a5981
Show file tree
Hide file tree
Showing 9 changed files with 1,252 additions and 139 deletions.
2 changes: 1 addition & 1 deletion packages/network/src/workers/Sync.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class SyncWorker<Cm extends Components> implements DoWork<SyncWorkerConfi

// No client mapping for this component contract
if (!clientComponentKey) {
console.warn("Received unknown component update", componentId);
console.warn("Received unknown component update", componentId, componentAddress);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function createNetworkLayer(config?: NetworkLayerConfig) {
Stamina: defineComponent(
world,
{ current: Type.Number, max: Type.Number, regeneration: Type.Number },
{ id: "Stamina", metadata: { contractId: keccak256("ember.component.personaComponent") } }
{ id: "Stamina", metadata: { contractId: keccak256("ember.component.staminaComponent") } }
),
LastActionTurn: defineComponent(
world,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function renderUIComponent(layers: Layers, key: string, { requirement, re

return (
<UIComponentContainer key={`component-${key}`} gridConfig={gridConfig}>
{render(state)};
{render(state)}
</UIComponentContainer>
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ri/contracts/deploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
]
},
{
"name": "CastSpellFacet",
"functions": ["castSpell"]
"name": "PlayerJoinFacet",
"functions": ["joinGame"]
}
]
}
27 changes: 0 additions & 27 deletions packages/ri/contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { HardhatUserConfig } from "hardhat/config";
import "hardhat-deploy";
import "@nomiclabs/hardhat-ethers";
import "./tasks/compile";

const degen = {
live: true,
Expand Down Expand Up @@ -51,14 +48,6 @@ const hardhat = {

const config: HardhatUserConfig = {
defaultNetwork: "hardhat",
namedAccounts: {
deployer: 0, // first skey derived from the hd wallet
user1: 1,
user2: 2,
},
paths: {
sources: "./src",
},
networks: {
degen,
localhost,
Expand All @@ -73,22 +62,6 @@ const config: HardhatUserConfig = {
},
},
},
external: {
contracts: [
{
artifacts: "@latticexyz/persona/abi",
},
],
},
deterministicDeployment: {
"4242": {
factory: "0xC39496f108A05b8111Ae5B283c114CfB0327B359",
deployer: "0x16820E675fF74dC1DfB0a21f8735c291eEE61F1f",
funding: "1000000000",
signedTx:
"0xf8a78085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3822147a0339736b46d151775b8649857c91ecc36b2e7f1c6fb78a07c8794abcb1ca5c826a002ddd269b8268ceeec100c69a4b467086a0f9541d29d979285cd0976c10d9963",
},
},
};

export default config;
13 changes: 9 additions & 4 deletions packages/ri/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
"solhint": "solhint --config ./.solhint.json 'src/**/*.sol' --fix",
"test": "forge test",
"----- BUILD/DEPLOY -----": "---------------------------",
"start": "run-p -l anvil:node deploy:local",
"start": "run-p -l hardhat:node deploy:hardhat",
"build": "yarn codegen && rimraf out && forge build --force && yarn dist && yarn types",
"dist": "rimraf abi && mkdir abi && bash exports.sh && yarn mud diamond-abi",
"deploy:local": "yarn mud deploy --deployerPrivateKey 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
"deploy:anvil": "wait-on tcp:8545 && yarn mud deploy --deployerPrivateKey 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
"deploy:hardhat": "wait-on tcp:8545 && yarn mud deploy --deployerPrivateKey 0x044C7963E9A89D4F8B64AB23E02E97B2E00DD57FCB60F316AC69B77135003AEF && yarn hardhat:resetfee",
"deploy:degen": "yarn mud deploy -i --deployerPrivateKey 0x044C7963E9A89D4F8B64AB23E02E97B2E00DD57FCB60F316AC69B77135003AEF",
"types": "rimraf types && typechain --target=ethers-v5 abi/*.json",
"anvil:node": "anvil -b 1 -vvvv",
"anvil:node": "anvil -b 1 --block-base-fee-per-gas 0",
"hardhat:node": "hardhat node",
"hardhat:resetfee": "curl -X POST localhost:8545 -H \"Content-Type: application/json\" --data '{\"jsonrpc\": \"2.0\", \"method\": \"hardhat_setNextBlockBaseFeePerGas\", \"params\": [\"0x0\"], \"id\": 1 }'",
"forge:deploy": "yarn codegen && forge script ./src/test/utils/BroadcastDeploy.sol --target-contract Deploy --broadcast -vvv",
"codegen": "yarn ejs src/libraries/LibDeploy.ejs -f deploy.json -o src/libraries/LibDeploy.sol"
},
Expand All @@ -43,6 +46,7 @@
"ethers": "^5.6.6",
"forge-std": "https://github.com/foundry-rs/forge-std.git#4d36e3f7e2168c8155c641eb0f80e85cd584bd1c",
"glob": "^8.0.3",
"hardhat": "https://gitpkg.now.sh/latticexyz/hardhat/packages/hardhat-core?build",
"memmove": "https://github.com/brockelmore/memmove.git#d577ecd1bc43656f4032edf4daa9797f756a8ad2",
"npm-run-all": "^4.1.5",
"openzeppelin-solidity": "https://github.com/OpenZeppelin/openzeppelin-contracts.git#57725120581e27ec469e1c7e497a4008aafff818",
Expand All @@ -54,5 +58,6 @@
"typechain": "^7.0.1",
"typescript": "^4.6.2",
"wait-on": "^6.0.1"
}
},
"dependencies": {}
}
19 changes: 7 additions & 12 deletions packages/ri/contracts/src/libraries/LibDeploy.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Cheats } from "../test/utils/Cheats.sol";

// ECS
import { World } from "solecs/World.sol";
import { Component } from "solecs/Component.sol";

// Diamonds
import { Diamantaire } from "../diamond/Diamantaire.sol";
Expand Down Expand Up @@ -70,7 +71,7 @@ library LibDeploy {

bytes4[] memory functionSelectors;

IDiamondCut.FacetCut[] memory diamondCut = new IDiamondCut.FacetCut[](4);
IDiamondCut.FacetCut[] memory diamondCut = new IDiamondCut.FacetCut[](<%= facets.length -%>);

// ------------------------
// Add facets
Expand Down Expand Up @@ -127,8 +128,12 @@ library LibDeploy {

// Deploy each component and transfer ownership to the diamond contract
if(!_reuseComponents) {
Component comp;
<% components.forEach(component => { -%>
(new <%= component %>(address(result.world))).transferOwnership(diamondAddress);
console.log("Deploying <%= component %>");
comp = new <%= component %>(address(result.world));
console.log(address(comp));
comp.transferOwnership(diamondAddress);
<% });%>
}

Expand All @@ -141,16 +146,6 @@ library LibDeploy {

// Register access controllers
InitializeFacet(diamondAddress).registerAccessControllerExternally(address(new PersonaAccessController()));

// Register content creators
InitializeFacet(diamondAddress).registerContentCreatorExternally(address(new SpellContentCreator()));

// Register embodied systems
address createEntityFromPrototypeEmbodiedSystem = address(new CreateEntityFromPrototypeEmbodiedSystem());
InitializeFacet(diamondAddress).registerEmbodiedSystemExternally(
createEntityFromPrototypeEmbodiedSystem,
CreateEntityFromPrototypeEmbodiedSystem.createEntityFromPrototype.selector
);
}
}
}
92 changes: 63 additions & 29 deletions packages/ri/contracts/src/libraries/LibDeploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Cheats } from "../test/utils/Cheats.sol";

// ECS
import { World } from "solecs/World.sol";
import { Component } from "solecs/Component.sol";

// Diamonds
import { Diamantaire } from "../diamond/Diamantaire.sol";
Expand All @@ -19,7 +20,7 @@ import { AppStorage, Config } from "../libraries/LibAppStorage.sol";
import { InitializeFacet } from "../facets/InitializeFacet.sol";
import { EmberFacet } from "../facets/EmberFacet.sol";
import { DebugFacet } from "../facets/DebugFacet.sol";
import { CastSpellFacet } from "../facets/CastSpellFacet.sol";
import { PlayerJoinFacet } from "../facets/PlayerJoinFacet.sol";

// Components
import { EmbodiedSystemArgumentComponent } from "../components/EmbodiedSystemArgumentComponent.sol";
Expand Down Expand Up @@ -131,14 +132,14 @@ library LibDeploy {
functionSelectors: functionSelectors
});

// Add CastSpellFacet
CastSpellFacet _CastSpellFacet = new CastSpellFacet();
// Add PlayerJoinFacet
PlayerJoinFacet _PlayerJoinFacet = new PlayerJoinFacet();

functionSelectors = new bytes4[](1);
functionSelectors[0] = CastSpellFacet.castSpell.selector;
functionSelectors[0] = PlayerJoinFacet.joinGame.selector;

diamondCut[3] = IDiamondCut.FacetCut({
facetAddress: address(_CastSpellFacet),
facetAddress: address(_PlayerJoinFacet),
action: action,
functionSelectors: functionSelectors
});
Expand Down Expand Up @@ -178,20 +179,63 @@ library LibDeploy {

// Deploy each component and transfer ownership to the diamond contract
if (!_reuseComponents) {
(new EmbodiedSystemArgumentComponent(address(result.world))).transferOwnership(diamondAddress);
(new EntityTypeComponent(address(result.world))).transferOwnership(diamondAddress);
(new GameConfigComponent(address(result.world))).transferOwnership(diamondAddress);
(new LastActionTurnComponent(address(result.world))).transferOwnership(diamondAddress);
(new LearnedSpellsComponent(address(result.world))).transferOwnership(diamondAddress);
(new MaxDistanceComponent(address(result.world))).transferOwnership(diamondAddress);
(new MineableComponent(address(result.world))).transferOwnership(diamondAddress);
(new MovableComponent(address(result.world))).transferOwnership(diamondAddress);
(new OwnedByComponent(address(result.world))).transferOwnership(diamondAddress);
(new PersonaComponent(address(result.world))).transferOwnership(diamondAddress);
(new PositionComponent(address(result.world))).transferOwnership(diamondAddress);
(new SpellComponent(address(result.world))).transferOwnership(diamondAddress);
(new StaminaComponent(address(result.world))).transferOwnership(diamondAddress);
(new UntraversableComponent(address(result.world))).transferOwnership(diamondAddress);
Component comp;
console.log("Deploying EmbodiedSystemArgumentComponent");
comp = new EmbodiedSystemArgumentComponent(address(result.world));
console.log(address(comp));
comp.transferOwnership(diamondAddress);
console.log("Deploying EntityTypeComponent");
comp = new EntityTypeComponent(address(result.world));
console.log(address(comp));
comp.transferOwnership(diamondAddress);
console.log("Deploying GameConfigComponent");
comp = new GameConfigComponent(address(result.world));
console.log(address(comp));
comp.transferOwnership(diamondAddress);
console.log("Deploying LastActionTurnComponent");
comp = new LastActionTurnComponent(address(result.world));
console.log(address(comp));
comp.transferOwnership(diamondAddress);
console.log("Deploying LearnedSpellsComponent");
comp = new LearnedSpellsComponent(address(result.world));
console.log(address(comp));
comp.transferOwnership(diamondAddress);
console.log("Deploying MaxDistanceComponent");
comp = new MaxDistanceComponent(address(result.world));
console.log(address(comp));
comp.transferOwnership(diamondAddress);
console.log("Deploying MineableComponent");
comp = new MineableComponent(address(result.world));
console.log(address(comp));
comp.transferOwnership(diamondAddress);
console.log("Deploying MovableComponent");
comp = new MovableComponent(address(result.world));
console.log(address(comp));
comp.transferOwnership(diamondAddress);
console.log("Deploying OwnedByComponent");
comp = new OwnedByComponent(address(result.world));
console.log(address(comp));
comp.transferOwnership(diamondAddress);
console.log("Deploying PersonaComponent");
comp = new PersonaComponent(address(result.world));
console.log(address(comp));
comp.transferOwnership(diamondAddress);
console.log("Deploying PositionComponent");
comp = new PositionComponent(address(result.world));
console.log(address(comp));
comp.transferOwnership(diamondAddress);
console.log("Deploying SpellComponent");
comp = new SpellComponent(address(result.world));
console.log(address(comp));
comp.transferOwnership(diamondAddress);
console.log("Deploying StaminaComponent");
comp = new StaminaComponent(address(result.world));
console.log(address(comp));
comp.transferOwnership(diamondAddress);
console.log("Deploying UntraversableComponent");
comp = new UntraversableComponent(address(result.world));
console.log(address(comp));
comp.transferOwnership(diamondAddress);
}

// ------------------------
Expand All @@ -203,16 +247,6 @@ library LibDeploy {

// Register access controllers
InitializeFacet(diamondAddress).registerAccessControllerExternally(address(new PersonaAccessController()));

// Register content creators
InitializeFacet(diamondAddress).registerContentCreatorExternally(address(new SpellContentCreator()));

// Register embodied systems
address createEntityFromPrototypeEmbodiedSystem = address(new CreateEntityFromPrototypeEmbodiedSystem());
InitializeFacet(diamondAddress).registerEmbodiedSystemExternally(
createEntityFromPrototypeEmbodiedSystem,
CreateEntityFromPrototypeEmbodiedSystem.createEntityFromPrototype.selector
);
}
}
}
Loading

0 comments on commit 45a5981

Please sign in to comment.