diff --git a/crates/contracts/src/lib.cairo b/crates/contracts/src/lib.cairo index c0ede36..5feaacc 100644 --- a/crates/contracts/src/lib.cairo +++ b/crates/contracts/src/lib.cairo @@ -87,7 +87,7 @@ pub mod world { mod iworld; pub use iworld::{ IWorld, IWorldDispatcher, IWorldDispatcherTrait, IUpgradeableWorld, - IUpgradeableWorldDispatcher, IUpgradeableWorldDispatcherTrait + IUpgradeableWorldDispatcher, IUpgradeableWorldDispatcherTrait, get_world_address, get_world }; #[cfg(target: "test")] diff --git a/crates/contracts/src/world/iworld.cairo b/crates/contracts/src/world/iworld.cairo index 46c7b98..8c63a82 100644 --- a/crates/contracts/src/world/iworld.cairo +++ b/crates/contracts/src/world/iworld.cairo @@ -3,9 +3,28 @@ use dojo::meta::Layout; use dojo::model::{ModelIndex, ResourceMetadata}; use starknet::{ClassHash, ContractAddress}; - +use starknet::{ + SyscallResultTrait, syscalls::{storage_read_syscall}, + storage_access::{storage_base_address_from_felt252, storage_address_from_base} +}; +const WORLD_ADDRESS_STORAGE_ADDRESS: felt252 = + 0x01704e5494cfadd87ce405d38a662ae6a1d354612ea0ebdc9fefdeb969065774; use super::resource::Resource; +pub fn get_world_address() -> ContractAddress { + storage_read_syscall( + 0, + storage_address_from_base(storage_base_address_from_felt252(WORLD_ADDRESS_STORAGE_ADDRESS)) + ) + .unwrap_syscall() + .try_into() + .unwrap() +} + +pub fn get_world() -> IWorldDispatcher { + IWorldDispatcher { contract_address: get_world_address() } +} + #[starknet::interface] pub trait IUpgradeableWorld { /// Upgrades the world with new_class_hash.