Skip to content

Commit

Permalink
ICR retirement handler
Browse files Browse the repository at this point in the history
  • Loading branch information
cujowolf committed Dec 6, 2023
1 parent 8a79118 commit 81e0f5f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
39 changes: 38 additions & 1 deletion polygon-digital-carbon/src/RetirementHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { MCO2_ERC20_CONTRACT, ZERO_ADDRESS } from '../../lib/utils/Constants'
import { ZERO_BI } from '../../lib/utils/Decimals'
import { C3OffsetNFT, VCUOMinted } from '../generated/C3-Offset/C3OffsetNFT'
import { CarbonOffset } from '../generated/MossCarbonOffset/CarbonChain'
import { RetiredVintage } from '../generated/templates/ICRProjectToken/ICRProjectToken'
import { Retired, Retired1 as Retired_1_4_0 } from '../generated/templates/ToucanCarbonOffsets/ToucanCarbonOffsets'
import { incrementAccountRetirements, loadOrCreateAccount } from './utils/Account'
import { loadCarbonCredit, loadOrCreateCarbonCredit } from './utils/CarbonCredit'
Expand Down Expand Up @@ -182,4 +183,40 @@ export function handleMossRetirement(event: CarbonOffset): void {
incrementAccountRetirements(event.transaction.from)
}

// export function handleMossRetirementToMainnet(): void {}
export function saveICRRetirement(event: RetiredVintage): void {
let credit = loadOrCreateCarbonCredit(event.address, 'ICR', event.params.tokenId)

credit.retired = credit.retired.plus(event.params.amount)
credit.save()

// Ensure account entities are created for all addresses
loadOrCreateAccount(event.params.account)
let sender = loadOrCreateAccount(event.transaction.from)

saveRetire(
event.transaction.from.concatI32(sender.totalRetirements),
event.address,
ZERO_ADDRESS,
'OTHER',
event.params.amount,
event.params.account,
'',
event.transaction.from,
'',
event.block.timestamp,
event.params.nftTokenId.toString()
)

incrementAccountRetirements(event.transaction.from)

recordProvenance(
event.transaction.hash,
event.address,
event.params.tokenId,
event.params.account,
ZERO_ADDRESS,
'RETIREMENT',
event.params.amount,
event.block.timestamp
)
}
9 changes: 7 additions & 2 deletions polygon-digital-carbon/src/TransferHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { loadOrCreateHolding } from './utils/Holding'
import { ZERO_BI } from '../../lib/utils/Decimals'
import { loadOrCreateAccount } from './utils/Account'
import { saveToucanRetirement, saveToucanRetirement_1_4_0 } from './RetirementHandler'
import { saveICRRetirement, saveToucanRetirement, saveToucanRetirement_1_4_0 } from './RetirementHandler'
import { saveBridge } from './utils/Bridge'
import { CarbonCredit, CrossChainBridge } from '../generated/schema'
import { checkForCarbonPoolSnapshot, loadOrCreateCarbonPool } from './utils/CarbonPool'
Expand Down Expand Up @@ -105,7 +105,12 @@ export function handle1155CreditTransferBatch(event: TransferBatch): void {
}
}

export function handleICRRetired(event: RetiredVintage): void {}
export function handleICRRetired(event: RetiredVintage): void {
// Ignore retirements of zero value
if (event.params.amount == ZERO_BI) return

saveICRRetirement(event)
}

export function handleExPostCreated(event: ExPostCreated): void {
updateICRCredit(event.address, event.params.tokenId, event.params.verificationPeriodStart)
Expand Down

0 comments on commit 81e0f5f

Please sign in to comment.