Skip to content

Instantly share code, notes, and snippets.

View mudgen's full-sized avatar

Nick Mudge mudgen

View GitHub Profile
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// A contract that implements Diamond Storage.
library LibA {
// This struct contains state variables we care about.
struct DiamondStorage {
address owner;
bytes32 dataA;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// Find facet for function that is called and execute the
// function if a facet is found and return any value.
fallback() external payable {
// get facet from function selector
address facet = selectorTofacet[msg.sig];
require(facet != address(0));
// Execute external function from facet using delegatecall and return any value.
//LibAppStorage.sol
struct AppStorage {
uint256 secondVar;
uint256 firstVar;
uint256 lastVar;
...
}
library LibAppStorage {
//LibAppStorage.sol
struct AppStorage {
uint256 secondVar;
uint256 firstVar;
uint256 lastVar;
...
}
library LibAppStorage {
//LibAppStorage.sol
struct AppStorage {
uint256 secondVar;
uint256 firstVar;
uint256 lastVar;
...
}
library LibAppStorage {
// AppStorage.sol
struct AppStorage {
uint256 secondVar;
uint256 firstVar;
uint256 lastVar;
...
}
// StakingFacet.sol
import "./AppStorage.sol"
// AppStorage.sol
struct AppStorage {
uint256 secondVar;
uint256 firstVar;
uint256 lastVar;
...
}
// StakingFacet.sol
import "./AppStorage.sol"
// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;
contract ContractA {
string internal tokenName = "FunToken";
function initialize() external {
address contractBAddress = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "depositor",
"type": "address"
},
@mudgen
mudgen / using-delegatecall-safely.sol
Last active September 20, 2020 18:18
Example showing how to use DELEGATECALL
// Author: Nick Mudge (https://twitter.com/mudgen)
// This is part of my tweet thread, "Six things you need to know to use DELEGATECALL safely": https://twitter.com/mudgen
// Shows how to use DELEGATECALL
// Using OpenZeppelin's Address library check to see if
// myContract has code.
require(Address.isContract(myContractAddress), "Address has no code");
// Set function argument we are going to use.
uint myArg = 10;