From b92d0bd1bcb1caf577552f958239c873ec793833 Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Tue, 4 Feb 2025 15:04:01 -0500 Subject: [PATCH 001/117] Move solidity and cairo to subfolders of core --- .github/workflows/test.yml | 10 +++++----- package.json | 3 ++- packages/{core-cairo => core/cairo}/.gitignore | 0 packages/{core-cairo => core/cairo}/CHANGELOG.md | 0 packages/{core-cairo => core/cairo}/LICENSE | 0 packages/{core-cairo => core/cairo}/NOTICE | 0 packages/{core-cairo => core/cairo}/README.md | 0 packages/{core-cairo => core/cairo}/ava.config.js | 0 packages/{core-cairo => core/cairo}/package.json | 2 +- .../{core-cairo => core/cairo}/src/account.test.ts | 0 .../cairo}/src/account.test.ts.md | 0 .../cairo}/src/account.test.ts.snap | Bin packages/{core-cairo => core/cairo}/src/account.ts | 0 .../{core-cairo => core/cairo}/src/add-pausable.ts | 0 packages/{core-cairo => core/cairo}/src/api.ts | 0 .../{core-cairo => core/cairo}/src/build-generic.ts | 0 .../cairo}/src/common-components.ts | 0 .../cairo}/src/common-options.ts | 0 .../{core-cairo => core/cairo}/src/contract.test.ts | 0 .../cairo}/src/contract.test.ts.md | 0 .../cairo}/src/contract.test.ts.snap | Bin packages/{core-cairo => core/cairo}/src/contract.ts | 0 .../{core-cairo => core/cairo}/src/custom.test.ts | 0 .../cairo}/src/custom.test.ts.md | 0 .../cairo}/src/custom.test.ts.snap | Bin packages/{core-cairo => core/cairo}/src/custom.ts | 0 .../{core-cairo => core/cairo}/src/erc1155.test.ts | 0 .../cairo}/src/erc1155.test.ts.md | 0 .../cairo}/src/erc1155.test.ts.snap | Bin packages/{core-cairo => core/cairo}/src/erc1155.ts | 0 .../{core-cairo => core/cairo}/src/erc20.test.ts | 0 .../{core-cairo => core/cairo}/src/erc20.test.ts.md | 0 .../cairo}/src/erc20.test.ts.snap | Bin packages/{core-cairo => core/cairo}/src/erc20.ts | 0 .../{core-cairo => core/cairo}/src/erc721.test.ts | 0 .../cairo}/src/erc721.test.ts.md | 0 .../cairo}/src/erc721.test.ts.snap | Bin packages/{core-cairo => core/cairo}/src/erc721.ts | 0 packages/{core-cairo => core/cairo}/src/error.ts | 0 .../cairo}/src/external-trait.ts | 0 .../cairo}/src/generate/account.ts | 0 .../cairo}/src/generate/alternatives.ts | 0 .../cairo}/src/generate/custom.ts | 0 .../cairo}/src/generate/erc1155.ts | 0 .../cairo}/src/generate/erc20.ts | 0 .../cairo}/src/generate/erc721.ts | 0 .../cairo}/src/generate/governor.ts | 0 .../cairo}/src/generate/sources.ts | 0 .../cairo}/src/generate/vesting.ts | 0 .../{core-cairo => core/cairo}/src/governor.test.ts | 0 .../cairo}/src/governor.test.ts.md | 0 .../cairo}/src/governor.test.ts.snap | Bin packages/{core-cairo => core/cairo}/src/governor.ts | 0 packages/{core-cairo => core/cairo}/src/index.ts | 0 packages/{core-cairo => core/cairo}/src/kind.ts | 0 packages/{core-cairo => core/cairo}/src/print.ts | 0 .../cairo}/src/scripts/update-scarb-project.ts | 0 .../cairo}/src/set-access-control.ts | 0 packages/{core-cairo => core/cairo}/src/set-info.ts | 0 .../cairo}/src/set-royalty-info.ts | 0 .../cairo}/src/set-upgradeable.ts | 0 packages/{core-cairo => core/cairo}/src/test.ts | 0 .../cairo}/src/utils/convert-strings.test.ts | 0 .../cairo}/src/utils/convert-strings.ts | 0 .../cairo}/src/utils/define-components.ts | 0 .../cairo}/src/utils/define-functions.ts | 0 .../cairo}/src/utils/duration.ts | 0 .../cairo}/src/utils/find-cover.ts | 0 .../cairo}/src/utils/format-lines.ts | 0 .../cairo}/src/utils/sorted-by.ts | 0 .../cairo}/src/utils/version.test.ts | 0 .../{core-cairo => core/cairo}/src/utils/version.ts | 0 .../{core-cairo => core/cairo}/src/vesting.test.ts | 0 .../cairo}/src/vesting.test.ts.md | 0 .../cairo}/src/vesting.test.ts.snap | Bin packages/{core-cairo => core/cairo}/src/vesting.ts | 0 .../cairo}/test_project/.gitignore | 0 .../cairo}/test_project/Scarb.lock | 0 .../cairo}/test_project/Scarb.toml | 0 packages/{core-cairo => core/cairo}/tsconfig.json | 2 +- packages/core/{ => solidity}/.gitignore | 0 packages/core/{ => solidity}/CHANGELOG.md | 0 packages/core/{ => solidity}/LICENSE | 0 packages/core/{ => solidity}/NOTICE | 0 packages/core/{ => solidity}/README.md | 0 packages/core/{ => solidity}/ava.config.js | 0 .../core/{ => solidity}/contracts/SafetyCheck.sol | 0 packages/core/{ => solidity}/get-imports.d.ts | 0 packages/core/{ => solidity}/get-imports.js | 0 packages/core/{ => solidity}/hardhat.config.js | 0 .../core/{ => solidity}/openzeppelin-contracts.d.ts | 0 packages/core/{ => solidity}/package.json | 2 +- packages/core/{ => solidity}/print-versioned.js | 0 packages/core/{ => solidity}/print-versioned.ts | 0 packages/core/{ => solidity}/src/add-pausable.ts | 0 packages/core/{ => solidity}/src/api.ts | 0 packages/core/{ => solidity}/src/build-generic.ts | 0 .../core/{ => solidity}/src/common-functions.ts | 0 packages/core/{ => solidity}/src/common-options.ts | 0 packages/core/{ => solidity}/src/contract.test.ts | 0 .../core/{ => solidity}/src/contract.test.ts.md | 0 .../core/{ => solidity}/src/contract.test.ts.snap | Bin packages/core/{ => solidity}/src/contract.ts | 0 packages/core/{ => solidity}/src/custom.test.ts | 0 packages/core/{ => solidity}/src/custom.test.ts.md | 0 .../core/{ => solidity}/src/custom.test.ts.snap | Bin packages/core/{ => solidity}/src/custom.ts | 0 .../src/environments/hardhat/package-lock.json | 0 .../src/environments/hardhat/package.json | 0 .../hardhat/upgradeable/package-lock.json | 0 .../environments/hardhat/upgradeable/package.json | 0 packages/core/{ => solidity}/src/erc1155.test.ts | 0 packages/core/{ => solidity}/src/erc1155.test.ts.md | 0 .../core/{ => solidity}/src/erc1155.test.ts.snap | Bin packages/core/{ => solidity}/src/erc1155.ts | 0 packages/core/{ => solidity}/src/erc20.test.ts | 0 packages/core/{ => solidity}/src/erc20.test.ts.md | 0 packages/core/{ => solidity}/src/erc20.test.ts.snap | Bin packages/core/{ => solidity}/src/erc20.ts | 0 packages/core/{ => solidity}/src/erc721.test.ts | 0 packages/core/{ => solidity}/src/erc721.test.ts.md | 0 .../core/{ => solidity}/src/erc721.test.ts.snap | Bin packages/core/{ => solidity}/src/erc721.ts | 0 packages/core/{ => solidity}/src/error.ts | 0 .../{ => solidity}/src/generate/alternatives.ts | 0 packages/core/{ => solidity}/src/generate/custom.ts | 0 .../core/{ => solidity}/src/generate/erc1155.ts | 0 packages/core/{ => solidity}/src/generate/erc20.ts | 0 packages/core/{ => solidity}/src/generate/erc721.ts | 0 .../core/{ => solidity}/src/generate/governor.ts | 0 .../core/{ => solidity}/src/generate/sources.ts | 0 .../core/{ => solidity}/src/generate/stablecoin.ts | 0 .../core/{ => solidity}/src/get-imports.test.ts | 0 packages/core/{ => solidity}/src/get-imports.ts | 0 packages/core/{ => solidity}/src/governor.test.ts | 0 .../core/{ => solidity}/src/governor.test.ts.md | 0 .../core/{ => solidity}/src/governor.test.ts.snap | Bin packages/core/{ => solidity}/src/governor.ts | 0 packages/core/{ => solidity}/src/index.ts | 0 .../{ => solidity}/src/infer-transpiled.test.ts | 0 .../core/{ => solidity}/src/infer-transpiled.ts | 0 packages/core/{ => solidity}/src/kind.ts | 0 packages/core/{ => solidity}/src/options.ts | 0 packages/core/{ => solidity}/src/print-versioned.ts | 0 packages/core/{ => solidity}/src/print.ts | 0 packages/core/{ => solidity}/src/scripts/prepare.ts | 0 .../core/{ => solidity}/src/set-access-control.ts | 0 packages/core/{ => solidity}/src/set-clock-mode.ts | 0 packages/core/{ => solidity}/src/set-info.ts | 0 packages/core/{ => solidity}/src/set-upgradeable.ts | 0 .../core/{ => solidity}/src/solidity-version.json | 0 packages/core/{ => solidity}/src/stablecoin.test.ts | 0 .../core/{ => solidity}/src/stablecoin.test.ts.md | 0 .../core/{ => solidity}/src/stablecoin.test.ts.snap | Bin packages/core/{ => solidity}/src/stablecoin.ts | 0 packages/core/{ => solidity}/src/test.ts | 0 .../{ => solidity}/src/utils/define-functions.ts | 0 packages/core/{ => solidity}/src/utils/duration.ts | 0 .../core/{ => solidity}/src/utils/find-cover.ts | 0 .../core/{ => solidity}/src/utils/format-lines.ts | 0 .../core/{ => solidity}/src/utils/map-values.ts | 0 packages/core/{ => solidity}/src/utils/sorted-by.ts | 0 .../{ => solidity}/src/utils/to-identifier.test.ts | 0 .../core/{ => solidity}/src/utils/to-identifier.ts | 0 .../{ => solidity}/src/utils/transitive-closure.ts | 0 .../core/{ => solidity}/src/utils/version.test.ts | 0 packages/core/{ => solidity}/src/utils/version.ts | 0 .../core/{ => solidity}/src/zip-foundry.test.ts | 0 .../core/{ => solidity}/src/zip-foundry.test.ts.md | 0 .../{ => solidity}/src/zip-foundry.test.ts.snap | Bin packages/core/{ => solidity}/src/zip-foundry.ts | 0 .../core/{ => solidity}/src/zip-hardhat.test.ts | 0 .../core/{ => solidity}/src/zip-hardhat.test.ts.md | 0 .../{ => solidity}/src/zip-hardhat.test.ts.snap | Bin packages/core/{ => solidity}/src/zip-hardhat.ts | 0 packages/core/{ => solidity}/tsconfig.json | 2 +- packages/core/{ => solidity}/zip-env-foundry.js | 0 packages/core/{ => solidity}/zip-env-foundry.ts | 0 packages/core/{ => solidity}/zip-env-hardhat.js | 0 packages/core/{ => solidity}/zip-env-hardhat.ts | 0 packages/ui/rollup.config.mjs | 4 ++-- packages/ui/tsconfig.json | 2 +- 182 files changed, 14 insertions(+), 13 deletions(-) rename packages/{core-cairo => core/cairo}/.gitignore (100%) rename packages/{core-cairo => core/cairo}/CHANGELOG.md (100%) rename packages/{core-cairo => core/cairo}/LICENSE (100%) rename packages/{core-cairo => core/cairo}/NOTICE (100%) rename packages/{core-cairo => core/cairo}/README.md (100%) rename packages/{core-cairo => core/cairo}/ava.config.js (100%) rename packages/{core-cairo => core/cairo}/package.json (93%) rename packages/{core-cairo => core/cairo}/src/account.test.ts (100%) rename packages/{core-cairo => core/cairo}/src/account.test.ts.md (100%) rename packages/{core-cairo => core/cairo}/src/account.test.ts.snap (100%) rename packages/{core-cairo => core/cairo}/src/account.ts (100%) rename packages/{core-cairo => core/cairo}/src/add-pausable.ts (100%) rename packages/{core-cairo => core/cairo}/src/api.ts (100%) rename packages/{core-cairo => core/cairo}/src/build-generic.ts (100%) rename packages/{core-cairo => core/cairo}/src/common-components.ts (100%) rename packages/{core-cairo => core/cairo}/src/common-options.ts (100%) rename packages/{core-cairo => core/cairo}/src/contract.test.ts (100%) rename packages/{core-cairo => core/cairo}/src/contract.test.ts.md (100%) rename packages/{core-cairo => core/cairo}/src/contract.test.ts.snap (100%) rename packages/{core-cairo => core/cairo}/src/contract.ts (100%) rename packages/{core-cairo => core/cairo}/src/custom.test.ts (100%) rename packages/{core-cairo => core/cairo}/src/custom.test.ts.md (100%) rename packages/{core-cairo => core/cairo}/src/custom.test.ts.snap (100%) rename packages/{core-cairo => core/cairo}/src/custom.ts (100%) rename packages/{core-cairo => core/cairo}/src/erc1155.test.ts (100%) rename packages/{core-cairo => core/cairo}/src/erc1155.test.ts.md (100%) rename packages/{core-cairo => core/cairo}/src/erc1155.test.ts.snap (100%) rename packages/{core-cairo => core/cairo}/src/erc1155.ts (100%) rename packages/{core-cairo => core/cairo}/src/erc20.test.ts (100%) rename packages/{core-cairo => core/cairo}/src/erc20.test.ts.md (100%) rename packages/{core-cairo => core/cairo}/src/erc20.test.ts.snap (100%) rename packages/{core-cairo => core/cairo}/src/erc20.ts (100%) rename packages/{core-cairo => core/cairo}/src/erc721.test.ts (100%) rename packages/{core-cairo => core/cairo}/src/erc721.test.ts.md (100%) rename packages/{core-cairo => core/cairo}/src/erc721.test.ts.snap (100%) rename packages/{core-cairo => core/cairo}/src/erc721.ts (100%) rename packages/{core-cairo => core/cairo}/src/error.ts (100%) rename packages/{core-cairo => core/cairo}/src/external-trait.ts (100%) rename packages/{core-cairo => core/cairo}/src/generate/account.ts (100%) rename packages/{core-cairo => core/cairo}/src/generate/alternatives.ts (100%) rename packages/{core-cairo => core/cairo}/src/generate/custom.ts (100%) rename packages/{core-cairo => core/cairo}/src/generate/erc1155.ts (100%) rename packages/{core-cairo => core/cairo}/src/generate/erc20.ts (100%) rename packages/{core-cairo => core/cairo}/src/generate/erc721.ts (100%) rename packages/{core-cairo => core/cairo}/src/generate/governor.ts (100%) rename packages/{core-cairo => core/cairo}/src/generate/sources.ts (100%) rename packages/{core-cairo => core/cairo}/src/generate/vesting.ts (100%) rename packages/{core-cairo => core/cairo}/src/governor.test.ts (100%) rename packages/{core-cairo => core/cairo}/src/governor.test.ts.md (100%) rename packages/{core-cairo => core/cairo}/src/governor.test.ts.snap (100%) rename packages/{core-cairo => core/cairo}/src/governor.ts (100%) rename packages/{core-cairo => core/cairo}/src/index.ts (100%) rename packages/{core-cairo => core/cairo}/src/kind.ts (100%) rename packages/{core-cairo => core/cairo}/src/print.ts (100%) rename packages/{core-cairo => core/cairo}/src/scripts/update-scarb-project.ts (100%) rename packages/{core-cairo => core/cairo}/src/set-access-control.ts (100%) rename packages/{core-cairo => core/cairo}/src/set-info.ts (100%) rename packages/{core-cairo => core/cairo}/src/set-royalty-info.ts (100%) rename packages/{core-cairo => core/cairo}/src/set-upgradeable.ts (100%) rename packages/{core-cairo => core/cairo}/src/test.ts (100%) rename packages/{core-cairo => core/cairo}/src/utils/convert-strings.test.ts (100%) rename packages/{core-cairo => core/cairo}/src/utils/convert-strings.ts (100%) rename packages/{core-cairo => core/cairo}/src/utils/define-components.ts (100%) rename packages/{core-cairo => core/cairo}/src/utils/define-functions.ts (100%) rename packages/{core-cairo => core/cairo}/src/utils/duration.ts (100%) rename packages/{core-cairo => core/cairo}/src/utils/find-cover.ts (100%) rename packages/{core-cairo => core/cairo}/src/utils/format-lines.ts (100%) rename packages/{core-cairo => core/cairo}/src/utils/sorted-by.ts (100%) rename packages/{core-cairo => core/cairo}/src/utils/version.test.ts (100%) rename packages/{core-cairo => core/cairo}/src/utils/version.ts (100%) rename packages/{core-cairo => core/cairo}/src/vesting.test.ts (100%) rename packages/{core-cairo => core/cairo}/src/vesting.test.ts.md (100%) rename packages/{core-cairo => core/cairo}/src/vesting.test.ts.snap (100%) rename packages/{core-cairo => core/cairo}/src/vesting.ts (100%) rename packages/{core-cairo => core/cairo}/test_project/.gitignore (100%) rename packages/{core-cairo => core/cairo}/test_project/Scarb.lock (100%) rename packages/{core-cairo => core/cairo}/test_project/Scarb.toml (100%) rename packages/{core-cairo => core/cairo}/tsconfig.json (85%) rename packages/core/{ => solidity}/.gitignore (100%) rename packages/core/{ => solidity}/CHANGELOG.md (100%) rename packages/core/{ => solidity}/LICENSE (100%) rename packages/core/{ => solidity}/NOTICE (100%) rename packages/core/{ => solidity}/README.md (100%) rename packages/core/{ => solidity}/ava.config.js (100%) rename packages/core/{ => solidity}/contracts/SafetyCheck.sol (100%) rename packages/core/{ => solidity}/get-imports.d.ts (100%) rename packages/core/{ => solidity}/get-imports.js (100%) rename packages/core/{ => solidity}/hardhat.config.js (100%) rename packages/core/{ => solidity}/openzeppelin-contracts.d.ts (100%) rename packages/core/{ => solidity}/package.json (95%) rename packages/core/{ => solidity}/print-versioned.js (100%) rename packages/core/{ => solidity}/print-versioned.ts (100%) rename packages/core/{ => solidity}/src/add-pausable.ts (100%) rename packages/core/{ => solidity}/src/api.ts (100%) rename packages/core/{ => solidity}/src/build-generic.ts (100%) rename packages/core/{ => solidity}/src/common-functions.ts (100%) rename packages/core/{ => solidity}/src/common-options.ts (100%) rename packages/core/{ => solidity}/src/contract.test.ts (100%) rename packages/core/{ => solidity}/src/contract.test.ts.md (100%) rename packages/core/{ => solidity}/src/contract.test.ts.snap (100%) rename packages/core/{ => solidity}/src/contract.ts (100%) rename packages/core/{ => solidity}/src/custom.test.ts (100%) rename packages/core/{ => solidity}/src/custom.test.ts.md (100%) rename packages/core/{ => solidity}/src/custom.test.ts.snap (100%) rename packages/core/{ => solidity}/src/custom.ts (100%) rename packages/core/{ => solidity}/src/environments/hardhat/package-lock.json (100%) rename packages/core/{ => solidity}/src/environments/hardhat/package.json (100%) rename packages/core/{ => solidity}/src/environments/hardhat/upgradeable/package-lock.json (100%) rename packages/core/{ => solidity}/src/environments/hardhat/upgradeable/package.json (100%) rename packages/core/{ => solidity}/src/erc1155.test.ts (100%) rename packages/core/{ => solidity}/src/erc1155.test.ts.md (100%) rename packages/core/{ => solidity}/src/erc1155.test.ts.snap (100%) rename packages/core/{ => solidity}/src/erc1155.ts (100%) rename packages/core/{ => solidity}/src/erc20.test.ts (100%) rename packages/core/{ => solidity}/src/erc20.test.ts.md (100%) rename packages/core/{ => solidity}/src/erc20.test.ts.snap (100%) rename packages/core/{ => solidity}/src/erc20.ts (100%) rename packages/core/{ => solidity}/src/erc721.test.ts (100%) rename packages/core/{ => solidity}/src/erc721.test.ts.md (100%) rename packages/core/{ => solidity}/src/erc721.test.ts.snap (100%) rename packages/core/{ => solidity}/src/erc721.ts (100%) rename packages/core/{ => solidity}/src/error.ts (100%) rename packages/core/{ => solidity}/src/generate/alternatives.ts (100%) rename packages/core/{ => solidity}/src/generate/custom.ts (100%) rename packages/core/{ => solidity}/src/generate/erc1155.ts (100%) rename packages/core/{ => solidity}/src/generate/erc20.ts (100%) rename packages/core/{ => solidity}/src/generate/erc721.ts (100%) rename packages/core/{ => solidity}/src/generate/governor.ts (100%) rename packages/core/{ => solidity}/src/generate/sources.ts (100%) rename packages/core/{ => solidity}/src/generate/stablecoin.ts (100%) rename packages/core/{ => solidity}/src/get-imports.test.ts (100%) rename packages/core/{ => solidity}/src/get-imports.ts (100%) rename packages/core/{ => solidity}/src/governor.test.ts (100%) rename packages/core/{ => solidity}/src/governor.test.ts.md (100%) rename packages/core/{ => solidity}/src/governor.test.ts.snap (100%) rename packages/core/{ => solidity}/src/governor.ts (100%) rename packages/core/{ => solidity}/src/index.ts (100%) rename packages/core/{ => solidity}/src/infer-transpiled.test.ts (100%) rename packages/core/{ => solidity}/src/infer-transpiled.ts (100%) rename packages/core/{ => solidity}/src/kind.ts (100%) rename packages/core/{ => solidity}/src/options.ts (100%) rename packages/core/{ => solidity}/src/print-versioned.ts (100%) rename packages/core/{ => solidity}/src/print.ts (100%) rename packages/core/{ => solidity}/src/scripts/prepare.ts (100%) rename packages/core/{ => solidity}/src/set-access-control.ts (100%) rename packages/core/{ => solidity}/src/set-clock-mode.ts (100%) rename packages/core/{ => solidity}/src/set-info.ts (100%) rename packages/core/{ => solidity}/src/set-upgradeable.ts (100%) rename packages/core/{ => solidity}/src/solidity-version.json (100%) rename packages/core/{ => solidity}/src/stablecoin.test.ts (100%) rename packages/core/{ => solidity}/src/stablecoin.test.ts.md (100%) rename packages/core/{ => solidity}/src/stablecoin.test.ts.snap (100%) rename packages/core/{ => solidity}/src/stablecoin.ts (100%) rename packages/core/{ => solidity}/src/test.ts (100%) rename packages/core/{ => solidity}/src/utils/define-functions.ts (100%) rename packages/core/{ => solidity}/src/utils/duration.ts (100%) rename packages/core/{ => solidity}/src/utils/find-cover.ts (100%) rename packages/core/{ => solidity}/src/utils/format-lines.ts (100%) rename packages/core/{ => solidity}/src/utils/map-values.ts (100%) rename packages/core/{ => solidity}/src/utils/sorted-by.ts (100%) rename packages/core/{ => solidity}/src/utils/to-identifier.test.ts (100%) rename packages/core/{ => solidity}/src/utils/to-identifier.ts (100%) rename packages/core/{ => solidity}/src/utils/transitive-closure.ts (100%) rename packages/core/{ => solidity}/src/utils/version.test.ts (100%) rename packages/core/{ => solidity}/src/utils/version.ts (100%) rename packages/core/{ => solidity}/src/zip-foundry.test.ts (100%) rename packages/core/{ => solidity}/src/zip-foundry.test.ts.md (100%) rename packages/core/{ => solidity}/src/zip-foundry.test.ts.snap (100%) rename packages/core/{ => solidity}/src/zip-foundry.ts (100%) rename packages/core/{ => solidity}/src/zip-hardhat.test.ts (100%) rename packages/core/{ => solidity}/src/zip-hardhat.test.ts.md (100%) rename packages/core/{ => solidity}/src/zip-hardhat.test.ts.snap (100%) rename packages/core/{ => solidity}/src/zip-hardhat.ts (100%) rename packages/core/{ => solidity}/tsconfig.json (85%) rename packages/core/{ => solidity}/zip-env-foundry.js (100%) rename packages/core/{ => solidity}/zip-env-foundry.ts (100%) rename packages/core/{ => solidity}/zip-env-hardhat.js (100%) rename packages/core/{ => solidity}/zip-env-hardhat.ts (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 70d51847e..4b5ab7d6c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,8 +10,8 @@ jobs: strategy: matrix: package: - - core - - core-cairo + - solidity + - cairo runs-on: ubuntu-latest steps: @@ -21,16 +21,16 @@ jobs: node-version: 18.x cache: 'yarn' - name: Install Foundry - if: matrix.package == 'core' + if: matrix.package == 'solidity' uses: foundry-rs/foundry-toolchain@v1 - name: Install dependencies run: yarn install --network-concurrency 1 - name: Compile TypeScript run: yarn tsc - working-directory: packages/${{matrix.package}} + working-directory: packages/core/${{matrix.package}} - name: Check Svelte run: yarn svelte-check working-directory: packages/ui - name: Run tests run: yarn test - working-directory: packages/${{matrix.package}} + working-directory: packages/core/${{matrix.package}} diff --git a/package.json b/package.json index 18a3f0663..c6c359d09 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ }, "workspaces": { "packages": [ - "packages/*" + "packages/core/*", + "packages/ui" ], "nohoist": [ "**/@types/*", diff --git a/packages/core-cairo/.gitignore b/packages/core/cairo/.gitignore similarity index 100% rename from packages/core-cairo/.gitignore rename to packages/core/cairo/.gitignore diff --git a/packages/core-cairo/CHANGELOG.md b/packages/core/cairo/CHANGELOG.md similarity index 100% rename from packages/core-cairo/CHANGELOG.md rename to packages/core/cairo/CHANGELOG.md diff --git a/packages/core-cairo/LICENSE b/packages/core/cairo/LICENSE similarity index 100% rename from packages/core-cairo/LICENSE rename to packages/core/cairo/LICENSE diff --git a/packages/core-cairo/NOTICE b/packages/core/cairo/NOTICE similarity index 100% rename from packages/core-cairo/NOTICE rename to packages/core/cairo/NOTICE diff --git a/packages/core-cairo/README.md b/packages/core/cairo/README.md similarity index 100% rename from packages/core-cairo/README.md rename to packages/core/cairo/README.md diff --git a/packages/core-cairo/ava.config.js b/packages/core/cairo/ava.config.js similarity index 100% rename from packages/core-cairo/ava.config.js rename to packages/core/cairo/ava.config.js diff --git a/packages/core-cairo/package.json b/packages/core/cairo/package.json similarity index 93% rename from packages/core-cairo/package.json rename to packages/core/cairo/package.json index 6cab34438..3e61b4fda 100644 --- a/packages/core-cairo/package.json +++ b/packages/core/cairo/package.json @@ -19,7 +19,7 @@ "prepublish": "rimraf dist *.tsbuildinfo", "test": "ava", "test:watch": "ava --watch", - "version": "node ../../scripts/bump-changelog.js" + "version": "node ../../../scripts/bump-changelog.js" }, "devDependencies": { "@types/node": "^18.0.0", diff --git a/packages/core-cairo/src/account.test.ts b/packages/core/cairo/src/account.test.ts similarity index 100% rename from packages/core-cairo/src/account.test.ts rename to packages/core/cairo/src/account.test.ts diff --git a/packages/core-cairo/src/account.test.ts.md b/packages/core/cairo/src/account.test.ts.md similarity index 100% rename from packages/core-cairo/src/account.test.ts.md rename to packages/core/cairo/src/account.test.ts.md diff --git a/packages/core-cairo/src/account.test.ts.snap b/packages/core/cairo/src/account.test.ts.snap similarity index 100% rename from packages/core-cairo/src/account.test.ts.snap rename to packages/core/cairo/src/account.test.ts.snap diff --git a/packages/core-cairo/src/account.ts b/packages/core/cairo/src/account.ts similarity index 100% rename from packages/core-cairo/src/account.ts rename to packages/core/cairo/src/account.ts diff --git a/packages/core-cairo/src/add-pausable.ts b/packages/core/cairo/src/add-pausable.ts similarity index 100% rename from packages/core-cairo/src/add-pausable.ts rename to packages/core/cairo/src/add-pausable.ts diff --git a/packages/core-cairo/src/api.ts b/packages/core/cairo/src/api.ts similarity index 100% rename from packages/core-cairo/src/api.ts rename to packages/core/cairo/src/api.ts diff --git a/packages/core-cairo/src/build-generic.ts b/packages/core/cairo/src/build-generic.ts similarity index 100% rename from packages/core-cairo/src/build-generic.ts rename to packages/core/cairo/src/build-generic.ts diff --git a/packages/core-cairo/src/common-components.ts b/packages/core/cairo/src/common-components.ts similarity index 100% rename from packages/core-cairo/src/common-components.ts rename to packages/core/cairo/src/common-components.ts diff --git a/packages/core-cairo/src/common-options.ts b/packages/core/cairo/src/common-options.ts similarity index 100% rename from packages/core-cairo/src/common-options.ts rename to packages/core/cairo/src/common-options.ts diff --git a/packages/core-cairo/src/contract.test.ts b/packages/core/cairo/src/contract.test.ts similarity index 100% rename from packages/core-cairo/src/contract.test.ts rename to packages/core/cairo/src/contract.test.ts diff --git a/packages/core-cairo/src/contract.test.ts.md b/packages/core/cairo/src/contract.test.ts.md similarity index 100% rename from packages/core-cairo/src/contract.test.ts.md rename to packages/core/cairo/src/contract.test.ts.md diff --git a/packages/core-cairo/src/contract.test.ts.snap b/packages/core/cairo/src/contract.test.ts.snap similarity index 100% rename from packages/core-cairo/src/contract.test.ts.snap rename to packages/core/cairo/src/contract.test.ts.snap diff --git a/packages/core-cairo/src/contract.ts b/packages/core/cairo/src/contract.ts similarity index 100% rename from packages/core-cairo/src/contract.ts rename to packages/core/cairo/src/contract.ts diff --git a/packages/core-cairo/src/custom.test.ts b/packages/core/cairo/src/custom.test.ts similarity index 100% rename from packages/core-cairo/src/custom.test.ts rename to packages/core/cairo/src/custom.test.ts diff --git a/packages/core-cairo/src/custom.test.ts.md b/packages/core/cairo/src/custom.test.ts.md similarity index 100% rename from packages/core-cairo/src/custom.test.ts.md rename to packages/core/cairo/src/custom.test.ts.md diff --git a/packages/core-cairo/src/custom.test.ts.snap b/packages/core/cairo/src/custom.test.ts.snap similarity index 100% rename from packages/core-cairo/src/custom.test.ts.snap rename to packages/core/cairo/src/custom.test.ts.snap diff --git a/packages/core-cairo/src/custom.ts b/packages/core/cairo/src/custom.ts similarity index 100% rename from packages/core-cairo/src/custom.ts rename to packages/core/cairo/src/custom.ts diff --git a/packages/core-cairo/src/erc1155.test.ts b/packages/core/cairo/src/erc1155.test.ts similarity index 100% rename from packages/core-cairo/src/erc1155.test.ts rename to packages/core/cairo/src/erc1155.test.ts diff --git a/packages/core-cairo/src/erc1155.test.ts.md b/packages/core/cairo/src/erc1155.test.ts.md similarity index 100% rename from packages/core-cairo/src/erc1155.test.ts.md rename to packages/core/cairo/src/erc1155.test.ts.md diff --git a/packages/core-cairo/src/erc1155.test.ts.snap b/packages/core/cairo/src/erc1155.test.ts.snap similarity index 100% rename from packages/core-cairo/src/erc1155.test.ts.snap rename to packages/core/cairo/src/erc1155.test.ts.snap diff --git a/packages/core-cairo/src/erc1155.ts b/packages/core/cairo/src/erc1155.ts similarity index 100% rename from packages/core-cairo/src/erc1155.ts rename to packages/core/cairo/src/erc1155.ts diff --git a/packages/core-cairo/src/erc20.test.ts b/packages/core/cairo/src/erc20.test.ts similarity index 100% rename from packages/core-cairo/src/erc20.test.ts rename to packages/core/cairo/src/erc20.test.ts diff --git a/packages/core-cairo/src/erc20.test.ts.md b/packages/core/cairo/src/erc20.test.ts.md similarity index 100% rename from packages/core-cairo/src/erc20.test.ts.md rename to packages/core/cairo/src/erc20.test.ts.md diff --git a/packages/core-cairo/src/erc20.test.ts.snap b/packages/core/cairo/src/erc20.test.ts.snap similarity index 100% rename from packages/core-cairo/src/erc20.test.ts.snap rename to packages/core/cairo/src/erc20.test.ts.snap diff --git a/packages/core-cairo/src/erc20.ts b/packages/core/cairo/src/erc20.ts similarity index 100% rename from packages/core-cairo/src/erc20.ts rename to packages/core/cairo/src/erc20.ts diff --git a/packages/core-cairo/src/erc721.test.ts b/packages/core/cairo/src/erc721.test.ts similarity index 100% rename from packages/core-cairo/src/erc721.test.ts rename to packages/core/cairo/src/erc721.test.ts diff --git a/packages/core-cairo/src/erc721.test.ts.md b/packages/core/cairo/src/erc721.test.ts.md similarity index 100% rename from packages/core-cairo/src/erc721.test.ts.md rename to packages/core/cairo/src/erc721.test.ts.md diff --git a/packages/core-cairo/src/erc721.test.ts.snap b/packages/core/cairo/src/erc721.test.ts.snap similarity index 100% rename from packages/core-cairo/src/erc721.test.ts.snap rename to packages/core/cairo/src/erc721.test.ts.snap diff --git a/packages/core-cairo/src/erc721.ts b/packages/core/cairo/src/erc721.ts similarity index 100% rename from packages/core-cairo/src/erc721.ts rename to packages/core/cairo/src/erc721.ts diff --git a/packages/core-cairo/src/error.ts b/packages/core/cairo/src/error.ts similarity index 100% rename from packages/core-cairo/src/error.ts rename to packages/core/cairo/src/error.ts diff --git a/packages/core-cairo/src/external-trait.ts b/packages/core/cairo/src/external-trait.ts similarity index 100% rename from packages/core-cairo/src/external-trait.ts rename to packages/core/cairo/src/external-trait.ts diff --git a/packages/core-cairo/src/generate/account.ts b/packages/core/cairo/src/generate/account.ts similarity index 100% rename from packages/core-cairo/src/generate/account.ts rename to packages/core/cairo/src/generate/account.ts diff --git a/packages/core-cairo/src/generate/alternatives.ts b/packages/core/cairo/src/generate/alternatives.ts similarity index 100% rename from packages/core-cairo/src/generate/alternatives.ts rename to packages/core/cairo/src/generate/alternatives.ts diff --git a/packages/core-cairo/src/generate/custom.ts b/packages/core/cairo/src/generate/custom.ts similarity index 100% rename from packages/core-cairo/src/generate/custom.ts rename to packages/core/cairo/src/generate/custom.ts diff --git a/packages/core-cairo/src/generate/erc1155.ts b/packages/core/cairo/src/generate/erc1155.ts similarity index 100% rename from packages/core-cairo/src/generate/erc1155.ts rename to packages/core/cairo/src/generate/erc1155.ts diff --git a/packages/core-cairo/src/generate/erc20.ts b/packages/core/cairo/src/generate/erc20.ts similarity index 100% rename from packages/core-cairo/src/generate/erc20.ts rename to packages/core/cairo/src/generate/erc20.ts diff --git a/packages/core-cairo/src/generate/erc721.ts b/packages/core/cairo/src/generate/erc721.ts similarity index 100% rename from packages/core-cairo/src/generate/erc721.ts rename to packages/core/cairo/src/generate/erc721.ts diff --git a/packages/core-cairo/src/generate/governor.ts b/packages/core/cairo/src/generate/governor.ts similarity index 100% rename from packages/core-cairo/src/generate/governor.ts rename to packages/core/cairo/src/generate/governor.ts diff --git a/packages/core-cairo/src/generate/sources.ts b/packages/core/cairo/src/generate/sources.ts similarity index 100% rename from packages/core-cairo/src/generate/sources.ts rename to packages/core/cairo/src/generate/sources.ts diff --git a/packages/core-cairo/src/generate/vesting.ts b/packages/core/cairo/src/generate/vesting.ts similarity index 100% rename from packages/core-cairo/src/generate/vesting.ts rename to packages/core/cairo/src/generate/vesting.ts diff --git a/packages/core-cairo/src/governor.test.ts b/packages/core/cairo/src/governor.test.ts similarity index 100% rename from packages/core-cairo/src/governor.test.ts rename to packages/core/cairo/src/governor.test.ts diff --git a/packages/core-cairo/src/governor.test.ts.md b/packages/core/cairo/src/governor.test.ts.md similarity index 100% rename from packages/core-cairo/src/governor.test.ts.md rename to packages/core/cairo/src/governor.test.ts.md diff --git a/packages/core-cairo/src/governor.test.ts.snap b/packages/core/cairo/src/governor.test.ts.snap similarity index 100% rename from packages/core-cairo/src/governor.test.ts.snap rename to packages/core/cairo/src/governor.test.ts.snap diff --git a/packages/core-cairo/src/governor.ts b/packages/core/cairo/src/governor.ts similarity index 100% rename from packages/core-cairo/src/governor.ts rename to packages/core/cairo/src/governor.ts diff --git a/packages/core-cairo/src/index.ts b/packages/core/cairo/src/index.ts similarity index 100% rename from packages/core-cairo/src/index.ts rename to packages/core/cairo/src/index.ts diff --git a/packages/core-cairo/src/kind.ts b/packages/core/cairo/src/kind.ts similarity index 100% rename from packages/core-cairo/src/kind.ts rename to packages/core/cairo/src/kind.ts diff --git a/packages/core-cairo/src/print.ts b/packages/core/cairo/src/print.ts similarity index 100% rename from packages/core-cairo/src/print.ts rename to packages/core/cairo/src/print.ts diff --git a/packages/core-cairo/src/scripts/update-scarb-project.ts b/packages/core/cairo/src/scripts/update-scarb-project.ts similarity index 100% rename from packages/core-cairo/src/scripts/update-scarb-project.ts rename to packages/core/cairo/src/scripts/update-scarb-project.ts diff --git a/packages/core-cairo/src/set-access-control.ts b/packages/core/cairo/src/set-access-control.ts similarity index 100% rename from packages/core-cairo/src/set-access-control.ts rename to packages/core/cairo/src/set-access-control.ts diff --git a/packages/core-cairo/src/set-info.ts b/packages/core/cairo/src/set-info.ts similarity index 100% rename from packages/core-cairo/src/set-info.ts rename to packages/core/cairo/src/set-info.ts diff --git a/packages/core-cairo/src/set-royalty-info.ts b/packages/core/cairo/src/set-royalty-info.ts similarity index 100% rename from packages/core-cairo/src/set-royalty-info.ts rename to packages/core/cairo/src/set-royalty-info.ts diff --git a/packages/core-cairo/src/set-upgradeable.ts b/packages/core/cairo/src/set-upgradeable.ts similarity index 100% rename from packages/core-cairo/src/set-upgradeable.ts rename to packages/core/cairo/src/set-upgradeable.ts diff --git a/packages/core-cairo/src/test.ts b/packages/core/cairo/src/test.ts similarity index 100% rename from packages/core-cairo/src/test.ts rename to packages/core/cairo/src/test.ts diff --git a/packages/core-cairo/src/utils/convert-strings.test.ts b/packages/core/cairo/src/utils/convert-strings.test.ts similarity index 100% rename from packages/core-cairo/src/utils/convert-strings.test.ts rename to packages/core/cairo/src/utils/convert-strings.test.ts diff --git a/packages/core-cairo/src/utils/convert-strings.ts b/packages/core/cairo/src/utils/convert-strings.ts similarity index 100% rename from packages/core-cairo/src/utils/convert-strings.ts rename to packages/core/cairo/src/utils/convert-strings.ts diff --git a/packages/core-cairo/src/utils/define-components.ts b/packages/core/cairo/src/utils/define-components.ts similarity index 100% rename from packages/core-cairo/src/utils/define-components.ts rename to packages/core/cairo/src/utils/define-components.ts diff --git a/packages/core-cairo/src/utils/define-functions.ts b/packages/core/cairo/src/utils/define-functions.ts similarity index 100% rename from packages/core-cairo/src/utils/define-functions.ts rename to packages/core/cairo/src/utils/define-functions.ts diff --git a/packages/core-cairo/src/utils/duration.ts b/packages/core/cairo/src/utils/duration.ts similarity index 100% rename from packages/core-cairo/src/utils/duration.ts rename to packages/core/cairo/src/utils/duration.ts diff --git a/packages/core-cairo/src/utils/find-cover.ts b/packages/core/cairo/src/utils/find-cover.ts similarity index 100% rename from packages/core-cairo/src/utils/find-cover.ts rename to packages/core/cairo/src/utils/find-cover.ts diff --git a/packages/core-cairo/src/utils/format-lines.ts b/packages/core/cairo/src/utils/format-lines.ts similarity index 100% rename from packages/core-cairo/src/utils/format-lines.ts rename to packages/core/cairo/src/utils/format-lines.ts diff --git a/packages/core-cairo/src/utils/sorted-by.ts b/packages/core/cairo/src/utils/sorted-by.ts similarity index 100% rename from packages/core-cairo/src/utils/sorted-by.ts rename to packages/core/cairo/src/utils/sorted-by.ts diff --git a/packages/core-cairo/src/utils/version.test.ts b/packages/core/cairo/src/utils/version.test.ts similarity index 100% rename from packages/core-cairo/src/utils/version.test.ts rename to packages/core/cairo/src/utils/version.test.ts diff --git a/packages/core-cairo/src/utils/version.ts b/packages/core/cairo/src/utils/version.ts similarity index 100% rename from packages/core-cairo/src/utils/version.ts rename to packages/core/cairo/src/utils/version.ts diff --git a/packages/core-cairo/src/vesting.test.ts b/packages/core/cairo/src/vesting.test.ts similarity index 100% rename from packages/core-cairo/src/vesting.test.ts rename to packages/core/cairo/src/vesting.test.ts diff --git a/packages/core-cairo/src/vesting.test.ts.md b/packages/core/cairo/src/vesting.test.ts.md similarity index 100% rename from packages/core-cairo/src/vesting.test.ts.md rename to packages/core/cairo/src/vesting.test.ts.md diff --git a/packages/core-cairo/src/vesting.test.ts.snap b/packages/core/cairo/src/vesting.test.ts.snap similarity index 100% rename from packages/core-cairo/src/vesting.test.ts.snap rename to packages/core/cairo/src/vesting.test.ts.snap diff --git a/packages/core-cairo/src/vesting.ts b/packages/core/cairo/src/vesting.ts similarity index 100% rename from packages/core-cairo/src/vesting.ts rename to packages/core/cairo/src/vesting.ts diff --git a/packages/core-cairo/test_project/.gitignore b/packages/core/cairo/test_project/.gitignore similarity index 100% rename from packages/core-cairo/test_project/.gitignore rename to packages/core/cairo/test_project/.gitignore diff --git a/packages/core-cairo/test_project/Scarb.lock b/packages/core/cairo/test_project/Scarb.lock similarity index 100% rename from packages/core-cairo/test_project/Scarb.lock rename to packages/core/cairo/test_project/Scarb.lock diff --git a/packages/core-cairo/test_project/Scarb.toml b/packages/core/cairo/test_project/Scarb.toml similarity index 100% rename from packages/core-cairo/test_project/Scarb.toml rename to packages/core/cairo/test_project/Scarb.toml diff --git a/packages/core-cairo/tsconfig.json b/packages/core/cairo/tsconfig.json similarity index 85% rename from packages/core-cairo/tsconfig.json rename to packages/core/cairo/tsconfig.json index f6a21a39d..e51988c6e 100644 --- a/packages/core-cairo/tsconfig.json +++ b/packages/core/cairo/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../tsconfig.base.json", + "extends": "../../../tsconfig.base.json", "compilerOptions": { "incremental": true, "module": "commonjs", diff --git a/packages/core/.gitignore b/packages/core/solidity/.gitignore similarity index 100% rename from packages/core/.gitignore rename to packages/core/solidity/.gitignore diff --git a/packages/core/CHANGELOG.md b/packages/core/solidity/CHANGELOG.md similarity index 100% rename from packages/core/CHANGELOG.md rename to packages/core/solidity/CHANGELOG.md diff --git a/packages/core/LICENSE b/packages/core/solidity/LICENSE similarity index 100% rename from packages/core/LICENSE rename to packages/core/solidity/LICENSE diff --git a/packages/core/NOTICE b/packages/core/solidity/NOTICE similarity index 100% rename from packages/core/NOTICE rename to packages/core/solidity/NOTICE diff --git a/packages/core/README.md b/packages/core/solidity/README.md similarity index 100% rename from packages/core/README.md rename to packages/core/solidity/README.md diff --git a/packages/core/ava.config.js b/packages/core/solidity/ava.config.js similarity index 100% rename from packages/core/ava.config.js rename to packages/core/solidity/ava.config.js diff --git a/packages/core/contracts/SafetyCheck.sol b/packages/core/solidity/contracts/SafetyCheck.sol similarity index 100% rename from packages/core/contracts/SafetyCheck.sol rename to packages/core/solidity/contracts/SafetyCheck.sol diff --git a/packages/core/get-imports.d.ts b/packages/core/solidity/get-imports.d.ts similarity index 100% rename from packages/core/get-imports.d.ts rename to packages/core/solidity/get-imports.d.ts diff --git a/packages/core/get-imports.js b/packages/core/solidity/get-imports.js similarity index 100% rename from packages/core/get-imports.js rename to packages/core/solidity/get-imports.js diff --git a/packages/core/hardhat.config.js b/packages/core/solidity/hardhat.config.js similarity index 100% rename from packages/core/hardhat.config.js rename to packages/core/solidity/hardhat.config.js diff --git a/packages/core/openzeppelin-contracts.d.ts b/packages/core/solidity/openzeppelin-contracts.d.ts similarity index 100% rename from packages/core/openzeppelin-contracts.d.ts rename to packages/core/solidity/openzeppelin-contracts.d.ts diff --git a/packages/core/package.json b/packages/core/solidity/package.json similarity index 95% rename from packages/core/package.json rename to packages/core/solidity/package.json index ae5744f89..86b9ea61c 100644 --- a/packages/core/package.json +++ b/packages/core/solidity/package.json @@ -18,7 +18,7 @@ "prepublish": "rimraf dist *.tsbuildinfo && hardhat clean", "test": "ava", "test:watch": "ava --watch", - "version": "node ../../scripts/bump-changelog.js", + "version": "node ../../../scripts/bump-changelog.js", "update-env": "rm ./src/environments/hardhat/package-lock.json && npm install --package-lock-only --prefix ./src/environments/hardhat && rm ./src/environments/hardhat/upgradeable/package-lock.json && npm install --package-lock-only --prefix ./src/environments/hardhat/upgradeable" }, "devDependencies": { diff --git a/packages/core/print-versioned.js b/packages/core/solidity/print-versioned.js similarity index 100% rename from packages/core/print-versioned.js rename to packages/core/solidity/print-versioned.js diff --git a/packages/core/print-versioned.ts b/packages/core/solidity/print-versioned.ts similarity index 100% rename from packages/core/print-versioned.ts rename to packages/core/solidity/print-versioned.ts diff --git a/packages/core/src/add-pausable.ts b/packages/core/solidity/src/add-pausable.ts similarity index 100% rename from packages/core/src/add-pausable.ts rename to packages/core/solidity/src/add-pausable.ts diff --git a/packages/core/src/api.ts b/packages/core/solidity/src/api.ts similarity index 100% rename from packages/core/src/api.ts rename to packages/core/solidity/src/api.ts diff --git a/packages/core/src/build-generic.ts b/packages/core/solidity/src/build-generic.ts similarity index 100% rename from packages/core/src/build-generic.ts rename to packages/core/solidity/src/build-generic.ts diff --git a/packages/core/src/common-functions.ts b/packages/core/solidity/src/common-functions.ts similarity index 100% rename from packages/core/src/common-functions.ts rename to packages/core/solidity/src/common-functions.ts diff --git a/packages/core/src/common-options.ts b/packages/core/solidity/src/common-options.ts similarity index 100% rename from packages/core/src/common-options.ts rename to packages/core/solidity/src/common-options.ts diff --git a/packages/core/src/contract.test.ts b/packages/core/solidity/src/contract.test.ts similarity index 100% rename from packages/core/src/contract.test.ts rename to packages/core/solidity/src/contract.test.ts diff --git a/packages/core/src/contract.test.ts.md b/packages/core/solidity/src/contract.test.ts.md similarity index 100% rename from packages/core/src/contract.test.ts.md rename to packages/core/solidity/src/contract.test.ts.md diff --git a/packages/core/src/contract.test.ts.snap b/packages/core/solidity/src/contract.test.ts.snap similarity index 100% rename from packages/core/src/contract.test.ts.snap rename to packages/core/solidity/src/contract.test.ts.snap diff --git a/packages/core/src/contract.ts b/packages/core/solidity/src/contract.ts similarity index 100% rename from packages/core/src/contract.ts rename to packages/core/solidity/src/contract.ts diff --git a/packages/core/src/custom.test.ts b/packages/core/solidity/src/custom.test.ts similarity index 100% rename from packages/core/src/custom.test.ts rename to packages/core/solidity/src/custom.test.ts diff --git a/packages/core/src/custom.test.ts.md b/packages/core/solidity/src/custom.test.ts.md similarity index 100% rename from packages/core/src/custom.test.ts.md rename to packages/core/solidity/src/custom.test.ts.md diff --git a/packages/core/src/custom.test.ts.snap b/packages/core/solidity/src/custom.test.ts.snap similarity index 100% rename from packages/core/src/custom.test.ts.snap rename to packages/core/solidity/src/custom.test.ts.snap diff --git a/packages/core/src/custom.ts b/packages/core/solidity/src/custom.ts similarity index 100% rename from packages/core/src/custom.ts rename to packages/core/solidity/src/custom.ts diff --git a/packages/core/src/environments/hardhat/package-lock.json b/packages/core/solidity/src/environments/hardhat/package-lock.json similarity index 100% rename from packages/core/src/environments/hardhat/package-lock.json rename to packages/core/solidity/src/environments/hardhat/package-lock.json diff --git a/packages/core/src/environments/hardhat/package.json b/packages/core/solidity/src/environments/hardhat/package.json similarity index 100% rename from packages/core/src/environments/hardhat/package.json rename to packages/core/solidity/src/environments/hardhat/package.json diff --git a/packages/core/src/environments/hardhat/upgradeable/package-lock.json b/packages/core/solidity/src/environments/hardhat/upgradeable/package-lock.json similarity index 100% rename from packages/core/src/environments/hardhat/upgradeable/package-lock.json rename to packages/core/solidity/src/environments/hardhat/upgradeable/package-lock.json diff --git a/packages/core/src/environments/hardhat/upgradeable/package.json b/packages/core/solidity/src/environments/hardhat/upgradeable/package.json similarity index 100% rename from packages/core/src/environments/hardhat/upgradeable/package.json rename to packages/core/solidity/src/environments/hardhat/upgradeable/package.json diff --git a/packages/core/src/erc1155.test.ts b/packages/core/solidity/src/erc1155.test.ts similarity index 100% rename from packages/core/src/erc1155.test.ts rename to packages/core/solidity/src/erc1155.test.ts diff --git a/packages/core/src/erc1155.test.ts.md b/packages/core/solidity/src/erc1155.test.ts.md similarity index 100% rename from packages/core/src/erc1155.test.ts.md rename to packages/core/solidity/src/erc1155.test.ts.md diff --git a/packages/core/src/erc1155.test.ts.snap b/packages/core/solidity/src/erc1155.test.ts.snap similarity index 100% rename from packages/core/src/erc1155.test.ts.snap rename to packages/core/solidity/src/erc1155.test.ts.snap diff --git a/packages/core/src/erc1155.ts b/packages/core/solidity/src/erc1155.ts similarity index 100% rename from packages/core/src/erc1155.ts rename to packages/core/solidity/src/erc1155.ts diff --git a/packages/core/src/erc20.test.ts b/packages/core/solidity/src/erc20.test.ts similarity index 100% rename from packages/core/src/erc20.test.ts rename to packages/core/solidity/src/erc20.test.ts diff --git a/packages/core/src/erc20.test.ts.md b/packages/core/solidity/src/erc20.test.ts.md similarity index 100% rename from packages/core/src/erc20.test.ts.md rename to packages/core/solidity/src/erc20.test.ts.md diff --git a/packages/core/src/erc20.test.ts.snap b/packages/core/solidity/src/erc20.test.ts.snap similarity index 100% rename from packages/core/src/erc20.test.ts.snap rename to packages/core/solidity/src/erc20.test.ts.snap diff --git a/packages/core/src/erc20.ts b/packages/core/solidity/src/erc20.ts similarity index 100% rename from packages/core/src/erc20.ts rename to packages/core/solidity/src/erc20.ts diff --git a/packages/core/src/erc721.test.ts b/packages/core/solidity/src/erc721.test.ts similarity index 100% rename from packages/core/src/erc721.test.ts rename to packages/core/solidity/src/erc721.test.ts diff --git a/packages/core/src/erc721.test.ts.md b/packages/core/solidity/src/erc721.test.ts.md similarity index 100% rename from packages/core/src/erc721.test.ts.md rename to packages/core/solidity/src/erc721.test.ts.md diff --git a/packages/core/src/erc721.test.ts.snap b/packages/core/solidity/src/erc721.test.ts.snap similarity index 100% rename from packages/core/src/erc721.test.ts.snap rename to packages/core/solidity/src/erc721.test.ts.snap diff --git a/packages/core/src/erc721.ts b/packages/core/solidity/src/erc721.ts similarity index 100% rename from packages/core/src/erc721.ts rename to packages/core/solidity/src/erc721.ts diff --git a/packages/core/src/error.ts b/packages/core/solidity/src/error.ts similarity index 100% rename from packages/core/src/error.ts rename to packages/core/solidity/src/error.ts diff --git a/packages/core/src/generate/alternatives.ts b/packages/core/solidity/src/generate/alternatives.ts similarity index 100% rename from packages/core/src/generate/alternatives.ts rename to packages/core/solidity/src/generate/alternatives.ts diff --git a/packages/core/src/generate/custom.ts b/packages/core/solidity/src/generate/custom.ts similarity index 100% rename from packages/core/src/generate/custom.ts rename to packages/core/solidity/src/generate/custom.ts diff --git a/packages/core/src/generate/erc1155.ts b/packages/core/solidity/src/generate/erc1155.ts similarity index 100% rename from packages/core/src/generate/erc1155.ts rename to packages/core/solidity/src/generate/erc1155.ts diff --git a/packages/core/src/generate/erc20.ts b/packages/core/solidity/src/generate/erc20.ts similarity index 100% rename from packages/core/src/generate/erc20.ts rename to packages/core/solidity/src/generate/erc20.ts diff --git a/packages/core/src/generate/erc721.ts b/packages/core/solidity/src/generate/erc721.ts similarity index 100% rename from packages/core/src/generate/erc721.ts rename to packages/core/solidity/src/generate/erc721.ts diff --git a/packages/core/src/generate/governor.ts b/packages/core/solidity/src/generate/governor.ts similarity index 100% rename from packages/core/src/generate/governor.ts rename to packages/core/solidity/src/generate/governor.ts diff --git a/packages/core/src/generate/sources.ts b/packages/core/solidity/src/generate/sources.ts similarity index 100% rename from packages/core/src/generate/sources.ts rename to packages/core/solidity/src/generate/sources.ts diff --git a/packages/core/src/generate/stablecoin.ts b/packages/core/solidity/src/generate/stablecoin.ts similarity index 100% rename from packages/core/src/generate/stablecoin.ts rename to packages/core/solidity/src/generate/stablecoin.ts diff --git a/packages/core/src/get-imports.test.ts b/packages/core/solidity/src/get-imports.test.ts similarity index 100% rename from packages/core/src/get-imports.test.ts rename to packages/core/solidity/src/get-imports.test.ts diff --git a/packages/core/src/get-imports.ts b/packages/core/solidity/src/get-imports.ts similarity index 100% rename from packages/core/src/get-imports.ts rename to packages/core/solidity/src/get-imports.ts diff --git a/packages/core/src/governor.test.ts b/packages/core/solidity/src/governor.test.ts similarity index 100% rename from packages/core/src/governor.test.ts rename to packages/core/solidity/src/governor.test.ts diff --git a/packages/core/src/governor.test.ts.md b/packages/core/solidity/src/governor.test.ts.md similarity index 100% rename from packages/core/src/governor.test.ts.md rename to packages/core/solidity/src/governor.test.ts.md diff --git a/packages/core/src/governor.test.ts.snap b/packages/core/solidity/src/governor.test.ts.snap similarity index 100% rename from packages/core/src/governor.test.ts.snap rename to packages/core/solidity/src/governor.test.ts.snap diff --git a/packages/core/src/governor.ts b/packages/core/solidity/src/governor.ts similarity index 100% rename from packages/core/src/governor.ts rename to packages/core/solidity/src/governor.ts diff --git a/packages/core/src/index.ts b/packages/core/solidity/src/index.ts similarity index 100% rename from packages/core/src/index.ts rename to packages/core/solidity/src/index.ts diff --git a/packages/core/src/infer-transpiled.test.ts b/packages/core/solidity/src/infer-transpiled.test.ts similarity index 100% rename from packages/core/src/infer-transpiled.test.ts rename to packages/core/solidity/src/infer-transpiled.test.ts diff --git a/packages/core/src/infer-transpiled.ts b/packages/core/solidity/src/infer-transpiled.ts similarity index 100% rename from packages/core/src/infer-transpiled.ts rename to packages/core/solidity/src/infer-transpiled.ts diff --git a/packages/core/src/kind.ts b/packages/core/solidity/src/kind.ts similarity index 100% rename from packages/core/src/kind.ts rename to packages/core/solidity/src/kind.ts diff --git a/packages/core/src/options.ts b/packages/core/solidity/src/options.ts similarity index 100% rename from packages/core/src/options.ts rename to packages/core/solidity/src/options.ts diff --git a/packages/core/src/print-versioned.ts b/packages/core/solidity/src/print-versioned.ts similarity index 100% rename from packages/core/src/print-versioned.ts rename to packages/core/solidity/src/print-versioned.ts diff --git a/packages/core/src/print.ts b/packages/core/solidity/src/print.ts similarity index 100% rename from packages/core/src/print.ts rename to packages/core/solidity/src/print.ts diff --git a/packages/core/src/scripts/prepare.ts b/packages/core/solidity/src/scripts/prepare.ts similarity index 100% rename from packages/core/src/scripts/prepare.ts rename to packages/core/solidity/src/scripts/prepare.ts diff --git a/packages/core/src/set-access-control.ts b/packages/core/solidity/src/set-access-control.ts similarity index 100% rename from packages/core/src/set-access-control.ts rename to packages/core/solidity/src/set-access-control.ts diff --git a/packages/core/src/set-clock-mode.ts b/packages/core/solidity/src/set-clock-mode.ts similarity index 100% rename from packages/core/src/set-clock-mode.ts rename to packages/core/solidity/src/set-clock-mode.ts diff --git a/packages/core/src/set-info.ts b/packages/core/solidity/src/set-info.ts similarity index 100% rename from packages/core/src/set-info.ts rename to packages/core/solidity/src/set-info.ts diff --git a/packages/core/src/set-upgradeable.ts b/packages/core/solidity/src/set-upgradeable.ts similarity index 100% rename from packages/core/src/set-upgradeable.ts rename to packages/core/solidity/src/set-upgradeable.ts diff --git a/packages/core/src/solidity-version.json b/packages/core/solidity/src/solidity-version.json similarity index 100% rename from packages/core/src/solidity-version.json rename to packages/core/solidity/src/solidity-version.json diff --git a/packages/core/src/stablecoin.test.ts b/packages/core/solidity/src/stablecoin.test.ts similarity index 100% rename from packages/core/src/stablecoin.test.ts rename to packages/core/solidity/src/stablecoin.test.ts diff --git a/packages/core/src/stablecoin.test.ts.md b/packages/core/solidity/src/stablecoin.test.ts.md similarity index 100% rename from packages/core/src/stablecoin.test.ts.md rename to packages/core/solidity/src/stablecoin.test.ts.md diff --git a/packages/core/src/stablecoin.test.ts.snap b/packages/core/solidity/src/stablecoin.test.ts.snap similarity index 100% rename from packages/core/src/stablecoin.test.ts.snap rename to packages/core/solidity/src/stablecoin.test.ts.snap diff --git a/packages/core/src/stablecoin.ts b/packages/core/solidity/src/stablecoin.ts similarity index 100% rename from packages/core/src/stablecoin.ts rename to packages/core/solidity/src/stablecoin.ts diff --git a/packages/core/src/test.ts b/packages/core/solidity/src/test.ts similarity index 100% rename from packages/core/src/test.ts rename to packages/core/solidity/src/test.ts diff --git a/packages/core/src/utils/define-functions.ts b/packages/core/solidity/src/utils/define-functions.ts similarity index 100% rename from packages/core/src/utils/define-functions.ts rename to packages/core/solidity/src/utils/define-functions.ts diff --git a/packages/core/src/utils/duration.ts b/packages/core/solidity/src/utils/duration.ts similarity index 100% rename from packages/core/src/utils/duration.ts rename to packages/core/solidity/src/utils/duration.ts diff --git a/packages/core/src/utils/find-cover.ts b/packages/core/solidity/src/utils/find-cover.ts similarity index 100% rename from packages/core/src/utils/find-cover.ts rename to packages/core/solidity/src/utils/find-cover.ts diff --git a/packages/core/src/utils/format-lines.ts b/packages/core/solidity/src/utils/format-lines.ts similarity index 100% rename from packages/core/src/utils/format-lines.ts rename to packages/core/solidity/src/utils/format-lines.ts diff --git a/packages/core/src/utils/map-values.ts b/packages/core/solidity/src/utils/map-values.ts similarity index 100% rename from packages/core/src/utils/map-values.ts rename to packages/core/solidity/src/utils/map-values.ts diff --git a/packages/core/src/utils/sorted-by.ts b/packages/core/solidity/src/utils/sorted-by.ts similarity index 100% rename from packages/core/src/utils/sorted-by.ts rename to packages/core/solidity/src/utils/sorted-by.ts diff --git a/packages/core/src/utils/to-identifier.test.ts b/packages/core/solidity/src/utils/to-identifier.test.ts similarity index 100% rename from packages/core/src/utils/to-identifier.test.ts rename to packages/core/solidity/src/utils/to-identifier.test.ts diff --git a/packages/core/src/utils/to-identifier.ts b/packages/core/solidity/src/utils/to-identifier.ts similarity index 100% rename from packages/core/src/utils/to-identifier.ts rename to packages/core/solidity/src/utils/to-identifier.ts diff --git a/packages/core/src/utils/transitive-closure.ts b/packages/core/solidity/src/utils/transitive-closure.ts similarity index 100% rename from packages/core/src/utils/transitive-closure.ts rename to packages/core/solidity/src/utils/transitive-closure.ts diff --git a/packages/core/src/utils/version.test.ts b/packages/core/solidity/src/utils/version.test.ts similarity index 100% rename from packages/core/src/utils/version.test.ts rename to packages/core/solidity/src/utils/version.test.ts diff --git a/packages/core/src/utils/version.ts b/packages/core/solidity/src/utils/version.ts similarity index 100% rename from packages/core/src/utils/version.ts rename to packages/core/solidity/src/utils/version.ts diff --git a/packages/core/src/zip-foundry.test.ts b/packages/core/solidity/src/zip-foundry.test.ts similarity index 100% rename from packages/core/src/zip-foundry.test.ts rename to packages/core/solidity/src/zip-foundry.test.ts diff --git a/packages/core/src/zip-foundry.test.ts.md b/packages/core/solidity/src/zip-foundry.test.ts.md similarity index 100% rename from packages/core/src/zip-foundry.test.ts.md rename to packages/core/solidity/src/zip-foundry.test.ts.md diff --git a/packages/core/src/zip-foundry.test.ts.snap b/packages/core/solidity/src/zip-foundry.test.ts.snap similarity index 100% rename from packages/core/src/zip-foundry.test.ts.snap rename to packages/core/solidity/src/zip-foundry.test.ts.snap diff --git a/packages/core/src/zip-foundry.ts b/packages/core/solidity/src/zip-foundry.ts similarity index 100% rename from packages/core/src/zip-foundry.ts rename to packages/core/solidity/src/zip-foundry.ts diff --git a/packages/core/src/zip-hardhat.test.ts b/packages/core/solidity/src/zip-hardhat.test.ts similarity index 100% rename from packages/core/src/zip-hardhat.test.ts rename to packages/core/solidity/src/zip-hardhat.test.ts diff --git a/packages/core/src/zip-hardhat.test.ts.md b/packages/core/solidity/src/zip-hardhat.test.ts.md similarity index 100% rename from packages/core/src/zip-hardhat.test.ts.md rename to packages/core/solidity/src/zip-hardhat.test.ts.md diff --git a/packages/core/src/zip-hardhat.test.ts.snap b/packages/core/solidity/src/zip-hardhat.test.ts.snap similarity index 100% rename from packages/core/src/zip-hardhat.test.ts.snap rename to packages/core/solidity/src/zip-hardhat.test.ts.snap diff --git a/packages/core/src/zip-hardhat.ts b/packages/core/solidity/src/zip-hardhat.ts similarity index 100% rename from packages/core/src/zip-hardhat.ts rename to packages/core/solidity/src/zip-hardhat.ts diff --git a/packages/core/tsconfig.json b/packages/core/solidity/tsconfig.json similarity index 85% rename from packages/core/tsconfig.json rename to packages/core/solidity/tsconfig.json index f6a21a39d..e51988c6e 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/solidity/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../tsconfig.base.json", + "extends": "../../../tsconfig.base.json", "compilerOptions": { "incremental": true, "module": "commonjs", diff --git a/packages/core/zip-env-foundry.js b/packages/core/solidity/zip-env-foundry.js similarity index 100% rename from packages/core/zip-env-foundry.js rename to packages/core/solidity/zip-env-foundry.js diff --git a/packages/core/zip-env-foundry.ts b/packages/core/solidity/zip-env-foundry.ts similarity index 100% rename from packages/core/zip-env-foundry.ts rename to packages/core/solidity/zip-env-foundry.ts diff --git a/packages/core/zip-env-hardhat.js b/packages/core/solidity/zip-env-hardhat.js similarity index 100% rename from packages/core/zip-env-hardhat.js rename to packages/core/solidity/zip-env-hardhat.js diff --git a/packages/core/zip-env-hardhat.ts b/packages/core/solidity/zip-env-hardhat.ts similarity index 100% rename from packages/core/zip-env-hardhat.ts rename to packages/core/solidity/zip-env-hardhat.ts diff --git a/packages/ui/rollup.config.mjs b/packages/ui/rollup.config.mjs index 2ba764434..76077d7e9 100644 --- a/packages/ui/rollup.config.mjs +++ b/packages/ui/rollup.config.mjs @@ -97,7 +97,7 @@ export default [ }, plugins: [ // Generate openzeppelin-contracts.js data file - onStartRun(...'yarn --cwd ../core prepare'.split(' ')), + onStartRun(...'yarn --cwd ../core/solidity prepare'.split(' ')), svelte(await import('./svelte.config.js')), @@ -132,7 +132,7 @@ export default [ commonjs(), typescript({ - include: ['src/**/*.ts', '../core/src/**/*.ts', '../core-cairo/src/**/*.ts'], + include: ['src/**/*.ts', '../core/solidity/src/**/*.ts', '../core/cairo/src/**/*.ts'], sourceMap: true, inlineSources: true, }), diff --git a/packages/ui/tsconfig.json b/packages/ui/tsconfig.json index e3669d435..d15cb2f27 100644 --- a/packages/ui/tsconfig.json +++ b/packages/ui/tsconfig.json @@ -5,6 +5,6 @@ "lib": ["dom", "dom.iterable", "es2019", "es2019.array"], "skipLibCheck": true }, - "include": ["src/**/*", "../core/src/**/*", "../core-cairo/src/**/*"], + "include": ["src/**/*", "../core/solidity/src/**/*", "../core/cairo/src/**/*"], "exclude": ["node_modules/*", "__sapper__/*", "public/*"] } From 7a2c2e916530c84b4b4ebe06865061be4c4dac3e Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Tue, 4 Feb 2025 15:06:08 -0500 Subject: [PATCH 002/117] Update dirs in readme --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f7a74bcc7..1a012040d 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,7 @@ Contracts Wizard is a web application to interactively build a contract out of c Install dependencies with `yarn install`. -`packages/core` contains the code generation logic for Solidity. - -`packages/core-cairo` contains the code generation logic for Cairo. +`packages/core` contains the code generation logic for Solidity and Cairo under separately named subfolders. `packages/ui` is the interface built in Svelte. `yarn dev` spins up a local server to develop the UI. @@ -38,5 +36,5 @@ For Cairo, use the `data-lang` attribute: ` Date: Tue, 4 Feb 2025 15:43:10 -0500 Subject: [PATCH 003/117] Move language specific UIs to subfolders --- .../cairo/AccessControlSection.svelte | 4 +-- .../{ => lang}/cairo/AccountControls.svelte | 4 +-- packages/ui/src/{ => lang}/cairo/App.svelte | 16 +++++------ .../{ => lang}/cairo/CustomControls.svelte | 4 +-- .../{ => lang}/cairo/ERC1155Controls.svelte | 2 +- .../src/{ => lang}/cairo/ERC20Controls.svelte | 4 +-- .../{ => lang}/cairo/ERC721Controls.svelte | 4 +-- .../{ => lang}/cairo/GovernorControls.svelte | 8 +++--- .../src/{ => lang}/cairo/InfoSection.svelte | 0 .../cairo/RoyaltyInfoSection.svelte | 4 +-- .../cairo/UpgradeabilityField.svelte | 2 +- .../{ => lang}/cairo/VestingControls.svelte | 4 +-- .../ui/src/{ => lang}/cairo/highlightjs.ts | 0 .../src/{ => lang}/cairo/inject-hyperlinks.ts | 0 .../solidity}/AccessControlSection.svelte | 4 +-- .../ui/src/{ => lang/solidity}/App.svelte | 28 +++++++++---------- .../{ => lang/solidity}/CustomControls.svelte | 2 +- .../solidity}/DefenderDeployModal.svelte | 0 .../solidity}/ERC1155Controls.svelte | 2 +- .../{ => lang/solidity}/ERC20Controls.svelte | 4 +-- .../{ => lang/solidity}/ERC721Controls.svelte | 4 +-- .../solidity}/GovernorControls.svelte | 8 +++--- .../{ => lang/solidity}/InfoSection.svelte | 2 +- .../solidity}/RealWorldAssetControls.svelte | 4 +-- .../solidity}/StablecoinControls.svelte | 4 +-- .../solidity}/UpgradeabilitySection.svelte | 4 +-- .../ui/src/{ => lang/solidity}/Wiz.svelte | 14 +++++----- .../ui/src/{ => lang/solidity}/highlightjs.ts | 0 .../solidity}/inject-hyperlinks.ts | 0 packages/ui/src/{ => lang/solidity}/remix.ts | 0 .../src/{ => lang/solidity}/wiz-functions.ts | 0 packages/ui/src/main.ts | 4 +-- 32 files changed, 70 insertions(+), 70 deletions(-) rename packages/ui/src/{ => lang}/cairo/AccessControlSection.svelte (94%) rename packages/ui/src/{ => lang}/cairo/AccountControls.svelte (96%) rename packages/ui/src/{ => lang}/cairo/App.svelte (95%) rename packages/ui/src/{ => lang}/cairo/CustomControls.svelte (93%) rename packages/ui/src/{ => lang}/cairo/ERC1155Controls.svelte (98%) rename packages/ui/src/{ => lang}/cairo/ERC20Controls.svelte (97%) rename packages/ui/src/{ => lang}/cairo/ERC721Controls.svelte (97%) rename packages/ui/src/{ => lang}/cairo/GovernorControls.svelte (97%) rename packages/ui/src/{ => lang}/cairo/InfoSection.svelte (100%) rename packages/ui/src/{ => lang}/cairo/RoyaltyInfoSection.svelte (94%) rename packages/ui/src/{ => lang}/cairo/UpgradeabilityField.svelte (89%) rename packages/ui/src/{ => lang}/cairo/VestingControls.svelte (95%) rename packages/ui/src/{ => lang}/cairo/highlightjs.ts (100%) rename packages/ui/src/{ => lang}/cairo/inject-hyperlinks.ts (100%) rename packages/ui/src/{ => lang/solidity}/AccessControlSection.svelte (95%) rename packages/ui/src/{ => lang/solidity}/App.svelte (95%) rename packages/ui/src/{ => lang/solidity}/CustomControls.svelte (96%) rename packages/ui/src/{ => lang/solidity}/DefenderDeployModal.svelte (100%) rename packages/ui/src/{ => lang/solidity}/ERC1155Controls.svelte (98%) rename packages/ui/src/{ => lang/solidity}/ERC20Controls.svelte (97%) rename packages/ui/src/{ => lang/solidity}/ERC721Controls.svelte (97%) rename packages/ui/src/{ => lang/solidity}/GovernorControls.svelte (97%) rename packages/ui/src/{ => lang/solidity}/InfoSection.svelte (94%) rename packages/ui/src/{ => lang/solidity}/RealWorldAssetControls.svelte (98%) rename packages/ui/src/{ => lang/solidity}/StablecoinControls.svelte (98%) rename packages/ui/src/{ => lang/solidity}/UpgradeabilitySection.svelte (92%) rename packages/ui/src/{ => lang/solidity}/Wiz.svelte (95%) rename packages/ui/src/{ => lang/solidity}/highlightjs.ts (100%) rename packages/ui/src/{utils => lang/solidity}/inject-hyperlinks.ts (100%) rename packages/ui/src/{ => lang/solidity}/remix.ts (100%) rename packages/ui/src/{ => lang/solidity}/wiz-functions.ts (100%) diff --git a/packages/ui/src/cairo/AccessControlSection.svelte b/packages/ui/src/lang/cairo/AccessControlSection.svelte similarity index 94% rename from packages/ui/src/cairo/AccessControlSection.svelte rename to packages/ui/src/lang/cairo/AccessControlSection.svelte index b170aee1e..751f51413 100644 --- a/packages/ui/src/cairo/AccessControlSection.svelte +++ b/packages/ui/src/lang/cairo/AccessControlSection.svelte @@ -1,8 +1,8 @@ diff --git a/packages/ui/src/cairo/VestingControls.svelte b/packages/ui/src/lang/cairo/VestingControls.svelte similarity index 95% rename from packages/ui/src/cairo/VestingControls.svelte rename to packages/ui/src/lang/cairo/VestingControls.svelte index 06fe80f81..40c25bce5 100644 --- a/packages/ui/src/cairo/VestingControls.svelte +++ b/packages/ui/src/lang/cairo/VestingControls.svelte @@ -1,11 +1,11 @@ diff --git a/packages/ui/src/RealWorldAssetControls.svelte b/packages/ui/src/lang/solidity/RealWorldAssetControls.svelte similarity index 98% rename from packages/ui/src/RealWorldAssetControls.svelte rename to packages/ui/src/lang/solidity/RealWorldAssetControls.svelte index 171e1c03d..a13634d05 100644 --- a/packages/ui/src/RealWorldAssetControls.svelte +++ b/packages/ui/src/lang/solidity/RealWorldAssetControls.svelte @@ -1,12 +1,12 @@ diff --git a/packages/ui/src/Wiz.svelte b/packages/ui/src/lang/solidity/Wiz.svelte similarity index 95% rename from packages/ui/src/Wiz.svelte rename to packages/ui/src/lang/solidity/Wiz.svelte index d8e64352c..25b747ec4 100644 --- a/packages/ui/src/Wiz.svelte +++ b/packages/ui/src/lang/solidity/Wiz.svelte @@ -1,13 +1,13 @@ diff --git a/packages/ui/src/lang/cairo/VestingControls.svelte b/packages/ui/src/cairo/VestingControls.svelte similarity index 95% rename from packages/ui/src/lang/cairo/VestingControls.svelte rename to packages/ui/src/cairo/VestingControls.svelte index 40c25bce5..1a51a31fa 100644 --- a/packages/ui/src/lang/cairo/VestingControls.svelte +++ b/packages/ui/src/cairo/VestingControls.svelte @@ -1,11 +1,11 @@ diff --git a/packages/ui/src/lang/solidity/RealWorldAssetControls.svelte b/packages/ui/src/solidity/RealWorldAssetControls.svelte similarity index 98% rename from packages/ui/src/lang/solidity/RealWorldAssetControls.svelte rename to packages/ui/src/solidity/RealWorldAssetControls.svelte index a13634d05..62dfaaa25 100644 --- a/packages/ui/src/lang/solidity/RealWorldAssetControls.svelte +++ b/packages/ui/src/solidity/RealWorldAssetControls.svelte @@ -1,12 +1,12 @@ diff --git a/packages/ui/src/lang/solidity/Wiz.svelte b/packages/ui/src/solidity/Wiz.svelte similarity index 95% rename from packages/ui/src/lang/solidity/Wiz.svelte rename to packages/ui/src/solidity/Wiz.svelte index 25b747ec4..346f8e8b8 100644 --- a/packages/ui/src/lang/solidity/Wiz.svelte +++ b/packages/ui/src/solidity/Wiz.svelte @@ -1,13 +1,13 @@ + + + +
+
+ OpenZeppelin + Solidity + Cairo + Stylus +
+
+ Forum + Docs + GitHub + Twitter +
+
+ +
+ +
+ + + + + + + + diff --git a/packages/ui/rollup.config.mjs b/packages/ui/rollup.config.mjs index 76077d7e9..79a0f7678 100644 --- a/packages/ui/rollup.config.mjs +++ b/packages/ui/rollup.config.mjs @@ -132,7 +132,7 @@ export default [ commonjs(), typescript({ - include: ['src/**/*.ts', '../core/solidity/src/**/*.ts', '../core/cairo/src/**/*.ts'], + include: ['src/**/*.ts', '../core/solidity/src/**/*.ts', '../core/cairo/src/**/*.ts', '../core/stylus/src/**/*.ts'], sourceMap: true, inlineSources: true, }), diff --git a/packages/ui/src/common/styles/vars.css b/packages/ui/src/common/styles/vars.css index ce023bfc8..991899453 100644 --- a/packages/ui/src/common/styles/vars.css +++ b/packages/ui/src/common/styles/vars.css @@ -32,6 +32,9 @@ --cairo-orange-1: #fe9149; --cairo-orange-2: #fe4a3c; + --stylus-pink-1: #e3066e; + --stylus-pink-2: #a3034e; + /* Dimensions (scale taken from Tailwind) */ --size-1: 0.25rem; diff --git a/packages/ui/src/main.ts b/packages/ui/src/main.ts index 05bfae007..47d91eb10 100644 --- a/packages/ui/src/main.ts +++ b/packages/ui/src/main.ts @@ -1,8 +1,9 @@ import './common/styles/global.css'; import type {} from 'svelte'; -import App from './solidity/App.svelte'; +import SolidityApp from './solidity/App.svelte'; import CairoApp from './cairo/App.svelte'; +import StylusApp from './stylus/App.svelte'; import { postMessage } from './common/post-message'; import UnsupportedVersion from './common/UnsupportedVersion.svelte'; import semver from 'semver'; @@ -38,10 +39,19 @@ let app; if (requestedVersion && !semver.satisfies(requestedVersion, compatibleVersionSemver)) { postMessage({ kind: 'oz-wizard-unsupported-version' }); app = new UnsupportedVersion({ target: document.body, props: { requestedVersion, compatibleVersionSemver }}); -} else if (lang === 'cairo') { - app = new CairoApp({ target: document.body, props: { initialTab, initialOpts } }); } else { - app = new App({ target: document.body, props: { initialTab, initialOpts } }); + switch (lang) { + case 'cairo': + app = new CairoApp({ target: document.body, props: { initialTab, initialOpts } }); + break; + case 'stylus': + app = new StylusApp({ target: document.body, props: { initialTab } }); + break; + case 'solidity': + default: + app = new SolidityApp({ target: document.body, props: { initialTab, initialOpts } }); + break; + } } app.$on('tab-change', (e: CustomEvent) => { diff --git a/packages/ui/src/standalone.css b/packages/ui/src/standalone.css index 339ae4155..f6ec7fac9 100644 --- a/packages/ui/src/standalone.css +++ b/packages/ui/src/standalone.css @@ -91,6 +91,11 @@ body { --color-2: var(--cairo-orange-2); } +.header .switch.switch-stylus { + --color-1: var(--stylus-pink-1); + --color-2: var(--stylus-pink-2); +} + .header .link { color: var(--text-color); display: block; diff --git a/packages/ui/src/stylus/AccessControlSection.svelte b/packages/ui/src/stylus/AccessControlSection.svelte new file mode 100644 index 000000000..34ca1258f --- /dev/null +++ b/packages/ui/src/stylus/AccessControlSection.svelte @@ -0,0 +1,62 @@ + + +
+

+ + +

+ +
+ + +
+ +
diff --git a/packages/ui/src/stylus/AccountControls.svelte b/packages/ui/src/stylus/AccountControls.svelte new file mode 100644 index 000000000..47046b915 --- /dev/null +++ b/packages/ui/src/stylus/AccountControls.svelte @@ -0,0 +1,89 @@ + + + +
+

Settings

+ + +
+ +
+

Account Type

+
+ + + +
+
+ +
+

Features

+ +
+ + + + + + + + +
+
+ + diff --git a/packages/ui/src/stylus/App.svelte b/packages/ui/src/stylus/App.svelte new file mode 100644 index 000000000..5e75cbf9c --- /dev/null +++ b/packages/ui/src/stylus/App.svelte @@ -0,0 +1,329 @@ + + +
+
+
+ + + + + + + + + +
+ +
+ + + + + + + +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
{@html highlightedCode}
+
+
+
+ + diff --git a/packages/ui/src/stylus/CustomControls.svelte b/packages/ui/src/stylus/CustomControls.svelte new file mode 100644 index 000000000..759d1d6d2 --- /dev/null +++ b/packages/ui/src/stylus/CustomControls.svelte @@ -0,0 +1,52 @@ + + +
+

Settings

+ + +
+ +
+

Features

+ +
+ + + +
+ +
+ + + + \ No newline at end of file diff --git a/packages/ui/src/stylus/ERC1155Controls.svelte b/packages/ui/src/stylus/ERC1155Controls.svelte new file mode 100644 index 000000000..fd1b9bcea --- /dev/null +++ b/packages/ui/src/stylus/ERC1155Controls.svelte @@ -0,0 +1,80 @@ + + +
+

Settings

+ + + +
+ +
+

Features

+ +
+ + + + + +
+
+ + + + + + diff --git a/packages/ui/src/stylus/ERC20Controls.svelte b/packages/ui/src/stylus/ERC20Controls.svelte new file mode 100644 index 000000000..c8215b7e8 --- /dev/null +++ b/packages/ui/src/stylus/ERC20Controls.svelte @@ -0,0 +1,114 @@ + + +
+

Settings

+ +
+ + + +
+ + +
+ +
+

Features

+ +
+ + + + + + + +
+
+ +
+

+ + +

+ + + + +
+ + + + diff --git a/packages/ui/src/stylus/ERC721Controls.svelte b/packages/ui/src/stylus/ERC721Controls.svelte new file mode 100644 index 000000000..f78bea66e --- /dev/null +++ b/packages/ui/src/stylus/ERC721Controls.svelte @@ -0,0 +1,118 @@ + + +
+

Settings

+ +
+ + +
+ +
+ +
+

Features

+ +
+ + + + + +
+
+ +
+

+ + +

+ + + + +
+ + + + + + \ No newline at end of file diff --git a/packages/ui/src/stylus/GovernorControls.svelte b/packages/ui/src/stylus/GovernorControls.svelte new file mode 100644 index 000000000..3a7f844e3 --- /dev/null +++ b/packages/ui/src/stylus/GovernorControls.svelte @@ -0,0 +1,231 @@ + + +
+

Settings

+ + + +
+ + + +
+ + + + + +

+ + Token amounts above will be extended with this number of zeroes. Does not apply to ERC721Votes. +

+ +
+ + +
+
+ +
+

Votes

+ +
+ + + +
+
+ +
+

+ + +

+ +
+ +
+
+ +
+

+ + +

+ +
+ +
+
+ +
+

+ + +

+ + + + +
+ + diff --git a/packages/ui/src/stylus/InfoSection.svelte b/packages/ui/src/stylus/InfoSection.svelte new file mode 100644 index 000000000..2f9ad5946 --- /dev/null +++ b/packages/ui/src/stylus/InfoSection.svelte @@ -0,0 +1,21 @@ + + +
+

+ + +

+ + +
+ diff --git a/packages/ui/src/stylus/RoyaltyInfoSection.svelte b/packages/ui/src/stylus/RoyaltyInfoSection.svelte new file mode 100644 index 000000000..e99dbea94 --- /dev/null +++ b/packages/ui/src/stylus/RoyaltyInfoSection.svelte @@ -0,0 +1,42 @@ + + +
+

+ + +

+ + + + +
diff --git a/packages/ui/src/stylus/UpgradeabilityField.svelte b/packages/ui/src/stylus/UpgradeabilityField.svelte new file mode 100644 index 000000000..239957228 --- /dev/null +++ b/packages/ui/src/stylus/UpgradeabilityField.svelte @@ -0,0 +1,15 @@ + + + diff --git a/packages/ui/src/stylus/VestingControls.svelte b/packages/ui/src/stylus/VestingControls.svelte new file mode 100644 index 000000000..c136b219a --- /dev/null +++ b/packages/ui/src/stylus/VestingControls.svelte @@ -0,0 +1,68 @@ + + +
+

Settings

+ + + + + + + +
+ +
+

Vesting Schedule

+
+ + +
+
+ + diff --git a/packages/ui/src/stylus/highlightjs.ts b/packages/ui/src/stylus/highlightjs.ts new file mode 100644 index 000000000..c94c01084 --- /dev/null +++ b/packages/ui/src/stylus/highlightjs.ts @@ -0,0 +1,7 @@ +import hljs from 'highlight.js/lib/core'; + +// @ts-ignore +import hljsDefineCairo from 'highlightjs-cairo'; +hljsDefineCairo(hljs); + +export default hljs; diff --git a/packages/ui/src/stylus/inject-hyperlinks.ts b/packages/ui/src/stylus/inject-hyperlinks.ts new file mode 100644 index 000000000..cab6fc0f5 --- /dev/null +++ b/packages/ui/src/stylus/inject-hyperlinks.ts @@ -0,0 +1,40 @@ +import { contractsVersionTag } from "@openzeppelin/wizard-stylus/src"; + +export function injectHyperlinks(code: string) { + const importRegex = /use<\/span> (openzeppelin)::([^A-Z]*)(::[a-zA-Z0-9]+|::{)/g + let result = code; + let match = importRegex.exec(code); + while (match != null) { + const [line, libraryPrefix, libraryPath, suffix] = match; + if (line !== undefined && libraryPrefix !== undefined && libraryPath !== undefined && suffix !== undefined) { + const githubPrefix = `https://github.com/OpenZeppelin/cairo-contracts/blob/${contractsVersionTag}/packages/`; + + let libraryPathSegments = libraryPath.split('::'); + libraryPathSegments.splice(1, 0, 'src'); + + if (libraryPathSegments !== undefined && libraryPathSegments.length > 0) { + let replacement; + if (suffix === '::{') { + // Multiple components are imported, so remove components and link to the parent .cairo file + replacement = `use<\/span> ${libraryPrefix}::${libraryPath}${suffix}`; // Exclude suffix from link + } else { + // Single component is imported + // If a mapping exists, link to the mapped file, otherwise remove the component and link to the parent .cairo file + const componentName = suffix.substring(2, suffix.length); + const mapping = componentMappings[componentName]; + const urlSuffix = mapping ? `/${mapping}.cairo` : '.cairo'; + replacement = `use<\/span> ${libraryPrefix}::${libraryPath}${suffix}`; // Include suffix (component) in link + } + + result = result.replace(line, replacement); + } + } + match = importRegex.exec(code); + } + return result; +} + +const componentMappings: { [key: string]: string } = { + 'AccountComponent': 'account', + 'UpgradeableComponent': 'upgradeable', +} as const; diff --git a/packages/ui/tailwind.config.js b/packages/ui/tailwind.config.js index 0934f5891..57dd932eb 100644 --- a/packages/ui/tailwind.config.js +++ b/packages/ui/tailwind.config.js @@ -5,6 +5,7 @@ module.exports = { // Using glob patterns results in infinite loop './public/index.html', './public/cairo.html', + './public/stylus.html', './public/embed.html', ], From 413e93d460ab7fa4b90b1741b7cc83c15901e4d4 Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Tue, 4 Feb 2025 16:54:57 -0500 Subject: [PATCH 007/117] Change language config, highlighter --- packages/ui/src/common/post-config.ts | 2 +- packages/ui/src/stylus/App.svelte | 4 ++-- packages/ui/src/stylus/highlightjs.ts | 6 ++---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/ui/src/common/post-config.ts b/packages/ui/src/common/post-config.ts index cf34c45f2..0e2ccb23e 100644 --- a/packages/ui/src/common/post-config.ts +++ b/packages/ui/src/common/post-config.ts @@ -8,7 +8,7 @@ declare global { } export type Action = 'copy' | 'remix' | 'download-npm' | 'download-hardhat' | 'download-foundry' | 'defender'; -export type Language = 'solidity' | 'cairo'; +export type Language = 'solidity' | 'cairo' | 'stylus'; export async function postConfig(opts: Required | Required, action: Action, language: Language) { window.gtag?.('event', 'wizard_action', { ...opts, action, wizard_lang: language }); diff --git a/packages/ui/src/stylus/App.svelte b/packages/ui/src/stylus/App.svelte index 5e75cbf9c..00346e75a 100644 --- a/packages/ui/src/stylus/App.svelte +++ b/packages/ui/src/stylus/App.svelte @@ -77,9 +77,9 @@ } $: code = printContract(contract); - $: highlightedCode = injectHyperlinks(hljs.highlight(code, {language: 'cairo'}).value); + $: highlightedCode = injectHyperlinks(hljs.highlight(code, {language: 'rust'}).value); - const language = 'cairo'; + const language = 'stylus'; let copied = false; const copyHandler = async () => { diff --git a/packages/ui/src/stylus/highlightjs.ts b/packages/ui/src/stylus/highlightjs.ts index c94c01084..85d7b7166 100644 --- a/packages/ui/src/stylus/highlightjs.ts +++ b/packages/ui/src/stylus/highlightjs.ts @@ -1,7 +1,5 @@ import hljs from 'highlight.js/lib/core'; - -// @ts-ignore -import hljsDefineCairo from 'highlightjs-cairo'; -hljsDefineCairo(hljs); +import rust from 'highlight.js/lib/languages/rust'; +hljs.registerLanguage('rust', rust); export default hljs; From 3c226b47edda3fe75f335055ea34a9252470851d Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Tue, 4 Feb 2025 16:56:56 -0500 Subject: [PATCH 008/117] Remove account, governor --- packages/ui/src/stylus/AccountControls.svelte | 89 ------- packages/ui/src/stylus/App.svelte | 8 - .../ui/src/stylus/GovernorControls.svelte | 231 ------------------ 3 files changed, 328 deletions(-) delete mode 100644 packages/ui/src/stylus/AccountControls.svelte delete mode 100644 packages/ui/src/stylus/GovernorControls.svelte diff --git a/packages/ui/src/stylus/AccountControls.svelte b/packages/ui/src/stylus/AccountControls.svelte deleted file mode 100644 index 47046b915..000000000 --- a/packages/ui/src/stylus/AccountControls.svelte +++ /dev/null @@ -1,89 +0,0 @@ - - - -
-

Settings

- - -
- -
-

Account Type

-
- - - -
-
- -
-

Features

- -
- - - - - - - - -
-
- - diff --git a/packages/ui/src/stylus/App.svelte b/packages/ui/src/stylus/App.svelte index 00346e75a..65fac4d03 100644 --- a/packages/ui/src/stylus/App.svelte +++ b/packages/ui/src/stylus/App.svelte @@ -55,8 +55,6 @@ case 'ERC721': opts.symbol = initialOpts.symbol ?? opts.symbol; break; - case 'Account': - case 'Governor': case 'Vesting': case 'ERC1155': case 'Custom': @@ -117,12 +115,6 @@ - - diff --git a/packages/ui/src/stylus/GovernorControls.svelte b/packages/ui/src/stylus/GovernorControls.svelte deleted file mode 100644 index 3a7f844e3..000000000 --- a/packages/ui/src/stylus/GovernorControls.svelte +++ /dev/null @@ -1,231 +0,0 @@ - - -
-

Settings

- - - -
- - - -
- - - - - -

- - Token amounts above will be extended with this number of zeroes. Does not apply to ERC721Votes. -

- -
- - -
-
- -
-

Votes

- -
- - - -
-
- -
-

- - -

- -
- -
-
- -
-

- - -

- -
- -
-
- -
-

- - -

- - - - -
- - From 62342a191e13b863c2eceb72d753aaede6b9a41d Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Tue, 4 Feb 2025 17:31:55 -0500 Subject: [PATCH 009/117] Remove everything except ERC20 --- packages/core/stylus/README.md | 48 +- packages/core/stylus/src/account.test.ts | 231 -- packages/core/stylus/src/account.test.ts.md | 1854 --------------- packages/core/stylus/src/account.test.ts.snap | Bin 2044 -> 0 bytes packages/core/stylus/src/account.ts | 216 -- packages/core/stylus/src/api.ts | 41 +- packages/core/stylus/src/build-generic.ts | 32 +- packages/core/stylus/src/custom.test.ts | 79 - packages/core/stylus/src/custom.test.ts.md | 447 ---- packages/core/stylus/src/custom.test.ts.snap | Bin 1351 -> 0 bytes packages/core/stylus/src/custom.ts | 54 - packages/core/stylus/src/erc1155.test.ts | 136 -- packages/core/stylus/src/erc1155.test.ts.md | 1885 --------------- packages/core/stylus/src/erc1155.test.ts.snap | Bin 3417 -> 0 bytes packages/core/stylus/src/erc1155.ts | 282 --- packages/core/stylus/src/erc721.test.ts | 191 -- packages/core/stylus/src/erc721.test.ts.md | 2060 ----------------- packages/core/stylus/src/erc721.test.ts.snap | Bin 3527 -> 0 bytes packages/core/stylus/src/erc721.ts | 274 --- packages/core/stylus/src/generate/account.ts | 21 - packages/core/stylus/src/generate/custom.ts | 19 - packages/core/stylus/src/generate/erc1155.ts | 25 - packages/core/stylus/src/generate/erc721.ts | 29 - packages/core/stylus/src/generate/governor.ts | 30 - packages/core/stylus/src/generate/sources.ts | 51 +- packages/core/stylus/src/generate/vesting.ts | 16 - packages/core/stylus/src/governor.test.ts | 181 -- packages/core/stylus/src/governor.test.ts.md | 1419 ------------ .../core/stylus/src/governor.test.ts.snap | Bin 2322 -> 0 bytes packages/core/stylus/src/governor.ts | 494 ---- packages/core/stylus/src/index.ts | 3 +- packages/core/stylus/src/set-upgradeable.ts | 23 - packages/core/stylus/src/test.ts | 36 +- packages/core/stylus/src/vesting.test.ts | 119 - packages/core/stylus/src/vesting.test.ts.md | 365 --- packages/core/stylus/src/vesting.test.ts.snap | Bin 1105 -> 0 bytes packages/core/stylus/src/vesting.ts | 219 -- packages/ui/src/stylus/App.svelte | 44 +- packages/ui/src/stylus/CustomControls.svelte | 52 - packages/ui/src/stylus/ERC1155Controls.svelte | 80 - packages/ui/src/stylus/ERC20Controls.svelte | 2 - packages/ui/src/stylus/ERC721Controls.svelte | 118 - .../ui/src/stylus/RoyaltyInfoSection.svelte | 42 - .../ui/src/stylus/UpgradeabilityField.svelte | 15 - packages/ui/src/stylus/VestingControls.svelte | 68 - 45 files changed, 10 insertions(+), 11291 deletions(-) delete mode 100644 packages/core/stylus/src/account.test.ts delete mode 100644 packages/core/stylus/src/account.test.ts.md delete mode 100644 packages/core/stylus/src/account.test.ts.snap delete mode 100644 packages/core/stylus/src/account.ts delete mode 100644 packages/core/stylus/src/custom.test.ts delete mode 100644 packages/core/stylus/src/custom.test.ts.md delete mode 100644 packages/core/stylus/src/custom.test.ts.snap delete mode 100644 packages/core/stylus/src/custom.ts delete mode 100644 packages/core/stylus/src/erc1155.test.ts delete mode 100644 packages/core/stylus/src/erc1155.test.ts.md delete mode 100644 packages/core/stylus/src/erc1155.test.ts.snap delete mode 100644 packages/core/stylus/src/erc1155.ts delete mode 100644 packages/core/stylus/src/erc721.test.ts delete mode 100644 packages/core/stylus/src/erc721.test.ts.md delete mode 100644 packages/core/stylus/src/erc721.test.ts.snap delete mode 100644 packages/core/stylus/src/erc721.ts delete mode 100644 packages/core/stylus/src/generate/account.ts delete mode 100644 packages/core/stylus/src/generate/custom.ts delete mode 100644 packages/core/stylus/src/generate/erc1155.ts delete mode 100644 packages/core/stylus/src/generate/erc721.ts delete mode 100644 packages/core/stylus/src/generate/governor.ts delete mode 100644 packages/core/stylus/src/generate/vesting.ts delete mode 100644 packages/core/stylus/src/governor.test.ts delete mode 100644 packages/core/stylus/src/governor.test.ts.md delete mode 100644 packages/core/stylus/src/governor.test.ts.snap delete mode 100644 packages/core/stylus/src/governor.ts delete mode 100644 packages/core/stylus/src/vesting.test.ts delete mode 100644 packages/core/stylus/src/vesting.test.ts.md delete mode 100644 packages/core/stylus/src/vesting.test.ts.snap delete mode 100644 packages/core/stylus/src/vesting.ts delete mode 100644 packages/ui/src/stylus/CustomControls.svelte delete mode 100644 packages/ui/src/stylus/ERC1155Controls.svelte delete mode 100644 packages/ui/src/stylus/ERC721Controls.svelte delete mode 100644 packages/ui/src/stylus/RoyaltyInfoSection.svelte delete mode 100644 packages/ui/src/stylus/UpgradeabilityField.svelte delete mode 100644 packages/ui/src/stylus/VestingControls.svelte diff --git a/packages/core/stylus/README.md b/packages/core/stylus/README.md index 0d6af139e..d0a50b4d1 100644 --- a/packages/core/stylus/README.md +++ b/packages/core/stylus/README.md @@ -12,10 +12,6 @@ This package provides a programmatic API. For a web interface, see https://wizar The following contract types are supported: - `erc20` -- `erc721` -- `erc1155` -- `vesting` -- `custom` Each contract type has functions/constants as defined below. @@ -25,59 +21,23 @@ Each contract type has functions/constants as defined below. ```js function print(opts?: ERC20Options): string ``` -```js -function print(opts?: ERC721Options): string -``` -```js -function print(opts?: ERC1155Options): string -``` -```js -function print(opts?: VestingOptions): string -``` -```js -function print(opts?: CustomOptions): string -``` Returns a string representation of a contract generated using the provided options. If `opts` is not provided, uses [`defaults`](#defaults). #### `defaults` ```js const defaults: Required ``` -```js -const defaults: Required -``` -```js -const defaults: Required -``` -```js -const defaults: Required -``` -```js -const defaults: Required -``` The default options that are used for [`print`](#print). #### `isAccessControlRequired` ```js function isAccessControlRequired(opts: Partial): boolean ``` -```js -function isAccessControlRequired(opts: Partial): boolean -``` -```js -function isAccessControlRequired(opts: Partial): boolean -``` -```js -function isAccessControlRequired(opts: Partial): boolean -``` Whether any of the provided options require access control to be enabled. If this returns `true`, then calling `print` with the same options would cause the `access` option to default to `'ownable'` if it was `undefined` or `false`. -> Note that contracts such as `vesting` have their own ways of handling permissions and do not support the `access` option. -Thus, those types do not include `isAccessControlRequired`. - ### Examples -Import the contract type(s) or function categories (for example, `erc20` or `utils`) that you want to use from the `@openzeppelin/wizard-stylus` package: +Import the contract type(s) (for example, `erc20`) that you want to use from the `@openzeppelin/wizard-stylus` package: ```js import { erc20 } from '@openzeppelin/wizard-stylus'; @@ -91,15 +51,13 @@ const contract = erc20.print(); To generate the source code for an ERC20 contract with some custom settings: ```js const contract = erc20.print({ - burnable: true, pausable: true, }); ``` - -To generate the source code for an ERC20 contract with all of the defaults but is upgradeable: +or ```js const contract = erc20.print({ ...erc20.defaults, - upgradeable: true, + pausable: true, }); ``` diff --git a/packages/core/stylus/src/account.test.ts b/packages/core/stylus/src/account.test.ts deleted file mode 100644 index 217e1d813..000000000 --- a/packages/core/stylus/src/account.test.ts +++ /dev/null @@ -1,231 +0,0 @@ -import test from 'ava'; - -import { buildAccount, AccountOptions } from './account'; -import { printContract } from './print'; - -import { account } from '.'; - -function testAccount(title: string, opts: Partial) { - test(title, t => { - const c = buildAccount({ - name: 'MyAccount', - type: 'stark', - ...opts, - }); - t.snapshot(printContract(c)); - }); -} - -function testEthAccount(title: string, opts: Partial) { - test(title, t => { - const c = buildAccount({ - name: 'MyAccount', - type: 'eth', - ...opts, - }); - t.snapshot(printContract(c)); - }); -} - -/** - * Tests external API for equivalence with internal API - */ -function testAPIEquivalence(title: string, opts?: AccountOptions) { - test(title, t => { - t.is(account.print(opts), printContract(buildAccount({ - name: 'MyAccount', - type: 'stark', - declare: true, - deploy: true, - pubkey: true, - outsideExecution: true, - ...opts, - }))); - }); -} - -testAccount('default full account, mixin + upgradeable', {}); - -testAccount('default full account, mixin + non-upgradeable', { - upgradeable: false -}); - -testAccount('explicit full account, mixin + upgradeable', { - name: 'MyAccount', - type: 'stark', - declare: true, - deploy: true, - pubkey: true, - outsideExecution: true, - upgradeable: true -}); - -testAccount('explicit full account, mixin + non-upgradeable', { - name: 'MyAccount', - type: 'stark', - declare: true, - deploy: true, - pubkey: true, - outsideExecution: true, - upgradeable: false -}); - -testAccount('basic account, upgradeable', { - declare: false, - deploy: false, - pubkey: false, - outsideExecution: false, -}); - -testAccount('basic account, non-upgradeable', { - declare: false, - deploy: false, - pubkey: false, - outsideExecution: false, - upgradeable: false -}); - -testAccount('account outside execution', { - deploy: false, - pubkey: false, - declare: false, -}); - -testAccount('account declarer', { - deploy: false, - pubkey: false, - outsideExecution: false, -}); - -testAccount('account deployable', { - declare: false, - pubkey: false, - outsideExecution: false, -}); - -testAccount('account public key', { - declare: false, - deploy: false, - outsideExecution: false, -}); - -testAccount('account declarer, deployable', { - pubkey: false, - outsideExecution: false, -}); - -testAccount('account declarer, public key', { - deploy: false, - outsideExecution: false, -}); - -testAccount('account deployable, public key', { - declare: false, - outsideExecution: false, -}); - -testEthAccount('default full ethAccount, mixin + upgradeable', {}); - -testEthAccount('default full ethAccount, mixin + non-upgradeable', { - upgradeable: false -}); - -testEthAccount('explicit full ethAccount, mixin + upgradeable', { - name: 'MyAccount', - type: 'eth', - declare: true, - deploy: true, - pubkey: true, - outsideExecution: true, - upgradeable: true -}); - -testEthAccount('explicit full ethAccount, mixin + non-upgradeable', { - name: 'MyAccount', - type: 'eth', - declare: true, - deploy: true, - pubkey: true, - outsideExecution: true, - upgradeable: false -}); - -testEthAccount('basic ethAccount, upgradeable', { - declare: false, - deploy: false, - pubkey: false, - outsideExecution: false, -}); - -testEthAccount('basic ethAccount, non-upgradeable', { - declare: false, - deploy: false, - pubkey: false, - outsideExecution: false, - upgradeable: false -}); - -testEthAccount('ethAccount outside execution', { - deploy: false, - pubkey: false, - declare: false, -}); - -testEthAccount('ethAccount declarer', { - deploy: false, - pubkey: false, - outsideExecution: false, -}); - -testEthAccount('ethAccount deployable', { - declare: false, - pubkey: false, - outsideExecution: false, -}); - -testEthAccount('ethAccount public key', { - declare: false, - deploy: false, - outsideExecution: false, -}); - -testEthAccount('ethAccount declarer, deployable', { - pubkey: false, - outsideExecution: false, -}); - -testEthAccount('ethAccount declarer, public key', { - deploy: false, - outsideExecution: false, -}); - -testEthAccount('ethAccount deployable, public key', { - declare: false, - outsideExecution: false, -}); - -testAPIEquivalence('account API default'); - -testAPIEquivalence('account API basic', { - name: 'CustomAccount', - type: 'stark', - declare: false, - deploy: false, - pubkey: false, - outsideExecution: false, - upgradeable: false, -}); - -testAPIEquivalence('account API full upgradeable', { - name: 'CustomAccount', - type: 'stark', - declare: true, - deploy: true, - pubkey: true, - outsideExecution: true, - upgradeable: true, -}); - -test('account API assert defaults', async t => { - t.is(account.print(account.defaults), account.print()); -}); diff --git a/packages/core/stylus/src/account.test.ts.md b/packages/core/stylus/src/account.test.ts.md deleted file mode 100644 index a62ea81f7..000000000 --- a/packages/core/stylus/src/account.test.ts.md +++ /dev/null @@ -1,1854 +0,0 @@ -# Snapshot report for `src/account.test.ts` - -The actual snapshot is saved in `account.test.ts.snap`. - -Generated by [AVA](https://avajs.dev). - -## default full account, mixin + upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::AccountComponent;␊ - use openzeppelin::account::extensions::SRC9Component;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::ClassHash;␊ - ␊ - component!(path: AccountComponent, storage: account, event: AccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: SRC9Component, storage: src9, event: SRC9Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl AccountMixinImpl = AccountComponent::AccountMixinImpl;␊ - #[abi(embed_v0)]␊ - impl OutsideExecutionV2Impl = SRC9Component::OutsideExecutionV2Impl;␊ - ␊ - // Internal␊ - impl AccountInternalImpl = AccountComponent::InternalImpl;␊ - impl OutsideExecutionInternalImpl = SRC9Component::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - account: AccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - src9: SRC9Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - AccountEvent: AccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - SRC9Event: SRC9Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: felt252) {␊ - self.account.initializer(public_key);␊ - self.src9.initializer();␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.account.assert_only_self();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## default full account, mixin + non-upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::AccountComponent;␊ - use openzeppelin::account::extensions::SRC9Component;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - ␊ - component!(path: AccountComponent, storage: account, event: AccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: SRC9Component, storage: src9, event: SRC9Event);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl AccountMixinImpl = AccountComponent::AccountMixinImpl;␊ - #[abi(embed_v0)]␊ - impl OutsideExecutionV2Impl = SRC9Component::OutsideExecutionV2Impl;␊ - ␊ - // Internal␊ - impl AccountInternalImpl = AccountComponent::InternalImpl;␊ - impl OutsideExecutionInternalImpl = SRC9Component::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - account: AccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - src9: SRC9Component::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - AccountEvent: AccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - SRC9Event: SRC9Component::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: felt252) {␊ - self.account.initializer(public_key);␊ - self.src9.initializer();␊ - }␊ - }␊ - ` - -## explicit full account, mixin + upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::AccountComponent;␊ - use openzeppelin::account::extensions::SRC9Component;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::ClassHash;␊ - ␊ - component!(path: AccountComponent, storage: account, event: AccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: SRC9Component, storage: src9, event: SRC9Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl AccountMixinImpl = AccountComponent::AccountMixinImpl;␊ - #[abi(embed_v0)]␊ - impl OutsideExecutionV2Impl = SRC9Component::OutsideExecutionV2Impl;␊ - ␊ - // Internal␊ - impl AccountInternalImpl = AccountComponent::InternalImpl;␊ - impl OutsideExecutionInternalImpl = SRC9Component::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - account: AccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - src9: SRC9Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - AccountEvent: AccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - SRC9Event: SRC9Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: felt252) {␊ - self.account.initializer(public_key);␊ - self.src9.initializer();␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.account.assert_only_self();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## explicit full account, mixin + non-upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::AccountComponent;␊ - use openzeppelin::account::extensions::SRC9Component;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - ␊ - component!(path: AccountComponent, storage: account, event: AccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: SRC9Component, storage: src9, event: SRC9Event);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl AccountMixinImpl = AccountComponent::AccountMixinImpl;␊ - #[abi(embed_v0)]␊ - impl OutsideExecutionV2Impl = SRC9Component::OutsideExecutionV2Impl;␊ - ␊ - // Internal␊ - impl AccountInternalImpl = AccountComponent::InternalImpl;␊ - impl OutsideExecutionInternalImpl = SRC9Component::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - account: AccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - src9: SRC9Component::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - AccountEvent: AccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - SRC9Event: SRC9Component::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: felt252) {␊ - self.account.initializer(public_key);␊ - self.src9.initializer();␊ - }␊ - }␊ - ` - -## basic account, upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::AccountComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::ClassHash;␊ - ␊ - component!(path: AccountComponent, storage: account, event: AccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl SRC6Impl = AccountComponent::SRC6Impl;␊ - #[abi(embed_v0)]␊ - impl SRC6CamelOnlyImpl = AccountComponent::SRC6CamelOnlyImpl;␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - // Internal␊ - impl AccountInternalImpl = AccountComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - account: AccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - AccountEvent: AccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: felt252) {␊ - self.account.initializer(public_key);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.account.assert_only_self();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## basic account, non-upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::AccountComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - ␊ - component!(path: AccountComponent, storage: account, event: AccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl SRC6Impl = AccountComponent::SRC6Impl;␊ - #[abi(embed_v0)]␊ - impl SRC6CamelOnlyImpl = AccountComponent::SRC6CamelOnlyImpl;␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - // Internal␊ - impl AccountInternalImpl = AccountComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - account: AccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - AccountEvent: AccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: felt252) {␊ - self.account.initializer(public_key);␊ - }␊ - }␊ - ` - -## account outside execution - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::AccountComponent;␊ - use openzeppelin::account::extensions::SRC9Component;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::ClassHash;␊ - ␊ - component!(path: AccountComponent, storage: account, event: AccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: SRC9Component, storage: src9, event: SRC9Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl SRC6Impl = AccountComponent::SRC6Impl;␊ - #[abi(embed_v0)]␊ - impl SRC6CamelOnlyImpl = AccountComponent::SRC6CamelOnlyImpl;␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - #[abi(embed_v0)]␊ - impl OutsideExecutionV2Impl = SRC9Component::OutsideExecutionV2Impl;␊ - ␊ - // Internal␊ - impl AccountInternalImpl = AccountComponent::InternalImpl;␊ - impl OutsideExecutionInternalImpl = SRC9Component::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - account: AccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - src9: SRC9Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - AccountEvent: AccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - SRC9Event: SRC9Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: felt252) {␊ - self.account.initializer(public_key);␊ - self.src9.initializer();␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.account.assert_only_self();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## account declarer - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::AccountComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::ClassHash;␊ - ␊ - component!(path: AccountComponent, storage: account, event: AccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl SRC6Impl = AccountComponent::SRC6Impl;␊ - #[abi(embed_v0)]␊ - impl SRC6CamelOnlyImpl = AccountComponent::SRC6CamelOnlyImpl;␊ - #[abi(embed_v0)]␊ - impl DeclarerImpl = AccountComponent::DeclarerImpl;␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - // Internal␊ - impl AccountInternalImpl = AccountComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - account: AccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - AccountEvent: AccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: felt252) {␊ - self.account.initializer(public_key);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.account.assert_only_self();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## account deployable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::AccountComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::ClassHash;␊ - ␊ - component!(path: AccountComponent, storage: account, event: AccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl SRC6Impl = AccountComponent::SRC6Impl;␊ - #[abi(embed_v0)]␊ - impl SRC6CamelOnlyImpl = AccountComponent::SRC6CamelOnlyImpl;␊ - #[abi(embed_v0)]␊ - impl DeployableImpl = AccountComponent::DeployableImpl;␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - // Internal␊ - impl AccountInternalImpl = AccountComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - account: AccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - AccountEvent: AccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: felt252) {␊ - self.account.initializer(public_key);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.account.assert_only_self();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## account public key - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::AccountComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::ClassHash;␊ - ␊ - component!(path: AccountComponent, storage: account, event: AccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl SRC6Impl = AccountComponent::SRC6Impl;␊ - #[abi(embed_v0)]␊ - impl SRC6CamelOnlyImpl = AccountComponent::SRC6CamelOnlyImpl;␊ - #[abi(embed_v0)]␊ - impl PublicKeyImpl = AccountComponent::PublicKeyImpl;␊ - #[abi(embed_v0)]␊ - impl PublicKeyCamelImpl = AccountComponent::PublicKeyCamelImpl;␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - // Internal␊ - impl AccountInternalImpl = AccountComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - account: AccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - AccountEvent: AccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: felt252) {␊ - self.account.initializer(public_key);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.account.assert_only_self();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## account declarer, deployable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::AccountComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::ClassHash;␊ - ␊ - component!(path: AccountComponent, storage: account, event: AccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl SRC6Impl = AccountComponent::SRC6Impl;␊ - #[abi(embed_v0)]␊ - impl SRC6CamelOnlyImpl = AccountComponent::SRC6CamelOnlyImpl;␊ - #[abi(embed_v0)]␊ - impl DeclarerImpl = AccountComponent::DeclarerImpl;␊ - #[abi(embed_v0)]␊ - impl DeployableImpl = AccountComponent::DeployableImpl;␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - // Internal␊ - impl AccountInternalImpl = AccountComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - account: AccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - AccountEvent: AccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: felt252) {␊ - self.account.initializer(public_key);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.account.assert_only_self();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## account declarer, public key - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::AccountComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::ClassHash;␊ - ␊ - component!(path: AccountComponent, storage: account, event: AccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl SRC6Impl = AccountComponent::SRC6Impl;␊ - #[abi(embed_v0)]␊ - impl SRC6CamelOnlyImpl = AccountComponent::SRC6CamelOnlyImpl;␊ - #[abi(embed_v0)]␊ - impl DeclarerImpl = AccountComponent::DeclarerImpl;␊ - #[abi(embed_v0)]␊ - impl PublicKeyImpl = AccountComponent::PublicKeyImpl;␊ - #[abi(embed_v0)]␊ - impl PublicKeyCamelImpl = AccountComponent::PublicKeyCamelImpl;␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - // Internal␊ - impl AccountInternalImpl = AccountComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - account: AccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - AccountEvent: AccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: felt252) {␊ - self.account.initializer(public_key);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.account.assert_only_self();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## account deployable, public key - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::AccountComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::ClassHash;␊ - ␊ - component!(path: AccountComponent, storage: account, event: AccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl SRC6Impl = AccountComponent::SRC6Impl;␊ - #[abi(embed_v0)]␊ - impl SRC6CamelOnlyImpl = AccountComponent::SRC6CamelOnlyImpl;␊ - #[abi(embed_v0)]␊ - impl DeployableImpl = AccountComponent::DeployableImpl;␊ - #[abi(embed_v0)]␊ - impl PublicKeyImpl = AccountComponent::PublicKeyImpl;␊ - #[abi(embed_v0)]␊ - impl PublicKeyCamelImpl = AccountComponent::PublicKeyCamelImpl;␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - // Internal␊ - impl AccountInternalImpl = AccountComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - account: AccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - AccountEvent: AccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: felt252) {␊ - self.account.initializer(public_key);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.account.assert_only_self();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## default full ethAccount, mixin + upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::eth_account::EthAccountComponent;␊ - use openzeppelin::account::extensions::SRC9Component;␊ - use openzeppelin::account::interface::EthPublicKey;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::ClassHash;␊ - ␊ - component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: SRC9Component, storage: src9, event: SRC9Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl EthAccountMixinImpl = EthAccountComponent::EthAccountMixinImpl;␊ - #[abi(embed_v0)]␊ - impl OutsideExecutionV2Impl = SRC9Component::OutsideExecutionV2Impl;␊ - ␊ - // Internal␊ - impl EthAccountInternalImpl = EthAccountComponent::InternalImpl;␊ - impl OutsideExecutionInternalImpl = SRC9Component::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - eth_account: EthAccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - src9: SRC9Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - EthAccountEvent: EthAccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - SRC9Event: SRC9Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: EthPublicKey) {␊ - self.eth_account.initializer(public_key);␊ - self.src9.initializer();␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.eth_account.assert_only_self();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## default full ethAccount, mixin + non-upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::eth_account::EthAccountComponent;␊ - use openzeppelin::account::extensions::SRC9Component;␊ - use openzeppelin::account::interface::EthPublicKey;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - ␊ - component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: SRC9Component, storage: src9, event: SRC9Event);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl EthAccountMixinImpl = EthAccountComponent::EthAccountMixinImpl;␊ - #[abi(embed_v0)]␊ - impl OutsideExecutionV2Impl = SRC9Component::OutsideExecutionV2Impl;␊ - ␊ - // Internal␊ - impl EthAccountInternalImpl = EthAccountComponent::InternalImpl;␊ - impl OutsideExecutionInternalImpl = SRC9Component::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - eth_account: EthAccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - src9: SRC9Component::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - EthAccountEvent: EthAccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - SRC9Event: SRC9Component::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: EthPublicKey) {␊ - self.eth_account.initializer(public_key);␊ - self.src9.initializer();␊ - }␊ - }␊ - ` - -## explicit full ethAccount, mixin + upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::eth_account::EthAccountComponent;␊ - use openzeppelin::account::extensions::SRC9Component;␊ - use openzeppelin::account::interface::EthPublicKey;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::ClassHash;␊ - ␊ - component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: SRC9Component, storage: src9, event: SRC9Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl EthAccountMixinImpl = EthAccountComponent::EthAccountMixinImpl;␊ - #[abi(embed_v0)]␊ - impl OutsideExecutionV2Impl = SRC9Component::OutsideExecutionV2Impl;␊ - ␊ - // Internal␊ - impl EthAccountInternalImpl = EthAccountComponent::InternalImpl;␊ - impl OutsideExecutionInternalImpl = SRC9Component::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - eth_account: EthAccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - src9: SRC9Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - EthAccountEvent: EthAccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - SRC9Event: SRC9Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: EthPublicKey) {␊ - self.eth_account.initializer(public_key);␊ - self.src9.initializer();␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.eth_account.assert_only_self();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## explicit full ethAccount, mixin + non-upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::eth_account::EthAccountComponent;␊ - use openzeppelin::account::extensions::SRC9Component;␊ - use openzeppelin::account::interface::EthPublicKey;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - ␊ - component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: SRC9Component, storage: src9, event: SRC9Event);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl EthAccountMixinImpl = EthAccountComponent::EthAccountMixinImpl;␊ - #[abi(embed_v0)]␊ - impl OutsideExecutionV2Impl = SRC9Component::OutsideExecutionV2Impl;␊ - ␊ - // Internal␊ - impl EthAccountInternalImpl = EthAccountComponent::InternalImpl;␊ - impl OutsideExecutionInternalImpl = SRC9Component::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - eth_account: EthAccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - src9: SRC9Component::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - EthAccountEvent: EthAccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - SRC9Event: SRC9Component::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: EthPublicKey) {␊ - self.eth_account.initializer(public_key);␊ - self.src9.initializer();␊ - }␊ - }␊ - ` - -## basic ethAccount, upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::eth_account::EthAccountComponent;␊ - use openzeppelin::account::interface::EthPublicKey;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::ClassHash;␊ - ␊ - component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl SRC6Impl = EthAccountComponent::SRC6Impl;␊ - #[abi(embed_v0)]␊ - impl SRC6CamelOnlyImpl = EthAccountComponent::SRC6CamelOnlyImpl;␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - // Internal␊ - impl EthAccountInternalImpl = EthAccountComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - eth_account: EthAccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - EthAccountEvent: EthAccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: EthPublicKey) {␊ - self.eth_account.initializer(public_key);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.eth_account.assert_only_self();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## basic ethAccount, non-upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::eth_account::EthAccountComponent;␊ - use openzeppelin::account::interface::EthPublicKey;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - ␊ - component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl SRC6Impl = EthAccountComponent::SRC6Impl;␊ - #[abi(embed_v0)]␊ - impl SRC6CamelOnlyImpl = EthAccountComponent::SRC6CamelOnlyImpl;␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - // Internal␊ - impl EthAccountInternalImpl = EthAccountComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - eth_account: EthAccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - EthAccountEvent: EthAccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: EthPublicKey) {␊ - self.eth_account.initializer(public_key);␊ - }␊ - }␊ - ` - -## ethAccount outside execution - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::eth_account::EthAccountComponent;␊ - use openzeppelin::account::extensions::SRC9Component;␊ - use openzeppelin::account::interface::EthPublicKey;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::ClassHash;␊ - ␊ - component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: SRC9Component, storage: src9, event: SRC9Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl SRC6Impl = EthAccountComponent::SRC6Impl;␊ - #[abi(embed_v0)]␊ - impl SRC6CamelOnlyImpl = EthAccountComponent::SRC6CamelOnlyImpl;␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - #[abi(embed_v0)]␊ - impl OutsideExecutionV2Impl = SRC9Component::OutsideExecutionV2Impl;␊ - ␊ - // Internal␊ - impl EthAccountInternalImpl = EthAccountComponent::InternalImpl;␊ - impl OutsideExecutionInternalImpl = SRC9Component::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - eth_account: EthAccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - src9: SRC9Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - EthAccountEvent: EthAccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - SRC9Event: SRC9Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: EthPublicKey) {␊ - self.eth_account.initializer(public_key);␊ - self.src9.initializer();␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.eth_account.assert_only_self();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## ethAccount declarer - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::eth_account::EthAccountComponent;␊ - use openzeppelin::account::interface::EthPublicKey;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::ClassHash;␊ - ␊ - component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl SRC6Impl = EthAccountComponent::SRC6Impl;␊ - #[abi(embed_v0)]␊ - impl SRC6CamelOnlyImpl = EthAccountComponent::SRC6CamelOnlyImpl;␊ - #[abi(embed_v0)]␊ - impl DeclarerImpl = EthAccountComponent::DeclarerImpl;␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - // Internal␊ - impl EthAccountInternalImpl = EthAccountComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - eth_account: EthAccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - EthAccountEvent: EthAccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: EthPublicKey) {␊ - self.eth_account.initializer(public_key);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.eth_account.assert_only_self();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## ethAccount deployable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::eth_account::EthAccountComponent;␊ - use openzeppelin::account::interface::EthPublicKey;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::ClassHash;␊ - ␊ - component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl SRC6Impl = EthAccountComponent::SRC6Impl;␊ - #[abi(embed_v0)]␊ - impl SRC6CamelOnlyImpl = EthAccountComponent::SRC6CamelOnlyImpl;␊ - #[abi(embed_v0)]␊ - impl DeployableImpl = EthAccountComponent::DeployableImpl;␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - // Internal␊ - impl EthAccountInternalImpl = EthAccountComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - eth_account: EthAccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - EthAccountEvent: EthAccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: EthPublicKey) {␊ - self.eth_account.initializer(public_key);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.eth_account.assert_only_self();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## ethAccount public key - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::eth_account::EthAccountComponent;␊ - use openzeppelin::account::interface::EthPublicKey;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::ClassHash;␊ - ␊ - component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl SRC6Impl = EthAccountComponent::SRC6Impl;␊ - #[abi(embed_v0)]␊ - impl SRC6CamelOnlyImpl = EthAccountComponent::SRC6CamelOnlyImpl;␊ - #[abi(embed_v0)]␊ - impl PublicKeyImpl = EthAccountComponent::PublicKeyImpl;␊ - #[abi(embed_v0)]␊ - impl PublicKeyCamelImpl = EthAccountComponent::PublicKeyCamelImpl;␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - // Internal␊ - impl EthAccountInternalImpl = EthAccountComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - eth_account: EthAccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - EthAccountEvent: EthAccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: EthPublicKey) {␊ - self.eth_account.initializer(public_key);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.eth_account.assert_only_self();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## ethAccount declarer, deployable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::eth_account::EthAccountComponent;␊ - use openzeppelin::account::interface::EthPublicKey;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::ClassHash;␊ - ␊ - component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl SRC6Impl = EthAccountComponent::SRC6Impl;␊ - #[abi(embed_v0)]␊ - impl SRC6CamelOnlyImpl = EthAccountComponent::SRC6CamelOnlyImpl;␊ - #[abi(embed_v0)]␊ - impl DeclarerImpl = EthAccountComponent::DeclarerImpl;␊ - #[abi(embed_v0)]␊ - impl DeployableImpl = EthAccountComponent::DeployableImpl;␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - // Internal␊ - impl EthAccountInternalImpl = EthAccountComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - eth_account: EthAccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - EthAccountEvent: EthAccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: EthPublicKey) {␊ - self.eth_account.initializer(public_key);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.eth_account.assert_only_self();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## ethAccount declarer, public key - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::eth_account::EthAccountComponent;␊ - use openzeppelin::account::interface::EthPublicKey;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::ClassHash;␊ - ␊ - component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl SRC6Impl = EthAccountComponent::SRC6Impl;␊ - #[abi(embed_v0)]␊ - impl SRC6CamelOnlyImpl = EthAccountComponent::SRC6CamelOnlyImpl;␊ - #[abi(embed_v0)]␊ - impl DeclarerImpl = EthAccountComponent::DeclarerImpl;␊ - #[abi(embed_v0)]␊ - impl PublicKeyImpl = EthAccountComponent::PublicKeyImpl;␊ - #[abi(embed_v0)]␊ - impl PublicKeyCamelImpl = EthAccountComponent::PublicKeyCamelImpl;␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - // Internal␊ - impl EthAccountInternalImpl = EthAccountComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - eth_account: EthAccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - EthAccountEvent: EthAccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: EthPublicKey) {␊ - self.eth_account.initializer(public_key);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.eth_account.assert_only_self();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## ethAccount deployable, public key - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract(account)]␊ - mod MyAccount {␊ - use openzeppelin::account::eth_account::EthAccountComponent;␊ - use openzeppelin::account::interface::EthPublicKey;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::ClassHash;␊ - ␊ - component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl SRC6Impl = EthAccountComponent::SRC6Impl;␊ - #[abi(embed_v0)]␊ - impl SRC6CamelOnlyImpl = EthAccountComponent::SRC6CamelOnlyImpl;␊ - #[abi(embed_v0)]␊ - impl DeployableImpl = EthAccountComponent::DeployableImpl;␊ - #[abi(embed_v0)]␊ - impl PublicKeyImpl = EthAccountComponent::PublicKeyImpl;␊ - #[abi(embed_v0)]␊ - impl PublicKeyCamelImpl = EthAccountComponent::PublicKeyCamelImpl;␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - // Internal␊ - impl EthAccountInternalImpl = EthAccountComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - eth_account: EthAccountComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - EthAccountEvent: EthAccountComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, public_key: EthPublicKey) {␊ - self.eth_account.initializer(public_key);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.eth_account.assert_only_self();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` diff --git a/packages/core/stylus/src/account.test.ts.snap b/packages/core/stylus/src/account.test.ts.snap deleted file mode 100644 index f3ee3b899daa0da7fe98fd892b812c854666bec5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2044 zcmV%_3M4v88rtv=P*5UKP$5bhYDAHqA~o`^f6RDi?Y(R^>mT2( z&h~q6?B|(zpLye(dDLxNwsGkFc;P3?O>WV_a));HzQswmZ&^e)47<;GgB+OylacpG z-?{7R9jdo2YI;m}yq?XyZy$9!I@iBk+I#8D%V+%G3un)~`r=1RYinfx=Cv zJi4;mp^Tedle!wYvHMwVZH;W(M~=?TwnfQ(llRD;L)llIU~n*LKOa zZn`%4dVO_ceRaK7yL89nx_ihd*EAy#tOqx|d{8^GJLJak)zL9|SR;gxzDJ4eQ1&1w zK+^(wO$!A5+p!sCd@Dm-)r!hTf-#}$M>YkO(Dcyu+8Wsz zaOyJM8XjM|qqogEJ!;cV>)!hE!SJMcYDdx{hDh#4WU~aHLj5mW&I;EJRy0vYw0|` z8?oMdy+{$6wE{(G;B7icD6e**kwdGS9fWbc+~1@ zM5@6J;`G~=X|xXMu|~So;v1VA%YsvVoz_<%=IbBZT_VQ8L<lrfvFq=MPG>k^n2C610tD@YZTHt-Up3T6-I>H0_&ObrJr zMWhOlDhPh#se;uEDnqUSxdP-0%7rWygNq8|K(XR@9F;D#bFcv?Qfi&^Gbz+!?TW|=X|oD`mI z^zDSG*rA4{yVO-A@$XB7*h3N@oQEX-ya?@D&<-aSAPN*dW1;MQ0Z)LRaxn}LWd=lX zV?=Q*`*^~a1`j1ju>dK66hO-SASG;xDVQRP08{`f02P2rH9%$LR&q#>6`=Bu1S)?4 zQ~)Xfm3e{6&0$NtPA8WjNj$Cf;Vott5s3kZfJ49`;83Y?Xz*roZmE%;!ueYwqd!1K zAR~}b5$BnZ9s&=6hm?xoA@GpELur|!r7IE-t(Ni2Z150xsQf&HEEK2<)CKASbuHrG zi^o47%HXc65_fHYyTD!GuA+WQ1oi@ZfxW<9V6O$RS3}zEg!10iFf32EwEUkEiTzq6 z5~IA=iVk+7C(q=or(dfe(iFgKhxek`Q*IVixLBYr;cZ0J6>DI%gS5UY_LI2ytHR%6 zJAN|zcJrD z4;FkDy-76UNlADF6%HkF5wf>J~r58oPX z5G2OI^j!ykkYe9=MfykbnPVR^8~KZ-i~b~7-AO;YuYxDq&&~Eq^N7qyJ7nl1ZBV+= zKL+=+4(>0G!%X&uhu=#;^G%U9Jj^4|2ne3iy4#45=HYF{)E*$;x2reeHLp> z>cd;LD)r&HO311;F`TW!M12KAWx7G+#xbhL#{{{~->Vc$l1?D_m|)KN22Y^Wlr0|r zli>7U%$NW%F=J9RI7}>Irz|5cyGLR|1`{%vkimq^!U3r-0aD8D1WzPHdJIGYA_0+# zhe(Ol<|aT=UN$EHCIORxNx-CBVN&Yixh)BkZdU65k%39Tq*7o~a?xC6A
    -1Jg% zv2-qY3_J!N1CK47#|G~xCic?z*Ic?Sq1nekGoTsJtY~O9=Se;!$N*%S`T#Nj8Gvjm zAWO}a{U!m~&j2z28GsBxhEyEL599~(1Njw${4Od#ALzuXyY?_iP#X a5BvxIQxh2Y5B#@4{`()c{?d4J;{X7F6Vk%~ diff --git a/packages/core/stylus/src/account.ts b/packages/core/stylus/src/account.ts deleted file mode 100644 index 68914729e..000000000 --- a/packages/core/stylus/src/account.ts +++ /dev/null @@ -1,216 +0,0 @@ -import { Contract, ContractBuilder } from './contract'; -import { CommonOptions, withCommonDefaults } from './common-options'; -import { defaults as commonDefaults } from './common-options'; -import { setAccountUpgradeable } from './set-upgradeable'; -import { setInfo } from './set-info'; -import { defineComponents } from './utils/define-components'; -import { printContract } from './print'; -import { addSRC5Component } from './common-components'; - - -export const accountTypes = ['stark', 'eth'] as const; -export type Account = typeof accountTypes[number]; - -export const defaults: Required = { - name: 'MyAccount', - type: 'stark', - declare: true, - deploy: true, - pubkey: true, - outsideExecution: true, - upgradeable: commonDefaults.upgradeable, - info: commonDefaults.info -} as const; - -export function printAccount(opts: AccountOptions = defaults): string { - return printContract(buildAccount(opts)); -} - -export interface AccountOptions extends CommonOptions { - name: string; - type: Account; - declare?: boolean; - deploy?: boolean; - pubkey?: boolean; - outsideExecution?: boolean; -} - -function withDefaults(opts: AccountOptions): Required { - return { - ...opts, - ...withCommonDefaults(opts), - declare: opts.declare ?? defaults.declare, - deploy: opts.deploy ?? defaults.deploy, - pubkey: opts.pubkey ?? defaults.pubkey, - outsideExecution: opts.outsideExecution ?? defaults.outsideExecution - } -} - -export function buildAccount(opts: AccountOptions): Contract { - const isAccount = true; - const c = new ContractBuilder(opts.name, isAccount); - - const allOpts = withDefaults(opts); - - switch (allOpts.type) { - case 'stark': - c.addConstructorArgument({ name: 'public_key', type: 'felt252' }); - c.addComponent(components.AccountComponent, [{ lit: 'public_key' }], true); - break; - case 'eth': - c.addUseClause('openzeppelin::account::interface', 'EthPublicKey'); - c.addConstructorArgument({ name: 'public_key', type: 'EthPublicKey' }); - c.addComponent(components.EthAccountComponent, [{ lit: 'public_key' }], true); - break; - } - - if (allOpts.declare && allOpts.deploy && allOpts.pubkey) { - addAccountMixin(c, allOpts.type); - } else { - addSRC6(c, allOpts.type); - - if (allOpts.declare) { - addDeclarer(c, allOpts.type); - } - - if (allOpts.deploy) { - addDeployer(c, allOpts.type); - } - - if (allOpts.pubkey) { - addPublicKey(c, allOpts.type); - } - } - - if (allOpts.outsideExecution) { - addOutsideExecution(c); - } - - setAccountUpgradeable(c, allOpts.upgradeable, allOpts.type); - setInfo(c, allOpts.info); - - return c; -} - -function addSRC6(c: ContractBuilder, accountType: Account) { - const [baseComponent, componentType] = getBaseCompAndCompType(accountType); - - c.addImplToComponent(componentType, { - name: 'SRC6Impl', - value: `${baseComponent}::SRC6Impl`, - }); - c.addImplToComponent(componentType, { - name: 'SRC6CamelOnlyImpl', - value: `${baseComponent}::SRC6CamelOnlyImpl`, - }); - - addSRC5Component(c); -} - -function addDeclarer(c: ContractBuilder, accountType: Account) { - const [baseComponent, componentType] = getBaseCompAndCompType(accountType); - - c.addImplToComponent(componentType, { - name: 'DeclarerImpl', - value: `${baseComponent}::DeclarerImpl`, - }); -} - -function addDeployer(c: ContractBuilder, accountType: Account) { - const [baseComponent, componentType] = getBaseCompAndCompType(accountType); - - c.addImplToComponent(componentType, { - name: 'DeployableImpl', - value: `${baseComponent}::DeployableImpl`, - }); -} - -function addPublicKey(c: ContractBuilder, accountType: Account) { - const [baseComponent, componentType] = getBaseCompAndCompType(accountType); - - c.addImplToComponent(componentType, { - name: 'PublicKeyImpl', - value: `${baseComponent}::PublicKeyImpl`, - }); - c.addImplToComponent(componentType, { - name: 'PublicKeyCamelImpl', - value: `${baseComponent}::PublicKeyCamelImpl`, - }); -} - -function addOutsideExecution(c: ContractBuilder) { - c.addUseClause('openzeppelin::account::extensions', 'SRC9Component'); - c.addComponent(components.SRC9Component, [], true); -} - -function addAccountMixin(c: ContractBuilder, accountType: Account) { - const accountMixinImpl = accountType === 'stark' ? 'AccountMixinImpl' : 'EthAccountMixinImpl'; - const [baseComponent, componentType] = getBaseCompAndCompType(accountType); - - c.addImplToComponent(componentType, { - name: `${accountMixinImpl}`, - value: `${baseComponent}::${accountMixinImpl}`, - }); - - c.addInterfaceFlag('ISRC5'); - addSRC5Component(c); -} - -function getBaseCompAndCompType(accountType: Account): [string, typeof componentType] { - const [baseComponent, componentType] = accountType === 'stark' ? ['AccountComponent', components.AccountComponent] : ['EthAccountComponent', components.EthAccountComponent]; - return [baseComponent, componentType]; -} - -const components = defineComponents( { - AccountComponent: { - path: 'openzeppelin::account', - substorage: { - name: 'account', - type: 'AccountComponent::Storage', - }, - event: { - name: 'AccountEvent', - type: 'AccountComponent::Event', - }, - impls: [{ - name: 'AccountInternalImpl', - embed: false, - value: 'AccountComponent::InternalImpl', - }], - }, - EthAccountComponent: { - path: 'openzeppelin::account::eth_account', - substorage: { - name: 'eth_account', - type: 'EthAccountComponent::Storage', - }, - event: { - name: 'EthAccountEvent', - type: 'EthAccountComponent::Event', - }, - impls: [{ - name: 'EthAccountInternalImpl', - embed: false, - value: 'EthAccountComponent::InternalImpl', - }] - }, - SRC9Component: { - path: 'openzeppelin::account::extensions', - substorage: { - name: 'src9', - type: 'SRC9Component::Storage', - }, - event: { - name: 'SRC9Event', - type: 'SRC9Component::Event', - }, - impls: [{ - name: 'OutsideExecutionV2Impl', - value: 'SRC9Component::OutsideExecutionV2Impl', - }, { - name: 'OutsideExecutionInternalImpl', - embed: false, - value: 'SRC9Component::InternalImpl', - }] - } -}); diff --git a/packages/core/stylus/src/api.ts b/packages/core/stylus/src/api.ts index a70fc497d..6022d6772 100644 --- a/packages/core/stylus/src/api.ts +++ b/packages/core/stylus/src/api.ts @@ -1,11 +1,5 @@ import type { CommonOptions, CommonContractOptions } from './common-options'; import { printERC20, defaults as erc20defaults, isAccessControlRequired as erc20IsAccessControlRequired, ERC20Options } from './erc20'; -import { printERC721, defaults as erc721defaults, isAccessControlRequired as erc721IsAccessControlRequired, ERC721Options } from './erc721'; -import { printERC1155, defaults as erc1155defaults, isAccessControlRequired as erc1155IsAccessControlRequired, ERC1155Options } from './erc1155'; -import { printAccount, defaults as accountDefaults, AccountOptions } from './account'; -import { printGovernor, defaults as governorDefaults, GovernorOptions } from './governor'; -import { printCustom, defaults as customDefaults, isAccessControlRequired as customIsAccessControlRequired, CustomOptions } from './custom'; -import { printVesting, defaults as vestingDefaults, VestingOptions } from './vesting'; export interface WizardAccountAPI{ /** @@ -40,42 +34,9 @@ export interface AccessControlAPI { } export type ERC20 = WizardContractAPI & AccessControlAPI; -export type ERC721 = WizardContractAPI & AccessControlAPI; -export type ERC1155 = WizardContractAPI & AccessControlAPI; -export type Account = WizardAccountAPI; -export type Governor = WizardContractAPI; -export type Vesting = WizardContractAPI; -export type Custom = WizardContractAPI & AccessControlAPI; export const erc20: ERC20 = { print: printERC20, defaults: erc20defaults, isAccessControlRequired: erc20IsAccessControlRequired, -} -export const erc721: ERC721 = { - print: printERC721, - defaults: erc721defaults, - isAccessControlRequired: erc721IsAccessControlRequired -} -export const erc1155: ERC1155 = { - print: printERC1155, - defaults: erc1155defaults, - isAccessControlRequired: erc1155IsAccessControlRequired -} -export const account: Account = { - print: printAccount, - defaults: accountDefaults, -} -export const governor: Governor = { - print: printGovernor, - defaults: governorDefaults, -} -export const vesting: Vesting = { - print: printVesting, - defaults: vestingDefaults, -} -export const custom: Custom = { - print: printCustom, - defaults: customDefaults, - isAccessControlRequired: customIsAccessControlRequired -} +}; diff --git a/packages/core/stylus/src/build-generic.ts b/packages/core/stylus/src/build-generic.ts index fc04c30dc..2aed9667f 100644 --- a/packages/core/stylus/src/build-generic.ts +++ b/packages/core/stylus/src/build-generic.ts @@ -1,19 +1,7 @@ import { ERC20Options, buildERC20 } from './erc20'; -import { ERC721Options, buildERC721 } from './erc721'; -import { ERC1155Options, buildERC1155 } from './erc1155'; -import { CustomOptions, buildCustom } from './custom'; -import { AccountOptions, buildAccount } from './account'; -import { GovernorOptions, buildGovernor } from './governor'; -import { VestingOptions, buildVesting } from './vesting'; export interface KindedOptions { ERC20: { kind: 'ERC20' } & ERC20Options; - ERC721: { kind: 'ERC721' } & ERC721Options; - ERC1155: { kind: 'ERC1155' } & ERC1155Options; - Account: { kind: 'Account' } & AccountOptions; - Governor: { kind: 'Governor' } & GovernorOptions; - Vesting: { kind: 'Vesting' } & VestingOptions; - Custom: { kind: 'Custom' } & CustomOptions; } export type GenericOptions = KindedOptions[keyof KindedOptions]; @@ -23,26 +11,8 @@ export function buildGeneric(opts: GenericOptions) { case 'ERC20': return buildERC20(opts); - case 'ERC721': - return buildERC721(opts); - - case 'ERC1155': - return buildERC1155(opts); - - case 'Account': - return buildAccount(opts); - - case 'Governor': - return buildGovernor(opts); - - case 'Vesting': - return buildVesting(opts); - - case 'Custom': - return buildCustom(opts); - default: - const _: never = opts; + const _: never = opts.kind; // TODO: When there are additional kinds above, change this assignment to just `opts` instead of `opts.kind` throw new Error('Unknown ERC'); } } diff --git a/packages/core/stylus/src/custom.test.ts b/packages/core/stylus/src/custom.test.ts deleted file mode 100644 index ae5b28cf0..000000000 --- a/packages/core/stylus/src/custom.test.ts +++ /dev/null @@ -1,79 +0,0 @@ -import test from 'ava'; -import { custom } from '.'; - -import { buildCustom, CustomOptions } from './custom'; -import { printContract } from './print'; - -function testCustom(title: string, opts: Partial) { - test(title, t => { - const c = buildCustom({ - name: 'MyContract', - ...opts, - }); - t.snapshot(printContract(c)); - }); -} - -/** - * Tests external API for equivalence with internal API - */ - function testAPIEquivalence(title: string, opts?: CustomOptions) { - test(title, t => { - t.is(custom.print(opts), printContract(buildCustom({ - name: 'MyContract', - ...opts, - }))); - }); -} - -testCustom('custom non-upgradeable', { - upgradeable: false, -}); - -testCustom('custom defaults', {}); - -testCustom('pausable', { - pausable: true, -}); - -testCustom('upgradeable', { - upgradeable: true, -}); - -testCustom('access control disabled', { - upgradeable: false, - access: false, -}); - -testCustom('access control ownable', { - access: 'ownable', -}); - -testCustom('access control roles', { - access: 'roles', -}); - -testCustom('pausable with access control disabled', { - // API should override access to true since it is required for pausable - access: false, - pausable: true, - upgradeable: false, -}); - -testAPIEquivalence('custom API default'); - -testAPIEquivalence('custom API full upgradeable', { - name: 'CustomContract', - access: 'roles', - pausable: true, - upgradeable: true, -}); - -test('custom API assert defaults', async t => { - t.is(custom.print(custom.defaults), custom.print()); -}); - -test('API isAccessControlRequired', async t => { - t.is(custom.isAccessControlRequired({ pausable: true }), true); - t.is(custom.isAccessControlRequired({ upgradeable: true }), true); -}); \ No newline at end of file diff --git a/packages/core/stylus/src/custom.test.ts.md b/packages/core/stylus/src/custom.test.ts.md deleted file mode 100644 index 6be7095fe..000000000 --- a/packages/core/stylus/src/custom.test.ts.md +++ /dev/null @@ -1,447 +0,0 @@ -# Snapshot report for `src/custom.test.ts` - -The actual snapshot is saved in `custom.test.ts.snap`. - -Generated by [AVA](https://avajs.dev). - -## custom non-upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyContract {␊ - #[storage]␊ - struct Storage {␊ - }␊ - }␊ - ` - -## custom defaults - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyContract {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## pausable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyContract {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::security::pausable::PausableComponent;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl PausableImpl = PausableComponent::PausableImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl PausableInternalImpl = PausableComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - pausable: PausableComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - PausableEvent: PausableComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn pause(ref self: ContractState) {␊ - self.ownable.assert_only_owner();␊ - self.pausable.pause();␊ - }␊ - ␊ - #[external(v0)]␊ - fn unpause(ref self: ContractState) {␊ - self.ownable.assert_only_owner();␊ - self.pausable.unpause();␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyContract {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## access control disabled - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyContract {␊ - #[storage]␊ - struct Storage {␊ - }␊ - }␊ - ` - -## access control ownable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyContract {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## access control roles - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - const UPGRADER_ROLE: felt252 = selector!("UPGRADER_ROLE");␊ - ␊ - #[starknet::contract]␊ - mod MyContract {␊ - use openzeppelin::access::accesscontrol::{AccessControlComponent, DEFAULT_ADMIN_ROLE};␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - use super::UPGRADER_ROLE;␊ - ␊ - component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl AccessControlMixinImpl = AccessControlComponent::AccessControlMixinImpl;␊ - ␊ - // Internal␊ - impl AccessControlInternalImpl = AccessControlComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - accesscontrol: AccessControlComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - AccessControlEvent: AccessControlComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - default_admin: ContractAddress,␊ - upgrader: ContractAddress,␊ - ) {␊ - self.accesscontrol.initializer();␊ - ␊ - self.accesscontrol._grant_role(DEFAULT_ADMIN_ROLE, default_admin);␊ - self.accesscontrol._grant_role(UPGRADER_ROLE, upgrader);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.accesscontrol.assert_only_role(UPGRADER_ROLE);␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## pausable with access control disabled - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyContract {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::security::pausable::PausableComponent;␊ - use starknet::ContractAddress;␊ - ␊ - component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl PausableImpl = PausableComponent::PausableImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl PausableInternalImpl = PausableComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - pausable: PausableComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - PausableEvent: PausableComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn pause(ref self: ContractState) {␊ - self.ownable.assert_only_owner();␊ - self.pausable.pause();␊ - }␊ - ␊ - #[external(v0)]␊ - fn unpause(ref self: ContractState) {␊ - self.ownable.assert_only_owner();␊ - self.pausable.unpause();␊ - }␊ - }␊ - }␊ - ` diff --git a/packages/core/stylus/src/custom.test.ts.snap b/packages/core/stylus/src/custom.test.ts.snap deleted file mode 100644 index fb2302b7eeddbd77ce0c80d27359a3cdb8356a92..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1351 zcmV-N1-SY_RzV+%8M;$_Wh<;vKUR_yUX*Axv7n1OE1`=ae8J;xyp@(*^wIjM|AcRnC z8gg<5CrMLCK5!*ENS`U2VPn`(cteHP1D^~6DGET3=YO}5{xUx;NCyH?7y zOm(;jzb3w>wvl^K1bGjt${ zgl|WkcA3#>65jxRiO)z;BIq?{%r{2B*rjnWZqPqY;kslE7Gn zYuzK7ULz%7tSCc0{GDBxcUl{%5wJlYB@Zlgen8}C6!|i(0+zgN zRfaK3vkZ~pp5bvrmQF&*(?C8$#PjG*HHF%PPUklu=1Z zKtBL)Ca!8J4s|i>nl_M|Z|+!EX5Gi_&`0LRl`BSLkUrBDRSlKFrQ^o?mD3}lhf%h7 znP>}$i4ef06SCmiNf0*`WXswpXZ^cr_h)zw^SsrI$Uu}b^YOyJ7GeFpFoT38z#VWZ zuQAqnz<5vndg*Lez+rHbMw^k6Hl7g4O^}Ws$e$XhqM$;OM)P0EXwOH^+0bkrEdlX_ zv^*K-y-8__q1%VCvo%$q-q;1?v!tRcrN$WagkCYrX-AfLxX<_o?8!!`yDAYl zwI+PLCOp6Gz@|ROcz$J9pJUYL81*?ueU4FcR>oPE>0XZ#jtB$f(L^G6GyB2eA_rI{ zyXNaDhF&;C)wEFK}$Cjd2HKZ>tqj=p#pK*>k*g_cELUrqKKL{dKJXz%;| zjm@onXMcBl3nL!_xw^KB-o~&YF0EJ1*OtxecsCsj@umM&PB6aNNZOsWZS3`%Ti*bflQ9gd7>>riA_7;^F#h1d-8GC4_B(4Yhg38BK?EFQEB95DTa~$tC9PCv zJZZVzO2SqOjks}wvv9G|^ijD5(j@fqq+wj{@BnhR0^|s}s?(QC^!6&Q1o!~bPgbp6 zaxYjk6c<@_lI{=?*#awM=NXkp)=3pFX9nuFm_xiiWd%vn%Fka>wWKBm?P67+rC{`K zQDN$wal)h%vvIRXGA(<+2EX4C%G$D98Jw9_Qg$XxJylG{__fv5*ZK=dDuC{LG;%!u zpQX0`nZ=`m2j2J?4KcU!Uc#-52kL_QYQ&VD^gs0_hS|AxFm0y=^?iXUy)Q6q{0}lJ Jp$Eb+003ptgXRDL diff --git a/packages/core/stylus/src/custom.ts b/packages/core/stylus/src/custom.ts deleted file mode 100644 index 7f361415f..000000000 --- a/packages/core/stylus/src/custom.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { Contract, ContractBuilder } from './contract'; -import { setAccessControl } from './set-access-control'; -import { addPausable } from './add-pausable'; -import { CommonContractOptions, withCommonContractDefaults } from './common-options'; -import { setUpgradeable } from './set-upgradeable'; -import { setInfo } from './set-info'; -import { contractDefaults as commonDefaults } from './common-options'; -import { printContract } from './print'; - -export const defaults: Required = { - name: 'MyContract', - pausable: false, - access: commonDefaults.access, - upgradeable: commonDefaults.upgradeable, - info: commonDefaults.info -} as const; - -export function printCustom(opts: CustomOptions = defaults): string { - return printContract(buildCustom(opts)); -} - -export interface CustomOptions extends CommonContractOptions { - name: string; - pausable?: boolean; -} - -function withDefaults(opts: CustomOptions): Required { - return { - ...opts, - ...withCommonContractDefaults(opts), - pausable: opts.pausable ?? defaults.pausable, - }; -} - -export function isAccessControlRequired(opts: Partial): boolean { - return opts.pausable === true || opts.upgradeable === true; -} - -export function buildCustom(opts: CustomOptions): Contract { - const c = new ContractBuilder(opts.name); - - const allOpts = withDefaults(opts); - - if (allOpts.pausable) { - addPausable(c, allOpts.access); - } - - setAccessControl(c, allOpts.access); - setUpgradeable(c, allOpts.upgradeable, allOpts.access); - setInfo(c, allOpts.info); - - return c; -} - diff --git a/packages/core/stylus/src/erc1155.test.ts b/packages/core/stylus/src/erc1155.test.ts deleted file mode 100644 index 9923de2d5..000000000 --- a/packages/core/stylus/src/erc1155.test.ts +++ /dev/null @@ -1,136 +0,0 @@ -import test from 'ava'; -import { erc1155 } from '.'; - -import { buildERC1155, ERC1155Options } from './erc1155'; -import { printContract } from './print'; -import { royaltyInfoOptions } from './set-royalty-info'; - -const NAME = 'MyToken'; -const CUSTOM_NAME = 'CustomToken'; -const BASE_URI = 'https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/'; - -const allFeaturesON: Partial = { - mintable: true, - burnable: true, - pausable: true, - royaltyInfo: royaltyInfoOptions.enabledDefault, - upgradeable: true -} as const; - -function testERC1155(title: string, opts: Partial) { - test(title, t => { - const c = buildERC1155({ - name: NAME, - baseUri: BASE_URI, - ...opts, - }); - t.snapshot(printContract(c)); - }); -} - -/** - * Tests external API for equivalence with internal API - */ -function testAPIEquivalence(title: string, opts?: ERC1155Options) { - test(title, t => { - t.is(erc1155.print(opts), printContract(buildERC1155({ - name: NAME, - baseUri: '', - ...opts, - }))); - }); -} - -testERC1155('basic non-upgradeable', { - upgradeable: false, -}); - -testERC1155('basic', {}); - -testERC1155('basic + roles', { - access: 'roles', -}); - -testERC1155('no updatable uri', { - updatableUri: false, -}); - -testERC1155('burnable', { - burnable: true, -}); - -testERC1155('pausable', { - pausable: true, -}); - -testERC1155('mintable', { - mintable: true, -}); - -testERC1155('mintable + roles', { - mintable: true, - access: 'roles', -}); - -testERC1155('royalty info disabled', { - royaltyInfo: royaltyInfoOptions.disabled -}); - -testERC1155('royalty info enabled default + ownable', { - royaltyInfo: royaltyInfoOptions.enabledDefault, - access: 'ownable' -}); - -testERC1155('royalty info enabled default + roles', { - royaltyInfo: royaltyInfoOptions.enabledDefault, - access: 'roles' -}); - -testERC1155('royalty info enabled custom + ownable', { - royaltyInfo: royaltyInfoOptions.enabledCustom, - access: 'ownable' -}); - -testERC1155('royalty info enabled custom + roles', { - royaltyInfo: royaltyInfoOptions.enabledCustom, - access: 'roles' -}); - -testERC1155('full non-upgradeable', { - ...allFeaturesON, - access: 'roles', - upgradeable: false, -}); - -testERC1155('full upgradeable', { - ...allFeaturesON, - access: 'roles', - upgradeable: true, -}); - -testAPIEquivalence('API default'); - -testAPIEquivalence('API basic', { name: CUSTOM_NAME, baseUri: BASE_URI }); - -testAPIEquivalence('API full upgradeable', { - ...allFeaturesON, - name: CUSTOM_NAME, - baseUri: BASE_URI, - access: 'roles', - upgradeable: true, -}); - -test('API assert defaults', async t => { - t.is(erc1155.print(erc1155.defaults), erc1155.print()); -}); - -test('API isAccessControlRequired', async t => { - t.is(erc1155.isAccessControlRequired({ updatableUri: false, mintable: true }), true); - t.is(erc1155.isAccessControlRequired({ updatableUri: false, pausable: true }), true); - t.is(erc1155.isAccessControlRequired({ updatableUri: false, upgradeable: true }), true); - t.is(erc1155.isAccessControlRequired({ updatableUri: true }), true); - t.is(erc1155.isAccessControlRequired({ royaltyInfo: royaltyInfoOptions.enabledDefault }), true); - t.is(erc1155.isAccessControlRequired({ royaltyInfo: royaltyInfoOptions.enabledCustom }), true); - t.is(erc1155.isAccessControlRequired({ updatableUri: false }), false); - t.is(erc1155.isAccessControlRequired({}), true); // updatableUri is true by default -}); \ No newline at end of file diff --git a/packages/core/stylus/src/erc1155.test.ts.md b/packages/core/stylus/src/erc1155.test.ts.md deleted file mode 100644 index 518920287..000000000 --- a/packages/core/stylus/src/erc1155.test.ts.md +++ /dev/null @@ -1,1885 +0,0 @@ -# Snapshot report for `src/erc1155.test.ts` - -The actual snapshot is saved in `erc1155.test.ts.snap`. - -Generated by [AVA](https://avajs.dev). - -## basic non-upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl};␊ - use starknet::ContractAddress;␊ - ␊ - component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC1155MixinImpl = ERC1155Component::ERC1155MixinImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl ERC1155InternalImpl = ERC1155Component::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc1155: ERC1155Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC1155Event: ERC1155Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.erc1155.initializer("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/");␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn set_base_uri(ref self: ContractState, base_uri: ByteArray) {␊ - self.ownable.assert_only_owner();␊ - self.erc1155._set_base_uri(base_uri);␊ - }␊ - ␊ - #[external(v0)]␊ - fn setBaseUri(ref self: ContractState, baseUri: ByteArray) {␊ - self.set_base_uri(baseUri);␊ - }␊ - }␊ - }␊ - ` - -## basic - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC1155MixinImpl = ERC1155Component::ERC1155MixinImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl ERC1155InternalImpl = ERC1155Component::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc1155: ERC1155Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC1155Event: ERC1155Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.erc1155.initializer("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/");␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn set_base_uri(ref self: ContractState, base_uri: ByteArray) {␊ - self.ownable.assert_only_owner();␊ - self.erc1155._set_base_uri(base_uri);␊ - }␊ - ␊ - #[external(v0)]␊ - fn setBaseUri(ref self: ContractState, baseUri: ByteArray) {␊ - self.set_base_uri(baseUri);␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## basic + roles - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - const URI_SETTER_ROLE: felt252 = selector!("URI_SETTER_ROLE");␊ - const UPGRADER_ROLE: felt252 = selector!("UPGRADER_ROLE");␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::accesscontrol::{AccessControlComponent, DEFAULT_ADMIN_ROLE};␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - use super::{UPGRADER_ROLE, URI_SETTER_ROLE};␊ - ␊ - component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC1155MixinImpl = ERC1155Component::ERC1155MixinImpl;␊ - #[abi(embed_v0)]␊ - impl AccessControlImpl = AccessControlComponent::AccessControlImpl;␊ - #[abi(embed_v0)]␊ - impl AccessControlCamelImpl = AccessControlComponent::AccessControlCamelImpl;␊ - ␊ - // Internal␊ - impl ERC1155InternalImpl = ERC1155Component::InternalImpl;␊ - impl AccessControlInternalImpl = AccessControlComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc1155: ERC1155Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - accesscontrol: AccessControlComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC1155Event: ERC1155Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - AccessControlEvent: AccessControlComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - default_admin: ContractAddress,␊ - uri_setter: ContractAddress,␊ - upgrader: ContractAddress,␊ - ) {␊ - self.erc1155.initializer("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/");␊ - self.accesscontrol.initializer();␊ - ␊ - self.accesscontrol._grant_role(DEFAULT_ADMIN_ROLE, default_admin);␊ - self.accesscontrol._grant_role(URI_SETTER_ROLE, uri_setter);␊ - self.accesscontrol._grant_role(UPGRADER_ROLE, upgrader);␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn set_base_uri(ref self: ContractState, base_uri: ByteArray) {␊ - self.accesscontrol.assert_only_role(URI_SETTER_ROLE);␊ - self.erc1155._set_base_uri(base_uri);␊ - }␊ - ␊ - #[external(v0)]␊ - fn setBaseUri(ref self: ContractState, baseUri: ByteArray) {␊ - self.set_base_uri(baseUri);␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.accesscontrol.assert_only_role(UPGRADER_ROLE);␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## no updatable uri - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC1155MixinImpl = ERC1155Component::ERC1155MixinImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl ERC1155InternalImpl = ERC1155Component::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc1155: ERC1155Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC1155Event: ERC1155Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.erc1155.initializer("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/");␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## burnable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress, get_caller_address};␊ - ␊ - component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC1155MixinImpl = ERC1155Component::ERC1155MixinImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl ERC1155InternalImpl = ERC1155Component::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc1155: ERC1155Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC1155Event: ERC1155Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.erc1155.initializer("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/");␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn burn(ref self: ContractState, account: ContractAddress, token_id: u256, value: u256) {␊ - let caller = get_caller_address();␊ - if account != caller {␊ - assert(self.erc1155.is_approved_for_all(account, caller), ERC1155Component::Errors::UNAUTHORIZED);␊ - }␊ - self.erc1155.burn(account, token_id, value);␊ - }␊ - ␊ - #[external(v0)]␊ - fn batch_burn(␊ - ref self: ContractState,␊ - account: ContractAddress,␊ - token_ids: Span,␊ - values: Span,␊ - ) {␊ - let caller = get_caller_address();␊ - if account != caller {␊ - assert(self.erc1155.is_approved_for_all(account, caller), ERC1155Component::Errors::UNAUTHORIZED);␊ - }␊ - self.erc1155.batch_burn(account, token_ids, values);␊ - }␊ - ␊ - #[external(v0)]␊ - fn batchBurn(␊ - ref self: ContractState,␊ - account: ContractAddress,␊ - tokenIds: Span,␊ - values: Span,␊ - ) {␊ - self.batch_burn(account, tokenIds, values);␊ - }␊ - ␊ - #[external(v0)]␊ - fn set_base_uri(ref self: ContractState, base_uri: ByteArray) {␊ - self.ownable.assert_only_owner();␊ - self.erc1155._set_base_uri(base_uri);␊ - }␊ - ␊ - #[external(v0)]␊ - fn setBaseUri(ref self: ContractState, baseUri: ByteArray) {␊ - self.set_base_uri(baseUri);␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## pausable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::security::pausable::PausableComponent;␊ - use openzeppelin::token::erc1155::ERC1155Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC1155MixinImpl = ERC1155Component::ERC1155MixinImpl;␊ - #[abi(embed_v0)]␊ - impl PausableImpl = PausableComponent::PausableImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl ERC1155InternalImpl = ERC1155Component::InternalImpl;␊ - impl PausableInternalImpl = PausableComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc1155: ERC1155Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - pausable: PausableComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC1155Event: ERC1155Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - PausableEvent: PausableComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.erc1155.initializer("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/");␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - impl ERC1155HooksImpl of ERC1155Component::ERC1155HooksTrait {␊ - fn before_update(␊ - ref self: ERC1155Component::ComponentState,␊ - from: ContractAddress,␊ - to: ContractAddress,␊ - token_ids: Span,␊ - values: Span,␊ - ) {␊ - let contract_state = self.get_contract();␊ - contract_state.pausable.assert_not_paused();␊ - }␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn pause(ref self: ContractState) {␊ - self.ownable.assert_only_owner();␊ - self.pausable.pause();␊ - }␊ - ␊ - #[external(v0)]␊ - fn unpause(ref self: ContractState) {␊ - self.ownable.assert_only_owner();␊ - self.pausable.unpause();␊ - }␊ - ␊ - #[external(v0)]␊ - fn set_base_uri(ref self: ContractState, base_uri: ByteArray) {␊ - self.ownable.assert_only_owner();␊ - self.erc1155._set_base_uri(base_uri);␊ - }␊ - ␊ - #[external(v0)]␊ - fn setBaseUri(ref self: ContractState, baseUri: ByteArray) {␊ - self.set_base_uri(baseUri);␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## mintable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC1155MixinImpl = ERC1155Component::ERC1155MixinImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl ERC1155InternalImpl = ERC1155Component::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc1155: ERC1155Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC1155Event: ERC1155Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.erc1155.initializer("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/");␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn mint(␊ - ref self: ContractState,␊ - account: ContractAddress,␊ - token_id: u256,␊ - value: u256,␊ - data: Span,␊ - ) {␊ - self.ownable.assert_only_owner();␊ - self.erc1155.mint_with_acceptance_check(account, token_id, value, data);␊ - }␊ - ␊ - #[external(v0)]␊ - fn batch_mint(␊ - ref self: ContractState,␊ - account: ContractAddress,␊ - token_ids: Span,␊ - values: Span,␊ - data: Span,␊ - ) {␊ - self.ownable.assert_only_owner();␊ - self.erc1155.batch_mint_with_acceptance_check(account, token_ids, values, data);␊ - }␊ - ␊ - #[external(v0)]␊ - fn batchMint(␊ - ref self: ContractState,␊ - account: ContractAddress,␊ - tokenIds: Span,␊ - values: Span,␊ - data: Span,␊ - ) {␊ - self.batch_mint(account, tokenIds, values, data);␊ - }␊ - ␊ - #[external(v0)]␊ - fn set_base_uri(ref self: ContractState, base_uri: ByteArray) {␊ - self.ownable.assert_only_owner();␊ - self.erc1155._set_base_uri(base_uri);␊ - }␊ - ␊ - #[external(v0)]␊ - fn setBaseUri(ref self: ContractState, baseUri: ByteArray) {␊ - self.set_base_uri(baseUri);␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## mintable + roles - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - const MINTER_ROLE: felt252 = selector!("MINTER_ROLE");␊ - const URI_SETTER_ROLE: felt252 = selector!("URI_SETTER_ROLE");␊ - const UPGRADER_ROLE: felt252 = selector!("UPGRADER_ROLE");␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::accesscontrol::{AccessControlComponent, DEFAULT_ADMIN_ROLE};␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - use super::{MINTER_ROLE, UPGRADER_ROLE, URI_SETTER_ROLE};␊ - ␊ - component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC1155MixinImpl = ERC1155Component::ERC1155MixinImpl;␊ - #[abi(embed_v0)]␊ - impl AccessControlImpl = AccessControlComponent::AccessControlImpl;␊ - #[abi(embed_v0)]␊ - impl AccessControlCamelImpl = AccessControlComponent::AccessControlCamelImpl;␊ - ␊ - // Internal␊ - impl ERC1155InternalImpl = ERC1155Component::InternalImpl;␊ - impl AccessControlInternalImpl = AccessControlComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc1155: ERC1155Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - accesscontrol: AccessControlComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC1155Event: ERC1155Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - AccessControlEvent: AccessControlComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - default_admin: ContractAddress,␊ - minter: ContractAddress,␊ - uri_setter: ContractAddress,␊ - upgrader: ContractAddress,␊ - ) {␊ - self.erc1155.initializer("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/");␊ - self.accesscontrol.initializer();␊ - ␊ - self.accesscontrol._grant_role(DEFAULT_ADMIN_ROLE, default_admin);␊ - self.accesscontrol._grant_role(MINTER_ROLE, minter);␊ - self.accesscontrol._grant_role(URI_SETTER_ROLE, uri_setter);␊ - self.accesscontrol._grant_role(UPGRADER_ROLE, upgrader);␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn mint(␊ - ref self: ContractState,␊ - account: ContractAddress,␊ - token_id: u256,␊ - value: u256,␊ - data: Span,␊ - ) {␊ - self.accesscontrol.assert_only_role(MINTER_ROLE);␊ - self.erc1155.mint_with_acceptance_check(account, token_id, value, data);␊ - }␊ - ␊ - #[external(v0)]␊ - fn batch_mint(␊ - ref self: ContractState,␊ - account: ContractAddress,␊ - token_ids: Span,␊ - values: Span,␊ - data: Span,␊ - ) {␊ - self.accesscontrol.assert_only_role(MINTER_ROLE);␊ - self.erc1155.batch_mint_with_acceptance_check(account, token_ids, values, data);␊ - }␊ - ␊ - #[external(v0)]␊ - fn batchMint(␊ - ref self: ContractState,␊ - account: ContractAddress,␊ - tokenIds: Span,␊ - values: Span,␊ - data: Span,␊ - ) {␊ - self.batch_mint(account, tokenIds, values, data);␊ - }␊ - ␊ - #[external(v0)]␊ - fn set_base_uri(ref self: ContractState, base_uri: ByteArray) {␊ - self.accesscontrol.assert_only_role(URI_SETTER_ROLE);␊ - self.erc1155._set_base_uri(base_uri);␊ - }␊ - ␊ - #[external(v0)]␊ - fn setBaseUri(ref self: ContractState, baseUri: ByteArray) {␊ - self.set_base_uri(baseUri);␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.accesscontrol.assert_only_role(UPGRADER_ROLE);␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## royalty info disabled - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC1155MixinImpl = ERC1155Component::ERC1155MixinImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl ERC1155InternalImpl = ERC1155Component::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc1155: ERC1155Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC1155Event: ERC1155Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.erc1155.initializer("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/");␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn set_base_uri(ref self: ContractState, base_uri: ByteArray) {␊ - self.ownable.assert_only_owner();␊ - self.erc1155._set_base_uri(base_uri);␊ - }␊ - ␊ - #[external(v0)]␊ - fn setBaseUri(ref self: ContractState, baseUri: ByteArray) {␊ - self.set_base_uri(baseUri);␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## royalty info enabled default + ownable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::common::erc2981::{DefaultConfig, ERC2981Component};␊ - use openzeppelin::token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - component!(path: ERC2981Component, storage: erc2981, event: ERC2981Event);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC1155MixinImpl = ERC1155Component::ERC1155MixinImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981Impl = ERC2981Component::ERC2981Impl;␊ - #[abi(embed_v0)]␊ - impl ERC2981InfoImpl = ERC2981Component::ERC2981InfoImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981AdminOwnableImpl = ERC2981Component::ERC2981AdminOwnableImpl;␊ - ␊ - // Internal␊ - impl ERC1155InternalImpl = ERC1155Component::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - impl ERC2981InternalImpl = ERC2981Component::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc1155: ERC1155Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - #[substorage(v0)]␊ - erc2981: ERC2981Component::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC1155Event: ERC1155Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - #[flat]␊ - ERC2981Event: ERC2981Component::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - owner: ContractAddress,␊ - default_royalty_receiver: ContractAddress,␊ - ) {␊ - self.erc1155.initializer("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/");␊ - self.ownable.initializer(owner);␊ - self.erc2981.initializer(default_royalty_receiver, 500);␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn set_base_uri(ref self: ContractState, base_uri: ByteArray) {␊ - self.ownable.assert_only_owner();␊ - self.erc1155._set_base_uri(base_uri);␊ - }␊ - ␊ - #[external(v0)]␊ - fn setBaseUri(ref self: ContractState, baseUri: ByteArray) {␊ - self.set_base_uri(baseUri);␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## royalty info enabled default + roles - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - const URI_SETTER_ROLE: felt252 = selector!("URI_SETTER_ROLE");␊ - const UPGRADER_ROLE: felt252 = selector!("UPGRADER_ROLE");␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::accesscontrol::{AccessControlComponent, DEFAULT_ADMIN_ROLE};␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::common::erc2981::{DefaultConfig, ERC2981Component};␊ - use openzeppelin::token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - use super::{UPGRADER_ROLE, URI_SETTER_ROLE};␊ - ␊ - component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - component!(path: ERC2981Component, storage: erc2981, event: ERC2981Event);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC1155MixinImpl = ERC1155Component::ERC1155MixinImpl;␊ - #[abi(embed_v0)]␊ - impl AccessControlImpl = AccessControlComponent::AccessControlImpl;␊ - #[abi(embed_v0)]␊ - impl AccessControlCamelImpl = AccessControlComponent::AccessControlCamelImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981Impl = ERC2981Component::ERC2981Impl;␊ - #[abi(embed_v0)]␊ - impl ERC2981InfoImpl = ERC2981Component::ERC2981InfoImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981AdminAccessControlImpl = ERC2981Component::ERC2981AdminAccessControlImpl;␊ - ␊ - // Internal␊ - impl ERC1155InternalImpl = ERC1155Component::InternalImpl;␊ - impl AccessControlInternalImpl = AccessControlComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - impl ERC2981InternalImpl = ERC2981Component::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc1155: ERC1155Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - accesscontrol: AccessControlComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - #[substorage(v0)]␊ - erc2981: ERC2981Component::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC1155Event: ERC1155Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - AccessControlEvent: AccessControlComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - #[flat]␊ - ERC2981Event: ERC2981Component::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - default_admin: ContractAddress,␊ - uri_setter: ContractAddress,␊ - upgrader: ContractAddress,␊ - default_royalty_receiver: ContractAddress,␊ - royalty_admin: ContractAddress,␊ - ) {␊ - self.erc1155.initializer("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/");␊ - self.accesscontrol.initializer();␊ - self.erc2981.initializer(default_royalty_receiver, 500);␊ - ␊ - self.accesscontrol._grant_role(DEFAULT_ADMIN_ROLE, default_admin);␊ - self.accesscontrol._grant_role(URI_SETTER_ROLE, uri_setter);␊ - self.accesscontrol._grant_role(UPGRADER_ROLE, upgrader);␊ - self.accesscontrol._grant_role(ERC2981Component::ROYALTY_ADMIN_ROLE, royalty_admin);␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn set_base_uri(ref self: ContractState, base_uri: ByteArray) {␊ - self.accesscontrol.assert_only_role(URI_SETTER_ROLE);␊ - self.erc1155._set_base_uri(base_uri);␊ - }␊ - ␊ - #[external(v0)]␊ - fn setBaseUri(ref self: ContractState, baseUri: ByteArray) {␊ - self.set_base_uri(baseUri);␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.accesscontrol.assert_only_role(UPGRADER_ROLE);␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## royalty info enabled custom + ownable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::common::erc2981::ERC2981Component;␊ - use openzeppelin::token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - component!(path: ERC2981Component, storage: erc2981, event: ERC2981Event);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC1155MixinImpl = ERC1155Component::ERC1155MixinImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981Impl = ERC2981Component::ERC2981Impl;␊ - #[abi(embed_v0)]␊ - impl ERC2981InfoImpl = ERC2981Component::ERC2981InfoImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981AdminOwnableImpl = ERC2981Component::ERC2981AdminOwnableImpl;␊ - ␊ - // Internal␊ - impl ERC1155InternalImpl = ERC1155Component::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - impl ERC2981InternalImpl = ERC2981Component::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc1155: ERC1155Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - #[substorage(v0)]␊ - erc2981: ERC2981Component::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC1155Event: ERC1155Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - #[flat]␊ - ERC2981Event: ERC2981Component::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - owner: ContractAddress,␊ - default_royalty_receiver: ContractAddress,␊ - ) {␊ - self.erc1155.initializer("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/");␊ - self.ownable.initializer(owner);␊ - self.erc2981.initializer(default_royalty_receiver, 15125);␊ - }␊ - ␊ - impl ERC2981ImmutableConfig of ERC2981Component::ImmutableConfig {␊ - const FEE_DENOMINATOR: u128 = 100000;␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn set_base_uri(ref self: ContractState, base_uri: ByteArray) {␊ - self.ownable.assert_only_owner();␊ - self.erc1155._set_base_uri(base_uri);␊ - }␊ - ␊ - #[external(v0)]␊ - fn setBaseUri(ref self: ContractState, baseUri: ByteArray) {␊ - self.set_base_uri(baseUri);␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## royalty info enabled custom + roles - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - const URI_SETTER_ROLE: felt252 = selector!("URI_SETTER_ROLE");␊ - const UPGRADER_ROLE: felt252 = selector!("UPGRADER_ROLE");␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::accesscontrol::{AccessControlComponent, DEFAULT_ADMIN_ROLE};␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::common::erc2981::ERC2981Component;␊ - use openzeppelin::token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - use super::{UPGRADER_ROLE, URI_SETTER_ROLE};␊ - ␊ - component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - component!(path: ERC2981Component, storage: erc2981, event: ERC2981Event);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC1155MixinImpl = ERC1155Component::ERC1155MixinImpl;␊ - #[abi(embed_v0)]␊ - impl AccessControlImpl = AccessControlComponent::AccessControlImpl;␊ - #[abi(embed_v0)]␊ - impl AccessControlCamelImpl = AccessControlComponent::AccessControlCamelImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981Impl = ERC2981Component::ERC2981Impl;␊ - #[abi(embed_v0)]␊ - impl ERC2981InfoImpl = ERC2981Component::ERC2981InfoImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981AdminAccessControlImpl = ERC2981Component::ERC2981AdminAccessControlImpl;␊ - ␊ - // Internal␊ - impl ERC1155InternalImpl = ERC1155Component::InternalImpl;␊ - impl AccessControlInternalImpl = AccessControlComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - impl ERC2981InternalImpl = ERC2981Component::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc1155: ERC1155Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - accesscontrol: AccessControlComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - #[substorage(v0)]␊ - erc2981: ERC2981Component::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC1155Event: ERC1155Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - AccessControlEvent: AccessControlComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - #[flat]␊ - ERC2981Event: ERC2981Component::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - default_admin: ContractAddress,␊ - uri_setter: ContractAddress,␊ - upgrader: ContractAddress,␊ - default_royalty_receiver: ContractAddress,␊ - royalty_admin: ContractAddress,␊ - ) {␊ - self.erc1155.initializer("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/");␊ - self.accesscontrol.initializer();␊ - self.erc2981.initializer(default_royalty_receiver, 15125);␊ - ␊ - self.accesscontrol._grant_role(DEFAULT_ADMIN_ROLE, default_admin);␊ - self.accesscontrol._grant_role(URI_SETTER_ROLE, uri_setter);␊ - self.accesscontrol._grant_role(UPGRADER_ROLE, upgrader);␊ - self.accesscontrol._grant_role(ERC2981Component::ROYALTY_ADMIN_ROLE, royalty_admin);␊ - }␊ - ␊ - impl ERC2981ImmutableConfig of ERC2981Component::ImmutableConfig {␊ - const FEE_DENOMINATOR: u128 = 100000;␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn set_base_uri(ref self: ContractState, base_uri: ByteArray) {␊ - self.accesscontrol.assert_only_role(URI_SETTER_ROLE);␊ - self.erc1155._set_base_uri(base_uri);␊ - }␊ - ␊ - #[external(v0)]␊ - fn setBaseUri(ref self: ContractState, baseUri: ByteArray) {␊ - self.set_base_uri(baseUri);␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.accesscontrol.assert_only_role(UPGRADER_ROLE);␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## full non-upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - const PAUSER_ROLE: felt252 = selector!("PAUSER_ROLE");␊ - const MINTER_ROLE: felt252 = selector!("MINTER_ROLE");␊ - const URI_SETTER_ROLE: felt252 = selector!("URI_SETTER_ROLE");␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::accesscontrol::{AccessControlComponent, DEFAULT_ADMIN_ROLE};␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::security::pausable::PausableComponent;␊ - use openzeppelin::token::common::erc2981::{DefaultConfig, ERC2981Component};␊ - use openzeppelin::token::erc1155::ERC1155Component;␊ - use starknet::{ContractAddress, get_caller_address};␊ - use super::{MINTER_ROLE, PAUSER_ROLE, URI_SETTER_ROLE};␊ - ␊ - component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ - component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent);␊ - component!(path: ERC2981Component, storage: erc2981, event: ERC2981Event);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC1155MixinImpl = ERC1155Component::ERC1155MixinImpl;␊ - #[abi(embed_v0)]␊ - impl PausableImpl = PausableComponent::PausableImpl;␊ - #[abi(embed_v0)]␊ - impl AccessControlImpl = AccessControlComponent::AccessControlImpl;␊ - #[abi(embed_v0)]␊ - impl AccessControlCamelImpl = AccessControlComponent::AccessControlCamelImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981Impl = ERC2981Component::ERC2981Impl;␊ - #[abi(embed_v0)]␊ - impl ERC2981InfoImpl = ERC2981Component::ERC2981InfoImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981AdminAccessControlImpl = ERC2981Component::ERC2981AdminAccessControlImpl;␊ - ␊ - // Internal␊ - impl ERC1155InternalImpl = ERC1155Component::InternalImpl;␊ - impl PausableInternalImpl = PausableComponent::InternalImpl;␊ - impl AccessControlInternalImpl = AccessControlComponent::InternalImpl;␊ - impl ERC2981InternalImpl = ERC2981Component::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc1155: ERC1155Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - pausable: PausableComponent::Storage,␊ - #[substorage(v0)]␊ - accesscontrol: AccessControlComponent::Storage,␊ - #[substorage(v0)]␊ - erc2981: ERC2981Component::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC1155Event: ERC1155Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - PausableEvent: PausableComponent::Event,␊ - #[flat]␊ - AccessControlEvent: AccessControlComponent::Event,␊ - #[flat]␊ - ERC2981Event: ERC2981Component::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - default_admin: ContractAddress,␊ - pauser: ContractAddress,␊ - minter: ContractAddress,␊ - uri_setter: ContractAddress,␊ - default_royalty_receiver: ContractAddress,␊ - royalty_admin: ContractAddress,␊ - ) {␊ - self.erc1155.initializer("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/");␊ - self.accesscontrol.initializer();␊ - self.erc2981.initializer(default_royalty_receiver, 500);␊ - ␊ - self.accesscontrol._grant_role(DEFAULT_ADMIN_ROLE, default_admin);␊ - self.accesscontrol._grant_role(PAUSER_ROLE, pauser);␊ - self.accesscontrol._grant_role(MINTER_ROLE, minter);␊ - self.accesscontrol._grant_role(URI_SETTER_ROLE, uri_setter);␊ - self.accesscontrol._grant_role(ERC2981Component::ROYALTY_ADMIN_ROLE, royalty_admin);␊ - }␊ - ␊ - impl ERC1155HooksImpl of ERC1155Component::ERC1155HooksTrait {␊ - fn before_update(␊ - ref self: ERC1155Component::ComponentState,␊ - from: ContractAddress,␊ - to: ContractAddress,␊ - token_ids: Span,␊ - values: Span,␊ - ) {␊ - let contract_state = self.get_contract();␊ - contract_state.pausable.assert_not_paused();␊ - }␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn pause(ref self: ContractState) {␊ - self.accesscontrol.assert_only_role(PAUSER_ROLE);␊ - self.pausable.pause();␊ - }␊ - ␊ - #[external(v0)]␊ - fn unpause(ref self: ContractState) {␊ - self.accesscontrol.assert_only_role(PAUSER_ROLE);␊ - self.pausable.unpause();␊ - }␊ - ␊ - #[external(v0)]␊ - fn burn(ref self: ContractState, account: ContractAddress, token_id: u256, value: u256) {␊ - let caller = get_caller_address();␊ - if account != caller {␊ - assert(self.erc1155.is_approved_for_all(account, caller), ERC1155Component::Errors::UNAUTHORIZED);␊ - }␊ - self.erc1155.burn(account, token_id, value);␊ - }␊ - ␊ - #[external(v0)]␊ - fn batch_burn(␊ - ref self: ContractState,␊ - account: ContractAddress,␊ - token_ids: Span,␊ - values: Span,␊ - ) {␊ - let caller = get_caller_address();␊ - if account != caller {␊ - assert(self.erc1155.is_approved_for_all(account, caller), ERC1155Component::Errors::UNAUTHORIZED);␊ - }␊ - self.erc1155.batch_burn(account, token_ids, values);␊ - }␊ - ␊ - #[external(v0)]␊ - fn batchBurn(␊ - ref self: ContractState,␊ - account: ContractAddress,␊ - tokenIds: Span,␊ - values: Span,␊ - ) {␊ - self.batch_burn(account, tokenIds, values);␊ - }␊ - ␊ - #[external(v0)]␊ - fn mint(␊ - ref self: ContractState,␊ - account: ContractAddress,␊ - token_id: u256,␊ - value: u256,␊ - data: Span,␊ - ) {␊ - self.accesscontrol.assert_only_role(MINTER_ROLE);␊ - self.erc1155.mint_with_acceptance_check(account, token_id, value, data);␊ - }␊ - ␊ - #[external(v0)]␊ - fn batch_mint(␊ - ref self: ContractState,␊ - account: ContractAddress,␊ - token_ids: Span,␊ - values: Span,␊ - data: Span,␊ - ) {␊ - self.accesscontrol.assert_only_role(MINTER_ROLE);␊ - self.erc1155.batch_mint_with_acceptance_check(account, token_ids, values, data);␊ - }␊ - ␊ - #[external(v0)]␊ - fn batchMint(␊ - ref self: ContractState,␊ - account: ContractAddress,␊ - tokenIds: Span,␊ - values: Span,␊ - data: Span,␊ - ) {␊ - self.batch_mint(account, tokenIds, values, data);␊ - }␊ - ␊ - #[external(v0)]␊ - fn set_base_uri(ref self: ContractState, base_uri: ByteArray) {␊ - self.accesscontrol.assert_only_role(URI_SETTER_ROLE);␊ - self.erc1155._set_base_uri(base_uri);␊ - }␊ - ␊ - #[external(v0)]␊ - fn setBaseUri(ref self: ContractState, baseUri: ByteArray) {␊ - self.set_base_uri(baseUri);␊ - }␊ - }␊ - }␊ - ` - -## full upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - const PAUSER_ROLE: felt252 = selector!("PAUSER_ROLE");␊ - const MINTER_ROLE: felt252 = selector!("MINTER_ROLE");␊ - const URI_SETTER_ROLE: felt252 = selector!("URI_SETTER_ROLE");␊ - const UPGRADER_ROLE: felt252 = selector!("UPGRADER_ROLE");␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::accesscontrol::{AccessControlComponent, DEFAULT_ADMIN_ROLE};␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::security::pausable::PausableComponent;␊ - use openzeppelin::token::common::erc2981::{DefaultConfig, ERC2981Component};␊ - use openzeppelin::token::erc1155::ERC1155Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress, get_caller_address};␊ - use super::{MINTER_ROLE, PAUSER_ROLE, UPGRADER_ROLE, URI_SETTER_ROLE};␊ - ␊ - component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ - component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - component!(path: ERC2981Component, storage: erc2981, event: ERC2981Event);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC1155MixinImpl = ERC1155Component::ERC1155MixinImpl;␊ - #[abi(embed_v0)]␊ - impl PausableImpl = PausableComponent::PausableImpl;␊ - #[abi(embed_v0)]␊ - impl AccessControlImpl = AccessControlComponent::AccessControlImpl;␊ - #[abi(embed_v0)]␊ - impl AccessControlCamelImpl = AccessControlComponent::AccessControlCamelImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981Impl = ERC2981Component::ERC2981Impl;␊ - #[abi(embed_v0)]␊ - impl ERC2981InfoImpl = ERC2981Component::ERC2981InfoImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981AdminAccessControlImpl = ERC2981Component::ERC2981AdminAccessControlImpl;␊ - ␊ - // Internal␊ - impl ERC1155InternalImpl = ERC1155Component::InternalImpl;␊ - impl PausableInternalImpl = PausableComponent::InternalImpl;␊ - impl AccessControlInternalImpl = AccessControlComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - impl ERC2981InternalImpl = ERC2981Component::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc1155: ERC1155Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - pausable: PausableComponent::Storage,␊ - #[substorage(v0)]␊ - accesscontrol: AccessControlComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - #[substorage(v0)]␊ - erc2981: ERC2981Component::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC1155Event: ERC1155Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - PausableEvent: PausableComponent::Event,␊ - #[flat]␊ - AccessControlEvent: AccessControlComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - #[flat]␊ - ERC2981Event: ERC2981Component::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - default_admin: ContractAddress,␊ - pauser: ContractAddress,␊ - minter: ContractAddress,␊ - uri_setter: ContractAddress,␊ - upgrader: ContractAddress,␊ - default_royalty_receiver: ContractAddress,␊ - royalty_admin: ContractAddress,␊ - ) {␊ - self.erc1155.initializer("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/");␊ - self.accesscontrol.initializer();␊ - self.erc2981.initializer(default_royalty_receiver, 500);␊ - ␊ - self.accesscontrol._grant_role(DEFAULT_ADMIN_ROLE, default_admin);␊ - self.accesscontrol._grant_role(PAUSER_ROLE, pauser);␊ - self.accesscontrol._grant_role(MINTER_ROLE, minter);␊ - self.accesscontrol._grant_role(URI_SETTER_ROLE, uri_setter);␊ - self.accesscontrol._grant_role(UPGRADER_ROLE, upgrader);␊ - self.accesscontrol._grant_role(ERC2981Component::ROYALTY_ADMIN_ROLE, royalty_admin);␊ - }␊ - ␊ - impl ERC1155HooksImpl of ERC1155Component::ERC1155HooksTrait {␊ - fn before_update(␊ - ref self: ERC1155Component::ComponentState,␊ - from: ContractAddress,␊ - to: ContractAddress,␊ - token_ids: Span,␊ - values: Span,␊ - ) {␊ - let contract_state = self.get_contract();␊ - contract_state.pausable.assert_not_paused();␊ - }␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn pause(ref self: ContractState) {␊ - self.accesscontrol.assert_only_role(PAUSER_ROLE);␊ - self.pausable.pause();␊ - }␊ - ␊ - #[external(v0)]␊ - fn unpause(ref self: ContractState) {␊ - self.accesscontrol.assert_only_role(PAUSER_ROLE);␊ - self.pausable.unpause();␊ - }␊ - ␊ - #[external(v0)]␊ - fn burn(ref self: ContractState, account: ContractAddress, token_id: u256, value: u256) {␊ - let caller = get_caller_address();␊ - if account != caller {␊ - assert(self.erc1155.is_approved_for_all(account, caller), ERC1155Component::Errors::UNAUTHORIZED);␊ - }␊ - self.erc1155.burn(account, token_id, value);␊ - }␊ - ␊ - #[external(v0)]␊ - fn batch_burn(␊ - ref self: ContractState,␊ - account: ContractAddress,␊ - token_ids: Span,␊ - values: Span,␊ - ) {␊ - let caller = get_caller_address();␊ - if account != caller {␊ - assert(self.erc1155.is_approved_for_all(account, caller), ERC1155Component::Errors::UNAUTHORIZED);␊ - }␊ - self.erc1155.batch_burn(account, token_ids, values);␊ - }␊ - ␊ - #[external(v0)]␊ - fn batchBurn(␊ - ref self: ContractState,␊ - account: ContractAddress,␊ - tokenIds: Span,␊ - values: Span,␊ - ) {␊ - self.batch_burn(account, tokenIds, values);␊ - }␊ - ␊ - #[external(v0)]␊ - fn mint(␊ - ref self: ContractState,␊ - account: ContractAddress,␊ - token_id: u256,␊ - value: u256,␊ - data: Span,␊ - ) {␊ - self.accesscontrol.assert_only_role(MINTER_ROLE);␊ - self.erc1155.mint_with_acceptance_check(account, token_id, value, data);␊ - }␊ - ␊ - #[external(v0)]␊ - fn batch_mint(␊ - ref self: ContractState,␊ - account: ContractAddress,␊ - token_ids: Span,␊ - values: Span,␊ - data: Span,␊ - ) {␊ - self.accesscontrol.assert_only_role(MINTER_ROLE);␊ - self.erc1155.batch_mint_with_acceptance_check(account, token_ids, values, data);␊ - }␊ - ␊ - #[external(v0)]␊ - fn batchMint(␊ - ref self: ContractState,␊ - account: ContractAddress,␊ - tokenIds: Span,␊ - values: Span,␊ - data: Span,␊ - ) {␊ - self.batch_mint(account, tokenIds, values, data);␊ - }␊ - ␊ - #[external(v0)]␊ - fn set_base_uri(ref self: ContractState, base_uri: ByteArray) {␊ - self.accesscontrol.assert_only_role(URI_SETTER_ROLE);␊ - self.erc1155._set_base_uri(base_uri);␊ - }␊ - ␊ - #[external(v0)]␊ - fn setBaseUri(ref self: ContractState, baseUri: ByteArray) {␊ - self.set_base_uri(baseUri);␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.accesscontrol.assert_only_role(UPGRADER_ROLE);␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` diff --git a/packages/core/stylus/src/erc1155.test.ts.snap b/packages/core/stylus/src/erc1155.test.ts.snap deleted file mode 100644 index ee615fb389db7c1778b57cf1ffced23782e6329d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3417 zcmV-f4W{xzRzVtHZcft*B61R&TLqpV}PhIS4FoLP=dG;UZ_Q5>diDa!FtbE~i>_d28~glQWaTU&~9)jDc=-{OjO6#nIrdYLe>4WR84YRAxG<=vNwl3(h@vD5eHp3tm}5@9dS1{**h8_6qK;{s{-X^4_J3LZasFBcUfi4`*T#cjS;BVn=7nXCoVbNNwI`0$R2pNM3 z#nf*g#lHdNi8)sNXaUGjf+XcS8n!<(--bVWgc)a~w#zKLF5I2Ld<_Z_>JE_q2T3cs ziTSV>;?0+(5dT6ww|acbr8H4cQM|vhR3KE36`)x(u(rhlK{`dk-)fBL$RVb#AZg;% zJym|lqS6bRh3hswQbn%Hq(Vy9nEt~l3A;w@#0%hI19QgH5Lu|gGa#1_dBi=_z` zN=VEyH@J7>N)hgg>^lgY#p3G8Wh76N;B$h{S#F;*e27HP5@DK)R|=kI;+h`XQS_7& z%eK&4okr_b{&*=lS2fQ;Qv2BHD=2oBreHo{v5dag4Si1{0uS6Bu?60zt@-C z_1E|A)Lr-27<6*fR*zeqPU}cLI(XGmkWNg#xwVP5y%7^{1$tO}lqluh>|yo8Umi7f z3o46cysA?`3c>$=UCUIItA_u(8T=NUzunf0#>uOW+SuJ|@B1Cdb>IO@q_IR?-n9u+ zlq<=U_2lF!7x>7VGO;*mj>U4NYRd^nBo%~>WNTAVQe|(`Rud1%SPjM%<_3o3@yjyv zh5*3mcECt}IOM7sK+>2XDZTXND|e27DQ+asMT`sdh>l&8tGG8XXbMRU%el<(9Cn@o zx9Z6`l2>F=aG7*-NR3Aio1CKRDZ`Yjp6^;qyH#~rnWI}3MJ0TQx}fYagvfqLWQvMG zO?mtxV#(4Zz|RuE&mxnG^LqM#)TS14Z4Y~T_|auX8k2tTZwZtB>jMZORUh`12*phY zWMztmT%Nh1rm13^qz)iMXkuJ5TH12w8%+Rdvcy2z5*jmvR3Ue8meGiQ*JU(2)A^$Z zlGAtZBXIgE?)25sDdDPyO_MMcm(dY~T%syEf{;rDxkP1i1R$?%E(NmDSx%GJ+ong}@!H=Y4XcCTs2Q%8vcuFTdLqm_6MGv>5in2uS6L^?4 z*{Y6;ZJSwVq^If@Q?Y5*LRs}t(vy1Djl`J6JU?W=angBtaMXU&+D-K8I_Qj`%@Y~qzLvpQNY?7f|ghI+Ff~3fFv9zc#P!v<3C?aKs@>7Nw-Y}KtKjMMP z;xbeMd`j?H3_c}Z+p|msyv$s98EK8qGz<_si%IN=3#%Vii5Z)`M~`31=W#}Q-(8|x zjHrGN6v;!9=|zqGnFf`Mt`!L8btrVod}MjSYHTIJr`{VD=-0ML+-P&VKTxOI6F54? z^uKrK>Yq6FKbiK0S(Td{FrmT#z5{%p(0sRi!8C&J`I{bn`f~}!uYWp&O^^24`vn^w z2_=Nhj$p4OpeAm-SCTM=>IgPYf{l}4KdpG7Nr#%V$SlpOhg-0f*WWpv~9Gm$V)mC{=n!bU6^j&du@VfD;^I96B zG*K!>6hZ29<;bJ?raoW%G?Px!T!&kOQ7IJnA4`1Fk6{bJLdqt&d@UbCQzF6zGA1Bn zV!;Ux$d~{kqgV=LOjM1$fQ$*qm>7>Y*x1_G+{!)|B6!jbTpn283nqrALnK$cM4_R= zf@tlFR!iM&?H}y5_ZyvqBL%q|n_r-9w6X4eqPEc-Pcwj=4S?Mfn(vk%`|)UyotLul zdkJFOpFqk+sZ%xp|0BrIfD8@D(0~jL$j|^{W8TCDWN0ih$pIM}kfBk+42_6s8Pyu( zXpG9y0AdPqM1ZUs&!l&oBf@ppG!eDvQ$bFeu6odt=&H{j%z&;sY@8gAW}Ac(Lz-&V zhgejN;c|%PGJ{_#N_<$mk~$N7Zf`Utoz!feD&d_V{{UxfnuMwNW(QLUQ>*0MRmygP zq{zatH0dn(xv^oDqO2m7hVoP97~WmLhXEh9kbGD?L1l3nQ+eL}8ZcqW`td_N%UpA1 z)RvnAlb*Dh#+e<7Ru1;do5>?Ns_C4n0_0e^USEf zpTZi+b99MrF`~M54|9@t8b-R2_^U57(Sm%Ah0d%&;b9qfd$>uGk}(NK5r|hEug?Ji zps)HEGQ5(^Ba&;ZM$g=c&7l@o{h8UTWpFWQj_jo0t2`!a61qyb8?(r&STjMxW7CZ; zom-EirpG@~#$`00EX+MKCV60zct}#_to8W~w4FhAB&VyPN6n&#+fhYXqW1|@Rg<4q zj*4xYS!blD>K0S6X%0`62_!wKXDvO9SOZBTj0{P(}L|nt+4d;9xg6*bNSL z8%tpjxt?<5Iu5$pe$aJfz!m*h3b_6ULBJK>MyO1zb`f7;xP6qkLN7d&FlY>~P(VBy z;?WR~UZ{99yzjB>QEqr|q?$4FrF!vXMxl3jbp@jHixr(;oL6Qbybs}h2=7C9zmnl! v2=7 = { - name: 'MyToken', - baseUri: '', - burnable: false, - pausable: false, - mintable: false, - updatableUri: true, - royaltyInfo: royaltyInfoDefaults, - access: commonDefaults.access, - upgradeable: commonDefaults.upgradeable, - info: commonDefaults.info -} as const; - -export function printERC1155(opts: ERC1155Options = defaults): string { - return printContract(buildERC1155(opts)); -} - -export interface ERC1155Options extends CommonContractOptions { - name: string; - baseUri: string; - burnable?: boolean; - pausable?: boolean; - mintable?: boolean; - updatableUri?: boolean; - royaltyInfo?: RoyaltyInfoOptions; -} - -function withDefaults(opts: ERC1155Options): Required { - return { - ...opts, - ...withCommonContractDefaults(opts), - burnable: opts.burnable ?? defaults.burnable, - pausable: opts.pausable ?? defaults.pausable, - mintable: opts.mintable ?? defaults.mintable, - updatableUri: opts.updatableUri ?? defaults.updatableUri, - royaltyInfo: opts.royaltyInfo ?? defaults.royaltyInfo, - }; -} - -export function isAccessControlRequired(opts: Partial): boolean { - return opts.mintable === true || opts.pausable === true || opts.updatableUri !== false || opts.upgradeable === true || opts.royaltyInfo?.enabled === true; -} - -export function buildERC1155(opts: ERC1155Options): Contract { - const c = new ContractBuilder(opts.name); - - const allOpts = withDefaults(opts); - - addBase(c, toByteArray(allOpts.baseUri)); - addERC1155Mixin(c); - - if (allOpts.pausable) { - addPausable(c, allOpts.access); - } - - if (allOpts.burnable) { - addBurnable(c); - } - - if (allOpts.mintable) { - addMintable(c, allOpts.access); - } - - if (allOpts.updatableUri) { - addSetBaseUri(c, allOpts.access); - } - - setAccessControl(c, allOpts.access); - setUpgradeable(c, allOpts.upgradeable, allOpts.access); - setInfo(c, allOpts.info); - setRoyaltyInfo(c, allOpts.royaltyInfo, allOpts.access); - - addHooks(c, allOpts); - - return c; -} - -function addHooks(c: ContractBuilder, allOpts: Required) { - const usesCustomHooks = allOpts.pausable; - if (usesCustomHooks) { - const hooksTrait = { - name: 'ERC1155HooksImpl', - of: 'ERC1155Component::ERC1155HooksTrait', - tags: [], - priority: 1, - }; - c.addImplementedTrait(hooksTrait); - c.addUseClause('starknet', 'ContractAddress'); - - c.addFunction(hooksTrait, { - name: 'before_update', - args: [ - { name: 'ref self', type: `ERC1155Component::ComponentState` }, - { name: 'from', type: 'ContractAddress' }, - { name: 'to', type: 'ContractAddress' }, - { name: 'token_ids', type: 'Span' }, - { name: 'values', type: 'Span' }, - ], - code: [ - 'let contract_state = self.get_contract()', - 'contract_state.pausable.assert_not_paused()', - ], - }); - } else { - c.addUseClause('openzeppelin::token::erc1155', 'ERC1155HooksEmptyImpl'); - } -} - -function addERC1155Mixin(c: ContractBuilder) { - c.addImplToComponent(components.ERC1155Component, { - name: 'ERC1155MixinImpl', - value: 'ERC1155Component::ERC1155MixinImpl', - }); - c.addInterfaceFlag('ISRC5'); - addSRC5Component(c); -} - -function addBase(c: ContractBuilder, baseUri: string) { - c.addComponent( - components.ERC1155Component, - [ - baseUri, - ], - true, - ); -} - -function addBurnable(c: ContractBuilder) { - c.addUseClause('starknet', 'ContractAddress'); - c.addUseClause('starknet', 'get_caller_address'); - c.addFunction(externalTrait, functions.burn); - c.addFunction(externalTrait, functions.batch_burn); - c.addFunction(externalTrait, functions.batchBurn); -} - -function addMintable(c: ContractBuilder, access: Access) { - c.addUseClause('starknet', 'ContractAddress'); - requireAccessControl(c, externalTrait, functions.mint, access, 'MINTER', 'minter'); - requireAccessControl(c, externalTrait, functions.batch_mint, access, 'MINTER', 'minter'); - - // Camel case version of batch_mint. Access control and pausable are already set on batch_mint. - c.addFunction(externalTrait, functions.batchMint); -} - -function addSetBaseUri(c: ContractBuilder, access: Access) { - requireAccessControl(c, externalTrait, functions.set_base_uri, access, 'URI_SETTER', 'uri_setter'); - - // Camel case version of set_base_uri. Access control is already set on set_base_uri. - c.addFunction(externalTrait, functions.setBaseUri); -} - -const components = defineComponents( { - ERC1155Component: { - path: 'openzeppelin::token::erc1155', - substorage: { - name: 'erc1155', - type: 'ERC1155Component::Storage', - }, - event: { - name: 'ERC1155Event', - type: 'ERC1155Component::Event', - }, - impls: [{ - name: 'ERC1155InternalImpl', - embed: false, - value: 'ERC1155Component::InternalImpl', - }], - }, -}); - -const functions = defineFunctions({ - burn: { - args: [ - getSelfArg(), - { name: 'account', type: 'ContractAddress' }, - { name: 'token_id', type: 'u256' }, - { name: 'value', type: 'u256' }, - ], - code: [ - 'let caller = get_caller_address();', - 'if account != caller {', - ' assert(self.erc1155.is_approved_for_all(account, caller), ERC1155Component::Errors::UNAUTHORIZED)', - '}', - 'self.erc1155.burn(account, token_id, value);' - ] - }, - batch_burn: { - args: [ - getSelfArg(), - { name: 'account', type: 'ContractAddress' }, - { name: 'token_ids', type: 'Span' }, - { name: 'values', type: 'Span' }, - ], - code: [ - 'let caller = get_caller_address();', - 'if account != caller {', - ' assert(self.erc1155.is_approved_for_all(account, caller), ERC1155Component::Errors::UNAUTHORIZED)', - '}', - 'self.erc1155.batch_burn(account, token_ids, values);' - ] - }, - batchBurn: { - args: [ - getSelfArg(), - { name: 'account', type: 'ContractAddress' }, - { name: 'tokenIds', type: 'Span' }, - { name: 'values', type: 'Span' }, - ], - code: [ - 'self.batch_burn(account, tokenIds, values);' - ] - }, - mint: { - args: [ - getSelfArg(), - { name: 'account', type: 'ContractAddress' }, - { name: 'token_id', type: 'u256' }, - { name: 'value', type: 'u256' }, - { name: 'data', type: 'Span' }, - ], - code: [ - 'self.erc1155.mint_with_acceptance_check(account, token_id, value, data);', - ] - }, - batch_mint: { - args: [ - getSelfArg(), - { name: 'account', type: 'ContractAddress' }, - { name: 'token_ids', type: 'Span' }, - { name: 'values', type: 'Span' }, - { name: 'data', type: 'Span' }, - ], - code: [ - 'self.erc1155.batch_mint_with_acceptance_check(account, token_ids, values, data);', - ] - }, - batchMint: { - args: [ - getSelfArg(), - { name: 'account', type: 'ContractAddress' }, - { name: 'tokenIds', type: 'Span' }, - { name: 'values', type: 'Span' }, - { name: 'data', type: 'Span' }, - ], - code: [ - 'self.batch_mint(account, tokenIds, values, data);', - ] - }, - set_base_uri: { - args: [ - getSelfArg(), - { name: 'base_uri', type: 'ByteArray' }, - ], - code: [ - 'self.erc1155._set_base_uri(base_uri);' - ] - }, - setBaseUri: { - args: [ - getSelfArg(), - { name: 'baseUri', type: 'ByteArray' }, - ], - code: [ - 'self.set_base_uri(baseUri);' - ] - }, -}); diff --git a/packages/core/stylus/src/erc721.test.ts b/packages/core/stylus/src/erc721.test.ts deleted file mode 100644 index 6608368fa..000000000 --- a/packages/core/stylus/src/erc721.test.ts +++ /dev/null @@ -1,191 +0,0 @@ -import test from 'ava'; - -import { buildERC721, ERC721Options } from './erc721'; -import { printContract } from './print'; -import { royaltyInfoOptions } from './set-royalty-info'; - -import { erc721, OptionsError } from '.'; - -const NAME = 'MyToken'; -const CUSTOM_NAME = 'CustomToken'; -const SYMBOL = 'MTK'; -const CUSTOM_SYMBOL = 'CTK'; -const APP_NAME = 'MY_DAPP_NAME'; -const APP_VERSION = 'MY_DAPP_VERSION'; -const BASE_URI = 'https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/'; - -const allFeaturesON: Partial = { - mintable: true, - burnable: true, - pausable: true, - enumerable: true, - royaltyInfo: royaltyInfoOptions.enabledDefault, - votes: true, - appName: APP_NAME, - appVersion: APP_VERSION, - upgradeable: true -} as const; - -function testERC721(title: string, opts: Partial) { - test(title, t => { - const c = buildERC721({ - name: NAME, - symbol: SYMBOL, - ...opts, - }); - t.snapshot(printContract(c)); - }); -} - -/** - * Tests external API for equivalence with internal API - */ - function testAPIEquivalence(title: string, opts?: ERC721Options) { - test(title, t => { - t.is(erc721.print(opts), printContract(buildERC721({ - name: NAME, - symbol: SYMBOL, - ...opts, - }))); - }); -} - -testERC721('basic non-upgradeable', { - upgradeable: false, -}); - -testERC721('basic', {}); - -testERC721('base uri', { - baseUri: BASE_URI, -}); - -testERC721('burnable', { - burnable: true, -}); - -testERC721('pausable', { - pausable: true, -}); - -testERC721('mintable', { - mintable: true, -}); - -testERC721('enumerable', { - enumerable: true, -}); - -testERC721('pausable + enumerable', { - pausable: true, - enumerable: true, -}); - -testERC721('mintable + roles', { - mintable: true, - access: 'roles', -}); - -testERC721('royalty info disabled', { - royaltyInfo: royaltyInfoOptions.disabled -}); - -testERC721('royalty info enabled default + ownable', { - royaltyInfo: royaltyInfoOptions.enabledDefault, - access: 'ownable' -}); - -testERC721('royalty info enabled default + roles', { - royaltyInfo: royaltyInfoOptions.enabledDefault, - access: 'roles' -}); - -testERC721('royalty info enabled custom + ownable', { - royaltyInfo: royaltyInfoOptions.enabledCustom, - access: 'ownable' -}); - -testERC721('royalty info enabled custom + roles', { - royaltyInfo: royaltyInfoOptions.enabledCustom, - access: 'roles' -}); - -testERC721('full non-upgradeable', { - ...allFeaturesON, - upgradeable: false, -}); - -testERC721('erc721 votes', { - votes: true, - appName: APP_NAME, -}); - -testERC721('erc721 votes, version', { - votes: true, - appName: APP_NAME, - appVersion: APP_VERSION, -}); - -test('erc721 votes, no name', async t => { - let error = t.throws(() => buildERC721({ - name: NAME, - symbol: SYMBOL, - votes: true, - })); - t.is((error as OptionsError).messages.appName, 'Application Name is required when Votes are enabled'); -}); - -test('erc721 votes, no version', async t => { - let error = t.throws(() => buildERC721({ - name: NAME, - symbol: SYMBOL, - votes: true, - appName: APP_NAME, - appVersion: '' - })); - t.is((error as OptionsError).messages.appVersion, 'Application Version is required when Votes are enabled'); -}); - -test('erc721 votes, empty version', async t => { - let error = t.throws(() => buildERC721({ - name: NAME, - symbol: SYMBOL, - votes: true, - appName: APP_NAME, - appVersion: '', // avoids default value of v1 - })); - t.is((error as OptionsError).messages.appVersion, 'Application Version is required when Votes are enabled'); -}); - -testERC721('erc721 votes, non-upgradeable', { - votes: true, - appName: APP_NAME, - upgradeable: false, -}); - -testERC721('full upgradeable', allFeaturesON); - -testAPIEquivalence('API default'); - -testAPIEquivalence('API basic', { name: CUSTOM_NAME, symbol: CUSTOM_SYMBOL }); - -testAPIEquivalence('API full upgradeable', { - ...allFeaturesON, - name: CUSTOM_NAME, - symbol: CUSTOM_SYMBOL -}); - -test('API assert defaults', async t => { - t.is(erc721.print(erc721.defaults), erc721.print()); -}); - -test('API isAccessControlRequired', async t => { - t.is(erc721.isAccessControlRequired({ mintable: true }), true); - t.is(erc721.isAccessControlRequired({ pausable: true }), true); - t.is(erc721.isAccessControlRequired({ upgradeable: true }), true); - t.is(erc721.isAccessControlRequired({ royaltyInfo: royaltyInfoOptions.enabledDefault }), true); - t.is(erc721.isAccessControlRequired({ royaltyInfo: royaltyInfoOptions.enabledCustom }), true); - t.is(erc721.isAccessControlRequired({ royaltyInfo: royaltyInfoOptions.disabled }), false); - t.is(erc721.isAccessControlRequired({ burnable: true }), false); - t.is(erc721.isAccessControlRequired({ enumerable: true }), false); -}); \ No newline at end of file diff --git a/packages/core/stylus/src/erc721.test.ts.md b/packages/core/stylus/src/erc721.test.ts.md deleted file mode 100644 index 2006fd867..000000000 --- a/packages/core/stylus/src/erc721.test.ts.md +++ /dev/null @@ -1,2060 +0,0 @@ -# Snapshot report for `src/erc721.test.ts` - -The actual snapshot is saved in `erc721.test.ts.snap`. - -Generated by [AVA](https://avajs.dev). - -## basic non-upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl};␊ - ␊ - component!(path: ERC721Component, storage: erc721, event: ERC721Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl;␊ - ␊ - // Internal␊ - impl ERC721InternalImpl = ERC721Component::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc721: ERC721Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC721Event: ERC721Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState) {␊ - self.erc721.initializer("MyToken", "MTK", "");␊ - }␊ - }␊ - ` - -## basic - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: ERC721Component, storage: erc721, event: ERC721Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl ERC721InternalImpl = ERC721Component::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc721: ERC721Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC721Event: ERC721Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.erc721.initializer("MyToken", "MTK", "");␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## base uri - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: ERC721Component, storage: erc721, event: ERC721Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl ERC721InternalImpl = ERC721Component::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc721: ERC721Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC721Event: ERC721Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.erc721.initializer("MyToken", "MTK", "https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/");␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## burnable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use core::num::traits::Zero;␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress, get_caller_address};␊ - ␊ - component!(path: ERC721Component, storage: erc721, event: ERC721Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl ERC721InternalImpl = ERC721Component::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc721: ERC721Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC721Event: ERC721Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.erc721.initializer("MyToken", "MTK", "");␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn burn(ref self: ContractState, token_id: u256) {␊ - self.erc721.update(Zero::zero(), token_id, get_caller_address());␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## pausable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::security::pausable::PausableComponent;␊ - use openzeppelin::token::erc721::ERC721Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: ERC721Component, storage: erc721, event: ERC721Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl;␊ - #[abi(embed_v0)]␊ - impl PausableImpl = PausableComponent::PausableImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl ERC721InternalImpl = ERC721Component::InternalImpl;␊ - impl PausableInternalImpl = PausableComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc721: ERC721Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - pausable: PausableComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC721Event: ERC721Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - PausableEvent: PausableComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.erc721.initializer("MyToken", "MTK", "");␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - impl ERC721HooksImpl of ERC721Component::ERC721HooksTrait {␊ - fn before_update(␊ - ref self: ERC721Component::ComponentState,␊ - to: ContractAddress,␊ - token_id: u256,␊ - auth: ContractAddress,␊ - ) {␊ - let contract_state = self.get_contract();␊ - contract_state.pausable.assert_not_paused();␊ - }␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn pause(ref self: ContractState) {␊ - self.ownable.assert_only_owner();␊ - self.pausable.pause();␊ - }␊ - ␊ - #[external(v0)]␊ - fn unpause(ref self: ContractState) {␊ - self.ownable.assert_only_owner();␊ - self.pausable.unpause();␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## mintable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: ERC721Component, storage: erc721, event: ERC721Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl ERC721InternalImpl = ERC721Component::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc721: ERC721Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC721Event: ERC721Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.erc721.initializer("MyToken", "MTK", "");␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn safe_mint(␊ - ref self: ContractState,␊ - recipient: ContractAddress,␊ - token_id: u256,␊ - data: Span,␊ - ) {␊ - self.ownable.assert_only_owner();␊ - self.erc721.safe_mint(recipient, token_id, data);␊ - }␊ - ␊ - #[external(v0)]␊ - fn safeMint(␊ - ref self: ContractState,␊ - recipient: ContractAddress,␊ - tokenId: u256,␊ - data: Span,␊ - ) {␊ - self.safe_mint(recipient, tokenId, data);␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## enumerable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::erc721::ERC721Component;␊ - use openzeppelin::token::erc721::extensions::ERC721EnumerableComponent;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: ERC721Component, storage: erc721, event: ERC721Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: ERC721EnumerableComponent, storage: erc721_enumerable, event: ERC721EnumerableEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl;␊ - #[abi(embed_v0)]␊ - impl ERC721EnumerableImpl = ERC721EnumerableComponent::ERC721EnumerableImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl ERC721InternalImpl = ERC721Component::InternalImpl;␊ - impl ERC721EnumerableInternalImpl = ERC721EnumerableComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc721: ERC721Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - erc721_enumerable: ERC721EnumerableComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC721Event: ERC721Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - ERC721EnumerableEvent: ERC721EnumerableComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.erc721.initializer("MyToken", "MTK", "");␊ - self.erc721_enumerable.initializer();␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - impl ERC721HooksImpl of ERC721Component::ERC721HooksTrait {␊ - fn before_update(␊ - ref self: ERC721Component::ComponentState,␊ - to: ContractAddress,␊ - token_id: u256,␊ - auth: ContractAddress,␊ - ) {␊ - let mut contract_state = self.get_contract_mut();␊ - contract_state.erc721_enumerable.before_update(to, token_id);␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## pausable + enumerable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::security::pausable::PausableComponent;␊ - use openzeppelin::token::erc721::ERC721Component;␊ - use openzeppelin::token::erc721::extensions::ERC721EnumerableComponent;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: ERC721Component, storage: erc721, event: ERC721Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - component!(path: ERC721EnumerableComponent, storage: erc721_enumerable, event: ERC721EnumerableEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl;␊ - #[abi(embed_v0)]␊ - impl PausableImpl = PausableComponent::PausableImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - #[abi(embed_v0)]␊ - impl ERC721EnumerableImpl = ERC721EnumerableComponent::ERC721EnumerableImpl;␊ - ␊ - // Internal␊ - impl ERC721InternalImpl = ERC721Component::InternalImpl;␊ - impl PausableInternalImpl = PausableComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - impl ERC721EnumerableInternalImpl = ERC721EnumerableComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc721: ERC721Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - pausable: PausableComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - #[substorage(v0)]␊ - erc721_enumerable: ERC721EnumerableComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC721Event: ERC721Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - PausableEvent: PausableComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - #[flat]␊ - ERC721EnumerableEvent: ERC721EnumerableComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.erc721.initializer("MyToken", "MTK", "");␊ - self.ownable.initializer(owner);␊ - self.erc721_enumerable.initializer();␊ - }␊ - ␊ - impl ERC721HooksImpl of ERC721Component::ERC721HooksTrait {␊ - fn before_update(␊ - ref self: ERC721Component::ComponentState,␊ - to: ContractAddress,␊ - token_id: u256,␊ - auth: ContractAddress,␊ - ) {␊ - let mut contract_state = self.get_contract_mut();␊ - contract_state.pausable.assert_not_paused();␊ - contract_state.erc721_enumerable.before_update(to, token_id);␊ - }␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn pause(ref self: ContractState) {␊ - self.ownable.assert_only_owner();␊ - self.pausable.pause();␊ - }␊ - ␊ - #[external(v0)]␊ - fn unpause(ref self: ContractState) {␊ - self.ownable.assert_only_owner();␊ - self.pausable.unpause();␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## mintable + roles - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - const MINTER_ROLE: felt252 = selector!("MINTER_ROLE");␊ - const UPGRADER_ROLE: felt252 = selector!("UPGRADER_ROLE");␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::accesscontrol::{AccessControlComponent, DEFAULT_ADMIN_ROLE};␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - use super::{MINTER_ROLE, UPGRADER_ROLE};␊ - ␊ - component!(path: ERC721Component, storage: erc721, event: ERC721Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl;␊ - #[abi(embed_v0)]␊ - impl AccessControlImpl = AccessControlComponent::AccessControlImpl;␊ - #[abi(embed_v0)]␊ - impl AccessControlCamelImpl = AccessControlComponent::AccessControlCamelImpl;␊ - ␊ - // Internal␊ - impl ERC721InternalImpl = ERC721Component::InternalImpl;␊ - impl AccessControlInternalImpl = AccessControlComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc721: ERC721Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - accesscontrol: AccessControlComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC721Event: ERC721Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - AccessControlEvent: AccessControlComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - default_admin: ContractAddress,␊ - minter: ContractAddress,␊ - upgrader: ContractAddress,␊ - ) {␊ - self.erc721.initializer("MyToken", "MTK", "");␊ - self.accesscontrol.initializer();␊ - ␊ - self.accesscontrol._grant_role(DEFAULT_ADMIN_ROLE, default_admin);␊ - self.accesscontrol._grant_role(MINTER_ROLE, minter);␊ - self.accesscontrol._grant_role(UPGRADER_ROLE, upgrader);␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn safe_mint(␊ - ref self: ContractState,␊ - recipient: ContractAddress,␊ - token_id: u256,␊ - data: Span,␊ - ) {␊ - self.accesscontrol.assert_only_role(MINTER_ROLE);␊ - self.erc721.safe_mint(recipient, token_id, data);␊ - }␊ - ␊ - #[external(v0)]␊ - fn safeMint(␊ - ref self: ContractState,␊ - recipient: ContractAddress,␊ - tokenId: u256,␊ - data: Span,␊ - ) {␊ - self.safe_mint(recipient, tokenId, data);␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.accesscontrol.assert_only_role(UPGRADER_ROLE);␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## royalty info disabled - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: ERC721Component, storage: erc721, event: ERC721Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl ERC721InternalImpl = ERC721Component::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc721: ERC721Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC721Event: ERC721Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.erc721.initializer("MyToken", "MTK", "");␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## royalty info enabled default + ownable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::common::erc2981::{DefaultConfig, ERC2981Component};␊ - use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: ERC721Component, storage: erc721, event: ERC721Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - component!(path: ERC2981Component, storage: erc2981, event: ERC2981Event);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981Impl = ERC2981Component::ERC2981Impl;␊ - #[abi(embed_v0)]␊ - impl ERC2981InfoImpl = ERC2981Component::ERC2981InfoImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981AdminOwnableImpl = ERC2981Component::ERC2981AdminOwnableImpl;␊ - ␊ - // Internal␊ - impl ERC721InternalImpl = ERC721Component::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - impl ERC2981InternalImpl = ERC2981Component::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc721: ERC721Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - #[substorage(v0)]␊ - erc2981: ERC2981Component::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC721Event: ERC721Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - #[flat]␊ - ERC2981Event: ERC2981Component::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - owner: ContractAddress,␊ - default_royalty_receiver: ContractAddress,␊ - ) {␊ - self.erc721.initializer("MyToken", "MTK", "");␊ - self.ownable.initializer(owner);␊ - self.erc2981.initializer(default_royalty_receiver, 500);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## royalty info enabled default + roles - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - const UPGRADER_ROLE: felt252 = selector!("UPGRADER_ROLE");␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::accesscontrol::{AccessControlComponent, DEFAULT_ADMIN_ROLE};␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::common::erc2981::{DefaultConfig, ERC2981Component};␊ - use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - use super::UPGRADER_ROLE;␊ - ␊ - component!(path: ERC721Component, storage: erc721, event: ERC721Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - component!(path: ERC2981Component, storage: erc2981, event: ERC2981Event);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl;␊ - #[abi(embed_v0)]␊ - impl AccessControlImpl = AccessControlComponent::AccessControlImpl;␊ - #[abi(embed_v0)]␊ - impl AccessControlCamelImpl = AccessControlComponent::AccessControlCamelImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981Impl = ERC2981Component::ERC2981Impl;␊ - #[abi(embed_v0)]␊ - impl ERC2981InfoImpl = ERC2981Component::ERC2981InfoImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981AdminAccessControlImpl = ERC2981Component::ERC2981AdminAccessControlImpl;␊ - ␊ - // Internal␊ - impl ERC721InternalImpl = ERC721Component::InternalImpl;␊ - impl AccessControlInternalImpl = AccessControlComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - impl ERC2981InternalImpl = ERC2981Component::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc721: ERC721Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - accesscontrol: AccessControlComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - #[substorage(v0)]␊ - erc2981: ERC2981Component::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC721Event: ERC721Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - AccessControlEvent: AccessControlComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - #[flat]␊ - ERC2981Event: ERC2981Component::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - default_admin: ContractAddress,␊ - upgrader: ContractAddress,␊ - default_royalty_receiver: ContractAddress,␊ - royalty_admin: ContractAddress,␊ - ) {␊ - self.erc721.initializer("MyToken", "MTK", "");␊ - self.accesscontrol.initializer();␊ - self.erc2981.initializer(default_royalty_receiver, 500);␊ - ␊ - self.accesscontrol._grant_role(DEFAULT_ADMIN_ROLE, default_admin);␊ - self.accesscontrol._grant_role(UPGRADER_ROLE, upgrader);␊ - self.accesscontrol._grant_role(ERC2981Component::ROYALTY_ADMIN_ROLE, royalty_admin);␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.accesscontrol.assert_only_role(UPGRADER_ROLE);␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## royalty info enabled custom + ownable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::common::erc2981::ERC2981Component;␊ - use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: ERC721Component, storage: erc721, event: ERC721Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - component!(path: ERC2981Component, storage: erc2981, event: ERC2981Event);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981Impl = ERC2981Component::ERC2981Impl;␊ - #[abi(embed_v0)]␊ - impl ERC2981InfoImpl = ERC2981Component::ERC2981InfoImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981AdminOwnableImpl = ERC2981Component::ERC2981AdminOwnableImpl;␊ - ␊ - // Internal␊ - impl ERC721InternalImpl = ERC721Component::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - impl ERC2981InternalImpl = ERC2981Component::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc721: ERC721Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - #[substorage(v0)]␊ - erc2981: ERC2981Component::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC721Event: ERC721Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - #[flat]␊ - ERC2981Event: ERC2981Component::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - owner: ContractAddress,␊ - default_royalty_receiver: ContractAddress,␊ - ) {␊ - self.erc721.initializer("MyToken", "MTK", "");␊ - self.ownable.initializer(owner);␊ - self.erc2981.initializer(default_royalty_receiver, 15125);␊ - }␊ - ␊ - impl ERC2981ImmutableConfig of ERC2981Component::ImmutableConfig {␊ - const FEE_DENOMINATOR: u128 = 100000;␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## royalty info enabled custom + roles - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - const UPGRADER_ROLE: felt252 = selector!("UPGRADER_ROLE");␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::accesscontrol::{AccessControlComponent, DEFAULT_ADMIN_ROLE};␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::common::erc2981::ERC2981Component;␊ - use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl};␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use starknet::{ClassHash, ContractAddress};␊ - use super::UPGRADER_ROLE;␊ - ␊ - component!(path: ERC721Component, storage: erc721, event: ERC721Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - component!(path: ERC2981Component, storage: erc2981, event: ERC2981Event);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl;␊ - #[abi(embed_v0)]␊ - impl AccessControlImpl = AccessControlComponent::AccessControlImpl;␊ - #[abi(embed_v0)]␊ - impl AccessControlCamelImpl = AccessControlComponent::AccessControlCamelImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981Impl = ERC2981Component::ERC2981Impl;␊ - #[abi(embed_v0)]␊ - impl ERC2981InfoImpl = ERC2981Component::ERC2981InfoImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981AdminAccessControlImpl = ERC2981Component::ERC2981AdminAccessControlImpl;␊ - ␊ - // Internal␊ - impl ERC721InternalImpl = ERC721Component::InternalImpl;␊ - impl AccessControlInternalImpl = AccessControlComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - impl ERC2981InternalImpl = ERC2981Component::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc721: ERC721Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - accesscontrol: AccessControlComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - #[substorage(v0)]␊ - erc2981: ERC2981Component::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC721Event: ERC721Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - AccessControlEvent: AccessControlComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - #[flat]␊ - ERC2981Event: ERC2981Component::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - default_admin: ContractAddress,␊ - upgrader: ContractAddress,␊ - default_royalty_receiver: ContractAddress,␊ - royalty_admin: ContractAddress,␊ - ) {␊ - self.erc721.initializer("MyToken", "MTK", "");␊ - self.accesscontrol.initializer();␊ - self.erc2981.initializer(default_royalty_receiver, 15125);␊ - ␊ - self.accesscontrol._grant_role(DEFAULT_ADMIN_ROLE, default_admin);␊ - self.accesscontrol._grant_role(UPGRADER_ROLE, upgrader);␊ - self.accesscontrol._grant_role(ERC2981Component::ROYALTY_ADMIN_ROLE, royalty_admin);␊ - }␊ - ␊ - impl ERC2981ImmutableConfig of ERC2981Component::ImmutableConfig {␊ - const FEE_DENOMINATOR: u128 = 100000;␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.accesscontrol.assert_only_role(UPGRADER_ROLE);␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## full non-upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use core::num::traits::Zero;␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::governance::votes::VotesComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::security::pausable::PausableComponent;␊ - use openzeppelin::token::common::erc2981::{DefaultConfig, ERC2981Component};␊ - use openzeppelin::token::erc721::ERC721Component;␊ - use openzeppelin::token::erc721::extensions::ERC721EnumerableComponent;␊ - use openzeppelin::utils::cryptography::nonces::NoncesComponent;␊ - use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ - use starknet::{ContractAddress, get_caller_address};␊ - ␊ - component!(path: ERC721Component, storage: erc721, event: ERC721Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - component!(path: ERC721EnumerableComponent, storage: erc721_enumerable, event: ERC721EnumerableEvent);␊ - component!(path: ERC2981Component, storage: erc2981, event: ERC2981Event);␊ - component!(path: NoncesComponent, storage: nonces, event: NoncesEvent);␊ - component!(path: VotesComponent, storage: votes, event: VotesEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl;␊ - #[abi(embed_v0)]␊ - impl PausableImpl = PausableComponent::PausableImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - #[abi(embed_v0)]␊ - impl ERC721EnumerableImpl = ERC721EnumerableComponent::ERC721EnumerableImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981Impl = ERC2981Component::ERC2981Impl;␊ - #[abi(embed_v0)]␊ - impl ERC2981InfoImpl = ERC2981Component::ERC2981InfoImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981AdminOwnableImpl = ERC2981Component::ERC2981AdminOwnableImpl;␊ - #[abi(embed_v0)]␊ - impl NoncesImpl = NoncesComponent::NoncesImpl;␊ - #[abi(embed_v0)]␊ - impl VotesImpl = VotesComponent::VotesImpl;␊ - ␊ - // Internal␊ - impl ERC721InternalImpl = ERC721Component::InternalImpl;␊ - impl PausableInternalImpl = PausableComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - impl ERC721EnumerableInternalImpl = ERC721EnumerableComponent::InternalImpl;␊ - impl ERC2981InternalImpl = ERC2981Component::InternalImpl;␊ - impl VotesInternalImpl = VotesComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc721: ERC721Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - pausable: PausableComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - #[substorage(v0)]␊ - erc721_enumerable: ERC721EnumerableComponent::Storage,␊ - #[substorage(v0)]␊ - erc2981: ERC2981Component::Storage,␊ - #[substorage(v0)]␊ - nonces: NoncesComponent::Storage,␊ - #[substorage(v0)]␊ - votes: VotesComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC721Event: ERC721Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - PausableEvent: PausableComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - #[flat]␊ - ERC721EnumerableEvent: ERC721EnumerableComponent::Event,␊ - #[flat]␊ - ERC2981Event: ERC2981Component::Event,␊ - #[flat]␊ - NoncesEvent: NoncesComponent::Event,␊ - #[flat]␊ - VotesEvent: VotesComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - owner: ContractAddress,␊ - default_royalty_receiver: ContractAddress,␊ - ) {␊ - self.erc721.initializer("MyToken", "MTK", "");␊ - self.ownable.initializer(owner);␊ - self.erc721_enumerable.initializer();␊ - self.erc2981.initializer(default_royalty_receiver, 500);␊ - }␊ - ␊ - impl ERC721HooksImpl of ERC721Component::ERC721HooksTrait {␊ - fn before_update(␊ - ref self: ERC721Component::ComponentState,␊ - to: ContractAddress,␊ - token_id: u256,␊ - auth: ContractAddress,␊ - ) {␊ - let mut contract_state = self.get_contract_mut();␊ - contract_state.pausable.assert_not_paused();␊ - contract_state.erc721_enumerable.before_update(to, token_id);␊ - let previous_owner = self._owner_of(token_id);␊ - contract_state.votes.transfer_voting_units(previous_owner, to, 1);␊ - }␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn pause(ref self: ContractState) {␊ - self.ownable.assert_only_owner();␊ - self.pausable.pause();␊ - }␊ - ␊ - #[external(v0)]␊ - fn unpause(ref self: ContractState) {␊ - self.ownable.assert_only_owner();␊ - self.pausable.unpause();␊ - }␊ - ␊ - #[external(v0)]␊ - fn burn(ref self: ContractState, token_id: u256) {␊ - self.erc721.update(Zero::zero(), token_id, get_caller_address());␊ - }␊ - ␊ - #[external(v0)]␊ - fn safe_mint(␊ - ref self: ContractState,␊ - recipient: ContractAddress,␊ - token_id: u256,␊ - data: Span,␊ - ) {␊ - self.ownable.assert_only_owner();␊ - self.erc721.safe_mint(recipient, token_id, data);␊ - }␊ - ␊ - #[external(v0)]␊ - fn safeMint(␊ - ref self: ContractState,␊ - recipient: ContractAddress,␊ - tokenId: u256,␊ - data: Span,␊ - ) {␊ - self.safe_mint(recipient, tokenId, data);␊ - }␊ - }␊ - ␊ - //␊ - // SNIP12 Metadata␊ - //␊ - ␊ - impl SNIP12MetadataImpl of SNIP12Metadata {␊ - fn name() -> felt252 {␊ - 'MY_DAPP_NAME'␊ - }␊ - ␊ - fn version() -> felt252 {␊ - 'MY_DAPP_VERSION'␊ - }␊ - }␊ - }␊ - ` - -## erc721 votes - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::governance::votes::VotesComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::erc721::ERC721Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use openzeppelin::utils::cryptography::nonces::NoncesComponent;␊ - use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: ERC721Component, storage: erc721, event: ERC721Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - component!(path: NoncesComponent, storage: nonces, event: NoncesEvent);␊ - component!(path: VotesComponent, storage: votes, event: VotesEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - #[abi(embed_v0)]␊ - impl NoncesImpl = NoncesComponent::NoncesImpl;␊ - #[abi(embed_v0)]␊ - impl VotesImpl = VotesComponent::VotesImpl;␊ - ␊ - // Internal␊ - impl ERC721InternalImpl = ERC721Component::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - impl VotesInternalImpl = VotesComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc721: ERC721Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - #[substorage(v0)]␊ - nonces: NoncesComponent::Storage,␊ - #[substorage(v0)]␊ - votes: VotesComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC721Event: ERC721Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - #[flat]␊ - NoncesEvent: NoncesComponent::Event,␊ - #[flat]␊ - VotesEvent: VotesComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.erc721.initializer("MyToken", "MTK", "");␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - impl ERC721HooksImpl of ERC721Component::ERC721HooksTrait {␊ - fn before_update(␊ - ref self: ERC721Component::ComponentState,␊ - to: ContractAddress,␊ - token_id: u256,␊ - auth: ContractAddress,␊ - ) {␊ - let mut contract_state = self.get_contract_mut();␊ - let previous_owner = self._owner_of(token_id);␊ - contract_state.votes.transfer_voting_units(previous_owner, to, 1);␊ - }␊ - }␊ - ␊ - //␊ - // SNIP12 Metadata␊ - //␊ - ␊ - impl SNIP12MetadataImpl of SNIP12Metadata {␊ - fn name() -> felt252 {␊ - 'MY_DAPP_NAME'␊ - }␊ - ␊ - fn version() -> felt252 {␊ - 'v1'␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## erc721 votes, version - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::governance::votes::VotesComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::erc721::ERC721Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use openzeppelin::utils::cryptography::nonces::NoncesComponent;␊ - use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - component!(path: ERC721Component, storage: erc721, event: ERC721Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - component!(path: NoncesComponent, storage: nonces, event: NoncesEvent);␊ - component!(path: VotesComponent, storage: votes, event: VotesEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - #[abi(embed_v0)]␊ - impl NoncesImpl = NoncesComponent::NoncesImpl;␊ - #[abi(embed_v0)]␊ - impl VotesImpl = VotesComponent::VotesImpl;␊ - ␊ - // Internal␊ - impl ERC721InternalImpl = ERC721Component::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - impl VotesInternalImpl = VotesComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc721: ERC721Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - #[substorage(v0)]␊ - nonces: NoncesComponent::Storage,␊ - #[substorage(v0)]␊ - votes: VotesComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC721Event: ERC721Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - #[flat]␊ - NoncesEvent: NoncesComponent::Event,␊ - #[flat]␊ - VotesEvent: VotesComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.erc721.initializer("MyToken", "MTK", "");␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - impl ERC721HooksImpl of ERC721Component::ERC721HooksTrait {␊ - fn before_update(␊ - ref self: ERC721Component::ComponentState,␊ - to: ContractAddress,␊ - token_id: u256,␊ - auth: ContractAddress,␊ - ) {␊ - let mut contract_state = self.get_contract_mut();␊ - let previous_owner = self._owner_of(token_id);␊ - contract_state.votes.transfer_voting_units(previous_owner, to, 1);␊ - }␊ - }␊ - ␊ - //␊ - // SNIP12 Metadata␊ - //␊ - ␊ - impl SNIP12MetadataImpl of SNIP12Metadata {␊ - fn name() -> felt252 {␊ - 'MY_DAPP_NAME'␊ - }␊ - ␊ - fn version() -> felt252 {␊ - 'MY_DAPP_VERSION'␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## erc721 votes, non-upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use openzeppelin::governance::votes::VotesComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::token::erc721::ERC721Component;␊ - use openzeppelin::utils::cryptography::nonces::NoncesComponent;␊ - use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ - use starknet::ContractAddress;␊ - ␊ - component!(path: ERC721Component, storage: erc721, event: ERC721Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: NoncesComponent, storage: nonces, event: NoncesEvent);␊ - component!(path: VotesComponent, storage: votes, event: VotesEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl;␊ - #[abi(embed_v0)]␊ - impl NoncesImpl = NoncesComponent::NoncesImpl;␊ - #[abi(embed_v0)]␊ - impl VotesImpl = VotesComponent::VotesImpl;␊ - ␊ - // Internal␊ - impl ERC721InternalImpl = ERC721Component::InternalImpl;␊ - impl VotesInternalImpl = VotesComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc721: ERC721Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - nonces: NoncesComponent::Storage,␊ - #[substorage(v0)]␊ - votes: VotesComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC721Event: ERC721Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - NoncesEvent: NoncesComponent::Event,␊ - #[flat]␊ - VotesEvent: VotesComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState) {␊ - self.erc721.initializer("MyToken", "MTK", "");␊ - }␊ - ␊ - impl ERC721HooksImpl of ERC721Component::ERC721HooksTrait {␊ - fn before_update(␊ - ref self: ERC721Component::ComponentState,␊ - to: ContractAddress,␊ - token_id: u256,␊ - auth: ContractAddress,␊ - ) {␊ - let mut contract_state = self.get_contract_mut();␊ - let previous_owner = self._owner_of(token_id);␊ - contract_state.votes.transfer_voting_units(previous_owner, to, 1);␊ - }␊ - }␊ - ␊ - //␊ - // SNIP12 Metadata␊ - //␊ - ␊ - impl SNIP12MetadataImpl of SNIP12Metadata {␊ - fn name() -> felt252 {␊ - 'MY_DAPP_NAME'␊ - }␊ - ␊ - fn version() -> felt252 {␊ - 'v1'␊ - }␊ - }␊ - }␊ - ` - -## full upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyToken {␊ - use core::num::traits::Zero;␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::governance::votes::VotesComponent;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::security::pausable::PausableComponent;␊ - use openzeppelin::token::common::erc2981::{DefaultConfig, ERC2981Component};␊ - use openzeppelin::token::erc721::ERC721Component;␊ - use openzeppelin::token::erc721::extensions::ERC721EnumerableComponent;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use openzeppelin::utils::cryptography::nonces::NoncesComponent;␊ - use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ - use starknet::{ClassHash, ContractAddress, get_caller_address};␊ - ␊ - component!(path: ERC721Component, storage: erc721, event: ERC721Event);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - component!(path: ERC721EnumerableComponent, storage: erc721_enumerable, event: ERC721EnumerableEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - component!(path: ERC2981Component, storage: erc2981, event: ERC2981Event);␊ - component!(path: NoncesComponent, storage: nonces, event: NoncesEvent);␊ - component!(path: VotesComponent, storage: votes, event: VotesEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl;␊ - #[abi(embed_v0)]␊ - impl PausableImpl = PausableComponent::PausableImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - #[abi(embed_v0)]␊ - impl ERC721EnumerableImpl = ERC721EnumerableComponent::ERC721EnumerableImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981Impl = ERC2981Component::ERC2981Impl;␊ - #[abi(embed_v0)]␊ - impl ERC2981InfoImpl = ERC2981Component::ERC2981InfoImpl;␊ - #[abi(embed_v0)]␊ - impl ERC2981AdminOwnableImpl = ERC2981Component::ERC2981AdminOwnableImpl;␊ - #[abi(embed_v0)]␊ - impl NoncesImpl = NoncesComponent::NoncesImpl;␊ - #[abi(embed_v0)]␊ - impl VotesImpl = VotesComponent::VotesImpl;␊ - ␊ - // Internal␊ - impl ERC721InternalImpl = ERC721Component::InternalImpl;␊ - impl PausableInternalImpl = PausableComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - impl ERC721EnumerableInternalImpl = ERC721EnumerableComponent::InternalImpl;␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - impl ERC2981InternalImpl = ERC2981Component::InternalImpl;␊ - impl VotesInternalImpl = VotesComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - erc721: ERC721Component::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - pausable: PausableComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - #[substorage(v0)]␊ - erc721_enumerable: ERC721EnumerableComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - #[substorage(v0)]␊ - erc2981: ERC2981Component::Storage,␊ - #[substorage(v0)]␊ - nonces: NoncesComponent::Storage,␊ - #[substorage(v0)]␊ - votes: VotesComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - ERC721Event: ERC721Component::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - PausableEvent: PausableComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - #[flat]␊ - ERC721EnumerableEvent: ERC721EnumerableComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - #[flat]␊ - ERC2981Event: ERC2981Component::Event,␊ - #[flat]␊ - NoncesEvent: NoncesComponent::Event,␊ - #[flat]␊ - VotesEvent: VotesComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - owner: ContractAddress,␊ - default_royalty_receiver: ContractAddress,␊ - ) {␊ - self.erc721.initializer("MyToken", "MTK", "");␊ - self.ownable.initializer(owner);␊ - self.erc721_enumerable.initializer();␊ - self.erc2981.initializer(default_royalty_receiver, 500);␊ - }␊ - ␊ - impl ERC721HooksImpl of ERC721Component::ERC721HooksTrait {␊ - fn before_update(␊ - ref self: ERC721Component::ComponentState,␊ - to: ContractAddress,␊ - token_id: u256,␊ - auth: ContractAddress,␊ - ) {␊ - let mut contract_state = self.get_contract_mut();␊ - contract_state.pausable.assert_not_paused();␊ - contract_state.erc721_enumerable.before_update(to, token_id);␊ - let previous_owner = self._owner_of(token_id);␊ - contract_state.votes.transfer_voting_units(previous_owner, to, 1);␊ - }␊ - }␊ - ␊ - #[generate_trait]␊ - #[abi(per_item)]␊ - impl ExternalImpl of ExternalTrait {␊ - #[external(v0)]␊ - fn pause(ref self: ContractState) {␊ - self.ownable.assert_only_owner();␊ - self.pausable.pause();␊ - }␊ - ␊ - #[external(v0)]␊ - fn unpause(ref self: ContractState) {␊ - self.ownable.assert_only_owner();␊ - self.pausable.unpause();␊ - }␊ - ␊ - #[external(v0)]␊ - fn burn(ref self: ContractState, token_id: u256) {␊ - self.erc721.update(Zero::zero(), token_id, get_caller_address());␊ - }␊ - ␊ - #[external(v0)]␊ - fn safe_mint(␊ - ref self: ContractState,␊ - recipient: ContractAddress,␊ - token_id: u256,␊ - data: Span,␊ - ) {␊ - self.ownable.assert_only_owner();␊ - self.erc721.safe_mint(recipient, token_id, data);␊ - }␊ - ␊ - #[external(v0)]␊ - fn safeMint(␊ - ref self: ContractState,␊ - recipient: ContractAddress,␊ - tokenId: u256,␊ - data: Span,␊ - ) {␊ - self.safe_mint(recipient, tokenId, data);␊ - }␊ - }␊ - ␊ - //␊ - // SNIP12 Metadata␊ - //␊ - ␊ - impl SNIP12MetadataImpl of SNIP12Metadata {␊ - fn name() -> felt252 {␊ - 'MY_DAPP_NAME'␊ - }␊ - ␊ - fn version() -> felt252 {␊ - 'MY_DAPP_VERSION'␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.ownable.assert_only_owner();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` diff --git a/packages/core/stylus/src/erc721.test.ts.snap b/packages/core/stylus/src/erc721.test.ts.snap deleted file mode 100644 index cb80f55cb5984868b69be2fd2543c7c18ee4fcf9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3527 zcmV;&4LI^aRzV$e(W$f}KlPC`$A;dEX@rITc-u55x#vefZ0e%W9-`ZuD-S=*{`}E6< z+f}EkPL->^@0`=eU$;*!X1sL&{13uSZV~TPcTEFPMpr!h%+Xs!KedSIQr&jX8Fzp8 zb*rUw{mJ_;zVqJq-V>j1efPa<-+uP~+8R1O-1%zdk!cX>l9k;Sq1h8a|vQLp>IN|7@L$k%(aQZO-3LE;uxQ8ZeaYjd9?l6=0;qtj)E^9GWODKc5HsR+p(>8cb0r{MpW$6 znyvG5j54)d&K&)WU=%b^N92M~9u;hgi{(3NSyJ~ClEmO*IigS`#TT=-hMKQAaj0(j z*EgQ&r)G_GPDx9K`MnCqO}@3y#06D=l$ zN8jhkPu^Dx7fZq)chGT{JD$POaqwNZ9Kv$mX;`!tk5hcYnawsH3aR%Y!(UJGgrw@f zi@NL2%k%J}MI7^j)OH+ZiwTU@b}(TveQ} z@8nnF&-HNezgv2@6mCt#-39;e&ibaM+XLlGBHxPC&*+P17@uM=M11FZ1n4OeB)l~N@H5^<@ zVpa*&ITVZQC!P!SGc=I2XuDM?v{DDPs$zOK$x~+!G07c7rN=SCg}Rt8aZsmr{SjeA zTrFG;Qa!)L7;l6-NwlFP6qdZxV^d3R6yln-QSzWnJ-vyswQ02c^EE`tE6ot+qjs*l z=NQFjWl~9*5$mo?9Ii2HU26V_YYE-Nr4!Fy^nXomFH!4V8ls(_>MlW^V=7SEeYj8_bAjJ(aQpDQt3s1eU@>73LAI>Go2aae7+TU~Xa)|M4$4FK*40N2(%R}FAK zv?PH0{KL`!+?nH7ml&R7@=J^(^N2O>MB{2Dx(tXfyMXkQB{YEG;TLAsnj| zHy*@YHi#T)GL)W~h3~2 zq^(&wE#qSZs_H}Vl8O+E#Fpq=;$p&}J~8|dH2Qw}=h3P4Flq|;XsYyxe6(XyuI8gx zekk$L?_U8vT4jIA98pamh85#(z_q5qwSXgyiz5NWnIGSYtG9_JP);8Ak@b`+WSF+; z&(P2eM_?(8j%}UZZ4--cZf)Mr=Ql&(zi`63!;CwfbnS><3=Hpu%)KdSZg)(I%h$oK zN(Bhm!-(wRh1jEsqvj7+Q@^IX3jAR-msF~jcxZu zBHhjS284!?80-ExJ4mWF&+ zkv7jd&a@1)z3jZZ7n4Q<5p>|)GvVF+g}W*$j!4)M1kOU>Y-LR>ETJB%jusyAhEiOYL7aWHhHKWsv+N{lmQM`>$Y?~s8Sj4RB@J|T}@7MV8y z;QpgiEZQL4j~}j3wh7di4#Q!oCps+g9_(}d|Kp2-<| ze1xc`VX_V&HSNech(ds?Im965#l-zQgTzV-eMtrL`dmj_>+3*x#zA;~(u45i1aW^)!8p@DM} zSeKnwpoIQs_F;NGb+oYbaJIpIIeM5ORqQubutz8$8k|-7-3yBrwLX<7!*l}!)6b%| zCKRSv9BJ5xfb3d3I(X7}bn-;%ois<4CEBwM4}1MnCG|Eum$OchtMTfOB<_6$GKltM z$LUqSU}Sh+=q`8`!LwLqdI_FIppnHgz_VB_>Ik02Me{6fY;A0AsZ+BAXH>`I!R!e~ zOPHZ0y<4RUbq5@HvK};>+D>!-U~hN7adL2kk+-q=Il6~7*2Sl)bZe@9%^St!D$lL? zPl;On4cwYDc55y;aYNw61TQ9dF&B(xf)^9$CwMV|ih>styqJ^pVn$TAsI|)aF@e-q zz=z7)o@F7*=t@FPmezlKSEBVRAD6~sYA}ajOuY`qeo`P8 zB74EOV5nb;KNIxDj^ouJ6AN>m#k)qhX}K61&ZW)SnWNk1ml#t<4KW$}{@>wbxYV>a zHZeZl-#y&e+#_5Ui(YMPNF7tiPnxV-7I8Fv?%c)jGLmuFDU{+;>oFlMSh2CNpkSda zd80{)@;9Pbl3%Q>#uIoe$}j_~ia};ve*fYYgGVWBB=rDBC&Un9{pTu_DnE)L2AH9} zXt7^+GZyPpYMy0T>G@t1JJy1{FsEO0Sh184gJ!p!0b~T6BD3BqZv{&T>8YwG z;Gkkb^{CuMfZ3GiY)9i6&u;%FC)oAgZcsL9=$+=A##9c{onlj70$)4y52GpV0Go_Y?=H#p1B zowCE>{u!=YVIjr%4RKg)IhoiyYs{)G50&V9zH+7yHk*(mJyyjya-;`FR}@)YlXtt@ zkZhTaHY534`81?@ht!tQ%KbPVQ11WDy(ijEOs^Z1^>c3k?4#OMF8R8l@aKeT-IJUO*X&JQ&P!nyEd5Qr9#nsJbt zd7u*`(gt7yzy{`?4XFHhF`Bjgj2(se^^-LTzoJh{gI^(Ahq`hVvvq(g4)TOlFi%J+ zQ>7}!0ds^DB#?pxQjkCjk_o0DDREj|1ooqaO>8ootii=nz;p*`QsV3BXHZsEFO@|! z77W=|(xoBWN{Ma3kZmRWK(>|M{ex^PkZlFBtw6Sw^gKbJ+zbQd{txITYKLSG0RZ{v B-K+or diff --git a/packages/core/stylus/src/erc721.ts b/packages/core/stylus/src/erc721.ts deleted file mode 100644 index 6b23e1c28..000000000 --- a/packages/core/stylus/src/erc721.ts +++ /dev/null @@ -1,274 +0,0 @@ -import { BaseImplementedTrait, Contract, ContractBuilder } from './contract'; -import { Access, requireAccessControl, setAccessControl } from './set-access-control'; -import { addPausable } from './add-pausable'; -import { defineFunctions } from './utils/define-functions'; -import { CommonContractOptions, withCommonContractDefaults, getSelfArg } from './common-options'; -import { setUpgradeable } from './set-upgradeable'; -import { setInfo } from './set-info'; -import { defineComponents } from './utils/define-components'; -import { contractDefaults as commonDefaults } from './common-options'; -import { printContract } from './print'; -import { addSRC5Component, addVotesComponent } from './common-components'; -import { externalTrait } from './external-trait'; -import { toByteArray, toFelt252 } from './utils/convert-strings'; -import { OptionsError } from './error'; -import { RoyaltyInfoOptions, setRoyaltyInfo, defaults as royaltyInfoDefaults } from './set-royalty-info'; - -export const defaults: Required = { - name: 'MyToken', - symbol: 'MTK', - baseUri: '', - burnable: false, - pausable: false, - mintable: false, - enumerable: false, - votes: false, - royaltyInfo: royaltyInfoDefaults, - appName: '', // Defaults to empty string, but user must provide a non-empty value if votes are enabled - appVersion: 'v1', - access: commonDefaults.access, - upgradeable: commonDefaults.upgradeable, - info: commonDefaults.info -} as const; - -export function printERC721(opts: ERC721Options = defaults): string { - return printContract(buildERC721(opts)); -} - -export interface ERC721Options extends CommonContractOptions { - name: string; - symbol: string; - baseUri?: string; - burnable?: boolean; - pausable?: boolean; - mintable?: boolean; - enumerable?: boolean; - votes?: boolean; - royaltyInfo?: RoyaltyInfoOptions; - appName?: string; - appVersion?: string; -} - -function withDefaults(opts: ERC721Options): Required { - return { - ...opts, - ...withCommonContractDefaults(opts), - baseUri: opts.baseUri ?? defaults.baseUri, - burnable: opts.burnable ?? defaults.burnable, - pausable: opts.pausable ?? defaults.pausable, - mintable: opts.mintable ?? defaults.mintable, - enumerable: opts.enumerable ?? defaults.enumerable, - royaltyInfo: opts.royaltyInfo ?? defaults.royaltyInfo, - votes: opts.votes ?? defaults.votes, - appName: opts.appName ?? defaults.appName, - appVersion: opts.appVersion ?? defaults.appVersion - }; -} - -export function isAccessControlRequired(opts: Partial): boolean { - return opts.mintable === true || opts.pausable === true || opts.upgradeable === true || opts.royaltyInfo?.enabled === true; -} - -export function buildERC721(opts: ERC721Options): Contract { - const c = new ContractBuilder(opts.name); - - const allOpts = withDefaults(opts); - - addBase(c, toByteArray(allOpts.name), toByteArray(allOpts.symbol), toByteArray(allOpts.baseUri)); - addERC721Mixin(c); - - if (allOpts.pausable) { - addPausable(c, allOpts.access); - } - - if (allOpts.burnable) { - addBurnable(c); - } - - if (allOpts.mintable) { - addMintable(c, allOpts.access); - } - - if (allOpts.enumerable) { - addEnumerable(c); - } - - setAccessControl(c, allOpts.access); - setUpgradeable(c, allOpts.upgradeable, allOpts.access); - setInfo(c, allOpts.info); - setRoyaltyInfo(c, allOpts.royaltyInfo, allOpts.access); - - addHooks(c, allOpts); - - return c; -} - -function addHooks(c: ContractBuilder, opts: Required) { - const usesCustomHooks = opts.pausable || opts.enumerable || opts.votes; - if (usesCustomHooks) { - const ERC721HooksTrait: BaseImplementedTrait = { - name: `ERC721HooksImpl`, - of: 'ERC721Component::ERC721HooksTrait', - tags: [], - priority: 0, - }; - c.addImplementedTrait(ERC721HooksTrait); - c.addUseClause('starknet', 'ContractAddress'); - - const requiresMutState = opts.enumerable || opts.votes; - const initStateLine = requiresMutState - ? 'let mut contract_state = self.get_contract_mut()' - : 'let contract_state = self.get_contract()'; - const beforeUpdateCode = [initStateLine]; - if (opts.pausable) { - beforeUpdateCode.push('contract_state.pausable.assert_not_paused()'); - } - if (opts.enumerable) { - beforeUpdateCode.push('contract_state.erc721_enumerable.before_update(to, token_id)'); - } - if (opts.votes) { - if (!opts.appName) { - throw new OptionsError({ - appName: 'Application Name is required when Votes are enabled', - }); - } - - if (!opts.appVersion) { - throw new OptionsError({ - appVersion: 'Application Version is required when Votes are enabled', - }); - } - - addVotesComponent( - c, - toFelt252(opts.appName, 'appName'), - toFelt252(opts.appVersion, 'appVersion'), - 'SNIP12 Metadata', - ); - beforeUpdateCode.push('let previous_owner = self._owner_of(token_id);'); - beforeUpdateCode.push('contract_state.votes.transfer_voting_units(previous_owner, to, 1);'); - } - c.addFunction(ERC721HooksTrait, { - name: 'before_update', - args: [ - { name: 'ref self', type: `ERC721Component::ComponentState` }, - { name: 'to', type: 'ContractAddress' }, - { name: 'token_id', type: 'u256' }, - { name: 'auth', type: 'ContractAddress' }, - ], - code: beforeUpdateCode, - }); - } else { - c.addUseClause('openzeppelin::token::erc721', 'ERC721HooksEmptyImpl'); - } -} - -function addERC721Mixin(c: ContractBuilder) { - c.addImplToComponent(components.ERC721Component, { - name: 'ERC721MixinImpl', - value: 'ERC721Component::ERC721MixinImpl', - }); - c.addInterfaceFlag('ISRC5'); - addSRC5Component(c); -} - -function addBase(c: ContractBuilder, name: string, symbol: string, baseUri: string) { - c.addComponent( - components.ERC721Component, - [ - name, symbol, baseUri, - ], - true, - ); -} - -function addEnumerable(c: ContractBuilder) { - c.addComponent(components.ERC721EnumerableComponent, [], true); -} - -function addBurnable(c: ContractBuilder) { - c.addUseClause('core::num::traits', 'Zero'); - c.addUseClause('starknet', 'get_caller_address'); - - c.addFunction(externalTrait, functions.burn); -} - -function addMintable(c: ContractBuilder, access: Access) { - c.addUseClause('starknet', 'ContractAddress'); - requireAccessControl(c, externalTrait, functions.safe_mint, access, 'MINTER', 'minter'); - - // Camel case version of safe_mint. Access control and pausable are already set on safe_mint. - c.addFunction(externalTrait, functions.safeMint); -} - -const components = defineComponents( { - ERC721Component: { - path: 'openzeppelin::token::erc721', - substorage: { - name: 'erc721', - type: 'ERC721Component::Storage', - }, - event: { - name: 'ERC721Event', - type: 'ERC721Component::Event', - }, - impls: [{ - name: 'ERC721InternalImpl', - embed: false, - value: 'ERC721Component::InternalImpl', - }], - }, - ERC721EnumerableComponent: { - path: 'openzeppelin::token::erc721::extensions', - substorage: { - name: 'erc721_enumerable', - type: 'ERC721EnumerableComponent::Storage', - }, - event: { - name: 'ERC721EnumerableEvent', - type: 'ERC721EnumerableComponent::Event', - }, - impls: [{ - name: 'ERC721EnumerableImpl', - value: 'ERC721EnumerableComponent::ERC721EnumerableImpl', - }, { - name: 'ERC721EnumerableInternalImpl', - embed: false, - value: 'ERC721EnumerableComponent::InternalImpl', - }], - }, -}); - -const functions = defineFunctions({ - burn: { - args: [ - getSelfArg(), - { name: 'token_id', type: 'u256' } - ], - code: [ - 'self.erc721.update(Zero::zero(), token_id, get_caller_address());', - ] - }, - safe_mint: { - args: [ - getSelfArg(), - { name: 'recipient', type: 'ContractAddress' }, - { name: 'token_id', type: 'u256' }, - { name: 'data', type: 'Span' }, - ], - code: [ - 'self.erc721.safe_mint(recipient, token_id, data);', - ] - }, - safeMint: { - args: [ - getSelfArg(), - { name: 'recipient', type: 'ContractAddress' }, - { name: 'tokenId', type: 'u256' }, - { name: 'data', type: 'Span' }, - ], - code: [ - 'self.safe_mint(recipient, tokenId, data);', - ] - }, -}); diff --git a/packages/core/stylus/src/generate/account.ts b/packages/core/stylus/src/generate/account.ts deleted file mode 100644 index 175ba8df9..000000000 --- a/packages/core/stylus/src/generate/account.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { accountTypes, type AccountOptions } from '../account'; -import { infoOptions } from '../set-info'; -import { upgradeableOptions } from '../set-upgradeable'; -import { generateAlternatives } from './alternatives'; - -const booleans = [true, false]; - -const blueprint = { - name: ['MyAccount'], - type: accountTypes, - declare: booleans, - deploy: booleans, - pubkey: booleans, - outsideExecution: booleans, - upgradeable: upgradeableOptions, - info: infoOptions, -}; - -export function* generateAccountOptions(): Generator> { - yield* generateAlternatives(blueprint); -} diff --git a/packages/core/stylus/src/generate/custom.ts b/packages/core/stylus/src/generate/custom.ts deleted file mode 100644 index 40207666a..000000000 --- a/packages/core/stylus/src/generate/custom.ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { CustomOptions } from '../custom'; -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: ['MyContract'], - pausable: booleans, - access: accessOptions, - upgradeable: upgradeableOptions, - info: infoOptions, -}; - -export function* generateCustomOptions(): Generator> { - yield* generateAlternatives(blueprint); -} diff --git a/packages/core/stylus/src/generate/erc1155.ts b/packages/core/stylus/src/generate/erc1155.ts deleted file mode 100644 index 07170fcbd..000000000 --- a/packages/core/stylus/src/generate/erc1155.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type { ERC1155Options } from '../erc1155'; -import { accessOptions } from '../set-access-control'; -import { infoOptions } from '../set-info'; -import { upgradeableOptions } from '../set-upgradeable'; -import { royaltyInfoOptions } from '../set-royalty-info'; -import { generateAlternatives } from './alternatives'; - -const booleans = [true, false]; - -const blueprint = { - name: ['MyToken'], - baseUri: ['https://example.com/'], - burnable: booleans, - pausable: booleans, - mintable: booleans, - updatableUri: booleans, - upgradeable: upgradeableOptions, - royaltyInfo: [royaltyInfoOptions.disabled, royaltyInfoOptions.enabledDefault, royaltyInfoOptions.enabledCustom], - access: accessOptions, - info: infoOptions, -}; - -export function* generateERC1155Options(): Generator> { - yield* generateAlternatives(blueprint); -} diff --git a/packages/core/stylus/src/generate/erc721.ts b/packages/core/stylus/src/generate/erc721.ts deleted file mode 100644 index e78a94f15..000000000 --- a/packages/core/stylus/src/generate/erc721.ts +++ /dev/null @@ -1,29 +0,0 @@ -import type { ERC721Options } from '../erc721'; -import { accessOptions } from '../set-access-control'; -import { infoOptions } from '../set-info'; -import { upgradeableOptions } from '../set-upgradeable'; -import { royaltyInfoOptions } from '../set-royalty-info'; -import { generateAlternatives } from './alternatives'; - -const booleans = [true, false]; - -const blueprint = { - name: ['MyToken'], - symbol: ['MTK'], - baseUri: ['https://example.com/'], - burnable: booleans, - enumerable: booleans, - votes: booleans, - appName: ['MyApp'], - appVersion: ['v1'], - pausable: booleans, - mintable: booleans, - royaltyInfo: [royaltyInfoOptions.disabled, royaltyInfoOptions.enabledDefault, royaltyInfoOptions.enabledCustom], - access: accessOptions, - upgradeable: upgradeableOptions, - info: infoOptions, -}; - -export function* generateERC721Options(): Generator> { - yield* generateAlternatives(blueprint); -} diff --git a/packages/core/stylus/src/generate/governor.ts b/packages/core/stylus/src/generate/governor.ts deleted file mode 100644 index 8ffee9aef..000000000 --- a/packages/core/stylus/src/generate/governor.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { clockModeOptions, GovernorOptions, quorumModeOptions, timelockOptions, votesOptions } from '../governor'; -import { infoOptions } from '../set-info'; -import { upgradeableOptions } from '../set-upgradeable'; -import { generateAlternatives } from './alternatives'; - -const booleans = [true, false]; - -const blueprint = { - name: ['MyGovernor'], - delay: ['1 day'], - period: ['1 week'], - proposalThreshold: ['1'], - decimals: [18], - quorumMode: quorumModeOptions, - quorumPercent: [10], - quorumAbsolute: ['10'], - votes: votesOptions, - clockMode: clockModeOptions, - timelock: timelockOptions, - settings: booleans, - appName: ['Openzeppelin Governor'], - appVersion: ['v1'], - upgradeable: upgradeableOptions, - info: infoOptions, -}; - -export function* generateGovernorOptions(): Generator> { - yield* generateAlternatives(blueprint); -} - diff --git a/packages/core/stylus/src/generate/sources.ts b/packages/core/stylus/src/generate/sources.ts index 5be28487c..e10ed38b2 100644 --- a/packages/core/stylus/src/generate/sources.ts +++ b/packages/core/stylus/src/generate/sources.ts @@ -3,12 +3,6 @@ import path from 'path'; import crypto from 'crypto'; import { generateERC20Options } from './erc20'; -import { generateERC721Options } from './erc721'; -import { generateERC1155Options } from './erc1155'; -import { generateAccountOptions } from './account'; -import { generateCustomOptions } from './custom'; -import { generateGovernorOptions } from './governor'; -import { generateVestingOptions } from './vesting'; import { buildGeneric, GenericOptions, KindedOptions } from '../build-generic'; import { printContract } from '../print'; import { OptionsError } from '../error'; @@ -25,42 +19,6 @@ export function* generateOptions(kind?: Kind): Generator { yield { kind: 'ERC20', ...kindOpts }; } } - - if (!kind || kind === 'ERC721') { - for (const kindOpts of generateERC721Options()) { - yield { kind: 'ERC721', ...kindOpts }; - } - } - - if (!kind || kind === 'ERC1155') { - for (const kindOpts of generateERC1155Options()) { - yield { kind: 'ERC1155', ...kindOpts }; - } - } - - if (!kind || kind === 'Account') { - for (const kindOpts of generateAccountOptions()) { - yield { kind: 'Account', ...kindOpts }; - } - } - - if (!kind || kind === 'Custom') { - for (const kindOpts of generateCustomOptions()) { - yield { kind: 'Custom', ...kindOpts }; - } - } - - if (!kind || kind === 'Governor') { - for (const kindOpts of generateGovernorOptions()) { - yield { kind: 'Governor', ...kindOpts }; - } - } - - if (!kind || kind === 'Vesting') { - for (const kindOpts of generateVestingOptions()) { - yield { kind: 'Vesting', ...kindOpts }; - } - } } interface GeneratedContract { @@ -102,17 +60,10 @@ function generateContractSubset(subset: Subset, kind?: Kind): GeneratedContract[ function filterByUpgradeableSetTo(isUpgradeable: boolean) { return (c: GeneratedContract) => { switch (c.options.kind) { - case 'Vesting': - return isUpgradeable === false; - case 'Account': case 'ERC20': - case 'ERC721': - case 'ERC1155': - case 'Governor': - case 'Custom': return c.options.upgradeable === isUpgradeable; default: - const _: never = c.options; + const _: never = c.options.kind; // TODO: When there are additional kinds above, change this assignment to just `c.options` instead of `c.options.kind` throw new Error('Unknown kind'); } } diff --git a/packages/core/stylus/src/generate/vesting.ts b/packages/core/stylus/src/generate/vesting.ts deleted file mode 100644 index 45de06143..000000000 --- a/packages/core/stylus/src/generate/vesting.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { infoOptions } from '../set-info'; -import type { VestingOptions } from '../vesting'; -import { generateAlternatives } from './alternatives'; - -const blueprint = { - name: ['MyVesting'], - startDate: ['2024-12-31T23:59'], - duration: ['90 days', '1 year'], - cliffDuration: ['0 seconds', '30 day'], - schedule: ['linear', 'custom'] as const, - info: infoOptions -}; - -export function* generateVestingOptions(): Generator> { - yield* generateAlternatives(blueprint); -} diff --git a/packages/core/stylus/src/governor.test.ts b/packages/core/stylus/src/governor.test.ts deleted file mode 100644 index e3b3f0c22..000000000 --- a/packages/core/stylus/src/governor.test.ts +++ /dev/null @@ -1,181 +0,0 @@ -import test from 'ava'; -import { governor } from '.'; - -import { buildGovernor, GovernorOptions } from './governor'; -import { printContract } from './print'; - -const NAME = 'MyGovernor'; - -function testGovernor(title: string, opts: Partial) { - test(title, t => { - const c = buildGovernor({ - name: NAME, - delay: '1 day', - period: '1 week', - ...opts, - }); - t.snapshot(printContract(c)); - }); -} - -/** - * Tests external API for equivalence with internal API - */ -function testAPIEquivalence(title: string, opts?: GovernorOptions) { - test(title, t => { - t.is(governor.print(opts), printContract(buildGovernor({ - name: NAME, - delay: '1 day', - period: '1 week', - ...opts, - }))); - }); -} - -testGovernor('basic + upgradeable', { - upgradeable: true -}); - -testGovernor('basic non-upgradeable', { - upgradeable: false -}); - -testGovernor('erc20 votes + timelock', { - votes: 'erc20votes', - timelock: 'openzeppelin', -}); - -testGovernor('erc721 votes + timelock', { - votes: 'erc721votes', - timelock: 'openzeppelin', -}); - -testGovernor('custom name', { - name: 'CustomGovernor', -}); - -testGovernor('custom settings', { - delay: '2 hours', - period: '1 year', - proposalThreshold: '300', - settings: true, -}); - -testGovernor('quorum mode absolute', { - quorumMode: 'absolute', - quorumAbsolute: '200', -}); - -testGovernor('quorum mode percent', { - quorumMode: 'percent', - quorumPercent: 40, -}); - -testGovernor('custom snip12 metadata', { - appName: 'Governor', - appVersion: 'v3', -}); - -testGovernor('all options', { - name: NAME, - delay: '4 day', - period: '4 week', - proposalThreshold: '500', - decimals: 10, - quorumMode: 'absolute', - quorumPercent: 50, - quorumAbsolute: '200', - votes: 'erc721votes', - clockMode: 'timestamp', - timelock: 'openzeppelin', - settings: true, - appName: 'MyApp2', - appVersion: 'v5', - upgradeable: true, -}); - -testAPIEquivalence('API basic + upgradeable', { - name: NAME, - delay: '1 day', - period: '1 week', - upgradeable: true -}); - -testAPIEquivalence('API basic non-upgradeable', { - name: NAME, - delay: '1 day', - period: '1 week', - upgradeable: false -}); - -testAPIEquivalence('API erc20 votes + timelock', { - name: NAME, - delay: '1 day', - period: '1 week', - votes: 'erc20votes', - timelock: 'openzeppelin', -}); - -testAPIEquivalence('API erc721 votes + timelock', { - name: NAME, - delay: '1 day', - period: '1 week', - votes: 'erc721votes', - timelock: 'openzeppelin', -}); - -testAPIEquivalence('API custom name', { - name: 'CustomGovernor', - delay: '1 day', - period: '1 week', -}); - -testAPIEquivalence('API custom settings', { - name: NAME, - delay: '2 hours', - period: '1 year', - proposalThreshold: '300', - settings: true, -}); - -testAPIEquivalence('API quorum mode absolute', { - name: NAME, - delay: '1 day', - period: '1 week', - quorumMode: 'absolute', - quorumAbsolute: '200', -}); - -testAPIEquivalence('API quorum mode percent', { - name: NAME, - delay: '1 day', - period: '1 week', - quorumMode: 'percent', - quorumPercent: 40, -}); - -testAPIEquivalence('API custom snip12 metadata', { - name: NAME, - delay: '1 day', - period: '1 week', - appName: 'Governor', - appVersion: 'v3', -}); - -testAPIEquivalence('API all options', { - name: NAME, - delay: '4 day', - period: '4 week', - proposalThreshold: '500', - decimals: 10, - quorumMode: 'absolute', - quorumPercent: 50, - quorumAbsolute: '200', - votes: 'erc721votes', - clockMode: 'timestamp', - timelock: 'openzeppelin', - settings: true, - appName: 'MyApp2', - appVersion: 'v5', - upgradeable: true, -}); diff --git a/packages/core/stylus/src/governor.test.ts.md b/packages/core/stylus/src/governor.test.ts.md deleted file mode 100644 index 3c8e8a77d..000000000 --- a/packages/core/stylus/src/governor.test.ts.md +++ /dev/null @@ -1,1419 +0,0 @@ -# Snapshot report for `src/governor.test.ts` - -The actual snapshot is saved in `governor.test.ts.snap`. - -Generated by [AVA](https://avajs.dev). - -## basic + upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyGovernor {␊ - use openzeppelin::governance::governor::{DefaultConfig, GovernorComponent};␊ - use openzeppelin::governance::governor::extensions::{␊ - GovernorCountingSimpleComponent, GovernorSettingsComponent,␊ - GovernorTimelockExecutionComponent, GovernorVotesQuorumFractionComponent␊ - };␊ - use openzeppelin::governance::governor::extensions::GovernorSettingsComponent::InternalTrait as GovernorSettingsInternalTrait;␊ - use openzeppelin::governance::governor::extensions::GovernorTimelockExecutionComponent::InternalTrait as GovernorTimelockExecutionInternalTrait;␊ - use openzeppelin::governance::governor::extensions::GovernorVotesQuorumFractionComponent::InternalTrait as GovernorVotesQuorumFractionInternalTrait;␊ - use openzeppelin::governance::governor::GovernorComponent::{␊ - InternalExtendedImpl, InternalTrait as GovernorInternalTrait␊ - };␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - const QUORUM_NUMERATOR: u256 = 40; // 4%␊ - const VOTING_DELAY: u64 = 86400; // 1 day␊ - const VOTING_PERIOD: u64 = 604800; // 1 week␊ - const PROPOSAL_THRESHOLD: u256 = 0;␊ - ␊ - component!(path: GovernorComponent, storage: governor, event: GovernorEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: GovernorCountingSimpleComponent, storage: governor_counting, event: GovernorCountingSimpleEvent);␊ - component!(path: GovernorVotesQuorumFractionComponent, storage: governor_votes, event: GovernorVotesEvent);␊ - component!(path: GovernorSettingsComponent, storage: governor_settings, event: GovernorSettingsEvent);␊ - component!(path: GovernorTimelockExecutionComponent, storage: governor_timelock_execution, event: GovernorTimelockExecutionEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // Extensions (external)␊ - #[abi(embed_v0)]␊ - impl QuorumFractionImpl = GovernorVotesQuorumFractionComponent::QuorumFractionImpl;␊ - #[abi(embed_v0)]␊ - impl GovernorSettingsAdminImpl = GovernorSettingsComponent::GovernorSettingsAdminImpl;␊ - #[abi(embed_v0)]␊ - impl TimelockedImpl = GovernorTimelockExecutionComponent::TimelockedImpl;␊ - ␊ - // Extensions (internal)␊ - impl GovernorCountingSimpleImpl = GovernorCountingSimpleComponent::GovernorCounting;␊ - impl GovernorQuorumImpl = GovernorVotesQuorumFractionComponent::GovernorQuorum;␊ - impl GovernorVotesImpl = GovernorVotesQuorumFractionComponent::GovernorVotes;␊ - impl GovernorSettingsImpl = GovernorSettingsComponent::GovernorSettings;␊ - impl GovernorTimelockExecutionImpl = GovernorTimelockExecutionComponent::GovernorExecution;␊ - ␊ - // Governor Core␊ - #[abi(embed_v0)]␊ - impl GovernorImpl = GovernorComponent::GovernorImpl;␊ - ␊ - // Internal␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - // SRC5␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - governor: GovernorComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - governor_counting: GovernorCountingSimpleComponent::Storage,␊ - #[substorage(v0)]␊ - governor_votes: GovernorVotesQuorumFractionComponent::Storage,␊ - #[substorage(v0)]␊ - governor_settings: GovernorSettingsComponent::Storage,␊ - #[substorage(v0)]␊ - governor_timelock_execution: GovernorTimelockExecutionComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - GovernorEvent: GovernorComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - GovernorCountingSimpleEvent: GovernorCountingSimpleComponent::Event,␊ - #[flat]␊ - GovernorVotesEvent: GovernorVotesQuorumFractionComponent::Event,␊ - #[flat]␊ - GovernorSettingsEvent: GovernorSettingsComponent::Event,␊ - #[flat]␊ - GovernorTimelockExecutionEvent: GovernorTimelockExecutionComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - votes_token: ContractAddress,␊ - timelock_controller: ContractAddress,␊ - ) {␊ - self.governor.initializer();␊ - self.governor_votes.initializer(votes_token, QUORUM_NUMERATOR);␊ - self.governor_settings.initializer(VOTING_DELAY, VOTING_PERIOD, PROPOSAL_THRESHOLD);␊ - self.governor_timelock_execution.initializer(timelock_controller);␊ - }␊ - ␊ - //␊ - // SNIP12 Metadata␊ - //␊ - ␊ - impl SNIP12MetadataImpl of SNIP12Metadata {␊ - fn name() -> felt252 {␊ - 'OpenZeppelin Governor'␊ - }␊ - ␊ - fn version() -> felt252 {␊ - 'v1'␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.governor.assert_only_governance();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## basic non-upgradeable - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyGovernor {␊ - use openzeppelin::governance::governor::{DefaultConfig, GovernorComponent};␊ - use openzeppelin::governance::governor::extensions::{␊ - GovernorCountingSimpleComponent, GovernorSettingsComponent,␊ - GovernorTimelockExecutionComponent, GovernorVotesQuorumFractionComponent␊ - };␊ - use openzeppelin::governance::governor::extensions::GovernorSettingsComponent::InternalTrait as GovernorSettingsInternalTrait;␊ - use openzeppelin::governance::governor::extensions::GovernorTimelockExecutionComponent::InternalTrait as GovernorTimelockExecutionInternalTrait;␊ - use openzeppelin::governance::governor::extensions::GovernorVotesQuorumFractionComponent::InternalTrait as GovernorVotesQuorumFractionInternalTrait;␊ - use openzeppelin::governance::governor::GovernorComponent::InternalTrait as GovernorInternalTrait;␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ - use starknet::ContractAddress;␊ - ␊ - const QUORUM_NUMERATOR: u256 = 40; // 4%␊ - const VOTING_DELAY: u64 = 86400; // 1 day␊ - const VOTING_PERIOD: u64 = 604800; // 1 week␊ - const PROPOSAL_THRESHOLD: u256 = 0;␊ - ␊ - component!(path: GovernorComponent, storage: governor, event: GovernorEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: GovernorCountingSimpleComponent, storage: governor_counting, event: GovernorCountingSimpleEvent);␊ - component!(path: GovernorVotesQuorumFractionComponent, storage: governor_votes, event: GovernorVotesEvent);␊ - component!(path: GovernorSettingsComponent, storage: governor_settings, event: GovernorSettingsEvent);␊ - component!(path: GovernorTimelockExecutionComponent, storage: governor_timelock_execution, event: GovernorTimelockExecutionEvent);␊ - ␊ - // Extensions (external)␊ - #[abi(embed_v0)]␊ - impl QuorumFractionImpl = GovernorVotesQuorumFractionComponent::QuorumFractionImpl;␊ - #[abi(embed_v0)]␊ - impl GovernorSettingsAdminImpl = GovernorSettingsComponent::GovernorSettingsAdminImpl;␊ - #[abi(embed_v0)]␊ - impl TimelockedImpl = GovernorTimelockExecutionComponent::TimelockedImpl;␊ - ␊ - // Extensions (internal)␊ - impl GovernorCountingSimpleImpl = GovernorCountingSimpleComponent::GovernorCounting;␊ - impl GovernorQuorumImpl = GovernorVotesQuorumFractionComponent::GovernorQuorum;␊ - impl GovernorVotesImpl = GovernorVotesQuorumFractionComponent::GovernorVotes;␊ - impl GovernorSettingsImpl = GovernorSettingsComponent::GovernorSettings;␊ - impl GovernorTimelockExecutionImpl = GovernorTimelockExecutionComponent::GovernorExecution;␊ - ␊ - // Governor Core␊ - #[abi(embed_v0)]␊ - impl GovernorImpl = GovernorComponent::GovernorImpl;␊ - ␊ - // SRC5␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - governor: GovernorComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - governor_counting: GovernorCountingSimpleComponent::Storage,␊ - #[substorage(v0)]␊ - governor_votes: GovernorVotesQuorumFractionComponent::Storage,␊ - #[substorage(v0)]␊ - governor_settings: GovernorSettingsComponent::Storage,␊ - #[substorage(v0)]␊ - governor_timelock_execution: GovernorTimelockExecutionComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - GovernorEvent: GovernorComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - GovernorCountingSimpleEvent: GovernorCountingSimpleComponent::Event,␊ - #[flat]␊ - GovernorVotesEvent: GovernorVotesQuorumFractionComponent::Event,␊ - #[flat]␊ - GovernorSettingsEvent: GovernorSettingsComponent::Event,␊ - #[flat]␊ - GovernorTimelockExecutionEvent: GovernorTimelockExecutionComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - votes_token: ContractAddress,␊ - timelock_controller: ContractAddress,␊ - ) {␊ - self.governor.initializer();␊ - self.governor_votes.initializer(votes_token, QUORUM_NUMERATOR);␊ - self.governor_settings.initializer(VOTING_DELAY, VOTING_PERIOD, PROPOSAL_THRESHOLD);␊ - self.governor_timelock_execution.initializer(timelock_controller);␊ - }␊ - ␊ - //␊ - // SNIP12 Metadata␊ - //␊ - ␊ - impl SNIP12MetadataImpl of SNIP12Metadata {␊ - fn name() -> felt252 {␊ - 'OpenZeppelin Governor'␊ - }␊ - ␊ - fn version() -> felt252 {␊ - 'v1'␊ - }␊ - }␊ - }␊ - ` - -## erc20 votes + timelock - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyGovernor {␊ - use openzeppelin::governance::governor::{DefaultConfig, GovernorComponent};␊ - use openzeppelin::governance::governor::extensions::{␊ - GovernorCountingSimpleComponent, GovernorSettingsComponent,␊ - GovernorTimelockExecutionComponent, GovernorVotesQuorumFractionComponent␊ - };␊ - use openzeppelin::governance::governor::extensions::GovernorSettingsComponent::InternalTrait as GovernorSettingsInternalTrait;␊ - use openzeppelin::governance::governor::extensions::GovernorTimelockExecutionComponent::InternalTrait as GovernorTimelockExecutionInternalTrait;␊ - use openzeppelin::governance::governor::extensions::GovernorVotesQuorumFractionComponent::InternalTrait as GovernorVotesQuorumFractionInternalTrait;␊ - use openzeppelin::governance::governor::GovernorComponent::{␊ - InternalExtendedImpl, InternalTrait as GovernorInternalTrait␊ - };␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - const QUORUM_NUMERATOR: u256 = 40; // 4%␊ - const VOTING_DELAY: u64 = 86400; // 1 day␊ - const VOTING_PERIOD: u64 = 604800; // 1 week␊ - const PROPOSAL_THRESHOLD: u256 = 0;␊ - ␊ - component!(path: GovernorComponent, storage: governor, event: GovernorEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: GovernorCountingSimpleComponent, storage: governor_counting, event: GovernorCountingSimpleEvent);␊ - component!(path: GovernorVotesQuorumFractionComponent, storage: governor_votes, event: GovernorVotesEvent);␊ - component!(path: GovernorSettingsComponent, storage: governor_settings, event: GovernorSettingsEvent);␊ - component!(path: GovernorTimelockExecutionComponent, storage: governor_timelock_execution, event: GovernorTimelockExecutionEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // Extensions (external)␊ - #[abi(embed_v0)]␊ - impl QuorumFractionImpl = GovernorVotesQuorumFractionComponent::QuorumFractionImpl;␊ - #[abi(embed_v0)]␊ - impl GovernorSettingsAdminImpl = GovernorSettingsComponent::GovernorSettingsAdminImpl;␊ - #[abi(embed_v0)]␊ - impl TimelockedImpl = GovernorTimelockExecutionComponent::TimelockedImpl;␊ - ␊ - // Extensions (internal)␊ - impl GovernorCountingSimpleImpl = GovernorCountingSimpleComponent::GovernorCounting;␊ - impl GovernorQuorumImpl = GovernorVotesQuorumFractionComponent::GovernorQuorum;␊ - impl GovernorVotesImpl = GovernorVotesQuorumFractionComponent::GovernorVotes;␊ - impl GovernorSettingsImpl = GovernorSettingsComponent::GovernorSettings;␊ - impl GovernorTimelockExecutionImpl = GovernorTimelockExecutionComponent::GovernorExecution;␊ - ␊ - // Governor Core␊ - #[abi(embed_v0)]␊ - impl GovernorImpl = GovernorComponent::GovernorImpl;␊ - ␊ - // Internal␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - // SRC5␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - governor: GovernorComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - governor_counting: GovernorCountingSimpleComponent::Storage,␊ - #[substorage(v0)]␊ - governor_votes: GovernorVotesQuorumFractionComponent::Storage,␊ - #[substorage(v0)]␊ - governor_settings: GovernorSettingsComponent::Storage,␊ - #[substorage(v0)]␊ - governor_timelock_execution: GovernorTimelockExecutionComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - GovernorEvent: GovernorComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - GovernorCountingSimpleEvent: GovernorCountingSimpleComponent::Event,␊ - #[flat]␊ - GovernorVotesEvent: GovernorVotesQuorumFractionComponent::Event,␊ - #[flat]␊ - GovernorSettingsEvent: GovernorSettingsComponent::Event,␊ - #[flat]␊ - GovernorTimelockExecutionEvent: GovernorTimelockExecutionComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - votes_token: ContractAddress,␊ - timelock_controller: ContractAddress,␊ - ) {␊ - self.governor.initializer();␊ - self.governor_votes.initializer(votes_token, QUORUM_NUMERATOR);␊ - self.governor_settings.initializer(VOTING_DELAY, VOTING_PERIOD, PROPOSAL_THRESHOLD);␊ - self.governor_timelock_execution.initializer(timelock_controller);␊ - }␊ - ␊ - //␊ - // SNIP12 Metadata␊ - //␊ - ␊ - impl SNIP12MetadataImpl of SNIP12Metadata {␊ - fn name() -> felt252 {␊ - 'OpenZeppelin Governor'␊ - }␊ - ␊ - fn version() -> felt252 {␊ - 'v1'␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.governor.assert_only_governance();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## erc721 votes + timelock - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyGovernor {␊ - use openzeppelin::governance::governor::{DefaultConfig, GovernorComponent};␊ - use openzeppelin::governance::governor::extensions::{␊ - GovernorCountingSimpleComponent, GovernorSettingsComponent,␊ - GovernorTimelockExecutionComponent, GovernorVotesQuorumFractionComponent␊ - };␊ - use openzeppelin::governance::governor::extensions::GovernorSettingsComponent::InternalTrait as GovernorSettingsInternalTrait;␊ - use openzeppelin::governance::governor::extensions::GovernorTimelockExecutionComponent::InternalTrait as GovernorTimelockExecutionInternalTrait;␊ - use openzeppelin::governance::governor::extensions::GovernorVotesQuorumFractionComponent::InternalTrait as GovernorVotesQuorumFractionInternalTrait;␊ - use openzeppelin::governance::governor::GovernorComponent::{␊ - InternalExtendedImpl, InternalTrait as GovernorInternalTrait␊ - };␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - const QUORUM_NUMERATOR: u256 = 40; // 4%␊ - const VOTING_DELAY: u64 = 86400; // 1 day␊ - const VOTING_PERIOD: u64 = 604800; // 1 week␊ - const PROPOSAL_THRESHOLD: u256 = 0;␊ - ␊ - component!(path: GovernorComponent, storage: governor, event: GovernorEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: GovernorCountingSimpleComponent, storage: governor_counting, event: GovernorCountingSimpleEvent);␊ - component!(path: GovernorVotesQuorumFractionComponent, storage: governor_votes, event: GovernorVotesEvent);␊ - component!(path: GovernorSettingsComponent, storage: governor_settings, event: GovernorSettingsEvent);␊ - component!(path: GovernorTimelockExecutionComponent, storage: governor_timelock_execution, event: GovernorTimelockExecutionEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // Extensions (external)␊ - #[abi(embed_v0)]␊ - impl QuorumFractionImpl = GovernorVotesQuorumFractionComponent::QuorumFractionImpl;␊ - #[abi(embed_v0)]␊ - impl GovernorSettingsAdminImpl = GovernorSettingsComponent::GovernorSettingsAdminImpl;␊ - #[abi(embed_v0)]␊ - impl TimelockedImpl = GovernorTimelockExecutionComponent::TimelockedImpl;␊ - ␊ - // Extensions (internal)␊ - impl GovernorCountingSimpleImpl = GovernorCountingSimpleComponent::GovernorCounting;␊ - impl GovernorQuorumImpl = GovernorVotesQuorumFractionComponent::GovernorQuorum;␊ - impl GovernorVotesImpl = GovernorVotesQuorumFractionComponent::GovernorVotes;␊ - impl GovernorSettingsImpl = GovernorSettingsComponent::GovernorSettings;␊ - impl GovernorTimelockExecutionImpl = GovernorTimelockExecutionComponent::GovernorExecution;␊ - ␊ - // Governor Core␊ - #[abi(embed_v0)]␊ - impl GovernorImpl = GovernorComponent::GovernorImpl;␊ - ␊ - // Internal␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - // SRC5␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - governor: GovernorComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - governor_counting: GovernorCountingSimpleComponent::Storage,␊ - #[substorage(v0)]␊ - governor_votes: GovernorVotesQuorumFractionComponent::Storage,␊ - #[substorage(v0)]␊ - governor_settings: GovernorSettingsComponent::Storage,␊ - #[substorage(v0)]␊ - governor_timelock_execution: GovernorTimelockExecutionComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - GovernorEvent: GovernorComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - GovernorCountingSimpleEvent: GovernorCountingSimpleComponent::Event,␊ - #[flat]␊ - GovernorVotesEvent: GovernorVotesQuorumFractionComponent::Event,␊ - #[flat]␊ - GovernorSettingsEvent: GovernorSettingsComponent::Event,␊ - #[flat]␊ - GovernorTimelockExecutionEvent: GovernorTimelockExecutionComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - votes_token: ContractAddress,␊ - timelock_controller: ContractAddress,␊ - ) {␊ - self.governor.initializer();␊ - self.governor_votes.initializer(votes_token, QUORUM_NUMERATOR);␊ - self.governor_settings.initializer(VOTING_DELAY, VOTING_PERIOD, PROPOSAL_THRESHOLD);␊ - self.governor_timelock_execution.initializer(timelock_controller);␊ - }␊ - ␊ - //␊ - // SNIP12 Metadata␊ - //␊ - ␊ - impl SNIP12MetadataImpl of SNIP12Metadata {␊ - fn name() -> felt252 {␊ - 'OpenZeppelin Governor'␊ - }␊ - ␊ - fn version() -> felt252 {␊ - 'v1'␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.governor.assert_only_governance();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## custom name - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod CustomGovernor {␊ - use openzeppelin::governance::governor::{DefaultConfig, GovernorComponent};␊ - use openzeppelin::governance::governor::extensions::{␊ - GovernorCountingSimpleComponent, GovernorSettingsComponent,␊ - GovernorTimelockExecutionComponent, GovernorVotesQuorumFractionComponent␊ - };␊ - use openzeppelin::governance::governor::extensions::GovernorSettingsComponent::InternalTrait as GovernorSettingsInternalTrait;␊ - use openzeppelin::governance::governor::extensions::GovernorTimelockExecutionComponent::InternalTrait as GovernorTimelockExecutionInternalTrait;␊ - use openzeppelin::governance::governor::extensions::GovernorVotesQuorumFractionComponent::InternalTrait as GovernorVotesQuorumFractionInternalTrait;␊ - use openzeppelin::governance::governor::GovernorComponent::{␊ - InternalExtendedImpl, InternalTrait as GovernorInternalTrait␊ - };␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - const QUORUM_NUMERATOR: u256 = 40; // 4%␊ - const VOTING_DELAY: u64 = 86400; // 1 day␊ - const VOTING_PERIOD: u64 = 604800; // 1 week␊ - const PROPOSAL_THRESHOLD: u256 = 0;␊ - ␊ - component!(path: GovernorComponent, storage: governor, event: GovernorEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: GovernorCountingSimpleComponent, storage: governor_counting, event: GovernorCountingSimpleEvent);␊ - component!(path: GovernorVotesQuorumFractionComponent, storage: governor_votes, event: GovernorVotesEvent);␊ - component!(path: GovernorSettingsComponent, storage: governor_settings, event: GovernorSettingsEvent);␊ - component!(path: GovernorTimelockExecutionComponent, storage: governor_timelock_execution, event: GovernorTimelockExecutionEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // Extensions (external)␊ - #[abi(embed_v0)]␊ - impl QuorumFractionImpl = GovernorVotesQuorumFractionComponent::QuorumFractionImpl;␊ - #[abi(embed_v0)]␊ - impl GovernorSettingsAdminImpl = GovernorSettingsComponent::GovernorSettingsAdminImpl;␊ - #[abi(embed_v0)]␊ - impl TimelockedImpl = GovernorTimelockExecutionComponent::TimelockedImpl;␊ - ␊ - // Extensions (internal)␊ - impl GovernorCountingSimpleImpl = GovernorCountingSimpleComponent::GovernorCounting;␊ - impl GovernorQuorumImpl = GovernorVotesQuorumFractionComponent::GovernorQuorum;␊ - impl GovernorVotesImpl = GovernorVotesQuorumFractionComponent::GovernorVotes;␊ - impl GovernorSettingsImpl = GovernorSettingsComponent::GovernorSettings;␊ - impl GovernorTimelockExecutionImpl = GovernorTimelockExecutionComponent::GovernorExecution;␊ - ␊ - // Governor Core␊ - #[abi(embed_v0)]␊ - impl GovernorImpl = GovernorComponent::GovernorImpl;␊ - ␊ - // Internal␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - // SRC5␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - governor: GovernorComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - governor_counting: GovernorCountingSimpleComponent::Storage,␊ - #[substorage(v0)]␊ - governor_votes: GovernorVotesQuorumFractionComponent::Storage,␊ - #[substorage(v0)]␊ - governor_settings: GovernorSettingsComponent::Storage,␊ - #[substorage(v0)]␊ - governor_timelock_execution: GovernorTimelockExecutionComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - GovernorEvent: GovernorComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - GovernorCountingSimpleEvent: GovernorCountingSimpleComponent::Event,␊ - #[flat]␊ - GovernorVotesEvent: GovernorVotesQuorumFractionComponent::Event,␊ - #[flat]␊ - GovernorSettingsEvent: GovernorSettingsComponent::Event,␊ - #[flat]␊ - GovernorTimelockExecutionEvent: GovernorTimelockExecutionComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - votes_token: ContractAddress,␊ - timelock_controller: ContractAddress,␊ - ) {␊ - self.governor.initializer();␊ - self.governor_votes.initializer(votes_token, QUORUM_NUMERATOR);␊ - self.governor_settings.initializer(VOTING_DELAY, VOTING_PERIOD, PROPOSAL_THRESHOLD);␊ - self.governor_timelock_execution.initializer(timelock_controller);␊ - }␊ - ␊ - //␊ - // SNIP12 Metadata␊ - //␊ - ␊ - impl SNIP12MetadataImpl of SNIP12Metadata {␊ - fn name() -> felt252 {␊ - 'OpenZeppelin Governor'␊ - }␊ - ␊ - fn version() -> felt252 {␊ - 'v1'␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.governor.assert_only_governance();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## custom settings - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyGovernor {␊ - use openzeppelin::governance::governor::{DefaultConfig, GovernorComponent};␊ - use openzeppelin::governance::governor::extensions::{␊ - GovernorCountingSimpleComponent, GovernorSettingsComponent,␊ - GovernorTimelockExecutionComponent, GovernorVotesQuorumFractionComponent␊ - };␊ - use openzeppelin::governance::governor::extensions::GovernorSettingsComponent::InternalTrait as GovernorSettingsInternalTrait;␊ - use openzeppelin::governance::governor::extensions::GovernorTimelockExecutionComponent::InternalTrait as GovernorTimelockExecutionInternalTrait;␊ - use openzeppelin::governance::governor::extensions::GovernorVotesQuorumFractionComponent::InternalTrait as GovernorVotesQuorumFractionInternalTrait;␊ - use openzeppelin::governance::governor::GovernorComponent::{␊ - InternalExtendedImpl, InternalTrait as GovernorInternalTrait␊ - };␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - const QUORUM_NUMERATOR: u256 = 40; // 4%␊ - const VOTING_DELAY: u64 = 7200; // 2 hours␊ - const VOTING_PERIOD: u64 = 31536000; // 1 year␊ - const PROPOSAL_THRESHOLD: u256 = 300000000000000000000; // 300 * pow!(10, 18)␊ - ␊ - component!(path: GovernorComponent, storage: governor, event: GovernorEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: GovernorCountingSimpleComponent, storage: governor_counting, event: GovernorCountingSimpleEvent);␊ - component!(path: GovernorVotesQuorumFractionComponent, storage: governor_votes, event: GovernorVotesEvent);␊ - component!(path: GovernorSettingsComponent, storage: governor_settings, event: GovernorSettingsEvent);␊ - component!(path: GovernorTimelockExecutionComponent, storage: governor_timelock_execution, event: GovernorTimelockExecutionEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // Extensions (external)␊ - #[abi(embed_v0)]␊ - impl QuorumFractionImpl = GovernorVotesQuorumFractionComponent::QuorumFractionImpl;␊ - #[abi(embed_v0)]␊ - impl GovernorSettingsAdminImpl = GovernorSettingsComponent::GovernorSettingsAdminImpl;␊ - #[abi(embed_v0)]␊ - impl TimelockedImpl = GovernorTimelockExecutionComponent::TimelockedImpl;␊ - ␊ - // Extensions (internal)␊ - impl GovernorCountingSimpleImpl = GovernorCountingSimpleComponent::GovernorCounting;␊ - impl GovernorQuorumImpl = GovernorVotesQuorumFractionComponent::GovernorQuorum;␊ - impl GovernorVotesImpl = GovernorVotesQuorumFractionComponent::GovernorVotes;␊ - impl GovernorSettingsImpl = GovernorSettingsComponent::GovernorSettings;␊ - impl GovernorTimelockExecutionImpl = GovernorTimelockExecutionComponent::GovernorExecution;␊ - ␊ - // Governor Core␊ - #[abi(embed_v0)]␊ - impl GovernorImpl = GovernorComponent::GovernorImpl;␊ - ␊ - // Internal␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - // SRC5␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - governor: GovernorComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - governor_counting: GovernorCountingSimpleComponent::Storage,␊ - #[substorage(v0)]␊ - governor_votes: GovernorVotesQuorumFractionComponent::Storage,␊ - #[substorage(v0)]␊ - governor_settings: GovernorSettingsComponent::Storage,␊ - #[substorage(v0)]␊ - governor_timelock_execution: GovernorTimelockExecutionComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - GovernorEvent: GovernorComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - GovernorCountingSimpleEvent: GovernorCountingSimpleComponent::Event,␊ - #[flat]␊ - GovernorVotesEvent: GovernorVotesQuorumFractionComponent::Event,␊ - #[flat]␊ - GovernorSettingsEvent: GovernorSettingsComponent::Event,␊ - #[flat]␊ - GovernorTimelockExecutionEvent: GovernorTimelockExecutionComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - votes_token: ContractAddress,␊ - timelock_controller: ContractAddress,␊ - ) {␊ - self.governor.initializer();␊ - self.governor_votes.initializer(votes_token, QUORUM_NUMERATOR);␊ - self.governor_settings.initializer(VOTING_DELAY, VOTING_PERIOD, PROPOSAL_THRESHOLD);␊ - self.governor_timelock_execution.initializer(timelock_controller);␊ - }␊ - ␊ - //␊ - // SNIP12 Metadata␊ - //␊ - ␊ - impl SNIP12MetadataImpl of SNIP12Metadata {␊ - fn name() -> felt252 {␊ - 'OpenZeppelin Governor'␊ - }␊ - ␊ - fn version() -> felt252 {␊ - 'v1'␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.governor.assert_only_governance();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## quorum mode absolute - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyGovernor {␊ - use openzeppelin::governance::governor::{DefaultConfig, GovernorComponent};␊ - use openzeppelin::governance::governor::extensions::{␊ - GovernorCountingSimpleComponent, GovernorSettingsComponent,␊ - GovernorTimelockExecutionComponent, GovernorVotesComponent␊ - };␊ - use openzeppelin::governance::governor::extensions::GovernorSettingsComponent::InternalTrait as GovernorSettingsInternalTrait;␊ - use openzeppelin::governance::governor::extensions::GovernorTimelockExecutionComponent::InternalTrait as GovernorTimelockExecutionInternalTrait;␊ - use openzeppelin::governance::governor::extensions::GovernorVotesComponent::InternalTrait as GovernorVotesInternalTrait;␊ - use openzeppelin::governance::governor::GovernorComponent::{␊ - InternalExtendedImpl, InternalTrait as GovernorInternalTrait␊ - };␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - const QUORUM: u256 = 200000000000000000000; // 200 * pow!(10, 18)␊ - const VOTING_DELAY: u64 = 86400; // 1 day␊ - const VOTING_PERIOD: u64 = 604800; // 1 week␊ - const PROPOSAL_THRESHOLD: u256 = 0;␊ - ␊ - component!(path: GovernorComponent, storage: governor, event: GovernorEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: GovernorCountingSimpleComponent, storage: governor_counting, event: GovernorCountingSimpleEvent);␊ - component!(path: GovernorVotesComponent, storage: governor_votes, event: GovernorVotesEvent);␊ - component!(path: GovernorSettingsComponent, storage: governor_settings, event: GovernorSettingsEvent);␊ - component!(path: GovernorTimelockExecutionComponent, storage: governor_timelock_execution, event: GovernorTimelockExecutionEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // Extensions (external)␊ - #[abi(embed_v0)]␊ - impl VotesTokenImpl = GovernorVotesComponent::VotesTokenImpl;␊ - #[abi(embed_v0)]␊ - impl GovernorSettingsAdminImpl = GovernorSettingsComponent::GovernorSettingsAdminImpl;␊ - #[abi(embed_v0)]␊ - impl TimelockedImpl = GovernorTimelockExecutionComponent::TimelockedImpl;␊ - ␊ - // Extensions (internal)␊ - impl GovernorCountingSimpleImpl = GovernorCountingSimpleComponent::GovernorCounting;␊ - impl GovernorVotesImpl = GovernorVotesComponent::GovernorVotes;␊ - impl GovernorSettingsImpl = GovernorSettingsComponent::GovernorSettings;␊ - impl GovernorTimelockExecutionImpl = GovernorTimelockExecutionComponent::GovernorExecution;␊ - ␊ - // Governor Core␊ - #[abi(embed_v0)]␊ - impl GovernorImpl = GovernorComponent::GovernorImpl;␊ - ␊ - // Internal␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - // SRC5␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - governor: GovernorComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - governor_counting: GovernorCountingSimpleComponent::Storage,␊ - #[substorage(v0)]␊ - governor_votes: GovernorVotesComponent::Storage,␊ - #[substorage(v0)]␊ - governor_settings: GovernorSettingsComponent::Storage,␊ - #[substorage(v0)]␊ - governor_timelock_execution: GovernorTimelockExecutionComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - GovernorEvent: GovernorComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - GovernorCountingSimpleEvent: GovernorCountingSimpleComponent::Event,␊ - #[flat]␊ - GovernorVotesEvent: GovernorVotesComponent::Event,␊ - #[flat]␊ - GovernorSettingsEvent: GovernorSettingsComponent::Event,␊ - #[flat]␊ - GovernorTimelockExecutionEvent: GovernorTimelockExecutionComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - votes_token: ContractAddress,␊ - timelock_controller: ContractAddress,␊ - ) {␊ - self.governor.initializer();␊ - self.governor_votes.initializer(votes_token);␊ - self.governor_settings.initializer(VOTING_DELAY, VOTING_PERIOD, PROPOSAL_THRESHOLD);␊ - self.governor_timelock_execution.initializer(timelock_controller);␊ - }␊ - ␊ - //␊ - // Locally implemented extensions␊ - //␊ - ␊ - impl GovernorQuorum of GovernorComponent::GovernorQuorumTrait {␊ - fn quorum(self: @GovernorComponent::ComponentState, timepoint: u64) -> u256 {␊ - QUORUM␊ - }␊ - }␊ - ␊ - //␊ - // SNIP12 Metadata␊ - //␊ - ␊ - impl SNIP12MetadataImpl of SNIP12Metadata {␊ - fn name() -> felt252 {␊ - 'OpenZeppelin Governor'␊ - }␊ - ␊ - fn version() -> felt252 {␊ - 'v1'␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.governor.assert_only_governance();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## quorum mode percent - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyGovernor {␊ - use openzeppelin::governance::governor::{DefaultConfig, GovernorComponent};␊ - use openzeppelin::governance::governor::extensions::{␊ - GovernorCountingSimpleComponent, GovernorSettingsComponent,␊ - GovernorTimelockExecutionComponent, GovernorVotesQuorumFractionComponent␊ - };␊ - use openzeppelin::governance::governor::extensions::GovernorSettingsComponent::InternalTrait as GovernorSettingsInternalTrait;␊ - use openzeppelin::governance::governor::extensions::GovernorTimelockExecutionComponent::InternalTrait as GovernorTimelockExecutionInternalTrait;␊ - use openzeppelin::governance::governor::extensions::GovernorVotesQuorumFractionComponent::InternalTrait as GovernorVotesQuorumFractionInternalTrait;␊ - use openzeppelin::governance::governor::GovernorComponent::{␊ - InternalExtendedImpl, InternalTrait as GovernorInternalTrait␊ - };␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - const QUORUM_NUMERATOR: u256 = 400; // 40%␊ - const VOTING_DELAY: u64 = 86400; // 1 day␊ - const VOTING_PERIOD: u64 = 604800; // 1 week␊ - const PROPOSAL_THRESHOLD: u256 = 0;␊ - ␊ - component!(path: GovernorComponent, storage: governor, event: GovernorEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: GovernorCountingSimpleComponent, storage: governor_counting, event: GovernorCountingSimpleEvent);␊ - component!(path: GovernorVotesQuorumFractionComponent, storage: governor_votes, event: GovernorVotesEvent);␊ - component!(path: GovernorSettingsComponent, storage: governor_settings, event: GovernorSettingsEvent);␊ - component!(path: GovernorTimelockExecutionComponent, storage: governor_timelock_execution, event: GovernorTimelockExecutionEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // Extensions (external)␊ - #[abi(embed_v0)]␊ - impl QuorumFractionImpl = GovernorVotesQuorumFractionComponent::QuorumFractionImpl;␊ - #[abi(embed_v0)]␊ - impl GovernorSettingsAdminImpl = GovernorSettingsComponent::GovernorSettingsAdminImpl;␊ - #[abi(embed_v0)]␊ - impl TimelockedImpl = GovernorTimelockExecutionComponent::TimelockedImpl;␊ - ␊ - // Extensions (internal)␊ - impl GovernorCountingSimpleImpl = GovernorCountingSimpleComponent::GovernorCounting;␊ - impl GovernorQuorumImpl = GovernorVotesQuorumFractionComponent::GovernorQuorum;␊ - impl GovernorVotesImpl = GovernorVotesQuorumFractionComponent::GovernorVotes;␊ - impl GovernorSettingsImpl = GovernorSettingsComponent::GovernorSettings;␊ - impl GovernorTimelockExecutionImpl = GovernorTimelockExecutionComponent::GovernorExecution;␊ - ␊ - // Governor Core␊ - #[abi(embed_v0)]␊ - impl GovernorImpl = GovernorComponent::GovernorImpl;␊ - ␊ - // Internal␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - // SRC5␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - governor: GovernorComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - governor_counting: GovernorCountingSimpleComponent::Storage,␊ - #[substorage(v0)]␊ - governor_votes: GovernorVotesQuorumFractionComponent::Storage,␊ - #[substorage(v0)]␊ - governor_settings: GovernorSettingsComponent::Storage,␊ - #[substorage(v0)]␊ - governor_timelock_execution: GovernorTimelockExecutionComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - GovernorEvent: GovernorComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - GovernorCountingSimpleEvent: GovernorCountingSimpleComponent::Event,␊ - #[flat]␊ - GovernorVotesEvent: GovernorVotesQuorumFractionComponent::Event,␊ - #[flat]␊ - GovernorSettingsEvent: GovernorSettingsComponent::Event,␊ - #[flat]␊ - GovernorTimelockExecutionEvent: GovernorTimelockExecutionComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - votes_token: ContractAddress,␊ - timelock_controller: ContractAddress,␊ - ) {␊ - self.governor.initializer();␊ - self.governor_votes.initializer(votes_token, QUORUM_NUMERATOR);␊ - self.governor_settings.initializer(VOTING_DELAY, VOTING_PERIOD, PROPOSAL_THRESHOLD);␊ - self.governor_timelock_execution.initializer(timelock_controller);␊ - }␊ - ␊ - //␊ - // SNIP12 Metadata␊ - //␊ - ␊ - impl SNIP12MetadataImpl of SNIP12Metadata {␊ - fn name() -> felt252 {␊ - 'OpenZeppelin Governor'␊ - }␊ - ␊ - fn version() -> felt252 {␊ - 'v1'␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.governor.assert_only_governance();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## custom snip12 metadata - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyGovernor {␊ - use openzeppelin::governance::governor::{DefaultConfig, GovernorComponent};␊ - use openzeppelin::governance::governor::extensions::{␊ - GovernorCountingSimpleComponent, GovernorSettingsComponent,␊ - GovernorTimelockExecutionComponent, GovernorVotesQuorumFractionComponent␊ - };␊ - use openzeppelin::governance::governor::extensions::GovernorSettingsComponent::InternalTrait as GovernorSettingsInternalTrait;␊ - use openzeppelin::governance::governor::extensions::GovernorTimelockExecutionComponent::InternalTrait as GovernorTimelockExecutionInternalTrait;␊ - use openzeppelin::governance::governor::extensions::GovernorVotesQuorumFractionComponent::InternalTrait as GovernorVotesQuorumFractionInternalTrait;␊ - use openzeppelin::governance::governor::GovernorComponent::{␊ - InternalExtendedImpl, InternalTrait as GovernorInternalTrait␊ - };␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - const QUORUM_NUMERATOR: u256 = 40; // 4%␊ - const VOTING_DELAY: u64 = 86400; // 1 day␊ - const VOTING_PERIOD: u64 = 604800; // 1 week␊ - const PROPOSAL_THRESHOLD: u256 = 0;␊ - ␊ - component!(path: GovernorComponent, storage: governor, event: GovernorEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: GovernorCountingSimpleComponent, storage: governor_counting, event: GovernorCountingSimpleEvent);␊ - component!(path: GovernorVotesQuorumFractionComponent, storage: governor_votes, event: GovernorVotesEvent);␊ - component!(path: GovernorSettingsComponent, storage: governor_settings, event: GovernorSettingsEvent);␊ - component!(path: GovernorTimelockExecutionComponent, storage: governor_timelock_execution, event: GovernorTimelockExecutionEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // Extensions (external)␊ - #[abi(embed_v0)]␊ - impl QuorumFractionImpl = GovernorVotesQuorumFractionComponent::QuorumFractionImpl;␊ - #[abi(embed_v0)]␊ - impl GovernorSettingsAdminImpl = GovernorSettingsComponent::GovernorSettingsAdminImpl;␊ - #[abi(embed_v0)]␊ - impl TimelockedImpl = GovernorTimelockExecutionComponent::TimelockedImpl;␊ - ␊ - // Extensions (internal)␊ - impl GovernorCountingSimpleImpl = GovernorCountingSimpleComponent::GovernorCounting;␊ - impl GovernorQuorumImpl = GovernorVotesQuorumFractionComponent::GovernorQuorum;␊ - impl GovernorVotesImpl = GovernorVotesQuorumFractionComponent::GovernorVotes;␊ - impl GovernorSettingsImpl = GovernorSettingsComponent::GovernorSettings;␊ - impl GovernorTimelockExecutionImpl = GovernorTimelockExecutionComponent::GovernorExecution;␊ - ␊ - // Governor Core␊ - #[abi(embed_v0)]␊ - impl GovernorImpl = GovernorComponent::GovernorImpl;␊ - ␊ - // Internal␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - // SRC5␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - governor: GovernorComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - governor_counting: GovernorCountingSimpleComponent::Storage,␊ - #[substorage(v0)]␊ - governor_votes: GovernorVotesQuorumFractionComponent::Storage,␊ - #[substorage(v0)]␊ - governor_settings: GovernorSettingsComponent::Storage,␊ - #[substorage(v0)]␊ - governor_timelock_execution: GovernorTimelockExecutionComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - GovernorEvent: GovernorComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - GovernorCountingSimpleEvent: GovernorCountingSimpleComponent::Event,␊ - #[flat]␊ - GovernorVotesEvent: GovernorVotesQuorumFractionComponent::Event,␊ - #[flat]␊ - GovernorSettingsEvent: GovernorSettingsComponent::Event,␊ - #[flat]␊ - GovernorTimelockExecutionEvent: GovernorTimelockExecutionComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - votes_token: ContractAddress,␊ - timelock_controller: ContractAddress,␊ - ) {␊ - self.governor.initializer();␊ - self.governor_votes.initializer(votes_token, QUORUM_NUMERATOR);␊ - self.governor_settings.initializer(VOTING_DELAY, VOTING_PERIOD, PROPOSAL_THRESHOLD);␊ - self.governor_timelock_execution.initializer(timelock_controller);␊ - }␊ - ␊ - //␊ - // SNIP12 Metadata␊ - //␊ - ␊ - impl SNIP12MetadataImpl of SNIP12Metadata {␊ - fn name() -> felt252 {␊ - 'Governor'␊ - }␊ - ␊ - fn version() -> felt252 {␊ - 'v3'␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.governor.assert_only_governance();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` - -## all options - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyGovernor {␊ - use openzeppelin::governance::governor::{DefaultConfig, GovernorComponent};␊ - use openzeppelin::governance::governor::extensions::{␊ - GovernorCountingSimpleComponent, GovernorSettingsComponent,␊ - GovernorTimelockExecutionComponent, GovernorVotesComponent␊ - };␊ - use openzeppelin::governance::governor::extensions::GovernorSettingsComponent::InternalTrait as GovernorSettingsInternalTrait;␊ - use openzeppelin::governance::governor::extensions::GovernorTimelockExecutionComponent::InternalTrait as GovernorTimelockExecutionInternalTrait;␊ - use openzeppelin::governance::governor::extensions::GovernorVotesComponent::InternalTrait as GovernorVotesInternalTrait;␊ - use openzeppelin::governance::governor::GovernorComponent::{␊ - InternalExtendedImpl, InternalTrait as GovernorInternalTrait␊ - };␊ - use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::upgrades::interface::IUpgradeable;␊ - use openzeppelin::upgrades::UpgradeableComponent;␊ - use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ - use starknet::{ClassHash, ContractAddress};␊ - ␊ - const QUORUM: u256 = 200;␊ - const VOTING_DELAY: u64 = 345600; // 4 day␊ - const VOTING_PERIOD: u64 = 2419200; // 4 week␊ - const PROPOSAL_THRESHOLD: u256 = 500;␊ - ␊ - component!(path: GovernorComponent, storage: governor, event: GovernorEvent);␊ - component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: GovernorCountingSimpleComponent, storage: governor_counting, event: GovernorCountingSimpleEvent);␊ - component!(path: GovernorVotesComponent, storage: governor_votes, event: GovernorVotesEvent);␊ - component!(path: GovernorSettingsComponent, storage: governor_settings, event: GovernorSettingsEvent);␊ - component!(path: GovernorTimelockExecutionComponent, storage: governor_timelock_execution, event: GovernorTimelockExecutionEvent);␊ - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ - ␊ - // Extensions (external)␊ - #[abi(embed_v0)]␊ - impl VotesTokenImpl = GovernorVotesComponent::VotesTokenImpl;␊ - #[abi(embed_v0)]␊ - impl GovernorSettingsAdminImpl = GovernorSettingsComponent::GovernorSettingsAdminImpl;␊ - #[abi(embed_v0)]␊ - impl TimelockedImpl = GovernorTimelockExecutionComponent::TimelockedImpl;␊ - ␊ - // Extensions (internal)␊ - impl GovernorCountingSimpleImpl = GovernorCountingSimpleComponent::GovernorCounting;␊ - impl GovernorVotesImpl = GovernorVotesComponent::GovernorVotes;␊ - impl GovernorSettingsImpl = GovernorSettingsComponent::GovernorSettings;␊ - impl GovernorTimelockExecutionImpl = GovernorTimelockExecutionComponent::GovernorExecution;␊ - ␊ - // Governor Core␊ - #[abi(embed_v0)]␊ - impl GovernorImpl = GovernorComponent::GovernorImpl;␊ - ␊ - // Internal␊ - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ - ␊ - // SRC5␊ - #[abi(embed_v0)]␊ - impl SRC5Impl = SRC5Component::SRC5Impl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - governor: GovernorComponent::Storage,␊ - #[substorage(v0)]␊ - src5: SRC5Component::Storage,␊ - #[substorage(v0)]␊ - governor_counting: GovernorCountingSimpleComponent::Storage,␊ - #[substorage(v0)]␊ - governor_votes: GovernorVotesComponent::Storage,␊ - #[substorage(v0)]␊ - governor_settings: GovernorSettingsComponent::Storage,␊ - #[substorage(v0)]␊ - governor_timelock_execution: GovernorTimelockExecutionComponent::Storage,␊ - #[substorage(v0)]␊ - upgradeable: UpgradeableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - GovernorEvent: GovernorComponent::Event,␊ - #[flat]␊ - SRC5Event: SRC5Component::Event,␊ - #[flat]␊ - GovernorCountingSimpleEvent: GovernorCountingSimpleComponent::Event,␊ - #[flat]␊ - GovernorVotesEvent: GovernorVotesComponent::Event,␊ - #[flat]␊ - GovernorSettingsEvent: GovernorSettingsComponent::Event,␊ - #[flat]␊ - GovernorTimelockExecutionEvent: GovernorTimelockExecutionComponent::Event,␊ - #[flat]␊ - UpgradeableEvent: UpgradeableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(␊ - ref self: ContractState,␊ - votes_token: ContractAddress,␊ - timelock_controller: ContractAddress,␊ - ) {␊ - self.governor.initializer();␊ - self.governor_votes.initializer(votes_token);␊ - self.governor_settings.initializer(VOTING_DELAY, VOTING_PERIOD, PROPOSAL_THRESHOLD);␊ - self.governor_timelock_execution.initializer(timelock_controller);␊ - }␊ - ␊ - //␊ - // Locally implemented extensions␊ - //␊ - ␊ - impl GovernorQuorum of GovernorComponent::GovernorQuorumTrait {␊ - fn quorum(self: @GovernorComponent::ComponentState, timepoint: u64) -> u256 {␊ - QUORUM␊ - }␊ - }␊ - ␊ - //␊ - // SNIP12 Metadata␊ - //␊ - ␊ - impl SNIP12MetadataImpl of SNIP12Metadata {␊ - fn name() -> felt252 {␊ - 'MyApp2'␊ - }␊ - ␊ - fn version() -> felt252 {␊ - 'v5'␊ - }␊ - }␊ - ␊ - //␊ - // Upgradeable␊ - //␊ - ␊ - #[abi(embed_v0)]␊ - impl UpgradeableImpl of IUpgradeable {␊ - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ - self.governor.assert_only_governance();␊ - self.upgradeable.upgrade(new_class_hash);␊ - }␊ - }␊ - }␊ - ` diff --git a/packages/core/stylus/src/governor.test.ts.snap b/packages/core/stylus/src/governor.test.ts.snap deleted file mode 100644 index cbf65b0b991efd13c0d88ddfb25c4df51daf566f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2322 zcmZ{cdpHvcAIH}bVx*hgl_H(F9?Nx;W8`oYA|jn!TZmHm^GztQnJFF3?Mfdz@V1r>c~l8ylWIiVFMCuqD&PIN7xlR)KQ ze`1bnB$kHaJ2D05#h9nS0YvUSO6}aKrNpa7PU;1^5fpA}=mc43%a6RDw5p>NB`Aet zlr0#Ac(d>~6QZ`EzwyE&1+!#<36zULYaj58Bs#i@^*-5lD>#ze#KS5Bl^WX6 zEsYJZx1ASX^+LFE@7IRpjE~43hys6_M;8VFYhi4V4fdSs_z+Nd7rt~Iw^>DO+~}k` z4y+Y|=Zp}y))<4<65acA+n%3b+Ay9^!ZFynp7pI`6n`WmEUBiB4gL{N9`!1bD-MgGjT&s&wJaA z-GmX7&qs61%Cs=QbDFL@e`zgqQ)3|d2{2I_|NiMl1;Zy~5z=dNP-Z^0;pmM>r8K-l zcg*5jNU8)gg0iR-SjS4qa|SEjE>HcdT_wfdXM4`OJOA#$MW|U3@A0A$B1-OJi2UHx z@?ePS_A?|UZJdCAp8gPvY-H-6If9ZKvBQ|9Y-WHZ{`%vg2I^*p^h zD~0Id*mzB3qrvq%0o{luWJ!O0SYz7LcUKpQxM2h}F@i1xu56~2oQXiwrM8f~;YOYn z?#s%$)vt_vCq>}`OVIH_r}^}1yuO$Mg{h%4k#f-7;-);nmb7YYs+-N2hUHwJKU#rt z*2twgn^i z`eg6Lr*w45tJ-_t=z%SbXlRrdNYToVOAT>#-&RXK<$_JQ@&V!PB6}hJyE*%Ms{n65 zKx*3~m!&R#4~a<9*ynjw)WG zHET^MjcV|_=wv5q9@pQH)m;ATBFY_==^jx-^1oSB0{ab(muMam9Nx`jk12USU7kMi z=hL)q)*s6wpX@T~81Jrh`|TTuKPgLp*Ko!MpKo)|OVE9^(zsXTb&;r?R9!FE4OErYRrIa&^RH;H`CbwV$wU`mU(^4pf(g}AQOC%pSy@Kkj~FbqXO!y?%QrMev(HoW5AiCzO1)@*y4EXJ4`}&| zlxXg#!Pu=e8j=w?*OGSyRVDQ{ zTj_zy`aaf6=C|oNo<^HBA&j`fU=z=j2fQ_RJ?~a_b!75KF3Yx0_D!qcfyaeFxP0KJ z_NdNVa={Y@{<+2Y0TPg9j7HtlwjBf;ntJ;M-n)wpzZ&%E`|)Em?eB;H**!3bu9%7L z;tlPNn&$uB17pZcv@P2Y^(+sel)P^B>`xHh$P*iYk;Lq>uU$y=xv!=;Fp?j&E%U?8f(%!;?kHzZ9-!EFW>Sul}-Z0 zVp<@8e8^ZH27${7*XKn{<`be%ri)mU!qTyO1tV=@tk`ue?0SxY5Z}-|{;cJ(b6Y_$ zkV?)Ev)wYj>h|I%zF`uEjN6X4$I+zuhIJpJ*PmflXY3T#B%(y1LdA#ZF>o??O78z* z1xq}t)c{&T%DCZK&Vh>=98lZmsZto~cyk5-9s?%JO-Tfc7zq^~qWz0k0kqNM|B71i zBf-OG{(;9!Q<{#!v`1lLCbqyL(UEWeof!(TC`ChQklCx2rG@G={K_UH#RWmjO~!71 zLJ^&L1J_;LwRqBE9i6NcB;IDs{zd8Me&2;l;qoSuMOZrv-2Y&Z8;;So5oK-VNj_ql z(Vli=v~}UY)pAeX^1~5J$?Vo^*|pUE7#1Huf4_?KVIy!=q{Hs7I2ZI{b2wreOQcXm zo%ufNep%O*XMkB@;o1CVARWVM4+~<3sWcs%kODR7y64sSzKy)|aQnIKlLJS3U_eKc zr;wg`d?SF4F7NS^p+Y19W{P#4MIvWMc2T$K@;xuf9VR<%4`rKx!ODBoP^G*2AW nNiz5pz3{_N%3bE%MF^X-tTtMXK6)CrA&ADEtq&Pv0swylzumOf diff --git a/packages/core/stylus/src/governor.ts b/packages/core/stylus/src/governor.ts deleted file mode 100644 index fac953e62..000000000 --- a/packages/core/stylus/src/governor.ts +++ /dev/null @@ -1,494 +0,0 @@ -import { contractDefaults as commonDefaults, withCommonDefaults } from './common-options'; -import type { CommonOptions } from './common-options'; -import { ContractBuilder, Contract } from "./contract"; -import { OptionsError } from "./error"; -import { printContract } from "./print"; -import { setInfo } from "./set-info"; -import { setUpgradeableGovernor } from "./set-upgradeable"; -import { defineComponents } from './utils/define-components'; -import { durationToTimestamp } from './utils/duration'; -import { addSNIP12Metadata, addSRC5Component } from './common-components'; -import { toUint } from './utils/convert-strings'; -export const clockModeOptions = ['timestamp'] as const; -export const clockModeDefault = 'timestamp' as const; -export type ClockMode = typeof clockModeOptions[number]; - -const extensionPath = 'openzeppelin::governance::governor::extensions'; -const extensionExternalSection = 'Extensions (external)'; -const extensionInternalSection = 'Extensions (internal)'; - -export const defaults: Required = { - name: 'MyGovernor', - delay: '1 day', - period: '1 week', - votes: 'erc20votes', - clockMode: clockModeDefault, - timelock: 'openzeppelin', - decimals: 18, - proposalThreshold: '0', - quorumMode: 'percent', - quorumPercent: 4, - quorumAbsolute: '', - settings: true, - upgradeable: commonDefaults.upgradeable, - appName: 'OpenZeppelin Governor', - appVersion: 'v1', - info: commonDefaults.info -} as const; - -export const quorumModeOptions = ['percent', 'absolute'] as const; -export type QuorumMode = typeof quorumModeOptions[number]; - -export const votesOptions = ['erc20votes', 'erc721votes'] as const; -export type VotesOptions = typeof votesOptions[number]; - -export const timelockOptions = [false, 'openzeppelin'] as const; -export type TimelockOptions = typeof timelockOptions[number]; - -export function printGovernor(opts: GovernorOptions = defaults): string { - return printContract(buildGovernor(opts)); -} -export interface GovernorOptions extends CommonOptions { - name: string; - delay: string; - period: string; - proposalThreshold?: string; - decimals?: number; - quorumMode?: QuorumMode; - quorumPercent?: number; - quorumAbsolute?: string; - votes?: VotesOptions; - clockMode?: ClockMode; - timelock?: TimelockOptions; - settings?: boolean; - appName?: string; - appVersion?: string; -} - -function withDefaults(opts: GovernorOptions): Required { - return { - ...opts, - ...withCommonDefaults(opts), - delay: opts.delay ?? defaults.delay, - period: opts.period ?? defaults.period, - proposalThreshold: opts.proposalThreshold || defaults.proposalThreshold, - decimals: opts.decimals ?? defaults.decimals, - quorumPercent: opts.quorumPercent ?? defaults.quorumPercent, - quorumAbsolute: opts.quorumAbsolute ?? defaults.quorumAbsolute, - settings: opts.settings ?? defaults.settings, - quorumMode: opts.quorumMode ?? defaults.quorumMode, - votes: opts.votes ?? defaults.votes, - clockMode: opts.clockMode ?? defaults.clockMode, - timelock: opts.timelock ?? defaults.timelock, - appName: opts.appName ?? defaults.appName, - appVersion: opts.appVersion ?? defaults.appVersion, - }; -} - -export function buildGovernor(opts: GovernorOptions): Contract { - const allOpts = withDefaults(opts); - - const c = new ContractBuilder(allOpts.name); - - validateDecimals(allOpts.decimals); - - addBase(c, allOpts); - addSRC5Component(c, 'SRC5'); - addSNIP12Metadata(c, allOpts.appName, allOpts.appVersion, 'SNIP12 Metadata'); - addCounting(c, allOpts); - addQuorumAndVotes(c, allOpts); - addSettings(c, allOpts); - addExecution(c, allOpts); - setUpgradeableGovernor(c, allOpts.upgradeable); - setInfo(c, allOpts.info); - - return c; -} - -const components = defineComponents( { - GovernorComponent: { - path: 'openzeppelin::governance::governor', - substorage: { - name: 'governor', - type: 'GovernorComponent::Storage', - }, - event: { - name: 'GovernorEvent', - type: 'GovernorComponent::Event', - }, - impls: [{ - name: 'GovernorImpl', - value: 'GovernorComponent::GovernorImpl', - section: 'Governor Core', - }], - }, - GovernorSettingsComponent: { - path: extensionPath, - substorage: { - name: 'governor_settings', - type: 'GovernorSettingsComponent::Storage', - }, - event: { - name: 'GovernorSettingsEvent', - type: 'GovernorSettingsComponent::Event', - }, - impls: [{ - name: 'GovernorSettingsAdminImpl', - value: 'GovernorSettingsComponent::GovernorSettingsAdminImpl', - section: extensionExternalSection, - }, { - name: 'GovernorSettingsImpl', - value: 'GovernorSettingsComponent::GovernorSettings', - embed: false, - section: extensionInternalSection, - }], - }, - GovernorVotesComponent: { - path: extensionPath, - substorage: { - name: 'governor_votes', - type: 'GovernorVotesComponent::Storage', - }, - event: { - name: 'GovernorVotesEvent', - type: 'GovernorVotesComponent::Event', - }, - impls: [{ - name: 'VotesTokenImpl', - value: 'GovernorVotesComponent::VotesTokenImpl', - section: extensionExternalSection, - }, { - name: 'GovernorVotesImpl', - value: 'GovernorVotesComponent::GovernorVotes', - embed: false, - section: extensionInternalSection, - }], - }, - GovernorVotesQuorumFractionComponent: { - path: extensionPath, - substorage: { - name: 'governor_votes', - type: 'GovernorVotesQuorumFractionComponent::Storage', - }, - event: { - name: 'GovernorVotesEvent', - type: 'GovernorVotesQuorumFractionComponent::Event', - }, - impls: [{ - name: 'GovernorQuorumImpl', - value: 'GovernorVotesQuorumFractionComponent::GovernorQuorum', - embed: false, - section: extensionInternalSection, - }, { - name: 'GovernorVotesImpl', - value: 'GovernorVotesQuorumFractionComponent::GovernorVotes', - embed: false, - section: extensionInternalSection, - }, { - name: 'QuorumFractionImpl', - value: 'GovernorVotesQuorumFractionComponent::QuorumFractionImpl', - section: extensionExternalSection, - }], - }, - GovernorCountingSimpleComponent: { - path: extensionPath, - substorage: { - name: 'governor_counting', - type: 'GovernorCountingSimpleComponent::Storage', - }, - event: { - name: 'GovernorCountingSimpleEvent', - type: 'GovernorCountingSimpleComponent::Event', - }, - impls: [{ - name: 'GovernorCountingSimpleImpl', - value: 'GovernorCountingSimpleComponent::GovernorCounting', - embed: false, - section: extensionInternalSection, - }], - }, - GovernorCoreExecutionComponent: { - path: extensionPath, - substorage: { - name: 'governor_execution', - type: 'GovernorCoreExecutionComponent::Storage', - }, - event: { - name: 'GovernorCoreExecutionEvent', - type: 'GovernorCoreExecutionComponent::Event', - }, - impls: [{ - name: 'GovernorCoreExecutionImpl', - value: 'GovernorCoreExecutionComponent::GovernorExecution', - embed: false, - section: extensionInternalSection, - }], - }, - GovernorTimelockExecutionComponent: { - path: extensionPath, - substorage: { - name: 'governor_timelock_execution', - type: 'GovernorTimelockExecutionComponent::Storage', - }, - event: { - name: 'GovernorTimelockExecutionEvent', - type: 'GovernorTimelockExecutionComponent::Event', - }, - impls: [{ - name: 'TimelockedImpl', - value: 'GovernorTimelockExecutionComponent::TimelockedImpl', - section: extensionExternalSection, - }, { - name: 'GovernorTimelockExecutionImpl', - value: 'GovernorTimelockExecutionComponent::GovernorExecution', - embed: false, - section: extensionInternalSection, - }], - }, -}); - -function addBase(c: ContractBuilder, _: GovernorOptions) { - c.addUseClause('starknet', 'ContractAddress'); - c.addUseClause('openzeppelin::governance::governor', 'DefaultConfig'); - c.addConstructorArgument({ name: 'votes_token', type: 'ContractAddress' }); - c.addUseClause('openzeppelin::governance::governor::GovernorComponent', 'InternalTrait', { alias: 'GovernorInternalTrait' }); - c.addComponent(components.GovernorComponent, [], true); -} - -function addSettings(c: ContractBuilder, allOpts: Required) { - c.addConstant({ - name: 'VOTING_DELAY', - type: 'u64', - value: getVotingDelay(allOpts).toString(), - comment: allOpts.delay, - inlineComment: true, - }); - c.addConstant({ - name: 'VOTING_PERIOD', - type: 'u64', - value: getVotingPeriod(allOpts).toString(), - comment: allOpts.period, - inlineComment: true, - }); - c.addConstant({ - name: 'PROPOSAL_THRESHOLD', - type: 'u256', - ...getProposalThreshold(allOpts), - inlineComment: true, - }); - - if (allOpts.settings) { - c.addUseClause(`${extensionPath}::GovernorSettingsComponent`, 'InternalTrait', { alias: 'GovernorSettingsInternalTrait' }); - c.addComponent(components.GovernorSettingsComponent, [ - { lit: 'VOTING_DELAY' }, - { lit: 'VOTING_PERIOD' }, - { lit: 'PROPOSAL_THRESHOLD' }, - ], true); - } else { - addSettingsLocalImpl(c, allOpts); - } -} - -function getVotingDelay(opts: Required): number { - try { - if (opts.clockMode === 'timestamp') { - return durationToTimestamp(opts.delay); - } else { - throw new Error('Invalid clock mode'); - } - } catch (e) { - if (e instanceof Error) { - throw new OptionsError({ - delay: e.message, - }); - } else { - throw e; - } - } -} - -function getVotingPeriod(opts: Required): number { - try { - if (opts.clockMode === 'timestamp') { - return durationToTimestamp(opts.period); - } else { - throw new Error('Invalid clock mode'); - } - } catch (e) { - if (e instanceof Error) { - throw new OptionsError({ - period: e.message, - }); - } else { - throw e; - } - } -} - -function validateDecimals(decimals: number) { - if (!/^\d+$/.test(decimals.toString())) { - throw new OptionsError({ - decimals: 'Not a valid number', - }); - } -} - -function getProposalThreshold({ proposalThreshold, decimals, votes }: Required): {value: string, comment?: string} { - if (!/^\d+$/.test(proposalThreshold)) { - throw new OptionsError({ - proposalThreshold: 'Not a valid number', - }); - } - - if (/^0+$/.test(proposalThreshold) || decimals === 0 || votes === 'erc721votes') { - return { value: proposalThreshold }; - } else { - let value = `${BigInt(proposalThreshold)*BigInt(10)**BigInt(decimals)}`; - value = toUint(value, 'proposalThreshold', 'u256').toString(); - return { value: `${value}`, comment: `${proposalThreshold} * pow!(10, ${decimals})` }; - } -} - -function addSettingsLocalImpl(c: ContractBuilder, _: Required) { - const settingsTrait = { - name: 'GovernorSettings', - of: 'GovernorComponent::GovernorSettingsTrait', - tags: [], - section: 'Locally implemented extensions', - priority: 2, - }; - c.addImplementedTrait(settingsTrait); - - c.addFunction(settingsTrait, { - name: 'voting_delay', - args: [{ - name: 'self', - type: '@GovernorComponent::ComponentState' - }], - returns: 'u64', - code: ['VOTING_DELAY'], - }); - - c.addFunction(settingsTrait, { - name: 'voting_period', - args: [{ - name: 'self', - type: '@GovernorComponent::ComponentState' - }], - returns: 'u64', - code: ['VOTING_PERIOD'], - }); - - c.addFunction(settingsTrait, { - name: 'proposal_threshold', - args: [{ - name: 'self', - type: '@GovernorComponent::ComponentState' - }], - returns: 'u256', - code: ['PROPOSAL_THRESHOLD'], - }); -} - -function addQuorumAndVotes(c: ContractBuilder, allOpts: Required) { - if (allOpts.quorumMode === 'percent') { - if (allOpts.quorumPercent > 100) { - throw new OptionsError({ - quorumPercent: 'Invalid percentage', - }); - } - - addVotesQuorumFractionComponent(c, allOpts.quorumPercent); - } - else if (allOpts.quorumMode === 'absolute') { - if (!numberPattern.test(allOpts.quorumAbsolute)) { - throw new OptionsError({ - quorumAbsolute: 'Not a valid number', - }); - } - - let quorum: string; - let comment = ''; - if (allOpts.decimals === 0 || allOpts.votes === 'erc721votes') { - quorum = `${allOpts.quorumAbsolute}`; - } else { - quorum = `${BigInt(allOpts.quorumAbsolute)*BigInt(10)**BigInt(allOpts.decimals)}`; - quorum = toUint(quorum, 'quorumAbsolute', 'u256').toString(); - comment = `${allOpts.quorumAbsolute} * pow!(10, ${allOpts.decimals})`; - } - - addVotesComponent(c, allOpts); - addQuorumLocalImpl(c, quorum, comment); - } -} - -function addVotesQuorumFractionComponent(c: ContractBuilder, quorumNumerator: number) { - c.addConstant({ - name: 'QUORUM_NUMERATOR', - type: 'u256', - value: (quorumNumerator * 10).toString(), - comment: `${quorumNumerator}%`, - inlineComment: true, - }); - c.addUseClause(`${extensionPath}::GovernorVotesQuorumFractionComponent`, 'InternalTrait', { alias: 'GovernorVotesQuorumFractionInternalTrait' }); - c.addComponent(components.GovernorVotesQuorumFractionComponent, [ - { lit: 'votes_token' }, - { lit: 'QUORUM_NUMERATOR' }, - ], true); -} - -function addVotesComponent(c: ContractBuilder, _: Required) { - c.addUseClause(`${extensionPath}::GovernorVotesComponent`, 'InternalTrait', { alias: 'GovernorVotesInternalTrait' }); - c.addComponent(components.GovernorVotesComponent, [ - { lit: 'votes_token' }, - ], true); -} - -function addQuorumLocalImpl(c: ContractBuilder, quorum: string, comment: string) { - c.addConstant({ - name: 'QUORUM', - type: 'u256', - value: quorum, - comment, - inlineComment: true, - }); - const quorumTrait = { - name: 'GovernorQuorum', - of: 'GovernorComponent::GovernorQuorumTrait', - tags: [], - section: 'Locally implemented extensions', - priority: 1, - }; - c.addImplementedTrait(quorumTrait); - - c.addFunction(quorumTrait, { - name: 'quorum', - args: [{ - name: 'self', - type: '@GovernorComponent::ComponentState' - }, { - name: 'timepoint', - type: 'u64', - }], - returns: 'u256', - code: ['QUORUM'], - }); -} - -function addCounting(c: ContractBuilder, _: Required) { - c.addComponent(components.GovernorCountingSimpleComponent, [], false); -} - -function addExecution(c: ContractBuilder, { timelock }: Required) { - if (timelock === false) { - c.addComponent(components.GovernorCoreExecutionComponent, [], false); - } else { - c.addConstructorArgument({ name: 'timelock_controller', type: 'ContractAddress' }); - c.addUseClause(`${extensionPath}::GovernorTimelockExecutionComponent`, 'InternalTrait', { alias: 'GovernorTimelockExecutionInternalTrait' }); - c.addComponent(components.GovernorTimelockExecutionComponent, [ - { lit: 'timelock_controller' }, - ], true); - } -} - -export const numberPattern = /^(?!$)(\d*)(?:\.(\d+))?(?:e(\d+))?$/; diff --git a/packages/core/stylus/src/index.ts b/packages/core/stylus/src/index.ts index 5f102fabb..2b01422dc 100644 --- a/packages/core/stylus/src/index.ts +++ b/packages/core/stylus/src/index.ts @@ -7,7 +7,6 @@ export { ContractBuilder } from './contract'; export { printContract } from './print'; export type { Access } from './set-access-control'; -export type { Account } from './account'; export type { Upgradeable } from './set-upgradeable'; export type { Info } from './set-info'; export type { RoyaltyInfoOptions } from './set-royalty-info'; @@ -25,4 +24,4 @@ export { sanitizeKind } from './kind'; export { contractsVersion, contractsVersionTag, compatibleContractsSemver } from './utils/version'; -export { erc20, erc721, erc1155, account, governor, vesting, custom } from './api'; +export { erc20 } from './api'; diff --git a/packages/core/stylus/src/set-upgradeable.ts b/packages/core/stylus/src/set-upgradeable.ts index 65a944128..e96ccb272 100644 --- a/packages/core/stylus/src/set-upgradeable.ts +++ b/packages/core/stylus/src/set-upgradeable.ts @@ -3,7 +3,6 @@ import type { BaseImplementedTrait, ContractBuilder } from './contract'; import { Access, requireAccessControl } from './set-access-control'; import { defineComponents } from './utils/define-components'; import { defineFunctions } from './utils/define-functions'; -import type { Account } from './account'; export const upgradeableOptions = [false, true] as const; @@ -41,28 +40,6 @@ export function setUpgradeable(c: ContractBuilder, upgradeable: Upgradeable, acc } } -export function setUpgradeableGovernor(c: ContractBuilder, upgradeable: Upgradeable): void { - const trait = setUpgradeableBase(c, upgradeable); - if (trait !== undefined) { - c.addUseClause('openzeppelin::governance::governor::GovernorComponent', 'InternalExtendedImpl'); - c.addFunctionCodeBefore(trait, functions.upgrade, 'self.governor.assert_only_governance()'); - } -} - -export function setAccountUpgradeable(c: ContractBuilder, upgradeable: Upgradeable, type: Account): void { - const trait = setUpgradeableBase(c, upgradeable); - if (trait !== undefined) { - switch (type) { - case 'stark': - c.addFunctionCodeBefore(trait, functions.upgrade, 'self.account.assert_only_self()'); - break; - case 'eth': - c.addFunctionCodeBefore(trait, functions.upgrade, 'self.eth_account.assert_only_self()'); - break; - } - } -} - const components = defineComponents( { UpgradeableComponent: { path: 'openzeppelin::upgrades', diff --git a/packages/core/stylus/src/test.ts b/packages/core/stylus/src/test.ts index 967e17ece..948e6ba66 100644 --- a/packages/core/stylus/src/test.ts +++ b/packages/core/stylus/src/test.ts @@ -5,7 +5,7 @@ import path from 'path'; import { generateSources, writeGeneratedSources } from './generate/sources'; import type { GenericOptions, KindedOptions } from './build-generic'; -import { custom, erc20, erc721, erc1155 } from './api'; +import { erc20, } from './api'; interface Context { generatedSourcesPath: string @@ -17,22 +17,6 @@ test.serial('erc20 result generated', async t => { await testGenerate(t, 'ERC20'); }); -test.serial('erc721 result generated', async t => { - await testGenerate(t, 'ERC721'); -}); - -test.serial('erc1155 result generated', async t => { - await testGenerate(t, 'ERC1155'); -}); - -test.serial('account result generated', async t => { - await testGenerate(t, 'Account'); -}); - -test.serial('custom result generated', async t => { - await testGenerate(t, 'Custom'); -}); - async function testGenerate(t: ExecutionContext, kind: keyof KindedOptions) { const generatedSourcesPath = path.join(os.tmpdir(), 'oz-wizard-cairo'); await fs.rm(generatedSourcesPath, { force: true, recursive: true }); @@ -45,14 +29,6 @@ function isAccessControlRequired(opts: GenericOptions) { switch(opts.kind) { case 'ERC20': return erc20.isAccessControlRequired(opts); - case 'ERC721': - return erc721.isAccessControlRequired(opts); - case 'ERC1155': - return erc1155.isAccessControlRequired(opts); - case 'Account': - throw new Error("Not applicable for accounts"); - case 'Custom': - return custom.isAccessControlRequired(opts); default: throw new Error("No such kind"); } @@ -63,15 +39,7 @@ test('is access control required', async t => { const regexOwnable = /(use openzeppelin::access::ownable::OwnableComponent)/gm; switch (contract.options.kind) { - case 'Account': - case 'Governor': - case 'Vesting': - // These contracts have no access control option - break; case 'ERC20': - case 'ERC721': - case 'ERC1155': - case 'Custom': if (!contract.options.access) { if (isAccessControlRequired(contract.options)) { t.regex(contract.source, regexOwnable, JSON.stringify(contract.options)); @@ -81,7 +49,7 @@ test('is access control required', async t => { } break; default: - const _: never = contract.options; + const _: never = contract.options.kind; // TODO: When there are additional kinds above, change this assignment to just `contract.options` instead of `contract.options.kind` throw new Error('Unknown kind'); } } diff --git a/packages/core/stylus/src/vesting.test.ts b/packages/core/stylus/src/vesting.test.ts deleted file mode 100644 index 3f9ead374..000000000 --- a/packages/core/stylus/src/vesting.test.ts +++ /dev/null @@ -1,119 +0,0 @@ -import test from 'ava'; -import { OptionsError, vesting } from '.'; -import { buildVesting, VestingOptions } from './vesting'; -import { printContract } from './print'; - -const defaults: VestingOptions = { - name: 'MyVesting', - startDate: '', - duration: '0 day', - cliffDuration: '0 day', - schedule: 'linear' -}; - -const CUSTOM_NAME = 'CustomVesting'; -const CUSTOM_DATE = '2024-12-31T23:59'; -const CUSTOM_DURATION = '36 months'; -const CUSTOM_CLIFF = '90 days'; - -// -// Test helpers -// - -function testVesting(title: string, opts: Partial) { - test(title, t => { - const c = buildVesting({ - ...defaults, - ...opts - }); - t.snapshot(printContract(c)); - }); -} - -function testAPIEquivalence(title: string, opts?: VestingOptions) { - test(title, t => { - t.is(vesting.print(opts), printContract(buildVesting({ - ...defaults, - ...opts - }))); - }); -} - -// -// Snapshot tests -// - -testVesting('custom name', { - name: CUSTOM_NAME, -}); - -testVesting('custom start date', { - startDate: CUSTOM_DATE -}); - -testVesting('custom duration', { - duration: CUSTOM_DURATION -}); - -testVesting('custom cliff', { - duration: CUSTOM_DURATION, - cliffDuration: CUSTOM_CLIFF -}); - -testVesting('custom schedule', { - schedule: 'custom' -}); - -testVesting('all custom settings', { - startDate: CUSTOM_DATE, - duration: CUSTOM_DURATION, - cliffDuration: CUSTOM_CLIFF, - schedule: 'custom' -}); - -// -// API tests -// - -testAPIEquivalence('API custom name', { - ...defaults, - name: CUSTOM_NAME -}); - -testAPIEquivalence('API custom start date', { - ...defaults, - startDate: CUSTOM_DATE -}); - -testAPIEquivalence('API custom duration', { - ...defaults, - duration: CUSTOM_DURATION -}); - -testAPIEquivalence('API custom cliff', { - ...defaults, - duration: CUSTOM_DURATION, - cliffDuration: CUSTOM_CLIFF -}); - -testAPIEquivalence('API custom schedule', { - ...defaults, - schedule: 'custom' -}); - -testAPIEquivalence('API all custom settings', { - ...defaults, - startDate: CUSTOM_DATE, - duration: CUSTOM_DURATION, - cliffDuration: CUSTOM_CLIFF, - schedule: 'custom' -}); - -test('cliff too high', async t => { - const error = t.throws(() => buildVesting({ - ...defaults, - duration: '20 days', - cliffDuration: '21 days' - })); - t.is((error as OptionsError).messages.cliffDuration, 'Cliff duration must be less than or equal to the total duration'); -}); diff --git a/packages/core/stylus/src/vesting.test.ts.md b/packages/core/stylus/src/vesting.test.ts.md deleted file mode 100644 index 6c35d8c65..000000000 --- a/packages/core/stylus/src/vesting.test.ts.md +++ /dev/null @@ -1,365 +0,0 @@ -# Snapshot report for `src/vesting.test.ts` - -The actual snapshot is saved in `vesting.test.ts.snap`. - -Generated by [AVA](https://avajs.dev). - -## custom name - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod CustomVesting {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::finance::vesting::{LinearVestingSchedule, VestingComponent};␊ - use starknet::ContractAddress;␊ - ␊ - const START: u64 = 0;␊ - const DURATION: u64 = 0; // 0 day␊ - const CLIFF_DURATION: u64 = 0; // 0 day␊ - ␊ - component!(path: VestingComponent, storage: vesting, event: VestingEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl VestingImpl = VestingComponent::VestingImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl VestingInternalImpl = VestingComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - vesting: VestingComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - VestingEvent: VestingComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.vesting.initializer(START, DURATION, CLIFF_DURATION);␊ - self.ownable.initializer(owner);␊ - }␊ - }␊ - ` - -## custom start date - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyVesting {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::finance::vesting::{LinearVestingSchedule, VestingComponent};␊ - use starknet::ContractAddress;␊ - ␊ - const START: u64 = 1735689540; // 31 Dec 2024, 23:59 (UTC)␊ - const DURATION: u64 = 0; // 0 day␊ - const CLIFF_DURATION: u64 = 0; // 0 day␊ - ␊ - component!(path: VestingComponent, storage: vesting, event: VestingEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl VestingImpl = VestingComponent::VestingImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl VestingInternalImpl = VestingComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - vesting: VestingComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - VestingEvent: VestingComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.vesting.initializer(START, DURATION, CLIFF_DURATION);␊ - self.ownable.initializer(owner);␊ - }␊ - }␊ - ` - -## custom duration - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyVesting {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::finance::vesting::{LinearVestingSchedule, VestingComponent};␊ - use starknet::ContractAddress;␊ - ␊ - const START: u64 = 0;␊ - const DURATION: u64 = 93312000; // 36 months␊ - const CLIFF_DURATION: u64 = 0; // 0 day␊ - ␊ - component!(path: VestingComponent, storage: vesting, event: VestingEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl VestingImpl = VestingComponent::VestingImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl VestingInternalImpl = VestingComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - vesting: VestingComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - VestingEvent: VestingComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.vesting.initializer(START, DURATION, CLIFF_DURATION);␊ - self.ownable.initializer(owner);␊ - }␊ - }␊ - ` - -## custom cliff - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyVesting {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::finance::vesting::{LinearVestingSchedule, VestingComponent};␊ - use starknet::ContractAddress;␊ - ␊ - const START: u64 = 0;␊ - const DURATION: u64 = 93312000; // 36 months␊ - const CLIFF_DURATION: u64 = 7776000; // 90 days␊ - ␊ - component!(path: VestingComponent, storage: vesting, event: VestingEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl VestingImpl = VestingComponent::VestingImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl VestingInternalImpl = VestingComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - vesting: VestingComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - VestingEvent: VestingComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.vesting.initializer(START, DURATION, CLIFF_DURATION);␊ - self.ownable.initializer(owner);␊ - }␊ - }␊ - ` - -## custom schedule - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyVesting {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::finance::vesting::VestingComponent;␊ - use starknet::ContractAddress;␊ - ␊ - const START: u64 = 0;␊ - const DURATION: u64 = 0; // 0 day␊ - const CLIFF_DURATION: u64 = 0; // 0 day␊ - ␊ - component!(path: VestingComponent, storage: vesting, event: VestingEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl VestingImpl = VestingComponent::VestingImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl VestingInternalImpl = VestingComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - vesting: VestingComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - VestingEvent: VestingComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.vesting.initializer(START, DURATION, CLIFF_DURATION);␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - impl VestingSchedule of VestingComponent::VestingScheduleTrait {␊ - fn calculate_vested_amount(␊ - self: @VestingComponent::ComponentState,␊ - token: ContractAddress,␊ - total_allocation: u256,␊ - timestamp: u64,␊ - start: u64,␊ - duration: u64,␊ - cliff: u64,␊ - ) -> u256 {␊ - // TODO: Must be implemented according to the desired vesting schedule;␊ - 0␊ - }␊ - }␊ - }␊ - ` - -## all custom settings - -> Snapshot 1 - - `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ - ␊ - #[starknet::contract]␊ - mod MyVesting {␊ - use openzeppelin::access::ownable::OwnableComponent;␊ - use openzeppelin::finance::vesting::VestingComponent;␊ - use starknet::ContractAddress;␊ - ␊ - const START: u64 = 1735689540; // 31 Dec 2024, 23:59 (UTC)␊ - const DURATION: u64 = 93312000; // 36 months␊ - const CLIFF_DURATION: u64 = 7776000; // 90 days␊ - ␊ - component!(path: VestingComponent, storage: vesting, event: VestingEvent);␊ - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ - ␊ - // External␊ - #[abi(embed_v0)]␊ - impl VestingImpl = VestingComponent::VestingImpl;␊ - #[abi(embed_v0)]␊ - impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ - ␊ - // Internal␊ - impl VestingInternalImpl = VestingComponent::InternalImpl;␊ - impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ - ␊ - #[storage]␊ - struct Storage {␊ - #[substorage(v0)]␊ - vesting: VestingComponent::Storage,␊ - #[substorage(v0)]␊ - ownable: OwnableComponent::Storage,␊ - }␊ - ␊ - #[event]␊ - #[derive(Drop, starknet::Event)]␊ - enum Event {␊ - #[flat]␊ - VestingEvent: VestingComponent::Event,␊ - #[flat]␊ - OwnableEvent: OwnableComponent::Event,␊ - }␊ - ␊ - #[constructor]␊ - fn constructor(ref self: ContractState, owner: ContractAddress) {␊ - self.vesting.initializer(START, DURATION, CLIFF_DURATION);␊ - self.ownable.initializer(owner);␊ - }␊ - ␊ - impl VestingSchedule of VestingComponent::VestingScheduleTrait {␊ - fn calculate_vested_amount(␊ - self: @VestingComponent::ComponentState,␊ - token: ContractAddress,␊ - total_allocation: u256,␊ - timestamp: u64,␊ - start: u64,␊ - duration: u64,␊ - cliff: u64,␊ - ) -> u256 {␊ - // TODO: Must be implemented according to the desired vesting schedule;␊ - 0␊ - }␊ - }␊ - }␊ - ` diff --git a/packages/core/stylus/src/vesting.test.ts.snap b/packages/core/stylus/src/vesting.test.ts.snap deleted file mode 100644 index 7051100b2580ab1369a3d8e9432ec7fd87aa4d36..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1105 zcmV-X1g`r*RzVPLXUN`C3sw`s7su8yLR9vo| z$7T{xX00a$?DM3TElv@4z-t(xYKi$52YioNe`F--)))$|Ce!Ja<>Gz`_ zcTSj#LgCKXL!p_^Fd}d|o;BKS7|I}|nk_iOE2ft)2~qrvVThaw7)qfd>S_hPj9^Gv zB;l9NZnv}BX*BLXSDHrW0yQD7F+6Jo(t}~@5M?!--n0L85DX(&z>I7#*^Isa}!|#~n~wM)U;|FhM(j7btXY`Z&334eI5pnJvhf?B{aEG?Pp9+HH9J zT4N+APw($Prwi7^V1eHJqSHD{8(9$Y%$ad={cs}+LJIxgWO<)zs`1g_Z*>tgco?w@Y>pxsI)$ybUS(?|6mbA) zLn$hsQ+?@0ak1A0ly*2*K3-hhb&(Vv&*Mlpa*}izt%ZC6g|=pdJ}BfqfztdrNyd_M zwsO3*3ehEx?V9P?WrAr&IeUvyGd*^k{ETrb=ZM+nxrCXUl0-VXF5!FnJ8p_-&QRYiand^B`IqLQHx}A;zP#*#*^io-tSe96pSeD#G zmT(7i79_< ze+*2it|a@h#B#!N!gAtcB{mfgpnkKayRBw<2(rmy*UkJ zEOaxs$$Ta7?dEX#Whz}6$SG-Pd5&TusZ|?I`J8et-Sm$-0&(}CU$J2UDoukhJ(J6Q z>4&76_Uwdf6_{0Y4~dcJjMbwK7nYbI7U#)QO1NtPbvcU8)Ygx?`(@YyS>r-#%?sVXF#T XRoJQmY*hg_w5s?EHmH{kzbOC!Gxr?8 diff --git a/packages/core/stylus/src/vesting.ts b/packages/core/stylus/src/vesting.ts deleted file mode 100644 index 51c6512f2..000000000 --- a/packages/core/stylus/src/vesting.ts +++ /dev/null @@ -1,219 +0,0 @@ -import { BaseImplementedTrait, Contract, ContractBuilder } from './contract'; -import { contractDefaults as commonDefaults } from './common-options'; -import { setAccessControl } from './set-access-control'; -import { setUpgradeable } from './set-upgradeable'; -import { Info, setInfo } from './set-info'; -import { defineComponents } from './utils/define-components'; -import { printContract } from './print'; -import { OptionsError } from './error'; -import { durationToTimestamp } from './utils/duration'; -import { toUint, validateUint } from './utils/convert-strings'; - -export type VestingSchedule = 'linear' | 'custom'; - -export const defaults: Required = { - name: 'VestingWallet', - startDate: '', - duration: '0 day', - cliffDuration: '0 day', - schedule: 'custom', - info: commonDefaults.info -} as const; - -export function printVesting(opts: VestingOptions = defaults): string { - return printContract(buildVesting(opts)); -} - -export interface VestingOptions { - name: string; - startDate: string; - duration: string; - cliffDuration: string; - schedule: VestingSchedule; - info?: Info; -} - -function withDefaults(opts: VestingOptions): Required { - return { - name: opts.name ?? defaults.name, - startDate: opts.startDate ?? defaults.startDate, - duration: opts.duration ?? defaults.duration, - cliffDuration: opts.cliffDuration ?? defaults.cliffDuration, - schedule: opts.schedule ?? defaults.schedule, - info: opts.info ?? defaults.info - }; -} - -export function buildVesting(opts: VestingOptions): Contract { - const c = new ContractBuilder(opts.name); - const allOpts = withDefaults(opts); - - addBase(c, opts); - addSchedule(c, opts); - setInfo(c, allOpts.info); - - // Vesting component depends on Ownable component - const access = 'ownable'; - setAccessControl(c, access); - - // Must be non-upgradable to guarantee vesting according to the schedule - setUpgradeable(c, false, access); - - return c; -} - -function addBase(c: ContractBuilder, opts: VestingOptions) { - c.addUseClause('starknet', 'ContractAddress'); - const startDate = getVestingStart(opts); - const totalDuration = getVestingDuration(opts); - const cliffDuration = getCliffDuration(opts); - validateDurations(totalDuration, cliffDuration); - if (startDate !== undefined) { - c.addConstant({ - name: 'START', - type: 'u64', - value: startDate.timestampInSec.toString(), - comment: startDate.formattedDate, - inlineComment: true - }); - } else { - c.addConstant({ - name: 'START', - type: 'u64', - value: '0' - }); - } - c.addConstant({ - name: 'DURATION', - type: 'u64', - value: totalDuration.toString(), - comment: opts.duration, - inlineComment: true - }); - c.addConstant({ - name: 'CLIFF_DURATION', - type: 'u64', - value: cliffDuration.toString(), - comment: opts.cliffDuration, - inlineComment: true - }); - const initParams = [{ lit: 'START' }, { lit: 'DURATION' }, { lit: 'CLIFF_DURATION' }]; - c.addComponent(components.VestingComponent, initParams, true); -} - -function addSchedule(c: ContractBuilder, opts: VestingOptions) { - switch (opts.schedule) { - case 'linear': - c.addUseClause('openzeppelin::finance::vesting', 'LinearVestingSchedule'); - return; - case 'custom': - const scheduleTrait: BaseImplementedTrait = { - name: `VestingSchedule`, - of: 'VestingComponent::VestingScheduleTrait', - tags: [], - priority: 0, - }; - c.addImplementedTrait(scheduleTrait); - c.addFunction(scheduleTrait, { - name: 'calculate_vested_amount', - returns: 'u256', - args: [ - { name: 'self', type: `@VestingComponent::ComponentState` }, - { name: 'token', type: 'ContractAddress' }, - { name: 'total_allocation', type: 'u256' }, - { name: 'timestamp', type: 'u64' }, - { name: 'start', type: 'u64' }, - { name: 'duration', type: 'u64' }, - { name: 'cliff', type: 'u64' } - ], - code: [ - '// TODO: Must be implemented according to the desired vesting schedule', - '0', - ], - }); - return; - } -} - -function getVestingStart(opts: VestingOptions): { timestampInSec: bigint, formattedDate: string } | undefined { - if (opts.startDate === '' || opts.startDate === 'NaN') { - return undefined; - } - const startDate = new Date(`${opts.startDate}Z`); - const timestampInMillis = startDate.getTime(); - const timestampInSec = toUint( - Math.floor(timestampInMillis / 1000), - 'startDate', - 'u64' - ); - const formattedDate = startDate.toLocaleString('en-GB', { - day: '2-digit', - month: 'short', - year: 'numeric', - hour: '2-digit', - minute: '2-digit', - hour12: false, - timeZone: 'UTC' - }); - return { timestampInSec, formattedDate: `${formattedDate} (UTC)` }; -} - -function getVestingDuration(opts: VestingOptions): number { - try { - return durationToTimestamp(opts.duration); - } catch (e) { - if (e instanceof Error) { - throw new OptionsError({ - duration: e.message - }); - } else { - throw e; - } - } -} - -function getCliffDuration(opts: VestingOptions): number { - try { - return durationToTimestamp(opts.cliffDuration); - } catch (e) { - if (e instanceof Error) { - throw new OptionsError({ - cliffDuration: e.message - }); - } else { - throw e; - } - } -} - -function validateDurations(duration: number, cliffDuration: number): void { - validateUint(duration, 'duration', 'u64'); - validateUint(cliffDuration, 'cliffDuration', 'u64'); - if (cliffDuration > duration) { - throw new OptionsError({ - cliffDuration: `Cliff duration must be less than or equal to the total duration` - }); - } -} - -const components = defineComponents({ - VestingComponent: { - path: 'openzeppelin::finance::vesting', - substorage: { - name: 'vesting', - type: 'VestingComponent::Storage', - }, - event: { - name: 'VestingEvent', - type: 'VestingComponent::Event', - }, - impls: [{ - name: 'VestingImpl', - value: 'VestingComponent::VestingImpl' - }, { - name: 'VestingInternalImpl', - embed: false, - value: 'VestingComponent::InternalImpl', - }], - } -}); diff --git a/packages/ui/src/stylus/App.svelte b/packages/ui/src/stylus/App.svelte index 65fac4d03..165c17725 100644 --- a/packages/ui/src/stylus/App.svelte +++ b/packages/ui/src/stylus/App.svelte @@ -4,11 +4,6 @@ import hljs from './highlightjs'; import ERC20Controls from './ERC20Controls.svelte'; - import ERC721Controls from './ERC721Controls.svelte'; - import ERC1155Controls from './ERC1155Controls.svelte'; - import CustomControls from './CustomControls.svelte'; - import AccountControls from './AccountControls.svelte'; - import GovernorControls from './GovernorControls.svelte'; import CopyIcon from '../common/icons/CopyIcon.svelte'; import CheckIcon from '../common/icons/CheckIcon.svelte'; import DownloadIcon from '../common/icons/DownloadIcon.svelte'; @@ -23,7 +18,6 @@ import { saveAs } from 'file-saver'; import { injectHyperlinks } from './inject-hyperlinks'; import { InitialOptions } from '../common/initial-options'; - import VestingControls from './VestingControls.svelte'; const dispatch = createEventDispatcher(); @@ -52,12 +46,6 @@ switch (opts.kind) { case 'ERC20': opts.premint = initialOpts.premint ?? opts.premint; - case 'ERC721': - opts.symbol = initialOpts.symbol ?? opts.symbol; - break; - case 'Vesting': - case 'ERC1155': - case 'Custom': } initialValuesSet = true; } @@ -109,18 +97,6 @@ - - - - @@ -143,7 +119,7 @@

    Single file

    -

    Requires a Scarb project with openzeppelin as a dependency.

    +

    Requires a Rust project with openzeppelin-stylus as a dependency.

    @@ -155,24 +131,6 @@
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    {@html highlightedCode}
    diff --git a/packages/ui/src/stylus/CustomControls.svelte b/packages/ui/src/stylus/CustomControls.svelte deleted file mode 100644 index 759d1d6d2..000000000 --- a/packages/ui/src/stylus/CustomControls.svelte +++ /dev/null @@ -1,52 +0,0 @@ - - -
    -

    Settings

    - - -
    - -
    -

    Features

    - -
    - - - -
    - -
    - - - - \ No newline at end of file diff --git a/packages/ui/src/stylus/ERC1155Controls.svelte b/packages/ui/src/stylus/ERC1155Controls.svelte deleted file mode 100644 index fd1b9bcea..000000000 --- a/packages/ui/src/stylus/ERC1155Controls.svelte +++ /dev/null @@ -1,80 +0,0 @@ - - -
    -

    Settings

    - - - -
    - -
    -

    Features

    - -
    - - - - - -
    -
    - - - - - - diff --git a/packages/ui/src/stylus/ERC20Controls.svelte b/packages/ui/src/stylus/ERC20Controls.svelte index c8215b7e8..0b46ed8eb 100644 --- a/packages/ui/src/stylus/ERC20Controls.svelte +++ b/packages/ui/src/stylus/ERC20Controls.svelte @@ -73,8 +73,6 @@ Useful for emergency response. - -
    diff --git a/packages/ui/src/stylus/ERC721Controls.svelte b/packages/ui/src/stylus/ERC721Controls.svelte deleted file mode 100644 index f78bea66e..000000000 --- a/packages/ui/src/stylus/ERC721Controls.svelte +++ /dev/null @@ -1,118 +0,0 @@ - - -
    -

    Settings

    - -
    - - -
    - -
    - -
    -

    Features

    - -
    - - - - - -
    -
    - -
    -

    - - -

    - - - - -
    - - - - - - \ No newline at end of file diff --git a/packages/ui/src/stylus/RoyaltyInfoSection.svelte b/packages/ui/src/stylus/RoyaltyInfoSection.svelte deleted file mode 100644 index e99dbea94..000000000 --- a/packages/ui/src/stylus/RoyaltyInfoSection.svelte +++ /dev/null @@ -1,42 +0,0 @@ - - -
    -

    - - -

    - - - - -
    diff --git a/packages/ui/src/stylus/UpgradeabilityField.svelte b/packages/ui/src/stylus/UpgradeabilityField.svelte deleted file mode 100644 index 239957228..000000000 --- a/packages/ui/src/stylus/UpgradeabilityField.svelte +++ /dev/null @@ -1,15 +0,0 @@ - - - diff --git a/packages/ui/src/stylus/VestingControls.svelte b/packages/ui/src/stylus/VestingControls.svelte deleted file mode 100644 index c136b219a..000000000 --- a/packages/ui/src/stylus/VestingControls.svelte +++ /dev/null @@ -1,68 +0,0 @@ - - -
    -

    Settings

    - - - - - - - -
    - -
    -

    Vesting Schedule

    -
    - - -
    -
    - - From d44d54cd73c9398051bd2ca79baa2c56b2fd21de Mon Sep 17 00:00:00 2001 From: makiopen Date: Wed, 5 Feb 2025 16:32:57 +0100 Subject: [PATCH 010/117] new icons plus styling --- packages/ui/public/cairo.html | 12 +-- packages/ui/public/icons/cairo.svg | 3 + packages/ui/public/icons/solidity.svg | 8 ++ packages/ui/public/icons/stylus.svg | 3 + packages/ui/public/index.html | 12 +-- packages/ui/public/logo.svg | 30 +++---- packages/ui/public/stylus.html | 12 +-- packages/ui/src/cairo/App.svelte | 16 ++-- packages/ui/src/common/styles/global.css | 10 ++- packages/ui/src/solidity/App.svelte | 24 ++++-- packages/ui/src/standalone.css | 101 +++++++++++++++-------- packages/ui/src/stylus/App.svelte | 16 ++-- 12 files changed, 163 insertions(+), 84 deletions(-) create mode 100644 packages/ui/public/icons/cairo.svg create mode 100644 packages/ui/public/icons/solidity.svg create mode 100644 packages/ui/public/icons/stylus.svg diff --git a/packages/ui/public/cairo.html b/packages/ui/public/cairo.html index d4038ebe3..58c81642e 100644 --- a/packages/ui/public/cairo.html +++ b/packages/ui/public/cairo.html @@ -41,10 +41,7 @@
    - OpenZeppelin - Solidity - Cairo - Stylus +
    Forum @@ -53,8 +50,13 @@ Twitter
    - +
    +
    diff --git a/packages/ui/public/icons/cairo.svg b/packages/ui/public/icons/cairo.svg new file mode 100644 index 000000000..63b33ffe6 --- /dev/null +++ b/packages/ui/public/icons/cairo.svg @@ -0,0 +1,3 @@ + + + diff --git a/packages/ui/public/icons/solidity.svg b/packages/ui/public/icons/solidity.svg new file mode 100644 index 000000000..0da2609ab --- /dev/null +++ b/packages/ui/public/icons/solidity.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/packages/ui/public/icons/stylus.svg b/packages/ui/public/icons/stylus.svg new file mode 100644 index 000000000..8361d7986 --- /dev/null +++ b/packages/ui/public/icons/stylus.svg @@ -0,0 +1,3 @@ + + + diff --git a/packages/ui/public/index.html b/packages/ui/public/index.html index a73e16454..5c04dc31d 100644 --- a/packages/ui/public/index.html +++ b/packages/ui/public/index.html @@ -73,10 +73,7 @@
    - OpenZeppelin - Solidity - Cairo - Stylus +
    Forum @@ -85,8 +82,13 @@ Twitter
    - +
    +
    diff --git a/packages/ui/public/logo.svg b/packages/ui/public/logo.svg index f1e14c2bb..6654d3f69 100644 --- a/packages/ui/public/logo.svg +++ b/packages/ui/public/logo.svg @@ -1,15 +1,17 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/packages/ui/public/stylus.html b/packages/ui/public/stylus.html index 849196dac..de0174034 100644 --- a/packages/ui/public/stylus.html +++ b/packages/ui/public/stylus.html @@ -41,10 +41,7 @@
    - OpenZeppelin - Solidity - Cairo - Stylus +
    Forum @@ -53,8 +50,13 @@ Twitter
    - +
    +
    diff --git a/packages/ui/src/cairo/App.svelte b/packages/ui/src/cairo/App.svelte index f14edf475..518ce16a6 100644 --- a/packages/ui/src/cairo/App.svelte +++ b/packages/ui/src/cairo/App.svelte @@ -142,7 +142,7 @@ - @@ -183,7 +183,7 @@
    -
    {@html highlightedCode}
    +
    {@html highlightedCode}
    @@ -204,9 +204,9 @@ .tab button, :global(.overflow-btn) { padding: var(--size-2) var(--size-3); - border-radius: 12px; - font-weight: bold; + border-radius: 20px; cursor: pointer; + transition: background-color ease-in-out .2s; } .tab button, :global(.overflow-btn) { @@ -215,8 +215,12 @@ } .action-button { - padding: var(--size-2); - border-radius: 12px; + padding: 7px; + border-radius: 20px; + transition: background-color ease-in-out .2s; + } + .with-text { + padding-right: var(--size-3); } .tab button:hover, :global(.overflow-btn):hover { diff --git a/packages/ui/src/common/styles/global.css b/packages/ui/src/common/styles/global.css index 3ccefb126..db2113924 100644 --- a/packages/ui/src/common/styles/global.css +++ b/packages/ui/src/common/styles/global.css @@ -139,6 +139,14 @@ input.input-inline { background: conic-gradient(rgb(196, 181, 253), rgb(110, 231, 183), rgb(249, 168, 212)) } -.hljs{ +.hljs.-solidity{ background: linear-gradient(30deg, #151a24, #2b323e); +} + +.hljs.-cairo{ + background: linear-gradient(30deg, #191717, #2a0f0f); +} + +.hljs.-stylus{ + background: linear-gradient(30deg, #181215, #360c1f); } \ No newline at end of file diff --git a/packages/ui/src/solidity/App.svelte b/packages/ui/src/solidity/App.svelte index 986d5f539..7801d0f1c 100644 --- a/packages/ui/src/solidity/App.svelte +++ b/packages/ui/src/solidity/App.svelte @@ -193,9 +193,10 @@
    - +
    + @@ -347,7 +348,7 @@
    -        {@html highlightedCode}
    +        {@html highlightedCode}
           
    @@ -460,13 +461,22 @@ .tab button, :global(.overflow-btn) { padding: var(--size-2) var(--size-4); - border-radius: 12px; - font-weight: bold; + border-radius: 20px; cursor: pointer; + transition: background-color ease-in-out .2s; } .action-button { - padding: var(--size-2); - border-radius: 12px; + padding: 7px; + border-radius: 20px; + transition: background-color ease-in-out .2s; + } + + .with-text { + padding-right: var(--size-3); + } + + .tab button{ + } .tab button, :global(.overflow-btn) { diff --git a/packages/ui/src/standalone.css b/packages/ui/src/standalone.css index f6ec7fac9..804c9f05b 100644 --- a/packages/ui/src/standalone.css +++ b/packages/ui/src/standalone.css @@ -41,11 +41,14 @@ body { font-style: normal; } +.logo { + width: 161px; +} + /* Header */ .header { text-align: left; - padding: 1.5rem 1rem 1.5rem; - margin: 0 0 14rem; + padding: 1.5rem 1rem 1rem; font-family: 'silka', Arial, Helvetica, sans-serif; background: white; display: flex; @@ -56,63 +59,91 @@ body { margin: 0 2rem 0; } -.header .switch { - --color-1: var(--solidity-blue-1); - --color-2: var(--solidity-blue-2); +.header .link { + color: var(--text-color); display: block; - background: linear-gradient(to right, var(--color-1), var(--color-2)); - font-size: 1.1rem; + background: white; + font-size: 1rem; + line-height: 1; + font-weight: 500; + text-decoration: none; + padding: 1rem 0.5rem; + width: fit-content; +} + +/* Navigation */ +.nav { + text-align: left; + margin: 1rem auto; + font-family: 'silka', Arial, Helvetica, sans-serif; + background: var(--gray-1); + display: flex; + flex-direction: row; + border-radius: 5rem; + width: fit-content; +} + +.nav img{ + margin-right:4px; +} + +.nav .switch { + --color-1: var(--solidity-blue-1); + --color-2: #6C6F88; + display: flex; + align-items:center; + font-size: 14.7px; + font-family: var(--sans-serif); line-height: 1; - color: white; + color: var(--color-2); font-weight: 500; text-transform: none; text-decoration: none; - border-radius: 0.5rem; - padding: 0.5rem 0.5rem; + border-radius: 5rem; + padding: 0.5rem 1rem; width: fit-content; margin: 0.5rem; - border-radius: 0.5rem; + border-radius: 5rem; white-space: nowrap; + transition: background-color ease-in-out .3s; } -.header .switch.switch-off:not(:hover, :focus) { - color: transparent; - background-clip: text; - box-shadow: 0 0 0 1px var(--color-2) inset; +.nav .switch:hover { + background-color: var(--gray-2); } -.header .switch.switch-solidity { - --color-1: var(--solidity-blue-1); - --color-2: var(--solidity-blue-2); +.active{ + background-color: white; } -.header .switch.switch-cairo { - --color-1: var(--cairo-orange-1); - --color-2: var(--cairo-orange-2); +.nav .switch.switch-solidity.active{ + --color-2: #2A2477; +} +.nav .switch.switch-solidity.active img{ + filter: brightness(0) saturate(100%) invert(11%) sepia(51%) saturate(5259%) hue-rotate(243deg) brightness(80%) contrast(92%); } -.header .switch.switch-stylus { - --color-1: var(--stylus-pink-1); - --color-2: var(--stylus-pink-2); +.nav .switch.switch-cairo.active { + --color-2: #EB5951; +} +.nav .switch.switch-cairo.active img{ + filter: brightness(0) saturate(100%) invert(61%) sepia(90%) saturate(4391%) hue-rotate(331deg) brightness(98%) contrast(87%) } -.header .link { - color: var(--text-color); - display: block; - background: white; - font-size: 1rem; - line-height: 1; - font-weight: 500; - text-decoration: none; - padding: 1rem 0.5rem; - width: fit-content; +.nav .switch.switch-stylus.active { + --color-2: #E3126F; +} +.nav .switch.switch-stylus.active img{ + filter: brightness(0) saturate(100%) invert(16%) sepia(96%) saturate(4083%) hue-rotate(323deg) brightness(91%) contrast(96%) } + + /* Wizard */ .wizard-container { padding: 0 1rem 1.5rem; max-width: 100%; - margin: -12rem auto 0; + margin: 0 auto 0; } .wizard { min-width: 800px; diff --git a/packages/ui/src/stylus/App.svelte b/packages/ui/src/stylus/App.svelte index 165c17725..73e5a2e10 100644 --- a/packages/ui/src/stylus/App.svelte +++ b/packages/ui/src/stylus/App.svelte @@ -110,7 +110,7 @@ - @@ -133,7 +133,7 @@
    -
    {@html highlightedCode}
    +
    {@html highlightedCode}
    @@ -154,9 +154,9 @@ .tab button, :global(.overflow-btn) { padding: var(--size-2) var(--size-3); - border-radius: 12px; - font-weight: bold; + border-radius: 20px; cursor: pointer; + transition: background-color ease-in-out .2s; } .tab button, :global(.overflow-btn) { @@ -165,8 +165,12 @@ } .action-button { - padding: var(--size-2); - border-radius: 12px; + padding: 7px; + border-radius: 20px; + transition: background-color ease-in-out .2s; + } + .with-text { + padding-right: var(--size-3); } .tab button:hover, :global(.overflow-btn):hover { From d1f7345bb76166f8a5b6eb2a87ea2bea8b6e16b7 Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Wed, 5 Feb 2025 11:26:22 -0500 Subject: [PATCH 011/117] Remove unused colors --- packages/ui/src/cairo/App.svelte | 2 +- packages/ui/src/common/styles/vars.css | 6 ++---- packages/ui/src/stylus/App.svelte | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/ui/src/cairo/App.svelte b/packages/ui/src/cairo/App.svelte index 518ce16a6..0cfc9b636 100644 --- a/packages/ui/src/cairo/App.svelte +++ b/packages/ui/src/cairo/App.svelte @@ -228,7 +228,7 @@ } .tab button.selected { - background-color: var(--cairo-orange-2); + background-color: var(--cairo-orange); color: white; order: -1; } diff --git a/packages/ui/src/common/styles/vars.css b/packages/ui/src/common/styles/vars.css index 991899453..e17741501 100644 --- a/packages/ui/src/common/styles/vars.css +++ b/packages/ui/src/common/styles/vars.css @@ -29,11 +29,9 @@ --solidity-blue-1: #51d4ff; --solidity-blue-2: #4e5de4; - --cairo-orange-1: #fe9149; - --cairo-orange-2: #fe4a3c; + --cairo-orange: #fe4a3c; - --stylus-pink-1: #e3066e; - --stylus-pink-2: #a3034e; + --stylus-pink: #e3066e; /* Dimensions (scale taken from Tailwind) */ diff --git a/packages/ui/src/stylus/App.svelte b/packages/ui/src/stylus/App.svelte index 73e5a2e10..b6ff850cb 100644 --- a/packages/ui/src/stylus/App.svelte +++ b/packages/ui/src/stylus/App.svelte @@ -178,7 +178,7 @@ } .tab button.selected { - background-color: var(--stylus-pink-1); + background-color: var(--stylus-pink); color: white; order: -1; } From 192562c2cf9ab4b6aadab27fb5a75f9b5a599e26 Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Wed, 5 Feb 2025 15:46:57 -0500 Subject: [PATCH 012/117] Add placeholders for Stellar --- packages/core/stellar/.gitignore | 4 + packages/core/stellar/CHANGELOG.md | 5 + packages/core/stellar/LICENSE | 661 +++++++ packages/core/stellar/NOTICE | 8 + packages/core/stellar/README.md | 63 + packages/core/stellar/ava.config.js | 13 + packages/core/stellar/package.json | 32 + packages/core/stellar/src/add-pausable.ts | 58 + packages/core/stellar/src/api.ts | 42 + packages/core/stellar/src/build-generic.ts | 18 + .../core/stellar/src/common-components.ts | 109 ++ packages/core/stellar/src/common-options.ts | 46 + packages/core/stellar/src/contract.test.ts | 112 ++ packages/core/stellar/src/contract.test.ts.md | 191 ++ .../core/stellar/src/contract.test.ts.snap | Bin 0 -> 720 bytes packages/core/stellar/src/contract.ts | 292 +++ packages/core/stellar/src/erc20.test.ts | 189 ++ packages/core/stellar/src/erc20.test.ts.md | 1674 +++++++++++++++++ packages/core/stellar/src/erc20.test.ts.snap | Bin 0 -> 2779 bytes packages/core/stellar/src/erc20.ts | 294 +++ packages/core/stellar/src/error.ts | 7 + packages/core/stellar/src/external-trait.ts | 11 + .../core/stellar/src/generate/alternatives.ts | 36 + packages/core/stellar/src/generate/erc20.ts | 26 + packages/core/stellar/src/generate/sources.ts | 100 + packages/core/stellar/src/index.ts | 27 + packages/core/stellar/src/kind.ts | 33 + packages/core/stellar/src/print.ts | 443 +++++ .../src/scripts/update-scarb-project.ts | 41 + .../core/stellar/src/set-access-control.ts | 129 ++ packages/core/stellar/src/set-info.ts | 17 + packages/core/stellar/src/set-royalty-info.ts | 131 ++ packages/core/stellar/src/set-upgradeable.ts | 72 + packages/core/stellar/src/test.ts | 56 + .../stellar/src/utils/convert-strings.test.ts | 99 + .../core/stellar/src/utils/convert-strings.ts | 97 + .../stellar/src/utils/define-components.ts | 18 + .../stellar/src/utils/define-functions.ts | 18 + packages/core/stellar/src/utils/duration.ts | 26 + packages/core/stellar/src/utils/find-cover.ts | 26 + .../core/stellar/src/utils/format-lines.ts | 29 + packages/core/stellar/src/utils/sorted-by.ts | 3 + .../core/stellar/src/utils/version.test.ts | 11 + packages/core/stellar/src/utils/version.ts | 17 + packages/core/stellar/tsconfig.json | 16 + packages/ui/public/cairo.html | 1 + packages/ui/public/index.html | 1 + packages/ui/public/stellar.html | 72 + packages/ui/public/stylus.html | 1 + packages/ui/rollup.config.mjs | 2 +- packages/ui/src/common/styles/vars.css | 2 + packages/ui/src/main.ts | 4 + packages/ui/src/standalone.css | 7 + .../src/stellar/AccessControlSection.svelte | 62 + packages/ui/src/stellar/App.svelte | 283 +++ packages/ui/src/stellar/ERC20Controls.svelte | 112 ++ packages/ui/src/stellar/InfoSection.svelte | 21 + packages/ui/src/stellar/highlightjs.ts | 5 + packages/ui/src/stellar/inject-hyperlinks.ts | 40 + 59 files changed, 5912 insertions(+), 1 deletion(-) create mode 100644 packages/core/stellar/.gitignore create mode 100644 packages/core/stellar/CHANGELOG.md create mode 100644 packages/core/stellar/LICENSE create mode 100644 packages/core/stellar/NOTICE create mode 100644 packages/core/stellar/README.md create mode 100644 packages/core/stellar/ava.config.js create mode 100644 packages/core/stellar/package.json create mode 100644 packages/core/stellar/src/add-pausable.ts create mode 100644 packages/core/stellar/src/api.ts create mode 100644 packages/core/stellar/src/build-generic.ts create mode 100644 packages/core/stellar/src/common-components.ts create mode 100644 packages/core/stellar/src/common-options.ts create mode 100644 packages/core/stellar/src/contract.test.ts create mode 100644 packages/core/stellar/src/contract.test.ts.md create mode 100644 packages/core/stellar/src/contract.test.ts.snap create mode 100644 packages/core/stellar/src/contract.ts create mode 100644 packages/core/stellar/src/erc20.test.ts create mode 100644 packages/core/stellar/src/erc20.test.ts.md create mode 100644 packages/core/stellar/src/erc20.test.ts.snap create mode 100644 packages/core/stellar/src/erc20.ts create mode 100644 packages/core/stellar/src/error.ts create mode 100644 packages/core/stellar/src/external-trait.ts create mode 100644 packages/core/stellar/src/generate/alternatives.ts create mode 100644 packages/core/stellar/src/generate/erc20.ts create mode 100644 packages/core/stellar/src/generate/sources.ts create mode 100644 packages/core/stellar/src/index.ts create mode 100644 packages/core/stellar/src/kind.ts create mode 100644 packages/core/stellar/src/print.ts create mode 100644 packages/core/stellar/src/scripts/update-scarb-project.ts create mode 100644 packages/core/stellar/src/set-access-control.ts create mode 100644 packages/core/stellar/src/set-info.ts create mode 100644 packages/core/stellar/src/set-royalty-info.ts create mode 100644 packages/core/stellar/src/set-upgradeable.ts create mode 100644 packages/core/stellar/src/test.ts create mode 100644 packages/core/stellar/src/utils/convert-strings.test.ts create mode 100644 packages/core/stellar/src/utils/convert-strings.ts create mode 100644 packages/core/stellar/src/utils/define-components.ts create mode 100644 packages/core/stellar/src/utils/define-functions.ts create mode 100644 packages/core/stellar/src/utils/duration.ts create mode 100644 packages/core/stellar/src/utils/find-cover.ts create mode 100644 packages/core/stellar/src/utils/format-lines.ts create mode 100644 packages/core/stellar/src/utils/sorted-by.ts create mode 100644 packages/core/stellar/src/utils/version.test.ts create mode 100644 packages/core/stellar/src/utils/version.ts create mode 100644 packages/core/stellar/tsconfig.json create mode 100644 packages/ui/public/stellar.html create mode 100644 packages/ui/src/stellar/AccessControlSection.svelte create mode 100644 packages/ui/src/stellar/App.svelte create mode 100644 packages/ui/src/stellar/ERC20Controls.svelte create mode 100644 packages/ui/src/stellar/InfoSection.svelte create mode 100644 packages/ui/src/stellar/highlightjs.ts create mode 100644 packages/ui/src/stellar/inject-hyperlinks.ts diff --git a/packages/core/stellar/.gitignore b/packages/core/stellar/.gitignore new file mode 100644 index 000000000..017fefa2d --- /dev/null +++ b/packages/core/stellar/.gitignore @@ -0,0 +1,4 @@ +/cache +/artifacts +/contracts/generated +/openzeppelin-contracts.json diff --git a/packages/core/stellar/CHANGELOG.md b/packages/core/stellar/CHANGELOG.md new file mode 100644 index 000000000..5c7fed0a1 --- /dev/null +++ b/packages/core/stellar/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +## Unreleased + +- Placeholder. ([#0000](https://github.com/OpenZeppelin/contracts-wizard/pull/0000)) diff --git a/packages/core/stellar/LICENSE b/packages/core/stellar/LICENSE new file mode 100644 index 000000000..be3f7b28e --- /dev/null +++ b/packages/core/stellar/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/packages/core/stellar/NOTICE b/packages/core/stellar/NOTICE new file mode 100644 index 000000000..e68e93389 --- /dev/null +++ b/packages/core/stellar/NOTICE @@ -0,0 +1,8 @@ +OpenZeppelin Contracts Wizard +Copyright (C) 2021-2025 Zeppelin Group Ltd + +This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License along with this program. If not, see . \ No newline at end of file diff --git a/packages/core/stellar/README.md b/packages/core/stellar/README.md new file mode 100644 index 000000000..835227286 --- /dev/null +++ b/packages/core/stellar/README.md @@ -0,0 +1,63 @@ +# OpenZeppelin Contracts Wizard for Stellar + +Interactively build a contract out of components from OpenZeppelin Soroban Contracts. Provide parameters and desired features for the kind of contract that you want, and the Wizard will generate all of the code necessary. The resulting code is ready to be compiled and deployed, or it can serve as a starting point and customized further with application specific logic. + +This package provides a programmatic API. For a web interface, see https://wizard.openzeppelin.com/stellar + +### Installation + +`npm install @openzeppelin/wizard-stellar` + +### Contract types + +The following contract types are supported: +- `erc20` + +Each contract type has functions/constants as defined below. + +### Functions + +#### `print` +```js +function print(opts?: ERC20Options): string +``` +Returns a string representation of a contract generated using the provided options. If `opts` is not provided, uses [`defaults`](#defaults). + +#### `defaults` +```js +const defaults: Required +``` +The default options that are used for [`print`](#print). + +#### `isAccessControlRequired` +```js +function isAccessControlRequired(opts: Partial): boolean +``` +Whether any of the provided options require access control to be enabled. If this returns `true`, then calling `print` with the same options would cause the `access` option to default to `'ownable'` if it was `undefined` or `false`. + +### Examples + +Import the contract type(s) (for example, `erc20`) that you want to use from the `@openzeppelin/wizard-stellar` package: + +```js +import { erc20 } from '@openzeppelin/wizard-stellar'; +``` + +To generate the source code for an ERC20 contract with all of the default settings: +```js +const contract = erc20.print(); +``` + +To generate the source code for an ERC20 contract with some custom settings: +```js +const contract = erc20.print({ + pausable: true, +}); +``` +or +```js +const contract = erc20.print({ + ...erc20.defaults, + pausable: true, +}); +``` diff --git a/packages/core/stellar/ava.config.js b/packages/core/stellar/ava.config.js new file mode 100644 index 000000000..77a9117a9 --- /dev/null +++ b/packages/core/stellar/ava.config.js @@ -0,0 +1,13 @@ +module.exports = { + extensions: ['ts'], + require: ['ts-node/register'], + watchmode: { + ignoreChanges: [ + 'contracts', + 'artifacts', + 'cache', + ], + }, + timeout: '10m', + workerThreads: false, +}; diff --git a/packages/core/stellar/package.json b/packages/core/stellar/package.json new file mode 100644 index 000000000..e8aebb82a --- /dev/null +++ b/packages/core/stellar/package.json @@ -0,0 +1,32 @@ +{ + "name": "@openzeppelin/wizard-stellar", + "version": "0.0.1", + "description": "A boilerplate generator to get started with OpenZeppelin Soroban Contracts", + "license": "AGPL-3.0-only", + "repository": "https://github.com/OpenZeppelin/contracts-wizard", + "main": "dist/index.js", + "ts:main": "src/index.ts", + "files": [ + "LICENSE", + "NOTICE", + "/dist", + "/src", + "!**/*.test.*" + ], + "scripts": { + "prepare": "tsc", + "prepublish": "rimraf dist *.tsbuildinfo", + "test": "ava", + "test:watch": "ava --watch", + "version": "node ../../../scripts/bump-changelog.js" + }, + "devDependencies": { + "@types/node": "^18.0.0", + "@types/semver": "^7.5.7", + "ava": "^6.0.0", + "rimraf": "^5.0.0", + "ts-node": "^10.4.0", + "typescript": "^5.0.0", + "semver": "^7.6.0" + } +} diff --git a/packages/core/stellar/src/add-pausable.ts b/packages/core/stellar/src/add-pausable.ts new file mode 100644 index 000000000..1e950f98e --- /dev/null +++ b/packages/core/stellar/src/add-pausable.ts @@ -0,0 +1,58 @@ +import { getSelfArg } from './common-options'; +import type { ContractBuilder } from './contract'; +import { Access, requireAccessControl } from './set-access-control'; +import { defineFunctions } from './utils/define-functions'; +import { defineComponents } from './utils/define-components'; +import { externalTrait } from './external-trait'; + +export function addPausable(c: ContractBuilder, access: Access) { + c.addComponent(components.PausableComponent, [], false); + + c.addFunction(externalTrait, functions.pause); + c.addFunction(externalTrait, functions.unpause); + requireAccessControl(c, externalTrait, functions.pause, access, 'PAUSER', 'pauser'); + requireAccessControl(c, externalTrait, functions.unpause, access, 'PAUSER', 'pauser'); +} + +const components = defineComponents( { + PausableComponent: { + path: 'openzeppelin::security::pausable', + substorage: { + name: 'pausable', + type: 'PausableComponent::Storage', + }, + event: { + name: 'PausableEvent', + type: 'PausableComponent::Event', + }, + impls: [{ + name: 'PausableImpl', + value: 'PausableComponent::PausableImpl', + }, { + name: 'PausableInternalImpl', + embed: false, + value: 'PausableComponent::InternalImpl', + } + ], + }, +}); + +const functions = defineFunctions({ + pause: { + args: [ + getSelfArg(), + ], + code: [ + 'self.pausable.pause()' + ] + }, + unpause: { + args: [ + getSelfArg(), + ], + code: [ + 'self.pausable.unpause()' + ] + }, +}); + diff --git a/packages/core/stellar/src/api.ts b/packages/core/stellar/src/api.ts new file mode 100644 index 000000000..6022d6772 --- /dev/null +++ b/packages/core/stellar/src/api.ts @@ -0,0 +1,42 @@ +import type { CommonOptions, CommonContractOptions } from './common-options'; +import { printERC20, defaults as erc20defaults, isAccessControlRequired as erc20IsAccessControlRequired, ERC20Options } from './erc20'; + +export interface WizardAccountAPI{ + /** + * Returns a string representation of a contract generated using the provided options. If opts is not provided, uses `defaults`. + */ + print: (opts?: Options) => string; + + /** + * The default options that are used for `print`. + */ + defaults: Required; +} + +export interface WizardContractAPI { + /** + * Returns a string representation of a contract generated using the provided options. If opts is not provided, uses `defaults`. + */ + print: (opts?: Options) => string; + + /** + * The default options that are used for `print`. + */ + defaults: Required; +} + +export interface AccessControlAPI { + /** + * Whether any of the provided options require access control to be enabled. If this returns `true`, then calling `print` with the + * same options would cause the `access` option to default to `'ownable'` if it was `undefined` or `false`. + */ + isAccessControlRequired: (opts: Partial) => boolean; +} + +export type ERC20 = WizardContractAPI & AccessControlAPI; + +export const erc20: ERC20 = { + print: printERC20, + defaults: erc20defaults, + isAccessControlRequired: erc20IsAccessControlRequired, +}; diff --git a/packages/core/stellar/src/build-generic.ts b/packages/core/stellar/src/build-generic.ts new file mode 100644 index 000000000..2aed9667f --- /dev/null +++ b/packages/core/stellar/src/build-generic.ts @@ -0,0 +1,18 @@ +import { ERC20Options, buildERC20 } from './erc20'; + +export interface KindedOptions { + ERC20: { kind: 'ERC20' } & ERC20Options; +} + +export type GenericOptions = KindedOptions[keyof KindedOptions]; + +export function buildGeneric(opts: GenericOptions) { + switch (opts.kind) { + case 'ERC20': + return buildERC20(opts); + + default: + const _: never = opts.kind; // TODO: When there are additional kinds above, change this assignment to just `opts` instead of `opts.kind` + throw new Error('Unknown ERC'); + } +} diff --git a/packages/core/stellar/src/common-components.ts b/packages/core/stellar/src/common-components.ts new file mode 100644 index 000000000..a05776fdd --- /dev/null +++ b/packages/core/stellar/src/common-components.ts @@ -0,0 +1,109 @@ +import type { BaseImplementedTrait, ContractBuilder } from './contract'; +import { defineComponents } from "./utils/define-components"; + +export const tokenTypes = ['ERC20', 'ERC721'] as const; +export type Token = typeof tokenTypes[number]; + +const components = defineComponents( { + SRC5Component: { + path: 'openzeppelin::introspection::src5', + substorage: { + name: 'src5', + type: 'SRC5Component::Storage', + }, + event: { + name: 'SRC5Event', + type: 'SRC5Component::Event', + }, + impls: [], + }, + + VotesComponent: { + path: 'openzeppelin::governance::votes', + substorage: { + name: 'votes', + type: 'VotesComponent::Storage', + }, + event: { + name: 'VotesEvent', + type: 'VotesComponent::Event', + }, + impls: [{ + name: 'VotesInternalImpl', + embed: false, + value: 'VotesComponent::InternalImpl', + }], + }, + + NoncesComponent: { + path: 'openzeppelin::utils::cryptography::nonces', + substorage: { + name: 'nonces', + type: 'NoncesComponent::Storage', + }, + event: { + name: 'NoncesEvent', + type: 'NoncesComponent::Event', + }, + impls: [ + { + name: 'NoncesImpl', + value: 'NoncesComponent::NoncesImpl', + }, + ], + }, +}) + +export function addSRC5Component(c: ContractBuilder, section?: string) { + c.addComponent(components.SRC5Component, [], false); + + if (!c.interfaceFlags.has('ISRC5')) { + c.addImplToComponent(components.SRC5Component, { + name: 'SRC5Impl', + value: 'SRC5Component::SRC5Impl', + section, + }); + c.addInterfaceFlag('ISRC5'); + } +} + +export function addVotesComponent(c: ContractBuilder, name: string, version: string, section?: string) { + addSNIP12Metadata(c, name, version, section); + c.addComponent(components.NoncesComponent, [], false); + c.addComponent(components.VotesComponent, [], false); + c.addImplToComponent(components.VotesComponent, { + name: 'VotesImpl', + value: `VotesComponent::VotesImpl`, + }); +} + +export function addSNIP12Metadata(c: ContractBuilder, name: string, version: string, section?: string) { + c.addUseClause('openzeppelin::utils::cryptography::snip12', 'SNIP12Metadata'); + + const SNIP12Metadata: BaseImplementedTrait = { + name: 'SNIP12MetadataImpl', + of: 'SNIP12Metadata', + tags: [], + priority: 0, + section, + }; + c.addImplementedTrait(SNIP12Metadata); + + c.addFunction(SNIP12Metadata, { + name: 'name', + args: [], + returns: 'felt252', + code: [ + `'${name}'`, + ], + }); + + c.addFunction(SNIP12Metadata, { + name: 'version', + args: [], + returns: 'felt252', + code: [ + `'${version}'`, + ], + }); +} diff --git a/packages/core/stellar/src/common-options.ts b/packages/core/stellar/src/common-options.ts new file mode 100644 index 000000000..067ea317a --- /dev/null +++ b/packages/core/stellar/src/common-options.ts @@ -0,0 +1,46 @@ +import type { Argument } from "./contract"; +import type { Access } from "./set-access-control"; +import type { Info } from "./set-info"; +import { defaults as infoDefaults } from "./set-info"; +import type { Upgradeable } from "./set-upgradeable"; + +export const defaults: Required = { + upgradeable: true, + info: infoDefaults, +} as const; + +export const contractDefaults: Required = { + ...defaults, + access: false, +} as const; + +export interface CommonOptions { + upgradeable?: Upgradeable; + info?: Info; +} + +export interface CommonContractOptions extends CommonOptions { + access?: Access; +} + +export function withCommonDefaults(opts: CommonOptions): Required { + return { + upgradeable: opts.upgradeable ?? defaults.upgradeable, + info: opts.info ?? defaults.info, + }; +} + +export function withCommonContractDefaults(opts: CommonContractOptions): Required { + return { + ...withCommonDefaults(opts), + access: opts.access ?? contractDefaults.access, + }; +} + +export function getSelfArg(scope: 'external' | 'view' = 'external'): Argument { + if (scope === 'view') { + return { name: 'self', type: '@ContractState' }; + } else { + return { name: 'ref self', type: 'ContractState' }; + } +} \ No newline at end of file diff --git a/packages/core/stellar/src/contract.test.ts b/packages/core/stellar/src/contract.test.ts new file mode 100644 index 000000000..b7d040ee0 --- /dev/null +++ b/packages/core/stellar/src/contract.test.ts @@ -0,0 +1,112 @@ +import test from 'ava'; + +import { ContractBuilder, BaseFunction, BaseImplementedTrait, Component } from './contract'; +import { printContract } from './print'; + +const FOO_COMPONENT: Component = { + name: 'FooComponent', + path: 'some::path', + substorage: { + name: 'foo', + type: 'FooComponent::Storage', + }, + event: { + name: 'FooEvent', + type: 'FooComponent::Event', + }, + impls: [{ + name: 'FooImpl', + value: 'FooComponent::FooImpl', + }, { + name: 'FooInternalImpl', + embed: false, + value: 'FooComponent::InternalImpl', + } + ], +}; + +test('contract basics', t => { + const Foo = new ContractBuilder('Foo'); + t.snapshot(printContract(Foo)); +}); + +test('contract with constructor code', t => { + const Foo = new ContractBuilder('Foo'); + Foo.addConstructorCode('someFunction()'); + t.snapshot(printContract(Foo)); +}); + +test('contract with constructor code with semicolon', t => { + const Foo = new ContractBuilder('Foo'); + Foo.addConstructorCode('someFunction();'); + t.snapshot(printContract(Foo)); +}); + +test('contract with function code before', t => { + const Foo = new ContractBuilder('Foo'); + const trait: BaseImplementedTrait = { + name: 'External', + of: 'ExternalTrait', + tags: [ + 'generate_trait', + 'abi(per_item)', + ], + perItemTag: 'external(v0)', + }; + Foo.addImplementedTrait(trait); + const fn: BaseFunction = { + name: 'someFunction', + args: [], + code: [ + 'someFunction()' + ] + }; + Foo.addFunction(trait, fn); + Foo.addFunctionCodeBefore(trait, fn, 'before()'); + t.snapshot(printContract(Foo)); +}); + +test('contract with function code before with semicolons', t => { + const Foo = new ContractBuilder('Foo'); + const trait: BaseImplementedTrait = { + name: 'External', + of: 'ExternalTrait', + tags: [ + 'generate_trait', + 'abi(per_item)', + ], + perItemTag: 'external(v0)', + }; + Foo.addImplementedTrait(trait); + const fn: BaseFunction = { + name: 'someFunction', + args: [], + code: [ + 'someFunction();' + ] + }; + Foo.addFunction(trait, fn); + Foo.addFunctionCodeBefore(trait, fn, 'before();'); + t.snapshot(printContract(Foo)); +}); + +test('contract with initializer params', t => { + const Foo = new ContractBuilder('Foo'); + + Foo.addComponent( + FOO_COMPONENT, + ['param1'], + true + ); + t.snapshot(printContract(Foo)); +}); + +test('contract with standalone import', t => { + const Foo = new ContractBuilder('Foo'); + Foo.addComponent( + FOO_COMPONENT, + ); + Foo.addUseClause('some::library', 'SomeLibrary'); + t.snapshot(printContract(Foo)); +}); + diff --git a/packages/core/stellar/src/contract.test.ts.md b/packages/core/stellar/src/contract.test.ts.md new file mode 100644 index 000000000..83f0b0adb --- /dev/null +++ b/packages/core/stellar/src/contract.test.ts.md @@ -0,0 +1,191 @@ +# Snapshot report for `src/contract.test.ts` + +The actual snapshot is saved in `contract.test.ts.snap`. + +Generated by [AVA](https://avajs.dev). + +## contract basics + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + #[starknet::contract]␊ + mod Foo {␊ + #[storage]␊ + struct Storage {␊ + }␊ + }␊ + ` + +## contract with constructor code + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + #[starknet::contract]␊ + mod Foo {␊ + #[storage]␊ + struct Storage {␊ + }␊ + ␊ + #[constructor]␊ + fn constructor(ref self: ContractState) {␊ + someFunction();␊ + }␊ + }␊ + ` + +## contract with constructor code with semicolon + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + #[starknet::contract]␊ + mod Foo {␊ + #[storage]␊ + struct Storage {␊ + }␊ + ␊ + #[constructor]␊ + fn constructor(ref self: ContractState) {␊ + someFunction();␊ + }␊ + }␊ + ` + +## contract with function code before + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + #[starknet::contract]␊ + mod Foo {␊ + #[storage]␊ + struct Storage {␊ + }␊ + ␊ + #[generate_trait]␊ + #[abi(per_item)]␊ + impl External of ExternalTrait {␊ + #[external(v0)]␊ + fn someFunction() {␊ + before();␊ + someFunction();␊ + }␊ + }␊ + }␊ + ` + +## contract with function code before with semicolons + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + #[starknet::contract]␊ + mod Foo {␊ + #[storage]␊ + struct Storage {␊ + }␊ + ␊ + #[generate_trait]␊ + #[abi(per_item)]␊ + impl External of ExternalTrait {␊ + #[external(v0)]␊ + fn someFunction() {␊ + before();␊ + someFunction();␊ + }␊ + }␊ + }␊ + ` + +## contract with initializer params + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + #[starknet::contract]␊ + mod Foo {␊ + use some::path::FooComponent;␊ + ␊ + component!(path: FooComponent, storage: foo, event: FooEvent);␊ + ␊ + // External␊ + #[abi(embed_v0)]␊ + impl FooImpl = FooComponent::FooImpl;␊ + ␊ + // Internal␊ + impl FooInternalImpl = FooComponent::InternalImpl;␊ + ␊ + #[storage]␊ + struct Storage {␊ + #[substorage(v0)]␊ + foo: FooComponent::Storage,␊ + }␊ + ␊ + #[event]␊ + #[derive(Drop, starknet::Event)]␊ + enum Event {␊ + #[flat]␊ + FooEvent: FooComponent::Event,␊ + }␊ + ␊ + #[constructor]␊ + fn constructor(ref self: ContractState) {␊ + self.foo.initializer("param1");␊ + }␊ + }␊ + ` + +## contract with standalone import + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + #[starknet::contract]␊ + mod Foo {␊ + use some::library::SomeLibrary;␊ + use some::path::FooComponent;␊ + ␊ + component!(path: FooComponent, storage: foo, event: FooEvent);␊ + ␊ + // External␊ + #[abi(embed_v0)]␊ + impl FooImpl = FooComponent::FooImpl;␊ + ␊ + // Internal␊ + impl FooInternalImpl = FooComponent::InternalImpl;␊ + ␊ + #[storage]␊ + struct Storage {␊ + #[substorage(v0)]␊ + foo: FooComponent::Storage,␊ + }␊ + ␊ + #[event]␊ + #[derive(Drop, starknet::Event)]␊ + enum Event {␊ + #[flat]␊ + FooEvent: FooComponent::Event,␊ + }␊ + ␊ + #[constructor]␊ + fn constructor(ref self: ContractState) {␊ + self.foo.initializer();␊ + }␊ + }␊ + ` diff --git a/packages/core/stellar/src/contract.test.ts.snap b/packages/core/stellar/src/contract.test.ts.snap new file mode 100644 index 0000000000000000000000000000000000000000..f18abae37cf688fe8e500e2154a60e171287084e GIT binary patch literal 720 zcmV;>0x$hRRzV)Hsgq4RK^_U+&lN&gl7+@BNoj>q{}U2Afgzr zO#Hg}pf>XT<}Df7K`R56aH*?9`vxUgOk^2sIkPc*sU5K5$VHDnCPWs2I~$ z8B}SO!1fuV(INqo)92lMV}<3leROa9)1KSx^r{O`*^^%-!4qAs)2tj|R=tg1t2g73 zs~_Hlnm0vFsH>^8VkHvw0S#orh;)v2%Xezp{aE_%+Knw1BL_hy_&5j#M0r8dsCl#0 zESjtz`vnH7n00X42Ox>o0Z&nL0ol%Pq@)CKsHWvHEg;+TS_Y4mS=Rbmj~a1v6#c_Vv0g3f?Aeh|#E1^tTLU zIlmJPOGZl&>TwE1pw@>>1YcI4s4&|?5u9n@Z~VM4ksV3YsaU~ZExhn#bQ%!4 literal 0 HcmV?d00001 diff --git a/packages/core/stellar/src/contract.ts b/packages/core/stellar/src/contract.ts new file mode 100644 index 000000000..b7f77d6a6 --- /dev/null +++ b/packages/core/stellar/src/contract.ts @@ -0,0 +1,292 @@ +import { toIdentifier } from './utils/convert-strings'; + +export interface Contract { + license: string; + name: string; + account: boolean; + useClauses: UseClause[]; + components: Component[]; + constants: Variable[]; + constructorCode: string[]; + constructorArgs: Argument[]; + upgradeable: boolean; + implementedTraits: ImplementedTrait[]; + superVariables: Variable[]; +} + +export type Value = string | number | bigint | { lit: string } | { note: string, value: Value }; + +export interface UseClause { + containerPath: string; + name: string; + groupable?: boolean; + alias?: string; +} + +export interface Component { + name: string; + path: string; + substorage: Substorage; + event: Event; + impls: Impl[]; + initializer?: Initializer; +} + +export interface Substorage { + name: string; + type: string; +} + +export interface Event { + name: string; + type: string; +} + +export interface Impl { + name: string; + value: string; + embed?: boolean; + section?: string; +} + +export interface Initializer { + params: Value[]; +} + +export interface BaseImplementedTrait { + name: string; + of: string; + tags: string[]; + perItemTag?: string; + section?: string; + /** + * Priority for which trait to print first. + * Lower numbers are higher priority, undefined is lowest priority. + */ + priority?: number; +} + +export interface ImplementedTrait extends BaseImplementedTrait { + superVariables: Variable[]; + functions: ContractFunction[]; + section?: string; +} + +export interface BaseFunction { + name: string; + args: Argument[]; + code: string[]; + returns?: string; +} + +export interface ContractFunction extends BaseFunction { + codeBefore?: string[]; + tag?: string; +} + +export interface Variable { + name: string; + type: string; + value: string; + comment?: string; + inlineComment?: boolean; +} + +export interface Argument { + name: string; + type?: string; +} + +export class ContractBuilder implements Contract { + readonly name: string; + readonly account: boolean; + license = 'MIT'; + upgradeable = false; + + readonly constructorArgs: Argument[] = []; + readonly constructorCode: string[] = []; + + private componentsMap: Map = new Map(); + private implementedTraitsMap: Map = new Map(); + private superVariablesMap: Map = new Map(); + private constantsMap: Map = new Map(); + private useClausesMap: Map = new Map(); + private interfaceFlagsSet: Set = new Set(); + + constructor(name: string, account: boolean = false) { + this.name = toIdentifier(name, true); + this.account = account; + } + + get components(): Component[] { + return [...this.componentsMap.values()]; + } + + get implementedTraits(): ImplementedTrait[] { + return [...this.implementedTraitsMap.values()]; + } + + get superVariables(): Variable[] { + return [...this.superVariablesMap.values()]; + } + + get constants(): Variable[] { + return [...this.constantsMap.values()]; + } + + get useClauses(): UseClause[] { + return [...this.useClausesMap.values()]; + } + + /** + * Custom flags to denote that the contract implements a specific interface, e.g. ISRC5, to avoid duplicates + **/ + get interfaceFlags(): Set { + return this.interfaceFlagsSet; + } + + addUseClause(containerPath: string, name: string, options?: { groupable?: boolean, alias?: string }): void { + // groupable defaults to true + const groupable = options?.groupable ?? true; + const alias = options?.alias ?? ''; + const uniqueName = alias.length > 0 ? alias : name; + const present = this.useClausesMap.has(uniqueName); + if (!present) { + this.useClausesMap.set(uniqueName, { containerPath, name, groupable, alias }); + } + } + + addComponent(component: Component, params: Value[] = [], initializable: boolean = true): boolean { + this.addUseClause(component.path, component.name); + const key = component.name; + const present = this.componentsMap.has(key); + if (!present) { + const initializer = initializable ? { params } : undefined; + const cp: Component = { initializer, ...component, impls: [ ...component.impls ] }; // spread impls to deep copy from original component + this.componentsMap.set(key, cp); + } + return !present; + } + + addImplToComponent(component: Component, impl: Impl): void { + this.addComponent(component); + const c = this.componentsMap.get(component.name); + if (c == undefined) { + throw new Error(`Component ${component.name} has not been added yet`); + } + + if (!c.impls.some(i => i.name === impl.name)) { + c.impls.push(impl); + } + } + + addConstant(constant: Variable): boolean { + if (this.constantsMap.has(constant.name)) { + return false; + } else { + this.constantsMap.set(constant.name, constant); + return true; + } + } + + addSuperVariable(variable: Variable): boolean { + if (this.superVariablesMap.has(variable.name)) { + return false; + } else { + this.superVariablesMap.set(variable.name, variable); + this.addUseClause('super', variable.name); + return true; + } + } + + addImplementedTrait(baseTrait: BaseImplementedTrait): ImplementedTrait { + const key = baseTrait.name; + const existingTrait = this.implementedTraitsMap.get(key); + if (existingTrait !== undefined) { + return existingTrait; + } else { + const t: ImplementedTrait = { + name: baseTrait.name, + of: baseTrait.of, + tags: [ ...baseTrait.tags ], + superVariables: [], + functions: [], + section: baseTrait.section, + priority: baseTrait.priority, + }; + this.implementedTraitsMap.set(key, t); + return t; + } + } + + addSuperVariableToTrait(baseTrait: BaseImplementedTrait, newVar: Variable): boolean { + const trait = this.addImplementedTrait(baseTrait); + for (const existingVar of trait.superVariables) { + if (existingVar.name === newVar.name) { + if (existingVar.type !== newVar.type) { + throw new Error( + `Tried to add duplicate super var ${newVar.name} with different type: ${newVar.type} instead of ${existingVar.type}.` + ); + } + if (existingVar.value !== newVar.value) { + throw new Error( + `Tried to add duplicate super var ${newVar.name} with different value: ${newVar.value} instead of ${existingVar.value}.` + ); + } + return false; // No need to add, already exists + } + } + trait.superVariables.push(newVar); + return true; + } + + addFunction(baseTrait: BaseImplementedTrait, fn: BaseFunction): ContractFunction { + const t = this.addImplementedTrait(baseTrait); + + const signature = this.getFunctionSignature(fn); + + // Look for the existing function with the same signature and return it if found + for (let i = 0; i < t.functions.length; i++) { + const existingFn = t.functions[i]; + if (existingFn !== undefined && this.getFunctionSignature(existingFn) === signature) { + return existingFn; + } + } + + // Otherwise, add the function + const contractFn: ContractFunction = { + ...fn, + codeBefore: [], + tag: baseTrait.perItemTag, + }; + t.functions.push(contractFn); + return contractFn; + } + + private getFunctionSignature(fn: BaseFunction): string { + return [fn.name, '(', ...fn.args.map(a => a.name), ')'].join(''); + } + + addFunctionCodeBefore(baseTrait: BaseImplementedTrait, fn: BaseFunction, codeBefore: string): void { + this.addImplementedTrait(baseTrait); + const existingFn = this.addFunction(baseTrait, fn); + existingFn.codeBefore = [ ...existingFn.codeBefore ?? [], codeBefore ]; + } + + addConstructorArgument(arg: Argument): void { + for (const existingArg of this.constructorArgs) { + if (existingArg.name == arg.name) { + return; + } + } + this.constructorArgs.push(arg); + } + + addConstructorCode(code: string): void { + this.constructorCode.push(code); + } + + addInterfaceFlag(flag: string): void { + this.interfaceFlagsSet.add(flag); + } +} diff --git a/packages/core/stellar/src/erc20.test.ts b/packages/core/stellar/src/erc20.test.ts new file mode 100644 index 000000000..69f4cdd3d --- /dev/null +++ b/packages/core/stellar/src/erc20.test.ts @@ -0,0 +1,189 @@ +import test from 'ava'; + +import { buildERC20, ERC20Options, getInitialSupply } from './erc20'; +import { printContract } from './print'; + +import { erc20, OptionsError } from '.'; + +function testERC20(title: string, opts: Partial) { + test(title, t => { + const c = buildERC20({ + name: 'MyToken', + symbol: 'MTK', + ...opts, + }); + t.snapshot(printContract(c)); + }); +} + +/** + * Tests external API for equivalence with internal API + */ +function testAPIEquivalence(title: string, opts?: ERC20Options) { + test(title, t => { + t.is(erc20.print(opts), printContract(buildERC20({ + name: 'MyToken', + symbol: 'MTK', + ...opts, + }))); + }); +} + +testERC20('basic erc20, non-upgradeable', { + upgradeable: false, +}); + +testERC20('basic erc20', {}); + +testERC20('erc20 burnable', { + burnable: true, +}); + +testERC20('erc20 pausable', { + pausable: true, + access: 'ownable', +}); + +testERC20('erc20 pausable with roles', { + pausable: true, + access: 'roles', +}); + +testERC20('erc20 burnable pausable', { + burnable: true, + pausable: true, +}); + +testERC20('erc20 preminted', { + premint: '1000', +}); + +testERC20('erc20 premint of 0', { + premint: '0', +}); + +testERC20('erc20 mintable', { + mintable: true, + access: 'ownable', +}); + +testERC20('erc20 mintable with roles', { + mintable: true, + access: 'roles', +}); + +testERC20('erc20 votes', { + votes: true, + appName: 'MY_DAPP_NAME', +}); + +testERC20('erc20 votes, version', { + votes: true, + appName: 'MY_DAPP_NAME', + appVersion: 'MY_DAPP_VERSION', +}); + +test('erc20 votes, no name', async t => { + let error = t.throws(() => buildERC20({ + name: 'MyToken', + symbol: 'MTK', + votes: true, + })); + t.is((error as OptionsError).messages.appName, 'Application Name is required when Votes are enabled'); +}); + +test('erc20 votes, empty version', async t => { + let error = t.throws(() => buildERC20({ + name: 'MyToken', + symbol: 'MTK', + votes: true, + appName: 'MY_DAPP_NAME', + appVersion: '', // avoids default value of v1 + })); + t.is((error as OptionsError).messages.appVersion, 'Application Version is required when Votes are enabled'); +}); + +testERC20('erc20 votes, non-upgradeable', { + votes: true, + appName: 'MY_DAPP_NAME', + upgradeable: false, +}); + +testERC20('erc20 full, non-upgradeable', { + premint: '2000', + access: 'ownable', + burnable: true, + mintable: true, + votes: true, + pausable: true, + upgradeable: false, + appName: 'MY_DAPP_NAME', + appVersion: 'MY_DAPP_VERSION', +}); + +testERC20('erc20 full upgradeable', { + premint: '2000', + access: 'ownable', + burnable: true, + mintable: true, + votes: true, + pausable: true, + upgradeable: true, + appName: 'MY_DAPP_NAME', + appVersion: 'MY_DAPP_VERSION', +}); + +testERC20('erc20 full upgradeable with roles', { + premint: '2000', + access: 'roles', + burnable: true, + mintable: true, + votes: true, + pausable: true, + upgradeable: true, + appName: 'MY_DAPP_NAME', + appVersion: 'MY_DAPP_VERSION', +}); + +testAPIEquivalence('erc20 API default'); + +testAPIEquivalence('erc20 API basic', { name: 'CustomToken', symbol: 'CTK' }); + +testAPIEquivalence('erc20 API full upgradeable', { + name: 'CustomToken', + symbol: 'CTK', + premint: '2000', + access: 'roles', + burnable: true, + mintable: true, + votes: true, + pausable: true, + upgradeable: true, + appName: 'MY_DAPP_NAME', + appVersion: 'MY_DAPP_VERSION', +}); + +test('erc20 API assert defaults', async t => { + t.is(erc20.print(erc20.defaults), erc20.print()); +}); + +test('erc20 API isAccessControlRequired', async t => { + t.is(erc20.isAccessControlRequired({ mintable: true }), true); + t.is(erc20.isAccessControlRequired({ pausable: true }), true); + t.is(erc20.isAccessControlRequired({ upgradeable: true }), true); +}); + +test('erc20 getInitialSupply', async t => { + t.is(getInitialSupply('1000', 18), '1000000000000000000000'); + t.is(getInitialSupply('1000.1', 18), '1000100000000000000000'); + t.is(getInitialSupply('.1', 18), '100000000000000000'); + t.is(getInitialSupply('.01', 2), '1'); + + let error = t.throws(() => getInitialSupply('.01', 1)); + t.not(error, undefined); + t.is((error as OptionsError).messages.premint, 'Too many decimals'); + + error = t.throws(() => getInitialSupply('1.1.1', 18)); + t.not(error, undefined); + t.is((error as OptionsError).messages.premint, 'Not a valid number'); +}); \ No newline at end of file diff --git a/packages/core/stellar/src/erc20.test.ts.md b/packages/core/stellar/src/erc20.test.ts.md new file mode 100644 index 000000000..4f2d5b916 --- /dev/null +++ b/packages/core/stellar/src/erc20.test.ts.md @@ -0,0 +1,1674 @@ +# Snapshot report for `src/erc20.test.ts` + +The actual snapshot is saved in `erc20.test.ts.snap`. + +Generated by [AVA](https://avajs.dev). + +## basic erc20, non-upgradeable + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + #[starknet::contract]␊ + mod MyToken {␊ + use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl};␊ + ␊ + component!(path: ERC20Component, storage: erc20, event: ERC20Event);␊ + ␊ + // External␊ + #[abi(embed_v0)]␊ + impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl;␊ + ␊ + // Internal␊ + impl ERC20InternalImpl = ERC20Component::InternalImpl;␊ + ␊ + #[storage]␊ + struct Storage {␊ + #[substorage(v0)]␊ + erc20: ERC20Component::Storage,␊ + }␊ + ␊ + #[event]␊ + #[derive(Drop, starknet::Event)]␊ + enum Event {␊ + #[flat]␊ + ERC20Event: ERC20Component::Event,␊ + }␊ + ␊ + #[constructor]␊ + fn constructor(ref self: ContractState) {␊ + self.erc20.initializer("MyToken", "MTK");␊ + }␊ + }␊ + ` + +## basic erc20 + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + #[starknet::contract]␊ + mod MyToken {␊ + use openzeppelin::access::ownable::OwnableComponent;␊ + use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl};␊ + use openzeppelin::upgrades::interface::IUpgradeable;␊ + use openzeppelin::upgrades::UpgradeableComponent;␊ + use starknet::{ClassHash, ContractAddress};␊ + ␊ + component!(path: ERC20Component, storage: erc20, event: ERC20Event);␊ + component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ + component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ + ␊ + // External␊ + #[abi(embed_v0)]␊ + impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl;␊ + #[abi(embed_v0)]␊ + impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ + ␊ + // Internal␊ + impl ERC20InternalImpl = ERC20Component::InternalImpl;␊ + impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ + impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ + ␊ + #[storage]␊ + struct Storage {␊ + #[substorage(v0)]␊ + erc20: ERC20Component::Storage,␊ + #[substorage(v0)]␊ + upgradeable: UpgradeableComponent::Storage,␊ + #[substorage(v0)]␊ + ownable: OwnableComponent::Storage,␊ + }␊ + ␊ + #[event]␊ + #[derive(Drop, starknet::Event)]␊ + enum Event {␊ + #[flat]␊ + ERC20Event: ERC20Component::Event,␊ + #[flat]␊ + UpgradeableEvent: UpgradeableComponent::Event,␊ + #[flat]␊ + OwnableEvent: OwnableComponent::Event,␊ + }␊ + ␊ + #[constructor]␊ + fn constructor(ref self: ContractState, owner: ContractAddress) {␊ + self.erc20.initializer("MyToken", "MTK");␊ + self.ownable.initializer(owner);␊ + }␊ + ␊ + //␊ + // Upgradeable␊ + //␊ + ␊ + #[abi(embed_v0)]␊ + impl UpgradeableImpl of IUpgradeable {␊ + fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ + self.ownable.assert_only_owner();␊ + self.upgradeable.upgrade(new_class_hash);␊ + }␊ + }␊ + }␊ + ` + +## erc20 burnable + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + #[starknet::contract]␊ + mod MyToken {␊ + use openzeppelin::access::ownable::OwnableComponent;␊ + use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl};␊ + use openzeppelin::upgrades::interface::IUpgradeable;␊ + use openzeppelin::upgrades::UpgradeableComponent;␊ + use starknet::{ClassHash, ContractAddress, get_caller_address};␊ + ␊ + component!(path: ERC20Component, storage: erc20, event: ERC20Event);␊ + component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ + component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ + ␊ + // External␊ + #[abi(embed_v0)]␊ + impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl;␊ + #[abi(embed_v0)]␊ + impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ + ␊ + // Internal␊ + impl ERC20InternalImpl = ERC20Component::InternalImpl;␊ + impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ + impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ + ␊ + #[storage]␊ + struct Storage {␊ + #[substorage(v0)]␊ + erc20: ERC20Component::Storage,␊ + #[substorage(v0)]␊ + upgradeable: UpgradeableComponent::Storage,␊ + #[substorage(v0)]␊ + ownable: OwnableComponent::Storage,␊ + }␊ + ␊ + #[event]␊ + #[derive(Drop, starknet::Event)]␊ + enum Event {␊ + #[flat]␊ + ERC20Event: ERC20Component::Event,␊ + #[flat]␊ + UpgradeableEvent: UpgradeableComponent::Event,␊ + #[flat]␊ + OwnableEvent: OwnableComponent::Event,␊ + }␊ + ␊ + #[constructor]␊ + fn constructor(ref self: ContractState, owner: ContractAddress) {␊ + self.erc20.initializer("MyToken", "MTK");␊ + self.ownable.initializer(owner);␊ + }␊ + ␊ + #[generate_trait]␊ + #[abi(per_item)]␊ + impl ExternalImpl of ExternalTrait {␊ + #[external(v0)]␊ + fn burn(ref self: ContractState, value: u256) {␊ + self.erc20.burn(get_caller_address(), value);␊ + }␊ + }␊ + ␊ + //␊ + // Upgradeable␊ + //␊ + ␊ + #[abi(embed_v0)]␊ + impl UpgradeableImpl of IUpgradeable {␊ + fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ + self.ownable.assert_only_owner();␊ + self.upgradeable.upgrade(new_class_hash);␊ + }␊ + }␊ + }␊ + ` + +## erc20 pausable + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + #[starknet::contract]␊ + mod MyToken {␊ + use openzeppelin::access::ownable::OwnableComponent;␊ + use openzeppelin::security::pausable::PausableComponent;␊ + use openzeppelin::token::erc20::ERC20Component;␊ + use openzeppelin::upgrades::interface::IUpgradeable;␊ + use openzeppelin::upgrades::UpgradeableComponent;␊ + use starknet::{ClassHash, ContractAddress};␊ + ␊ + component!(path: ERC20Component, storage: erc20, event: ERC20Event);␊ + component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ + component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ + component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ + ␊ + // External␊ + #[abi(embed_v0)]␊ + impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl;␊ + #[abi(embed_v0)]␊ + impl PausableImpl = PausableComponent::PausableImpl;␊ + #[abi(embed_v0)]␊ + impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ + ␊ + // Internal␊ + impl ERC20InternalImpl = ERC20Component::InternalImpl;␊ + impl PausableInternalImpl = PausableComponent::InternalImpl;␊ + impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ + impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ + ␊ + #[storage]␊ + struct Storage {␊ + #[substorage(v0)]␊ + erc20: ERC20Component::Storage,␊ + #[substorage(v0)]␊ + pausable: PausableComponent::Storage,␊ + #[substorage(v0)]␊ + ownable: OwnableComponent::Storage,␊ + #[substorage(v0)]␊ + upgradeable: UpgradeableComponent::Storage,␊ + }␊ + ␊ + #[event]␊ + #[derive(Drop, starknet::Event)]␊ + enum Event {␊ + #[flat]␊ + ERC20Event: ERC20Component::Event,␊ + #[flat]␊ + PausableEvent: PausableComponent::Event,␊ + #[flat]␊ + OwnableEvent: OwnableComponent::Event,␊ + #[flat]␊ + UpgradeableEvent: UpgradeableComponent::Event,␊ + }␊ + ␊ + #[constructor]␊ + fn constructor(ref self: ContractState, owner: ContractAddress) {␊ + self.erc20.initializer("MyToken", "MTK");␊ + self.ownable.initializer(owner);␊ + }␊ + ␊ + impl ERC20HooksImpl of ERC20Component::ERC20HooksTrait {␊ + fn before_update(␊ + ref self: ERC20Component::ComponentState,␊ + from: ContractAddress,␊ + recipient: ContractAddress,␊ + amount: u256,␊ + ) {␊ + let contract_state = self.get_contract();␊ + contract_state.pausable.assert_not_paused();␊ + }␊ + }␊ + ␊ + #[generate_trait]␊ + #[abi(per_item)]␊ + impl ExternalImpl of ExternalTrait {␊ + #[external(v0)]␊ + fn pause(ref self: ContractState) {␊ + self.ownable.assert_only_owner();␊ + self.pausable.pause();␊ + }␊ + ␊ + #[external(v0)]␊ + fn unpause(ref self: ContractState) {␊ + self.ownable.assert_only_owner();␊ + self.pausable.unpause();␊ + }␊ + }␊ + ␊ + //␊ + // Upgradeable␊ + //␊ + ␊ + #[abi(embed_v0)]␊ + impl UpgradeableImpl of IUpgradeable {␊ + fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ + self.ownable.assert_only_owner();␊ + self.upgradeable.upgrade(new_class_hash);␊ + }␊ + }␊ + }␊ + ` + +## erc20 pausable with roles + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + const PAUSER_ROLE: felt252 = selector!("PAUSER_ROLE");␊ + const UPGRADER_ROLE: felt252 = selector!("UPGRADER_ROLE");␊ + ␊ + #[starknet::contract]␊ + mod MyToken {␊ + use openzeppelin::access::accesscontrol::{AccessControlComponent, DEFAULT_ADMIN_ROLE};␊ + use openzeppelin::introspection::src5::SRC5Component;␊ + use openzeppelin::security::pausable::PausableComponent;␊ + use openzeppelin::token::erc20::ERC20Component;␊ + use openzeppelin::upgrades::interface::IUpgradeable;␊ + use openzeppelin::upgrades::UpgradeableComponent;␊ + use starknet::{ClassHash, ContractAddress};␊ + use super::{PAUSER_ROLE, UPGRADER_ROLE};␊ + ␊ + component!(path: ERC20Component, storage: erc20, event: ERC20Event);␊ + component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ + component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent);␊ + component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ + component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ + ␊ + // External␊ + #[abi(embed_v0)]␊ + impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl;␊ + #[abi(embed_v0)]␊ + impl PausableImpl = PausableComponent::PausableImpl;␊ + #[abi(embed_v0)]␊ + impl AccessControlMixinImpl = AccessControlComponent::AccessControlMixinImpl;␊ + ␊ + // Internal␊ + impl ERC20InternalImpl = ERC20Component::InternalImpl;␊ + impl PausableInternalImpl = PausableComponent::InternalImpl;␊ + impl AccessControlInternalImpl = AccessControlComponent::InternalImpl;␊ + impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ + ␊ + #[storage]␊ + struct Storage {␊ + #[substorage(v0)]␊ + erc20: ERC20Component::Storage,␊ + #[substorage(v0)]␊ + pausable: PausableComponent::Storage,␊ + #[substorage(v0)]␊ + accesscontrol: AccessControlComponent::Storage,␊ + #[substorage(v0)]␊ + src5: SRC5Component::Storage,␊ + #[substorage(v0)]␊ + upgradeable: UpgradeableComponent::Storage,␊ + }␊ + ␊ + #[event]␊ + #[derive(Drop, starknet::Event)]␊ + enum Event {␊ + #[flat]␊ + ERC20Event: ERC20Component::Event,␊ + #[flat]␊ + PausableEvent: PausableComponent::Event,␊ + #[flat]␊ + AccessControlEvent: AccessControlComponent::Event,␊ + #[flat]␊ + SRC5Event: SRC5Component::Event,␊ + #[flat]␊ + UpgradeableEvent: UpgradeableComponent::Event,␊ + }␊ + ␊ + #[constructor]␊ + fn constructor(␊ + ref self: ContractState,␊ + default_admin: ContractAddress,␊ + pauser: ContractAddress,␊ + upgrader: ContractAddress,␊ + ) {␊ + self.erc20.initializer("MyToken", "MTK");␊ + self.accesscontrol.initializer();␊ + ␊ + self.accesscontrol._grant_role(DEFAULT_ADMIN_ROLE, default_admin);␊ + self.accesscontrol._grant_role(PAUSER_ROLE, pauser);␊ + self.accesscontrol._grant_role(UPGRADER_ROLE, upgrader);␊ + }␊ + ␊ + impl ERC20HooksImpl of ERC20Component::ERC20HooksTrait {␊ + fn before_update(␊ + ref self: ERC20Component::ComponentState,␊ + from: ContractAddress,␊ + recipient: ContractAddress,␊ + amount: u256,␊ + ) {␊ + let contract_state = self.get_contract();␊ + contract_state.pausable.assert_not_paused();␊ + }␊ + }␊ + ␊ + #[generate_trait]␊ + #[abi(per_item)]␊ + impl ExternalImpl of ExternalTrait {␊ + #[external(v0)]␊ + fn pause(ref self: ContractState) {␊ + self.accesscontrol.assert_only_role(PAUSER_ROLE);␊ + self.pausable.pause();␊ + }␊ + ␊ + #[external(v0)]␊ + fn unpause(ref self: ContractState) {␊ + self.accesscontrol.assert_only_role(PAUSER_ROLE);␊ + self.pausable.unpause();␊ + }␊ + }␊ + ␊ + //␊ + // Upgradeable␊ + //␊ + ␊ + #[abi(embed_v0)]␊ + impl UpgradeableImpl of IUpgradeable {␊ + fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ + self.accesscontrol.assert_only_role(UPGRADER_ROLE);␊ + self.upgradeable.upgrade(new_class_hash);␊ + }␊ + }␊ + }␊ + ` + +## erc20 burnable pausable + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + #[starknet::contract]␊ + mod MyToken {␊ + use openzeppelin::access::ownable::OwnableComponent;␊ + use openzeppelin::security::pausable::PausableComponent;␊ + use openzeppelin::token::erc20::ERC20Component;␊ + use openzeppelin::upgrades::interface::IUpgradeable;␊ + use openzeppelin::upgrades::UpgradeableComponent;␊ + use starknet::{ClassHash, ContractAddress, get_caller_address};␊ + ␊ + component!(path: ERC20Component, storage: erc20, event: ERC20Event);␊ + component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ + component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ + component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ + ␊ + // External␊ + #[abi(embed_v0)]␊ + impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl;␊ + #[abi(embed_v0)]␊ + impl PausableImpl = PausableComponent::PausableImpl;␊ + #[abi(embed_v0)]␊ + impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ + ␊ + // Internal␊ + impl ERC20InternalImpl = ERC20Component::InternalImpl;␊ + impl PausableInternalImpl = PausableComponent::InternalImpl;␊ + impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ + impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ + ␊ + #[storage]␊ + struct Storage {␊ + #[substorage(v0)]␊ + erc20: ERC20Component::Storage,␊ + #[substorage(v0)]␊ + pausable: PausableComponent::Storage,␊ + #[substorage(v0)]␊ + ownable: OwnableComponent::Storage,␊ + #[substorage(v0)]␊ + upgradeable: UpgradeableComponent::Storage,␊ + }␊ + ␊ + #[event]␊ + #[derive(Drop, starknet::Event)]␊ + enum Event {␊ + #[flat]␊ + ERC20Event: ERC20Component::Event,␊ + #[flat]␊ + PausableEvent: PausableComponent::Event,␊ + #[flat]␊ + OwnableEvent: OwnableComponent::Event,␊ + #[flat]␊ + UpgradeableEvent: UpgradeableComponent::Event,␊ + }␊ + ␊ + #[constructor]␊ + fn constructor(ref self: ContractState, owner: ContractAddress) {␊ + self.erc20.initializer("MyToken", "MTK");␊ + self.ownable.initializer(owner);␊ + }␊ + ␊ + impl ERC20HooksImpl of ERC20Component::ERC20HooksTrait {␊ + fn before_update(␊ + ref self: ERC20Component::ComponentState,␊ + from: ContractAddress,␊ + recipient: ContractAddress,␊ + amount: u256,␊ + ) {␊ + let contract_state = self.get_contract();␊ + contract_state.pausable.assert_not_paused();␊ + }␊ + }␊ + ␊ + #[generate_trait]␊ + #[abi(per_item)]␊ + impl ExternalImpl of ExternalTrait {␊ + #[external(v0)]␊ + fn pause(ref self: ContractState) {␊ + self.ownable.assert_only_owner();␊ + self.pausable.pause();␊ + }␊ + ␊ + #[external(v0)]␊ + fn unpause(ref self: ContractState) {␊ + self.ownable.assert_only_owner();␊ + self.pausable.unpause();␊ + }␊ + ␊ + #[external(v0)]␊ + fn burn(ref self: ContractState, value: u256) {␊ + self.erc20.burn(get_caller_address(), value);␊ + }␊ + }␊ + ␊ + //␊ + // Upgradeable␊ + //␊ + ␊ + #[abi(embed_v0)]␊ + impl UpgradeableImpl of IUpgradeable {␊ + fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ + self.ownable.assert_only_owner();␊ + self.upgradeable.upgrade(new_class_hash);␊ + }␊ + }␊ + }␊ + ` + +## erc20 preminted + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + #[starknet::contract]␊ + mod MyToken {␊ + use openzeppelin::access::ownable::OwnableComponent;␊ + use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl};␊ + use openzeppelin::upgrades::interface::IUpgradeable;␊ + use openzeppelin::upgrades::UpgradeableComponent;␊ + use starknet::{ClassHash, ContractAddress};␊ + ␊ + component!(path: ERC20Component, storage: erc20, event: ERC20Event);␊ + component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ + component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ + ␊ + // External␊ + #[abi(embed_v0)]␊ + impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl;␊ + #[abi(embed_v0)]␊ + impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ + ␊ + // Internal␊ + impl ERC20InternalImpl = ERC20Component::InternalImpl;␊ + impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ + impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ + ␊ + #[storage]␊ + struct Storage {␊ + #[substorage(v0)]␊ + erc20: ERC20Component::Storage,␊ + #[substorage(v0)]␊ + upgradeable: UpgradeableComponent::Storage,␊ + #[substorage(v0)]␊ + ownable: OwnableComponent::Storage,␊ + }␊ + ␊ + #[event]␊ + #[derive(Drop, starknet::Event)]␊ + enum Event {␊ + #[flat]␊ + ERC20Event: ERC20Component::Event,␊ + #[flat]␊ + UpgradeableEvent: UpgradeableComponent::Event,␊ + #[flat]␊ + OwnableEvent: OwnableComponent::Event,␊ + }␊ + ␊ + #[constructor]␊ + fn constructor(ref self: ContractState, recipient: ContractAddress, owner: ContractAddress) {␊ + self.erc20.initializer("MyToken", "MTK");␊ + self.ownable.initializer(owner);␊ + ␊ + self.erc20.mint(recipient, 1000000000000000000000);␊ + }␊ + ␊ + //␊ + // Upgradeable␊ + //␊ + ␊ + #[abi(embed_v0)]␊ + impl UpgradeableImpl of IUpgradeable {␊ + fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ + self.ownable.assert_only_owner();␊ + self.upgradeable.upgrade(new_class_hash);␊ + }␊ + }␊ + }␊ + ` + +## erc20 premint of 0 + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + #[starknet::contract]␊ + mod MyToken {␊ + use openzeppelin::access::ownable::OwnableComponent;␊ + use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl};␊ + use openzeppelin::upgrades::interface::IUpgradeable;␊ + use openzeppelin::upgrades::UpgradeableComponent;␊ + use starknet::{ClassHash, ContractAddress};␊ + ␊ + component!(path: ERC20Component, storage: erc20, event: ERC20Event);␊ + component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ + component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ + ␊ + // External␊ + #[abi(embed_v0)]␊ + impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl;␊ + #[abi(embed_v0)]␊ + impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ + ␊ + // Internal␊ + impl ERC20InternalImpl = ERC20Component::InternalImpl;␊ + impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ + impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ + ␊ + #[storage]␊ + struct Storage {␊ + #[substorage(v0)]␊ + erc20: ERC20Component::Storage,␊ + #[substorage(v0)]␊ + upgradeable: UpgradeableComponent::Storage,␊ + #[substorage(v0)]␊ + ownable: OwnableComponent::Storage,␊ + }␊ + ␊ + #[event]␊ + #[derive(Drop, starknet::Event)]␊ + enum Event {␊ + #[flat]␊ + ERC20Event: ERC20Component::Event,␊ + #[flat]␊ + UpgradeableEvent: UpgradeableComponent::Event,␊ + #[flat]␊ + OwnableEvent: OwnableComponent::Event,␊ + }␊ + ␊ + #[constructor]␊ + fn constructor(ref self: ContractState, owner: ContractAddress) {␊ + self.erc20.initializer("MyToken", "MTK");␊ + self.ownable.initializer(owner);␊ + }␊ + ␊ + //␊ + // Upgradeable␊ + //␊ + ␊ + #[abi(embed_v0)]␊ + impl UpgradeableImpl of IUpgradeable {␊ + fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ + self.ownable.assert_only_owner();␊ + self.upgradeable.upgrade(new_class_hash);␊ + }␊ + }␊ + }␊ + ` + +## erc20 mintable + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + #[starknet::contract]␊ + mod MyToken {␊ + use openzeppelin::access::ownable::OwnableComponent;␊ + use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl};␊ + use openzeppelin::upgrades::interface::IUpgradeable;␊ + use openzeppelin::upgrades::UpgradeableComponent;␊ + use starknet::{ClassHash, ContractAddress};␊ + ␊ + component!(path: ERC20Component, storage: erc20, event: ERC20Event);␊ + component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ + component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ + ␊ + // External␊ + #[abi(embed_v0)]␊ + impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl;␊ + #[abi(embed_v0)]␊ + impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ + ␊ + // Internal␊ + impl ERC20InternalImpl = ERC20Component::InternalImpl;␊ + impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ + impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ + ␊ + #[storage]␊ + struct Storage {␊ + #[substorage(v0)]␊ + erc20: ERC20Component::Storage,␊ + #[substorage(v0)]␊ + ownable: OwnableComponent::Storage,␊ + #[substorage(v0)]␊ + upgradeable: UpgradeableComponent::Storage,␊ + }␊ + ␊ + #[event]␊ + #[derive(Drop, starknet::Event)]␊ + enum Event {␊ + #[flat]␊ + ERC20Event: ERC20Component::Event,␊ + #[flat]␊ + OwnableEvent: OwnableComponent::Event,␊ + #[flat]␊ + UpgradeableEvent: UpgradeableComponent::Event,␊ + }␊ + ␊ + #[constructor]␊ + fn constructor(ref self: ContractState, owner: ContractAddress) {␊ + self.erc20.initializer("MyToken", "MTK");␊ + self.ownable.initializer(owner);␊ + }␊ + ␊ + #[generate_trait]␊ + #[abi(per_item)]␊ + impl ExternalImpl of ExternalTrait {␊ + #[external(v0)]␊ + fn mint(ref self: ContractState, recipient: ContractAddress, amount: u256) {␊ + self.ownable.assert_only_owner();␊ + self.erc20.mint(recipient, amount);␊ + }␊ + }␊ + ␊ + //␊ + // Upgradeable␊ + //␊ + ␊ + #[abi(embed_v0)]␊ + impl UpgradeableImpl of IUpgradeable {␊ + fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ + self.ownable.assert_only_owner();␊ + self.upgradeable.upgrade(new_class_hash);␊ + }␊ + }␊ + }␊ + ` + +## erc20 mintable with roles + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + const MINTER_ROLE: felt252 = selector!("MINTER_ROLE");␊ + const UPGRADER_ROLE: felt252 = selector!("UPGRADER_ROLE");␊ + ␊ + #[starknet::contract]␊ + mod MyToken {␊ + use openzeppelin::access::accesscontrol::{AccessControlComponent, DEFAULT_ADMIN_ROLE};␊ + use openzeppelin::introspection::src5::SRC5Component;␊ + use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl};␊ + use openzeppelin::upgrades::interface::IUpgradeable;␊ + use openzeppelin::upgrades::UpgradeableComponent;␊ + use starknet::{ClassHash, ContractAddress};␊ + use super::{MINTER_ROLE, UPGRADER_ROLE};␊ + ␊ + component!(path: ERC20Component, storage: erc20, event: ERC20Event);␊ + component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent);␊ + component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ + component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ + ␊ + // External␊ + #[abi(embed_v0)]␊ + impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl;␊ + #[abi(embed_v0)]␊ + impl AccessControlMixinImpl = AccessControlComponent::AccessControlMixinImpl;␊ + ␊ + // Internal␊ + impl ERC20InternalImpl = ERC20Component::InternalImpl;␊ + impl AccessControlInternalImpl = AccessControlComponent::InternalImpl;␊ + impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ + ␊ + #[storage]␊ + struct Storage {␊ + #[substorage(v0)]␊ + erc20: ERC20Component::Storage,␊ + #[substorage(v0)]␊ + accesscontrol: AccessControlComponent::Storage,␊ + #[substorage(v0)]␊ + src5: SRC5Component::Storage,␊ + #[substorage(v0)]␊ + upgradeable: UpgradeableComponent::Storage,␊ + }␊ + ␊ + #[event]␊ + #[derive(Drop, starknet::Event)]␊ + enum Event {␊ + #[flat]␊ + ERC20Event: ERC20Component::Event,␊ + #[flat]␊ + AccessControlEvent: AccessControlComponent::Event,␊ + #[flat]␊ + SRC5Event: SRC5Component::Event,␊ + #[flat]␊ + UpgradeableEvent: UpgradeableComponent::Event,␊ + }␊ + ␊ + #[constructor]␊ + fn constructor(␊ + ref self: ContractState,␊ + default_admin: ContractAddress,␊ + minter: ContractAddress,␊ + upgrader: ContractAddress,␊ + ) {␊ + self.erc20.initializer("MyToken", "MTK");␊ + self.accesscontrol.initializer();␊ + ␊ + self.accesscontrol._grant_role(DEFAULT_ADMIN_ROLE, default_admin);␊ + self.accesscontrol._grant_role(MINTER_ROLE, minter);␊ + self.accesscontrol._grant_role(UPGRADER_ROLE, upgrader);␊ + }␊ + ␊ + #[generate_trait]␊ + #[abi(per_item)]␊ + impl ExternalImpl of ExternalTrait {␊ + #[external(v0)]␊ + fn mint(ref self: ContractState, recipient: ContractAddress, amount: u256) {␊ + self.accesscontrol.assert_only_role(MINTER_ROLE);␊ + self.erc20.mint(recipient, amount);␊ + }␊ + }␊ + ␊ + //␊ + // Upgradeable␊ + //␊ + ␊ + #[abi(embed_v0)]␊ + impl UpgradeableImpl of IUpgradeable {␊ + fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ + self.accesscontrol.assert_only_role(UPGRADER_ROLE);␊ + self.upgradeable.upgrade(new_class_hash);␊ + }␊ + }␊ + }␊ + ` + +## erc20 votes + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + #[starknet::contract]␊ + mod MyToken {␊ + use openzeppelin::access::ownable::OwnableComponent;␊ + use openzeppelin::governance::votes::VotesComponent;␊ + use openzeppelin::token::erc20::ERC20Component;␊ + use openzeppelin::upgrades::interface::IUpgradeable;␊ + use openzeppelin::upgrades::UpgradeableComponent;␊ + use openzeppelin::utils::cryptography::nonces::NoncesComponent;␊ + use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ + use starknet::{ClassHash, ContractAddress};␊ + ␊ + component!(path: ERC20Component, storage: erc20, event: ERC20Event);␊ + component!(path: NoncesComponent, storage: nonces, event: NoncesEvent);␊ + component!(path: VotesComponent, storage: votes, event: VotesEvent);␊ + component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ + component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ + ␊ + // External␊ + #[abi(embed_v0)]␊ + impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl;␊ + #[abi(embed_v0)]␊ + impl NoncesImpl = NoncesComponent::NoncesImpl;␊ + #[abi(embed_v0)]␊ + impl VotesImpl = VotesComponent::VotesImpl;␊ + #[abi(embed_v0)]␊ + impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ + ␊ + // Internal␊ + impl ERC20InternalImpl = ERC20Component::InternalImpl;␊ + impl VotesInternalImpl = VotesComponent::InternalImpl;␊ + impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ + impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ + ␊ + #[storage]␊ + struct Storage {␊ + #[substorage(v0)]␊ + erc20: ERC20Component::Storage,␊ + #[substorage(v0)]␊ + nonces: NoncesComponent::Storage,␊ + #[substorage(v0)]␊ + votes: VotesComponent::Storage,␊ + #[substorage(v0)]␊ + upgradeable: UpgradeableComponent::Storage,␊ + #[substorage(v0)]␊ + ownable: OwnableComponent::Storage,␊ + }␊ + ␊ + #[event]␊ + #[derive(Drop, starknet::Event)]␊ + enum Event {␊ + #[flat]␊ + ERC20Event: ERC20Component::Event,␊ + #[flat]␊ + NoncesEvent: NoncesComponent::Event,␊ + #[flat]␊ + VotesEvent: VotesComponent::Event,␊ + #[flat]␊ + UpgradeableEvent: UpgradeableComponent::Event,␊ + #[flat]␊ + OwnableEvent: OwnableComponent::Event,␊ + }␊ + ␊ + #[constructor]␊ + fn constructor(ref self: ContractState, owner: ContractAddress) {␊ + self.erc20.initializer("MyToken", "MTK");␊ + self.ownable.initializer(owner);␊ + }␊ + ␊ + impl ERC20HooksImpl of ERC20Component::ERC20HooksTrait {␊ + fn after_update(␊ + ref self: ERC20Component::ComponentState,␊ + from: ContractAddress,␊ + recipient: ContractAddress,␊ + amount: u256,␊ + ) {␊ + let mut contract_state = self.get_contract_mut();␊ + contract_state.votes.transfer_voting_units(from, recipient, amount);␊ + }␊ + }␊ + ␊ + //␊ + // SNIP12 Metadata␊ + //␊ + ␊ + impl SNIP12MetadataImpl of SNIP12Metadata {␊ + fn name() -> felt252 {␊ + 'MY_DAPP_NAME'␊ + }␊ + ␊ + fn version() -> felt252 {␊ + 'v1'␊ + }␊ + }␊ + ␊ + //␊ + // Upgradeable␊ + //␊ + ␊ + #[abi(embed_v0)]␊ + impl UpgradeableImpl of IUpgradeable {␊ + fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ + self.ownable.assert_only_owner();␊ + self.upgradeable.upgrade(new_class_hash);␊ + }␊ + }␊ + }␊ + ` + +## erc20 votes, version + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + #[starknet::contract]␊ + mod MyToken {␊ + use openzeppelin::access::ownable::OwnableComponent;␊ + use openzeppelin::governance::votes::VotesComponent;␊ + use openzeppelin::token::erc20::ERC20Component;␊ + use openzeppelin::upgrades::interface::IUpgradeable;␊ + use openzeppelin::upgrades::UpgradeableComponent;␊ + use openzeppelin::utils::cryptography::nonces::NoncesComponent;␊ + use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ + use starknet::{ClassHash, ContractAddress};␊ + ␊ + component!(path: ERC20Component, storage: erc20, event: ERC20Event);␊ + component!(path: NoncesComponent, storage: nonces, event: NoncesEvent);␊ + component!(path: VotesComponent, storage: votes, event: VotesEvent);␊ + component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ + component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ + ␊ + // External␊ + #[abi(embed_v0)]␊ + impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl;␊ + #[abi(embed_v0)]␊ + impl NoncesImpl = NoncesComponent::NoncesImpl;␊ + #[abi(embed_v0)]␊ + impl VotesImpl = VotesComponent::VotesImpl;␊ + #[abi(embed_v0)]␊ + impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ + ␊ + // Internal␊ + impl ERC20InternalImpl = ERC20Component::InternalImpl;␊ + impl VotesInternalImpl = VotesComponent::InternalImpl;␊ + impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ + impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ + ␊ + #[storage]␊ + struct Storage {␊ + #[substorage(v0)]␊ + erc20: ERC20Component::Storage,␊ + #[substorage(v0)]␊ + nonces: NoncesComponent::Storage,␊ + #[substorage(v0)]␊ + votes: VotesComponent::Storage,␊ + #[substorage(v0)]␊ + upgradeable: UpgradeableComponent::Storage,␊ + #[substorage(v0)]␊ + ownable: OwnableComponent::Storage,␊ + }␊ + ␊ + #[event]␊ + #[derive(Drop, starknet::Event)]␊ + enum Event {␊ + #[flat]␊ + ERC20Event: ERC20Component::Event,␊ + #[flat]␊ + NoncesEvent: NoncesComponent::Event,␊ + #[flat]␊ + VotesEvent: VotesComponent::Event,␊ + #[flat]␊ + UpgradeableEvent: UpgradeableComponent::Event,␊ + #[flat]␊ + OwnableEvent: OwnableComponent::Event,␊ + }␊ + ␊ + #[constructor]␊ + fn constructor(ref self: ContractState, owner: ContractAddress) {␊ + self.erc20.initializer("MyToken", "MTK");␊ + self.ownable.initializer(owner);␊ + }␊ + ␊ + impl ERC20HooksImpl of ERC20Component::ERC20HooksTrait {␊ + fn after_update(␊ + ref self: ERC20Component::ComponentState,␊ + from: ContractAddress,␊ + recipient: ContractAddress,␊ + amount: u256,␊ + ) {␊ + let mut contract_state = self.get_contract_mut();␊ + contract_state.votes.transfer_voting_units(from, recipient, amount);␊ + }␊ + }␊ + ␊ + //␊ + // SNIP12 Metadata␊ + //␊ + ␊ + impl SNIP12MetadataImpl of SNIP12Metadata {␊ + fn name() -> felt252 {␊ + 'MY_DAPP_NAME'␊ + }␊ + ␊ + fn version() -> felt252 {␊ + 'MY_DAPP_VERSION'␊ + }␊ + }␊ + ␊ + //␊ + // Upgradeable␊ + //␊ + ␊ + #[abi(embed_v0)]␊ + impl UpgradeableImpl of IUpgradeable {␊ + fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ + self.ownable.assert_only_owner();␊ + self.upgradeable.upgrade(new_class_hash);␊ + }␊ + }␊ + }␊ + ` + +## erc20 votes, non-upgradeable + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + #[starknet::contract]␊ + mod MyToken {␊ + use openzeppelin::governance::votes::VotesComponent;␊ + use openzeppelin::token::erc20::ERC20Component;␊ + use openzeppelin::utils::cryptography::nonces::NoncesComponent;␊ + use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ + ␊ + component!(path: ERC20Component, storage: erc20, event: ERC20Event);␊ + component!(path: NoncesComponent, storage: nonces, event: NoncesEvent);␊ + component!(path: VotesComponent, storage: votes, event: VotesEvent);␊ + ␊ + // External␊ + #[abi(embed_v0)]␊ + impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl;␊ + #[abi(embed_v0)]␊ + impl NoncesImpl = NoncesComponent::NoncesImpl;␊ + #[abi(embed_v0)]␊ + impl VotesImpl = VotesComponent::VotesImpl;␊ + ␊ + // Internal␊ + impl ERC20InternalImpl = ERC20Component::InternalImpl;␊ + impl VotesInternalImpl = VotesComponent::InternalImpl;␊ + ␊ + #[storage]␊ + struct Storage {␊ + #[substorage(v0)]␊ + erc20: ERC20Component::Storage,␊ + #[substorage(v0)]␊ + nonces: NoncesComponent::Storage,␊ + #[substorage(v0)]␊ + votes: VotesComponent::Storage,␊ + }␊ + ␊ + #[event]␊ + #[derive(Drop, starknet::Event)]␊ + enum Event {␊ + #[flat]␊ + ERC20Event: ERC20Component::Event,␊ + #[flat]␊ + NoncesEvent: NoncesComponent::Event,␊ + #[flat]␊ + VotesEvent: VotesComponent::Event,␊ + }␊ + ␊ + #[constructor]␊ + fn constructor(ref self: ContractState) {␊ + self.erc20.initializer("MyToken", "MTK");␊ + }␊ + ␊ + impl ERC20HooksImpl of ERC20Component::ERC20HooksTrait {␊ + fn after_update(␊ + ref self: ERC20Component::ComponentState,␊ + from: ContractAddress,␊ + recipient: ContractAddress,␊ + amount: u256,␊ + ) {␊ + let mut contract_state = self.get_contract_mut();␊ + contract_state.votes.transfer_voting_units(from, recipient, amount);␊ + }␊ + }␊ + ␊ + //␊ + // SNIP12 Metadata␊ + //␊ + ␊ + impl SNIP12MetadataImpl of SNIP12Metadata {␊ + fn name() -> felt252 {␊ + 'MY_DAPP_NAME'␊ + }␊ + ␊ + fn version() -> felt252 {␊ + 'v1'␊ + }␊ + }␊ + }␊ + ` + +## erc20 full, non-upgradeable + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + #[starknet::contract]␊ + mod MyToken {␊ + use openzeppelin::access::ownable::OwnableComponent;␊ + use openzeppelin::governance::votes::VotesComponent;␊ + use openzeppelin::security::pausable::PausableComponent;␊ + use openzeppelin::token::erc20::ERC20Component;␊ + use openzeppelin::utils::cryptography::nonces::NoncesComponent;␊ + use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ + use starknet::{ContractAddress, get_caller_address};␊ + ␊ + component!(path: ERC20Component, storage: erc20, event: ERC20Event);␊ + component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ + component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ + component!(path: NoncesComponent, storage: nonces, event: NoncesEvent);␊ + component!(path: VotesComponent, storage: votes, event: VotesEvent);␊ + ␊ + // External␊ + #[abi(embed_v0)]␊ + impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl;␊ + #[abi(embed_v0)]␊ + impl PausableImpl = PausableComponent::PausableImpl;␊ + #[abi(embed_v0)]␊ + impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ + #[abi(embed_v0)]␊ + impl NoncesImpl = NoncesComponent::NoncesImpl;␊ + #[abi(embed_v0)]␊ + impl VotesImpl = VotesComponent::VotesImpl;␊ + ␊ + // Internal␊ + impl ERC20InternalImpl = ERC20Component::InternalImpl;␊ + impl PausableInternalImpl = PausableComponent::InternalImpl;␊ + impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ + impl VotesInternalImpl = VotesComponent::InternalImpl;␊ + ␊ + #[storage]␊ + struct Storage {␊ + #[substorage(v0)]␊ + erc20: ERC20Component::Storage,␊ + #[substorage(v0)]␊ + pausable: PausableComponent::Storage,␊ + #[substorage(v0)]␊ + ownable: OwnableComponent::Storage,␊ + #[substorage(v0)]␊ + nonces: NoncesComponent::Storage,␊ + #[substorage(v0)]␊ + votes: VotesComponent::Storage,␊ + }␊ + ␊ + #[event]␊ + #[derive(Drop, starknet::Event)]␊ + enum Event {␊ + #[flat]␊ + ERC20Event: ERC20Component::Event,␊ + #[flat]␊ + PausableEvent: PausableComponent::Event,␊ + #[flat]␊ + OwnableEvent: OwnableComponent::Event,␊ + #[flat]␊ + NoncesEvent: NoncesComponent::Event,␊ + #[flat]␊ + VotesEvent: VotesComponent::Event,␊ + }␊ + ␊ + #[constructor]␊ + fn constructor(ref self: ContractState, recipient: ContractAddress, owner: ContractAddress) {␊ + self.erc20.initializer("MyToken", "MTK");␊ + self.ownable.initializer(owner);␊ + ␊ + self.erc20.mint(recipient, 2000000000000000000000);␊ + }␊ + ␊ + impl ERC20HooksImpl of ERC20Component::ERC20HooksTrait {␊ + fn before_update(␊ + ref self: ERC20Component::ComponentState,␊ + from: ContractAddress,␊ + recipient: ContractAddress,␊ + amount: u256,␊ + ) {␊ + let contract_state = self.get_contract();␊ + contract_state.pausable.assert_not_paused();␊ + }␊ + ␊ + fn after_update(␊ + ref self: ERC20Component::ComponentState,␊ + from: ContractAddress,␊ + recipient: ContractAddress,␊ + amount: u256,␊ + ) {␊ + let mut contract_state = self.get_contract_mut();␊ + contract_state.votes.transfer_voting_units(from, recipient, amount);␊ + }␊ + }␊ + ␊ + #[generate_trait]␊ + #[abi(per_item)]␊ + impl ExternalImpl of ExternalTrait {␊ + #[external(v0)]␊ + fn pause(ref self: ContractState) {␊ + self.ownable.assert_only_owner();␊ + self.pausable.pause();␊ + }␊ + ␊ + #[external(v0)]␊ + fn unpause(ref self: ContractState) {␊ + self.ownable.assert_only_owner();␊ + self.pausable.unpause();␊ + }␊ + ␊ + #[external(v0)]␊ + fn burn(ref self: ContractState, value: u256) {␊ + self.erc20.burn(get_caller_address(), value);␊ + }␊ + ␊ + #[external(v0)]␊ + fn mint(ref self: ContractState, recipient: ContractAddress, amount: u256) {␊ + self.ownable.assert_only_owner();␊ + self.erc20.mint(recipient, amount);␊ + }␊ + }␊ + ␊ + //␊ + // SNIP12 Metadata␊ + //␊ + ␊ + impl SNIP12MetadataImpl of SNIP12Metadata {␊ + fn name() -> felt252 {␊ + 'MY_DAPP_NAME'␊ + }␊ + ␊ + fn version() -> felt252 {␊ + 'MY_DAPP_VERSION'␊ + }␊ + }␊ + }␊ + ` + +## erc20 full upgradeable + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + #[starknet::contract]␊ + mod MyToken {␊ + use openzeppelin::access::ownable::OwnableComponent;␊ + use openzeppelin::governance::votes::VotesComponent;␊ + use openzeppelin::security::pausable::PausableComponent;␊ + use openzeppelin::token::erc20::ERC20Component;␊ + use openzeppelin::upgrades::interface::IUpgradeable;␊ + use openzeppelin::upgrades::UpgradeableComponent;␊ + use openzeppelin::utils::cryptography::nonces::NoncesComponent;␊ + use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ + use starknet::{ClassHash, ContractAddress, get_caller_address};␊ + ␊ + component!(path: ERC20Component, storage: erc20, event: ERC20Event);␊ + component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ + component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ + component!(path: NoncesComponent, storage: nonces, event: NoncesEvent);␊ + component!(path: VotesComponent, storage: votes, event: VotesEvent);␊ + component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ + ␊ + // External␊ + #[abi(embed_v0)]␊ + impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl;␊ + #[abi(embed_v0)]␊ + impl PausableImpl = PausableComponent::PausableImpl;␊ + #[abi(embed_v0)]␊ + impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl;␊ + #[abi(embed_v0)]␊ + impl NoncesImpl = NoncesComponent::NoncesImpl;␊ + #[abi(embed_v0)]␊ + impl VotesImpl = VotesComponent::VotesImpl;␊ + ␊ + // Internal␊ + impl ERC20InternalImpl = ERC20Component::InternalImpl;␊ + impl PausableInternalImpl = PausableComponent::InternalImpl;␊ + impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ + impl VotesInternalImpl = VotesComponent::InternalImpl;␊ + impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ + ␊ + #[storage]␊ + struct Storage {␊ + #[substorage(v0)]␊ + erc20: ERC20Component::Storage,␊ + #[substorage(v0)]␊ + pausable: PausableComponent::Storage,␊ + #[substorage(v0)]␊ + ownable: OwnableComponent::Storage,␊ + #[substorage(v0)]␊ + nonces: NoncesComponent::Storage,␊ + #[substorage(v0)]␊ + votes: VotesComponent::Storage,␊ + #[substorage(v0)]␊ + upgradeable: UpgradeableComponent::Storage,␊ + }␊ + ␊ + #[event]␊ + #[derive(Drop, starknet::Event)]␊ + enum Event {␊ + #[flat]␊ + ERC20Event: ERC20Component::Event,␊ + #[flat]␊ + PausableEvent: PausableComponent::Event,␊ + #[flat]␊ + OwnableEvent: OwnableComponent::Event,␊ + #[flat]␊ + NoncesEvent: NoncesComponent::Event,␊ + #[flat]␊ + VotesEvent: VotesComponent::Event,␊ + #[flat]␊ + UpgradeableEvent: UpgradeableComponent::Event,␊ + }␊ + ␊ + #[constructor]␊ + fn constructor(ref self: ContractState, recipient: ContractAddress, owner: ContractAddress) {␊ + self.erc20.initializer("MyToken", "MTK");␊ + self.ownable.initializer(owner);␊ + ␊ + self.erc20.mint(recipient, 2000000000000000000000);␊ + }␊ + ␊ + impl ERC20HooksImpl of ERC20Component::ERC20HooksTrait {␊ + fn before_update(␊ + ref self: ERC20Component::ComponentState,␊ + from: ContractAddress,␊ + recipient: ContractAddress,␊ + amount: u256,␊ + ) {␊ + let contract_state = self.get_contract();␊ + contract_state.pausable.assert_not_paused();␊ + }␊ + ␊ + fn after_update(␊ + ref self: ERC20Component::ComponentState,␊ + from: ContractAddress,␊ + recipient: ContractAddress,␊ + amount: u256,␊ + ) {␊ + let mut contract_state = self.get_contract_mut();␊ + contract_state.votes.transfer_voting_units(from, recipient, amount);␊ + }␊ + }␊ + ␊ + #[generate_trait]␊ + #[abi(per_item)]␊ + impl ExternalImpl of ExternalTrait {␊ + #[external(v0)]␊ + fn pause(ref self: ContractState) {␊ + self.ownable.assert_only_owner();␊ + self.pausable.pause();␊ + }␊ + ␊ + #[external(v0)]␊ + fn unpause(ref self: ContractState) {␊ + self.ownable.assert_only_owner();␊ + self.pausable.unpause();␊ + }␊ + ␊ + #[external(v0)]␊ + fn burn(ref self: ContractState, value: u256) {␊ + self.erc20.burn(get_caller_address(), value);␊ + }␊ + ␊ + #[external(v0)]␊ + fn mint(ref self: ContractState, recipient: ContractAddress, amount: u256) {␊ + self.ownable.assert_only_owner();␊ + self.erc20.mint(recipient, amount);␊ + }␊ + }␊ + ␊ + //␊ + // SNIP12 Metadata␊ + //␊ + ␊ + impl SNIP12MetadataImpl of SNIP12Metadata {␊ + fn name() -> felt252 {␊ + 'MY_DAPP_NAME'␊ + }␊ + ␊ + fn version() -> felt252 {␊ + 'MY_DAPP_VERSION'␊ + }␊ + }␊ + ␊ + //␊ + // Upgradeable␊ + //␊ + ␊ + #[abi(embed_v0)]␊ + impl UpgradeableImpl of IUpgradeable {␊ + fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ + self.ownable.assert_only_owner();␊ + self.upgradeable.upgrade(new_class_hash);␊ + }␊ + }␊ + }␊ + ` + +## erc20 full upgradeable with roles + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊ + ␊ + const PAUSER_ROLE: felt252 = selector!("PAUSER_ROLE");␊ + const MINTER_ROLE: felt252 = selector!("MINTER_ROLE");␊ + const UPGRADER_ROLE: felt252 = selector!("UPGRADER_ROLE");␊ + ␊ + #[starknet::contract]␊ + mod MyToken {␊ + use openzeppelin::access::accesscontrol::{AccessControlComponent, DEFAULT_ADMIN_ROLE};␊ + use openzeppelin::governance::votes::VotesComponent;␊ + use openzeppelin::introspection::src5::SRC5Component;␊ + use openzeppelin::security::pausable::PausableComponent;␊ + use openzeppelin::token::erc20::ERC20Component;␊ + use openzeppelin::upgrades::interface::IUpgradeable;␊ + use openzeppelin::upgrades::UpgradeableComponent;␊ + use openzeppelin::utils::cryptography::nonces::NoncesComponent;␊ + use openzeppelin::utils::cryptography::snip12::SNIP12Metadata;␊ + use starknet::{ClassHash, ContractAddress, get_caller_address};␊ + use super::{MINTER_ROLE, PAUSER_ROLE, UPGRADER_ROLE};␊ + ␊ + component!(path: ERC20Component, storage: erc20, event: ERC20Event);␊ + component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ + component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent);␊ + component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ + component!(path: NoncesComponent, storage: nonces, event: NoncesEvent);␊ + component!(path: VotesComponent, storage: votes, event: VotesEvent);␊ + component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ + ␊ + // External␊ + #[abi(embed_v0)]␊ + impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl;␊ + #[abi(embed_v0)]␊ + impl PausableImpl = PausableComponent::PausableImpl;␊ + #[abi(embed_v0)]␊ + impl AccessControlMixinImpl = AccessControlComponent::AccessControlMixinImpl;␊ + #[abi(embed_v0)]␊ + impl NoncesImpl = NoncesComponent::NoncesImpl;␊ + #[abi(embed_v0)]␊ + impl VotesImpl = VotesComponent::VotesImpl;␊ + ␊ + // Internal␊ + impl ERC20InternalImpl = ERC20Component::InternalImpl;␊ + impl PausableInternalImpl = PausableComponent::InternalImpl;␊ + impl AccessControlInternalImpl = AccessControlComponent::InternalImpl;␊ + impl VotesInternalImpl = VotesComponent::InternalImpl;␊ + impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ + ␊ + #[storage]␊ + struct Storage {␊ + #[substorage(v0)]␊ + erc20: ERC20Component::Storage,␊ + #[substorage(v0)]␊ + pausable: PausableComponent::Storage,␊ + #[substorage(v0)]␊ + accesscontrol: AccessControlComponent::Storage,␊ + #[substorage(v0)]␊ + src5: SRC5Component::Storage,␊ + #[substorage(v0)]␊ + nonces: NoncesComponent::Storage,␊ + #[substorage(v0)]␊ + votes: VotesComponent::Storage,␊ + #[substorage(v0)]␊ + upgradeable: UpgradeableComponent::Storage,␊ + }␊ + ␊ + #[event]␊ + #[derive(Drop, starknet::Event)]␊ + enum Event {␊ + #[flat]␊ + ERC20Event: ERC20Component::Event,␊ + #[flat]␊ + PausableEvent: PausableComponent::Event,␊ + #[flat]␊ + AccessControlEvent: AccessControlComponent::Event,␊ + #[flat]␊ + SRC5Event: SRC5Component::Event,␊ + #[flat]␊ + NoncesEvent: NoncesComponent::Event,␊ + #[flat]␊ + VotesEvent: VotesComponent::Event,␊ + #[flat]␊ + UpgradeableEvent: UpgradeableComponent::Event,␊ + }␊ + ␊ + #[constructor]␊ + fn constructor(␊ + ref self: ContractState,␊ + recipient: ContractAddress,␊ + default_admin: ContractAddress,␊ + pauser: ContractAddress,␊ + minter: ContractAddress,␊ + upgrader: ContractAddress,␊ + ) {␊ + self.erc20.initializer("MyToken", "MTK");␊ + self.accesscontrol.initializer();␊ + ␊ + self.erc20.mint(recipient, 2000000000000000000000);␊ + self.accesscontrol._grant_role(DEFAULT_ADMIN_ROLE, default_admin);␊ + self.accesscontrol._grant_role(PAUSER_ROLE, pauser);␊ + self.accesscontrol._grant_role(MINTER_ROLE, minter);␊ + self.accesscontrol._grant_role(UPGRADER_ROLE, upgrader);␊ + }␊ + ␊ + impl ERC20HooksImpl of ERC20Component::ERC20HooksTrait {␊ + fn before_update(␊ + ref self: ERC20Component::ComponentState,␊ + from: ContractAddress,␊ + recipient: ContractAddress,␊ + amount: u256,␊ + ) {␊ + let contract_state = self.get_contract();␊ + contract_state.pausable.assert_not_paused();␊ + }␊ + ␊ + fn after_update(␊ + ref self: ERC20Component::ComponentState,␊ + from: ContractAddress,␊ + recipient: ContractAddress,␊ + amount: u256,␊ + ) {␊ + let mut contract_state = self.get_contract_mut();␊ + contract_state.votes.transfer_voting_units(from, recipient, amount);␊ + }␊ + }␊ + ␊ + #[generate_trait]␊ + #[abi(per_item)]␊ + impl ExternalImpl of ExternalTrait {␊ + #[external(v0)]␊ + fn pause(ref self: ContractState) {␊ + self.accesscontrol.assert_only_role(PAUSER_ROLE);␊ + self.pausable.pause();␊ + }␊ + ␊ + #[external(v0)]␊ + fn unpause(ref self: ContractState) {␊ + self.accesscontrol.assert_only_role(PAUSER_ROLE);␊ + self.pausable.unpause();␊ + }␊ + ␊ + #[external(v0)]␊ + fn burn(ref self: ContractState, value: u256) {␊ + self.erc20.burn(get_caller_address(), value);␊ + }␊ + ␊ + #[external(v0)]␊ + fn mint(ref self: ContractState, recipient: ContractAddress, amount: u256) {␊ + self.accesscontrol.assert_only_role(MINTER_ROLE);␊ + self.erc20.mint(recipient, amount);␊ + }␊ + }␊ + ␊ + //␊ + // SNIP12 Metadata␊ + //␊ + ␊ + impl SNIP12MetadataImpl of SNIP12Metadata {␊ + fn name() -> felt252 {␊ + 'MY_DAPP_NAME'␊ + }␊ + ␊ + fn version() -> felt252 {␊ + 'MY_DAPP_VERSION'␊ + }␊ + }␊ + ␊ + //␊ + // Upgradeable␊ + //␊ + ␊ + #[abi(embed_v0)]␊ + impl UpgradeableImpl of IUpgradeable {␊ + fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {␊ + self.accesscontrol.assert_only_role(UPGRADER_ROLE);␊ + self.upgradeable.upgrade(new_class_hash);␊ + }␊ + }␊ + }␊ + ` diff --git a/packages/core/stellar/src/erc20.test.ts.snap b/packages/core/stellar/src/erc20.test.ts.snap new file mode 100644 index 0000000000000000000000000000000000000000..42e963093102131a963546147234838e409def3e GIT binary patch literal 2779 zcmV<13MBPGRzVNFL{9DCLV3(-9Bm{U zpHHT}4IhgL00000000B+T}^M}xEY>yP;@8Q9qa&m*rHp2lR1n7I3E)rJ#e}Uq)FNh zI?1H@Sads>3XDu8LS#yiC{MD%9QqG>>U|6JC-mG)Zv}cT`Ue*M14V&e3hK+GOv{cf z+miD7;xFDoCLOssBdm=v=MXJYUo|~q(jNM zL+yYOFSvAh@cVB&9m2`i58pm~@WTh<^}QcFc=G+jhwJO;wu4c0I!FbBCgLHoru#J<5JdJ&!szLpv_xJ~4TKEZ0Xn#P(hEyN$KY zjkS%XrDtyfPW&rIImTv^@aE8bi0HQLSaCW>rwVif{HO0|6&|93*+0p zT2^!?cza&EV1_ndZ&-p0z?=tsNjIdR?t``TurCg}5AnHZ}H zewG^TgcDA`=oh!oq~iL>>CZ#J<-hgNq93A0$8`?4ADSGU#J?qdkfaOGlccSziQ*M^ z#6ZyrL_13NJ}oS==-cE=hx&Gpwsw8j6Shx>Lu~0d5oKW)ML#HYu^httHR$)xU^Swj zbCob%7Pr&&V-SlW>9>|oEfi44!bmaMic|&h_gd8QHJjPoCXW3L^;^ry;9YK`<%82- zEw8*xN`AkTT$NYSMLBp4eh@0xp!GpTuR&s(Gzc(u-!UEn-rP_s{xM+~|x_VolBa#<|^bNDzEUg3ESh(d|yhr$JEa+@b~2RZ@bJ=JX6y z%2EiO?==ZF>Ddf2NxGm}uoyk5n~a}tSvEo!GSg;AQpe=*biF(-YSOeE;-CqtvKka4 zNCR3w`0s?4&QKb2RBwgSWzAp9!)!7FM!tS^#wc-}Yzw1{1u8dHPQHF-Ig;K~@-=zo^oSFRxq5T!r&?kXTOz_3Tw+=)34n%f07ILap?M?>^bGAI zqA;}MkDA8N0&0f7&2KPHjezk{^68HBPMy`N&Esaz*#?X#VWpWa!6&R zSYT?#1bd(h`a`?X6fzg58K=v_0%;C2c z5X*PF0~TxN$}w%vj{2}L9qGEENF!MQ6R-~si%`- z*FRFVSgf6V*P+3nEc^IxiY)uf$1{~>(WH%zw$D!Xj*a8jul6vqsKYn6Hsfoais}4m zYgtMmrrtQ)+0ieLw|9#(DrrR45|m*49_4i%jBmH2?>q5#iSY04{bKv<)v2+)d$4~P zRbZ$K-WGWSkDA>}IEsRf&ceX%f4po_1`p~03#<$WKX{%$Sj*@iPpvqvCQJ7&X z*$N9#Mwf&u#$E;|5`ok$QR*uFBR4_c-x%vNG(!9;P0N7}GY1Ia>4mVmehoGC9T21S zN}W+aR8J(T2j}nM9W(+eo4W^kW`W8)D`Xgt&JuK}MM8%gq|>!ofv}7u!=R>b=LgrY zBqfM{<$_Xjrfb`fq{f9$7&inJZw<1=wrYdoQe`NG3B~pqKeNJ|+L`shkI{dDAEOjM zhB^jiC7d6{Rq<<-RO5T(=NMrzWwI&X^YKo-O|W1$`tg$D_V^#{MmNJxu$a3FVTZb5 zvK@A)VTT%asOu)CVTW4E0Xx*7>|lp_7CY4A)DiAruHCk|o9vqVv?~-$M-v184@ETo z6=LA49%KdqWs4VT_0dugP&OI?0?KM1P*y;W7b8b>*kTQCWi@T17aO`41lN~9e0+uY zh*rb-Kfrx}`vCU=?gQMXS=?vQ?pB~E(?pjGexl#cfAnXCp8OHc{{eaed+5!fC$KGD z9-$~kY0P#q>;`KV>*}5LlQ?=N@Kwp1wcRfuX>p*blma4D8_!g;^hxZg)cbRfJ%vcoMbYIt2XjL3B?L`YgqTCjW13*x zn8)abB#3#Gp_COkwol11kIm9TBLcG|bAmRytMO(W)piw&rJl=m^62rdB9FEnH_h{X z;r7JU!UXq^Y=H4s;;o)hY`I+Ab^?q||Hk9)g-^W88;qIDOaXKly-$V_Fxz{viSfzd z{?Uug1ImdQER}Q7=b9)X#YV`W;)I1*>Y$LIqCt}(Makf{hN*;5+#3mUt`F03I{|Fe zH3_QPo5>~L=q--8g(_0s3UDt+{F+|hC6nyn=)D6*yc!L365LTTsWOyic}>rZ$lRaU z2fGCBWT`{oAh9_08x}X%4abQcG`iua_`zthS>rxofkl0z=W?4}7$LKH&=M_^^x^o* zET)Gj<%a|6Eb3&HL#7?A{;GB)BVF2BL91V6TOg`oo*#T|>~0?&8Hd{kd(Wjx${;=J z2e!)!ae6PFk7{D=#pgUX=C~v^+i4GIH0Q4s&G~cCoS->DbAsjs%?X+lG$&|I(43$- zL31L|oK4i6Db81W$0z%*4?%#csi(X%^fN_)GMBANfSS0UwxUFTQq{Ph`3lN;E4+p) zHqb%CbWklc%DvNZCDBt5V)Bq`Rr8IY;%}Paj$_LSqgK zx(^;XUDkyhKMIaLaO{C&4;*{o*aOGj=t_ZOuO5!QTzerN;V$tAPxa2w!V{}M{g2`o z{qEB_oLGIdeRfiO@U)boe_}NpbUm?;ck&am!8=?*?{J2pJK|fqcIJNGclmzhnw%gG z{^|z!t7mm)dU2`X!Jg8CJ-g%L!JA!-P?k5ldI#8pXS`aT@hY6d-$eI%R>;Wn|Htt= zj{A&&$g@=RjDUJQL|_76|Bzy4^Z)`y62!)@($foI#{+geV8^2_J02q*Fd@w~RoMY4 hsm8D)QiJEWzz&H#oz!55WI@lX`9Cj4&yncS001yrdQSiV literal 0 HcmV?d00001 diff --git a/packages/core/stellar/src/erc20.ts b/packages/core/stellar/src/erc20.ts new file mode 100644 index 000000000..57cfe8d86 --- /dev/null +++ b/packages/core/stellar/src/erc20.ts @@ -0,0 +1,294 @@ +import { Contract, ContractBuilder } from './contract'; +import { Access, requireAccessControl, setAccessControl } from './set-access-control'; +import { addPausable } from './add-pausable'; +import { defineFunctions } from './utils/define-functions'; +import { CommonContractOptions, withCommonContractDefaults, getSelfArg } from './common-options'; +import { setUpgradeable } from './set-upgradeable'; +import { setInfo } from './set-info'; +import { OptionsError } from './error'; +import { defineComponents } from './utils/define-components'; +import { contractDefaults as commonDefaults } from './common-options'; +import { printContract } from './print'; +import { externalTrait } from './external-trait'; +import { toByteArray, toFelt252, toUint } from './utils/convert-strings'; +import { addVotesComponent } from './common-components'; + + +export const defaults: Required = { + name: 'MyToken', + symbol: 'MTK', + burnable: false, + pausable: false, + premint: '0', + mintable: false, + votes: false, + appName: '', // Defaults to empty string, but user must provide a non-empty value if votes are enabled + appVersion: 'v1', + access: commonDefaults.access, + upgradeable: commonDefaults.upgradeable, + info: commonDefaults.info +} as const; + +export function printERC20(opts: ERC20Options = defaults): string { + return printContract(buildERC20(opts)); +} + +export interface ERC20Options extends CommonContractOptions { + name: string; + symbol: string; + burnable?: boolean; + pausable?: boolean; + premint?: string; + mintable?: boolean; + votes?: boolean; + appName?: string; + appVersion?: string; +} + +function withDefaults(opts: ERC20Options): Required { + return { + ...opts, + ...withCommonContractDefaults(opts), + burnable: opts.burnable ?? defaults.burnable, + pausable: opts.pausable ?? defaults.pausable, + premint: opts.premint || defaults.premint, + mintable: opts.mintable ?? defaults.mintable, + votes: opts.votes ?? defaults.votes, + appName: opts.appName ?? defaults.appName, + appVersion: opts.appVersion ?? defaults.appVersion + }; +} + +export function isAccessControlRequired(opts: Partial): boolean { + return opts.mintable === true || opts.pausable === true || opts.upgradeable === true; +} + +export function buildERC20(opts: ERC20Options): Contract { + const c = new ContractBuilder(opts.name); + + const allOpts = withDefaults(opts); + + addBase(c, toByteArray(allOpts.name), toByteArray(allOpts.symbol)); + addERC20Mixin(c); + + if (allOpts.premint) { + addPremint(c, allOpts.premint); + } + + if (allOpts.pausable) { + addPausable(c, allOpts.access); + } + + if (allOpts.burnable) { + addBurnable(c); + } + + if (allOpts.mintable) { + addMintable(c, allOpts.access); + } + + addHooks(c, allOpts); + + setAccessControl(c, allOpts.access); + setUpgradeable(c, allOpts.upgradeable, allOpts.access); + setInfo(c, allOpts.info); + + return c; +} + +function addHooks(c: ContractBuilder, allOpts: Required) { + const usesCustomHooks = allOpts.pausable || allOpts.votes; + if (usesCustomHooks) { + const hooksTrait = { + name: 'ERC20HooksImpl', + of: 'ERC20Component::ERC20HooksTrait', + tags: [], + priority: 1, + }; + c.addImplementedTrait(hooksTrait); + + if (allOpts.pausable) { + const beforeUpdateFn = c.addFunction(hooksTrait, { + name: 'before_update', + args: [ + { name: 'ref self', type: 'ERC20Component::ComponentState' }, + { name: 'from', type: 'ContractAddress' }, + { name: 'recipient', type: 'ContractAddress' }, + { name: 'amount', type: 'u256' }, + ], + code: [], + }); + + beforeUpdateFn.code.push( + 'let contract_state = self.get_contract();', + 'contract_state.pausable.assert_not_paused();', + ); + } + + if (allOpts.votes) { + if (!allOpts.appName) { + throw new OptionsError({ + appName: 'Application Name is required when Votes are enabled', + }); + } + + if (!allOpts.appVersion) { + throw new OptionsError({ + appVersion: 'Application Version is required when Votes are enabled', + }); + } + + addVotesComponent( + c, + toFelt252(allOpts.appName, 'appName'), + toFelt252(allOpts.appVersion, 'appVersion'), + 'SNIP12 Metadata', + ); + + const afterUpdateFn = c.addFunction(hooksTrait, { + name: 'after_update', + args: [ + { name: 'ref self', type: 'ERC20Component::ComponentState' }, + { name: 'from', type: 'ContractAddress' }, + { name: 'recipient', type: 'ContractAddress' }, + { name: 'amount', type: 'u256' }, + ], + code: [], + }); + + afterUpdateFn.code.push( + 'let mut contract_state = self.get_contract_mut();', + 'contract_state.votes.transfer_voting_units(from, recipient, amount);', + ); + } + } else { + c.addUseClause('openzeppelin::token::erc20', 'ERC20HooksEmptyImpl'); + } +} + +function addERC20Mixin(c: ContractBuilder) { + c.addImplToComponent(components.ERC20Component, { + name: 'ERC20MixinImpl', + value: 'ERC20Component::ERC20MixinImpl', + }); +} + +function addBase(c: ContractBuilder, name: string, symbol: string) { + c.addComponent( + components.ERC20Component, + [ + name, symbol + ], + true, + ); +} + +function addBurnable(c: ContractBuilder) { + c.addUseClause('starknet', 'get_caller_address'); + c.addFunction(externalTrait, functions.burn); +} + +export const premintPattern = /^(\d*\.?\d*)$/; + +function addPremint(c: ContractBuilder, amount: string) { + if (amount !== undefined && amount !== '0') { + if (!premintPattern.test(amount)) { + throw new OptionsError({ + premint: 'Not a valid number', + }); + } + + const premintAbsolute = toUint(getInitialSupply(amount, 18), 'premint', 'u256'); + + c.addUseClause('starknet', 'ContractAddress'); + c.addConstructorArgument({ name:'recipient', type:'ContractAddress' }); + c.addConstructorCode(`self.erc20.mint(recipient, ${premintAbsolute})`); + } +} + +/** + * Calculates the initial supply that would be used in an ERC20 contract based on a given premint amount and number of decimals. + * + * @param premint Premint amount in token units, may be fractional + * @param decimals The number of decimals in the token + * @returns `premint` with zeros padded or removed based on `decimals`. + * @throws OptionsError if `premint` has more than one decimal character or is more precise than allowed by the `decimals` argument. + */ +export function getInitialSupply(premint: string, decimals: number): string { + let result; + const premintSegments = premint.split("."); + if (premintSegments.length > 2) { + throw new OptionsError({ + premint: 'Not a valid number', + }); + } else { + let firstSegment = premintSegments[0] ?? ''; + let lastSegment = premintSegments[1] ?? ''; + if (decimals > lastSegment.length) { + try { + lastSegment += "0".repeat(decimals - lastSegment.length); + } catch (e) { + // .repeat gives an error if decimals number is too large + throw new OptionsError({ + premint: 'Decimals number too large', + }); + } + } else if (decimals < lastSegment.length) { + throw new OptionsError({ + premint: 'Too many decimals', + }); + } + // concat segments without leading zeros + result = firstSegment.concat(lastSegment).replace(/^0+/, ''); + } + if (result.length === 0) { + result = '0'; + } + return result; +} + +function addMintable(c: ContractBuilder, access: Access) { + c.addUseClause('starknet', 'ContractAddress'); + requireAccessControl(c, externalTrait, functions.mint, access, 'MINTER', 'minter'); +} + +const components = defineComponents( { + ERC20Component: { + path: 'openzeppelin::token::erc20', + substorage: { + name: 'erc20', + type: 'ERC20Component::Storage', + }, + event: { + name: 'ERC20Event', + type: 'ERC20Component::Event', + }, + impls: [{ + name: 'ERC20InternalImpl', + embed: false, + value: 'ERC20Component::InternalImpl', + }], + }, +}); + +const functions = defineFunctions({ + burn: { + args: [ + getSelfArg(), + { name: 'value', type: 'u256' } + ], + code: [ + 'self.erc20.burn(get_caller_address(), value);' + ] + }, + mint: { + args: [ + getSelfArg(), + { name: 'recipient', type: 'ContractAddress' }, + { name: 'amount', type: 'u256' } + ], + code: [ + 'self.erc20.mint(recipient, amount);' + ] + }, +}); diff --git a/packages/core/stellar/src/error.ts b/packages/core/stellar/src/error.ts new file mode 100644 index 000000000..8b3d2b8e3 --- /dev/null +++ b/packages/core/stellar/src/error.ts @@ -0,0 +1,7 @@ +export type OptionsErrorMessages = { [prop in string]?: string }; + +export class OptionsError extends Error { + constructor(readonly messages: OptionsErrorMessages) { + super("Invalid options"); + } +} diff --git a/packages/core/stellar/src/external-trait.ts b/packages/core/stellar/src/external-trait.ts new file mode 100644 index 000000000..ed7e99e45 --- /dev/null +++ b/packages/core/stellar/src/external-trait.ts @@ -0,0 +1,11 @@ +import type { BaseImplementedTrait } from "./contract"; + +export const externalTrait: BaseImplementedTrait = { + name: 'ExternalImpl', + of: 'ExternalTrait', + tags: [ + 'generate_trait', + 'abi(per_item)', + ], + perItemTag: 'external(v0)', +} diff --git a/packages/core/stellar/src/generate/alternatives.ts b/packages/core/stellar/src/generate/alternatives.ts new file mode 100644 index 000000000..afd89ab67 --- /dev/null +++ b/packages/core/stellar/src/generate/alternatives.ts @@ -0,0 +1,36 @@ +type Blueprint = Record; + +type Alternatives = { + [k in keyof B]: B[k][number]; +}; + +export function* generateAlternatives( + blueprint: B, +): Generator> { + const entries = Object.entries(blueprint).map(([key, values]) => ({ + key, + values, + current: 0, + limit: values.length, + })); + + for (; !done(); advance()) { + yield Object.fromEntries( + entries.map(e => [e.key, e.values[e.current % e.limit]]), + ) as Alternatives; + } + + function done() { + const last = entries[entries.length - 1]; + return last?.current === last?.limit; + } + + function advance() { + for (const e of entries) { + e.current = (e.current % e.limit) + 1; + if (e.current < e.limit) { + break; + } + } + } +} diff --git a/packages/core/stellar/src/generate/erc20.ts b/packages/core/stellar/src/generate/erc20.ts new file mode 100644 index 000000000..941505c7e --- /dev/null +++ b/packages/core/stellar/src/generate/erc20.ts @@ -0,0 +1,26 @@ +import type { ERC20Options } from '../erc20'; +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'], + symbol: ['MTK'], + burnable: booleans, + pausable: booleans, + mintable: booleans, + premint: ['1'], + votes: booleans, + appName: ['MyApp'], + appVersion: ['v1'], + access: accessOptions, + upgradeable: upgradeableOptions, + info: infoOptions +}; + +export function* generateERC20Options(): Generator> { + yield* generateAlternatives(blueprint); +} diff --git a/packages/core/stellar/src/generate/sources.ts b/packages/core/stellar/src/generate/sources.ts new file mode 100644 index 000000000..e10ed38b2 --- /dev/null +++ b/packages/core/stellar/src/generate/sources.ts @@ -0,0 +1,100 @@ +import { promises as fs } from 'fs'; +import path from 'path'; +import crypto from 'crypto'; + +import { generateERC20Options } from './erc20'; +import { buildGeneric, GenericOptions, KindedOptions } from '../build-generic'; +import { printContract } from '../print'; +import { OptionsError } from '../error'; +import { findCover } from '../utils/find-cover'; +import type { Contract } from '../contract'; + +type Subset = 'all' | 'minimal-cover'; + +type Kind = keyof KindedOptions; + +export function* generateOptions(kind?: Kind): Generator { + if (!kind || kind === 'ERC20') { + for (const kindOpts of generateERC20Options()) { + yield { kind: 'ERC20', ...kindOpts }; + } + } +} + +interface GeneratedContract { + id: string; + options: GenericOptions; + contract: Contract; +} + +interface GeneratedSource extends GeneratedContract { + source: string; +} + +function generateContractSubset(subset: Subset, kind?: Kind): GeneratedContract[] { + const contracts = []; + + for (const options of generateOptions(kind)) { + const id = crypto + .createHash('sha1') + .update(JSON.stringify(options)) + .digest() + .toString('hex'); + + try { + const contract = buildGeneric(options); + contracts.push({ id, options, contract }); + } catch (e: unknown) { + if (e instanceof OptionsError) { + continue; + } else { + throw e; + } + } + } + + if (subset === 'all') { + return contracts; + } else { + const getParents = (c: GeneratedContract) => c.contract.components.map(p => p.path); + function filterByUpgradeableSetTo(isUpgradeable: boolean) { + return (c: GeneratedContract) => { + switch (c.options.kind) { + case 'ERC20': + return c.options.upgradeable === isUpgradeable; + default: + const _: never = c.options.kind; // TODO: When there are additional kinds above, change this assignment to just `c.options` instead of `c.options.kind` + throw new Error('Unknown kind'); + } + } + } + return [ + ...findCover(contracts.filter(filterByUpgradeableSetTo(true)), getParents), + ...findCover(contracts.filter(filterByUpgradeableSetTo(false)), getParents), + ]; + } +} + +export function* generateSources(subset: Subset, uniqueName?: boolean, kind?: Kind): Generator { + let counter = 1; + for (const c of generateContractSubset(subset, kind)) { + if (uniqueName) { + c.contract.name = `Contract${counter++}`; + } + const source = printContract(c.contract); + yield { ...c, source }; + } +} + +export async function writeGeneratedSources(dir: string, subset: Subset, uniqueName?: boolean, kind?: Kind): Promise { + await fs.mkdir(dir, { recursive: true }); + let contractNames = []; + + for (const { id, contract, source } of generateSources(subset, uniqueName, kind)) { + const name = uniqueName ? contract.name : id; + await fs.writeFile(path.format({ dir, name, ext: '.cairo' }), source); + contractNames.push(name); + } + + return contractNames; +} diff --git a/packages/core/stellar/src/index.ts b/packages/core/stellar/src/index.ts new file mode 100644 index 000000000..2b01422dc --- /dev/null +++ b/packages/core/stellar/src/index.ts @@ -0,0 +1,27 @@ +export type { GenericOptions, KindedOptions } from './build-generic'; +export { buildGeneric } from './build-generic'; + +export type { Contract } from './contract'; +export { ContractBuilder } from './contract'; + +export { printContract } from './print'; + +export type { Access } from './set-access-control'; +export type { Upgradeable } from './set-upgradeable'; +export type { Info } from './set-info'; +export type { RoyaltyInfoOptions } from './set-royalty-info'; + +export { premintPattern } from './erc20'; + +export { defaults as infoDefaults } from './set-info'; +export { defaults as royaltyInfoDefaults } from './set-royalty-info'; + +export type { OptionsErrorMessages } from './error'; +export { OptionsError } from './error'; + +export type { Kind } from './kind'; +export { sanitizeKind } from './kind'; + +export { contractsVersion, contractsVersionTag, compatibleContractsSemver } from './utils/version'; + +export { erc20 } from './api'; diff --git a/packages/core/stellar/src/kind.ts b/packages/core/stellar/src/kind.ts new file mode 100644 index 000000000..d61180216 --- /dev/null +++ b/packages/core/stellar/src/kind.ts @@ -0,0 +1,33 @@ +import type { GenericOptions } from './build-generic'; + +export type Kind = GenericOptions['kind']; + +export function sanitizeKind(kind: unknown): Kind { + if (typeof kind === 'string') { + const sanitized = kind.replace(/^(ERC|.)/i, c => c.toUpperCase()); + if (isKind(sanitized)) { + return sanitized; + } + } + return 'ERC20'; +} + +function isKind(value: Kind | T): value is Kind { + switch (value) { + case 'ERC20': + case 'ERC721': + case 'ERC1155': + case 'Account': + case 'Governor': + case 'Vesting': + case 'Custom': + return true; + + default: { + // Static assert that we've checked all kinds. + const _: T = value; + return false; + } + } +} + diff --git a/packages/core/stellar/src/print.ts b/packages/core/stellar/src/print.ts new file mode 100644 index 000000000..157866f8a --- /dev/null +++ b/packages/core/stellar/src/print.ts @@ -0,0 +1,443 @@ +import type { Contract, Component, Argument, Value, Impl, ContractFunction, ImplementedTrait, UseClause, } from './contract'; + +import { formatLines, spaceBetween, Lines } from './utils/format-lines'; +import { getSelfArg } from './common-options'; +import { compatibleContractsSemver } from './utils/version'; + +const DEFAULT_SECTION = '1. with no section'; +const STANDALONE_IMPORTS_GROUP = 'Standalone Imports'; +const MAX_USE_CLAUSE_LINE_LENGTH = 90; +const TAB = "\t"; + +export function printContract(contract: Contract): string { + const contractAttribute = contract.account ? '#[starknet::contract(account)]' : '#[starknet::contract]' + return formatLines( + ...spaceBetween( + [ + `// SPDX-License-Identifier: ${contract.license}`, + `// Compatible with OpenZeppelin Contracts for Cairo ${compatibleContractsSemver}`, + ], + printSuperVariables(contract), + [ + `${contractAttribute}`, + `mod ${contract.name} {`, + spaceBetween( + printUseClauses(contract), + printConstants(contract), + printComponentDeclarations(contract), + printImpls(contract), + printStorage(contract), + printEvents(contract), + printConstructor(contract), + printImplementedTraits(contract), + ), + `}`, + ], + ), + ); +} + +function withSemicolons(lines: string[]): string[] { + return lines.map(line => line.endsWith(';') ? line : line + ';'); +} + +function printSuperVariables(contract: Contract): string[] { + return withSemicolons(contract.superVariables.map(v => `const ${v.name}: ${v.type} = ${v.value}`)); +} + +function printUseClauses(contract: Contract): Lines[] { + const useClauses = sortUseClauses(contract); + + // group by containerPath + const grouped = useClauses.reduce( + (result: { [containerPath: string]: UseClause[] }, useClause: UseClause) => { + if (useClause.groupable) { + (result[useClause.containerPath] = result[useClause.containerPath] || []).push(useClause); + } else { + (result[STANDALONE_IMPORTS_GROUP] = result[STANDALONE_IMPORTS_GROUP] || []).push(useClause); + } + return result; + }, {}); + + const lines = Object.entries(grouped).flatMap(([groupName, group]) => getLinesFromUseClausesGroup(group, groupName)); + return lines.flatMap(line => splitLongUseClauseLine(line.toString())); +} + +function getLinesFromUseClausesGroup(group: UseClause[], groupName: string): Lines[] { + const lines = []; + if (groupName === STANDALONE_IMPORTS_GROUP) { + for (const useClause of group) { + const alias = useClause.alias ?? ''; + if (alias.length > 0) { + lines.push(`use ${useClause.containerPath}::${useClause.name} as ${alias};`); + } else { + lines.push(`use ${useClause.containerPath}::${useClause.name};`); + } + } + } else { + if (group.length == 1) { + const alias = group[0]!.alias ?? ''; + if (alias.length > 0) { + lines.push(`use ${groupName}::${group[0]!.name} as ${alias};`); + } else { + lines.push(`use ${groupName}::${group[0]!.name};`); + } + + } else if (group.length > 1) { + let clauses = group.reduce((clauses, useClause) => { + const alias = useClause.alias ?? ''; + if (alias.length > 0) { + clauses += `${useClause.name} as ${useClause.alias}, `; + } else { + clauses += `${useClause.name}, `; + } + return clauses; + }, ''); + clauses = clauses.slice(0, -2); + + lines.push(`use ${groupName}::{${clauses}};`); + } + } + return lines; +} + +// TODO: remove this when we can use a formatting js library +function splitLongUseClauseLine(line: string): Lines[] { + const lines = []; + + const containsBraces = line.indexOf('{') !== -1; + if (containsBraces && line.length > MAX_USE_CLAUSE_LINE_LENGTH) { + // split at the first brace + lines.push(line.slice(0, line.indexOf('{') + 1)); + lines.push(...splitLongLineInner(line.slice(line.indexOf('{') + 1, -2))); + lines.push("};"); + } else { + lines.push(line); + } + return lines; +} + +function splitLongLineInner(line: string): Lines[] { + const lines = []; + if (line.length > MAX_USE_CLAUSE_LINE_LENGTH) { + const max_accessible_string = line.slice(0, MAX_USE_CLAUSE_LINE_LENGTH); + const lastCommaIndex = max_accessible_string.lastIndexOf(','); + if (lastCommaIndex !== -1) { + lines.push(TAB + max_accessible_string.slice(0, lastCommaIndex + 1)); + lines.push(...splitLongLineInner(line.slice(lastCommaIndex + 2))); + } else { + lines.push(TAB + max_accessible_string); + } + } else { + lines.push(TAB + line); + } + return lines; +} + +function sortUseClauses(contract: Contract): UseClause[] { + return contract.useClauses.sort((a, b) => { + const aFullPath = `${a.containerPath}::${a.name}`; + const bFullPath = `${b.containerPath}::${b.name}`; + return aFullPath.localeCompare(bFullPath); + }); +} + +function printConstants(contract: Contract): Lines[] { + const lines = []; + for (const constant of contract.constants) { + // inlineComment is optional, default to false + const inlineComment = constant.inlineComment ?? false; + const commented = !!constant.comment; + + if (commented && !inlineComment) { + lines.push(`// ${constant.comment}`); + lines.push(`const ${constant.name}: ${constant.type} = ${constant.value};`); + } else if (commented) { + lines.push(`const ${constant.name}: ${constant.type} = ${constant.value}; // ${constant.comment}`); + } else { + lines.push(`const ${constant.name}: ${constant.type} = ${constant.value};`); + } + } + return lines; +} + +function printComponentDeclarations(contract: Contract): Lines[] { + const lines = []; + for (const component of contract.components) { + lines.push(`component!(path: ${component.name}, storage: ${component.substorage.name}, event: ${component.event.name});`); + } + return lines; +} + +function printImpls(contract: Contract): Lines[] { + const impls = contract.components.flatMap(c => c.impls); + + // group by section + const grouped = impls.reduce( + (result: { [section: string]: Impl[] }, current:Impl) => { + // default section depends on embed + // embed defaults to true + const embed = current.embed ?? true; + const section = current.section ?? (embed ? 'External' : 'Internal'); + (result[section] = result[section] || []).push(current); + return result; + }, {}); + + const sections = Object.entries(grouped).sort((a, b) => a[0].localeCompare(b[0])).map( + ([section, impls]) => printSection(section, impls as Impl[]), + ); + return spaceBetween(...sections); +} + +function printSection(section: string, impls: Impl[]): Lines[] { + const lines = []; + lines.push(`// ${section}`); + impls.map(impl => lines.push(...printImpl(impl))); + return lines; +} + +function printImpl(impl: Impl): Lines[] { + const lines = []; + // embed is optional, default to true + if (impl.embed ?? true) { + lines.push('#[abi(embed_v0)]'); + } + lines.push(`impl ${impl.name} = ${impl.value};`); + return lines; +} + +function printStorage(contract: Contract): (string | string[])[] { + const lines = []; + // storage is required regardless of whether there are components + lines.push('#[storage]'); + lines.push('struct Storage {'); + const storageLines = []; + for (const component of contract.components) { + storageLines.push(`#[substorage(v0)]`); + storageLines.push(`${component.substorage.name}: ${component.substorage.type},`); + } + lines.push(storageLines); + lines.push('}'); + return lines; +} + +function printEvents(contract: Contract): (string | string[])[] { + const lines = []; + if (contract.components.length > 0) { + lines.push('#[event]'); + lines.push('#[derive(Drop, starknet::Event)]'); + lines.push('enum Event {') + const eventLines = []; + for (const component of contract.components) { + eventLines.push('#[flat]'); + eventLines.push(`${component.event.name}: ${component.event.type},`); + } + lines.push(eventLines); + lines.push('}'); + } + return lines; +} + +function printImplementedTraits(contract: Contract): Lines[] { + // sort first by priority, then number of tags, then name + const sortedTraits = contract.implementedTraits.sort((a, b) => { + if (a.priority !== b.priority) { + return (a.priority ?? Infinity) - (b.priority ?? Infinity); + } + if (a.tags.length !== b.tags.length) { + return a.tags.length - b.tags.length; + } + return a.name.localeCompare(b.name); + }); + + // group by section + const grouped = sortedTraits.reduce( + (result: { [section: string]: ImplementedTrait[] }, current:ImplementedTrait) => { + // default to no section + const section = current.section ?? DEFAULT_SECTION; + (result[section] = result[section] || []).push(current); + return result; + }, {}); + + const sections = Object.entries(grouped).sort((a, b) => a[0].localeCompare(b[0])).map( + ([section, impls]) => printImplementedTraitsSection(section, impls as ImplementedTrait[]), + ); + + return spaceBetween(...sections); +} + +function printImplementedTraitsSection(section: string, impls: ImplementedTrait[]): Lines[] { + const lines = []; + const isDefaultSection = section === DEFAULT_SECTION; + if (!isDefaultSection) { + lines.push('//'); + lines.push(`// ${section}`); + lines.push('//'); + } + impls.forEach((trait, index) => { + if (index > 0 || !isDefaultSection) { + lines.push(''); + } + lines.push(...printImplementedTrait(trait)); + }); + return lines; +} + +function printImplementedTrait(trait: ImplementedTrait): Lines[] { + const implLines = []; + implLines.push(...trait.tags.map(t => `#[${t}]`)); + implLines.push(`impl ${trait.name} of ${trait.of} {`); + + const superVars = withSemicolons( + trait.superVariables.map(v => `const ${v.name}: ${v.type} = ${v.value}`) + ); + implLines.push(superVars); + + const fns = trait.functions.map(fn => printFunction(fn)); + implLines.push(spaceBetween(...fns)); + implLines.push('}'); + return implLines; +} + +function printFunction(fn: ContractFunction): Lines[] { + const head = `fn ${fn.name}`; + const args = fn.args.map(a => printArgument(a)); + + const codeLines = fn.codeBefore?.concat(fn.code) ?? fn.code; + for (let i = 0; i < codeLines.length; i++) { + const line = codeLines[i]; + const shouldEndWithSemicolon = i < codeLines.length - 1 || fn.returns === undefined; + if (line !== undefined && line.length > 0) { + if (shouldEndWithSemicolon && !['{', '}', ';'].includes(line.charAt(line.length - 1))) { + codeLines[i] += ';'; + } else if (!shouldEndWithSemicolon && line.endsWith(';')) { + codeLines[i] = line.slice(0, line.length - 1); + } + } + } + + return printFunction2(head, args, fn.tag, fn.returns, undefined, codeLines); +} + +function printConstructor(contract: Contract): Lines[] { + const hasInitializers = contract.components.some(p => p.initializer !== undefined); + const hasConstructorCode = contract.constructorCode.length > 0; + if (hasInitializers || hasConstructorCode) { + const parents = contract.components + .filter(hasInitializer) + .flatMap(p => printParentConstructor(p)); + const tag = 'constructor'; + const head = 'fn constructor'; + const args = [ getSelfArg(), ...contract.constructorArgs ]; + + const body = spaceBetween( + withSemicolons(parents), + withSemicolons(contract.constructorCode), + ); + + const constructor = printFunction2( + head, + args.map(a => printArgument(a)), + tag, + undefined, + undefined, + body, + ); + return constructor; + } else { + return []; + } +} + +function hasInitializer(parent: Component): boolean { + return parent.initializer !== undefined && parent.substorage?.name !== undefined; +} + +function printParentConstructor({ substorage, initializer }: Component): [] | [string] { + if (initializer === undefined || substorage?.name === undefined) { + return []; + } + const fn = `self.${substorage.name}.initializer`; + return [ + fn + '(' + initializer.params.map(printValue).join(', ') + ')', + ]; +} + +export function printValue(value: Value): string { + if (typeof value === 'object') { + if ('lit' in value) { + return value.lit; + } else if ('note' in value) { + // TODO: add /* ${value.note} */ after lsp is fixed + return `${printValue(value.value)}`; + } else { + throw Error('Unknown value type'); + } + } else if (typeof value === 'number') { + if (Number.isSafeInteger(value)) { + return value.toFixed(0); + } else { + throw new Error(`Number not representable (${value})`); + } + } else if (typeof value === 'bigint') { + return `${value}` + } else { + return `"${value}"`; + } +} + +// generic for functions and constructors +// kindedName = 'fn foo' +function printFunction2( + kindedName: string, + args: string[], + tag: string | undefined, + returns: string | undefined, + returnLine: string | undefined, + code: Lines[] +): Lines[] { + const fn = []; + + if (tag !== undefined) { + fn.push(`#[${tag}]`); + } + + let accum = `${kindedName}(`; + + if (args.length > 0) { + const formattedArgs = args.join(', '); + if (formattedArgs.length > 80) { + fn.push(accum); + accum = ''; + // print each arg in a separate line + fn.push(args.map(arg => `${arg},`)); + } else { + accum += `${formattedArgs}`; + } + } + accum += ')'; + + if (returns === undefined) { + accum += ' {'; + } else { + accum += ` -> ${returns} {`; + } + + fn.push(accum); + fn.push(code); + if (returnLine !== undefined) { + fn.push([returnLine]); + } + fn.push('}'); + + return fn; +} + +function printArgument(arg: Argument): string { + if (arg.type !== undefined) { + const type = arg.type; + return `${arg.name}: ${type}`; + } else { + return `${arg.name}`; + } +} diff --git a/packages/core/stellar/src/scripts/update-scarb-project.ts b/packages/core/stellar/src/scripts/update-scarb-project.ts new file mode 100644 index 000000000..022e74759 --- /dev/null +++ b/packages/core/stellar/src/scripts/update-scarb-project.ts @@ -0,0 +1,41 @@ +import { promises as fs } from 'fs'; +import path from 'path'; + +import { writeGeneratedSources } from '../generate/sources'; +import { contractsVersion, 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(/openzeppelin = "\d+\.\d+\.\d+"/, `openzeppelin = "${contractsVersion}"`); + + await fs.writeFile(scarbTomlPath, updatedContent, 'utf8'); +} + +updateScarbProject(); diff --git a/packages/core/stellar/src/set-access-control.ts b/packages/core/stellar/src/set-access-control.ts new file mode 100644 index 000000000..7bd3c2218 --- /dev/null +++ b/packages/core/stellar/src/set-access-control.ts @@ -0,0 +1,129 @@ +import type { BaseFunction, BaseImplementedTrait, ContractBuilder } from './contract'; +import { defineComponents } from './utils/define-components'; +import { addSRC5Component } from './common-components'; + +export const accessOptions = [false, 'ownable', 'roles'] as const; +export const DEFAULT_ACCESS_CONTROL = 'ownable'; + +export type Access = typeof accessOptions[number]; + +/** + * Sets access control for the contract by adding inheritance. + */ + export function setAccessControl(c: ContractBuilder, access: Access): void { + switch (access) { + case 'ownable': { + c.addComponent(components.OwnableComponent, [{ lit: 'owner' }], true); + + c.addUseClause('starknet', 'ContractAddress'); + c.addConstructorArgument({ name: 'owner', type: 'ContractAddress'}); + + break; + } + case 'roles': { + if (c.addComponent(components.AccessControlComponent, [], true)) { + if (c.interfaceFlags.has('ISRC5')) { + c.addImplToComponent(components.AccessControlComponent, { + name: 'AccessControlImpl', + value: 'AccessControlComponent::AccessControlImpl', + }); + c.addImplToComponent(components.AccessControlComponent, { + name: 'AccessControlCamelImpl', + value: 'AccessControlComponent::AccessControlCamelImpl', + }); + } else { + c.addImplToComponent(components.AccessControlComponent, { + name: 'AccessControlMixinImpl', + value: 'AccessControlComponent::AccessControlMixinImpl', + }); + c.addInterfaceFlag('ISRC5'); + } + addSRC5Component(c); + + c.addUseClause('starknet', 'ContractAddress'); + c.addConstructorArgument({ name: 'default_admin', type: 'ContractAddress'}); + + c.addUseClause('openzeppelin::access::accesscontrol', 'DEFAULT_ADMIN_ROLE'); + c.addConstructorCode('self.accesscontrol._grant_role(DEFAULT_ADMIN_ROLE, default_admin)'); + } + break; + } + } +} + +/** + * Enables access control for the contract and restricts the given function with access control. + */ +export function requireAccessControl( + c: ContractBuilder, + trait: BaseImplementedTrait, + fn: BaseFunction, + access: Access, + roleIdPrefix: string, + roleOwner: string | undefined +): void { + if (access === false) { + access = DEFAULT_ACCESS_CONTROL; + } + setAccessControl(c, access); + + switch (access) { + case 'ownable': { + c.addFunctionCodeBefore(trait, fn, 'self.ownable.assert_only_owner()'); + break; + } + case 'roles': { + const roleId = roleIdPrefix + '_ROLE'; + const addedSuper = c.addSuperVariable({ name: roleId, type: 'felt252', value: `selector!("${roleId}")` }) + if (roleOwner !== undefined) { + c.addUseClause('starknet', 'ContractAddress'); + c.addConstructorArgument({ name: roleOwner, type: 'ContractAddress'}); + if (addedSuper) { + c.addConstructorCode(`self.accesscontrol._grant_role(${roleId}, ${roleOwner})`); + } + } + + c.addFunctionCodeBefore(trait, fn, `self.accesscontrol.assert_only_role(${roleId})`); + + break; + } + } +} + +const components = defineComponents( { + OwnableComponent: { + path: 'openzeppelin::access::ownable', + substorage: { + name: 'ownable', + type: 'OwnableComponent::Storage', + }, + event: { + name: 'OwnableEvent', + type: 'OwnableComponent::Event', + }, + impls: [{ + name: 'OwnableMixinImpl', + value: 'OwnableComponent::OwnableMixinImpl', + }, { + name: 'OwnableInternalImpl', + embed: false, + value: 'OwnableComponent::InternalImpl', + }], + }, + AccessControlComponent: { + path: 'openzeppelin::access::accesscontrol', + substorage: { + name: 'accesscontrol', + type: 'AccessControlComponent::Storage', + }, + event: { + name: 'AccessControlEvent', + type: 'AccessControlComponent::Event', + }, + impls: [{ + name: 'AccessControlInternalImpl', + embed: false, + value: 'AccessControlComponent::InternalImpl', + }], + }, +}); diff --git a/packages/core/stellar/src/set-info.ts b/packages/core/stellar/src/set-info.ts new file mode 100644 index 000000000..421a15029 --- /dev/null +++ b/packages/core/stellar/src/set-info.ts @@ -0,0 +1,17 @@ +import type { ContractBuilder } from "./contract"; + +export const infoOptions = [{}, { license: 'WTFPL' }] as const; + +export const defaults: Info = { license: 'MIT' }; + +export type Info = { + license?: string; +} + +export function setInfo(c: ContractBuilder, info: Info): void { + const { license } = info; + + if (license) { + c.license = license; + } +} diff --git a/packages/core/stellar/src/set-royalty-info.ts b/packages/core/stellar/src/set-royalty-info.ts new file mode 100644 index 000000000..5464be105 --- /dev/null +++ b/packages/core/stellar/src/set-royalty-info.ts @@ -0,0 +1,131 @@ +import type { BaseImplementedTrait, ContractBuilder } from './contract'; +import { defineComponents } from './utils/define-components'; +import { OptionsError } from "./error"; +import { toUint } from './utils/convert-strings'; +import { Access, setAccessControl, DEFAULT_ACCESS_CONTROL } from './set-access-control'; + +const DEFAULT_FEE_DENOMINATOR = BigInt(10_000); + +export const defaults: RoyaltyInfoOptions = { + enabled: false, + defaultRoyaltyFraction: '0', + feeDenominator: DEFAULT_FEE_DENOMINATOR.toString() +}; + +export const royaltyInfoOptions = { + disabled: defaults, + enabledDefault: { + enabled: true, + defaultRoyaltyFraction: '500', + feeDenominator: DEFAULT_FEE_DENOMINATOR.toString(), + }, + enabledCustom: { + enabled: true, + defaultRoyaltyFraction: '15125', + feeDenominator: '100000', + } +} + +export type RoyaltyInfoOptions = { + enabled: boolean, + defaultRoyaltyFraction: string, + feeDenominator: string, +}; + +export function setRoyaltyInfo(c: ContractBuilder, options: RoyaltyInfoOptions, access: Access): void { + if (!options.enabled) { + return; + } + if (access === false) { + access = DEFAULT_ACCESS_CONTROL; + } + setAccessControl(c, access); + + const { defaultRoyaltyFraction, feeDenominator } = getRoyaltyParameters(options); + const initParams = [ + { lit: 'default_royalty_receiver' }, + defaultRoyaltyFraction + ]; + + c.addComponent(components.ERC2981Component, initParams, true); + c.addUseClause('starknet', 'ContractAddress'); + c.addConstructorArgument({ name: 'default_royalty_receiver', type: 'ContractAddress'}); + + switch (access) { + case 'ownable': + c.addImplToComponent(components.ERC2981Component, { + name: 'ERC2981AdminOwnableImpl', + value: `ERC2981Component::ERC2981AdminOwnableImpl`, + }); + break; + case 'roles': + c.addImplToComponent(components.ERC2981Component, { + name: 'ERC2981AdminAccessControlImpl', + value: `ERC2981Component::ERC2981AdminAccessControlImpl`, + }); + c.addConstructorArgument({ name: 'royalty_admin', type: 'ContractAddress'}); + c.addConstructorCode('self.accesscontrol._grant_role(ERC2981Component::ROYALTY_ADMIN_ROLE, royalty_admin)'); + break; + } + + if (feeDenominator === DEFAULT_FEE_DENOMINATOR) { + c.addUseClause('openzeppelin::token::common::erc2981', 'DefaultConfig'); + } else { + const trait: BaseImplementedTrait = { + name: 'ERC2981ImmutableConfig', + of: 'ERC2981Component::ImmutableConfig', + tags: [], + }; + c.addImplementedTrait(trait); + c.addSuperVariableToTrait(trait, { + name: 'FEE_DENOMINATOR', + type: 'u128', + value: feeDenominator.toString() + }); + } +} + +function getRoyaltyParameters(opts: Required): { defaultRoyaltyFraction: bigint, feeDenominator: bigint } { + const feeDenominator = toUint(opts.feeDenominator, 'feeDenominator', 'u128'); + if (feeDenominator === BigInt(0)) { + throw new OptionsError({ + feeDenominator: 'Must be greater than 0' + }); + } + const defaultRoyaltyFraction = toUint(opts.defaultRoyaltyFraction, 'defaultRoyaltyFraction', 'u128'); + if (defaultRoyaltyFraction > feeDenominator) { + throw new OptionsError({ + defaultRoyaltyFraction: 'Cannot be greater than fee denominator' + }); + } + return { defaultRoyaltyFraction, feeDenominator }; +} + +const components = defineComponents({ + ERC2981Component: { + path: 'openzeppelin::token::common::erc2981', + substorage: { + name: 'erc2981', + type: 'ERC2981Component::Storage', + }, + event: { + name: 'ERC2981Event', + type: 'ERC2981Component::Event', + }, + impls: [ + { + name: 'ERC2981Impl', + value: 'ERC2981Component::ERC2981Impl', + }, + { + name: 'ERC2981InfoImpl', + value: 'ERC2981Component::ERC2981InfoImpl', + }, + { + name: 'ERC2981InternalImpl', + value: 'ERC2981Component::InternalImpl', + embed: false + } + ], + }, +}); diff --git a/packages/core/stellar/src/set-upgradeable.ts b/packages/core/stellar/src/set-upgradeable.ts new file mode 100644 index 000000000..e96ccb272 --- /dev/null +++ b/packages/core/stellar/src/set-upgradeable.ts @@ -0,0 +1,72 @@ +import { getSelfArg } from './common-options'; +import type { BaseImplementedTrait, ContractBuilder } from './contract'; +import { Access, requireAccessControl } from './set-access-control'; +import { defineComponents } from './utils/define-components'; +import { defineFunctions } from './utils/define-functions'; + +export const upgradeableOptions = [false, true] as const; + +export type Upgradeable = typeof upgradeableOptions[number]; + +function setUpgradeableBase(c: ContractBuilder, upgradeable: Upgradeable): BaseImplementedTrait | undefined { + if (upgradeable === false) { + return undefined; + } + + c.upgradeable = true; + + c.addComponent(components.UpgradeableComponent, [], false); + + c.addUseClause('openzeppelin::upgrades::interface', 'IUpgradeable'); + c.addUseClause('starknet', 'ClassHash'); + + const t: BaseImplementedTrait = { + name: 'UpgradeableImpl', + of: 'IUpgradeable', + section: 'Upgradeable', + tags: [ + 'abi(embed_v0)' + ], + }; + c.addImplementedTrait(t); + + return t; +} + +export function setUpgradeable(c: ContractBuilder, upgradeable: Upgradeable, access: Access): void { + const trait = setUpgradeableBase(c, upgradeable); + if (trait !== undefined) { + requireAccessControl(c, trait, functions.upgrade, access, 'UPGRADER', 'upgrader'); + } +} + +const components = defineComponents( { + UpgradeableComponent: { + path: 'openzeppelin::upgrades', + substorage: { + name: 'upgradeable', + type: 'UpgradeableComponent::Storage', + }, + event: { + name: 'UpgradeableEvent', + type: 'UpgradeableComponent::Event', + }, + impls: [{ + name: 'UpgradeableInternalImpl', + embed: false, + value: 'UpgradeableComponent::InternalImpl', + }], + }, +}); + +const functions = defineFunctions({ + upgrade: { + args: [ + getSelfArg(), + { name: 'new_class_hash', type: 'ClassHash' }, + ], + code: [ + 'self.upgradeable.upgrade(new_class_hash)' + ] + }, +}); diff --git a/packages/core/stellar/src/test.ts b/packages/core/stellar/src/test.ts new file mode 100644 index 000000000..948e6ba66 --- /dev/null +++ b/packages/core/stellar/src/test.ts @@ -0,0 +1,56 @@ +import { promises as fs } from 'fs'; +import os from 'os'; +import _test, { TestFn, ExecutionContext } from 'ava'; +import path from 'path'; + +import { generateSources, writeGeneratedSources } from './generate/sources'; +import type { GenericOptions, KindedOptions } from './build-generic'; +import { erc20, } from './api'; + +interface Context { + generatedSourcesPath: string +} + +const test = _test as TestFn; + +test.serial('erc20 result generated', async t => { + await testGenerate(t, 'ERC20'); +}); + +async function testGenerate(t: ExecutionContext, kind: keyof KindedOptions) { + const generatedSourcesPath = path.join(os.tmpdir(), 'oz-wizard-cairo'); + await fs.rm(generatedSourcesPath, { force: true, recursive: true }); + await writeGeneratedSources(generatedSourcesPath, 'all', true, kind); + + t.pass(); +} + +function isAccessControlRequired(opts: GenericOptions) { + switch(opts.kind) { + case 'ERC20': + return erc20.isAccessControlRequired(opts); + default: + throw new Error("No such kind"); + } +} + +test('is access control required', async t => { + for (const contract of generateSources('all')) { + const regexOwnable = /(use openzeppelin::access::ownable::OwnableComponent)/gm; + + switch (contract.options.kind) { + case 'ERC20': + if (!contract.options.access) { + if (isAccessControlRequired(contract.options)) { + t.regex(contract.source, regexOwnable, JSON.stringify(contract.options)); + } else { + t.notRegex(contract.source, regexOwnable, JSON.stringify(contract.options)); + } + } + break; + default: + const _: never = contract.options.kind; // TODO: When there are additional kinds above, change this assignment to just `contract.options` instead of `contract.options.kind` + throw new Error('Unknown kind'); + } + } +}); diff --git a/packages/core/stellar/src/utils/convert-strings.test.ts b/packages/core/stellar/src/utils/convert-strings.test.ts new file mode 100644 index 000000000..8a1421343 --- /dev/null +++ b/packages/core/stellar/src/utils/convert-strings.test.ts @@ -0,0 +1,99 @@ +import test from 'ava'; + +import { toIdentifier, toByteArray, toFelt252 } from './convert-strings'; +import { OptionsError } from '../error'; + +test('identifier - unmodified', t => { + t.is(toIdentifier('abc'), 'abc'); +}); + +test('identifier - remove leading specials', t => { + t.is(toIdentifier('--abc'), 'abc'); +}); + +test('identifier - remove specials and upcase next char', t => { + t.is(toIdentifier('abc-def'), 'abcDef'); + t.is(toIdentifier('abc--def'), 'abcDef'); +}); + +test('identifier - capitalize', t => { + t.is(toIdentifier('abc', true), 'Abc'); +}); + +test('identifier - remove accents', t => { + t.is(toIdentifier('ábc'), 'abc'); +}); + +test('identifier - underscores', t => { + t.is(toIdentifier('_abc_'), '_abc_'); +}); + +test('identifier - remove starting numbers', t => { + t.is(toIdentifier('123abc456'), 'abc456'); +}); + +test('identifier - empty string', t => { + let error = t.throws(() => toIdentifier(''), { instanceOf: OptionsError }); + t.is(error.messages.name, 'Identifier is empty or does not have valid characters'); +}); + +test('identifier - no valid chars', t => { + let error = t.throws(() => toIdentifier('123'), { instanceOf: OptionsError }); + t.is(error.messages.name, 'Identifier is empty or does not have valid characters'); +}); + +test('toByteArray - unmodified', t => { + t.is(toByteArray('abc'), 'abc'); +}); + +test('toByteArray - remove accents', t => { + t.is(toByteArray('ábc'), 'abc'); +}); + +test('toByteArray - remove non-ascii-printable characters', t => { + t.is(toByteArray('abc😀'), 'abc'); +}); + +test('toByteArray - escape double quote', t => { + t.is(toByteArray("abc\"def"), "abc\\\"def"); +}); + +test('toByteArray - does not escape single quote', t => { + t.is(toByteArray("abc'def"), "abc'def"); +}); + +test('toByteArray - escape backslash', t => { + t.is(toByteArray('abc\\def'), 'abc\\\\def'); +}); + +test('more than 31 characters', t => { + t.is(toByteArray('A234567890123456789012345678901'), 'A234567890123456789012345678901'); + t.is(toByteArray('A2345678901234567890123456789012'), 'A2345678901234567890123456789012'); +}); + +test('toFelt252 - unmodified', t => { + t.is(toFelt252('abc', 'foo'), 'abc'); +}); + +test('toFelt252 - remove accents', t => { + t.is(toFelt252('ábc', 'foo'), 'abc'); +}); + +test('toFelt252 - remove non-ascii-printable characters', t => { + t.is(toFelt252('abc😀', 'foo'), 'abc'); +}); + +test('toFelt252 - escape single quote', t => { + t.is(toFelt252("abc'def", 'foo'), "abc\\'def"); +}); + +test('toFelt252 - escape backslash', t => { + t.is(toFelt252('abc\\def', 'foo'), 'abc\\\\def'); +}); + +test('toFelt252 - max 31 characters', t => { + t.is(toFelt252('A234567890123456789012345678901', 'foo'), 'A234567890123456789012345678901'); + + let error = t.throws(() => toFelt252('A2345678901234567890123456789012', 'foo'), { instanceOf: OptionsError }); + t.is(error.messages.foo, 'String is longer than 31 characters'); +}); \ No newline at end of file diff --git a/packages/core/stellar/src/utils/convert-strings.ts b/packages/core/stellar/src/utils/convert-strings.ts new file mode 100644 index 000000000..d1681ec09 --- /dev/null +++ b/packages/core/stellar/src/utils/convert-strings.ts @@ -0,0 +1,97 @@ +import { OptionsError } from "../error"; + +/** + * Converts to an identifier according to the rules in https://docs.cairo-lang.org/language_constructs/identifiers.html + */ +export function toIdentifier(str: string, capitalize = false): string { + const result = str + .normalize('NFD').replace(/[\u0300-\u036f]/g, '') // remove accents + .replace(/^[^a-zA-Z_]+/, '') + .replace(/^(.)/, c => capitalize ? c.toUpperCase() : c) + .replace(/[^\w]+(.?)/g, (_, c) => c.toUpperCase()); + + if (result.length === 0) { + throw new OptionsError({ + name: 'Identifier is empty or does not have valid characters', + }); + } else { + return result; + } +} + +/** + * Converts to a ByteArray compatible string literal + */ +export function toByteArray(str: string): string { + return str + .normalize('NFD').replace(/[\u0300-\u036f]/g, '') // remove accents + .replace(/[^\x20-\x7E]+/g, '') // remove non-ascii-printable characters + .replace(/(\\|")/g, (_, c) => '\\' + c); // escape backslash or double quotes +} + +/** + * Converts to a felt252-compatible short string according to the rules in https://docs.cairo-lang.org/language_constructs/literal-expressions.html#short_string_literals + */ +export function toFelt252(str: string, field: string): string { + const result = str + .normalize('NFD').replace(/[\u0300-\u036f]/g, '') // remove accents + .replace(/[^\x20-\x7E]+/g, '') // remove non-ascii-printable characters + .replace(/(\\|')/g, (_, c) => '\\' + c); // escape backslash or single quote + + if (result.length > 31) { + throw new OptionsError({ + [field]: 'String is longer than 31 characters', + }); + } else { + return result; + } +} + +function maxValueOfUint(bits: number): bigint { + if (bits <= 0) { + throw new Error(`Number of bits must be positive (actual '${bits}').`) + } + if (bits % 8 !== 0) { + throw new Error(`The number of bits must be a multiple of 8 (actual '${bits}').`) + } + const bytes = bits / 8; + return BigInt('0x' + 'ff'.repeat(bytes)) +} + +const UINT_MAX_VALUES = { + 'u8': maxValueOfUint(8), + 'u16': maxValueOfUint(16), + 'u32': maxValueOfUint(32), + 'u64': maxValueOfUint(64), + 'u128': maxValueOfUint(128), + 'u256': maxValueOfUint(256) +} as const; + +export type UintType = keyof typeof UINT_MAX_VALUES; + +/** + * Checks that a string/number value is a valid `uint` value and converts it to bigint + */ +export function toUint(value: number | string, field: string, type: UintType): bigint { + const valueAsStr = value.toString(); + const isValidNumber = /^\d+$/.test(valueAsStr); + if (!isValidNumber) { + throw new OptionsError({ + [field]: 'Not a valid number' + }); + } + const numValue = BigInt(valueAsStr); + if (numValue > UINT_MAX_VALUES[type]) { + throw new OptionsError({ + [field]: `Value is greater than ${type} max value` + }); + } + return numValue; +} + +/** + * Checks that a string/number value is a valid `uint` value + */ +export function validateUint(value: number | string, field: string, type: UintType): void { + const _ = toUint(value, field, type); +} diff --git a/packages/core/stellar/src/utils/define-components.ts b/packages/core/stellar/src/utils/define-components.ts new file mode 100644 index 000000000..62ba3ca6e --- /dev/null +++ b/packages/core/stellar/src/utils/define-components.ts @@ -0,0 +1,18 @@ +import type { Component } from '../contract'; + +type ImplicitNameComponent = Omit; + +export function defineComponents( + fns: Record, +): Record; + +export function defineComponents( + modules: Record, +): Record { + return Object.fromEntries( + Object.entries(modules).map(([name, module]) => [ + name, + Object.assign({ name }, module), + ]), + ); +} diff --git a/packages/core/stellar/src/utils/define-functions.ts b/packages/core/stellar/src/utils/define-functions.ts new file mode 100644 index 000000000..c1f664e7e --- /dev/null +++ b/packages/core/stellar/src/utils/define-functions.ts @@ -0,0 +1,18 @@ +import type { BaseFunction } from '../contract'; + +type ImplicitNameFunction = Omit; + +export function defineFunctions( + fns: Record, +): Record; + +export function defineFunctions( + fns: Record, +): Record { + return Object.fromEntries( + Object.entries(fns).map(([name, fn]) => [ + name, + Object.assign({ name }, fn), + ]), + ); +} diff --git a/packages/core/stellar/src/utils/duration.ts b/packages/core/stellar/src/utils/duration.ts new file mode 100644 index 000000000..ffc2fe5b5 --- /dev/null +++ b/packages/core/stellar/src/utils/duration.ts @@ -0,0 +1,26 @@ +const durationUnits = ['second', 'minute', 'hour', 'day', 'week', 'month', 'year'] as const; +type DurationUnit = typeof durationUnits[number]; +export const durationPattern = new RegExp(`^(\\d+(?:\\.\\d+)?) +(${durationUnits.join('|')})s?$`); + +const second = 1; +const minute = 60 * second; +const hour = 60 * minute; +const day = 24 * hour; +const week = 7 * day; +const month = 30 * day; +const year = 365 * day; +const secondsForUnit = { second, minute, hour, day, week, month, year }; + +export function durationToTimestamp(duration: string): number { + const match = duration.trim().match(durationPattern); + + if (!match || match.length < 2) { + throw new Error('Bad duration format'); + } + + const value = parseFloat(match[1]!); + const unit = match[2]! as DurationUnit; + + const durationSeconds = value * secondsForUnit[unit]; + return Math.round(durationSeconds); +} diff --git a/packages/core/stellar/src/utils/find-cover.ts b/packages/core/stellar/src/utils/find-cover.ts new file mode 100644 index 000000000..939ed9240 --- /dev/null +++ b/packages/core/stellar/src/utils/find-cover.ts @@ -0,0 +1,26 @@ +import { sortedBy } from './sorted-by'; + +// Greedy approximation of minimum set cover. + +export function findCover(sets: T[], getElements: (set: T) => unknown[]): T[] { + const sortedSets = sortedBy( + sets.map(set => ({ set, elems: getElements(set) })), + s => -s.elems.length, + ); + + const seen = new Set(); + const res = []; + + for (const { set, elems } of sortedSets) { + let included = false; + for (const e of elems) { + if (!included && !seen.has(e)) { + res.push(set); + included = true; + } + seen.add(e); + } + } + + return res; +} diff --git a/packages/core/stellar/src/utils/format-lines.ts b/packages/core/stellar/src/utils/format-lines.ts new file mode 100644 index 000000000..5e18a0c4a --- /dev/null +++ b/packages/core/stellar/src/utils/format-lines.ts @@ -0,0 +1,29 @@ +export type Lines = string | typeof whitespace | Lines[]; + +const whitespace = Symbol('whitespace'); + +export function formatLines(...lines: Lines[]): string { + return [...indentEach(0, lines)].join('\n') + '\n'; +} + +function* indentEach( + indent: number, + lines: Lines[], +): Generator { + for (const line of lines) { + if (line === whitespace) { + yield ''; + } else if (Array.isArray(line)) { + yield* indentEach(indent + 1, line); + } else { + yield ' '.repeat(indent) + line; + } + } +} + +export function spaceBetween(...lines: Lines[][]): Lines[] { + return lines + .filter(l => l.length > 0) + .flatMap(l => [whitespace, ...l]) + .slice(1); +} diff --git a/packages/core/stellar/src/utils/sorted-by.ts b/packages/core/stellar/src/utils/sorted-by.ts new file mode 100644 index 000000000..c865494bb --- /dev/null +++ b/packages/core/stellar/src/utils/sorted-by.ts @@ -0,0 +1,3 @@ +export function sortedBy(xs: Iterable, fn: (x: T) => number): T[] { + return Array.from(xs).sort((a, b) => fn(a) - fn(b)); +} diff --git a/packages/core/stellar/src/utils/version.test.ts b/packages/core/stellar/src/utils/version.test.ts new file mode 100644 index 000000000..5b580626c --- /dev/null +++ b/packages/core/stellar/src/utils/version.test.ts @@ -0,0 +1,11 @@ +import test from 'ava'; + +import semver from 'semver'; + +import { contractsVersion, compatibleContractsSemver } from './version'; + +test('latest target contracts satisfies compatible range', t => { + t.true(semver.satisfies(contractsVersion, compatibleContractsSemver), + `Latest target contracts version ${contractsVersion} does not satisfy compatible range ${compatibleContractsSemver}. +Check whether the compatible range is up to date.`); +}); diff --git a/packages/core/stellar/src/utils/version.ts b/packages/core/stellar/src/utils/version.ts new file mode 100644 index 000000000..ccba00acc --- /dev/null +++ b/packages/core/stellar/src/utils/version.ts @@ -0,0 +1,17 @@ +/** + * The actual latest version to use in links. + */ +export const contractsVersion = '0.20.0'; +export const contractsVersionTag = `v${contractsVersion}`; + +/** + * Cairo compiler versions. + */ +export const edition = '2024_07'; +export const cairoVersion = '2.9.1'; +export const scarbVersion = '2.9.1'; + +/** + * Semantic version string representing of the minimum compatible version of Contracts to display in output. + */ +export const compatibleContractsSemver = '^0.20.0'; diff --git a/packages/core/stellar/tsconfig.json b/packages/core/stellar/tsconfig.json new file mode 100644 index 000000000..e51988c6e --- /dev/null +++ b/packages/core/stellar/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "incremental": true, + "module": "commonjs", + "sourceMap": true, + "declaration": true, + "declarationMap": true, + "skipLibCheck": true, + "rootDir": "src", + "outDir": "dist" + }, + "include": [ + "src/**/*" + ] +} diff --git a/packages/ui/public/cairo.html b/packages/ui/public/cairo.html index 58c81642e..f1401d2a5 100644 --- a/packages/ui/public/cairo.html +++ b/packages/ui/public/cairo.html @@ -54,6 +54,7 @@ soliditySolidity cairoCairo stylusStylus + stellarStellar
    diff --git a/packages/ui/public/index.html b/packages/ui/public/index.html index 5c04dc31d..604199f6c 100644 --- a/packages/ui/public/index.html +++ b/packages/ui/public/index.html @@ -86,6 +86,7 @@ soliditySolidity cairoCairo stylusStylus + stellarStellar
    diff --git a/packages/ui/public/stellar.html b/packages/ui/public/stellar.html new file mode 100644 index 000000000..5a31cfeb9 --- /dev/null +++ b/packages/ui/public/stellar.html @@ -0,0 +1,72 @@ + + + + + + OpenZeppelin Contracts Wizard for Stellar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + +
    +
    + Forum + Docs + GitHub + Twitter +
    +
    + +
    + + +
    + + + + + + + + diff --git a/packages/ui/public/stylus.html b/packages/ui/public/stylus.html index de0174034..18efe75b2 100644 --- a/packages/ui/public/stylus.html +++ b/packages/ui/public/stylus.html @@ -54,6 +54,7 @@ soliditySolidity cairoCairo stylusStylus + stellarStellar
    diff --git a/packages/ui/rollup.config.mjs b/packages/ui/rollup.config.mjs index 79a0f7678..28b9628c9 100644 --- a/packages/ui/rollup.config.mjs +++ b/packages/ui/rollup.config.mjs @@ -132,7 +132,7 @@ export default [ commonjs(), typescript({ - include: ['src/**/*.ts', '../core/solidity/src/**/*.ts', '../core/cairo/src/**/*.ts', '../core/stylus/src/**/*.ts'], + include: ['src/**/*.ts', '../core/*/src/**/*.ts'], sourceMap: true, inlineSources: true, }), diff --git a/packages/ui/src/common/styles/vars.css b/packages/ui/src/common/styles/vars.css index e17741501..2f1bcdc01 100644 --- a/packages/ui/src/common/styles/vars.css +++ b/packages/ui/src/common/styles/vars.css @@ -33,6 +33,8 @@ --stylus-pink: #e3066e; + --stellar-black: #0f0f0f; + /* Dimensions (scale taken from Tailwind) */ --size-1: 0.25rem; diff --git a/packages/ui/src/main.ts b/packages/ui/src/main.ts index 47d91eb10..82ece1972 100644 --- a/packages/ui/src/main.ts +++ b/packages/ui/src/main.ts @@ -4,6 +4,7 @@ import type {} from 'svelte'; import SolidityApp from './solidity/App.svelte'; import CairoApp from './cairo/App.svelte'; import StylusApp from './stylus/App.svelte'; +import StellarApp from './stellar/App.svelte'; import { postMessage } from './common/post-message'; import UnsupportedVersion from './common/UnsupportedVersion.svelte'; import semver from 'semver'; @@ -47,6 +48,9 @@ if (requestedVersion && !semver.satisfies(requestedVersion, compatibleVersionSem case 'stylus': app = new StylusApp({ target: document.body, props: { initialTab } }); break; + case 'stellar': + app = new StellarApp({ target: document.body, props: { initialTab, initialOpts } }); + break; case 'solidity': default: app = new SolidityApp({ target: document.body, props: { initialTab, initialOpts } }); diff --git a/packages/ui/src/standalone.css b/packages/ui/src/standalone.css index 804c9f05b..b6653d18d 100644 --- a/packages/ui/src/standalone.css +++ b/packages/ui/src/standalone.css @@ -137,6 +137,13 @@ body { filter: brightness(0) saturate(100%) invert(16%) sepia(96%) saturate(4083%) hue-rotate(323deg) brightness(91%) contrast(96%) } +.nav .switch.switch-stellar.active { + --color-2: #0F0F0F; +} +.nav .switch.switch-stellar.active img{ + filter: brightness(0) saturate(100%) invert(0%) sepia(0%) saturate(0%) hue-rotate(0deg) brightness(100%) contrast(100%) +} + /* Wizard */ diff --git a/packages/ui/src/stellar/AccessControlSection.svelte b/packages/ui/src/stellar/AccessControlSection.svelte new file mode 100644 index 000000000..6fbc168c9 --- /dev/null +++ b/packages/ui/src/stellar/AccessControlSection.svelte @@ -0,0 +1,62 @@ + + +
    +

    + + +

    + +
    + + +
    + +
    diff --git a/packages/ui/src/stellar/App.svelte b/packages/ui/src/stellar/App.svelte new file mode 100644 index 000000000..550e0979b --- /dev/null +++ b/packages/ui/src/stellar/App.svelte @@ -0,0 +1,283 @@ + + +
    +
    +
    + + + +
    + +
    + + + + + + + +
    +
    + +
    +
    +
    + +
    +
    +
    +
    {@html highlightedCode}
    +
    +
    +
    + + diff --git a/packages/ui/src/stellar/ERC20Controls.svelte b/packages/ui/src/stellar/ERC20Controls.svelte new file mode 100644 index 000000000..10f4248b4 --- /dev/null +++ b/packages/ui/src/stellar/ERC20Controls.svelte @@ -0,0 +1,112 @@ + + +
    +

    Settings

    + +
    + + + +
    + + +
    + +
    +

    Features

    + +
    + + + + + +
    +
    + +
    +

    + + +

    + + + + +
    + + + + diff --git a/packages/ui/src/stellar/InfoSection.svelte b/packages/ui/src/stellar/InfoSection.svelte new file mode 100644 index 000000000..497cd85e4 --- /dev/null +++ b/packages/ui/src/stellar/InfoSection.svelte @@ -0,0 +1,21 @@ + + +
    +

    + + +

    + + +
    + diff --git a/packages/ui/src/stellar/highlightjs.ts b/packages/ui/src/stellar/highlightjs.ts new file mode 100644 index 000000000..85d7b7166 --- /dev/null +++ b/packages/ui/src/stellar/highlightjs.ts @@ -0,0 +1,5 @@ +import hljs from 'highlight.js/lib/core'; +import rust from 'highlight.js/lib/languages/rust'; +hljs.registerLanguage('rust', rust); + +export default hljs; diff --git a/packages/ui/src/stellar/inject-hyperlinks.ts b/packages/ui/src/stellar/inject-hyperlinks.ts new file mode 100644 index 000000000..c2e7c8994 --- /dev/null +++ b/packages/ui/src/stellar/inject-hyperlinks.ts @@ -0,0 +1,40 @@ +import { contractsVersionTag } from "@openzeppelin/wizard-stellar/src"; + +export function injectHyperlinks(code: string) { + const importRegex = /use<\/span> (openzeppelin)::([^A-Z]*)(::[a-zA-Z0-9]+|::{)/g + let result = code; + let match = importRegex.exec(code); + while (match != null) { + const [line, libraryPrefix, libraryPath, suffix] = match; + if (line !== undefined && libraryPrefix !== undefined && libraryPath !== undefined && suffix !== undefined) { + const githubPrefix = `https://github.com/OpenZeppelin/cairo-contracts/blob/${contractsVersionTag}/packages/`; + + let libraryPathSegments = libraryPath.split('::'); + libraryPathSegments.splice(1, 0, 'src'); + + if (libraryPathSegments !== undefined && libraryPathSegments.length > 0) { + let replacement; + if (suffix === '::{') { + // Multiple components are imported, so remove components and link to the parent .cairo file + replacement = `use<\/span> ${libraryPrefix}::${libraryPath}${suffix}`; // Exclude suffix from link + } else { + // Single component is imported + // If a mapping exists, link to the mapped file, otherwise remove the component and link to the parent .cairo file + const componentName = suffix.substring(2, suffix.length); + const mapping = componentMappings[componentName]; + const urlSuffix = mapping ? `/${mapping}.cairo` : '.cairo'; + replacement = `use<\/span> ${libraryPrefix}::${libraryPath}${suffix}`; // Include suffix (component) in link + } + + result = result.replace(line, replacement); + } + } + match = importRegex.exec(code); + } + return result; +} + +const componentMappings: { [key: string]: string } = { + 'AccountComponent': 'account', + 'UpgradeableComponent': 'upgradeable', +} as const; From d6af3046c973c2ec46d23448043a56711929357c Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Wed, 5 Feb 2025 16:05:42 -0500 Subject: [PATCH 013/117] Change to Fungible --- packages/ui/src/stellar/App.svelte | 2 +- packages/ui/src/stellar/ERC20Controls.svelte | 33 -------------------- 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/packages/ui/src/stellar/App.svelte b/packages/ui/src/stellar/App.svelte index 550e0979b..f0e19e368 100644 --- a/packages/ui/src/stellar/App.svelte +++ b/packages/ui/src/stellar/App.svelte @@ -95,7 +95,7 @@
    diff --git a/packages/ui/src/stellar/ERC20Controls.svelte b/packages/ui/src/stellar/ERC20Controls.svelte index 10f4248b4..d0ab1596e 100644 --- a/packages/ui/src/stellar/ERC20Controls.svelte +++ b/packages/ui/src/stellar/ERC20Controls.svelte @@ -76,37 +76,4 @@
    -
    -

    - - -

    - - - - -
    - - - From a876c38063804f67dce19cfcdd55e82535b37550 Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Wed, 5 Feb 2025 18:27:13 -0500 Subject: [PATCH 014/117] Change stellar to soroban --- packages/core/{stellar => soroban}/.gitignore | 0 packages/core/{stellar => soroban}/CHANGELOG.md | 0 packages/core/{stellar => soroban}/LICENSE | 0 packages/core/{stellar => soroban}/NOTICE | 0 packages/core/{stellar => soroban}/README.md | 10 +++++----- packages/core/{stellar => soroban}/ava.config.js | 0 packages/core/{stellar => soroban}/package.json | 2 +- .../core/{stellar => soroban}/src/add-pausable.ts | 0 packages/core/{stellar => soroban}/src/api.ts | 0 .../core/{stellar => soroban}/src/build-generic.ts | 0 .../{stellar => soroban}/src/common-components.ts | 0 .../core/{stellar => soroban}/src/common-options.ts | 0 .../core/{stellar => soroban}/src/contract.test.ts | 0 .../{stellar => soroban}/src/contract.test.ts.md | 0 .../{stellar => soroban}/src/contract.test.ts.snap | Bin packages/core/{stellar => soroban}/src/contract.ts | 0 .../core/{stellar => soroban}/src/erc20.test.ts | 0 .../core/{stellar => soroban}/src/erc20.test.ts.md | 0 .../{stellar => soroban}/src/erc20.test.ts.snap | Bin packages/core/{stellar => soroban}/src/erc20.ts | 0 packages/core/{stellar => soroban}/src/error.ts | 0 .../core/{stellar => soroban}/src/external-trait.ts | 0 .../src/generate/alternatives.ts | 0 .../core/{stellar => soroban}/src/generate/erc20.ts | 0 .../{stellar => soroban}/src/generate/sources.ts | 0 packages/core/{stellar => soroban}/src/index.ts | 0 packages/core/{stellar => soroban}/src/kind.ts | 0 packages/core/{stellar => soroban}/src/print.ts | 0 .../src/scripts/update-scarb-project.ts | 0 .../{stellar => soroban}/src/set-access-control.ts | 0 packages/core/{stellar => soroban}/src/set-info.ts | 0 .../{stellar => soroban}/src/set-royalty-info.ts | 0 .../{stellar => soroban}/src/set-upgradeable.ts | 0 packages/core/{stellar => soroban}/src/test.ts | 0 .../src/utils/convert-strings.test.ts | 0 .../src/utils/convert-strings.ts | 0 .../src/utils/define-components.ts | 0 .../src/utils/define-functions.ts | 0 .../core/{stellar => soroban}/src/utils/duration.ts | 0 .../{stellar => soroban}/src/utils/find-cover.ts | 0 .../{stellar => soroban}/src/utils/format-lines.ts | 0 .../{stellar => soroban}/src/utils/sorted-by.ts | 0 .../{stellar => soroban}/src/utils/version.test.ts | 0 .../core/{stellar => soroban}/src/utils/version.ts | 0 packages/core/{stellar => soroban}/tsconfig.json | 0 packages/ui/public/cairo.html | 2 +- packages/ui/public/index.html | 2 +- packages/ui/public/{stellar.html => soroban.html} | 8 ++++---- packages/ui/public/stylus.html | 2 +- packages/ui/src/common/styles/vars.css | 2 +- packages/ui/src/main.ts | 6 +++--- .../AccessControlSection.svelte | 2 +- packages/ui/src/{stellar => soroban}/App.svelte | 12 ++++++------ .../src/{stellar => soroban}/ERC20Controls.svelte | 4 ++-- .../ui/src/{stellar => soroban}/InfoSection.svelte | 4 ++-- packages/ui/src/{stellar => soroban}/highlightjs.ts | 0 .../src/{stellar => soroban}/inject-hyperlinks.ts | 2 +- packages/ui/src/standalone.css | 4 ++-- 58 files changed, 31 insertions(+), 31 deletions(-) rename packages/core/{stellar => soroban}/.gitignore (100%) rename packages/core/{stellar => soroban}/CHANGELOG.md (100%) rename packages/core/{stellar => soroban}/LICENSE (100%) rename packages/core/{stellar => soroban}/NOTICE (100%) rename packages/core/{stellar => soroban}/README.md (87%) rename packages/core/{stellar => soroban}/ava.config.js (100%) rename packages/core/{stellar => soroban}/package.json (94%) rename packages/core/{stellar => soroban}/src/add-pausable.ts (100%) rename packages/core/{stellar => soroban}/src/api.ts (100%) rename packages/core/{stellar => soroban}/src/build-generic.ts (100%) rename packages/core/{stellar => soroban}/src/common-components.ts (100%) rename packages/core/{stellar => soroban}/src/common-options.ts (100%) rename packages/core/{stellar => soroban}/src/contract.test.ts (100%) rename packages/core/{stellar => soroban}/src/contract.test.ts.md (100%) rename packages/core/{stellar => soroban}/src/contract.test.ts.snap (100%) rename packages/core/{stellar => soroban}/src/contract.ts (100%) rename packages/core/{stellar => soroban}/src/erc20.test.ts (100%) rename packages/core/{stellar => soroban}/src/erc20.test.ts.md (100%) rename packages/core/{stellar => soroban}/src/erc20.test.ts.snap (100%) rename packages/core/{stellar => soroban}/src/erc20.ts (100%) rename packages/core/{stellar => soroban}/src/error.ts (100%) rename packages/core/{stellar => soroban}/src/external-trait.ts (100%) rename packages/core/{stellar => soroban}/src/generate/alternatives.ts (100%) rename packages/core/{stellar => soroban}/src/generate/erc20.ts (100%) rename packages/core/{stellar => soroban}/src/generate/sources.ts (100%) rename packages/core/{stellar => soroban}/src/index.ts (100%) rename packages/core/{stellar => soroban}/src/kind.ts (100%) rename packages/core/{stellar => soroban}/src/print.ts (100%) rename packages/core/{stellar => soroban}/src/scripts/update-scarb-project.ts (100%) rename packages/core/{stellar => soroban}/src/set-access-control.ts (100%) rename packages/core/{stellar => soroban}/src/set-info.ts (100%) rename packages/core/{stellar => soroban}/src/set-royalty-info.ts (100%) rename packages/core/{stellar => soroban}/src/set-upgradeable.ts (100%) rename packages/core/{stellar => soroban}/src/test.ts (100%) rename packages/core/{stellar => soroban}/src/utils/convert-strings.test.ts (100%) rename packages/core/{stellar => soroban}/src/utils/convert-strings.ts (100%) rename packages/core/{stellar => soroban}/src/utils/define-components.ts (100%) rename packages/core/{stellar => soroban}/src/utils/define-functions.ts (100%) rename packages/core/{stellar => soroban}/src/utils/duration.ts (100%) rename packages/core/{stellar => soroban}/src/utils/find-cover.ts (100%) rename packages/core/{stellar => soroban}/src/utils/format-lines.ts (100%) rename packages/core/{stellar => soroban}/src/utils/sorted-by.ts (100%) rename packages/core/{stellar => soroban}/src/utils/version.test.ts (100%) rename packages/core/{stellar => soroban}/src/utils/version.ts (100%) rename packages/core/{stellar => soroban}/tsconfig.json (100%) rename packages/ui/public/{stellar.html => soroban.html} (95%) rename packages/ui/src/{stellar => soroban}/AccessControlSection.svelte (96%) rename packages/ui/src/{stellar => soroban}/App.svelte (96%) rename packages/ui/src/{stellar => soroban}/ERC20Controls.svelte (98%) rename packages/ui/src/{stellar => soroban}/InfoSection.svelte (77%) rename packages/ui/src/{stellar => soroban}/highlightjs.ts (100%) rename packages/ui/src/{stellar => soroban}/inject-hyperlinks.ts (96%) diff --git a/packages/core/stellar/.gitignore b/packages/core/soroban/.gitignore similarity index 100% rename from packages/core/stellar/.gitignore rename to packages/core/soroban/.gitignore diff --git a/packages/core/stellar/CHANGELOG.md b/packages/core/soroban/CHANGELOG.md similarity index 100% rename from packages/core/stellar/CHANGELOG.md rename to packages/core/soroban/CHANGELOG.md diff --git a/packages/core/stellar/LICENSE b/packages/core/soroban/LICENSE similarity index 100% rename from packages/core/stellar/LICENSE rename to packages/core/soroban/LICENSE diff --git a/packages/core/stellar/NOTICE b/packages/core/soroban/NOTICE similarity index 100% rename from packages/core/stellar/NOTICE rename to packages/core/soroban/NOTICE diff --git a/packages/core/stellar/README.md b/packages/core/soroban/README.md similarity index 87% rename from packages/core/stellar/README.md rename to packages/core/soroban/README.md index 835227286..3f1e455cc 100644 --- a/packages/core/stellar/README.md +++ b/packages/core/soroban/README.md @@ -1,12 +1,12 @@ -# OpenZeppelin Contracts Wizard for Stellar +# OpenZeppelin Contracts Wizard for Soroban Interactively build a contract out of components from OpenZeppelin Soroban Contracts. Provide parameters and desired features for the kind of contract that you want, and the Wizard will generate all of the code necessary. The resulting code is ready to be compiled and deployed, or it can serve as a starting point and customized further with application specific logic. -This package provides a programmatic API. For a web interface, see https://wizard.openzeppelin.com/stellar +This package provides a programmatic API. For a web interface, see https://wizard.openzeppelin.com/soroban ### Installation -`npm install @openzeppelin/wizard-stellar` +`npm install @openzeppelin/wizard-soroban` ### Contract types @@ -37,10 +37,10 @@ Whether any of the provided options require access control to be enabled. If thi ### Examples -Import the contract type(s) (for example, `erc20`) that you want to use from the `@openzeppelin/wizard-stellar` package: +Import the contract type(s) (for example, `erc20`) that you want to use from the `@openzeppelin/wizard-soroban` package: ```js -import { erc20 } from '@openzeppelin/wizard-stellar'; +import { erc20 } from '@openzeppelin/wizard-soroban'; ``` To generate the source code for an ERC20 contract with all of the default settings: diff --git a/packages/core/stellar/ava.config.js b/packages/core/soroban/ava.config.js similarity index 100% rename from packages/core/stellar/ava.config.js rename to packages/core/soroban/ava.config.js diff --git a/packages/core/stellar/package.json b/packages/core/soroban/package.json similarity index 94% rename from packages/core/stellar/package.json rename to packages/core/soroban/package.json index e8aebb82a..81bd6b613 100644 --- a/packages/core/stellar/package.json +++ b/packages/core/soroban/package.json @@ -1,5 +1,5 @@ { - "name": "@openzeppelin/wizard-stellar", + "name": "@openzeppelin/wizard-soroban", "version": "0.0.1", "description": "A boilerplate generator to get started with OpenZeppelin Soroban Contracts", "license": "AGPL-3.0-only", diff --git a/packages/core/stellar/src/add-pausable.ts b/packages/core/soroban/src/add-pausable.ts similarity index 100% rename from packages/core/stellar/src/add-pausable.ts rename to packages/core/soroban/src/add-pausable.ts diff --git a/packages/core/stellar/src/api.ts b/packages/core/soroban/src/api.ts similarity index 100% rename from packages/core/stellar/src/api.ts rename to packages/core/soroban/src/api.ts diff --git a/packages/core/stellar/src/build-generic.ts b/packages/core/soroban/src/build-generic.ts similarity index 100% rename from packages/core/stellar/src/build-generic.ts rename to packages/core/soroban/src/build-generic.ts diff --git a/packages/core/stellar/src/common-components.ts b/packages/core/soroban/src/common-components.ts similarity index 100% rename from packages/core/stellar/src/common-components.ts rename to packages/core/soroban/src/common-components.ts diff --git a/packages/core/stellar/src/common-options.ts b/packages/core/soroban/src/common-options.ts similarity index 100% rename from packages/core/stellar/src/common-options.ts rename to packages/core/soroban/src/common-options.ts diff --git a/packages/core/stellar/src/contract.test.ts b/packages/core/soroban/src/contract.test.ts similarity index 100% rename from packages/core/stellar/src/contract.test.ts rename to packages/core/soroban/src/contract.test.ts diff --git a/packages/core/stellar/src/contract.test.ts.md b/packages/core/soroban/src/contract.test.ts.md similarity index 100% rename from packages/core/stellar/src/contract.test.ts.md rename to packages/core/soroban/src/contract.test.ts.md diff --git a/packages/core/stellar/src/contract.test.ts.snap b/packages/core/soroban/src/contract.test.ts.snap similarity index 100% rename from packages/core/stellar/src/contract.test.ts.snap rename to packages/core/soroban/src/contract.test.ts.snap diff --git a/packages/core/stellar/src/contract.ts b/packages/core/soroban/src/contract.ts similarity index 100% rename from packages/core/stellar/src/contract.ts rename to packages/core/soroban/src/contract.ts diff --git a/packages/core/stellar/src/erc20.test.ts b/packages/core/soroban/src/erc20.test.ts similarity index 100% rename from packages/core/stellar/src/erc20.test.ts rename to packages/core/soroban/src/erc20.test.ts diff --git a/packages/core/stellar/src/erc20.test.ts.md b/packages/core/soroban/src/erc20.test.ts.md similarity index 100% rename from packages/core/stellar/src/erc20.test.ts.md rename to packages/core/soroban/src/erc20.test.ts.md diff --git a/packages/core/stellar/src/erc20.test.ts.snap b/packages/core/soroban/src/erc20.test.ts.snap similarity index 100% rename from packages/core/stellar/src/erc20.test.ts.snap rename to packages/core/soroban/src/erc20.test.ts.snap diff --git a/packages/core/stellar/src/erc20.ts b/packages/core/soroban/src/erc20.ts similarity index 100% rename from packages/core/stellar/src/erc20.ts rename to packages/core/soroban/src/erc20.ts diff --git a/packages/core/stellar/src/error.ts b/packages/core/soroban/src/error.ts similarity index 100% rename from packages/core/stellar/src/error.ts rename to packages/core/soroban/src/error.ts diff --git a/packages/core/stellar/src/external-trait.ts b/packages/core/soroban/src/external-trait.ts similarity index 100% rename from packages/core/stellar/src/external-trait.ts rename to packages/core/soroban/src/external-trait.ts diff --git a/packages/core/stellar/src/generate/alternatives.ts b/packages/core/soroban/src/generate/alternatives.ts similarity index 100% rename from packages/core/stellar/src/generate/alternatives.ts rename to packages/core/soroban/src/generate/alternatives.ts diff --git a/packages/core/stellar/src/generate/erc20.ts b/packages/core/soroban/src/generate/erc20.ts similarity index 100% rename from packages/core/stellar/src/generate/erc20.ts rename to packages/core/soroban/src/generate/erc20.ts diff --git a/packages/core/stellar/src/generate/sources.ts b/packages/core/soroban/src/generate/sources.ts similarity index 100% rename from packages/core/stellar/src/generate/sources.ts rename to packages/core/soroban/src/generate/sources.ts diff --git a/packages/core/stellar/src/index.ts b/packages/core/soroban/src/index.ts similarity index 100% rename from packages/core/stellar/src/index.ts rename to packages/core/soroban/src/index.ts diff --git a/packages/core/stellar/src/kind.ts b/packages/core/soroban/src/kind.ts similarity index 100% rename from packages/core/stellar/src/kind.ts rename to packages/core/soroban/src/kind.ts diff --git a/packages/core/stellar/src/print.ts b/packages/core/soroban/src/print.ts similarity index 100% rename from packages/core/stellar/src/print.ts rename to packages/core/soroban/src/print.ts diff --git a/packages/core/stellar/src/scripts/update-scarb-project.ts b/packages/core/soroban/src/scripts/update-scarb-project.ts similarity index 100% rename from packages/core/stellar/src/scripts/update-scarb-project.ts rename to packages/core/soroban/src/scripts/update-scarb-project.ts diff --git a/packages/core/stellar/src/set-access-control.ts b/packages/core/soroban/src/set-access-control.ts similarity index 100% rename from packages/core/stellar/src/set-access-control.ts rename to packages/core/soroban/src/set-access-control.ts diff --git a/packages/core/stellar/src/set-info.ts b/packages/core/soroban/src/set-info.ts similarity index 100% rename from packages/core/stellar/src/set-info.ts rename to packages/core/soroban/src/set-info.ts diff --git a/packages/core/stellar/src/set-royalty-info.ts b/packages/core/soroban/src/set-royalty-info.ts similarity index 100% rename from packages/core/stellar/src/set-royalty-info.ts rename to packages/core/soroban/src/set-royalty-info.ts diff --git a/packages/core/stellar/src/set-upgradeable.ts b/packages/core/soroban/src/set-upgradeable.ts similarity index 100% rename from packages/core/stellar/src/set-upgradeable.ts rename to packages/core/soroban/src/set-upgradeable.ts diff --git a/packages/core/stellar/src/test.ts b/packages/core/soroban/src/test.ts similarity index 100% rename from packages/core/stellar/src/test.ts rename to packages/core/soroban/src/test.ts diff --git a/packages/core/stellar/src/utils/convert-strings.test.ts b/packages/core/soroban/src/utils/convert-strings.test.ts similarity index 100% rename from packages/core/stellar/src/utils/convert-strings.test.ts rename to packages/core/soroban/src/utils/convert-strings.test.ts diff --git a/packages/core/stellar/src/utils/convert-strings.ts b/packages/core/soroban/src/utils/convert-strings.ts similarity index 100% rename from packages/core/stellar/src/utils/convert-strings.ts rename to packages/core/soroban/src/utils/convert-strings.ts diff --git a/packages/core/stellar/src/utils/define-components.ts b/packages/core/soroban/src/utils/define-components.ts similarity index 100% rename from packages/core/stellar/src/utils/define-components.ts rename to packages/core/soroban/src/utils/define-components.ts diff --git a/packages/core/stellar/src/utils/define-functions.ts b/packages/core/soroban/src/utils/define-functions.ts similarity index 100% rename from packages/core/stellar/src/utils/define-functions.ts rename to packages/core/soroban/src/utils/define-functions.ts diff --git a/packages/core/stellar/src/utils/duration.ts b/packages/core/soroban/src/utils/duration.ts similarity index 100% rename from packages/core/stellar/src/utils/duration.ts rename to packages/core/soroban/src/utils/duration.ts diff --git a/packages/core/stellar/src/utils/find-cover.ts b/packages/core/soroban/src/utils/find-cover.ts similarity index 100% rename from packages/core/stellar/src/utils/find-cover.ts rename to packages/core/soroban/src/utils/find-cover.ts diff --git a/packages/core/stellar/src/utils/format-lines.ts b/packages/core/soroban/src/utils/format-lines.ts similarity index 100% rename from packages/core/stellar/src/utils/format-lines.ts rename to packages/core/soroban/src/utils/format-lines.ts diff --git a/packages/core/stellar/src/utils/sorted-by.ts b/packages/core/soroban/src/utils/sorted-by.ts similarity index 100% rename from packages/core/stellar/src/utils/sorted-by.ts rename to packages/core/soroban/src/utils/sorted-by.ts diff --git a/packages/core/stellar/src/utils/version.test.ts b/packages/core/soroban/src/utils/version.test.ts similarity index 100% rename from packages/core/stellar/src/utils/version.test.ts rename to packages/core/soroban/src/utils/version.test.ts diff --git a/packages/core/stellar/src/utils/version.ts b/packages/core/soroban/src/utils/version.ts similarity index 100% rename from packages/core/stellar/src/utils/version.ts rename to packages/core/soroban/src/utils/version.ts diff --git a/packages/core/stellar/tsconfig.json b/packages/core/soroban/tsconfig.json similarity index 100% rename from packages/core/stellar/tsconfig.json rename to packages/core/soroban/tsconfig.json diff --git a/packages/ui/public/cairo.html b/packages/ui/public/cairo.html index f1401d2a5..791cfd17f 100644 --- a/packages/ui/public/cairo.html +++ b/packages/ui/public/cairo.html @@ -54,7 +54,7 @@ soliditySolidity cairoCairo stylusStylus - stellarStellar + sorobanSoroban
    diff --git a/packages/ui/public/index.html b/packages/ui/public/index.html index 604199f6c..4ff117518 100644 --- a/packages/ui/public/index.html +++ b/packages/ui/public/index.html @@ -86,7 +86,7 @@ soliditySolidity cairoCairo stylusStylus - stellarStellar + sorobanSoroban
    diff --git a/packages/ui/public/stellar.html b/packages/ui/public/soroban.html similarity index 95% rename from packages/ui/public/stellar.html rename to packages/ui/public/soroban.html index 5a31cfeb9..f14f26b73 100644 --- a/packages/ui/public/stellar.html +++ b/packages/ui/public/soroban.html @@ -3,12 +3,12 @@ - OpenZeppelin Contracts Wizard for Stellar + OpenZeppelin Contracts Wizard for Soroban - + @@ -54,11 +54,11 @@ soliditySolidity cairoCairo stylusStylus - stellarStellar + sorobanSoroban
    - +