Skip to content

Commit

Permalink
Add veDelegate configuration index
Browse files Browse the repository at this point in the history
  • Loading branch information
ifavo committed Aug 30, 2024
1 parent a6ea768 commit 531bdc8
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 0 deletions.
69 changes: 69 additions & 0 deletions abis/VeDelegate-Configs.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
96 changes: 96 additions & 0 deletions generated/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<VeDelegateConfig | null>(
store.get_in_block("VeDelegateConfig", id),
);
}

static load(id: string): VeDelegateConfig | null {
return changetype<VeDelegateConfig | null>(
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();
Expand Down
103 changes: 103 additions & 0 deletions generated/vedelegate-configs/IVeDelegateConfigs.ts
Original file line number Diff line number Diff line change
@@ -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<string>): Array<BigInt> {
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<string>,
): ethereum.CallResult<Array<BigInt>> {
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<string> {
return this._call.inputValues[0].value.toStringArray();
}

get values(): Array<BigInt> {
return this._call.inputValues[1].value.toBigIntArray();
}
}

export class SetValuesCall__Outputs {
_call: SetValuesCall;

constructor(call: SetValuesCall) {
this._call = call;
}
}
17 changes: 17 additions & 0 deletions src/VeDelegate-Configs.ts
Original file line number Diff line number Diff line change
@@ -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()
}
7 changes: 7 additions & 0 deletions subgraph.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
22 changes: 22 additions & 0 deletions subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 531bdc8

Please sign in to comment.