Skip to content

Commit

Permalink
upgraded builder examples with world v0.0.17 changes (#37)
Browse files Browse the repository at this point in the history
* upgrading gate keeper to the latest version

* upgraded item-seller version

* upgrade item trade contract to latest world version

* updating mock-data to latest world version

* upgrade smart gate to latest world version

* upgraded smart turret to latest world version

* upgraded vending machine to latest world contracts

* add the smartcharacter lib
  • Loading branch information
0xxlegolas authored Sep 28, 2024
1 parent 62b672e commit 0e6a8c3
Show file tree
Hide file tree
Showing 54 changed files with 2,172 additions and 438 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,30 @@ cd item-seller
cat readme.md
```

### Bonus TIP
**Run the local indexer, explore, interact and observe the state changes using world explorer**

From any of the example root folder run the below command to run a local world explorer to see all the state changes

```sh
builder-examples/gate-keeper/
pnpm explorer <worldAddress>
```

eg: `pnpm explorer 0x8a791620dd6260079bf849dc5567adc3f2fdc318`

It looks like this

![alt text](readme-imgs/explorer.png)


![alt text](readme-imgs/explorer-view.png)


You can interact in the inteact tab and explore the values in the explore tab and also query using SQL commands

![alt text](readme-imgs/query.png)

## Guides
### Smart Turret: [View](./smart-turret/readme.md)
Configure and deploy a Smart Turret smart contract, ready to be further developed.
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ services:

world-deployer:
container_name: world-deployer
image: ghcr.io/projectawakening/world-chain-deployer-image:0.0.16
image: ghcr.io/projectawakening/world-chain-deployer-image:0.0.17
platform: linux/amd64
depends_on:
foundry:
Expand Down
6 changes: 3 additions & 3 deletions gate-keeper/packages/contracts/.mud/local/systems.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
"name": "GateKeeperSystem",
"systemId": "0x73797465737400000000000000000000476174654b656570657253797374656d",
"abi": [
"error Inventory_InvalidItem(string message, uint256 typeId)",
"error Inventory_InvalidItem(string message, uint256 inventoryItemId)",
"function changeTargetQuantity(uint256 smartObjectId, uint256 inventoryItemId, uint256 targetQuantity)",
"function configureGateKeeper(uint256 smartObjectId, uint256 inventoryItemId, uint256 targetItemQuantity)",
"function depositToSSU(uint256 smartObjectId, uint256 quantity)",
"function getContractAddress() returns (address)",
"function getGateKeeperConfig(uint256 smartObjectId) returns ((uint256 itemIn, uint256 targetItemQuantity, bool isGoalReached))"
],
"worldAbi": [
"error Inventory_InvalidItem(string message, uint256 typeId)",
"error Inventory_InvalidItem(string message, uint256 inventoryItemId)",
"function test__changeTargetQuantity(uint256 smartObjectId, uint256 inventoryItemId, uint256 targetQuantity)",
"function test__configureGateKeeper(uint256 smartObjectId, uint256 inventoryItemId, uint256 targetItemQuantity)",
"function test__depositToSSU(uint256 smartObjectId, uint256 quantity)",
Expand All @@ -24,5 +24,5 @@
]
}
],
"createdAt": 1727190063475
"createdAt": 1727456005359
}
2 changes: 1 addition & 1 deletion gate-keeper/packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"dependencies": {
"@eveworld/common-constants": "0.0.13",
"@eveworld/world": "0.0.16",
"@eveworld/world": "0.0.17",
"@latticexyz/cli": "2.2.9",
"@latticexyz/schema-type": "2.2.9",
"@latticexyz/store": "2.2.9",
Expand Down
12 changes: 12 additions & 0 deletions gate-keeper/packages/contracts/script/DepositToSSU.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.

import { Utils } from "../src/systems/gate_keeper/Utils.sol";
import { GateKeeperSystem } from "../src/systems/gate_keeper/GateKeeperSystem.sol";
import { EphemeralInvItemTableData, EphemeralInvItemTable } from "@eveworld/world/src/codegen/tables/EphemeralInvItemTable.sol";

contract DepositToSSU is Script {
function run(address worldAddress) external {
Expand All @@ -19,12 +20,23 @@ contract DepositToSSU is Script {
IBaseWorld world = IBaseWorld(worldAddress);

uint256 smartStorageUnitId = vm.envUint("SSU_ID");
uint256 inventoryItemId = vm.envUint("INVENTORY_ITEM_ID");
uint256 quantity = 9; // test value

ResourceId systemId = Utils.gateKeeperSystemId();

EphemeralInvItemTableData memory invItem = EphemeralInvItemTable.get(
smartStorageUnitId,
inventoryItemId,
vm.addr(playerPrivateKey)
);
console.log(invItem.quantity); //15

//The method below will change based on the namespace you have configurd. If the namespace is changed, make sure to update the method name
world.call(systemId, abi.encodeCall(GateKeeperSystem.depositToSSU, (smartStorageUnitId, quantity)));

invItem = EphemeralInvItemTable.get(smartStorageUnitId, inventoryItemId, vm.addr(playerPrivateKey));
console.log(invItem.quantity); //6
vm.stopBroadcast();
}
}
19 changes: 19 additions & 0 deletions gate-keeper/packages/contracts/script/MockSsuData.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@ import { FRONTIER_WORLD_DEPLOYMENT_NAMESPACE } from "@eveworld/common-constants/
import { GlobalDeployableState } from "@eveworld/world/src/codegen/tables/GlobalDeployableState.sol";
import { SmartStorageUnitLib } from "@eveworld/world/src/modules/smart-storage-unit/SmartStorageUnitLib.sol";
import { EntityRecordLib } from "@eveworld/world/src/modules/entity-record/EntityRecordLib.sol";
import { SmartCharacterLib } from "@eveworld/world/src/modules/smart-character/SmartCharacterLib.sol";
import { EntityRecordData as CharacterEntityRecord } from "@eveworld/world/src/modules/smart-character/types.sol";
import { EntityRecordOffchainTableData } from "@eveworld/world/src/codegen/tables/EntityRecordOffchainTable.sol";

contract MockSsuData is Script {
using SmartDeployableLib for SmartDeployableLib.World;
using SmartStorageUnitLib for SmartStorageUnitLib.World;
using EntityRecordLib for EntityRecordLib.World;
using SmartCharacterLib for SmartCharacterLib.World;
using SmartDeployableUtils for bytes14;

SmartDeployableLib.World smartDeployable;
SmartStorageUnitLib.World smartStorageUnit;
EntityRecordLib.World entityRecord;
SmartCharacterLib.World smartCharacter;

function run(address worldAddress) public {
StoreSwitch.setStoreAddress(worldAddress);
Expand All @@ -51,6 +56,20 @@ contract MockSsuData is Script {
namespace: FRONTIER_WORLD_DEPLOYMENT_NAMESPACE
});

smartCharacter = SmartCharacterLib.World({
iface: IBaseWorld(worldAddress),
namespace: FRONTIER_WORLD_DEPLOYMENT_NAMESPACE
});

smartCharacter.createCharacter(
1250081923,
player,
22662,
CharacterEntityRecord({ typeId: 123, itemId: 234, volume: 100 }),
EntityRecordOffchainTableData({ name: "harryporter", dappURL: "noURL", description: "." }),
""
);

uint256 smartStorageUnitId = vm.envUint("SSU_ID");
uint256 inventoryItem = vm.envUint("INVENTORY_ITEM_ID");
createAnchorAndOnline(smartStorageUnitId, player, inventoryItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Utils as SmartDeployableUtils } from "@eveworld/world/src/modules/smart
import { Utils as InventoryUitls } from "@eveworld/world/src/modules/inventory/Utils.sol";
import { FRONTIER_WORLD_DEPLOYMENT_NAMESPACE as DEPLOYMENT_NAMESPACE } from "@eveworld/common-constants/src/constants.sol";
import { EphemeralInvItemTableData, EphemeralInvItemTable } from "@eveworld/world/src/codegen/tables/EphemeralInvItemTable.sol";
import { TransferItem } from "@eveworld/world/src/modules/inventory/types.sol";

import { GateKeeperConfig, GateKeeperConfigData } from "../../codegen/tables/GateKeeperConfig.sol";

Expand Down Expand Up @@ -102,17 +103,10 @@ contract GateKeeperSystem is System {
revert IInventoryErrors.Inventory_InvalidItem("GateKeeper: item is not created on-chain", entityInRecord.itemId);
}

InventoryItem[] memory inItems = new InventoryItem[](1);
inItems[0] = InventoryItem(
gatekeeperConfig.itemIn,
_msgSender(),
entityInRecord.itemId,
entityInRecord.typeId,
entityInRecord.volume,
quantity
);

_inventoryLib().ephemeralToInventoryTransfer(smartObjectId, inItems);
TransferItem[] memory ephInvTransferItems = new TransferItem[](1);
ephInvTransferItems[0] = TransferItem(gatekeeperConfig.itemIn, _msgSender(), quantity);

_inventoryLib().ephemeralToInventoryTransfer(smartObjectId, ephInvTransferItems);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions gate-keeper/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion item-seller/packages/contracts/.env
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SSU_ID=0649628243651142495531168912546043385862592837062164755938498896191863454
##### ITEM SELLER CONFIGURATION
#ITEM ID 77800 - Common Ore
INVENTORY_ITEM_ID=1235
ERC20_TOKEN_ADDRESS=0xC2bbBEA3CFF4b942b5B66E95CA4A80A817e7d29e
ERC20_TOKEN_ADDRESS=0x609CdC61471B76fF8544118740162b35564a19D5
RECEIVER_ADDRESS=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
##PRICE SHOULD BE IN WEI
PRICE_IN_WEI=500000000000000000
6 changes: 3 additions & 3 deletions item-seller/packages/contracts/.mud/local/systems.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"name": "ItemSellerSystem",
"systemId": "0x737974657374000000000000000000004974656d53656c6c657253797374656d",
"abi": [
"error Inventory_InvalidItem(string message, uint256 typeId)",
"error Inventory_InvalidItem(string message, uint256 inventoryItemId)",
"function collectTokens(uint256 smartObjectId)",
"function getContractAddress() returns (address)",
"function getERC20Data(uint256 smartObjectId) returns ((address tokenAddress, uint256 tokenDecimals, address receiver))",
Expand All @@ -19,7 +19,7 @@
"function updateERC20Receiver(uint256 smartObjectId, address receiver)"
],
"worldAbi": [
"error Inventory_InvalidItem(string message, uint256 typeId)",
"error Inventory_InvalidItem(string message, uint256 inventoryItemId)",
"function test__collectTokens(uint256 smartObjectId)",
"function test__getContractAddress() returns (address)",
"function test__getERC20Data(uint256 smartObjectId) returns ((address tokenAddress, uint256 tokenDecimals, address receiver))",
Expand All @@ -32,5 +32,5 @@
]
}
],
"createdAt": 1727188028548
"createdAt": 1727459566464
}
2 changes: 1 addition & 1 deletion item-seller/packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"dependencies": {
"@eveworld/common-constants": "0.0.13",
"@eveworld/world": "0.0.16",
"@eveworld/world": "0.0.17",
"@latticexyz/cli": "2.2.9",
"@latticexyz/schema-type": "2.2.9",
"@latticexyz/store": "2.2.9",
Expand Down
22 changes: 22 additions & 0 deletions item-seller/packages/contracts/script/MockSsuData.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ import { EntityRecordData, WorldPosition, SmartObjectData, Coord } from "@evewor
import { FRONTIER_WORLD_DEPLOYMENT_NAMESPACE } from "@eveworld/common-constants/src/constants.sol";
import { GlobalDeployableState } from "@eveworld/world/src/codegen/tables/GlobalDeployableState.sol";
import { SmartStorageUnitLib } from "@eveworld/world/src/modules/smart-storage-unit/SmartStorageUnitLib.sol";
import { SmartCharacterLib } from "@eveworld/world/src/modules/smart-character/SmartCharacterLib.sol";
import { EntityRecordData as CharacterEntityRecord } from "@eveworld/world/src/modules/smart-character/types.sol";
import { EntityRecordOffchainTableData } from "@eveworld/world/src/codegen/tables/EntityRecordOffchainTable.sol";
import { CharactersByAddressTable } from "@eveworld/world/src/codegen/tables/CharactersByAddressTable.sol";

contract MockSsuData is Script {
using SmartDeployableLib for SmartDeployableLib.World;
using SmartStorageUnitLib for SmartStorageUnitLib.World;
using SmartCharacterLib for SmartCharacterLib.World;
using SmartDeployableUtils for bytes14;

SmartDeployableLib.World smartDeployable;
SmartStorageUnitLib.World smartStorageUnit;
SmartCharacterLib.World smartCharacter;

function run(address worldAddress) public {
StoreSwitch.setStoreAddress(worldAddress);
Expand All @@ -43,6 +49,22 @@ contract MockSsuData is Script {
namespace: FRONTIER_WORLD_DEPLOYMENT_NAMESPACE
});

smartCharacter = SmartCharacterLib.World({
iface: IBaseWorld(worldAddress),
namespace: FRONTIER_WORLD_DEPLOYMENT_NAMESPACE
});

if (CharactersByAddressTable.get(player) == 0) {
smartCharacter.createCharacter(
11111166565,
player,
1005555,
CharacterEntityRecord({ typeId: 123, itemId: 234, volume: 100 }),
EntityRecordOffchainTableData({ name: "harryporter", dappURL: "noURL", description: "." }),
""
);
}

uint256 smartStorageUnitId = vm.envUint("SSU_ID");
uint256 inventoryItem = vm.envUint("INVENTORY_ITEM_ID");
createAnchorAndOnline(smartStorageUnitId, player, inventoryItem);
Expand Down
13 changes: 6 additions & 7 deletions item-seller/packages/contracts/script/PostDeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ contract PostDeploy is Script {
vm.startBroadcast(deployerPrivateKey);

//Deploy a fake ERC20 token
string memory namespace = "test1erc20";
string memory namespace = "testerc20";
string memory name = "Test Token";
string memory symbol = "TEST";
uint8 decimals = uint8(18);
address to = address(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266);
uint256 amount = 10000000000;
IERC20Mintable erc20Token;
StoreSwitch.setStoreAddress(address(worldAddress));
erc20Token = registerERC20(

IERC20Mintable erc20Token;
StoreSwitch.setStoreAddress(address(worldAddress));
erc20Token = registerERC20(
world,
stringToBytes14(namespace),
ERC20MetadataData({ decimals: decimals, name: name, symbol: symbol })
);

console.log("Deploying ERC20 token with address: ", address(erc20Token));
console.log("Deploying ERC20 token with address: ", address(erc20Token));

address erc20Address = address(erc20Token);

Expand All @@ -53,7 +53,6 @@ contract PostDeploy is Script {
console.log("minting to: ", address(to));
console.log("amount: ", amount * 1 ether);


vm.stopBroadcast();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { FRONTIER_WORLD_DEPLOYMENT_NAMESPACE as DEPLOYMENT_NAMESPACE } from "@ev
import { ItemSellerERC20, ItemSellerERC20Data } from "../../codegen/tables/ItemSellerERC20.sol";
import { ItemPrice, ItemPriceData } from "../../codegen/tables/ItemPrice.sol";
import { Utils as ItemSellerUtils } from "./Utils.sol";
import { TransferItem } from "@eveworld/world/src/modules/inventory/types.sol";

/**
* @dev This contract is an example for extending Inventory functionality from game.
Expand Down Expand Up @@ -126,17 +127,10 @@ contract ItemSellerSystem is System {
revert IInventoryErrors.Inventory_InvalidItem("ItemSeller: item is not created on-chain", itemOutEntity.itemId);
}

InventoryItem[] memory outItems = new InventoryItem[](1);
outItems[0] = InventoryItem(
inventoryItemId,
_msgSender(),
itemOutEntity.itemId,
itemOutEntity.typeId,
itemOutEntity.volume,
quantity
);

_inventoryLib().inventoryToEphemeralTransfer(smartObjectId, outItems);
TransferItem[] memory transferItems = new TransferItem[](1);
transferItems[0] = TransferItem(inventoryItemId, _msgSender(), quantity);

_inventoryLib().inventoryToEphemeralTransfer(smartObjectId, _msgSender(), transferItems);
}

/**
Expand Down
Loading

0 comments on commit 0e6a8c3

Please sign in to comment.