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",
|
"name": "@tornado/tornado-oracles",
|
||||||
"version": "0.2.2",
|
"version": "0.2.3",
|
||||||
"description": "Gas oracle for Tornado-specific transactions",
|
"description": "Gas oracle for Tornado-specific transactions",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"types": "./lib/index.d.ts",
|
"types": "./lib/index.d.ts",
|
||||||
|
@ -25,13 +25,13 @@ const tornToken: Token = {
|
|||||||
};
|
};
|
||||||
const tornadoTokens = [tornToken, ...filterTokensFromTornadoInstances(instances)];
|
const tornadoTokens = [tornToken, ...filterTokensFromTornadoInstances(instances)];
|
||||||
|
|
||||||
const defaultTokenPrices: TokenPrices = {
|
const defaultTornadoTokenPrices: TokenPrices = {
|
||||||
cdai: '12143621157112',
|
torn: '1689423546359032',
|
||||||
dai: '543174175301531',
|
dai: '598416104472725',
|
||||||
usdc: '543496781058130',
|
cdai: '13384388487019',
|
||||||
usdt: '540358243246849',
|
usdc: '599013776676721',
|
||||||
wbtc: '15944433090979762571',
|
usdt: '599323410893614',
|
||||||
torn: '1683813509941878',
|
wbtc: '15659889148334216720',
|
||||||
};
|
};
|
||||||
|
|
||||||
export class TokenPriceOracle {
|
export class TokenPriceOracle {
|
||||||
@ -47,12 +47,18 @@ export class TokenPriceOracle {
|
|||||||
constructor(
|
constructor(
|
||||||
rpcUrl: string,
|
rpcUrl: string,
|
||||||
private tokens: Token[] = tornadoTokens,
|
private tokens: Token[] = tornadoTokens,
|
||||||
|
private defaultTokenPrices: TokenPrices = defaultTornadoTokenPrices,
|
||||||
) {
|
) {
|
||||||
this.provider = new ethers.providers.JsonRpcProvider(rpcUrl);
|
this.provider = new ethers.providers.JsonRpcProvider(rpcUrl);
|
||||||
this.oracle = getOffchainOracleContract(this.provider);
|
this.oracle = getOffchainOracleContract(this.provider);
|
||||||
this.multiCall = getMultiCallContract(this.provider);
|
this.multiCall = getMultiCallContract(this.provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Instant return default token prices
|
||||||
|
get defaultPrices(): TokenPrices {
|
||||||
|
return this.defaultTokenPrices;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare data for MultiCall contract
|
* Prepare data for MultiCall contract
|
||||||
* @param {Token[]} tokens Tokens array
|
* @param {Token[]} tokens Tokens array
|
||||||
@ -81,7 +87,7 @@ export class TokenPriceOracle {
|
|||||||
for (let i = 0; i < results.length; i++) {
|
for (let i = 0; i < results.length; i++) {
|
||||||
const tokenSymbol = tokens[i].symbol.toLowerCase() as TokenSymbol;
|
const tokenSymbol = tokens[i].symbol.toLowerCase() as TokenSymbol;
|
||||||
if (!success[i]) {
|
if (!success[i]) {
|
||||||
if (defaultTokenPrices[tokenSymbol]) prices[tokenSymbol] = defaultTokenPrices[tokenSymbol];
|
if (this.defaultTokenPrices[tokenSymbol]) prices[tokenSymbol] = this.defaultTokenPrices[tokenSymbol];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +100,7 @@ export class TokenPriceOracle {
|
|||||||
return prices;
|
return prices;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Cannot get token prices, return default: ' + e);
|
console.error('Cannot get token prices, return default: ' + e);
|
||||||
return defaultTokenPrices;
|
return this.defaultTokenPrices;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user