From e05e531ef54f9c54d7168a8c869fa3b497087324 Mon Sep 17 00:00:00 2001 From: BkChoy Date: Wed, 23 Oct 2024 09:10:22 -0400 Subject: [PATCH] rewrote test env setup scripts --- package.json | 3 +- scripts/test/deploy/deploy.ts | 6 +- ...test-contracts.ts => deploy-deprecated.ts} | 8 +- .../deploy/modules/deploy-link-staking.ts | 24 +- .../deploy/modules/deploy-metis-staking.ts | 21 +- scripts/test/deploy/modules/deploy-other.ts | 44 ++ scripts/test/setup-test-env.ts | 407 ------------------ scripts/test/setup/modules/setup-core.ts | 69 +++ .../test/setup/modules/setup-link-staking.ts | 220 ++++++++++ .../test/setup/modules/setup-metis-staking.ts | 163 +++++++ scripts/test/setup/modules/setup-other.ts | 16 + scripts/test/setup/setup-test-env.ts | 22 + scripts/utils/helpers.ts | 6 +- yarn.lock | 12 + 14 files changed, 580 insertions(+), 441 deletions(-) rename scripts/test/deploy/modules/{deploy-test-contracts.ts => deploy-deprecated.ts} (85%) create mode 100644 scripts/test/deploy/modules/deploy-other.ts delete mode 100644 scripts/test/setup-test-env.ts create mode 100644 scripts/test/setup/modules/setup-core.ts create mode 100644 scripts/test/setup/modules/setup-link-staking.ts create mode 100644 scripts/test/setup/modules/setup-metis-staking.ts create mode 100644 scripts/test/setup/modules/setup-other.ts create mode 100644 scripts/test/setup/setup-test-env.ts diff --git a/package.json b/package.json index e3f24783..14cf4900 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "deploy": "ts-node --files scripts/test/deploy/deploy.ts", "geth-dev-fund": "ts-node --files scripts/test/geth-dev-fund.ts", "start-test-env": "node scripts/test/start-test-envs.js", - "setup-test-env": "ts-node --files scripts/test/setup-test-env.ts", + "setup-test-env": "ts-node --files scripts/test/setup/setup-test-env.ts", "compile": "npx hardhat compile", "tsc": "tsc", "prettier": "prettier --check \"contracts/**/*.sol*\" \"test/**/*.ts*\" \"scripts/**/*.ts*\"", @@ -36,6 +36,7 @@ "@types/fs-extra": "^11.0.4", "@types/mocha": ">=9.1.0", "@types/node": ">=18.0.0", + "bs58": "^6.0.0", "chai": "^4.2.0", "ethers": "^6.4.0", "fs-extra": "^11.2.0", diff --git a/scripts/test/deploy/deploy.ts b/scripts/test/deploy/deploy.ts index 0aff96f3..a799d91f 100644 --- a/scripts/test/deploy/deploy.ts +++ b/scripts/test/deploy/deploy.ts @@ -2,7 +2,8 @@ import fs from 'fs' import { deployCore } from './modules/deploy-core' import { deployLINKStaking } from './modules/deploy-link-staking' import { deployMETISStaking } from './modules/deploy-metis-staking' -import { deployTestContracts } from './modules/deploy-test-contracts' +import { deployDeprecated } from './modules/deploy-deprecated' +import { deployOther } from './modules/deploy-other' const path = './deployments/localhost.json' @@ -11,10 +12,11 @@ async function main() { fs.unlinkSync(path) } - await deployTestContracts() + await deployDeprecated() await deployCore() await deployLINKStaking() await deployMETISStaking() + await deployOther() } main() diff --git a/scripts/test/deploy/modules/deploy-test-contracts.ts b/scripts/test/deploy/modules/deploy-deprecated.ts similarity index 85% rename from scripts/test/deploy/modules/deploy-test-contracts.ts rename to scripts/test/deploy/modules/deploy-deprecated.ts index 79e5fd25..c762b0c8 100644 --- a/scripts/test/deploy/modules/deploy-test-contracts.ts +++ b/scripts/test/deploy/modules/deploy-deprecated.ts @@ -1,6 +1,6 @@ import { updateDeployments, deploy } from '../../../utils/deployment' -export async function deployTestContracts() { +export async function deployDeprecated() { const lplToken = await deploy('contracts/core/tokens/base/ERC677.sol:ERC677', [ 'LinkPool', 'LPL', @@ -15,9 +15,6 @@ export async function deployTestContracts() { ]) console.log('LINKToken deployed: ', linkToken.target) - const multicall = await deploy('Multicall3', []) - console.log('Multicall3 deployed: ', multicall.target) - const poolOwners = await deploy('PoolOwnersV1', [lplToken.target]) console.log('PoolOwners (v1) deployed: ', poolOwners.target) @@ -34,7 +31,7 @@ export async function deployTestContracts() { 'linkLPLA', poolOwners.target, ]) - console.log('PoolAllowance (v1) deployed: ', multicall.target) + console.log('PoolAllowance (v1) deployed: ', poolAllowance.target) let tx = await poolOwners.addRewardToken( linkToken.target, @@ -50,7 +47,6 @@ export async function deployTestContracts() { PoolOwnersV1: poolOwners.target, LINK_OwnersRewardsPoolV1: ownersRewardsPoolV1.target, PoolAllowanceV1: poolAllowance.target, - Multicall3: multicall.target, }, { LPLToken: 'contracts/core/tokens/base/ERC677.sol:ERC677', diff --git a/scripts/test/deploy/modules/deploy-link-staking.ts b/scripts/test/deploy/modules/deploy-link-staking.ts index b9834889..a2c382ac 100644 --- a/scripts/test/deploy/modules/deploy-link-staking.ts +++ b/scripts/test/deploy/modules/deploy-link-staking.ts @@ -34,7 +34,7 @@ async function deployOperatorVCS(vaultDepositController: string) { stakingRewardsMock.target, toEther(1000), toEther(75000), - toEther(10000000), + toEther(1000000), 28 * 86400, 7 * 86400, ]) @@ -64,7 +64,7 @@ async function deployOperatorVCS(vaultDepositController: string) { await (await linkToken.transfer(pfAlertsControllerMock.target, toEther(10000))).wait() await (await stakingPool.addStrategy(operatorVCS.target)).wait() - for (let i = 0; i < 3; i++) { + for (let i = 0; i < 5; i++) { await ( await operatorVCS.addVault(ethers.ZeroAddress, accounts[0], pfAlertsControllerMock.target) ).wait() @@ -80,9 +80,9 @@ async function deployOperatorVCS(vaultDepositController: string) { // Community Vault Controller Strategy const CommunityVCSArgs = { - maxDepositSizeBP: 9000, //basis point amount of the remaing deposit room in the Chainlink staking contract that can be deposited at once + maxDepositSizeBP: 10000, //basis point amount of the remaing deposit room in the Chainlink staking contract that can be deposited at once vaultDeploymentThreshold: 10, // the min number of non-full vaults before a new batch is deployed - vaultDeploymentAmount: 10, // amount of vaults to deploy when threshold is met + vaultDeploymentAmount: 5, // amount of vaults to deploy when threshold is met fees: [], // fee receivers & percentage amounts in basis points vaultMaxDeposits: toEther(15000), // max number of tokens that a vault can hold } @@ -97,7 +97,7 @@ async function deployCommunityVCS(vaultDepositController: string) { stakingRewardsMock.target, toEther(1000), toEther(15000), - toEther(10000000), + toEther(1000000), 28 * 86400, 7 * 86400, ]) @@ -223,6 +223,7 @@ export async function deployLINKStaking() { await (await sdlPoolPrimary.addToken(stakingPool.target, stLinkSDLRewardsPool.target)).wait() await (await stakingPool.setPriorityPool(priorityPool.target)).wait() + await (await stakingPool.setRebaseController(accounts[0])).wait() await (await priorityPool.setDistributionOracle(accounts[0])).wait() await (await priorityPool.setWithdrawalPool(withdrawalPool.target)).wait() @@ -238,9 +239,14 @@ export async function deployLINKStaking() { 7 * 86400, 5, ]) - console.log('FundFlowController deployed at', fundFlowController.target) + console.log('LINK_FundFlowController deployed at', fundFlowController.target) - updateDeployments({ - FundFlowController: fundFlowController.target, - }) + updateDeployments( + { + LINK_FundFlowController: fundFlowController.target, + }, + { + LINK_FundFlowController: 'FundFlowController', + } + ) } diff --git a/scripts/test/deploy/modules/deploy-metis-staking.ts b/scripts/test/deploy/modules/deploy-metis-staking.ts index 1b0c8eb6..3d2a8cd4 100644 --- a/scripts/test/deploy/modules/deploy-metis-staking.ts +++ b/scripts/test/deploy/modules/deploy-metis-staking.ts @@ -13,24 +13,21 @@ import { } from '../../../utils/deployment' import { getAccounts, toEther } from '../../../utils/helpers' -async function deploySequencerVCS() { +async function deployL2Strategy() { const metisToken = (await getContract('METISToken')) as ERC20 const stakingPool = (await getContract('METIS_StakingPool')) as StakingPool - const sequencerVCS = await deployUpgradeable('StrategyMock', [ + const l2Strategy = await deployUpgradeable('StrategyMock', [ metisToken.target, stakingPool.target, - toEther(1000), - toEther(10), + toEther(100000), + toEther(20000), ]) - console.log('SequencerVCS deployed: ', sequencerVCS.target) + console.log('METIS_L2Strategy deployed: ', l2Strategy.target) - await (await stakingPool.addStrategy(sequencerVCS.target)).wait() + await (await stakingPool.addStrategy(l2Strategy.target)).wait() - updateDeployments( - { METIS_SequencerVCS: sequencerVCS.target }, - { METIS_SequencerVCS: 'SequencerVCS' } - ) + updateDeployments({ METIS_L2Strategy: l2Strategy.target }, { METIS_L2Strategy: 'StrategyMock' }) } // Wrapped stMETIS @@ -109,9 +106,9 @@ export async function deployMETISStaking() { ]) console.log('stMetis_SDLRewardsPool deployed: ', stMetisSDLRewardsPool.target) - await (await stakingPool.addFee(stMetisSDLRewardsPool.target, 1000)).wait() await (await sdlPoolPrimary.addToken(stakingPool.target, stMetisSDLRewardsPool.target)).wait() await (await stakingPool.setPriorityPool(priorityPool.target)).wait() + await (await stakingPool.setRebaseController(accounts[0])).wait() await (await priorityPool.setDistributionOracle(accounts[0])).wait() await (await priorityPool.setWithdrawalPool(withdrawalPool.target)).wait() @@ -134,5 +131,5 @@ export async function deployMETISStaking() { } ) - await deploySequencerVCS() + await deployL2Strategy() } diff --git a/scripts/test/deploy/modules/deploy-other.ts b/scripts/test/deploy/modules/deploy-other.ts new file mode 100644 index 00000000..153c648c --- /dev/null +++ b/scripts/test/deploy/modules/deploy-other.ts @@ -0,0 +1,44 @@ +import { ERC677 } from '../../../../typechain-types' +import { updateDeployments, deploy, getContract } from '../../../utils/deployment' +import { getAccounts } from '../../../utils/helpers' + +const vestingStart = 1695312000 // Sep 21 2023 12pm EDT +const vestingDuration = 4 * 365 * 86400 // 4 years + +export async function deployOther() { + const { accounts } = await getAccounts() + const linkToken = (await getContract('LINKToken')) as ERC677 + const stakingPool = await getContract('LINK_StakingPool') + + // Multicall + + const multicall = await deploy('Multicall3', []) + console.log('Multicall3 deployed: ', multicall.target) + + // stLINK/LINK Curve Mock + + const curveMock = await deploy('CurveMock', [stakingPool.target, linkToken.target]) + console.log('LINK_CurvePool deployed: ', curveMock.target) + + // Node Operator SDL Vesting + + let vesting0 = await deploy('Vesting', [accounts[0], accounts[12], vestingStart, vestingDuration]) + console.log('SDL_Vesting_NOP_0 deployed: ', vesting0.target) + + let vesting1 = await deploy('Vesting', [accounts[0], accounts[13], vestingStart, vestingDuration]) + console.log('SDL_Vesting_NOP_1 deployed: ', vesting1.target) + + updateDeployments( + { + SDL_Vesting_NOP_0: vesting0.target, + SDL_Vesting_NOP_1: vesting1.target, + LINK_CurvePool: curveMock.target, + Multicall3: multicall.target, + }, + { + SDL_Vesting_NOP_0: 'Vesting', + SDL_Vesting_NOP_1: 'Vesting', + LINK_CurvePool: 'CurveMock', + } + ) +} diff --git a/scripts/test/setup-test-env.ts b/scripts/test/setup-test-env.ts deleted file mode 100644 index b4286a90..00000000 --- a/scripts/test/setup-test-env.ts +++ /dev/null @@ -1,407 +0,0 @@ -import { getAccounts, toEther } from '../utils/helpers' -import { - getContract, - deployUpgradeable, - deploy, - updateDeployments, - printDeployments, -} from '../utils/deployment' -import { - LPLMigration, - StakingAllowance, - StakingPool, - ERC677, - StrategyMock, - PriorityPool, - DelegatorPool, - CurveMock, - SDLPoolPrimary, - ERC20, -} from '../../typechain-types' -import { ethers } from 'hardhat' - -/* -Accounts: -0 - main account that holds most of the tokens. Do not test ui with this account. -1 - holds no tokens -2 - holds SDL/LPL/LINK/METIS + has staked LPL + has PoolOwners LINK rewards -3 - holds SDL/LPL/LINK/METIS + stSDL/stLINK + has DelegatorPool stLINK rewards -4 - holds SDL/LPL/LINK/METIS + stLINK + has queued LINK + has withdrawable stLINK in the queue -5 - holds SDL/LPL/LINK/METIS + reSDL + has queued LINK + has SDLPool stLINK rewards -6 - holds SDL/LPL/LINK/METIS + reSDL (locked) + has queued LINK + has withdrawable stLINK in the queue -7 - holds SDL/LPL/LINK/METIS + has queued LINK -8 - holds SDL/LPL/LINK/METIS + stLINK + has queued LINK + cannot withdraw full queued LINK amount -*/ - -/* -Staking Queue IPFS mock data -CID: QmV1N49KT7at9LpNxyyPnCNBLEztMFHvLXoHpdPRoUzGgz -data: -{ - "merkleRoot": "0x52171b32a0a6c33f6756c5c33673790b66945c4f1c4ec4a81932e60b06b5a321", - "data": { - "0x0000000000000000000000000000000000000000": { - "amount": "0", - "sharesAmount": "0" - }, - "0x555f27995D7BB56c989d7C1cA4e5e03e930ecA67": { - "amount": "50000000000000000000", - "sharesAmount": "25000000000000000000" - }, - "0xccc41e903D40e13bC87eE29413219d33a1161f72": { - "amount": "0", - "sharesAmount": "0" - }, - "0x65079BB3f085240f1AFCBb3E4188afE93c194b84": { - "amount": "150000000000000000000", - "sharesAmount": "75000000000000000000" - } - } -} -*/ - -async function main() { - const { signers, accounts } = await getAccounts() - const sdlToken = (await getContract('SDLToken')) as StakingAllowance - const lplMigration = (await getContract('LPLMigration')) as LPLMigration - const LINK_StakingPool = (await getContract('LINK_StakingPool')) as StakingPool - const linkToken = (await getContract('LINKToken')) as ERC677 - const LINK_PriorityPool = (await getContract('LINK_PriorityPool')) as PriorityPool - const delegatorPool = (await getContract('DelegatorPool')) as DelegatorPool - const lplToken = (await getContract('LPLToken')) as ERC677 - - const poolOwnersV1 = (await getContract('PoolOwnersV1')) as any - const ownersRewardsPoolV1 = (await getContract('LINK_OwnersRewardsPoolV1')) as any - const sdlPool = (await getContract('SDLPool')) as SDLPoolPrimary - - const METISToken = (await getContract('METISToken')) as ERC20 - const METIS_StakingPool = (await getContract('METIS_StakingPool')) as StakingPool - const METIS_PriorityPool = (await getContract('METIS_PriorityPool')) as PriorityPool - - const strategyMockMETIS = (await ethers.getContractAt( - 'StrategyMock', - ( - await METIS_StakingPool.getStrategies() - )[0] - )) as StrategyMock - - // LPL migration - - let tx = await sdlToken.mint(lplMigration.target, toEther(100000)) - await tx.wait() - - // LINK Staking - - await (await LINK_StakingPool.removeStrategy(0, '0x', '0x')).wait() - await (await LINK_StakingPool.removeStrategy(0, '0x', '0x')).wait() - - const strategyMockLINK = (await deployUpgradeable('StrategyMock', [ - linkToken.target, - LINK_StakingPool.target, - toEther(1000), - toEther(10), - ])) as StrategyMock - tx = await LINK_StakingPool.addStrategy(strategyMockLINK.target) - await tx.wait() - tx = await LINK_PriorityPool.setDistributionOracle(accounts[0]) - await tx.wait() - - let stLINK_DelegatorRewardsPool = await deploy('RewardsPool', [ - delegatorPool.target, - LINK_StakingPool.target, - ]) - tx = await delegatorPool.addToken(LINK_StakingPool.target, stLINK_DelegatorRewardsPool.target) - await tx.wait() - - updateDeployments( - { - stLINK_DelegatorRewardsPool: stLINK_DelegatorRewardsPool.target, - }, - { - stLINK_DelegatorRewardsPool: 'RewardsPool', - } - ) - // Basic Curve Mock - - const curveMock = (await deploy('CurveMock', [ - LINK_StakingPool.target, - linkToken.target, - ])) as CurveMock - tx = await linkToken.transfer(curveMock.target, toEther(1000)) - await tx.wait() - - updateDeployments({ - CurvePool: curveMock.target.toString(), - }) - - // Accounts - - for (let i = 2; i < accounts.length; i++) { - tx = await sdlToken.mint(accounts[i], toEther(10000)) - await tx.wait() - tx = await lplToken.transfer(accounts[i], toEther(10000)) - await tx.wait() - tx = await linkToken.transfer(accounts[i], toEther(10000)) - await tx.wait() - tx = await METISToken.transfer(accounts[i], toEther(10000)) - await tx.wait() - } - - tx = await linkToken.transferAndCall( - LINK_PriorityPool.target, - toEther(500), - ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes[]'], [false, ['0x']]) - ) - - await (await METISToken.approve(METIS_PriorityPool.target, ethers.MaxUint256)).wait() - await (await METIS_PriorityPool.deposit(toEther(500), false, ['0x'])).wait() - - // Account 2 - - tx = await lplToken.connect(signers[2]).transferAndCall(poolOwnersV1.target, toEther(10), '0x') - await tx.wait() - tx = await linkToken.transfer(ownersRewardsPoolV1.target, toEther(10)) - await tx.wait() - tx = await ownersRewardsPoolV1.distributeRewards() - await tx.wait() - - // stSDL - - // Account 3 - tx = await sdlToken.connect(signers[3]).transferAndCall(delegatorPool.target, toEther(1000), '0x') - await tx.wait() - - // Account 9 - tx = await sdlToken.connect(signers[9]).transferAndCall(delegatorPool.target, toEther(1000), '0x') - await tx.wait() - - // Account 10 - tx = await sdlToken - .connect(signers[10]) - .transferAndCall(delegatorPool.target, toEther(1000), '0x') - await tx.wait() - - // Account 11 - tx = await sdlToken - .connect(signers[11]) - .transferAndCall(delegatorPool.target, toEther(1000), '0x') - await tx.wait() - - // Account 12 - tx = await sdlToken - .connect(signers[12]) - .transferAndCall(delegatorPool.target, toEther(1000), '0x') - await tx.wait() - - // Account 13 - tx = await sdlToken - .connect(signers[13]) - .transferAndCall(delegatorPool.target, toEther(1000), '0x') - await tx.wait() - - tx = await linkToken - .connect(signers[3]) - .transferAndCall( - LINK_PriorityPool.target, - toEther(100), - ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes[]'], [false, ['0x']]) - ) - await tx.wait() - await ( - await METISToken.connect(signers[3]).approve(METIS_PriorityPool.target, ethers.MaxUint256) - ).wait() - await (await METIS_PriorityPool.connect(signers[3]).deposit(toEther(100), false, ['0x'])).wait() - - await tx.wait() - tx = await LINK_StakingPool.transferAndCall(delegatorPool.target, toEther(100), '0x') - await tx.wait() - tx = await delegatorPool.retireDelegatorPool([], sdlPool.target) - await tx.wait() - - // Account 4 - - tx = await linkToken - .connect(signers[4]) - .transferAndCall( - LINK_PriorityPool.target, - toEther(500), - ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes[]'], [true, ['0x']]) - ) - await tx.wait() - await ( - await METISToken.connect(signers[4]).approve(METIS_PriorityPool.target, ethers.MaxUint256) - ).wait() - await (await METIS_PriorityPool.connect(signers[4]).deposit(toEther(500), true, ['0x'])).wait() - - // Account 5 - - tx = await sdlToken - .connect(signers[5]) - .transferAndCall( - sdlPool.target, - toEther(2000), - ethers.AbiCoder.defaultAbiCoder().encode(['uint256', 'uint64'], [0, 0]) - ) - await tx.wait() - - tx = await linkToken - .connect(signers[5]) - .transferAndCall( - LINK_PriorityPool.target, - toEther(200), - ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes[]'], [true, ['0x']]) - ) - await ( - await METISToken.connect(signers[5]).approve(METIS_PriorityPool.target, ethers.MaxUint256) - ).wait() - await (await METIS_PriorityPool.connect(signers[5]).deposit(toEther(200), true, ['0x'])).wait() - - // Account 6 - - tx = await sdlToken - .connect(signers[6]) - .transferAndCall( - sdlPool.target, - toEther(1000), - ethers.AbiCoder.defaultAbiCoder().encode(['uint256', 'uint64'], [0, 365 * 86400]) - ) - await tx.wait() - tx = await linkToken - .connect(signers[6]) - .transferAndCall( - LINK_PriorityPool.target, - toEther(300), - ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes[]'], [true, ['0x']]) - ) - await tx.wait() - await ( - await METISToken.connect(signers[6]).approve(METIS_PriorityPool.target, ethers.MaxUint256) - ).wait() - await (await METIS_PriorityPool.connect(signers[6]).deposit(toEther(300), true, ['0x'])).wait() - - // Reward Distributions - - await tx.wait() - tx = await LINK_StakingPool.transferAndCall(sdlPool.target, toEther(50), '0x') - await tx.wait() - tx = await LINK_StakingPool.transferAndCall(sdlPool.target, toEther(50), '0x') - await tx.wait() - await (await METIS_StakingPool.transferAndCall(sdlPool.target, toEther(50), '0x')).wait() - await (await METIS_StakingPool.transferAndCall(sdlPool.target, toEther(50), '0x')).wait() - - tx = await linkToken.transfer(strategyMockLINK.target, toEther(500)) - await tx.wait() - - await LINK_StakingPool.setRebaseController(accounts[0]) - tx = await LINK_StakingPool.updateStrategyRewards([0], '0x') - await tx.wait() - tx = await linkToken.transfer(strategyMockLINK.target, toEther(500)) - await tx.wait() - tx = await LINK_StakingPool.updateStrategyRewards([0], '0x') - await tx.wait() - - tx = await METISToken.transfer(strategyMockMETIS.target, toEther(500)) - await tx.wait() - - await METIS_StakingPool.setRebaseController(accounts[0]) - tx = await METIS_StakingPool.updateStrategyRewards([0], '0x') - await tx.wait() - tx = await METISToken.transfer(strategyMockMETIS.target, toEther(500)) - await tx.wait() - tx = await METIS_StakingPool.updateStrategyRewards([0], '0x') - await tx.wait() - - // Staking Queue - - tx = await strategyMockLINK.setMaxDeposits(toEther(2200)) - await tx.wait() - - tx = await LINK_PriorityPool.depositQueuedTokens(toEther(0), toEther(10000), ['0x']) - await tx.wait() - - tx = await LINK_PriorityPool.pauseForUpdate() - await tx.wait() - tx = await LINK_PriorityPool.updateDistribution( - '0x52171b32a0a6c33f6756c5c33673790b66945c4f1c4ec4a81932e60b06b5a321', - '0x6310F1189600F807FAC771D10706B6665628B99797054447F58F4C8A05971B83', - toEther(200), - toEther(100) - ) - await tx.wait() - - tx = await strategyMockMETIS.setMaxDeposits(toEther(2200)) - await tx.wait() - - tx = await METIS_PriorityPool.depositQueuedTokens(toEther(0), toEther(10000), ['0x']) - await tx.wait() - - tx = await METIS_PriorityPool.pauseForUpdate() - await tx.wait() - tx = await METIS_PriorityPool.updateDistribution( - '0x52171b32a0a6c33f6756c5c33673790b66945c4f1c4ec4a81932e60b06b5a321', - '0x6310F1189600F807FAC771D10706B6665628B99797054447F58F4C8A05971B83', - toEther(200), - toEther(100) - ) - await tx.wait() - - // Account 7 - - tx = await linkToken - .connect(signers[7]) - .transferAndCall( - LINK_PriorityPool.target, - toEther(100), - ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes[]'], [true, ['0x']]) - ) - await tx.wait() - - // Account 8 - - tx = await LINK_StakingPool.transfer(accounts[8], toEther(100)) - await tx.wait() - tx = await linkToken - .connect(signers[8]) - .transferAndCall( - LINK_PriorityPool.target, - toEther(5000), - ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes[]'], [true, ['0x']]) - ) - await tx.wait() - - tx = await strategyMockLINK.setMaxDeposits(toEther(6200)) - await tx.wait() - tx = await LINK_PriorityPool.depositQueuedTokens(toEther(0), toEther(100000), ['0x']) - await tx.wait() - - const vestingStart = 1695312000 // Sep 21 2023 12pm EDT - const vestingDuration = 4 * 365 * 86400 // 4 years - - let vesting0 = await deploy('Vesting', [accounts[0], accounts[12], vestingStart, vestingDuration]) - let vesting1 = await deploy('Vesting', [accounts[0], accounts[13], vestingStart, vestingDuration]) - - await sdlToken.mint(vesting0.target, toEther(10000)) - await sdlToken.mint(vesting1.target, toEther(10000)) - - updateDeployments( - { - SDL_Vesting_NOP_0: vesting0.target, - SDL_Vesting_NOP_1: vesting1.target, - }, - { - SDL_Vesting_NOP0: 'Vesting', - SDL_Vesting_NOP1: 'Vesting', - } - ) - - printDeployments() - - console.log('setup-test-env-ready') -} - -main() - .then(() => process.exit(0)) - .catch((error) => { - console.error(error) - process.exit(1) - }) diff --git a/scripts/test/setup/modules/setup-core.ts b/scripts/test/setup/modules/setup-core.ts new file mode 100644 index 00000000..44095d30 --- /dev/null +++ b/scripts/test/setup/modules/setup-core.ts @@ -0,0 +1,69 @@ +import { getAccounts, toEther, setupToken } from '../../../utils/helpers' +import { getContract } from '../../../utils/deployment' +import { StakingAllowance, ERC677, DelegatorPool } from '../../../../typechain-types' +import { ethers } from 'hardhat' + +/* +Accounts: +0 - main account that holds most of the tokens +1 - holds SDL + LPL +2 - holds SDL + reSDL +3 - holds SDL + reSDL +4 - holds SDL + reSDL + stSDL +*/ + +export async function setupCore() { + const { signers, accounts } = await getAccounts() + const sdlToken = (await getContract('SDLToken')) as StakingAllowance + const sdlPool = await getContract('SDLPool') + const lplToken = (await getContract('LPLToken')) as ERC677 + const delegatorPool = (await getContract('DelegatorPool')) as DelegatorPool + + // Token Setup + + await (await sdlToken.mint(accounts[0], toEther(100000000))).wait() + await setupToken(sdlToken, accounts) + await (await lplToken.transfer(accounts[1], toEther(500))).wait() + + // Account 2 + + await sdlToken + .connect(signers[2]) + .transferAndCall( + sdlPool.target, + toEther(2000), + ethers.AbiCoder.defaultAbiCoder().encode(['uint256', 'uint64'], [0, 0]) + ) + + // Account 3 + + await sdlToken + .connect(signers[3]) + .transferAndCall( + sdlPool.target, + toEther(3000), + ethers.AbiCoder.defaultAbiCoder().encode(['uint256', 'uint64'], [0, 365 * 86400]) + ) + + // Account 4 + + await ( + await sdlToken.connect(signers[4]).transferAndCall(delegatorPool.target, toEther(1000), '0x') + ).wait() + + await sdlToken + .connect(signers[4]) + .transferAndCall( + sdlPool.target, + toEther(4000), + ethers.AbiCoder.defaultAbiCoder().encode(['uint256', 'uint64'], [0, 0]) + ) + + await sdlToken + .connect(signers[4]) + .transferAndCall( + sdlPool.target, + toEther(5000), + ethers.AbiCoder.defaultAbiCoder().encode(['uint256', 'uint64'], [0, 4 * 365 * 86400]) + ) +} diff --git a/scripts/test/setup/modules/setup-link-staking.ts b/scripts/test/setup/modules/setup-link-staking.ts new file mode 100644 index 00000000..f51be3cb --- /dev/null +++ b/scripts/test/setup/modules/setup-link-staking.ts @@ -0,0 +1,220 @@ +import { getAccounts, toEther, setupToken } from '../../../utils/helpers' +import { getContract, deploy, updateDeployments } from '../../../utils/deployment' +import { + StakingPool, + ERC677, + PriorityPool, + DelegatorPool, + CommunityVCS, + OperatorVCS, +} from '../../../../typechain-types' +import base58 from 'bs58' +import { ethers } from 'hardhat' +import { StandardMerkleTree } from '@openzeppelin/merkle-tree' + +/* +Accounts: +0 - main account that holds most of the tokens +1 - holds LINK + stLINK +2 - holds LINK + stLINK + has withdrawable LINK + has unclaimed stLINK rewards +3 - holds LINK + stLINK + has queued LINK + has claimable stLINK + has unclaimed stLINK rewards +4 - holds LINK + has queued LINK + has claimable stLINK + has unclaimed stLINK rewards +*/ + +/* +Priority Pool IPFS mock data +CID: Qmd6Dw11iCiMaYGiQVE2E44mjLMwyqh1rX5fNPC5YFUJeY +data: +{ + "merkleRoot": "0x636b20fe97efac2148da6cc0342a0dfc7e670ee78681c00cfdf4338c8984d23f", + "data": { + "0x0000000000000000000000000000000000000000": { + "amount": "0", + "sharesAmount": "0" + }, + "0x444485D3d01447da706550B1c10362676193CAd0": { + "amount": "30000000000000000000", + "sharesAmount": "15000000000000000000" + }, + "0x555f27995D7BB56c989d7C1cA4e5e03e930ecA67": { + "amount": "40000000000000000000", + "sharesAmount": "20000000000000000000" + }, + } +} +*/ + +const depositData = [ + ethers.AbiCoder.defaultAbiCoder().encode(['uint256[]'], [[]]), + ethers.AbiCoder.defaultAbiCoder().encode(['uint256[]'], [[]]), +] + +export async function setupLINKStaking() { + const { signers, accounts } = await getAccounts() + const linkToken = (await getContract('LINKToken')) as ERC677 + const stakingPool = (await getContract('LINK_StakingPool')) as StakingPool + const priorityPool = (await getContract('LINK_PriorityPool')) as PriorityPool + const communityVCS = (await getContract('LINK_CommunityVCS')) as CommunityVCS + const operatorVCS = (await getContract('LINK_OperatorVCS')) as OperatorVCS + const delegatorPool = (await getContract('DelegatorPool')) as DelegatorPool + const wsdToken = await getContract('LINK_WrappedSDToken') + const sdlPool = await getContract('SDLPool') + const stLINKSDLRewardsPool = await getContract('stLINK_SDLRewardsPool') + + // Staking Setup + + await setupToken(linkToken, accounts) + + await ( + await linkToken.transferAndCall( + priorityPool.target, + toEther(222000), + ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes[]'], [false, depositData]) + ) + ).wait() + await (await linkToken.transfer(communityVCS.target, toEther(222000))).wait() + await (await stakingPool.updateStrategyRewards([0, 1], '0x')).wait() + await (await priorityPool.depositQueuedTokens(0, toEther(222000), depositData)).wait() + + // Account 1 + + await ( + await linkToken + .connect(signers[1]) + .transferAndCall( + priorityPool.target, + toEther(1000), + ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes[]'], [false, depositData]) + ) + ).wait() + + // Account 2 + + await ( + await linkToken + .connect(signers[2]) + .transferAndCall( + priorityPool.target, + toEther(2000), + ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes[]'], [false, depositData]) + ) + ).wait() + await (await stakingPool.approve(priorityPool.target, toEther(500))).wait() + await (await priorityPool.withdraw(toEther(500), 0, 0, [], false, true, depositData)).wait() + + // Account 3 + + await ( + await linkToken + .connect(signers[3]) + .transferAndCall( + priorityPool.target, + toEther(3500), + ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes[]'], [false, depositData]) + ) + ).wait() + + await ( + await linkToken + .connect(signers[3]) + .transferAndCall( + priorityPool.target, + toEther(3700), + ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes[]'], [true, depositData]) + ) + ).wait() + + // Account 4 + + await ( + await linkToken + .connect(signers[4]) + .transferAndCall( + priorityPool.target, + toEther(4000), + ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes[]'], [true, depositData]) + ) + ).wait() + + // Priority Pool Distribution + + await (await communityVCS.addVaults(1)).wait() + await (await priorityPool.depositQueuedTokens(toEther(700), toEther(700), depositData)).wait() + await (await priorityPool.pauseForUpdate()).wait() + + let tree = StandardMerkleTree.of( + [ + [ethers.ZeroAddress, toEther(0), toEther(0)], + [accounts[3], toEther(300), toEther(150)], + [accounts[4], toEther(400), toEther(200)], + ], + ['address', 'uint256', 'uint256'] + ) + await ( + await priorityPool.updateDistribution( + tree.root, + '0x' + + Buffer.from(base58.decode('Qmd6Dw11iCiMaYGiQVE2E44mjLMwyqh1rX5fNPC5YFUJeY')) + .toString('hex') + .slice(4), + toEther(700), + toEther(350) + ) + ).wait() + + // Reward Distribution + + await (await operatorVCS.addFee(stLINKSDLRewardsPool.target, 1500)).wait() + await (await communityVCS.addFee(stLINKSDLRewardsPool.target, 1000)).wait() + await (await stakingPool.addFee(accounts[0], 300)).wait() + + const opVaults = await operatorVCS.getVaults() + const opRewardsController = await ethers.getContractAt( + 'StakingRewardsMock', + await ( + await ethers.getContractAt('StakingMock', await operatorVCS.stakeController()) + ).rewardVault() + ) + const comVaults = await communityVCS.getVaults() + const comRewardsController = await ethers.getContractAt( + 'StakingRewardsMock', + await ( + await ethers.getContractAt('StakingMock', await communityVCS.stakeController()) + ).rewardVault() + ) + + await (await opRewardsController.setReward(opVaults[0], toEther(2000))).wait() + await (await comRewardsController.setReward(comVaults[3], toEther(1000))).wait() + await (await stakingPool.updateStrategyRewards([0, 1], '0x')).wait() + + await (await opRewardsController.setReward(opVaults[1], toEther(698))).wait() + await (await comRewardsController.setReward(comVaults[2], toEther(777))).wait() + await (await stakingPool.updateStrategyRewards([0, 1], '0x')).wait() + + await (await opRewardsController.setReward(opVaults[2], toEther(1893))).wait() + await (await comRewardsController.setReward(comVaults[4], toEther(1237))).wait() + await (await stakingPool.updateStrategyRewards([0, 1], '0x')).wait() + + // Delegator Pool Setup + + let stLINK_DelegatorRewardsPool = await deploy('RewardsPoolWSD', [ + delegatorPool.target, + stakingPool.target, + wsdToken.target, + ]) + await ( + await delegatorPool.addToken(stakingPool.target, stLINK_DelegatorRewardsPool.target) + ).wait() + + updateDeployments( + { + stLINK_DelegatorRewardsPool: stLINK_DelegatorRewardsPool.target, + }, + { + stLINK_DelegatorRewardsPool: 'RewardsPoolWSD', + } + ) + + await (await stakingPool.transferAndCall(delegatorPool.target, toEther(1000), '0x')).wait() + await (await delegatorPool.retireDelegatorPool([], sdlPool.target)).wait() +} diff --git a/scripts/test/setup/modules/setup-metis-staking.ts b/scripts/test/setup/modules/setup-metis-staking.ts new file mode 100644 index 00000000..73c5fb89 --- /dev/null +++ b/scripts/test/setup/modules/setup-metis-staking.ts @@ -0,0 +1,163 @@ +import { getAccounts, toEther, setupToken } from '../../../utils/helpers' +import { getContract } from '../../../utils/deployment' +import { StakingPool, ERC677, PriorityPool, StrategyMock } from '../../../../typechain-types' +import base58 from 'bs58' +import { ethers } from 'hardhat' +import { StandardMerkleTree } from '@openzeppelin/merkle-tree' + +/* +Accounts: +0 - main account that holds most of the tokens +1 - holds METIS + stMETIS +2 - holds METIS + stMETIS + has withdrawable METIS + has unclaimed stMETIS rewards +3 - holds METIS + stMETIS + has queued METIS + has claimable stMETIS + has unclaimed stMETIS rewards +4 - holds METIS + has queued METIS + has claimable stMETIS + has unclaimed stMETIS rewards +*/ + +/* +Priority Pool IPFS mock data +CID: Qmd6Dw11iCiMaYGiQVE2E44mjLMwyqh1rX5fNPC5YFUJeY +data: +{ + "merkleRoot": "0x636b20fe97efac2148da6cc0342a0dfc7e670ee78681c00cfdf4338c8984d23f", + "data": { + "0x0000000000000000000000000000000000000000": { + "amount": "0", + "sharesAmount": "0" + }, + "0x444485D3d01447da706550B1c10362676193CAd0": { + "amount": "30000000000000000000", + "sharesAmount": "15000000000000000000" + }, + "0x555f27995D7BB56c989d7C1cA4e5e03e930ecA67": { + "amount": "40000000000000000000", + "sharesAmount": "20000000000000000000" + }, + } +} +*/ + +export async function setupMETISStaking() { + const { signers, accounts } = await getAccounts() + const metisToken = (await getContract('METISToken')) as ERC677 + const stakingPool = (await getContract('METIS_StakingPool')) as StakingPool + const priorityPool = (await getContract('METIS_PriorityPool')) as PriorityPool + const l2Strategy = (await getContract('METIS_L2Strategy')) as StrategyMock + const stMETISSDLRewardsPool = await getContract('stMETIS_SDLRewardsPool') + + // Staking Setup + + await setupToken(metisToken, accounts) + + await ( + await metisToken.transferAndCall( + priorityPool.target, + toEther(47000), + ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes[]'], [false, ['0x']]) + ) + ).wait() + await (await metisToken.transfer(l2Strategy.target, toEther(47000))).wait() + await (await stakingPool.updateStrategyRewards([0], '0x')).wait() + + // Account 1 + + await ( + await metisToken + .connect(signers[1]) + .transferAndCall( + priorityPool.target, + toEther(1000), + ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes[]'], [false, ['0x']]) + ) + ).wait() + + // Account 2 + + await ( + await metisToken + .connect(signers[2]) + .transferAndCall( + priorityPool.target, + toEther(2000), + ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes[]'], [false, ['0x']]) + ) + ).wait() + await (await l2Strategy.setMinDeposits(toEther(100000))).wait() + await (await stakingPool.approve(priorityPool.target, toEther(500))).wait() + await (await priorityPool.withdraw(toEther(500), 0, 0, [], false, true, ['0x'])).wait() + await (await l2Strategy.setMinDeposits(toEther(20000))).wait() + + // Account 3 + + await ( + await metisToken + .connect(signers[3]) + .transferAndCall( + priorityPool.target, + toEther(3500), + ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes[]'], [false, ['0x']]) + ) + ).wait() + + await ( + await metisToken + .connect(signers[3]) + .transferAndCall( + priorityPool.target, + toEther(3700), + ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes[]'], [true, ['0x']]) + ) + ).wait() + + // Account 4 + + await ( + await metisToken + .connect(signers[4]) + .transferAndCall( + priorityPool.target, + toEther(4000), + ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes[]'], [true, ['0x']]) + ) + ).wait() + + // Priority Pool Distribution + + await (await l2Strategy.setMaxDeposits(toEther(100700))).wait() + await (await priorityPool.depositQueuedTokens(toEther(700), toEther(700), ['0x'])).wait() + await (await priorityPool.pauseForUpdate()).wait() + + let tree = StandardMerkleTree.of( + [ + [ethers.ZeroAddress, toEther(0), toEther(0)], + [accounts[3], toEther(300), toEther(150)], + [accounts[4], toEther(400), toEther(200)], + ], + ['address', 'uint256', 'uint256'] + ) + await ( + await priorityPool.updateDistribution( + tree.root, + '0x' + + Buffer.from(base58.decode('Qmd6Dw11iCiMaYGiQVE2E44mjLMwyqh1rX5fNPC5YFUJeY')) + .toString('hex') + .slice(4), + toEther(700), + toEther(350) + ) + ).wait() + + // Reward Distribution + + await (await stakingPool.addFee(stMETISSDLRewardsPool.target, 1000)).wait() + await (await stakingPool.addFee(accounts[0], 300)).wait() + + await (await metisToken.transfer(l2Strategy.target, toEther(3000))).wait() + await (await stakingPool.updateStrategyRewards([0], '0x')).wait() + + await (await metisToken.transfer(l2Strategy.target, toEther(2384))).wait() + await (await stakingPool.updateStrategyRewards([0], '0x')).wait() + + await (await metisToken.transfer(l2Strategy.target, toEther(5968))).wait() + await (await stakingPool.updateStrategyRewards([0], '0x')).wait() +} diff --git a/scripts/test/setup/modules/setup-other.ts b/scripts/test/setup/modules/setup-other.ts new file mode 100644 index 00000000..082cd296 --- /dev/null +++ b/scripts/test/setup/modules/setup-other.ts @@ -0,0 +1,16 @@ +import { toEther } from '../../../utils/helpers' +import { getContract } from '../../../utils/deployment' +import { StakingAllowance, ERC677 } from '../../../../typechain-types' + +export async function setupOther() { + const linkCurvePool = await getContract('LINK_CurvePool') + const linkToken = (await getContract('LINKToken')) as ERC677 + const sdlToken = (await getContract('SDLToken')) as StakingAllowance + const vesting0 = await getContract('SDL_Vesting_NOP_0') + const vesting1 = await getContract('SDL_Vesting_NOP_1') + + await (await linkToken.transfer(linkCurvePool.target, toEther(1000))).wait() + + await (await sdlToken.mint(vesting0.target, toEther(10000))).wait() + await (await sdlToken.mint(vesting1.target, toEther(10000))).wait() +} diff --git a/scripts/test/setup/setup-test-env.ts b/scripts/test/setup/setup-test-env.ts new file mode 100644 index 00000000..52a81f84 --- /dev/null +++ b/scripts/test/setup/setup-test-env.ts @@ -0,0 +1,22 @@ +import { printDeployments } from '../../utils/deployment' +import { setupCore } from './modules/setup-core' +import { setupLINKStaking } from './modules/setup-link-staking' +import { setupMETISStaking } from './modules/setup-metis-staking' +import { setupOther } from './modules/setup-other' + +async function main() { + await setupCore() + await setupLINKStaking() + await setupMETISStaking() + await setupOther() + + printDeployments() + console.log('setup-test-env-ready') +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error) + process.exit(1) + }) diff --git a/scripts/utils/helpers.ts b/scripts/utils/helpers.ts index 5d36b074..7d831850 100644 --- a/scripts/utils/helpers.ts +++ b/scripts/utils/helpers.ts @@ -15,8 +15,6 @@ export const getAccounts = async (): Promise => { return { signers, accounts } } -export const setupToken = async (token: ERC677, accounts: string[]) => { - return Promise.all( - accounts.map((account, index) => token.transfer(account, toEther(index < 4 ? 10000 : 0))) - ) +export const setupToken = async (token: any, accounts: string[]) => { + return Promise.all(accounts.map((account) => token.transfer(account, toEther(10000)))) } diff --git a/yarn.lock b/yarn.lock index 6559e59f..ffc033dc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1788,6 +1788,11 @@ base-x@^3.0.2: dependencies: safe-buffer "^5.0.1" +base-x@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/base-x/-/base-x-5.0.0.tgz#6d835ceae379130e1a4cb846a70ac4746f28ea9b" + integrity sha512-sMW3VGSX1QWVFA6l8U62MLKz29rRfpTlYdCqLdpLo1/Yd4zZwSbnUaDfciIAowAqvq7YFnWq9hrhdg1KYgc1lQ== + base64-js@^1.0.2, base64-js@^1.3.1: version "1.5.1" resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" @@ -1909,6 +1914,13 @@ bs58@^4.0.0: dependencies: base-x "^3.0.2" +bs58@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/bs58/-/bs58-6.0.0.tgz#a2cda0130558535dd281a2f8697df79caaf425d8" + integrity sha512-PD0wEnEYg6ijszw/u8s+iI3H17cTymlrwkKhDhPZq+Sokl3AU4htyBFTjAeNAlCCmg0f53g6ih3jATyCKftTfw== + dependencies: + base-x "^5.0.0" + bs58check@^2.1.2: version "2.1.2" resolved "https://registry.yarnpkg.com/bs58check/-/bs58check-2.1.2.tgz#53b018291228d82a5aa08e7d796fdafda54aebfc"