diff --git a/src/BalanceGuard.ts b/src/BalanceGuard.ts index 2496040..f18decd 100644 --- a/src/BalanceGuard.ts +++ b/src/BalanceGuard.ts @@ -27,16 +27,20 @@ export default class BalanceGuard { private readonly signer: ethers.Signer; + private readonly logger?: (message: string) => void; + constructor( balances: Partial>>, nativeCryptocurrency: Asset, provider: ethers.providers.Provider, signer: ethers.Signer, + logger?: (message: string) => void, ) { this.balances = balances; this.nativeCryptocurrency = nativeCryptocurrency; this.provider = provider; this.signer = signer; + this.logger = logger; } registerRequirement(expense: BalanceRequirement) { @@ -132,11 +136,12 @@ export default class BalanceGuard { const gasLimit = await this.provider.estimateGas(unsignedApproveTx); unsignedApproveTx.gasLimit = gasLimit; + this.logger?.('Approve transaction signing...'); const signedTx = await this.signer.signTransaction(unsignedApproveTx); const txResponse = await this.provider.sendTransaction(signedTx); - console.log(`${issue.asset.name} approve transaction sent ${txResponse.hash}. Waiting for confirmation...`); + this.logger?.(`${issue.asset.name} approve transaction sent ${txResponse.hash}. Waiting for confirmation...`); await txResponse.wait(); - console.log(`${issue.asset.name} approve transaction confirmed.`); + this.logger?.(`${issue.asset.name} approve transaction confirmed.`); }; await issue.fixes?.reduce(async (promise, item) => { await promise; @@ -156,7 +161,7 @@ export default class BalanceGuard { }; async check(fixAutofixable?: boolean) { - console.log(`Balance requirements: ${this.requirements + this.logger?.(`Balance requirements: ${this.requirements .map((requirement) => `${requirement.amount} ${requirement.asset.name} ` + `for '${requirement.reason}' ` + `from [${requirement.sources.join(' + ')}]`) diff --git a/src/OrionUnit/Exchange/swapMarket.ts b/src/OrionUnit/Exchange/swapMarket.ts index 9ce4faa..7ed7e1d 100644 --- a/src/OrionUnit/Exchange/swapMarket.ts +++ b/src/OrionUnit/Exchange/swapMarket.ts @@ -114,6 +114,7 @@ export default async function swapMarket({ }, provider, signer, + options?.logger, ); const swapInfo = await simpleFetch(orionAggregator.getSwapInfo)( @@ -231,8 +232,8 @@ export default async function swapMarket({ const nonce = await provider.getTransactionCount(walletAddress, 'pending'); unsignedSwapThroughOrionPoolTx.nonce = nonce; - const signedSwapThroughOrionPoolTx = await signer.signTransaction(unsignedSwapThroughOrionPoolTx); - const swapThroughOrionPoolTxResponse = await provider.sendTransaction(signedSwapThroughOrionPoolTx); + options?.logger?.('Signing transaction...'); + const swapThroughOrionPoolTxResponse = await signer.sendTransaction(unsignedSwapThroughOrionPoolTx); return { through: 'orion_pool', txHash: swapThroughOrionPoolTxResponse.hash,