Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contracts: wrapped resources #1704

Merged
merged 23 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
983088c
contracts: wrapped resources
credence0x Sep 23, 2024
ddc102c
contracts: wrapped resources
credence0x Sep 23, 2024
068c336
del
credence0x Sep 23, 2024
d478f1e
del
credence0x Sep 23, 2024
a594b45
contracts: remove unused code
credence0x Sep 23, 2024
20daf82
contracts: ensure resources can only be bridged in through banks
credence0x Sep 23, 2024
acbbc9e
contracts: abstraction
credence0x Sep 23, 2024
9286215
contracts: fix test
credence0x Sep 23, 2024
f7b86cb
contracts: resource bridge: update
credence0x Sep 26, 2024
38ec117
prettier
credence0x Sep 26, 2024
37de0a3
fix test
credence0x Sep 26, 2024
ecabbd8
contracts: fix test
credence0x Sep 27, 2024
2788315
minor refactor
credence0x Sep 30, 2024
711e478
Merge branch 'rc' into resource-factory
credence0x Oct 2, 2024
ba5bc2d
Merge branch 'rc' into resource-factory
credence0x Oct 7, 2024
12f7cf4
acarb fmt
credence0x Oct 7, 2024
21d0954
Merge branch 'rc' of github.com:BibliothecaDAO/eternum into resource-…
edisontim Oct 7, 2024
5bab5f1
Merge branch 'rc' of github.com:BibliothecaDAO/eternum into resource-…
edisontim Oct 8, 2024
145eb51
Merge branch 'rc' of github.com:BibliothecaDAO/eternum into resource-…
edisontim Oct 9, 2024
4139b59
fix prettier
edisontim Oct 9, 2024
f426a66
Merge branch 'rc' of https://github.com/BibliothecaDAO/eternum into r…
credence0x Oct 9, 2024
93f809c
fix
credence0x Oct 9, 2024
03842c9
fix client build
credence0x Oct 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions contracts/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,91 @@ dependencies = [
"alexandria_math",
"cubit",
"dojo",
"openzeppelin",
]

[[package]]
name = "openzeppelin"
version = "0.15.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.15.0#f57642960f1c8cffafefb88bfff418eca8510634"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_governance",
"openzeppelin_introspection",
"openzeppelin_presets",
"openzeppelin_security",
"openzeppelin_token",
"openzeppelin_upgrades",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_access"
version = "0.15.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.15.0#f57642960f1c8cffafefb88bfff418eca8510634"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_account"
version = "0.15.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.15.0#f57642960f1c8cffafefb88bfff418eca8510634"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_token",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_governance"
version = "0.15.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.15.0#f57642960f1c8cffafefb88bfff418eca8510634"
dependencies = [
"openzeppelin_access",
"openzeppelin_introspection",
]

[[package]]
name = "openzeppelin_introspection"
version = "0.15.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.15.0#f57642960f1c8cffafefb88bfff418eca8510634"

[[package]]
name = "openzeppelin_presets"
version = "0.15.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.15.0#f57642960f1c8cffafefb88bfff418eca8510634"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_introspection",
"openzeppelin_token",
"openzeppelin_upgrades",
]

[[package]]
name = "openzeppelin_security"
version = "0.15.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.15.0#f57642960f1c8cffafefb88bfff418eca8510634"

[[package]]
name = "openzeppelin_token"
version = "0.15.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.15.0#f57642960f1c8cffafefb88bfff418eca8510634"
dependencies = [
"openzeppelin_account",
"openzeppelin_governance",
"openzeppelin_introspection",
]

[[package]]
name = "openzeppelin_upgrades"
version = "0.15.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.15.0#f57642960f1c8cffafefb88bfff418eca8510634"

[[package]]
name = "openzeppelin_utils"
version = "0.15.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.15.0#f57642960f1c8cffafefb88bfff418eca8510634"
2 changes: 1 addition & 1 deletion contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-alpha.12" }
alexandria_math = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "e1b080577aaa6889116fc8be5dde72b2fd21e397" }
alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "e1b080577aaa6889116fc8be5dde72b2fd21e397" }
cubit = { git = "https://github.com/dojoengine/cubit", branch = "cairo_2.7" }

