Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 73 additions & 94 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions subgraph/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
/troves.json.bak
/brackets.json
/brackets.json.bak
/tests/.bin/
/tests/.latest.json
43 changes: 27 additions & 16 deletions subgraph/networks.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
{
"local": {
"celo": {
"BoldToken": {
"address": "0x0e18b884ec3095f7c27bbbeb0a266a5674bcaffd"
"address": "0xb38aEf2bF4e34B997330D626EBCd7629De3885C9",
"startBlock": 60668167
},
"Governance": {
"address": "0x79fdb65c20e75f8961d54f6714d2fcc4c30d1073"
"BoldTokenCHFm": {
"address": "0x4e105fEf015dB26320c077427bd605acEad9262E",
"startBlock": 65390610
},
"BoldTokenJPYm": {
"address": "0xd2E65aF47d927d5E84f384AE6BAC4F97c3da65df",
"startBlock": 65390636
}
},
"mainnet": {
"celo-sepolia": {
"BoldToken": {
"address": "0x6440f144b7e50d6a8439336510312d2f54beb01d",
"startBlock": 22483043
"address": "0x3ADFF16949513480E051F451748Ee8B801731c46",
"startBlock": 19187423
},
"BoldTokenCHFm": {
"address": "0xc21dc07eC1707d315A7eff31A6556e628E43A3f8",
"startBlock": 23671277
},
"Governance": {
"address": "0x807def5e7d057df05c796f4bc75c3fe82bd6eee1",
"startBlock": 22496547
"BoldTokenJPYm": {
"address": "0xeD54259166EbbFe72083FC37eE2a00e922fbA84D",
"startBlock": 23671448
}
},
Comment thread
bayological marked this conversation as resolved.
"sepolia": {
"local": {
"BoldToken": {
"address": "0x181dff47198bf3f3ed65877332e8395eb6817c4c",
"startBlock": 8316063
"address": "0x0e18b884ec3095f7c27bbbeb0a266a5674bcaffd"
},
"BoldTokenCHFm": {
"address": "0x0000000000000000000000000000000000000000"
},
"Governance": {
"address": "0xf68db4e851d89daf0fb842b01f75d94e0cb44f49",
"startBlock": 8316191
"BoldTokenJPYm": {
"address": "0x0000000000000000000000000000000000000000"
}
}
}
8 changes: 6 additions & 2 deletions subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
"license": "MIT",
"version": "1.0.0",
"scripts": {
"codegen": "pnpm graph codegen"
"codegen": "pnpm graph codegen",
"build": "pnpm graph build",
"test": "pnpm graph test"
},
"devDependencies": {
"@graphprotocol/graph-cli": "^0.97.0"
"@graphprotocol/graph-cli": "^0.97.0",
"assemblyscript": "0.19.23",
"matchstick-as": "^0.6.0"
},
"dependencies": {
"@graphprotocol/graph-ts": "^0.38.0",
Expand Down
77 changes: 46 additions & 31 deletions subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,52 @@ type Trove @entity(immutable: false) {
redemptionCount: Int!
redeemedColl: BigInt!
redeemedDebt: BigInt!
operations: [TroveOperation!]! @derivedFrom(field: "trove")
}

# Mirrors ITroveEvents.Operation. Order must match the contract enum so a uint8
# can be stored as the corresponding string value with no remapping.
enum TroveOperationKind {
openTrove
closeTrove
adjustTrove
adjustTroveInterestRate
applyPendingDebt
liquidate
redeemCollateral
openTroveAndJoinBatch
setInterestBatchManager
removeFromBatch
}

# Immutable per-operation history row. One row per TroveOperation event.
# IDs combine tx hash + log index so they are stable across reorgs.
type TroveOperation @entity(immutable: true) {
id: Bytes! # tx hash concatenated with logIndex
trove: Trove!
blockNumber: BigInt!
timestamp: BigInt!
transactionHash: Bytes!
logIndex: BigInt!
operation: TroveOperationKind!
initiator: Bytes! # transaction.from
# Signed changes from the operation itself. Excludes accrued/redistributed values.
collateralDelta: BigInt!
debtDelta: BigInt!
# Post-state snapshots, captured after TroveUpdated has been applied.
newCollateral: BigInt!
newDebt: BigInt!
newInterestRate: BigInt!
# Accrued portions from redistribution. Always positive.
collIncreaseFromRedist: BigInt!
debtIncreaseFromRedist: BigInt!
# Upfront borrowing fee added to debt this op (zero outside open/adjust paths).
upfrontFee: BigInt!
# Enriched from same-tx Redemption / Liquidation events when applicable.
redemptionPrice: BigInt
liquidationPrice: BigInt
# Set when the op happened against a trove in a batch.
batch: InterestBatch
}

type BorrowerInfo @entity(immutable: false) {
Expand All @@ -74,34 +120,3 @@ type InterestBatch @entity(immutable: false) {
updatedAt: BigInt!
troves: [Trove!]! @derivedFrom(field: "interestBatch")
}

type GovernanceVotingPower @entity(immutable: false) {
id: ID! # userAddress, e.g. "0x0000000000000000000000000000000000000000", or "total"
allocatedLQTY: BigInt!
allocatedOffset: BigInt!
unallocatedLQTY: BigInt!
unallocatedOffset: BigInt!
}

type GovernanceAllocationIndex @entity(immutable: false) {
id: ID! # "userAddress:initiativeAddress" or "initiativeAddress"
user: String
initiative: GovernanceInitiative!
latestAllocation: GovernanceAllocation!
}

type GovernanceAllocation @entity(immutable: false) {
id: ID! # "userAddress:initiativeAddress:epoch" or "initiativeAddress:epoch"
user: String
initiative: GovernanceInitiative!
epoch: BigInt!
voteLQTY: BigInt!
vetoLQTY: BigInt!
voteOffset: BigInt!
vetoOffset: BigInt!
}

type GovernanceInitiative @entity(immutable: false) {
id: ID! # "initiativeAddress", e.g. "0x0000000000000000000000000000000000000000"
registered: Boolean!
}
22 changes: 19 additions & 3 deletions subgraph/src/BoldToken.mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,27 @@ import { TroveManager as TroveManagerContract } from "../generated/BoldToken/Tro
import { Collateral, CollateralAddresses } from "../generated/schema";
import { TroveManager as TroveManagerTemplate, TroveNFT as TroveNFTTemplate } from "../generated/templates";

// Mento V3 runs one independent CDP instance per FX-pegged stable (GBPm, CHFm,
// JPYm, ...). Each instance has its own CollateralRegistry, and each registry
// starts numbering its collaterals at index 0. Naming entities by `collIndex`
// alone collides across branches — every branch would write to Collateral
// id="0", Trove id="0:<troveId>", etc.
//
// We namespace every entity ID by the branch's TroveManager address (each
// branch's TroveManager is unique, and it's the address that emits the
// CollateralRegistryAddressChanged event we're handling, so it's already in
// `event.address`). The resulting collId looks like
// "0x<troveManager>:<collIndex>" and flows through DataSourceContext into
// every downstream entity ID (Trove, InterestRateBracket, InterestBatch,
// CollateralAddresses).
function addCollateral(
branchPrefix: string,
collIndex: i32,
totalCollaterals: i32,
tokenAddress: Address,
troveManagerAddress: Address,
): void {
let collId = collIndex.toString();
let collId = branchPrefix + ":" + collIndex.toString();

let collateral = new Collateral(collId);
collateral.collIndex = collIndex;
Expand Down Expand Up @@ -53,6 +67,7 @@ function addCollateral(
}

export function handleCollateralRegistryAddressChanged(event: CollateralRegistryAddressChangedEvent): void {
let branchPrefix = event.address.toHexString();
let registry = CollateralRegistryContract.bind(event.params._newCollateralRegistryAddress);
let totalCollaterals = registry.totalCollaterals().toI32();

Expand All @@ -64,9 +79,10 @@ export function handleCollateralRegistryAddressChanged(event: CollateralRegistry
break;
}

// we use the token address as the id for the collateral
if (!Collateral.load(tokenAddress.toHexString())) {
let collId = branchPrefix + ":" + index.toString();
if (!Collateral.load(collId)) {
addCollateral(
branchPrefix,
index,
totalCollaterals,
tokenAddress,
Expand Down
Loading