Skip to content
Merged
Changes from 1 commit
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
40 changes: 40 additions & 0 deletions contracts/test/PegOutPayer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import "../LiquidityBridgeContractV2.sol";
import "../QuotesV2.sol";

contract PegOutPayer {

event Deposit(address indexed sender, uint256 amount);
event PegOutPaid(QuotesV2.PegOutQuote quote, address indexed caller);
event Withdraw(address indexed owner, uint256 amount);

LiquidityBridgeContractV2 public immutable lbc;
address public immutable owner;

constructor(address payable _lbc) {
lbc = LiquidityBridgeContractV2(_lbc);
owner = msg.sender;
}


receive() external payable {
emit Deposit(msg.sender, msg.value);
}

function executePegOut(QuotesV2.PegOutQuote memory quote, bytes memory signature) external {
uint256 total = quote.value + quote.gasFee + quote.callFee + quote.productFeeAmount;
require(total <= address(this).balance, "Insufficient balance in contract");
lbc.depositPegout{value: total}(quote, signature);
emit PegOutPaid(quote, msg.sender);
}

function withdraw(uint256 amount) external {
require(msg.sender == owner, "Only owner can withdraw");
require(amount <= address(this).balance, "Insufficient balance in contract");
(bool sent, ) = payable(owner).call{value: amount}("");
require(sent, "Failed to withdraw funds");
emit Withdraw(owner, amount);
}
}