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(Escrow): cap the amount #88

Merged
merged 2 commits into from
Dec 18, 2024
Merged
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
14 changes: 12 additions & 2 deletions contracts/src/EscrowUniversal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ contract EscrowUniversal is IEscrow, IArbitrableV2 {
uint256 public settlementTimeout; // Time in seconds a party can take to accept or propose a settlement before being considered unresponsive.
Transaction[] public transactions; // List of all created transactions.
mapping(uint256 => uint256) public disputeIDtoTransactionID; // Naps dispute ID to tx ID.
mapping(IERC20 => uint256) public amountCaps; // Caps the amount of the respective token for the Escrow transaction.

// ************************************* //
// * Function Modifiers * //
Expand All @@ -47,6 +48,11 @@ contract EscrowUniversal is IEscrow, IArbitrableV2 {
_;
}

modifier shouldNotExceedCap(IERC20 _token, uint256 _amount) {
if (amountCaps[_token] != 0 && _amount > amountCaps[_token]) revert AmountExceedsCap();
_;
}

// ************************************* //
// * Constructor * //
// ************************************* //
Expand Down Expand Up @@ -117,6 +123,10 @@ contract EscrowUniversal is IEscrow, IArbitrableV2 {
emit ParameterUpdated(feeTimeout, _settlementTimeout, arbitratorExtraData);
}

function changeAmountCap(IERC20 _token, uint256 _amountCap) external onlyByGovernor {
amountCaps[_token] = _amountCap;
}
jaybuidl marked this conversation as resolved.
Show resolved Hide resolved

// ************************************* //
// * State Modifiers * //
// ************************************* //
Expand All @@ -126,7 +136,7 @@ contract EscrowUniversal is IEscrow, IArbitrableV2 {
uint256 _deadline,
string memory _transactionUri,
address payable _seller
) external payable override returns (uint256 transactionID) {
) external payable override shouldNotExceedCap(NATIVE, msg.value) returns (uint256 transactionID) {
Transaction storage transaction = transactions.push();
transaction.buyer = payable(msg.sender);
transaction.seller = _seller;
Expand All @@ -153,7 +163,7 @@ contract EscrowUniversal is IEscrow, IArbitrableV2 {
uint256 _deadline,
string memory _transactionUri,
address payable _seller
) external override returns (uint256 transactionID) {
) external override shouldNotExceedCap(_token, _amount) returns (uint256 transactionID) {
// Transfers token from sender wallet to contract.
if (!_token.safeTransferFrom(msg.sender, address(this), _amount)) revert TokenTransferFailed();
Transaction storage transaction = transactions.push();
Expand Down
1 change: 1 addition & 0 deletions contracts/src/interfaces/IEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,5 @@ interface IEscrow {
error SettlementPeriodNotOver();
error NotSupported();
error TokenTransferFailed();
error AmountExceedsCap();
}
Loading