Skip to content

Commit

Permalink
feat: use bytes for addresses ids (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
gauthiermyr authored Oct 24, 2023
1 parent 22ae20b commit 8f8c2a1
Show file tree
Hide file tree
Showing 21 changed files with 532 additions and 456 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"format": "prettier --config .prettierrc 'abis_ts/**/*.ts' 'src/**/*.ts' --write"
},
"dependencies": {
"@graphprotocol/graph-cli": "0.51.2",
"@graphprotocol/cost-model": "^0.1.16",
"@graphprotocol/graph-cli": "0.60.0",
"@graphprotocol/graph-ts": "0.31.0",
"@graphprotocol/indexer-cli": "^0.20.17",
"prettier": "2.8.1"
Expand Down
43 changes: 21 additions & 22 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type MetaContract @entity {
#

type PluggableHatcher @entity {
id: String!
id: Bytes!
address: Bytes!
contract: MetaContract!

Expand All @@ -36,7 +36,7 @@ type PluggableHatcher @entity {
}

type Cub @entity {
id: String!
id: Bytes!
address: Bytes!
contract: MetaContract!

Expand Down Expand Up @@ -70,7 +70,7 @@ type Fix @entity {
}

type PluggableHatcherImplementation @entity {
id: String!
id: Bytes!
address: Bytes!

pluggableHatcher: PluggableHatcher!
Expand All @@ -82,8 +82,9 @@ type PluggableHatcherImplementation @entity {
}

type TUPProxy @entity {
id: String!
id: Bytes!

address: Bytes!
freezeTime: BigInt!
admin: Bytes!
pauser: Bytes!
Expand Down Expand Up @@ -118,7 +119,7 @@ type TUPProxyUpgrade @entity {
#

type Nexus @entity {
id: String!
id: Bytes!
address: Bytes!
contract: MetaContract!
proxy: TUPProxy!
Expand Down Expand Up @@ -158,7 +159,7 @@ type Nexus @entity {
#

type vFactory @entity {
id: String!
id: Bytes!
address: Bytes!
contract: MetaContract!

Expand Down Expand Up @@ -325,7 +326,7 @@ type FactoryDepositor @entity {
#

type vTreasury @entity {
id: String!
id: Bytes!
address: Bytes!

cub: Cub!
Expand Down Expand Up @@ -393,7 +394,7 @@ type TreasuryFeeVote @entity {
#

type vPool @entity {
id: String!
id: Bytes!
address: Bytes!
contract: MetaContract!

Expand Down Expand Up @@ -690,7 +691,7 @@ type PoolDepositor @entity {
# ▀▀

type vExitQueue @entity {
id: String!
id: Bytes!
address: Bytes!
contract: MetaContract!

Expand Down Expand Up @@ -799,7 +800,7 @@ type Cask @entity {
#

type vExecLayerRecipient @entity {
id: String!
id: Bytes!
address: Bytes!
contract: MetaContract!

Expand Down Expand Up @@ -836,7 +837,7 @@ type ExecLayerSuppliedEther @entity {
#

type vCoverageRecipient @entity {
id: String!
id: Bytes!
address: Bytes!
contract: MetaContract!

Expand Down Expand Up @@ -906,7 +907,7 @@ type CoverageVoidedShares @entity {
#

type vWithdrawalRecipient @entity {
id: String!
id: Bytes!
address: Bytes!

withdrawalCredentials: Bytes!
Expand All @@ -929,7 +930,7 @@ type vWithdrawalRecipient @entity {
#

type vOracleAggregator @entity {
id: String!
id: Bytes!
address: Bytes!
contract: MetaContract!

Expand Down Expand Up @@ -1029,7 +1030,7 @@ type Commission @entity {
}

type IntegrationChannel @entity {
id: String!
id: Bytes!
name: String!
implementation: Bytes!
contract: MetaContract!
Expand All @@ -1041,7 +1042,7 @@ type IntegrationChannel @entity {
}

interface Integration {
id: String!
id: Bytes!
address: Bytes!
channel: IntegrationChannel!
name: String!
Expand Down Expand Up @@ -1108,7 +1109,7 @@ type MultiPoolRewardsSnapshot @entity {
}

interface vPoolIntegration {
id: String!
id: Bytes!

pools: [MultiPool!]! @derivedFrom(field: "integration")
commissions: [Commission!]! @derivedFrom(field: "vPoolIntegration")
Expand Down Expand Up @@ -1161,11 +1162,10 @@ type ERC20 implements vPoolIntegration & Integration @entity {

# vPoolIntegration
pools: [MultiPool!]! @derivedFrom(field: "integration")
_poolsDerived: [MultiPool!]!
commissions: [Commission!]! @derivedFrom(field: "vPoolIntegration")

# Integration
id: String!
id: Bytes!
address: Bytes!
channel: IntegrationChannel!
name: String!
Expand Down Expand Up @@ -1348,12 +1348,11 @@ type ERC1155Integration implements vPoolIntegration & Integration @entity {

# vPoolIntegration
pools: [MultiPool!]! @derivedFrom(field: "integration")
_poolsDerived: [MultiPool!]!
commissions: [Commission!]! @derivedFrom(field: "vPoolIntegration")
maxCommission: BigInt!

# Integration
id: String!
id: Bytes!
address: Bytes!
channel: IntegrationChannel!
name: String!
Expand Down Expand Up @@ -1396,7 +1395,7 @@ type VaultClaim @entity {
}

type MerkleVault @entity {
id: String!
id: Bytes!

root: Bytes!
frameSize: BigInt!
Expand Down Expand Up @@ -1443,7 +1442,7 @@ type vNFTIntegration implements Integration @entity {
approvals: [vNFTApprovals!]! @derivedFrom(field: "integration")

# Integration
id: String!
id: Bytes!
address: Bytes!
channel: IntegrationChannel!
name: String!
Expand Down
4 changes: 2 additions & 2 deletions src/Cub.mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { AppliedFixes } from '../generated/templates/Cub/Cub';
import { entityUUID, eventUUID } from './utils/utils';

export function handleAppliedFixes(event: AppliedFixes): void {
const cub = Cub.load(entityUUID(event, []));
const cub = Cub.load(event.address);

for (let idx = 0; idx < event.params.fixes.length; ++idx) {
const fixId = eventUUID(event, ['fix', event.params.fixes[idx].toHexString()]);

const fix = new Fix(fixId);
fix.address = event.params.fixes[idx];
fix.fix = entityUUID(event, []);
fix.fix = event.address;

fix.createdAt = event.block.timestamp;
fix.createdAtBlock = event.block.number;
Expand Down
31 changes: 15 additions & 16 deletions src/ERC1155.mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
import { getOrCreateBalance } from './vPool.mapping';

export function handleSetName(event: SetName): void {
const erc1155 = ERC1155Integration.load(entityUUID(event, []));
const erc1155 = ERC1155Integration.load(event.address);

erc1155!.name = event.params.name;

Expand All @@ -50,7 +50,7 @@ export function handleSetName(event: SetName): void {
}

export function handleSetURIPrefix(event: SetURIPrefix): void {
const erc1155 = ERC1155Integration.load(entityUUID(event, []));
const erc1155 = ERC1155Integration.load(event.address);

erc1155!.uriPrefix = event.params.uri;

Expand All @@ -61,7 +61,7 @@ export function handleSetURIPrefix(event: SetURIPrefix): void {
}

export function handleSetSymbol(event: SetSymbol): void {
const erc1155 = ERC1155Integration.load(entityUUID(event, []));
const erc1155 = ERC1155Integration.load(event.address);
erc1155!.symbol = event.params.symbol;

erc1155!.editedAt = event.block.timestamp;
Expand All @@ -71,7 +71,7 @@ export function handleSetSymbol(event: SetSymbol): void {
}

export function handleSetDepositsPaused(event: SetDepositsPaused): void {
const erc1155 = ERC1155Integration.load(entityUUID(event, []));
const erc1155 = ERC1155Integration.load(event.address);
erc1155!.paused = event.params.isPaused;

erc1155!.editedAt = event.block.timestamp;
Expand All @@ -81,9 +81,8 @@ export function handleSetDepositsPaused(event: SetDepositsPaused): void {
}

export function handleCommissionSharesSold(event: CommissionSharesSold): void {
const erc1155 = ERC1155Integration.load(externalEntityUUID(event.address, []));
const multiPoolId = erc1155!._poolsDerived[event.params.id.toU32()];
const multiPool = MultiPool.load(multiPoolId);
const erc1155 = ERC1155Integration.load(event.address);
const multiPool = MultiPool.load(entityUUID(event, [event.params.id.toString()]));
multiPool!.soldEth = multiPool!.soldEth.plus(event.params.amountSold);
multiPool!.commissionPaid = multiPool!.commissionPaid.plus(event.params.amountSold);
const ucs = getOrCreateUnassignedCommissionSold();
Expand All @@ -104,13 +103,13 @@ export function handlePoolAdded(event: PoolAdded): void {
const tokenAndPoolId = entityUUID(event, [poolId.toString()]);
const multiPool = new MultiPool(tokenAndPoolId);
multiPool.number = poolId;
multiPool.pool = externalEntityUUID(vPool, []);
multiPool.pool = vPool;
multiPool.active = true;
multiPool.fees = BigInt.zero();
multiPool.commissionPaid = BigInt.zero();
multiPool.injectedEth = BigInt.zero();
multiPool.exitedEth = BigInt.zero();
multiPool.integration = entityUUID(event, []);
multiPool.integration = event.address;
multiPool.poolAllocation = BigInt.zero();
multiPool.soldEth = BigInt.zero();
const poolBalance = getOrCreateBalance(
Expand All @@ -133,7 +132,7 @@ export function handlePoolAdded(event: PoolAdded): void {

const erc1155 = new ERC1155(tokenAndPoolId);
erc1155.pool = tokenAndPoolId;
erc1155.integration = entityUUID(event, []);
erc1155.integration = event.address;
erc1155.tokenId = poolId;
erc1155.totalSupply = BigInt.zero();
erc1155.totalUnderlyingSupply = BigInt.zero();
Expand Down Expand Up @@ -171,7 +170,7 @@ export function handlePoolActivation(event: PoolActivation): void {
}

export function handleNewCommissionSplit(event: NewCommissionSplit): void {
const erc1155 = ERC1155Integration.load(entityUUID(event, []));
const erc1155 = ERC1155Integration.load(event.address);
const recipients = event.params.recipients;
const splits = event.params.splits;
const ts = event.block.timestamp;
Expand Down Expand Up @@ -206,7 +205,7 @@ export function handleNewCommissionSplit(event: NewCommissionSplit): void {
}

export function handleCommissionWithdrawn(event: CommissionWithdrawn): void {
const erc1155 = ERC1155Integration.load(entityUUID(event, []));
const erc1155 = ERC1155Integration.load(event.address);
const ts = event.block.timestamp;
const blockId = event.block.number;

Expand All @@ -225,7 +224,7 @@ export function handleCommissionWithdrawn(event: CommissionWithdrawn): void {
export function handleStake_1_0_0_rc4(event: Stake_1_0_0_rc4): void {
const tokenId = event.params.id;
const erc1155 = ERC1155.load(entityUUID(event, [tokenId.toString()]));
const erc1155Integration = ERC1155Integration.load(entityUUID(event, []));
const erc1155Integration = ERC1155Integration.load(event.address);

const ts = event.block.timestamp;
const blockId = event.block.number;
Expand Down Expand Up @@ -292,7 +291,7 @@ export function handleStake_1_0_0_rc4(event: Stake_1_0_0_rc4): void {
export function handleStake(event: Stake): void {
const tokenId = event.params.stakeDetails[0].poolId;
const erc1155 = ERC1155.load(entityUUID(event, [tokenId.toString()]));
const erc1155Integration = ERC1155Integration.load(entityUUID(event, []));
const erc1155Integration = ERC1155Integration.load(event.address);

const ts = event.block.timestamp;
const blockId = event.block.number;
Expand Down Expand Up @@ -477,15 +476,15 @@ export function handleApprovalForAll(event: ApprovalForAll): void {
export function handleVPoolSharesReceived(event: VPoolSharesReceived): void {}

export function handleSetAdmin(event: SetAdmin): void {
const erc1155Integration = ERC1155Integration.load(entityUUID(event, []));
const erc1155Integration = ERC1155Integration.load(event.address);
erc1155Integration!.admin = event.params.admin;
erc1155Integration!.editedAt = event.block.timestamp;
erc1155Integration!.editedAtBlock = event.block.number;
erc1155Integration!.save();
}

export function handleSetMaxCommission(event: SetMaxCommission): void {
const erc1155Integration = ERC1155Integration.load(entityUUID(event, []));
const erc1155Integration = ERC1155Integration.load(event.address);
erc1155Integration!.maxCommission = event.params.maxCommission;
erc1155Integration!.editedAt = event.block.timestamp;
erc1155Integration!.editedAtBlock = event.block.number;
Expand Down
Loading

0 comments on commit 8f8c2a1

Please sign in to comment.