11import hre , { ethers } from 'hardhat'
22import {
3- Controller , ElasticSupplyPool , TenderToken , IMatic , BPool , EIP173Proxy , Matic , ERC20
3+ TenderToken , IMatic , TenderFarm , EIP173Proxy , Matic , ERC20 , TenderSwap , Audius , LiquidityPoolToken
44} from '../../typechain'
5+ import { getCurrentBlockTimestamp } from '../util/evm'
56
67import rootChainAbi from './abis/matic/RootChain.json'
78
@@ -15,7 +16,8 @@ import { BigNumber } from '@ethersproject/bignumber'
1516import { Contract , ContractTransaction } from '@ethersproject/contracts'
1617
1718import { Signer } from '@ethersproject/abstract-signer'
18- import { percOf2 , sharesToTokens , buildsubmitCheckpointPaylod , getBlockHeader } from '../util/helpers'
19+ import { percOf2 , sharesToTokens } from '../util/helpers'
20+ import { buildsubmitCheckpointPaylod , getBlockHeader } from '../util/matic_mainnet_helpers'
1921const MerkleTree = require ( '../util/merkle-tree' )
2022const ethUtils = require ( 'ethereumjs-util' )
2123
@@ -27,11 +29,11 @@ const {
2729describe ( 'Matic Mainnet Fork Test' , ( ) => {
2830 let MaticStaking : IMatic
2931 let MaticToken : ERC20
30- let Controller : Controller
3132 let Tenderizer : Matic
3233 let TenderToken : TenderToken
33- let Esp : ElasticSupplyPool
34- let BPool : BPool
34+ let TenderSwap : TenderSwap
35+ let LpToken : LiquidityPoolToken
36+ let TenderFarm : TenderFarm
3537
3638 let Matic : { [ name : string ] : Deployment }
3739
@@ -214,17 +216,26 @@ describe('Matic Mainnet Fork Test', () => {
214216 Matic = await hre . deployments . fixture ( [ 'Matic' ] , {
215217 keepExistingDeployments : false
216218 } )
217- Controller = ( await ethers . getContractAt ( 'Controller' , Matic . Controller . address ) ) as Controller
218- Tenderizer = ( await ethers . getContractAt ( 'Matic' , Matic . Matic . address ) ) as Matic
219- TenderToken = ( await ethers . getContractAt ( 'TenderToken' , Matic . TenderToken . address ) ) as TenderToken
220- Esp = ( await ethers . getContractAt ( 'ElasticSupplyPool' , Matic . ElasticSupplyPool . address ) ) as ElasticSupplyPool
221- BPool = ( await ethers . getContractAt ( 'BPool' , await Esp . bPool ( ) ) ) as BPool
222- await Controller . batchExecute (
223- [ Tenderizer . address , Tenderizer . address ] ,
224- [ 0 , 0 ] ,
225- [ Tenderizer . interface . encodeFunctionData ( 'setProtocolFee' , [ protocolFeesPercent ] ) ,
226- Tenderizer . interface . encodeFunctionData ( 'setLiquidityFee' , [ liquidityFeesPercent ] ) ]
227- )
219+
220+ Tenderizer = ( await ethers . getContractAt ( 'Audius' , Matic . Matic . address ) ) as Matic
221+ TenderToken = ( await ethers . getContractAt ( 'TenderToken' , await Tenderizer . tenderToken ( ) ) ) as TenderToken
222+ TenderSwap = ( await ethers . getContractAt ( 'TenderSwap' , await Tenderizer . tenderSwap ( ) ) ) as TenderSwap
223+ TenderFarm = ( await ethers . getContractAt ( 'TenderFarm' , await Tenderizer . tenderFarm ( ) ) ) as TenderFarm
224+ LpToken = ( await ethers . getContractAt ( 'LiquidityPoolToken' , await TenderSwap . lpToken ( ) ) ) as LiquidityPoolToken
225+ await Tenderizer . setProtocolFee ( protocolFeesPercent )
226+ await Tenderizer . setLiquidityFee ( liquidityFeesPercent )
227+
228+
229+ // Deposit initial stake
230+ await MaticToken . approve ( Tenderizer . address , initialStake )
231+ await Tenderizer . deposit ( initialStake , { gasLimit : 500000 } )
232+ // Add initial liquidity
233+ await MaticToken . approve ( TenderSwap . address , initialStake )
234+ await TenderToken . approve ( TenderSwap . address , initialStake )
235+ const lpTokensOut = await TenderSwap . calculateTokenAmount ( [ initialStake , initialStake ] , true )
236+ await TenderSwap . addLiquidity ( [ initialStake , initialStake ] , lpTokensOut , ( await getCurrentBlockTimestamp ( ) ) + 1000 )
237+ await LpToken . approve ( TenderFarm . address , lpTokensOut )
238+ await TenderFarm . farm ( lpTokensOut )
228239 } )
229240
230241 const initialStake = ethers . utils . parseEther ( STEAK_AMOUNT ) . div ( '2' )
@@ -233,13 +244,13 @@ describe('Matic Mainnet Fork Test', () => {
233244
234245 describe ( 'deposit' , ( ) => {
235246 it ( 'reverts because transfer amount exceeds allowance' , async ( ) => {
236- await expect ( Controller . deposit ( deposit ) ) . to . be . reverted
247+ await expect ( Tenderizer . deposit ( deposit ) ) . to . be . reverted
237248 } )
238249
239250 describe ( 'deposits funds succesfully' , async ( ) => {
240251 before ( async ( ) => {
241- await MaticToken . approve ( Controller . address , deposit )
242- tx = await Controller . deposit ( deposit )
252+ await MaticToken . approve ( Tenderizer . address , deposit )
253+ tx = await Tenderizer . deposit ( deposit )
243254 } )
244255
245256 it ( 'increases TenderToken supply' , async ( ) => {
@@ -265,15 +276,15 @@ describe('Matic Mainnet Fork Test', () => {
265276 before ( async ( ) => {
266277 // Exchange rate would be 1 at this point, so can simply comapre the shares
267278 stakeBefore = await MaticStaking . balanceOf ( Tenderizer . address )
268- tx = await Controller . gulp ( )
279+ tx = await Tenderizer . claimRewards ( )
269280 } )
270281
271282 it ( 'bond succeeds' , async ( ) => {
272- expect ( await MaticStaking . balanceOf ( Tenderizer . address ) ) . to . eq ( stakeBefore . add ( deposit ) )
283+ expect ( await MaticStaking . balanceOf ( Tenderizer . address ) ) . to . eq ( initialStake . add ( deposit ) )
273284 } )
274285
275286 it ( 'emits Stake event from tenderizer' , async ( ) => {
276- expect ( tx ) . to . emit ( Tenderizer , 'Stake' ) . withArgs ( NODE , deposit )
287+ expect ( tx ) . to . emit ( Tenderizer , 'Stake' ) . withArgs ( NODE , initialStake . add ( deposit ) )
277288 } )
278289 } )
279290
@@ -353,7 +364,7 @@ describe('Matic Mainnet Fork Test', () => {
353364 const protocolFees = percOf2 ( increase . add ( swappedLPTRewards ) , protocolFeesPercent )
354365 newStake = deposit . add ( initialStake ) . add ( increase )
355366 newStakeMinusFees = newStake . add ( swappedLPTRewards ) . sub ( liquidityFees . add ( protocolFees ) )
356- tx = await Controller . rebase ( )
367+ tx = await Tenderizer . claimRewards ( )
357368 } )
358369
359370 it ( 'updates currentPrincipal' , async ( ) => {
0 commit comments