Skip to content

Commit

Permalink
Simplify compounding in test ethereum script
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejearley committed Jul 18, 2023
1 parent 5cfe739 commit 7703fe6
Showing 1 changed file with 21 additions and 30 deletions.
51 changes: 21 additions & 30 deletions contracts/ethereum/test/fixtures/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,14 @@ export async function sweepPostSecondUserDepositFixture() {
await runUpkeep({ upkeep, keeper })
const sweptRewards = 0.105
const stakedPoolIds = await manager.getStakedPoolIds()
const compoundablePoolIds = [0, 0, 0, 0, 0]
for (let i = 0; i < compoundablePoolIds.length; i++) {
if (i < stakedPoolIds.length) compoundablePoolIds[i] = stakedPoolIds[i]
for (const poolId of stakedPoolIds) {
const poolAddress = await manager.getPoolAddress(poolId)
const poolSweptRewards = sweptRewards / stakedPoolIds.length
const currentBalance = await ethers.provider.getBalance(poolAddress)
const nextBalance = currentBalance.add(ethers.utils.parseEther(poolSweptRewards.toString()))
await setBalance(poolAddress, nextBalance)
}
const compoundablePoolIds = [1, 0, 0, 0, 0]
const nextValues = {
activeBalance: 32,
sweptBalance: sweptRewards,
Expand All @@ -165,13 +169,6 @@ export async function sweepPostSecondUserDepositFixture() {
values: nextValues,
requestId
})
for (const poolId of stakedPoolIds) {
const poolAddress = await manager.getPoolAddress(poolId)
const poolSweptRewards = sweptRewards / stakedPoolIds.length
const currentBalance = await ethers.provider.getBalance(poolAddress)
const nextBalance = currentBalance.add(ethers.utils.parseEther(poolSweptRewards.toString()))
await setBalance(poolAddress, nextBalance)
}
await runUpkeep({ upkeep, keeper })

return { manager, registry, upkeep, views, owner, firstUser, secondUser, keeper, oracle, requestId }
Expand Down Expand Up @@ -245,10 +242,14 @@ export async function sweepPostThirdUserDepositFixture() {
await runUpkeep({ upkeep, keeper })
const sweptRewards = 0.21
const stakedPoolIds = await manager.getStakedPoolIds()
const compoundablePoolIds = [0, 0, 0, 0, 0]
for (let i = 0; i < compoundablePoolIds.length; i++) {
if (i < stakedPoolIds.length) compoundablePoolIds[i] = stakedPoolIds[i]
for (const poolId of stakedPoolIds) {
const poolAddress = await manager.getPoolAddress(poolId)
const poolSweptRewards = sweptRewards / stakedPoolIds.length
const currentBalance = await ethers.provider.getBalance(poolAddress)
const nextBalance = currentBalance.add(ethers.utils.parseEther(poolSweptRewards.toString()))
await setBalance(poolAddress, nextBalance)
}
const compoundablePoolIds = [1, 2, 0, 0, 0]
const nextValues = {
activeBalance: 64,
sweptBalance: sweptRewards,
Expand All @@ -263,13 +264,6 @@ export async function sweepPostThirdUserDepositFixture() {
values: nextValues,
requestId
})
for (const poolId of stakedPoolIds) {
const poolAddress = await manager.getPoolAddress(poolId)
const poolSweptRewards = sweptRewards / stakedPoolIds.length
const currentBalance = await ethers.provider.getBalance(poolAddress)
const nextBalance = currentBalance.add(ethers.utils.parseEther(poolSweptRewards.toString()))
await setBalance(poolAddress, nextBalance)
}
await runUpkeep({ upkeep, keeper })

return { manager, registry, upkeep, views, owner, firstUser, secondUser, thirdUser, keeper, oracle, requestId }
Expand Down Expand Up @@ -470,10 +464,14 @@ export async function simulationFixture() {
const stakedPoolIds = await manager.getStakedPoolIds()
await time.increase(time.duration.days(1))
await runUpkeep({ upkeep, keeper })
const compoundablePoolIds = [0, 0, 0, 0, 0]
for (let i = 0; i < compoundablePoolIds.length; i++) {
if (i < stakedPoolIds.length) compoundablePoolIds[i] = stakedPoolIds[i]
for (const poolId of stakedPoolIds) {
const poolAddress = await manager.getPoolAddress(poolId)
const poolSweptRewards = sweptRewards / stakedPoolIds.length
const currentBalance = await ethers.provider.getBalance(poolAddress)
const nextBalance = currentBalance.add(ethers.utils.parseEther(poolSweptRewards.toString()))
await setBalance(poolAddress, nextBalance)
}
const compoundablePoolIds = [2, 3, 4, 0, 0]
const nextValues = {
activeBalance: 96,
sweptBalance: sweptRewards,
Expand All @@ -488,13 +486,6 @@ export async function simulationFixture() {
values: nextValues,
requestId
})
for (const poolId of stakedPoolIds) {
const poolAddress = await manager.getPoolAddress(poolId)
const poolSweptRewards = sweptRewards / stakedPoolIds.length
const currentBalance = await ethers.provider.getBalance(poolAddress)
const nextBalance = currentBalance.add(ethers.utils.parseEther(poolSweptRewards.toString()))
await setBalance(poolAddress, nextBalance)
}
await runUpkeep({ upkeep, keeper })

return { manager, registry, upkeep, views, firstUser, secondUser, thirdUser, fourthUser, keeper, oracle, requestId }
Expand Down

0 comments on commit 7703fe6

Please sign in to comment.