Skip to content

Commit

Permalink
Create ZetaTokenConsumer (#22)
Browse files Browse the repository at this point in the history
* Standardize underscore

* Add ZetaGasPayer base

* Add uniswap contracts

* Small tweaks

* ZetaGasPayer -> ZetaTokenConsumer

* Tests and improvements

* WIP: UniV3

* add UniV3 strategy

* update contracts and test

* secure updateStrategy and add events

* add zero validations

* update comments

* import uniswap v3 contracts

* remove fallback

* Naming, syntax

* Remove fallback & payable

* Update packages/protocol-contracts/contracts/ZetaTokenConsumerRecommended.strategy.sol

* Details

* zetaTokenInput_ -> zetaToken_

* Add receive function

* Copy

* add test for events

* move addresses to json file

* update ZetaTokenConsumerUniV3

* remove old comment

* Install order keys plugins

* Rename

* Delete recommended strategy

* tokenPoolFee

* Blankline

Co-authored-by: Lucas Janon <[email protected]>
  • Loading branch information
andresaiello and lucas-janon authored Jun 28, 2022
1 parent 8822455 commit c3aa49b
Show file tree
Hide file tree
Showing 39 changed files with 1,361 additions and 173 deletions.
18 changes: 11 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ module.exports = {
mocha: true,
node: true,
},
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint", "simple-import-sort", "prettier"],
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",
"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"],
Expand All @@ -29,9 +38,4 @@ module.exports = {
},
},
},
rules: {
camelcase: "off",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
},
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-simple-import-sort": "7.0.0",
"eslint-plugin-sort-keys-fix": "1.1.2",
"eslint-plugin-typescript-sort-keys": "2.1.0",
"ethereum-waffle": "^3.4.4",
"ethereumjs-utils": "^5.2.5",
"ethers": "5.6.8",
Expand Down
46 changes: 29 additions & 17 deletions packages/addresses/src/addresses.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,37 @@ export type ZetaAddress =
| "connector"
| "crossChainCounter"
| "crossChainNft"
| "dai"
| "multiChainSwap"
| "multiChainSwapZetaConnector"
| "multiChainValue"
| "tss"
| "tssUpdater"
| "uniswapV2Router02"
| "uniswapV3NftManager"
| "uniswapV3Quoter"
| "uniswapV3Router"
| "usdc"
| "weth9"
| "zetaToken";

type NetworkAddresses = Record<ZetaAddress, string>;
const zetaAddresses: Record<ZetaAddress, boolean> = {
connector: true,
crossChainCounter: true,
crossChainNft: true,
dai: true,
multiChainSwap: true,
multiChainSwapZetaConnector: true,
multiChainValue: true,
tss: true,
tssUpdater: true,
uniswapV2Router02: true,
uniswapV3NftManager: true,
uniswapV3Quoter: true,
uniswapV3Router: true,
usdc: true,
weth9: true,
zetaToken: true,
};

Expand All @@ -37,7 +49,7 @@ export const isZetaAddress = (a: string | undefined): a is ZetaAddress => Boolea
* @description Localnet
*/

export type LocalNetworkName = "hardhat" | "eth-localnet" | "bsc-localnet" | "polygon-localnet";
export type LocalNetworkName = "bsc-localnet" | "eth-localnet" | "hardhat" | "polygon-localnet";
export type ZetaLocalNetworkName = "troy";
type LocalnetAddressGroup = Record<LocalNetworkName, NetworkAddresses>;
export const isLocalNetworkName = (networkName: string): networkName is LocalNetworkName =>
Expand Down Expand Up @@ -92,20 +104,20 @@ const getMainnetList: () => Record<ZetaMainnetNetworkName, MainnetAddressGroup>
* @description Shared
*/

export type NetworkName = LocalNetworkName | TestnetNetworkName | MainnetNetworkName;
export type ZetaNetworkName = ZetaLocalNetworkName | ZetaTestnetNetworkName | ZetaMainnetNetworkName;
export type NetworkName = LocalNetworkName | MainnetNetworkName | TestnetNetworkName;
export type ZetaNetworkName = ZetaLocalNetworkName | ZetaMainnetNetworkName | ZetaTestnetNetworkName;

