Skip to content

Commit 7d763d6

Browse files
author
Van Gulck Rik
committed
Merge.
2 parents 62f5561 + 61a0d33 commit 7d763d6

9 files changed

+706
-7
lines changed

generated/schema.ts

+140
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,23 @@ export class Node extends Entity {
600600
constructor(id: string) {
601601
super();
602602
this.set("id", Value.fromString(id));
603+
604+
this.set("timezone", Value.fromString(""));
605+
this.set("rplStaked", Value.fromBigInt(BigInt.zero()));
606+
this.set("effectiveRPLStaked", Value.fromBigInt(BigInt.zero()));
607+
this.set("totalRPLSlashed", Value.fromBigInt(BigInt.zero()));
608+
this.set("totalClaimedRPLRewards", Value.fromBigInt(BigInt.zero()));
609+
this.set("minimumRPLNeededForMinipools", Value.fromBigInt(BigInt.zero()));
610+
this.set("maximumRPLNeededForMinipools", Value.fromBigInt(BigInt.zero()));
611+
this.set("queuedMinipools", Value.fromBigInt(BigInt.zero()));
612+
this.set("stakingMinipools", Value.fromBigInt(BigInt.zero()));
613+
this.set("stakingUnbondedMinipools", Value.fromBigInt(BigInt.zero()));
614+
this.set("withdrawableMinipools", Value.fromBigInt(BigInt.zero()));
615+
this.set("totalFinalizedMinipools", Value.fromBigInt(BigInt.zero()));
616+
this.set("averageFeeForActiveMinipools", Value.fromBigInt(BigInt.zero()));
617+
this.set("minipools", Value.fromStringArray(new Array(0)));
618+
this.set("block", Value.fromBigInt(BigInt.zero()));
619+
this.set("blockTime", Value.fromBigInt(BigInt.zero()));
603620
}
604621

605622
save(): void {
@@ -760,6 +777,15 @@ export class Node extends Entity {
760777
}
761778
}
762779

780+
get minipools(): Array<string> {
781+
let value = this.get("minipools");
782+
return value!.toStringArray();
783+
}
784+
785+
set minipools(value: Array<string>) {
786+
this.set("minipools", Value.fromStringArray(value));
787+
}
788+
763789
get block(): BigInt {
764790
let value = this.get("block");
765791
return value.toBigInt();
@@ -1606,3 +1632,117 @@ export class NodeBalanceCheckpoint extends Entity {
16061632
this.set("blockTime", Value.fromBigInt(value));
16071633
}
16081634
}
1635+
1636+
export class Minipool extends Entity {
1637+
constructor(id: string) {
1638+
super();
1639+
this.set("id", Value.fromString(id));
1640+
1641+
this.set("node", Value.fromString(""));
1642+
this.set("fee", Value.fromBigInt(BigInt.zero()));
1643+
this.set("queuedBlockTime", Value.fromBigInt(BigInt.zero()));
1644+
this.set("dequeuedBlockTime", Value.fromBigInt(BigInt.zero()));
1645+
this.set("destroyedBlockTime", Value.fromBigInt(BigInt.zero()));
1646+
this.set("stakingBlockTime", Value.fromBigInt(BigInt.zero()));
1647+
this.set("withdrawableBlockTime", Value.fromBigInt(BigInt.zero()));
1648+
this.set("finalizedBlockTime", Value.fromBigInt(BigInt.zero()));
1649+
}
1650+
1651+
save(): void {
1652+
let id = this.get("id");
1653+
assert(id != null, "Cannot save Minipool entity without an ID");
1654+
if (id) {
1655+
assert(
1656+
id.kind == ValueKind.STRING,
1657+
"Cannot save Minipool entity with non-string ID. " +
1658+
'Considering using .toHex() to convert the "id" to a string.'
1659+
);
1660+
store.set("Minipool", id.toString(), this);
1661+
}
1662+
}
1663+
1664+
static load(id: string): Minipool | null {
1665+
return changetype<Minipool | null>(store.get("Minipool", id));
1666+
}
1667+
1668+
get id(): string {
1669+
let value = this.get("id");
1670+
return value!.toString();
1671+
}
1672+
1673+
set id(value: string) {
1674+
this.set("id", Value.fromString(value));
1675+
}
1676+
1677+
get node(): string {
1678+
let value = this.get("node");
1679+
return value!.toString();
1680+
}
1681+
1682+
set node(value: string) {
1683+
this.set("node", Value.fromString(value));
1684+
}
1685+
1686+
get fee(): BigInt {
1687+
let value = this.get("fee");
1688+
return value!.toBigInt();
1689+
}
1690+
1691+
set fee(value: BigInt) {
1692+
this.set("fee", Value.fromBigInt(value));
1693+
}
1694+
1695+
get queuedBlockTime(): BigInt {
1696+
let value = this.get("queuedBlockTime");
1697+
return value!.toBigInt();
1698+
}
1699+
1700+
set queuedBlockTime(value: BigInt) {
1701+
this.set("queuedBlockTime", Value.fromBigInt(value));
1702+
}
1703+
1704+
get dequeuedBlockTime(): BigInt {
1705+
let value = this.get("dequeuedBlockTime");
1706+
return value!.toBigInt();
1707+
}
1708+
1709+
set dequeuedBlockTime(value: BigInt) {
1710+
this.set("dequeuedBlockTime", Value.fromBigInt(value));
1711+
}
1712+
1713+
get destroyedBlockTime(): BigInt {
1714+
let value = this.get("destroyedBlockTime");
1715+
return value!.toBigInt();
1716+
}
1717+
1718+
set destroyedBlockTime(value: BigInt) {
1719+
this.set("destroyedBlockTime", Value.fromBigInt(value));
1720+
}
1721+
1722+
get stakingBlockTime(): BigInt {
1723+
let value = this.get("stakingBlockTime");
1724+
return value!.toBigInt();
1725+
}
1726+
1727+
set stakingBlockTime(value: BigInt) {
1728+
this.set("stakingBlockTime", Value.fromBigInt(value));
1729+
}
1730+
1731+
get withdrawableBlockTime(): BigInt {
1732+
let value = this.get("withdrawableBlockTime");
1733+
return value!.toBigInt();
1734+
}
1735+
1736+
set withdrawableBlockTime(value: BigInt) {
1737+
this.set("withdrawableBlockTime", Value.fromBigInt(value));
1738+
}
1739+
1740+
get finalizedBlockTime(): BigInt {
1741+
let value = this.get("finalizedBlockTime");
1742+
return value!.toBigInt();
1743+
}
1744+
1745+
set finalizedBlockTime(value: BigInt) {
1746+
this.set("finalizedBlockTime", Value.fromBigInt(value));
1747+
}
1748+
}

schema.graphql

+33
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ type Node @entity {
195195
# Last node balance checkpoint for this node.
196196
lastNodeBalanceCheckpoint: NodeBalanceCheckpoint
197197

198+
# Associated minipools for this node.
199+
minipools: [Minipool!]!
200+
198201
# Block number at which this node was first registered with the protocol.
199202
block: BigInt!
200203

@@ -442,4 +445,34 @@ type NodeBalanceCheckpoint @entity {
442445

443446
# Block timestamp that was associated with this checkpoint.
444447
blockTime: BigInt!
448+
}
449+
450+
# Entity representing a minipool for a node.
451+
type Minipool @entity {
452+
# Address of the minipool
453+
id: ID!
454+
455+
# Node that is associated with this minipool
456+
node: Node!
457+
458+
# Fee that is associated with this minipool
459+
fee: BigInt!
460+
461+
# Block timestamp that was associated with the creation of this minipool.
462+
queuedBlockTime: BigInt!
463+
464+
# Block timestamp that was associated with the dequeue of the minipool that will (most of the time) lead to staking.
465+
dequeuedBlockTime: BigInt!
466+
467+
# Block timestamp that was associated with the destruction of this minipool.
468+
destroyedBlockTime: BigInt!
469+
470+
# Block number that was associated with this minipool transitioning to the staking state.
471+
stakingBlockTime: BigInt!
472+
473+
# Block timestamp that was associated with this minipool being marked as withdrawable.
474+
withdrawableBlockTime: BigInt!
475+
476+
# Block timestamp that was associated with this minipool being marked as finalized.
477+
finalizedBlockTime: BigInt!
445478
}

src/entityfactory.ts

+22
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,28 @@ class RocketPoolEntityFactory {
357357

358358
return checkpoint;
359359
}
360+
361+
/**
362+
* Attempts to create a new minipool.
363+
*/
364+
public createMinipool(
365+
id: string,
366+
node: Node,
367+
fee: BigInt,
368+
blockTime: BigInt) {
369+
370+
let minipool = new Minipool(id)
371+
minipool.node = node.id
372+
minipool.fee = fee;
373+
minipool.queuedBlockTime = blockTime
374+
minipool.dequeuedBlockTime = BigInt.fromI32(0)
375+
minipool.destroyedBlockTime = BigInt.fromI32(0)
376+
minipool.stakingBlockTime = BigInt.fromI32(0)
377+
minipool.withdrawableBlockTime = BigInt.fromI32(0)
378+
minipool.finalizedBlockTime = BigInt.fromI32(0)
379+
380+
return minipool
381+
}
360382
}
361383

362384
export let rocketPoolEntityFactory = new RocketPoolEntityFactory();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { BigInt } from '@graphprotocol/graph-ts'
2+
import { rocketStorage } from '../../generated/rocketDAONodeTrusted/rocketStorage';
3+
import { DecrementMemberUnbondedValidatorCountCall, IncrementMemberUnbondedValidatorCountCall } from '../../generated/rocketDAONodeTrusted/rocketDAONodeTrusted'
4+
import { Minipool, Node } from '../../generated/schema'
5+
import { ROCKET_MINIPOOL_MANAGER_CONTRACT_NAME, ROCKET_STORAGE_ADDRESS } from '../constants/contractconstants';
6+
import { generalUtilities } from '../utilities/generalUtilities';
7+
8+
/**
9+
* Occurs after a trusted node operator creates a minipool, via the RocketMinipoolManager.
10+
*/
11+
export function handleIncrementMemberUnbondedValidatorCount(call: IncrementMemberUnbondedValidatorCountCall) : void {
12+
// Preliminary null checks.
13+
if(call === null || call.from === null || call.inputs === null || call.inputs._nodeAddress === null) return;
14+
15+
// Calling address should be something.
16+
let callingAddress = call.from.toHexString();
17+
if(callingAddress == null) return;
18+
19+
// Calling address should be the rocketMinipoolManager
20+
let rocketStorageContract = rocketStorage.bind(ROCKET_STORAGE_ADDRESS);
21+
let rocketMinipoolManagerContractAddress = rocketStorageContract.getAddress(generalUtilities.getRocketVaultContractAddressKey(ROCKET_MINIPOOL_MANAGER_CONTRACT_NAME))
22+
if (rocketMinipoolManagerContractAddress === null ||
23+
rocketMinipoolManagerContractAddress.toHexString() != callingAddress) return
24+
25+
// Retrieve the parent node. It has to exist.
26+
let node = Node.load(call.inputs._nodeAddress.toHexString())
27+
if (node === null) return
28+
29+
// TODO: Change naming.
30+
// Increment total unbonded minipools
31+
node.stakingUnbondedMinipools = node.stakingUnbondedMinipools.plus(BigInt.fromI32(1));
32+
33+
// RPL Effective balances don't need to be updated; this will be done in the finalize call of the RocketMiniPoolManager.
34+
35+
// Index the minipool and the associated node.
36+
node.save();
37+
}
38+
39+
/**
40+
* Occurs after a minipool finalizes his unbonded validator.
41+
*/
42+
export function handleDecrementMemberUnbondedValidatorCount(call: DecrementMemberUnbondedValidatorCountCall) : void {
43+
// Preliminary null checks.
44+
if(call === null || call.from === null || call.inputs === null || call.inputs._nodeAddress === null) return;
45+
46+
// Calling address should be something.
47+
let callingAddress = call.from.toHexString();
48+
if(callingAddress == null) return;
49+
50+
// There must be a minipool with the same address as the calling address.
51+
// If a minipool, it shouldn't be finalized or destroyed.
52+
// If a minipool, it should've been queued, staking and set withdrawable before this.
53+
let minipool = Minipool.load(callingAddress)
54+
if (minipool !== null ||
55+
minipool.queuedBlockTime == BigInt.fromI32(0) ||
56+
minipool.stakingBlockTime == BigInt.fromI32(0) ||
57+
minipool.withdrawableBlockTime == BigInt.fromI32(0) ||
58+
minipool.finalizedBlockTime != BigInt.fromI32(0) ||
59+
minipool.destroyedBlockTime != BigInt.fromI32(0)) return
60+
61+
// Retrieve the parent node. It has to exist.
62+
let node = Node.load(call.inputs._nodeAddress.toHexString())
63+
if (node === null) return
64+
65+
// TODO: Change naming.
66+
// Decrement total unbonded minipools
67+
node.stakingUnbondedMinipools = node.stakingUnbondedMinipools.minus(BigInt.fromI32(1));
68+
if(node.stakingUnbondedMinipools < BigInt.fromI32(0)) node.stakingUnbondedMinipools = BigInt.fromI32(0);
69+
70+
// RPL Effective balances don't need to be updated; this will be done in the finalize call of the RocketMiniPoolManager.
71+
72+
// Index the minipool and the associated node.
73+
node.save();
74+
}

0 commit comments

Comments
 (0)