openzeppelin = {git = "https://github.com/openzeppelin/cairo-contracts", tag="v0.15.0"}
[[target.dojo]]

[tool.fmt]
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/models/combat.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use eternum::models::resources::{
use eternum::models::structure::{Structure, StructureCustomImpl};
use eternum::models::weight::Weight;
use eternum::models::weight::WeightCustomTrait;
use eternum::systems::resources::contracts::resource_systems::{InternalResourceSystemsImpl};
use eternum::systems::resources::contracts::resource_systems::resource_systems::{InternalResourceSystemsImpl};
use eternum::utils::math::{PercentageImpl, PercentageValueImpl, min, max};
use eternum::utils::number::NumberTrait;

Expand Down
39 changes: 39 additions & 0 deletions contracts/src/models/config.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,42 @@ pub struct HasClaimedStartingResources {
config_id: ID,
claimed: bool,
}


#[dojo::model]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
struct ResourceBridgeConfig {
#[key]
config_id: ID,
deposit_paused: bool,
withdraw_paused: bool,
}

#[dojo::model]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
struct ResourceBridgeFeeSplitConfig {
#[key]
config_id: ID,
// the percentage of the deposit and withdrawal amount that the velords addr will receive
velords_fee_on_dpt_percent: u16,
velords_fee_on_wtdr_percent: u16,
// the percentage of the deposit and withdrawal amount that the season pool will receive
season_pool_fee_on_dpt_percent: u16,
season_pool_fee_on_wtdr_percent: u16,
// the percentage of the deposit and withdrawal amount that the frontend provider will receive
client_fee_on_dpt_percent: u16,
client_fee_on_wtdr_percent: u16,
// the address that will receive the velords fee percentage
velords_fee_recipient: ContractAddress,
// the address that will receive the season pool fee
season_pool_fee_recipient: ContractAddress,
}


#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct ResourceBridgeWhitelistConfig {
#[key]
token: ContractAddress,
resource_type: u8
}
5 changes: 2 additions & 3 deletions contracts/src/models/resources.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,8 @@ impl ResourceFoodImpl of ResourceFoodTrait {
impl ResourceCustomImpl of ResourceCustomTrait {
fn get(world: IWorldDispatcher, key: (ID, u8)) -> Resource {
let mut resource: Resource = get!(world, key, Resource);
if resource.entity_id == 0 {
return resource;
};
assert!(resource.resource_type.is_non_zero(), "resource type not found");
assert!(resource.entity_id.is_non_zero(), "entity id not found");

resource.harvest(world);
return resource;
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/systems/bank/contracts/bank.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod bank_systems {
use eternum::models::position::{Position, Coord};
use eternum::models::resources::{Resource, ResourceCustomImpl};
use eternum::models::structure::{Structure, StructureCategory, StructureCount, StructureCountCustomTrait};
use eternum::systems::resources::contracts::resource_systems::{InternalResourceSystemsImpl};
use eternum::systems::resources::contracts::resource_systems::resource_systems::{InternalResourceSystemsImpl};

use traits::Into;

Expand Down
2 changes: 1 addition & 1 deletion contracts/src/systems/combat/contracts.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ mod combat_systems {
AttackingArmyQuantityTrackerCustomImpl,
},
};
use eternum::systems::resources::contracts::resource_systems::{InternalResourceSystemsImpl};
use eternum::systems::resources::contracts::resource_systems::resource_systems::{InternalResourceSystemsImpl};
use eternum::systems::transport::contracts::travel_systems::travel_systems::{InternalTravelSystemsImpl};

use eternum::utils::math::{PercentageValueImpl, PercentageImpl};
Expand Down
54 changes: 52 additions & 2 deletions contracts/src/systems/config/contracts.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use dojo::world::IWorldDispatcher;
use eternum::alias::ID;
use eternum::models::buildings::BuildingCategory;
use eternum::models::combat::{Troops};
use eternum::models::config::{TroopConfig, MapConfig, BattleConfig, MercenariesConfig, CapacityConfig};
use eternum::models::config::{
TroopConfig, MapConfig, BattleConfig, MercenariesConfig, CapacityConfig, ResourceBridgeConfig,
ResourceBridgeFeeSplitConfig, ResourceBridgeWhitelistConfig
};
use eternum::models::position::Coord;

#[dojo::interface]
Expand Down Expand Up @@ -132,6 +135,16 @@ trait IMercenariesConfig {
fn set_mercenaries_config(ref world: IWorldDispatcher, troops: Troops, rewards: Span<(u8, u128)>);
}

#[dojo::interface]
trait IResourceBridgeConfig {
fn set_resource_bridge_config(ref world: IWorldDispatcher, resource_bridge_config: ResourceBridgeConfig);
fn set_resource_bridge_fee_split_config(
ref world: IWorldDispatcher, resource_bridge_fee_split_config: ResourceBridgeFeeSplitConfig
);
fn set_resource_bridge_whitelist_config(
ref world: IWorldDispatcher, resource_bridge_whitelist_config: ResourceBridgeWhitelistConfig
);
}

#[dojo::contract]
mod config_systems {
Expand All @@ -149,7 +162,8 @@ mod config_systems {
CapacityConfig, SpeedConfig, WeightConfig, WorldConfig, LevelingConfig, RealmFreeMintConfig, MapConfig,
TickConfig, ProductionConfig, BankConfig, TroopConfig, BuildingConfig, BuildingCategoryPopConfig,
PopulationConfig, HyperstructureResourceConfig, HyperstructureConfig, StaminaConfig, StaminaRefillConfig,
MercenariesConfig, BattleConfig, TravelStaminaCostConfig
MercenariesConfig, BattleConfig, TravelStaminaCostConfig, ResourceBridgeConfig, ResourceBridgeFeeSplitConfig,
ResourceBridgeWhitelistConfig
};

use eternum::models::position::{Position, PositionCustomTrait, Coord};
Expand Down Expand Up @@ -570,4 +584,40 @@ mod config_systems {
set!(world, (MercenariesConfig { config_id: WORLD_CONFIG_ID, troops, rewards }));
}
}

impl IResourceBridgeConfig of super::IResourceBridgeConfig<ContractState> {
fn set_resource_bridge_config(ref world: IWorldDispatcher, mut resource_bridge_config: ResourceBridgeConfig) {
assert_caller_is_admin(world);

resource_bridge_config.config_id = WORLD_CONFIG_ID;
set!(world, (resource_bridge_config));
}

fn set_resource_bridge_fee_split_config(
ref world: IWorldDispatcher, mut resource_bridge_fee_split_config: ResourceBridgeFeeSplitConfig
) {
assert_caller_is_admin(world);

resource_bridge_fee_split_config.config_id = WORLD_CONFIG_ID;
set!(world, (resource_bridge_fee_split_config));
}

fn set_resource_bridge_whitelist_config(
ref world: IWorldDispatcher, mut resource_bridge_whitelist_config: ResourceBridgeWhitelistConfig
) {
assert_caller_is_admin(world);

// note: if we are whitelisting a NEW resource type, we WILL need to
// update several functions related to resources in `eternum::constants`
// so the new resource type is recognized throughout the contract.

assert!(resource_bridge_whitelist_config.resource_type > 0, "resource type should be non zero");
assert!(
resource_bridge_whitelist_config.resource_type <= 255,
"the system only supports at most 255 resource types"
);

set!(world, (resource_bridge_whitelist_config));
}
}
}
2 changes: 1 addition & 1 deletion contracts/src/systems/map/contracts.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mod map_systems {
use eternum::models::stamina::StaminaCustomImpl;
use eternum::models::structure::{Structure, StructureCategory, StructureCount, StructureCountCustomTrait};
use eternum::systems::combat::contracts::combat_systems::{InternalCombatImpl};
use eternum::systems::resources::contracts::resource_systems::{InternalResourceSystemsImpl};
use eternum::systems::resources::contracts::resource_systems::resource_systems::{InternalResourceSystemsImpl};
use eternum::systems::transport::contracts::travel_systems::travel_systems::{InternalTravelSystemsImpl};
use eternum::utils::map::biomes::{Biome, get_biome};
use eternum::utils::random;
Expand Down
Loading
Loading