Skip to content

Commit

Permalink
Update cyberpunk theme dice game (#91)
Browse files Browse the repository at this point in the history
Co-authored-by: CarlosR <[email protected]>
Co-authored-by: Carlos Ramos <[email protected]>
Co-authored-by: GianMarco <[email protected]>
Co-authored-by: 0xquantum3labs <[email protected]>
Co-authored-by: Quantum3Labs <[email protected]>
Co-authored-by: avimak <[email protected]>
Co-authored-by: Eduardo <[email protected]>
Co-authored-by: Eduardo <[email protected]>
Co-authored-by: goofylfg <[email protected]>
Co-authored-by: Nico <[email protected]>
Co-authored-by: Ege <[email protected]>
Co-authored-by: GianM <[email protected]>
Co-authored-by: gianmalarcon <[email protected]>
Co-authored-by: Nadai2010 <[email protected]>
Co-authored-by: jrcarlos2000 <[email protected]>
Co-authored-by: Daniel Calderón Díaz <[email protected]>
  • Loading branch information
17 people authored Jul 28, 2024
1 parent b48ae10 commit 060b895
Show file tree
Hide file tree
Showing 75 changed files with 3,039 additions and 2,307 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/demo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: scaffold-stark-demo workflow

on:
pull_request:
types: [closed]
branches: [main]
paths:
- 'packages/nextjs/**'

jobs:
version-bump-nextjs:
runs-on: ubuntu-22.04
steps:

- name: Checkout Source Repository
uses: actions/checkout@v4
with:
repository: Quantum3-Labs/scaffold-stark-2
token: ${{ secrets.ORG_GITHUB_TOKEN }}
path: source_repo

- name: Modify scaffoldConfig in Source Repository
run: |
cd source_repo
sed -i 's/targetNetworks: \[chains.devnet\]/targetNetworks: \[chains.sepolia\]/' packages/nextjs/scaffold.config.ts
cat packages/nextjs/scaffold.config.ts
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 20
registry-url: 'https://registry.yarnpkg.com'

- name: Deploy to vercel
if: success()
id: deploy
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
run: |
cd source_repo
yarn install
vercel link --yes --project $VERCEL_PROJECT_ID --token $VERCEL_TOKEN --scope $VERCEL_ORG_ID
vercel --build-env NEXT_PUBLIC_IGNORE_BUILD_ERROR=true --prod --token $VERCEL_TOKEN --scope $VERCEL_ORG_ID
- name: Notify Slack on Success
if: success()
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
slack-message: "GitHub deployed to vercel result: ${{ job.status }}\nRepository Name: ${{ github.repository }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

- name: Notify Slack on Failure
if: failure()
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
slack-message: "GitHub deployed to vercel result: ${{ job.status }}\nRepository Name: ${{ github.repository }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
114 changes: 114 additions & 0 deletions .github/workflows/release-create-stark.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: Version Bump and Notify

on:
pull_request:
types: [closed]
branches: [main]

jobs:
version-bump:
runs-on: ubuntu-22.04

steps:
- name: Checkout Source Repository
uses: actions/checkout@v4
with:
repository: Quantum3-Labs/scaffold-stark-2
token: ${{ secrets.ORG_GITHUB_TOKEN }}
path: source_repo

- name: Checkout Destination Repository
uses: actions/checkout@v4
with:
repository: Quantum3-Labs/create-stark
token: ${{ secrets.ORG_GITHUB_TOKEN }}
path: destination_repo

- name: Determine version bump type
id: version
run: |
cd source_repo
commit_message=$(git log -1 --pretty=%B)
if [[ "$commit_message" == *"[major]"* ]]; then
echo "type=major" >> "$GITHUB_ENV"
elif [[ "$commit_message" == *"[minor]"* ]]; then
echo "type=minor" >> "$GITHUB_ENV"
else
echo "type=patch" >> "$GITHUB_ENV"
fi
- name: Bump version in Source Repository
id: bump-version-source
run: |
cd source_repo
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
new_version=$(npm version ${{ env.type }} -m "chore(release): %s [skip ci]")
echo "NEW_VERSION=${new_version}" >> "$GITHUB_ENV"
git push origin main --follow-tags
- name: Copy Files to Destination Repository
run: |
rsync -av --delete --exclude='.git' source_repo/ destination_repo/templates/base
cd destination_repo
git add .
git commit -m "chore: sync files from scaffold-stark-2 [skip ci]"
- name: Format .gitignore files
run: |
find destination_repo/templates/base -type f -name ".gitignore" | while read -r gitignore_file; do
mjs_file="${gitignore_file%/*}/.gitignore.template.mjs"
gitignore_content=$(cat "$gitignore_file")
cat > "$mjs_file" <<-EOF
const contents = () =>
\`${gitignore_content}\`
export default contents;
EOF
rm "$gitignore_file"
done
cd destination_repo
git add .
git commit -m "Processed $gitignore_file into $mjs_file"
- name: Bump version in Destination Repository
id: bump-version-destination
run: |
cd destination_repo
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
new_version=$(npm version ${{ env.type }} -m "chore(release): %s [skip ci]")
git push origin main --follow-tags
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
registry-url: 'https://registry.npmjs.org/'

- name: Publish release
if: success()
id: publish-release
run: |
cd destination_repo
npm install && npm run build && npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Notify Slack on Success
if: success()
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
slack-message: "GitHub Action succeeded for version bump to ${{ env.NEW_VERSION }}."
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

- name: Notify Slack on Failure
if: failure()
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
slack-message: "GitHub Action failed for version bump."
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
29 changes: 29 additions & 0 deletions .github/workflows/test_contract.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Next.js CI

on:
push:
paths:
- "packages/snfoundry/contracts/**"
pull_request:
paths:
- "packages/snfoundry/contracts/**"

jobs:
snfoundry:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master

- name: Install scarb
run: curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v 2.5.4

- name: Install snfoundryup
run: curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh

- name: Install snforge
run: snfoundryup -v 0.25.0

- name: Run snforge tests
run: snforge test
working-directory: ./packages/snfoundry/contracts
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ Next add a `riggedRoll()` function. This function should predict the randomness
- [ ] Uncomment the code in `packages/nextjs/app/dice/page.tsx` to show a riggedRoll button and contract balance on the main UI tab. Now you can test your function without switching tabs.
- [ ] Does your riggedRoll function only call `rollTheDice()` when it's going to be a winning roll? What happens when it does call `rollTheDice()`?

![RiggedLosingRoll](https://raw.githubusercontent.com/Quantum3-Labs/speedrunstark/663143e24ecab9a71c2550ac5fe2d8fa5d23ee2c/packages/nextjs/public/rolldice.png)
![RiggedLosingRoll](https://raw.githubusercontent.com/Quantum3-Labs/speedrunstark/gabi/dice-game/packages/nextjs/public/ch3-roll.png)

---

## Checkpoint 3: 💵 Where's my money?!?

You have beaten the game, but where is your money? Since the RiggedRoll contract is the one calling `rollTheDice()`, that is where the prize money is being sent.

![RiggedRollAddress](https://raw.githubusercontent.com/Quantum3-Labs/speedrunstark/663143e24ecab9a71c2550ac5fe2d8fa5d23ee2c/packages/nextjs/public/riggedroll.png)
![RiggedRollAddress](https://raw.githubusercontent.com/Quantum3-Labs/speedrunstark/gabi/dice-game/packages/nextjs/public/ch3-events.png)

📥 Create a `fn withdraw(ref self: ContractState, to: ContractAddress, amount: u256)` function to allow you to send Eth from RiggedRoll to another address.

Expand All @@ -127,7 +127,7 @@ You have beaten the game, but where is your money? Since the RiggedRoll contract

- [ ] Lock the withdraw function so it can only be called by the owner.

![WithdrawOnlyOwner](https://github.com/Quantum3-Labs/speedrunstark/blob/dice-game/packages/nextjs/public/withdraw.png)
![WithdrawOnlyOwner](https://raw.githubusercontent.com/Quantum3-Labs/speedrunstark/gabi/dice-game/packages/nextjs/public/ch3-debug.png)

> ⚠️ But wait, I am not the owner! You will want to set your front end address as the owner in `deploy.ts`. This will allow your front end address to call the withdraw function.
Expand Down
Binary file removed assests/debug-contracts.png
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/nextjs/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1 @@
NEXT_PUBLIC_PROVIDER_URL=
NEXT_PUBLIC_PROVIDER_URL=https://starknet-sepolia.infura.io/v3/c45bd0ce3e584ba4a5e6a5928c9c0b0f
12 changes: 0 additions & 12 deletions packages/nextjs/app/api/ipfs/add/route.ts

This file was deleted.

12 changes: 0 additions & 12 deletions packages/nextjs/app/api/ipfs/get-metadata/route.ts

This file was deleted.

14 changes: 3 additions & 11 deletions packages/nextjs/app/debug/_components/DebugContracts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ContractUI } from "~~/app/debug/_components/contract";
import { ContractName } from "~~/utils/scaffold-stark/contract";
import { getAllContracts } from "~~/utils/scaffold-stark/contractsData";

const selectedContractStorageKey = "scaffoldEth2.selectedContract";
const selectedContractStorageKey = "scaffoldStark2.selectedContract";
const contractsData = getAllContracts();
const contractNames = Object.keys(contractsData) as ContractName[];

Expand Down Expand Up @@ -35,21 +35,13 @@ export function DebugContracts() {
<button
className={`btn btn-secondary btn-sm font-light hover:border-transparent ${
contractName === selectedContract
? "bg-base-300 hover:bg-base-300 no-animation text-base-100 "
: "bg-base-100 hover:bg-secondary hover:text-neutral-content text-primary"
? "bg-secondary hover:bg-secondary no-animation text-white"
: "bg-transparent text-neutral hover:text-white"
}`}
key={contractName}
onClick={() => setSelectedContract(contractName)}
>
{contractName}
{/* {contractsData[contractName].external && (
<span
className="tooltip tooltip-top tooltip-accent"
data-tip="External contract"
>
<BarsArrowUpIcon className="h-4 w-4 cursor-pointer" />
</span>
)} */}
</button>
))}
</div>
Expand Down
41 changes: 6 additions & 35 deletions packages/nextjs/app/debug/_components/contract/ContractInput.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
"use client";

import { Dispatch, SetStateAction } from "react";
// import { Tuple } from "./Tuple";
// import { TupleArray } from "./TupleArray";
import {
InputBase,
// AddressInput,
// Bytes32Input,
// BytesInput,
// InputBase,
IntegerInput,
} from "~~/components/scaffold-stark";
// import { AbiParameterTuple } from "~~/utils/scaffold-eth/contract";
import { InputBase, IntegerInput } from "~~/components/scaffold-stark";
import { AbiParameter } from "~~/utils/scaffold-stark/contract";
import { displayType } from "./utilsDisplay";
import {
isCairoArray,
isCairoBigInt,
isCairoInt,
isCairoU256,
Expand All @@ -27,9 +18,6 @@ type ContractInputProps = {
paramType: AbiParameter;
};

/**
* Generic Input component to handle input's based on their function param type
*/
export const ContractInput = ({
setForm,
form,
Expand All @@ -52,29 +40,12 @@ export const ContractInput = ({

const renderInput = () => {
switch (paramType.type) {
// case "address":
// return <AddressInput {...inputProps} />;
// case "bytes32":
// return <Bytes32Input {...inputProps} />;
// case "bytes":
// return <BytesInput {...inputProps} />;
// case "string":
// return <InputBase {...inputProps} />;
// case "tuple":
// return (
// <Tuple
// setParentForm={setForm}
// parentForm={form}
// abiTupleParameter={paramType as AbiParameterTuple}
// parentStateObjectKey={stateObjectKey}
// />
// );
default:
// Handling 'int' types and 'tuple[]' types
if (
isCairoInt(paramType.type) ||
isCairoBigInt(paramType.type) ||
isCairoU256(paramType.type)
!isCairoArray(paramType.type) &&
(isCairoInt(paramType.type) ||
isCairoBigInt(paramType.type) ||
isCairoU256(paramType.type))
) {
return <IntegerInput {...inputProps} variant={paramType.type} />;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Abi } from "abi-wan-kanabi";
import {
AbiFunction,
Contract,
ContractName,
GenericContract,
InheritedFunctions,
getFunctionsByStateMutability,
} from "~~/utils/scaffold-stark/contract";
import { ReadOnlyFunctionForm } from "./ReadOnlyFunctionForm";
Expand Down
Loading

0 comments on commit 060b895

Please sign in to comment.