Merge pull request #105 from TrooperCrypto/master

feat/add ethereumRPC for custom rpc's
This commit is contained in:
Trooper
2023-05-31 21:52:38 +02:00
committed by GitHub
3 changed files with 29 additions and 7 deletions

View File

@@ -44,7 +44,7 @@ node marketmaker.js
## Configuration Via Environment Variables ## Configuration Via Environment Variables
It is __recommended__ to use environment variables to set your private keys. You can set `ETH_PRIVKEY`, `CRYPTOWATCH_API_KEY` and `INFURA` using them. You can set them using `ETH_PRIVKEY=0x____`. For more informations on private keys read [this](https://linuxize.com/post/how-to-set-and-list-environment-variables-in-linux/). It is __recommended__ to use environment variables to set your private keys. You can set `ETH_PRIVKEY`, `CRYPTOWATCH_API_KEY` and `RPC` using them. You can set them using `ETH_PRIVKEY=0x____`. For more informations on private keys read [this](https://linuxize.com/post/how-to-set-and-list-environment-variables-in-linux/).
If your hosting service requires you to pass in configs via environment variables you can compress `config.json`: If your hosting service requires you to pass in configs via environment variables you can compress `config.json`:
@@ -139,10 +139,9 @@ Example:
``` ```
###### Chainlink ###### Chainlink
With chainlink you have access to price oracles via blockchain. The requests are read-calls to a smart contract. The public ethers provider might be too slow for a higher number of pairs or at times of high demand. Therefore, it might be needed to have access to an Infura account (100000 Requests/Day for free). You can get an endpoint for your market maker (like https://mainnet.infura.io/v3/...), You can add this with the `infuraUrl` field in `config.json`, like this: With chainlink you have access to price oracles via blockchain. The requests are read-calls to a smart contract. The public ethers provider might be too slow for a higher number of pairs or at times of high demand. Therefore, it might be needed to have access to an RPC provider account like quicknode, alchemy, ... (some offer free calls). You can get an endpoint for your market maker (like "https://eth.llamarpc.com"), You can add this with the `ethereumRPC` field in `config.json`, like this:
``` ```
"ethereumRPC": "https://eth.llamarpc.com",
"infuraUrl": "https://mainnet.infura.io/v3/xxxxxxxx",
"pairs": { "pairs": {
"ETH-USDC": { "ETH-USDC": {
"zigzagChainId": 1, "zigzagChainId": 1,
@@ -161,9 +160,9 @@ You can get the available market contracts [here.](https://docs.chain.link/docs/
``` ```
###### UniswapV3 ###### UniswapV3
With uniswapV3 you have access to price feed's via blockchain. The requests are read-calls to a smart contract. The public ethers provider might be too slow for a higher number of pairs or at times of high demand. Therefore, it might be needed to have access to an Infura account (100000 Requests/Day for free). You can get an endpoint for your market maker (like https://mainnet.infura.io/v3/...), You can add this with the `infuraUrl` field in `config.json`, like this: With uniswapV3 you have access to price feed's via blockchain. The requests are read-calls to a smart contract. The public ethers provider might be too slow for a higher number of pairs or at times of high demand. Therefore, it might be needed to have access to an RPC provider account like quicknode, alchemy, ... (some offer free calls). You can get an endpoint for your market maker (like "https://eth.llamarpc.com"), You can add this with the `ethereumRPC` field in `config.json`, like this:
``` ```
"infuraUrl": "https://mainnet.infura.io/v3/xxxxxxxx", "ethereumRPC": "https://eth.llamarpc.com",
"pairs": { "pairs": {
"ETH-USDC": { "ETH-USDC": {
"zigzagChainId": 1, "zigzagChainId": 1,

View File

@@ -6,6 +6,7 @@
], ],
"zigzagChainId": 1, "zigzagChainId": 1,
"zigzagWsUrl": "wss://zigzag-exchange.herokuapp.com", "zigzagWsUrl": "wss://zigzag-exchange.herokuapp.com",
"ethereumRPC": "https://eth.llamarpc.com",
"pairs": { "pairs": {
"ETH-USDC": { "ETH-USDC": {
"priceFeedPrimary": "cryptowatch:6631", "priceFeedPrimary": "cryptowatch:6631",

View File

@@ -47,14 +47,36 @@ console.log("ACTIVE PAIRS", activePairs);
const CHAIN_ID = parseInt(MM_CONFIG.zigzagChainId); const CHAIN_ID = parseInt(MM_CONFIG.zigzagChainId);
const ETH_NETWORK = (CHAIN_ID === 1) ? "mainnet" : "goerli"; const ETH_NETWORK = (CHAIN_ID === 1) ? "mainnet" : "goerli";
const infureKey = (process.env.infura || MM_CONFIG.infura); const infureKey = (process.env.infura || MM_CONFIG.infura);
const ethereumRPC = process.env.infuraUrl || process.env.RPC || process.env.ethereumRPC || MM_CONFIG.infuraUrl || MM_CONFIG.RPC || MM_CONFIG.ethereumRPC;
let ethersProvider = null; let ethersProvider = null;
if (infureKey) { if (infureKey) {
ethersProvider = new ethers.providers.InfuraProvider( ethersProvider = new ethers.providers.InfuraProvider(
"mainnet", "mainnet",
infureKey infureKey
); );
} else if (ethereumRPC) {
ethersProvider = new ethers.providers.JsonRpcProvider(ethereumRPC);
} else { } else {
ethersProvider = new ethers.getDefaultProvider("mainnet"); console.error(`
You did not provider an rpc url with "ethereumRPC" inside your config
or with ETHEREUM_RPC in the environment variables.
Please add a custom one. There are some providers with free plans.
Using a public provider, there is no guarantee that it is stable, for a stable market-maker create a custom RPC.`
)
ethersProvider = new ethers.providers.JsonRpcProvider('https://eth.llamarpc.com');
}
const resProvider = await Promise.race([
ethersProvider.ready,
new Promise((_, reject) => {
setTimeout(() => reject(new Error('Request timed out')), 10_000)
})
])
// check if provider is working
if (Number(resProvider.chainId) !== 1) {
throw new Error(`Cant connect provider, use "ethereumRPC" in the config to add an ethereumRPC`)
} }
// Start price feeds // Start price feeds