Minor updates #1
44
dist/index.js
vendored
44
dist/index.js
vendored
@ -1664,7 +1664,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0xd90e2f925DA726b50C4Ed8D0Fb90Ad053324F31b",
|
||||
echoContract: "0x9B27DD5Bb15d42DC224FCD0B7caEbBe16161Df42",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
tornContract: "0x77777FeDdddFfC19Ff86DB637967013e6C6A116C",
|
||||
governanceContract: "0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce",
|
||||
stakingRewardsContract: "0x5B3f656C80E8ddb9ec01Dd9018815576E9238c29",
|
||||
@ -1778,7 +1778,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x0D5550d52428E7e3175bfc9550207e4ad3859b17",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
tornadoSubgraph: "tornadocash/bsc-tornado-subgraph",
|
||||
subgraphs: {},
|
||||
rpcUrls: {
|
||||
@ -1841,7 +1841,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x0D5550d52428E7e3175bfc9550207e4ad3859b17",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
tornadoSubgraph: "tornadocash/matic-tornado-subgraph",
|
||||
subgraphs: {},
|
||||
rpcUrls: {
|
||||
@ -1892,7 +1892,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x0D5550d52428E7e3175bfc9550207e4ad3859b17",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
ovmGasPriceOracleContract: "0x420000000000000000000000000000000000000F",
|
||||
tornadoSubgraph: "tornadocash/optimism-tornado-subgraph",
|
||||
subgraphs: {},
|
||||
@ -1944,7 +1944,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x0D5550d52428E7e3175bfc9550207e4ad3859b17",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
tornadoSubgraph: "tornadocash/arbitrum-tornado-subgraph",
|
||||
subgraphs: {},
|
||||
rpcUrls: {
|
||||
@ -1999,7 +1999,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x0D5550d52428E7e3175bfc9550207e4ad3859b17",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
tornadoSubgraph: "tornadocash/xdai-tornado-subgraph",
|
||||
subgraphs: {},
|
||||
rpcUrls: {
|
||||
@ -2050,7 +2050,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x0D5550d52428E7e3175bfc9550207e4ad3859b17",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
tornadoSubgraph: "tornadocash/avalanche-tornado-subgraph",
|
||||
subgraphs: {},
|
||||
rpcUrls: {
|
||||
@ -2100,6 +2100,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x1572AFE6949fdF51Cb3E0856216670ae9Ee160Ee",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x1f89EAF03E5b260Bc6D4Ae3c3334b1B750F3e127",
|
||||
tornContract: "0x3AE6667167C0f44394106E197904519D808323cA",
|
||||
governanceContract: "0xe5324cD7602eeb387418e594B87aCADee08aeCAD",
|
||||
stakingRewardsContract: "0x6d0018890751Efd31feb8166711B16732E2b496b",
|
||||
@ -10300,16 +10301,19 @@ class TokenPriceOracle {
|
||||
oracle;
|
||||
multicall;
|
||||
provider;
|
||||
fallbackPrice;
|
||||
constructor(provider, multicall2, oracle) {
|
||||
this.provider = provider;
|
||||
this.multicall = multicall2;
|
||||
this.oracle = oracle;
|
||||
this.fallbackPrice = ethers.parseEther("0.0001");
|
||||
}
|
||||
buildCalls(tokens) {
|
||||
return tokens.map(({ tokenAddress }) => ({
|
||||
contract: this.oracle,
|
||||
name: "getRateToEth",
|
||||
params: [tokenAddress, true]
|
||||
params: [tokenAddress, true],
|
||||
allowFailure: true
|
||||
}));
|
||||
}
|
||||
buildStable(stablecoinAddress) {
|
||||
@ -10322,32 +10326,42 @@ class TokenPriceOracle {
|
||||
{
|
||||
contract: this.oracle,
|
||||
name: "getRateToEth",
|
||||
params: [stablecoin.target, true]
|
||||
params: [stablecoin.target, true],
|
||||
allowFailure: true
|
||||
}
|
||||
];
|
||||
}
|
||||
async fetchPrice(tokenAddress, decimals) {
|
||||
if (!this.oracle) {
|
||||
return new Promise((resolve) => resolve(ethers.parseEther("0.0001")));
|
||||
return new Promise((resolve) => resolve(this.fallbackPrice));
|
||||
}
|
||||
try {
|
||||
const price = await this.oracle.getRateToEth(tokenAddress, true);
|
||||
return price * BigInt(10 ** decimals) / BigInt(10 ** 18);
|
||||
} catch (err) {
|
||||
console.log(`Failed to fetch oracle price for ${tokenAddress}, will use fallback price ${this.fallbackPrice}`);
|
||||
console.log(err);
|
||||
return this.fallbackPrice;
|
||||
}
|
||||
const price = await this.oracle.getRateToEth(tokenAddress, true);
|
||||
return price * BigInt(10 ** decimals) / BigInt(10 ** 18);
|
||||
}
|
||||
async fetchPrices(tokens) {
|
||||
if (!this.oracle) {
|
||||
return new Promise((resolve) => resolve(tokens.map(() => ethers.parseEther("0.0001"))));
|
||||
return new Promise((resolve) => resolve(tokens.map(() => this.fallbackPrice)));
|
||||
}
|
||||
const prices = await multicall(this.multicall, this.buildCalls(tokens));
|
||||
return prices.map((price, index) => {
|
||||
if (!price) {
|
||||
price = this.fallbackPrice;
|
||||
}
|
||||
return price * BigInt(10 ** tokens[index].decimals) / BigInt(10 ** 18);
|
||||
});
|
||||
}
|
||||
async fetchEthUSD(stablecoinAddress) {
|
||||
if (!this.oracle) {
|
||||
return new Promise((resolve) => resolve(1e4));
|
||||
return new Promise((resolve) => resolve(10 ** 18 / Number(this.fallbackPrice)));
|
||||
}
|
||||
const [decimals, price] = await multicall(this.multicall, this.buildStable(stablecoinAddress));
|
||||
const ethPrice = price * BigInt(10n ** decimals) / BigInt(10 ** 18);
|
||||
const ethPrice = (price || this.fallbackPrice) * BigInt(10n ** decimals) / BigInt(10 ** 18);
|
||||
return 1 / Number(ethers.formatEther(ethPrice));
|
||||
}
|
||||
}
|
||||
|
44
dist/index.mjs
vendored
44
dist/index.mjs
vendored
@ -1643,7 +1643,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0xd90e2f925DA726b50C4Ed8D0Fb90Ad053324F31b",
|
||||
echoContract: "0x9B27DD5Bb15d42DC224FCD0B7caEbBe16161Df42",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
tornContract: "0x77777FeDdddFfC19Ff86DB637967013e6C6A116C",
|
||||
governanceContract: "0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce",
|
||||
stakingRewardsContract: "0x5B3f656C80E8ddb9ec01Dd9018815576E9238c29",
|
||||
@ -1757,7 +1757,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x0D5550d52428E7e3175bfc9550207e4ad3859b17",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
tornadoSubgraph: "tornadocash/bsc-tornado-subgraph",
|
||||
subgraphs: {},
|
||||
rpcUrls: {
|
||||
@ -1820,7 +1820,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x0D5550d52428E7e3175bfc9550207e4ad3859b17",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
tornadoSubgraph: "tornadocash/matic-tornado-subgraph",
|
||||
subgraphs: {},
|
||||
rpcUrls: {
|
||||
@ -1871,7 +1871,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x0D5550d52428E7e3175bfc9550207e4ad3859b17",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
ovmGasPriceOracleContract: "0x420000000000000000000000000000000000000F",
|
||||
tornadoSubgraph: "tornadocash/optimism-tornado-subgraph",
|
||||
subgraphs: {},
|
||||
@ -1923,7 +1923,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x0D5550d52428E7e3175bfc9550207e4ad3859b17",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
tornadoSubgraph: "tornadocash/arbitrum-tornado-subgraph",
|
||||
subgraphs: {},
|
||||
rpcUrls: {
|
||||
@ -1978,7 +1978,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x0D5550d52428E7e3175bfc9550207e4ad3859b17",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
tornadoSubgraph: "tornadocash/xdai-tornado-subgraph",
|
||||
subgraphs: {},
|
||||
rpcUrls: {
|
||||
@ -2029,7 +2029,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x0D5550d52428E7e3175bfc9550207e4ad3859b17",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
tornadoSubgraph: "tornadocash/avalanche-tornado-subgraph",
|
||||
subgraphs: {},
|
||||
rpcUrls: {
|
||||
@ -2079,6 +2079,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x1572AFE6949fdF51Cb3E0856216670ae9Ee160Ee",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x1f89EAF03E5b260Bc6D4Ae3c3334b1B750F3e127",
|
||||
tornContract: "0x3AE6667167C0f44394106E197904519D808323cA",
|
||||
governanceContract: "0xe5324cD7602eeb387418e594B87aCADee08aeCAD",
|
||||
stakingRewardsContract: "0x6d0018890751Efd31feb8166711B16732E2b496b",
|
||||
@ -10279,16 +10280,19 @@ class TokenPriceOracle {
|
||||
oracle;
|
||||
multicall;
|
||||
provider;
|
||||
fallbackPrice;
|
||||
constructor(provider, multicall2, oracle) {
|
||||
this.provider = provider;
|
||||
this.multicall = multicall2;
|
||||
this.oracle = oracle;
|
||||
this.fallbackPrice = parseEther("0.0001");
|
||||
}
|
||||
buildCalls(tokens) {
|
||||
return tokens.map(({ tokenAddress }) => ({
|
||||
contract: this.oracle,
|
||||
name: "getRateToEth",
|
||||
params: [tokenAddress, true]
|
||||
params: [tokenAddress, true],
|
||||
allowFailure: true
|
||||
}));
|
||||
}
|
||||
buildStable(stablecoinAddress) {
|
||||
@ -10301,32 +10305,42 @@ class TokenPriceOracle {
|
||||
{
|
||||
contract: this.oracle,
|
||||
name: "getRateToEth",
|
||||
params: [stablecoin.target, true]
|
||||
params: [stablecoin.target, true],
|
||||
allowFailure: true
|
||||
}
|
||||
];
|
||||
}
|
||||
async fetchPrice(tokenAddress, decimals) {
|
||||
if (!this.oracle) {
|
||||
return new Promise((resolve) => resolve(parseEther("0.0001")));
|
||||
return new Promise((resolve) => resolve(this.fallbackPrice));
|
||||
}
|
||||
try {
|
||||
const price = await this.oracle.getRateToEth(tokenAddress, true);
|
||||
return price * BigInt(10 ** decimals) / BigInt(10 ** 18);
|
||||
} catch (err) {
|
||||
console.log(`Failed to fetch oracle price for ${tokenAddress}, will use fallback price ${this.fallbackPrice}`);
|
||||
console.log(err);
|
||||
return this.fallbackPrice;
|
||||
}
|
||||
const price = await this.oracle.getRateToEth(tokenAddress, true);
|
||||
return price * BigInt(10 ** decimals) / BigInt(10 ** 18);
|
||||
}
|
||||
async fetchPrices(tokens) {
|
||||
if (!this.oracle) {
|
||||
return new Promise((resolve) => resolve(tokens.map(() => parseEther("0.0001"))));
|
||||
return new Promise((resolve) => resolve(tokens.map(() => this.fallbackPrice)));
|
||||
}
|
||||
const prices = await multicall(this.multicall, this.buildCalls(tokens));
|
||||
return prices.map((price, index) => {
|
||||
if (!price) {
|
||||
price = this.fallbackPrice;
|
||||
}
|
||||
return price * BigInt(10 ** tokens[index].decimals) / BigInt(10 ** 18);
|
||||
});
|
||||
}
|
||||
async fetchEthUSD(stablecoinAddress) {
|
||||
if (!this.oracle) {
|
||||
return new Promise((resolve) => resolve(1e4));
|
||||
return new Promise((resolve) => resolve(10 ** 18 / Number(this.fallbackPrice)));
|
||||
}
|
||||
const [decimals, price] = await multicall(this.multicall, this.buildStable(stablecoinAddress));
|
||||
const ethPrice = price * BigInt(10n ** decimals) / BigInt(10 ** 18);
|
||||
const ethPrice = (price || this.fallbackPrice) * BigInt(10n ** decimals) / BigInt(10 ** 18);
|
||||
return 1 / Number(formatEther(ethPrice));
|
||||
}
|
||||
}
|
||||
|
1
dist/prices.d.ts
vendored
1
dist/prices.d.ts
vendored
@ -5,6 +5,7 @@ export declare class TokenPriceOracle {
|
||||
oracle?: OffchainOracle;
|
||||
multicall: Multicall;
|
||||
provider: Provider;
|
||||
fallbackPrice: bigint;
|
||||
constructor(provider: Provider, multicall: Multicall, oracle?: OffchainOracle);
|
||||
buildCalls(tokens: {
|
||||
tokenAddress: string;
|
||||
|
44
dist/tornado.umd.js
vendored
44
dist/tornado.umd.js
vendored
@ -62509,7 +62509,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0xd90e2f925DA726b50C4Ed8D0Fb90Ad053324F31b",
|
||||
echoContract: "0x9B27DD5Bb15d42DC224FCD0B7caEbBe16161Df42",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
tornContract: "0x77777FeDdddFfC19Ff86DB637967013e6C6A116C",
|
||||
governanceContract: "0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce",
|
||||
stakingRewardsContract: "0x5B3f656C80E8ddb9ec01Dd9018815576E9238c29",
|
||||
@ -62623,7 +62623,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x0D5550d52428E7e3175bfc9550207e4ad3859b17",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
tornadoSubgraph: "tornadocash/bsc-tornado-subgraph",
|
||||
subgraphs: {},
|
||||
rpcUrls: {
|
||||
@ -62686,7 +62686,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x0D5550d52428E7e3175bfc9550207e4ad3859b17",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
tornadoSubgraph: "tornadocash/matic-tornado-subgraph",
|
||||
subgraphs: {},
|
||||
rpcUrls: {
|
||||
@ -62737,7 +62737,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x0D5550d52428E7e3175bfc9550207e4ad3859b17",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
ovmGasPriceOracleContract: "0x420000000000000000000000000000000000000F",
|
||||
tornadoSubgraph: "tornadocash/optimism-tornado-subgraph",
|
||||
subgraphs: {},
|
||||
@ -62789,7 +62789,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x0D5550d52428E7e3175bfc9550207e4ad3859b17",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
tornadoSubgraph: "tornadocash/arbitrum-tornado-subgraph",
|
||||
subgraphs: {},
|
||||
rpcUrls: {
|
||||
@ -62844,7 +62844,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x0D5550d52428E7e3175bfc9550207e4ad3859b17",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
tornadoSubgraph: "tornadocash/xdai-tornado-subgraph",
|
||||
subgraphs: {},
|
||||
rpcUrls: {
|
||||
@ -62895,7 +62895,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x0D5550d52428E7e3175bfc9550207e4ad3859b17",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8",
|
||||
offchainOracleContract: "0x00000000000D6FFc74A8feb35aF5827bf57f6786",
|
||||
tornadoSubgraph: "tornadocash/avalanche-tornado-subgraph",
|
||||
subgraphs: {},
|
||||
rpcUrls: {
|
||||
@ -62945,6 +62945,7 @@ const defaultConfig = {
|
||||
multicallContract: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
||||
routerContract: "0x1572AFE6949fdF51Cb3E0856216670ae9Ee160Ee",
|
||||
echoContract: "0xa75BF2815618872f155b7C4B0C81bF990f5245E4",
|
||||
offchainOracleContract: "0x1f89EAF03E5b260Bc6D4Ae3c3334b1B750F3e127",
|
||||
tornContract: "0x3AE6667167C0f44394106E197904519D808323cA",
|
||||
governanceContract: "0xe5324cD7602eeb387418e594B87aCADee08aeCAD",
|
||||
stakingRewardsContract: "0x6d0018890751Efd31feb8166711B16732E2b496b",
|
||||
@ -63134,16 +63135,19 @@ class TokenPriceOracle {
|
||||
oracle;
|
||||
multicall;
|
||||
provider;
|
||||
fallbackPrice;
|
||||
constructor(provider, multicall2, oracle) {
|
||||
this.provider = provider;
|
||||
this.multicall = multicall2;
|
||||
this.oracle = oracle;
|
||||
this.fallbackPrice = (0,ethers__WEBPACK_IMPORTED_MODULE_1__/* .parseEther */ .g5)("0.0001");
|
||||
}
|
||||
buildCalls(tokens) {
|
||||
return tokens.map(({ tokenAddress }) => ({
|
||||
contract: this.oracle,
|
||||
name: "getRateToEth",
|
||||
params: [tokenAddress, true]
|
||||
params: [tokenAddress, true],
|
||||
allowFailure: true
|
||||
}));
|
||||
}
|
||||
buildStable(stablecoinAddress) {
|
||||
@ -63156,32 +63160,42 @@ class TokenPriceOracle {
|
||||
{
|
||||
contract: this.oracle,
|
||||
name: "getRateToEth",
|
||||
params: [stablecoin.target, true]
|
||||
params: [stablecoin.target, true],
|
||||
allowFailure: true
|
||||
}
|
||||
];
|
||||
}
|
||||
async fetchPrice(tokenAddress, decimals) {
|
||||
if (!this.oracle) {
|
||||
return new Promise((resolve) => resolve((0,ethers__WEBPACK_IMPORTED_MODULE_1__/* .parseEther */ .g5)("0.0001")));
|
||||
return new Promise((resolve) => resolve(this.fallbackPrice));
|
||||
}
|
||||
try {
|
||||
const price = await this.oracle.getRateToEth(tokenAddress, true);
|
||||
return price * BigInt(10 ** decimals) / BigInt(10 ** 18);
|
||||
} catch (err) {
|
||||
console.log(`Failed to fetch oracle price for ${tokenAddress}, will use fallback price ${this.fallbackPrice}`);
|
||||
console.log(err);
|
||||
return this.fallbackPrice;
|
||||
}
|
||||
const price = await this.oracle.getRateToEth(tokenAddress, true);
|
||||
return price * BigInt(10 ** decimals) / BigInt(10 ** 18);
|
||||
}
|
||||
async fetchPrices(tokens) {
|
||||
if (!this.oracle) {
|
||||
return new Promise((resolve) => resolve(tokens.map(() => (0,ethers__WEBPACK_IMPORTED_MODULE_1__/* .parseEther */ .g5)("0.0001"))));
|
||||
return new Promise((resolve) => resolve(tokens.map(() => this.fallbackPrice)));
|
||||
}
|
||||
const prices = await (0,_multicall__WEBPACK_IMPORTED_MODULE_2__/* .multicall */ .C)(this.multicall, this.buildCalls(tokens));
|
||||
return prices.map((price, index) => {
|
||||
if (!price) {
|
||||
price = this.fallbackPrice;
|
||||
}
|
||||
return price * BigInt(10 ** tokens[index].decimals) / BigInt(10 ** 18);
|
||||
});
|
||||
}
|
||||
async fetchEthUSD(stablecoinAddress) {
|
||||
if (!this.oracle) {
|
||||
return new Promise((resolve) => resolve(1e4));
|
||||
return new Promise((resolve) => resolve(10 ** 18 / Number(this.fallbackPrice)));
|
||||
}
|
||||
const [decimals, price] = await (0,_multicall__WEBPACK_IMPORTED_MODULE_2__/* .multicall */ .C)(this.multicall, this.buildStable(stablecoinAddress));
|
||||
const ethPrice = price * BigInt(10n ** decimals) / BigInt(10 ** 18);
|
||||
const ethPrice = (price || this.fallbackPrice) * BigInt(10n ** decimals) / BigInt(10 ** 18);
|
||||
return 1 / Number((0,ethers__WEBPACK_IMPORTED_MODULE_1__/* .formatEther */ .ck)(ethPrice));
|
||||
}
|
||||
}
|
||||
|
2
dist/tornado.umd.min.js
vendored
2
dist/tornado.umd.min.js
vendored
File diff suppressed because one or more lines are too long
@ -151,7 +151,7 @@ export const defaultConfig: networkConfig = {
|
||||
multicallContract: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
||||
routerContract: '0xd90e2f925DA726b50C4Ed8D0Fb90Ad053324F31b',
|
||||
echoContract: '0x9B27DD5Bb15d42DC224FCD0B7caEbBe16161Df42',
|
||||
offchainOracleContract: '0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8',
|
||||
offchainOracleContract: '0x00000000000D6FFc74A8feb35aF5827bf57f6786',
|
||||
tornContract: '0x77777FeDdddFfC19Ff86DB637967013e6C6A116C',
|
||||
governanceContract: '0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce',
|
||||
stakingRewardsContract: '0x5B3f656C80E8ddb9ec01Dd9018815576E9238c29',
|
||||
@ -265,7 +265,7 @@ export const defaultConfig: networkConfig = {
|
||||
multicallContract: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
||||
routerContract: '0x0D5550d52428E7e3175bfc9550207e4ad3859b17',
|
||||
echoContract: '0xa75BF2815618872f155b7C4B0C81bF990f5245E4',
|
||||
offchainOracleContract: '0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8',
|
||||
offchainOracleContract: '0x00000000000D6FFc74A8feb35aF5827bf57f6786',
|
||||
tornadoSubgraph: 'tornadocash/bsc-tornado-subgraph',
|
||||
subgraphs: {},
|
||||
rpcUrls: {
|
||||
@ -328,7 +328,7 @@ export const defaultConfig: networkConfig = {
|
||||
multicallContract: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
||||
routerContract: '0x0D5550d52428E7e3175bfc9550207e4ad3859b17',
|
||||
echoContract: '0xa75BF2815618872f155b7C4B0C81bF990f5245E4',
|
||||
offchainOracleContract: '0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8',
|
||||
offchainOracleContract: '0x00000000000D6FFc74A8feb35aF5827bf57f6786',
|
||||
tornadoSubgraph: 'tornadocash/matic-tornado-subgraph',
|
||||
subgraphs: {},
|
||||
rpcUrls: {
|
||||
@ -379,7 +379,7 @@ export const defaultConfig: networkConfig = {
|
||||
multicallContract: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
||||
routerContract: '0x0D5550d52428E7e3175bfc9550207e4ad3859b17',
|
||||
echoContract: '0xa75BF2815618872f155b7C4B0C81bF990f5245E4',
|
||||
offchainOracleContract: '0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8',
|
||||
offchainOracleContract: '0x00000000000D6FFc74A8feb35aF5827bf57f6786',
|
||||
ovmGasPriceOracleContract: '0x420000000000000000000000000000000000000F',
|
||||
tornadoSubgraph: 'tornadocash/optimism-tornado-subgraph',
|
||||
subgraphs: {},
|
||||
@ -431,7 +431,7 @@ export const defaultConfig: networkConfig = {
|
||||
multicallContract: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
||||
routerContract: '0x0D5550d52428E7e3175bfc9550207e4ad3859b17',
|
||||
echoContract: '0xa75BF2815618872f155b7C4B0C81bF990f5245E4',
|
||||
offchainOracleContract: '0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8',
|
||||
offchainOracleContract: '0x00000000000D6FFc74A8feb35aF5827bf57f6786',
|
||||
tornadoSubgraph: 'tornadocash/arbitrum-tornado-subgraph',
|
||||
subgraphs: {},
|
||||
rpcUrls: {
|
||||
@ -486,7 +486,7 @@ export const defaultConfig: networkConfig = {
|
||||
multicallContract: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
||||
routerContract: '0x0D5550d52428E7e3175bfc9550207e4ad3859b17',
|
||||
echoContract: '0xa75BF2815618872f155b7C4B0C81bF990f5245E4',
|
||||
offchainOracleContract: '0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8',
|
||||
offchainOracleContract: '0x00000000000D6FFc74A8feb35aF5827bf57f6786',
|
||||
tornadoSubgraph: 'tornadocash/xdai-tornado-subgraph',
|
||||
subgraphs: {},
|
||||
rpcUrls: {
|
||||
@ -537,7 +537,7 @@ export const defaultConfig: networkConfig = {
|
||||
multicallContract: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
||||
routerContract: '0x0D5550d52428E7e3175bfc9550207e4ad3859b17',
|
||||
echoContract: '0xa75BF2815618872f155b7C4B0C81bF990f5245E4',
|
||||
offchainOracleContract: '0x0AdDd25a91563696D8567Df78D5A01C9a991F9B8',
|
||||
offchainOracleContract: '0x00000000000D6FFc74A8feb35aF5827bf57f6786',
|
||||
tornadoSubgraph: 'tornadocash/avalanche-tornado-subgraph',
|
||||
subgraphs: {},
|
||||
rpcUrls: {
|
||||
@ -587,6 +587,7 @@ export const defaultConfig: networkConfig = {
|
||||
multicallContract: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
||||
routerContract: '0x1572AFE6949fdF51Cb3E0856216670ae9Ee160Ee',
|
||||
echoContract: '0xa75BF2815618872f155b7C4B0C81bF990f5245E4',
|
||||
offchainOracleContract: '0x1f89EAF03E5b260Bc6D4Ae3c3334b1B750F3e127',
|
||||
tornContract: '0x3AE6667167C0f44394106E197904519D808323cA',
|
||||
governanceContract: '0xe5324cD7602eeb387418e594B87aCADee08aeCAD',
|
||||
stakingRewardsContract: '0x6d0018890751Efd31feb8166711B16732E2b496b',
|
||||
|
@ -7,10 +7,13 @@ export class TokenPriceOracle {
|
||||
multicall: Multicall;
|
||||
provider: Provider;
|
||||
|
||||
fallbackPrice: bigint;
|
||||
|
||||
constructor(provider: Provider, multicall: Multicall, oracle?: OffchainOracle) {
|
||||
this.provider = provider;
|
||||
this.multicall = multicall;
|
||||
this.oracle = oracle;
|
||||
this.fallbackPrice = parseEther('0.0001');
|
||||
}
|
||||
|
||||
buildCalls(
|
||||
@ -23,6 +26,7 @@ export class TokenPriceOracle {
|
||||
contract: this.oracle,
|
||||
name: 'getRateToEth',
|
||||
params: [tokenAddress, true],
|
||||
allowFailure: true,
|
||||
}));
|
||||
}
|
||||
|
||||
@ -38,6 +42,7 @@ export class TokenPriceOracle {
|
||||
contract: this.oracle,
|
||||
name: 'getRateToEth',
|
||||
params: [stablecoin.target, true],
|
||||
allowFailure: true,
|
||||
},
|
||||
];
|
||||
}
|
||||
@ -45,12 +50,18 @@ export class TokenPriceOracle {
|
||||
async fetchPrice(tokenAddress: string, decimals: number): Promise<bigint> {
|
||||
// setup mock price for testnets
|
||||
if (!this.oracle) {
|
||||
return new Promise((resolve) => resolve(parseEther('0.0001')));
|
||||
return new Promise((resolve) => resolve(this.fallbackPrice));
|
||||
}
|
||||
|
||||
const price = await this.oracle.getRateToEth(tokenAddress, true);
|
||||
try {
|
||||
const price = await this.oracle.getRateToEth(tokenAddress, true);
|
||||
|
||||
return (price * BigInt(10 ** decimals)) / BigInt(10 ** 18);
|
||||
return (price * BigInt(10 ** decimals)) / BigInt(10 ** 18);
|
||||
} catch (err) {
|
||||
console.log(`Failed to fetch oracle price for ${tokenAddress}, will use fallback price ${this.fallbackPrice}`);
|
||||
console.log(err);
|
||||
return this.fallbackPrice;
|
||||
}
|
||||
}
|
||||
|
||||
async fetchPrices(
|
||||
@ -61,12 +72,15 @@ export class TokenPriceOracle {
|
||||
): Promise<bigint[]> {
|
||||
// setup mock price for testnets
|
||||
if (!this.oracle) {
|
||||
return new Promise((resolve) => resolve(tokens.map(() => parseEther('0.0001'))));
|
||||
return new Promise((resolve) => resolve(tokens.map(() => this.fallbackPrice)));
|
||||
}
|
||||
|
||||
const prices = (await multicall(this.multicall, this.buildCalls(tokens))) as bigint[];
|
||||
const prices = (await multicall(this.multicall, this.buildCalls(tokens))) as (bigint | null)[];
|
||||
|
||||
return prices.map((price, index) => {
|
||||
if (!price) {
|
||||
price = this.fallbackPrice;
|
||||
}
|
||||
return (price * BigInt(10 ** tokens[index].decimals)) / BigInt(10 ** 18);
|
||||
});
|
||||
}
|
||||
@ -74,13 +88,13 @@ export class TokenPriceOracle {
|
||||
async fetchEthUSD(stablecoinAddress: string): Promise<number> {
|
||||
// setup mock price for testnets
|
||||
if (!this.oracle) {
|
||||
return new Promise((resolve) => resolve(10000));
|
||||
return new Promise((resolve) => resolve(10 ** 18 / Number(this.fallbackPrice)));
|
||||
}
|
||||
|
||||
const [decimals, price] = await multicall(this.multicall, this.buildStable(stablecoinAddress));
|
||||
|
||||
// eth wei price of usdc token
|
||||
const ethPrice = (price * BigInt(10n ** decimals)) / BigInt(10 ** 18);
|
||||
const ethPrice = ((price || this.fallbackPrice) * BigInt(10n ** decimals)) / BigInt(10 ** 18);
|
||||
|
||||
return 1 / Number(formatEther(ethPrice));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user