-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 824fc7c
Showing
6 changed files
with
4,703 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
INFURA_API_KEY: | ||
INTERVAL: | ||
NETWORK: | ||
FACTORY_ADDRESS: | ||
QUOTER_ADDRESS: | ||
TOKEN_IN_ADDRESS: | ||
TOKEN_OUT_ADDRESS: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
.history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Uniswap Prices Monitor | ||
|
||
This project includes a bot written in Node.js that monitors the prices of a specific pair on Uniswap. | ||
|
||
## Prerequisites | ||
|
||
- Node.js v18.17.0 or greater | ||
|
||
## Installation | ||
|
||
- npm install | ||
|
||
## Enviroment variables | ||
|
||
- Make sure to setup an Infura API Key on: https://www.infura.io/ | ||
- Then finally make sure to fill in the environment variables on the .env file | ||
|
||
Example: | ||
|
||
INFURA_API_KEY: .... // YOUR INFURA API KEY | ||
INTERVAL: 300000 // 5 Minutes | ||
NETWORK: goerli // NETWORK NAME | ||
FACTORY_ADDRESS: // POOL FACTORY CONTRACT ADDRESS - https://docs.uniswap.org/contracts/v3/reference/deployments | ||
QUOTER_ADDRESS: // QUOTE CONTRACT ADDRESS - https://docs.uniswap.org/contracts/v3/reference/deployments | ||
TOKEN_IN_ADDRESS: 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 // WETH | ||
TOKEN_OUT_ADDRESS: 0xdac17f958d2ee523a2206206994597c13d831ec7 // USDT | ||
|
||
## Initialization | ||
|
||
- npm start | ||
|
||
## Disclaimer | ||
|
||
The bot has been inspired by the following article: | ||
|
||
https://www.luiztools.com.br/post/como-monitorar-precos-de-criptomoedas-na-uniswap-v3/ | ||
|
||
Thanks to Luiz Tools! :) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require("dotenv").config(); | ||
|
||
const { INTERVAL, FACTORY_ADDRESS, QUOTER_ADDRESS, TOKEN_IN_ADDRESS, TOKEN_OUT_ADDRESS, NETWORK, INFURA_API_KEY } = process.env; | ||
|
||
const { ChainId, Token } = require("@uniswap/sdk-core"); | ||
const WETH_TOKEN = new Token(ChainId.MAINNET, TOKEN_IN_ADDRESS, 18, 'WETH', 'Wrapped Ether'); | ||
const USDT_TOKEN = new Token(ChainId.MAINNET, TOKEN_OUT_ADDRESS, 6, 'USDT', 'Tether'); | ||
|
||
const { ethers } = require("ethers"); | ||
const provider = new ethers.InfuraProvider(NETWORK, INFURA_API_KEY); | ||
|
||
async function preparationCycle() { | ||
|
||
const { computePoolAddress, FeeAmount } = require("@uniswap/v3-sdk") | ||
const currentPoolAddress = computePoolAddress({ | ||
factoryAddress: FACTORY_ADDRESS, | ||
tokenA: WETH_TOKEN, | ||
tokenB: USDT_TOKEN, | ||
fee: FeeAmount.MEDIUM, | ||
}) | ||
|
||
const IUniswapV3PoolABI = require("@uniswap/v3-core/artifacts/contracts/interfaces/IUniswapV3Pool.sol/IUniswapV3Pool.json"); | ||
const poolContract = new ethers.Contract(currentPoolAddress, IUniswapV3PoolABI.abi, provider); | ||
const result = getTokenOrder(TOKEN_IN_ADDRESS, TOKEN_OUT_ADDRESS); | ||
|
||
result.fee = await poolContract.fee(); | ||
|
||
return result; | ||
} | ||
|
||
|
||
function getTokenOrder(tokenIn, tokenOut) { | ||
if (ethers.toBigInt(tokenIn) <= ethers.toBigInt(tokenOut)) | ||
return { token0: tokenIn, token1: tokenOut }; | ||
else | ||
return { token0: tokenOut, token1: tokenIn }; | ||
} | ||
|
||
|
||
async function executionCycle(token0, token1, fee) { | ||
const Quoter = require("@uniswap/v3-periphery/artifacts/contracts/lens/Quoter.sol/Quoter.json"); | ||
const quoterContract = new ethers.Contract(QUOTER_ADDRESS, Quoter.abi, provider); | ||
const quotedAmountOut = await quoterContract.quoteExactInputSingle.staticCall( | ||
token0, | ||
token1, | ||
fee, | ||
ethers.parseEther("1"), | ||
0 | ||
) | ||
|
||
console.log("WETH 1 is equals to USDT " + ethers.formatUnits(quotedAmountOut, 6)); | ||
} | ||
|
||
(async () => { | ||
console.log("Running"); | ||
const { token0, token1, fee } = await preparationCycle(); | ||
|
||
setInterval(() => executionCycle(token0, token1, fee), INTERVAL); | ||
|
||
executionCycle(token0, token1, fee); | ||
})(); |
Oops, something went wrong.