Skip to content

Commit

Permalink
Merge pull request #250 from subquery/add-per-account-limit
Browse files Browse the repository at this point in the history
add per account trade limit (usd)
  • Loading branch information
ianhe8x authored Sep 27, 2023
2 parents 2741e06 + 1fd889c commit 61932c3
Show file tree
Hide file tree
Showing 3 changed files with 232 additions and 79 deletions.
23 changes: 23 additions & 0 deletions contracts/PermissionedExchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ contract PermissionedExchange is Initializable, OwnableUpgradeable {
mapping(uint256 => ExchangeOrder) public orders;
/// @notice stable coin trade limitation
uint256 public tradeLimitation;
/// @notice accumulated stable coin trades per account
mapping(address => uint256) public accumulatedTrades;
/// @notice stable coin trade limitation per account
uint256 public tradeLimitationPerAccount;

/// @dev ### EVENTS
/// @notice Emitted when exchange order sent.
Expand Down Expand Up @@ -110,6 +114,23 @@ contract PermissionedExchange is Initializable, OwnableUpgradeable {
tradeLimitation = _limit;
}

/**
* @notice Set the stable coin trading limitation in single transaction.
* @param _limit New limitation.
*/
function setTradeLimitationPerAccount(uint256 _limit) external onlyOwner {
tradeLimitationPerAccount = _limit;
}

/**
* @notice Override accumulatedTrades for given user
* @param user user address
* @param newValue new accumulatedTrades value
*/
function setAccumulatedTrades(address user, uint256 newValue) external onlyOwner {
accumulatedTrades[user] = newValue;
}

/**
* @notice Add liquidity to a exist order.
* @param _orderId order id
Expand Down Expand Up @@ -214,6 +235,8 @@ contract PermissionedExchange is Initializable, OwnableUpgradeable {
}
if (order.tokenGive == settings.getSQToken()) {
require(_amount <= tradeLimitation, 'PE012');
accumulatedTrades[msg.sender] = accumulatedTrades[msg.sender] + _amount;
require(accumulatedTrades[msg.sender] <= tradeLimitationPerAccount, 'PE013');
}
require(order.expireDate > block.timestamp, 'PE006');
uint256 amount = (order.amountGive * _amount) / order.amountGet;
Expand Down
63 changes: 63 additions & 0 deletions publish/ABI/PermissionedExchange.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,25 @@
"name": "Trade",
"type": "event"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "accumulatedTrades",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -444,6 +463,24 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "user",
"type": "address"
},
{
"internalType": "uint256",
"name": "newValue",
"type": "uint256"
}
],
"name": "setAccumulatedTrades",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -488,6 +525,19 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_limit",
"type": "uint256"
}
],
"name": "setTradeLimitationPerAccount",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "settings",
Expand Down Expand Up @@ -545,6 +595,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "tradeLimitationPerAccount",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down
Loading

0 comments on commit 61932c3

Please sign in to comment.