Add getter to TokenPriceOracle for default token prices & bump version to 0.2.3
This commit is contained in:
parent
f5244ae722
commit
c63e6a320f
@ -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",
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user