-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* decrease block_span for Fuji * ReserveConstraint * lint * update withdrawReserves scenario * lint * PR feedback * lint * bump approximation threshold for stETH scenario * update Arbitrum/USDC flash loan pool
- Loading branch information
1 parent
fe6f0a7
commit 6d9c48c
Showing
10 changed files
with
82 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Constraint, Solution } from '../../plugins/scenario'; | ||
import { CometContext } from '../context/CometContext'; | ||
import { expect } from 'chai'; | ||
import { Requirements } from './Requirements'; | ||
import { exp } from '../../test/helpers'; | ||
import { ComparisonOp, parseAmount, getToTransferAmount } from '../utils'; | ||
|
||
export class ReservesConstraint<T extends CometContext, R extends Requirements> implements Constraint<T, R> { | ||
async solve(requirements: R, _initialContext: T) { | ||
const reservesRequirement = requirements.reserves; | ||
if (reservesRequirement !== undefined) { | ||
const solutions: Solution<T>[] = []; | ||
solutions.push(async function barelyMeet(context: T) { | ||
const comet = await context.getComet(); | ||
const baseToken = await comet.baseToken(); | ||
const currentReserves = (await comet.getReserves()).toBigInt(); | ||
const amount = parseAmount(reservesRequirement); | ||
const decimals = await comet.decimals(); | ||
|
||
expect(amount.op).to.equal(ComparisonOp.GTE, `Operation ${amount.op} not supported (yet) by reserve cap constraint`); | ||
|
||
const amountToSource = getToTransferAmount(amount, currentReserves, decimals); | ||
// add buffer to adjust for interest accrual | ||
await context.sourceTokens(amountToSource * 105n / 100n, baseToken, comet.address); | ||
|
||
return context; | ||
}); | ||
return solutions; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
async check(requirements: R, context: T) { | ||
const reservesRequirement = requirements.reserves; | ||
if (reservesRequirement !== undefined) { | ||
const comet = await context.getComet(); | ||
const amount = parseAmount(reservesRequirement); | ||
const decimals = await comet.decimals(); | ||
const currentReserves = (await comet.getReserves()).toBigInt(); | ||
const expectedReserves = exp(amount.val, decimals); | ||
|
||
switch (amount.op) { | ||
case ComparisonOp.EQ: | ||
expect(currentReserves).to.equal(expectedReserves); | ||
break; | ||
case ComparisonOp.GTE: | ||
expect(currentReserves).to.be.at.least(expectedReserves); | ||
break; | ||
case ComparisonOp.LTE: | ||
expect(currentReserves).to.be.at.most(expectedReserves); | ||
break; | ||
case ComparisonOp.GT: | ||
expect(currentReserves).to.be.above(expectedReserves); | ||
break; | ||
case ComparisonOp.LT: | ||
expect(currentReserves).to.be.below(expectedReserves); | ||
break; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters