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

#[dojo::contract] for tokens #21

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 12 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Origami CI
on: [push, pull_request]

env:
DOJO_VERSION: v0.3.14
DOJO_VERSION: v0.3.15
SCARB_VERSION: v2.3.1

jobs:
Expand Down Expand Up @@ -73,3 +73,14 @@ jobs:
- name: Test
run: sozo test -f hex_map
shell: bash

token:
needs: [check, build]
runs-on: ubuntu-latest
name: Test token
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- name: Test
run: sozo test -f token
shell: bash
4 changes: 2 additions & 2 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ source = "git+https://github.com/influenceth/cubit?rev=b459053#b4590530d5aeae9aa

[[package]]
name = "dojo"
version = "0.3.14"
source = "git+https://github.com/dojoengine/dojo?tag=v0.3.14#d7e9788459f3b2e797b6565f1057c96a6f5f8cc2"
version = "0.3.15"
source = "git+https://github.com/dojoengine/dojo?tag=v0.3.15#cdbaca4121b1642e1a8ca40d6831bad73d28ed26"
dependencies = [
"dojo_plugin",
]
Expand Down
2 changes: 1 addition & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ authors = ["bal7hazar@proton.me"]

[workspace.dependencies]
cubit = { git = "https://github.com/influenceth/cubit", rev = "b459053" }
dojo = { git = "https://github.com/dojoengine/dojo", tag = "v0.3.14" }
dojo = { git = "https://github.com/dojoengine/dojo", tag = "v0.3.15" }
origami = { path = "crates" }
15 changes: 5 additions & 10 deletions token/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,20 @@ version = 1

[[package]]
name = "dojo"
version = "0.3.4"
source = "git+https://github.com/dojoengine/dojo.git?rev=d62ec8a#d62ec8a522f92d0a0ccf226c6e929bb918b31128"
version = "0.3.15"
source = "git+https://github.com/dojoengine/dojo?tag=v0.3.15#cdbaca4121b1642e1a8ca40d6831bad73d28ed26"
dependencies = [
"dojo_plugin",
]

[[package]]
name = "dojo_plugin"
version = "0.3.4"
version = "0.3.11"
source = "git+https://github.com/dojoengine/dojo?tag=v0.3.11#1e651b5d4d3b79b14a7d8aa29a92062fcb9e6659"

[[package]]
name = "openzeppelin"
version = "0.8.0-beta.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?rev=4eafccf#4eafccf107f98d975b20cbb6544b2a998e5f403f"

[[package]]
name = "presets"
name = "token"
version = "0.0.0"
dependencies = [
"dojo",
"openzeppelin",
]
2 changes: 1 addition & 1 deletion token/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ description = "Implementations of ERC standards for the Dojo framework."
homepage = "https://github.com/dojoengine/origami/tree/presets"

[dependencies]
dojo.workspace = true
dojo.workspace = true
21 changes: 2 additions & 19 deletions token/src/erc1155/erc1155.cairo
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
#[starknet::contract]
#[dojo::contract]
mod ERC1155 {
use token::erc1155::models::{ERC1155Meta, ERC1155OperatorApproval, ERC1155Balance};
use token::erc1155::interface;
use token::erc1155::interface::{IERC1155, IERC1155CamelOnly};
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};
use starknet::ContractAddress;
use starknet::{get_caller_address, get_contract_address};
use array::ArrayTCloneImpl;
use zeroable::Zeroable;
use debug::PrintTrait;

#[storage]
struct Storage {
_world: ContractAddress,
}

