Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(resubscribe): setup for curveDetails #78

Merged
merged 13 commits into from
Dec 28, 2021
27 changes: 23 additions & 4 deletions contracts/Foundry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,17 @@ contract Foundry is IFoundry, Ownable, Initializable {
totalSupply_,
meToken_.balancePooled
);

uint256 targetAssetsReturned;
// Logic for if we're switching to a new curve type // updating curveDetails
if (
(hub_.updating && (hub_.targetCurve != address(0))) ||
(hub_.reconfigure)
) {
uint256 targetassetsReturned;
if (hub_.targetCurve != address(0)) {
// Means we are updating to a new curve type

targetassetsReturned = ICurve(hub_.targetCurve)
targetAssetsReturned = ICurve(hub_.targetCurve)
.viewAssetsReturned(
_meTokensBurned,
meToken_.hubId,
Expand All @@ -360,7 +361,7 @@ contract Foundry is IFoundry, Ownable, Initializable {
);
} else {
// Must mean we're updating curveDetails
targetassetsReturned = ICurve(hub_.curve)
targetAssetsReturned = ICurve(hub_.curve)
.viewTargetAssetsReturned(
_meTokensBurned,
meToken_.hubId,
Expand All @@ -370,10 +371,28 @@ contract Foundry is IFoundry, Ownable, Initializable {
}
rawAssetsReturned = WeightedAverage.calculate(
rawAssetsReturned,
targetassetsReturned,
targetAssetsReturned,
hub_.startTime,
hub_.endTime
);
} else if (meToken_.targetHubId != 0) {
Details.Hub memory targetHub_ = hub.getDetails(
meToken_.targetHubId
);

// Calculate return assuming update is not happening
targetAssetsReturned = ICurve(targetHub_.curve).viewAssetsReturned(
_meTokensBurned,
meToken_.targetHubId,
totalSupply_,
meToken_.balancePooled
);
rawAssetsReturned = WeightedAverage.calculate(
rawAssetsReturned,
targetAssetsReturned,
meToken_.startTime,
meToken_.endTime
);
}
}

Expand Down
45 changes: 45 additions & 0 deletions test/contracts/migrations/UniswapSingleTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,51 @@ const setup = async () => {
)
).to.be.revertedWith("Invalid _encodedMigrationArgs");
});
it("should revert when try to approve already approved vaults", async () => {
await expect(
migrationRegistry.approve(
initialVault.address,
targetVault.address,
migration.address
)
).to.be.revertedWith("migration already approved");
});
it("should be able to unapprove migration vaults", async () => {
let tx = await migrationRegistry.unapprove(
initialVault.address,
targetVault.address,
migration.address
);
await tx.wait();

// should revert to init resubscribe when unapproved
await expect(
meTokenRegistry
.connect(account1)
.initResubscribe(
meToken.address,
hubId2,
migration.address,
encodedMigrationArgs
)
).to.be.revertedWith("!approved");
});
it("should revert when try to unapprove already unapproved vaults", async () => {
await expect(
migrationRegistry.unapprove(
initialVault.address,
targetVault.address,
migration.address
)
).to.be.revertedWith("migration not approved");

// approve vaults again
const tx = await migrationRegistry.approve(
initialVault.address,
targetVault.address,
migration.address
);
});
it("Set correct _ust values", async () => {
await meTokenRegistry
.connect(account1)
Expand Down
40 changes: 20 additions & 20 deletions test/integration/Hub/UpdateCurveDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ const setup = async () => {
toETHNumber(meTokenDetails.balancePooled),
reserveWeight / MAX_WEIGHT
);
const targetassetsReturned = calculateCollateralReturned(
const targetAssetsReturned = calculateCollateralReturned(
toETHNumber(balAfter),
toETHNumber(meTokenTotalSupply),
toETHNumber(meTokenDetails.balancePooled),
Expand Down Expand Up @@ -337,7 +337,7 @@ const setup = async () => {
(rawAssetsReturned * refundRatio.toNumber()) / MAX_WEIGHT;
const calcWAvrgRes = weightedAverageSimulation(
rawAssetsReturned,
targetassetsReturned,
targetAssetsReturned,
startTime.toNumber(),
endTime.toNumber(),
block.timestamp
Expand Down Expand Up @@ -389,7 +389,7 @@ const setup = async () => {
toETHNumber(meTokenDetails.balancePooled),
reserveWeight / MAX_WEIGHT
);
const targetassetsReturned = calculateCollateralReturned(
const targetAssetsReturned = calculateCollateralReturned(
toETHNumber(metokenToBurn),
toETHNumber(meTokenTotalSupply),
toETHNumber(meTokenDetails.balancePooled),
Expand Down Expand Up @@ -419,7 +419,7 @@ const setup = async () => {

const calcWAvrgRes = weightedAverageSimulation(
rawAssetsReturned,
targetassetsReturned,
targetAssetsReturned,
startTime.toNumber(),
endTime.toNumber(),
block.timestamp
Expand Down Expand Up @@ -475,7 +475,7 @@ const setup = async () => {
toETHNumber(meTokenDetails.balancePooled),
reserveWeight / MAX_WEIGHT
);
const targetassetsReturned = calculateCollateralReturned(
const targetAssetsReturned = calculateCollateralReturned(
toETHNumber(metokenToBurn),
toETHNumber(meTokenTotalSupply),
toETHNumber(meTokenDetails.balancePooled),
Expand Down Expand Up @@ -506,7 +506,7 @@ const setup = async () => {
// the weighted average on the curve should be applied for owner and buyers
const calcWAvrgRes = weightedAverageSimulation(
rawAssetsReturned,
targetassetsReturned,
targetAssetsReturned,
startTime.toNumber(),
endTime.toNumber(),
block.timestamp
Expand Down Expand Up @@ -694,7 +694,7 @@ const setup = async () => {
curve,
targetCurve,
} = await hub.getDetails(1);
const targetassetsReturned = calculateCollateralReturned(
const targetAssetsReturned = calculateCollateralReturned(
toETHNumber(metokenToBurn),
toETHNumber(meTokenTotalSupply),
toETHNumber(meTokenDetails.balancePooled),
Expand Down Expand Up @@ -735,7 +735,7 @@ const setup = async () => {
// the weighted average on the curve should be applied for owner and buyers
// but the owner gets a proportional share of the token burnt from the balanced locked
const assetsReturned =
targetassetsReturned +
targetAssetsReturned +
(toETHNumber(metokenToBurn) / toETHNumber(meTokenTotalSupply)) *
toETHNumber(meTokenDetailsBeforeBurn.balanceLocked);

Expand Down Expand Up @@ -808,7 +808,7 @@ const setup = async () => {
curve,
targetCurve,
} = await hub.getDetails(1);
const targetassetsReturned = calculateCollateralReturned(
const targetAssetsReturned = calculateCollateralReturned(
toETHNumber(metokenToBurn),
toETHNumber(meTokenTotalSupply),
toETHNumber(meTokenDetails.balancePooled),
Expand Down Expand Up @@ -848,7 +848,7 @@ const setup = async () => {

// as it is a buyer we apply the refund ratio
const assetsReturned =
(targetassetsReturned * refundRatio.toNumber()) / MAX_WEIGHT;
(targetAssetsReturned * refundRatio.toNumber()) / MAX_WEIGHT;

// we get the calcWAvrgRes percentage of the tokens returned by the Metokens burn
// expect(balDaiAfterBurn.sub(balDaiAfterMint)).to.equal(calculatedReturn);
Expand Down Expand Up @@ -1046,7 +1046,7 @@ const setup = async () => {
toETHNumber(meTokenDetails.balancePooled),
reserveWeight / MAX_WEIGHT
);
const targetassetsReturned = calculateCollateralReturned(
const targetAssetsReturned = calculateCollateralReturned(
toETHNumber(balAfter),
toETHNumber(meTokenTotalSupply),
toETHNumber(meTokenDetails.balancePooled),
Expand Down Expand Up @@ -1076,7 +1076,7 @@ const setup = async () => {
(rawAssetsReturned * refundRatio.toNumber()) / MAX_WEIGHT;
const calcWAvrgRes = weightedAverageSimulation(
rawAssetsReturned,
targetassetsReturned,
targetAssetsReturned,
startTime.toNumber(),
endTime.toNumber(),
block.timestamp
Expand Down Expand Up @@ -1130,7 +1130,7 @@ const setup = async () => {
toETHNumber(meTokenDetails.balancePooled),
reserveWeight / MAX_WEIGHT
);
const targetassetsReturned = calculateCollateralReturned(
const targetAssetsReturned = calculateCollateralReturned(
toETHNumber(metokenToBurn),
toETHNumber(meTokenTotalSupply),
toETHNumber(meTokenDetails.balancePooled),
Expand Down Expand Up @@ -1160,7 +1160,7 @@ const setup = async () => {

const calcWAvrgRes = weightedAverageSimulation(
rawAssetsReturned,
targetassetsReturned,
targetAssetsReturned,
startTime.toNumber(),
endTime.toNumber(),
block.timestamp
Expand Down Expand Up @@ -1220,7 +1220,7 @@ const setup = async () => {
toETHNumber(meTokenDetails.balancePooled),
reserveWeight / MAX_WEIGHT
);
const targetassetsReturned = calculateCollateralReturned(
const targetAssetsReturned = calculateCollateralReturned(
toETHNumber(metokenToBurn),
toETHNumber(meTokenTotalSupply),
toETHNumber(meTokenDetails.balancePooled),
Expand Down Expand Up @@ -1252,7 +1252,7 @@ const setup = async () => {
// the weighted average on the curve should be applied for owner and buyers
const calcWAvrgRes = weightedAverageSimulation(
rawAssetsReturned,
targetassetsReturned,
targetAssetsReturned,
startTime.toNumber(),
endTime.toNumber(),
block.timestamp
Expand Down Expand Up @@ -1431,7 +1431,7 @@ const setup = async () => {
curve,
targetCurve,
} = await hub.getDetails(1);
const targetassetsReturned = calculateCollateralReturned(
const targetAssetsReturned = calculateCollateralReturned(
toETHNumber(metokenToBurn),
toETHNumber(meTokenTotalSupply),
toETHNumber(meTokenDetails.balancePooled),
Expand Down Expand Up @@ -1467,7 +1467,7 @@ const setup = async () => {

// but the owner gets a proportional share of the token burnt from the balanced locked
const assetsReturned =
targetassetsReturned +
targetAssetsReturned +
(toETHNumber(metokenToBurn) / toETHNumber(meTokenTotalSupply)) *
toETHNumber(meTokenDetailsBeforeBurn.balanceLocked);

Expand Down Expand Up @@ -1544,7 +1544,7 @@ const setup = async () => {
curve,
targetCurve,
} = await hub.getDetails(1);
const targetassetsReturned = calculateCollateralReturned(
const targetAssetsReturned = calculateCollateralReturned(
toETHNumber(metokenToBurn),
toETHNumber(meTokenTotalSupply),
toETHNumber(meTokenDetails.balancePooled),
Expand Down Expand Up @@ -1573,7 +1573,7 @@ const setup = async () => {

// as it is a buyer we apply the refund ratio
const assetsReturned =
(targetassetsReturned * refundRatio.toNumber()) / MAX_WEIGHT;
(targetAssetsReturned * refundRatio.toNumber()) / MAX_WEIGHT;

// we get the calcWAvrgRes percentage of the tokens returned by the Metokens burn
// expect(balDaiAfterBurn.sub(balDaiAfterMint)).to.equal(calculatedReturn);
Expand Down
Loading