Added ERC20Tornado instances on BSC

This commit is contained in:
Tornado Contrib 2024-11-23 15:55:07 +00:00
parent 68fcf07c2a
commit 2337892195
Signed by: tornadocontrib
GPG Key ID: 60B4DF1A076C64B1
12 changed files with 471 additions and 123 deletions

47
dist/events/db.d.ts vendored

@ -1,10 +1,10 @@
import { IndexedDB } from '../idb'; import { IndexedDB } from '../idb';
import { BaseTornadoService, BaseTornadoServiceConstructor, BaseEchoService, BaseEchoServiceConstructor, BaseEncryptedNotesService, BaseEncryptedNotesServiceConstructor, BaseGovernanceService, BaseGovernanceServiceConstructor, BaseRegistryService, BaseRegistryServiceConstructor, BaseRevenueService, BaseRevenueServiceConstructor, CachedRelayers } from './base'; import { BaseTornadoService, BaseTornadoServiceConstructor, BaseEchoService, BaseEchoServiceConstructor, BaseEncryptedNotesService, BaseEncryptedNotesServiceConstructor, BaseGovernanceService, BaseGovernanceServiceConstructor, BaseRegistryService, BaseRegistryServiceConstructor, BaseRevenueService, BaseRevenueServiceConstructor, CachedRelayers, BaseMultiTornadoService, BaseMultiTornadoServiceConstructor } from './base';
import { BaseEvents, MinimalEvents, DepositsEvents, WithdrawalsEvents, CachedEvents, EchoEvents, EncryptedNotesEvents, AllGovernanceEvents, AllRelayerRegistryEvents, StakeBurnedEvents } from './types'; import { BaseEvents, MinimalEvents, DepositsEvents, WithdrawalsEvents, CachedEvents, EchoEvents, EncryptedNotesEvents, AllGovernanceEvents, AllRelayerRegistryEvents, StakeBurnedEvents, MultiDepositsEvents, MultiWithdrawalsEvents } from './types';
export declare function saveDBEvents<T extends MinimalEvents>({ idb, instanceName, events, lastBlock, }: { export declare function saveDBEvents<T extends MinimalEvents>({ idb, instanceName, newEvents, lastBlock, }: {
idb: IndexedDB; idb: IndexedDB;
instanceName: string; instanceName: string;
events: T[]; newEvents: T[];
lastBlock: number; lastBlock: number;
}): Promise<void>; }): Promise<void>;
export declare function loadDBEvents<T extends MinimalEvents>({ idb, instanceName, }: { export declare function loadDBEvents<T extends MinimalEvents>({ idb, instanceName, }: {
@ -28,7 +28,24 @@ export declare class DBTornadoService extends BaseTornadoService {
constructor(params: DBTornadoServiceConstructor); constructor(params: DBTornadoServiceConstructor);
getEventsFromDB(): Promise<BaseEvents<DepositsEvents | WithdrawalsEvents>>; getEventsFromDB(): Promise<BaseEvents<DepositsEvents | WithdrawalsEvents>>;
getEventsFromCache(): Promise<CachedEvents<DepositsEvents | WithdrawalsEvents>>; getEventsFromCache(): Promise<CachedEvents<DepositsEvents | WithdrawalsEvents>>;
saveEvents({ events, lastBlock }: BaseEvents<DepositsEvents | WithdrawalsEvents>): Promise<void>; saveEvents({ newEvents, lastBlock, }: BaseEvents<DepositsEvents | WithdrawalsEvents> & {
newEvents: (DepositsEvents | WithdrawalsEvents)[];
}): Promise<void>;
}
export interface DBMultiTornadoServiceConstructor extends BaseMultiTornadoServiceConstructor {
staticUrl: string;
idb: IndexedDB;
}
export declare class DBMultiTornadoService extends BaseMultiTornadoService {
staticUrl: string;
idb: IndexedDB;
zipDigest?: string;
constructor(params: DBMultiTornadoServiceConstructor);
getEventsFromDB(): Promise<BaseEvents<MultiDepositsEvents | MultiWithdrawalsEvents>>;
getEventsFromCache(): Promise<CachedEvents<MultiDepositsEvents | MultiWithdrawalsEvents>>;
saveEvents({ newEvents, lastBlock, }: BaseEvents<MultiDepositsEvents | MultiWithdrawalsEvents> & {
newEvents: (MultiDepositsEvents | MultiWithdrawalsEvents)[];
}): Promise<void>;
} }
export interface DBEchoServiceConstructor extends BaseEchoServiceConstructor { export interface DBEchoServiceConstructor extends BaseEchoServiceConstructor {
staticUrl: string; staticUrl: string;
@ -41,7 +58,9 @@ export declare class DBEchoService extends BaseEchoService {
constructor(params: DBEchoServiceConstructor); constructor(params: DBEchoServiceConstructor);
getEventsFromDB(): Promise<BaseEvents<EchoEvents>>; getEventsFromDB(): Promise<BaseEvents<EchoEvents>>;
getEventsFromCache(): Promise<CachedEvents<EchoEvents>>; getEventsFromCache(): Promise<CachedEvents<EchoEvents>>;
saveEvents({ events, lastBlock }: BaseEvents<EchoEvents>): Promise<void>; saveEvents({ newEvents, lastBlock }: BaseEvents<EchoEvents> & {
newEvents: EchoEvents[];
}): Promise<void>;
} }
export interface DBEncryptedNotesServiceConstructor extends BaseEncryptedNotesServiceConstructor { export interface DBEncryptedNotesServiceConstructor extends BaseEncryptedNotesServiceConstructor {
staticUrl: string; staticUrl: string;
@ -54,7 +73,9 @@ export declare class DBEncryptedNotesService extends BaseEncryptedNotesService {
constructor(params: DBEncryptedNotesServiceConstructor); constructor(params: DBEncryptedNotesServiceConstructor);
getEventsFromDB(): Promise<BaseEvents<EncryptedNotesEvents>>; getEventsFromDB(): Promise<BaseEvents<EncryptedNotesEvents>>;
getEventsFromCache(): Promise<CachedEvents<EncryptedNotesEvents>>; getEventsFromCache(): Promise<CachedEvents<EncryptedNotesEvents>>;
saveEvents({ events, lastBlock }: BaseEvents<EncryptedNotesEvents>): Promise<void>; saveEvents({ newEvents, lastBlock, }: BaseEvents<EncryptedNotesEvents> & {
newEvents: EncryptedNotesEvents[];
}): Promise<void>;
} }
export interface DBGovernanceServiceConstructor extends BaseGovernanceServiceConstructor { export interface DBGovernanceServiceConstructor extends BaseGovernanceServiceConstructor {
staticUrl: string; staticUrl: string;
@ -67,7 +88,9 @@ export declare class DBGovernanceService extends BaseGovernanceService {
constructor(params: DBGovernanceServiceConstructor); constructor(params: DBGovernanceServiceConstructor);
getEventsFromDB(): Promise<BaseEvents<AllGovernanceEvents>>; getEventsFromDB(): Promise<BaseEvents<AllGovernanceEvents>>;
getEventsFromCache(): Promise<CachedEvents<AllGovernanceEvents>>; getEventsFromCache(): Promise<CachedEvents<AllGovernanceEvents>>;
saveEvents({ events, lastBlock }: BaseEvents<AllGovernanceEvents>): Promise<void>; saveEvents({ newEvents, lastBlock }: BaseEvents<AllGovernanceEvents> & {
newEvents: AllGovernanceEvents[];
}): Promise<void>;
} }
export interface DBRegistryServiceConstructor extends BaseRegistryServiceConstructor { export interface DBRegistryServiceConstructor extends BaseRegistryServiceConstructor {
staticUrl: string; staticUrl: string;
@ -81,7 +104,9 @@ export declare class DBRegistryService extends BaseRegistryService {
constructor(params: DBRegistryServiceConstructor); constructor(params: DBRegistryServiceConstructor);
getEventsFromDB(): Promise<BaseEvents<AllRelayerRegistryEvents>>; getEventsFromDB(): Promise<BaseEvents<AllRelayerRegistryEvents>>;
getEventsFromCache(): Promise<CachedEvents<AllRelayerRegistryEvents>>; getEventsFromCache(): Promise<CachedEvents<AllRelayerRegistryEvents>>;
saveEvents({ events, lastBlock }: BaseEvents<AllRelayerRegistryEvents>): Promise<void>; saveEvents({ newEvents, lastBlock, }: BaseEvents<AllRelayerRegistryEvents> & {
newEvents: AllRelayerRegistryEvents[];
}): Promise<void>;
getRelayersFromDB(): Promise<CachedRelayers>; getRelayersFromDB(): Promise<CachedRelayers>;
getRelayersFromCache(): Promise<CachedRelayers>; getRelayersFromCache(): Promise<CachedRelayers>;
saveRelayers(cachedRelayers: CachedRelayers): Promise<void>; saveRelayers(cachedRelayers: CachedRelayers): Promise<void>;
@ -98,5 +123,7 @@ export declare class DBRevenueService extends BaseRevenueService {
constructor(params: DBRevenueServiceConstructor); constructor(params: DBRevenueServiceConstructor);
getEventsFromDB(): Promise<BaseEvents<StakeBurnedEvents>>; getEventsFromDB(): Promise<BaseEvents<StakeBurnedEvents>>;
getEventsFromCache(): Promise<CachedEvents<StakeBurnedEvents>>; getEventsFromCache(): Promise<CachedEvents<StakeBurnedEvents>>;
saveEvents({ events, lastBlock }: BaseEvents<StakeBurnedEvents>): Promise<void>; saveEvents({ newEvents, lastBlock }: BaseEvents<StakeBurnedEvents> & {
newEvents: StakeBurnedEvents[];
}): Promise<void>;
} }

2
dist/fees.d.ts vendored

@ -29,7 +29,7 @@ export declare class TornadoFeeOracle {
* (A single block can bump 12.5% of fees, see the methodology https://hackmd.io/@tvanepps/1559-wallets) * (A single block can bump 12.5% of fees, see the methodology https://hackmd.io/@tvanepps/1559-wallets)
* (Still it is recommended to use 100% premium for sending transactions to prevent stucking it) * (Still it is recommended to use 100% premium for sending transactions to prevent stucking it)
*/ */
gasPrice(): Promise<bigint>; gasPrice(premium?: number): Promise<bigint>;
/** /**
* Calculate L1 fee for op-stack chains * Calculate L1 fee for op-stack chains
* *

128
dist/index.js vendored

@ -1031,6 +1031,34 @@ const defaultConfig = {
}, },
symbol: "BNB", symbol: "BNB",
decimals: 18 decimals: 18
},
usdt: {
instanceAddress: {
"10": "0x261fB4f84bb0BdEe7E035B6a8a08e5c35AdacdDD",
"100": "0x3957861d4897d883C9b944C0b4E22bBd0DDE6e21",
"1000": "0x6D180403AdFb39F70983eB51A033C5e52eb9BB69",
"10000": "0x3722662D8AaB07B216B14C02eF0ee940d14A4200"
},
instanceApproval: true,
tokenAddress: "0x55d398326f99059fF775485246999027B3197955",
tokenGasLimit: 7e4,
symbol: "USDT",
decimals: 18,
gasLimit: 7e5
},
btcb: {
instanceAddress: {
"0.0001": "0x736dABbFc8101Ae75287104eCcf67e45D7369Ae1",
"0.001": "0x82c7Ce6f1F158cEC5536d591a2BC19864b3CA823",
"0.01": "0x8284c96679037d8081E498d8F767cA5a140BFAAf",
"0.1": "0x2bcD128Ce23ee30Ee945E613ff129c4DE1102C79"
},
instanceApproval: true,
tokenAddress: "0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c",
tokenGasLimit: 7e4,
symbol: "BTCB",
decimals: 18,
gasLimit: 7e5
} }
}, },
relayerEnsSubdomain: "bsc-tornado", relayerEnsSubdomain: "bsc-tornado",
@ -2578,7 +2606,10 @@ class BaseMultiTornadoService extends BaseEventsService {
} }
return acc; return acc;
}, },
{} {
depositEvents: [],
withdrawalEvents: []
}
); );
return { return {
depositEvents, depositEvents,
@ -3257,11 +3288,11 @@ async function downloadZip({
async function saveDBEvents({ async function saveDBEvents({
idb, idb,
instanceName, instanceName,
events, newEvents,
lastBlock lastBlock
}) { }) {
try { try {
const formattedEvents = events.map((e) => { const formattedEvents = newEvents.map((e) => {
return { return {
eid: `${e.transactionHash}_${e.logIndex}`, eid: `${e.transactionHash}_${e.logIndex}`,
...e ...e
@ -3372,11 +3403,49 @@ class DBTornadoService extends BaseTornadoService {
zipDigest: this.zipDigest zipDigest: this.zipDigest
}); });
} }
async saveEvents({ events, lastBlock }) { async saveEvents({
newEvents,
lastBlock
}) {
await saveDBEvents({ await saveDBEvents({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock
});
}
}
class DBMultiTornadoService extends BaseMultiTornadoService {
staticUrl;
idb;
zipDigest;
constructor(params) {
super(params);
this.staticUrl = params.staticUrl;
this.idb = params.idb;
}
async getEventsFromDB() {
return await loadDBEvents({
idb: this.idb,
instanceName: this.getInstanceName()
});
}
async getEventsFromCache() {
return await loadRemoteEvents({
staticUrl: this.staticUrl,
instanceName: this.getInstanceName(),
deployedBlock: this.deployedBlock,
zipDigest: this.zipDigest
});
}
async saveEvents({
newEvents,
lastBlock
}) {
await saveDBEvents({
idb: this.idb,
instanceName: this.getInstanceName(),
newEvents,
lastBlock lastBlock
}); });
} }
@ -3404,11 +3473,11 @@ class DBEchoService extends BaseEchoService {
zipDigest: this.zipDigest zipDigest: this.zipDigest
}); });
} }
async saveEvents({ events, lastBlock }) { async saveEvents({ newEvents, lastBlock }) {
await saveDBEvents({ await saveDBEvents({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock lastBlock
}); });
} }
@ -3436,11 +3505,14 @@ class DBEncryptedNotesService extends BaseEncryptedNotesService {
zipDigest: this.zipDigest zipDigest: this.zipDigest
}); });
} }
async saveEvents({ events, lastBlock }) { async saveEvents({
newEvents,
lastBlock
}) {
await saveDBEvents({ await saveDBEvents({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock lastBlock
}); });
} }
@ -3468,11 +3540,11 @@ class DBGovernanceService extends BaseGovernanceService {
zipDigest: this.zipDigest zipDigest: this.zipDigest
}); });
} }
async saveEvents({ events, lastBlock }) { async saveEvents({ newEvents, lastBlock }) {
await saveDBEvents({ await saveDBEvents({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock lastBlock
}); });
} }
@ -3501,11 +3573,14 @@ class DBRegistryService extends BaseRegistryService {
zipDigest: this.zipDigest zipDigest: this.zipDigest
}); });
} }
async saveEvents({ events, lastBlock }) { async saveEvents({
newEvents,
lastBlock
}) {
await saveDBEvents({ await saveDBEvents({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock lastBlock
}); });
} }
@ -3594,11 +3669,11 @@ class DBRevenueService extends BaseRevenueService {
zipDigest: this.zipDigest zipDigest: this.zipDigest
}); });
} }
async saveEvents({ events, lastBlock }) { async saveEvents({ newEvents, lastBlock }) {
await saveDBEvents({ await saveDBEvents({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock lastBlock
}); });
} }
@ -9341,7 +9416,7 @@ class TornadoFeeOracle {
* (A single block can bump 12.5% of fees, see the methodology https://hackmd.io/@tvanepps/1559-wallets) * (A single block can bump 12.5% of fees, see the methodology https://hackmd.io/@tvanepps/1559-wallets)
* (Still it is recommended to use 100% premium for sending transactions to prevent stucking it) * (Still it is recommended to use 100% premium for sending transactions to prevent stucking it)
*/ */
async gasPrice() { async gasPrice(premium) {
const [block, getGasPrice, getPriorityFee] = await Promise.all([ const [block, getGasPrice, getPriorityFee] = await Promise.all([
this.provider.getBlock("latest"), this.provider.getBlock("latest"),
(async () => { (async () => {
@ -9359,7 +9434,7 @@ class TornadoFeeOracle {
} }
})() })()
]); ]);
return block?.baseFeePerGas ? block.baseFeePerGas * BigInt(15) / BigInt(10) + getPriorityFee : getGasPrice; return block?.baseFeePerGas ? block.baseFeePerGas * BigInt(1e4 * (100 + (premium || 50))) / BigInt(1e4 * 100) + getPriorityFee : getGasPrice;
} }
/** /**
* Calculate L1 fee for op-stack chains * Calculate L1 fee for op-stack chains
@ -9502,7 +9577,7 @@ class IndexedDB {
} }
}; };
this.dbName = dbName; this.dbName = dbName;
this.dbVersion = 35; this.dbVersion = 36;
} }
async initDB() { async initDB() {
try { try {
@ -9698,15 +9773,16 @@ async function getIndexedDB(netId) {
} }
const minimalIndexes = [ const minimalIndexes = [
{ {
name: "blockNumber", name: "eid",
unique: false unique: true
},
{
name: "transactionHash",
unique: false
} }
]; ];
const defaultState = [ const defaultState = [
{
name: `tornado_${netId}`,
keyPath: "eid",
indexes: [...minimalIndexes]
},
{ {
name: `echo_${netId}`, name: `echo_${netId}`,
keyPath: "eid", keyPath: "eid",
@ -9734,8 +9810,7 @@ async function getIndexedDB(netId) {
] ]
} }
]; ];
const config = getConfig(netId); const { tokens, nativeCurrency, registryContract, governanceContract } = getConfig(netId);
const { tokens, nativeCurrency, registryContract, governanceContract } = config;
const stores = [...defaultState]; const stores = [...defaultState];
if (registryContract) { if (registryContract) {
stores.push({ stores.push({
@ -10641,6 +10716,7 @@ exports.BatchTransactionService = BatchTransactionService;
exports.DBEchoService = DBEchoService; exports.DBEchoService = DBEchoService;
exports.DBEncryptedNotesService = DBEncryptedNotesService; exports.DBEncryptedNotesService = DBEncryptedNotesService;
exports.DBGovernanceService = DBGovernanceService; exports.DBGovernanceService = DBGovernanceService;
exports.DBMultiTornadoService = DBMultiTornadoService;
exports.DBRegistryService = DBRegistryService; exports.DBRegistryService = DBRegistryService;
exports.DBRevenueService = DBRevenueService; exports.DBRevenueService = DBRevenueService;
exports.DBTornadoService = DBTornadoService; exports.DBTornadoService = DBTornadoService;

129
dist/index.mjs vendored

@ -1009,6 +1009,34 @@ const defaultConfig = {
}, },
symbol: "BNB", symbol: "BNB",
decimals: 18 decimals: 18
},
usdt: {
instanceAddress: {
"10": "0x261fB4f84bb0BdEe7E035B6a8a08e5c35AdacdDD",
"100": "0x3957861d4897d883C9b944C0b4E22bBd0DDE6e21",
"1000": "0x6D180403AdFb39F70983eB51A033C5e52eb9BB69",
"10000": "0x3722662D8AaB07B216B14C02eF0ee940d14A4200"
},
instanceApproval: true,
tokenAddress: "0x55d398326f99059fF775485246999027B3197955",
tokenGasLimit: 7e4,
symbol: "USDT",
decimals: 18,
gasLimit: 7e5
},
btcb: {
instanceAddress: {
"0.0001": "0x736dABbFc8101Ae75287104eCcf67e45D7369Ae1",
"0.001": "0x82c7Ce6f1F158cEC5536d591a2BC19864b3CA823",
"0.01": "0x8284c96679037d8081E498d8F767cA5a140BFAAf",
"0.1": "0x2bcD128Ce23ee30Ee945E613ff129c4DE1102C79"
},
instanceApproval: true,
tokenAddress: "0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c",
tokenGasLimit: 7e4,
symbol: "BTCB",
decimals: 18,
gasLimit: 7e5
} }
}, },
relayerEnsSubdomain: "bsc-tornado", relayerEnsSubdomain: "bsc-tornado",
@ -2556,7 +2584,10 @@ class BaseMultiTornadoService extends BaseEventsService {
} }
return acc; return acc;
}, },
{} {
depositEvents: [],
withdrawalEvents: []
}
); );
return { return {
depositEvents, depositEvents,
@ -3235,11 +3266,11 @@ async function downloadZip({
async function saveDBEvents({ async function saveDBEvents({
idb, idb,
instanceName, instanceName,
events, newEvents,
lastBlock lastBlock
}) { }) {
try { try {
const formattedEvents = events.map((e) => { const formattedEvents = newEvents.map((e) => {
return { return {
eid: `${e.transactionHash}_${e.logIndex}`, eid: `${e.transactionHash}_${e.logIndex}`,
...e ...e
@ -3350,11 +3381,49 @@ class DBTornadoService extends BaseTornadoService {
zipDigest: this.zipDigest zipDigest: this.zipDigest
}); });
} }
async saveEvents({ events, lastBlock }) { async saveEvents({
newEvents,
lastBlock
}) {
await saveDBEvents({ await saveDBEvents({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock
});
}
}
class DBMultiTornadoService extends BaseMultiTornadoService {
staticUrl;
idb;
zipDigest;
constructor(params) {
super(params);
this.staticUrl = params.staticUrl;
this.idb = params.idb;
}
async getEventsFromDB() {
return await loadDBEvents({
idb: this.idb,
instanceName: this.getInstanceName()
});
}
async getEventsFromCache() {
return await loadRemoteEvents({
staticUrl: this.staticUrl,
instanceName: this.getInstanceName(),
deployedBlock: this.deployedBlock,
zipDigest: this.zipDigest
});
}
async saveEvents({
newEvents,
lastBlock
}) {
await saveDBEvents({
idb: this.idb,
instanceName: this.getInstanceName(),
newEvents,
lastBlock lastBlock
}); });
} }
@ -3382,11 +3451,11 @@ class DBEchoService extends BaseEchoService {
zipDigest: this.zipDigest zipDigest: this.zipDigest
}); });
} }
async saveEvents({ events, lastBlock }) { async saveEvents({ newEvents, lastBlock }) {
await saveDBEvents({ await saveDBEvents({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock lastBlock
}); });
} }
@ -3414,11 +3483,14 @@ class DBEncryptedNotesService extends BaseEncryptedNotesService {
zipDigest: this.zipDigest zipDigest: this.zipDigest
}); });
} }
async saveEvents({ events, lastBlock }) { async saveEvents({
newEvents,
lastBlock
}) {
await saveDBEvents({ await saveDBEvents({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock lastBlock
}); });
} }
@ -3446,11 +3518,11 @@ class DBGovernanceService extends BaseGovernanceService {
zipDigest: this.zipDigest zipDigest: this.zipDigest
}); });
} }
async saveEvents({ events, lastBlock }) { async saveEvents({ newEvents, lastBlock }) {
await saveDBEvents({ await saveDBEvents({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock lastBlock
}); });
} }
@ -3479,11 +3551,14 @@ class DBRegistryService extends BaseRegistryService {
zipDigest: this.zipDigest zipDigest: this.zipDigest
}); });
} }
async saveEvents({ events, lastBlock }) { async saveEvents({
newEvents,
lastBlock
}) {
await saveDBEvents({ await saveDBEvents({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock lastBlock
}); });
} }
@ -3572,11 +3647,11 @@ class DBRevenueService extends BaseRevenueService {
zipDigest: this.zipDigest zipDigest: this.zipDigest
}); });
} }
async saveEvents({ events, lastBlock }) { async saveEvents({ newEvents, lastBlock }) {
await saveDBEvents({ await saveDBEvents({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock lastBlock
}); });
} }
@ -9319,7 +9394,7 @@ class TornadoFeeOracle {
* (A single block can bump 12.5% of fees, see the methodology https://hackmd.io/@tvanepps/1559-wallets) * (A single block can bump 12.5% of fees, see the methodology https://hackmd.io/@tvanepps/1559-wallets)
* (Still it is recommended to use 100% premium for sending transactions to prevent stucking it) * (Still it is recommended to use 100% premium for sending transactions to prevent stucking it)
*/ */
async gasPrice() { async gasPrice(premium) {
const [block, getGasPrice, getPriorityFee] = await Promise.all([ const [block, getGasPrice, getPriorityFee] = await Promise.all([
this.provider.getBlock("latest"), this.provider.getBlock("latest"),
(async () => { (async () => {
@ -9337,7 +9412,7 @@ class TornadoFeeOracle {
} }
})() })()
]); ]);
return block?.baseFeePerGas ? block.baseFeePerGas * BigInt(15) / BigInt(10) + getPriorityFee : getGasPrice; return block?.baseFeePerGas ? block.baseFeePerGas * BigInt(1e4 * (100 + (premium || 50))) / BigInt(1e4 * 100) + getPriorityFee : getGasPrice;
} }
/** /**
* Calculate L1 fee for op-stack chains * Calculate L1 fee for op-stack chains
@ -9480,7 +9555,7 @@ class IndexedDB {
} }
}; };
this.dbName = dbName; this.dbName = dbName;
this.dbVersion = 35; this.dbVersion = 36;
} }
async initDB() { async initDB() {
try { try {
@ -9676,15 +9751,16 @@ async function getIndexedDB(netId) {
} }
const minimalIndexes = [ const minimalIndexes = [
{ {
name: "blockNumber", name: "eid",
unique: false unique: true
},
{
name: "transactionHash",
unique: false
} }
]; ];
const defaultState = [ const defaultState = [
{
name: `tornado_${netId}`,
keyPath: "eid",
indexes: [...minimalIndexes]
},
{ {
name: `echo_${netId}`, name: `echo_${netId}`,
keyPath: "eid", keyPath: "eid",
@ -9712,8 +9788,7 @@ async function getIndexedDB(netId) {
] ]
} }
]; ];
const config = getConfig(netId); const { tokens, nativeCurrency, registryContract, governanceContract } = getConfig(netId);
const { tokens, nativeCurrency, registryContract, governanceContract } = config;
const stores = [...defaultState]; const stores = [...defaultState];
if (registryContract) { if (registryContract) {
stores.push({ stores.push({
@ -10605,4 +10680,4 @@ async function calculateSnarkProof(input, circuit, provingKey) {
return { proof, args }; return { proof, args };
} }
export { BaseEchoService, BaseEncryptedNotesService, BaseEventsService, BaseGovernanceService, BaseMultiTornadoService, BaseRegistryService, BaseRevenueService, BaseTornadoService, BatchBlockService, BatchEventsService, BatchTransactionService, DBEchoService, DBEncryptedNotesService, DBGovernanceService, DBRegistryService, DBRevenueService, DBTornadoService, Deposit, ENSNameWrapper__factory, ENSRegistry__factory, ENSResolver__factory, ENSUtils, ENS__factory, ERC20__factory, EnsContracts, INDEX_DB_ERROR, IndexedDB, Invoice, MAX_FEE, MAX_TOVARISH_EVENTS, MIN_FEE, MIN_STAKE_BALANCE, MerkleTreeService, Mimc, Multicall__factory, NetId, NoteAccount, OffchainOracle__factory, OvmGasPriceOracle__factory, Pedersen, RelayerClient, ReverseRecords__factory, TokenPriceOracle, TornadoBrowserProvider, TornadoFeeOracle, TornadoRpcSigner, TornadoVoidSigner, TornadoWallet, TovarishClient, addNetwork, addressSchemaType, ajv, base64ToBytes, bigIntReplacer, bnSchemaType, bnToBytes, buffPedersenHash, bufferToBytes, bytes32BNSchemaType, bytes32SchemaType, bytesToBN, bytesToBase64, bytesToHex, calculateScore, calculateSnarkProof, chunk, concatBytes, convertETHToTokenAmount, createDeposit, crypto, customConfig, defaultConfig, defaultUserAgent, deployHasher, depositsEventsSchema, digest, downloadZip, echoEventsSchema, enabledChains, encodedLabelToLabelhash, encryptedNotesSchema, index as factories, fetchData, fetchGetUrlFunc, fetchIp, fromContentHash, gasZipID, gasZipInbounds, gasZipInput, gasZipMinMax, getActiveTokenInstances, getActiveTokens, getConfig, getEventsSchemaValidator, getHttpAgent, getIndexedDB, getInstanceByAddress, getMultiInstances, getNetworkConfig, getPermit2CommitmentsSignature, getPermit2Signature, getPermitCommitmentsSignature, getPermitSignature, getProvider, getProviderWithNetId, getRelayerEnsSubdomains, getStatusSchema, getSubInfo, getSupportedInstances, getTokenBalances, getTovarishNetworks, getWeightRandom, governanceEventsSchema, hasherBytecode, hexToBytes, initGroth16, isHex, isNode, jobRequestSchema, jobsSchema, labelhash, leBuff2Int, leInt2Buff, loadDBEvents, loadRemoteEvents, makeLabelNodeAndParent, mimc, multiQueryFilter, multicall, numberFormatter, packEncryptedMessage, parseInvoice, parseNote, pedersen, permit2Address, pickWeightedRandomRelayer, populateTransaction, proofSchemaType, proposalState, rBigInt, rHex, relayerRegistryEventsSchema, saveDBEvents, sleep, stakeBurnedEventsSchema, substring, toContentHash, toFixedHex, toFixedLength, tornadoEventsSchema, unpackEncryptedMessage, unzipAsync, validateUrl, withdrawalsEventsSchema, zipAsync }; export { BaseEchoService, BaseEncryptedNotesService, BaseEventsService, BaseGovernanceService, BaseMultiTornadoService, BaseRegistryService, BaseRevenueService, BaseTornadoService, BatchBlockService, BatchEventsService, BatchTransactionService, DBEchoService, DBEncryptedNotesService, DBGovernanceService, DBMultiTornadoService, DBRegistryService, DBRevenueService, DBTornadoService, Deposit, ENSNameWrapper__factory, ENSRegistry__factory, ENSResolver__factory, ENSUtils, ENS__factory, ERC20__factory, EnsContracts, INDEX_DB_ERROR, IndexedDB, Invoice, MAX_FEE, MAX_TOVARISH_EVENTS, MIN_FEE, MIN_STAKE_BALANCE, MerkleTreeService, Mimc, Multicall__factory, NetId, NoteAccount, OffchainOracle__factory, OvmGasPriceOracle__factory, Pedersen, RelayerClient, ReverseRecords__factory, TokenPriceOracle, TornadoBrowserProvider, TornadoFeeOracle, TornadoRpcSigner, TornadoVoidSigner, TornadoWallet, TovarishClient, addNetwork, addressSchemaType, ajv, base64ToBytes, bigIntReplacer, bnSchemaType, bnToBytes, buffPedersenHash, bufferToBytes, bytes32BNSchemaType, bytes32SchemaType, bytesToBN, bytesToBase64, bytesToHex, calculateScore, calculateSnarkProof, chunk, concatBytes, convertETHToTokenAmount, createDeposit, crypto, customConfig, defaultConfig, defaultUserAgent, deployHasher, depositsEventsSchema, digest, downloadZip, echoEventsSchema, enabledChains, encodedLabelToLabelhash, encryptedNotesSchema, index as factories, fetchData, fetchGetUrlFunc, fetchIp, fromContentHash, gasZipID, gasZipInbounds, gasZipInput, gasZipMinMax, getActiveTokenInstances, getActiveTokens, getConfig, getEventsSchemaValidator, getHttpAgent, getIndexedDB, getInstanceByAddress, getMultiInstances, getNetworkConfig, getPermit2CommitmentsSignature, getPermit2Signature, getPermitCommitmentsSignature, getPermitSignature, getProvider, getProviderWithNetId, getRelayerEnsSubdomains, getStatusSchema, getSubInfo, getSupportedInstances, getTokenBalances, getTovarishNetworks, getWeightRandom, governanceEventsSchema, hasherBytecode, hexToBytes, initGroth16, isHex, isNode, jobRequestSchema, jobsSchema, labelhash, leBuff2Int, leInt2Buff, loadDBEvents, loadRemoteEvents, makeLabelNodeAndParent, mimc, multiQueryFilter, multicall, numberFormatter, packEncryptedMessage, parseInvoice, parseNote, pedersen, permit2Address, pickWeightedRandomRelayer, populateTransaction, proofSchemaType, proposalState, rBigInt, rHex, relayerRegistryEventsSchema, saveDBEvents, sleep, stakeBurnedEventsSchema, substring, toContentHash, toFixedHex, toFixedLength, tornadoEventsSchema, unpackEncryptedMessage, unzipAsync, validateUrl, withdrawalsEventsSchema, zipAsync };

@ -31,6 +31,7 @@ export interface TornadoInstance {
instanceAddress: { instanceAddress: {
[key: string]: string; [key: string]: string;
}; };
instanceApproval?: boolean;
optionalInstances?: string[]; optionalInstances?: string[];
tokenAddress?: string; tokenAddress?: string;
tokenGasLimit?: number; tokenGasLimit?: number;

129
dist/tornado.umd.js vendored

@ -92585,7 +92585,10 @@ class BaseMultiTornadoService extends BaseEventsService {
} }
return acc; return acc;
}, },
{} {
depositEvents: [],
withdrawalEvents: []
}
); );
return { return {
depositEvents, depositEvents,
@ -93222,6 +93225,7 @@ RevenueService: Mismatch on withdrawal logs (${withdrawalLogs.length} ) and even
/* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ $B: () => (/* binding */ DBEncryptedNotesService), /* harmony export */ $B: () => (/* binding */ DBEncryptedNotesService),
/* harmony export */ Aq: () => (/* binding */ DBGovernanceService), /* harmony export */ Aq: () => (/* binding */ DBGovernanceService),
/* harmony export */ C_: () => (/* binding */ DBMultiTornadoService),
/* harmony export */ Fb: () => (/* binding */ saveDBEvents), /* harmony export */ Fb: () => (/* binding */ saveDBEvents),
/* harmony export */ Oz: () => (/* binding */ loadRemoteEvents), /* harmony export */ Oz: () => (/* binding */ loadRemoteEvents),
/* harmony export */ f8: () => (/* binding */ DBTornadoService), /* harmony export */ f8: () => (/* binding */ DBTornadoService),
@ -93242,11 +93246,11 @@ RevenueService: Mismatch on withdrawal logs (${withdrawalLogs.length} ) and even
async function saveDBEvents({ async function saveDBEvents({
idb, idb,
instanceName, instanceName,
events, newEvents,
lastBlock lastBlock
}) { }) {
try { try {
const formattedEvents = events.map((e) => { const formattedEvents = newEvents.map((e) => {
return { return {
eid: `${e.transactionHash}_${e.logIndex}`, eid: `${e.transactionHash}_${e.logIndex}`,
...e ...e
@ -93357,11 +93361,49 @@ class DBTornadoService extends _base__WEBPACK_IMPORTED_MODULE_3__/* .BaseTornado
zipDigest: this.zipDigest zipDigest: this.zipDigest
}); });
} }
async saveEvents({ events, lastBlock }) { async saveEvents({
newEvents,
lastBlock
}) {
await saveDBEvents({ await saveDBEvents({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock
});
}
}
class DBMultiTornadoService extends _base__WEBPACK_IMPORTED_MODULE_3__/* .BaseMultiTornadoService */ .lG {
staticUrl;
idb;
zipDigest;
constructor(params) {
super(params);
this.staticUrl = params.staticUrl;
this.idb = params.idb;
}
async getEventsFromDB() {
return await loadDBEvents({
idb: this.idb,
instanceName: this.getInstanceName()
});
}
async getEventsFromCache() {
return await loadRemoteEvents({
staticUrl: this.staticUrl,
instanceName: this.getInstanceName(),
deployedBlock: this.deployedBlock,
zipDigest: this.zipDigest
});
}
async saveEvents({
newEvents,
lastBlock
}) {
await saveDBEvents({
idb: this.idb,
instanceName: this.getInstanceName(),
newEvents,
lastBlock lastBlock
}); });
} }
@ -93389,11 +93431,11 @@ class DBEchoService extends _base__WEBPACK_IMPORTED_MODULE_3__/* .BaseEchoServic
zipDigest: this.zipDigest zipDigest: this.zipDigest
}); });
} }
async saveEvents({ events, lastBlock }) { async saveEvents({ newEvents, lastBlock }) {
await saveDBEvents({ await saveDBEvents({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock lastBlock
}); });
} }
@ -93421,11 +93463,14 @@ class DBEncryptedNotesService extends _base__WEBPACK_IMPORTED_MODULE_3__/* .Base
zipDigest: this.zipDigest zipDigest: this.zipDigest
}); });
} }
async saveEvents({ events, lastBlock }) { async saveEvents({
newEvents,
lastBlock
}) {
await saveDBEvents({ await saveDBEvents({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock lastBlock
}); });
} }
@ -93453,11 +93498,11 @@ class DBGovernanceService extends _base__WEBPACK_IMPORTED_MODULE_3__/* .BaseGove
zipDigest: this.zipDigest zipDigest: this.zipDigest
}); });
} }
async saveEvents({ events, lastBlock }) { async saveEvents({ newEvents, lastBlock }) {
await saveDBEvents({ await saveDBEvents({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock lastBlock
}); });
} }
@ -93486,11 +93531,14 @@ class DBRegistryService extends _base__WEBPACK_IMPORTED_MODULE_3__/* .BaseRegist
zipDigest: this.zipDigest zipDigest: this.zipDigest
}); });
} }
async saveEvents({ events, lastBlock }) { async saveEvents({
newEvents,
lastBlock
}) {
await saveDBEvents({ await saveDBEvents({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock lastBlock
}); });
} }
@ -93579,11 +93627,11 @@ class DBRevenueService extends _base__WEBPACK_IMPORTED_MODULE_3__/* .BaseRevenue
zipDigest: this.zipDigest zipDigest: this.zipDigest
}); });
} }
async saveEvents({ events, lastBlock }) { async saveEvents({ newEvents, lastBlock }) {
await saveDBEvents({ await saveDBEvents({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock lastBlock
}); });
} }
@ -93609,6 +93657,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ DBEchoService: () => (/* reexport safe */ _db__WEBPACK_IMPORTED_MODULE_2__.xc), /* harmony export */ DBEchoService: () => (/* reexport safe */ _db__WEBPACK_IMPORTED_MODULE_2__.xc),
/* harmony export */ DBEncryptedNotesService: () => (/* reexport safe */ _db__WEBPACK_IMPORTED_MODULE_2__.$B), /* harmony export */ DBEncryptedNotesService: () => (/* reexport safe */ _db__WEBPACK_IMPORTED_MODULE_2__.$B),
/* harmony export */ DBGovernanceService: () => (/* reexport safe */ _db__WEBPACK_IMPORTED_MODULE_2__.Aq), /* harmony export */ DBGovernanceService: () => (/* reexport safe */ _db__WEBPACK_IMPORTED_MODULE_2__.Aq),
/* harmony export */ DBMultiTornadoService: () => (/* reexport safe */ _db__WEBPACK_IMPORTED_MODULE_2__.C_),
/* harmony export */ DBRegistryService: () => (/* reexport safe */ _db__WEBPACK_IMPORTED_MODULE_2__.hD), /* harmony export */ DBRegistryService: () => (/* reexport safe */ _db__WEBPACK_IMPORTED_MODULE_2__.hD),
/* harmony export */ DBRevenueService: () => (/* reexport safe */ _db__WEBPACK_IMPORTED_MODULE_2__.wV), /* harmony export */ DBRevenueService: () => (/* reexport safe */ _db__WEBPACK_IMPORTED_MODULE_2__.wV),
/* harmony export */ DBTornadoService: () => (/* reexport safe */ _db__WEBPACK_IMPORTED_MODULE_2__.f8), /* harmony export */ DBTornadoService: () => (/* reexport safe */ _db__WEBPACK_IMPORTED_MODULE_2__.f8),
@ -93677,7 +93726,7 @@ class TornadoFeeOracle {
* (A single block can bump 12.5% of fees, see the methodology https://hackmd.io/@tvanepps/1559-wallets) * (A single block can bump 12.5% of fees, see the methodology https://hackmd.io/@tvanepps/1559-wallets)
* (Still it is recommended to use 100% premium for sending transactions to prevent stucking it) * (Still it is recommended to use 100% premium for sending transactions to prevent stucking it)
*/ */
async gasPrice() { async gasPrice(premium) {
const [block, getGasPrice, getPriorityFee] = await Promise.all([ const [block, getGasPrice, getPriorityFee] = await Promise.all([
this.provider.getBlock("latest"), this.provider.getBlock("latest"),
(async () => { (async () => {
@ -93695,7 +93744,7 @@ class TornadoFeeOracle {
} }
})() })()
]); ]);
return block?.baseFeePerGas ? block.baseFeePerGas * BigInt(15) / BigInt(10) + getPriorityFee : getGasPrice; return block?.baseFeePerGas ? block.baseFeePerGas * BigInt(1e4 * (100 + (premium || 50))) / BigInt(1e4 * 100) + getPriorityFee : getGasPrice;
} }
/** /**
* Calculate L1 fee for op-stack chains * Calculate L1 fee for op-stack chains
@ -94196,7 +94245,7 @@ class IndexedDB {
} }
}; };
this.dbName = dbName; this.dbName = dbName;
this.dbVersion = 35; this.dbVersion = 36;
} }
async initDB() { async initDB() {
try { try {
@ -94392,15 +94441,16 @@ async function getIndexedDB(netId) {
} }
const minimalIndexes = [ const minimalIndexes = [
{ {
name: "blockNumber", name: "eid",
unique: false unique: true
},
{
name: "transactionHash",
unique: false
} }
]; ];
const defaultState = [ const defaultState = [
{
name: `tornado_${netId}`,
keyPath: "eid",
indexes: [...minimalIndexes]
},
{ {
name: `echo_${netId}`, name: `echo_${netId}`,
keyPath: "eid", keyPath: "eid",
@ -94428,8 +94478,7 @@ async function getIndexedDB(netId) {
] ]
} }
]; ];
const config = (0,networkConfig/* getConfig */.zj)(netId); const { tokens, nativeCurrency, registryContract, governanceContract } = (0,networkConfig/* getConfig */.zj)(netId);
const { tokens, nativeCurrency, registryContract, governanceContract } = config;
const stores = [...defaultState]; const stores = [...defaultState];
if (registryContract) { if (registryContract) {
stores.push({ stores.push({
@ -95015,6 +95064,34 @@ const defaultConfig = {
}, },
symbol: "BNB", symbol: "BNB",
decimals: 18 decimals: 18
},
usdt: {
instanceAddress: {
"10": "0x261fB4f84bb0BdEe7E035B6a8a08e5c35AdacdDD",
"100": "0x3957861d4897d883C9b944C0b4E22bBd0DDE6e21",
"1000": "0x6D180403AdFb39F70983eB51A033C5e52eb9BB69",
"10000": "0x3722662D8AaB07B216B14C02eF0ee940d14A4200"
},
instanceApproval: true,
tokenAddress: "0x55d398326f99059fF775485246999027B3197955",
tokenGasLimit: 7e4,
symbol: "USDT",
decimals: 18,
gasLimit: 7e5
},
btcb: {
instanceAddress: {
"0.0001": "0x736dABbFc8101Ae75287104eCcf67e45D7369Ae1",
"0.001": "0x82c7Ce6f1F158cEC5536d591a2BC19864b3CA823",
"0.01": "0x8284c96679037d8081E498d8F767cA5a140BFAAf",
"0.1": "0x2bcD128Ce23ee30Ee945E613ff129c4DE1102C79"
},
instanceApproval: true,
tokenAddress: "0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c",
tokenGasLimit: 7e4,
symbol: "BTCB",
decimals: 18,
gasLimit: 7e5
} }
}, },
relayerEnsSubdomain: "bsc-tornado", relayerEnsSubdomain: "bsc-tornado",

File diff suppressed because one or more lines are too long

@ -613,9 +613,9 @@ export class BaseMultiTornadoService extends BaseEventsService<MultiDepositsEven
} }
return acc; return acc;
}, },
{} as { {
depositEvents: MultiDepositsEvents[]; depositEvents: [] as MultiDepositsEvents[],
withdrawalEvents: MultiWithdrawalsEvents[]; withdrawalEvents: [] as MultiWithdrawalsEvents[],
}, },
); );

@ -17,6 +17,8 @@ import {
BaseRevenueService, BaseRevenueService,
BaseRevenueServiceConstructor, BaseRevenueServiceConstructor,
CachedRelayers, CachedRelayers,
BaseMultiTornadoService,
BaseMultiTornadoServiceConstructor,
} from './base'; } from './base';
import { import {
@ -30,21 +32,23 @@ import {
AllGovernanceEvents, AllGovernanceEvents,
AllRelayerRegistryEvents, AllRelayerRegistryEvents,
StakeBurnedEvents, StakeBurnedEvents,
MultiDepositsEvents,
MultiWithdrawalsEvents,
} from './types'; } from './types';
export async function saveDBEvents<T extends MinimalEvents>({ export async function saveDBEvents<T extends MinimalEvents>({
idb, idb,
instanceName, instanceName,
events, newEvents,
lastBlock, lastBlock,
}: { }: {
idb: IndexedDB; idb: IndexedDB;
instanceName: string; instanceName: string;
events: T[]; newEvents: T[];
lastBlock: number; lastBlock: number;
}) { }) {
try { try {
const formattedEvents = events.map((e) => { const formattedEvents = newEvents.map((e) => {
return { return {
eid: `${e.transactionHash}_${e.logIndex}`, eid: `${e.transactionHash}_${e.logIndex}`,
...e, ...e,
@ -192,11 +196,63 @@ export class DBTornadoService extends BaseTornadoService {
}); });
} }
async saveEvents({ events, lastBlock }: BaseEvents<DepositsEvents | WithdrawalsEvents>) { async saveEvents({
newEvents,
lastBlock,
}: BaseEvents<DepositsEvents | WithdrawalsEvents> & { newEvents: (DepositsEvents | WithdrawalsEvents)[] }) {
await saveDBEvents<DepositsEvents | WithdrawalsEvents>({ await saveDBEvents<DepositsEvents | WithdrawalsEvents>({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock,
});
}
}
export interface DBMultiTornadoServiceConstructor extends BaseMultiTornadoServiceConstructor {
staticUrl: string;
idb: IndexedDB;
}
export class DBMultiTornadoService extends BaseMultiTornadoService {
staticUrl: string;
idb: IndexedDB;
zipDigest?: string;
constructor(params: DBMultiTornadoServiceConstructor) {
super(params);
this.staticUrl = params.staticUrl;
this.idb = params.idb;
}
async getEventsFromDB() {
return await loadDBEvents<MultiDepositsEvents | MultiWithdrawalsEvents>({
idb: this.idb,
instanceName: this.getInstanceName(),
});
}
async getEventsFromCache() {
return await loadRemoteEvents<MultiDepositsEvents | MultiWithdrawalsEvents>({
staticUrl: this.staticUrl,
instanceName: this.getInstanceName(),
deployedBlock: this.deployedBlock,
zipDigest: this.zipDigest,
});
}
async saveEvents({
newEvents,
lastBlock,
}: BaseEvents<MultiDepositsEvents | MultiWithdrawalsEvents> & {
newEvents: (MultiDepositsEvents | MultiWithdrawalsEvents)[];
}) {
await saveDBEvents<MultiDepositsEvents | MultiWithdrawalsEvents>({
idb: this.idb,
instanceName: this.getInstanceName(),
newEvents,
lastBlock, lastBlock,
}); });
} }
@ -236,11 +292,11 @@ export class DBEchoService extends BaseEchoService {
}); });
} }
async saveEvents({ events, lastBlock }: BaseEvents<EchoEvents>) { async saveEvents({ newEvents, lastBlock }: BaseEvents<EchoEvents> & { newEvents: EchoEvents[] }) {
await saveDBEvents<EchoEvents>({ await saveDBEvents<EchoEvents>({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock, lastBlock,
}); });
} }
@ -280,11 +336,14 @@ export class DBEncryptedNotesService extends BaseEncryptedNotesService {
}); });
} }
async saveEvents({ events, lastBlock }: BaseEvents<EncryptedNotesEvents>) { async saveEvents({
newEvents,
lastBlock,
}: BaseEvents<EncryptedNotesEvents> & { newEvents: EncryptedNotesEvents[] }) {
await saveDBEvents<EncryptedNotesEvents>({ await saveDBEvents<EncryptedNotesEvents>({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock, lastBlock,
}); });
} }
@ -324,11 +383,11 @@ export class DBGovernanceService extends BaseGovernanceService {
}); });
} }
async saveEvents({ events, lastBlock }: BaseEvents<AllGovernanceEvents>) { async saveEvents({ newEvents, lastBlock }: BaseEvents<AllGovernanceEvents> & { newEvents: AllGovernanceEvents[] }) {
await saveDBEvents<AllGovernanceEvents>({ await saveDBEvents<AllGovernanceEvents>({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock, lastBlock,
}); });
} }
@ -369,11 +428,14 @@ export class DBRegistryService extends BaseRegistryService {
}); });
} }
async saveEvents({ events, lastBlock }: BaseEvents<AllRelayerRegistryEvents>) { async saveEvents({
newEvents,
lastBlock,
}: BaseEvents<AllRelayerRegistryEvents> & { newEvents: AllRelayerRegistryEvents[] }) {
await saveDBEvents<AllRelayerRegistryEvents>({ await saveDBEvents<AllRelayerRegistryEvents>({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock, lastBlock,
}); });
} }
@ -486,11 +548,11 @@ export class DBRevenueService extends BaseRevenueService {
}); });
} }
async saveEvents({ events, lastBlock }: BaseEvents<StakeBurnedEvents>) { async saveEvents({ newEvents, lastBlock }: BaseEvents<StakeBurnedEvents> & { newEvents: StakeBurnedEvents[] }) {
await saveDBEvents<StakeBurnedEvents>({ await saveDBEvents<StakeBurnedEvents>({
idb: this.idb, idb: this.idb,
instanceName: this.getInstanceName(), instanceName: this.getInstanceName(),
events, newEvents,
lastBlock, lastBlock,
}); });
} }

