Skip to content

Instantly share code, notes, and snippets.

@gnidan
Last active April 6, 2020 02:50
Show Gist options
  • Save gnidan/54ab7cd920460015d73c012128a88041 to your computer and use it in GitHub Desktop.
Save gnidan/54ab7cd920460015d73c012128a88041 to your computer and use it in GitHub Desktop.
Diamond / Truffle discussion with @mudgen
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