From c63e6a320f605c323bdb6cc482fa5e0cdd2b8928 Mon Sep 17 00:00:00 2001 From: Theo Date: Sun, 20 Aug 2023 11:49:12 -0700 Subject: [PATCH] Add getter to TokenPriceOracle for default token prices & bump version to 0.2.3 --- package.json | 2 +- src/tokenPriceOracle.ts | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 4b4425e..c2e8427 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tornado/tornado-oracles", - "version": "0.2.2", + "version": "0.2.3", "description": "Gas oracle for Tornado-specific transactions", "main": "./lib/index.js", "types": "./lib/index.d.ts", diff --git a/src/tokenPriceOracle.ts b/src/tokenPriceOracle.ts index e1257a3..0906b7f 100644 --- a/src/tokenPriceOracle.ts +++ b/src/tokenPriceOracle.ts @@ -25,13 +25,13 @@ const tornToken: Token = { }; const tornadoTokens = [tornToken, ...filterTokensFromTornadoInstances(instances)]; -const defaultTokenPrices: TokenPrices = { - cdai: '12143621157112', - dai: '543174175301531', - usdc: '543496781058130', - usdt: '540358243246849', - wbtc: '15944433090979762571', - torn: '1683813509941878', +const defaultTornadoTokenPrices: TokenPrices = { + torn: '1689423546359032', + dai: '598416104472725', + cdai: '13384388487019', + usdc: '599013776676721', + usdt: '599323410893614', + wbtc: '15659889148334216720', }; export class TokenPriceOracle { @@ -47,12 +47,18 @@ export class TokenPriceOracle { constructor( rpcUrl: string, private tokens: Token[] = tornadoTokens, + private defaultTokenPrices: TokenPrices = defaultTornadoTokenPrices, ) { this.provider = new ethers.providers.JsonRpcProvider(rpcUrl); this.oracle = getOffchainOracleContract(this.provider); this.multiCall = getMultiCallContract(this.provider); } + // Instant return default token prices + get defaultPrices(): TokenPrices { + return this.defaultTokenPrices; + } + /** * Prepare data for MultiCall contract * @param {Token[]} tokens Tokens array @@ -81,7 +87,7 @@ export class TokenPriceOracle { for (let i = 0; i < results.length; i++) { const tokenSymbol = tokens[i].symbol.toLowerCase() as TokenSymbol; if (!success[i]) { - if (defaultTokenPrices[tokenSymbol]) prices[tokenSymbol] = defaultTokenPrices[tokenSymbol]; + if (this.defaultTokenPrices[tokenSymbol]) prices[tokenSymbol] = this.defaultTokenPrices[tokenSymbol]; continue; } @@ -94,7 +100,7 @@ export class TokenPriceOracle { return prices; } catch (e) { console.error('Cannot get token prices, return default: ' + e); - return defaultTokenPrices; + return this.defaultTokenPrices; } } }