Skip to content
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
17 changes: 16 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
NODE_ENV=test
INFURA_API_KEY=<KEY>

# network specific node uri : `"ETH_NODE_URI_" + networkName.toUpperCase()`
ETH_NODE_URI_MAINNET=https://eth-mainnet.alchemyapi.io/v2/<apiKey>
# generic node uri (if no specific found) :
ETH_NODE_URI=https://{{networkName}}.infura.io/v3/<apiKey>

# network specific mnemonic : `"MNEMONIC_ " + networkName.toUpperCase()`
MNEMONIC_MAINNET=<mnemonic for mainnet>
# generic mnemonic (if no specific found):
MNEMONIC=<mnemonic>

# coinmarketcap api key for gas report
COINMARKETCAP_API_KEY=

# etherscan api key
ETHERSCAN_API_KEY=
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.sol linguist-language=Solidity
*.ts linguist-language=Typescript
* text=auto eol=lf
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
- name: Lint
run: yarn lint
- name: Test
run: yarn test:src
run: yarn test:src && yarn test:contracts
3 changes: 3 additions & 0 deletions .solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
skipFiles: ['test'],
};
53 changes: 28 additions & 25 deletions contracts/DealsRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -333,36 +333,39 @@ abstract contract DealsRegistry is
) external {
address buyer = _msgSender();

bytes32 offerHash = _hashTypedDataV4(hash(offer));
Supplier storage supplier = suppliers[offer.supplierId];

// Supplier who created an offer must be registered
if (supplier.signer == address(0)) {
revert InvalidSupplier();
}
/// @dev variable scoping used to avoid stack too deep errors
{
bytes32 offerHash = _hashTypedDataV4(hash(offer));
Supplier storage supplier = suppliers[offer.supplierId];

// Supplier who created an offer must be registered
if (supplier.signer == address(0)) {
revert InvalidSupplier();
}

// Checking ECDSA/AA signature is valid
if (!supplier.signer.isValidSignatureNow(offerHash, signs[0])) {
revert InvalidOfferSignature();
}
// Checking ECDSA/AA signature is valid
if (!supplier.signer.isValidSignatureNow(offerHash, signs[0])) {
revert InvalidOfferSignature();
}

// Not-enabled suppliers are not allowed to accept deals
// So, we cannot allow to create such a deal
if (!supplier.enabled) {
revert DisabledSupplier();
}
// Not-enabled suppliers are not allowed to accept deals
// So, we cannot allow to create such a deal
if (!supplier.enabled) {
revert DisabledSupplier();
}

// Deal can be created only once
if (deals[offer.id].offer.id == offer.id) {
revert DealExists();
}
// Deal can be created only once
if (deals[offer.id].offer.id == offer.id) {
revert DealExists();
}

bytes32 paymentHash = hash(paymentOptions);
bytes32 paymentHash = hash(paymentOptions);

// payment options provided with argument must be the same
// as signed in the offer
if (paymentHash != offer.paymentHash) {
revert InvalidPaymentOptions();
// payment options provided with argument must be the same
// as signed in the offer
if (paymentHash != offer.paymentHash) {
revert InvalidPaymentOptions();
}
}

uint256 price;
Expand Down
3 changes: 1 addition & 2 deletions contracts/Market.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ contract Market is Ownable, Pausable, DealsRegistry, ERC721Token {
// Prevent transfer of token when this is not allowed by the offer
// or the deal is in the non-transferrable status
if (
!offerDeal.offer.transferable ||
offerDeal.status != DealStatus.Claimed
!offerDeal.offer.transferable || offerDeal.status != DealStatus.Claimed
) {
revert TokenTransferNotAllowed();
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/utils/SignatureUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ library SignatureUtils {
/// @dev Splits signature into v/r/s form
function split(
bytes memory signature
) public pure returns (uint8 v, bytes32 r, bytes32 s) {
) internal pure returns (uint8 v, bytes32 r, bytes32 s) {
if (signature.length == 65) {
assembly {
r := mload(add(signature, 0x20))
Expand Down
2 changes: 1 addition & 1 deletion contracts/utils/StringUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ library StringUtils {
function equal(
string memory s1,
string memory s2
) public pure returns (bool) {
) internal pure returns (bool) {
return keccak256(abi.encodePacked(s1)) == keccak256(abi.encodePacked(s2));
}
}
1 change: 1 addition & 0 deletions coverage.json

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions deploy/001.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* eslint-disable @typescript-eslint/unbound-method */
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';
import { eip712name, eip712version, minDeposit } from '../test/contracts/setup';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { network, deployments, getNamedAccounts } = hre;

if (!['hardhat', 'localhost'].includes(network.name)) {
return;
}

const { deploy } = deployments;
const { owner } = await getNamedAccounts();

// Simple ERC20 token
const erc20 = await deploy('MockERC20Dec18', {
from: owner,
args: ['STABLE', 'STABLE', owner],
log: true,
autoMine: true,
});

if (erc20.newlyDeployed) {
console.log(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
`MockERC20Dec18 (erc20) was deployed at: ${erc20.address} using ${erc20.receipt?.gasUsed} gas`,
);
}

// ERC20 token with permit
const lif = await deploy('MockERC20Dec18Permit', {
from: owner,
args: ['LIF', 'LIF', owner],
log: true,
autoMine: true,
});

if (lif.newlyDeployed) {
console.log(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
`MockERC20Dec18Permit (lif) was deployed at: ${lif.address} using ${lif.receipt?.gasUsed} gas`,
);
}

// Market
const market = await deploy('Market', {
from: owner,
args: [owner, eip712name, eip712version, lif.address, minDeposit],
log: true,
autoMine: true,
});

if (market.newlyDeployed) {
console.log(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
`Market was deployed at: ${market.address} using ${market.receipt?.gasUsed} gas`,
);
}
};

export default func;
func.tags = ['MockERC20Dec18', 'MockERC20Dec18Permit', 'Market'];
90 changes: 59 additions & 31 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,76 @@
import 'dotenv/config';
import { HardhatUserConfig } from 'hardhat/config.js';
import '@matterlabs/hardhat-zksync-toolbox';
import { HardhatUserConfig } from 'hardhat/types';
import '@nomiclabs/hardhat-ethers';
import '@nomiclabs/hardhat-solhint';
import '@nomicfoundation/hardhat-chai-matchers';
import '@openzeppelin/hardhat-upgrades';
import '@nomiclabs/hardhat-etherscan';
import '@typechain/hardhat';
import 'hardhat-deploy';
import 'hardhat-deploy-ethers';
import 'hardhat-gas-reporter';
import 'solidity-coverage';
import './tasks';

const zkSyncTestnet =
process.env.NODE_ENV === 'test'
? {
url: 'http://localhost:3050',
ethNetwork: 'http://localhost:8545',
zksync: true,
}
: {
url: 'https://zksync2-testnet.zksync.dev',
ethNetwork: 'goerli',
zksync: true,
};
import { nodeUrl, accounts, addForkConfiguration } from './utils/network';

const config: HardhatUserConfig = {
zksolc: {
version: '1.3.8',
compilerSource: 'binary',
settings: {
isSystem: true,
},
solidity: {
compilers: [
{
version: '0.8.19',
settings: {
optimizer: {
enabled: true,
runs: 2000,
},
},
},
],
},
namedAccounts: {
owner: 0,
notOwner: 1,
buyer: 2,
supplierOwner: 3,
supplierSigner: 4,
},
defaultNetwork: 'hardhat',
networks: {
networks: addForkConfiguration({
hardhat: {
zksync: true,
initialBaseFeePerGas: 0,
allowUnlimitedContractSize: true,
},
goerli: {
url: `https://goerli.infura.io/v3/${process.env.INFURA_API_KEY ?? ''}`,
zksync: false,
localhost: {
url: nodeUrl('localhost'),
accounts: accounts(),
},
zkSyncTestnet,
},
solidity: {
version: '0.8.19',
}),
gasReporter: {
currency: 'USD',
gasPrice: 100,
enabled: process.env.REPORT_GAS ? true : false,
coinmarketcap: process.env.COINMARKETCAP_API_KEY,
maxMethodDiff: 10,
},
typechain: {
outDir: 'typechain',
target: 'ethers-v5',
},
mocha: {
timeout: 0,
},
external: process.env.HARDHAT_FORK
? {
deployments: {
hardhat: ['deployments/' + process.env.HARDHAT_FORK],
localhost: ['deployments/' + process.env.HARDHAT_FORK],
},
}
: undefined,
verify: {
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY,
},
},
};

export default config;
5 changes: 0 additions & 5 deletions network/clear.sh

This file was deleted.

47 changes: 0 additions & 47 deletions network/docker-compose.yml

This file was deleted.

42 changes: 0 additions & 42 deletions network/rich-wallets.json

This file was deleted.

Loading