RelayerMarketplace

Introduction

This document defines a specification for a Solidity contract where relayers can register themselves and publish the parameters of what they can offer and what they are looking for in return.

Data structures

Type aliases

Name Type Description Example
Protocol bytes32 Supported protocols ETH, BTC .....
ProfileId bytes32 Id generated for each of the profiles added
CapabilityKey bytes32 Capability name latency, bandwidth, latencySLA, bandwidthSLA, ...
CapabilityValue uint256 Capability value
RewardKey bytes32 Reward name perByte, perDay, perMonth, ...
RewardValue uint256 Reward value

Capability

struct Capability {
    CapabilityKey key;
    CapabilityValue value;
}

Reward

struct Reward {
    RewardKey key;
    RewardValue value;
}

RelayerProfileData

struct RelayerProfileData {
    Protocol protocol;
    Capability[] capabilities;
    Reward[] rewards;
}

Relayer

mapping(profileId => RelayerProfileData)

Storage

relayers

relayers: mapping(address => Relayer)

Events

RelayerProfileAdded

event RelayerProfileAdded(profile: ProfileId, protocol: Protocol, capabilities: Capability[], rewards: Reward[], sender: address);

RelayerProfileRemoved

event RelayerProfileRemoved(profileId: ProfileId, sender: address);

RelayerProtocolEdited

event RelayerProtocolEdited(profile: ProfileId, newProtocol: Protocol, sender: address);

RelayerCapabilityEdited

event RelayerCapabilityEdited(profile: ProfileId, capabilities: Capability[], sender: address);

RelayerRewardEdited

event RelayerRewardEdited(profile: ProfileId, rewards: Reward[], sender: address);

Functions

Public

addRelayerProfile

Adds a relayer profile to publish details of capabilities and expected rewards.

function addRelayerProfile(protocol: Protocol, capabilities: Capability[], rewards: Reward[]) {
    bytes32 profileId = keccak256(protocol, msg.sender);
    relayers[msg.sender][profileId].protocol = protocol;
    relayers[msg.sender][profileId].capabilities = capabilities;
    relayers[msg.sender][profileId].rewards = rewards;

    emit RelayerProfileAdded(profileId, protocol, capabilities, rewards, msg.sender);
}

removeRelayerProfile

Removes a relayer profile that is published on the marketplace.

function removeRelayerProfile(profileId: ProfileId) {
    delete relayers[msg.sender][profileId];

    emit RelayerProfileRemoved(profileId, msg.sender);
}

editRelayerProtocol

Edits the protocol for which the profile of relayer is published on the marketplace.

function editRelayerProtocol(profileId: ProfileId, newProtocol: Protocol) {
    relayers[msg.sender][profileId].protocol = newProtocol;

    emit RelayerCapabilityEdited(profileId, newProtocol, msg.sender);
}

editRelayerCapability

Edits the capabilities of the relayer published on the marketplace.

function editRelayerCapability(profileId: ProfileId, capabilities: Capability[]) {
    relayers[msg.sender][profileId].capabilities = capabilities;

    emit RelayerCapabilityEdited(profileId, capabilities, msg.sender);
}

editRelayerReward

Edits the expected rewards of the relayer published on the marketplace.

function editRelayerReward(profileId: ProfileId, rewards: Reward[]) {
    relayers[msg.sender][profileId].rewards = rewards;

    emit RelayerRewardEdited(profileId, rewards, msg.sender);
}

getProfile

Gets a particular relayer profile.

function getProfile(relayerAddress: address, profileId: ProfileId) returns (RelayerProfileData) {
    RelayerProfileData profile = relayers[relayerAddress][profileId];
    require(profile.protocol != 0);

    return profile;
}