From 531bdc899bbcbeb7e9fef45d7cac1a68cf3f0d5d Mon Sep 17 00:00:00 2001 From: Mario Micklisch Date: Fri, 30 Aug 2024 11:26:23 +0200 Subject: [PATCH] Add veDelegate configuration index --- abis/VeDelegate-Configs.json | 69 ++++++++++++ generated/schema.ts | 96 ++++++++++++++++ .../vedelegate-configs/IVeDelegateConfigs.ts | 103 ++++++++++++++++++ src/VeDelegate-Configs.ts | 17 +++ subgraph.graphql | 7 ++ subgraph.yaml | 22 ++++ 6 files changed, 314 insertions(+) create mode 100644 abis/VeDelegate-Configs.json create mode 100644 generated/vedelegate-configs/IVeDelegateConfigs.ts create mode 100644 src/VeDelegate-Configs.ts diff --git a/abis/VeDelegate-Configs.json b/abis/VeDelegate-Configs.json new file mode 100644 index 0000000..1ada438 --- /dev/null +++ b/abis/VeDelegate-Configs.json @@ -0,0 +1,69 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": true, + "internalType": "string", + "name": "configId", + "type": "string" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "ConfigUpdated", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "internalType": "string[]", + "name": "ids", + "type": "string[]" + } + ], + "name": "getValues", + "outputs": [ + { + "internalType": "uint256[]", + "name": "values", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string[]", + "name": "ids", + "type": "string[]" + }, + { + "internalType": "uint256[]", + "name": "values", + "type": "uint256[]" + } + ], + "name": "setValues", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] \ No newline at end of file diff --git a/generated/schema.ts b/generated/schema.ts index 6eec6fe..d7ec0be 100644 --- a/generated/schema.ts +++ b/generated/schema.ts @@ -50,6 +50,19 @@ export class Round extends Entity { this.set("id", Value.fromString(value)); } + get number(): BigInt { + let value = this.get("number"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set number(value: BigInt) { + this.set("number", Value.fromBigInt(value)); + } + get voteStart(): BigInt { let value = this.get("voteStart"); if (!value || value.kind == ValueKind.NULL) { @@ -1508,6 +1521,89 @@ export class VeDelegateAccount extends Entity { } } +export class VeDelegateConfig extends Entity { + constructor(id: string) { + super(); + this.set("id", Value.fromString(id)); + } + + save(): void { + let id = this.get("id"); + assert(id != null, "Cannot save VeDelegateConfig entity without an ID"); + if (id) { + assert( + id.kind == ValueKind.STRING, + `Entities of type VeDelegateConfig must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}`, + ); + store.set("VeDelegateConfig", id.toString(), this); + } + } + + static loadInBlock(id: string): VeDelegateConfig | null { + return changetype( + store.get_in_block("VeDelegateConfig", id), + ); + } + + static load(id: string): VeDelegateConfig | null { + return changetype( + store.get("VeDelegateConfig", id), + ); + } + + get id(): string { + let value = this.get("id"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set id(value: string) { + this.set("id", Value.fromString(value)); + } + + get account(): Bytes { + let value = this.get("account"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set account(value: Bytes) { + this.set("account", Value.fromBytes(value)); + } + + get configId(): string { + let value = this.get("configId"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set configId(value: string) { + this.set("configId", Value.fromString(value)); + } + + get value(): BigInt { + let value = this.get("value"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set value(value: BigInt) { + this.set("value", Value.fromBigInt(value)); + } +} + export class VetDomainsNames extends Entity { constructor(id: string) { super(); diff --git a/generated/vedelegate-configs/IVeDelegateConfigs.ts b/generated/vedelegate-configs/IVeDelegateConfigs.ts new file mode 100644 index 0000000..85f5f44 --- /dev/null +++ b/generated/vedelegate-configs/IVeDelegateConfigs.ts @@ -0,0 +1,103 @@ +// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. + +import { + ethereum, + JSONValue, + TypedMap, + Entity, + Bytes, + Address, + BigInt, +} from "@graphprotocol/graph-ts"; + +export class ConfigUpdated extends ethereum.Event { + get params(): ConfigUpdated__Params { + return new ConfigUpdated__Params(this); + } +} + +export class ConfigUpdated__Params { + _event: ConfigUpdated; + + constructor(event: ConfigUpdated) { + this._event = event; + } + + get sender(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get configId(): Bytes { + return this._event.parameters[1].value.toBytes(); + } + + get value(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } +} + +export class IVeDelegateConfigs extends ethereum.SmartContract { + static bind(address: Address): IVeDelegateConfigs { + return new IVeDelegateConfigs("IVeDelegateConfigs", address); + } + + getValues(user: Address, ids: Array): Array { + let result = super.call( + "getValues", + "getValues(address,string[]):(uint256[])", + [ethereum.Value.fromAddress(user), ethereum.Value.fromStringArray(ids)], + ); + + return result[0].toBigIntArray(); + } + + try_getValues( + user: Address, + ids: Array, + ): ethereum.CallResult> { + let result = super.tryCall( + "getValues", + "getValues(address,string[]):(uint256[])", + [ethereum.Value.fromAddress(user), ethereum.Value.fromStringArray(ids)], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigIntArray()); + } +} + +export class SetValuesCall extends ethereum.Call { + get inputs(): SetValuesCall__Inputs { + return new SetValuesCall__Inputs(this); + } + + get outputs(): SetValuesCall__Outputs { + return new SetValuesCall__Outputs(this); + } +} + +export class SetValuesCall__Inputs { + _call: SetValuesCall; + + constructor(call: SetValuesCall) { + this._call = call; + } + + get ids(): Array { + return this._call.inputValues[0].value.toStringArray(); + } + + get values(): Array { + return this._call.inputValues[1].value.toBigIntArray(); + } +} + +export class SetValuesCall__Outputs { + _call: SetValuesCall; + + constructor(call: SetValuesCall) { + this._call = call; + } +} diff --git a/src/VeDelegate-Configs.ts b/src/VeDelegate-Configs.ts new file mode 100644 index 0000000..8224d57 --- /dev/null +++ b/src/VeDelegate-Configs.ts @@ -0,0 +1,17 @@ +import { ConfigUpdated as ConfigUpdatedEvent } from '../generated/vedelegate-configs/IVeDelegateConfigs' +import { fetchAccount } from '../node_modules/@openzeppelin/subgraphs/src/fetch/account' +import { VeDelegateConfig } from '../generated/schema'; + +export function handleConfigUpdated(event: ConfigUpdatedEvent): void { + let sender = fetchAccount(event.params.sender) + const id = [sender.id.toHexString(), event.params.configId.toHexString()].join('/') + let config = VeDelegateConfig.load(id) + if (!config) { + config = new VeDelegateConfig(id) + config.account = sender.id + } + + config.configId = event.params.configId.toHexString() + config.value = event.params.value + config.save() +} \ No newline at end of file diff --git a/subgraph.graphql b/subgraph.graphql index 6af5823..a655c94 100644 --- a/subgraph.graphql +++ b/subgraph.graphql @@ -152,6 +152,13 @@ type VeDelegateAccount @entity { token: ERC721Token! } +type VeDelegateConfig @entity { + id: ID! + account: Account! + configId: String! + value: BigInt! +} + type VetDomainsNames @entity { id: String! address: Bytes! diff --git a/subgraph.yaml b/subgraph.yaml index d750042..9fe471b 100644 --- a/subgraph.yaml +++ b/subgraph.yaml @@ -203,6 +203,28 @@ dataSources: handler: handleTransfer file: ./src/VeDelegate-ERC721.ts + # veDelegate.vet Configs + - kind: ethereum/contract + name: vedelegate-configs + network: mainnet + source: + address: "0x763d4da44EDa9DD3d738Ae87F3961c9e92fb5bEe" + abi: IVeDelegateConfigs + startBlock: 19386843 + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - ERC721Contract + abis: + - name: IVeDelegateConfigs + file: ./abis/VeDelegate-Configs.json + eventHandlers: + - event: ConfigUpdated(indexed address,indexed string,uint256) + handler: handleConfigUpdated + file: ./src/VeDelegate-Configs.ts + # Gov: VOT3 Delegation - kind: ethereum/contract name: voting