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

feat(contract): withdraw_from_service_manager in BatcherPaymentService.sol #1772

Open
wants to merge 4 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions contracts/script/output/devnet/batcher_deployment_output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"addresses": {
"batcherPaymentService": "0x7bc06c482DEAd17c0e297aFbC32f6e63d3846650",
"batcherPaymentServiceImplementation": "0x7969c5eD335650692Bc04293B07F5BF2e7A673C0"
}
}

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions contracts/src/core/BatcherPaymentService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ contract BatcherPaymentService is

// PAYABLE FUNCTIONS
receive() external payable {
userData[msg.sender].balance += msg.value;
userData[msg.sender].unlockBlockTime = 0;
emit PaymentReceived(msg.sender, msg.value);
if (msg.sender != address(alignedLayerServiceManager)) { // `alignedLayerServiceManager.withdraw()` triggers `receive()` (and with only 2300 gas)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MauroToscano does it make sense to you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uri mentioned it doesn't work without that, you can try just in case

userData[msg.sender].balance += msg.value;
userData[msg.sender].unlockBlockTime = 0;
emit PaymentReceived(msg.sender, msg.value);
}
}

// PUBLIC FUNCTIONS
Expand Down Expand Up @@ -178,6 +180,18 @@ contract BatcherPaymentService is
emit FundsWithdrawn(msg.sender, amount);
}


function withdrawFromServiceManager(
uint256 amount,
address withdrawAddress
) public payable onlyOwner {
alignedLayerServiceManager.withdraw(amount); // reverts if InsufficientBalance
// money is now in this contract
// we transfer it to the withdraw address
payable(withdrawAddress).transfer(amount); // non-reentrant since .transfer() has low gas limit. Also, Owner is a multisig.
// this.balance is unchanged
}

function pause() public onlyOwner {
_pause();
}
Expand Down
2 changes: 2 additions & 0 deletions contracts/src/core/IAlignedLayerServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ interface IAlignedLayerServiceManager {

function balanceOf(address account) external view returns (uint256);

function withdraw(uint256 amount) external;

function setAggregator(address _aggregator) external;

function isVerifierDisabled(
Expand Down