From 2dbb3bcbee79f2d82f34d0cc7bb4ab975ecfadbb Mon Sep 17 00:00:00 2001 From: Nitin Mittal Date: Thu, 9 May 2024 01:08:55 +0400 Subject: [PATCH] new: compress claims --- package-lock.json | 14 +++--- package.json | 2 +- src/services/auto-claim.ts | 96 +++++++++++++++++++------------------- 3 files changed, 55 insertions(+), 57 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6670f76..1a3f888 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@maticnetwork/chain-indexer-framework": "^1.3.5", "axios": "^1.6.8", "dotenv": "^16.0.1", - "ethers": "^6.12.0", + "ethers": "^6.12.1", "long": "^5.2.0" }, "devDependencies": { @@ -6143,9 +6143,9 @@ } }, "node_modules/ethers": { - "version": "6.12.0", - "resolved": "https://registry.npmjs.org/ethers/-/ethers-6.12.0.tgz", - "integrity": "sha512-zL5NlOTjML239gIvtVJuaSk0N9GQLi1Hom3ZWUszE5lDTQE/IVB62mrPkQ2W1bGcZwVGSLaetQbWNQSvI4rGDQ==", + "version": "6.12.1", + "resolved": "https://registry.npmjs.org/ethers/-/ethers-6.12.1.tgz", + "integrity": "sha512-j6wcVoZf06nqEcBbDWkKg8Fp895SS96dSnTCjiXT+8vt2o02raTn4Lo9ERUuIVU5bAjoPYeA+7ytQFexFmLuVw==", "funding": [ { "type": "individual", @@ -16137,9 +16137,9 @@ } }, "ethers": { - "version": "6.12.0", - "resolved": "https://registry.npmjs.org/ethers/-/ethers-6.12.0.tgz", - "integrity": "sha512-zL5NlOTjML239gIvtVJuaSk0N9GQLi1Hom3ZWUszE5lDTQE/IVB62mrPkQ2W1bGcZwVGSLaetQbWNQSvI4rGDQ==", + "version": "6.12.1", + "resolved": "https://registry.npmjs.org/ethers/-/ethers-6.12.1.tgz", + "integrity": "sha512-j6wcVoZf06nqEcBbDWkKg8Fp895SS96dSnTCjiXT+8vt2o02raTn4Lo9ERUuIVU5bAjoPYeA+7ytQFexFmLuVw==", "requires": { "@adraffy/ens-normalize": "1.10.1", "@noble/curves": "1.2.0", diff --git a/package.json b/package.json index 2a6f414..a8efc42 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "@maticnetwork/chain-indexer-framework": "^1.3.5", "axios": "^1.6.8", "dotenv": "^16.0.1", - "ethers": "^6.12.0", + "ethers": "^6.12.1", "long": "^5.2.0" }, "devDependencies": { diff --git a/src/services/auto-claim.ts b/src/services/auto-claim.ts index 375ded0..089111d 100644 --- a/src/services/auto-claim.ts +++ b/src/services/auto-claim.ts @@ -35,41 +35,44 @@ export default class AutoClaimService { } async estimateGas(transaction: ITransaction, proof: IProof, globalIndex: BigInt): Promise { + let compressedClaimCalls = null; try { if (transaction.dataType === 'ERC20') { - await this.contract.estimateGas.compressClaimCall( + compressedClaimCalls = await this.contract.compressClaimCall( proof.main_exit_root, proof.rollup_exit_root, [{ - SmtProofLocalExitRoot: proof.merkle_proof, - SmtProofRollupExitRoot: proof.rollup_merkle_proof, - GlobalIndex: globalIndex.toString(), - OriginNetwork: transaction.originTokenNetwork, - OriginAddress: transaction.originTokenAddress, - DestinationAddress: transaction.receiver, - Amount: transaction.amounts ? transaction.amounts[0] : '0', - Metadata: transaction.metadata && transaction.metadata !== "" ? transaction.metadata : '0x', - IsMessage: false + smtProofLocalExitRoot: proof.merkle_proof, + smtProofRollupExitRoot: proof.rollup_merkle_proof, + globalIndex: globalIndex.toString(), + originNetwork: transaction.originTokenNetwork, + originAddress: transaction.originTokenAddress, + destinationAddress: transaction.receiver, + amount: transaction.amounts ? transaction.amounts[0] : '0', + metadata: transaction.metadata && transaction.metadata !== "" ? transaction.metadata : '0x', + isMessage: false }] ) - + } else { - await this.contract.estimateGas.compressClaimCall( + compressedClaimCalls = await this.contract.compressClaimCall.estimateGas( proof.main_exit_root, proof.rollup_exit_root, [{ - SmtProofLocalExitRoot: proof.merkle_proof, - SmtProofRollupExitRoot: proof.rollup_merkle_proof, - GlobalIndex: globalIndex.toString(), - OriginNetwork: '0', - OriginAddress: transaction.transactionInitiator, - DestinationAddress: transaction.receiver, - Amount: transaction.originTokenAddress ? '0' : transaction.amounts ? transaction.amounts[0] : '0', - Metadata: transaction.metadata && transaction.metadata !== "" ? transaction.metadata : '0x', - IsMessage: true + smtProofLocalExitRoot: proof.merkle_proof, + smtProofRollupExitRoot: proof.rollup_merkle_proof, + globalIndex: globalIndex.toString(), + originNetwork: '0', + originAddress: transaction.transactionInitiator, + destinationAddress: transaction.receiver, + amount: transaction.originTokenAddress ? '0' : transaction.amounts ? transaction.amounts[0] : '0', + metadata: transaction.metadata && transaction.metadata !== "" ? transaction.metadata : '0x', + isMessage: true }] ) } + + await this.contract.sendCompressedClaims.estimateGas(compressedClaimCalls); return true; } catch (error: any) { if (this.slackNotify) { @@ -89,7 +92,7 @@ export default class AutoClaimService { async claim(batch: { transaction: ITransaction, proof: IProof, globalIndex: BigInt }[]): Promise { const gasPrice = await this.gasStation.getGasPrice(); - let tx: ethers.TransactionResponse | null = null; + let response: ethers.TransactionResponse | null = null; try { Logger.info({ type: 'claimBatch', @@ -102,47 +105,48 @@ export default class AutoClaimService { for (const tx of batch) { if (tx.transaction.dataType === 'ERC20') { data.push({ - SmtProofLocalExitRoot: tx.proof.merkle_proof, - SmtProofRollupExitRoot: tx.proof.rollup_merkle_proof, - GlobalIndex: tx.globalIndex.toString(), - OriginNetwork: tx.transaction.originTokenNetwork, - OriginAddress: tx.transaction.originTokenAddress, - DestinationAddress: tx.transaction.receiver, - Amount: tx.transaction.amounts ? tx.transaction.amounts[0] : '0', - Metadata: tx.transaction.metadata && tx.transaction.metadata !== "" ? tx.transaction.metadata : '0x', - IsMessage: false + smtProofLocalExitRoot: tx.proof.merkle_proof, + smtProofRollupExitRoot: tx.proof.rollup_merkle_proof, + globalIndex: tx.globalIndex.toString(), + originNetwork: tx.transaction.originTokenNetwork, + originAddress: tx.transaction.originTokenAddress, + destinationAddress: tx.transaction.receiver, + amount: tx.transaction.amounts ? tx.transaction.amounts[0] : '0', + metadata: tx.transaction.metadata && tx.transaction.metadata !== "" ? tx.transaction.metadata : '0x', + isMessage: false }) } else { data.push({ - SmtProofLocalExitRoot: tx.proof.merkle_proof, - SmtProofRollupExitRoot: tx.proof.rollup_merkle_proof, - GlobalIndex: tx.globalIndex.toString(), - OriginNetwork: '0', - OriginAddress: tx.transaction.transactionInitiator, - DestinationAddress: tx.transaction.receiver, - Amount: tx.transaction.originTokenAddress ? '0' : tx.transaction.amounts ? tx.transaction.amounts[0] : '0', - Metadata: tx.transaction.metadata && tx.transaction.metadata !== "" ? tx.transaction.metadata : '0x', - IsMessage: true + smtProofLocalExitRoot: tx.proof.merkle_proof, + smtProofRollupExitRoot: tx.proof.rollup_merkle_proof, + globalIndex: tx.globalIndex.toString(), + originNetwork: '0', + originAddress: tx.transaction.transactionInitiator, + destinationAddress: tx.transaction.receiver, + amount: tx.transaction.originTokenAddress ? '0' : tx.transaction.amounts ? tx.transaction.amounts[0] : '0', + metadata: tx.transaction.metadata && tx.transaction.metadata !== "" ? tx.transaction.metadata : '0x', + isMessage: true }) } } - const transaction = await this.contract.compressClaimCall( + response = await this.contract.compressClaimCall( main_exit_root, rollup_exit_root, data, { gasPrice } ) + response = await this.contract.sendCompressedClaims(response) Logger.info({ type: 'claimBatch', status: 'success', - claimTransactionHash: transaction.hash + claimTransactionHash: response?.hash }) } catch (error: any) { Logger.error({ error }) } - return tx; + return response; } async claimTransactions() { @@ -177,12 +181,6 @@ export default class AutoClaimService { await this.claim(batch); } - const remaining = length % 5; - if (remaining > 0) { - const lastBatch = finalClaimableTransaction.slice(-remaining); - await this.claim(lastBatch); - } - Logger.info({ location: 'AutoClaimService', function: 'claimTransactions',