Joining The Registry

Step 1: Implement the Required Methods

To integrate your protocol into the decentralized solver’s solution and engage in the solving process, you implement the Protocol interface. This interface defines how your protocol interacts with the registry.

Here is the basic structure:

// Protocol defines a generic interface for all types of DeFi protocols.
type Protocol interface {
    // GenerateCalldata creates the necessary blockchain transaction data.
    GenerateCalldata(ctx context.Context, chainID *big.Int, action ContractAction, params TransactionParams) (string, error)

    // Validate checks if the provided parameters are valid for the specified action.
    Validate(ctx context.Context, chainID *big.Int, action ContractAction, params TransactionParams) error

    // GetBalance retrieves the balance for a specified account and asset.
    GetBalance(ctx context.Context, chainID *big.Int, account, asset common.Address) (*big.Int, error)

    // GetSupportedAssets returns a list of assets supported by the protocol on the specified chain.
    GetSupportedAssets(ctx context.Context, chainID *big.Int) ([]common.Address, error)

    // IsSupportedAsset checks if the specified asset is supported on the given chain.
    IsSupportedAsset(ctx context.Context, chainID *big.Int, asset common.Address) bool

    // GetProtocolConfig returns the protocol config for a specific chain.
    GetProtocolConfig(chainID *big.Int) ProtocolConfig

    // GetABI returns the ABI of the protocol's contract, allowing dynamic interaction.
    GetABI(chainID *big.Int) abi.ABI

    // GetType returns the protocol type.
    GetType() ProtocolType

    // GetName returns the human-readable name of the protocol.
    GetName() string

    // GetVersion returns the version of the protocol.
    GetVersion() string

    // GetContractAddress returns the contract address for a specific chain.
    GetContractAddress(chainID *big.Int) common.Address
}

Step 2: Define Supported Chains and Assets

Once your protocol has implemented the interface, you can register it with the Borsa Protocol Registry.

type ProtocolRegistry interface {
  // GetChainConfig retrieves the configuration for a specific chain
    GetChainConfig(chainID *big.Int) (ChainConfig, error)
   
    // RegisterProtocol adds a new protocol to the registry for a specific chain
    RegisterProtocol(chainID *big.Int, address common.Address, protocol Protocol) error

    // GetProtocol retrieves a protocol by its contract address and chain ID
    GetProtocol(chainID *big.Int, address common.Address) (Protocol, error)

    // ListProtocols returns a list of all registered protocols for a specific chain
    ListProtocols(chainID *big.Int) []Protocol

    // ListProtocolsByType lists all protocols of a specific type for a given chain
    ListProtocolsByType(chainID *big.Int, protocolType ProtocolType) []Protocol
}

Provide the following key details for registration:

  • Contract Address: The address of your protocol’s contract.

  • ChainID: The blockchain network where your protocol is deployed.

  • Supported Assets: The tokens and assets your protocol supports on each chain.

This step ensures that your protocol is accessible to the entire Borsa network.

Step 3: Test & Validate

Before going live, it’s essential to test and validate your protocol within the registry. The Validate() method ensures that all transaction parameters are correct and that your protocol interacts smoothly with the Borsa system.

// Validate checks if the parameters are valid for the specified action. 
Validate(ctx context.Context, chainID *big.Int, action ContractAction, params TransactionParams) error

4. Deploy & Extend

After successful testing, your protocol is officially part of the Borsa network. You can also extend its functionality by integrating additional features or cross-chain services. The registry’s extensible design allows protocols to easily scale and provide more services to users.

Last updated