LogoLogo
  • 🌊Superfluid
  • Protocol Overview
    • šŸ’”What is Superfluid?
    • šŸ“„In-Depth Overview
      • Super Tokens
      • Super Agreements
        • 🚰Money Streaming (CFA)
        • āœ³ļøDistributions (IDA)
        • 🌊Streaming Distributions
      • Super Apps
      • Superfluid Host
    • 🧠Use Cases
      • Recurring Payments
      • DeFi
      • Social & Community
      • Gaming
    • šŸ“”Glossary of Terms
  • Developers
    • šŸƒQuickstart
    • šŸŖ™Super Tokens
      • Super Tokens - Solidity
      • Super Tokens - SDK Core
      • Super Tokens - Frontend Examples
      • Types of Super Tokens
      • Deploy a Super Token
        • Deploying a Wrapper Super Token
        • Deploying a Self Governed Super Token
        • Deploying a Pure Super Token
      • In-Depth
        • Tracking Super Token Balances
        • ERC777 in Super Tokens
      • Test Super Token Faucet
    • 🌊Money Streaming (CFA)
      • Solidity
        • Read Methods
          • getFlowInfo
          • getFlowRate
          • getNetFlowRate
        • Write Methods
          • createFlow
          • updateFlow
          • deleteFlow
          • With User Data
          • With Context
      • SDK Core
        • Read Methods
          • getFlow
          • getNetFlow
          • getAccountFlowInfo
        • Write Methods
          • createFlow
          • updateFlow
          • deleteFlow
      • Access Control List (ACL)
        • Solidity
          • createFlowFrom
          • updateFlowFrom
          • deleteFlowFrom
          • setFlowPermissions
          • setMaxFlowPermissions
          • revokeFlowPermissions
          • increaseFlowRateAllowanceWithPermissions
          • decreaseFlowRateAllowanceWithPermissions
          • getFlowPermissions
        • SDK Core
          • createFlowByOperator
          • updateFlowByOperator
          • deleteFlowByOperator
          • updateFlowOperatorPermissions
          • revokeFlowOperatorPermissions
          • increaseFlowRateAllowanceWithPermissions
          • getFlowOperatorData
      • Frontend Examples
      • More...
        • Flow Rate Time Frames
        • Building Batched Streams in Safe
        • Flow NFTs
    • āœ³ļøDistributions (IDA)
      • IDA - Solidity
      • IDA - SDK Core
      • IDA - Frontend Examples
    • šŸ¤–Super Apps
      • Super Apps in Depth
      • Super App Callbacks
        • Calling Agreements In Super Apps
      • User Data
        • NFT Billboard Example
      • SuperAppBaseFlow
      • Super App Examples
      • Super App Deployment Guide
    • 🧺Batch Calls
      • Batch Calls - SDK Core
      • Batch Calls - Frontend Examples
    • āš™ļøAutomations
      • Auto-Wrap
        • Dev Guide
      • Stream Scheduler
        • Dev Guide
      • Vesting Scheduler
        • Dev Guide
      • Stream Accounting API
        • Dev Guide
      • Automation Subgraphs
        • Stream Scheduler Subgraph
        • Vesting Scheduler Subgraph
        • Auto Wrap Subgraph
    • šŸ—ļøIntegration Guides
      • For Your Integration: The Basics
        • Supporting Super Tokens
        • Supporting Money Streams
        • Supporting Instant Distributions
      • Gating with Superfluid Subscriptions & Guild.xyz
      • Displaying Token Balances
      • Useful Queries for Your Integration
        • Instant Distribution Events
        • Money Streaming Events
        • Super Token Events
        • Other Helpful Queries
      • Constructing Links to The Superfluid Dashboard
    • šŸ”Superfluid Subscriptions
      • Superfluid Checkout Widget
      • Implementing Subscriptions in your App
    • SDK Core General
      • Initialization
      • Functionality
      • Getting Data
      • Resolver
      • Reference Docs
    • Solidity General
      • Calling Super Agreements
      • Libraries
      • Resolver
    • Testing Guide
      • Hardhat Testing
      • Foundry Testing
      • In-Depth
        • Hardhat Mainnet Fork Testing
        • Super App Testing on Mainnet Forks
    • Subgraph
    • Reference
      • Deploying The Framework
      • EVM Contracts
      • SDK Redux
      • Superfluid Console
      • Superfluid Protocol Addresses
    • Contract Addresses
  • Sentinels
    • šŸ„…Liquidations & TOGA
    • šŸ¤–Running a Sentinel
    • šŸ—ŗļøSolvency Dashboard
  • Resources
    • 🌊Superfluid Wave Pool
    • šŸ“œSuperfluid on Ethereum Mainnet
    • šŸ’°Bounty Program
    • šŸ›”ļøSecurity & Bug Bounties
    • šŸ’”Project Ideas
    • šŸ—³ļøToken Dashboard Submission
    • šŸŽ„Videos
    • Superfluid Deployment Guide
    • Learn about Ethereum
    • Code of Conduct
Powered by GitBook
On this page

Was this helpful?

  1. Developers
  2. Testing Guide
  3. In-Depth

Super App Testing on Mainnet Forks

Learn how to test Super Apps on Hardhat mainnet forks

PreviousHardhat Mainnet Fork TestingNextSubgraph

Last updated 2 years ago

Was this helpful?

This section is based off the of , 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

const HOST_ABI = ["function getGovernance() external view returns (address)"];
const HOST_ADDR = "0x3E14dC1b13c488a8d5D310918780c983bD5982E7";

const hostInstance = new ethers.Contract(HOST_ADDR, HOST_ABI, <<providerOrSigner>>);

Next, let's get an instance of the Superfluid Governance contract and its owner's address.

const GOV_ABI = [
  "function setConfig(address host, address superToken, bytes32 key, uint256 value) external",
  "function setAppRegistrationKey(address host, address deployer, string memory registrationKey, uint256 expirationTs) external",
  "function getConfigAsUint256(address host, address superToken, bytes32 key) external view returns (uint256 value)",
  "function verifyAppRegistrationKey(address host, address deployer, string memory registrationKey) external view returns (bool validNow, uint256 expirationTs)",
  "function owner() public view returns (address)",
];

const govInstance = new ethers.Contract(
  await hostInstance.getGovernance(),
  GOV_ABI,
  <<providerOrSigner>>
);

const govOwnerAddr = await govInstance.owner();

Now, impersonate the governance owner!

// 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!

const superAppFactory = await hre.ethers.getContractFactory(<<SuperAppContractName>>);
const mySuperApp = await factory.deploy(HOST_ADDR, registrationKey);

await mySuperApp.deployed();
work
omnifient