Skip to content

Commit

Permalink
adding outboundAmount to NativeOFTV2 and NativeOFTWithFee
Browse files Browse the repository at this point in the history
  • Loading branch information
sirarthurmoney committed Nov 8, 2023
1 parent 920b723 commit 5c1632d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 5 additions & 0 deletions contracts/token/oft/v2/NativeOFTV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "./OFTV2.sol";

contract NativeOFTV2 is OFTV2, ReentrancyGuard {
uint public outboundAmount;

event Deposit(address indexed _dst, uint _amount);
event Withdrawal(address indexed _src, uint _amount);

Expand Down Expand Up @@ -115,6 +117,7 @@ contract NativeOFTV2 is OFTV2, ReentrancyGuard {

function _debitMsgSender(uint _amount) internal returns (uint messageFee) {
uint msgSenderBalance = balanceOf(msg.sender);
outboundAmount += _amount;

if (msgSenderBalance < _amount) {
require(msgSenderBalance + msg.value >= _amount, "NativeOFTV2: Insufficient msg.value");
Expand All @@ -135,6 +138,7 @@ contract NativeOFTV2 is OFTV2, ReentrancyGuard {

function _debitMsgFrom(address _from, uint _amount) internal returns (uint messageFee) {
uint msgFromBalance = balanceOf(_from);
outboundAmount += _amount;

if (msgFromBalance < _amount) {
require(msgFromBalance + msg.value >= _amount, "NativeOFTV2: Insufficient msg.value");
Expand Down Expand Up @@ -165,6 +169,7 @@ contract NativeOFTV2 is OFTV2, ReentrancyGuard {
address _toAddress,
uint _amount
) internal override returns (uint) {
outboundAmount -= _amount;
_burn(address(this), _amount);
(bool success, ) = _toAddress.call{value: _amount}("");
require(success, "NativeOFTV2: failed to _creditTo");
Expand Down
5 changes: 2 additions & 3 deletions contracts/token/oft/v2/fee/NativeOFTWithFee.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "./OFTWithFee.sol";

contract NativeOFTWithFee is OFTWithFee, ReentrancyGuard {

uint public outboundAmount;

event Deposit(address indexed _dst, uint _amount);
Expand Down Expand Up @@ -89,6 +88,7 @@ contract NativeOFTWithFee is OFTWithFee, ReentrancyGuard {

function _debitMsgSender(uint _amount, uint currentMsgValue) internal returns (uint messageFee) {
uint msgSenderBalance = balanceOf(msg.sender);
outboundAmount += _amount;

if (msgSenderBalance < _amount) {
require(msgSenderBalance + currentMsgValue >= _amount, "NativeOFTWithFee: Insufficient msg.value");
Expand All @@ -105,12 +105,12 @@ contract NativeOFTWithFee is OFTWithFee, ReentrancyGuard {
}

_transfer(msg.sender, address(this), _amount);
outboundAmount += _amount;
return messageFee;
}

function _debitMsgFrom(address _from, uint _amount, uint currentMsgValue) internal returns (uint messageFee) {
uint msgFromBalance = balanceOf(_from);
outboundAmount += _amount;

if (msgFromBalance < _amount) {
require(msgFromBalance + currentMsgValue >= _amount, "NativeOFTWithFee: Insufficient msg.value");
Expand All @@ -133,7 +133,6 @@ contract NativeOFTWithFee is OFTWithFee, ReentrancyGuard {

_spendAllowance(_from, msg.sender, _amount);
_transfer(_from, address(this), _amount);
outboundAmount += _amount;
return messageFee;
}

Expand Down

0 comments on commit 5c1632d

Please sign in to comment.