Skip to content

GuiGou12358/decentralized_oracle-graph-api-oracle

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Graph Api Oracle with Ink! Smart Contract (on Astar Network) and Ink! Phat Contract (on Phala Network)

Scenario described here in the communication between Ink! Smart Contract on Astar Network and Ink! Phat Contract on Phala Network:

  1. The Phat Contract GraphApiOracle (on Phala Network) queries the data from a graph api (subsquid, subquery or graph) and pushes the data into the Smart Contract GraphApiConsumer (on Astar Network)
  2. The Smart Contract GraphApiConsumer (on Astar Network) verifies the data and saves them to be displayed in the UI

You can find a demo here: TODO

The Phat Contract and Ink! Smart Contract have been built with the Phat Offchain Rollup. The full documentation of this SDK can be found here: https://github.com/Phala-Network/phat-offchain-rollup

The Phat Contract GraphApiOracle is implemented by the generic Phat Contract JS Offchain Rollup and a specific js script to in charge of :

  • format the data in input (graph api endpoint + data coming from Ink! Smart Contract by example)
  • query the graph indexer and do business logic
  • format the data in output

We use the @phala/fn CLI tool to generates the js code.

Phat Contract GraphApiOracle

To deploy this Phat Contract you can build the contract or use existing artifacts

More information here: phat/contracts/js_offchain_rollup/README.md

Build the contract

To build the contract:

cd phat/contracts/js_offchain_rollup
cargo contract build

Use existing artifacts

All artifacts are here: phat/artifacts

Ink! Smart Contract GraphApiConsumer

To deploy this Ink! Smart Contract you can build the contract or use existing artifacts

More information here: ink/contracts/graph_api_consumer/README.md

Build the contract

To build the contract:

cd ink/contracts/graph_api_consumer
cargo contract build

Use existing artifacts

All artifacts are here: ink/artifacts

Configure the target contract in the Phat Contract GraphApiOracle

You have to configure the rpc, the pallet id, the call id and the contract id to call the Smart Contract GraphApiConsumer.

For example:

RPC=https://shibuya.public.blastapi.io
PALLET_ID=70
CALL_ID=6
#public key of the contract aesULxtrttD4VGe1oDWGnDihbknjQ44GYwN1L8RXMcWZxis
CONTRACT_ID=0xd0a5af9b2cd1fa7ca7b8c37cb1323b6596c7810b661085dbc32bdcd3a498219c

config_target_contract

Enable Meta-Tx

Meta transaction allows the Phat Contract to submit rollup tx with attest key signature while using arbitrary account to pay the gas fee. To enable meta tx in the unit test you have to set the private key

For example, the private key of account //bob: 0x398f0c28f98885e046333d4a41c19cee4c37368a9832c6502f6cfd182e2aef89

If you don't use Meta-Tx, you have to be sure that address of Phat Contract GraphApiOracle will be able to pay transaction fees on Astar Network.

Configure the graph api in the Phat Contract GraphApiOracle

You have to configure the http endpoint to reach to query the data.

image

image

Configure the js used to query the data in the Phat Contract GraphApiOracle

You have to configure the js source code that will run inside the crate phat::js. The graph api endoing configured above will be given in parameter in the main method of js code. All data comming from the Ink! Smart Contract GraphApiConsumer will be also given in parameters.

image

image

Grant the attestor in the Smart Contract GraphApiConsumer

You have to grant the Phat Contract GraphApiOracle as attestor in the Smart Contract GraphApiConsumer.

If you use the Meta-Tx, you have to grant the ecdsa address.

get_attest_address

If you don't use the Meta-Tx, you have to grant the sr25519 public key.

get_attest_ecdsa_address

And grant the Phat Contract as attestor

image

Register the code hash used to query the data

In the Smart Contract GraphApiConsumer, you have to register the hash of the source code used to query the data by the Phat Contract GraphApiOracle.

Capture

image

Test

Phat Contract GraphApiOracle - Push the data into GraphApiConsumer

Query the data from the graph api and push them into the Smart Contract GraphApiConsumer.

image

image

In result you have the transaction id.

image

Ink! Smart Contract GraphApiConsumer - Read the data coming from GraphApiOracle

image

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 78.5%
  • TypeScript 21.5%