Skip to content

Commit

Permalink
More review tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
dave committed Aug 1, 2022
1 parent 1718d64 commit f96687c
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/toucan.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,37 +159,34 @@ async function deployTco2(contracts, vintageId) {
}

async function mintBatch(cBatches, batch, vintageId, admin, broker) {
let batchBroker = broker;
if (batch.Owner != null) {
// if Owner is specified in the genesis data, override the default broker.
batchBroker = await ethers.getSignerOrNull(batch.Owner);
broker = await ethers.getSignerOrNull(batch.Owner);
}

// Mint an empty batch to start the bridging process for the broker
console.log("Starting the tokenization process for a broker...");
console.log("1. Minting an empty batch...");
const batchTx = await cBatches.connect(batchBroker).mintEmptyBatch(batchBroker.address);
const batchTx = await cBatches.connect(broker).mintEmptyBatch(broker.address);
const batchId = await getBatchId(batchTx);
console.log(` - Minted batch ${batchId}`);

// Confirm credit tokenization
console.log("2. Updating the batch with data...");
await cBatches
.connect(batchBroker)
.updateBatchWithData(batchId, batch.SerialNumber, batch.Quantity, batch.Uri);
await cBatches.connect(broker).updateBatchWithData(batchId, batch.SerialNumber, batch.Quantity, batch.Uri);
console.log("3. Linking the batch to the vintage...");
await cBatches.connect(admin).linkWithVintage(batchId, vintageId);
console.log("4. Confirming the batch...");
await cBatches.connect(admin).confirmRetirement(batchId);

// Broker can now fractionalize to TCO2
console.log("5. Fractionalizing the batch to TCO2...");
await cBatches.connect(batchBroker).fractionalize(batchId);
await cBatches.connect(broker).fractionalize(batchId);
if (batch.Transfers != null) {
console.log("6. Transferring tokens...");
for (const transfer of batch.Transfers) {
console.log(` - ${transfer.Quantity} tokens transferred to ${transfer.Recipient}`);
await tco2.connect(batchBroker).transfer(transfer.Recipient, wei(transfer.Quantity));
await tco2.connect(broker).transfer(transfer.Recipient, wei(transfer.Quantity));
}
}
}
Expand Down

0 comments on commit f96687c

Please sign in to comment.