Skip to content

Commit

Permalink
refactor: added data to call pushed event in LaminatedProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
TokenTitan committed Oct 29, 2024
1 parent 3df9f9a commit c8212f3
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 25 deletions.
6 changes: 5 additions & 1 deletion src/TimeTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,18 @@ struct ReturnObject {
}

/// @param initialized Flag indicating if the CallObject has been pushed as a deferred call
/// @param executed The first block where the CallObject is callable
/// @param none The first block where the CallObject is callable
/// @param firstCallableBlock The first block where the CallObject is callable
/// @param callObj The actual CallObject instance
/// @param callObjs The list of call objs
/// @param data Additional info for the sequence of call objs
struct CallObjectHolder {
bool initialized;
bool executed;
uint256 nonce;
uint256 firstCallableBlock;
CallObject[] callObjs;
SolverData[] data;
}

struct CallObjectHolderStorage {
Expand Down
31 changes: 22 additions & 9 deletions src/lamination/LaminatedProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ contract LaminatedProxy is LaminatedStorage, ReentrancyGuard {
/// @dev Emitted when a function call is deferred and added to the queue.
/// @param callObjs The CallObject[] containing details of the deferred function call.
/// @param sequenceNumber The sequence number assigned to the deferred function call.
event CallPushed(CallObject[] callObjs, uint256 sequenceNumber);
/// @param data Additional data to be associated with the sequence of call objs
event CallPushed(CallObject[] callObjs, uint256 sequenceNumber, SolverData[] data);

/// @dev Emitted when a deferred function call is executed from the queue.
/// @param callObjs The CallObject[] containing details of the executed function call.
Expand Down Expand Up @@ -189,11 +190,17 @@ contract LaminatedProxy is LaminatedStorage, ReentrancyGuard {
/// @dev Returns a tuple containing a boolean indicating whether the deferred call exists,
/// and the CallObject containing details of the deferred function call.
/// @param seqNumber The sequence number of the deferred function call to view.
/// @return exists A boolean indicating whether the deferred call exists.
/// @return callObj The CallObject containing details of the deferred function call.
function viewDeferredCall(uint256 seqNumber) external view returns (bool, bool, CallObject[] memory) {
/// @return boolean indicating whether the deferred call was initialized.
/// @return boolean indicating whether the deferred call was execured.
/// @return the sequence of call objs to within the deferred function call.
/// @return the data associated to the deferred function call.
function viewDeferredCall(uint256 seqNumber)
external
view
returns (bool, bool, CallObject[] memory, SolverData[] memory)
{
CallObjectHolder memory coh = deferredCalls(seqNumber);
return (coh.initialized, coh.executed, coh.callObjs);
return (coh.initialized, coh.executed, coh.callObjs, coh.data);
}

function getExecutingCallObject() external view onlyWhileExecuting returns (CallObject memory) {
Expand All @@ -210,20 +217,25 @@ contract LaminatedProxy is LaminatedStorage, ReentrancyGuard {
/// It can also be called re-entrantly to enable the contract to do cronjobs with tail recursion.
/// @param input The encoded CallObject containing information about the function call to defer.
/// @param delay The number of blocks to delay before the function call can be executed.
/// Use 0 for no delay.
/// @param data Additional data to be associated with the sequence of call objs
/// @return callSequenceNumber The sequence number assigned to this deferred call.
function push(bytes memory input, uint256 delay) public onlyLaminatorOrProxy returns (uint256 callSequenceNumber) {
function push(bytes memory input, uint256 delay, SolverData[] memory data)
public
onlyLaminatorOrProxy
returns (uint256 callSequenceNumber)
{
CallObjectHolder memory holder;
holder.callObjs = abi.decode(input, (CallObject[]));
callSequenceNumber = _incrementSequenceNumber();
holder.initialized = true;
holder.executed = false;
holder.nonce = executingNonce;
holder.data = data;
holder.firstCallableBlock = block.number + delay;
_deferredCalls[callSequenceNumber].store(holder);

emit CallableBlock(block.number + delay, block.number);
emit CallPushed(holder.callObjs, callSequenceNumber);
emit CallPushed(holder.callObjs, callSequenceNumber, data);
}

/// @dev Executes the function call specified by the CallObject `callToMake`.
Expand Down Expand Up @@ -274,8 +286,9 @@ contract LaminatedProxy is LaminatedStorage, ReentrancyGuard {

CallObjectHolderStorage storage coh = _deferredCalls[seqNumber];
_checkInitialized(coh);
CallObjectHolder memory holder = coh.load();

return push(abi.encode(coh.load().callObjs), delay);
return push(abi.encode(holder.callObjs), delay, holder.data);
}

/// @dev Safety checks before pushing calls to the LaminatedProxy
Expand Down
2 changes: 1 addition & 1 deletion src/lamination/Laminator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ contract Laminator is ILaminator {
{
LaminatedProxy proxy = LaminatedProxy(payable(_getOrCreateProxy(msg.sender)));

sequenceNumber = proxy.push(cData, delay);
sequenceNumber = proxy.push(cData, delay, dataValues);

CallObject[] memory callObjs = abi.decode(cData, (CallObject[]));
emit ProxyPushed(address(proxy), callObjs, sequenceNumber, selector, dataValues);
Expand Down
2 changes: 1 addition & 1 deletion test/CronCounter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ contract CronTest is Test, CronCounterLib {
assertFalse(callbreaker.isPortalOpen());

// Should be cleared so init should be false (testFail format is for compliance with Kontrol framework)
(bool init, bool exec,) = LaminatedProxy(pusherLaminated).viewDeferredCall(laminatorSequenceNumber);
(bool init, bool exec,,) = LaminatedProxy(pusherLaminated).viewDeferredCall(laminatorSequenceNumber);

assertTrue(init);
assertTrue(exec);
Expand Down
2 changes: 1 addition & 1 deletion test/FlashLiquidity.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ contract FlashLiquidityTest is Test, FlashLiquidityLib {

assertFalse(callbreaker.isPortalOpen());

(bool init, bool exec,) = LaminatedProxy(pusherLaminated).viewDeferredCall(laminatorSequenceNumber);
(bool init, bool exec,,) = LaminatedProxy(pusherLaminated).viewDeferredCall(laminatorSequenceNumber);

assertTrue(init);
assertTrue(exec);
Expand Down
2 changes: 1 addition & 1 deletion test/FlashLoan.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ contract FlashLoanTest is Test, FlashLoanLib {

assertFalse(callbreaker.isPortalOpen());

(bool init, bool exec,) = LaminatedProxy(pusherLaminated).viewDeferredCall(laminatorSequenceNumber);
(bool init, bool exec,,) = LaminatedProxy(pusherLaminated).viewDeferredCall(laminatorSequenceNumber);

assertTrue(init);
assertTrue(exec);
Expand Down
16 changes: 10 additions & 6 deletions test/Laminator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ contract LaminatorTest is Test {
SolverData[] dataValues
);
event ProxyCreated(address indexed owner, address indexed proxyAddress);
event CallPushed(CallObject[] callObjs, uint256 sequenceNumber);
event CallPushed(CallObject[] callObjs, uint256 sequenceNumber, SolverData[] data);
event CallPulled(CallObject[] callObjs, uint256 sequenceNumber);
event CallExecuted(CallObject callObj);

Expand Down Expand Up @@ -82,7 +82,7 @@ contract LaminatorTest is Test {

vm.expectEmit(true, true, true, true);
emit ProxyPushed(address(proxy), callObj1, 0, DEFAULT_CODE, dataValues);
emit CallPushed(callObj1, 0);
emit CallPushed(callObj1, 0, dataValues);

uint256 sequenceNumber1 = laminator.pushToProxy(cData, 1, DEFAULT_CODE, dataValues);
assertEq(sequenceNumber1, 0);
Expand All @@ -102,7 +102,7 @@ contract LaminatorTest is Test {
cData = abi.encode(callObj2);
vm.expectEmit(true, true, true, true);
emit ProxyPushed(address(proxy), callObj2, 1, DEFAULT_CODE, dataValues);
emit CallPushed(callObj2, 1);
emit CallPushed(callObj1, 0, dataValues);
uint256 sequenceNumber2 = laminator.pushToProxy(cData, 1, DEFAULT_CODE, dataValues);
assertEq(sequenceNumber2, 1);

Expand Down Expand Up @@ -207,9 +207,11 @@ contract LaminatorTest is Test {
callvalue: abi.encodeWithSignature("emitArg(uint256)", val)
});
bytes memory cData = abi.encode(callObj);
SolverData[] memory dataValues = Constants.emptyDataValues();

vm.prank(randomFriendAddress, randomFriendAddress);
vm.expectRevert(LaminatedProxy.NotLaminatorOrProxy.selector);
proxy.push(cData, 0);
proxy.push(cData, 0, dataValues);
}

// ensure pushes as the laminator work
Expand All @@ -225,10 +227,12 @@ contract LaminatorTest is Test {
callvalue: abi.encodeWithSignature("emitArg(uint256)", val)
});
bytes memory cData = abi.encode(callObj);
SolverData[] memory dataValues = Constants.emptyDataValues();

vm.prank(address(laminator), address(laminator));
vm.expectEmit(true, true, true, true);
emit CallPushed(callObj, 0);
proxy.push(cData, 1);
emit CallPushed(callObj, 0, dataValues);
proxy.push(cData, 1, dataValues);
}

function testExecute() public {
Expand Down
2 changes: 1 addition & 1 deletion test/MEVTimeCompute.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract MEVTimeComputeTest is Test, MEVTimeComputeLib {

assertFalse(callbreaker.isPortalOpen());

(bool init, bool exec,) = LaminatedProxy(pusherLaminated).viewDeferredCall(laminatorSequenceNumber);
(bool init, bool exec,,) = LaminatedProxy(pusherLaminated).viewDeferredCall(laminatorSequenceNumber);

assertTrue(init);
assertTrue(exec);
Expand Down
2 changes: 1 addition & 1 deletion test/PnP.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract PnPTest is Test, PnPLib {

assertFalse(callbreaker.isPortalOpen());

(bool init, bool exec,) = LaminatedProxy(pusherLaminated).viewDeferredCall(laminatorSequenceNumber);
(bool init, bool exec,,) = LaminatedProxy(pusherLaminated).viewDeferredCall(laminatorSequenceNumber);

assertTrue(init);
assertTrue(exec);
Expand Down
2 changes: 1 addition & 1 deletion test/Sandwich.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ contract CronTest is Test, CronCounterLib {
assertFalse(callbreaker.isPortalOpen());

// Should be cleared so init should be false (testFail format is for compliance with Kontrol framework)
(bool init, bool exec,) = LaminatedProxy(pusherLaminated).viewDeferredCall(laminatorSequenceNumber);
(bool init, bool exec,,) = LaminatedProxy(pusherLaminated).viewDeferredCall(laminatorSequenceNumber);

assertTrue(init);
assertTrue(exec);
Expand Down
2 changes: 1 addition & 1 deletion test/SelfCheckout.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ contract SelfCheckoutTest is Test, SelfCheckoutLib {
assertEq(erc20b.balanceOf(filler), 0);
assertFalse(callbreaker.isPortalOpen());

(bool init, bool exec,) = LaminatedProxy(pusherLaminated).viewDeferredCall(laminatorSequenceNumber);
(bool init, bool exec,,) = LaminatedProxy(pusherLaminated).viewDeferredCall(laminatorSequenceNumber);

assertTrue(init);
assertTrue(exec);
Expand Down
2 changes: 1 addition & 1 deletion test/SlippageProtection.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract SlippageProtectionTest is Test, SlippageProtectionLib {

assertFalse(callbreaker.isPortalOpen());

(bool init, bool exec,) = LaminatedProxy(pusherLaminated).viewDeferredCall(laminatorSequenceNumber);
(bool init, bool exec,,) = LaminatedProxy(pusherLaminated).viewDeferredCall(laminatorSequenceNumber);

assertTrue(init);
assertTrue(exec);
Expand Down

0 comments on commit c8212f3

Please sign in to comment.