-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>
- Loading branch information
1 parent
5cc1451
commit 5ddbf45
Showing
10 changed files
with
218 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Compile Cairo contracts | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
generate_and_compile: | ||
name: Compile Cairo contracts | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18.x | ||
cache: 'yarn' | ||
- name: Install dependencies | ||
run: yarn install | ||
- name: Generate contracts | ||
run: yarn workspace @openzeppelin/wizard-cairo update_scarb_project | ||
- name: Extract scarb version | ||
run: | | ||
SCARB_VERSION=$(grep 'scarb-version = ' packages/core-cairo/test_project/Scarb.toml | sed 's/scarb-version = "\(.*\)"/\1/') | ||
echo "SCARB_VERSION=$SCARB_VERSION" >> $GITHUB_ENV | ||
- uses: software-mansion/setup-scarb@v1 | ||
with: | ||
scarb-version: ${{ env.SCARB_VERSION }} | ||
- name: Compile contracts | ||
working-directory: ./packages/core-cairo/test_project | ||
run: scarb build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { ERC1155Options } from '../erc1155'; | ||
import { accessOptions } from '../set-access-control'; | ||
import { infoOptions } from '../set-info'; | ||
import { upgradeableOptions } from '../set-upgradeable'; | ||
import { generateAlternatives } from './alternatives'; | ||
|
||
const booleans = [true, false]; | ||
|
||
const blueprint = { | ||
name: ['MyToken'], | ||
baseUri: ['https://example.com/'], | ||
burnable: booleans, | ||
pausable: booleans, | ||
mintable: booleans, | ||
updatableUri: booleans, | ||
access: accessOptions, | ||
upgradeable: upgradeableOptions, | ||
info: infoOptions, | ||
}; | ||
|
||
export function* generateERC1155Options(): Generator<Required<ERC1155Options>> { | ||
yield* generateAlternatives(blueprint); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { promises as fs } from 'fs'; | ||
import path from 'path'; | ||
|
||
import { writeGeneratedSources } from '../generate/sources'; | ||
import { contractsVersionTag, edition, cairoVersion, scarbVersion } from '../utils/version'; | ||
|
||
export async function updateScarbProject() { | ||
const generatedSourcesPath = path.join('test_project', 'src'); | ||
await fs.rm(generatedSourcesPath, { force: true, recursive: true }); | ||
|
||
// Generate the contracts source code | ||
const contractNames = await writeGeneratedSources(generatedSourcesPath, 'all', true); | ||
|
||
// Generate lib.cairo file | ||
writeLibCairo(contractNames); | ||
|
||
// Update Scarb.toml | ||
updateScarbToml(); | ||
} | ||
|
||
async function writeLibCairo(contractNames: string[]) { | ||
const libCairoPath = path.join('test_project/src', 'lib.cairo'); | ||
const libCairo = contractNames.map(name => `pub mod ${name};\n`).join(''); | ||
await fs.writeFile(libCairoPath, libCairo); | ||
} | ||
|
||
async function updateScarbToml() { | ||
const scarbTomlPath = path.join('test_project', 'Scarb.toml'); | ||
|
||
let currentContent = await fs.readFile(scarbTomlPath, 'utf8'); | ||
let updatedContent = currentContent | ||
.replace(/edition = "\w+"/, `edition = "${edition}"`) | ||
.replace(/cairo-version = "\d+\.\d+\.\d+"/, `cairo-version = "${cairoVersion}"`) | ||
.replace(/scarb-version = "\d+\.\d+\.\d+"/, `scarb-version = "${scarbVersion}"`) | ||
.replace(/starknet = "\d+\.\d+\.\d+"/, `starknet = "${cairoVersion}"`) | ||
.replace(/tag = "v\d+\.\d+\.\d+"/, `tag = "${contractsVersionTag}"`); | ||
|
||
await fs.writeFile(scarbTomlPath, updatedContent, 'utf8'); | ||
} | ||
|
||
updateScarbProject(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
src | ||
target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Code generated by scarb DO NOT EDIT. | ||
version = 1 | ||
|
||
[[package]] | ||
name = "openzeppelin" | ||
version = "0.13.0" | ||
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.13.0#978b4e75209da355667d8954d2450e32bd71fe49" | ||
|
||
[[package]] | ||
name = "test_project" | ||
version = "0.1.0" | ||
dependencies = [ | ||
"openzeppelin", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "test_project" | ||
version = "0.1.0" | ||
edition = "2023_01" | ||
cairo-version = "2.6.4" | ||
scarb-version = "2.6.5" | ||
|
||
[dependencies] | ||
starknet = "2.6.4" | ||
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.13.0" } | ||
|
||
[lib] | ||
|
||
[[target.starknet-contract]] | ||
allowed-libfuncs-list.name = "experimental" | ||
sierra = true | ||
casm = false |