0.0.8-alpha

Signed-off-by: T-Hax <>
This commit is contained in:
T-Hax 2023-05-11 18:49:07 +00:00
parent efdc55df2c
commit 798598cfff
37 changed files with 835 additions and 188 deletions

View file

@ -13,7 +13,7 @@
"crypto",
"zk"
],
"version": "0.0.7-alpha",
"version": "0.0.8-alpha",
"engines": {
"node": "^18"
},
@ -83,6 +83,5 @@
"tsconfig-paths@4.2.0": {
"unplugged": true
}
},
"stableVersion": "2023.04.28"
}
}

View file

@ -131,9 +131,14 @@ type RelayerProperties = MarkOptional<
export class Core extends Synchronizer {
private _mutex: AsyncUtils.SimpleMutex
private _chain?: Chain
caches: Map<string, Cache.Base<Docs.Base>>
chain?: Chain
get chain(): Chain {
this._checkProvider('chain')
return this._chain!
}
constructor() {
super()
@ -143,33 +148,31 @@ export class Core extends Synchronizer {
private _checkProvider(parentCallName: string): void {
try {
this.chain?.id
this._chain?.id
} catch (err) {
throw ErrorUtils.getError('Core.' + parentCallName + ': you must first connect a provider!')
}
}
async connect(provider: Provider): Promise<void> {
if (!this.chain) this.chain = new Chain(provider)
else this.chain.provider = provider
await this.chain.fetchChainData()
if (!this._chain) this._chain = new Chain(provider)
else this._chain.provider = provider
await this._chain.fetchChainData()
}
getInstances(keys: Array<{ token: string; denomination: number | string }>): Array<TornadoInstance> {
this._checkProvider('getInstances')
return keys.map((key) =>
Contracts.getInstance(String(this.chain!.id), key.token, String(key.denomination), this.chain!.provider)
Contracts.getInstance(String(this.chain.id), key.token, String(key.denomination), this.chain.provider)
)
}
getInstance(token: string, denomination: number | string): TornadoInstance {
this._checkProvider('getInstance')
return this.loadInstance(this.chain!.id, token, denomination)
return this.loadInstance(this.chain.id, token, denomination)
}
getProxy(): TornadoProxy {
this._checkProvider('getProxy')
return Contracts.getProxy(String(this.chain!.id), this.chain!.provider)
return Contracts.getProxy(String(this.chain.id), this.chain.provider)
}
async buildDepositProof(
@ -297,7 +300,7 @@ export class Core extends Synchronizer {
// Rest of note invariant arguments
const inputsForProofs: InputFor.ZKProof[] = []
const gasPrice = options?.gasPrice ?? (await this.chain!.getGasPrice())
const gasPrice = options?.gasPrice ?? (await this.chain.getGasPrice())
const gasPriceCushion = options?.gasPrice ?? gasPrice.mul(10).div(100)
// In reality, if a manual withdraw is made, we don't differentiate it from a relayer withdraw
@ -313,7 +316,7 @@ export class Core extends Synchronizer {
.mul(decimals)
.div(10 ** denomination.length)
const native = token == this.chain!.symbol
const native = token == this.chain.symbol
if (!tokenPrice && !native)
throw ErrorUtils.getError(
@ -588,8 +591,6 @@ export class Core extends Synchronizer {
instances: Array<TornadoInstance>,
options?: Options.Core.Deposit
): Array<Transactions.Deposit> {
this._checkProvider('buildDepositTransactions')
const depositsPerInstance = options?.depositsPerInstance ?? new Array<number>(instances.length).fill(1)
const doNotPopulate = options?.doNotPopulate ?? false
@ -599,9 +600,9 @@ export class Core extends Synchronizer {
'Core.buildDepositTx: number of deposit amount elements must equal the number of instances!'
)
const chainId = this.chain!.id
const chainId = this.chain.id
const proxy: TornadoProxy = Contracts.getProxy(String(chainId), this.chain!.provider)
const proxy: TornadoProxy = Contracts.getProxy(String(chainId), this.chain.provider)
const txs: Array<Transactions.Deposit> = []
@ -699,6 +700,11 @@ export class Core extends Synchronizer {
release()
}
async exportAsArchive(cacheName: string, outDirPath?: string, debug?: boolean): Promise<void> {
const cache = this.loadCache<Cache.Base<Docs.Base>>(cacheName)
await cache.exportAsArchive(outDirPath, debug)
}
loadDepositCache(name: string, options?: Options.Sync): DepositCache {
if (!this.caches.has(name)) {
this.caches.set(
@ -740,7 +746,7 @@ export class Core extends Synchronizer {
loadInstance(chainId: number | string, token: string, denomination: number | string): TornadoInstance {
token = token.toLowerCase()
return Contracts.getInstance('' + chainId, token, '' + denomination, this.chain!.provider)
return Contracts.getInstance('' + chainId, token, '' + denomination, this.chain.provider)
}
async syncDeposits(instance: TornadoInstance, options?: Options.Sync): Promise<void> {
@ -788,7 +794,7 @@ export class Core extends Synchronizer {
protected async _populateSyncOptions(options: Options.Sync): Promise<DeepRequired<Options.Sync>> {
if (!options.startBlock) throw ErrorUtils.getError('Core._populateSyncOptions: startBlock not set.')
options.targetBlock = options.targetBlock ?? (await this.chain!.latestBlockNum())
options.targetBlock = options.targetBlock ?? (await this.chain.latestBlockNum())
options.blockDivisor = options.blockDivisor ?? 40