From 1cb561a63822ab7b9cf0a14e00008907830404a9 Mon Sep 17 00:00:00 2001 From: PedroAraoz Date: Thu, 22 Jan 2026 16:54:28 -0300 Subject: [PATCH 1/6] evm: create mimic helper contract --- packages/evm/contracts/MimicHelper.sol | 31 ++++++++++++++++ .../evm/contracts/interfaces/IMimicHelper.sol | 14 ++++++++ packages/evm/test/MimicHelper.test.ts | 35 +++++++++++++++++++ yarn.lock | 31 ++++++++++++++-- 4 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 packages/evm/contracts/MimicHelper.sol create mode 100644 packages/evm/contracts/interfaces/IMimicHelper.sol create mode 100644 packages/evm/test/MimicHelper.test.ts diff --git a/packages/evm/contracts/MimicHelper.sol b/packages/evm/contracts/MimicHelper.sol new file mode 100644 index 0000000..bda69f0 --- /dev/null +++ b/packages/evm/contracts/MimicHelper.sol @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity ^0.8.20; + +import './interfaces/IMimicHelper.sol'; + +/** + * @title Mimic Helper + * @dev Collection of helper functions for the Mimic Protocol + */ +contract MimicHelper is IMimicHelper { + /** + * @dev Tells the native token balance of an address + * @param target Address to get native token balance + */ + function getNativeTokenBalance(address target) external view returns (uint256) { + return target.balance; + } +} diff --git a/packages/evm/contracts/interfaces/IMimicHelper.sol b/packages/evm/contracts/interfaces/IMimicHelper.sol new file mode 100644 index 0000000..3ab2a31 --- /dev/null +++ b/packages/evm/contracts/interfaces/IMimicHelper.sol @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.20; + +/** + * @title Helper interface + */ +interface IMimicHelper { + /** + * @dev Tells the native token balance of an address + * @param target Address to get native token balance + */ + function getNativeTokenBalance(address target) external view returns (uint256); +} diff --git a/packages/evm/test/MimicHelper.test.ts b/packages/evm/test/MimicHelper.test.ts new file mode 100644 index 0000000..a83664c --- /dev/null +++ b/packages/evm/test/MimicHelper.test.ts @@ -0,0 +1,35 @@ +import { randomEvmAddress } from '@mimicprotocol/sdk' +import { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/types' +import { expect } from 'chai' +import { network } from 'hardhat' + +import { MimicHelper } from '../types/ethers-contracts/index.js' + +const { ethers } = await network.connect() + +describe('MimicHelper', () => { + let mimicHelper: MimicHelper + let other: HardhatEthersSigner + + beforeEach('deploy mimic helper', async () => { + // eslint-disable-next-line prettier/prettier + [, other] = await ethers.getSigners() + mimicHelper = await ethers.deployContract('MimicHelper', []) + }) + + describe('getNativeTokenBalance', () => { + context('when the target has balance', () => { + it('returns the correct balance', async () => { + const balance = await mimicHelper.getNativeTokenBalance(other.address) + expect(balance).to.be.equal(10000000000000000000000n) + }) + }) + + context('when the target has no balance', () => { + it('returns 0', async () => { + const balance = await mimicHelper.getNativeTokenBalance(randomEvmAddress()) + expect(balance).to.be.equal(0) + }) + }) + }) +}) diff --git a/yarn.lock b/yarn.lock index 9081310..70bafcf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4009,7 +4009,16 @@ string-format@^2.0.0: resolved "https://registry.yarnpkg.com/string-format/-/string-format-2.0.0.tgz#f2df2e7097440d3b65de31b6d40d54c96eaffb9b" integrity sha512-bbEs3scLeYNXLecRRuk6uJxdXUSj6le/8rNPHChIJTn2V79aXVTR1EH2OH5zLKKoz0V02fOUKZZcw01pLUShZA== -"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0": + version "4.2.3" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + +string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -4066,7 +4075,14 @@ string_decoder@^1.1.1: dependencies: safe-buffer "~5.2.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1": + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + +strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -4504,7 +4520,16 @@ workerpool@^6.5.1: resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.5.1.tgz#060f73b39d0caf97c6db64da004cd01b4c099544" integrity sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + +wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== From 8f00b6626a32d533546eb552aa3033f7728ef83f Mon Sep 17 00:00:00 2001 From: PedroAraoz Date: Mon, 26 Jan 2026 12:02:36 -0300 Subject: [PATCH 2/6] evm: remove IMimicHelper --- packages/evm/contracts/MimicHelper.sol | 4 +--- packages/evm/contracts/interfaces/IMimicHelper.sol | 14 -------------- 2 files changed, 1 insertion(+), 17 deletions(-) delete mode 100644 packages/evm/contracts/interfaces/IMimicHelper.sol diff --git a/packages/evm/contracts/MimicHelper.sol b/packages/evm/contracts/MimicHelper.sol index bda69f0..272ddd5 100644 --- a/packages/evm/contracts/MimicHelper.sol +++ b/packages/evm/contracts/MimicHelper.sol @@ -14,13 +14,11 @@ pragma solidity ^0.8.20; -import './interfaces/IMimicHelper.sol'; - /** * @title Mimic Helper * @dev Collection of helper functions for the Mimic Protocol */ -contract MimicHelper is IMimicHelper { +contract MimicHelper { /** * @dev Tells the native token balance of an address * @param target Address to get native token balance diff --git a/packages/evm/contracts/interfaces/IMimicHelper.sol b/packages/evm/contracts/interfaces/IMimicHelper.sol deleted file mode 100644 index 3ab2a31..0000000 --- a/packages/evm/contracts/interfaces/IMimicHelper.sol +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.20; - -/** - * @title Helper interface - */ -interface IMimicHelper { - /** - * @dev Tells the native token balance of an address - * @param target Address to get native token balance - */ - function getNativeTokenBalance(address target) external view returns (uint256); -} From e19c16d96a472b1e9f4716a5add1997b2b2d1afa Mon Sep 17 00:00:00 2001 From: PedroAraoz Date: Mon, 26 Jan 2026 12:02:48 -0300 Subject: [PATCH 3/6] evm: add MimicHelper to deploy script --- packages/evm/scripts/deploy-contracts.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/evm/scripts/deploy-contracts.ts b/packages/evm/scripts/deploy-contracts.ts index e3206d8..bde34c1 100644 --- a/packages/evm/scripts/deploy-contracts.ts +++ b/packages/evm/scripts/deploy-contracts.ts @@ -4,6 +4,7 @@ import hre, { network } from 'hardhat' import type { Artifact } from 'hardhat/types/artifacts' import ControllerArtifact from '../artifacts/contracts/Controller.sol/Controller.json' +import MimicHelperArtifact from '../artifacts/contracts/MimicHelper.sol/MimicHelper.json' import SettlerArtifact from '../artifacts/contracts/Settler.sol/Settler.json' import SmartAccount7702 from '../artifacts/contracts/smart-accounts/SmartAccount7702.sol/SmartAccount7702.json' import buildCreate3Module from '../ignition/modules/Create3' @@ -21,6 +22,7 @@ async function main(): Promise { const controller = await deployCreate3(ControllerArtifact, controllerArgs, '0x17') const settler = await deployCreate3(SettlerArtifact, [controller.target, ADMIN], '0x18') await deployCreate3(SmartAccount7702, [settler.target], '0x19') + await deployCreate3(MimicHelperArtifact, [], '0x20') } // eslint-disable-next-line @typescript-eslint/no-explicit-any From 890eb74d00622c47c715ea9d339fa87306b4f86b Mon Sep 17 00:00:00 2001 From: Agustincito Date: Mon, 26 Jan 2026 15:53:33 -0300 Subject: [PATCH 4/6] Move MimicHelper --- packages/evm/contracts/{ => utils}/MimicHelper.sol | 0 packages/evm/test/{ => utils}/MimicHelper.test.ts | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename packages/evm/contracts/{ => utils}/MimicHelper.sol (100%) rename packages/evm/test/{ => utils}/MimicHelper.test.ts (100%) diff --git a/packages/evm/contracts/MimicHelper.sol b/packages/evm/contracts/utils/MimicHelper.sol similarity index 100% rename from packages/evm/contracts/MimicHelper.sol rename to packages/evm/contracts/utils/MimicHelper.sol diff --git a/packages/evm/test/MimicHelper.test.ts b/packages/evm/test/utils/MimicHelper.test.ts similarity index 100% rename from packages/evm/test/MimicHelper.test.ts rename to packages/evm/test/utils/MimicHelper.test.ts From a6f90d478e72f773b473003a683a84cf9e39bd8d Mon Sep 17 00:00:00 2001 From: Agustincito Date: Mon, 26 Jan 2026 15:58:23 -0300 Subject: [PATCH 5/6] Deploy --- .../Create3MimicHelper#ICreateX.dbg.json | 4 + .../Create3MimicHelper#ICreateX.json | 51 +++ .../Create3MimicHelper#MimicHelper.dbg.json | 4 + .../Create3MimicHelper#MimicHelper.json | 33 ++ ...0d0a8e9df290d290e91b2999a1f7443c2b528.json | 290 ++++++++++++++++++ .../chain-1/deployed_addresses.json | 4 +- .../deployments/chain-1/journal.jsonl | 11 +- .../Create3MimicHelper#ICreateX.dbg.json | 4 + .../Create3MimicHelper#ICreateX.json | 51 +++ .../Create3MimicHelper#MimicHelper.dbg.json | 4 + .../Create3MimicHelper#MimicHelper.json | 33 ++ ...0d0a8e9df290d290e91b2999a1f7443c2b528.json | 290 ++++++++++++++++++ .../chain-10/deployed_addresses.json | 4 +- .../deployments/chain-10/journal.jsonl | 11 +- .../Create3MimicHelper#ICreateX.dbg.json | 4 + .../Create3MimicHelper#ICreateX.json | 51 +++ .../Create3MimicHelper#MimicHelper.dbg.json | 4 + .../Create3MimicHelper#MimicHelper.json | 33 ++ ...0d0a8e9df290d290e91b2999a1f7443c2b528.json | 290 ++++++++++++++++++ .../chain-100/deployed_addresses.json | 4 +- .../deployments/chain-100/journal.jsonl | 11 +- .../Create3MimicHelper#ICreateX.dbg.json | 4 + .../Create3MimicHelper#ICreateX.json | 51 +++ .../Create3MimicHelper#MimicHelper.dbg.json | 4 + .../Create3MimicHelper#MimicHelper.json | 33 ++ ...0d0a8e9df290d290e91b2999a1f7443c2b528.json | 290 ++++++++++++++++++ .../chain-146/deployed_addresses.json | 4 +- .../deployments/chain-146/journal.jsonl | 11 +- .../Create3MimicHelper#ICreateX.dbg.json | 4 + .../Create3MimicHelper#ICreateX.json | 51 +++ .../Create3MimicHelper#MimicHelper.dbg.json | 4 + .../Create3MimicHelper#MimicHelper.json | 33 ++ ...0d0a8e9df290d290e91b2999a1f7443c2b528.json | 290 ++++++++++++++++++ .../chain-42161/deployed_addresses.json | 4 +- .../deployments/chain-42161/journal.jsonl | 11 +- .../Create3MimicHelper#ICreateX.dbg.json | 4 + .../Create3MimicHelper#ICreateX.json | 51 +++ .../Create3MimicHelper#MimicHelper.dbg.json | 4 + .../Create3MimicHelper#MimicHelper.json | 33 ++ ...0d0a8e9df290d290e91b2999a1f7443c2b528.json | 290 ++++++++++++++++++ .../chain-8453/deployed_addresses.json | 4 +- .../deployments/chain-8453/journal.jsonl | 11 +- .../Create3MimicHelper#ICreateX.dbg.json | 4 + .../Create3MimicHelper#ICreateX.json | 51 +++ .../Create3MimicHelper#MimicHelper.dbg.json | 4 + .../Create3MimicHelper#MimicHelper.json | 33 ++ ...0d0a8e9df290d290e91b2999a1f7443c2b528.json | 290 ++++++++++++++++++ .../chain-84532/deployed_addresses.json | 4 +- .../deployments/chain-84532/journal.jsonl | 11 +- packages/evm/scripts/deploy-contracts.ts | 25 +- 50 files changed, 2777 insertions(+), 27 deletions(-) create mode 100644 packages/evm/ignition/deployments/chain-1/artifacts/Create3MimicHelper#ICreateX.dbg.json create mode 100644 packages/evm/ignition/deployments/chain-1/artifacts/Create3MimicHelper#ICreateX.json create mode 100644 packages/evm/ignition/deployments/chain-1/artifacts/Create3MimicHelper#MimicHelper.dbg.json create mode 100644 packages/evm/ignition/deployments/chain-1/artifacts/Create3MimicHelper#MimicHelper.json create mode 100644 packages/evm/ignition/deployments/chain-1/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json create mode 100644 packages/evm/ignition/deployments/chain-10/artifacts/Create3MimicHelper#ICreateX.dbg.json create mode 100644 packages/evm/ignition/deployments/chain-10/artifacts/Create3MimicHelper#ICreateX.json create mode 100644 packages/evm/ignition/deployments/chain-10/artifacts/Create3MimicHelper#MimicHelper.dbg.json create mode 100644 packages/evm/ignition/deployments/chain-10/artifacts/Create3MimicHelper#MimicHelper.json create mode 100644 packages/evm/ignition/deployments/chain-10/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json create mode 100644 packages/evm/ignition/deployments/chain-100/artifacts/Create3MimicHelper#ICreateX.dbg.json create mode 100644 packages/evm/ignition/deployments/chain-100/artifacts/Create3MimicHelper#ICreateX.json create mode 100644 packages/evm/ignition/deployments/chain-100/artifacts/Create3MimicHelper#MimicHelper.dbg.json create mode 100644 packages/evm/ignition/deployments/chain-100/artifacts/Create3MimicHelper#MimicHelper.json create mode 100644 packages/evm/ignition/deployments/chain-100/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json create mode 100644 packages/evm/ignition/deployments/chain-146/artifacts/Create3MimicHelper#ICreateX.dbg.json create mode 100644 packages/evm/ignition/deployments/chain-146/artifacts/Create3MimicHelper#ICreateX.json create mode 100644 packages/evm/ignition/deployments/chain-146/artifacts/Create3MimicHelper#MimicHelper.dbg.json create mode 100644 packages/evm/ignition/deployments/chain-146/artifacts/Create3MimicHelper#MimicHelper.json create mode 100644 packages/evm/ignition/deployments/chain-146/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json create mode 100644 packages/evm/ignition/deployments/chain-42161/artifacts/Create3MimicHelper#ICreateX.dbg.json create mode 100644 packages/evm/ignition/deployments/chain-42161/artifacts/Create3MimicHelper#ICreateX.json create mode 100644 packages/evm/ignition/deployments/chain-42161/artifacts/Create3MimicHelper#MimicHelper.dbg.json create mode 100644 packages/evm/ignition/deployments/chain-42161/artifacts/Create3MimicHelper#MimicHelper.json create mode 100644 packages/evm/ignition/deployments/chain-42161/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json create mode 100644 packages/evm/ignition/deployments/chain-8453/artifacts/Create3MimicHelper#ICreateX.dbg.json create mode 100644 packages/evm/ignition/deployments/chain-8453/artifacts/Create3MimicHelper#ICreateX.json create mode 100644 packages/evm/ignition/deployments/chain-8453/artifacts/Create3MimicHelper#MimicHelper.dbg.json create mode 100644 packages/evm/ignition/deployments/chain-8453/artifacts/Create3MimicHelper#MimicHelper.json create mode 100644 packages/evm/ignition/deployments/chain-8453/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json create mode 100644 packages/evm/ignition/deployments/chain-84532/artifacts/Create3MimicHelper#ICreateX.dbg.json create mode 100644 packages/evm/ignition/deployments/chain-84532/artifacts/Create3MimicHelper#ICreateX.json create mode 100644 packages/evm/ignition/deployments/chain-84532/artifacts/Create3MimicHelper#MimicHelper.dbg.json create mode 100644 packages/evm/ignition/deployments/chain-84532/artifacts/Create3MimicHelper#MimicHelper.json create mode 100644 packages/evm/ignition/deployments/chain-84532/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json diff --git a/packages/evm/ignition/deployments/chain-1/artifacts/Create3MimicHelper#ICreateX.dbg.json b/packages/evm/ignition/deployments/chain-1/artifacts/Create3MimicHelper#ICreateX.dbg.json new file mode 100644 index 0000000..817dddf --- /dev/null +++ b/packages/evm/ignition/deployments/chain-1/artifacts/Create3MimicHelper#ICreateX.dbg.json @@ -0,0 +1,4 @@ +{ + "_format": "hh-sol-dbg-1", + "buildInfo": "../build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-1/artifacts/Create3MimicHelper#ICreateX.json b/packages/evm/ignition/deployments/chain-1/artifacts/Create3MimicHelper#ICreateX.json new file mode 100644 index 0000000..a4701c6 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-1/artifacts/Create3MimicHelper#ICreateX.json @@ -0,0 +1,51 @@ +{ + "_format": "hh3-artifact-1", + "contractName": "ICreateX", + "sourceName": "contracts/interfaces/ICreateX.sol", + "abi": [ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "newContract", + "type": "address" + } + ], + "name": "ContractCreation", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "salt", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "initCode", + "type": "bytes" + } + ], + "name": "deployCreate3", + "outputs": [ + { + "internalType": "address", + "name": "newContract", + "type": "address" + } + ], + "stateMutability": "payable", + "type": "function" + } + ], + "bytecode": "0x", + "deployedBytecode": "0x", + "linkReferences": {}, + "deployedLinkReferences": {}, + "immutableReferences": {}, + "inputSourceName": "project/contracts/interfaces/ICreateX.sol", + "buildInfoId": "b650d0a8e9df290d290e91b2999a1f7443c2b528" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-1/artifacts/Create3MimicHelper#MimicHelper.dbg.json b/packages/evm/ignition/deployments/chain-1/artifacts/Create3MimicHelper#MimicHelper.dbg.json new file mode 100644 index 0000000..817dddf --- /dev/null +++ b/packages/evm/ignition/deployments/chain-1/artifacts/Create3MimicHelper#MimicHelper.dbg.json @@ -0,0 +1,4 @@ +{ + "_format": "hh-sol-dbg-1", + "buildInfo": "../build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-1/artifacts/Create3MimicHelper#MimicHelper.json b/packages/evm/ignition/deployments/chain-1/artifacts/Create3MimicHelper#MimicHelper.json new file mode 100644 index 0000000..a01b577 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-1/artifacts/Create3MimicHelper#MimicHelper.json @@ -0,0 +1,33 @@ +{ + "_format": "hh3-artifact-1", + "contractName": "MimicHelper", + "sourceName": "contracts/utils/MimicHelper.sol", + "abi": [ + { + "inputs": [ + { + "internalType": "address", + "name": "target", + "type": "address" + } + ], + "name": "getNativeTokenBalance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + } + ], + "bytecode": "0x6080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033", + "deployedBytecode": "0x6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033", + "linkReferences": {}, + "deployedLinkReferences": {}, + "immutableReferences": {}, + "inputSourceName": "project/contracts/utils/MimicHelper.sol", + "buildInfoId": "b650d0a8e9df290d290e91b2999a1f7443c2b528" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-1/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json b/packages/evm/ignition/deployments/chain-1/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json new file mode 100644 index 0000000..657a777 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-1/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json @@ -0,0 +1,290 @@ +{ + "_format": "hh3-sol-build-info-1", + "id": "b650d0a8e9df290d290e91b2999a1f7443c2b528", + "solcVersion": "0.8.28", + "solcLongVersion": "0.8.28+commit.7893614a", + "userSourceNameMap": { + "contracts/Controller.sol": "project/contracts/Controller.sol", + "contracts/Intents.sol": "project/contracts/Intents.sol", + "contracts/Settler.sol": "project/contracts/Settler.sol", + "contracts/interfaces/IController.sol": "project/contracts/interfaces/IController.sol", + "contracts/interfaces/ICreateX.sol": "project/contracts/interfaces/ICreateX.sol", + "contracts/interfaces/IExecutor.sol": "project/contracts/interfaces/IExecutor.sol", + "contracts/interfaces/IIntentsValidator.sol": "project/contracts/interfaces/IIntentsValidator.sol", + "contracts/interfaces/ISafe.sol": "project/contracts/interfaces/ISafe.sol", + "contracts/interfaces/ISettler.sol": "project/contracts/interfaces/ISettler.sol", + "contracts/interfaces/ISmartAccount.sol": "project/contracts/interfaces/ISmartAccount.sol", + "contracts/interfaces/ISmartAccountContract.sol": "project/contracts/interfaces/ISmartAccountContract.sol", + "contracts/interfaces/ISmartAccountsHandler.sol": "project/contracts/interfaces/ISmartAccountsHandler.sol", + "contracts/safeguards/BaseIntentsValidator.sol": "project/contracts/safeguards/BaseIntentsValidator.sol", + "contracts/safeguards/CallIntentsValidator.sol": "project/contracts/safeguards/CallIntentsValidator.sol", + "contracts/safeguards/IntentsValidator.sol": "project/contracts/safeguards/IntentsValidator.sol", + "contracts/safeguards/Safeguards.sol": "project/contracts/safeguards/Safeguards.sol", + "contracts/safeguards/SwapIntentsValidator.sol": "project/contracts/safeguards/SwapIntentsValidator.sol", + "contracts/safeguards/TransferIntentsValidator.sol": "project/contracts/safeguards/TransferIntentsValidator.sol", + "contracts/smart-accounts/SmartAccount7702.sol": "project/contracts/smart-accounts/SmartAccount7702.sol", + "contracts/smart-accounts/SmartAccountBase.sol": "project/contracts/smart-accounts/SmartAccountBase.sol", + "contracts/smart-accounts/SmartAccountContract.sol": "project/contracts/smart-accounts/SmartAccountContract.sol", + "contracts/smart-accounts/SmartAccountsHandler.sol": "project/contracts/smart-accounts/SmartAccountsHandler.sol", + "contracts/smart-accounts/SmartAccountsHandlerHelpers.sol": "project/contracts/smart-accounts/SmartAccountsHandlerHelpers.sol", + "contracts/test/CallMock.sol": "project/contracts/test/CallMock.sol", + "contracts/test/TokenMock.sol": "project/contracts/test/TokenMock.sol", + "contracts/test/executors/EmptyExecutorMock.sol": "project/contracts/test/executors/EmptyExecutorMock.sol", + "contracts/test/executors/MintExecutorMock.sol": "project/contracts/test/executors/MintExecutorMock.sol", + "contracts/test/executors/ReentrantExecutorMock.sol": "project/contracts/test/executors/ReentrantExecutorMock.sol", + "contracts/test/executors/TransferExecutorMock.sol": "project/contracts/test/executors/TransferExecutorMock.sol", + "contracts/test/smart-accounts/SafeMock.sol": "project/contracts/test/smart-accounts/SafeMock.sol", + "contracts/test/utils/DenominationsMock.sol": "project/contracts/test/utils/DenominationsMock.sol", + "contracts/test/utils/ERC20HelpersMock.sol": "project/contracts/test/utils/ERC20HelpersMock.sol", + "contracts/utils/Denominations.sol": "project/contracts/utils/Denominations.sol", + "contracts/utils/ERC20Helpers.sol": "project/contracts/utils/ERC20Helpers.sol", + "contracts/utils/MimicHelper.sol": "project/contracts/utils/MimicHelper.sol" + }, + "input": { + "language": "Solidity", + "settings": { + "optimizer": { + "enabled": true, + "runs": 1000 + }, + "evmVersion": "cancun", + "outputSelection": { + "*": { + "": [ + "ast" + ], + "*": [ + "abi", + "evm.bytecode", + "evm.deployedBytecode", + "evm.methodIdentifiers", + "metadata" + ] + } + }, + "remappings": [ + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/" + ] + }, + "sources": { + "npm/@openzeppelin/contracts@5.3.0/access/Ownable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)\n\npragma solidity ^0.8.20;\n\nimport {Context} from \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * The initial owner is set to the address provided by the deployer. This can\n * later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n /**\n * @dev The caller account is not authorized to perform an operation.\n */\n error OwnableUnauthorizedAccount(address account);\n\n /**\n * @dev The owner is not a valid owner account. (eg. `address(0)`)\n */\n error OwnableInvalidOwner(address owner);\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the address provided by the deployer as the initial owner.\n */\n constructor(address initialOwner) {\n if (initialOwner == address(0)) {\n revert OwnableInvalidOwner(address(0));\n }\n _transferOwnership(initialOwner);\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n if (owner() != _msgSender()) {\n revert OwnableUnauthorizedAccount(_msgSender());\n }\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby disabling any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n if (newOwner == address(0)) {\n revert OwnableInvalidOwner(address(0));\n }\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/draft-IERC6093.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol)\npragma solidity ^0.8.20;\n\n/**\n * @dev Standard ERC-20 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.\n */\ninterface IERC20Errors {\n /**\n * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param balance Current balance for the interacting account.\n * @param needed Minimum amount required to perform a transfer.\n */\n error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC20InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC20InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.\n * @param spender Address that may be allowed to operate on tokens without being their owner.\n * @param allowance Amount of tokens a `spender` is allowed to operate with.\n * @param needed Minimum amount required to perform a transfer.\n */\n error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC20InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `spender` to be approved. Used in approvals.\n * @param spender Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC20InvalidSpender(address spender);\n}\n\n/**\n * @dev Standard ERC-721 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.\n */\ninterface IERC721Errors {\n /**\n * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.\n * Used in balance queries.\n * @param owner Address of the current owner of a token.\n */\n error ERC721InvalidOwner(address owner);\n\n /**\n * @dev Indicates a `tokenId` whose `owner` is the zero address.\n * @param tokenId Identifier number of a token.\n */\n error ERC721NonexistentToken(uint256 tokenId);\n\n /**\n * @dev Indicates an error related to the ownership over a particular token. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param tokenId Identifier number of a token.\n * @param owner Address of the current owner of a token.\n */\n error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC721InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC721InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n * @param tokenId Identifier number of a token.\n */\n error ERC721InsufficientApproval(address operator, uint256 tokenId);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC721InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC721InvalidOperator(address operator);\n}\n\n/**\n * @dev Standard ERC-1155 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.\n */\ninterface IERC1155Errors {\n /**\n * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param balance Current balance for the interacting account.\n * @param needed Minimum amount required to perform a transfer.\n * @param tokenId Identifier number of a token.\n */\n error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC1155InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC1155InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n * @param owner Address of the current owner of a token.\n */\n error ERC1155MissingApprovalForAll(address operator, address owner);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC1155InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC1155InvalidOperator(address operator);\n\n /**\n * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.\n * Used in batch transfers.\n * @param idsLength Length of the array of token identifiers\n * @param valuesLength Length of the array of token amounts\n */\n error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC1271.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (interfaces/IERC1271.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-1271 standard signature validation method for\n * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].\n */\ninterface IERC1271 {\n /**\n * @dev Should return whether the signature provided is valid for the provided data\n * @param hash Hash of the data to be signed\n * @param signature Signature byte array associated with `hash`\n */\n function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC1363.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"./IERC20.sol\";\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @title IERC1363\n * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].\n *\n * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract\n * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.\n */\ninterface IERC1363 is IERC20, IERC165 {\n /*\n * Note: the ERC-165 identifier for this interface is 0xb0202a11.\n * 0xb0202a11 ===\n * bytes4(keccak256('transferAndCall(address,uint256)')) ^\n * bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^\n * bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^\n * bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^\n * bytes4(keccak256('approveAndCall(address,uint256)')) ^\n * bytes4(keccak256('approveAndCall(address,uint256,bytes)'))\n */\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferAndCall(address to, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @param data Additional data with no specified format, sent in call to `to`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param from The address which you want to send tokens from.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferFromAndCall(address from, address to, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param from The address which you want to send tokens from.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @param data Additional data with no specified format, sent in call to `to`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.\n * @param spender The address which will spend the funds.\n * @param value The amount of tokens to be spent.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function approveAndCall(address spender, uint256 value) external returns (bool);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.\n * @param spender The address which will spend the funds.\n * @param value The amount of tokens to be spent.\n * @param data Additional data with no specified format, sent in call to `spender`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"../utils/introspection/IERC165.sol\";\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../token/ERC20/IERC20.sol\";\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC5267.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)\n\npragma solidity ^0.8.20;\n\ninterface IERC5267 {\n /**\n * @dev MAY be emitted to signal that the domain could have changed.\n */\n event EIP712DomainChanged();\n\n /**\n * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712\n * signature.\n */\n function eip712Domain()\n external\n view\n returns (\n bytes1 fields,\n string memory name,\n string memory version,\n uint256 chainId,\n address verifyingContract,\n bytes32 salt,\n uint256[] memory extensions\n );\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/ERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"./IERC20.sol\";\nimport {IERC20Metadata} from \"./extensions/IERC20Metadata.sol\";\nimport {Context} from \"../../utils/Context.sol\";\nimport {IERC20Errors} from \"../../interfaces/draft-IERC6093.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * The default value of {decimals} is 18. To change this, you should override\n * this function so it returns a different value.\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC-20\n * applications.\n */\nabstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {\n mapping(address account => uint256) private _balances;\n\n mapping(address account => mapping(address spender => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * Both values are immutable: they can only be set once during construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the default value returned by this function, unless\n * it's overridden.\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `value`.\n */\n function transfer(address to, uint256 value) public virtual returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, value);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 value) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, value);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Skips emitting an {Approval} event indicating an allowance update. This is not\n * required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `value`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `value`.\n */\n function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, value);\n _transfer(from, to, value);\n return true;\n }\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead.\n */\n function _transfer(address from, address to, uint256 value) internal {\n if (from == address(0)) {\n revert ERC20InvalidSender(address(0));\n }\n if (to == address(0)) {\n revert ERC20InvalidReceiver(address(0));\n }\n _update(from, to, value);\n }\n\n /**\n * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`\n * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding\n * this function.\n *\n * Emits a {Transfer} event.\n */\n function _update(address from, address to, uint256 value) internal virtual {\n if (from == address(0)) {\n // Overflow check required: The rest of the code assumes that totalSupply never overflows\n _totalSupply += value;\n } else {\n uint256 fromBalance = _balances[from];\n if (fromBalance < value) {\n revert ERC20InsufficientBalance(from, fromBalance, value);\n }\n unchecked {\n // Overflow not possible: value <= fromBalance <= totalSupply.\n _balances[from] = fromBalance - value;\n }\n }\n\n if (to == address(0)) {\n unchecked {\n // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.\n _totalSupply -= value;\n }\n } else {\n unchecked {\n // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.\n _balances[to] += value;\n }\n }\n\n emit Transfer(from, to, value);\n }\n\n /**\n * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).\n * Relies on the `_update` mechanism\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead.\n */\n function _mint(address account, uint256 value) internal {\n if (account == address(0)) {\n revert ERC20InvalidReceiver(address(0));\n }\n _update(address(0), account, value);\n }\n\n /**\n * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.\n * Relies on the `_update` mechanism.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead\n */\n function _burn(address account, uint256 value) internal {\n if (account == address(0)) {\n revert ERC20InvalidSender(address(0));\n }\n _update(account, address(0), value);\n }\n\n /**\n * @dev Sets `value` as the allowance of `spender` over the `owner`'s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n *\n * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.\n */\n function _approve(address owner, address spender, uint256 value) internal {\n _approve(owner, spender, value, true);\n }\n\n /**\n * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.\n *\n * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by\n * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any\n * `Approval` event during `transferFrom` operations.\n *\n * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to\n * true using the following override:\n *\n * ```solidity\n * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {\n * super._approve(owner, spender, value, true);\n * }\n * ```\n *\n * Requirements are the same as {_approve}.\n */\n function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {\n if (owner == address(0)) {\n revert ERC20InvalidApprover(address(0));\n }\n if (spender == address(0)) {\n revert ERC20InvalidSpender(address(0));\n }\n _allowances[owner][spender] = value;\n if (emitEvent) {\n emit Approval(owner, spender, value);\n }\n }\n\n /**\n * @dev Updates `owner`'s allowance for `spender` based on spent `value`.\n *\n * Does not update the allowance value in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Does not emit an {Approval} event.\n */\n function _spendAllowance(address owner, address spender, uint256 value) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance < type(uint256).max) {\n if (currentAllowance < value) {\n revert ERC20InsufficientAllowance(spender, currentAllowance, value);\n }\n unchecked {\n _approve(owner, spender, currentAllowance - value, false);\n }\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/extensions/IERC20Metadata.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC-20 standard.\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-20 standard as defined in the ERC.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the value of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the value of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 value) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the\n * allowance mechanism. `value` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(address from, address to, uint256 value) external returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/utils/SafeERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../IERC20.sol\";\nimport {IERC1363} from \"../../../interfaces/IERC1363.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC-20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n /**\n * @dev An operation with an ERC-20 token failed.\n */\n error SafeERC20FailedOperation(address token);\n\n /**\n * @dev Indicates a failed `decreaseAllowance` request.\n */\n error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);\n\n /**\n * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,\n * non-reverting calls are assumed to be successful.\n */\n function safeTransfer(IERC20 token, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));\n }\n\n /**\n * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the\n * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.\n */\n function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));\n }\n\n /**\n * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.\n */\n function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {\n return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));\n }\n\n /**\n * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.\n */\n function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {\n return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));\n }\n\n /**\n * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n * non-reverting calls are assumed to be successful.\n *\n * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the \"client\"\n * smart contract uses ERC-7674 to set temporary allowances, then the \"client\" smart contract should avoid using\n * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract\n * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.\n */\n function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n uint256 oldAllowance = token.allowance(address(this), spender);\n forceApprove(token, spender, oldAllowance + value);\n }\n\n /**\n * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no\n * value, non-reverting calls are assumed to be successful.\n *\n * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the \"client\"\n * smart contract uses ERC-7674 to set temporary allowances, then the \"client\" smart contract should avoid using\n * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract\n * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.\n */\n function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {\n unchecked {\n uint256 currentAllowance = token.allowance(address(this), spender);\n if (currentAllowance < requestedDecrease) {\n revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);\n }\n forceApprove(token, spender, currentAllowance - requestedDecrease);\n }\n }\n\n /**\n * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,\n * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval\n * to be set to zero before setting it to a non-zero value, such as USDT.\n *\n * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function\n * only sets the \"standard\" allowance. Any temporary allowance will remain active, in addition to the value being\n * set here.\n */\n function forceApprove(IERC20 token, address spender, uint256 value) internal {\n bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));\n\n if (!_callOptionalReturnBool(token, approvalCall)) {\n _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));\n _callOptionalReturn(token, approvalCall);\n }\n }\n\n /**\n * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no\n * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * Reverts if the returned value is other than `true`.\n */\n function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {\n if (to.code.length == 0) {\n safeTransfer(token, to, value);\n } else if (!token.transferAndCall(to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target\n * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * Reverts if the returned value is other than `true`.\n */\n function transferFromAndCallRelaxed(\n IERC1363 token,\n address from,\n address to,\n uint256 value,\n bytes memory data\n ) internal {\n if (to.code.length == 0) {\n safeTransferFrom(token, from, to, value);\n } else if (!token.transferFromAndCall(from, to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no\n * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.\n * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}\n * once without retrying, and relies on the returned value to be true.\n *\n * Reverts if the returned value is other than `true`.\n */\n function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {\n if (to.code.length == 0) {\n forceApprove(token, to, value);\n } else if (!token.approveAndCall(to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n *\n * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.\n */\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)\n // bubble errors\n if iszero(success) {\n let ptr := mload(0x40)\n returndatacopy(ptr, 0, returndatasize())\n revert(ptr, returndatasize())\n }\n returnSize := returndatasize()\n returnValue := mload(0)\n }\n\n if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n *\n * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.\n */\n function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {\n bool success;\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)\n returnSize := returndatasize()\n returnValue := mload(0)\n }\n return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Address.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.2.0) (utils/Address.sol)\n\npragma solidity ^0.8.20;\n\nimport {Errors} from \"./Errors.sol\";\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev There's no code at `target` (it is not a contract).\n */\n error AddressEmptyCode(address target);\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n if (address(this).balance < amount) {\n revert Errors.InsufficientBalance(address(this).balance, amount);\n }\n\n (bool success, bytes memory returndata) = recipient.call{value: amount}(\"\");\n if (!success) {\n _revert(returndata);\n }\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason or custom error, it is bubbled\n * up by this function (like regular Solidity function calls). However, if\n * the call reverted with no returned reason, this function reverts with a\n * {Errors.FailedCall} error.\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n */\n function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n if (address(this).balance < value) {\n revert Errors.InsufficientBalance(address(this).balance, value);\n }\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target\n * was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case\n * of an unsuccessful call.\n */\n function verifyCallResultFromTarget(\n address target,\n bool success,\n bytes memory returndata\n ) internal view returns (bytes memory) {\n if (!success) {\n _revert(returndata);\n } else {\n // only check if target is a contract if the call was successful and the return data is empty\n // otherwise we already know that it was a contract\n if (returndata.length == 0 && target.code.length == 0) {\n revert AddressEmptyCode(target);\n }\n return returndata;\n }\n }\n\n /**\n * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the\n * revert reason or with a default {Errors.FailedCall} error.\n */\n function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {\n if (!success) {\n _revert(returndata);\n } else {\n return returndata;\n }\n }\n\n /**\n * @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.\n */\n function _revert(bytes memory returndata) private pure {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n assembly (\"memory-safe\") {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert Errors.FailedCall();\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Context.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n\n function _contextSuffixLength() internal view virtual returns (uint256) {\n return 0;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/ECDSA.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/ECDSA.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.\n *\n * These functions can be used to verify that a message was signed by the holder\n * of the private keys of a given address.\n */\nlibrary ECDSA {\n enum RecoverError {\n NoError,\n InvalidSignature,\n InvalidSignatureLength,\n InvalidSignatureS\n }\n\n /**\n * @dev The signature derives the `address(0)`.\n */\n error ECDSAInvalidSignature();\n\n /**\n * @dev The signature has an invalid length.\n */\n error ECDSAInvalidSignatureLength(uint256 length);\n\n /**\n * @dev The signature has an S value that is in the upper half order.\n */\n error ECDSAInvalidSignatureS(bytes32 s);\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not\n * return address(0) without also returning an error description. Errors are documented using an enum (error type)\n * and a bytes32 providing additional information about the error.\n *\n * If no error is returned, then the address can be used for verification purposes.\n *\n * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.\n *\n * Documentation for signature generation:\n * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]\n * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]\n */\n function tryRecover(\n bytes32 hash,\n bytes memory signature\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n if (signature.length == 65) {\n bytes32 r;\n bytes32 s;\n uint8 v;\n // ecrecover takes the signature parameters, and the only way to get them\n // currently is to use assembly.\n assembly (\"memory-safe\") {\n r := mload(add(signature, 0x20))\n s := mload(add(signature, 0x40))\n v := byte(0, mload(add(signature, 0x60)))\n }\n return tryRecover(hash, v, r, s);\n } else {\n return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));\n }\n }\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with\n * `signature`. This address can then be used for verification purposes.\n *\n * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.\n */\n function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.\n *\n * See https://eips.ethereum.org/EIPS/eip-2098[ERC-2098 short signatures]\n */\n function tryRecover(\n bytes32 hash,\n bytes32 r,\n bytes32 vs\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n unchecked {\n bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n // We do not check for an overflow here since the shift operation results in 0 or 1.\n uint8 v = uint8((uint256(vs) >> 255) + 27);\n return tryRecover(hash, v, r, s);\n }\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\n */\n function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function tryRecover(\n bytes32 hash,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\n // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\n // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\n // signatures from current libraries generate a unique signature with an s-value in the lower half order.\n //\n // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\n // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\n // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\n // these malleable signatures as well.\n if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\n return (address(0), RecoverError.InvalidSignatureS, s);\n }\n\n // If the signature is valid (and not malleable), return the signer address\n address signer = ecrecover(hash, v, r, s);\n if (signer == address(0)) {\n return (address(0), RecoverError.InvalidSignature, bytes32(0));\n }\n\n return (signer, RecoverError.NoError, bytes32(0));\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.\n */\n function _throwError(RecoverError error, bytes32 errorArg) private pure {\n if (error == RecoverError.NoError) {\n return; // no error: do nothing\n } else if (error == RecoverError.InvalidSignature) {\n revert ECDSAInvalidSignature();\n } else if (error == RecoverError.InvalidSignatureLength) {\n revert ECDSAInvalidSignatureLength(uint256(errorArg));\n } else if (error == RecoverError.InvalidSignatureS) {\n revert ECDSAInvalidSignatureS(errorArg);\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/EIP712.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/EIP712.sol)\n\npragma solidity ^0.8.20;\n\nimport {MessageHashUtils} from \"./MessageHashUtils.sol\";\nimport {ShortStrings, ShortString} from \"../ShortStrings.sol\";\nimport {IERC5267} from \"../../interfaces/IERC5267.sol\";\n\n/**\n * @dev https://eips.ethereum.org/EIPS/eip-712[EIP-712] is a standard for hashing and signing of typed structured data.\n *\n * The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose\n * encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract\n * does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to\n * produce the hash of their typed data using a combination of `abi.encode` and `keccak256`.\n *\n * This contract implements the EIP-712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding\n * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA\n * ({_hashTypedDataV4}).\n *\n * The implementation of the domain separator was designed to be as efficient as possible while still properly updating\n * the chain id to protect against replay attacks on an eventual fork of the chain.\n *\n * NOTE: This contract implements the version of the encoding known as \"v4\", as implemented by the JSON RPC method\n * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].\n *\n * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain\n * separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the\n * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.\n *\n * @custom:oz-upgrades-unsafe-allow state-variable-immutable\n */\nabstract contract EIP712 is IERC5267 {\n using ShortStrings for *;\n\n bytes32 private constant TYPE_HASH =\n keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\");\n\n // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to\n // invalidate the cached domain separator if the chain id changes.\n bytes32 private immutable _cachedDomainSeparator;\n uint256 private immutable _cachedChainId;\n address private immutable _cachedThis;\n\n bytes32 private immutable _hashedName;\n bytes32 private immutable _hashedVersion;\n\n ShortString private immutable _name;\n ShortString private immutable _version;\n // slither-disable-next-line constable-states\n string private _nameFallback;\n // slither-disable-next-line constable-states\n string private _versionFallback;\n\n /**\n * @dev Initializes the domain separator and parameter caches.\n *\n * The meaning of `name` and `version` is specified in\n * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP-712]:\n *\n * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.\n * - `version`: the current major version of the signing domain.\n *\n * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart\n * contract upgrade].\n */\n constructor(string memory name, string memory version) {\n _name = name.toShortStringWithFallback(_nameFallback);\n _version = version.toShortStringWithFallback(_versionFallback);\n _hashedName = keccak256(bytes(name));\n _hashedVersion = keccak256(bytes(version));\n\n _cachedChainId = block.chainid;\n _cachedDomainSeparator = _buildDomainSeparator();\n _cachedThis = address(this);\n }\n\n /**\n * @dev Returns the domain separator for the current chain.\n */\n function _domainSeparatorV4() internal view returns (bytes32) {\n if (address(this) == _cachedThis && block.chainid == _cachedChainId) {\n return _cachedDomainSeparator;\n } else {\n return _buildDomainSeparator();\n }\n }\n\n function _buildDomainSeparator() private view returns (bytes32) {\n return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));\n }\n\n /**\n * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this\n * function returns the hash of the fully encoded EIP712 message for this domain.\n *\n * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:\n *\n * ```solidity\n * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(\n * keccak256(\"Mail(address to,string contents)\"),\n * mailTo,\n * keccak256(bytes(mailContents))\n * )));\n * address signer = ECDSA.recover(digest, signature);\n * ```\n */\n function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {\n return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);\n }\n\n /**\n * @inheritdoc IERC5267\n */\n function eip712Domain()\n public\n view\n virtual\n returns (\n bytes1 fields,\n string memory name,\n string memory version,\n uint256 chainId,\n address verifyingContract,\n bytes32 salt,\n uint256[] memory extensions\n )\n {\n return (\n hex\"0f\", // 01111\n _EIP712Name(),\n _EIP712Version(),\n block.chainid,\n address(this),\n bytes32(0),\n new uint256[](0)\n );\n }\n\n /**\n * @dev The name parameter for the EIP712 domain.\n *\n * NOTE: By default this function reads _name which is an immutable value.\n * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).\n */\n // solhint-disable-next-line func-name-mixedcase\n function _EIP712Name() internal view returns (string memory) {\n return _name.toStringWithFallback(_nameFallback);\n }\n\n /**\n * @dev The version parameter for the EIP712 domain.\n *\n * NOTE: By default this function reads _version which is an immutable value.\n * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).\n */\n // solhint-disable-next-line func-name-mixedcase\n function _EIP712Version() internal view returns (string memory) {\n return _version.toStringWithFallback(_versionFallback);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/MessageHashUtils.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/MessageHashUtils.sol)\n\npragma solidity ^0.8.20;\n\nimport {Strings} from \"../Strings.sol\";\n\n/**\n * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.\n *\n * The library provides methods for generating a hash of a message that conforms to the\n * https://eips.ethereum.org/EIPS/eip-191[ERC-191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]\n * specifications.\n */\nlibrary MessageHashUtils {\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x45` (`personal_sign` messages).\n *\n * The digest is calculated by prefixing a bytes32 `messageHash` with\n * `\"\\x19Ethereum Signed Message:\\n32\"` and hashing the result. It corresponds with the\n * hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.\n *\n * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with\n * keccak256, although any bytes32 value can be safely used because the final digest will\n * be re-hashed.\n *\n * See {ECDSA-recover}.\n */\n function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n mstore(0x00, \"\\x19Ethereum Signed Message:\\n32\") // 32 is the bytes-length of messageHash\n mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix\n digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)\n }\n }\n\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x45` (`personal_sign` messages).\n *\n * The digest is calculated by prefixing an arbitrary `message` with\n * `\"\\x19Ethereum Signed Message:\\n\" + len(message)` and hashing the result. It corresponds with the\n * hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.\n *\n * See {ECDSA-recover}.\n */\n function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {\n return\n keccak256(bytes.concat(\"\\x19Ethereum Signed Message:\\n\", bytes(Strings.toString(message.length)), message));\n }\n\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x00` (data with intended validator).\n *\n * The digest is calculated by prefixing an arbitrary `data` with `\"\\x19\\x00\"` and the intended\n * `validator` address. Then hashing the result.\n *\n * See {ECDSA-recover}.\n */\n function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(hex\"19_00\", validator, data));\n }\n\n /**\n * @dev Variant of {toDataWithIntendedValidatorHash-address-bytes} optimized for cases where `data` is a bytes32.\n */\n function toDataWithIntendedValidatorHash(\n address validator,\n bytes32 messageHash\n ) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n mstore(0x00, hex\"19_00\")\n mstore(0x02, shl(96, validator))\n mstore(0x16, messageHash)\n digest := keccak256(0x00, 0x36)\n }\n }\n\n /**\n * @dev Returns the keccak256 digest of an EIP-712 typed data (ERC-191 version `0x01`).\n *\n * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with\n * `\\x19\\x01` and hashing the result. It corresponds to the hash signed by the\n * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.\n *\n * See {ECDSA-recover}.\n */\n function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n let ptr := mload(0x40)\n mstore(ptr, hex\"19_01\")\n mstore(add(ptr, 0x02), domainSeparator)\n mstore(add(ptr, 0x22), structHash)\n digest := keccak256(ptr, 0x42)\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Errors.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Collection of common custom errors used in multiple contracts\n *\n * IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.\n * It is recommended to avoid relying on the error API for critical functionality.\n *\n * _Available since v5.1._\n */\nlibrary Errors {\n /**\n * @dev The ETH balance of the account is not enough to perform the operation.\n */\n error InsufficientBalance(uint256 balance, uint256 needed);\n\n /**\n * @dev A call to an address target failed. The target may have reverted.\n */\n error FailedCall();\n\n /**\n * @dev The deployment failed.\n */\n error FailedDeployment();\n\n /**\n * @dev A necessary precompile is missing.\n */\n error MissingPrecompile(address);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/ERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/ERC165Checker.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165Checker.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @dev Library used to query support of an interface declared via {IERC165}.\n *\n * Note that these functions return the actual result of the query: they do not\n * `revert` if an interface is not supported. It is up to the caller to decide\n * what to do in these cases.\n */\nlibrary ERC165Checker {\n // As per the ERC-165 spec, no interface should ever match 0xffffffff\n bytes4 private constant INTERFACE_ID_INVALID = 0xffffffff;\n\n /**\n * @dev Returns true if `account` supports the {IERC165} interface.\n */\n function supportsERC165(address account) internal view returns (bool) {\n // Any contract that implements ERC-165 must explicitly indicate support of\n // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid\n return\n supportsERC165InterfaceUnchecked(account, type(IERC165).interfaceId) &&\n !supportsERC165InterfaceUnchecked(account, INTERFACE_ID_INVALID);\n }\n\n /**\n * @dev Returns true if `account` supports the interface defined by\n * `interfaceId`. Support for {IERC165} itself is queried automatically.\n *\n * See {IERC165-supportsInterface}.\n */\n function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {\n // query support of both ERC-165 as per the spec and support of _interfaceId\n return supportsERC165(account) && supportsERC165InterfaceUnchecked(account, interfaceId);\n }\n\n /**\n * @dev Returns a boolean array where each value corresponds to the\n * interfaces passed in and whether they're supported or not. This allows\n * you to batch check interfaces for a contract where your expectation\n * is that some interfaces may not be supported.\n *\n * See {IERC165-supportsInterface}.\n */\n function getSupportedInterfaces(\n address account,\n bytes4[] memory interfaceIds\n ) internal view returns (bool[] memory) {\n // an array of booleans corresponding to interfaceIds and whether they're supported or not\n bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length);\n\n // query support of ERC-165 itself\n if (supportsERC165(account)) {\n // query support of each interface in interfaceIds\n for (uint256 i = 0; i < interfaceIds.length; i++) {\n interfaceIdsSupported[i] = supportsERC165InterfaceUnchecked(account, interfaceIds[i]);\n }\n }\n\n return interfaceIdsSupported;\n }\n\n /**\n * @dev Returns true if `account` supports all the interfaces defined in\n * `interfaceIds`. Support for {IERC165} itself is queried automatically.\n *\n * Batch-querying can lead to gas savings by skipping repeated checks for\n * {IERC165} support.\n *\n * See {IERC165-supportsInterface}.\n */\n function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {\n // query support of ERC-165 itself\n if (!supportsERC165(account)) {\n return false;\n }\n\n // query support of each interface in interfaceIds\n for (uint256 i = 0; i < interfaceIds.length; i++) {\n if (!supportsERC165InterfaceUnchecked(account, interfaceIds[i])) {\n return false;\n }\n }\n\n // all interfaces supported\n return true;\n }\n\n /**\n * @notice Query if a contract implements an interface, does not check ERC-165 support\n * @param account The address of the contract to query for support of an interface\n * @param interfaceId The interface identifier, as specified in ERC-165\n * @return true if the contract at account indicates support of the interface with\n * identifier interfaceId, false otherwise\n * @dev Assumes that account contains a contract that supports ERC-165, otherwise\n * the behavior of this method is undefined. This precondition can be checked\n * with {supportsERC165}.\n *\n * Some precompiled contracts will falsely indicate support for a given interface, so caution\n * should be exercised when using this function.\n *\n * Interface identification is specified in ERC-165.\n */\n function supportsERC165InterfaceUnchecked(address account, bytes4 interfaceId) internal view returns (bool) {\n // prepare call\n bytes memory encodedParams = abi.encodeCall(IERC165.supportsInterface, (interfaceId));\n\n // perform static call\n bool success;\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n success := staticcall(30000, account, add(encodedParams, 0x20), mload(encodedParams), 0x00, 0x20)\n returnSize := returndatasize()\n returnValue := mload(0x00)\n }\n\n return success && returnSize >= 0x20 && returnValue > 0;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/IERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[ERC].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/Math.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.20;\n\nimport {Panic} from \"../Panic.sol\";\nimport {SafeCast} from \"./SafeCast.sol\";\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n enum Rounding {\n Floor, // Toward negative infinity\n Ceil, // Toward positive infinity\n Trunc, // Toward zero\n Expand // Away from zero\n }\n\n /**\n * @dev Return the 512-bit addition of two uint256.\n *\n * The result is stored in two 256 variables such that sum = high * 2²⁵⁶ + low.\n */\n function add512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {\n assembly (\"memory-safe\") {\n low := add(a, b)\n high := lt(low, a)\n }\n }\n\n /**\n * @dev Return the 512-bit multiplication of two uint256.\n *\n * The result is stored in two 256 variables such that product = high * 2²⁵⁶ + low.\n */\n function mul512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {\n // 512-bit multiply [high low] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use\n // the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n // variables such that product = high * 2²⁵⁶ + low.\n assembly (\"memory-safe\") {\n let mm := mulmod(a, b, not(0))\n low := mul(a, b)\n high := sub(sub(mm, low), lt(mm, low))\n }\n }\n\n /**\n * @dev Returns the addition of two unsigned integers, with a success flag (no overflow).\n */\n function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a + b;\n success = c >= a;\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, with a success flag (no overflow).\n */\n function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a - b;\n success = c <= a;\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, with a success flag (no overflow).\n */\n function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a * b;\n assembly (\"memory-safe\") {\n // Only true when the multiplication doesn't overflow\n // (c / a == b) || (a == 0)\n success := or(eq(div(c, a), b), iszero(a))\n }\n // equivalent to: success ? c : 0\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the division of two unsigned integers, with a success flag (no division by zero).\n */\n function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n success = b > 0;\n assembly (\"memory-safe\") {\n // The `DIV` opcode returns zero when the denominator is 0.\n result := div(a, b)\n }\n }\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).\n */\n function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n success = b > 0;\n assembly (\"memory-safe\") {\n // The `MOD` opcode returns zero when the denominator is 0.\n result := mod(a, b)\n }\n }\n }\n\n /**\n * @dev Unsigned saturating addition, bounds to `2²⁵⁶ - 1` instead of overflowing.\n */\n function saturatingAdd(uint256 a, uint256 b) internal pure returns (uint256) {\n (bool success, uint256 result) = tryAdd(a, b);\n return ternary(success, result, type(uint256).max);\n }\n\n /**\n * @dev Unsigned saturating subtraction, bounds to zero instead of overflowing.\n */\n function saturatingSub(uint256 a, uint256 b) internal pure returns (uint256) {\n (, uint256 result) = trySub(a, b);\n return result;\n }\n\n /**\n * @dev Unsigned saturating multiplication, bounds to `2²⁵⁶ - 1` instead of overflowing.\n */\n function saturatingMul(uint256 a, uint256 b) internal pure returns (uint256) {\n (bool success, uint256 result) = tryMul(a, b);\n return ternary(success, result, type(uint256).max);\n }\n\n /**\n * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.\n *\n * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.\n * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute\n * one branch when needed, making this function more expensive.\n */\n function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {\n unchecked {\n // branchless ternary works because:\n // b ^ (a ^ b) == a\n // b ^ 0 == b\n return b ^ ((a ^ b) * SafeCast.toUint(condition));\n }\n }\n\n /**\n * @dev Returns the largest of two numbers.\n */\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\n return ternary(a > b, a, b);\n }\n\n /**\n * @dev Returns the smallest of two numbers.\n */\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\n return ternary(a < b, a, b);\n }\n\n /**\n * @dev Returns the average of two numbers. The result is rounded towards\n * zero.\n */\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b) / 2 can overflow.\n return (a & b) + (a ^ b) / 2;\n }\n\n /**\n * @dev Returns the ceiling of the division of two numbers.\n *\n * This differs from standard division with `/` in that it rounds towards infinity instead\n * of rounding towards zero.\n */\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n if (b == 0) {\n // Guarantee the same behavior as in a regular Solidity division.\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n\n // The following calculation ensures accurate ceiling division without overflow.\n // Since a is non-zero, (a - 1) / b will not overflow.\n // The largest possible result occurs when (a - 1) / b is type(uint256).max,\n // but the largest value we can obtain is type(uint256).max - 1, which happens\n // when a = type(uint256).max and b = 1.\n unchecked {\n return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);\n }\n }\n\n /**\n * @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or\n * denominator == 0.\n *\n * Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by\n * Uniswap Labs also under MIT license.\n */\n function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {\n unchecked {\n (uint256 high, uint256 low) = mul512(x, y);\n\n // Handle non-overflow cases, 256 by 256 division.\n if (high == 0) {\n // Solidity will revert if denominator == 0, unlike the div opcode on its own.\n // The surrounding unchecked block does not change this fact.\n // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.\n return low / denominator;\n }\n\n // Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.\n if (denominator <= high) {\n Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));\n }\n\n ///////////////////////////////////////////////\n // 512 by 256 division.\n ///////////////////////////////////////////////\n\n // Make division exact by subtracting the remainder from [high low].\n uint256 remainder;\n assembly (\"memory-safe\") {\n // Compute remainder using mulmod.\n remainder := mulmod(x, y, denominator)\n\n // Subtract 256 bit number from 512 bit number.\n high := sub(high, gt(remainder, low))\n low := sub(low, remainder)\n }\n\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator.\n // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.\n\n uint256 twos = denominator & (0 - denominator);\n assembly (\"memory-safe\") {\n // Divide denominator by twos.\n denominator := div(denominator, twos)\n\n // Divide [high low] by twos.\n low := div(low, twos)\n\n // Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.\n twos := add(div(sub(0, twos), twos), 1)\n }\n\n // Shift in bits from high into low.\n low |= high * twos;\n\n // Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such\n // that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for\n // four bits. That is, denominator * inv ≡ 1 mod 2⁴.\n uint256 inverse = (3 * denominator) ^ 2;\n\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also\n // works in modular arithmetic, doubling the correct bits in each step.\n inverse *= 2 - denominator * inverse; // inverse mod 2⁸\n inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶\n inverse *= 2 - denominator * inverse; // inverse mod 2³²\n inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴\n inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸\n inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶\n\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n // This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is\n // less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and high\n // is no longer required.\n result = low * inverse;\n return result;\n }\n }\n\n /**\n * @dev Calculates x * y / denominator with full precision, following the selected rounding direction.\n */\n function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {\n return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);\n }\n\n /**\n * @dev Calculates floor(x * y >> n) with full precision. Throws if result overflows a uint256.\n */\n function mulShr(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 result) {\n unchecked {\n (uint256 high, uint256 low) = mul512(x, y);\n if (high >= 1 << n) {\n Panic.panic(Panic.UNDER_OVERFLOW);\n }\n return (high << (256 - n)) | (low >> n);\n }\n }\n\n /**\n * @dev Calculates x * y >> n with full precision, following the selected rounding direction.\n */\n function mulShr(uint256 x, uint256 y, uint8 n, Rounding rounding) internal pure returns (uint256) {\n return mulShr(x, y, n) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, 1 << n) > 0);\n }\n\n /**\n * @dev Calculate the modular multiplicative inverse of a number in Z/nZ.\n *\n * If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.\n * If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.\n *\n * If the input value is not inversible, 0 is returned.\n *\n * NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the\n * inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.\n */\n function invMod(uint256 a, uint256 n) internal pure returns (uint256) {\n unchecked {\n if (n == 0) return 0;\n\n // The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)\n // Used to compute integers x and y such that: ax + ny = gcd(a, n).\n // When the gcd is 1, then the inverse of a modulo n exists and it's x.\n // ax + ny = 1\n // ax = 1 + (-y)n\n // ax ≡ 1 (mod n) # x is the inverse of a modulo n\n\n // If the remainder is 0 the gcd is n right away.\n uint256 remainder = a % n;\n uint256 gcd = n;\n\n // Therefore the initial coefficients are:\n // ax + ny = gcd(a, n) = n\n // 0a + 1n = n\n int256 x = 0;\n int256 y = 1;\n\n while (remainder != 0) {\n uint256 quotient = gcd / remainder;\n\n (gcd, remainder) = (\n // The old remainder is the next gcd to try.\n remainder,\n // Compute the next remainder.\n // Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd\n // where gcd is at most n (capped to type(uint256).max)\n gcd - remainder * quotient\n );\n\n (x, y) = (\n // Increment the coefficient of a.\n y,\n // Decrement the coefficient of n.\n // Can overflow, but the result is casted to uint256 so that the\n // next value of y is \"wrapped around\" to a value between 0 and n - 1.\n x - y * int256(quotient)\n );\n }\n\n if (gcd != 1) return 0; // No inverse exists.\n return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.\n }\n }\n\n /**\n * @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.\n *\n * From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is\n * prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that\n * `a**(p-2)` is the modular multiplicative inverse of a in Fp.\n *\n * NOTE: this function does NOT check that `p` is a prime greater than `2`.\n */\n function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {\n unchecked {\n return Math.modExp(a, p - 2, p);\n }\n }\n\n /**\n * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)\n *\n * Requirements:\n * - modulus can't be zero\n * - underlying staticcall to precompile must succeed\n *\n * IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make\n * sure the chain you're using it on supports the precompiled contract for modular exponentiation\n * at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,\n * the underlying function will succeed given the lack of a revert, but the result may be incorrectly\n * interpreted as 0.\n */\n function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {\n (bool success, uint256 result) = tryModExp(b, e, m);\n if (!success) {\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n return result;\n }\n\n /**\n * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).\n * It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying\n * to operate modulo 0 or if the underlying precompile reverted.\n *\n * IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain\n * you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in\n * https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack\n * of a revert, but the result may be incorrectly interpreted as 0.\n */\n function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {\n if (m == 0) return (false, 0);\n assembly (\"memory-safe\") {\n let ptr := mload(0x40)\n // | Offset | Content | Content (Hex) |\n // |-----------|------------|--------------------------------------------------------------------|\n // | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x60:0x7f | value of b | 0x<.............................................................b> |\n // | 0x80:0x9f | value of e | 0x<.............................................................e> |\n // | 0xa0:0xbf | value of m | 0x<.............................................................m> |\n mstore(ptr, 0x20)\n mstore(add(ptr, 0x20), 0x20)\n mstore(add(ptr, 0x40), 0x20)\n mstore(add(ptr, 0x60), b)\n mstore(add(ptr, 0x80), e)\n mstore(add(ptr, 0xa0), m)\n\n // Given the result < m, it's guaranteed to fit in 32 bytes,\n // so we can use the memory scratch space located at offset 0.\n success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)\n result := mload(0x00)\n }\n }\n\n /**\n * @dev Variant of {modExp} that supports inputs of arbitrary length.\n */\n function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {\n (bool success, bytes memory result) = tryModExp(b, e, m);\n if (!success) {\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n return result;\n }\n\n /**\n * @dev Variant of {tryModExp} that supports inputs of arbitrary length.\n */\n function tryModExp(\n bytes memory b,\n bytes memory e,\n bytes memory m\n ) internal view returns (bool success, bytes memory result) {\n if (_zeroBytes(m)) return (false, new bytes(0));\n\n uint256 mLen = m.length;\n\n // Encode call args in result and move the free memory pointer\n result = abi.encodePacked(b.length, e.length, mLen, b, e, m);\n\n assembly (\"memory-safe\") {\n let dataPtr := add(result, 0x20)\n // Write result on top of args to avoid allocating extra memory.\n success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)\n // Overwrite the length.\n // result.length > returndatasize() is guaranteed because returndatasize() == m.length\n mstore(result, mLen)\n // Set the memory pointer after the returned data.\n mstore(0x40, add(dataPtr, mLen))\n }\n }\n\n /**\n * @dev Returns whether the provided byte array is zero.\n */\n function _zeroBytes(bytes memory byteArray) private pure returns (bool) {\n for (uint256 i = 0; i < byteArray.length; ++i) {\n if (byteArray[i] != 0) {\n return false;\n }\n }\n return true;\n }\n\n /**\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded\n * towards zero.\n *\n * This method is based on Newton's method for computing square roots; the algorithm is restricted to only\n * using integer operations.\n */\n function sqrt(uint256 a) internal pure returns (uint256) {\n unchecked {\n // Take care of easy edge cases when a == 0 or a == 1\n if (a <= 1) {\n return a;\n }\n\n // In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a\n // sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between\n // the current value as `ε_n = | x_n - sqrt(a) |`.\n //\n // For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root\n // of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is\n // bigger than any uint256.\n //\n // By noticing that\n // `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`\n // we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar\n // to the msb function.\n uint256 aa = a;\n uint256 xn = 1;\n\n if (aa >= (1 << 128)) {\n aa >>= 128;\n xn <<= 64;\n }\n if (aa >= (1 << 64)) {\n aa >>= 64;\n xn <<= 32;\n }\n if (aa >= (1 << 32)) {\n aa >>= 32;\n xn <<= 16;\n }\n if (aa >= (1 << 16)) {\n aa >>= 16;\n xn <<= 8;\n }\n if (aa >= (1 << 8)) {\n aa >>= 8;\n xn <<= 4;\n }\n if (aa >= (1 << 4)) {\n aa >>= 4;\n xn <<= 2;\n }\n if (aa >= (1 << 2)) {\n xn <<= 1;\n }\n\n // We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).\n //\n // We can refine our estimation by noticing that the middle of that interval minimizes the error.\n // If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).\n // This is going to be our x_0 (and ε_0)\n xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)\n\n // From here, Newton's method give us:\n // x_{n+1} = (x_n + a / x_n) / 2\n //\n // One should note that:\n // x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a\n // = ((x_n² + a) / (2 * x_n))² - a\n // = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a\n // = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)\n // = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)\n // = (x_n² - a)² / (2 * x_n)²\n // = ((x_n² - a) / (2 * x_n))²\n // ≥ 0\n // Which proves that for all n ≥ 1, sqrt(a) ≤ x_n\n //\n // This gives us the proof of quadratic convergence of the sequence:\n // ε_{n+1} = | x_{n+1} - sqrt(a) |\n // = | (x_n + a / x_n) / 2 - sqrt(a) |\n // = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |\n // = | (x_n - sqrt(a))² / (2 * x_n) |\n // = | ε_n² / (2 * x_n) |\n // = ε_n² / | (2 * x_n) |\n //\n // For the first iteration, we have a special case where x_0 is known:\n // ε_1 = ε_0² / | (2 * x_0) |\n // ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))\n // ≤ 2**(2*e-4) / (3 * 2**(e-1))\n // ≤ 2**(e-3) / 3\n // ≤ 2**(e-3-log2(3))\n // ≤ 2**(e-4.5)\n //\n // For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:\n // ε_{n+1} = ε_n² / | (2 * x_n) |\n // ≤ (2**(e-k))² / (2 * 2**(e-1))\n // ≤ 2**(2*e-2*k) / 2**e\n // ≤ 2**(e-2*k)\n xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above\n xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5\n xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9\n xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18\n xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36\n xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72\n\n // Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision\n // ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either\n // sqrt(a) or sqrt(a) + 1.\n return xn - SafeCast.toUint(xn > a / xn);\n }\n }\n\n /**\n * @dev Calculates sqrt(a), following the selected rounding direction.\n */\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = sqrt(a);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);\n }\n }\n\n /**\n * @dev Return the log in base 2 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n */\n function log2(uint256 x) internal pure returns (uint256 r) {\n // If value has upper 128 bits set, log2 result is at least 128\n r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;\n // If upper 64 bits of 128-bit half set, add 64 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;\n // If upper 32 bits of 64-bit half set, add 32 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;\n // If upper 16 bits of 32-bit half set, add 16 to result\n r |= SafeCast.toUint((x >> r) > 0xffff) << 4;\n // If upper 8 bits of 16-bit half set, add 8 to result\n r |= SafeCast.toUint((x >> r) > 0xff) << 3;\n // If upper 4 bits of 8-bit half set, add 4 to result\n r |= SafeCast.toUint((x >> r) > 0xf) << 2;\n\n // Shifts value right by the current result and use it as an index into this lookup table:\n //\n // | x (4 bits) | index | table[index] = MSB position |\n // |------------|---------|-----------------------------|\n // | 0000 | 0 | table[0] = 0 |\n // | 0001 | 1 | table[1] = 0 |\n // | 0010 | 2 | table[2] = 1 |\n // | 0011 | 3 | table[3] = 1 |\n // | 0100 | 4 | table[4] = 2 |\n // | 0101 | 5 | table[5] = 2 |\n // | 0110 | 6 | table[6] = 2 |\n // | 0111 | 7 | table[7] = 2 |\n // | 1000 | 8 | table[8] = 3 |\n // | 1001 | 9 | table[9] = 3 |\n // | 1010 | 10 | table[10] = 3 |\n // | 1011 | 11 | table[11] = 3 |\n // | 1100 | 12 | table[12] = 3 |\n // | 1101 | 13 | table[13] = 3 |\n // | 1110 | 14 | table[14] = 3 |\n // | 1111 | 15 | table[15] = 3 |\n //\n // The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes.\n assembly (\"memory-safe\") {\n r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000))\n }\n }\n\n /**\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log2(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);\n }\n }\n\n /**\n * @dev Return the log in base 10 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n */\n function log10(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >= 10 ** 64) {\n value /= 10 ** 64;\n result += 64;\n }\n if (value >= 10 ** 32) {\n value /= 10 ** 32;\n result += 32;\n }\n if (value >= 10 ** 16) {\n value /= 10 ** 16;\n result += 16;\n }\n if (value >= 10 ** 8) {\n value /= 10 ** 8;\n result += 8;\n }\n if (value >= 10 ** 4) {\n value /= 10 ** 4;\n result += 4;\n }\n if (value >= 10 ** 2) {\n value /= 10 ** 2;\n result += 2;\n }\n if (value >= 10 ** 1) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log10(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);\n }\n }\n\n /**\n * @dev Return the log in base 256 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n *\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n */\n function log256(uint256 x) internal pure returns (uint256 r) {\n // If value has upper 128 bits set, log2 result is at least 128\n r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;\n // If upper 64 bits of 128-bit half set, add 64 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;\n // If upper 32 bits of 64-bit half set, add 32 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;\n // If upper 16 bits of 32-bit half set, add 16 to result\n r |= SafeCast.toUint((x >> r) > 0xffff) << 4;\n // Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8\n return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);\n }\n\n /**\n * @dev Return the log in base 256, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log256(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);\n }\n }\n\n /**\n * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.\n */\n function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {\n return uint8(rounding) % 2 == 1;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/SafeCast.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeCast {\n /**\n * @dev Value doesn't fit in an uint of `bits` size.\n */\n error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);\n\n /**\n * @dev An int value doesn't fit in an uint of `bits` size.\n */\n error SafeCastOverflowedIntToUint(int256 value);\n\n /**\n * @dev Value doesn't fit in an int of `bits` size.\n */\n error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);\n\n /**\n * @dev An uint value doesn't fit in an int of `bits` size.\n */\n error SafeCastOverflowedUintToInt(uint256 value);\n\n /**\n * @dev Returns the downcasted uint248 from uint256, reverting on\n * overflow (when the input is greater than largest uint248).\n *\n * Counterpart to Solidity's `uint248` operator.\n *\n * Requirements:\n *\n * - input must fit into 248 bits\n */\n function toUint248(uint256 value) internal pure returns (uint248) {\n if (value > type(uint248).max) {\n revert SafeCastOverflowedUintDowncast(248, value);\n }\n return uint248(value);\n }\n\n /**\n * @dev Returns the downcasted uint240 from uint256, reverting on\n * overflow (when the input is greater than largest uint240).\n *\n * Counterpart to Solidity's `uint240` operator.\n *\n * Requirements:\n *\n * - input must fit into 240 bits\n */\n function toUint240(uint256 value) internal pure returns (uint240) {\n if (value > type(uint240).max) {\n revert SafeCastOverflowedUintDowncast(240, value);\n }\n return uint240(value);\n }\n\n /**\n * @dev Returns the downcasted uint232 from uint256, reverting on\n * overflow (when the input is greater than largest uint232).\n *\n * Counterpart to Solidity's `uint232` operator.\n *\n * Requirements:\n *\n * - input must fit into 232 bits\n */\n function toUint232(uint256 value) internal pure returns (uint232) {\n if (value > type(uint232).max) {\n revert SafeCastOverflowedUintDowncast(232, value);\n }\n return uint232(value);\n }\n\n /**\n * @dev Returns the downcasted uint224 from uint256, reverting on\n * overflow (when the input is greater than largest uint224).\n *\n * Counterpart to Solidity's `uint224` operator.\n *\n * Requirements:\n *\n * - input must fit into 224 bits\n */\n function toUint224(uint256 value) internal pure returns (uint224) {\n if (value > type(uint224).max) {\n revert SafeCastOverflowedUintDowncast(224, value);\n }\n return uint224(value);\n }\n\n /**\n * @dev Returns the downcasted uint216 from uint256, reverting on\n * overflow (when the input is greater than largest uint216).\n *\n * Counterpart to Solidity's `uint216` operator.\n *\n * Requirements:\n *\n * - input must fit into 216 bits\n */\n function toUint216(uint256 value) internal pure returns (uint216) {\n if (value > type(uint216).max) {\n revert SafeCastOverflowedUintDowncast(216, value);\n }\n return uint216(value);\n }\n\n /**\n * @dev Returns the downcasted uint208 from uint256, reverting on\n * overflow (when the input is greater than largest uint208).\n *\n * Counterpart to Solidity's `uint208` operator.\n *\n * Requirements:\n *\n * - input must fit into 208 bits\n */\n function toUint208(uint256 value) internal pure returns (uint208) {\n if (value > type(uint208).max) {\n revert SafeCastOverflowedUintDowncast(208, value);\n }\n return uint208(value);\n }\n\n /**\n * @dev Returns the downcasted uint200 from uint256, reverting on\n * overflow (when the input is greater than largest uint200).\n *\n * Counterpart to Solidity's `uint200` operator.\n *\n * Requirements:\n *\n * - input must fit into 200 bits\n */\n function toUint200(uint256 value) internal pure returns (uint200) {\n if (value > type(uint200).max) {\n revert SafeCastOverflowedUintDowncast(200, value);\n }\n return uint200(value);\n }\n\n /**\n * @dev Returns the downcasted uint192 from uint256, reverting on\n * overflow (when the input is greater than largest uint192).\n *\n * Counterpart to Solidity's `uint192` operator.\n *\n * Requirements:\n *\n * - input must fit into 192 bits\n */\n function toUint192(uint256 value) internal pure returns (uint192) {\n if (value > type(uint192).max) {\n revert SafeCastOverflowedUintDowncast(192, value);\n }\n return uint192(value);\n }\n\n /**\n * @dev Returns the downcasted uint184 from uint256, reverting on\n * overflow (when the input is greater than largest uint184).\n *\n * Counterpart to Solidity's `uint184` operator.\n *\n * Requirements:\n *\n * - input must fit into 184 bits\n */\n function toUint184(uint256 value) internal pure returns (uint184) {\n if (value > type(uint184).max) {\n revert SafeCastOverflowedUintDowncast(184, value);\n }\n return uint184(value);\n }\n\n /**\n * @dev Returns the downcasted uint176 from uint256, reverting on\n * overflow (when the input is greater than largest uint176).\n *\n * Counterpart to Solidity's `uint176` operator.\n *\n * Requirements:\n *\n * - input must fit into 176 bits\n */\n function toUint176(uint256 value) internal pure returns (uint176) {\n if (value > type(uint176).max) {\n revert SafeCastOverflowedUintDowncast(176, value);\n }\n return uint176(value);\n }\n\n /**\n * @dev Returns the downcasted uint168 from uint256, reverting on\n * overflow (when the input is greater than largest uint168).\n *\n * Counterpart to Solidity's `uint168` operator.\n *\n * Requirements:\n *\n * - input must fit into 168 bits\n */\n function toUint168(uint256 value) internal pure returns (uint168) {\n if (value > type(uint168).max) {\n revert SafeCastOverflowedUintDowncast(168, value);\n }\n return uint168(value);\n }\n\n /**\n * @dev Returns the downcasted uint160 from uint256, reverting on\n * overflow (when the input is greater than largest uint160).\n *\n * Counterpart to Solidity's `uint160` operator.\n *\n * Requirements:\n *\n * - input must fit into 160 bits\n */\n function toUint160(uint256 value) internal pure returns (uint160) {\n if (value > type(uint160).max) {\n revert SafeCastOverflowedUintDowncast(160, value);\n }\n return uint160(value);\n }\n\n /**\n * @dev Returns the downcasted uint152 from uint256, reverting on\n * overflow (when the input is greater than largest uint152).\n *\n * Counterpart to Solidity's `uint152` operator.\n *\n * Requirements:\n *\n * - input must fit into 152 bits\n */\n function toUint152(uint256 value) internal pure returns (uint152) {\n if (value > type(uint152).max) {\n revert SafeCastOverflowedUintDowncast(152, value);\n }\n return uint152(value);\n }\n\n /**\n * @dev Returns the downcasted uint144 from uint256, reverting on\n * overflow (when the input is greater than largest uint144).\n *\n * Counterpart to Solidity's `uint144` operator.\n *\n * Requirements:\n *\n * - input must fit into 144 bits\n */\n function toUint144(uint256 value) internal pure returns (uint144) {\n if (value > type(uint144).max) {\n revert SafeCastOverflowedUintDowncast(144, value);\n }\n return uint144(value);\n }\n\n /**\n * @dev Returns the downcasted uint136 from uint256, reverting on\n * overflow (when the input is greater than largest uint136).\n *\n * Counterpart to Solidity's `uint136` operator.\n *\n * Requirements:\n *\n * - input must fit into 136 bits\n */\n function toUint136(uint256 value) internal pure returns (uint136) {\n if (value > type(uint136).max) {\n revert SafeCastOverflowedUintDowncast(136, value);\n }\n return uint136(value);\n }\n\n /**\n * @dev Returns the downcasted uint128 from uint256, reverting on\n * overflow (when the input is greater than largest uint128).\n *\n * Counterpart to Solidity's `uint128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n */\n function toUint128(uint256 value) internal pure returns (uint128) {\n if (value > type(uint128).max) {\n revert SafeCastOverflowedUintDowncast(128, value);\n }\n return uint128(value);\n }\n\n /**\n * @dev Returns the downcasted uint120 from uint256, reverting on\n * overflow (when the input is greater than largest uint120).\n *\n * Counterpart to Solidity's `uint120` operator.\n *\n * Requirements:\n *\n * - input must fit into 120 bits\n */\n function toUint120(uint256 value) internal pure returns (uint120) {\n if (value > type(uint120).max) {\n revert SafeCastOverflowedUintDowncast(120, value);\n }\n return uint120(value);\n }\n\n /**\n * @dev Returns the downcasted uint112 from uint256, reverting on\n * overflow (when the input is greater than largest uint112).\n *\n * Counterpart to Solidity's `uint112` operator.\n *\n * Requirements:\n *\n * - input must fit into 112 bits\n */\n function toUint112(uint256 value) internal pure returns (uint112) {\n if (value > type(uint112).max) {\n revert SafeCastOverflowedUintDowncast(112, value);\n }\n return uint112(value);\n }\n\n /**\n * @dev Returns the downcasted uint104 from uint256, reverting on\n * overflow (when the input is greater than largest uint104).\n *\n * Counterpart to Solidity's `uint104` operator.\n *\n * Requirements:\n *\n * - input must fit into 104 bits\n */\n function toUint104(uint256 value) internal pure returns (uint104) {\n if (value > type(uint104).max) {\n revert SafeCastOverflowedUintDowncast(104, value);\n }\n return uint104(value);\n }\n\n /**\n * @dev Returns the downcasted uint96 from uint256, reverting on\n * overflow (when the input is greater than largest uint96).\n *\n * Counterpart to Solidity's `uint96` operator.\n *\n * Requirements:\n *\n * - input must fit into 96 bits\n */\n function toUint96(uint256 value) internal pure returns (uint96) {\n if (value > type(uint96).max) {\n revert SafeCastOverflowedUintDowncast(96, value);\n }\n return uint96(value);\n }\n\n /**\n * @dev Returns the downcasted uint88 from uint256, reverting on\n * overflow (when the input is greater than largest uint88).\n *\n * Counterpart to Solidity's `uint88` operator.\n *\n * Requirements:\n *\n * - input must fit into 88 bits\n */\n function toUint88(uint256 value) internal pure returns (uint88) {\n if (value > type(uint88).max) {\n revert SafeCastOverflowedUintDowncast(88, value);\n }\n return uint88(value);\n }\n\n /**\n * @dev Returns the downcasted uint80 from uint256, reverting on\n * overflow (when the input is greater than largest uint80).\n *\n * Counterpart to Solidity's `uint80` operator.\n *\n * Requirements:\n *\n * - input must fit into 80 bits\n */\n function toUint80(uint256 value) internal pure returns (uint80) {\n if (value > type(uint80).max) {\n revert SafeCastOverflowedUintDowncast(80, value);\n }\n return uint80(value);\n }\n\n /**\n * @dev Returns the downcasted uint72 from uint256, reverting on\n * overflow (when the input is greater than largest uint72).\n *\n * Counterpart to Solidity's `uint72` operator.\n *\n * Requirements:\n *\n * - input must fit into 72 bits\n */\n function toUint72(uint256 value) internal pure returns (uint72) {\n if (value > type(uint72).max) {\n revert SafeCastOverflowedUintDowncast(72, value);\n }\n return uint72(value);\n }\n\n /**\n * @dev Returns the downcasted uint64 from uint256, reverting on\n * overflow (when the input is greater than largest uint64).\n *\n * Counterpart to Solidity's `uint64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n */\n function toUint64(uint256 value) internal pure returns (uint64) {\n if (value > type(uint64).max) {\n revert SafeCastOverflowedUintDowncast(64, value);\n }\n return uint64(value);\n }\n\n /**\n * @dev Returns the downcasted uint56 from uint256, reverting on\n * overflow (when the input is greater than largest uint56).\n *\n * Counterpart to Solidity's `uint56` operator.\n *\n * Requirements:\n *\n * - input must fit into 56 bits\n */\n function toUint56(uint256 value) internal pure returns (uint56) {\n if (value > type(uint56).max) {\n revert SafeCastOverflowedUintDowncast(56, value);\n }\n return uint56(value);\n }\n\n /**\n * @dev Returns the downcasted uint48 from uint256, reverting on\n * overflow (when the input is greater than largest uint48).\n *\n * Counterpart to Solidity's `uint48` operator.\n *\n * Requirements:\n *\n * - input must fit into 48 bits\n */\n function toUint48(uint256 value) internal pure returns (uint48) {\n if (value > type(uint48).max) {\n revert SafeCastOverflowedUintDowncast(48, value);\n }\n return uint48(value);\n }\n\n /**\n * @dev Returns the downcasted uint40 from uint256, reverting on\n * overflow (when the input is greater than largest uint40).\n *\n * Counterpart to Solidity's `uint40` operator.\n *\n * Requirements:\n *\n * - input must fit into 40 bits\n */\n function toUint40(uint256 value) internal pure returns (uint40) {\n if (value > type(uint40).max) {\n revert SafeCastOverflowedUintDowncast(40, value);\n }\n return uint40(value);\n }\n\n /**\n * @dev Returns the downcasted uint32 from uint256, reverting on\n * overflow (when the input is greater than largest uint32).\n *\n * Counterpart to Solidity's `uint32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n */\n function toUint32(uint256 value) internal pure returns (uint32) {\n if (value > type(uint32).max) {\n revert SafeCastOverflowedUintDowncast(32, value);\n }\n return uint32(value);\n }\n\n /**\n * @dev Returns the downcasted uint24 from uint256, reverting on\n * overflow (when the input is greater than largest uint24).\n *\n * Counterpart to Solidity's `uint24` operator.\n *\n * Requirements:\n *\n * - input must fit into 24 bits\n */\n function toUint24(uint256 value) internal pure returns (uint24) {\n if (value > type(uint24).max) {\n revert SafeCastOverflowedUintDowncast(24, value);\n }\n return uint24(value);\n }\n\n /**\n * @dev Returns the downcasted uint16 from uint256, reverting on\n * overflow (when the input is greater than largest uint16).\n *\n * Counterpart to Solidity's `uint16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n */\n function toUint16(uint256 value) internal pure returns (uint16) {\n if (value > type(uint16).max) {\n revert SafeCastOverflowedUintDowncast(16, value);\n }\n return uint16(value);\n }\n\n /**\n * @dev Returns the downcasted uint8 from uint256, reverting on\n * overflow (when the input is greater than largest uint8).\n *\n * Counterpart to Solidity's `uint8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits\n */\n function toUint8(uint256 value) internal pure returns (uint8) {\n if (value > type(uint8).max) {\n revert SafeCastOverflowedUintDowncast(8, value);\n }\n return uint8(value);\n }\n\n /**\n * @dev Converts a signed int256 into an unsigned uint256.\n *\n * Requirements:\n *\n * - input must be greater than or equal to 0.\n */\n function toUint256(int256 value) internal pure returns (uint256) {\n if (value < 0) {\n revert SafeCastOverflowedIntToUint(value);\n }\n return uint256(value);\n }\n\n /**\n * @dev Returns the downcasted int248 from int256, reverting on\n * overflow (when the input is less than smallest int248 or\n * greater than largest int248).\n *\n * Counterpart to Solidity's `int248` operator.\n *\n * Requirements:\n *\n * - input must fit into 248 bits\n */\n function toInt248(int256 value) internal pure returns (int248 downcasted) {\n downcasted = int248(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(248, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int240 from int256, reverting on\n * overflow (when the input is less than smallest int240 or\n * greater than largest int240).\n *\n * Counterpart to Solidity's `int240` operator.\n *\n * Requirements:\n *\n * - input must fit into 240 bits\n */\n function toInt240(int256 value) internal pure returns (int240 downcasted) {\n downcasted = int240(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(240, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int232 from int256, reverting on\n * overflow (when the input is less than smallest int232 or\n * greater than largest int232).\n *\n * Counterpart to Solidity's `int232` operator.\n *\n * Requirements:\n *\n * - input must fit into 232 bits\n */\n function toInt232(int256 value) internal pure returns (int232 downcasted) {\n downcasted = int232(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(232, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int224 from int256, reverting on\n * overflow (when the input is less than smallest int224 or\n * greater than largest int224).\n *\n * Counterpart to Solidity's `int224` operator.\n *\n * Requirements:\n *\n * - input must fit into 224 bits\n */\n function toInt224(int256 value) internal pure returns (int224 downcasted) {\n downcasted = int224(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(224, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int216 from int256, reverting on\n * overflow (when the input is less than smallest int216 or\n * greater than largest int216).\n *\n * Counterpart to Solidity's `int216` operator.\n *\n * Requirements:\n *\n * - input must fit into 216 bits\n */\n function toInt216(int256 value) internal pure returns (int216 downcasted) {\n downcasted = int216(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(216, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int208 from int256, reverting on\n * overflow (when the input is less than smallest int208 or\n * greater than largest int208).\n *\n * Counterpart to Solidity's `int208` operator.\n *\n * Requirements:\n *\n * - input must fit into 208 bits\n */\n function toInt208(int256 value) internal pure returns (int208 downcasted) {\n downcasted = int208(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(208, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int200 from int256, reverting on\n * overflow (when the input is less than smallest int200 or\n * greater than largest int200).\n *\n * Counterpart to Solidity's `int200` operator.\n *\n * Requirements:\n *\n * - input must fit into 200 bits\n */\n function toInt200(int256 value) internal pure returns (int200 downcasted) {\n downcasted = int200(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(200, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int192 from int256, reverting on\n * overflow (when the input is less than smallest int192 or\n * greater than largest int192).\n *\n * Counterpart to Solidity's `int192` operator.\n *\n * Requirements:\n *\n * - input must fit into 192 bits\n */\n function toInt192(int256 value) internal pure returns (int192 downcasted) {\n downcasted = int192(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(192, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int184 from int256, reverting on\n * overflow (when the input is less than smallest int184 or\n * greater than largest int184).\n *\n * Counterpart to Solidity's `int184` operator.\n *\n * Requirements:\n *\n * - input must fit into 184 bits\n */\n function toInt184(int256 value) internal pure returns (int184 downcasted) {\n downcasted = int184(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(184, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int176 from int256, reverting on\n * overflow (when the input is less than smallest int176 or\n * greater than largest int176).\n *\n * Counterpart to Solidity's `int176` operator.\n *\n * Requirements:\n *\n * - input must fit into 176 bits\n */\n function toInt176(int256 value) internal pure returns (int176 downcasted) {\n downcasted = int176(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(176, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int168 from int256, reverting on\n * overflow (when the input is less than smallest int168 or\n * greater than largest int168).\n *\n * Counterpart to Solidity's `int168` operator.\n *\n * Requirements:\n *\n * - input must fit into 168 bits\n */\n function toInt168(int256 value) internal pure returns (int168 downcasted) {\n downcasted = int168(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(168, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int160 from int256, reverting on\n * overflow (when the input is less than smallest int160 or\n * greater than largest int160).\n *\n * Counterpart to Solidity's `int160` operator.\n *\n * Requirements:\n *\n * - input must fit into 160 bits\n */\n function toInt160(int256 value) internal pure returns (int160 downcasted) {\n downcasted = int160(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(160, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int152 from int256, reverting on\n * overflow (when the input is less than smallest int152 or\n * greater than largest int152).\n *\n * Counterpart to Solidity's `int152` operator.\n *\n * Requirements:\n *\n * - input must fit into 152 bits\n */\n function toInt152(int256 value) internal pure returns (int152 downcasted) {\n downcasted = int152(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(152, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int144 from int256, reverting on\n * overflow (when the input is less than smallest int144 or\n * greater than largest int144).\n *\n * Counterpart to Solidity's `int144` operator.\n *\n * Requirements:\n *\n * - input must fit into 144 bits\n */\n function toInt144(int256 value) internal pure returns (int144 downcasted) {\n downcasted = int144(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(144, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int136 from int256, reverting on\n * overflow (when the input is less than smallest int136 or\n * greater than largest int136).\n *\n * Counterpart to Solidity's `int136` operator.\n *\n * Requirements:\n *\n * - input must fit into 136 bits\n */\n function toInt136(int256 value) internal pure returns (int136 downcasted) {\n downcasted = int136(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(136, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int128 from int256, reverting on\n * overflow (when the input is less than smallest int128 or\n * greater than largest int128).\n *\n * Counterpart to Solidity's `int128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n */\n function toInt128(int256 value) internal pure returns (int128 downcasted) {\n downcasted = int128(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(128, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int120 from int256, reverting on\n * overflow (when the input is less than smallest int120 or\n * greater than largest int120).\n *\n * Counterpart to Solidity's `int120` operator.\n *\n * Requirements:\n *\n * - input must fit into 120 bits\n */\n function toInt120(int256 value) internal pure returns (int120 downcasted) {\n downcasted = int120(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(120, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int112 from int256, reverting on\n * overflow (when the input is less than smallest int112 or\n * greater than largest int112).\n *\n * Counterpart to Solidity's `int112` operator.\n *\n * Requirements:\n *\n * - input must fit into 112 bits\n */\n function toInt112(int256 value) internal pure returns (int112 downcasted) {\n downcasted = int112(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(112, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int104 from int256, reverting on\n * overflow (when the input is less than smallest int104 or\n * greater than largest int104).\n *\n * Counterpart to Solidity's `int104` operator.\n *\n * Requirements:\n *\n * - input must fit into 104 bits\n */\n function toInt104(int256 value) internal pure returns (int104 downcasted) {\n downcasted = int104(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(104, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int96 from int256, reverting on\n * overflow (when the input is less than smallest int96 or\n * greater than largest int96).\n *\n * Counterpart to Solidity's `int96` operator.\n *\n * Requirements:\n *\n * - input must fit into 96 bits\n */\n function toInt96(int256 value) internal pure returns (int96 downcasted) {\n downcasted = int96(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(96, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int88 from int256, reverting on\n * overflow (when the input is less than smallest int88 or\n * greater than largest int88).\n *\n * Counterpart to Solidity's `int88` operator.\n *\n * Requirements:\n *\n * - input must fit into 88 bits\n */\n function toInt88(int256 value) internal pure returns (int88 downcasted) {\n downcasted = int88(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(88, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int80 from int256, reverting on\n * overflow (when the input is less than smallest int80 or\n * greater than largest int80).\n *\n * Counterpart to Solidity's `int80` operator.\n *\n * Requirements:\n *\n * - input must fit into 80 bits\n */\n function toInt80(int256 value) internal pure returns (int80 downcasted) {\n downcasted = int80(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(80, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int72 from int256, reverting on\n * overflow (when the input is less than smallest int72 or\n * greater than largest int72).\n *\n * Counterpart to Solidity's `int72` operator.\n *\n * Requirements:\n *\n * - input must fit into 72 bits\n */\n function toInt72(int256 value) internal pure returns (int72 downcasted) {\n downcasted = int72(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(72, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int64 from int256, reverting on\n * overflow (when the input is less than smallest int64 or\n * greater than largest int64).\n *\n * Counterpart to Solidity's `int64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n */\n function toInt64(int256 value) internal pure returns (int64 downcasted) {\n downcasted = int64(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(64, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int56 from int256, reverting on\n * overflow (when the input is less than smallest int56 or\n * greater than largest int56).\n *\n * Counterpart to Solidity's `int56` operator.\n *\n * Requirements:\n *\n * - input must fit into 56 bits\n */\n function toInt56(int256 value) internal pure returns (int56 downcasted) {\n downcasted = int56(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(56, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int48 from int256, reverting on\n * overflow (when the input is less than smallest int48 or\n * greater than largest int48).\n *\n * Counterpart to Solidity's `int48` operator.\n *\n * Requirements:\n *\n * - input must fit into 48 bits\n */\n function toInt48(int256 value) internal pure returns (int48 downcasted) {\n downcasted = int48(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(48, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int40 from int256, reverting on\n * overflow (when the input is less than smallest int40 or\n * greater than largest int40).\n *\n * Counterpart to Solidity's `int40` operator.\n *\n * Requirements:\n *\n * - input must fit into 40 bits\n */\n function toInt40(int256 value) internal pure returns (int40 downcasted) {\n downcasted = int40(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(40, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int32 from int256, reverting on\n * overflow (when the input is less than smallest int32 or\n * greater than largest int32).\n *\n * Counterpart to Solidity's `int32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n */\n function toInt32(int256 value) internal pure returns (int32 downcasted) {\n downcasted = int32(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(32, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int24 from int256, reverting on\n * overflow (when the input is less than smallest int24 or\n * greater than largest int24).\n *\n * Counterpart to Solidity's `int24` operator.\n *\n * Requirements:\n *\n * - input must fit into 24 bits\n */\n function toInt24(int256 value) internal pure returns (int24 downcasted) {\n downcasted = int24(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(24, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int16 from int256, reverting on\n * overflow (when the input is less than smallest int16 or\n * greater than largest int16).\n *\n * Counterpart to Solidity's `int16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n */\n function toInt16(int256 value) internal pure returns (int16 downcasted) {\n downcasted = int16(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(16, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int8 from int256, reverting on\n * overflow (when the input is less than smallest int8 or\n * greater than largest int8).\n *\n * Counterpart to Solidity's `int8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits\n */\n function toInt8(int256 value) internal pure returns (int8 downcasted) {\n downcasted = int8(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(8, value);\n }\n }\n\n /**\n * @dev Converts an unsigned uint256 into a signed int256.\n *\n * Requirements:\n *\n * - input must be less than or equal to maxInt256.\n */\n function toInt256(uint256 value) internal pure returns (int256) {\n // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n if (value > uint256(type(int256).max)) {\n revert SafeCastOverflowedUintToInt(value);\n }\n return int256(value);\n }\n\n /**\n * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.\n */\n function toUint(bool b) internal pure returns (uint256 u) {\n assembly (\"memory-safe\") {\n u := iszero(iszero(b))\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/SignedMath.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol)\n\npragma solidity ^0.8.20;\n\nimport {SafeCast} from \"./SafeCast.sol\";\n\n/**\n * @dev Standard signed math utilities missing in the Solidity language.\n */\nlibrary SignedMath {\n /**\n * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.\n *\n * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.\n * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute\n * one branch when needed, making this function more expensive.\n */\n function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {\n unchecked {\n // branchless ternary works because:\n // b ^ (a ^ b) == a\n // b ^ 0 == b\n return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));\n }\n }\n\n /**\n * @dev Returns the largest of two signed numbers.\n */\n function max(int256 a, int256 b) internal pure returns (int256) {\n return ternary(a > b, a, b);\n }\n\n /**\n * @dev Returns the smallest of two signed numbers.\n */\n function min(int256 a, int256 b) internal pure returns (int256) {\n return ternary(a < b, a, b);\n }\n\n /**\n * @dev Returns the average of two signed numbers without overflow.\n * The result is rounded towards zero.\n */\n function average(int256 a, int256 b) internal pure returns (int256) {\n // Formula from the book \"Hacker's Delight\"\n int256 x = (a & b) + ((a ^ b) >> 1);\n return x + (int256(uint256(x) >> 255) & (a ^ b));\n }\n\n /**\n * @dev Returns the absolute unsigned value of a signed value.\n */\n function abs(int256 n) internal pure returns (uint256) {\n unchecked {\n // Formula from the \"Bit Twiddling Hacks\" by Sean Eron Anderson.\n // Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,\n // taking advantage of the most significant (or \"sign\" bit) in two's complement representation.\n // This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,\n // the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative).\n int256 mask = n >> 255;\n\n // A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.\n return uint256((n + mask) ^ mask);\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Panic.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Helper library for emitting standardized panic codes.\n *\n * ```solidity\n * contract Example {\n * using Panic for uint256;\n *\n * // Use any of the declared internal constants\n * function foo() { Panic.GENERIC.panic(); }\n *\n * // Alternatively\n * function foo() { Panic.panic(Panic.GENERIC); }\n * }\n * ```\n *\n * Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].\n *\n * _Available since v5.1._\n */\n// slither-disable-next-line unused-state\nlibrary Panic {\n /// @dev generic / unspecified error\n uint256 internal constant GENERIC = 0x00;\n /// @dev used by the assert() builtin\n uint256 internal constant ASSERT = 0x01;\n /// @dev arithmetic underflow or overflow\n uint256 internal constant UNDER_OVERFLOW = 0x11;\n /// @dev division or modulo by zero\n uint256 internal constant DIVISION_BY_ZERO = 0x12;\n /// @dev enum conversion error\n uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;\n /// @dev invalid encoding in storage\n uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;\n /// @dev empty array pop\n uint256 internal constant EMPTY_ARRAY_POP = 0x31;\n /// @dev array out of bounds access\n uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;\n /// @dev resource error (too large allocation or too large array)\n uint256 internal constant RESOURCE_ERROR = 0x41;\n /// @dev calling invalid internal function\n uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;\n\n /// @dev Reverts with a panic code. Recommended to use with\n /// the internal constants with predefined codes.\n function panic(uint256 code) internal pure {\n assembly (\"memory-safe\") {\n mstore(0x00, 0x4e487b71)\n mstore(0x20, code)\n revert(0x1c, 0x24)\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/ReentrancyGuard.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,\n * consider using {ReentrancyGuardTransient} instead.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant NOT_ENTERED = 1;\n uint256 private constant ENTERED = 2;\n\n uint256 private _status;\n\n /**\n * @dev Unauthorized reentrant call.\n */\n error ReentrancyGuardReentrantCall();\n\n constructor() {\n _status = NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and making it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n _nonReentrantBefore();\n _;\n _nonReentrantAfter();\n }\n\n function _nonReentrantBefore() private {\n // On the first call to nonReentrant, _status will be NOT_ENTERED\n if (_status == ENTERED) {\n revert ReentrancyGuardReentrantCall();\n }\n\n // Any calls to nonReentrant after this point will fail\n _status = ENTERED;\n }\n\n function _nonReentrantAfter() private {\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = NOT_ENTERED;\n }\n\n /**\n * @dev Returns true if the reentrancy guard is currently set to \"entered\", which indicates there is a\n * `nonReentrant` function in the call stack.\n */\n function _reentrancyGuardEntered() internal view returns (bool) {\n return _status == ENTERED;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/ShortStrings.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/ShortStrings.sol)\n\npragma solidity ^0.8.20;\n\nimport {StorageSlot} from \"./StorageSlot.sol\";\n\n// | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |\n// | length | 0x BB |\ntype ShortString is bytes32;\n\n/**\n * @dev This library provides functions to convert short memory strings\n * into a `ShortString` type that can be used as an immutable variable.\n *\n * Strings of arbitrary length can be optimized using this library if\n * they are short enough (up to 31 bytes) by packing them with their\n * length (1 byte) in a single EVM word (32 bytes). Additionally, a\n * fallback mechanism can be used for every other case.\n *\n * Usage example:\n *\n * ```solidity\n * contract Named {\n * using ShortStrings for *;\n *\n * ShortString private immutable _name;\n * string private _nameFallback;\n *\n * constructor(string memory contractName) {\n * _name = contractName.toShortStringWithFallback(_nameFallback);\n * }\n *\n * function name() external view returns (string memory) {\n * return _name.toStringWithFallback(_nameFallback);\n * }\n * }\n * ```\n */\nlibrary ShortStrings {\n // Used as an identifier for strings longer than 31 bytes.\n bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;\n\n error StringTooLong(string str);\n error InvalidShortString();\n\n /**\n * @dev Encode a string of at most 31 chars into a `ShortString`.\n *\n * This will trigger a `StringTooLong` error is the input string is too long.\n */\n function toShortString(string memory str) internal pure returns (ShortString) {\n bytes memory bstr = bytes(str);\n if (bstr.length > 31) {\n revert StringTooLong(str);\n }\n return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));\n }\n\n /**\n * @dev Decode a `ShortString` back to a \"normal\" string.\n */\n function toString(ShortString sstr) internal pure returns (string memory) {\n uint256 len = byteLength(sstr);\n // using `new string(len)` would work locally but is not memory safe.\n string memory str = new string(32);\n assembly (\"memory-safe\") {\n mstore(str, len)\n mstore(add(str, 0x20), sstr)\n }\n return str;\n }\n\n /**\n * @dev Return the length of a `ShortString`.\n */\n function byteLength(ShortString sstr) internal pure returns (uint256) {\n uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;\n if (result > 31) {\n revert InvalidShortString();\n }\n return result;\n }\n\n /**\n * @dev Encode a string into a `ShortString`, or write it to storage if it is too long.\n */\n function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {\n if (bytes(value).length < 32) {\n return toShortString(value);\n } else {\n StorageSlot.getStringSlot(store).value = value;\n return ShortString.wrap(FALLBACK_SENTINEL);\n }\n }\n\n /**\n * @dev Decode a string that was encoded to `ShortString` or written to storage using {toShortStringWithFallback}.\n */\n function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {\n if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {\n return toString(value);\n } else {\n return store;\n }\n }\n\n /**\n * @dev Return the length of a string that was encoded to `ShortString` or written to storage using\n * {toShortStringWithFallback}.\n *\n * WARNING: This will return the \"byte length\" of the string. This may not reflect the actual length in terms of\n * actual characters as the UTF-8 encoding of a single character can span over multiple bytes.\n */\n function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {\n if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {\n return byteLength(value);\n } else {\n return bytes(store).length;\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/StorageSlot.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)\n// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Library for reading and writing primitive types to specific storage slots.\n *\n * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\n * This library helps with reading and writing to such slots without the need for inline assembly.\n *\n * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\n *\n * Example usage to set ERC-1967 implementation slot:\n * ```solidity\n * contract ERC1967 {\n * // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.\n * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n *\n * function _getImplementation() internal view returns (address) {\n * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n * }\n *\n * function _setImplementation(address newImplementation) internal {\n * require(newImplementation.code.length > 0);\n * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n * }\n * }\n * ```\n *\n * TIP: Consider using this library along with {SlotDerivation}.\n */\nlibrary StorageSlot {\n struct AddressSlot {\n address value;\n }\n\n struct BooleanSlot {\n bool value;\n }\n\n struct Bytes32Slot {\n bytes32 value;\n }\n\n struct Uint256Slot {\n uint256 value;\n }\n\n struct Int256Slot {\n int256 value;\n }\n\n struct StringSlot {\n string value;\n }\n\n struct BytesSlot {\n bytes value;\n }\n\n /**\n * @dev Returns an `AddressSlot` with member `value` located at `slot`.\n */\n function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `BooleanSlot` with member `value` located at `slot`.\n */\n function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Bytes32Slot` with member `value` located at `slot`.\n */\n function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Uint256Slot` with member `value` located at `slot`.\n */\n function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Int256Slot` with member `value` located at `slot`.\n */\n function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `StringSlot` with member `value` located at `slot`.\n */\n function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `StringSlot` representation of the string storage pointer `store`.\n */\n function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := store.slot\n }\n }\n\n /**\n * @dev Returns a `BytesSlot` with member `value` located at `slot`.\n */\n function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.\n */\n function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := store.slot\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Strings.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/Strings.sol)\n\npragma solidity ^0.8.20;\n\nimport {Math} from \"./math/Math.sol\";\nimport {SafeCast} from \"./math/SafeCast.sol\";\nimport {SignedMath} from \"./math/SignedMath.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n using SafeCast for *;\n\n bytes16 private constant HEX_DIGITS = \"0123456789abcdef\";\n uint8 private constant ADDRESS_LENGTH = 20;\n uint256 private constant SPECIAL_CHARS_LOOKUP =\n (1 << 0x08) | // backspace\n (1 << 0x09) | // tab\n (1 << 0x0a) | // newline\n (1 << 0x0c) | // form feed\n (1 << 0x0d) | // carriage return\n (1 << 0x22) | // double quote\n (1 << 0x5c); // backslash\n\n /**\n * @dev The `value` string doesn't fit in the specified `length`.\n */\n error StringsInsufficientHexLength(uint256 value, uint256 length);\n\n /**\n * @dev The string being parsed contains characters that are not in scope of the given base.\n */\n error StringsInvalidChar();\n\n /**\n * @dev The string being parsed is not a properly formatted address.\n */\n error StringsInvalidAddressFormat();\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n unchecked {\n uint256 length = Math.log10(value) + 1;\n string memory buffer = new string(length);\n uint256 ptr;\n assembly (\"memory-safe\") {\n ptr := add(buffer, add(32, length))\n }\n while (true) {\n ptr--;\n assembly (\"memory-safe\") {\n mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))\n }\n value /= 10;\n if (value == 0) break;\n }\n return buffer;\n }\n }\n\n /**\n * @dev Converts a `int256` to its ASCII `string` decimal representation.\n */\n function toStringSigned(int256 value) internal pure returns (string memory) {\n return string.concat(value < 0 ? \"-\" : \"\", toString(SignedMath.abs(value)));\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n unchecked {\n return toHexString(value, Math.log256(value) + 1);\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n uint256 localValue = value;\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = HEX_DIGITS[localValue & 0xf];\n localValue >>= 4;\n }\n if (localValue != 0) {\n revert StringsInsufficientHexLength(value, length);\n }\n return string(buffer);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal\n * representation.\n */\n function toHexString(address addr) internal pure returns (string memory) {\n return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal\n * representation, according to EIP-55.\n */\n function toChecksumHexString(address addr) internal pure returns (string memory) {\n bytes memory buffer = bytes(toHexString(addr));\n\n // hash the hex part of buffer (skip length + 2 bytes, length 40)\n uint256 hashValue;\n assembly (\"memory-safe\") {\n hashValue := shr(96, keccak256(add(buffer, 0x22), 40))\n }\n\n for (uint256 i = 41; i > 1; --i) {\n // possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)\n if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {\n // case shift by xoring with 0x20\n buffer[i] ^= 0x20;\n }\n hashValue >>= 4;\n }\n return string(buffer);\n }\n\n /**\n * @dev Returns true if the two strings are equal.\n */\n function equal(string memory a, string memory b) internal pure returns (bool) {\n return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));\n }\n\n /**\n * @dev Parse a decimal string and returns the value as a `uint256`.\n *\n * Requirements:\n * - The string must be formatted as `[0-9]*`\n * - The result must fit into an `uint256` type\n */\n function parseUint(string memory input) internal pure returns (uint256) {\n return parseUint(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseUint-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `[0-9]*`\n * - The result must fit into an `uint256` type\n */\n function parseUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {\n (bool success, uint256 value) = tryParseUint(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseUint-string} that returns false if the parsing fails because of an invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseUint(string memory input) internal pure returns (bool success, uint256 value) {\n return _tryParseUintUncheckedBounds(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseUint-string-uint256-uint256} that returns false if the parsing fails because of an invalid\n * character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseUint(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, uint256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseUintUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseUint-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseUintUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, uint256 value) {\n bytes memory buffer = bytes(input);\n\n uint256 result = 0;\n for (uint256 i = begin; i < end; ++i) {\n uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));\n if (chr > 9) return (false, 0);\n result *= 10;\n result += chr;\n }\n return (true, result);\n }\n\n /**\n * @dev Parse a decimal string and returns the value as a `int256`.\n *\n * Requirements:\n * - The string must be formatted as `[-+]?[0-9]*`\n * - The result must fit in an `int256` type.\n */\n function parseInt(string memory input) internal pure returns (int256) {\n return parseInt(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseInt-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `[-+]?[0-9]*`\n * - The result must fit in an `int256` type.\n */\n function parseInt(string memory input, uint256 begin, uint256 end) internal pure returns (int256) {\n (bool success, int256 value) = tryParseInt(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseInt-string} that returns false if the parsing fails because of an invalid character or if\n * the result does not fit in a `int256`.\n *\n * NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.\n */\n function tryParseInt(string memory input) internal pure returns (bool success, int256 value) {\n return _tryParseIntUncheckedBounds(input, 0, bytes(input).length);\n }\n\n uint256 private constant ABS_MIN_INT256 = 2 ** 255;\n\n /**\n * @dev Variant of {parseInt-string-uint256-uint256} that returns false if the parsing fails because of an invalid\n * character or if the result does not fit in a `int256`.\n *\n * NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.\n */\n function tryParseInt(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, int256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseIntUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseInt-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseIntUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, int256 value) {\n bytes memory buffer = bytes(input);\n\n // Check presence of a negative sign.\n bytes1 sign = begin == end ? bytes1(0) : bytes1(_unsafeReadBytesOffset(buffer, begin)); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n bool positiveSign = sign == bytes1(\"+\");\n bool negativeSign = sign == bytes1(\"-\");\n uint256 offset = (positiveSign || negativeSign).toUint();\n\n (bool absSuccess, uint256 absValue) = tryParseUint(input, begin + offset, end);\n\n if (absSuccess && absValue < ABS_MIN_INT256) {\n return (true, negativeSign ? -int256(absValue) : int256(absValue));\n } else if (absSuccess && negativeSign && absValue == ABS_MIN_INT256) {\n return (true, type(int256).min);\n } else return (false, 0);\n }\n\n /**\n * @dev Parse a hexadecimal string (with or without \"0x\" prefix), and returns the value as a `uint256`.\n *\n * Requirements:\n * - The string must be formatted as `(0x)?[0-9a-fA-F]*`\n * - The result must fit in an `uint256` type.\n */\n function parseHexUint(string memory input) internal pure returns (uint256) {\n return parseHexUint(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseHexUint-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `(0x)?[0-9a-fA-F]*`\n * - The result must fit in an `uint256` type.\n */\n function parseHexUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {\n (bool success, uint256 value) = tryParseHexUint(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseHexUint-string} that returns false if the parsing fails because of an invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseHexUint(string memory input) internal pure returns (bool success, uint256 value) {\n return _tryParseHexUintUncheckedBounds(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseHexUint-string-uint256-uint256} that returns false if the parsing fails because of an\n * invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseHexUint(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, uint256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseHexUintUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseHexUint-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseHexUintUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, uint256 value) {\n bytes memory buffer = bytes(input);\n\n // skip 0x prefix if present\n bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(buffer, begin)) == bytes2(\"0x\"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n uint256 offset = hasPrefix.toUint() * 2;\n\n uint256 result = 0;\n for (uint256 i = begin + offset; i < end; ++i) {\n uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));\n if (chr > 15) return (false, 0);\n result *= 16;\n unchecked {\n // Multiplying by 16 is equivalent to a shift of 4 bits (with additional overflow check).\n // This guarantees that adding a value < 16 will not cause an overflow, hence the unchecked.\n result += chr;\n }\n }\n return (true, result);\n }\n\n /**\n * @dev Parse a hexadecimal string (with or without \"0x\" prefix), and returns the value as an `address`.\n *\n * Requirements:\n * - The string must be formatted as `(0x)?[0-9a-fA-F]{40}`\n */\n function parseAddress(string memory input) internal pure returns (address) {\n return parseAddress(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseAddress-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `(0x)?[0-9a-fA-F]{40}`\n */\n function parseAddress(string memory input, uint256 begin, uint256 end) internal pure returns (address) {\n (bool success, address value) = tryParseAddress(input, begin, end);\n if (!success) revert StringsInvalidAddressFormat();\n return value;\n }\n\n /**\n * @dev Variant of {parseAddress-string} that returns false if the parsing fails because the input is not a properly\n * formatted address. See {parseAddress-string} requirements.\n */\n function tryParseAddress(string memory input) internal pure returns (bool success, address value) {\n return tryParseAddress(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseAddress-string-uint256-uint256} that returns false if the parsing fails because input is not a properly\n * formatted address. See {parseAddress-string-uint256-uint256} requirements.\n */\n function tryParseAddress(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, address value) {\n if (end > bytes(input).length || begin > end) return (false, address(0));\n\n bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(bytes(input), begin)) == bytes2(\"0x\"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n uint256 expectedLength = 40 + hasPrefix.toUint() * 2;\n\n // check that input is the correct length\n if (end - begin == expectedLength) {\n // length guarantees that this does not overflow, and value is at most type(uint160).max\n (bool s, uint256 v) = _tryParseHexUintUncheckedBounds(input, begin, end);\n return (s, address(uint160(v)));\n } else {\n return (false, address(0));\n }\n }\n\n function _tryParseChr(bytes1 chr) private pure returns (uint8) {\n uint8 value = uint8(chr);\n\n // Try to parse `chr`:\n // - Case 1: [0-9]\n // - Case 2: [a-f]\n // - Case 3: [A-F]\n // - otherwise not supported\n unchecked {\n if (value > 47 && value < 58) value -= 48;\n else if (value > 96 && value < 103) value -= 87;\n else if (value > 64 && value < 71) value -= 55;\n else return type(uint8).max;\n }\n\n return value;\n }\n\n /**\n * @dev Escape special characters in JSON strings. This can be useful to prevent JSON injection in NFT metadata.\n *\n * WARNING: This function should only be used in double quoted JSON strings. Single quotes are not escaped.\n *\n * NOTE: This function escapes all unicode characters, and not just the ones in ranges defined in section 2.5 of\n * RFC-4627 (U+0000 to U+001F, U+0022 and U+005C). ECMAScript's `JSON.parse` does recover escaped unicode\n * characters that are not in this range, but other tooling may provide different results.\n */\n function escapeJSON(string memory input) internal pure returns (string memory) {\n bytes memory buffer = bytes(input);\n bytes memory output = new bytes(2 * buffer.length); // worst case scenario\n uint256 outputLength = 0;\n\n for (uint256 i; i < buffer.length; ++i) {\n bytes1 char = bytes1(_unsafeReadBytesOffset(buffer, i));\n if (((SPECIAL_CHARS_LOOKUP & (1 << uint8(char))) != 0)) {\n output[outputLength++] = \"\\\\\";\n if (char == 0x08) output[outputLength++] = \"b\";\n else if (char == 0x09) output[outputLength++] = \"t\";\n else if (char == 0x0a) output[outputLength++] = \"n\";\n else if (char == 0x0c) output[outputLength++] = \"f\";\n else if (char == 0x0d) output[outputLength++] = \"r\";\n else if (char == 0x5c) output[outputLength++] = \"\\\\\";\n else if (char == 0x22) {\n // solhint-disable-next-line quotes\n output[outputLength++] = '\"';\n }\n } else {\n output[outputLength++] = char;\n }\n }\n // write the actual length and deallocate unused memory\n assembly (\"memory-safe\") {\n mstore(output, outputLength)\n mstore(0x40, add(output, shl(5, shr(5, add(outputLength, 63)))))\n }\n\n return string(output);\n }\n\n /**\n * @dev Reads a bytes32 from a bytes array without bounds checking.\n *\n * NOTE: making this function internal would mean it could be used with memory unsafe offset, and marking the\n * assembly block as such would prevent some optimizations.\n */\n function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {\n // This is not memory safe in the general case, but all calls to this private function are within bounds.\n assembly (\"memory-safe\") {\n value := mload(add(buffer, add(0x20, offset)))\n }\n }\n}\n" + }, + "project/contracts/Controller.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\n\nimport './interfaces/IController.sol';\n\n/**\n * @title Controller\n * @dev Manages allow lists for solvers, executors, proposal signers and validators\n */\ncontract Controller is IController, Ownable {\n // List of allowed solvers\n mapping (address => bool) public override isSolverAllowed;\n\n // List of allowed executors\n mapping (address => bool) public override isExecutorAllowed;\n\n // List of allowed proposal signers\n mapping (address => bool) public override isProposalSignerAllowed;\n\n // List of allowed validators\n mapping (address => bool) public override isValidatorAllowed;\n\n // Minimum number of validations allowed\n uint8 public override minValidations;\n\n /**\n * @dev Creates a new Controller contract\n * @param owner Address that will own the contract\n * @param solvers List of allowed solvers\n * @param executors List of allowed executors\n * @param proposalSigners List of allowed proposal signers\n * @param validators List of allowed validators\n * @param _minValidations Minimum number of validations allowed\n */\n constructor(\n address owner,\n address[] memory solvers,\n address[] memory executors,\n address[] memory proposalSigners,\n address[] memory validators,\n uint8 _minValidations\n ) Ownable(owner) {\n for (uint256 i = 0; i < solvers.length; i++) _setAllowedSolver(solvers[i], true);\n for (uint256 i = 0; i < executors.length; i++) _setAllowedExecutor(executors[i], true);\n for (uint256 i = 0; i < proposalSigners.length; i++) _setAllowedProposalSigner(proposalSigners[i], true);\n for (uint256 i = 0; i < validators.length; i++) _setAllowedValidator(validators[i], true);\n _setMinValidations(_minValidations);\n }\n\n /**\n * @dev Sets permissions for multiple solvers\n * @param solvers List of solver addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedSolvers(address[] memory solvers, bool[] memory alloweds) external override onlyOwner {\n if (solvers.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < solvers.length; i++) _setAllowedSolver(solvers[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple executors\n * @param executors List of executor addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedExecutors(address[] memory executors, bool[] memory alloweds) external override onlyOwner {\n if (executors.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < executors.length; i++) _setAllowedExecutor(executors[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple proposal signers\n * @param signers List of proposal signer addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedProposalSigners(address[] memory signers, bool[] memory alloweds) external override onlyOwner {\n if (signers.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < signers.length; i++) _setAllowedProposalSigner(signers[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple validators\n * @param validators List of validator addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedValidators(address[] memory validators, bool[] memory alloweds) external override onlyOwner {\n if (validators.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < validators.length; i++) _setAllowedValidator(validators[i], alloweds[i]);\n }\n\n /**\n * @dev Sets the minimum number of validations allowed\n * @param newMinValidations minimum number of validations allowed\n */\n function setMinValidations(uint8 newMinValidations) external override onlyOwner {\n _setMinValidations(newMinValidations);\n }\n\n /**\n * @dev Sets a solver permission\n */\n function _setAllowedSolver(address solver, bool allowed) internal {\n isSolverAllowed[solver] = allowed;\n emit SolverAllowedSet(solver, allowed);\n }\n\n /**\n * @dev Sets an executor permission\n */\n function _setAllowedExecutor(address executor, bool allowed) internal {\n isExecutorAllowed[executor] = allowed;\n emit ExecutorAllowedSet(executor, allowed);\n }\n\n /**\n * @dev Sets a proposal signer permission\n */\n function _setAllowedProposalSigner(address signer, bool allowed) internal {\n isProposalSignerAllowed[signer] = allowed;\n emit ProposalSignerAllowedSet(signer, allowed);\n }\n\n /**\n * @dev Sets a validator permission\n */\n function _setAllowedValidator(address validator, bool allowed) internal {\n isValidatorAllowed[validator] = allowed;\n emit ValidatorAllowedSet(validator, allowed);\n }\n\n /**\n * @dev Sets the minimum number of validations allowed\n */\n function _setMinValidations(uint8 newMinValidations) internal {\n minValidations = newMinValidations;\n emit MinValidationSet(newMinValidations);\n }\n}\n" + }, + "project/contracts/Intents.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Enum representing the type of intent operation.\n * - Swap: Swap tokens between chains or tokens.\n * - Transfer: Transfer tokens to one or more recipients.\n * - Call: Execute arbitrary contract calls.\n */\nenum OpType {\n Swap,\n Transfer,\n Call\n}\n\n/**\n * @dev Execution structure.\n * @param intent Intent to be fulfilled.\n * @param proposal Proposal to be executed.\n * @param signature Proposal signature.\n */\nstruct Execution {\n Intent intent;\n Proposal proposal;\n bytes signature;\n}\n\n/**\n * @dev EIP-712 typed data struct representing a validator's approval of an intent.\n * @param intent The hash of the intent being validated.\n */\nstruct Validation {\n bytes32 intent;\n}\n\n/**\n * @dev General intent structure used to abstract over different intent types.\n * @param op The type of operation this intent represents.\n * @param user The originator of the intent.\n * @param settler The address responsible for executing the intent on-chain.\n * @param nonce A unique value used to prevent replay attacks and distinguish intents.\n * @param deadline The timestamp by which the intent must be executed.\n * @param data ABI-encoded data representing a specific intent type (e.g. SwapIntent, TransferIntent, CallIntent).\n * @param maxFees List of max fees the user is willing to pay for the intent.\n * @param events List of custom intent events to be emitted.\n * @param configSig The signature of the configuration that this intent belongs to\n * @param minValidations The minimum number of validator approvals required for this intent to be considered valid.\n * @param validations The list validator signatures attesting to this intent.\n */\nstruct Intent {\n uint8 op;\n address user;\n address settler;\n bytes32 nonce;\n uint256 deadline;\n bytes data;\n MaxFee[] maxFees;\n IntentEvent[] events;\n bytes configSig;\n uint256 minValidations;\n bytes[] validations;\n}\n\n/**\n * @dev Max fee representation\n * @param token Token used to pay for the execution fee.\n * @param amount Max amount of fee token to be paid for settling this intent.\n */\nstruct MaxFee {\n address token;\n uint256 amount;\n}\n\n/**\n * @dev Intent event representation.\n * @param topic Event topic to be emitted.\n * @param data Event data to be emitted.\n */\nstruct IntentEvent {\n bytes32 topic;\n bytes data;\n}\n\n/**\n * @dev Represents a swap intent between two chains.\n * @param sourceChain Chain ID where tokens will be sent from.\n * @param destinationChain Chain ID where tokens will be received.\n * @param tokensIn List of input tokens and amounts to swap.\n * @param tokensOut List of expected output tokens, minimum amounts, and recipients.\n */\nstruct SwapIntent {\n uint256 sourceChain;\n uint256 destinationChain;\n TokenIn[] tokensIn;\n TokenOut[] tokensOut;\n}\n\n/**\n * @dev Token in representation.\n * @param token Address of a token to be sent.\n * @param amount Amount of tokens to be sent.\n */\nstruct TokenIn {\n address token;\n uint256 amount;\n}\n\n/**\n * @dev Token out representation.\n * @param token Address of a token to be received.\n * @param minAmount Minimum amount of tokens to be received.\n * @param recipient Recipient address that will receive the token out.\n */\nstruct TokenOut {\n address token;\n uint256 minAmount;\n address recipient;\n}\n\n/**\n * @dev Represents a transfer intent containing multiple token transfers.\n * @param chainId Chain ID where the transfers should be executed.\n * @param transfers List of token transfers to be performed.\n */\nstruct TransferIntent {\n uint256 chainId;\n TransferData[] transfers;\n}\n\n/**\n * @dev Transfer data for a single token transfer.\n * @param token Address of the token to transfer.\n * @param amount Amount of the token to transfer.\n * @param recipient Recipient of the token transfer.\n */\nstruct TransferData {\n address token;\n uint256 amount;\n address recipient;\n}\n\n/**\n * @dev Represents a generic call intent consisting of one or more contract calls.\n * @param chainId Chain ID where the calls should be executed.\n * @param calls List of low-level contract calls to be executed.\n */\nstruct CallIntent {\n uint256 chainId;\n CallData[] calls;\n}\n\n/**\n * @dev Low-level call data for a target contract interaction.\n * @param target Target contract address.\n * @param data Calldata to be sent to the target.\n * @param value ETH value to send along with the call.\n */\nstruct CallData {\n address target;\n bytes data;\n uint256 value;\n}\n\n/**\n * @dev Generic proposal structure representing a solver’s response to an intent.\n * @param deadline Timestamp until when the proposal is valid.\n * @param data ABI-encoded proposal-specific data (e.g. SwapProposal).\n * @param fees List of fee amounts the solver requires for execution.\n */\nstruct Proposal {\n uint256 deadline;\n bytes data;\n uint256[] fees;\n}\n\n/**\n * @dev Swap proposal representation for a swap intent.\n * @param executor Address of the executor contract that should be called during intent execution.\n * @param data Arbitrary data used to call the executor contract.\n * @param amountsOut List of amounts of tokens out proposed by the solver.\n */\nstruct SwapProposal {\n address executor;\n bytes data;\n uint256[] amountsOut;\n}\n\nlibrary IntentsHelpers {\n bytes32 internal constant INTENT_TYPE_HASH =\n keccak256(\n 'Intent(uint8 op,address user,address settler,bytes32 nonce,uint256 deadline,bytes data,MaxFee[] maxFees,IntentEvent[] events,bytes configSig,uint256 minValidations)IntentEvent(bytes32 topic,bytes data)MaxFee(address token,uint256 amount)'\n );\n\n bytes32 internal constant PROPOSAL_TYPE_HASH =\n keccak256('Proposal(bytes32 intent,address solver,uint256 deadline,bytes data,uint256[] fees)');\n\n bytes32 internal constant VALIDATION_TYPE_HASH = keccak256('Validation(bytes32 intent)');\n\n bytes32 internal constant MAX_FEE_TYPE_HASH = keccak256('MaxFee(address token,uint256 amount)');\n\n bytes32 internal constant INTENT_EVENT_TYPE_HASH = keccak256('IntentEvent(bytes32 topic,bytes data)');\n\n function hash(Intent memory intent) internal pure returns (bytes32) {\n return\n keccak256(\n abi.encode(\n INTENT_TYPE_HASH,\n intent.op,\n intent.user,\n intent.settler,\n intent.nonce,\n intent.deadline,\n keccak256(intent.data),\n hash(intent.maxFees),\n hash(intent.events),\n intent.configSig,\n intent.minValidations\n )\n );\n }\n\n function hash(Proposal memory proposal, Intent memory intent, address solver) internal pure returns (bytes32) {\n return\n keccak256(\n abi.encode(\n PROPOSAL_TYPE_HASH,\n hash(intent),\n solver,\n proposal.deadline,\n keccak256(proposal.data),\n hash(proposal.fees)\n )\n );\n }\n\n function hash(MaxFee[] memory fees) internal pure returns (bytes32) {\n bytes32[] memory hashes = new bytes32[](fees.length);\n for (uint256 i = 0; i < fees.length; i++) {\n hashes[i] = keccak256(abi.encode(MAX_FEE_TYPE_HASH, fees[i].token, fees[i].amount));\n }\n return keccak256(abi.encodePacked(hashes));\n }\n\n function hash(IntentEvent[] memory events) internal pure returns (bytes32) {\n bytes32[] memory hashes = new bytes32[](events.length);\n for (uint256 i = 0; i < events.length; i++) {\n hashes[i] = keccak256(abi.encode(INTENT_EVENT_TYPE_HASH, events[i].topic, keccak256(events[i].data)));\n }\n return keccak256(abi.encodePacked(hashes));\n }\n\n function hash(uint256[] memory fees) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(fees));\n }\n\n function hash(Validation memory validation) internal pure returns (bytes32) {\n return keccak256(abi.encode(VALIDATION_TYPE_HASH, validation.intent));\n }\n}\n" + }, + "project/contracts/interfaces/IController.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @title Controller interface\n */\ninterface IController {\n /**\n * @dev The input arrays are not of equal length\n */\n error ControllerInputInvalidLength();\n\n /**\n * @dev Emitted every time a solver permission is set\n */\n event SolverAllowedSet(address indexed solver, bool allowed);\n\n /**\n * @dev Emitted every time an executor permission is set\n */\n event ExecutorAllowedSet(address indexed executor, bool allowed);\n\n /**\n * @dev Emitted every time a proposal signer permission is set\n */\n event ProposalSignerAllowedSet(address indexed proposalSigner, bool allowed);\n\n /**\n * @dev Emitted every time a validator permission is set\n */\n event ValidatorAllowedSet(address indexed validator, bool allowed);\n\n /**\n * @dev Emitted when the minimum validations changes\n */\n event MinValidationSet(uint8 indexed newMinValidation);\n\n /**\n * @dev Tells whether a solver is allowed\n * @param solver Address of the solver being queried\n */\n function isSolverAllowed(address solver) external view returns (bool);\n\n /**\n * @dev Tells whether an executor is allowed\n * @param executor Address of the executor being queried\n */\n function isExecutorAllowed(address executor) external view returns (bool);\n\n /**\n * @dev Tells whether a proposal signer is allowed\n * @param signer Address of the proposal signer being queried\n */\n function isProposalSignerAllowed(address signer) external view returns (bool);\n\n /**\n * @dev Tells whether a validator is allowed\n * @param validator Address of the validator being queried\n */\n function isValidatorAllowed(address validator) external view returns (bool);\n\n /**\n * @dev Tells the minimum number of validations allowed\n */\n function minValidations() external view returns (uint8);\n\n /**\n * @dev Sets permissions for multiple solvers\n * @param solvers List of solver addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedSolvers(address[] memory solvers, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple executors\n * @param executors List of executor addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedExecutors(address[] memory executors, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple proposal signers\n * @param signers List of proposal signer addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedProposalSigners(address[] memory signers, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple validators\n * @param validators List of validator addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedValidators(address[] memory validators, bool[] memory alloweds) external;\n\n /**\n * @dev Sets the minimum number of validations allowed\n * @param newMinValidations minimum number of validations allowed\n */\n function setMinValidations(uint8 newMinValidations) external;\n}\n" + }, + "project/contracts/interfaces/ICreateX.sol": { + "content": "// SPDX-License-Identifier: AGPL-3.0-only\n\npragma solidity ^0.8.4;\n\n/**\n * @title CreateX Factory Interface Definition\n * @author pcaversaccio (https://web.archive.org/web/20230921103111/https://pcaversaccio.com/)\n * @custom:coauthor Matt Solomon (https://web.archive.org/web/20230921103335/https://mattsolomon.dev/)\n */\ninterface ICreateX {\n event ContractCreation(address indexed newContract);\n\n function deployCreate3(bytes32 salt, bytes memory initCode) external payable returns (address newContract);\n}\n" + }, + "project/contracts/interfaces/IExecutor.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\n\n/**\n * @title Executor interface\n */\ninterface IExecutor {\n /**\n * @dev Executes an intent proposal\n * @param intent Intent to be executed\n * @param proposal Proposal to be executed to fulfill the intent\n */\n function execute(Intent memory intent, Proposal memory proposal) external;\n}\n" + }, + "project/contracts/interfaces/IIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\nimport '../safeguards/Safeguards.sol';\n\n/**\n * @title IntentsValidator\n * @dev Performs intents validations based on safeguards\n */\ninterface IIntentsValidator {\n /**\n * @dev Validates an intent for a safeguard\n * @param intent Intent to be validated\n * @param config Safeguard config to validate the intent with\n */\n function validate(Intent memory intent, bytes memory config) external pure;\n}\n" + }, + "project/contracts/interfaces/ISafe.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nenum SafeOperation {\n Call,\n DelegateCall\n}\n\ninterface ISafe {\n function getThreshold() external view returns (uint256);\n\n function execTransactionFromModuleReturnData(address to, uint256 value, bytes memory data, SafeOperation operation)\n external\n returns (bool success, bytes memory returnData);\n}\n" + }, + "project/contracts/interfaces/ISettler.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\nimport '../safeguards/Safeguards.sol';\n\n/**\n * @title Settler interface\n */\ninterface ISettler {\n /**\n * @dev The requested intent type is unknown\n */\n error SettlerUnknownIntentType(uint8 op);\n\n /**\n * @dev The simulation has been successful\n */\n error SettlerSimulationSuccess(uint256 gasUsed);\n\n /**\n * @dev The solver is not allowed\n */\n error SettlerSolverNotAllowed(address solver);\n\n /**\n * @dev The executor is not allowed\n */\n error SettlerExecutorNotAllowed(address executor);\n\n /**\n * @dev The proposal signer is not allowed\n */\n error SettlerProposalSignerNotAllowed(address signer);\n\n /**\n * @dev The validator is not allowed\n */\n error SettlerValidatorNotAllowed(address validator);\n\n /**\n * @dev The validator is duplicated\n */\n error SettlerValidatorDuplicatedOrUnsorted(address previous, address current);\n\n /**\n * @dev The settler is not the current contract\n */\n error SettlerInvalidSettler(address settler);\n\n /**\n * @dev The nonce is zero\n */\n error SettlerNonceZero();\n\n /**\n * @dev The nonce has already been used for the user\n */\n error SettlerNonceAlreadyUsed(address user, bytes32 nonce);\n\n /**\n * @dev The intent deadline is in the past\n */\n error SettlerIntentPastDeadline(uint256 deadline, uint256 timestamp);\n\n /**\n * @dev The current chain is not valid\n */\n error SettlerInvalidChain(uint256 chainId);\n\n /**\n * @dev The recipient is the settler contract\n */\n error SettlerInvalidRecipient(address to);\n\n /**\n * @dev The user is not a smart account\n */\n error SettlerUserNotSmartAccount(address user);\n\n /**\n * @dev The amount out is lower than the proposed amount\n */\n error SettlerAmountOutLtProposed(uint256 index, uint256 amountOut, uint256 proposed);\n\n /**\n * @dev The proposed amount is lower than the minimum amount\n */\n error SettlerProposedAmountLtMinAmount(uint256 index, uint256 proposed, uint256 minAmount);\n\n /**\n * @dev The proposed amounts array and the tokens out array are not of equal length\n */\n error SettlerInvalidProposedAmounts();\n\n /**\n * @dev The balance after the proposal execution is lower than the balance before\n */\n error SettlerPostBalanceOutLtPre(uint256 index, uint256 post, uint256 pre);\n\n /**\n * @dev The solver fees length does not match the requested by the user\n */\n error SettlerSolverFeeInvalidLength();\n\n /**\n * @dev The solver fee is too high\n */\n error SettlerSolverFeeTooHigh(uint256 fee, uint256 max);\n\n /**\n * @dev The intent validations are not enough\n */\n error SettlerIntentValidationsNotEnough(uint256 min, uint256 current);\n\n /**\n * @dev The proposal deadline is in the past\n */\n error SettlerProposalPastDeadline(uint256 deadline, uint256 timestamp);\n\n /**\n * @dev The proposal data is not empty\n */\n error SettlerProposalDataNotEmpty();\n\n /**\n * @dev The rescue funds recipient is zero\n */\n error SettlerRescueFundsRecipientZero();\n\n /**\n * @dev The list of safeguards exceed the maximum allowed\n */\n error SettlerTooManySafeguards(uint256 lengthRequested);\n\n /**\n * @dev The new smart accounts handler is zero\n */\n error SmartAccountsHandlerZero();\n\n /**\n * @dev Custom events emitted for each intent\n */\n event IntentExecuted(\n address indexed user,\n bytes32 indexed topic,\n uint8 indexed op,\n Intent intent,\n Proposal proposal,\n bytes output,\n bytes data\n );\n\n /**\n * @dev Emitted every time an intent is fulfilled\n */\n event ProposalExecuted(bytes32 indexed proposal, uint256 index);\n\n /**\n * @dev Emitted every time tokens are withdrawn from the contract balance\n */\n event FundsRescued(address indexed token, address indexed recipient, uint256 amount);\n\n /**\n * @dev Emitted every time the smart accounts handler is set\n */\n event SmartAccountsHandlerSet(address indexed smartAccountsHandler);\n\n /**\n * @dev Emitted every time the intents validator is set\n */\n event IntentsValidatorSet(address indexed intentsValidator);\n\n /**\n * @dev Emitted every time a safeguard is set\n */\n event SafeguardSet(address indexed user);\n\n /**\n * @dev Tells the reference to the Mimic controller\n */\n function controller() external view returns (address);\n\n /**\n * @dev Tells the reference to the smart accounts handler\n */\n function smartAccountsHandler() external view returns (address);\n\n /**\n * @dev Tells the reference to the intents validator\n */\n function intentsValidator() external view returns (address);\n\n /**\n * @dev Tells the block at which a user nonce was used. Returns 0 if unused.\n * @param user Address of the user being queried\n * @param nonce Nonce being queried\n */\n function getNonceBlock(address user, bytes32 nonce) external view returns (uint256);\n\n /**\n * @dev Tells the safeguard set for a user\n * @param user Address of the user being queried\n */\n function getUserSafeguard(address user) external view returns (bytes memory);\n\n /**\n * @dev Tells the hash of an intent\n * @param intent Intent to get the hash of\n */\n function getIntentHash(Intent memory intent) external pure returns (bytes32);\n\n /**\n * @dev Tells the hash of a proposal\n * @param proposal Proposal to be hashed\n * @param intent Intent being fulfilled by the requested proposal\n * @param solver Address of the solver that made the proposal\n */\n function getProposalHash(Proposal memory proposal, Intent memory intent, address solver)\n external\n pure\n returns (bytes32);\n\n /**\n * @dev Withdraws ERC20 or native tokens from the contract\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function rescueFunds(address token, address recipient, uint256 amount) external;\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function setSmartAccountsHandler(address newSmartAccountsHandler) external;\n\n /**\n * @dev Sets a new intents validator address\n * @param newIntentsValidator New intents validator to be set\n */\n function setIntentsValidator(address newIntentsValidator) external;\n\n /**\n * @dev Sets a safeguard for a user\n * @param safeguard Safeguard to be set\n */\n function setSafeguard(bytes memory safeguard) external;\n\n /**\n * @dev Executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function execute(Execution[] memory executions) external;\n\n /**\n * @dev Simulates an execution. It will always revert. Successful executions are returned as\n * `SettlerSimulationSuccess` errors. Any other error should be treated as failure.\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function simulate(Execution[] memory executions) external;\n}\n" + }, + "project/contracts/interfaces/ISmartAccount.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/introspection/IERC165.sol';\n\n/**\n * @title SmartAccount interface\n */\ninterface ISmartAccount is IERC165 {\n /**\n * @dev Emitted every time tokens are transferred\n */\n event Transferred(address indexed token, address indexed recipient, uint256 amount);\n\n /**\n * @dev Emitted every time `call` is called\n */\n event Called(address indexed target, bytes data, uint256 value, bytes result);\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the owner or the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) external;\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the owner or the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n */\n function call(address target, bytes memory data, uint256 value) external returns (bytes memory result);\n}\n" + }, + "project/contracts/interfaces/ISmartAccountContract.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/interfaces/IERC1271.sol';\n\nimport './ISmartAccount.sol';\n\n/**\n * @title SmartAccountContract interface\n */\ninterface ISmartAccountContract is ISmartAccount, IERC1271 {\n // solhint-disable-previous-line no-empty-blocks\n}\n" + }, + "project/contracts/interfaces/ISmartAccountsHandler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\ninterface ISmartAccountsHandler {\n /**\n * @dev The smart account given is not supported\n */\n error SmartAccountsHandlerUnsupportedAccount(address account);\n\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address account) external view returns (bool);\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address account, address token, address to, uint256 amount) external;\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address account, address target, bytes memory data, uint256 value) external returns (bytes memory);\n}\n" + }, + "project/contracts/safeguards/BaseIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @title BaseIntentsValidator\n */\ncontract BaseIntentsValidator {\n /**\n * @dev No intents allowed\n */\n error IntentsValidatorNoneAllowed();\n\n /**\n * @dev Intent type unknown\n */\n error IntentsValidatorUnknownIntentType(uint8 opType);\n\n /**\n * @dev Invalid safeguard mode\n */\n error IntentsValidatorInvalidSafeguardMode(uint8 mode);\n\n /**\n * @dev Tells whether a chain is allowed\n */\n function _isChainAllowed(uint256 chainId, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, uint256[] memory values) = abi.decode(config, (bool, uint256[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (chainId == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (chainId == values[i]) return true;\n }\n return false;\n }\n }\n\n /**\n * @dev Tells whether an account is allowed\n */\n function _isAccountAllowed(address account, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, address[] memory values) = abi.decode(config, (bool, address[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (account == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (account == values[i]) return true;\n }\n return false;\n }\n }\n\n /**\n * @dev Tells whether a selector is allowed\n */\n function _isSelectorAllowed(bytes4 selector, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, bytes4[] memory values) = abi.decode(config, (bool, bytes4[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (selector == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (selector == values[i]) return true;\n }\n return false;\n }\n }\n}\n" + }, + "project/contracts/safeguards/CallIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './Safeguards.sol';\nimport './BaseIntentsValidator.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Call safeguard modes to validate call intents\n * @param None To ensure no calls are allowed\n * @param Chain To validate that the chain where calls execute is allowed\n * @param Target To validate that the call targets (contract addresses) are allowed\n * @param Selector To validate that the function selectors being called are allowed\n */\nenum CallSafeguardMode {\n None,\n Chain,\n Target,\n Selector\n}\n\n/**\n * @title CallIntentsValidator\n * @dev Performs call intents validations based on safeguards\n */\ncontract CallIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a call intent is valid for a safeguard\n * @param intent Call intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isCallIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n CallIntent memory callIntent = abi.decode(intent.data, (CallIntent));\n if (safeguard.mode == uint8(CallSafeguardMode.Chain))\n return _isChainAllowed(callIntent.chainId, safeguard.config);\n if (safeguard.mode == uint8(CallSafeguardMode.Target))\n return _areCallTargetsValid(callIntent.calls, safeguard.config);\n if (safeguard.mode == uint8(CallSafeguardMode.Selector))\n return _areCallSelectorsValid(callIntent.calls, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the call targets are allowed\n */\n function _areCallTargetsValid(CallData[] memory calls, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < calls.length; i++) {\n if (!_isAccountAllowed(calls[i].target, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the call selectors are allowed\n */\n function _areCallSelectorsValid(CallData[] memory calls, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < calls.length; i++) {\n if (!_isSelectorAllowed(bytes4(calls[i].data), config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/safeguards/IntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './CallIntentsValidator.sol';\nimport './TransferIntentsValidator.sol';\nimport './Safeguards.sol';\nimport './SwapIntentsValidator.sol';\nimport '../Intents.sol';\nimport '../interfaces/IIntentsValidator.sol';\n\n/**\n * @title IntentsValidator\n * @dev Performs intents validations based on safeguards\n */\ncontract IntentsValidator is IIntentsValidator, SwapIntentsValidator, TransferIntentsValidator, CallIntentsValidator {\n /**\n * @dev Safeguard validation failed\n */\n error IntentsValidatorSafeguardFailed();\n\n /**\n * @dev Invalid safeguard config mode\n */\n error IntentsValidatorInvalidSafeguardConfigMode(uint8 mode);\n\n /**\n * @dev Invalid safeguard group logic mode\n */\n error IntentsValidatorInvalidSafeguardGroupLogicMode(uint8 mode);\n\n /**\n * @dev Tells whether an intent is valid for a safeguard\n * @param intent Intent to be validated\n * @param config Safeguard config to validate the intent with\n */\n function validate(Intent memory intent, bytes memory config) external pure override {\n (uint8 mode, bytes memory safeguard) = abi.decode(config, (uint8, bytes));\n if (mode == uint8(SafeguardConfigMode.List)) _validate(intent, abi.decode(safeguard, (Safeguard[])));\n else if (mode == uint8(SafeguardConfigMode.Tree)) _validate(intent, _decodeSafeguardTree(safeguard));\n else revert IntentsValidatorInvalidSafeguardConfigMode(mode);\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguards list\n * @param intent Intent to be validated\n * @param safeguards Safeguard list to validate the intent with\n */\n function _validate(Intent memory intent, Safeguard[] memory safeguards) internal pure {\n if (safeguards.length == 0) revert IntentsValidatorSafeguardFailed();\n for (uint256 i = 0; i < safeguards.length; i++) {\n if (!_isSafeguardValid(intent, safeguards[i])) revert IntentsValidatorSafeguardFailed();\n }\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard tree\n * @param intent Intent to be validated\n * @param tree Safeguard tree to validate the intent with\n */\n function _validate(Intent memory intent, SafeguardTree memory tree) internal pure {\n if (tree.nodes.length == 0) revert IntentsValidatorSafeguardFailed();\n if (!_isSafeguardGroupValid(intent, tree, 0)) revert IntentsValidatorSafeguardFailed();\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard tree at a certain level\n * @param intent Intent to be validated\n * @param tree Safeguard tree to validate the intent with\n * @param index Index of the group node to evaluate\n */\n function _isSafeguardGroupValid(Intent memory intent, SafeguardTree memory tree, uint16 index)\n internal\n pure\n returns (bool)\n {\n SafeguardGroup memory group = tree.nodes[index];\n\n if (group.logic == uint8(SafeguardGroupLogic.NOT)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i])) return false;\n }\n return true;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.AND)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (!_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (!_isSafeguardGroupValid(intent, tree, group.children[i])) return false;\n }\n return true;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.OR)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return true;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i])) return true;\n }\n return false;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.XOR)) {\n uint256 hits = 0;\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]]))\n if (++hits > 1) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i]))\n if (++hits > 1) return false;\n }\n return hits == 1;\n }\n\n revert IntentsValidatorInvalidSafeguardGroupLogicMode(group.logic);\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard\n * @param intent Intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isSafeguardValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n if (safeguard.mode == uint8(0)) revert IntentsValidatorNoneAllowed();\n if (intent.op == uint8(OpType.Swap)) return _isSwapIntentValid(intent, safeguard);\n if (intent.op == uint8(OpType.Transfer)) return _isTransferIntentValid(intent, safeguard);\n if (intent.op == uint8(OpType.Call)) return _isCallIntentValid(intent, safeguard);\n revert IntentsValidatorUnknownIntentType(uint8(intent.op));\n }\n\n /**\n * @dev Safely decodes a safeguard tree avoiding compiler issues with dynamic arrays\n * @param data Safeguard tree data to be decoded\n */\n function _decodeSafeguardTree(bytes memory data) private pure returns (SafeguardTree memory) {\n (SafeguardGroup[] memory nodes, Safeguard[] memory leaves) = abi.decode(data, (SafeguardGroup[], Safeguard[]));\n return SafeguardTree(nodes, leaves);\n }\n}\n" + }, + "project/contracts/safeguards/Safeguards.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Safeguard config modes\n * - List: Safeguard lists\n * - Tree: Safeguard groups\n */\nenum SafeguardConfigMode {\n List,\n Tree\n}\n\n/**\n * @dev Logical operators for safeguard groups\n * - AND: every child must pass\n * - OR: at least one child must pass\n * - XOR: exactly one child must pass\n * - NOT: every child must fail\n */\nenum SafeguardGroupLogic {\n AND,\n OR,\n XOR,\n NOT\n}\n\n/**\n * @dev Flat node in the safeguard tree\n * @param logic Group operator (AND/OR/XOR/NOT)\n * @param leaves Indices into `SafeguardTree.leaves`\n * @param children Indices into `SafeguardTree.nodes`\n */\nstruct SafeguardGroup {\n uint8 logic;\n uint16[] leaves;\n uint16[] children;\n}\n\n/**\n * @dev Safeguard tree representation\n * @param nodes List of all the nodes in the tree\n * @param leaves List of all the leaves in the tree\n */\nstruct SafeguardTree {\n SafeguardGroup[] nodes;\n Safeguard[] leaves;\n}\n\n/**\n * @dev Safeguard representation\n * @param mode Safeguard mode\n * @param config Safeguard configuration settings or parameters\n */\nstruct Safeguard {\n uint8 mode;\n bytes config;\n}\n" + }, + "project/contracts/safeguards/SwapIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './BaseIntentsValidator.sol';\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Swap safeguard modes to validate swap intents\n * @param None To ensure no swaps are allowed\n * @param SourceChain To validate that the source chain is allowed\n * @param DestinationChain To validate that the destination chain is allowed\n * @param TokenIn To validate that the tokens to be sent are allowed\n * @param TokenOut To validate that the tokens to be received are allowed\n * @param Recipient To validate that the recipients that will receive the tokens are allowed\n */\nenum SwapSafeguardMode {\n None,\n SourceChain,\n DestinationChain,\n TokenIn,\n TokenOut,\n Recipient\n}\n\n/**\n * @title SwapIntentsValidator\n * @dev Performs swap intents validations based on safeguards\n */\ncontract SwapIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a swap intent is valid for a safeguard\n * @param intent Swap intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isSwapIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n if (safeguard.mode == uint8(SwapSafeguardMode.SourceChain))\n return _isChainAllowed(swapIntent.sourceChain, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.DestinationChain))\n return _isChainAllowed(swapIntent.destinationChain, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.TokenIn))\n return _areSwapTokensInValid(swapIntent.tokensIn, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.TokenOut))\n return _areSwapTokensOutValid(swapIntent.tokensOut, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.Recipient))\n return _areSwapRecipientsValid(swapIntent.tokensOut, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the tokens to be sent are allowed\n */\n function _areSwapTokensInValid(TokenIn[] memory tokensIn, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensIn.length; i++) {\n if (!_isAccountAllowed(tokensIn[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the tokens to be received are allowed\n */\n function _areSwapTokensOutValid(TokenOut[] memory tokensOut, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensOut.length; i++) {\n if (!_isAccountAllowed(tokensOut[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the recipients to be received are allowed\n */\n function _areSwapRecipientsValid(TokenOut[] memory tokensOut, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensOut.length; i++) {\n if (!_isAccountAllowed(tokensOut[i].recipient, config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/safeguards/TransferIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './BaseIntentsValidator.sol';\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Transfer safeguard modes to validate transfer intents\n * @param None To ensure no transfers are allowed\n * @param Chain To validate that the chain where transfers execute is allowed\n * @param Token To validate that the tokens being transferred are allowed\n * @param Recipient To validate that the recipients of the transfers are allowed\n */\nenum TransferSafeguardMode {\n None,\n Chain,\n Token,\n Recipient\n}\n\n/**\n * @title TransferIntentsValidator\n * @dev Performs transfer intents validations based on safeguards\n */\ncontract TransferIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a transfer intent is valid for a safeguard\n * @param intent Transfer intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isTransferIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n TransferIntent memory transferIntent = abi.decode(intent.data, (TransferIntent));\n if (safeguard.mode == uint8(TransferSafeguardMode.Chain))\n return _isChainAllowed(transferIntent.chainId, safeguard.config);\n if (safeguard.mode == uint8(TransferSafeguardMode.Token))\n return _areTransferTokensValid(transferIntent.transfers, safeguard.config);\n if (safeguard.mode == uint8(TransferSafeguardMode.Recipient))\n return _areTransferRecipientsValid(transferIntent.transfers, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the tokens being transferred are allowed\n */\n function _areTransferTokensValid(TransferData[] memory transfers, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < transfers.length; i++) {\n if (!_isAccountAllowed(transfers[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the recipients of the transfers are allowed\n */\n function _areTransferRecipientsValid(TransferData[] memory transfers, bytes memory config)\n private\n pure\n returns (bool)\n {\n for (uint256 i = 0; i < transfers.length; i++) {\n if (!_isAccountAllowed(transfers[i].recipient, config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/Settler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/cryptography/ECDSA.sol';\nimport '@openzeppelin/contracts/utils/cryptography/EIP712.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165Checker.sol';\n\nimport './Intents.sol';\nimport './interfaces/IController.sol';\nimport './interfaces/IIntentsValidator.sol';\nimport './interfaces/IExecutor.sol';\nimport './interfaces/ISettler.sol';\nimport './utils/Denominations.sol';\nimport './utils/ERC20Helpers.sol';\nimport './smart-accounts/SmartAccountsHandler.sol';\nimport './smart-accounts/SmartAccountsHandlerHelpers.sol';\n\n/**\n * @title Settler\n * @dev Contract that provides the appropriate context for solvers to execute proposals that fulfill user intents\n */\ncontract Settler is ISettler, Ownable, ReentrancyGuard, EIP712 {\n using SafeERC20 for IERC20;\n using IntentsHelpers for Intent;\n using IntentsHelpers for Proposal;\n using IntentsHelpers for Validation;\n using SmartAccountsHandlerHelpers for address;\n\n // Mimic controller reference\n // solhint-disable-next-line immutable-vars-naming\n address public immutable override controller;\n\n // Smart accounts handler reference\n address public override smartAccountsHandler;\n\n // Intents validator reference\n address public override intentsValidator;\n\n // List of block numbers at which a user nonce was used\n mapping (address => mapping (bytes32 => uint256)) public override getNonceBlock;\n\n // Safeguard config per user\n mapping (address => bytes) internal _userSafeguard;\n\n /**\n * @dev Modifier to tag settler functions in order to check if the sender is an allowed solver\n */\n modifier onlySolver() {\n address sender = _msgSender();\n if (!IController(controller).isSolverAllowed(sender)) revert SettlerSolverNotAllowed(sender);\n _;\n }\n\n /**\n * @dev Creates a new Settler contract\n * @param _controller Address of the Settler controller\n * @param _owner Address that will own the contract\n */\n constructor(address _controller, address _owner) Ownable(_owner) EIP712('Mimic Protocol Settler', '1') {\n controller = _controller;\n smartAccountsHandler = address(new SmartAccountsHandler());\n }\n\n /**\n * @dev Tells the hash of an intent\n * @param intent Intent to get the hash of\n */\n function getIntentHash(Intent memory intent) external pure override returns (bytes32) {\n return intent.hash();\n }\n\n /**\n * @dev Tells the hash of a proposal\n * @param proposal Proposal to be hashed\n * @param intent Intent being fulfilled by the requested proposal\n * @param solver Address of the solver that made the proposal\n */\n function getProposalHash(Proposal memory proposal, Intent memory intent, address solver)\n external\n pure\n override\n returns (bytes32)\n {\n return proposal.hash(intent, solver);\n }\n\n /**\n * @dev Tells the safeguard set for a user\n * @param user Address of the user being queried\n */\n function getUserSafeguard(address user) external view override returns (bytes memory) {\n return _userSafeguard[user];\n }\n\n /**\n * @dev It allows receiving native token transfers\n * Note: This method mainly allows supporting native tokens for swaps\n */\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n /**\n * @dev Withdraws ERC20 or native tokens from the contract\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function rescueFunds(address token, address recipient, uint256 amount) external override onlyOwner nonReentrant {\n if (recipient == address(0)) revert SettlerRescueFundsRecipientZero();\n ERC20Helpers.transfer(token, recipient, amount);\n emit FundsRescued(token, recipient, amount);\n }\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function setSmartAccountsHandler(address newSmartAccountsHandler) external override onlyOwner {\n _setSmartAccountsHandler(newSmartAccountsHandler);\n }\n\n /**\n * @dev Sets a new intents validator address\n * @param newIntentsValidator New intents validator to be set\n */\n function setIntentsValidator(address newIntentsValidator) external override onlyOwner {\n _setIntentsValidator(newIntentsValidator);\n }\n\n /**\n * @dev Sets a safeguard for a user\n * @param safeguard Safeguard to be set\n */\n function setSafeguard(bytes memory safeguard) external override {\n _setSafeguard(msg.sender, safeguard);\n }\n\n /**\n * @dev Executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function execute(Execution[] memory executions) external override onlySolver {\n _execute(executions, false);\n }\n\n /**\n * @dev Simulates an execution. It will always revert. Successful executions are returned as\n * `SettlerSimulationSuccess` errors. Any other error should be treated as failure.\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function simulate(Execution[] memory executions) external override onlySolver {\n uint256 initialGas = gasleft();\n _execute(executions, true);\n uint256 gasUsed = initialGas - gasleft();\n revert SettlerSimulationSuccess(gasUsed);\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n * @param simulated Whether the execution is a simulation\n */\n function _execute(Execution[] memory executions, bool simulated) internal nonReentrant {\n for (uint256 i = 0; i < executions.length; i++) {\n Intent memory intent = executions[i].intent;\n Proposal memory proposal = executions[i].proposal;\n bytes memory signature = executions[i].signature;\n\n _validateIntent(intent, proposal, signature, simulated);\n getNonceBlock[intent.user][intent.nonce] = block.number;\n\n if (intent.op == uint8(OpType.Swap)) _executeSwap(intent, proposal);\n else if (intent.op == uint8(OpType.Transfer)) _executeTransfer(intent, proposal);\n else if (intent.op == uint8(OpType.Call)) _executeCall(intent, proposal);\n else revert SettlerUnknownIntentType(uint8(intent.op));\n\n emit ProposalExecuted(proposal.hash(intent, _msgSender()), i);\n }\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a swap intent\n * @param intent Swap intent to be fulfilled\n * @param proposal Swap proposal to be executed\n */\n function _executeSwap(Intent memory intent, Proposal memory proposal) internal {\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n _validateSwapIntent(swapIntent, swapProposal);\n\n bool isSmartAccount = smartAccountsHandler.isSmartAccount(intent.user);\n if (swapIntent.sourceChain == block.chainid) {\n for (uint256 i = 0; i < swapIntent.tokensIn.length; i++) {\n TokenIn memory tokenIn = swapIntent.tokensIn[i];\n _transferFrom(tokenIn.token, intent.user, swapProposal.executor, tokenIn.amount, isSmartAccount);\n }\n }\n\n uint256[] memory preBalancesOut = _getTokensOutBalance(swapIntent);\n IExecutor(swapProposal.executor).execute(intent, proposal);\n\n if (swapIntent.destinationChain == block.chainid) {\n uint256[] memory outputs = new uint256[](swapIntent.tokensOut.length);\n for (uint256 i = 0; i < swapIntent.tokensOut.length; i++) {\n TokenOut memory tokenOut = swapIntent.tokensOut[i];\n uint256 postBalanceOut = ERC20Helpers.balanceOf(tokenOut.token, address(this));\n uint256 preBalanceOut = preBalancesOut[i];\n if (postBalanceOut < preBalanceOut) revert SettlerPostBalanceOutLtPre(i, postBalanceOut, preBalanceOut);\n\n outputs[i] = postBalanceOut - preBalanceOut;\n uint256 proposedAmount = swapProposal.amountsOut[i];\n if (outputs[i] < proposedAmount) revert SettlerAmountOutLtProposed(i, outputs[i], proposedAmount);\n\n ERC20Helpers.transfer(tokenOut.token, tokenOut.recipient, outputs[i]);\n }\n\n _emitIntentEvents(intent, proposal, abi.encode(outputs));\n _payFees(intent, proposal, isSmartAccount);\n }\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a transfer intent\n * @param intent Transfer intent to be fulfilled\n * @param proposal Transfer proposal to be executed\n */\n function _executeTransfer(Intent memory intent, Proposal memory proposal) internal {\n TransferIntent memory transferIntent = abi.decode(intent.data, (TransferIntent));\n _validateTransferIntent(transferIntent, proposal);\n\n bool isSmartAccount = smartAccountsHandler.isSmartAccount(intent.user);\n for (uint256 i = 0; i < transferIntent.transfers.length; i++) {\n TransferData memory transfer = transferIntent.transfers[i];\n _transferFrom(transfer.token, intent.user, transfer.recipient, transfer.amount, isSmartAccount);\n }\n\n _emitIntentEvents(intent, proposal, new bytes(0));\n _payFees(intent, proposal, isSmartAccount);\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a call intent\n * @param intent Call intent to be fulfilled\n * @param proposal Call proposal to be executed\n */\n function _executeCall(Intent memory intent, Proposal memory proposal) internal {\n CallIntent memory callIntent = abi.decode(intent.data, (CallIntent));\n _validateCallIntent(callIntent, proposal, intent.user);\n\n bytes[] memory outputs = new bytes[](callIntent.calls.length);\n for (uint256 i = 0; i < callIntent.calls.length; i++) {\n CallData memory call = callIntent.calls[i];\n // solhint-disable-next-line avoid-low-level-calls\n outputs[i] = smartAccountsHandler.call(intent.user, call.target, call.data, call.value);\n }\n\n _emitIntentEvents(intent, proposal, abi.encode(outputs));\n _payFees(intent, proposal, true);\n }\n\n /**\n * @dev Validates an intent and its corresponding proposal\n * @param intent Intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param signature Proposal signature\n * @param simulated Whether the execution is a simulation\n */\n function _validateIntent(Intent memory intent, Proposal memory proposal, bytes memory signature, bool simulated)\n internal\n view\n {\n if (intent.settler != address(this)) revert SettlerInvalidSettler(intent.settler);\n if (intent.nonce == bytes32(0)) revert SettlerNonceZero();\n if (getNonceBlock[intent.user][intent.nonce] != 0) revert SettlerNonceAlreadyUsed(intent.user, intent.nonce);\n\n if (intentsValidator != address(0)) {\n bytes memory safeguard = _userSafeguard[intent.user];\n if (safeguard.length > 0) IIntentsValidator(intentsValidator).validate(intent, safeguard);\n }\n\n bool shouldValidateDeadlines = _shouldValidateDeadlines(intent);\n if (shouldValidateDeadlines) {\n if (intent.deadline <= block.timestamp) revert SettlerIntentPastDeadline(intent.deadline, block.timestamp);\n bool isProposalPastDeadline = proposal.deadline <= block.timestamp;\n if (isProposalPastDeadline) revert SettlerProposalPastDeadline(proposal.deadline, block.timestamp);\n }\n\n if (intent.maxFees.length != proposal.fees.length) revert SettlerSolverFeeInvalidLength();\n for (uint256 i = 0; i < intent.maxFees.length; i++) {\n uint256 maxFee = intent.maxFees[i].amount;\n uint256 proposalFee = proposal.fees[i];\n if (proposalFee > maxFee) revert SettlerSolverFeeTooHigh(proposalFee, maxFee);\n }\n\n uint8 minValidations = IController(controller).minValidations();\n uint256 requiredValidations = intent.minValidations > minValidations ? intent.minValidations : minValidations;\n\n if (intent.validations.length < requiredValidations) {\n revert SettlerIntentValidationsNotEnough(requiredValidations, intent.validations.length);\n }\n\n address lastValidator = address(0);\n Validation memory validation = Validation(intent.hash());\n bytes32 typedDataHash = _hashTypedDataV4(validation.hash());\n for (uint256 i = 0; i < intent.validations.length; i++) {\n address validator = ECDSA.recover(typedDataHash, intent.validations[i]);\n if (validator <= lastValidator) {\n revert SettlerValidatorDuplicatedOrUnsorted(lastValidator, validator);\n }\n lastValidator = validator;\n bool isValidatorNotAllowed = !IController(controller).isValidatorAllowed(validator);\n if (isValidatorNotAllowed) revert SettlerValidatorNotAllowed(validator);\n }\n\n address signer = ECDSA.recover(_hashTypedDataV4(proposal.hash(intent, _msgSender())), signature);\n bool isProposalSignerNotAllowed = !IController(controller).isProposalSignerAllowed(signer) && !simulated;\n if (isProposalSignerNotAllowed) revert SettlerProposalSignerNotAllowed(signer);\n }\n\n /**\n * @dev Validates a swap intent and its corresponding proposal\n * @param intent Swap intent to be fulfilled\n * @param proposal Proposal to be executed\n */\n function _validateSwapIntent(SwapIntent memory intent, SwapProposal memory proposal) internal view {\n bool isChainInvalid = intent.sourceChain != block.chainid && intent.destinationChain != block.chainid;\n if (isChainInvalid) revert SettlerInvalidChain(block.chainid);\n\n if (proposal.amountsOut.length != intent.tokensOut.length) revert SettlerInvalidProposedAmounts();\n\n for (uint256 i = 0; i < intent.tokensOut.length; i++) {\n TokenOut memory tokenOut = intent.tokensOut[i];\n address recipient = tokenOut.recipient;\n if (recipient == address(this)) revert SettlerInvalidRecipient(recipient);\n\n uint256 minAmount = tokenOut.minAmount;\n uint256 proposedAmount = proposal.amountsOut[i];\n if (proposedAmount < minAmount) revert SettlerProposedAmountLtMinAmount(i, proposedAmount, minAmount);\n }\n\n if (intent.sourceChain != intent.destinationChain) {\n bool isExecutorInvalid = !IController(controller).isExecutorAllowed(proposal.executor);\n if (isExecutorInvalid) revert SettlerExecutorNotAllowed(proposal.executor);\n }\n }\n\n /**\n * @dev Validates a transfer intent and its corresponding proposal\n * @param intent Transfer intent to be fulfilled\n * @param proposal Proposal to be executed\n */\n function _validateTransferIntent(TransferIntent memory intent, Proposal memory proposal) internal view {\n if (intent.chainId != block.chainid) revert SettlerInvalidChain(block.chainid);\n if (proposal.data.length > 0) revert SettlerProposalDataNotEmpty();\n for (uint256 i = 0; i < intent.transfers.length; i++) {\n address recipient = intent.transfers[i].recipient;\n if (recipient == address(this)) revert SettlerInvalidRecipient(recipient);\n }\n }\n\n /**\n * @dev Validates a call intent and its corresponding proposal\n * @param intent Call intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param user The originator of the intent\n */\n function _validateCallIntent(CallIntent memory intent, Proposal memory proposal, address user) internal view {\n if (intent.chainId != block.chainid) revert SettlerInvalidChain(block.chainid);\n if (proposal.data.length > 0) revert SettlerProposalDataNotEmpty();\n if (!smartAccountsHandler.isSmartAccount(user)) revert SettlerUserNotSmartAccount(user);\n }\n\n /**\n * @dev Tells the contract balance for each token out of a swap intent\n * @param intent Swap intent containing the list of tokens out\n */\n function _getTokensOutBalance(SwapIntent memory intent) internal view returns (uint256[] memory balances) {\n balances = new uint256[](intent.tokensOut.length);\n if (intent.destinationChain == block.chainid) {\n for (uint256 i = 0; i < intent.tokensOut.length; i++) {\n balances[i] = ERC20Helpers.balanceOf(intent.tokensOut[i].token, address(this));\n }\n }\n }\n\n /**\n * @dev Tells if the intent and proposal deadlines should be validated\n * @param intent Intent to be fulfilled\n */\n function _shouldValidateDeadlines(Intent memory intent) internal view returns (bool) {\n if (intent.op != uint8(OpType.Swap)) return true;\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n if (swapIntent.sourceChain == swapIntent.destinationChain) return true;\n return swapIntent.sourceChain == block.chainid;\n }\n\n /**\n * @dev Emits intent custom events\n * @param intent Intent to emit the custom events for\n * @param proposal Proposal that fulfills the intent\n * @param output Encoded array of outputs\n */\n function _emitIntentEvents(Intent memory intent, Proposal memory proposal, bytes memory output) internal {\n for (uint256 i = 0; i < intent.events.length; i++) {\n IntentEvent memory intentEvent = intent.events[i];\n emit IntentExecuted(\n intent.user,\n intentEvent.topic,\n uint8(intent.op),\n intent,\n proposal,\n output,\n intentEvent.data\n );\n }\n }\n\n /**\n * @dev Pays fees\n * @param intent Intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param isSmartAccount Whether the intent user is a smart account\n */\n function _payFees(Intent memory intent, Proposal memory proposal, bool isSmartAccount) internal {\n address from = intent.user;\n address to = _msgSender();\n for (uint256 i = 0; i < intent.maxFees.length; i++) {\n address token = intent.maxFees[i].token;\n if (!Denominations.isUSD(token)) _transferFrom(token, from, to, proposal.fees[i], isSmartAccount);\n }\n }\n\n /**\n * @dev Transfers tokens from one account to another\n * @param token Address of the token to transfer\n * @param from Address of the account sending the tokens\n * @param to Address of the account receiving the tokens\n * @param amount Amount of tokens to transfer\n * @param isSmartAccount Whether the sender is a smart account\n */\n function _transferFrom(address token, address from, address to, uint256 amount, bool isSmartAccount) internal {\n if (isSmartAccount) {\n smartAccountsHandler.transfer(from, token, to, amount);\n } else {\n IERC20(token).safeTransferFrom(from, to, amount);\n }\n }\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function _setSmartAccountsHandler(address newSmartAccountsHandler) internal {\n if (newSmartAccountsHandler == address(0)) revert SmartAccountsHandlerZero();\n smartAccountsHandler = newSmartAccountsHandler;\n emit SmartAccountsHandlerSet(newSmartAccountsHandler);\n }\n\n /**\n * @dev Sets the intents validator\n * @param newIntentsValidator New intents validator to be set\n */\n function _setIntentsValidator(address newIntentsValidator) internal {\n intentsValidator = newIntentsValidator;\n emit IntentsValidatorSet(newIntentsValidator);\n }\n\n /**\n * @dev Sets a safeguard for a user\n * @param user Address of the user to set the safeguard for\n * @param safeguard Safeguard to be set\n */\n function _setSafeguard(address user, bytes memory safeguard) internal {\n delete _userSafeguard[user];\n _userSafeguard[user] = safeguard;\n emit SafeguardSet(user);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccount7702.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/Context.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccount.sol';\nimport '../utils/ERC20Helpers.sol';\nimport './SmartAccountBase.sol';\n\n/**\n * @title SmartAccount7702\n * @dev Provides the smart account logic to use with EIP7702\n */\ncontract SmartAccount7702 is SmartAccountBase {\n // Mimic settler reference\n // solhint-disable-next-line immutable-vars-naming\n address public immutable settler;\n\n /**\n * @dev The sender is not the settler\n */\n error SmartAccount7702SenderNotSettler();\n\n /**\n * @dev Reverts unless the sender is the settler\n */\n modifier onlySettler() {\n if (_msgSender() != settler) revert SmartAccount7702SenderNotSettler();\n _;\n }\n\n /**\n * @dev Creates a new SmartAccount7702 contract\n * @param _settler Address of the Mimic settler\n */\n constructor(address _settler) {\n settler = _settler;\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) public override onlySettler {\n super.transfer(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value) public override onlySettler returns (bytes memory) {\n // solhint-disable-next-line avoid-low-level-calls\n return super.call(target, data, value);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountBase.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/Context.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccount.sol';\nimport '../utils/ERC20Helpers.sol';\n\n/**\n * @title SmartAccountBase\n * @dev Provides the base logic for managing assets and executing arbitrary calls\n */\ncontract SmartAccountBase is ISmartAccount, Context, ERC165, ReentrancyGuard {\n /**\n * @dev Tells whether the contract supports the given interface ID. Overrides ERC165 to declare support for ISmartAccount interface.\n * @param interfaceId Interface ID is defined as the XOR of all function selectors in the interface\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {\n return interfaceId == type(ISmartAccount).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) public virtual override nonReentrant {\n ERC20Helpers.transfer(token, recipient, amount);\n emit Transferred(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value)\n public\n virtual\n override\n nonReentrant\n returns (bytes memory result)\n {\n result = Address.functionCallWithValue(target, data, value);\n emit Called(target, data, value, result);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountContract.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/cryptography/ECDSA.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccountContract.sol';\nimport './SmartAccountBase.sol';\n\n/**\n * @title SmartAccountContract\n * @dev Provides the smart account logic to use as a standalone contract\n */\ncontract SmartAccountContract is ISmartAccountContract, Ownable, SmartAccountBase {\n // EIP1271 magic return value\n bytes4 internal constant EIP1271_MAGIC_VALUE = 0x1626ba7e;\n\n // EIP1271 invalid signature return value\n bytes4 internal constant EIP1271_INVALID_SIGNATURE = 0xffffffff;\n\n // List of account permissions\n mapping (address => bool) public isSignerAllowed;\n\n // Mimic settler reference\n address public settler;\n\n /**\n * @dev The settler is zero\n */\n error SmartAccountSettlerZero();\n\n /**\n * @dev The input arrays are not of equal length\n */\n error SmartAccountInputInvalidLength();\n\n /**\n * @dev The sender is not the owner or the settler\n */\n error SmartAccountUnauthorizedSender(address sender);\n\n /**\n * @dev Emitted every time the settler is set\n */\n event SettlerSet(address indexed settler);\n\n /**\n * @dev Emitted every time a signer allowance is set\n */\n event SignerAllowedSet(address indexed account, bool allowed);\n\n /**\n * @dev Reverts unless the sender is the owner or the settler\n */\n modifier onlyOwnerOrSettler() {\n address sender = _msgSender();\n bool isAuthorized = sender == owner() || sender == settler;\n if (!isAuthorized) revert SmartAccountUnauthorizedSender(sender);\n _;\n }\n\n /**\n * @dev Creates a new SmartAccount contract\n * @param _settler Address of the Mimic settler\n * @param _owner Address that will own the contract\n */\n constructor(address _settler, address _owner) Ownable(_owner) {\n _setSettler(_settler);\n }\n\n /**\n * @dev Tells whether the signature provided belongs to an allowed account.\n * @param hash Message signed by the account\n * @param signature Signature provided to be verified\n */\n function isValidSignature(bytes32 hash, bytes memory signature) external view override returns (bytes4) {\n (address signer, , ) = ECDSA.tryRecover(hash, signature);\n if (signer != address(0) && (signer == owner() || isSignerAllowed[signer])) return EIP1271_MAGIC_VALUE;\n return EIP1271_INVALID_SIGNATURE;\n }\n\n /**\n * @dev It allows receiving native token transfers\n */\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n /**\n * @dev Sets the settler. Sender must be the owner.\n * @param newSettler Address of the new settler to be set\n */\n function setSettler(address newSettler) external onlyOwner {\n _setSettler(newSettler);\n }\n\n /**\n * @dev Sets a list of allowed signers. Sender must be the owner.\n * @param accounts List of account addresses\n * @param allowances List of allowed condition per account\n */\n function setAllowedSigners(address[] memory accounts, bool[] memory allowances) external onlyOwner {\n if (accounts.length != allowances.length) revert SmartAccountInputInvalidLength();\n for (uint256 i = 0; i < accounts.length; i++) {\n address account = accounts[i];\n bool allowed = allowances[i];\n isSignerAllowed[account] = allowed;\n emit SignerAllowedSet(account, allowed);\n }\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the owner or the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount)\n public\n override(ISmartAccount, SmartAccountBase)\n onlyOwnerOrSettler\n {\n super.transfer(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the owner or the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value)\n public\n override(ISmartAccount, SmartAccountBase)\n onlyOwnerOrSettler\n returns (bytes memory)\n {\n // solhint-disable-next-line avoid-low-level-calls\n return super.call(target, data, value);\n }\n\n /**\n * @dev Sets the settler\n * @param newSettler Address of the new settler to be set\n */\n function _setSettler(address newSettler) internal {\n if (newSettler == address(0)) revert SmartAccountSettlerZero();\n settler = newSettler;\n emit SettlerSet(newSettler);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountsHandler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport '../interfaces/ISafe.sol';\nimport '../interfaces/ISmartAccount.sol';\nimport '../interfaces/ISmartAccountsHandler.sol';\nimport '../utils/Denominations.sol';\n\ncontract SmartAccountsHandler is ISmartAccountsHandler {\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address account) external view override returns (bool) {\n if (account.code.length == 0) return false;\n if (_isMimicSmartAccount(account)) return true;\n if (_isSafe(account)) return true;\n return false;\n }\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address account, address token, address to, uint256 amount) external override {\n if (_isMimicSmartAccount(account)) return ISmartAccount(account).transfer(token, to, amount);\n if (_isSafe(account)) return _transferSafe(account, token, to, amount);\n revert SmartAccountsHandlerUnsupportedAccount(account);\n }\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address account, address target, bytes memory data, uint256 value)\n external\n override\n returns (bytes memory)\n {\n // solhint-disable-next-line avoid-low-level-calls\n if (_isMimicSmartAccount(account)) return ISmartAccount(account).call(target, data, value);\n if (_isSafe(account)) return _callSafe(account, target, data, value);\n revert SmartAccountsHandlerUnsupportedAccount(account);\n }\n\n /**\n * @dev Performs a transfer from a safe\n */\n function _transferSafe(address account, address token, address to, uint256 amount) internal {\n Denominations.isNativeToken(token)\n ? _callSafe(account, to, new bytes(0), amount)\n : _callSafe(account, token, abi.encodeWithSelector(IERC20.transfer.selector, to, amount), 0);\n }\n\n /**\n * @dev Performs a call from a safe\n */\n function _callSafe(address account, address target, bytes memory data, uint256 value)\n internal\n returns (bytes memory)\n {\n (bool success, bytes memory result) = ISafe(account).execTransactionFromModuleReturnData(\n target,\n value,\n data,\n SafeOperation.Call\n );\n return\n data.length == 0\n ? Address.verifyCallResult(success, result)\n : Address.verifyCallResultFromTarget(target, success, result);\n }\n\n /**\n * @dev Tells whether an account is a Mimic smart account\n * @param account Address of the account being queried\n */\n function _isMimicSmartAccount(address account) internal view returns (bool) {\n try ISmartAccount(account).supportsInterface(type(ISmartAccount).interfaceId) returns (bool ok) {\n return ok;\n } catch {\n return false;\n }\n }\n\n /**\n * @dev Tells whether an account is a Gnosis Safe\n * @param account Address of the account being queried\n */\n function _isSafe(address account) internal view returns (bool) {\n try ISafe(account).getThreshold() returns (uint256) {\n return true;\n } catch {\n return false;\n }\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountsHandlerHelpers.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport '../interfaces/ISmartAccountsHandler.sol';\n\nlibrary SmartAccountsHandlerHelpers {\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address handler, address account) internal view returns (bool) {\n return ISmartAccountsHandler(handler).isSmartAccount(account);\n }\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address handler, address account, address token, address to, uint256 amount) internal {\n Address.functionDelegateCall(\n handler,\n abi.encodeWithSelector(ISmartAccountsHandler.transfer.selector, account, token, to, amount)\n );\n }\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address handler, address account, address target, bytes memory data, uint256 value)\n internal\n returns (bytes memory)\n {\n return\n Address.functionDelegateCall(\n handler,\n abi.encodeWithSelector(ISmartAccountsHandler.call.selector, account, target, data, value)\n );\n }\n}\n" + }, + "project/contracts/test/CallMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\ncontract CallMock {\n event CallReceived(address indexed sender, uint256 value);\n error CallError();\n\n function call() external payable {\n emit CallReceived(msg.sender, msg.value);\n }\n\n function callError() external payable {\n revert CallError();\n }\n}\n" + }, + "project/contracts/test/executors/EmptyExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\n\ncontract EmptyExecutorMock is IExecutor {\n event Executed();\n\n function execute(Intent memory, Proposal memory) external override {\n emit Executed();\n }\n}\n" + }, + "project/contracts/test/executors/MintExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../TokenMock.sol';\nimport '../../interfaces/IExecutor.sol';\n\n/* solhint-disable custom-errors */\n\ncontract MintExecutorMock is IExecutor {\n event Minted();\n\n function execute(Intent memory intent, Proposal memory proposal) external override {\n require(intent.op == uint8(OpType.Swap), 'Invalid intent type');\n\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n (address[] memory tokens, uint256[] memory amounts) = abi.decode(swapProposal.data, (address[], uint256[]));\n\n require(tokens.length == amounts.length, 'Invalid inputs');\n\n for (uint256 i = 0; i < tokens.length; i++) {\n TokenMock(tokens[i]).mint(msg.sender, amounts[i]);\n emit Minted();\n }\n }\n}\n" + }, + "project/contracts/test/executors/ReentrantExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\nimport '../../interfaces/ISettler.sol';\n\ncontract ReentrantExecutorMock is IExecutor {\n // solhint-disable-next-line immutable-vars-naming\n address payable public immutable settler;\n\n constructor(address payable _settler) {\n settler = _settler;\n }\n\n function execute(Intent memory, Proposal memory) external override {\n ISettler(settler).execute(new Execution[](0));\n }\n}\n" + }, + "project/contracts/test/executors/TransferExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\nimport '../../utils/ERC20Helpers.sol';\n\n/* solhint-disable custom-errors */\n\ncontract TransferExecutorMock is IExecutor {\n event Transferred();\n\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n function execute(Intent memory intent, Proposal memory proposal) external override {\n require(intent.op == uint8(OpType.Swap), 'Invalid intent type');\n\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n (address[] memory tokens, uint256[] memory amounts) = abi.decode(swapProposal.data, (address[], uint256[]));\n\n require(tokens.length == amounts.length, 'Invalid inputs');\n\n for (uint256 i = 0; i < tokens.length; i++) {\n ERC20Helpers.transfer(tokens[i], msg.sender, amounts[i]);\n emit Transferred();\n }\n }\n}\n" + }, + "project/contracts/test/smart-accounts/SafeMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/ISafe.sol';\n\ncontract SafeMock is ISafe {\n event ModuleTxExecuted(\n address indexed target,\n bytes data,\n uint256 value,\n SafeOperation operation,\n bool success,\n bytes result\n );\n\n receive() external payable {}\n\n function getThreshold() external pure returns (uint256) {\n return 1;\n }\n\n function execTransactionFromModuleReturnData(address to, uint256 value, bytes memory data, SafeOperation operation)\n external\n returns (bool success, bytes memory result)\n {\n // solhint-disable-next-line avoid-low-level-calls\n (success, result) = to.call{ value: value }(data);\n emit ModuleTxExecuted(to, data, value, operation, success, result);\n }\n}\n" + }, + "project/contracts/test/TokenMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/ERC20.sol';\n\ncontract TokenMock is ERC20 {\n uint8 internal _decimals;\n\n constructor(string memory symbol, uint8 dec) ERC20(symbol, symbol) {\n _decimals = dec;\n }\n\n function mint(address account, uint256 amount) external {\n _mint(account, amount);\n }\n\n function decimals() public view override returns (uint8) {\n return _decimals;\n }\n}\n" + }, + "project/contracts/test/utils/DenominationsMock.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '../../utils/Denominations.sol';\n\n// solhint-disable func-name-mixedcase\n\ncontract DenominationsMock {\n function NATIVE_TOKEN() external pure returns (address) {\n return Denominations.NATIVE_TOKEN;\n }\n\n function USD() external pure returns (address) {\n return Denominations.USD;\n }\n}\n" + }, + "project/contracts/test/utils/ERC20HelpersMock.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '../../utils/ERC20Helpers.sol';\n\ncontract ERC20HelpersMock {\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n function approve(address token, address to, uint256 amount) external {\n ERC20Helpers.approve(token, to, amount);\n }\n\n function transfer(address token, address to, uint256 amount) external {\n ERC20Helpers.transfer(token, to, amount);\n }\n\n function balanceOf(address token, address account) external view returns (uint256) {\n return ERC20Helpers.balanceOf(token, account);\n }\n}\n" + }, + "project/contracts/utils/Denominations.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\n/**\n * @title Denominations\n * @dev Provides a list of ground denominations for those tokens that cannot be represented by an ERC20.\n * For now, the only needed is the native token that could be ETH, MATIC, or other depending on the layer being operated.\n */\nlibrary Denominations {\n address internal constant NATIVE_TOKEN = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;\n\n // Fiat currencies follow https://en.wikipedia.org/wiki/ISO_4217\n address internal constant USD = address(840);\n\n function isUSD(address token) internal pure returns (bool) {\n return token == USD;\n }\n\n function isNativeToken(address token) internal pure returns (bool) {\n return token == NATIVE_TOKEN;\n }\n}\n" + }, + "project/contracts/utils/ERC20Helpers.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport './Denominations.sol';\n\n/**\n * @title ERC20Helpers\n * @dev Provides a list of ERC20 helper methods\n */\nlibrary ERC20Helpers {\n function approve(address token, address to, uint256 amount) internal {\n SafeERC20.forceApprove(IERC20(token), to, amount);\n }\n\n function transfer(address token, address to, uint256 amount) internal {\n if (Denominations.isNativeToken(token)) Address.sendValue(payable(to), amount);\n else SafeERC20.safeTransfer(IERC20(token), to, amount);\n }\n\n function balanceOf(address token, address account) internal view returns (uint256) {\n if (Denominations.isNativeToken(token)) return address(account).balance;\n else return IERC20(token).balanceOf(address(account));\n }\n}\n" + }, + "project/contracts/utils/MimicHelper.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\n/**\n * @title Mimic Helper\n * @dev Collection of helper functions for the Mimic Protocol\n */\ncontract MimicHelper {\n /**\n * @dev Tells the native token balance of an address\n * @param target Address to get native token balance\n */\n function getNativeTokenBalance(address target) external view returns (uint256) {\n return target.balance;\n }\n}\n" + } + } + } +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-1/deployed_addresses.json b/packages/evm/ignition/deployments/chain-1/deployed_addresses.json index a1a41be..e981fe5 100644 --- a/packages/evm/ignition/deployments/chain-1/deployed_addresses.json +++ b/packages/evm/ignition/deployments/chain-1/deployed_addresses.json @@ -2,5 +2,7 @@ "Create3Controller#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", "Create3Controller#Controller": "0x6002825BabC837776A08799404fA55f15DCedA6b", "Create3Settler#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", - "Create3Settler#Settler": "0x609d831C0068844e11eF85a273c7F356212Fd6D1" + "Create3Settler#Settler": "0x609d831C0068844e11eF85a273c7F356212Fd6D1", + "Create3MimicHelper#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", + "Create3MimicHelper#MimicHelper": "0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0" } \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-1/journal.jsonl b/packages/evm/ignition/deployments/chain-1/journal.jsonl index d0556e8..a86db5f 100644 --- a/packages/evm/ignition/deployments/chain-1/journal.jsonl +++ b/packages/evm/ignition/deployments/chain-1/journal.jsonl @@ -17,4 +17,13 @@ {"futureId":"Create3Settler#ICreateX.deployCreate3","hash":"0x70b453c357ad30c3d8629a9795b891150a72afbb169ef93c00443b162e394ae7","networkInteractionId":1,"receipt":{"blockHash":"0xbe6d3f3c5213120d5e05c0738a66be132a51a3bc5299761bf64677d52a453ad4","blockNumber":24033735,"logs":[{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":442,"topics":["0x2feea65dd4e9f9cbd86b74b7734210c59a1b2981b5b137bd0ee3e208200c9067","0x0000000000000000000000001a68cee754105b3f806c92f6f59e3175f0b0fc2c","0xd5d101dbdd8374fa4f730d105879acbe6c9855ed7be06a019574ba923a935d7d"]},{"address":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","data":"0x","logIndex":443,"topics":["0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000003a0ce8115b4913f42c4928d6bc3f554e9a81468b"]},{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":444,"topics":["0x4db17dd5e4732fb6da34a148104a592783ca119a1e7bb8829eba6cbadef0b511","0x000000000000000000000000609d831c0068844e11ef85a273c7f356212fd6d1"]}],"status":"SUCCESS"},"type":"TRANSACTION_CONFIRM"} {"futureId":"Create3Settler#ICreateX.deployCreate3","result":{"type":"SUCCESS"},"type":"CALL_EXECUTION_STATE_COMPLETE"} {"artifactId":"Create3Settler#ICreateX","dependencies":["Create3Settler#ICreateX.deployCreate3","Create3Settler#ICreateX"],"emitterAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","eventIndex":0,"eventName":"ContractCreation","futureId":"Create3Settler#ICreateX.ContractCreation.newContract.0","nameOrIndex":"newContract","result":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","strategy":"basic","strategyConfig":{},"txToReadFrom":"0x70b453c357ad30c3d8629a9795b891150a72afbb169ef93c00443b162e394ae7","type":"READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE"} -{"artifactId":"Create3Settler#Settler","contractAddress":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","contractName":"Settler","dependencies":["Create3Settler#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3Settler#Settler","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} \ No newline at end of file +{"artifactId":"Create3Settler#Settler","contractAddress":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","contractName":"Settler","dependencies":["Create3Settler#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3Settler#Settler","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} +{"artifactId":"Create3MimicHelper#ICreateX","contractAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","contractName":"ICreateX","dependencies":[],"futureId":"Create3MimicHelper#ICreateX","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} +{"args":["0x3a0ce8115b4913f42c4928d6bc3f554e9a81468b000000000000000000000040","0x6080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033"],"artifactId":"Create3MimicHelper#ICreateX","contractAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","dependencies":["Create3MimicHelper#ICreateX"],"from":"0x3a0ce8115b4913f42c4928d6bc3f554e9a81468b","functionName":"deployCreate3","futureId":"Create3MimicHelper#ICreateX.deployCreate3","strategy":"basic","strategyConfig":{},"type":"CALL_EXECUTION_STATE_INITIALIZE","value":{"_kind":"bigint","value":"0"}} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteraction":{"data":"0x9c36a2863a0ce8115b4913f42c4928d6bc3f554e9a81468b000000000000000000000040000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e96080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c00330000000000000000000000000000000000000000000000","id":1,"to":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","type":"ONCHAIN_INTERACTION","value":{"_kind":"bigint","value":"0"}},"type":"NETWORK_INTERACTION_REQUEST"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteractionId":1,"nonce":8,"type":"TRANSACTION_PREPARE_SEND"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteractionId":1,"nonce":8,"transaction":{"fees":{"maxFeePerGas":{"_kind":"bigint","value":"332473850"},"maxPriorityFeePerGas":{"_kind":"bigint","value":"2"}},"hash":"0x523016fd6f2ed2427a06dab243267fd8b3f90541faa3e51b1958fa86d7b2f1a4"},"type":"TRANSACTION_SEND"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","hash":"0x523016fd6f2ed2427a06dab243267fd8b3f90541faa3e51b1958fa86d7b2f1a4","networkInteractionId":1,"receipt":{"blockHash":"0xbfe9f7eaeedba7606bdafb02493d33f2fb452593021246884b5fe902f3fbd797","blockNumber":24320930,"logs":[{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":453,"topics":["0x2feea65dd4e9f9cbd86b74b7734210c59a1b2981b5b137bd0ee3e208200c9067","0x0000000000000000000000009074e2fea6f668ccf7fb884fac62943acc03ea43","0x721f4d59bffa983c2a99dc5a3b93053d035180c65840e4dc318b06bb0484a80f"]},{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":454,"topics":["0x4db17dd5e4732fb6da34a148104a592783ca119a1e7bb8829eba6cbadef0b511","0x0000000000000000000000004766ef65d66e8d2d92f3089ee42e5705e8817ff0"]}],"status":"SUCCESS"},"type":"TRANSACTION_CONFIRM"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","result":{"type":"SUCCESS"},"type":"CALL_EXECUTION_STATE_COMPLETE"} +{"artifactId":"Create3MimicHelper#ICreateX","dependencies":["Create3MimicHelper#ICreateX.deployCreate3","Create3MimicHelper#ICreateX"],"emitterAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","eventIndex":0,"eventName":"ContractCreation","futureId":"Create3MimicHelper#ICreateX.ContractCreation.newContract.0","nameOrIndex":"newContract","result":"0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0","strategy":"basic","strategyConfig":{},"txToReadFrom":"0x523016fd6f2ed2427a06dab243267fd8b3f90541faa3e51b1958fa86d7b2f1a4","type":"READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE"} +{"artifactId":"Create3MimicHelper#MimicHelper","contractAddress":"0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0","contractName":"MimicHelper","dependencies":["Create3MimicHelper#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3MimicHelper#MimicHelper","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-10/artifacts/Create3MimicHelper#ICreateX.dbg.json b/packages/evm/ignition/deployments/chain-10/artifacts/Create3MimicHelper#ICreateX.dbg.json new file mode 100644 index 0000000..817dddf --- /dev/null +++ b/packages/evm/ignition/deployments/chain-10/artifacts/Create3MimicHelper#ICreateX.dbg.json @@ -0,0 +1,4 @@ +{ + "_format": "hh-sol-dbg-1", + "buildInfo": "../build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-10/artifacts/Create3MimicHelper#ICreateX.json b/packages/evm/ignition/deployments/chain-10/artifacts/Create3MimicHelper#ICreateX.json new file mode 100644 index 0000000..a4701c6 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-10/artifacts/Create3MimicHelper#ICreateX.json @@ -0,0 +1,51 @@ +{ + "_format": "hh3-artifact-1", + "contractName": "ICreateX", + "sourceName": "contracts/interfaces/ICreateX.sol", + "abi": [ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "newContract", + "type": "address" + } + ], + "name": "ContractCreation", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "salt", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "initCode", + "type": "bytes" + } + ], + "name": "deployCreate3", + "outputs": [ + { + "internalType": "address", + "name": "newContract", + "type": "address" + } + ], + "stateMutability": "payable", + "type": "function" + } + ], + "bytecode": "0x", + "deployedBytecode": "0x", + "linkReferences": {}, + "deployedLinkReferences": {}, + "immutableReferences": {}, + "inputSourceName": "project/contracts/interfaces/ICreateX.sol", + "buildInfoId": "b650d0a8e9df290d290e91b2999a1f7443c2b528" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-10/artifacts/Create3MimicHelper#MimicHelper.dbg.json b/packages/evm/ignition/deployments/chain-10/artifacts/Create3MimicHelper#MimicHelper.dbg.json new file mode 100644 index 0000000..817dddf --- /dev/null +++ b/packages/evm/ignition/deployments/chain-10/artifacts/Create3MimicHelper#MimicHelper.dbg.json @@ -0,0 +1,4 @@ +{ + "_format": "hh-sol-dbg-1", + "buildInfo": "../build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-10/artifacts/Create3MimicHelper#MimicHelper.json b/packages/evm/ignition/deployments/chain-10/artifacts/Create3MimicHelper#MimicHelper.json new file mode 100644 index 0000000..a01b577 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-10/artifacts/Create3MimicHelper#MimicHelper.json @@ -0,0 +1,33 @@ +{ + "_format": "hh3-artifact-1", + "contractName": "MimicHelper", + "sourceName": "contracts/utils/MimicHelper.sol", + "abi": [ + { + "inputs": [ + { + "internalType": "address", + "name": "target", + "type": "address" + } + ], + "name": "getNativeTokenBalance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + } + ], + "bytecode": "0x6080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033", + "deployedBytecode": "0x6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033", + "linkReferences": {}, + "deployedLinkReferences": {}, + "immutableReferences": {}, + "inputSourceName": "project/contracts/utils/MimicHelper.sol", + "buildInfoId": "b650d0a8e9df290d290e91b2999a1f7443c2b528" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-10/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json b/packages/evm/ignition/deployments/chain-10/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json new file mode 100644 index 0000000..657a777 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-10/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json @@ -0,0 +1,290 @@ +{ + "_format": "hh3-sol-build-info-1", + "id": "b650d0a8e9df290d290e91b2999a1f7443c2b528", + "solcVersion": "0.8.28", + "solcLongVersion": "0.8.28+commit.7893614a", + "userSourceNameMap": { + "contracts/Controller.sol": "project/contracts/Controller.sol", + "contracts/Intents.sol": "project/contracts/Intents.sol", + "contracts/Settler.sol": "project/contracts/Settler.sol", + "contracts/interfaces/IController.sol": "project/contracts/interfaces/IController.sol", + "contracts/interfaces/ICreateX.sol": "project/contracts/interfaces/ICreateX.sol", + "contracts/interfaces/IExecutor.sol": "project/contracts/interfaces/IExecutor.sol", + "contracts/interfaces/IIntentsValidator.sol": "project/contracts/interfaces/IIntentsValidator.sol", + "contracts/interfaces/ISafe.sol": "project/contracts/interfaces/ISafe.sol", + "contracts/interfaces/ISettler.sol": "project/contracts/interfaces/ISettler.sol", + "contracts/interfaces/ISmartAccount.sol": "project/contracts/interfaces/ISmartAccount.sol", + "contracts/interfaces/ISmartAccountContract.sol": "project/contracts/interfaces/ISmartAccountContract.sol", + "contracts/interfaces/ISmartAccountsHandler.sol": "project/contracts/interfaces/ISmartAccountsHandler.sol", + "contracts/safeguards/BaseIntentsValidator.sol": "project/contracts/safeguards/BaseIntentsValidator.sol", + "contracts/safeguards/CallIntentsValidator.sol": "project/contracts/safeguards/CallIntentsValidator.sol", + "contracts/safeguards/IntentsValidator.sol": "project/contracts/safeguards/IntentsValidator.sol", + "contracts/safeguards/Safeguards.sol": "project/contracts/safeguards/Safeguards.sol", + "contracts/safeguards/SwapIntentsValidator.sol": "project/contracts/safeguards/SwapIntentsValidator.sol", + "contracts/safeguards/TransferIntentsValidator.sol": "project/contracts/safeguards/TransferIntentsValidator.sol", + "contracts/smart-accounts/SmartAccount7702.sol": "project/contracts/smart-accounts/SmartAccount7702.sol", + "contracts/smart-accounts/SmartAccountBase.sol": "project/contracts/smart-accounts/SmartAccountBase.sol", + "contracts/smart-accounts/SmartAccountContract.sol": "project/contracts/smart-accounts/SmartAccountContract.sol", + "contracts/smart-accounts/SmartAccountsHandler.sol": "project/contracts/smart-accounts/SmartAccountsHandler.sol", + "contracts/smart-accounts/SmartAccountsHandlerHelpers.sol": "project/contracts/smart-accounts/SmartAccountsHandlerHelpers.sol", + "contracts/test/CallMock.sol": "project/contracts/test/CallMock.sol", + "contracts/test/TokenMock.sol": "project/contracts/test/TokenMock.sol", + "contracts/test/executors/EmptyExecutorMock.sol": "project/contracts/test/executors/EmptyExecutorMock.sol", + "contracts/test/executors/MintExecutorMock.sol": "project/contracts/test/executors/MintExecutorMock.sol", + "contracts/test/executors/ReentrantExecutorMock.sol": "project/contracts/test/executors/ReentrantExecutorMock.sol", + "contracts/test/executors/TransferExecutorMock.sol": "project/contracts/test/executors/TransferExecutorMock.sol", + "contracts/test/smart-accounts/SafeMock.sol": "project/contracts/test/smart-accounts/SafeMock.sol", + "contracts/test/utils/DenominationsMock.sol": "project/contracts/test/utils/DenominationsMock.sol", + "contracts/test/utils/ERC20HelpersMock.sol": "project/contracts/test/utils/ERC20HelpersMock.sol", + "contracts/utils/Denominations.sol": "project/contracts/utils/Denominations.sol", + "contracts/utils/ERC20Helpers.sol": "project/contracts/utils/ERC20Helpers.sol", + "contracts/utils/MimicHelper.sol": "project/contracts/utils/MimicHelper.sol" + }, + "input": { + "language": "Solidity", + "settings": { + "optimizer": { + "enabled": true, + "runs": 1000 + }, + "evmVersion": "cancun", + "outputSelection": { + "*": { + "": [ + "ast" + ], + "*": [ + "abi", + "evm.bytecode", + "evm.deployedBytecode", + "evm.methodIdentifiers", + "metadata" + ] + } + }, + "remappings": [ + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/" + ] + }, + "sources": { + "npm/@openzeppelin/contracts@5.3.0/access/Ownable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)\n\npragma solidity ^0.8.20;\n\nimport {Context} from \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * The initial owner is set to the address provided by the deployer. This can\n * later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n /**\n * @dev The caller account is not authorized to perform an operation.\n */\n error OwnableUnauthorizedAccount(address account);\n\n /**\n * @dev The owner is not a valid owner account. (eg. `address(0)`)\n */\n error OwnableInvalidOwner(address owner);\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the address provided by the deployer as the initial owner.\n */\n constructor(address initialOwner) {\n if (initialOwner == address(0)) {\n revert OwnableInvalidOwner(address(0));\n }\n _transferOwnership(initialOwner);\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n if (owner() != _msgSender()) {\n revert OwnableUnauthorizedAccount(_msgSender());\n }\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby disabling any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n if (newOwner == address(0)) {\n revert OwnableInvalidOwner(address(0));\n }\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/draft-IERC6093.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol)\npragma solidity ^0.8.20;\n\n/**\n * @dev Standard ERC-20 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.\n */\ninterface IERC20Errors {\n /**\n * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param balance Current balance for the interacting account.\n * @param needed Minimum amount required to perform a transfer.\n */\n error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC20InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC20InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.\n * @param spender Address that may be allowed to operate on tokens without being their owner.\n * @param allowance Amount of tokens a `spender` is allowed to operate with.\n * @param needed Minimum amount required to perform a transfer.\n */\n error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC20InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `spender` to be approved. Used in approvals.\n * @param spender Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC20InvalidSpender(address spender);\n}\n\n/**\n * @dev Standard ERC-721 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.\n */\ninterface IERC721Errors {\n /**\n * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.\n * Used in balance queries.\n * @param owner Address of the current owner of a token.\n */\n error ERC721InvalidOwner(address owner);\n\n /**\n * @dev Indicates a `tokenId` whose `owner` is the zero address.\n * @param tokenId Identifier number of a token.\n */\n error ERC721NonexistentToken(uint256 tokenId);\n\n /**\n * @dev Indicates an error related to the ownership over a particular token. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param tokenId Identifier number of a token.\n * @param owner Address of the current owner of a token.\n */\n error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC721InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC721InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n * @param tokenId Identifier number of a token.\n */\n error ERC721InsufficientApproval(address operator, uint256 tokenId);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC721InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC721InvalidOperator(address operator);\n}\n\n/**\n * @dev Standard ERC-1155 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.\n */\ninterface IERC1155Errors {\n /**\n * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param balance Current balance for the interacting account.\n * @param needed Minimum amount required to perform a transfer.\n * @param tokenId Identifier number of a token.\n */\n error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC1155InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC1155InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n * @param owner Address of the current owner of a token.\n */\n error ERC1155MissingApprovalForAll(address operator, address owner);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC1155InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC1155InvalidOperator(address operator);\n\n /**\n * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.\n * Used in batch transfers.\n * @param idsLength Length of the array of token identifiers\n * @param valuesLength Length of the array of token amounts\n */\n error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC1271.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (interfaces/IERC1271.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-1271 standard signature validation method for\n * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].\n */\ninterface IERC1271 {\n /**\n * @dev Should return whether the signature provided is valid for the provided data\n * @param hash Hash of the data to be signed\n * @param signature Signature byte array associated with `hash`\n */\n function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC1363.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"./IERC20.sol\";\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @title IERC1363\n * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].\n *\n * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract\n * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.\n */\ninterface IERC1363 is IERC20, IERC165 {\n /*\n * Note: the ERC-165 identifier for this interface is 0xb0202a11.\n * 0xb0202a11 ===\n * bytes4(keccak256('transferAndCall(address,uint256)')) ^\n * bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^\n * bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^\n * bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^\n * bytes4(keccak256('approveAndCall(address,uint256)')) ^\n * bytes4(keccak256('approveAndCall(address,uint256,bytes)'))\n */\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferAndCall(address to, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @param data Additional data with no specified format, sent in call to `to`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param from The address which you want to send tokens from.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferFromAndCall(address from, address to, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param from The address which you want to send tokens from.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @param data Additional data with no specified format, sent in call to `to`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.\n * @param spender The address which will spend the funds.\n * @param value The amount of tokens to be spent.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function approveAndCall(address spender, uint256 value) external returns (bool);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.\n * @param spender The address which will spend the funds.\n * @param value The amount of tokens to be spent.\n * @param data Additional data with no specified format, sent in call to `spender`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"../utils/introspection/IERC165.sol\";\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../token/ERC20/IERC20.sol\";\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC5267.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)\n\npragma solidity ^0.8.20;\n\ninterface IERC5267 {\n /**\n * @dev MAY be emitted to signal that the domain could have changed.\n */\n event EIP712DomainChanged();\n\n /**\n * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712\n * signature.\n */\n function eip712Domain()\n external\n view\n returns (\n bytes1 fields,\n string memory name,\n string memory version,\n uint256 chainId,\n address verifyingContract,\n bytes32 salt,\n uint256[] memory extensions\n );\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/ERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"./IERC20.sol\";\nimport {IERC20Metadata} from \"./extensions/IERC20Metadata.sol\";\nimport {Context} from \"../../utils/Context.sol\";\nimport {IERC20Errors} from \"../../interfaces/draft-IERC6093.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * The default value of {decimals} is 18. To change this, you should override\n * this function so it returns a different value.\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC-20\n * applications.\n */\nabstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {\n mapping(address account => uint256) private _balances;\n\n mapping(address account => mapping(address spender => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * Both values are immutable: they can only be set once during construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the default value returned by this function, unless\n * it's overridden.\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `value`.\n */\n function transfer(address to, uint256 value) public virtual returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, value);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 value) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, value);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Skips emitting an {Approval} event indicating an allowance update. This is not\n * required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `value`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `value`.\n */\n function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, value);\n _transfer(from, to, value);\n return true;\n }\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead.\n */\n function _transfer(address from, address to, uint256 value) internal {\n if (from == address(0)) {\n revert ERC20InvalidSender(address(0));\n }\n if (to == address(0)) {\n revert ERC20InvalidReceiver(address(0));\n }\n _update(from, to, value);\n }\n\n /**\n * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`\n * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding\n * this function.\n *\n * Emits a {Transfer} event.\n */\n function _update(address from, address to, uint256 value) internal virtual {\n if (from == address(0)) {\n // Overflow check required: The rest of the code assumes that totalSupply never overflows\n _totalSupply += value;\n } else {\n uint256 fromBalance = _balances[from];\n if (fromBalance < value) {\n revert ERC20InsufficientBalance(from, fromBalance, value);\n }\n unchecked {\n // Overflow not possible: value <= fromBalance <= totalSupply.\n _balances[from] = fromBalance - value;\n }\n }\n\n if (to == address(0)) {\n unchecked {\n // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.\n _totalSupply -= value;\n }\n } else {\n unchecked {\n // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.\n _balances[to] += value;\n }\n }\n\n emit Transfer(from, to, value);\n }\n\n /**\n * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).\n * Relies on the `_update` mechanism\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead.\n */\n function _mint(address account, uint256 value) internal {\n if (account == address(0)) {\n revert ERC20InvalidReceiver(address(0));\n }\n _update(address(0), account, value);\n }\n\n /**\n * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.\n * Relies on the `_update` mechanism.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead\n */\n function _burn(address account, uint256 value) internal {\n if (account == address(0)) {\n revert ERC20InvalidSender(address(0));\n }\n _update(account, address(0), value);\n }\n\n /**\n * @dev Sets `value` as the allowance of `spender` over the `owner`'s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n *\n * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.\n */\n function _approve(address owner, address spender, uint256 value) internal {\n _approve(owner, spender, value, true);\n }\n\n /**\n * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.\n *\n * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by\n * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any\n * `Approval` event during `transferFrom` operations.\n *\n * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to\n * true using the following override:\n *\n * ```solidity\n * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {\n * super._approve(owner, spender, value, true);\n * }\n * ```\n *\n * Requirements are the same as {_approve}.\n */\n function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {\n if (owner == address(0)) {\n revert ERC20InvalidApprover(address(0));\n }\n if (spender == address(0)) {\n revert ERC20InvalidSpender(address(0));\n }\n _allowances[owner][spender] = value;\n if (emitEvent) {\n emit Approval(owner, spender, value);\n }\n }\n\n /**\n * @dev Updates `owner`'s allowance for `spender` based on spent `value`.\n *\n * Does not update the allowance value in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Does not emit an {Approval} event.\n */\n function _spendAllowance(address owner, address spender, uint256 value) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance < type(uint256).max) {\n if (currentAllowance < value) {\n revert ERC20InsufficientAllowance(spender, currentAllowance, value);\n }\n unchecked {\n _approve(owner, spender, currentAllowance - value, false);\n }\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/extensions/IERC20Metadata.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC-20 standard.\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-20 standard as defined in the ERC.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the value of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the value of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 value) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the\n * allowance mechanism. `value` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(address from, address to, uint256 value) external returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/utils/SafeERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../IERC20.sol\";\nimport {IERC1363} from \"../../../interfaces/IERC1363.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC-20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n /**\n * @dev An operation with an ERC-20 token failed.\n */\n error SafeERC20FailedOperation(address token);\n\n /**\n * @dev Indicates a failed `decreaseAllowance` request.\n */\n error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);\n\n /**\n * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,\n * non-reverting calls are assumed to be successful.\n */\n function safeTransfer(IERC20 token, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));\n }\n\n /**\n * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the\n * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.\n */\n function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));\n }\n\n /**\n * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.\n */\n function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {\n return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));\n }\n\n /**\n * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.\n */\n function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {\n return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));\n }\n\n /**\n * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n * non-reverting calls are assumed to be successful.\n *\n * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the \"client\"\n * smart contract uses ERC-7674 to set temporary allowances, then the \"client\" smart contract should avoid using\n * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract\n * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.\n */\n function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n uint256 oldAllowance = token.allowance(address(this), spender);\n forceApprove(token, spender, oldAllowance + value);\n }\n\n /**\n * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no\n * value, non-reverting calls are assumed to be successful.\n *\n * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the \"client\"\n * smart contract uses ERC-7674 to set temporary allowances, then the \"client\" smart contract should avoid using\n * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract\n * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.\n */\n function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {\n unchecked {\n uint256 currentAllowance = token.allowance(address(this), spender);\n if (currentAllowance < requestedDecrease) {\n revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);\n }\n forceApprove(token, spender, currentAllowance - requestedDecrease);\n }\n }\n\n /**\n * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,\n * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval\n * to be set to zero before setting it to a non-zero value, such as USDT.\n *\n * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function\n * only sets the \"standard\" allowance. Any temporary allowance will remain active, in addition to the value being\n * set here.\n */\n function forceApprove(IERC20 token, address spender, uint256 value) internal {\n bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));\n\n if (!_callOptionalReturnBool(token, approvalCall)) {\n _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));\n _callOptionalReturn(token, approvalCall);\n }\n }\n\n /**\n * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no\n * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * Reverts if the returned value is other than `true`.\n */\n function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {\n if (to.code.length == 0) {\n safeTransfer(token, to, value);\n } else if (!token.transferAndCall(to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target\n * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * Reverts if the returned value is other than `true`.\n */\n function transferFromAndCallRelaxed(\n IERC1363 token,\n address from,\n address to,\n uint256 value,\n bytes memory data\n ) internal {\n if (to.code.length == 0) {\n safeTransferFrom(token, from, to, value);\n } else if (!token.transferFromAndCall(from, to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no\n * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.\n * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}\n * once without retrying, and relies on the returned value to be true.\n *\n * Reverts if the returned value is other than `true`.\n */\n function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {\n if (to.code.length == 0) {\n forceApprove(token, to, value);\n } else if (!token.approveAndCall(to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n *\n * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.\n */\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)\n // bubble errors\n if iszero(success) {\n let ptr := mload(0x40)\n returndatacopy(ptr, 0, returndatasize())\n revert(ptr, returndatasize())\n }\n returnSize := returndatasize()\n returnValue := mload(0)\n }\n\n if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n *\n * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.\n */\n function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {\n bool success;\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)\n returnSize := returndatasize()\n returnValue := mload(0)\n }\n return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Address.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.2.0) (utils/Address.sol)\n\npragma solidity ^0.8.20;\n\nimport {Errors} from \"./Errors.sol\";\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev There's no code at `target` (it is not a contract).\n */\n error AddressEmptyCode(address target);\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n if (address(this).balance < amount) {\n revert Errors.InsufficientBalance(address(this).balance, amount);\n }\n\n (bool success, bytes memory returndata) = recipient.call{value: amount}(\"\");\n if (!success) {\n _revert(returndata);\n }\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason or custom error, it is bubbled\n * up by this function (like regular Solidity function calls). However, if\n * the call reverted with no returned reason, this function reverts with a\n * {Errors.FailedCall} error.\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n */\n function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n if (address(this).balance < value) {\n revert Errors.InsufficientBalance(address(this).balance, value);\n }\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target\n * was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case\n * of an unsuccessful call.\n */\n function verifyCallResultFromTarget(\n address target,\n bool success,\n bytes memory returndata\n ) internal view returns (bytes memory) {\n if (!success) {\n _revert(returndata);\n } else {\n // only check if target is a contract if the call was successful and the return data is empty\n // otherwise we already know that it was a contract\n if (returndata.length == 0 && target.code.length == 0) {\n revert AddressEmptyCode(target);\n }\n return returndata;\n }\n }\n\n /**\n * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the\n * revert reason or with a default {Errors.FailedCall} error.\n */\n function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {\n if (!success) {\n _revert(returndata);\n } else {\n return returndata;\n }\n }\n\n /**\n * @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.\n */\n function _revert(bytes memory returndata) private pure {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n assembly (\"memory-safe\") {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert Errors.FailedCall();\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Context.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n\n function _contextSuffixLength() internal view virtual returns (uint256) {\n return 0;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/ECDSA.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/ECDSA.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.\n *\n * These functions can be used to verify that a message was signed by the holder\n * of the private keys of a given address.\n */\nlibrary ECDSA {\n enum RecoverError {\n NoError,\n InvalidSignature,\n InvalidSignatureLength,\n InvalidSignatureS\n }\n\n /**\n * @dev The signature derives the `address(0)`.\n */\n error ECDSAInvalidSignature();\n\n /**\n * @dev The signature has an invalid length.\n */\n error ECDSAInvalidSignatureLength(uint256 length);\n\n /**\n * @dev The signature has an S value that is in the upper half order.\n */\n error ECDSAInvalidSignatureS(bytes32 s);\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not\n * return address(0) without also returning an error description. Errors are documented using an enum (error type)\n * and a bytes32 providing additional information about the error.\n *\n * If no error is returned, then the address can be used for verification purposes.\n *\n * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.\n *\n * Documentation for signature generation:\n * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]\n * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]\n */\n function tryRecover(\n bytes32 hash,\n bytes memory signature\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n if (signature.length == 65) {\n bytes32 r;\n bytes32 s;\n uint8 v;\n // ecrecover takes the signature parameters, and the only way to get them\n // currently is to use assembly.\n assembly (\"memory-safe\") {\n r := mload(add(signature, 0x20))\n s := mload(add(signature, 0x40))\n v := byte(0, mload(add(signature, 0x60)))\n }\n return tryRecover(hash, v, r, s);\n } else {\n return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));\n }\n }\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with\n * `signature`. This address can then be used for verification purposes.\n *\n * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.\n */\n function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.\n *\n * See https://eips.ethereum.org/EIPS/eip-2098[ERC-2098 short signatures]\n */\n function tryRecover(\n bytes32 hash,\n bytes32 r,\n bytes32 vs\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n unchecked {\n bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n // We do not check for an overflow here since the shift operation results in 0 or 1.\n uint8 v = uint8((uint256(vs) >> 255) + 27);\n return tryRecover(hash, v, r, s);\n }\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\n */\n function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function tryRecover(\n bytes32 hash,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\n // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\n // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\n // signatures from current libraries generate a unique signature with an s-value in the lower half order.\n //\n // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\n // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\n // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\n // these malleable signatures as well.\n if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\n return (address(0), RecoverError.InvalidSignatureS, s);\n }\n\n // If the signature is valid (and not malleable), return the signer address\n address signer = ecrecover(hash, v, r, s);\n if (signer == address(0)) {\n return (address(0), RecoverError.InvalidSignature, bytes32(0));\n }\n\n return (signer, RecoverError.NoError, bytes32(0));\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.\n */\n function _throwError(RecoverError error, bytes32 errorArg) private pure {\n if (error == RecoverError.NoError) {\n return; // no error: do nothing\n } else if (error == RecoverError.InvalidSignature) {\n revert ECDSAInvalidSignature();\n } else if (error == RecoverError.InvalidSignatureLength) {\n revert ECDSAInvalidSignatureLength(uint256(errorArg));\n } else if (error == RecoverError.InvalidSignatureS) {\n revert ECDSAInvalidSignatureS(errorArg);\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/EIP712.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/EIP712.sol)\n\npragma solidity ^0.8.20;\n\nimport {MessageHashUtils} from \"./MessageHashUtils.sol\";\nimport {ShortStrings, ShortString} from \"../ShortStrings.sol\";\nimport {IERC5267} from \"../../interfaces/IERC5267.sol\";\n\n/**\n * @dev https://eips.ethereum.org/EIPS/eip-712[EIP-712] is a standard for hashing and signing of typed structured data.\n *\n * The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose\n * encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract\n * does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to\n * produce the hash of their typed data using a combination of `abi.encode` and `keccak256`.\n *\n * This contract implements the EIP-712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding\n * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA\n * ({_hashTypedDataV4}).\n *\n * The implementation of the domain separator was designed to be as efficient as possible while still properly updating\n * the chain id to protect against replay attacks on an eventual fork of the chain.\n *\n * NOTE: This contract implements the version of the encoding known as \"v4\", as implemented by the JSON RPC method\n * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].\n *\n * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain\n * separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the\n * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.\n *\n * @custom:oz-upgrades-unsafe-allow state-variable-immutable\n */\nabstract contract EIP712 is IERC5267 {\n using ShortStrings for *;\n\n bytes32 private constant TYPE_HASH =\n keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\");\n\n // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to\n // invalidate the cached domain separator if the chain id changes.\n bytes32 private immutable _cachedDomainSeparator;\n uint256 private immutable _cachedChainId;\n address private immutable _cachedThis;\n\n bytes32 private immutable _hashedName;\n bytes32 private immutable _hashedVersion;\n\n ShortString private immutable _name;\n ShortString private immutable _version;\n // slither-disable-next-line constable-states\n string private _nameFallback;\n // slither-disable-next-line constable-states\n string private _versionFallback;\n\n /**\n * @dev Initializes the domain separator and parameter caches.\n *\n * The meaning of `name` and `version` is specified in\n * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP-712]:\n *\n * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.\n * - `version`: the current major version of the signing domain.\n *\n * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart\n * contract upgrade].\n */\n constructor(string memory name, string memory version) {\n _name = name.toShortStringWithFallback(_nameFallback);\n _version = version.toShortStringWithFallback(_versionFallback);\n _hashedName = keccak256(bytes(name));\n _hashedVersion = keccak256(bytes(version));\n\n _cachedChainId = block.chainid;\n _cachedDomainSeparator = _buildDomainSeparator();\n _cachedThis = address(this);\n }\n\n /**\n * @dev Returns the domain separator for the current chain.\n */\n function _domainSeparatorV4() internal view returns (bytes32) {\n if (address(this) == _cachedThis && block.chainid == _cachedChainId) {\n return _cachedDomainSeparator;\n } else {\n return _buildDomainSeparator();\n }\n }\n\n function _buildDomainSeparator() private view returns (bytes32) {\n return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));\n }\n\n /**\n * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this\n * function returns the hash of the fully encoded EIP712 message for this domain.\n *\n * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:\n *\n * ```solidity\n * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(\n * keccak256(\"Mail(address to,string contents)\"),\n * mailTo,\n * keccak256(bytes(mailContents))\n * )));\n * address signer = ECDSA.recover(digest, signature);\n * ```\n */\n function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {\n return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);\n }\n\n /**\n * @inheritdoc IERC5267\n */\n function eip712Domain()\n public\n view\n virtual\n returns (\n bytes1 fields,\n string memory name,\n string memory version,\n uint256 chainId,\n address verifyingContract,\n bytes32 salt,\n uint256[] memory extensions\n )\n {\n return (\n hex\"0f\", // 01111\n _EIP712Name(),\n _EIP712Version(),\n block.chainid,\n address(this),\n bytes32(0),\n new uint256[](0)\n );\n }\n\n /**\n * @dev The name parameter for the EIP712 domain.\n *\n * NOTE: By default this function reads _name which is an immutable value.\n * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).\n */\n // solhint-disable-next-line func-name-mixedcase\n function _EIP712Name() internal view returns (string memory) {\n return _name.toStringWithFallback(_nameFallback);\n }\n\n /**\n * @dev The version parameter for the EIP712 domain.\n *\n * NOTE: By default this function reads _version which is an immutable value.\n * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).\n */\n // solhint-disable-next-line func-name-mixedcase\n function _EIP712Version() internal view returns (string memory) {\n return _version.toStringWithFallback(_versionFallback);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/MessageHashUtils.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/MessageHashUtils.sol)\n\npragma solidity ^0.8.20;\n\nimport {Strings} from \"../Strings.sol\";\n\n/**\n * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.\n *\n * The library provides methods for generating a hash of a message that conforms to the\n * https://eips.ethereum.org/EIPS/eip-191[ERC-191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]\n * specifications.\n */\nlibrary MessageHashUtils {\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x45` (`personal_sign` messages).\n *\n * The digest is calculated by prefixing a bytes32 `messageHash` with\n * `\"\\x19Ethereum Signed Message:\\n32\"` and hashing the result. It corresponds with the\n * hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.\n *\n * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with\n * keccak256, although any bytes32 value can be safely used because the final digest will\n * be re-hashed.\n *\n * See {ECDSA-recover}.\n */\n function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n mstore(0x00, \"\\x19Ethereum Signed Message:\\n32\") // 32 is the bytes-length of messageHash\n mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix\n digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)\n }\n }\n\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x45` (`personal_sign` messages).\n *\n * The digest is calculated by prefixing an arbitrary `message` with\n * `\"\\x19Ethereum Signed Message:\\n\" + len(message)` and hashing the result. It corresponds with the\n * hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.\n *\n * See {ECDSA-recover}.\n */\n function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {\n return\n keccak256(bytes.concat(\"\\x19Ethereum Signed Message:\\n\", bytes(Strings.toString(message.length)), message));\n }\n\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x00` (data with intended validator).\n *\n * The digest is calculated by prefixing an arbitrary `data` with `\"\\x19\\x00\"` and the intended\n * `validator` address. Then hashing the result.\n *\n * See {ECDSA-recover}.\n */\n function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(hex\"19_00\", validator, data));\n }\n\n /**\n * @dev Variant of {toDataWithIntendedValidatorHash-address-bytes} optimized for cases where `data` is a bytes32.\n */\n function toDataWithIntendedValidatorHash(\n address validator,\n bytes32 messageHash\n ) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n mstore(0x00, hex\"19_00\")\n mstore(0x02, shl(96, validator))\n mstore(0x16, messageHash)\n digest := keccak256(0x00, 0x36)\n }\n }\n\n /**\n * @dev Returns the keccak256 digest of an EIP-712 typed data (ERC-191 version `0x01`).\n *\n * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with\n * `\\x19\\x01` and hashing the result. It corresponds to the hash signed by the\n * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.\n *\n * See {ECDSA-recover}.\n */\n function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n let ptr := mload(0x40)\n mstore(ptr, hex\"19_01\")\n mstore(add(ptr, 0x02), domainSeparator)\n mstore(add(ptr, 0x22), structHash)\n digest := keccak256(ptr, 0x42)\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Errors.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Collection of common custom errors used in multiple contracts\n *\n * IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.\n * It is recommended to avoid relying on the error API for critical functionality.\n *\n * _Available since v5.1._\n */\nlibrary Errors {\n /**\n * @dev The ETH balance of the account is not enough to perform the operation.\n */\n error InsufficientBalance(uint256 balance, uint256 needed);\n\n /**\n * @dev A call to an address target failed. The target may have reverted.\n */\n error FailedCall();\n\n /**\n * @dev The deployment failed.\n */\n error FailedDeployment();\n\n /**\n * @dev A necessary precompile is missing.\n */\n error MissingPrecompile(address);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/ERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/ERC165Checker.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165Checker.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @dev Library used to query support of an interface declared via {IERC165}.\n *\n * Note that these functions return the actual result of the query: they do not\n * `revert` if an interface is not supported. It is up to the caller to decide\n * what to do in these cases.\n */\nlibrary ERC165Checker {\n // As per the ERC-165 spec, no interface should ever match 0xffffffff\n bytes4 private constant INTERFACE_ID_INVALID = 0xffffffff;\n\n /**\n * @dev Returns true if `account` supports the {IERC165} interface.\n */\n function supportsERC165(address account) internal view returns (bool) {\n // Any contract that implements ERC-165 must explicitly indicate support of\n // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid\n return\n supportsERC165InterfaceUnchecked(account, type(IERC165).interfaceId) &&\n !supportsERC165InterfaceUnchecked(account, INTERFACE_ID_INVALID);\n }\n\n /**\n * @dev Returns true if `account` supports the interface defined by\n * `interfaceId`. Support for {IERC165} itself is queried automatically.\n *\n * See {IERC165-supportsInterface}.\n */\n function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {\n // query support of both ERC-165 as per the spec and support of _interfaceId\n return supportsERC165(account) && supportsERC165InterfaceUnchecked(account, interfaceId);\n }\n\n /**\n * @dev Returns a boolean array where each value corresponds to the\n * interfaces passed in and whether they're supported or not. This allows\n * you to batch check interfaces for a contract where your expectation\n * is that some interfaces may not be supported.\n *\n * See {IERC165-supportsInterface}.\n */\n function getSupportedInterfaces(\n address account,\n bytes4[] memory interfaceIds\n ) internal view returns (bool[] memory) {\n // an array of booleans corresponding to interfaceIds and whether they're supported or not\n bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length);\n\n // query support of ERC-165 itself\n if (supportsERC165(account)) {\n // query support of each interface in interfaceIds\n for (uint256 i = 0; i < interfaceIds.length; i++) {\n interfaceIdsSupported[i] = supportsERC165InterfaceUnchecked(account, interfaceIds[i]);\n }\n }\n\n return interfaceIdsSupported;\n }\n\n /**\n * @dev Returns true if `account` supports all the interfaces defined in\n * `interfaceIds`. Support for {IERC165} itself is queried automatically.\n *\n * Batch-querying can lead to gas savings by skipping repeated checks for\n * {IERC165} support.\n *\n * See {IERC165-supportsInterface}.\n */\n function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {\n // query support of ERC-165 itself\n if (!supportsERC165(account)) {\n return false;\n }\n\n // query support of each interface in interfaceIds\n for (uint256 i = 0; i < interfaceIds.length; i++) {\n if (!supportsERC165InterfaceUnchecked(account, interfaceIds[i])) {\n return false;\n }\n }\n\n // all interfaces supported\n return true;\n }\n\n /**\n * @notice Query if a contract implements an interface, does not check ERC-165 support\n * @param account The address of the contract to query for support of an interface\n * @param interfaceId The interface identifier, as specified in ERC-165\n * @return true if the contract at account indicates support of the interface with\n * identifier interfaceId, false otherwise\n * @dev Assumes that account contains a contract that supports ERC-165, otherwise\n * the behavior of this method is undefined. This precondition can be checked\n * with {supportsERC165}.\n *\n * Some precompiled contracts will falsely indicate support for a given interface, so caution\n * should be exercised when using this function.\n *\n * Interface identification is specified in ERC-165.\n */\n function supportsERC165InterfaceUnchecked(address account, bytes4 interfaceId) internal view returns (bool) {\n // prepare call\n bytes memory encodedParams = abi.encodeCall(IERC165.supportsInterface, (interfaceId));\n\n // perform static call\n bool success;\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n success := staticcall(30000, account, add(encodedParams, 0x20), mload(encodedParams), 0x00, 0x20)\n returnSize := returndatasize()\n returnValue := mload(0x00)\n }\n\n return success && returnSize >= 0x20 && returnValue > 0;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/IERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[ERC].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/Math.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.20;\n\nimport {Panic} from \"../Panic.sol\";\nimport {SafeCast} from \"./SafeCast.sol\";\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n enum Rounding {\n Floor, // Toward negative infinity\n Ceil, // Toward positive infinity\n Trunc, // Toward zero\n Expand // Away from zero\n }\n\n /**\n * @dev Return the 512-bit addition of two uint256.\n *\n * The result is stored in two 256 variables such that sum = high * 2²⁵⁶ + low.\n */\n function add512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {\n assembly (\"memory-safe\") {\n low := add(a, b)\n high := lt(low, a)\n }\n }\n\n /**\n * @dev Return the 512-bit multiplication of two uint256.\n *\n * The result is stored in two 256 variables such that product = high * 2²⁵⁶ + low.\n */\n function mul512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {\n // 512-bit multiply [high low] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use\n // the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n // variables such that product = high * 2²⁵⁶ + low.\n assembly (\"memory-safe\") {\n let mm := mulmod(a, b, not(0))\n low := mul(a, b)\n high := sub(sub(mm, low), lt(mm, low))\n }\n }\n\n /**\n * @dev Returns the addition of two unsigned integers, with a success flag (no overflow).\n */\n function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a + b;\n success = c >= a;\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, with a success flag (no overflow).\n */\n function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a - b;\n success = c <= a;\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, with a success flag (no overflow).\n */\n function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a * b;\n assembly (\"memory-safe\") {\n // Only true when the multiplication doesn't overflow\n // (c / a == b) || (a == 0)\n success := or(eq(div(c, a), b), iszero(a))\n }\n // equivalent to: success ? c : 0\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the division of two unsigned integers, with a success flag (no division by zero).\n */\n function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n success = b > 0;\n assembly (\"memory-safe\") {\n // The `DIV` opcode returns zero when the denominator is 0.\n result := div(a, b)\n }\n }\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).\n */\n function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n success = b > 0;\n assembly (\"memory-safe\") {\n // The `MOD` opcode returns zero when the denominator is 0.\n result := mod(a, b)\n }\n }\n }\n\n /**\n * @dev Unsigned saturating addition, bounds to `2²⁵⁶ - 1` instead of overflowing.\n */\n function saturatingAdd(uint256 a, uint256 b) internal pure returns (uint256) {\n (bool success, uint256 result) = tryAdd(a, b);\n return ternary(success, result, type(uint256).max);\n }\n\n /**\n * @dev Unsigned saturating subtraction, bounds to zero instead of overflowing.\n */\n function saturatingSub(uint256 a, uint256 b) internal pure returns (uint256) {\n (, uint256 result) = trySub(a, b);\n return result;\n }\n\n /**\n * @dev Unsigned saturating multiplication, bounds to `2²⁵⁶ - 1` instead of overflowing.\n */\n function saturatingMul(uint256 a, uint256 b) internal pure returns (uint256) {\n (bool success, uint256 result) = tryMul(a, b);\n return ternary(success, result, type(uint256).max);\n }\n\n /**\n * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.\n *\n * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.\n * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute\n * one branch when needed, making this function more expensive.\n */\n function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {\n unchecked {\n // branchless ternary works because:\n // b ^ (a ^ b) == a\n // b ^ 0 == b\n return b ^ ((a ^ b) * SafeCast.toUint(condition));\n }\n }\n\n /**\n * @dev Returns the largest of two numbers.\n */\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\n return ternary(a > b, a, b);\n }\n\n /**\n * @dev Returns the smallest of two numbers.\n */\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\n return ternary(a < b, a, b);\n }\n\n /**\n * @dev Returns the average of two numbers. The result is rounded towards\n * zero.\n */\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b) / 2 can overflow.\n return (a & b) + (a ^ b) / 2;\n }\n\n /**\n * @dev Returns the ceiling of the division of two numbers.\n *\n * This differs from standard division with `/` in that it rounds towards infinity instead\n * of rounding towards zero.\n */\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n if (b == 0) {\n // Guarantee the same behavior as in a regular Solidity division.\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n\n // The following calculation ensures accurate ceiling division without overflow.\n // Since a is non-zero, (a - 1) / b will not overflow.\n // The largest possible result occurs when (a - 1) / b is type(uint256).max,\n // but the largest value we can obtain is type(uint256).max - 1, which happens\n // when a = type(uint256).max and b = 1.\n unchecked {\n return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);\n }\n }\n\n /**\n * @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or\n * denominator == 0.\n *\n * Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by\n * Uniswap Labs also under MIT license.\n */\n function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {\n unchecked {\n (uint256 high, uint256 low) = mul512(x, y);\n\n // Handle non-overflow cases, 256 by 256 division.\n if (high == 0) {\n // Solidity will revert if denominator == 0, unlike the div opcode on its own.\n // The surrounding unchecked block does not change this fact.\n // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.\n return low / denominator;\n }\n\n // Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.\n if (denominator <= high) {\n Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));\n }\n\n ///////////////////////////////////////////////\n // 512 by 256 division.\n ///////////////////////////////////////////////\n\n // Make division exact by subtracting the remainder from [high low].\n uint256 remainder;\n assembly (\"memory-safe\") {\n // Compute remainder using mulmod.\n remainder := mulmod(x, y, denominator)\n\n // Subtract 256 bit number from 512 bit number.\n high := sub(high, gt(remainder, low))\n low := sub(low, remainder)\n }\n\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator.\n // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.\n\n uint256 twos = denominator & (0 - denominator);\n assembly (\"memory-safe\") {\n // Divide denominator by twos.\n denominator := div(denominator, twos)\n\n // Divide [high low] by twos.\n low := div(low, twos)\n\n // Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.\n twos := add(div(sub(0, twos), twos), 1)\n }\n\n // Shift in bits from high into low.\n low |= high * twos;\n\n // Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such\n // that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for\n // four bits. That is, denominator * inv ≡ 1 mod 2⁴.\n uint256 inverse = (3 * denominator) ^ 2;\n\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also\n // works in modular arithmetic, doubling the correct bits in each step.\n inverse *= 2 - denominator * inverse; // inverse mod 2⁸\n inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶\n inverse *= 2 - denominator * inverse; // inverse mod 2³²\n inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴\n inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸\n inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶\n\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n // This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is\n // less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and high\n // is no longer required.\n result = low * inverse;\n return result;\n }\n }\n\n /**\n * @dev Calculates x * y / denominator with full precision, following the selected rounding direction.\n */\n function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {\n return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);\n }\n\n /**\n * @dev Calculates floor(x * y >> n) with full precision. Throws if result overflows a uint256.\n */\n function mulShr(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 result) {\n unchecked {\n (uint256 high, uint256 low) = mul512(x, y);\n if (high >= 1 << n) {\n Panic.panic(Panic.UNDER_OVERFLOW);\n }\n return (high << (256 - n)) | (low >> n);\n }\n }\n\n /**\n * @dev Calculates x * y >> n with full precision, following the selected rounding direction.\n */\n function mulShr(uint256 x, uint256 y, uint8 n, Rounding rounding) internal pure returns (uint256) {\n return mulShr(x, y, n) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, 1 << n) > 0);\n }\n\n /**\n * @dev Calculate the modular multiplicative inverse of a number in Z/nZ.\n *\n * If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.\n * If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.\n *\n * If the input value is not inversible, 0 is returned.\n *\n * NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the\n * inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.\n */\n function invMod(uint256 a, uint256 n) internal pure returns (uint256) {\n unchecked {\n if (n == 0) return 0;\n\n // The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)\n // Used to compute integers x and y such that: ax + ny = gcd(a, n).\n // When the gcd is 1, then the inverse of a modulo n exists and it's x.\n // ax + ny = 1\n // ax = 1 + (-y)n\n // ax ≡ 1 (mod n) # x is the inverse of a modulo n\n\n // If the remainder is 0 the gcd is n right away.\n uint256 remainder = a % n;\n uint256 gcd = n;\n\n // Therefore the initial coefficients are:\n // ax + ny = gcd(a, n) = n\n // 0a + 1n = n\n int256 x = 0;\n int256 y = 1;\n\n while (remainder != 0) {\n uint256 quotient = gcd / remainder;\n\n (gcd, remainder) = (\n // The old remainder is the next gcd to try.\n remainder,\n // Compute the next remainder.\n // Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd\n // where gcd is at most n (capped to type(uint256).max)\n gcd - remainder * quotient\n );\n\n (x, y) = (\n // Increment the coefficient of a.\n y,\n // Decrement the coefficient of n.\n // Can overflow, but the result is casted to uint256 so that the\n // next value of y is \"wrapped around\" to a value between 0 and n - 1.\n x - y * int256(quotient)\n );\n }\n\n if (gcd != 1) return 0; // No inverse exists.\n return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.\n }\n }\n\n /**\n * @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.\n *\n * From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is\n * prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that\n * `a**(p-2)` is the modular multiplicative inverse of a in Fp.\n *\n * NOTE: this function does NOT check that `p` is a prime greater than `2`.\n */\n function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {\n unchecked {\n return Math.modExp(a, p - 2, p);\n }\n }\n\n /**\n * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)\n *\n * Requirements:\n * - modulus can't be zero\n * - underlying staticcall to precompile must succeed\n *\n * IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make\n * sure the chain you're using it on supports the precompiled contract for modular exponentiation\n * at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,\n * the underlying function will succeed given the lack of a revert, but the result may be incorrectly\n * interpreted as 0.\n */\n function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {\n (bool success, uint256 result) = tryModExp(b, e, m);\n if (!success) {\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n return result;\n }\n\n /**\n * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).\n * It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying\n * to operate modulo 0 or if the underlying precompile reverted.\n *\n * IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain\n * you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in\n * https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack\n * of a revert, but the result may be incorrectly interpreted as 0.\n */\n function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {\n if (m == 0) return (false, 0);\n assembly (\"memory-safe\") {\n let ptr := mload(0x40)\n // | Offset | Content | Content (Hex) |\n // |-----------|------------|--------------------------------------------------------------------|\n // | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x60:0x7f | value of b | 0x<.............................................................b> |\n // | 0x80:0x9f | value of e | 0x<.............................................................e> |\n // | 0xa0:0xbf | value of m | 0x<.............................................................m> |\n mstore(ptr, 0x20)\n mstore(add(ptr, 0x20), 0x20)\n mstore(add(ptr, 0x40), 0x20)\n mstore(add(ptr, 0x60), b)\n mstore(add(ptr, 0x80), e)\n mstore(add(ptr, 0xa0), m)\n\n // Given the result < m, it's guaranteed to fit in 32 bytes,\n // so we can use the memory scratch space located at offset 0.\n success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)\n result := mload(0x00)\n }\n }\n\n /**\n * @dev Variant of {modExp} that supports inputs of arbitrary length.\n */\n function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {\n (bool success, bytes memory result) = tryModExp(b, e, m);\n if (!success) {\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n return result;\n }\n\n /**\n * @dev Variant of {tryModExp} that supports inputs of arbitrary length.\n */\n function tryModExp(\n bytes memory b,\n bytes memory e,\n bytes memory m\n ) internal view returns (bool success, bytes memory result) {\n if (_zeroBytes(m)) return (false, new bytes(0));\n\n uint256 mLen = m.length;\n\n // Encode call args in result and move the free memory pointer\n result = abi.encodePacked(b.length, e.length, mLen, b, e, m);\n\n assembly (\"memory-safe\") {\n let dataPtr := add(result, 0x20)\n // Write result on top of args to avoid allocating extra memory.\n success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)\n // Overwrite the length.\n // result.length > returndatasize() is guaranteed because returndatasize() == m.length\n mstore(result, mLen)\n // Set the memory pointer after the returned data.\n mstore(0x40, add(dataPtr, mLen))\n }\n }\n\n /**\n * @dev Returns whether the provided byte array is zero.\n */\n function _zeroBytes(bytes memory byteArray) private pure returns (bool) {\n for (uint256 i = 0; i < byteArray.length; ++i) {\n if (byteArray[i] != 0) {\n return false;\n }\n }\n return true;\n }\n\n /**\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded\n * towards zero.\n *\n * This method is based on Newton's method for computing square roots; the algorithm is restricted to only\n * using integer operations.\n */\n function sqrt(uint256 a) internal pure returns (uint256) {\n unchecked {\n // Take care of easy edge cases when a == 0 or a == 1\n if (a <= 1) {\n return a;\n }\n\n // In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a\n // sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between\n // the current value as `ε_n = | x_n - sqrt(a) |`.\n //\n // For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root\n // of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is\n // bigger than any uint256.\n //\n // By noticing that\n // `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`\n // we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar\n // to the msb function.\n uint256 aa = a;\n uint256 xn = 1;\n\n if (aa >= (1 << 128)) {\n aa >>= 128;\n xn <<= 64;\n }\n if (aa >= (1 << 64)) {\n aa >>= 64;\n xn <<= 32;\n }\n if (aa >= (1 << 32)) {\n aa >>= 32;\n xn <<= 16;\n }\n if (aa >= (1 << 16)) {\n aa >>= 16;\n xn <<= 8;\n }\n if (aa >= (1 << 8)) {\n aa >>= 8;\n xn <<= 4;\n }\n if (aa >= (1 << 4)) {\n aa >>= 4;\n xn <<= 2;\n }\n if (aa >= (1 << 2)) {\n xn <<= 1;\n }\n\n // We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).\n //\n // We can refine our estimation by noticing that the middle of that interval minimizes the error.\n // If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).\n // This is going to be our x_0 (and ε_0)\n xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)\n\n // From here, Newton's method give us:\n // x_{n+1} = (x_n + a / x_n) / 2\n //\n // One should note that:\n // x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a\n // = ((x_n² + a) / (2 * x_n))² - a\n // = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a\n // = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)\n // = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)\n // = (x_n² - a)² / (2 * x_n)²\n // = ((x_n² - a) / (2 * x_n))²\n // ≥ 0\n // Which proves that for all n ≥ 1, sqrt(a) ≤ x_n\n //\n // This gives us the proof of quadratic convergence of the sequence:\n // ε_{n+1} = | x_{n+1} - sqrt(a) |\n // = | (x_n + a / x_n) / 2 - sqrt(a) |\n // = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |\n // = | (x_n - sqrt(a))² / (2 * x_n) |\n // = | ε_n² / (2 * x_n) |\n // = ε_n² / | (2 * x_n) |\n //\n // For the first iteration, we have a special case where x_0 is known:\n // ε_1 = ε_0² / | (2 * x_0) |\n // ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))\n // ≤ 2**(2*e-4) / (3 * 2**(e-1))\n // ≤ 2**(e-3) / 3\n // ≤ 2**(e-3-log2(3))\n // ≤ 2**(e-4.5)\n //\n // For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:\n // ε_{n+1} = ε_n² / | (2 * x_n) |\n // ≤ (2**(e-k))² / (2 * 2**(e-1))\n // ≤ 2**(2*e-2*k) / 2**e\n // ≤ 2**(e-2*k)\n xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above\n xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5\n xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9\n xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18\n xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36\n xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72\n\n // Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision\n // ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either\n // sqrt(a) or sqrt(a) + 1.\n return xn - SafeCast.toUint(xn > a / xn);\n }\n }\n\n /**\n * @dev Calculates sqrt(a), following the selected rounding direction.\n */\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = sqrt(a);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);\n }\n }\n\n /**\n * @dev Return the log in base 2 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n */\n function log2(uint256 x) internal pure returns (uint256 r) {\n // If value has upper 128 bits set, log2 result is at least 128\n r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;\n // If upper 64 bits of 128-bit half set, add 64 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;\n // If upper 32 bits of 64-bit half set, add 32 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;\n // If upper 16 bits of 32-bit half set, add 16 to result\n r |= SafeCast.toUint((x >> r) > 0xffff) << 4;\n // If upper 8 bits of 16-bit half set, add 8 to result\n r |= SafeCast.toUint((x >> r) > 0xff) << 3;\n // If upper 4 bits of 8-bit half set, add 4 to result\n r |= SafeCast.toUint((x >> r) > 0xf) << 2;\n\n // Shifts value right by the current result and use it as an index into this lookup table:\n //\n // | x (4 bits) | index | table[index] = MSB position |\n // |------------|---------|-----------------------------|\n // | 0000 | 0 | table[0] = 0 |\n // | 0001 | 1 | table[1] = 0 |\n // | 0010 | 2 | table[2] = 1 |\n // | 0011 | 3 | table[3] = 1 |\n // | 0100 | 4 | table[4] = 2 |\n // | 0101 | 5 | table[5] = 2 |\n // | 0110 | 6 | table[6] = 2 |\n // | 0111 | 7 | table[7] = 2 |\n // | 1000 | 8 | table[8] = 3 |\n // | 1001 | 9 | table[9] = 3 |\n // | 1010 | 10 | table[10] = 3 |\n // | 1011 | 11 | table[11] = 3 |\n // | 1100 | 12 | table[12] = 3 |\n // | 1101 | 13 | table[13] = 3 |\n // | 1110 | 14 | table[14] = 3 |\n // | 1111 | 15 | table[15] = 3 |\n //\n // The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes.\n assembly (\"memory-safe\") {\n r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000))\n }\n }\n\n /**\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log2(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);\n }\n }\n\n /**\n * @dev Return the log in base 10 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n */\n function log10(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >= 10 ** 64) {\n value /= 10 ** 64;\n result += 64;\n }\n if (value >= 10 ** 32) {\n value /= 10 ** 32;\n result += 32;\n }\n if (value >= 10 ** 16) {\n value /= 10 ** 16;\n result += 16;\n }\n if (value >= 10 ** 8) {\n value /= 10 ** 8;\n result += 8;\n }\n if (value >= 10 ** 4) {\n value /= 10 ** 4;\n result += 4;\n }\n if (value >= 10 ** 2) {\n value /= 10 ** 2;\n result += 2;\n }\n if (value >= 10 ** 1) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log10(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);\n }\n }\n\n /**\n * @dev Return the log in base 256 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n *\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n */\n function log256(uint256 x) internal pure returns (uint256 r) {\n // If value has upper 128 bits set, log2 result is at least 128\n r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;\n // If upper 64 bits of 128-bit half set, add 64 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;\n // If upper 32 bits of 64-bit half set, add 32 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;\n // If upper 16 bits of 32-bit half set, add 16 to result\n r |= SafeCast.toUint((x >> r) > 0xffff) << 4;\n // Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8\n return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);\n }\n\n /**\n * @dev Return the log in base 256, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log256(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);\n }\n }\n\n /**\n * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.\n */\n function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {\n return uint8(rounding) % 2 == 1;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/SafeCast.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeCast {\n /**\n * @dev Value doesn't fit in an uint of `bits` size.\n */\n error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);\n\n /**\n * @dev An int value doesn't fit in an uint of `bits` size.\n */\n error SafeCastOverflowedIntToUint(int256 value);\n\n /**\n * @dev Value doesn't fit in an int of `bits` size.\n */\n error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);\n\n /**\n * @dev An uint value doesn't fit in an int of `bits` size.\n */\n error SafeCastOverflowedUintToInt(uint256 value);\n\n /**\n * @dev Returns the downcasted uint248 from uint256, reverting on\n * overflow (when the input is greater than largest uint248).\n *\n * Counterpart to Solidity's `uint248` operator.\n *\n * Requirements:\n *\n * - input must fit into 248 bits\n */\n function toUint248(uint256 value) internal pure returns (uint248) {\n if (value > type(uint248).max) {\n revert SafeCastOverflowedUintDowncast(248, value);\n }\n return uint248(value);\n }\n\n /**\n * @dev Returns the downcasted uint240 from uint256, reverting on\n * overflow (when the input is greater than largest uint240).\n *\n * Counterpart to Solidity's `uint240` operator.\n *\n * Requirements:\n *\n * - input must fit into 240 bits\n */\n function toUint240(uint256 value) internal pure returns (uint240) {\n if (value > type(uint240).max) {\n revert SafeCastOverflowedUintDowncast(240, value);\n }\n return uint240(value);\n }\n\n /**\n * @dev Returns the downcasted uint232 from uint256, reverting on\n * overflow (when the input is greater than largest uint232).\n *\n * Counterpart to Solidity's `uint232` operator.\n *\n * Requirements:\n *\n * - input must fit into 232 bits\n */\n function toUint232(uint256 value) internal pure returns (uint232) {\n if (value > type(uint232).max) {\n revert SafeCastOverflowedUintDowncast(232, value);\n }\n return uint232(value);\n }\n\n /**\n * @dev Returns the downcasted uint224 from uint256, reverting on\n * overflow (when the input is greater than largest uint224).\n *\n * Counterpart to Solidity's `uint224` operator.\n *\n * Requirements:\n *\n * - input must fit into 224 bits\n */\n function toUint224(uint256 value) internal pure returns (uint224) {\n if (value > type(uint224).max) {\n revert SafeCastOverflowedUintDowncast(224, value);\n }\n return uint224(value);\n }\n\n /**\n * @dev Returns the downcasted uint216 from uint256, reverting on\n * overflow (when the input is greater than largest uint216).\n *\n * Counterpart to Solidity's `uint216` operator.\n *\n * Requirements:\n *\n * - input must fit into 216 bits\n */\n function toUint216(uint256 value) internal pure returns (uint216) {\n if (value > type(uint216).max) {\n revert SafeCastOverflowedUintDowncast(216, value);\n }\n return uint216(value);\n }\n\n /**\n * @dev Returns the downcasted uint208 from uint256, reverting on\n * overflow (when the input is greater than largest uint208).\n *\n * Counterpart to Solidity's `uint208` operator.\n *\n * Requirements:\n *\n * - input must fit into 208 bits\n */\n function toUint208(uint256 value) internal pure returns (uint208) {\n if (value > type(uint208).max) {\n revert SafeCastOverflowedUintDowncast(208, value);\n }\n return uint208(value);\n }\n\n /**\n * @dev Returns the downcasted uint200 from uint256, reverting on\n * overflow (when the input is greater than largest uint200).\n *\n * Counterpart to Solidity's `uint200` operator.\n *\n * Requirements:\n *\n * - input must fit into 200 bits\n */\n function toUint200(uint256 value) internal pure returns (uint200) {\n if (value > type(uint200).max) {\n revert SafeCastOverflowedUintDowncast(200, value);\n }\n return uint200(value);\n }\n\n /**\n * @dev Returns the downcasted uint192 from uint256, reverting on\n * overflow (when the input is greater than largest uint192).\n *\n * Counterpart to Solidity's `uint192` operator.\n *\n * Requirements:\n *\n * - input must fit into 192 bits\n */\n function toUint192(uint256 value) internal pure returns (uint192) {\n if (value > type(uint192).max) {\n revert SafeCastOverflowedUintDowncast(192, value);\n }\n return uint192(value);\n }\n\n /**\n * @dev Returns the downcasted uint184 from uint256, reverting on\n * overflow (when the input is greater than largest uint184).\n *\n * Counterpart to Solidity's `uint184` operator.\n *\n * Requirements:\n *\n * - input must fit into 184 bits\n */\n function toUint184(uint256 value) internal pure returns (uint184) {\n if (value > type(uint184).max) {\n revert SafeCastOverflowedUintDowncast(184, value);\n }\n return uint184(value);\n }\n\n /**\n * @dev Returns the downcasted uint176 from uint256, reverting on\n * overflow (when the input is greater than largest uint176).\n *\n * Counterpart to Solidity's `uint176` operator.\n *\n * Requirements:\n *\n * - input must fit into 176 bits\n */\n function toUint176(uint256 value) internal pure returns (uint176) {\n if (value > type(uint176).max) {\n revert SafeCastOverflowedUintDowncast(176, value);\n }\n return uint176(value);\n }\n\n /**\n * @dev Returns the downcasted uint168 from uint256, reverting on\n * overflow (when the input is greater than largest uint168).\n *\n * Counterpart to Solidity's `uint168` operator.\n *\n * Requirements:\n *\n * - input must fit into 168 bits\n */\n function toUint168(uint256 value) internal pure returns (uint168) {\n if (value > type(uint168).max) {\n revert SafeCastOverflowedUintDowncast(168, value);\n }\n return uint168(value);\n }\n\n /**\n * @dev Returns the downcasted uint160 from uint256, reverting on\n * overflow (when the input is greater than largest uint160).\n *\n * Counterpart to Solidity's `uint160` operator.\n *\n * Requirements:\n *\n * - input must fit into 160 bits\n */\n function toUint160(uint256 value) internal pure returns (uint160) {\n if (value > type(uint160).max) {\n revert SafeCastOverflowedUintDowncast(160, value);\n }\n return uint160(value);\n }\n\n /**\n * @dev Returns the downcasted uint152 from uint256, reverting on\n * overflow (when the input is greater than largest uint152).\n *\n * Counterpart to Solidity's `uint152` operator.\n *\n * Requirements:\n *\n * - input must fit into 152 bits\n */\n function toUint152(uint256 value) internal pure returns (uint152) {\n if (value > type(uint152).max) {\n revert SafeCastOverflowedUintDowncast(152, value);\n }\n return uint152(value);\n }\n\n /**\n * @dev Returns the downcasted uint144 from uint256, reverting on\n * overflow (when the input is greater than largest uint144).\n *\n * Counterpart to Solidity's `uint144` operator.\n *\n * Requirements:\n *\n * - input must fit into 144 bits\n */\n function toUint144(uint256 value) internal pure returns (uint144) {\n if (value > type(uint144).max) {\n revert SafeCastOverflowedUintDowncast(144, value);\n }\n return uint144(value);\n }\n\n /**\n * @dev Returns the downcasted uint136 from uint256, reverting on\n * overflow (when the input is greater than largest uint136).\n *\n * Counterpart to Solidity's `uint136` operator.\n *\n * Requirements:\n *\n * - input must fit into 136 bits\n */\n function toUint136(uint256 value) internal pure returns (uint136) {\n if (value > type(uint136).max) {\n revert SafeCastOverflowedUintDowncast(136, value);\n }\n return uint136(value);\n }\n\n /**\n * @dev Returns the downcasted uint128 from uint256, reverting on\n * overflow (when the input is greater than largest uint128).\n *\n * Counterpart to Solidity's `uint128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n */\n function toUint128(uint256 value) internal pure returns (uint128) {\n if (value > type(uint128).max) {\n revert SafeCastOverflowedUintDowncast(128, value);\n }\n return uint128(value);\n }\n\n /**\n * @dev Returns the downcasted uint120 from uint256, reverting on\n * overflow (when the input is greater than largest uint120).\n *\n * Counterpart to Solidity's `uint120` operator.\n *\n * Requirements:\n *\n * - input must fit into 120 bits\n */\n function toUint120(uint256 value) internal pure returns (uint120) {\n if (value > type(uint120).max) {\n revert SafeCastOverflowedUintDowncast(120, value);\n }\n return uint120(value);\n }\n\n /**\n * @dev Returns the downcasted uint112 from uint256, reverting on\n * overflow (when the input is greater than largest uint112).\n *\n * Counterpart to Solidity's `uint112` operator.\n *\n * Requirements:\n *\n * - input must fit into 112 bits\n */\n function toUint112(uint256 value) internal pure returns (uint112) {\n if (value > type(uint112).max) {\n revert SafeCastOverflowedUintDowncast(112, value);\n }\n return uint112(value);\n }\n\n /**\n * @dev Returns the downcasted uint104 from uint256, reverting on\n * overflow (when the input is greater than largest uint104).\n *\n * Counterpart to Solidity's `uint104` operator.\n *\n * Requirements:\n *\n * - input must fit into 104 bits\n */\n function toUint104(uint256 value) internal pure returns (uint104) {\n if (value > type(uint104).max) {\n revert SafeCastOverflowedUintDowncast(104, value);\n }\n return uint104(value);\n }\n\n /**\n * @dev Returns the downcasted uint96 from uint256, reverting on\n * overflow (when the input is greater than largest uint96).\n *\n * Counterpart to Solidity's `uint96` operator.\n *\n * Requirements:\n *\n * - input must fit into 96 bits\n */\n function toUint96(uint256 value) internal pure returns (uint96) {\n if (value > type(uint96).max) {\n revert SafeCastOverflowedUintDowncast(96, value);\n }\n return uint96(value);\n }\n\n /**\n * @dev Returns the downcasted uint88 from uint256, reverting on\n * overflow (when the input is greater than largest uint88).\n *\n * Counterpart to Solidity's `uint88` operator.\n *\n * Requirements:\n *\n * - input must fit into 88 bits\n */\n function toUint88(uint256 value) internal pure returns (uint88) {\n if (value > type(uint88).max) {\n revert SafeCastOverflowedUintDowncast(88, value);\n }\n return uint88(value);\n }\n\n /**\n * @dev Returns the downcasted uint80 from uint256, reverting on\n * overflow (when the input is greater than largest uint80).\n *\n * Counterpart to Solidity's `uint80` operator.\n *\n * Requirements:\n *\n * - input must fit into 80 bits\n */\n function toUint80(uint256 value) internal pure returns (uint80) {\n if (value > type(uint80).max) {\n revert SafeCastOverflowedUintDowncast(80, value);\n }\n return uint80(value);\n }\n\n /**\n * @dev Returns the downcasted uint72 from uint256, reverting on\n * overflow (when the input is greater than largest uint72).\n *\n * Counterpart to Solidity's `uint72` operator.\n *\n * Requirements:\n *\n * - input must fit into 72 bits\n */\n function toUint72(uint256 value) internal pure returns (uint72) {\n if (value > type(uint72).max) {\n revert SafeCastOverflowedUintDowncast(72, value);\n }\n return uint72(value);\n }\n\n /**\n * @dev Returns the downcasted uint64 from uint256, reverting on\n * overflow (when the input is greater than largest uint64).\n *\n * Counterpart to Solidity's `uint64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n */\n function toUint64(uint256 value) internal pure returns (uint64) {\n if (value > type(uint64).max) {\n revert SafeCastOverflowedUintDowncast(64, value);\n }\n return uint64(value);\n }\n\n /**\n * @dev Returns the downcasted uint56 from uint256, reverting on\n * overflow (when the input is greater than largest uint56).\n *\n * Counterpart to Solidity's `uint56` operator.\n *\n * Requirements:\n *\n * - input must fit into 56 bits\n */\n function toUint56(uint256 value) internal pure returns (uint56) {\n if (value > type(uint56).max) {\n revert SafeCastOverflowedUintDowncast(56, value);\n }\n return uint56(value);\n }\n\n /**\n * @dev Returns the downcasted uint48 from uint256, reverting on\n * overflow (when the input is greater than largest uint48).\n *\n * Counterpart to Solidity's `uint48` operator.\n *\n * Requirements:\n *\n * - input must fit into 48 bits\n */\n function toUint48(uint256 value) internal pure returns (uint48) {\n if (value > type(uint48).max) {\n revert SafeCastOverflowedUintDowncast(48, value);\n }\n return uint48(value);\n }\n\n /**\n * @dev Returns the downcasted uint40 from uint256, reverting on\n * overflow (when the input is greater than largest uint40).\n *\n * Counterpart to Solidity's `uint40` operator.\n *\n * Requirements:\n *\n * - input must fit into 40 bits\n */\n function toUint40(uint256 value) internal pure returns (uint40) {\n if (value > type(uint40).max) {\n revert SafeCastOverflowedUintDowncast(40, value);\n }\n return uint40(value);\n }\n\n /**\n * @dev Returns the downcasted uint32 from uint256, reverting on\n * overflow (when the input is greater than largest uint32).\n *\n * Counterpart to Solidity's `uint32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n */\n function toUint32(uint256 value) internal pure returns (uint32) {\n if (value > type(uint32).max) {\n revert SafeCastOverflowedUintDowncast(32, value);\n }\n return uint32(value);\n }\n\n /**\n * @dev Returns the downcasted uint24 from uint256, reverting on\n * overflow (when the input is greater than largest uint24).\n *\n * Counterpart to Solidity's `uint24` operator.\n *\n * Requirements:\n *\n * - input must fit into 24 bits\n */\n function toUint24(uint256 value) internal pure returns (uint24) {\n if (value > type(uint24).max) {\n revert SafeCastOverflowedUintDowncast(24, value);\n }\n return uint24(value);\n }\n\n /**\n * @dev Returns the downcasted uint16 from uint256, reverting on\n * overflow (when the input is greater than largest uint16).\n *\n * Counterpart to Solidity's `uint16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n */\n function toUint16(uint256 value) internal pure returns (uint16) {\n if (value > type(uint16).max) {\n revert SafeCastOverflowedUintDowncast(16, value);\n }\n return uint16(value);\n }\n\n /**\n * @dev Returns the downcasted uint8 from uint256, reverting on\n * overflow (when the input is greater than largest uint8).\n *\n * Counterpart to Solidity's `uint8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits\n */\n function toUint8(uint256 value) internal pure returns (uint8) {\n if (value > type(uint8).max) {\n revert SafeCastOverflowedUintDowncast(8, value);\n }\n return uint8(value);\n }\n\n /**\n * @dev Converts a signed int256 into an unsigned uint256.\n *\n * Requirements:\n *\n * - input must be greater than or equal to 0.\n */\n function toUint256(int256 value) internal pure returns (uint256) {\n if (value < 0) {\n revert SafeCastOverflowedIntToUint(value);\n }\n return uint256(value);\n }\n\n /**\n * @dev Returns the downcasted int248 from int256, reverting on\n * overflow (when the input is less than smallest int248 or\n * greater than largest int248).\n *\n * Counterpart to Solidity's `int248` operator.\n *\n * Requirements:\n *\n * - input must fit into 248 bits\n */\n function toInt248(int256 value) internal pure returns (int248 downcasted) {\n downcasted = int248(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(248, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int240 from int256, reverting on\n * overflow (when the input is less than smallest int240 or\n * greater than largest int240).\n *\n * Counterpart to Solidity's `int240` operator.\n *\n * Requirements:\n *\n * - input must fit into 240 bits\n */\n function toInt240(int256 value) internal pure returns (int240 downcasted) {\n downcasted = int240(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(240, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int232 from int256, reverting on\n * overflow (when the input is less than smallest int232 or\n * greater than largest int232).\n *\n * Counterpart to Solidity's `int232` operator.\n *\n * Requirements:\n *\n * - input must fit into 232 bits\n */\n function toInt232(int256 value) internal pure returns (int232 downcasted) {\n downcasted = int232(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(232, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int224 from int256, reverting on\n * overflow (when the input is less than smallest int224 or\n * greater than largest int224).\n *\n * Counterpart to Solidity's `int224` operator.\n *\n * Requirements:\n *\n * - input must fit into 224 bits\n */\n function toInt224(int256 value) internal pure returns (int224 downcasted) {\n downcasted = int224(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(224, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int216 from int256, reverting on\n * overflow (when the input is less than smallest int216 or\n * greater than largest int216).\n *\n * Counterpart to Solidity's `int216` operator.\n *\n * Requirements:\n *\n * - input must fit into 216 bits\n */\n function toInt216(int256 value) internal pure returns (int216 downcasted) {\n downcasted = int216(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(216, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int208 from int256, reverting on\n * overflow (when the input is less than smallest int208 or\n * greater than largest int208).\n *\n * Counterpart to Solidity's `int208` operator.\n *\n * Requirements:\n *\n * - input must fit into 208 bits\n */\n function toInt208(int256 value) internal pure returns (int208 downcasted) {\n downcasted = int208(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(208, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int200 from int256, reverting on\n * overflow (when the input is less than smallest int200 or\n * greater than largest int200).\n *\n * Counterpart to Solidity's `int200` operator.\n *\n * Requirements:\n *\n * - input must fit into 200 bits\n */\n function toInt200(int256 value) internal pure returns (int200 downcasted) {\n downcasted = int200(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(200, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int192 from int256, reverting on\n * overflow (when the input is less than smallest int192 or\n * greater than largest int192).\n *\n * Counterpart to Solidity's `int192` operator.\n *\n * Requirements:\n *\n * - input must fit into 192 bits\n */\n function toInt192(int256 value) internal pure returns (int192 downcasted) {\n downcasted = int192(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(192, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int184 from int256, reverting on\n * overflow (when the input is less than smallest int184 or\n * greater than largest int184).\n *\n * Counterpart to Solidity's `int184` operator.\n *\n * Requirements:\n *\n * - input must fit into 184 bits\n */\n function toInt184(int256 value) internal pure returns (int184 downcasted) {\n downcasted = int184(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(184, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int176 from int256, reverting on\n * overflow (when the input is less than smallest int176 or\n * greater than largest int176).\n *\n * Counterpart to Solidity's `int176` operator.\n *\n * Requirements:\n *\n * - input must fit into 176 bits\n */\n function toInt176(int256 value) internal pure returns (int176 downcasted) {\n downcasted = int176(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(176, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int168 from int256, reverting on\n * overflow (when the input is less than smallest int168 or\n * greater than largest int168).\n *\n * Counterpart to Solidity's `int168` operator.\n *\n * Requirements:\n *\n * - input must fit into 168 bits\n */\n function toInt168(int256 value) internal pure returns (int168 downcasted) {\n downcasted = int168(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(168, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int160 from int256, reverting on\n * overflow (when the input is less than smallest int160 or\n * greater than largest int160).\n *\n * Counterpart to Solidity's `int160` operator.\n *\n * Requirements:\n *\n * - input must fit into 160 bits\n */\n function toInt160(int256 value) internal pure returns (int160 downcasted) {\n downcasted = int160(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(160, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int152 from int256, reverting on\n * overflow (when the input is less than smallest int152 or\n * greater than largest int152).\n *\n * Counterpart to Solidity's `int152` operator.\n *\n * Requirements:\n *\n * - input must fit into 152 bits\n */\n function toInt152(int256 value) internal pure returns (int152 downcasted) {\n downcasted = int152(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(152, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int144 from int256, reverting on\n * overflow (when the input is less than smallest int144 or\n * greater than largest int144).\n *\n * Counterpart to Solidity's `int144` operator.\n *\n * Requirements:\n *\n * - input must fit into 144 bits\n */\n function toInt144(int256 value) internal pure returns (int144 downcasted) {\n downcasted = int144(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(144, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int136 from int256, reverting on\n * overflow (when the input is less than smallest int136 or\n * greater than largest int136).\n *\n * Counterpart to Solidity's `int136` operator.\n *\n * Requirements:\n *\n * - input must fit into 136 bits\n */\n function toInt136(int256 value) internal pure returns (int136 downcasted) {\n downcasted = int136(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(136, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int128 from int256, reverting on\n * overflow (when the input is less than smallest int128 or\n * greater than largest int128).\n *\n * Counterpart to Solidity's `int128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n */\n function toInt128(int256 value) internal pure returns (int128 downcasted) {\n downcasted = int128(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(128, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int120 from int256, reverting on\n * overflow (when the input is less than smallest int120 or\n * greater than largest int120).\n *\n * Counterpart to Solidity's `int120` operator.\n *\n * Requirements:\n *\n * - input must fit into 120 bits\n */\n function toInt120(int256 value) internal pure returns (int120 downcasted) {\n downcasted = int120(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(120, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int112 from int256, reverting on\n * overflow (when the input is less than smallest int112 or\n * greater than largest int112).\n *\n * Counterpart to Solidity's `int112` operator.\n *\n * Requirements:\n *\n * - input must fit into 112 bits\n */\n function toInt112(int256 value) internal pure returns (int112 downcasted) {\n downcasted = int112(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(112, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int104 from int256, reverting on\n * overflow (when the input is less than smallest int104 or\n * greater than largest int104).\n *\n * Counterpart to Solidity's `int104` operator.\n *\n * Requirements:\n *\n * - input must fit into 104 bits\n */\n function toInt104(int256 value) internal pure returns (int104 downcasted) {\n downcasted = int104(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(104, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int96 from int256, reverting on\n * overflow (when the input is less than smallest int96 or\n * greater than largest int96).\n *\n * Counterpart to Solidity's `int96` operator.\n *\n * Requirements:\n *\n * - input must fit into 96 bits\n */\n function toInt96(int256 value) internal pure returns (int96 downcasted) {\n downcasted = int96(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(96, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int88 from int256, reverting on\n * overflow (when the input is less than smallest int88 or\n * greater than largest int88).\n *\n * Counterpart to Solidity's `int88` operator.\n *\n * Requirements:\n *\n * - input must fit into 88 bits\n */\n function toInt88(int256 value) internal pure returns (int88 downcasted) {\n downcasted = int88(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(88, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int80 from int256, reverting on\n * overflow (when the input is less than smallest int80 or\n * greater than largest int80).\n *\n * Counterpart to Solidity's `int80` operator.\n *\n * Requirements:\n *\n * - input must fit into 80 bits\n */\n function toInt80(int256 value) internal pure returns (int80 downcasted) {\n downcasted = int80(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(80, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int72 from int256, reverting on\n * overflow (when the input is less than smallest int72 or\n * greater than largest int72).\n *\n * Counterpart to Solidity's `int72` operator.\n *\n * Requirements:\n *\n * - input must fit into 72 bits\n */\n function toInt72(int256 value) internal pure returns (int72 downcasted) {\n downcasted = int72(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(72, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int64 from int256, reverting on\n * overflow (when the input is less than smallest int64 or\n * greater than largest int64).\n *\n * Counterpart to Solidity's `int64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n */\n function toInt64(int256 value) internal pure returns (int64 downcasted) {\n downcasted = int64(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(64, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int56 from int256, reverting on\n * overflow (when the input is less than smallest int56 or\n * greater than largest int56).\n *\n * Counterpart to Solidity's `int56` operator.\n *\n * Requirements:\n *\n * - input must fit into 56 bits\n */\n function toInt56(int256 value) internal pure returns (int56 downcasted) {\n downcasted = int56(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(56, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int48 from int256, reverting on\n * overflow (when the input is less than smallest int48 or\n * greater than largest int48).\n *\n * Counterpart to Solidity's `int48` operator.\n *\n * Requirements:\n *\n * - input must fit into 48 bits\n */\n function toInt48(int256 value) internal pure returns (int48 downcasted) {\n downcasted = int48(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(48, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int40 from int256, reverting on\n * overflow (when the input is less than smallest int40 or\n * greater than largest int40).\n *\n * Counterpart to Solidity's `int40` operator.\n *\n * Requirements:\n *\n * - input must fit into 40 bits\n */\n function toInt40(int256 value) internal pure returns (int40 downcasted) {\n downcasted = int40(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(40, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int32 from int256, reverting on\n * overflow (when the input is less than smallest int32 or\n * greater than largest int32).\n *\n * Counterpart to Solidity's `int32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n */\n function toInt32(int256 value) internal pure returns (int32 downcasted) {\n downcasted = int32(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(32, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int24 from int256, reverting on\n * overflow (when the input is less than smallest int24 or\n * greater than largest int24).\n *\n * Counterpart to Solidity's `int24` operator.\n *\n * Requirements:\n *\n * - input must fit into 24 bits\n */\n function toInt24(int256 value) internal pure returns (int24 downcasted) {\n downcasted = int24(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(24, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int16 from int256, reverting on\n * overflow (when the input is less than smallest int16 or\n * greater than largest int16).\n *\n * Counterpart to Solidity's `int16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n */\n function toInt16(int256 value) internal pure returns (int16 downcasted) {\n downcasted = int16(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(16, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int8 from int256, reverting on\n * overflow (when the input is less than smallest int8 or\n * greater than largest int8).\n *\n * Counterpart to Solidity's `int8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits\n */\n function toInt8(int256 value) internal pure returns (int8 downcasted) {\n downcasted = int8(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(8, value);\n }\n }\n\n /**\n * @dev Converts an unsigned uint256 into a signed int256.\n *\n * Requirements:\n *\n * - input must be less than or equal to maxInt256.\n */\n function toInt256(uint256 value) internal pure returns (int256) {\n // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n if (value > uint256(type(int256).max)) {\n revert SafeCastOverflowedUintToInt(value);\n }\n return int256(value);\n }\n\n /**\n * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.\n */\n function toUint(bool b) internal pure returns (uint256 u) {\n assembly (\"memory-safe\") {\n u := iszero(iszero(b))\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/SignedMath.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol)\n\npragma solidity ^0.8.20;\n\nimport {SafeCast} from \"./SafeCast.sol\";\n\n/**\n * @dev Standard signed math utilities missing in the Solidity language.\n */\nlibrary SignedMath {\n /**\n * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.\n *\n * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.\n * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute\n * one branch when needed, making this function more expensive.\n */\n function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {\n unchecked {\n // branchless ternary works because:\n // b ^ (a ^ b) == a\n // b ^ 0 == b\n return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));\n }\n }\n\n /**\n * @dev Returns the largest of two signed numbers.\n */\n function max(int256 a, int256 b) internal pure returns (int256) {\n return ternary(a > b, a, b);\n }\n\n /**\n * @dev Returns the smallest of two signed numbers.\n */\n function min(int256 a, int256 b) internal pure returns (int256) {\n return ternary(a < b, a, b);\n }\n\n /**\n * @dev Returns the average of two signed numbers without overflow.\n * The result is rounded towards zero.\n */\n function average(int256 a, int256 b) internal pure returns (int256) {\n // Formula from the book \"Hacker's Delight\"\n int256 x = (a & b) + ((a ^ b) >> 1);\n return x + (int256(uint256(x) >> 255) & (a ^ b));\n }\n\n /**\n * @dev Returns the absolute unsigned value of a signed value.\n */\n function abs(int256 n) internal pure returns (uint256) {\n unchecked {\n // Formula from the \"Bit Twiddling Hacks\" by Sean Eron Anderson.\n // Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,\n // taking advantage of the most significant (or \"sign\" bit) in two's complement representation.\n // This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,\n // the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative).\n int256 mask = n >> 255;\n\n // A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.\n return uint256((n + mask) ^ mask);\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Panic.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Helper library for emitting standardized panic codes.\n *\n * ```solidity\n * contract Example {\n * using Panic for uint256;\n *\n * // Use any of the declared internal constants\n * function foo() { Panic.GENERIC.panic(); }\n *\n * // Alternatively\n * function foo() { Panic.panic(Panic.GENERIC); }\n * }\n * ```\n *\n * Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].\n *\n * _Available since v5.1._\n */\n// slither-disable-next-line unused-state\nlibrary Panic {\n /// @dev generic / unspecified error\n uint256 internal constant GENERIC = 0x00;\n /// @dev used by the assert() builtin\n uint256 internal constant ASSERT = 0x01;\n /// @dev arithmetic underflow or overflow\n uint256 internal constant UNDER_OVERFLOW = 0x11;\n /// @dev division or modulo by zero\n uint256 internal constant DIVISION_BY_ZERO = 0x12;\n /// @dev enum conversion error\n uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;\n /// @dev invalid encoding in storage\n uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;\n /// @dev empty array pop\n uint256 internal constant EMPTY_ARRAY_POP = 0x31;\n /// @dev array out of bounds access\n uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;\n /// @dev resource error (too large allocation or too large array)\n uint256 internal constant RESOURCE_ERROR = 0x41;\n /// @dev calling invalid internal function\n uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;\n\n /// @dev Reverts with a panic code. Recommended to use with\n /// the internal constants with predefined codes.\n function panic(uint256 code) internal pure {\n assembly (\"memory-safe\") {\n mstore(0x00, 0x4e487b71)\n mstore(0x20, code)\n revert(0x1c, 0x24)\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/ReentrancyGuard.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,\n * consider using {ReentrancyGuardTransient} instead.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant NOT_ENTERED = 1;\n uint256 private constant ENTERED = 2;\n\n uint256 private _status;\n\n /**\n * @dev Unauthorized reentrant call.\n */\n error ReentrancyGuardReentrantCall();\n\n constructor() {\n _status = NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and making it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n _nonReentrantBefore();\n _;\n _nonReentrantAfter();\n }\n\n function _nonReentrantBefore() private {\n // On the first call to nonReentrant, _status will be NOT_ENTERED\n if (_status == ENTERED) {\n revert ReentrancyGuardReentrantCall();\n }\n\n // Any calls to nonReentrant after this point will fail\n _status = ENTERED;\n }\n\n function _nonReentrantAfter() private {\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = NOT_ENTERED;\n }\n\n /**\n * @dev Returns true if the reentrancy guard is currently set to \"entered\", which indicates there is a\n * `nonReentrant` function in the call stack.\n */\n function _reentrancyGuardEntered() internal view returns (bool) {\n return _status == ENTERED;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/ShortStrings.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/ShortStrings.sol)\n\npragma solidity ^0.8.20;\n\nimport {StorageSlot} from \"./StorageSlot.sol\";\n\n// | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |\n// | length | 0x BB |\ntype ShortString is bytes32;\n\n/**\n * @dev This library provides functions to convert short memory strings\n * into a `ShortString` type that can be used as an immutable variable.\n *\n * Strings of arbitrary length can be optimized using this library if\n * they are short enough (up to 31 bytes) by packing them with their\n * length (1 byte) in a single EVM word (32 bytes). Additionally, a\n * fallback mechanism can be used for every other case.\n *\n * Usage example:\n *\n * ```solidity\n * contract Named {\n * using ShortStrings for *;\n *\n * ShortString private immutable _name;\n * string private _nameFallback;\n *\n * constructor(string memory contractName) {\n * _name = contractName.toShortStringWithFallback(_nameFallback);\n * }\n *\n * function name() external view returns (string memory) {\n * return _name.toStringWithFallback(_nameFallback);\n * }\n * }\n * ```\n */\nlibrary ShortStrings {\n // Used as an identifier for strings longer than 31 bytes.\n bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;\n\n error StringTooLong(string str);\n error InvalidShortString();\n\n /**\n * @dev Encode a string of at most 31 chars into a `ShortString`.\n *\n * This will trigger a `StringTooLong` error is the input string is too long.\n */\n function toShortString(string memory str) internal pure returns (ShortString) {\n bytes memory bstr = bytes(str);\n if (bstr.length > 31) {\n revert StringTooLong(str);\n }\n return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));\n }\n\n /**\n * @dev Decode a `ShortString` back to a \"normal\" string.\n */\n function toString(ShortString sstr) internal pure returns (string memory) {\n uint256 len = byteLength(sstr);\n // using `new string(len)` would work locally but is not memory safe.\n string memory str = new string(32);\n assembly (\"memory-safe\") {\n mstore(str, len)\n mstore(add(str, 0x20), sstr)\n }\n return str;\n }\n\n /**\n * @dev Return the length of a `ShortString`.\n */\n function byteLength(ShortString sstr) internal pure returns (uint256) {\n uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;\n if (result > 31) {\n revert InvalidShortString();\n }\n return result;\n }\n\n /**\n * @dev Encode a string into a `ShortString`, or write it to storage if it is too long.\n */\n function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {\n if (bytes(value).length < 32) {\n return toShortString(value);\n } else {\n StorageSlot.getStringSlot(store).value = value;\n return ShortString.wrap(FALLBACK_SENTINEL);\n }\n }\n\n /**\n * @dev Decode a string that was encoded to `ShortString` or written to storage using {toShortStringWithFallback}.\n */\n function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {\n if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {\n return toString(value);\n } else {\n return store;\n }\n }\n\n /**\n * @dev Return the length of a string that was encoded to `ShortString` or written to storage using\n * {toShortStringWithFallback}.\n *\n * WARNING: This will return the \"byte length\" of the string. This may not reflect the actual length in terms of\n * actual characters as the UTF-8 encoding of a single character can span over multiple bytes.\n */\n function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {\n if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {\n return byteLength(value);\n } else {\n return bytes(store).length;\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/StorageSlot.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)\n// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Library for reading and writing primitive types to specific storage slots.\n *\n * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\n * This library helps with reading and writing to such slots without the need for inline assembly.\n *\n * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\n *\n * Example usage to set ERC-1967 implementation slot:\n * ```solidity\n * contract ERC1967 {\n * // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.\n * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n *\n * function _getImplementation() internal view returns (address) {\n * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n * }\n *\n * function _setImplementation(address newImplementation) internal {\n * require(newImplementation.code.length > 0);\n * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n * }\n * }\n * ```\n *\n * TIP: Consider using this library along with {SlotDerivation}.\n */\nlibrary StorageSlot {\n struct AddressSlot {\n address value;\n }\n\n struct BooleanSlot {\n bool value;\n }\n\n struct Bytes32Slot {\n bytes32 value;\n }\n\n struct Uint256Slot {\n uint256 value;\n }\n\n struct Int256Slot {\n int256 value;\n }\n\n struct StringSlot {\n string value;\n }\n\n struct BytesSlot {\n bytes value;\n }\n\n /**\n * @dev Returns an `AddressSlot` with member `value` located at `slot`.\n */\n function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `BooleanSlot` with member `value` located at `slot`.\n */\n function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Bytes32Slot` with member `value` located at `slot`.\n */\n function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Uint256Slot` with member `value` located at `slot`.\n */\n function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Int256Slot` with member `value` located at `slot`.\n */\n function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `StringSlot` with member `value` located at `slot`.\n */\n function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `StringSlot` representation of the string storage pointer `store`.\n */\n function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := store.slot\n }\n }\n\n /**\n * @dev Returns a `BytesSlot` with member `value` located at `slot`.\n */\n function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.\n */\n function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := store.slot\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Strings.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/Strings.sol)\n\npragma solidity ^0.8.20;\n\nimport {Math} from \"./math/Math.sol\";\nimport {SafeCast} from \"./math/SafeCast.sol\";\nimport {SignedMath} from \"./math/SignedMath.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n using SafeCast for *;\n\n bytes16 private constant HEX_DIGITS = \"0123456789abcdef\";\n uint8 private constant ADDRESS_LENGTH = 20;\n uint256 private constant SPECIAL_CHARS_LOOKUP =\n (1 << 0x08) | // backspace\n (1 << 0x09) | // tab\n (1 << 0x0a) | // newline\n (1 << 0x0c) | // form feed\n (1 << 0x0d) | // carriage return\n (1 << 0x22) | // double quote\n (1 << 0x5c); // backslash\n\n /**\n * @dev The `value` string doesn't fit in the specified `length`.\n */\n error StringsInsufficientHexLength(uint256 value, uint256 length);\n\n /**\n * @dev The string being parsed contains characters that are not in scope of the given base.\n */\n error StringsInvalidChar();\n\n /**\n * @dev The string being parsed is not a properly formatted address.\n */\n error StringsInvalidAddressFormat();\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n unchecked {\n uint256 length = Math.log10(value) + 1;\n string memory buffer = new string(length);\n uint256 ptr;\n assembly (\"memory-safe\") {\n ptr := add(buffer, add(32, length))\n }\n while (true) {\n ptr--;\n assembly (\"memory-safe\") {\n mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))\n }\n value /= 10;\n if (value == 0) break;\n }\n return buffer;\n }\n }\n\n /**\n * @dev Converts a `int256` to its ASCII `string` decimal representation.\n */\n function toStringSigned(int256 value) internal pure returns (string memory) {\n return string.concat(value < 0 ? \"-\" : \"\", toString(SignedMath.abs(value)));\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n unchecked {\n return toHexString(value, Math.log256(value) + 1);\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n uint256 localValue = value;\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = HEX_DIGITS[localValue & 0xf];\n localValue >>= 4;\n }\n if (localValue != 0) {\n revert StringsInsufficientHexLength(value, length);\n }\n return string(buffer);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal\n * representation.\n */\n function toHexString(address addr) internal pure returns (string memory) {\n return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal\n * representation, according to EIP-55.\n */\n function toChecksumHexString(address addr) internal pure returns (string memory) {\n bytes memory buffer = bytes(toHexString(addr));\n\n // hash the hex part of buffer (skip length + 2 bytes, length 40)\n uint256 hashValue;\n assembly (\"memory-safe\") {\n hashValue := shr(96, keccak256(add(buffer, 0x22), 40))\n }\n\n for (uint256 i = 41; i > 1; --i) {\n // possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)\n if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {\n // case shift by xoring with 0x20\n buffer[i] ^= 0x20;\n }\n hashValue >>= 4;\n }\n return string(buffer);\n }\n\n /**\n * @dev Returns true if the two strings are equal.\n */\n function equal(string memory a, string memory b) internal pure returns (bool) {\n return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));\n }\n\n /**\n * @dev Parse a decimal string and returns the value as a `uint256`.\n *\n * Requirements:\n * - The string must be formatted as `[0-9]*`\n * - The result must fit into an `uint256` type\n */\n function parseUint(string memory input) internal pure returns (uint256) {\n return parseUint(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseUint-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `[0-9]*`\n * - The result must fit into an `uint256` type\n */\n function parseUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {\n (bool success, uint256 value) = tryParseUint(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseUint-string} that returns false if the parsing fails because of an invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseUint(string memory input) internal pure returns (bool success, uint256 value) {\n return _tryParseUintUncheckedBounds(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseUint-string-uint256-uint256} that returns false if the parsing fails because of an invalid\n * character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseUint(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, uint256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseUintUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseUint-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseUintUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, uint256 value) {\n bytes memory buffer = bytes(input);\n\n uint256 result = 0;\n for (uint256 i = begin; i < end; ++i) {\n uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));\n if (chr > 9) return (false, 0);\n result *= 10;\n result += chr;\n }\n return (true, result);\n }\n\n /**\n * @dev Parse a decimal string and returns the value as a `int256`.\n *\n * Requirements:\n * - The string must be formatted as `[-+]?[0-9]*`\n * - The result must fit in an `int256` type.\n */\n function parseInt(string memory input) internal pure returns (int256) {\n return parseInt(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseInt-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `[-+]?[0-9]*`\n * - The result must fit in an `int256` type.\n */\n function parseInt(string memory input, uint256 begin, uint256 end) internal pure returns (int256) {\n (bool success, int256 value) = tryParseInt(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseInt-string} that returns false if the parsing fails because of an invalid character or if\n * the result does not fit in a `int256`.\n *\n * NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.\n */\n function tryParseInt(string memory input) internal pure returns (bool success, int256 value) {\n return _tryParseIntUncheckedBounds(input, 0, bytes(input).length);\n }\n\n uint256 private constant ABS_MIN_INT256 = 2 ** 255;\n\n /**\n * @dev Variant of {parseInt-string-uint256-uint256} that returns false if the parsing fails because of an invalid\n * character or if the result does not fit in a `int256`.\n *\n * NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.\n */\n function tryParseInt(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, int256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseIntUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseInt-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseIntUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, int256 value) {\n bytes memory buffer = bytes(input);\n\n // Check presence of a negative sign.\n bytes1 sign = begin == end ? bytes1(0) : bytes1(_unsafeReadBytesOffset(buffer, begin)); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n bool positiveSign = sign == bytes1(\"+\");\n bool negativeSign = sign == bytes1(\"-\");\n uint256 offset = (positiveSign || negativeSign).toUint();\n\n (bool absSuccess, uint256 absValue) = tryParseUint(input, begin + offset, end);\n\n if (absSuccess && absValue < ABS_MIN_INT256) {\n return (true, negativeSign ? -int256(absValue) : int256(absValue));\n } else if (absSuccess && negativeSign && absValue == ABS_MIN_INT256) {\n return (true, type(int256).min);\n } else return (false, 0);\n }\n\n /**\n * @dev Parse a hexadecimal string (with or without \"0x\" prefix), and returns the value as a `uint256`.\n *\n * Requirements:\n * - The string must be formatted as `(0x)?[0-9a-fA-F]*`\n * - The result must fit in an `uint256` type.\n */\n function parseHexUint(string memory input) internal pure returns (uint256) {\n return parseHexUint(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseHexUint-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `(0x)?[0-9a-fA-F]*`\n * - The result must fit in an `uint256` type.\n */\n function parseHexUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {\n (bool success, uint256 value) = tryParseHexUint(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseHexUint-string} that returns false if the parsing fails because of an invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseHexUint(string memory input) internal pure returns (bool success, uint256 value) {\n return _tryParseHexUintUncheckedBounds(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseHexUint-string-uint256-uint256} that returns false if the parsing fails because of an\n * invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseHexUint(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, uint256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseHexUintUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseHexUint-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseHexUintUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, uint256 value) {\n bytes memory buffer = bytes(input);\n\n // skip 0x prefix if present\n bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(buffer, begin)) == bytes2(\"0x\"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n uint256 offset = hasPrefix.toUint() * 2;\n\n uint256 result = 0;\n for (uint256 i = begin + offset; i < end; ++i) {\n uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));\n if (chr > 15) return (false, 0);\n result *= 16;\n unchecked {\n // Multiplying by 16 is equivalent to a shift of 4 bits (with additional overflow check).\n // This guarantees that adding a value < 16 will not cause an overflow, hence the unchecked.\n result += chr;\n }\n }\n return (true, result);\n }\n\n /**\n * @dev Parse a hexadecimal string (with or without \"0x\" prefix), and returns the value as an `address`.\n *\n * Requirements:\n * - The string must be formatted as `(0x)?[0-9a-fA-F]{40}`\n */\n function parseAddress(string memory input) internal pure returns (address) {\n return parseAddress(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseAddress-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `(0x)?[0-9a-fA-F]{40}`\n */\n function parseAddress(string memory input, uint256 begin, uint256 end) internal pure returns (address) {\n (bool success, address value) = tryParseAddress(input, begin, end);\n if (!success) revert StringsInvalidAddressFormat();\n return value;\n }\n\n /**\n * @dev Variant of {parseAddress-string} that returns false if the parsing fails because the input is not a properly\n * formatted address. See {parseAddress-string} requirements.\n */\n function tryParseAddress(string memory input) internal pure returns (bool success, address value) {\n return tryParseAddress(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseAddress-string-uint256-uint256} that returns false if the parsing fails because input is not a properly\n * formatted address. See {parseAddress-string-uint256-uint256} requirements.\n */\n function tryParseAddress(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, address value) {\n if (end > bytes(input).length || begin > end) return (false, address(0));\n\n bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(bytes(input), begin)) == bytes2(\"0x\"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n uint256 expectedLength = 40 + hasPrefix.toUint() * 2;\n\n // check that input is the correct length\n if (end - begin == expectedLength) {\n // length guarantees that this does not overflow, and value is at most type(uint160).max\n (bool s, uint256 v) = _tryParseHexUintUncheckedBounds(input, begin, end);\n return (s, address(uint160(v)));\n } else {\n return (false, address(0));\n }\n }\n\n function _tryParseChr(bytes1 chr) private pure returns (uint8) {\n uint8 value = uint8(chr);\n\n // Try to parse `chr`:\n // - Case 1: [0-9]\n // - Case 2: [a-f]\n // - Case 3: [A-F]\n // - otherwise not supported\n unchecked {\n if (value > 47 && value < 58) value -= 48;\n else if (value > 96 && value < 103) value -= 87;\n else if (value > 64 && value < 71) value -= 55;\n else return type(uint8).max;\n }\n\n return value;\n }\n\n /**\n * @dev Escape special characters in JSON strings. This can be useful to prevent JSON injection in NFT metadata.\n *\n * WARNING: This function should only be used in double quoted JSON strings. Single quotes are not escaped.\n *\n * NOTE: This function escapes all unicode characters, and not just the ones in ranges defined in section 2.5 of\n * RFC-4627 (U+0000 to U+001F, U+0022 and U+005C). ECMAScript's `JSON.parse` does recover escaped unicode\n * characters that are not in this range, but other tooling may provide different results.\n */\n function escapeJSON(string memory input) internal pure returns (string memory) {\n bytes memory buffer = bytes(input);\n bytes memory output = new bytes(2 * buffer.length); // worst case scenario\n uint256 outputLength = 0;\n\n for (uint256 i; i < buffer.length; ++i) {\n bytes1 char = bytes1(_unsafeReadBytesOffset(buffer, i));\n if (((SPECIAL_CHARS_LOOKUP & (1 << uint8(char))) != 0)) {\n output[outputLength++] = \"\\\\\";\n if (char == 0x08) output[outputLength++] = \"b\";\n else if (char == 0x09) output[outputLength++] = \"t\";\n else if (char == 0x0a) output[outputLength++] = \"n\";\n else if (char == 0x0c) output[outputLength++] = \"f\";\n else if (char == 0x0d) output[outputLength++] = \"r\";\n else if (char == 0x5c) output[outputLength++] = \"\\\\\";\n else if (char == 0x22) {\n // solhint-disable-next-line quotes\n output[outputLength++] = '\"';\n }\n } else {\n output[outputLength++] = char;\n }\n }\n // write the actual length and deallocate unused memory\n assembly (\"memory-safe\") {\n mstore(output, outputLength)\n mstore(0x40, add(output, shl(5, shr(5, add(outputLength, 63)))))\n }\n\n return string(output);\n }\n\n /**\n * @dev Reads a bytes32 from a bytes array without bounds checking.\n *\n * NOTE: making this function internal would mean it could be used with memory unsafe offset, and marking the\n * assembly block as such would prevent some optimizations.\n */\n function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {\n // This is not memory safe in the general case, but all calls to this private function are within bounds.\n assembly (\"memory-safe\") {\n value := mload(add(buffer, add(0x20, offset)))\n }\n }\n}\n" + }, + "project/contracts/Controller.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\n\nimport './interfaces/IController.sol';\n\n/**\n * @title Controller\n * @dev Manages allow lists for solvers, executors, proposal signers and validators\n */\ncontract Controller is IController, Ownable {\n // List of allowed solvers\n mapping (address => bool) public override isSolverAllowed;\n\n // List of allowed executors\n mapping (address => bool) public override isExecutorAllowed;\n\n // List of allowed proposal signers\n mapping (address => bool) public override isProposalSignerAllowed;\n\n // List of allowed validators\n mapping (address => bool) public override isValidatorAllowed;\n\n // Minimum number of validations allowed\n uint8 public override minValidations;\n\n /**\n * @dev Creates a new Controller contract\n * @param owner Address that will own the contract\n * @param solvers List of allowed solvers\n * @param executors List of allowed executors\n * @param proposalSigners List of allowed proposal signers\n * @param validators List of allowed validators\n * @param _minValidations Minimum number of validations allowed\n */\n constructor(\n address owner,\n address[] memory solvers,\n address[] memory executors,\n address[] memory proposalSigners,\n address[] memory validators,\n uint8 _minValidations\n ) Ownable(owner) {\n for (uint256 i = 0; i < solvers.length; i++) _setAllowedSolver(solvers[i], true);\n for (uint256 i = 0; i < executors.length; i++) _setAllowedExecutor(executors[i], true);\n for (uint256 i = 0; i < proposalSigners.length; i++) _setAllowedProposalSigner(proposalSigners[i], true);\n for (uint256 i = 0; i < validators.length; i++) _setAllowedValidator(validators[i], true);\n _setMinValidations(_minValidations);\n }\n\n /**\n * @dev Sets permissions for multiple solvers\n * @param solvers List of solver addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedSolvers(address[] memory solvers, bool[] memory alloweds) external override onlyOwner {\n if (solvers.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < solvers.length; i++) _setAllowedSolver(solvers[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple executors\n * @param executors List of executor addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedExecutors(address[] memory executors, bool[] memory alloweds) external override onlyOwner {\n if (executors.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < executors.length; i++) _setAllowedExecutor(executors[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple proposal signers\n * @param signers List of proposal signer addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedProposalSigners(address[] memory signers, bool[] memory alloweds) external override onlyOwner {\n if (signers.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < signers.length; i++) _setAllowedProposalSigner(signers[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple validators\n * @param validators List of validator addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedValidators(address[] memory validators, bool[] memory alloweds) external override onlyOwner {\n if (validators.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < validators.length; i++) _setAllowedValidator(validators[i], alloweds[i]);\n }\n\n /**\n * @dev Sets the minimum number of validations allowed\n * @param newMinValidations minimum number of validations allowed\n */\n function setMinValidations(uint8 newMinValidations) external override onlyOwner {\n _setMinValidations(newMinValidations);\n }\n\n /**\n * @dev Sets a solver permission\n */\n function _setAllowedSolver(address solver, bool allowed) internal {\n isSolverAllowed[solver] = allowed;\n emit SolverAllowedSet(solver, allowed);\n }\n\n /**\n * @dev Sets an executor permission\n */\n function _setAllowedExecutor(address executor, bool allowed) internal {\n isExecutorAllowed[executor] = allowed;\n emit ExecutorAllowedSet(executor, allowed);\n }\n\n /**\n * @dev Sets a proposal signer permission\n */\n function _setAllowedProposalSigner(address signer, bool allowed) internal {\n isProposalSignerAllowed[signer] = allowed;\n emit ProposalSignerAllowedSet(signer, allowed);\n }\n\n /**\n * @dev Sets a validator permission\n */\n function _setAllowedValidator(address validator, bool allowed) internal {\n isValidatorAllowed[validator] = allowed;\n emit ValidatorAllowedSet(validator, allowed);\n }\n\n /**\n * @dev Sets the minimum number of validations allowed\n */\n function _setMinValidations(uint8 newMinValidations) internal {\n minValidations = newMinValidations;\n emit MinValidationSet(newMinValidations);\n }\n}\n" + }, + "project/contracts/Intents.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Enum representing the type of intent operation.\n * - Swap: Swap tokens between chains or tokens.\n * - Transfer: Transfer tokens to one or more recipients.\n * - Call: Execute arbitrary contract calls.\n */\nenum OpType {\n Swap,\n Transfer,\n Call\n}\n\n/**\n * @dev Execution structure.\n * @param intent Intent to be fulfilled.\n * @param proposal Proposal to be executed.\n * @param signature Proposal signature.\n */\nstruct Execution {\n Intent intent;\n Proposal proposal;\n bytes signature;\n}\n\n/**\n * @dev EIP-712 typed data struct representing a validator's approval of an intent.\n * @param intent The hash of the intent being validated.\n */\nstruct Validation {\n bytes32 intent;\n}\n\n/**\n * @dev General intent structure used to abstract over different intent types.\n * @param op The type of operation this intent represents.\n * @param user The originator of the intent.\n * @param settler The address responsible for executing the intent on-chain.\n * @param nonce A unique value used to prevent replay attacks and distinguish intents.\n * @param deadline The timestamp by which the intent must be executed.\n * @param data ABI-encoded data representing a specific intent type (e.g. SwapIntent, TransferIntent, CallIntent).\n * @param maxFees List of max fees the user is willing to pay for the intent.\n * @param events List of custom intent events to be emitted.\n * @param configSig The signature of the configuration that this intent belongs to\n * @param minValidations The minimum number of validator approvals required for this intent to be considered valid.\n * @param validations The list validator signatures attesting to this intent.\n */\nstruct Intent {\n uint8 op;\n address user;\n address settler;\n bytes32 nonce;\n uint256 deadline;\n bytes data;\n MaxFee[] maxFees;\n IntentEvent[] events;\n bytes configSig;\n uint256 minValidations;\n bytes[] validations;\n}\n\n/**\n * @dev Max fee representation\n * @param token Token used to pay for the execution fee.\n * @param amount Max amount of fee token to be paid for settling this intent.\n */\nstruct MaxFee {\n address token;\n uint256 amount;\n}\n\n/**\n * @dev Intent event representation.\n * @param topic Event topic to be emitted.\n * @param data Event data to be emitted.\n */\nstruct IntentEvent {\n bytes32 topic;\n bytes data;\n}\n\n/**\n * @dev Represents a swap intent between two chains.\n * @param sourceChain Chain ID where tokens will be sent from.\n * @param destinationChain Chain ID where tokens will be received.\n * @param tokensIn List of input tokens and amounts to swap.\n * @param tokensOut List of expected output tokens, minimum amounts, and recipients.\n */\nstruct SwapIntent {\n uint256 sourceChain;\n uint256 destinationChain;\n TokenIn[] tokensIn;\n TokenOut[] tokensOut;\n}\n\n/**\n * @dev Token in representation.\n * @param token Address of a token to be sent.\n * @param amount Amount of tokens to be sent.\n */\nstruct TokenIn {\n address token;\n uint256 amount;\n}\n\n/**\n * @dev Token out representation.\n * @param token Address of a token to be received.\n * @param minAmount Minimum amount of tokens to be received.\n * @param recipient Recipient address that will receive the token out.\n */\nstruct TokenOut {\n address token;\n uint256 minAmount;\n address recipient;\n}\n\n/**\n * @dev Represents a transfer intent containing multiple token transfers.\n * @param chainId Chain ID where the transfers should be executed.\n * @param transfers List of token transfers to be performed.\n */\nstruct TransferIntent {\n uint256 chainId;\n TransferData[] transfers;\n}\n\n/**\n * @dev Transfer data for a single token transfer.\n * @param token Address of the token to transfer.\n * @param amount Amount of the token to transfer.\n * @param recipient Recipient of the token transfer.\n */\nstruct TransferData {\n address token;\n uint256 amount;\n address recipient;\n}\n\n/**\n * @dev Represents a generic call intent consisting of one or more contract calls.\n * @param chainId Chain ID where the calls should be executed.\n * @param calls List of low-level contract calls to be executed.\n */\nstruct CallIntent {\n uint256 chainId;\n CallData[] calls;\n}\n\n/**\n * @dev Low-level call data for a target contract interaction.\n * @param target Target contract address.\n * @param data Calldata to be sent to the target.\n * @param value ETH value to send along with the call.\n */\nstruct CallData {\n address target;\n bytes data;\n uint256 value;\n}\n\n/**\n * @dev Generic proposal structure representing a solver’s response to an intent.\n * @param deadline Timestamp until when the proposal is valid.\n * @param data ABI-encoded proposal-specific data (e.g. SwapProposal).\n * @param fees List of fee amounts the solver requires for execution.\n */\nstruct Proposal {\n uint256 deadline;\n bytes data;\n uint256[] fees;\n}\n\n/**\n * @dev Swap proposal representation for a swap intent.\n * @param executor Address of the executor contract that should be called during intent execution.\n * @param data Arbitrary data used to call the executor contract.\n * @param amountsOut List of amounts of tokens out proposed by the solver.\n */\nstruct SwapProposal {\n address executor;\n bytes data;\n uint256[] amountsOut;\n}\n\nlibrary IntentsHelpers {\n bytes32 internal constant INTENT_TYPE_HASH =\n keccak256(\n 'Intent(uint8 op,address user,address settler,bytes32 nonce,uint256 deadline,bytes data,MaxFee[] maxFees,IntentEvent[] events,bytes configSig,uint256 minValidations)IntentEvent(bytes32 topic,bytes data)MaxFee(address token,uint256 amount)'\n );\n\n bytes32 internal constant PROPOSAL_TYPE_HASH =\n keccak256('Proposal(bytes32 intent,address solver,uint256 deadline,bytes data,uint256[] fees)');\n\n bytes32 internal constant VALIDATION_TYPE_HASH = keccak256('Validation(bytes32 intent)');\n\n bytes32 internal constant MAX_FEE_TYPE_HASH = keccak256('MaxFee(address token,uint256 amount)');\n\n bytes32 internal constant INTENT_EVENT_TYPE_HASH = keccak256('IntentEvent(bytes32 topic,bytes data)');\n\n function hash(Intent memory intent) internal pure returns (bytes32) {\n return\n keccak256(\n abi.encode(\n INTENT_TYPE_HASH,\n intent.op,\n intent.user,\n intent.settler,\n intent.nonce,\n intent.deadline,\n keccak256(intent.data),\n hash(intent.maxFees),\n hash(intent.events),\n intent.configSig,\n intent.minValidations\n )\n );\n }\n\n function hash(Proposal memory proposal, Intent memory intent, address solver) internal pure returns (bytes32) {\n return\n keccak256(\n abi.encode(\n PROPOSAL_TYPE_HASH,\n hash(intent),\n solver,\n proposal.deadline,\n keccak256(proposal.data),\n hash(proposal.fees)\n )\n );\n }\n\n function hash(MaxFee[] memory fees) internal pure returns (bytes32) {\n bytes32[] memory hashes = new bytes32[](fees.length);\n for (uint256 i = 0; i < fees.length; i++) {\n hashes[i] = keccak256(abi.encode(MAX_FEE_TYPE_HASH, fees[i].token, fees[i].amount));\n }\n return keccak256(abi.encodePacked(hashes));\n }\n\n function hash(IntentEvent[] memory events) internal pure returns (bytes32) {\n bytes32[] memory hashes = new bytes32[](events.length);\n for (uint256 i = 0; i < events.length; i++) {\n hashes[i] = keccak256(abi.encode(INTENT_EVENT_TYPE_HASH, events[i].topic, keccak256(events[i].data)));\n }\n return keccak256(abi.encodePacked(hashes));\n }\n\n function hash(uint256[] memory fees) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(fees));\n }\n\n function hash(Validation memory validation) internal pure returns (bytes32) {\n return keccak256(abi.encode(VALIDATION_TYPE_HASH, validation.intent));\n }\n}\n" + }, + "project/contracts/interfaces/IController.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @title Controller interface\n */\ninterface IController {\n /**\n * @dev The input arrays are not of equal length\n */\n error ControllerInputInvalidLength();\n\n /**\n * @dev Emitted every time a solver permission is set\n */\n event SolverAllowedSet(address indexed solver, bool allowed);\n\n /**\n * @dev Emitted every time an executor permission is set\n */\n event ExecutorAllowedSet(address indexed executor, bool allowed);\n\n /**\n * @dev Emitted every time a proposal signer permission is set\n */\n event ProposalSignerAllowedSet(address indexed proposalSigner, bool allowed);\n\n /**\n * @dev Emitted every time a validator permission is set\n */\n event ValidatorAllowedSet(address indexed validator, bool allowed);\n\n /**\n * @dev Emitted when the minimum validations changes\n */\n event MinValidationSet(uint8 indexed newMinValidation);\n\n /**\n * @dev Tells whether a solver is allowed\n * @param solver Address of the solver being queried\n */\n function isSolverAllowed(address solver) external view returns (bool);\n\n /**\n * @dev Tells whether an executor is allowed\n * @param executor Address of the executor being queried\n */\n function isExecutorAllowed(address executor) external view returns (bool);\n\n /**\n * @dev Tells whether a proposal signer is allowed\n * @param signer Address of the proposal signer being queried\n */\n function isProposalSignerAllowed(address signer) external view returns (bool);\n\n /**\n * @dev Tells whether a validator is allowed\n * @param validator Address of the validator being queried\n */\n function isValidatorAllowed(address validator) external view returns (bool);\n\n /**\n * @dev Tells the minimum number of validations allowed\n */\n function minValidations() external view returns (uint8);\n\n /**\n * @dev Sets permissions for multiple solvers\n * @param solvers List of solver addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedSolvers(address[] memory solvers, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple executors\n * @param executors List of executor addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedExecutors(address[] memory executors, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple proposal signers\n * @param signers List of proposal signer addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedProposalSigners(address[] memory signers, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple validators\n * @param validators List of validator addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedValidators(address[] memory validators, bool[] memory alloweds) external;\n\n /**\n * @dev Sets the minimum number of validations allowed\n * @param newMinValidations minimum number of validations allowed\n */\n function setMinValidations(uint8 newMinValidations) external;\n}\n" + }, + "project/contracts/interfaces/ICreateX.sol": { + "content": "// SPDX-License-Identifier: AGPL-3.0-only\n\npragma solidity ^0.8.4;\n\n/**\n * @title CreateX Factory Interface Definition\n * @author pcaversaccio (https://web.archive.org/web/20230921103111/https://pcaversaccio.com/)\n * @custom:coauthor Matt Solomon (https://web.archive.org/web/20230921103335/https://mattsolomon.dev/)\n */\ninterface ICreateX {\n event ContractCreation(address indexed newContract);\n\n function deployCreate3(bytes32 salt, bytes memory initCode) external payable returns (address newContract);\n}\n" + }, + "project/contracts/interfaces/IExecutor.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\n\n/**\n * @title Executor interface\n */\ninterface IExecutor {\n /**\n * @dev Executes an intent proposal\n * @param intent Intent to be executed\n * @param proposal Proposal to be executed to fulfill the intent\n */\n function execute(Intent memory intent, Proposal memory proposal) external;\n}\n" + }, + "project/contracts/interfaces/IIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\nimport '../safeguards/Safeguards.sol';\n\n/**\n * @title IntentsValidator\n * @dev Performs intents validations based on safeguards\n */\ninterface IIntentsValidator {\n /**\n * @dev Validates an intent for a safeguard\n * @param intent Intent to be validated\n * @param config Safeguard config to validate the intent with\n */\n function validate(Intent memory intent, bytes memory config) external pure;\n}\n" + }, + "project/contracts/interfaces/ISafe.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nenum SafeOperation {\n Call,\n DelegateCall\n}\n\ninterface ISafe {\n function getThreshold() external view returns (uint256);\n\n function execTransactionFromModuleReturnData(address to, uint256 value, bytes memory data, SafeOperation operation)\n external\n returns (bool success, bytes memory returnData);\n}\n" + }, + "project/contracts/interfaces/ISettler.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\nimport '../safeguards/Safeguards.sol';\n\n/**\n * @title Settler interface\n */\ninterface ISettler {\n /**\n * @dev The requested intent type is unknown\n */\n error SettlerUnknownIntentType(uint8 op);\n\n /**\n * @dev The simulation has been successful\n */\n error SettlerSimulationSuccess(uint256 gasUsed);\n\n /**\n * @dev The solver is not allowed\n */\n error SettlerSolverNotAllowed(address solver);\n\n /**\n * @dev The executor is not allowed\n */\n error SettlerExecutorNotAllowed(address executor);\n\n /**\n * @dev The proposal signer is not allowed\n */\n error SettlerProposalSignerNotAllowed(address signer);\n\n /**\n * @dev The validator is not allowed\n */\n error SettlerValidatorNotAllowed(address validator);\n\n /**\n * @dev The validator is duplicated\n */\n error SettlerValidatorDuplicatedOrUnsorted(address previous, address current);\n\n /**\n * @dev The settler is not the current contract\n */\n error SettlerInvalidSettler(address settler);\n\n /**\n * @dev The nonce is zero\n */\n error SettlerNonceZero();\n\n /**\n * @dev The nonce has already been used for the user\n */\n error SettlerNonceAlreadyUsed(address user, bytes32 nonce);\n\n /**\n * @dev The intent deadline is in the past\n */\n error SettlerIntentPastDeadline(uint256 deadline, uint256 timestamp);\n\n /**\n * @dev The current chain is not valid\n */\n error SettlerInvalidChain(uint256 chainId);\n\n /**\n * @dev The recipient is the settler contract\n */\n error SettlerInvalidRecipient(address to);\n\n /**\n * @dev The user is not a smart account\n */\n error SettlerUserNotSmartAccount(address user);\n\n /**\n * @dev The amount out is lower than the proposed amount\n */\n error SettlerAmountOutLtProposed(uint256 index, uint256 amountOut, uint256 proposed);\n\n /**\n * @dev The proposed amount is lower than the minimum amount\n */\n error SettlerProposedAmountLtMinAmount(uint256 index, uint256 proposed, uint256 minAmount);\n\n /**\n * @dev The proposed amounts array and the tokens out array are not of equal length\n */\n error SettlerInvalidProposedAmounts();\n\n /**\n * @dev The balance after the proposal execution is lower than the balance before\n */\n error SettlerPostBalanceOutLtPre(uint256 index, uint256 post, uint256 pre);\n\n /**\n * @dev The solver fees length does not match the requested by the user\n */\n error SettlerSolverFeeInvalidLength();\n\n /**\n * @dev The solver fee is too high\n */\n error SettlerSolverFeeTooHigh(uint256 fee, uint256 max);\n\n /**\n * @dev The intent validations are not enough\n */\n error SettlerIntentValidationsNotEnough(uint256 min, uint256 current);\n\n /**\n * @dev The proposal deadline is in the past\n */\n error SettlerProposalPastDeadline(uint256 deadline, uint256 timestamp);\n\n /**\n * @dev The proposal data is not empty\n */\n error SettlerProposalDataNotEmpty();\n\n /**\n * @dev The rescue funds recipient is zero\n */\n error SettlerRescueFundsRecipientZero();\n\n /**\n * @dev The list of safeguards exceed the maximum allowed\n */\n error SettlerTooManySafeguards(uint256 lengthRequested);\n\n /**\n * @dev The new smart accounts handler is zero\n */\n error SmartAccountsHandlerZero();\n\n /**\n * @dev Custom events emitted for each intent\n */\n event IntentExecuted(\n address indexed user,\n bytes32 indexed topic,\n uint8 indexed op,\n Intent intent,\n Proposal proposal,\n bytes output,\n bytes data\n );\n\n /**\n * @dev Emitted every time an intent is fulfilled\n */\n event ProposalExecuted(bytes32 indexed proposal, uint256 index);\n\n /**\n * @dev Emitted every time tokens are withdrawn from the contract balance\n */\n event FundsRescued(address indexed token, address indexed recipient, uint256 amount);\n\n /**\n * @dev Emitted every time the smart accounts handler is set\n */\n event SmartAccountsHandlerSet(address indexed smartAccountsHandler);\n\n /**\n * @dev Emitted every time the intents validator is set\n */\n event IntentsValidatorSet(address indexed intentsValidator);\n\n /**\n * @dev Emitted every time a safeguard is set\n */\n event SafeguardSet(address indexed user);\n\n /**\n * @dev Tells the reference to the Mimic controller\n */\n function controller() external view returns (address);\n\n /**\n * @dev Tells the reference to the smart accounts handler\n */\n function smartAccountsHandler() external view returns (address);\n\n /**\n * @dev Tells the reference to the intents validator\n */\n function intentsValidator() external view returns (address);\n\n /**\n * @dev Tells the block at which a user nonce was used. Returns 0 if unused.\n * @param user Address of the user being queried\n * @param nonce Nonce being queried\n */\n function getNonceBlock(address user, bytes32 nonce) external view returns (uint256);\n\n /**\n * @dev Tells the safeguard set for a user\n * @param user Address of the user being queried\n */\n function getUserSafeguard(address user) external view returns (bytes memory);\n\n /**\n * @dev Tells the hash of an intent\n * @param intent Intent to get the hash of\n */\n function getIntentHash(Intent memory intent) external pure returns (bytes32);\n\n /**\n * @dev Tells the hash of a proposal\n * @param proposal Proposal to be hashed\n * @param intent Intent being fulfilled by the requested proposal\n * @param solver Address of the solver that made the proposal\n */\n function getProposalHash(Proposal memory proposal, Intent memory intent, address solver)\n external\n pure\n returns (bytes32);\n\n /**\n * @dev Withdraws ERC20 or native tokens from the contract\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function rescueFunds(address token, address recipient, uint256 amount) external;\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function setSmartAccountsHandler(address newSmartAccountsHandler) external;\n\n /**\n * @dev Sets a new intents validator address\n * @param newIntentsValidator New intents validator to be set\n */\n function setIntentsValidator(address newIntentsValidator) external;\n\n /**\n * @dev Sets a safeguard for a user\n * @param safeguard Safeguard to be set\n */\n function setSafeguard(bytes memory safeguard) external;\n\n /**\n * @dev Executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function execute(Execution[] memory executions) external;\n\n /**\n * @dev Simulates an execution. It will always revert. Successful executions are returned as\n * `SettlerSimulationSuccess` errors. Any other error should be treated as failure.\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function simulate(Execution[] memory executions) external;\n}\n" + }, + "project/contracts/interfaces/ISmartAccount.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/introspection/IERC165.sol';\n\n/**\n * @title SmartAccount interface\n */\ninterface ISmartAccount is IERC165 {\n /**\n * @dev Emitted every time tokens are transferred\n */\n event Transferred(address indexed token, address indexed recipient, uint256 amount);\n\n /**\n * @dev Emitted every time `call` is called\n */\n event Called(address indexed target, bytes data, uint256 value, bytes result);\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the owner or the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) external;\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the owner or the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n */\n function call(address target, bytes memory data, uint256 value) external returns (bytes memory result);\n}\n" + }, + "project/contracts/interfaces/ISmartAccountContract.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/interfaces/IERC1271.sol';\n\nimport './ISmartAccount.sol';\n\n/**\n * @title SmartAccountContract interface\n */\ninterface ISmartAccountContract is ISmartAccount, IERC1271 {\n // solhint-disable-previous-line no-empty-blocks\n}\n" + }, + "project/contracts/interfaces/ISmartAccountsHandler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\ninterface ISmartAccountsHandler {\n /**\n * @dev The smart account given is not supported\n */\n error SmartAccountsHandlerUnsupportedAccount(address account);\n\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address account) external view returns (bool);\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address account, address token, address to, uint256 amount) external;\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address account, address target, bytes memory data, uint256 value) external returns (bytes memory);\n}\n" + }, + "project/contracts/safeguards/BaseIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @title BaseIntentsValidator\n */\ncontract BaseIntentsValidator {\n /**\n * @dev No intents allowed\n */\n error IntentsValidatorNoneAllowed();\n\n /**\n * @dev Intent type unknown\n */\n error IntentsValidatorUnknownIntentType(uint8 opType);\n\n /**\n * @dev Invalid safeguard mode\n */\n error IntentsValidatorInvalidSafeguardMode(uint8 mode);\n\n /**\n * @dev Tells whether a chain is allowed\n */\n function _isChainAllowed(uint256 chainId, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, uint256[] memory values) = abi.decode(config, (bool, uint256[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (chainId == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (chainId == values[i]) return true;\n }\n return false;\n }\n }\n\n /**\n * @dev Tells whether an account is allowed\n */\n function _isAccountAllowed(address account, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, address[] memory values) = abi.decode(config, (bool, address[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (account == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (account == values[i]) return true;\n }\n return false;\n }\n }\n\n /**\n * @dev Tells whether a selector is allowed\n */\n function _isSelectorAllowed(bytes4 selector, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, bytes4[] memory values) = abi.decode(config, (bool, bytes4[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (selector == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (selector == values[i]) return true;\n }\n return false;\n }\n }\n}\n" + }, + "project/contracts/safeguards/CallIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './Safeguards.sol';\nimport './BaseIntentsValidator.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Call safeguard modes to validate call intents\n * @param None To ensure no calls are allowed\n * @param Chain To validate that the chain where calls execute is allowed\n * @param Target To validate that the call targets (contract addresses) are allowed\n * @param Selector To validate that the function selectors being called are allowed\n */\nenum CallSafeguardMode {\n None,\n Chain,\n Target,\n Selector\n}\n\n/**\n * @title CallIntentsValidator\n * @dev Performs call intents validations based on safeguards\n */\ncontract CallIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a call intent is valid for a safeguard\n * @param intent Call intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isCallIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n CallIntent memory callIntent = abi.decode(intent.data, (CallIntent));\n if (safeguard.mode == uint8(CallSafeguardMode.Chain))\n return _isChainAllowed(callIntent.chainId, safeguard.config);\n if (safeguard.mode == uint8(CallSafeguardMode.Target))\n return _areCallTargetsValid(callIntent.calls, safeguard.config);\n if (safeguard.mode == uint8(CallSafeguardMode.Selector))\n return _areCallSelectorsValid(callIntent.calls, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the call targets are allowed\n */\n function _areCallTargetsValid(CallData[] memory calls, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < calls.length; i++) {\n if (!_isAccountAllowed(calls[i].target, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the call selectors are allowed\n */\n function _areCallSelectorsValid(CallData[] memory calls, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < calls.length; i++) {\n if (!_isSelectorAllowed(bytes4(calls[i].data), config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/safeguards/IntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './CallIntentsValidator.sol';\nimport './TransferIntentsValidator.sol';\nimport './Safeguards.sol';\nimport './SwapIntentsValidator.sol';\nimport '../Intents.sol';\nimport '../interfaces/IIntentsValidator.sol';\n\n/**\n * @title IntentsValidator\n * @dev Performs intents validations based on safeguards\n */\ncontract IntentsValidator is IIntentsValidator, SwapIntentsValidator, TransferIntentsValidator, CallIntentsValidator {\n /**\n * @dev Safeguard validation failed\n */\n error IntentsValidatorSafeguardFailed();\n\n /**\n * @dev Invalid safeguard config mode\n */\n error IntentsValidatorInvalidSafeguardConfigMode(uint8 mode);\n\n /**\n * @dev Invalid safeguard group logic mode\n */\n error IntentsValidatorInvalidSafeguardGroupLogicMode(uint8 mode);\n\n /**\n * @dev Tells whether an intent is valid for a safeguard\n * @param intent Intent to be validated\n * @param config Safeguard config to validate the intent with\n */\n function validate(Intent memory intent, bytes memory config) external pure override {\n (uint8 mode, bytes memory safeguard) = abi.decode(config, (uint8, bytes));\n if (mode == uint8(SafeguardConfigMode.List)) _validate(intent, abi.decode(safeguard, (Safeguard[])));\n else if (mode == uint8(SafeguardConfigMode.Tree)) _validate(intent, _decodeSafeguardTree(safeguard));\n else revert IntentsValidatorInvalidSafeguardConfigMode(mode);\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguards list\n * @param intent Intent to be validated\n * @param safeguards Safeguard list to validate the intent with\n */\n function _validate(Intent memory intent, Safeguard[] memory safeguards) internal pure {\n if (safeguards.length == 0) revert IntentsValidatorSafeguardFailed();\n for (uint256 i = 0; i < safeguards.length; i++) {\n if (!_isSafeguardValid(intent, safeguards[i])) revert IntentsValidatorSafeguardFailed();\n }\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard tree\n * @param intent Intent to be validated\n * @param tree Safeguard tree to validate the intent with\n */\n function _validate(Intent memory intent, SafeguardTree memory tree) internal pure {\n if (tree.nodes.length == 0) revert IntentsValidatorSafeguardFailed();\n if (!_isSafeguardGroupValid(intent, tree, 0)) revert IntentsValidatorSafeguardFailed();\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard tree at a certain level\n * @param intent Intent to be validated\n * @param tree Safeguard tree to validate the intent with\n * @param index Index of the group node to evaluate\n */\n function _isSafeguardGroupValid(Intent memory intent, SafeguardTree memory tree, uint16 index)\n internal\n pure\n returns (bool)\n {\n SafeguardGroup memory group = tree.nodes[index];\n\n if (group.logic == uint8(SafeguardGroupLogic.NOT)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i])) return false;\n }\n return true;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.AND)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (!_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (!_isSafeguardGroupValid(intent, tree, group.children[i])) return false;\n }\n return true;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.OR)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return true;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i])) return true;\n }\n return false;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.XOR)) {\n uint256 hits = 0;\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]]))\n if (++hits > 1) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i]))\n if (++hits > 1) return false;\n }\n return hits == 1;\n }\n\n revert IntentsValidatorInvalidSafeguardGroupLogicMode(group.logic);\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard\n * @param intent Intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isSafeguardValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n if (safeguard.mode == uint8(0)) revert IntentsValidatorNoneAllowed();\n if (intent.op == uint8(OpType.Swap)) return _isSwapIntentValid(intent, safeguard);\n if (intent.op == uint8(OpType.Transfer)) return _isTransferIntentValid(intent, safeguard);\n if (intent.op == uint8(OpType.Call)) return _isCallIntentValid(intent, safeguard);\n revert IntentsValidatorUnknownIntentType(uint8(intent.op));\n }\n\n /**\n * @dev Safely decodes a safeguard tree avoiding compiler issues with dynamic arrays\n * @param data Safeguard tree data to be decoded\n */\n function _decodeSafeguardTree(bytes memory data) private pure returns (SafeguardTree memory) {\n (SafeguardGroup[] memory nodes, Safeguard[] memory leaves) = abi.decode(data, (SafeguardGroup[], Safeguard[]));\n return SafeguardTree(nodes, leaves);\n }\n}\n" + }, + "project/contracts/safeguards/Safeguards.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Safeguard config modes\n * - List: Safeguard lists\n * - Tree: Safeguard groups\n */\nenum SafeguardConfigMode {\n List,\n Tree\n}\n\n/**\n * @dev Logical operators for safeguard groups\n * - AND: every child must pass\n * - OR: at least one child must pass\n * - XOR: exactly one child must pass\n * - NOT: every child must fail\n */\nenum SafeguardGroupLogic {\n AND,\n OR,\n XOR,\n NOT\n}\n\n/**\n * @dev Flat node in the safeguard tree\n * @param logic Group operator (AND/OR/XOR/NOT)\n * @param leaves Indices into `SafeguardTree.leaves`\n * @param children Indices into `SafeguardTree.nodes`\n */\nstruct SafeguardGroup {\n uint8 logic;\n uint16[] leaves;\n uint16[] children;\n}\n\n/**\n * @dev Safeguard tree representation\n * @param nodes List of all the nodes in the tree\n * @param leaves List of all the leaves in the tree\n */\nstruct SafeguardTree {\n SafeguardGroup[] nodes;\n Safeguard[] leaves;\n}\n\n/**\n * @dev Safeguard representation\n * @param mode Safeguard mode\n * @param config Safeguard configuration settings or parameters\n */\nstruct Safeguard {\n uint8 mode;\n bytes config;\n}\n" + }, + "project/contracts/safeguards/SwapIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './BaseIntentsValidator.sol';\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Swap safeguard modes to validate swap intents\n * @param None To ensure no swaps are allowed\n * @param SourceChain To validate that the source chain is allowed\n * @param DestinationChain To validate that the destination chain is allowed\n * @param TokenIn To validate that the tokens to be sent are allowed\n * @param TokenOut To validate that the tokens to be received are allowed\n * @param Recipient To validate that the recipients that will receive the tokens are allowed\n */\nenum SwapSafeguardMode {\n None,\n SourceChain,\n DestinationChain,\n TokenIn,\n TokenOut,\n Recipient\n}\n\n/**\n * @title SwapIntentsValidator\n * @dev Performs swap intents validations based on safeguards\n */\ncontract SwapIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a swap intent is valid for a safeguard\n * @param intent Swap intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isSwapIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n if (safeguard.mode == uint8(SwapSafeguardMode.SourceChain))\n return _isChainAllowed(swapIntent.sourceChain, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.DestinationChain))\n return _isChainAllowed(swapIntent.destinationChain, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.TokenIn))\n return _areSwapTokensInValid(swapIntent.tokensIn, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.TokenOut))\n return _areSwapTokensOutValid(swapIntent.tokensOut, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.Recipient))\n return _areSwapRecipientsValid(swapIntent.tokensOut, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the tokens to be sent are allowed\n */\n function _areSwapTokensInValid(TokenIn[] memory tokensIn, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensIn.length; i++) {\n if (!_isAccountAllowed(tokensIn[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the tokens to be received are allowed\n */\n function _areSwapTokensOutValid(TokenOut[] memory tokensOut, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensOut.length; i++) {\n if (!_isAccountAllowed(tokensOut[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the recipients to be received are allowed\n */\n function _areSwapRecipientsValid(TokenOut[] memory tokensOut, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensOut.length; i++) {\n if (!_isAccountAllowed(tokensOut[i].recipient, config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/safeguards/TransferIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './BaseIntentsValidator.sol';\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Transfer safeguard modes to validate transfer intents\n * @param None To ensure no transfers are allowed\n * @param Chain To validate that the chain where transfers execute is allowed\n * @param Token To validate that the tokens being transferred are allowed\n * @param Recipient To validate that the recipients of the transfers are allowed\n */\nenum TransferSafeguardMode {\n None,\n Chain,\n Token,\n Recipient\n}\n\n/**\n * @title TransferIntentsValidator\n * @dev Performs transfer intents validations based on safeguards\n */\ncontract TransferIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a transfer intent is valid for a safeguard\n * @param intent Transfer intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isTransferIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n TransferIntent memory transferIntent = abi.decode(intent.data, (TransferIntent));\n if (safeguard.mode == uint8(TransferSafeguardMode.Chain))\n return _isChainAllowed(transferIntent.chainId, safeguard.config);\n if (safeguard.mode == uint8(TransferSafeguardMode.Token))\n return _areTransferTokensValid(transferIntent.transfers, safeguard.config);\n if (safeguard.mode == uint8(TransferSafeguardMode.Recipient))\n return _areTransferRecipientsValid(transferIntent.transfers, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the tokens being transferred are allowed\n */\n function _areTransferTokensValid(TransferData[] memory transfers, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < transfers.length; i++) {\n if (!_isAccountAllowed(transfers[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the recipients of the transfers are allowed\n */\n function _areTransferRecipientsValid(TransferData[] memory transfers, bytes memory config)\n private\n pure\n returns (bool)\n {\n for (uint256 i = 0; i < transfers.length; i++) {\n if (!_isAccountAllowed(transfers[i].recipient, config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/Settler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/cryptography/ECDSA.sol';\nimport '@openzeppelin/contracts/utils/cryptography/EIP712.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165Checker.sol';\n\nimport './Intents.sol';\nimport './interfaces/IController.sol';\nimport './interfaces/IIntentsValidator.sol';\nimport './interfaces/IExecutor.sol';\nimport './interfaces/ISettler.sol';\nimport './utils/Denominations.sol';\nimport './utils/ERC20Helpers.sol';\nimport './smart-accounts/SmartAccountsHandler.sol';\nimport './smart-accounts/SmartAccountsHandlerHelpers.sol';\n\n/**\n * @title Settler\n * @dev Contract that provides the appropriate context for solvers to execute proposals that fulfill user intents\n */\ncontract Settler is ISettler, Ownable, ReentrancyGuard, EIP712 {\n using SafeERC20 for IERC20;\n using IntentsHelpers for Intent;\n using IntentsHelpers for Proposal;\n using IntentsHelpers for Validation;\n using SmartAccountsHandlerHelpers for address;\n\n // Mimic controller reference\n // solhint-disable-next-line immutable-vars-naming\n address public immutable override controller;\n\n // Smart accounts handler reference\n address public override smartAccountsHandler;\n\n // Intents validator reference\n address public override intentsValidator;\n\n // List of block numbers at which a user nonce was used\n mapping (address => mapping (bytes32 => uint256)) public override getNonceBlock;\n\n // Safeguard config per user\n mapping (address => bytes) internal _userSafeguard;\n\n /**\n * @dev Modifier to tag settler functions in order to check if the sender is an allowed solver\n */\n modifier onlySolver() {\n address sender = _msgSender();\n if (!IController(controller).isSolverAllowed(sender)) revert SettlerSolverNotAllowed(sender);\n _;\n }\n\n /**\n * @dev Creates a new Settler contract\n * @param _controller Address of the Settler controller\n * @param _owner Address that will own the contract\n */\n constructor(address _controller, address _owner) Ownable(_owner) EIP712('Mimic Protocol Settler', '1') {\n controller = _controller;\n smartAccountsHandler = address(new SmartAccountsHandler());\n }\n\n /**\n * @dev Tells the hash of an intent\n * @param intent Intent to get the hash of\n */\n function getIntentHash(Intent memory intent) external pure override returns (bytes32) {\n return intent.hash();\n }\n\n /**\n * @dev Tells the hash of a proposal\n * @param proposal Proposal to be hashed\n * @param intent Intent being fulfilled by the requested proposal\n * @param solver Address of the solver that made the proposal\n */\n function getProposalHash(Proposal memory proposal, Intent memory intent, address solver)\n external\n pure\n override\n returns (bytes32)\n {\n return proposal.hash(intent, solver);\n }\n\n /**\n * @dev Tells the safeguard set for a user\n * @param user Address of the user being queried\n */\n function getUserSafeguard(address user) external view override returns (bytes memory) {\n return _userSafeguard[user];\n }\n\n /**\n * @dev It allows receiving native token transfers\n * Note: This method mainly allows supporting native tokens for swaps\n */\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n /**\n * @dev Withdraws ERC20 or native tokens from the contract\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function rescueFunds(address token, address recipient, uint256 amount) external override onlyOwner nonReentrant {\n if (recipient == address(0)) revert SettlerRescueFundsRecipientZero();\n ERC20Helpers.transfer(token, recipient, amount);\n emit FundsRescued(token, recipient, amount);\n }\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function setSmartAccountsHandler(address newSmartAccountsHandler) external override onlyOwner {\n _setSmartAccountsHandler(newSmartAccountsHandler);\n }\n\n /**\n * @dev Sets a new intents validator address\n * @param newIntentsValidator New intents validator to be set\n */\n function setIntentsValidator(address newIntentsValidator) external override onlyOwner {\n _setIntentsValidator(newIntentsValidator);\n }\n\n /**\n * @dev Sets a safeguard for a user\n * @param safeguard Safeguard to be set\n */\n function setSafeguard(bytes memory safeguard) external override {\n _setSafeguard(msg.sender, safeguard);\n }\n\n /**\n * @dev Executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function execute(Execution[] memory executions) external override onlySolver {\n _execute(executions, false);\n }\n\n /**\n * @dev Simulates an execution. It will always revert. Successful executions are returned as\n * `SettlerSimulationSuccess` errors. Any other error should be treated as failure.\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function simulate(Execution[] memory executions) external override onlySolver {\n uint256 initialGas = gasleft();\n _execute(executions, true);\n uint256 gasUsed = initialGas - gasleft();\n revert SettlerSimulationSuccess(gasUsed);\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n * @param simulated Whether the execution is a simulation\n */\n function _execute(Execution[] memory executions, bool simulated) internal nonReentrant {\n for (uint256 i = 0; i < executions.length; i++) {\n Intent memory intent = executions[i].intent;\n Proposal memory proposal = executions[i].proposal;\n bytes memory signature = executions[i].signature;\n\n _validateIntent(intent, proposal, signature, simulated);\n getNonceBlock[intent.user][intent.nonce] = block.number;\n\n if (intent.op == uint8(OpType.Swap)) _executeSwap(intent, proposal);\n else if (intent.op == uint8(OpType.Transfer)) _executeTransfer(intent, proposal);\n else if (intent.op == uint8(OpType.Call)) _executeCall(intent, proposal);\n else revert SettlerUnknownIntentType(uint8(intent.op));\n\n emit ProposalExecuted(proposal.hash(intent, _msgSender()), i);\n }\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a swap intent\n * @param intent Swap intent to be fulfilled\n * @param proposal Swap proposal to be executed\n */\n function _executeSwap(Intent memory intent, Proposal memory proposal) internal {\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n _validateSwapIntent(swapIntent, swapProposal);\n\n bool isSmartAccount = smartAccountsHandler.isSmartAccount(intent.user);\n if (swapIntent.sourceChain == block.chainid) {\n for (uint256 i = 0; i < swapIntent.tokensIn.length; i++) {\n TokenIn memory tokenIn = swapIntent.tokensIn[i];\n _transferFrom(tokenIn.token, intent.user, swapProposal.executor, tokenIn.amount, isSmartAccount);\n }\n }\n\n uint256[] memory preBalancesOut = _getTokensOutBalance(swapIntent);\n IExecutor(swapProposal.executor).execute(intent, proposal);\n\n if (swapIntent.destinationChain == block.chainid) {\n uint256[] memory outputs = new uint256[](swapIntent.tokensOut.length);\n for (uint256 i = 0; i < swapIntent.tokensOut.length; i++) {\n TokenOut memory tokenOut = swapIntent.tokensOut[i];\n uint256 postBalanceOut = ERC20Helpers.balanceOf(tokenOut.token, address(this));\n uint256 preBalanceOut = preBalancesOut[i];\n if (postBalanceOut < preBalanceOut) revert SettlerPostBalanceOutLtPre(i, postBalanceOut, preBalanceOut);\n\n outputs[i] = postBalanceOut - preBalanceOut;\n uint256 proposedAmount = swapProposal.amountsOut[i];\n if (outputs[i] < proposedAmount) revert SettlerAmountOutLtProposed(i, outputs[i], proposedAmount);\n\n ERC20Helpers.transfer(tokenOut.token, tokenOut.recipient, outputs[i]);\n }\n\n _emitIntentEvents(intent, proposal, abi.encode(outputs));\n _payFees(intent, proposal, isSmartAccount);\n }\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a transfer intent\n * @param intent Transfer intent to be fulfilled\n * @param proposal Transfer proposal to be executed\n */\n function _executeTransfer(Intent memory intent, Proposal memory proposal) internal {\n TransferIntent memory transferIntent = abi.decode(intent.data, (TransferIntent));\n _validateTransferIntent(transferIntent, proposal);\n\n bool isSmartAccount = smartAccountsHandler.isSmartAccount(intent.user);\n for (uint256 i = 0; i < transferIntent.transfers.length; i++) {\n TransferData memory transfer = transferIntent.transfers[i];\n _transferFrom(transfer.token, intent.user, transfer.recipient, transfer.amount, isSmartAccount);\n }\n\n _emitIntentEvents(intent, proposal, new bytes(0));\n _payFees(intent, proposal, isSmartAccount);\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a call intent\n * @param intent Call intent to be fulfilled\n * @param proposal Call proposal to be executed\n */\n function _executeCall(Intent memory intent, Proposal memory proposal) internal {\n CallIntent memory callIntent = abi.decode(intent.data, (CallIntent));\n _validateCallIntent(callIntent, proposal, intent.user);\n\n bytes[] memory outputs = new bytes[](callIntent.calls.length);\n for (uint256 i = 0; i < callIntent.calls.length; i++) {\n CallData memory call = callIntent.calls[i];\n // solhint-disable-next-line avoid-low-level-calls\n outputs[i] = smartAccountsHandler.call(intent.user, call.target, call.data, call.value);\n }\n\n _emitIntentEvents(intent, proposal, abi.encode(outputs));\n _payFees(intent, proposal, true);\n }\n\n /**\n * @dev Validates an intent and its corresponding proposal\n * @param intent Intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param signature Proposal signature\n * @param simulated Whether the execution is a simulation\n */\n function _validateIntent(Intent memory intent, Proposal memory proposal, bytes memory signature, bool simulated)\n internal\n view\n {\n if (intent.settler != address(this)) revert SettlerInvalidSettler(intent.settler);\n if (intent.nonce == bytes32(0)) revert SettlerNonceZero();\n if (getNonceBlock[intent.user][intent.nonce] != 0) revert SettlerNonceAlreadyUsed(intent.user, intent.nonce);\n\n if (intentsValidator != address(0)) {\n bytes memory safeguard = _userSafeguard[intent.user];\n if (safeguard.length > 0) IIntentsValidator(intentsValidator).validate(intent, safeguard);\n }\n\n bool shouldValidateDeadlines = _shouldValidateDeadlines(intent);\n if (shouldValidateDeadlines) {\n if (intent.deadline <= block.timestamp) revert SettlerIntentPastDeadline(intent.deadline, block.timestamp);\n bool isProposalPastDeadline = proposal.deadline <= block.timestamp;\n if (isProposalPastDeadline) revert SettlerProposalPastDeadline(proposal.deadline, block.timestamp);\n }\n\n if (intent.maxFees.length != proposal.fees.length) revert SettlerSolverFeeInvalidLength();\n for (uint256 i = 0; i < intent.maxFees.length; i++) {\n uint256 maxFee = intent.maxFees[i].amount;\n uint256 proposalFee = proposal.fees[i];\n if (proposalFee > maxFee) revert SettlerSolverFeeTooHigh(proposalFee, maxFee);\n }\n\n uint8 minValidations = IController(controller).minValidations();\n uint256 requiredValidations = intent.minValidations > minValidations ? intent.minValidations : minValidations;\n\n if (intent.validations.length < requiredValidations) {\n revert SettlerIntentValidationsNotEnough(requiredValidations, intent.validations.length);\n }\n\n address lastValidator = address(0);\n Validation memory validation = Validation(intent.hash());\n bytes32 typedDataHash = _hashTypedDataV4(validation.hash());\n for (uint256 i = 0; i < intent.validations.length; i++) {\n address validator = ECDSA.recover(typedDataHash, intent.validations[i]);\n if (validator <= lastValidator) {\n revert SettlerValidatorDuplicatedOrUnsorted(lastValidator, validator);\n }\n lastValidator = validator;\n bool isValidatorNotAllowed = !IController(controller).isValidatorAllowed(validator);\n if (isValidatorNotAllowed) revert SettlerValidatorNotAllowed(validator);\n }\n\n address signer = ECDSA.recover(_hashTypedDataV4(proposal.hash(intent, _msgSender())), signature);\n bool isProposalSignerNotAllowed = !IController(controller).isProposalSignerAllowed(signer) && !simulated;\n if (isProposalSignerNotAllowed) revert SettlerProposalSignerNotAllowed(signer);\n }\n\n /**\n * @dev Validates a swap intent and its corresponding proposal\n * @param intent Swap intent to be fulfilled\n * @param proposal Proposal to be executed\n */\n function _validateSwapIntent(SwapIntent memory intent, SwapProposal memory proposal) internal view {\n bool isChainInvalid = intent.sourceChain != block.chainid && intent.destinationChain != block.chainid;\n if (isChainInvalid) revert SettlerInvalidChain(block.chainid);\n\n if (proposal.amountsOut.length != intent.tokensOut.length) revert SettlerInvalidProposedAmounts();\n\n for (uint256 i = 0; i < intent.tokensOut.length; i++) {\n TokenOut memory tokenOut = intent.tokensOut[i];\n address recipient = tokenOut.recipient;\n if (recipient == address(this)) revert SettlerInvalidRecipient(recipient);\n\n uint256 minAmount = tokenOut.minAmount;\n uint256 proposedAmount = proposal.amountsOut[i];\n if (proposedAmount < minAmount) revert SettlerProposedAmountLtMinAmount(i, proposedAmount, minAmount);\n }\n\n if (intent.sourceChain != intent.destinationChain) {\n bool isExecutorInvalid = !IController(controller).isExecutorAllowed(proposal.executor);\n if (isExecutorInvalid) revert SettlerExecutorNotAllowed(proposal.executor);\n }\n }\n\n /**\n * @dev Validates a transfer intent and its corresponding proposal\n * @param intent Transfer intent to be fulfilled\n * @param proposal Proposal to be executed\n */\n function _validateTransferIntent(TransferIntent memory intent, Proposal memory proposal) internal view {\n if (intent.chainId != block.chainid) revert SettlerInvalidChain(block.chainid);\n if (proposal.data.length > 0) revert SettlerProposalDataNotEmpty();\n for (uint256 i = 0; i < intent.transfers.length; i++) {\n address recipient = intent.transfers[i].recipient;\n if (recipient == address(this)) revert SettlerInvalidRecipient(recipient);\n }\n }\n\n /**\n * @dev Validates a call intent and its corresponding proposal\n * @param intent Call intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param user The originator of the intent\n */\n function _validateCallIntent(CallIntent memory intent, Proposal memory proposal, address user) internal view {\n if (intent.chainId != block.chainid) revert SettlerInvalidChain(block.chainid);\n if (proposal.data.length > 0) revert SettlerProposalDataNotEmpty();\n if (!smartAccountsHandler.isSmartAccount(user)) revert SettlerUserNotSmartAccount(user);\n }\n\n /**\n * @dev Tells the contract balance for each token out of a swap intent\n * @param intent Swap intent containing the list of tokens out\n */\n function _getTokensOutBalance(SwapIntent memory intent) internal view returns (uint256[] memory balances) {\n balances = new uint256[](intent.tokensOut.length);\n if (intent.destinationChain == block.chainid) {\n for (uint256 i = 0; i < intent.tokensOut.length; i++) {\n balances[i] = ERC20Helpers.balanceOf(intent.tokensOut[i].token, address(this));\n }\n }\n }\n\n /**\n * @dev Tells if the intent and proposal deadlines should be validated\n * @param intent Intent to be fulfilled\n */\n function _shouldValidateDeadlines(Intent memory intent) internal view returns (bool) {\n if (intent.op != uint8(OpType.Swap)) return true;\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n if (swapIntent.sourceChain == swapIntent.destinationChain) return true;\n return swapIntent.sourceChain == block.chainid;\n }\n\n /**\n * @dev Emits intent custom events\n * @param intent Intent to emit the custom events for\n * @param proposal Proposal that fulfills the intent\n * @param output Encoded array of outputs\n */\n function _emitIntentEvents(Intent memory intent, Proposal memory proposal, bytes memory output) internal {\n for (uint256 i = 0; i < intent.events.length; i++) {\n IntentEvent memory intentEvent = intent.events[i];\n emit IntentExecuted(\n intent.user,\n intentEvent.topic,\n uint8(intent.op),\n intent,\n proposal,\n output,\n intentEvent.data\n );\n }\n }\n\n /**\n * @dev Pays fees\n * @param intent Intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param isSmartAccount Whether the intent user is a smart account\n */\n function _payFees(Intent memory intent, Proposal memory proposal, bool isSmartAccount) internal {\n address from = intent.user;\n address to = _msgSender();\n for (uint256 i = 0; i < intent.maxFees.length; i++) {\n address token = intent.maxFees[i].token;\n if (!Denominations.isUSD(token)) _transferFrom(token, from, to, proposal.fees[i], isSmartAccount);\n }\n }\n\n /**\n * @dev Transfers tokens from one account to another\n * @param token Address of the token to transfer\n * @param from Address of the account sending the tokens\n * @param to Address of the account receiving the tokens\n * @param amount Amount of tokens to transfer\n * @param isSmartAccount Whether the sender is a smart account\n */\n function _transferFrom(address token, address from, address to, uint256 amount, bool isSmartAccount) internal {\n if (isSmartAccount) {\n smartAccountsHandler.transfer(from, token, to, amount);\n } else {\n IERC20(token).safeTransferFrom(from, to, amount);\n }\n }\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function _setSmartAccountsHandler(address newSmartAccountsHandler) internal {\n if (newSmartAccountsHandler == address(0)) revert SmartAccountsHandlerZero();\n smartAccountsHandler = newSmartAccountsHandler;\n emit SmartAccountsHandlerSet(newSmartAccountsHandler);\n }\n\n /**\n * @dev Sets the intents validator\n * @param newIntentsValidator New intents validator to be set\n */\n function _setIntentsValidator(address newIntentsValidator) internal {\n intentsValidator = newIntentsValidator;\n emit IntentsValidatorSet(newIntentsValidator);\n }\n\n /**\n * @dev Sets a safeguard for a user\n * @param user Address of the user to set the safeguard for\n * @param safeguard Safeguard to be set\n */\n function _setSafeguard(address user, bytes memory safeguard) internal {\n delete _userSafeguard[user];\n _userSafeguard[user] = safeguard;\n emit SafeguardSet(user);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccount7702.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/Context.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccount.sol';\nimport '../utils/ERC20Helpers.sol';\nimport './SmartAccountBase.sol';\n\n/**\n * @title SmartAccount7702\n * @dev Provides the smart account logic to use with EIP7702\n */\ncontract SmartAccount7702 is SmartAccountBase {\n // Mimic settler reference\n // solhint-disable-next-line immutable-vars-naming\n address public immutable settler;\n\n /**\n * @dev The sender is not the settler\n */\n error SmartAccount7702SenderNotSettler();\n\n /**\n * @dev Reverts unless the sender is the settler\n */\n modifier onlySettler() {\n if (_msgSender() != settler) revert SmartAccount7702SenderNotSettler();\n _;\n }\n\n /**\n * @dev Creates a new SmartAccount7702 contract\n * @param _settler Address of the Mimic settler\n */\n constructor(address _settler) {\n settler = _settler;\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) public override onlySettler {\n super.transfer(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value) public override onlySettler returns (bytes memory) {\n // solhint-disable-next-line avoid-low-level-calls\n return super.call(target, data, value);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountBase.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/Context.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccount.sol';\nimport '../utils/ERC20Helpers.sol';\n\n/**\n * @title SmartAccountBase\n * @dev Provides the base logic for managing assets and executing arbitrary calls\n */\ncontract SmartAccountBase is ISmartAccount, Context, ERC165, ReentrancyGuard {\n /**\n * @dev Tells whether the contract supports the given interface ID. Overrides ERC165 to declare support for ISmartAccount interface.\n * @param interfaceId Interface ID is defined as the XOR of all function selectors in the interface\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {\n return interfaceId == type(ISmartAccount).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) public virtual override nonReentrant {\n ERC20Helpers.transfer(token, recipient, amount);\n emit Transferred(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value)\n public\n virtual\n override\n nonReentrant\n returns (bytes memory result)\n {\n result = Address.functionCallWithValue(target, data, value);\n emit Called(target, data, value, result);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountContract.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/cryptography/ECDSA.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccountContract.sol';\nimport './SmartAccountBase.sol';\n\n/**\n * @title SmartAccountContract\n * @dev Provides the smart account logic to use as a standalone contract\n */\ncontract SmartAccountContract is ISmartAccountContract, Ownable, SmartAccountBase {\n // EIP1271 magic return value\n bytes4 internal constant EIP1271_MAGIC_VALUE = 0x1626ba7e;\n\n // EIP1271 invalid signature return value\n bytes4 internal constant EIP1271_INVALID_SIGNATURE = 0xffffffff;\n\n // List of account permissions\n mapping (address => bool) public isSignerAllowed;\n\n // Mimic settler reference\n address public settler;\n\n /**\n * @dev The settler is zero\n */\n error SmartAccountSettlerZero();\n\n /**\n * @dev The input arrays are not of equal length\n */\n error SmartAccountInputInvalidLength();\n\n /**\n * @dev The sender is not the owner or the settler\n */\n error SmartAccountUnauthorizedSender(address sender);\n\n /**\n * @dev Emitted every time the settler is set\n */\n event SettlerSet(address indexed settler);\n\n /**\n * @dev Emitted every time a signer allowance is set\n */\n event SignerAllowedSet(address indexed account, bool allowed);\n\n /**\n * @dev Reverts unless the sender is the owner or the settler\n */\n modifier onlyOwnerOrSettler() {\n address sender = _msgSender();\n bool isAuthorized = sender == owner() || sender == settler;\n if (!isAuthorized) revert SmartAccountUnauthorizedSender(sender);\n _;\n }\n\n /**\n * @dev Creates a new SmartAccount contract\n * @param _settler Address of the Mimic settler\n * @param _owner Address that will own the contract\n */\n constructor(address _settler, address _owner) Ownable(_owner) {\n _setSettler(_settler);\n }\n\n /**\n * @dev Tells whether the signature provided belongs to an allowed account.\n * @param hash Message signed by the account\n * @param signature Signature provided to be verified\n */\n function isValidSignature(bytes32 hash, bytes memory signature) external view override returns (bytes4) {\n (address signer, , ) = ECDSA.tryRecover(hash, signature);\n if (signer != address(0) && (signer == owner() || isSignerAllowed[signer])) return EIP1271_MAGIC_VALUE;\n return EIP1271_INVALID_SIGNATURE;\n }\n\n /**\n * @dev It allows receiving native token transfers\n */\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n /**\n * @dev Sets the settler. Sender must be the owner.\n * @param newSettler Address of the new settler to be set\n */\n function setSettler(address newSettler) external onlyOwner {\n _setSettler(newSettler);\n }\n\n /**\n * @dev Sets a list of allowed signers. Sender must be the owner.\n * @param accounts List of account addresses\n * @param allowances List of allowed condition per account\n */\n function setAllowedSigners(address[] memory accounts, bool[] memory allowances) external onlyOwner {\n if (accounts.length != allowances.length) revert SmartAccountInputInvalidLength();\n for (uint256 i = 0; i < accounts.length; i++) {\n address account = accounts[i];\n bool allowed = allowances[i];\n isSignerAllowed[account] = allowed;\n emit SignerAllowedSet(account, allowed);\n }\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the owner or the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount)\n public\n override(ISmartAccount, SmartAccountBase)\n onlyOwnerOrSettler\n {\n super.transfer(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the owner or the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value)\n public\n override(ISmartAccount, SmartAccountBase)\n onlyOwnerOrSettler\n returns (bytes memory)\n {\n // solhint-disable-next-line avoid-low-level-calls\n return super.call(target, data, value);\n }\n\n /**\n * @dev Sets the settler\n * @param newSettler Address of the new settler to be set\n */\n function _setSettler(address newSettler) internal {\n if (newSettler == address(0)) revert SmartAccountSettlerZero();\n settler = newSettler;\n emit SettlerSet(newSettler);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountsHandler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport '../interfaces/ISafe.sol';\nimport '../interfaces/ISmartAccount.sol';\nimport '../interfaces/ISmartAccountsHandler.sol';\nimport '../utils/Denominations.sol';\n\ncontract SmartAccountsHandler is ISmartAccountsHandler {\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address account) external view override returns (bool) {\n if (account.code.length == 0) return false;\n if (_isMimicSmartAccount(account)) return true;\n if (_isSafe(account)) return true;\n return false;\n }\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address account, address token, address to, uint256 amount) external override {\n if (_isMimicSmartAccount(account)) return ISmartAccount(account).transfer(token, to, amount);\n if (_isSafe(account)) return _transferSafe(account, token, to, amount);\n revert SmartAccountsHandlerUnsupportedAccount(account);\n }\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address account, address target, bytes memory data, uint256 value)\n external\n override\n returns (bytes memory)\n {\n // solhint-disable-next-line avoid-low-level-calls\n if (_isMimicSmartAccount(account)) return ISmartAccount(account).call(target, data, value);\n if (_isSafe(account)) return _callSafe(account, target, data, value);\n revert SmartAccountsHandlerUnsupportedAccount(account);\n }\n\n /**\n * @dev Performs a transfer from a safe\n */\n function _transferSafe(address account, address token, address to, uint256 amount) internal {\n Denominations.isNativeToken(token)\n ? _callSafe(account, to, new bytes(0), amount)\n : _callSafe(account, token, abi.encodeWithSelector(IERC20.transfer.selector, to, amount), 0);\n }\n\n /**\n * @dev Performs a call from a safe\n */\n function _callSafe(address account, address target, bytes memory data, uint256 value)\n internal\n returns (bytes memory)\n {\n (bool success, bytes memory result) = ISafe(account).execTransactionFromModuleReturnData(\n target,\n value,\n data,\n SafeOperation.Call\n );\n return\n data.length == 0\n ? Address.verifyCallResult(success, result)\n : Address.verifyCallResultFromTarget(target, success, result);\n }\n\n /**\n * @dev Tells whether an account is a Mimic smart account\n * @param account Address of the account being queried\n */\n function _isMimicSmartAccount(address account) internal view returns (bool) {\n try ISmartAccount(account).supportsInterface(type(ISmartAccount).interfaceId) returns (bool ok) {\n return ok;\n } catch {\n return false;\n }\n }\n\n /**\n * @dev Tells whether an account is a Gnosis Safe\n * @param account Address of the account being queried\n */\n function _isSafe(address account) internal view returns (bool) {\n try ISafe(account).getThreshold() returns (uint256) {\n return true;\n } catch {\n return false;\n }\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountsHandlerHelpers.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport '../interfaces/ISmartAccountsHandler.sol';\n\nlibrary SmartAccountsHandlerHelpers {\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address handler, address account) internal view returns (bool) {\n return ISmartAccountsHandler(handler).isSmartAccount(account);\n }\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address handler, address account, address token, address to, uint256 amount) internal {\n Address.functionDelegateCall(\n handler,\n abi.encodeWithSelector(ISmartAccountsHandler.transfer.selector, account, token, to, amount)\n );\n }\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address handler, address account, address target, bytes memory data, uint256 value)\n internal\n returns (bytes memory)\n {\n return\n Address.functionDelegateCall(\n handler,\n abi.encodeWithSelector(ISmartAccountsHandler.call.selector, account, target, data, value)\n );\n }\n}\n" + }, + "project/contracts/test/CallMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\ncontract CallMock {\n event CallReceived(address indexed sender, uint256 value);\n error CallError();\n\n function call() external payable {\n emit CallReceived(msg.sender, msg.value);\n }\n\n function callError() external payable {\n revert CallError();\n }\n}\n" + }, + "project/contracts/test/executors/EmptyExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\n\ncontract EmptyExecutorMock is IExecutor {\n event Executed();\n\n function execute(Intent memory, Proposal memory) external override {\n emit Executed();\n }\n}\n" + }, + "project/contracts/test/executors/MintExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../TokenMock.sol';\nimport '../../interfaces/IExecutor.sol';\n\n/* solhint-disable custom-errors */\n\ncontract MintExecutorMock is IExecutor {\n event Minted();\n\n function execute(Intent memory intent, Proposal memory proposal) external override {\n require(intent.op == uint8(OpType.Swap), 'Invalid intent type');\n\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n (address[] memory tokens, uint256[] memory amounts) = abi.decode(swapProposal.data, (address[], uint256[]));\n\n require(tokens.length == amounts.length, 'Invalid inputs');\n\n for (uint256 i = 0; i < tokens.length; i++) {\n TokenMock(tokens[i]).mint(msg.sender, amounts[i]);\n emit Minted();\n }\n }\n}\n" + }, + "project/contracts/test/executors/ReentrantExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\nimport '../../interfaces/ISettler.sol';\n\ncontract ReentrantExecutorMock is IExecutor {\n // solhint-disable-next-line immutable-vars-naming\n address payable public immutable settler;\n\n constructor(address payable _settler) {\n settler = _settler;\n }\n\n function execute(Intent memory, Proposal memory) external override {\n ISettler(settler).execute(new Execution[](0));\n }\n}\n" + }, + "project/contracts/test/executors/TransferExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\nimport '../../utils/ERC20Helpers.sol';\n\n/* solhint-disable custom-errors */\n\ncontract TransferExecutorMock is IExecutor {\n event Transferred();\n\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n function execute(Intent memory intent, Proposal memory proposal) external override {\n require(intent.op == uint8(OpType.Swap), 'Invalid intent type');\n\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n (address[] memory tokens, uint256[] memory amounts) = abi.decode(swapProposal.data, (address[], uint256[]));\n\n require(tokens.length == amounts.length, 'Invalid inputs');\n\n for (uint256 i = 0; i < tokens.length; i++) {\n ERC20Helpers.transfer(tokens[i], msg.sender, amounts[i]);\n emit Transferred();\n }\n }\n}\n" + }, + "project/contracts/test/smart-accounts/SafeMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/ISafe.sol';\n\ncontract SafeMock is ISafe {\n event ModuleTxExecuted(\n address indexed target,\n bytes data,\n uint256 value,\n SafeOperation operation,\n bool success,\n bytes result\n );\n\n receive() external payable {}\n\n function getThreshold() external pure returns (uint256) {\n return 1;\n }\n\n function execTransactionFromModuleReturnData(address to, uint256 value, bytes memory data, SafeOperation operation)\n external\n returns (bool success, bytes memory result)\n {\n // solhint-disable-next-line avoid-low-level-calls\n (success, result) = to.call{ value: value }(data);\n emit ModuleTxExecuted(to, data, value, operation, success, result);\n }\n}\n" + }, + "project/contracts/test/TokenMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/ERC20.sol';\n\ncontract TokenMock is ERC20 {\n uint8 internal _decimals;\n\n constructor(string memory symbol, uint8 dec) ERC20(symbol, symbol) {\n _decimals = dec;\n }\n\n function mint(address account, uint256 amount) external {\n _mint(account, amount);\n }\n\n function decimals() public view override returns (uint8) {\n return _decimals;\n }\n}\n" + }, + "project/contracts/test/utils/DenominationsMock.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '../../utils/Denominations.sol';\n\n// solhint-disable func-name-mixedcase\n\ncontract DenominationsMock {\n function NATIVE_TOKEN() external pure returns (address) {\n return Denominations.NATIVE_TOKEN;\n }\n\n function USD() external pure returns (address) {\n return Denominations.USD;\n }\n}\n" + }, + "project/contracts/test/utils/ERC20HelpersMock.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '../../utils/ERC20Helpers.sol';\n\ncontract ERC20HelpersMock {\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n function approve(address token, address to, uint256 amount) external {\n ERC20Helpers.approve(token, to, amount);\n }\n\n function transfer(address token, address to, uint256 amount) external {\n ERC20Helpers.transfer(token, to, amount);\n }\n\n function balanceOf(address token, address account) external view returns (uint256) {\n return ERC20Helpers.balanceOf(token, account);\n }\n}\n" + }, + "project/contracts/utils/Denominations.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\n/**\n * @title Denominations\n * @dev Provides a list of ground denominations for those tokens that cannot be represented by an ERC20.\n * For now, the only needed is the native token that could be ETH, MATIC, or other depending on the layer being operated.\n */\nlibrary Denominations {\n address internal constant NATIVE_TOKEN = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;\n\n // Fiat currencies follow https://en.wikipedia.org/wiki/ISO_4217\n address internal constant USD = address(840);\n\n function isUSD(address token) internal pure returns (bool) {\n return token == USD;\n }\n\n function isNativeToken(address token) internal pure returns (bool) {\n return token == NATIVE_TOKEN;\n }\n}\n" + }, + "project/contracts/utils/ERC20Helpers.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport './Denominations.sol';\n\n/**\n * @title ERC20Helpers\n * @dev Provides a list of ERC20 helper methods\n */\nlibrary ERC20Helpers {\n function approve(address token, address to, uint256 amount) internal {\n SafeERC20.forceApprove(IERC20(token), to, amount);\n }\n\n function transfer(address token, address to, uint256 amount) internal {\n if (Denominations.isNativeToken(token)) Address.sendValue(payable(to), amount);\n else SafeERC20.safeTransfer(IERC20(token), to, amount);\n }\n\n function balanceOf(address token, address account) internal view returns (uint256) {\n if (Denominations.isNativeToken(token)) return address(account).balance;\n else return IERC20(token).balanceOf(address(account));\n }\n}\n" + }, + "project/contracts/utils/MimicHelper.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\n/**\n * @title Mimic Helper\n * @dev Collection of helper functions for the Mimic Protocol\n */\ncontract MimicHelper {\n /**\n * @dev Tells the native token balance of an address\n * @param target Address to get native token balance\n */\n function getNativeTokenBalance(address target) external view returns (uint256) {\n return target.balance;\n }\n}\n" + } + } + } +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-10/deployed_addresses.json b/packages/evm/ignition/deployments/chain-10/deployed_addresses.json index a1a41be..e981fe5 100644 --- a/packages/evm/ignition/deployments/chain-10/deployed_addresses.json +++ b/packages/evm/ignition/deployments/chain-10/deployed_addresses.json @@ -2,5 +2,7 @@ "Create3Controller#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", "Create3Controller#Controller": "0x6002825BabC837776A08799404fA55f15DCedA6b", "Create3Settler#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", - "Create3Settler#Settler": "0x609d831C0068844e11eF85a273c7F356212Fd6D1" + "Create3Settler#Settler": "0x609d831C0068844e11eF85a273c7F356212Fd6D1", + "Create3MimicHelper#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", + "Create3MimicHelper#MimicHelper": "0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0" } \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-10/journal.jsonl b/packages/evm/ignition/deployments/chain-10/journal.jsonl index 9022ba2..2f68352 100644 --- a/packages/evm/ignition/deployments/chain-10/journal.jsonl +++ b/packages/evm/ignition/deployments/chain-10/journal.jsonl @@ -17,4 +17,13 @@ {"futureId":"Create3Settler#ICreateX.deployCreate3","hash":"0x23ca9ecc53e496e9b58a497e0f257a62445afaa9b18de5baa072fa0d303283de","networkInteractionId":1,"receipt":{"blockHash":"0x0e3d242add0df9ef33b21e10cfb82d75a8be094e710ceb0060d43f9814cc195d","blockNumber":141612751,"logs":[{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":51,"topics":["0x2feea65dd4e9f9cbd86b74b7734210c59a1b2981b5b137bd0ee3e208200c9067","0x0000000000000000000000001a68cee754105b3f806c92f6f59e3175f0b0fc2c","0xd5d101dbdd8374fa4f730d105879acbe6c9855ed7be06a019574ba923a935d7d"]},{"address":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","data":"0x","logIndex":52,"topics":["0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000003a0ce8115b4913f42c4928d6bc3f554e9a81468b"]},{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":53,"topics":["0x4db17dd5e4732fb6da34a148104a592783ca119a1e7bb8829eba6cbadef0b511","0x000000000000000000000000609d831c0068844e11ef85a273c7f356212fd6d1"]}],"status":"SUCCESS"},"type":"TRANSACTION_CONFIRM"} {"futureId":"Create3Settler#ICreateX.deployCreate3","result":{"type":"SUCCESS"},"type":"CALL_EXECUTION_STATE_COMPLETE"} {"artifactId":"Create3Settler#ICreateX","dependencies":["Create3Settler#ICreateX.deployCreate3","Create3Settler#ICreateX"],"emitterAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","eventIndex":0,"eventName":"ContractCreation","futureId":"Create3Settler#ICreateX.ContractCreation.newContract.0","nameOrIndex":"newContract","result":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","strategy":"basic","strategyConfig":{},"txToReadFrom":"0x23ca9ecc53e496e9b58a497e0f257a62445afaa9b18de5baa072fa0d303283de","type":"READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE"} -{"artifactId":"Create3Settler#Settler","contractAddress":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","contractName":"Settler","dependencies":["Create3Settler#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3Settler#Settler","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} \ No newline at end of file +{"artifactId":"Create3Settler#Settler","contractAddress":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","contractName":"Settler","dependencies":["Create3Settler#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3Settler#Settler","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} +{"artifactId":"Create3MimicHelper#ICreateX","contractAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","contractName":"ICreateX","dependencies":[],"futureId":"Create3MimicHelper#ICreateX","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} +{"args":["0x3a0ce8115b4913f42c4928d6bc3f554e9a81468b000000000000000000000040","0x6080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033"],"artifactId":"Create3MimicHelper#ICreateX","contractAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","dependencies":["Create3MimicHelper#ICreateX"],"from":"0x3a0ce8115b4913f42c4928d6bc3f554e9a81468b","functionName":"deployCreate3","futureId":"Create3MimicHelper#ICreateX.deployCreate3","strategy":"basic","strategyConfig":{},"type":"CALL_EXECUTION_STATE_INITIALIZE","value":{"_kind":"bigint","value":"0"}} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteraction":{"data":"0x9c36a2863a0ce8115b4913f42c4928d6bc3f554e9a81468b000000000000000000000040000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e96080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c00330000000000000000000000000000000000000000000000","id":1,"to":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","type":"ONCHAIN_INTERACTION","value":{"_kind":"bigint","value":"0"}},"type":"NETWORK_INTERACTION_REQUEST"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteractionId":1,"nonce":69,"type":"TRANSACTION_PREPARE_SEND"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteractionId":1,"nonce":69,"transaction":{"fees":{"maxFeePerGas":{"_kind":"bigint","value":"1044104"},"maxPriorityFeePerGas":{"_kind":"bigint","value":"1000000"}},"hash":"0xff23a65f6f902c2dab118459af2815c361a37ee9403c3c0877f7a8d8915fa151"},"type":"TRANSACTION_SEND"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","hash":"0xff23a65f6f902c2dab118459af2815c361a37ee9403c3c0877f7a8d8915fa151","networkInteractionId":1,"receipt":{"blockHash":"0x12d6c8149ac4c77fb94af575933bc2de2d516bd0bf14a3b0aacb398ea98432b6","blockNumber":146927248,"logs":[{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":175,"topics":["0x2feea65dd4e9f9cbd86b74b7734210c59a1b2981b5b137bd0ee3e208200c9067","0x0000000000000000000000009074e2fea6f668ccf7fb884fac62943acc03ea43","0x721f4d59bffa983c2a99dc5a3b93053d035180c65840e4dc318b06bb0484a80f"]},{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":176,"topics":["0x4db17dd5e4732fb6da34a148104a592783ca119a1e7bb8829eba6cbadef0b511","0x0000000000000000000000004766ef65d66e8d2d92f3089ee42e5705e8817ff0"]}],"status":"SUCCESS"},"type":"TRANSACTION_CONFIRM"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","result":{"type":"SUCCESS"},"type":"CALL_EXECUTION_STATE_COMPLETE"} +{"artifactId":"Create3MimicHelper#ICreateX","dependencies":["Create3MimicHelper#ICreateX.deployCreate3","Create3MimicHelper#ICreateX"],"emitterAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","eventIndex":0,"eventName":"ContractCreation","futureId":"Create3MimicHelper#ICreateX.ContractCreation.newContract.0","nameOrIndex":"newContract","result":"0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0","strategy":"basic","strategyConfig":{},"txToReadFrom":"0xff23a65f6f902c2dab118459af2815c361a37ee9403c3c0877f7a8d8915fa151","type":"READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE"} +{"artifactId":"Create3MimicHelper#MimicHelper","contractAddress":"0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0","contractName":"MimicHelper","dependencies":["Create3MimicHelper#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3MimicHelper#MimicHelper","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-100/artifacts/Create3MimicHelper#ICreateX.dbg.json b/packages/evm/ignition/deployments/chain-100/artifacts/Create3MimicHelper#ICreateX.dbg.json new file mode 100644 index 0000000..817dddf --- /dev/null +++ b/packages/evm/ignition/deployments/chain-100/artifacts/Create3MimicHelper#ICreateX.dbg.json @@ -0,0 +1,4 @@ +{ + "_format": "hh-sol-dbg-1", + "buildInfo": "../build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-100/artifacts/Create3MimicHelper#ICreateX.json b/packages/evm/ignition/deployments/chain-100/artifacts/Create3MimicHelper#ICreateX.json new file mode 100644 index 0000000..a4701c6 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-100/artifacts/Create3MimicHelper#ICreateX.json @@ -0,0 +1,51 @@ +{ + "_format": "hh3-artifact-1", + "contractName": "ICreateX", + "sourceName": "contracts/interfaces/ICreateX.sol", + "abi": [ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "newContract", + "type": "address" + } + ], + "name": "ContractCreation", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "salt", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "initCode", + "type": "bytes" + } + ], + "name": "deployCreate3", + "outputs": [ + { + "internalType": "address", + "name": "newContract", + "type": "address" + } + ], + "stateMutability": "payable", + "type": "function" + } + ], + "bytecode": "0x", + "deployedBytecode": "0x", + "linkReferences": {}, + "deployedLinkReferences": {}, + "immutableReferences": {}, + "inputSourceName": "project/contracts/interfaces/ICreateX.sol", + "buildInfoId": "b650d0a8e9df290d290e91b2999a1f7443c2b528" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-100/artifacts/Create3MimicHelper#MimicHelper.dbg.json b/packages/evm/ignition/deployments/chain-100/artifacts/Create3MimicHelper#MimicHelper.dbg.json new file mode 100644 index 0000000..817dddf --- /dev/null +++ b/packages/evm/ignition/deployments/chain-100/artifacts/Create3MimicHelper#MimicHelper.dbg.json @@ -0,0 +1,4 @@ +{ + "_format": "hh-sol-dbg-1", + "buildInfo": "../build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-100/artifacts/Create3MimicHelper#MimicHelper.json b/packages/evm/ignition/deployments/chain-100/artifacts/Create3MimicHelper#MimicHelper.json new file mode 100644 index 0000000..a01b577 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-100/artifacts/Create3MimicHelper#MimicHelper.json @@ -0,0 +1,33 @@ +{ + "_format": "hh3-artifact-1", + "contractName": "MimicHelper", + "sourceName": "contracts/utils/MimicHelper.sol", + "abi": [ + { + "inputs": [ + { + "internalType": "address", + "name": "target", + "type": "address" + } + ], + "name": "getNativeTokenBalance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + } + ], + "bytecode": "0x6080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033", + "deployedBytecode": "0x6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033", + "linkReferences": {}, + "deployedLinkReferences": {}, + "immutableReferences": {}, + "inputSourceName": "project/contracts/utils/MimicHelper.sol", + "buildInfoId": "b650d0a8e9df290d290e91b2999a1f7443c2b528" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-100/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json b/packages/evm/ignition/deployments/chain-100/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json new file mode 100644 index 0000000..657a777 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-100/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json @@ -0,0 +1,290 @@ +{ + "_format": "hh3-sol-build-info-1", + "id": "b650d0a8e9df290d290e91b2999a1f7443c2b528", + "solcVersion": "0.8.28", + "solcLongVersion": "0.8.28+commit.7893614a", + "userSourceNameMap": { + "contracts/Controller.sol": "project/contracts/Controller.sol", + "contracts/Intents.sol": "project/contracts/Intents.sol", + "contracts/Settler.sol": "project/contracts/Settler.sol", + "contracts/interfaces/IController.sol": "project/contracts/interfaces/IController.sol", + "contracts/interfaces/ICreateX.sol": "project/contracts/interfaces/ICreateX.sol", + "contracts/interfaces/IExecutor.sol": "project/contracts/interfaces/IExecutor.sol", + "contracts/interfaces/IIntentsValidator.sol": "project/contracts/interfaces/IIntentsValidator.sol", + "contracts/interfaces/ISafe.sol": "project/contracts/interfaces/ISafe.sol", + "contracts/interfaces/ISettler.sol": "project/contracts/interfaces/ISettler.sol", + "contracts/interfaces/ISmartAccount.sol": "project/contracts/interfaces/ISmartAccount.sol", + "contracts/interfaces/ISmartAccountContract.sol": "project/contracts/interfaces/ISmartAccountContract.sol", + "contracts/interfaces/ISmartAccountsHandler.sol": "project/contracts/interfaces/ISmartAccountsHandler.sol", + "contracts/safeguards/BaseIntentsValidator.sol": "project/contracts/safeguards/BaseIntentsValidator.sol", + "contracts/safeguards/CallIntentsValidator.sol": "project/contracts/safeguards/CallIntentsValidator.sol", + "contracts/safeguards/IntentsValidator.sol": "project/contracts/safeguards/IntentsValidator.sol", + "contracts/safeguards/Safeguards.sol": "project/contracts/safeguards/Safeguards.sol", + "contracts/safeguards/SwapIntentsValidator.sol": "project/contracts/safeguards/SwapIntentsValidator.sol", + "contracts/safeguards/TransferIntentsValidator.sol": "project/contracts/safeguards/TransferIntentsValidator.sol", + "contracts/smart-accounts/SmartAccount7702.sol": "project/contracts/smart-accounts/SmartAccount7702.sol", + "contracts/smart-accounts/SmartAccountBase.sol": "project/contracts/smart-accounts/SmartAccountBase.sol", + "contracts/smart-accounts/SmartAccountContract.sol": "project/contracts/smart-accounts/SmartAccountContract.sol", + "contracts/smart-accounts/SmartAccountsHandler.sol": "project/contracts/smart-accounts/SmartAccountsHandler.sol", + "contracts/smart-accounts/SmartAccountsHandlerHelpers.sol": "project/contracts/smart-accounts/SmartAccountsHandlerHelpers.sol", + "contracts/test/CallMock.sol": "project/contracts/test/CallMock.sol", + "contracts/test/TokenMock.sol": "project/contracts/test/TokenMock.sol", + "contracts/test/executors/EmptyExecutorMock.sol": "project/contracts/test/executors/EmptyExecutorMock.sol", + "contracts/test/executors/MintExecutorMock.sol": "project/contracts/test/executors/MintExecutorMock.sol", + "contracts/test/executors/ReentrantExecutorMock.sol": "project/contracts/test/executors/ReentrantExecutorMock.sol", + "contracts/test/executors/TransferExecutorMock.sol": "project/contracts/test/executors/TransferExecutorMock.sol", + "contracts/test/smart-accounts/SafeMock.sol": "project/contracts/test/smart-accounts/SafeMock.sol", + "contracts/test/utils/DenominationsMock.sol": "project/contracts/test/utils/DenominationsMock.sol", + "contracts/test/utils/ERC20HelpersMock.sol": "project/contracts/test/utils/ERC20HelpersMock.sol", + "contracts/utils/Denominations.sol": "project/contracts/utils/Denominations.sol", + "contracts/utils/ERC20Helpers.sol": "project/contracts/utils/ERC20Helpers.sol", + "contracts/utils/MimicHelper.sol": "project/contracts/utils/MimicHelper.sol" + }, + "input": { + "language": "Solidity", + "settings": { + "optimizer": { + "enabled": true, + "runs": 1000 + }, + "evmVersion": "cancun", + "outputSelection": { + "*": { + "": [ + "ast" + ], + "*": [ + "abi", + "evm.bytecode", + "evm.deployedBytecode", + "evm.methodIdentifiers", + "metadata" + ] + } + }, + "remappings": [ + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/" + ] + }, + "sources": { + "npm/@openzeppelin/contracts@5.3.0/access/Ownable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)\n\npragma solidity ^0.8.20;\n\nimport {Context} from \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * The initial owner is set to the address provided by the deployer. This can\n * later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n /**\n * @dev The caller account is not authorized to perform an operation.\n */\n error OwnableUnauthorizedAccount(address account);\n\n /**\n * @dev The owner is not a valid owner account. (eg. `address(0)`)\n */\n error OwnableInvalidOwner(address owner);\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the address provided by the deployer as the initial owner.\n */\n constructor(address initialOwner) {\n if (initialOwner == address(0)) {\n revert OwnableInvalidOwner(address(0));\n }\n _transferOwnership(initialOwner);\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n if (owner() != _msgSender()) {\n revert OwnableUnauthorizedAccount(_msgSender());\n }\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby disabling any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n if (newOwner == address(0)) {\n revert OwnableInvalidOwner(address(0));\n }\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/draft-IERC6093.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol)\npragma solidity ^0.8.20;\n\n/**\n * @dev Standard ERC-20 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.\n */\ninterface IERC20Errors {\n /**\n * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param balance Current balance for the interacting account.\n * @param needed Minimum amount required to perform a transfer.\n */\n error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC20InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC20InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.\n * @param spender Address that may be allowed to operate on tokens without being their owner.\n * @param allowance Amount of tokens a `spender` is allowed to operate with.\n * @param needed Minimum amount required to perform a transfer.\n */\n error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC20InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `spender` to be approved. Used in approvals.\n * @param spender Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC20InvalidSpender(address spender);\n}\n\n/**\n * @dev Standard ERC-721 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.\n */\ninterface IERC721Errors {\n /**\n * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.\n * Used in balance queries.\n * @param owner Address of the current owner of a token.\n */\n error ERC721InvalidOwner(address owner);\n\n /**\n * @dev Indicates a `tokenId` whose `owner` is the zero address.\n * @param tokenId Identifier number of a token.\n */\n error ERC721NonexistentToken(uint256 tokenId);\n\n /**\n * @dev Indicates an error related to the ownership over a particular token. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param tokenId Identifier number of a token.\n * @param owner Address of the current owner of a token.\n */\n error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC721InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC721InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n * @param tokenId Identifier number of a token.\n */\n error ERC721InsufficientApproval(address operator, uint256 tokenId);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC721InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC721InvalidOperator(address operator);\n}\n\n/**\n * @dev Standard ERC-1155 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.\n */\ninterface IERC1155Errors {\n /**\n * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param balance Current balance for the interacting account.\n * @param needed Minimum amount required to perform a transfer.\n * @param tokenId Identifier number of a token.\n */\n error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC1155InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC1155InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n * @param owner Address of the current owner of a token.\n */\n error ERC1155MissingApprovalForAll(address operator, address owner);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC1155InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC1155InvalidOperator(address operator);\n\n /**\n * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.\n * Used in batch transfers.\n * @param idsLength Length of the array of token identifiers\n * @param valuesLength Length of the array of token amounts\n */\n error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC1271.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (interfaces/IERC1271.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-1271 standard signature validation method for\n * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].\n */\ninterface IERC1271 {\n /**\n * @dev Should return whether the signature provided is valid for the provided data\n * @param hash Hash of the data to be signed\n * @param signature Signature byte array associated with `hash`\n */\n function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC1363.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"./IERC20.sol\";\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @title IERC1363\n * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].\n *\n * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract\n * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.\n */\ninterface IERC1363 is IERC20, IERC165 {\n /*\n * Note: the ERC-165 identifier for this interface is 0xb0202a11.\n * 0xb0202a11 ===\n * bytes4(keccak256('transferAndCall(address,uint256)')) ^\n * bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^\n * bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^\n * bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^\n * bytes4(keccak256('approveAndCall(address,uint256)')) ^\n * bytes4(keccak256('approveAndCall(address,uint256,bytes)'))\n */\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferAndCall(address to, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @param data Additional data with no specified format, sent in call to `to`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param from The address which you want to send tokens from.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferFromAndCall(address from, address to, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param from The address which you want to send tokens from.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @param data Additional data with no specified format, sent in call to `to`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.\n * @param spender The address which will spend the funds.\n * @param value The amount of tokens to be spent.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function approveAndCall(address spender, uint256 value) external returns (bool);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.\n * @param spender The address which will spend the funds.\n * @param value The amount of tokens to be spent.\n * @param data Additional data with no specified format, sent in call to `spender`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"../utils/introspection/IERC165.sol\";\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../token/ERC20/IERC20.sol\";\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC5267.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)\n\npragma solidity ^0.8.20;\n\ninterface IERC5267 {\n /**\n * @dev MAY be emitted to signal that the domain could have changed.\n */\n event EIP712DomainChanged();\n\n /**\n * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712\n * signature.\n */\n function eip712Domain()\n external\n view\n returns (\n bytes1 fields,\n string memory name,\n string memory version,\n uint256 chainId,\n address verifyingContract,\n bytes32 salt,\n uint256[] memory extensions\n );\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/ERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"./IERC20.sol\";\nimport {IERC20Metadata} from \"./extensions/IERC20Metadata.sol\";\nimport {Context} from \"../../utils/Context.sol\";\nimport {IERC20Errors} from \"../../interfaces/draft-IERC6093.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * The default value of {decimals} is 18. To change this, you should override\n * this function so it returns a different value.\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC-20\n * applications.\n */\nabstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {\n mapping(address account => uint256) private _balances;\n\n mapping(address account => mapping(address spender => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * Both values are immutable: they can only be set once during construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the default value returned by this function, unless\n * it's overridden.\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `value`.\n */\n function transfer(address to, uint256 value) public virtual returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, value);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 value) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, value);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Skips emitting an {Approval} event indicating an allowance update. This is not\n * required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `value`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `value`.\n */\n function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, value);\n _transfer(from, to, value);\n return true;\n }\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead.\n */\n function _transfer(address from, address to, uint256 value) internal {\n if (from == address(0)) {\n revert ERC20InvalidSender(address(0));\n }\n if (to == address(0)) {\n revert ERC20InvalidReceiver(address(0));\n }\n _update(from, to, value);\n }\n\n /**\n * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`\n * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding\n * this function.\n *\n * Emits a {Transfer} event.\n */\n function _update(address from, address to, uint256 value) internal virtual {\n if (from == address(0)) {\n // Overflow check required: The rest of the code assumes that totalSupply never overflows\n _totalSupply += value;\n } else {\n uint256 fromBalance = _balances[from];\n if (fromBalance < value) {\n revert ERC20InsufficientBalance(from, fromBalance, value);\n }\n unchecked {\n // Overflow not possible: value <= fromBalance <= totalSupply.\n _balances[from] = fromBalance - value;\n }\n }\n\n if (to == address(0)) {\n unchecked {\n // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.\n _totalSupply -= value;\n }\n } else {\n unchecked {\n // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.\n _balances[to] += value;\n }\n }\n\n emit Transfer(from, to, value);\n }\n\n /**\n * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).\n * Relies on the `_update` mechanism\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead.\n */\n function _mint(address account, uint256 value) internal {\n if (account == address(0)) {\n revert ERC20InvalidReceiver(address(0));\n }\n _update(address(0), account, value);\n }\n\n /**\n * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.\n * Relies on the `_update` mechanism.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead\n */\n function _burn(address account, uint256 value) internal {\n if (account == address(0)) {\n revert ERC20InvalidSender(address(0));\n }\n _update(account, address(0), value);\n }\n\n /**\n * @dev Sets `value` as the allowance of `spender` over the `owner`'s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n *\n * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.\n */\n function _approve(address owner, address spender, uint256 value) internal {\n _approve(owner, spender, value, true);\n }\n\n /**\n * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.\n *\n * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by\n * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any\n * `Approval` event during `transferFrom` operations.\n *\n * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to\n * true using the following override:\n *\n * ```solidity\n * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {\n * super._approve(owner, spender, value, true);\n * }\n * ```\n *\n * Requirements are the same as {_approve}.\n */\n function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {\n if (owner == address(0)) {\n revert ERC20InvalidApprover(address(0));\n }\n if (spender == address(0)) {\n revert ERC20InvalidSpender(address(0));\n }\n _allowances[owner][spender] = value;\n if (emitEvent) {\n emit Approval(owner, spender, value);\n }\n }\n\n /**\n * @dev Updates `owner`'s allowance for `spender` based on spent `value`.\n *\n * Does not update the allowance value in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Does not emit an {Approval} event.\n */\n function _spendAllowance(address owner, address spender, uint256 value) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance < type(uint256).max) {\n if (currentAllowance < value) {\n revert ERC20InsufficientAllowance(spender, currentAllowance, value);\n }\n unchecked {\n _approve(owner, spender, currentAllowance - value, false);\n }\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/extensions/IERC20Metadata.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC-20 standard.\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-20 standard as defined in the ERC.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the value of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the value of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 value) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the\n * allowance mechanism. `value` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(address from, address to, uint256 value) external returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/utils/SafeERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../IERC20.sol\";\nimport {IERC1363} from \"../../../interfaces/IERC1363.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC-20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n /**\n * @dev An operation with an ERC-20 token failed.\n */\n error SafeERC20FailedOperation(address token);\n\n /**\n * @dev Indicates a failed `decreaseAllowance` request.\n */\n error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);\n\n /**\n * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,\n * non-reverting calls are assumed to be successful.\n */\n function safeTransfer(IERC20 token, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));\n }\n\n /**\n * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the\n * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.\n */\n function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));\n }\n\n /**\n * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.\n */\n function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {\n return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));\n }\n\n /**\n * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.\n */\n function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {\n return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));\n }\n\n /**\n * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n * non-reverting calls are assumed to be successful.\n *\n * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the \"client\"\n * smart contract uses ERC-7674 to set temporary allowances, then the \"client\" smart contract should avoid using\n * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract\n * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.\n */\n function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n uint256 oldAllowance = token.allowance(address(this), spender);\n forceApprove(token, spender, oldAllowance + value);\n }\n\n /**\n * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no\n * value, non-reverting calls are assumed to be successful.\n *\n * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the \"client\"\n * smart contract uses ERC-7674 to set temporary allowances, then the \"client\" smart contract should avoid using\n * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract\n * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.\n */\n function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {\n unchecked {\n uint256 currentAllowance = token.allowance(address(this), spender);\n if (currentAllowance < requestedDecrease) {\n revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);\n }\n forceApprove(token, spender, currentAllowance - requestedDecrease);\n }\n }\n\n /**\n * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,\n * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval\n * to be set to zero before setting it to a non-zero value, such as USDT.\n *\n * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function\n * only sets the \"standard\" allowance. Any temporary allowance will remain active, in addition to the value being\n * set here.\n */\n function forceApprove(IERC20 token, address spender, uint256 value) internal {\n bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));\n\n if (!_callOptionalReturnBool(token, approvalCall)) {\n _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));\n _callOptionalReturn(token, approvalCall);\n }\n }\n\n /**\n * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no\n * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * Reverts if the returned value is other than `true`.\n */\n function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {\n if (to.code.length == 0) {\n safeTransfer(token, to, value);\n } else if (!token.transferAndCall(to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target\n * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * Reverts if the returned value is other than `true`.\n */\n function transferFromAndCallRelaxed(\n IERC1363 token,\n address from,\n address to,\n uint256 value,\n bytes memory data\n ) internal {\n if (to.code.length == 0) {\n safeTransferFrom(token, from, to, value);\n } else if (!token.transferFromAndCall(from, to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no\n * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.\n * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}\n * once without retrying, and relies on the returned value to be true.\n *\n * Reverts if the returned value is other than `true`.\n */\n function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {\n if (to.code.length == 0) {\n forceApprove(token, to, value);\n } else if (!token.approveAndCall(to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n *\n * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.\n */\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)\n // bubble errors\n if iszero(success) {\n let ptr := mload(0x40)\n returndatacopy(ptr, 0, returndatasize())\n revert(ptr, returndatasize())\n }\n returnSize := returndatasize()\n returnValue := mload(0)\n }\n\n if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n *\n * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.\n */\n function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {\n bool success;\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)\n returnSize := returndatasize()\n returnValue := mload(0)\n }\n return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Address.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.2.0) (utils/Address.sol)\n\npragma solidity ^0.8.20;\n\nimport {Errors} from \"./Errors.sol\";\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev There's no code at `target` (it is not a contract).\n */\n error AddressEmptyCode(address target);\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n if (address(this).balance < amount) {\n revert Errors.InsufficientBalance(address(this).balance, amount);\n }\n\n (bool success, bytes memory returndata) = recipient.call{value: amount}(\"\");\n if (!success) {\n _revert(returndata);\n }\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason or custom error, it is bubbled\n * up by this function (like regular Solidity function calls). However, if\n * the call reverted with no returned reason, this function reverts with a\n * {Errors.FailedCall} error.\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n */\n function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n if (address(this).balance < value) {\n revert Errors.InsufficientBalance(address(this).balance, value);\n }\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target\n * was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case\n * of an unsuccessful call.\n */\n function verifyCallResultFromTarget(\n address target,\n bool success,\n bytes memory returndata\n ) internal view returns (bytes memory) {\n if (!success) {\n _revert(returndata);\n } else {\n // only check if target is a contract if the call was successful and the return data is empty\n // otherwise we already know that it was a contract\n if (returndata.length == 0 && target.code.length == 0) {\n revert AddressEmptyCode(target);\n }\n return returndata;\n }\n }\n\n /**\n * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the\n * revert reason or with a default {Errors.FailedCall} error.\n */\n function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {\n if (!success) {\n _revert(returndata);\n } else {\n return returndata;\n }\n }\n\n /**\n * @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.\n */\n function _revert(bytes memory returndata) private pure {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n assembly (\"memory-safe\") {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert Errors.FailedCall();\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Context.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n\n function _contextSuffixLength() internal view virtual returns (uint256) {\n return 0;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/ECDSA.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/ECDSA.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.\n *\n * These functions can be used to verify that a message was signed by the holder\n * of the private keys of a given address.\n */\nlibrary ECDSA {\n enum RecoverError {\n NoError,\n InvalidSignature,\n InvalidSignatureLength,\n InvalidSignatureS\n }\n\n /**\n * @dev The signature derives the `address(0)`.\n */\n error ECDSAInvalidSignature();\n\n /**\n * @dev The signature has an invalid length.\n */\n error ECDSAInvalidSignatureLength(uint256 length);\n\n /**\n * @dev The signature has an S value that is in the upper half order.\n */\n error ECDSAInvalidSignatureS(bytes32 s);\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not\n * return address(0) without also returning an error description. Errors are documented using an enum (error type)\n * and a bytes32 providing additional information about the error.\n *\n * If no error is returned, then the address can be used for verification purposes.\n *\n * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.\n *\n * Documentation for signature generation:\n * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]\n * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]\n */\n function tryRecover(\n bytes32 hash,\n bytes memory signature\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n if (signature.length == 65) {\n bytes32 r;\n bytes32 s;\n uint8 v;\n // ecrecover takes the signature parameters, and the only way to get them\n // currently is to use assembly.\n assembly (\"memory-safe\") {\n r := mload(add(signature, 0x20))\n s := mload(add(signature, 0x40))\n v := byte(0, mload(add(signature, 0x60)))\n }\n return tryRecover(hash, v, r, s);\n } else {\n return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));\n }\n }\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with\n * `signature`. This address can then be used for verification purposes.\n *\n * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.\n */\n function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.\n *\n * See https://eips.ethereum.org/EIPS/eip-2098[ERC-2098 short signatures]\n */\n function tryRecover(\n bytes32 hash,\n bytes32 r,\n bytes32 vs\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n unchecked {\n bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n // We do not check for an overflow here since the shift operation results in 0 or 1.\n uint8 v = uint8((uint256(vs) >> 255) + 27);\n return tryRecover(hash, v, r, s);\n }\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\n */\n function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function tryRecover(\n bytes32 hash,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\n // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\n // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\n // signatures from current libraries generate a unique signature with an s-value in the lower half order.\n //\n // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\n // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\n // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\n // these malleable signatures as well.\n if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\n return (address(0), RecoverError.InvalidSignatureS, s);\n }\n\n // If the signature is valid (and not malleable), return the signer address\n address signer = ecrecover(hash, v, r, s);\n if (signer == address(0)) {\n return (address(0), RecoverError.InvalidSignature, bytes32(0));\n }\n\n return (signer, RecoverError.NoError, bytes32(0));\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.\n */\n function _throwError(RecoverError error, bytes32 errorArg) private pure {\n if (error == RecoverError.NoError) {\n return; // no error: do nothing\n } else if (error == RecoverError.InvalidSignature) {\n revert ECDSAInvalidSignature();\n } else if (error == RecoverError.InvalidSignatureLength) {\n revert ECDSAInvalidSignatureLength(uint256(errorArg));\n } else if (error == RecoverError.InvalidSignatureS) {\n revert ECDSAInvalidSignatureS(errorArg);\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/EIP712.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/EIP712.sol)\n\npragma solidity ^0.8.20;\n\nimport {MessageHashUtils} from \"./MessageHashUtils.sol\";\nimport {ShortStrings, ShortString} from \"../ShortStrings.sol\";\nimport {IERC5267} from \"../../interfaces/IERC5267.sol\";\n\n/**\n * @dev https://eips.ethereum.org/EIPS/eip-712[EIP-712] is a standard for hashing and signing of typed structured data.\n *\n * The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose\n * encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract\n * does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to\n * produce the hash of their typed data using a combination of `abi.encode` and `keccak256`.\n *\n * This contract implements the EIP-712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding\n * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA\n * ({_hashTypedDataV4}).\n *\n * The implementation of the domain separator was designed to be as efficient as possible while still properly updating\n * the chain id to protect against replay attacks on an eventual fork of the chain.\n *\n * NOTE: This contract implements the version of the encoding known as \"v4\", as implemented by the JSON RPC method\n * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].\n *\n * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain\n * separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the\n * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.\n *\n * @custom:oz-upgrades-unsafe-allow state-variable-immutable\n */\nabstract contract EIP712 is IERC5267 {\n using ShortStrings for *;\n\n bytes32 private constant TYPE_HASH =\n keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\");\n\n // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to\n // invalidate the cached domain separator if the chain id changes.\n bytes32 private immutable _cachedDomainSeparator;\n uint256 private immutable _cachedChainId;\n address private immutable _cachedThis;\n\n bytes32 private immutable _hashedName;\n bytes32 private immutable _hashedVersion;\n\n ShortString private immutable _name;\n ShortString private immutable _version;\n // slither-disable-next-line constable-states\n string private _nameFallback;\n // slither-disable-next-line constable-states\n string private _versionFallback;\n\n /**\n * @dev Initializes the domain separator and parameter caches.\n *\n * The meaning of `name` and `version` is specified in\n * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP-712]:\n *\n * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.\n * - `version`: the current major version of the signing domain.\n *\n * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart\n * contract upgrade].\n */\n constructor(string memory name, string memory version) {\n _name = name.toShortStringWithFallback(_nameFallback);\n _version = version.toShortStringWithFallback(_versionFallback);\n _hashedName = keccak256(bytes(name));\n _hashedVersion = keccak256(bytes(version));\n\n _cachedChainId = block.chainid;\n _cachedDomainSeparator = _buildDomainSeparator();\n _cachedThis = address(this);\n }\n\n /**\n * @dev Returns the domain separator for the current chain.\n */\n function _domainSeparatorV4() internal view returns (bytes32) {\n if (address(this) == _cachedThis && block.chainid == _cachedChainId) {\n return _cachedDomainSeparator;\n } else {\n return _buildDomainSeparator();\n }\n }\n\n function _buildDomainSeparator() private view returns (bytes32) {\n return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));\n }\n\n /**\n * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this\n * function returns the hash of the fully encoded EIP712 message for this domain.\n *\n * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:\n *\n * ```solidity\n * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(\n * keccak256(\"Mail(address to,string contents)\"),\n * mailTo,\n * keccak256(bytes(mailContents))\n * )));\n * address signer = ECDSA.recover(digest, signature);\n * ```\n */\n function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {\n return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);\n }\n\n /**\n * @inheritdoc IERC5267\n */\n function eip712Domain()\n public\n view\n virtual\n returns (\n bytes1 fields,\n string memory name,\n string memory version,\n uint256 chainId,\n address verifyingContract,\n bytes32 salt,\n uint256[] memory extensions\n )\n {\n return (\n hex\"0f\", // 01111\n _EIP712Name(),\n _EIP712Version(),\n block.chainid,\n address(this),\n bytes32(0),\n new uint256[](0)\n );\n }\n\n /**\n * @dev The name parameter for the EIP712 domain.\n *\n * NOTE: By default this function reads _name which is an immutable value.\n * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).\n */\n // solhint-disable-next-line func-name-mixedcase\n function _EIP712Name() internal view returns (string memory) {\n return _name.toStringWithFallback(_nameFallback);\n }\n\n /**\n * @dev The version parameter for the EIP712 domain.\n *\n * NOTE: By default this function reads _version which is an immutable value.\n * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).\n */\n // solhint-disable-next-line func-name-mixedcase\n function _EIP712Version() internal view returns (string memory) {\n return _version.toStringWithFallback(_versionFallback);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/MessageHashUtils.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/MessageHashUtils.sol)\n\npragma solidity ^0.8.20;\n\nimport {Strings} from \"../Strings.sol\";\n\n/**\n * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.\n *\n * The library provides methods for generating a hash of a message that conforms to the\n * https://eips.ethereum.org/EIPS/eip-191[ERC-191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]\n * specifications.\n */\nlibrary MessageHashUtils {\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x45` (`personal_sign` messages).\n *\n * The digest is calculated by prefixing a bytes32 `messageHash` with\n * `\"\\x19Ethereum Signed Message:\\n32\"` and hashing the result. It corresponds with the\n * hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.\n *\n * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with\n * keccak256, although any bytes32 value can be safely used because the final digest will\n * be re-hashed.\n *\n * See {ECDSA-recover}.\n */\n function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n mstore(0x00, \"\\x19Ethereum Signed Message:\\n32\") // 32 is the bytes-length of messageHash\n mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix\n digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)\n }\n }\n\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x45` (`personal_sign` messages).\n *\n * The digest is calculated by prefixing an arbitrary `message` with\n * `\"\\x19Ethereum Signed Message:\\n\" + len(message)` and hashing the result. It corresponds with the\n * hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.\n *\n * See {ECDSA-recover}.\n */\n function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {\n return\n keccak256(bytes.concat(\"\\x19Ethereum Signed Message:\\n\", bytes(Strings.toString(message.length)), message));\n }\n\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x00` (data with intended validator).\n *\n * The digest is calculated by prefixing an arbitrary `data` with `\"\\x19\\x00\"` and the intended\n * `validator` address. Then hashing the result.\n *\n * See {ECDSA-recover}.\n */\n function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(hex\"19_00\", validator, data));\n }\n\n /**\n * @dev Variant of {toDataWithIntendedValidatorHash-address-bytes} optimized for cases where `data` is a bytes32.\n */\n function toDataWithIntendedValidatorHash(\n address validator,\n bytes32 messageHash\n ) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n mstore(0x00, hex\"19_00\")\n mstore(0x02, shl(96, validator))\n mstore(0x16, messageHash)\n digest := keccak256(0x00, 0x36)\n }\n }\n\n /**\n * @dev Returns the keccak256 digest of an EIP-712 typed data (ERC-191 version `0x01`).\n *\n * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with\n * `\\x19\\x01` and hashing the result. It corresponds to the hash signed by the\n * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.\n *\n * See {ECDSA-recover}.\n */\n function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n let ptr := mload(0x40)\n mstore(ptr, hex\"19_01\")\n mstore(add(ptr, 0x02), domainSeparator)\n mstore(add(ptr, 0x22), structHash)\n digest := keccak256(ptr, 0x42)\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Errors.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Collection of common custom errors used in multiple contracts\n *\n * IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.\n * It is recommended to avoid relying on the error API for critical functionality.\n *\n * _Available since v5.1._\n */\nlibrary Errors {\n /**\n * @dev The ETH balance of the account is not enough to perform the operation.\n */\n error InsufficientBalance(uint256 balance, uint256 needed);\n\n /**\n * @dev A call to an address target failed. The target may have reverted.\n */\n error FailedCall();\n\n /**\n * @dev The deployment failed.\n */\n error FailedDeployment();\n\n /**\n * @dev A necessary precompile is missing.\n */\n error MissingPrecompile(address);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/ERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/ERC165Checker.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165Checker.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @dev Library used to query support of an interface declared via {IERC165}.\n *\n * Note that these functions return the actual result of the query: they do not\n * `revert` if an interface is not supported. It is up to the caller to decide\n * what to do in these cases.\n */\nlibrary ERC165Checker {\n // As per the ERC-165 spec, no interface should ever match 0xffffffff\n bytes4 private constant INTERFACE_ID_INVALID = 0xffffffff;\n\n /**\n * @dev Returns true if `account` supports the {IERC165} interface.\n */\n function supportsERC165(address account) internal view returns (bool) {\n // Any contract that implements ERC-165 must explicitly indicate support of\n // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid\n return\n supportsERC165InterfaceUnchecked(account, type(IERC165).interfaceId) &&\n !supportsERC165InterfaceUnchecked(account, INTERFACE_ID_INVALID);\n }\n\n /**\n * @dev Returns true if `account` supports the interface defined by\n * `interfaceId`. Support for {IERC165} itself is queried automatically.\n *\n * See {IERC165-supportsInterface}.\n */\n function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {\n // query support of both ERC-165 as per the spec and support of _interfaceId\n return supportsERC165(account) && supportsERC165InterfaceUnchecked(account, interfaceId);\n }\n\n /**\n * @dev Returns a boolean array where each value corresponds to the\n * interfaces passed in and whether they're supported or not. This allows\n * you to batch check interfaces for a contract where your expectation\n * is that some interfaces may not be supported.\n *\n * See {IERC165-supportsInterface}.\n */\n function getSupportedInterfaces(\n address account,\n bytes4[] memory interfaceIds\n ) internal view returns (bool[] memory) {\n // an array of booleans corresponding to interfaceIds and whether they're supported or not\n bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length);\n\n // query support of ERC-165 itself\n if (supportsERC165(account)) {\n // query support of each interface in interfaceIds\n for (uint256 i = 0; i < interfaceIds.length; i++) {\n interfaceIdsSupported[i] = supportsERC165InterfaceUnchecked(account, interfaceIds[i]);\n }\n }\n\n return interfaceIdsSupported;\n }\n\n /**\n * @dev Returns true if `account` supports all the interfaces defined in\n * `interfaceIds`. Support for {IERC165} itself is queried automatically.\n *\n * Batch-querying can lead to gas savings by skipping repeated checks for\n * {IERC165} support.\n *\n * See {IERC165-supportsInterface}.\n */\n function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {\n // query support of ERC-165 itself\n if (!supportsERC165(account)) {\n return false;\n }\n\n // query support of each interface in interfaceIds\n for (uint256 i = 0; i < interfaceIds.length; i++) {\n if (!supportsERC165InterfaceUnchecked(account, interfaceIds[i])) {\n return false;\n }\n }\n\n // all interfaces supported\n return true;\n }\n\n /**\n * @notice Query if a contract implements an interface, does not check ERC-165 support\n * @param account The address of the contract to query for support of an interface\n * @param interfaceId The interface identifier, as specified in ERC-165\n * @return true if the contract at account indicates support of the interface with\n * identifier interfaceId, false otherwise\n * @dev Assumes that account contains a contract that supports ERC-165, otherwise\n * the behavior of this method is undefined. This precondition can be checked\n * with {supportsERC165}.\n *\n * Some precompiled contracts will falsely indicate support for a given interface, so caution\n * should be exercised when using this function.\n *\n * Interface identification is specified in ERC-165.\n */\n function supportsERC165InterfaceUnchecked(address account, bytes4 interfaceId) internal view returns (bool) {\n // prepare call\n bytes memory encodedParams = abi.encodeCall(IERC165.supportsInterface, (interfaceId));\n\n // perform static call\n bool success;\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n success := staticcall(30000, account, add(encodedParams, 0x20), mload(encodedParams), 0x00, 0x20)\n returnSize := returndatasize()\n returnValue := mload(0x00)\n }\n\n return success && returnSize >= 0x20 && returnValue > 0;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/IERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[ERC].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/Math.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.20;\n\nimport {Panic} from \"../Panic.sol\";\nimport {SafeCast} from \"./SafeCast.sol\";\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n enum Rounding {\n Floor, // Toward negative infinity\n Ceil, // Toward positive infinity\n Trunc, // Toward zero\n Expand // Away from zero\n }\n\n /**\n * @dev Return the 512-bit addition of two uint256.\n *\n * The result is stored in two 256 variables such that sum = high * 2²⁵⁶ + low.\n */\n function add512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {\n assembly (\"memory-safe\") {\n low := add(a, b)\n high := lt(low, a)\n }\n }\n\n /**\n * @dev Return the 512-bit multiplication of two uint256.\n *\n * The result is stored in two 256 variables such that product = high * 2²⁵⁶ + low.\n */\n function mul512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {\n // 512-bit multiply [high low] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use\n // the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n // variables such that product = high * 2²⁵⁶ + low.\n assembly (\"memory-safe\") {\n let mm := mulmod(a, b, not(0))\n low := mul(a, b)\n high := sub(sub(mm, low), lt(mm, low))\n }\n }\n\n /**\n * @dev Returns the addition of two unsigned integers, with a success flag (no overflow).\n */\n function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a + b;\n success = c >= a;\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, with a success flag (no overflow).\n */\n function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a - b;\n success = c <= a;\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, with a success flag (no overflow).\n */\n function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a * b;\n assembly (\"memory-safe\") {\n // Only true when the multiplication doesn't overflow\n // (c / a == b) || (a == 0)\n success := or(eq(div(c, a), b), iszero(a))\n }\n // equivalent to: success ? c : 0\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the division of two unsigned integers, with a success flag (no division by zero).\n */\n function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n success = b > 0;\n assembly (\"memory-safe\") {\n // The `DIV` opcode returns zero when the denominator is 0.\n result := div(a, b)\n }\n }\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).\n */\n function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n success = b > 0;\n assembly (\"memory-safe\") {\n // The `MOD` opcode returns zero when the denominator is 0.\n result := mod(a, b)\n }\n }\n }\n\n /**\n * @dev Unsigned saturating addition, bounds to `2²⁵⁶ - 1` instead of overflowing.\n */\n function saturatingAdd(uint256 a, uint256 b) internal pure returns (uint256) {\n (bool success, uint256 result) = tryAdd(a, b);\n return ternary(success, result, type(uint256).max);\n }\n\n /**\n * @dev Unsigned saturating subtraction, bounds to zero instead of overflowing.\n */\n function saturatingSub(uint256 a, uint256 b) internal pure returns (uint256) {\n (, uint256 result) = trySub(a, b);\n return result;\n }\n\n /**\n * @dev Unsigned saturating multiplication, bounds to `2²⁵⁶ - 1` instead of overflowing.\n */\n function saturatingMul(uint256 a, uint256 b) internal pure returns (uint256) {\n (bool success, uint256 result) = tryMul(a, b);\n return ternary(success, result, type(uint256).max);\n }\n\n /**\n * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.\n *\n * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.\n * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute\n * one branch when needed, making this function more expensive.\n */\n function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {\n unchecked {\n // branchless ternary works because:\n // b ^ (a ^ b) == a\n // b ^ 0 == b\n return b ^ ((a ^ b) * SafeCast.toUint(condition));\n }\n }\n\n /**\n * @dev Returns the largest of two numbers.\n */\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\n return ternary(a > b, a, b);\n }\n\n /**\n * @dev Returns the smallest of two numbers.\n */\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\n return ternary(a < b, a, b);\n }\n\n /**\n * @dev Returns the average of two numbers. The result is rounded towards\n * zero.\n */\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b) / 2 can overflow.\n return (a & b) + (a ^ b) / 2;\n }\n\n /**\n * @dev Returns the ceiling of the division of two numbers.\n *\n * This differs from standard division with `/` in that it rounds towards infinity instead\n * of rounding towards zero.\n */\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n if (b == 0) {\n // Guarantee the same behavior as in a regular Solidity division.\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n\n // The following calculation ensures accurate ceiling division without overflow.\n // Since a is non-zero, (a - 1) / b will not overflow.\n // The largest possible result occurs when (a - 1) / b is type(uint256).max,\n // but the largest value we can obtain is type(uint256).max - 1, which happens\n // when a = type(uint256).max and b = 1.\n unchecked {\n return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);\n }\n }\n\n /**\n * @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or\n * denominator == 0.\n *\n * Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by\n * Uniswap Labs also under MIT license.\n */\n function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {\n unchecked {\n (uint256 high, uint256 low) = mul512(x, y);\n\n // Handle non-overflow cases, 256 by 256 division.\n if (high == 0) {\n // Solidity will revert if denominator == 0, unlike the div opcode on its own.\n // The surrounding unchecked block does not change this fact.\n // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.\n return low / denominator;\n }\n\n // Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.\n if (denominator <= high) {\n Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));\n }\n\n ///////////////////////////////////////////////\n // 512 by 256 division.\n ///////////////////////////////////////////////\n\n // Make division exact by subtracting the remainder from [high low].\n uint256 remainder;\n assembly (\"memory-safe\") {\n // Compute remainder using mulmod.\n remainder := mulmod(x, y, denominator)\n\n // Subtract 256 bit number from 512 bit number.\n high := sub(high, gt(remainder, low))\n low := sub(low, remainder)\n }\n\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator.\n // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.\n\n uint256 twos = denominator & (0 - denominator);\n assembly (\"memory-safe\") {\n // Divide denominator by twos.\n denominator := div(denominator, twos)\n\n // Divide [high low] by twos.\n low := div(low, twos)\n\n // Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.\n twos := add(div(sub(0, twos), twos), 1)\n }\n\n // Shift in bits from high into low.\n low |= high * twos;\n\n // Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such\n // that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for\n // four bits. That is, denominator * inv ≡ 1 mod 2⁴.\n uint256 inverse = (3 * denominator) ^ 2;\n\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also\n // works in modular arithmetic, doubling the correct bits in each step.\n inverse *= 2 - denominator * inverse; // inverse mod 2⁸\n inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶\n inverse *= 2 - denominator * inverse; // inverse mod 2³²\n inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴\n inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸\n inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶\n\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n // This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is\n // less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and high\n // is no longer required.\n result = low * inverse;\n return result;\n }\n }\n\n /**\n * @dev Calculates x * y / denominator with full precision, following the selected rounding direction.\n */\n function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {\n return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);\n }\n\n /**\n * @dev Calculates floor(x * y >> n) with full precision. Throws if result overflows a uint256.\n */\n function mulShr(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 result) {\n unchecked {\n (uint256 high, uint256 low) = mul512(x, y);\n if (high >= 1 << n) {\n Panic.panic(Panic.UNDER_OVERFLOW);\n }\n return (high << (256 - n)) | (low >> n);\n }\n }\n\n /**\n * @dev Calculates x * y >> n with full precision, following the selected rounding direction.\n */\n function mulShr(uint256 x, uint256 y, uint8 n, Rounding rounding) internal pure returns (uint256) {\n return mulShr(x, y, n) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, 1 << n) > 0);\n }\n\n /**\n * @dev Calculate the modular multiplicative inverse of a number in Z/nZ.\n *\n * If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.\n * If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.\n *\n * If the input value is not inversible, 0 is returned.\n *\n * NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the\n * inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.\n */\n function invMod(uint256 a, uint256 n) internal pure returns (uint256) {\n unchecked {\n if (n == 0) return 0;\n\n // The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)\n // Used to compute integers x and y such that: ax + ny = gcd(a, n).\n // When the gcd is 1, then the inverse of a modulo n exists and it's x.\n // ax + ny = 1\n // ax = 1 + (-y)n\n // ax ≡ 1 (mod n) # x is the inverse of a modulo n\n\n // If the remainder is 0 the gcd is n right away.\n uint256 remainder = a % n;\n uint256 gcd = n;\n\n // Therefore the initial coefficients are:\n // ax + ny = gcd(a, n) = n\n // 0a + 1n = n\n int256 x = 0;\n int256 y = 1;\n\n while (remainder != 0) {\n uint256 quotient = gcd / remainder;\n\n (gcd, remainder) = (\n // The old remainder is the next gcd to try.\n remainder,\n // Compute the next remainder.\n // Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd\n // where gcd is at most n (capped to type(uint256).max)\n gcd - remainder * quotient\n );\n\n (x, y) = (\n // Increment the coefficient of a.\n y,\n // Decrement the coefficient of n.\n // Can overflow, but the result is casted to uint256 so that the\n // next value of y is \"wrapped around\" to a value between 0 and n - 1.\n x - y * int256(quotient)\n );\n }\n\n if (gcd != 1) return 0; // No inverse exists.\n return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.\n }\n }\n\n /**\n * @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.\n *\n * From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is\n * prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that\n * `a**(p-2)` is the modular multiplicative inverse of a in Fp.\n *\n * NOTE: this function does NOT check that `p` is a prime greater than `2`.\n */\n function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {\n unchecked {\n return Math.modExp(a, p - 2, p);\n }\n }\n\n /**\n * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)\n *\n * Requirements:\n * - modulus can't be zero\n * - underlying staticcall to precompile must succeed\n *\n * IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make\n * sure the chain you're using it on supports the precompiled contract for modular exponentiation\n * at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,\n * the underlying function will succeed given the lack of a revert, but the result may be incorrectly\n * interpreted as 0.\n */\n function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {\n (bool success, uint256 result) = tryModExp(b, e, m);\n if (!success) {\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n return result;\n }\n\n /**\n * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).\n * It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying\n * to operate modulo 0 or if the underlying precompile reverted.\n *\n * IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain\n * you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in\n * https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack\n * of a revert, but the result may be incorrectly interpreted as 0.\n */\n function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {\n if (m == 0) return (false, 0);\n assembly (\"memory-safe\") {\n let ptr := mload(0x40)\n // | Offset | Content | Content (Hex) |\n // |-----------|------------|--------------------------------------------------------------------|\n // | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x60:0x7f | value of b | 0x<.............................................................b> |\n // | 0x80:0x9f | value of e | 0x<.............................................................e> |\n // | 0xa0:0xbf | value of m | 0x<.............................................................m> |\n mstore(ptr, 0x20)\n mstore(add(ptr, 0x20), 0x20)\n mstore(add(ptr, 0x40), 0x20)\n mstore(add(ptr, 0x60), b)\n mstore(add(ptr, 0x80), e)\n mstore(add(ptr, 0xa0), m)\n\n // Given the result < m, it's guaranteed to fit in 32 bytes,\n // so we can use the memory scratch space located at offset 0.\n success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)\n result := mload(0x00)\n }\n }\n\n /**\n * @dev Variant of {modExp} that supports inputs of arbitrary length.\n */\n function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {\n (bool success, bytes memory result) = tryModExp(b, e, m);\n if (!success) {\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n return result;\n }\n\n /**\n * @dev Variant of {tryModExp} that supports inputs of arbitrary length.\n */\n function tryModExp(\n bytes memory b,\n bytes memory e,\n bytes memory m\n ) internal view returns (bool success, bytes memory result) {\n if (_zeroBytes(m)) return (false, new bytes(0));\n\n uint256 mLen = m.length;\n\n // Encode call args in result and move the free memory pointer\n result = abi.encodePacked(b.length, e.length, mLen, b, e, m);\n\n assembly (\"memory-safe\") {\n let dataPtr := add(result, 0x20)\n // Write result on top of args to avoid allocating extra memory.\n success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)\n // Overwrite the length.\n // result.length > returndatasize() is guaranteed because returndatasize() == m.length\n mstore(result, mLen)\n // Set the memory pointer after the returned data.\n mstore(0x40, add(dataPtr, mLen))\n }\n }\n\n /**\n * @dev Returns whether the provided byte array is zero.\n */\n function _zeroBytes(bytes memory byteArray) private pure returns (bool) {\n for (uint256 i = 0; i < byteArray.length; ++i) {\n if (byteArray[i] != 0) {\n return false;\n }\n }\n return true;\n }\n\n /**\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded\n * towards zero.\n *\n * This method is based on Newton's method for computing square roots; the algorithm is restricted to only\n * using integer operations.\n */\n function sqrt(uint256 a) internal pure returns (uint256) {\n unchecked {\n // Take care of easy edge cases when a == 0 or a == 1\n if (a <= 1) {\n return a;\n }\n\n // In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a\n // sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between\n // the current value as `ε_n = | x_n - sqrt(a) |`.\n //\n // For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root\n // of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is\n // bigger than any uint256.\n //\n // By noticing that\n // `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`\n // we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar\n // to the msb function.\n uint256 aa = a;\n uint256 xn = 1;\n\n if (aa >= (1 << 128)) {\n aa >>= 128;\n xn <<= 64;\n }\n if (aa >= (1 << 64)) {\n aa >>= 64;\n xn <<= 32;\n }\n if (aa >= (1 << 32)) {\n aa >>= 32;\n xn <<= 16;\n }\n if (aa >= (1 << 16)) {\n aa >>= 16;\n xn <<= 8;\n }\n if (aa >= (1 << 8)) {\n aa >>= 8;\n xn <<= 4;\n }\n if (aa >= (1 << 4)) {\n aa >>= 4;\n xn <<= 2;\n }\n if (aa >= (1 << 2)) {\n xn <<= 1;\n }\n\n // We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).\n //\n // We can refine our estimation by noticing that the middle of that interval minimizes the error.\n // If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).\n // This is going to be our x_0 (and ε_0)\n xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)\n\n // From here, Newton's method give us:\n // x_{n+1} = (x_n + a / x_n) / 2\n //\n // One should note that:\n // x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a\n // = ((x_n² + a) / (2 * x_n))² - a\n // = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a\n // = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)\n // = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)\n // = (x_n² - a)² / (2 * x_n)²\n // = ((x_n² - a) / (2 * x_n))²\n // ≥ 0\n // Which proves that for all n ≥ 1, sqrt(a) ≤ x_n\n //\n // This gives us the proof of quadratic convergence of the sequence:\n // ε_{n+1} = | x_{n+1} - sqrt(a) |\n // = | (x_n + a / x_n) / 2 - sqrt(a) |\n // = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |\n // = | (x_n - sqrt(a))² / (2 * x_n) |\n // = | ε_n² / (2 * x_n) |\n // = ε_n² / | (2 * x_n) |\n //\n // For the first iteration, we have a special case where x_0 is known:\n // ε_1 = ε_0² / | (2 * x_0) |\n // ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))\n // ≤ 2**(2*e-4) / (3 * 2**(e-1))\n // ≤ 2**(e-3) / 3\n // ≤ 2**(e-3-log2(3))\n // ≤ 2**(e-4.5)\n //\n // For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:\n // ε_{n+1} = ε_n² / | (2 * x_n) |\n // ≤ (2**(e-k))² / (2 * 2**(e-1))\n // ≤ 2**(2*e-2*k) / 2**e\n // ≤ 2**(e-2*k)\n xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above\n xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5\n xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9\n xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18\n xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36\n xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72\n\n // Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision\n // ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either\n // sqrt(a) or sqrt(a) + 1.\n return xn - SafeCast.toUint(xn > a / xn);\n }\n }\n\n /**\n * @dev Calculates sqrt(a), following the selected rounding direction.\n */\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = sqrt(a);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);\n }\n }\n\n /**\n * @dev Return the log in base 2 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n */\n function log2(uint256 x) internal pure returns (uint256 r) {\n // If value has upper 128 bits set, log2 result is at least 128\n r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;\n // If upper 64 bits of 128-bit half set, add 64 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;\n // If upper 32 bits of 64-bit half set, add 32 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;\n // If upper 16 bits of 32-bit half set, add 16 to result\n r |= SafeCast.toUint((x >> r) > 0xffff) << 4;\n // If upper 8 bits of 16-bit half set, add 8 to result\n r |= SafeCast.toUint((x >> r) > 0xff) << 3;\n // If upper 4 bits of 8-bit half set, add 4 to result\n r |= SafeCast.toUint((x >> r) > 0xf) << 2;\n\n // Shifts value right by the current result and use it as an index into this lookup table:\n //\n // | x (4 bits) | index | table[index] = MSB position |\n // |------------|---------|-----------------------------|\n // | 0000 | 0 | table[0] = 0 |\n // | 0001 | 1 | table[1] = 0 |\n // | 0010 | 2 | table[2] = 1 |\n // | 0011 | 3 | table[3] = 1 |\n // | 0100 | 4 | table[4] = 2 |\n // | 0101 | 5 | table[5] = 2 |\n // | 0110 | 6 | table[6] = 2 |\n // | 0111 | 7 | table[7] = 2 |\n // | 1000 | 8 | table[8] = 3 |\n // | 1001 | 9 | table[9] = 3 |\n // | 1010 | 10 | table[10] = 3 |\n // | 1011 | 11 | table[11] = 3 |\n // | 1100 | 12 | table[12] = 3 |\n // | 1101 | 13 | table[13] = 3 |\n // | 1110 | 14 | table[14] = 3 |\n // | 1111 | 15 | table[15] = 3 |\n //\n // The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes.\n assembly (\"memory-safe\") {\n r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000))\n }\n }\n\n /**\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log2(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);\n }\n }\n\n /**\n * @dev Return the log in base 10 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n */\n function log10(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >= 10 ** 64) {\n value /= 10 ** 64;\n result += 64;\n }\n if (value >= 10 ** 32) {\n value /= 10 ** 32;\n result += 32;\n }\n if (value >= 10 ** 16) {\n value /= 10 ** 16;\n result += 16;\n }\n if (value >= 10 ** 8) {\n value /= 10 ** 8;\n result += 8;\n }\n if (value >= 10 ** 4) {\n value /= 10 ** 4;\n result += 4;\n }\n if (value >= 10 ** 2) {\n value /= 10 ** 2;\n result += 2;\n }\n if (value >= 10 ** 1) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log10(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);\n }\n }\n\n /**\n * @dev Return the log in base 256 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n *\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n */\n function log256(uint256 x) internal pure returns (uint256 r) {\n // If value has upper 128 bits set, log2 result is at least 128\n r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;\n // If upper 64 bits of 128-bit half set, add 64 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;\n // If upper 32 bits of 64-bit half set, add 32 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;\n // If upper 16 bits of 32-bit half set, add 16 to result\n r |= SafeCast.toUint((x >> r) > 0xffff) << 4;\n // Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8\n return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);\n }\n\n /**\n * @dev Return the log in base 256, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log256(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);\n }\n }\n\n /**\n * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.\n */\n function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {\n return uint8(rounding) % 2 == 1;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/SafeCast.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeCast {\n /**\n * @dev Value doesn't fit in an uint of `bits` size.\n */\n error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);\n\n /**\n * @dev An int value doesn't fit in an uint of `bits` size.\n */\n error SafeCastOverflowedIntToUint(int256 value);\n\n /**\n * @dev Value doesn't fit in an int of `bits` size.\n */\n error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);\n\n /**\n * @dev An uint value doesn't fit in an int of `bits` size.\n */\n error SafeCastOverflowedUintToInt(uint256 value);\n\n /**\n * @dev Returns the downcasted uint248 from uint256, reverting on\n * overflow (when the input is greater than largest uint248).\n *\n * Counterpart to Solidity's `uint248` operator.\n *\n * Requirements:\n *\n * - input must fit into 248 bits\n */\n function toUint248(uint256 value) internal pure returns (uint248) {\n if (value > type(uint248).max) {\n revert SafeCastOverflowedUintDowncast(248, value);\n }\n return uint248(value);\n }\n\n /**\n * @dev Returns the downcasted uint240 from uint256, reverting on\n * overflow (when the input is greater than largest uint240).\n *\n * Counterpart to Solidity's `uint240` operator.\n *\n * Requirements:\n *\n * - input must fit into 240 bits\n */\n function toUint240(uint256 value) internal pure returns (uint240) {\n if (value > type(uint240).max) {\n revert SafeCastOverflowedUintDowncast(240, value);\n }\n return uint240(value);\n }\n\n /**\n * @dev Returns the downcasted uint232 from uint256, reverting on\n * overflow (when the input is greater than largest uint232).\n *\n * Counterpart to Solidity's `uint232` operator.\n *\n * Requirements:\n *\n * - input must fit into 232 bits\n */\n function toUint232(uint256 value) internal pure returns (uint232) {\n if (value > type(uint232).max) {\n revert SafeCastOverflowedUintDowncast(232, value);\n }\n return uint232(value);\n }\n\n /**\n * @dev Returns the downcasted uint224 from uint256, reverting on\n * overflow (when the input is greater than largest uint224).\n *\n * Counterpart to Solidity's `uint224` operator.\n *\n * Requirements:\n *\n * - input must fit into 224 bits\n */\n function toUint224(uint256 value) internal pure returns (uint224) {\n if (value > type(uint224).max) {\n revert SafeCastOverflowedUintDowncast(224, value);\n }\n return uint224(value);\n }\n\n /**\n * @dev Returns the downcasted uint216 from uint256, reverting on\n * overflow (when the input is greater than largest uint216).\n *\n * Counterpart to Solidity's `uint216` operator.\n *\n * Requirements:\n *\n * - input must fit into 216 bits\n */\n function toUint216(uint256 value) internal pure returns (uint216) {\n if (value > type(uint216).max) {\n revert SafeCastOverflowedUintDowncast(216, value);\n }\n return uint216(value);\n }\n\n /**\n * @dev Returns the downcasted uint208 from uint256, reverting on\n * overflow (when the input is greater than largest uint208).\n *\n * Counterpart to Solidity's `uint208` operator.\n *\n * Requirements:\n *\n * - input must fit into 208 bits\n */\n function toUint208(uint256 value) internal pure returns (uint208) {\n if (value > type(uint208).max) {\n revert SafeCastOverflowedUintDowncast(208, value);\n }\n return uint208(value);\n }\n\n /**\n * @dev Returns the downcasted uint200 from uint256, reverting on\n * overflow (when the input is greater than largest uint200).\n *\n * Counterpart to Solidity's `uint200` operator.\n *\n * Requirements:\n *\n * - input must fit into 200 bits\n */\n function toUint200(uint256 value) internal pure returns (uint200) {\n if (value > type(uint200).max) {\n revert SafeCastOverflowedUintDowncast(200, value);\n }\n return uint200(value);\n }\n\n /**\n * @dev Returns the downcasted uint192 from uint256, reverting on\n * overflow (when the input is greater than largest uint192).\n *\n * Counterpart to Solidity's `uint192` operator.\n *\n * Requirements:\n *\n * - input must fit into 192 bits\n */\n function toUint192(uint256 value) internal pure returns (uint192) {\n if (value > type(uint192).max) {\n revert SafeCastOverflowedUintDowncast(192, value);\n }\n return uint192(value);\n }\n\n /**\n * @dev Returns the downcasted uint184 from uint256, reverting on\n * overflow (when the input is greater than largest uint184).\n *\n * Counterpart to Solidity's `uint184` operator.\n *\n * Requirements:\n *\n * - input must fit into 184 bits\n */\n function toUint184(uint256 value) internal pure returns (uint184) {\n if (value > type(uint184).max) {\n revert SafeCastOverflowedUintDowncast(184, value);\n }\n return uint184(value);\n }\n\n /**\n * @dev Returns the downcasted uint176 from uint256, reverting on\n * overflow (when the input is greater than largest uint176).\n *\n * Counterpart to Solidity's `uint176` operator.\n *\n * Requirements:\n *\n * - input must fit into 176 bits\n */\n function toUint176(uint256 value) internal pure returns (uint176) {\n if (value > type(uint176).max) {\n revert SafeCastOverflowedUintDowncast(176, value);\n }\n return uint176(value);\n }\n\n /**\n * @dev Returns the downcasted uint168 from uint256, reverting on\n * overflow (when the input is greater than largest uint168).\n *\n * Counterpart to Solidity's `uint168` operator.\n *\n * Requirements:\n *\n * - input must fit into 168 bits\n */\n function toUint168(uint256 value) internal pure returns (uint168) {\n if (value > type(uint168).max) {\n revert SafeCastOverflowedUintDowncast(168, value);\n }\n return uint168(value);\n }\n\n /**\n * @dev Returns the downcasted uint160 from uint256, reverting on\n * overflow (when the input is greater than largest uint160).\n *\n * Counterpart to Solidity's `uint160` operator.\n *\n * Requirements:\n *\n * - input must fit into 160 bits\n */\n function toUint160(uint256 value) internal pure returns (uint160) {\n if (value > type(uint160).max) {\n revert SafeCastOverflowedUintDowncast(160, value);\n }\n return uint160(value);\n }\n\n /**\n * @dev Returns the downcasted uint152 from uint256, reverting on\n * overflow (when the input is greater than largest uint152).\n *\n * Counterpart to Solidity's `uint152` operator.\n *\n * Requirements:\n *\n * - input must fit into 152 bits\n */\n function toUint152(uint256 value) internal pure returns (uint152) {\n if (value > type(uint152).max) {\n revert SafeCastOverflowedUintDowncast(152, value);\n }\n return uint152(value);\n }\n\n /**\n * @dev Returns the downcasted uint144 from uint256, reverting on\n * overflow (when the input is greater than largest uint144).\n *\n * Counterpart to Solidity's `uint144` operator.\n *\n * Requirements:\n *\n * - input must fit into 144 bits\n */\n function toUint144(uint256 value) internal pure returns (uint144) {\n if (value > type(uint144).max) {\n revert SafeCastOverflowedUintDowncast(144, value);\n }\n return uint144(value);\n }\n\n /**\n * @dev Returns the downcasted uint136 from uint256, reverting on\n * overflow (when the input is greater than largest uint136).\n *\n * Counterpart to Solidity's `uint136` operator.\n *\n * Requirements:\n *\n * - input must fit into 136 bits\n */\n function toUint136(uint256 value) internal pure returns (uint136) {\n if (value > type(uint136).max) {\n revert SafeCastOverflowedUintDowncast(136, value);\n }\n return uint136(value);\n }\n\n /**\n * @dev Returns the downcasted uint128 from uint256, reverting on\n * overflow (when the input is greater than largest uint128).\n *\n * Counterpart to Solidity's `uint128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n */\n function toUint128(uint256 value) internal pure returns (uint128) {\n if (value > type(uint128).max) {\n revert SafeCastOverflowedUintDowncast(128, value);\n }\n return uint128(value);\n }\n\n /**\n * @dev Returns the downcasted uint120 from uint256, reverting on\n * overflow (when the input is greater than largest uint120).\n *\n * Counterpart to Solidity's `uint120` operator.\n *\n * Requirements:\n *\n * - input must fit into 120 bits\n */\n function toUint120(uint256 value) internal pure returns (uint120) {\n if (value > type(uint120).max) {\n revert SafeCastOverflowedUintDowncast(120, value);\n }\n return uint120(value);\n }\n\n /**\n * @dev Returns the downcasted uint112 from uint256, reverting on\n * overflow (when the input is greater than largest uint112).\n *\n * Counterpart to Solidity's `uint112` operator.\n *\n * Requirements:\n *\n * - input must fit into 112 bits\n */\n function toUint112(uint256 value) internal pure returns (uint112) {\n if (value > type(uint112).max) {\n revert SafeCastOverflowedUintDowncast(112, value);\n }\n return uint112(value);\n }\n\n /**\n * @dev Returns the downcasted uint104 from uint256, reverting on\n * overflow (when the input is greater than largest uint104).\n *\n * Counterpart to Solidity's `uint104` operator.\n *\n * Requirements:\n *\n * - input must fit into 104 bits\n */\n function toUint104(uint256 value) internal pure returns (uint104) {\n if (value > type(uint104).max) {\n revert SafeCastOverflowedUintDowncast(104, value);\n }\n return uint104(value);\n }\n\n /**\n * @dev Returns the downcasted uint96 from uint256, reverting on\n * overflow (when the input is greater than largest uint96).\n *\n * Counterpart to Solidity's `uint96` operator.\n *\n * Requirements:\n *\n * - input must fit into 96 bits\n */\n function toUint96(uint256 value) internal pure returns (uint96) {\n if (value > type(uint96).max) {\n revert SafeCastOverflowedUintDowncast(96, value);\n }\n return uint96(value);\n }\n\n /**\n * @dev Returns the downcasted uint88 from uint256, reverting on\n * overflow (when the input is greater than largest uint88).\n *\n * Counterpart to Solidity's `uint88` operator.\n *\n * Requirements:\n *\n * - input must fit into 88 bits\n */\n function toUint88(uint256 value) internal pure returns (uint88) {\n if (value > type(uint88).max) {\n revert SafeCastOverflowedUintDowncast(88, value);\n }\n return uint88(value);\n }\n\n /**\n * @dev Returns the downcasted uint80 from uint256, reverting on\n * overflow (when the input is greater than largest uint80).\n *\n * Counterpart to Solidity's `uint80` operator.\n *\n * Requirements:\n *\n * - input must fit into 80 bits\n */\n function toUint80(uint256 value) internal pure returns (uint80) {\n if (value > type(uint80).max) {\n revert SafeCastOverflowedUintDowncast(80, value);\n }\n return uint80(value);\n }\n\n /**\n * @dev Returns the downcasted uint72 from uint256, reverting on\n * overflow (when the input is greater than largest uint72).\n *\n * Counterpart to Solidity's `uint72` operator.\n *\n * Requirements:\n *\n * - input must fit into 72 bits\n */\n function toUint72(uint256 value) internal pure returns (uint72) {\n if (value > type(uint72).max) {\n revert SafeCastOverflowedUintDowncast(72, value);\n }\n return uint72(value);\n }\n\n /**\n * @dev Returns the downcasted uint64 from uint256, reverting on\n * overflow (when the input is greater than largest uint64).\n *\n * Counterpart to Solidity's `uint64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n */\n function toUint64(uint256 value) internal pure returns (uint64) {\n if (value > type(uint64).max) {\n revert SafeCastOverflowedUintDowncast(64, value);\n }\n return uint64(value);\n }\n\n /**\n * @dev Returns the downcasted uint56 from uint256, reverting on\n * overflow (when the input is greater than largest uint56).\n *\n * Counterpart to Solidity's `uint56` operator.\n *\n * Requirements:\n *\n * - input must fit into 56 bits\n */\n function toUint56(uint256 value) internal pure returns (uint56) {\n if (value > type(uint56).max) {\n revert SafeCastOverflowedUintDowncast(56, value);\n }\n return uint56(value);\n }\n\n /**\n * @dev Returns the downcasted uint48 from uint256, reverting on\n * overflow (when the input is greater than largest uint48).\n *\n * Counterpart to Solidity's `uint48` operator.\n *\n * Requirements:\n *\n * - input must fit into 48 bits\n */\n function toUint48(uint256 value) internal pure returns (uint48) {\n if (value > type(uint48).max) {\n revert SafeCastOverflowedUintDowncast(48, value);\n }\n return uint48(value);\n }\n\n /**\n * @dev Returns the downcasted uint40 from uint256, reverting on\n * overflow (when the input is greater than largest uint40).\n *\n * Counterpart to Solidity's `uint40` operator.\n *\n * Requirements:\n *\n * - input must fit into 40 bits\n */\n function toUint40(uint256 value) internal pure returns (uint40) {\n if (value > type(uint40).max) {\n revert SafeCastOverflowedUintDowncast(40, value);\n }\n return uint40(value);\n }\n\n /**\n * @dev Returns the downcasted uint32 from uint256, reverting on\n * overflow (when the input is greater than largest uint32).\n *\n * Counterpart to Solidity's `uint32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n */\n function toUint32(uint256 value) internal pure returns (uint32) {\n if (value > type(uint32).max) {\n revert SafeCastOverflowedUintDowncast(32, value);\n }\n return uint32(value);\n }\n\n /**\n * @dev Returns the downcasted uint24 from uint256, reverting on\n * overflow (when the input is greater than largest uint24).\n *\n * Counterpart to Solidity's `uint24` operator.\n *\n * Requirements:\n *\n * - input must fit into 24 bits\n */\n function toUint24(uint256 value) internal pure returns (uint24) {\n if (value > type(uint24).max) {\n revert SafeCastOverflowedUintDowncast(24, value);\n }\n return uint24(value);\n }\n\n /**\n * @dev Returns the downcasted uint16 from uint256, reverting on\n * overflow (when the input is greater than largest uint16).\n *\n * Counterpart to Solidity's `uint16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n */\n function toUint16(uint256 value) internal pure returns (uint16) {\n if (value > type(uint16).max) {\n revert SafeCastOverflowedUintDowncast(16, value);\n }\n return uint16(value);\n }\n\n /**\n * @dev Returns the downcasted uint8 from uint256, reverting on\n * overflow (when the input is greater than largest uint8).\n *\n * Counterpart to Solidity's `uint8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits\n */\n function toUint8(uint256 value) internal pure returns (uint8) {\n if (value > type(uint8).max) {\n revert SafeCastOverflowedUintDowncast(8, value);\n }\n return uint8(value);\n }\n\n /**\n * @dev Converts a signed int256 into an unsigned uint256.\n *\n * Requirements:\n *\n * - input must be greater than or equal to 0.\n */\n function toUint256(int256 value) internal pure returns (uint256) {\n if (value < 0) {\n revert SafeCastOverflowedIntToUint(value);\n }\n return uint256(value);\n }\n\n /**\n * @dev Returns the downcasted int248 from int256, reverting on\n * overflow (when the input is less than smallest int248 or\n * greater than largest int248).\n *\n * Counterpart to Solidity's `int248` operator.\n *\n * Requirements:\n *\n * - input must fit into 248 bits\n */\n function toInt248(int256 value) internal pure returns (int248 downcasted) {\n downcasted = int248(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(248, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int240 from int256, reverting on\n * overflow (when the input is less than smallest int240 or\n * greater than largest int240).\n *\n * Counterpart to Solidity's `int240` operator.\n *\n * Requirements:\n *\n * - input must fit into 240 bits\n */\n function toInt240(int256 value) internal pure returns (int240 downcasted) {\n downcasted = int240(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(240, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int232 from int256, reverting on\n * overflow (when the input is less than smallest int232 or\n * greater than largest int232).\n *\n * Counterpart to Solidity's `int232` operator.\n *\n * Requirements:\n *\n * - input must fit into 232 bits\n */\n function toInt232(int256 value) internal pure returns (int232 downcasted) {\n downcasted = int232(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(232, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int224 from int256, reverting on\n * overflow (when the input is less than smallest int224 or\n * greater than largest int224).\n *\n * Counterpart to Solidity's `int224` operator.\n *\n * Requirements:\n *\n * - input must fit into 224 bits\n */\n function toInt224(int256 value) internal pure returns (int224 downcasted) {\n downcasted = int224(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(224, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int216 from int256, reverting on\n * overflow (when the input is less than smallest int216 or\n * greater than largest int216).\n *\n * Counterpart to Solidity's `int216` operator.\n *\n * Requirements:\n *\n * - input must fit into 216 bits\n */\n function toInt216(int256 value) internal pure returns (int216 downcasted) {\n downcasted = int216(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(216, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int208 from int256, reverting on\n * overflow (when the input is less than smallest int208 or\n * greater than largest int208).\n *\n * Counterpart to Solidity's `int208` operator.\n *\n * Requirements:\n *\n * - input must fit into 208 bits\n */\n function toInt208(int256 value) internal pure returns (int208 downcasted) {\n downcasted = int208(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(208, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int200 from int256, reverting on\n * overflow (when the input is less than smallest int200 or\n * greater than largest int200).\n *\n * Counterpart to Solidity's `int200` operator.\n *\n * Requirements:\n *\n * - input must fit into 200 bits\n */\n function toInt200(int256 value) internal pure returns (int200 downcasted) {\n downcasted = int200(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(200, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int192 from int256, reverting on\n * overflow (when the input is less than smallest int192 or\n * greater than largest int192).\n *\n * Counterpart to Solidity's `int192` operator.\n *\n * Requirements:\n *\n * - input must fit into 192 bits\n */\n function toInt192(int256 value) internal pure returns (int192 downcasted) {\n downcasted = int192(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(192, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int184 from int256, reverting on\n * overflow (when the input is less than smallest int184 or\n * greater than largest int184).\n *\n * Counterpart to Solidity's `int184` operator.\n *\n * Requirements:\n *\n * - input must fit into 184 bits\n */\n function toInt184(int256 value) internal pure returns (int184 downcasted) {\n downcasted = int184(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(184, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int176 from int256, reverting on\n * overflow (when the input is less than smallest int176 or\n * greater than largest int176).\n *\n * Counterpart to Solidity's `int176` operator.\n *\n * Requirements:\n *\n * - input must fit into 176 bits\n */\n function toInt176(int256 value) internal pure returns (int176 downcasted) {\n downcasted = int176(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(176, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int168 from int256, reverting on\n * overflow (when the input is less than smallest int168 or\n * greater than largest int168).\n *\n * Counterpart to Solidity's `int168` operator.\n *\n * Requirements:\n *\n * - input must fit into 168 bits\n */\n function toInt168(int256 value) internal pure returns (int168 downcasted) {\n downcasted = int168(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(168, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int160 from int256, reverting on\n * overflow (when the input is less than smallest int160 or\n * greater than largest int160).\n *\n * Counterpart to Solidity's `int160` operator.\n *\n * Requirements:\n *\n * - input must fit into 160 bits\n */\n function toInt160(int256 value) internal pure returns (int160 downcasted) {\n downcasted = int160(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(160, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int152 from int256, reverting on\n * overflow (when the input is less than smallest int152 or\n * greater than largest int152).\n *\n * Counterpart to Solidity's `int152` operator.\n *\n * Requirements:\n *\n * - input must fit into 152 bits\n */\n function toInt152(int256 value) internal pure returns (int152 downcasted) {\n downcasted = int152(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(152, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int144 from int256, reverting on\n * overflow (when the input is less than smallest int144 or\n * greater than largest int144).\n *\n * Counterpart to Solidity's `int144` operator.\n *\n * Requirements:\n *\n * - input must fit into 144 bits\n */\n function toInt144(int256 value) internal pure returns (int144 downcasted) {\n downcasted = int144(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(144, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int136 from int256, reverting on\n * overflow (when the input is less than smallest int136 or\n * greater than largest int136).\n *\n * Counterpart to Solidity's `int136` operator.\n *\n * Requirements:\n *\n * - input must fit into 136 bits\n */\n function toInt136(int256 value) internal pure returns (int136 downcasted) {\n downcasted = int136(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(136, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int128 from int256, reverting on\n * overflow (when the input is less than smallest int128 or\n * greater than largest int128).\n *\n * Counterpart to Solidity's `int128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n */\n function toInt128(int256 value) internal pure returns (int128 downcasted) {\n downcasted = int128(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(128, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int120 from int256, reverting on\n * overflow (when the input is less than smallest int120 or\n * greater than largest int120).\n *\n * Counterpart to Solidity's `int120` operator.\n *\n * Requirements:\n *\n * - input must fit into 120 bits\n */\n function toInt120(int256 value) internal pure returns (int120 downcasted) {\n downcasted = int120(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(120, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int112 from int256, reverting on\n * overflow (when the input is less than smallest int112 or\n * greater than largest int112).\n *\n * Counterpart to Solidity's `int112` operator.\n *\n * Requirements:\n *\n * - input must fit into 112 bits\n */\n function toInt112(int256 value) internal pure returns (int112 downcasted) {\n downcasted = int112(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(112, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int104 from int256, reverting on\n * overflow (when the input is less than smallest int104 or\n * greater than largest int104).\n *\n * Counterpart to Solidity's `int104` operator.\n *\n * Requirements:\n *\n * - input must fit into 104 bits\n */\n function toInt104(int256 value) internal pure returns (int104 downcasted) {\n downcasted = int104(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(104, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int96 from int256, reverting on\n * overflow (when the input is less than smallest int96 or\n * greater than largest int96).\n *\n * Counterpart to Solidity's `int96` operator.\n *\n * Requirements:\n *\n * - input must fit into 96 bits\n */\n function toInt96(int256 value) internal pure returns (int96 downcasted) {\n downcasted = int96(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(96, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int88 from int256, reverting on\n * overflow (when the input is less than smallest int88 or\n * greater than largest int88).\n *\n * Counterpart to Solidity's `int88` operator.\n *\n * Requirements:\n *\n * - input must fit into 88 bits\n */\n function toInt88(int256 value) internal pure returns (int88 downcasted) {\n downcasted = int88(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(88, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int80 from int256, reverting on\n * overflow (when the input is less than smallest int80 or\n * greater than largest int80).\n *\n * Counterpart to Solidity's `int80` operator.\n *\n * Requirements:\n *\n * - input must fit into 80 bits\n */\n function toInt80(int256 value) internal pure returns (int80 downcasted) {\n downcasted = int80(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(80, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int72 from int256, reverting on\n * overflow (when the input is less than smallest int72 or\n * greater than largest int72).\n *\n * Counterpart to Solidity's `int72` operator.\n *\n * Requirements:\n *\n * - input must fit into 72 bits\n */\n function toInt72(int256 value) internal pure returns (int72 downcasted) {\n downcasted = int72(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(72, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int64 from int256, reverting on\n * overflow (when the input is less than smallest int64 or\n * greater than largest int64).\n *\n * Counterpart to Solidity's `int64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n */\n function toInt64(int256 value) internal pure returns (int64 downcasted) {\n downcasted = int64(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(64, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int56 from int256, reverting on\n * overflow (when the input is less than smallest int56 or\n * greater than largest int56).\n *\n * Counterpart to Solidity's `int56` operator.\n *\n * Requirements:\n *\n * - input must fit into 56 bits\n */\n function toInt56(int256 value) internal pure returns (int56 downcasted) {\n downcasted = int56(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(56, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int48 from int256, reverting on\n * overflow (when the input is less than smallest int48 or\n * greater than largest int48).\n *\n * Counterpart to Solidity's `int48` operator.\n *\n * Requirements:\n *\n * - input must fit into 48 bits\n */\n function toInt48(int256 value) internal pure returns (int48 downcasted) {\n downcasted = int48(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(48, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int40 from int256, reverting on\n * overflow (when the input is less than smallest int40 or\n * greater than largest int40).\n *\n * Counterpart to Solidity's `int40` operator.\n *\n * Requirements:\n *\n * - input must fit into 40 bits\n */\n function toInt40(int256 value) internal pure returns (int40 downcasted) {\n downcasted = int40(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(40, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int32 from int256, reverting on\n * overflow (when the input is less than smallest int32 or\n * greater than largest int32).\n *\n * Counterpart to Solidity's `int32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n */\n function toInt32(int256 value) internal pure returns (int32 downcasted) {\n downcasted = int32(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(32, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int24 from int256, reverting on\n * overflow (when the input is less than smallest int24 or\n * greater than largest int24).\n *\n * Counterpart to Solidity's `int24` operator.\n *\n * Requirements:\n *\n * - input must fit into 24 bits\n */\n function toInt24(int256 value) internal pure returns (int24 downcasted) {\n downcasted = int24(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(24, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int16 from int256, reverting on\n * overflow (when the input is less than smallest int16 or\n * greater than largest int16).\n *\n * Counterpart to Solidity's `int16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n */\n function toInt16(int256 value) internal pure returns (int16 downcasted) {\n downcasted = int16(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(16, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int8 from int256, reverting on\n * overflow (when the input is less than smallest int8 or\n * greater than largest int8).\n *\n * Counterpart to Solidity's `int8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits\n */\n function toInt8(int256 value) internal pure returns (int8 downcasted) {\n downcasted = int8(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(8, value);\n }\n }\n\n /**\n * @dev Converts an unsigned uint256 into a signed int256.\n *\n * Requirements:\n *\n * - input must be less than or equal to maxInt256.\n */\n function toInt256(uint256 value) internal pure returns (int256) {\n // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n if (value > uint256(type(int256).max)) {\n revert SafeCastOverflowedUintToInt(value);\n }\n return int256(value);\n }\n\n /**\n * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.\n */\n function toUint(bool b) internal pure returns (uint256 u) {\n assembly (\"memory-safe\") {\n u := iszero(iszero(b))\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/SignedMath.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol)\n\npragma solidity ^0.8.20;\n\nimport {SafeCast} from \"./SafeCast.sol\";\n\n/**\n * @dev Standard signed math utilities missing in the Solidity language.\n */\nlibrary SignedMath {\n /**\n * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.\n *\n * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.\n * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute\n * one branch when needed, making this function more expensive.\n */\n function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {\n unchecked {\n // branchless ternary works because:\n // b ^ (a ^ b) == a\n // b ^ 0 == b\n return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));\n }\n }\n\n /**\n * @dev Returns the largest of two signed numbers.\n */\n function max(int256 a, int256 b) internal pure returns (int256) {\n return ternary(a > b, a, b);\n }\n\n /**\n * @dev Returns the smallest of two signed numbers.\n */\n function min(int256 a, int256 b) internal pure returns (int256) {\n return ternary(a < b, a, b);\n }\n\n /**\n * @dev Returns the average of two signed numbers without overflow.\n * The result is rounded towards zero.\n */\n function average(int256 a, int256 b) internal pure returns (int256) {\n // Formula from the book \"Hacker's Delight\"\n int256 x = (a & b) + ((a ^ b) >> 1);\n return x + (int256(uint256(x) >> 255) & (a ^ b));\n }\n\n /**\n * @dev Returns the absolute unsigned value of a signed value.\n */\n function abs(int256 n) internal pure returns (uint256) {\n unchecked {\n // Formula from the \"Bit Twiddling Hacks\" by Sean Eron Anderson.\n // Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,\n // taking advantage of the most significant (or \"sign\" bit) in two's complement representation.\n // This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,\n // the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative).\n int256 mask = n >> 255;\n\n // A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.\n return uint256((n + mask) ^ mask);\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Panic.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Helper library for emitting standardized panic codes.\n *\n * ```solidity\n * contract Example {\n * using Panic for uint256;\n *\n * // Use any of the declared internal constants\n * function foo() { Panic.GENERIC.panic(); }\n *\n * // Alternatively\n * function foo() { Panic.panic(Panic.GENERIC); }\n * }\n * ```\n *\n * Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].\n *\n * _Available since v5.1._\n */\n// slither-disable-next-line unused-state\nlibrary Panic {\n /// @dev generic / unspecified error\n uint256 internal constant GENERIC = 0x00;\n /// @dev used by the assert() builtin\n uint256 internal constant ASSERT = 0x01;\n /// @dev arithmetic underflow or overflow\n uint256 internal constant UNDER_OVERFLOW = 0x11;\n /// @dev division or modulo by zero\n uint256 internal constant DIVISION_BY_ZERO = 0x12;\n /// @dev enum conversion error\n uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;\n /// @dev invalid encoding in storage\n uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;\n /// @dev empty array pop\n uint256 internal constant EMPTY_ARRAY_POP = 0x31;\n /// @dev array out of bounds access\n uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;\n /// @dev resource error (too large allocation or too large array)\n uint256 internal constant RESOURCE_ERROR = 0x41;\n /// @dev calling invalid internal function\n uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;\n\n /// @dev Reverts with a panic code. Recommended to use with\n /// the internal constants with predefined codes.\n function panic(uint256 code) internal pure {\n assembly (\"memory-safe\") {\n mstore(0x00, 0x4e487b71)\n mstore(0x20, code)\n revert(0x1c, 0x24)\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/ReentrancyGuard.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,\n * consider using {ReentrancyGuardTransient} instead.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant NOT_ENTERED = 1;\n uint256 private constant ENTERED = 2;\n\n uint256 private _status;\n\n /**\n * @dev Unauthorized reentrant call.\n */\n error ReentrancyGuardReentrantCall();\n\n constructor() {\n _status = NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and making it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n _nonReentrantBefore();\n _;\n _nonReentrantAfter();\n }\n\n function _nonReentrantBefore() private {\n // On the first call to nonReentrant, _status will be NOT_ENTERED\n if (_status == ENTERED) {\n revert ReentrancyGuardReentrantCall();\n }\n\n // Any calls to nonReentrant after this point will fail\n _status = ENTERED;\n }\n\n function _nonReentrantAfter() private {\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = NOT_ENTERED;\n }\n\n /**\n * @dev Returns true if the reentrancy guard is currently set to \"entered\", which indicates there is a\n * `nonReentrant` function in the call stack.\n */\n function _reentrancyGuardEntered() internal view returns (bool) {\n return _status == ENTERED;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/ShortStrings.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/ShortStrings.sol)\n\npragma solidity ^0.8.20;\n\nimport {StorageSlot} from \"./StorageSlot.sol\";\n\n// | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |\n// | length | 0x BB |\ntype ShortString is bytes32;\n\n/**\n * @dev This library provides functions to convert short memory strings\n * into a `ShortString` type that can be used as an immutable variable.\n *\n * Strings of arbitrary length can be optimized using this library if\n * they are short enough (up to 31 bytes) by packing them with their\n * length (1 byte) in a single EVM word (32 bytes). Additionally, a\n * fallback mechanism can be used for every other case.\n *\n * Usage example:\n *\n * ```solidity\n * contract Named {\n * using ShortStrings for *;\n *\n * ShortString private immutable _name;\n * string private _nameFallback;\n *\n * constructor(string memory contractName) {\n * _name = contractName.toShortStringWithFallback(_nameFallback);\n * }\n *\n * function name() external view returns (string memory) {\n * return _name.toStringWithFallback(_nameFallback);\n * }\n * }\n * ```\n */\nlibrary ShortStrings {\n // Used as an identifier for strings longer than 31 bytes.\n bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;\n\n error StringTooLong(string str);\n error InvalidShortString();\n\n /**\n * @dev Encode a string of at most 31 chars into a `ShortString`.\n *\n * This will trigger a `StringTooLong` error is the input string is too long.\n */\n function toShortString(string memory str) internal pure returns (ShortString) {\n bytes memory bstr = bytes(str);\n if (bstr.length > 31) {\n revert StringTooLong(str);\n }\n return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));\n }\n\n /**\n * @dev Decode a `ShortString` back to a \"normal\" string.\n */\n function toString(ShortString sstr) internal pure returns (string memory) {\n uint256 len = byteLength(sstr);\n // using `new string(len)` would work locally but is not memory safe.\n string memory str = new string(32);\n assembly (\"memory-safe\") {\n mstore(str, len)\n mstore(add(str, 0x20), sstr)\n }\n return str;\n }\n\n /**\n * @dev Return the length of a `ShortString`.\n */\n function byteLength(ShortString sstr) internal pure returns (uint256) {\n uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;\n if (result > 31) {\n revert InvalidShortString();\n }\n return result;\n }\n\n /**\n * @dev Encode a string into a `ShortString`, or write it to storage if it is too long.\n */\n function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {\n if (bytes(value).length < 32) {\n return toShortString(value);\n } else {\n StorageSlot.getStringSlot(store).value = value;\n return ShortString.wrap(FALLBACK_SENTINEL);\n }\n }\n\n /**\n * @dev Decode a string that was encoded to `ShortString` or written to storage using {toShortStringWithFallback}.\n */\n function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {\n if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {\n return toString(value);\n } else {\n return store;\n }\n }\n\n /**\n * @dev Return the length of a string that was encoded to `ShortString` or written to storage using\n * {toShortStringWithFallback}.\n *\n * WARNING: This will return the \"byte length\" of the string. This may not reflect the actual length in terms of\n * actual characters as the UTF-8 encoding of a single character can span over multiple bytes.\n */\n function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {\n if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {\n return byteLength(value);\n } else {\n return bytes(store).length;\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/StorageSlot.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)\n// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Library for reading and writing primitive types to specific storage slots.\n *\n * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\n * This library helps with reading and writing to such slots without the need for inline assembly.\n *\n * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\n *\n * Example usage to set ERC-1967 implementation slot:\n * ```solidity\n * contract ERC1967 {\n * // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.\n * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n *\n * function _getImplementation() internal view returns (address) {\n * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n * }\n *\n * function _setImplementation(address newImplementation) internal {\n * require(newImplementation.code.length > 0);\n * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n * }\n * }\n * ```\n *\n * TIP: Consider using this library along with {SlotDerivation}.\n */\nlibrary StorageSlot {\n struct AddressSlot {\n address value;\n }\n\n struct BooleanSlot {\n bool value;\n }\n\n struct Bytes32Slot {\n bytes32 value;\n }\n\n struct Uint256Slot {\n uint256 value;\n }\n\n struct Int256Slot {\n int256 value;\n }\n\n struct StringSlot {\n string value;\n }\n\n struct BytesSlot {\n bytes value;\n }\n\n /**\n * @dev Returns an `AddressSlot` with member `value` located at `slot`.\n */\n function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `BooleanSlot` with member `value` located at `slot`.\n */\n function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Bytes32Slot` with member `value` located at `slot`.\n */\n function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Uint256Slot` with member `value` located at `slot`.\n */\n function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Int256Slot` with member `value` located at `slot`.\n */\n function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `StringSlot` with member `value` located at `slot`.\n */\n function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `StringSlot` representation of the string storage pointer `store`.\n */\n function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := store.slot\n }\n }\n\n /**\n * @dev Returns a `BytesSlot` with member `value` located at `slot`.\n */\n function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.\n */\n function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := store.slot\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Strings.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/Strings.sol)\n\npragma solidity ^0.8.20;\n\nimport {Math} from \"./math/Math.sol\";\nimport {SafeCast} from \"./math/SafeCast.sol\";\nimport {SignedMath} from \"./math/SignedMath.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n using SafeCast for *;\n\n bytes16 private constant HEX_DIGITS = \"0123456789abcdef\";\n uint8 private constant ADDRESS_LENGTH = 20;\n uint256 private constant SPECIAL_CHARS_LOOKUP =\n (1 << 0x08) | // backspace\n (1 << 0x09) | // tab\n (1 << 0x0a) | // newline\n (1 << 0x0c) | // form feed\n (1 << 0x0d) | // carriage return\n (1 << 0x22) | // double quote\n (1 << 0x5c); // backslash\n\n /**\n * @dev The `value` string doesn't fit in the specified `length`.\n */\n error StringsInsufficientHexLength(uint256 value, uint256 length);\n\n /**\n * @dev The string being parsed contains characters that are not in scope of the given base.\n */\n error StringsInvalidChar();\n\n /**\n * @dev The string being parsed is not a properly formatted address.\n */\n error StringsInvalidAddressFormat();\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n unchecked {\n uint256 length = Math.log10(value) + 1;\n string memory buffer = new string(length);\n uint256 ptr;\n assembly (\"memory-safe\") {\n ptr := add(buffer, add(32, length))\n }\n while (true) {\n ptr--;\n assembly (\"memory-safe\") {\n mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))\n }\n value /= 10;\n if (value == 0) break;\n }\n return buffer;\n }\n }\n\n /**\n * @dev Converts a `int256` to its ASCII `string` decimal representation.\n */\n function toStringSigned(int256 value) internal pure returns (string memory) {\n return string.concat(value < 0 ? \"-\" : \"\", toString(SignedMath.abs(value)));\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n unchecked {\n return toHexString(value, Math.log256(value) + 1);\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n uint256 localValue = value;\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = HEX_DIGITS[localValue & 0xf];\n localValue >>= 4;\n }\n if (localValue != 0) {\n revert StringsInsufficientHexLength(value, length);\n }\n return string(buffer);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal\n * representation.\n */\n function toHexString(address addr) internal pure returns (string memory) {\n return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal\n * representation, according to EIP-55.\n */\n function toChecksumHexString(address addr) internal pure returns (string memory) {\n bytes memory buffer = bytes(toHexString(addr));\n\n // hash the hex part of buffer (skip length + 2 bytes, length 40)\n uint256 hashValue;\n assembly (\"memory-safe\") {\n hashValue := shr(96, keccak256(add(buffer, 0x22), 40))\n }\n\n for (uint256 i = 41; i > 1; --i) {\n // possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)\n if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {\n // case shift by xoring with 0x20\n buffer[i] ^= 0x20;\n }\n hashValue >>= 4;\n }\n return string(buffer);\n }\n\n /**\n * @dev Returns true if the two strings are equal.\n */\n function equal(string memory a, string memory b) internal pure returns (bool) {\n return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));\n }\n\n /**\n * @dev Parse a decimal string and returns the value as a `uint256`.\n *\n * Requirements:\n * - The string must be formatted as `[0-9]*`\n * - The result must fit into an `uint256` type\n */\n function parseUint(string memory input) internal pure returns (uint256) {\n return parseUint(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseUint-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `[0-9]*`\n * - The result must fit into an `uint256` type\n */\n function parseUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {\n (bool success, uint256 value) = tryParseUint(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseUint-string} that returns false if the parsing fails because of an invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseUint(string memory input) internal pure returns (bool success, uint256 value) {\n return _tryParseUintUncheckedBounds(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseUint-string-uint256-uint256} that returns false if the parsing fails because of an invalid\n * character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseUint(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, uint256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseUintUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseUint-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseUintUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, uint256 value) {\n bytes memory buffer = bytes(input);\n\n uint256 result = 0;\n for (uint256 i = begin; i < end; ++i) {\n uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));\n if (chr > 9) return (false, 0);\n result *= 10;\n result += chr;\n }\n return (true, result);\n }\n\n /**\n * @dev Parse a decimal string and returns the value as a `int256`.\n *\n * Requirements:\n * - The string must be formatted as `[-+]?[0-9]*`\n * - The result must fit in an `int256` type.\n */\n function parseInt(string memory input) internal pure returns (int256) {\n return parseInt(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseInt-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `[-+]?[0-9]*`\n * - The result must fit in an `int256` type.\n */\n function parseInt(string memory input, uint256 begin, uint256 end) internal pure returns (int256) {\n (bool success, int256 value) = tryParseInt(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseInt-string} that returns false if the parsing fails because of an invalid character or if\n * the result does not fit in a `int256`.\n *\n * NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.\n */\n function tryParseInt(string memory input) internal pure returns (bool success, int256 value) {\n return _tryParseIntUncheckedBounds(input, 0, bytes(input).length);\n }\n\n uint256 private constant ABS_MIN_INT256 = 2 ** 255;\n\n /**\n * @dev Variant of {parseInt-string-uint256-uint256} that returns false if the parsing fails because of an invalid\n * character or if the result does not fit in a `int256`.\n *\n * NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.\n */\n function tryParseInt(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, int256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseIntUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseInt-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseIntUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, int256 value) {\n bytes memory buffer = bytes(input);\n\n // Check presence of a negative sign.\n bytes1 sign = begin == end ? bytes1(0) : bytes1(_unsafeReadBytesOffset(buffer, begin)); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n bool positiveSign = sign == bytes1(\"+\");\n bool negativeSign = sign == bytes1(\"-\");\n uint256 offset = (positiveSign || negativeSign).toUint();\n\n (bool absSuccess, uint256 absValue) = tryParseUint(input, begin + offset, end);\n\n if (absSuccess && absValue < ABS_MIN_INT256) {\n return (true, negativeSign ? -int256(absValue) : int256(absValue));\n } else if (absSuccess && negativeSign && absValue == ABS_MIN_INT256) {\n return (true, type(int256).min);\n } else return (false, 0);\n }\n\n /**\n * @dev Parse a hexadecimal string (with or without \"0x\" prefix), and returns the value as a `uint256`.\n *\n * Requirements:\n * - The string must be formatted as `(0x)?[0-9a-fA-F]*`\n * - The result must fit in an `uint256` type.\n */\n function parseHexUint(string memory input) internal pure returns (uint256) {\n return parseHexUint(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseHexUint-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `(0x)?[0-9a-fA-F]*`\n * - The result must fit in an `uint256` type.\n */\n function parseHexUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {\n (bool success, uint256 value) = tryParseHexUint(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseHexUint-string} that returns false if the parsing fails because of an invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseHexUint(string memory input) internal pure returns (bool success, uint256 value) {\n return _tryParseHexUintUncheckedBounds(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseHexUint-string-uint256-uint256} that returns false if the parsing fails because of an\n * invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseHexUint(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, uint256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseHexUintUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseHexUint-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseHexUintUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, uint256 value) {\n bytes memory buffer = bytes(input);\n\n // skip 0x prefix if present\n bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(buffer, begin)) == bytes2(\"0x\"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n uint256 offset = hasPrefix.toUint() * 2;\n\n uint256 result = 0;\n for (uint256 i = begin + offset; i < end; ++i) {\n uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));\n if (chr > 15) return (false, 0);\n result *= 16;\n unchecked {\n // Multiplying by 16 is equivalent to a shift of 4 bits (with additional overflow check).\n // This guarantees that adding a value < 16 will not cause an overflow, hence the unchecked.\n result += chr;\n }\n }\n return (true, result);\n }\n\n /**\n * @dev Parse a hexadecimal string (with or without \"0x\" prefix), and returns the value as an `address`.\n *\n * Requirements:\n * - The string must be formatted as `(0x)?[0-9a-fA-F]{40}`\n */\n function parseAddress(string memory input) internal pure returns (address) {\n return parseAddress(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseAddress-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `(0x)?[0-9a-fA-F]{40}`\n */\n function parseAddress(string memory input, uint256 begin, uint256 end) internal pure returns (address) {\n (bool success, address value) = tryParseAddress(input, begin, end);\n if (!success) revert StringsInvalidAddressFormat();\n return value;\n }\n\n /**\n * @dev Variant of {parseAddress-string} that returns false if the parsing fails because the input is not a properly\n * formatted address. See {parseAddress-string} requirements.\n */\n function tryParseAddress(string memory input) internal pure returns (bool success, address value) {\n return tryParseAddress(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseAddress-string-uint256-uint256} that returns false if the parsing fails because input is not a properly\n * formatted address. See {parseAddress-string-uint256-uint256} requirements.\n */\n function tryParseAddress(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, address value) {\n if (end > bytes(input).length || begin > end) return (false, address(0));\n\n bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(bytes(input), begin)) == bytes2(\"0x\"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n uint256 expectedLength = 40 + hasPrefix.toUint() * 2;\n\n // check that input is the correct length\n if (end - begin == expectedLength) {\n // length guarantees that this does not overflow, and value is at most type(uint160).max\n (bool s, uint256 v) = _tryParseHexUintUncheckedBounds(input, begin, end);\n return (s, address(uint160(v)));\n } else {\n return (false, address(0));\n }\n }\n\n function _tryParseChr(bytes1 chr) private pure returns (uint8) {\n uint8 value = uint8(chr);\n\n // Try to parse `chr`:\n // - Case 1: [0-9]\n // - Case 2: [a-f]\n // - Case 3: [A-F]\n // - otherwise not supported\n unchecked {\n if (value > 47 && value < 58) value -= 48;\n else if (value > 96 && value < 103) value -= 87;\n else if (value > 64 && value < 71) value -= 55;\n else return type(uint8).max;\n }\n\n return value;\n }\n\n /**\n * @dev Escape special characters in JSON strings. This can be useful to prevent JSON injection in NFT metadata.\n *\n * WARNING: This function should only be used in double quoted JSON strings. Single quotes are not escaped.\n *\n * NOTE: This function escapes all unicode characters, and not just the ones in ranges defined in section 2.5 of\n * RFC-4627 (U+0000 to U+001F, U+0022 and U+005C). ECMAScript's `JSON.parse` does recover escaped unicode\n * characters that are not in this range, but other tooling may provide different results.\n */\n function escapeJSON(string memory input) internal pure returns (string memory) {\n bytes memory buffer = bytes(input);\n bytes memory output = new bytes(2 * buffer.length); // worst case scenario\n uint256 outputLength = 0;\n\n for (uint256 i; i < buffer.length; ++i) {\n bytes1 char = bytes1(_unsafeReadBytesOffset(buffer, i));\n if (((SPECIAL_CHARS_LOOKUP & (1 << uint8(char))) != 0)) {\n output[outputLength++] = \"\\\\\";\n if (char == 0x08) output[outputLength++] = \"b\";\n else if (char == 0x09) output[outputLength++] = \"t\";\n else if (char == 0x0a) output[outputLength++] = \"n\";\n else if (char == 0x0c) output[outputLength++] = \"f\";\n else if (char == 0x0d) output[outputLength++] = \"r\";\n else if (char == 0x5c) output[outputLength++] = \"\\\\\";\n else if (char == 0x22) {\n // solhint-disable-next-line quotes\n output[outputLength++] = '\"';\n }\n } else {\n output[outputLength++] = char;\n }\n }\n // write the actual length and deallocate unused memory\n assembly (\"memory-safe\") {\n mstore(output, outputLength)\n mstore(0x40, add(output, shl(5, shr(5, add(outputLength, 63)))))\n }\n\n return string(output);\n }\n\n /**\n * @dev Reads a bytes32 from a bytes array without bounds checking.\n *\n * NOTE: making this function internal would mean it could be used with memory unsafe offset, and marking the\n * assembly block as such would prevent some optimizations.\n */\n function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {\n // This is not memory safe in the general case, but all calls to this private function are within bounds.\n assembly (\"memory-safe\") {\n value := mload(add(buffer, add(0x20, offset)))\n }\n }\n}\n" + }, + "project/contracts/Controller.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\n\nimport './interfaces/IController.sol';\n\n/**\n * @title Controller\n * @dev Manages allow lists for solvers, executors, proposal signers and validators\n */\ncontract Controller is IController, Ownable {\n // List of allowed solvers\n mapping (address => bool) public override isSolverAllowed;\n\n // List of allowed executors\n mapping (address => bool) public override isExecutorAllowed;\n\n // List of allowed proposal signers\n mapping (address => bool) public override isProposalSignerAllowed;\n\n // List of allowed validators\n mapping (address => bool) public override isValidatorAllowed;\n\n // Minimum number of validations allowed\n uint8 public override minValidations;\n\n /**\n * @dev Creates a new Controller contract\n * @param owner Address that will own the contract\n * @param solvers List of allowed solvers\n * @param executors List of allowed executors\n * @param proposalSigners List of allowed proposal signers\n * @param validators List of allowed validators\n * @param _minValidations Minimum number of validations allowed\n */\n constructor(\n address owner,\n address[] memory solvers,\n address[] memory executors,\n address[] memory proposalSigners,\n address[] memory validators,\n uint8 _minValidations\n ) Ownable(owner) {\n for (uint256 i = 0; i < solvers.length; i++) _setAllowedSolver(solvers[i], true);\n for (uint256 i = 0; i < executors.length; i++) _setAllowedExecutor(executors[i], true);\n for (uint256 i = 0; i < proposalSigners.length; i++) _setAllowedProposalSigner(proposalSigners[i], true);\n for (uint256 i = 0; i < validators.length; i++) _setAllowedValidator(validators[i], true);\n _setMinValidations(_minValidations);\n }\n\n /**\n * @dev Sets permissions for multiple solvers\n * @param solvers List of solver addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedSolvers(address[] memory solvers, bool[] memory alloweds) external override onlyOwner {\n if (solvers.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < solvers.length; i++) _setAllowedSolver(solvers[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple executors\n * @param executors List of executor addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedExecutors(address[] memory executors, bool[] memory alloweds) external override onlyOwner {\n if (executors.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < executors.length; i++) _setAllowedExecutor(executors[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple proposal signers\n * @param signers List of proposal signer addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedProposalSigners(address[] memory signers, bool[] memory alloweds) external override onlyOwner {\n if (signers.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < signers.length; i++) _setAllowedProposalSigner(signers[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple validators\n * @param validators List of validator addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedValidators(address[] memory validators, bool[] memory alloweds) external override onlyOwner {\n if (validators.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < validators.length; i++) _setAllowedValidator(validators[i], alloweds[i]);\n }\n\n /**\n * @dev Sets the minimum number of validations allowed\n * @param newMinValidations minimum number of validations allowed\n */\n function setMinValidations(uint8 newMinValidations) external override onlyOwner {\n _setMinValidations(newMinValidations);\n }\n\n /**\n * @dev Sets a solver permission\n */\n function _setAllowedSolver(address solver, bool allowed) internal {\n isSolverAllowed[solver] = allowed;\n emit SolverAllowedSet(solver, allowed);\n }\n\n /**\n * @dev Sets an executor permission\n */\n function _setAllowedExecutor(address executor, bool allowed) internal {\n isExecutorAllowed[executor] = allowed;\n emit ExecutorAllowedSet(executor, allowed);\n }\n\n /**\n * @dev Sets a proposal signer permission\n */\n function _setAllowedProposalSigner(address signer, bool allowed) internal {\n isProposalSignerAllowed[signer] = allowed;\n emit ProposalSignerAllowedSet(signer, allowed);\n }\n\n /**\n * @dev Sets a validator permission\n */\n function _setAllowedValidator(address validator, bool allowed) internal {\n isValidatorAllowed[validator] = allowed;\n emit ValidatorAllowedSet(validator, allowed);\n }\n\n /**\n * @dev Sets the minimum number of validations allowed\n */\n function _setMinValidations(uint8 newMinValidations) internal {\n minValidations = newMinValidations;\n emit MinValidationSet(newMinValidations);\n }\n}\n" + }, + "project/contracts/Intents.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Enum representing the type of intent operation.\n * - Swap: Swap tokens between chains or tokens.\n * - Transfer: Transfer tokens to one or more recipients.\n * - Call: Execute arbitrary contract calls.\n */\nenum OpType {\n Swap,\n Transfer,\n Call\n}\n\n/**\n * @dev Execution structure.\n * @param intent Intent to be fulfilled.\n * @param proposal Proposal to be executed.\n * @param signature Proposal signature.\n */\nstruct Execution {\n Intent intent;\n Proposal proposal;\n bytes signature;\n}\n\n/**\n * @dev EIP-712 typed data struct representing a validator's approval of an intent.\n * @param intent The hash of the intent being validated.\n */\nstruct Validation {\n bytes32 intent;\n}\n\n/**\n * @dev General intent structure used to abstract over different intent types.\n * @param op The type of operation this intent represents.\n * @param user The originator of the intent.\n * @param settler The address responsible for executing the intent on-chain.\n * @param nonce A unique value used to prevent replay attacks and distinguish intents.\n * @param deadline The timestamp by which the intent must be executed.\n * @param data ABI-encoded data representing a specific intent type (e.g. SwapIntent, TransferIntent, CallIntent).\n * @param maxFees List of max fees the user is willing to pay for the intent.\n * @param events List of custom intent events to be emitted.\n * @param configSig The signature of the configuration that this intent belongs to\n * @param minValidations The minimum number of validator approvals required for this intent to be considered valid.\n * @param validations The list validator signatures attesting to this intent.\n */\nstruct Intent {\n uint8 op;\n address user;\n address settler;\n bytes32 nonce;\n uint256 deadline;\n bytes data;\n MaxFee[] maxFees;\n IntentEvent[] events;\n bytes configSig;\n uint256 minValidations;\n bytes[] validations;\n}\n\n/**\n * @dev Max fee representation\n * @param token Token used to pay for the execution fee.\n * @param amount Max amount of fee token to be paid for settling this intent.\n */\nstruct MaxFee {\n address token;\n uint256 amount;\n}\n\n/**\n * @dev Intent event representation.\n * @param topic Event topic to be emitted.\n * @param data Event data to be emitted.\n */\nstruct IntentEvent {\n bytes32 topic;\n bytes data;\n}\n\n/**\n * @dev Represents a swap intent between two chains.\n * @param sourceChain Chain ID where tokens will be sent from.\n * @param destinationChain Chain ID where tokens will be received.\n * @param tokensIn List of input tokens and amounts to swap.\n * @param tokensOut List of expected output tokens, minimum amounts, and recipients.\n */\nstruct SwapIntent {\n uint256 sourceChain;\n uint256 destinationChain;\n TokenIn[] tokensIn;\n TokenOut[] tokensOut;\n}\n\n/**\n * @dev Token in representation.\n * @param token Address of a token to be sent.\n * @param amount Amount of tokens to be sent.\n */\nstruct TokenIn {\n address token;\n uint256 amount;\n}\n\n/**\n * @dev Token out representation.\n * @param token Address of a token to be received.\n * @param minAmount Minimum amount of tokens to be received.\n * @param recipient Recipient address that will receive the token out.\n */\nstruct TokenOut {\n address token;\n uint256 minAmount;\n address recipient;\n}\n\n/**\n * @dev Represents a transfer intent containing multiple token transfers.\n * @param chainId Chain ID where the transfers should be executed.\n * @param transfers List of token transfers to be performed.\n */\nstruct TransferIntent {\n uint256 chainId;\n TransferData[] transfers;\n}\n\n/**\n * @dev Transfer data for a single token transfer.\n * @param token Address of the token to transfer.\n * @param amount Amount of the token to transfer.\n * @param recipient Recipient of the token transfer.\n */\nstruct TransferData {\n address token;\n uint256 amount;\n address recipient;\n}\n\n/**\n * @dev Represents a generic call intent consisting of one or more contract calls.\n * @param chainId Chain ID where the calls should be executed.\n * @param calls List of low-level contract calls to be executed.\n */\nstruct CallIntent {\n uint256 chainId;\n CallData[] calls;\n}\n\n/**\n * @dev Low-level call data for a target contract interaction.\n * @param target Target contract address.\n * @param data Calldata to be sent to the target.\n * @param value ETH value to send along with the call.\n */\nstruct CallData {\n address target;\n bytes data;\n uint256 value;\n}\n\n/**\n * @dev Generic proposal structure representing a solver’s response to an intent.\n * @param deadline Timestamp until when the proposal is valid.\n * @param data ABI-encoded proposal-specific data (e.g. SwapProposal).\n * @param fees List of fee amounts the solver requires for execution.\n */\nstruct Proposal {\n uint256 deadline;\n bytes data;\n uint256[] fees;\n}\n\n/**\n * @dev Swap proposal representation for a swap intent.\n * @param executor Address of the executor contract that should be called during intent execution.\n * @param data Arbitrary data used to call the executor contract.\n * @param amountsOut List of amounts of tokens out proposed by the solver.\n */\nstruct SwapProposal {\n address executor;\n bytes data;\n uint256[] amountsOut;\n}\n\nlibrary IntentsHelpers {\n bytes32 internal constant INTENT_TYPE_HASH =\n keccak256(\n 'Intent(uint8 op,address user,address settler,bytes32 nonce,uint256 deadline,bytes data,MaxFee[] maxFees,IntentEvent[] events,bytes configSig,uint256 minValidations)IntentEvent(bytes32 topic,bytes data)MaxFee(address token,uint256 amount)'\n );\n\n bytes32 internal constant PROPOSAL_TYPE_HASH =\n keccak256('Proposal(bytes32 intent,address solver,uint256 deadline,bytes data,uint256[] fees)');\n\n bytes32 internal constant VALIDATION_TYPE_HASH = keccak256('Validation(bytes32 intent)');\n\n bytes32 internal constant MAX_FEE_TYPE_HASH = keccak256('MaxFee(address token,uint256 amount)');\n\n bytes32 internal constant INTENT_EVENT_TYPE_HASH = keccak256('IntentEvent(bytes32 topic,bytes data)');\n\n function hash(Intent memory intent) internal pure returns (bytes32) {\n return\n keccak256(\n abi.encode(\n INTENT_TYPE_HASH,\n intent.op,\n intent.user,\n intent.settler,\n intent.nonce,\n intent.deadline,\n keccak256(intent.data),\n hash(intent.maxFees),\n hash(intent.events),\n intent.configSig,\n intent.minValidations\n )\n );\n }\n\n function hash(Proposal memory proposal, Intent memory intent, address solver) internal pure returns (bytes32) {\n return\n keccak256(\n abi.encode(\n PROPOSAL_TYPE_HASH,\n hash(intent),\n solver,\n proposal.deadline,\n keccak256(proposal.data),\n hash(proposal.fees)\n )\n );\n }\n\n function hash(MaxFee[] memory fees) internal pure returns (bytes32) {\n bytes32[] memory hashes = new bytes32[](fees.length);\n for (uint256 i = 0; i < fees.length; i++) {\n hashes[i] = keccak256(abi.encode(MAX_FEE_TYPE_HASH, fees[i].token, fees[i].amount));\n }\n return keccak256(abi.encodePacked(hashes));\n }\n\n function hash(IntentEvent[] memory events) internal pure returns (bytes32) {\n bytes32[] memory hashes = new bytes32[](events.length);\n for (uint256 i = 0; i < events.length; i++) {\n hashes[i] = keccak256(abi.encode(INTENT_EVENT_TYPE_HASH, events[i].topic, keccak256(events[i].data)));\n }\n return keccak256(abi.encodePacked(hashes));\n }\n\n function hash(uint256[] memory fees) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(fees));\n }\n\n function hash(Validation memory validation) internal pure returns (bytes32) {\n return keccak256(abi.encode(VALIDATION_TYPE_HASH, validation.intent));\n }\n}\n" + }, + "project/contracts/interfaces/IController.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @title Controller interface\n */\ninterface IController {\n /**\n * @dev The input arrays are not of equal length\n */\n error ControllerInputInvalidLength();\n\n /**\n * @dev Emitted every time a solver permission is set\n */\n event SolverAllowedSet(address indexed solver, bool allowed);\n\n /**\n * @dev Emitted every time an executor permission is set\n */\n event ExecutorAllowedSet(address indexed executor, bool allowed);\n\n /**\n * @dev Emitted every time a proposal signer permission is set\n */\n event ProposalSignerAllowedSet(address indexed proposalSigner, bool allowed);\n\n /**\n * @dev Emitted every time a validator permission is set\n */\n event ValidatorAllowedSet(address indexed validator, bool allowed);\n\n /**\n * @dev Emitted when the minimum validations changes\n */\n event MinValidationSet(uint8 indexed newMinValidation);\n\n /**\n * @dev Tells whether a solver is allowed\n * @param solver Address of the solver being queried\n */\n function isSolverAllowed(address solver) external view returns (bool);\n\n /**\n * @dev Tells whether an executor is allowed\n * @param executor Address of the executor being queried\n */\n function isExecutorAllowed(address executor) external view returns (bool);\n\n /**\n * @dev Tells whether a proposal signer is allowed\n * @param signer Address of the proposal signer being queried\n */\n function isProposalSignerAllowed(address signer) external view returns (bool);\n\n /**\n * @dev Tells whether a validator is allowed\n * @param validator Address of the validator being queried\n */\n function isValidatorAllowed(address validator) external view returns (bool);\n\n /**\n * @dev Tells the minimum number of validations allowed\n */\n function minValidations() external view returns (uint8);\n\n /**\n * @dev Sets permissions for multiple solvers\n * @param solvers List of solver addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedSolvers(address[] memory solvers, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple executors\n * @param executors List of executor addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedExecutors(address[] memory executors, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple proposal signers\n * @param signers List of proposal signer addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedProposalSigners(address[] memory signers, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple validators\n * @param validators List of validator addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedValidators(address[] memory validators, bool[] memory alloweds) external;\n\n /**\n * @dev Sets the minimum number of validations allowed\n * @param newMinValidations minimum number of validations allowed\n */\n function setMinValidations(uint8 newMinValidations) external;\n}\n" + }, + "project/contracts/interfaces/ICreateX.sol": { + "content": "// SPDX-License-Identifier: AGPL-3.0-only\n\npragma solidity ^0.8.4;\n\n/**\n * @title CreateX Factory Interface Definition\n * @author pcaversaccio (https://web.archive.org/web/20230921103111/https://pcaversaccio.com/)\n * @custom:coauthor Matt Solomon (https://web.archive.org/web/20230921103335/https://mattsolomon.dev/)\n */\ninterface ICreateX {\n event ContractCreation(address indexed newContract);\n\n function deployCreate3(bytes32 salt, bytes memory initCode) external payable returns (address newContract);\n}\n" + }, + "project/contracts/interfaces/IExecutor.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\n\n/**\n * @title Executor interface\n */\ninterface IExecutor {\n /**\n * @dev Executes an intent proposal\n * @param intent Intent to be executed\n * @param proposal Proposal to be executed to fulfill the intent\n */\n function execute(Intent memory intent, Proposal memory proposal) external;\n}\n" + }, + "project/contracts/interfaces/IIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\nimport '../safeguards/Safeguards.sol';\n\n/**\n * @title IntentsValidator\n * @dev Performs intents validations based on safeguards\n */\ninterface IIntentsValidator {\n /**\n * @dev Validates an intent for a safeguard\n * @param intent Intent to be validated\n * @param config Safeguard config to validate the intent with\n */\n function validate(Intent memory intent, bytes memory config) external pure;\n}\n" + }, + "project/contracts/interfaces/ISafe.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nenum SafeOperation {\n Call,\n DelegateCall\n}\n\ninterface ISafe {\n function getThreshold() external view returns (uint256);\n\n function execTransactionFromModuleReturnData(address to, uint256 value, bytes memory data, SafeOperation operation)\n external\n returns (bool success, bytes memory returnData);\n}\n" + }, + "project/contracts/interfaces/ISettler.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\nimport '../safeguards/Safeguards.sol';\n\n/**\n * @title Settler interface\n */\ninterface ISettler {\n /**\n * @dev The requested intent type is unknown\n */\n error SettlerUnknownIntentType(uint8 op);\n\n /**\n * @dev The simulation has been successful\n */\n error SettlerSimulationSuccess(uint256 gasUsed);\n\n /**\n * @dev The solver is not allowed\n */\n error SettlerSolverNotAllowed(address solver);\n\n /**\n * @dev The executor is not allowed\n */\n error SettlerExecutorNotAllowed(address executor);\n\n /**\n * @dev The proposal signer is not allowed\n */\n error SettlerProposalSignerNotAllowed(address signer);\n\n /**\n * @dev The validator is not allowed\n */\n error SettlerValidatorNotAllowed(address validator);\n\n /**\n * @dev The validator is duplicated\n */\n error SettlerValidatorDuplicatedOrUnsorted(address previous, address current);\n\n /**\n * @dev The settler is not the current contract\n */\n error SettlerInvalidSettler(address settler);\n\n /**\n * @dev The nonce is zero\n */\n error SettlerNonceZero();\n\n /**\n * @dev The nonce has already been used for the user\n */\n error SettlerNonceAlreadyUsed(address user, bytes32 nonce);\n\n /**\n * @dev The intent deadline is in the past\n */\n error SettlerIntentPastDeadline(uint256 deadline, uint256 timestamp);\n\n /**\n * @dev The current chain is not valid\n */\n error SettlerInvalidChain(uint256 chainId);\n\n /**\n * @dev The recipient is the settler contract\n */\n error SettlerInvalidRecipient(address to);\n\n /**\n * @dev The user is not a smart account\n */\n error SettlerUserNotSmartAccount(address user);\n\n /**\n * @dev The amount out is lower than the proposed amount\n */\n error SettlerAmountOutLtProposed(uint256 index, uint256 amountOut, uint256 proposed);\n\n /**\n * @dev The proposed amount is lower than the minimum amount\n */\n error SettlerProposedAmountLtMinAmount(uint256 index, uint256 proposed, uint256 minAmount);\n\n /**\n * @dev The proposed amounts array and the tokens out array are not of equal length\n */\n error SettlerInvalidProposedAmounts();\n\n /**\n * @dev The balance after the proposal execution is lower than the balance before\n */\n error SettlerPostBalanceOutLtPre(uint256 index, uint256 post, uint256 pre);\n\n /**\n * @dev The solver fees length does not match the requested by the user\n */\n error SettlerSolverFeeInvalidLength();\n\n /**\n * @dev The solver fee is too high\n */\n error SettlerSolverFeeTooHigh(uint256 fee, uint256 max);\n\n /**\n * @dev The intent validations are not enough\n */\n error SettlerIntentValidationsNotEnough(uint256 min, uint256 current);\n\n /**\n * @dev The proposal deadline is in the past\n */\n error SettlerProposalPastDeadline(uint256 deadline, uint256 timestamp);\n\n /**\n * @dev The proposal data is not empty\n */\n error SettlerProposalDataNotEmpty();\n\n /**\n * @dev The rescue funds recipient is zero\n */\n error SettlerRescueFundsRecipientZero();\n\n /**\n * @dev The list of safeguards exceed the maximum allowed\n */\n error SettlerTooManySafeguards(uint256 lengthRequested);\n\n /**\n * @dev The new smart accounts handler is zero\n */\n error SmartAccountsHandlerZero();\n\n /**\n * @dev Custom events emitted for each intent\n */\n event IntentExecuted(\n address indexed user,\n bytes32 indexed topic,\n uint8 indexed op,\n Intent intent,\n Proposal proposal,\n bytes output,\n bytes data\n );\n\n /**\n * @dev Emitted every time an intent is fulfilled\n */\n event ProposalExecuted(bytes32 indexed proposal, uint256 index);\n\n /**\n * @dev Emitted every time tokens are withdrawn from the contract balance\n */\n event FundsRescued(address indexed token, address indexed recipient, uint256 amount);\n\n /**\n * @dev Emitted every time the smart accounts handler is set\n */\n event SmartAccountsHandlerSet(address indexed smartAccountsHandler);\n\n /**\n * @dev Emitted every time the intents validator is set\n */\n event IntentsValidatorSet(address indexed intentsValidator);\n\n /**\n * @dev Emitted every time a safeguard is set\n */\n event SafeguardSet(address indexed user);\n\n /**\n * @dev Tells the reference to the Mimic controller\n */\n function controller() external view returns (address);\n\n /**\n * @dev Tells the reference to the smart accounts handler\n */\n function smartAccountsHandler() external view returns (address);\n\n /**\n * @dev Tells the reference to the intents validator\n */\n function intentsValidator() external view returns (address);\n\n /**\n * @dev Tells the block at which a user nonce was used. Returns 0 if unused.\n * @param user Address of the user being queried\n * @param nonce Nonce being queried\n */\n function getNonceBlock(address user, bytes32 nonce) external view returns (uint256);\n\n /**\n * @dev Tells the safeguard set for a user\n * @param user Address of the user being queried\n */\n function getUserSafeguard(address user) external view returns (bytes memory);\n\n /**\n * @dev Tells the hash of an intent\n * @param intent Intent to get the hash of\n */\n function getIntentHash(Intent memory intent) external pure returns (bytes32);\n\n /**\n * @dev Tells the hash of a proposal\n * @param proposal Proposal to be hashed\n * @param intent Intent being fulfilled by the requested proposal\n * @param solver Address of the solver that made the proposal\n */\n function getProposalHash(Proposal memory proposal, Intent memory intent, address solver)\n external\n pure\n returns (bytes32);\n\n /**\n * @dev Withdraws ERC20 or native tokens from the contract\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function rescueFunds(address token, address recipient, uint256 amount) external;\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function setSmartAccountsHandler(address newSmartAccountsHandler) external;\n\n /**\n * @dev Sets a new intents validator address\n * @param newIntentsValidator New intents validator to be set\n */\n function setIntentsValidator(address newIntentsValidator) external;\n\n /**\n * @dev Sets a safeguard for a user\n * @param safeguard Safeguard to be set\n */\n function setSafeguard(bytes memory safeguard) external;\n\n /**\n * @dev Executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function execute(Execution[] memory executions) external;\n\n /**\n * @dev Simulates an execution. It will always revert. Successful executions are returned as\n * `SettlerSimulationSuccess` errors. Any other error should be treated as failure.\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function simulate(Execution[] memory executions) external;\n}\n" + }, + "project/contracts/interfaces/ISmartAccount.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/introspection/IERC165.sol';\n\n/**\n * @title SmartAccount interface\n */\ninterface ISmartAccount is IERC165 {\n /**\n * @dev Emitted every time tokens are transferred\n */\n event Transferred(address indexed token, address indexed recipient, uint256 amount);\n\n /**\n * @dev Emitted every time `call` is called\n */\n event Called(address indexed target, bytes data, uint256 value, bytes result);\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the owner or the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) external;\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the owner or the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n */\n function call(address target, bytes memory data, uint256 value) external returns (bytes memory result);\n}\n" + }, + "project/contracts/interfaces/ISmartAccountContract.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/interfaces/IERC1271.sol';\n\nimport './ISmartAccount.sol';\n\n/**\n * @title SmartAccountContract interface\n */\ninterface ISmartAccountContract is ISmartAccount, IERC1271 {\n // solhint-disable-previous-line no-empty-blocks\n}\n" + }, + "project/contracts/interfaces/ISmartAccountsHandler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\ninterface ISmartAccountsHandler {\n /**\n * @dev The smart account given is not supported\n */\n error SmartAccountsHandlerUnsupportedAccount(address account);\n\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address account) external view returns (bool);\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address account, address token, address to, uint256 amount) external;\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address account, address target, bytes memory data, uint256 value) external returns (bytes memory);\n}\n" + }, + "project/contracts/safeguards/BaseIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @title BaseIntentsValidator\n */\ncontract BaseIntentsValidator {\n /**\n * @dev No intents allowed\n */\n error IntentsValidatorNoneAllowed();\n\n /**\n * @dev Intent type unknown\n */\n error IntentsValidatorUnknownIntentType(uint8 opType);\n\n /**\n * @dev Invalid safeguard mode\n */\n error IntentsValidatorInvalidSafeguardMode(uint8 mode);\n\n /**\n * @dev Tells whether a chain is allowed\n */\n function _isChainAllowed(uint256 chainId, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, uint256[] memory values) = abi.decode(config, (bool, uint256[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (chainId == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (chainId == values[i]) return true;\n }\n return false;\n }\n }\n\n /**\n * @dev Tells whether an account is allowed\n */\n function _isAccountAllowed(address account, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, address[] memory values) = abi.decode(config, (bool, address[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (account == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (account == values[i]) return true;\n }\n return false;\n }\n }\n\n /**\n * @dev Tells whether a selector is allowed\n */\n function _isSelectorAllowed(bytes4 selector, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, bytes4[] memory values) = abi.decode(config, (bool, bytes4[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (selector == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (selector == values[i]) return true;\n }\n return false;\n }\n }\n}\n" + }, + "project/contracts/safeguards/CallIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './Safeguards.sol';\nimport './BaseIntentsValidator.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Call safeguard modes to validate call intents\n * @param None To ensure no calls are allowed\n * @param Chain To validate that the chain where calls execute is allowed\n * @param Target To validate that the call targets (contract addresses) are allowed\n * @param Selector To validate that the function selectors being called are allowed\n */\nenum CallSafeguardMode {\n None,\n Chain,\n Target,\n Selector\n}\n\n/**\n * @title CallIntentsValidator\n * @dev Performs call intents validations based on safeguards\n */\ncontract CallIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a call intent is valid for a safeguard\n * @param intent Call intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isCallIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n CallIntent memory callIntent = abi.decode(intent.data, (CallIntent));\n if (safeguard.mode == uint8(CallSafeguardMode.Chain))\n return _isChainAllowed(callIntent.chainId, safeguard.config);\n if (safeguard.mode == uint8(CallSafeguardMode.Target))\n return _areCallTargetsValid(callIntent.calls, safeguard.config);\n if (safeguard.mode == uint8(CallSafeguardMode.Selector))\n return _areCallSelectorsValid(callIntent.calls, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the call targets are allowed\n */\n function _areCallTargetsValid(CallData[] memory calls, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < calls.length; i++) {\n if (!_isAccountAllowed(calls[i].target, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the call selectors are allowed\n */\n function _areCallSelectorsValid(CallData[] memory calls, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < calls.length; i++) {\n if (!_isSelectorAllowed(bytes4(calls[i].data), config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/safeguards/IntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './CallIntentsValidator.sol';\nimport './TransferIntentsValidator.sol';\nimport './Safeguards.sol';\nimport './SwapIntentsValidator.sol';\nimport '../Intents.sol';\nimport '../interfaces/IIntentsValidator.sol';\n\n/**\n * @title IntentsValidator\n * @dev Performs intents validations based on safeguards\n */\ncontract IntentsValidator is IIntentsValidator, SwapIntentsValidator, TransferIntentsValidator, CallIntentsValidator {\n /**\n * @dev Safeguard validation failed\n */\n error IntentsValidatorSafeguardFailed();\n\n /**\n * @dev Invalid safeguard config mode\n */\n error IntentsValidatorInvalidSafeguardConfigMode(uint8 mode);\n\n /**\n * @dev Invalid safeguard group logic mode\n */\n error IntentsValidatorInvalidSafeguardGroupLogicMode(uint8 mode);\n\n /**\n * @dev Tells whether an intent is valid for a safeguard\n * @param intent Intent to be validated\n * @param config Safeguard config to validate the intent with\n */\n function validate(Intent memory intent, bytes memory config) external pure override {\n (uint8 mode, bytes memory safeguard) = abi.decode(config, (uint8, bytes));\n if (mode == uint8(SafeguardConfigMode.List)) _validate(intent, abi.decode(safeguard, (Safeguard[])));\n else if (mode == uint8(SafeguardConfigMode.Tree)) _validate(intent, _decodeSafeguardTree(safeguard));\n else revert IntentsValidatorInvalidSafeguardConfigMode(mode);\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguards list\n * @param intent Intent to be validated\n * @param safeguards Safeguard list to validate the intent with\n */\n function _validate(Intent memory intent, Safeguard[] memory safeguards) internal pure {\n if (safeguards.length == 0) revert IntentsValidatorSafeguardFailed();\n for (uint256 i = 0; i < safeguards.length; i++) {\n if (!_isSafeguardValid(intent, safeguards[i])) revert IntentsValidatorSafeguardFailed();\n }\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard tree\n * @param intent Intent to be validated\n * @param tree Safeguard tree to validate the intent with\n */\n function _validate(Intent memory intent, SafeguardTree memory tree) internal pure {\n if (tree.nodes.length == 0) revert IntentsValidatorSafeguardFailed();\n if (!_isSafeguardGroupValid(intent, tree, 0)) revert IntentsValidatorSafeguardFailed();\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard tree at a certain level\n * @param intent Intent to be validated\n * @param tree Safeguard tree to validate the intent with\n * @param index Index of the group node to evaluate\n */\n function _isSafeguardGroupValid(Intent memory intent, SafeguardTree memory tree, uint16 index)\n internal\n pure\n returns (bool)\n {\n SafeguardGroup memory group = tree.nodes[index];\n\n if (group.logic == uint8(SafeguardGroupLogic.NOT)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i])) return false;\n }\n return true;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.AND)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (!_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (!_isSafeguardGroupValid(intent, tree, group.children[i])) return false;\n }\n return true;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.OR)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return true;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i])) return true;\n }\n return false;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.XOR)) {\n uint256 hits = 0;\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]]))\n if (++hits > 1) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i]))\n if (++hits > 1) return false;\n }\n return hits == 1;\n }\n\n revert IntentsValidatorInvalidSafeguardGroupLogicMode(group.logic);\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard\n * @param intent Intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isSafeguardValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n if (safeguard.mode == uint8(0)) revert IntentsValidatorNoneAllowed();\n if (intent.op == uint8(OpType.Swap)) return _isSwapIntentValid(intent, safeguard);\n if (intent.op == uint8(OpType.Transfer)) return _isTransferIntentValid(intent, safeguard);\n if (intent.op == uint8(OpType.Call)) return _isCallIntentValid(intent, safeguard);\n revert IntentsValidatorUnknownIntentType(uint8(intent.op));\n }\n\n /**\n * @dev Safely decodes a safeguard tree avoiding compiler issues with dynamic arrays\n * @param data Safeguard tree data to be decoded\n */\n function _decodeSafeguardTree(bytes memory data) private pure returns (SafeguardTree memory) {\n (SafeguardGroup[] memory nodes, Safeguard[] memory leaves) = abi.decode(data, (SafeguardGroup[], Safeguard[]));\n return SafeguardTree(nodes, leaves);\n }\n}\n" + }, + "project/contracts/safeguards/Safeguards.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Safeguard config modes\n * - List: Safeguard lists\n * - Tree: Safeguard groups\n */\nenum SafeguardConfigMode {\n List,\n Tree\n}\n\n/**\n * @dev Logical operators for safeguard groups\n * - AND: every child must pass\n * - OR: at least one child must pass\n * - XOR: exactly one child must pass\n * - NOT: every child must fail\n */\nenum SafeguardGroupLogic {\n AND,\n OR,\n XOR,\n NOT\n}\n\n/**\n * @dev Flat node in the safeguard tree\n * @param logic Group operator (AND/OR/XOR/NOT)\n * @param leaves Indices into `SafeguardTree.leaves`\n * @param children Indices into `SafeguardTree.nodes`\n */\nstruct SafeguardGroup {\n uint8 logic;\n uint16[] leaves;\n uint16[] children;\n}\n\n/**\n * @dev Safeguard tree representation\n * @param nodes List of all the nodes in the tree\n * @param leaves List of all the leaves in the tree\n */\nstruct SafeguardTree {\n SafeguardGroup[] nodes;\n Safeguard[] leaves;\n}\n\n/**\n * @dev Safeguard representation\n * @param mode Safeguard mode\n * @param config Safeguard configuration settings or parameters\n */\nstruct Safeguard {\n uint8 mode;\n bytes config;\n}\n" + }, + "project/contracts/safeguards/SwapIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './BaseIntentsValidator.sol';\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Swap safeguard modes to validate swap intents\n * @param None To ensure no swaps are allowed\n * @param SourceChain To validate that the source chain is allowed\n * @param DestinationChain To validate that the destination chain is allowed\n * @param TokenIn To validate that the tokens to be sent are allowed\n * @param TokenOut To validate that the tokens to be received are allowed\n * @param Recipient To validate that the recipients that will receive the tokens are allowed\n */\nenum SwapSafeguardMode {\n None,\n SourceChain,\n DestinationChain,\n TokenIn,\n TokenOut,\n Recipient\n}\n\n/**\n * @title SwapIntentsValidator\n * @dev Performs swap intents validations based on safeguards\n */\ncontract SwapIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a swap intent is valid for a safeguard\n * @param intent Swap intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isSwapIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n if (safeguard.mode == uint8(SwapSafeguardMode.SourceChain))\n return _isChainAllowed(swapIntent.sourceChain, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.DestinationChain))\n return _isChainAllowed(swapIntent.destinationChain, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.TokenIn))\n return _areSwapTokensInValid(swapIntent.tokensIn, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.TokenOut))\n return _areSwapTokensOutValid(swapIntent.tokensOut, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.Recipient))\n return _areSwapRecipientsValid(swapIntent.tokensOut, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the tokens to be sent are allowed\n */\n function _areSwapTokensInValid(TokenIn[] memory tokensIn, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensIn.length; i++) {\n if (!_isAccountAllowed(tokensIn[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the tokens to be received are allowed\n */\n function _areSwapTokensOutValid(TokenOut[] memory tokensOut, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensOut.length; i++) {\n if (!_isAccountAllowed(tokensOut[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the recipients to be received are allowed\n */\n function _areSwapRecipientsValid(TokenOut[] memory tokensOut, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensOut.length; i++) {\n if (!_isAccountAllowed(tokensOut[i].recipient, config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/safeguards/TransferIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './BaseIntentsValidator.sol';\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Transfer safeguard modes to validate transfer intents\n * @param None To ensure no transfers are allowed\n * @param Chain To validate that the chain where transfers execute is allowed\n * @param Token To validate that the tokens being transferred are allowed\n * @param Recipient To validate that the recipients of the transfers are allowed\n */\nenum TransferSafeguardMode {\n None,\n Chain,\n Token,\n Recipient\n}\n\n/**\n * @title TransferIntentsValidator\n * @dev Performs transfer intents validations based on safeguards\n */\ncontract TransferIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a transfer intent is valid for a safeguard\n * @param intent Transfer intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isTransferIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n TransferIntent memory transferIntent = abi.decode(intent.data, (TransferIntent));\n if (safeguard.mode == uint8(TransferSafeguardMode.Chain))\n return _isChainAllowed(transferIntent.chainId, safeguard.config);\n if (safeguard.mode == uint8(TransferSafeguardMode.Token))\n return _areTransferTokensValid(transferIntent.transfers, safeguard.config);\n if (safeguard.mode == uint8(TransferSafeguardMode.Recipient))\n return _areTransferRecipientsValid(transferIntent.transfers, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the tokens being transferred are allowed\n */\n function _areTransferTokensValid(TransferData[] memory transfers, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < transfers.length; i++) {\n if (!_isAccountAllowed(transfers[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the recipients of the transfers are allowed\n */\n function _areTransferRecipientsValid(TransferData[] memory transfers, bytes memory config)\n private\n pure\n returns (bool)\n {\n for (uint256 i = 0; i < transfers.length; i++) {\n if (!_isAccountAllowed(transfers[i].recipient, config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/Settler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/cryptography/ECDSA.sol';\nimport '@openzeppelin/contracts/utils/cryptography/EIP712.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165Checker.sol';\n\nimport './Intents.sol';\nimport './interfaces/IController.sol';\nimport './interfaces/IIntentsValidator.sol';\nimport './interfaces/IExecutor.sol';\nimport './interfaces/ISettler.sol';\nimport './utils/Denominations.sol';\nimport './utils/ERC20Helpers.sol';\nimport './smart-accounts/SmartAccountsHandler.sol';\nimport './smart-accounts/SmartAccountsHandlerHelpers.sol';\n\n/**\n * @title Settler\n * @dev Contract that provides the appropriate context for solvers to execute proposals that fulfill user intents\n */\ncontract Settler is ISettler, Ownable, ReentrancyGuard, EIP712 {\n using SafeERC20 for IERC20;\n using IntentsHelpers for Intent;\n using IntentsHelpers for Proposal;\n using IntentsHelpers for Validation;\n using SmartAccountsHandlerHelpers for address;\n\n // Mimic controller reference\n // solhint-disable-next-line immutable-vars-naming\n address public immutable override controller;\n\n // Smart accounts handler reference\n address public override smartAccountsHandler;\n\n // Intents validator reference\n address public override intentsValidator;\n\n // List of block numbers at which a user nonce was used\n mapping (address => mapping (bytes32 => uint256)) public override getNonceBlock;\n\n // Safeguard config per user\n mapping (address => bytes) internal _userSafeguard;\n\n /**\n * @dev Modifier to tag settler functions in order to check if the sender is an allowed solver\n */\n modifier onlySolver() {\n address sender = _msgSender();\n if (!IController(controller).isSolverAllowed(sender)) revert SettlerSolverNotAllowed(sender);\n _;\n }\n\n /**\n * @dev Creates a new Settler contract\n * @param _controller Address of the Settler controller\n * @param _owner Address that will own the contract\n */\n constructor(address _controller, address _owner) Ownable(_owner) EIP712('Mimic Protocol Settler', '1') {\n controller = _controller;\n smartAccountsHandler = address(new SmartAccountsHandler());\n }\n\n /**\n * @dev Tells the hash of an intent\n * @param intent Intent to get the hash of\n */\n function getIntentHash(Intent memory intent) external pure override returns (bytes32) {\n return intent.hash();\n }\n\n /**\n * @dev Tells the hash of a proposal\n * @param proposal Proposal to be hashed\n * @param intent Intent being fulfilled by the requested proposal\n * @param solver Address of the solver that made the proposal\n */\n function getProposalHash(Proposal memory proposal, Intent memory intent, address solver)\n external\n pure\n override\n returns (bytes32)\n {\n return proposal.hash(intent, solver);\n }\n\n /**\n * @dev Tells the safeguard set for a user\n * @param user Address of the user being queried\n */\n function getUserSafeguard(address user) external view override returns (bytes memory) {\n return _userSafeguard[user];\n }\n\n /**\n * @dev It allows receiving native token transfers\n * Note: This method mainly allows supporting native tokens for swaps\n */\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n /**\n * @dev Withdraws ERC20 or native tokens from the contract\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function rescueFunds(address token, address recipient, uint256 amount) external override onlyOwner nonReentrant {\n if (recipient == address(0)) revert SettlerRescueFundsRecipientZero();\n ERC20Helpers.transfer(token, recipient, amount);\n emit FundsRescued(token, recipient, amount);\n }\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function setSmartAccountsHandler(address newSmartAccountsHandler) external override onlyOwner {\n _setSmartAccountsHandler(newSmartAccountsHandler);\n }\n\n /**\n * @dev Sets a new intents validator address\n * @param newIntentsValidator New intents validator to be set\n */\n function setIntentsValidator(address newIntentsValidator) external override onlyOwner {\n _setIntentsValidator(newIntentsValidator);\n }\n\n /**\n * @dev Sets a safeguard for a user\n * @param safeguard Safeguard to be set\n */\n function setSafeguard(bytes memory safeguard) external override {\n _setSafeguard(msg.sender, safeguard);\n }\n\n /**\n * @dev Executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function execute(Execution[] memory executions) external override onlySolver {\n _execute(executions, false);\n }\n\n /**\n * @dev Simulates an execution. It will always revert. Successful executions are returned as\n * `SettlerSimulationSuccess` errors. Any other error should be treated as failure.\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function simulate(Execution[] memory executions) external override onlySolver {\n uint256 initialGas = gasleft();\n _execute(executions, true);\n uint256 gasUsed = initialGas - gasleft();\n revert SettlerSimulationSuccess(gasUsed);\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n * @param simulated Whether the execution is a simulation\n */\n function _execute(Execution[] memory executions, bool simulated) internal nonReentrant {\n for (uint256 i = 0; i < executions.length; i++) {\n Intent memory intent = executions[i].intent;\n Proposal memory proposal = executions[i].proposal;\n bytes memory signature = executions[i].signature;\n\n _validateIntent(intent, proposal, signature, simulated);\n getNonceBlock[intent.user][intent.nonce] = block.number;\n\n if (intent.op == uint8(OpType.Swap)) _executeSwap(intent, proposal);\n else if (intent.op == uint8(OpType.Transfer)) _executeTransfer(intent, proposal);\n else if (intent.op == uint8(OpType.Call)) _executeCall(intent, proposal);\n else revert SettlerUnknownIntentType(uint8(intent.op));\n\n emit ProposalExecuted(proposal.hash(intent, _msgSender()), i);\n }\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a swap intent\n * @param intent Swap intent to be fulfilled\n * @param proposal Swap proposal to be executed\n */\n function _executeSwap(Intent memory intent, Proposal memory proposal) internal {\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n _validateSwapIntent(swapIntent, swapProposal);\n\n bool isSmartAccount = smartAccountsHandler.isSmartAccount(intent.user);\n if (swapIntent.sourceChain == block.chainid) {\n for (uint256 i = 0; i < swapIntent.tokensIn.length; i++) {\n TokenIn memory tokenIn = swapIntent.tokensIn[i];\n _transferFrom(tokenIn.token, intent.user, swapProposal.executor, tokenIn.amount, isSmartAccount);\n }\n }\n\n uint256[] memory preBalancesOut = _getTokensOutBalance(swapIntent);\n IExecutor(swapProposal.executor).execute(intent, proposal);\n\n if (swapIntent.destinationChain == block.chainid) {\n uint256[] memory outputs = new uint256[](swapIntent.tokensOut.length);\n for (uint256 i = 0; i < swapIntent.tokensOut.length; i++) {\n TokenOut memory tokenOut = swapIntent.tokensOut[i];\n uint256 postBalanceOut = ERC20Helpers.balanceOf(tokenOut.token, address(this));\n uint256 preBalanceOut = preBalancesOut[i];\n if (postBalanceOut < preBalanceOut) revert SettlerPostBalanceOutLtPre(i, postBalanceOut, preBalanceOut);\n\n outputs[i] = postBalanceOut - preBalanceOut;\n uint256 proposedAmount = swapProposal.amountsOut[i];\n if (outputs[i] < proposedAmount) revert SettlerAmountOutLtProposed(i, outputs[i], proposedAmount);\n\n ERC20Helpers.transfer(tokenOut.token, tokenOut.recipient, outputs[i]);\n }\n\n _emitIntentEvents(intent, proposal, abi.encode(outputs));\n _payFees(intent, proposal, isSmartAccount);\n }\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a transfer intent\n * @param intent Transfer intent to be fulfilled\n * @param proposal Transfer proposal to be executed\n */\n function _executeTransfer(Intent memory intent, Proposal memory proposal) internal {\n TransferIntent memory transferIntent = abi.decode(intent.data, (TransferIntent));\n _validateTransferIntent(transferIntent, proposal);\n\n bool isSmartAccount = smartAccountsHandler.isSmartAccount(intent.user);\n for (uint256 i = 0; i < transferIntent.transfers.length; i++) {\n TransferData memory transfer = transferIntent.transfers[i];\n _transferFrom(transfer.token, intent.user, transfer.recipient, transfer.amount, isSmartAccount);\n }\n\n _emitIntentEvents(intent, proposal, new bytes(0));\n _payFees(intent, proposal, isSmartAccount);\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a call intent\n * @param intent Call intent to be fulfilled\n * @param proposal Call proposal to be executed\n */\n function _executeCall(Intent memory intent, Proposal memory proposal) internal {\n CallIntent memory callIntent = abi.decode(intent.data, (CallIntent));\n _validateCallIntent(callIntent, proposal, intent.user);\n\n bytes[] memory outputs = new bytes[](callIntent.calls.length);\n for (uint256 i = 0; i < callIntent.calls.length; i++) {\n CallData memory call = callIntent.calls[i];\n // solhint-disable-next-line avoid-low-level-calls\n outputs[i] = smartAccountsHandler.call(intent.user, call.target, call.data, call.value);\n }\n\n _emitIntentEvents(intent, proposal, abi.encode(outputs));\n _payFees(intent, proposal, true);\n }\n\n /**\n * @dev Validates an intent and its corresponding proposal\n * @param intent Intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param signature Proposal signature\n * @param simulated Whether the execution is a simulation\n */\n function _validateIntent(Intent memory intent, Proposal memory proposal, bytes memory signature, bool simulated)\n internal\n view\n {\n if (intent.settler != address(this)) revert SettlerInvalidSettler(intent.settler);\n if (intent.nonce == bytes32(0)) revert SettlerNonceZero();\n if (getNonceBlock[intent.user][intent.nonce] != 0) revert SettlerNonceAlreadyUsed(intent.user, intent.nonce);\n\n if (intentsValidator != address(0)) {\n bytes memory safeguard = _userSafeguard[intent.user];\n if (safeguard.length > 0) IIntentsValidator(intentsValidator).validate(intent, safeguard);\n }\n\n bool shouldValidateDeadlines = _shouldValidateDeadlines(intent);\n if (shouldValidateDeadlines) {\n if (intent.deadline <= block.timestamp) revert SettlerIntentPastDeadline(intent.deadline, block.timestamp);\n bool isProposalPastDeadline = proposal.deadline <= block.timestamp;\n if (isProposalPastDeadline) revert SettlerProposalPastDeadline(proposal.deadline, block.timestamp);\n }\n\n if (intent.maxFees.length != proposal.fees.length) revert SettlerSolverFeeInvalidLength();\n for (uint256 i = 0; i < intent.maxFees.length; i++) {\n uint256 maxFee = intent.maxFees[i].amount;\n uint256 proposalFee = proposal.fees[i];\n if (proposalFee > maxFee) revert SettlerSolverFeeTooHigh(proposalFee, maxFee);\n }\n\n uint8 minValidations = IController(controller).minValidations();\n uint256 requiredValidations = intent.minValidations > minValidations ? intent.minValidations : minValidations;\n\n if (intent.validations.length < requiredValidations) {\n revert SettlerIntentValidationsNotEnough(requiredValidations, intent.validations.length);\n }\n\n address lastValidator = address(0);\n Validation memory validation = Validation(intent.hash());\n bytes32 typedDataHash = _hashTypedDataV4(validation.hash());\n for (uint256 i = 0; i < intent.validations.length; i++) {\n address validator = ECDSA.recover(typedDataHash, intent.validations[i]);\n if (validator <= lastValidator) {\n revert SettlerValidatorDuplicatedOrUnsorted(lastValidator, validator);\n }\n lastValidator = validator;\n bool isValidatorNotAllowed = !IController(controller).isValidatorAllowed(validator);\n if (isValidatorNotAllowed) revert SettlerValidatorNotAllowed(validator);\n }\n\n address signer = ECDSA.recover(_hashTypedDataV4(proposal.hash(intent, _msgSender())), signature);\n bool isProposalSignerNotAllowed = !IController(controller).isProposalSignerAllowed(signer) && !simulated;\n if (isProposalSignerNotAllowed) revert SettlerProposalSignerNotAllowed(signer);\n }\n\n /**\n * @dev Validates a swap intent and its corresponding proposal\n * @param intent Swap intent to be fulfilled\n * @param proposal Proposal to be executed\n */\n function _validateSwapIntent(SwapIntent memory intent, SwapProposal memory proposal) internal view {\n bool isChainInvalid = intent.sourceChain != block.chainid && intent.destinationChain != block.chainid;\n if (isChainInvalid) revert SettlerInvalidChain(block.chainid);\n\n if (proposal.amountsOut.length != intent.tokensOut.length) revert SettlerInvalidProposedAmounts();\n\n for (uint256 i = 0; i < intent.tokensOut.length; i++) {\n TokenOut memory tokenOut = intent.tokensOut[i];\n address recipient = tokenOut.recipient;\n if (recipient == address(this)) revert SettlerInvalidRecipient(recipient);\n\n uint256 minAmount = tokenOut.minAmount;\n uint256 proposedAmount = proposal.amountsOut[i];\n if (proposedAmount < minAmount) revert SettlerProposedAmountLtMinAmount(i, proposedAmount, minAmount);\n }\n\n if (intent.sourceChain != intent.destinationChain) {\n bool isExecutorInvalid = !IController(controller).isExecutorAllowed(proposal.executor);\n if (isExecutorInvalid) revert SettlerExecutorNotAllowed(proposal.executor);\n }\n }\n\n /**\n * @dev Validates a transfer intent and its corresponding proposal\n * @param intent Transfer intent to be fulfilled\n * @param proposal Proposal to be executed\n */\n function _validateTransferIntent(TransferIntent memory intent, Proposal memory proposal) internal view {\n if (intent.chainId != block.chainid) revert SettlerInvalidChain(block.chainid);\n if (proposal.data.length > 0) revert SettlerProposalDataNotEmpty();\n for (uint256 i = 0; i < intent.transfers.length; i++) {\n address recipient = intent.transfers[i].recipient;\n if (recipient == address(this)) revert SettlerInvalidRecipient(recipient);\n }\n }\n\n /**\n * @dev Validates a call intent and its corresponding proposal\n * @param intent Call intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param user The originator of the intent\n */\n function _validateCallIntent(CallIntent memory intent, Proposal memory proposal, address user) internal view {\n if (intent.chainId != block.chainid) revert SettlerInvalidChain(block.chainid);\n if (proposal.data.length > 0) revert SettlerProposalDataNotEmpty();\n if (!smartAccountsHandler.isSmartAccount(user)) revert SettlerUserNotSmartAccount(user);\n }\n\n /**\n * @dev Tells the contract balance for each token out of a swap intent\n * @param intent Swap intent containing the list of tokens out\n */\n function _getTokensOutBalance(SwapIntent memory intent) internal view returns (uint256[] memory balances) {\n balances = new uint256[](intent.tokensOut.length);\n if (intent.destinationChain == block.chainid) {\n for (uint256 i = 0; i < intent.tokensOut.length; i++) {\n balances[i] = ERC20Helpers.balanceOf(intent.tokensOut[i].token, address(this));\n }\n }\n }\n\n /**\n * @dev Tells if the intent and proposal deadlines should be validated\n * @param intent Intent to be fulfilled\n */\n function _shouldValidateDeadlines(Intent memory intent) internal view returns (bool) {\n if (intent.op != uint8(OpType.Swap)) return true;\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n if (swapIntent.sourceChain == swapIntent.destinationChain) return true;\n return swapIntent.sourceChain == block.chainid;\n }\n\n /**\n * @dev Emits intent custom events\n * @param intent Intent to emit the custom events for\n * @param proposal Proposal that fulfills the intent\n * @param output Encoded array of outputs\n */\n function _emitIntentEvents(Intent memory intent, Proposal memory proposal, bytes memory output) internal {\n for (uint256 i = 0; i < intent.events.length; i++) {\n IntentEvent memory intentEvent = intent.events[i];\n emit IntentExecuted(\n intent.user,\n intentEvent.topic,\n uint8(intent.op),\n intent,\n proposal,\n output,\n intentEvent.data\n );\n }\n }\n\n /**\n * @dev Pays fees\n * @param intent Intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param isSmartAccount Whether the intent user is a smart account\n */\n function _payFees(Intent memory intent, Proposal memory proposal, bool isSmartAccount) internal {\n address from = intent.user;\n address to = _msgSender();\n for (uint256 i = 0; i < intent.maxFees.length; i++) {\n address token = intent.maxFees[i].token;\n if (!Denominations.isUSD(token)) _transferFrom(token, from, to, proposal.fees[i], isSmartAccount);\n }\n }\n\n /**\n * @dev Transfers tokens from one account to another\n * @param token Address of the token to transfer\n * @param from Address of the account sending the tokens\n * @param to Address of the account receiving the tokens\n * @param amount Amount of tokens to transfer\n * @param isSmartAccount Whether the sender is a smart account\n */\n function _transferFrom(address token, address from, address to, uint256 amount, bool isSmartAccount) internal {\n if (isSmartAccount) {\n smartAccountsHandler.transfer(from, token, to, amount);\n } else {\n IERC20(token).safeTransferFrom(from, to, amount);\n }\n }\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function _setSmartAccountsHandler(address newSmartAccountsHandler) internal {\n if (newSmartAccountsHandler == address(0)) revert SmartAccountsHandlerZero();\n smartAccountsHandler = newSmartAccountsHandler;\n emit SmartAccountsHandlerSet(newSmartAccountsHandler);\n }\n\n /**\n * @dev Sets the intents validator\n * @param newIntentsValidator New intents validator to be set\n */\n function _setIntentsValidator(address newIntentsValidator) internal {\n intentsValidator = newIntentsValidator;\n emit IntentsValidatorSet(newIntentsValidator);\n }\n\n /**\n * @dev Sets a safeguard for a user\n * @param user Address of the user to set the safeguard for\n * @param safeguard Safeguard to be set\n */\n function _setSafeguard(address user, bytes memory safeguard) internal {\n delete _userSafeguard[user];\n _userSafeguard[user] = safeguard;\n emit SafeguardSet(user);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccount7702.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/Context.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccount.sol';\nimport '../utils/ERC20Helpers.sol';\nimport './SmartAccountBase.sol';\n\n/**\n * @title SmartAccount7702\n * @dev Provides the smart account logic to use with EIP7702\n */\ncontract SmartAccount7702 is SmartAccountBase {\n // Mimic settler reference\n // solhint-disable-next-line immutable-vars-naming\n address public immutable settler;\n\n /**\n * @dev The sender is not the settler\n */\n error SmartAccount7702SenderNotSettler();\n\n /**\n * @dev Reverts unless the sender is the settler\n */\n modifier onlySettler() {\n if (_msgSender() != settler) revert SmartAccount7702SenderNotSettler();\n _;\n }\n\n /**\n * @dev Creates a new SmartAccount7702 contract\n * @param _settler Address of the Mimic settler\n */\n constructor(address _settler) {\n settler = _settler;\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) public override onlySettler {\n super.transfer(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value) public override onlySettler returns (bytes memory) {\n // solhint-disable-next-line avoid-low-level-calls\n return super.call(target, data, value);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountBase.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/Context.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccount.sol';\nimport '../utils/ERC20Helpers.sol';\n\n/**\n * @title SmartAccountBase\n * @dev Provides the base logic for managing assets and executing arbitrary calls\n */\ncontract SmartAccountBase is ISmartAccount, Context, ERC165, ReentrancyGuard {\n /**\n * @dev Tells whether the contract supports the given interface ID. Overrides ERC165 to declare support for ISmartAccount interface.\n * @param interfaceId Interface ID is defined as the XOR of all function selectors in the interface\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {\n return interfaceId == type(ISmartAccount).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) public virtual override nonReentrant {\n ERC20Helpers.transfer(token, recipient, amount);\n emit Transferred(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value)\n public\n virtual\n override\n nonReentrant\n returns (bytes memory result)\n {\n result = Address.functionCallWithValue(target, data, value);\n emit Called(target, data, value, result);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountContract.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/cryptography/ECDSA.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccountContract.sol';\nimport './SmartAccountBase.sol';\n\n/**\n * @title SmartAccountContract\n * @dev Provides the smart account logic to use as a standalone contract\n */\ncontract SmartAccountContract is ISmartAccountContract, Ownable, SmartAccountBase {\n // EIP1271 magic return value\n bytes4 internal constant EIP1271_MAGIC_VALUE = 0x1626ba7e;\n\n // EIP1271 invalid signature return value\n bytes4 internal constant EIP1271_INVALID_SIGNATURE = 0xffffffff;\n\n // List of account permissions\n mapping (address => bool) public isSignerAllowed;\n\n // Mimic settler reference\n address public settler;\n\n /**\n * @dev The settler is zero\n */\n error SmartAccountSettlerZero();\n\n /**\n * @dev The input arrays are not of equal length\n */\n error SmartAccountInputInvalidLength();\n\n /**\n * @dev The sender is not the owner or the settler\n */\n error SmartAccountUnauthorizedSender(address sender);\n\n /**\n * @dev Emitted every time the settler is set\n */\n event SettlerSet(address indexed settler);\n\n /**\n * @dev Emitted every time a signer allowance is set\n */\n event SignerAllowedSet(address indexed account, bool allowed);\n\n /**\n * @dev Reverts unless the sender is the owner or the settler\n */\n modifier onlyOwnerOrSettler() {\n address sender = _msgSender();\n bool isAuthorized = sender == owner() || sender == settler;\n if (!isAuthorized) revert SmartAccountUnauthorizedSender(sender);\n _;\n }\n\n /**\n * @dev Creates a new SmartAccount contract\n * @param _settler Address of the Mimic settler\n * @param _owner Address that will own the contract\n */\n constructor(address _settler, address _owner) Ownable(_owner) {\n _setSettler(_settler);\n }\n\n /**\n * @dev Tells whether the signature provided belongs to an allowed account.\n * @param hash Message signed by the account\n * @param signature Signature provided to be verified\n */\n function isValidSignature(bytes32 hash, bytes memory signature) external view override returns (bytes4) {\n (address signer, , ) = ECDSA.tryRecover(hash, signature);\n if (signer != address(0) && (signer == owner() || isSignerAllowed[signer])) return EIP1271_MAGIC_VALUE;\n return EIP1271_INVALID_SIGNATURE;\n }\n\n /**\n * @dev It allows receiving native token transfers\n */\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n /**\n * @dev Sets the settler. Sender must be the owner.\n * @param newSettler Address of the new settler to be set\n */\n function setSettler(address newSettler) external onlyOwner {\n _setSettler(newSettler);\n }\n\n /**\n * @dev Sets a list of allowed signers. Sender must be the owner.\n * @param accounts List of account addresses\n * @param allowances List of allowed condition per account\n */\n function setAllowedSigners(address[] memory accounts, bool[] memory allowances) external onlyOwner {\n if (accounts.length != allowances.length) revert SmartAccountInputInvalidLength();\n for (uint256 i = 0; i < accounts.length; i++) {\n address account = accounts[i];\n bool allowed = allowances[i];\n isSignerAllowed[account] = allowed;\n emit SignerAllowedSet(account, allowed);\n }\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the owner or the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount)\n public\n override(ISmartAccount, SmartAccountBase)\n onlyOwnerOrSettler\n {\n super.transfer(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the owner or the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value)\n public\n override(ISmartAccount, SmartAccountBase)\n onlyOwnerOrSettler\n returns (bytes memory)\n {\n // solhint-disable-next-line avoid-low-level-calls\n return super.call(target, data, value);\n }\n\n /**\n * @dev Sets the settler\n * @param newSettler Address of the new settler to be set\n */\n function _setSettler(address newSettler) internal {\n if (newSettler == address(0)) revert SmartAccountSettlerZero();\n settler = newSettler;\n emit SettlerSet(newSettler);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountsHandler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport '../interfaces/ISafe.sol';\nimport '../interfaces/ISmartAccount.sol';\nimport '../interfaces/ISmartAccountsHandler.sol';\nimport '../utils/Denominations.sol';\n\ncontract SmartAccountsHandler is ISmartAccountsHandler {\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address account) external view override returns (bool) {\n if (account.code.length == 0) return false;\n if (_isMimicSmartAccount(account)) return true;\n if (_isSafe(account)) return true;\n return false;\n }\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address account, address token, address to, uint256 amount) external override {\n if (_isMimicSmartAccount(account)) return ISmartAccount(account).transfer(token, to, amount);\n if (_isSafe(account)) return _transferSafe(account, token, to, amount);\n revert SmartAccountsHandlerUnsupportedAccount(account);\n }\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address account, address target, bytes memory data, uint256 value)\n external\n override\n returns (bytes memory)\n {\n // solhint-disable-next-line avoid-low-level-calls\n if (_isMimicSmartAccount(account)) return ISmartAccount(account).call(target, data, value);\n if (_isSafe(account)) return _callSafe(account, target, data, value);\n revert SmartAccountsHandlerUnsupportedAccount(account);\n }\n\n /**\n * @dev Performs a transfer from a safe\n */\n function _transferSafe(address account, address token, address to, uint256 amount) internal {\n Denominations.isNativeToken(token)\n ? _callSafe(account, to, new bytes(0), amount)\n : _callSafe(account, token, abi.encodeWithSelector(IERC20.transfer.selector, to, amount), 0);\n }\n\n /**\n * @dev Performs a call from a safe\n */\n function _callSafe(address account, address target, bytes memory data, uint256 value)\n internal\n returns (bytes memory)\n {\n (bool success, bytes memory result) = ISafe(account).execTransactionFromModuleReturnData(\n target,\n value,\n data,\n SafeOperation.Call\n );\n return\n data.length == 0\n ? Address.verifyCallResult(success, result)\n : Address.verifyCallResultFromTarget(target, success, result);\n }\n\n /**\n * @dev Tells whether an account is a Mimic smart account\n * @param account Address of the account being queried\n */\n function _isMimicSmartAccount(address account) internal view returns (bool) {\n try ISmartAccount(account).supportsInterface(type(ISmartAccount).interfaceId) returns (bool ok) {\n return ok;\n } catch {\n return false;\n }\n }\n\n /**\n * @dev Tells whether an account is a Gnosis Safe\n * @param account Address of the account being queried\n */\n function _isSafe(address account) internal view returns (bool) {\n try ISafe(account).getThreshold() returns (uint256) {\n return true;\n } catch {\n return false;\n }\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountsHandlerHelpers.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport '../interfaces/ISmartAccountsHandler.sol';\n\nlibrary SmartAccountsHandlerHelpers {\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address handler, address account) internal view returns (bool) {\n return ISmartAccountsHandler(handler).isSmartAccount(account);\n }\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address handler, address account, address token, address to, uint256 amount) internal {\n Address.functionDelegateCall(\n handler,\n abi.encodeWithSelector(ISmartAccountsHandler.transfer.selector, account, token, to, amount)\n );\n }\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address handler, address account, address target, bytes memory data, uint256 value)\n internal\n returns (bytes memory)\n {\n return\n Address.functionDelegateCall(\n handler,\n abi.encodeWithSelector(ISmartAccountsHandler.call.selector, account, target, data, value)\n );\n }\n}\n" + }, + "project/contracts/test/CallMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\ncontract CallMock {\n event CallReceived(address indexed sender, uint256 value);\n error CallError();\n\n function call() external payable {\n emit CallReceived(msg.sender, msg.value);\n }\n\n function callError() external payable {\n revert CallError();\n }\n}\n" + }, + "project/contracts/test/executors/EmptyExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\n\ncontract EmptyExecutorMock is IExecutor {\n event Executed();\n\n function execute(Intent memory, Proposal memory) external override {\n emit Executed();\n }\n}\n" + }, + "project/contracts/test/executors/MintExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../TokenMock.sol';\nimport '../../interfaces/IExecutor.sol';\n\n/* solhint-disable custom-errors */\n\ncontract MintExecutorMock is IExecutor {\n event Minted();\n\n function execute(Intent memory intent, Proposal memory proposal) external override {\n require(intent.op == uint8(OpType.Swap), 'Invalid intent type');\n\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n (address[] memory tokens, uint256[] memory amounts) = abi.decode(swapProposal.data, (address[], uint256[]));\n\n require(tokens.length == amounts.length, 'Invalid inputs');\n\n for (uint256 i = 0; i < tokens.length; i++) {\n TokenMock(tokens[i]).mint(msg.sender, amounts[i]);\n emit Minted();\n }\n }\n}\n" + }, + "project/contracts/test/executors/ReentrantExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\nimport '../../interfaces/ISettler.sol';\n\ncontract ReentrantExecutorMock is IExecutor {\n // solhint-disable-next-line immutable-vars-naming\n address payable public immutable settler;\n\n constructor(address payable _settler) {\n settler = _settler;\n }\n\n function execute(Intent memory, Proposal memory) external override {\n ISettler(settler).execute(new Execution[](0));\n }\n}\n" + }, + "project/contracts/test/executors/TransferExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\nimport '../../utils/ERC20Helpers.sol';\n\n/* solhint-disable custom-errors */\n\ncontract TransferExecutorMock is IExecutor {\n event Transferred();\n\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n function execute(Intent memory intent, Proposal memory proposal) external override {\n require(intent.op == uint8(OpType.Swap), 'Invalid intent type');\n\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n (address[] memory tokens, uint256[] memory amounts) = abi.decode(swapProposal.data, (address[], uint256[]));\n\n require(tokens.length == amounts.length, 'Invalid inputs');\n\n for (uint256 i = 0; i < tokens.length; i++) {\n ERC20Helpers.transfer(tokens[i], msg.sender, amounts[i]);\n emit Transferred();\n }\n }\n}\n" + }, + "project/contracts/test/smart-accounts/SafeMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/ISafe.sol';\n\ncontract SafeMock is ISafe {\n event ModuleTxExecuted(\n address indexed target,\n bytes data,\n uint256 value,\n SafeOperation operation,\n bool success,\n bytes result\n );\n\n receive() external payable {}\n\n function getThreshold() external pure returns (uint256) {\n return 1;\n }\n\n function execTransactionFromModuleReturnData(address to, uint256 value, bytes memory data, SafeOperation operation)\n external\n returns (bool success, bytes memory result)\n {\n // solhint-disable-next-line avoid-low-level-calls\n (success, result) = to.call{ value: value }(data);\n emit ModuleTxExecuted(to, data, value, operation, success, result);\n }\n}\n" + }, + "project/contracts/test/TokenMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/ERC20.sol';\n\ncontract TokenMock is ERC20 {\n uint8 internal _decimals;\n\n constructor(string memory symbol, uint8 dec) ERC20(symbol, symbol) {\n _decimals = dec;\n }\n\n function mint(address account, uint256 amount) external {\n _mint(account, amount);\n }\n\n function decimals() public view override returns (uint8) {\n return _decimals;\n }\n}\n" + }, + "project/contracts/test/utils/DenominationsMock.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '../../utils/Denominations.sol';\n\n// solhint-disable func-name-mixedcase\n\ncontract DenominationsMock {\n function NATIVE_TOKEN() external pure returns (address) {\n return Denominations.NATIVE_TOKEN;\n }\n\n function USD() external pure returns (address) {\n return Denominations.USD;\n }\n}\n" + }, + "project/contracts/test/utils/ERC20HelpersMock.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '../../utils/ERC20Helpers.sol';\n\ncontract ERC20HelpersMock {\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n function approve(address token, address to, uint256 amount) external {\n ERC20Helpers.approve(token, to, amount);\n }\n\n function transfer(address token, address to, uint256 amount) external {\n ERC20Helpers.transfer(token, to, amount);\n }\n\n function balanceOf(address token, address account) external view returns (uint256) {\n return ERC20Helpers.balanceOf(token, account);\n }\n}\n" + }, + "project/contracts/utils/Denominations.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\n/**\n * @title Denominations\n * @dev Provides a list of ground denominations for those tokens that cannot be represented by an ERC20.\n * For now, the only needed is the native token that could be ETH, MATIC, or other depending on the layer being operated.\n */\nlibrary Denominations {\n address internal constant NATIVE_TOKEN = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;\n\n // Fiat currencies follow https://en.wikipedia.org/wiki/ISO_4217\n address internal constant USD = address(840);\n\n function isUSD(address token) internal pure returns (bool) {\n return token == USD;\n }\n\n function isNativeToken(address token) internal pure returns (bool) {\n return token == NATIVE_TOKEN;\n }\n}\n" + }, + "project/contracts/utils/ERC20Helpers.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport './Denominations.sol';\n\n/**\n * @title ERC20Helpers\n * @dev Provides a list of ERC20 helper methods\n */\nlibrary ERC20Helpers {\n function approve(address token, address to, uint256 amount) internal {\n SafeERC20.forceApprove(IERC20(token), to, amount);\n }\n\n function transfer(address token, address to, uint256 amount) internal {\n if (Denominations.isNativeToken(token)) Address.sendValue(payable(to), amount);\n else SafeERC20.safeTransfer(IERC20(token), to, amount);\n }\n\n function balanceOf(address token, address account) internal view returns (uint256) {\n if (Denominations.isNativeToken(token)) return address(account).balance;\n else return IERC20(token).balanceOf(address(account));\n }\n}\n" + }, + "project/contracts/utils/MimicHelper.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\n/**\n * @title Mimic Helper\n * @dev Collection of helper functions for the Mimic Protocol\n */\ncontract MimicHelper {\n /**\n * @dev Tells the native token balance of an address\n * @param target Address to get native token balance\n */\n function getNativeTokenBalance(address target) external view returns (uint256) {\n return target.balance;\n }\n}\n" + } + } + } +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-100/deployed_addresses.json b/packages/evm/ignition/deployments/chain-100/deployed_addresses.json index a1a41be..e981fe5 100644 --- a/packages/evm/ignition/deployments/chain-100/deployed_addresses.json +++ b/packages/evm/ignition/deployments/chain-100/deployed_addresses.json @@ -2,5 +2,7 @@ "Create3Controller#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", "Create3Controller#Controller": "0x6002825BabC837776A08799404fA55f15DCedA6b", "Create3Settler#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", - "Create3Settler#Settler": "0x609d831C0068844e11eF85a273c7F356212Fd6D1" + "Create3Settler#Settler": "0x609d831C0068844e11eF85a273c7F356212Fd6D1", + "Create3MimicHelper#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", + "Create3MimicHelper#MimicHelper": "0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0" } \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-100/journal.jsonl b/packages/evm/ignition/deployments/chain-100/journal.jsonl index 2680fdc..27da0a0 100644 --- a/packages/evm/ignition/deployments/chain-100/journal.jsonl +++ b/packages/evm/ignition/deployments/chain-100/journal.jsonl @@ -17,4 +17,13 @@ {"futureId":"Create3Settler#ICreateX.deployCreate3","hash":"0x3ca47318b95bb5541d7d33b887b6568e9b00a1de0a9e1fc9298f41d9f94bee5a","networkInteractionId":1,"receipt":{"blockHash":"0x964f2e7486aba299ac5725e80880ce6398f1066eb3f5e0f6ab70d7fcb303c9ea","blockNumber":42305828,"logs":[{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":42,"topics":["0x2feea65dd4e9f9cbd86b74b7734210c59a1b2981b5b137bd0ee3e208200c9067","0x0000000000000000000000001a68cee754105b3f806c92f6f59e3175f0b0fc2c","0xd5d101dbdd8374fa4f730d105879acbe6c9855ed7be06a019574ba923a935d7d"]},{"address":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","data":"0x","logIndex":43,"topics":["0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000003a0ce8115b4913f42c4928d6bc3f554e9a81468b"]},{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":44,"topics":["0x4db17dd5e4732fb6da34a148104a592783ca119a1e7bb8829eba6cbadef0b511","0x000000000000000000000000609d831c0068844e11ef85a273c7f356212fd6d1"]}],"status":"SUCCESS"},"type":"TRANSACTION_CONFIRM"} {"futureId":"Create3Settler#ICreateX.deployCreate3","result":{"type":"SUCCESS"},"type":"CALL_EXECUTION_STATE_COMPLETE"} {"artifactId":"Create3Settler#ICreateX","dependencies":["Create3Settler#ICreateX.deployCreate3","Create3Settler#ICreateX"],"emitterAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","eventIndex":0,"eventName":"ContractCreation","futureId":"Create3Settler#ICreateX.ContractCreation.newContract.0","nameOrIndex":"newContract","result":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","strategy":"basic","strategyConfig":{},"txToReadFrom":"0x3ca47318b95bb5541d7d33b887b6568e9b00a1de0a9e1fc9298f41d9f94bee5a","type":"READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE"} -{"artifactId":"Create3Settler#Settler","contractAddress":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","contractName":"Settler","dependencies":["Create3Settler#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3Settler#Settler","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} \ No newline at end of file +{"artifactId":"Create3Settler#Settler","contractAddress":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","contractName":"Settler","dependencies":["Create3Settler#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3Settler#Settler","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} +{"artifactId":"Create3MimicHelper#ICreateX","contractAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","contractName":"ICreateX","dependencies":[],"futureId":"Create3MimicHelper#ICreateX","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} +{"args":["0x3a0ce8115b4913f42c4928d6bc3f554e9a81468b000000000000000000000040","0x6080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033"],"artifactId":"Create3MimicHelper#ICreateX","contractAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","dependencies":["Create3MimicHelper#ICreateX"],"from":"0x3a0ce8115b4913f42c4928d6bc3f554e9a81468b","functionName":"deployCreate3","futureId":"Create3MimicHelper#ICreateX.deployCreate3","strategy":"basic","strategyConfig":{},"type":"CALL_EXECUTION_STATE_INITIALIZE","value":{"_kind":"bigint","value":"0"}} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteraction":{"data":"0x9c36a2863a0ce8115b4913f42c4928d6bc3f554e9a81468b000000000000000000000040000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e96080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c00330000000000000000000000000000000000000000000000","id":1,"to":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","type":"ONCHAIN_INTERACTION","value":{"_kind":"bigint","value":"0"}},"type":"NETWORK_INTERACTION_REQUEST"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteractionId":1,"nonce":27,"type":"TRANSACTION_PREPARE_SEND"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteractionId":1,"nonce":27,"transaction":{"fees":{"maxFeePerGas":{"_kind":"bigint","value":"1843"},"maxPriorityFeePerGas":{"_kind":"bigint","value":"69"}},"hash":"0x68467a605e7e44284a1a6e3ec10fcb54def84555934fcdd2978b722d5e0e6128"},"type":"TRANSACTION_SEND"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","hash":"0x68467a605e7e44284a1a6e3ec10fcb54def84555934fcdd2978b722d5e0e6128","networkInteractionId":1,"receipt":{"blockHash":"0xf3387d454cfa16156bce5fe5f1e77b48aefd4c745821eb8a64dc3171e767db45","blockNumber":44362214,"logs":[{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":104,"topics":["0x2feea65dd4e9f9cbd86b74b7734210c59a1b2981b5b137bd0ee3e208200c9067","0x0000000000000000000000009074e2fea6f668ccf7fb884fac62943acc03ea43","0x721f4d59bffa983c2a99dc5a3b93053d035180c65840e4dc318b06bb0484a80f"]},{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":105,"topics":["0x4db17dd5e4732fb6da34a148104a592783ca119a1e7bb8829eba6cbadef0b511","0x0000000000000000000000004766ef65d66e8d2d92f3089ee42e5705e8817ff0"]}],"status":"SUCCESS"},"type":"TRANSACTION_CONFIRM"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","result":{"type":"SUCCESS"},"type":"CALL_EXECUTION_STATE_COMPLETE"} +{"artifactId":"Create3MimicHelper#ICreateX","dependencies":["Create3MimicHelper#ICreateX.deployCreate3","Create3MimicHelper#ICreateX"],"emitterAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","eventIndex":0,"eventName":"ContractCreation","futureId":"Create3MimicHelper#ICreateX.ContractCreation.newContract.0","nameOrIndex":"newContract","result":"0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0","strategy":"basic","strategyConfig":{},"txToReadFrom":"0x68467a605e7e44284a1a6e3ec10fcb54def84555934fcdd2978b722d5e0e6128","type":"READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE"} +{"artifactId":"Create3MimicHelper#MimicHelper","contractAddress":"0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0","contractName":"MimicHelper","dependencies":["Create3MimicHelper#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3MimicHelper#MimicHelper","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-146/artifacts/Create3MimicHelper#ICreateX.dbg.json b/packages/evm/ignition/deployments/chain-146/artifacts/Create3MimicHelper#ICreateX.dbg.json new file mode 100644 index 0000000..817dddf --- /dev/null +++ b/packages/evm/ignition/deployments/chain-146/artifacts/Create3MimicHelper#ICreateX.dbg.json @@ -0,0 +1,4 @@ +{ + "_format": "hh-sol-dbg-1", + "buildInfo": "../build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-146/artifacts/Create3MimicHelper#ICreateX.json b/packages/evm/ignition/deployments/chain-146/artifacts/Create3MimicHelper#ICreateX.json new file mode 100644 index 0000000..a4701c6 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-146/artifacts/Create3MimicHelper#ICreateX.json @@ -0,0 +1,51 @@ +{ + "_format": "hh3-artifact-1", + "contractName": "ICreateX", + "sourceName": "contracts/interfaces/ICreateX.sol", + "abi": [ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "newContract", + "type": "address" + } + ], + "name": "ContractCreation", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "salt", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "initCode", + "type": "bytes" + } + ], + "name": "deployCreate3", + "outputs": [ + { + "internalType": "address", + "name": "newContract", + "type": "address" + } + ], + "stateMutability": "payable", + "type": "function" + } + ], + "bytecode": "0x", + "deployedBytecode": "0x", + "linkReferences": {}, + "deployedLinkReferences": {}, + "immutableReferences": {}, + "inputSourceName": "project/contracts/interfaces/ICreateX.sol", + "buildInfoId": "b650d0a8e9df290d290e91b2999a1f7443c2b528" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-146/artifacts/Create3MimicHelper#MimicHelper.dbg.json b/packages/evm/ignition/deployments/chain-146/artifacts/Create3MimicHelper#MimicHelper.dbg.json new file mode 100644 index 0000000..817dddf --- /dev/null +++ b/packages/evm/ignition/deployments/chain-146/artifacts/Create3MimicHelper#MimicHelper.dbg.json @@ -0,0 +1,4 @@ +{ + "_format": "hh-sol-dbg-1", + "buildInfo": "../build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-146/artifacts/Create3MimicHelper#MimicHelper.json b/packages/evm/ignition/deployments/chain-146/artifacts/Create3MimicHelper#MimicHelper.json new file mode 100644 index 0000000..a01b577 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-146/artifacts/Create3MimicHelper#MimicHelper.json @@ -0,0 +1,33 @@ +{ + "_format": "hh3-artifact-1", + "contractName": "MimicHelper", + "sourceName": "contracts/utils/MimicHelper.sol", + "abi": [ + { + "inputs": [ + { + "internalType": "address", + "name": "target", + "type": "address" + } + ], + "name": "getNativeTokenBalance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + } + ], + "bytecode": "0x6080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033", + "deployedBytecode": "0x6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033", + "linkReferences": {}, + "deployedLinkReferences": {}, + "immutableReferences": {}, + "inputSourceName": "project/contracts/utils/MimicHelper.sol", + "buildInfoId": "b650d0a8e9df290d290e91b2999a1f7443c2b528" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-146/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json b/packages/evm/ignition/deployments/chain-146/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json new file mode 100644 index 0000000..657a777 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-146/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json @@ -0,0 +1,290 @@ +{ + "_format": "hh3-sol-build-info-1", + "id": "b650d0a8e9df290d290e91b2999a1f7443c2b528", + "solcVersion": "0.8.28", + "solcLongVersion": "0.8.28+commit.7893614a", + "userSourceNameMap": { + "contracts/Controller.sol": "project/contracts/Controller.sol", + "contracts/Intents.sol": "project/contracts/Intents.sol", + "contracts/Settler.sol": "project/contracts/Settler.sol", + "contracts/interfaces/IController.sol": "project/contracts/interfaces/IController.sol", + "contracts/interfaces/ICreateX.sol": "project/contracts/interfaces/ICreateX.sol", + "contracts/interfaces/IExecutor.sol": "project/contracts/interfaces/IExecutor.sol", + "contracts/interfaces/IIntentsValidator.sol": "project/contracts/interfaces/IIntentsValidator.sol", + "contracts/interfaces/ISafe.sol": "project/contracts/interfaces/ISafe.sol", + "contracts/interfaces/ISettler.sol": "project/contracts/interfaces/ISettler.sol", + "contracts/interfaces/ISmartAccount.sol": "project/contracts/interfaces/ISmartAccount.sol", + "contracts/interfaces/ISmartAccountContract.sol": "project/contracts/interfaces/ISmartAccountContract.sol", + "contracts/interfaces/ISmartAccountsHandler.sol": "project/contracts/interfaces/ISmartAccountsHandler.sol", + "contracts/safeguards/BaseIntentsValidator.sol": "project/contracts/safeguards/BaseIntentsValidator.sol", + "contracts/safeguards/CallIntentsValidator.sol": "project/contracts/safeguards/CallIntentsValidator.sol", + "contracts/safeguards/IntentsValidator.sol": "project/contracts/safeguards/IntentsValidator.sol", + "contracts/safeguards/Safeguards.sol": "project/contracts/safeguards/Safeguards.sol", + "contracts/safeguards/SwapIntentsValidator.sol": "project/contracts/safeguards/SwapIntentsValidator.sol", + "contracts/safeguards/TransferIntentsValidator.sol": "project/contracts/safeguards/TransferIntentsValidator.sol", + "contracts/smart-accounts/SmartAccount7702.sol": "project/contracts/smart-accounts/SmartAccount7702.sol", + "contracts/smart-accounts/SmartAccountBase.sol": "project/contracts/smart-accounts/SmartAccountBase.sol", + "contracts/smart-accounts/SmartAccountContract.sol": "project/contracts/smart-accounts/SmartAccountContract.sol", + "contracts/smart-accounts/SmartAccountsHandler.sol": "project/contracts/smart-accounts/SmartAccountsHandler.sol", + "contracts/smart-accounts/SmartAccountsHandlerHelpers.sol": "project/contracts/smart-accounts/SmartAccountsHandlerHelpers.sol", + "contracts/test/CallMock.sol": "project/contracts/test/CallMock.sol", + "contracts/test/TokenMock.sol": "project/contracts/test/TokenMock.sol", + "contracts/test/executors/EmptyExecutorMock.sol": "project/contracts/test/executors/EmptyExecutorMock.sol", + "contracts/test/executors/MintExecutorMock.sol": "project/contracts/test/executors/MintExecutorMock.sol", + "contracts/test/executors/ReentrantExecutorMock.sol": "project/contracts/test/executors/ReentrantExecutorMock.sol", + "contracts/test/executors/TransferExecutorMock.sol": "project/contracts/test/executors/TransferExecutorMock.sol", + "contracts/test/smart-accounts/SafeMock.sol": "project/contracts/test/smart-accounts/SafeMock.sol", + "contracts/test/utils/DenominationsMock.sol": "project/contracts/test/utils/DenominationsMock.sol", + "contracts/test/utils/ERC20HelpersMock.sol": "project/contracts/test/utils/ERC20HelpersMock.sol", + "contracts/utils/Denominations.sol": "project/contracts/utils/Denominations.sol", + "contracts/utils/ERC20Helpers.sol": "project/contracts/utils/ERC20Helpers.sol", + "contracts/utils/MimicHelper.sol": "project/contracts/utils/MimicHelper.sol" + }, + "input": { + "language": "Solidity", + "settings": { + "optimizer": { + "enabled": true, + "runs": 1000 + }, + "evmVersion": "cancun", + "outputSelection": { + "*": { + "": [ + "ast" + ], + "*": [ + "abi", + "evm.bytecode", + "evm.deployedBytecode", + "evm.methodIdentifiers", + "metadata" + ] + } + }, + "remappings": [ + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/" + ] + }, + "sources": { + "npm/@openzeppelin/contracts@5.3.0/access/Ownable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)\n\npragma solidity ^0.8.20;\n\nimport {Context} from \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * The initial owner is set to the address provided by the deployer. This can\n * later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n /**\n * @dev The caller account is not authorized to perform an operation.\n */\n error OwnableUnauthorizedAccount(address account);\n\n /**\n * @dev The owner is not a valid owner account. (eg. `address(0)`)\n */\n error OwnableInvalidOwner(address owner);\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the address provided by the deployer as the initial owner.\n */\n constructor(address initialOwner) {\n if (initialOwner == address(0)) {\n revert OwnableInvalidOwner(address(0));\n }\n _transferOwnership(initialOwner);\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n if (owner() != _msgSender()) {\n revert OwnableUnauthorizedAccount(_msgSender());\n }\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby disabling any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n if (newOwner == address(0)) {\n revert OwnableInvalidOwner(address(0));\n }\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/draft-IERC6093.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol)\npragma solidity ^0.8.20;\n\n/**\n * @dev Standard ERC-20 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.\n */\ninterface IERC20Errors {\n /**\n * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param balance Current balance for the interacting account.\n * @param needed Minimum amount required to perform a transfer.\n */\n error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC20InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC20InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.\n * @param spender Address that may be allowed to operate on tokens without being their owner.\n * @param allowance Amount of tokens a `spender` is allowed to operate with.\n * @param needed Minimum amount required to perform a transfer.\n */\n error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC20InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `spender` to be approved. Used in approvals.\n * @param spender Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC20InvalidSpender(address spender);\n}\n\n/**\n * @dev Standard ERC-721 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.\n */\ninterface IERC721Errors {\n /**\n * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.\n * Used in balance queries.\n * @param owner Address of the current owner of a token.\n */\n error ERC721InvalidOwner(address owner);\n\n /**\n * @dev Indicates a `tokenId` whose `owner` is the zero address.\n * @param tokenId Identifier number of a token.\n */\n error ERC721NonexistentToken(uint256 tokenId);\n\n /**\n * @dev Indicates an error related to the ownership over a particular token. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param tokenId Identifier number of a token.\n * @param owner Address of the current owner of a token.\n */\n error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC721InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC721InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n * @param tokenId Identifier number of a token.\n */\n error ERC721InsufficientApproval(address operator, uint256 tokenId);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC721InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC721InvalidOperator(address operator);\n}\n\n/**\n * @dev Standard ERC-1155 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.\n */\ninterface IERC1155Errors {\n /**\n * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param balance Current balance for the interacting account.\n * @param needed Minimum amount required to perform a transfer.\n * @param tokenId Identifier number of a token.\n */\n error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC1155InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC1155InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n * @param owner Address of the current owner of a token.\n */\n error ERC1155MissingApprovalForAll(address operator, address owner);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC1155InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC1155InvalidOperator(address operator);\n\n /**\n * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.\n * Used in batch transfers.\n * @param idsLength Length of the array of token identifiers\n * @param valuesLength Length of the array of token amounts\n */\n error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC1271.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (interfaces/IERC1271.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-1271 standard signature validation method for\n * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].\n */\ninterface IERC1271 {\n /**\n * @dev Should return whether the signature provided is valid for the provided data\n * @param hash Hash of the data to be signed\n * @param signature Signature byte array associated with `hash`\n */\n function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC1363.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"./IERC20.sol\";\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @title IERC1363\n * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].\n *\n * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract\n * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.\n */\ninterface IERC1363 is IERC20, IERC165 {\n /*\n * Note: the ERC-165 identifier for this interface is 0xb0202a11.\n * 0xb0202a11 ===\n * bytes4(keccak256('transferAndCall(address,uint256)')) ^\n * bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^\n * bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^\n * bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^\n * bytes4(keccak256('approveAndCall(address,uint256)')) ^\n * bytes4(keccak256('approveAndCall(address,uint256,bytes)'))\n */\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferAndCall(address to, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @param data Additional data with no specified format, sent in call to `to`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param from The address which you want to send tokens from.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferFromAndCall(address from, address to, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param from The address which you want to send tokens from.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @param data Additional data with no specified format, sent in call to `to`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.\n * @param spender The address which will spend the funds.\n * @param value The amount of tokens to be spent.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function approveAndCall(address spender, uint256 value) external returns (bool);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.\n * @param spender The address which will spend the funds.\n * @param value The amount of tokens to be spent.\n * @param data Additional data with no specified format, sent in call to `spender`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"../utils/introspection/IERC165.sol\";\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../token/ERC20/IERC20.sol\";\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC5267.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)\n\npragma solidity ^0.8.20;\n\ninterface IERC5267 {\n /**\n * @dev MAY be emitted to signal that the domain could have changed.\n */\n event EIP712DomainChanged();\n\n /**\n * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712\n * signature.\n */\n function eip712Domain()\n external\n view\n returns (\n bytes1 fields,\n string memory name,\n string memory version,\n uint256 chainId,\n address verifyingContract,\n bytes32 salt,\n uint256[] memory extensions\n );\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/ERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"./IERC20.sol\";\nimport {IERC20Metadata} from \"./extensions/IERC20Metadata.sol\";\nimport {Context} from \"../../utils/Context.sol\";\nimport {IERC20Errors} from \"../../interfaces/draft-IERC6093.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * The default value of {decimals} is 18. To change this, you should override\n * this function so it returns a different value.\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC-20\n * applications.\n */\nabstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {\n mapping(address account => uint256) private _balances;\n\n mapping(address account => mapping(address spender => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * Both values are immutable: they can only be set once during construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the default value returned by this function, unless\n * it's overridden.\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `value`.\n */\n function transfer(address to, uint256 value) public virtual returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, value);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 value) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, value);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Skips emitting an {Approval} event indicating an allowance update. This is not\n * required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `value`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `value`.\n */\n function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, value);\n _transfer(from, to, value);\n return true;\n }\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead.\n */\n function _transfer(address from, address to, uint256 value) internal {\n if (from == address(0)) {\n revert ERC20InvalidSender(address(0));\n }\n if (to == address(0)) {\n revert ERC20InvalidReceiver(address(0));\n }\n _update(from, to, value);\n }\n\n /**\n * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`\n * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding\n * this function.\n *\n * Emits a {Transfer} event.\n */\n function _update(address from, address to, uint256 value) internal virtual {\n if (from == address(0)) {\n // Overflow check required: The rest of the code assumes that totalSupply never overflows\n _totalSupply += value;\n } else {\n uint256 fromBalance = _balances[from];\n if (fromBalance < value) {\n revert ERC20InsufficientBalance(from, fromBalance, value);\n }\n unchecked {\n // Overflow not possible: value <= fromBalance <= totalSupply.\n _balances[from] = fromBalance - value;\n }\n }\n\n if (to == address(0)) {\n unchecked {\n // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.\n _totalSupply -= value;\n }\n } else {\n unchecked {\n // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.\n _balances[to] += value;\n }\n }\n\n emit Transfer(from, to, value);\n }\n\n /**\n * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).\n * Relies on the `_update` mechanism\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead.\n */\n function _mint(address account, uint256 value) internal {\n if (account == address(0)) {\n revert ERC20InvalidReceiver(address(0));\n }\n _update(address(0), account, value);\n }\n\n /**\n * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.\n * Relies on the `_update` mechanism.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead\n */\n function _burn(address account, uint256 value) internal {\n if (account == address(0)) {\n revert ERC20InvalidSender(address(0));\n }\n _update(account, address(0), value);\n }\n\n /**\n * @dev Sets `value` as the allowance of `spender` over the `owner`'s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n *\n * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.\n */\n function _approve(address owner, address spender, uint256 value) internal {\n _approve(owner, spender, value, true);\n }\n\n /**\n * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.\n *\n * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by\n * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any\n * `Approval` event during `transferFrom` operations.\n *\n * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to\n * true using the following override:\n *\n * ```solidity\n * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {\n * super._approve(owner, spender, value, true);\n * }\n * ```\n *\n * Requirements are the same as {_approve}.\n */\n function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {\n if (owner == address(0)) {\n revert ERC20InvalidApprover(address(0));\n }\n if (spender == address(0)) {\n revert ERC20InvalidSpender(address(0));\n }\n _allowances[owner][spender] = value;\n if (emitEvent) {\n emit Approval(owner, spender, value);\n }\n }\n\n /**\n * @dev Updates `owner`'s allowance for `spender` based on spent `value`.\n *\n * Does not update the allowance value in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Does not emit an {Approval} event.\n */\n function _spendAllowance(address owner, address spender, uint256 value) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance < type(uint256).max) {\n if (currentAllowance < value) {\n revert ERC20InsufficientAllowance(spender, currentAllowance, value);\n }\n unchecked {\n _approve(owner, spender, currentAllowance - value, false);\n }\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/extensions/IERC20Metadata.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC-20 standard.\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-20 standard as defined in the ERC.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the value of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the value of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 value) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the\n * allowance mechanism. `value` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(address from, address to, uint256 value) external returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/utils/SafeERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../IERC20.sol\";\nimport {IERC1363} from \"../../../interfaces/IERC1363.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC-20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n /**\n * @dev An operation with an ERC-20 token failed.\n */\n error SafeERC20FailedOperation(address token);\n\n /**\n * @dev Indicates a failed `decreaseAllowance` request.\n */\n error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);\n\n /**\n * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,\n * non-reverting calls are assumed to be successful.\n */\n function safeTransfer(IERC20 token, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));\n }\n\n /**\n * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the\n * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.\n */\n function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));\n }\n\n /**\n * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.\n */\n function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {\n return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));\n }\n\n /**\n * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.\n */\n function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {\n return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));\n }\n\n /**\n * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n * non-reverting calls are assumed to be successful.\n *\n * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the \"client\"\n * smart contract uses ERC-7674 to set temporary allowances, then the \"client\" smart contract should avoid using\n * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract\n * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.\n */\n function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n uint256 oldAllowance = token.allowance(address(this), spender);\n forceApprove(token, spender, oldAllowance + value);\n }\n\n /**\n * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no\n * value, non-reverting calls are assumed to be successful.\n *\n * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the \"client\"\n * smart contract uses ERC-7674 to set temporary allowances, then the \"client\" smart contract should avoid using\n * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract\n * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.\n */\n function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {\n unchecked {\n uint256 currentAllowance = token.allowance(address(this), spender);\n if (currentAllowance < requestedDecrease) {\n revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);\n }\n forceApprove(token, spender, currentAllowance - requestedDecrease);\n }\n }\n\n /**\n * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,\n * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval\n * to be set to zero before setting it to a non-zero value, such as USDT.\n *\n * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function\n * only sets the \"standard\" allowance. Any temporary allowance will remain active, in addition to the value being\n * set here.\n */\n function forceApprove(IERC20 token, address spender, uint256 value) internal {\n bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));\n\n if (!_callOptionalReturnBool(token, approvalCall)) {\n _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));\n _callOptionalReturn(token, approvalCall);\n }\n }\n\n /**\n * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no\n * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * Reverts if the returned value is other than `true`.\n */\n function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {\n if (to.code.length == 0) {\n safeTransfer(token, to, value);\n } else if (!token.transferAndCall(to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target\n * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * Reverts if the returned value is other than `true`.\n */\n function transferFromAndCallRelaxed(\n IERC1363 token,\n address from,\n address to,\n uint256 value,\n bytes memory data\n ) internal {\n if (to.code.length == 0) {\n safeTransferFrom(token, from, to, value);\n } else if (!token.transferFromAndCall(from, to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no\n * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.\n * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}\n * once without retrying, and relies on the returned value to be true.\n *\n * Reverts if the returned value is other than `true`.\n */\n function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {\n if (to.code.length == 0) {\n forceApprove(token, to, value);\n } else if (!token.approveAndCall(to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n *\n * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.\n */\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)\n // bubble errors\n if iszero(success) {\n let ptr := mload(0x40)\n returndatacopy(ptr, 0, returndatasize())\n revert(ptr, returndatasize())\n }\n returnSize := returndatasize()\n returnValue := mload(0)\n }\n\n if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n *\n * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.\n */\n function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {\n bool success;\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)\n returnSize := returndatasize()\n returnValue := mload(0)\n }\n return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Address.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.2.0) (utils/Address.sol)\n\npragma solidity ^0.8.20;\n\nimport {Errors} from \"./Errors.sol\";\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev There's no code at `target` (it is not a contract).\n */\n error AddressEmptyCode(address target);\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n if (address(this).balance < amount) {\n revert Errors.InsufficientBalance(address(this).balance, amount);\n }\n\n (bool success, bytes memory returndata) = recipient.call{value: amount}(\"\");\n if (!success) {\n _revert(returndata);\n }\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason or custom error, it is bubbled\n * up by this function (like regular Solidity function calls). However, if\n * the call reverted with no returned reason, this function reverts with a\n * {Errors.FailedCall} error.\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n */\n function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n if (address(this).balance < value) {\n revert Errors.InsufficientBalance(address(this).balance, value);\n }\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target\n * was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case\n * of an unsuccessful call.\n */\n function verifyCallResultFromTarget(\n address target,\n bool success,\n bytes memory returndata\n ) internal view returns (bytes memory) {\n if (!success) {\n _revert(returndata);\n } else {\n // only check if target is a contract if the call was successful and the return data is empty\n // otherwise we already know that it was a contract\n if (returndata.length == 0 && target.code.length == 0) {\n revert AddressEmptyCode(target);\n }\n return returndata;\n }\n }\n\n /**\n * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the\n * revert reason or with a default {Errors.FailedCall} error.\n */\n function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {\n if (!success) {\n _revert(returndata);\n } else {\n return returndata;\n }\n }\n\n /**\n * @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.\n */\n function _revert(bytes memory returndata) private pure {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n assembly (\"memory-safe\") {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert Errors.FailedCall();\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Context.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n\n function _contextSuffixLength() internal view virtual returns (uint256) {\n return 0;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/ECDSA.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/ECDSA.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.\n *\n * These functions can be used to verify that a message was signed by the holder\n * of the private keys of a given address.\n */\nlibrary ECDSA {\n enum RecoverError {\n NoError,\n InvalidSignature,\n InvalidSignatureLength,\n InvalidSignatureS\n }\n\n /**\n * @dev The signature derives the `address(0)`.\n */\n error ECDSAInvalidSignature();\n\n /**\n * @dev The signature has an invalid length.\n */\n error ECDSAInvalidSignatureLength(uint256 length);\n\n /**\n * @dev The signature has an S value that is in the upper half order.\n */\n error ECDSAInvalidSignatureS(bytes32 s);\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not\n * return address(0) without also returning an error description. Errors are documented using an enum (error type)\n * and a bytes32 providing additional information about the error.\n *\n * If no error is returned, then the address can be used for verification purposes.\n *\n * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.\n *\n * Documentation for signature generation:\n * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]\n * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]\n */\n function tryRecover(\n bytes32 hash,\n bytes memory signature\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n if (signature.length == 65) {\n bytes32 r;\n bytes32 s;\n uint8 v;\n // ecrecover takes the signature parameters, and the only way to get them\n // currently is to use assembly.\n assembly (\"memory-safe\") {\n r := mload(add(signature, 0x20))\n s := mload(add(signature, 0x40))\n v := byte(0, mload(add(signature, 0x60)))\n }\n return tryRecover(hash, v, r, s);\n } else {\n return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));\n }\n }\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with\n * `signature`. This address can then be used for verification purposes.\n *\n * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.\n */\n function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.\n *\n * See https://eips.ethereum.org/EIPS/eip-2098[ERC-2098 short signatures]\n */\n function tryRecover(\n bytes32 hash,\n bytes32 r,\n bytes32 vs\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n unchecked {\n bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n // We do not check for an overflow here since the shift operation results in 0 or 1.\n uint8 v = uint8((uint256(vs) >> 255) + 27);\n return tryRecover(hash, v, r, s);\n }\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\n */\n function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function tryRecover(\n bytes32 hash,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\n // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\n // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\n // signatures from current libraries generate a unique signature with an s-value in the lower half order.\n //\n // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\n // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\n // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\n // these malleable signatures as well.\n if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\n return (address(0), RecoverError.InvalidSignatureS, s);\n }\n\n // If the signature is valid (and not malleable), return the signer address\n address signer = ecrecover(hash, v, r, s);\n if (signer == address(0)) {\n return (address(0), RecoverError.InvalidSignature, bytes32(0));\n }\n\n return (signer, RecoverError.NoError, bytes32(0));\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.\n */\n function _throwError(RecoverError error, bytes32 errorArg) private pure {\n if (error == RecoverError.NoError) {\n return; // no error: do nothing\n } else if (error == RecoverError.InvalidSignature) {\n revert ECDSAInvalidSignature();\n } else if (error == RecoverError.InvalidSignatureLength) {\n revert ECDSAInvalidSignatureLength(uint256(errorArg));\n } else if (error == RecoverError.InvalidSignatureS) {\n revert ECDSAInvalidSignatureS(errorArg);\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/EIP712.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/EIP712.sol)\n\npragma solidity ^0.8.20;\n\nimport {MessageHashUtils} from \"./MessageHashUtils.sol\";\nimport {ShortStrings, ShortString} from \"../ShortStrings.sol\";\nimport {IERC5267} from \"../../interfaces/IERC5267.sol\";\n\n/**\n * @dev https://eips.ethereum.org/EIPS/eip-712[EIP-712] is a standard for hashing and signing of typed structured data.\n *\n * The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose\n * encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract\n * does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to\n * produce the hash of their typed data using a combination of `abi.encode` and `keccak256`.\n *\n * This contract implements the EIP-712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding\n * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA\n * ({_hashTypedDataV4}).\n *\n * The implementation of the domain separator was designed to be as efficient as possible while still properly updating\n * the chain id to protect against replay attacks on an eventual fork of the chain.\n *\n * NOTE: This contract implements the version of the encoding known as \"v4\", as implemented by the JSON RPC method\n * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].\n *\n * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain\n * separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the\n * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.\n *\n * @custom:oz-upgrades-unsafe-allow state-variable-immutable\n */\nabstract contract EIP712 is IERC5267 {\n using ShortStrings for *;\n\n bytes32 private constant TYPE_HASH =\n keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\");\n\n // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to\n // invalidate the cached domain separator if the chain id changes.\n bytes32 private immutable _cachedDomainSeparator;\n uint256 private immutable _cachedChainId;\n address private immutable _cachedThis;\n\n bytes32 private immutable _hashedName;\n bytes32 private immutable _hashedVersion;\n\n ShortString private immutable _name;\n ShortString private immutable _version;\n // slither-disable-next-line constable-states\n string private _nameFallback;\n // slither-disable-next-line constable-states\n string private _versionFallback;\n\n /**\n * @dev Initializes the domain separator and parameter caches.\n *\n * The meaning of `name` and `version` is specified in\n * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP-712]:\n *\n * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.\n * - `version`: the current major version of the signing domain.\n *\n * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart\n * contract upgrade].\n */\n constructor(string memory name, string memory version) {\n _name = name.toShortStringWithFallback(_nameFallback);\n _version = version.toShortStringWithFallback(_versionFallback);\n _hashedName = keccak256(bytes(name));\n _hashedVersion = keccak256(bytes(version));\n\n _cachedChainId = block.chainid;\n _cachedDomainSeparator = _buildDomainSeparator();\n _cachedThis = address(this);\n }\n\n /**\n * @dev Returns the domain separator for the current chain.\n */\n function _domainSeparatorV4() internal view returns (bytes32) {\n if (address(this) == _cachedThis && block.chainid == _cachedChainId) {\n return _cachedDomainSeparator;\n } else {\n return _buildDomainSeparator();\n }\n }\n\n function _buildDomainSeparator() private view returns (bytes32) {\n return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));\n }\n\n /**\n * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this\n * function returns the hash of the fully encoded EIP712 message for this domain.\n *\n * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:\n *\n * ```solidity\n * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(\n * keccak256(\"Mail(address to,string contents)\"),\n * mailTo,\n * keccak256(bytes(mailContents))\n * )));\n * address signer = ECDSA.recover(digest, signature);\n * ```\n */\n function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {\n return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);\n }\n\n /**\n * @inheritdoc IERC5267\n */\n function eip712Domain()\n public\n view\n virtual\n returns (\n bytes1 fields,\n string memory name,\n string memory version,\n uint256 chainId,\n address verifyingContract,\n bytes32 salt,\n uint256[] memory extensions\n )\n {\n return (\n hex\"0f\", // 01111\n _EIP712Name(),\n _EIP712Version(),\n block.chainid,\n address(this),\n bytes32(0),\n new uint256[](0)\n );\n }\n\n /**\n * @dev The name parameter for the EIP712 domain.\n *\n * NOTE: By default this function reads _name which is an immutable value.\n * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).\n */\n // solhint-disable-next-line func-name-mixedcase\n function _EIP712Name() internal view returns (string memory) {\n return _name.toStringWithFallback(_nameFallback);\n }\n\n /**\n * @dev The version parameter for the EIP712 domain.\n *\n * NOTE: By default this function reads _version which is an immutable value.\n * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).\n */\n // solhint-disable-next-line func-name-mixedcase\n function _EIP712Version() internal view returns (string memory) {\n return _version.toStringWithFallback(_versionFallback);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/MessageHashUtils.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/MessageHashUtils.sol)\n\npragma solidity ^0.8.20;\n\nimport {Strings} from \"../Strings.sol\";\n\n/**\n * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.\n *\n * The library provides methods for generating a hash of a message that conforms to the\n * https://eips.ethereum.org/EIPS/eip-191[ERC-191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]\n * specifications.\n */\nlibrary MessageHashUtils {\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x45` (`personal_sign` messages).\n *\n * The digest is calculated by prefixing a bytes32 `messageHash` with\n * `\"\\x19Ethereum Signed Message:\\n32\"` and hashing the result. It corresponds with the\n * hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.\n *\n * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with\n * keccak256, although any bytes32 value can be safely used because the final digest will\n * be re-hashed.\n *\n * See {ECDSA-recover}.\n */\n function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n mstore(0x00, \"\\x19Ethereum Signed Message:\\n32\") // 32 is the bytes-length of messageHash\n mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix\n digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)\n }\n }\n\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x45` (`personal_sign` messages).\n *\n * The digest is calculated by prefixing an arbitrary `message` with\n * `\"\\x19Ethereum Signed Message:\\n\" + len(message)` and hashing the result. It corresponds with the\n * hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.\n *\n * See {ECDSA-recover}.\n */\n function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {\n return\n keccak256(bytes.concat(\"\\x19Ethereum Signed Message:\\n\", bytes(Strings.toString(message.length)), message));\n }\n\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x00` (data with intended validator).\n *\n * The digest is calculated by prefixing an arbitrary `data` with `\"\\x19\\x00\"` and the intended\n * `validator` address. Then hashing the result.\n *\n * See {ECDSA-recover}.\n */\n function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(hex\"19_00\", validator, data));\n }\n\n /**\n * @dev Variant of {toDataWithIntendedValidatorHash-address-bytes} optimized for cases where `data` is a bytes32.\n */\n function toDataWithIntendedValidatorHash(\n address validator,\n bytes32 messageHash\n ) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n mstore(0x00, hex\"19_00\")\n mstore(0x02, shl(96, validator))\n mstore(0x16, messageHash)\n digest := keccak256(0x00, 0x36)\n }\n }\n\n /**\n * @dev Returns the keccak256 digest of an EIP-712 typed data (ERC-191 version `0x01`).\n *\n * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with\n * `\\x19\\x01` and hashing the result. It corresponds to the hash signed by the\n * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.\n *\n * See {ECDSA-recover}.\n */\n function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n let ptr := mload(0x40)\n mstore(ptr, hex\"19_01\")\n mstore(add(ptr, 0x02), domainSeparator)\n mstore(add(ptr, 0x22), structHash)\n digest := keccak256(ptr, 0x42)\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Errors.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Collection of common custom errors used in multiple contracts\n *\n * IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.\n * It is recommended to avoid relying on the error API for critical functionality.\n *\n * _Available since v5.1._\n */\nlibrary Errors {\n /**\n * @dev The ETH balance of the account is not enough to perform the operation.\n */\n error InsufficientBalance(uint256 balance, uint256 needed);\n\n /**\n * @dev A call to an address target failed. The target may have reverted.\n */\n error FailedCall();\n\n /**\n * @dev The deployment failed.\n */\n error FailedDeployment();\n\n /**\n * @dev A necessary precompile is missing.\n */\n error MissingPrecompile(address);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/ERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/ERC165Checker.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165Checker.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @dev Library used to query support of an interface declared via {IERC165}.\n *\n * Note that these functions return the actual result of the query: they do not\n * `revert` if an interface is not supported. It is up to the caller to decide\n * what to do in these cases.\n */\nlibrary ERC165Checker {\n // As per the ERC-165 spec, no interface should ever match 0xffffffff\n bytes4 private constant INTERFACE_ID_INVALID = 0xffffffff;\n\n /**\n * @dev Returns true if `account` supports the {IERC165} interface.\n */\n function supportsERC165(address account) internal view returns (bool) {\n // Any contract that implements ERC-165 must explicitly indicate support of\n // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid\n return\n supportsERC165InterfaceUnchecked(account, type(IERC165).interfaceId) &&\n !supportsERC165InterfaceUnchecked(account, INTERFACE_ID_INVALID);\n }\n\n /**\n * @dev Returns true if `account` supports the interface defined by\n * `interfaceId`. Support for {IERC165} itself is queried automatically.\n *\n * See {IERC165-supportsInterface}.\n */\n function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {\n // query support of both ERC-165 as per the spec and support of _interfaceId\n return supportsERC165(account) && supportsERC165InterfaceUnchecked(account, interfaceId);\n }\n\n /**\n * @dev Returns a boolean array where each value corresponds to the\n * interfaces passed in and whether they're supported or not. This allows\n * you to batch check interfaces for a contract where your expectation\n * is that some interfaces may not be supported.\n *\n * See {IERC165-supportsInterface}.\n */\n function getSupportedInterfaces(\n address account,\n bytes4[] memory interfaceIds\n ) internal view returns (bool[] memory) {\n // an array of booleans corresponding to interfaceIds and whether they're supported or not\n bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length);\n\n // query support of ERC-165 itself\n if (supportsERC165(account)) {\n // query support of each interface in interfaceIds\n for (uint256 i = 0; i < interfaceIds.length; i++) {\n interfaceIdsSupported[i] = supportsERC165InterfaceUnchecked(account, interfaceIds[i]);\n }\n }\n\n return interfaceIdsSupported;\n }\n\n /**\n * @dev Returns true if `account` supports all the interfaces defined in\n * `interfaceIds`. Support for {IERC165} itself is queried automatically.\n *\n * Batch-querying can lead to gas savings by skipping repeated checks for\n * {IERC165} support.\n *\n * See {IERC165-supportsInterface}.\n */\n function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {\n // query support of ERC-165 itself\n if (!supportsERC165(account)) {\n return false;\n }\n\n // query support of each interface in interfaceIds\n for (uint256 i = 0; i < interfaceIds.length; i++) {\n if (!supportsERC165InterfaceUnchecked(account, interfaceIds[i])) {\n return false;\n }\n }\n\n // all interfaces supported\n return true;\n }\n\n /**\n * @notice Query if a contract implements an interface, does not check ERC-165 support\n * @param account The address of the contract to query for support of an interface\n * @param interfaceId The interface identifier, as specified in ERC-165\n * @return true if the contract at account indicates support of the interface with\n * identifier interfaceId, false otherwise\n * @dev Assumes that account contains a contract that supports ERC-165, otherwise\n * the behavior of this method is undefined. This precondition can be checked\n * with {supportsERC165}.\n *\n * Some precompiled contracts will falsely indicate support for a given interface, so caution\n * should be exercised when using this function.\n *\n * Interface identification is specified in ERC-165.\n */\n function supportsERC165InterfaceUnchecked(address account, bytes4 interfaceId) internal view returns (bool) {\n // prepare call\n bytes memory encodedParams = abi.encodeCall(IERC165.supportsInterface, (interfaceId));\n\n // perform static call\n bool success;\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n success := staticcall(30000, account, add(encodedParams, 0x20), mload(encodedParams), 0x00, 0x20)\n returnSize := returndatasize()\n returnValue := mload(0x00)\n }\n\n return success && returnSize >= 0x20 && returnValue > 0;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/IERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[ERC].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/Math.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.20;\n\nimport {Panic} from \"../Panic.sol\";\nimport {SafeCast} from \"./SafeCast.sol\";\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n enum Rounding {\n Floor, // Toward negative infinity\n Ceil, // Toward positive infinity\n Trunc, // Toward zero\n Expand // Away from zero\n }\n\n /**\n * @dev Return the 512-bit addition of two uint256.\n *\n * The result is stored in two 256 variables such that sum = high * 2²⁵⁶ + low.\n */\n function add512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {\n assembly (\"memory-safe\") {\n low := add(a, b)\n high := lt(low, a)\n }\n }\n\n /**\n * @dev Return the 512-bit multiplication of two uint256.\n *\n * The result is stored in two 256 variables such that product = high * 2²⁵⁶ + low.\n */\n function mul512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {\n // 512-bit multiply [high low] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use\n // the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n // variables such that product = high * 2²⁵⁶ + low.\n assembly (\"memory-safe\") {\n let mm := mulmod(a, b, not(0))\n low := mul(a, b)\n high := sub(sub(mm, low), lt(mm, low))\n }\n }\n\n /**\n * @dev Returns the addition of two unsigned integers, with a success flag (no overflow).\n */\n function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a + b;\n success = c >= a;\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, with a success flag (no overflow).\n */\n function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a - b;\n success = c <= a;\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, with a success flag (no overflow).\n */\n function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a * b;\n assembly (\"memory-safe\") {\n // Only true when the multiplication doesn't overflow\n // (c / a == b) || (a == 0)\n success := or(eq(div(c, a), b), iszero(a))\n }\n // equivalent to: success ? c : 0\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the division of two unsigned integers, with a success flag (no division by zero).\n */\n function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n success = b > 0;\n assembly (\"memory-safe\") {\n // The `DIV` opcode returns zero when the denominator is 0.\n result := div(a, b)\n }\n }\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).\n */\n function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n success = b > 0;\n assembly (\"memory-safe\") {\n // The `MOD` opcode returns zero when the denominator is 0.\n result := mod(a, b)\n }\n }\n }\n\n /**\n * @dev Unsigned saturating addition, bounds to `2²⁵⁶ - 1` instead of overflowing.\n */\n function saturatingAdd(uint256 a, uint256 b) internal pure returns (uint256) {\n (bool success, uint256 result) = tryAdd(a, b);\n return ternary(success, result, type(uint256).max);\n }\n\n /**\n * @dev Unsigned saturating subtraction, bounds to zero instead of overflowing.\n */\n function saturatingSub(uint256 a, uint256 b) internal pure returns (uint256) {\n (, uint256 result) = trySub(a, b);\n return result;\n }\n\n /**\n * @dev Unsigned saturating multiplication, bounds to `2²⁵⁶ - 1` instead of overflowing.\n */\n function saturatingMul(uint256 a, uint256 b) internal pure returns (uint256) {\n (bool success, uint256 result) = tryMul(a, b);\n return ternary(success, result, type(uint256).max);\n }\n\n /**\n * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.\n *\n * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.\n * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute\n * one branch when needed, making this function more expensive.\n */\n function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {\n unchecked {\n // branchless ternary works because:\n // b ^ (a ^ b) == a\n // b ^ 0 == b\n return b ^ ((a ^ b) * SafeCast.toUint(condition));\n }\n }\n\n /**\n * @dev Returns the largest of two numbers.\n */\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\n return ternary(a > b, a, b);\n }\n\n /**\n * @dev Returns the smallest of two numbers.\n */\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\n return ternary(a < b, a, b);\n }\n\n /**\n * @dev Returns the average of two numbers. The result is rounded towards\n * zero.\n */\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b) / 2 can overflow.\n return (a & b) + (a ^ b) / 2;\n }\n\n /**\n * @dev Returns the ceiling of the division of two numbers.\n *\n * This differs from standard division with `/` in that it rounds towards infinity instead\n * of rounding towards zero.\n */\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n if (b == 0) {\n // Guarantee the same behavior as in a regular Solidity division.\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n\n // The following calculation ensures accurate ceiling division without overflow.\n // Since a is non-zero, (a - 1) / b will not overflow.\n // The largest possible result occurs when (a - 1) / b is type(uint256).max,\n // but the largest value we can obtain is type(uint256).max - 1, which happens\n // when a = type(uint256).max and b = 1.\n unchecked {\n return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);\n }\n }\n\n /**\n * @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or\n * denominator == 0.\n *\n * Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by\n * Uniswap Labs also under MIT license.\n */\n function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {\n unchecked {\n (uint256 high, uint256 low) = mul512(x, y);\n\n // Handle non-overflow cases, 256 by 256 division.\n if (high == 0) {\n // Solidity will revert if denominator == 0, unlike the div opcode on its own.\n // The surrounding unchecked block does not change this fact.\n // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.\n return low / denominator;\n }\n\n // Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.\n if (denominator <= high) {\n Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));\n }\n\n ///////////////////////////////////////////////\n // 512 by 256 division.\n ///////////////////////////////////////////////\n\n // Make division exact by subtracting the remainder from [high low].\n uint256 remainder;\n assembly (\"memory-safe\") {\n // Compute remainder using mulmod.\n remainder := mulmod(x, y, denominator)\n\n // Subtract 256 bit number from 512 bit number.\n high := sub(high, gt(remainder, low))\n low := sub(low, remainder)\n }\n\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator.\n // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.\n\n uint256 twos = denominator & (0 - denominator);\n assembly (\"memory-safe\") {\n // Divide denominator by twos.\n denominator := div(denominator, twos)\n\n // Divide [high low] by twos.\n low := div(low, twos)\n\n // Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.\n twos := add(div(sub(0, twos), twos), 1)\n }\n\n // Shift in bits from high into low.\n low |= high * twos;\n\n // Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such\n // that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for\n // four bits. That is, denominator * inv ≡ 1 mod 2⁴.\n uint256 inverse = (3 * denominator) ^ 2;\n\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also\n // works in modular arithmetic, doubling the correct bits in each step.\n inverse *= 2 - denominator * inverse; // inverse mod 2⁸\n inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶\n inverse *= 2 - denominator * inverse; // inverse mod 2³²\n inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴\n inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸\n inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶\n\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n // This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is\n // less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and high\n // is no longer required.\n result = low * inverse;\n return result;\n }\n }\n\n /**\n * @dev Calculates x * y / denominator with full precision, following the selected rounding direction.\n */\n function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {\n return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);\n }\n\n /**\n * @dev Calculates floor(x * y >> n) with full precision. Throws if result overflows a uint256.\n */\n function mulShr(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 result) {\n unchecked {\n (uint256 high, uint256 low) = mul512(x, y);\n if (high >= 1 << n) {\n Panic.panic(Panic.UNDER_OVERFLOW);\n }\n return (high << (256 - n)) | (low >> n);\n }\n }\n\n /**\n * @dev Calculates x * y >> n with full precision, following the selected rounding direction.\n */\n function mulShr(uint256 x, uint256 y, uint8 n, Rounding rounding) internal pure returns (uint256) {\n return mulShr(x, y, n) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, 1 << n) > 0);\n }\n\n /**\n * @dev Calculate the modular multiplicative inverse of a number in Z/nZ.\n *\n * If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.\n * If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.\n *\n * If the input value is not inversible, 0 is returned.\n *\n * NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the\n * inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.\n */\n function invMod(uint256 a, uint256 n) internal pure returns (uint256) {\n unchecked {\n if (n == 0) return 0;\n\n // The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)\n // Used to compute integers x and y such that: ax + ny = gcd(a, n).\n // When the gcd is 1, then the inverse of a modulo n exists and it's x.\n // ax + ny = 1\n // ax = 1 + (-y)n\n // ax ≡ 1 (mod n) # x is the inverse of a modulo n\n\n // If the remainder is 0 the gcd is n right away.\n uint256 remainder = a % n;\n uint256 gcd = n;\n\n // Therefore the initial coefficients are:\n // ax + ny = gcd(a, n) = n\n // 0a + 1n = n\n int256 x = 0;\n int256 y = 1;\n\n while (remainder != 0) {\n uint256 quotient = gcd / remainder;\n\n (gcd, remainder) = (\n // The old remainder is the next gcd to try.\n remainder,\n // Compute the next remainder.\n // Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd\n // where gcd is at most n (capped to type(uint256).max)\n gcd - remainder * quotient\n );\n\n (x, y) = (\n // Increment the coefficient of a.\n y,\n // Decrement the coefficient of n.\n // Can overflow, but the result is casted to uint256 so that the\n // next value of y is \"wrapped around\" to a value between 0 and n - 1.\n x - y * int256(quotient)\n );\n }\n\n if (gcd != 1) return 0; // No inverse exists.\n return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.\n }\n }\n\n /**\n * @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.\n *\n * From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is\n * prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that\n * `a**(p-2)` is the modular multiplicative inverse of a in Fp.\n *\n * NOTE: this function does NOT check that `p` is a prime greater than `2`.\n */\n function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {\n unchecked {\n return Math.modExp(a, p - 2, p);\n }\n }\n\n /**\n * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)\n *\n * Requirements:\n * - modulus can't be zero\n * - underlying staticcall to precompile must succeed\n *\n * IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make\n * sure the chain you're using it on supports the precompiled contract for modular exponentiation\n * at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,\n * the underlying function will succeed given the lack of a revert, but the result may be incorrectly\n * interpreted as 0.\n */\n function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {\n (bool success, uint256 result) = tryModExp(b, e, m);\n if (!success) {\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n return result;\n }\n\n /**\n * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).\n * It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying\n * to operate modulo 0 or if the underlying precompile reverted.\n *\n * IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain\n * you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in\n * https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack\n * of a revert, but the result may be incorrectly interpreted as 0.\n */\n function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {\n if (m == 0) return (false, 0);\n assembly (\"memory-safe\") {\n let ptr := mload(0x40)\n // | Offset | Content | Content (Hex) |\n // |-----------|------------|--------------------------------------------------------------------|\n // | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x60:0x7f | value of b | 0x<.............................................................b> |\n // | 0x80:0x9f | value of e | 0x<.............................................................e> |\n // | 0xa0:0xbf | value of m | 0x<.............................................................m> |\n mstore(ptr, 0x20)\n mstore(add(ptr, 0x20), 0x20)\n mstore(add(ptr, 0x40), 0x20)\n mstore(add(ptr, 0x60), b)\n mstore(add(ptr, 0x80), e)\n mstore(add(ptr, 0xa0), m)\n\n // Given the result < m, it's guaranteed to fit in 32 bytes,\n // so we can use the memory scratch space located at offset 0.\n success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)\n result := mload(0x00)\n }\n }\n\n /**\n * @dev Variant of {modExp} that supports inputs of arbitrary length.\n */\n function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {\n (bool success, bytes memory result) = tryModExp(b, e, m);\n if (!success) {\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n return result;\n }\n\n /**\n * @dev Variant of {tryModExp} that supports inputs of arbitrary length.\n */\n function tryModExp(\n bytes memory b,\n bytes memory e,\n bytes memory m\n ) internal view returns (bool success, bytes memory result) {\n if (_zeroBytes(m)) return (false, new bytes(0));\n\n uint256 mLen = m.length;\n\n // Encode call args in result and move the free memory pointer\n result = abi.encodePacked(b.length, e.length, mLen, b, e, m);\n\n assembly (\"memory-safe\") {\n let dataPtr := add(result, 0x20)\n // Write result on top of args to avoid allocating extra memory.\n success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)\n // Overwrite the length.\n // result.length > returndatasize() is guaranteed because returndatasize() == m.length\n mstore(result, mLen)\n // Set the memory pointer after the returned data.\n mstore(0x40, add(dataPtr, mLen))\n }\n }\n\n /**\n * @dev Returns whether the provided byte array is zero.\n */\n function _zeroBytes(bytes memory byteArray) private pure returns (bool) {\n for (uint256 i = 0; i < byteArray.length; ++i) {\n if (byteArray[i] != 0) {\n return false;\n }\n }\n return true;\n }\n\n /**\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded\n * towards zero.\n *\n * This method is based on Newton's method for computing square roots; the algorithm is restricted to only\n * using integer operations.\n */\n function sqrt(uint256 a) internal pure returns (uint256) {\n unchecked {\n // Take care of easy edge cases when a == 0 or a == 1\n if (a <= 1) {\n return a;\n }\n\n // In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a\n // sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between\n // the current value as `ε_n = | x_n - sqrt(a) |`.\n //\n // For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root\n // of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is\n // bigger than any uint256.\n //\n // By noticing that\n // `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`\n // we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar\n // to the msb function.\n uint256 aa = a;\n uint256 xn = 1;\n\n if (aa >= (1 << 128)) {\n aa >>= 128;\n xn <<= 64;\n }\n if (aa >= (1 << 64)) {\n aa >>= 64;\n xn <<= 32;\n }\n if (aa >= (1 << 32)) {\n aa >>= 32;\n xn <<= 16;\n }\n if (aa >= (1 << 16)) {\n aa >>= 16;\n xn <<= 8;\n }\n if (aa >= (1 << 8)) {\n aa >>= 8;\n xn <<= 4;\n }\n if (aa >= (1 << 4)) {\n aa >>= 4;\n xn <<= 2;\n }\n if (aa >= (1 << 2)) {\n xn <<= 1;\n }\n\n // We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).\n //\n // We can refine our estimation by noticing that the middle of that interval minimizes the error.\n // If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).\n // This is going to be our x_0 (and ε_0)\n xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)\n\n // From here, Newton's method give us:\n // x_{n+1} = (x_n + a / x_n) / 2\n //\n // One should note that:\n // x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a\n // = ((x_n² + a) / (2 * x_n))² - a\n // = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a\n // = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)\n // = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)\n // = (x_n² - a)² / (2 * x_n)²\n // = ((x_n² - a) / (2 * x_n))²\n // ≥ 0\n // Which proves that for all n ≥ 1, sqrt(a) ≤ x_n\n //\n // This gives us the proof of quadratic convergence of the sequence:\n // ε_{n+1} = | x_{n+1} - sqrt(a) |\n // = | (x_n + a / x_n) / 2 - sqrt(a) |\n // = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |\n // = | (x_n - sqrt(a))² / (2 * x_n) |\n // = | ε_n² / (2 * x_n) |\n // = ε_n² / | (2 * x_n) |\n //\n // For the first iteration, we have a special case where x_0 is known:\n // ε_1 = ε_0² / | (2 * x_0) |\n // ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))\n // ≤ 2**(2*e-4) / (3 * 2**(e-1))\n // ≤ 2**(e-3) / 3\n // ≤ 2**(e-3-log2(3))\n // ≤ 2**(e-4.5)\n //\n // For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:\n // ε_{n+1} = ε_n² / | (2 * x_n) |\n // ≤ (2**(e-k))² / (2 * 2**(e-1))\n // ≤ 2**(2*e-2*k) / 2**e\n // ≤ 2**(e-2*k)\n xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above\n xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5\n xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9\n xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18\n xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36\n xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72\n\n // Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision\n // ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either\n // sqrt(a) or sqrt(a) + 1.\n return xn - SafeCast.toUint(xn > a / xn);\n }\n }\n\n /**\n * @dev Calculates sqrt(a), following the selected rounding direction.\n */\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = sqrt(a);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);\n }\n }\n\n /**\n * @dev Return the log in base 2 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n */\n function log2(uint256 x) internal pure returns (uint256 r) {\n // If value has upper 128 bits set, log2 result is at least 128\n r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;\n // If upper 64 bits of 128-bit half set, add 64 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;\n // If upper 32 bits of 64-bit half set, add 32 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;\n // If upper 16 bits of 32-bit half set, add 16 to result\n r |= SafeCast.toUint((x >> r) > 0xffff) << 4;\n // If upper 8 bits of 16-bit half set, add 8 to result\n r |= SafeCast.toUint((x >> r) > 0xff) << 3;\n // If upper 4 bits of 8-bit half set, add 4 to result\n r |= SafeCast.toUint((x >> r) > 0xf) << 2;\n\n // Shifts value right by the current result and use it as an index into this lookup table:\n //\n // | x (4 bits) | index | table[index] = MSB position |\n // |------------|---------|-----------------------------|\n // | 0000 | 0 | table[0] = 0 |\n // | 0001 | 1 | table[1] = 0 |\n // | 0010 | 2 | table[2] = 1 |\n // | 0011 | 3 | table[3] = 1 |\n // | 0100 | 4 | table[4] = 2 |\n // | 0101 | 5 | table[5] = 2 |\n // | 0110 | 6 | table[6] = 2 |\n // | 0111 | 7 | table[7] = 2 |\n // | 1000 | 8 | table[8] = 3 |\n // | 1001 | 9 | table[9] = 3 |\n // | 1010 | 10 | table[10] = 3 |\n // | 1011 | 11 | table[11] = 3 |\n // | 1100 | 12 | table[12] = 3 |\n // | 1101 | 13 | table[13] = 3 |\n // | 1110 | 14 | table[14] = 3 |\n // | 1111 | 15 | table[15] = 3 |\n //\n // The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes.\n assembly (\"memory-safe\") {\n r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000))\n }\n }\n\n /**\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log2(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);\n }\n }\n\n /**\n * @dev Return the log in base 10 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n */\n function log10(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >= 10 ** 64) {\n value /= 10 ** 64;\n result += 64;\n }\n if (value >= 10 ** 32) {\n value /= 10 ** 32;\n result += 32;\n }\n if (value >= 10 ** 16) {\n value /= 10 ** 16;\n result += 16;\n }\n if (value >= 10 ** 8) {\n value /= 10 ** 8;\n result += 8;\n }\n if (value >= 10 ** 4) {\n value /= 10 ** 4;\n result += 4;\n }\n if (value >= 10 ** 2) {\n value /= 10 ** 2;\n result += 2;\n }\n if (value >= 10 ** 1) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log10(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);\n }\n }\n\n /**\n * @dev Return the log in base 256 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n *\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n */\n function log256(uint256 x) internal pure returns (uint256 r) {\n // If value has upper 128 bits set, log2 result is at least 128\n r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;\n // If upper 64 bits of 128-bit half set, add 64 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;\n // If upper 32 bits of 64-bit half set, add 32 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;\n // If upper 16 bits of 32-bit half set, add 16 to result\n r |= SafeCast.toUint((x >> r) > 0xffff) << 4;\n // Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8\n return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);\n }\n\n /**\n * @dev Return the log in base 256, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log256(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);\n }\n }\n\n /**\n * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.\n */\n function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {\n return uint8(rounding) % 2 == 1;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/SafeCast.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeCast {\n /**\n * @dev Value doesn't fit in an uint of `bits` size.\n */\n error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);\n\n /**\n * @dev An int value doesn't fit in an uint of `bits` size.\n */\n error SafeCastOverflowedIntToUint(int256 value);\n\n /**\n * @dev Value doesn't fit in an int of `bits` size.\n */\n error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);\n\n /**\n * @dev An uint value doesn't fit in an int of `bits` size.\n */\n error SafeCastOverflowedUintToInt(uint256 value);\n\n /**\n * @dev Returns the downcasted uint248 from uint256, reverting on\n * overflow (when the input is greater than largest uint248).\n *\n * Counterpart to Solidity's `uint248` operator.\n *\n * Requirements:\n *\n * - input must fit into 248 bits\n */\n function toUint248(uint256 value) internal pure returns (uint248) {\n if (value > type(uint248).max) {\n revert SafeCastOverflowedUintDowncast(248, value);\n }\n return uint248(value);\n }\n\n /**\n * @dev Returns the downcasted uint240 from uint256, reverting on\n * overflow (when the input is greater than largest uint240).\n *\n * Counterpart to Solidity's `uint240` operator.\n *\n * Requirements:\n *\n * - input must fit into 240 bits\n */\n function toUint240(uint256 value) internal pure returns (uint240) {\n if (value > type(uint240).max) {\n revert SafeCastOverflowedUintDowncast(240, value);\n }\n return uint240(value);\n }\n\n /**\n * @dev Returns the downcasted uint232 from uint256, reverting on\n * overflow (when the input is greater than largest uint232).\n *\n * Counterpart to Solidity's `uint232` operator.\n *\n * Requirements:\n *\n * - input must fit into 232 bits\n */\n function toUint232(uint256 value) internal pure returns (uint232) {\n if (value > type(uint232).max) {\n revert SafeCastOverflowedUintDowncast(232, value);\n }\n return uint232(value);\n }\n\n /**\n * @dev Returns the downcasted uint224 from uint256, reverting on\n * overflow (when the input is greater than largest uint224).\n *\n * Counterpart to Solidity's `uint224` operator.\n *\n * Requirements:\n *\n * - input must fit into 224 bits\n */\n function toUint224(uint256 value) internal pure returns (uint224) {\n if (value > type(uint224).max) {\n revert SafeCastOverflowedUintDowncast(224, value);\n }\n return uint224(value);\n }\n\n /**\n * @dev Returns the downcasted uint216 from uint256, reverting on\n * overflow (when the input is greater than largest uint216).\n *\n * Counterpart to Solidity's `uint216` operator.\n *\n * Requirements:\n *\n * - input must fit into 216 bits\n */\n function toUint216(uint256 value) internal pure returns (uint216) {\n if (value > type(uint216).max) {\n revert SafeCastOverflowedUintDowncast(216, value);\n }\n return uint216(value);\n }\n\n /**\n * @dev Returns the downcasted uint208 from uint256, reverting on\n * overflow (when the input is greater than largest uint208).\n *\n * Counterpart to Solidity's `uint208` operator.\n *\n * Requirements:\n *\n * - input must fit into 208 bits\n */\n function toUint208(uint256 value) internal pure returns (uint208) {\n if (value > type(uint208).max) {\n revert SafeCastOverflowedUintDowncast(208, value);\n }\n return uint208(value);\n }\n\n /**\n * @dev Returns the downcasted uint200 from uint256, reverting on\n * overflow (when the input is greater than largest uint200).\n *\n * Counterpart to Solidity's `uint200` operator.\n *\n * Requirements:\n *\n * - input must fit into 200 bits\n */\n function toUint200(uint256 value) internal pure returns (uint200) {\n if (value > type(uint200).max) {\n revert SafeCastOverflowedUintDowncast(200, value);\n }\n return uint200(value);\n }\n\n /**\n * @dev Returns the downcasted uint192 from uint256, reverting on\n * overflow (when the input is greater than largest uint192).\n *\n * Counterpart to Solidity's `uint192` operator.\n *\n * Requirements:\n *\n * - input must fit into 192 bits\n */\n function toUint192(uint256 value) internal pure returns (uint192) {\n if (value > type(uint192).max) {\n revert SafeCastOverflowedUintDowncast(192, value);\n }\n return uint192(value);\n }\n\n /**\n * @dev Returns the downcasted uint184 from uint256, reverting on\n * overflow (when the input is greater than largest uint184).\n *\n * Counterpart to Solidity's `uint184` operator.\n *\n * Requirements:\n *\n * - input must fit into 184 bits\n */\n function toUint184(uint256 value) internal pure returns (uint184) {\n if (value > type(uint184).max) {\n revert SafeCastOverflowedUintDowncast(184, value);\n }\n return uint184(value);\n }\n\n /**\n * @dev Returns the downcasted uint176 from uint256, reverting on\n * overflow (when the input is greater than largest uint176).\n *\n * Counterpart to Solidity's `uint176` operator.\n *\n * Requirements:\n *\n * - input must fit into 176 bits\n */\n function toUint176(uint256 value) internal pure returns (uint176) {\n if (value > type(uint176).max) {\n revert SafeCastOverflowedUintDowncast(176, value);\n }\n return uint176(value);\n }\n\n /**\n * @dev Returns the downcasted uint168 from uint256, reverting on\n * overflow (when the input is greater than largest uint168).\n *\n * Counterpart to Solidity's `uint168` operator.\n *\n * Requirements:\n *\n * - input must fit into 168 bits\n */\n function toUint168(uint256 value) internal pure returns (uint168) {\n if (value > type(uint168).max) {\n revert SafeCastOverflowedUintDowncast(168, value);\n }\n return uint168(value);\n }\n\n /**\n * @dev Returns the downcasted uint160 from uint256, reverting on\n * overflow (when the input is greater than largest uint160).\n *\n * Counterpart to Solidity's `uint160` operator.\n *\n * Requirements:\n *\n * - input must fit into 160 bits\n */\n function toUint160(uint256 value) internal pure returns (uint160) {\n if (value > type(uint160).max) {\n revert SafeCastOverflowedUintDowncast(160, value);\n }\n return uint160(value);\n }\n\n /**\n * @dev Returns the downcasted uint152 from uint256, reverting on\n * overflow (when the input is greater than largest uint152).\n *\n * Counterpart to Solidity's `uint152` operator.\n *\n * Requirements:\n *\n * - input must fit into 152 bits\n */\n function toUint152(uint256 value) internal pure returns (uint152) {\n if (value > type(uint152).max) {\n revert SafeCastOverflowedUintDowncast(152, value);\n }\n return uint152(value);\n }\n\n /**\n * @dev Returns the downcasted uint144 from uint256, reverting on\n * overflow (when the input is greater than largest uint144).\n *\n * Counterpart to Solidity's `uint144` operator.\n *\n * Requirements:\n *\n * - input must fit into 144 bits\n */\n function toUint144(uint256 value) internal pure returns (uint144) {\n if (value > type(uint144).max) {\n revert SafeCastOverflowedUintDowncast(144, value);\n }\n return uint144(value);\n }\n\n /**\n * @dev Returns the downcasted uint136 from uint256, reverting on\n * overflow (when the input is greater than largest uint136).\n *\n * Counterpart to Solidity's `uint136` operator.\n *\n * Requirements:\n *\n * - input must fit into 136 bits\n */\n function toUint136(uint256 value) internal pure returns (uint136) {\n if (value > type(uint136).max) {\n revert SafeCastOverflowedUintDowncast(136, value);\n }\n return uint136(value);\n }\n\n /**\n * @dev Returns the downcasted uint128 from uint256, reverting on\n * overflow (when the input is greater than largest uint128).\n *\n * Counterpart to Solidity's `uint128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n */\n function toUint128(uint256 value) internal pure returns (uint128) {\n if (value > type(uint128).max) {\n revert SafeCastOverflowedUintDowncast(128, value);\n }\n return uint128(value);\n }\n\n /**\n * @dev Returns the downcasted uint120 from uint256, reverting on\n * overflow (when the input is greater than largest uint120).\n *\n * Counterpart to Solidity's `uint120` operator.\n *\n * Requirements:\n *\n * - input must fit into 120 bits\n */\n function toUint120(uint256 value) internal pure returns (uint120) {\n if (value > type(uint120).max) {\n revert SafeCastOverflowedUintDowncast(120, value);\n }\n return uint120(value);\n }\n\n /**\n * @dev Returns the downcasted uint112 from uint256, reverting on\n * overflow (when the input is greater than largest uint112).\n *\n * Counterpart to Solidity's `uint112` operator.\n *\n * Requirements:\n *\n * - input must fit into 112 bits\n */\n function toUint112(uint256 value) internal pure returns (uint112) {\n if (value > type(uint112).max) {\n revert SafeCastOverflowedUintDowncast(112, value);\n }\n return uint112(value);\n }\n\n /**\n * @dev Returns the downcasted uint104 from uint256, reverting on\n * overflow (when the input is greater than largest uint104).\n *\n * Counterpart to Solidity's `uint104` operator.\n *\n * Requirements:\n *\n * - input must fit into 104 bits\n */\n function toUint104(uint256 value) internal pure returns (uint104) {\n if (value > type(uint104).max) {\n revert SafeCastOverflowedUintDowncast(104, value);\n }\n return uint104(value);\n }\n\n /**\n * @dev Returns the downcasted uint96 from uint256, reverting on\n * overflow (when the input is greater than largest uint96).\n *\n * Counterpart to Solidity's `uint96` operator.\n *\n * Requirements:\n *\n * - input must fit into 96 bits\n */\n function toUint96(uint256 value) internal pure returns (uint96) {\n if (value > type(uint96).max) {\n revert SafeCastOverflowedUintDowncast(96, value);\n }\n return uint96(value);\n }\n\n /**\n * @dev Returns the downcasted uint88 from uint256, reverting on\n * overflow (when the input is greater than largest uint88).\n *\n * Counterpart to Solidity's `uint88` operator.\n *\n * Requirements:\n *\n * - input must fit into 88 bits\n */\n function toUint88(uint256 value) internal pure returns (uint88) {\n if (value > type(uint88).max) {\n revert SafeCastOverflowedUintDowncast(88, value);\n }\n return uint88(value);\n }\n\n /**\n * @dev Returns the downcasted uint80 from uint256, reverting on\n * overflow (when the input is greater than largest uint80).\n *\n * Counterpart to Solidity's `uint80` operator.\n *\n * Requirements:\n *\n * - input must fit into 80 bits\n */\n function toUint80(uint256 value) internal pure returns (uint80) {\n if (value > type(uint80).max) {\n revert SafeCastOverflowedUintDowncast(80, value);\n }\n return uint80(value);\n }\n\n /**\n * @dev Returns the downcasted uint72 from uint256, reverting on\n * overflow (when the input is greater than largest uint72).\n *\n * Counterpart to Solidity's `uint72` operator.\n *\n * Requirements:\n *\n * - input must fit into 72 bits\n */\n function toUint72(uint256 value) internal pure returns (uint72) {\n if (value > type(uint72).max) {\n revert SafeCastOverflowedUintDowncast(72, value);\n }\n return uint72(value);\n }\n\n /**\n * @dev Returns the downcasted uint64 from uint256, reverting on\n * overflow (when the input is greater than largest uint64).\n *\n * Counterpart to Solidity's `uint64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n */\n function toUint64(uint256 value) internal pure returns (uint64) {\n if (value > type(uint64).max) {\n revert SafeCastOverflowedUintDowncast(64, value);\n }\n return uint64(value);\n }\n\n /**\n * @dev Returns the downcasted uint56 from uint256, reverting on\n * overflow (when the input is greater than largest uint56).\n *\n * Counterpart to Solidity's `uint56` operator.\n *\n * Requirements:\n *\n * - input must fit into 56 bits\n */\n function toUint56(uint256 value) internal pure returns (uint56) {\n if (value > type(uint56).max) {\n revert SafeCastOverflowedUintDowncast(56, value);\n }\n return uint56(value);\n }\n\n /**\n * @dev Returns the downcasted uint48 from uint256, reverting on\n * overflow (when the input is greater than largest uint48).\n *\n * Counterpart to Solidity's `uint48` operator.\n *\n * Requirements:\n *\n * - input must fit into 48 bits\n */\n function toUint48(uint256 value) internal pure returns (uint48) {\n if (value > type(uint48).max) {\n revert SafeCastOverflowedUintDowncast(48, value);\n }\n return uint48(value);\n }\n\n /**\n * @dev Returns the downcasted uint40 from uint256, reverting on\n * overflow (when the input is greater than largest uint40).\n *\n * Counterpart to Solidity's `uint40` operator.\n *\n * Requirements:\n *\n * - input must fit into 40 bits\n */\n function toUint40(uint256 value) internal pure returns (uint40) {\n if (value > type(uint40).max) {\n revert SafeCastOverflowedUintDowncast(40, value);\n }\n return uint40(value);\n }\n\n /**\n * @dev Returns the downcasted uint32 from uint256, reverting on\n * overflow (when the input is greater than largest uint32).\n *\n * Counterpart to Solidity's `uint32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n */\n function toUint32(uint256 value) internal pure returns (uint32) {\n if (value > type(uint32).max) {\n revert SafeCastOverflowedUintDowncast(32, value);\n }\n return uint32(value);\n }\n\n /**\n * @dev Returns the downcasted uint24 from uint256, reverting on\n * overflow (when the input is greater than largest uint24).\n *\n * Counterpart to Solidity's `uint24` operator.\n *\n * Requirements:\n *\n * - input must fit into 24 bits\n */\n function toUint24(uint256 value) internal pure returns (uint24) {\n if (value > type(uint24).max) {\n revert SafeCastOverflowedUintDowncast(24, value);\n }\n return uint24(value);\n }\n\n /**\n * @dev Returns the downcasted uint16 from uint256, reverting on\n * overflow (when the input is greater than largest uint16).\n *\n * Counterpart to Solidity's `uint16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n */\n function toUint16(uint256 value) internal pure returns (uint16) {\n if (value > type(uint16).max) {\n revert SafeCastOverflowedUintDowncast(16, value);\n }\n return uint16(value);\n }\n\n /**\n * @dev Returns the downcasted uint8 from uint256, reverting on\n * overflow (when the input is greater than largest uint8).\n *\n * Counterpart to Solidity's `uint8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits\n */\n function toUint8(uint256 value) internal pure returns (uint8) {\n if (value > type(uint8).max) {\n revert SafeCastOverflowedUintDowncast(8, value);\n }\n return uint8(value);\n }\n\n /**\n * @dev Converts a signed int256 into an unsigned uint256.\n *\n * Requirements:\n *\n * - input must be greater than or equal to 0.\n */\n function toUint256(int256 value) internal pure returns (uint256) {\n if (value < 0) {\n revert SafeCastOverflowedIntToUint(value);\n }\n return uint256(value);\n }\n\n /**\n * @dev Returns the downcasted int248 from int256, reverting on\n * overflow (when the input is less than smallest int248 or\n * greater than largest int248).\n *\n * Counterpart to Solidity's `int248` operator.\n *\n * Requirements:\n *\n * - input must fit into 248 bits\n */\n function toInt248(int256 value) internal pure returns (int248 downcasted) {\n downcasted = int248(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(248, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int240 from int256, reverting on\n * overflow (when the input is less than smallest int240 or\n * greater than largest int240).\n *\n * Counterpart to Solidity's `int240` operator.\n *\n * Requirements:\n *\n * - input must fit into 240 bits\n */\n function toInt240(int256 value) internal pure returns (int240 downcasted) {\n downcasted = int240(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(240, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int232 from int256, reverting on\n * overflow (when the input is less than smallest int232 or\n * greater than largest int232).\n *\n * Counterpart to Solidity's `int232` operator.\n *\n * Requirements:\n *\n * - input must fit into 232 bits\n */\n function toInt232(int256 value) internal pure returns (int232 downcasted) {\n downcasted = int232(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(232, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int224 from int256, reverting on\n * overflow (when the input is less than smallest int224 or\n * greater than largest int224).\n *\n * Counterpart to Solidity's `int224` operator.\n *\n * Requirements:\n *\n * - input must fit into 224 bits\n */\n function toInt224(int256 value) internal pure returns (int224 downcasted) {\n downcasted = int224(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(224, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int216 from int256, reverting on\n * overflow (when the input is less than smallest int216 or\n * greater than largest int216).\n *\n * Counterpart to Solidity's `int216` operator.\n *\n * Requirements:\n *\n * - input must fit into 216 bits\n */\n function toInt216(int256 value) internal pure returns (int216 downcasted) {\n downcasted = int216(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(216, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int208 from int256, reverting on\n * overflow (when the input is less than smallest int208 or\n * greater than largest int208).\n *\n * Counterpart to Solidity's `int208` operator.\n *\n * Requirements:\n *\n * - input must fit into 208 bits\n */\n function toInt208(int256 value) internal pure returns (int208 downcasted) {\n downcasted = int208(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(208, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int200 from int256, reverting on\n * overflow (when the input is less than smallest int200 or\n * greater than largest int200).\n *\n * Counterpart to Solidity's `int200` operator.\n *\n * Requirements:\n *\n * - input must fit into 200 bits\n */\n function toInt200(int256 value) internal pure returns (int200 downcasted) {\n downcasted = int200(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(200, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int192 from int256, reverting on\n * overflow (when the input is less than smallest int192 or\n * greater than largest int192).\n *\n * Counterpart to Solidity's `int192` operator.\n *\n * Requirements:\n *\n * - input must fit into 192 bits\n */\n function toInt192(int256 value) internal pure returns (int192 downcasted) {\n downcasted = int192(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(192, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int184 from int256, reverting on\n * overflow (when the input is less than smallest int184 or\n * greater than largest int184).\n *\n * Counterpart to Solidity's `int184` operator.\n *\n * Requirements:\n *\n * - input must fit into 184 bits\n */\n function toInt184(int256 value) internal pure returns (int184 downcasted) {\n downcasted = int184(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(184, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int176 from int256, reverting on\n * overflow (when the input is less than smallest int176 or\n * greater than largest int176).\n *\n * Counterpart to Solidity's `int176` operator.\n *\n * Requirements:\n *\n * - input must fit into 176 bits\n */\n function toInt176(int256 value) internal pure returns (int176 downcasted) {\n downcasted = int176(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(176, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int168 from int256, reverting on\n * overflow (when the input is less than smallest int168 or\n * greater than largest int168).\n *\n * Counterpart to Solidity's `int168` operator.\n *\n * Requirements:\n *\n * - input must fit into 168 bits\n */\n function toInt168(int256 value) internal pure returns (int168 downcasted) {\n downcasted = int168(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(168, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int160 from int256, reverting on\n * overflow (when the input is less than smallest int160 or\n * greater than largest int160).\n *\n * Counterpart to Solidity's `int160` operator.\n *\n * Requirements:\n *\n * - input must fit into 160 bits\n */\n function toInt160(int256 value) internal pure returns (int160 downcasted) {\n downcasted = int160(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(160, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int152 from int256, reverting on\n * overflow (when the input is less than smallest int152 or\n * greater than largest int152).\n *\n * Counterpart to Solidity's `int152` operator.\n *\n * Requirements:\n *\n * - input must fit into 152 bits\n */\n function toInt152(int256 value) internal pure returns (int152 downcasted) {\n downcasted = int152(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(152, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int144 from int256, reverting on\n * overflow (when the input is less than smallest int144 or\n * greater than largest int144).\n *\n * Counterpart to Solidity's `int144` operator.\n *\n * Requirements:\n *\n * - input must fit into 144 bits\n */\n function toInt144(int256 value) internal pure returns (int144 downcasted) {\n downcasted = int144(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(144, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int136 from int256, reverting on\n * overflow (when the input is less than smallest int136 or\n * greater than largest int136).\n *\n * Counterpart to Solidity's `int136` operator.\n *\n * Requirements:\n *\n * - input must fit into 136 bits\n */\n function toInt136(int256 value) internal pure returns (int136 downcasted) {\n downcasted = int136(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(136, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int128 from int256, reverting on\n * overflow (when the input is less than smallest int128 or\n * greater than largest int128).\n *\n * Counterpart to Solidity's `int128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n */\n function toInt128(int256 value) internal pure returns (int128 downcasted) {\n downcasted = int128(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(128, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int120 from int256, reverting on\n * overflow (when the input is less than smallest int120 or\n * greater than largest int120).\n *\n * Counterpart to Solidity's `int120` operator.\n *\n * Requirements:\n *\n * - input must fit into 120 bits\n */\n function toInt120(int256 value) internal pure returns (int120 downcasted) {\n downcasted = int120(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(120, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int112 from int256, reverting on\n * overflow (when the input is less than smallest int112 or\n * greater than largest int112).\n *\n * Counterpart to Solidity's `int112` operator.\n *\n * Requirements:\n *\n * - input must fit into 112 bits\n */\n function toInt112(int256 value) internal pure returns (int112 downcasted) {\n downcasted = int112(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(112, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int104 from int256, reverting on\n * overflow (when the input is less than smallest int104 or\n * greater than largest int104).\n *\n * Counterpart to Solidity's `int104` operator.\n *\n * Requirements:\n *\n * - input must fit into 104 bits\n */\n function toInt104(int256 value) internal pure returns (int104 downcasted) {\n downcasted = int104(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(104, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int96 from int256, reverting on\n * overflow (when the input is less than smallest int96 or\n * greater than largest int96).\n *\n * Counterpart to Solidity's `int96` operator.\n *\n * Requirements:\n *\n * - input must fit into 96 bits\n */\n function toInt96(int256 value) internal pure returns (int96 downcasted) {\n downcasted = int96(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(96, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int88 from int256, reverting on\n * overflow (when the input is less than smallest int88 or\n * greater than largest int88).\n *\n * Counterpart to Solidity's `int88` operator.\n *\n * Requirements:\n *\n * - input must fit into 88 bits\n */\n function toInt88(int256 value) internal pure returns (int88 downcasted) {\n downcasted = int88(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(88, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int80 from int256, reverting on\n * overflow (when the input is less than smallest int80 or\n * greater than largest int80).\n *\n * Counterpart to Solidity's `int80` operator.\n *\n * Requirements:\n *\n * - input must fit into 80 bits\n */\n function toInt80(int256 value) internal pure returns (int80 downcasted) {\n downcasted = int80(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(80, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int72 from int256, reverting on\n * overflow (when the input is less than smallest int72 or\n * greater than largest int72).\n *\n * Counterpart to Solidity's `int72` operator.\n *\n * Requirements:\n *\n * - input must fit into 72 bits\n */\n function toInt72(int256 value) internal pure returns (int72 downcasted) {\n downcasted = int72(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(72, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int64 from int256, reverting on\n * overflow (when the input is less than smallest int64 or\n * greater than largest int64).\n *\n * Counterpart to Solidity's `int64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n */\n function toInt64(int256 value) internal pure returns (int64 downcasted) {\n downcasted = int64(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(64, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int56 from int256, reverting on\n * overflow (when the input is less than smallest int56 or\n * greater than largest int56).\n *\n * Counterpart to Solidity's `int56` operator.\n *\n * Requirements:\n *\n * - input must fit into 56 bits\n */\n function toInt56(int256 value) internal pure returns (int56 downcasted) {\n downcasted = int56(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(56, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int48 from int256, reverting on\n * overflow (when the input is less than smallest int48 or\n * greater than largest int48).\n *\n * Counterpart to Solidity's `int48` operator.\n *\n * Requirements:\n *\n * - input must fit into 48 bits\n */\n function toInt48(int256 value) internal pure returns (int48 downcasted) {\n downcasted = int48(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(48, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int40 from int256, reverting on\n * overflow (when the input is less than smallest int40 or\n * greater than largest int40).\n *\n * Counterpart to Solidity's `int40` operator.\n *\n * Requirements:\n *\n * - input must fit into 40 bits\n */\n function toInt40(int256 value) internal pure returns (int40 downcasted) {\n downcasted = int40(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(40, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int32 from int256, reverting on\n * overflow (when the input is less than smallest int32 or\n * greater than largest int32).\n *\n * Counterpart to Solidity's `int32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n */\n function toInt32(int256 value) internal pure returns (int32 downcasted) {\n downcasted = int32(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(32, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int24 from int256, reverting on\n * overflow (when the input is less than smallest int24 or\n * greater than largest int24).\n *\n * Counterpart to Solidity's `int24` operator.\n *\n * Requirements:\n *\n * - input must fit into 24 bits\n */\n function toInt24(int256 value) internal pure returns (int24 downcasted) {\n downcasted = int24(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(24, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int16 from int256, reverting on\n * overflow (when the input is less than smallest int16 or\n * greater than largest int16).\n *\n * Counterpart to Solidity's `int16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n */\n function toInt16(int256 value) internal pure returns (int16 downcasted) {\n downcasted = int16(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(16, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int8 from int256, reverting on\n * overflow (when the input is less than smallest int8 or\n * greater than largest int8).\n *\n * Counterpart to Solidity's `int8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits\n */\n function toInt8(int256 value) internal pure returns (int8 downcasted) {\n downcasted = int8(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(8, value);\n }\n }\n\n /**\n * @dev Converts an unsigned uint256 into a signed int256.\n *\n * Requirements:\n *\n * - input must be less than or equal to maxInt256.\n */\n function toInt256(uint256 value) internal pure returns (int256) {\n // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n if (value > uint256(type(int256).max)) {\n revert SafeCastOverflowedUintToInt(value);\n }\n return int256(value);\n }\n\n /**\n * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.\n */\n function toUint(bool b) internal pure returns (uint256 u) {\n assembly (\"memory-safe\") {\n u := iszero(iszero(b))\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/SignedMath.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol)\n\npragma solidity ^0.8.20;\n\nimport {SafeCast} from \"./SafeCast.sol\";\n\n/**\n * @dev Standard signed math utilities missing in the Solidity language.\n */\nlibrary SignedMath {\n /**\n * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.\n *\n * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.\n * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute\n * one branch when needed, making this function more expensive.\n */\n function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {\n unchecked {\n // branchless ternary works because:\n // b ^ (a ^ b) == a\n // b ^ 0 == b\n return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));\n }\n }\n\n /**\n * @dev Returns the largest of two signed numbers.\n */\n function max(int256 a, int256 b) internal pure returns (int256) {\n return ternary(a > b, a, b);\n }\n\n /**\n * @dev Returns the smallest of two signed numbers.\n */\n function min(int256 a, int256 b) internal pure returns (int256) {\n return ternary(a < b, a, b);\n }\n\n /**\n * @dev Returns the average of two signed numbers without overflow.\n * The result is rounded towards zero.\n */\n function average(int256 a, int256 b) internal pure returns (int256) {\n // Formula from the book \"Hacker's Delight\"\n int256 x = (a & b) + ((a ^ b) >> 1);\n return x + (int256(uint256(x) >> 255) & (a ^ b));\n }\n\n /**\n * @dev Returns the absolute unsigned value of a signed value.\n */\n function abs(int256 n) internal pure returns (uint256) {\n unchecked {\n // Formula from the \"Bit Twiddling Hacks\" by Sean Eron Anderson.\n // Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,\n // taking advantage of the most significant (or \"sign\" bit) in two's complement representation.\n // This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,\n // the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative).\n int256 mask = n >> 255;\n\n // A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.\n return uint256((n + mask) ^ mask);\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Panic.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Helper library for emitting standardized panic codes.\n *\n * ```solidity\n * contract Example {\n * using Panic for uint256;\n *\n * // Use any of the declared internal constants\n * function foo() { Panic.GENERIC.panic(); }\n *\n * // Alternatively\n * function foo() { Panic.panic(Panic.GENERIC); }\n * }\n * ```\n *\n * Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].\n *\n * _Available since v5.1._\n */\n// slither-disable-next-line unused-state\nlibrary Panic {\n /// @dev generic / unspecified error\n uint256 internal constant GENERIC = 0x00;\n /// @dev used by the assert() builtin\n uint256 internal constant ASSERT = 0x01;\n /// @dev arithmetic underflow or overflow\n uint256 internal constant UNDER_OVERFLOW = 0x11;\n /// @dev division or modulo by zero\n uint256 internal constant DIVISION_BY_ZERO = 0x12;\n /// @dev enum conversion error\n uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;\n /// @dev invalid encoding in storage\n uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;\n /// @dev empty array pop\n uint256 internal constant EMPTY_ARRAY_POP = 0x31;\n /// @dev array out of bounds access\n uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;\n /// @dev resource error (too large allocation or too large array)\n uint256 internal constant RESOURCE_ERROR = 0x41;\n /// @dev calling invalid internal function\n uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;\n\n /// @dev Reverts with a panic code. Recommended to use with\n /// the internal constants with predefined codes.\n function panic(uint256 code) internal pure {\n assembly (\"memory-safe\") {\n mstore(0x00, 0x4e487b71)\n mstore(0x20, code)\n revert(0x1c, 0x24)\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/ReentrancyGuard.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,\n * consider using {ReentrancyGuardTransient} instead.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant NOT_ENTERED = 1;\n uint256 private constant ENTERED = 2;\n\n uint256 private _status;\n\n /**\n * @dev Unauthorized reentrant call.\n */\n error ReentrancyGuardReentrantCall();\n\n constructor() {\n _status = NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and making it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n _nonReentrantBefore();\n _;\n _nonReentrantAfter();\n }\n\n function _nonReentrantBefore() private {\n // On the first call to nonReentrant, _status will be NOT_ENTERED\n if (_status == ENTERED) {\n revert ReentrancyGuardReentrantCall();\n }\n\n // Any calls to nonReentrant after this point will fail\n _status = ENTERED;\n }\n\n function _nonReentrantAfter() private {\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = NOT_ENTERED;\n }\n\n /**\n * @dev Returns true if the reentrancy guard is currently set to \"entered\", which indicates there is a\n * `nonReentrant` function in the call stack.\n */\n function _reentrancyGuardEntered() internal view returns (bool) {\n return _status == ENTERED;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/ShortStrings.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/ShortStrings.sol)\n\npragma solidity ^0.8.20;\n\nimport {StorageSlot} from \"./StorageSlot.sol\";\n\n// | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |\n// | length | 0x BB |\ntype ShortString is bytes32;\n\n/**\n * @dev This library provides functions to convert short memory strings\n * into a `ShortString` type that can be used as an immutable variable.\n *\n * Strings of arbitrary length can be optimized using this library if\n * they are short enough (up to 31 bytes) by packing them with their\n * length (1 byte) in a single EVM word (32 bytes). Additionally, a\n * fallback mechanism can be used for every other case.\n *\n * Usage example:\n *\n * ```solidity\n * contract Named {\n * using ShortStrings for *;\n *\n * ShortString private immutable _name;\n * string private _nameFallback;\n *\n * constructor(string memory contractName) {\n * _name = contractName.toShortStringWithFallback(_nameFallback);\n * }\n *\n * function name() external view returns (string memory) {\n * return _name.toStringWithFallback(_nameFallback);\n * }\n * }\n * ```\n */\nlibrary ShortStrings {\n // Used as an identifier for strings longer than 31 bytes.\n bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;\n\n error StringTooLong(string str);\n error InvalidShortString();\n\n /**\n * @dev Encode a string of at most 31 chars into a `ShortString`.\n *\n * This will trigger a `StringTooLong` error is the input string is too long.\n */\n function toShortString(string memory str) internal pure returns (ShortString) {\n bytes memory bstr = bytes(str);\n if (bstr.length > 31) {\n revert StringTooLong(str);\n }\n return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));\n }\n\n /**\n * @dev Decode a `ShortString` back to a \"normal\" string.\n */\n function toString(ShortString sstr) internal pure returns (string memory) {\n uint256 len = byteLength(sstr);\n // using `new string(len)` would work locally but is not memory safe.\n string memory str = new string(32);\n assembly (\"memory-safe\") {\n mstore(str, len)\n mstore(add(str, 0x20), sstr)\n }\n return str;\n }\n\n /**\n * @dev Return the length of a `ShortString`.\n */\n function byteLength(ShortString sstr) internal pure returns (uint256) {\n uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;\n if (result > 31) {\n revert InvalidShortString();\n }\n return result;\n }\n\n /**\n * @dev Encode a string into a `ShortString`, or write it to storage if it is too long.\n */\n function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {\n if (bytes(value).length < 32) {\n return toShortString(value);\n } else {\n StorageSlot.getStringSlot(store).value = value;\n return ShortString.wrap(FALLBACK_SENTINEL);\n }\n }\n\n /**\n * @dev Decode a string that was encoded to `ShortString` or written to storage using {toShortStringWithFallback}.\n */\n function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {\n if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {\n return toString(value);\n } else {\n return store;\n }\n }\n\n /**\n * @dev Return the length of a string that was encoded to `ShortString` or written to storage using\n * {toShortStringWithFallback}.\n *\n * WARNING: This will return the \"byte length\" of the string. This may not reflect the actual length in terms of\n * actual characters as the UTF-8 encoding of a single character can span over multiple bytes.\n */\n function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {\n if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {\n return byteLength(value);\n } else {\n return bytes(store).length;\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/StorageSlot.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)\n// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Library for reading and writing primitive types to specific storage slots.\n *\n * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\n * This library helps with reading and writing to such slots without the need for inline assembly.\n *\n * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\n *\n * Example usage to set ERC-1967 implementation slot:\n * ```solidity\n * contract ERC1967 {\n * // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.\n * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n *\n * function _getImplementation() internal view returns (address) {\n * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n * }\n *\n * function _setImplementation(address newImplementation) internal {\n * require(newImplementation.code.length > 0);\n * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n * }\n * }\n * ```\n *\n * TIP: Consider using this library along with {SlotDerivation}.\n */\nlibrary StorageSlot {\n struct AddressSlot {\n address value;\n }\n\n struct BooleanSlot {\n bool value;\n }\n\n struct Bytes32Slot {\n bytes32 value;\n }\n\n struct Uint256Slot {\n uint256 value;\n }\n\n struct Int256Slot {\n int256 value;\n }\n\n struct StringSlot {\n string value;\n }\n\n struct BytesSlot {\n bytes value;\n }\n\n /**\n * @dev Returns an `AddressSlot` with member `value` located at `slot`.\n */\n function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `BooleanSlot` with member `value` located at `slot`.\n */\n function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Bytes32Slot` with member `value` located at `slot`.\n */\n function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Uint256Slot` with member `value` located at `slot`.\n */\n function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Int256Slot` with member `value` located at `slot`.\n */\n function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `StringSlot` with member `value` located at `slot`.\n */\n function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `StringSlot` representation of the string storage pointer `store`.\n */\n function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := store.slot\n }\n }\n\n /**\n * @dev Returns a `BytesSlot` with member `value` located at `slot`.\n */\n function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.\n */\n function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := store.slot\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Strings.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/Strings.sol)\n\npragma solidity ^0.8.20;\n\nimport {Math} from \"./math/Math.sol\";\nimport {SafeCast} from \"./math/SafeCast.sol\";\nimport {SignedMath} from \"./math/SignedMath.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n using SafeCast for *;\n\n bytes16 private constant HEX_DIGITS = \"0123456789abcdef\";\n uint8 private constant ADDRESS_LENGTH = 20;\n uint256 private constant SPECIAL_CHARS_LOOKUP =\n (1 << 0x08) | // backspace\n (1 << 0x09) | // tab\n (1 << 0x0a) | // newline\n (1 << 0x0c) | // form feed\n (1 << 0x0d) | // carriage return\n (1 << 0x22) | // double quote\n (1 << 0x5c); // backslash\n\n /**\n * @dev The `value` string doesn't fit in the specified `length`.\n */\n error StringsInsufficientHexLength(uint256 value, uint256 length);\n\n /**\n * @dev The string being parsed contains characters that are not in scope of the given base.\n */\n error StringsInvalidChar();\n\n /**\n * @dev The string being parsed is not a properly formatted address.\n */\n error StringsInvalidAddressFormat();\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n unchecked {\n uint256 length = Math.log10(value) + 1;\n string memory buffer = new string(length);\n uint256 ptr;\n assembly (\"memory-safe\") {\n ptr := add(buffer, add(32, length))\n }\n while (true) {\n ptr--;\n assembly (\"memory-safe\") {\n mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))\n }\n value /= 10;\n if (value == 0) break;\n }\n return buffer;\n }\n }\n\n /**\n * @dev Converts a `int256` to its ASCII `string` decimal representation.\n */\n function toStringSigned(int256 value) internal pure returns (string memory) {\n return string.concat(value < 0 ? \"-\" : \"\", toString(SignedMath.abs(value)));\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n unchecked {\n return toHexString(value, Math.log256(value) + 1);\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n uint256 localValue = value;\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = HEX_DIGITS[localValue & 0xf];\n localValue >>= 4;\n }\n if (localValue != 0) {\n revert StringsInsufficientHexLength(value, length);\n }\n return string(buffer);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal\n * representation.\n */\n function toHexString(address addr) internal pure returns (string memory) {\n return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal\n * representation, according to EIP-55.\n */\n function toChecksumHexString(address addr) internal pure returns (string memory) {\n bytes memory buffer = bytes(toHexString(addr));\n\n // hash the hex part of buffer (skip length + 2 bytes, length 40)\n uint256 hashValue;\n assembly (\"memory-safe\") {\n hashValue := shr(96, keccak256(add(buffer, 0x22), 40))\n }\n\n for (uint256 i = 41; i > 1; --i) {\n // possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)\n if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {\n // case shift by xoring with 0x20\n buffer[i] ^= 0x20;\n }\n hashValue >>= 4;\n }\n return string(buffer);\n }\n\n /**\n * @dev Returns true if the two strings are equal.\n */\n function equal(string memory a, string memory b) internal pure returns (bool) {\n return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));\n }\n\n /**\n * @dev Parse a decimal string and returns the value as a `uint256`.\n *\n * Requirements:\n * - The string must be formatted as `[0-9]*`\n * - The result must fit into an `uint256` type\n */\n function parseUint(string memory input) internal pure returns (uint256) {\n return parseUint(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseUint-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `[0-9]*`\n * - The result must fit into an `uint256` type\n */\n function parseUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {\n (bool success, uint256 value) = tryParseUint(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseUint-string} that returns false if the parsing fails because of an invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseUint(string memory input) internal pure returns (bool success, uint256 value) {\n return _tryParseUintUncheckedBounds(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseUint-string-uint256-uint256} that returns false if the parsing fails because of an invalid\n * character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseUint(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, uint256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseUintUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseUint-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseUintUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, uint256 value) {\n bytes memory buffer = bytes(input);\n\n uint256 result = 0;\n for (uint256 i = begin; i < end; ++i) {\n uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));\n if (chr > 9) return (false, 0);\n result *= 10;\n result += chr;\n }\n return (true, result);\n }\n\n /**\n * @dev Parse a decimal string and returns the value as a `int256`.\n *\n * Requirements:\n * - The string must be formatted as `[-+]?[0-9]*`\n * - The result must fit in an `int256` type.\n */\n function parseInt(string memory input) internal pure returns (int256) {\n return parseInt(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseInt-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `[-+]?[0-9]*`\n * - The result must fit in an `int256` type.\n */\n function parseInt(string memory input, uint256 begin, uint256 end) internal pure returns (int256) {\n (bool success, int256 value) = tryParseInt(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseInt-string} that returns false if the parsing fails because of an invalid character or if\n * the result does not fit in a `int256`.\n *\n * NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.\n */\n function tryParseInt(string memory input) internal pure returns (bool success, int256 value) {\n return _tryParseIntUncheckedBounds(input, 0, bytes(input).length);\n }\n\n uint256 private constant ABS_MIN_INT256 = 2 ** 255;\n\n /**\n * @dev Variant of {parseInt-string-uint256-uint256} that returns false if the parsing fails because of an invalid\n * character or if the result does not fit in a `int256`.\n *\n * NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.\n */\n function tryParseInt(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, int256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseIntUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseInt-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseIntUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, int256 value) {\n bytes memory buffer = bytes(input);\n\n // Check presence of a negative sign.\n bytes1 sign = begin == end ? bytes1(0) : bytes1(_unsafeReadBytesOffset(buffer, begin)); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n bool positiveSign = sign == bytes1(\"+\");\n bool negativeSign = sign == bytes1(\"-\");\n uint256 offset = (positiveSign || negativeSign).toUint();\n\n (bool absSuccess, uint256 absValue) = tryParseUint(input, begin + offset, end);\n\n if (absSuccess && absValue < ABS_MIN_INT256) {\n return (true, negativeSign ? -int256(absValue) : int256(absValue));\n } else if (absSuccess && negativeSign && absValue == ABS_MIN_INT256) {\n return (true, type(int256).min);\n } else return (false, 0);\n }\n\n /**\n * @dev Parse a hexadecimal string (with or without \"0x\" prefix), and returns the value as a `uint256`.\n *\n * Requirements:\n * - The string must be formatted as `(0x)?[0-9a-fA-F]*`\n * - The result must fit in an `uint256` type.\n */\n function parseHexUint(string memory input) internal pure returns (uint256) {\n return parseHexUint(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseHexUint-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `(0x)?[0-9a-fA-F]*`\n * - The result must fit in an `uint256` type.\n */\n function parseHexUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {\n (bool success, uint256 value) = tryParseHexUint(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseHexUint-string} that returns false if the parsing fails because of an invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseHexUint(string memory input) internal pure returns (bool success, uint256 value) {\n return _tryParseHexUintUncheckedBounds(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseHexUint-string-uint256-uint256} that returns false if the parsing fails because of an\n * invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseHexUint(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, uint256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseHexUintUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseHexUint-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseHexUintUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, uint256 value) {\n bytes memory buffer = bytes(input);\n\n // skip 0x prefix if present\n bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(buffer, begin)) == bytes2(\"0x\"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n uint256 offset = hasPrefix.toUint() * 2;\n\n uint256 result = 0;\n for (uint256 i = begin + offset; i < end; ++i) {\n uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));\n if (chr > 15) return (false, 0);\n result *= 16;\n unchecked {\n // Multiplying by 16 is equivalent to a shift of 4 bits (with additional overflow check).\n // This guarantees that adding a value < 16 will not cause an overflow, hence the unchecked.\n result += chr;\n }\n }\n return (true, result);\n }\n\n /**\n * @dev Parse a hexadecimal string (with or without \"0x\" prefix), and returns the value as an `address`.\n *\n * Requirements:\n * - The string must be formatted as `(0x)?[0-9a-fA-F]{40}`\n */\n function parseAddress(string memory input) internal pure returns (address) {\n return parseAddress(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseAddress-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `(0x)?[0-9a-fA-F]{40}`\n */\n function parseAddress(string memory input, uint256 begin, uint256 end) internal pure returns (address) {\n (bool success, address value) = tryParseAddress(input, begin, end);\n if (!success) revert StringsInvalidAddressFormat();\n return value;\n }\n\n /**\n * @dev Variant of {parseAddress-string} that returns false if the parsing fails because the input is not a properly\n * formatted address. See {parseAddress-string} requirements.\n */\n function tryParseAddress(string memory input) internal pure returns (bool success, address value) {\n return tryParseAddress(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseAddress-string-uint256-uint256} that returns false if the parsing fails because input is not a properly\n * formatted address. See {parseAddress-string-uint256-uint256} requirements.\n */\n function tryParseAddress(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, address value) {\n if (end > bytes(input).length || begin > end) return (false, address(0));\n\n bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(bytes(input), begin)) == bytes2(\"0x\"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n uint256 expectedLength = 40 + hasPrefix.toUint() * 2;\n\n // check that input is the correct length\n if (end - begin == expectedLength) {\n // length guarantees that this does not overflow, and value is at most type(uint160).max\n (bool s, uint256 v) = _tryParseHexUintUncheckedBounds(input, begin, end);\n return (s, address(uint160(v)));\n } else {\n return (false, address(0));\n }\n }\n\n function _tryParseChr(bytes1 chr) private pure returns (uint8) {\n uint8 value = uint8(chr);\n\n // Try to parse `chr`:\n // - Case 1: [0-9]\n // - Case 2: [a-f]\n // - Case 3: [A-F]\n // - otherwise not supported\n unchecked {\n if (value > 47 && value < 58) value -= 48;\n else if (value > 96 && value < 103) value -= 87;\n else if (value > 64 && value < 71) value -= 55;\n else return type(uint8).max;\n }\n\n return value;\n }\n\n /**\n * @dev Escape special characters in JSON strings. This can be useful to prevent JSON injection in NFT metadata.\n *\n * WARNING: This function should only be used in double quoted JSON strings. Single quotes are not escaped.\n *\n * NOTE: This function escapes all unicode characters, and not just the ones in ranges defined in section 2.5 of\n * RFC-4627 (U+0000 to U+001F, U+0022 and U+005C). ECMAScript's `JSON.parse` does recover escaped unicode\n * characters that are not in this range, but other tooling may provide different results.\n */\n function escapeJSON(string memory input) internal pure returns (string memory) {\n bytes memory buffer = bytes(input);\n bytes memory output = new bytes(2 * buffer.length); // worst case scenario\n uint256 outputLength = 0;\n\n for (uint256 i; i < buffer.length; ++i) {\n bytes1 char = bytes1(_unsafeReadBytesOffset(buffer, i));\n if (((SPECIAL_CHARS_LOOKUP & (1 << uint8(char))) != 0)) {\n output[outputLength++] = \"\\\\\";\n if (char == 0x08) output[outputLength++] = \"b\";\n else if (char == 0x09) output[outputLength++] = \"t\";\n else if (char == 0x0a) output[outputLength++] = \"n\";\n else if (char == 0x0c) output[outputLength++] = \"f\";\n else if (char == 0x0d) output[outputLength++] = \"r\";\n else if (char == 0x5c) output[outputLength++] = \"\\\\\";\n else if (char == 0x22) {\n // solhint-disable-next-line quotes\n output[outputLength++] = '\"';\n }\n } else {\n output[outputLength++] = char;\n }\n }\n // write the actual length and deallocate unused memory\n assembly (\"memory-safe\") {\n mstore(output, outputLength)\n mstore(0x40, add(output, shl(5, shr(5, add(outputLength, 63)))))\n }\n\n return string(output);\n }\n\n /**\n * @dev Reads a bytes32 from a bytes array without bounds checking.\n *\n * NOTE: making this function internal would mean it could be used with memory unsafe offset, and marking the\n * assembly block as such would prevent some optimizations.\n */\n function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {\n // This is not memory safe in the general case, but all calls to this private function are within bounds.\n assembly (\"memory-safe\") {\n value := mload(add(buffer, add(0x20, offset)))\n }\n }\n}\n" + }, + "project/contracts/Controller.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\n\nimport './interfaces/IController.sol';\n\n/**\n * @title Controller\n * @dev Manages allow lists for solvers, executors, proposal signers and validators\n */\ncontract Controller is IController, Ownable {\n // List of allowed solvers\n mapping (address => bool) public override isSolverAllowed;\n\n // List of allowed executors\n mapping (address => bool) public override isExecutorAllowed;\n\n // List of allowed proposal signers\n mapping (address => bool) public override isProposalSignerAllowed;\n\n // List of allowed validators\n mapping (address => bool) public override isValidatorAllowed;\n\n // Minimum number of validations allowed\n uint8 public override minValidations;\n\n /**\n * @dev Creates a new Controller contract\n * @param owner Address that will own the contract\n * @param solvers List of allowed solvers\n * @param executors List of allowed executors\n * @param proposalSigners List of allowed proposal signers\n * @param validators List of allowed validators\n * @param _minValidations Minimum number of validations allowed\n */\n constructor(\n address owner,\n address[] memory solvers,\n address[] memory executors,\n address[] memory proposalSigners,\n address[] memory validators,\n uint8 _minValidations\n ) Ownable(owner) {\n for (uint256 i = 0; i < solvers.length; i++) _setAllowedSolver(solvers[i], true);\n for (uint256 i = 0; i < executors.length; i++) _setAllowedExecutor(executors[i], true);\n for (uint256 i = 0; i < proposalSigners.length; i++) _setAllowedProposalSigner(proposalSigners[i], true);\n for (uint256 i = 0; i < validators.length; i++) _setAllowedValidator(validators[i], true);\n _setMinValidations(_minValidations);\n }\n\n /**\n * @dev Sets permissions for multiple solvers\n * @param solvers List of solver addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedSolvers(address[] memory solvers, bool[] memory alloweds) external override onlyOwner {\n if (solvers.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < solvers.length; i++) _setAllowedSolver(solvers[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple executors\n * @param executors List of executor addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedExecutors(address[] memory executors, bool[] memory alloweds) external override onlyOwner {\n if (executors.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < executors.length; i++) _setAllowedExecutor(executors[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple proposal signers\n * @param signers List of proposal signer addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedProposalSigners(address[] memory signers, bool[] memory alloweds) external override onlyOwner {\n if (signers.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < signers.length; i++) _setAllowedProposalSigner(signers[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple validators\n * @param validators List of validator addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedValidators(address[] memory validators, bool[] memory alloweds) external override onlyOwner {\n if (validators.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < validators.length; i++) _setAllowedValidator(validators[i], alloweds[i]);\n }\n\n /**\n * @dev Sets the minimum number of validations allowed\n * @param newMinValidations minimum number of validations allowed\n */\n function setMinValidations(uint8 newMinValidations) external override onlyOwner {\n _setMinValidations(newMinValidations);\n }\n\n /**\n * @dev Sets a solver permission\n */\n function _setAllowedSolver(address solver, bool allowed) internal {\n isSolverAllowed[solver] = allowed;\n emit SolverAllowedSet(solver, allowed);\n }\n\n /**\n * @dev Sets an executor permission\n */\n function _setAllowedExecutor(address executor, bool allowed) internal {\n isExecutorAllowed[executor] = allowed;\n emit ExecutorAllowedSet(executor, allowed);\n }\n\n /**\n * @dev Sets a proposal signer permission\n */\n function _setAllowedProposalSigner(address signer, bool allowed) internal {\n isProposalSignerAllowed[signer] = allowed;\n emit ProposalSignerAllowedSet(signer, allowed);\n }\n\n /**\n * @dev Sets a validator permission\n */\n function _setAllowedValidator(address validator, bool allowed) internal {\n isValidatorAllowed[validator] = allowed;\n emit ValidatorAllowedSet(validator, allowed);\n }\n\n /**\n * @dev Sets the minimum number of validations allowed\n */\n function _setMinValidations(uint8 newMinValidations) internal {\n minValidations = newMinValidations;\n emit MinValidationSet(newMinValidations);\n }\n}\n" + }, + "project/contracts/Intents.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Enum representing the type of intent operation.\n * - Swap: Swap tokens between chains or tokens.\n * - Transfer: Transfer tokens to one or more recipients.\n * - Call: Execute arbitrary contract calls.\n */\nenum OpType {\n Swap,\n Transfer,\n Call\n}\n\n/**\n * @dev Execution structure.\n * @param intent Intent to be fulfilled.\n * @param proposal Proposal to be executed.\n * @param signature Proposal signature.\n */\nstruct Execution {\n Intent intent;\n Proposal proposal;\n bytes signature;\n}\n\n/**\n * @dev EIP-712 typed data struct representing a validator's approval of an intent.\n * @param intent The hash of the intent being validated.\n */\nstruct Validation {\n bytes32 intent;\n}\n\n/**\n * @dev General intent structure used to abstract over different intent types.\n * @param op The type of operation this intent represents.\n * @param user The originator of the intent.\n * @param settler The address responsible for executing the intent on-chain.\n * @param nonce A unique value used to prevent replay attacks and distinguish intents.\n * @param deadline The timestamp by which the intent must be executed.\n * @param data ABI-encoded data representing a specific intent type (e.g. SwapIntent, TransferIntent, CallIntent).\n * @param maxFees List of max fees the user is willing to pay for the intent.\n * @param events List of custom intent events to be emitted.\n * @param configSig The signature of the configuration that this intent belongs to\n * @param minValidations The minimum number of validator approvals required for this intent to be considered valid.\n * @param validations The list validator signatures attesting to this intent.\n */\nstruct Intent {\n uint8 op;\n address user;\n address settler;\n bytes32 nonce;\n uint256 deadline;\n bytes data;\n MaxFee[] maxFees;\n IntentEvent[] events;\n bytes configSig;\n uint256 minValidations;\n bytes[] validations;\n}\n\n/**\n * @dev Max fee representation\n * @param token Token used to pay for the execution fee.\n * @param amount Max amount of fee token to be paid for settling this intent.\n */\nstruct MaxFee {\n address token;\n uint256 amount;\n}\n\n/**\n * @dev Intent event representation.\n * @param topic Event topic to be emitted.\n * @param data Event data to be emitted.\n */\nstruct IntentEvent {\n bytes32 topic;\n bytes data;\n}\n\n/**\n * @dev Represents a swap intent between two chains.\n * @param sourceChain Chain ID where tokens will be sent from.\n * @param destinationChain Chain ID where tokens will be received.\n * @param tokensIn List of input tokens and amounts to swap.\n * @param tokensOut List of expected output tokens, minimum amounts, and recipients.\n */\nstruct SwapIntent {\n uint256 sourceChain;\n uint256 destinationChain;\n TokenIn[] tokensIn;\n TokenOut[] tokensOut;\n}\n\n/**\n * @dev Token in representation.\n * @param token Address of a token to be sent.\n * @param amount Amount of tokens to be sent.\n */\nstruct TokenIn {\n address token;\n uint256 amount;\n}\n\n/**\n * @dev Token out representation.\n * @param token Address of a token to be received.\n * @param minAmount Minimum amount of tokens to be received.\n * @param recipient Recipient address that will receive the token out.\n */\nstruct TokenOut {\n address token;\n uint256 minAmount;\n address recipient;\n}\n\n/**\n * @dev Represents a transfer intent containing multiple token transfers.\n * @param chainId Chain ID where the transfers should be executed.\n * @param transfers List of token transfers to be performed.\n */\nstruct TransferIntent {\n uint256 chainId;\n TransferData[] transfers;\n}\n\n/**\n * @dev Transfer data for a single token transfer.\n * @param token Address of the token to transfer.\n * @param amount Amount of the token to transfer.\n * @param recipient Recipient of the token transfer.\n */\nstruct TransferData {\n address token;\n uint256 amount;\n address recipient;\n}\n\n/**\n * @dev Represents a generic call intent consisting of one or more contract calls.\n * @param chainId Chain ID where the calls should be executed.\n * @param calls List of low-level contract calls to be executed.\n */\nstruct CallIntent {\n uint256 chainId;\n CallData[] calls;\n}\n\n/**\n * @dev Low-level call data for a target contract interaction.\n * @param target Target contract address.\n * @param data Calldata to be sent to the target.\n * @param value ETH value to send along with the call.\n */\nstruct CallData {\n address target;\n bytes data;\n uint256 value;\n}\n\n/**\n * @dev Generic proposal structure representing a solver’s response to an intent.\n * @param deadline Timestamp until when the proposal is valid.\n * @param data ABI-encoded proposal-specific data (e.g. SwapProposal).\n * @param fees List of fee amounts the solver requires for execution.\n */\nstruct Proposal {\n uint256 deadline;\n bytes data;\n uint256[] fees;\n}\n\n/**\n * @dev Swap proposal representation for a swap intent.\n * @param executor Address of the executor contract that should be called during intent execution.\n * @param data Arbitrary data used to call the executor contract.\n * @param amountsOut List of amounts of tokens out proposed by the solver.\n */\nstruct SwapProposal {\n address executor;\n bytes data;\n uint256[] amountsOut;\n}\n\nlibrary IntentsHelpers {\n bytes32 internal constant INTENT_TYPE_HASH =\n keccak256(\n 'Intent(uint8 op,address user,address settler,bytes32 nonce,uint256 deadline,bytes data,MaxFee[] maxFees,IntentEvent[] events,bytes configSig,uint256 minValidations)IntentEvent(bytes32 topic,bytes data)MaxFee(address token,uint256 amount)'\n );\n\n bytes32 internal constant PROPOSAL_TYPE_HASH =\n keccak256('Proposal(bytes32 intent,address solver,uint256 deadline,bytes data,uint256[] fees)');\n\n bytes32 internal constant VALIDATION_TYPE_HASH = keccak256('Validation(bytes32 intent)');\n\n bytes32 internal constant MAX_FEE_TYPE_HASH = keccak256('MaxFee(address token,uint256 amount)');\n\n bytes32 internal constant INTENT_EVENT_TYPE_HASH = keccak256('IntentEvent(bytes32 topic,bytes data)');\n\n function hash(Intent memory intent) internal pure returns (bytes32) {\n return\n keccak256(\n abi.encode(\n INTENT_TYPE_HASH,\n intent.op,\n intent.user,\n intent.settler,\n intent.nonce,\n intent.deadline,\n keccak256(intent.data),\n hash(intent.maxFees),\n hash(intent.events),\n intent.configSig,\n intent.minValidations\n )\n );\n }\n\n function hash(Proposal memory proposal, Intent memory intent, address solver) internal pure returns (bytes32) {\n return\n keccak256(\n abi.encode(\n PROPOSAL_TYPE_HASH,\n hash(intent),\n solver,\n proposal.deadline,\n keccak256(proposal.data),\n hash(proposal.fees)\n )\n );\n }\n\n function hash(MaxFee[] memory fees) internal pure returns (bytes32) {\n bytes32[] memory hashes = new bytes32[](fees.length);\n for (uint256 i = 0; i < fees.length; i++) {\n hashes[i] = keccak256(abi.encode(MAX_FEE_TYPE_HASH, fees[i].token, fees[i].amount));\n }\n return keccak256(abi.encodePacked(hashes));\n }\n\n function hash(IntentEvent[] memory events) internal pure returns (bytes32) {\n bytes32[] memory hashes = new bytes32[](events.length);\n for (uint256 i = 0; i < events.length; i++) {\n hashes[i] = keccak256(abi.encode(INTENT_EVENT_TYPE_HASH, events[i].topic, keccak256(events[i].data)));\n }\n return keccak256(abi.encodePacked(hashes));\n }\n\n function hash(uint256[] memory fees) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(fees));\n }\n\n function hash(Validation memory validation) internal pure returns (bytes32) {\n return keccak256(abi.encode(VALIDATION_TYPE_HASH, validation.intent));\n }\n}\n" + }, + "project/contracts/interfaces/IController.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @title Controller interface\n */\ninterface IController {\n /**\n * @dev The input arrays are not of equal length\n */\n error ControllerInputInvalidLength();\n\n /**\n * @dev Emitted every time a solver permission is set\n */\n event SolverAllowedSet(address indexed solver, bool allowed);\n\n /**\n * @dev Emitted every time an executor permission is set\n */\n event ExecutorAllowedSet(address indexed executor, bool allowed);\n\n /**\n * @dev Emitted every time a proposal signer permission is set\n */\n event ProposalSignerAllowedSet(address indexed proposalSigner, bool allowed);\n\n /**\n * @dev Emitted every time a validator permission is set\n */\n event ValidatorAllowedSet(address indexed validator, bool allowed);\n\n /**\n * @dev Emitted when the minimum validations changes\n */\n event MinValidationSet(uint8 indexed newMinValidation);\n\n /**\n * @dev Tells whether a solver is allowed\n * @param solver Address of the solver being queried\n */\n function isSolverAllowed(address solver) external view returns (bool);\n\n /**\n * @dev Tells whether an executor is allowed\n * @param executor Address of the executor being queried\n */\n function isExecutorAllowed(address executor) external view returns (bool);\n\n /**\n * @dev Tells whether a proposal signer is allowed\n * @param signer Address of the proposal signer being queried\n */\n function isProposalSignerAllowed(address signer) external view returns (bool);\n\n /**\n * @dev Tells whether a validator is allowed\n * @param validator Address of the validator being queried\n */\n function isValidatorAllowed(address validator) external view returns (bool);\n\n /**\n * @dev Tells the minimum number of validations allowed\n */\n function minValidations() external view returns (uint8);\n\n /**\n * @dev Sets permissions for multiple solvers\n * @param solvers List of solver addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedSolvers(address[] memory solvers, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple executors\n * @param executors List of executor addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedExecutors(address[] memory executors, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple proposal signers\n * @param signers List of proposal signer addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedProposalSigners(address[] memory signers, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple validators\n * @param validators List of validator addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedValidators(address[] memory validators, bool[] memory alloweds) external;\n\n /**\n * @dev Sets the minimum number of validations allowed\n * @param newMinValidations minimum number of validations allowed\n */\n function setMinValidations(uint8 newMinValidations) external;\n}\n" + }, + "project/contracts/interfaces/ICreateX.sol": { + "content": "// SPDX-License-Identifier: AGPL-3.0-only\n\npragma solidity ^0.8.4;\n\n/**\n * @title CreateX Factory Interface Definition\n * @author pcaversaccio (https://web.archive.org/web/20230921103111/https://pcaversaccio.com/)\n * @custom:coauthor Matt Solomon (https://web.archive.org/web/20230921103335/https://mattsolomon.dev/)\n */\ninterface ICreateX {\n event ContractCreation(address indexed newContract);\n\n function deployCreate3(bytes32 salt, bytes memory initCode) external payable returns (address newContract);\n}\n" + }, + "project/contracts/interfaces/IExecutor.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\n\n/**\n * @title Executor interface\n */\ninterface IExecutor {\n /**\n * @dev Executes an intent proposal\n * @param intent Intent to be executed\n * @param proposal Proposal to be executed to fulfill the intent\n */\n function execute(Intent memory intent, Proposal memory proposal) external;\n}\n" + }, + "project/contracts/interfaces/IIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\nimport '../safeguards/Safeguards.sol';\n\n/**\n * @title IntentsValidator\n * @dev Performs intents validations based on safeguards\n */\ninterface IIntentsValidator {\n /**\n * @dev Validates an intent for a safeguard\n * @param intent Intent to be validated\n * @param config Safeguard config to validate the intent with\n */\n function validate(Intent memory intent, bytes memory config) external pure;\n}\n" + }, + "project/contracts/interfaces/ISafe.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nenum SafeOperation {\n Call,\n DelegateCall\n}\n\ninterface ISafe {\n function getThreshold() external view returns (uint256);\n\n function execTransactionFromModuleReturnData(address to, uint256 value, bytes memory data, SafeOperation operation)\n external\n returns (bool success, bytes memory returnData);\n}\n" + }, + "project/contracts/interfaces/ISettler.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\nimport '../safeguards/Safeguards.sol';\n\n/**\n * @title Settler interface\n */\ninterface ISettler {\n /**\n * @dev The requested intent type is unknown\n */\n error SettlerUnknownIntentType(uint8 op);\n\n /**\n * @dev The simulation has been successful\n */\n error SettlerSimulationSuccess(uint256 gasUsed);\n\n /**\n * @dev The solver is not allowed\n */\n error SettlerSolverNotAllowed(address solver);\n\n /**\n * @dev The executor is not allowed\n */\n error SettlerExecutorNotAllowed(address executor);\n\n /**\n * @dev The proposal signer is not allowed\n */\n error SettlerProposalSignerNotAllowed(address signer);\n\n /**\n * @dev The validator is not allowed\n */\n error SettlerValidatorNotAllowed(address validator);\n\n /**\n * @dev The validator is duplicated\n */\n error SettlerValidatorDuplicatedOrUnsorted(address previous, address current);\n\n /**\n * @dev The settler is not the current contract\n */\n error SettlerInvalidSettler(address settler);\n\n /**\n * @dev The nonce is zero\n */\n error SettlerNonceZero();\n\n /**\n * @dev The nonce has already been used for the user\n */\n error SettlerNonceAlreadyUsed(address user, bytes32 nonce);\n\n /**\n * @dev The intent deadline is in the past\n */\n error SettlerIntentPastDeadline(uint256 deadline, uint256 timestamp);\n\n /**\n * @dev The current chain is not valid\n */\n error SettlerInvalidChain(uint256 chainId);\n\n /**\n * @dev The recipient is the settler contract\n */\n error SettlerInvalidRecipient(address to);\n\n /**\n * @dev The user is not a smart account\n */\n error SettlerUserNotSmartAccount(address user);\n\n /**\n * @dev The amount out is lower than the proposed amount\n */\n error SettlerAmountOutLtProposed(uint256 index, uint256 amountOut, uint256 proposed);\n\n /**\n * @dev The proposed amount is lower than the minimum amount\n */\n error SettlerProposedAmountLtMinAmount(uint256 index, uint256 proposed, uint256 minAmount);\n\n /**\n * @dev The proposed amounts array and the tokens out array are not of equal length\n */\n error SettlerInvalidProposedAmounts();\n\n /**\n * @dev The balance after the proposal execution is lower than the balance before\n */\n error SettlerPostBalanceOutLtPre(uint256 index, uint256 post, uint256 pre);\n\n /**\n * @dev The solver fees length does not match the requested by the user\n */\n error SettlerSolverFeeInvalidLength();\n\n /**\n * @dev The solver fee is too high\n */\n error SettlerSolverFeeTooHigh(uint256 fee, uint256 max);\n\n /**\n * @dev The intent validations are not enough\n */\n error SettlerIntentValidationsNotEnough(uint256 min, uint256 current);\n\n /**\n * @dev The proposal deadline is in the past\n */\n error SettlerProposalPastDeadline(uint256 deadline, uint256 timestamp);\n\n /**\n * @dev The proposal data is not empty\n */\n error SettlerProposalDataNotEmpty();\n\n /**\n * @dev The rescue funds recipient is zero\n */\n error SettlerRescueFundsRecipientZero();\n\n /**\n * @dev The list of safeguards exceed the maximum allowed\n */\n error SettlerTooManySafeguards(uint256 lengthRequested);\n\n /**\n * @dev The new smart accounts handler is zero\n */\n error SmartAccountsHandlerZero();\n\n /**\n * @dev Custom events emitted for each intent\n */\n event IntentExecuted(\n address indexed user,\n bytes32 indexed topic,\n uint8 indexed op,\n Intent intent,\n Proposal proposal,\n bytes output,\n bytes data\n );\n\n /**\n * @dev Emitted every time an intent is fulfilled\n */\n event ProposalExecuted(bytes32 indexed proposal, uint256 index);\n\n /**\n * @dev Emitted every time tokens are withdrawn from the contract balance\n */\n event FundsRescued(address indexed token, address indexed recipient, uint256 amount);\n\n /**\n * @dev Emitted every time the smart accounts handler is set\n */\n event SmartAccountsHandlerSet(address indexed smartAccountsHandler);\n\n /**\n * @dev Emitted every time the intents validator is set\n */\n event IntentsValidatorSet(address indexed intentsValidator);\n\n /**\n * @dev Emitted every time a safeguard is set\n */\n event SafeguardSet(address indexed user);\n\n /**\n * @dev Tells the reference to the Mimic controller\n */\n function controller() external view returns (address);\n\n /**\n * @dev Tells the reference to the smart accounts handler\n */\n function smartAccountsHandler() external view returns (address);\n\n /**\n * @dev Tells the reference to the intents validator\n */\n function intentsValidator() external view returns (address);\n\n /**\n * @dev Tells the block at which a user nonce was used. Returns 0 if unused.\n * @param user Address of the user being queried\n * @param nonce Nonce being queried\n */\n function getNonceBlock(address user, bytes32 nonce) external view returns (uint256);\n\n /**\n * @dev Tells the safeguard set for a user\n * @param user Address of the user being queried\n */\n function getUserSafeguard(address user) external view returns (bytes memory);\n\n /**\n * @dev Tells the hash of an intent\n * @param intent Intent to get the hash of\n */\n function getIntentHash(Intent memory intent) external pure returns (bytes32);\n\n /**\n * @dev Tells the hash of a proposal\n * @param proposal Proposal to be hashed\n * @param intent Intent being fulfilled by the requested proposal\n * @param solver Address of the solver that made the proposal\n */\n function getProposalHash(Proposal memory proposal, Intent memory intent, address solver)\n external\n pure\n returns (bytes32);\n\n /**\n * @dev Withdraws ERC20 or native tokens from the contract\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function rescueFunds(address token, address recipient, uint256 amount) external;\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function setSmartAccountsHandler(address newSmartAccountsHandler) external;\n\n /**\n * @dev Sets a new intents validator address\n * @param newIntentsValidator New intents validator to be set\n */\n function setIntentsValidator(address newIntentsValidator) external;\n\n /**\n * @dev Sets a safeguard for a user\n * @param safeguard Safeguard to be set\n */\n function setSafeguard(bytes memory safeguard) external;\n\n /**\n * @dev Executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function execute(Execution[] memory executions) external;\n\n /**\n * @dev Simulates an execution. It will always revert. Successful executions are returned as\n * `SettlerSimulationSuccess` errors. Any other error should be treated as failure.\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function simulate(Execution[] memory executions) external;\n}\n" + }, + "project/contracts/interfaces/ISmartAccount.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/introspection/IERC165.sol';\n\n/**\n * @title SmartAccount interface\n */\ninterface ISmartAccount is IERC165 {\n /**\n * @dev Emitted every time tokens are transferred\n */\n event Transferred(address indexed token, address indexed recipient, uint256 amount);\n\n /**\n * @dev Emitted every time `call` is called\n */\n event Called(address indexed target, bytes data, uint256 value, bytes result);\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the owner or the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) external;\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the owner or the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n */\n function call(address target, bytes memory data, uint256 value) external returns (bytes memory result);\n}\n" + }, + "project/contracts/interfaces/ISmartAccountContract.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/interfaces/IERC1271.sol';\n\nimport './ISmartAccount.sol';\n\n/**\n * @title SmartAccountContract interface\n */\ninterface ISmartAccountContract is ISmartAccount, IERC1271 {\n // solhint-disable-previous-line no-empty-blocks\n}\n" + }, + "project/contracts/interfaces/ISmartAccountsHandler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\ninterface ISmartAccountsHandler {\n /**\n * @dev The smart account given is not supported\n */\n error SmartAccountsHandlerUnsupportedAccount(address account);\n\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address account) external view returns (bool);\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address account, address token, address to, uint256 amount) external;\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address account, address target, bytes memory data, uint256 value) external returns (bytes memory);\n}\n" + }, + "project/contracts/safeguards/BaseIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @title BaseIntentsValidator\n */\ncontract BaseIntentsValidator {\n /**\n * @dev No intents allowed\n */\n error IntentsValidatorNoneAllowed();\n\n /**\n * @dev Intent type unknown\n */\n error IntentsValidatorUnknownIntentType(uint8 opType);\n\n /**\n * @dev Invalid safeguard mode\n */\n error IntentsValidatorInvalidSafeguardMode(uint8 mode);\n\n /**\n * @dev Tells whether a chain is allowed\n */\n function _isChainAllowed(uint256 chainId, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, uint256[] memory values) = abi.decode(config, (bool, uint256[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (chainId == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (chainId == values[i]) return true;\n }\n return false;\n }\n }\n\n /**\n * @dev Tells whether an account is allowed\n */\n function _isAccountAllowed(address account, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, address[] memory values) = abi.decode(config, (bool, address[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (account == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (account == values[i]) return true;\n }\n return false;\n }\n }\n\n /**\n * @dev Tells whether a selector is allowed\n */\n function _isSelectorAllowed(bytes4 selector, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, bytes4[] memory values) = abi.decode(config, (bool, bytes4[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (selector == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (selector == values[i]) return true;\n }\n return false;\n }\n }\n}\n" + }, + "project/contracts/safeguards/CallIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './Safeguards.sol';\nimport './BaseIntentsValidator.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Call safeguard modes to validate call intents\n * @param None To ensure no calls are allowed\n * @param Chain To validate that the chain where calls execute is allowed\n * @param Target To validate that the call targets (contract addresses) are allowed\n * @param Selector To validate that the function selectors being called are allowed\n */\nenum CallSafeguardMode {\n None,\n Chain,\n Target,\n Selector\n}\n\n/**\n * @title CallIntentsValidator\n * @dev Performs call intents validations based on safeguards\n */\ncontract CallIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a call intent is valid for a safeguard\n * @param intent Call intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isCallIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n CallIntent memory callIntent = abi.decode(intent.data, (CallIntent));\n if (safeguard.mode == uint8(CallSafeguardMode.Chain))\n return _isChainAllowed(callIntent.chainId, safeguard.config);\n if (safeguard.mode == uint8(CallSafeguardMode.Target))\n return _areCallTargetsValid(callIntent.calls, safeguard.config);\n if (safeguard.mode == uint8(CallSafeguardMode.Selector))\n return _areCallSelectorsValid(callIntent.calls, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the call targets are allowed\n */\n function _areCallTargetsValid(CallData[] memory calls, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < calls.length; i++) {\n if (!_isAccountAllowed(calls[i].target, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the call selectors are allowed\n */\n function _areCallSelectorsValid(CallData[] memory calls, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < calls.length; i++) {\n if (!_isSelectorAllowed(bytes4(calls[i].data), config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/safeguards/IntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './CallIntentsValidator.sol';\nimport './TransferIntentsValidator.sol';\nimport './Safeguards.sol';\nimport './SwapIntentsValidator.sol';\nimport '../Intents.sol';\nimport '../interfaces/IIntentsValidator.sol';\n\n/**\n * @title IntentsValidator\n * @dev Performs intents validations based on safeguards\n */\ncontract IntentsValidator is IIntentsValidator, SwapIntentsValidator, TransferIntentsValidator, CallIntentsValidator {\n /**\n * @dev Safeguard validation failed\n */\n error IntentsValidatorSafeguardFailed();\n\n /**\n * @dev Invalid safeguard config mode\n */\n error IntentsValidatorInvalidSafeguardConfigMode(uint8 mode);\n\n /**\n * @dev Invalid safeguard group logic mode\n */\n error IntentsValidatorInvalidSafeguardGroupLogicMode(uint8 mode);\n\n /**\n * @dev Tells whether an intent is valid for a safeguard\n * @param intent Intent to be validated\n * @param config Safeguard config to validate the intent with\n */\n function validate(Intent memory intent, bytes memory config) external pure override {\n (uint8 mode, bytes memory safeguard) = abi.decode(config, (uint8, bytes));\n if (mode == uint8(SafeguardConfigMode.List)) _validate(intent, abi.decode(safeguard, (Safeguard[])));\n else if (mode == uint8(SafeguardConfigMode.Tree)) _validate(intent, _decodeSafeguardTree(safeguard));\n else revert IntentsValidatorInvalidSafeguardConfigMode(mode);\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguards list\n * @param intent Intent to be validated\n * @param safeguards Safeguard list to validate the intent with\n */\n function _validate(Intent memory intent, Safeguard[] memory safeguards) internal pure {\n if (safeguards.length == 0) revert IntentsValidatorSafeguardFailed();\n for (uint256 i = 0; i < safeguards.length; i++) {\n if (!_isSafeguardValid(intent, safeguards[i])) revert IntentsValidatorSafeguardFailed();\n }\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard tree\n * @param intent Intent to be validated\n * @param tree Safeguard tree to validate the intent with\n */\n function _validate(Intent memory intent, SafeguardTree memory tree) internal pure {\n if (tree.nodes.length == 0) revert IntentsValidatorSafeguardFailed();\n if (!_isSafeguardGroupValid(intent, tree, 0)) revert IntentsValidatorSafeguardFailed();\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard tree at a certain level\n * @param intent Intent to be validated\n * @param tree Safeguard tree to validate the intent with\n * @param index Index of the group node to evaluate\n */\n function _isSafeguardGroupValid(Intent memory intent, SafeguardTree memory tree, uint16 index)\n internal\n pure\n returns (bool)\n {\n SafeguardGroup memory group = tree.nodes[index];\n\n if (group.logic == uint8(SafeguardGroupLogic.NOT)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i])) return false;\n }\n return true;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.AND)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (!_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (!_isSafeguardGroupValid(intent, tree, group.children[i])) return false;\n }\n return true;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.OR)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return true;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i])) return true;\n }\n return false;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.XOR)) {\n uint256 hits = 0;\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]]))\n if (++hits > 1) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i]))\n if (++hits > 1) return false;\n }\n return hits == 1;\n }\n\n revert IntentsValidatorInvalidSafeguardGroupLogicMode(group.logic);\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard\n * @param intent Intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isSafeguardValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n if (safeguard.mode == uint8(0)) revert IntentsValidatorNoneAllowed();\n if (intent.op == uint8(OpType.Swap)) return _isSwapIntentValid(intent, safeguard);\n if (intent.op == uint8(OpType.Transfer)) return _isTransferIntentValid(intent, safeguard);\n if (intent.op == uint8(OpType.Call)) return _isCallIntentValid(intent, safeguard);\n revert IntentsValidatorUnknownIntentType(uint8(intent.op));\n }\n\n /**\n * @dev Safely decodes a safeguard tree avoiding compiler issues with dynamic arrays\n * @param data Safeguard tree data to be decoded\n */\n function _decodeSafeguardTree(bytes memory data) private pure returns (SafeguardTree memory) {\n (SafeguardGroup[] memory nodes, Safeguard[] memory leaves) = abi.decode(data, (SafeguardGroup[], Safeguard[]));\n return SafeguardTree(nodes, leaves);\n }\n}\n" + }, + "project/contracts/safeguards/Safeguards.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Safeguard config modes\n * - List: Safeguard lists\n * - Tree: Safeguard groups\n */\nenum SafeguardConfigMode {\n List,\n Tree\n}\n\n/**\n * @dev Logical operators for safeguard groups\n * - AND: every child must pass\n * - OR: at least one child must pass\n * - XOR: exactly one child must pass\n * - NOT: every child must fail\n */\nenum SafeguardGroupLogic {\n AND,\n OR,\n XOR,\n NOT\n}\n\n/**\n * @dev Flat node in the safeguard tree\n * @param logic Group operator (AND/OR/XOR/NOT)\n * @param leaves Indices into `SafeguardTree.leaves`\n * @param children Indices into `SafeguardTree.nodes`\n */\nstruct SafeguardGroup {\n uint8 logic;\n uint16[] leaves;\n uint16[] children;\n}\n\n/**\n * @dev Safeguard tree representation\n * @param nodes List of all the nodes in the tree\n * @param leaves List of all the leaves in the tree\n */\nstruct SafeguardTree {\n SafeguardGroup[] nodes;\n Safeguard[] leaves;\n}\n\n/**\n * @dev Safeguard representation\n * @param mode Safeguard mode\n * @param config Safeguard configuration settings or parameters\n */\nstruct Safeguard {\n uint8 mode;\n bytes config;\n}\n" + }, + "project/contracts/safeguards/SwapIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './BaseIntentsValidator.sol';\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Swap safeguard modes to validate swap intents\n * @param None To ensure no swaps are allowed\n * @param SourceChain To validate that the source chain is allowed\n * @param DestinationChain To validate that the destination chain is allowed\n * @param TokenIn To validate that the tokens to be sent are allowed\n * @param TokenOut To validate that the tokens to be received are allowed\n * @param Recipient To validate that the recipients that will receive the tokens are allowed\n */\nenum SwapSafeguardMode {\n None,\n SourceChain,\n DestinationChain,\n TokenIn,\n TokenOut,\n Recipient\n}\n\n/**\n * @title SwapIntentsValidator\n * @dev Performs swap intents validations based on safeguards\n */\ncontract SwapIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a swap intent is valid for a safeguard\n * @param intent Swap intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isSwapIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n if (safeguard.mode == uint8(SwapSafeguardMode.SourceChain))\n return _isChainAllowed(swapIntent.sourceChain, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.DestinationChain))\n return _isChainAllowed(swapIntent.destinationChain, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.TokenIn))\n return _areSwapTokensInValid(swapIntent.tokensIn, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.TokenOut))\n return _areSwapTokensOutValid(swapIntent.tokensOut, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.Recipient))\n return _areSwapRecipientsValid(swapIntent.tokensOut, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the tokens to be sent are allowed\n */\n function _areSwapTokensInValid(TokenIn[] memory tokensIn, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensIn.length; i++) {\n if (!_isAccountAllowed(tokensIn[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the tokens to be received are allowed\n */\n function _areSwapTokensOutValid(TokenOut[] memory tokensOut, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensOut.length; i++) {\n if (!_isAccountAllowed(tokensOut[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the recipients to be received are allowed\n */\n function _areSwapRecipientsValid(TokenOut[] memory tokensOut, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensOut.length; i++) {\n if (!_isAccountAllowed(tokensOut[i].recipient, config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/safeguards/TransferIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './BaseIntentsValidator.sol';\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Transfer safeguard modes to validate transfer intents\n * @param None To ensure no transfers are allowed\n * @param Chain To validate that the chain where transfers execute is allowed\n * @param Token To validate that the tokens being transferred are allowed\n * @param Recipient To validate that the recipients of the transfers are allowed\n */\nenum TransferSafeguardMode {\n None,\n Chain,\n Token,\n Recipient\n}\n\n/**\n * @title TransferIntentsValidator\n * @dev Performs transfer intents validations based on safeguards\n */\ncontract TransferIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a transfer intent is valid for a safeguard\n * @param intent Transfer intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isTransferIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n TransferIntent memory transferIntent = abi.decode(intent.data, (TransferIntent));\n if (safeguard.mode == uint8(TransferSafeguardMode.Chain))\n return _isChainAllowed(transferIntent.chainId, safeguard.config);\n if (safeguard.mode == uint8(TransferSafeguardMode.Token))\n return _areTransferTokensValid(transferIntent.transfers, safeguard.config);\n if (safeguard.mode == uint8(TransferSafeguardMode.Recipient))\n return _areTransferRecipientsValid(transferIntent.transfers, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the tokens being transferred are allowed\n */\n function _areTransferTokensValid(TransferData[] memory transfers, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < transfers.length; i++) {\n if (!_isAccountAllowed(transfers[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the recipients of the transfers are allowed\n */\n function _areTransferRecipientsValid(TransferData[] memory transfers, bytes memory config)\n private\n pure\n returns (bool)\n {\n for (uint256 i = 0; i < transfers.length; i++) {\n if (!_isAccountAllowed(transfers[i].recipient, config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/Settler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/cryptography/ECDSA.sol';\nimport '@openzeppelin/contracts/utils/cryptography/EIP712.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165Checker.sol';\n\nimport './Intents.sol';\nimport './interfaces/IController.sol';\nimport './interfaces/IIntentsValidator.sol';\nimport './interfaces/IExecutor.sol';\nimport './interfaces/ISettler.sol';\nimport './utils/Denominations.sol';\nimport './utils/ERC20Helpers.sol';\nimport './smart-accounts/SmartAccountsHandler.sol';\nimport './smart-accounts/SmartAccountsHandlerHelpers.sol';\n\n/**\n * @title Settler\n * @dev Contract that provides the appropriate context for solvers to execute proposals that fulfill user intents\n */\ncontract Settler is ISettler, Ownable, ReentrancyGuard, EIP712 {\n using SafeERC20 for IERC20;\n using IntentsHelpers for Intent;\n using IntentsHelpers for Proposal;\n using IntentsHelpers for Validation;\n using SmartAccountsHandlerHelpers for address;\n\n // Mimic controller reference\n // solhint-disable-next-line immutable-vars-naming\n address public immutable override controller;\n\n // Smart accounts handler reference\n address public override smartAccountsHandler;\n\n // Intents validator reference\n address public override intentsValidator;\n\n // List of block numbers at which a user nonce was used\n mapping (address => mapping (bytes32 => uint256)) public override getNonceBlock;\n\n // Safeguard config per user\n mapping (address => bytes) internal _userSafeguard;\n\n /**\n * @dev Modifier to tag settler functions in order to check if the sender is an allowed solver\n */\n modifier onlySolver() {\n address sender = _msgSender();\n if (!IController(controller).isSolverAllowed(sender)) revert SettlerSolverNotAllowed(sender);\n _;\n }\n\n /**\n * @dev Creates a new Settler contract\n * @param _controller Address of the Settler controller\n * @param _owner Address that will own the contract\n */\n constructor(address _controller, address _owner) Ownable(_owner) EIP712('Mimic Protocol Settler', '1') {\n controller = _controller;\n smartAccountsHandler = address(new SmartAccountsHandler());\n }\n\n /**\n * @dev Tells the hash of an intent\n * @param intent Intent to get the hash of\n */\n function getIntentHash(Intent memory intent) external pure override returns (bytes32) {\n return intent.hash();\n }\n\n /**\n * @dev Tells the hash of a proposal\n * @param proposal Proposal to be hashed\n * @param intent Intent being fulfilled by the requested proposal\n * @param solver Address of the solver that made the proposal\n */\n function getProposalHash(Proposal memory proposal, Intent memory intent, address solver)\n external\n pure\n override\n returns (bytes32)\n {\n return proposal.hash(intent, solver);\n }\n\n /**\n * @dev Tells the safeguard set for a user\n * @param user Address of the user being queried\n */\n function getUserSafeguard(address user) external view override returns (bytes memory) {\n return _userSafeguard[user];\n }\n\n /**\n * @dev It allows receiving native token transfers\n * Note: This method mainly allows supporting native tokens for swaps\n */\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n /**\n * @dev Withdraws ERC20 or native tokens from the contract\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function rescueFunds(address token, address recipient, uint256 amount) external override onlyOwner nonReentrant {\n if (recipient == address(0)) revert SettlerRescueFundsRecipientZero();\n ERC20Helpers.transfer(token, recipient, amount);\n emit FundsRescued(token, recipient, amount);\n }\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function setSmartAccountsHandler(address newSmartAccountsHandler) external override onlyOwner {\n _setSmartAccountsHandler(newSmartAccountsHandler);\n }\n\n /**\n * @dev Sets a new intents validator address\n * @param newIntentsValidator New intents validator to be set\n */\n function setIntentsValidator(address newIntentsValidator) external override onlyOwner {\n _setIntentsValidator(newIntentsValidator);\n }\n\n /**\n * @dev Sets a safeguard for a user\n * @param safeguard Safeguard to be set\n */\n function setSafeguard(bytes memory safeguard) external override {\n _setSafeguard(msg.sender, safeguard);\n }\n\n /**\n * @dev Executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function execute(Execution[] memory executions) external override onlySolver {\n _execute(executions, false);\n }\n\n /**\n * @dev Simulates an execution. It will always revert. Successful executions are returned as\n * `SettlerSimulationSuccess` errors. Any other error should be treated as failure.\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function simulate(Execution[] memory executions) external override onlySolver {\n uint256 initialGas = gasleft();\n _execute(executions, true);\n uint256 gasUsed = initialGas - gasleft();\n revert SettlerSimulationSuccess(gasUsed);\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n * @param simulated Whether the execution is a simulation\n */\n function _execute(Execution[] memory executions, bool simulated) internal nonReentrant {\n for (uint256 i = 0; i < executions.length; i++) {\n Intent memory intent = executions[i].intent;\n Proposal memory proposal = executions[i].proposal;\n bytes memory signature = executions[i].signature;\n\n _validateIntent(intent, proposal, signature, simulated);\n getNonceBlock[intent.user][intent.nonce] = block.number;\n\n if (intent.op == uint8(OpType.Swap)) _executeSwap(intent, proposal);\n else if (intent.op == uint8(OpType.Transfer)) _executeTransfer(intent, proposal);\n else if (intent.op == uint8(OpType.Call)) _executeCall(intent, proposal);\n else revert SettlerUnknownIntentType(uint8(intent.op));\n\n emit ProposalExecuted(proposal.hash(intent, _msgSender()), i);\n }\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a swap intent\n * @param intent Swap intent to be fulfilled\n * @param proposal Swap proposal to be executed\n */\n function _executeSwap(Intent memory intent, Proposal memory proposal) internal {\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n _validateSwapIntent(swapIntent, swapProposal);\n\n bool isSmartAccount = smartAccountsHandler.isSmartAccount(intent.user);\n if (swapIntent.sourceChain == block.chainid) {\n for (uint256 i = 0; i < swapIntent.tokensIn.length; i++) {\n TokenIn memory tokenIn = swapIntent.tokensIn[i];\n _transferFrom(tokenIn.token, intent.user, swapProposal.executor, tokenIn.amount, isSmartAccount);\n }\n }\n\n uint256[] memory preBalancesOut = _getTokensOutBalance(swapIntent);\n IExecutor(swapProposal.executor).execute(intent, proposal);\n\n if (swapIntent.destinationChain == block.chainid) {\n uint256[] memory outputs = new uint256[](swapIntent.tokensOut.length);\n for (uint256 i = 0; i < swapIntent.tokensOut.length; i++) {\n TokenOut memory tokenOut = swapIntent.tokensOut[i];\n uint256 postBalanceOut = ERC20Helpers.balanceOf(tokenOut.token, address(this));\n uint256 preBalanceOut = preBalancesOut[i];\n if (postBalanceOut < preBalanceOut) revert SettlerPostBalanceOutLtPre(i, postBalanceOut, preBalanceOut);\n\n outputs[i] = postBalanceOut - preBalanceOut;\n uint256 proposedAmount = swapProposal.amountsOut[i];\n if (outputs[i] < proposedAmount) revert SettlerAmountOutLtProposed(i, outputs[i], proposedAmount);\n\n ERC20Helpers.transfer(tokenOut.token, tokenOut.recipient, outputs[i]);\n }\n\n _emitIntentEvents(intent, proposal, abi.encode(outputs));\n _payFees(intent, proposal, isSmartAccount);\n }\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a transfer intent\n * @param intent Transfer intent to be fulfilled\n * @param proposal Transfer proposal to be executed\n */\n function _executeTransfer(Intent memory intent, Proposal memory proposal) internal {\n TransferIntent memory transferIntent = abi.decode(intent.data, (TransferIntent));\n _validateTransferIntent(transferIntent, proposal);\n\n bool isSmartAccount = smartAccountsHandler.isSmartAccount(intent.user);\n for (uint256 i = 0; i < transferIntent.transfers.length; i++) {\n TransferData memory transfer = transferIntent.transfers[i];\n _transferFrom(transfer.token, intent.user, transfer.recipient, transfer.amount, isSmartAccount);\n }\n\n _emitIntentEvents(intent, proposal, new bytes(0));\n _payFees(intent, proposal, isSmartAccount);\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a call intent\n * @param intent Call intent to be fulfilled\n * @param proposal Call proposal to be executed\n */\n function _executeCall(Intent memory intent, Proposal memory proposal) internal {\n CallIntent memory callIntent = abi.decode(intent.data, (CallIntent));\n _validateCallIntent(callIntent, proposal, intent.user);\n\n bytes[] memory outputs = new bytes[](callIntent.calls.length);\n for (uint256 i = 0; i < callIntent.calls.length; i++) {\n CallData memory call = callIntent.calls[i];\n // solhint-disable-next-line avoid-low-level-calls\n outputs[i] = smartAccountsHandler.call(intent.user, call.target, call.data, call.value);\n }\n\n _emitIntentEvents(intent, proposal, abi.encode(outputs));\n _payFees(intent, proposal, true);\n }\n\n /**\n * @dev Validates an intent and its corresponding proposal\n * @param intent Intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param signature Proposal signature\n * @param simulated Whether the execution is a simulation\n */\n function _validateIntent(Intent memory intent, Proposal memory proposal, bytes memory signature, bool simulated)\n internal\n view\n {\n if (intent.settler != address(this)) revert SettlerInvalidSettler(intent.settler);\n if (intent.nonce == bytes32(0)) revert SettlerNonceZero();\n if (getNonceBlock[intent.user][intent.nonce] != 0) revert SettlerNonceAlreadyUsed(intent.user, intent.nonce);\n\n if (intentsValidator != address(0)) {\n bytes memory safeguard = _userSafeguard[intent.user];\n if (safeguard.length > 0) IIntentsValidator(intentsValidator).validate(intent, safeguard);\n }\n\n bool shouldValidateDeadlines = _shouldValidateDeadlines(intent);\n if (shouldValidateDeadlines) {\n if (intent.deadline <= block.timestamp) revert SettlerIntentPastDeadline(intent.deadline, block.timestamp);\n bool isProposalPastDeadline = proposal.deadline <= block.timestamp;\n if (isProposalPastDeadline) revert SettlerProposalPastDeadline(proposal.deadline, block.timestamp);\n }\n\n if (intent.maxFees.length != proposal.fees.length) revert SettlerSolverFeeInvalidLength();\n for (uint256 i = 0; i < intent.maxFees.length; i++) {\n uint256 maxFee = intent.maxFees[i].amount;\n uint256 proposalFee = proposal.fees[i];\n if (proposalFee > maxFee) revert SettlerSolverFeeTooHigh(proposalFee, maxFee);\n }\n\n uint8 minValidations = IController(controller).minValidations();\n uint256 requiredValidations = intent.minValidations > minValidations ? intent.minValidations : minValidations;\n\n if (intent.validations.length < requiredValidations) {\n revert SettlerIntentValidationsNotEnough(requiredValidations, intent.validations.length);\n }\n\n address lastValidator = address(0);\n Validation memory validation = Validation(intent.hash());\n bytes32 typedDataHash = _hashTypedDataV4(validation.hash());\n for (uint256 i = 0; i < intent.validations.length; i++) {\n address validator = ECDSA.recover(typedDataHash, intent.validations[i]);\n if (validator <= lastValidator) {\n revert SettlerValidatorDuplicatedOrUnsorted(lastValidator, validator);\n }\n lastValidator = validator;\n bool isValidatorNotAllowed = !IController(controller).isValidatorAllowed(validator);\n if (isValidatorNotAllowed) revert SettlerValidatorNotAllowed(validator);\n }\n\n address signer = ECDSA.recover(_hashTypedDataV4(proposal.hash(intent, _msgSender())), signature);\n bool isProposalSignerNotAllowed = !IController(controller).isProposalSignerAllowed(signer) && !simulated;\n if (isProposalSignerNotAllowed) revert SettlerProposalSignerNotAllowed(signer);\n }\n\n /**\n * @dev Validates a swap intent and its corresponding proposal\n * @param intent Swap intent to be fulfilled\n * @param proposal Proposal to be executed\n */\n function _validateSwapIntent(SwapIntent memory intent, SwapProposal memory proposal) internal view {\n bool isChainInvalid = intent.sourceChain != block.chainid && intent.destinationChain != block.chainid;\n if (isChainInvalid) revert SettlerInvalidChain(block.chainid);\n\n if (proposal.amountsOut.length != intent.tokensOut.length) revert SettlerInvalidProposedAmounts();\n\n for (uint256 i = 0; i < intent.tokensOut.length; i++) {\n TokenOut memory tokenOut = intent.tokensOut[i];\n address recipient = tokenOut.recipient;\n if (recipient == address(this)) revert SettlerInvalidRecipient(recipient);\n\n uint256 minAmount = tokenOut.minAmount;\n uint256 proposedAmount = proposal.amountsOut[i];\n if (proposedAmount < minAmount) revert SettlerProposedAmountLtMinAmount(i, proposedAmount, minAmount);\n }\n\n if (intent.sourceChain != intent.destinationChain) {\n bool isExecutorInvalid = !IController(controller).isExecutorAllowed(proposal.executor);\n if (isExecutorInvalid) revert SettlerExecutorNotAllowed(proposal.executor);\n }\n }\n\n /**\n * @dev Validates a transfer intent and its corresponding proposal\n * @param intent Transfer intent to be fulfilled\n * @param proposal Proposal to be executed\n */\n function _validateTransferIntent(TransferIntent memory intent, Proposal memory proposal) internal view {\n if (intent.chainId != block.chainid) revert SettlerInvalidChain(block.chainid);\n if (proposal.data.length > 0) revert SettlerProposalDataNotEmpty();\n for (uint256 i = 0; i < intent.transfers.length; i++) {\n address recipient = intent.transfers[i].recipient;\n if (recipient == address(this)) revert SettlerInvalidRecipient(recipient);\n }\n }\n\n /**\n * @dev Validates a call intent and its corresponding proposal\n * @param intent Call intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param user The originator of the intent\n */\n function _validateCallIntent(CallIntent memory intent, Proposal memory proposal, address user) internal view {\n if (intent.chainId != block.chainid) revert SettlerInvalidChain(block.chainid);\n if (proposal.data.length > 0) revert SettlerProposalDataNotEmpty();\n if (!smartAccountsHandler.isSmartAccount(user)) revert SettlerUserNotSmartAccount(user);\n }\n\n /**\n * @dev Tells the contract balance for each token out of a swap intent\n * @param intent Swap intent containing the list of tokens out\n */\n function _getTokensOutBalance(SwapIntent memory intent) internal view returns (uint256[] memory balances) {\n balances = new uint256[](intent.tokensOut.length);\n if (intent.destinationChain == block.chainid) {\n for (uint256 i = 0; i < intent.tokensOut.length; i++) {\n balances[i] = ERC20Helpers.balanceOf(intent.tokensOut[i].token, address(this));\n }\n }\n }\n\n /**\n * @dev Tells if the intent and proposal deadlines should be validated\n * @param intent Intent to be fulfilled\n */\n function _shouldValidateDeadlines(Intent memory intent) internal view returns (bool) {\n if (intent.op != uint8(OpType.Swap)) return true;\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n if (swapIntent.sourceChain == swapIntent.destinationChain) return true;\n return swapIntent.sourceChain == block.chainid;\n }\n\n /**\n * @dev Emits intent custom events\n * @param intent Intent to emit the custom events for\n * @param proposal Proposal that fulfills the intent\n * @param output Encoded array of outputs\n */\n function _emitIntentEvents(Intent memory intent, Proposal memory proposal, bytes memory output) internal {\n for (uint256 i = 0; i < intent.events.length; i++) {\n IntentEvent memory intentEvent = intent.events[i];\n emit IntentExecuted(\n intent.user,\n intentEvent.topic,\n uint8(intent.op),\n intent,\n proposal,\n output,\n intentEvent.data\n );\n }\n }\n\n /**\n * @dev Pays fees\n * @param intent Intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param isSmartAccount Whether the intent user is a smart account\n */\n function _payFees(Intent memory intent, Proposal memory proposal, bool isSmartAccount) internal {\n address from = intent.user;\n address to = _msgSender();\n for (uint256 i = 0; i < intent.maxFees.length; i++) {\n address token = intent.maxFees[i].token;\n if (!Denominations.isUSD(token)) _transferFrom(token, from, to, proposal.fees[i], isSmartAccount);\n }\n }\n\n /**\n * @dev Transfers tokens from one account to another\n * @param token Address of the token to transfer\n * @param from Address of the account sending the tokens\n * @param to Address of the account receiving the tokens\n * @param amount Amount of tokens to transfer\n * @param isSmartAccount Whether the sender is a smart account\n */\n function _transferFrom(address token, address from, address to, uint256 amount, bool isSmartAccount) internal {\n if (isSmartAccount) {\n smartAccountsHandler.transfer(from, token, to, amount);\n } else {\n IERC20(token).safeTransferFrom(from, to, amount);\n }\n }\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function _setSmartAccountsHandler(address newSmartAccountsHandler) internal {\n if (newSmartAccountsHandler == address(0)) revert SmartAccountsHandlerZero();\n smartAccountsHandler = newSmartAccountsHandler;\n emit SmartAccountsHandlerSet(newSmartAccountsHandler);\n }\n\n /**\n * @dev Sets the intents validator\n * @param newIntentsValidator New intents validator to be set\n */\n function _setIntentsValidator(address newIntentsValidator) internal {\n intentsValidator = newIntentsValidator;\n emit IntentsValidatorSet(newIntentsValidator);\n }\n\n /**\n * @dev Sets a safeguard for a user\n * @param user Address of the user to set the safeguard for\n * @param safeguard Safeguard to be set\n */\n function _setSafeguard(address user, bytes memory safeguard) internal {\n delete _userSafeguard[user];\n _userSafeguard[user] = safeguard;\n emit SafeguardSet(user);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccount7702.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/Context.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccount.sol';\nimport '../utils/ERC20Helpers.sol';\nimport './SmartAccountBase.sol';\n\n/**\n * @title SmartAccount7702\n * @dev Provides the smart account logic to use with EIP7702\n */\ncontract SmartAccount7702 is SmartAccountBase {\n // Mimic settler reference\n // solhint-disable-next-line immutable-vars-naming\n address public immutable settler;\n\n /**\n * @dev The sender is not the settler\n */\n error SmartAccount7702SenderNotSettler();\n\n /**\n * @dev Reverts unless the sender is the settler\n */\n modifier onlySettler() {\n if (_msgSender() != settler) revert SmartAccount7702SenderNotSettler();\n _;\n }\n\n /**\n * @dev Creates a new SmartAccount7702 contract\n * @param _settler Address of the Mimic settler\n */\n constructor(address _settler) {\n settler = _settler;\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) public override onlySettler {\n super.transfer(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value) public override onlySettler returns (bytes memory) {\n // solhint-disable-next-line avoid-low-level-calls\n return super.call(target, data, value);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountBase.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/Context.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccount.sol';\nimport '../utils/ERC20Helpers.sol';\n\n/**\n * @title SmartAccountBase\n * @dev Provides the base logic for managing assets and executing arbitrary calls\n */\ncontract SmartAccountBase is ISmartAccount, Context, ERC165, ReentrancyGuard {\n /**\n * @dev Tells whether the contract supports the given interface ID. Overrides ERC165 to declare support for ISmartAccount interface.\n * @param interfaceId Interface ID is defined as the XOR of all function selectors in the interface\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {\n return interfaceId == type(ISmartAccount).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) public virtual override nonReentrant {\n ERC20Helpers.transfer(token, recipient, amount);\n emit Transferred(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value)\n public\n virtual\n override\n nonReentrant\n returns (bytes memory result)\n {\n result = Address.functionCallWithValue(target, data, value);\n emit Called(target, data, value, result);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountContract.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/cryptography/ECDSA.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccountContract.sol';\nimport './SmartAccountBase.sol';\n\n/**\n * @title SmartAccountContract\n * @dev Provides the smart account logic to use as a standalone contract\n */\ncontract SmartAccountContract is ISmartAccountContract, Ownable, SmartAccountBase {\n // EIP1271 magic return value\n bytes4 internal constant EIP1271_MAGIC_VALUE = 0x1626ba7e;\n\n // EIP1271 invalid signature return value\n bytes4 internal constant EIP1271_INVALID_SIGNATURE = 0xffffffff;\n\n // List of account permissions\n mapping (address => bool) public isSignerAllowed;\n\n // Mimic settler reference\n address public settler;\n\n /**\n * @dev The settler is zero\n */\n error SmartAccountSettlerZero();\n\n /**\n * @dev The input arrays are not of equal length\n */\n error SmartAccountInputInvalidLength();\n\n /**\n * @dev The sender is not the owner or the settler\n */\n error SmartAccountUnauthorizedSender(address sender);\n\n /**\n * @dev Emitted every time the settler is set\n */\n event SettlerSet(address indexed settler);\n\n /**\n * @dev Emitted every time a signer allowance is set\n */\n event SignerAllowedSet(address indexed account, bool allowed);\n\n /**\n * @dev Reverts unless the sender is the owner or the settler\n */\n modifier onlyOwnerOrSettler() {\n address sender = _msgSender();\n bool isAuthorized = sender == owner() || sender == settler;\n if (!isAuthorized) revert SmartAccountUnauthorizedSender(sender);\n _;\n }\n\n /**\n * @dev Creates a new SmartAccount contract\n * @param _settler Address of the Mimic settler\n * @param _owner Address that will own the contract\n */\n constructor(address _settler, address _owner) Ownable(_owner) {\n _setSettler(_settler);\n }\n\n /**\n * @dev Tells whether the signature provided belongs to an allowed account.\n * @param hash Message signed by the account\n * @param signature Signature provided to be verified\n */\n function isValidSignature(bytes32 hash, bytes memory signature) external view override returns (bytes4) {\n (address signer, , ) = ECDSA.tryRecover(hash, signature);\n if (signer != address(0) && (signer == owner() || isSignerAllowed[signer])) return EIP1271_MAGIC_VALUE;\n return EIP1271_INVALID_SIGNATURE;\n }\n\n /**\n * @dev It allows receiving native token transfers\n */\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n /**\n * @dev Sets the settler. Sender must be the owner.\n * @param newSettler Address of the new settler to be set\n */\n function setSettler(address newSettler) external onlyOwner {\n _setSettler(newSettler);\n }\n\n /**\n * @dev Sets a list of allowed signers. Sender must be the owner.\n * @param accounts List of account addresses\n * @param allowances List of allowed condition per account\n */\n function setAllowedSigners(address[] memory accounts, bool[] memory allowances) external onlyOwner {\n if (accounts.length != allowances.length) revert SmartAccountInputInvalidLength();\n for (uint256 i = 0; i < accounts.length; i++) {\n address account = accounts[i];\n bool allowed = allowances[i];\n isSignerAllowed[account] = allowed;\n emit SignerAllowedSet(account, allowed);\n }\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the owner or the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount)\n public\n override(ISmartAccount, SmartAccountBase)\n onlyOwnerOrSettler\n {\n super.transfer(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the owner or the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value)\n public\n override(ISmartAccount, SmartAccountBase)\n onlyOwnerOrSettler\n returns (bytes memory)\n {\n // solhint-disable-next-line avoid-low-level-calls\n return super.call(target, data, value);\n }\n\n /**\n * @dev Sets the settler\n * @param newSettler Address of the new settler to be set\n */\n function _setSettler(address newSettler) internal {\n if (newSettler == address(0)) revert SmartAccountSettlerZero();\n settler = newSettler;\n emit SettlerSet(newSettler);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountsHandler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport '../interfaces/ISafe.sol';\nimport '../interfaces/ISmartAccount.sol';\nimport '../interfaces/ISmartAccountsHandler.sol';\nimport '../utils/Denominations.sol';\n\ncontract SmartAccountsHandler is ISmartAccountsHandler {\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address account) external view override returns (bool) {\n if (account.code.length == 0) return false;\n if (_isMimicSmartAccount(account)) return true;\n if (_isSafe(account)) return true;\n return false;\n }\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address account, address token, address to, uint256 amount) external override {\n if (_isMimicSmartAccount(account)) return ISmartAccount(account).transfer(token, to, amount);\n if (_isSafe(account)) return _transferSafe(account, token, to, amount);\n revert SmartAccountsHandlerUnsupportedAccount(account);\n }\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address account, address target, bytes memory data, uint256 value)\n external\n override\n returns (bytes memory)\n {\n // solhint-disable-next-line avoid-low-level-calls\n if (_isMimicSmartAccount(account)) return ISmartAccount(account).call(target, data, value);\n if (_isSafe(account)) return _callSafe(account, target, data, value);\n revert SmartAccountsHandlerUnsupportedAccount(account);\n }\n\n /**\n * @dev Performs a transfer from a safe\n */\n function _transferSafe(address account, address token, address to, uint256 amount) internal {\n Denominations.isNativeToken(token)\n ? _callSafe(account, to, new bytes(0), amount)\n : _callSafe(account, token, abi.encodeWithSelector(IERC20.transfer.selector, to, amount), 0);\n }\n\n /**\n * @dev Performs a call from a safe\n */\n function _callSafe(address account, address target, bytes memory data, uint256 value)\n internal\n returns (bytes memory)\n {\n (bool success, bytes memory result) = ISafe(account).execTransactionFromModuleReturnData(\n target,\n value,\n data,\n SafeOperation.Call\n );\n return\n data.length == 0\n ? Address.verifyCallResult(success, result)\n : Address.verifyCallResultFromTarget(target, success, result);\n }\n\n /**\n * @dev Tells whether an account is a Mimic smart account\n * @param account Address of the account being queried\n */\n function _isMimicSmartAccount(address account) internal view returns (bool) {\n try ISmartAccount(account).supportsInterface(type(ISmartAccount).interfaceId) returns (bool ok) {\n return ok;\n } catch {\n return false;\n }\n }\n\n /**\n * @dev Tells whether an account is a Gnosis Safe\n * @param account Address of the account being queried\n */\n function _isSafe(address account) internal view returns (bool) {\n try ISafe(account).getThreshold() returns (uint256) {\n return true;\n } catch {\n return false;\n }\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountsHandlerHelpers.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport '../interfaces/ISmartAccountsHandler.sol';\n\nlibrary SmartAccountsHandlerHelpers {\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address handler, address account) internal view returns (bool) {\n return ISmartAccountsHandler(handler).isSmartAccount(account);\n }\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address handler, address account, address token, address to, uint256 amount) internal {\n Address.functionDelegateCall(\n handler,\n abi.encodeWithSelector(ISmartAccountsHandler.transfer.selector, account, token, to, amount)\n );\n }\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address handler, address account, address target, bytes memory data, uint256 value)\n internal\n returns (bytes memory)\n {\n return\n Address.functionDelegateCall(\n handler,\n abi.encodeWithSelector(ISmartAccountsHandler.call.selector, account, target, data, value)\n );\n }\n}\n" + }, + "project/contracts/test/CallMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\ncontract CallMock {\n event CallReceived(address indexed sender, uint256 value);\n error CallError();\n\n function call() external payable {\n emit CallReceived(msg.sender, msg.value);\n }\n\n function callError() external payable {\n revert CallError();\n }\n}\n" + }, + "project/contracts/test/executors/EmptyExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\n\ncontract EmptyExecutorMock is IExecutor {\n event Executed();\n\n function execute(Intent memory, Proposal memory) external override {\n emit Executed();\n }\n}\n" + }, + "project/contracts/test/executors/MintExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../TokenMock.sol';\nimport '../../interfaces/IExecutor.sol';\n\n/* solhint-disable custom-errors */\n\ncontract MintExecutorMock is IExecutor {\n event Minted();\n\n function execute(Intent memory intent, Proposal memory proposal) external override {\n require(intent.op == uint8(OpType.Swap), 'Invalid intent type');\n\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n (address[] memory tokens, uint256[] memory amounts) = abi.decode(swapProposal.data, (address[], uint256[]));\n\n require(tokens.length == amounts.length, 'Invalid inputs');\n\n for (uint256 i = 0; i < tokens.length; i++) {\n TokenMock(tokens[i]).mint(msg.sender, amounts[i]);\n emit Minted();\n }\n }\n}\n" + }, + "project/contracts/test/executors/ReentrantExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\nimport '../../interfaces/ISettler.sol';\n\ncontract ReentrantExecutorMock is IExecutor {\n // solhint-disable-next-line immutable-vars-naming\n address payable public immutable settler;\n\n constructor(address payable _settler) {\n settler = _settler;\n }\n\n function execute(Intent memory, Proposal memory) external override {\n ISettler(settler).execute(new Execution[](0));\n }\n}\n" + }, + "project/contracts/test/executors/TransferExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\nimport '../../utils/ERC20Helpers.sol';\n\n/* solhint-disable custom-errors */\n\ncontract TransferExecutorMock is IExecutor {\n event Transferred();\n\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n function execute(Intent memory intent, Proposal memory proposal) external override {\n require(intent.op == uint8(OpType.Swap), 'Invalid intent type');\n\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n (address[] memory tokens, uint256[] memory amounts) = abi.decode(swapProposal.data, (address[], uint256[]));\n\n require(tokens.length == amounts.length, 'Invalid inputs');\n\n for (uint256 i = 0; i < tokens.length; i++) {\n ERC20Helpers.transfer(tokens[i], msg.sender, amounts[i]);\n emit Transferred();\n }\n }\n}\n" + }, + "project/contracts/test/smart-accounts/SafeMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/ISafe.sol';\n\ncontract SafeMock is ISafe {\n event ModuleTxExecuted(\n address indexed target,\n bytes data,\n uint256 value,\n SafeOperation operation,\n bool success,\n bytes result\n );\n\n receive() external payable {}\n\n function getThreshold() external pure returns (uint256) {\n return 1;\n }\n\n function execTransactionFromModuleReturnData(address to, uint256 value, bytes memory data, SafeOperation operation)\n external\n returns (bool success, bytes memory result)\n {\n // solhint-disable-next-line avoid-low-level-calls\n (success, result) = to.call{ value: value }(data);\n emit ModuleTxExecuted(to, data, value, operation, success, result);\n }\n}\n" + }, + "project/contracts/test/TokenMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/ERC20.sol';\n\ncontract TokenMock is ERC20 {\n uint8 internal _decimals;\n\n constructor(string memory symbol, uint8 dec) ERC20(symbol, symbol) {\n _decimals = dec;\n }\n\n function mint(address account, uint256 amount) external {\n _mint(account, amount);\n }\n\n function decimals() public view override returns (uint8) {\n return _decimals;\n }\n}\n" + }, + "project/contracts/test/utils/DenominationsMock.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '../../utils/Denominations.sol';\n\n// solhint-disable func-name-mixedcase\n\ncontract DenominationsMock {\n function NATIVE_TOKEN() external pure returns (address) {\n return Denominations.NATIVE_TOKEN;\n }\n\n function USD() external pure returns (address) {\n return Denominations.USD;\n }\n}\n" + }, + "project/contracts/test/utils/ERC20HelpersMock.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '../../utils/ERC20Helpers.sol';\n\ncontract ERC20HelpersMock {\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n function approve(address token, address to, uint256 amount) external {\n ERC20Helpers.approve(token, to, amount);\n }\n\n function transfer(address token, address to, uint256 amount) external {\n ERC20Helpers.transfer(token, to, amount);\n }\n\n function balanceOf(address token, address account) external view returns (uint256) {\n return ERC20Helpers.balanceOf(token, account);\n }\n}\n" + }, + "project/contracts/utils/Denominations.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\n/**\n * @title Denominations\n * @dev Provides a list of ground denominations for those tokens that cannot be represented by an ERC20.\n * For now, the only needed is the native token that could be ETH, MATIC, or other depending on the layer being operated.\n */\nlibrary Denominations {\n address internal constant NATIVE_TOKEN = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;\n\n // Fiat currencies follow https://en.wikipedia.org/wiki/ISO_4217\n address internal constant USD = address(840);\n\n function isUSD(address token) internal pure returns (bool) {\n return token == USD;\n }\n\n function isNativeToken(address token) internal pure returns (bool) {\n return token == NATIVE_TOKEN;\n }\n}\n" + }, + "project/contracts/utils/ERC20Helpers.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport './Denominations.sol';\n\n/**\n * @title ERC20Helpers\n * @dev Provides a list of ERC20 helper methods\n */\nlibrary ERC20Helpers {\n function approve(address token, address to, uint256 amount) internal {\n SafeERC20.forceApprove(IERC20(token), to, amount);\n }\n\n function transfer(address token, address to, uint256 amount) internal {\n if (Denominations.isNativeToken(token)) Address.sendValue(payable(to), amount);\n else SafeERC20.safeTransfer(IERC20(token), to, amount);\n }\n\n function balanceOf(address token, address account) internal view returns (uint256) {\n if (Denominations.isNativeToken(token)) return address(account).balance;\n else return IERC20(token).balanceOf(address(account));\n }\n}\n" + }, + "project/contracts/utils/MimicHelper.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\n/**\n * @title Mimic Helper\n * @dev Collection of helper functions for the Mimic Protocol\n */\ncontract MimicHelper {\n /**\n * @dev Tells the native token balance of an address\n * @param target Address to get native token balance\n */\n function getNativeTokenBalance(address target) external view returns (uint256) {\n return target.balance;\n }\n}\n" + } + } + } +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-146/deployed_addresses.json b/packages/evm/ignition/deployments/chain-146/deployed_addresses.json index a1a41be..e981fe5 100644 --- a/packages/evm/ignition/deployments/chain-146/deployed_addresses.json +++ b/packages/evm/ignition/deployments/chain-146/deployed_addresses.json @@ -2,5 +2,7 @@ "Create3Controller#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", "Create3Controller#Controller": "0x6002825BabC837776A08799404fA55f15DCedA6b", "Create3Settler#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", - "Create3Settler#Settler": "0x609d831C0068844e11eF85a273c7F356212Fd6D1" + "Create3Settler#Settler": "0x609d831C0068844e11eF85a273c7F356212Fd6D1", + "Create3MimicHelper#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", + "Create3MimicHelper#MimicHelper": "0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0" } \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-146/journal.jsonl b/packages/evm/ignition/deployments/chain-146/journal.jsonl index d618ebc..df2d898 100644 --- a/packages/evm/ignition/deployments/chain-146/journal.jsonl +++ b/packages/evm/ignition/deployments/chain-146/journal.jsonl @@ -17,4 +17,13 @@ {"futureId":"Create3Settler#ICreateX.deployCreate3","hash":"0x7d8ea15f5e78fd062bbeb02ae5027e353907ab3fc457fb038f069669ac177b07","networkInteractionId":1,"receipt":{"blockHash":"0x77b4399b6bf9b497485023a3e241423693190710794df6e522e403dddbb152d1","blockNumber":48189933,"logs":[{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":0,"topics":["0x2feea65dd4e9f9cbd86b74b7734210c59a1b2981b5b137bd0ee3e208200c9067","0x0000000000000000000000001a68cee754105b3f806c92f6f59e3175f0b0fc2c","0xd5d101dbdd8374fa4f730d105879acbe6c9855ed7be06a019574ba923a935d7d"]},{"address":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","data":"0x","logIndex":1,"topics":["0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000003a0ce8115b4913f42c4928d6bc3f554e9a81468b"]},{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":2,"topics":["0x4db17dd5e4732fb6da34a148104a592783ca119a1e7bb8829eba6cbadef0b511","0x000000000000000000000000609d831c0068844e11ef85a273c7f356212fd6d1"]}],"status":"SUCCESS"},"type":"TRANSACTION_CONFIRM"} {"futureId":"Create3Settler#ICreateX.deployCreate3","result":{"type":"SUCCESS"},"type":"CALL_EXECUTION_STATE_COMPLETE"} {"artifactId":"Create3Settler#ICreateX","dependencies":["Create3Settler#ICreateX.deployCreate3","Create3Settler#ICreateX"],"emitterAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","eventIndex":0,"eventName":"ContractCreation","futureId":"Create3Settler#ICreateX.ContractCreation.newContract.0","nameOrIndex":"newContract","result":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","strategy":"basic","strategyConfig":{},"txToReadFrom":"0x7d8ea15f5e78fd062bbeb02ae5027e353907ab3fc457fb038f069669ac177b07","type":"READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE"} -{"artifactId":"Create3Settler#Settler","contractAddress":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","contractName":"Settler","dependencies":["Create3Settler#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3Settler#Settler","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} \ No newline at end of file +{"artifactId":"Create3Settler#Settler","contractAddress":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","contractName":"Settler","dependencies":["Create3Settler#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3Settler#Settler","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} +{"artifactId":"Create3MimicHelper#ICreateX","contractAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","contractName":"ICreateX","dependencies":[],"futureId":"Create3MimicHelper#ICreateX","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} +{"args":["0x3a0ce8115b4913f42c4928d6bc3f554e9a81468b000000000000000000000040","0x6080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033"],"artifactId":"Create3MimicHelper#ICreateX","contractAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","dependencies":["Create3MimicHelper#ICreateX"],"from":"0x3a0ce8115b4913f42c4928d6bc3f554e9a81468b","functionName":"deployCreate3","futureId":"Create3MimicHelper#ICreateX.deployCreate3","strategy":"basic","strategyConfig":{},"type":"CALL_EXECUTION_STATE_INITIALIZE","value":{"_kind":"bigint","value":"0"}} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteraction":{"data":"0x9c36a2863a0ce8115b4913f42c4928d6bc3f554e9a81468b000000000000000000000040000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e96080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c00330000000000000000000000000000000000000000000000","id":1,"to":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","type":"ONCHAIN_INTERACTION","value":{"_kind":"bigint","value":"0"}},"type":"NETWORK_INTERACTION_REQUEST"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteractionId":1,"nonce":10,"type":"TRANSACTION_PREPARE_SEND"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteractionId":1,"nonce":10,"transaction":{"fees":{"maxFeePerGas":{"_kind":"bigint","value":"100000000001"},"maxPriorityFeePerGas":{"_kind":"bigint","value":"1"}},"hash":"0x28b3b6e47fda9c048487abd70af94efe42a2782d04c86c27185cd36e300f00a6"},"type":"TRANSACTION_SEND"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","hash":"0x28b3b6e47fda9c048487abd70af94efe42a2782d04c86c27185cd36e300f00a6","networkInteractionId":1,"receipt":{"blockHash":"0x2404a15e74fc6198c2461c55375d703a1faf5deb37d653a0ea19b80b31174b21","blockNumber":61213638,"logs":[{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":0,"topics":["0x2feea65dd4e9f9cbd86b74b7734210c59a1b2981b5b137bd0ee3e208200c9067","0x0000000000000000000000009074e2fea6f668ccf7fb884fac62943acc03ea43","0x721f4d59bffa983c2a99dc5a3b93053d035180c65840e4dc318b06bb0484a80f"]},{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":1,"topics":["0x4db17dd5e4732fb6da34a148104a592783ca119a1e7bb8829eba6cbadef0b511","0x0000000000000000000000004766ef65d66e8d2d92f3089ee42e5705e8817ff0"]}],"status":"SUCCESS"},"type":"TRANSACTION_CONFIRM"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","result":{"type":"SUCCESS"},"type":"CALL_EXECUTION_STATE_COMPLETE"} +{"artifactId":"Create3MimicHelper#ICreateX","dependencies":["Create3MimicHelper#ICreateX.deployCreate3","Create3MimicHelper#ICreateX"],"emitterAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","eventIndex":0,"eventName":"ContractCreation","futureId":"Create3MimicHelper#ICreateX.ContractCreation.newContract.0","nameOrIndex":"newContract","result":"0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0","strategy":"basic","strategyConfig":{},"txToReadFrom":"0x28b3b6e47fda9c048487abd70af94efe42a2782d04c86c27185cd36e300f00a6","type":"READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE"} +{"artifactId":"Create3MimicHelper#MimicHelper","contractAddress":"0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0","contractName":"MimicHelper","dependencies":["Create3MimicHelper#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3MimicHelper#MimicHelper","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-42161/artifacts/Create3MimicHelper#ICreateX.dbg.json b/packages/evm/ignition/deployments/chain-42161/artifacts/Create3MimicHelper#ICreateX.dbg.json new file mode 100644 index 0000000..817dddf --- /dev/null +++ b/packages/evm/ignition/deployments/chain-42161/artifacts/Create3MimicHelper#ICreateX.dbg.json @@ -0,0 +1,4 @@ +{ + "_format": "hh-sol-dbg-1", + "buildInfo": "../build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-42161/artifacts/Create3MimicHelper#ICreateX.json b/packages/evm/ignition/deployments/chain-42161/artifacts/Create3MimicHelper#ICreateX.json new file mode 100644 index 0000000..a4701c6 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-42161/artifacts/Create3MimicHelper#ICreateX.json @@ -0,0 +1,51 @@ +{ + "_format": "hh3-artifact-1", + "contractName": "ICreateX", + "sourceName": "contracts/interfaces/ICreateX.sol", + "abi": [ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "newContract", + "type": "address" + } + ], + "name": "ContractCreation", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "salt", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "initCode", + "type": "bytes" + } + ], + "name": "deployCreate3", + "outputs": [ + { + "internalType": "address", + "name": "newContract", + "type": "address" + } + ], + "stateMutability": "payable", + "type": "function" + } + ], + "bytecode": "0x", + "deployedBytecode": "0x", + "linkReferences": {}, + "deployedLinkReferences": {}, + "immutableReferences": {}, + "inputSourceName": "project/contracts/interfaces/ICreateX.sol", + "buildInfoId": "b650d0a8e9df290d290e91b2999a1f7443c2b528" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-42161/artifacts/Create3MimicHelper#MimicHelper.dbg.json b/packages/evm/ignition/deployments/chain-42161/artifacts/Create3MimicHelper#MimicHelper.dbg.json new file mode 100644 index 0000000..817dddf --- /dev/null +++ b/packages/evm/ignition/deployments/chain-42161/artifacts/Create3MimicHelper#MimicHelper.dbg.json @@ -0,0 +1,4 @@ +{ + "_format": "hh-sol-dbg-1", + "buildInfo": "../build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-42161/artifacts/Create3MimicHelper#MimicHelper.json b/packages/evm/ignition/deployments/chain-42161/artifacts/Create3MimicHelper#MimicHelper.json new file mode 100644 index 0000000..a01b577 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-42161/artifacts/Create3MimicHelper#MimicHelper.json @@ -0,0 +1,33 @@ +{ + "_format": "hh3-artifact-1", + "contractName": "MimicHelper", + "sourceName": "contracts/utils/MimicHelper.sol", + "abi": [ + { + "inputs": [ + { + "internalType": "address", + "name": "target", + "type": "address" + } + ], + "name": "getNativeTokenBalance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + } + ], + "bytecode": "0x6080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033", + "deployedBytecode": "0x6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033", + "linkReferences": {}, + "deployedLinkReferences": {}, + "immutableReferences": {}, + "inputSourceName": "project/contracts/utils/MimicHelper.sol", + "buildInfoId": "b650d0a8e9df290d290e91b2999a1f7443c2b528" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-42161/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json b/packages/evm/ignition/deployments/chain-42161/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json new file mode 100644 index 0000000..657a777 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-42161/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json @@ -0,0 +1,290 @@ +{ + "_format": "hh3-sol-build-info-1", + "id": "b650d0a8e9df290d290e91b2999a1f7443c2b528", + "solcVersion": "0.8.28", + "solcLongVersion": "0.8.28+commit.7893614a", + "userSourceNameMap": { + "contracts/Controller.sol": "project/contracts/Controller.sol", + "contracts/Intents.sol": "project/contracts/Intents.sol", + "contracts/Settler.sol": "project/contracts/Settler.sol", + "contracts/interfaces/IController.sol": "project/contracts/interfaces/IController.sol", + "contracts/interfaces/ICreateX.sol": "project/contracts/interfaces/ICreateX.sol", + "contracts/interfaces/IExecutor.sol": "project/contracts/interfaces/IExecutor.sol", + "contracts/interfaces/IIntentsValidator.sol": "project/contracts/interfaces/IIntentsValidator.sol", + "contracts/interfaces/ISafe.sol": "project/contracts/interfaces/ISafe.sol", + "contracts/interfaces/ISettler.sol": "project/contracts/interfaces/ISettler.sol", + "contracts/interfaces/ISmartAccount.sol": "project/contracts/interfaces/ISmartAccount.sol", + "contracts/interfaces/ISmartAccountContract.sol": "project/contracts/interfaces/ISmartAccountContract.sol", + "contracts/interfaces/ISmartAccountsHandler.sol": "project/contracts/interfaces/ISmartAccountsHandler.sol", + "contracts/safeguards/BaseIntentsValidator.sol": "project/contracts/safeguards/BaseIntentsValidator.sol", + "contracts/safeguards/CallIntentsValidator.sol": "project/contracts/safeguards/CallIntentsValidator.sol", + "contracts/safeguards/IntentsValidator.sol": "project/contracts/safeguards/IntentsValidator.sol", + "contracts/safeguards/Safeguards.sol": "project/contracts/safeguards/Safeguards.sol", + "contracts/safeguards/SwapIntentsValidator.sol": "project/contracts/safeguards/SwapIntentsValidator.sol", + "contracts/safeguards/TransferIntentsValidator.sol": "project/contracts/safeguards/TransferIntentsValidator.sol", + "contracts/smart-accounts/SmartAccount7702.sol": "project/contracts/smart-accounts/SmartAccount7702.sol", + "contracts/smart-accounts/SmartAccountBase.sol": "project/contracts/smart-accounts/SmartAccountBase.sol", + "contracts/smart-accounts/SmartAccountContract.sol": "project/contracts/smart-accounts/SmartAccountContract.sol", + "contracts/smart-accounts/SmartAccountsHandler.sol": "project/contracts/smart-accounts/SmartAccountsHandler.sol", + "contracts/smart-accounts/SmartAccountsHandlerHelpers.sol": "project/contracts/smart-accounts/SmartAccountsHandlerHelpers.sol", + "contracts/test/CallMock.sol": "project/contracts/test/CallMock.sol", + "contracts/test/TokenMock.sol": "project/contracts/test/TokenMock.sol", + "contracts/test/executors/EmptyExecutorMock.sol": "project/contracts/test/executors/EmptyExecutorMock.sol", + "contracts/test/executors/MintExecutorMock.sol": "project/contracts/test/executors/MintExecutorMock.sol", + "contracts/test/executors/ReentrantExecutorMock.sol": "project/contracts/test/executors/ReentrantExecutorMock.sol", + "contracts/test/executors/TransferExecutorMock.sol": "project/contracts/test/executors/TransferExecutorMock.sol", + "contracts/test/smart-accounts/SafeMock.sol": "project/contracts/test/smart-accounts/SafeMock.sol", + "contracts/test/utils/DenominationsMock.sol": "project/contracts/test/utils/DenominationsMock.sol", + "contracts/test/utils/ERC20HelpersMock.sol": "project/contracts/test/utils/ERC20HelpersMock.sol", + "contracts/utils/Denominations.sol": "project/contracts/utils/Denominations.sol", + "contracts/utils/ERC20Helpers.sol": "project/contracts/utils/ERC20Helpers.sol", + "contracts/utils/MimicHelper.sol": "project/contracts/utils/MimicHelper.sol" + }, + "input": { + "language": "Solidity", + "settings": { + "optimizer": { + "enabled": true, + "runs": 1000 + }, + "evmVersion": "cancun", + "outputSelection": { + "*": { + "": [ + "ast" + ], + "*": [ + "abi", + "evm.bytecode", + "evm.deployedBytecode", + "evm.methodIdentifiers", + "metadata" + ] + } + }, + "remappings": [ + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/" + ] + }, + "sources": { + "npm/@openzeppelin/contracts@5.3.0/access/Ownable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)\n\npragma solidity ^0.8.20;\n\nimport {Context} from \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * The initial owner is set to the address provided by the deployer. This can\n * later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n /**\n * @dev The caller account is not authorized to perform an operation.\n */\n error OwnableUnauthorizedAccount(address account);\n\n /**\n * @dev The owner is not a valid owner account. (eg. `address(0)`)\n */\n error OwnableInvalidOwner(address owner);\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the address provided by the deployer as the initial owner.\n */\n constructor(address initialOwner) {\n if (initialOwner == address(0)) {\n revert OwnableInvalidOwner(address(0));\n }\n _transferOwnership(initialOwner);\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n if (owner() != _msgSender()) {\n revert OwnableUnauthorizedAccount(_msgSender());\n }\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby disabling any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n if (newOwner == address(0)) {\n revert OwnableInvalidOwner(address(0));\n }\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/draft-IERC6093.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol)\npragma solidity ^0.8.20;\n\n/**\n * @dev Standard ERC-20 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.\n */\ninterface IERC20Errors {\n /**\n * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param balance Current balance for the interacting account.\n * @param needed Minimum amount required to perform a transfer.\n */\n error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC20InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC20InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.\n * @param spender Address that may be allowed to operate on tokens without being their owner.\n * @param allowance Amount of tokens a `spender` is allowed to operate with.\n * @param needed Minimum amount required to perform a transfer.\n */\n error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC20InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `spender` to be approved. Used in approvals.\n * @param spender Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC20InvalidSpender(address spender);\n}\n\n/**\n * @dev Standard ERC-721 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.\n */\ninterface IERC721Errors {\n /**\n * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.\n * Used in balance queries.\n * @param owner Address of the current owner of a token.\n */\n error ERC721InvalidOwner(address owner);\n\n /**\n * @dev Indicates a `tokenId` whose `owner` is the zero address.\n * @param tokenId Identifier number of a token.\n */\n error ERC721NonexistentToken(uint256 tokenId);\n\n /**\n * @dev Indicates an error related to the ownership over a particular token. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param tokenId Identifier number of a token.\n * @param owner Address of the current owner of a token.\n */\n error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC721InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC721InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n * @param tokenId Identifier number of a token.\n */\n error ERC721InsufficientApproval(address operator, uint256 tokenId);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC721InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC721InvalidOperator(address operator);\n}\n\n/**\n * @dev Standard ERC-1155 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.\n */\ninterface IERC1155Errors {\n /**\n * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param balance Current balance for the interacting account.\n * @param needed Minimum amount required to perform a transfer.\n * @param tokenId Identifier number of a token.\n */\n error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC1155InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC1155InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n * @param owner Address of the current owner of a token.\n */\n error ERC1155MissingApprovalForAll(address operator, address owner);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC1155InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC1155InvalidOperator(address operator);\n\n /**\n * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.\n * Used in batch transfers.\n * @param idsLength Length of the array of token identifiers\n * @param valuesLength Length of the array of token amounts\n */\n error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC1271.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (interfaces/IERC1271.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-1271 standard signature validation method for\n * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].\n */\ninterface IERC1271 {\n /**\n * @dev Should return whether the signature provided is valid for the provided data\n * @param hash Hash of the data to be signed\n * @param signature Signature byte array associated with `hash`\n */\n function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC1363.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"./IERC20.sol\";\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @title IERC1363\n * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].\n *\n * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract\n * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.\n */\ninterface IERC1363 is IERC20, IERC165 {\n /*\n * Note: the ERC-165 identifier for this interface is 0xb0202a11.\n * 0xb0202a11 ===\n * bytes4(keccak256('transferAndCall(address,uint256)')) ^\n * bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^\n * bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^\n * bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^\n * bytes4(keccak256('approveAndCall(address,uint256)')) ^\n * bytes4(keccak256('approveAndCall(address,uint256,bytes)'))\n */\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferAndCall(address to, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @param data Additional data with no specified format, sent in call to `to`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param from The address which you want to send tokens from.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferFromAndCall(address from, address to, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param from The address which you want to send tokens from.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @param data Additional data with no specified format, sent in call to `to`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.\n * @param spender The address which will spend the funds.\n * @param value The amount of tokens to be spent.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function approveAndCall(address spender, uint256 value) external returns (bool);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.\n * @param spender The address which will spend the funds.\n * @param value The amount of tokens to be spent.\n * @param data Additional data with no specified format, sent in call to `spender`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"../utils/introspection/IERC165.sol\";\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../token/ERC20/IERC20.sol\";\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC5267.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)\n\npragma solidity ^0.8.20;\n\ninterface IERC5267 {\n /**\n * @dev MAY be emitted to signal that the domain could have changed.\n */\n event EIP712DomainChanged();\n\n /**\n * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712\n * signature.\n */\n function eip712Domain()\n external\n view\n returns (\n bytes1 fields,\n string memory name,\n string memory version,\n uint256 chainId,\n address verifyingContract,\n bytes32 salt,\n uint256[] memory extensions\n );\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/ERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"./IERC20.sol\";\nimport {IERC20Metadata} from \"./extensions/IERC20Metadata.sol\";\nimport {Context} from \"../../utils/Context.sol\";\nimport {IERC20Errors} from \"../../interfaces/draft-IERC6093.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * The default value of {decimals} is 18. To change this, you should override\n * this function so it returns a different value.\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC-20\n * applications.\n */\nabstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {\n mapping(address account => uint256) private _balances;\n\n mapping(address account => mapping(address spender => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * Both values are immutable: they can only be set once during construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the default value returned by this function, unless\n * it's overridden.\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `value`.\n */\n function transfer(address to, uint256 value) public virtual returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, value);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 value) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, value);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Skips emitting an {Approval} event indicating an allowance update. This is not\n * required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `value`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `value`.\n */\n function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, value);\n _transfer(from, to, value);\n return true;\n }\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead.\n */\n function _transfer(address from, address to, uint256 value) internal {\n if (from == address(0)) {\n revert ERC20InvalidSender(address(0));\n }\n if (to == address(0)) {\n revert ERC20InvalidReceiver(address(0));\n }\n _update(from, to, value);\n }\n\n /**\n * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`\n * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding\n * this function.\n *\n * Emits a {Transfer} event.\n */\n function _update(address from, address to, uint256 value) internal virtual {\n if (from == address(0)) {\n // Overflow check required: The rest of the code assumes that totalSupply never overflows\n _totalSupply += value;\n } else {\n uint256 fromBalance = _balances[from];\n if (fromBalance < value) {\n revert ERC20InsufficientBalance(from, fromBalance, value);\n }\n unchecked {\n // Overflow not possible: value <= fromBalance <= totalSupply.\n _balances[from] = fromBalance - value;\n }\n }\n\n if (to == address(0)) {\n unchecked {\n // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.\n _totalSupply -= value;\n }\n } else {\n unchecked {\n // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.\n _balances[to] += value;\n }\n }\n\n emit Transfer(from, to, value);\n }\n\n /**\n * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).\n * Relies on the `_update` mechanism\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead.\n */\n function _mint(address account, uint256 value) internal {\n if (account == address(0)) {\n revert ERC20InvalidReceiver(address(0));\n }\n _update(address(0), account, value);\n }\n\n /**\n * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.\n * Relies on the `_update` mechanism.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead\n */\n function _burn(address account, uint256 value) internal {\n if (account == address(0)) {\n revert ERC20InvalidSender(address(0));\n }\n _update(account, address(0), value);\n }\n\n /**\n * @dev Sets `value` as the allowance of `spender` over the `owner`'s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n *\n * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.\n */\n function _approve(address owner, address spender, uint256 value) internal {\n _approve(owner, spender, value, true);\n }\n\n /**\n * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.\n *\n * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by\n * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any\n * `Approval` event during `transferFrom` operations.\n *\n * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to\n * true using the following override:\n *\n * ```solidity\n * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {\n * super._approve(owner, spender, value, true);\n * }\n * ```\n *\n * Requirements are the same as {_approve}.\n */\n function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {\n if (owner == address(0)) {\n revert ERC20InvalidApprover(address(0));\n }\n if (spender == address(0)) {\n revert ERC20InvalidSpender(address(0));\n }\n _allowances[owner][spender] = value;\n if (emitEvent) {\n emit Approval(owner, spender, value);\n }\n }\n\n /**\n * @dev Updates `owner`'s allowance for `spender` based on spent `value`.\n *\n * Does not update the allowance value in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Does not emit an {Approval} event.\n */\n function _spendAllowance(address owner, address spender, uint256 value) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance < type(uint256).max) {\n if (currentAllowance < value) {\n revert ERC20InsufficientAllowance(spender, currentAllowance, value);\n }\n unchecked {\n _approve(owner, spender, currentAllowance - value, false);\n }\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/extensions/IERC20Metadata.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC-20 standard.\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-20 standard as defined in the ERC.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the value of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the value of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 value) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the\n * allowance mechanism. `value` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(address from, address to, uint256 value) external returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/utils/SafeERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../IERC20.sol\";\nimport {IERC1363} from \"../../../interfaces/IERC1363.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC-20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n /**\n * @dev An operation with an ERC-20 token failed.\n */\n error SafeERC20FailedOperation(address token);\n\n /**\n * @dev Indicates a failed `decreaseAllowance` request.\n */\n error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);\n\n /**\n * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,\n * non-reverting calls are assumed to be successful.\n */\n function safeTransfer(IERC20 token, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));\n }\n\n /**\n * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the\n * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.\n */\n function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));\n }\n\n /**\n * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.\n */\n function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {\n return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));\n }\n\n /**\n * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.\n */\n function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {\n return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));\n }\n\n /**\n * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n * non-reverting calls are assumed to be successful.\n *\n * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the \"client\"\n * smart contract uses ERC-7674 to set temporary allowances, then the \"client\" smart contract should avoid using\n * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract\n * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.\n */\n function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n uint256 oldAllowance = token.allowance(address(this), spender);\n forceApprove(token, spender, oldAllowance + value);\n }\n\n /**\n * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no\n * value, non-reverting calls are assumed to be successful.\n *\n * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the \"client\"\n * smart contract uses ERC-7674 to set temporary allowances, then the \"client\" smart contract should avoid using\n * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract\n * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.\n */\n function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {\n unchecked {\n uint256 currentAllowance = token.allowance(address(this), spender);\n if (currentAllowance < requestedDecrease) {\n revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);\n }\n forceApprove(token, spender, currentAllowance - requestedDecrease);\n }\n }\n\n /**\n * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,\n * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval\n * to be set to zero before setting it to a non-zero value, such as USDT.\n *\n * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function\n * only sets the \"standard\" allowance. Any temporary allowance will remain active, in addition to the value being\n * set here.\n */\n function forceApprove(IERC20 token, address spender, uint256 value) internal {\n bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));\n\n if (!_callOptionalReturnBool(token, approvalCall)) {\n _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));\n _callOptionalReturn(token, approvalCall);\n }\n }\n\n /**\n * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no\n * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * Reverts if the returned value is other than `true`.\n */\n function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {\n if (to.code.length == 0) {\n safeTransfer(token, to, value);\n } else if (!token.transferAndCall(to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target\n * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * Reverts if the returned value is other than `true`.\n */\n function transferFromAndCallRelaxed(\n IERC1363 token,\n address from,\n address to,\n uint256 value,\n bytes memory data\n ) internal {\n if (to.code.length == 0) {\n safeTransferFrom(token, from, to, value);\n } else if (!token.transferFromAndCall(from, to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no\n * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.\n * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}\n * once without retrying, and relies on the returned value to be true.\n *\n * Reverts if the returned value is other than `true`.\n */\n function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {\n if (to.code.length == 0) {\n forceApprove(token, to, value);\n } else if (!token.approveAndCall(to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n *\n * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.\n */\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)\n // bubble errors\n if iszero(success) {\n let ptr := mload(0x40)\n returndatacopy(ptr, 0, returndatasize())\n revert(ptr, returndatasize())\n }\n returnSize := returndatasize()\n returnValue := mload(0)\n }\n\n if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n *\n * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.\n */\n function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {\n bool success;\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)\n returnSize := returndatasize()\n returnValue := mload(0)\n }\n return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Address.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.2.0) (utils/Address.sol)\n\npragma solidity ^0.8.20;\n\nimport {Errors} from \"./Errors.sol\";\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev There's no code at `target` (it is not a contract).\n */\n error AddressEmptyCode(address target);\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n if (address(this).balance < amount) {\n revert Errors.InsufficientBalance(address(this).balance, amount);\n }\n\n (bool success, bytes memory returndata) = recipient.call{value: amount}(\"\");\n if (!success) {\n _revert(returndata);\n }\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason or custom error, it is bubbled\n * up by this function (like regular Solidity function calls). However, if\n * the call reverted with no returned reason, this function reverts with a\n * {Errors.FailedCall} error.\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n */\n function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n if (address(this).balance < value) {\n revert Errors.InsufficientBalance(address(this).balance, value);\n }\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target\n * was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case\n * of an unsuccessful call.\n */\n function verifyCallResultFromTarget(\n address target,\n bool success,\n bytes memory returndata\n ) internal view returns (bytes memory) {\n if (!success) {\n _revert(returndata);\n } else {\n // only check if target is a contract if the call was successful and the return data is empty\n // otherwise we already know that it was a contract\n if (returndata.length == 0 && target.code.length == 0) {\n revert AddressEmptyCode(target);\n }\n return returndata;\n }\n }\n\n /**\n * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the\n * revert reason or with a default {Errors.FailedCall} error.\n */\n function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {\n if (!success) {\n _revert(returndata);\n } else {\n return returndata;\n }\n }\n\n /**\n * @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.\n */\n function _revert(bytes memory returndata) private pure {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n assembly (\"memory-safe\") {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert Errors.FailedCall();\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Context.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n\n function _contextSuffixLength() internal view virtual returns (uint256) {\n return 0;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/ECDSA.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/ECDSA.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.\n *\n * These functions can be used to verify that a message was signed by the holder\n * of the private keys of a given address.\n */\nlibrary ECDSA {\n enum RecoverError {\n NoError,\n InvalidSignature,\n InvalidSignatureLength,\n InvalidSignatureS\n }\n\n /**\n * @dev The signature derives the `address(0)`.\n */\n error ECDSAInvalidSignature();\n\n /**\n * @dev The signature has an invalid length.\n */\n error ECDSAInvalidSignatureLength(uint256 length);\n\n /**\n * @dev The signature has an S value that is in the upper half order.\n */\n error ECDSAInvalidSignatureS(bytes32 s);\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not\n * return address(0) without also returning an error description. Errors are documented using an enum (error type)\n * and a bytes32 providing additional information about the error.\n *\n * If no error is returned, then the address can be used for verification purposes.\n *\n * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.\n *\n * Documentation for signature generation:\n * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]\n * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]\n */\n function tryRecover(\n bytes32 hash,\n bytes memory signature\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n if (signature.length == 65) {\n bytes32 r;\n bytes32 s;\n uint8 v;\n // ecrecover takes the signature parameters, and the only way to get them\n // currently is to use assembly.\n assembly (\"memory-safe\") {\n r := mload(add(signature, 0x20))\n s := mload(add(signature, 0x40))\n v := byte(0, mload(add(signature, 0x60)))\n }\n return tryRecover(hash, v, r, s);\n } else {\n return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));\n }\n }\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with\n * `signature`. This address can then be used for verification purposes.\n *\n * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.\n */\n function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.\n *\n * See https://eips.ethereum.org/EIPS/eip-2098[ERC-2098 short signatures]\n */\n function tryRecover(\n bytes32 hash,\n bytes32 r,\n bytes32 vs\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n unchecked {\n bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n // We do not check for an overflow here since the shift operation results in 0 or 1.\n uint8 v = uint8((uint256(vs) >> 255) + 27);\n return tryRecover(hash, v, r, s);\n }\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\n */\n function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function tryRecover(\n bytes32 hash,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\n // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\n // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\n // signatures from current libraries generate a unique signature with an s-value in the lower half order.\n //\n // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\n // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\n // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\n // these malleable signatures as well.\n if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\n return (address(0), RecoverError.InvalidSignatureS, s);\n }\n\n // If the signature is valid (and not malleable), return the signer address\n address signer = ecrecover(hash, v, r, s);\n if (signer == address(0)) {\n return (address(0), RecoverError.InvalidSignature, bytes32(0));\n }\n\n return (signer, RecoverError.NoError, bytes32(0));\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.\n */\n function _throwError(RecoverError error, bytes32 errorArg) private pure {\n if (error == RecoverError.NoError) {\n return; // no error: do nothing\n } else if (error == RecoverError.InvalidSignature) {\n revert ECDSAInvalidSignature();\n } else if (error == RecoverError.InvalidSignatureLength) {\n revert ECDSAInvalidSignatureLength(uint256(errorArg));\n } else if (error == RecoverError.InvalidSignatureS) {\n revert ECDSAInvalidSignatureS(errorArg);\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/EIP712.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/EIP712.sol)\n\npragma solidity ^0.8.20;\n\nimport {MessageHashUtils} from \"./MessageHashUtils.sol\";\nimport {ShortStrings, ShortString} from \"../ShortStrings.sol\";\nimport {IERC5267} from \"../../interfaces/IERC5267.sol\";\n\n/**\n * @dev https://eips.ethereum.org/EIPS/eip-712[EIP-712] is a standard for hashing and signing of typed structured data.\n *\n * The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose\n * encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract\n * does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to\n * produce the hash of their typed data using a combination of `abi.encode` and `keccak256`.\n *\n * This contract implements the EIP-712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding\n * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA\n * ({_hashTypedDataV4}).\n *\n * The implementation of the domain separator was designed to be as efficient as possible while still properly updating\n * the chain id to protect against replay attacks on an eventual fork of the chain.\n *\n * NOTE: This contract implements the version of the encoding known as \"v4\", as implemented by the JSON RPC method\n * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].\n *\n * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain\n * separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the\n * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.\n *\n * @custom:oz-upgrades-unsafe-allow state-variable-immutable\n */\nabstract contract EIP712 is IERC5267 {\n using ShortStrings for *;\n\n bytes32 private constant TYPE_HASH =\n keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\");\n\n // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to\n // invalidate the cached domain separator if the chain id changes.\n bytes32 private immutable _cachedDomainSeparator;\n uint256 private immutable _cachedChainId;\n address private immutable _cachedThis;\n\n bytes32 private immutable _hashedName;\n bytes32 private immutable _hashedVersion;\n\n ShortString private immutable _name;\n ShortString private immutable _version;\n // slither-disable-next-line constable-states\n string private _nameFallback;\n // slither-disable-next-line constable-states\n string private _versionFallback;\n\n /**\n * @dev Initializes the domain separator and parameter caches.\n *\n * The meaning of `name` and `version` is specified in\n * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP-712]:\n *\n * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.\n * - `version`: the current major version of the signing domain.\n *\n * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart\n * contract upgrade].\n */\n constructor(string memory name, string memory version) {\n _name = name.toShortStringWithFallback(_nameFallback);\n _version = version.toShortStringWithFallback(_versionFallback);\n _hashedName = keccak256(bytes(name));\n _hashedVersion = keccak256(bytes(version));\n\n _cachedChainId = block.chainid;\n _cachedDomainSeparator = _buildDomainSeparator();\n _cachedThis = address(this);\n }\n\n /**\n * @dev Returns the domain separator for the current chain.\n */\n function _domainSeparatorV4() internal view returns (bytes32) {\n if (address(this) == _cachedThis && block.chainid == _cachedChainId) {\n return _cachedDomainSeparator;\n } else {\n return _buildDomainSeparator();\n }\n }\n\n function _buildDomainSeparator() private view returns (bytes32) {\n return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));\n }\n\n /**\n * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this\n * function returns the hash of the fully encoded EIP712 message for this domain.\n *\n * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:\n *\n * ```solidity\n * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(\n * keccak256(\"Mail(address to,string contents)\"),\n * mailTo,\n * keccak256(bytes(mailContents))\n * )));\n * address signer = ECDSA.recover(digest, signature);\n * ```\n */\n function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {\n return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);\n }\n\n /**\n * @inheritdoc IERC5267\n */\n function eip712Domain()\n public\n view\n virtual\n returns (\n bytes1 fields,\n string memory name,\n string memory version,\n uint256 chainId,\n address verifyingContract,\n bytes32 salt,\n uint256[] memory extensions\n )\n {\n return (\n hex\"0f\", // 01111\n _EIP712Name(),\n _EIP712Version(),\n block.chainid,\n address(this),\n bytes32(0),\n new uint256[](0)\n );\n }\n\n /**\n * @dev The name parameter for the EIP712 domain.\n *\n * NOTE: By default this function reads _name which is an immutable value.\n * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).\n */\n // solhint-disable-next-line func-name-mixedcase\n function _EIP712Name() internal view returns (string memory) {\n return _name.toStringWithFallback(_nameFallback);\n }\n\n /**\n * @dev The version parameter for the EIP712 domain.\n *\n * NOTE: By default this function reads _version which is an immutable value.\n * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).\n */\n // solhint-disable-next-line func-name-mixedcase\n function _EIP712Version() internal view returns (string memory) {\n return _version.toStringWithFallback(_versionFallback);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/MessageHashUtils.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/MessageHashUtils.sol)\n\npragma solidity ^0.8.20;\n\nimport {Strings} from \"../Strings.sol\";\n\n/**\n * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.\n *\n * The library provides methods for generating a hash of a message that conforms to the\n * https://eips.ethereum.org/EIPS/eip-191[ERC-191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]\n * specifications.\n */\nlibrary MessageHashUtils {\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x45` (`personal_sign` messages).\n *\n * The digest is calculated by prefixing a bytes32 `messageHash` with\n * `\"\\x19Ethereum Signed Message:\\n32\"` and hashing the result. It corresponds with the\n * hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.\n *\n * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with\n * keccak256, although any bytes32 value can be safely used because the final digest will\n * be re-hashed.\n *\n * See {ECDSA-recover}.\n */\n function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n mstore(0x00, \"\\x19Ethereum Signed Message:\\n32\") // 32 is the bytes-length of messageHash\n mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix\n digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)\n }\n }\n\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x45` (`personal_sign` messages).\n *\n * The digest is calculated by prefixing an arbitrary `message` with\n * `\"\\x19Ethereum Signed Message:\\n\" + len(message)` and hashing the result. It corresponds with the\n * hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.\n *\n * See {ECDSA-recover}.\n */\n function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {\n return\n keccak256(bytes.concat(\"\\x19Ethereum Signed Message:\\n\", bytes(Strings.toString(message.length)), message));\n }\n\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x00` (data with intended validator).\n *\n * The digest is calculated by prefixing an arbitrary `data` with `\"\\x19\\x00\"` and the intended\n * `validator` address. Then hashing the result.\n *\n * See {ECDSA-recover}.\n */\n function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(hex\"19_00\", validator, data));\n }\n\n /**\n * @dev Variant of {toDataWithIntendedValidatorHash-address-bytes} optimized for cases where `data` is a bytes32.\n */\n function toDataWithIntendedValidatorHash(\n address validator,\n bytes32 messageHash\n ) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n mstore(0x00, hex\"19_00\")\n mstore(0x02, shl(96, validator))\n mstore(0x16, messageHash)\n digest := keccak256(0x00, 0x36)\n }\n }\n\n /**\n * @dev Returns the keccak256 digest of an EIP-712 typed data (ERC-191 version `0x01`).\n *\n * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with\n * `\\x19\\x01` and hashing the result. It corresponds to the hash signed by the\n * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.\n *\n * See {ECDSA-recover}.\n */\n function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n let ptr := mload(0x40)\n mstore(ptr, hex\"19_01\")\n mstore(add(ptr, 0x02), domainSeparator)\n mstore(add(ptr, 0x22), structHash)\n digest := keccak256(ptr, 0x42)\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Errors.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Collection of common custom errors used in multiple contracts\n *\n * IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.\n * It is recommended to avoid relying on the error API for critical functionality.\n *\n * _Available since v5.1._\n */\nlibrary Errors {\n /**\n * @dev The ETH balance of the account is not enough to perform the operation.\n */\n error InsufficientBalance(uint256 balance, uint256 needed);\n\n /**\n * @dev A call to an address target failed. The target may have reverted.\n */\n error FailedCall();\n\n /**\n * @dev The deployment failed.\n */\n error FailedDeployment();\n\n /**\n * @dev A necessary precompile is missing.\n */\n error MissingPrecompile(address);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/ERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/ERC165Checker.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165Checker.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @dev Library used to query support of an interface declared via {IERC165}.\n *\n * Note that these functions return the actual result of the query: they do not\n * `revert` if an interface is not supported. It is up to the caller to decide\n * what to do in these cases.\n */\nlibrary ERC165Checker {\n // As per the ERC-165 spec, no interface should ever match 0xffffffff\n bytes4 private constant INTERFACE_ID_INVALID = 0xffffffff;\n\n /**\n * @dev Returns true if `account` supports the {IERC165} interface.\n */\n function supportsERC165(address account) internal view returns (bool) {\n // Any contract that implements ERC-165 must explicitly indicate support of\n // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid\n return\n supportsERC165InterfaceUnchecked(account, type(IERC165).interfaceId) &&\n !supportsERC165InterfaceUnchecked(account, INTERFACE_ID_INVALID);\n }\n\n /**\n * @dev Returns true if `account` supports the interface defined by\n * `interfaceId`. Support for {IERC165} itself is queried automatically.\n *\n * See {IERC165-supportsInterface}.\n */\n function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {\n // query support of both ERC-165 as per the spec and support of _interfaceId\n return supportsERC165(account) && supportsERC165InterfaceUnchecked(account, interfaceId);\n }\n\n /**\n * @dev Returns a boolean array where each value corresponds to the\n * interfaces passed in and whether they're supported or not. This allows\n * you to batch check interfaces for a contract where your expectation\n * is that some interfaces may not be supported.\n *\n * See {IERC165-supportsInterface}.\n */\n function getSupportedInterfaces(\n address account,\n bytes4[] memory interfaceIds\n ) internal view returns (bool[] memory) {\n // an array of booleans corresponding to interfaceIds and whether they're supported or not\n bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length);\n\n // query support of ERC-165 itself\n if (supportsERC165(account)) {\n // query support of each interface in interfaceIds\n for (uint256 i = 0; i < interfaceIds.length; i++) {\n interfaceIdsSupported[i] = supportsERC165InterfaceUnchecked(account, interfaceIds[i]);\n }\n }\n\n return interfaceIdsSupported;\n }\n\n /**\n * @dev Returns true if `account` supports all the interfaces defined in\n * `interfaceIds`. Support for {IERC165} itself is queried automatically.\n *\n * Batch-querying can lead to gas savings by skipping repeated checks for\n * {IERC165} support.\n *\n * See {IERC165-supportsInterface}.\n */\n function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {\n // query support of ERC-165 itself\n if (!supportsERC165(account)) {\n return false;\n }\n\n // query support of each interface in interfaceIds\n for (uint256 i = 0; i < interfaceIds.length; i++) {\n if (!supportsERC165InterfaceUnchecked(account, interfaceIds[i])) {\n return false;\n }\n }\n\n // all interfaces supported\n return true;\n }\n\n /**\n * @notice Query if a contract implements an interface, does not check ERC-165 support\n * @param account The address of the contract to query for support of an interface\n * @param interfaceId The interface identifier, as specified in ERC-165\n * @return true if the contract at account indicates support of the interface with\n * identifier interfaceId, false otherwise\n * @dev Assumes that account contains a contract that supports ERC-165, otherwise\n * the behavior of this method is undefined. This precondition can be checked\n * with {supportsERC165}.\n *\n * Some precompiled contracts will falsely indicate support for a given interface, so caution\n * should be exercised when using this function.\n *\n * Interface identification is specified in ERC-165.\n */\n function supportsERC165InterfaceUnchecked(address account, bytes4 interfaceId) internal view returns (bool) {\n // prepare call\n bytes memory encodedParams = abi.encodeCall(IERC165.supportsInterface, (interfaceId));\n\n // perform static call\n bool success;\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n success := staticcall(30000, account, add(encodedParams, 0x20), mload(encodedParams), 0x00, 0x20)\n returnSize := returndatasize()\n returnValue := mload(0x00)\n }\n\n return success && returnSize >= 0x20 && returnValue > 0;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/IERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[ERC].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/Math.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.20;\n\nimport {Panic} from \"../Panic.sol\";\nimport {SafeCast} from \"./SafeCast.sol\";\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n enum Rounding {\n Floor, // Toward negative infinity\n Ceil, // Toward positive infinity\n Trunc, // Toward zero\n Expand // Away from zero\n }\n\n /**\n * @dev Return the 512-bit addition of two uint256.\n *\n * The result is stored in two 256 variables such that sum = high * 2²⁵⁶ + low.\n */\n function add512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {\n assembly (\"memory-safe\") {\n low := add(a, b)\n high := lt(low, a)\n }\n }\n\n /**\n * @dev Return the 512-bit multiplication of two uint256.\n *\n * The result is stored in two 256 variables such that product = high * 2²⁵⁶ + low.\n */\n function mul512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {\n // 512-bit multiply [high low] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use\n // the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n // variables such that product = high * 2²⁵⁶ + low.\n assembly (\"memory-safe\") {\n let mm := mulmod(a, b, not(0))\n low := mul(a, b)\n high := sub(sub(mm, low), lt(mm, low))\n }\n }\n\n /**\n * @dev Returns the addition of two unsigned integers, with a success flag (no overflow).\n */\n function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a + b;\n success = c >= a;\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, with a success flag (no overflow).\n */\n function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a - b;\n success = c <= a;\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, with a success flag (no overflow).\n */\n function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a * b;\n assembly (\"memory-safe\") {\n // Only true when the multiplication doesn't overflow\n // (c / a == b) || (a == 0)\n success := or(eq(div(c, a), b), iszero(a))\n }\n // equivalent to: success ? c : 0\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the division of two unsigned integers, with a success flag (no division by zero).\n */\n function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n success = b > 0;\n assembly (\"memory-safe\") {\n // The `DIV` opcode returns zero when the denominator is 0.\n result := div(a, b)\n }\n }\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).\n */\n function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n success = b > 0;\n assembly (\"memory-safe\") {\n // The `MOD` opcode returns zero when the denominator is 0.\n result := mod(a, b)\n }\n }\n }\n\n /**\n * @dev Unsigned saturating addition, bounds to `2²⁵⁶ - 1` instead of overflowing.\n */\n function saturatingAdd(uint256 a, uint256 b) internal pure returns (uint256) {\n (bool success, uint256 result) = tryAdd(a, b);\n return ternary(success, result, type(uint256).max);\n }\n\n /**\n * @dev Unsigned saturating subtraction, bounds to zero instead of overflowing.\n */\n function saturatingSub(uint256 a, uint256 b) internal pure returns (uint256) {\n (, uint256 result) = trySub(a, b);\n return result;\n }\n\n /**\n * @dev Unsigned saturating multiplication, bounds to `2²⁵⁶ - 1` instead of overflowing.\n */\n function saturatingMul(uint256 a, uint256 b) internal pure returns (uint256) {\n (bool success, uint256 result) = tryMul(a, b);\n return ternary(success, result, type(uint256).max);\n }\n\n /**\n * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.\n *\n * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.\n * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute\n * one branch when needed, making this function more expensive.\n */\n function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {\n unchecked {\n // branchless ternary works because:\n // b ^ (a ^ b) == a\n // b ^ 0 == b\n return b ^ ((a ^ b) * SafeCast.toUint(condition));\n }\n }\n\n /**\n * @dev Returns the largest of two numbers.\n */\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\n return ternary(a > b, a, b);\n }\n\n /**\n * @dev Returns the smallest of two numbers.\n */\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\n return ternary(a < b, a, b);\n }\n\n /**\n * @dev Returns the average of two numbers. The result is rounded towards\n * zero.\n */\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b) / 2 can overflow.\n return (a & b) + (a ^ b) / 2;\n }\n\n /**\n * @dev Returns the ceiling of the division of two numbers.\n *\n * This differs from standard division with `/` in that it rounds towards infinity instead\n * of rounding towards zero.\n */\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n if (b == 0) {\n // Guarantee the same behavior as in a regular Solidity division.\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n\n // The following calculation ensures accurate ceiling division without overflow.\n // Since a is non-zero, (a - 1) / b will not overflow.\n // The largest possible result occurs when (a - 1) / b is type(uint256).max,\n // but the largest value we can obtain is type(uint256).max - 1, which happens\n // when a = type(uint256).max and b = 1.\n unchecked {\n return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);\n }\n }\n\n /**\n * @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or\n * denominator == 0.\n *\n * Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by\n * Uniswap Labs also under MIT license.\n */\n function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {\n unchecked {\n (uint256 high, uint256 low) = mul512(x, y);\n\n // Handle non-overflow cases, 256 by 256 division.\n if (high == 0) {\n // Solidity will revert if denominator == 0, unlike the div opcode on its own.\n // The surrounding unchecked block does not change this fact.\n // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.\n return low / denominator;\n }\n\n // Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.\n if (denominator <= high) {\n Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));\n }\n\n ///////////////////////////////////////////////\n // 512 by 256 division.\n ///////////////////////////////////////////////\n\n // Make division exact by subtracting the remainder from [high low].\n uint256 remainder;\n assembly (\"memory-safe\") {\n // Compute remainder using mulmod.\n remainder := mulmod(x, y, denominator)\n\n // Subtract 256 bit number from 512 bit number.\n high := sub(high, gt(remainder, low))\n low := sub(low, remainder)\n }\n\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator.\n // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.\n\n uint256 twos = denominator & (0 - denominator);\n assembly (\"memory-safe\") {\n // Divide denominator by twos.\n denominator := div(denominator, twos)\n\n // Divide [high low] by twos.\n low := div(low, twos)\n\n // Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.\n twos := add(div(sub(0, twos), twos), 1)\n }\n\n // Shift in bits from high into low.\n low |= high * twos;\n\n // Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such\n // that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for\n // four bits. That is, denominator * inv ≡ 1 mod 2⁴.\n uint256 inverse = (3 * denominator) ^ 2;\n\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also\n // works in modular arithmetic, doubling the correct bits in each step.\n inverse *= 2 - denominator * inverse; // inverse mod 2⁸\n inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶\n inverse *= 2 - denominator * inverse; // inverse mod 2³²\n inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴\n inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸\n inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶\n\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n // This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is\n // less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and high\n // is no longer required.\n result = low * inverse;\n return result;\n }\n }\n\n /**\n * @dev Calculates x * y / denominator with full precision, following the selected rounding direction.\n */\n function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {\n return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);\n }\n\n /**\n * @dev Calculates floor(x * y >> n) with full precision. Throws if result overflows a uint256.\n */\n function mulShr(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 result) {\n unchecked {\n (uint256 high, uint256 low) = mul512(x, y);\n if (high >= 1 << n) {\n Panic.panic(Panic.UNDER_OVERFLOW);\n }\n return (high << (256 - n)) | (low >> n);\n }\n }\n\n /**\n * @dev Calculates x * y >> n with full precision, following the selected rounding direction.\n */\n function mulShr(uint256 x, uint256 y, uint8 n, Rounding rounding) internal pure returns (uint256) {\n return mulShr(x, y, n) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, 1 << n) > 0);\n }\n\n /**\n * @dev Calculate the modular multiplicative inverse of a number in Z/nZ.\n *\n * If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.\n * If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.\n *\n * If the input value is not inversible, 0 is returned.\n *\n * NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the\n * inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.\n */\n function invMod(uint256 a, uint256 n) internal pure returns (uint256) {\n unchecked {\n if (n == 0) return 0;\n\n // The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)\n // Used to compute integers x and y such that: ax + ny = gcd(a, n).\n // When the gcd is 1, then the inverse of a modulo n exists and it's x.\n // ax + ny = 1\n // ax = 1 + (-y)n\n // ax ≡ 1 (mod n) # x is the inverse of a modulo n\n\n // If the remainder is 0 the gcd is n right away.\n uint256 remainder = a % n;\n uint256 gcd = n;\n\n // Therefore the initial coefficients are:\n // ax + ny = gcd(a, n) = n\n // 0a + 1n = n\n int256 x = 0;\n int256 y = 1;\n\n while (remainder != 0) {\n uint256 quotient = gcd / remainder;\n\n (gcd, remainder) = (\n // The old remainder is the next gcd to try.\n remainder,\n // Compute the next remainder.\n // Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd\n // where gcd is at most n (capped to type(uint256).max)\n gcd - remainder * quotient\n );\n\n (x, y) = (\n // Increment the coefficient of a.\n y,\n // Decrement the coefficient of n.\n // Can overflow, but the result is casted to uint256 so that the\n // next value of y is \"wrapped around\" to a value between 0 and n - 1.\n x - y * int256(quotient)\n );\n }\n\n if (gcd != 1) return 0; // No inverse exists.\n return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.\n }\n }\n\n /**\n * @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.\n *\n * From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is\n * prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that\n * `a**(p-2)` is the modular multiplicative inverse of a in Fp.\n *\n * NOTE: this function does NOT check that `p` is a prime greater than `2`.\n */\n function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {\n unchecked {\n return Math.modExp(a, p - 2, p);\n }\n }\n\n /**\n * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)\n *\n * Requirements:\n * - modulus can't be zero\n * - underlying staticcall to precompile must succeed\n *\n * IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make\n * sure the chain you're using it on supports the precompiled contract for modular exponentiation\n * at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,\n * the underlying function will succeed given the lack of a revert, but the result may be incorrectly\n * interpreted as 0.\n */\n function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {\n (bool success, uint256 result) = tryModExp(b, e, m);\n if (!success) {\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n return result;\n }\n\n /**\n * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).\n * It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying\n * to operate modulo 0 or if the underlying precompile reverted.\n *\n * IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain\n * you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in\n * https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack\n * of a revert, but the result may be incorrectly interpreted as 0.\n */\n function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {\n if (m == 0) return (false, 0);\n assembly (\"memory-safe\") {\n let ptr := mload(0x40)\n // | Offset | Content | Content (Hex) |\n // |-----------|------------|--------------------------------------------------------------------|\n // | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x60:0x7f | value of b | 0x<.............................................................b> |\n // | 0x80:0x9f | value of e | 0x<.............................................................e> |\n // | 0xa0:0xbf | value of m | 0x<.............................................................m> |\n mstore(ptr, 0x20)\n mstore(add(ptr, 0x20), 0x20)\n mstore(add(ptr, 0x40), 0x20)\n mstore(add(ptr, 0x60), b)\n mstore(add(ptr, 0x80), e)\n mstore(add(ptr, 0xa0), m)\n\n // Given the result < m, it's guaranteed to fit in 32 bytes,\n // so we can use the memory scratch space located at offset 0.\n success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)\n result := mload(0x00)\n }\n }\n\n /**\n * @dev Variant of {modExp} that supports inputs of arbitrary length.\n */\n function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {\n (bool success, bytes memory result) = tryModExp(b, e, m);\n if (!success) {\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n return result;\n }\n\n /**\n * @dev Variant of {tryModExp} that supports inputs of arbitrary length.\n */\n function tryModExp(\n bytes memory b,\n bytes memory e,\n bytes memory m\n ) internal view returns (bool success, bytes memory result) {\n if (_zeroBytes(m)) return (false, new bytes(0));\n\n uint256 mLen = m.length;\n\n // Encode call args in result and move the free memory pointer\n result = abi.encodePacked(b.length, e.length, mLen, b, e, m);\n\n assembly (\"memory-safe\") {\n let dataPtr := add(result, 0x20)\n // Write result on top of args to avoid allocating extra memory.\n success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)\n // Overwrite the length.\n // result.length > returndatasize() is guaranteed because returndatasize() == m.length\n mstore(result, mLen)\n // Set the memory pointer after the returned data.\n mstore(0x40, add(dataPtr, mLen))\n }\n }\n\n /**\n * @dev Returns whether the provided byte array is zero.\n */\n function _zeroBytes(bytes memory byteArray) private pure returns (bool) {\n for (uint256 i = 0; i < byteArray.length; ++i) {\n if (byteArray[i] != 0) {\n return false;\n }\n }\n return true;\n }\n\n /**\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded\n * towards zero.\n *\n * This method is based on Newton's method for computing square roots; the algorithm is restricted to only\n * using integer operations.\n */\n function sqrt(uint256 a) internal pure returns (uint256) {\n unchecked {\n // Take care of easy edge cases when a == 0 or a == 1\n if (a <= 1) {\n return a;\n }\n\n // In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a\n // sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between\n // the current value as `ε_n = | x_n - sqrt(a) |`.\n //\n // For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root\n // of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is\n // bigger than any uint256.\n //\n // By noticing that\n // `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`\n // we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar\n // to the msb function.\n uint256 aa = a;\n uint256 xn = 1;\n\n if (aa >= (1 << 128)) {\n aa >>= 128;\n xn <<= 64;\n }\n if (aa >= (1 << 64)) {\n aa >>= 64;\n xn <<= 32;\n }\n if (aa >= (1 << 32)) {\n aa >>= 32;\n xn <<= 16;\n }\n if (aa >= (1 << 16)) {\n aa >>= 16;\n xn <<= 8;\n }\n if (aa >= (1 << 8)) {\n aa >>= 8;\n xn <<= 4;\n }\n if (aa >= (1 << 4)) {\n aa >>= 4;\n xn <<= 2;\n }\n if (aa >= (1 << 2)) {\n xn <<= 1;\n }\n\n // We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).\n //\n // We can refine our estimation by noticing that the middle of that interval minimizes the error.\n // If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).\n // This is going to be our x_0 (and ε_0)\n xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)\n\n // From here, Newton's method give us:\n // x_{n+1} = (x_n + a / x_n) / 2\n //\n // One should note that:\n // x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a\n // = ((x_n² + a) / (2 * x_n))² - a\n // = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a\n // = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)\n // = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)\n // = (x_n² - a)² / (2 * x_n)²\n // = ((x_n² - a) / (2 * x_n))²\n // ≥ 0\n // Which proves that for all n ≥ 1, sqrt(a) ≤ x_n\n //\n // This gives us the proof of quadratic convergence of the sequence:\n // ε_{n+1} = | x_{n+1} - sqrt(a) |\n // = | (x_n + a / x_n) / 2 - sqrt(a) |\n // = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |\n // = | (x_n - sqrt(a))² / (2 * x_n) |\n // = | ε_n² / (2 * x_n) |\n // = ε_n² / | (2 * x_n) |\n //\n // For the first iteration, we have a special case where x_0 is known:\n // ε_1 = ε_0² / | (2 * x_0) |\n // ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))\n // ≤ 2**(2*e-4) / (3 * 2**(e-1))\n // ≤ 2**(e-3) / 3\n // ≤ 2**(e-3-log2(3))\n // ≤ 2**(e-4.5)\n //\n // For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:\n // ε_{n+1} = ε_n² / | (2 * x_n) |\n // ≤ (2**(e-k))² / (2 * 2**(e-1))\n // ≤ 2**(2*e-2*k) / 2**e\n // ≤ 2**(e-2*k)\n xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above\n xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5\n xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9\n xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18\n xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36\n xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72\n\n // Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision\n // ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either\n // sqrt(a) or sqrt(a) + 1.\n return xn - SafeCast.toUint(xn > a / xn);\n }\n }\n\n /**\n * @dev Calculates sqrt(a), following the selected rounding direction.\n */\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = sqrt(a);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);\n }\n }\n\n /**\n * @dev Return the log in base 2 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n */\n function log2(uint256 x) internal pure returns (uint256 r) {\n // If value has upper 128 bits set, log2 result is at least 128\n r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;\n // If upper 64 bits of 128-bit half set, add 64 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;\n // If upper 32 bits of 64-bit half set, add 32 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;\n // If upper 16 bits of 32-bit half set, add 16 to result\n r |= SafeCast.toUint((x >> r) > 0xffff) << 4;\n // If upper 8 bits of 16-bit half set, add 8 to result\n r |= SafeCast.toUint((x >> r) > 0xff) << 3;\n // If upper 4 bits of 8-bit half set, add 4 to result\n r |= SafeCast.toUint((x >> r) > 0xf) << 2;\n\n // Shifts value right by the current result and use it as an index into this lookup table:\n //\n // | x (4 bits) | index | table[index] = MSB position |\n // |------------|---------|-----------------------------|\n // | 0000 | 0 | table[0] = 0 |\n // | 0001 | 1 | table[1] = 0 |\n // | 0010 | 2 | table[2] = 1 |\n // | 0011 | 3 | table[3] = 1 |\n // | 0100 | 4 | table[4] = 2 |\n // | 0101 | 5 | table[5] = 2 |\n // | 0110 | 6 | table[6] = 2 |\n // | 0111 | 7 | table[7] = 2 |\n // | 1000 | 8 | table[8] = 3 |\n // | 1001 | 9 | table[9] = 3 |\n // | 1010 | 10 | table[10] = 3 |\n // | 1011 | 11 | table[11] = 3 |\n // | 1100 | 12 | table[12] = 3 |\n // | 1101 | 13 | table[13] = 3 |\n // | 1110 | 14 | table[14] = 3 |\n // | 1111 | 15 | table[15] = 3 |\n //\n // The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes.\n assembly (\"memory-safe\") {\n r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000))\n }\n }\n\n /**\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log2(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);\n }\n }\n\n /**\n * @dev Return the log in base 10 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n */\n function log10(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >= 10 ** 64) {\n value /= 10 ** 64;\n result += 64;\n }\n if (value >= 10 ** 32) {\n value /= 10 ** 32;\n result += 32;\n }\n if (value >= 10 ** 16) {\n value /= 10 ** 16;\n result += 16;\n }\n if (value >= 10 ** 8) {\n value /= 10 ** 8;\n result += 8;\n }\n if (value >= 10 ** 4) {\n value /= 10 ** 4;\n result += 4;\n }\n if (value >= 10 ** 2) {\n value /= 10 ** 2;\n result += 2;\n }\n if (value >= 10 ** 1) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log10(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);\n }\n }\n\n /**\n * @dev Return the log in base 256 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n *\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n */\n function log256(uint256 x) internal pure returns (uint256 r) {\n // If value has upper 128 bits set, log2 result is at least 128\n r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;\n // If upper 64 bits of 128-bit half set, add 64 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;\n // If upper 32 bits of 64-bit half set, add 32 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;\n // If upper 16 bits of 32-bit half set, add 16 to result\n r |= SafeCast.toUint((x >> r) > 0xffff) << 4;\n // Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8\n return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);\n }\n\n /**\n * @dev Return the log in base 256, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log256(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);\n }\n }\n\n /**\n * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.\n */\n function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {\n return uint8(rounding) % 2 == 1;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/SafeCast.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeCast {\n /**\n * @dev Value doesn't fit in an uint of `bits` size.\n */\n error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);\n\n /**\n * @dev An int value doesn't fit in an uint of `bits` size.\n */\n error SafeCastOverflowedIntToUint(int256 value);\n\n /**\n * @dev Value doesn't fit in an int of `bits` size.\n */\n error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);\n\n /**\n * @dev An uint value doesn't fit in an int of `bits` size.\n */\n error SafeCastOverflowedUintToInt(uint256 value);\n\n /**\n * @dev Returns the downcasted uint248 from uint256, reverting on\n * overflow (when the input is greater than largest uint248).\n *\n * Counterpart to Solidity's `uint248` operator.\n *\n * Requirements:\n *\n * - input must fit into 248 bits\n */\n function toUint248(uint256 value) internal pure returns (uint248) {\n if (value > type(uint248).max) {\n revert SafeCastOverflowedUintDowncast(248, value);\n }\n return uint248(value);\n }\n\n /**\n * @dev Returns the downcasted uint240 from uint256, reverting on\n * overflow (when the input is greater than largest uint240).\n *\n * Counterpart to Solidity's `uint240` operator.\n *\n * Requirements:\n *\n * - input must fit into 240 bits\n */\n function toUint240(uint256 value) internal pure returns (uint240) {\n if (value > type(uint240).max) {\n revert SafeCastOverflowedUintDowncast(240, value);\n }\n return uint240(value);\n }\n\n /**\n * @dev Returns the downcasted uint232 from uint256, reverting on\n * overflow (when the input is greater than largest uint232).\n *\n * Counterpart to Solidity's `uint232` operator.\n *\n * Requirements:\n *\n * - input must fit into 232 bits\n */\n function toUint232(uint256 value) internal pure returns (uint232) {\n if (value > type(uint232).max) {\n revert SafeCastOverflowedUintDowncast(232, value);\n }\n return uint232(value);\n }\n\n /**\n * @dev Returns the downcasted uint224 from uint256, reverting on\n * overflow (when the input is greater than largest uint224).\n *\n * Counterpart to Solidity's `uint224` operator.\n *\n * Requirements:\n *\n * - input must fit into 224 bits\n */\n function toUint224(uint256 value) internal pure returns (uint224) {\n if (value > type(uint224).max) {\n revert SafeCastOverflowedUintDowncast(224, value);\n }\n return uint224(value);\n }\n\n /**\n * @dev Returns the downcasted uint216 from uint256, reverting on\n * overflow (when the input is greater than largest uint216).\n *\n * Counterpart to Solidity's `uint216` operator.\n *\n * Requirements:\n *\n * - input must fit into 216 bits\n */\n function toUint216(uint256 value) internal pure returns (uint216) {\n if (value > type(uint216).max) {\n revert SafeCastOverflowedUintDowncast(216, value);\n }\n return uint216(value);\n }\n\n /**\n * @dev Returns the downcasted uint208 from uint256, reverting on\n * overflow (when the input is greater than largest uint208).\n *\n * Counterpart to Solidity's `uint208` operator.\n *\n * Requirements:\n *\n * - input must fit into 208 bits\n */\n function toUint208(uint256 value) internal pure returns (uint208) {\n if (value > type(uint208).max) {\n revert SafeCastOverflowedUintDowncast(208, value);\n }\n return uint208(value);\n }\n\n /**\n * @dev Returns the downcasted uint200 from uint256, reverting on\n * overflow (when the input is greater than largest uint200).\n *\n * Counterpart to Solidity's `uint200` operator.\n *\n * Requirements:\n *\n * - input must fit into 200 bits\n */\n function toUint200(uint256 value) internal pure returns (uint200) {\n if (value > type(uint200).max) {\n revert SafeCastOverflowedUintDowncast(200, value);\n }\n return uint200(value);\n }\n\n /**\n * @dev Returns the downcasted uint192 from uint256, reverting on\n * overflow (when the input is greater than largest uint192).\n *\n * Counterpart to Solidity's `uint192` operator.\n *\n * Requirements:\n *\n * - input must fit into 192 bits\n */\n function toUint192(uint256 value) internal pure returns (uint192) {\n if (value > type(uint192).max) {\n revert SafeCastOverflowedUintDowncast(192, value);\n }\n return uint192(value);\n }\n\n /**\n * @dev Returns the downcasted uint184 from uint256, reverting on\n * overflow (when the input is greater than largest uint184).\n *\n * Counterpart to Solidity's `uint184` operator.\n *\n * Requirements:\n *\n * - input must fit into 184 bits\n */\n function toUint184(uint256 value) internal pure returns (uint184) {\n if (value > type(uint184).max) {\n revert SafeCastOverflowedUintDowncast(184, value);\n }\n return uint184(value);\n }\n\n /**\n * @dev Returns the downcasted uint176 from uint256, reverting on\n * overflow (when the input is greater than largest uint176).\n *\n * Counterpart to Solidity's `uint176` operator.\n *\n * Requirements:\n *\n * - input must fit into 176 bits\n */\n function toUint176(uint256 value) internal pure returns (uint176) {\n if (value > type(uint176).max) {\n revert SafeCastOverflowedUintDowncast(176, value);\n }\n return uint176(value);\n }\n\n /**\n * @dev Returns the downcasted uint168 from uint256, reverting on\n * overflow (when the input is greater than largest uint168).\n *\n * Counterpart to Solidity's `uint168` operator.\n *\n * Requirements:\n *\n * - input must fit into 168 bits\n */\n function toUint168(uint256 value) internal pure returns (uint168) {\n if (value > type(uint168).max) {\n revert SafeCastOverflowedUintDowncast(168, value);\n }\n return uint168(value);\n }\n\n /**\n * @dev Returns the downcasted uint160 from uint256, reverting on\n * overflow (when the input is greater than largest uint160).\n *\n * Counterpart to Solidity's `uint160` operator.\n *\n * Requirements:\n *\n * - input must fit into 160 bits\n */\n function toUint160(uint256 value) internal pure returns (uint160) {\n if (value > type(uint160).max) {\n revert SafeCastOverflowedUintDowncast(160, value);\n }\n return uint160(value);\n }\n\n /**\n * @dev Returns the downcasted uint152 from uint256, reverting on\n * overflow (when the input is greater than largest uint152).\n *\n * Counterpart to Solidity's `uint152` operator.\n *\n * Requirements:\n *\n * - input must fit into 152 bits\n */\n function toUint152(uint256 value) internal pure returns (uint152) {\n if (value > type(uint152).max) {\n revert SafeCastOverflowedUintDowncast(152, value);\n }\n return uint152(value);\n }\n\n /**\n * @dev Returns the downcasted uint144 from uint256, reverting on\n * overflow (when the input is greater than largest uint144).\n *\n * Counterpart to Solidity's `uint144` operator.\n *\n * Requirements:\n *\n * - input must fit into 144 bits\n */\n function toUint144(uint256 value) internal pure returns (uint144) {\n if (value > type(uint144).max) {\n revert SafeCastOverflowedUintDowncast(144, value);\n }\n return uint144(value);\n }\n\n /**\n * @dev Returns the downcasted uint136 from uint256, reverting on\n * overflow (when the input is greater than largest uint136).\n *\n * Counterpart to Solidity's `uint136` operator.\n *\n * Requirements:\n *\n * - input must fit into 136 bits\n */\n function toUint136(uint256 value) internal pure returns (uint136) {\n if (value > type(uint136).max) {\n revert SafeCastOverflowedUintDowncast(136, value);\n }\n return uint136(value);\n }\n\n /**\n * @dev Returns the downcasted uint128 from uint256, reverting on\n * overflow (when the input is greater than largest uint128).\n *\n * Counterpart to Solidity's `uint128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n */\n function toUint128(uint256 value) internal pure returns (uint128) {\n if (value > type(uint128).max) {\n revert SafeCastOverflowedUintDowncast(128, value);\n }\n return uint128(value);\n }\n\n /**\n * @dev Returns the downcasted uint120 from uint256, reverting on\n * overflow (when the input is greater than largest uint120).\n *\n * Counterpart to Solidity's `uint120` operator.\n *\n * Requirements:\n *\n * - input must fit into 120 bits\n */\n function toUint120(uint256 value) internal pure returns (uint120) {\n if (value > type(uint120).max) {\n revert SafeCastOverflowedUintDowncast(120, value);\n }\n return uint120(value);\n }\n\n /**\n * @dev Returns the downcasted uint112 from uint256, reverting on\n * overflow (when the input is greater than largest uint112).\n *\n * Counterpart to Solidity's `uint112` operator.\n *\n * Requirements:\n *\n * - input must fit into 112 bits\n */\n function toUint112(uint256 value) internal pure returns (uint112) {\n if (value > type(uint112).max) {\n revert SafeCastOverflowedUintDowncast(112, value);\n }\n return uint112(value);\n }\n\n /**\n * @dev Returns the downcasted uint104 from uint256, reverting on\n * overflow (when the input is greater than largest uint104).\n *\n * Counterpart to Solidity's `uint104` operator.\n *\n * Requirements:\n *\n * - input must fit into 104 bits\n */\n function toUint104(uint256 value) internal pure returns (uint104) {\n if (value > type(uint104).max) {\n revert SafeCastOverflowedUintDowncast(104, value);\n }\n return uint104(value);\n }\n\n /**\n * @dev Returns the downcasted uint96 from uint256, reverting on\n * overflow (when the input is greater than largest uint96).\n *\n * Counterpart to Solidity's `uint96` operator.\n *\n * Requirements:\n *\n * - input must fit into 96 bits\n */\n function toUint96(uint256 value) internal pure returns (uint96) {\n if (value > type(uint96).max) {\n revert SafeCastOverflowedUintDowncast(96, value);\n }\n return uint96(value);\n }\n\n /**\n * @dev Returns the downcasted uint88 from uint256, reverting on\n * overflow (when the input is greater than largest uint88).\n *\n * Counterpart to Solidity's `uint88` operator.\n *\n * Requirements:\n *\n * - input must fit into 88 bits\n */\n function toUint88(uint256 value) internal pure returns (uint88) {\n if (value > type(uint88).max) {\n revert SafeCastOverflowedUintDowncast(88, value);\n }\n return uint88(value);\n }\n\n /**\n * @dev Returns the downcasted uint80 from uint256, reverting on\n * overflow (when the input is greater than largest uint80).\n *\n * Counterpart to Solidity's `uint80` operator.\n *\n * Requirements:\n *\n * - input must fit into 80 bits\n */\n function toUint80(uint256 value) internal pure returns (uint80) {\n if (value > type(uint80).max) {\n revert SafeCastOverflowedUintDowncast(80, value);\n }\n return uint80(value);\n }\n\n /**\n * @dev Returns the downcasted uint72 from uint256, reverting on\n * overflow (when the input is greater than largest uint72).\n *\n * Counterpart to Solidity's `uint72` operator.\n *\n * Requirements:\n *\n * - input must fit into 72 bits\n */\n function toUint72(uint256 value) internal pure returns (uint72) {\n if (value > type(uint72).max) {\n revert SafeCastOverflowedUintDowncast(72, value);\n }\n return uint72(value);\n }\n\n /**\n * @dev Returns the downcasted uint64 from uint256, reverting on\n * overflow (when the input is greater than largest uint64).\n *\n * Counterpart to Solidity's `uint64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n */\n function toUint64(uint256 value) internal pure returns (uint64) {\n if (value > type(uint64).max) {\n revert SafeCastOverflowedUintDowncast(64, value);\n }\n return uint64(value);\n }\n\n /**\n * @dev Returns the downcasted uint56 from uint256, reverting on\n * overflow (when the input is greater than largest uint56).\n *\n * Counterpart to Solidity's `uint56` operator.\n *\n * Requirements:\n *\n * - input must fit into 56 bits\n */\n function toUint56(uint256 value) internal pure returns (uint56) {\n if (value > type(uint56).max) {\n revert SafeCastOverflowedUintDowncast(56, value);\n }\n return uint56(value);\n }\n\n /**\n * @dev Returns the downcasted uint48 from uint256, reverting on\n * overflow (when the input is greater than largest uint48).\n *\n * Counterpart to Solidity's `uint48` operator.\n *\n * Requirements:\n *\n * - input must fit into 48 bits\n */\n function toUint48(uint256 value) internal pure returns (uint48) {\n if (value > type(uint48).max) {\n revert SafeCastOverflowedUintDowncast(48, value);\n }\n return uint48(value);\n }\n\n /**\n * @dev Returns the downcasted uint40 from uint256, reverting on\n * overflow (when the input is greater than largest uint40).\n *\n * Counterpart to Solidity's `uint40` operator.\n *\n * Requirements:\n *\n * - input must fit into 40 bits\n */\n function toUint40(uint256 value) internal pure returns (uint40) {\n if (value > type(uint40).max) {\n revert SafeCastOverflowedUintDowncast(40, value);\n }\n return uint40(value);\n }\n\n /**\n * @dev Returns the downcasted uint32 from uint256, reverting on\n * overflow (when the input is greater than largest uint32).\n *\n * Counterpart to Solidity's `uint32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n */\n function toUint32(uint256 value) internal pure returns (uint32) {\n if (value > type(uint32).max) {\n revert SafeCastOverflowedUintDowncast(32, value);\n }\n return uint32(value);\n }\n\n /**\n * @dev Returns the downcasted uint24 from uint256, reverting on\n * overflow (when the input is greater than largest uint24).\n *\n * Counterpart to Solidity's `uint24` operator.\n *\n * Requirements:\n *\n * - input must fit into 24 bits\n */\n function toUint24(uint256 value) internal pure returns (uint24) {\n if (value > type(uint24).max) {\n revert SafeCastOverflowedUintDowncast(24, value);\n }\n return uint24(value);\n }\n\n /**\n * @dev Returns the downcasted uint16 from uint256, reverting on\n * overflow (when the input is greater than largest uint16).\n *\n * Counterpart to Solidity's `uint16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n */\n function toUint16(uint256 value) internal pure returns (uint16) {\n if (value > type(uint16).max) {\n revert SafeCastOverflowedUintDowncast(16, value);\n }\n return uint16(value);\n }\n\n /**\n * @dev Returns the downcasted uint8 from uint256, reverting on\n * overflow (when the input is greater than largest uint8).\n *\n * Counterpart to Solidity's `uint8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits\n */\n function toUint8(uint256 value) internal pure returns (uint8) {\n if (value > type(uint8).max) {\n revert SafeCastOverflowedUintDowncast(8, value);\n }\n return uint8(value);\n }\n\n /**\n * @dev Converts a signed int256 into an unsigned uint256.\n *\n * Requirements:\n *\n * - input must be greater than or equal to 0.\n */\n function toUint256(int256 value) internal pure returns (uint256) {\n if (value < 0) {\n revert SafeCastOverflowedIntToUint(value);\n }\n return uint256(value);\n }\n\n /**\n * @dev Returns the downcasted int248 from int256, reverting on\n * overflow (when the input is less than smallest int248 or\n * greater than largest int248).\n *\n * Counterpart to Solidity's `int248` operator.\n *\n * Requirements:\n *\n * - input must fit into 248 bits\n */\n function toInt248(int256 value) internal pure returns (int248 downcasted) {\n downcasted = int248(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(248, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int240 from int256, reverting on\n * overflow (when the input is less than smallest int240 or\n * greater than largest int240).\n *\n * Counterpart to Solidity's `int240` operator.\n *\n * Requirements:\n *\n * - input must fit into 240 bits\n */\n function toInt240(int256 value) internal pure returns (int240 downcasted) {\n downcasted = int240(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(240, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int232 from int256, reverting on\n * overflow (when the input is less than smallest int232 or\n * greater than largest int232).\n *\n * Counterpart to Solidity's `int232` operator.\n *\n * Requirements:\n *\n * - input must fit into 232 bits\n */\n function toInt232(int256 value) internal pure returns (int232 downcasted) {\n downcasted = int232(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(232, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int224 from int256, reverting on\n * overflow (when the input is less than smallest int224 or\n * greater than largest int224).\n *\n * Counterpart to Solidity's `int224` operator.\n *\n * Requirements:\n *\n * - input must fit into 224 bits\n */\n function toInt224(int256 value) internal pure returns (int224 downcasted) {\n downcasted = int224(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(224, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int216 from int256, reverting on\n * overflow (when the input is less than smallest int216 or\n * greater than largest int216).\n *\n * Counterpart to Solidity's `int216` operator.\n *\n * Requirements:\n *\n * - input must fit into 216 bits\n */\n function toInt216(int256 value) internal pure returns (int216 downcasted) {\n downcasted = int216(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(216, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int208 from int256, reverting on\n * overflow (when the input is less than smallest int208 or\n * greater than largest int208).\n *\n * Counterpart to Solidity's `int208` operator.\n *\n * Requirements:\n *\n * - input must fit into 208 bits\n */\n function toInt208(int256 value) internal pure returns (int208 downcasted) {\n downcasted = int208(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(208, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int200 from int256, reverting on\n * overflow (when the input is less than smallest int200 or\n * greater than largest int200).\n *\n * Counterpart to Solidity's `int200` operator.\n *\n * Requirements:\n *\n * - input must fit into 200 bits\n */\n function toInt200(int256 value) internal pure returns (int200 downcasted) {\n downcasted = int200(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(200, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int192 from int256, reverting on\n * overflow (when the input is less than smallest int192 or\n * greater than largest int192).\n *\n * Counterpart to Solidity's `int192` operator.\n *\n * Requirements:\n *\n * - input must fit into 192 bits\n */\n function toInt192(int256 value) internal pure returns (int192 downcasted) {\n downcasted = int192(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(192, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int184 from int256, reverting on\n * overflow (when the input is less than smallest int184 or\n * greater than largest int184).\n *\n * Counterpart to Solidity's `int184` operator.\n *\n * Requirements:\n *\n * - input must fit into 184 bits\n */\n function toInt184(int256 value) internal pure returns (int184 downcasted) {\n downcasted = int184(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(184, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int176 from int256, reverting on\n * overflow (when the input is less than smallest int176 or\n * greater than largest int176).\n *\n * Counterpart to Solidity's `int176` operator.\n *\n * Requirements:\n *\n * - input must fit into 176 bits\n */\n function toInt176(int256 value) internal pure returns (int176 downcasted) {\n downcasted = int176(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(176, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int168 from int256, reverting on\n * overflow (when the input is less than smallest int168 or\n * greater than largest int168).\n *\n * Counterpart to Solidity's `int168` operator.\n *\n * Requirements:\n *\n * - input must fit into 168 bits\n */\n function toInt168(int256 value) internal pure returns (int168 downcasted) {\n downcasted = int168(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(168, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int160 from int256, reverting on\n * overflow (when the input is less than smallest int160 or\n * greater than largest int160).\n *\n * Counterpart to Solidity's `int160` operator.\n *\n * Requirements:\n *\n * - input must fit into 160 bits\n */\n function toInt160(int256 value) internal pure returns (int160 downcasted) {\n downcasted = int160(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(160, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int152 from int256, reverting on\n * overflow (when the input is less than smallest int152 or\n * greater than largest int152).\n *\n * Counterpart to Solidity's `int152` operator.\n *\n * Requirements:\n *\n * - input must fit into 152 bits\n */\n function toInt152(int256 value) internal pure returns (int152 downcasted) {\n downcasted = int152(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(152, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int144 from int256, reverting on\n * overflow (when the input is less than smallest int144 or\n * greater than largest int144).\n *\n * Counterpart to Solidity's `int144` operator.\n *\n * Requirements:\n *\n * - input must fit into 144 bits\n */\n function toInt144(int256 value) internal pure returns (int144 downcasted) {\n downcasted = int144(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(144, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int136 from int256, reverting on\n * overflow (when the input is less than smallest int136 or\n * greater than largest int136).\n *\n * Counterpart to Solidity's `int136` operator.\n *\n * Requirements:\n *\n * - input must fit into 136 bits\n */\n function toInt136(int256 value) internal pure returns (int136 downcasted) {\n downcasted = int136(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(136, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int128 from int256, reverting on\n * overflow (when the input is less than smallest int128 or\n * greater than largest int128).\n *\n * Counterpart to Solidity's `int128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n */\n function toInt128(int256 value) internal pure returns (int128 downcasted) {\n downcasted = int128(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(128, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int120 from int256, reverting on\n * overflow (when the input is less than smallest int120 or\n * greater than largest int120).\n *\n * Counterpart to Solidity's `int120` operator.\n *\n * Requirements:\n *\n * - input must fit into 120 bits\n */\n function toInt120(int256 value) internal pure returns (int120 downcasted) {\n downcasted = int120(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(120, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int112 from int256, reverting on\n * overflow (when the input is less than smallest int112 or\n * greater than largest int112).\n *\n * Counterpart to Solidity's `int112` operator.\n *\n * Requirements:\n *\n * - input must fit into 112 bits\n */\n function toInt112(int256 value) internal pure returns (int112 downcasted) {\n downcasted = int112(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(112, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int104 from int256, reverting on\n * overflow (when the input is less than smallest int104 or\n * greater than largest int104).\n *\n * Counterpart to Solidity's `int104` operator.\n *\n * Requirements:\n *\n * - input must fit into 104 bits\n */\n function toInt104(int256 value) internal pure returns (int104 downcasted) {\n downcasted = int104(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(104, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int96 from int256, reverting on\n * overflow (when the input is less than smallest int96 or\n * greater than largest int96).\n *\n * Counterpart to Solidity's `int96` operator.\n *\n * Requirements:\n *\n * - input must fit into 96 bits\n */\n function toInt96(int256 value) internal pure returns (int96 downcasted) {\n downcasted = int96(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(96, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int88 from int256, reverting on\n * overflow (when the input is less than smallest int88 or\n * greater than largest int88).\n *\n * Counterpart to Solidity's `int88` operator.\n *\n * Requirements:\n *\n * - input must fit into 88 bits\n */\n function toInt88(int256 value) internal pure returns (int88 downcasted) {\n downcasted = int88(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(88, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int80 from int256, reverting on\n * overflow (when the input is less than smallest int80 or\n * greater than largest int80).\n *\n * Counterpart to Solidity's `int80` operator.\n *\n * Requirements:\n *\n * - input must fit into 80 bits\n */\n function toInt80(int256 value) internal pure returns (int80 downcasted) {\n downcasted = int80(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(80, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int72 from int256, reverting on\n * overflow (when the input is less than smallest int72 or\n * greater than largest int72).\n *\n * Counterpart to Solidity's `int72` operator.\n *\n * Requirements:\n *\n * - input must fit into 72 bits\n */\n function toInt72(int256 value) internal pure returns (int72 downcasted) {\n downcasted = int72(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(72, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int64 from int256, reverting on\n * overflow (when the input is less than smallest int64 or\n * greater than largest int64).\n *\n * Counterpart to Solidity's `int64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n */\n function toInt64(int256 value) internal pure returns (int64 downcasted) {\n downcasted = int64(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(64, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int56 from int256, reverting on\n * overflow (when the input is less than smallest int56 or\n * greater than largest int56).\n *\n * Counterpart to Solidity's `int56` operator.\n *\n * Requirements:\n *\n * - input must fit into 56 bits\n */\n function toInt56(int256 value) internal pure returns (int56 downcasted) {\n downcasted = int56(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(56, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int48 from int256, reverting on\n * overflow (when the input is less than smallest int48 or\n * greater than largest int48).\n *\n * Counterpart to Solidity's `int48` operator.\n *\n * Requirements:\n *\n * - input must fit into 48 bits\n */\n function toInt48(int256 value) internal pure returns (int48 downcasted) {\n downcasted = int48(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(48, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int40 from int256, reverting on\n * overflow (when the input is less than smallest int40 or\n * greater than largest int40).\n *\n * Counterpart to Solidity's `int40` operator.\n *\n * Requirements:\n *\n * - input must fit into 40 bits\n */\n function toInt40(int256 value) internal pure returns (int40 downcasted) {\n downcasted = int40(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(40, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int32 from int256, reverting on\n * overflow (when the input is less than smallest int32 or\n * greater than largest int32).\n *\n * Counterpart to Solidity's `int32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n */\n function toInt32(int256 value) internal pure returns (int32 downcasted) {\n downcasted = int32(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(32, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int24 from int256, reverting on\n * overflow (when the input is less than smallest int24 or\n * greater than largest int24).\n *\n * Counterpart to Solidity's `int24` operator.\n *\n * Requirements:\n *\n * - input must fit into 24 bits\n */\n function toInt24(int256 value) internal pure returns (int24 downcasted) {\n downcasted = int24(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(24, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int16 from int256, reverting on\n * overflow (when the input is less than smallest int16 or\n * greater than largest int16).\n *\n * Counterpart to Solidity's `int16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n */\n function toInt16(int256 value) internal pure returns (int16 downcasted) {\n downcasted = int16(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(16, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int8 from int256, reverting on\n * overflow (when the input is less than smallest int8 or\n * greater than largest int8).\n *\n * Counterpart to Solidity's `int8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits\n */\n function toInt8(int256 value) internal pure returns (int8 downcasted) {\n downcasted = int8(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(8, value);\n }\n }\n\n /**\n * @dev Converts an unsigned uint256 into a signed int256.\n *\n * Requirements:\n *\n * - input must be less than or equal to maxInt256.\n */\n function toInt256(uint256 value) internal pure returns (int256) {\n // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n if (value > uint256(type(int256).max)) {\n revert SafeCastOverflowedUintToInt(value);\n }\n return int256(value);\n }\n\n /**\n * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.\n */\n function toUint(bool b) internal pure returns (uint256 u) {\n assembly (\"memory-safe\") {\n u := iszero(iszero(b))\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/SignedMath.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol)\n\npragma solidity ^0.8.20;\n\nimport {SafeCast} from \"./SafeCast.sol\";\n\n/**\n * @dev Standard signed math utilities missing in the Solidity language.\n */\nlibrary SignedMath {\n /**\n * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.\n *\n * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.\n * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute\n * one branch when needed, making this function more expensive.\n */\n function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {\n unchecked {\n // branchless ternary works because:\n // b ^ (a ^ b) == a\n // b ^ 0 == b\n return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));\n }\n }\n\n /**\n * @dev Returns the largest of two signed numbers.\n */\n function max(int256 a, int256 b) internal pure returns (int256) {\n return ternary(a > b, a, b);\n }\n\n /**\n * @dev Returns the smallest of two signed numbers.\n */\n function min(int256 a, int256 b) internal pure returns (int256) {\n return ternary(a < b, a, b);\n }\n\n /**\n * @dev Returns the average of two signed numbers without overflow.\n * The result is rounded towards zero.\n */\n function average(int256 a, int256 b) internal pure returns (int256) {\n // Formula from the book \"Hacker's Delight\"\n int256 x = (a & b) + ((a ^ b) >> 1);\n return x + (int256(uint256(x) >> 255) & (a ^ b));\n }\n\n /**\n * @dev Returns the absolute unsigned value of a signed value.\n */\n function abs(int256 n) internal pure returns (uint256) {\n unchecked {\n // Formula from the \"Bit Twiddling Hacks\" by Sean Eron Anderson.\n // Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,\n // taking advantage of the most significant (or \"sign\" bit) in two's complement representation.\n // This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,\n // the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative).\n int256 mask = n >> 255;\n\n // A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.\n return uint256((n + mask) ^ mask);\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Panic.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Helper library for emitting standardized panic codes.\n *\n * ```solidity\n * contract Example {\n * using Panic for uint256;\n *\n * // Use any of the declared internal constants\n * function foo() { Panic.GENERIC.panic(); }\n *\n * // Alternatively\n * function foo() { Panic.panic(Panic.GENERIC); }\n * }\n * ```\n *\n * Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].\n *\n * _Available since v5.1._\n */\n// slither-disable-next-line unused-state\nlibrary Panic {\n /// @dev generic / unspecified error\n uint256 internal constant GENERIC = 0x00;\n /// @dev used by the assert() builtin\n uint256 internal constant ASSERT = 0x01;\n /// @dev arithmetic underflow or overflow\n uint256 internal constant UNDER_OVERFLOW = 0x11;\n /// @dev division or modulo by zero\n uint256 internal constant DIVISION_BY_ZERO = 0x12;\n /// @dev enum conversion error\n uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;\n /// @dev invalid encoding in storage\n uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;\n /// @dev empty array pop\n uint256 internal constant EMPTY_ARRAY_POP = 0x31;\n /// @dev array out of bounds access\n uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;\n /// @dev resource error (too large allocation or too large array)\n uint256 internal constant RESOURCE_ERROR = 0x41;\n /// @dev calling invalid internal function\n uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;\n\n /// @dev Reverts with a panic code. Recommended to use with\n /// the internal constants with predefined codes.\n function panic(uint256 code) internal pure {\n assembly (\"memory-safe\") {\n mstore(0x00, 0x4e487b71)\n mstore(0x20, code)\n revert(0x1c, 0x24)\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/ReentrancyGuard.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,\n * consider using {ReentrancyGuardTransient} instead.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant NOT_ENTERED = 1;\n uint256 private constant ENTERED = 2;\n\n uint256 private _status;\n\n /**\n * @dev Unauthorized reentrant call.\n */\n error ReentrancyGuardReentrantCall();\n\n constructor() {\n _status = NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and making it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n _nonReentrantBefore();\n _;\n _nonReentrantAfter();\n }\n\n function _nonReentrantBefore() private {\n // On the first call to nonReentrant, _status will be NOT_ENTERED\n if (_status == ENTERED) {\n revert ReentrancyGuardReentrantCall();\n }\n\n // Any calls to nonReentrant after this point will fail\n _status = ENTERED;\n }\n\n function _nonReentrantAfter() private {\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = NOT_ENTERED;\n }\n\n /**\n * @dev Returns true if the reentrancy guard is currently set to \"entered\", which indicates there is a\n * `nonReentrant` function in the call stack.\n */\n function _reentrancyGuardEntered() internal view returns (bool) {\n return _status == ENTERED;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/ShortStrings.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/ShortStrings.sol)\n\npragma solidity ^0.8.20;\n\nimport {StorageSlot} from \"./StorageSlot.sol\";\n\n// | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |\n// | length | 0x BB |\ntype ShortString is bytes32;\n\n/**\n * @dev This library provides functions to convert short memory strings\n * into a `ShortString` type that can be used as an immutable variable.\n *\n * Strings of arbitrary length can be optimized using this library if\n * they are short enough (up to 31 bytes) by packing them with their\n * length (1 byte) in a single EVM word (32 bytes). Additionally, a\n * fallback mechanism can be used for every other case.\n *\n * Usage example:\n *\n * ```solidity\n * contract Named {\n * using ShortStrings for *;\n *\n * ShortString private immutable _name;\n * string private _nameFallback;\n *\n * constructor(string memory contractName) {\n * _name = contractName.toShortStringWithFallback(_nameFallback);\n * }\n *\n * function name() external view returns (string memory) {\n * return _name.toStringWithFallback(_nameFallback);\n * }\n * }\n * ```\n */\nlibrary ShortStrings {\n // Used as an identifier for strings longer than 31 bytes.\n bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;\n\n error StringTooLong(string str);\n error InvalidShortString();\n\n /**\n * @dev Encode a string of at most 31 chars into a `ShortString`.\n *\n * This will trigger a `StringTooLong` error is the input string is too long.\n */\n function toShortString(string memory str) internal pure returns (ShortString) {\n bytes memory bstr = bytes(str);\n if (bstr.length > 31) {\n revert StringTooLong(str);\n }\n return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));\n }\n\n /**\n * @dev Decode a `ShortString` back to a \"normal\" string.\n */\n function toString(ShortString sstr) internal pure returns (string memory) {\n uint256 len = byteLength(sstr);\n // using `new string(len)` would work locally but is not memory safe.\n string memory str = new string(32);\n assembly (\"memory-safe\") {\n mstore(str, len)\n mstore(add(str, 0x20), sstr)\n }\n return str;\n }\n\n /**\n * @dev Return the length of a `ShortString`.\n */\n function byteLength(ShortString sstr) internal pure returns (uint256) {\n uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;\n if (result > 31) {\n revert InvalidShortString();\n }\n return result;\n }\n\n /**\n * @dev Encode a string into a `ShortString`, or write it to storage if it is too long.\n */\n function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {\n if (bytes(value).length < 32) {\n return toShortString(value);\n } else {\n StorageSlot.getStringSlot(store).value = value;\n return ShortString.wrap(FALLBACK_SENTINEL);\n }\n }\n\n /**\n * @dev Decode a string that was encoded to `ShortString` or written to storage using {toShortStringWithFallback}.\n */\n function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {\n if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {\n return toString(value);\n } else {\n return store;\n }\n }\n\n /**\n * @dev Return the length of a string that was encoded to `ShortString` or written to storage using\n * {toShortStringWithFallback}.\n *\n * WARNING: This will return the \"byte length\" of the string. This may not reflect the actual length in terms of\n * actual characters as the UTF-8 encoding of a single character can span over multiple bytes.\n */\n function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {\n if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {\n return byteLength(value);\n } else {\n return bytes(store).length;\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/StorageSlot.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)\n// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Library for reading and writing primitive types to specific storage slots.\n *\n * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\n * This library helps with reading and writing to such slots without the need for inline assembly.\n *\n * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\n *\n * Example usage to set ERC-1967 implementation slot:\n * ```solidity\n * contract ERC1967 {\n * // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.\n * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n *\n * function _getImplementation() internal view returns (address) {\n * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n * }\n *\n * function _setImplementation(address newImplementation) internal {\n * require(newImplementation.code.length > 0);\n * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n * }\n * }\n * ```\n *\n * TIP: Consider using this library along with {SlotDerivation}.\n */\nlibrary StorageSlot {\n struct AddressSlot {\n address value;\n }\n\n struct BooleanSlot {\n bool value;\n }\n\n struct Bytes32Slot {\n bytes32 value;\n }\n\n struct Uint256Slot {\n uint256 value;\n }\n\n struct Int256Slot {\n int256 value;\n }\n\n struct StringSlot {\n string value;\n }\n\n struct BytesSlot {\n bytes value;\n }\n\n /**\n * @dev Returns an `AddressSlot` with member `value` located at `slot`.\n */\n function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `BooleanSlot` with member `value` located at `slot`.\n */\n function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Bytes32Slot` with member `value` located at `slot`.\n */\n function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Uint256Slot` with member `value` located at `slot`.\n */\n function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Int256Slot` with member `value` located at `slot`.\n */\n function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `StringSlot` with member `value` located at `slot`.\n */\n function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `StringSlot` representation of the string storage pointer `store`.\n */\n function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := store.slot\n }\n }\n\n /**\n * @dev Returns a `BytesSlot` with member `value` located at `slot`.\n */\n function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.\n */\n function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := store.slot\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Strings.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/Strings.sol)\n\npragma solidity ^0.8.20;\n\nimport {Math} from \"./math/Math.sol\";\nimport {SafeCast} from \"./math/SafeCast.sol\";\nimport {SignedMath} from \"./math/SignedMath.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n using SafeCast for *;\n\n bytes16 private constant HEX_DIGITS = \"0123456789abcdef\";\n uint8 private constant ADDRESS_LENGTH = 20;\n uint256 private constant SPECIAL_CHARS_LOOKUP =\n (1 << 0x08) | // backspace\n (1 << 0x09) | // tab\n (1 << 0x0a) | // newline\n (1 << 0x0c) | // form feed\n (1 << 0x0d) | // carriage return\n (1 << 0x22) | // double quote\n (1 << 0x5c); // backslash\n\n /**\n * @dev The `value` string doesn't fit in the specified `length`.\n */\n error StringsInsufficientHexLength(uint256 value, uint256 length);\n\n /**\n * @dev The string being parsed contains characters that are not in scope of the given base.\n */\n error StringsInvalidChar();\n\n /**\n * @dev The string being parsed is not a properly formatted address.\n */\n error StringsInvalidAddressFormat();\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n unchecked {\n uint256 length = Math.log10(value) + 1;\n string memory buffer = new string(length);\n uint256 ptr;\n assembly (\"memory-safe\") {\n ptr := add(buffer, add(32, length))\n }\n while (true) {\n ptr--;\n assembly (\"memory-safe\") {\n mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))\n }\n value /= 10;\n if (value == 0) break;\n }\n return buffer;\n }\n }\n\n /**\n * @dev Converts a `int256` to its ASCII `string` decimal representation.\n */\n function toStringSigned(int256 value) internal pure returns (string memory) {\n return string.concat(value < 0 ? \"-\" : \"\", toString(SignedMath.abs(value)));\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n unchecked {\n return toHexString(value, Math.log256(value) + 1);\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n uint256 localValue = value;\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = HEX_DIGITS[localValue & 0xf];\n localValue >>= 4;\n }\n if (localValue != 0) {\n revert StringsInsufficientHexLength(value, length);\n }\n return string(buffer);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal\n * representation.\n */\n function toHexString(address addr) internal pure returns (string memory) {\n return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal\n * representation, according to EIP-55.\n */\n function toChecksumHexString(address addr) internal pure returns (string memory) {\n bytes memory buffer = bytes(toHexString(addr));\n\n // hash the hex part of buffer (skip length + 2 bytes, length 40)\n uint256 hashValue;\n assembly (\"memory-safe\") {\n hashValue := shr(96, keccak256(add(buffer, 0x22), 40))\n }\n\n for (uint256 i = 41; i > 1; --i) {\n // possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)\n if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {\n // case shift by xoring with 0x20\n buffer[i] ^= 0x20;\n }\n hashValue >>= 4;\n }\n return string(buffer);\n }\n\n /**\n * @dev Returns true if the two strings are equal.\n */\n function equal(string memory a, string memory b) internal pure returns (bool) {\n return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));\n }\n\n /**\n * @dev Parse a decimal string and returns the value as a `uint256`.\n *\n * Requirements:\n * - The string must be formatted as `[0-9]*`\n * - The result must fit into an `uint256` type\n */\n function parseUint(string memory input) internal pure returns (uint256) {\n return parseUint(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseUint-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `[0-9]*`\n * - The result must fit into an `uint256` type\n */\n function parseUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {\n (bool success, uint256 value) = tryParseUint(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseUint-string} that returns false if the parsing fails because of an invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseUint(string memory input) internal pure returns (bool success, uint256 value) {\n return _tryParseUintUncheckedBounds(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseUint-string-uint256-uint256} that returns false if the parsing fails because of an invalid\n * character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseUint(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, uint256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseUintUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseUint-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseUintUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, uint256 value) {\n bytes memory buffer = bytes(input);\n\n uint256 result = 0;\n for (uint256 i = begin; i < end; ++i) {\n uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));\n if (chr > 9) return (false, 0);\n result *= 10;\n result += chr;\n }\n return (true, result);\n }\n\n /**\n * @dev Parse a decimal string and returns the value as a `int256`.\n *\n * Requirements:\n * - The string must be formatted as `[-+]?[0-9]*`\n * - The result must fit in an `int256` type.\n */\n function parseInt(string memory input) internal pure returns (int256) {\n return parseInt(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseInt-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `[-+]?[0-9]*`\n * - The result must fit in an `int256` type.\n */\n function parseInt(string memory input, uint256 begin, uint256 end) internal pure returns (int256) {\n (bool success, int256 value) = tryParseInt(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseInt-string} that returns false if the parsing fails because of an invalid character or if\n * the result does not fit in a `int256`.\n *\n * NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.\n */\n function tryParseInt(string memory input) internal pure returns (bool success, int256 value) {\n return _tryParseIntUncheckedBounds(input, 0, bytes(input).length);\n }\n\n uint256 private constant ABS_MIN_INT256 = 2 ** 255;\n\n /**\n * @dev Variant of {parseInt-string-uint256-uint256} that returns false if the parsing fails because of an invalid\n * character or if the result does not fit in a `int256`.\n *\n * NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.\n */\n function tryParseInt(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, int256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseIntUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseInt-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseIntUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, int256 value) {\n bytes memory buffer = bytes(input);\n\n // Check presence of a negative sign.\n bytes1 sign = begin == end ? bytes1(0) : bytes1(_unsafeReadBytesOffset(buffer, begin)); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n bool positiveSign = sign == bytes1(\"+\");\n bool negativeSign = sign == bytes1(\"-\");\n uint256 offset = (positiveSign || negativeSign).toUint();\n\n (bool absSuccess, uint256 absValue) = tryParseUint(input, begin + offset, end);\n\n if (absSuccess && absValue < ABS_MIN_INT256) {\n return (true, negativeSign ? -int256(absValue) : int256(absValue));\n } else if (absSuccess && negativeSign && absValue == ABS_MIN_INT256) {\n return (true, type(int256).min);\n } else return (false, 0);\n }\n\n /**\n * @dev Parse a hexadecimal string (with or without \"0x\" prefix), and returns the value as a `uint256`.\n *\n * Requirements:\n * - The string must be formatted as `(0x)?[0-9a-fA-F]*`\n * - The result must fit in an `uint256` type.\n */\n function parseHexUint(string memory input) internal pure returns (uint256) {\n return parseHexUint(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseHexUint-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `(0x)?[0-9a-fA-F]*`\n * - The result must fit in an `uint256` type.\n */\n function parseHexUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {\n (bool success, uint256 value) = tryParseHexUint(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseHexUint-string} that returns false if the parsing fails because of an invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseHexUint(string memory input) internal pure returns (bool success, uint256 value) {\n return _tryParseHexUintUncheckedBounds(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseHexUint-string-uint256-uint256} that returns false if the parsing fails because of an\n * invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseHexUint(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, uint256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseHexUintUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseHexUint-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseHexUintUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, uint256 value) {\n bytes memory buffer = bytes(input);\n\n // skip 0x prefix if present\n bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(buffer, begin)) == bytes2(\"0x\"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n uint256 offset = hasPrefix.toUint() * 2;\n\n uint256 result = 0;\n for (uint256 i = begin + offset; i < end; ++i) {\n uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));\n if (chr > 15) return (false, 0);\n result *= 16;\n unchecked {\n // Multiplying by 16 is equivalent to a shift of 4 bits (with additional overflow check).\n // This guarantees that adding a value < 16 will not cause an overflow, hence the unchecked.\n result += chr;\n }\n }\n return (true, result);\n }\n\n /**\n * @dev Parse a hexadecimal string (with or without \"0x\" prefix), and returns the value as an `address`.\n *\n * Requirements:\n * - The string must be formatted as `(0x)?[0-9a-fA-F]{40}`\n */\n function parseAddress(string memory input) internal pure returns (address) {\n return parseAddress(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseAddress-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `(0x)?[0-9a-fA-F]{40}`\n */\n function parseAddress(string memory input, uint256 begin, uint256 end) internal pure returns (address) {\n (bool success, address value) = tryParseAddress(input, begin, end);\n if (!success) revert StringsInvalidAddressFormat();\n return value;\n }\n\n /**\n * @dev Variant of {parseAddress-string} that returns false if the parsing fails because the input is not a properly\n * formatted address. See {parseAddress-string} requirements.\n */\n function tryParseAddress(string memory input) internal pure returns (bool success, address value) {\n return tryParseAddress(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseAddress-string-uint256-uint256} that returns false if the parsing fails because input is not a properly\n * formatted address. See {parseAddress-string-uint256-uint256} requirements.\n */\n function tryParseAddress(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, address value) {\n if (end > bytes(input).length || begin > end) return (false, address(0));\n\n bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(bytes(input), begin)) == bytes2(\"0x\"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n uint256 expectedLength = 40 + hasPrefix.toUint() * 2;\n\n // check that input is the correct length\n if (end - begin == expectedLength) {\n // length guarantees that this does not overflow, and value is at most type(uint160).max\n (bool s, uint256 v) = _tryParseHexUintUncheckedBounds(input, begin, end);\n return (s, address(uint160(v)));\n } else {\n return (false, address(0));\n }\n }\n\n function _tryParseChr(bytes1 chr) private pure returns (uint8) {\n uint8 value = uint8(chr);\n\n // Try to parse `chr`:\n // - Case 1: [0-9]\n // - Case 2: [a-f]\n // - Case 3: [A-F]\n // - otherwise not supported\n unchecked {\n if (value > 47 && value < 58) value -= 48;\n else if (value > 96 && value < 103) value -= 87;\n else if (value > 64 && value < 71) value -= 55;\n else return type(uint8).max;\n }\n\n return value;\n }\n\n /**\n * @dev Escape special characters in JSON strings. This can be useful to prevent JSON injection in NFT metadata.\n *\n * WARNING: This function should only be used in double quoted JSON strings. Single quotes are not escaped.\n *\n * NOTE: This function escapes all unicode characters, and not just the ones in ranges defined in section 2.5 of\n * RFC-4627 (U+0000 to U+001F, U+0022 and U+005C). ECMAScript's `JSON.parse` does recover escaped unicode\n * characters that are not in this range, but other tooling may provide different results.\n */\n function escapeJSON(string memory input) internal pure returns (string memory) {\n bytes memory buffer = bytes(input);\n bytes memory output = new bytes(2 * buffer.length); // worst case scenario\n uint256 outputLength = 0;\n\n for (uint256 i; i < buffer.length; ++i) {\n bytes1 char = bytes1(_unsafeReadBytesOffset(buffer, i));\n if (((SPECIAL_CHARS_LOOKUP & (1 << uint8(char))) != 0)) {\n output[outputLength++] = \"\\\\\";\n if (char == 0x08) output[outputLength++] = \"b\";\n else if (char == 0x09) output[outputLength++] = \"t\";\n else if (char == 0x0a) output[outputLength++] = \"n\";\n else if (char == 0x0c) output[outputLength++] = \"f\";\n else if (char == 0x0d) output[outputLength++] = \"r\";\n else if (char == 0x5c) output[outputLength++] = \"\\\\\";\n else if (char == 0x22) {\n // solhint-disable-next-line quotes\n output[outputLength++] = '\"';\n }\n } else {\n output[outputLength++] = char;\n }\n }\n // write the actual length and deallocate unused memory\n assembly (\"memory-safe\") {\n mstore(output, outputLength)\n mstore(0x40, add(output, shl(5, shr(5, add(outputLength, 63)))))\n }\n\n return string(output);\n }\n\n /**\n * @dev Reads a bytes32 from a bytes array without bounds checking.\n *\n * NOTE: making this function internal would mean it could be used with memory unsafe offset, and marking the\n * assembly block as such would prevent some optimizations.\n */\n function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {\n // This is not memory safe in the general case, but all calls to this private function are within bounds.\n assembly (\"memory-safe\") {\n value := mload(add(buffer, add(0x20, offset)))\n }\n }\n}\n" + }, + "project/contracts/Controller.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\n\nimport './interfaces/IController.sol';\n\n/**\n * @title Controller\n * @dev Manages allow lists for solvers, executors, proposal signers and validators\n */\ncontract Controller is IController, Ownable {\n // List of allowed solvers\n mapping (address => bool) public override isSolverAllowed;\n\n // List of allowed executors\n mapping (address => bool) public override isExecutorAllowed;\n\n // List of allowed proposal signers\n mapping (address => bool) public override isProposalSignerAllowed;\n\n // List of allowed validators\n mapping (address => bool) public override isValidatorAllowed;\n\n // Minimum number of validations allowed\n uint8 public override minValidations;\n\n /**\n * @dev Creates a new Controller contract\n * @param owner Address that will own the contract\n * @param solvers List of allowed solvers\n * @param executors List of allowed executors\n * @param proposalSigners List of allowed proposal signers\n * @param validators List of allowed validators\n * @param _minValidations Minimum number of validations allowed\n */\n constructor(\n address owner,\n address[] memory solvers,\n address[] memory executors,\n address[] memory proposalSigners,\n address[] memory validators,\n uint8 _minValidations\n ) Ownable(owner) {\n for (uint256 i = 0; i < solvers.length; i++) _setAllowedSolver(solvers[i], true);\n for (uint256 i = 0; i < executors.length; i++) _setAllowedExecutor(executors[i], true);\n for (uint256 i = 0; i < proposalSigners.length; i++) _setAllowedProposalSigner(proposalSigners[i], true);\n for (uint256 i = 0; i < validators.length; i++) _setAllowedValidator(validators[i], true);\n _setMinValidations(_minValidations);\n }\n\n /**\n * @dev Sets permissions for multiple solvers\n * @param solvers List of solver addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedSolvers(address[] memory solvers, bool[] memory alloweds) external override onlyOwner {\n if (solvers.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < solvers.length; i++) _setAllowedSolver(solvers[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple executors\n * @param executors List of executor addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedExecutors(address[] memory executors, bool[] memory alloweds) external override onlyOwner {\n if (executors.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < executors.length; i++) _setAllowedExecutor(executors[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple proposal signers\n * @param signers List of proposal signer addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedProposalSigners(address[] memory signers, bool[] memory alloweds) external override onlyOwner {\n if (signers.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < signers.length; i++) _setAllowedProposalSigner(signers[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple validators\n * @param validators List of validator addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedValidators(address[] memory validators, bool[] memory alloweds) external override onlyOwner {\n if (validators.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < validators.length; i++) _setAllowedValidator(validators[i], alloweds[i]);\n }\n\n /**\n * @dev Sets the minimum number of validations allowed\n * @param newMinValidations minimum number of validations allowed\n */\n function setMinValidations(uint8 newMinValidations) external override onlyOwner {\n _setMinValidations(newMinValidations);\n }\n\n /**\n * @dev Sets a solver permission\n */\n function _setAllowedSolver(address solver, bool allowed) internal {\n isSolverAllowed[solver] = allowed;\n emit SolverAllowedSet(solver, allowed);\n }\n\n /**\n * @dev Sets an executor permission\n */\n function _setAllowedExecutor(address executor, bool allowed) internal {\n isExecutorAllowed[executor] = allowed;\n emit ExecutorAllowedSet(executor, allowed);\n }\n\n /**\n * @dev Sets a proposal signer permission\n */\n function _setAllowedProposalSigner(address signer, bool allowed) internal {\n isProposalSignerAllowed[signer] = allowed;\n emit ProposalSignerAllowedSet(signer, allowed);\n }\n\n /**\n * @dev Sets a validator permission\n */\n function _setAllowedValidator(address validator, bool allowed) internal {\n isValidatorAllowed[validator] = allowed;\n emit ValidatorAllowedSet(validator, allowed);\n }\n\n /**\n * @dev Sets the minimum number of validations allowed\n */\n function _setMinValidations(uint8 newMinValidations) internal {\n minValidations = newMinValidations;\n emit MinValidationSet(newMinValidations);\n }\n}\n" + }, + "project/contracts/Intents.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Enum representing the type of intent operation.\n * - Swap: Swap tokens between chains or tokens.\n * - Transfer: Transfer tokens to one or more recipients.\n * - Call: Execute arbitrary contract calls.\n */\nenum OpType {\n Swap,\n Transfer,\n Call\n}\n\n/**\n * @dev Execution structure.\n * @param intent Intent to be fulfilled.\n * @param proposal Proposal to be executed.\n * @param signature Proposal signature.\n */\nstruct Execution {\n Intent intent;\n Proposal proposal;\n bytes signature;\n}\n\n/**\n * @dev EIP-712 typed data struct representing a validator's approval of an intent.\n * @param intent The hash of the intent being validated.\n */\nstruct Validation {\n bytes32 intent;\n}\n\n/**\n * @dev General intent structure used to abstract over different intent types.\n * @param op The type of operation this intent represents.\n * @param user The originator of the intent.\n * @param settler The address responsible for executing the intent on-chain.\n * @param nonce A unique value used to prevent replay attacks and distinguish intents.\n * @param deadline The timestamp by which the intent must be executed.\n * @param data ABI-encoded data representing a specific intent type (e.g. SwapIntent, TransferIntent, CallIntent).\n * @param maxFees List of max fees the user is willing to pay for the intent.\n * @param events List of custom intent events to be emitted.\n * @param configSig The signature of the configuration that this intent belongs to\n * @param minValidations The minimum number of validator approvals required for this intent to be considered valid.\n * @param validations The list validator signatures attesting to this intent.\n */\nstruct Intent {\n uint8 op;\n address user;\n address settler;\n bytes32 nonce;\n uint256 deadline;\n bytes data;\n MaxFee[] maxFees;\n IntentEvent[] events;\n bytes configSig;\n uint256 minValidations;\n bytes[] validations;\n}\n\n/**\n * @dev Max fee representation\n * @param token Token used to pay for the execution fee.\n * @param amount Max amount of fee token to be paid for settling this intent.\n */\nstruct MaxFee {\n address token;\n uint256 amount;\n}\n\n/**\n * @dev Intent event representation.\n * @param topic Event topic to be emitted.\n * @param data Event data to be emitted.\n */\nstruct IntentEvent {\n bytes32 topic;\n bytes data;\n}\n\n/**\n * @dev Represents a swap intent between two chains.\n * @param sourceChain Chain ID where tokens will be sent from.\n * @param destinationChain Chain ID where tokens will be received.\n * @param tokensIn List of input tokens and amounts to swap.\n * @param tokensOut List of expected output tokens, minimum amounts, and recipients.\n */\nstruct SwapIntent {\n uint256 sourceChain;\n uint256 destinationChain;\n TokenIn[] tokensIn;\n TokenOut[] tokensOut;\n}\n\n/**\n * @dev Token in representation.\n * @param token Address of a token to be sent.\n * @param amount Amount of tokens to be sent.\n */\nstruct TokenIn {\n address token;\n uint256 amount;\n}\n\n/**\n * @dev Token out representation.\n * @param token Address of a token to be received.\n * @param minAmount Minimum amount of tokens to be received.\n * @param recipient Recipient address that will receive the token out.\n */\nstruct TokenOut {\n address token;\n uint256 minAmount;\n address recipient;\n}\n\n/**\n * @dev Represents a transfer intent containing multiple token transfers.\n * @param chainId Chain ID where the transfers should be executed.\n * @param transfers List of token transfers to be performed.\n */\nstruct TransferIntent {\n uint256 chainId;\n TransferData[] transfers;\n}\n\n/**\n * @dev Transfer data for a single token transfer.\n * @param token Address of the token to transfer.\n * @param amount Amount of the token to transfer.\n * @param recipient Recipient of the token transfer.\n */\nstruct TransferData {\n address token;\n uint256 amount;\n address recipient;\n}\n\n/**\n * @dev Represents a generic call intent consisting of one or more contract calls.\n * @param chainId Chain ID where the calls should be executed.\n * @param calls List of low-level contract calls to be executed.\n */\nstruct CallIntent {\n uint256 chainId;\n CallData[] calls;\n}\n\n/**\n * @dev Low-level call data for a target contract interaction.\n * @param target Target contract address.\n * @param data Calldata to be sent to the target.\n * @param value ETH value to send along with the call.\n */\nstruct CallData {\n address target;\n bytes data;\n uint256 value;\n}\n\n/**\n * @dev Generic proposal structure representing a solver’s response to an intent.\n * @param deadline Timestamp until when the proposal is valid.\n * @param data ABI-encoded proposal-specific data (e.g. SwapProposal).\n * @param fees List of fee amounts the solver requires for execution.\n */\nstruct Proposal {\n uint256 deadline;\n bytes data;\n uint256[] fees;\n}\n\n/**\n * @dev Swap proposal representation for a swap intent.\n * @param executor Address of the executor contract that should be called during intent execution.\n * @param data Arbitrary data used to call the executor contract.\n * @param amountsOut List of amounts of tokens out proposed by the solver.\n */\nstruct SwapProposal {\n address executor;\n bytes data;\n uint256[] amountsOut;\n}\n\nlibrary IntentsHelpers {\n bytes32 internal constant INTENT_TYPE_HASH =\n keccak256(\n 'Intent(uint8 op,address user,address settler,bytes32 nonce,uint256 deadline,bytes data,MaxFee[] maxFees,IntentEvent[] events,bytes configSig,uint256 minValidations)IntentEvent(bytes32 topic,bytes data)MaxFee(address token,uint256 amount)'\n );\n\n bytes32 internal constant PROPOSAL_TYPE_HASH =\n keccak256('Proposal(bytes32 intent,address solver,uint256 deadline,bytes data,uint256[] fees)');\n\n bytes32 internal constant VALIDATION_TYPE_HASH = keccak256('Validation(bytes32 intent)');\n\n bytes32 internal constant MAX_FEE_TYPE_HASH = keccak256('MaxFee(address token,uint256 amount)');\n\n bytes32 internal constant INTENT_EVENT_TYPE_HASH = keccak256('IntentEvent(bytes32 topic,bytes data)');\n\n function hash(Intent memory intent) internal pure returns (bytes32) {\n return\n keccak256(\n abi.encode(\n INTENT_TYPE_HASH,\n intent.op,\n intent.user,\n intent.settler,\n intent.nonce,\n intent.deadline,\n keccak256(intent.data),\n hash(intent.maxFees),\n hash(intent.events),\n intent.configSig,\n intent.minValidations\n )\n );\n }\n\n function hash(Proposal memory proposal, Intent memory intent, address solver) internal pure returns (bytes32) {\n return\n keccak256(\n abi.encode(\n PROPOSAL_TYPE_HASH,\n hash(intent),\n solver,\n proposal.deadline,\n keccak256(proposal.data),\n hash(proposal.fees)\n )\n );\n }\n\n function hash(MaxFee[] memory fees) internal pure returns (bytes32) {\n bytes32[] memory hashes = new bytes32[](fees.length);\n for (uint256 i = 0; i < fees.length; i++) {\n hashes[i] = keccak256(abi.encode(MAX_FEE_TYPE_HASH, fees[i].token, fees[i].amount));\n }\n return keccak256(abi.encodePacked(hashes));\n }\n\n function hash(IntentEvent[] memory events) internal pure returns (bytes32) {\n bytes32[] memory hashes = new bytes32[](events.length);\n for (uint256 i = 0; i < events.length; i++) {\n hashes[i] = keccak256(abi.encode(INTENT_EVENT_TYPE_HASH, events[i].topic, keccak256(events[i].data)));\n }\n return keccak256(abi.encodePacked(hashes));\n }\n\n function hash(uint256[] memory fees) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(fees));\n }\n\n function hash(Validation memory validation) internal pure returns (bytes32) {\n return keccak256(abi.encode(VALIDATION_TYPE_HASH, validation.intent));\n }\n}\n" + }, + "project/contracts/interfaces/IController.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @title Controller interface\n */\ninterface IController {\n /**\n * @dev The input arrays are not of equal length\n */\n error ControllerInputInvalidLength();\n\n /**\n * @dev Emitted every time a solver permission is set\n */\n event SolverAllowedSet(address indexed solver, bool allowed);\n\n /**\n * @dev Emitted every time an executor permission is set\n */\n event ExecutorAllowedSet(address indexed executor, bool allowed);\n\n /**\n * @dev Emitted every time a proposal signer permission is set\n */\n event ProposalSignerAllowedSet(address indexed proposalSigner, bool allowed);\n\n /**\n * @dev Emitted every time a validator permission is set\n */\n event ValidatorAllowedSet(address indexed validator, bool allowed);\n\n /**\n * @dev Emitted when the minimum validations changes\n */\n event MinValidationSet(uint8 indexed newMinValidation);\n\n /**\n * @dev Tells whether a solver is allowed\n * @param solver Address of the solver being queried\n */\n function isSolverAllowed(address solver) external view returns (bool);\n\n /**\n * @dev Tells whether an executor is allowed\n * @param executor Address of the executor being queried\n */\n function isExecutorAllowed(address executor) external view returns (bool);\n\n /**\n * @dev Tells whether a proposal signer is allowed\n * @param signer Address of the proposal signer being queried\n */\n function isProposalSignerAllowed(address signer) external view returns (bool);\n\n /**\n * @dev Tells whether a validator is allowed\n * @param validator Address of the validator being queried\n */\n function isValidatorAllowed(address validator) external view returns (bool);\n\n /**\n * @dev Tells the minimum number of validations allowed\n */\n function minValidations() external view returns (uint8);\n\n /**\n * @dev Sets permissions for multiple solvers\n * @param solvers List of solver addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedSolvers(address[] memory solvers, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple executors\n * @param executors List of executor addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedExecutors(address[] memory executors, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple proposal signers\n * @param signers List of proposal signer addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedProposalSigners(address[] memory signers, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple validators\n * @param validators List of validator addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedValidators(address[] memory validators, bool[] memory alloweds) external;\n\n /**\n * @dev Sets the minimum number of validations allowed\n * @param newMinValidations minimum number of validations allowed\n */\n function setMinValidations(uint8 newMinValidations) external;\n}\n" + }, + "project/contracts/interfaces/ICreateX.sol": { + "content": "// SPDX-License-Identifier: AGPL-3.0-only\n\npragma solidity ^0.8.4;\n\n/**\n * @title CreateX Factory Interface Definition\n * @author pcaversaccio (https://web.archive.org/web/20230921103111/https://pcaversaccio.com/)\n * @custom:coauthor Matt Solomon (https://web.archive.org/web/20230921103335/https://mattsolomon.dev/)\n */\ninterface ICreateX {\n event ContractCreation(address indexed newContract);\n\n function deployCreate3(bytes32 salt, bytes memory initCode) external payable returns (address newContract);\n}\n" + }, + "project/contracts/interfaces/IExecutor.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\n\n/**\n * @title Executor interface\n */\ninterface IExecutor {\n /**\n * @dev Executes an intent proposal\n * @param intent Intent to be executed\n * @param proposal Proposal to be executed to fulfill the intent\n */\n function execute(Intent memory intent, Proposal memory proposal) external;\n}\n" + }, + "project/contracts/interfaces/IIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\nimport '../safeguards/Safeguards.sol';\n\n/**\n * @title IntentsValidator\n * @dev Performs intents validations based on safeguards\n */\ninterface IIntentsValidator {\n /**\n * @dev Validates an intent for a safeguard\n * @param intent Intent to be validated\n * @param config Safeguard config to validate the intent with\n */\n function validate(Intent memory intent, bytes memory config) external pure;\n}\n" + }, + "project/contracts/interfaces/ISafe.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nenum SafeOperation {\n Call,\n DelegateCall\n}\n\ninterface ISafe {\n function getThreshold() external view returns (uint256);\n\n function execTransactionFromModuleReturnData(address to, uint256 value, bytes memory data, SafeOperation operation)\n external\n returns (bool success, bytes memory returnData);\n}\n" + }, + "project/contracts/interfaces/ISettler.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\nimport '../safeguards/Safeguards.sol';\n\n/**\n * @title Settler interface\n */\ninterface ISettler {\n /**\n * @dev The requested intent type is unknown\n */\n error SettlerUnknownIntentType(uint8 op);\n\n /**\n * @dev The simulation has been successful\n */\n error SettlerSimulationSuccess(uint256 gasUsed);\n\n /**\n * @dev The solver is not allowed\n */\n error SettlerSolverNotAllowed(address solver);\n\n /**\n * @dev The executor is not allowed\n */\n error SettlerExecutorNotAllowed(address executor);\n\n /**\n * @dev The proposal signer is not allowed\n */\n error SettlerProposalSignerNotAllowed(address signer);\n\n /**\n * @dev The validator is not allowed\n */\n error SettlerValidatorNotAllowed(address validator);\n\n /**\n * @dev The validator is duplicated\n */\n error SettlerValidatorDuplicatedOrUnsorted(address previous, address current);\n\n /**\n * @dev The settler is not the current contract\n */\n error SettlerInvalidSettler(address settler);\n\n /**\n * @dev The nonce is zero\n */\n error SettlerNonceZero();\n\n /**\n * @dev The nonce has already been used for the user\n */\n error SettlerNonceAlreadyUsed(address user, bytes32 nonce);\n\n /**\n * @dev The intent deadline is in the past\n */\n error SettlerIntentPastDeadline(uint256 deadline, uint256 timestamp);\n\n /**\n * @dev The current chain is not valid\n */\n error SettlerInvalidChain(uint256 chainId);\n\n /**\n * @dev The recipient is the settler contract\n */\n error SettlerInvalidRecipient(address to);\n\n /**\n * @dev The user is not a smart account\n */\n error SettlerUserNotSmartAccount(address user);\n\n /**\n * @dev The amount out is lower than the proposed amount\n */\n error SettlerAmountOutLtProposed(uint256 index, uint256 amountOut, uint256 proposed);\n\n /**\n * @dev The proposed amount is lower than the minimum amount\n */\n error SettlerProposedAmountLtMinAmount(uint256 index, uint256 proposed, uint256 minAmount);\n\n /**\n * @dev The proposed amounts array and the tokens out array are not of equal length\n */\n error SettlerInvalidProposedAmounts();\n\n /**\n * @dev The balance after the proposal execution is lower than the balance before\n */\n error SettlerPostBalanceOutLtPre(uint256 index, uint256 post, uint256 pre);\n\n /**\n * @dev The solver fees length does not match the requested by the user\n */\n error SettlerSolverFeeInvalidLength();\n\n /**\n * @dev The solver fee is too high\n */\n error SettlerSolverFeeTooHigh(uint256 fee, uint256 max);\n\n /**\n * @dev The intent validations are not enough\n */\n error SettlerIntentValidationsNotEnough(uint256 min, uint256 current);\n\n /**\n * @dev The proposal deadline is in the past\n */\n error SettlerProposalPastDeadline(uint256 deadline, uint256 timestamp);\n\n /**\n * @dev The proposal data is not empty\n */\n error SettlerProposalDataNotEmpty();\n\n /**\n * @dev The rescue funds recipient is zero\n */\n error SettlerRescueFundsRecipientZero();\n\n /**\n * @dev The list of safeguards exceed the maximum allowed\n */\n error SettlerTooManySafeguards(uint256 lengthRequested);\n\n /**\n * @dev The new smart accounts handler is zero\n */\n error SmartAccountsHandlerZero();\n\n /**\n * @dev Custom events emitted for each intent\n */\n event IntentExecuted(\n address indexed user,\n bytes32 indexed topic,\n uint8 indexed op,\n Intent intent,\n Proposal proposal,\n bytes output,\n bytes data\n );\n\n /**\n * @dev Emitted every time an intent is fulfilled\n */\n event ProposalExecuted(bytes32 indexed proposal, uint256 index);\n\n /**\n * @dev Emitted every time tokens are withdrawn from the contract balance\n */\n event FundsRescued(address indexed token, address indexed recipient, uint256 amount);\n\n /**\n * @dev Emitted every time the smart accounts handler is set\n */\n event SmartAccountsHandlerSet(address indexed smartAccountsHandler);\n\n /**\n * @dev Emitted every time the intents validator is set\n */\n event IntentsValidatorSet(address indexed intentsValidator);\n\n /**\n * @dev Emitted every time a safeguard is set\n */\n event SafeguardSet(address indexed user);\n\n /**\n * @dev Tells the reference to the Mimic controller\n */\n function controller() external view returns (address);\n\n /**\n * @dev Tells the reference to the smart accounts handler\n */\n function smartAccountsHandler() external view returns (address);\n\n /**\n * @dev Tells the reference to the intents validator\n */\n function intentsValidator() external view returns (address);\n\n /**\n * @dev Tells the block at which a user nonce was used. Returns 0 if unused.\n * @param user Address of the user being queried\n * @param nonce Nonce being queried\n */\n function getNonceBlock(address user, bytes32 nonce) external view returns (uint256);\n\n /**\n * @dev Tells the safeguard set for a user\n * @param user Address of the user being queried\n */\n function getUserSafeguard(address user) external view returns (bytes memory);\n\n /**\n * @dev Tells the hash of an intent\n * @param intent Intent to get the hash of\n */\n function getIntentHash(Intent memory intent) external pure returns (bytes32);\n\n /**\n * @dev Tells the hash of a proposal\n * @param proposal Proposal to be hashed\n * @param intent Intent being fulfilled by the requested proposal\n * @param solver Address of the solver that made the proposal\n */\n function getProposalHash(Proposal memory proposal, Intent memory intent, address solver)\n external\n pure\n returns (bytes32);\n\n /**\n * @dev Withdraws ERC20 or native tokens from the contract\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function rescueFunds(address token, address recipient, uint256 amount) external;\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function setSmartAccountsHandler(address newSmartAccountsHandler) external;\n\n /**\n * @dev Sets a new intents validator address\n * @param newIntentsValidator New intents validator to be set\n */\n function setIntentsValidator(address newIntentsValidator) external;\n\n /**\n * @dev Sets a safeguard for a user\n * @param safeguard Safeguard to be set\n */\n function setSafeguard(bytes memory safeguard) external;\n\n /**\n * @dev Executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function execute(Execution[] memory executions) external;\n\n /**\n * @dev Simulates an execution. It will always revert. Successful executions are returned as\n * `SettlerSimulationSuccess` errors. Any other error should be treated as failure.\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function simulate(Execution[] memory executions) external;\n}\n" + }, + "project/contracts/interfaces/ISmartAccount.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/introspection/IERC165.sol';\n\n/**\n * @title SmartAccount interface\n */\ninterface ISmartAccount is IERC165 {\n /**\n * @dev Emitted every time tokens are transferred\n */\n event Transferred(address indexed token, address indexed recipient, uint256 amount);\n\n /**\n * @dev Emitted every time `call` is called\n */\n event Called(address indexed target, bytes data, uint256 value, bytes result);\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the owner or the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) external;\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the owner or the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n */\n function call(address target, bytes memory data, uint256 value) external returns (bytes memory result);\n}\n" + }, + "project/contracts/interfaces/ISmartAccountContract.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/interfaces/IERC1271.sol';\n\nimport './ISmartAccount.sol';\n\n/**\n * @title SmartAccountContract interface\n */\ninterface ISmartAccountContract is ISmartAccount, IERC1271 {\n // solhint-disable-previous-line no-empty-blocks\n}\n" + }, + "project/contracts/interfaces/ISmartAccountsHandler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\ninterface ISmartAccountsHandler {\n /**\n * @dev The smart account given is not supported\n */\n error SmartAccountsHandlerUnsupportedAccount(address account);\n\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address account) external view returns (bool);\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address account, address token, address to, uint256 amount) external;\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address account, address target, bytes memory data, uint256 value) external returns (bytes memory);\n}\n" + }, + "project/contracts/safeguards/BaseIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @title BaseIntentsValidator\n */\ncontract BaseIntentsValidator {\n /**\n * @dev No intents allowed\n */\n error IntentsValidatorNoneAllowed();\n\n /**\n * @dev Intent type unknown\n */\n error IntentsValidatorUnknownIntentType(uint8 opType);\n\n /**\n * @dev Invalid safeguard mode\n */\n error IntentsValidatorInvalidSafeguardMode(uint8 mode);\n\n /**\n * @dev Tells whether a chain is allowed\n */\n function _isChainAllowed(uint256 chainId, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, uint256[] memory values) = abi.decode(config, (bool, uint256[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (chainId == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (chainId == values[i]) return true;\n }\n return false;\n }\n }\n\n /**\n * @dev Tells whether an account is allowed\n */\n function _isAccountAllowed(address account, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, address[] memory values) = abi.decode(config, (bool, address[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (account == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (account == values[i]) return true;\n }\n return false;\n }\n }\n\n /**\n * @dev Tells whether a selector is allowed\n */\n function _isSelectorAllowed(bytes4 selector, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, bytes4[] memory values) = abi.decode(config, (bool, bytes4[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (selector == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (selector == values[i]) return true;\n }\n return false;\n }\n }\n}\n" + }, + "project/contracts/safeguards/CallIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './Safeguards.sol';\nimport './BaseIntentsValidator.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Call safeguard modes to validate call intents\n * @param None To ensure no calls are allowed\n * @param Chain To validate that the chain where calls execute is allowed\n * @param Target To validate that the call targets (contract addresses) are allowed\n * @param Selector To validate that the function selectors being called are allowed\n */\nenum CallSafeguardMode {\n None,\n Chain,\n Target,\n Selector\n}\n\n/**\n * @title CallIntentsValidator\n * @dev Performs call intents validations based on safeguards\n */\ncontract CallIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a call intent is valid for a safeguard\n * @param intent Call intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isCallIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n CallIntent memory callIntent = abi.decode(intent.data, (CallIntent));\n if (safeguard.mode == uint8(CallSafeguardMode.Chain))\n return _isChainAllowed(callIntent.chainId, safeguard.config);\n if (safeguard.mode == uint8(CallSafeguardMode.Target))\n return _areCallTargetsValid(callIntent.calls, safeguard.config);\n if (safeguard.mode == uint8(CallSafeguardMode.Selector))\n return _areCallSelectorsValid(callIntent.calls, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the call targets are allowed\n */\n function _areCallTargetsValid(CallData[] memory calls, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < calls.length; i++) {\n if (!_isAccountAllowed(calls[i].target, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the call selectors are allowed\n */\n function _areCallSelectorsValid(CallData[] memory calls, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < calls.length; i++) {\n if (!_isSelectorAllowed(bytes4(calls[i].data), config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/safeguards/IntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './CallIntentsValidator.sol';\nimport './TransferIntentsValidator.sol';\nimport './Safeguards.sol';\nimport './SwapIntentsValidator.sol';\nimport '../Intents.sol';\nimport '../interfaces/IIntentsValidator.sol';\n\n/**\n * @title IntentsValidator\n * @dev Performs intents validations based on safeguards\n */\ncontract IntentsValidator is IIntentsValidator, SwapIntentsValidator, TransferIntentsValidator, CallIntentsValidator {\n /**\n * @dev Safeguard validation failed\n */\n error IntentsValidatorSafeguardFailed();\n\n /**\n * @dev Invalid safeguard config mode\n */\n error IntentsValidatorInvalidSafeguardConfigMode(uint8 mode);\n\n /**\n * @dev Invalid safeguard group logic mode\n */\n error IntentsValidatorInvalidSafeguardGroupLogicMode(uint8 mode);\n\n /**\n * @dev Tells whether an intent is valid for a safeguard\n * @param intent Intent to be validated\n * @param config Safeguard config to validate the intent with\n */\n function validate(Intent memory intent, bytes memory config) external pure override {\n (uint8 mode, bytes memory safeguard) = abi.decode(config, (uint8, bytes));\n if (mode == uint8(SafeguardConfigMode.List)) _validate(intent, abi.decode(safeguard, (Safeguard[])));\n else if (mode == uint8(SafeguardConfigMode.Tree)) _validate(intent, _decodeSafeguardTree(safeguard));\n else revert IntentsValidatorInvalidSafeguardConfigMode(mode);\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguards list\n * @param intent Intent to be validated\n * @param safeguards Safeguard list to validate the intent with\n */\n function _validate(Intent memory intent, Safeguard[] memory safeguards) internal pure {\n if (safeguards.length == 0) revert IntentsValidatorSafeguardFailed();\n for (uint256 i = 0; i < safeguards.length; i++) {\n if (!_isSafeguardValid(intent, safeguards[i])) revert IntentsValidatorSafeguardFailed();\n }\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard tree\n * @param intent Intent to be validated\n * @param tree Safeguard tree to validate the intent with\n */\n function _validate(Intent memory intent, SafeguardTree memory tree) internal pure {\n if (tree.nodes.length == 0) revert IntentsValidatorSafeguardFailed();\n if (!_isSafeguardGroupValid(intent, tree, 0)) revert IntentsValidatorSafeguardFailed();\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard tree at a certain level\n * @param intent Intent to be validated\n * @param tree Safeguard tree to validate the intent with\n * @param index Index of the group node to evaluate\n */\n function _isSafeguardGroupValid(Intent memory intent, SafeguardTree memory tree, uint16 index)\n internal\n pure\n returns (bool)\n {\n SafeguardGroup memory group = tree.nodes[index];\n\n if (group.logic == uint8(SafeguardGroupLogic.NOT)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i])) return false;\n }\n return true;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.AND)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (!_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (!_isSafeguardGroupValid(intent, tree, group.children[i])) return false;\n }\n return true;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.OR)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return true;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i])) return true;\n }\n return false;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.XOR)) {\n uint256 hits = 0;\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]]))\n if (++hits > 1) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i]))\n if (++hits > 1) return false;\n }\n return hits == 1;\n }\n\n revert IntentsValidatorInvalidSafeguardGroupLogicMode(group.logic);\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard\n * @param intent Intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isSafeguardValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n if (safeguard.mode == uint8(0)) revert IntentsValidatorNoneAllowed();\n if (intent.op == uint8(OpType.Swap)) return _isSwapIntentValid(intent, safeguard);\n if (intent.op == uint8(OpType.Transfer)) return _isTransferIntentValid(intent, safeguard);\n if (intent.op == uint8(OpType.Call)) return _isCallIntentValid(intent, safeguard);\n revert IntentsValidatorUnknownIntentType(uint8(intent.op));\n }\n\n /**\n * @dev Safely decodes a safeguard tree avoiding compiler issues with dynamic arrays\n * @param data Safeguard tree data to be decoded\n */\n function _decodeSafeguardTree(bytes memory data) private pure returns (SafeguardTree memory) {\n (SafeguardGroup[] memory nodes, Safeguard[] memory leaves) = abi.decode(data, (SafeguardGroup[], Safeguard[]));\n return SafeguardTree(nodes, leaves);\n }\n}\n" + }, + "project/contracts/safeguards/Safeguards.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Safeguard config modes\n * - List: Safeguard lists\n * - Tree: Safeguard groups\n */\nenum SafeguardConfigMode {\n List,\n Tree\n}\n\n/**\n * @dev Logical operators for safeguard groups\n * - AND: every child must pass\n * - OR: at least one child must pass\n * - XOR: exactly one child must pass\n * - NOT: every child must fail\n */\nenum SafeguardGroupLogic {\n AND,\n OR,\n XOR,\n NOT\n}\n\n/**\n * @dev Flat node in the safeguard tree\n * @param logic Group operator (AND/OR/XOR/NOT)\n * @param leaves Indices into `SafeguardTree.leaves`\n * @param children Indices into `SafeguardTree.nodes`\n */\nstruct SafeguardGroup {\n uint8 logic;\n uint16[] leaves;\n uint16[] children;\n}\n\n/**\n * @dev Safeguard tree representation\n * @param nodes List of all the nodes in the tree\n * @param leaves List of all the leaves in the tree\n */\nstruct SafeguardTree {\n SafeguardGroup[] nodes;\n Safeguard[] leaves;\n}\n\n/**\n * @dev Safeguard representation\n * @param mode Safeguard mode\n * @param config Safeguard configuration settings or parameters\n */\nstruct Safeguard {\n uint8 mode;\n bytes config;\n}\n" + }, + "project/contracts/safeguards/SwapIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './BaseIntentsValidator.sol';\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Swap safeguard modes to validate swap intents\n * @param None To ensure no swaps are allowed\n * @param SourceChain To validate that the source chain is allowed\n * @param DestinationChain To validate that the destination chain is allowed\n * @param TokenIn To validate that the tokens to be sent are allowed\n * @param TokenOut To validate that the tokens to be received are allowed\n * @param Recipient To validate that the recipients that will receive the tokens are allowed\n */\nenum SwapSafeguardMode {\n None,\n SourceChain,\n DestinationChain,\n TokenIn,\n TokenOut,\n Recipient\n}\n\n/**\n * @title SwapIntentsValidator\n * @dev Performs swap intents validations based on safeguards\n */\ncontract SwapIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a swap intent is valid for a safeguard\n * @param intent Swap intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isSwapIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n if (safeguard.mode == uint8(SwapSafeguardMode.SourceChain))\n return _isChainAllowed(swapIntent.sourceChain, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.DestinationChain))\n return _isChainAllowed(swapIntent.destinationChain, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.TokenIn))\n return _areSwapTokensInValid(swapIntent.tokensIn, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.TokenOut))\n return _areSwapTokensOutValid(swapIntent.tokensOut, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.Recipient))\n return _areSwapRecipientsValid(swapIntent.tokensOut, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the tokens to be sent are allowed\n */\n function _areSwapTokensInValid(TokenIn[] memory tokensIn, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensIn.length; i++) {\n if (!_isAccountAllowed(tokensIn[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the tokens to be received are allowed\n */\n function _areSwapTokensOutValid(TokenOut[] memory tokensOut, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensOut.length; i++) {\n if (!_isAccountAllowed(tokensOut[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the recipients to be received are allowed\n */\n function _areSwapRecipientsValid(TokenOut[] memory tokensOut, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensOut.length; i++) {\n if (!_isAccountAllowed(tokensOut[i].recipient, config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/safeguards/TransferIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './BaseIntentsValidator.sol';\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Transfer safeguard modes to validate transfer intents\n * @param None To ensure no transfers are allowed\n * @param Chain To validate that the chain where transfers execute is allowed\n * @param Token To validate that the tokens being transferred are allowed\n * @param Recipient To validate that the recipients of the transfers are allowed\n */\nenum TransferSafeguardMode {\n None,\n Chain,\n Token,\n Recipient\n}\n\n/**\n * @title TransferIntentsValidator\n * @dev Performs transfer intents validations based on safeguards\n */\ncontract TransferIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a transfer intent is valid for a safeguard\n * @param intent Transfer intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isTransferIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n TransferIntent memory transferIntent = abi.decode(intent.data, (TransferIntent));\n if (safeguard.mode == uint8(TransferSafeguardMode.Chain))\n return _isChainAllowed(transferIntent.chainId, safeguard.config);\n if (safeguard.mode == uint8(TransferSafeguardMode.Token))\n return _areTransferTokensValid(transferIntent.transfers, safeguard.config);\n if (safeguard.mode == uint8(TransferSafeguardMode.Recipient))\n return _areTransferRecipientsValid(transferIntent.transfers, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the tokens being transferred are allowed\n */\n function _areTransferTokensValid(TransferData[] memory transfers, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < transfers.length; i++) {\n if (!_isAccountAllowed(transfers[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the recipients of the transfers are allowed\n */\n function _areTransferRecipientsValid(TransferData[] memory transfers, bytes memory config)\n private\n pure\n returns (bool)\n {\n for (uint256 i = 0; i < transfers.length; i++) {\n if (!_isAccountAllowed(transfers[i].recipient, config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/Settler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/cryptography/ECDSA.sol';\nimport '@openzeppelin/contracts/utils/cryptography/EIP712.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165Checker.sol';\n\nimport './Intents.sol';\nimport './interfaces/IController.sol';\nimport './interfaces/IIntentsValidator.sol';\nimport './interfaces/IExecutor.sol';\nimport './interfaces/ISettler.sol';\nimport './utils/Denominations.sol';\nimport './utils/ERC20Helpers.sol';\nimport './smart-accounts/SmartAccountsHandler.sol';\nimport './smart-accounts/SmartAccountsHandlerHelpers.sol';\n\n/**\n * @title Settler\n * @dev Contract that provides the appropriate context for solvers to execute proposals that fulfill user intents\n */\ncontract Settler is ISettler, Ownable, ReentrancyGuard, EIP712 {\n using SafeERC20 for IERC20;\n using IntentsHelpers for Intent;\n using IntentsHelpers for Proposal;\n using IntentsHelpers for Validation;\n using SmartAccountsHandlerHelpers for address;\n\n // Mimic controller reference\n // solhint-disable-next-line immutable-vars-naming\n address public immutable override controller;\n\n // Smart accounts handler reference\n address public override smartAccountsHandler;\n\n // Intents validator reference\n address public override intentsValidator;\n\n // List of block numbers at which a user nonce was used\n mapping (address => mapping (bytes32 => uint256)) public override getNonceBlock;\n\n // Safeguard config per user\n mapping (address => bytes) internal _userSafeguard;\n\n /**\n * @dev Modifier to tag settler functions in order to check if the sender is an allowed solver\n */\n modifier onlySolver() {\n address sender = _msgSender();\n if (!IController(controller).isSolverAllowed(sender)) revert SettlerSolverNotAllowed(sender);\n _;\n }\n\n /**\n * @dev Creates a new Settler contract\n * @param _controller Address of the Settler controller\n * @param _owner Address that will own the contract\n */\n constructor(address _controller, address _owner) Ownable(_owner) EIP712('Mimic Protocol Settler', '1') {\n controller = _controller;\n smartAccountsHandler = address(new SmartAccountsHandler());\n }\n\n /**\n * @dev Tells the hash of an intent\n * @param intent Intent to get the hash of\n */\n function getIntentHash(Intent memory intent) external pure override returns (bytes32) {\n return intent.hash();\n }\n\n /**\n * @dev Tells the hash of a proposal\n * @param proposal Proposal to be hashed\n * @param intent Intent being fulfilled by the requested proposal\n * @param solver Address of the solver that made the proposal\n */\n function getProposalHash(Proposal memory proposal, Intent memory intent, address solver)\n external\n pure\n override\n returns (bytes32)\n {\n return proposal.hash(intent, solver);\n }\n\n /**\n * @dev Tells the safeguard set for a user\n * @param user Address of the user being queried\n */\n function getUserSafeguard(address user) external view override returns (bytes memory) {\n return _userSafeguard[user];\n }\n\n /**\n * @dev It allows receiving native token transfers\n * Note: This method mainly allows supporting native tokens for swaps\n */\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n /**\n * @dev Withdraws ERC20 or native tokens from the contract\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function rescueFunds(address token, address recipient, uint256 amount) external override onlyOwner nonReentrant {\n if (recipient == address(0)) revert SettlerRescueFundsRecipientZero();\n ERC20Helpers.transfer(token, recipient, amount);\n emit FundsRescued(token, recipient, amount);\n }\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function setSmartAccountsHandler(address newSmartAccountsHandler) external override onlyOwner {\n _setSmartAccountsHandler(newSmartAccountsHandler);\n }\n\n /**\n * @dev Sets a new intents validator address\n * @param newIntentsValidator New intents validator to be set\n */\n function setIntentsValidator(address newIntentsValidator) external override onlyOwner {\n _setIntentsValidator(newIntentsValidator);\n }\n\n /**\n * @dev Sets a safeguard for a user\n * @param safeguard Safeguard to be set\n */\n function setSafeguard(bytes memory safeguard) external override {\n _setSafeguard(msg.sender, safeguard);\n }\n\n /**\n * @dev Executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function execute(Execution[] memory executions) external override onlySolver {\n _execute(executions, false);\n }\n\n /**\n * @dev Simulates an execution. It will always revert. Successful executions are returned as\n * `SettlerSimulationSuccess` errors. Any other error should be treated as failure.\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function simulate(Execution[] memory executions) external override onlySolver {\n uint256 initialGas = gasleft();\n _execute(executions, true);\n uint256 gasUsed = initialGas - gasleft();\n revert SettlerSimulationSuccess(gasUsed);\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n * @param simulated Whether the execution is a simulation\n */\n function _execute(Execution[] memory executions, bool simulated) internal nonReentrant {\n for (uint256 i = 0; i < executions.length; i++) {\n Intent memory intent = executions[i].intent;\n Proposal memory proposal = executions[i].proposal;\n bytes memory signature = executions[i].signature;\n\n _validateIntent(intent, proposal, signature, simulated);\n getNonceBlock[intent.user][intent.nonce] = block.number;\n\n if (intent.op == uint8(OpType.Swap)) _executeSwap(intent, proposal);\n else if (intent.op == uint8(OpType.Transfer)) _executeTransfer(intent, proposal);\n else if (intent.op == uint8(OpType.Call)) _executeCall(intent, proposal);\n else revert SettlerUnknownIntentType(uint8(intent.op));\n\n emit ProposalExecuted(proposal.hash(intent, _msgSender()), i);\n }\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a swap intent\n * @param intent Swap intent to be fulfilled\n * @param proposal Swap proposal to be executed\n */\n function _executeSwap(Intent memory intent, Proposal memory proposal) internal {\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n _validateSwapIntent(swapIntent, swapProposal);\n\n bool isSmartAccount = smartAccountsHandler.isSmartAccount(intent.user);\n if (swapIntent.sourceChain == block.chainid) {\n for (uint256 i = 0; i < swapIntent.tokensIn.length; i++) {\n TokenIn memory tokenIn = swapIntent.tokensIn[i];\n _transferFrom(tokenIn.token, intent.user, swapProposal.executor, tokenIn.amount, isSmartAccount);\n }\n }\n\n uint256[] memory preBalancesOut = _getTokensOutBalance(swapIntent);\n IExecutor(swapProposal.executor).execute(intent, proposal);\n\n if (swapIntent.destinationChain == block.chainid) {\n uint256[] memory outputs = new uint256[](swapIntent.tokensOut.length);\n for (uint256 i = 0; i < swapIntent.tokensOut.length; i++) {\n TokenOut memory tokenOut = swapIntent.tokensOut[i];\n uint256 postBalanceOut = ERC20Helpers.balanceOf(tokenOut.token, address(this));\n uint256 preBalanceOut = preBalancesOut[i];\n if (postBalanceOut < preBalanceOut) revert SettlerPostBalanceOutLtPre(i, postBalanceOut, preBalanceOut);\n\n outputs[i] = postBalanceOut - preBalanceOut;\n uint256 proposedAmount = swapProposal.amountsOut[i];\n if (outputs[i] < proposedAmount) revert SettlerAmountOutLtProposed(i, outputs[i], proposedAmount);\n\n ERC20Helpers.transfer(tokenOut.token, tokenOut.recipient, outputs[i]);\n }\n\n _emitIntentEvents(intent, proposal, abi.encode(outputs));\n _payFees(intent, proposal, isSmartAccount);\n }\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a transfer intent\n * @param intent Transfer intent to be fulfilled\n * @param proposal Transfer proposal to be executed\n */\n function _executeTransfer(Intent memory intent, Proposal memory proposal) internal {\n TransferIntent memory transferIntent = abi.decode(intent.data, (TransferIntent));\n _validateTransferIntent(transferIntent, proposal);\n\n bool isSmartAccount = smartAccountsHandler.isSmartAccount(intent.user);\n for (uint256 i = 0; i < transferIntent.transfers.length; i++) {\n TransferData memory transfer = transferIntent.transfers[i];\n _transferFrom(transfer.token, intent.user, transfer.recipient, transfer.amount, isSmartAccount);\n }\n\n _emitIntentEvents(intent, proposal, new bytes(0));\n _payFees(intent, proposal, isSmartAccount);\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a call intent\n * @param intent Call intent to be fulfilled\n * @param proposal Call proposal to be executed\n */\n function _executeCall(Intent memory intent, Proposal memory proposal) internal {\n CallIntent memory callIntent = abi.decode(intent.data, (CallIntent));\n _validateCallIntent(callIntent, proposal, intent.user);\n\n bytes[] memory outputs = new bytes[](callIntent.calls.length);\n for (uint256 i = 0; i < callIntent.calls.length; i++) {\n CallData memory call = callIntent.calls[i];\n // solhint-disable-next-line avoid-low-level-calls\n outputs[i] = smartAccountsHandler.call(intent.user, call.target, call.data, call.value);\n }\n\n _emitIntentEvents(intent, proposal, abi.encode(outputs));\n _payFees(intent, proposal, true);\n }\n\n /**\n * @dev Validates an intent and its corresponding proposal\n * @param intent Intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param signature Proposal signature\n * @param simulated Whether the execution is a simulation\n */\n function _validateIntent(Intent memory intent, Proposal memory proposal, bytes memory signature, bool simulated)\n internal\n view\n {\n if (intent.settler != address(this)) revert SettlerInvalidSettler(intent.settler);\n if (intent.nonce == bytes32(0)) revert SettlerNonceZero();\n if (getNonceBlock[intent.user][intent.nonce] != 0) revert SettlerNonceAlreadyUsed(intent.user, intent.nonce);\n\n if (intentsValidator != address(0)) {\n bytes memory safeguard = _userSafeguard[intent.user];\n if (safeguard.length > 0) IIntentsValidator(intentsValidator).validate(intent, safeguard);\n }\n\n bool shouldValidateDeadlines = _shouldValidateDeadlines(intent);\n if (shouldValidateDeadlines) {\n if (intent.deadline <= block.timestamp) revert SettlerIntentPastDeadline(intent.deadline, block.timestamp);\n bool isProposalPastDeadline = proposal.deadline <= block.timestamp;\n if (isProposalPastDeadline) revert SettlerProposalPastDeadline(proposal.deadline, block.timestamp);\n }\n\n if (intent.maxFees.length != proposal.fees.length) revert SettlerSolverFeeInvalidLength();\n for (uint256 i = 0; i < intent.maxFees.length; i++) {\n uint256 maxFee = intent.maxFees[i].amount;\n uint256 proposalFee = proposal.fees[i];\n if (proposalFee > maxFee) revert SettlerSolverFeeTooHigh(proposalFee, maxFee);\n }\n\n uint8 minValidations = IController(controller).minValidations();\n uint256 requiredValidations = intent.minValidations > minValidations ? intent.minValidations : minValidations;\n\n if (intent.validations.length < requiredValidations) {\n revert SettlerIntentValidationsNotEnough(requiredValidations, intent.validations.length);\n }\n\n address lastValidator = address(0);\n Validation memory validation = Validation(intent.hash());\n bytes32 typedDataHash = _hashTypedDataV4(validation.hash());\n for (uint256 i = 0; i < intent.validations.length; i++) {\n address validator = ECDSA.recover(typedDataHash, intent.validations[i]);\n if (validator <= lastValidator) {\n revert SettlerValidatorDuplicatedOrUnsorted(lastValidator, validator);\n }\n lastValidator = validator;\n bool isValidatorNotAllowed = !IController(controller).isValidatorAllowed(validator);\n if (isValidatorNotAllowed) revert SettlerValidatorNotAllowed(validator);\n }\n\n address signer = ECDSA.recover(_hashTypedDataV4(proposal.hash(intent, _msgSender())), signature);\n bool isProposalSignerNotAllowed = !IController(controller).isProposalSignerAllowed(signer) && !simulated;\n if (isProposalSignerNotAllowed) revert SettlerProposalSignerNotAllowed(signer);\n }\n\n /**\n * @dev Validates a swap intent and its corresponding proposal\n * @param intent Swap intent to be fulfilled\n * @param proposal Proposal to be executed\n */\n function _validateSwapIntent(SwapIntent memory intent, SwapProposal memory proposal) internal view {\n bool isChainInvalid = intent.sourceChain != block.chainid && intent.destinationChain != block.chainid;\n if (isChainInvalid) revert SettlerInvalidChain(block.chainid);\n\n if (proposal.amountsOut.length != intent.tokensOut.length) revert SettlerInvalidProposedAmounts();\n\n for (uint256 i = 0; i < intent.tokensOut.length; i++) {\n TokenOut memory tokenOut = intent.tokensOut[i];\n address recipient = tokenOut.recipient;\n if (recipient == address(this)) revert SettlerInvalidRecipient(recipient);\n\n uint256 minAmount = tokenOut.minAmount;\n uint256 proposedAmount = proposal.amountsOut[i];\n if (proposedAmount < minAmount) revert SettlerProposedAmountLtMinAmount(i, proposedAmount, minAmount);\n }\n\n if (intent.sourceChain != intent.destinationChain) {\n bool isExecutorInvalid = !IController(controller).isExecutorAllowed(proposal.executor);\n if (isExecutorInvalid) revert SettlerExecutorNotAllowed(proposal.executor);\n }\n }\n\n /**\n * @dev Validates a transfer intent and its corresponding proposal\n * @param intent Transfer intent to be fulfilled\n * @param proposal Proposal to be executed\n */\n function _validateTransferIntent(TransferIntent memory intent, Proposal memory proposal) internal view {\n if (intent.chainId != block.chainid) revert SettlerInvalidChain(block.chainid);\n if (proposal.data.length > 0) revert SettlerProposalDataNotEmpty();\n for (uint256 i = 0; i < intent.transfers.length; i++) {\n address recipient = intent.transfers[i].recipient;\n if (recipient == address(this)) revert SettlerInvalidRecipient(recipient);\n }\n }\n\n /**\n * @dev Validates a call intent and its corresponding proposal\n * @param intent Call intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param user The originator of the intent\n */\n function _validateCallIntent(CallIntent memory intent, Proposal memory proposal, address user) internal view {\n if (intent.chainId != block.chainid) revert SettlerInvalidChain(block.chainid);\n if (proposal.data.length > 0) revert SettlerProposalDataNotEmpty();\n if (!smartAccountsHandler.isSmartAccount(user)) revert SettlerUserNotSmartAccount(user);\n }\n\n /**\n * @dev Tells the contract balance for each token out of a swap intent\n * @param intent Swap intent containing the list of tokens out\n */\n function _getTokensOutBalance(SwapIntent memory intent) internal view returns (uint256[] memory balances) {\n balances = new uint256[](intent.tokensOut.length);\n if (intent.destinationChain == block.chainid) {\n for (uint256 i = 0; i < intent.tokensOut.length; i++) {\n balances[i] = ERC20Helpers.balanceOf(intent.tokensOut[i].token, address(this));\n }\n }\n }\n\n /**\n * @dev Tells if the intent and proposal deadlines should be validated\n * @param intent Intent to be fulfilled\n */\n function _shouldValidateDeadlines(Intent memory intent) internal view returns (bool) {\n if (intent.op != uint8(OpType.Swap)) return true;\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n if (swapIntent.sourceChain == swapIntent.destinationChain) return true;\n return swapIntent.sourceChain == block.chainid;\n }\n\n /**\n * @dev Emits intent custom events\n * @param intent Intent to emit the custom events for\n * @param proposal Proposal that fulfills the intent\n * @param output Encoded array of outputs\n */\n function _emitIntentEvents(Intent memory intent, Proposal memory proposal, bytes memory output) internal {\n for (uint256 i = 0; i < intent.events.length; i++) {\n IntentEvent memory intentEvent = intent.events[i];\n emit IntentExecuted(\n intent.user,\n intentEvent.topic,\n uint8(intent.op),\n intent,\n proposal,\n output,\n intentEvent.data\n );\n }\n }\n\n /**\n * @dev Pays fees\n * @param intent Intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param isSmartAccount Whether the intent user is a smart account\n */\n function _payFees(Intent memory intent, Proposal memory proposal, bool isSmartAccount) internal {\n address from = intent.user;\n address to = _msgSender();\n for (uint256 i = 0; i < intent.maxFees.length; i++) {\n address token = intent.maxFees[i].token;\n if (!Denominations.isUSD(token)) _transferFrom(token, from, to, proposal.fees[i], isSmartAccount);\n }\n }\n\n /**\n * @dev Transfers tokens from one account to another\n * @param token Address of the token to transfer\n * @param from Address of the account sending the tokens\n * @param to Address of the account receiving the tokens\n * @param amount Amount of tokens to transfer\n * @param isSmartAccount Whether the sender is a smart account\n */\n function _transferFrom(address token, address from, address to, uint256 amount, bool isSmartAccount) internal {\n if (isSmartAccount) {\n smartAccountsHandler.transfer(from, token, to, amount);\n } else {\n IERC20(token).safeTransferFrom(from, to, amount);\n }\n }\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function _setSmartAccountsHandler(address newSmartAccountsHandler) internal {\n if (newSmartAccountsHandler == address(0)) revert SmartAccountsHandlerZero();\n smartAccountsHandler = newSmartAccountsHandler;\n emit SmartAccountsHandlerSet(newSmartAccountsHandler);\n }\n\n /**\n * @dev Sets the intents validator\n * @param newIntentsValidator New intents validator to be set\n */\n function _setIntentsValidator(address newIntentsValidator) internal {\n intentsValidator = newIntentsValidator;\n emit IntentsValidatorSet(newIntentsValidator);\n }\n\n /**\n * @dev Sets a safeguard for a user\n * @param user Address of the user to set the safeguard for\n * @param safeguard Safeguard to be set\n */\n function _setSafeguard(address user, bytes memory safeguard) internal {\n delete _userSafeguard[user];\n _userSafeguard[user] = safeguard;\n emit SafeguardSet(user);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccount7702.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/Context.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccount.sol';\nimport '../utils/ERC20Helpers.sol';\nimport './SmartAccountBase.sol';\n\n/**\n * @title SmartAccount7702\n * @dev Provides the smart account logic to use with EIP7702\n */\ncontract SmartAccount7702 is SmartAccountBase {\n // Mimic settler reference\n // solhint-disable-next-line immutable-vars-naming\n address public immutable settler;\n\n /**\n * @dev The sender is not the settler\n */\n error SmartAccount7702SenderNotSettler();\n\n /**\n * @dev Reverts unless the sender is the settler\n */\n modifier onlySettler() {\n if (_msgSender() != settler) revert SmartAccount7702SenderNotSettler();\n _;\n }\n\n /**\n * @dev Creates a new SmartAccount7702 contract\n * @param _settler Address of the Mimic settler\n */\n constructor(address _settler) {\n settler = _settler;\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) public override onlySettler {\n super.transfer(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value) public override onlySettler returns (bytes memory) {\n // solhint-disable-next-line avoid-low-level-calls\n return super.call(target, data, value);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountBase.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/Context.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccount.sol';\nimport '../utils/ERC20Helpers.sol';\n\n/**\n * @title SmartAccountBase\n * @dev Provides the base logic for managing assets and executing arbitrary calls\n */\ncontract SmartAccountBase is ISmartAccount, Context, ERC165, ReentrancyGuard {\n /**\n * @dev Tells whether the contract supports the given interface ID. Overrides ERC165 to declare support for ISmartAccount interface.\n * @param interfaceId Interface ID is defined as the XOR of all function selectors in the interface\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {\n return interfaceId == type(ISmartAccount).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) public virtual override nonReentrant {\n ERC20Helpers.transfer(token, recipient, amount);\n emit Transferred(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value)\n public\n virtual\n override\n nonReentrant\n returns (bytes memory result)\n {\n result = Address.functionCallWithValue(target, data, value);\n emit Called(target, data, value, result);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountContract.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/cryptography/ECDSA.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccountContract.sol';\nimport './SmartAccountBase.sol';\n\n/**\n * @title SmartAccountContract\n * @dev Provides the smart account logic to use as a standalone contract\n */\ncontract SmartAccountContract is ISmartAccountContract, Ownable, SmartAccountBase {\n // EIP1271 magic return value\n bytes4 internal constant EIP1271_MAGIC_VALUE = 0x1626ba7e;\n\n // EIP1271 invalid signature return value\n bytes4 internal constant EIP1271_INVALID_SIGNATURE = 0xffffffff;\n\n // List of account permissions\n mapping (address => bool) public isSignerAllowed;\n\n // Mimic settler reference\n address public settler;\n\n /**\n * @dev The settler is zero\n */\n error SmartAccountSettlerZero();\n\n /**\n * @dev The input arrays are not of equal length\n */\n error SmartAccountInputInvalidLength();\n\n /**\n * @dev The sender is not the owner or the settler\n */\n error SmartAccountUnauthorizedSender(address sender);\n\n /**\n * @dev Emitted every time the settler is set\n */\n event SettlerSet(address indexed settler);\n\n /**\n * @dev Emitted every time a signer allowance is set\n */\n event SignerAllowedSet(address indexed account, bool allowed);\n\n /**\n * @dev Reverts unless the sender is the owner or the settler\n */\n modifier onlyOwnerOrSettler() {\n address sender = _msgSender();\n bool isAuthorized = sender == owner() || sender == settler;\n if (!isAuthorized) revert SmartAccountUnauthorizedSender(sender);\n _;\n }\n\n /**\n * @dev Creates a new SmartAccount contract\n * @param _settler Address of the Mimic settler\n * @param _owner Address that will own the contract\n */\n constructor(address _settler, address _owner) Ownable(_owner) {\n _setSettler(_settler);\n }\n\n /**\n * @dev Tells whether the signature provided belongs to an allowed account.\n * @param hash Message signed by the account\n * @param signature Signature provided to be verified\n */\n function isValidSignature(bytes32 hash, bytes memory signature) external view override returns (bytes4) {\n (address signer, , ) = ECDSA.tryRecover(hash, signature);\n if (signer != address(0) && (signer == owner() || isSignerAllowed[signer])) return EIP1271_MAGIC_VALUE;\n return EIP1271_INVALID_SIGNATURE;\n }\n\n /**\n * @dev It allows receiving native token transfers\n */\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n /**\n * @dev Sets the settler. Sender must be the owner.\n * @param newSettler Address of the new settler to be set\n */\n function setSettler(address newSettler) external onlyOwner {\n _setSettler(newSettler);\n }\n\n /**\n * @dev Sets a list of allowed signers. Sender must be the owner.\n * @param accounts List of account addresses\n * @param allowances List of allowed condition per account\n */\n function setAllowedSigners(address[] memory accounts, bool[] memory allowances) external onlyOwner {\n if (accounts.length != allowances.length) revert SmartAccountInputInvalidLength();\n for (uint256 i = 0; i < accounts.length; i++) {\n address account = accounts[i];\n bool allowed = allowances[i];\n isSignerAllowed[account] = allowed;\n emit SignerAllowedSet(account, allowed);\n }\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the owner or the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount)\n public\n override(ISmartAccount, SmartAccountBase)\n onlyOwnerOrSettler\n {\n super.transfer(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the owner or the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value)\n public\n override(ISmartAccount, SmartAccountBase)\n onlyOwnerOrSettler\n returns (bytes memory)\n {\n // solhint-disable-next-line avoid-low-level-calls\n return super.call(target, data, value);\n }\n\n /**\n * @dev Sets the settler\n * @param newSettler Address of the new settler to be set\n */\n function _setSettler(address newSettler) internal {\n if (newSettler == address(0)) revert SmartAccountSettlerZero();\n settler = newSettler;\n emit SettlerSet(newSettler);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountsHandler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport '../interfaces/ISafe.sol';\nimport '../interfaces/ISmartAccount.sol';\nimport '../interfaces/ISmartAccountsHandler.sol';\nimport '../utils/Denominations.sol';\n\ncontract SmartAccountsHandler is ISmartAccountsHandler {\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address account) external view override returns (bool) {\n if (account.code.length == 0) return false;\n if (_isMimicSmartAccount(account)) return true;\n if (_isSafe(account)) return true;\n return false;\n }\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address account, address token, address to, uint256 amount) external override {\n if (_isMimicSmartAccount(account)) return ISmartAccount(account).transfer(token, to, amount);\n if (_isSafe(account)) return _transferSafe(account, token, to, amount);\n revert SmartAccountsHandlerUnsupportedAccount(account);\n }\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address account, address target, bytes memory data, uint256 value)\n external\n override\n returns (bytes memory)\n {\n // solhint-disable-next-line avoid-low-level-calls\n if (_isMimicSmartAccount(account)) return ISmartAccount(account).call(target, data, value);\n if (_isSafe(account)) return _callSafe(account, target, data, value);\n revert SmartAccountsHandlerUnsupportedAccount(account);\n }\n\n /**\n * @dev Performs a transfer from a safe\n */\n function _transferSafe(address account, address token, address to, uint256 amount) internal {\n Denominations.isNativeToken(token)\n ? _callSafe(account, to, new bytes(0), amount)\n : _callSafe(account, token, abi.encodeWithSelector(IERC20.transfer.selector, to, amount), 0);\n }\n\n /**\n * @dev Performs a call from a safe\n */\n function _callSafe(address account, address target, bytes memory data, uint256 value)\n internal\n returns (bytes memory)\n {\n (bool success, bytes memory result) = ISafe(account).execTransactionFromModuleReturnData(\n target,\n value,\n data,\n SafeOperation.Call\n );\n return\n data.length == 0\n ? Address.verifyCallResult(success, result)\n : Address.verifyCallResultFromTarget(target, success, result);\n }\n\n /**\n * @dev Tells whether an account is a Mimic smart account\n * @param account Address of the account being queried\n */\n function _isMimicSmartAccount(address account) internal view returns (bool) {\n try ISmartAccount(account).supportsInterface(type(ISmartAccount).interfaceId) returns (bool ok) {\n return ok;\n } catch {\n return false;\n }\n }\n\n /**\n * @dev Tells whether an account is a Gnosis Safe\n * @param account Address of the account being queried\n */\n function _isSafe(address account) internal view returns (bool) {\n try ISafe(account).getThreshold() returns (uint256) {\n return true;\n } catch {\n return false;\n }\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountsHandlerHelpers.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport '../interfaces/ISmartAccountsHandler.sol';\n\nlibrary SmartAccountsHandlerHelpers {\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address handler, address account) internal view returns (bool) {\n return ISmartAccountsHandler(handler).isSmartAccount(account);\n }\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address handler, address account, address token, address to, uint256 amount) internal {\n Address.functionDelegateCall(\n handler,\n abi.encodeWithSelector(ISmartAccountsHandler.transfer.selector, account, token, to, amount)\n );\n }\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address handler, address account, address target, bytes memory data, uint256 value)\n internal\n returns (bytes memory)\n {\n return\n Address.functionDelegateCall(\n handler,\n abi.encodeWithSelector(ISmartAccountsHandler.call.selector, account, target, data, value)\n );\n }\n}\n" + }, + "project/contracts/test/CallMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\ncontract CallMock {\n event CallReceived(address indexed sender, uint256 value);\n error CallError();\n\n function call() external payable {\n emit CallReceived(msg.sender, msg.value);\n }\n\n function callError() external payable {\n revert CallError();\n }\n}\n" + }, + "project/contracts/test/executors/EmptyExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\n\ncontract EmptyExecutorMock is IExecutor {\n event Executed();\n\n function execute(Intent memory, Proposal memory) external override {\n emit Executed();\n }\n}\n" + }, + "project/contracts/test/executors/MintExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../TokenMock.sol';\nimport '../../interfaces/IExecutor.sol';\n\n/* solhint-disable custom-errors */\n\ncontract MintExecutorMock is IExecutor {\n event Minted();\n\n function execute(Intent memory intent, Proposal memory proposal) external override {\n require(intent.op == uint8(OpType.Swap), 'Invalid intent type');\n\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n (address[] memory tokens, uint256[] memory amounts) = abi.decode(swapProposal.data, (address[], uint256[]));\n\n require(tokens.length == amounts.length, 'Invalid inputs');\n\n for (uint256 i = 0; i < tokens.length; i++) {\n TokenMock(tokens[i]).mint(msg.sender, amounts[i]);\n emit Minted();\n }\n }\n}\n" + }, + "project/contracts/test/executors/ReentrantExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\nimport '../../interfaces/ISettler.sol';\n\ncontract ReentrantExecutorMock is IExecutor {\n // solhint-disable-next-line immutable-vars-naming\n address payable public immutable settler;\n\n constructor(address payable _settler) {\n settler = _settler;\n }\n\n function execute(Intent memory, Proposal memory) external override {\n ISettler(settler).execute(new Execution[](0));\n }\n}\n" + }, + "project/contracts/test/executors/TransferExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\nimport '../../utils/ERC20Helpers.sol';\n\n/* solhint-disable custom-errors */\n\ncontract TransferExecutorMock is IExecutor {\n event Transferred();\n\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n function execute(Intent memory intent, Proposal memory proposal) external override {\n require(intent.op == uint8(OpType.Swap), 'Invalid intent type');\n\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n (address[] memory tokens, uint256[] memory amounts) = abi.decode(swapProposal.data, (address[], uint256[]));\n\n require(tokens.length == amounts.length, 'Invalid inputs');\n\n for (uint256 i = 0; i < tokens.length; i++) {\n ERC20Helpers.transfer(tokens[i], msg.sender, amounts[i]);\n emit Transferred();\n }\n }\n}\n" + }, + "project/contracts/test/smart-accounts/SafeMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/ISafe.sol';\n\ncontract SafeMock is ISafe {\n event ModuleTxExecuted(\n address indexed target,\n bytes data,\n uint256 value,\n SafeOperation operation,\n bool success,\n bytes result\n );\n\n receive() external payable {}\n\n function getThreshold() external pure returns (uint256) {\n return 1;\n }\n\n function execTransactionFromModuleReturnData(address to, uint256 value, bytes memory data, SafeOperation operation)\n external\n returns (bool success, bytes memory result)\n {\n // solhint-disable-next-line avoid-low-level-calls\n (success, result) = to.call{ value: value }(data);\n emit ModuleTxExecuted(to, data, value, operation, success, result);\n }\n}\n" + }, + "project/contracts/test/TokenMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/ERC20.sol';\n\ncontract TokenMock is ERC20 {\n uint8 internal _decimals;\n\n constructor(string memory symbol, uint8 dec) ERC20(symbol, symbol) {\n _decimals = dec;\n }\n\n function mint(address account, uint256 amount) external {\n _mint(account, amount);\n }\n\n function decimals() public view override returns (uint8) {\n return _decimals;\n }\n}\n" + }, + "project/contracts/test/utils/DenominationsMock.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '../../utils/Denominations.sol';\n\n// solhint-disable func-name-mixedcase\n\ncontract DenominationsMock {\n function NATIVE_TOKEN() external pure returns (address) {\n return Denominations.NATIVE_TOKEN;\n }\n\n function USD() external pure returns (address) {\n return Denominations.USD;\n }\n}\n" + }, + "project/contracts/test/utils/ERC20HelpersMock.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '../../utils/ERC20Helpers.sol';\n\ncontract ERC20HelpersMock {\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n function approve(address token, address to, uint256 amount) external {\n ERC20Helpers.approve(token, to, amount);\n }\n\n function transfer(address token, address to, uint256 amount) external {\n ERC20Helpers.transfer(token, to, amount);\n }\n\n function balanceOf(address token, address account) external view returns (uint256) {\n return ERC20Helpers.balanceOf(token, account);\n }\n}\n" + }, + "project/contracts/utils/Denominations.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\n/**\n * @title Denominations\n * @dev Provides a list of ground denominations for those tokens that cannot be represented by an ERC20.\n * For now, the only needed is the native token that could be ETH, MATIC, or other depending on the layer being operated.\n */\nlibrary Denominations {\n address internal constant NATIVE_TOKEN = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;\n\n // Fiat currencies follow https://en.wikipedia.org/wiki/ISO_4217\n address internal constant USD = address(840);\n\n function isUSD(address token) internal pure returns (bool) {\n return token == USD;\n }\n\n function isNativeToken(address token) internal pure returns (bool) {\n return token == NATIVE_TOKEN;\n }\n}\n" + }, + "project/contracts/utils/ERC20Helpers.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport './Denominations.sol';\n\n/**\n * @title ERC20Helpers\n * @dev Provides a list of ERC20 helper methods\n */\nlibrary ERC20Helpers {\n function approve(address token, address to, uint256 amount) internal {\n SafeERC20.forceApprove(IERC20(token), to, amount);\n }\n\n function transfer(address token, address to, uint256 amount) internal {\n if (Denominations.isNativeToken(token)) Address.sendValue(payable(to), amount);\n else SafeERC20.safeTransfer(IERC20(token), to, amount);\n }\n\n function balanceOf(address token, address account) internal view returns (uint256) {\n if (Denominations.isNativeToken(token)) return address(account).balance;\n else return IERC20(token).balanceOf(address(account));\n }\n}\n" + }, + "project/contracts/utils/MimicHelper.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\n/**\n * @title Mimic Helper\n * @dev Collection of helper functions for the Mimic Protocol\n */\ncontract MimicHelper {\n /**\n * @dev Tells the native token balance of an address\n * @param target Address to get native token balance\n */\n function getNativeTokenBalance(address target) external view returns (uint256) {\n return target.balance;\n }\n}\n" + } + } + } +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-42161/deployed_addresses.json b/packages/evm/ignition/deployments/chain-42161/deployed_addresses.json index a1a41be..e981fe5 100644 --- a/packages/evm/ignition/deployments/chain-42161/deployed_addresses.json +++ b/packages/evm/ignition/deployments/chain-42161/deployed_addresses.json @@ -2,5 +2,7 @@ "Create3Controller#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", "Create3Controller#Controller": "0x6002825BabC837776A08799404fA55f15DCedA6b", "Create3Settler#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", - "Create3Settler#Settler": "0x609d831C0068844e11eF85a273c7F356212Fd6D1" + "Create3Settler#Settler": "0x609d831C0068844e11eF85a273c7F356212Fd6D1", + "Create3MimicHelper#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", + "Create3MimicHelper#MimicHelper": "0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0" } \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-42161/journal.jsonl b/packages/evm/ignition/deployments/chain-42161/journal.jsonl index 08daf16..5ad1d0b 100644 --- a/packages/evm/ignition/deployments/chain-42161/journal.jsonl +++ b/packages/evm/ignition/deployments/chain-42161/journal.jsonl @@ -17,4 +17,13 @@ {"futureId":"Create3Settler#ICreateX.deployCreate3","hash":"0xb965b1eee217371649208888ed2c6f500141dc622399c31ddd940dfba2d430e8","networkInteractionId":1,"receipt":{"blockHash":"0x3a3c7c1e5a7b9d6e4f4a645526c779ecdf30281cd5a88971299d53dae6895316","blockNumber":382948244,"logs":[{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":2,"topics":["0x2feea65dd4e9f9cbd86b74b7734210c59a1b2981b5b137bd0ee3e208200c9067","0x0000000000000000000000001a68cee754105b3f806c92f6f59e3175f0b0fc2c","0xd5d101dbdd8374fa4f730d105879acbe6c9855ed7be06a019574ba923a935d7d"]},{"address":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","data":"0x","logIndex":3,"topics":["0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000003a0ce8115b4913f42c4928d6bc3f554e9a81468b"]},{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":4,"topics":["0x4db17dd5e4732fb6da34a148104a592783ca119a1e7bb8829eba6cbadef0b511","0x000000000000000000000000609d831c0068844e11ef85a273c7f356212fd6d1"]}],"status":"SUCCESS"},"type":"TRANSACTION_CONFIRM"} {"futureId":"Create3Settler#ICreateX.deployCreate3","result":{"type":"SUCCESS"},"type":"CALL_EXECUTION_STATE_COMPLETE"} {"artifactId":"Create3Settler#ICreateX","dependencies":["Create3Settler#ICreateX.deployCreate3","Create3Settler#ICreateX"],"emitterAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","eventIndex":0,"eventName":"ContractCreation","futureId":"Create3Settler#ICreateX.ContractCreation.newContract.0","nameOrIndex":"newContract","result":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","strategy":"basic","strategyConfig":{},"txToReadFrom":"0xb965b1eee217371649208888ed2c6f500141dc622399c31ddd940dfba2d430e8","type":"READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE"} -{"artifactId":"Create3Settler#Settler","contractAddress":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","contractName":"Settler","dependencies":["Create3Settler#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3Settler#Settler","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} \ No newline at end of file +{"artifactId":"Create3Settler#Settler","contractAddress":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","contractName":"Settler","dependencies":["Create3Settler#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3Settler#Settler","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} +{"artifactId":"Create3MimicHelper#ICreateX","contractAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","contractName":"ICreateX","dependencies":[],"futureId":"Create3MimicHelper#ICreateX","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} +{"args":["0x3a0ce8115b4913f42c4928d6bc3f554e9a81468b000000000000000000000040","0x6080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033"],"artifactId":"Create3MimicHelper#ICreateX","contractAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","dependencies":["Create3MimicHelper#ICreateX"],"from":"0x3a0ce8115b4913f42c4928d6bc3f554e9a81468b","functionName":"deployCreate3","futureId":"Create3MimicHelper#ICreateX.deployCreate3","strategy":"basic","strategyConfig":{},"type":"CALL_EXECUTION_STATE_INITIALIZE","value":{"_kind":"bigint","value":"0"}} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteraction":{"data":"0x9c36a2863a0ce8115b4913f42c4928d6bc3f554e9a81468b000000000000000000000040000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e96080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c00330000000000000000000000000000000000000000000000","id":1,"to":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","type":"ONCHAIN_INTERACTION","value":{"_kind":"bigint","value":"0"}},"type":"NETWORK_INTERACTION_REQUEST"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteractionId":1,"nonce":47,"type":"TRANSACTION_PREPARE_SEND"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteractionId":1,"nonce":47,"transaction":{"fees":{"maxFeePerGas":{"_kind":"bigint","value":"40296000"},"maxPriorityFeePerGas":{"_kind":"bigint","value":"0"}},"hash":"0xc019948b1c556d9c1dc994d3fb6372ad3de14f247e730baf1a9fb026e6b58f4a"},"type":"TRANSACTION_SEND"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","hash":"0xc019948b1c556d9c1dc994d3fb6372ad3de14f247e730baf1a9fb026e6b58f4a","networkInteractionId":1,"receipt":{"blockHash":"0x2337201b157f716e7ce40f825a7b5587ee32416ec46f54b3bece1fbc4063904c","blockNumber":425507182,"logs":[{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":1,"topics":["0x2feea65dd4e9f9cbd86b74b7734210c59a1b2981b5b137bd0ee3e208200c9067","0x0000000000000000000000009074e2fea6f668ccf7fb884fac62943acc03ea43","0x721f4d59bffa983c2a99dc5a3b93053d035180c65840e4dc318b06bb0484a80f"]},{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":2,"topics":["0x4db17dd5e4732fb6da34a148104a592783ca119a1e7bb8829eba6cbadef0b511","0x0000000000000000000000004766ef65d66e8d2d92f3089ee42e5705e8817ff0"]}],"status":"SUCCESS"},"type":"TRANSACTION_CONFIRM"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","result":{"type":"SUCCESS"},"type":"CALL_EXECUTION_STATE_COMPLETE"} +{"artifactId":"Create3MimicHelper#ICreateX","dependencies":["Create3MimicHelper#ICreateX.deployCreate3","Create3MimicHelper#ICreateX"],"emitterAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","eventIndex":0,"eventName":"ContractCreation","futureId":"Create3MimicHelper#ICreateX.ContractCreation.newContract.0","nameOrIndex":"newContract","result":"0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0","strategy":"basic","strategyConfig":{},"txToReadFrom":"0xc019948b1c556d9c1dc994d3fb6372ad3de14f247e730baf1a9fb026e6b58f4a","type":"READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE"} +{"artifactId":"Create3MimicHelper#MimicHelper","contractAddress":"0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0","contractName":"MimicHelper","dependencies":["Create3MimicHelper#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3MimicHelper#MimicHelper","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-8453/artifacts/Create3MimicHelper#ICreateX.dbg.json b/packages/evm/ignition/deployments/chain-8453/artifacts/Create3MimicHelper#ICreateX.dbg.json new file mode 100644 index 0000000..817dddf --- /dev/null +++ b/packages/evm/ignition/deployments/chain-8453/artifacts/Create3MimicHelper#ICreateX.dbg.json @@ -0,0 +1,4 @@ +{ + "_format": "hh-sol-dbg-1", + "buildInfo": "../build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-8453/artifacts/Create3MimicHelper#ICreateX.json b/packages/evm/ignition/deployments/chain-8453/artifacts/Create3MimicHelper#ICreateX.json new file mode 100644 index 0000000..a4701c6 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-8453/artifacts/Create3MimicHelper#ICreateX.json @@ -0,0 +1,51 @@ +{ + "_format": "hh3-artifact-1", + "contractName": "ICreateX", + "sourceName": "contracts/interfaces/ICreateX.sol", + "abi": [ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "newContract", + "type": "address" + } + ], + "name": "ContractCreation", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "salt", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "initCode", + "type": "bytes" + } + ], + "name": "deployCreate3", + "outputs": [ + { + "internalType": "address", + "name": "newContract", + "type": "address" + } + ], + "stateMutability": "payable", + "type": "function" + } + ], + "bytecode": "0x", + "deployedBytecode": "0x", + "linkReferences": {}, + "deployedLinkReferences": {}, + "immutableReferences": {}, + "inputSourceName": "project/contracts/interfaces/ICreateX.sol", + "buildInfoId": "b650d0a8e9df290d290e91b2999a1f7443c2b528" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-8453/artifacts/Create3MimicHelper#MimicHelper.dbg.json b/packages/evm/ignition/deployments/chain-8453/artifacts/Create3MimicHelper#MimicHelper.dbg.json new file mode 100644 index 0000000..817dddf --- /dev/null +++ b/packages/evm/ignition/deployments/chain-8453/artifacts/Create3MimicHelper#MimicHelper.dbg.json @@ -0,0 +1,4 @@ +{ + "_format": "hh-sol-dbg-1", + "buildInfo": "../build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-8453/artifacts/Create3MimicHelper#MimicHelper.json b/packages/evm/ignition/deployments/chain-8453/artifacts/Create3MimicHelper#MimicHelper.json new file mode 100644 index 0000000..a01b577 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-8453/artifacts/Create3MimicHelper#MimicHelper.json @@ -0,0 +1,33 @@ +{ + "_format": "hh3-artifact-1", + "contractName": "MimicHelper", + "sourceName": "contracts/utils/MimicHelper.sol", + "abi": [ + { + "inputs": [ + { + "internalType": "address", + "name": "target", + "type": "address" + } + ], + "name": "getNativeTokenBalance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + } + ], + "bytecode": "0x6080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033", + "deployedBytecode": "0x6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033", + "linkReferences": {}, + "deployedLinkReferences": {}, + "immutableReferences": {}, + "inputSourceName": "project/contracts/utils/MimicHelper.sol", + "buildInfoId": "b650d0a8e9df290d290e91b2999a1f7443c2b528" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-8453/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json b/packages/evm/ignition/deployments/chain-8453/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json new file mode 100644 index 0000000..657a777 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-8453/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json @@ -0,0 +1,290 @@ +{ + "_format": "hh3-sol-build-info-1", + "id": "b650d0a8e9df290d290e91b2999a1f7443c2b528", + "solcVersion": "0.8.28", + "solcLongVersion": "0.8.28+commit.7893614a", + "userSourceNameMap": { + "contracts/Controller.sol": "project/contracts/Controller.sol", + "contracts/Intents.sol": "project/contracts/Intents.sol", + "contracts/Settler.sol": "project/contracts/Settler.sol", + "contracts/interfaces/IController.sol": "project/contracts/interfaces/IController.sol", + "contracts/interfaces/ICreateX.sol": "project/contracts/interfaces/ICreateX.sol", + "contracts/interfaces/IExecutor.sol": "project/contracts/interfaces/IExecutor.sol", + "contracts/interfaces/IIntentsValidator.sol": "project/contracts/interfaces/IIntentsValidator.sol", + "contracts/interfaces/ISafe.sol": "project/contracts/interfaces/ISafe.sol", + "contracts/interfaces/ISettler.sol": "project/contracts/interfaces/ISettler.sol", + "contracts/interfaces/ISmartAccount.sol": "project/contracts/interfaces/ISmartAccount.sol", + "contracts/interfaces/ISmartAccountContract.sol": "project/contracts/interfaces/ISmartAccountContract.sol", + "contracts/interfaces/ISmartAccountsHandler.sol": "project/contracts/interfaces/ISmartAccountsHandler.sol", + "contracts/safeguards/BaseIntentsValidator.sol": "project/contracts/safeguards/BaseIntentsValidator.sol", + "contracts/safeguards/CallIntentsValidator.sol": "project/contracts/safeguards/CallIntentsValidator.sol", + "contracts/safeguards/IntentsValidator.sol": "project/contracts/safeguards/IntentsValidator.sol", + "contracts/safeguards/Safeguards.sol": "project/contracts/safeguards/Safeguards.sol", + "contracts/safeguards/SwapIntentsValidator.sol": "project/contracts/safeguards/SwapIntentsValidator.sol", + "contracts/safeguards/TransferIntentsValidator.sol": "project/contracts/safeguards/TransferIntentsValidator.sol", + "contracts/smart-accounts/SmartAccount7702.sol": "project/contracts/smart-accounts/SmartAccount7702.sol", + "contracts/smart-accounts/SmartAccountBase.sol": "project/contracts/smart-accounts/SmartAccountBase.sol", + "contracts/smart-accounts/SmartAccountContract.sol": "project/contracts/smart-accounts/SmartAccountContract.sol", + "contracts/smart-accounts/SmartAccountsHandler.sol": "project/contracts/smart-accounts/SmartAccountsHandler.sol", + "contracts/smart-accounts/SmartAccountsHandlerHelpers.sol": "project/contracts/smart-accounts/SmartAccountsHandlerHelpers.sol", + "contracts/test/CallMock.sol": "project/contracts/test/CallMock.sol", + "contracts/test/TokenMock.sol": "project/contracts/test/TokenMock.sol", + "contracts/test/executors/EmptyExecutorMock.sol": "project/contracts/test/executors/EmptyExecutorMock.sol", + "contracts/test/executors/MintExecutorMock.sol": "project/contracts/test/executors/MintExecutorMock.sol", + "contracts/test/executors/ReentrantExecutorMock.sol": "project/contracts/test/executors/ReentrantExecutorMock.sol", + "contracts/test/executors/TransferExecutorMock.sol": "project/contracts/test/executors/TransferExecutorMock.sol", + "contracts/test/smart-accounts/SafeMock.sol": "project/contracts/test/smart-accounts/SafeMock.sol", + "contracts/test/utils/DenominationsMock.sol": "project/contracts/test/utils/DenominationsMock.sol", + "contracts/test/utils/ERC20HelpersMock.sol": "project/contracts/test/utils/ERC20HelpersMock.sol", + "contracts/utils/Denominations.sol": "project/contracts/utils/Denominations.sol", + "contracts/utils/ERC20Helpers.sol": "project/contracts/utils/ERC20Helpers.sol", + "contracts/utils/MimicHelper.sol": "project/contracts/utils/MimicHelper.sol" + }, + "input": { + "language": "Solidity", + "settings": { + "optimizer": { + "enabled": true, + "runs": 1000 + }, + "evmVersion": "cancun", + "outputSelection": { + "*": { + "": [ + "ast" + ], + "*": [ + "abi", + "evm.bytecode", + "evm.deployedBytecode", + "evm.methodIdentifiers", + "metadata" + ] + } + }, + "remappings": [ + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/" + ] + }, + "sources": { + "npm/@openzeppelin/contracts@5.3.0/access/Ownable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)\n\npragma solidity ^0.8.20;\n\nimport {Context} from \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * The initial owner is set to the address provided by the deployer. This can\n * later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n /**\n * @dev The caller account is not authorized to perform an operation.\n */\n error OwnableUnauthorizedAccount(address account);\n\n /**\n * @dev The owner is not a valid owner account. (eg. `address(0)`)\n */\n error OwnableInvalidOwner(address owner);\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the address provided by the deployer as the initial owner.\n */\n constructor(address initialOwner) {\n if (initialOwner == address(0)) {\n revert OwnableInvalidOwner(address(0));\n }\n _transferOwnership(initialOwner);\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n if (owner() != _msgSender()) {\n revert OwnableUnauthorizedAccount(_msgSender());\n }\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby disabling any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n if (newOwner == address(0)) {\n revert OwnableInvalidOwner(address(0));\n }\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/draft-IERC6093.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol)\npragma solidity ^0.8.20;\n\n/**\n * @dev Standard ERC-20 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.\n */\ninterface IERC20Errors {\n /**\n * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param balance Current balance for the interacting account.\n * @param needed Minimum amount required to perform a transfer.\n */\n error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC20InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC20InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.\n * @param spender Address that may be allowed to operate on tokens without being their owner.\n * @param allowance Amount of tokens a `spender` is allowed to operate with.\n * @param needed Minimum amount required to perform a transfer.\n */\n error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC20InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `spender` to be approved. Used in approvals.\n * @param spender Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC20InvalidSpender(address spender);\n}\n\n/**\n * @dev Standard ERC-721 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.\n */\ninterface IERC721Errors {\n /**\n * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.\n * Used in balance queries.\n * @param owner Address of the current owner of a token.\n */\n error ERC721InvalidOwner(address owner);\n\n /**\n * @dev Indicates a `tokenId` whose `owner` is the zero address.\n * @param tokenId Identifier number of a token.\n */\n error ERC721NonexistentToken(uint256 tokenId);\n\n /**\n * @dev Indicates an error related to the ownership over a particular token. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param tokenId Identifier number of a token.\n * @param owner Address of the current owner of a token.\n */\n error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC721InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC721InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n * @param tokenId Identifier number of a token.\n */\n error ERC721InsufficientApproval(address operator, uint256 tokenId);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC721InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC721InvalidOperator(address operator);\n}\n\n/**\n * @dev Standard ERC-1155 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.\n */\ninterface IERC1155Errors {\n /**\n * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param balance Current balance for the interacting account.\n * @param needed Minimum amount required to perform a transfer.\n * @param tokenId Identifier number of a token.\n */\n error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC1155InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC1155InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n * @param owner Address of the current owner of a token.\n */\n error ERC1155MissingApprovalForAll(address operator, address owner);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC1155InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC1155InvalidOperator(address operator);\n\n /**\n * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.\n * Used in batch transfers.\n * @param idsLength Length of the array of token identifiers\n * @param valuesLength Length of the array of token amounts\n */\n error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC1271.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (interfaces/IERC1271.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-1271 standard signature validation method for\n * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].\n */\ninterface IERC1271 {\n /**\n * @dev Should return whether the signature provided is valid for the provided data\n * @param hash Hash of the data to be signed\n * @param signature Signature byte array associated with `hash`\n */\n function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC1363.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"./IERC20.sol\";\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @title IERC1363\n * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].\n *\n * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract\n * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.\n */\ninterface IERC1363 is IERC20, IERC165 {\n /*\n * Note: the ERC-165 identifier for this interface is 0xb0202a11.\n * 0xb0202a11 ===\n * bytes4(keccak256('transferAndCall(address,uint256)')) ^\n * bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^\n * bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^\n * bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^\n * bytes4(keccak256('approveAndCall(address,uint256)')) ^\n * bytes4(keccak256('approveAndCall(address,uint256,bytes)'))\n */\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferAndCall(address to, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @param data Additional data with no specified format, sent in call to `to`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param from The address which you want to send tokens from.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferFromAndCall(address from, address to, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param from The address which you want to send tokens from.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @param data Additional data with no specified format, sent in call to `to`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.\n * @param spender The address which will spend the funds.\n * @param value The amount of tokens to be spent.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function approveAndCall(address spender, uint256 value) external returns (bool);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.\n * @param spender The address which will spend the funds.\n * @param value The amount of tokens to be spent.\n * @param data Additional data with no specified format, sent in call to `spender`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"../utils/introspection/IERC165.sol\";\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../token/ERC20/IERC20.sol\";\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC5267.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)\n\npragma solidity ^0.8.20;\n\ninterface IERC5267 {\n /**\n * @dev MAY be emitted to signal that the domain could have changed.\n */\n event EIP712DomainChanged();\n\n /**\n * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712\n * signature.\n */\n function eip712Domain()\n external\n view\n returns (\n bytes1 fields,\n string memory name,\n string memory version,\n uint256 chainId,\n address verifyingContract,\n bytes32 salt,\n uint256[] memory extensions\n );\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/ERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"./IERC20.sol\";\nimport {IERC20Metadata} from \"./extensions/IERC20Metadata.sol\";\nimport {Context} from \"../../utils/Context.sol\";\nimport {IERC20Errors} from \"../../interfaces/draft-IERC6093.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * The default value of {decimals} is 18. To change this, you should override\n * this function so it returns a different value.\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC-20\n * applications.\n */\nabstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {\n mapping(address account => uint256) private _balances;\n\n mapping(address account => mapping(address spender => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * Both values are immutable: they can only be set once during construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the default value returned by this function, unless\n * it's overridden.\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `value`.\n */\n function transfer(address to, uint256 value) public virtual returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, value);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 value) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, value);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Skips emitting an {Approval} event indicating an allowance update. This is not\n * required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `value`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `value`.\n */\n function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, value);\n _transfer(from, to, value);\n return true;\n }\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead.\n */\n function _transfer(address from, address to, uint256 value) internal {\n if (from == address(0)) {\n revert ERC20InvalidSender(address(0));\n }\n if (to == address(0)) {\n revert ERC20InvalidReceiver(address(0));\n }\n _update(from, to, value);\n }\n\n /**\n * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`\n * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding\n * this function.\n *\n * Emits a {Transfer} event.\n */\n function _update(address from, address to, uint256 value) internal virtual {\n if (from == address(0)) {\n // Overflow check required: The rest of the code assumes that totalSupply never overflows\n _totalSupply += value;\n } else {\n uint256 fromBalance = _balances[from];\n if (fromBalance < value) {\n revert ERC20InsufficientBalance(from, fromBalance, value);\n }\n unchecked {\n // Overflow not possible: value <= fromBalance <= totalSupply.\n _balances[from] = fromBalance - value;\n }\n }\n\n if (to == address(0)) {\n unchecked {\n // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.\n _totalSupply -= value;\n }\n } else {\n unchecked {\n // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.\n _balances[to] += value;\n }\n }\n\n emit Transfer(from, to, value);\n }\n\n /**\n * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).\n * Relies on the `_update` mechanism\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead.\n */\n function _mint(address account, uint256 value) internal {\n if (account == address(0)) {\n revert ERC20InvalidReceiver(address(0));\n }\n _update(address(0), account, value);\n }\n\n /**\n * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.\n * Relies on the `_update` mechanism.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead\n */\n function _burn(address account, uint256 value) internal {\n if (account == address(0)) {\n revert ERC20InvalidSender(address(0));\n }\n _update(account, address(0), value);\n }\n\n /**\n * @dev Sets `value` as the allowance of `spender` over the `owner`'s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n *\n * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.\n */\n function _approve(address owner, address spender, uint256 value) internal {\n _approve(owner, spender, value, true);\n }\n\n /**\n * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.\n *\n * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by\n * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any\n * `Approval` event during `transferFrom` operations.\n *\n * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to\n * true using the following override:\n *\n * ```solidity\n * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {\n * super._approve(owner, spender, value, true);\n * }\n * ```\n *\n * Requirements are the same as {_approve}.\n */\n function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {\n if (owner == address(0)) {\n revert ERC20InvalidApprover(address(0));\n }\n if (spender == address(0)) {\n revert ERC20InvalidSpender(address(0));\n }\n _allowances[owner][spender] = value;\n if (emitEvent) {\n emit Approval(owner, spender, value);\n }\n }\n\n /**\n * @dev Updates `owner`'s allowance for `spender` based on spent `value`.\n *\n * Does not update the allowance value in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Does not emit an {Approval} event.\n */\n function _spendAllowance(address owner, address spender, uint256 value) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance < type(uint256).max) {\n if (currentAllowance < value) {\n revert ERC20InsufficientAllowance(spender, currentAllowance, value);\n }\n unchecked {\n _approve(owner, spender, currentAllowance - value, false);\n }\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/extensions/IERC20Metadata.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC-20 standard.\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-20 standard as defined in the ERC.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the value of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the value of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 value) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the\n * allowance mechanism. `value` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(address from, address to, uint256 value) external returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/utils/SafeERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../IERC20.sol\";\nimport {IERC1363} from \"../../../interfaces/IERC1363.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC-20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n /**\n * @dev An operation with an ERC-20 token failed.\n */\n error SafeERC20FailedOperation(address token);\n\n /**\n * @dev Indicates a failed `decreaseAllowance` request.\n */\n error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);\n\n /**\n * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,\n * non-reverting calls are assumed to be successful.\n */\n function safeTransfer(IERC20 token, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));\n }\n\n /**\n * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the\n * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.\n */\n function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));\n }\n\n /**\n * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.\n */\n function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {\n return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));\n }\n\n /**\n * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.\n */\n function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {\n return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));\n }\n\n /**\n * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n * non-reverting calls are assumed to be successful.\n *\n * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the \"client\"\n * smart contract uses ERC-7674 to set temporary allowances, then the \"client\" smart contract should avoid using\n * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract\n * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.\n */\n function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n uint256 oldAllowance = token.allowance(address(this), spender);\n forceApprove(token, spender, oldAllowance + value);\n }\n\n /**\n * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no\n * value, non-reverting calls are assumed to be successful.\n *\n * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the \"client\"\n * smart contract uses ERC-7674 to set temporary allowances, then the \"client\" smart contract should avoid using\n * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract\n * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.\n */\n function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {\n unchecked {\n uint256 currentAllowance = token.allowance(address(this), spender);\n if (currentAllowance < requestedDecrease) {\n revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);\n }\n forceApprove(token, spender, currentAllowance - requestedDecrease);\n }\n }\n\n /**\n * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,\n * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval\n * to be set to zero before setting it to a non-zero value, such as USDT.\n *\n * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function\n * only sets the \"standard\" allowance. Any temporary allowance will remain active, in addition to the value being\n * set here.\n */\n function forceApprove(IERC20 token, address spender, uint256 value) internal {\n bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));\n\n if (!_callOptionalReturnBool(token, approvalCall)) {\n _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));\n _callOptionalReturn(token, approvalCall);\n }\n }\n\n /**\n * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no\n * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * Reverts if the returned value is other than `true`.\n */\n function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {\n if (to.code.length == 0) {\n safeTransfer(token, to, value);\n } else if (!token.transferAndCall(to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target\n * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * Reverts if the returned value is other than `true`.\n */\n function transferFromAndCallRelaxed(\n IERC1363 token,\n address from,\n address to,\n uint256 value,\n bytes memory data\n ) internal {\n if (to.code.length == 0) {\n safeTransferFrom(token, from, to, value);\n } else if (!token.transferFromAndCall(from, to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no\n * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.\n * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}\n * once without retrying, and relies on the returned value to be true.\n *\n * Reverts if the returned value is other than `true`.\n */\n function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {\n if (to.code.length == 0) {\n forceApprove(token, to, value);\n } else if (!token.approveAndCall(to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n *\n * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.\n */\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)\n // bubble errors\n if iszero(success) {\n let ptr := mload(0x40)\n returndatacopy(ptr, 0, returndatasize())\n revert(ptr, returndatasize())\n }\n returnSize := returndatasize()\n returnValue := mload(0)\n }\n\n if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n *\n * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.\n */\n function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {\n bool success;\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)\n returnSize := returndatasize()\n returnValue := mload(0)\n }\n return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Address.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.2.0) (utils/Address.sol)\n\npragma solidity ^0.8.20;\n\nimport {Errors} from \"./Errors.sol\";\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev There's no code at `target` (it is not a contract).\n */\n error AddressEmptyCode(address target);\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n if (address(this).balance < amount) {\n revert Errors.InsufficientBalance(address(this).balance, amount);\n }\n\n (bool success, bytes memory returndata) = recipient.call{value: amount}(\"\");\n if (!success) {\n _revert(returndata);\n }\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason or custom error, it is bubbled\n * up by this function (like regular Solidity function calls). However, if\n * the call reverted with no returned reason, this function reverts with a\n * {Errors.FailedCall} error.\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n */\n function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n if (address(this).balance < value) {\n revert Errors.InsufficientBalance(address(this).balance, value);\n }\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target\n * was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case\n * of an unsuccessful call.\n */\n function verifyCallResultFromTarget(\n address target,\n bool success,\n bytes memory returndata\n ) internal view returns (bytes memory) {\n if (!success) {\n _revert(returndata);\n } else {\n // only check if target is a contract if the call was successful and the return data is empty\n // otherwise we already know that it was a contract\n if (returndata.length == 0 && target.code.length == 0) {\n revert AddressEmptyCode(target);\n }\n return returndata;\n }\n }\n\n /**\n * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the\n * revert reason or with a default {Errors.FailedCall} error.\n */\n function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {\n if (!success) {\n _revert(returndata);\n } else {\n return returndata;\n }\n }\n\n /**\n * @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.\n */\n function _revert(bytes memory returndata) private pure {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n assembly (\"memory-safe\") {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert Errors.FailedCall();\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Context.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n\n function _contextSuffixLength() internal view virtual returns (uint256) {\n return 0;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/ECDSA.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/ECDSA.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.\n *\n * These functions can be used to verify that a message was signed by the holder\n * of the private keys of a given address.\n */\nlibrary ECDSA {\n enum RecoverError {\n NoError,\n InvalidSignature,\n InvalidSignatureLength,\n InvalidSignatureS\n }\n\n /**\n * @dev The signature derives the `address(0)`.\n */\n error ECDSAInvalidSignature();\n\n /**\n * @dev The signature has an invalid length.\n */\n error ECDSAInvalidSignatureLength(uint256 length);\n\n /**\n * @dev The signature has an S value that is in the upper half order.\n */\n error ECDSAInvalidSignatureS(bytes32 s);\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not\n * return address(0) without also returning an error description. Errors are documented using an enum (error type)\n * and a bytes32 providing additional information about the error.\n *\n * If no error is returned, then the address can be used for verification purposes.\n *\n * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.\n *\n * Documentation for signature generation:\n * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]\n * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]\n */\n function tryRecover(\n bytes32 hash,\n bytes memory signature\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n if (signature.length == 65) {\n bytes32 r;\n bytes32 s;\n uint8 v;\n // ecrecover takes the signature parameters, and the only way to get them\n // currently is to use assembly.\n assembly (\"memory-safe\") {\n r := mload(add(signature, 0x20))\n s := mload(add(signature, 0x40))\n v := byte(0, mload(add(signature, 0x60)))\n }\n return tryRecover(hash, v, r, s);\n } else {\n return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));\n }\n }\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with\n * `signature`. This address can then be used for verification purposes.\n *\n * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.\n */\n function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.\n *\n * See https://eips.ethereum.org/EIPS/eip-2098[ERC-2098 short signatures]\n */\n function tryRecover(\n bytes32 hash,\n bytes32 r,\n bytes32 vs\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n unchecked {\n bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n // We do not check for an overflow here since the shift operation results in 0 or 1.\n uint8 v = uint8((uint256(vs) >> 255) + 27);\n return tryRecover(hash, v, r, s);\n }\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\n */\n function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function tryRecover(\n bytes32 hash,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\n // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\n // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\n // signatures from current libraries generate a unique signature with an s-value in the lower half order.\n //\n // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\n // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\n // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\n // these malleable signatures as well.\n if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\n return (address(0), RecoverError.InvalidSignatureS, s);\n }\n\n // If the signature is valid (and not malleable), return the signer address\n address signer = ecrecover(hash, v, r, s);\n if (signer == address(0)) {\n return (address(0), RecoverError.InvalidSignature, bytes32(0));\n }\n\n return (signer, RecoverError.NoError, bytes32(0));\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.\n */\n function _throwError(RecoverError error, bytes32 errorArg) private pure {\n if (error == RecoverError.NoError) {\n return; // no error: do nothing\n } else if (error == RecoverError.InvalidSignature) {\n revert ECDSAInvalidSignature();\n } else if (error == RecoverError.InvalidSignatureLength) {\n revert ECDSAInvalidSignatureLength(uint256(errorArg));\n } else if (error == RecoverError.InvalidSignatureS) {\n revert ECDSAInvalidSignatureS(errorArg);\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/EIP712.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/EIP712.sol)\n\npragma solidity ^0.8.20;\n\nimport {MessageHashUtils} from \"./MessageHashUtils.sol\";\nimport {ShortStrings, ShortString} from \"../ShortStrings.sol\";\nimport {IERC5267} from \"../../interfaces/IERC5267.sol\";\n\n/**\n * @dev https://eips.ethereum.org/EIPS/eip-712[EIP-712] is a standard for hashing and signing of typed structured data.\n *\n * The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose\n * encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract\n * does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to\n * produce the hash of their typed data using a combination of `abi.encode` and `keccak256`.\n *\n * This contract implements the EIP-712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding\n * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA\n * ({_hashTypedDataV4}).\n *\n * The implementation of the domain separator was designed to be as efficient as possible while still properly updating\n * the chain id to protect against replay attacks on an eventual fork of the chain.\n *\n * NOTE: This contract implements the version of the encoding known as \"v4\", as implemented by the JSON RPC method\n * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].\n *\n * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain\n * separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the\n * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.\n *\n * @custom:oz-upgrades-unsafe-allow state-variable-immutable\n */\nabstract contract EIP712 is IERC5267 {\n using ShortStrings for *;\n\n bytes32 private constant TYPE_HASH =\n keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\");\n\n // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to\n // invalidate the cached domain separator if the chain id changes.\n bytes32 private immutable _cachedDomainSeparator;\n uint256 private immutable _cachedChainId;\n address private immutable _cachedThis;\n\n bytes32 private immutable _hashedName;\n bytes32 private immutable _hashedVersion;\n\n ShortString private immutable _name;\n ShortString private immutable _version;\n // slither-disable-next-line constable-states\n string private _nameFallback;\n // slither-disable-next-line constable-states\n string private _versionFallback;\n\n /**\n * @dev Initializes the domain separator and parameter caches.\n *\n * The meaning of `name` and `version` is specified in\n * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP-712]:\n *\n * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.\n * - `version`: the current major version of the signing domain.\n *\n * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart\n * contract upgrade].\n */\n constructor(string memory name, string memory version) {\n _name = name.toShortStringWithFallback(_nameFallback);\n _version = version.toShortStringWithFallback(_versionFallback);\n _hashedName = keccak256(bytes(name));\n _hashedVersion = keccak256(bytes(version));\n\n _cachedChainId = block.chainid;\n _cachedDomainSeparator = _buildDomainSeparator();\n _cachedThis = address(this);\n }\n\n /**\n * @dev Returns the domain separator for the current chain.\n */\n function _domainSeparatorV4() internal view returns (bytes32) {\n if (address(this) == _cachedThis && block.chainid == _cachedChainId) {\n return _cachedDomainSeparator;\n } else {\n return _buildDomainSeparator();\n }\n }\n\n function _buildDomainSeparator() private view returns (bytes32) {\n return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));\n }\n\n /**\n * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this\n * function returns the hash of the fully encoded EIP712 message for this domain.\n *\n * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:\n *\n * ```solidity\n * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(\n * keccak256(\"Mail(address to,string contents)\"),\n * mailTo,\n * keccak256(bytes(mailContents))\n * )));\n * address signer = ECDSA.recover(digest, signature);\n * ```\n */\n function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {\n return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);\n }\n\n /**\n * @inheritdoc IERC5267\n */\n function eip712Domain()\n public\n view\n virtual\n returns (\n bytes1 fields,\n string memory name,\n string memory version,\n uint256 chainId,\n address verifyingContract,\n bytes32 salt,\n uint256[] memory extensions\n )\n {\n return (\n hex\"0f\", // 01111\n _EIP712Name(),\n _EIP712Version(),\n block.chainid,\n address(this),\n bytes32(0),\n new uint256[](0)\n );\n }\n\n /**\n * @dev The name parameter for the EIP712 domain.\n *\n * NOTE: By default this function reads _name which is an immutable value.\n * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).\n */\n // solhint-disable-next-line func-name-mixedcase\n function _EIP712Name() internal view returns (string memory) {\n return _name.toStringWithFallback(_nameFallback);\n }\n\n /**\n * @dev The version parameter for the EIP712 domain.\n *\n * NOTE: By default this function reads _version which is an immutable value.\n * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).\n */\n // solhint-disable-next-line func-name-mixedcase\n function _EIP712Version() internal view returns (string memory) {\n return _version.toStringWithFallback(_versionFallback);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/MessageHashUtils.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/MessageHashUtils.sol)\n\npragma solidity ^0.8.20;\n\nimport {Strings} from \"../Strings.sol\";\n\n/**\n * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.\n *\n * The library provides methods for generating a hash of a message that conforms to the\n * https://eips.ethereum.org/EIPS/eip-191[ERC-191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]\n * specifications.\n */\nlibrary MessageHashUtils {\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x45` (`personal_sign` messages).\n *\n * The digest is calculated by prefixing a bytes32 `messageHash` with\n * `\"\\x19Ethereum Signed Message:\\n32\"` and hashing the result. It corresponds with the\n * hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.\n *\n * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with\n * keccak256, although any bytes32 value can be safely used because the final digest will\n * be re-hashed.\n *\n * See {ECDSA-recover}.\n */\n function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n mstore(0x00, \"\\x19Ethereum Signed Message:\\n32\") // 32 is the bytes-length of messageHash\n mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix\n digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)\n }\n }\n\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x45` (`personal_sign` messages).\n *\n * The digest is calculated by prefixing an arbitrary `message` with\n * `\"\\x19Ethereum Signed Message:\\n\" + len(message)` and hashing the result. It corresponds with the\n * hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.\n *\n * See {ECDSA-recover}.\n */\n function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {\n return\n keccak256(bytes.concat(\"\\x19Ethereum Signed Message:\\n\", bytes(Strings.toString(message.length)), message));\n }\n\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x00` (data with intended validator).\n *\n * The digest is calculated by prefixing an arbitrary `data` with `\"\\x19\\x00\"` and the intended\n * `validator` address. Then hashing the result.\n *\n * See {ECDSA-recover}.\n */\n function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(hex\"19_00\", validator, data));\n }\n\n /**\n * @dev Variant of {toDataWithIntendedValidatorHash-address-bytes} optimized for cases where `data` is a bytes32.\n */\n function toDataWithIntendedValidatorHash(\n address validator,\n bytes32 messageHash\n ) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n mstore(0x00, hex\"19_00\")\n mstore(0x02, shl(96, validator))\n mstore(0x16, messageHash)\n digest := keccak256(0x00, 0x36)\n }\n }\n\n /**\n * @dev Returns the keccak256 digest of an EIP-712 typed data (ERC-191 version `0x01`).\n *\n * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with\n * `\\x19\\x01` and hashing the result. It corresponds to the hash signed by the\n * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.\n *\n * See {ECDSA-recover}.\n */\n function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n let ptr := mload(0x40)\n mstore(ptr, hex\"19_01\")\n mstore(add(ptr, 0x02), domainSeparator)\n mstore(add(ptr, 0x22), structHash)\n digest := keccak256(ptr, 0x42)\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Errors.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Collection of common custom errors used in multiple contracts\n *\n * IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.\n * It is recommended to avoid relying on the error API for critical functionality.\n *\n * _Available since v5.1._\n */\nlibrary Errors {\n /**\n * @dev The ETH balance of the account is not enough to perform the operation.\n */\n error InsufficientBalance(uint256 balance, uint256 needed);\n\n /**\n * @dev A call to an address target failed. The target may have reverted.\n */\n error FailedCall();\n\n /**\n * @dev The deployment failed.\n */\n error FailedDeployment();\n\n /**\n * @dev A necessary precompile is missing.\n */\n error MissingPrecompile(address);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/ERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/ERC165Checker.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165Checker.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @dev Library used to query support of an interface declared via {IERC165}.\n *\n * Note that these functions return the actual result of the query: they do not\n * `revert` if an interface is not supported. It is up to the caller to decide\n * what to do in these cases.\n */\nlibrary ERC165Checker {\n // As per the ERC-165 spec, no interface should ever match 0xffffffff\n bytes4 private constant INTERFACE_ID_INVALID = 0xffffffff;\n\n /**\n * @dev Returns true if `account` supports the {IERC165} interface.\n */\n function supportsERC165(address account) internal view returns (bool) {\n // Any contract that implements ERC-165 must explicitly indicate support of\n // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid\n return\n supportsERC165InterfaceUnchecked(account, type(IERC165).interfaceId) &&\n !supportsERC165InterfaceUnchecked(account, INTERFACE_ID_INVALID);\n }\n\n /**\n * @dev Returns true if `account` supports the interface defined by\n * `interfaceId`. Support for {IERC165} itself is queried automatically.\n *\n * See {IERC165-supportsInterface}.\n */\n function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {\n // query support of both ERC-165 as per the spec and support of _interfaceId\n return supportsERC165(account) && supportsERC165InterfaceUnchecked(account, interfaceId);\n }\n\n /**\n * @dev Returns a boolean array where each value corresponds to the\n * interfaces passed in and whether they're supported or not. This allows\n * you to batch check interfaces for a contract where your expectation\n * is that some interfaces may not be supported.\n *\n * See {IERC165-supportsInterface}.\n */\n function getSupportedInterfaces(\n address account,\n bytes4[] memory interfaceIds\n ) internal view returns (bool[] memory) {\n // an array of booleans corresponding to interfaceIds and whether they're supported or not\n bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length);\n\n // query support of ERC-165 itself\n if (supportsERC165(account)) {\n // query support of each interface in interfaceIds\n for (uint256 i = 0; i < interfaceIds.length; i++) {\n interfaceIdsSupported[i] = supportsERC165InterfaceUnchecked(account, interfaceIds[i]);\n }\n }\n\n return interfaceIdsSupported;\n }\n\n /**\n * @dev Returns true if `account` supports all the interfaces defined in\n * `interfaceIds`. Support for {IERC165} itself is queried automatically.\n *\n * Batch-querying can lead to gas savings by skipping repeated checks for\n * {IERC165} support.\n *\n * See {IERC165-supportsInterface}.\n */\n function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {\n // query support of ERC-165 itself\n if (!supportsERC165(account)) {\n return false;\n }\n\n // query support of each interface in interfaceIds\n for (uint256 i = 0; i < interfaceIds.length; i++) {\n if (!supportsERC165InterfaceUnchecked(account, interfaceIds[i])) {\n return false;\n }\n }\n\n // all interfaces supported\n return true;\n }\n\n /**\n * @notice Query if a contract implements an interface, does not check ERC-165 support\n * @param account The address of the contract to query for support of an interface\n * @param interfaceId The interface identifier, as specified in ERC-165\n * @return true if the contract at account indicates support of the interface with\n * identifier interfaceId, false otherwise\n * @dev Assumes that account contains a contract that supports ERC-165, otherwise\n * the behavior of this method is undefined. This precondition can be checked\n * with {supportsERC165}.\n *\n * Some precompiled contracts will falsely indicate support for a given interface, so caution\n * should be exercised when using this function.\n *\n * Interface identification is specified in ERC-165.\n */\n function supportsERC165InterfaceUnchecked(address account, bytes4 interfaceId) internal view returns (bool) {\n // prepare call\n bytes memory encodedParams = abi.encodeCall(IERC165.supportsInterface, (interfaceId));\n\n // perform static call\n bool success;\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n success := staticcall(30000, account, add(encodedParams, 0x20), mload(encodedParams), 0x00, 0x20)\n returnSize := returndatasize()\n returnValue := mload(0x00)\n }\n\n return success && returnSize >= 0x20 && returnValue > 0;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/IERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[ERC].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/Math.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.20;\n\nimport {Panic} from \"../Panic.sol\";\nimport {SafeCast} from \"./SafeCast.sol\";\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n enum Rounding {\n Floor, // Toward negative infinity\n Ceil, // Toward positive infinity\n Trunc, // Toward zero\n Expand // Away from zero\n }\n\n /**\n * @dev Return the 512-bit addition of two uint256.\n *\n * The result is stored in two 256 variables such that sum = high * 2²⁵⁶ + low.\n */\n function add512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {\n assembly (\"memory-safe\") {\n low := add(a, b)\n high := lt(low, a)\n }\n }\n\n /**\n * @dev Return the 512-bit multiplication of two uint256.\n *\n * The result is stored in two 256 variables such that product = high * 2²⁵⁶ + low.\n */\n function mul512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {\n // 512-bit multiply [high low] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use\n // the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n // variables such that product = high * 2²⁵⁶ + low.\n assembly (\"memory-safe\") {\n let mm := mulmod(a, b, not(0))\n low := mul(a, b)\n high := sub(sub(mm, low), lt(mm, low))\n }\n }\n\n /**\n * @dev Returns the addition of two unsigned integers, with a success flag (no overflow).\n */\n function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a + b;\n success = c >= a;\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, with a success flag (no overflow).\n */\n function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a - b;\n success = c <= a;\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, with a success flag (no overflow).\n */\n function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a * b;\n assembly (\"memory-safe\") {\n // Only true when the multiplication doesn't overflow\n // (c / a == b) || (a == 0)\n success := or(eq(div(c, a), b), iszero(a))\n }\n // equivalent to: success ? c : 0\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the division of two unsigned integers, with a success flag (no division by zero).\n */\n function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n success = b > 0;\n assembly (\"memory-safe\") {\n // The `DIV` opcode returns zero when the denominator is 0.\n result := div(a, b)\n }\n }\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).\n */\n function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n success = b > 0;\n assembly (\"memory-safe\") {\n // The `MOD` opcode returns zero when the denominator is 0.\n result := mod(a, b)\n }\n }\n }\n\n /**\n * @dev Unsigned saturating addition, bounds to `2²⁵⁶ - 1` instead of overflowing.\n */\n function saturatingAdd(uint256 a, uint256 b) internal pure returns (uint256) {\n (bool success, uint256 result) = tryAdd(a, b);\n return ternary(success, result, type(uint256).max);\n }\n\n /**\n * @dev Unsigned saturating subtraction, bounds to zero instead of overflowing.\n */\n function saturatingSub(uint256 a, uint256 b) internal pure returns (uint256) {\n (, uint256 result) = trySub(a, b);\n return result;\n }\n\n /**\n * @dev Unsigned saturating multiplication, bounds to `2²⁵⁶ - 1` instead of overflowing.\n */\n function saturatingMul(uint256 a, uint256 b) internal pure returns (uint256) {\n (bool success, uint256 result) = tryMul(a, b);\n return ternary(success, result, type(uint256).max);\n }\n\n /**\n * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.\n *\n * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.\n * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute\n * one branch when needed, making this function more expensive.\n */\n function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {\n unchecked {\n // branchless ternary works because:\n // b ^ (a ^ b) == a\n // b ^ 0 == b\n return b ^ ((a ^ b) * SafeCast.toUint(condition));\n }\n }\n\n /**\n * @dev Returns the largest of two numbers.\n */\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\n return ternary(a > b, a, b);\n }\n\n /**\n * @dev Returns the smallest of two numbers.\n */\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\n return ternary(a < b, a, b);\n }\n\n /**\n * @dev Returns the average of two numbers. The result is rounded towards\n * zero.\n */\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b) / 2 can overflow.\n return (a & b) + (a ^ b) / 2;\n }\n\n /**\n * @dev Returns the ceiling of the division of two numbers.\n *\n * This differs from standard division with `/` in that it rounds towards infinity instead\n * of rounding towards zero.\n */\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n if (b == 0) {\n // Guarantee the same behavior as in a regular Solidity division.\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n\n // The following calculation ensures accurate ceiling division without overflow.\n // Since a is non-zero, (a - 1) / b will not overflow.\n // The largest possible result occurs when (a - 1) / b is type(uint256).max,\n // but the largest value we can obtain is type(uint256).max - 1, which happens\n // when a = type(uint256).max and b = 1.\n unchecked {\n return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);\n }\n }\n\n /**\n * @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or\n * denominator == 0.\n *\n * Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by\n * Uniswap Labs also under MIT license.\n */\n function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {\n unchecked {\n (uint256 high, uint256 low) = mul512(x, y);\n\n // Handle non-overflow cases, 256 by 256 division.\n if (high == 0) {\n // Solidity will revert if denominator == 0, unlike the div opcode on its own.\n // The surrounding unchecked block does not change this fact.\n // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.\n return low / denominator;\n }\n\n // Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.\n if (denominator <= high) {\n Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));\n }\n\n ///////////////////////////////////////////////\n // 512 by 256 division.\n ///////////////////////////////////////////////\n\n // Make division exact by subtracting the remainder from [high low].\n uint256 remainder;\n assembly (\"memory-safe\") {\n // Compute remainder using mulmod.\n remainder := mulmod(x, y, denominator)\n\n // Subtract 256 bit number from 512 bit number.\n high := sub(high, gt(remainder, low))\n low := sub(low, remainder)\n }\n\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator.\n // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.\n\n uint256 twos = denominator & (0 - denominator);\n assembly (\"memory-safe\") {\n // Divide denominator by twos.\n denominator := div(denominator, twos)\n\n // Divide [high low] by twos.\n low := div(low, twos)\n\n // Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.\n twos := add(div(sub(0, twos), twos), 1)\n }\n\n // Shift in bits from high into low.\n low |= high * twos;\n\n // Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such\n // that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for\n // four bits. That is, denominator * inv ≡ 1 mod 2⁴.\n uint256 inverse = (3 * denominator) ^ 2;\n\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also\n // works in modular arithmetic, doubling the correct bits in each step.\n inverse *= 2 - denominator * inverse; // inverse mod 2⁸\n inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶\n inverse *= 2 - denominator * inverse; // inverse mod 2³²\n inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴\n inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸\n inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶\n\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n // This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is\n // less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and high\n // is no longer required.\n result = low * inverse;\n return result;\n }\n }\n\n /**\n * @dev Calculates x * y / denominator with full precision, following the selected rounding direction.\n */\n function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {\n return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);\n }\n\n /**\n * @dev Calculates floor(x * y >> n) with full precision. Throws if result overflows a uint256.\n */\n function mulShr(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 result) {\n unchecked {\n (uint256 high, uint256 low) = mul512(x, y);\n if (high >= 1 << n) {\n Panic.panic(Panic.UNDER_OVERFLOW);\n }\n return (high << (256 - n)) | (low >> n);\n }\n }\n\n /**\n * @dev Calculates x * y >> n with full precision, following the selected rounding direction.\n */\n function mulShr(uint256 x, uint256 y, uint8 n, Rounding rounding) internal pure returns (uint256) {\n return mulShr(x, y, n) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, 1 << n) > 0);\n }\n\n /**\n * @dev Calculate the modular multiplicative inverse of a number in Z/nZ.\n *\n * If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.\n * If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.\n *\n * If the input value is not inversible, 0 is returned.\n *\n * NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the\n * inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.\n */\n function invMod(uint256 a, uint256 n) internal pure returns (uint256) {\n unchecked {\n if (n == 0) return 0;\n\n // The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)\n // Used to compute integers x and y such that: ax + ny = gcd(a, n).\n // When the gcd is 1, then the inverse of a modulo n exists and it's x.\n // ax + ny = 1\n // ax = 1 + (-y)n\n // ax ≡ 1 (mod n) # x is the inverse of a modulo n\n\n // If the remainder is 0 the gcd is n right away.\n uint256 remainder = a % n;\n uint256 gcd = n;\n\n // Therefore the initial coefficients are:\n // ax + ny = gcd(a, n) = n\n // 0a + 1n = n\n int256 x = 0;\n int256 y = 1;\n\n while (remainder != 0) {\n uint256 quotient = gcd / remainder;\n\n (gcd, remainder) = (\n // The old remainder is the next gcd to try.\n remainder,\n // Compute the next remainder.\n // Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd\n // where gcd is at most n (capped to type(uint256).max)\n gcd - remainder * quotient\n );\n\n (x, y) = (\n // Increment the coefficient of a.\n y,\n // Decrement the coefficient of n.\n // Can overflow, but the result is casted to uint256 so that the\n // next value of y is \"wrapped around\" to a value between 0 and n - 1.\n x - y * int256(quotient)\n );\n }\n\n if (gcd != 1) return 0; // No inverse exists.\n return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.\n }\n }\n\n /**\n * @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.\n *\n * From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is\n * prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that\n * `a**(p-2)` is the modular multiplicative inverse of a in Fp.\n *\n * NOTE: this function does NOT check that `p` is a prime greater than `2`.\n */\n function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {\n unchecked {\n return Math.modExp(a, p - 2, p);\n }\n }\n\n /**\n * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)\n *\n * Requirements:\n * - modulus can't be zero\n * - underlying staticcall to precompile must succeed\n *\n * IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make\n * sure the chain you're using it on supports the precompiled contract for modular exponentiation\n * at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,\n * the underlying function will succeed given the lack of a revert, but the result may be incorrectly\n * interpreted as 0.\n */\n function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {\n (bool success, uint256 result) = tryModExp(b, e, m);\n if (!success) {\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n return result;\n }\n\n /**\n * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).\n * It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying\n * to operate modulo 0 or if the underlying precompile reverted.\n *\n * IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain\n * you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in\n * https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack\n * of a revert, but the result may be incorrectly interpreted as 0.\n */\n function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {\n if (m == 0) return (false, 0);\n assembly (\"memory-safe\") {\n let ptr := mload(0x40)\n // | Offset | Content | Content (Hex) |\n // |-----------|------------|--------------------------------------------------------------------|\n // | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x60:0x7f | value of b | 0x<.............................................................b> |\n // | 0x80:0x9f | value of e | 0x<.............................................................e> |\n // | 0xa0:0xbf | value of m | 0x<.............................................................m> |\n mstore(ptr, 0x20)\n mstore(add(ptr, 0x20), 0x20)\n mstore(add(ptr, 0x40), 0x20)\n mstore(add(ptr, 0x60), b)\n mstore(add(ptr, 0x80), e)\n mstore(add(ptr, 0xa0), m)\n\n // Given the result < m, it's guaranteed to fit in 32 bytes,\n // so we can use the memory scratch space located at offset 0.\n success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)\n result := mload(0x00)\n }\n }\n\n /**\n * @dev Variant of {modExp} that supports inputs of arbitrary length.\n */\n function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {\n (bool success, bytes memory result) = tryModExp(b, e, m);\n if (!success) {\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n return result;\n }\n\n /**\n * @dev Variant of {tryModExp} that supports inputs of arbitrary length.\n */\n function tryModExp(\n bytes memory b,\n bytes memory e,\n bytes memory m\n ) internal view returns (bool success, bytes memory result) {\n if (_zeroBytes(m)) return (false, new bytes(0));\n\n uint256 mLen = m.length;\n\n // Encode call args in result and move the free memory pointer\n result = abi.encodePacked(b.length, e.length, mLen, b, e, m);\n\n assembly (\"memory-safe\") {\n let dataPtr := add(result, 0x20)\n // Write result on top of args to avoid allocating extra memory.\n success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)\n // Overwrite the length.\n // result.length > returndatasize() is guaranteed because returndatasize() == m.length\n mstore(result, mLen)\n // Set the memory pointer after the returned data.\n mstore(0x40, add(dataPtr, mLen))\n }\n }\n\n /**\n * @dev Returns whether the provided byte array is zero.\n */\n function _zeroBytes(bytes memory byteArray) private pure returns (bool) {\n for (uint256 i = 0; i < byteArray.length; ++i) {\n if (byteArray[i] != 0) {\n return false;\n }\n }\n return true;\n }\n\n /**\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded\n * towards zero.\n *\n * This method is based on Newton's method for computing square roots; the algorithm is restricted to only\n * using integer operations.\n */\n function sqrt(uint256 a) internal pure returns (uint256) {\n unchecked {\n // Take care of easy edge cases when a == 0 or a == 1\n if (a <= 1) {\n return a;\n }\n\n // In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a\n // sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between\n // the current value as `ε_n = | x_n - sqrt(a) |`.\n //\n // For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root\n // of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is\n // bigger than any uint256.\n //\n // By noticing that\n // `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`\n // we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar\n // to the msb function.\n uint256 aa = a;\n uint256 xn = 1;\n\n if (aa >= (1 << 128)) {\n aa >>= 128;\n xn <<= 64;\n }\n if (aa >= (1 << 64)) {\n aa >>= 64;\n xn <<= 32;\n }\n if (aa >= (1 << 32)) {\n aa >>= 32;\n xn <<= 16;\n }\n if (aa >= (1 << 16)) {\n aa >>= 16;\n xn <<= 8;\n }\n if (aa >= (1 << 8)) {\n aa >>= 8;\n xn <<= 4;\n }\n if (aa >= (1 << 4)) {\n aa >>= 4;\n xn <<= 2;\n }\n if (aa >= (1 << 2)) {\n xn <<= 1;\n }\n\n // We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).\n //\n // We can refine our estimation by noticing that the middle of that interval minimizes the error.\n // If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).\n // This is going to be our x_0 (and ε_0)\n xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)\n\n // From here, Newton's method give us:\n // x_{n+1} = (x_n + a / x_n) / 2\n //\n // One should note that:\n // x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a\n // = ((x_n² + a) / (2 * x_n))² - a\n // = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a\n // = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)\n // = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)\n // = (x_n² - a)² / (2 * x_n)²\n // = ((x_n² - a) / (2 * x_n))²\n // ≥ 0\n // Which proves that for all n ≥ 1, sqrt(a) ≤ x_n\n //\n // This gives us the proof of quadratic convergence of the sequence:\n // ε_{n+1} = | x_{n+1} - sqrt(a) |\n // = | (x_n + a / x_n) / 2 - sqrt(a) |\n // = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |\n // = | (x_n - sqrt(a))² / (2 * x_n) |\n // = | ε_n² / (2 * x_n) |\n // = ε_n² / | (2 * x_n) |\n //\n // For the first iteration, we have a special case where x_0 is known:\n // ε_1 = ε_0² / | (2 * x_0) |\n // ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))\n // ≤ 2**(2*e-4) / (3 * 2**(e-1))\n // ≤ 2**(e-3) / 3\n // ≤ 2**(e-3-log2(3))\n // ≤ 2**(e-4.5)\n //\n // For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:\n // ε_{n+1} = ε_n² / | (2 * x_n) |\n // ≤ (2**(e-k))² / (2 * 2**(e-1))\n // ≤ 2**(2*e-2*k) / 2**e\n // ≤ 2**(e-2*k)\n xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above\n xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5\n xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9\n xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18\n xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36\n xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72\n\n // Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision\n // ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either\n // sqrt(a) or sqrt(a) + 1.\n return xn - SafeCast.toUint(xn > a / xn);\n }\n }\n\n /**\n * @dev Calculates sqrt(a), following the selected rounding direction.\n */\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = sqrt(a);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);\n }\n }\n\n /**\n * @dev Return the log in base 2 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n */\n function log2(uint256 x) internal pure returns (uint256 r) {\n // If value has upper 128 bits set, log2 result is at least 128\n r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;\n // If upper 64 bits of 128-bit half set, add 64 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;\n // If upper 32 bits of 64-bit half set, add 32 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;\n // If upper 16 bits of 32-bit half set, add 16 to result\n r |= SafeCast.toUint((x >> r) > 0xffff) << 4;\n // If upper 8 bits of 16-bit half set, add 8 to result\n r |= SafeCast.toUint((x >> r) > 0xff) << 3;\n // If upper 4 bits of 8-bit half set, add 4 to result\n r |= SafeCast.toUint((x >> r) > 0xf) << 2;\n\n // Shifts value right by the current result and use it as an index into this lookup table:\n //\n // | x (4 bits) | index | table[index] = MSB position |\n // |------------|---------|-----------------------------|\n // | 0000 | 0 | table[0] = 0 |\n // | 0001 | 1 | table[1] = 0 |\n // | 0010 | 2 | table[2] = 1 |\n // | 0011 | 3 | table[3] = 1 |\n // | 0100 | 4 | table[4] = 2 |\n // | 0101 | 5 | table[5] = 2 |\n // | 0110 | 6 | table[6] = 2 |\n // | 0111 | 7 | table[7] = 2 |\n // | 1000 | 8 | table[8] = 3 |\n // | 1001 | 9 | table[9] = 3 |\n // | 1010 | 10 | table[10] = 3 |\n // | 1011 | 11 | table[11] = 3 |\n // | 1100 | 12 | table[12] = 3 |\n // | 1101 | 13 | table[13] = 3 |\n // | 1110 | 14 | table[14] = 3 |\n // | 1111 | 15 | table[15] = 3 |\n //\n // The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes.\n assembly (\"memory-safe\") {\n r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000))\n }\n }\n\n /**\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log2(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);\n }\n }\n\n /**\n * @dev Return the log in base 10 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n */\n function log10(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >= 10 ** 64) {\n value /= 10 ** 64;\n result += 64;\n }\n if (value >= 10 ** 32) {\n value /= 10 ** 32;\n result += 32;\n }\n if (value >= 10 ** 16) {\n value /= 10 ** 16;\n result += 16;\n }\n if (value >= 10 ** 8) {\n value /= 10 ** 8;\n result += 8;\n }\n if (value >= 10 ** 4) {\n value /= 10 ** 4;\n result += 4;\n }\n if (value >= 10 ** 2) {\n value /= 10 ** 2;\n result += 2;\n }\n if (value >= 10 ** 1) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log10(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);\n }\n }\n\n /**\n * @dev Return the log in base 256 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n *\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n */\n function log256(uint256 x) internal pure returns (uint256 r) {\n // If value has upper 128 bits set, log2 result is at least 128\n r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;\n // If upper 64 bits of 128-bit half set, add 64 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;\n // If upper 32 bits of 64-bit half set, add 32 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;\n // If upper 16 bits of 32-bit half set, add 16 to result\n r |= SafeCast.toUint((x >> r) > 0xffff) << 4;\n // Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8\n return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);\n }\n\n /**\n * @dev Return the log in base 256, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log256(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);\n }\n }\n\n /**\n * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.\n */\n function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {\n return uint8(rounding) % 2 == 1;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/SafeCast.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeCast {\n /**\n * @dev Value doesn't fit in an uint of `bits` size.\n */\n error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);\n\n /**\n * @dev An int value doesn't fit in an uint of `bits` size.\n */\n error SafeCastOverflowedIntToUint(int256 value);\n\n /**\n * @dev Value doesn't fit in an int of `bits` size.\n */\n error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);\n\n /**\n * @dev An uint value doesn't fit in an int of `bits` size.\n */\n error SafeCastOverflowedUintToInt(uint256 value);\n\n /**\n * @dev Returns the downcasted uint248 from uint256, reverting on\n * overflow (when the input is greater than largest uint248).\n *\n * Counterpart to Solidity's `uint248` operator.\n *\n * Requirements:\n *\n * - input must fit into 248 bits\n */\n function toUint248(uint256 value) internal pure returns (uint248) {\n if (value > type(uint248).max) {\n revert SafeCastOverflowedUintDowncast(248, value);\n }\n return uint248(value);\n }\n\n /**\n * @dev Returns the downcasted uint240 from uint256, reverting on\n * overflow (when the input is greater than largest uint240).\n *\n * Counterpart to Solidity's `uint240` operator.\n *\n * Requirements:\n *\n * - input must fit into 240 bits\n */\n function toUint240(uint256 value) internal pure returns (uint240) {\n if (value > type(uint240).max) {\n revert SafeCastOverflowedUintDowncast(240, value);\n }\n return uint240(value);\n }\n\n /**\n * @dev Returns the downcasted uint232 from uint256, reverting on\n * overflow (when the input is greater than largest uint232).\n *\n * Counterpart to Solidity's `uint232` operator.\n *\n * Requirements:\n *\n * - input must fit into 232 bits\n */\n function toUint232(uint256 value) internal pure returns (uint232) {\n if (value > type(uint232).max) {\n revert SafeCastOverflowedUintDowncast(232, value);\n }\n return uint232(value);\n }\n\n /**\n * @dev Returns the downcasted uint224 from uint256, reverting on\n * overflow (when the input is greater than largest uint224).\n *\n * Counterpart to Solidity's `uint224` operator.\n *\n * Requirements:\n *\n * - input must fit into 224 bits\n */\n function toUint224(uint256 value) internal pure returns (uint224) {\n if (value > type(uint224).max) {\n revert SafeCastOverflowedUintDowncast(224, value);\n }\n return uint224(value);\n }\n\n /**\n * @dev Returns the downcasted uint216 from uint256, reverting on\n * overflow (when the input is greater than largest uint216).\n *\n * Counterpart to Solidity's `uint216` operator.\n *\n * Requirements:\n *\n * - input must fit into 216 bits\n */\n function toUint216(uint256 value) internal pure returns (uint216) {\n if (value > type(uint216).max) {\n revert SafeCastOverflowedUintDowncast(216, value);\n }\n return uint216(value);\n }\n\n /**\n * @dev Returns the downcasted uint208 from uint256, reverting on\n * overflow (when the input is greater than largest uint208).\n *\n * Counterpart to Solidity's `uint208` operator.\n *\n * Requirements:\n *\n * - input must fit into 208 bits\n */\n function toUint208(uint256 value) internal pure returns (uint208) {\n if (value > type(uint208).max) {\n revert SafeCastOverflowedUintDowncast(208, value);\n }\n return uint208(value);\n }\n\n /**\n * @dev Returns the downcasted uint200 from uint256, reverting on\n * overflow (when the input is greater than largest uint200).\n *\n * Counterpart to Solidity's `uint200` operator.\n *\n * Requirements:\n *\n * - input must fit into 200 bits\n */\n function toUint200(uint256 value) internal pure returns (uint200) {\n if (value > type(uint200).max) {\n revert SafeCastOverflowedUintDowncast(200, value);\n }\n return uint200(value);\n }\n\n /**\n * @dev Returns the downcasted uint192 from uint256, reverting on\n * overflow (when the input is greater than largest uint192).\n *\n * Counterpart to Solidity's `uint192` operator.\n *\n * Requirements:\n *\n * - input must fit into 192 bits\n */\n function toUint192(uint256 value) internal pure returns (uint192) {\n if (value > type(uint192).max) {\n revert SafeCastOverflowedUintDowncast(192, value);\n }\n return uint192(value);\n }\n\n /**\n * @dev Returns the downcasted uint184 from uint256, reverting on\n * overflow (when the input is greater than largest uint184).\n *\n * Counterpart to Solidity's `uint184` operator.\n *\n * Requirements:\n *\n * - input must fit into 184 bits\n */\n function toUint184(uint256 value) internal pure returns (uint184) {\n if (value > type(uint184).max) {\n revert SafeCastOverflowedUintDowncast(184, value);\n }\n return uint184(value);\n }\n\n /**\n * @dev Returns the downcasted uint176 from uint256, reverting on\n * overflow (when the input is greater than largest uint176).\n *\n * Counterpart to Solidity's `uint176` operator.\n *\n * Requirements:\n *\n * - input must fit into 176 bits\n */\n function toUint176(uint256 value) internal pure returns (uint176) {\n if (value > type(uint176).max) {\n revert SafeCastOverflowedUintDowncast(176, value);\n }\n return uint176(value);\n }\n\n /**\n * @dev Returns the downcasted uint168 from uint256, reverting on\n * overflow (when the input is greater than largest uint168).\n *\n * Counterpart to Solidity's `uint168` operator.\n *\n * Requirements:\n *\n * - input must fit into 168 bits\n */\n function toUint168(uint256 value) internal pure returns (uint168) {\n if (value > type(uint168).max) {\n revert SafeCastOverflowedUintDowncast(168, value);\n }\n return uint168(value);\n }\n\n /**\n * @dev Returns the downcasted uint160 from uint256, reverting on\n * overflow (when the input is greater than largest uint160).\n *\n * Counterpart to Solidity's `uint160` operator.\n *\n * Requirements:\n *\n * - input must fit into 160 bits\n */\n function toUint160(uint256 value) internal pure returns (uint160) {\n if (value > type(uint160).max) {\n revert SafeCastOverflowedUintDowncast(160, value);\n }\n return uint160(value);\n }\n\n /**\n * @dev Returns the downcasted uint152 from uint256, reverting on\n * overflow (when the input is greater than largest uint152).\n *\n * Counterpart to Solidity's `uint152` operator.\n *\n * Requirements:\n *\n * - input must fit into 152 bits\n */\n function toUint152(uint256 value) internal pure returns (uint152) {\n if (value > type(uint152).max) {\n revert SafeCastOverflowedUintDowncast(152, value);\n }\n return uint152(value);\n }\n\n /**\n * @dev Returns the downcasted uint144 from uint256, reverting on\n * overflow (when the input is greater than largest uint144).\n *\n * Counterpart to Solidity's `uint144` operator.\n *\n * Requirements:\n *\n * - input must fit into 144 bits\n */\n function toUint144(uint256 value) internal pure returns (uint144) {\n if (value > type(uint144).max) {\n revert SafeCastOverflowedUintDowncast(144, value);\n }\n return uint144(value);\n }\n\n /**\n * @dev Returns the downcasted uint136 from uint256, reverting on\n * overflow (when the input is greater than largest uint136).\n *\n * Counterpart to Solidity's `uint136` operator.\n *\n * Requirements:\n *\n * - input must fit into 136 bits\n */\n function toUint136(uint256 value) internal pure returns (uint136) {\n if (value > type(uint136).max) {\n revert SafeCastOverflowedUintDowncast(136, value);\n }\n return uint136(value);\n }\n\n /**\n * @dev Returns the downcasted uint128 from uint256, reverting on\n * overflow (when the input is greater than largest uint128).\n *\n * Counterpart to Solidity's `uint128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n */\n function toUint128(uint256 value) internal pure returns (uint128) {\n if (value > type(uint128).max) {\n revert SafeCastOverflowedUintDowncast(128, value);\n }\n return uint128(value);\n }\n\n /**\n * @dev Returns the downcasted uint120 from uint256, reverting on\n * overflow (when the input is greater than largest uint120).\n *\n * Counterpart to Solidity's `uint120` operator.\n *\n * Requirements:\n *\n * - input must fit into 120 bits\n */\n function toUint120(uint256 value) internal pure returns (uint120) {\n if (value > type(uint120).max) {\n revert SafeCastOverflowedUintDowncast(120, value);\n }\n return uint120(value);\n }\n\n /**\n * @dev Returns the downcasted uint112 from uint256, reverting on\n * overflow (when the input is greater than largest uint112).\n *\n * Counterpart to Solidity's `uint112` operator.\n *\n * Requirements:\n *\n * - input must fit into 112 bits\n */\n function toUint112(uint256 value) internal pure returns (uint112) {\n if (value > type(uint112).max) {\n revert SafeCastOverflowedUintDowncast(112, value);\n }\n return uint112(value);\n }\n\n /**\n * @dev Returns the downcasted uint104 from uint256, reverting on\n * overflow (when the input is greater than largest uint104).\n *\n * Counterpart to Solidity's `uint104` operator.\n *\n * Requirements:\n *\n * - input must fit into 104 bits\n */\n function toUint104(uint256 value) internal pure returns (uint104) {\n if (value > type(uint104).max) {\n revert SafeCastOverflowedUintDowncast(104, value);\n }\n return uint104(value);\n }\n\n /**\n * @dev Returns the downcasted uint96 from uint256, reverting on\n * overflow (when the input is greater than largest uint96).\n *\n * Counterpart to Solidity's `uint96` operator.\n *\n * Requirements:\n *\n * - input must fit into 96 bits\n */\n function toUint96(uint256 value) internal pure returns (uint96) {\n if (value > type(uint96).max) {\n revert SafeCastOverflowedUintDowncast(96, value);\n }\n return uint96(value);\n }\n\n /**\n * @dev Returns the downcasted uint88 from uint256, reverting on\n * overflow (when the input is greater than largest uint88).\n *\n * Counterpart to Solidity's `uint88` operator.\n *\n * Requirements:\n *\n * - input must fit into 88 bits\n */\n function toUint88(uint256 value) internal pure returns (uint88) {\n if (value > type(uint88).max) {\n revert SafeCastOverflowedUintDowncast(88, value);\n }\n return uint88(value);\n }\n\n /**\n * @dev Returns the downcasted uint80 from uint256, reverting on\n * overflow (when the input is greater than largest uint80).\n *\n * Counterpart to Solidity's `uint80` operator.\n *\n * Requirements:\n *\n * - input must fit into 80 bits\n */\n function toUint80(uint256 value) internal pure returns (uint80) {\n if (value > type(uint80).max) {\n revert SafeCastOverflowedUintDowncast(80, value);\n }\n return uint80(value);\n }\n\n /**\n * @dev Returns the downcasted uint72 from uint256, reverting on\n * overflow (when the input is greater than largest uint72).\n *\n * Counterpart to Solidity's `uint72` operator.\n *\n * Requirements:\n *\n * - input must fit into 72 bits\n */\n function toUint72(uint256 value) internal pure returns (uint72) {\n if (value > type(uint72).max) {\n revert SafeCastOverflowedUintDowncast(72, value);\n }\n return uint72(value);\n }\n\n /**\n * @dev Returns the downcasted uint64 from uint256, reverting on\n * overflow (when the input is greater than largest uint64).\n *\n * Counterpart to Solidity's `uint64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n */\n function toUint64(uint256 value) internal pure returns (uint64) {\n if (value > type(uint64).max) {\n revert SafeCastOverflowedUintDowncast(64, value);\n }\n return uint64(value);\n }\n\n /**\n * @dev Returns the downcasted uint56 from uint256, reverting on\n * overflow (when the input is greater than largest uint56).\n *\n * Counterpart to Solidity's `uint56` operator.\n *\n * Requirements:\n *\n * - input must fit into 56 bits\n */\n function toUint56(uint256 value) internal pure returns (uint56) {\n if (value > type(uint56).max) {\n revert SafeCastOverflowedUintDowncast(56, value);\n }\n return uint56(value);\n }\n\n /**\n * @dev Returns the downcasted uint48 from uint256, reverting on\n * overflow (when the input is greater than largest uint48).\n *\n * Counterpart to Solidity's `uint48` operator.\n *\n * Requirements:\n *\n * - input must fit into 48 bits\n */\n function toUint48(uint256 value) internal pure returns (uint48) {\n if (value > type(uint48).max) {\n revert SafeCastOverflowedUintDowncast(48, value);\n }\n return uint48(value);\n }\n\n /**\n * @dev Returns the downcasted uint40 from uint256, reverting on\n * overflow (when the input is greater than largest uint40).\n *\n * Counterpart to Solidity's `uint40` operator.\n *\n * Requirements:\n *\n * - input must fit into 40 bits\n */\n function toUint40(uint256 value) internal pure returns (uint40) {\n if (value > type(uint40).max) {\n revert SafeCastOverflowedUintDowncast(40, value);\n }\n return uint40(value);\n }\n\n /**\n * @dev Returns the downcasted uint32 from uint256, reverting on\n * overflow (when the input is greater than largest uint32).\n *\n * Counterpart to Solidity's `uint32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n */\n function toUint32(uint256 value) internal pure returns (uint32) {\n if (value > type(uint32).max) {\n revert SafeCastOverflowedUintDowncast(32, value);\n }\n return uint32(value);\n }\n\n /**\n * @dev Returns the downcasted uint24 from uint256, reverting on\n * overflow (when the input is greater than largest uint24).\n *\n * Counterpart to Solidity's `uint24` operator.\n *\n * Requirements:\n *\n * - input must fit into 24 bits\n */\n function toUint24(uint256 value) internal pure returns (uint24) {\n if (value > type(uint24).max) {\n revert SafeCastOverflowedUintDowncast(24, value);\n }\n return uint24(value);\n }\n\n /**\n * @dev Returns the downcasted uint16 from uint256, reverting on\n * overflow (when the input is greater than largest uint16).\n *\n * Counterpart to Solidity's `uint16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n */\n function toUint16(uint256 value) internal pure returns (uint16) {\n if (value > type(uint16).max) {\n revert SafeCastOverflowedUintDowncast(16, value);\n }\n return uint16(value);\n }\n\n /**\n * @dev Returns the downcasted uint8 from uint256, reverting on\n * overflow (when the input is greater than largest uint8).\n *\n * Counterpart to Solidity's `uint8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits\n */\n function toUint8(uint256 value) internal pure returns (uint8) {\n if (value > type(uint8).max) {\n revert SafeCastOverflowedUintDowncast(8, value);\n }\n return uint8(value);\n }\n\n /**\n * @dev Converts a signed int256 into an unsigned uint256.\n *\n * Requirements:\n *\n * - input must be greater than or equal to 0.\n */\n function toUint256(int256 value) internal pure returns (uint256) {\n if (value < 0) {\n revert SafeCastOverflowedIntToUint(value);\n }\n return uint256(value);\n }\n\n /**\n * @dev Returns the downcasted int248 from int256, reverting on\n * overflow (when the input is less than smallest int248 or\n * greater than largest int248).\n *\n * Counterpart to Solidity's `int248` operator.\n *\n * Requirements:\n *\n * - input must fit into 248 bits\n */\n function toInt248(int256 value) internal pure returns (int248 downcasted) {\n downcasted = int248(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(248, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int240 from int256, reverting on\n * overflow (when the input is less than smallest int240 or\n * greater than largest int240).\n *\n * Counterpart to Solidity's `int240` operator.\n *\n * Requirements:\n *\n * - input must fit into 240 bits\n */\n function toInt240(int256 value) internal pure returns (int240 downcasted) {\n downcasted = int240(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(240, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int232 from int256, reverting on\n * overflow (when the input is less than smallest int232 or\n * greater than largest int232).\n *\n * Counterpart to Solidity's `int232` operator.\n *\n * Requirements:\n *\n * - input must fit into 232 bits\n */\n function toInt232(int256 value) internal pure returns (int232 downcasted) {\n downcasted = int232(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(232, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int224 from int256, reverting on\n * overflow (when the input is less than smallest int224 or\n * greater than largest int224).\n *\n * Counterpart to Solidity's `int224` operator.\n *\n * Requirements:\n *\n * - input must fit into 224 bits\n */\n function toInt224(int256 value) internal pure returns (int224 downcasted) {\n downcasted = int224(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(224, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int216 from int256, reverting on\n * overflow (when the input is less than smallest int216 or\n * greater than largest int216).\n *\n * Counterpart to Solidity's `int216` operator.\n *\n * Requirements:\n *\n * - input must fit into 216 bits\n */\n function toInt216(int256 value) internal pure returns (int216 downcasted) {\n downcasted = int216(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(216, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int208 from int256, reverting on\n * overflow (when the input is less than smallest int208 or\n * greater than largest int208).\n *\n * Counterpart to Solidity's `int208` operator.\n *\n * Requirements:\n *\n * - input must fit into 208 bits\n */\n function toInt208(int256 value) internal pure returns (int208 downcasted) {\n downcasted = int208(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(208, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int200 from int256, reverting on\n * overflow (when the input is less than smallest int200 or\n * greater than largest int200).\n *\n * Counterpart to Solidity's `int200` operator.\n *\n * Requirements:\n *\n * - input must fit into 200 bits\n */\n function toInt200(int256 value) internal pure returns (int200 downcasted) {\n downcasted = int200(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(200, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int192 from int256, reverting on\n * overflow (when the input is less than smallest int192 or\n * greater than largest int192).\n *\n * Counterpart to Solidity's `int192` operator.\n *\n * Requirements:\n *\n * - input must fit into 192 bits\n */\n function toInt192(int256 value) internal pure returns (int192 downcasted) {\n downcasted = int192(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(192, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int184 from int256, reverting on\n * overflow (when the input is less than smallest int184 or\n * greater than largest int184).\n *\n * Counterpart to Solidity's `int184` operator.\n *\n * Requirements:\n *\n * - input must fit into 184 bits\n */\n function toInt184(int256 value) internal pure returns (int184 downcasted) {\n downcasted = int184(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(184, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int176 from int256, reverting on\n * overflow (when the input is less than smallest int176 or\n * greater than largest int176).\n *\n * Counterpart to Solidity's `int176` operator.\n *\n * Requirements:\n *\n * - input must fit into 176 bits\n */\n function toInt176(int256 value) internal pure returns (int176 downcasted) {\n downcasted = int176(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(176, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int168 from int256, reverting on\n * overflow (when the input is less than smallest int168 or\n * greater than largest int168).\n *\n * Counterpart to Solidity's `int168` operator.\n *\n * Requirements:\n *\n * - input must fit into 168 bits\n */\n function toInt168(int256 value) internal pure returns (int168 downcasted) {\n downcasted = int168(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(168, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int160 from int256, reverting on\n * overflow (when the input is less than smallest int160 or\n * greater than largest int160).\n *\n * Counterpart to Solidity's `int160` operator.\n *\n * Requirements:\n *\n * - input must fit into 160 bits\n */\n function toInt160(int256 value) internal pure returns (int160 downcasted) {\n downcasted = int160(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(160, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int152 from int256, reverting on\n * overflow (when the input is less than smallest int152 or\n * greater than largest int152).\n *\n * Counterpart to Solidity's `int152` operator.\n *\n * Requirements:\n *\n * - input must fit into 152 bits\n */\n function toInt152(int256 value) internal pure returns (int152 downcasted) {\n downcasted = int152(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(152, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int144 from int256, reverting on\n * overflow (when the input is less than smallest int144 or\n * greater than largest int144).\n *\n * Counterpart to Solidity's `int144` operator.\n *\n * Requirements:\n *\n * - input must fit into 144 bits\n */\n function toInt144(int256 value) internal pure returns (int144 downcasted) {\n downcasted = int144(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(144, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int136 from int256, reverting on\n * overflow (when the input is less than smallest int136 or\n * greater than largest int136).\n *\n * Counterpart to Solidity's `int136` operator.\n *\n * Requirements:\n *\n * - input must fit into 136 bits\n */\n function toInt136(int256 value) internal pure returns (int136 downcasted) {\n downcasted = int136(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(136, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int128 from int256, reverting on\n * overflow (when the input is less than smallest int128 or\n * greater than largest int128).\n *\n * Counterpart to Solidity's `int128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n */\n function toInt128(int256 value) internal pure returns (int128 downcasted) {\n downcasted = int128(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(128, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int120 from int256, reverting on\n * overflow (when the input is less than smallest int120 or\n * greater than largest int120).\n *\n * Counterpart to Solidity's `int120` operator.\n *\n * Requirements:\n *\n * - input must fit into 120 bits\n */\n function toInt120(int256 value) internal pure returns (int120 downcasted) {\n downcasted = int120(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(120, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int112 from int256, reverting on\n * overflow (when the input is less than smallest int112 or\n * greater than largest int112).\n *\n * Counterpart to Solidity's `int112` operator.\n *\n * Requirements:\n *\n * - input must fit into 112 bits\n */\n function toInt112(int256 value) internal pure returns (int112 downcasted) {\n downcasted = int112(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(112, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int104 from int256, reverting on\n * overflow (when the input is less than smallest int104 or\n * greater than largest int104).\n *\n * Counterpart to Solidity's `int104` operator.\n *\n * Requirements:\n *\n * - input must fit into 104 bits\n */\n function toInt104(int256 value) internal pure returns (int104 downcasted) {\n downcasted = int104(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(104, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int96 from int256, reverting on\n * overflow (when the input is less than smallest int96 or\n * greater than largest int96).\n *\n * Counterpart to Solidity's `int96` operator.\n *\n * Requirements:\n *\n * - input must fit into 96 bits\n */\n function toInt96(int256 value) internal pure returns (int96 downcasted) {\n downcasted = int96(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(96, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int88 from int256, reverting on\n * overflow (when the input is less than smallest int88 or\n * greater than largest int88).\n *\n * Counterpart to Solidity's `int88` operator.\n *\n * Requirements:\n *\n * - input must fit into 88 bits\n */\n function toInt88(int256 value) internal pure returns (int88 downcasted) {\n downcasted = int88(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(88, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int80 from int256, reverting on\n * overflow (when the input is less than smallest int80 or\n * greater than largest int80).\n *\n * Counterpart to Solidity's `int80` operator.\n *\n * Requirements:\n *\n * - input must fit into 80 bits\n */\n function toInt80(int256 value) internal pure returns (int80 downcasted) {\n downcasted = int80(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(80, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int72 from int256, reverting on\n * overflow (when the input is less than smallest int72 or\n * greater than largest int72).\n *\n * Counterpart to Solidity's `int72` operator.\n *\n * Requirements:\n *\n * - input must fit into 72 bits\n */\n function toInt72(int256 value) internal pure returns (int72 downcasted) {\n downcasted = int72(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(72, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int64 from int256, reverting on\n * overflow (when the input is less than smallest int64 or\n * greater than largest int64).\n *\n * Counterpart to Solidity's `int64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n */\n function toInt64(int256 value) internal pure returns (int64 downcasted) {\n downcasted = int64(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(64, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int56 from int256, reverting on\n * overflow (when the input is less than smallest int56 or\n * greater than largest int56).\n *\n * Counterpart to Solidity's `int56` operator.\n *\n * Requirements:\n *\n * - input must fit into 56 bits\n */\n function toInt56(int256 value) internal pure returns (int56 downcasted) {\n downcasted = int56(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(56, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int48 from int256, reverting on\n * overflow (when the input is less than smallest int48 or\n * greater than largest int48).\n *\n * Counterpart to Solidity's `int48` operator.\n *\n * Requirements:\n *\n * - input must fit into 48 bits\n */\n function toInt48(int256 value) internal pure returns (int48 downcasted) {\n downcasted = int48(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(48, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int40 from int256, reverting on\n * overflow (when the input is less than smallest int40 or\n * greater than largest int40).\n *\n * Counterpart to Solidity's `int40` operator.\n *\n * Requirements:\n *\n * - input must fit into 40 bits\n */\n function toInt40(int256 value) internal pure returns (int40 downcasted) {\n downcasted = int40(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(40, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int32 from int256, reverting on\n * overflow (when the input is less than smallest int32 or\n * greater than largest int32).\n *\n * Counterpart to Solidity's `int32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n */\n function toInt32(int256 value) internal pure returns (int32 downcasted) {\n downcasted = int32(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(32, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int24 from int256, reverting on\n * overflow (when the input is less than smallest int24 or\n * greater than largest int24).\n *\n * Counterpart to Solidity's `int24` operator.\n *\n * Requirements:\n *\n * - input must fit into 24 bits\n */\n function toInt24(int256 value) internal pure returns (int24 downcasted) {\n downcasted = int24(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(24, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int16 from int256, reverting on\n * overflow (when the input is less than smallest int16 or\n * greater than largest int16).\n *\n * Counterpart to Solidity's `int16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n */\n function toInt16(int256 value) internal pure returns (int16 downcasted) {\n downcasted = int16(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(16, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int8 from int256, reverting on\n * overflow (when the input is less than smallest int8 or\n * greater than largest int8).\n *\n * Counterpart to Solidity's `int8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits\n */\n function toInt8(int256 value) internal pure returns (int8 downcasted) {\n downcasted = int8(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(8, value);\n }\n }\n\n /**\n * @dev Converts an unsigned uint256 into a signed int256.\n *\n * Requirements:\n *\n * - input must be less than or equal to maxInt256.\n */\n function toInt256(uint256 value) internal pure returns (int256) {\n // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n if (value > uint256(type(int256).max)) {\n revert SafeCastOverflowedUintToInt(value);\n }\n return int256(value);\n }\n\n /**\n * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.\n */\n function toUint(bool b) internal pure returns (uint256 u) {\n assembly (\"memory-safe\") {\n u := iszero(iszero(b))\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/SignedMath.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol)\n\npragma solidity ^0.8.20;\n\nimport {SafeCast} from \"./SafeCast.sol\";\n\n/**\n * @dev Standard signed math utilities missing in the Solidity language.\n */\nlibrary SignedMath {\n /**\n * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.\n *\n * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.\n * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute\n * one branch when needed, making this function more expensive.\n */\n function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {\n unchecked {\n // branchless ternary works because:\n // b ^ (a ^ b) == a\n // b ^ 0 == b\n return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));\n }\n }\n\n /**\n * @dev Returns the largest of two signed numbers.\n */\n function max(int256 a, int256 b) internal pure returns (int256) {\n return ternary(a > b, a, b);\n }\n\n /**\n * @dev Returns the smallest of two signed numbers.\n */\n function min(int256 a, int256 b) internal pure returns (int256) {\n return ternary(a < b, a, b);\n }\n\n /**\n * @dev Returns the average of two signed numbers without overflow.\n * The result is rounded towards zero.\n */\n function average(int256 a, int256 b) internal pure returns (int256) {\n // Formula from the book \"Hacker's Delight\"\n int256 x = (a & b) + ((a ^ b) >> 1);\n return x + (int256(uint256(x) >> 255) & (a ^ b));\n }\n\n /**\n * @dev Returns the absolute unsigned value of a signed value.\n */\n function abs(int256 n) internal pure returns (uint256) {\n unchecked {\n // Formula from the \"Bit Twiddling Hacks\" by Sean Eron Anderson.\n // Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,\n // taking advantage of the most significant (or \"sign\" bit) in two's complement representation.\n // This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,\n // the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative).\n int256 mask = n >> 255;\n\n // A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.\n return uint256((n + mask) ^ mask);\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Panic.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Helper library for emitting standardized panic codes.\n *\n * ```solidity\n * contract Example {\n * using Panic for uint256;\n *\n * // Use any of the declared internal constants\n * function foo() { Panic.GENERIC.panic(); }\n *\n * // Alternatively\n * function foo() { Panic.panic(Panic.GENERIC); }\n * }\n * ```\n *\n * Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].\n *\n * _Available since v5.1._\n */\n// slither-disable-next-line unused-state\nlibrary Panic {\n /// @dev generic / unspecified error\n uint256 internal constant GENERIC = 0x00;\n /// @dev used by the assert() builtin\n uint256 internal constant ASSERT = 0x01;\n /// @dev arithmetic underflow or overflow\n uint256 internal constant UNDER_OVERFLOW = 0x11;\n /// @dev division or modulo by zero\n uint256 internal constant DIVISION_BY_ZERO = 0x12;\n /// @dev enum conversion error\n uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;\n /// @dev invalid encoding in storage\n uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;\n /// @dev empty array pop\n uint256 internal constant EMPTY_ARRAY_POP = 0x31;\n /// @dev array out of bounds access\n uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;\n /// @dev resource error (too large allocation or too large array)\n uint256 internal constant RESOURCE_ERROR = 0x41;\n /// @dev calling invalid internal function\n uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;\n\n /// @dev Reverts with a panic code. Recommended to use with\n /// the internal constants with predefined codes.\n function panic(uint256 code) internal pure {\n assembly (\"memory-safe\") {\n mstore(0x00, 0x4e487b71)\n mstore(0x20, code)\n revert(0x1c, 0x24)\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/ReentrancyGuard.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,\n * consider using {ReentrancyGuardTransient} instead.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant NOT_ENTERED = 1;\n uint256 private constant ENTERED = 2;\n\n uint256 private _status;\n\n /**\n * @dev Unauthorized reentrant call.\n */\n error ReentrancyGuardReentrantCall();\n\n constructor() {\n _status = NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and making it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n _nonReentrantBefore();\n _;\n _nonReentrantAfter();\n }\n\n function _nonReentrantBefore() private {\n // On the first call to nonReentrant, _status will be NOT_ENTERED\n if (_status == ENTERED) {\n revert ReentrancyGuardReentrantCall();\n }\n\n // Any calls to nonReentrant after this point will fail\n _status = ENTERED;\n }\n\n function _nonReentrantAfter() private {\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = NOT_ENTERED;\n }\n\n /**\n * @dev Returns true if the reentrancy guard is currently set to \"entered\", which indicates there is a\n * `nonReentrant` function in the call stack.\n */\n function _reentrancyGuardEntered() internal view returns (bool) {\n return _status == ENTERED;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/ShortStrings.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/ShortStrings.sol)\n\npragma solidity ^0.8.20;\n\nimport {StorageSlot} from \"./StorageSlot.sol\";\n\n// | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |\n// | length | 0x BB |\ntype ShortString is bytes32;\n\n/**\n * @dev This library provides functions to convert short memory strings\n * into a `ShortString` type that can be used as an immutable variable.\n *\n * Strings of arbitrary length can be optimized using this library if\n * they are short enough (up to 31 bytes) by packing them with their\n * length (1 byte) in a single EVM word (32 bytes). Additionally, a\n * fallback mechanism can be used for every other case.\n *\n * Usage example:\n *\n * ```solidity\n * contract Named {\n * using ShortStrings for *;\n *\n * ShortString private immutable _name;\n * string private _nameFallback;\n *\n * constructor(string memory contractName) {\n * _name = contractName.toShortStringWithFallback(_nameFallback);\n * }\n *\n * function name() external view returns (string memory) {\n * return _name.toStringWithFallback(_nameFallback);\n * }\n * }\n * ```\n */\nlibrary ShortStrings {\n // Used as an identifier for strings longer than 31 bytes.\n bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;\n\n error StringTooLong(string str);\n error InvalidShortString();\n\n /**\n * @dev Encode a string of at most 31 chars into a `ShortString`.\n *\n * This will trigger a `StringTooLong` error is the input string is too long.\n */\n function toShortString(string memory str) internal pure returns (ShortString) {\n bytes memory bstr = bytes(str);\n if (bstr.length > 31) {\n revert StringTooLong(str);\n }\n return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));\n }\n\n /**\n * @dev Decode a `ShortString` back to a \"normal\" string.\n */\n function toString(ShortString sstr) internal pure returns (string memory) {\n uint256 len = byteLength(sstr);\n // using `new string(len)` would work locally but is not memory safe.\n string memory str = new string(32);\n assembly (\"memory-safe\") {\n mstore(str, len)\n mstore(add(str, 0x20), sstr)\n }\n return str;\n }\n\n /**\n * @dev Return the length of a `ShortString`.\n */\n function byteLength(ShortString sstr) internal pure returns (uint256) {\n uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;\n if (result > 31) {\n revert InvalidShortString();\n }\n return result;\n }\n\n /**\n * @dev Encode a string into a `ShortString`, or write it to storage if it is too long.\n */\n function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {\n if (bytes(value).length < 32) {\n return toShortString(value);\n } else {\n StorageSlot.getStringSlot(store).value = value;\n return ShortString.wrap(FALLBACK_SENTINEL);\n }\n }\n\n /**\n * @dev Decode a string that was encoded to `ShortString` or written to storage using {toShortStringWithFallback}.\n */\n function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {\n if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {\n return toString(value);\n } else {\n return store;\n }\n }\n\n /**\n * @dev Return the length of a string that was encoded to `ShortString` or written to storage using\n * {toShortStringWithFallback}.\n *\n * WARNING: This will return the \"byte length\" of the string. This may not reflect the actual length in terms of\n * actual characters as the UTF-8 encoding of a single character can span over multiple bytes.\n */\n function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {\n if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {\n return byteLength(value);\n } else {\n return bytes(store).length;\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/StorageSlot.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)\n// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Library for reading and writing primitive types to specific storage slots.\n *\n * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\n * This library helps with reading and writing to such slots without the need for inline assembly.\n *\n * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\n *\n * Example usage to set ERC-1967 implementation slot:\n * ```solidity\n * contract ERC1967 {\n * // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.\n * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n *\n * function _getImplementation() internal view returns (address) {\n * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n * }\n *\n * function _setImplementation(address newImplementation) internal {\n * require(newImplementation.code.length > 0);\n * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n * }\n * }\n * ```\n *\n * TIP: Consider using this library along with {SlotDerivation}.\n */\nlibrary StorageSlot {\n struct AddressSlot {\n address value;\n }\n\n struct BooleanSlot {\n bool value;\n }\n\n struct Bytes32Slot {\n bytes32 value;\n }\n\n struct Uint256Slot {\n uint256 value;\n }\n\n struct Int256Slot {\n int256 value;\n }\n\n struct StringSlot {\n string value;\n }\n\n struct BytesSlot {\n bytes value;\n }\n\n /**\n * @dev Returns an `AddressSlot` with member `value` located at `slot`.\n */\n function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `BooleanSlot` with member `value` located at `slot`.\n */\n function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Bytes32Slot` with member `value` located at `slot`.\n */\n function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Uint256Slot` with member `value` located at `slot`.\n */\n function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Int256Slot` with member `value` located at `slot`.\n */\n function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `StringSlot` with member `value` located at `slot`.\n */\n function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `StringSlot` representation of the string storage pointer `store`.\n */\n function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := store.slot\n }\n }\n\n /**\n * @dev Returns a `BytesSlot` with member `value` located at `slot`.\n */\n function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.\n */\n function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := store.slot\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Strings.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/Strings.sol)\n\npragma solidity ^0.8.20;\n\nimport {Math} from \"./math/Math.sol\";\nimport {SafeCast} from \"./math/SafeCast.sol\";\nimport {SignedMath} from \"./math/SignedMath.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n using SafeCast for *;\n\n bytes16 private constant HEX_DIGITS = \"0123456789abcdef\";\n uint8 private constant ADDRESS_LENGTH = 20;\n uint256 private constant SPECIAL_CHARS_LOOKUP =\n (1 << 0x08) | // backspace\n (1 << 0x09) | // tab\n (1 << 0x0a) | // newline\n (1 << 0x0c) | // form feed\n (1 << 0x0d) | // carriage return\n (1 << 0x22) | // double quote\n (1 << 0x5c); // backslash\n\n /**\n * @dev The `value` string doesn't fit in the specified `length`.\n */\n error StringsInsufficientHexLength(uint256 value, uint256 length);\n\n /**\n * @dev The string being parsed contains characters that are not in scope of the given base.\n */\n error StringsInvalidChar();\n\n /**\n * @dev The string being parsed is not a properly formatted address.\n */\n error StringsInvalidAddressFormat();\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n unchecked {\n uint256 length = Math.log10(value) + 1;\n string memory buffer = new string(length);\n uint256 ptr;\n assembly (\"memory-safe\") {\n ptr := add(buffer, add(32, length))\n }\n while (true) {\n ptr--;\n assembly (\"memory-safe\") {\n mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))\n }\n value /= 10;\n if (value == 0) break;\n }\n return buffer;\n }\n }\n\n /**\n * @dev Converts a `int256` to its ASCII `string` decimal representation.\n */\n function toStringSigned(int256 value) internal pure returns (string memory) {\n return string.concat(value < 0 ? \"-\" : \"\", toString(SignedMath.abs(value)));\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n unchecked {\n return toHexString(value, Math.log256(value) + 1);\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n uint256 localValue = value;\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = HEX_DIGITS[localValue & 0xf];\n localValue >>= 4;\n }\n if (localValue != 0) {\n revert StringsInsufficientHexLength(value, length);\n }\n return string(buffer);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal\n * representation.\n */\n function toHexString(address addr) internal pure returns (string memory) {\n return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal\n * representation, according to EIP-55.\n */\n function toChecksumHexString(address addr) internal pure returns (string memory) {\n bytes memory buffer = bytes(toHexString(addr));\n\n // hash the hex part of buffer (skip length + 2 bytes, length 40)\n uint256 hashValue;\n assembly (\"memory-safe\") {\n hashValue := shr(96, keccak256(add(buffer, 0x22), 40))\n }\n\n for (uint256 i = 41; i > 1; --i) {\n // possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)\n if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {\n // case shift by xoring with 0x20\n buffer[i] ^= 0x20;\n }\n hashValue >>= 4;\n }\n return string(buffer);\n }\n\n /**\n * @dev Returns true if the two strings are equal.\n */\n function equal(string memory a, string memory b) internal pure returns (bool) {\n return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));\n }\n\n /**\n * @dev Parse a decimal string and returns the value as a `uint256`.\n *\n * Requirements:\n * - The string must be formatted as `[0-9]*`\n * - The result must fit into an `uint256` type\n */\n function parseUint(string memory input) internal pure returns (uint256) {\n return parseUint(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseUint-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `[0-9]*`\n * - The result must fit into an `uint256` type\n */\n function parseUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {\n (bool success, uint256 value) = tryParseUint(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseUint-string} that returns false if the parsing fails because of an invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseUint(string memory input) internal pure returns (bool success, uint256 value) {\n return _tryParseUintUncheckedBounds(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseUint-string-uint256-uint256} that returns false if the parsing fails because of an invalid\n * character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseUint(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, uint256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseUintUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseUint-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseUintUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, uint256 value) {\n bytes memory buffer = bytes(input);\n\n uint256 result = 0;\n for (uint256 i = begin; i < end; ++i) {\n uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));\n if (chr > 9) return (false, 0);\n result *= 10;\n result += chr;\n }\n return (true, result);\n }\n\n /**\n * @dev Parse a decimal string and returns the value as a `int256`.\n *\n * Requirements:\n * - The string must be formatted as `[-+]?[0-9]*`\n * - The result must fit in an `int256` type.\n */\n function parseInt(string memory input) internal pure returns (int256) {\n return parseInt(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseInt-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `[-+]?[0-9]*`\n * - The result must fit in an `int256` type.\n */\n function parseInt(string memory input, uint256 begin, uint256 end) internal pure returns (int256) {\n (bool success, int256 value) = tryParseInt(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseInt-string} that returns false if the parsing fails because of an invalid character or if\n * the result does not fit in a `int256`.\n *\n * NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.\n */\n function tryParseInt(string memory input) internal pure returns (bool success, int256 value) {\n return _tryParseIntUncheckedBounds(input, 0, bytes(input).length);\n }\n\n uint256 private constant ABS_MIN_INT256 = 2 ** 255;\n\n /**\n * @dev Variant of {parseInt-string-uint256-uint256} that returns false if the parsing fails because of an invalid\n * character or if the result does not fit in a `int256`.\n *\n * NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.\n */\n function tryParseInt(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, int256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseIntUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseInt-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseIntUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, int256 value) {\n bytes memory buffer = bytes(input);\n\n // Check presence of a negative sign.\n bytes1 sign = begin == end ? bytes1(0) : bytes1(_unsafeReadBytesOffset(buffer, begin)); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n bool positiveSign = sign == bytes1(\"+\");\n bool negativeSign = sign == bytes1(\"-\");\n uint256 offset = (positiveSign || negativeSign).toUint();\n\n (bool absSuccess, uint256 absValue) = tryParseUint(input, begin + offset, end);\n\n if (absSuccess && absValue < ABS_MIN_INT256) {\n return (true, negativeSign ? -int256(absValue) : int256(absValue));\n } else if (absSuccess && negativeSign && absValue == ABS_MIN_INT256) {\n return (true, type(int256).min);\n } else return (false, 0);\n }\n\n /**\n * @dev Parse a hexadecimal string (with or without \"0x\" prefix), and returns the value as a `uint256`.\n *\n * Requirements:\n * - The string must be formatted as `(0x)?[0-9a-fA-F]*`\n * - The result must fit in an `uint256` type.\n */\n function parseHexUint(string memory input) internal pure returns (uint256) {\n return parseHexUint(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseHexUint-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `(0x)?[0-9a-fA-F]*`\n * - The result must fit in an `uint256` type.\n */\n function parseHexUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {\n (bool success, uint256 value) = tryParseHexUint(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseHexUint-string} that returns false if the parsing fails because of an invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseHexUint(string memory input) internal pure returns (bool success, uint256 value) {\n return _tryParseHexUintUncheckedBounds(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseHexUint-string-uint256-uint256} that returns false if the parsing fails because of an\n * invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseHexUint(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, uint256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseHexUintUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseHexUint-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseHexUintUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, uint256 value) {\n bytes memory buffer = bytes(input);\n\n // skip 0x prefix if present\n bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(buffer, begin)) == bytes2(\"0x\"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n uint256 offset = hasPrefix.toUint() * 2;\n\n uint256 result = 0;\n for (uint256 i = begin + offset; i < end; ++i) {\n uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));\n if (chr > 15) return (false, 0);\n result *= 16;\n unchecked {\n // Multiplying by 16 is equivalent to a shift of 4 bits (with additional overflow check).\n // This guarantees that adding a value < 16 will not cause an overflow, hence the unchecked.\n result += chr;\n }\n }\n return (true, result);\n }\n\n /**\n * @dev Parse a hexadecimal string (with or without \"0x\" prefix), and returns the value as an `address`.\n *\n * Requirements:\n * - The string must be formatted as `(0x)?[0-9a-fA-F]{40}`\n */\n function parseAddress(string memory input) internal pure returns (address) {\n return parseAddress(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseAddress-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `(0x)?[0-9a-fA-F]{40}`\n */\n function parseAddress(string memory input, uint256 begin, uint256 end) internal pure returns (address) {\n (bool success, address value) = tryParseAddress(input, begin, end);\n if (!success) revert StringsInvalidAddressFormat();\n return value;\n }\n\n /**\n * @dev Variant of {parseAddress-string} that returns false if the parsing fails because the input is not a properly\n * formatted address. See {parseAddress-string} requirements.\n */\n function tryParseAddress(string memory input) internal pure returns (bool success, address value) {\n return tryParseAddress(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseAddress-string-uint256-uint256} that returns false if the parsing fails because input is not a properly\n * formatted address. See {parseAddress-string-uint256-uint256} requirements.\n */\n function tryParseAddress(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, address value) {\n if (end > bytes(input).length || begin > end) return (false, address(0));\n\n bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(bytes(input), begin)) == bytes2(\"0x\"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n uint256 expectedLength = 40 + hasPrefix.toUint() * 2;\n\n // check that input is the correct length\n if (end - begin == expectedLength) {\n // length guarantees that this does not overflow, and value is at most type(uint160).max\n (bool s, uint256 v) = _tryParseHexUintUncheckedBounds(input, begin, end);\n return (s, address(uint160(v)));\n } else {\n return (false, address(0));\n }\n }\n\n function _tryParseChr(bytes1 chr) private pure returns (uint8) {\n uint8 value = uint8(chr);\n\n // Try to parse `chr`:\n // - Case 1: [0-9]\n // - Case 2: [a-f]\n // - Case 3: [A-F]\n // - otherwise not supported\n unchecked {\n if (value > 47 && value < 58) value -= 48;\n else if (value > 96 && value < 103) value -= 87;\n else if (value > 64 && value < 71) value -= 55;\n else return type(uint8).max;\n }\n\n return value;\n }\n\n /**\n * @dev Escape special characters in JSON strings. This can be useful to prevent JSON injection in NFT metadata.\n *\n * WARNING: This function should only be used in double quoted JSON strings. Single quotes are not escaped.\n *\n * NOTE: This function escapes all unicode characters, and not just the ones in ranges defined in section 2.5 of\n * RFC-4627 (U+0000 to U+001F, U+0022 and U+005C). ECMAScript's `JSON.parse` does recover escaped unicode\n * characters that are not in this range, but other tooling may provide different results.\n */\n function escapeJSON(string memory input) internal pure returns (string memory) {\n bytes memory buffer = bytes(input);\n bytes memory output = new bytes(2 * buffer.length); // worst case scenario\n uint256 outputLength = 0;\n\n for (uint256 i; i < buffer.length; ++i) {\n bytes1 char = bytes1(_unsafeReadBytesOffset(buffer, i));\n if (((SPECIAL_CHARS_LOOKUP & (1 << uint8(char))) != 0)) {\n output[outputLength++] = \"\\\\\";\n if (char == 0x08) output[outputLength++] = \"b\";\n else if (char == 0x09) output[outputLength++] = \"t\";\n else if (char == 0x0a) output[outputLength++] = \"n\";\n else if (char == 0x0c) output[outputLength++] = \"f\";\n else if (char == 0x0d) output[outputLength++] = \"r\";\n else if (char == 0x5c) output[outputLength++] = \"\\\\\";\n else if (char == 0x22) {\n // solhint-disable-next-line quotes\n output[outputLength++] = '\"';\n }\n } else {\n output[outputLength++] = char;\n }\n }\n // write the actual length and deallocate unused memory\n assembly (\"memory-safe\") {\n mstore(output, outputLength)\n mstore(0x40, add(output, shl(5, shr(5, add(outputLength, 63)))))\n }\n\n return string(output);\n }\n\n /**\n * @dev Reads a bytes32 from a bytes array without bounds checking.\n *\n * NOTE: making this function internal would mean it could be used with memory unsafe offset, and marking the\n * assembly block as such would prevent some optimizations.\n */\n function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {\n // This is not memory safe in the general case, but all calls to this private function are within bounds.\n assembly (\"memory-safe\") {\n value := mload(add(buffer, add(0x20, offset)))\n }\n }\n}\n" + }, + "project/contracts/Controller.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\n\nimport './interfaces/IController.sol';\n\n/**\n * @title Controller\n * @dev Manages allow lists for solvers, executors, proposal signers and validators\n */\ncontract Controller is IController, Ownable {\n // List of allowed solvers\n mapping (address => bool) public override isSolverAllowed;\n\n // List of allowed executors\n mapping (address => bool) public override isExecutorAllowed;\n\n // List of allowed proposal signers\n mapping (address => bool) public override isProposalSignerAllowed;\n\n // List of allowed validators\n mapping (address => bool) public override isValidatorAllowed;\n\n // Minimum number of validations allowed\n uint8 public override minValidations;\n\n /**\n * @dev Creates a new Controller contract\n * @param owner Address that will own the contract\n * @param solvers List of allowed solvers\n * @param executors List of allowed executors\n * @param proposalSigners List of allowed proposal signers\n * @param validators List of allowed validators\n * @param _minValidations Minimum number of validations allowed\n */\n constructor(\n address owner,\n address[] memory solvers,\n address[] memory executors,\n address[] memory proposalSigners,\n address[] memory validators,\n uint8 _minValidations\n ) Ownable(owner) {\n for (uint256 i = 0; i < solvers.length; i++) _setAllowedSolver(solvers[i], true);\n for (uint256 i = 0; i < executors.length; i++) _setAllowedExecutor(executors[i], true);\n for (uint256 i = 0; i < proposalSigners.length; i++) _setAllowedProposalSigner(proposalSigners[i], true);\n for (uint256 i = 0; i < validators.length; i++) _setAllowedValidator(validators[i], true);\n _setMinValidations(_minValidations);\n }\n\n /**\n * @dev Sets permissions for multiple solvers\n * @param solvers List of solver addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedSolvers(address[] memory solvers, bool[] memory alloweds) external override onlyOwner {\n if (solvers.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < solvers.length; i++) _setAllowedSolver(solvers[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple executors\n * @param executors List of executor addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedExecutors(address[] memory executors, bool[] memory alloweds) external override onlyOwner {\n if (executors.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < executors.length; i++) _setAllowedExecutor(executors[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple proposal signers\n * @param signers List of proposal signer addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedProposalSigners(address[] memory signers, bool[] memory alloweds) external override onlyOwner {\n if (signers.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < signers.length; i++) _setAllowedProposalSigner(signers[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple validators\n * @param validators List of validator addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedValidators(address[] memory validators, bool[] memory alloweds) external override onlyOwner {\n if (validators.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < validators.length; i++) _setAllowedValidator(validators[i], alloweds[i]);\n }\n\n /**\n * @dev Sets the minimum number of validations allowed\n * @param newMinValidations minimum number of validations allowed\n */\n function setMinValidations(uint8 newMinValidations) external override onlyOwner {\n _setMinValidations(newMinValidations);\n }\n\n /**\n * @dev Sets a solver permission\n */\n function _setAllowedSolver(address solver, bool allowed) internal {\n isSolverAllowed[solver] = allowed;\n emit SolverAllowedSet(solver, allowed);\n }\n\n /**\n * @dev Sets an executor permission\n */\n function _setAllowedExecutor(address executor, bool allowed) internal {\n isExecutorAllowed[executor] = allowed;\n emit ExecutorAllowedSet(executor, allowed);\n }\n\n /**\n * @dev Sets a proposal signer permission\n */\n function _setAllowedProposalSigner(address signer, bool allowed) internal {\n isProposalSignerAllowed[signer] = allowed;\n emit ProposalSignerAllowedSet(signer, allowed);\n }\n\n /**\n * @dev Sets a validator permission\n */\n function _setAllowedValidator(address validator, bool allowed) internal {\n isValidatorAllowed[validator] = allowed;\n emit ValidatorAllowedSet(validator, allowed);\n }\n\n /**\n * @dev Sets the minimum number of validations allowed\n */\n function _setMinValidations(uint8 newMinValidations) internal {\n minValidations = newMinValidations;\n emit MinValidationSet(newMinValidations);\n }\n}\n" + }, + "project/contracts/Intents.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Enum representing the type of intent operation.\n * - Swap: Swap tokens between chains or tokens.\n * - Transfer: Transfer tokens to one or more recipients.\n * - Call: Execute arbitrary contract calls.\n */\nenum OpType {\n Swap,\n Transfer,\n Call\n}\n\n/**\n * @dev Execution structure.\n * @param intent Intent to be fulfilled.\n * @param proposal Proposal to be executed.\n * @param signature Proposal signature.\n */\nstruct Execution {\n Intent intent;\n Proposal proposal;\n bytes signature;\n}\n\n/**\n * @dev EIP-712 typed data struct representing a validator's approval of an intent.\n * @param intent The hash of the intent being validated.\n */\nstruct Validation {\n bytes32 intent;\n}\n\n/**\n * @dev General intent structure used to abstract over different intent types.\n * @param op The type of operation this intent represents.\n * @param user The originator of the intent.\n * @param settler The address responsible for executing the intent on-chain.\n * @param nonce A unique value used to prevent replay attacks and distinguish intents.\n * @param deadline The timestamp by which the intent must be executed.\n * @param data ABI-encoded data representing a specific intent type (e.g. SwapIntent, TransferIntent, CallIntent).\n * @param maxFees List of max fees the user is willing to pay for the intent.\n * @param events List of custom intent events to be emitted.\n * @param configSig The signature of the configuration that this intent belongs to\n * @param minValidations The minimum number of validator approvals required for this intent to be considered valid.\n * @param validations The list validator signatures attesting to this intent.\n */\nstruct Intent {\n uint8 op;\n address user;\n address settler;\n bytes32 nonce;\n uint256 deadline;\n bytes data;\n MaxFee[] maxFees;\n IntentEvent[] events;\n bytes configSig;\n uint256 minValidations;\n bytes[] validations;\n}\n\n/**\n * @dev Max fee representation\n * @param token Token used to pay for the execution fee.\n * @param amount Max amount of fee token to be paid for settling this intent.\n */\nstruct MaxFee {\n address token;\n uint256 amount;\n}\n\n/**\n * @dev Intent event representation.\n * @param topic Event topic to be emitted.\n * @param data Event data to be emitted.\n */\nstruct IntentEvent {\n bytes32 topic;\n bytes data;\n}\n\n/**\n * @dev Represents a swap intent between two chains.\n * @param sourceChain Chain ID where tokens will be sent from.\n * @param destinationChain Chain ID where tokens will be received.\n * @param tokensIn List of input tokens and amounts to swap.\n * @param tokensOut List of expected output tokens, minimum amounts, and recipients.\n */\nstruct SwapIntent {\n uint256 sourceChain;\n uint256 destinationChain;\n TokenIn[] tokensIn;\n TokenOut[] tokensOut;\n}\n\n/**\n * @dev Token in representation.\n * @param token Address of a token to be sent.\n * @param amount Amount of tokens to be sent.\n */\nstruct TokenIn {\n address token;\n uint256 amount;\n}\n\n/**\n * @dev Token out representation.\n * @param token Address of a token to be received.\n * @param minAmount Minimum amount of tokens to be received.\n * @param recipient Recipient address that will receive the token out.\n */\nstruct TokenOut {\n address token;\n uint256 minAmount;\n address recipient;\n}\n\n/**\n * @dev Represents a transfer intent containing multiple token transfers.\n * @param chainId Chain ID where the transfers should be executed.\n * @param transfers List of token transfers to be performed.\n */\nstruct TransferIntent {\n uint256 chainId;\n TransferData[] transfers;\n}\n\n/**\n * @dev Transfer data for a single token transfer.\n * @param token Address of the token to transfer.\n * @param amount Amount of the token to transfer.\n * @param recipient Recipient of the token transfer.\n */\nstruct TransferData {\n address token;\n uint256 amount;\n address recipient;\n}\n\n/**\n * @dev Represents a generic call intent consisting of one or more contract calls.\n * @param chainId Chain ID where the calls should be executed.\n * @param calls List of low-level contract calls to be executed.\n */\nstruct CallIntent {\n uint256 chainId;\n CallData[] calls;\n}\n\n/**\n * @dev Low-level call data for a target contract interaction.\n * @param target Target contract address.\n * @param data Calldata to be sent to the target.\n * @param value ETH value to send along with the call.\n */\nstruct CallData {\n address target;\n bytes data;\n uint256 value;\n}\n\n/**\n * @dev Generic proposal structure representing a solver’s response to an intent.\n * @param deadline Timestamp until when the proposal is valid.\n * @param data ABI-encoded proposal-specific data (e.g. SwapProposal).\n * @param fees List of fee amounts the solver requires for execution.\n */\nstruct Proposal {\n uint256 deadline;\n bytes data;\n uint256[] fees;\n}\n\n/**\n * @dev Swap proposal representation for a swap intent.\n * @param executor Address of the executor contract that should be called during intent execution.\n * @param data Arbitrary data used to call the executor contract.\n * @param amountsOut List of amounts of tokens out proposed by the solver.\n */\nstruct SwapProposal {\n address executor;\n bytes data;\n uint256[] amountsOut;\n}\n\nlibrary IntentsHelpers {\n bytes32 internal constant INTENT_TYPE_HASH =\n keccak256(\n 'Intent(uint8 op,address user,address settler,bytes32 nonce,uint256 deadline,bytes data,MaxFee[] maxFees,IntentEvent[] events,bytes configSig,uint256 minValidations)IntentEvent(bytes32 topic,bytes data)MaxFee(address token,uint256 amount)'\n );\n\n bytes32 internal constant PROPOSAL_TYPE_HASH =\n keccak256('Proposal(bytes32 intent,address solver,uint256 deadline,bytes data,uint256[] fees)');\n\n bytes32 internal constant VALIDATION_TYPE_HASH = keccak256('Validation(bytes32 intent)');\n\n bytes32 internal constant MAX_FEE_TYPE_HASH = keccak256('MaxFee(address token,uint256 amount)');\n\n bytes32 internal constant INTENT_EVENT_TYPE_HASH = keccak256('IntentEvent(bytes32 topic,bytes data)');\n\n function hash(Intent memory intent) internal pure returns (bytes32) {\n return\n keccak256(\n abi.encode(\n INTENT_TYPE_HASH,\n intent.op,\n intent.user,\n intent.settler,\n intent.nonce,\n intent.deadline,\n keccak256(intent.data),\n hash(intent.maxFees),\n hash(intent.events),\n intent.configSig,\n intent.minValidations\n )\n );\n }\n\n function hash(Proposal memory proposal, Intent memory intent, address solver) internal pure returns (bytes32) {\n return\n keccak256(\n abi.encode(\n PROPOSAL_TYPE_HASH,\n hash(intent),\n solver,\n proposal.deadline,\n keccak256(proposal.data),\n hash(proposal.fees)\n )\n );\n }\n\n function hash(MaxFee[] memory fees) internal pure returns (bytes32) {\n bytes32[] memory hashes = new bytes32[](fees.length);\n for (uint256 i = 0; i < fees.length; i++) {\n hashes[i] = keccak256(abi.encode(MAX_FEE_TYPE_HASH, fees[i].token, fees[i].amount));\n }\n return keccak256(abi.encodePacked(hashes));\n }\n\n function hash(IntentEvent[] memory events) internal pure returns (bytes32) {\n bytes32[] memory hashes = new bytes32[](events.length);\n for (uint256 i = 0; i < events.length; i++) {\n hashes[i] = keccak256(abi.encode(INTENT_EVENT_TYPE_HASH, events[i].topic, keccak256(events[i].data)));\n }\n return keccak256(abi.encodePacked(hashes));\n }\n\n function hash(uint256[] memory fees) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(fees));\n }\n\n function hash(Validation memory validation) internal pure returns (bytes32) {\n return keccak256(abi.encode(VALIDATION_TYPE_HASH, validation.intent));\n }\n}\n" + }, + "project/contracts/interfaces/IController.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @title Controller interface\n */\ninterface IController {\n /**\n * @dev The input arrays are not of equal length\n */\n error ControllerInputInvalidLength();\n\n /**\n * @dev Emitted every time a solver permission is set\n */\n event SolverAllowedSet(address indexed solver, bool allowed);\n\n /**\n * @dev Emitted every time an executor permission is set\n */\n event ExecutorAllowedSet(address indexed executor, bool allowed);\n\n /**\n * @dev Emitted every time a proposal signer permission is set\n */\n event ProposalSignerAllowedSet(address indexed proposalSigner, bool allowed);\n\n /**\n * @dev Emitted every time a validator permission is set\n */\n event ValidatorAllowedSet(address indexed validator, bool allowed);\n\n /**\n * @dev Emitted when the minimum validations changes\n */\n event MinValidationSet(uint8 indexed newMinValidation);\n\n /**\n * @dev Tells whether a solver is allowed\n * @param solver Address of the solver being queried\n */\n function isSolverAllowed(address solver) external view returns (bool);\n\n /**\n * @dev Tells whether an executor is allowed\n * @param executor Address of the executor being queried\n */\n function isExecutorAllowed(address executor) external view returns (bool);\n\n /**\n * @dev Tells whether a proposal signer is allowed\n * @param signer Address of the proposal signer being queried\n */\n function isProposalSignerAllowed(address signer) external view returns (bool);\n\n /**\n * @dev Tells whether a validator is allowed\n * @param validator Address of the validator being queried\n */\n function isValidatorAllowed(address validator) external view returns (bool);\n\n /**\n * @dev Tells the minimum number of validations allowed\n */\n function minValidations() external view returns (uint8);\n\n /**\n * @dev Sets permissions for multiple solvers\n * @param solvers List of solver addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedSolvers(address[] memory solvers, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple executors\n * @param executors List of executor addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedExecutors(address[] memory executors, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple proposal signers\n * @param signers List of proposal signer addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedProposalSigners(address[] memory signers, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple validators\n * @param validators List of validator addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedValidators(address[] memory validators, bool[] memory alloweds) external;\n\n /**\n * @dev Sets the minimum number of validations allowed\n * @param newMinValidations minimum number of validations allowed\n */\n function setMinValidations(uint8 newMinValidations) external;\n}\n" + }, + "project/contracts/interfaces/ICreateX.sol": { + "content": "// SPDX-License-Identifier: AGPL-3.0-only\n\npragma solidity ^0.8.4;\n\n/**\n * @title CreateX Factory Interface Definition\n * @author pcaversaccio (https://web.archive.org/web/20230921103111/https://pcaversaccio.com/)\n * @custom:coauthor Matt Solomon (https://web.archive.org/web/20230921103335/https://mattsolomon.dev/)\n */\ninterface ICreateX {\n event ContractCreation(address indexed newContract);\n\n function deployCreate3(bytes32 salt, bytes memory initCode) external payable returns (address newContract);\n}\n" + }, + "project/contracts/interfaces/IExecutor.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\n\n/**\n * @title Executor interface\n */\ninterface IExecutor {\n /**\n * @dev Executes an intent proposal\n * @param intent Intent to be executed\n * @param proposal Proposal to be executed to fulfill the intent\n */\n function execute(Intent memory intent, Proposal memory proposal) external;\n}\n" + }, + "project/contracts/interfaces/IIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\nimport '../safeguards/Safeguards.sol';\n\n/**\n * @title IntentsValidator\n * @dev Performs intents validations based on safeguards\n */\ninterface IIntentsValidator {\n /**\n * @dev Validates an intent for a safeguard\n * @param intent Intent to be validated\n * @param config Safeguard config to validate the intent with\n */\n function validate(Intent memory intent, bytes memory config) external pure;\n}\n" + }, + "project/contracts/interfaces/ISafe.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nenum SafeOperation {\n Call,\n DelegateCall\n}\n\ninterface ISafe {\n function getThreshold() external view returns (uint256);\n\n function execTransactionFromModuleReturnData(address to, uint256 value, bytes memory data, SafeOperation operation)\n external\n returns (bool success, bytes memory returnData);\n}\n" + }, + "project/contracts/interfaces/ISettler.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\nimport '../safeguards/Safeguards.sol';\n\n/**\n * @title Settler interface\n */\ninterface ISettler {\n /**\n * @dev The requested intent type is unknown\n */\n error SettlerUnknownIntentType(uint8 op);\n\n /**\n * @dev The simulation has been successful\n */\n error SettlerSimulationSuccess(uint256 gasUsed);\n\n /**\n * @dev The solver is not allowed\n */\n error SettlerSolverNotAllowed(address solver);\n\n /**\n * @dev The executor is not allowed\n */\n error SettlerExecutorNotAllowed(address executor);\n\n /**\n * @dev The proposal signer is not allowed\n */\n error SettlerProposalSignerNotAllowed(address signer);\n\n /**\n * @dev The validator is not allowed\n */\n error SettlerValidatorNotAllowed(address validator);\n\n /**\n * @dev The validator is duplicated\n */\n error SettlerValidatorDuplicatedOrUnsorted(address previous, address current);\n\n /**\n * @dev The settler is not the current contract\n */\n error SettlerInvalidSettler(address settler);\n\n /**\n * @dev The nonce is zero\n */\n error SettlerNonceZero();\n\n /**\n * @dev The nonce has already been used for the user\n */\n error SettlerNonceAlreadyUsed(address user, bytes32 nonce);\n\n /**\n * @dev The intent deadline is in the past\n */\n error SettlerIntentPastDeadline(uint256 deadline, uint256 timestamp);\n\n /**\n * @dev The current chain is not valid\n */\n error SettlerInvalidChain(uint256 chainId);\n\n /**\n * @dev The recipient is the settler contract\n */\n error SettlerInvalidRecipient(address to);\n\n /**\n * @dev The user is not a smart account\n */\n error SettlerUserNotSmartAccount(address user);\n\n /**\n * @dev The amount out is lower than the proposed amount\n */\n error SettlerAmountOutLtProposed(uint256 index, uint256 amountOut, uint256 proposed);\n\n /**\n * @dev The proposed amount is lower than the minimum amount\n */\n error SettlerProposedAmountLtMinAmount(uint256 index, uint256 proposed, uint256 minAmount);\n\n /**\n * @dev The proposed amounts array and the tokens out array are not of equal length\n */\n error SettlerInvalidProposedAmounts();\n\n /**\n * @dev The balance after the proposal execution is lower than the balance before\n */\n error SettlerPostBalanceOutLtPre(uint256 index, uint256 post, uint256 pre);\n\n /**\n * @dev The solver fees length does not match the requested by the user\n */\n error SettlerSolverFeeInvalidLength();\n\n /**\n * @dev The solver fee is too high\n */\n error SettlerSolverFeeTooHigh(uint256 fee, uint256 max);\n\n /**\n * @dev The intent validations are not enough\n */\n error SettlerIntentValidationsNotEnough(uint256 min, uint256 current);\n\n /**\n * @dev The proposal deadline is in the past\n */\n error SettlerProposalPastDeadline(uint256 deadline, uint256 timestamp);\n\n /**\n * @dev The proposal data is not empty\n */\n error SettlerProposalDataNotEmpty();\n\n /**\n * @dev The rescue funds recipient is zero\n */\n error SettlerRescueFundsRecipientZero();\n\n /**\n * @dev The list of safeguards exceed the maximum allowed\n */\n error SettlerTooManySafeguards(uint256 lengthRequested);\n\n /**\n * @dev The new smart accounts handler is zero\n */\n error SmartAccountsHandlerZero();\n\n /**\n * @dev Custom events emitted for each intent\n */\n event IntentExecuted(\n address indexed user,\n bytes32 indexed topic,\n uint8 indexed op,\n Intent intent,\n Proposal proposal,\n bytes output,\n bytes data\n );\n\n /**\n * @dev Emitted every time an intent is fulfilled\n */\n event ProposalExecuted(bytes32 indexed proposal, uint256 index);\n\n /**\n * @dev Emitted every time tokens are withdrawn from the contract balance\n */\n event FundsRescued(address indexed token, address indexed recipient, uint256 amount);\n\n /**\n * @dev Emitted every time the smart accounts handler is set\n */\n event SmartAccountsHandlerSet(address indexed smartAccountsHandler);\n\n /**\n * @dev Emitted every time the intents validator is set\n */\n event IntentsValidatorSet(address indexed intentsValidator);\n\n /**\n * @dev Emitted every time a safeguard is set\n */\n event SafeguardSet(address indexed user);\n\n /**\n * @dev Tells the reference to the Mimic controller\n */\n function controller() external view returns (address);\n\n /**\n * @dev Tells the reference to the smart accounts handler\n */\n function smartAccountsHandler() external view returns (address);\n\n /**\n * @dev Tells the reference to the intents validator\n */\n function intentsValidator() external view returns (address);\n\n /**\n * @dev Tells the block at which a user nonce was used. Returns 0 if unused.\n * @param user Address of the user being queried\n * @param nonce Nonce being queried\n */\n function getNonceBlock(address user, bytes32 nonce) external view returns (uint256);\n\n /**\n * @dev Tells the safeguard set for a user\n * @param user Address of the user being queried\n */\n function getUserSafeguard(address user) external view returns (bytes memory);\n\n /**\n * @dev Tells the hash of an intent\n * @param intent Intent to get the hash of\n */\n function getIntentHash(Intent memory intent) external pure returns (bytes32);\n\n /**\n * @dev Tells the hash of a proposal\n * @param proposal Proposal to be hashed\n * @param intent Intent being fulfilled by the requested proposal\n * @param solver Address of the solver that made the proposal\n */\n function getProposalHash(Proposal memory proposal, Intent memory intent, address solver)\n external\n pure\n returns (bytes32);\n\n /**\n * @dev Withdraws ERC20 or native tokens from the contract\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function rescueFunds(address token, address recipient, uint256 amount) external;\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function setSmartAccountsHandler(address newSmartAccountsHandler) external;\n\n /**\n * @dev Sets a new intents validator address\n * @param newIntentsValidator New intents validator to be set\n */\n function setIntentsValidator(address newIntentsValidator) external;\n\n /**\n * @dev Sets a safeguard for a user\n * @param safeguard Safeguard to be set\n */\n function setSafeguard(bytes memory safeguard) external;\n\n /**\n * @dev Executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function execute(Execution[] memory executions) external;\n\n /**\n * @dev Simulates an execution. It will always revert. Successful executions are returned as\n * `SettlerSimulationSuccess` errors. Any other error should be treated as failure.\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function simulate(Execution[] memory executions) external;\n}\n" + }, + "project/contracts/interfaces/ISmartAccount.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/introspection/IERC165.sol';\n\n/**\n * @title SmartAccount interface\n */\ninterface ISmartAccount is IERC165 {\n /**\n * @dev Emitted every time tokens are transferred\n */\n event Transferred(address indexed token, address indexed recipient, uint256 amount);\n\n /**\n * @dev Emitted every time `call` is called\n */\n event Called(address indexed target, bytes data, uint256 value, bytes result);\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the owner or the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) external;\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the owner or the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n */\n function call(address target, bytes memory data, uint256 value) external returns (bytes memory result);\n}\n" + }, + "project/contracts/interfaces/ISmartAccountContract.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/interfaces/IERC1271.sol';\n\nimport './ISmartAccount.sol';\n\n/**\n * @title SmartAccountContract interface\n */\ninterface ISmartAccountContract is ISmartAccount, IERC1271 {\n // solhint-disable-previous-line no-empty-blocks\n}\n" + }, + "project/contracts/interfaces/ISmartAccountsHandler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\ninterface ISmartAccountsHandler {\n /**\n * @dev The smart account given is not supported\n */\n error SmartAccountsHandlerUnsupportedAccount(address account);\n\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address account) external view returns (bool);\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address account, address token, address to, uint256 amount) external;\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address account, address target, bytes memory data, uint256 value) external returns (bytes memory);\n}\n" + }, + "project/contracts/safeguards/BaseIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @title BaseIntentsValidator\n */\ncontract BaseIntentsValidator {\n /**\n * @dev No intents allowed\n */\n error IntentsValidatorNoneAllowed();\n\n /**\n * @dev Intent type unknown\n */\n error IntentsValidatorUnknownIntentType(uint8 opType);\n\n /**\n * @dev Invalid safeguard mode\n */\n error IntentsValidatorInvalidSafeguardMode(uint8 mode);\n\n /**\n * @dev Tells whether a chain is allowed\n */\n function _isChainAllowed(uint256 chainId, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, uint256[] memory values) = abi.decode(config, (bool, uint256[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (chainId == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (chainId == values[i]) return true;\n }\n return false;\n }\n }\n\n /**\n * @dev Tells whether an account is allowed\n */\n function _isAccountAllowed(address account, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, address[] memory values) = abi.decode(config, (bool, address[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (account == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (account == values[i]) return true;\n }\n return false;\n }\n }\n\n /**\n * @dev Tells whether a selector is allowed\n */\n function _isSelectorAllowed(bytes4 selector, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, bytes4[] memory values) = abi.decode(config, (bool, bytes4[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (selector == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (selector == values[i]) return true;\n }\n return false;\n }\n }\n}\n" + }, + "project/contracts/safeguards/CallIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './Safeguards.sol';\nimport './BaseIntentsValidator.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Call safeguard modes to validate call intents\n * @param None To ensure no calls are allowed\n * @param Chain To validate that the chain where calls execute is allowed\n * @param Target To validate that the call targets (contract addresses) are allowed\n * @param Selector To validate that the function selectors being called are allowed\n */\nenum CallSafeguardMode {\n None,\n Chain,\n Target,\n Selector\n}\n\n/**\n * @title CallIntentsValidator\n * @dev Performs call intents validations based on safeguards\n */\ncontract CallIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a call intent is valid for a safeguard\n * @param intent Call intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isCallIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n CallIntent memory callIntent = abi.decode(intent.data, (CallIntent));\n if (safeguard.mode == uint8(CallSafeguardMode.Chain))\n return _isChainAllowed(callIntent.chainId, safeguard.config);\n if (safeguard.mode == uint8(CallSafeguardMode.Target))\n return _areCallTargetsValid(callIntent.calls, safeguard.config);\n if (safeguard.mode == uint8(CallSafeguardMode.Selector))\n return _areCallSelectorsValid(callIntent.calls, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the call targets are allowed\n */\n function _areCallTargetsValid(CallData[] memory calls, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < calls.length; i++) {\n if (!_isAccountAllowed(calls[i].target, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the call selectors are allowed\n */\n function _areCallSelectorsValid(CallData[] memory calls, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < calls.length; i++) {\n if (!_isSelectorAllowed(bytes4(calls[i].data), config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/safeguards/IntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './CallIntentsValidator.sol';\nimport './TransferIntentsValidator.sol';\nimport './Safeguards.sol';\nimport './SwapIntentsValidator.sol';\nimport '../Intents.sol';\nimport '../interfaces/IIntentsValidator.sol';\n\n/**\n * @title IntentsValidator\n * @dev Performs intents validations based on safeguards\n */\ncontract IntentsValidator is IIntentsValidator, SwapIntentsValidator, TransferIntentsValidator, CallIntentsValidator {\n /**\n * @dev Safeguard validation failed\n */\n error IntentsValidatorSafeguardFailed();\n\n /**\n * @dev Invalid safeguard config mode\n */\n error IntentsValidatorInvalidSafeguardConfigMode(uint8 mode);\n\n /**\n * @dev Invalid safeguard group logic mode\n */\n error IntentsValidatorInvalidSafeguardGroupLogicMode(uint8 mode);\n\n /**\n * @dev Tells whether an intent is valid for a safeguard\n * @param intent Intent to be validated\n * @param config Safeguard config to validate the intent with\n */\n function validate(Intent memory intent, bytes memory config) external pure override {\n (uint8 mode, bytes memory safeguard) = abi.decode(config, (uint8, bytes));\n if (mode == uint8(SafeguardConfigMode.List)) _validate(intent, abi.decode(safeguard, (Safeguard[])));\n else if (mode == uint8(SafeguardConfigMode.Tree)) _validate(intent, _decodeSafeguardTree(safeguard));\n else revert IntentsValidatorInvalidSafeguardConfigMode(mode);\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguards list\n * @param intent Intent to be validated\n * @param safeguards Safeguard list to validate the intent with\n */\n function _validate(Intent memory intent, Safeguard[] memory safeguards) internal pure {\n if (safeguards.length == 0) revert IntentsValidatorSafeguardFailed();\n for (uint256 i = 0; i < safeguards.length; i++) {\n if (!_isSafeguardValid(intent, safeguards[i])) revert IntentsValidatorSafeguardFailed();\n }\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard tree\n * @param intent Intent to be validated\n * @param tree Safeguard tree to validate the intent with\n */\n function _validate(Intent memory intent, SafeguardTree memory tree) internal pure {\n if (tree.nodes.length == 0) revert IntentsValidatorSafeguardFailed();\n if (!_isSafeguardGroupValid(intent, tree, 0)) revert IntentsValidatorSafeguardFailed();\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard tree at a certain level\n * @param intent Intent to be validated\n * @param tree Safeguard tree to validate the intent with\n * @param index Index of the group node to evaluate\n */\n function _isSafeguardGroupValid(Intent memory intent, SafeguardTree memory tree, uint16 index)\n internal\n pure\n returns (bool)\n {\n SafeguardGroup memory group = tree.nodes[index];\n\n if (group.logic == uint8(SafeguardGroupLogic.NOT)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i])) return false;\n }\n return true;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.AND)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (!_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (!_isSafeguardGroupValid(intent, tree, group.children[i])) return false;\n }\n return true;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.OR)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return true;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i])) return true;\n }\n return false;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.XOR)) {\n uint256 hits = 0;\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]]))\n if (++hits > 1) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i]))\n if (++hits > 1) return false;\n }\n return hits == 1;\n }\n\n revert IntentsValidatorInvalidSafeguardGroupLogicMode(group.logic);\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard\n * @param intent Intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isSafeguardValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n if (safeguard.mode == uint8(0)) revert IntentsValidatorNoneAllowed();\n if (intent.op == uint8(OpType.Swap)) return _isSwapIntentValid(intent, safeguard);\n if (intent.op == uint8(OpType.Transfer)) return _isTransferIntentValid(intent, safeguard);\n if (intent.op == uint8(OpType.Call)) return _isCallIntentValid(intent, safeguard);\n revert IntentsValidatorUnknownIntentType(uint8(intent.op));\n }\n\n /**\n * @dev Safely decodes a safeguard tree avoiding compiler issues with dynamic arrays\n * @param data Safeguard tree data to be decoded\n */\n function _decodeSafeguardTree(bytes memory data) private pure returns (SafeguardTree memory) {\n (SafeguardGroup[] memory nodes, Safeguard[] memory leaves) = abi.decode(data, (SafeguardGroup[], Safeguard[]));\n return SafeguardTree(nodes, leaves);\n }\n}\n" + }, + "project/contracts/safeguards/Safeguards.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Safeguard config modes\n * - List: Safeguard lists\n * - Tree: Safeguard groups\n */\nenum SafeguardConfigMode {\n List,\n Tree\n}\n\n/**\n * @dev Logical operators for safeguard groups\n * - AND: every child must pass\n * - OR: at least one child must pass\n * - XOR: exactly one child must pass\n * - NOT: every child must fail\n */\nenum SafeguardGroupLogic {\n AND,\n OR,\n XOR,\n NOT\n}\n\n/**\n * @dev Flat node in the safeguard tree\n * @param logic Group operator (AND/OR/XOR/NOT)\n * @param leaves Indices into `SafeguardTree.leaves`\n * @param children Indices into `SafeguardTree.nodes`\n */\nstruct SafeguardGroup {\n uint8 logic;\n uint16[] leaves;\n uint16[] children;\n}\n\n/**\n * @dev Safeguard tree representation\n * @param nodes List of all the nodes in the tree\n * @param leaves List of all the leaves in the tree\n */\nstruct SafeguardTree {\n SafeguardGroup[] nodes;\n Safeguard[] leaves;\n}\n\n/**\n * @dev Safeguard representation\n * @param mode Safeguard mode\n * @param config Safeguard configuration settings or parameters\n */\nstruct Safeguard {\n uint8 mode;\n bytes config;\n}\n" + }, + "project/contracts/safeguards/SwapIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './BaseIntentsValidator.sol';\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Swap safeguard modes to validate swap intents\n * @param None To ensure no swaps are allowed\n * @param SourceChain To validate that the source chain is allowed\n * @param DestinationChain To validate that the destination chain is allowed\n * @param TokenIn To validate that the tokens to be sent are allowed\n * @param TokenOut To validate that the tokens to be received are allowed\n * @param Recipient To validate that the recipients that will receive the tokens are allowed\n */\nenum SwapSafeguardMode {\n None,\n SourceChain,\n DestinationChain,\n TokenIn,\n TokenOut,\n Recipient\n}\n\n/**\n * @title SwapIntentsValidator\n * @dev Performs swap intents validations based on safeguards\n */\ncontract SwapIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a swap intent is valid for a safeguard\n * @param intent Swap intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isSwapIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n if (safeguard.mode == uint8(SwapSafeguardMode.SourceChain))\n return _isChainAllowed(swapIntent.sourceChain, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.DestinationChain))\n return _isChainAllowed(swapIntent.destinationChain, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.TokenIn))\n return _areSwapTokensInValid(swapIntent.tokensIn, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.TokenOut))\n return _areSwapTokensOutValid(swapIntent.tokensOut, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.Recipient))\n return _areSwapRecipientsValid(swapIntent.tokensOut, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the tokens to be sent are allowed\n */\n function _areSwapTokensInValid(TokenIn[] memory tokensIn, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensIn.length; i++) {\n if (!_isAccountAllowed(tokensIn[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the tokens to be received are allowed\n */\n function _areSwapTokensOutValid(TokenOut[] memory tokensOut, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensOut.length; i++) {\n if (!_isAccountAllowed(tokensOut[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the recipients to be received are allowed\n */\n function _areSwapRecipientsValid(TokenOut[] memory tokensOut, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensOut.length; i++) {\n if (!_isAccountAllowed(tokensOut[i].recipient, config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/safeguards/TransferIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './BaseIntentsValidator.sol';\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Transfer safeguard modes to validate transfer intents\n * @param None To ensure no transfers are allowed\n * @param Chain To validate that the chain where transfers execute is allowed\n * @param Token To validate that the tokens being transferred are allowed\n * @param Recipient To validate that the recipients of the transfers are allowed\n */\nenum TransferSafeguardMode {\n None,\n Chain,\n Token,\n Recipient\n}\n\n/**\n * @title TransferIntentsValidator\n * @dev Performs transfer intents validations based on safeguards\n */\ncontract TransferIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a transfer intent is valid for a safeguard\n * @param intent Transfer intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isTransferIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n TransferIntent memory transferIntent = abi.decode(intent.data, (TransferIntent));\n if (safeguard.mode == uint8(TransferSafeguardMode.Chain))\n return _isChainAllowed(transferIntent.chainId, safeguard.config);\n if (safeguard.mode == uint8(TransferSafeguardMode.Token))\n return _areTransferTokensValid(transferIntent.transfers, safeguard.config);\n if (safeguard.mode == uint8(TransferSafeguardMode.Recipient))\n return _areTransferRecipientsValid(transferIntent.transfers, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the tokens being transferred are allowed\n */\n function _areTransferTokensValid(TransferData[] memory transfers, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < transfers.length; i++) {\n if (!_isAccountAllowed(transfers[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the recipients of the transfers are allowed\n */\n function _areTransferRecipientsValid(TransferData[] memory transfers, bytes memory config)\n private\n pure\n returns (bool)\n {\n for (uint256 i = 0; i < transfers.length; i++) {\n if (!_isAccountAllowed(transfers[i].recipient, config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/Settler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/cryptography/ECDSA.sol';\nimport '@openzeppelin/contracts/utils/cryptography/EIP712.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165Checker.sol';\n\nimport './Intents.sol';\nimport './interfaces/IController.sol';\nimport './interfaces/IIntentsValidator.sol';\nimport './interfaces/IExecutor.sol';\nimport './interfaces/ISettler.sol';\nimport './utils/Denominations.sol';\nimport './utils/ERC20Helpers.sol';\nimport './smart-accounts/SmartAccountsHandler.sol';\nimport './smart-accounts/SmartAccountsHandlerHelpers.sol';\n\n/**\n * @title Settler\n * @dev Contract that provides the appropriate context for solvers to execute proposals that fulfill user intents\n */\ncontract Settler is ISettler, Ownable, ReentrancyGuard, EIP712 {\n using SafeERC20 for IERC20;\n using IntentsHelpers for Intent;\n using IntentsHelpers for Proposal;\n using IntentsHelpers for Validation;\n using SmartAccountsHandlerHelpers for address;\n\n // Mimic controller reference\n // solhint-disable-next-line immutable-vars-naming\n address public immutable override controller;\n\n // Smart accounts handler reference\n address public override smartAccountsHandler;\n\n // Intents validator reference\n address public override intentsValidator;\n\n // List of block numbers at which a user nonce was used\n mapping (address => mapping (bytes32 => uint256)) public override getNonceBlock;\n\n // Safeguard config per user\n mapping (address => bytes) internal _userSafeguard;\n\n /**\n * @dev Modifier to tag settler functions in order to check if the sender is an allowed solver\n */\n modifier onlySolver() {\n address sender = _msgSender();\n if (!IController(controller).isSolverAllowed(sender)) revert SettlerSolverNotAllowed(sender);\n _;\n }\n\n /**\n * @dev Creates a new Settler contract\n * @param _controller Address of the Settler controller\n * @param _owner Address that will own the contract\n */\n constructor(address _controller, address _owner) Ownable(_owner) EIP712('Mimic Protocol Settler', '1') {\n controller = _controller;\n smartAccountsHandler = address(new SmartAccountsHandler());\n }\n\n /**\n * @dev Tells the hash of an intent\n * @param intent Intent to get the hash of\n */\n function getIntentHash(Intent memory intent) external pure override returns (bytes32) {\n return intent.hash();\n }\n\n /**\n * @dev Tells the hash of a proposal\n * @param proposal Proposal to be hashed\n * @param intent Intent being fulfilled by the requested proposal\n * @param solver Address of the solver that made the proposal\n */\n function getProposalHash(Proposal memory proposal, Intent memory intent, address solver)\n external\n pure\n override\n returns (bytes32)\n {\n return proposal.hash(intent, solver);\n }\n\n /**\n * @dev Tells the safeguard set for a user\n * @param user Address of the user being queried\n */\n function getUserSafeguard(address user) external view override returns (bytes memory) {\n return _userSafeguard[user];\n }\n\n /**\n * @dev It allows receiving native token transfers\n * Note: This method mainly allows supporting native tokens for swaps\n */\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n /**\n * @dev Withdraws ERC20 or native tokens from the contract\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function rescueFunds(address token, address recipient, uint256 amount) external override onlyOwner nonReentrant {\n if (recipient == address(0)) revert SettlerRescueFundsRecipientZero();\n ERC20Helpers.transfer(token, recipient, amount);\n emit FundsRescued(token, recipient, amount);\n }\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function setSmartAccountsHandler(address newSmartAccountsHandler) external override onlyOwner {\n _setSmartAccountsHandler(newSmartAccountsHandler);\n }\n\n /**\n * @dev Sets a new intents validator address\n * @param newIntentsValidator New intents validator to be set\n */\n function setIntentsValidator(address newIntentsValidator) external override onlyOwner {\n _setIntentsValidator(newIntentsValidator);\n }\n\n /**\n * @dev Sets a safeguard for a user\n * @param safeguard Safeguard to be set\n */\n function setSafeguard(bytes memory safeguard) external override {\n _setSafeguard(msg.sender, safeguard);\n }\n\n /**\n * @dev Executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function execute(Execution[] memory executions) external override onlySolver {\n _execute(executions, false);\n }\n\n /**\n * @dev Simulates an execution. It will always revert. Successful executions are returned as\n * `SettlerSimulationSuccess` errors. Any other error should be treated as failure.\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function simulate(Execution[] memory executions) external override onlySolver {\n uint256 initialGas = gasleft();\n _execute(executions, true);\n uint256 gasUsed = initialGas - gasleft();\n revert SettlerSimulationSuccess(gasUsed);\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n * @param simulated Whether the execution is a simulation\n */\n function _execute(Execution[] memory executions, bool simulated) internal nonReentrant {\n for (uint256 i = 0; i < executions.length; i++) {\n Intent memory intent = executions[i].intent;\n Proposal memory proposal = executions[i].proposal;\n bytes memory signature = executions[i].signature;\n\n _validateIntent(intent, proposal, signature, simulated);\n getNonceBlock[intent.user][intent.nonce] = block.number;\n\n if (intent.op == uint8(OpType.Swap)) _executeSwap(intent, proposal);\n else if (intent.op == uint8(OpType.Transfer)) _executeTransfer(intent, proposal);\n else if (intent.op == uint8(OpType.Call)) _executeCall(intent, proposal);\n else revert SettlerUnknownIntentType(uint8(intent.op));\n\n emit ProposalExecuted(proposal.hash(intent, _msgSender()), i);\n }\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a swap intent\n * @param intent Swap intent to be fulfilled\n * @param proposal Swap proposal to be executed\n */\n function _executeSwap(Intent memory intent, Proposal memory proposal) internal {\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n _validateSwapIntent(swapIntent, swapProposal);\n\n bool isSmartAccount = smartAccountsHandler.isSmartAccount(intent.user);\n if (swapIntent.sourceChain == block.chainid) {\n for (uint256 i = 0; i < swapIntent.tokensIn.length; i++) {\n TokenIn memory tokenIn = swapIntent.tokensIn[i];\n _transferFrom(tokenIn.token, intent.user, swapProposal.executor, tokenIn.amount, isSmartAccount);\n }\n }\n\n uint256[] memory preBalancesOut = _getTokensOutBalance(swapIntent);\n IExecutor(swapProposal.executor).execute(intent, proposal);\n\n if (swapIntent.destinationChain == block.chainid) {\n uint256[] memory outputs = new uint256[](swapIntent.tokensOut.length);\n for (uint256 i = 0; i < swapIntent.tokensOut.length; i++) {\n TokenOut memory tokenOut = swapIntent.tokensOut[i];\n uint256 postBalanceOut = ERC20Helpers.balanceOf(tokenOut.token, address(this));\n uint256 preBalanceOut = preBalancesOut[i];\n if (postBalanceOut < preBalanceOut) revert SettlerPostBalanceOutLtPre(i, postBalanceOut, preBalanceOut);\n\n outputs[i] = postBalanceOut - preBalanceOut;\n uint256 proposedAmount = swapProposal.amountsOut[i];\n if (outputs[i] < proposedAmount) revert SettlerAmountOutLtProposed(i, outputs[i], proposedAmount);\n\n ERC20Helpers.transfer(tokenOut.token, tokenOut.recipient, outputs[i]);\n }\n\n _emitIntentEvents(intent, proposal, abi.encode(outputs));\n _payFees(intent, proposal, isSmartAccount);\n }\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a transfer intent\n * @param intent Transfer intent to be fulfilled\n * @param proposal Transfer proposal to be executed\n */\n function _executeTransfer(Intent memory intent, Proposal memory proposal) internal {\n TransferIntent memory transferIntent = abi.decode(intent.data, (TransferIntent));\n _validateTransferIntent(transferIntent, proposal);\n\n bool isSmartAccount = smartAccountsHandler.isSmartAccount(intent.user);\n for (uint256 i = 0; i < transferIntent.transfers.length; i++) {\n TransferData memory transfer = transferIntent.transfers[i];\n _transferFrom(transfer.token, intent.user, transfer.recipient, transfer.amount, isSmartAccount);\n }\n\n _emitIntentEvents(intent, proposal, new bytes(0));\n _payFees(intent, proposal, isSmartAccount);\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a call intent\n * @param intent Call intent to be fulfilled\n * @param proposal Call proposal to be executed\n */\n function _executeCall(Intent memory intent, Proposal memory proposal) internal {\n CallIntent memory callIntent = abi.decode(intent.data, (CallIntent));\n _validateCallIntent(callIntent, proposal, intent.user);\n\n bytes[] memory outputs = new bytes[](callIntent.calls.length);\n for (uint256 i = 0; i < callIntent.calls.length; i++) {\n CallData memory call = callIntent.calls[i];\n // solhint-disable-next-line avoid-low-level-calls\n outputs[i] = smartAccountsHandler.call(intent.user, call.target, call.data, call.value);\n }\n\n _emitIntentEvents(intent, proposal, abi.encode(outputs));\n _payFees(intent, proposal, true);\n }\n\n /**\n * @dev Validates an intent and its corresponding proposal\n * @param intent Intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param signature Proposal signature\n * @param simulated Whether the execution is a simulation\n */\n function _validateIntent(Intent memory intent, Proposal memory proposal, bytes memory signature, bool simulated)\n internal\n view\n {\n if (intent.settler != address(this)) revert SettlerInvalidSettler(intent.settler);\n if (intent.nonce == bytes32(0)) revert SettlerNonceZero();\n if (getNonceBlock[intent.user][intent.nonce] != 0) revert SettlerNonceAlreadyUsed(intent.user, intent.nonce);\n\n if (intentsValidator != address(0)) {\n bytes memory safeguard = _userSafeguard[intent.user];\n if (safeguard.length > 0) IIntentsValidator(intentsValidator).validate(intent, safeguard);\n }\n\n bool shouldValidateDeadlines = _shouldValidateDeadlines(intent);\n if (shouldValidateDeadlines) {\n if (intent.deadline <= block.timestamp) revert SettlerIntentPastDeadline(intent.deadline, block.timestamp);\n bool isProposalPastDeadline = proposal.deadline <= block.timestamp;\n if (isProposalPastDeadline) revert SettlerProposalPastDeadline(proposal.deadline, block.timestamp);\n }\n\n if (intent.maxFees.length != proposal.fees.length) revert SettlerSolverFeeInvalidLength();\n for (uint256 i = 0; i < intent.maxFees.length; i++) {\n uint256 maxFee = intent.maxFees[i].amount;\n uint256 proposalFee = proposal.fees[i];\n if (proposalFee > maxFee) revert SettlerSolverFeeTooHigh(proposalFee, maxFee);\n }\n\n uint8 minValidations = IController(controller).minValidations();\n uint256 requiredValidations = intent.minValidations > minValidations ? intent.minValidations : minValidations;\n\n if (intent.validations.length < requiredValidations) {\n revert SettlerIntentValidationsNotEnough(requiredValidations, intent.validations.length);\n }\n\n address lastValidator = address(0);\n Validation memory validation = Validation(intent.hash());\n bytes32 typedDataHash = _hashTypedDataV4(validation.hash());\n for (uint256 i = 0; i < intent.validations.length; i++) {\n address validator = ECDSA.recover(typedDataHash, intent.validations[i]);\n if (validator <= lastValidator) {\n revert SettlerValidatorDuplicatedOrUnsorted(lastValidator, validator);\n }\n lastValidator = validator;\n bool isValidatorNotAllowed = !IController(controller).isValidatorAllowed(validator);\n if (isValidatorNotAllowed) revert SettlerValidatorNotAllowed(validator);\n }\n\n address signer = ECDSA.recover(_hashTypedDataV4(proposal.hash(intent, _msgSender())), signature);\n bool isProposalSignerNotAllowed = !IController(controller).isProposalSignerAllowed(signer) && !simulated;\n if (isProposalSignerNotAllowed) revert SettlerProposalSignerNotAllowed(signer);\n }\n\n /**\n * @dev Validates a swap intent and its corresponding proposal\n * @param intent Swap intent to be fulfilled\n * @param proposal Proposal to be executed\n */\n function _validateSwapIntent(SwapIntent memory intent, SwapProposal memory proposal) internal view {\n bool isChainInvalid = intent.sourceChain != block.chainid && intent.destinationChain != block.chainid;\n if (isChainInvalid) revert SettlerInvalidChain(block.chainid);\n\n if (proposal.amountsOut.length != intent.tokensOut.length) revert SettlerInvalidProposedAmounts();\n\n for (uint256 i = 0; i < intent.tokensOut.length; i++) {\n TokenOut memory tokenOut = intent.tokensOut[i];\n address recipient = tokenOut.recipient;\n if (recipient == address(this)) revert SettlerInvalidRecipient(recipient);\n\n uint256 minAmount = tokenOut.minAmount;\n uint256 proposedAmount = proposal.amountsOut[i];\n if (proposedAmount < minAmount) revert SettlerProposedAmountLtMinAmount(i, proposedAmount, minAmount);\n }\n\n if (intent.sourceChain != intent.destinationChain) {\n bool isExecutorInvalid = !IController(controller).isExecutorAllowed(proposal.executor);\n if (isExecutorInvalid) revert SettlerExecutorNotAllowed(proposal.executor);\n }\n }\n\n /**\n * @dev Validates a transfer intent and its corresponding proposal\n * @param intent Transfer intent to be fulfilled\n * @param proposal Proposal to be executed\n */\n function _validateTransferIntent(TransferIntent memory intent, Proposal memory proposal) internal view {\n if (intent.chainId != block.chainid) revert SettlerInvalidChain(block.chainid);\n if (proposal.data.length > 0) revert SettlerProposalDataNotEmpty();\n for (uint256 i = 0; i < intent.transfers.length; i++) {\n address recipient = intent.transfers[i].recipient;\n if (recipient == address(this)) revert SettlerInvalidRecipient(recipient);\n }\n }\n\n /**\n * @dev Validates a call intent and its corresponding proposal\n * @param intent Call intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param user The originator of the intent\n */\n function _validateCallIntent(CallIntent memory intent, Proposal memory proposal, address user) internal view {\n if (intent.chainId != block.chainid) revert SettlerInvalidChain(block.chainid);\n if (proposal.data.length > 0) revert SettlerProposalDataNotEmpty();\n if (!smartAccountsHandler.isSmartAccount(user)) revert SettlerUserNotSmartAccount(user);\n }\n\n /**\n * @dev Tells the contract balance for each token out of a swap intent\n * @param intent Swap intent containing the list of tokens out\n */\n function _getTokensOutBalance(SwapIntent memory intent) internal view returns (uint256[] memory balances) {\n balances = new uint256[](intent.tokensOut.length);\n if (intent.destinationChain == block.chainid) {\n for (uint256 i = 0; i < intent.tokensOut.length; i++) {\n balances[i] = ERC20Helpers.balanceOf(intent.tokensOut[i].token, address(this));\n }\n }\n }\n\n /**\n * @dev Tells if the intent and proposal deadlines should be validated\n * @param intent Intent to be fulfilled\n */\n function _shouldValidateDeadlines(Intent memory intent) internal view returns (bool) {\n if (intent.op != uint8(OpType.Swap)) return true;\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n if (swapIntent.sourceChain == swapIntent.destinationChain) return true;\n return swapIntent.sourceChain == block.chainid;\n }\n\n /**\n * @dev Emits intent custom events\n * @param intent Intent to emit the custom events for\n * @param proposal Proposal that fulfills the intent\n * @param output Encoded array of outputs\n */\n function _emitIntentEvents(Intent memory intent, Proposal memory proposal, bytes memory output) internal {\n for (uint256 i = 0; i < intent.events.length; i++) {\n IntentEvent memory intentEvent = intent.events[i];\n emit IntentExecuted(\n intent.user,\n intentEvent.topic,\n uint8(intent.op),\n intent,\n proposal,\n output,\n intentEvent.data\n );\n }\n }\n\n /**\n * @dev Pays fees\n * @param intent Intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param isSmartAccount Whether the intent user is a smart account\n */\n function _payFees(Intent memory intent, Proposal memory proposal, bool isSmartAccount) internal {\n address from = intent.user;\n address to = _msgSender();\n for (uint256 i = 0; i < intent.maxFees.length; i++) {\n address token = intent.maxFees[i].token;\n if (!Denominations.isUSD(token)) _transferFrom(token, from, to, proposal.fees[i], isSmartAccount);\n }\n }\n\n /**\n * @dev Transfers tokens from one account to another\n * @param token Address of the token to transfer\n * @param from Address of the account sending the tokens\n * @param to Address of the account receiving the tokens\n * @param amount Amount of tokens to transfer\n * @param isSmartAccount Whether the sender is a smart account\n */\n function _transferFrom(address token, address from, address to, uint256 amount, bool isSmartAccount) internal {\n if (isSmartAccount) {\n smartAccountsHandler.transfer(from, token, to, amount);\n } else {\n IERC20(token).safeTransferFrom(from, to, amount);\n }\n }\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function _setSmartAccountsHandler(address newSmartAccountsHandler) internal {\n if (newSmartAccountsHandler == address(0)) revert SmartAccountsHandlerZero();\n smartAccountsHandler = newSmartAccountsHandler;\n emit SmartAccountsHandlerSet(newSmartAccountsHandler);\n }\n\n /**\n * @dev Sets the intents validator\n * @param newIntentsValidator New intents validator to be set\n */\n function _setIntentsValidator(address newIntentsValidator) internal {\n intentsValidator = newIntentsValidator;\n emit IntentsValidatorSet(newIntentsValidator);\n }\n\n /**\n * @dev Sets a safeguard for a user\n * @param user Address of the user to set the safeguard for\n * @param safeguard Safeguard to be set\n */\n function _setSafeguard(address user, bytes memory safeguard) internal {\n delete _userSafeguard[user];\n _userSafeguard[user] = safeguard;\n emit SafeguardSet(user);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccount7702.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/Context.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccount.sol';\nimport '../utils/ERC20Helpers.sol';\nimport './SmartAccountBase.sol';\n\n/**\n * @title SmartAccount7702\n * @dev Provides the smart account logic to use with EIP7702\n */\ncontract SmartAccount7702 is SmartAccountBase {\n // Mimic settler reference\n // solhint-disable-next-line immutable-vars-naming\n address public immutable settler;\n\n /**\n * @dev The sender is not the settler\n */\n error SmartAccount7702SenderNotSettler();\n\n /**\n * @dev Reverts unless the sender is the settler\n */\n modifier onlySettler() {\n if (_msgSender() != settler) revert SmartAccount7702SenderNotSettler();\n _;\n }\n\n /**\n * @dev Creates a new SmartAccount7702 contract\n * @param _settler Address of the Mimic settler\n */\n constructor(address _settler) {\n settler = _settler;\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) public override onlySettler {\n super.transfer(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value) public override onlySettler returns (bytes memory) {\n // solhint-disable-next-line avoid-low-level-calls\n return super.call(target, data, value);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountBase.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/Context.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccount.sol';\nimport '../utils/ERC20Helpers.sol';\n\n/**\n * @title SmartAccountBase\n * @dev Provides the base logic for managing assets and executing arbitrary calls\n */\ncontract SmartAccountBase is ISmartAccount, Context, ERC165, ReentrancyGuard {\n /**\n * @dev Tells whether the contract supports the given interface ID. Overrides ERC165 to declare support for ISmartAccount interface.\n * @param interfaceId Interface ID is defined as the XOR of all function selectors in the interface\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {\n return interfaceId == type(ISmartAccount).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) public virtual override nonReentrant {\n ERC20Helpers.transfer(token, recipient, amount);\n emit Transferred(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value)\n public\n virtual\n override\n nonReentrant\n returns (bytes memory result)\n {\n result = Address.functionCallWithValue(target, data, value);\n emit Called(target, data, value, result);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountContract.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/cryptography/ECDSA.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccountContract.sol';\nimport './SmartAccountBase.sol';\n\n/**\n * @title SmartAccountContract\n * @dev Provides the smart account logic to use as a standalone contract\n */\ncontract SmartAccountContract is ISmartAccountContract, Ownable, SmartAccountBase {\n // EIP1271 magic return value\n bytes4 internal constant EIP1271_MAGIC_VALUE = 0x1626ba7e;\n\n // EIP1271 invalid signature return value\n bytes4 internal constant EIP1271_INVALID_SIGNATURE = 0xffffffff;\n\n // List of account permissions\n mapping (address => bool) public isSignerAllowed;\n\n // Mimic settler reference\n address public settler;\n\n /**\n * @dev The settler is zero\n */\n error SmartAccountSettlerZero();\n\n /**\n * @dev The input arrays are not of equal length\n */\n error SmartAccountInputInvalidLength();\n\n /**\n * @dev The sender is not the owner or the settler\n */\n error SmartAccountUnauthorizedSender(address sender);\n\n /**\n * @dev Emitted every time the settler is set\n */\n event SettlerSet(address indexed settler);\n\n /**\n * @dev Emitted every time a signer allowance is set\n */\n event SignerAllowedSet(address indexed account, bool allowed);\n\n /**\n * @dev Reverts unless the sender is the owner or the settler\n */\n modifier onlyOwnerOrSettler() {\n address sender = _msgSender();\n bool isAuthorized = sender == owner() || sender == settler;\n if (!isAuthorized) revert SmartAccountUnauthorizedSender(sender);\n _;\n }\n\n /**\n * @dev Creates a new SmartAccount contract\n * @param _settler Address of the Mimic settler\n * @param _owner Address that will own the contract\n */\n constructor(address _settler, address _owner) Ownable(_owner) {\n _setSettler(_settler);\n }\n\n /**\n * @dev Tells whether the signature provided belongs to an allowed account.\n * @param hash Message signed by the account\n * @param signature Signature provided to be verified\n */\n function isValidSignature(bytes32 hash, bytes memory signature) external view override returns (bytes4) {\n (address signer, , ) = ECDSA.tryRecover(hash, signature);\n if (signer != address(0) && (signer == owner() || isSignerAllowed[signer])) return EIP1271_MAGIC_VALUE;\n return EIP1271_INVALID_SIGNATURE;\n }\n\n /**\n * @dev It allows receiving native token transfers\n */\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n /**\n * @dev Sets the settler. Sender must be the owner.\n * @param newSettler Address of the new settler to be set\n */\n function setSettler(address newSettler) external onlyOwner {\n _setSettler(newSettler);\n }\n\n /**\n * @dev Sets a list of allowed signers. Sender must be the owner.\n * @param accounts List of account addresses\n * @param allowances List of allowed condition per account\n */\n function setAllowedSigners(address[] memory accounts, bool[] memory allowances) external onlyOwner {\n if (accounts.length != allowances.length) revert SmartAccountInputInvalidLength();\n for (uint256 i = 0; i < accounts.length; i++) {\n address account = accounts[i];\n bool allowed = allowances[i];\n isSignerAllowed[account] = allowed;\n emit SignerAllowedSet(account, allowed);\n }\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the owner or the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount)\n public\n override(ISmartAccount, SmartAccountBase)\n onlyOwnerOrSettler\n {\n super.transfer(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the owner or the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value)\n public\n override(ISmartAccount, SmartAccountBase)\n onlyOwnerOrSettler\n returns (bytes memory)\n {\n // solhint-disable-next-line avoid-low-level-calls\n return super.call(target, data, value);\n }\n\n /**\n * @dev Sets the settler\n * @param newSettler Address of the new settler to be set\n */\n function _setSettler(address newSettler) internal {\n if (newSettler == address(0)) revert SmartAccountSettlerZero();\n settler = newSettler;\n emit SettlerSet(newSettler);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountsHandler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport '../interfaces/ISafe.sol';\nimport '../interfaces/ISmartAccount.sol';\nimport '../interfaces/ISmartAccountsHandler.sol';\nimport '../utils/Denominations.sol';\n\ncontract SmartAccountsHandler is ISmartAccountsHandler {\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address account) external view override returns (bool) {\n if (account.code.length == 0) return false;\n if (_isMimicSmartAccount(account)) return true;\n if (_isSafe(account)) return true;\n return false;\n }\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address account, address token, address to, uint256 amount) external override {\n if (_isMimicSmartAccount(account)) return ISmartAccount(account).transfer(token, to, amount);\n if (_isSafe(account)) return _transferSafe(account, token, to, amount);\n revert SmartAccountsHandlerUnsupportedAccount(account);\n }\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address account, address target, bytes memory data, uint256 value)\n external\n override\n returns (bytes memory)\n {\n // solhint-disable-next-line avoid-low-level-calls\n if (_isMimicSmartAccount(account)) return ISmartAccount(account).call(target, data, value);\n if (_isSafe(account)) return _callSafe(account, target, data, value);\n revert SmartAccountsHandlerUnsupportedAccount(account);\n }\n\n /**\n * @dev Performs a transfer from a safe\n */\n function _transferSafe(address account, address token, address to, uint256 amount) internal {\n Denominations.isNativeToken(token)\n ? _callSafe(account, to, new bytes(0), amount)\n : _callSafe(account, token, abi.encodeWithSelector(IERC20.transfer.selector, to, amount), 0);\n }\n\n /**\n * @dev Performs a call from a safe\n */\n function _callSafe(address account, address target, bytes memory data, uint256 value)\n internal\n returns (bytes memory)\n {\n (bool success, bytes memory result) = ISafe(account).execTransactionFromModuleReturnData(\n target,\n value,\n data,\n SafeOperation.Call\n );\n return\n data.length == 0\n ? Address.verifyCallResult(success, result)\n : Address.verifyCallResultFromTarget(target, success, result);\n }\n\n /**\n * @dev Tells whether an account is a Mimic smart account\n * @param account Address of the account being queried\n */\n function _isMimicSmartAccount(address account) internal view returns (bool) {\n try ISmartAccount(account).supportsInterface(type(ISmartAccount).interfaceId) returns (bool ok) {\n return ok;\n } catch {\n return false;\n }\n }\n\n /**\n * @dev Tells whether an account is a Gnosis Safe\n * @param account Address of the account being queried\n */\n function _isSafe(address account) internal view returns (bool) {\n try ISafe(account).getThreshold() returns (uint256) {\n return true;\n } catch {\n return false;\n }\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountsHandlerHelpers.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport '../interfaces/ISmartAccountsHandler.sol';\n\nlibrary SmartAccountsHandlerHelpers {\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address handler, address account) internal view returns (bool) {\n return ISmartAccountsHandler(handler).isSmartAccount(account);\n }\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address handler, address account, address token, address to, uint256 amount) internal {\n Address.functionDelegateCall(\n handler,\n abi.encodeWithSelector(ISmartAccountsHandler.transfer.selector, account, token, to, amount)\n );\n }\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address handler, address account, address target, bytes memory data, uint256 value)\n internal\n returns (bytes memory)\n {\n return\n Address.functionDelegateCall(\n handler,\n abi.encodeWithSelector(ISmartAccountsHandler.call.selector, account, target, data, value)\n );\n }\n}\n" + }, + "project/contracts/test/CallMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\ncontract CallMock {\n event CallReceived(address indexed sender, uint256 value);\n error CallError();\n\n function call() external payable {\n emit CallReceived(msg.sender, msg.value);\n }\n\n function callError() external payable {\n revert CallError();\n }\n}\n" + }, + "project/contracts/test/executors/EmptyExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\n\ncontract EmptyExecutorMock is IExecutor {\n event Executed();\n\n function execute(Intent memory, Proposal memory) external override {\n emit Executed();\n }\n}\n" + }, + "project/contracts/test/executors/MintExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../TokenMock.sol';\nimport '../../interfaces/IExecutor.sol';\n\n/* solhint-disable custom-errors */\n\ncontract MintExecutorMock is IExecutor {\n event Minted();\n\n function execute(Intent memory intent, Proposal memory proposal) external override {\n require(intent.op == uint8(OpType.Swap), 'Invalid intent type');\n\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n (address[] memory tokens, uint256[] memory amounts) = abi.decode(swapProposal.data, (address[], uint256[]));\n\n require(tokens.length == amounts.length, 'Invalid inputs');\n\n for (uint256 i = 0; i < tokens.length; i++) {\n TokenMock(tokens[i]).mint(msg.sender, amounts[i]);\n emit Minted();\n }\n }\n}\n" + }, + "project/contracts/test/executors/ReentrantExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\nimport '../../interfaces/ISettler.sol';\n\ncontract ReentrantExecutorMock is IExecutor {\n // solhint-disable-next-line immutable-vars-naming\n address payable public immutable settler;\n\n constructor(address payable _settler) {\n settler = _settler;\n }\n\n function execute(Intent memory, Proposal memory) external override {\n ISettler(settler).execute(new Execution[](0));\n }\n}\n" + }, + "project/contracts/test/executors/TransferExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\nimport '../../utils/ERC20Helpers.sol';\n\n/* solhint-disable custom-errors */\n\ncontract TransferExecutorMock is IExecutor {\n event Transferred();\n\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n function execute(Intent memory intent, Proposal memory proposal) external override {\n require(intent.op == uint8(OpType.Swap), 'Invalid intent type');\n\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n (address[] memory tokens, uint256[] memory amounts) = abi.decode(swapProposal.data, (address[], uint256[]));\n\n require(tokens.length == amounts.length, 'Invalid inputs');\n\n for (uint256 i = 0; i < tokens.length; i++) {\n ERC20Helpers.transfer(tokens[i], msg.sender, amounts[i]);\n emit Transferred();\n }\n }\n}\n" + }, + "project/contracts/test/smart-accounts/SafeMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/ISafe.sol';\n\ncontract SafeMock is ISafe {\n event ModuleTxExecuted(\n address indexed target,\n bytes data,\n uint256 value,\n SafeOperation operation,\n bool success,\n bytes result\n );\n\n receive() external payable {}\n\n function getThreshold() external pure returns (uint256) {\n return 1;\n }\n\n function execTransactionFromModuleReturnData(address to, uint256 value, bytes memory data, SafeOperation operation)\n external\n returns (bool success, bytes memory result)\n {\n // solhint-disable-next-line avoid-low-level-calls\n (success, result) = to.call{ value: value }(data);\n emit ModuleTxExecuted(to, data, value, operation, success, result);\n }\n}\n" + }, + "project/contracts/test/TokenMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/ERC20.sol';\n\ncontract TokenMock is ERC20 {\n uint8 internal _decimals;\n\n constructor(string memory symbol, uint8 dec) ERC20(symbol, symbol) {\n _decimals = dec;\n }\n\n function mint(address account, uint256 amount) external {\n _mint(account, amount);\n }\n\n function decimals() public view override returns (uint8) {\n return _decimals;\n }\n}\n" + }, + "project/contracts/test/utils/DenominationsMock.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '../../utils/Denominations.sol';\n\n// solhint-disable func-name-mixedcase\n\ncontract DenominationsMock {\n function NATIVE_TOKEN() external pure returns (address) {\n return Denominations.NATIVE_TOKEN;\n }\n\n function USD() external pure returns (address) {\n return Denominations.USD;\n }\n}\n" + }, + "project/contracts/test/utils/ERC20HelpersMock.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '../../utils/ERC20Helpers.sol';\n\ncontract ERC20HelpersMock {\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n function approve(address token, address to, uint256 amount) external {\n ERC20Helpers.approve(token, to, amount);\n }\n\n function transfer(address token, address to, uint256 amount) external {\n ERC20Helpers.transfer(token, to, amount);\n }\n\n function balanceOf(address token, address account) external view returns (uint256) {\n return ERC20Helpers.balanceOf(token, account);\n }\n}\n" + }, + "project/contracts/utils/Denominations.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\n/**\n * @title Denominations\n * @dev Provides a list of ground denominations for those tokens that cannot be represented by an ERC20.\n * For now, the only needed is the native token that could be ETH, MATIC, or other depending on the layer being operated.\n */\nlibrary Denominations {\n address internal constant NATIVE_TOKEN = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;\n\n // Fiat currencies follow https://en.wikipedia.org/wiki/ISO_4217\n address internal constant USD = address(840);\n\n function isUSD(address token) internal pure returns (bool) {\n return token == USD;\n }\n\n function isNativeToken(address token) internal pure returns (bool) {\n return token == NATIVE_TOKEN;\n }\n}\n" + }, + "project/contracts/utils/ERC20Helpers.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport './Denominations.sol';\n\n/**\n * @title ERC20Helpers\n * @dev Provides a list of ERC20 helper methods\n */\nlibrary ERC20Helpers {\n function approve(address token, address to, uint256 amount) internal {\n SafeERC20.forceApprove(IERC20(token), to, amount);\n }\n\n function transfer(address token, address to, uint256 amount) internal {\n if (Denominations.isNativeToken(token)) Address.sendValue(payable(to), amount);\n else SafeERC20.safeTransfer(IERC20(token), to, amount);\n }\n\n function balanceOf(address token, address account) internal view returns (uint256) {\n if (Denominations.isNativeToken(token)) return address(account).balance;\n else return IERC20(token).balanceOf(address(account));\n }\n}\n" + }, + "project/contracts/utils/MimicHelper.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\n/**\n * @title Mimic Helper\n * @dev Collection of helper functions for the Mimic Protocol\n */\ncontract MimicHelper {\n /**\n * @dev Tells the native token balance of an address\n * @param target Address to get native token balance\n */\n function getNativeTokenBalance(address target) external view returns (uint256) {\n return target.balance;\n }\n}\n" + } + } + } +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-8453/deployed_addresses.json b/packages/evm/ignition/deployments/chain-8453/deployed_addresses.json index a1a41be..e981fe5 100644 --- a/packages/evm/ignition/deployments/chain-8453/deployed_addresses.json +++ b/packages/evm/ignition/deployments/chain-8453/deployed_addresses.json @@ -2,5 +2,7 @@ "Create3Controller#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", "Create3Controller#Controller": "0x6002825BabC837776A08799404fA55f15DCedA6b", "Create3Settler#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", - "Create3Settler#Settler": "0x609d831C0068844e11eF85a273c7F356212Fd6D1" + "Create3Settler#Settler": "0x609d831C0068844e11eF85a273c7F356212Fd6D1", + "Create3MimicHelper#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", + "Create3MimicHelper#MimicHelper": "0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0" } \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-8453/journal.jsonl b/packages/evm/ignition/deployments/chain-8453/journal.jsonl index 7a7f49e..c9773c9 100644 --- a/packages/evm/ignition/deployments/chain-8453/journal.jsonl +++ b/packages/evm/ignition/deployments/chain-8453/journal.jsonl @@ -17,4 +17,13 @@ {"futureId":"Create3Settler#ICreateX.deployCreate3","hash":"0xe0ba0e4e86ee0af62924bee6c70cc98ee620847fb6694605616494ff176bdf1d","networkInteractionId":1,"receipt":{"blockHash":"0xb802cb535ce89139c882a018824b4929c0f94daa731bb69b2eed9439e711a731","blockNumber":36013782,"logs":[{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":235,"topics":["0x2feea65dd4e9f9cbd86b74b7734210c59a1b2981b5b137bd0ee3e208200c9067","0x0000000000000000000000001a68cee754105b3f806c92f6f59e3175f0b0fc2c","0xd5d101dbdd8374fa4f730d105879acbe6c9855ed7be06a019574ba923a935d7d"]},{"address":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","data":"0x","logIndex":236,"topics":["0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000003a0ce8115b4913f42c4928d6bc3f554e9a81468b"]},{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":237,"topics":["0x4db17dd5e4732fb6da34a148104a592783ca119a1e7bb8829eba6cbadef0b511","0x000000000000000000000000609d831c0068844e11ef85a273c7f356212fd6d1"]}],"status":"SUCCESS"},"type":"TRANSACTION_CONFIRM"} {"futureId":"Create3Settler#ICreateX.deployCreate3","result":{"type":"SUCCESS"},"type":"CALL_EXECUTION_STATE_COMPLETE"} {"artifactId":"Create3Settler#ICreateX","dependencies":["Create3Settler#ICreateX.deployCreate3","Create3Settler#ICreateX"],"emitterAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","eventIndex":0,"eventName":"ContractCreation","futureId":"Create3Settler#ICreateX.ContractCreation.newContract.0","nameOrIndex":"newContract","result":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","strategy":"basic","strategyConfig":{},"txToReadFrom":"0xe0ba0e4e86ee0af62924bee6c70cc98ee620847fb6694605616494ff176bdf1d","type":"READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE"} -{"artifactId":"Create3Settler#Settler","contractAddress":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","contractName":"Settler","dependencies":["Create3Settler#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3Settler#Settler","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} \ No newline at end of file +{"artifactId":"Create3Settler#Settler","contractAddress":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","contractName":"Settler","dependencies":["Create3Settler#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3Settler#Settler","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} +{"artifactId":"Create3MimicHelper#ICreateX","contractAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","contractName":"ICreateX","dependencies":[],"futureId":"Create3MimicHelper#ICreateX","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} +{"args":["0x3a0ce8115b4913f42c4928d6bc3f554e9a81468b000000000000000000000040","0x6080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033"],"artifactId":"Create3MimicHelper#ICreateX","contractAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","dependencies":["Create3MimicHelper#ICreateX"],"from":"0x3a0ce8115b4913f42c4928d6bc3f554e9a81468b","functionName":"deployCreate3","futureId":"Create3MimicHelper#ICreateX.deployCreate3","strategy":"basic","strategyConfig":{},"type":"CALL_EXECUTION_STATE_INITIALIZE","value":{"_kind":"bigint","value":"0"}} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteraction":{"data":"0x9c36a2863a0ce8115b4913f42c4928d6bc3f554e9a81468b000000000000000000000040000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e96080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c00330000000000000000000000000000000000000000000000","id":1,"to":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","type":"ONCHAIN_INTERACTION","value":{"_kind":"bigint","value":"0"}},"type":"NETWORK_INTERACTION_REQUEST"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteractionId":1,"nonce":50,"type":"TRANSACTION_PREPARE_SEND"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteractionId":1,"nonce":50,"transaction":{"fees":{"maxFeePerGas":{"_kind":"bigint","value":"5341868"},"maxPriorityFeePerGas":{"_kind":"bigint","value":"1000000"}},"hash":"0xc6f72f92e7342998560e6b557847147a9b0a0c3daac25409f5b82808b44e7bde"},"type":"TRANSACTION_SEND"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","hash":"0xc6f72f92e7342998560e6b557847147a9b0a0c3daac25409f5b82808b44e7bde","networkInteractionId":1,"receipt":{"blockHash":"0xe8c29fa7fb9873ad919fcbdbb3b211e69b976b9c94e117cf656f0576e9c14990","blockNumber":41331990,"logs":[{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":370,"topics":["0x2feea65dd4e9f9cbd86b74b7734210c59a1b2981b5b137bd0ee3e208200c9067","0x0000000000000000000000009074e2fea6f668ccf7fb884fac62943acc03ea43","0x721f4d59bffa983c2a99dc5a3b93053d035180c65840e4dc318b06bb0484a80f"]},{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":371,"topics":["0x4db17dd5e4732fb6da34a148104a592783ca119a1e7bb8829eba6cbadef0b511","0x0000000000000000000000004766ef65d66e8d2d92f3089ee42e5705e8817ff0"]}],"status":"SUCCESS"},"type":"TRANSACTION_CONFIRM"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","result":{"type":"SUCCESS"},"type":"CALL_EXECUTION_STATE_COMPLETE"} +{"artifactId":"Create3MimicHelper#ICreateX","dependencies":["Create3MimicHelper#ICreateX.deployCreate3","Create3MimicHelper#ICreateX"],"emitterAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","eventIndex":0,"eventName":"ContractCreation","futureId":"Create3MimicHelper#ICreateX.ContractCreation.newContract.0","nameOrIndex":"newContract","result":"0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0","strategy":"basic","strategyConfig":{},"txToReadFrom":"0xc6f72f92e7342998560e6b557847147a9b0a0c3daac25409f5b82808b44e7bde","type":"READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE"} +{"artifactId":"Create3MimicHelper#MimicHelper","contractAddress":"0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0","contractName":"MimicHelper","dependencies":["Create3MimicHelper#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3MimicHelper#MimicHelper","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-84532/artifacts/Create3MimicHelper#ICreateX.dbg.json b/packages/evm/ignition/deployments/chain-84532/artifacts/Create3MimicHelper#ICreateX.dbg.json new file mode 100644 index 0000000..817dddf --- /dev/null +++ b/packages/evm/ignition/deployments/chain-84532/artifacts/Create3MimicHelper#ICreateX.dbg.json @@ -0,0 +1,4 @@ +{ + "_format": "hh-sol-dbg-1", + "buildInfo": "../build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-84532/artifacts/Create3MimicHelper#ICreateX.json b/packages/evm/ignition/deployments/chain-84532/artifacts/Create3MimicHelper#ICreateX.json new file mode 100644 index 0000000..a4701c6 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-84532/artifacts/Create3MimicHelper#ICreateX.json @@ -0,0 +1,51 @@ +{ + "_format": "hh3-artifact-1", + "contractName": "ICreateX", + "sourceName": "contracts/interfaces/ICreateX.sol", + "abi": [ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "newContract", + "type": "address" + } + ], + "name": "ContractCreation", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "salt", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "initCode", + "type": "bytes" + } + ], + "name": "deployCreate3", + "outputs": [ + { + "internalType": "address", + "name": "newContract", + "type": "address" + } + ], + "stateMutability": "payable", + "type": "function" + } + ], + "bytecode": "0x", + "deployedBytecode": "0x", + "linkReferences": {}, + "deployedLinkReferences": {}, + "immutableReferences": {}, + "inputSourceName": "project/contracts/interfaces/ICreateX.sol", + "buildInfoId": "b650d0a8e9df290d290e91b2999a1f7443c2b528" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-84532/artifacts/Create3MimicHelper#MimicHelper.dbg.json b/packages/evm/ignition/deployments/chain-84532/artifacts/Create3MimicHelper#MimicHelper.dbg.json new file mode 100644 index 0000000..817dddf --- /dev/null +++ b/packages/evm/ignition/deployments/chain-84532/artifacts/Create3MimicHelper#MimicHelper.dbg.json @@ -0,0 +1,4 @@ +{ + "_format": "hh-sol-dbg-1", + "buildInfo": "../build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-84532/artifacts/Create3MimicHelper#MimicHelper.json b/packages/evm/ignition/deployments/chain-84532/artifacts/Create3MimicHelper#MimicHelper.json new file mode 100644 index 0000000..a01b577 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-84532/artifacts/Create3MimicHelper#MimicHelper.json @@ -0,0 +1,33 @@ +{ + "_format": "hh3-artifact-1", + "contractName": "MimicHelper", + "sourceName": "contracts/utils/MimicHelper.sol", + "abi": [ + { + "inputs": [ + { + "internalType": "address", + "name": "target", + "type": "address" + } + ], + "name": "getNativeTokenBalance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + } + ], + "bytecode": "0x6080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033", + "deployedBytecode": "0x6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033", + "linkReferences": {}, + "deployedLinkReferences": {}, + "immutableReferences": {}, + "inputSourceName": "project/contracts/utils/MimicHelper.sol", + "buildInfoId": "b650d0a8e9df290d290e91b2999a1f7443c2b528" +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-84532/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json b/packages/evm/ignition/deployments/chain-84532/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json new file mode 100644 index 0000000..657a777 --- /dev/null +++ b/packages/evm/ignition/deployments/chain-84532/build-info/b650d0a8e9df290d290e91b2999a1f7443c2b528.json @@ -0,0 +1,290 @@ +{ + "_format": "hh3-sol-build-info-1", + "id": "b650d0a8e9df290d290e91b2999a1f7443c2b528", + "solcVersion": "0.8.28", + "solcLongVersion": "0.8.28+commit.7893614a", + "userSourceNameMap": { + "contracts/Controller.sol": "project/contracts/Controller.sol", + "contracts/Intents.sol": "project/contracts/Intents.sol", + "contracts/Settler.sol": "project/contracts/Settler.sol", + "contracts/interfaces/IController.sol": "project/contracts/interfaces/IController.sol", + "contracts/interfaces/ICreateX.sol": "project/contracts/interfaces/ICreateX.sol", + "contracts/interfaces/IExecutor.sol": "project/contracts/interfaces/IExecutor.sol", + "contracts/interfaces/IIntentsValidator.sol": "project/contracts/interfaces/IIntentsValidator.sol", + "contracts/interfaces/ISafe.sol": "project/contracts/interfaces/ISafe.sol", + "contracts/interfaces/ISettler.sol": "project/contracts/interfaces/ISettler.sol", + "contracts/interfaces/ISmartAccount.sol": "project/contracts/interfaces/ISmartAccount.sol", + "contracts/interfaces/ISmartAccountContract.sol": "project/contracts/interfaces/ISmartAccountContract.sol", + "contracts/interfaces/ISmartAccountsHandler.sol": "project/contracts/interfaces/ISmartAccountsHandler.sol", + "contracts/safeguards/BaseIntentsValidator.sol": "project/contracts/safeguards/BaseIntentsValidator.sol", + "contracts/safeguards/CallIntentsValidator.sol": "project/contracts/safeguards/CallIntentsValidator.sol", + "contracts/safeguards/IntentsValidator.sol": "project/contracts/safeguards/IntentsValidator.sol", + "contracts/safeguards/Safeguards.sol": "project/contracts/safeguards/Safeguards.sol", + "contracts/safeguards/SwapIntentsValidator.sol": "project/contracts/safeguards/SwapIntentsValidator.sol", + "contracts/safeguards/TransferIntentsValidator.sol": "project/contracts/safeguards/TransferIntentsValidator.sol", + "contracts/smart-accounts/SmartAccount7702.sol": "project/contracts/smart-accounts/SmartAccount7702.sol", + "contracts/smart-accounts/SmartAccountBase.sol": "project/contracts/smart-accounts/SmartAccountBase.sol", + "contracts/smart-accounts/SmartAccountContract.sol": "project/contracts/smart-accounts/SmartAccountContract.sol", + "contracts/smart-accounts/SmartAccountsHandler.sol": "project/contracts/smart-accounts/SmartAccountsHandler.sol", + "contracts/smart-accounts/SmartAccountsHandlerHelpers.sol": "project/contracts/smart-accounts/SmartAccountsHandlerHelpers.sol", + "contracts/test/CallMock.sol": "project/contracts/test/CallMock.sol", + "contracts/test/TokenMock.sol": "project/contracts/test/TokenMock.sol", + "contracts/test/executors/EmptyExecutorMock.sol": "project/contracts/test/executors/EmptyExecutorMock.sol", + "contracts/test/executors/MintExecutorMock.sol": "project/contracts/test/executors/MintExecutorMock.sol", + "contracts/test/executors/ReentrantExecutorMock.sol": "project/contracts/test/executors/ReentrantExecutorMock.sol", + "contracts/test/executors/TransferExecutorMock.sol": "project/contracts/test/executors/TransferExecutorMock.sol", + "contracts/test/smart-accounts/SafeMock.sol": "project/contracts/test/smart-accounts/SafeMock.sol", + "contracts/test/utils/DenominationsMock.sol": "project/contracts/test/utils/DenominationsMock.sol", + "contracts/test/utils/ERC20HelpersMock.sol": "project/contracts/test/utils/ERC20HelpersMock.sol", + "contracts/utils/Denominations.sol": "project/contracts/utils/Denominations.sol", + "contracts/utils/ERC20Helpers.sol": "project/contracts/utils/ERC20Helpers.sol", + "contracts/utils/MimicHelper.sol": "project/contracts/utils/MimicHelper.sol" + }, + "input": { + "language": "Solidity", + "settings": { + "optimizer": { + "enabled": true, + "runs": 1000 + }, + "evmVersion": "cancun", + "outputSelection": { + "*": { + "": [ + "ast" + ], + "*": [ + "abi", + "evm.bytecode", + "evm.deployedBytecode", + "evm.methodIdentifiers", + "metadata" + ] + } + }, + "remappings": [ + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/", + "project/:@openzeppelin/contracts/=npm/@openzeppelin/contracts@5.3.0/" + ] + }, + "sources": { + "npm/@openzeppelin/contracts@5.3.0/access/Ownable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)\n\npragma solidity ^0.8.20;\n\nimport {Context} from \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * The initial owner is set to the address provided by the deployer. This can\n * later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n /**\n * @dev The caller account is not authorized to perform an operation.\n */\n error OwnableUnauthorizedAccount(address account);\n\n /**\n * @dev The owner is not a valid owner account. (eg. `address(0)`)\n */\n error OwnableInvalidOwner(address owner);\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the address provided by the deployer as the initial owner.\n */\n constructor(address initialOwner) {\n if (initialOwner == address(0)) {\n revert OwnableInvalidOwner(address(0));\n }\n _transferOwnership(initialOwner);\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n if (owner() != _msgSender()) {\n revert OwnableUnauthorizedAccount(_msgSender());\n }\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby disabling any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n if (newOwner == address(0)) {\n revert OwnableInvalidOwner(address(0));\n }\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/draft-IERC6093.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol)\npragma solidity ^0.8.20;\n\n/**\n * @dev Standard ERC-20 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.\n */\ninterface IERC20Errors {\n /**\n * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param balance Current balance for the interacting account.\n * @param needed Minimum amount required to perform a transfer.\n */\n error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC20InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC20InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.\n * @param spender Address that may be allowed to operate on tokens without being their owner.\n * @param allowance Amount of tokens a `spender` is allowed to operate with.\n * @param needed Minimum amount required to perform a transfer.\n */\n error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC20InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `spender` to be approved. Used in approvals.\n * @param spender Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC20InvalidSpender(address spender);\n}\n\n/**\n * @dev Standard ERC-721 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.\n */\ninterface IERC721Errors {\n /**\n * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.\n * Used in balance queries.\n * @param owner Address of the current owner of a token.\n */\n error ERC721InvalidOwner(address owner);\n\n /**\n * @dev Indicates a `tokenId` whose `owner` is the zero address.\n * @param tokenId Identifier number of a token.\n */\n error ERC721NonexistentToken(uint256 tokenId);\n\n /**\n * @dev Indicates an error related to the ownership over a particular token. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param tokenId Identifier number of a token.\n * @param owner Address of the current owner of a token.\n */\n error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC721InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC721InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n * @param tokenId Identifier number of a token.\n */\n error ERC721InsufficientApproval(address operator, uint256 tokenId);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC721InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC721InvalidOperator(address operator);\n}\n\n/**\n * @dev Standard ERC-1155 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.\n */\ninterface IERC1155Errors {\n /**\n * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param balance Current balance for the interacting account.\n * @param needed Minimum amount required to perform a transfer.\n * @param tokenId Identifier number of a token.\n */\n error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC1155InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC1155InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n * @param owner Address of the current owner of a token.\n */\n error ERC1155MissingApprovalForAll(address operator, address owner);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC1155InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC1155InvalidOperator(address operator);\n\n /**\n * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.\n * Used in batch transfers.\n * @param idsLength Length of the array of token identifiers\n * @param valuesLength Length of the array of token amounts\n */\n error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC1271.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (interfaces/IERC1271.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-1271 standard signature validation method for\n * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].\n */\ninterface IERC1271 {\n /**\n * @dev Should return whether the signature provided is valid for the provided data\n * @param hash Hash of the data to be signed\n * @param signature Signature byte array associated with `hash`\n */\n function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC1363.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"./IERC20.sol\";\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @title IERC1363\n * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].\n *\n * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract\n * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.\n */\ninterface IERC1363 is IERC20, IERC165 {\n /*\n * Note: the ERC-165 identifier for this interface is 0xb0202a11.\n * 0xb0202a11 ===\n * bytes4(keccak256('transferAndCall(address,uint256)')) ^\n * bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^\n * bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^\n * bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^\n * bytes4(keccak256('approveAndCall(address,uint256)')) ^\n * bytes4(keccak256('approveAndCall(address,uint256,bytes)'))\n */\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferAndCall(address to, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @param data Additional data with no specified format, sent in call to `to`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param from The address which you want to send tokens from.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferFromAndCall(address from, address to, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism\n * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n * @param from The address which you want to send tokens from.\n * @param to The address which you want to transfer to.\n * @param value The amount of tokens to be transferred.\n * @param data Additional data with no specified format, sent in call to `to`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.\n * @param spender The address which will spend the funds.\n * @param value The amount of tokens to be spent.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function approveAndCall(address spender, uint256 value) external returns (bool);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.\n * @param spender The address which will spend the funds.\n * @param value The amount of tokens to be spent.\n * @param data Additional data with no specified format, sent in call to `spender`.\n * @return A boolean value indicating whether the operation succeeded unless throwing.\n */\n function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"../utils/introspection/IERC165.sol\";\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../token/ERC20/IERC20.sol\";\n" + }, + "npm/@openzeppelin/contracts@5.3.0/interfaces/IERC5267.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)\n\npragma solidity ^0.8.20;\n\ninterface IERC5267 {\n /**\n * @dev MAY be emitted to signal that the domain could have changed.\n */\n event EIP712DomainChanged();\n\n /**\n * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712\n * signature.\n */\n function eip712Domain()\n external\n view\n returns (\n bytes1 fields,\n string memory name,\n string memory version,\n uint256 chainId,\n address verifyingContract,\n bytes32 salt,\n uint256[] memory extensions\n );\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/ERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"./IERC20.sol\";\nimport {IERC20Metadata} from \"./extensions/IERC20Metadata.sol\";\nimport {Context} from \"../../utils/Context.sol\";\nimport {IERC20Errors} from \"../../interfaces/draft-IERC6093.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * The default value of {decimals} is 18. To change this, you should override\n * this function so it returns a different value.\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC-20\n * applications.\n */\nabstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {\n mapping(address account => uint256) private _balances;\n\n mapping(address account => mapping(address spender => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * Both values are immutable: they can only be set once during construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the default value returned by this function, unless\n * it's overridden.\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `value`.\n */\n function transfer(address to, uint256 value) public virtual returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, value);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 value) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, value);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Skips emitting an {Approval} event indicating an allowance update. This is not\n * required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `value`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `value`.\n */\n function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, value);\n _transfer(from, to, value);\n return true;\n }\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead.\n */\n function _transfer(address from, address to, uint256 value) internal {\n if (from == address(0)) {\n revert ERC20InvalidSender(address(0));\n }\n if (to == address(0)) {\n revert ERC20InvalidReceiver(address(0));\n }\n _update(from, to, value);\n }\n\n /**\n * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`\n * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding\n * this function.\n *\n * Emits a {Transfer} event.\n */\n function _update(address from, address to, uint256 value) internal virtual {\n if (from == address(0)) {\n // Overflow check required: The rest of the code assumes that totalSupply never overflows\n _totalSupply += value;\n } else {\n uint256 fromBalance = _balances[from];\n if (fromBalance < value) {\n revert ERC20InsufficientBalance(from, fromBalance, value);\n }\n unchecked {\n // Overflow not possible: value <= fromBalance <= totalSupply.\n _balances[from] = fromBalance - value;\n }\n }\n\n if (to == address(0)) {\n unchecked {\n // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.\n _totalSupply -= value;\n }\n } else {\n unchecked {\n // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.\n _balances[to] += value;\n }\n }\n\n emit Transfer(from, to, value);\n }\n\n /**\n * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).\n * Relies on the `_update` mechanism\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead.\n */\n function _mint(address account, uint256 value) internal {\n if (account == address(0)) {\n revert ERC20InvalidReceiver(address(0));\n }\n _update(address(0), account, value);\n }\n\n /**\n * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.\n * Relies on the `_update` mechanism.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead\n */\n function _burn(address account, uint256 value) internal {\n if (account == address(0)) {\n revert ERC20InvalidSender(address(0));\n }\n _update(account, address(0), value);\n }\n\n /**\n * @dev Sets `value` as the allowance of `spender` over the `owner`'s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n *\n * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.\n */\n function _approve(address owner, address spender, uint256 value) internal {\n _approve(owner, spender, value, true);\n }\n\n /**\n * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.\n *\n * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by\n * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any\n * `Approval` event during `transferFrom` operations.\n *\n * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to\n * true using the following override:\n *\n * ```solidity\n * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {\n * super._approve(owner, spender, value, true);\n * }\n * ```\n *\n * Requirements are the same as {_approve}.\n */\n function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {\n if (owner == address(0)) {\n revert ERC20InvalidApprover(address(0));\n }\n if (spender == address(0)) {\n revert ERC20InvalidSpender(address(0));\n }\n _allowances[owner][spender] = value;\n if (emitEvent) {\n emit Approval(owner, spender, value);\n }\n }\n\n /**\n * @dev Updates `owner`'s allowance for `spender` based on spent `value`.\n *\n * Does not update the allowance value in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Does not emit an {Approval} event.\n */\n function _spendAllowance(address owner, address spender, uint256 value) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance < type(uint256).max) {\n if (currentAllowance < value) {\n revert ERC20InsufficientAllowance(spender, currentAllowance, value);\n }\n unchecked {\n _approve(owner, spender, currentAllowance - value, false);\n }\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/extensions/IERC20Metadata.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC-20 standard.\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-20 standard as defined in the ERC.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the value of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the value of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 value) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the\n * allowance mechanism. `value` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(address from, address to, uint256 value) external returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/token/ERC20/utils/SafeERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../IERC20.sol\";\nimport {IERC1363} from \"../../../interfaces/IERC1363.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC-20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n /**\n * @dev An operation with an ERC-20 token failed.\n */\n error SafeERC20FailedOperation(address token);\n\n /**\n * @dev Indicates a failed `decreaseAllowance` request.\n */\n error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);\n\n /**\n * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,\n * non-reverting calls are assumed to be successful.\n */\n function safeTransfer(IERC20 token, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));\n }\n\n /**\n * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the\n * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.\n */\n function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));\n }\n\n /**\n * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.\n */\n function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {\n return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));\n }\n\n /**\n * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.\n */\n function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {\n return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));\n }\n\n /**\n * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n * non-reverting calls are assumed to be successful.\n *\n * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the \"client\"\n * smart contract uses ERC-7674 to set temporary allowances, then the \"client\" smart contract should avoid using\n * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract\n * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.\n */\n function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n uint256 oldAllowance = token.allowance(address(this), spender);\n forceApprove(token, spender, oldAllowance + value);\n }\n\n /**\n * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no\n * value, non-reverting calls are assumed to be successful.\n *\n * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the \"client\"\n * smart contract uses ERC-7674 to set temporary allowances, then the \"client\" smart contract should avoid using\n * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract\n * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.\n */\n function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {\n unchecked {\n uint256 currentAllowance = token.allowance(address(this), spender);\n if (currentAllowance < requestedDecrease) {\n revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);\n }\n forceApprove(token, spender, currentAllowance - requestedDecrease);\n }\n }\n\n /**\n * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,\n * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval\n * to be set to zero before setting it to a non-zero value, such as USDT.\n *\n * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function\n * only sets the \"standard\" allowance. Any temporary allowance will remain active, in addition to the value being\n * set here.\n */\n function forceApprove(IERC20 token, address spender, uint256 value) internal {\n bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));\n\n if (!_callOptionalReturnBool(token, approvalCall)) {\n _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));\n _callOptionalReturn(token, approvalCall);\n }\n }\n\n /**\n * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no\n * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * Reverts if the returned value is other than `true`.\n */\n function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {\n if (to.code.length == 0) {\n safeTransfer(token, to, value);\n } else if (!token.transferAndCall(to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target\n * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * Reverts if the returned value is other than `true`.\n */\n function transferFromAndCallRelaxed(\n IERC1363 token,\n address from,\n address to,\n uint256 value,\n bytes memory data\n ) internal {\n if (to.code.length == 0) {\n safeTransferFrom(token, from, to, value);\n } else if (!token.transferFromAndCall(from, to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no\n * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n * targeting contracts.\n *\n * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.\n * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}\n * once without retrying, and relies on the returned value to be true.\n *\n * Reverts if the returned value is other than `true`.\n */\n function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {\n if (to.code.length == 0) {\n forceApprove(token, to, value);\n } else if (!token.approveAndCall(to, value, data)) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n *\n * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.\n */\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)\n // bubble errors\n if iszero(success) {\n let ptr := mload(0x40)\n returndatacopy(ptr, 0, returndatasize())\n revert(ptr, returndatasize())\n }\n returnSize := returndatasize()\n returnValue := mload(0)\n }\n\n if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {\n revert SafeERC20FailedOperation(address(token));\n }\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n *\n * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.\n */\n function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {\n bool success;\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)\n returnSize := returndatasize()\n returnValue := mload(0)\n }\n return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Address.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.2.0) (utils/Address.sol)\n\npragma solidity ^0.8.20;\n\nimport {Errors} from \"./Errors.sol\";\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev There's no code at `target` (it is not a contract).\n */\n error AddressEmptyCode(address target);\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n if (address(this).balance < amount) {\n revert Errors.InsufficientBalance(address(this).balance, amount);\n }\n\n (bool success, bytes memory returndata) = recipient.call{value: amount}(\"\");\n if (!success) {\n _revert(returndata);\n }\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason or custom error, it is bubbled\n * up by this function (like regular Solidity function calls). However, if\n * the call reverted with no returned reason, this function reverts with a\n * {Errors.FailedCall} error.\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n */\n function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n if (address(this).balance < value) {\n revert Errors.InsufficientBalance(address(this).balance, value);\n }\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResultFromTarget(target, success, returndata);\n }\n\n /**\n * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target\n * was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case\n * of an unsuccessful call.\n */\n function verifyCallResultFromTarget(\n address target,\n bool success,\n bytes memory returndata\n ) internal view returns (bytes memory) {\n if (!success) {\n _revert(returndata);\n } else {\n // only check if target is a contract if the call was successful and the return data is empty\n // otherwise we already know that it was a contract\n if (returndata.length == 0 && target.code.length == 0) {\n revert AddressEmptyCode(target);\n }\n return returndata;\n }\n }\n\n /**\n * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the\n * revert reason or with a default {Errors.FailedCall} error.\n */\n function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {\n if (!success) {\n _revert(returndata);\n } else {\n return returndata;\n }\n }\n\n /**\n * @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.\n */\n function _revert(bytes memory returndata) private pure {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n assembly (\"memory-safe\") {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert Errors.FailedCall();\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Context.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n\n function _contextSuffixLength() internal view virtual returns (uint256) {\n return 0;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/ECDSA.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/ECDSA.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.\n *\n * These functions can be used to verify that a message was signed by the holder\n * of the private keys of a given address.\n */\nlibrary ECDSA {\n enum RecoverError {\n NoError,\n InvalidSignature,\n InvalidSignatureLength,\n InvalidSignatureS\n }\n\n /**\n * @dev The signature derives the `address(0)`.\n */\n error ECDSAInvalidSignature();\n\n /**\n * @dev The signature has an invalid length.\n */\n error ECDSAInvalidSignatureLength(uint256 length);\n\n /**\n * @dev The signature has an S value that is in the upper half order.\n */\n error ECDSAInvalidSignatureS(bytes32 s);\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not\n * return address(0) without also returning an error description. Errors are documented using an enum (error type)\n * and a bytes32 providing additional information about the error.\n *\n * If no error is returned, then the address can be used for verification purposes.\n *\n * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.\n *\n * Documentation for signature generation:\n * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]\n * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]\n */\n function tryRecover(\n bytes32 hash,\n bytes memory signature\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n if (signature.length == 65) {\n bytes32 r;\n bytes32 s;\n uint8 v;\n // ecrecover takes the signature parameters, and the only way to get them\n // currently is to use assembly.\n assembly (\"memory-safe\") {\n r := mload(add(signature, 0x20))\n s := mload(add(signature, 0x40))\n v := byte(0, mload(add(signature, 0x60)))\n }\n return tryRecover(hash, v, r, s);\n } else {\n return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));\n }\n }\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with\n * `signature`. This address can then be used for verification purposes.\n *\n * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.\n */\n function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.\n *\n * See https://eips.ethereum.org/EIPS/eip-2098[ERC-2098 short signatures]\n */\n function tryRecover(\n bytes32 hash,\n bytes32 r,\n bytes32 vs\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n unchecked {\n bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n // We do not check for an overflow here since the shift operation results in 0 or 1.\n uint8 v = uint8((uint256(vs) >> 255) + 27);\n return tryRecover(hash, v, r, s);\n }\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\n */\n function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function tryRecover(\n bytes32 hash,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {\n // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\n // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\n // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\n // signatures from current libraries generate a unique signature with an s-value in the lower half order.\n //\n // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\n // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\n // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\n // these malleable signatures as well.\n if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\n return (address(0), RecoverError.InvalidSignatureS, s);\n }\n\n // If the signature is valid (and not malleable), return the signer address\n address signer = ecrecover(hash, v, r, s);\n if (signer == address(0)) {\n return (address(0), RecoverError.InvalidSignature, bytes32(0));\n }\n\n return (signer, RecoverError.NoError, bytes32(0));\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.\n */\n function _throwError(RecoverError error, bytes32 errorArg) private pure {\n if (error == RecoverError.NoError) {\n return; // no error: do nothing\n } else if (error == RecoverError.InvalidSignature) {\n revert ECDSAInvalidSignature();\n } else if (error == RecoverError.InvalidSignatureLength) {\n revert ECDSAInvalidSignatureLength(uint256(errorArg));\n } else if (error == RecoverError.InvalidSignatureS) {\n revert ECDSAInvalidSignatureS(errorArg);\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/EIP712.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/EIP712.sol)\n\npragma solidity ^0.8.20;\n\nimport {MessageHashUtils} from \"./MessageHashUtils.sol\";\nimport {ShortStrings, ShortString} from \"../ShortStrings.sol\";\nimport {IERC5267} from \"../../interfaces/IERC5267.sol\";\n\n/**\n * @dev https://eips.ethereum.org/EIPS/eip-712[EIP-712] is a standard for hashing and signing of typed structured data.\n *\n * The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose\n * encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract\n * does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to\n * produce the hash of their typed data using a combination of `abi.encode` and `keccak256`.\n *\n * This contract implements the EIP-712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding\n * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA\n * ({_hashTypedDataV4}).\n *\n * The implementation of the domain separator was designed to be as efficient as possible while still properly updating\n * the chain id to protect against replay attacks on an eventual fork of the chain.\n *\n * NOTE: This contract implements the version of the encoding known as \"v4\", as implemented by the JSON RPC method\n * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].\n *\n * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain\n * separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the\n * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.\n *\n * @custom:oz-upgrades-unsafe-allow state-variable-immutable\n */\nabstract contract EIP712 is IERC5267 {\n using ShortStrings for *;\n\n bytes32 private constant TYPE_HASH =\n keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\");\n\n // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to\n // invalidate the cached domain separator if the chain id changes.\n bytes32 private immutable _cachedDomainSeparator;\n uint256 private immutable _cachedChainId;\n address private immutable _cachedThis;\n\n bytes32 private immutable _hashedName;\n bytes32 private immutable _hashedVersion;\n\n ShortString private immutable _name;\n ShortString private immutable _version;\n // slither-disable-next-line constable-states\n string private _nameFallback;\n // slither-disable-next-line constable-states\n string private _versionFallback;\n\n /**\n * @dev Initializes the domain separator and parameter caches.\n *\n * The meaning of `name` and `version` is specified in\n * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP-712]:\n *\n * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.\n * - `version`: the current major version of the signing domain.\n *\n * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart\n * contract upgrade].\n */\n constructor(string memory name, string memory version) {\n _name = name.toShortStringWithFallback(_nameFallback);\n _version = version.toShortStringWithFallback(_versionFallback);\n _hashedName = keccak256(bytes(name));\n _hashedVersion = keccak256(bytes(version));\n\n _cachedChainId = block.chainid;\n _cachedDomainSeparator = _buildDomainSeparator();\n _cachedThis = address(this);\n }\n\n /**\n * @dev Returns the domain separator for the current chain.\n */\n function _domainSeparatorV4() internal view returns (bytes32) {\n if (address(this) == _cachedThis && block.chainid == _cachedChainId) {\n return _cachedDomainSeparator;\n } else {\n return _buildDomainSeparator();\n }\n }\n\n function _buildDomainSeparator() private view returns (bytes32) {\n return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));\n }\n\n /**\n * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this\n * function returns the hash of the fully encoded EIP712 message for this domain.\n *\n * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:\n *\n * ```solidity\n * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(\n * keccak256(\"Mail(address to,string contents)\"),\n * mailTo,\n * keccak256(bytes(mailContents))\n * )));\n * address signer = ECDSA.recover(digest, signature);\n * ```\n */\n function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {\n return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);\n }\n\n /**\n * @inheritdoc IERC5267\n */\n function eip712Domain()\n public\n view\n virtual\n returns (\n bytes1 fields,\n string memory name,\n string memory version,\n uint256 chainId,\n address verifyingContract,\n bytes32 salt,\n uint256[] memory extensions\n )\n {\n return (\n hex\"0f\", // 01111\n _EIP712Name(),\n _EIP712Version(),\n block.chainid,\n address(this),\n bytes32(0),\n new uint256[](0)\n );\n }\n\n /**\n * @dev The name parameter for the EIP712 domain.\n *\n * NOTE: By default this function reads _name which is an immutable value.\n * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).\n */\n // solhint-disable-next-line func-name-mixedcase\n function _EIP712Name() internal view returns (string memory) {\n return _name.toStringWithFallback(_nameFallback);\n }\n\n /**\n * @dev The version parameter for the EIP712 domain.\n *\n * NOTE: By default this function reads _version which is an immutable value.\n * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).\n */\n // solhint-disable-next-line func-name-mixedcase\n function _EIP712Version() internal view returns (string memory) {\n return _version.toStringWithFallback(_versionFallback);\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/cryptography/MessageHashUtils.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/MessageHashUtils.sol)\n\npragma solidity ^0.8.20;\n\nimport {Strings} from \"../Strings.sol\";\n\n/**\n * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.\n *\n * The library provides methods for generating a hash of a message that conforms to the\n * https://eips.ethereum.org/EIPS/eip-191[ERC-191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]\n * specifications.\n */\nlibrary MessageHashUtils {\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x45` (`personal_sign` messages).\n *\n * The digest is calculated by prefixing a bytes32 `messageHash` with\n * `\"\\x19Ethereum Signed Message:\\n32\"` and hashing the result. It corresponds with the\n * hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.\n *\n * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with\n * keccak256, although any bytes32 value can be safely used because the final digest will\n * be re-hashed.\n *\n * See {ECDSA-recover}.\n */\n function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n mstore(0x00, \"\\x19Ethereum Signed Message:\\n32\") // 32 is the bytes-length of messageHash\n mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix\n digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)\n }\n }\n\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x45` (`personal_sign` messages).\n *\n * The digest is calculated by prefixing an arbitrary `message` with\n * `\"\\x19Ethereum Signed Message:\\n\" + len(message)` and hashing the result. It corresponds with the\n * hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.\n *\n * See {ECDSA-recover}.\n */\n function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {\n return\n keccak256(bytes.concat(\"\\x19Ethereum Signed Message:\\n\", bytes(Strings.toString(message.length)), message));\n }\n\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x00` (data with intended validator).\n *\n * The digest is calculated by prefixing an arbitrary `data` with `\"\\x19\\x00\"` and the intended\n * `validator` address. Then hashing the result.\n *\n * See {ECDSA-recover}.\n */\n function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(hex\"19_00\", validator, data));\n }\n\n /**\n * @dev Variant of {toDataWithIntendedValidatorHash-address-bytes} optimized for cases where `data` is a bytes32.\n */\n function toDataWithIntendedValidatorHash(\n address validator,\n bytes32 messageHash\n ) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n mstore(0x00, hex\"19_00\")\n mstore(0x02, shl(96, validator))\n mstore(0x16, messageHash)\n digest := keccak256(0x00, 0x36)\n }\n }\n\n /**\n * @dev Returns the keccak256 digest of an EIP-712 typed data (ERC-191 version `0x01`).\n *\n * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with\n * `\\x19\\x01` and hashing the result. It corresponds to the hash signed by the\n * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.\n *\n * See {ECDSA-recover}.\n */\n function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {\n assembly (\"memory-safe\") {\n let ptr := mload(0x40)\n mstore(ptr, hex\"19_01\")\n mstore(add(ptr, 0x02), domainSeparator)\n mstore(add(ptr, 0x22), structHash)\n digest := keccak256(ptr, 0x42)\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Errors.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Collection of common custom errors used in multiple contracts\n *\n * IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.\n * It is recommended to avoid relying on the error API for critical functionality.\n *\n * _Available since v5.1._\n */\nlibrary Errors {\n /**\n * @dev The ETH balance of the account is not enough to perform the operation.\n */\n error InsufficientBalance(uint256 balance, uint256 needed);\n\n /**\n * @dev A call to an address target failed. The target may have reverted.\n */\n error FailedCall();\n\n /**\n * @dev The deployment failed.\n */\n error FailedDeployment();\n\n /**\n * @dev A necessary precompile is missing.\n */\n error MissingPrecompile(address);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/ERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/ERC165Checker.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165Checker.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @dev Library used to query support of an interface declared via {IERC165}.\n *\n * Note that these functions return the actual result of the query: they do not\n * `revert` if an interface is not supported. It is up to the caller to decide\n * what to do in these cases.\n */\nlibrary ERC165Checker {\n // As per the ERC-165 spec, no interface should ever match 0xffffffff\n bytes4 private constant INTERFACE_ID_INVALID = 0xffffffff;\n\n /**\n * @dev Returns true if `account` supports the {IERC165} interface.\n */\n function supportsERC165(address account) internal view returns (bool) {\n // Any contract that implements ERC-165 must explicitly indicate support of\n // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid\n return\n supportsERC165InterfaceUnchecked(account, type(IERC165).interfaceId) &&\n !supportsERC165InterfaceUnchecked(account, INTERFACE_ID_INVALID);\n }\n\n /**\n * @dev Returns true if `account` supports the interface defined by\n * `interfaceId`. Support for {IERC165} itself is queried automatically.\n *\n * See {IERC165-supportsInterface}.\n */\n function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {\n // query support of both ERC-165 as per the spec and support of _interfaceId\n return supportsERC165(account) && supportsERC165InterfaceUnchecked(account, interfaceId);\n }\n\n /**\n * @dev Returns a boolean array where each value corresponds to the\n * interfaces passed in and whether they're supported or not. This allows\n * you to batch check interfaces for a contract where your expectation\n * is that some interfaces may not be supported.\n *\n * See {IERC165-supportsInterface}.\n */\n function getSupportedInterfaces(\n address account,\n bytes4[] memory interfaceIds\n ) internal view returns (bool[] memory) {\n // an array of booleans corresponding to interfaceIds and whether they're supported or not\n bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length);\n\n // query support of ERC-165 itself\n if (supportsERC165(account)) {\n // query support of each interface in interfaceIds\n for (uint256 i = 0; i < interfaceIds.length; i++) {\n interfaceIdsSupported[i] = supportsERC165InterfaceUnchecked(account, interfaceIds[i]);\n }\n }\n\n return interfaceIdsSupported;\n }\n\n /**\n * @dev Returns true if `account` supports all the interfaces defined in\n * `interfaceIds`. Support for {IERC165} itself is queried automatically.\n *\n * Batch-querying can lead to gas savings by skipping repeated checks for\n * {IERC165} support.\n *\n * See {IERC165-supportsInterface}.\n */\n function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {\n // query support of ERC-165 itself\n if (!supportsERC165(account)) {\n return false;\n }\n\n // query support of each interface in interfaceIds\n for (uint256 i = 0; i < interfaceIds.length; i++) {\n if (!supportsERC165InterfaceUnchecked(account, interfaceIds[i])) {\n return false;\n }\n }\n\n // all interfaces supported\n return true;\n }\n\n /**\n * @notice Query if a contract implements an interface, does not check ERC-165 support\n * @param account The address of the contract to query for support of an interface\n * @param interfaceId The interface identifier, as specified in ERC-165\n * @return true if the contract at account indicates support of the interface with\n * identifier interfaceId, false otherwise\n * @dev Assumes that account contains a contract that supports ERC-165, otherwise\n * the behavior of this method is undefined. This precondition can be checked\n * with {supportsERC165}.\n *\n * Some precompiled contracts will falsely indicate support for a given interface, so caution\n * should be exercised when using this function.\n *\n * Interface identification is specified in ERC-165.\n */\n function supportsERC165InterfaceUnchecked(address account, bytes4 interfaceId) internal view returns (bool) {\n // prepare call\n bytes memory encodedParams = abi.encodeCall(IERC165.supportsInterface, (interfaceId));\n\n // perform static call\n bool success;\n uint256 returnSize;\n uint256 returnValue;\n assembly (\"memory-safe\") {\n success := staticcall(30000, account, add(encodedParams, 0x20), mload(encodedParams), 0x00, 0x20)\n returnSize := returndatasize()\n returnValue := mload(0x00)\n }\n\n return success && returnSize >= 0x20 && returnValue > 0;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/introspection/IERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[ERC].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/Math.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.20;\n\nimport {Panic} from \"../Panic.sol\";\nimport {SafeCast} from \"./SafeCast.sol\";\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n enum Rounding {\n Floor, // Toward negative infinity\n Ceil, // Toward positive infinity\n Trunc, // Toward zero\n Expand // Away from zero\n }\n\n /**\n * @dev Return the 512-bit addition of two uint256.\n *\n * The result is stored in two 256 variables such that sum = high * 2²⁵⁶ + low.\n */\n function add512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {\n assembly (\"memory-safe\") {\n low := add(a, b)\n high := lt(low, a)\n }\n }\n\n /**\n * @dev Return the 512-bit multiplication of two uint256.\n *\n * The result is stored in two 256 variables such that product = high * 2²⁵⁶ + low.\n */\n function mul512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {\n // 512-bit multiply [high low] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use\n // the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n // variables such that product = high * 2²⁵⁶ + low.\n assembly (\"memory-safe\") {\n let mm := mulmod(a, b, not(0))\n low := mul(a, b)\n high := sub(sub(mm, low), lt(mm, low))\n }\n }\n\n /**\n * @dev Returns the addition of two unsigned integers, with a success flag (no overflow).\n */\n function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a + b;\n success = c >= a;\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, with a success flag (no overflow).\n */\n function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a - b;\n success = c <= a;\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, with a success flag (no overflow).\n */\n function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a * b;\n assembly (\"memory-safe\") {\n // Only true when the multiplication doesn't overflow\n // (c / a == b) || (a == 0)\n success := or(eq(div(c, a), b), iszero(a))\n }\n // equivalent to: success ? c : 0\n result = c * SafeCast.toUint(success);\n }\n }\n\n /**\n * @dev Returns the division of two unsigned integers, with a success flag (no division by zero).\n */\n function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n success = b > 0;\n assembly (\"memory-safe\") {\n // The `DIV` opcode returns zero when the denominator is 0.\n result := div(a, b)\n }\n }\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).\n */\n function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n success = b > 0;\n assembly (\"memory-safe\") {\n // The `MOD` opcode returns zero when the denominator is 0.\n result := mod(a, b)\n }\n }\n }\n\n /**\n * @dev Unsigned saturating addition, bounds to `2²⁵⁶ - 1` instead of overflowing.\n */\n function saturatingAdd(uint256 a, uint256 b) internal pure returns (uint256) {\n (bool success, uint256 result) = tryAdd(a, b);\n return ternary(success, result, type(uint256).max);\n }\n\n /**\n * @dev Unsigned saturating subtraction, bounds to zero instead of overflowing.\n */\n function saturatingSub(uint256 a, uint256 b) internal pure returns (uint256) {\n (, uint256 result) = trySub(a, b);\n return result;\n }\n\n /**\n * @dev Unsigned saturating multiplication, bounds to `2²⁵⁶ - 1` instead of overflowing.\n */\n function saturatingMul(uint256 a, uint256 b) internal pure returns (uint256) {\n (bool success, uint256 result) = tryMul(a, b);\n return ternary(success, result, type(uint256).max);\n }\n\n /**\n * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.\n *\n * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.\n * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute\n * one branch when needed, making this function more expensive.\n */\n function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {\n unchecked {\n // branchless ternary works because:\n // b ^ (a ^ b) == a\n // b ^ 0 == b\n return b ^ ((a ^ b) * SafeCast.toUint(condition));\n }\n }\n\n /**\n * @dev Returns the largest of two numbers.\n */\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\n return ternary(a > b, a, b);\n }\n\n /**\n * @dev Returns the smallest of two numbers.\n */\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\n return ternary(a < b, a, b);\n }\n\n /**\n * @dev Returns the average of two numbers. The result is rounded towards\n * zero.\n */\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b) / 2 can overflow.\n return (a & b) + (a ^ b) / 2;\n }\n\n /**\n * @dev Returns the ceiling of the division of two numbers.\n *\n * This differs from standard division with `/` in that it rounds towards infinity instead\n * of rounding towards zero.\n */\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n if (b == 0) {\n // Guarantee the same behavior as in a regular Solidity division.\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n\n // The following calculation ensures accurate ceiling division without overflow.\n // Since a is non-zero, (a - 1) / b will not overflow.\n // The largest possible result occurs when (a - 1) / b is type(uint256).max,\n // but the largest value we can obtain is type(uint256).max - 1, which happens\n // when a = type(uint256).max and b = 1.\n unchecked {\n return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);\n }\n }\n\n /**\n * @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or\n * denominator == 0.\n *\n * Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by\n * Uniswap Labs also under MIT license.\n */\n function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {\n unchecked {\n (uint256 high, uint256 low) = mul512(x, y);\n\n // Handle non-overflow cases, 256 by 256 division.\n if (high == 0) {\n // Solidity will revert if denominator == 0, unlike the div opcode on its own.\n // The surrounding unchecked block does not change this fact.\n // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.\n return low / denominator;\n }\n\n // Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.\n if (denominator <= high) {\n Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));\n }\n\n ///////////////////////////////////////////////\n // 512 by 256 division.\n ///////////////////////////////////////////////\n\n // Make division exact by subtracting the remainder from [high low].\n uint256 remainder;\n assembly (\"memory-safe\") {\n // Compute remainder using mulmod.\n remainder := mulmod(x, y, denominator)\n\n // Subtract 256 bit number from 512 bit number.\n high := sub(high, gt(remainder, low))\n low := sub(low, remainder)\n }\n\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator.\n // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.\n\n uint256 twos = denominator & (0 - denominator);\n assembly (\"memory-safe\") {\n // Divide denominator by twos.\n denominator := div(denominator, twos)\n\n // Divide [high low] by twos.\n low := div(low, twos)\n\n // Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.\n twos := add(div(sub(0, twos), twos), 1)\n }\n\n // Shift in bits from high into low.\n low |= high * twos;\n\n // Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such\n // that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for\n // four bits. That is, denominator * inv ≡ 1 mod 2⁴.\n uint256 inverse = (3 * denominator) ^ 2;\n\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also\n // works in modular arithmetic, doubling the correct bits in each step.\n inverse *= 2 - denominator * inverse; // inverse mod 2⁸\n inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶\n inverse *= 2 - denominator * inverse; // inverse mod 2³²\n inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴\n inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸\n inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶\n\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n // This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is\n // less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and high\n // is no longer required.\n result = low * inverse;\n return result;\n }\n }\n\n /**\n * @dev Calculates x * y / denominator with full precision, following the selected rounding direction.\n */\n function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {\n return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);\n }\n\n /**\n * @dev Calculates floor(x * y >> n) with full precision. Throws if result overflows a uint256.\n */\n function mulShr(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 result) {\n unchecked {\n (uint256 high, uint256 low) = mul512(x, y);\n if (high >= 1 << n) {\n Panic.panic(Panic.UNDER_OVERFLOW);\n }\n return (high << (256 - n)) | (low >> n);\n }\n }\n\n /**\n * @dev Calculates x * y >> n with full precision, following the selected rounding direction.\n */\n function mulShr(uint256 x, uint256 y, uint8 n, Rounding rounding) internal pure returns (uint256) {\n return mulShr(x, y, n) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, 1 << n) > 0);\n }\n\n /**\n * @dev Calculate the modular multiplicative inverse of a number in Z/nZ.\n *\n * If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.\n * If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.\n *\n * If the input value is not inversible, 0 is returned.\n *\n * NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the\n * inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.\n */\n function invMod(uint256 a, uint256 n) internal pure returns (uint256) {\n unchecked {\n if (n == 0) return 0;\n\n // The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)\n // Used to compute integers x and y such that: ax + ny = gcd(a, n).\n // When the gcd is 1, then the inverse of a modulo n exists and it's x.\n // ax + ny = 1\n // ax = 1 + (-y)n\n // ax ≡ 1 (mod n) # x is the inverse of a modulo n\n\n // If the remainder is 0 the gcd is n right away.\n uint256 remainder = a % n;\n uint256 gcd = n;\n\n // Therefore the initial coefficients are:\n // ax + ny = gcd(a, n) = n\n // 0a + 1n = n\n int256 x = 0;\n int256 y = 1;\n\n while (remainder != 0) {\n uint256 quotient = gcd / remainder;\n\n (gcd, remainder) = (\n // The old remainder is the next gcd to try.\n remainder,\n // Compute the next remainder.\n // Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd\n // where gcd is at most n (capped to type(uint256).max)\n gcd - remainder * quotient\n );\n\n (x, y) = (\n // Increment the coefficient of a.\n y,\n // Decrement the coefficient of n.\n // Can overflow, but the result is casted to uint256 so that the\n // next value of y is \"wrapped around\" to a value between 0 and n - 1.\n x - y * int256(quotient)\n );\n }\n\n if (gcd != 1) return 0; // No inverse exists.\n return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.\n }\n }\n\n /**\n * @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.\n *\n * From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is\n * prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that\n * `a**(p-2)` is the modular multiplicative inverse of a in Fp.\n *\n * NOTE: this function does NOT check that `p` is a prime greater than `2`.\n */\n function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {\n unchecked {\n return Math.modExp(a, p - 2, p);\n }\n }\n\n /**\n * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)\n *\n * Requirements:\n * - modulus can't be zero\n * - underlying staticcall to precompile must succeed\n *\n * IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make\n * sure the chain you're using it on supports the precompiled contract for modular exponentiation\n * at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,\n * the underlying function will succeed given the lack of a revert, but the result may be incorrectly\n * interpreted as 0.\n */\n function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {\n (bool success, uint256 result) = tryModExp(b, e, m);\n if (!success) {\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n return result;\n }\n\n /**\n * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).\n * It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying\n * to operate modulo 0 or if the underlying precompile reverted.\n *\n * IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain\n * you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in\n * https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack\n * of a revert, but the result may be incorrectly interpreted as 0.\n */\n function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {\n if (m == 0) return (false, 0);\n assembly (\"memory-safe\") {\n let ptr := mload(0x40)\n // | Offset | Content | Content (Hex) |\n // |-----------|------------|--------------------------------------------------------------------|\n // | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x60:0x7f | value of b | 0x<.............................................................b> |\n // | 0x80:0x9f | value of e | 0x<.............................................................e> |\n // | 0xa0:0xbf | value of m | 0x<.............................................................m> |\n mstore(ptr, 0x20)\n mstore(add(ptr, 0x20), 0x20)\n mstore(add(ptr, 0x40), 0x20)\n mstore(add(ptr, 0x60), b)\n mstore(add(ptr, 0x80), e)\n mstore(add(ptr, 0xa0), m)\n\n // Given the result < m, it's guaranteed to fit in 32 bytes,\n // so we can use the memory scratch space located at offset 0.\n success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)\n result := mload(0x00)\n }\n }\n\n /**\n * @dev Variant of {modExp} that supports inputs of arbitrary length.\n */\n function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {\n (bool success, bytes memory result) = tryModExp(b, e, m);\n if (!success) {\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n return result;\n }\n\n /**\n * @dev Variant of {tryModExp} that supports inputs of arbitrary length.\n */\n function tryModExp(\n bytes memory b,\n bytes memory e,\n bytes memory m\n ) internal view returns (bool success, bytes memory result) {\n if (_zeroBytes(m)) return (false, new bytes(0));\n\n uint256 mLen = m.length;\n\n // Encode call args in result and move the free memory pointer\n result = abi.encodePacked(b.length, e.length, mLen, b, e, m);\n\n assembly (\"memory-safe\") {\n let dataPtr := add(result, 0x20)\n // Write result on top of args to avoid allocating extra memory.\n success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)\n // Overwrite the length.\n // result.length > returndatasize() is guaranteed because returndatasize() == m.length\n mstore(result, mLen)\n // Set the memory pointer after the returned data.\n mstore(0x40, add(dataPtr, mLen))\n }\n }\n\n /**\n * @dev Returns whether the provided byte array is zero.\n */\n function _zeroBytes(bytes memory byteArray) private pure returns (bool) {\n for (uint256 i = 0; i < byteArray.length; ++i) {\n if (byteArray[i] != 0) {\n return false;\n }\n }\n return true;\n }\n\n /**\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded\n * towards zero.\n *\n * This method is based on Newton's method for computing square roots; the algorithm is restricted to only\n * using integer operations.\n */\n function sqrt(uint256 a) internal pure returns (uint256) {\n unchecked {\n // Take care of easy edge cases when a == 0 or a == 1\n if (a <= 1) {\n return a;\n }\n\n // In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a\n // sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between\n // the current value as `ε_n = | x_n - sqrt(a) |`.\n //\n // For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root\n // of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is\n // bigger than any uint256.\n //\n // By noticing that\n // `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`\n // we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar\n // to the msb function.\n uint256 aa = a;\n uint256 xn = 1;\n\n if (aa >= (1 << 128)) {\n aa >>= 128;\n xn <<= 64;\n }\n if (aa >= (1 << 64)) {\n aa >>= 64;\n xn <<= 32;\n }\n if (aa >= (1 << 32)) {\n aa >>= 32;\n xn <<= 16;\n }\n if (aa >= (1 << 16)) {\n aa >>= 16;\n xn <<= 8;\n }\n if (aa >= (1 << 8)) {\n aa >>= 8;\n xn <<= 4;\n }\n if (aa >= (1 << 4)) {\n aa >>= 4;\n xn <<= 2;\n }\n if (aa >= (1 << 2)) {\n xn <<= 1;\n }\n\n // We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).\n //\n // We can refine our estimation by noticing that the middle of that interval minimizes the error.\n // If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).\n // This is going to be our x_0 (and ε_0)\n xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)\n\n // From here, Newton's method give us:\n // x_{n+1} = (x_n + a / x_n) / 2\n //\n // One should note that:\n // x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a\n // = ((x_n² + a) / (2 * x_n))² - a\n // = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a\n // = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)\n // = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)\n // = (x_n² - a)² / (2 * x_n)²\n // = ((x_n² - a) / (2 * x_n))²\n // ≥ 0\n // Which proves that for all n ≥ 1, sqrt(a) ≤ x_n\n //\n // This gives us the proof of quadratic convergence of the sequence:\n // ε_{n+1} = | x_{n+1} - sqrt(a) |\n // = | (x_n + a / x_n) / 2 - sqrt(a) |\n // = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |\n // = | (x_n - sqrt(a))² / (2 * x_n) |\n // = | ε_n² / (2 * x_n) |\n // = ε_n² / | (2 * x_n) |\n //\n // For the first iteration, we have a special case where x_0 is known:\n // ε_1 = ε_0² / | (2 * x_0) |\n // ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))\n // ≤ 2**(2*e-4) / (3 * 2**(e-1))\n // ≤ 2**(e-3) / 3\n // ≤ 2**(e-3-log2(3))\n // ≤ 2**(e-4.5)\n //\n // For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:\n // ε_{n+1} = ε_n² / | (2 * x_n) |\n // ≤ (2**(e-k))² / (2 * 2**(e-1))\n // ≤ 2**(2*e-2*k) / 2**e\n // ≤ 2**(e-2*k)\n xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above\n xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5\n xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9\n xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18\n xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36\n xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72\n\n // Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision\n // ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either\n // sqrt(a) or sqrt(a) + 1.\n return xn - SafeCast.toUint(xn > a / xn);\n }\n }\n\n /**\n * @dev Calculates sqrt(a), following the selected rounding direction.\n */\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = sqrt(a);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);\n }\n }\n\n /**\n * @dev Return the log in base 2 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n */\n function log2(uint256 x) internal pure returns (uint256 r) {\n // If value has upper 128 bits set, log2 result is at least 128\n r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;\n // If upper 64 bits of 128-bit half set, add 64 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;\n // If upper 32 bits of 64-bit half set, add 32 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;\n // If upper 16 bits of 32-bit half set, add 16 to result\n r |= SafeCast.toUint((x >> r) > 0xffff) << 4;\n // If upper 8 bits of 16-bit half set, add 8 to result\n r |= SafeCast.toUint((x >> r) > 0xff) << 3;\n // If upper 4 bits of 8-bit half set, add 4 to result\n r |= SafeCast.toUint((x >> r) > 0xf) << 2;\n\n // Shifts value right by the current result and use it as an index into this lookup table:\n //\n // | x (4 bits) | index | table[index] = MSB position |\n // |------------|---------|-----------------------------|\n // | 0000 | 0 | table[0] = 0 |\n // | 0001 | 1 | table[1] = 0 |\n // | 0010 | 2 | table[2] = 1 |\n // | 0011 | 3 | table[3] = 1 |\n // | 0100 | 4 | table[4] = 2 |\n // | 0101 | 5 | table[5] = 2 |\n // | 0110 | 6 | table[6] = 2 |\n // | 0111 | 7 | table[7] = 2 |\n // | 1000 | 8 | table[8] = 3 |\n // | 1001 | 9 | table[9] = 3 |\n // | 1010 | 10 | table[10] = 3 |\n // | 1011 | 11 | table[11] = 3 |\n // | 1100 | 12 | table[12] = 3 |\n // | 1101 | 13 | table[13] = 3 |\n // | 1110 | 14 | table[14] = 3 |\n // | 1111 | 15 | table[15] = 3 |\n //\n // The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes.\n assembly (\"memory-safe\") {\n r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000))\n }\n }\n\n /**\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log2(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);\n }\n }\n\n /**\n * @dev Return the log in base 10 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n */\n function log10(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >= 10 ** 64) {\n value /= 10 ** 64;\n result += 64;\n }\n if (value >= 10 ** 32) {\n value /= 10 ** 32;\n result += 32;\n }\n if (value >= 10 ** 16) {\n value /= 10 ** 16;\n result += 16;\n }\n if (value >= 10 ** 8) {\n value /= 10 ** 8;\n result += 8;\n }\n if (value >= 10 ** 4) {\n value /= 10 ** 4;\n result += 4;\n }\n if (value >= 10 ** 2) {\n value /= 10 ** 2;\n result += 2;\n }\n if (value >= 10 ** 1) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log10(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);\n }\n }\n\n /**\n * @dev Return the log in base 256 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n *\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n */\n function log256(uint256 x) internal pure returns (uint256 r) {\n // If value has upper 128 bits set, log2 result is at least 128\n r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;\n // If upper 64 bits of 128-bit half set, add 64 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;\n // If upper 32 bits of 64-bit half set, add 32 to result\n r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;\n // If upper 16 bits of 32-bit half set, add 16 to result\n r |= SafeCast.toUint((x >> r) > 0xffff) << 4;\n // Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8\n return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);\n }\n\n /**\n * @dev Return the log in base 256, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log256(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);\n }\n }\n\n /**\n * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.\n */\n function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {\n return uint8(rounding) % 2 == 1;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/SafeCast.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeCast {\n /**\n * @dev Value doesn't fit in an uint of `bits` size.\n */\n error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);\n\n /**\n * @dev An int value doesn't fit in an uint of `bits` size.\n */\n error SafeCastOverflowedIntToUint(int256 value);\n\n /**\n * @dev Value doesn't fit in an int of `bits` size.\n */\n error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);\n\n /**\n * @dev An uint value doesn't fit in an int of `bits` size.\n */\n error SafeCastOverflowedUintToInt(uint256 value);\n\n /**\n * @dev Returns the downcasted uint248 from uint256, reverting on\n * overflow (when the input is greater than largest uint248).\n *\n * Counterpart to Solidity's `uint248` operator.\n *\n * Requirements:\n *\n * - input must fit into 248 bits\n */\n function toUint248(uint256 value) internal pure returns (uint248) {\n if (value > type(uint248).max) {\n revert SafeCastOverflowedUintDowncast(248, value);\n }\n return uint248(value);\n }\n\n /**\n * @dev Returns the downcasted uint240 from uint256, reverting on\n * overflow (when the input is greater than largest uint240).\n *\n * Counterpart to Solidity's `uint240` operator.\n *\n * Requirements:\n *\n * - input must fit into 240 bits\n */\n function toUint240(uint256 value) internal pure returns (uint240) {\n if (value > type(uint240).max) {\n revert SafeCastOverflowedUintDowncast(240, value);\n }\n return uint240(value);\n }\n\n /**\n * @dev Returns the downcasted uint232 from uint256, reverting on\n * overflow (when the input is greater than largest uint232).\n *\n * Counterpart to Solidity's `uint232` operator.\n *\n * Requirements:\n *\n * - input must fit into 232 bits\n */\n function toUint232(uint256 value) internal pure returns (uint232) {\n if (value > type(uint232).max) {\n revert SafeCastOverflowedUintDowncast(232, value);\n }\n return uint232(value);\n }\n\n /**\n * @dev Returns the downcasted uint224 from uint256, reverting on\n * overflow (when the input is greater than largest uint224).\n *\n * Counterpart to Solidity's `uint224` operator.\n *\n * Requirements:\n *\n * - input must fit into 224 bits\n */\n function toUint224(uint256 value) internal pure returns (uint224) {\n if (value > type(uint224).max) {\n revert SafeCastOverflowedUintDowncast(224, value);\n }\n return uint224(value);\n }\n\n /**\n * @dev Returns the downcasted uint216 from uint256, reverting on\n * overflow (when the input is greater than largest uint216).\n *\n * Counterpart to Solidity's `uint216` operator.\n *\n * Requirements:\n *\n * - input must fit into 216 bits\n */\n function toUint216(uint256 value) internal pure returns (uint216) {\n if (value > type(uint216).max) {\n revert SafeCastOverflowedUintDowncast(216, value);\n }\n return uint216(value);\n }\n\n /**\n * @dev Returns the downcasted uint208 from uint256, reverting on\n * overflow (when the input is greater than largest uint208).\n *\n * Counterpart to Solidity's `uint208` operator.\n *\n * Requirements:\n *\n * - input must fit into 208 bits\n */\n function toUint208(uint256 value) internal pure returns (uint208) {\n if (value > type(uint208).max) {\n revert SafeCastOverflowedUintDowncast(208, value);\n }\n return uint208(value);\n }\n\n /**\n * @dev Returns the downcasted uint200 from uint256, reverting on\n * overflow (when the input is greater than largest uint200).\n *\n * Counterpart to Solidity's `uint200` operator.\n *\n * Requirements:\n *\n * - input must fit into 200 bits\n */\n function toUint200(uint256 value) internal pure returns (uint200) {\n if (value > type(uint200).max) {\n revert SafeCastOverflowedUintDowncast(200, value);\n }\n return uint200(value);\n }\n\n /**\n * @dev Returns the downcasted uint192 from uint256, reverting on\n * overflow (when the input is greater than largest uint192).\n *\n * Counterpart to Solidity's `uint192` operator.\n *\n * Requirements:\n *\n * - input must fit into 192 bits\n */\n function toUint192(uint256 value) internal pure returns (uint192) {\n if (value > type(uint192).max) {\n revert SafeCastOverflowedUintDowncast(192, value);\n }\n return uint192(value);\n }\n\n /**\n * @dev Returns the downcasted uint184 from uint256, reverting on\n * overflow (when the input is greater than largest uint184).\n *\n * Counterpart to Solidity's `uint184` operator.\n *\n * Requirements:\n *\n * - input must fit into 184 bits\n */\n function toUint184(uint256 value) internal pure returns (uint184) {\n if (value > type(uint184).max) {\n revert SafeCastOverflowedUintDowncast(184, value);\n }\n return uint184(value);\n }\n\n /**\n * @dev Returns the downcasted uint176 from uint256, reverting on\n * overflow (when the input is greater than largest uint176).\n *\n * Counterpart to Solidity's `uint176` operator.\n *\n * Requirements:\n *\n * - input must fit into 176 bits\n */\n function toUint176(uint256 value) internal pure returns (uint176) {\n if (value > type(uint176).max) {\n revert SafeCastOverflowedUintDowncast(176, value);\n }\n return uint176(value);\n }\n\n /**\n * @dev Returns the downcasted uint168 from uint256, reverting on\n * overflow (when the input is greater than largest uint168).\n *\n * Counterpart to Solidity's `uint168` operator.\n *\n * Requirements:\n *\n * - input must fit into 168 bits\n */\n function toUint168(uint256 value) internal pure returns (uint168) {\n if (value > type(uint168).max) {\n revert SafeCastOverflowedUintDowncast(168, value);\n }\n return uint168(value);\n }\n\n /**\n * @dev Returns the downcasted uint160 from uint256, reverting on\n * overflow (when the input is greater than largest uint160).\n *\n * Counterpart to Solidity's `uint160` operator.\n *\n * Requirements:\n *\n * - input must fit into 160 bits\n */\n function toUint160(uint256 value) internal pure returns (uint160) {\n if (value > type(uint160).max) {\n revert SafeCastOverflowedUintDowncast(160, value);\n }\n return uint160(value);\n }\n\n /**\n * @dev Returns the downcasted uint152 from uint256, reverting on\n * overflow (when the input is greater than largest uint152).\n *\n * Counterpart to Solidity's `uint152` operator.\n *\n * Requirements:\n *\n * - input must fit into 152 bits\n */\n function toUint152(uint256 value) internal pure returns (uint152) {\n if (value > type(uint152).max) {\n revert SafeCastOverflowedUintDowncast(152, value);\n }\n return uint152(value);\n }\n\n /**\n * @dev Returns the downcasted uint144 from uint256, reverting on\n * overflow (when the input is greater than largest uint144).\n *\n * Counterpart to Solidity's `uint144` operator.\n *\n * Requirements:\n *\n * - input must fit into 144 bits\n */\n function toUint144(uint256 value) internal pure returns (uint144) {\n if (value > type(uint144).max) {\n revert SafeCastOverflowedUintDowncast(144, value);\n }\n return uint144(value);\n }\n\n /**\n * @dev Returns the downcasted uint136 from uint256, reverting on\n * overflow (when the input is greater than largest uint136).\n *\n * Counterpart to Solidity's `uint136` operator.\n *\n * Requirements:\n *\n * - input must fit into 136 bits\n */\n function toUint136(uint256 value) internal pure returns (uint136) {\n if (value > type(uint136).max) {\n revert SafeCastOverflowedUintDowncast(136, value);\n }\n return uint136(value);\n }\n\n /**\n * @dev Returns the downcasted uint128 from uint256, reverting on\n * overflow (when the input is greater than largest uint128).\n *\n * Counterpart to Solidity's `uint128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n */\n function toUint128(uint256 value) internal pure returns (uint128) {\n if (value > type(uint128).max) {\n revert SafeCastOverflowedUintDowncast(128, value);\n }\n return uint128(value);\n }\n\n /**\n * @dev Returns the downcasted uint120 from uint256, reverting on\n * overflow (when the input is greater than largest uint120).\n *\n * Counterpart to Solidity's `uint120` operator.\n *\n * Requirements:\n *\n * - input must fit into 120 bits\n */\n function toUint120(uint256 value) internal pure returns (uint120) {\n if (value > type(uint120).max) {\n revert SafeCastOverflowedUintDowncast(120, value);\n }\n return uint120(value);\n }\n\n /**\n * @dev Returns the downcasted uint112 from uint256, reverting on\n * overflow (when the input is greater than largest uint112).\n *\n * Counterpart to Solidity's `uint112` operator.\n *\n * Requirements:\n *\n * - input must fit into 112 bits\n */\n function toUint112(uint256 value) internal pure returns (uint112) {\n if (value > type(uint112).max) {\n revert SafeCastOverflowedUintDowncast(112, value);\n }\n return uint112(value);\n }\n\n /**\n * @dev Returns the downcasted uint104 from uint256, reverting on\n * overflow (when the input is greater than largest uint104).\n *\n * Counterpart to Solidity's `uint104` operator.\n *\n * Requirements:\n *\n * - input must fit into 104 bits\n */\n function toUint104(uint256 value) internal pure returns (uint104) {\n if (value > type(uint104).max) {\n revert SafeCastOverflowedUintDowncast(104, value);\n }\n return uint104(value);\n }\n\n /**\n * @dev Returns the downcasted uint96 from uint256, reverting on\n * overflow (when the input is greater than largest uint96).\n *\n * Counterpart to Solidity's `uint96` operator.\n *\n * Requirements:\n *\n * - input must fit into 96 bits\n */\n function toUint96(uint256 value) internal pure returns (uint96) {\n if (value > type(uint96).max) {\n revert SafeCastOverflowedUintDowncast(96, value);\n }\n return uint96(value);\n }\n\n /**\n * @dev Returns the downcasted uint88 from uint256, reverting on\n * overflow (when the input is greater than largest uint88).\n *\n * Counterpart to Solidity's `uint88` operator.\n *\n * Requirements:\n *\n * - input must fit into 88 bits\n */\n function toUint88(uint256 value) internal pure returns (uint88) {\n if (value > type(uint88).max) {\n revert SafeCastOverflowedUintDowncast(88, value);\n }\n return uint88(value);\n }\n\n /**\n * @dev Returns the downcasted uint80 from uint256, reverting on\n * overflow (when the input is greater than largest uint80).\n *\n * Counterpart to Solidity's `uint80` operator.\n *\n * Requirements:\n *\n * - input must fit into 80 bits\n */\n function toUint80(uint256 value) internal pure returns (uint80) {\n if (value > type(uint80).max) {\n revert SafeCastOverflowedUintDowncast(80, value);\n }\n return uint80(value);\n }\n\n /**\n * @dev Returns the downcasted uint72 from uint256, reverting on\n * overflow (when the input is greater than largest uint72).\n *\n * Counterpart to Solidity's `uint72` operator.\n *\n * Requirements:\n *\n * - input must fit into 72 bits\n */\n function toUint72(uint256 value) internal pure returns (uint72) {\n if (value > type(uint72).max) {\n revert SafeCastOverflowedUintDowncast(72, value);\n }\n return uint72(value);\n }\n\n /**\n * @dev Returns the downcasted uint64 from uint256, reverting on\n * overflow (when the input is greater than largest uint64).\n *\n * Counterpart to Solidity's `uint64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n */\n function toUint64(uint256 value) internal pure returns (uint64) {\n if (value > type(uint64).max) {\n revert SafeCastOverflowedUintDowncast(64, value);\n }\n return uint64(value);\n }\n\n /**\n * @dev Returns the downcasted uint56 from uint256, reverting on\n * overflow (when the input is greater than largest uint56).\n *\n * Counterpart to Solidity's `uint56` operator.\n *\n * Requirements:\n *\n * - input must fit into 56 bits\n */\n function toUint56(uint256 value) internal pure returns (uint56) {\n if (value > type(uint56).max) {\n revert SafeCastOverflowedUintDowncast(56, value);\n }\n return uint56(value);\n }\n\n /**\n * @dev Returns the downcasted uint48 from uint256, reverting on\n * overflow (when the input is greater than largest uint48).\n *\n * Counterpart to Solidity's `uint48` operator.\n *\n * Requirements:\n *\n * - input must fit into 48 bits\n */\n function toUint48(uint256 value) internal pure returns (uint48) {\n if (value > type(uint48).max) {\n revert SafeCastOverflowedUintDowncast(48, value);\n }\n return uint48(value);\n }\n\n /**\n * @dev Returns the downcasted uint40 from uint256, reverting on\n * overflow (when the input is greater than largest uint40).\n *\n * Counterpart to Solidity's `uint40` operator.\n *\n * Requirements:\n *\n * - input must fit into 40 bits\n */\n function toUint40(uint256 value) internal pure returns (uint40) {\n if (value > type(uint40).max) {\n revert SafeCastOverflowedUintDowncast(40, value);\n }\n return uint40(value);\n }\n\n /**\n * @dev Returns the downcasted uint32 from uint256, reverting on\n * overflow (when the input is greater than largest uint32).\n *\n * Counterpart to Solidity's `uint32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n */\n function toUint32(uint256 value) internal pure returns (uint32) {\n if (value > type(uint32).max) {\n revert SafeCastOverflowedUintDowncast(32, value);\n }\n return uint32(value);\n }\n\n /**\n * @dev Returns the downcasted uint24 from uint256, reverting on\n * overflow (when the input is greater than largest uint24).\n *\n * Counterpart to Solidity's `uint24` operator.\n *\n * Requirements:\n *\n * - input must fit into 24 bits\n */\n function toUint24(uint256 value) internal pure returns (uint24) {\n if (value > type(uint24).max) {\n revert SafeCastOverflowedUintDowncast(24, value);\n }\n return uint24(value);\n }\n\n /**\n * @dev Returns the downcasted uint16 from uint256, reverting on\n * overflow (when the input is greater than largest uint16).\n *\n * Counterpart to Solidity's `uint16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n */\n function toUint16(uint256 value) internal pure returns (uint16) {\n if (value > type(uint16).max) {\n revert SafeCastOverflowedUintDowncast(16, value);\n }\n return uint16(value);\n }\n\n /**\n * @dev Returns the downcasted uint8 from uint256, reverting on\n * overflow (when the input is greater than largest uint8).\n *\n * Counterpart to Solidity's `uint8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits\n */\n function toUint8(uint256 value) internal pure returns (uint8) {\n if (value > type(uint8).max) {\n revert SafeCastOverflowedUintDowncast(8, value);\n }\n return uint8(value);\n }\n\n /**\n * @dev Converts a signed int256 into an unsigned uint256.\n *\n * Requirements:\n *\n * - input must be greater than or equal to 0.\n */\n function toUint256(int256 value) internal pure returns (uint256) {\n if (value < 0) {\n revert SafeCastOverflowedIntToUint(value);\n }\n return uint256(value);\n }\n\n /**\n * @dev Returns the downcasted int248 from int256, reverting on\n * overflow (when the input is less than smallest int248 or\n * greater than largest int248).\n *\n * Counterpart to Solidity's `int248` operator.\n *\n * Requirements:\n *\n * - input must fit into 248 bits\n */\n function toInt248(int256 value) internal pure returns (int248 downcasted) {\n downcasted = int248(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(248, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int240 from int256, reverting on\n * overflow (when the input is less than smallest int240 or\n * greater than largest int240).\n *\n * Counterpart to Solidity's `int240` operator.\n *\n * Requirements:\n *\n * - input must fit into 240 bits\n */\n function toInt240(int256 value) internal pure returns (int240 downcasted) {\n downcasted = int240(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(240, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int232 from int256, reverting on\n * overflow (when the input is less than smallest int232 or\n * greater than largest int232).\n *\n * Counterpart to Solidity's `int232` operator.\n *\n * Requirements:\n *\n * - input must fit into 232 bits\n */\n function toInt232(int256 value) internal pure returns (int232 downcasted) {\n downcasted = int232(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(232, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int224 from int256, reverting on\n * overflow (when the input is less than smallest int224 or\n * greater than largest int224).\n *\n * Counterpart to Solidity's `int224` operator.\n *\n * Requirements:\n *\n * - input must fit into 224 bits\n */\n function toInt224(int256 value) internal pure returns (int224 downcasted) {\n downcasted = int224(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(224, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int216 from int256, reverting on\n * overflow (when the input is less than smallest int216 or\n * greater than largest int216).\n *\n * Counterpart to Solidity's `int216` operator.\n *\n * Requirements:\n *\n * - input must fit into 216 bits\n */\n function toInt216(int256 value) internal pure returns (int216 downcasted) {\n downcasted = int216(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(216, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int208 from int256, reverting on\n * overflow (when the input is less than smallest int208 or\n * greater than largest int208).\n *\n * Counterpart to Solidity's `int208` operator.\n *\n * Requirements:\n *\n * - input must fit into 208 bits\n */\n function toInt208(int256 value) internal pure returns (int208 downcasted) {\n downcasted = int208(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(208, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int200 from int256, reverting on\n * overflow (when the input is less than smallest int200 or\n * greater than largest int200).\n *\n * Counterpart to Solidity's `int200` operator.\n *\n * Requirements:\n *\n * - input must fit into 200 bits\n */\n function toInt200(int256 value) internal pure returns (int200 downcasted) {\n downcasted = int200(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(200, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int192 from int256, reverting on\n * overflow (when the input is less than smallest int192 or\n * greater than largest int192).\n *\n * Counterpart to Solidity's `int192` operator.\n *\n * Requirements:\n *\n * - input must fit into 192 bits\n */\n function toInt192(int256 value) internal pure returns (int192 downcasted) {\n downcasted = int192(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(192, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int184 from int256, reverting on\n * overflow (when the input is less than smallest int184 or\n * greater than largest int184).\n *\n * Counterpart to Solidity's `int184` operator.\n *\n * Requirements:\n *\n * - input must fit into 184 bits\n */\n function toInt184(int256 value) internal pure returns (int184 downcasted) {\n downcasted = int184(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(184, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int176 from int256, reverting on\n * overflow (when the input is less than smallest int176 or\n * greater than largest int176).\n *\n * Counterpart to Solidity's `int176` operator.\n *\n * Requirements:\n *\n * - input must fit into 176 bits\n */\n function toInt176(int256 value) internal pure returns (int176 downcasted) {\n downcasted = int176(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(176, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int168 from int256, reverting on\n * overflow (when the input is less than smallest int168 or\n * greater than largest int168).\n *\n * Counterpart to Solidity's `int168` operator.\n *\n * Requirements:\n *\n * - input must fit into 168 bits\n */\n function toInt168(int256 value) internal pure returns (int168 downcasted) {\n downcasted = int168(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(168, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int160 from int256, reverting on\n * overflow (when the input is less than smallest int160 or\n * greater than largest int160).\n *\n * Counterpart to Solidity's `int160` operator.\n *\n * Requirements:\n *\n * - input must fit into 160 bits\n */\n function toInt160(int256 value) internal pure returns (int160 downcasted) {\n downcasted = int160(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(160, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int152 from int256, reverting on\n * overflow (when the input is less than smallest int152 or\n * greater than largest int152).\n *\n * Counterpart to Solidity's `int152` operator.\n *\n * Requirements:\n *\n * - input must fit into 152 bits\n */\n function toInt152(int256 value) internal pure returns (int152 downcasted) {\n downcasted = int152(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(152, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int144 from int256, reverting on\n * overflow (when the input is less than smallest int144 or\n * greater than largest int144).\n *\n * Counterpart to Solidity's `int144` operator.\n *\n * Requirements:\n *\n * - input must fit into 144 bits\n */\n function toInt144(int256 value) internal pure returns (int144 downcasted) {\n downcasted = int144(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(144, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int136 from int256, reverting on\n * overflow (when the input is less than smallest int136 or\n * greater than largest int136).\n *\n * Counterpart to Solidity's `int136` operator.\n *\n * Requirements:\n *\n * - input must fit into 136 bits\n */\n function toInt136(int256 value) internal pure returns (int136 downcasted) {\n downcasted = int136(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(136, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int128 from int256, reverting on\n * overflow (when the input is less than smallest int128 or\n * greater than largest int128).\n *\n * Counterpart to Solidity's `int128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n */\n function toInt128(int256 value) internal pure returns (int128 downcasted) {\n downcasted = int128(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(128, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int120 from int256, reverting on\n * overflow (when the input is less than smallest int120 or\n * greater than largest int120).\n *\n * Counterpart to Solidity's `int120` operator.\n *\n * Requirements:\n *\n * - input must fit into 120 bits\n */\n function toInt120(int256 value) internal pure returns (int120 downcasted) {\n downcasted = int120(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(120, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int112 from int256, reverting on\n * overflow (when the input is less than smallest int112 or\n * greater than largest int112).\n *\n * Counterpart to Solidity's `int112` operator.\n *\n * Requirements:\n *\n * - input must fit into 112 bits\n */\n function toInt112(int256 value) internal pure returns (int112 downcasted) {\n downcasted = int112(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(112, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int104 from int256, reverting on\n * overflow (when the input is less than smallest int104 or\n * greater than largest int104).\n *\n * Counterpart to Solidity's `int104` operator.\n *\n * Requirements:\n *\n * - input must fit into 104 bits\n */\n function toInt104(int256 value) internal pure returns (int104 downcasted) {\n downcasted = int104(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(104, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int96 from int256, reverting on\n * overflow (when the input is less than smallest int96 or\n * greater than largest int96).\n *\n * Counterpart to Solidity's `int96` operator.\n *\n * Requirements:\n *\n * - input must fit into 96 bits\n */\n function toInt96(int256 value) internal pure returns (int96 downcasted) {\n downcasted = int96(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(96, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int88 from int256, reverting on\n * overflow (when the input is less than smallest int88 or\n * greater than largest int88).\n *\n * Counterpart to Solidity's `int88` operator.\n *\n * Requirements:\n *\n * - input must fit into 88 bits\n */\n function toInt88(int256 value) internal pure returns (int88 downcasted) {\n downcasted = int88(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(88, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int80 from int256, reverting on\n * overflow (when the input is less than smallest int80 or\n * greater than largest int80).\n *\n * Counterpart to Solidity's `int80` operator.\n *\n * Requirements:\n *\n * - input must fit into 80 bits\n */\n function toInt80(int256 value) internal pure returns (int80 downcasted) {\n downcasted = int80(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(80, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int72 from int256, reverting on\n * overflow (when the input is less than smallest int72 or\n * greater than largest int72).\n *\n * Counterpart to Solidity's `int72` operator.\n *\n * Requirements:\n *\n * - input must fit into 72 bits\n */\n function toInt72(int256 value) internal pure returns (int72 downcasted) {\n downcasted = int72(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(72, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int64 from int256, reverting on\n * overflow (when the input is less than smallest int64 or\n * greater than largest int64).\n *\n * Counterpart to Solidity's `int64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n */\n function toInt64(int256 value) internal pure returns (int64 downcasted) {\n downcasted = int64(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(64, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int56 from int256, reverting on\n * overflow (when the input is less than smallest int56 or\n * greater than largest int56).\n *\n * Counterpart to Solidity's `int56` operator.\n *\n * Requirements:\n *\n * - input must fit into 56 bits\n */\n function toInt56(int256 value) internal pure returns (int56 downcasted) {\n downcasted = int56(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(56, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int48 from int256, reverting on\n * overflow (when the input is less than smallest int48 or\n * greater than largest int48).\n *\n * Counterpart to Solidity's `int48` operator.\n *\n * Requirements:\n *\n * - input must fit into 48 bits\n */\n function toInt48(int256 value) internal pure returns (int48 downcasted) {\n downcasted = int48(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(48, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int40 from int256, reverting on\n * overflow (when the input is less than smallest int40 or\n * greater than largest int40).\n *\n * Counterpart to Solidity's `int40` operator.\n *\n * Requirements:\n *\n * - input must fit into 40 bits\n */\n function toInt40(int256 value) internal pure returns (int40 downcasted) {\n downcasted = int40(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(40, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int32 from int256, reverting on\n * overflow (when the input is less than smallest int32 or\n * greater than largest int32).\n *\n * Counterpart to Solidity's `int32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n */\n function toInt32(int256 value) internal pure returns (int32 downcasted) {\n downcasted = int32(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(32, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int24 from int256, reverting on\n * overflow (when the input is less than smallest int24 or\n * greater than largest int24).\n *\n * Counterpart to Solidity's `int24` operator.\n *\n * Requirements:\n *\n * - input must fit into 24 bits\n */\n function toInt24(int256 value) internal pure returns (int24 downcasted) {\n downcasted = int24(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(24, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int16 from int256, reverting on\n * overflow (when the input is less than smallest int16 or\n * greater than largest int16).\n *\n * Counterpart to Solidity's `int16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n */\n function toInt16(int256 value) internal pure returns (int16 downcasted) {\n downcasted = int16(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(16, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int8 from int256, reverting on\n * overflow (when the input is less than smallest int8 or\n * greater than largest int8).\n *\n * Counterpart to Solidity's `int8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits\n */\n function toInt8(int256 value) internal pure returns (int8 downcasted) {\n downcasted = int8(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(8, value);\n }\n }\n\n /**\n * @dev Converts an unsigned uint256 into a signed int256.\n *\n * Requirements:\n *\n * - input must be less than or equal to maxInt256.\n */\n function toInt256(uint256 value) internal pure returns (int256) {\n // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n if (value > uint256(type(int256).max)) {\n revert SafeCastOverflowedUintToInt(value);\n }\n return int256(value);\n }\n\n /**\n * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.\n */\n function toUint(bool b) internal pure returns (uint256 u) {\n assembly (\"memory-safe\") {\n u := iszero(iszero(b))\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/math/SignedMath.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol)\n\npragma solidity ^0.8.20;\n\nimport {SafeCast} from \"./SafeCast.sol\";\n\n/**\n * @dev Standard signed math utilities missing in the Solidity language.\n */\nlibrary SignedMath {\n /**\n * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.\n *\n * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.\n * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute\n * one branch when needed, making this function more expensive.\n */\n function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {\n unchecked {\n // branchless ternary works because:\n // b ^ (a ^ b) == a\n // b ^ 0 == b\n return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));\n }\n }\n\n /**\n * @dev Returns the largest of two signed numbers.\n */\n function max(int256 a, int256 b) internal pure returns (int256) {\n return ternary(a > b, a, b);\n }\n\n /**\n * @dev Returns the smallest of two signed numbers.\n */\n function min(int256 a, int256 b) internal pure returns (int256) {\n return ternary(a < b, a, b);\n }\n\n /**\n * @dev Returns the average of two signed numbers without overflow.\n * The result is rounded towards zero.\n */\n function average(int256 a, int256 b) internal pure returns (int256) {\n // Formula from the book \"Hacker's Delight\"\n int256 x = (a & b) + ((a ^ b) >> 1);\n return x + (int256(uint256(x) >> 255) & (a ^ b));\n }\n\n /**\n * @dev Returns the absolute unsigned value of a signed value.\n */\n function abs(int256 n) internal pure returns (uint256) {\n unchecked {\n // Formula from the \"Bit Twiddling Hacks\" by Sean Eron Anderson.\n // Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,\n // taking advantage of the most significant (or \"sign\" bit) in two's complement representation.\n // This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,\n // the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative).\n int256 mask = n >> 255;\n\n // A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.\n return uint256((n + mask) ^ mask);\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Panic.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Helper library for emitting standardized panic codes.\n *\n * ```solidity\n * contract Example {\n * using Panic for uint256;\n *\n * // Use any of the declared internal constants\n * function foo() { Panic.GENERIC.panic(); }\n *\n * // Alternatively\n * function foo() { Panic.panic(Panic.GENERIC); }\n * }\n * ```\n *\n * Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].\n *\n * _Available since v5.1._\n */\n// slither-disable-next-line unused-state\nlibrary Panic {\n /// @dev generic / unspecified error\n uint256 internal constant GENERIC = 0x00;\n /// @dev used by the assert() builtin\n uint256 internal constant ASSERT = 0x01;\n /// @dev arithmetic underflow or overflow\n uint256 internal constant UNDER_OVERFLOW = 0x11;\n /// @dev division or modulo by zero\n uint256 internal constant DIVISION_BY_ZERO = 0x12;\n /// @dev enum conversion error\n uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;\n /// @dev invalid encoding in storage\n uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;\n /// @dev empty array pop\n uint256 internal constant EMPTY_ARRAY_POP = 0x31;\n /// @dev array out of bounds access\n uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;\n /// @dev resource error (too large allocation or too large array)\n uint256 internal constant RESOURCE_ERROR = 0x41;\n /// @dev calling invalid internal function\n uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;\n\n /// @dev Reverts with a panic code. Recommended to use with\n /// the internal constants with predefined codes.\n function panic(uint256 code) internal pure {\n assembly (\"memory-safe\") {\n mstore(0x00, 0x4e487b71)\n mstore(0x20, code)\n revert(0x1c, 0x24)\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/ReentrancyGuard.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,\n * consider using {ReentrancyGuardTransient} instead.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant NOT_ENTERED = 1;\n uint256 private constant ENTERED = 2;\n\n uint256 private _status;\n\n /**\n * @dev Unauthorized reentrant call.\n */\n error ReentrancyGuardReentrantCall();\n\n constructor() {\n _status = NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and making it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n _nonReentrantBefore();\n _;\n _nonReentrantAfter();\n }\n\n function _nonReentrantBefore() private {\n // On the first call to nonReentrant, _status will be NOT_ENTERED\n if (_status == ENTERED) {\n revert ReentrancyGuardReentrantCall();\n }\n\n // Any calls to nonReentrant after this point will fail\n _status = ENTERED;\n }\n\n function _nonReentrantAfter() private {\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = NOT_ENTERED;\n }\n\n /**\n * @dev Returns true if the reentrancy guard is currently set to \"entered\", which indicates there is a\n * `nonReentrant` function in the call stack.\n */\n function _reentrancyGuardEntered() internal view returns (bool) {\n return _status == ENTERED;\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/ShortStrings.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/ShortStrings.sol)\n\npragma solidity ^0.8.20;\n\nimport {StorageSlot} from \"./StorageSlot.sol\";\n\n// | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |\n// | length | 0x BB |\ntype ShortString is bytes32;\n\n/**\n * @dev This library provides functions to convert short memory strings\n * into a `ShortString` type that can be used as an immutable variable.\n *\n * Strings of arbitrary length can be optimized using this library if\n * they are short enough (up to 31 bytes) by packing them with their\n * length (1 byte) in a single EVM word (32 bytes). Additionally, a\n * fallback mechanism can be used for every other case.\n *\n * Usage example:\n *\n * ```solidity\n * contract Named {\n * using ShortStrings for *;\n *\n * ShortString private immutable _name;\n * string private _nameFallback;\n *\n * constructor(string memory contractName) {\n * _name = contractName.toShortStringWithFallback(_nameFallback);\n * }\n *\n * function name() external view returns (string memory) {\n * return _name.toStringWithFallback(_nameFallback);\n * }\n * }\n * ```\n */\nlibrary ShortStrings {\n // Used as an identifier for strings longer than 31 bytes.\n bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;\n\n error StringTooLong(string str);\n error InvalidShortString();\n\n /**\n * @dev Encode a string of at most 31 chars into a `ShortString`.\n *\n * This will trigger a `StringTooLong` error is the input string is too long.\n */\n function toShortString(string memory str) internal pure returns (ShortString) {\n bytes memory bstr = bytes(str);\n if (bstr.length > 31) {\n revert StringTooLong(str);\n }\n return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));\n }\n\n /**\n * @dev Decode a `ShortString` back to a \"normal\" string.\n */\n function toString(ShortString sstr) internal pure returns (string memory) {\n uint256 len = byteLength(sstr);\n // using `new string(len)` would work locally but is not memory safe.\n string memory str = new string(32);\n assembly (\"memory-safe\") {\n mstore(str, len)\n mstore(add(str, 0x20), sstr)\n }\n return str;\n }\n\n /**\n * @dev Return the length of a `ShortString`.\n */\n function byteLength(ShortString sstr) internal pure returns (uint256) {\n uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;\n if (result > 31) {\n revert InvalidShortString();\n }\n return result;\n }\n\n /**\n * @dev Encode a string into a `ShortString`, or write it to storage if it is too long.\n */\n function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {\n if (bytes(value).length < 32) {\n return toShortString(value);\n } else {\n StorageSlot.getStringSlot(store).value = value;\n return ShortString.wrap(FALLBACK_SENTINEL);\n }\n }\n\n /**\n * @dev Decode a string that was encoded to `ShortString` or written to storage using {toShortStringWithFallback}.\n */\n function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {\n if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {\n return toString(value);\n } else {\n return store;\n }\n }\n\n /**\n * @dev Return the length of a string that was encoded to `ShortString` or written to storage using\n * {toShortStringWithFallback}.\n *\n * WARNING: This will return the \"byte length\" of the string. This may not reflect the actual length in terms of\n * actual characters as the UTF-8 encoding of a single character can span over multiple bytes.\n */\n function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {\n if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {\n return byteLength(value);\n } else {\n return bytes(store).length;\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/StorageSlot.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)\n// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Library for reading and writing primitive types to specific storage slots.\n *\n * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\n * This library helps with reading and writing to such slots without the need for inline assembly.\n *\n * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\n *\n * Example usage to set ERC-1967 implementation slot:\n * ```solidity\n * contract ERC1967 {\n * // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.\n * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n *\n * function _getImplementation() internal view returns (address) {\n * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n * }\n *\n * function _setImplementation(address newImplementation) internal {\n * require(newImplementation.code.length > 0);\n * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n * }\n * }\n * ```\n *\n * TIP: Consider using this library along with {SlotDerivation}.\n */\nlibrary StorageSlot {\n struct AddressSlot {\n address value;\n }\n\n struct BooleanSlot {\n bool value;\n }\n\n struct Bytes32Slot {\n bytes32 value;\n }\n\n struct Uint256Slot {\n uint256 value;\n }\n\n struct Int256Slot {\n int256 value;\n }\n\n struct StringSlot {\n string value;\n }\n\n struct BytesSlot {\n bytes value;\n }\n\n /**\n * @dev Returns an `AddressSlot` with member `value` located at `slot`.\n */\n function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `BooleanSlot` with member `value` located at `slot`.\n */\n function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Bytes32Slot` with member `value` located at `slot`.\n */\n function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Uint256Slot` with member `value` located at `slot`.\n */\n function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Int256Slot` with member `value` located at `slot`.\n */\n function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `StringSlot` with member `value` located at `slot`.\n */\n function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `StringSlot` representation of the string storage pointer `store`.\n */\n function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := store.slot\n }\n }\n\n /**\n * @dev Returns a `BytesSlot` with member `value` located at `slot`.\n */\n function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.\n */\n function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := store.slot\n }\n }\n}\n" + }, + "npm/@openzeppelin/contracts@5.3.0/utils/Strings.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/Strings.sol)\n\npragma solidity ^0.8.20;\n\nimport {Math} from \"./math/Math.sol\";\nimport {SafeCast} from \"./math/SafeCast.sol\";\nimport {SignedMath} from \"./math/SignedMath.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n using SafeCast for *;\n\n bytes16 private constant HEX_DIGITS = \"0123456789abcdef\";\n uint8 private constant ADDRESS_LENGTH = 20;\n uint256 private constant SPECIAL_CHARS_LOOKUP =\n (1 << 0x08) | // backspace\n (1 << 0x09) | // tab\n (1 << 0x0a) | // newline\n (1 << 0x0c) | // form feed\n (1 << 0x0d) | // carriage return\n (1 << 0x22) | // double quote\n (1 << 0x5c); // backslash\n\n /**\n * @dev The `value` string doesn't fit in the specified `length`.\n */\n error StringsInsufficientHexLength(uint256 value, uint256 length);\n\n /**\n * @dev The string being parsed contains characters that are not in scope of the given base.\n */\n error StringsInvalidChar();\n\n /**\n * @dev The string being parsed is not a properly formatted address.\n */\n error StringsInvalidAddressFormat();\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n unchecked {\n uint256 length = Math.log10(value) + 1;\n string memory buffer = new string(length);\n uint256 ptr;\n assembly (\"memory-safe\") {\n ptr := add(buffer, add(32, length))\n }\n while (true) {\n ptr--;\n assembly (\"memory-safe\") {\n mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))\n }\n value /= 10;\n if (value == 0) break;\n }\n return buffer;\n }\n }\n\n /**\n * @dev Converts a `int256` to its ASCII `string` decimal representation.\n */\n function toStringSigned(int256 value) internal pure returns (string memory) {\n return string.concat(value < 0 ? \"-\" : \"\", toString(SignedMath.abs(value)));\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n unchecked {\n return toHexString(value, Math.log256(value) + 1);\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n uint256 localValue = value;\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = HEX_DIGITS[localValue & 0xf];\n localValue >>= 4;\n }\n if (localValue != 0) {\n revert StringsInsufficientHexLength(value, length);\n }\n return string(buffer);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal\n * representation.\n */\n function toHexString(address addr) internal pure returns (string memory) {\n return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal\n * representation, according to EIP-55.\n */\n function toChecksumHexString(address addr) internal pure returns (string memory) {\n bytes memory buffer = bytes(toHexString(addr));\n\n // hash the hex part of buffer (skip length + 2 bytes, length 40)\n uint256 hashValue;\n assembly (\"memory-safe\") {\n hashValue := shr(96, keccak256(add(buffer, 0x22), 40))\n }\n\n for (uint256 i = 41; i > 1; --i) {\n // possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)\n if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {\n // case shift by xoring with 0x20\n buffer[i] ^= 0x20;\n }\n hashValue >>= 4;\n }\n return string(buffer);\n }\n\n /**\n * @dev Returns true if the two strings are equal.\n */\n function equal(string memory a, string memory b) internal pure returns (bool) {\n return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));\n }\n\n /**\n * @dev Parse a decimal string and returns the value as a `uint256`.\n *\n * Requirements:\n * - The string must be formatted as `[0-9]*`\n * - The result must fit into an `uint256` type\n */\n function parseUint(string memory input) internal pure returns (uint256) {\n return parseUint(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseUint-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `[0-9]*`\n * - The result must fit into an `uint256` type\n */\n function parseUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {\n (bool success, uint256 value) = tryParseUint(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseUint-string} that returns false if the parsing fails because of an invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseUint(string memory input) internal pure returns (bool success, uint256 value) {\n return _tryParseUintUncheckedBounds(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseUint-string-uint256-uint256} that returns false if the parsing fails because of an invalid\n * character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseUint(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, uint256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseUintUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseUint-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseUintUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, uint256 value) {\n bytes memory buffer = bytes(input);\n\n uint256 result = 0;\n for (uint256 i = begin; i < end; ++i) {\n uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));\n if (chr > 9) return (false, 0);\n result *= 10;\n result += chr;\n }\n return (true, result);\n }\n\n /**\n * @dev Parse a decimal string and returns the value as a `int256`.\n *\n * Requirements:\n * - The string must be formatted as `[-+]?[0-9]*`\n * - The result must fit in an `int256` type.\n */\n function parseInt(string memory input) internal pure returns (int256) {\n return parseInt(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseInt-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `[-+]?[0-9]*`\n * - The result must fit in an `int256` type.\n */\n function parseInt(string memory input, uint256 begin, uint256 end) internal pure returns (int256) {\n (bool success, int256 value) = tryParseInt(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseInt-string} that returns false if the parsing fails because of an invalid character or if\n * the result does not fit in a `int256`.\n *\n * NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.\n */\n function tryParseInt(string memory input) internal pure returns (bool success, int256 value) {\n return _tryParseIntUncheckedBounds(input, 0, bytes(input).length);\n }\n\n uint256 private constant ABS_MIN_INT256 = 2 ** 255;\n\n /**\n * @dev Variant of {parseInt-string-uint256-uint256} that returns false if the parsing fails because of an invalid\n * character or if the result does not fit in a `int256`.\n *\n * NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.\n */\n function tryParseInt(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, int256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseIntUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseInt-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseIntUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, int256 value) {\n bytes memory buffer = bytes(input);\n\n // Check presence of a negative sign.\n bytes1 sign = begin == end ? bytes1(0) : bytes1(_unsafeReadBytesOffset(buffer, begin)); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n bool positiveSign = sign == bytes1(\"+\");\n bool negativeSign = sign == bytes1(\"-\");\n uint256 offset = (positiveSign || negativeSign).toUint();\n\n (bool absSuccess, uint256 absValue) = tryParseUint(input, begin + offset, end);\n\n if (absSuccess && absValue < ABS_MIN_INT256) {\n return (true, negativeSign ? -int256(absValue) : int256(absValue));\n } else if (absSuccess && negativeSign && absValue == ABS_MIN_INT256) {\n return (true, type(int256).min);\n } else return (false, 0);\n }\n\n /**\n * @dev Parse a hexadecimal string (with or without \"0x\" prefix), and returns the value as a `uint256`.\n *\n * Requirements:\n * - The string must be formatted as `(0x)?[0-9a-fA-F]*`\n * - The result must fit in an `uint256` type.\n */\n function parseHexUint(string memory input) internal pure returns (uint256) {\n return parseHexUint(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseHexUint-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `(0x)?[0-9a-fA-F]*`\n * - The result must fit in an `uint256` type.\n */\n function parseHexUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {\n (bool success, uint256 value) = tryParseHexUint(input, begin, end);\n if (!success) revert StringsInvalidChar();\n return value;\n }\n\n /**\n * @dev Variant of {parseHexUint-string} that returns false if the parsing fails because of an invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseHexUint(string memory input) internal pure returns (bool success, uint256 value) {\n return _tryParseHexUintUncheckedBounds(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseHexUint-string-uint256-uint256} that returns false if the parsing fails because of an\n * invalid character.\n *\n * NOTE: This function will revert if the result does not fit in a `uint256`.\n */\n function tryParseHexUint(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, uint256 value) {\n if (end > bytes(input).length || begin > end) return (false, 0);\n return _tryParseHexUintUncheckedBounds(input, begin, end);\n }\n\n /**\n * @dev Implementation of {tryParseHexUint-string-uint256-uint256} that does not check bounds. Caller should make sure that\n * `begin <= end <= input.length`. Other inputs would result in undefined behavior.\n */\n function _tryParseHexUintUncheckedBounds(\n string memory input,\n uint256 begin,\n uint256 end\n ) private pure returns (bool success, uint256 value) {\n bytes memory buffer = bytes(input);\n\n // skip 0x prefix if present\n bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(buffer, begin)) == bytes2(\"0x\"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n uint256 offset = hasPrefix.toUint() * 2;\n\n uint256 result = 0;\n for (uint256 i = begin + offset; i < end; ++i) {\n uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));\n if (chr > 15) return (false, 0);\n result *= 16;\n unchecked {\n // Multiplying by 16 is equivalent to a shift of 4 bits (with additional overflow check).\n // This guarantees that adding a value < 16 will not cause an overflow, hence the unchecked.\n result += chr;\n }\n }\n return (true, result);\n }\n\n /**\n * @dev Parse a hexadecimal string (with or without \"0x\" prefix), and returns the value as an `address`.\n *\n * Requirements:\n * - The string must be formatted as `(0x)?[0-9a-fA-F]{40}`\n */\n function parseAddress(string memory input) internal pure returns (address) {\n return parseAddress(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseAddress-string} that parses a substring of `input` located between position `begin` (included) and\n * `end` (excluded).\n *\n * Requirements:\n * - The substring must be formatted as `(0x)?[0-9a-fA-F]{40}`\n */\n function parseAddress(string memory input, uint256 begin, uint256 end) internal pure returns (address) {\n (bool success, address value) = tryParseAddress(input, begin, end);\n if (!success) revert StringsInvalidAddressFormat();\n return value;\n }\n\n /**\n * @dev Variant of {parseAddress-string} that returns false if the parsing fails because the input is not a properly\n * formatted address. See {parseAddress-string} requirements.\n */\n function tryParseAddress(string memory input) internal pure returns (bool success, address value) {\n return tryParseAddress(input, 0, bytes(input).length);\n }\n\n /**\n * @dev Variant of {parseAddress-string-uint256-uint256} that returns false if the parsing fails because input is not a properly\n * formatted address. See {parseAddress-string-uint256-uint256} requirements.\n */\n function tryParseAddress(\n string memory input,\n uint256 begin,\n uint256 end\n ) internal pure returns (bool success, address value) {\n if (end > bytes(input).length || begin > end) return (false, address(0));\n\n bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(bytes(input), begin)) == bytes2(\"0x\"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty\n uint256 expectedLength = 40 + hasPrefix.toUint() * 2;\n\n // check that input is the correct length\n if (end - begin == expectedLength) {\n // length guarantees that this does not overflow, and value is at most type(uint160).max\n (bool s, uint256 v) = _tryParseHexUintUncheckedBounds(input, begin, end);\n return (s, address(uint160(v)));\n } else {\n return (false, address(0));\n }\n }\n\n function _tryParseChr(bytes1 chr) private pure returns (uint8) {\n uint8 value = uint8(chr);\n\n // Try to parse `chr`:\n // - Case 1: [0-9]\n // - Case 2: [a-f]\n // - Case 3: [A-F]\n // - otherwise not supported\n unchecked {\n if (value > 47 && value < 58) value -= 48;\n else if (value > 96 && value < 103) value -= 87;\n else if (value > 64 && value < 71) value -= 55;\n else return type(uint8).max;\n }\n\n return value;\n }\n\n /**\n * @dev Escape special characters in JSON strings. This can be useful to prevent JSON injection in NFT metadata.\n *\n * WARNING: This function should only be used in double quoted JSON strings. Single quotes are not escaped.\n *\n * NOTE: This function escapes all unicode characters, and not just the ones in ranges defined in section 2.5 of\n * RFC-4627 (U+0000 to U+001F, U+0022 and U+005C). ECMAScript's `JSON.parse` does recover escaped unicode\n * characters that are not in this range, but other tooling may provide different results.\n */\n function escapeJSON(string memory input) internal pure returns (string memory) {\n bytes memory buffer = bytes(input);\n bytes memory output = new bytes(2 * buffer.length); // worst case scenario\n uint256 outputLength = 0;\n\n for (uint256 i; i < buffer.length; ++i) {\n bytes1 char = bytes1(_unsafeReadBytesOffset(buffer, i));\n if (((SPECIAL_CHARS_LOOKUP & (1 << uint8(char))) != 0)) {\n output[outputLength++] = \"\\\\\";\n if (char == 0x08) output[outputLength++] = \"b\";\n else if (char == 0x09) output[outputLength++] = \"t\";\n else if (char == 0x0a) output[outputLength++] = \"n\";\n else if (char == 0x0c) output[outputLength++] = \"f\";\n else if (char == 0x0d) output[outputLength++] = \"r\";\n else if (char == 0x5c) output[outputLength++] = \"\\\\\";\n else if (char == 0x22) {\n // solhint-disable-next-line quotes\n output[outputLength++] = '\"';\n }\n } else {\n output[outputLength++] = char;\n }\n }\n // write the actual length and deallocate unused memory\n assembly (\"memory-safe\") {\n mstore(output, outputLength)\n mstore(0x40, add(output, shl(5, shr(5, add(outputLength, 63)))))\n }\n\n return string(output);\n }\n\n /**\n * @dev Reads a bytes32 from a bytes array without bounds checking.\n *\n * NOTE: making this function internal would mean it could be used with memory unsafe offset, and marking the\n * assembly block as such would prevent some optimizations.\n */\n function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {\n // This is not memory safe in the general case, but all calls to this private function are within bounds.\n assembly (\"memory-safe\") {\n value := mload(add(buffer, add(0x20, offset)))\n }\n }\n}\n" + }, + "project/contracts/Controller.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\n\nimport './interfaces/IController.sol';\n\n/**\n * @title Controller\n * @dev Manages allow lists for solvers, executors, proposal signers and validators\n */\ncontract Controller is IController, Ownable {\n // List of allowed solvers\n mapping (address => bool) public override isSolverAllowed;\n\n // List of allowed executors\n mapping (address => bool) public override isExecutorAllowed;\n\n // List of allowed proposal signers\n mapping (address => bool) public override isProposalSignerAllowed;\n\n // List of allowed validators\n mapping (address => bool) public override isValidatorAllowed;\n\n // Minimum number of validations allowed\n uint8 public override minValidations;\n\n /**\n * @dev Creates a new Controller contract\n * @param owner Address that will own the contract\n * @param solvers List of allowed solvers\n * @param executors List of allowed executors\n * @param proposalSigners List of allowed proposal signers\n * @param validators List of allowed validators\n * @param _minValidations Minimum number of validations allowed\n */\n constructor(\n address owner,\n address[] memory solvers,\n address[] memory executors,\n address[] memory proposalSigners,\n address[] memory validators,\n uint8 _minValidations\n ) Ownable(owner) {\n for (uint256 i = 0; i < solvers.length; i++) _setAllowedSolver(solvers[i], true);\n for (uint256 i = 0; i < executors.length; i++) _setAllowedExecutor(executors[i], true);\n for (uint256 i = 0; i < proposalSigners.length; i++) _setAllowedProposalSigner(proposalSigners[i], true);\n for (uint256 i = 0; i < validators.length; i++) _setAllowedValidator(validators[i], true);\n _setMinValidations(_minValidations);\n }\n\n /**\n * @dev Sets permissions for multiple solvers\n * @param solvers List of solver addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedSolvers(address[] memory solvers, bool[] memory alloweds) external override onlyOwner {\n if (solvers.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < solvers.length; i++) _setAllowedSolver(solvers[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple executors\n * @param executors List of executor addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedExecutors(address[] memory executors, bool[] memory alloweds) external override onlyOwner {\n if (executors.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < executors.length; i++) _setAllowedExecutor(executors[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple proposal signers\n * @param signers List of proposal signer addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedProposalSigners(address[] memory signers, bool[] memory alloweds) external override onlyOwner {\n if (signers.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < signers.length; i++) _setAllowedProposalSigner(signers[i], alloweds[i]);\n }\n\n /**\n * @dev Sets permissions for multiple validators\n * @param validators List of validator addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedValidators(address[] memory validators, bool[] memory alloweds) external override onlyOwner {\n if (validators.length != alloweds.length) revert ControllerInputInvalidLength();\n for (uint256 i = 0; i < validators.length; i++) _setAllowedValidator(validators[i], alloweds[i]);\n }\n\n /**\n * @dev Sets the minimum number of validations allowed\n * @param newMinValidations minimum number of validations allowed\n */\n function setMinValidations(uint8 newMinValidations) external override onlyOwner {\n _setMinValidations(newMinValidations);\n }\n\n /**\n * @dev Sets a solver permission\n */\n function _setAllowedSolver(address solver, bool allowed) internal {\n isSolverAllowed[solver] = allowed;\n emit SolverAllowedSet(solver, allowed);\n }\n\n /**\n * @dev Sets an executor permission\n */\n function _setAllowedExecutor(address executor, bool allowed) internal {\n isExecutorAllowed[executor] = allowed;\n emit ExecutorAllowedSet(executor, allowed);\n }\n\n /**\n * @dev Sets a proposal signer permission\n */\n function _setAllowedProposalSigner(address signer, bool allowed) internal {\n isProposalSignerAllowed[signer] = allowed;\n emit ProposalSignerAllowedSet(signer, allowed);\n }\n\n /**\n * @dev Sets a validator permission\n */\n function _setAllowedValidator(address validator, bool allowed) internal {\n isValidatorAllowed[validator] = allowed;\n emit ValidatorAllowedSet(validator, allowed);\n }\n\n /**\n * @dev Sets the minimum number of validations allowed\n */\n function _setMinValidations(uint8 newMinValidations) internal {\n minValidations = newMinValidations;\n emit MinValidationSet(newMinValidations);\n }\n}\n" + }, + "project/contracts/Intents.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Enum representing the type of intent operation.\n * - Swap: Swap tokens between chains or tokens.\n * - Transfer: Transfer tokens to one or more recipients.\n * - Call: Execute arbitrary contract calls.\n */\nenum OpType {\n Swap,\n Transfer,\n Call\n}\n\n/**\n * @dev Execution structure.\n * @param intent Intent to be fulfilled.\n * @param proposal Proposal to be executed.\n * @param signature Proposal signature.\n */\nstruct Execution {\n Intent intent;\n Proposal proposal;\n bytes signature;\n}\n\n/**\n * @dev EIP-712 typed data struct representing a validator's approval of an intent.\n * @param intent The hash of the intent being validated.\n */\nstruct Validation {\n bytes32 intent;\n}\n\n/**\n * @dev General intent structure used to abstract over different intent types.\n * @param op The type of operation this intent represents.\n * @param user The originator of the intent.\n * @param settler The address responsible for executing the intent on-chain.\n * @param nonce A unique value used to prevent replay attacks and distinguish intents.\n * @param deadline The timestamp by which the intent must be executed.\n * @param data ABI-encoded data representing a specific intent type (e.g. SwapIntent, TransferIntent, CallIntent).\n * @param maxFees List of max fees the user is willing to pay for the intent.\n * @param events List of custom intent events to be emitted.\n * @param configSig The signature of the configuration that this intent belongs to\n * @param minValidations The minimum number of validator approvals required for this intent to be considered valid.\n * @param validations The list validator signatures attesting to this intent.\n */\nstruct Intent {\n uint8 op;\n address user;\n address settler;\n bytes32 nonce;\n uint256 deadline;\n bytes data;\n MaxFee[] maxFees;\n IntentEvent[] events;\n bytes configSig;\n uint256 minValidations;\n bytes[] validations;\n}\n\n/**\n * @dev Max fee representation\n * @param token Token used to pay for the execution fee.\n * @param amount Max amount of fee token to be paid for settling this intent.\n */\nstruct MaxFee {\n address token;\n uint256 amount;\n}\n\n/**\n * @dev Intent event representation.\n * @param topic Event topic to be emitted.\n * @param data Event data to be emitted.\n */\nstruct IntentEvent {\n bytes32 topic;\n bytes data;\n}\n\n/**\n * @dev Represents a swap intent between two chains.\n * @param sourceChain Chain ID where tokens will be sent from.\n * @param destinationChain Chain ID where tokens will be received.\n * @param tokensIn List of input tokens and amounts to swap.\n * @param tokensOut List of expected output tokens, minimum amounts, and recipients.\n */\nstruct SwapIntent {\n uint256 sourceChain;\n uint256 destinationChain;\n TokenIn[] tokensIn;\n TokenOut[] tokensOut;\n}\n\n/**\n * @dev Token in representation.\n * @param token Address of a token to be sent.\n * @param amount Amount of tokens to be sent.\n */\nstruct TokenIn {\n address token;\n uint256 amount;\n}\n\n/**\n * @dev Token out representation.\n * @param token Address of a token to be received.\n * @param minAmount Minimum amount of tokens to be received.\n * @param recipient Recipient address that will receive the token out.\n */\nstruct TokenOut {\n address token;\n uint256 minAmount;\n address recipient;\n}\n\n/**\n * @dev Represents a transfer intent containing multiple token transfers.\n * @param chainId Chain ID where the transfers should be executed.\n * @param transfers List of token transfers to be performed.\n */\nstruct TransferIntent {\n uint256 chainId;\n TransferData[] transfers;\n}\n\n/**\n * @dev Transfer data for a single token transfer.\n * @param token Address of the token to transfer.\n * @param amount Amount of the token to transfer.\n * @param recipient Recipient of the token transfer.\n */\nstruct TransferData {\n address token;\n uint256 amount;\n address recipient;\n}\n\n/**\n * @dev Represents a generic call intent consisting of one or more contract calls.\n * @param chainId Chain ID where the calls should be executed.\n * @param calls List of low-level contract calls to be executed.\n */\nstruct CallIntent {\n uint256 chainId;\n CallData[] calls;\n}\n\n/**\n * @dev Low-level call data for a target contract interaction.\n * @param target Target contract address.\n * @param data Calldata to be sent to the target.\n * @param value ETH value to send along with the call.\n */\nstruct CallData {\n address target;\n bytes data;\n uint256 value;\n}\n\n/**\n * @dev Generic proposal structure representing a solver’s response to an intent.\n * @param deadline Timestamp until when the proposal is valid.\n * @param data ABI-encoded proposal-specific data (e.g. SwapProposal).\n * @param fees List of fee amounts the solver requires for execution.\n */\nstruct Proposal {\n uint256 deadline;\n bytes data;\n uint256[] fees;\n}\n\n/**\n * @dev Swap proposal representation for a swap intent.\n * @param executor Address of the executor contract that should be called during intent execution.\n * @param data Arbitrary data used to call the executor contract.\n * @param amountsOut List of amounts of tokens out proposed by the solver.\n */\nstruct SwapProposal {\n address executor;\n bytes data;\n uint256[] amountsOut;\n}\n\nlibrary IntentsHelpers {\n bytes32 internal constant INTENT_TYPE_HASH =\n keccak256(\n 'Intent(uint8 op,address user,address settler,bytes32 nonce,uint256 deadline,bytes data,MaxFee[] maxFees,IntentEvent[] events,bytes configSig,uint256 minValidations)IntentEvent(bytes32 topic,bytes data)MaxFee(address token,uint256 amount)'\n );\n\n bytes32 internal constant PROPOSAL_TYPE_HASH =\n keccak256('Proposal(bytes32 intent,address solver,uint256 deadline,bytes data,uint256[] fees)');\n\n bytes32 internal constant VALIDATION_TYPE_HASH = keccak256('Validation(bytes32 intent)');\n\n bytes32 internal constant MAX_FEE_TYPE_HASH = keccak256('MaxFee(address token,uint256 amount)');\n\n bytes32 internal constant INTENT_EVENT_TYPE_HASH = keccak256('IntentEvent(bytes32 topic,bytes data)');\n\n function hash(Intent memory intent) internal pure returns (bytes32) {\n return\n keccak256(\n abi.encode(\n INTENT_TYPE_HASH,\n intent.op,\n intent.user,\n intent.settler,\n intent.nonce,\n intent.deadline,\n keccak256(intent.data),\n hash(intent.maxFees),\n hash(intent.events),\n intent.configSig,\n intent.minValidations\n )\n );\n }\n\n function hash(Proposal memory proposal, Intent memory intent, address solver) internal pure returns (bytes32) {\n return\n keccak256(\n abi.encode(\n PROPOSAL_TYPE_HASH,\n hash(intent),\n solver,\n proposal.deadline,\n keccak256(proposal.data),\n hash(proposal.fees)\n )\n );\n }\n\n function hash(MaxFee[] memory fees) internal pure returns (bytes32) {\n bytes32[] memory hashes = new bytes32[](fees.length);\n for (uint256 i = 0; i < fees.length; i++) {\n hashes[i] = keccak256(abi.encode(MAX_FEE_TYPE_HASH, fees[i].token, fees[i].amount));\n }\n return keccak256(abi.encodePacked(hashes));\n }\n\n function hash(IntentEvent[] memory events) internal pure returns (bytes32) {\n bytes32[] memory hashes = new bytes32[](events.length);\n for (uint256 i = 0; i < events.length; i++) {\n hashes[i] = keccak256(abi.encode(INTENT_EVENT_TYPE_HASH, events[i].topic, keccak256(events[i].data)));\n }\n return keccak256(abi.encodePacked(hashes));\n }\n\n function hash(uint256[] memory fees) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(fees));\n }\n\n function hash(Validation memory validation) internal pure returns (bytes32) {\n return keccak256(abi.encode(VALIDATION_TYPE_HASH, validation.intent));\n }\n}\n" + }, + "project/contracts/interfaces/IController.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @title Controller interface\n */\ninterface IController {\n /**\n * @dev The input arrays are not of equal length\n */\n error ControllerInputInvalidLength();\n\n /**\n * @dev Emitted every time a solver permission is set\n */\n event SolverAllowedSet(address indexed solver, bool allowed);\n\n /**\n * @dev Emitted every time an executor permission is set\n */\n event ExecutorAllowedSet(address indexed executor, bool allowed);\n\n /**\n * @dev Emitted every time a proposal signer permission is set\n */\n event ProposalSignerAllowedSet(address indexed proposalSigner, bool allowed);\n\n /**\n * @dev Emitted every time a validator permission is set\n */\n event ValidatorAllowedSet(address indexed validator, bool allowed);\n\n /**\n * @dev Emitted when the minimum validations changes\n */\n event MinValidationSet(uint8 indexed newMinValidation);\n\n /**\n * @dev Tells whether a solver is allowed\n * @param solver Address of the solver being queried\n */\n function isSolverAllowed(address solver) external view returns (bool);\n\n /**\n * @dev Tells whether an executor is allowed\n * @param executor Address of the executor being queried\n */\n function isExecutorAllowed(address executor) external view returns (bool);\n\n /**\n * @dev Tells whether a proposal signer is allowed\n * @param signer Address of the proposal signer being queried\n */\n function isProposalSignerAllowed(address signer) external view returns (bool);\n\n /**\n * @dev Tells whether a validator is allowed\n * @param validator Address of the validator being queried\n */\n function isValidatorAllowed(address validator) external view returns (bool);\n\n /**\n * @dev Tells the minimum number of validations allowed\n */\n function minValidations() external view returns (uint8);\n\n /**\n * @dev Sets permissions for multiple solvers\n * @param solvers List of solver addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedSolvers(address[] memory solvers, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple executors\n * @param executors List of executor addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedExecutors(address[] memory executors, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple proposal signers\n * @param signers List of proposal signer addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedProposalSigners(address[] memory signers, bool[] memory alloweds) external;\n\n /**\n * @dev Sets permissions for multiple validators\n * @param validators List of validator addresses\n * @param alloweds List of permission statuses\n */\n function setAllowedValidators(address[] memory validators, bool[] memory alloweds) external;\n\n /**\n * @dev Sets the minimum number of validations allowed\n * @param newMinValidations minimum number of validations allowed\n */\n function setMinValidations(uint8 newMinValidations) external;\n}\n" + }, + "project/contracts/interfaces/ICreateX.sol": { + "content": "// SPDX-License-Identifier: AGPL-3.0-only\n\npragma solidity ^0.8.4;\n\n/**\n * @title CreateX Factory Interface Definition\n * @author pcaversaccio (https://web.archive.org/web/20230921103111/https://pcaversaccio.com/)\n * @custom:coauthor Matt Solomon (https://web.archive.org/web/20230921103335/https://mattsolomon.dev/)\n */\ninterface ICreateX {\n event ContractCreation(address indexed newContract);\n\n function deployCreate3(bytes32 salt, bytes memory initCode) external payable returns (address newContract);\n}\n" + }, + "project/contracts/interfaces/IExecutor.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\n\n/**\n * @title Executor interface\n */\ninterface IExecutor {\n /**\n * @dev Executes an intent proposal\n * @param intent Intent to be executed\n * @param proposal Proposal to be executed to fulfill the intent\n */\n function execute(Intent memory intent, Proposal memory proposal) external;\n}\n" + }, + "project/contracts/interfaces/IIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\nimport '../safeguards/Safeguards.sol';\n\n/**\n * @title IntentsValidator\n * @dev Performs intents validations based on safeguards\n */\ninterface IIntentsValidator {\n /**\n * @dev Validates an intent for a safeguard\n * @param intent Intent to be validated\n * @param config Safeguard config to validate the intent with\n */\n function validate(Intent memory intent, bytes memory config) external pure;\n}\n" + }, + "project/contracts/interfaces/ISafe.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nenum SafeOperation {\n Call,\n DelegateCall\n}\n\ninterface ISafe {\n function getThreshold() external view returns (uint256);\n\n function execTransactionFromModuleReturnData(address to, uint256 value, bytes memory data, SafeOperation operation)\n external\n returns (bool success, bytes memory returnData);\n}\n" + }, + "project/contracts/interfaces/ISettler.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../Intents.sol';\nimport '../safeguards/Safeguards.sol';\n\n/**\n * @title Settler interface\n */\ninterface ISettler {\n /**\n * @dev The requested intent type is unknown\n */\n error SettlerUnknownIntentType(uint8 op);\n\n /**\n * @dev The simulation has been successful\n */\n error SettlerSimulationSuccess(uint256 gasUsed);\n\n /**\n * @dev The solver is not allowed\n */\n error SettlerSolverNotAllowed(address solver);\n\n /**\n * @dev The executor is not allowed\n */\n error SettlerExecutorNotAllowed(address executor);\n\n /**\n * @dev The proposal signer is not allowed\n */\n error SettlerProposalSignerNotAllowed(address signer);\n\n /**\n * @dev The validator is not allowed\n */\n error SettlerValidatorNotAllowed(address validator);\n\n /**\n * @dev The validator is duplicated\n */\n error SettlerValidatorDuplicatedOrUnsorted(address previous, address current);\n\n /**\n * @dev The settler is not the current contract\n */\n error SettlerInvalidSettler(address settler);\n\n /**\n * @dev The nonce is zero\n */\n error SettlerNonceZero();\n\n /**\n * @dev The nonce has already been used for the user\n */\n error SettlerNonceAlreadyUsed(address user, bytes32 nonce);\n\n /**\n * @dev The intent deadline is in the past\n */\n error SettlerIntentPastDeadline(uint256 deadline, uint256 timestamp);\n\n /**\n * @dev The current chain is not valid\n */\n error SettlerInvalidChain(uint256 chainId);\n\n /**\n * @dev The recipient is the settler contract\n */\n error SettlerInvalidRecipient(address to);\n\n /**\n * @dev The user is not a smart account\n */\n error SettlerUserNotSmartAccount(address user);\n\n /**\n * @dev The amount out is lower than the proposed amount\n */\n error SettlerAmountOutLtProposed(uint256 index, uint256 amountOut, uint256 proposed);\n\n /**\n * @dev The proposed amount is lower than the minimum amount\n */\n error SettlerProposedAmountLtMinAmount(uint256 index, uint256 proposed, uint256 minAmount);\n\n /**\n * @dev The proposed amounts array and the tokens out array are not of equal length\n */\n error SettlerInvalidProposedAmounts();\n\n /**\n * @dev The balance after the proposal execution is lower than the balance before\n */\n error SettlerPostBalanceOutLtPre(uint256 index, uint256 post, uint256 pre);\n\n /**\n * @dev The solver fees length does not match the requested by the user\n */\n error SettlerSolverFeeInvalidLength();\n\n /**\n * @dev The solver fee is too high\n */\n error SettlerSolverFeeTooHigh(uint256 fee, uint256 max);\n\n /**\n * @dev The intent validations are not enough\n */\n error SettlerIntentValidationsNotEnough(uint256 min, uint256 current);\n\n /**\n * @dev The proposal deadline is in the past\n */\n error SettlerProposalPastDeadline(uint256 deadline, uint256 timestamp);\n\n /**\n * @dev The proposal data is not empty\n */\n error SettlerProposalDataNotEmpty();\n\n /**\n * @dev The rescue funds recipient is zero\n */\n error SettlerRescueFundsRecipientZero();\n\n /**\n * @dev The list of safeguards exceed the maximum allowed\n */\n error SettlerTooManySafeguards(uint256 lengthRequested);\n\n /**\n * @dev The new smart accounts handler is zero\n */\n error SmartAccountsHandlerZero();\n\n /**\n * @dev Custom events emitted for each intent\n */\n event IntentExecuted(\n address indexed user,\n bytes32 indexed topic,\n uint8 indexed op,\n Intent intent,\n Proposal proposal,\n bytes output,\n bytes data\n );\n\n /**\n * @dev Emitted every time an intent is fulfilled\n */\n event ProposalExecuted(bytes32 indexed proposal, uint256 index);\n\n /**\n * @dev Emitted every time tokens are withdrawn from the contract balance\n */\n event FundsRescued(address indexed token, address indexed recipient, uint256 amount);\n\n /**\n * @dev Emitted every time the smart accounts handler is set\n */\n event SmartAccountsHandlerSet(address indexed smartAccountsHandler);\n\n /**\n * @dev Emitted every time the intents validator is set\n */\n event IntentsValidatorSet(address indexed intentsValidator);\n\n /**\n * @dev Emitted every time a safeguard is set\n */\n event SafeguardSet(address indexed user);\n\n /**\n * @dev Tells the reference to the Mimic controller\n */\n function controller() external view returns (address);\n\n /**\n * @dev Tells the reference to the smart accounts handler\n */\n function smartAccountsHandler() external view returns (address);\n\n /**\n * @dev Tells the reference to the intents validator\n */\n function intentsValidator() external view returns (address);\n\n /**\n * @dev Tells the block at which a user nonce was used. Returns 0 if unused.\n * @param user Address of the user being queried\n * @param nonce Nonce being queried\n */\n function getNonceBlock(address user, bytes32 nonce) external view returns (uint256);\n\n /**\n * @dev Tells the safeguard set for a user\n * @param user Address of the user being queried\n */\n function getUserSafeguard(address user) external view returns (bytes memory);\n\n /**\n * @dev Tells the hash of an intent\n * @param intent Intent to get the hash of\n */\n function getIntentHash(Intent memory intent) external pure returns (bytes32);\n\n /**\n * @dev Tells the hash of a proposal\n * @param proposal Proposal to be hashed\n * @param intent Intent being fulfilled by the requested proposal\n * @param solver Address of the solver that made the proposal\n */\n function getProposalHash(Proposal memory proposal, Intent memory intent, address solver)\n external\n pure\n returns (bytes32);\n\n /**\n * @dev Withdraws ERC20 or native tokens from the contract\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function rescueFunds(address token, address recipient, uint256 amount) external;\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function setSmartAccountsHandler(address newSmartAccountsHandler) external;\n\n /**\n * @dev Sets a new intents validator address\n * @param newIntentsValidator New intents validator to be set\n */\n function setIntentsValidator(address newIntentsValidator) external;\n\n /**\n * @dev Sets a safeguard for a user\n * @param safeguard Safeguard to be set\n */\n function setSafeguard(bytes memory safeguard) external;\n\n /**\n * @dev Executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function execute(Execution[] memory executions) external;\n\n /**\n * @dev Simulates an execution. It will always revert. Successful executions are returned as\n * `SettlerSimulationSuccess` errors. Any other error should be treated as failure.\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function simulate(Execution[] memory executions) external;\n}\n" + }, + "project/contracts/interfaces/ISmartAccount.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/introspection/IERC165.sol';\n\n/**\n * @title SmartAccount interface\n */\ninterface ISmartAccount is IERC165 {\n /**\n * @dev Emitted every time tokens are transferred\n */\n event Transferred(address indexed token, address indexed recipient, uint256 amount);\n\n /**\n * @dev Emitted every time `call` is called\n */\n event Called(address indexed target, bytes data, uint256 value, bytes result);\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the owner or the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) external;\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the owner or the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n */\n function call(address target, bytes memory data, uint256 value) external returns (bytes memory result);\n}\n" + }, + "project/contracts/interfaces/ISmartAccountContract.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/interfaces/IERC1271.sol';\n\nimport './ISmartAccount.sol';\n\n/**\n * @title SmartAccountContract interface\n */\ninterface ISmartAccountContract is ISmartAccount, IERC1271 {\n // solhint-disable-previous-line no-empty-blocks\n}\n" + }, + "project/contracts/interfaces/ISmartAccountsHandler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\ninterface ISmartAccountsHandler {\n /**\n * @dev The smart account given is not supported\n */\n error SmartAccountsHandlerUnsupportedAccount(address account);\n\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address account) external view returns (bool);\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address account, address token, address to, uint256 amount) external;\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address account, address target, bytes memory data, uint256 value) external returns (bytes memory);\n}\n" + }, + "project/contracts/safeguards/BaseIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @title BaseIntentsValidator\n */\ncontract BaseIntentsValidator {\n /**\n * @dev No intents allowed\n */\n error IntentsValidatorNoneAllowed();\n\n /**\n * @dev Intent type unknown\n */\n error IntentsValidatorUnknownIntentType(uint8 opType);\n\n /**\n * @dev Invalid safeguard mode\n */\n error IntentsValidatorInvalidSafeguardMode(uint8 mode);\n\n /**\n * @dev Tells whether a chain is allowed\n */\n function _isChainAllowed(uint256 chainId, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, uint256[] memory values) = abi.decode(config, (bool, uint256[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (chainId == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (chainId == values[i]) return true;\n }\n return false;\n }\n }\n\n /**\n * @dev Tells whether an account is allowed\n */\n function _isAccountAllowed(address account, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, address[] memory values) = abi.decode(config, (bool, address[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (account == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (account == values[i]) return true;\n }\n return false;\n }\n }\n\n /**\n * @dev Tells whether a selector is allowed\n */\n function _isSelectorAllowed(bytes4 selector, bytes memory config) internal pure returns (bool) {\n (bool isDenyList, bytes4[] memory values) = abi.decode(config, (bool, bytes4[]));\n if (isDenyList) {\n for (uint256 i = 0; i < values.length; i++) {\n if (selector == values[i]) return false;\n }\n return true;\n } else {\n for (uint256 i = 0; i < values.length; i++) {\n if (selector == values[i]) return true;\n }\n return false;\n }\n }\n}\n" + }, + "project/contracts/safeguards/CallIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './Safeguards.sol';\nimport './BaseIntentsValidator.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Call safeguard modes to validate call intents\n * @param None To ensure no calls are allowed\n * @param Chain To validate that the chain where calls execute is allowed\n * @param Target To validate that the call targets (contract addresses) are allowed\n * @param Selector To validate that the function selectors being called are allowed\n */\nenum CallSafeguardMode {\n None,\n Chain,\n Target,\n Selector\n}\n\n/**\n * @title CallIntentsValidator\n * @dev Performs call intents validations based on safeguards\n */\ncontract CallIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a call intent is valid for a safeguard\n * @param intent Call intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isCallIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n CallIntent memory callIntent = abi.decode(intent.data, (CallIntent));\n if (safeguard.mode == uint8(CallSafeguardMode.Chain))\n return _isChainAllowed(callIntent.chainId, safeguard.config);\n if (safeguard.mode == uint8(CallSafeguardMode.Target))\n return _areCallTargetsValid(callIntent.calls, safeguard.config);\n if (safeguard.mode == uint8(CallSafeguardMode.Selector))\n return _areCallSelectorsValid(callIntent.calls, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the call targets are allowed\n */\n function _areCallTargetsValid(CallData[] memory calls, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < calls.length; i++) {\n if (!_isAccountAllowed(calls[i].target, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the call selectors are allowed\n */\n function _areCallSelectorsValid(CallData[] memory calls, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < calls.length; i++) {\n if (!_isSelectorAllowed(bytes4(calls[i].data), config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/safeguards/IntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './CallIntentsValidator.sol';\nimport './TransferIntentsValidator.sol';\nimport './Safeguards.sol';\nimport './SwapIntentsValidator.sol';\nimport '../Intents.sol';\nimport '../interfaces/IIntentsValidator.sol';\n\n/**\n * @title IntentsValidator\n * @dev Performs intents validations based on safeguards\n */\ncontract IntentsValidator is IIntentsValidator, SwapIntentsValidator, TransferIntentsValidator, CallIntentsValidator {\n /**\n * @dev Safeguard validation failed\n */\n error IntentsValidatorSafeguardFailed();\n\n /**\n * @dev Invalid safeguard config mode\n */\n error IntentsValidatorInvalidSafeguardConfigMode(uint8 mode);\n\n /**\n * @dev Invalid safeguard group logic mode\n */\n error IntentsValidatorInvalidSafeguardGroupLogicMode(uint8 mode);\n\n /**\n * @dev Tells whether an intent is valid for a safeguard\n * @param intent Intent to be validated\n * @param config Safeguard config to validate the intent with\n */\n function validate(Intent memory intent, bytes memory config) external pure override {\n (uint8 mode, bytes memory safeguard) = abi.decode(config, (uint8, bytes));\n if (mode == uint8(SafeguardConfigMode.List)) _validate(intent, abi.decode(safeguard, (Safeguard[])));\n else if (mode == uint8(SafeguardConfigMode.Tree)) _validate(intent, _decodeSafeguardTree(safeguard));\n else revert IntentsValidatorInvalidSafeguardConfigMode(mode);\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguards list\n * @param intent Intent to be validated\n * @param safeguards Safeguard list to validate the intent with\n */\n function _validate(Intent memory intent, Safeguard[] memory safeguards) internal pure {\n if (safeguards.length == 0) revert IntentsValidatorSafeguardFailed();\n for (uint256 i = 0; i < safeguards.length; i++) {\n if (!_isSafeguardValid(intent, safeguards[i])) revert IntentsValidatorSafeguardFailed();\n }\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard tree\n * @param intent Intent to be validated\n * @param tree Safeguard tree to validate the intent with\n */\n function _validate(Intent memory intent, SafeguardTree memory tree) internal pure {\n if (tree.nodes.length == 0) revert IntentsValidatorSafeguardFailed();\n if (!_isSafeguardGroupValid(intent, tree, 0)) revert IntentsValidatorSafeguardFailed();\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard tree at a certain level\n * @param intent Intent to be validated\n * @param tree Safeguard tree to validate the intent with\n * @param index Index of the group node to evaluate\n */\n function _isSafeguardGroupValid(Intent memory intent, SafeguardTree memory tree, uint16 index)\n internal\n pure\n returns (bool)\n {\n SafeguardGroup memory group = tree.nodes[index];\n\n if (group.logic == uint8(SafeguardGroupLogic.NOT)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i])) return false;\n }\n return true;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.AND)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (!_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (!_isSafeguardGroupValid(intent, tree, group.children[i])) return false;\n }\n return true;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.OR)) {\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]])) return true;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i])) return true;\n }\n return false;\n }\n\n if (group.logic == uint8(SafeguardGroupLogic.XOR)) {\n uint256 hits = 0;\n for (uint256 i = 0; i < group.leaves.length; i++) {\n if (_isSafeguardValid(intent, tree.leaves[group.leaves[i]]))\n if (++hits > 1) return false;\n }\n for (uint256 i = 0; i < group.children.length; i++) {\n if (_isSafeguardGroupValid(intent, tree, group.children[i]))\n if (++hits > 1) return false;\n }\n return hits == 1;\n }\n\n revert IntentsValidatorInvalidSafeguardGroupLogicMode(group.logic);\n }\n\n /**\n * @dev Tells whether an intent is valid for a safeguard\n * @param intent Intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isSafeguardValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n if (safeguard.mode == uint8(0)) revert IntentsValidatorNoneAllowed();\n if (intent.op == uint8(OpType.Swap)) return _isSwapIntentValid(intent, safeguard);\n if (intent.op == uint8(OpType.Transfer)) return _isTransferIntentValid(intent, safeguard);\n if (intent.op == uint8(OpType.Call)) return _isCallIntentValid(intent, safeguard);\n revert IntentsValidatorUnknownIntentType(uint8(intent.op));\n }\n\n /**\n * @dev Safely decodes a safeguard tree avoiding compiler issues with dynamic arrays\n * @param data Safeguard tree data to be decoded\n */\n function _decodeSafeguardTree(bytes memory data) private pure returns (SafeguardTree memory) {\n (SafeguardGroup[] memory nodes, Safeguard[] memory leaves) = abi.decode(data, (SafeguardGroup[], Safeguard[]));\n return SafeguardTree(nodes, leaves);\n }\n}\n" + }, + "project/contracts/safeguards/Safeguards.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Safeguard config modes\n * - List: Safeguard lists\n * - Tree: Safeguard groups\n */\nenum SafeguardConfigMode {\n List,\n Tree\n}\n\n/**\n * @dev Logical operators for safeguard groups\n * - AND: every child must pass\n * - OR: at least one child must pass\n * - XOR: exactly one child must pass\n * - NOT: every child must fail\n */\nenum SafeguardGroupLogic {\n AND,\n OR,\n XOR,\n NOT\n}\n\n/**\n * @dev Flat node in the safeguard tree\n * @param logic Group operator (AND/OR/XOR/NOT)\n * @param leaves Indices into `SafeguardTree.leaves`\n * @param children Indices into `SafeguardTree.nodes`\n */\nstruct SafeguardGroup {\n uint8 logic;\n uint16[] leaves;\n uint16[] children;\n}\n\n/**\n * @dev Safeguard tree representation\n * @param nodes List of all the nodes in the tree\n * @param leaves List of all the leaves in the tree\n */\nstruct SafeguardTree {\n SafeguardGroup[] nodes;\n Safeguard[] leaves;\n}\n\n/**\n * @dev Safeguard representation\n * @param mode Safeguard mode\n * @param config Safeguard configuration settings or parameters\n */\nstruct Safeguard {\n uint8 mode;\n bytes config;\n}\n" + }, + "project/contracts/safeguards/SwapIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './BaseIntentsValidator.sol';\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Swap safeguard modes to validate swap intents\n * @param None To ensure no swaps are allowed\n * @param SourceChain To validate that the source chain is allowed\n * @param DestinationChain To validate that the destination chain is allowed\n * @param TokenIn To validate that the tokens to be sent are allowed\n * @param TokenOut To validate that the tokens to be received are allowed\n * @param Recipient To validate that the recipients that will receive the tokens are allowed\n */\nenum SwapSafeguardMode {\n None,\n SourceChain,\n DestinationChain,\n TokenIn,\n TokenOut,\n Recipient\n}\n\n/**\n * @title SwapIntentsValidator\n * @dev Performs swap intents validations based on safeguards\n */\ncontract SwapIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a swap intent is valid for a safeguard\n * @param intent Swap intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isSwapIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n if (safeguard.mode == uint8(SwapSafeguardMode.SourceChain))\n return _isChainAllowed(swapIntent.sourceChain, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.DestinationChain))\n return _isChainAllowed(swapIntent.destinationChain, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.TokenIn))\n return _areSwapTokensInValid(swapIntent.tokensIn, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.TokenOut))\n return _areSwapTokensOutValid(swapIntent.tokensOut, safeguard.config);\n if (safeguard.mode == uint8(SwapSafeguardMode.Recipient))\n return _areSwapRecipientsValid(swapIntent.tokensOut, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the tokens to be sent are allowed\n */\n function _areSwapTokensInValid(TokenIn[] memory tokensIn, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensIn.length; i++) {\n if (!_isAccountAllowed(tokensIn[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the tokens to be received are allowed\n */\n function _areSwapTokensOutValid(TokenOut[] memory tokensOut, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensOut.length; i++) {\n if (!_isAccountAllowed(tokensOut[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the recipients to be received are allowed\n */\n function _areSwapRecipientsValid(TokenOut[] memory tokensOut, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < tokensOut.length; i++) {\n if (!_isAccountAllowed(tokensOut[i].recipient, config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/safeguards/TransferIntentsValidator.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport './BaseIntentsValidator.sol';\nimport './Safeguards.sol';\nimport '../Intents.sol';\n\n/**\n * @dev Transfer safeguard modes to validate transfer intents\n * @param None To ensure no transfers are allowed\n * @param Chain To validate that the chain where transfers execute is allowed\n * @param Token To validate that the tokens being transferred are allowed\n * @param Recipient To validate that the recipients of the transfers are allowed\n */\nenum TransferSafeguardMode {\n None,\n Chain,\n Token,\n Recipient\n}\n\n/**\n * @title TransferIntentsValidator\n * @dev Performs transfer intents validations based on safeguards\n */\ncontract TransferIntentsValidator is BaseIntentsValidator {\n /**\n * @dev Tells whether a transfer intent is valid for a safeguard\n * @param intent Transfer intent to be validated\n * @param safeguard Safeguard to validate the intent with\n */\n function _isTransferIntentValid(Intent memory intent, Safeguard memory safeguard) internal pure returns (bool) {\n TransferIntent memory transferIntent = abi.decode(intent.data, (TransferIntent));\n if (safeguard.mode == uint8(TransferSafeguardMode.Chain))\n return _isChainAllowed(transferIntent.chainId, safeguard.config);\n if (safeguard.mode == uint8(TransferSafeguardMode.Token))\n return _areTransferTokensValid(transferIntent.transfers, safeguard.config);\n if (safeguard.mode == uint8(TransferSafeguardMode.Recipient))\n return _areTransferRecipientsValid(transferIntent.transfers, safeguard.config);\n revert IntentsValidatorInvalidSafeguardMode(safeguard.mode);\n }\n\n /**\n * @dev Tells whether the tokens being transferred are allowed\n */\n function _areTransferTokensValid(TransferData[] memory transfers, bytes memory config) private pure returns (bool) {\n for (uint256 i = 0; i < transfers.length; i++) {\n if (!_isAccountAllowed(transfers[i].token, config)) return false;\n }\n return true;\n }\n\n /**\n * @dev Tells whether the recipients of the transfers are allowed\n */\n function _areTransferRecipientsValid(TransferData[] memory transfers, bytes memory config)\n private\n pure\n returns (bool)\n {\n for (uint256 i = 0; i < transfers.length; i++) {\n if (!_isAccountAllowed(transfers[i].recipient, config)) return false;\n }\n return true;\n }\n}\n" + }, + "project/contracts/Settler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/cryptography/ECDSA.sol';\nimport '@openzeppelin/contracts/utils/cryptography/EIP712.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165Checker.sol';\n\nimport './Intents.sol';\nimport './interfaces/IController.sol';\nimport './interfaces/IIntentsValidator.sol';\nimport './interfaces/IExecutor.sol';\nimport './interfaces/ISettler.sol';\nimport './utils/Denominations.sol';\nimport './utils/ERC20Helpers.sol';\nimport './smart-accounts/SmartAccountsHandler.sol';\nimport './smart-accounts/SmartAccountsHandlerHelpers.sol';\n\n/**\n * @title Settler\n * @dev Contract that provides the appropriate context for solvers to execute proposals that fulfill user intents\n */\ncontract Settler is ISettler, Ownable, ReentrancyGuard, EIP712 {\n using SafeERC20 for IERC20;\n using IntentsHelpers for Intent;\n using IntentsHelpers for Proposal;\n using IntentsHelpers for Validation;\n using SmartAccountsHandlerHelpers for address;\n\n // Mimic controller reference\n // solhint-disable-next-line immutable-vars-naming\n address public immutable override controller;\n\n // Smart accounts handler reference\n address public override smartAccountsHandler;\n\n // Intents validator reference\n address public override intentsValidator;\n\n // List of block numbers at which a user nonce was used\n mapping (address => mapping (bytes32 => uint256)) public override getNonceBlock;\n\n // Safeguard config per user\n mapping (address => bytes) internal _userSafeguard;\n\n /**\n * @dev Modifier to tag settler functions in order to check if the sender is an allowed solver\n */\n modifier onlySolver() {\n address sender = _msgSender();\n if (!IController(controller).isSolverAllowed(sender)) revert SettlerSolverNotAllowed(sender);\n _;\n }\n\n /**\n * @dev Creates a new Settler contract\n * @param _controller Address of the Settler controller\n * @param _owner Address that will own the contract\n */\n constructor(address _controller, address _owner) Ownable(_owner) EIP712('Mimic Protocol Settler', '1') {\n controller = _controller;\n smartAccountsHandler = address(new SmartAccountsHandler());\n }\n\n /**\n * @dev Tells the hash of an intent\n * @param intent Intent to get the hash of\n */\n function getIntentHash(Intent memory intent) external pure override returns (bytes32) {\n return intent.hash();\n }\n\n /**\n * @dev Tells the hash of a proposal\n * @param proposal Proposal to be hashed\n * @param intent Intent being fulfilled by the requested proposal\n * @param solver Address of the solver that made the proposal\n */\n function getProposalHash(Proposal memory proposal, Intent memory intent, address solver)\n external\n pure\n override\n returns (bytes32)\n {\n return proposal.hash(intent, solver);\n }\n\n /**\n * @dev Tells the safeguard set for a user\n * @param user Address of the user being queried\n */\n function getUserSafeguard(address user) external view override returns (bytes memory) {\n return _userSafeguard[user];\n }\n\n /**\n * @dev It allows receiving native token transfers\n * Note: This method mainly allows supporting native tokens for swaps\n */\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n /**\n * @dev Withdraws ERC20 or native tokens from the contract\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function rescueFunds(address token, address recipient, uint256 amount) external override onlyOwner nonReentrant {\n if (recipient == address(0)) revert SettlerRescueFundsRecipientZero();\n ERC20Helpers.transfer(token, recipient, amount);\n emit FundsRescued(token, recipient, amount);\n }\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function setSmartAccountsHandler(address newSmartAccountsHandler) external override onlyOwner {\n _setSmartAccountsHandler(newSmartAccountsHandler);\n }\n\n /**\n * @dev Sets a new intents validator address\n * @param newIntentsValidator New intents validator to be set\n */\n function setIntentsValidator(address newIntentsValidator) external override onlyOwner {\n _setIntentsValidator(newIntentsValidator);\n }\n\n /**\n * @dev Sets a safeguard for a user\n * @param safeguard Safeguard to be set\n */\n function setSafeguard(bytes memory safeguard) external override {\n _setSafeguard(msg.sender, safeguard);\n }\n\n /**\n * @dev Executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function execute(Execution[] memory executions) external override onlySolver {\n _execute(executions, false);\n }\n\n /**\n * @dev Simulates an execution. It will always revert. Successful executions are returned as\n * `SettlerSimulationSuccess` errors. Any other error should be treated as failure.\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n */\n function simulate(Execution[] memory executions) external override onlySolver {\n uint256 initialGas = gasleft();\n _execute(executions, true);\n uint256 gasUsed = initialGas - gasleft();\n revert SettlerSimulationSuccess(gasUsed);\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill an intent\n * @param executions List of executions, each including the intent, proposal, and proposal signature\n * @param simulated Whether the execution is a simulation\n */\n function _execute(Execution[] memory executions, bool simulated) internal nonReentrant {\n for (uint256 i = 0; i < executions.length; i++) {\n Intent memory intent = executions[i].intent;\n Proposal memory proposal = executions[i].proposal;\n bytes memory signature = executions[i].signature;\n\n _validateIntent(intent, proposal, signature, simulated);\n getNonceBlock[intent.user][intent.nonce] = block.number;\n\n if (intent.op == uint8(OpType.Swap)) _executeSwap(intent, proposal);\n else if (intent.op == uint8(OpType.Transfer)) _executeTransfer(intent, proposal);\n else if (intent.op == uint8(OpType.Call)) _executeCall(intent, proposal);\n else revert SettlerUnknownIntentType(uint8(intent.op));\n\n emit ProposalExecuted(proposal.hash(intent, _msgSender()), i);\n }\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a swap intent\n * @param intent Swap intent to be fulfilled\n * @param proposal Swap proposal to be executed\n */\n function _executeSwap(Intent memory intent, Proposal memory proposal) internal {\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n _validateSwapIntent(swapIntent, swapProposal);\n\n bool isSmartAccount = smartAccountsHandler.isSmartAccount(intent.user);\n if (swapIntent.sourceChain == block.chainid) {\n for (uint256 i = 0; i < swapIntent.tokensIn.length; i++) {\n TokenIn memory tokenIn = swapIntent.tokensIn[i];\n _transferFrom(tokenIn.token, intent.user, swapProposal.executor, tokenIn.amount, isSmartAccount);\n }\n }\n\n uint256[] memory preBalancesOut = _getTokensOutBalance(swapIntent);\n IExecutor(swapProposal.executor).execute(intent, proposal);\n\n if (swapIntent.destinationChain == block.chainid) {\n uint256[] memory outputs = new uint256[](swapIntent.tokensOut.length);\n for (uint256 i = 0; i < swapIntent.tokensOut.length; i++) {\n TokenOut memory tokenOut = swapIntent.tokensOut[i];\n uint256 postBalanceOut = ERC20Helpers.balanceOf(tokenOut.token, address(this));\n uint256 preBalanceOut = preBalancesOut[i];\n if (postBalanceOut < preBalanceOut) revert SettlerPostBalanceOutLtPre(i, postBalanceOut, preBalanceOut);\n\n outputs[i] = postBalanceOut - preBalanceOut;\n uint256 proposedAmount = swapProposal.amountsOut[i];\n if (outputs[i] < proposedAmount) revert SettlerAmountOutLtProposed(i, outputs[i], proposedAmount);\n\n ERC20Helpers.transfer(tokenOut.token, tokenOut.recipient, outputs[i]);\n }\n\n _emitIntentEvents(intent, proposal, abi.encode(outputs));\n _payFees(intent, proposal, isSmartAccount);\n }\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a transfer intent\n * @param intent Transfer intent to be fulfilled\n * @param proposal Transfer proposal to be executed\n */\n function _executeTransfer(Intent memory intent, Proposal memory proposal) internal {\n TransferIntent memory transferIntent = abi.decode(intent.data, (TransferIntent));\n _validateTransferIntent(transferIntent, proposal);\n\n bool isSmartAccount = smartAccountsHandler.isSmartAccount(intent.user);\n for (uint256 i = 0; i < transferIntent.transfers.length; i++) {\n TransferData memory transfer = transferIntent.transfers[i];\n _transferFrom(transfer.token, intent.user, transfer.recipient, transfer.amount, isSmartAccount);\n }\n\n _emitIntentEvents(intent, proposal, new bytes(0));\n _payFees(intent, proposal, isSmartAccount);\n }\n\n /**\n * @dev Validates and executes a proposal to fulfill a call intent\n * @param intent Call intent to be fulfilled\n * @param proposal Call proposal to be executed\n */\n function _executeCall(Intent memory intent, Proposal memory proposal) internal {\n CallIntent memory callIntent = abi.decode(intent.data, (CallIntent));\n _validateCallIntent(callIntent, proposal, intent.user);\n\n bytes[] memory outputs = new bytes[](callIntent.calls.length);\n for (uint256 i = 0; i < callIntent.calls.length; i++) {\n CallData memory call = callIntent.calls[i];\n // solhint-disable-next-line avoid-low-level-calls\n outputs[i] = smartAccountsHandler.call(intent.user, call.target, call.data, call.value);\n }\n\n _emitIntentEvents(intent, proposal, abi.encode(outputs));\n _payFees(intent, proposal, true);\n }\n\n /**\n * @dev Validates an intent and its corresponding proposal\n * @param intent Intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param signature Proposal signature\n * @param simulated Whether the execution is a simulation\n */\n function _validateIntent(Intent memory intent, Proposal memory proposal, bytes memory signature, bool simulated)\n internal\n view\n {\n if (intent.settler != address(this)) revert SettlerInvalidSettler(intent.settler);\n if (intent.nonce == bytes32(0)) revert SettlerNonceZero();\n if (getNonceBlock[intent.user][intent.nonce] != 0) revert SettlerNonceAlreadyUsed(intent.user, intent.nonce);\n\n if (intentsValidator != address(0)) {\n bytes memory safeguard = _userSafeguard[intent.user];\n if (safeguard.length > 0) IIntentsValidator(intentsValidator).validate(intent, safeguard);\n }\n\n bool shouldValidateDeadlines = _shouldValidateDeadlines(intent);\n if (shouldValidateDeadlines) {\n if (intent.deadline <= block.timestamp) revert SettlerIntentPastDeadline(intent.deadline, block.timestamp);\n bool isProposalPastDeadline = proposal.deadline <= block.timestamp;\n if (isProposalPastDeadline) revert SettlerProposalPastDeadline(proposal.deadline, block.timestamp);\n }\n\n if (intent.maxFees.length != proposal.fees.length) revert SettlerSolverFeeInvalidLength();\n for (uint256 i = 0; i < intent.maxFees.length; i++) {\n uint256 maxFee = intent.maxFees[i].amount;\n uint256 proposalFee = proposal.fees[i];\n if (proposalFee > maxFee) revert SettlerSolverFeeTooHigh(proposalFee, maxFee);\n }\n\n uint8 minValidations = IController(controller).minValidations();\n uint256 requiredValidations = intent.minValidations > minValidations ? intent.minValidations : minValidations;\n\n if (intent.validations.length < requiredValidations) {\n revert SettlerIntentValidationsNotEnough(requiredValidations, intent.validations.length);\n }\n\n address lastValidator = address(0);\n Validation memory validation = Validation(intent.hash());\n bytes32 typedDataHash = _hashTypedDataV4(validation.hash());\n for (uint256 i = 0; i < intent.validations.length; i++) {\n address validator = ECDSA.recover(typedDataHash, intent.validations[i]);\n if (validator <= lastValidator) {\n revert SettlerValidatorDuplicatedOrUnsorted(lastValidator, validator);\n }\n lastValidator = validator;\n bool isValidatorNotAllowed = !IController(controller).isValidatorAllowed(validator);\n if (isValidatorNotAllowed) revert SettlerValidatorNotAllowed(validator);\n }\n\n address signer = ECDSA.recover(_hashTypedDataV4(proposal.hash(intent, _msgSender())), signature);\n bool isProposalSignerNotAllowed = !IController(controller).isProposalSignerAllowed(signer) && !simulated;\n if (isProposalSignerNotAllowed) revert SettlerProposalSignerNotAllowed(signer);\n }\n\n /**\n * @dev Validates a swap intent and its corresponding proposal\n * @param intent Swap intent to be fulfilled\n * @param proposal Proposal to be executed\n */\n function _validateSwapIntent(SwapIntent memory intent, SwapProposal memory proposal) internal view {\n bool isChainInvalid = intent.sourceChain != block.chainid && intent.destinationChain != block.chainid;\n if (isChainInvalid) revert SettlerInvalidChain(block.chainid);\n\n if (proposal.amountsOut.length != intent.tokensOut.length) revert SettlerInvalidProposedAmounts();\n\n for (uint256 i = 0; i < intent.tokensOut.length; i++) {\n TokenOut memory tokenOut = intent.tokensOut[i];\n address recipient = tokenOut.recipient;\n if (recipient == address(this)) revert SettlerInvalidRecipient(recipient);\n\n uint256 minAmount = tokenOut.minAmount;\n uint256 proposedAmount = proposal.amountsOut[i];\n if (proposedAmount < minAmount) revert SettlerProposedAmountLtMinAmount(i, proposedAmount, minAmount);\n }\n\n if (intent.sourceChain != intent.destinationChain) {\n bool isExecutorInvalid = !IController(controller).isExecutorAllowed(proposal.executor);\n if (isExecutorInvalid) revert SettlerExecutorNotAllowed(proposal.executor);\n }\n }\n\n /**\n * @dev Validates a transfer intent and its corresponding proposal\n * @param intent Transfer intent to be fulfilled\n * @param proposal Proposal to be executed\n */\n function _validateTransferIntent(TransferIntent memory intent, Proposal memory proposal) internal view {\n if (intent.chainId != block.chainid) revert SettlerInvalidChain(block.chainid);\n if (proposal.data.length > 0) revert SettlerProposalDataNotEmpty();\n for (uint256 i = 0; i < intent.transfers.length; i++) {\n address recipient = intent.transfers[i].recipient;\n if (recipient == address(this)) revert SettlerInvalidRecipient(recipient);\n }\n }\n\n /**\n * @dev Validates a call intent and its corresponding proposal\n * @param intent Call intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param user The originator of the intent\n */\n function _validateCallIntent(CallIntent memory intent, Proposal memory proposal, address user) internal view {\n if (intent.chainId != block.chainid) revert SettlerInvalidChain(block.chainid);\n if (proposal.data.length > 0) revert SettlerProposalDataNotEmpty();\n if (!smartAccountsHandler.isSmartAccount(user)) revert SettlerUserNotSmartAccount(user);\n }\n\n /**\n * @dev Tells the contract balance for each token out of a swap intent\n * @param intent Swap intent containing the list of tokens out\n */\n function _getTokensOutBalance(SwapIntent memory intent) internal view returns (uint256[] memory balances) {\n balances = new uint256[](intent.tokensOut.length);\n if (intent.destinationChain == block.chainid) {\n for (uint256 i = 0; i < intent.tokensOut.length; i++) {\n balances[i] = ERC20Helpers.balanceOf(intent.tokensOut[i].token, address(this));\n }\n }\n }\n\n /**\n * @dev Tells if the intent and proposal deadlines should be validated\n * @param intent Intent to be fulfilled\n */\n function _shouldValidateDeadlines(Intent memory intent) internal view returns (bool) {\n if (intent.op != uint8(OpType.Swap)) return true;\n SwapIntent memory swapIntent = abi.decode(intent.data, (SwapIntent));\n if (swapIntent.sourceChain == swapIntent.destinationChain) return true;\n return swapIntent.sourceChain == block.chainid;\n }\n\n /**\n * @dev Emits intent custom events\n * @param intent Intent to emit the custom events for\n * @param proposal Proposal that fulfills the intent\n * @param output Encoded array of outputs\n */\n function _emitIntentEvents(Intent memory intent, Proposal memory proposal, bytes memory output) internal {\n for (uint256 i = 0; i < intent.events.length; i++) {\n IntentEvent memory intentEvent = intent.events[i];\n emit IntentExecuted(\n intent.user,\n intentEvent.topic,\n uint8(intent.op),\n intent,\n proposal,\n output,\n intentEvent.data\n );\n }\n }\n\n /**\n * @dev Pays fees\n * @param intent Intent to be fulfilled\n * @param proposal Proposal to be executed\n * @param isSmartAccount Whether the intent user is a smart account\n */\n function _payFees(Intent memory intent, Proposal memory proposal, bool isSmartAccount) internal {\n address from = intent.user;\n address to = _msgSender();\n for (uint256 i = 0; i < intent.maxFees.length; i++) {\n address token = intent.maxFees[i].token;\n if (!Denominations.isUSD(token)) _transferFrom(token, from, to, proposal.fees[i], isSmartAccount);\n }\n }\n\n /**\n * @dev Transfers tokens from one account to another\n * @param token Address of the token to transfer\n * @param from Address of the account sending the tokens\n * @param to Address of the account receiving the tokens\n * @param amount Amount of tokens to transfer\n * @param isSmartAccount Whether the sender is a smart account\n */\n function _transferFrom(address token, address from, address to, uint256 amount, bool isSmartAccount) internal {\n if (isSmartAccount) {\n smartAccountsHandler.transfer(from, token, to, amount);\n } else {\n IERC20(token).safeTransferFrom(from, to, amount);\n }\n }\n\n /**\n * @dev Sets a new smart accounts handler\n * @param newSmartAccountsHandler New smart accounts handler to be set\n */\n function _setSmartAccountsHandler(address newSmartAccountsHandler) internal {\n if (newSmartAccountsHandler == address(0)) revert SmartAccountsHandlerZero();\n smartAccountsHandler = newSmartAccountsHandler;\n emit SmartAccountsHandlerSet(newSmartAccountsHandler);\n }\n\n /**\n * @dev Sets the intents validator\n * @param newIntentsValidator New intents validator to be set\n */\n function _setIntentsValidator(address newIntentsValidator) internal {\n intentsValidator = newIntentsValidator;\n emit IntentsValidatorSet(newIntentsValidator);\n }\n\n /**\n * @dev Sets a safeguard for a user\n * @param user Address of the user to set the safeguard for\n * @param safeguard Safeguard to be set\n */\n function _setSafeguard(address user, bytes memory safeguard) internal {\n delete _userSafeguard[user];\n _userSafeguard[user] = safeguard;\n emit SafeguardSet(user);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccount7702.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/Context.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccount.sol';\nimport '../utils/ERC20Helpers.sol';\nimport './SmartAccountBase.sol';\n\n/**\n * @title SmartAccount7702\n * @dev Provides the smart account logic to use with EIP7702\n */\ncontract SmartAccount7702 is SmartAccountBase {\n // Mimic settler reference\n // solhint-disable-next-line immutable-vars-naming\n address public immutable settler;\n\n /**\n * @dev The sender is not the settler\n */\n error SmartAccount7702SenderNotSettler();\n\n /**\n * @dev Reverts unless the sender is the settler\n */\n modifier onlySettler() {\n if (_msgSender() != settler) revert SmartAccount7702SenderNotSettler();\n _;\n }\n\n /**\n * @dev Creates a new SmartAccount7702 contract\n * @param _settler Address of the Mimic settler\n */\n constructor(address _settler) {\n settler = _settler;\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) public override onlySettler {\n super.transfer(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value) public override onlySettler returns (bytes memory) {\n // solhint-disable-next-line avoid-low-level-calls\n return super.call(target, data, value);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountBase.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/Context.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccount.sol';\nimport '../utils/ERC20Helpers.sol';\n\n/**\n * @title SmartAccountBase\n * @dev Provides the base logic for managing assets and executing arbitrary calls\n */\ncontract SmartAccountBase is ISmartAccount, Context, ERC165, ReentrancyGuard {\n /**\n * @dev Tells whether the contract supports the given interface ID. Overrides ERC165 to declare support for ISmartAccount interface.\n * @param interfaceId Interface ID is defined as the XOR of all function selectors in the interface\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {\n return interfaceId == type(ISmartAccount).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount) public virtual override nonReentrant {\n ERC20Helpers.transfer(token, recipient, amount);\n emit Transferred(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value)\n public\n virtual\n override\n nonReentrant\n returns (bytes memory result)\n {\n result = Address.functionCallWithValue(target, data, value);\n emit Called(target, data, value, result);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountContract.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\nimport '@openzeppelin/contracts/utils/ReentrancyGuard.sol';\nimport '@openzeppelin/contracts/utils/cryptography/ECDSA.sol';\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport '../interfaces/ISmartAccountContract.sol';\nimport './SmartAccountBase.sol';\n\n/**\n * @title SmartAccountContract\n * @dev Provides the smart account logic to use as a standalone contract\n */\ncontract SmartAccountContract is ISmartAccountContract, Ownable, SmartAccountBase {\n // EIP1271 magic return value\n bytes4 internal constant EIP1271_MAGIC_VALUE = 0x1626ba7e;\n\n // EIP1271 invalid signature return value\n bytes4 internal constant EIP1271_INVALID_SIGNATURE = 0xffffffff;\n\n // List of account permissions\n mapping (address => bool) public isSignerAllowed;\n\n // Mimic settler reference\n address public settler;\n\n /**\n * @dev The settler is zero\n */\n error SmartAccountSettlerZero();\n\n /**\n * @dev The input arrays are not of equal length\n */\n error SmartAccountInputInvalidLength();\n\n /**\n * @dev The sender is not the owner or the settler\n */\n error SmartAccountUnauthorizedSender(address sender);\n\n /**\n * @dev Emitted every time the settler is set\n */\n event SettlerSet(address indexed settler);\n\n /**\n * @dev Emitted every time a signer allowance is set\n */\n event SignerAllowedSet(address indexed account, bool allowed);\n\n /**\n * @dev Reverts unless the sender is the owner or the settler\n */\n modifier onlyOwnerOrSettler() {\n address sender = _msgSender();\n bool isAuthorized = sender == owner() || sender == settler;\n if (!isAuthorized) revert SmartAccountUnauthorizedSender(sender);\n _;\n }\n\n /**\n * @dev Creates a new SmartAccount contract\n * @param _settler Address of the Mimic settler\n * @param _owner Address that will own the contract\n */\n constructor(address _settler, address _owner) Ownable(_owner) {\n _setSettler(_settler);\n }\n\n /**\n * @dev Tells whether the signature provided belongs to an allowed account.\n * @param hash Message signed by the account\n * @param signature Signature provided to be verified\n */\n function isValidSignature(bytes32 hash, bytes memory signature) external view override returns (bytes4) {\n (address signer, , ) = ECDSA.tryRecover(hash, signature);\n if (signer != address(0) && (signer == owner() || isSignerAllowed[signer])) return EIP1271_MAGIC_VALUE;\n return EIP1271_INVALID_SIGNATURE;\n }\n\n /**\n * @dev It allows receiving native token transfers\n */\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n /**\n * @dev Sets the settler. Sender must be the owner.\n * @param newSettler Address of the new settler to be set\n */\n function setSettler(address newSettler) external onlyOwner {\n _setSettler(newSettler);\n }\n\n /**\n * @dev Sets a list of allowed signers. Sender must be the owner.\n * @param accounts List of account addresses\n * @param allowances List of allowed condition per account\n */\n function setAllowedSigners(address[] memory accounts, bool[] memory allowances) external onlyOwner {\n if (accounts.length != allowances.length) revert SmartAccountInputInvalidLength();\n for (uint256 i = 0; i < accounts.length; i++) {\n address account = accounts[i];\n bool allowed = allowances[i];\n isSignerAllowed[account] = allowed;\n emit SignerAllowedSet(account, allowed);\n }\n }\n\n /**\n * @dev Transfers ERC20 or native tokens to the recipient. Sender must be the owner or the settler.\n * @param token Address of the token to be withdrawn\n * @param recipient Address of the account receiving the tokens\n * @param amount Amount of tokens to be withdrawn\n */\n function transfer(address token, address recipient, uint256 amount)\n public\n override(ISmartAccount, SmartAccountBase)\n onlyOwnerOrSettler\n {\n super.transfer(token, recipient, amount);\n }\n\n /**\n * @dev Executes an arbitrary call from the contract. Sender must be the owner or the settler.\n * @param target Address where the call will be sent\n * @param data Calldata to be sent to the target\n * @param value Native token value to send along with the call\n * @return result Call response if it was successful, otherwise it reverts\n */\n function call(address target, bytes memory data, uint256 value)\n public\n override(ISmartAccount, SmartAccountBase)\n onlyOwnerOrSettler\n returns (bytes memory)\n {\n // solhint-disable-next-line avoid-low-level-calls\n return super.call(target, data, value);\n }\n\n /**\n * @dev Sets the settler\n * @param newSettler Address of the new settler to be set\n */\n function _setSettler(address newSettler) internal {\n if (newSettler == address(0)) revert SmartAccountSettlerZero();\n settler = newSettler;\n emit SettlerSet(newSettler);\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountsHandler.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport '../interfaces/ISafe.sol';\nimport '../interfaces/ISmartAccount.sol';\nimport '../interfaces/ISmartAccountsHandler.sol';\nimport '../utils/Denominations.sol';\n\ncontract SmartAccountsHandler is ISmartAccountsHandler {\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address account) external view override returns (bool) {\n if (account.code.length == 0) return false;\n if (_isMimicSmartAccount(account)) return true;\n if (_isSafe(account)) return true;\n return false;\n }\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address account, address token, address to, uint256 amount) external override {\n if (_isMimicSmartAccount(account)) return ISmartAccount(account).transfer(token, to, amount);\n if (_isSafe(account)) return _transferSafe(account, token, to, amount);\n revert SmartAccountsHandlerUnsupportedAccount(account);\n }\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address account, address target, bytes memory data, uint256 value)\n external\n override\n returns (bytes memory)\n {\n // solhint-disable-next-line avoid-low-level-calls\n if (_isMimicSmartAccount(account)) return ISmartAccount(account).call(target, data, value);\n if (_isSafe(account)) return _callSafe(account, target, data, value);\n revert SmartAccountsHandlerUnsupportedAccount(account);\n }\n\n /**\n * @dev Performs a transfer from a safe\n */\n function _transferSafe(address account, address token, address to, uint256 amount) internal {\n Denominations.isNativeToken(token)\n ? _callSafe(account, to, new bytes(0), amount)\n : _callSafe(account, token, abi.encodeWithSelector(IERC20.transfer.selector, to, amount), 0);\n }\n\n /**\n * @dev Performs a call from a safe\n */\n function _callSafe(address account, address target, bytes memory data, uint256 value)\n internal\n returns (bytes memory)\n {\n (bool success, bytes memory result) = ISafe(account).execTransactionFromModuleReturnData(\n target,\n value,\n data,\n SafeOperation.Call\n );\n return\n data.length == 0\n ? Address.verifyCallResult(success, result)\n : Address.verifyCallResultFromTarget(target, success, result);\n }\n\n /**\n * @dev Tells whether an account is a Mimic smart account\n * @param account Address of the account being queried\n */\n function _isMimicSmartAccount(address account) internal view returns (bool) {\n try ISmartAccount(account).supportsInterface(type(ISmartAccount).interfaceId) returns (bool ok) {\n return ok;\n } catch {\n return false;\n }\n }\n\n /**\n * @dev Tells whether an account is a Gnosis Safe\n * @param account Address of the account being queried\n */\n function _isSafe(address account) internal view returns (bool) {\n try ISafe(account).getThreshold() returns (uint256) {\n return true;\n } catch {\n return false;\n }\n }\n}\n" + }, + "project/contracts/smart-accounts/SmartAccountsHandlerHelpers.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport '../interfaces/ISmartAccountsHandler.sol';\n\nlibrary SmartAccountsHandlerHelpers {\n /**\n * @dev Tells whether an account is a supported smart account\n * @param account Address of the account being queried\n */\n function isSmartAccount(address handler, address account) internal view returns (bool) {\n return ISmartAccountsHandler(handler).isSmartAccount(account);\n }\n\n /**\n * @dev Performs a transfer from a smart account\n */\n function transfer(address handler, address account, address token, address to, uint256 amount) internal {\n Address.functionDelegateCall(\n handler,\n abi.encodeWithSelector(ISmartAccountsHandler.transfer.selector, account, token, to, amount)\n );\n }\n\n /**\n * @dev Performs a call from a smart account\n */\n function call(address handler, address account, address target, bytes memory data, uint256 value)\n internal\n returns (bytes memory)\n {\n return\n Address.functionDelegateCall(\n handler,\n abi.encodeWithSelector(ISmartAccountsHandler.call.selector, account, target, data, value)\n );\n }\n}\n" + }, + "project/contracts/test/CallMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\ncontract CallMock {\n event CallReceived(address indexed sender, uint256 value);\n error CallError();\n\n function call() external payable {\n emit CallReceived(msg.sender, msg.value);\n }\n\n function callError() external payable {\n revert CallError();\n }\n}\n" + }, + "project/contracts/test/executors/EmptyExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\n\ncontract EmptyExecutorMock is IExecutor {\n event Executed();\n\n function execute(Intent memory, Proposal memory) external override {\n emit Executed();\n }\n}\n" + }, + "project/contracts/test/executors/MintExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../TokenMock.sol';\nimport '../../interfaces/IExecutor.sol';\n\n/* solhint-disable custom-errors */\n\ncontract MintExecutorMock is IExecutor {\n event Minted();\n\n function execute(Intent memory intent, Proposal memory proposal) external override {\n require(intent.op == uint8(OpType.Swap), 'Invalid intent type');\n\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n (address[] memory tokens, uint256[] memory amounts) = abi.decode(swapProposal.data, (address[], uint256[]));\n\n require(tokens.length == amounts.length, 'Invalid inputs');\n\n for (uint256 i = 0; i < tokens.length; i++) {\n TokenMock(tokens[i]).mint(msg.sender, amounts[i]);\n emit Minted();\n }\n }\n}\n" + }, + "project/contracts/test/executors/ReentrantExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\nimport '../../interfaces/ISettler.sol';\n\ncontract ReentrantExecutorMock is IExecutor {\n // solhint-disable-next-line immutable-vars-naming\n address payable public immutable settler;\n\n constructor(address payable _settler) {\n settler = _settler;\n }\n\n function execute(Intent memory, Proposal memory) external override {\n ISettler(settler).execute(new Execution[](0));\n }\n}\n" + }, + "project/contracts/test/executors/TransferExecutorMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/IExecutor.sol';\nimport '../../utils/ERC20Helpers.sol';\n\n/* solhint-disable custom-errors */\n\ncontract TransferExecutorMock is IExecutor {\n event Transferred();\n\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n function execute(Intent memory intent, Proposal memory proposal) external override {\n require(intent.op == uint8(OpType.Swap), 'Invalid intent type');\n\n SwapProposal memory swapProposal = abi.decode(proposal.data, (SwapProposal));\n (address[] memory tokens, uint256[] memory amounts) = abi.decode(swapProposal.data, (address[], uint256[]));\n\n require(tokens.length == amounts.length, 'Invalid inputs');\n\n for (uint256 i = 0; i < tokens.length; i++) {\n ERC20Helpers.transfer(tokens[i], msg.sender, amounts[i]);\n emit Transferred();\n }\n }\n}\n" + }, + "project/contracts/test/smart-accounts/SafeMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '../../interfaces/ISafe.sol';\n\ncontract SafeMock is ISafe {\n event ModuleTxExecuted(\n address indexed target,\n bytes data,\n uint256 value,\n SafeOperation operation,\n bool success,\n bytes result\n );\n\n receive() external payable {}\n\n function getThreshold() external pure returns (uint256) {\n return 1;\n }\n\n function execTransactionFromModuleReturnData(address to, uint256 value, bytes memory data, SafeOperation operation)\n external\n returns (bool success, bytes memory result)\n {\n // solhint-disable-next-line avoid-low-level-calls\n (success, result) = to.call{ value: value }(data);\n emit ModuleTxExecuted(to, data, value, operation, success, result);\n }\n}\n" + }, + "project/contracts/test/TokenMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/ERC20.sol';\n\ncontract TokenMock is ERC20 {\n uint8 internal _decimals;\n\n constructor(string memory symbol, uint8 dec) ERC20(symbol, symbol) {\n _decimals = dec;\n }\n\n function mint(address account, uint256 amount) external {\n _mint(account, amount);\n }\n\n function decimals() public view override returns (uint8) {\n return _decimals;\n }\n}\n" + }, + "project/contracts/test/utils/DenominationsMock.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '../../utils/Denominations.sol';\n\n// solhint-disable func-name-mixedcase\n\ncontract DenominationsMock {\n function NATIVE_TOKEN() external pure returns (address) {\n return Denominations.NATIVE_TOKEN;\n }\n\n function USD() external pure returns (address) {\n return Denominations.USD;\n }\n}\n" + }, + "project/contracts/test/utils/ERC20HelpersMock.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '../../utils/ERC20Helpers.sol';\n\ncontract ERC20HelpersMock {\n receive() external payable {\n // solhint-disable-previous-line no-empty-blocks\n }\n\n function approve(address token, address to, uint256 amount) external {\n ERC20Helpers.approve(token, to, amount);\n }\n\n function transfer(address token, address to, uint256 amount) external {\n ERC20Helpers.transfer(token, to, amount);\n }\n\n function balanceOf(address token, address account) external view returns (uint256) {\n return ERC20Helpers.balanceOf(token, account);\n }\n}\n" + }, + "project/contracts/utils/Denominations.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\n/**\n * @title Denominations\n * @dev Provides a list of ground denominations for those tokens that cannot be represented by an ERC20.\n * For now, the only needed is the native token that could be ETH, MATIC, or other depending on the layer being operated.\n */\nlibrary Denominations {\n address internal constant NATIVE_TOKEN = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;\n\n // Fiat currencies follow https://en.wikipedia.org/wiki/ISO_4217\n address internal constant USD = address(840);\n\n function isUSD(address token) internal pure returns (bool) {\n return token == USD;\n }\n\n function isNativeToken(address token) internal pure returns (bool) {\n return token == NATIVE_TOKEN;\n }\n}\n" + }, + "project/contracts/utils/ERC20Helpers.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';\nimport '@openzeppelin/contracts/utils/Address.sol';\n\nimport './Denominations.sol';\n\n/**\n * @title ERC20Helpers\n * @dev Provides a list of ERC20 helper methods\n */\nlibrary ERC20Helpers {\n function approve(address token, address to, uint256 amount) internal {\n SafeERC20.forceApprove(IERC20(token), to, amount);\n }\n\n function transfer(address token, address to, uint256 amount) internal {\n if (Denominations.isNativeToken(token)) Address.sendValue(payable(to), amount);\n else SafeERC20.safeTransfer(IERC20(token), to, amount);\n }\n\n function balanceOf(address token, address account) internal view returns (uint256) {\n if (Denominations.isNativeToken(token)) return address(account).balance;\n else return IERC20(token).balanceOf(address(account));\n }\n}\n" + }, + "project/contracts/utils/MimicHelper.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\npragma solidity ^0.8.20;\n\n/**\n * @title Mimic Helper\n * @dev Collection of helper functions for the Mimic Protocol\n */\ncontract MimicHelper {\n /**\n * @dev Tells the native token balance of an address\n * @param target Address to get native token balance\n */\n function getNativeTokenBalance(address target) external view returns (uint256) {\n return target.balance;\n }\n}\n" + } + } + } +} \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-84532/deployed_addresses.json b/packages/evm/ignition/deployments/chain-84532/deployed_addresses.json index a1a41be..e981fe5 100644 --- a/packages/evm/ignition/deployments/chain-84532/deployed_addresses.json +++ b/packages/evm/ignition/deployments/chain-84532/deployed_addresses.json @@ -2,5 +2,7 @@ "Create3Controller#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", "Create3Controller#Controller": "0x6002825BabC837776A08799404fA55f15DCedA6b", "Create3Settler#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", - "Create3Settler#Settler": "0x609d831C0068844e11eF85a273c7F356212Fd6D1" + "Create3Settler#Settler": "0x609d831C0068844e11eF85a273c7F356212Fd6D1", + "Create3MimicHelper#ICreateX": "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", + "Create3MimicHelper#MimicHelper": "0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0" } \ No newline at end of file diff --git a/packages/evm/ignition/deployments/chain-84532/journal.jsonl b/packages/evm/ignition/deployments/chain-84532/journal.jsonl index 0c773ee..d91c64d 100644 --- a/packages/evm/ignition/deployments/chain-84532/journal.jsonl +++ b/packages/evm/ignition/deployments/chain-84532/journal.jsonl @@ -17,4 +17,13 @@ {"futureId":"Create3Settler#ICreateX.deployCreate3","hash":"0x347f2a0e4b16a680bf4de17133f67fcd3064187582909a5b3e2a4300af3dad4e","networkInteractionId":1,"receipt":{"blockHash":"0xbc039972be3e02e6ac06c666c4367e94aff81a8beee5cc46eaabfdf735790591","blockNumber":34206254,"logs":[{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":135,"topics":["0x2feea65dd4e9f9cbd86b74b7734210c59a1b2981b5b137bd0ee3e208200c9067","0x0000000000000000000000001a68cee754105b3f806c92f6f59e3175f0b0fc2c","0xd5d101dbdd8374fa4f730d105879acbe6c9855ed7be06a019574ba923a935d7d"]},{"address":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","data":"0x","logIndex":136,"topics":["0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000003a0ce8115b4913f42c4928d6bc3f554e9a81468b"]},{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":137,"topics":["0x4db17dd5e4732fb6da34a148104a592783ca119a1e7bb8829eba6cbadef0b511","0x000000000000000000000000609d831c0068844e11ef85a273c7f356212fd6d1"]}],"status":"SUCCESS"},"type":"TRANSACTION_CONFIRM"} {"futureId":"Create3Settler#ICreateX.deployCreate3","result":{"type":"SUCCESS"},"type":"CALL_EXECUTION_STATE_COMPLETE"} {"artifactId":"Create3Settler#ICreateX","dependencies":["Create3Settler#ICreateX.deployCreate3","Create3Settler#ICreateX"],"emitterAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","eventIndex":0,"eventName":"ContractCreation","futureId":"Create3Settler#ICreateX.ContractCreation.newContract.0","nameOrIndex":"newContract","result":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","strategy":"basic","strategyConfig":{},"txToReadFrom":"0x347f2a0e4b16a680bf4de17133f67fcd3064187582909a5b3e2a4300af3dad4e","type":"READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE"} -{"artifactId":"Create3Settler#Settler","contractAddress":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","contractName":"Settler","dependencies":["Create3Settler#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3Settler#Settler","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} \ No newline at end of file +{"artifactId":"Create3Settler#Settler","contractAddress":"0x609d831C0068844e11eF85a273c7F356212Fd6D1","contractName":"Settler","dependencies":["Create3Settler#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3Settler#Settler","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} +{"artifactId":"Create3MimicHelper#ICreateX","contractAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","contractName":"ICreateX","dependencies":[],"futureId":"Create3MimicHelper#ICreateX","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} +{"args":["0x3a0ce8115b4913f42c4928d6bc3f554e9a81468b000000000000000000000040","0x6080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c0033"],"artifactId":"Create3MimicHelper#ICreateX","contractAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","dependencies":["Create3MimicHelper#ICreateX"],"from":"0x3a0ce8115b4913f42c4928d6bc3f554e9a81468b","functionName":"deployCreate3","futureId":"Create3MimicHelper#ICreateX.deployCreate3","strategy":"basic","strategyConfig":{},"type":"CALL_EXECUTION_STATE_INITIALIZE","value":{"_kind":"bigint","value":"0"}} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteraction":{"data":"0x9c36a2863a0ce8115b4913f42c4928d6bc3f554e9a81468b000000000000000000000040000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e96080604052348015600e575f5ffd5b5060cf80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063effd663c14602a575b5f5ffd5b604f60353660046061565b73ffffffffffffffffffffffffffffffffffffffff163190565b60405190815260200160405180910390f35b5f602082840312156070575f5ffd5b813573ffffffffffffffffffffffffffffffffffffffff811681146092575f5ffd5b939250505056fea2646970667358221220bb1ce2cd0b8d26244d77e180ab4e56bb52690949ec0a30d5c25e3ac02f58774664736f6c634300081c00330000000000000000000000000000000000000000000000","id":1,"to":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","type":"ONCHAIN_INTERACTION","value":{"_kind":"bigint","value":"0"}},"type":"NETWORK_INTERACTION_REQUEST"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteractionId":1,"nonce":3,"type":"TRANSACTION_PREPARE_SEND"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","networkInteractionId":1,"nonce":3,"transaction":{"fees":{"maxFeePerGas":{"_kind":"bigint","value":"1400000"},"maxPriorityFeePerGas":{"_kind":"bigint","value":"1000000"}},"hash":"0xcab15394a7dce4f39c8da40ff030b9033cfb57b2f2f1e84c2454b485fede401e"},"type":"TRANSACTION_SEND"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","hash":"0xcab15394a7dce4f39c8da40ff030b9033cfb57b2f2f1e84c2454b485fede401e","networkInteractionId":1,"receipt":{"blockHash":"0xccc76eaa024ca3e014ad399d94b6b1d77227ae4d7de9e503a35ea6ee14dd3fa3","blockNumber":36842644,"logs":[{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":7,"topics":["0x2feea65dd4e9f9cbd86b74b7734210c59a1b2981b5b137bd0ee3e208200c9067","0x0000000000000000000000009074e2fea6f668ccf7fb884fac62943acc03ea43","0x721f4d59bffa983c2a99dc5a3b93053d035180c65840e4dc318b06bb0484a80f"]},{"address":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","data":"0x","logIndex":8,"topics":["0x4db17dd5e4732fb6da34a148104a592783ca119a1e7bb8829eba6cbadef0b511","0x0000000000000000000000004766ef65d66e8d2d92f3089ee42e5705e8817ff0"]}],"status":"SUCCESS"},"type":"TRANSACTION_CONFIRM"} +{"futureId":"Create3MimicHelper#ICreateX.deployCreate3","result":{"type":"SUCCESS"},"type":"CALL_EXECUTION_STATE_COMPLETE"} +{"artifactId":"Create3MimicHelper#ICreateX","dependencies":["Create3MimicHelper#ICreateX.deployCreate3","Create3MimicHelper#ICreateX"],"emitterAddress":"0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed","eventIndex":0,"eventName":"ContractCreation","futureId":"Create3MimicHelper#ICreateX.ContractCreation.newContract.0","nameOrIndex":"newContract","result":"0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0","strategy":"basic","strategyConfig":{},"txToReadFrom":"0xcab15394a7dce4f39c8da40ff030b9033cfb57b2f2f1e84c2454b485fede401e","type":"READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE"} +{"artifactId":"Create3MimicHelper#MimicHelper","contractAddress":"0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0","contractName":"MimicHelper","dependencies":["Create3MimicHelper#ICreateX.ContractCreation.newContract.0"],"futureId":"Create3MimicHelper#MimicHelper","futureType":"NAMED_ARTIFACT_CONTRACT_AT","strategy":"basic","strategyConfig":{},"type":"CONTRACT_AT_EXECUTION_STATE_INITIALIZE"} \ No newline at end of file diff --git a/packages/evm/scripts/deploy-contracts.ts b/packages/evm/scripts/deploy-contracts.ts index bde34c1..2b411eb 100644 --- a/packages/evm/scripts/deploy-contracts.ts +++ b/packages/evm/scripts/deploy-contracts.ts @@ -4,7 +4,7 @@ import hre, { network } from 'hardhat' import type { Artifact } from 'hardhat/types/artifacts' import ControllerArtifact from '../artifacts/contracts/Controller.sol/Controller.json' -import MimicHelperArtifact from '../artifacts/contracts/MimicHelper.sol/MimicHelper.json' +import MimicHelperArtifact from '../artifacts/contracts/utils/MimicHelper.sol/MimicHelper.json' import SettlerArtifact from '../artifacts/contracts/Settler.sol/Settler.json' import SmartAccount7702 from '../artifacts/contracts/smart-accounts/SmartAccount7702.sol/SmartAccount7702.json' import buildCreate3Module from '../ignition/modules/Create3' @@ -12,17 +12,17 @@ import buildCreate3Module from '../ignition/modules/Create3' const MIN_VALIDATORS = 1 async function main(): Promise { - if (!process.env.AXIA) throw Error('AXIA env variable not provided') - if (!process.env.ADMIN) throw Error('ADMIN env variable not provided') - if (!process.env.SOLVER) throw Error('SOLVER env variable not provided') - if (!process.env.VALIDATOR) throw Error('VALIDATOR env variable not provided') - const { ADMIN, SOLVER, AXIA, VALIDATOR } = process.env - - const controllerArgs = [ADMIN, [SOLVER], [], [AXIA], [VALIDATOR], MIN_VALIDATORS] - const controller = await deployCreate3(ControllerArtifact, controllerArgs, '0x17') - const settler = await deployCreate3(SettlerArtifact, [controller.target, ADMIN], '0x18') - await deployCreate3(SmartAccount7702, [settler.target], '0x19') - await deployCreate3(MimicHelperArtifact, [], '0x20') + // if (!process.env.AXIA) throw Error('AXIA env variable not provided') + // if (!process.env.ADMIN) throw Error('ADMIN env variable not provided') + // if (!process.env.SOLVER) throw Error('SOLVER env variable not provided') + // if (!process.env.VALIDATOR) throw Error('VALIDATOR env variable not provided') + // const { ADMIN, SOLVER, AXIA, VALIDATOR } = process.env + + // const controllerArgs = [ADMIN, [SOLVER], [], [AXIA], [VALIDATOR], MIN_VALIDATORS] + // const controller = await deployCreate3(ControllerArtifact, controllerArgs, '0x17') + // const settler = await deployCreate3(SettlerArtifact, [controller.target, ADMIN], '0x18') + // await deployCreate3(SmartAccount7702, [settler.target], '0x19') + await deployCreate3(MimicHelperArtifact, [], '0x40') } // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -30,7 +30,6 @@ async function deployCreate3(artifact: Artifact, args: any[], saltSuffix: string const { ethers, ignition } = await network.connect() const [signer] = await ethers.getSigners() const salt = buildProtectedSalt(signer.address, saltSuffix) - const { contractName, abi, bytecode } = artifact const encodedArgs = new Interface(abi).encodeDeploy(args) const initCode = bytecode + encodedArgs.slice(2) From 7da9f8f921abc5c1c7fb98612166fb4eec27100c Mon Sep 17 00:00:00 2001 From: Agustincito Date: Mon, 26 Jan 2026 16:00:59 -0300 Subject: [PATCH 6/6] Fix deploy contracts script --- packages/evm/scripts/deploy-contracts.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/evm/scripts/deploy-contracts.ts b/packages/evm/scripts/deploy-contracts.ts index 2b411eb..56500ea 100644 --- a/packages/evm/scripts/deploy-contracts.ts +++ b/packages/evm/scripts/deploy-contracts.ts @@ -4,24 +4,24 @@ import hre, { network } from 'hardhat' import type { Artifact } from 'hardhat/types/artifacts' import ControllerArtifact from '../artifacts/contracts/Controller.sol/Controller.json' -import MimicHelperArtifact from '../artifacts/contracts/utils/MimicHelper.sol/MimicHelper.json' import SettlerArtifact from '../artifacts/contracts/Settler.sol/Settler.json' import SmartAccount7702 from '../artifacts/contracts/smart-accounts/SmartAccount7702.sol/SmartAccount7702.json' +import MimicHelperArtifact from '../artifacts/contracts/utils/MimicHelper.sol/MimicHelper.json' import buildCreate3Module from '../ignition/modules/Create3' const MIN_VALIDATORS = 1 async function main(): Promise { - // if (!process.env.AXIA) throw Error('AXIA env variable not provided') - // if (!process.env.ADMIN) throw Error('ADMIN env variable not provided') - // if (!process.env.SOLVER) throw Error('SOLVER env variable not provided') - // if (!process.env.VALIDATOR) throw Error('VALIDATOR env variable not provided') - // const { ADMIN, SOLVER, AXIA, VALIDATOR } = process.env - - // const controllerArgs = [ADMIN, [SOLVER], [], [AXIA], [VALIDATOR], MIN_VALIDATORS] - // const controller = await deployCreate3(ControllerArtifact, controllerArgs, '0x17') - // const settler = await deployCreate3(SettlerArtifact, [controller.target, ADMIN], '0x18') - // await deployCreate3(SmartAccount7702, [settler.target], '0x19') + if (!process.env.AXIA) throw Error('AXIA env variable not provided') + if (!process.env.ADMIN) throw Error('ADMIN env variable not provided') + if (!process.env.SOLVER) throw Error('SOLVER env variable not provided') + if (!process.env.VALIDATOR) throw Error('VALIDATOR env variable not provided') + const { ADMIN, SOLVER, AXIA, VALIDATOR } = process.env + + const controllerArgs = [ADMIN, [SOLVER], [], [AXIA], [VALIDATOR], MIN_VALIDATORS] + const controller = await deployCreate3(ControllerArtifact, controllerArgs, '0x17') + const settler = await deployCreate3(SettlerArtifact, [controller.target, ADMIN], '0x18') + await deployCreate3(SmartAccount7702, [settler.target], '0x19') await deployCreate3(MimicHelperArtifact, [], '0x40') }