awesome-solidity-patterns icon indicating copy to clipboard operation
awesome-solidity-patterns copied to clipboard

TODO

Open liamzebedee opened this issue 6 years ago • 4 comments

https://github.com/OpenZeppelin/openzeppelin-solidity/tree/master/contracts

https://github.com/0xProject/0x-monorepo

liamzebedee avatar Sep 18 '18 15:09 liamzebedee

https://ethereum.stackexchange.com/questions/32354/mapping-to-contract

You're bringing the whole bytecode of MyContract into MappingExample. The code for MyContract isn't shown, but let's say it's near the gasLimit because it's a complex beast. MappingExample will be that big plus additional bytecode for its own function. Multiple layers of this style lead to contracts that are too large to be deployed. This is what happens when you say MyContract c. You could just as well say MyContractInterface c and it would be smaller.

liamzebedee avatar Sep 18 '18 16:09 liamzebedee

explain linking

https://ethereum.stackexchange.com/questions/17558/what-does-deploy-link-exactly-do-in-truffle

liamzebedee avatar Sep 18 '18 17:09 liamzebedee

how to issue a token contract and then access it from other areas of codebase.

https://sourcegraph.com/github.com/AugurProject/augur-core@master/-/blob/source/contracts/trading/FillOrder.sol#L104

https://sourcegraph.com/github.com/AugurProject/augur-core@master/-/blob/source/contracts/reporting/Universe.sol#L49:27

liamzebedee avatar Sep 20 '18 12:09 liamzebedee

Delegate pattern:

  • Controller: register of all contracts
  • IControlled - inheritance gives access to singleton controller instance throughout code
  • Delegator responsible for forwarding calls to the contract registered in the controller. Looking up contract address from controller, delegatecall'ing the contract, and then returning the data (asm)
  • Delegator _delegator = new Delegator(_controller, "ReputationToken"); will forward calls to the contract registered by the name "ReputationToken"
  • registration occurs in the deployment process
  • IReputationToken _reputationToken = IReputationToken(_delegator); the interface provides the ABI typings to interact with the delegated contract
  • _reputationToken.initialize(_universe); initialise is a generic pattern to inject the controller instance
contract ReputationTokenFactory {
    function createReputationToken(IController _controller, IUniverse _universe) public returns (IReputationToken) {
        Delegator _delegator = new Delegator(_controller, "ReputationToken");
        IReputationToken _reputationToken = IReputationToken(_delegator);
        _reputationToken.initialize(_universe);
        return _reputationToken;
    }
}

https://sourcegraph.com/github.com/AugurProject/augur-core@master/-/blob/source/contracts/factories/ReputationTokenFactory.sol#L11:60

liamzebedee avatar Sep 20 '18 12:09 liamzebedee