mirror of
https://github.com/Instadapp/dsa-resolvers-deprecated.git
synced 2024-07-29 22:38:16 +00:00
add randomSeed assss optional paramter to hint functions
This commit is contained in:
parent
4df8b8bf56
commit
b471eab625
|
|
@ -167,18 +167,19 @@ contract Resolver is Helpers {
|
|||
return System(borrowFee, ethTvl, tcr, isInRecoveryMode);
|
||||
}
|
||||
|
||||
function getTrovePositionHints(uint collateral, uint debt, uint searchIterations) external view returns (
|
||||
function getTrovePositionHints(uint collateral, uint debt, uint searchIterations, uint randomSeed) external view returns (
|
||||
address upperHint,
|
||||
address lowerHint
|
||||
) {
|
||||
// See: https://github.com/liquity/dev#supplying-hints-to-trove-operations
|
||||
uint nominalCr = hintHelpers.computeNominalCR(collateral, debt);
|
||||
searchIterations = searchIterations == 0 ? mul(10, sqrt(sortedTroves.getSize())) : searchIterations;
|
||||
(address hintAddress, ,) = hintHelpers.getApproxHint(nominalCr, searchIterations, 3);
|
||||
randomSeed = randomSeed == 0 ? block.number : randomSeed;
|
||||
(address hintAddress, ,) = hintHelpers.getApproxHint(nominalCr, searchIterations, randomSeed);
|
||||
return sortedTroves.findInsertPosition(nominalCr, hintAddress, hintAddress);
|
||||
}
|
||||
|
||||
function getRedemptionPositionHints(uint amount, uint oracleEthPrice, uint searchIterations) external view returns (
|
||||
function getRedemptionPositionHints(uint amount, uint oracleEthPrice, uint searchIterations, uint randomSeed) external view returns (
|
||||
uint partialHintNicr,
|
||||
address firstHint,
|
||||
address upperHint,
|
||||
|
|
@ -187,7 +188,8 @@ contract Resolver is Helpers {
|
|||
// See: https://github.com/liquity/dev#hints-for-redeemcollateral
|
||||
(firstHint, partialHintNicr, ) = hintHelpers.getRedemptionHints(amount, oracleEthPrice, 0);
|
||||
searchIterations = searchIterations == 0 ? mul(10, sqrt(sortedTroves.getSize())) : searchIterations;
|
||||
(address hintAddress, ,) = hintHelpers.getApproxHint(partialHintNicr, searchIterations, 3);
|
||||
randomSeed = randomSeed == 0 ? block.number : randomSeed;
|
||||
(address hintAddress, ,) = hintHelpers.getApproxHint(partialHintNicr, searchIterations, randomSeed);
|
||||
(upperHint, lowerHint) = sortedTroves.findInsertPosition(partialHintNicr, hintAddress, hintAddress);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -164,12 +164,14 @@ describe("InstaLiquityResolver", () => {
|
|||
describe("getTrovePositionHints()", () => {
|
||||
it("returns the upper and lower address of Troves nearest to the given Trove", async () => {
|
||||
const collateral = hre.ethers.utils.parseEther("10");
|
||||
const debt = hre.ethers.utils.parseUnits("5000", 18);
|
||||
const debt = hre.ethers.utils.parseUnits("5000", 18); // 5,000 LUSD
|
||||
const searchIterations = 10;
|
||||
const randomSeed = 3;
|
||||
const [upperHint, lowerHint] = await liquity.getTrovePositionHints(
|
||||
collateral,
|
||||
debt,
|
||||
searchIterations
|
||||
searchIterations,
|
||||
randomSeed
|
||||
);
|
||||
|
||||
expect(upperHint).eq(expectedTrovePositionHints.upperHint);
|
||||
|
|
@ -182,6 +184,7 @@ describe("InstaLiquityResolver", () => {
|
|||
const amount = hre.ethers.utils.parseUnits("10000", 18); // 10,000 LUSD
|
||||
const oracleEthPrice = await liquityPriceOracle.callStatic.fetchPrice();
|
||||
const searchIterations = 10;
|
||||
const randomSeed = 3;
|
||||
const [
|
||||
partialRedemptionHintNicr,
|
||||
firstHint,
|
||||
|
|
@ -190,7 +193,8 @@ describe("InstaLiquityResolver", () => {
|
|||
] = await liquity.getRedemptionPositionHints(
|
||||
amount,
|
||||
oracleEthPrice,
|
||||
searchIterations
|
||||
searchIterations,
|
||||
randomSeed
|
||||
);
|
||||
|
||||
expect(partialRedemptionHintNicr).eq(
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user