Skip to content

Commit 75ecdea

Browse files
authored
Merge pull request #145 from meTokens/fix/remove-soonest
Remove Soonest
2 parents d9dc4cb + 0a6138a commit 75ecdea

File tree

10 files changed

+117
-131
lines changed

10 files changed

+117
-131
lines changed

contracts/migrations/SameAssetTransferMigration.sol

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ contract SameAssetTransferMigration is ReentrancyGuard, Vault, IMigration {
6060
HubInfo memory hubInfo = IHubFacet(diamond).getHubInfo(
6161
meTokenInfo.hubId
6262
);
63-
if (usts.isMigrating && !usts.started) {
63+
if (
64+
usts.isMigrating && // this is to ensure the meToken is resubscribing
65+
block.timestamp > meTokenInfo.startTime && // swap can only happen after resubscribe
66+
!usts.started // should skip if already started
67+
) {
6468
ISingleAssetVault(hubInfo.vault).startMigration(meToken);
6569
usts.started = true;
6670
}

contracts/migrations/UniswapSingleTransferMigration.sol

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ contract UniswapSingleTransferMigration is ReentrancyGuard, Vault, IMigration {
2323
using SafeERC20 for IERC20;
2424

2525
struct UniswapSingleTransfer {
26-
// The earliest time that the swap can occur
27-
uint256 soonest;
2826
// Fee configured to pay on swap
2927
uint24 fee;
3028
// if migration is active and startMigration() has not been triggered
@@ -65,13 +63,9 @@ contract UniswapSingleTransferMigration is ReentrancyGuard, Vault, IMigration {
6563

6664
require(hubInfo.asset != targetHubInfo.asset, "same asset");
6765

68-
(uint256 soonest, uint24 fee) = abi.decode(
69-
encodedArgs,
70-
(uint256, uint24)
71-
);
66+
uint24 fee = abi.decode(encodedArgs, (uint24));
7267
UniswapSingleTransfer storage usts = _uniswapSingleTransfers[meToken];
7368
usts.fee = fee;
74-
usts.soonest = soonest;
7569
}
7670

7771
/// @inheritdoc IMigration
@@ -84,9 +78,9 @@ contract UniswapSingleTransferMigration is ReentrancyGuard, Vault, IMigration {
8478
meTokenInfo.hubId
8579
);
8680
if (
87-
usts.soonest != 0 && // this is to ensure the meToken is resubscribing
88-
block.timestamp > usts.soonest &&
89-
!usts.started
81+
usts.fee != 0 && // this is to ensure the meToken is resubscribing
82+
block.timestamp > meTokenInfo.startTime && // swap can only happen after resubscribe
83+
!usts.started // should skip if already started
9084
) {
9185
ISingleAssetVault(hubInfo.vault).startMigration(meToken);
9286
usts.started = true;
@@ -103,7 +97,6 @@ contract UniswapSingleTransferMigration is ReentrancyGuard, Vault, IMigration {
10397
{
10498
require(msg.sender == diamond, "!diamond");
10599
UniswapSingleTransfer storage usts = _uniswapSingleTransfers[meToken];
106-
require(usts.soonest < block.timestamp, "timestamp < soonest");
107100

108101
MeTokenInfo memory meTokenInfo = IMeTokenRegistryFacet(diamond)
109102
.getMeTokenInfo(meToken);
@@ -116,7 +109,6 @@ contract UniswapSingleTransferMigration is ReentrancyGuard, Vault, IMigration {
116109

117110
if (!usts.started) {
118111
ISingleAssetVault(hubInfo.vault).startMigration(meToken);
119-
usts.started = true;
120112
amountOut = _swap(meToken);
121113
} else {
122114
// No swap, amountOut = amountIn
@@ -150,11 +142,11 @@ contract UniswapSingleTransferMigration is ReentrancyGuard, Vault, IMigration {
150142
{
151143
// encodedArgs empty
152144
if (encodedArgs.length == 0) return false;
153-
(uint256 soon, uint24 fee) = abi.decode(encodedArgs, (uint256, uint24));
154-
// Too soon
155-
if (soon < block.timestamp) return false;
145+
156146
MeTokenInfo memory meTokenInfo = IMeTokenRegistryFacet(diamond)
157147
.getMeTokenInfo(meToken);
148+
uint24 fee = abi.decode(encodedArgs, (uint24));
149+
158150
// MeToken not subscribed to a hub
159151
if (meTokenInfo.hubId == 0) return false;
160152
// Invalid fee
@@ -193,14 +185,8 @@ contract UniswapSingleTransferMigration is ReentrancyGuard, Vault, IMigration {
193185
// - There are tokens to swap
194186
// - The resubscription has started
195187
// - The asset hasn't been swapped
196-
// - Current time is past the soonest it can swap, and time to swap has been set
197-
if (
198-
amountIn == 0 ||
199-
!usts.started ||
200-
usts.swapped ||
201-
usts.soonest == 0 ||
202-
usts.soonest > block.timestamp
203-
) {
188+
// - Current time is past the startTime it can swap, and time to swap has been set
189+
if (amountIn == 0) {
204190
return 0;
205191
}
206192

test/contracts/facets/FoundryFacet.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -974,10 +974,7 @@ const setup = async () => {
974974
account1.address, // DAO
975975
foundry.address // diamond
976976
);
977-
const block = await ethers.provider.getBlock("latest");
978-
// earliestSwapTime 10 hour
979-
const earliestSwapTime = block.timestamp + 600 * 60;
980-
ethers.utils.defaultAbiCoder.encode(["uint256"], [earliestSwapTime]);
977+
981978
// 10 hour
982979
await hub.setHubDuration(600 * 60);
983980
await hub.setHubWarmup(60 * 60);
@@ -1212,10 +1209,9 @@ const setup = async () => {
12121209
);
12131210

12141211
let block = await ethers.provider.getBlock("latest");
1215-
const earliestSwapTime = block.timestamp + 600 * 60; // 10h in future
12161212
const encodedMigrationArgs = ethers.utils.defaultAbiCoder.encode(
1217-
["uint256", "uint24"],
1218-
[earliestSwapTime, fee]
1213+
["uint24"],
1214+
[fee]
12191215
);
12201216

12211217
await meTokenRegistry
@@ -1226,14 +1222,15 @@ const setup = async () => {
12261222
migration.address,
12271223
encodedMigrationArgs
12281224
);
1229-
expect(
1230-
(await meTokenRegistry.getMeTokenInfo(meToken.address)).migration
1231-
).to.equal(migration.address);
1232-
const migrationDetails = await migration.getDetails(meToken.address);
1233-
await mineBlock(migrationDetails.soonest.toNumber() + 2);
1225+
1226+
const meTokenDetails = await meTokenRegistry.getMeTokenInfo(
1227+
meToken.address
1228+
);
1229+
expect(meTokenDetails.migration).to.equal(migration.address);
1230+
await mineBlock(meTokenDetails.startTime.toNumber() + 2);
12341231

12351232
block = await ethers.provider.getBlock("latest");
1236-
expect(migrationDetails.soonest).to.be.lt(block.timestamp);
1233+
expect(meTokenDetails.startTime).to.be.lt(block.timestamp);
12371234
});
12381235
it("should revert when meToken is resubscribing", async () => {
12391236
await expect(foundry.donate(meToken.address, 10)).to.be.revertedWith(

test/contracts/facets/MeTokenRegistryFacet.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,10 @@ const setup = async () => {
435435
meToken = meTokenAddr0;
436436
targetHubId = hubId2;
437437
block = await ethers.provider.getBlock("latest");
438-
const earliestSwapTime = block.timestamp + 600 * 60; // 10h in future
438+
439439
encodedMigrationArgs = ethers.utils.defaultAbiCoder.encode(
440-
["uint256", "uint24"],
441-
[earliestSwapTime, fees]
440+
["uint24"],
441+
[fees]
442442
);
443443

444444
const tx = meTokenRegistry
@@ -654,10 +654,9 @@ const setup = async () => {
654654
block = await ethers.provider.getBlock("latest");
655655
expect(oldMeTokenRegistryDetails.endCooldown).to.be.lt(block.timestamp);
656656

657-
const earliestSwapTime = block.timestamp + 600 * 60; // 10h in future
658657
encodedMigrationArgs = ethers.utils.defaultAbiCoder.encode(
659-
["uint256", "uint24"],
660-
[earliestSwapTime, fees]
658+
["uint24"],
659+
[fees]
661660
);
662661

663662
tx = await meTokenRegistry.initResubscribe(
@@ -677,10 +676,9 @@ const setup = async () => {
677676
);
678677
block = await ethers.provider.getBlock("latest");
679678

680-
const earliestSwapTime = block.timestamp + 600 * 60; // 10h in future
681679
encodedMigrationArgs = ethers.utils.defaultAbiCoder.encode(
682-
["uint256", "uint24"],
683-
[earliestSwapTime, fees]
680+
["uint24"],
681+
[fees]
684682
);
685683

686684
await meTokenRegistry.initResubscribe(
@@ -700,8 +698,10 @@ const setup = async () => {
700698
await foundry.mint(meTokenAddr0, tokenDeposited, account0.address);
701699

702700
await mineBlock(
703-
(await migration.getDetails(meTokenAddr0)).soonest.toNumber() + 2
704-
); // starTime > soonest
701+
(
702+
await meTokenRegistry.getMeTokenInfo(meTokenAddr0)
703+
).startTime.toNumber() + 2
704+
);
705705

706706
tx = await migration.poke(meTokenAddr0); // would call startMigration and swap
707707

@@ -779,10 +779,9 @@ const setup = async () => {
779779

780780
describe("updateBalances()", () => {
781781
before(async () => {
782-
const earliestSwapTime = block.timestamp + 600 * 60; // 10h in future
783782
encodedMigrationArgs = ethers.utils.defaultAbiCoder.encode(
784-
["uint256", "uint24"],
785-
[earliestSwapTime, fees]
783+
["uint24"],
784+
[fees]
786785
);
787786

788787
tx = await meTokenRegistry

test/contracts/migrations/SameAssetTransferMigration.ts

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919

2020
const setup = async () => {
2121
describe("SameAssetTransferMigration.sol", () => {
22-
let earliestSwapTime: number;
2322
let DAI: string;
2423
let DAIWhale: string;
2524
let daiHolder: Signer;
@@ -72,9 +71,6 @@ const setup = async () => {
7271
[DAI]
7372
);
7473

75-
const block = await ethers.provider.getBlock("latest");
76-
earliestSwapTime = block.timestamp + 600 * 60; // 10h in future
77-
7874
encodedMigrationArgs = "0x";
7975

8076
({
@@ -139,7 +135,11 @@ const setup = async () => {
139135
account1.address
140136
);
141137
meToken = await getContractAt<MeToken>("MeToken", meTokenAddr);
138+
142139
await hub.setHubWarmup(hubWarmup);
140+
await meTokenRegistry.setMeTokenWarmup(warmup);
141+
await meTokenRegistry.setMeTokenDuration(duration);
142+
await meTokenRegistry.setMeTokenCooldown(coolDown);
143143
});
144144

145145
describe("isValid()", () => {
@@ -236,6 +236,16 @@ const setup = async () => {
236236

237237
await expect(tx).to.not.emit(initialVault, "StartMigration");
238238
});
239+
it("should be able to call when migration before startTime(), but wont run startMigration()", async () => {
240+
const meTokenInfo = await meTokenRegistry.getMeTokenInfo(
241+
meToken.address
242+
);
243+
block = await ethers.provider.getBlock("latest");
244+
expect(meTokenInfo.startTime).to.be.gt(block.timestamp);
245+
246+
const tx = await migration.poke(meToken.address);
247+
await expect(tx).to.not.emit(initialVault, "StartMigration");
248+
});
239249
it("Triggers startMigration()", async () => {
240250
const meTokenInfo = await meTokenRegistry.getMeTokenInfo(
241251
meToken.address
@@ -271,6 +281,7 @@ const setup = async () => {
271281
meToken.address
272282
);
273283

284+
await mineBlock(meTokenRegistryDetails.endTime.toNumber() + 2);
274285
block = await ethers.provider.getBlock("latest");
275286
expect(meTokenRegistryDetails.endTime).to.be.lt(block.timestamp);
276287

@@ -294,13 +305,15 @@ const setup = async () => {
294305
expect(migrationDetails.started).to.equal(false);
295306
});
296307
it("Triggers startsMigration() if it hasn't already started", async () => {
308+
let meTokenRegistryDetails = await meTokenRegistry.getMeTokenInfo(
309+
meToken.address
310+
);
311+
312+
await mineBlock(meTokenRegistryDetails.endCooldown.toNumber() + 2);
297313
block = await ethers.provider.getBlock("latest");
298-
earliestSwapTime = block.timestamp + 600 * 60; // 10h in future
314+
expect(meTokenRegistryDetails.endCooldown).to.be.lt(block.timestamp);
299315

300-
encodedMigrationArgs = ethers.utils.defaultAbiCoder.encode(
301-
["uint256", "uint24"],
302-
[earliestSwapTime, fees]
303-
);
316+
encodedMigrationArgs = "0x";
304317

305318
await meTokenRegistry
306319
.connect(account1)
@@ -310,10 +323,14 @@ const setup = async () => {
310323
migration.address,
311324
encodedMigrationArgs
312325
);
313-
let meTokenRegistryDetails = await meTokenRegistry.getMeTokenInfo(
326+
meTokenRegistryDetails = await meTokenRegistry.getMeTokenInfo(
314327
meToken.address
315328
);
316329

330+
await mineBlock(meTokenRegistryDetails.endTime.toNumber() + 2);
331+
block = await ethers.provider.getBlock("latest");
332+
expect(meTokenRegistryDetails.endTime).to.be.lt(block.timestamp);
333+
317334
const tx = await meTokenRegistry.finishResubscribe(meToken.address);
318335
await tx.wait();
319336

@@ -339,10 +356,6 @@ const setup = async () => {
339356

340357
describe("During resubscribe", () => {
341358
before(async () => {
342-
await meTokenRegistry.setMeTokenWarmup(warmup);
343-
await meTokenRegistry.setMeTokenDuration(duration);
344-
await meTokenRegistry.setMeTokenCooldown(coolDown);
345-
346359
await meTokenRegistry
347360
.connect(account2)
348361
.subscribe(name, symbol, hubId1, 0);
@@ -351,13 +364,7 @@ const setup = async () => {
351364
);
352365
meToken = await getContractAt<MeToken>("MeToken", meTokenAddr);
353366

354-
block = await ethers.provider.getBlock("latest");
355-
earliestSwapTime = block.timestamp + 600 * 60; // 10h in future
356-
357-
encodedMigrationArgs = ethers.utils.defaultAbiCoder.encode(
358-
["uint256", "uint24"],
359-
[earliestSwapTime, fees]
360-
);
367+
encodedMigrationArgs = "0x";
361368

362369
await meTokenRegistry
363370
.connect(account2)

0 commit comments

Comments
 (0)