Protocol
The YAR protocol implements a network for delivering on-chain transactions to external networks. It consists of the following elements:
A standard EVM transaction that needs to be delivered
The
YarRequest
smart contract, which serves as the entry pointThe
YarResponse
smart contract, responsible for on-chain transaction deliveryThe
YarHub
the smart contract, located only in YarChain, represents a mempool of cross-chain transactionsThe Solidity structure
YarLib.YarTX
, a wrapper around a standard EVM transaction with additional metadataThe EVM-compatible blockchain YarChain
A network of validators known as Relayers
These elements are combined in the following sequence:
The initiator (EOA wallet or smart contract) calls
YarRequest.send(...)
YarRequest
generates aSend
eventUpon receiving the
Send
event, Relayers add the pending transaction toYarHub
After adding the transaction to the queue, Relayers move transactions into execution, locking a sufficient amount of fees
Relayers call
YarResponse.deliver(...)
, which executes the transaction to the destination addressAfter executing the transaction, Relayers update the transaction status and return any unspent fees
0. Standard EVM Transaction
There are no restrictions on the transactions being sent:
The address in the external network does not need to conform to any specific interface; transactions can be delivered even to EOA wallets
The transaction can transfer the native token, i.e., use the [value] parameter
The transaction can represent another cross-chain call, allowing complex sequences of data transfers across multiple networks
1. YarRequest
Smart Contract
YarRequest
Smart ContractThe starting point of the protocol. It is responsible for sending events to validators.
There are 3 types of unique events:
Send
- sends a cross-chain transaction
Deposit
- replenishes the balance, which is debited to pay for cross-chain transactions
Approve
- similar toEIP20.approve
. Allows applications to debit the user's balance to pay for their cross-chain transaction
Each event corresponds to a function of the same name:
send
- acceptsYarLib.YarTX
and sends it to the Relayers network
deposit
- accepts tokens (native or EIP20) from the user
approve
- allows the [spender] to debit [amount] YarToken from the user's deposit
2. YarResponse
Smart Contract
YarResponse
Smart ContractActs as the entry point for sending transactions by the Relayers network. This is done via the deliver
function, which deploys the cross-chain transaction [yarTx] and delivers it to the recipient.
Additionally, this smart contract is used by applications for authorization if their recipient function should only accept calls from Relayers and not any address.
Temporarily, it stores the metadata of the current cross-chain transaction, which can be accessed in the trustedYarTx
function. The metadata is recorded before the call and deleted immediately afterward.
!!! Passing flags to enable/disable writing trustedYarTx
fields to storage can save gas.
3. YarHub
Smart Contract
YarHub
Smart ContractYarHub
stores all pending, executed, and unexecuted cross-chain transactions, which are accessible in the wrappedYarTXs
mapping.
To access a specific transaction [yarTx]
, the key used is the keccak hash of the entire YarLib.YarTx
model.
You can also obtain the identifying hash of a cross-chain transaction using the [YarHub.getYarTxHash]
method.
YarHub
also stores user deposits in Yar tokens, which are used to pay for transaction fees.
The balance is credited to the deposit only from the relayer’s address after processing the Deposit
event.
To view the current balance:
4. Solidity Structure YarLib.YarTX
YarLib.YarTX
Last updated