orderbuild fixes; tranche table work; ordershapes still broken
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {ethers} from "ethers";
|
||||
import {ethers, FixedNumber} from "ethers";
|
||||
|
||||
const UNISWAPV3_POOL_INIT_CODE_HASH = '0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54'
|
||||
const uniswapV3Addresses = {
|
||||
@@ -26,4 +26,14 @@ export function uniswapV3PoolAddress(chainId, tokenAddrA, tokenAddrB, fee) {
|
||||
return null
|
||||
}
|
||||
return ethers.getCreate2Address(factory, salt, UNISWAPV3_POOL_INIT_CODE_HASH)
|
||||
}
|
||||
|
||||
|
||||
export function uniswapV3AveragePrice(amountIn, amountOut, fee) {
|
||||
if (amountIn === 0n || amountOut === 0n) return null
|
||||
const fmtX18 = {decimals: 18, width: 256, signed: false};
|
||||
let result = FixedNumber.fromValue(amountOut, 0, fmtX18)
|
||||
.div(FixedNumber.fromValue(amountIn, 0, fmtX18)).toUnsafeFloat()
|
||||
result /= (1 - fee / 1_000_000) // adjust for pool fee
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user