#[event]
#[derive(Clone, Drop, starknet::Event)]
enum Event {
Expand Down Expand Up @@ -62,14 +56,7 @@ mod ERC1155 {
}

#[constructor]
fn constructor(
ref self: ContractState,
world: ContractAddress,
name: felt252,
symbol: felt252,
base_uri: felt252,
) {
self._world.write(world);
fn constructor(ref self: ContractState, name: felt252, symbol: felt252, base_uri: felt252,) {
self.initializer(name, symbol, base_uri);
}

Expand Down Expand Up @@ -209,10 +196,6 @@ mod ERC1155 {

#[generate_trait]
impl WorldInteractionsImpl of WorldInteractionsTrait {
fn world(self: @ContractState) -> IWorldDispatcher {
IWorldDispatcher { contract_address: self._world.read() }
}

fn get_meta(self: @ContractState) -> ERC1155Meta {
get!(self.world(), get_contract_address(), ERC1155Meta)
}
Expand Down
8 changes: 4 additions & 4 deletions token/src/erc1155/tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use token::erc1155::models::{
ERC1155Meta, erc_1155_meta, ERC1155OperatorApproval, erc_1155_operator_approval, ERC1155Balance,
erc_1155_balance
};
use token::erc1155::ERC1155::_worldContractMemberStateTrait;
use token::erc1155::ERC1155::world_dispatcherContractMemberStateTrait;
use debug::PrintTrait;

//
Expand All @@ -38,7 +38,7 @@ fn STATE() -> (IWorldDispatcher, ERC1155::ContractState) {
]
);
let mut state = ERC1155::contract_state_for_testing();
state._world.write(world.contract_address);
state.world_dispatcher.write(world);

InternalImpl::_mint(ref state, OWNER(), TOKEN_ID, TOKEN_AMOUNT);
utils::drop_event(ZERO());
Expand All @@ -51,7 +51,7 @@ fn STATE() -> (IWorldDispatcher, ERC1155::ContractState) {

fn setup() -> ERC1155::ContractState {
let (world, mut state) = STATE();
ERC1155::constructor(ref state, world.contract_address, NAME, SYMBOL, URI);
ERC1155::constructor(ref state, NAME, SYMBOL, URI);
utils::drop_event(ZERO());
state
}
Expand All @@ -64,7 +64,7 @@ fn setup() -> ERC1155::ContractState {
#[available_gas(20000000)]
fn test_constructor() {
let (world, mut state) = STATE();
ERC1155::constructor(ref state, world.contract_address, NAME, SYMBOL, URI);
ERC1155::constructor(ref state, NAME, SYMBOL, URI);

assert(ERC1155MetadataImpl::name(@state) == NAME, 'Name should be NAME');
assert(ERC1155MetadataImpl::symbol(@state) == SYMBOL, 'Symbol should be SYMBOL');
Expand Down
15 changes: 1 addition & 14 deletions token/src/erc20/erc20.cairo
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
#[starknet::contract]
#[dojo::contract]
mod ERC20 {
use token::erc20::models::{ERC20Allowance, ERC20Balance, ERC20Meta};
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};
use token::erc20::interface;
use integer::BoundedInt;
use starknet::ContractAddress;
use starknet::{get_caller_address, get_contract_address};
use zeroable::Zeroable;


#[storage]
struct Storage {
_world: ContractAddress,
}

#[event]
#[derive(Copy, Drop, starknet::Event)]
enum Event {
Expand Down Expand Up @@ -47,13 +40,11 @@ mod ERC20 {
#[constructor]
fn constructor(
ref self: ContractState,
world: ContractAddress,
name: felt252,
symbol: felt252,
initial_supply: u256,
recipient: ContractAddress
) {
self._world.write(world);
self.initializer(name, symbol);
self._mint(recipient, initial_supply);
}
Expand Down Expand Up @@ -177,10 +168,6 @@ mod ERC20 {

#[generate_trait]
impl WorldInteractionsImpl of WorldInteractionsTrait {
fn world(self: @ContractState) -> IWorldDispatcher {
IWorldDispatcher { contract_address: self._world.read() }
}

fn get_meta(self: @ContractState) -> ERC20Meta {
get!(self.world(), get_contract_address(), ERC20Meta)
}
Expand Down
8 changes: 4 additions & 4 deletions token/src/erc20/tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};
use token::erc20::models::{
ERC20Allowance, erc_20_allowance, ERC20Balance, erc_20_balance, ERC20Meta, erc_20_meta
};
use token::erc20::ERC20::_worldContractMemberStateTrait;
use token::erc20::ERC20::world_dispatcherContractMemberStateTrait;
use debug::PrintTrait;

//
Expand All @@ -37,13 +37,13 @@ fn STATE() -> (IWorldDispatcher, ERC20::ContractState) {
]
);
let mut state = ERC20::contract_state_for_testing();
state._world.write(world.contract_address);
state.world_dispatcher.write(world);
(world, state)
}

fn setup() -> ERC20::ContractState {
let (world, mut state) = STATE();
ERC20::constructor(ref state, world.contract_address, NAME, SYMBOL, SUPPLY, OWNER());
ERC20::constructor(ref state, NAME, SYMBOL, SUPPLY, OWNER());
utils::drop_event(ZERO());
state
}
Expand All @@ -69,7 +69,7 @@ fn test_initializer() {
#[available_gas(25000000)]
fn test_constructor() {
let (world, mut state) = STATE();
ERC20::constructor(ref state, world.contract_address, NAME, SYMBOL, SUPPLY, OWNER());
ERC20::constructor(ref state, NAME, SYMBOL, SUPPLY, OWNER());

assert_only_event_transfer(ZERO(), OWNER(), SUPPLY);

Expand Down
14 changes: 1 addition & 13 deletions token/src/erc721/erc721.cairo
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
#[starknet::contract]
#[dojo::contract]
mod ERC721 {
use token::erc721::models::{
ERC721Meta, ERC721OperatorApproval, ERC721Owner, ERC721Balance, ERC721TokenApproval
};
use token::erc721::interface;
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};
use integer::BoundedInt;
use starknet::ContractAddress;
use starknet::{get_caller_address, get_contract_address};
use zeroable::Zeroable;


#[storage]
struct Storage {
_world: ContractAddress,
}

#[event]
#[derive(Copy, Drop, starknet::Event)]
enum Event {
Expand Down Expand Up @@ -61,14 +55,12 @@ mod ERC721 {
#[constructor]
fn constructor(
ref self: ContractState,
world: ContractAddress,
name: felt252,
symbol: felt252,
base_uri: felt252,
recipient: ContractAddress,
token_id: u256
) {
self._world.write(world);
self.initializer(name, symbol, base_uri);
self._mint(recipient, token_id);
}
Expand Down Expand Up @@ -207,10 +199,6 @@ mod ERC721 {

#[generate_trait]
impl WorldInteractionsImpl of WorldInteractionsTrait {
fn world(self: @ContractState) -> IWorldDispatcher {
IWorldDispatcher { contract_address: self._world.read() }
}

fn get_meta(self: @ContractState) -> ERC721Meta {
get!(self.world(), get_contract_address(), ERC721Meta)
}
Expand Down
8 changes: 4 additions & 4 deletions token/src/erc721/tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use token::erc721::models::{
ERC721Meta, erc_721_meta, ERC721OperatorApproval, erc_721_operator_approval, ERC721Owner,
erc_721_owner, ERC721Balance, erc_721_balance, ERC721TokenApproval, erc_721_token_approval
};
use token::erc721::ERC721::_worldContractMemberStateTrait;
use token::erc721::ERC721::world_dispatcherContractMemberStateTrait;

//
// Setup
Expand All @@ -52,13 +52,13 @@ fn STATE() -> (IWorldDispatcher, ERC721::ContractState) {
]
);
let mut state = ERC721::contract_state_for_testing();
state._world.write(world.contract_address);
state.world_dispatcher.write(world);
(world, state)
}

fn setup() -> ERC721::ContractState {
let (world, mut state) = STATE();
ERC721::constructor(ref state, world.contract_address, NAME, SYMBOL, URI, OWNER(), TOKEN_ID);
ERC721::constructor(ref state, NAME, SYMBOL, URI, OWNER(), TOKEN_ID);
utils::drop_event(ZERO());
state
}
Expand Down Expand Up @@ -89,7 +89,7 @@ fn setup() -> ERC721::ContractState {
#[available_gas(20000000)]
fn test_constructor() {
let (world, mut state) = STATE();
ERC721::constructor(ref state, world.contract_address, NAME, SYMBOL, URI, OWNER(), TOKEN_ID);
ERC721::constructor(ref state, NAME, SYMBOL, URI, OWNER(), TOKEN_ID);

assert(ERC721MetadataImpl::name(@state) == NAME, 'Name should be NAME');
assert(ERC721MetadataImpl::symbol(@state) == SYMBOL, 'Symbol should be SYMBOL');
Expand Down