Skip to content

Commit

Permalink
update deploy.sh, BriqFactoryMint, add treasury address
Browse files Browse the repository at this point in the history
  • Loading branch information
notV4l committed Aug 24, 2023
1 parent 8a900b4 commit ca72657
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
44 changes: 31 additions & 13 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ export STARKNET_KEYSTORE="scripts/katana_signer"
export KEYSTORE_PWD="katana"

export STARKNET_ACCOUNT="scripts/katana_account.json"

export ACCOUNT_ADDRESS=$(jq .deployment.address scripts/katana_account.json -r)
export TREASURY_ADDRESS="0x33c627a3e5213790e246a917770ce23d7e562baa5b4d2917c23b1be6d91961c"

# https://github.com/dojoengine/dojo/blob/main/crates/katana/core/src/constants.rs
# katana predeployed fee_token_address (uses transferFrom..)
export FEE_TOKEN_ADDR="0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"

sozo build

echo "\nDeclaring class hashes ...\n"

export BRIQ_HASH=$(starkli declare --compiler-version 2.1.0 target/dev/briq_protocol-BriqToken.json --keystore-password $KEYSTORE_PWD)
export SET_HASH=$(starkli declare --compiler-version 2.1.0 target/dev/briq_protocol-SetNft.json --keystore-password $KEYSTORE_PWD)
export ERC1155_HASH=$(starkli declare --compiler-version 2.1.0 target/dev/briq_protocol-GenericERC1155.json --keystore-password $KEYSTORE_PWD)
export BRIQ_HASH=$(starkli declare --compiler-version 2.1.0 target/dev/briq_protocol-BriqToken.json --keystore-password $KEYSTORE_PWD)
export SET_HASH=$(starkli declare --compiler-version 2.1.0 target/dev/briq_protocol-SetNft.json --keystore-password $KEYSTORE_PWD)
export ERC1155_HASH=$(starkli declare --compiler-version 2.1.0 target/dev/briq_protocol-GenericERC1155.json --keystore-password $KEYSTORE_PWD)

echo "\n*************************************"
echo BRIQ_HASH=$BRIQ_HASH
Expand All @@ -27,6 +31,8 @@ echo "*************************************"
sozo migrate

export WORLD_ADDRESS=0x23aa0e3ffa4663cca36a00577eb9c188aff648568c859735e6de463d41713ec
export EXECUTOR_ADDRESS=0x461be0e8caa002e9fa011760f4412fdad3579afc58cc120f22c794a888bfb6b


echo "\nDeploying contracts ...\n"

Expand All @@ -36,26 +42,38 @@ export BOX_ADDR=$(starkli deploy $ERC1155_HASH $WORLD_ADDRESS --keystore-passwor
export SET_ADDR=$(starkli deploy $SET_HASH $WORLD_ADDRESS --keystore-password $KEYSTORE_PWD)

echo "\n*************************************"
echo FEE_TOKEN_ADDR=$FEE_TOKEN_ADDR
echo BRIQ_ADDR=$BRIQ_ADDR
echo BOOKLET_ADDR=$BOOKLET_ADDR
echo BOX_ADDR=$BOX_ADDR
echo SET_ADDR=$SET_ADDR
echo "*************************************"


## Setup Wold config
sozo execute SetupWorld --world $WORLD_ADDRESS --calldata $ACCOUNT_ADDRESS,$BRIQ_ADDR,$SET_ADDR,$BOOKLET_ADDR,$BOX_ADDR
## Setup World config
sozo execute SetupWorld --world $WORLD_ADDRESS --calldata $ACCOUNT_ADDRESS,$TREASURY_ADDRESS,$BRIQ_ADDR,$SET_ADDR,$BOOKLET_ADDR,$BOX_ADDR

## Return wolrd config
## Return World config
sozo component entity WorldConfig 1 --world $WORLD_ADDRESS

return
## Setup briq_factory
sozo execute BriqFactoryInitialize --world $WORLD_ADDRESS --calldata 0,0,$FEE_TOKEN_ADDR

## Return briq_factory config
sozo component entity BriqFactoryStore 1 --world $WORLD_ADDRESS

## Integration tests
# mint briqs for
#sozo execute ERC1155MintBurn --calldata $WORLD_ADDRESS,$BRIQ_ADDR,0,$ACCOUNT_ADDRESS,1,1,1,100 --world $WORLD_ADDRESS
## approve EXECUTOR to spend 1eth FEE_TOKEN
starkli invoke $FEE_TOKEN_ADDR approve $EXECUTOR_ADDRESS u256:1000000000000000000 --keystore-password $KEYSTORE_PWD --watch
starkli call $FEE_TOKEN_ADDR allowance $ACCOUNT_ADDRESS $EXECUTOR_ADDRESS

# Doesnt' work at all --> should use entity instead of get
#sozo component get ERC1155Balance $BRIQ_ADDR, --world $WORLD_ADDRESS
## Buy 10000 briqs with material_id=1 in briq_factory
sozo execute BriqFactoryMint --world $WORLD_ADDRESS --calldata 1,10000

return


## ACCOUNT_ADDRESS balance : BRIQ
# starkli call $BRIQ_ADDR balance_of $ACCOUNT_ADDRESS u256:1

## ACCOUNT_ADDRESS balance : ETH
# starkli balance $ACCOUNT_ADDRESS
11 changes: 3 additions & 8 deletions src/briq_factory/systems.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,11 @@ mod BriqFactoryMint {

#[starknet::interface]
trait IERC20<TState> {
fn transfer_from(
fn transferFrom(
ref self: TState, spender: ContractAddress, recipient: ContractAddress, amount: u256
);
}

#[starknet::interface]
trait IBriq<TState> {
fn mint(ref self: TState, to: ContractAddress, id: felt252, amount: u128, data: Array<u8>);
}

fn execute(ctx: Context, params: BriqFactoryBuyParams) {
let BriqFactoryBuyParams{material, amount: amount_u32 } = params;
let amount: felt252 = amount_u32.into();
Expand All @@ -71,10 +66,10 @@ mod BriqFactoryMint {
// Transfer funds to receiver wallet
// TODO: use something other than the super-admin address for this.
let world_config = get_world_config(ctx.world);
let buyer = get_caller_address();
let buyer = ctx.origin;
IERC20Dispatcher {
contract_address: briq_factory.buy_token
}.transfer_from(buyer, world_config.super_admin, price.into());
}.transferFrom(buyer, world_config.treasury, price.into());

// update store
briq_factory.last_purchase_time = get_block_timestamp();
Expand Down
6 changes: 5 additions & 1 deletion src/world_config.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct WorldConfig {
#[key]
config_id: u32,
super_admin: ContractAddress,
treasury: ContractAddress,
briq: ContractAddress,
set: ContractAddress,
booklet: ContractAddress,
Expand Down Expand Up @@ -53,14 +54,17 @@ mod SetupWorld {
fn execute(
ctx: Context,
super_admin: ContractAddress,
treasury: ContractAddress,
briq: ContractAddress,
set: ContractAddress,
booklet: ContractAddress,
box: ContractAddress
) {
set!(
ctx.world,
(WorldConfig { config_id: SYSTEM_CONFIG_ID, super_admin, briq, set, booklet, box, })
(WorldConfig {
config_id: SYSTEM_CONFIG_ID, super_admin, treasury, briq, set, booklet, box,
})
);
return ();
}
Expand Down

0 comments on commit ca72657

Please sign in to comment.