@ -55,7 +55,7 @@ export class TornadoFeeOracle {
* (A single block can bump 12.5% of fees, see the methodology https://hackmd.io/@tvanepps/1559-wallets) * (A single block can bump 12.5% of fees, see the methodology https://hackmd.io/@tvanepps/1559-wallets)
* (Still it is recommended to use 100% premium for sending transactions to prevent stucking it) * (Still it is recommended to use 100% premium for sending transactions to prevent stucking it)
*/ */
async gasPrice() { async gasPrice(premium?: number) {
const [block, getGasPrice, getPriorityFee] = await Promise.all([ const [block, getGasPrice, getPriorityFee] = await Promise.all([
this.provider.getBlock('latest'), this.provider.getBlock('latest'),
(async () => { (async () => {
@ -74,7 +74,9 @@ export class TornadoFeeOracle {
})(), })(),
]); ]);
return block?.baseFeePerGas ? (block.baseFeePerGas * BigInt(15)) / BigInt(10) + getPriorityFee : getGasPrice; return block?.baseFeePerGas
? (block.baseFeePerGas * BigInt(10000 * (100 + (premium || 50)))) / BigInt(10000 * 100) + getPriorityFee
: getGasPrice;
} }
/** /**

@ -55,7 +55,7 @@ export class IndexedDB {
}; };
this.dbName = dbName; this.dbName = dbName;
this.dbVersion = 35; this.dbVersion = 36;
} }
async initDB() { async initDB() {
@ -324,16 +324,17 @@ export async function getIndexedDB(netId?: NetIdType) {
const minimalIndexes = [ const minimalIndexes = [
{ {
name: 'blockNumber', name: 'eid',
unique: false, unique: true,
},
{
name: 'transactionHash',
unique: false,
}, },
]; ];
const defaultState = [ const defaultState = [
{
name: `tornado_${netId}`,
keyPath: 'eid',
indexes: [...minimalIndexes],
},
{ {
name: `echo_${netId}`, name: `echo_${netId}`,
keyPath: 'eid', keyPath: 'eid',
@ -362,9 +363,7 @@ export async function getIndexedDB(netId?: NetIdType) {
}, },
]; ];
const config = getConfig(netId); const { tokens, nativeCurrency, registryContract, governanceContract } = getConfig(netId);
const { tokens, nativeCurrency, registryContract, governanceContract } = config;
const stores = [...defaultState]; const stores = [...defaultState];

@ -38,6 +38,7 @@ export interface TornadoInstance {
instanceAddress: { instanceAddress: {
[key: string]: string; [key: string]: string;
}; };
instanceApproval?: boolean;
optionalInstances?: string[]; optionalInstances?: string[];
tokenAddress?: string; tokenAddress?: string;
tokenGasLimit?: number; tokenGasLimit?: number;
@ -303,6 +304,34 @@ export const defaultConfig: networkConfig = {
symbol: 'BNB', symbol: 'BNB',
decimals: 18, decimals: 18,
}, },
usdt: {
instanceAddress: {
'10': '0x261fB4f84bb0BdEe7E035B6a8a08e5c35AdacdDD',
'100': '0x3957861d4897d883C9b944C0b4E22bBd0DDE6e21',
'1000': '0x6D180403AdFb39F70983eB51A033C5e52eb9BB69',
'10000': '0x3722662D8AaB07B216B14C02eF0ee940d14A4200',
},
instanceApproval: true,
tokenAddress: '0x55d398326f99059fF775485246999027B3197955',
tokenGasLimit: 70_000,
symbol: 'USDT',
decimals: 18,
gasLimit: 700_000,
},
btcb: {
instanceAddress: {
'0.0001': '0x736dABbFc8101Ae75287104eCcf67e45D7369Ae1',
'0.001': '0x82c7Ce6f1F158cEC5536d591a2BC19864b3CA823',
'0.01': '0x8284c96679037d8081E498d8F767cA5a140BFAAf',
'0.1': '0x2bcD128Ce23ee30Ee945E613ff129c4DE1102C79',
},
instanceApproval: true,
tokenAddress: '0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c',
tokenGasLimit: 70_000,
symbol: 'BTCB',
decimals: 18,
gasLimit: 700_000,
},
}, },
relayerEnsSubdomain: 'bsc-tornado', relayerEnsSubdomain: 'bsc-tornado',
pollInterval: 10, pollInterval: 10,