Skip to content

Commit 21f5465

Browse files
committed
Merge branch 'challenge-base' into token-vendor
2 parents 6fea718 + 2884f6d commit 21f5465

40 files changed

+1880
-2101
lines changed

.github/workflows/test_contract.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Next.js CI
2+
3+
on:
4+
push:
5+
paths:
6+
- "packages/snfoundry/contracts/**"
7+
pull_request:
8+
paths:
9+
- "packages/snfoundry/contracts/**"
10+
11+
jobs:
12+
snfoundry:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@master
17+
18+
- name: Install scarb
19+
run: curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v 2.5.4
20+
21+
- name: Install snfoundryup
22+
run: curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh
23+
24+
- name: Install snforge
25+
run: snfoundryup -v 0.25.0
26+
27+
- name: Run snforge tests
28+
run: snforge test
29+
working-directory: ./packages/snfoundry/contracts

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ yarn start
6868

6969
> 👩‍💻 Edit `YourToken.cairo` to reuse the **ERC20** token standard from OpenZeppelin. To accomplish this, you can use [`Cairo Components`](https://book.cairo-lang.org/ch16-02-00-composability-and-components.html) to embed the `ERC20` logic inside your contract.
7070
71-
> Mint **1000** (\* 10 \*\* 18) to your frontend address using the `constructor()`. In devnet, by default we choose the first pre-deployed account: `0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691`, to deploy the contracts. In order to complete this checkpoint, you need to connect to devnet using the same address.
71+
> Mint **2000** (\* 10 \*\* 18) to your frontend address using the `constructor()`. In devnet, by default we choose the first pre-deployed account: `0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691`, to deploy the contracts. In order to complete this checkpoint, you need to connect to devnet using the same address. In testnet, you can use your own address to deploy the contracts. Edi the .env file in the `snfoundry` package to set the `ACCOUNT_ADDRESS_SEPOLIA` to your own address.
7272
7373
(Your frontend address is the address in the top right of <http://localhost:3000>)
7474

@@ -89,7 +89,7 @@ yarn start
8989

9090
> 👩‍💻 Edit the `Vendor.cairo` contract with a `buy_tokens()` function
9191
92-
Use a price variable named `tokensPerEth` set to **100**:
92+
Create a price variable named `tokensPerEth` set to **100**:
9393

9494
```cairo
9595
const TokensPerEth: u256 = 100;
@@ -101,7 +101,7 @@ const TokensPerEth: u256 = 100;
101101
102102
Edit `packages/snfoundry/scripts-ts/deploy.ts` to deploy the `Vendor` (uncomment Vendor deploy lines).
103103

104-
Create a `tokens_per_eth` function in `Vendor.cairo` that returns the `tokensPerEth` value.
104+
Implement `tokens_per_eth` function in `Vendor.cairo` that returns the `tokensPerEth` value.
105105

106106
Uncomment the `Buy Tokens` sections in `packages/nextjs/app/token-vendor/page.tsx` to show the UI to buy tokens on the Token Vendor tab.
107107

@@ -115,8 +115,6 @@ Uncomment the `Buy Tokens` sections in `packages/nextjs/app/token-vendor/page.ts
115115

116116
> ✏️ We can't hard code the vendor address like we did above when deploying to the network because we won't know the vendor address at the time we create the token contract.
117117
118-
> ✏️ So instead, edit `YourToken.cairo` to mint the tokens to the `recipient` (deployer) in the **constructor()**.
119-
120118
> ✏️ Then, edit `packages/snfoundry/scripts-ts/deploy.ts` to transfer 1000 tokens to vendor address.
121119
122120
```ts

packages/nextjs/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
NEXT_PUBLIC_PROVIDER_URL=
1+
NEXT_PUBLIC_PROVIDER_URL=https://starknet-sepolia.infura.io/v3/c45bd0ce3e584ba4a5e6a5928c9c0b0f

packages/nextjs/app/api/ipfs/add/route.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/nextjs/app/api/ipfs/get-metadata/route.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/nextjs/app/debug/_components/DebugContracts.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ContractUI } from "~~/app/debug/_components/contract";
66
import { ContractName } from "~~/utils/scaffold-stark/contract";
77
import { getAllContracts } from "~~/utils/scaffold-stark/contractsData";
88

9-
const selectedContractStorageKey = "scaffoldEth2.selectedContract";
9+
const selectedContractStorageKey = "scaffoldStark2.selectedContract";
1010
const contractsData = getAllContracts();
1111
const contractNames = Object.keys(contractsData) as ContractName[];
1212

@@ -42,14 +42,6 @@ export function DebugContracts() {
4242
onClick={() => setSelectedContract(contractName)}
4343
>
4444
{contractName}
45-
{/* {contractsData[contractName].external && (
46-
<span
47-
className="tooltip tooltip-top tooltip-accent"
48-
data-tip="External contract"
49-
>
50-
<BarsArrowUpIcon className="h-4 w-4 cursor-pointer" />
51-
</span>
52-
)} */}
5345
</button>
5446
))}
5547
</div>

packages/nextjs/app/debug/_components/contract/ContractInput.tsx

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
"use client";
22

33
import { Dispatch, SetStateAction } from "react";
4-
// import { Tuple } from "./Tuple";
5-
// import { TupleArray } from "./TupleArray";
6-
import {
7-
InputBase,
8-
// AddressInput,
9-
// Bytes32Input,
10-
// BytesInput,
11-
// InputBase,
12-
IntegerInput,
13-
} from "~~/components/scaffold-stark";
14-
// import { AbiParameterTuple } from "~~/utils/scaffold-eth/contract";
4+
import { InputBase, IntegerInput } from "~~/components/scaffold-stark";
155
import { AbiParameter } from "~~/utils/scaffold-stark/contract";
166
import { displayType } from "./utilsDisplay";
177
import {
8+
isCairoArray,
189
isCairoBigInt,
1910
isCairoInt,
2011
isCairoU256,
@@ -27,9 +18,6 @@ type ContractInputProps = {
2718
paramType: AbiParameter;
2819
};
2920

30-
/**
31-
* Generic Input component to handle input's based on their function param type
32-
*/
3321
export const ContractInput = ({
3422
setForm,
3523
form,
@@ -52,29 +40,12 @@ export const ContractInput = ({
5240

5341
const renderInput = () => {
5442
switch (paramType.type) {
55-
// case "address":
56-
// return <AddressInput {...inputProps} />;
57-
// case "bytes32":
58-
// return <Bytes32Input {...inputProps} />;
59-
// case "bytes":
60-
// return <BytesInput {...inputProps} />;
61-
// case "string":
62-
// return <InputBase {...inputProps} />;
63-
// case "tuple":
64-
// return (
65-
// <Tuple
66-
// setParentForm={setForm}
67-
// parentForm={form}
68-
// abiTupleParameter={paramType as AbiParameterTuple}
69-
// parentStateObjectKey={stateObjectKey}
70-
// />
71-
// );
7243
default:
73-
// Handling 'int' types and 'tuple[]' types
7444
if (
75-
isCairoInt(paramType.type) ||
76-
isCairoBigInt(paramType.type) ||
77-
isCairoU256(paramType.type)
45+
!isCairoArray(paramType.type) &&
46+
(isCairoInt(paramType.type) ||
47+
isCairoBigInt(paramType.type) ||
48+
isCairoU256(paramType.type))
7849
) {
7950
return <IntegerInput {...inputProps} variant={paramType.type} />;
8051
} else {

packages/nextjs/app/debug/_components/contract/tuple.tsx

Lines changed: 0 additions & 68 deletions
This file was deleted.

packages/nextjs/app/debug/_components/contract/utilsContract.tsx

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import {
33
AbiParameter,
44
parseParamWithType,
55
} from "~~/utils/scaffold-stark/contract";
6-
import { uint256 } from "starknet";
7-
import { byteArray } from "starknet-dev";
86
/**
97
* Generates a key based on function metadata
108
*/
@@ -36,7 +34,6 @@ const getInitialFormState = (abiFunction: AbiFunction) => {
3634
return initialForm;
3735
};
3836

39-
// Recursive function to deeply parse JSON strings, correctly handling nested arrays and encoded JSON strings
4037
const deepParseValues = (
4138
value: any,
4239
isRead: boolean,
@@ -99,24 +96,9 @@ const getParsedContractFunctionArgs = (
9996
};
10097

10198
const adjustInput = (input: AbiParameter): AbiParameter => {
102-
// if (input.type.startsWith("tuple[")) {
103-
// const depth = (input.type.match(/\[\]/g) || []).length;
104-
// return {
105-
// ...input,
106-
// components: transformComponents(input.components, depth, {
107-
// internalType: input.internalType || "struct",
108-
// name: input.name,
109-
// }),
110-
// };
111-
// } else if (input.components) {
11299
return {
113100
...input,
114-
// components: input.components.map((value) =>
115-
// adjustInput(value as AbiParameterTuple)
116-
// ),
117101
};
118-
// }
119-
// return input;
120102
};
121103

122104
const transformAbiFunction = (abiFunction: AbiFunction): AbiFunction => {

packages/nextjs/app/debug/_components/contract/utilsDisplay.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import {
1010
isCairoContractAddress,
1111
isCairoTuple,
12+
parseGenericType,
1213
} from "~~/utils/scaffold-stark/types";
1314
import { formatEther } from "ethers";
1415

@@ -79,7 +80,24 @@ export const displayTxResult = (
7980
return JSON.stringify(displayContent, replacer, 2);
8081
};
8182

82-
export const displayType = (type: string) =>
83-
type.includes("::") ? type.split("::").pop() : type;
83+
export const displayType = (type: string) => {
84+
if (type.includes("core::array") || type.includes("core::option")) {
85+
const kindOfArray = type.split("::").at(2);
86+
const parsed = parseGenericType(type);
87+
const arrayType = Array.isArray(parsed)
88+
? parsed[0].split("::").pop()
89+
: `(${parsed
90+
.split(",")
91+
.map((t) => t.split("::").pop())
92+
.join(",")}`;
93+
return `${kindOfArray}<${arrayType}>`;
94+
} else if (type.includes("core::result")) {
95+
const types = type.split("::");
96+
return `${types.at(-4)}<${types.at(-2)?.split(",").at(0)},${types.at(-1)}`;
97+
} else if (type.includes("::")) {
98+
return type.split("::").pop();
99+
}
100+
return type;
101+
};
84102
const displayTxResultAsText = (displayContent: DisplayContent) =>
85103
displayTxResult(displayContent, true);

0 commit comments

Comments
 (0)