Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
gas optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
simonDos committed Sep 19, 2023
1 parent e041d76 commit 116bed5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .soliumrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"no-unused-vars": 1,
"quotes": 1,
"error-reason": 0,
"indentation": ["error", 2],
"indentation": ["error", 4],
"arg-overflow": ["error", 8],
"whitespace": 1,
"deprecated-suicide": 1,
Expand Down
35 changes: 18 additions & 17 deletions contracts/root/depositManager/DepositManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ interface IPolygonMigration {
function migrate(uint256 amount) external;
}


contract DepositManager is DepositManagerStorage, IDepositManager, ERC721Holder {
using SafeMath for uint256;
using SafeERC20 for IERC20;

modifier isTokenMapped(address _token) {
// new: exception for POL token
require(registry.isTokenMapped(_token) || _token == registry.contractMap(keccak256("pol")), "TOKEN_NOT_SUPPORTED");
require(
registry.isTokenMapped(_token) || _token == registry.contractMap(keccak256("pol")),
"TOKEN_NOT_SUPPORTED"
);
_;
}

Expand Down Expand Up @@ -68,21 +70,21 @@ contract DepositManager is DepositManagerStorage, IDepositManager, ERC721Holder
function transferAssets(address _token, address _user, uint256 _amountOrNFTId) external isPredicateAuthorized {
address wethToken = registry.getWethTokenAddress();

// so we don't assign to a function var
address memory token = _token;

// new: pay out POL when MATIC is withdrawn
if (_token == registry.contractMap(keccak256("matic"))) {
token = registry.contractMap(keccak256("pol"));
}

if (registry.isERC721(token)) {
IERC721(token).transferFrom(address(this), _user, _amountOrNFTId);
} else if (token == wethToken) {
WETH t = WETH(token);
if (registry.isERC721(_token)) {
IERC721(_token).transferFrom(address(this), _user, _amountOrNFTId);
} else if (_token == wethToken) {
WETH t = WETH(_token);
t.withdraw(_amountOrNFTId, _user);
} else {
require(IERC20(token).transfer(_user, _amountOrNFTId), "TRANSFER_FAILED");
// new: pay out POL when MATIC is withdrawn
if (_token == registry.contractMap(keccak256("matic"))) {
require(
IERC20(registry.contractMap(keccak256("pol"))).transfer(_user, _amountOrNFTId),
"TRANSFER_FAILED"
);
} else {
require(IERC20(_token).transfer(_user, _amountOrNFTId), "TRANSFER_FAILED");
}
}
}

Expand Down Expand Up @@ -167,9 +169,8 @@ contract DepositManager is DepositManagerStorage, IDepositManager, ERC721Holder
if (_token == registry.contractMap(keccak256("matic"))) {
_migrateMatic(_amountOrToken);
}

// new: bridge POL as MATIC, child chain behaviour does not change
if(_token == registry.contractMap(keccak256("pol"))) {
else if (_token == registry.contractMap(keccak256("pol"))) {
_token == registry.contractMap(keccak256("matic"));
}

Expand Down

0 comments on commit 116bed5

Please sign in to comment.