-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
151 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,16 @@ | |
pragma solidity ^0.7.1; | ||
pragma experimental ABIEncoderV2; | ||
|
||
/******************************************************************************\ | ||
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen) | ||
/******************************************************************************/ | ||
|
||
interface IDiamondCut { | ||
struct Facet { | ||
enum FacetCutAction {Add, Replace, Remove} | ||
|
||
struct FacetCut { | ||
address facetAddress; | ||
FacetCutAction action; | ||
bytes4[] functionSelectors; | ||
} | ||
|
||
|
@@ -15,10 +22,10 @@ interface IDiamondCut { | |
/// @param _calldata A function call, including function selector and arguments | ||
/// _calldata is executed with delegatecall on _init | ||
function diamondCut( | ||
Facet[] calldata _diamondCut, | ||
FacetCut[] calldata _diamondCut, | ||
address _init, | ||
bytes calldata _calldata | ||
) external; | ||
|
||
event DiamondCut(Facet[] _diamondCut, address _init, bytes _calldata); | ||
event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,43 @@ | ||
/* eslint-disable prefer-const */ | ||
/* global artifacts */ | ||
|
||
const Diamond = artifacts.require('Diamond') | ||
const DiamondCutFacet = artifacts.require('DiamondCutFacet') | ||
const DiamondLoupeFacet = artifacts.require('DiamondLoupeFacet') | ||
const OwnershipFacet = artifacts.require('OwnershipFacet') | ||
const Test1Facet = artifacts.require('Test1Facet') | ||
const Test2Facet = artifacts.require('Test2Facet') | ||
|
||
const FacetCutAction = { | ||
Add: 0, | ||
Replace: 1, | ||
Remove: 2 | ||
} | ||
|
||
function getSelectors (contract) { | ||
const selectors = contract.abi.reduce((acc, val) => { | ||
if (val.type === 'function') { | ||
acc.push(val.signature) | ||
return acc | ||
} else { | ||
return acc | ||
} | ||
}, []) | ||
return selectors | ||
} | ||
|
||
module.exports = function (deployer, network, accounts) { | ||
// deployment steps | ||
// The constructor inside Diamond deploys DiamondFacet | ||
deployer.deploy(Diamond, accounts[0]) | ||
deployer.deploy(Test1Facet) | ||
deployer.deploy(Test2Facet) | ||
|
||
deployer.deploy(DiamondCutFacet) | ||
deployer.deploy(DiamondLoupeFacet) | ||
deployer.deploy(OwnershipFacet).then(() => { | ||
const diamondCut = [ | ||
[DiamondCutFacet.address, FacetCutAction.Add, getSelectors(DiamondCutFacet)], | ||
[DiamondLoupeFacet.address, FacetCutAction.Add, getSelectors(DiamondLoupeFacet)], | ||
[OwnershipFacet.address, FacetCutAction.Add, getSelectors(OwnershipFacet)] | ||
] | ||
return deployer.deploy(Diamond, accounts[0], diamondCut) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.