import { Crypto } from '@peculiar/webcrypto' ; ( global as any ) . crypto = new Crypto ( ) ; import * as OracleSdk from '@keydonix/uniswap-oracle-sdk' ; import { PriceEmitter } from './generated/price-emitter' ; import { deployAllTheThings } from './deploy-contract' ; import { createMnemonicRpc } from './rpc-factories' ; import { ethGetBlockByNumber } from './adapters' ; import { resetUniswapAndAccount , setPrice } from './uniswap-helpers' ; async function main ( ) { const gasPrice = 10n ** 9n ; const rpc = await createMnemonicRpc ( 'http://localhost:1237' , gasPrice ) ; const rpcSignerAddress = await rpc . addressProvider ( ) ; const { uniswapExchange , priceEmitter , token0 , token1 } = await deployAllTheThings ( rpc ) ; await resetUniswapAndAccount ( uniswapExchange , token0 , token1 , rpcSignerAddress , 1n , 1n ) ; await uniswapExchange . sync ( ) ; const blockNumber = await rpc . getBlockNumber ( ) ; await setPrice ( uniswapExchange , token0 , token1 , 2n , 1n ) ; await uniswapExchange . sync ( ) ; const proof = await OracleSdk . getProof ( rpc . getStorageAt , rpc . getProof , ethGetBlockByNumber . bind ( undefined , rpc ) , uniswapExchange . address , token0 . address , blockNumber ) ; const events = await priceEmitter . emitPrice ( uniswapExchange . address , token0 . address , 4n , 4n , proof ) ; const contractPrice = ( events . find ( x => x . name === 'Price' ) as PriceEmitter . Price ) . parameters . price ; console . log ( `Contract Price: ${ Number ( contractPrice ) / 2 ** 112 }` ) ; const sdkPrice = await OracleSdk . getPrice ( rpc . getStorageAt , ethGetBlockByNumber . bind ( undefined , rpc ) , uniswapExchange . address , token0 . address , blockNumber ) ; console . log ( `SDK Price: ${ Number ( sdkPrice ) / 2 ** 112 }` ) ; } main ( ) . then ( ( ) => { process . exit ( 0 ) ; } ) . catch ( error => { console . dir ( error , { depth : null } ) ; process . exit ( 1 ) ; } ) ;