Skip to content

Commit 782aaaf

Browse files
authored
Merge pull request #339 from rsksmart/feature/GBI-2765
test: add pegout payer contract
2 parents 06f8f4d + 83e74d9 commit 782aaaf

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

contracts/test/PegOutPayer.sol

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.18;
3+
4+
import "../LiquidityBridgeContractV2.sol";
5+
import "../QuotesV2.sol";
6+
7+
contract PegOutPayer {
8+
9+
event Deposit(address indexed sender, uint256 amount);
10+
event PegOutPaid(QuotesV2.PegOutQuote quote, address indexed caller);
11+
event Withdraw(address indexed owner, uint256 amount);
12+
13+
LiquidityBridgeContractV2 public immutable lbc;
14+
address public immutable owner;
15+
16+
constructor(address payable _lbc) {
17+
lbc = LiquidityBridgeContractV2(_lbc);
18+
owner = msg.sender;
19+
}
20+
21+
22+
receive() external payable {
23+
emit Deposit(msg.sender, msg.value);
24+
}
25+
26+
function executePegOut(QuotesV2.PegOutQuote memory quote, bytes memory signature) external {
27+
uint256 total = quote.value + quote.gasFee + quote.callFee + quote.productFeeAmount;
28+
require(total <= address(this).balance, "Insufficient balance in contract");
29+
emit PegOutPaid(quote, msg.sender);
30+
lbc.depositPegout{value: total}(quote, signature);
31+
}
32+
33+
function withdraw(uint256 amount) external {
34+
require(msg.sender == owner, "Only owner can withdraw");
35+
require(amount <= address(this).balance, "Insufficient balance in contract");
36+
emit Withdraw(owner, amount);
37+
(bool sent, ) = payable(owner).call{value: amount}("");
38+
require(sent, "Failed to withdraw funds");
39+
}
40+
}

0 commit comments

Comments
 (0)