Skip to content

Commit

Permalink
scripts used for actual mint
Browse files Browse the repository at this point in the history
  • Loading branch information
amiecorso committed Mar 18, 2024
1 parent 5738efe commit cb3063e
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 134 deletions.
107 changes: 45 additions & 62 deletions tasks/aggregate-removals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},

Check warning on line 15 in tasks/aggregate-removals.ts

View workflow job for this annotation

GitHub Actions / lint

Parameter name `options` must have one leading underscore(s)

Check warning on line 15 in tasks/aggregate-removals.ts

View workflow job for this annotation

GitHub Actions / lint

'options' is defined but never used. Allowed unused args must match /_/u
_: CustomHardHatRuntimeEnvironment
): Promise<void> => {
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
Expand Down Expand Up @@ -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) => {

Check failure on line 63 in tasks/aggregate-removals.ts

View workflow job for this annotation

GitHub Actions / analyze

Parameter 'batch' implicitly has an 'any' type.
return {
Expand All @@ -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(
Expand All @@ -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);
})();
117 changes: 45 additions & 72 deletions tasks/retire-certificates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
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(),
Expand Down Expand Up @@ -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) => {

Check failure on line 57 in tasks/retire-certificates.ts

View workflow job for this annotation

GitHub Actions / analyze

Parameter 'batch' implicitly has an 'any' type.
return {
Expand All @@ -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
);
})();

0 comments on commit cb3063e

Please sign in to comment.