Skip to content

Commit 3064e9d

Browse files
authored
Merge pull request #8 from kostysh/refactor/remove-zksync
refactor: 💡 Fallback repo from zkSync to Hardhat
2 parents 2043cc6 + dcabf8d commit 3064e9d

25 files changed

+1952
-1174
lines changed

.env.example

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
11
NODE_ENV=test
2-
INFURA_API_KEY=<KEY>
2+
3+
# network specific node uri : `"ETH_NODE_URI_" + networkName.toUpperCase()`
4+
ETH_NODE_URI_MAINNET=https://eth-mainnet.alchemyapi.io/v2/<apiKey>
5+
# generic node uri (if no specific found) :
6+
ETH_NODE_URI=https://{{networkName}}.infura.io/v3/<apiKey>
7+
8+
# network specific mnemonic : `"MNEMONIC_ " + networkName.toUpperCase()`
9+
MNEMONIC_MAINNET=<mnemonic for mainnet>
10+
# generic mnemonic (if no specific found):
11+
MNEMONIC=<mnemonic>
12+
13+
# coinmarketcap api key for gas report
14+
COINMARKETCAP_API_KEY=
15+
16+
# etherscan api key
17+
ETHERSCAN_API_KEY=

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.sol linguist-language=Solidity
2+
*.ts linguist-language=Typescript
3+
* text=auto eol=lf

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ jobs:
2121
- name: Lint
2222
run: yarn lint
2323
- name: Test
24-
run: yarn test:src
24+
run: yarn test:src && yarn test:contracts

.solcover.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
skipFiles: ['test'],
3+
};

contracts/DealsRegistry.sol

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -333,36 +333,39 @@ abstract contract DealsRegistry is
333333
) external {
334334
address buyer = _msgSender();
335335

336-
bytes32 offerHash = _hashTypedDataV4(hash(offer));
337-
Supplier storage supplier = suppliers[offer.supplierId];
338-
339-
// Supplier who created an offer must be registered
340-
if (supplier.signer == address(0)) {
341-
revert InvalidSupplier();
342-
}
336+
/// @dev variable scoping used to avoid stack too deep errors
337+
{
338+
bytes32 offerHash = _hashTypedDataV4(hash(offer));
339+
Supplier storage supplier = suppliers[offer.supplierId];
340+
341+
// Supplier who created an offer must be registered
342+
if (supplier.signer == address(0)) {
343+
revert InvalidSupplier();
344+
}
343345

344-
// Checking ECDSA/AA signature is valid
345-
if (!supplier.signer.isValidSignatureNow(offerHash, signs[0])) {
346-
revert InvalidOfferSignature();
347-
}
346+
// Checking ECDSA/AA signature is valid
347+
if (!supplier.signer.isValidSignatureNow(offerHash, signs[0])) {
348+
revert InvalidOfferSignature();
349+
}
348350

349-
// Not-enabled suppliers are not allowed to accept deals
350-
// So, we cannot allow to create such a deal
351-
if (!supplier.enabled) {
352-
revert DisabledSupplier();
353-
}
351+
// Not-enabled suppliers are not allowed to accept deals
352+
// So, we cannot allow to create such a deal
353+
if (!supplier.enabled) {
354+
revert DisabledSupplier();
355+
}
354356

355-
// Deal can be created only once
356-
if (deals[offer.id].offer.id == offer.id) {
357-
revert DealExists();
358-
}
357+
// Deal can be created only once
358+
if (deals[offer.id].offer.id == offer.id) {
359+
revert DealExists();
360+
}
359361

360-
bytes32 paymentHash = hash(paymentOptions);
362+
bytes32 paymentHash = hash(paymentOptions);
361363

362-
// payment options provided with argument must be the same
363-
// as signed in the offer
364-
if (paymentHash != offer.paymentHash) {
365-
revert InvalidPaymentOptions();
364+
// payment options provided with argument must be the same
365+
// as signed in the offer
366+
if (paymentHash != offer.paymentHash) {
367+
revert InvalidPaymentOptions();
368+
}
366369
}
367370

368371
uint256 price;

contracts/Market.sol

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ contract Market is Ownable, Pausable, DealsRegistry, ERC721Token {
168168
// Prevent transfer of token when this is not allowed by the offer
169169
// or the deal is in the non-transferrable status
170170
if (
171-
!offerDeal.offer.transferable ||
172-
offerDeal.status != DealStatus.Claimed
171+
!offerDeal.offer.transferable || offerDeal.status != DealStatus.Claimed
173172
) {
174173
revert TokenTransferNotAllowed();
175174
}

contracts/utils/SignatureUtils.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ library SignatureUtils {
77
/// @dev Splits signature into v/r/s form
88
function split(
99
bytes memory signature
10-
) public pure returns (uint8 v, bytes32 r, bytes32 s) {
10+
) internal pure returns (uint8 v, bytes32 r, bytes32 s) {
1111
if (signature.length == 65) {
1212
assembly {
1313
r := mload(add(signature, 0x20))

contracts/utils/StringUtils.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ library StringUtils {
55
function equal(
66
string memory s1,
77
string memory s2
8-
) public pure returns (bool) {
8+
) internal pure returns (bool) {
99
return keccak256(abi.encodePacked(s1)) == keccak256(abi.encodePacked(s2));
1010
}
1111
}

coverage.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

deploy/001.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* eslint-disable @typescript-eslint/unbound-method */
2+
import { HardhatRuntimeEnvironment } from 'hardhat/types';
3+
import { DeployFunction } from 'hardhat-deploy/types';
4+
import { eip712name, eip712version, minDeposit } from '../test/contracts/setup';
5+
6+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
7+
const { network, deployments, getNamedAccounts } = hre;
8+
9+
if (!['hardhat', 'localhost'].includes(network.name)) {
10+
return;
11+
}
12+
13+
const { deploy } = deployments;
14+
const { owner } = await getNamedAccounts();
15+
16+
// Simple ERC20 token
17+
const erc20 = await deploy('MockERC20Dec18', {
18+
from: owner,
19+
args: ['STABLE', 'STABLE', owner],
20+
log: true,
21+
autoMine: true,
22+
});
23+
24+
if (erc20.newlyDeployed) {
25+
console.log(
26+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
27+
`MockERC20Dec18 (erc20) was deployed at: ${erc20.address} using ${erc20.receipt?.gasUsed} gas`,
28+
);
29+
}
30+
31+
// ERC20 token with permit
32+
const lif = await deploy('MockERC20Dec18Permit', {
33+
from: owner,
34+
args: ['LIF', 'LIF', owner],
35+
log: true,
36+
autoMine: true,
37+
});
38+
39+
if (lif.newlyDeployed) {
40+
console.log(
41+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
42+
`MockERC20Dec18Permit (lif) was deployed at: ${lif.address} using ${lif.receipt?.gasUsed} gas`,
43+
);
44+
}
45+
46+
// Market
47+
const market = await deploy('Market', {
48+
from: owner,
49+
args: [owner, eip712name, eip712version, lif.address, minDeposit],
50+
log: true,
51+
autoMine: true,
52+
});
53+
54+
if (market.newlyDeployed) {
55+
console.log(
56+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
57+
`Market was deployed at: ${market.address} using ${market.receipt?.gasUsed} gas`,
58+
);
59+
}
60+
};
61+
62+
export default func;
63+
func.tags = ['MockERC20Dec18', 'MockERC20Dec18Permit', 'Market'];

0 commit comments

Comments
 (0)