aelf Oracle Episode 2: What did aelf oracle do in the mainnet swap?

ælf
aelf
Published in
3 min readSep 15, 2021

--

Some of you guys have swapped mainnet tokens and have participated in the raffle on our website in recent days. How do you like it? Cheap and fast isn’t it? aelf oracle helped. When swapping ERC-20 ELF to mainnet ELF tokens, aelf oracle helps retrieve the LockMapping contract from Ethereum to aelf mainnet so that users could swap their ELF tokens.

SEND: Create off-chain data

Here is the off-chain data is created for the aelf oracle organization on the website.

Enter the amount of ELF and click “Lock”, a transaction will then be sent to the LockMapping contract of Ethereum. The transaction name is createReceipt. This transaction only accomplishes two things:
- Transfer the amount of ELF entered by the user from the user’s Ethereum account to the LockMapping contract;
- The LockMapping contract creates a receipt for the user.

The hash value of each receipt delivers two messages:
- The number of ERC-20 tokens locked;
- The aelf address to receive the tokens.

TRANSMIT: aelf oracle to retrieve off-chain data

One node within the organization will query the contract every one minute or so. When the node finds that a new receipt is created in the LockMapping contract, it will initiate a Query to fetch data.

For example, if the aforementioned oracle node discovers that Ethereum has recently created five new receipts with receipt ids ranging from 101 to 105, then the query_info of this Query transaction is set as:
- Title: record_receipts
- Options: [101, 105]

Also, the callback information (callback_info) is the way to execute the RecordReceiptHash in the Bridge contract. After the Query transaction whose title is “record_receipts” is packaged into a certain block, the corresponding QueryCreated event will start. Subsequently, the aelf oracle node will update the hash value of the 5 receipts (101–105) to the Bridge contract. And finally, users could utilize the receipt information to synchronize in aelf Bridge contract.

RECEIVE:aelf contact to process off-chain data

In the RECEIVE section, users can find the receipt id created for them by the LockMapping contract. Select and click Receive, the swap website will guide the user to send a transaction called SwapToken for the Bridge contract of the aelf mainnet, and help the user fill in the number of ERC20 ELF previously locked by the user in the LockMapping contract (this data is automatically checked by the LockMapping contract Obtain).

In the SwapToken transaction, the Bridge contract will re-hash the user’s aelf address and lock the number of ERC20 ELF tokens. Through Merkle Proof, verify whether the hash value is in a certain Merkle recorded by the MerkleTreeRecorder contract on the aelf mainnet. On the tree. If there is a matching record, the Bridge contract will enter the corresponding amount of ELF for the user (the user will be locked in 105% of the ERC20 ELF within the first 15 days of the currency exchange activity).

That’s the whole process of our mainnet token swap.

Note: Users can visit explorer.aelf.io/vote/ Election to obtain the income of the Citizen Welfare dividend pool by voting on candidate production nodes at any time.

--

--

ælf
aelf

ælf, the next breakthrough in Blockchain.