From cb3063e37daf1f5f094933ca7865d9984d22f0a7 Mon Sep 17 00:00:00 2001 From: amiecorso Date: Mon, 18 Mar 2024 15:40:06 -0700 Subject: [PATCH] scripts used for actual mint --- tasks/aggregate-removals.ts | 107 ++++++++++++++------------------ tasks/retire-certificates.ts | 117 ++++++++++++++--------------------- 2 files changed, 90 insertions(+), 134 deletions(-) diff --git a/tasks/aggregate-removals.ts b/tasks/aggregate-removals.ts index d8a2b6cb..68efe4d7 100644 --- a/tasks/aggregate-removals.ts +++ b/tasks/aggregate-removals.ts @@ -12,16 +12,10 @@ export const GET_AGGREGATE_REMOVALS_TASK = () => name: 'aggregate-removals', description: 'Utility to aggregate removals to a consignor', run: async ( - options: { - aggregateremovals: boolean; - batchfilename: string; - }, + options: {}, _: CustomHardHatRuntimeEnvironment ): Promise => { - const { - aggregateremovals, - batchfilename = 'bayer_batches_for_retirement.csv', - } = options; + const batchfilename = 'bayer_batches_for_retirement.csv'; const BLOCK_CONFIRMATIONS = 5; const SUPPLIER_WALLET_ADDRESS = '0xdca851dE155B20CC534b887bD2a1D780D0DEc077'; // Bayer @@ -64,7 +58,7 @@ export const GET_AGGREGATE_REMOVALS_TASK = () => // console.log(`Bayer has ${bayerMintedTokens.length} minted tokens`); const rawBatchData = readJsonSync(batchfilename); - console.log('RAW BATCH DATA', rawBatchData.slice(0, 5)); + // console.log('RAW BATCH DATA', rawBatchData.slice(0, 5)); const batches = rawBatchData.map((batch) => { return { @@ -76,54 +70,51 @@ export const GET_AGGREGATE_REMOVALS_TASK = () => }), }; }); - console.log('BATCH DATA', batches); + // console.log('BATCH DATA', batches); - if (aggregateremovals) { - const timestamp = new Date().toISOString(); - // Aggregate removals with consignor ======================== - const aggregationOutputFilename = `aggregation_txn_receipts_${timestamp}.json`; - const aggregationTransactionOutput = []; - let pendingTx; - let maybePendingTx; - let txReceipt; - for (let i = 0; i < batches.length; i++) { - maybePendingTx = - await removalContract.callStatic.consignorBatchTransfer( - SUPPLIER_WALLET_ADDRESS, - signerAddress, - batches[i].removalIdsForRetirement, - batches[i].balancesForRetirement, - { - gasPrice: fastGasPriceHexString, - } - ); - if (maybePendingTx === undefined) { - throw new Error(`No pending transaction returned`); - } else { - pendingTx = maybePendingTx; + const timestamp = new Date().toISOString(); + // Aggregate removals with consignor ======================== + const aggregationOutputFilename = `aggregation_txn_receipts_${timestamp}.json`; + const aggregationTransactionOutput = []; + let pendingTx; + let maybePendingTx; + let txReceipt; + for (let i = 0; i < batches.length; i++) { + maybePendingTx = await removalContract.consignorBatchTransfer( + SUPPLIER_WALLET_ADDRESS, + signerAddress, + batches[i].removalIdsForRetirement, + batches[i].balancesForRetirement, + { + gasPrice: fastGasPriceHexString, } - if (pendingTx !== undefined) { - console.info( - `📝 Awaiting aggregation transaction ${i}/${batches.length}: ${pendingTx.hash}` + ); + if (maybePendingTx === undefined) { + throw new Error(`No pending transaction returned`); + } else { + pendingTx = maybePendingTx; + } + if (pendingTx !== undefined) { + console.info( + `📝 Awaiting aggregation transaction ${i}/${batches.length}: ${pendingTx.hash}` + ); + const txResult = await pendingTx.wait(BLOCK_CONFIRMATIONS); + console.info('Getting txReceipt...'); + txReceipt = await removalContract.provider.getTransactionReceipt( + txResult.transactionHash + ); + aggregationTransactionOutput.push(txReceipt); + if (txReceipt.status !== 1) { + console.error( + `❌ Transaction ${pendingTx.hash} failed with failure status ${txReceipt.status} - exiting early` + ); + writeJsonSync( + aggregationOutputFilename, + aggregationTransactionOutput ); - const txResult = await pendingTx.wait(BLOCK_CONFIRMATIONS); - console.info('Getting txReceipt...'); - txReceipt = await removalContract.provider.getTransactionReceipt( - txResult.transactionHash + throw new Error( + 'Transaction failed with unsuccessful status - exiting early' ); - aggregationTransactionOutput.push(txReceipt); - if (txReceipt.status !== 1) { - console.error( - `❌ Transaction ${pendingTx.hash} failed with failure status ${txReceipt.status} - exiting early` - ); - writeJsonSync( - aggregationOutputFilename, - aggregationTransactionOutput - ); - throw new Error( - 'Transaction failed with unsuccessful status - exiting early' - ); - } } } console.log( @@ -136,13 +127,5 @@ export const GET_AGGREGATE_REMOVALS_TASK = () => (() => { const { name, description, run } = GET_AGGREGATE_REMOVALS_TASK(); - task(name, description, run) - .addFlag('aggregateremovals', 'Aggregate removals to consignor') - .addParam( - 'batchfilename', - 'Path to the file containing the batch data', - undefined, - types.string, - false - ); + task(name, description, run); })(); diff --git a/tasks/retire-certificates.ts b/tasks/retire-certificates.ts index ff9913ca..836aab79 100644 --- a/tasks/retire-certificates.ts +++ b/tasks/retire-certificates.ts @@ -11,17 +11,12 @@ export const GET_RETIRE_CERTIFICATES_TASK = () => description: 'Utility to retire large Bayer certificates', run: async ( options: { - doretirement: boolean; - batchfilename: string; - batchIndex: number; + batchindex: number; }, _: CustomHardHatRuntimeEnvironment ): Promise => { - const { - doretirement, - batchfilename = 'bayer_batches_for_retirement.csv', - batchIndex = 0, - } = options; + const { batchindex = 0 } = options; + const batchfilename = 'bayer_batches_for_retirement.csv'; const CERTIFICATE_SIZE_TONNES = 10_000; const CERTIFICATE_SIZE_WEI = ethers.utils.parseUnits( CERTIFICATE_SIZE_TONNES.toString(), @@ -58,7 +53,6 @@ export const GET_RETIRE_CERTIFICATES_TASK = () => ); const rawBatchData = readJsonSync(batchfilename); - console.log('RAW BATCH DATA', rawBatchData.slice(0, 5)); const batches = rawBatchData.map((batch) => { return { @@ -70,79 +64,58 @@ export const GET_RETIRE_CERTIFICATES_TASK = () => }), }; }); - console.log('BATCH DATA', batches); - if (doretirement) { - const timestamp = new Date().toISOString(); - // Do the retirement ======================================== - const retirementOutputFilename = `${batchIndex}_retirement_txn_receipt_${timestamp}.json`; - const retirementTransactionOutput = []; - let pendingTx; - let maybePendingTx; - let txReceipt; - maybePendingTx = await removalContract.callStatic.retire( - batches[batchIndex].removalIdsForRetirement, - batches[batchIndex].balancesForRetirement, - RECIPIENT, // recipient - CERTIFICATE_SIZE_WEI, - { - gasPrice: fastGasPriceHexString, - } - ); - if (maybePendingTx === undefined) { - throw new Error(`No pending transaction returned`); - } else { - pendingTx = maybePendingTx; + const timestamp = new Date().toISOString(); + // Do the retirement ======================================== + const retirementOutputFilename = `${batchindex}_retirement_txn_receipt_${timestamp}.json`; + let pendingTx; + let maybePendingTx; + let txReceipt; + maybePendingTx = await removalContract.retire( + batches[batchindex].removalIdsForRetirement, + batches[batchindex].balancesForRetirement, + RECIPIENT, // recipient + CERTIFICATE_SIZE_WEI, + { + gasPrice: fastGasPriceHexString, } - if (pendingTx !== undefined) { - console.info( - `📝 Awaiting retire transaction for batch ${batchIndex} + ); + if (maybePendingTx === undefined) { + throw new Error(`No pending transaction returned`); + } else { + pendingTx = maybePendingTx; + } + if (pendingTx !== undefined) { + console.info( + `📝 Awaiting retire transaction for batch ${batchindex} }: ${pendingTx.hash}` + ); + const txResult = await pendingTx.wait(BLOCK_CONFIRMATIONS); + console.info('Getting txReceipt...'); + txReceipt = await removalContract.provider.getTransactionReceipt( + txResult.transactionHash + ); + if (txReceipt.status !== 1) { + console.error( + `❌ Transaction ${pendingTx.hash} failed with failure status ${txReceipt.status} - exiting early` ); - const txResult = await pendingTx.wait(BLOCK_CONFIRMATIONS); - console.info('Getting txReceipt...'); - txReceipt = await removalContract.provider.getTransactionReceipt( - txResult.transactionHash + writeJsonSync(retirementOutputFilename, txReceipt); + throw new Error( + 'Transaction failed with unsuccessful status - exiting early' ); - retirementTransactionOutput.push(txReceipt); - if (txReceipt.status !== 1) { - console.error( - `❌ Transaction ${pendingTx.hash} failed with failure status ${txReceipt.status} - exiting early` - ); - writeJsonSync( - retirementOutputFilename, - retirementTransactionOutput - ); - throw new Error( - 'Transaction failed with unsuccessful status - exiting early' - ); - } } - - console.log( - 'Successfully aggregated all batches of removals to consignor! Writing transaction receipts to file...' - ); - writeJsonSync(retirementOutputFilename, retirementTransactionOutput); } + writeJsonSync(retirementOutputFilename, txReceipt); }, } as const); (() => { const { name, description, run } = GET_RETIRE_CERTIFICATES_TASK(); - task(name, description, run) - .addFlag('doretirement', 'Actually execute the retirement') - .addParam( - 'batchfilename', - 'Path to the file containing the batch data', - undefined, - types.string, - false - ) - .addParam( - 'batchIndex', - 'which batch to retire', - undefined, - types.int, - false - ); + task(name, description, run).addParam( + 'batchindex', + 'which batch to retire', + undefined, + types.int, + false + ); })();