CarlosAlegreUr / CallOrderControl-SmartContract-DesignPattern

Solidity smart contract that ensures your functions are only called by an address in a previously allowed order or a previously allowed number of times.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool



CallOrderControl Contract


Ensures your functions are only called by an address in a previously allowed order or a previously allowed number of times

πŸ’½Testing and implementation example repo => (click) πŸ’½

πŸ’½NPM repo => (click) πŸ’½


If further elaboration or development please mention me in your work.

πŸ˜‰ https://github.com/CarlosAlegreUr πŸ˜‰


πŸ€– General usecase explanation πŸ€–

CallOrderControl can be used to control that functions are only called by an address in a previously allowed order or a previously allowed number of times.

You can use this contract if you want the user to only call certain functions in a predefined order. Like if you want your client to call func1, then func2 and then func3 and not in any other way. CallOrderControl manages that.

It can also manage cases where you want just a function to be called X times regardless of the order, or even X times taking into account the order.


✨ How to use ✨

  1. Make your contract inherit CallOrderControl and add the isAllowedCall() modifier in the functions you desire to control. Make sure to pass the correct arguments:

    1.1 -> Function selector of the function where it's being applied: bytes4(keccak256(bytes("funcSignatureAsString")))

    1.2 -> msg.sender => to know who is calling.

  2. Additionally you can override callAllowFuncCallsFor() if you please mixing this functionality with, for example, other useful ones like Owner or AccessControl contracts from OpenZeppelin.

Check a simple implemented example at UseCaseContract.sol.


πŸ“° Last Changes πŸ“°

  • Fixed bug, funcToCallsLeft mapping now is overwritten correctly. In previous version it could overflow and/or lead to unexpected behaviours.

  • Added getIsSequence() function.

  • Deleted argument _isSequence ins getAllowedFuncCalls().

  • New tests in tests' repository.

πŸŽ‰ FUTURE IMPROVEMENTS πŸŽ‰

  • Improve and review (static analysis, audit...) code's tests.

  • Test in testnet.

  • Create modifier locker. Make it more flexible and be able to activate or deactivate CallControl in your functions.

  • Check if worth it to create better option: adding more allowed calls to client who hasn't used all of them. Now it overwrites.

  • Check gas implications of changing 4 bytes function selector to 32 bytes hashed function signatures.


πŸ“¨ Contact πŸ“¨

Carlos Alegre UrquizΓΊ - calegreu@gmail.com


β˜• Buy me a CryptoCoffee β˜•

Buy me a crypto coffe in ETH, MATIC or BNB β˜•πŸ§β˜• (or tokens if you please :p )

0x2365bf29236757bcfD141Fdb5C9318183716d866


πŸ“œ License πŸ“œ

Distributed under the MIT License. See LICENSE in the repository for more information.

About

Solidity smart contract that ensures your functions are only called by an address in a previously allowed order or a previously allowed number of times.

License:MIT License


Languages

Language:Solidity 100.0%