layout | title |
---|---|
default |
Oracles (Savers) |
- Repo: Saver Lib
- Repo: EVM Saver
- Repo: Solana Saver
- Repo: Near Saver
Managing events' creation requires some special logic for every chain that will observe blockchain state for new events, parse in accordance with chain rules, etc. Rarimo core can not fetch events data by itself because interaction with other systems can not be deterministic. So there should be custom software for observing blockchain state and transferring events from source chain to Rarimo core. That is why we’ve created Oracles.
Rarimo oracles are built to provide everyone an opportunity to deliver and validate cross-chain messages. We believe that architecture constructed on worldwide open and transparent oracles brings the real decentralization into any cross-chain protocol.
In Rarimo oracle’s goal is to observe blockchains state for new events, deliver such events into the Rarimo core and verify events delivered from other oracles. In particular oracles should observe new token deposits, create transfer operations, submit them into the core and vote for correctness of submitted operations.
The oracle services designed to be launched by anyone in two supported modes:
- saver (connects to the chain rpc and submits new transfer operations to the Rarimo core)
- voter (fetches new operations from core, verifies the content and votes for its correctness)
Currently, there are three implementations exists:
- evm-saver (used with any evm-compatible chains)
- solana-saver (used with any solana-compatible chains)
- near-saver (used with any near-compatible chains)
For native and fungible tokens all information should be pre-defined in collections of tokenmanager
module.
So oracles should only fetch the corresponding data and submit it in MsgCreateTransferOp
transaction.
NFT tokens collection can contain huge amount of tokens under it, and also they can be minted if future.
So we can not define all tokens in core during initialization or token add operation. That is why collections flow was
created.
Using tokenmanager
Collection
and CollectionData
we can define collection global and chain information regardless
of the number of tokens in collection or their metadata.
Token information (Item
and OnChainItem
) will be set up during the first token transfer.
During the first transfer oracles should fill the metadata field in MsgCreateTransferOp
and provide all required token
information to create Item
and OnChainItem
.
Token addresses are equal to the token collection addresses that is already defined in Collection
but for token id we
should provide more complicated implementation.
Let's describe the flow more accurately:
-
If token was already transferred between source and destination chain no additional actions required. Oracle just fetches
OnChainItem
from core and leaves metadata field empty. -
If source
OnChainItem
exists but destinationOnChainItem
does no (it means that token never was transferred on destination chain) oracle should construct destinationOnChainItem
using the following rules:
- if destination chain is Solana, tokenId should be derived using bridge address and seed from
Item
metadata (Item
should exist causeOnChainItem
exists) - otherwise tokenId will be equal to the home chain tokenId (the chain where token was minted firstly).
- If source
OnChainItem
does not exists it means that we are transferring token at first time andItem
with its metadata also does not exist. So oracle should createItem
metadata which means fetching on-chain metadata and generation of solana seed. Then using paragraph 2 rules oracle constructs destinationOnChainItem
. SourceOnChainItem
, which is homeOnChainItem
, can be constructed using deposit event information.
In github.com/rarimo/saver-grpc-lib
we defined the common utils for all oracles.
Every oracle should implement verifiers.TransferOperator
interface for every supported token type
and put that implementations into the voter.Subscriber
and voter.Catchupper
using verifiers.TransferVerifier
wrapper.
Also, we recommend to split verifiers.TransferOperator
logic in two methods: verifier and message creator.
It allows to use message creator while fetching new events and submitting them into core.
All oracles recommended to integrate with broadcaster service (broadcaster-svc
) to submit queued transactions. Cause
any transaction should contain valid account sequence
(is incremental value) it becomes problematically to submit concurrent transactions.
So our oracles implementations use broadcaster service as an endpoint for sending messages using a queue.
Saver mode flow:
- Oracle subscribes to the new events on bridge contract.
- Oracle receives new event.
- Oracle creates and submits
MsgCreateTransferOp
usingbroadcaster-svc
.
Voter mode flow:
- Oracle subscribes to the new operations on Rarimo core for defined oracle's chain.
- Oracle receives new operation.
- Oracle verifies operation and if it is correct submits
MsgVote
transaction withYES
vote. Otherwise, oracle submitsMsgVote
transaction withNO
vote. - After operation votes reaches
Quorum
(defined inRarimocore
module)rarimocore
calculates the voting power and vote results. To becomeAPPROVED
there should be at leastThreshold
(defined inGov
module) percentage positive votes. Otherwise, operation becomesNOT_APPROVED
.