Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Jun 13, 2023
2 parents 6385d09 + b37fa0a commit df10b8e
Show file tree
Hide file tree
Showing 112 changed files with 3,946 additions and 833 deletions.
7 changes: 7 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.yarn
artifacts
cache
dist
node_modules
pkg
typechain-types
44 changes: 44 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const path = require("path");

const OFF = 0;

/**
* @type {import("eslint").Linter.Config}
*/
module.exports = {
env: {
browser: false,
es2021: true,
mocha: true,
node: true,
},
extends: ["plugin:prettier/recommended"],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 12,
},
plugins: ["@typescript-eslint", "prettier", "simple-import-sort", "sort-keys-fix", "typescript-sort-keys"],
rules: {
"@typescript-eslint/sort-type-union-intersection-members": "error",
camelcase: "off",
"no-console": OFF,
"simple-import-sort/exports": "error",
"simple-import-sort/imports": "error",
"sort-keys-fix/sort-keys-fix": "error",
"typescript-sort-keys/interface": "error",
"typescript-sort-keys/string-enum": "error",
},
settings: {
"import/parsers": {
"@typescript-eslint/parser": [".js", ".jsx", ".ts", ".tsx", ".d.ts"],
},
"import/resolver": {
node: {
extensions: [".js", ".jsx", ".ts", ".tsx", ".d.ts"],
},
typescript: {
project: path.join(__dirname, "tsconfig.json"),
},
},
},
};
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.yarn
artifacts
cache
coverage*
gasReporterOutput.json
node_modules
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"printWidth": 120
}
10 changes: 10 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "solhint:recommended",
"rules": {
"compiler-version": ["error", "0.8.7"],
"func-visibility": ["warn", { "ignoreConstructors": true }],
"reason-string": ["warn", { "maxLength": 80 }],
"no-empty-blocks": "off",
"check-send-result": "off"
}
}
18 changes: 9 additions & 9 deletions contracts/evm/ERC20Custody.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ contract ERC20Custody {

/// @notice If custody operations are paused.
bool public paused;
/// @notice TSSAddress is the TSS address collectively possessed by Zeta blockchain validators.
address public TSSAddress;
/// @notice Threshold Signature Scheme (TSS) [GG20] is a multi-sig ECDSA/EdDSA protocol.
/// @notice TSSAddress is the TSS address collectively possessed by Zeta blockchain validators.
address public TSSAddress;
/// @notice Threshold Signature Scheme (TSS) [GG20] is a multi-sig ECDSA/EdDSA protocol.
address public TSSAddressUpdater;
/// @notice Current zeta fee for depositing funds into ZetaChain.
uint256 public zetaFee;
/// @notice Maximum zeta fee for transaction.
uint256 immutable public zetaMaxFee;
uint256 public immutable zetaMaxFee;
/// @notice Zeta ERC20 token .
IERC20 immutable public zeta;
IERC20 public immutable zeta;
/// @notice Mapping of whitelisted token => true/false.
mapping(IERC20 => bool) public whitelisted;

event Paused(address sender);
event Unpaused(address sender);
event Whitelisted(IERC20 indexed asset);
Expand Down Expand Up @@ -64,8 +64,8 @@ contract ERC20Custody {
_;
}

constructor(address TSSAddress_, address TSSAddressUpdater_, uint256 zetaFee_, uint256 zetaMaxFee_, IERC20 zeta_) {
TSSAddress = TSSAddress_;
constructor(address TSSAddress_, address TSSAddressUpdater_, uint256 zetaFee_, uint256 zetaMaxFee_, IERC20 zeta_) {
TSSAddress = TSSAddress_;
TSSAddressUpdater = TSSAddressUpdater_;
zetaFee = zetaFee_;
zeta = zeta_;
Expand Down Expand Up @@ -173,7 +173,7 @@ contract ERC20Custody {
}
uint256 oldBalance = asset.balanceOf(address(this));
asset.safeTransferFrom(msg.sender, address(this), amount);
// In case if there is a fee on a token transfer, we might not receive a full exepected amount
// In case if there is a fee on a token transfer, we might not receive a full exepected amount
// and we need to correctly process that, o we subtract an old balance from a new balance, which should be an actual received amount.
emit Deposited(recipient, asset, asset.balanceOf(address(this)) - oldBalance, message);
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/evm/Zeta.eth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
* @dev ZetaEth is an implementation of OpenZeppelin's ERC20
*/
contract ZetaEth is ERC20("Zeta", "ZETA") {
constructor(uint256 initialSupply) {
_mint(msg.sender, initialSupply * (10 ** uint256(decimals())));
constructor(address creator, uint256 initialSupply) {
_mint(creator, initialSupply * (10 ** uint256(decimals())));
}
}
34 changes: 12 additions & 22 deletions contracts/evm/testing/TestUniswapV3Contracts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ interface INonfungiblePositionManager {
/// @return feeGrowthInside1LastX128 The fee growth of token1 as of the last action on the individual position
/// @return tokensOwed0 The uncollected amount of token0 owed to the position as of the last computation
/// @return tokensOwed1 The uncollected amount of token1 owed to the position as of the last computation
function positions(uint256 tokenId)
function positions(
uint256 tokenId
)
external
view
returns (
Expand Down Expand Up @@ -82,15 +84,9 @@ interface INonfungiblePositionManager {
/// @return liquidity The amount of liquidity for this position
/// @return amount0 The amount of token0
/// @return amount1 The amount of token1
function mint(MintParams calldata params)
external
payable
returns (
uint256 tokenId,
uint128 liquidity,
uint256 amount0,
uint256 amount1
);
function mint(
MintParams calldata params
) external payable returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);

struct IncreaseLiquidityParams {
uint256 tokenId;
Expand All @@ -111,14 +107,9 @@ interface INonfungiblePositionManager {
/// @return liquidity The new liquidity amount as a result of the increase
/// @return amount0 The amount of token0 to acheive resulting liquidity
/// @return amount1 The amount of token1 to acheive resulting liquidity
function increaseLiquidity(IncreaseLiquidityParams calldata params)
external
payable
returns (
uint128 liquidity,
uint256 amount0,
uint256 amount1
);
function increaseLiquidity(
IncreaseLiquidityParams calldata params
) external payable returns (uint128 liquidity, uint256 amount0, uint256 amount1);

struct DecreaseLiquidityParams {
uint256 tokenId;
Expand All @@ -136,10 +127,9 @@ interface INonfungiblePositionManager {
/// deadline The time by which the transaction must be included to effect the change
/// @return amount0 The amount of token0 accounted to the position's tokens owed
/// @return amount1 The amount of token1 accounted to the position's tokens owed
function decreaseLiquidity(DecreaseLiquidityParams calldata params)
external
payable
returns (uint256 amount0, uint256 amount1);
function decreaseLiquidity(
DecreaseLiquidityParams calldata params
) external payable returns (uint256 amount0, uint256 amount1);

struct CollectParams {
uint256 tokenId;
Expand Down
6 changes: 2 additions & 4 deletions contracts/evm/testing/ZetaInteractorMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
pragma solidity 0.8.7;

import "@openzeppelin/contracts/access/Ownable2Step.sol";
import "../ZetaInteractor.sol";
import "../tools/ZetaInteractor.sol";

contract ZetaInteractorMock is Ownable2Step, ZetaInteractor, ZetaReceiver {
constructor(
address zetaConnectorAddress
) ZetaInteractor(zetaConnectorAddress) {}
constructor(address zetaConnectorAddress) ZetaInteractor(zetaConnectorAddress) {}

function onZetaMessage(
ZetaInterfaces.ZetaMessage calldata zetaMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ contract ImmutableCreate2Factory {
// mapping to track which addresses have already been deployed.
mapping(address => bool) private _deployed;

function safeCreate2Internal(bytes32 salt, bytes memory initializationCode)
internal
returns (address deploymentAddress)
{
function safeCreate2Internal(
bytes32 salt,
bytes memory initializationCode
) internal returns (address deploymentAddress) {
// move the initialization code from calldata to memory.
bytes memory initCode = initializationCode;

Expand Down Expand Up @@ -84,12 +84,10 @@ contract ImmutableCreate2Factory {
* @return Address of the contract that will be created, or the null address
* if a contract already exists at that address.
*/
function safeCreate2(bytes32 salt, bytes memory initializationCode)
public
payable
containsCaller(salt)
returns (address deploymentAddress)
{
function safeCreate2(
bytes32 salt,
bytes memory initializationCode
) public payable containsCaller(salt) returns (address deploymentAddress) {
return safeCreate2Internal(salt, initializationCode);
}

Expand All @@ -107,11 +105,10 @@ contract ImmutableCreate2Factory {
* @return Address of the contract that will be created, or the null address
* if a contract has already been deployed to that address.
*/
function findCreate2Address(bytes32 salt, bytes calldata initCode)
external
view
returns (address deploymentAddress)
{
function findCreate2Address(
bytes32 salt,
bytes calldata initCode
) external view returns (address deploymentAddress) {
// determine the address where the contract will be deployed.
deploymentAddress = address(
uint160( // downcast to match the address type.
Expand Down Expand Up @@ -148,11 +145,10 @@ contract ImmutableCreate2Factory {
* @return Address of the contract that will be created, or the null address
* if a contract has already been deployed to that address.
*/
function findCreate2AddressViaHash(bytes32 salt, bytes32 initCodeHash)
external
view
returns (address deploymentAddress)
{
function findCreate2AddressViaHash(
bytes32 salt,
bytes32 initCodeHash
) external view returns (address deploymentAddress) {
// determine the address where the contract will be deployed.
deploymentAddress = address(
uint160( // downcast to match the address type.
Expand Down Expand Up @@ -203,12 +199,10 @@ contract ImmutableCreate2Factory {
_;
}

function safeCreate2AndTransfer(bytes32 salt, bytes calldata initializationCode)
external
payable
containsCaller(salt)
returns (address deploymentAddress)
{
function safeCreate2AndTransfer(
bytes32 salt,
bytes calldata initializationCode
) external payable containsCaller(salt) returns (address deploymentAddress) {
deploymentAddress = safeCreate2Internal(salt, initializationCode);
Ownable(deploymentAddress).transferOwnership(msg.sender);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ pragma solidity 0.8.7;

import "@openzeppelin/contracts/access/Ownable2Step.sol";

import "./interfaces/ZetaInterfaces.sol";
import "./interfaces/ZetaInteractorErrors.sol";
import "../interfaces/ZetaInterfaces.sol";
import "../interfaces/ZetaInteractorErrors.sol";

abstract contract ZetaInteractor is Ownable2Step, ZetaInteractorErrors {
bytes32 constant ZERO_BYTES = keccak256(new bytes(0));
Expand All @@ -20,29 +20,22 @@ abstract contract ZetaInteractor is Ownable2Step, ZetaInteractorErrors {
*/
mapping(uint256 => bytes) public interactorsByChainId;

modifier isValidMessageCall(
ZetaInterfaces.ZetaMessage calldata zetaMessage
) {
modifier isValidMessageCall(ZetaInterfaces.ZetaMessage calldata zetaMessage) {
_isValidCaller();
if (
keccak256(zetaMessage.zetaTxSenderAddress) !=
keccak256(interactorsByChainId[zetaMessage.sourceChainId])
) revert InvalidZetaMessageCall();
if (keccak256(zetaMessage.zetaTxSenderAddress) != keccak256(interactorsByChainId[zetaMessage.sourceChainId]))
revert InvalidZetaMessageCall();
_;
}

modifier isValidRevertCall(ZetaInterfaces.ZetaRevert calldata zetaRevert) {
_isValidCaller();
if (zetaRevert.zetaTxSenderAddress != address(this))
revert InvalidZetaRevertCall();
if (zetaRevert.sourceChainId != currentChainId)
revert InvalidZetaRevertCall();
if (zetaRevert.zetaTxSenderAddress != address(this)) revert InvalidZetaRevertCall();
if (zetaRevert.sourceChainId != currentChainId) revert InvalidZetaRevertCall();
_;
}

constructor(address zetaConnectorAddress) {
if (zetaConnectorAddress == address(0))
revert ZetaCommonErrors.InvalidAddress();
if (zetaConnectorAddress == address(0)) revert ZetaCommonErrors.InvalidAddress();
currentChainId = block.chainid;
connector = ZetaConnector(zetaConnectorAddress);
}
Expand All @@ -58,10 +51,7 @@ abstract contract ZetaInteractor is Ownable2Step, ZetaInteractorErrors {
return (keccak256(interactorsByChainId[chainId]) != ZERO_BYTES);
}

function setInteractorByChainId(
uint256 destinationChainId,
bytes calldata contractAddress
) external onlyOwner {
function setInteractorByChainId(uint256 destinationChainId, bytes calldata contractAddress) external onlyOwner {
interactorsByChainId[destinationChainId] = contractAddress;
}
}
Loading

0 comments on commit df10b8e

Please sign in to comment.