Last active
April 6, 2020 02:50
-
-
Save gnidan/54ab7cd920460015d73c012128a88041 to your computer and use it in GitHub Desktop.
Diamond / Truffle discussion with @mudgen
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
const Diamond = artifacts.require("Diamond"); // can this return a special Diamond abstraction? | |
const MyToken = artifacts.require("MyToken"); | |
// - create a config to enable the EIP-2535 Diamond spec | |
// - when that config is enabled, check for the Diamond EIP-165 functions (so we know when we have a Diamond) | |
// - add special behavior to the @truffle/contract abstraction when EIP-2535 is detected | |
module.exports = async (deployer) => { | |
await deployer.deploy(Diamond); | |
const diamond = await Diamond.deployed(); | |
await deployer.deploy(MyToken); | |
const token = await MyToken.deployed(); | |
/* | |
* if we don't have a special Diamond abstraction | |
*/ | |
await deployer.diamond(diamond).cut( | |
token.transfer, | |
token.totalSupply | |
); | |
const diamondAsMyToken = await MyToken.at(diamond.address); | |
await diamondAsMyToken.transfer(...); | |
/* | |
* if we do have a special Diamond abstraction | |
*/ | |
await diamond.cut( | |
token.transfer, | |
token.totalSupply | |
); | |
await diamond.transfer(...); | |
// given a special EIP-2535 abstraction instance, we can use the following | |
// to detect all the methods (and thus that's where .transfer can come from) | |
await diamond.facets(); // throws if no Loupe exists - no biggie, just don't get special methods | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment