diff --git a/.gitmodules b/.gitmodules index a01ded3b35..888d42dcd9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "lib/forge-std"] path = lib/forge-std url = https://github.com/foundry-rs/forge-std -[submodule "cairo_contracts"] - path = packages/starknet-contracts/lib/cairo_contracts - url = https://github.com/OpenZeppelin/cairo-contracts diff --git a/LICENSE b/LICENSE index c40232aa16..1035c91979 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ Superfluid Protocol -Copyright @ 2020-2023 Superfluid Finance Ltd +Copyright @ 2020-2025 Superfluid Finance Ltd This is the monorepo of Superfluid Protocol. @@ -10,8 +10,9 @@ Notably: - packages/spec-haskell - MIT - packages/solidity-semantic-money - MIT -- packages/ethereum-contracts - AGPLv3 (core contracts) & MIT (for external developers) -- packages/subgraph - AGPLv3 +- packages/ethereum-contracts - MIT +- packages/metadata - MIT +- packages/subgraph - MIT - packages/automation-contracts/* - MIT - packages/js-sdk - MIT - packages/sdk-core - MIT diff --git a/packages/automation-contracts/autowrap/LICENSE b/packages/automation-contracts/autowrap/LICENSE deleted file mode 100644 index aa13c7d0e1..0000000000 --- a/packages/automation-contracts/autowrap/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright © 2020-2023 Superfluid Finance Ltd - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/automation-contracts/autowrap/MIT-LICENSE b/packages/automation-contracts/autowrap/MIT-LICENSE new file mode 100644 index 0000000000..fa4009bd75 --- /dev/null +++ b/packages/automation-contracts/autowrap/MIT-LICENSE @@ -0,0 +1,25 @@ +The MIT License (MIT) +===================== + +Copyright © 2025 Superfluid Finance LTD. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/automation-contracts/scheduler/LICENSE b/packages/automation-contracts/scheduler/LICENSE deleted file mode 100644 index aa13c7d0e1..0000000000 --- a/packages/automation-contracts/scheduler/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright © 2020-2023 Superfluid Finance Ltd - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/automation-contracts/scheduler/MIT-LICENSE b/packages/automation-contracts/scheduler/MIT-LICENSE new file mode 100644 index 0000000000..fa4009bd75 --- /dev/null +++ b/packages/automation-contracts/scheduler/MIT-LICENSE @@ -0,0 +1,25 @@ +The MIT License (MIT) +===================== + +Copyright © 2025 Superfluid Finance LTD. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/ethereum-contracts/LICENSE b/packages/ethereum-contracts/LICENSE deleted file mode 100644 index 52feb626b0..0000000000 --- a/packages/ethereum-contracts/LICENSE +++ /dev/null @@ -1,45 +0,0 @@ -This file contains two licenses (AGPLv3 and MIT, each source file of this -package shall state its license type explicitly. - --------------------------------------------------------------------------------- - -Superfluid Protocol Core Contracts - -Copyright @ 2020-2023 Superfluid Finance Ltd - -This program is free software: you can redistribute it and/or modify it under -the terms of the GNU Affero General Public License as published by the Free -Software Foundation, either version 3 of the License, or (at your option) any -later version. - -This program is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License along -with this program. If not, see . - --------------------------------------------------------------------------------- - -Superfluid Protocol Development Interfaces - -MIT License - -Copyright © 2020-2023 Superfluid Finance Ltd - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/ethereum-contracts/MIT-LICENSE b/packages/ethereum-contracts/MIT-LICENSE new file mode 100644 index 0000000000..fa4009bd75 --- /dev/null +++ b/packages/ethereum-contracts/MIT-LICENSE @@ -0,0 +1,25 @@ +The MIT License (MIT) +===================== + +Copyright © 2025 Superfluid Finance LTD. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/hot-fuzz/LICENSE b/packages/hot-fuzz/LICENSE deleted file mode 100644 index aa13c7d0e1..0000000000 --- a/packages/hot-fuzz/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright © 2020-2023 Superfluid Finance Ltd - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/hot-fuzz/MIT-LICENSE b/packages/hot-fuzz/MIT-LICENSE new file mode 100644 index 0000000000..fa4009bd75 --- /dev/null +++ b/packages/hot-fuzz/MIT-LICENSE @@ -0,0 +1,25 @@ +The MIT License (MIT) +===================== + +Copyright © 2025 Superfluid Finance LTD. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/js-sdk/LICENSE b/packages/js-sdk/LICENSE deleted file mode 100644 index aa13c7d0e1..0000000000 --- a/packages/js-sdk/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright © 2020-2023 Superfluid Finance Ltd - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/js-sdk/MIT-LICENSE b/packages/js-sdk/MIT-LICENSE new file mode 100644 index 0000000000..fa4009bd75 --- /dev/null +++ b/packages/js-sdk/MIT-LICENSE @@ -0,0 +1,25 @@ +The MIT License (MIT) +===================== + +Copyright © 2025 Superfluid Finance LTD. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/metadata/LICENSE b/packages/metadata/LICENSE deleted file mode 100644 index aa13c7d0e1..0000000000 --- a/packages/metadata/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright © 2020-2023 Superfluid Finance Ltd - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/metadata/MIT-LICENSE b/packages/metadata/MIT-LICENSE new file mode 100644 index 0000000000..fa4009bd75 --- /dev/null +++ b/packages/metadata/MIT-LICENSE @@ -0,0 +1,25 @@ +The MIT License (MIT) +===================== + +Copyright © 2025 Superfluid Finance LTD. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/sdk-core/LICENSE b/packages/sdk-core/LICENSE deleted file mode 100644 index aa13c7d0e1..0000000000 --- a/packages/sdk-core/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright © 2020-2023 Superfluid Finance Ltd - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/sdk-core/MIT-LICENSE b/packages/sdk-core/MIT-LICENSE new file mode 100644 index 0000000000..fa4009bd75 --- /dev/null +++ b/packages/sdk-core/MIT-LICENSE @@ -0,0 +1,25 @@ +The MIT License (MIT) +===================== + +Copyright © 2025 Superfluid Finance LTD. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/sdk-redux/LICENSE b/packages/sdk-redux/LICENSE deleted file mode 100644 index aa13c7d0e1..0000000000 --- a/packages/sdk-redux/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright © 2020-2023 Superfluid Finance Ltd - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/sdk-redux/MIT-LICENSE b/packages/sdk-redux/MIT-LICENSE new file mode 100644 index 0000000000..fa4009bd75 --- /dev/null +++ b/packages/sdk-redux/MIT-LICENSE @@ -0,0 +1,25 @@ +The MIT License (MIT) +===================== + +Copyright © 2025 Superfluid Finance LTD. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/solidity-semantic-money/LICENSE b/packages/solidity-semantic-money/LICENSE deleted file mode 100644 index aa13c7d0e1..0000000000 --- a/packages/solidity-semantic-money/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright © 2020-2023 Superfluid Finance Ltd - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/solidity-semantic-money/MIT-LICENSE b/packages/solidity-semantic-money/MIT-LICENSE new file mode 100644 index 0000000000..fa4009bd75 --- /dev/null +++ b/packages/solidity-semantic-money/MIT-LICENSE @@ -0,0 +1,25 @@ +The MIT License (MIT) +===================== + +Copyright © 2025 Superfluid Finance LTD. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/spec-haskell/LICENSE b/packages/spec-haskell/LICENSE deleted file mode 100644 index aa13c7d0e1..0000000000 --- a/packages/spec-haskell/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright © 2020-2023 Superfluid Finance Ltd - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/spec-haskell/MIT-LICENSE b/packages/spec-haskell/MIT-LICENSE new file mode 100644 index 0000000000..fa4009bd75 --- /dev/null +++ b/packages/spec-haskell/MIT-LICENSE @@ -0,0 +1,25 @@ +The MIT License (MIT) +===================== + +Copyright © 2025 Superfluid Finance LTD. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/starknet-contracts/.gitignore b/packages/starknet-contracts/.gitignore deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/packages/starknet-contracts/README.md b/packages/starknet-contracts/README.md deleted file mode 100644 index 65eebd2586..0000000000 --- a/packages/starknet-contracts/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Setup Guide - -## Installations - -- Set up StarkNet DevNet using this [guide](https://0xspaceshard.github.io/starknet-devnet/docs/intro) -- Set up protostar using this [guide](https://docs.swmansion.com/protostar/docs/legacy/installation) - -## Usage - -- Build - `protostar build-cairo0` -- Test - `protostar test-cairo0` - -## Demo - -- [Live Dapp](https://starknet-superfluidv2-demo.vercel.app/) -- [Contract](https://testnet.starkscan.co/contract/0x0517ce183b644b9f7484c498c7e9071542c724f999b9d815e1f9e5cc4c8617aa#read-write-contract) -- [Faucet](https://faucet.goerli.starknet.io/) - -## Deployment and Interaction (Local Environment) - -In StarkNet, contracts are declared before deployment. Contract declarations returns a class hash(`CLASS_HASH`) which will be used for the deployment - -- Declare Contract - `protostar -p devnet declare-cairo0 ./build/.json --account-address ACCOUNT_ADDRESS --max-fee FEE --private-key-path ./.pkey` - -- Deploy - `protostar -p devnet deploy CLASS_HASH --account-address ACCOUNT_ADDRESS --max-fee FEE --private-key-path ./.pkey` - -- `pkey` is a file containing the private key associated with `ACCOUNT_ADDRESS` gotten from the starknet devnet running starknet - -- Use this [guide](https://docs.swmansion.com/protostar/docs/legacy/interacting-with-starknet) for steps on invoking and calling contracts with protostar diff --git a/packages/starknet-contracts/lib/cairo_contracts b/packages/starknet-contracts/lib/cairo_contracts deleted file mode 160000 index 331844dcf2..0000000000 --- a/packages/starknet-contracts/lib/cairo_contracts +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 331844dcf278ccdf96ce3b63fb3e5f2c78970561 diff --git a/packages/starknet-contracts/protostar.toml b/packages/starknet-contracts/protostar.toml deleted file mode 100644 index f70a9abc37..0000000000 --- a/packages/starknet-contracts/protostar.toml +++ /dev/null @@ -1,14 +0,0 @@ -[project] -protostar-version = "0.13.0" -lib-path = "lib" -cairo-path = ["lib/cairo_contracts/src"] - -[contracts] -SuperToken = ["src/tokens/ERC20x/SuperToken/SuperTokenImpl.cairo"] -Pool = ["src/pools/PoolImpl.cairo"] -Aqueduct = ["src/examples/aqueduct/AqueductImpl.cairo"] -TestAccount = ["src/utils/account/TestAccountImpl.cairo"] - -[profile.devnet.project] -gateway-url = "http://127.0.0.1:5050/" -chain-id = 1536727068981429685321 diff --git a/packages/starknet-contracts/src/examples/aqueduct/AqueductImpl.cairo b/packages/starknet-contracts/src/examples/aqueduct/AqueductImpl.cairo deleted file mode 100644 index 3b478b38cf..0000000000 --- a/packages/starknet-contracts/src/examples/aqueduct/AqueductImpl.cairo +++ /dev/null @@ -1,42 +0,0 @@ -%lang starknet - -from starkware.cairo.common.cairo_builtins import HashBuiltin - -from src.examples.aqueduct.library import Aqueduct - -@constructor -func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - tokenL: felt, tokenR: felt -) { - Aqueduct.initializer(tokenL, tokenR); - return (); -} - -@view -func token1{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> ( - token: felt -) { - return Aqueduct.token1(); -} - -@view -func token2{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> ( - token: felt -) { - return Aqueduct.token2(); -} - -@view -func pool1{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (pool: felt) { - return Aqueduct.pool1(); -} - -@view -func pool2{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (pool: felt) { - return Aqueduct.pool2(); -} - -@external -func onFlowUpdate{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(token: felt, _from: felt, ir0: felt, ir1: felt) { - return Aqueduct.onFlowUpdate(token, _from, ir0, ir1); -} \ No newline at end of file diff --git a/packages/starknet-contracts/src/examples/aqueduct/library.cairo b/packages/starknet-contracts/src/examples/aqueduct/library.cairo deleted file mode 100644 index 1adc28e75f..0000000000 --- a/packages/starknet-contracts/src/examples/aqueduct/library.cairo +++ /dev/null @@ -1,136 +0,0 @@ -%lang starknet - -from starkware.cairo.common.cairo_builtins import HashBuiltin -from starkware.cairo.common.math import unsigned_div_rem -from starkware.cairo.common.bool import TRUE, FALSE - -from src.interfaces.ISuperfluidToken import ISuperfluidToken -from src.interfaces.ISuperfluidPool import ISuperfluidPool - -namespace AqueductLibrary { - struct SideState { - totalInFlowRate: felt, - } - - func clone{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(a: SideState) -> ( - b: SideState - ) { - let sideState = SideState(a.totalInFlowRate); - return (b=sideState); - } - - func update_side{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - a: SideState, curUnitsB: felt, r0: felt, r1: felt - ) -> (b: SideState, newDistFlowRateA: felt, newUnitsB: felt) { - let newTotalFlowRate = a.totalInFlowRate + r1 - r0; - let b = SideState(newTotalFlowRate); - let newDistFlowRateA = newTotalFlowRate; - // TODO: Review the usefulness of this - let newUnitsB = curUnitsB + r1 - r0; - return (b=b, newDistFlowRateA=newDistFlowRateA, newUnitsB=newUnitsB); - } - - func cal_new_flowrate_A{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - totalA: felt, totalB: felt, oldFlowRateB: felt, newFlowRateB: felt - ) -> (newFlowRateA: felt) { - let (newFlowRateA, _) = unsigned_div_rem(totalA * newFlowRateB, ((totalB + newFlowRateB) - oldFlowRateB)); - return (newFlowRateA=newFlowRateA); - } - - func cal_new_flowrate_B{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - totalA: felt, totalB: felt, oldFlowRateA: felt, newFlowRateA: felt - ) -> (newFlowRateB: felt) { - let (newFlowRateB, _) = unsigned_div_rem(totalB * newFlowRateA, (totalA + newFlowRateA) - oldFlowRateA); - return (newFlowRateB=newFlowRateB); - } -} - -struct Side { - superToken: felt, - superTokenPool: felt, - state: AqueductLibrary.SideState, -} - -@storage_var -func _left() -> (res: Side) { -} - -@storage_var -func _right() -> (res: Side) { -} - -namespace Aqueduct { - - const SWAP_DISTRIBUTE_FLOW_ID = 0; - const ADJUSTMENT_FLOW_ID = 0; - - func initializer{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - tokenL: felt, tokenR: felt - ) { - let (pool) = ISuperfluidToken.createPool(contract_address=tokenL); - let (left) = _left.read(); - let newLeft = Side(tokenL, pool, left.state); - _left.write(newLeft); - - - let (pool) = ISuperfluidToken.createPool(contract_address=tokenR); - let (right) = _right.read(); - let newRight= Side(tokenR, pool, right.state); - _right.write(newRight); - return (); - } - - func token1{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> ( - token: felt - ) { - let (left) = _left.read(); - return (token=left.superToken); - } - - func token2{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> ( - token: felt - ) { - let (right) = _right.read(); - return (token=right.superToken); - } - - func pool1{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (pool: felt) { - let (left) = _left.read(); - return (pool=left.superTokenPool); - } - - func pool2{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (pool: felt) { - let (right) = _right.read(); - return (pool=right.superTokenPool); - } - - func onFlowUpdate{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(token: felt, _from: felt, ir0: felt, ir1: felt) { - let (left) = _left.read(); - let (right) = _right.read(); - if(token == left.superToken){ - _onFlowUpdate(left, right, _from, ir0, ir1, TRUE); - } else { - if(token == right.superToken){ - _onFlowUpdate(right, left, _from, ir0, ir1, FALSE); - } else { - return (); - } - } - return (); - } - - func _onFlowUpdate{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(a: Side, b: Side, _from: felt, ir0: felt, ir1: felt, update_left: felt) { - alloc_locals; - // Update units based on new flowrate - let (curUnitsB) = ISuperfluidPool.getUnits(contract_address=b.superTokenPool, memberAddress=_from); - let (newSideStateB, _, unit) = AqueductLibrary.update_side(b.state, curUnitsB, ir0, ir1); - let newSide = Side(b.superToken, b.superTokenPool, newSideStateB); - if (update_left == TRUE){ - _left.write(newSide); - } else { - _right.write(newSide); - } - ISuperfluidPool.updateMember(contract_address=b.superTokenPool, memberAddress=_from, unit=unit); - return (); - } -} diff --git a/packages/starknet-contracts/src/interfaces/IAqueduct.cairo b/packages/starknet-contracts/src/interfaces/IAqueduct.cairo deleted file mode 100644 index a4a3211af1..0000000000 --- a/packages/starknet-contracts/src/interfaces/IAqueduct.cairo +++ /dev/null @@ -1,8 +0,0 @@ -%lang starknet - - -@contract_interface -namespace IAqueduct { - func onFlowUpdate(token: felt, _from: felt, ir0: felt, ir1: felt){ - } -} diff --git a/packages/starknet-contracts/src/interfaces/ISuperfluidPool.cairo b/packages/starknet-contracts/src/interfaces/ISuperfluidPool.cairo deleted file mode 100644 index 2ba48fa7fb..0000000000 --- a/packages/starknet-contracts/src/interfaces/ISuperfluidPool.cairo +++ /dev/null @@ -1,82 +0,0 @@ -%lang starknet - -from src.utils.SemanticMoney import PDPoolIndex, PDPoolMember, BasicParticle - -/////////////////////////////////////////////////////////// -////// The interface for any super token pool regardless of the distribution schemes. -/////////////////////////////////////////////////////////// - -@contract_interface -namespace ISuperfluidPool { - func admin() -> (address: felt) { - } - - func getIndex() -> (index: PDPoolIndex) { - } - - func getTotalUnits() -> (value: felt) { - } - - func getDisconnectedUnits() -> (unit: felt) { - } - - func getUnits(memberAddress: felt) -> (value: felt) { - } - - func getDistributionFlowRate() -> (flow_rate: felt) { - } - - func getConnectedFlowRate() -> (flow_rate: felt) { - } - - func getDisconnectedFlowRate() -> (flow_rate: felt) { - } - - func getDisconnectedBalance(time: felt) -> (value: felt) { - } - - func getMemberFlowRate(memberAddress: felt) -> (flow_rate: felt) { - } - - func getClaimable(time: felt, memberAddress: felt) -> (value: felt) { - } - - func updateMember(memberAddress: felt, unit: felt) -> (success: felt) { - } - - func claimAll() -> (success: felt) { - } - - func operatorSetIndex(index: PDPoolIndex) -> (success: felt) { - } - - // WARNING for operators: it is undefined behavior if member is already connected or disconnected - func operatorConnectMember(memberAddress: felt, dbConnect: felt) -> (success: felt) { - } - - func getMember(memberAddress: felt) -> (member_data: PDPoolMember) { - } -} - - /////////////////////////////////////////////////////////// - ////// The interface for the operator of a super token pool - /////////////////////////////////////////////////////////// - -@contract_interface -namespace ISuperfluidPoolOperator { - /// Check if an address is connected to the pool - func isMemberConnected(pool: felt, memberAddress: felt) -> (success: felt) { - } - - /// Get pool adjustment flow information: (recipient, flowHahs, flowRate) - func getPoolAdjustmentFlowInfo(pool: felt) -> (address: felt, flow_hash: felt, flow_rate: felt) { - } - - /// Update the adjustment flow rate - func appendIndexUpdateByPool(particle: BasicParticle, time: felt) -> (success: felt) { - } - - /// Settle the claim - func poolSettleClaim(claimRecipient: felt, amount: felt) -> (success: felt) { - } -} diff --git a/packages/starknet-contracts/src/interfaces/ISuperfluidToken.cairo b/packages/starknet-contracts/src/interfaces/ISuperfluidToken.cairo deleted file mode 100644 index cba0547ff9..0000000000 --- a/packages/starknet-contracts/src/interfaces/ISuperfluidToken.cairo +++ /dev/null @@ -1,118 +0,0 @@ -%lang starknet - -from src.utils.SemanticMoney import BasicParticle - -@contract_interface -namespace ISuperfluidToken { - func name() -> (name: felt) { - } - - func symbol() -> (symbol: felt) { - } - - func decimals() -> (decimals: felt) { - } - - func totalSupply() -> (totalSupply: felt) { - } - - func balanceOf(account: felt) -> (balance: felt) { - } - - func allowance(owner: felt, spender: felt) -> (remaining: felt) { - } - - func transfer(to: felt, amount: felt) -> (success: felt) { - } - - func transferFrom(_from: felt, to: felt, amount: felt) -> (success: felt) { - } - - func mint(receiver: felt, amount: felt) { - } - - func approve(spender: felt, amount: felt) -> (success: felt) { - } - - // ////////////////////////////////////////////////////////////////////////////// - // Generalized Payment Primitives - // ////////////////////////////////////////////////////////////////////////////// - - func realtimeBalanceNow(account: felt) -> (rtb: felt) { - } - - func realtimeBalanceAt(account: felt, time: felt) -> (rtb: felt) { - } - - func realtimeBalanceVectorNow(account: felt) -> (own: felt, fromPool: felt, deposit: felt) { - } - - func realtimeBalanceVectorAt(account: felt, time: felt) -> (own: felt, fromPool: felt, deposit: felt) { - } - - func getNetFlowRate(account: felt) -> (flow_rate: felt) { - } - - func getFlowRate(_from: felt, to: felt, flowId: felt) -> (flow_rate: felt) { - } - - func shift(senderAddress: felt, receiverAddress: felt, amount: felt) -> (success: felt) { - } - - func flow(senderAddress: felt, receiverAddress: felt, flowId: felt, flowRate: felt) -> ( - success: felt - ) { - } - - func distribute(senderAddress: felt, poolAddress: felt, reqAmount: felt) -> ( - success: felt, actualAmount: felt - ) { - } - - func distributeFlow( - senderAddress: felt, poolAddress: felt, flowId: felt, reqFlowRate: felt - ) -> (success: felt, actualFlowRate: felt, newDistributionFlowRate: felt) { - } - - // ////////////////////////////////////////////////////////////////////////////// - // Pool Operations - // ////////////////////////////////////////////////////////////////////////////// - - func isPool(address: felt) -> (success: felt) { - } - - func connectPool(to: felt) -> (success: felt) { - } - - func disconnectPool(to: felt) -> (success: felt) { - } - - func connectPoolEnum(to: felt, connect: felt) -> (success: felt) { - } - - // ////////////////////////////////////////////////////////////////////////////// - // Pool Owner Operations - // ////////////////////////////////////////////////////////////////////////////// - - func createPool() -> (pool: felt) { - } - - func getNumConnections(account: felt) -> (value: felt) { - } - - /// Check if an address is connected to the pool - func isMemberConnected(pool: felt, memberAddress: felt) -> (success: felt) { - } - - /// Get pool adjustment flow information: (recipient, flowHash, flowRate) - func getPoolAdjustmentFlowInfo(pool: felt) -> (adjustmentRecipient: felt, flowHash: felt, flowRate: felt) { - } - - /// Update the adjustment flow rate - func appendIndexUpdateByPool(particle: BasicParticle, time: felt) -> (success: felt) { - } - - /// Settle the claim - func poolSettleClaim(claimRecipient: felt, amount: felt) -> (success: felt) { - } -} diff --git a/packages/starknet-contracts/src/pools/PoolImpl.cairo b/packages/starknet-contracts/src/pools/PoolImpl.cairo deleted file mode 100644 index 899613cda7..0000000000 --- a/packages/starknet-contracts/src/pools/PoolImpl.cairo +++ /dev/null @@ -1,109 +0,0 @@ -%lang starknet - -from starkware.cairo.common.cairo_builtins import HashBuiltin -from starkware.starknet.common.syscalls import get_block_timestamp, get_caller_address - -from src.pools.library import Pool, PDPoolIndex, PDPoolMember - -@constructor -func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(admin: felt) { - Pool.initializer(admin); - return (); -} - -@view -func admin{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (address: felt) { - return Pool.admin(); -} - -@view -func getIndex{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> ( - index: PDPoolIndex -) { - return Pool.getIndex(); -} - -@view -func getTotalUnits{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> ( - value: felt -) { - return Pool.getTotalUnits(); -} - -@view -func getDisconnectedUnits{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (unit: felt) { - return Pool.getDisconnectedUnits(); -} - -@view -func getUnits{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - memberAddress: felt -) -> (value: felt) { - return Pool.getUnits(memberAddress); -} - -@view -func getDistributionFlowRate{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> ( - flow_rate: felt -) { - return Pool.getDistributionFlowRate(); -} - -@view -func getConnectedFlowRate{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (flowRate: felt) { - return Pool.getConnectedFlowRate(); -} - -@view -func getDisconnectedFlowRate{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (flowRate: felt) { - return Pool.getDisconnectedFlowRate(); -} - -@view -func getDisconnectedBalance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(time: felt) -> (value: felt) { - return Pool.getDisconnectedBalance(time); -} - -@view -func getMemberFlowRate{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - memberAddress: felt -) -> (flow_rate: felt) { - return Pool.getMemberFlowRate(memberAddress); -} - -@view -func getClaimable{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - time: felt, memberAddress: felt -) -> (value: felt) { - return Pool.getClaimable(time, memberAddress); -} - -@external -func updateMember{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - member: felt, unit: felt -) -> (success: felt) { - return Pool.updateMember(member, unit); -} - -@external -func claimAll{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> ( - success: felt -) { - let (caller) = get_caller_address(); - return Pool.claimAll(caller); -} - -@external -func operatorSetIndex{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - index: PDPoolIndex -) -> (success: felt) { - return Pool.operatorSetIndex(index); -} - -@external -func operatorConnectMember{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - memberAddress: felt, dbConnect: felt -) -> (success: felt) { - let (timestamp) = get_block_timestamp(); - return Pool.operatorConnectMember(timestamp, memberAddress, dbConnect); -} diff --git a/packages/starknet-contracts/src/pools/library.cairo b/packages/starknet-contracts/src/pools/library.cairo deleted file mode 100644 index bf8a47b13b..0000000000 --- a/packages/starknet-contracts/src/pools/library.cairo +++ /dev/null @@ -1,282 +0,0 @@ -%lang starknet - -from starkware.cairo.common.cairo_builtins import HashBuiltin -from starkware.starknet.common.syscalls import ( - get_caller_address, - get_block_timestamp, - get_contract_address, -) -from starkware.cairo.common.math import assert_nn, assert_not_zero -from starkware.cairo.common.bool import TRUE, FALSE -from starkware.cairo.common.alloc import alloc - -from openzeppelin.access.ownable.library import Ownable - -from src.utils.SemanticMoney import ( - PDPoolIndex, - PDPoolMember, - PDPoolMemberMU, - SemanticMoney, - BasicParticle, -) -from src.interfaces.ISuperfluidPool import ISuperfluidPoolOperator - -@storage_var -func Pool_POOL_OPERATOR() -> (address: felt) { -} - -@storage_var -func Pool_admin() -> (address: felt) { -} - -@storage_var -func Pool_index() -> (index: PDPoolIndex) { -} - -@storage_var -func Pool_members(member: felt) -> (member_data: PDPoolMember) { -} - -@storage_var -func Pool_claimed_values(member: felt) -> (value: felt) { -} - -@storage_var -func Pool_disconnectedMembers() -> (pdMember: PDPoolMember) { -} - -@storage_var -func Pool_claimedByDisconnectedMembers() -> (value: felt) { -} - -namespace Pool { - // - // Initializer - // - func initializer{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(admin: felt) { - let (caller) = get_caller_address(); - Pool_POOL_OPERATOR.write(caller); - Pool_admin.write(admin); - return (); - } - - func admin{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (address: felt) { - return Pool_admin.read(); - } - - func getIndex{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> ( - index: PDPoolIndex - ) { - return Pool_index.read(); - } - - func getTotalUnits{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> ( - value: felt - ) { - let (index) = Pool_index.read(); - return (value=index.total_units); - } - - func getDisconnectedUnits{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> ( - unit: felt - ) { - let (pdMember) = Pool_disconnectedMembers.read(); - return (unit=pdMember.owned_unit); - } - - func getUnits{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - memberAddress: felt - ) -> (value: felt) { - let (member_data) = Pool_members.read(memberAddress); - return (value=member_data.owned_unit); - } - - func getDistributionFlowRate{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - ) -> (flow_rate: felt) { - let (index) = Pool_index.read(); - let (flow_rate) = SemanticMoney.flow_rate_for_pool_index(index); - return (flow_rate=flow_rate); - } - - func getConnectedFlowRate{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (flowRate: felt) { - let (index) = Pool_index.read(); - let (flowRate) = SemanticMoney.flow_rate_for_pool_index(index); - return (flowRate=flowRate); - } - - func getDisconnectedFlowRate{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - ) -> (flowRate: felt) { - let (index) = Pool_index.read(); - let (flowRate) = SemanticMoney.flow_rate_per_unit(index); - let (disconnectedPDMember) = Pool_disconnectedMembers.read(); - return (flowRate=flowRate * disconnectedPDMember.owned_unit); - } - - func getDisconnectedBalance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(time: felt) -> (value: felt) { - let (disconnectedPDMember) = Pool_disconnectedMembers.read(); - let (index) = Pool_index.read(); - let pdMemberMu = PDPoolMemberMU(index, disconnectedPDMember); - let (balance) = SemanticMoney.realtime_balance_of_pool_member_mu(pdMemberMu, time); - let (claimedByDisconnectedMembers) = Pool_claimedByDisconnectedMembers.read(); - return (value = balance - claimedByDisconnectedMembers); - } - - func getMemberFlowRate{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - memberAddress: felt - ) -> (flow_rate: felt) { - let (member_data) = Pool_members.read(memberAddress); - if (member_data.owned_unit == 0) { - return (flow_rate=0); - } else { - let (index) = Pool_index.read(); - let (flow_rate) = SemanticMoney.flow_rate_per_unit(index); - return (flow_rate=flow_rate * member_data.owned_unit); - } - } - - func getClaimable{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - time: felt, memberAddress: felt - ) -> (value: felt) { - let (index) = Pool_index.read(); - let (member_data) = Pool_members.read(memberAddress); - let pdMemberMu = PDPoolMemberMU(index, member_data); - let (realtime_balance) = SemanticMoney.realtime_balance_of_pool_member_mu( - pdMemberMu, time - ); - let (claimed_value) = Pool_claimed_values.read(memberAddress); - let claimable = realtime_balance - claimed_value; - return (value=claimable); - } - - func updateMember{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - member: felt, unit: felt - ) -> (success: felt) { - alloc_locals; - with_attr error_message("Pool: negative unit not allowed") { - assert_nn(unit); - } - let (caller) = get_caller_address(); - let (admin) = Pool_admin.read(); - with_attr error_message("Pool: not the admin!") { - assert caller = admin; - } - let (contract_address) = get_contract_address(); - let (pool_operator) = Pool_POOL_OPERATOR.read(); - let (connected) = ISuperfluidPoolOperator.isMemberConnected( - contract_address=pool_operator, pool=contract_address, memberAddress=member - ); - let (index) = Pool_index.read(); - let (pdMember) = Pool_members.read(member); - let (time) = get_block_timestamp(); - - let pd_member_mu = PDPoolMemberMU(index, pdMember); - let empty_particle = BasicParticle(0, 0, 0); - - if (connected == FALSE) { - // trigger the side effect of claiming all if not connected - let (claimed_amount) = _claimAll(time, member); - // update pool's disconnected units - _shiftDisconnectedUnits(unit - pdMember.owned_unit, claimed_amount, time); - - let (index, pdMember, p) = SemanticMoney.pool_member_update(pd_member_mu, empty_particle, unit, time); - Pool_index.write(index); - Pool_members.write(member, pdMember); - let (success) = ISuperfluidPoolOperator.appendIndexUpdateByPool(contract_address=pool_operator, particle=p, time=time); - } else { - let (index, pdMember, p) = SemanticMoney.pool_member_update(pd_member_mu, empty_particle, unit, time); - Pool_index.write(index); - Pool_members.write(member, pdMember); - let (success) = ISuperfluidPoolOperator.appendIndexUpdateByPool(contract_address=pool_operator, particle=p, time=time); - } - return (success=TRUE); - } - - func claimAll{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(memberAddress: felt) -> ( - success: felt - ) { - alloc_locals; - let (pool_operator) = Pool_POOL_OPERATOR.read(); - let (contract_address) = get_contract_address(); - let (connected) = ISuperfluidPoolOperator.isMemberConnected( - contract_address=pool_operator, pool=contract_address, memberAddress=memberAddress - ); - let (time) = get_block_timestamp(); - let (claimed_amount) = _claimAll(time, memberAddress); - if (connected == FALSE) { - _shiftDisconnectedUnits(0, claimed_amount, time); - return (success=TRUE); - } else { - return (success=TRUE); - } - } - - func _claimAll{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - time: felt, memberAddress: felt - ) -> (value: felt) { - alloc_locals; - let (value) = getClaimable(time, memberAddress); - let (pool_operator) = Pool_POOL_OPERATOR.read(); - - let (success) = ISuperfluidPoolOperator.poolSettleClaim(contract_address=pool_operator, claimRecipient=memberAddress, amount=value); - assert success = TRUE; - - let (initialClaimedValue) = Pool_claimed_values.read(memberAddress); - Pool_claimed_values.write(memberAddress, value + initialClaimedValue); - - return (value = value); - } - - func operatorSetIndex{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - index: PDPoolIndex - ) -> (success: felt) { - let (caller) = get_caller_address(); - let (pool_operator) = Pool_POOL_OPERATOR.read(); - with_attr error_message("Pool: caller is not pool admin") { - assert pool_operator = caller; - } - Pool_index.write(index); - return (success=TRUE); - } - - func operatorConnectMember{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - time: felt, memberAddress: felt, dbConnect: felt - ) -> (success: felt) { - alloc_locals; - let (caller) = get_caller_address(); - let (pool_operator) = Pool_POOL_OPERATOR.read(); - with_attr error_message("Pool: caller is not pool operator") { - assert pool_operator = caller; - } - - // NB! This is an assumption that isConnected = !doConnect, - // and it should be respected by the operator. - - // trigger the side effects of claiming all - let (claimed_amount) = _claimAll(time, memberAddress); - let (pdMember) = Pool_members.read(memberAddress); - let (time) = get_block_timestamp(); - if (dbConnect == TRUE) { - // previous disconnected, now to be connected - // => removing from the disconnected distribution group - _shiftDisconnectedUnits(-pdMember.owned_unit, claimed_amount, time); - } else { - // previous connected, now to be disconnected - // => adding to disconnected distribution group - _shiftDisconnectedUnits(pdMember.owned_unit, 0, time); - } - return (success=TRUE); - } - - func _shiftDisconnectedUnits{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(shift_units: felt, claimed_amount: felt, time: felt){ - let (index) = Pool_index.read(); - let (disconnectedPDMembers) = Pool_disconnectedMembers.read(); - let pdMemberMu = PDPoolMemberMU(index, disconnectedPDMembers); - let (settledPoolMemberMu) = SemanticMoney.settle_for_pool_member_mu(pdMemberMu, time); - let new_disconnectedMembers = PDPoolMember(settledPoolMemberMu.pdPoolMember.owned_unit + shift_units, settledPoolMemberMu.pdPoolMember._settled_value, settledPoolMemberMu.pdPoolMember._synced_particle); - Pool_disconnectedMembers.write(new_disconnectedMembers); - let (claimedByDisconnectedMembers) = Pool_claimedByDisconnectedMembers.read(); - Pool_claimedByDisconnectedMembers.write(claimedByDisconnectedMembers + claimed_amount); - return (); - } - -} diff --git a/packages/starknet-contracts/src/tokens/ERC20x/SuperToken/SuperTokenImpl.cairo b/packages/starknet-contracts/src/tokens/ERC20x/SuperToken/SuperTokenImpl.cairo deleted file mode 100644 index abe0c66d82..0000000000 --- a/packages/starknet-contracts/src/tokens/ERC20x/SuperToken/SuperTokenImpl.cairo +++ /dev/null @@ -1,199 +0,0 @@ -%lang starknet - -from starkware.starknet.common.syscalls import get_caller_address, get_block_timestamp -from starkware.cairo.common.cairo_builtins import HashBuiltin -from starkware.cairo.common.uint256 import Uint256 -from starkware.cairo.common.bool import TRUE - -from openzeppelin.access.ownable.library import Ownable - -from src.tokens.ERC20x.SuperToken.library import SuperToken, BasicParticle - -@constructor -func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - name: felt, symbol: felt, decimals: felt, pool_class_hash: felt -) { - let (caller) = get_caller_address(); - SuperToken.initializer(name, symbol, decimals, pool_class_hash); - return (); -} - -// -// Getters -// - -@view -func name{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (name: felt) { - return SuperToken.name(); -} - -@view -func symbol{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (symbol: felt) { - return SuperToken.symbol(); -} - -@view -func totalSupply{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> ( - totalSupply: felt -) { - return SuperToken.totalSupply(); -} - -@view -func decimals{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> ( - decimals: felt -) { - return SuperToken.decimals(); -} - -@view -func balanceOf{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(account: felt) -> ( - balance: felt -) { - return SuperToken.balanceOf(account); -} - -@view -func realtimeBalanceNow{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - account: felt -) -> (rtb: felt) { - let (timestamp) = get_block_timestamp(); - return SuperToken.realtimeBalanceAt(account, timestamp); -} - -@view -func realtimeBalanceAt{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - account: felt, time: felt -) -> (rtb: felt) { - return SuperToken.realtimeBalanceAt(account, time); -} - -@view -func realtimeBalanceVectorNow{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - account: felt -) -> (own: felt, fromPool: felt, deposit: felt) { - let (timestamp) = get_block_timestamp(); - return SuperToken.realtimeBalanceVectorAt(account, timestamp); -} - -@view -func realtimeBalanceVectorAt{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - account: felt, time: felt -) -> (own: felt, fromPool: felt, deposit: felt) { - return SuperToken.realtimeBalanceVectorAt(account, time); -} - -@view -func getNetFlowRate{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - account: felt -) -> (flowRate: felt) { - return SuperToken.getNetFlowRate(account); -} - -@view -func getFlowRate{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - _from: felt, to: felt, flowId: felt -) -> (flowRate: felt) { - return SuperToken.getFlowRate(_from, to, flowId); -} - -@external -func transfer{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(to: felt, amount: felt) -> (success: felt) { - alloc_locals; - return SuperToken.transfer(to, amount); -} - -@external -func transferFrom{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(_from: felt, to: felt, amount: felt) -> (success: felt) { - alloc_locals; - return SuperToken.transferFrom(_from, to, amount); -} - -@external -func shift{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - sender: felt, recipient: felt, amount: felt -) -> (success: felt) { - return SuperToken.shift(sender, recipient, amount); -} - -@external -func flow{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - sender: felt, recipient: felt, flowId: felt, flowRate: felt -) -> (success: felt) { - return SuperToken.flow(sender, recipient, flowId, flowRate); -} - -@external -func distribute{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - sender: felt, poolAddress: felt, reqAmount: felt -) -> (success: felt, actualAmount: felt) { - return SuperToken.distribute(sender, poolAddress, reqAmount); -} - -@external -func distributeFlow{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - sender: felt, pool: felt, flowId: felt, reqFlowRate: felt -) -> (success: felt, actualFlowRate: felt, newDistributionFlowRate: felt) { - return SuperToken.distributeFlow(sender, pool, flowId, reqFlowRate); -} - -@external -func connectPool{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(to: felt) -> ( - success: felt -) { - return SuperToken.connectPool(to); -} - -@external -func disconnectPool{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(to: felt) -> ( - success: felt -) { - return SuperToken.disconnectPool(to); -} - -@external -func createPool{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (pool: felt) { - return SuperToken.createPool(); -} - -@view -func isMemberConnected{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - pool: felt, memberAddress: felt -) -> (success: felt) { - return SuperToken.isMemberConnected(pool, memberAddress); -} - -@view -func getPoolAdjustmentFlowInfo{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(pool: felt) -> (adjustmentRecipient: felt, flowHash: felt, flowRate: felt){ - return SuperToken.getPoolAdjustmentFlowInfo(pool); -} - -@external -func appendIndexUpdateByPool{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(particle: BasicParticle, time: felt) -> (success: felt) { - SuperToken.appendIndexUpdateByPool(particle, time); - return (success=TRUE); -} - -@external -func poolSettleClaim{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(claimRecipient: felt, amount: felt) -> (success: felt){ - SuperToken.poolSettleClaim(claimRecipient, amount); - return (success=TRUE); -} - -func isPool{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(address: felt) -> (success: felt) { - return SuperToken.isPool(address); -} - -@view -func getNumConnections{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - account: felt -) -> (value: felt) { - return SuperToken.getNumConnections(account); -} - -@external -func mint{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(to: felt, amount: felt) { - SuperToken._mint(to, amount); - return (); -} - diff --git a/packages/starknet-contracts/src/tokens/ERC20x/SuperToken/library.cairo b/packages/starknet-contracts/src/tokens/ERC20x/SuperToken/library.cairo deleted file mode 100644 index bd1dd1ea02..0000000000 --- a/packages/starknet-contracts/src/tokens/ERC20x/SuperToken/library.cairo +++ /dev/null @@ -1,826 +0,0 @@ -%lang starknet - -from starkware.starknet.common.syscalls import ( - get_caller_address, - get_block_timestamp, - get_contract_address, -) -from starkware.cairo.common.cairo_builtins import HashBuiltin -from starkware.cairo.common.math import assert_not_zero, assert_le, assert_nn, assert_not_equal -from starkware.cairo.common.math_cmp import is_not_zero, is_le, is_nn -from starkware.cairo.common.bool import TRUE, FALSE -from starkware.cairo.common.bitwise import bitwise_not -from starkware.cairo.common.hash_chain import hash_chain -from starkware.cairo.common.alloc import alloc -from starkware.starknet.common.syscalls import deploy -from starkware.cairo.common.hash import hash2 - -from openzeppelin.utils.constants.library import UINT8_MAX - -from src.utils.SemanticMoney import SemanticMoney, BasicParticle, PDPoolMemberMU -from src.interfaces.ISuperfluidPool import ISuperfluidPool - - -// -// Structs -// - -struct AccountData { - totalBuffer: felt, - totalInflowRate: felt, - totalOutflowRate: felt, -} - -struct FlowData { - _from: felt, - to: felt, - flowRate: felt, - buffer: felt, -} - -// -// Events -// - -@event -func Transfer(from_: felt, to: felt, value: felt) { -} - -@event -func Approval(owner: felt, spender: felt, value: felt) { -} - -@event -func PoolCreated(admin: felt, poolAddress: felt) { -} - -@event -func FlowCreated(sender: felt, recipient: felt, flowId: felt, flowRate: felt) { -} - -@event -func FlowDistributed(sender: felt, poolAddress: felt, flowId: felt, flowRate: felt) { -} - -@event -func Distributed(sender: felt, poolAddress: felt, amount: felt) { -} - -// -// Storage -// - -@storage_var -func SuperToken_salt() -> (value: felt) { -} - -@storage_var -func SuperToken_pool_class_hash() -> (value: felt) { -} - -@storage_var -func SuperToken_name() -> (name: felt) { -} - -@storage_var -func SuperToken_symbol() -> (symbol: felt) { -} - -@storage_var -func SuperToken_decimals() -> (decimals: felt) { -} - -@storage_var -func SuperToken_universal_indexes(address: felt) -> (index: BasicParticle) { -} - -@storage_var -func SuperToken_flow_data(hash: felt) -> (data: FlowData) { -} - -@storage_var -func SuperToken_pool_length() -> (value: felt) { -} - -@storage_var -func SuperToken_pools(index: felt) -> (pool: felt) { -} - -@storage_var -func SuperToken_pool_indexes(pool: felt) -> (index: felt) { -} - -@storage_var -func SuperToken_connection_map(account: felt, index: felt) -> (connected: felt) { -} - -@storage_var -func SuperToken_account_data(account: felt) -> (data: AccountData) { -} - -@storage_var -func SuperToken_liquidation_period() -> (value: felt) { -} - -@storage_var -func SuperToken_connected_pool_length(account: felt) -> (value: felt) { -} - -const FLOW_AS_FELT = 1718382455; -const DISTRIBUTE_FLOW_AS_FELT = 133470332451617709077403932975189225335; -const POOL_ADJUSTMENT_FLOW_AS_FELT = 641892055390323327801894208654700561001886805879; - -namespace SuperToken { - - // - // Initializer - // - func initializer{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - name: felt, symbol: felt, decimals: felt, pool_class_hash: felt - ) { - SuperToken_name.write(name); - SuperToken_symbol.write(symbol); - with_attr error_message("SuperToken: decimals exceed 2^8") { - assert_le(decimals, UINT8_MAX); - } - SuperToken_decimals.write(decimals); - SuperToken_pool_class_hash.write(pool_class_hash); - SuperToken_liquidation_period.write(1000); - return (); - } - - func name{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (name: felt) { - return SuperToken_name.read(); - } - - func symbol{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> ( - symbol: felt - ) { - return SuperToken_symbol.read(); - } - - func totalSupply{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> ( - totalSupply: felt - ) { - return (totalSupply=0); - } - - func decimals{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> ( - decimals: felt - ) { - return SuperToken_decimals.read(); - } - - func balanceOf{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - account: felt - ) -> (balance: felt) { - alloc_locals; - let (timestamp) = get_block_timestamp(); - let (rtb) = realtimeBalanceAt(account, timestamp); - let is_less_than_or_equals_zero = is_le(rtb, 0); - if (is_less_than_or_equals_zero == TRUE) { - return (balance=0); - } else { - return (balance=rtb); - } - } - - func transfer{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(to: felt, amount: felt) -> (success: felt) { - alloc_locals; - let (caller) = get_caller_address(); - return _shift(caller, caller, to, amount); - } - - func transferFrom{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(_from: felt, to: felt, amount: felt) -> (success: felt) { - alloc_locals; - let (caller) = get_caller_address(); - return _shift(caller, _from, to, amount); - } - - // // ////////////////////////////////////////////////////////////////////////////// - // // Generalized Payment Primitives starts here - // // ////////////////////////////////////////////////////////////////////////////// - - func realtimeBalanceAt{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - account: felt, time: felt - ) -> (rtb: felt) { - let (own, fromPool ,_) = realtimeBalanceVectorAt(account, time); - return (rtb = own + fromPool); - } - - func realtimeBalanceVectorAt{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr - }(account: felt, time: felt) -> (own: felt, fromPool: felt, deposit: felt) { - alloc_locals; - let (accountIndex) = SuperToken_universal_indexes.read(account); - let (available) = SemanticMoney.realtime_balance_of(accountIndex, time); - let (isAPool) = isPool(account); - if (isAPool == TRUE) { - let (own) = ISuperfluidPool.getDisconnectedBalance(contract_address=account, time=time); - let (length) = SuperToken_pool_length.read(); - let (poolBalance) = poolBalanceOf(account, length, 0); - let (accountData) = SuperToken_account_data.read(account); - let deposit = accountData.totalBuffer; - return (own=own, fromPool=poolBalance, deposit=deposit); - } else { - let (uIndex) = SuperToken_universal_indexes.read(account); - let (own) = SemanticMoney.realtime_balance_of(uIndex, time); - let (length) = SuperToken_pool_length.read(); - let (poolBalance) = poolBalanceOf(account, length, 0); - let (accountData) = SuperToken_account_data.read(account); - let deposit = accountData.totalBuffer; - return (own=own, fromPool=poolBalance, deposit=deposit); - } - } - - func poolBalanceOf{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - account: felt, pool_length: felt, sum: felt - ) -> (balance: felt) { - if (pool_length == 0) { - return (balance=sum); - } - let (connected) = SuperToken_connection_map.read(account, pool_length); - if (connected == TRUE) { - let (pool) = SuperToken_pools.read(pool_length); - let (timestamp) = get_block_timestamp(); - let (balance) = ISuperfluidPool.getClaimable( - contract_address=pool, time=timestamp, memberAddress=account - ); - let _sum = sum + balance; - return poolBalanceOf(account, pool_length - 1, _sum); - } else { - return poolBalanceOf(account, pool_length - 1, sum); - } - } - - func getNetFlowRate{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - account: felt - ) -> (flowRate: felt) { - alloc_locals; - let (accountIndex) = SuperToken_universal_indexes.read(account); - let (flowRate) = SemanticMoney.flow_rate(accountIndex); - let (isAPool) = isPool(account); - - if (isAPool == TRUE) { - let (dfr) = ISuperfluidPool.getDisconnectedFlowRate(contract_address=account); - let nr = flowRate + dfr; - let (length) = SuperToken_pool_length.read(); - let (poolFlowRate) = poolFlowRateOf(account, length, 0); - let totalFlowRate = nr + poolFlowRate; - return (flowRate=totalFlowRate); - } else { - let (length) = SuperToken_pool_length.read(); - let (poolFlowRate) = poolFlowRateOf(account, length, 0); - let nr = flowRate + poolFlowRate; - return (flowRate=nr); - } - } - - func poolFlowRateOf{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - account: felt, pool_length: felt, sum: felt - ) -> (flow_rate: felt) { - if (pool_length == 0) { - return (flow_rate=sum); - } - let (connected) = SuperToken_connection_map.read(account, pool_length); - if (connected == TRUE) { - let (pool) = SuperToken_pools.read(pool_length); - let (flow_rate) = ISuperfluidPool.getMemberFlowRate( - contract_address=pool, memberAddress=account - ); - let _sum = sum + flow_rate; - return poolFlowRateOf(account, pool_length - 1, _sum); - } else { - return poolFlowRateOf(account, pool_length - 1, sum); - } - } - - func getFlowRate{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - _from: felt, to: felt, flowId: felt - ) -> (flowRate: felt) { - let (flowHash) = getFlowHash(_from, to, flowId); - let (flowRate) = _getFlowRate(flowHash); - return (flowRate=flowRate); - } - - func getFlowHash{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(_from: felt, to: felt, flow_id: felt) -> (hash: felt) { - let (hash_sender_and_recipient) = hash2{hash_ptr=pedersen_ptr}(_from, to); - let (hash_sender_and_recipient_and_flow_type) = hash2{hash_ptr=pedersen_ptr}( - hash_sender_and_recipient, FLOW_AS_FELT - ); - let (flowHash) = hash2{hash_ptr=pedersen_ptr}(hash_sender_and_recipient_and_flow_type, flow_id); - return (hash=flowHash); - } - - func getDistributionFlowHash{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr - }(_from: felt, to: felt, flowId: felt) -> (hash: felt) { - let (hash_sender_and_poolAddress) = hash2{hash_ptr=pedersen_ptr}(_from, to); - let (hash_sender_and_poolAddress_and_flow_type) = hash2{hash_ptr=pedersen_ptr}( - hash_sender_and_poolAddress, DISTRIBUTE_FLOW_AS_FELT - ); - let (flowHash) = hash2{hash_ptr=pedersen_ptr}( - hash_sender_and_poolAddress_and_flow_type, flowId - ); - return (hash=flowHash); - } - - func getPoolAdjustmentFlowHash{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr - }(_from: felt, to: felt) -> (hash: felt) { - let (hash_sender_and_poolAddress) = hash2{hash_ptr=pedersen_ptr}(_from, to); - let (flowHash) = hash2{hash_ptr=pedersen_ptr}( - hash_sender_and_poolAddress, POOL_ADJUSTMENT_FLOW_AS_FELT - ); - return (hash=flowHash); - } - - func shift{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - sender: felt, recipient: felt, amount: felt - ) -> (success: felt) { - let (caller) = get_caller_address(); - return _shift(caller, sender, recipient, amount); - } - - func _shift{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(operator: felt, sender: felt, recipient: felt, amount: felt) -> (success: felt) { - alloc_locals; - let (is_a_pool) = isPool(recipient); - with_attr error_message("SuperToken: recepient is a pool!") { - assert_not_equal(is_a_pool, 1); - } - with_attr error_message("SuperToken: amount is negative!") { - assert_nn(amount); - } - let (aclStatus) = _acl(operator, sender); - with_attr error_message("SuperToken: ACL for shift not supported") { - assert aclStatus = TRUE; - } - _doShift(sender, recipient, amount); - return (success=TRUE); - } - - func _doShift{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(_from: felt, to: felt, amount: felt) -> (success: felt) { - alloc_locals; - if (_from == to) { - return (success=TRUE); - } else { - let (senderIndex) = SuperToken_universal_indexes.read(_from); - let (recipientIndex) = SuperToken_universal_indexes.read(to); - let (newSenderIndex, newRecipientIndex) = SemanticMoney.shift2( - senderIndex, recipientIndex, amount - ); - SuperToken_universal_indexes.write(_from, newSenderIndex); - SuperToken_universal_indexes.write(to, newRecipientIndex); - return (success=TRUE); - } - } - - - func flow{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - sender: felt, recipient: felt, flowId: felt, flowRate: felt - ) -> (success: felt) { - alloc_locals; - let (caller) = get_caller_address(); - return _flow(caller, sender, recipient, flowId, flowRate); - } - - func _flow{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - operator: felt, sender: felt, recipient: felt, flowId: felt, flowRate: felt - ) -> (success: felt) { - alloc_locals; - let (caller) = get_caller_address(); - with_attr error_message("SuperToken: invalid sender!") { - assert caller = sender; - } - with_attr error_message("SuperToken: negative flow rate not allowed") { - assert_nn(flowRate); - } - - let (is_a_pool) = isPool(recipient); - with_attr error_message("SuperToken: recepient is a pool!") { - assert_not_equal(is_a_pool, 1); - } - - let (aclStatus) = _acl(operator, sender); - with_attr error_message("SuperToken: ACL for flow not supported") { - assert aclStatus = TRUE; - } - - let (flowHash) = getFlowHash(sender, recipient, flowId); - let (time) = get_block_timestamp(); - _doFlow(sender, recipient, flowHash, flowRate, time); - _adjustBuffer(sender, flowHash, flowRate); - FlowCreated.emit(sender, recipient, flowId, flowRate); - return (success=TRUE); - } - - func _doFlow{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - _from: felt, to: felt, flowHash: felt, flowRate: felt, time: felt - ) -> (success: felt) { - alloc_locals; - if (_from == to) { - return (success=TRUE); - } else { - let (oldFlowRate) = _getFlowRate(flowHash); - let flowRateDelta = flowRate - oldFlowRate; - let (uIndexForFrom) = SuperToken_universal_indexes.read(_from); - let (uIndexForTo) = SuperToken_universal_indexes.read(to); - let (newUIndexForFrom, newUIndexForTo) = SemanticMoney.shiftFlow2(uIndexForFrom, uIndexForTo, flowRateDelta, time); - SuperToken_universal_indexes.write(_from, newUIndexForFrom); - SuperToken_universal_indexes.write(to, newUIndexForTo); - _setFlowInfo(flowHash, _from, to, flowRate, flowRateDelta); - return (success=TRUE); - } - } - - func distribute{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(sender: felt, poolAddress: felt, reqAmount: felt - ) -> (success: felt, actualAmount: felt) { - alloc_locals; - let (caller) = get_caller_address(); - return _distribute(caller, sender, poolAddress, reqAmount); - } - - func _distribute{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - operator: felt, sender: felt, pool: felt, reqAmount: felt - ) -> (success: felt, actualAmount: felt) { - alloc_locals; - let (is_a_pool) = isPool(pool); - with_attr error("SuperToken: Pool does not exist") { - assert is_a_pool = TRUE; - } - with_attr error_message("SuperToken: negative amount not allowed") { - assert_nn(reqAmount); - } - let (caller) = get_caller_address(); - with_attr error_message("SuperToken: invalid sender!") { - assert caller = sender; - } - - let (aclStatus) = _acl(operator, sender); - with_attr error_message("SuperToken: ACL for flow not supported") { - assert aclStatus = TRUE; - } - - let (actualAmount) = _doDistributeViaPool(sender, pool, reqAmount); - Distributed.emit(sender, pool, actualAmount); - return (success=TRUE, actualAmount=actualAmount); - } - - func _doDistributeViaPool{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(_from: felt, pool: felt, reqAmount: felt) -> (actualAmount: felt) { - alloc_locals; - with_attr error_message("SuperToken: sender can't be equal to pool") { - assert_not_equal(_from, pool); - } - let (uIndexForFrom) = SuperToken_universal_indexes.read(_from); - let (pdIndex) = ISuperfluidPool.getIndex(contract_address=pool); - let (newUIndexForFrom, newPdIndex, actualAmount) = SemanticMoney.shift2_pd( - uIndexForFrom, pdIndex, reqAmount - ); - SuperToken_universal_indexes.write(_from, newUIndexForFrom); - ISuperfluidPool.operatorSetIndex(contract_address=pool, index=newPdIndex); - return (actualAmount=actualAmount); - } - - func distributeFlow{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - sender: felt, pool: felt, flowId: felt, reqFlowRate: felt - ) -> (success: felt, actualFlowRate: felt, newDistributionFlowRate: felt) { - alloc_locals; - let (caller) = get_caller_address(); - return _distributeFlow(caller, sender, pool, flowId, reqFlowRate); - } - - func _distributeFlow{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - operator: felt, sender: felt, pool: felt, flowId: felt, reqFlowRate: felt - ) -> (success: felt, actualFlowRate: felt, newDistributionFlowRate: felt) { - alloc_locals; - let (is_a_pool) = isPool(pool); - with_attr error("SuperToken: Pool does not exist") { - assert is_a_pool = TRUE; - } - with_attr error_message("SuperToken: negative flow_rate not allowed") { - assert_nn(reqFlowRate); - } - let (caller) = get_caller_address(); - with_attr error_message("SuperToken: invalid sender!") { - assert caller = sender; - } - - let (aclStatus) = _acl(operator, sender); - with_attr error_message("SuperToken: ACL for flow not supported") { - assert aclStatus = TRUE; - } - - let (flowHash) = getDistributionFlowHash(sender, pool, flowId); - let (time) = get_block_timestamp(); - let (newActualFlowRate, newDistributionFlowRate) = _doDistributeFlowViaPool(sender, pool, flowHash, reqFlowRate, time); - _adjustBuffer(sender, flowHash, newActualFlowRate); - FlowDistributed.emit(sender, pool, flowId, newActualFlowRate); - return (success=TRUE, actualFlowRate=newActualFlowRate, newDistributionFlowRate=newDistributionFlowRate); - } - - func _doDistributeFlowViaPool{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(_from: felt, pool: felt, flowHash: felt, reqFlowRate: felt, time: felt) -> (newActualFlowRate: felt, newDistributionFlowRate: felt) { - alloc_locals; - with_attr error_message("SuperToken: sender can't be equal to pool") { - assert_not_equal(_from, pool); - } - // uIndexForFrom: from uidx -> uIndexForPool: pool uidx -> pdIndex: pool pdpidx - // uIndexForPool handles the adjustment flow through _get/_setPoolAdjustmentFlowRate. - let (uIndexForFrom) = SuperToken_universal_indexes.read(_from); - let (uIndexForPool) = SuperToken_universal_indexes.read(pool); - let (pdIndex) = ISuperfluidPool.getIndex(contract_address=pool); - let (currentAdjustmentFlowRate) = _getPoolAdjustmentFlowRate(pool); - - let (oldFlowRate) = _getFlowRate(flowHash); // flow rate of : from -> pool - let (oldDistributionFlowRate) = SemanticMoney.flow_rate_for_pool_index(pdIndex); - let shiftFlowRate = reqFlowRate - oldFlowRate; - - - // to readjust, include the current adjustment flow rate here - let (newUIndexForPool, newPdIndex, newDistributionFlowRate) = SemanticMoney.shiftFlow_pd(uIndexForPool, pdIndex, shiftFlowRate + currentAdjustmentFlowRate, time); - - with_attr error_message("SuperToken: distribution flow rate cannot be negative") { - assert_nn(newDistributionFlowRate); - } - let newActualFlowRate = oldFlowRate + (newDistributionFlowRate - oldDistributionFlowRate) - currentAdjustmentFlowRate; - let newActualFlowRateisNotNeg = is_nn(newActualFlowRate); - if (newActualFlowRateisNotNeg == TRUE){ - let newAdjustmentFlowRate = 0; - let actualFlowRateDelta = newActualFlowRate - oldFlowRate; - let (newUIndexForFrom, _newUIndexForPool) = SemanticMoney.shiftFlow2(uIndexForFrom, newUIndexForPool, actualFlowRateDelta, time); - SuperToken_universal_indexes.write(_from, newUIndexForFrom); - SuperToken_universal_indexes.write(pool, _newUIndexForPool); - ISuperfluidPool.operatorSetIndex(contract_address=pool, index=newPdIndex); - _setFlowInfo(flowHash, _from, pool, newActualFlowRate, actualFlowRateDelta); - _setPoolAdjustmentFlowRate(pool, FALSE, newAdjustmentFlowRate, time); - return (newActualFlowRate=newActualFlowRate, newDistributionFlowRate=newDistributionFlowRate); - } else { - let newAdjustmentFlowRate = -newActualFlowRate; - let newActualFlowRate = 0; - let actualFlowRateDelta = newActualFlowRate - oldFlowRate; - let (newUIndexForFrom, _newUIndexForPool) = SemanticMoney.shiftFlow2(uIndexForFrom, newUIndexForPool, actualFlowRateDelta, time); - SuperToken_universal_indexes.write(_from, newUIndexForFrom); - SuperToken_universal_indexes.write(pool, _newUIndexForPool); - ISuperfluidPool.operatorSetIndex(contract_address=pool, index=newPdIndex); - _setFlowInfo(flowHash, _from, pool, newActualFlowRate, actualFlowRateDelta); - _setPoolAdjustmentFlowRate(pool, FALSE, newAdjustmentFlowRate, time); - return (newActualFlowRate=newActualFlowRate, newDistributionFlowRate=newDistributionFlowRate); - } - } - - func connectPool{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(to: felt) -> ( - success: felt - ) { - alloc_locals; - let (caller) = get_caller_address(); - let (poolIndex) = SuperToken_pool_indexes.read(to); - let (connected) = SuperToken_connection_map.read(caller, poolIndex); - with_attr error_message("SuperToken: already connected") { - assert connected = FALSE; - } - return connectPoolEnum(to, TRUE); - } - - func disconnectPool{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - to: felt - ) -> (success: felt) { - alloc_locals; - let (caller) = get_caller_address(); - let (poolIndex) = SuperToken_pool_indexes.read(to); - let (connected) = SuperToken_connection_map.read(caller, poolIndex); - with_attr error_message("SuperToken: no connections") { - assert connected = TRUE; - } - return connectPoolEnum(to, FALSE); - } - - func connectPoolEnum{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - pool: felt, dbConnect: felt - ) -> (success: felt) { - alloc_locals; - let (caller) = get_caller_address(); - let (poolIndex) = SuperToken_pool_indexes.read(pool); - let (timestamp) = get_block_timestamp(); - if (dbConnect == TRUE) { - SuperToken_connection_map.write(caller, poolIndex, TRUE); - let (connected) = ISuperfluidPool.operatorConnectMember( - contract_address=pool, memberAddress=caller, dbConnect=TRUE - ); - assert connected = TRUE; - let (connectedPoolLength) = SuperToken_connected_pool_length.read(caller); - SuperToken_connected_pool_length.write(caller, connectedPoolLength + 1); - } else { - SuperToken_connection_map.write(caller, poolIndex, FALSE); - let (disconnected) = ISuperfluidPool.operatorConnectMember( - contract_address=pool, memberAddress=caller, dbConnect=FALSE - ); - assert disconnected = TRUE; - let (connectedPoolLength) = SuperToken_connected_pool_length.read(caller); - SuperToken_connected_pool_length.write(caller, connectedPoolLength - 1); - } - return (success=TRUE); - } - - func setLiquadationPeriod{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(value: felt) { - with_attr error_message("SuperToken: liquidation value is negative") { - assert_nn(value); - } - SuperToken_liquidation_period.write(value); - return (); - } - - func _getFlowRate{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(flowHash: felt) -> (flowRate: felt) { - let (flowData) = SuperToken_flow_data.read(flowHash); - return (flowRate=flowData.flowRate); - } - - // // ////////////////////////////////////////////////////////////////////////////// - // // Generalized Payment Primitives ends here - // // ////////////////////////////////////////////////////////////////////////////// - - // // ////////////////////////////////////////////////////////////////////////////// - // ///////// Pool Operations starts here - // // ////////////////////////////////////////////////////////////////////////////// - - func isMemberConnected{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - pool: felt, memberAddress: felt - ) -> (success: felt) { - let (poolIndex) = SuperToken_pool_indexes.read(pool); - let (isMemberConnected) = SuperToken_connection_map.read(memberAddress, poolIndex); - return (success=isMemberConnected); - } - - func getPoolAdjustmentFlowInfo{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(pool: felt) -> (adjustmentRecipient: felt, flowHash: felt, flowRate: felt){ - return _getPoolAdjustmentFlowInfo(pool); - } - - func _getPoolAdjustmentFlowInfo{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(pool: felt) -> (adjustmentRecipient: felt, flowHash: felt, flowRate: felt){ - let (adjustmentRecipient) = ISuperfluidPool.admin(contract_address=pool); - let (flowHash) = getPoolAdjustmentFlowHash(pool, adjustmentRecipient); - let (flowData) = SuperToken_flow_data.read(flowHash); - return (adjustmentRecipient=adjustmentRecipient, flowHash=flowHash, flowRate=flowData.flowRate); - } - - func _getPoolAdjustmentFlowRate{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(pool: felt) -> (flowRate: felt){ - let (_,_,flowRate) = _getPoolAdjustmentFlowInfo(pool); - return (flowRate=flowRate); - } - - func _setPoolAdjustmentFlowRate{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(pool: felt, shiftFlow: felt, flowRate: felt, time: felt){ - let (adjustmentRecipient) = ISuperfluidPool.admin(contract_address=pool); - let (adjustmentFlowHash) = getPoolAdjustmentFlowHash(pool, adjustmentRecipient); - if (shiftFlow == TRUE){ - let (oldFlowRate) = _getFlowRate(adjustmentFlowHash); - let _flowRate = flowRate + oldFlowRate; - _doFlow(pool, adjustmentRecipient, adjustmentFlowHash, _flowRate, time); - } else { - _doFlow(pool, adjustmentRecipient, adjustmentFlowHash, flowRate, time); - } - return (); - } - - func appendIndexUpdateByPool{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(particle: BasicParticle, time: felt) -> (success: felt) { - let (caller) = get_caller_address(); - _appendIndexUpdateByPool(caller, particle, time); - return (success=TRUE); - } - - func _appendIndexUpdateByPool{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(pool: felt, particle: BasicParticle, time: felt){ - let (isAPool) = isPool(pool); - with_attr error_message("SuperToken: Only a pool can adjust flow!") { - assert isAPool = TRUE; - } - let (uIndexForPool) = SuperToken_universal_indexes.read(pool); - let (newUIndexForPool) = SemanticMoney.mappend(uIndexForPool, particle); - SuperToken_universal_indexes.write(pool, newUIndexForPool); - let (flowRate) = SemanticMoney.flow_rate(particle); - _setPoolAdjustmentFlowRate(pool, TRUE, flowRate, time); - return (); - } - - func poolSettleClaim{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(claimRecipient: felt, amount: felt) -> (success: felt){ - let (caller) = get_caller_address(); - _poolSettleClaim(caller, claimRecipient, amount); - return (success=TRUE); - } - - func _poolSettleClaim{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(pool:felt, claimRecipient: felt, amount: felt){ - let (isAPool) = isPool(pool); - with_attr error_message("SuperToken: Only a pool can settle claim!") { - assert isAPool = TRUE; - } - _doShift(pool, claimRecipient, amount); - return (); - } - - func isPool{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(address: felt) -> (success: felt) { - let (poolIndex) = SuperToken_pool_indexes.read(address); - let (is_pool) = SuperToken_pools.read(poolIndex); - if (is_pool == FALSE){ - return (success=FALSE); - } else { - return (success=TRUE); - } - } - - func createPool{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> ( - pool: felt - ) { - alloc_locals; - let (caller) = get_caller_address(); - let (class_hash) = SuperToken_pool_class_hash.read(); - let (current_salt) = SuperToken_salt.read(); - let (contract_address) = deploy( - class_hash=class_hash, - contract_address_salt=current_salt, - constructor_calldata_size=1, - constructor_calldata=cast(new (caller,), felt*), - deploy_from_zero=FALSE, - ); - SuperToken_salt.write(current_salt + 1); - let (pool_length) = SuperToken_pool_length.read(); - SuperToken_pool_length.write(pool_length + 1); - SuperToken_pool_indexes.write(contract_address, pool_length + 1); - SuperToken_pools.write(pool_length + 1, contract_address); - PoolCreated.emit(caller, contract_address); - return (pool=contract_address); - } - - func getNumConnections{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - account: felt - ) -> (value: felt) { - return SuperToken_connected_pool_length.read(account); - } - - /////////////////////////////////////////////////////////////////////////////////// - //////////// Pool Operations ends here - /////////////////////////////////////////////////////////////////////////////////// - - //////////////////////////////////////////////////////////////////////////////////// - /////////// Buffer Solvency - //////////////////////////////////////////////////////////////////////////////////// - - func _adjustBuffer{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(_from: felt, flow_hash: felt, newflowRate: felt){ - alloc_locals; - let (lp) = SuperToken_liquidation_period.read(); - let newBufferAmount = newflowRate * lp; - let (flowData) = SuperToken_flow_data.read(flow_hash); - let bufferDelta = newBufferAmount - flowData.buffer; - let (contract_address) = get_contract_address(); - _doShift(_from, contract_address, bufferDelta); - - let (accountData) = SuperToken_account_data.read(_from); - let newAccountData = AccountData(accountData.totalBuffer + bufferDelta, accountData.totalInflowRate, accountData.totalOutflowRate); - SuperToken_account_data.write(_from, newAccountData); - - let newFlowData = FlowData(flowData._from, flowData.to, flowData.flowRate, newBufferAmount); - SuperToken_flow_data.write(flow_hash, newFlowData); - return (); - } - - //////////////////////////////////////////////////////////////////////////////////// - //// Others - //////////////////////////////////////////////////////////////////////////////////// - - func _setFlowInfo{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(flowHash: felt, _from: felt, to: felt, newflowRate: felt, flowRateDelta: felt){ - let (flowData) = SuperToken_flow_data.read(flowHash); - let newFlowData = FlowData(flowData._from, flowData.to, newflowRate, flowData.buffer); - SuperToken_flow_data.write(flowHash, newFlowData); - - let (senderAccountData) = SuperToken_account_data.read(_from); - let newSenderAccountData = AccountData(senderAccountData.totalBuffer, senderAccountData.totalInflowRate, senderAccountData.totalOutflowRate + flowRateDelta); - SuperToken_account_data.write(_from, newSenderAccountData); - - let (recipientAccountData) = SuperToken_account_data.read(to); - let newRecipienAccountData = AccountData(recipientAccountData.totalBuffer, recipientAccountData.totalInflowRate + flowRateDelta, recipientAccountData.totalOutflowRate); - SuperToken_account_data.write(to, recipientAccountData); - return (); - } - - func _acl{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(operator: felt, _from: felt) -> (status: felt){ - if (operator == _from){ - return (status=TRUE); - } else { - return (status=FALSE); - } - } - - func _mint{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - recipient: felt, amount: felt - ) { - with_attr error_message("SuperToken: amount is negative") { - assert_nn(amount); - } - with_attr error_message("SuperToken: cannot mint to the zero address") { - assert_not_zero(recipient); - } - let (zeroAddressIndex) = SuperToken_universal_indexes.read(0); - let (recipientIndex) = SuperToken_universal_indexes.read(recipient); - let (newZeroAddressIndex, newRecipientIndex) = SemanticMoney.shift2( - zeroAddressIndex, recipientIndex, amount - ); - SuperToken_universal_indexes.write(0, newZeroAddressIndex); - SuperToken_universal_indexes.write(recipient, newRecipientIndex); - Transfer.emit(0, recipient, amount); - return (); - } -} diff --git a/packages/starknet-contracts/src/utils/BitMap.cairo b/packages/starknet-contracts/src/utils/BitMap.cairo deleted file mode 100644 index 8c0781ee2d..0000000000 --- a/packages/starknet-contracts/src/utils/BitMap.cairo +++ /dev/null @@ -1,19 +0,0 @@ -// %lang starknet - -// from starkware.cairo.common.cairo_builtins import HashBuiltin - -// struct Data { -// key: felt; -// value: felt; -// } - -// namespace BitMap { - -// func set{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( -// set: Set, value: felt -// ) -> (data: Data, index: felt) { -// let bucket = index / (251); // Right-Shift -// let mask = 1 * (2 ** (index / (2 ** 251))); -// } - -// } diff --git a/packages/starknet-contracts/src/utils/EnumerableSet.cairo b/packages/starknet-contracts/src/utils/EnumerableSet.cairo deleted file mode 100644 index d05f63553b..0000000000 --- a/packages/starknet-contracts/src/utils/EnumerableSet.cairo +++ /dev/null @@ -1,47 +0,0 @@ -%lang starknet - -from starkware.cairo.common.cairo_builtins import HashBuiltin -from starkware.cairo.common.bool import TRUE, FALSE - -struct Set { - values: felt*, - indexes: felt*, - length: felt, -} - -namespace EnumerableSet { - func add{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - set: Set, value: felt - ) -> (set: Set, success: felt) { - let setContains = contains(set, value); - if (setContains == TRUE) { - assert [set.values + set.length] = value; - assert [set.indexes] = set.length; - let new_set = Set(set.values, set.indexes, set.length + 1); - return (set=new_set, success=TRUE); - } - return (set=Set(0, 0, 0), success=FALSE); - } - - func contains{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - set: Set, value: felt - ) -> (success: felt) { - let found = find(set, value); - return (success=found); - } - - func find{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - set: Set, value: felt - ) -> (success: felt) { - if (set.length != 0) { - let _value = [set.values + (set.length - 1)]; - if (_value == value) { - return (success=TRUE); - } else { - let new_set = Set(set.indexes, set.values, set.length - 1); - find(new_set, value); - } - } - return (success=FALSE); - } -} diff --git a/packages/starknet-contracts/src/utils/MathLib.cairo b/packages/starknet-contracts/src/utils/MathLib.cairo deleted file mode 100644 index a564f47d15..0000000000 --- a/packages/starknet-contracts/src/utils/MathLib.cairo +++ /dev/null @@ -1,29 +0,0 @@ -%lang starknet - -from starkware.cairo.common.cairo_builtins import HashBuiltin -from starkware.cairo.common.math import unsigned_div_rem, signed_div_rem, assert_in_range -from starkware.cairo.common.math_cmp import RC_BOUND, is_le, is_not_zero, is_nn -from starkware.cairo.common.bool import TRUE - - -const DIVISOR_MAX = 10633823966279327296825105735305134080; // PRIME//RC_BOUND - -const BOUND = RC_BOUND/2; // bound <= rc_bound / 2. - -namespace MathLib { - - func div{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(value: felt, div: felt) -> (quotient: felt, remainder: felt) { - alloc_locals; - with_attr error_message("MathLib: Invalid Divisor") { - assert_in_range(div, 0, DIVISOR_MAX); - } - let is_not_negative = is_nn(value); - if (is_not_negative == TRUE){ - let (quotient, remainder) = unsigned_div_rem(value, div); - return (quotient=quotient, remainder=remainder); - } else { - let (quotient, remainder) = signed_div_rem(value, div, BOUND); - return (quotient=quotient, remainder=remainder); - } - } -} diff --git a/packages/starknet-contracts/src/utils/SemanticMoney.cairo b/packages/starknet-contracts/src/utils/SemanticMoney.cairo deleted file mode 100644 index cda9ed42ba..0000000000 --- a/packages/starknet-contracts/src/utils/SemanticMoney.cairo +++ /dev/null @@ -1,339 +0,0 @@ -%lang starknet - -from starkware.cairo.common.cairo_builtins import HashBuiltin -from starkware.cairo.common.math_cmp import is_le, is_not_zero, is_nn -from starkware.cairo.common.bool import TRUE - -from src.utils.MathLib import MathLib - -struct BasicParticle { - _settled_at: felt, - _settled_value: felt, - _flow_rate: felt, -} - -struct PDPoolIndex { - total_units: felt, - _wrapped_particle: BasicParticle, // This value is measured per unit -} - -struct PDPoolMember { - owned_unit: felt, - _settled_value: felt, - _synced_particle: BasicParticle, // It is a copy of the wrapped_particle of the index at the time an operation is performed. -} - -// Pool Member Monetary unit -struct PDPoolMemberMU { - pdPoolIndex: PDPoolIndex, - pdPoolMember: PDPoolMember, -} - -// Pure Functions - -namespace SemanticMoney { - - // monoid append - func mappend{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - a: BasicParticle, b: BasicParticle - ) -> (c: BasicParticle) { - alloc_locals; - let a_is_less_than_or_equal_to_b = is_le(a._settled_at, b._settled_at); - if (a_is_less_than_or_equal_to_b == TRUE) { - let (settledBasicParticleForA) = settle(a, b._settled_at); - let (settledBasicParticleForB) = settle(b, b._settled_at); - let c = BasicParticle( - b._settled_at, - settledBasicParticleForA._settled_value + settledBasicParticleForB._settled_value, - a._flow_rate + b._flow_rate, - ); - return (c=c); - } else { - let (settledBasicParticleForA) = settle(a, a._settled_at); - let (settledBasicParticleForB) = settle(b, a._settled_at); - let c = BasicParticle( - a._settled_at, - settledBasicParticleForA._settled_value + settledBasicParticleForB._settled_value, - a._flow_rate + b._flow_rate, - ); - return (c=c); - } - } - - //////////////////////////////////////////////////////////////////////////////////////// - //////////// Basic Particle Operations - //////////////////////////////////////////////////////////////////////////////////////// - - func clone{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(a: BasicParticle) -> (b: BasicParticle) { - let clonedBasicParticle = BasicParticle(a._settled_at, a._settled_value, a._flow_rate); - return (b=clonedBasicParticle); - } - - func settled_at{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(a: BasicParticle) -> (time: felt) { - return (time=a._settled_at); - } - - func flow_rate{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(a: BasicParticle) -> (flow_rate: felt) { - return (flow_rate=a._flow_rate); - } - - func settle{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - index: BasicParticle, time: felt - ) -> (index: BasicParticle) { - let timeDelta = time - index._settled_at; - let newSettledValue = (timeDelta * index._flow_rate) + index._settled_value; - let newBasicParticle = BasicParticle(time, newSettledValue, index._flow_rate); - return (index=newBasicParticle); - } - - func realtime_balance_of{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - index: BasicParticle, time: felt - ) -> (balance: felt) { - let timeDelta = time - index._settled_at; - let balance = (timeDelta * index._flow_rate) + index._settled_value; - return (balance=balance); - } - - func shift1{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - amount: felt, index: BasicParticle - ) -> (index: BasicParticle, amount: felt) { - let newBasicParticle = BasicParticle( - index._settled_at, index._settled_value + amount, index._flow_rate - ); - return (index=newBasicParticle, amount=amount); - } - - func flow1{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - flow_rate: felt, index: BasicParticle - ) -> (index: BasicParticle, flow_rate: felt) { - let newBasicParticle = BasicParticle(index._settled_at, index._settled_value, flow_rate); - return (index=newBasicParticle, flow_rate=flow_rate); - } - - func shift2{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - a: BasicParticle, b: BasicParticle, amount: felt - ) -> (a: BasicParticle, b: BasicParticle) { - let (bBasicParticle, _) = shift1(amount, b); - let (aBasicParticle, _) = shift1(-amount, a); - return (a=aBasicParticle, b=bBasicParticle); - } - - func flow2{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - a: BasicParticle, b: BasicParticle, flow_rate: felt, time: felt - ) -> (a: BasicParticle, b: BasicParticle) { - let (settledBasicParticleForA) = settle(a, time); - let (settledBasicParticleForB) = settle(b, time); - let (bBasicParticle, _) = flow1(flow_rate, settledBasicParticleForB); - let (aBasicParticle, _) = flow1(-flow_rate, settledBasicParticleForA); - return (a=aBasicParticle, b=bBasicParticle); - } - - func shiftFlow2{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - a: BasicParticle, b: BasicParticle, flow_rate: felt, time: felt - ) -> (m: BasicParticle, n: BasicParticle) { - alloc_locals; - let mempty = BasicParticle(0, 0, 0); - let (_, b1) = flow2(a, mempty, a._flow_rate, time); - let (m, b2) = flow2(a, mempty, -a._flow_rate + flow_rate, time); - let (b_and_b1) = mappend(b, b1); - let (n) = mappend(b_and_b1, b2); - return (m=m, n=n); - } - - //////////////////////////////////////////////////////////////////////////////////////// - //////////// Proportional Distribution Pool Index Operations - //////////////////////////////////////////////////////////////////////////////////////// - - func clone_of_pool_index{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - index: PDPoolIndex - ) -> (index: PDPoolIndex) { - let clonedPoolIndex = PDPoolIndex( - index.total_units, - BasicParticle(index.wrapped_particle._settled_at, index._settled_value, index._flow_rate), - ); - return (index=clonedPoolIndex); - } - - func settled_at_pool_index{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - index: PDPoolIndex - ) -> (time: felt) { - let (time) = settled_at(index._wrapped_particle); - return (time=time); - } - - func settle_for_pool_index{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - index: PDPoolIndex, time: felt - ) -> (index: PDPoolIndex) { - let (settled_wrapped_particle) = settle(index._wrapped_particle, time); - let newPoolIndex = PDPoolIndex(index.total_units, settled_wrapped_particle); - return (index=newPoolIndex); - } - - func flow_rate_for_pool_index{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(a: PDPoolIndex) -> (flow_rate: felt){ - return (flow_rate=a._wrapped_particle._flow_rate * a.total_units); - } - - func flow_rate_per_unit{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(a: PDPoolIndex) -> (flow_rate: felt) { - let (fr) = flow_rate(a._wrapped_particle); - return (flow_rate=fr); - } - - func shift1_for_pool_index{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(a: PDPoolIndex, value: felt) -> (b:PDPoolIndex, value: felt) { - alloc_locals; - let zero_status = is_not_zero(a.total_units); - if(zero_status == TRUE) { - let (quotient, _) = MathLib.div(value, a.total_units); - let actualValue = quotient * a.total_units; - let (newWrappedParticle, _) = shift1(actualValue/a.total_units, a._wrapped_particle); - let newPoolIndex = PDPoolIndex(a.total_units, newWrappedParticle); - return (b=newPoolIndex, value=actualValue); - } - return (b=a, value=0); - } - - func flow1_for_pool_index{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(a: PDPoolIndex, value: felt) -> (b:PDPoolIndex, flow_rate: felt) { - alloc_locals; - let zero_status = is_not_zero(a.total_units); - let is_not_negative = is_nn(value); - if(zero_status == TRUE) { - let (quotient, _) = MathLib.div(value, a.total_units); - let actualFlowRate = quotient * a.total_units; - let (newWrappedParticle, _) = flow1(actualFlowRate/a.total_units, a._wrapped_particle); - let newPoolIndex = PDPoolIndex(a.total_units, newWrappedParticle); - return (b=newPoolIndex, flow_rate=actualFlowRate); - } - return (b=a, flow_rate=0); - } - - //////////////////////////////////////////////////////////////////////////////////////// - //////////// Proportional Distribution Pool Member Operations - //////////////////////////////////////////////////////////////////////////////////////// - - func clone_of_pool_member_mu{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - poolMemberMU: PDPoolMemberMU - ) -> (poolMemberMU: PDPoolMemberMU) { - let clonedPoolMemberMU = PDPoolMemberMU( - PDPoolIndex( - poolMemberMU.pdPoolIndex.total_units, poolMemberMU.pdPoolIndex._wrapped_particle - ), - PDPoolMember( - poolMemberMU.pdPoolMember.owned_unit, - poolMemberMU.pdPoolMember._settled_value, - poolMemberMU.pdPoolMember._synced_particle, - ), - ); - return (index=clonedPoolMemberMU); - } - - func realtime_balance_of_pool_member_mu{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr - }(poolMemberMU: PDPoolMemberMU, time: felt) -> (balance: felt) { - let (realtime_balance_of_wrapped_particle) = realtime_balance_of( - poolMemberMU.pdPoolIndex._wrapped_particle, time - ); - let (realtime_balance_of_synced_particle) = realtime_balance_of( - poolMemberMU.pdPoolMember._synced_particle, - poolMemberMU.pdPoolMember._synced_particle._settled_at, - ); - let balance = ( - (realtime_balance_of_wrapped_particle - realtime_balance_of_synced_particle) * - poolMemberMU.pdPoolMember.owned_unit - ) + poolMemberMU.pdPoolMember._settled_value; - return (balance=balance); - } - - func settle_for_pool_member_mu{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - poolMemberMU: PDPoolMemberMU, time: felt - ) -> (poolMemberMU: PDPoolMemberMU) { - let (newSettledPoolIndex) = settle_for_pool_index(poolMemberMU.pdPoolIndex, time); - let (new_settled_value) = realtime_balance_of_pool_member_mu(poolMemberMU, time); - let newPoolMemberMU = PDPoolMemberMU( - newSettledPoolIndex, - PDPoolMember( - poolMemberMU.pdPoolMember.owned_unit, - new_settled_value, - newSettledPoolIndex._wrapped_particle, - ), - ); - return (poolMemberMU=newPoolMemberMU); - } - - func pool_member_update{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - poolMemberMU: PDPoolMemberMU, u_index: BasicParticle, unit: felt, time: felt - ) -> (p_index: PDPoolIndex, pool_member: PDPoolMember, u_index: BasicParticle) { - alloc_locals; - let old_total_units = poolMemberMU.pdPoolIndex.total_units; - let new_total_units = (old_total_units + unit) - poolMemberMU.pdPoolMember.owned_unit; - let (settled_pool_member_mu) = settle_for_pool_member_mu(poolMemberMU, time); - - if (new_total_units != 0) { - let nr = settled_pool_member_mu.pdPoolIndex._wrapped_particle._flow_rate; - let er = 0; - let r_mul_otu = nr * old_total_units; - let (quotient, remainder) = MathLib.div(r_mul_otu, new_total_units); - let nr = quotient; - let er = remainder; - let (wp_with_new_fr, _) = flow1( - nr, settled_pool_member_mu.pdPoolIndex._wrapped_particle - ); - let (settled_u_index) = settle(u_index, time); - let (u_index_with_new_fr, _) = flow1(settled_u_index._flow_rate + er, settled_u_index); - - let newPoolIndex = PDPoolIndex(new_total_units, wp_with_new_fr); - let newPoolMember = PDPoolMember( - unit, settled_pool_member_mu.pdPoolMember._settled_value, wp_with_new_fr - ); - return (p_index=newPoolIndex, pool_member=newPoolMember, u_index=u_index_with_new_fr); - } else { - let er = settled_pool_member_mu.pdPoolIndex._wrapped_particle._flow_rate * - old_total_units; - let nr = 0; - let (wp_with_new_fr, _) = flow1( - nr, settled_pool_member_mu.pdPoolIndex._wrapped_particle - ); - let (settled_u_index) = settle(u_index, time); - let (u_index_with_new_fr, _) = flow1(settled_u_index._flow_rate + er, settled_u_index); - - let newPoolIndex = PDPoolIndex(new_total_units, wp_with_new_fr); - let newPoolMember = PDPoolMember( - unit, settled_pool_member_mu.pdPoolMember._settled_value, wp_with_new_fr - ); - return (p_index=newPoolIndex, pool_member=newPoolMember, u_index=u_index_with_new_fr); - } - } - - func shift2_pd{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - u_index: BasicParticle, p_index: PDPoolIndex, value: felt - ) -> (u_index: BasicParticle, p_index: PDPoolIndex, actualAmount: felt) { - alloc_locals; - let (newPoolIndex, actualAmount) = shift1_for_pool_index(p_index, value); - let (newBasicParticle, _) = shift1(-actualAmount, u_index); - return (u_index=newBasicParticle, p_index=newPoolIndex, actualAmount=actualAmount); - - } - - func flow2_pd{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - u_index: BasicParticle, p_index: PDPoolIndex, flow_rate: felt, time: felt - ) -> (u_index: BasicParticle, p_index: PDPoolIndex, actualFlowRate: felt) { - alloc_locals; - let (settled_u_index) = settle(u_index, time); - let (settled_p_index) = settle_for_pool_index(p_index, time); - let (newPoolIndex, actualFlowRate) = flow1_for_pool_index(settled_p_index, flow_rate); - let (newBasicParticle, _) = flow1(-actualFlowRate, settled_u_index); - return (u_index=newBasicParticle, p_index=newPoolIndex, actualFlowRate=actualFlowRate); - - } - - func shiftFlow_pd{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - a: BasicParticle, b: PDPoolIndex, flow_rate: felt, time: felt - ) -> (m: BasicParticle, n: PDPoolIndex, actualFlowRate: felt) { - alloc_locals; - let mempty = BasicParticle(0, 0, 0); - let (_flow_rate) = flow_rate_for_pool_index(b); - let (a1, _, _) = flow2_pd(mempty, b, -_flow_rate, time); - let (a2, n, actualFlowRate) = flow2_pd(mempty, b, _flow_rate + flow_rate, time); - let (a_and_a1) = mappend(a, a1); - let (m) = mappend(a_and_a1, a2); - return (m=m, n=n, actualFlowRate=actualFlowRate); - } -} diff --git a/packages/starknet-contracts/src/utils/account/ITestAccount.cairo b/packages/starknet-contracts/src/utils/account/ITestAccount.cairo deleted file mode 100644 index 1412e48da2..0000000000 --- a/packages/starknet-contracts/src/utils/account/ITestAccount.cairo +++ /dev/null @@ -1,9 +0,0 @@ -%lang starknet - -from src.utils.account.library import Call - -@contract_interface -namespace ITestAccount { - func execute(calls_len: felt, calls: Call*, calldata_len:felt, calldata: felt*) { - } -} diff --git a/packages/starknet-contracts/src/utils/account/TestAccountImpl.cairo b/packages/starknet-contracts/src/utils/account/TestAccountImpl.cairo deleted file mode 100644 index aecc5b61c5..0000000000 --- a/packages/starknet-contracts/src/utils/account/TestAccountImpl.cairo +++ /dev/null @@ -1,11 +0,0 @@ -%lang starknet - -from starkware.cairo.common.cairo_builtins import HashBuiltin - -from src.utils.account.library import TestAccount, Call - -@external -func execute{syscall_ptr: felt*}(calls_len: felt, calls: Call*, calldata_len:felt, calldata: felt*){ - TestAccount.execute(calls_len, calls, calldata_len, calldata); - return (); -} \ No newline at end of file diff --git a/packages/starknet-contracts/src/utils/account/library.cairo b/packages/starknet-contracts/src/utils/account/library.cairo deleted file mode 100644 index 05ef100fac..0000000000 --- a/packages/starknet-contracts/src/utils/account/library.cairo +++ /dev/null @@ -1,25 +0,0 @@ -%lang starknet - -from starkware.starknet.common.syscalls import ( - call_contract -) - -struct Call { - to: felt, - selector: felt, -} - -namespace TestAccount { - - func execute{syscall_ptr: felt*}(calls_len: felt, calls: Call*, calldata_len:felt, calldata: felt*) { - alloc_locals; - let this_call: Call = [calls]; - let res = call_contract( - contract_address=this_call.to, - function_selector=this_call.selector, - calldata_size=calldata_len, - calldata=calldata, - ); - return (); - } -} \ No newline at end of file diff --git a/packages/starknet-contracts/tests/test_aqueduct.cairo b/packages/starknet-contracts/tests/test_aqueduct.cairo deleted file mode 100644 index e6b51285c6..0000000000 --- a/packages/starknet-contracts/tests/test_aqueduct.cairo +++ /dev/null @@ -1,66 +0,0 @@ -%lang starknet - -from starkware.cairo.common.cairo_builtins import HashBuiltin - -from src.interfaces.ISuperfluidToken import ISuperfluidToken -from src.interfaces.IAqueduct import IAqueduct - -// @external -// func __setup__{syscall_ptr: felt*}() { -// %{ -// declare("./src/pools/PoolImpl.cairo") -// context.supertoken_1 = deploy_contract("./src/tokens/ERC20x/SuperToken/SuperTokenImpl.cairo", -// [1539470638642759296633, 21332, 18, -// 1967013752834806001269811315755539563695215919214241724661593146835538551452]).contract_address -// context.supertoken_2 = deploy_contract("./src/tokens/ERC20x/SuperToken/SuperTokenImpl.cairo", -// [1539470638642759296633, 21332, 18, -// 1967013752834806001269811315755539563695215919214241724661593146835538551452]).contract_address -// context.aqueduct = deploy_contract("./src/examples/aqueduct/AqueductImpl.cairo", [context.supertoken_1, -// context.supertoken_2]).contract_address -// %} -// return (); -// } - -// @external -// func _flowWithCallback{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( -// token: felt, _from: felt, rate: felt -// ) { -// tempvar aqueduct; -// %{ ids.aqueduct = context.aqueduct %} - -// %{ stop_prank_callable = start_prank(ids._from, ids.token) %} -// let (oldRate) = ISuperToken.getFlowRate( -// contract_address=token, _from=_from, to=aqueduct, flowId=0 -// ); -// ISuperToken.flow( -// contract_address=token, -// senderAddress=_from, -// receiverAddress=aqueduct, -// flowId=0, -// flowRate=rate, -// ); -// IAqueduct.onFlowUpdate( -// contract_address=aqueduct, token=token, _from=_from, ir0=oldRate, ir1=rate -// ); -// %{ stop_prank_callable() %} -// return (); -// } - -// @external -// func setup_1lp_bootstrap{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { -// %{ -// given( -// r1 = strategy.felts(), # first rate -// r2 = strategy.felts(), # second rate -// t1 = strategy.integers(1, 1000), # time -// ) -// %} -// return (); -// } - -// @external -// func test_1lp_bootstrap{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( -// r1: felt, r2: felt, t1: felt -// ) { -// return (); -// } diff --git a/packages/starknet-contracts/tests/test_aqueduct_library.cairo b/packages/starknet-contracts/tests/test_aqueduct_library.cairo deleted file mode 100644 index b6253c7514..0000000000 --- a/packages/starknet-contracts/tests/test_aqueduct_library.cairo +++ /dev/null @@ -1,60 +0,0 @@ -%lang starknet - -from starkware.cairo.common.cairo_builtins import HashBuiltin -from starkware.cairo.common.math import unsigned_div_rem - -from src.examples.aqueduct.library import AqueductLibrary, Aqueduct - -@external -func setup_cal_new_flowrate_A{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - totalA = strategy.integers(1, 100000), # total A - totalB = strategy.integers(1, 100000), # total B - oldFlowRateB = strategy.integers(1, 500), # old flowrate B - newFlowRateB = strategy.integers(501, 1000), # new flowrate B - ) - %} - return (); -} - -@external -func test_cal_new_flowrate_A{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - totalA: felt, totalB: felt, oldFlowRateB: felt, newFlowRateB: felt -) { - let (newFlowRateA) = AqueductLibrary.cal_new_flowrate_A( - totalA, totalB, oldFlowRateB, newFlowRateB - ); - let (expected_newFlowRateA, _) = unsigned_div_rem( - totalA * newFlowRateB, (totalB + newFlowRateB) - oldFlowRateB - ); - assert newFlowRateA = expected_newFlowRateA; - return (); -} - -@external -func setup_cal_new_flowrate_B{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - totalA = strategy.integers(1, 100000), # total A - totalB = strategy.integers(1, 100000), # total B - oldFlowRateA = strategy.integers(1, 500), # old flowrate A - newFlowRateA = strategy.integers(501, 1000), # new flowrate A - ) - %} - return (); -} - -@external -func test_cal_new_flowrate_B{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - totalA: felt, totalB: felt, oldFlowRateA: felt, newFlowRateA: felt -) { - let (newFlowRateB) = AqueductLibrary.cal_new_flowrate_B( - totalA, totalB, oldFlowRateA, newFlowRateA - ); - let (expected_newFlowRateB, _) = unsigned_div_rem( - totalB * newFlowRateA, (totalA + newFlowRateA) - oldFlowRateA - ); - assert newFlowRateB = expected_newFlowRateB; - return (); -} diff --git a/packages/starknet-contracts/tests/test_mathlib.cairo b/packages/starknet-contracts/tests/test_mathlib.cairo deleted file mode 100644 index 72f44e1433..0000000000 --- a/packages/starknet-contracts/tests/test_mathlib.cairo +++ /dev/null @@ -1,25 +0,0 @@ -%lang starknet - -from starkware.cairo.common.cairo_builtins import HashBuiltin -from starkware.cairo.common.math import unsigned_div_rem - -from src.utils.MathLib import MathLib - - -@external -func setup_div{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - value = strategy.integers(-100000000000000000000000, 10000000000000000000000), - div = strategy.integers(1, 1000000000000000000) - ) - %} - return (); -} - -@external -func test_div{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(value: felt, div: felt) { - %{ assume(ids.value > 0) %} - MathLib.div(value, div); - return (); -} diff --git a/packages/starknet-contracts/tests/test_semantic_money.cairo b/packages/starknet-contracts/tests/test_semantic_money.cairo deleted file mode 100644 index 49cc66de4e..0000000000 --- a/packages/starknet-contracts/tests/test_semantic_money.cairo +++ /dev/null @@ -1,829 +0,0 @@ -%lang starknet - -from starkware.cairo.common.cairo_builtins import HashBuiltin -from starkware.cairo.common.math import unsigned_div_rem - -from src.utils.SemanticMoney import ( - SemanticMoney, - BasicParticle, - PDPoolIndex, - PDPoolMember, - PDPoolMemberMU, -) - -@external -func test_m_append{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - // If `_settled_at` of b of greater - let a = BasicParticle(5, 10, 10); - let b = BasicParticle(10, 10, 10); - let (newBasicParticle) = SemanticMoney.mappend(a, b); - assert newBasicParticle._flow_rate = 20; - assert newBasicParticle._settled_at = 10; - assert newBasicParticle._settled_value = 70; - - // if `_settled_at` of a and b are same - let a = BasicParticle(10, 10, 10); - let b = BasicParticle(10, 10, 10); - let (newBasicParticle) = SemanticMoney.mappend(a, b); - assert newBasicParticle._flow_rate = 20; - assert newBasicParticle._settled_at = 10; - assert newBasicParticle._settled_value = 20; - - // if `_settled_at` of a of greater - let a = BasicParticle(20, 10, 10); - let b = BasicParticle(10, 10, 10); - let (newBasicParticle) = SemanticMoney.mappend(a, b); - assert newBasicParticle._flow_rate = 20; - assert newBasicParticle._settled_at = 20; - assert newBasicParticle._settled_value = 120; - - let (_newBasicParticle) = SemanticMoney.mappend(b, newBasicParticle); - assert _newBasicParticle._flow_rate = 30; - assert _newBasicParticle._settled_at = 20; - assert _newBasicParticle._settled_value = 230; - return (); -} - -@external -func setup_flowrate_quotrem_unit{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - r = strategy.felts(), - u = strategy.integers(0, 1000), - ) - %} - return (); -} - -@external -func test_flowrate_quotrem_unit{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(r: felt, u: felt) { - %{ assume(ids.u != 0) %} - %{ assume(ids.r <= 3402823669209384634633746074317682114) %} - let (q, e) = unsigned_div_rem(r, u); - assert (q * u) + e = r; - return (); -} - -@external -func setup_distributive_law{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - x = strategy.felts(), - u1 = strategy.integers(0, 1000), - u2 = strategy.integers(0, 1000), - ) - %} - return (); -} - -@external -func test_distributive_law{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(x: felt, u1: felt, u2: felt) { - assert (x * u1) + (x * u2) = x * (u1 + u2); - return (); -} - -@external -func setup_u_monoid_identity{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - _settled_at = strategy.integers(0, 1000), - _settled_value = strategy.integers(0, 1000), - _flow_rate = strategy.felts(), - ) - %} - return (); -} - -@external -func test_u_monoid_identity{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(_settled_at: felt, _settled_value: felt, _flow_rate: felt) { - alloc_locals; - let p1 = BasicParticle(_settled_at, _settled_value, _flow_rate); - let ep = BasicParticle(0, 0, 0); - let (p2) = SemanticMoney.mappend(ep, p1); - assert p2 = p1; - let (p3) = SemanticMoney.mappend(p1, ep); - assert p3 = p1; - return (); -} - -@external -func setup_u_monoid_assoc{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - _settled_at_1 = strategy.integers(0, 1000), - _settled_value_1 = strategy.integers(0, 1000), - _flow_rate_1 = strategy.felts(), - _settled_at_2 = strategy.integers(0, 1000), - _settled_value_2 = strategy.integers(0, 1000), - _flow_rate_2 = strategy.felts(), - _settled_at_3 = strategy.integers(0, 1000), - _settled_value_3 = strategy.integers(0, 1000), - _flow_rate_3 = strategy.felts(), - ) - %} - return (); -} - -@external -func test_u_monoid_assoc{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(_settled_at_1: felt, _settled_value_1: felt, _flow_rate_1: felt, _settled_at_2: felt, _settled_value_2: felt, _flow_rate_2: felt, _settled_at_3: felt, _settled_value_3: felt, _flow_rate_3: felt) { - alloc_locals; - let p1 = BasicParticle(_settled_at_1, _settled_value_1, _flow_rate_1); - let p2 = BasicParticle(_settled_at_2, _settled_value_2, _flow_rate_2); - let p3 = BasicParticle(_settled_at_3, _settled_value_3, _flow_rate_3); - let (p1_and_p2) = SemanticMoney.mappend(p1, p2); - let (agg1) = SemanticMoney.mappend(p1_and_p2, p3); - let (p2_and_p3) = SemanticMoney.mappend(p2, p3); - let (agg2) = SemanticMoney.mappend(p2_and_p3, p1); - assert agg1 = agg2; - return (); -} - -@external -func setup_u_settle_idempotence{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - _settled_at = strategy.integers(0, 1000), - _settled_value = strategy.integers(0, 1000), - _flow_rate = strategy.felts(), - time = strategy.integers(1, 1000), - ) - %} - return (); -} - -@external -func test_u_settle_idempotence{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(_settled_at: felt, _settled_value: felt, _flow_rate: felt, time: felt) { - alloc_locals; - let p = BasicParticle(_settled_at, _settled_value, _flow_rate); - let (settled_at) = SemanticMoney.settled_at(p); - let t1 = settled_at + time; - let (p1) = SemanticMoney.settle(p, t1); - let (p2) = SemanticMoney.settle(p1, t1); - assert p1._settled_at = t1; - assert p1 = p2; - return (); -} - -@external -func setup_u_constant_rtb{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - _settled_at = strategy.integers(0, 1000), - _settled_value = strategy.integers(0, 1000), - _flow_rate = strategy.felts(), - m1 = strategy.integers(1, 1000), - m2 = strategy.integers(1, 1000), - m3 = strategy.integers(1, 1000), - ) - %} - return (); -} - -@external -func test_u_constant_rtb{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(_settled_at: felt, _settled_value: felt, _flow_rate: felt, m1: felt, m2: felt, m3: felt) { - alloc_locals; - let p = BasicParticle(_settled_at, _settled_value, _flow_rate); - let (settled_at) = SemanticMoney.settled_at(p); - let t1 = settled_at + m1; - let t2 = t1 + m2; - let t3 = t2 + m3; - let (settle_p_at_t1) = SemanticMoney.settle(p, t1); - let (settle_p_at_t2) = SemanticMoney.settle(p, t2); - let (rtb_of_settle_p_at_t1_at_t3) = SemanticMoney.realtime_balance_of(settle_p_at_t1, t3); - let (rtb_of_settle_p_at_t2_at_t3) = SemanticMoney.realtime_balance_of(settle_p_at_t2, t3); - let (rtb_of_p_at_t3) = SemanticMoney.realtime_balance_of(p, t3); - assert rtb_of_settle_p_at_t1_at_t3 = rtb_of_p_at_t3; - assert rtb_of_settle_p_at_t2_at_t3 = rtb_of_p_at_t3; - let (settle_p_at_t1_at_t2) = SemanticMoney.settle(settle_p_at_t1, t2); - let (rtb_of_settle_p_at_t1_at_t2_at_t3) = SemanticMoney.realtime_balance_of(settle_p_at_t1_at_t2, t3); - assert rtb_of_settle_p_at_t1_at_t2_at_t3 = rtb_of_p_at_t3; - return (); -} - -@external -func setup_realtime_balance_of{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - fr = strategy.felts(), # flow rate - sv = strategy.felts(), # settled value - t1 = strategy.integers(0, 100), # time 1 - t2 = strategy.integers(101, 200), # time 2 - t3 = strategy.integers(201, 300), # time 3 - t4 = strategy.integers(301, 400), # time 4 - ) - %} - return (); -} - -@external -func test_realtime_balance_of{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - fr: felt, sv: felt, t1: felt, t2: felt, t3: felt, t4: felt -) { - let u_index = BasicParticle(t1, sv, fr); - - let (balance) = SemanticMoney.realtime_balance_of(u_index, t2); - assert balance = ((t2 - t1) * fr) + sv; - - let (balance) = SemanticMoney.realtime_balance_of(u_index, t3); - assert balance = ((t3 - t1) * fr) + sv; - - let (balance) = SemanticMoney.realtime_balance_of(u_index, t4); - assert balance = ((t4 - t1) * fr) + sv; - - return (); -} - -@external -func setup_realtime_balance_of_pool_member_mu{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr -}() { - %{ - given( - tu = strategy.felts(), # total unit - ou = strategy.felts(), # owned unit - fr = strategy.felts(), # flow rate - sv_wrapped = strategy.felts(), # settled value in wrapped particle - sv_synced = strategy.felts(), # settled value in synced particle - sv_for_member = strategy.felts(), # settled value for pd member - t1 = strategy.integers(1, 100), # time 1 - t2 = strategy.integers(101, 200), # time 2 - t3 = strategy.integers(201, 300), # time 3 - t4 = strategy.integers(301, 400), # time 4 - ) - %} - return (); -} - -@external -func test_realtime_balance_of_pool_member_mu{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr -}( - tu: felt, - ou: felt, - fr: felt, - sv_wrapped: felt, - sv_synced: felt, - sv_for_member: felt, - t1: felt, - t2: felt, - t3: felt, - t4: felt, -) { - let pdPoolIndex = PDPoolIndex(tu, BasicParticle(t1, sv_wrapped, fr)); - let pdPoolMember = PDPoolMember(ou, sv_for_member, BasicParticle(t1, sv_synced, fr)); - let pdPoolMemberMU = PDPoolMemberMU(pdPoolIndex, pdPoolMember); - let (balance_for_wrapped_particle) = SemanticMoney.realtime_balance_of( - BasicParticle(t1, sv_wrapped, fr), t2 - ); - let (balance_for_synced_particle) = SemanticMoney.realtime_balance_of( - BasicParticle(t1, sv_synced, fr), t1 - ); - let (balance) = SemanticMoney.realtime_balance_of_pool_member_mu(pdPoolMemberMU, t2); - assert balance = ((balance_for_wrapped_particle - balance_for_synced_particle) * ou) + - sv_for_member; - - let pdPoolIndex = PDPoolIndex(tu, BasicParticle(t2, sv_wrapped, fr)); - let pdPoolMember = PDPoolMember(ou, sv_for_member, BasicParticle(t2, sv_synced, fr)); - let pdPoolMemberMU = PDPoolMemberMU(pdPoolIndex, pdPoolMember); - let (balance_for_wrapped_particle) = SemanticMoney.realtime_balance_of( - BasicParticle(t2, sv_wrapped, fr), t3 - ); - let (balance_for_synced_particle) = SemanticMoney.realtime_balance_of( - BasicParticle(t2, sv_synced, fr), t2 - ); - let (balance) = SemanticMoney.realtime_balance_of_pool_member_mu(pdPoolMemberMU, t3); - assert balance = ((balance_for_wrapped_particle - balance_for_synced_particle) * ou) + - sv_for_member; - - let pdPoolIndex = PDPoolIndex(tu, BasicParticle(t3, sv_wrapped, fr)); - let pdPoolMember = PDPoolMember(ou, sv_for_member, BasicParticle(t3, sv_synced, fr)); - let pdPoolMemberMU = PDPoolMemberMU(pdPoolIndex, pdPoolMember); - let (balance_for_wrapped_particle) = SemanticMoney.realtime_balance_of( - BasicParticle(t3, sv_wrapped, fr), t4 - ); - let (balance_for_synced_particle) = SemanticMoney.realtime_balance_of( - BasicParticle(t3, sv_synced, fr), t3 - ); - let (balance) = SemanticMoney.realtime_balance_of_pool_member_mu(pdPoolMemberMU, t4); - assert balance = ((balance_for_wrapped_particle - balance_for_synced_particle) * ou) + - sv_for_member; - return (); -} - -@external -func setup_settle{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - fr = strategy.felts(), # flow rate - sv = strategy.felts(), # settled value - t1 = strategy.integers(1, 100), # time 1 - t2 = strategy.integers(101, 200), # time 2 - ) - %} - return (); -} - -@external -func test_settle{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - fr: felt, sv: felt, t1: felt, t2: felt -) { - let index = BasicParticle(t1, sv, fr); - let (newIndex) = SemanticMoney.settle(index, t2); - assert newIndex._settled_value = ((t2 - t1) * fr) + sv; - assert newIndex._settled_at = t2; - return (); -} - -@external -func setup_settle_for_pool_index{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - ) { - %{ - given( - tu = strategy.felts(), # total unit - ou = strategy.felts(), # owned unit - fr = strategy.felts(), # flow rate - sv = strategy.felts(), # settled value in wrapped particle - t1 = strategy.integers(1, 100), # time 1 - t2 = strategy.integers(101, 200), # time 2 - t3 = strategy.integers(201, 300), # time 3 - t4 = strategy.integers(301, 400), # time 4 - ) - %} - return (); -} - -@external -func test_settle_for_pool_index{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - tu: felt, ou: felt, fr: felt, sv: felt, t1: felt, t2: felt, t3: felt, t4: felt -) { - let poolIndex = PDPoolIndex(tu, BasicParticle(t1, sv, fr)); - let (settled_pool_index) = SemanticMoney.settle_for_pool_index(poolIndex, t2); - assert settled_pool_index._wrapped_particle._settled_at = t2; - assert settled_pool_index._wrapped_particle._settled_value = ((t2 - t1) * fr) + sv; - - let (_settled_pool_index) = SemanticMoney.settle_for_pool_index(settled_pool_index, t3); - assert _settled_pool_index._wrapped_particle._settled_at = t3; - assert _settled_pool_index._wrapped_particle._settled_value = ((t3 - t2) * fr) + ( - ((t2 - t1) * fr) + sv - ); - - let (__settled_pool_index) = SemanticMoney.settle_for_pool_index(_settled_pool_index, t4); - assert __settled_pool_index._wrapped_particle._settled_at = t4; - assert __settled_pool_index._wrapped_particle._settled_value = ((t4 - t3) * fr) + ( - (t3 - t2) * fr - ) + (((t2 - t1) * fr) + sv); - return (); -} - -@external -func setup_settle_for_pool_member_mu{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr -}() { - %{ - given( - tu = strategy.felts(), # total unit - ou = strategy.felts(), # owned unit - fr = strategy.felts(), # flow rate - sv_wrapped = strategy.felts(), # settled value in wrapped particle - sv_synced = strategy.felts(), # settled value in synced particle - sv_for_member = strategy.felts(), # settled value for pd member - t1 = strategy.integers(1, 100), # time 1 - t2 = strategy.integers(101, 200), # time 2 - ) - %} - return (); -} - -@external -func test_settle_for_pool_member_mu{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr -}( - tu: felt, - ou: felt, - fr: felt, - sv_wrapped: felt, - sv_synced: felt, - sv_for_member: felt, - t1: felt, - t2: felt, -) { - let poolIndex = PDPoolIndex(tu, BasicParticle(t1, sv_wrapped, fr)); - let poolMember = PDPoolMember(ou, sv_for_member, BasicParticle(t1, sv_synced, fr)); - let poolMemberMU = PDPoolMemberMU(poolIndex, poolMember); - let (settled_poolMemberMU) = SemanticMoney.settle_for_pool_member_mu(poolMemberMU, t2); - - assert settled_poolMemberMU.pdPoolIndex._wrapped_particle._settled_at = t2; - assert settled_poolMemberMU.pdPoolIndex._wrapped_particle._settled_value = ((t2 - t1) * fr) + - sv_wrapped; - assert settled_poolMemberMU.pdPoolMember._synced_particle._settled_at = settled_poolMemberMU.pdPoolIndex._wrapped_particle._settled_at; - assert settled_poolMemberMU.pdPoolMember._synced_particle._settled_value = settled_poolMemberMU.pdPoolIndex._wrapped_particle._settled_value; - let (balanceOfPDMemberMU) = SemanticMoney.realtime_balance_of_pool_member_mu(poolMemberMU, t2); - assert settled_poolMemberMU.pdPoolMember._settled_value = balanceOfPDMemberMU; - return (); -} - -@external -func setup_shift1{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - fr = strategy.felts(), # flow rate - sv = strategy.felts(), # settled value - amount = strategy.felts(), - t1 = strategy.integers(0, 100), # time 1 - ) - %} - return (); -} - -@external -func test_shift1{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - fr: felt, sv: felt, amount: felt, t1: felt -) { - let index = BasicParticle(t1, sv, fr); - let (newIndex, _amount) = SemanticMoney.shift1(amount, index); - assert newIndex._settled_value = amount + sv; - assert _amount = amount; - return (); -} - -@external -func setup_shift2{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - fr = strategy.felts(), # flow rate - amount = strategy.felts(), - t1 = strategy.integers(0, 100), # time 1 - ) - %} - return (); -} - -@external -func test_shift2{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - fr: felt, amount: felt, t1: felt -) { - let aIndex = BasicParticle(0, 0, 0); - let bIndex = BasicParticle(0, 0, 0); - let (_aIndex, _bIndex) = SemanticMoney.shift2(aIndex, bIndex, amount); - assert _aIndex._settled_value = (((t1 - _aIndex._settled_at) * _aIndex._flow_rate) + 0) - - amount; - assert _bIndex._settled_value = (((t1 - _bIndex._settled_at) * _bIndex._flow_rate) + 0) + - amount; - assert _aIndex._settled_value + _bIndex._settled_value = 0; - return (); -} - -@external -func setup_flow1{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - fr = strategy.felts(), # flow rate - sv = strategy.felts(), # settled value - fr_1 = strategy.felts(), # new flow rate - t1 = strategy.integers(0, 100), # time - ) - %} - return (); -} - -@external -func test_flow1{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - fr: felt, sv: felt, fr_1: felt, t1: felt -) { - let index = BasicParticle(t1, sv, fr); - let (newIndex, _) = SemanticMoney.flow1(fr_1, index); - assert newIndex._flow_rate = fr_1; - return (); -} - -@external -func setup_flow2{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - fr_1 = strategy.felts(), # flow rate for sender - t1 = strategy.integers(0, 100), # time 1 - t2 = strategy.integers(101, 200), # time 2 - ) - %} - return (); -} - -@external -func test_flow2{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - fr_1: felt, t1: felt, t2: felt -) { - let aIndex = BasicParticle(0, 0, 0); - let bIndex = BasicParticle(0, 0, 0); - let (_aIndex, _bIndex) = SemanticMoney.flow2(aIndex, bIndex, fr_1, t1); - assert _aIndex._flow_rate = -fr_1; - assert _bIndex._flow_rate = fr_1; - - let (balance_for_sender_particle) = SemanticMoney.realtime_balance_of(_aIndex, t2); - let (balance_for_receiver_particle) = SemanticMoney.realtime_balance_of(_bIndex, t2); - assert balance_for_sender_particle + balance_for_receiver_particle = 0; - return (); -} - -@external -func setup_shiftFlow2{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - fr1 = strategy.felts(), # flow rate - fr2 = strategy.felts(), # flow rate - fr3 = strategy.felts(), # flow rate - sv1 = strategy.felts(), # settled value - sv2 = strategy.felts(), # settled value - t1 = strategy.integers(0, 100), # time - t2 = strategy.integers(101, 200), # time - t3 = strategy.integers(201, 300), # time - ) - %} - return (); -} - -@external -func test_shiftFlow2{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - fr1: felt, fr2: felt, fr3: felt, sv1: felt, sv2: felt, t1: felt, t2: felt, t3: felt -) { - let aIndex = BasicParticle(t1, sv1, fr1); - let bIndex = BasicParticle(t2, sv2, fr2); - let (newAIndex, newBIndex) = SemanticMoney.shiftFlow2(aIndex, bIndex, fr3, t3); - assert newAIndex._flow_rate = fr1 - fr3; - assert newBIndex._flow_rate = fr2 + fr3; - return (); -} - -@external -func setup_flow2_pd{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - ou_1 = strategy.integers(1, 100), # owned unit for first pd member, - ou_2 = strategy.integers(1, 100), # owned unit for second pd member, - fr = strategy.felts(), # default flow rate - t1 = strategy.integers(1, 100), # time 1 - t2 = strategy.integers(101, 200), # time 2 - t3 = strategy.integers(201, 300), # time 3 - t4 = strategy.integers(301, 400), # time 4 - t5 = strategy.integers(401, 500), # time 5 - t6 = strategy.integers(501, 600), # time 6 - t7 = strategy.integers(601, 700), # time 7 - ) - %} - return (); -} - -@external -func test_flow2_pd{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - ou_1: felt, - ou_2: felt, - fr: felt, - t1: felt, - t2: felt, - t3: felt, - t4: felt, - t5: felt, - t6: felt, - t7: felt, -) { - alloc_locals; - %{ assume(ids.fr * (ids.ou_1 + ids.ou_2) <= 10000000000000000000000000000000000000000) %} - - let u_index = BasicParticle(0, 0, 0); - let p_index = PDPoolIndex(0, BasicParticle(0, 0, 0)); - let pool_member_1 = PDPoolMember(0, 0, BasicParticle(0, 0, 0)); - let pool_member_mu = PDPoolMemberMU(p_index, pool_member_1); - - let (p_index, pool_member_1, u_index) = SemanticMoney.pool_member_update( - pool_member_mu, u_index, ou_1, t1 - ); - - let (_u_index, _p_index, actualFlowRate) = SemanticMoney.flow2_pd(u_index, p_index, fr, t2); - assert _u_index._flow_rate = -actualFlowRate; - assert _p_index._wrapped_particle._flow_rate = actualFlowRate / _p_index.total_units; // Per Unit - assert _u_index._settled_at = t2; - assert _p_index._wrapped_particle._settled_at = t2; - - let pool_member_mu = PDPoolMemberMU(_p_index, pool_member_1); - let (realtime_balance_of_pool_member_mu_1) = SemanticMoney.realtime_balance_of_pool_member_mu( - pool_member_mu, t4 - ); - let (balance_for_wrapped_particle) = SemanticMoney.realtime_balance_of( - _p_index._wrapped_particle, t4 - ); - let (balance_for_synced_particle) = SemanticMoney.realtime_balance_of( - pool_member_1._synced_particle, t2 - ); - assert realtime_balance_of_pool_member_mu_1 = ( - (balance_for_wrapped_particle - balance_for_synced_particle) * ou_1 - ) + pool_member_1._settled_value; - - let pool_member_2 = PDPoolMember(0, 0, BasicParticle(0, 0, 0)); - let pool_member_mu = PDPoolMemberMU(_p_index, pool_member_2); - let (p_index, pool_member_2, u_index) = SemanticMoney.pool_member_update( - pool_member_mu, _u_index, ou_2, t6 - ); - - let pool_member_mu = PDPoolMemberMU(p_index, pool_member_2); - let (realtime_balance_of_pool_member_mu_2) = SemanticMoney.realtime_balance_of_pool_member_mu( - pool_member_mu, t7 - ); - let (balance_for_wrapped_particle) = SemanticMoney.realtime_balance_of( - p_index._wrapped_particle, t7 - ); - let (balance_for_synced_particle) = SemanticMoney.realtime_balance_of( - pool_member_2._synced_particle, t6 - ); - assert realtime_balance_of_pool_member_mu_2 = ( - (balance_for_wrapped_particle - balance_for_synced_particle) * ou_2 - ) + pool_member_2._settled_value; - - let pool_member_mu = PDPoolMemberMU(p_index, pool_member_1); - let (realtime_balance_of_pool_member_mu_1) = SemanticMoney.realtime_balance_of_pool_member_mu( - pool_member_mu, t7 - ); - let (balance_for_wrapped_particle) = SemanticMoney.realtime_balance_of( - p_index._wrapped_particle, t7 - ); - let (balance_for_synced_particle) = SemanticMoney.realtime_balance_of( - pool_member_1._synced_particle, t2 - ); - assert realtime_balance_of_pool_member_mu_1 = ( - (balance_for_wrapped_particle - balance_for_synced_particle) * ou_1 - ) + pool_member_1._settled_value; - - let (realtime_balance_of_u_index) = SemanticMoney.realtime_balance_of(u_index, t7); - assert realtime_balance_of_u_index + realtime_balance_of_pool_member_mu_1 + - realtime_balance_of_pool_member_mu_2 = 0; - return (); -} - -@external -func setup_shifFlow2_pd{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - tu = strategy.integers(1, 1000), # time - fr = strategy.felts(), # flow rate - t = strategy.integers(0, 100), # time - ) - %} - return (); -} - -@external -func test_shifFlow2_pd{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - tu: felt, fr: felt, t: felt -) { - alloc_locals; - %{ assume(ids.fr * ids.tu <= 10000000000000000000000000000000000000000) %} - let u_index = BasicParticle(0, 0, 0); - let p_index = PDPoolIndex(tu, BasicParticle(0, 0, 0)); - let (_u_index, _p_index, actualFlowRate) = SemanticMoney.shiftFlow_pd(u_index, p_index, fr, t); - assert _u_index._flow_rate = 0 - actualFlowRate; - assert _p_index._wrapped_particle._flow_rate = 0 + (actualFlowRate / tu); - return (); -} - -@external -func setup_shift2_pd{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - ou_1 = strategy.integers(1, 100), # owned unit for first pd member, - ou_2 = strategy.integers(1, 100), # owned unit for second pd member, - fr = strategy.felts(), # default flow rate - amount = strategy.felts(), # flow rate of flow, - t1 = strategy.integers(1, 100), # time 1 - t2 = strategy.integers(101, 200), # time 2 - t3 = strategy.integers(201, 300), # time 3 - t4 = strategy.integers(301, 400), # time 4 - t5 = strategy.integers(401, 500), # time 5 - t6 = strategy.integers(501, 600), # time 6 - t7 = strategy.integers(601, 700), # time 7 - ) - %} - return (); -} - -@external -func test_shift2_pd{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - ou_1: felt, - ou_2: felt, - fr: felt, - amount: felt, - t1: felt, - t2: felt, - t3: felt, - t4: felt, - t5: felt, - t6: felt, - t7: felt, -) { - alloc_locals; - %{ assume(ids.fr <= 10000000000000000000000000000000000) %} - %{ assume(ids.amount * (ids.ou_1 + ids.ou_2) <= 10000000000000000000000000000000000000000000) %} - - let u_index = BasicParticle(0, 0, 0); - let p_index = PDPoolIndex(0, BasicParticle(0, 0, 0)); - let pool_member_1 = PDPoolMember(0, 0, BasicParticle(0, 0, 0)); - let pool_member_mu = PDPoolMemberMU(p_index, pool_member_1); - - let (p_index, pool_member_1, u_index) = SemanticMoney.pool_member_update( - pool_member_mu, u_index, ou_1, t1 - ); - - let (_u_index, _p_index, actualAmount) = SemanticMoney.shift2_pd(u_index, p_index, amount); - assert _u_index._settled_value = (((t2 - t1) * u_index._flow_rate) + u_index._settled_value) - - actualAmount; - assert _p_index._wrapped_particle._settled_value = ( - ((t2 - t1) * p_index._wrapped_particle._flow_rate) + - p_index._wrapped_particle._settled_value - ) + (actualAmount / p_index.total_units); // Per Unit - - let pool_member_mu = PDPoolMemberMU(_p_index, pool_member_1); - let (realtime_balance_of_pool_member_mu_1) = SemanticMoney.realtime_balance_of_pool_member_mu( - pool_member_mu, t3 - ); - let (balance_for_wrapped_particle) = SemanticMoney.realtime_balance_of( - _p_index._wrapped_particle, t3 - ); - let (balance_for_synced_particle) = SemanticMoney.realtime_balance_of( - pool_member_1._synced_particle, t2 - ); - assert realtime_balance_of_pool_member_mu_1 = ( - (balance_for_wrapped_particle - balance_for_synced_particle) * ou_1 - ) + pool_member_1._settled_value; - - let pool_member_2 = PDPoolMember(0, 0, BasicParticle(0, 0, 0)); - let pool_member_mu = PDPoolMemberMU(_p_index, pool_member_2); - let (p_index, pool_member_2, u_index) = SemanticMoney.pool_member_update( - pool_member_mu, _u_index, ou_2, t4 - ); - - let pool_member_mu = PDPoolMemberMU(p_index, pool_member_2); - let (realtime_balance_of_pool_member_mu_2) = SemanticMoney.realtime_balance_of_pool_member_mu( - pool_member_mu, t5 - ); - let (balance_for_wrapped_particle) = SemanticMoney.realtime_balance_of( - p_index._wrapped_particle, t5 - ); - let (balance_for_synced_particle) = SemanticMoney.realtime_balance_of( - pool_member_2._synced_particle, t4 - ); - assert realtime_balance_of_pool_member_mu_2 = ( - (balance_for_wrapped_particle - balance_for_synced_particle) * ou_2 - ) + pool_member_2._settled_value; - - let pool_member_mu = PDPoolMemberMU(p_index, pool_member_1); - let (realtime_balance_of_pool_member_mu_1) = SemanticMoney.realtime_balance_of_pool_member_mu( - pool_member_mu, t5 - ); - let (balance_for_wrapped_particle) = SemanticMoney.realtime_balance_of( - p_index._wrapped_particle, t5 - ); - let (balance_for_synced_particle) = SemanticMoney.realtime_balance_of( - pool_member_1._synced_particle, t2 - ); - assert realtime_balance_of_pool_member_mu_1 = ( - (balance_for_wrapped_particle - balance_for_synced_particle) * ou_1 - ) + pool_member_1._settled_value; - - let (_u_index, _p_index, actualAmount) = SemanticMoney.shift2_pd(u_index, p_index, amount); - assert _u_index._settled_value = (((t6 - t4) * u_index._flow_rate) + u_index._settled_value) - - actualAmount; - assert _p_index._wrapped_particle._settled_value = ( - ((t6 - t4) * p_index._wrapped_particle._flow_rate) + - p_index._wrapped_particle._settled_value - ) + (actualAmount / p_index.total_units); // Per Unit - - let pool_member_mu = PDPoolMemberMU(_p_index, pool_member_2); - let (realtime_balance_of_pool_member_mu_2) = SemanticMoney.realtime_balance_of_pool_member_mu( - pool_member_mu, t7 - ); - let (balance_for_wrapped_particle) = SemanticMoney.realtime_balance_of( - _p_index._wrapped_particle, t7 - ); - let (balance_for_synced_particle) = SemanticMoney.realtime_balance_of( - pool_member_2._synced_particle, t4 - ); - assert realtime_balance_of_pool_member_mu_2 = ( - (balance_for_wrapped_particle - balance_for_synced_particle) * ou_2 - ) + pool_member_2._settled_value; - - let pool_member_mu = PDPoolMemberMU(_p_index, pool_member_1); - let (realtime_balance_of_pool_member_mu_1) = SemanticMoney.realtime_balance_of_pool_member_mu( - pool_member_mu, t7 - ); - let (balance_for_wrapped_particle) = SemanticMoney.realtime_balance_of( - _p_index._wrapped_particle, t7 - ); - let (balance_for_synced_particle) = SemanticMoney.realtime_balance_of( - pool_member_1._synced_particle, t2 - ); - assert realtime_balance_of_pool_member_mu_1 = ( - (balance_for_wrapped_particle - balance_for_synced_particle) * ou_1 - ) + pool_member_1._settled_value; - - let (realtime_balance_of_u_index) = SemanticMoney.realtime_balance_of(_u_index, t7); - assert realtime_balance_of_u_index + realtime_balance_of_pool_member_mu_1 + - realtime_balance_of_pool_member_mu_2 = 0; - return (); -} diff --git a/packages/starknet-contracts/tests/test_super_token.cairo b/packages/starknet-contracts/tests/test_super_token.cairo deleted file mode 100644 index 2dbc408c36..0000000000 --- a/packages/starknet-contracts/tests/test_super_token.cairo +++ /dev/null @@ -1,1616 +0,0 @@ -%lang starknet - -from starkware.cairo.common.cairo_builtins import HashBuiltin -from starkware.starknet.common.syscalls import ( - get_caller_address, - get_contract_address, - get_block_timestamp, - get_tx_info, -) -from starkware.cairo.common.math import unsigned_div_rem -from starkware.cairo.common.bool import TRUE, FALSE -from starkware.cairo.common.alloc import alloc - -from src.tokens.ERC20x.SuperToken.library import SuperToken -from src.utils.SemanticMoney import ( - SemanticMoney, - BasicParticle, - PDPoolIndex, - PDPoolMember, - PDPoolMemberMU, -) -from src.utils.account.ITestAccount import ITestAccount -from src.utils.account.library import Call -from src.interfaces.ISuperfluidToken import ISuperfluidToken -from src.interfaces.ISuperfluidPool import ISuperfluidPool, ISuperfluidPoolOperator - -from protostar.asserts import ( - assert_eq, - assert_not_eq, - assert_signed_lt, - assert_signed_le, - assert_signed_gt, - assert_unsigned_lt, - assert_unsigned_le, - assert_unsigned_gt, - assert_signed_ge, - assert_unsigned_ge, -) - -@external -func __setup__{syscall_ptr: felt*}() { - %{ - declare("./src/pools/PoolImpl.cairo") - context.test_account_address1 = deploy_contract("./src/utils/account/TestAccountImpl.cairo").contract_address - context.test_account_address2 = deploy_contract("./src/utils/account/TestAccountImpl.cairo").contract_address - context.supertoken_contract_address = deploy_contract("./src/tokens/ERC20x/SuperToken/SuperTokenImpl.cairo", [1539470638642759296633, 21332, 18, 3600748221340956293245257266815110776189556141392786261445796616585040799092]).contract_address - context.MINT_AMOUNT = 1000000000000000000 - context.LIQUIDATION_PERIOD = 1000 - %} - return (); -} - - -func _createPool{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(by: felt) -> (pool: felt) { - tempvar supertoken_contract_address; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - %} - %{ stop_prank_callable = start_prank(ids.by, ids.supertoken_contract_address) %} - let (pool) = ISuperfluidToken.createPool(contract_address=supertoken_contract_address); - %{ stop_prank_callable() %} - return (pool=pool); -} - -func _connectPool{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(pool: felt, by: felt) { - alloc_locals; - tempvar supertoken_contract_address; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - %} - let (local calls: Call*) = alloc(); - let connectPoolSelector = 548208072097493527300120807205932284557878311980095480278893301204690846585; - assert [calls] = Call(supertoken_contract_address, connectPoolSelector); - - let (local calldata: felt*) = alloc(); - assert [calldata] = pool; - ITestAccount.execute(contract_address=by, calls_len=1, calls=calls, calldata_len=1, calldata=calldata); - return (); -} - -func _disconnectPool{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(pool: felt, by: felt) { - alloc_locals; - tempvar supertoken_contract_address; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - %} - let (local calls: Call*) = alloc(); - let disconnectPoolSelector = 28166688197912724383049707936424227093755017102822508708685168553869669375; - assert [calls] = Call(supertoken_contract_address, disconnectPoolSelector); - - let (local calldata: felt*) = alloc(); - assert [calldata] = pool; - ITestAccount.execute(contract_address=by, calls_len=1, calls=calls, calldata_len=1, calldata=calldata); - return (); -} - -func _getAdjustmentFlowRate{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(pool: felt, expectedRecipient: felt) -> (flowRate: felt) { - tempvar supertoken_contract_address; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - %} - let (recipient,_,flowRate) = ISuperfluidToken.getPoolAdjustmentFlowInfo(contract_address=supertoken_contract_address, pool=pool); - with_attr error_message("SuperToken Test: expectedRecipient fail") { - assert recipient = expectedRecipient; - } - return (flowRate=flowRate); -} - -@external -func setup_erc20_transfer{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - x1 = strategy.integers(1, 1000000), - x2 = strategy.integers(1, 1000000), - account1 = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - account2 = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - ) - %} - return (); -} - -@external -func test_erc20_transfer{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(x1: felt, x2: felt, account1: felt, account2: felt) { - %{ assume(ids.account1 != ids.account2) %} - tempvar supertoken_contract_address; - tempvar MINT_AMOUNT; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.MINT_AMOUNT = context.MINT_AMOUNT - %} - ISuperfluidToken.mint(contract_address=supertoken_contract_address, receiver=account1, amount=MINT_AMOUNT); - ISuperfluidToken.mint(contract_address=supertoken_contract_address, receiver=account2, amount=MINT_AMOUNT); - %{ stop_prank_callable = start_prank(ids.account1, ids.supertoken_contract_address) %} - ISuperfluidToken.transfer(contract_address=supertoken_contract_address, to=account2, amount=x1); - %{ stop_prank_callable() %} - %{ stop_prank_callable = start_prank(ids.account2, ids.supertoken_contract_address) %} - ISuperfluidToken.transfer(contract_address=supertoken_contract_address, to=account1, amount=x2); - %{ stop_prank_callable() %} - let (balanceOfAccount1) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=account1); - let (balanceOfAccount2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=account2); - assert balanceOfAccount1 = MINT_AMOUNT - x1 + x2; - assert balanceOfAccount2 = MINT_AMOUNT - x2 + x1; - return (); -} - -@external -func setup_erc20_self_transfer{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - x = strategy.integers(1, 1000000), - account = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - ) - %} - return (); -} - -@external -func test_erc20_self_transfer{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(x: felt, account: felt) { - tempvar supertoken_contract_address; - tempvar MINT_AMOUNT; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.MINT_AMOUNT = context.MINT_AMOUNT - %} - ISuperfluidToken.mint(contract_address=supertoken_contract_address, receiver=account, amount=MINT_AMOUNT); - %{ stop_prank_callable = start_prank(ids.account, ids.supertoken_contract_address) %} - ISuperfluidToken.transfer(contract_address=supertoken_contract_address, to=account, amount=x); - %{ stop_prank_callable() %} - let (balanceOfAccount) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=account); - assert balanceOfAccount = MINT_AMOUNT; - return (); -} - -@external -func setup_1to1_flow_update{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - fr1 = strategy.integers(1, 1000000), - fr2 = strategy.integers(1, 1000000), - account1 = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - account2 = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - dt1 = strategy.integers(1, 1000), - dt2 = strategy.integers(1, 1000) - ) - %} - return (); -} - -@external -func test_1to1_flow_update{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - fr1: felt, fr2: felt, account1: felt, account2: felt, dt1: felt, dt2: felt -) { - %{ assume(ids.account1 != ids.account2) %} - - tempvar supertoken_contract_address; - tempvar MINT_AMOUNT; - tempvar LIQUIDATION_PERIOD; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.MINT_AMOUNT = context.MINT_AMOUNT - ids.LIQUIDATION_PERIOD = context.LIQUIDATION_PERIOD - %} - - ISuperfluidToken.mint(contract_address=supertoken_contract_address, receiver=account1, amount=MINT_AMOUNT); - - let (netFlowRateOfAccount1) = ISuperfluidToken.getNetFlowRate( - contract_address=supertoken_contract_address, account=account1 - ); - let (netFlowRateOfAccount2) = ISuperfluidToken.getNetFlowRate( - contract_address=supertoken_contract_address, account=account2 - ); - - assert netFlowRateOfAccount1 = 0; - assert netFlowRateOfAccount2 = 0; - - let (flowRateOfAccount1andAccount2) = ISuperfluidToken.getFlowRate( - contract_address=supertoken_contract_address, _from=account1, to=account2, flowId=0 - ); - - assert flowRateOfAccount1andAccount2 = 0; - - %{ stop_prank_callable = start_prank(ids.account1, ids.supertoken_contract_address) %} - ISuperfluidToken.flow( - contract_address=supertoken_contract_address, - senderAddress=account1, - receiverAddress=account2, - flowId=0, - flowRate=fr1, - ); - %{ stop_prank_callable() %} - - let (netFlowRateOfAccount1) = ISuperfluidToken.getNetFlowRate( - contract_address=supertoken_contract_address, account=account1 - ); - let (netFlowRateOfAccount2) = ISuperfluidToken.getNetFlowRate( - contract_address=supertoken_contract_address, account=account2 - ); - - assert netFlowRateOfAccount1 = -fr1; - assert netFlowRateOfAccount2 = fr1; - - let (flowRateOfAccount1andAccount2) = ISuperfluidToken.getFlowRate( - contract_address=supertoken_contract_address, _from=account1, to=account2, flowId=0 - ); - - assert flowRateOfAccount1andAccount2 = fr1; - - let (timestamp) = get_block_timestamp(); - let t1 = timestamp + dt1; - let t2 = t1 + dt2; - %{ stop_warp = warp(ids.t1, ids.supertoken_contract_address) %} - let (balanceOfSender) = ISuperfluidToken.balanceOf( - contract_address=supertoken_contract_address, account=account1 - ); - let (balanceOfReceiver) = ISuperfluidToken.balanceOf( - contract_address=supertoken_contract_address, account=account2 - ); - let bufferAmount = LIQUIDATION_PERIOD * fr1; - assert balanceOfSender = MINT_AMOUNT - (fr1 * (t1 - timestamp)) - bufferAmount; - assert balanceOfReceiver = (fr1 * (t1 - timestamp)); - %{ stop_prank_callable = start_prank(ids.account1, ids.supertoken_contract_address) %} - ISuperfluidToken.flow( - contract_address=supertoken_contract_address, - senderAddress=account1, - receiverAddress=account2, - flowId=0, - flowRate=fr2, - ); - %{ stop_prank_callable() %} - - let (netFlowRateOfAccount1) = ISuperfluidToken.getNetFlowRate( - contract_address=supertoken_contract_address, account=account1 - ); - let (netFlowRateOfAccount2) = ISuperfluidToken.getNetFlowRate( - contract_address=supertoken_contract_address, account=account2 - ); - - assert netFlowRateOfAccount1 = -fr2; - assert netFlowRateOfAccount2 = fr2; - - let (flowRateOfAccount1andAccount2) = ISuperfluidToken.getFlowRate( - contract_address=supertoken_contract_address, _from=account1, to=account2, flowId=0 - ); - - assert flowRateOfAccount1andAccount2 = fr2; - - %{ stop_warp = warp(ids.t2, ids.supertoken_contract_address) %} - let (balanceOfSender_1) = ISuperfluidToken.balanceOf( - contract_address=supertoken_contract_address, account=account1 - ); - let (balanceOfReceiver_1) = ISuperfluidToken.balanceOf( - contract_address=supertoken_contract_address, account=account2 - ); - let newBufferAmount = LIQUIDATION_PERIOD * fr2; - let bufferDelta = newBufferAmount - bufferAmount; - assert balanceOfSender_1 = balanceOfSender - (fr2 * (t2 - t1)) - bufferDelta; - assert balanceOfReceiver_1 = balanceOfReceiver + (fr2 * (t2 - t1)); - %{ stop_warp() %} - return (); -} - -@external -func setup_1to2_flow{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - fr1 = strategy.integers(1, 100000000), - fr2 = strategy.integers(1, 100000000), - account1 = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - account2 = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - account3 = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - t1 = strategy.integers(1, 1000) - ) - %} - return (); -} - -@external -func test_1to2_flow{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - fr1: felt, fr2: felt, account1: felt, account2: felt, account3: felt, t1: felt -) { - %{ assume(ids.account1 != ids.account2) %} - %{ assume(ids.account1 != ids.account3) %} - %{ assume(ids.account2 != ids.account3) %} - - tempvar supertoken_contract_address; - tempvar MINT_AMOUNT; - tempvar LIQUIDATION_PERIOD; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.MINT_AMOUNT = context.MINT_AMOUNT - ids.LIQUIDATION_PERIOD = context.LIQUIDATION_PERIOD - %} - - ISuperfluidToken.mint(contract_address=supertoken_contract_address, receiver=account1, amount=MINT_AMOUNT); - - let (netFlowRateOfAccount1) = ISuperfluidToken.getNetFlowRate( - contract_address=supertoken_contract_address, account=account1 - ); - let (netFlowRateOfAccount2) = ISuperfluidToken.getNetFlowRate( - contract_address=supertoken_contract_address, account=account2 - ); - let (netFlowRateOfAccount3) = ISuperfluidToken.getNetFlowRate( - contract_address=supertoken_contract_address, account=account3 - ); - - assert netFlowRateOfAccount1 = 0; - assert netFlowRateOfAccount2 = 0; - assert netFlowRateOfAccount3 = 0; - - let (flowRateOfAccount1andAccount2) = ISuperfluidToken.getFlowRate( - contract_address=supertoken_contract_address, _from=account1, to=account2, flowId=0 - ); - let (flowRateOfAccount1andAccount3) = ISuperfluidToken.getFlowRate( - contract_address=supertoken_contract_address, _from=account1, to=account3, flowId=0 - ); - - assert flowRateOfAccount1andAccount2 = 0; - assert flowRateOfAccount1andAccount3 = 0; - - %{ stop_prank_callable = start_prank(ids.account1, ids.supertoken_contract_address) %} - ISuperfluidToken.flow( - contract_address=supertoken_contract_address, - senderAddress=account1, - receiverAddress=account2, - flowId=0, - flowRate=fr1, - ); - ISuperfluidToken.flow( - contract_address=supertoken_contract_address, - senderAddress=account1, - receiverAddress=account3, - flowId=0, - flowRate=fr2, - ); - %{ stop_prank_callable() %} - - let (netFlowRateOfAccount1) = ISuperfluidToken.getNetFlowRate( - contract_address=supertoken_contract_address, account=account1 - ); - let (netFlowRateOfAccount2) = ISuperfluidToken.getNetFlowRate( - contract_address=supertoken_contract_address, account=account2 - ); - let (netFlowRateOfAccount3) = ISuperfluidToken.getNetFlowRate( - contract_address=supertoken_contract_address, account=account3 - ); - - assert netFlowRateOfAccount1 = -(fr1 + fr2); - assert netFlowRateOfAccount2 = fr1; - assert netFlowRateOfAccount3 = fr2; - - let (flowRateOfAccount1andAccount2) = ISuperfluidToken.getFlowRate( - contract_address=supertoken_contract_address, _from=account1, to=account2, flowId=0 - ); - let (flowRateOfAccount1andAccount3) = ISuperfluidToken.getFlowRate( - contract_address=supertoken_contract_address, _from=account1, to=account3, flowId=0 - ); - - assert flowRateOfAccount1andAccount2 = fr1; - assert flowRateOfAccount1andAccount3 = fr2; - - let (timestamp) = get_block_timestamp(); - let t2 = timestamp + t1; - %{ stop_warp = warp(ids.t2, ids.supertoken_contract_address) %} - let (balanceOfSender) = ISuperfluidToken.balanceOf( - contract_address=supertoken_contract_address, account=account1 - ); - let (balanceOfReceiver1) = ISuperfluidToken.balanceOf( - contract_address=supertoken_contract_address, account=account2 - ); - let (balanceOfReceiver2) = ISuperfluidToken.balanceOf( - contract_address=supertoken_contract_address, account=account3 - ); - %{ stop_warp() %} - assert balanceOfSender = MINT_AMOUNT - ((fr1 + fr2) * (t2 - timestamp)) - (LIQUIDATION_PERIOD * (fr1 + fr2)); - assert balanceOfReceiver1 = (fr1 * (t2 - timestamp)); - assert balanceOfReceiver2 = (fr2 * (t2 - timestamp)); - return (); -} - -@external -func setup_2to1_flow{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - fr1 = strategy.integers(1, 1000000), - fr2 = strategy.integers(1, 1000000), - account1 = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - account2 = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - account3 = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - t1 = strategy.integers(1, 1000) - ) - %} - return (); -} - -@external -func test_2to1_flow{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - fr1: felt, fr2: felt, account1: felt, account2: felt, account3: felt, t1: felt -) { - %{ assume(ids.account1 != ids.account2) %} - %{ assume(ids.account1 != ids.account3) %} - %{ assume(ids.account2 != ids.account3) %} - - tempvar supertoken_contract_address; - %{ ids.supertoken_contract_address = context.supertoken_contract_address %} - - let (netFlowRateOfAccount1) = ISuperfluidToken.getNetFlowRate( - contract_address=supertoken_contract_address, account=account1 - ); - let (netFlowRateOfAccount2) = ISuperfluidToken.getNetFlowRate( - contract_address=supertoken_contract_address, account=account2 - ); - let (netFlowRateOfAccount3) = ISuperfluidToken.getNetFlowRate( - contract_address=supertoken_contract_address, account=account3 - ); - - assert netFlowRateOfAccount1 = 0; - assert netFlowRateOfAccount2 = 0; - assert netFlowRateOfAccount3 = 0; - - let (flowRateOfAccount1andAccount3) = ISuperfluidToken.getFlowRate( - contract_address=supertoken_contract_address, _from=account1, to=account3, flowId=0 - ); - let (flowRateOfAccount2andAccount3) = ISuperfluidToken.getFlowRate( - contract_address=supertoken_contract_address, _from=account2, to=account3, flowId=0 - ); - - assert flowRateOfAccount1andAccount3 = 0; - assert flowRateOfAccount2andAccount3 = 0; - - %{ stop_prank_callable = start_prank(ids.account1, ids.supertoken_contract_address) %} - ISuperfluidToken.flow( - contract_address=supertoken_contract_address, - senderAddress=account1, - receiverAddress=account3, - flowId=0, - flowRate=fr1, - ); - %{ stop_prank_callable() %} - - %{ stop_prank_callable = start_prank(ids.account2, ids.supertoken_contract_address) %} - ISuperfluidToken.flow( - contract_address=supertoken_contract_address, - senderAddress=account2, - receiverAddress=account3, - flowId=0, - flowRate=fr2, - ); - %{ stop_prank_callable() %} - - let (netFlowRateOfAccount1) = ISuperfluidToken.getNetFlowRate( - contract_address=supertoken_contract_address, account=account1 - ); - let (netFlowRateOfAccount2) = ISuperfluidToken.getNetFlowRate( - contract_address=supertoken_contract_address, account=account2 - ); - let (netFlowRateOfAccount3) = ISuperfluidToken.getNetFlowRate( - contract_address=supertoken_contract_address, account=account3 - ); - - assert netFlowRateOfAccount1 = -fr1; - assert netFlowRateOfAccount2 = -fr2; - assert netFlowRateOfAccount3 = fr1 + fr2; - - let (flowRateOfAccount1andAccount3) = ISuperfluidToken.getFlowRate( - contract_address=supertoken_contract_address, _from=account1, to=account3, flowId=0 - ); - let (flowRateOfAccount2andAccount3) = ISuperfluidToken.getFlowRate( - contract_address=supertoken_contract_address, _from=account2, to=account3, flowId=0 - ); - - assert flowRateOfAccount1andAccount3 = fr1; - assert flowRateOfAccount2andAccount3 = fr2; - - let (timestamp) = get_block_timestamp(); - let t2 = t1 + timestamp; - %{ stop_warp = warp(ids.t2, ids.supertoken_contract_address) %} - let (balanceOfAccount1) = ISuperfluidToken.balanceOf( - contract_address=supertoken_contract_address, account=account1 - ); - let (balanceOfAccount2) = ISuperfluidToken.balanceOf( - contract_address=supertoken_contract_address, account=account2 - ); - let (balanceOfAccount3) = ISuperfluidToken.balanceOf( - contract_address=supertoken_contract_address, account=account3 - ); - %{ stop_warp() %} - assert balanceOfAccount1 = 0; - assert balanceOfAccount2 = 0; - assert balanceOfAccount3 = ((fr2 + fr1) * (t2 - timestamp)); - return (); -} - -@external -func setup_1to2_instdistribute{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { - %{ - given( - amount = strategy.integers(1, 1000000), - u1 = strategy.integers(0, 1000000), - u2 = strategy.integers(0, 1000000), - account1 = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - ) - %} - return (); -} - -@external -func test_1to2_instdistribute{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - amount: felt, u1: felt, u2: felt, account1: felt -) { - alloc_locals; - let tu = u1 + u2; - %{ assume(ids.tu > 0) %} - - tempvar supertoken_contract_address; - tempvar MINT_AMOUNT; - tempvar test_account_address1; - tempvar test_account_address2; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.MINT_AMOUNT = context.MINT_AMOUNT - ids.test_account_address1 = context.test_account_address1 - ids.test_account_address2 = context.test_account_address2 - %} - - ISuperfluidToken.mint(contract_address=supertoken_contract_address, receiver=account1, amount=MINT_AMOUNT); - - let (pool) = _createPool(account1); - - let (disconnectedUnits) = ISuperfluidPool.getDisconnectedUnits(contract_address=pool); - assert disconnectedUnits = 0; - - let (contract_address) = get_contract_address(); - - %{ stop_prank_callable = start_prank(ids.account1, ids.pool) %} - ISuperfluidPool.updateMember(contract_address=pool, memberAddress=test_account_address1, unit=u1); - ISuperfluidPool.updateMember(contract_address=pool, memberAddress=test_account_address2, unit=u2); - %{ stop_prank_callable() %} - - let (disconnectedUnits) = ISuperfluidPool.getDisconnectedUnits(contract_address=pool); - assert disconnectedUnits = u1 + u2; - - let tu = u1 + u2; - - let (poolIndex) = ISuperfluidPool.getIndex(contract_address=pool); - assert poolIndex.total_units = tu; - - %{ stop_prank_callable = start_prank(ids.account1, ids.supertoken_contract_address) %} - ISuperfluidToken.distribute( - contract_address=supertoken_contract_address, - senderAddress=account1, - poolAddress=pool, - reqAmount=amount, - ); - %{ stop_prank_callable() %} - - let (time) = get_block_timestamp(); - let (claimableForAccount2) = ISuperfluidPool.getClaimable(contract_address=pool, time=time, memberAddress=test_account_address1); - let (claimableForAccount3) = ISuperfluidPool.getClaimable(contract_address=pool, time=time, memberAddress=test_account_address2); - let (quotient, _) = unsigned_div_rem(amount, tu); - let actualAmount = quotient * tu; - let amountPerUnit = actualAmount / tu; - assert claimableForAccount2 = amountPerUnit * u1; - assert claimableForAccount3 = amountPerUnit * u2; - - let (isConnectedToPool) = ISuperfluidPoolOperator.isMemberConnected( - contract_address=supertoken_contract_address, pool=pool, memberAddress=test_account_address1 - ); - let (connectedPools) = ISuperfluidToken.getNumConnections( - contract_address=supertoken_contract_address, account=test_account_address1 - ); - assert isConnectedToPool = FALSE; - assert connectedPools = 0; - - /// Call ConnectPool Using the TestAccount 1 - _connectPool(pool, test_account_address1); - - tempvar supertoken_contract_address; - tempvar test_account_address1; - tempvar test_account_address2; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.test_account_address1 = context.test_account_address1 - ids.test_account_address2 = context.test_account_address2 - %} - - let (isConnectedToPool) = ISuperfluidPoolOperator.isMemberConnected( - contract_address=supertoken_contract_address, pool=pool, memberAddress=test_account_address1 - ); - let (connectedPools) = ISuperfluidToken.getNumConnections( - contract_address=supertoken_contract_address, account=test_account_address1 - ); - assert isConnectedToPool = TRUE; - assert connectedPools = 1; - - let (isConnectedToPool) = ISuperfluidPoolOperator.isMemberConnected( - contract_address=supertoken_contract_address, pool=pool, memberAddress=test_account_address2 - ); - let (connectedPools) = ISuperfluidToken.getNumConnections( - contract_address=supertoken_contract_address, account=test_account_address2 - ); - assert isConnectedToPool = FALSE; - assert connectedPools = 0; - - /// Calling ConnectPool Using the Test Account 2 - _connectPool(pool, test_account_address2); - - tempvar supertoken_contract_address; - tempvar test_account_address1; - tempvar test_account_address2; - tempvar MINT_AMOUNT; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.test_account_address1 = context.test_account_address1 - ids.test_account_address2 = context.test_account_address2 - ids.MINT_AMOUNT = context.MINT_AMOUNT - %} - - let (isConnectedToPool) = ISuperfluidPoolOperator.isMemberConnected( - contract_address=supertoken_contract_address, pool=pool, memberAddress=test_account_address2 - ); - let (connectedPools) = ISuperfluidToken.getNumConnections( - contract_address=supertoken_contract_address, account=test_account_address2 - ); - assert isConnectedToPool = TRUE; - assert connectedPools = 1; - - let (disconnectedUnits) = ISuperfluidPool.getDisconnectedUnits(contract_address=pool); - assert disconnectedUnits = 0; - - let (balanceOfAccount1) = ISuperfluidToken.balanceOf( - contract_address=supertoken_contract_address, account=account1 - ); - let (balanceOfAccount2) = ISuperfluidToken.balanceOf( - contract_address=supertoken_contract_address, account=test_account_address1 - ); - let (balanceOfAccount3) = ISuperfluidToken.balanceOf( - contract_address=supertoken_contract_address, account=test_account_address2 - ); - let (quotient, _) = unsigned_div_rem(amount, tu); - let actualAmount = quotient * tu; - let amountPerUnit = actualAmount / tu; - assert balanceOfAccount1 = MINT_AMOUNT - actualAmount; - assert balanceOfAccount2 = amountPerUnit * u1; - assert balanceOfAccount3 = amountPerUnit * u2; - let (time) = get_block_timestamp(); - let (claimableForAccount2) = ISuperfluidPool.getClaimable(contract_address=pool, time=time, memberAddress=test_account_address1); - let (claimableForAccount3) = ISuperfluidPool.getClaimable(contract_address=pool, time=time, memberAddress=test_account_address2); - assert claimableForAccount2 = 0; - assert claimableForAccount3 = 0; - return (); -} - -@external -func setup_1to2_distributeflow_bothconnected{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr -}() { - %{ - given( - u1 = strategy.integers(0, 1000000), - u2 = strategy.integers(0, 1000000), - r1 = strategy.integers(1, 1000000), - r2 = strategy.integers(1, 1000000), - dt1 = strategy.integers(1, 10000), - dt2 = strategy.integers(1, 10000), - account1 = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - ) - %} - return (); -} - -@external -func test_1to2_distributeflow_bothconnected{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr -}(u1: felt, u2: felt, r1: felt, r2: felt, dt1: felt, dt2: felt, account1: felt) { - alloc_locals; - let tu = u1 + u2; - %{ assume(ids.tu > 0) %} - let (rr1, _) = unsigned_div_rem(r1, tu); - let rrr1 = rr1 * tu; - let (rr2, _) = unsigned_div_rem(r2, tu); - let rrr2 = rr2 * tu; - - tempvar supertoken_contract_address; - tempvar MINT_AMOUNT; - tempvar test_account_address1; - tempvar test_account_address2; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.MINT_AMOUNT = context.MINT_AMOUNT - ids.test_account_address1 = context.test_account_address1 - ids.test_account_address2 = context.test_account_address2 - %} - ISuperfluidToken.mint(contract_address=supertoken_contract_address, receiver=account1, amount=MINT_AMOUNT); - - let (pool) = _createPool(account1); - - tempvar supertoken_contract_address; - tempvar test_account_address1; - tempvar test_account_address2; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.test_account_address1 = context.test_account_address1 - ids.test_account_address2 = context.test_account_address2 - %} - let (a1) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=account1); - let (b1) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=test_account_address1); - let (c1) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=test_account_address2); - let (p1) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=pool); - - %{ stop_prank_callable = start_prank(ids.account1, ids.pool) %} - ISuperfluidPool.updateMember(contract_address=pool, memberAddress=test_account_address1, unit=u1); - ISuperfluidPool.updateMember(contract_address=pool, memberAddress=test_account_address2, unit=u2); - %{ stop_prank_callable() %} - let (time) = get_block_timestamp(); - let (claimableForAccount2) = ISuperfluidPool.getClaimable(contract_address=pool, time=time, memberAddress=test_account_address1); - let (claimableForAccount3) = ISuperfluidPool.getClaimable(contract_address=pool, time=time, memberAddress=test_account_address2); - assert claimableForAccount2 = 0; - assert claimableForAccount3 = 0; - %{ stop_prank_callable = start_prank(ids.account1, ids.supertoken_contract_address) %} - let (_,af,ndf) = ISuperfluidToken.distributeFlow(contract_address=supertoken_contract_address, senderAddress=account1, poolAddress=pool, flowId=0, reqFlowRate=r1); - %{ stop_prank_callable() %} - - let (disconnectedUnits) = ISuperfluidPool.getDisconnectedUnits(contract_address=pool); - assert disconnectedUnits = tu; - - tempvar test_account_address1; - %{ - ids.test_account_address1 = context.test_account_address1 - %} - _connectPool(pool, test_account_address1); - tempvar test_account_address2; - %{ - ids.test_account_address2 = context.test_account_address2 - %} - _connectPool(pool, test_account_address2); - - let (disconnectedUnits) = ISuperfluidPool.getDisconnectedUnits(contract_address=pool); - assert disconnectedUnits = 0; - - tempvar supertoken_contract_address; - tempvar test_account_address1; - tempvar test_account_address2; - tempvar LIQUIDATION_PERIOD; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.test_account_address1 = context.test_account_address1 - ids.test_account_address2 = context.test_account_address2 - ids.LIQUIDATION_PERIOD = context.LIQUIDATION_PERIOD - %} - - let (pdr1) = ISuperfluidPool.getConnectedFlowRate(contract_address=pool); - let (adj1) = _getAdjustmentFlowRate(pool, account1); - let (a1nr1) = ISuperfluidToken.getNetFlowRate(contract_address=supertoken_contract_address, account=account1); - let (ta1nr1) = ISuperfluidToken.getNetFlowRate(contract_address=supertoken_contract_address, account=test_account_address1); - let (ta2nr1) = ISuperfluidToken.getNetFlowRate(contract_address=supertoken_contract_address, account=test_account_address2); - let (pnr1) = ISuperfluidToken.getNetFlowRate(contract_address=supertoken_contract_address, account=pool); - - assert pdr1 = ndf; - assert a1nr1 = -af + adj1; - assert pdr1 = rrr1; - assert a1nr1 = -rrr1; - assert ta1nr1 + ta2nr1 = rrr1; - assert pnr1 = -adj1; - assert a1nr1 + ta1nr1 + ta2nr1 + pnr1 = 0; - - let (timestamp) = get_block_timestamp(); - let t1 = timestamp + dt1; - let t2 = t1 + dt2; - %{ stop_warp = warp(ids.t1, ids.supertoken_contract_address) %} - - %{ stop_prank_callable = start_prank(ids.account1, ids.supertoken_contract_address) %} - let (_,af,ndf) = ISuperfluidToken.distributeFlow(contract_address=supertoken_contract_address, senderAddress=account1, poolAddress=pool, flowId=0, reqFlowRate=r2); - %{ stop_prank_callable() %} - - %{ stop_warp = warp(ids.t2, ids.supertoken_contract_address) %} - - let (pdr2) = ISuperfluidPool.getConnectedFlowRate(contract_address=pool); - let (adj2) = _getAdjustmentFlowRate(pool, account1); - let (a1nr2) = ISuperfluidToken.getNetFlowRate(contract_address=supertoken_contract_address, account=account1); - let (ta1nr2) = ISuperfluidToken.getNetFlowRate(contract_address=supertoken_contract_address, account=test_account_address1); - let (ta2nr2) = ISuperfluidToken.getNetFlowRate(contract_address=supertoken_contract_address, account=test_account_address2); - let (pnr2) = ISuperfluidToken.getNetFlowRate(contract_address=supertoken_contract_address, account=pool); - - assert pdr2 = ndf; - assert a1nr2 = -af + adj2; - assert pdr2 = rrr2; - assert a1nr2 = -rrr2; - assert ta1nr2 + ta2nr2 = rrr2; - assert pnr2 = -adj2; - assert a1nr2 + ta1nr2 + ta2nr2 + pnr2 = 0; - - let (a2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=account1); - let (b2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=test_account_address1); - let (c2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=test_account_address2); - let (p2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=pool); - let (k2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=supertoken_contract_address); - - %{ stop_warp() %} - - assert a1 - a2 = k2 + (rrr1 * dt1) + (rrr2 * dt2); - assert a1 - a2 = k2 + (b2 - b1) + (c2 - c1) + (p2 - p1); - - let (claimableForTestAccount1) = ISuperfluidPool.getClaimable(contract_address=pool, time=t2, memberAddress=test_account_address1); - let (claimableForTestAccount2) = ISuperfluidPool.getClaimable(contract_address=pool, time=t2, memberAddress=test_account_address2); - - assert a1 - a2 - k2 = claimableForTestAccount1 + claimableForTestAccount2; - assert k2 = rrr2 * LIQUIDATION_PERIOD; - - return (); -} - -@external -func setup_1to2_distributeflow_oneconnected{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr -}() { - %{ - given( - u1 = strategy.integers(0, 1000000), - u2 = strategy.integers(0, 1000000), - r = strategy.integers(1, 1000000), - dt = strategy.integers(1, 10000), - account1 = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - ) - %} - return (); -} - -@external -func test_1to2_distributeflow_oneconnected{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr -}(u1: felt, u2: felt, r: felt, dt: felt, account1: felt) { - alloc_locals; - let tu = u1 + u2; - %{ assume(ids.tu > 0) %} - - let (rr, _) = unsigned_div_rem(r, tu); - let rrr = rr * tu; - - let (timestamp) = get_block_timestamp(); - let t1 = timestamp + dt; - - tempvar supertoken_contract_address; - tempvar MINT_AMOUNT; - tempvar test_account_address1; - tempvar test_account_address2; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.MINT_AMOUNT = context.MINT_AMOUNT - ids.test_account_address1 = context.test_account_address1 - ids.test_account_address2 = context.test_account_address2 - %} - ISuperfluidToken.mint(contract_address=supertoken_contract_address, receiver=account1, amount=MINT_AMOUNT); - let (pool) = _createPool(account1); - - tempvar supertoken_contract_address; - tempvar test_account_address1; - tempvar test_account_address2; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.test_account_address1 = context.test_account_address1 - ids.test_account_address2 = context.test_account_address2 - %} - let (a1) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=account1); - let (b1) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=test_account_address1); - let (c1) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=test_account_address2); - let (p1) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=pool); - - %{ stop_prank_callable = start_prank(ids.account1, ids.pool) %} - ISuperfluidPool.updateMember(contract_address=pool, memberAddress=test_account_address1, unit=u1); - ISuperfluidPool.updateMember(contract_address=pool, memberAddress=test_account_address2, unit=u2); - %{ stop_prank_callable() %} - - %{ stop_prank_callable = start_prank(ids.account1, ids.supertoken_contract_address) %} - ISuperfluidToken.distributeFlow( - contract_address=supertoken_contract_address, - senderAddress=account1, - poolAddress=pool, - flowId=0, - reqFlowRate=r, - ); - %{ stop_prank_callable() %} - - let (disconnectedUnits) = ISuperfluidPool.getDisconnectedUnits(contract_address=pool); - assert disconnectedUnits = tu; - - tempvar test_account_address1; - %{ - ids.test_account_address1 = context.test_account_address1 - %} - _connectPool(pool, test_account_address1); - - let (disconnectedUnits) = ISuperfluidPool.getDisconnectedUnits(contract_address=pool); - assert disconnectedUnits = u2; - - tempvar supertoken_contract_address; - tempvar test_account_address1; - tempvar test_account_address2; - tempvar LIQUIDATION_PERIOD; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.test_account_address1 = context.test_account_address1 - ids.test_account_address2 = context.test_account_address2 - ids.LIQUIDATION_PERIOD = context.LIQUIDATION_PERIOD - %} - - %{ stop_warp = warp(ids.t1, ids.supertoken_contract_address) %} - - let (a2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=account1); - let (b2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=test_account_address1); - let (c2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=test_account_address2); - let (p2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=pool); - let (k2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=supertoken_contract_address); - - assert a1 - a2 = k2 + (rrr * dt); - assert c2 - c1 = 0; - assert a1 - a2 = k2 + (b2 - b1) + (c2 - c1) + (p2 - p1); - - let (claimableForTestAccount1) = ISuperfluidPool.getClaimable(contract_address=pool, time=t1, memberAddress=test_account_address1); - let (claimableForTestAccount2) = ISuperfluidPool.getClaimable(contract_address=pool, time=t1, memberAddress=test_account_address2); - - assert a1 - a2 - k2 = claimableForTestAccount1 + claimableForTestAccount2; - assert k2 = rrr * LIQUIDATION_PERIOD; - - let (ar2) = ISuperfluidToken.getNetFlowRate(contract_address=supertoken_contract_address, account=account1); - let (br2) = ISuperfluidToken.getNetFlowRate(contract_address=supertoken_contract_address, account=test_account_address1); - let (cr2) = ISuperfluidToken.getNetFlowRate(contract_address=supertoken_contract_address, account=test_account_address2); - let (pr2) = ISuperfluidToken.getNetFlowRate(contract_address=supertoken_contract_address, account=pool); - - let (cfr) = ISuperfluidPool.getConnectedFlowRate(contract_address=pool); - assert cfr = rrr; - assert ar2 = -rrr; - let (dfr) = ISuperfluidPool.getDisconnectedFlowRate(contract_address=pool); - assert br2 + dfr = rrr; - assert pr2 = dfr; - assert ar2 + br2 + cr2 + pr2 = 0; - return (); -} - -@external -func setup_1to1_distributeflow_connect_disconnect_connect{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr -}() { - %{ - given( - u = strategy.integers(1, 1000000), - r = strategy.integers(1, 1000000), - dt1 = strategy.integers(1, 10000), - dt2 = strategy.integers(1, 10000), - dt3 = strategy.integers(1, 10000), - dt4 = strategy.integers(1, 10000), - account1 = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - ) - %} - return (); -} - -@external -func test_1to1_distributeflow_connect_disconnect_connect{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(u: felt, r: felt, dt1: felt, dt2: felt, dt3: felt, dt4: felt, account1: felt) { - alloc_locals; - let tu = u; - - let (rr, _) = unsigned_div_rem(r, tu); - let rrr = rr * tu; - - tempvar supertoken_contract_address; - tempvar MINT_AMOUNT; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.MINT_AMOUNT = context.MINT_AMOUNT - %} - ISuperfluidToken.mint(contract_address=supertoken_contract_address, receiver=account1, amount=MINT_AMOUNT); - let (pool) = _createPool(account1); - - tempvar supertoken_contract_address; - tempvar test_account_address1; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.test_account_address1 = context.test_account_address1 - %} - let (a0) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=account1); - let (b0) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=test_account_address1); - let (p0) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=pool); - - %{ stop_prank_callable = start_prank(ids.account1, ids.pool) %} - ISuperfluidPool.updateMember(contract_address=pool, memberAddress=test_account_address1, unit=u); - %{ stop_prank_callable() %} - - %{ stop_prank_callable = start_prank(ids.account1, ids.supertoken_contract_address) %} - ISuperfluidToken.distributeFlow( - contract_address=supertoken_contract_address, - senderAddress=account1, - poolAddress=pool, - flowId=0, - reqFlowRate=r, - ); - %{ stop_prank_callable() %} - - let (disconnectedUnits) = ISuperfluidPool.getDisconnectedUnits(contract_address=pool); - assert disconnectedUnits = u; - - let (timestamp) = get_block_timestamp(); - let t0 = timestamp; - let t1 = t0 + dt1; - - // t1 - %{ stop_warp = warp(ids.t1, ids.supertoken_contract_address) %} - tempvar test_account_address1; - %{ - ids.test_account_address1 = context.test_account_address1 - %} - _connectPool(pool, test_account_address1); - let (disconnectedUnits) = ISuperfluidPool.getDisconnectedUnits(contract_address=pool); - assert disconnectedUnits = 0; - - // t2 - tempvar supertoken_contract_address; - tempvar test_account_address1; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.test_account_address1 = context.test_account_address1 - %} - - let t2 = t1 + dt2; - %{ stop_warp = warp(ids.t2, ids.supertoken_contract_address) %} - _disconnectPool(pool, test_account_address1); - let (disconnectedUnits) = ISuperfluidPool.getDisconnectedUnits(contract_address=pool); - assert disconnectedUnits = u; - - // t3 - tempvar supertoken_contract_address; - tempvar test_account_address1; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.test_account_address1 = context.test_account_address1 - %} - - let t3 = t2 + dt3; - %{ stop_warp = warp(ids.t3, ids.supertoken_contract_address) %} - _connectPool(pool, test_account_address1); - let (disconnectedUnits) = ISuperfluidPool.getDisconnectedUnits(contract_address=pool); - assert disconnectedUnits = 0; - - // t4 - tempvar supertoken_contract_address; - tempvar test_account_address1; - tempvar LIQUIDATION_PERIOD; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.test_account_address1 = context.test_account_address1 - ids.LIQUIDATION_PERIOD = context.LIQUIDATION_PERIOD - %} - - let t4 = t3 + dt4; - %{ stop_warp = warp(ids.t4, ids.supertoken_contract_address) %} - - let (anr4) = ISuperfluidToken.getNetFlowRate(contract_address=supertoken_contract_address, account=account1); - let (bnr4) = ISuperfluidToken.getNetFlowRate(contract_address=supertoken_contract_address, account=test_account_address1); - let (pnr4) = ISuperfluidToken.getNetFlowRate(contract_address=supertoken_contract_address, account=pool); - - let (cfr) = ISuperfluidPool.getConnectedFlowRate(contract_address=pool); - - assert cfr = rrr; - assert anr4 = -rrr; - - let (dfr) = ISuperfluidPool.getDisconnectedFlowRate(contract_address=pool); - assert bnr4 + dfr = rrr; - assert pnr4 = dfr; - assert anr4 + bnr4 + pnr4 = 0; - - let (a4) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=account1); - let (b4) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=test_account_address1); - let (p4) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=pool); - let (k4) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=supertoken_contract_address); - - assert a0 - a4 = k4 + (rrr * (dt1 + dt2 + dt3 + dt4)); - assert a0 - a4 = k4 + (b4 - b0) + (p4 - p0); - assert k4 = rrr * LIQUIDATION_PERIOD; - - return (); -} - -@external -func setup_1to2_distributeflow_unit_updates{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr -}() { - %{ - given( - u1 = strategy.integers(0, 1000000), - u2 = strategy.integers(0, 1000000), - r1 = strategy.integers(1, 100), - r2 = strategy.integers(1000, 1000000), - dt1 = strategy.integers(1, 10000), - dt2 = strategy.integers(1, 10000), - account1 = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - ) - %} - return (); -} - -@external -func test_1to2_distributeflow_unit_updates{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(u1: felt, u2: felt, r1: felt, r2: felt, dt1: felt, dt2: felt, account1: felt) { - alloc_locals; - let tu = u1 + u2; - %{ assume(ids.tu > 0) %} - - let (rr1, _) = unsigned_div_rem(r1, tu); - let rrr1 = rr1 * tu; - let (rr2, _) = unsigned_div_rem(r2, tu); - let rrr2 = rr2 * tu; - - tempvar supertoken_contract_address; - tempvar MINT_AMOUNT; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.MINT_AMOUNT = context.MINT_AMOUNT - %} - ISuperfluidToken.mint(contract_address=supertoken_contract_address, receiver=account1, amount=MINT_AMOUNT); - let (pool) = _createPool(account1); - tempvar test_account_address1; - %{ - ids.test_account_address1 = context.test_account_address1 - %} - _connectPool(pool, test_account_address1); - - tempvar supertoken_contract_address; - tempvar test_account_address1; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.test_account_address1 = context.test_account_address1 - %} - - %{ stop_prank_callable = start_prank(ids.account1, ids.pool) %} - ISuperfluidPool.updateMember(contract_address=pool, memberAddress=test_account_address1, unit=u1); - %{ stop_prank_callable() %} - - %{ stop_prank_callable = start_prank(ids.account1, ids.supertoken_contract_address) %} - ISuperfluidToken.distributeFlow( - contract_address=supertoken_contract_address, - senderAddress=account1, - poolAddress=pool, - flowId=0, - reqFlowRate=r1, - ); - %{ stop_prank_callable() %} - - let (timestamp) = get_block_timestamp(); - let t1 = timestamp + dt1; - - %{ stop_warp = warp(ids.t1, ids.supertoken_contract_address) %} - - %{ stop_prank_callable = start_prank(ids.account1, ids.pool) %} - ISuperfluidPool.updateMember(contract_address=pool, memberAddress=test_account_address1, unit=u2); - %{ stop_prank_callable() %} - - %{ stop_prank_callable = start_prank(ids.account1, ids.supertoken_contract_address) %} - ISuperfluidToken.distributeFlow( - contract_address=supertoken_contract_address, - senderAddress=account1, - poolAddress=pool, - flowId=0, - reqFlowRate=r2, - ); - %{ stop_prank_callable() %} - - // let t2 = t1 + dt2; - // %{ stop_warp = warp(ids.t2, ids.supertoken_contract_address) %} - - // %{ stop_prank_callable = start_prank(ids.account1, ids.supertoken_contract_address) %} - // ISuperfluidToken.distributeFlow( - // contract_address=supertoken_contract_address, - // senderAddress=account1, - // poolAddress=pool, - // flowId=0, - // reqFlowRate=1000, - // ); - // %{ stop_prank_callable() %} - - return (); -} - -@external -func setup_2to1_distributeflow{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr -}() { - %{ - given( - u = strategy.integers(1, 1000000), - r1 = strategy.integers(1, 1000000), - r2 = strategy.integers(1, 1000000), - dt = strategy.integers(1, 10000), - account1 = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - account2 = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - ) - %} - return (); -} - -@external -func test_2to1_distributeflow{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(u: felt, r1: felt, r2: felt, dt: felt, account1: felt, account2: felt) { - alloc_locals; - %{ assume(ids.account1 != ids.account2) %} - let tu = u; - let (rr1, _) = unsigned_div_rem(r1, tu); - let rrr1 = rr1 * tu; - let (rr2, _) = unsigned_div_rem(r2, tu); - let rrr2 = rr2 * tu; - - tempvar supertoken_contract_address; - tempvar MINT_AMOUNT; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.MINT_AMOUNT = context.MINT_AMOUNT - %} - ISuperfluidToken.mint(contract_address=supertoken_contract_address, receiver=account1, amount=MINT_AMOUNT); - ISuperfluidToken.mint(contract_address=supertoken_contract_address, receiver=account2, amount=MINT_AMOUNT); - - let (pool) = _createPool(account1); - - tempvar supertoken_contract_address; - tempvar test_account_address1; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.test_account_address1 = context.test_account_address1 - %} - - let (a1) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=account1); - let (b1) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=account2); - let (c1) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=test_account_address1); - let (p1) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=pool); - - %{ stop_prank_callable = start_prank(ids.account1, ids.pool) %} - ISuperfluidPool.updateMember(contract_address=pool, memberAddress=test_account_address1, unit=u); - %{ stop_prank_callable() %} - - %{ stop_prank_callable = start_prank(ids.account1, ids.supertoken_contract_address) %} - let (_,ar,_) = ISuperfluidToken.distributeFlow(contract_address=supertoken_contract_address, senderAddress=account1, poolAddress=pool, flowId=0, reqFlowRate=r1); - let (k1) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=supertoken_contract_address); - %{ stop_prank_callable() %} - - %{ stop_prank_callable = start_prank(ids.account2, ids.supertoken_contract_address) %} - let (_,br,pdr) = ISuperfluidToken.distributeFlow(contract_address=supertoken_contract_address, senderAddress=account2, poolAddress=pool, flowId=0, reqFlowRate=r2); - let (newBalance) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=supertoken_contract_address); - let k2 = newBalance - k1; - %{ stop_prank_callable() %} - - let (disconnectedUnits) = ISuperfluidPool.getDisconnectedUnits(contract_address=pool); - assert disconnectedUnits = tu; - - _connectPool(pool, test_account_address1); - - let (disconnectedUnits) = ISuperfluidPool.getDisconnectedUnits(contract_address=pool); - assert disconnectedUnits = 0; - - let (timestamp) = get_block_timestamp(); - let t1 = timestamp + dt; - - tempvar supertoken_contract_address; - tempvar test_account_address1; - tempvar LIQUIDATION_PERIOD; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.test_account_address1 = context.test_account_address1 - ids.LIQUIDATION_PERIOD = context.LIQUIDATION_PERIOD - %} - - %{ stop_warp = warp(ids.t1, ids.supertoken_contract_address) %} - - let (ar2) = ISuperfluidToken.getNetFlowRate(contract_address=supertoken_contract_address, account=account1); - let (br2) = ISuperfluidToken.getNetFlowRate(contract_address=supertoken_contract_address, account=account2); - let (cr2) = ISuperfluidToken.getNetFlowRate(contract_address=supertoken_contract_address, account=test_account_address1); - let (pr2) = ISuperfluidToken.getNetFlowRate(contract_address=supertoken_contract_address, account=pool); - let (cfr2) = ISuperfluidPool.getConnectedFlowRate(contract_address=pool); - let (dfr2) = ISuperfluidPool.getDisconnectedFlowRate(contract_address=pool); - - assert cfr2 = rrr1 + rrr2; - assert dfr2 = 0; - assert ar2 = -rrr1; - assert br2 = -rrr2; - assert pr2 = 0; - assert ar2 + br2 + cr2 + pr2 = 0; - assert cfr2 = pdr; - assert -ar2 = ar; - assert -br2 = br; - - let (a2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=account1); - let (b2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=account2); - let (c2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=test_account_address1); - let (p2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=pool); - - assert a1 - a2 = k1 + (rrr1 * dt); - assert b1 - b2 = k2 + (rrr2 * dt); - assert (a1 - a2) + (b1 - b2) = k1 + k2 + (c2 - c1) + (p2 - p1); - - let (claimableForTestAccount) = ISuperfluidPool.getClaimable(contract_address=pool, time=t1, memberAddress=test_account_address1); - - assert (a1 - a2) + (b1 - b2) - k1 - k2 = claimableForTestAccount; - assert k1 = rrr1 * LIQUIDATION_PERIOD; - assert k2 = rrr2 * LIQUIDATION_PERIOD; - - return (); -} - -@external -func setup_pool_distributeflow_claim_connected_pool{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr -}() { - %{ - given( - u = strategy.integers(1, 1000000), - r = strategy.integers(1, 1000000), - dt1 = strategy.integers(1, 10000), - dt2 = strategy.integers(1, 10000), - account1 = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - ) - %} - return (); -} - -@external -func test_pool_distributeflow_claim_connected_pool{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(u: felt, r: felt, dt1: felt, dt2: felt, account1: felt) { - alloc_locals; - let tu = u; - let (rr, _) = unsigned_div_rem(r, tu); - let rrr = rr * tu; - let (t0) = get_block_timestamp(); - let t1 = t0 + dt1; - let t2 = t1 + dt2; - - tempvar supertoken_contract_address; - tempvar MINT_AMOUNT; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.MINT_AMOUNT = context.MINT_AMOUNT - %} - ISuperfluidToken.mint(contract_address=supertoken_contract_address, receiver=account1, amount=MINT_AMOUNT); - - let (pool) = _createPool(account1); - - tempvar supertoken_contract_address; - tempvar test_account_address1; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.test_account_address1 = context.test_account_address1 - %} - - let (a0) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=account1); - let (b0) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=test_account_address1); - let (p0) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=pool); - - %{ stop_prank_callable = start_prank(ids.account1, ids.pool) %} - ISuperfluidPool.updateMember(contract_address=pool, memberAddress=test_account_address1, unit=u); - %{ stop_prank_callable() %} - - %{ stop_prank_callable = start_prank(ids.account1, ids.supertoken_contract_address) %} - ISuperfluidToken.distributeFlow(contract_address=supertoken_contract_address, senderAddress=account1, poolAddress=pool, flowId=0, reqFlowRate=r); - %{ stop_prank_callable() %} - - _connectPool(pool, test_account_address1); - - tempvar supertoken_contract_address; - tempvar test_account_address1; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.test_account_address1 = context.test_account_address1 - %} - - %{ stop_warp = warp(ids.t1, ids.supertoken_contract_address) %} - - %{ stop_prank_callable = start_prank(ids.test_account_address1, ids.pool) %} - %{ stop_warp = warp(ids.t1, ids.pool) %} - ISuperfluidPool.claimAll(contract_address=pool); - %{ stop_warp() %} - %{ stop_prank_callable() %} - - let (claimableForTestAccount) = ISuperfluidPool.getClaimable(contract_address=pool, time=t1, memberAddress=test_account_address1); - - assert claimableForTestAccount = 0; - - %{ stop_warp = warp(ids.t2, ids.supertoken_contract_address) %} - - let (a2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=account1); - let (b2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=test_account_address1); - let (p2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=pool); - let (k2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=supertoken_contract_address); - - assert a0 - a2 = k2 + (rrr * (dt1 + dt2)); - assert a0 - a2 = k2 + (b2 - b0) + (p2 - p0); - - return (); -} - -@external -func setup_pool_distributeflow_update_unit{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr -}() { - %{ - given( - u1 = strategy.integers(1, 1000000), - u2 = strategy.integers(1, 1000000), - r = strategy.integers(1, 1000000), - dt1 = strategy.integers(1, 10000), - dt2 = strategy.integers(1, 10000), - account1 = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - ) - %} - return (); -} - -@external -func test_pool_distributeflow_update_unit{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(u1: felt, u2: felt, r: felt, dt1: felt, dt2: felt, account1: felt) { - alloc_locals; - let (rr1, _) = unsigned_div_rem(r, u1); - let rrr1 = rr1 * u1; - let (rr2, _) = unsigned_div_rem(rrr1, u2); - let rrr2 = rr2 * u2; - let (t0) = get_block_timestamp(); - let t1 = t0 + dt1; - let t2 = t1 + dt2; - - tempvar supertoken_contract_address; - tempvar MINT_AMOUNT; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.MINT_AMOUNT = context.MINT_AMOUNT - %} - ISuperfluidToken.mint(contract_address=supertoken_contract_address, receiver=account1, amount=MINT_AMOUNT); - - let (pool) = _createPool(account1); - - tempvar supertoken_contract_address; - tempvar test_account_address1; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.test_account_address1 = context.test_account_address1 - %} - - let (a0) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=account1); - let (b0) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=test_account_address1); - let (p0) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=pool); - - %{ stop_prank_callable = start_prank(ids.account1, ids.pool) %} - ISuperfluidPool.updateMember(contract_address=pool, memberAddress=test_account_address1, unit=u1); - %{ stop_prank_callable() %} - - %{ stop_prank_callable = start_prank(ids.account1, ids.supertoken_contract_address) %} - ISuperfluidToken.distributeFlow(contract_address=supertoken_contract_address, senderAddress=account1, poolAddress=pool, flowId=0, reqFlowRate=r); - %{ stop_prank_callable() %} - - %{ stop_warp = warp(ids.t1, ids.supertoken_contract_address) %} - - %{ stop_prank_callable = start_prank(ids.account1, ids.pool) %} - %{ stop_warp = warp(ids.t1, ids.pool) %} - ISuperfluidPool.updateMember(contract_address=pool, memberAddress=test_account_address1, unit=u2); - %{ stop_warp() %} - %{ stop_prank_callable() %} - - let (claimableForTestAccount) = ISuperfluidPool.getClaimable(contract_address=pool, time=t1, memberAddress=test_account_address1); - assert claimableForTestAccount = 0; - - %{ stop_warp = warp(ids.t2, ids.supertoken_contract_address) %} - - let (a2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=account1); - let (b2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=test_account_address1); - let (p2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=pool); - let (k2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=supertoken_contract_address); - - assert a0 - a2 = k2 + (rrr1 * dt1) + (rrr2 * dt2); - assert a0 - a2 = k2 + (b2 - b0) + (p2 - p0); - - return (); -} - -@external -func setup_pool_multiple_claims{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr -}() { - %{ - given( - u = strategy.integers(1, 1000000), - r = strategy.integers(1, 1000000), - dt1 = strategy.integers(1, 10000), - dt2 = strategy.integers(1, 10000), - account1 = strategy.integers(1, 100000000000000000000000000000000000000000000000000000000000000000000000), - ) - %} - return (); -} - -@external -func test_pool_multiple_claims{ - syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(u: felt, r: felt, dt1: felt, dt2: felt, account1: felt) { - alloc_locals; - let (rr, _) = unsigned_div_rem(r, u); - let rrr = rr * u; - let (t0) = get_block_timestamp(); - let t1 = t0 + dt1; - let t2 = t1 + dt2; - - tempvar supertoken_contract_address; - tempvar MINT_AMOUNT; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.MINT_AMOUNT = context.MINT_AMOUNT - %} - ISuperfluidToken.mint(contract_address=supertoken_contract_address, receiver=account1, amount=MINT_AMOUNT); - - let (pool) = _createPool(account1); - - tempvar supertoken_contract_address; - tempvar test_account_address1; - %{ - ids.supertoken_contract_address = context.supertoken_contract_address - ids.test_account_address1 = context.test_account_address1 - %} - - let (a1) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=account1); - let (b1) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=test_account_address1); - let (p1) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=pool); - - %{ stop_prank_callable = start_prank(ids.account1, ids.pool) %} - ISuperfluidPool.updateMember(contract_address=pool, memberAddress=test_account_address1, unit=u); - %{ stop_prank_callable() %} - - %{ stop_prank_callable = start_prank(ids.account1, ids.supertoken_contract_address) %} - ISuperfluidToken.distributeFlow(contract_address=supertoken_contract_address, senderAddress=account1, poolAddress=pool, flowId=0, reqFlowRate=r); - %{ stop_prank_callable() %} - - %{ stop_warp = warp(ids.t1, ids.supertoken_contract_address) %} - - let (a2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=account1); - let (b2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=test_account_address1); - let (k2) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=supertoken_contract_address); - - let (claimableForAccount1) = ISuperfluidPool.getClaimable(contract_address=pool, time=t1, memberAddress=account1); - let (claimableForTestAccount) = ISuperfluidPool.getClaimable(contract_address=pool, time=t1, memberAddress=test_account_address1); - - assert a1 - a2 - k2 = claimableForAccount1 + claimableForTestAccount; - assert b2 = b1; - - %{ stop_prank_callable = start_prank(ids.test_account_address1, ids.pool) %} - %{ stop_warp = warp(ids.t1, ids.pool) %} - - ISuperfluidPool.claimAll(contract_address=pool); - - let (claimableForTestAccount) = ISuperfluidPool.getClaimable(contract_address=pool, time=t1, memberAddress=test_account_address1); - assert claimableForTestAccount = 0; - - ISuperfluidPool.claimAll(contract_address=pool); - - let (claimableForTestAccount) = ISuperfluidPool.getClaimable(contract_address=pool, time=t1, memberAddress=test_account_address1); - assert claimableForTestAccount = 0; - - %{ stop_warp() %} - %{ stop_prank_callable() %} - - %{ stop_warp = warp(ids.t2, ids.supertoken_contract_address) %} - - let (a3) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=account1); - let (b3) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=test_account_address1); - let (p3) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=pool); - let (k3) = ISuperfluidToken.realtimeBalanceNow(contract_address=supertoken_contract_address, account=supertoken_contract_address); - - let (claimableForTestAccount) = ISuperfluidPool.getClaimable(contract_address=pool, time=t2, memberAddress=test_account_address1); - - assert k2 = k3; - assert a2 - a3 = claimableForTestAccount; - assert p3 = claimableForTestAccount; - - assert a1 - a3 = k2 + (rrr * (dt1 + dt2)); - assert a1 - a3 = k2 + (b3 - b1) + (p3 - p1); - - return (); -} diff --git a/packages/subgraph/LICENSE b/packages/subgraph/LICENSE deleted file mode 100644 index d3369f1203..0000000000 --- a/packages/subgraph/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -Superfluid Protocol - -Copyright @ 2020-2023 Superfluid Finance Ltd - -This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License along with this program. If not, see . diff --git a/packages/subgraph/MIT-LICENSE b/packages/subgraph/MIT-LICENSE new file mode 100644 index 0000000000..fa4009bd75 --- /dev/null +++ b/packages/subgraph/MIT-LICENSE @@ -0,0 +1,25 @@ +The MIT License (MIT) +===================== + +Copyright © 2025 Superfluid Finance LTD. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE.