threesigmaxyz / filplus-allocator-bot

A bot that tracks the state and events for the Fillecoin Plus program.
MIT License
0 stars 0 forks source link

Track multisig signers for EVM smart contract accounts #2

Open asynctomatic opened 4 months ago

asynctomatic commented 4 months ago

Description

Currently the bot is only tracking multisig signers for Filecoin multisig actor addresses (ie. f2). Alternatively, allocators must be implemented as an EVM smart contract with a f410 address. In this scenario the bot should be able to query the smart contract to get the list of signers.

❗Currently the allocators contracts are not live on mainnet, so this feature is not yet available.

The following pseudo-code implements the desired functionality:

import { ethAddressFromDelegated } from "@glif/filecoin-address";
import dotenv from "dotenv";
import { ethers } from "ethers";
import { HttpJsonRpcConnector, LotusClient } from "filecoin.js";

import allocatorABI from "./abi/allocator-abi";
import allocatorFactoryABI from "./abi/allocator-factory-abi";

// Initialize configuration from the .env file.
dotenv.config();

// Extract Lotus client configuration from environment variables.
// The default connection uses the endpoint from https://api.node.glif.io/ which is a public Lotus node.
// This endpoint does not require authentication, so the token is not set by default.
// If we run into rate limits we should create an AUTH_TOKEN in the Glif dashboard.
const LOTUS_RPC_ENDPOINT =
  process.env.LOTUS_RPC_ENDPOINT || "https://api.node.glif.io/";
const LOTUS_AUTH_TOKEN = process.env.LOTUS_AUTH_TOKEN || "";

(async () => {
  // Set up the JSON RPC connector with URL and token from environment variables.
  const connector = new HttpJsonRpcConnector({
    url: LOTUS_RPC_ENDPOINT,
    token: LOTUS_AUTH_TOKEN,
  });

  // Initialize the Lotus client with the configured connector.
  const client = new LotusClient(connector);

  // Convert the actor address to an EVM compatible address.
  const multisigAddress = "f410fyfz7afhoduqt4nyac6f44qwccvvux4y6mdusdra";
  const multisigEthAddress = ethAddressFromDelegated(multisigAddress);
  console.log("Multisig Eth Address:", multisigEthAddress);

  // Fetch actor information.
  const actor = await client.state.getActor(multisigAddress);
  console.log("Actor:", actor);

  // Connect to the allocator factory contract.
  const allocatorFactoryAddress = new ethers.Contract(
    allocatorFactoryAddress,
    allocatorFactoryABI,
    filecoinEvmProvider
  );

  // If the contract was not deployed by the allocator factory, it will not be tracked.
  if (await allocatorFactoryAddress.contracts(multisigEthAddress)) {
    // Connect to the allocated contract.
    const allocatorContract = new ethers.Contract(
      multisigEthAddress,
      allocatorABI,
      filecoinEvmProvider
    );

    const signers = await allocatorContract.getAllocators();
    console.log("Signers:", signers);
  }
})()
  .then()
  .catch();

Acceptance Criteria