Skip to main content

Resolver’s setup script example

Below is the script which executes the following steps to become a resolver

  1. Approves staking 1inch for 1inch contract
  2. Stakes 1inch to get unicorn power
  3. Adds a delegation pod to enable power delegation
  4. Registers self to be a resolver
  5. Changes the default farm to a new farm (optional, default can be used)
  6. Delegates available unicorn power to self
  7. Registers a resolver at the whitelist
  8. Sets up a worker to settle fusion orders

Setup script example#

const { ether, time } = require('@1inch/solidity-utils');const { ethers } = require('hardhat');
// Setup envirementconst inch = await ethers.getContractAt('IERC20', '0x111111111117dc0aa78b770fa6a738034120c302');const st1inch = await ethers.getContractAt('IERC20', '0x9a0c8ff858d273f57072d714bca7411d717501d7');const powerPod = await ethers.getContractAt('IERC20', '0xdaf782667d98d5069ee7ba139932945c4d08fde9');const whitelist = await ethers.getContractAt('WhitelistRegistry', '0xa49ecb28cc8ab39659be2bfb6f7b86f0c4461a0b');
const stakeAmount = ether('1000000');const lockTime = time.duration.years('2');const myShareToken = {    name: 'MyShareTokenName',    symbol: 'MST',};const worker = '...'; // Address of wallet which send transactionconst [resolver] = await ethers.getSigners();
// Ethers setup script
// approve 1inch stakingawait (await inch.connect(resolver).approve(st1inch.address, stakeAmount));// stake 1inch tokenawait (await st1inch.connect(resolver).deposit(stakeAmount, lockTime)).wait();// add delegation pod to// 1. make it possible for any user to delegate staking power to// the resolver's account// 2. make it possible for a resolver to allocate its staking power for itselfawait (await st1inch.connect(resolver).addPod(powerPod.address)).wait();
// register resolver's delegation token to count stakers' shares and rewardsawait (    await powerPod        .connect(resolver)        .functions['register(string,string)'](            myShareToken.name,            myShareToken.symbol,        )).wait();
// Set default rewards farm// Optional, needed to incentivize staker for delegationconst shareTokenAddress = await powerPod.registration(resolver.address);const FarmingPod = await ethers.getContractFactory('FarmingPod');const gift = await ethers.getContractAt('IERC20', '...'); // Your gift token addressconst farm = await FarmingPod.deploy(shareTokenAddress.address, gift.address);await (await powerPod.connect(resolver).setDefaultFarm(farm.address)).wait();
// Delegate staked power to selfawait (await powerPod.connect(resolver).delegate(resolver.address)).wait();
// Whitelist resolver (there should be enough staked power to be in top 5)await (await whitelist.connect(resolver).register()).wait();
// Add worker address from which order settlement will be executedawait (await whitelist.connect(resolver).promote(1, worker)).wait();