-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
0ca0dd9
commit 30728d6
Showing
30 changed files
with
1,397 additions
and
1,067 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
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
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
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
2 changes: 1 addition & 1 deletion
2
...n/ssv/src/interfaces/ExchangeRateInput.ts → common/ssv/src/interfaces/PriceInput.ts
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
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
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 |
---|---|---|
@@ -1,17 +1,17 @@ | ||
import { ethers } from 'ethers' | ||
import { ExchangeRateInput } from '../interfaces/ExchangeRateInput' | ||
import { PriceInput } from '../interfaces/PriceInput' | ||
import IUniswapV3FactoryJson from '@casimir/ethereum/build/artifacts/@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol/IUniswapV3Factory.json' | ||
import IUniswapV3PoolStateJson from '@casimir/ethereum/build/artifacts/@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolState.sol/IUniswapV3PoolState.json' | ||
import { IUniswapV3Factory, IUniswapV3PoolState } from '@casimir/ethereum/build/artifacts/types' | ||
|
||
const uniswapV3FactoryAddress = '0x1F98431c8aD98523631AE4a59f267346ea31F984' | ||
|
||
export async function getExchangeRate(input: ExchangeRateInput) { | ||
export async function getPrice(input: PriceInput) { | ||
const { provider, tokenIn, tokenOut, uniswapFeeTier } = input | ||
const uniswapV3FactoryContract = new ethers.Contract(uniswapV3FactoryAddress, IUniswapV3FactoryJson.abi, provider) as IUniswapV3Factory & ethers.Contract | ||
const poolAddress = await uniswapV3FactoryContract.getPool(tokenIn, tokenOut, uniswapFeeTier) | ||
const poolContract = new ethers.Contract(poolAddress, IUniswapV3PoolStateJson.abi, provider) as IUniswapV3PoolState & ethers.Contract | ||
const slot0 = await poolContract.slot0() | ||
const tick = slot0.tick // price (tick) = 1.0001 ^ tick | ||
return Math.pow(1.0001, tick) | ||
const tick = slot0.tick | ||
return 1.0001 ** tick | ||
} |
Oops, something went wrong.