diff --git a/abis/GrtLiquidityWallet.json b/abis/GrtLiquidityWallet.json index 009d180..aa8cc28 100644 --- a/abis/GrtLiquidityWallet.json +++ b/abis/GrtLiquidityWallet.json @@ -1,4 +1,19 @@ [ + { + "inputs": [], + "name": "FailedToSendNativeTokens", + "type": "error" + }, + { + "inputs": [], + "name": "InsufficientBalance", + "type": "error" + }, + { + "inputs": [], + "name": "NotAllowedToPayTheOffer", + "type": "error" + }, { "anonymous": false, "inputs": [ diff --git a/abis/GrtPool.json b/abis/GrtPool.json index f2fc7b6..b2fcfeb 100644 --- a/abis/GrtPool.json +++ b/abis/GrtPool.json @@ -1,4 +1,34 @@ [ + { + "inputs": [], + "name": "FailedToSendNativeTokens", + "type": "error" + }, + { + "inputs": [], + "name": "NotAllowedToModifyOffer", + "type": "error" + }, + { + "inputs": [], + "name": "OfferInactive", + "type": "error" + }, + { + "inputs": [], + "name": "TransferedAmountMustBePositive", + "type": "error" + }, + { + "inputs": [], + "name": "ZeroAddressIsNotAllowed", + "type": "error" + }, + { + "inputs": [], + "name": "ZeroAddressNotAllowed", + "type": "error" + }, { "anonymous": false, "inputs": [ diff --git a/contracts/v-testnet-launch/GrtOffer.sol b/contracts/v-testnet-launch/GrtOffer.sol index 3f0dbb2..21e8a49 100644 --- a/contracts/v-testnet-launch/GrtOffer.sol +++ b/contracts/v-testnet-launch/GrtOffer.sol @@ -25,56 +25,53 @@ contract GrtOffer is GrtOfferUtils { ); event LogSetStatusOffer(bytes32 indexed _idOffer, bool indexed _isActive); - function setChainIdOffer(bytes32 offerId, uint256 chainId) external { + modifier isOwner(Offer memory offer) { require( - msg.sender == _offers[offerId].user, + msg.sender == offer.user, "Grindery offer: you are not allowed to modify this offer." ); - _offers[offerId].chainId = chainId; + _; + } + + function setChainIdOffer(bytes32 offerId, uint256 chainId) external isOwner(_offers[offerId]) { + Offer storage offer = _offers[offerId]; + offer.chainId = chainId; emit LogSetChainIdOffer(offerId, chainId); } - function setTokenOffer(bytes32 offerId, address token) external { + function setTokenOffer(bytes32 offerId, address token) external isOwner(_offers[offerId]) { require( msg.sender == _offers[offerId].user, "Grindery offer: you are not allowed to modify this offer." ); - _offers[offerId].token = token; + Offer storage offer = _offers[offerId]; + offer.token = token; emit LogSetTokenOffer(offerId, token); } function setMinPriceLimit( bytes32 offerId, bytes calldata minPriceLimit - ) external { - require( - msg.sender == _offers[offerId].user, - "Grindery offer: you are not allowed to modify this offer." - ); + ) external isOwner(_offers[offerId]) { + Offer storage offer = _offers[offerId]; bytes32 priceLimit = keccak256(abi.encodePacked(minPriceLimit)); - _offers[offerId].minPriceLimit = priceLimit; + offer.minPriceLimit = priceLimit; emit LogSetMinPriceLimit(offerId, priceLimit); } function setMaxPriceLimit( bytes32 offerId, bytes calldata maxPriceLimit - ) external { - require( - msg.sender == _offers[offerId].user, - "Grindery offer: you are not allowed to modify this offer." - ); + ) external isOwner(_offers[offerId]) { + Offer storage offer = _offers[offerId]; bytes32 priceLimit = keccak256(abi.encodePacked(maxPriceLimit)); - _offers[offerId].maxPriceLimit = priceLimit; + offer.maxPriceLimit = priceLimit; emit LogSetMaxPriceLimit(offerId, priceLimit); } - function setIsActive(bytes32 offerId, bool isActive) external { - require( - msg.sender == _offers[offerId].user, - "Grindery offer: you are not allowed to modify this offer." - ); - _offers[offerId].isActive = isActive; + function setIsActive(bytes32 offerId, bool isActive) external isOwner(_offers[offerId]) { + Offer storage offer = _offers[offerId]; + offer.isActive = isActive; emit LogSetStatusOffer(offerId, isActive); } @@ -91,14 +88,15 @@ contract GrtOffer is GrtOfferUtils { bytes32 offerId = keccak256( abi.encodePacked(msg.sender, _noncesOffer[msg.sender]) ); - _offers[offerId].user = msg.sender; - _offers[offerId].isActive = true; - _offers[offerId].chainId = chainId; - _offers[offerId].token = token; - _offers[offerId].minPriceLimit = keccak256( + Offer storage offer = _offers[offerId]; + offer.user = msg.sender; + offer.isActive = true; + offer.chainId = chainId; + offer.token = token; + offer.minPriceLimit = keccak256( abi.encodePacked(minPriceLimit) ); - _offers[offerId].maxPriceLimit = keccak256( + offer.maxPriceLimit = keccak256( abi.encodePacked(maxPriceLimit) ); emit LogNewOffer(offerId, token, chainId); diff --git a/contracts/v-testnet-launch/GrtPool.sol b/contracts/v-testnet-launch/GrtPool.sol index e71eec9..acc53e2 100644 --- a/contracts/v-testnet-launch/GrtPool.sol +++ b/contracts/v-testnet-launch/GrtPool.sol @@ -36,8 +36,6 @@ contract GrtPool is OwnableUpgradeable, GrtOffer, UUPSUpgradeable { function _authorizeUpgrade(address) internal override onlyOwner onlyProxy {} - receive() external payable {} - function depositETHAndAcceptOffer( bytes32 offerId, address destAddr @@ -54,7 +52,6 @@ contract GrtPool is OwnableUpgradeable, GrtOffer, UUPSUpgradeable { _offers[offerId].isActive, "Grindery Pool: the offer is inactive." ); - (bool sent, ) = address(this).call{value: msg.value}(""); require(sent, "Grindery Pool: failed to send native tokens."); bytes32 tradeId = keccak256( @@ -63,7 +60,7 @@ contract GrtPool is OwnableUpgradeable, GrtOffer, UUPSUpgradeable { Trade storage trade = _trades[tradeId]; trade.userAddr = msg.sender; trade.destAddr = destAddr; - trade.deposit = setTokenInfo(address(0), msg.value, block.chainid); + trade.deposit = TokenInfo(address(0), msg.value, block.chainid); trade.offerId = offerId; _noncesDeposit[msg.sender]++; emit LogTrade(tradeId, address(0), msg.value, offerId); @@ -100,11 +97,5 @@ contract GrtPool is OwnableUpgradeable, GrtOffer, UUPSUpgradeable { return _trades[tradeId].deposit.chainId; } - function setTokenInfo( - address token, - uint256 amount, - uint256 chainId - ) internal pure returns (TokenInfo memory) { - return TokenInfo(token, amount, chainId); - } + receive() external payable {} } diff --git a/hardhat.config.ts b/hardhat.config.ts index 7ac7778..3d97acb 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -18,6 +18,7 @@ import "./tasks/v-testnet-launch/deploy-grtPool"; import "./tasks/v-testnet-launch/deploy-grtLiquidityWallet"; import "./tasks/v-testnet-launch/update-grtLiquidityWallet"; import "./tasks/v-testnet-launch/update-grtPool"; +import "hardhat-gas-reporter"; let protocolVersion = "-testnet-launch"; @@ -161,7 +162,14 @@ const config: HardhatUserConfig = { spacing: 2, format: "json", }, - + gasReporter: { + //outputFile: "gas-report.txt", + enabled: process.env.REPORT_GAS !== undefined, + currency: "USD", + noColors: true, + // coinmarketcap: process.env.COIN_MARKETCAP_API_KEY || "", + token: "ETH" + } // deterministicDeployment: () => { // return { // factory: contractAddress, diff --git a/test/v-testnet-launch/GrtOffer.ts b/test/v-testnet-launch/GrtOffer.ts index 125240e..6207337 100644 --- a/test/v-testnet-launch/GrtOffer.ts +++ b/test/v-testnet-launch/GrtOffer.ts @@ -1,7 +1,7 @@ import { expect } from "chai"; import { ethers, upgrades } from "hardhat"; import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; -import { Contract } from "ethers"; +import { Contract, constants } from "ethers"; const protocolVersion = "v-testnet-launch"; @@ -213,9 +213,7 @@ describe("Grindery Offer testings", function () { it("Should fail if the sender is not the creator of the offer", async function () { await expect( grtOffer.connect(user2).setChainIdOffer(offerId, 34) - ).to.be.revertedWith( - "Grindery offer: you are not allowed to modify this offer." - ); + ).to.be.revertedWith("Grindery offer: you are not allowed to modify this offer.") }); it("Should modify the chainID", async function () { @@ -236,9 +234,7 @@ describe("Grindery Offer testings", function () { it("Should fail if the sender is not the creator of the offer", async function () { await expect( grtOffer.connect(user2).setTokenOffer(offerId, token1.address) - ).to.be.revertedWith( - "Grindery offer: you are not allowed to modify this offer." - ); + ).to.be.revertedWith("Grindery offer: you are not allowed to modify this offer.") }); it("Should modify the token address", async function () { @@ -269,9 +265,7 @@ describe("Grindery Offer testings", function () { ["FIRA", "50"] ) ) - ).to.be.revertedWith( - "Grindery offer: you are not allowed to modify this offer." - ); + ).to.be.revertedWith("Grindery offer: you are not allowed to modify this offer.") }); it("Should modify the Min price limit options", async function () { @@ -341,9 +335,7 @@ describe("Grindery Offer testings", function () { ["FIRA", "2000"] ) ) - ).to.be.revertedWith( - "Grindery offer: you are not allowed to modify this offer." - ); + ).to.be.revertedWith("Grindery offer: you are not allowed to modify this offer.") }); it("Should modify the Max price limit options", async function () { @@ -405,9 +397,7 @@ describe("Grindery Offer testings", function () { it("Should fail if the sender is not the creator of the offer", async function () { await expect( grtOffer.connect(user2).setIsActive(offerId, false) - ).to.be.revertedWith( - "Grindery offer: you are not allowed to modify this offer." - ); + ).to.be.revertedWith("Grindery offer: you are not allowed to modify this offer.") }); it("Should modify the status", async function () { diff --git a/test/v-testnet-launch/GrtPool.ts b/test/v-testnet-launch/GrtPool.ts index 6c0c4ce..560ee55 100644 --- a/test/v-testnet-launch/GrtPool.ts +++ b/test/v-testnet-launch/GrtPool.ts @@ -76,9 +76,7 @@ describe("Grindery Offer testings", function () { .depositETHAndAcceptOffer(offerId, user3.address, { value: 0, }) - ).to.be.revertedWith( - "Grindery Pool: transfered amount must be positive." - ); + ).to.be.revertedWith("Grindery Pool: transfered amount must be positive."); }); it("Should fail if the offer is inactive", async function () {