diff --git a/.github/workflows/git-clean.yaml b/.github/workflows/git-clean.yaml index 4715398..d7b645a 100644 --- a/.github/workflows/git-clean.yaml +++ b/.github/workflows/git-clean.yaml @@ -1,26 +1,33 @@ name: Git is clean on: [push] - jobs: git-clean: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - uses: nixbuild/nix-quick-install-action@v30 with: - submodules: recursive - fetch-depth: 0 - - - uses: DeterminateSystems/nix-installer-action@main - - uses: DeterminateSystems/magic-nix-cache-action@main - - # Build metas etc. required to do a correct pointer build. - - run: nix develop -c rain-flare-prelude - - - run: nix develop -c forge script ./script/BuildPointers.sol - - # Format the repo after generating pointers so that the pointer files are - # formatted too. - - run: nix develop -c forge fmt - - # Check if the repo is clean after generating pointers and formatting. - - run: git diff --exit-code \ No newline at end of file + nix_conf: | + keep-env-derivations = true + keep-outputs = true + - name: Restore and save Nix store + uses: nix-community/cache-nix-action@v6 + with: + primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/flake.lock') }} + restore-prefixes-first-match: nix-${{ runner.os }}- + gc-max-store-size-linux: 1G + - name: Install soldeer dependencies + if: hashFiles('soldeer.lock') != '' + run: nix develop github:rainlanguage/rainix#sol-shell -c forge soldeer install + - name: Regenerate meta files + run: nix run .#rain-flare-prelude + - name: Regenerate pointer artifacts + run: nix develop github:rainlanguage/rainix#sol-shell -c forge script ./script/BuildPointers.sol + - name: Format + run: nix develop github:rainlanguage/rainix#sol-shell -c forge fmt + - name: Assert committed artifacts match freshly built + run: | + if ! git diff --exit-code; then + echo "::error::Committed meta or pointer artifacts are stale. Regenerate and commit." + exit 1 + fi diff --git a/.github/workflows/manual-sol-artifacts.yaml b/.github/workflows/manual-sol-artifacts.yaml new file mode 100644 index 0000000..ebcc6aa --- /dev/null +++ b/.github/workflows/manual-sol-artifacts.yaml @@ -0,0 +1,16 @@ +name: Manual sol artifacts +on: + workflow_dispatch: + inputs: + suite: + description: "The suite to deploy" + required: true + type: choice + options: + - flare-ftso-words +jobs: + deploy: + uses: rainlanguage/rainix/.github/workflows/rainix-manual-sol-artifacts.yaml@main + with: + suite: ${{ inputs.suite }} + secrets: inherit diff --git a/.github/workflows/manual-sol-artifacts.yml b/.github/workflows/manual-sol-artifacts.yml deleted file mode 100644 index 6fa1bc3..0000000 --- a/.github/workflows/manual-sol-artifacts.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: Manual sol artifacts -on: - workflow_dispatch: - inputs: - network: - description: 'Network to deploy to' - required: true - type: choice - options: - - songbird - - flare - -jobs: - deploy: - runs-on: ubuntu-latest - steps: - - run: | - network=${{ inputs.network }} - echo "etherscan_api_key_secret_name=CI_DEPLOY_${network^^}_ETHERSCAN_API_KEY" >> $GITHUB_ENV - echo "rpc_secret_name=CI_DEPLOY_${network^^}_RPC_URL" >> $GITHUB_ENV - echo "verify_secret_name=CI_DEPLOY_${network^^}_VERIFY" >> $GITHUB_ENV - echo "verifier_secret_name=CI_DEPLOY_${network^^}_VERIFIER" >> $GITHUB_ENV - echo "verifier_url_secret_name=CI_DEPLOY_${network^^}_VERIFIER_URL" >> $GITHUB_ENV - echo "metaboard_address_secret_name=CI_DEPLOY_${network^^}_METABOARD_ADDRESS" >> $GITHUB_ENV - - - uses: actions/checkout@v4 - with: - submodules: recursive - fetch-depth: 0 - - - uses: DeterminateSystems/nix-installer-action@v4 - - uses: DeterminateSystems/magic-nix-cache-action@v2 - - - run: nix develop -c rainix-sol-prelude - working-directory: ./lib/rain.interpreter - - run: nix develop -c rainix-rs-prelude - working-directory: ./lib/rain.interpreter - - run: nix develop -c i9r-prelude - working-directory: ./lib/rain.interpreter - - - run: nix develop -c rainix-sol-prelude - - run: nix develop -c rain-flare-prelude - - - run: nix develop -c rainix-sol-artifacts - env: - DEPLOY_BROADCAST: '1' - DEPLOYMENT_KEY: ${{ github.ref == 'refs/heads/main' && secrets.PRIVATE_KEY || secrets.PRIVATE_KEY_DEV }} - ETH_RPC_URL: ${{ secrets[env.rpc_secret_name] || vars[env.rpc_secret_name] || '' }} - ETHERSCAN_API_KEY: ${{ secrets[env.etherscan_api_key_secret_name] || vars[env.etherscan_api_key_secret_name] || ''}} - DEPLOY_VERIFY: ${{ secrets[env.verify_secret_name] || vars[env.verify_secret_name] || '' }} - DEPLOY_VERIFIER: ${{ secrets[env.verifier_secret_name] || vars[env.verifier_secret_name] || '' }} - DEPLOY_VERIFIER_URL: ${{ secrets[env.verifier_url_secret_name] || vars[env.verifier_url_secret_name] || '' }} - DEPLOY_METABOARD_ADDRESS: ${{ secrets[env.metaboard_address_secret_name] || vars[env.metaboard_address_secret_name] || '' }} \ No newline at end of file diff --git a/.github/workflows/publish-soldeer.yaml b/.github/workflows/publish-soldeer.yaml new file mode 100644 index 0000000..066aa41 --- /dev/null +++ b/.github/workflows/publish-soldeer.yaml @@ -0,0 +1,8 @@ +name: Publish to Soldeer +on: + push: + tags: ["v*"] +jobs: + publish: + uses: rainlanguage/rainix/.github/workflows/publish-soldeer.yaml@main + secrets: inherit diff --git a/.github/workflows/rainix-sol.yaml b/.github/workflows/rainix-sol.yaml new file mode 100644 index 0000000..827ab30 --- /dev/null +++ b/.github/workflows/rainix-sol.yaml @@ -0,0 +1,6 @@ +name: rainix-sol +on: [push] +jobs: + rainix-sol: + uses: rainlanguage/rainix/.github/workflows/rainix-sol.yaml@main + secrets: inherit diff --git a/.github/workflows/rainix.yml b/.github/workflows/rainix.yml deleted file mode 100644 index bb46595..0000000 --- a/.github/workflows/rainix.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Rainix CI -on: [push] - -jobs: - rainix: - strategy: - matrix: - os: [ubuntu-latest] - task: [rainix-sol-test, rainix-sol-static, rainix-sol-legal] - fail-fast: false - runs-on: ${{ matrix.os }} - env: - DEPLOYMENT_KEY: ${{ github.ref == 'refs/heads/main' && secrets.PRIVATE_KEY || secrets.PRIVATE_KEY_DEV }} - steps: - - uses: actions/checkout@v4 - with: - submodules: recursive - fetch-depth: 0 - - - uses: DeterminateSystems/nix-installer-action@v4 - - uses: DeterminateSystems/magic-nix-cache-action@v2 - - - run: nix develop -c rainix-sol-prelude - working-directory: ./lib/rain.interpreter - - run: nix develop -c i9r-prelude - working-directory: ./lib/rain.interpreter - - - run: nix develop -c rainix-sol-prelude - - run: nix develop -c rain-flare-prelude - - name: Run ${{ matrix.task }} - env: - ETH_RPC_URL: ${{ secrets.CI_DEPLOY_RPC_URL }} - ETHERSCAN_API_KEY: ${{ secrets.EXPLORER_VERIFICATION_KEY }} - RPC_URL_FLARE_FORK: ${{ secrets.RPC_URL_FLARE_FORK }} - run: nix develop -c ${{ matrix.task }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index fb5751b..e9a24fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Compiler files cache/ out/ +dependencies/ # Ignores development broadcast logs !/broadcast @@ -13,4 +14,5 @@ docs/ # Dotenv file .env -meta \ No newline at end of file +.direnv +.pre-commit-config.yaml diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 2a1cd11..0000000 --- a/.gitmodules +++ /dev/null @@ -1,9 +0,0 @@ -[submodule "lib/flare-smart-contracts-v2"] - path = lib/flare-smart-contracts-v2 - url = https://github.com/flare-foundation/flare-smart-contracts-v2 -[submodule "lib/rain.interpreter"] - path = lib/rain.interpreter - url = https://github.com/rainlanguage/rain.interpreter -[submodule "lib/flare-smart-contracts"] - path = lib/flare-smart-contracts - url = https://gitlab.com/flarenetwork/flare-smart-contracts diff --git a/.soldeerignore b/.soldeerignore new file mode 100644 index 0000000..ad1586c --- /dev/null +++ b/.soldeerignore @@ -0,0 +1,30 @@ +.DS_Store +.cargo +.coderabbit.yaml +.devcontainer.json +.envrc +.gas-snapshot +.git +.github +.gitignore +.gitmodules +.pre-commit-config.yaml +.prettierignore +.soldeerignore +.vscode +CLAUDE.md +/audit +/cache +/dependencies +/flake.lock +/flake.nix +/foundry.lock +/foundry.toml +/lib +/out +/remappings.txt +/slither.config.json +/soldeer.lock +/REUSE.toml +/deployments +/meta diff --git a/LICENSES/MIT.txt b/LICENSES/MIT.txt new file mode 100644 index 0000000..d817195 --- /dev/null +++ b/LICENSES/MIT.txt @@ -0,0 +1,18 @@ +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the +following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/REUSE.toml b/REUSE.toml index f49a274..d3732fe 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -2,17 +2,26 @@ version = 1 [[annotations]] path = [ - ".gas-snapshot", - ".github/workflows/**/", - ".gitignore", - ".gitmodules", - "README.md", - "flake.lock", - "flake.nix", - "foundry.toml", - "slither.config.json", - "REUSE.toml", - "foundry.lock", + ".gas-snapshot", + ".github/workflows/**/", + ".gitignore", + ".soldeerignore", + "README.md", + "flake.lock", + "flake.nix", + "foundry.toml", + "meta/**/", + "remappings.txt", + "slither.config.json", + "REUSE.toml", + "soldeer.lock", + "src/generated/**/", ] SPDX-FileCopyrightText = "Copyright (c) 2020 Rain Open Source Software Ltd" SPDX-License-Identifier = "LicenseRef-DCL-1.0" + +# Vendored Flare interface files (upstream MIT, see LICENSES/MIT.txt). +[[annotations]] +path = ["src/vendor/**/"] +SPDX-FileCopyrightText = "Copyright (c) 2024 Flare Foundation" +SPDX-License-Identifier = "MIT" diff --git a/flake.lock b/flake.lock index f643092..e92e62c 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,37 @@ { "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -23,11 +55,11 @@ "systems": "systems_2" }, "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { @@ -41,11 +73,11 @@ "systems": "systems_3" }, "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { @@ -74,11 +106,11 @@ "systems": "systems_4" }, "locked": { - "lastModified": 1705309234, - "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", - "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { @@ -91,24 +123,6 @@ "inputs": { "systems": "systems_5" }, - "locked": { - "lastModified": 1705309234, - "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_7": { - "inputs": { - "systems": "systems_6" - }, "locked": { "lastModified": 1731533236, "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", @@ -123,7 +137,7 @@ "type": "github" } }, - "flake-utils_8": { + "flake-utils_7": { "locked": { "lastModified": 1644229661, "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", @@ -138,9 +152,9 @@ "type": "github" } }, - "flake-utils_9": { + "flake-utils_8": { "inputs": { - "systems": "systems_7" + "systems": "systems_6" }, "locked": { "lastModified": 1731533236, @@ -162,31 +176,30 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1714727549, - "narHash": "sha256-CWXRTxxcgMfQubJugpeg3yVWIfm70MYTtgaKWKgD60U=", + "lastModified": 1778486972, + "narHash": "sha256-iuy/TbK9AbghEld2VSFuxyAF30LkOGUUdtrvixLfE7M=", "owner": "shazow", "repo": "foundry.nix", - "rev": "47cf189ec395eda4b3e0623179d1075c8027ca97", + "rev": "db117ae95a77b9ead24137c3ccb28896ae4fa4ec", "type": "github" }, "original": { "owner": "shazow", - "ref": "monthly", "repo": "foundry.nix", "type": "github" } }, "foundry_2": { "inputs": { - "flake-utils": "flake-utils_8", - "nixpkgs": "nixpkgs_5" + "flake-utils": "flake-utils_7", + "nixpkgs": "nixpkgs_6" }, "locked": { - "lastModified": 1758705030, - "narHash": "sha256-zYM8PiEXANNrtjfyGUc7w37/D/kCynp0cQS+wCQ77GI=", + "lastModified": 1778486972, + "narHash": "sha256-iuy/TbK9AbghEld2VSFuxyAF30LkOGUUdtrvixLfE7M=", "owner": "shazow", "repo": "foundry.nix", - "rev": "b59a55014050110170023e3e1c277c1d4a2f055b", + "rev": "db117ae95a77b9ead24137c3ccb28896ae4fa4ec", "type": "github" }, "original": { @@ -195,6 +208,91 @@ "type": "github" } }, + "git-hooks-nix": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1778507602, + "narHash": "sha256-kTwur1wV+01SdqskVMSo6JMEpg71ps3HpbFY2GsflKs=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "61ab0e80d9c7ab14c256b5b453d8b3fb0189ba0a", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "git-hooks-nix_2": { + "inputs": { + "flake-compat": "flake-compat_2", + "gitignore": "gitignore_2", + "nixpkgs": "nixpkgs_7" + }, + "locked": { + "lastModified": 1778507602, + "narHash": "sha256-kTwur1wV+01SdqskVMSo6JMEpg71ps3HpbFY2GsflKs=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "61ab0e80d9c7ab14c256b5b453d8b3fb0189ba0a", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "rain", + "rainix", + "git-hooks-nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "gitignore_2": { + "inputs": { + "nixpkgs": [ + "rainix", + "git-hooks-nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1666753130, @@ -209,13 +307,45 @@ "type": "indirect" } }, + "nixpkgs_10": { + "locked": { + "lastModified": 1777641297, + "narHash": "sha256-WNGcmeOZ8Tr9dq6ztCspYbzWFswr2mPebM9LpsfGxPk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c6d65881c5624c9cae5ea6cedef24699b0c0a4c0", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs_2": { "locked": { - "lastModified": 1714764285, - "narHash": "sha256-oeevp27kMeDjKdxaTyXyS14TLjJrpJhXp7UVEUdYqYs=", + "lastModified": 1770073757, + "narHash": "sha256-Vy+G+F+3E/Tl+GMNgiHl9Pah2DgShmIUBJXmbiQPHbI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "47472570b1e607482890801aeaf29bfb749884f6", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1778656924, + "narHash": "sha256-lKVrom9wOmpC3i7m+uBoGaBdW0PfH3QbLRG1XmuC6YA=", "owner": "nixos", "repo": "nixpkgs", - "rev": "d121ce778b2609ae9e749a711295ffca013a82c4", + "rev": "4ba039de0909446943c07e2b42bd2f0f4507072e", "type": "github" }, "original": { @@ -224,13 +354,13 @@ "type": "github" } }, - "nixpkgs_3": { + "nixpkgs_4": { "locked": { - "lastModified": 1706487304, - "narHash": "sha256-LE8lVX28MV2jWJsidW13D2qrHU/RUUONendL2Q/WlJg=", + "lastModified": 1744536153, + "narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "90f456026d284c22b3e3497be980b2e47d0b28ac", + "rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11", "type": "github" }, "original": { @@ -240,13 +370,13 @@ "type": "github" } }, - "nixpkgs_4": { + "nixpkgs_5": { "locked": { - "lastModified": 1708564076, - "narHash": "sha256-KKkqoxlgx9n3nwST7O2kM8tliDOijiSSNaWuSkiozdQ=", + "lastModified": 1777641297, + "narHash": "sha256-WNGcmeOZ8Tr9dq6ztCspYbzWFswr2mPebM9LpsfGxPk=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "98b00b6947a9214381112bdb6f89c25498db4959", + "rev": "c6d65881c5624c9cae5ea6cedef24699b0c0a4c0", "type": "github" }, "original": { @@ -256,7 +386,7 @@ "type": "github" } }, - "nixpkgs_5": { + "nixpkgs_6": { "locked": { "lastModified": 1666753130, "narHash": "sha256-Wff1dGPFSneXJLI2c0kkdWTgxnQ416KE6X4KnFkgPYQ=", @@ -270,44 +400,44 @@ "type": "indirect" } }, - "nixpkgs_6": { + "nixpkgs_7": { "locked": { - "lastModified": 1758711836, - "narHash": "sha256-uBqPg7wNX2v6YUdTswH7wWU8wqb60cFZx0tHaWTGF30=", - "owner": "nixos", + "lastModified": 1770073757, + "narHash": "sha256-Vy+G+F+3E/Tl+GMNgiHl9Pah2DgShmIUBJXmbiQPHbI=", + "owner": "NixOS", "repo": "nixpkgs", - "rev": "46f97b78e825ae762c0224e3983c47687436a498", + "rev": "47472570b1e607482890801aeaf29bfb749884f6", "type": "github" }, "original": { - "owner": "nixos", + "owner": "NixOS", + "ref": "nixpkgs-unstable", "repo": "nixpkgs", "type": "github" } }, - "nixpkgs_7": { + "nixpkgs_8": { "locked": { - "lastModified": 1744536153, - "narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=", - "owner": "NixOS", + "lastModified": 1778656924, + "narHash": "sha256-lKVrom9wOmpC3i7m+uBoGaBdW0PfH3QbLRG1XmuC6YA=", + "owner": "nixos", "repo": "nixpkgs", - "rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11", + "rev": "4ba039de0909446943c07e2b42bd2f0f4507072e", "type": "github" }, "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", + "owner": "nixos", "repo": "nixpkgs", "type": "github" } }, - "nixpkgs_8": { + "nixpkgs_9": { "locked": { - "lastModified": 1748662220, - "narHash": "sha256-7gGa49iB9nCnFk4h/g9zwjlQAyjtpgcFkODjcOQS0Es=", + "lastModified": 1744536153, + "narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "59138c7667b7970d205d6a05a8bfa2d78caa3643", + "rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11", "type": "github" }, "original": { @@ -323,11 +453,11 @@ "rainix": "rainix" }, "locked": { - "lastModified": 1714768001, - "narHash": "sha256-Vv5FZx6AFaHsJWQl5bsuhLbY8NWGeD0JHbAdceVZMqo=", + "lastModified": 1778746225, + "narHash": "sha256-AwCvQF3zlhjO8eQWBrkjMy6buhNXDabN6/DeHq5En+A=", "owner": "rainlanguage", "repo": "rain.cli", - "rev": "dc7ffe3b905ca57e92be6f294426f32fcf8005eb", + "rev": "bbf79984f43aae3ef8f72f60a2ca46108f27f12f", "type": "github" }, "original": { @@ -340,16 +470,17 @@ "inputs": { "flake-utils": "flake-utils_3", "foundry": "foundry", - "nixpkgs": "nixpkgs_2", + "git-hooks-nix": "git-hooks-nix", + "nixpkgs": "nixpkgs_3", "rust-overlay": "rust-overlay", "solc": "solc" }, "locked": { - "lastModified": 1714764843, - "narHash": "sha256-7ae0pHvjlInc1V3QxjW5iNhXAYerO1/fhLgzQnPNPjE=", + "lastModified": 1778696671, + "narHash": "sha256-egKixfe1+7/MtwhFjtfvGz+1eNtMQRNUdaWeR1GiXi0=", "owner": "rainlanguage", "repo": "rainix", - "rev": "f3bdb28f353f8cba28b2bba86f79c362dd65ee53", + "rev": "998bd91d4dbf8a28a32c7683d66624c91a907579", "type": "github" }, "original": { @@ -360,22 +491,23 @@ }, "rainix_2": { "inputs": { - "flake-utils": "flake-utils_7", + "flake-utils": "flake-utils_6", "foundry": "foundry_2", - "nixpkgs": "nixpkgs_6", + "git-hooks-nix": "git-hooks-nix_2", + "nixpkgs": "nixpkgs_8", "rust-overlay": "rust-overlay_2", "solc": "solc_2" }, "locked": { - "lastModified": 1760460761, - "narHash": "sha256-IHvwnmphDaOyZnzvObwOoDQlA9nzym2ZUxe9K/5vs0U=", - "owner": "rainprotocol", + "lastModified": 1778696671, + "narHash": "sha256-egKixfe1+7/MtwhFjtfvGz+1eNtMQRNUdaWeR1GiXi0=", + "owner": "rainlanguage", "repo": "rainix", - "rev": "add0d8a1fd76ce0e65b962c952e9252257876465", + "rev": "998bd91d4dbf8a28a32c7683d66624c91a907579", "type": "github" }, "original": { - "owner": "rainprotocol", + "owner": "rainlanguage", "repo": "rainix", "type": "github" } @@ -389,15 +521,14 @@ }, "rust-overlay": { "inputs": { - "flake-utils": "flake-utils_5", - "nixpkgs": "nixpkgs_3" + "nixpkgs": "nixpkgs_4" }, "locked": { - "lastModified": 1714702555, - "narHash": "sha256-/NoUbE5S5xpK1FU3nlHhQ/tL126+JcisXdzy3Ng4pDU=", + "lastModified": 1778642276, + "narHash": "sha256-bhk4lawR4ZnFhPtamB5WkCyvfgyZmsEUbWfT/3FRxFY=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "7f0e3ef7b7fbed78e12e5100851175d28af4b7c6", + "rev": "77265d2dc1e61b2abfd3b1d6609dbb66fe75e0a5", "type": "github" }, "original": { @@ -408,14 +539,14 @@ }, "rust-overlay_2": { "inputs": { - "nixpkgs": "nixpkgs_7" + "nixpkgs": "nixpkgs_9" }, "locked": { - "lastModified": 1758681214, - "narHash": "sha256-8cW731vev6kfr58cILO2ZsjHwaPhm88dQ8Q6nTSjP9I=", + "lastModified": 1778642276, + "narHash": "sha256-bhk4lawR4ZnFhPtamB5WkCyvfgyZmsEUbWfT/3FRxFY=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "b12ed88d8d33d4f3cbc842bf29fad93bb1437299", + "rev": "77265d2dc1e61b2abfd3b1d6609dbb66fe75e0a5", "type": "github" }, "original": { @@ -426,15 +557,16 @@ }, "solc": { "inputs": { - "flake-utils": "flake-utils_6", - "nixpkgs": "nixpkgs_4" + "flake-utils": "flake-utils_5", + "nixpkgs": "nixpkgs_5", + "solc-macos-amd64-list-json": "solc-macos-amd64-list-json" }, "locked": { - "lastModified": 1711538161, - "narHash": "sha256-rETVdEIQ2PyEcNgzXXFSiYAYl0koCeGDIWp9XYBTxoQ=", + "lastModified": 1777817996, + "narHash": "sha256-iI71iUhD7THLibl3w1JcQEhHmTwZMxChi70RTe33BAo=", "owner": "hellwolf", "repo": "solc.nix", - "rev": "a995838545a7383a0b37776e969743b1346d5479", + "rev": "e3cf898cb804d5c0e5474b378a300fe8942e67d6", "type": "github" }, "original": { @@ -446,27 +578,39 @@ "solc-macos-amd64-list-json": { "flake": false, "locked": { - "narHash": "sha256-AvITkfpNYgCypXuLJyqco0li+unVw39BAfdOZvd/SPE=", + "narHash": "sha256-zzwwHA2qPotv7yp8mK7+y9BZhm7ytuFeCJVvKBBdBn4=", + "type": "file", + "url": "https://github.com/argotorg/solc-bin/raw/902dfaf/macosx-amd64/list.json" + }, + "original": { + "type": "file", + "url": "https://github.com/argotorg/solc-bin/raw/902dfaf/macosx-amd64/list.json" + } + }, + "solc-macos-amd64-list-json_2": { + "flake": false, + "locked": { + "narHash": "sha256-zzwwHA2qPotv7yp8mK7+y9BZhm7ytuFeCJVvKBBdBn4=", "type": "file", - "url": "https://github.com/argotorg/solc-bin/raw/26fc3fd/macosx-amd64/list.json" + "url": "https://github.com/argotorg/solc-bin/raw/902dfaf/macosx-amd64/list.json" }, "original": { "type": "file", - "url": "https://github.com/argotorg/solc-bin/raw/26fc3fd/macosx-amd64/list.json" + "url": "https://github.com/argotorg/solc-bin/raw/902dfaf/macosx-amd64/list.json" } }, "solc_2": { "inputs": { - "flake-utils": "flake-utils_9", - "nixpkgs": "nixpkgs_8", - "solc-macos-amd64-list-json": "solc-macos-amd64-list-json" + "flake-utils": "flake-utils_8", + "nixpkgs": "nixpkgs_10", + "solc-macos-amd64-list-json": "solc-macos-amd64-list-json_2" }, "locked": { - "lastModified": 1756368702, - "narHash": "sha256-cqEHv7uCV0LibmQphyiXZ1+jYtGjMNb9Pae4tfcAcF8=", + "lastModified": 1777817996, + "narHash": "sha256-iI71iUhD7THLibl3w1JcQEhHmTwZMxChi70RTe33BAo=", "owner": "hellwolf", "repo": "solc.nix", - "rev": "d83e90df2fa8359a690f6baabf76099432193c3f", + "rev": "e3cf898cb804d5c0e5474b378a300fe8942e67d6", "type": "github" }, "original": { @@ -564,21 +708,6 @@ "repo": "default", "type": "github" } - }, - "systems_7": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 6a7538e..63fa640 100644 --- a/flake.nix +++ b/flake.nix @@ -3,15 +3,23 @@ inputs = { flake-utils.url = "github:numtide/flake-utils"; - rainix.url = "github:rainprotocol/rainix"; + rainix.url = "github:rainlanguage/rainix"; rain.url = "github:rainlanguage/rain.cli"; }; - outputs = { self, flake-utils, rainix, rain }: - flake-utils.lib.eachDefaultSystem (system: + outputs = + { + flake-utils, + rainix, + rain, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: let pkgs = rainix.pkgs.${system}; - in rec { + in + rec { packages = { rain-flare-prelude = rainix.mkTask.${system} { name = "rain-flare-prelude"; @@ -29,8 +37,10 @@ -o meta/FlareFtsoWords.rain.meta \ ; ''; + additionalBuildInputs = rainix.sol-build-inputs.${system} ++ [ rain.defaultPackage.${system} ]; }; - } // rainix.packages.${system}; + } + // rainix.packages.${system}; devShells.default = pkgs.mkShell { packages = [ @@ -38,9 +48,8 @@ rain.defaultPackage.${system} ]; - shellHook = rainix.devShells.${system}.default.shellHook; - buildInputs = rainix.devShells.${system}.default.buildInputs; - nativeBuildInputs = rainix.devShells.${system}.default.nativeBuildInputs; - }; } + inherit (rainix.devShells.${system}.default) shellHook buildInputs nativeBuildInputs; + }; + } ); -} \ No newline at end of file +} diff --git a/foundry.lock b/foundry.lock deleted file mode 100644 index 7b4b433..0000000 --- a/foundry.lock +++ /dev/null @@ -1,11 +0,0 @@ -{ - "lib/flare-smart-contracts": { - "rev": "03ae9c741e364bb5582afdb0dc49726b149c18f7" - }, - "lib/flare-smart-contracts-v2": { - "rev": "ecfefacd5677836974bbc193d60031796fb0bd18" - }, - "lib/rain.interpreter": { - "rev": "018871e00a0eebd63fa715674041e7b4d6f42cf0" - } -} \ No newline at end of file diff --git a/foundry.toml b/foundry.toml index 5b6dfc4..0f627a7 100644 --- a/foundry.toml +++ b/foundry.toml @@ -1,28 +1,47 @@ [profile.default] +libs = ['dependencies'] # See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options solc = "0.8.25" +optimizer = true +optimizer_runs = 1000 +evm_version = "cancun" +bytecode_hash = "none" +cbor_metadata = false +# Vendored Flare interface files (MIT-licensed, under src/vendor/). +# Neither flare-smart-contracts repo is on soldeer; only these specific +# interfaces are needed, so they're checked in rather than pulled as +# submodules. remappings = [ - "forge-std/=lib/rain.interpreter/lib/rain.interpreter.interface/lib/forge-std/src/", - "rain.sol.codegen/=lib/rain.interpreter/lib/rain.interpreter.interface/lib/rain.sol.codegen/src/", - "rain.intorastring/=lib/rain.interpreter/lib/rain.interpreter.interface/lib/rain.intorastring/src/", - "rain.metadata/=lib/rain.interpreter/lib/rain.metadata/src/", - "rain.interpreter/=lib/rain.interpreter/src/", - "@openzeppelin/contracts/token/ERC20/=lib/rain.interpreter/lib/rain.interpreter.interface/lib/forge-std/src/interfaces/", - "rain.math.float/=lib/rain.interpreter/lib/rain.interpreter.interface/lib/rain.math.float/src/", + "flare-smart-contracts/=src/vendor/flare-smart-contracts/", + "flare-smart-contracts-v2/=src/vendor/flare-smart-contracts-v2/", ] fs_permissions = [ - { access = "read-write", path = "src/generated" }, - { access = "read-write", path = "meta" }, - { access = "read", path = "lib/rain.interpreter/meta/RainterpreterExpressionDeployerNPE2.rain.meta" }, + { access = "read-write", path = "src/generated" }, + { access = "read-write", path = "meta" }, ] -optimizer = true -optimizer_runs = 1000 -evm_version = "cancun" +[dependencies] +forge-std = "1.16.1" +"@openzeppelin-contracts" = "5.6.1" +"rain-deploy" = "0.1.2" +"rain-extrospection" = "0.1.0" +"rain-interpreter-interface" = "0.1.0" +"rain-intorastring" = "0.1.0" +"rain-lib-hash" = "0.1.0" +"rain-lib-memkv" = "0.1.0" +"rain-lib-typecast" = "0.1.0" +"rain-math-binary" = "0.1.1" +"rain-math-float" = "0.1.1" +"rain-metadata" = "0.1.0" +"rain-sol-codegen" = "0.1.0" +"rain-solmem" = "0.1.3" +"rain-string" = "0.2.0" +"rain-tofu-erc20-decimals" = "0.1.1" +"rainlang" = "0.1.1" -bytecode_hash = "none" -cbor_metadata = false \ No newline at end of file +[soldeer] +recursive_deps = false diff --git a/lib/flare-smart-contracts b/lib/flare-smart-contracts deleted file mode 160000 index 03ae9c7..0000000 --- a/lib/flare-smart-contracts +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 03ae9c741e364bb5582afdb0dc49726b149c18f7 diff --git a/lib/flare-smart-contracts-v2 b/lib/flare-smart-contracts-v2 deleted file mode 160000 index ecfefac..0000000 --- a/lib/flare-smart-contracts-v2 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ecfefacd5677836974bbc193d60031796fb0bd18 diff --git a/lib/rain.interpreter b/lib/rain.interpreter deleted file mode 160000 index 018871e..0000000 --- a/lib/rain.interpreter +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 018871e00a0eebd63fa715674041e7b4d6f42cf0 diff --git a/meta/FlareFtsoSubParserAuthoringMeta.rain.meta b/meta/FlareFtsoSubParserAuthoringMeta.rain.meta new file mode 100644 index 0000000..30c24d4 Binary files /dev/null and b/meta/FlareFtsoSubParserAuthoringMeta.rain.meta differ diff --git a/meta/FlareFtsoWords.rain.meta b/meta/FlareFtsoWords.rain.meta new file mode 100644 index 0000000..279dff9 Binary files /dev/null and b/meta/FlareFtsoWords.rain.meta differ diff --git a/remappings.txt b/remappings.txt new file mode 100644 index 0000000..dea249a --- /dev/null +++ b/remappings.txt @@ -0,0 +1,17 @@ +@openzeppelin-contracts-5.6.1/=dependencies/@openzeppelin-contracts-5.6.1/ +forge-std-1.16.1/=dependencies/forge-std-1.16.1/ +rain-deploy-0.1.2/=dependencies/rain-deploy-0.1.2/ +rain-extrospection-0.1.0/=dependencies/rain-extrospection-0.1.0/ +rain-interpreter-interface-0.1.0/=dependencies/rain-interpreter-interface-0.1.0/ +rain-intorastring-0.1.0/=dependencies/rain-intorastring-0.1.0/ +rain-lib-hash-0.1.0/=dependencies/rain-lib-hash-0.1.0/ +rain-lib-memkv-0.1.0/=dependencies/rain-lib-memkv-0.1.0/ +rain-lib-typecast-0.1.0/=dependencies/rain-lib-typecast-0.1.0/ +rain-math-binary-0.1.1/=dependencies/rain-math-binary-0.1.1/ +rain-math-float-0.1.1/=dependencies/rain-math-float-0.1.1/ +rain-metadata-0.1.0/=dependencies/rain-metadata-0.1.0/ +rain-sol-codegen-0.1.0/=dependencies/rain-sol-codegen-0.1.0/ +rain-solmem-0.1.3/=dependencies/rain-solmem-0.1.3/ +rain-string-0.2.0/=dependencies/rain-string-0.2.0/ +rain-tofu-erc20-decimals-0.1.1/=dependencies/rain-tofu-erc20-decimals-0.1.1/ +rainlang-0.1.1/=dependencies/rainlang-0.1.1/ diff --git a/script/BuildAuthoringMeta.sol b/script/BuildAuthoringMeta.sol index 216eb1d..16e8878 100644 --- a/script/BuildAuthoringMeta.sol +++ b/script/BuildAuthoringMeta.sol @@ -2,7 +2,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity =0.8.25; -import {Script} from "forge-std/Script.sol"; +import {Script} from "forge-std-1.16.1/src/Script.sol"; import {LibFlareFtsoSubParser} from "src/lib/parse/LibFlareFtsoSubParser.sol"; /// @title FlareFtso subparser Authoring Meta diff --git a/script/BuildPointers.sol b/script/BuildPointers.sol index 37841f5..4f95eb8 100644 --- a/script/BuildPointers.sol +++ b/script/BuildPointers.sol @@ -2,14 +2,14 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity =0.8.25; -import {Script} from "forge-std/Script.sol"; +import {Script} from "forge-std-1.16.1/src/Script.sol"; import {FlareFtsoWords} from "src/concrete/FlareFtsoWords.sol"; -import {LibCodeGen} from "rain.sol.codegen/lib/LibCodeGen.sol"; -import {LibFs} from "rain.sol.codegen/lib/LibFs.sol"; +import {LibCodeGen} from "rain-sol-codegen-0.1.0/src/lib/LibCodeGen.sol"; +import {LibFs} from "rain-sol-codegen-0.1.0/src/lib/LibFs.sol"; import {PARSE_META_BUILD_DEPTH} from "src/abstract/FlareFtsoSubParser.sol"; import {LibFlareFtsoSubParser} from "src/lib/parse/LibFlareFtsoSubParser.sol"; -import {LibGenParseMeta} from "rain.interpreter.interface/lib/codegen/LibGenParseMeta.sol"; +import {LibGenParseMeta} from "rain-interpreter-interface-0.1.0/src/lib/codegen/LibGenParseMeta.sol"; contract BuildPointers is Script { function buildFlareFtsoWordsPointers() internal { diff --git a/script/Deploy.sol b/script/Deploy.sol index e630f58..65764c0 100644 --- a/script/Deploy.sol +++ b/script/Deploy.sol @@ -2,10 +2,10 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity =0.8.25; -import {Script} from "forge-std/Script.sol"; +import {Script} from "forge-std-1.16.1/src/Script.sol"; import {FlareFtsoWords} from "../src/concrete/FlareFtsoWords.sol"; -import {IMetaBoardV1_2} from "rain.metadata/interface/unstable/IMetaBoardV1_2.sol"; -import {LibDescribedByMeta} from "rain.metadata/lib/LibDescribedByMeta.sol"; +import {IMetaBoardV1_2} from "rain-metadata-0.1.0/src/interface/unstable/IMetaBoardV1_2.sol"; +import {LibDescribedByMeta} from "rain-metadata-0.1.0/src/lib/LibDescribedByMeta.sol"; contract Deploy is Script { function run() public { diff --git a/slither.config.json b/slither.config.json index d9b1a8b..2500dff 100644 --- a/slither.config.json +++ b/slither.config.json @@ -1,4 +1,4 @@ { "detectors_to_exclude": "assembly-usage,solc-version,unused-imports,pragma", - "filter_paths": "forge-std,openzeppelin,test,rain.math.float" + "filter_paths": "dependencies/,src/vendor/" } diff --git a/soldeer.lock b/soldeer.lock new file mode 100644 index 0000000..9ca8d33 --- /dev/null +++ b/soldeer.lock @@ -0,0 +1,62 @@ +[[dependencies]] +name = "@openzeppelin-contracts" +version = "5.6.1" +url = "https://soldeer-revisions.s3.amazonaws.com/@openzeppelin-contracts/5_6_1_15-03-2026_09:19:50_contracts.zip" +checksum = "a3b6bc661be858c7c27f60a1708cbebe8c71034b4cc1e9fe270d0a05b069352f" +integrity = "bce03af7ada1eee21a7fff393f238bcd7cd75a022a4db55ffb6b0dbb32433d35" + +[[dependencies]] +name = "forge-std" +version = "1.16.1" +url = "https://soldeer-revisions.s3.amazonaws.com/forge-std/1_16_1_08-05-2026_08:51:16_forge-std-1.16.zip" +checksum = "839b61832925c7152c7b6dffbfa4998d9e606211179bd8f604733124e8a7cb57" +integrity = "60e55d10150354ca4a1e2985c5456c834b92b82ef85ab0e1d92a7786cddbd219" + +[[dependencies]] +name = "rain-interpreter-interface" +version = "0.1.0" +url = "https://soldeer-revisions.s3.amazonaws.com/rain-interpreter-interface/0_1_0_12-05-2026_18:43:02_rain.interpreter.zip" +checksum = "887c4d5f1a87713c49f015b3fcdb295defbb495b126d15f9850c0ce72ef79639" +integrity = "c1b89f8a7ad02507ceb051b6c0f2750f6abe1ba99ffdfe1c9ac93905db90e75d" + +[[dependencies]] +name = "rain-intorastring" +version = "0.1.0" +url = "https://soldeer-revisions.s3.amazonaws.com/rain-intorastring/0_1_0_12-05-2026_19:21:48_rain.zip" +checksum = "6cd4b0e5ea0a7ffc8adef762b3687d180e4c1408ec4ff8bf8d88d5f9712bf5af" +integrity = "cad9d7a463dd388f73b1f2cf85dd212fd46320203f8d39cb0938ffb451295384" + +[[dependencies]] +name = "rain-lib-typecast" +version = "0.1.0" +url = "https://soldeer-revisions.s3.amazonaws.com/rain-lib-typecast/0_1_0_12-05-2026_16:31:39_rain.lib.zip" +checksum = "5c0419501e4c763ef161a3489934af192219f994cb2c9187699bc4dee0b4e2bb" +integrity = "092781f87fd9227c4c95aafde59300c503d6a9a355beaeb5c5732fe6e36676d6" + +[[dependencies]] +name = "rain-math-float" +version = "0.1.1" +url = "https://soldeer-revisions.s3.amazonaws.com/rain-math-float/0_1_1_13-05-2026_13:48:34_rain.math.zip" +checksum = "322956f272ae3073ee02b0e7301b8834f08f2de62bcd6c309c44e946d7cd7056" +integrity = "dccdd4406a37db6af690872b805084a7dbe5211c57961a61ef083a7912ddbdc9" + +[[dependencies]] +name = "rain-metadata" +version = "0.1.0" +url = "https://soldeer-revisions.s3.amazonaws.com/rain-metadata/0_1_0_12-05-2026_20:20:51_rain.zip" +checksum = "801d2b97b393d346c19a2f4f454d0279ba8f7d0f81fa3eb4fe8609da7291203d" +integrity = "f17f10aa50e9e2b254c689c83f41b3cabab81c95bad06424b9b3e9c92d02e577" + +[[dependencies]] +name = "rain-sol-codegen" +version = "0.1.0" +url = "https://soldeer-revisions.s3.amazonaws.com/rain-sol-codegen/0_1_0_09-05-2026_20:30:25_rain.sol.zip" +checksum = "6b5abd394c5db86ac64214262b7a5115158f480b2fbd74442672dfe52bb67310" +integrity = "e22748ce2ba7eca3ce71e23b2271d1c0f370b989507e784b0a4850a7a9e52157" + +[[dependencies]] +name = "rainlang" +version = "0.1.1" +url = "https://soldeer-revisions.s3.amazonaws.com/rainlang/0_1_1_14-05-2026_07:01:44_rainlang.zip" +checksum = "8297278d5b98c1fc2778d756e63bf964d336eaa304d3812a916de83ed308ce15" +integrity = "82213331ad557c000157641f22bebfe5d99622c3884434593a1d51239b46e377" diff --git a/src/abstract/FlareFtsoExtern.sol b/src/abstract/FlareFtsoExtern.sol index 0a4b9e1..00e10e6 100644 --- a/src/abstract/FlareFtsoExtern.sol +++ b/src/abstract/FlareFtsoExtern.sol @@ -2,12 +2,8 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity ^0.8.25; -import { - BaseRainterpreterExternNPE2, - OperandV2, - StackItem -} from "rain.interpreter/abstract/BaseRainterpreterExternNPE2.sol"; -import {LibConvert} from "rain.lib.typecast/LibConvert.sol"; +import {BaseRainlangExtern, OperandV2, StackItem} from "rainlang-0.1.1/src/abstract/BaseRainlangExtern.sol"; +import {LibConvert} from "rain-lib-typecast-0.1.0/src/LibConvert.sol"; import {LibOpFtsoCurrentPriceUsd} from "../lib/op/LibOpFtsoCurrentPriceUsd.sol"; import {LibOpFtsoCurrentPricePair} from "../lib/op/LibOpFtsoCurrentPricePair.sol"; import {LibOpSLFRCurrentExchangeRate} from "../lib/op/LibOpSFlrCurrentExchangeRate.sol"; @@ -39,13 +35,13 @@ uint256 constant OPCODE_FUNCTION_POINTERS_LENGTH = 3; /// Authoring rainlang against raw extern implementations is not a good UX so /// this is intended to be used with FlareFtsoSubParser which provides all the /// appropriate sugar to make the externs work like native rain words. -abstract contract FlareFtsoExtern is BaseRainterpreterExternNPE2 { - /// @inheritdoc BaseRainterpreterExternNPE2 +abstract contract FlareFtsoExtern is BaseRainlangExtern { + /// @inheritdoc BaseRainlangExtern function opcodeFunctionPointers() internal pure override returns (bytes memory) { return OPCODE_FUNCTION_POINTERS; } - /// @inheritdoc BaseRainterpreterExternNPE2 + /// @inheritdoc BaseRainlangExtern function integrityFunctionPointers() internal pure override returns (bytes memory) { return INTEGRITY_FUNCTION_POINTERS; } @@ -54,13 +50,9 @@ abstract contract FlareFtsoExtern is BaseRainterpreterExternNPE2 { /// relatively gas inefficent so it is only called during tests to cross /// reference against the constant values that are used at runtime. function buildOpcodeFunctionPointers() external pure returns (bytes memory) { - function(OperandV2, StackItem[] memory) - internal - view - returns (StackItem[] memory)[] memory fs = new function(OperandV2, StackItem[] memory) - internal - view - returns (StackItem[] memory)[](OPCODE_FUNCTION_POINTERS_LENGTH); + function(OperandV2, StackItem[] memory) internal view returns (StackItem[] memory)[] memory fs = new function(OperandV2, StackItem[] memory) + internal + view returns (StackItem[] memory)[](OPCODE_FUNCTION_POINTERS_LENGTH); fs[OPCODE_FTSO_CURRENT_PRICE_USD] = LibOpFtsoCurrentPriceUsd.run; fs[OPCODE_FTSO_CURRENT_PRICE_PAIR] = LibOpFtsoCurrentPricePair.run; fs[OPCODE_SLFR_CURRENT_EXCHANGE_RATE] = LibOpSLFRCurrentExchangeRate.run; @@ -76,13 +68,9 @@ abstract contract FlareFtsoExtern is BaseRainterpreterExternNPE2 { /// is relatively gas inefficent so it is only called during tests to cross /// reference against the constant values that are used at runtime. function buildIntegrityFunctionPointers() external pure returns (bytes memory) { - function(OperandV2, uint256, uint256) - internal - pure - returns (uint256, uint256)[] memory fs = new function(OperandV2, uint256, uint256) - internal - pure - returns (uint256, uint256)[](OPCODE_FUNCTION_POINTERS_LENGTH); + function(OperandV2, uint256, uint256) internal pure returns (uint256, uint256)[] memory fs = new function(OperandV2, uint256, uint256) + internal + pure returns (uint256, uint256)[](OPCODE_FUNCTION_POINTERS_LENGTH); fs[OPCODE_FTSO_CURRENT_PRICE_USD] = LibOpFtsoCurrentPriceUsd.integrity; fs[OPCODE_FTSO_CURRENT_PRICE_PAIR] = LibOpFtsoCurrentPricePair.integrity; fs[OPCODE_SLFR_CURRENT_EXCHANGE_RATE] = LibOpSLFRCurrentExchangeRate.integrity; diff --git a/src/abstract/FlareFtsoSubParser.sol b/src/abstract/FlareFtsoSubParser.sol index 876baa0..b7daf8a 100644 --- a/src/abstract/FlareFtsoSubParser.sol +++ b/src/abstract/FlareFtsoSubParser.sol @@ -3,22 +3,22 @@ pragma solidity ^0.8.25; import { - BaseRainterpreterSubParserNPE2, + BaseRainlangSubParser, OperandV2, IParserToolingV1, ISubParserToolingV1 -} from "rain.interpreter/abstract/BaseRainterpreterSubParserNPE2.sol"; +} from "rainlang-0.1.1/src/abstract/BaseRainlangSubParser.sol"; import { OPCODE_FTSO_CURRENT_PRICE_USD, OPCODE_FTSO_CURRENT_PRICE_PAIR, OPCODE_SLFR_CURRENT_EXCHANGE_RATE } from "./FlareFtsoExtern.sol"; -import {LibSubParse, IInterpreterExternV4} from "rain.interpreter/lib/parse/LibSubParse.sol"; -import {LibParseOperand} from "rain.interpreter/lib/parse/LibParseOperand.sol"; -import {LibConvert} from "rain.lib.typecast/LibConvert.sol"; +import {LibSubParse, IInterpreterExternV4} from "rainlang-0.1.1/src/lib/parse/LibSubParse.sol"; +import {LibParseOperand} from "rainlang-0.1.1/src/lib/parse/LibParseOperand.sol"; +import {LibConvert} from "rain-lib-typecast-0.1.0/src/LibConvert.sol"; //Export this for convenience. //forge-lint: disable-next-line(mixed-case-function,unused-import) -import {AuthoringMetaV2} from "rain.interpreter.interface/interface/deprecated/IParserV1.sol"; +import {AuthoringMetaV2} from "rain-interpreter-interface-0.1.0/src/interface/deprecated/v1/IParserV1.sol"; import { SUB_PARSER_WORD_FTSO_CURRENT_PRICE_USD, SUB_PARSER_WORD_FTSO_CURRENT_PRICE_PAIR, @@ -37,22 +37,22 @@ uint8 constant PARSE_META_BUILD_DEPTH = 1; /// Implements the sub parser half of FlareFtsoWords. Responsible for parsing /// the words and operands that are used by the FlareFtsoWords. Provides the /// sugar required to make the externs work like native rain words. -abstract contract FlareFtsoSubParser is BaseRainterpreterSubParserNPE2 { +abstract contract FlareFtsoSubParser is BaseRainlangSubParser { /// Allows the FlareFtsoWords contract to feed the extern address (itself) /// into the sub parser functions by overriding `extern`. function extern() internal view virtual returns (address); - /// @inheritdoc BaseRainterpreterSubParserNPE2 + /// @inheritdoc BaseRainlangSubParser function subParserParseMeta() internal pure override returns (bytes memory) { return SUB_PARSER_PARSE_META; } - /// @inheritdoc BaseRainterpreterSubParserNPE2 + /// @inheritdoc BaseRainlangSubParser function subParserWordParsers() internal pure override returns (bytes memory) { return SUB_PARSER_WORD_PARSERS; } - /// @inheritdoc BaseRainterpreterSubParserNPE2 + /// @inheritdoc BaseRainlangSubParser function subParserOperandHandlers() internal pure override returns (bytes memory) { return SUB_PARSER_OPERAND_HANDLERS; } @@ -62,10 +62,8 @@ abstract contract FlareFtsoSubParser is BaseRainterpreterSubParserNPE2 { /// reference against the constant values that are used at runtime. /// @inheritdoc IParserToolingV1 function buildOperandHandlerFunctionPointers() external pure returns (bytes memory) { - function(bytes32[] memory) internal pure returns (OperandV2)[] memory fs = new function(bytes32[] memory) - internal - pure - returns (OperandV2)[](SUB_PARSER_WORD_PARSERS_LENGTH); + function(bytes32[] memory) internal pure returns (OperandV2)[] memory fs = + new function(bytes32[] memory) internal pure returns (OperandV2)[](SUB_PARSER_WORD_PARSERS_LENGTH); fs[SUB_PARSER_WORD_FTSO_CURRENT_PRICE_USD] = LibParseOperand.handleOperandDisallowed; fs[SUB_PARSER_WORD_FTSO_CURRENT_PRICE_PAIR] = LibParseOperand.handleOperandDisallowed; fs[SUB_PARSER_WORD_SFLR_EXCHANGE_RATE] = LibParseOperand.handleOperandDisallowed; @@ -87,13 +85,9 @@ abstract contract FlareFtsoSubParser is BaseRainterpreterSubParserNPE2 { /// against the constant values that are used at runtime. /// @inheritdoc ISubParserToolingV1 function buildSubParserWordParsers() external pure returns (bytes memory) { - function(uint256, uint256, OperandV2) - internal - view - returns (bool, bytes memory, bytes32[] memory)[] memory fs = new function(uint256, uint256, OperandV2) - internal - view - returns (bool, bytes memory, bytes32[] memory)[](SUB_PARSER_WORD_PARSERS_LENGTH); + function(uint256, uint256, OperandV2) internal view returns (bool, bytes memory, bytes32[] memory)[] memory fs = new function(uint256, uint256, OperandV2) + internal + view returns (bool, bytes memory, bytes32[] memory)[](SUB_PARSER_WORD_PARSERS_LENGTH); fs[SUB_PARSER_WORD_FTSO_CURRENT_PRICE_USD] = ftsoCurrentPriceUsdSubParser; fs[SUB_PARSER_WORD_FTSO_CURRENT_PRICE_PAIR] = ftsoCurrentPricePairSubParser; fs[SUB_PARSER_WORD_SFLR_EXCHANGE_RATE] = sFlrCurrentExchangeRateSubParser; diff --git a/src/concrete/FlareFtsoWords.sol b/src/concrete/FlareFtsoWords.sol index 3f71e15..e197a1f 100644 --- a/src/concrete/FlareFtsoWords.sol +++ b/src/concrete/FlareFtsoWords.sol @@ -4,26 +4,32 @@ pragma solidity =0.8.25; import { FlareFtsoExtern, + //forge-lint: disable-next-line(unused-import) OPCODE_FUNCTION_POINTERS, + //forge-lint: disable-next-line(unused-import) INTEGRITY_FUNCTION_POINTERS, - BaseRainterpreterExternNPE2 + BaseRainlangExtern } from "../abstract/FlareFtsoExtern.sol"; import { FlareFtsoSubParser, + //forge-lint: disable-next-line(unused-import) SUB_PARSER_WORD_PARSERS, + //forge-lint: disable-next-line(unused-import) SUB_PARSER_OPERAND_HANDLERS, + //forge-lint: disable-next-line(unused-import) SUB_PARSER_PARSE_META, - BaseRainterpreterSubParserNPE2, + BaseRainlangSubParser, + //forge-lint: disable-next-line(unused-import) AuthoringMetaV2 } from "../abstract/FlareFtsoSubParser.sol"; import {DESCRIBED_BY_META_HASH} from "../generated/FlareFtsoWords.pointers.sol"; -import {IDescribedByMetaV1} from "rain.metadata/interface/IDescribedByMetaV1.sol"; +import {IDescribedByMetaV1} from "rain-metadata-0.1.0/src/interface/IDescribedByMetaV1.sol"; /// @title FlareFtsoWords /// Simply merges the two abstract contracts into a single concrete contract. @@ -42,12 +48,12 @@ contract FlareFtsoWords is FlareFtsoExtern, FlareFtsoSubParser { /// This is only needed because the parser and extern base contracts both /// implement IERC165, and the compiler needs to be told how to resolve the /// ambiguity. - /// @inheritdoc BaseRainterpreterSubParserNPE2 + /// @inheritdoc BaseRainlangSubParser function supportsInterface(bytes4 interfaceId) public view virtual - override(BaseRainterpreterSubParserNPE2, BaseRainterpreterExternNPE2) + override(BaseRainlangSubParser, BaseRainlangExtern) returns (bool) { return super.supportsInterface(interfaceId); diff --git a/src/generated/FlareFtsoWords.pointers.sol b/src/generated/FlareFtsoWords.pointers.sol index 76ba550..5fe54d7 100644 --- a/src/generated/FlareFtsoWords.pointers.sol +++ b/src/generated/FlareFtsoWords.pointers.sol @@ -10,7 +10,7 @@ pragma solidity ^0.8.25; // file needs the contract to exist so that it can be compiled. /// @dev Hash of the known bytecode. -bytes32 constant BYTECODE_HASH = bytes32(0xa88c8d381e7af50dc6c4d861853d564618238a14cc567021448a444c84f740fc); +bytes32 constant BYTECODE_HASH = bytes32(0x96e4ec5ff213f69e32f76c5ce42fb5ae8a42af3ad080341ce1d1b74a0061723d); /// @dev The hash of the meta that describes the contract. bytes32 constant DESCRIBED_BY_META_HASH = bytes32(0x8717d07737e3cedcdddea6cd3337ae762d7089918bf8d818fb0afc5b63e3985a); @@ -43,18 +43,18 @@ uint8 constant PARSE_META_BUILD_DEPTH = 1; /// bytecode that dials back into this contract at eval time, and mapping /// to things that happen entirely on the interpreter such as well known /// constants and references to the context grid. -bytes constant SUB_PARSER_WORD_PARSERS = hex"08a008c008d2"; +bytes constant SUB_PARSER_WORD_PARSERS = hex"093509550967"; /// @dev Every two bytes is a function pointer for an operand handler. /// These positional indexes all map to the same indexes looked up in the parse /// meta. -bytes constant OPERAND_HANDLER_FUNCTION_POINTERS = hex"0dad0dad0dad"; +bytes constant OPERAND_HANDLER_FUNCTION_POINTERS = hex"0e430e430e43"; /// @dev The function pointers for the integrity check fns. -bytes constant INTEGRITY_FUNCTION_POINTERS = hex"0d8a0d960da2"; +bytes constant INTEGRITY_FUNCTION_POINTERS = hex"0e200e2c0e38"; /// @dev The function pointers known to the interpreter for dynamic dispatch. /// By setting these as a constant they can be inlined into the interpreter /// and loaded at eval time for very low gas (~100) due to the compiler /// optimising it to a single `codecopy` to build the in memory bytes array. -bytes constant OPCODE_FUNCTION_POINTERS = hex"09740a4f0aa4"; +bytes constant OPCODE_FUNCTION_POINTERS = hex"0a090ac70b1c"; diff --git a/src/lib/op/LibOpFtsoCurrentPricePair.sol b/src/lib/op/LibOpFtsoCurrentPricePair.sol index 5840e35..5d98aa3 100644 --- a/src/lib/op/LibOpFtsoCurrentPricePair.sol +++ b/src/lib/op/LibOpFtsoCurrentPricePair.sol @@ -2,9 +2,9 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity ^0.8.19; -import {OperandV2, StackItem} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol"; +import {OperandV2, StackItem} from "rain-interpreter-interface-0.1.0/src/interface/IInterpreterV4.sol"; import {LibOpFtsoCurrentPriceUsd} from "./LibOpFtsoCurrentPriceUsd.sol"; -import {LibDecimalFloat, Float} from "rain.math.float/lib/LibDecimalFloat.sol"; +import {LibDecimalFloat, Float} from "rain-math-float-0.1.1/src/lib/LibDecimalFloat.sol"; /// @title LibOpFtsoCurrentPricePair /// Implements the `ftsoCurrentPricePair` externed opcode. diff --git a/src/lib/op/LibOpFtsoCurrentPriceUsd.sol b/src/lib/op/LibOpFtsoCurrentPriceUsd.sol index dfa833f..ba6076d 100644 --- a/src/lib/op/LibOpFtsoCurrentPriceUsd.sol +++ b/src/lib/op/LibOpFtsoCurrentPriceUsd.sol @@ -2,12 +2,12 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity ^0.8.19; -import {OperandV2, StackItem} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol"; -import {LibIntOrAString, IntOrAString} from "rain.intorastring/lib/LibIntOrAString.sol"; +import {OperandV2, StackItem} from "rain-interpreter-interface-0.1.0/src/interface/IInterpreterV4.sol"; +import {LibIntOrAString, IntOrAString} from "rain-intorastring-0.1.0/src/lib/LibIntOrAString.sol"; import {LibFtsoCurrentPriceUsd} from "../price/LibFtsoCurrentPriceUsd.sol"; import {DecimalsTooLarge} from "../../err/ErrFtso.sol"; -import {LibDecimalFloat, Float} from "rain.math.float/lib/LibDecimalFloat.sol"; +import {LibDecimalFloat, Float} from "rain-math-float-0.1.1/src/lib/LibDecimalFloat.sol"; /// @title LibOpFtsoCurrentPriceUsd /// Implements the `ftsoCurrentPriceUsd` externed opcode. @@ -45,7 +45,7 @@ library LibOpFtsoCurrentPriceUsd { } (uint256 price, uint256 decimals) = LibFtsoCurrentPriceUsd.ftsoCurrentPriceUsd( - symbol.toString(), LibDecimalFloat.toFixedDecimalLossless(timeout, 0) + symbol.toStringV3(), LibDecimalFloat.toFixedDecimalLossless(timeout, 0) ); if (decimals > type(uint8).max) { revert DecimalsTooLarge(decimals); diff --git a/src/lib/op/LibOpSFlrCurrentExchangeRate.sol b/src/lib/op/LibOpSFlrCurrentExchangeRate.sol index 8db0423..2a85266 100644 --- a/src/lib/op/LibOpSFlrCurrentExchangeRate.sol +++ b/src/lib/op/LibOpSFlrCurrentExchangeRate.sol @@ -2,9 +2,9 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity ^0.8.19; -import {OperandV2, StackItem} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol"; +import {OperandV2, StackItem} from "rain-interpreter-interface-0.1.0/src/interface/IInterpreterV4.sol"; import {LibSceptreStakedFlare} from "../sflr/LibSceptreStakedFlare.sol"; -import {LibDecimalFloat, Float} from "rain.math.float/lib/LibDecimalFloat.sol"; +import {LibDecimalFloat, Float} from "rain-math-float-0.1.1/src/lib/LibDecimalFloat.sol"; /// @title LibOpSLFRCurrentExchangeRate /// Implements the `sflrCurrentExchangeRate` externed opcode. diff --git a/src/lib/parse/LibFlareFtsoSubParser.sol b/src/lib/parse/LibFlareFtsoSubParser.sol index e5006bc..290d6dc 100644 --- a/src/lib/parse/LibFlareFtsoSubParser.sol +++ b/src/lib/parse/LibFlareFtsoSubParser.sol @@ -2,7 +2,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity ^0.8.19; -import {AuthoringMetaV2} from "rain.interpreter.interface/interface/deprecated/IParserV1.sol"; +import {AuthoringMetaV2} from "rain-interpreter-interface-0.1.0/src/interface/deprecated/v1/IParserV1.sol"; /// @dev Index into the function pointers array for the current USD price. uint256 constant SUB_PARSER_WORD_FTSO_CURRENT_PRICE_USD = 0; diff --git a/src/lib/price/LibFtsoCurrentPriceUsd.sol b/src/lib/price/LibFtsoCurrentPriceUsd.sol index f2aa502..85d817a 100644 --- a/src/lib/price/LibFtsoCurrentPriceUsd.sol +++ b/src/lib/price/LibFtsoCurrentPriceUsd.sol @@ -31,12 +31,8 @@ library LibFtsoCurrentPriceUsd { // There are other fallback finalization modes, but weighted median and // trusted addresses are the only ones that don't imply the price was // simply copied from an earlier epoch. - if ( - !( - priceFinalizationType == IFtso.PriceFinalizationType.WEIGHTED_MEDIAN - || priceFinalizationType == IFtso.PriceFinalizationType.TRUSTED_ADDRESSES - ) - ) { + if (!(priceFinalizationType == IFtso.PriceFinalizationType.WEIGHTED_MEDIAN + || priceFinalizationType == IFtso.PriceFinalizationType.TRUSTED_ADDRESSES)) { revert PriceNotFinalized(priceFinalizationType); } diff --git a/src/vendor/flare-smart-contracts-v2/userInterfaces/IFeeCalculator.sol b/src/vendor/flare-smart-contracts-v2/userInterfaces/IFeeCalculator.sol new file mode 100644 index 0000000..6d143f1 --- /dev/null +++ b/src/vendor/flare-smart-contracts-v2/userInterfaces/IFeeCalculator.sol @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.7.6 <0.9; + +/** + * FeeCalculator interface. + */ +interface IFeeCalculator { + /** + * Calculates a fee that needs to be paid to fetch feeds' data. + * @param _feedIds List of feed ids. + */ + function calculateFeeByIds(bytes21[] memory _feedIds) external view returns (uint256 _fee); + + /** + * Calculates a fee that needs to be paid to fetch feeds' data. + * @param _indices Indices of the feeds, corresponding to feed ids in + * the FastUpdatesConfiguration contract. + */ + function calculateFeeByIndices(uint256[] memory _indices) external view returns (uint256 _fee); +} + diff --git a/src/vendor/flare-smart-contracts-v2/userInterfaces/LTS/FtsoV2Interface.sol b/src/vendor/flare-smart-contracts-v2/userInterfaces/LTS/FtsoV2Interface.sol new file mode 100644 index 0000000..d84afce --- /dev/null +++ b/src/vendor/flare-smart-contracts-v2/userInterfaces/LTS/FtsoV2Interface.sol @@ -0,0 +1,114 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.7.6 <0.9; + +/** + * FtsoV2 long term support interface. + */ +interface FtsoV2Interface { + /// Feed data structure + struct FeedData { + uint32 votingRoundId; + bytes21 id; + int32 value; + uint16 turnoutBIPS; + int8 decimals; + } + + /// Feed data with proof structure + struct FeedDataWithProof { + bytes32[] proof; + FeedData body; + } + + /// Feed id change structure + struct FeedIdChange { + bytes21 oldFeedId; + bytes21 newFeedId; + } + + /// Event emitted when a feed id is changed (e.g. feed renamed). + event FeedIdChanged(bytes21 indexed oldFeedId, bytes21 indexed newFeedId); + + /** + * Returns the FTSO protocol id. + */ + function getFtsoProtocolId() external view returns (uint256); + + /** + * Returns the list of supported feed ids (currently active feed ids). + * To get the list of all available feed ids, combine with `getFeedIdChanges()`. + * @return _feedIds The list of supported feed ids. + */ + function getSupportedFeedIds() external view returns (bytes21[] memory _feedIds); + + /** + * Returns the list of feed id changes. + * @return _feedIdChanges The list of changed feed id pairs (old and new feed id). + */ + function getFeedIdChanges() external view returns (FeedIdChange[] memory _feedIdChanges); + + /** + * Calculates the fee for fetching a feed. + * @param _feedId The id of the feed. + * @return _fee The fee for fetching the feed. + */ + function calculateFeeById(bytes21 _feedId) external view returns (uint256 _fee); + + /** + * Calculates the fee for fetching feeds. + * @param _feedIds The list of feed ids. + * @return _fee The fee for fetching the feeds. + */ + function calculateFeeByIds(bytes21[] memory _feedIds) external view returns (uint256 _fee); + + /** + * Returns stored data of a feed. + * A fee (calculated by the FeeCalculator contract) may need to be paid. + * @param _feedId The id of the feed. + * @return _value The value for the requested feed. + * @return _decimals The decimal places for the requested feed. + * @return _timestamp The timestamp of the last update. + */ + function getFeedById(bytes21 _feedId) external payable returns (uint256 _value, int8 _decimals, uint64 _timestamp); + + /** + * Returns stored data of each feed. + * A fee (calculated by the FeeCalculator contract) may need to be paid. + * @param _feedIds The list of feed ids. + * @return _values The list of values for the requested feeds. + * @return _decimals The list of decimal places for the requested feeds. + * @return _timestamp The timestamp of the last update. + */ + function getFeedsById(bytes21[] memory _feedIds) + external + payable + returns (uint256[] memory _values, int8[] memory _decimals, uint64 _timestamp); + + /** + * Returns value in wei and timestamp of a feed. + * A fee (calculated by the FeeCalculator contract) may need to be paid. + * @param _feedId The id of the feed. + * @return _value The value for the requested feed in wei (i.e. with 18 decimal places). + * @return _timestamp The timestamp of the last update. + */ + function getFeedByIdInWei(bytes21 _feedId) external payable returns (uint256 _value, uint64 _timestamp); + + /** + * Returns value of each feed and a timestamp. + * For some feeds, a fee (calculated by the FeeCalculator contract) may need to be paid. + * @param _feedIds Ids of the feeds. + * @return _values The list of values for the requested feeds in wei (i.e. with 18 decimal places). + * @return _timestamp The timestamp of the last update. + */ + function getFeedsByIdInWei(bytes21[] memory _feedIds) + external + payable + returns (uint256[] memory _values, uint64 _timestamp); + + /** + * Checks if the feed data is valid (i.e. is part of the confirmed Merkle tree). + * @param _feedData Structure containing data about the feed (FeedData structure) and Merkle proof. + * @return true if the feed data is valid. + */ + function verifyFeedData(FeedDataWithProof calldata _feedData) external view returns (bool); +} diff --git a/src/vendor/flare-smart-contracts/ftso/interface/IIFtso.sol b/src/vendor/flare-smart-contracts/ftso/interface/IIFtso.sol new file mode 100644 index 0000000..c275698 --- /dev/null +++ b/src/vendor/flare-smart-contracts/ftso/interface/IIFtso.sol @@ -0,0 +1,195 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.7.6 <0.9; + +import "../../genesis/interface/IFtsoGenesis.sol"; +import "../../userInterfaces/IFtso.sol"; +import "../../token/interface/IIVPToken.sol"; + +/** + * Internal interface for each of the FTSO contracts that handles an asset. + * Read the [FTSO documentation page](https://docs.flare.network/tech/ftso/) + * for general information about the FTSO system. + */ +interface IIFtso is IFtso, IFtsoGenesis { + /** + * Computes epoch price based on gathered votes. + * + * * If the price reveal window for the epoch has ended, finalize the epoch. + * * Iterate list of price submissions. + * * Find weighted median. + * * Find adjacent 50% of price submissions. + * * Allocate rewards for price submissions. + * @param _epochId ID of the epoch to finalize. + * @param _returnRewardData Parameter that determines if the reward data is returned. + * @return _eligibleAddresses List of addresses eligible for reward. + * @return _natWeights List of native token weights corresponding to the eligible addresses. + * @return _totalNatWeight Sum of weights in `_natWeights`. + */ + function finalizePriceEpoch(uint256 _epochId, bool _returnRewardData) + external + returns (address[] memory _eligibleAddresses, uint256[] memory _natWeights, uint256 _totalNatWeight); + + /** + * Forces finalization of a price epoch, calculating the median price from trusted addresses only. + * + * Used as a fallback method, for example, due to an unexpected error during normal epoch finalization or + * because the `ftsoManager` enabled the fallback mode. + * @param _epochId ID of the epoch to finalize. + */ + function fallbackFinalizePriceEpoch(uint256 _epochId) external; + + /** + * Forces finalization of a price epoch by copying the price from the previous epoch. + * + * Used as a fallback method if `fallbackFinalizePriceEpoch` fails due to an exception. + * @param _epochId ID of the epoch to finalize. + */ + function forceFinalizePriceEpoch(uint256 _epochId) external; + + /** + * Initializes FTSO immutable settings and activates the contract. + * @param _firstEpochStartTs Timestamp of the first epoch in seconds from UNIX epoch. + * @param _submitPeriodSeconds Duration of epoch submission window in seconds. + * @param _revealPeriodSeconds Duration of epoch reveal window in seconds. + */ + function activateFtso(uint256 _firstEpochStartTs, uint256 _submitPeriodSeconds, uint256 _revealPeriodSeconds) + external; + + /** + * Deactivates the contract. + */ + function deactivateFtso() external; + + /** + * Updates initial asset price when the contract is not active yet. + */ + function updateInitialPrice(uint256 _initialPriceUSD, uint256 _initialPriceTimestamp) external; + + /** + * Sets configurable settings related to epochs. + * @param _maxVotePowerNatThresholdFraction High threshold for native token vote power per voter. + * @param _maxVotePowerAssetThresholdFraction High threshold for asset vote power per voter. + * @param _lowAssetUSDThreshold Threshold for low asset vote power (in scaled USD). + * @param _highAssetUSDThreshold Threshold for high asset vote power (in scaled USD). + * @param _highAssetTurnoutThresholdBIPS Threshold for high asset turnout (in BIPS). + * @param _lowNatTurnoutThresholdBIPS Threshold for low nat turnout (in BIPS). + * @param _elasticBandRewardBIPS Percentage of the rewards (in BIPS) that go to the [secondary + * reward band](https://docs.flare.network/tech/ftso/#rewards). The rest go to the primary reward band. + * @param _elasticBandWidthPPM Width of the secondary reward band, in parts-per-milion of the median. + * @param _trustedAddresses Trusted voters that will be used if low voter turnout is detected. + */ + function configureEpochs( + uint256 _maxVotePowerNatThresholdFraction, + uint256 _maxVotePowerAssetThresholdFraction, + uint256 _lowAssetUSDThreshold, + uint256 _highAssetUSDThreshold, + uint256 _highAssetTurnoutThresholdBIPS, + uint256 _lowNatTurnoutThresholdBIPS, + uint256 _elasticBandRewardBIPS, + uint256 _elasticBandWidthPPM, + address[] memory _trustedAddresses + ) external; + + /** + * Sets asset for FTSO to operate as single-asset oracle. + * @param _asset Address of the `IIVPToken` contract that will be the asset tracked by this FTSO. + */ + function setAsset(IIVPToken _asset) external; + + /** + * Sets an array of FTSOs for FTSO to operate as multi-asset oracle. + * FTSOs implicitly determine the FTSO assets. + * @param _assetFtsos Array of FTSOs. + */ + function setAssetFtsos(IIFtso[] memory _assetFtsos) external; + + /** + * Sets the current vote power block. + * Current vote power block will update per reward epoch. + * The FTSO doesn't have notion of reward epochs. + * @param _blockNumber Vote power block. + */ + function setVotePowerBlock(uint256 _blockNumber) external; + + /** + * Initializes current epoch instance for reveal. + * @param _circulatingSupplyNat Epoch native token circulating supply. + * @param _fallbackMode Whether the current epoch is in fallback mode. + */ + function initializeCurrentEpochStateForReveal(uint256 _circulatingSupplyNat, bool _fallbackMode) external; + + /** + * Returns the FTSO manager's address. + * @return Address of the FTSO manager contract. + */ + function ftsoManager() external view returns (address); + + /** + * Returns the FTSO asset. + * @return Address of the `IIVPToken` tracked by this FTSO. + * `null` in case of multi-asset FTSO. + */ + function getAsset() external view returns (IIVPToken); + + /** + * Returns the asset FTSOs. + * @return Array of `IIFtso` contract addresses. + * `null` in case of single-asset FTSO. + */ + function getAssetFtsos() external view returns (IIFtso[] memory); + + /** + * Returns current configuration of epoch state. + * @return _maxVotePowerNatThresholdFraction High threshold for native token vote power per voter. + * @return _maxVotePowerAssetThresholdFraction High threshold for asset vote power per voter. + * @return _lowAssetUSDThreshold Threshold for low asset vote power (in scaled USD). + * @return _highAssetUSDThreshold Threshold for high asset vote power (in scaled USD). + * @return _highAssetTurnoutThresholdBIPS Threshold for high asset turnout (in BIPS). + * @return _lowNatTurnoutThresholdBIPS Threshold for low nat turnout (in BIPS). + * @return _elasticBandRewardBIPS Percentage of the rewards (in BIPS) that go to the [secondary + * reward band](https://docs.flare.network/tech/ftso/#rewards). The rest go to the primary reward band. + * @return _elasticBandWidthPPM Width of the secondary reward band, in parts-per-milion of the median. + * @return _trustedAddresses Trusted voters that will be used if low voter turnout is detected. + */ + function epochsConfiguration() + external + view + returns ( + uint256 _maxVotePowerNatThresholdFraction, + uint256 _maxVotePowerAssetThresholdFraction, + uint256 _lowAssetUSDThreshold, + uint256 _highAssetUSDThreshold, + uint256 _highAssetTurnoutThresholdBIPS, + uint256 _lowNatTurnoutThresholdBIPS, + uint256 _elasticBandRewardBIPS, + uint256 _elasticBandWidthPPM, + address[] memory _trustedAddresses + ); + + /** + * Returns parameters necessary for replicating vote weighting (used in VoterWhitelister). + * @return _assets The list of assets that are accounted in vote. + * @return _assetMultipliers Weight multiplier of each asset in (multiasset) FTSO. + * @return _totalVotePowerNat Total native token vote power at block. + * @return _totalVotePowerAsset Total combined asset vote power at block. + * @return _assetWeightRatio Ratio of combined asset vote power vs. native token vp (in BIPS). + * @return _votePowerBlock Vote power block for the epoch. + */ + function getVoteWeightingParameters() + external + view + returns ( + IIVPToken[] memory _assets, + uint256[] memory _assetMultipliers, + uint256 _totalVotePowerNat, + uint256 _totalVotePowerAsset, + uint256 _assetWeightRatio, + uint256 _votePowerBlock + ); + + /** + * Address of the WNat contract. + * @return Address of the WNat contract. + */ + function wNat() external view returns (IIVPToken); +} diff --git a/src/vendor/flare-smart-contracts/genesis/interface/IFtsoGenesis.sol b/src/vendor/flare-smart-contracts/genesis/interface/IFtsoGenesis.sol new file mode 100644 index 0000000..e696abf --- /dev/null +++ b/src/vendor/flare-smart-contracts/genesis/interface/IFtsoGenesis.sol @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.7.6 <0.9; + +/** + * Portion of the IFtso interface that is available to contracts deployed at genesis. + */ +interface IFtsoGenesis { + /** + * Reveals the price submitted by a voter on a specific epoch. + * The hash of _price and _random must be equal to the submitted hash + * @param _voter Voter address. + * @param _epochId ID of the epoch in which the price hash was submitted. + * @param _price Submitted price. + * @param _voterWNatVP Voter's vote power in WNat units. + */ + function revealPriceSubmitter(address _voter, uint256 _epochId, uint256 _price, uint256 _voterWNatVP) external; + + /** + * Get and cache the vote power of a voter on a specific epoch, in WNat units. + * @param _voter Voter address. + * @param _epochId ID of the epoch in which the price hash was submitted. + * @return Voter's vote power in WNat units. + */ + function wNatVotePowerCached(address _voter, uint256 _epochId) external returns (uint256); +} diff --git a/src/vendor/flare-smart-contracts/genesis/interface/IFtsoRegistryGenesis.sol b/src/vendor/flare-smart-contracts/genesis/interface/IFtsoRegistryGenesis.sol new file mode 100644 index 0000000..fa36dc2 --- /dev/null +++ b/src/vendor/flare-smart-contracts/genesis/interface/IFtsoRegistryGenesis.sol @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.7.6 <0.9; + +import "./IFtsoGenesis.sol"; + +/** + * Portion of the `IFtsoRegistry` interface that is available to contracts deployed at genesis. + */ +interface IFtsoRegistryGenesis { + /** + * Get the addresses of the active FTSOs at the given indices. + * Reverts if any of the provided indices is non-existing or inactive. + * @param _indices Array of FTSO indices to query. + * @return _ftsos The array of FTSO addresses. + */ + function getFtsos(uint256[] memory _indices) external view returns (IFtsoGenesis[] memory _ftsos); +} diff --git a/src/vendor/flare-smart-contracts/token/interface/IICleanable.sol b/src/vendor/flare-smart-contracts/token/interface/IICleanable.sol new file mode 100644 index 0000000..bfd9811 --- /dev/null +++ b/src/vendor/flare-smart-contracts/token/interface/IICleanable.sol @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.7.6 <0.9; + +/** + * Internal interface for entities that can have their block history cleaned. + */ +interface IICleanable { + /** + * Set the contract that is allowed to call history cleaning methods. + * @param _cleanerContract Address of the cleanup contract. + * Usually this will be an instance of `CleanupBlockNumberManager`. + */ + function setCleanerContract(address _cleanerContract) external; + + /** + * Set the cleanup block number. + * Historic data for the blocks before `cleanupBlockNumber` can be erased. + * History before that block should never be used since it can be inconsistent. + * In particular, cleanup block number must be lower than the current vote power block. + * @param _blockNumber The new cleanup block number. + */ + function setCleanupBlockNumber(uint256 _blockNumber) external; + + /** + * Get the current cleanup block number set with `setCleanupBlockNumber()`. + * @return The currently set cleanup block number. + */ + function cleanupBlockNumber() external view returns (uint256); +} diff --git a/src/vendor/flare-smart-contracts/token/interface/IIGovernanceVotePower.sol b/src/vendor/flare-smart-contracts/token/interface/IIGovernanceVotePower.sol new file mode 100644 index 0000000..2a4445a --- /dev/null +++ b/src/vendor/flare-smart-contracts/token/interface/IIGovernanceVotePower.sol @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.7.6 <0.9; + +import "../../userInterfaces/IVPToken.sol"; +import "../../userInterfaces/IPChainStakeMirror.sol"; +import "../../userInterfaces/IGovernanceVotePower.sol"; + +/** + * Internal interface for contracts delegating their governance vote power. + */ +interface IIGovernanceVotePower is IGovernanceVotePower { + /** + * Emitted when a delegate's vote power changes, as a result of a new delegation + * or a token transfer, for example. + * + * The event is always emitted from a `GovernanceVotePower` contract. + * @param delegate The account receiving the changing delegated vote power. + * @param previousBalance Delegated vote power before the change. + * @param newBalance Delegated vote power after the change. + */ + event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance); + + /** + * Emitted when an account starts delegating vote power or switches its delegation + * to another address. + * + * The event is always emitted from a `GovernanceVotePower` contract. + * @param delegator Account delegating its vote power. + * @param fromDelegate Account receiving the delegation before the change. + * Can be address(0) if there was no previous delegation. + * @param toDelegate Account receiving the delegation after the change. + * Can be address(0) if `delegator` just undelegated all its vote power. + */ + event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate); + + /** + * Update governance vote power of all involved delegates after tokens are transferred. + * + * This function **MUST** be called after each governance token transfer for the + * delegates to reflect the correct balance. + * @param _from Source address of the transfer. + * @param _to Destination address of the transfer. + * @param _fromBalance _Ignored._ + * @param _toBalance _Ignored._ + * @param _amount Amount being transferred. + */ + function updateAtTokenTransfer( + address _from, + address _to, + uint256 _fromBalance, + uint256 _toBalance, + uint256 _amount + ) external; + + /** + * Set the cleanup block number. + * Historic data for the blocks before `cleanupBlockNumber` can be erased. + * History before that block should never be used since it can be inconsistent. + * In particular, cleanup block number must be lower than the current vote power block. + * @param _blockNumber The new cleanup block number. + */ + function setCleanupBlockNumber(uint256 _blockNumber) external; + + /** + * Set the contract that is allowed to call history cleaning methods. + * @param _cleanerContract Address of the cleanup contract. + * Usually this will be an instance of `CleanupBlockNumberManager`. + */ + function setCleanerContract(address _cleanerContract) external; + + /** + * Get the token that this governance vote power contract belongs to. + * @return The IVPToken interface owning this contract. + */ + function ownerToken() external view returns (IVPToken); + + /** + * Get the stake mirror contract that this governance vote power contract belongs to. + * @return The IPChainStakeMirror interface owning this contract. + */ + function pChainStakeMirror() external view returns (IPChainStakeMirror); + + /** + * Get the current cleanup block number set with `setCleanupBlockNumber()`. + * @return The currently set cleanup block number. + */ + function getCleanupBlockNumber() external view returns (uint256); +} diff --git a/src/vendor/flare-smart-contracts/token/interface/IIVPContract.sol b/src/vendor/flare-smart-contracts/token/interface/IIVPContract.sol new file mode 100644 index 0000000..c629851 --- /dev/null +++ b/src/vendor/flare-smart-contracts/token/interface/IIVPContract.sol @@ -0,0 +1,222 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.7.6 <0.9; + +import "../../userInterfaces/IVPToken.sol"; +import "../../userInterfaces/IVPContractEvents.sol"; +import "./IICleanable.sol"; + +/** + * Internal interface for helper contracts handling functionality for an associated VPToken. + */ +interface IIVPContract is IICleanable, IVPContractEvents { + /** + * Update vote powers when tokens are transferred. + * Also update delegated vote powers for percentage delegation + * and check for enough funds for explicit delegations. + * @param _from Source account of the transfer. + * @param _to Destination account of the transfer. + * @param _fromBalance Balance of the source account before the transfer. + * @param _toBalance Balance of the destination account before the transfer. + * @param _amount Amount that has been transferred. + */ + function updateAtTokenTransfer( + address _from, + address _to, + uint256 _fromBalance, + uint256 _toBalance, + uint256 _amount + ) external; + + /** + * Delegate `_bips` percentage of voting power from a delegator address to a delegatee address. + * @param _from The address of the delegator. + * @param _to The address of the delegatee. + * @param _balance The delegator's current balance + * @param _bips The percentage of voting power to be delegated expressed in basis points (1/100 of one percent). + * Not cumulative: every call resets the delegation value (and a value of 0 revokes delegation). + */ + function delegate(address _from, address _to, uint256 _balance, uint256 _bips) external; + + /** + * Explicitly delegate `_amount` tokens of voting power from a delegator address to a delegatee address. + * @param _from The address of the delegator. + * @param _to The address of the delegatee. + * @param _balance The delegator's current balance. + * @param _amount An explicit vote power amount to be delegated. + * Not cumulative: every call resets the delegation value (and a value of 0 undelegates `_to`). + */ + function delegateExplicit(address _from, address _to, uint256 _balance, uint256 _amount) external; + + /** + * Revoke all vote power delegation from a delegator address to a delegatee address at a given block. + * Only affects the reads via `votePowerOfAtCached()` in the block `_blockNumber`. + * This method should be used only to prevent rogue delegate voting in the current voting block. + * To stop delegating use `delegate` or `delegateExplicit` with value of 0, + * or `undelegateAll`/ `undelegateAllExplicit`. + * @param _from The address of the delegator. + * @param _to Address of the delegatee. + * @param _balance The delegator's current balance. + * @param _blockNumber The block number at which to revoke delegation. Must be in the past. + */ + function revokeDelegationAt(address _from, address _to, uint256 _balance, uint256 _blockNumber) external; + + /** + * Undelegate all voting power for a delegator address. + * Can only be used with percentage delegation. + * Does not reset delegation mode back to `NOTSET`. + * @param _from The address of the delegator. + * @param _balance The delegator's current balance. + */ + function undelegateAll(address _from, uint256 _balance) external; + + /** + * Undelegate all explicit vote power by amount for a delegator address. + * Can only be used with explicit delegation. + * Does not reset delegation mode back to `NOTSET`. + * @param _from The address of the delegator. + * @param _delegateAddresses Explicit delegation does not store delegatees' addresses, + * so the caller must supply them. + * @return The amount still delegated (in case the list of delegates was incomplete). + */ + function undelegateAllExplicit(address _from, address[] memory _delegateAddresses) external returns (uint256); + + /** + * Get the vote power of an address at a given block number. + * Reads/updates cache and upholds revocations. + * @param _who The address being queried. + * @param _blockNumber The block number being queried. + * @return Vote power of `_who` at `_blockNumber`, including any delegation received. + */ + function votePowerOfAtCached(address _who, uint256 _blockNumber) external returns (uint256); + + /** + * Get the current vote power of an address. + * @param _who The address being queried. + * @return Current vote power of `_who`, including any delegation received. + */ + function votePowerOf(address _who) external view returns (uint256); + + /** + * Get the vote power of an address at a given block number + * @param _who The address being queried. + * @param _blockNumber The block number being queried. + * @return Vote power of `_who` at `_blockNumber`, including any delegation received. + */ + function votePowerOfAt(address _who, uint256 _blockNumber) external view returns (uint256); + + /** + * Get the vote power of an address at a given block number, ignoring revocation information and cache. + * @param _who The address being queried. + * @param _blockNumber The block number being queried. + * @return Vote power of `_who` at `_blockNumber`, including any delegation received. + * Result doesn't change if vote power is revoked. + */ + function votePowerOfAtIgnoringRevocation(address _who, uint256 _blockNumber) external view returns (uint256); + + /** + * Get the vote power of a set of addresses at a given block number. + * @param _owners The list of addresses being queried. + * @param _blockNumber The block number being queried. + * @return Vote power of each address at `_blockNumber`, including any delegation received. + */ + function batchVotePowerOfAt(address[] memory _owners, uint256 _blockNumber) external view returns (uint256[] memory); + + /** + * Get current delegated vote power from a delegator to a delegatee. + * @param _from Address of the delegator. + * @param _to Address of the delegatee. + * @param _balance The delegator's current balance. + * @return The delegated vote power. + */ + function votePowerFromTo(address _from, address _to, uint256 _balance) external view returns (uint256); + + /** + * Get delegated the vote power from a delegator to a delegatee at a given block number. + * @param _from Address of the delegator. + * @param _to Address of the delegatee. + * @param _balance The delegator's current balance. + * @param _blockNumber The block number being queried. + * @return The delegated vote power. + */ + function votePowerFromToAt(address _from, address _to, uint256 _balance, uint256 _blockNumber) + external + view + returns (uint256); + + /** + * Compute the current undelegated vote power of an address. + * @param _owner The address being queried. + * @param _balance Current balance of that address. + * @return The unallocated vote power of `_owner`, this is, the amount of vote power + * currently not being delegated to other addresses. + */ + function undelegatedVotePowerOf(address _owner, uint256 _balance) external view returns (uint256); + + /** + * Compute the undelegated vote power of an address at a given block. + * @param _owner The address being queried. + * @param _blockNumber The block number being queried. + * @return The unallocated vote power of `_owner`, this is, the amount of vote power + * that was not being delegated to other addresses at that block number. + */ + function undelegatedVotePowerOfAt(address _owner, uint256 _balance, uint256 _blockNumber) + external + view + returns (uint256); + + /** + * Get the delegation mode of an address. This mode determines whether vote power is + * allocated by percentage or by explicit value and cannot be changed once set with + * `delegate` or `delegateExplicit`. + * @param _who The address being queried. + * @return Delegation mode (NOTSET=0, PERCENTAGE=1, AMOUNT=2). See Delegatable.DelegationMode. + */ + function delegationModeOf(address _who) external view returns (uint256); + + /** + * Get the percentages and addresses being delegated to by a vote power delegator. + * @param _owner The address of the delegator being queried. + * @return _delegateAddresses Array of delegatee addresses. + * @return _bips Array of delegation percents specified in basis points (1/100 or 1 percent), for each delegatee. + * @return _count The number of returned delegatees. + * @return _delegationMode The mode of the delegation (NOTSET=0, PERCENTAGE=1, AMOUNT=2). + * See Delegatable.DelegationMode. + */ + function delegatesOf(address _owner) + external + view + returns (address[] memory _delegateAddresses, uint256[] memory _bips, uint256 _count, uint256 _delegationMode); + + /** + * Get the percentages and addresses being delegated to by a vote power delegator, + * at a given block. + * @param _owner The address of the delegator being queried. + * @param _blockNumber The block number being queried. + * @return _delegateAddresses Array of delegatee addresses. + * @return _bips Array of delegation percents specified in basis points (1/100 or 1 percent), for each delegatee. + * @return _count The number of returned delegatees. + * @return _delegationMode The mode of the delegation (NOTSET=0, PERCENTAGE=1, AMOUNT=2). + * See Delegatable.DelegationMode. + */ + function delegatesOfAt(address _owner, uint256 _blockNumber) + external + view + returns (address[] memory _delegateAddresses, uint256[] memory _bips, uint256 _count, uint256 _delegationMode); + + /** + * The VPToken (or some other contract) that owns this VPContract. + * All state changing methods may be called only from this address. + * This is because original `msg.sender` is typically sent in a parameter + * and we must make sure that it cannot be faked by directly calling + * IIVPContract methods. + * Owner token is also used in case of replacement to recover vote powers from balances. + */ + function ownerToken() external view returns (IVPToken); + + /** + * Return true if this IIVPContract is configured to be used as a replacement for other contract. + * It means that vote powers are not necessarily correct at the initialization, therefore + * every method that reads vote power must check whether it is initialized for that address and block. + */ + function isReplacement() external view returns (bool); +} diff --git a/src/vendor/flare-smart-contracts/token/interface/IIVPToken.sol b/src/vendor/flare-smart-contracts/token/interface/IIVPToken.sol new file mode 100644 index 0000000..3c06d46 --- /dev/null +++ b/src/vendor/flare-smart-contracts/token/interface/IIVPToken.sol @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.7.6 <0.9; + +import "../../userInterfaces/IVPToken.sol"; +import "../../userInterfaces/IGovernanceVotePower.sol"; +import "./IIVPContract.sol"; +import "./IIGovernanceVotePower.sol"; +import "./IICleanable.sol"; + +/** + * Vote power token internal interface. + */ +interface IIVPToken is IVPToken, IICleanable { + /** + * Set the contract that is allowed to set cleanupBlockNumber. + * Usually this will be an instance of CleanupBlockNumberManager. + */ + function setCleanupBlockNumberManager(address _cleanupBlockNumberManager) external; + + /** + * Sets new governance vote power contract that allows token owners to participate in governance voting + * and delegate governance vote power. + */ + function setGovernanceVotePower(IIGovernanceVotePower _governanceVotePower) external; + + /** + * Get the total vote power at block `_blockNumber` using cache. + * It tries to read the cached value and if it is not found, reads the actual value and stores it in the cache. + * Can only be used if `_blockNumber` is in the past, otherwise reverts. + * @param _blockNumber The block number to query. + * @return The total vote power at the queried block (sum of all accounts' vote powers). + */ + function totalVotePowerAtCached(uint256 _blockNumber) external returns (uint256); + + /** + * Get the vote power of `_owner` at block `_blockNumber` using cache. + * It tries to read the cached value and if it is not found, reads the actual value and stores it in the cache. + * Can only be used if `_blockNumber` is in the past, otherwise reverts. + * @param _owner The address to query. + * @param _blockNumber The block number to query. + * @return Vote power of `_owner` at `_blockNumber`. + */ + function votePowerOfAtCached(address _owner, uint256 _blockNumber) external returns (uint256); + + /** + * Return the vote power for several addresses. + * @param _owners The list of addresses to query. + * @param _blockNumber The block number to query. + * @return Array of vote power for each queried address. + */ + function batchVotePowerOfAt(address[] memory _owners, uint256 _blockNumber) external view returns (uint256[] memory); +} diff --git a/src/vendor/flare-smart-contracts/userInterfaces/IFlareContractRegistry.sol b/src/vendor/flare-smart-contracts/userInterfaces/IFlareContractRegistry.sol new file mode 100644 index 0000000..c47cd3a --- /dev/null +++ b/src/vendor/flare-smart-contracts/userInterfaces/IFlareContractRegistry.sol @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.7.6 <0.9; +pragma abicoder v2; + +/** + * Interface for the `FlareContractRegistry`. + * + * Entry point for all external dapps that need the latest contract addresses deployed by Flare. + */ +interface IFlareContractRegistry { + /** + * Returns the address of a given contract name. + * @param _name Name of the contract. + * @return Address of the contract, or `address(0)` if not found. + */ + function getContractAddressByName(string calldata _name) external view returns (address); + + /** + * Returns the address of a given contract hash. + * @param _nameHash Hash of the contract name as: `keccak256(abi.encode(name))`. + * @return Address of the contract, or `address(0)` if not found. + */ + function getContractAddressByHash(bytes32 _nameHash) external view returns (address); + + /** + * Returns the addresses of a list of contract names. + * @param _names Array of contract names. + * @return Array of addresses of the contracts. + * Any of them might be `address(0)` if not found. + */ + function getContractAddressesByName(string[] calldata _names) external view returns (address[] memory); + + /** + * Returns the addresses of a list of contract hashes. + * @param _nameHashes Array of contract name hashes as: `keccak256(abi.encode(name))`. + * @return Array of addresses of the contracts. + * Any of them might be `address(0)` if not found. + */ + function getContractAddressesByHash(bytes32[] calldata _nameHashes) external view returns (address[] memory); + + /** + * Returns all contract names and their corresponding addresses. + * @return _names Array of contract names. + * @return _addresses Array of corresponding contract addresses. + */ + function getAllContracts() external view returns (string[] memory _names, address[] memory _addresses); +} diff --git a/src/vendor/flare-smart-contracts/userInterfaces/IFtso.sol b/src/vendor/flare-smart-contracts/userInterfaces/IFtso.sol new file mode 100644 index 0000000..eff5576 --- /dev/null +++ b/src/vendor/flare-smart-contracts/userInterfaces/IFtso.sol @@ -0,0 +1,251 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.7.6 <0.9; + +/** + * Interface for each of the FTSO contracts that handles an asset. + * Read the [FTSO documentation page](https://docs.flare.network/tech/ftso/) + * for general information about the FTSO system. + */ +interface IFtso { + /** + * How did a price epoch finalize. + * + * * `NOT_FINALIZED`: The epoch has not been finalized yet. This is the initial state. + * * `WEIGHTED_MEDIAN`: The median was used to calculate the final price. + * This is the most common state in normal operation. + * * `TRUSTED_ADDRESSES`: Due to low turnout, the final price was calculated using only + * the median of trusted addresses. + * * `PREVIOUS_PRICE_COPIED`: Due to low turnout and absence of votes from trusted addresses, + * the final price was copied from the previous epoch. + * * `TRUSTED_ADDRESSES_EXCEPTION`: Due to an exception, the final price was calculated + * using only the median of trusted addresses. + * * `PREVIOUS_PRICE_COPIED_EXCEPTION`: Due to an exception, the final price was copied + * from the previous epoch. + */ + enum PriceFinalizationType { + NOT_FINALIZED, + WEIGHTED_MEDIAN, + TRUSTED_ADDRESSES, + PREVIOUS_PRICE_COPIED, + TRUSTED_ADDRESSES_EXCEPTION, + PREVIOUS_PRICE_COPIED_EXCEPTION + } + + /** + * A voter has revealed its price. + * @param voter The voter. + * @param epochId The ID of the epoch for which the price has been revealed. + * @param price The revealed price. + * @param timestamp Timestamp of the block where the reveal happened. + * @param votePowerNat Vote power of the voter in this epoch. This includes the + * vote power derived from its WNat holdings and the delegations. + * @param votePowerAsset _Unused_. + */ + event PriceRevealed( + address indexed voter, + uint256 indexed epochId, + uint256 price, + uint256 timestamp, + uint256 votePowerNat, + uint256 votePowerAsset + ); + + /** + * An epoch has ended and the asset price is available. + * @param epochId The ID of the epoch that has just ended. + * @param price The asset's price for that epoch. + * @param rewardedFtso Whether the next 4 parameters contain data. + * @param lowIQRRewardPrice Lowest price in the primary (inter-quartile) reward band. + * @param highIQRRewardPrice Highest price in the primary (inter-quartile) reward band. + * @param lowElasticBandRewardPrice Lowest price in the secondary (elastic) reward band. + * @param highElasticBandRewardPrice Highest price in the secondary (elastic) reward band. + * @param finalizationType Reason for the finalization of the epoch. + * @param timestamp Timestamp of the block where the price has been finalized. + */ + event PriceFinalized( + uint256 indexed epochId, + uint256 price, + bool rewardedFtso, + uint256 lowIQRRewardPrice, + uint256 highIQRRewardPrice, + uint256 lowElasticBandRewardPrice, + uint256 highElasticBandRewardPrice, + PriceFinalizationType finalizationType, + uint256 timestamp + ); + + /** + * All necessary parameters have been set for an epoch and prices can start being _revealed_. + * Note that prices can already be _submitted_ immediately after the previous price epoch submit end time is over. + * + * This event is not emitted in fallback mode (see `getPriceEpochData`). + * @param epochId The ID of the epoch that has just started. + * @param endTime Deadline to submit prices, in seconds since UNIX epoch. + * @param timestamp Current on-chain timestamp. + */ + event PriceEpochInitializedOnFtso(uint256 indexed epochId, uint256 endTime, uint256 timestamp); + + /** + * Not enough votes were received for this asset during a price epoch that has just ended. + * @param epochId The ID of the epoch. + * @param natTurnout Total received vote power, as a percentage of the circulating supply in BIPS. + * @param lowNatTurnoutThresholdBIPS Minimum required vote power, as a percentage + * of the circulating supply in BIPS. + * The fact that this number is higher than `natTurnout` is what triggered this event. + * @param timestamp Timestamp of the block where the price epoch ended. + */ + event LowTurnout( + uint256 indexed epochId, uint256 natTurnout, uint256 lowNatTurnoutThresholdBIPS, uint256 timestamp + ); + + /** + * Returns whether FTSO is active or not. + */ + function active() external view returns (bool); + + /** + * Returns the FTSO symbol. + */ + function symbol() external view returns (string memory); + + /** + * Returns the current epoch ID. + * @return Currently running epoch ID. IDs are consecutive numbers starting from zero. + */ + function getCurrentEpochId() external view returns (uint256); + + /** + * Returns the ID of the epoch that was opened for price submission at the specified timestamp. + * @param _timestamp Queried timestamp in seconds from UNIX epoch. + * @return Epoch ID corresponding to that timestamp. IDs are consecutive numbers starting from zero. + */ + function getEpochId(uint256 _timestamp) external view returns (uint256); + + /** + * Returns the random number used in a specific past epoch, obtained from the random numbers + * provided by all data providers along with their data submissions. + * @param _epochId ID of the queried epoch. + * Current epoch cannot be queried, and the previous epoch is constantly updated + * as data providers reveal their prices and random numbers. + * Only the last 50 epochs can be queried and there is no bounds checking + * for this parameter. Out-of-bounds queries return undefined values. + * + * @return The random number used in that epoch. + */ + function getRandom(uint256 _epochId) external view returns (uint256); + + /** + * Returns agreed asset price in the specified epoch. + * @param _epochId ID of the epoch. + * Only the last 200 epochs can be queried. Out-of-bounds queries revert. + * @return Price in USD multiplied by 10^`ASSET_PRICE_USD_DECIMALS`. + */ + function getEpochPrice(uint256 _epochId) external view returns (uint256); + + /** + * Returns current epoch data. + * Intervals are open on the right: End times are not included. + * @return _epochId Current epoch ID. + * @return _epochSubmitEndTime End time of the price submission window in seconds from UNIX epoch. + * @return _epochRevealEndTime End time of the price reveal window in seconds from UNIX epoch. + * @return _votePowerBlock Vote power block for the current epoch. + * @return _fallbackMode Whether the current epoch is in fallback mode. + * Only votes from trusted addresses are used in this mode. + */ + function getPriceEpochData() + external + view + returns ( + uint256 _epochId, + uint256 _epochSubmitEndTime, + uint256 _epochRevealEndTime, + uint256 _votePowerBlock, + bool _fallbackMode + ); + + /** + * Returns current epoch's configuration. + * @return _firstEpochStartTs First epoch start timestamp in seconds from UNIX epoch. + * @return _submitPeriodSeconds Submit period in seconds. + * @return _revealPeriodSeconds Reveal period in seconds. + */ + function getPriceEpochConfiguration() + external + view + returns (uint256 _firstEpochStartTs, uint256 _submitPeriodSeconds, uint256 _revealPeriodSeconds); + + /** + * Returns asset price submitted by a voter in the specified epoch. + * @param _epochId ID of the epoch being queried. + * Only the last 200 epochs can be queried. Out-of-bounds queries revert. + * @param _voter Address of the voter being queried. + * @return Price in USD multiplied by 10^`ASSET_PRICE_USD_DECIMALS`. + */ + function getEpochPriceForVoter(uint256 _epochId, address _voter) external view returns (uint256); + + /** + * Returns the current asset price. + * @return _price Price in USD multiplied by 10^`ASSET_PRICE_USD_DECIMALS`. + * @return _timestamp Time when price was updated for the last time, + * in seconds from UNIX epoch. + */ + function getCurrentPrice() external view returns (uint256 _price, uint256 _timestamp); + + /** + * Returns current asset price and number of decimals. + * @return _price Price in USD multiplied by 10^`_assetPriceUsdDecimals`. + * @return _timestamp Time when price was updated for the last time, + * in seconds from UNIX epoch. + * @return _assetPriceUsdDecimals Number of decimals used to return the USD price. + */ + function getCurrentPriceWithDecimals() + external + view + returns (uint256 _price, uint256 _timestamp, uint256 _assetPriceUsdDecimals); + + /** + * Returns current asset price calculated only using input from trusted providers. + * @return _price Price in USD multiplied by 10^`ASSET_PRICE_USD_DECIMALS`. + * @return _timestamp Time when price was updated for the last time, + * in seconds from UNIX epoch. + */ + function getCurrentPriceFromTrustedProviders() external view returns (uint256 _price, uint256 _timestamp); + + /** + * Returns current asset price calculated only using input from trusted providers and number of decimals. + * @return _price Price in USD multiplied by 10^`ASSET_PRICE_USD_DECIMALS`. + * @return _timestamp Time when price was updated for the last time, + * in seconds from UNIX epoch. + * @return _assetPriceUsdDecimals Number of decimals used to return the USD price. + */ + function getCurrentPriceWithDecimalsFromTrustedProviders() + external + view + returns (uint256 _price, uint256 _timestamp, uint256 _assetPriceUsdDecimals); + + /** + * Returns asset's current price details. + * All timestamps are in seconds from UNIX epoch. + * @return _price Price in USD multiplied by 10^`ASSET_PRICE_USD_DECIMALS`. + * @return _priceTimestamp Time when price was updated for the last time. + * @return _priceFinalizationType Finalization type when price was updated for the last time. + * @return _lastPriceEpochFinalizationTimestamp Time when last price epoch was finalized. + * @return _lastPriceEpochFinalizationType Finalization type of last finalized price epoch. + */ + function getCurrentPriceDetails() + external + view + returns ( + uint256 _price, + uint256 _priceTimestamp, + PriceFinalizationType _priceFinalizationType, + uint256 _lastPriceEpochFinalizationTimestamp, + PriceFinalizationType _lastPriceEpochFinalizationType + ); + + /** + * Returns the random number for the previous price epoch, obtained from the random numbers + * provided by all data providers along with their data submissions. + */ + function getCurrentRandom() external view returns (uint256); +} diff --git a/src/vendor/flare-smart-contracts/userInterfaces/IFtsoRegistry.sol b/src/vendor/flare-smart-contracts/userInterfaces/IFtsoRegistry.sol new file mode 100644 index 0000000..756153d --- /dev/null +++ b/src/vendor/flare-smart-contracts/userInterfaces/IFtsoRegistry.sol @@ -0,0 +1,193 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.7.6 <0.9; +pragma abicoder v2; + +import "../ftso/interface/IIFtso.sol"; +import "../genesis/interface/IFtsoRegistryGenesis.sol"; + +/** + * Interface for the `FtsoRegistry` contract. + */ +interface IFtsoRegistry is IFtsoRegistryGenesis { + /** + * Structure describing the price of an FTSO asset at a particular point in time. + */ + struct PriceInfo { + // Index of the asset. + uint256 ftsoIndex; + // Price of the asset in USD, multiplied by 10^`ASSET_PRICE_USD_DECIMALS` + uint256 price; + // Number of decimals used in the `price` field. + uint256 decimals; + // Timestamp for when this price was updated, in seconds since UNIX epoch. + uint256 timestamp; + } + + /** + * Returns the address of the FTSO contract for a given index. + * Reverts if unsupported index is passed. + * @param _activeFtso The queried index. + * @return _activeFtsoAddress FTSO contract address for the queried index. + */ + + function getFtso(uint256 _activeFtso) external view returns (IIFtso _activeFtsoAddress); + /** + * Returns the address of the FTSO contract for a given symbol. + * Reverts if unsupported symbol is passed. + * @param _symbol The queried symbol. + * @return _activeFtsoAddress FTSO contract address for the queried symbol. + */ + + function getFtsoBySymbol(string memory _symbol) external view returns (IIFtso _activeFtsoAddress); + /** + * Returns the indices of the currently supported FTSOs. + * Active FTSOs are ones that currently receive price feeds. + * @return _supportedIndices Array of all active FTSO indices in increasing order. + */ + function getSupportedIndices() external view returns (uint256[] memory _supportedIndices); + + /** + * Returns the symbols of the currently supported FTSOs. + * Active FTSOs are ones that currently receive price feeds. + * @return _supportedSymbols Array of all active FTSO symbols in increasing order. + */ + function getSupportedSymbols() external view returns (string[] memory _supportedSymbols); + + /** + * Get array of all FTSO contracts for all supported asset indices. + * The index of FTSO in returned array does not necessarily correspond to the asset's index. + * Due to deletion, some indices might be unsupported. + * + * Use `getSupportedIndicesAndFtsos` to retrieve pairs of correct indices and FTSOs, + * where possible "null" holes are readily apparent. + * @return _ftsos Array of all supported FTSOs. + */ + function getSupportedFtsos() external view returns (IIFtso[] memory _ftsos); + + /** + * Returns the FTSO index corresponding to a given asset symbol. + * Reverts if the symbol is not supported. + * @param _symbol Symbol to query. + * @return _assetIndex The corresponding asset index. + */ + function getFtsoIndex(string memory _symbol) external view returns (uint256 _assetIndex); + + /** + * Returns the asset symbol corresponding to a given FTSO index. + * Reverts if the index is not supported. + * @param _ftsoIndex Index to query. + * @return _symbol The corresponding asset symbol. + */ + function getFtsoSymbol(uint256 _ftsoIndex) external view returns (string memory _symbol); + + /** + * Public view function to get the current price of a given active FTSO index. + * Reverts if the index is not supported. + * @param _ftsoIndex Index to query. + * @return _price Current price of the asset in USD multiplied by 10^`ASSET_PRICE_USD_DECIMALS`. + * @return _timestamp Timestamp for when this price was updated, in seconds since UNIX epoch. + */ + function getCurrentPrice(uint256 _ftsoIndex) external view returns (uint256 _price, uint256 _timestamp); + + /** + * Public view function to get the current price of a given active asset symbol. + * Reverts if the symbol is not supported. + * @param _symbol Symbol to query. + * @return _price Current price of the asset in USD multiplied by 10^`ASSET_PRICE_USD_DECIMALS`. + * @return _timestamp Timestamp for when this price was updated, in seconds since UNIX epoch. + */ + function getCurrentPrice(string memory _symbol) external view returns (uint256 _price, uint256 _timestamp); + + /** + * Public view function to get the current price and decimals of a given active FTSO index. + * Reverts if the index is not supported. + * @param _assetIndex Index to query. + * @return _price Current price of the asset in USD multiplied by 10^`_assetPriceUsdDecimals`. + * @return _timestamp Timestamp for when this price was updated, in seconds since UNIX epoch. + * @return _assetPriceUsdDecimals Number of decimals used to return the `_price`. + */ + function getCurrentPriceWithDecimals(uint256 _assetIndex) + external + view + returns (uint256 _price, uint256 _timestamp, uint256 _assetPriceUsdDecimals); + + /** + * Public view function to get the current price and decimals of a given active asset symbol. + * Reverts if the symbol is not supported. + * @param _symbol Symbol to query. + * @return _price Current price of the asset in USD multiplied by 10^`_assetPriceUsdDecimals`. + * @return _timestamp Timestamp for when this price was updated, in seconds since UNIX epoch. + * @return _assetPriceUsdDecimals Number of decimals used to return the `_price`. + */ + function getCurrentPriceWithDecimals(string memory _symbol) + external + view + returns (uint256 _price, uint256 _timestamp, uint256 _assetPriceUsdDecimals); + + /** + * Returns the current price of all supported assets. + * @return Array of `PriceInfo` structures. + */ + function getAllCurrentPrices() external view returns (PriceInfo[] memory); + + /** + * Returns the current price of a list of indices. + * Reverts if any of the indices is not supported. + * @param _indices Array of indices to query. + * @return Array of `PriceInfo` structures. + */ + function getCurrentPricesByIndices(uint256[] memory _indices) external view returns (PriceInfo[] memory); + + /** + * Returns the current price of a list of asset symbols. + * Reverts if any of the symbols is not supported. + * @param _symbols Array of symbols to query. + * @return Array of `PriceInfo` structures. + */ + function getCurrentPricesBySymbols(string[] memory _symbols) external view returns (PriceInfo[] memory); + + /** + * Get all supported indices and corresponding FTSO addresses. + * Active FTSOs are ones that currently receive price feeds. + * @return _supportedIndices Array of all supported indices. + * @return _ftsos Array of all supported FTSO addresses. + */ + function getSupportedIndicesAndFtsos() + external + view + returns (uint256[] memory _supportedIndices, IIFtso[] memory _ftsos); + + /** + * Get all supported symbols and corresponding FTSO addresses. + * Active FTSOs are ones that currently receive price feeds. + * @return _supportedSymbols Array of all supported symbols. + * @return _ftsos Array of all supported FTSO addresses. + */ + function getSupportedSymbolsAndFtsos() + external + view + returns (string[] memory _supportedSymbols, IIFtso[] memory _ftsos); + + /** + * Get all supported indices and corresponding symbols. + * Active FTSOs are ones that currently receive price feeds. + * @return _supportedIndices Array of all supported indices. + * @return _supportedSymbols Array of all supported symbols. + */ + function getSupportedIndicesAndSymbols() + external + view + returns (uint256[] memory _supportedIndices, string[] memory _supportedSymbols); + + /** + * Get all supported indices, symbols, and corresponding FTSO addresses. + * Active FTSOs are ones that currently receive price feeds. + * @return _supportedIndices Array of all supported indices. + * @return _supportedSymbols Array of all supported symbols. + * @return _ftsos Array of all supported FTSO addresses. + */ + function getSupportedIndicesSymbolsAndFtsos() + external + view + returns (uint256[] memory _supportedIndices, string[] memory _supportedSymbols, IIFtso[] memory _ftsos); +} diff --git a/src/vendor/flare-smart-contracts/userInterfaces/IGovernanceSettings.sol b/src/vendor/flare-smart-contracts/userInterfaces/IGovernanceSettings.sol new file mode 100644 index 0000000..bcda848 --- /dev/null +++ b/src/vendor/flare-smart-contracts/userInterfaces/IGovernanceSettings.sol @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.7.6 <0.9; + +/** + * Interface for the `GovernanceSettings` that hold the Flare governance address and its timelock. + * + * All governance calls are delayed by the timelock specified in this contract. + * + * **NOTE**: This contract enables updating the governance address and timelock only + * by hard-forking the network, meaning only by updating validator code. + */ +interface IGovernanceSettings { + /** + * Gets the governance account address. + * The governance address can only be changed by a hard fork. + * @return _address The governance account address. + */ + function getGovernanceAddress() external view returns (address _address); + + /** + * Gets the time in seconds that must pass between a governance call and its execution. + * The timelock value can only be changed by a hard fork. + * @return _timelock Time in seconds that passes between the governance call and execution. + */ + function getTimelock() external view returns (uint256 _timelock); + + /** + * Gets the addresses of the accounts that are allowed to execute the timelocked governance calls, + * once the timelock period expires. + * Executors can be changed without a hard fork, via a normal governance call. + * @return _addresses Array of executor addresses. + */ + function getExecutors() external view returns (address[] memory _addresses); + + /** + * Checks whether an address is one of the allowed executors. See `getExecutors`. + * @param _address The address to check. + * @return True if `_address` is in the executors list. + */ + function isExecutor(address _address) external view returns (bool); +} diff --git a/src/vendor/flare-smart-contracts/userInterfaces/IGovernanceVotePower.sol b/src/vendor/flare-smart-contracts/userInterfaces/IGovernanceVotePower.sol new file mode 100644 index 0000000..f538b5e --- /dev/null +++ b/src/vendor/flare-smart-contracts/userInterfaces/IGovernanceVotePower.sol @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.7.6 <0.9; + +/** + * Interface for contracts delegating their governance vote power. + */ +interface IGovernanceVotePower { + /** + * Delegates all governance vote power of `msg.sender` to address `_to`. + * @param _to The address of the recipient. + */ + function delegate(address _to) external; + + /** + * Undelegates all governance vote power of `msg.sender`. + */ + function undelegate() external; + + /** + * Gets the governance vote power of an address at a given block number, including + * all delegations made to it. + * @param _who The address being queried. + * @param _blockNumber The block number at which to fetch the vote power. + * @return Governance vote power of `_who` at `_blockNumber`. + */ + function votePowerOfAt(address _who, uint256 _blockNumber) external view returns (uint256); + + /** + * Gets the governance vote power of an address at the latest block, including + * all delegations made to it. + * @param _who The address being queried. + * @return Governance vote power of `account` at the lastest block. + */ + function getVotes(address _who) external view returns (uint256); + + /** + * Gets the address an account is delegating its governance vote power to, at a given block number. + * @param _who The address being queried. + * @param _blockNumber The block number at which to fetch the address. + * @return Address where `_who` was delegating its governance vote power at block `_blockNumber`. + */ + function getDelegateOfAt(address _who, uint256 _blockNumber) external view returns (address); + + /** + * Gets the address an account is delegating its governance vote power to, at the latest block number. + * @param _who The address being queried. + * @return Address where `_who` is currently delegating its governance vote power. + */ + function getDelegateOfAtNow(address _who) external view returns (address); +} diff --git a/src/vendor/flare-smart-contracts/userInterfaces/IPChainStakeMirror.sol b/src/vendor/flare-smart-contracts/userInterfaces/IPChainStakeMirror.sol new file mode 100644 index 0000000..721f76e --- /dev/null +++ b/src/vendor/flare-smart-contracts/userInterfaces/IPChainStakeMirror.sol @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.7.6 <0.9; +pragma abicoder v2; + +import "./IPChainVotePower.sol"; +import "./IPChainStakeMirrorVerifier.sol"; + +/** + * Interface for the `PChainStakeMirror` contract. + */ +interface IPChainStakeMirror is IPChainVotePower { + /** + * Event emitted when max updates per block is set. + * @param maxUpdatesPerBlock new number of max updated per block + */ + event MaxUpdatesPerBlockSet(uint256 maxUpdatesPerBlock); + + /** + * Event emitted when the stake is confirmed. + * @param owner The address who opened the stake. + * @param nodeId Node id to which the stake was added. + * @param txHash Unique tx hash - keccak256(abi.encode(PChainStake.txId, PChainStake.inputAddress)); + * @param amountWei Stake amount (in wei). + * @param pChainTxId P-chain transaction id. + */ + event StakeConfirmed( + address indexed owner, bytes20 indexed nodeId, bytes32 indexed txHash, uint256 amountWei, bytes32 pChainTxId + ); + + /** + * Event emitted when the stake has ended. + * @param owner The address whose stake has ended. + * @param nodeId Node id from which the stake was removed. + * @param txHash Unique tx hash - keccak256(abi.encode(PChainStake.txId, PChainStake.inputAddress)); + * @param amountWei Stake amount (in wei). + */ + event StakeEnded(address indexed owner, bytes20 indexed nodeId, bytes32 indexed txHash, uint256 amountWei); + + /** + * Event emitted when the stake was revoked. + * @param owner The address whose stake has ended. + * @param nodeId Node id from which the stake was removed. + * @param txHash Unique tx hash - keccak256(abi.encode(PChainStake.txId, PChainStake.inputAddress)); + * @param amountWei Stake amount (in wei). + */ + event StakeRevoked(address indexed owner, bytes20 indexed nodeId, bytes32 indexed txHash, uint256 amountWei); + + /** + * Method for P-chain stake mirroring using `PChainStake` data and Merkle proof. + * @param _stakeData Information about P-chain stake. + * @param _merkleProof Merkle proof that should be used to prove the P-chain stake. + */ + function mirrorStake(IPChainStakeMirrorVerifier.PChainStake calldata _stakeData, bytes32[] calldata _merkleProof) + external; + + /** + * Method for checking if active stake (stake start time <= block.timestamp < stake end time) was already mirrored. + * @param _txId P-chain stake transaction id. + * @param _inputAddress P-chain address that opened stake. + * @return True if stake is active and mirrored. + */ + function isActiveStakeMirrored(bytes32 _txId, bytes20 _inputAddress) external view returns (bool); + + /** + * Total amount of tokens at current block. + * @return The current total amount of tokens. + * + */ + function totalSupply() external view returns (uint256); + + /** + * Total amount of tokens at a specific `_blockNumber`. + * @param _blockNumber The block number when the totalSupply is queried. + * @return The total amount of tokens at `_blockNumber`. + * + */ + function totalSupplyAt(uint256 _blockNumber) external view returns (uint256); + + /** + * Queries the token balance of `_owner` at current block. + * @param _owner The address from which the balance will be retrieved. + * @return The current balance. + * + */ + function balanceOf(address _owner) external view returns (uint256); + + /** + * Queries the token balance of `_owner` at a specific `_blockNumber`. + * @param _owner The address from which the balance will be retrieved. + * @param _blockNumber The block number when the balance is queried. + * @return The balance at `_blockNumber`. + * + */ + function balanceOfAt(address _owner, uint256 _blockNumber) external view returns (uint256); +} diff --git a/src/vendor/flare-smart-contracts/userInterfaces/IPChainStakeMirrorVerifier.sol b/src/vendor/flare-smart-contracts/userInterfaces/IPChainStakeMirrorVerifier.sol new file mode 100644 index 0000000..cfdfee2 --- /dev/null +++ b/src/vendor/flare-smart-contracts/userInterfaces/IPChainStakeMirrorVerifier.sol @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.7.6 <0.9; +pragma abicoder v2; + +/** + * Interface with structure for P-chain stake mirror verifications. + */ +interface IPChainStakeMirrorVerifier { + /** + * Structure describing the P-chain stake. + */ + struct PChainStake { + // Hash of the transaction on the underlying chain. + bytes32 txId; + // Type of the staking/delegation transaction: '0' for 'ADD_VALIDATOR_TX' and '1' for 'ADD_DELEGATOR_TX'. + uint8 stakingType; + // Input address that triggered the staking or delegation transaction. + // See https://support.avax.network/en/articles/4596397-what-is-an-address for address definition for P-chain. + bytes20 inputAddress; + // NodeID to which staking or delegation is done. + // For definitions, see https://github.com/ava-labs/avalanchego/blob/master/ids/node_id.go. + bytes20 nodeId; + // Start time of the staking/delegation in seconds (Unix epoch). + uint64 startTime; + // End time of the staking/delegation in seconds (Unix epoch). + uint64 endTime; + // Staked or delegated amount in Gwei (nano FLR). + uint64 weight; + } +} diff --git a/src/vendor/flare-smart-contracts/userInterfaces/IPChainVotePower.sol b/src/vendor/flare-smart-contracts/userInterfaces/IPChainVotePower.sol new file mode 100644 index 0000000..cb4928d --- /dev/null +++ b/src/vendor/flare-smart-contracts/userInterfaces/IPChainVotePower.sol @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.7.6 <0.9; + +/** + * Interface for the vote power part of the `PChainStakeMirror` contract. + */ +interface IPChainVotePower { + /** + * Event triggered when a stake is confirmed or at the time it ends. + * Definition: `votePowerFromTo(owner, nodeId)` is `changed` from `priorVotePower` to `newVotePower`. + * @param owner The account that has changed the amount of vote power it is staking. + * @param nodeId The node id whose received vote power has changed. + * @param priorVotePower The vote power originally on that node id. + * @param newVotePower The new vote power that triggered this event. + */ + event VotePowerChanged(address indexed owner, bytes20 indexed nodeId, uint256 priorVotePower, uint256 newVotePower); + + /** + * Emitted when a vote power cache entry is created. + * Allows history cleaners to track vote power cache cleanup opportunities off-chain. + * @param nodeId The node id whose vote power has just been cached. + * @param blockNumber The block number at which the vote power has been cached. + */ + event VotePowerCacheCreated(bytes20 nodeId, uint256 blockNumber); + + /** + * Get the vote power of `_owner` at block `_blockNumber` using cache. + * It tries to read the cached value and if not found, reads the actual value and stores it in cache. + * Can only be used if _blockNumber is in the past, otherwise reverts. + * @param _owner The node id to get voting power. + * @param _blockNumber The block number at which to fetch. + * @return Vote power of `_owner` at `_blockNumber`. + */ + function votePowerOfAtCached(bytes20 _owner, uint256 _blockNumber) external returns (uint256); + + /** + * Get the total vote power at block `_blockNumber` using cache. + * It tries to read the cached value and if not found, reads the actual value and stores it in cache. + * Can only be used if `_blockNumber` is in the past, otherwise reverts. + * @param _blockNumber The block number at which to fetch. + * @return The total vote power at the block (sum of all accounts' vote powers). + */ + function totalVotePowerAtCached(uint256 _blockNumber) external returns (uint256); + + /** + * Get the current total vote power. + * @return The current total vote power (sum of all accounts' vote powers). + */ + function totalVotePower() external view returns (uint256); + + /** + * Get the total vote power at block `_blockNumber` + * @param _blockNumber The block number at which to fetch. + * @return The total vote power at the block (sum of all accounts' vote powers). + */ + function totalVotePowerAt(uint256 _blockNumber) external view returns (uint256); + + /** + * Get the amounts and node ids being staked to by a vote power owner. + * @param _owner The address being queried. + * @return _nodeIds Array of node ids. + * @return _amounts Array of staked amounts, for each node id. + */ + function stakesOf(address _owner) external view returns (bytes20[] memory _nodeIds, uint256[] memory _amounts); + + /** + * Get the amounts and node ids being staked to by a vote power owner, + * at a given block. + * @param _owner The address being queried. + * @param _blockNumber The block number being queried. + * @return _nodeIds Array of node ids. + * @return _amounts Array of staked amounts, for each node id. + */ + function stakesOfAt(address _owner, uint256 _blockNumber) + external + view + returns (bytes20[] memory _nodeIds, uint256[] memory _amounts); + + /** + * Get the current vote power of `_nodeId`. + * @param _nodeId The node id to get voting power. + * @return Current vote power of `_nodeId`. + */ + function votePowerOf(bytes20 _nodeId) external view returns (uint256); + + /** + * Get the vote power of `_nodeId` at block `_blockNumber` + * @param _nodeId The node id to get voting power. + * @param _blockNumber The block number at which to fetch. + * @return Vote power of `_nodeId` at `_blockNumber`. + */ + function votePowerOfAt(bytes20 _nodeId, uint256 _blockNumber) external view returns (uint256); + + /** + * Get current staked vote power from `_owner` staked to `_nodeId`. + * @param _owner Address of vote power owner. + * @param _nodeId Node id. + * @return The staked vote power. + */ + function votePowerFromTo(address _owner, bytes20 _nodeId) external view returns (uint256); + + /** + * Get current staked vote power from `_owner` staked to `_nodeId` at `_blockNumber`. + * @param _owner Address of vote power owner. + * @param _nodeId Node id. + * @param _blockNumber The block number at which to fetch. + * @return The staked vote power. + */ + function votePowerFromToAt(address _owner, bytes20 _nodeId, uint256 _blockNumber) external view returns (uint256); + + /** + * Return vote powers for several node ids in a batch. + * @param _nodeIds The list of node ids to fetch vote power of. + * @param _blockNumber The block number at which to fetch. + * @return A list of vote powers. + */ + function batchVotePowerOfAt(bytes20[] memory _nodeIds, uint256 _blockNumber) + external + view + returns (uint256[] memory); +} diff --git a/src/vendor/flare-smart-contracts/userInterfaces/IVPContractEvents.sol b/src/vendor/flare-smart-contracts/userInterfaces/IVPContractEvents.sol new file mode 100644 index 0000000..c250e75 --- /dev/null +++ b/src/vendor/flare-smart-contracts/userInterfaces/IVPContractEvents.sol @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.7.6 <0.9; + +/** + * Events interface for vote-power related operations. + */ +interface IVPContractEvents { + /** + * Emitted when the amount of vote power delegated from one account to another changes. + * + * **Note**: This event is always emitted from VPToken's `writeVotePowerContract`. + * @param from The account that has changed the amount of vote power it is delegating. + * @param to The account whose received vote power has changed. + * @param priorVotePower The vote power originally delegated. + * @param newVotePower The new vote power that triggered this event. + * It can be 0 if the delegation is completely canceled. + */ + event Delegate(address indexed from, address indexed to, uint256 priorVotePower, uint256 newVotePower); + + /** + * Emitted when an account revokes its vote power delegation to another account + * for a single current or past block (typically the current vote block). + * + * **Note**: This event is always emitted from VPToken's `writeVotePowerContract` or `readVotePowerContract`. + * + * See `revokeDelegationAt` in `IVPToken`. + * @param delegator The account that revoked the delegation. + * @param delegatee The account that has been revoked. + * @param votePower The revoked vote power. + * @param blockNumber The block number at which the delegation has been revoked. + */ + event Revoke(address indexed delegator, address indexed delegatee, uint256 votePower, uint256 blockNumber); +} diff --git a/src/vendor/flare-smart-contracts/userInterfaces/IVPToken.sol b/src/vendor/flare-smart-contracts/userInterfaces/IVPToken.sol new file mode 100644 index 0000000..309211d --- /dev/null +++ b/src/vendor/flare-smart-contracts/userInterfaces/IVPToken.sol @@ -0,0 +1,254 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.7.6 <0.9; + +import {IERC20} from "@openzeppelin-contracts-5.6.1/token/ERC20/IERC20.sol"; +import {IGovernanceVotePower} from "./IGovernanceVotePower.sol"; +import {IVPContractEvents} from "./IVPContractEvents.sol"; + +/** + * Vote power token interface. + */ +interface IVPToken is IERC20 { + /** + * Delegate voting power to account `_to` from `msg.sender`, by percentage. + * @param _to The address of the recipient. + * @param _bips The percentage of voting power to be delegated expressed in basis points (1/100 of one percent). + * Not cumulative: every call resets the delegation value (and a value of 0 revokes all previous delegations). + */ + function delegate(address _to, uint256 _bips) external; + + /** + * Undelegate all percentage delegations from the sender and then delegate corresponding + * `_bips` percentage of voting power from the sender to each member of the `_delegatees` array. + * @param _delegatees The addresses of the new recipients. + * @param _bips The percentages of voting power to be delegated expressed in basis points (1/100 of one percent). + * The sum of all `_bips` values must be at most 10000 (100%). + */ + function batchDelegate(address[] memory _delegatees, uint256[] memory _bips) external; + + /** + * Explicitly delegate `_amount` voting power to account `_to` from `msg.sender`. + * Compare with `delegate` which delegates by percentage. + * @param _to The address of the recipient. + * @param _amount An explicit vote power amount to be delegated. + * Not cumulative: every call resets the delegation value (and a value of 0 revokes all previous delegations). + */ + function delegateExplicit(address _to, uint256 _amount) external; + + /** + * Revoke all delegation from sender to `_who` at given block. + * Only affects the reads via `votePowerOfAtCached()` in the block `_blockNumber`. + * Block `_blockNumber` must be in the past. + * This method should be used only to prevent rogue delegate voting in the current voting block. + * To stop delegating use delegate / delegateExplicit with value of 0 or undelegateAll / undelegateAllExplicit. + * @param _who Address of the delegatee. + * @param _blockNumber The block number at which to revoke delegation.. + */ + function revokeDelegationAt(address _who, uint256 _blockNumber) external; + + /** + * Undelegate all voting power of `msg.sender`. This effectively revokes all previous delegations. + * Can only be used with percentage delegation. + * Does not reset delegation mode back to NOT SET. + */ + function undelegateAll() external; + + /** + * Undelegate all explicit vote power by amount of `msg.sender`. + * Can only be used with explicit delegation. + * Does not reset delegation mode back to NOT SET. + * @param _delegateAddresses Explicit delegation does not store delegatees' addresses, + * so the caller must supply them. + * @return The amount still delegated (in case the list of delegates was incomplete). + */ + function undelegateAllExplicit(address[] memory _delegateAddresses) external returns (uint256); + + /** + * Returns the name of the token. + * @dev Should be compatible with ERC20 method. + */ + function name() external view returns (string memory); + + /** + * Returns the symbol of the token, usually a shorter version of the name. + * @dev Should be compatible with ERC20 method. + */ + function symbol() external view returns (string memory); + + /** + * Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals 2, a balance of 505 tokens should + * be displayed to a user as 5.05 (505 / 102). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and wei. This is the default value returned by this function, unless + * it's overridden. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * balanceOf and transfer. + * @dev Should be compatible with ERC20 method. + */ + function decimals() external view returns (uint8); + + /** + * Total amount of tokens held by all accounts at a specific block number. + * @param _blockNumber The block number to query. + * @return The total amount of tokens at `_blockNumber`. + */ + function totalSupplyAt(uint256 _blockNumber) external view returns (uint256); + + /** + * Queries the token balance of `_owner` at a specific `_blockNumber`. + * @param _owner The address from which the balance will be retrieved. + * @param _blockNumber The block number to query. + * @return The balance at `_blockNumber`. + */ + function balanceOfAt(address _owner, uint256 _blockNumber) external view returns (uint256); + + /** + * Get the current total vote power. + * @return The current total vote power (sum of all accounts' vote power). + */ + function totalVotePower() external view returns (uint256); + + /** + * Get the total vote power at block `_blockNumber`. + * @param _blockNumber The block number to query. + * @return The total vote power at the queried block (sum of all accounts' vote powers). + */ + function totalVotePowerAt(uint256 _blockNumber) external view returns (uint256); + + /** + * Get the current vote power of `_owner`. + * @param _owner The address to query. + * @return Current vote power of `_owner`. + */ + function votePowerOf(address _owner) external view returns (uint256); + + /** + * Get the vote power of `_owner` at block `_blockNumber` + * @param _owner The address to query. + * @param _blockNumber The block number to query. + * @return Vote power of `_owner` at block number `_blockNumber`. + */ + function votePowerOfAt(address _owner, uint256 _blockNumber) external view returns (uint256); + + /** + * Get the vote power of `_owner` at block `_blockNumber`, ignoring revocation information (and cache). + * @param _owner The address to query. + * @param _blockNumber The block number to query. + * @return Vote power of `_owner` at block number `_blockNumber`. Result doesn't change if vote power is revoked. + */ + function votePowerOfAtIgnoringRevocation(address _owner, uint256 _blockNumber) external view returns (uint256); + + /** + * Get the delegation mode for account '_who'. This mode determines whether vote power is + * allocated by percentage or by explicit amount. Once the delegation mode is set, + * it can never be changed, even if all delegations are removed. + * @param _who The address to get delegation mode. + * @return Delegation mode: 0 = NOT SET, 1 = PERCENTAGE, 2 = AMOUNT (i.e. explicit). + */ + function delegationModeOf(address _who) external view returns (uint256); + + /** + * Get current delegated vote power from delegator `_from` to delegatee `_to`. + * @param _from Address of delegator. + * @param _to Address of delegatee. + * @return votePower The delegated vote power. + */ + function votePowerFromTo(address _from, address _to) external view returns (uint256); + + /** + * Get delegated vote power from delegator `_from` to delegatee `_to` at `_blockNumber`. + * @param _from Address of delegator. + * @param _to Address of delegatee. + * @param _blockNumber The block number to query. + * @return The delegated vote power. + */ + function votePowerFromToAt(address _from, address _to, uint256 _blockNumber) external view returns (uint256); + + /** + * Compute the current undelegated vote power of the `_owner` account. + * @param _owner The address to query. + * @return The unallocated vote power of `_owner`. + */ + function undelegatedVotePowerOf(address _owner) external view returns (uint256); + + /** + * Get the undelegated vote power of the `_owner` account at a given block number. + * @param _owner The address to query. + * @param _blockNumber The block number to query. + * @return The unallocated vote power of `_owner`. + */ + function undelegatedVotePowerOfAt(address _owner, uint256 _blockNumber) external view returns (uint256); + + /** + * Get the list of addresses to which `_who` is delegating, and their percentages. + * @param _who The address to query. + * @return _delegateAddresses Positional array of addresses being delegated to. + * @return _bips Positional array of delegation percents specified in basis points (1/100 of 1 percent). + * Each one matches the address in the same position in the `_delegateAddresses` array. + * @return _count The number of delegates. + * @return _delegationMode Delegation mode: 0 = NOT SET, 1 = PERCENTAGE, 2 = AMOUNT (i.e. explicit). + */ + function delegatesOf(address _who) + external + view + returns (address[] memory _delegateAddresses, uint256[] memory _bips, uint256 _count, uint256 _delegationMode); + + /** + * Get the list of addresses to which `_who` is delegating, and their percentages, at the given block. + * @param _who The address to query. + * @param _blockNumber The block number to query. + * @return _delegateAddresses Positional array of addresses being delegated to. + * @return _bips Positional array of delegation percents specified in basis points (1/100 of 1 percent). + * Each one matches the address in the same position in the `_delegateAddresses` array. + * @return _count The number of delegates. + * @return _delegationMode Delegation mode: 0 = NOT SET, 1 = PERCENTAGE, 2 = AMOUNT (i.e. explicit). + */ + function delegatesOfAt(address _who, uint256 _blockNumber) + external + view + returns (address[] memory _delegateAddresses, uint256[] memory _bips, uint256 _count, uint256 _delegationMode); + + /** + * Returns VPContract event interface used for read-only operations (view methods). + * The only non-view method that might be called on it is `revokeDelegationAt`. + * + * `readVotePowerContract` is almost always equal to `writeVotePowerContract` + * except during an upgrade from one `VPContract` to a new version (which should happen + * rarely or never and will be announced beforehand). + * + * Do not call any methods on `VPContract` directly. + * State changing methods are forbidden from direct calls. + * All methods are exposed via `VPToken`. + * This is the reason that this method returns `IVPContractEvents`. + * Use it only for listening to events and revoking. + */ + function readVotePowerContract() external view returns (IVPContractEvents); + + /** + * Returns VPContract event interface used for state-changing operations (non-view methods). + * The only non-view method that might be called on it is `revokeDelegationAt`. + * + * `writeVotePowerContract` is almost always equal to `readVotePowerContract`, + * except during upgrade from one `VPContract` to a new version (which should happen + * rarely or never and will be announced beforehand). + * In the case of an upgrade, `writeVotePowerContract` is replaced first to establish delegations. + * After some period (e.g., after a reward epoch ends), `readVotePowerContract` is set equal to it. + * + * Do not call any methods on `VPContract` directly. + * State changing methods are forbidden from direct calls. + * All are exposed via `VPToken`. + * This is the reason that this method returns `IVPContractEvents` + * Use it only for listening to events, delegating, and revoking. + */ + function writeVotePowerContract() external view returns (IVPContractEvents); + + /** + * When set, allows token owners to participate in governance voting + * and delegating governance vote power. + */ + function governanceVotePower() external view returns (IGovernanceVotePower); +} diff --git a/test/abstract/FtsoTest.sol b/test/abstract/FtsoTest.sol index 910edba..3db7bd9 100644 --- a/test/abstract/FtsoTest.sol +++ b/test/abstract/FtsoTest.sol @@ -2,17 +2,18 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity =0.8.25; -import {Test} from "forge-std/Test.sol"; +import {Test} from "forge-std-1.16.1/src/Test.sol"; import { IFtso, IFtsoRegistry, + //forge-lint: disable-next-line(unused-import) LibFlareContractRegistry, FLARE_CONTRACT_REGISTRY, FTSO_REGISTRY_NAME, IFlareContractRegistry } from "src/lib/registry/LibFlareContractRegistry.sol"; -import {OperandV2, StackItem} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol"; +import {OperandV2, StackItem} from "rain-interpreter-interface-0.1.0/src/interface/IInterpreterV4.sol"; abstract contract FtsoTest is Test { address constant FTSO = address(0x1000000); diff --git a/test/fork/LibFork.sol b/test/fork/LibFork.sol index 0f29a03..c278e52 100644 --- a/test/fork/LibFork.sol +++ b/test/fork/LibFork.sol @@ -2,7 +2,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity ^0.8.19; -import {Vm} from "forge-std/Vm.sol"; +import {Vm} from "forge-std-1.16.1/src/Vm.sol"; library LibFork { function rpcUrlFlare(Vm vm) internal view returns (string memory) { diff --git a/test/prod/FlareInterfacesProd.t.sol b/test/prod/FlareInterfacesProd.t.sol new file mode 100644 index 0000000..546f34f --- /dev/null +++ b/test/prod/FlareInterfacesProd.t.sol @@ -0,0 +1,174 @@ +// SPDX-License-Identifier: LicenseRef-DCL-1.0 +// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd +pragma solidity =0.8.25; + +import {Test} from "forge-std-1.16.1/src/Test.sol"; +import {LibFork} from "../fork/LibFork.sol"; +import {BLOCK_NUMBER} from "../src/lib/registry/LibFlareContractRegistry.t.sol"; + +import {IFlareContractRegistry} from "flare-smart-contracts/userInterfaces/IFlareContractRegistry.sol"; +import {IFtsoRegistry} from "flare-smart-contracts/userInterfaces/IFtsoRegistry.sol"; +import {IFtso} from "flare-smart-contracts/userInterfaces/IFtso.sol"; +import {FtsoV2Interface} from "flare-smart-contracts-v2/userInterfaces/LTS/FtsoV2Interface.sol"; +import {IFeeCalculator} from "flare-smart-contracts-v2/userInterfaces/IFeeCalculator.sol"; + +import { + FLARE_CONTRACT_REGISTRY, + FTSO_REGISTRY_NAME, + FTSO_V2_LTS_NAME, + FEE_CALCULATOR_NAME, + LibFlareContractRegistry +} from "../../src/lib/registry/LibFlareContractRegistry.sol"; +import { + FLR_USD_FEED_ID, + SGB_USD_FEED_ID, + BTC_USD_FEED_ID, + XRP_USD_FEED_ID, + LTC_USD_FEED_ID, + XLM_USD_FEED_ID, + DOGE_USD_FEED_ID, + ADA_USD_FEED_ID, + ETH_USD_FEED_ID +} from "../../src/lib/lts/LibFtsoV2LTS.sol"; + +/// @title FlareInterfacesProdTest +/// @notice Exercises every method this repo calls on a vendored Flare +/// interface (src/vendor/) against the live Flare network at a pinned block. +/// If upstream Flare ever changes a method signature or removes a contract +/// from the canonical name registry, the corresponding test fails — catching +/// drift between our vendored copies and the on-chain ABI. +contract FlareInterfacesProdTest is Test { + /// IFlareContractRegistry: name resolution is the entry point for every + /// other interface we use. + function testFlareContractRegistryGetContractAddressByName() external { + vm.createSelectFork(LibFork.rpcUrlFlare(vm), BLOCK_NUMBER); + assertTrue( + FLARE_CONTRACT_REGISTRY.getContractAddressByName(FTSO_REGISTRY_NAME) != address(0), + "FtsoRegistry not registered" + ); + assertTrue( + FLARE_CONTRACT_REGISTRY.getContractAddressByName(FTSO_V2_LTS_NAME) != address(0), "FtsoV2 not registered" + ); + assertTrue( + FLARE_CONTRACT_REGISTRY.getContractAddressByName(FEE_CALCULATOR_NAME) != address(0), + "FeeCalculator not registered" + ); + } + + /// IFtsoRegistry.getFtsoBySymbol — used in LibFtsoCurrentPriceUsd to look + /// up an FTSO by its symbol. + function testFtsoRegistryGetFtsoBySymbol() external { + vm.createSelectFork(LibFork.rpcUrlFlare(vm), BLOCK_NUMBER); + IFtsoRegistry registry = LibFlareContractRegistry.getFtsoRegistry(); + IFtso ftso = registry.getFtsoBySymbol("FLR"); + assertTrue(address(ftso) != address(0), "FLR FTSO not found"); + } + + /// IFtso.active and IFtso.getCurrentPriceWithDecimals — used in + /// LibFtsoCurrentPriceUsd to read the FLR/USD price. + function testFtsoActiveAndGetCurrentPriceWithDecimals() external { + vm.createSelectFork(LibFork.rpcUrlFlare(vm), BLOCK_NUMBER); + IFtso ftso = LibFlareContractRegistry.getFtsoRegistry().getFtsoBySymbol("FLR"); + assertTrue(ftso.active(), "FLR FTSO not active"); + (uint256 price, uint256 timestamp, uint256 decimals) = ftso.getCurrentPriceWithDecimals(); + assertTrue(price > 0, "FLR price is zero"); + assertTrue(timestamp > 0, "FLR price timestamp is zero"); + assertTrue(decimals > 0 && decimals < 30, "FLR decimals out of plausible range"); + } + + /// IFtso.getCurrentPriceDetails — used in LibFtsoCurrentPricePair to + /// guard against stale prices. + function testFtsoGetCurrentPriceDetails() external { + vm.createSelectFork(LibFork.rpcUrlFlare(vm), BLOCK_NUMBER); + IFtso ftso = LibFlareContractRegistry.getFtsoRegistry().getFtsoBySymbol("FLR"); + (uint256 price, uint256 timestamp,,,) = ftso.getCurrentPriceDetails(); + assertTrue(price > 0, "FLR price is zero"); + assertTrue(timestamp > 0, "FLR price timestamp is zero"); + } + + /// IFeeCalculator.calculateFeeByIds — used in LibFtsoV2LTS to compute + /// the wei value needed for the FtsoV2 getFeedByIdInWei call. + function testFeeCalculatorCalculateFeeByIds() external { + vm.createSelectFork(LibFork.rpcUrlFlare(vm), BLOCK_NUMBER); + IFeeCalculator feeCalc = LibFlareContractRegistry.getFeeCalculator(); + bytes21[] memory feedIds = new bytes21[](1); + feedIds[0] = FLR_USD_FEED_ID; + uint256 fee = feeCalc.calculateFeeByIds(feedIds); + // Fee is allowed to be zero on Flare but the call must not revert. + assertTrue(fee < 1 ether, "fee is implausibly large"); + } + + /// FtsoV2Interface.getFeedByIdInWei — used in LibFtsoV2LTS for v2 LTS + /// feed reads. The call is `payable`; we pay the fee returned by the + /// FeeCalculator above. + function testFtsoV2LTSGetFeedByIdInWei() external { + vm.createSelectFork(LibFork.rpcUrlFlare(vm), BLOCK_NUMBER); + FtsoV2Interface ftsoV2 = LibFlareContractRegistry.getFtsoV2LTS(); + IFeeCalculator feeCalc = LibFlareContractRegistry.getFeeCalculator(); + bytes21[] memory feedIds = new bytes21[](1); + feedIds[0] = BTC_USD_FEED_ID; + uint256 fee = feeCalc.calculateFeeByIds(feedIds); + vm.deal(address(this), fee); + (uint256 value, uint64 timestamp) = ftsoV2.getFeedByIdInWei{value: fee}(BTC_USD_FEED_ID); + assertTrue(value > 0, "BTC feed value is zero"); + assertTrue(timestamp > 0, "BTC feed timestamp is zero"); + } + + /// IFtsoRegistry.getFtsoBySymbol resolves the canonical major symbols. + function testFtsoRegistryGetFtsoBySymbolMajors() external { + vm.createSelectFork(LibFork.rpcUrlFlare(vm), BLOCK_NUMBER); + IFtsoRegistry registry = LibFlareContractRegistry.getFtsoRegistry(); + string[7] memory symbols = ["FLR", "BTC", "ETH", "XRP", "LTC", "ADA", "DOGE"]; + for (uint256 i = 0; i < symbols.length; i++) { + IFtso ftso = registry.getFtsoBySymbol(symbols[i]); + assertTrue(address(ftso) != address(0), string.concat(symbols[i], " FTSO not found")); + assertTrue(ftso.active(), string.concat(symbols[i], " FTSO not active")); + (uint256 price, uint256 timestamp, uint256 decimals) = ftso.getCurrentPriceWithDecimals(); + assertTrue(price > 0, string.concat(symbols[i], " price is zero")); + assertTrue(timestamp > 0, string.concat(symbols[i], " timestamp is zero")); + assertTrue(decimals > 0 && decimals < 30, string.concat(symbols[i], " decimals out of range")); + } + } + + /// IFeeCalculator handles multi-feed batches, which LibFtsoV2LTS may + /// invoke for pair lookups. + function testFeeCalculatorMultipleFeeds() external { + vm.createSelectFork(LibFork.rpcUrlFlare(vm), BLOCK_NUMBER); + IFeeCalculator feeCalc = LibFlareContractRegistry.getFeeCalculator(); + bytes21[] memory feedIds = new bytes21[](3); + feedIds[0] = FLR_USD_FEED_ID; + feedIds[1] = BTC_USD_FEED_ID; + feedIds[2] = ETH_USD_FEED_ID; + uint256 fee = feeCalc.calculateFeeByIds(feedIds); + assertTrue(fee < 1 ether, "multi-feed fee is implausibly large"); + } + + /// FtsoV2 LTS feeds resolve and return non-zero values for every feed ID + /// defined as a constant in LibFtsoV2LTS that this repo's source might + /// reference. + function testFtsoV2LTSFeedsAllMajors() external { + vm.createSelectFork(LibFork.rpcUrlFlare(vm), BLOCK_NUMBER); + FtsoV2Interface ftsoV2 = LibFlareContractRegistry.getFtsoV2LTS(); + IFeeCalculator feeCalc = LibFlareContractRegistry.getFeeCalculator(); + bytes21[9] memory feeds = [ + FLR_USD_FEED_ID, + SGB_USD_FEED_ID, + BTC_USD_FEED_ID, + XRP_USD_FEED_ID, + LTC_USD_FEED_ID, + XLM_USD_FEED_ID, + DOGE_USD_FEED_ID, + ADA_USD_FEED_ID, + ETH_USD_FEED_ID + ]; + for (uint256 i = 0; i < feeds.length; i++) { + bytes21[] memory ids = new bytes21[](1); + ids[0] = feeds[i]; + uint256 fee = feeCalc.calculateFeeByIds(ids); + vm.deal(address(this), fee); + (uint256 value, uint64 timestamp) = ftsoV2.getFeedByIdInWei{value: fee}(feeds[i]); + assertTrue(value > 0, "feed value is zero"); + assertTrue(timestamp > 0, "feed timestamp is zero"); + } + } +} diff --git a/test/src/concrete/FlareFtsoWords.describedByMeta.t.sol b/test/src/concrete/FlareFtsoWords.describedByMeta.t.sol index f9e1c2c..1fe3a8d 100644 --- a/test/src/concrete/FlareFtsoWords.describedByMeta.t.sol +++ b/test/src/concrete/FlareFtsoWords.describedByMeta.t.sol @@ -2,7 +2,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity =0.8.25; -import {Test} from "forge-std/Test.sol"; +import {Test} from "forge-std-1.16.1/src/Test.sol"; import {FlareFtsoWords} from "src/concrete/FlareFtsoWords.sol"; contract FlareFtsoWordsDescribedByMetaTest is Test { diff --git a/test/src/concrete/FlareFtsoWords.ftsoCurrentPricePair.t.sol b/test/src/concrete/FlareFtsoWords.ftsoCurrentPricePair.t.sol index b82a5a8..339a5b7 100644 --- a/test/src/concrete/FlareFtsoWords.ftsoCurrentPricePair.t.sol +++ b/test/src/concrete/FlareFtsoWords.ftsoCurrentPricePair.t.sol @@ -2,12 +2,12 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity =0.8.25; -import {OpTest, StackItem} from "rain.interpreter/../test/abstract/OpTest.sol"; +import {OpTest, StackItem} from "rainlang-0.1.1/src/../test/abstract/OpTest.sol"; import {FlareFtsoWords} from "src/concrete/FlareFtsoWords.sol"; import {LibFork} from "test/fork/LibFork.sol"; -import {Strings} from "openzeppelin-contracts/contracts/utils/Strings.sol"; +import {Strings} from "@openzeppelin-contracts-5.6.1/utils/Strings.sol"; import {BLOCK_NUMBER} from "../lib/registry/LibFlareContractRegistry.t.sol"; -import {LibDecimalFloat, Float} from "rain.math.float/lib/LibDecimalFloat.sol"; +import {LibDecimalFloat, Float} from "rain-math-float-0.1.1/src/lib/LibDecimalFloat.sol"; contract FlareFtsoWordsFtsoCurrentPricePairTest is OpTest { using Strings for address; diff --git a/test/src/concrete/FlareFtsoWords.ftsoCurrentPriceUsd.t.sol b/test/src/concrete/FlareFtsoWords.ftsoCurrentPriceUsd.t.sol index ccb8b84..fb3e711 100644 --- a/test/src/concrete/FlareFtsoWords.ftsoCurrentPriceUsd.t.sol +++ b/test/src/concrete/FlareFtsoWords.ftsoCurrentPriceUsd.t.sol @@ -2,12 +2,12 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity =0.8.25; -import {OpTest, StackItem} from "rain.interpreter/../test/abstract/OpTest.sol"; +import {OpTest, StackItem} from "rainlang-0.1.1/src/../test/abstract/OpTest.sol"; import {FlareFtsoWords} from "src/concrete/FlareFtsoWords.sol"; import {LibFork} from "test/fork/LibFork.sol"; -import {Strings} from "openzeppelin-contracts/contracts/utils/Strings.sol"; +import {Strings} from "@openzeppelin-contracts-5.6.1/utils/Strings.sol"; import {BLOCK_NUMBER} from "../lib/registry/LibFlareContractRegistry.t.sol"; -import {LibDecimalFloat, Float} from "rain.math.float/lib/LibDecimalFloat.sol"; +import {LibDecimalFloat, Float} from "rain-math-float-0.1.1/src/lib/LibDecimalFloat.sol"; contract FlareFtsoWordsFtsoCurrentPriceUsdTest is OpTest { using Strings for address; diff --git a/test/src/concrete/FlareFtsoWords.ierc165.t.sol b/test/src/concrete/FlareFtsoWords.ierc165.t.sol index aba81da..21af900 100644 --- a/test/src/concrete/FlareFtsoWords.ierc165.t.sol +++ b/test/src/concrete/FlareFtsoWords.ierc165.t.sol @@ -2,17 +2,17 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity =0.8.25; -import {Test} from "forge-std/Test.sol"; +import {Test} from "forge-std-1.16.1/src/Test.sol"; -import {IERC165} from "openzeppelin-contracts/contracts/utils/introspection/IERC165.sol"; -import {IInterpreterExternV4} from "rain.interpreter.interface/interface/unstable/IInterpreterExternV4.sol"; -import {ISubParserV4} from "rain.interpreter.interface/interface/unstable/ISubParserV4.sol"; +import {IERC165} from "@openzeppelin-contracts-5.6.1/utils/introspection/IERC165.sol"; +import {IInterpreterExternV4} from "rain-interpreter-interface-0.1.0/src/interface/IInterpreterExternV4.sol"; +import {ISubParserV4} from "rain-interpreter-interface-0.1.0/src/interface/ISubParserV4.sol"; import {FlareFtsoWords} from "src/concrete/FlareFtsoWords.sol"; -import {IDescribedByMetaV1} from "rain.metadata/interface/IDescribedByMetaV1.sol"; -import {IIntegrityToolingV1} from "rain.sol.codegen/interface/IIntegrityToolingV1.sol"; -import {IOpcodeToolingV1} from "rain.sol.codegen/interface/IOpcodeToolingV1.sol"; -import {IParserToolingV1} from "rain.sol.codegen/interface/IParserToolingV1.sol"; -import {ISubParserToolingV1} from "rain.sol.codegen/interface/ISubParserToolingV1.sol"; +import {IDescribedByMetaV1} from "rain-metadata-0.1.0/src/interface/IDescribedByMetaV1.sol"; +import {IIntegrityToolingV1} from "rain-sol-codegen-0.1.0/src/interface/IIntegrityToolingV1.sol"; +import {IOpcodeToolingV1} from "rain-sol-codegen-0.1.0/src/interface/IOpcodeToolingV1.sol"; +import {IParserToolingV1} from "rain-sol-codegen-0.1.0/src/interface/IParserToolingV1.sol"; +import {ISubParserToolingV1} from "rain-sol-codegen-0.1.0/src/interface/ISubParserToolingV1.sol"; contract FlareFtsoWordsIERC165Test is Test { /// Test that ERC165 is implemented for the FlareFtsoWords contract. diff --git a/test/src/concrete/FlareFtsoWords.pointers.t.sol b/test/src/concrete/FlareFtsoWords.pointers.t.sol index 729e79f..285cd6b 100644 --- a/test/src/concrete/FlareFtsoWords.pointers.t.sol +++ b/test/src/concrete/FlareFtsoWords.pointers.t.sol @@ -2,7 +2,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity =0.8.25; -import {Test} from "forge-std/Test.sol"; +import {Test} from "forge-std-1.16.1/src/Test.sol"; import { FlareFtsoWords, INTEGRITY_FUNCTION_POINTERS, @@ -12,7 +12,7 @@ import { SUB_PARSER_PARSE_META, AuthoringMetaV2 } from "src/concrete/FlareFtsoWords.sol"; -import {LibGenParseMeta} from "rain.interpreter.interface/lib/codegen/LibGenParseMeta.sol"; +import {LibGenParseMeta} from "rain-interpreter-interface-0.1.0/src/lib/codegen/LibGenParseMeta.sol"; import {LibFlareFtsoSubParser} from "src/lib/parse/LibFlareFtsoSubParser.sol"; contract FlareFtsoWordsPointersTest is Test { diff --git a/test/src/concrete/FlareFtsoWords.sflrCurrentExchangeRate.t.sol b/test/src/concrete/FlareFtsoWords.sflrCurrentExchangeRate.t.sol index 8ff8768..7034e00 100644 --- a/test/src/concrete/FlareFtsoWords.sflrCurrentExchangeRate.t.sol +++ b/test/src/concrete/FlareFtsoWords.sflrCurrentExchangeRate.t.sol @@ -2,11 +2,11 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity =0.8.25; -import {OpTest, StackItem} from "rain.interpreter/../test/abstract/OpTest.sol"; +import {OpTest, StackItem} from "rainlang-0.1.1/src/../test/abstract/OpTest.sol"; import {FlareFtsoWords} from "src/concrete/FlareFtsoWords.sol"; import {LibFork} from "test/fork/LibFork.sol"; -import {Strings} from "openzeppelin-contracts/contracts/utils/Strings.sol"; -import {LibDecimalFloat, Float} from "rain.math.float/lib/LibDecimalFloat.sol"; +import {Strings} from "@openzeppelin-contracts-5.6.1/utils/Strings.sol"; +import {LibDecimalFloat, Float} from "rain-math-float-0.1.1/src/lib/LibDecimalFloat.sol"; uint256 constant BLOCK_NUMBER = 31843105; diff --git a/test/src/lib/flreth/LibDineroFlrEth.t.sol b/test/src/lib/flreth/LibDineroFlrEth.t.sol index 868d421..a0c33f6 100644 --- a/test/src/lib/flreth/LibDineroFlrEth.t.sol +++ b/test/src/lib/flreth/LibDineroFlrEth.t.sol @@ -2,7 +2,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity =0.8.25; -import {Test} from "forge-std/Test.sol"; +import {Test} from "forge-std-1.16.1/src/Test.sol"; import {LibFork} from "test/fork/LibFork.sol"; import {LibDineroFlrEth} from "src/lib/flreth/LibDineroFlrEth.sol"; diff --git a/test/src/lib/lts/LibFtsoV2LTS.t.sol b/test/src/lib/lts/LibFtsoV2LTS.t.sol index 4bcfbb2..9fc286c 100644 --- a/test/src/lib/lts/LibFtsoV2LTS.t.sol +++ b/test/src/lib/lts/LibFtsoV2LTS.t.sol @@ -2,7 +2,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity =0.8.25; -import {Test} from "forge-std/Test.sol"; +import {Test} from "forge-std-1.16.1/src/Test.sol"; import {LibFtsoV2LTS, ETH_USD_FEED_ID} from "src/lib/lts/LibFtsoV2LTS.sol"; import {BLOCK_NUMBER} from "../registry/LibFlareContractRegistry.t.sol"; import {LibFork} from "test/fork/LibFork.sol"; diff --git a/test/src/lib/op/LibOpFtsoCurrentPricePair.t.sol b/test/src/lib/op/LibOpFtsoCurrentPricePair.t.sol index 384253f..ad7ac64 100644 --- a/test/src/lib/op/LibOpFtsoCurrentPricePair.t.sol +++ b/test/src/lib/op/LibOpFtsoCurrentPricePair.t.sol @@ -4,11 +4,11 @@ pragma solidity =0.8.25; import {FtsoTest, OperandV2, StackItem, IFtso} from "../../../abstract/FtsoTest.sol"; import {LibOpFtsoCurrentPricePair} from "src/lib/op/LibOpFtsoCurrentPricePair.sol"; -import {LibIntOrAString, IntOrAString} from "rain.intorastring/lib/LibIntOrAString.sol"; +import {LibIntOrAString, IntOrAString} from "rain-intorastring-0.1.0/src/lib/LibIntOrAString.sol"; import {BLOCK_NUMBER} from "../registry/LibFlareContractRegistry.t.sol"; import {LibFork} from "test/fork/LibFork.sol"; import {InactiveFtso} from "src/err/ErrFtso.sol"; -import {LibDecimalFloat, Float} from "rain.math.float/lib/LibDecimalFloat.sol"; +import {LibDecimalFloat, Float} from "rain-math-float-0.1.1/src/lib/LibDecimalFloat.sol"; contract LibOpFtsoCurrentPricePairTest is FtsoTest { function externalRun(OperandV2 operand, StackItem[] memory inputs) @@ -31,8 +31,8 @@ contract LibOpFtsoCurrentPricePairTest is FtsoTest { vm.createSelectFork(LibFork.rpcUrlFlare(vm), BLOCK_NUMBER); StackItem[] memory inputs = new StackItem[](3); - inputs[0] = StackItem.wrap(bytes32(IntOrAString.unwrap(LibIntOrAString.fromString2("ETH")))); - inputs[1] = StackItem.wrap(bytes32(IntOrAString.unwrap(LibIntOrAString.fromString2("BTC")))); + inputs[0] = StackItem.wrap(bytes32(IntOrAString.unwrap(LibIntOrAString.fromStringV3("ETH")))); + inputs[1] = StackItem.wrap(bytes32(IntOrAString.unwrap(LibIntOrAString.fromStringV3("BTC")))); inputs[2] = StackItem.wrap(bytes32(uint256(3600))); StackItem[] memory outputs = this.externalRun(OperandV2.wrap(0), inputs); assertEq(outputs.length, 1); @@ -45,8 +45,8 @@ contract LibOpFtsoCurrentPricePairTest is FtsoTest { ) ); - inputs[0] = StackItem.wrap(bytes32(IntOrAString.unwrap(LibIntOrAString.fromString2("BTC")))); - inputs[1] = StackItem.wrap(bytes32(IntOrAString.unwrap(LibIntOrAString.fromString2("ETH")))); + inputs[0] = StackItem.wrap(bytes32(IntOrAString.unwrap(LibIntOrAString.fromStringV3("BTC")))); + inputs[1] = StackItem.wrap(bytes32(IntOrAString.unwrap(LibIntOrAString.fromStringV3("ETH")))); outputs = this.externalRun(OperandV2.wrap(0), inputs); assertEq(outputs.length, 1); assertEq( @@ -78,8 +78,8 @@ contract LibOpFtsoCurrentPricePairTest is FtsoTest { timeout = bound(timeout, 0, uint256(int256(type(int224).max))); warpNotStale(currentPriceB, timeout, currentTime); - uint256 intSymbolA = IntOrAString.unwrap(LibIntOrAString.fromString2(symbolA)); - uint256 intSymbolB = IntOrAString.unwrap(LibIntOrAString.fromString2(symbolB)); + uint256 intSymbolA = IntOrAString.unwrap(LibIntOrAString.fromStringV3(symbolA)); + uint256 intSymbolB = IntOrAString.unwrap(LibIntOrAString.fromStringV3(symbolB)); mockRegistry(2); mockFtsoRegistry(FTSO_A, symbolA); @@ -111,8 +111,8 @@ contract LibOpFtsoCurrentPricePairTest is FtsoTest { timeout = bound(timeout, 0, uint256(int256(type(int224).max))); - uint256 intSymbolA = IntOrAString.unwrap(LibIntOrAString.fromString2(symbolA)); - uint256 intSymbolB = IntOrAString.unwrap(LibIntOrAString.fromString2(symbolB)); + uint256 intSymbolA = IntOrAString.unwrap(LibIntOrAString.fromStringV3(symbolA)); + uint256 intSymbolB = IntOrAString.unwrap(LibIntOrAString.fromStringV3(symbolB)); mockRegistry(1); mockFtsoRegistry(FTSO_B, symbolB); diff --git a/test/src/lib/op/LibOpFtsoCurrentPriceUsd.t.sol b/test/src/lib/op/LibOpFtsoCurrentPriceUsd.t.sol index f8ca794..730693e 100644 --- a/test/src/lib/op/LibOpFtsoCurrentPriceUsd.t.sol +++ b/test/src/lib/op/LibOpFtsoCurrentPriceUsd.t.sol @@ -5,11 +5,11 @@ pragma solidity =0.8.25; import {FtsoTest, OperandV2, StackItem} from "../../../abstract/FtsoTest.sol"; import {LibOpFtsoCurrentPriceUsd} from "src/lib/op/LibOpFtsoCurrentPriceUsd.sol"; import {IFtso} from "src/lib/registry/LibFlareContractRegistry.sol"; -import {LibIntOrAString, IntOrAString} from "rain.intorastring/lib/LibIntOrAString.sol"; +import {LibIntOrAString, IntOrAString} from "rain-intorastring-0.1.0/src/lib/LibIntOrAString.sol"; import {LibFork} from "test/fork/LibFork.sol"; import {BLOCK_NUMBER} from "../registry/LibFlareContractRegistry.t.sol"; import {InactiveFtso, PriceNotFinalized, StalePrice, DecimalsTooLarge} from "src/err/ErrFtso.sol"; -import {LibDecimalFloat, Float} from "rain.math.float/lib/LibDecimalFloat.sol"; +import {LibDecimalFloat, Float} from "rain-math-float-0.1.1/src/lib/LibDecimalFloat.sol"; contract LibOpFtsoCurrentPriceUsdTest is FtsoTest { function externalRun(OperandV2 operand, StackItem[] memory inputs) @@ -32,25 +32,25 @@ contract LibOpFtsoCurrentPriceUsdTest is FtsoTest { vm.createSelectFork(LibFork.rpcUrlFlare(vm), BLOCK_NUMBER); StackItem[] memory inputs = new StackItem[](2); - inputs[0] = StackItem.wrap(bytes32(IntOrAString.unwrap(LibIntOrAString.fromString2("ETH")))); + inputs[0] = StackItem.wrap(bytes32(IntOrAString.unwrap(LibIntOrAString.fromStringV3("ETH")))); inputs[1] = StackItem.wrap(bytes32(uint256(3600))); StackItem[] memory outputs = this.externalRun(OperandV2.wrap(0), inputs); assertEq(outputs.length, 1); assertEq(StackItem.unwrap(outputs[0]), Float.unwrap(LibDecimalFloat.packLossless(2525.74849e5, -5))); - inputs[0] = StackItem.wrap(bytes32(IntOrAString.unwrap(LibIntOrAString.fromString2("BTC")))); + inputs[0] = StackItem.wrap(bytes32(IntOrAString.unwrap(LibIntOrAString.fromStringV3("BTC")))); outputs = this.externalRun(OperandV2.wrap(0), inputs); assertEq(outputs.length, 1); assertEq(StackItem.unwrap(outputs[0]), Float.unwrap(LibDecimalFloat.packLossless(67694.11308e5, -5))); - inputs[0] = StackItem.wrap(bytes32(IntOrAString.unwrap(LibIntOrAString.fromString2("XRP")))); + inputs[0] = StackItem.wrap(bytes32(IntOrAString.unwrap(LibIntOrAString.fromStringV3("XRP")))); outputs = this.externalRun(OperandV2.wrap(0), inputs); assertEq(outputs.length, 1); assertEq(StackItem.unwrap(outputs[0]), Float.unwrap(LibDecimalFloat.packLossless(0.53163e5, -5))); // USDT is interesting as it probably has different decimals to the // others, but should still get normalized to 18 decimals. - inputs[0] = StackItem.wrap(bytes32(IntOrAString.unwrap(LibIntOrAString.fromString2("USDT")))); + inputs[0] = StackItem.wrap(bytes32(IntOrAString.unwrap(LibIntOrAString.fromStringV3("USDT")))); outputs = this.externalRun(OperandV2.wrap(0), inputs); assertEq(outputs.length, 1); assertEq(StackItem.unwrap(outputs[0]), Float.unwrap(LibDecimalFloat.packLossless(0.99919e5, -5))); @@ -67,7 +67,7 @@ contract LibOpFtsoCurrentPriceUsdTest is FtsoTest { currentPrice.price = bound(currentPrice.price, 0, uint256(int256(type(int224).max))); currentPrice.decimals = bound(currentPrice.decimals, 0, type(uint8).max); vm.assume(bytes(symbol).length <= 31); - uint256 intSymbol = IntOrAString.unwrap(LibIntOrAString.fromString2(symbol)); + uint256 intSymbol = IntOrAString.unwrap(LibIntOrAString.fromStringV3(symbol)); timeout = bound(timeout, 0, uint256(int256(type(int224).max))); currentTime = warpNotStale(currentPrice, timeout, currentTime); @@ -102,7 +102,7 @@ contract LibOpFtsoCurrentPriceUsdTest is FtsoTest { CurrentPrice memory currentPrice ) external { vm.assume(bytes(symbol).length <= 31); - uint256 intSymbol = IntOrAString.unwrap(LibIntOrAString.fromString2(symbol)); + uint256 intSymbol = IntOrAString.unwrap(LibIntOrAString.fromStringV3(symbol)); currentPrice.decimals = bound(currentPrice.decimals, uint256(type(uint8).max) + 1, uint256(int256(type(int32).max))); currentPrice.price = bound(currentPrice.price, 0, uint256(int256(type(int224).max))); @@ -138,7 +138,7 @@ contract LibOpFtsoCurrentPriceUsdTest is FtsoTest { CurrentPrice memory currentPrice ) external { vm.assume(bytes(symbol).length <= 31); - uint256 intSymbol = IntOrAString.unwrap(LibIntOrAString.fromString2(symbol)); + uint256 intSymbol = IntOrAString.unwrap(LibIntOrAString.fromStringV3(symbol)); timeout = bound(timeout, 0, uint256(int256(type(int224).max))); currentPrice.timestamp = bound(currentPrice.timestamp, 0, type(uint256).max - timeout - 1); @@ -171,17 +171,14 @@ contract LibOpFtsoCurrentPriceUsdTest is FtsoTest { CurrentPrice memory currentPrice ) external { vm.assume(bytes(symbol).length <= 31); - uint256 intSymbol = IntOrAString.unwrap(LibIntOrAString.fromString2(symbol)); + uint256 intSymbol = IntOrAString.unwrap(LibIntOrAString.fromStringV3(symbol)); timeout = bound(timeout, 0, uint256(int256(type(int224).max))); conformPriceDetails(priceDetails, currentPrice); vm.assume( - !( - ( - priceDetails.priceFinalizationType == uint8(IFtso.PriceFinalizationType.WEIGHTED_MEDIAN) - || (priceDetails.priceFinalizationType == uint8(IFtso.PriceFinalizationType.TRUSTED_ADDRESSES)) - ) - ) + !((priceDetails.priceFinalizationType == uint8(IFtso.PriceFinalizationType.WEIGHTED_MEDIAN) + || (priceDetails.priceFinalizationType + == uint8(IFtso.PriceFinalizationType.TRUSTED_ADDRESSES)))) ); mockRegistry(); @@ -200,7 +197,7 @@ contract LibOpFtsoCurrentPriceUsdTest is FtsoTest { /// An inactive FTSO should revert. function testRunFtsoNotActive(OperandV2 operand, string memory symbol, uint256 timeout) external { vm.assume(bytes(symbol).length < 0x20); - uint256 intSymbol = IntOrAString.unwrap(LibIntOrAString.fromString2(symbol)); + uint256 intSymbol = IntOrAString.unwrap(LibIntOrAString.fromStringV3(symbol)); timeout = bound(timeout, 0, uint256(int256(type(int224).max))); mockRegistry(); diff --git a/test/src/lib/registry/LibFlareContractRegistry.t.sol b/test/src/lib/registry/LibFlareContractRegistry.t.sol index 84718f1..892ec5c 100644 --- a/test/src/lib/registry/LibFlareContractRegistry.t.sol +++ b/test/src/lib/registry/LibFlareContractRegistry.t.sol @@ -2,7 +2,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity =0.8.25; -import {Test} from "forge-std/Test.sol"; +import {Test} from "forge-std-1.16.1/src/Test.sol"; import {LibFork} from "test/fork/LibFork.sol"; import {LibFlareContractRegistry, IFtsoRegistry} from "src/lib/registry/LibFlareContractRegistry.sol"; diff --git a/test/src/lib/sflr/LibSceptreStakedFlare.t.sol b/test/src/lib/sflr/LibSceptreStakedFlare.t.sol index 70f7635..cf91014 100644 --- a/test/src/lib/sflr/LibSceptreStakedFlare.t.sol +++ b/test/src/lib/sflr/LibSceptreStakedFlare.t.sol @@ -2,7 +2,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity =0.8.25; -import {Test} from "forge-std/Test.sol"; +import {Test} from "forge-std-1.16.1/src/Test.sol"; import {LibFork} from "test/fork/LibFork.sol"; import {LibSceptreStakedFlare} from "src/lib/sflr/LibSceptreStakedFlare.sol";