export const getChainId = (networkName: NetworkName) => {
const chainIds: Record<NetworkName, number> = {
"bsc-localnet": 97,
"bsc-testnet": 97,
"eth-localnet": 5,
"eth-mainnet": 1,
"polygon-mumbai": 80001,
goerli: 5,
ropsten: 3,
hardhat: 1337,
"eth-localnet": 5,
"bsc-localnet": 97,
"polygon-localnet": 80001,
"polygon-mumbai": 80001,
ropsten: 3,
};

return chainIds[networkName];
Expand All @@ -123,15 +135,15 @@ export const getScanVariable = ({ customNetworkName }: { customNetworkName?: str
dotenv.config();

const v = {
"bsc-localnet": "",
"bsc-testnet": process.env.BSCSCAN_API_KEY || "",
"eth-localnet": "",
"eth-mainnet": process.env.ETHERSCAN_API_KEY || "",
"polygon-mumbai": process.env.POLYGONSCAN_API_KEY || "",
goerli: process.env.ETHERSCAN_API_KEY || "",
ropsten: process.env.ETHERSCAN_API_KEY || "",
hardhat: "",
"eth-localnet": "",
"bsc-localnet": "",
"polygon-localnet": "",
"polygon-mumbai": process.env.POLYGONSCAN_API_KEY || "",
ropsten: process.env.ETHERSCAN_API_KEY || "",
};

return v[networkName];
Expand All @@ -143,15 +155,15 @@ export const getExplorerUrl = ({ customNetworkName }: { customNetworkName?: stri
dotenv.config();

const v = {
"bsc-localnet": "",
"bsc-testnet": "https://testnet.bscscan.com/",
"eth-localnet": "",
"eth-mainnet": "https://etherscan.io/",
"polygon-mumbai": "https://mumbai.polygonscan.com/",
goerli: "https://goerli.etherscan.io/",
ropsten: "https://ropsten.etherscan.io/",
hardhat: "",
"eth-localnet": "",
"bsc-localnet": "",
"polygon-localnet": "",
"polygon-mumbai": "https://mumbai.polygonscan.com/",
ropsten: "https://ropsten.etherscan.io/",
};

return v[networkName];
Expand Down Expand Up @@ -317,9 +329,9 @@ export const addNewNetwork = (newNetworkName: string, addTo: ZetaNetworkName[])
const orderedFileNetworks = Object.keys(fileNetworks)
.sort()
.reduce((obj, key) => {
obj[key as MainnetNetworkName | TestnetNetworkName | LocalNetworkName] = fileNetworks[key];
obj[key as LocalNetworkName | MainnetNetworkName | TestnetNetworkName] = fileNetworks[key];
return obj;
}, {} as MainnetAddressGroup & TestnetAddressGroup & LocalnetAddressGroup);
}, {} as LocalnetAddressGroup & MainnetAddressGroup & TestnetAddressGroup);

writeFileSync(addressesFilePath, JSON.stringify(orderedFileNetworks, null, 2));
});
Expand Down
34 changes: 29 additions & 5 deletions packages/addresses/src/addresses/addresses.athens.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,66 @@
"connector": "0x202aed942eb71203741eced2913a29C695a7c7F6",
"crossChainCounter": "",
"crossChainNft": "0xa9016FB99846314E0f96f657E5271cFD7919a244",
"dai": "",
"multiChainSwap": "0xD4fAa6BAbBb97E0BDF755D396af48CB66eBa736c",
"multiChainValue": "0x8f56b3e5b0D4bC33E7E52eC55271e73ece6024c6",
"tss": "0x61141bce5352fc9b5ff648468676e356518d86ab",
"tssUpdater": "0x7274d1d5dddef36aac53dd45b93487ce01ef0a55",
"uniswapV2Router02": "0x9Ac64Cc6e4415144C455BD8E4837Fea55603e5c3",
"zetaToken": "0xad7d0795ffdf21f20c89240D540487B1445c7D03",
"multiChainSwap": "0xD4fAa6BAbBb97E0BDF755D396af48CB66eBa736c"
"uniswapV3NftManager": "",
"uniswapV3Quoter": "",
"uniswapV3Router": "",
"usdc": "",
"weth9": "",
"zetaToken": "0xad7d0795ffdf21f20c89240D540487B1445c7D03"
},
"goerli": {
"connector": "0x0B16Fc7e2D627d82255ba21e53Cf6c11B5186046",
"crossChainCounter": "",
"crossChainNft": "0xe08f1d23a68231543a595391D82c39BbaFc22470",
"dai": "",
"multiChainSwap": "0xDB6D960642ea523549Ad108F495c89cfE5E51668",
"multiChainValue": "0x0EaA929a2874183e2324Bb2745F812c942b00F60",
"tss": "0x61141bce5352fc9b5ff648468676e356518d86ab",
"tssUpdater": "0x7274d1d5dddef36aac53dd45b93487ce01ef0a55",
"uniswapV2Router02": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
"zetaToken": "0x011a76081989aDA18d0a16bf3fee2C6c3BD07B07",
"multiChainSwap": "0xDB6D960642ea523549Ad108F495c89cfE5E51668"
"uniswapV3NftManager": "",
"uniswapV3Quoter": "",
"uniswapV3Router": "",
"usdc": "",
"weth9": "",
"zetaToken": "0x011a76081989aDA18d0a16bf3fee2C6c3BD07B07"
},
"polygon-mumbai": {
"connector": "0xa5467B39Ad9f51DEb6b30Abfa9828531dCBA99A9",
"crossChainCounter": "",
"crossChainNft": "",
"dai": "",
"multiChainValue": "0xb3021F5603291895b0Df5fC6276cda33a0B90fa6",
"tss": "0x61141bce5352fc9b5ff648468676e356518d86ab",
"tssUpdater": "0x7274d1d5dddef36aac53dd45b93487ce01ef0a55",
"uniswapV2Router02": "",
"uniswapV3NftManager": "",
"uniswapV3Quoter": "",
"uniswapV3Router": "",
"usdc": "",
"weth9": "",
"zetaToken": "0x84383be9B3Eda50ABD5899936D4963505d449de2"
},
"ropsten": {
"connector": "0x91Ea4f79D39DA890B03E965111953d0494936072",
"crossChainCounter": "",
"crossChainNft": "",
"dai": "",
"multiChainValue": "0x4740f4051eA6D896C694303228D86Ba3141065ca",
"tss": "0x61141Bce5352fC9b5Ff648468676e356518D86AB",
"tssUpdater": "0x7274d1d5dddef36aac53dd45b93487ce01ef0a55",
"uniswapV2Router02": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
"uniswapV3NftManager": "",
"uniswapV3Quoter": "",
"uniswapV3Router": "",
"usdc": "",
"weth9": "",
"zetaToken": "0x3357A3bd90A001282bA2152D6c0a2372c8E0e28E"
}
}
}
8 changes: 7 additions & 1 deletion packages/addresses/src/addresses/addresses.mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
"connector": "",
"crossChainCounter": "",
"crossChainNft": "",
"dai": "0x6b175474e89094c44da98b954eedeac495271d0f",
"multiChainValue": "",
"tss": "",
"tssUpdater": "",
"uniswapV2Router02": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
"uniswapV3NftManager": "0xC36442b4a4522E871399CD717aBDD847Ab11FE88",
"uniswapV3Quoter": "0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6",
"uniswapV3Router": "0xE592427A0AEce92De3Edee1F18E0157C05861564",
"usdc": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"weth9": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"zetaToken": ""
}
}
}
30 changes: 27 additions & 3 deletions packages/addresses/src/addresses/addresses.troy.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,65 @@
"connector": "0xB06c856C8eaBd1d8321b687E188204C1018BC4E5",
"crossChainCounter": "",
"crossChainNft": "",
"dai": "",
"multiChainSwap": "0xddE78e6202518FF4936b5302cC2891ec180E8bFf",
"multiChainValue": "",
"tss": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
"tssUpdater": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
"uniswapV2Router02": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
"zetaToken": "0xddE78e6202518FF4936b5302cC2891ec180E8bFf",
"multiChainSwap": "0xddE78e6202518FF4936b5302cC2891ec180E8bFf"
"uniswapV3NftManager": "",
"uniswapV3Quoter": "",
"uniswapV3Router": "",
"usdc": "",
"weth9": "",
"zetaToken": "0xddE78e6202518FF4936b5302cC2891ec180E8bFf"
},
"eth-localnet": {
"connector": "0xD7db1F9D0279876a9dcDb92e06057E0818b9B34b",
"crossChainCounter": "",
"crossChainNft": "",
"dai": "",
"multiChainValue": "",
"tss": "0x8C001e2204000D8ED10cAcf0F68106b68e036A26",
"tssUpdater": "0xfBec4048e09749515110c89D881EcDcA4460D377",
"uniswapV2Router02": "",
"uniswapV3NftManager": "",
"uniswapV3Quoter": "",
"uniswapV3Router": "",
"usdc": "",
"weth9": "",
"zetaToken": "0xaEF27C0E302005dB3b442edF762EB070Dc2DB9b5"
},
"bsc-localnet": {
"connector": "0x960bd6A9d8424455953a68c17Be7f56e0cf83A9E",
"crossChainCounter": "",
"crossChainNft": "",
"dai": "",
"multiChainValue": "",
"tss": "0x8C001e2204000D8ED10cAcf0F68106b68e036A26",
"tssUpdater": "0x12Dc2227AA4b98b00Ff8148fDA9Ef750929B0F68",
"uniswapV2Router02": "",
"uniswapV3NftManager": "",
"uniswapV3Quoter": "",
"uniswapV3Router": "",
"usdc": "",
"weth9": "",
"zetaToken": "0x0CF6e5aA211A4b7da5d04e93dC40Ee18202a5f84"
},
"polygon-localnet": {
"connector": "0xa16BD8468d10d28E6c16F03798EEb710fc84F616",
"crossChainCounter": "",
"crossChainNft": "",
"dai": "",
"multiChainValue": "",
"tss": "0x8C001e2204000D8ED10cAcf0F68106b68e036A26",
"tssUpdater": "0x78C18E214174A08Fc32e174fb203Aba05B016789",
"uniswapV2Router02": "",
"uniswapV3NftManager": "",
"uniswapV3Quoter": "",
"uniswapV3Router": "",
"usdc": "",
"weth9": "",
"zetaToken": "0xD443E93f689a7E1d517Fef799b1d2Fd2FA536d3A"
}
}
}
Loading

0 comments on commit c3aa49b

Please sign in to comment.