Skip to content

Commit

Permalink
Feat: add reset_prize
Browse files Browse the repository at this point in the history
  • Loading branch information
gianalarcon committed Aug 10, 2024
1 parent 1417ca2 commit f4196b0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 36 deletions.
23 changes: 3 additions & 20 deletions packages/nextjs/contracts/deployedContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const deployedContracts = {
devnet: {
DiceGame: {
address:
"0x210b1ef37a3ac645656349a874e009c57241bb1cf937db896f5907c20342abc",
"0x66e4dcf6230bf18042e2be9b6a2631448388a843e52bd5d00f74789d342358e",
abi: [
{
type: "impl",
Expand Down Expand Up @@ -42,18 +42,6 @@ const deployedContracts = {
type: "interface",
name: "contracts::DiceGame::IDiceGame",
items: [
{
type: "function",
name: "init",
inputs: [
{
name: "init_balance",
type: "core::integer::u256",
},
],
outputs: [],
state_mutability: "external",
},
{
type: "function",
name: "roll_dice",
Expand Down Expand Up @@ -115,12 +103,7 @@ const deployedContracts = {
{
type: "constructor",
name: "constructor",
inputs: [
{
name: "owner",
type: "core::starknet::contract_address::ContractAddress",
},
],
inputs: [],
},
{
type: "event",
Expand Down Expand Up @@ -182,7 +165,7 @@ const deployedContracts = {
},
RiggedRoll: {
address:
"0x7a9aff1482fe4d97527c1c3e71831c7a0abd2a93f5f93c43a1dae37e056b6d2",
"0x5066136cdb0912938065748ac43fb25e863bd25c6b8dbe5537c73fab3720780",
abi: [
{
type: "impl",
Expand Down
12 changes: 2 additions & 10 deletions packages/snfoundry/contracts/src/DiceGame.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait};
#[starknet::interface]
pub trait IDiceGame<T> {
fn init(ref self: T, init_balance: u256);
fn roll_dice(ref self: T, amount: u256);
fn last_dice_value(self: @T) -> u256;
fn nonce(self: @T) -> u256;
Expand Down Expand Up @@ -49,22 +48,15 @@ mod DiceGame {
}

#[constructor]
fn constructor(ref self: ContractState, owner: ContractAddress) {
fn constructor(ref self: ContractState) {
let eth_contract: ContractAddress = ETH_CONTRACT_ADDRESS.try_into().unwrap();
self.eth_token.write(IERC20CamelDispatcher { contract_address: eth_contract });
self._reset_prize();
}


#[abi(embed_v0)]
impl DiceGameImpl of super::IDiceGame<ContractState> {
fn init(ref self: ContractState, init_balance: u256) {
self
.eth_token
.read()
.transferFrom(get_caller_address(), get_contract_address(), init_balance);
self._reset_prize();
}

fn roll_dice(ref self: ContractState, amount: u256) {
// >= 0.002 ETH
assert(amount >= 2000000000000000, 'Not enough ETH');
Expand Down
11 changes: 5 additions & 6 deletions packages/snfoundry/scripts-ts/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import { Abi, Contract, TransactionStatus } from "starknet";
import { Abi, Contract } from "starknet";
import {
deployContract,
executeDeployCalls,
exportDeployments,
deployer,
provider,
} from "./deploy-contract";

import preDeployedContracts from "../../nextjs/contracts/predeployedContracts";

const deployScript = async (): Promise<void> => {
const { address: diceGameAddr } = await deployContract(
{ owner: deployer.address },
const { address: diceGameAddr } = await deployContract(null,

"DiceGame"
);
const ethAbi = preDeployedContracts.devnet.Eth.abi as Abi;
const ethAddress = preDeployedContracts.devnet.Eth.address as `0x${string}`;

const ethContract = new Contract(ethAbi, ethAddress, deployer);

const tx = await ethContract.invoke("transfer", [diceGameAddr, 1000000000n]);
const receipt = await provider.waitForTransaction(tx.transaction_hash);
const tx = await ethContract.invoke("transfer", [diceGameAddr, 1000000000000000000n]);
//const receipt = await provider.waitForTransaction(tx.transaction_hash);

await deployContract(
{
Expand Down

0 comments on commit f4196b0

Please sign in to comment.