For the visually inclined, view our video explainer HERE.
Example Code
Hardhat Example
We recommend including the following imports and deployment scripts when setting up your hardhat tests. The deployTestFramework() script will allow you to deploy the framework using the SuperfluidFrameworkDeployer contract, and to call deployWrapperSuperToken() to mint fake Super Tokens for your tests.
Dependencies you'll need are listed at the top of the file, but if you already have a hardhat project set up, you'll likely only need @superfluid-finance/sdk-core and @superfluid-finance/ethereum-contracts.
const { expect } =require("chai")const { Framework } =require("@superfluid-finance/sdk-core")const { ethers } =require("hardhat")const { deployTestFramework } =require("@superfluid-finance/ethereum-contracts/dev-scripts/deploy-test-framework");constTestToken=require("@superfluid-finance/ethereum-contracts/build/contracts/TestToken.json")let sfDeployerlet contractsFrameworklet sflet moneyRouterlet dailet daix// Test Accountslet ownerlet account1let account2constthousandEther=ethers.utils.parseEther("10000")before(asyncfunction () {// get hardhat accounts [owner, account1, account2] =awaitethers.getSigners(); sfDeployer =awaitdeployTestFramework();// GETTING SUPERFLUID FRAMEWORK SET UP// deploy the framework locally contractsFramework =awaitsfDeployer.frameworkDeployer.getFramework()// initialize framework sf =awaitFramework.create({ chainId:31337, provider:owner.provider, resolverAddress:contractsFramework.resolver,// (empty) protocolReleaseVersion:"test" })// // DEPLOYING DAI and DAI wrapper super token (which will be our `spreaderToken`) tokenDeployment =awaitsfDeployer.frameworkDeployer.deployWrapperSuperToken("Fake DAI Token","fDAI",18,ethers.utils.parseEther("100000000").toString() );// DEPLOYING DAI and DAI wrapper super token (which will be our `spreaderToken`) daix =awaitsf.loadSuperToken("fDAIx") dai =newethers.Contract(daix.underlyingToken.address,TestToken.abi, owner )// minting test DAIawaitdai.mint(owner.address, thousandEther)awaitdai.mint(account1.address, thousandEther)awaitdai.mint(account2.address, thousandEther) // approving DAIx to spend DAI (Super Token object is not an ethers contract object and has different operation syntax)
awaitdai.approve(daix.address,ethers.constants.MaxInt256)await dai.connect(account1).approve(daix.address,ethers.constants.MaxInt256)await dai.connect(account2).approve(daix.address,ethers.constants.MaxInt256)// Upgrading all DAI to DAIxconstownerUpgrade=daix.upgrade({amount: thousandEther});constaccount1Upgrade=daix.upgrade({amount: thousandEther});constaccount2Upgrade=daix.upgrade({amount: thousandEther});awaitownerUpgrade.exec(owner)awaitaccount1Upgrade.exec(account1)awaitaccount2Upgrade.exec(account2)let MoneyRouter =awaitethers.getContractFactory("MoneyRouter", owner) moneyRouter =awaitMoneyRouter.deploy(owner.address )awaitmoneyRouter.deployed()});//Write your tests...