hoprnet / hopr-devrel

Projects related to support our users, node runners and developers
hopr-prompt.vercel.app
GNU General Public License v3.0
1 stars 12 forks source link

subgraph-dufour #342

Closed MartinBenediktBusch closed 1 year ago

MartinBenediktBusch commented 1 year ago

Overview

We need to program and deploy a subgraph that listens to the smart contracts of the dufour environment for several use cases.

  1. The ct-app needs the subgraph to create a link between the safe-address, node-address, and wxHOPR stake of a node runner to create a distribution strategy based on stake.
  2. The web-app team needs the subgraph to verify the correctness of the onboarding flow.

Expected Outcome of the Subgraph

{
    safeAddress: 0xD720099cBC14e669695EaE0708E6Ca614B387921 // will be searching by this one - you should get this from event of safe creation NodeStakeFactory.clone()
    moduleAddress: 0xD720099cBC14e669695EaE0708E6Ca614B387922 // you should get this from event of safe creation NodeStakeFactory.clone()
    ownerAddress:  0xD720099cBC14e669695EaE0708E6Ca614B387923 // you should get this from event of safe creation NodeStakeFactory.clone() (?), it would be owner, or signer when creating
    nodesRegisteredWithSafe: [
        0xD720099cBC14e669695EaE0708E6Ca614B387924 // will be registered in NetworkRegistry by COMM team, probably needs safe and node Address
    ],
    isSafeInNetwoRegistry: true/false, // should get from the call of registering by COM team,
    balance_xDai: 0, // NATIVE token of the safeAddress
    balance_mHOPR: 0, // balacnecOf of the safeAddress
    balance_wxHOPR: 0, //  balacnecOf of the safeAddress
    balance_xHOPR: 0, //  balacnecOf of the safeAddress
        balance_wxHOPR_in_all_hopr_safes: 0, //  balacnecOf all wxHOPR staked in HOPR safes
    nodesRegisteredWithSafe: [  // can have multiple nodes, we need to structure it somehow
        0xD720099cBC14e669695EaE0708E6Ca614B387924: {
            allowance_wxHOPR: 0,
            allowance_mHOPR: 0,
            xDai: 0 // xDai on nodeAddress
        }
    ],
    includedNode: { ... probably the responce with all data of NodeModule().includeNode(def-permissions)} // NodeModule().includeNode(def-permissions) is a call by Safe
    registerSafeWithNodeSig: { ... probably the responce with all data of HoprNodeSafeRegistry.registerSafeWithNodeSig(NodeSafe memory nodeSafe, bytes calldata sig)} // is a call by Node
}

Current Progress

What is missing

Strategy discussed with Q

// gets updated per // (NodeSafeRegistry.sol) // 1. event RegisteredNodeSafe(address indexed safeAddress, address indexed nodeAddress); // 2. event DergisteredNodeSafe(address indexed safeAddress, address indexed nodeAddress); // (NetworkRegistry.sol) // 3. event Registered(address indexed stakingAccount, address indexed nodeAddress); // Emit when a node is included in // 4. event Deregistered(address indexed stakingAccount, address indexed nodeAddress); // Emit when a node is removed from // 5. event RegisteredByManager(address indexed stakingAccount, address indexed nodeAddress); // Emit when the contract // 6. event DeregisteredByManager(address indexed stakingAccount, address indexed nodeAddress); // Emit when the contract type NodeSafeRegistration @entity { id: ID! // ${nodeAddress}-${safeAddres} nodeAddress: Bytes! safeAddress: Bytes! isRegisteredOnNodeSafeRegistry: Boolean! // gets updated when event 1 or 2 is emitted. Default value is false isRegisteredOnNetworkRegistry: Boolean! // gets updated when event 3 - 6 is emitted. Default value is false }

// gets updated per event 1 - 6, 7 // 7. event EligibilityUpdated(address indexed stakingAccount, bool indexed eligibility); // Emit when the eligibility of type Safe @entity { id: ID! // safeAddress safeAddress: Bytes! nodes: [NodeSafeRegistration!]! @derivedFrom(field: "safeAddress") networkRegistryEligibility: Boolean! // gets updated when event 7 is emitted. Default value is false }

// gets updated per // 8. event RequirementUpdated(address indexed requirementImplementation); // Emit when the network registry proxy is // 9. event NetworkRegistryStatusUpdated(bool indexed isEnabled); // Global toggle of the network registry type NetworkRegistry @entity { id: ID! // ${nodeAddress}-${safeAddres} nodes: [NodeSafeRegistration!]! @derivedFrom(field: "nodeAddress") safes: [Safe!]! @derivedFrom(field: "safeAddress") requirementImplementation: Bytes! // gets updated when event 8 is emitted isEnabled: Boolean! // gets updated when event 9 is emitted. Default value is false }

QYuQianchen commented 1 year ago

Continued the development. Please refer to the README file https://github.com/hoprnet/hopr-devrel/tree/c2553a0d3ca2feb61c1c4141e7ca7f0be13e5baa/subgraph/packages/subgraph-dufour for details

MartinBenediktBusch commented 1 year ago

Deployed the subgraph to my own studio and tested it. Approved to merge :)

QYuQianchen commented 1 year ago

Will publish this subgraph once a new set of rotsee contracts gets deployed. Waiting for auditor's ack before contract deployment