Learn how to test Super Apps on Hardhat mainnet forks
This section is based off the work of omnifient, a valued community member rš
In order for a Super App's callbacks to work, it needs to be registered with the Superfluid host.
On testnets, this is done permissionlessly, but on a mainnet it requires a registration key which is permissioned by Superfluid governance. See the constructor below š
constructor(
ISuperfluid host,
string memory registrationKey
) {
uint256 configWord = SuperAppDefinitions.APP_LEVEL_FINAL |
SuperAppDefinitions.BEFORE_AGREEMENT_CREATED_NOOP |
SuperAppDefinitions.BEFORE_AGREEMENT_UPDATED_NOOP |
SuperAppDefinitions.BEFORE_AGREEMENT_TERMINATED_NOOP;
if (bytes(registrationKey).length > 0) {
// works on MAINNET
host.registerAppWithKey(configWord, registrationKey);
} else {
// works on TESTNET
host.registerApp(configWord);
}
}
So, in order to test a Super App on a mainnet fork, you are going to need to be able to simulate the creation of a registration key so that you can provide it to your Super App upon deployment.
Here's how you do it in Hardhat's Node.js-based environment.
Simulating Creation of a Registration Key
First, get an instance of the Superfluid Host. Here, we're just setting up the instance with the only function we'll be using - getGovernance
// impersonate the governance owner
await network.provider.request({
method: "hardhat_impersonateAccount",
params: [govOwnerAddr],
});
// give it a lot of ETH (or MATIC because we're on Polygon!)
await network.provider.send("hardhat_setBalance", [
govOwnerAddr,
hexValue(parseEther("1000000")),
]);
const govOwnerSigner = await ethers.getSigner(govOwnerAddr);
Time to make your registration key
// Set your registration key string
const registrationKey = `GM-${Date.now()}`;
// Get a configuration key
const configKey = ethers.utils.keccak256(
ethers.utils.defaultAbiCoder.encode(
["string", "address", "string"],
[
"org.superfluid-finance.superfluid.appWhiteListing.registrationKey",
<<account that will deploy the Super App>>,
registrationKey
]
)
);
// Set it in Governance - now your registrationKey is good to go!
let tx = await govInstance.setConfig(
HOST_ADDR,
"0x0000000000000000000000000000000000000000",
configKey,
Math.floor(Date.now() / 1000) + 3600 * 24 * 180 // 180 day expiration for key
);
await tx.wait();
Finally, deploy the Super App with the registrationKey you've permissioned!