Multichain Gas Station Contract
The multichain gas station smart contract accepts payments in NEAR tokens in exchange for gas funding on non-NEAR foreign chains. Part of the NEAR Multichain effort, it works in conjunction with the MPC recovery service to generate on-chain signatures.
What is it?
This smart contract is a piece of the NEAR Multichain project, which makes NEAR Protocol an effortlessly cross-chain network. This contract accepts EVM transaction request payloads and facilitates the signing, gas funding, and relaying of the signed transactions to their destination chains. It works in conjunction with a few different services, including:
- The MPC recovery service, also called the "MPC signer service", includes a network of trusted MPC signers, which hold keyshares and cooperatively sign transactions on behalf of the MPC network. It also includes an on-chain component, called the "MPC signer contract," which accepts on-chain signature requests and returns signatures computed by the MPC network.
- The multichain relayer server scans this smart contract for signed transaction payloads and emits them to foreign chain RPCs.
How it works
Currently, relaying one transaction to a foreign chain requires three transactions. Three transactions are required because of the gas restrictions imposed by the protocol. Currently (pre-NEP-516), the MPC signing function requires a lot of gas, so dividing up the signing process into three parts is required to maximize the amount of gas available to each signing call.
NEP-516 (delayed receipts / runtime triggers) will reduce the required transactions to one.
Transaction breakdown:
- The first transaction is a call to the
create_transaction
function. This function accepts an EVM transaction request payload and a deposit amount (to pay for gas on the foreign chain) and returns anid
and apending_transactions_count
. - The second transaction is a call to the
sign_next
function. This function accepts theid
returned in step 1 and returns a signed payload. This payload is the gas funding transaction, transferring funds from a paymaster account on the foreign chain to the user's account on the foreign chain. It must be submitted to the foreign chain before the second signed payload. - The third transaction is another call to the
sign_next
function, identical to the one before. This function accepts anid
and returns a signed payload. This payload is the signed user transaction.
Once this service and its supporting services are live, the multichain relayer server will be monitoring this gas station contract and relaying the signed transactions in the proper order as they become available, so it will not be strictly necessary for the users of this contract to ensure that the transactions are properly relayed, unless the user wishes to relay the transactions using their own RPC (e.g. to minimize latency).
Variable Gas fees
There's a premium on the Gas Station in NEAR
for what the gas will cost on the foreign chain to account for variation in both the exchange rate between transactions, settlement between chains, and to account for variation in gas costs until the transaction is confirmed.
BSC
This is the formula for calculating the gas fee:
(gas_limit_of_user_transaction + 21000) * gas_price_of_user_transaction * near_tokens_per_foreign_token * 1.2
21000
is the exact amount of gas necessary to transfer funds onBSC
.1.2
is an arbitrage fee: charge 20% more than market rate to discourage people from using the Gas Station as an arbitrage/DEX.