Skip to content

Commit

Permalink
Marketplace/ICR Vintages Fix (#124)
Browse files Browse the repository at this point in the history
* in-progress script to update tokenIds

* working tokenIds script

* add tokenIds to project, match tokenIds when creating Projects
  • Loading branch information
psparacino authored Apr 4, 2024
1 parent 0b0c16b commit a802b11
Show file tree
Hide file tree
Showing 5 changed files with 1,967 additions and 937 deletions.
1 change: 1 addition & 0 deletions carbonmark/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Project @entity {
methodology: String!
vintage: BigInt!
projectAddress: Bytes!
tokenId: BigInt!
registry: String!
# #relationships
activities: [Activity!] @derivedFrom(field: "project")
Expand Down
2 changes: 1 addition & 1 deletion carbonmark/src/Carbonmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function handleListingCreated(event: ListingCreated): void {
// Ensure the user entity exists
loadOrCreateUser(event.params.account)
loadOrCreateUser(event.transaction.from)
let project = loadOrCreateProject(event.params.token)
let project = loadOrCreateProject(event.params.token, event.params.tokenId)

let listing = loadOrCreateListing(event.params.id.toHexString())

Expand Down
7 changes: 4 additions & 3 deletions carbonmark/src/Entities.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Activity, Category, Country, Listing, Project, Purchase, User } from '../generated/schema'
import { ZERO_BI } from '../../lib/utils/Decimals'
import { ZERO_ADDRESS } from '../../lib/utils/Constants'
import { Address, BigInt, Bytes } from '@graphprotocol/graph-ts'
import { Address, BigInt, Bytes, log } from '@graphprotocol/graph-ts'
import { PROJECT_INFO } from './Projects'

export function loadOrCreateProject(token: Address): Project {
export function loadOrCreateProject(token: Address, tokenId: BigInt): Project {
// Find the project + vintage ID from token address
let tokenAddress = token.toHexString()
let id = ''
let registry = ''
let projectIndex = 0
for (let i = 0; i < PROJECT_INFO.length; i++) {
if (tokenAddress == PROJECT_INFO[i][0]) {
if (tokenAddress.toLowerCase() == PROJECT_INFO[i][0] && tokenId.toString() == PROJECT_INFO[i][7]) {
id = PROJECT_INFO[i][1] + '-' + PROJECT_INFO[i][2]
registry = PROJECT_INFO[i][1].split('-')[0]
projectIndex = i
Expand All @@ -31,6 +31,7 @@ export function loadOrCreateProject(token: Address): Project {
project.registry = registry
project.category = PROJECT_INFO[projectIndex][5]
project.country = PROJECT_INFO[projectIndex][6]
project.tokenId = tokenId
project.save()

createCountry(project.country)
Expand Down
Loading

0 comments on commit a802b11

Please sign in to comment.