From 86f6cc7e5be439bf23ccd14fef3f28fdf8682cae Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Tue, 4 Oct 2022 23:17:04 +0200 Subject: [PATCH 01/42] Create rng-oracle-bridge --- docs/learn/crosschain_guide/rng-oracle-bridge | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 docs/learn/crosschain_guide/rng-oracle-bridge diff --git a/docs/learn/crosschain_guide/rng-oracle-bridge b/docs/learn/crosschain_guide/rng-oracle-bridge new file mode 100644 index 00000000..714ef8c8 --- /dev/null +++ b/docs/learn/crosschain_guide/rng-oracle-bridge @@ -0,0 +1,58 @@ +# RNG ORACLE BRIDGE + +## REPOSITORY + +You can find the repository for the RNG Oracle Bridge [here](https://github.com/telosnetwork/rng-oracle-bridge) + +## HOW IT WORKS + +The method we use is similar to Chainlink's Direct funding method. You must directly fund consuming contracts with TLOS tokens before they request randomness. + +The `callback_gas` variable contains the gas units you estimate will be needed to call your `receiveRandom()` callback function in your own smart contract (ie: 50000). This is the maximum amount of gas that will be spent by the bridge when calling your contract. + +### Note on transaction costs. + +Because the consuming contract directly pays the TLOS for the request, the cost is calculated during the request and not during the callback when the randomness is fulfilled. Test your callback function to learn how to correctly estimate the callback gas limit. + +You can query the TLOS value to pass in your `request()` function call by calling the `calculateRequestPrice(uint callback_gas)` public function. + +You can alternatively calculate that price by taking the gas price from the `GasOracleBridge` with `getPrice()`, multiply that price with your estimate gas units (ie: 50000) and add the fee from the `RNGOracleBridge` that you can query with `fee()`: + +`Price = Gas Units * Gas Price + Bridge Fee` + +If the gas limit is underestimated, the callback fails and the consuming contract is still charged for the work done to generate the requested random values. +If the gas limit is overestimated, the callback function will be executed but your contract is not refunded for the excess gas amount that you paid. +Make sure that your consuming contracts are funded with enough TLOS tokens to cover the transaction costs. If the consuming contract doesn't have enough TLOS tokens, your request will revert. + +## REQUEST & RECEIVE DATA + +![RNGOracleBridge](https://user-images.githubusercontent.com/5913758/193873078-b8e2e7ab-1f33-41d8-ac47-32ec81548c64.jpg) + +## MAKE A REQUEST ! + +Deploy a contract that calls the `RNGOracleBridge` contract's `request()` function, passing a value to cover fee and callback gas cost (refer to the **callback gas** section further ahead). + +``` +interface IRNGOracleBridge { + function request(uint callId, uint64 seed, uint callback_gas, address callback_address, uint number_count) external payable; +} + +contract MyContract { + IRNGOracleBridge bridge; + + constructor(address _bridge) { + bridge = IRNGOracleBridge(_bridge); + } + + function makeRequest(uint64 seed, uint callback_gas, uint count) external payable { + ... YOUR LOGIC TO SETUP THE CALLID, ETC... + bridge.request{value: msg.value }(callId, seed, callback_gas, address(this), count); + } +} +``` + +The request function takes in a **callId**, for you to keep track of the requests & handle answers later, a **seed** for the random generation that you can generate however you like as long as it fits into 64 bytes, the **callback_gas** unit (see below), the **callback_address** where to call your implementation of the callback function and the **number_count** of requested numbers. + +On the same contract, or in a new one, implement a `receiveRandom(uint callId, uint[] numbers) external` callback function in order to receive the oracle's answer. + +You can refer to the [`RNGOracleConsumer`](https://github.com/telosnetwork/rng-oracle-bridge/blob/main/evm/contracts/RNGOracleConsumer.sol) EVM contract for an example. From 54f3cbf6281aaa3e6193b06ad933f9e3f413acd0 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Tue, 4 Oct 2022 23:21:20 +0200 Subject: [PATCH 02/42] Rename rng-oracle-bridge to rng-oracle-bridge.md --- .../crosschain_guide/{rng-oracle-bridge => rng-oracle-bridge.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/learn/crosschain_guide/{rng-oracle-bridge => rng-oracle-bridge.md} (100%) diff --git a/docs/learn/crosschain_guide/rng-oracle-bridge b/docs/learn/crosschain_guide/rng-oracle-bridge.md similarity index 100% rename from docs/learn/crosschain_guide/rng-oracle-bridge rename to docs/learn/crosschain_guide/rng-oracle-bridge.md From dd3351f6ebb1e434b97dd4443a9da1e67c59517c Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Tue, 4 Oct 2022 23:22:01 +0200 Subject: [PATCH 03/42] Update rng-oracle-bridge.md --- docs/learn/crosschain_guide/rng-oracle-bridge.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/learn/crosschain_guide/rng-oracle-bridge.md b/docs/learn/crosschain_guide/rng-oracle-bridge.md index 714ef8c8..85260398 100644 --- a/docs/learn/crosschain_guide/rng-oracle-bridge.md +++ b/docs/learn/crosschain_guide/rng-oracle-bridge.md @@ -4,6 +4,12 @@ You can find the repository for the RNG Oracle Bridge [here](https://github.com/telosnetwork/rng-oracle-bridge) +## DEPLOYMENTS + +**MAINNET:** TBD + +**TESTNET:** TBD + ## HOW IT WORKS The method we use is similar to Chainlink's Direct funding method. You must directly fund consuming contracts with TLOS tokens before they request randomness. From 5adcd6f60b72e22864a37d4b72b7c4efd91f6023 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Tue, 4 Oct 2022 23:24:32 +0200 Subject: [PATCH 04/42] Update rng-oracle-bridge.md --- .../crosschain_guide/rng-oracle-bridge.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/learn/crosschain_guide/rng-oracle-bridge.md b/docs/learn/crosschain_guide/rng-oracle-bridge.md index 85260398..300cad45 100644 --- a/docs/learn/crosschain_guide/rng-oracle-bridge.md +++ b/docs/learn/crosschain_guide/rng-oracle-bridge.md @@ -59,6 +59,21 @@ contract MyContract { The request function takes in a **callId**, for you to keep track of the requests & handle answers later, a **seed** for the random generation that you can generate however you like as long as it fits into 64 bytes, the **callback_gas** unit (see below), the **callback_address** where to call your implementation of the callback function and the **number_count** of requested numbers. -On the same contract, or in a new one, implement a `receiveRandom(uint callId, uint[] numbers) external` callback function in order to receive the oracle's answer. +On the same contract, or in a new one, implement a `receiveRandom(uint callId, uint[] numbers) external` callback function in order to receive the oracle's answer, like so: -You can refer to the [`RNGOracleConsumer`](https://github.com/telosnetwork/rng-oracle-bridge/blob/main/evm/contracts/RNGOracleConsumer.sol) EVM contract for an example. + +``` +contract MyContract { + IRNGOracleBridge bridge; + + constructor(address _bridge) { + bridge = IRNGOracleBridge(_bridge); + } + + function receiveRandom(callId, numbers){ + // Handle whatever logic you need with the random numbers received here + } +} +``` + +You can refer to the [`RNGOracleConsumer`](https://github.com/telosnetwork/rng-oracle-bridge/blob/main/evm/contracts/RNGOracleConsumer.sol) EVM contract for a complete example. From a56706abdd19c96a545b623602f8604e40d54c45 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Tue, 4 Oct 2022 23:25:46 +0200 Subject: [PATCH 05/42] Update rng-oracle-bridge.md --- docs/learn/crosschain_guide/rng-oracle-bridge.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/learn/crosschain_guide/rng-oracle-bridge.md b/docs/learn/crosschain_guide/rng-oracle-bridge.md index 300cad45..22be414d 100644 --- a/docs/learn/crosschain_guide/rng-oracle-bridge.md +++ b/docs/learn/crosschain_guide/rng-oracle-bridge.md @@ -71,7 +71,10 @@ contract MyContract { } function receiveRandom(callId, numbers){ + require(msg.sender == address(bridge), "Only the bridge contract can call this function"); + // Handle whatever logic you need with the random numbers received here + } } ``` From 1b0349ecf664e435a8ffb35aae8f04d055f30a0d Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Tue, 4 Oct 2022 23:31:40 +0200 Subject: [PATCH 06/42] Update rng-oracle-bridge.md --- docs/learn/crosschain_guide/rng-oracle-bridge.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/learn/crosschain_guide/rng-oracle-bridge.md b/docs/learn/crosschain_guide/rng-oracle-bridge.md index 22be414d..77608af1 100644 --- a/docs/learn/crosschain_guide/rng-oracle-bridge.md +++ b/docs/learn/crosschain_guide/rng-oracle-bridge.md @@ -10,6 +10,12 @@ You can find the repository for the RNG Oracle Bridge [here](https://github.com/ **TESTNET:** TBD +## IMPORTANT CONSIDERATIONS + +There is a max request per consumer contract, if you reach it, wait for an answer or use the `deleteRequestorRequest(address requestor, uint callId)` method from your the smart contract that made the request to delete one. + +Your implementation of the `receiveRandom()` callback function must not revert + ## HOW IT WORKS The method we use is similar to Chainlink's Direct funding method. You must directly fund consuming contracts with TLOS tokens before they request randomness. From 1d8771b76112c6a5590ad599a7503a73cc892274 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Tue, 4 Oct 2022 23:32:16 +0200 Subject: [PATCH 07/42] Update rng-oracle-bridge.md --- docs/learn/crosschain_guide/rng-oracle-bridge.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/learn/crosschain_guide/rng-oracle-bridge.md b/docs/learn/crosschain_guide/rng-oracle-bridge.md index 77608af1..5e58d99a 100644 --- a/docs/learn/crosschain_guide/rng-oracle-bridge.md +++ b/docs/learn/crosschain_guide/rng-oracle-bridge.md @@ -12,7 +12,7 @@ You can find the repository for the RNG Oracle Bridge [here](https://github.com/ ## IMPORTANT CONSIDERATIONS -There is a max request per consumer contract, if you reach it, wait for an answer or use the `deleteRequestorRequest(address requestor, uint callId)` method from your the smart contract that made the request to delete one. +There is a max request per consumer contract, set at 25 for now, if you reach it wait for an answer or use the `deleteRequestorRequest(address requestor, uint callId)` method from your the smart contract that made that request to delete one. Your implementation of the `receiveRandom()` callback function must not revert From af1b59e715dc6531039c98cf4a623ce8451cb1c6 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Tue, 4 Oct 2022 23:32:44 +0200 Subject: [PATCH 08/42] Update rng-oracle-bridge.md --- docs/learn/crosschain_guide/rng-oracle-bridge.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/learn/crosschain_guide/rng-oracle-bridge.md b/docs/learn/crosschain_guide/rng-oracle-bridge.md index 5e58d99a..a8b927fc 100644 --- a/docs/learn/crosschain_guide/rng-oracle-bridge.md +++ b/docs/learn/crosschain_guide/rng-oracle-bridge.md @@ -10,12 +10,6 @@ You can find the repository for the RNG Oracle Bridge [here](https://github.com/ **TESTNET:** TBD -## IMPORTANT CONSIDERATIONS - -There is a max request per consumer contract, set at 25 for now, if you reach it wait for an answer or use the `deleteRequestorRequest(address requestor, uint callId)` method from your the smart contract that made that request to delete one. - -Your implementation of the `receiveRandom()` callback function must not revert - ## HOW IT WORKS The method we use is similar to Chainlink's Direct funding method. You must directly fund consuming contracts with TLOS tokens before they request randomness. @@ -86,3 +80,9 @@ contract MyContract { ``` You can refer to the [`RNGOracleConsumer`](https://github.com/telosnetwork/rng-oracle-bridge/blob/main/evm/contracts/RNGOracleConsumer.sol) EVM contract for a complete example. + +## IMPORTANT CONSIDERATIONS + +There is a max request per consumer contract, set at 25 for now, if you reach it wait for an answer or use the `deleteRequestorRequest(address requestor, uint callId)` method from your the smart contract that made that request to delete one. + +Your implementation of the `receiveRandom()` callback function must not revert From e98e06658d5d0707582dcc5f072a89dfc3d00b79 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Tue, 4 Oct 2022 23:33:20 +0200 Subject: [PATCH 09/42] Create delphi-oracle-bridge.md --- docs/learn/crosschain_guide/delphi-oracle-bridge.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/learn/crosschain_guide/delphi-oracle-bridge.md diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md new file mode 100644 index 00000000..512d67bd --- /dev/null +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -0,0 +1 @@ +# DELPHI ORACLE BRIDGE From 39eeb1a227dbea079c60d289d5a7633772d1b7f9 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Tue, 4 Oct 2022 23:33:57 +0200 Subject: [PATCH 10/42] Create gas-oracle-bridge.md --- docs/learn/crosschain_guide/gas-oracle-bridge.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/learn/crosschain_guide/gas-oracle-bridge.md diff --git a/docs/learn/crosschain_guide/gas-oracle-bridge.md b/docs/learn/crosschain_guide/gas-oracle-bridge.md new file mode 100644 index 00000000..186a2932 --- /dev/null +++ b/docs/learn/crosschain_guide/gas-oracle-bridge.md @@ -0,0 +1 @@ +# GAS ORACLE BRIDGE From 7166ddcf29db4ee5c3002b0e03d428fa767b2a86 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 00:54:44 +0200 Subject: [PATCH 11/42] Update delphi-oracle-bridge.md --- .../crosschain_guide/delphi-oracle-bridge.md | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md index 512d67bd..7b7c8a6a 100644 --- a/docs/learn/crosschain_guide/delphi-oracle-bridge.md +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -1 +1,32 @@ # DELPHI ORACLE BRIDGE + +## REPOSITORY + +You can find the repository for the Delphi Oracle Bridge [here](https://github.com/telosnetwork/delphi-oracle-bridge) + +## DEPLOYMENTS + +**MAINNET:** TBD + +**TESTNET:** TBD + +## HOW IT WORKS + +The method we use is similar to Chainlink's Direct funding method. You must directly fund consuming contracts with TLOS tokens before they request randomness. + +The `callback_gas` variable contains the gas units you estimate will be needed to call your `receiveDatapoints()` callback function in your own smart contract (ie: 50000). This is the maximum amount of gas that will be spent by the bridge when calling your contract. + +### Note on transaction costs. + +Because the consuming contract directly pays the TLOS for the request, the cost is calculated during the request and not during the callback when the randomness is fulfilled. Test your callback function to learn how to correctly estimate the callback gas limit. + +You can query the TLOS value to pass in your `request()` function call by calling the `calculateRequestPrice(uint callback_gas)` public function. + +You can alternatively calculate that price by taking the gas price from the `GasOracleBridge` with `getPrice()`, multiply that price with your estimate gas units (ie: 50000) and add the fee from the `DelphiOracleBridge` that you can query with `fee()`: + +`Price = Gas Units * Gas Price + Bridge Fee` + +If the gas limit is underestimated, the callback fails and the consuming contract is still charged for the work done to generate the requested random values. +If the gas limit is overestimated, the callback function will be executed but your contract is not refunded for the excess gas amount that you paid. +Make sure that your consuming contracts are funded with enough TLOS tokens to cover the transaction costs. If the consuming contract doesn't have enough TLOS tokens, your request will revert. + From 33265a2b39883db4f86c3370466a8a5c7c159839 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 00:57:23 +0200 Subject: [PATCH 12/42] Update rng-oracle-bridge.md --- docs/learn/crosschain_guide/rng-oracle-bridge.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/learn/crosschain_guide/rng-oracle-bridge.md b/docs/learn/crosschain_guide/rng-oracle-bridge.md index a8b927fc..65c61a55 100644 --- a/docs/learn/crosschain_guide/rng-oracle-bridge.md +++ b/docs/learn/crosschain_guide/rng-oracle-bridge.md @@ -63,6 +63,10 @@ On the same contract, or in a new one, implement a `receiveRandom(uint callId, u ``` +interface IRNGOracleBridge { + function request(uint callId, uint64 seed, uint callback_gas, address callback_address, uint number_count) external payable; +} + contract MyContract { IRNGOracleBridge bridge; From 793f63dd4040a54a0358b8313013add908a5ba9c Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 01:02:47 +0200 Subject: [PATCH 13/42] Update delphi-oracle-bridge.md --- .../crosschain_guide/delphi-oracle-bridge.md | 69 ++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md index 7b7c8a6a..50fddd8d 100644 --- a/docs/learn/crosschain_guide/delphi-oracle-bridge.md +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -12,7 +12,7 @@ You can find the repository for the Delphi Oracle Bridge [here](https://github.c ## HOW IT WORKS -The method we use is similar to Chainlink's Direct funding method. You must directly fund consuming contracts with TLOS tokens before they request randomness. +The method we use is similar to Chainlink's Direct funding method. You must directly fund consuming contracts with TLOS tokens before they request datapoints. The `callback_gas` variable contains the gas units you estimate will be needed to call your `receiveDatapoints()` callback function in your own smart contract (ie: 50000). This is the maximum amount of gas that will be spent by the bridge when calling your contract. @@ -28,5 +28,70 @@ You can alternatively calculate that price by taking the gas price from the `Gas If the gas limit is underestimated, the callback fails and the consuming contract is still charged for the work done to generate the requested random values. If the gas limit is overestimated, the callback function will be executed but your contract is not refunded for the excess gas amount that you paid. -Make sure that your consuming contracts are funded with enough TLOS tokens to cover the transaction costs. If the consuming contract doesn't have enough TLOS tokens, your request will revert. +Make sure that your consuming contracts are funded with enough TLOS tokens to cover the transaction costs. If the consuming contract doesn't have enough TLOS tokens, your request will revert. + +## MAKE A REQUEST ! + +Deploy a contract that calls the `RNGOracleBridge` contract's `request()` function, passing a value to cover fee and callback gas cost (refer to the **callback gas** section further ahead). + +``` +interface IDelphiOracleBridge { + function request(uint callId, string calldata pair, uint limit, uint callback_gas, address callback_address) external payable; +} + +contract MyContract { + IDelphiOracleBridge bridge; + + constructor(address _bridge) { + bridge = IRNGOracleBridge(_bridge); + } + + function makeRequest(string calldata pair, uint limit, uint callback_gas) external payable { + ... YOUR LOGIC TO SETUP THE CALLID, ETC... + bridge.request{value: msg.value }(callId, pair, limit, callback_gas, address(this)); + } +} +``` + +The request function takes in a **callId**, for you to keep track of the requests & handle answers later, the **pair** you are requesting, the **limit** of the datapoints to receive, the **callback_gas** unit (see below) and the **callback_address** where to call your implementation of the callback function. + +On the same contract, or in a new one, implement a `receiveDatapoints(uint callId, Datapoint[] calldata datapoints) external` callback function in order to receive the oracle's answer, like so: + + +``` +interface IDelphiOracleBridge { + function request(uint callId, string calldata pair, uint limit, uint callback_gas, address callback_address) external payable; +} + +contract MyContract { + IDelphiOracleBridge bridge; + + struct Datapoint { + string pair; + string owner; + uint timestamp; + uint median; + uint value; + } + + constructor(address _bridge) { + bridge = IDelphiOracleBridge(_bridge); + } + + function receiveDatapoints(uint callId, Datapoint[] calldata datapoints) external { + require(msg.sender == address(bridge), "Only the bridge contract can call this function"); + + // Handle whatever logic you need with the random numbers received here + + } +} +``` + +You can refer to the [`DelphiOracleConsumer`](https://github.com/telosnetwork/delphi-oracle-bridge/blob/main/evm/contracts/DelphiOracleConsumer.sol) EVM contract for a complete example. + +## IMPORTANT CONSIDERATIONS + +There is a max request per consumer contract, set at 25 for now, if you reach it wait for an answer or use the `deleteRequestorRequest(address requestor, uint callId)` method from your the smart contract that made that request to delete one. + +Your implementation of the `receiveDatapoints()` callback function must not revert From ac9789b5c0b2b2331e8ddc3c3f74355871f3e7f0 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 01:03:46 +0200 Subject: [PATCH 14/42] Update delphi-oracle-bridge.md --- docs/learn/crosschain_guide/delphi-oracle-bridge.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md index 50fddd8d..bc4c112e 100644 --- a/docs/learn/crosschain_guide/delphi-oracle-bridge.md +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -14,11 +14,11 @@ You can find the repository for the Delphi Oracle Bridge [here](https://github.c The method we use is similar to Chainlink's Direct funding method. You must directly fund consuming contracts with TLOS tokens before they request datapoints. -The `callback_gas` variable contains the gas units you estimate will be needed to call your `receiveDatapoints()` callback function in your own smart contract (ie: 50000). This is the maximum amount of gas that will be spent by the bridge when calling your contract. +The `callback_gas` variable contains the maximum gas units you estimate will be needed to call your `receiveDatapoints()` callback function in your own smart contract (ie: 50000). This is the maximum amount of gas that will be spent by the bridge when calling your contract. ### Note on transaction costs. -Because the consuming contract directly pays the TLOS for the request, the cost is calculated during the request and not during the callback when the randomness is fulfilled. Test your callback function to learn how to correctly estimate the callback gas limit. +Because the consuming contract directly pays the TLOS for the request, the cost is calculated during the request and not during the callback when the request is fulfilled. Test your callback function to learn how to correctly estimate the callback gas limit. You can query the TLOS value to pass in your `request()` function call by calling the `calculateRequestPrice(uint callback_gas)` public function. From 5c69ba17e737ec834620eab839f606820d789f5e Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 02:02:50 +0200 Subject: [PATCH 15/42] Update delphi-oracle-bridge.md --- docs/learn/crosschain_guide/delphi-oracle-bridge.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md index bc4c112e..15377cfa 100644 --- a/docs/learn/crosschain_guide/delphi-oracle-bridge.md +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -30,9 +30,14 @@ If the gas limit is underestimated, the callback fails and the consuming contrac If the gas limit is overestimated, the callback function will be executed but your contract is not refunded for the excess gas amount that you paid. Make sure that your consuming contracts are funded with enough TLOS tokens to cover the transaction costs. If the consuming contract doesn't have enough TLOS tokens, your request will revert. +## REQUEST & RECEIVE DATAPOINTS + +![DelphiOracleBridge](https://user-images.githubusercontent.com/5913758/193951928-58a946c3-622e-4b96-8873-d02b7bedea33.jpg) + + ## MAKE A REQUEST ! -Deploy a contract that calls the `RNGOracleBridge` contract's `request()` function, passing a value to cover fee and callback gas cost (refer to the **callback gas** section further ahead). +Deploy a contract that calls the `DelphiOracleBridge` contract's `request()` function, passing a value to cover fee and callback gas cost (refer to the **Note on transaction costs** section above). ``` interface IDelphiOracleBridge { From 203e40457deb0ae4f71474ba1d03004ee3c2782a Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 02:04:15 +0200 Subject: [PATCH 16/42] Update delphi-oracle-bridge.md --- docs/learn/crosschain_guide/delphi-oracle-bridge.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md index 15377cfa..5fced1b0 100644 --- a/docs/learn/crosschain_guide/delphi-oracle-bridge.md +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -96,7 +96,11 @@ You can refer to the [`DelphiOracleConsumer`](https://github.com/telosnetwork/de ## IMPORTANT CONSIDERATIONS +Your implementation of the `receiveDatapoints()` callback function must not revert + +## LIMITS + There is a max request per consumer contract, set at 25 for now, if you reach it wait for an answer or use the `deleteRequestorRequest(address requestor, uint callId)` method from your the smart contract that made that request to delete one. -Your implementation of the `receiveDatapoints()` callback function must not revert +The maximum limit of datapoints you can request is 10. From 03d0879e100f0f528624a902d139c2c0752527eb Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 02:04:35 +0200 Subject: [PATCH 17/42] Update delphi-oracle-bridge.md --- docs/learn/crosschain_guide/delphi-oracle-bridge.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md index 5fced1b0..9c43d13a 100644 --- a/docs/learn/crosschain_guide/delphi-oracle-bridge.md +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -102,5 +102,5 @@ Your implementation of the `receiveDatapoints()` callback function must not reve There is a max request per consumer contract, set at 25 for now, if you reach it wait for an answer or use the `deleteRequestorRequest(address requestor, uint callId)` method from your the smart contract that made that request to delete one. -The maximum limit of datapoints you can request is 10. +The maximum limit of datapoints you can request for a pair is 10. From 9a62ff4cd534942cc3038bd76d71be16d700d174 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 02:05:28 +0200 Subject: [PATCH 18/42] Update delphi-oracle-bridge.md --- docs/learn/crosschain_guide/delphi-oracle-bridge.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md index 9c43d13a..88fc179b 100644 --- a/docs/learn/crosschain_guide/delphi-oracle-bridge.md +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -102,5 +102,5 @@ Your implementation of the `receiveDatapoints()` callback function must not reve There is a max request per consumer contract, set at 25 for now, if you reach it wait for an answer or use the `deleteRequestorRequest(address requestor, uint callId)` method from your the smart contract that made that request to delete one. -The maximum limit of datapoints you can request for a pair is 10. +The maximum limit of datapoints you can request for a pair is 10. Note that there may be less datapoints received depending on the pair and the data available. From b3129efc1851307e18c820d25fea86ac786e0e4b Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 02:06:38 +0200 Subject: [PATCH 19/42] Update delphi-oracle-bridge.md --- docs/learn/crosschain_guide/delphi-oracle-bridge.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md index 88fc179b..59402dc0 100644 --- a/docs/learn/crosschain_guide/delphi-oracle-bridge.md +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -86,7 +86,7 @@ contract MyContract { function receiveDatapoints(uint callId, Datapoint[] calldata datapoints) external { require(msg.sender == address(bridge), "Only the bridge contract can call this function"); - // Handle whatever logic you need with the random numbers received here + // Handle whatever logic you need with the datapoints received here } } From 6522c22e3fbe737e47992be61050cadb47e59ba6 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 03:01:19 +0200 Subject: [PATCH 20/42] Update gas-oracle-bridge.md --- docs/learn/crosschain_guide/gas-oracle-bridge.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/learn/crosschain_guide/gas-oracle-bridge.md b/docs/learn/crosschain_guide/gas-oracle-bridge.md index 186a2932..479eedd0 100644 --- a/docs/learn/crosschain_guide/gas-oracle-bridge.md +++ b/docs/learn/crosschain_guide/gas-oracle-bridge.md @@ -1 +1,16 @@ # GAS ORACLE BRIDGE + +## REPOSITORY +You can find the repository for the Delphi Oracle Bridge here + +## DEPLOYMENTS + +**MAINNET:** TBD + +**TESTNET:** TBD + +## HOW IT WORKS + +Listeners compare the gas price stored on the `GasOracleBridge` EVM contract to the one stored and the `eosio.evm` Antelope contract. If they are different they notify the bridge's antelope contract to query the new price from `eosio.evm` and update the bridge's EVM contract accordingly. + +You can query the current gas price by calling the `getPrice()` public function of the `GasOracleBridge` contract on EVM. From 6984490ddb53eaf81bc54e96b657117d0fe92264 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 03:01:55 +0200 Subject: [PATCH 21/42] Update gas-oracle-bridge.md --- docs/learn/crosschain_guide/gas-oracle-bridge.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/learn/crosschain_guide/gas-oracle-bridge.md b/docs/learn/crosschain_guide/gas-oracle-bridge.md index 479eedd0..9fb2c202 100644 --- a/docs/learn/crosschain_guide/gas-oracle-bridge.md +++ b/docs/learn/crosschain_guide/gas-oracle-bridge.md @@ -1,7 +1,7 @@ # GAS ORACLE BRIDGE ## REPOSITORY -You can find the repository for the Delphi Oracle Bridge here +You can find the repository for the Gas Oracle Bridge [here](https://github.com/telosnetwork/gas-oracle-bridge) ## DEPLOYMENTS From b947397e706494174dfcf9a6ed15bd03f1ac03cc Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 03:02:31 +0200 Subject: [PATCH 22/42] Update gas-oracle-bridge.md --- docs/learn/crosschain_guide/gas-oracle-bridge.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/learn/crosschain_guide/gas-oracle-bridge.md b/docs/learn/crosschain_guide/gas-oracle-bridge.md index 9fb2c202..6bd7cde5 100644 --- a/docs/learn/crosschain_guide/gas-oracle-bridge.md +++ b/docs/learn/crosschain_guide/gas-oracle-bridge.md @@ -11,6 +11,6 @@ You can find the repository for the Gas Oracle Bridge [here](https://github.com/ ## HOW IT WORKS -Listeners compare the gas price stored on the `GasOracleBridge` EVM contract to the one stored and the `eosio.evm` Antelope contract. If they are different they notify the bridge's antelope contract to query the new price from `eosio.evm` and update the bridge's EVM contract accordingly. +A listener compares the gas price stored on the `GasOracleBridge` EVM contract to the one stored and the `eosio.evm` Antelope contract. If they are different they notify the bridge's antelope contract to query the new price from `eosio.evm` and update the bridge's EVM contract accordingly. You can query the current gas price by calling the `getPrice()` public function of the `GasOracleBridge` contract on EVM. From eb221ee8c0508889da68f25992efdb9e1e4a3100 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 03:09:12 +0200 Subject: [PATCH 23/42] Update gas-oracle-bridge.md --- docs/learn/crosschain_guide/gas-oracle-bridge.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/learn/crosschain_guide/gas-oracle-bridge.md b/docs/learn/crosschain_guide/gas-oracle-bridge.md index 6bd7cde5..107ccc32 100644 --- a/docs/learn/crosschain_guide/gas-oracle-bridge.md +++ b/docs/learn/crosschain_guide/gas-oracle-bridge.md @@ -14,3 +14,5 @@ You can find the repository for the Gas Oracle Bridge [here](https://github.com/ A listener compares the gas price stored on the `GasOracleBridge` EVM contract to the one stored and the `eosio.evm` Antelope contract. If they are different they notify the bridge's antelope contract to query the new price from `eosio.evm` and update the bridge's EVM contract accordingly. You can query the current gas price by calling the `getPrice()` public function of the `GasOracleBridge` contract on EVM. + +![GasOracleBridge](https://user-images.githubusercontent.com/5913758/193957976-e97593b9-9154-4dd3-9f4c-a6ba7eec78b3.jpg) From a73ed553c7c702ff4e2fa205566dd7a5b9c1639a Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 04:38:52 +0200 Subject: [PATCH 24/42] Update delphi-oracle-bridge.md --- docs/learn/crosschain_guide/delphi-oracle-bridge.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md index 59402dc0..d9494cc2 100644 --- a/docs/learn/crosschain_guide/delphi-oracle-bridge.md +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -12,6 +12,8 @@ You can find the repository for the Delphi Oracle Bridge [here](https://github.c ## HOW IT WORKS +Your contract will need to make a call to the `request(uint callId, string calldata pair, uint limit, uint callback_gas, address callback_address)` function of the DelphiOracleBridge and you will need to implement a `receiveDatapoints()` callback function in the same or another contract. Refer to the **Make a request** section below. + The method we use is similar to Chainlink's Direct funding method. You must directly fund consuming contracts with TLOS tokens before they request datapoints. The `callback_gas` variable contains the maximum gas units you estimate will be needed to call your `receiveDatapoints()` callback function in your own smart contract (ie: 50000). This is the maximum amount of gas that will be spent by the bridge when calling your contract. @@ -20,7 +22,7 @@ The `callback_gas` variable contains the maximum gas units you estimate will be Because the consuming contract directly pays the TLOS for the request, the cost is calculated during the request and not during the callback when the request is fulfilled. Test your callback function to learn how to correctly estimate the callback gas limit. -You can query the TLOS value to pass in your `request()` function call by calling the `calculateRequestPrice(uint callback_gas)` public function. +You can query the TLOS value to pass in your `request(uint callId, string calldata pair, uint limit, uint callback_gas, address callback_address)` function call by calling the `calculateRequestPrice(uint callback_gas)` public function. You can alternatively calculate that price by taking the gas price from the `GasOracleBridge` with `getPrice()`, multiply that price with your estimate gas units (ie: 50000) and add the fee from the `DelphiOracleBridge` that you can query with `fee()`: @@ -37,7 +39,7 @@ Make sure that your consuming contracts are funded with enough TLOS tokens to co ## MAKE A REQUEST ! -Deploy a contract that calls the `DelphiOracleBridge` contract's `request()` function, passing a value to cover fee and callback gas cost (refer to the **Note on transaction costs** section above). +Deploy a contract that calls the `DelphiOracleBridge` contract's `request(uint callId, string calldata pair, uint limit, uint callback_gas, address callback_address)` function, passing a value to cover fee and callback gas cost (refer to the **Note on transaction costs** section above). ``` interface IDelphiOracleBridge { From c2ae57932f3f7859a164e2ef1ac935e5aab4a58a Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 04:39:41 +0200 Subject: [PATCH 25/42] Update delphi-oracle-bridge.md --- docs/learn/crosschain_guide/delphi-oracle-bridge.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md index d9494cc2..16a966fc 100644 --- a/docs/learn/crosschain_guide/delphi-oracle-bridge.md +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -12,11 +12,11 @@ You can find the repository for the Delphi Oracle Bridge [here](https://github.c ## HOW IT WORKS -Your contract will need to make a call to the `request(uint callId, string calldata pair, uint limit, uint callback_gas, address callback_address)` function of the DelphiOracleBridge and you will need to implement a `receiveDatapoints()` callback function in the same or another contract. Refer to the **Make a request** section below. +Your contract will need to make a call to the `request(uint callId, string calldata pair, uint limit, uint callback_gas, address callback_address)` function of the DelphiOracleBridge and you will need to implement a `receiveDatapoints(uint callId, Datapoint[] calldata datapoints)` callback function in the same or another contract. Refer to the **Make a request** section below. The method we use is similar to Chainlink's Direct funding method. You must directly fund consuming contracts with TLOS tokens before they request datapoints. -The `callback_gas` variable contains the maximum gas units you estimate will be needed to call your `receiveDatapoints()` callback function in your own smart contract (ie: 50000). This is the maximum amount of gas that will be spent by the bridge when calling your contract. +The `callback_gas` variable contains the maximum gas units you estimate will be needed to call your `receiveDatapoints(uint callId, Datapoint[] calldata datapoints)` callback function in your own smart contract (ie: 50000). This is the maximum amount of gas that will be spent by the bridge when calling your contract. ### Note on transaction costs. From 0641a5ab93b9f6d77f943137a495174fe9e2776c Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 04:40:41 +0200 Subject: [PATCH 26/42] Update delphi-oracle-bridge.md --- docs/learn/crosschain_guide/delphi-oracle-bridge.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md index 16a966fc..7eb24620 100644 --- a/docs/learn/crosschain_guide/delphi-oracle-bridge.md +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -12,7 +12,7 @@ You can find the repository for the Delphi Oracle Bridge [here](https://github.c ## HOW IT WORKS -Your contract will need to make a call to the `request(uint callId, string calldata pair, uint limit, uint callback_gas, address callback_address)` function of the DelphiOracleBridge and you will need to implement a `receiveDatapoints(uint callId, Datapoint[] calldata datapoints)` callback function in the same or another contract. Refer to the **Make a request** section below. +Your contract will need to make a call to the `request(uint callId, string calldata pair, uint limit, uint callback_gas, address callback_address)` function of the `DelphiOracleBridge` contract and you will need to implement a `receiveDatapoints(uint callId, Datapoint[] calldata datapoints)` callback function in the same or in another contract (see the **callback_address** argument). Refer to the **Make a request** section below. The method we use is similar to Chainlink's Direct funding method. You must directly fund consuming contracts with TLOS tokens before they request datapoints. From f8f36c198a0ee690f7b68378196473b5f260a5ea Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 04:41:12 +0200 Subject: [PATCH 27/42] Update delphi-oracle-bridge.md --- docs/learn/crosschain_guide/delphi-oracle-bridge.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md index 7eb24620..6328e883 100644 --- a/docs/learn/crosschain_guide/delphi-oracle-bridge.md +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -12,11 +12,11 @@ You can find the repository for the Delphi Oracle Bridge [here](https://github.c ## HOW IT WORKS -Your contract will need to make a call to the `request(uint callId, string calldata pair, uint limit, uint callback_gas, address callback_address)` function of the `DelphiOracleBridge` contract and you will need to implement a `receiveDatapoints(uint callId, Datapoint[] calldata datapoints)` callback function in the same or in another contract (see the **callback_address** argument). Refer to the **Make a request** section below. +Your contract will need to make a call to the `request(uint callId, string calldata pair, uint limit, uint callback_gas, address callback_address)` function of the `DelphiOracleBridge` contract and you will need to implement a `receiveDatapoints(uint callId, Datapoint[] calldata datapoints)` callback function in the same or in another contract (see the **callback_address** parameter). Refer to the **Make a request** section below. The method we use is similar to Chainlink's Direct funding method. You must directly fund consuming contracts with TLOS tokens before they request datapoints. -The `callback_gas` variable contains the maximum gas units you estimate will be needed to call your `receiveDatapoints(uint callId, Datapoint[] calldata datapoints)` callback function in your own smart contract (ie: 50000). This is the maximum amount of gas that will be spent by the bridge when calling your contract. +The `callback_gas` parameter contains the maximum gas units you estimate will be needed to call your `receiveDatapoints(uint callId, Datapoint[] calldata datapoints)` callback function in your own smart contract (ie: 50000). This is the maximum amount of gas that will be spent by the bridge when calling your contract. ### Note on transaction costs. From 8166fac81cab5e100a477faaa6a4693fdfcf5589 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 04:42:03 +0200 Subject: [PATCH 28/42] Update delphi-oracle-bridge.md --- docs/learn/crosschain_guide/delphi-oracle-bridge.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md index 6328e883..09eef127 100644 --- a/docs/learn/crosschain_guide/delphi-oracle-bridge.md +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -22,7 +22,7 @@ The `callback_gas` parameter contains the maximum gas units you estimate will be Because the consuming contract directly pays the TLOS for the request, the cost is calculated during the request and not during the callback when the request is fulfilled. Test your callback function to learn how to correctly estimate the callback gas limit. -You can query the TLOS value to pass in your `request(uint callId, string calldata pair, uint limit, uint callback_gas, address callback_address)` function call by calling the `calculateRequestPrice(uint callback_gas)` public function. +You can query the TLOS value to pass in your `request(uint callId, string calldata pair, uint limit, uint callback_gas, address callback_address)` function call by calling the `calculateRequestPrice(uint callback_gas)` public function beforehand. You can alternatively calculate that price by taking the gas price from the `GasOracleBridge` with `getPrice()`, multiply that price with your estimate gas units (ie: 50000) and add the fee from the `DelphiOracleBridge` that you can query with `fee()`: From 4e24919e462a70f9e39da83ba84d5a05ce12ffa2 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 04:42:28 +0200 Subject: [PATCH 29/42] Update delphi-oracle-bridge.md --- docs/learn/crosschain_guide/delphi-oracle-bridge.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md index 09eef127..627c06fd 100644 --- a/docs/learn/crosschain_guide/delphi-oracle-bridge.md +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -26,7 +26,7 @@ You can query the TLOS value to pass in your `request(uint callId, string callda You can alternatively calculate that price by taking the gas price from the `GasOracleBridge` with `getPrice()`, multiply that price with your estimate gas units (ie: 50000) and add the fee from the `DelphiOracleBridge` that you can query with `fee()`: -`Price = Gas Units * Gas Price + Bridge Fee` +`Price = (Gas Units * Gas Price) + Bridge Fee` If the gas limit is underestimated, the callback fails and the consuming contract is still charged for the work done to generate the requested random values. If the gas limit is overestimated, the callback function will be executed but your contract is not refunded for the excess gas amount that you paid. From f92488b4f6d74021dc5653df288bb7f2b328fff5 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 04:43:15 +0200 Subject: [PATCH 30/42] Update delphi-oracle-bridge.md --- docs/learn/crosschain_guide/delphi-oracle-bridge.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md index 627c06fd..9f897b56 100644 --- a/docs/learn/crosschain_guide/delphi-oracle-bridge.md +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -30,7 +30,7 @@ You can alternatively calculate that price by taking the gas price from the `Gas If the gas limit is underestimated, the callback fails and the consuming contract is still charged for the work done to generate the requested random values. If the gas limit is overestimated, the callback function will be executed but your contract is not refunded for the excess gas amount that you paid. -Make sure that your consuming contracts are funded with enough TLOS tokens to cover the transaction costs. If the consuming contract doesn't have enough TLOS tokens, your request will revert. +Make sure that your consuming contracts are funded with enough TLOS tokens to cover the transaction costs. ## REQUEST & RECEIVE DATAPOINTS From df328e04c00d348f346bc6a074c85d4fd712af70 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 04:43:41 +0200 Subject: [PATCH 31/42] Update delphi-oracle-bridge.md --- docs/learn/crosschain_guide/delphi-oracle-bridge.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md index 9f897b56..2d66eec5 100644 --- a/docs/learn/crosschain_guide/delphi-oracle-bridge.md +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -98,7 +98,7 @@ You can refer to the [`DelphiOracleConsumer`](https://github.com/telosnetwork/de ## IMPORTANT CONSIDERATIONS -Your implementation of the `receiveDatapoints()` callback function must not revert +Your implementation of the `receiveDatapoints()` callback function must not revert, we will not handle it. ## LIMITS From 1de4fdb8cef1477be391b1e0c8873a21a0a369e0 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 04:44:58 +0200 Subject: [PATCH 32/42] Update delphi-oracle-bridge.md --- docs/learn/crosschain_guide/delphi-oracle-bridge.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md index 2d66eec5..2c0a8b23 100644 --- a/docs/learn/crosschain_guide/delphi-oracle-bridge.md +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -100,6 +100,8 @@ You can refer to the [`DelphiOracleConsumer`](https://github.com/telosnetwork/de Your implementation of the `receiveDatapoints()` callback function must not revert, we will not handle it. +Requesting a non existant pair, or a pair that has no data will return an empty Datapoint array. + ## LIMITS There is a max request per consumer contract, set at 25 for now, if you reach it wait for an answer or use the `deleteRequestorRequest(address requestor, uint callId)` method from your the smart contract that made that request to delete one. From b8150d5ef9660cadf3622b542c012ff7e22dd6c5 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 04:45:46 +0200 Subject: [PATCH 33/42] Update delphi-oracle-bridge.md --- docs/learn/crosschain_guide/delphi-oracle-bridge.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md index 2c0a8b23..668d886d 100644 --- a/docs/learn/crosschain_guide/delphi-oracle-bridge.md +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -104,7 +104,7 @@ Requesting a non existant pair, or a pair that has no data will return an empty ## LIMITS -There is a max request per consumer contract, set at 25 for now, if you reach it wait for an answer or use the `deleteRequestorRequest(address requestor, uint callId)` method from your the smart contract that made that request to delete one. +There is a max request per consumer contract, set at 25 for now, if you reach it wait for an answer or use the `deleteRequestorRequest(address requestor, uint callId)` method from the smart contract that made that request to delete one. The maximum limit of datapoints you can request for a pair is 10. Note that there may be less datapoints received depending on the pair and the data available. From ee33068c67f93168c25230adba0cd67070fa0500 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 05:01:03 +0200 Subject: [PATCH 34/42] Update rng-oracle-bridge.md --- docs/learn/crosschain_guide/rng-oracle-bridge.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/learn/crosschain_guide/rng-oracle-bridge.md b/docs/learn/crosschain_guide/rng-oracle-bridge.md index 65c61a55..ea42fcce 100644 --- a/docs/learn/crosschain_guide/rng-oracle-bridge.md +++ b/docs/learn/crosschain_guide/rng-oracle-bridge.md @@ -32,7 +32,7 @@ Make sure that your consuming contracts are funded with enough TLOS tokens to co ## REQUEST & RECEIVE DATA -![RNGOracleBridge](https://user-images.githubusercontent.com/5913758/193873078-b8e2e7ab-1f33-41d8-ac47-32ec81548c64.jpg) +![RNGOracleBridge](https://user-images.githubusercontent.com/5913758/193971791-6e4ceda4-c55f-45d6-81ef-2122d80e5963.jpg) ## MAKE A REQUEST ! @@ -87,6 +87,8 @@ You can refer to the [`RNGOracleConsumer`](https://github.com/telosnetwork/rng-o ## IMPORTANT CONSIDERATIONS -There is a max request per consumer contract, set at 25 for now, if you reach it wait for an answer or use the `deleteRequestorRequest(address requestor, uint callId)` method from your the smart contract that made that request to delete one. - Your implementation of the `receiveRandom()` callback function must not revert + +## LIMITS + +There is a max request per consumer contract, set at 25 for now, if you reach it wait for an answer or use the `deleteRequestorRequest(address requestor, uint callId)` method from your the smart contract that made that request to delete one. From 59ee9a9712e78061c0b46b72ba527eafb54ac6cc Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 05:03:31 +0200 Subject: [PATCH 35/42] Update delphi-oracle-bridge.md --- docs/learn/crosschain_guide/delphi-oracle-bridge.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md index 668d886d..61c0d904 100644 --- a/docs/learn/crosschain_guide/delphi-oracle-bridge.md +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -32,7 +32,7 @@ If the gas limit is underestimated, the callback fails and the consuming contrac If the gas limit is overestimated, the callback function will be executed but your contract is not refunded for the excess gas amount that you paid. Make sure that your consuming contracts are funded with enough TLOS tokens to cover the transaction costs. -## REQUEST & RECEIVE DATAPOINTS +## DIAGRAM ![DelphiOracleBridge](https://user-images.githubusercontent.com/5913758/193951928-58a946c3-622e-4b96-8873-d02b7bedea33.jpg) From a10493aea5e245c4705d4d96821e32b9ead07d5e Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 05:03:49 +0200 Subject: [PATCH 36/42] Update rng-oracle-bridge.md --- docs/learn/crosschain_guide/rng-oracle-bridge.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/learn/crosschain_guide/rng-oracle-bridge.md b/docs/learn/crosschain_guide/rng-oracle-bridge.md index ea42fcce..da059db5 100644 --- a/docs/learn/crosschain_guide/rng-oracle-bridge.md +++ b/docs/learn/crosschain_guide/rng-oracle-bridge.md @@ -30,7 +30,7 @@ If the gas limit is underestimated, the callback fails and the consuming contrac If the gas limit is overestimated, the callback function will be executed but your contract is not refunded for the excess gas amount that you paid. Make sure that your consuming contracts are funded with enough TLOS tokens to cover the transaction costs. If the consuming contract doesn't have enough TLOS tokens, your request will revert. -## REQUEST & RECEIVE DATA +## DIAGRAM ![RNGOracleBridge](https://user-images.githubusercontent.com/5913758/193971791-6e4ceda4-c55f-45d6-81ef-2122d80e5963.jpg) From 6daa2d15515b02eebb5d5a6be12c093483b6b9bf Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 05:05:34 +0200 Subject: [PATCH 37/42] Update rng-oracle-bridge.md --- docs/learn/crosschain_guide/rng-oracle-bridge.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/learn/crosschain_guide/rng-oracle-bridge.md b/docs/learn/crosschain_guide/rng-oracle-bridge.md index da059db5..20d57776 100644 --- a/docs/learn/crosschain_guide/rng-oracle-bridge.md +++ b/docs/learn/crosschain_guide/rng-oracle-bridge.md @@ -12,9 +12,11 @@ You can find the repository for the RNG Oracle Bridge [here](https://github.com/ ## HOW IT WORKS +Your contract will need to make a call to the `request(uint callId, uint64 seed, uint callback_gas, address callback_address, uint number_count)` function of the `RNGOracleBridge` contract and you will need to implement a `receiveRandom(uint callId, uint[] numbers)` callback function in the same or in another contract (see the **callback_address** parameter). Refer to the **Make a request** section below. + The method we use is similar to Chainlink's Direct funding method. You must directly fund consuming contracts with TLOS tokens before they request randomness. -The `callback_gas` variable contains the gas units you estimate will be needed to call your `receiveRandom()` callback function in your own smart contract (ie: 50000). This is the maximum amount of gas that will be spent by the bridge when calling your contract. +The `callback_gas` variable contains the gas units you estimate will be needed to call your `receiveRandom(uint callId, uint[] numbers)` callback function in your own smart contract (ie: 50000). This is the maximum amount of gas that will be spent by the bridge when calling your contract. ### Note on transaction costs. From 780b18624bd83e86e74f5ae3e8398e6d1d600af5 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 05:06:35 +0200 Subject: [PATCH 38/42] Update rng-oracle-bridge.md --- docs/learn/crosschain_guide/rng-oracle-bridge.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/learn/crosschain_guide/rng-oracle-bridge.md b/docs/learn/crosschain_guide/rng-oracle-bridge.md index 20d57776..cbe73cf5 100644 --- a/docs/learn/crosschain_guide/rng-oracle-bridge.md +++ b/docs/learn/crosschain_guide/rng-oracle-bridge.md @@ -16,7 +16,7 @@ Your contract will need to make a call to the `request(uint callId, uint64 seed, The method we use is similar to Chainlink's Direct funding method. You must directly fund consuming contracts with TLOS tokens before they request randomness. -The `callback_gas` variable contains the gas units you estimate will be needed to call your `receiveRandom(uint callId, uint[] numbers)` callback function in your own smart contract (ie: 50000). This is the maximum amount of gas that will be spent by the bridge when calling your contract. +The `callback_gas` parameter contains the gas units you estimate will be needed to call your `receiveRandom(uint callId, uint[] numbers)` callback function in your own smart contract (ie: 50000). This is the maximum amount of gas that will be spent by the bridge when calling your contract. ### Note on transaction costs. From 84ba6801d9d8a7a50731f55d92bd7e21df5f14b1 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 05:07:51 +0200 Subject: [PATCH 39/42] Update rng-oracle-bridge.md --- docs/learn/crosschain_guide/rng-oracle-bridge.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/learn/crosschain_guide/rng-oracle-bridge.md b/docs/learn/crosschain_guide/rng-oracle-bridge.md index cbe73cf5..d9ef9247 100644 --- a/docs/learn/crosschain_guide/rng-oracle-bridge.md +++ b/docs/learn/crosschain_guide/rng-oracle-bridge.md @@ -94,3 +94,5 @@ Your implementation of the `receiveRandom()` callback function must not revert ## LIMITS There is a max request per consumer contract, set at 25 for now, if you reach it wait for an answer or use the `deleteRequestorRequest(address requestor, uint callId)` method from your the smart contract that made that request to delete one. + +There is a max number count per request, set at 25 for now. From f39527771552fbfff919e6d8c78164ba23985bbb Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 05:08:49 +0200 Subject: [PATCH 40/42] Update rng-oracle-bridge.md --- docs/learn/crosschain_guide/rng-oracle-bridge.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/learn/crosschain_guide/rng-oracle-bridge.md b/docs/learn/crosschain_guide/rng-oracle-bridge.md index d9ef9247..c50b3f6f 100644 --- a/docs/learn/crosschain_guide/rng-oracle-bridge.md +++ b/docs/learn/crosschain_guide/rng-oracle-bridge.md @@ -59,7 +59,7 @@ contract MyContract { } ``` -The request function takes in a **callId**, for you to keep track of the requests & handle answers later, a **seed** for the random generation that you can generate however you like as long as it fits into 64 bytes, the **callback_gas** unit (see below), the **callback_address** where to call your implementation of the callback function and the **number_count** of requested numbers. +The `request()` function takes in a **callId**, for you to keep track of the requests & handle answers later, a **seed** for the random generation that you can generate however you like as long as it fits into 64 bytes, the **callback_gas** unit (see below), the **callback_address** where to call your implementation of the callback function and the **number_count** of requested numbers. On the same contract, or in a new one, implement a `receiveRandom(uint callId, uint[] numbers) external` callback function in order to receive the oracle's answer, like so: From 7a9b57160e9367de9a7149cd363f72015dff3c69 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 17:00:10 +0200 Subject: [PATCH 41/42] Update rng-oracle-bridge.md --- docs/learn/crosschain_guide/rng-oracle-bridge.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/learn/crosschain_guide/rng-oracle-bridge.md b/docs/learn/crosschain_guide/rng-oracle-bridge.md index c50b3f6f..85486fd9 100644 --- a/docs/learn/crosschain_guide/rng-oracle-bridge.md +++ b/docs/learn/crosschain_guide/rng-oracle-bridge.md @@ -43,6 +43,7 @@ Deploy a contract that calls the `RNGOracleBridge` contract's `request()` functi ``` interface IRNGOracleBridge { function request(uint callId, uint64 seed, uint callback_gas, address callback_address, uint number_count) external payable; + function calculateRequestPrice(uint callback_gas) external view returns(uint); } contract MyContract { @@ -54,7 +55,12 @@ contract MyContract { function makeRequest(uint64 seed, uint callback_gas, uint count) external payable { ... YOUR LOGIC TO SETUP THE CALLID, ETC... - bridge.request{value: msg.value }(callId, seed, callback_gas, address(this), count); + + uint price = bridge.calculateRequestPrice(callback_gas); + require(price > 0, "Could not calculate price"); + require(address(this).balance >= price, "Contract balance is too low"); + + bridge.request{value: price }(callId, seed, callback_gas, address(this), count); } } ``` @@ -67,6 +73,7 @@ On the same contract, or in a new one, implement a `receiveRandom(uint callId, u ``` interface IRNGOracleBridge { function request(uint callId, uint64 seed, uint callback_gas, address callback_address, uint number_count) external payable; + function calculateRequestPrice(uint callback_gas) external view returns(uint); } contract MyContract { @@ -96,3 +103,5 @@ Your implementation of the `receiveRandom()` callback function must not revert There is a max request per consumer contract, set at 25 for now, if you reach it wait for an answer or use the `deleteRequestorRequest(address requestor, uint callId)` method from your the smart contract that made that request to delete one. There is a max number count per request, set at 25 for now. + +The maximum callback gas is: From 666c83b51b0e139e26281f65ca2a867c347ebf51 Mon Sep 17 00:00:00 2001 From: Thomas Cuvillier Date: Wed, 5 Oct 2022 17:01:31 +0200 Subject: [PATCH 42/42] Update delphi-oracle-bridge.md --- docs/learn/crosschain_guide/delphi-oracle-bridge.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/learn/crosschain_guide/delphi-oracle-bridge.md b/docs/learn/crosschain_guide/delphi-oracle-bridge.md index 61c0d904..8ab77275 100644 --- a/docs/learn/crosschain_guide/delphi-oracle-bridge.md +++ b/docs/learn/crosschain_guide/delphi-oracle-bridge.md @@ -44,6 +44,7 @@ Deploy a contract that calls the `DelphiOracleBridge` contract's `request(uint c ``` interface IDelphiOracleBridge { function request(uint callId, string calldata pair, uint limit, uint callback_gas, address callback_address) external payable; + function calculateRequestPrice(uint callback_gas) external view returns(uint); } contract MyContract { @@ -54,7 +55,13 @@ contract MyContract { } function makeRequest(string calldata pair, uint limit, uint callback_gas) external payable { + ... YOUR LOGIC TO SETUP THE CALLID, ETC... + + uint price = bridge.calculateRequestPrice(callback_gas); + require(price > 0, "Could not calculate price"); + require(address(this).balance >= price, "Contract balance is too low"); + bridge.request{value: msg.value }(callId, pair, limit, callback_gas, address(this)); } } @@ -68,6 +75,7 @@ On the same contract, or in a new one, implement a `receiveDatapoints(uint callI ``` interface IDelphiOracleBridge { function request(uint callId, string calldata pair, uint limit, uint callback_gas, address callback_address) external payable; + function calculateRequestPrice(uint callback_gas) external view returns(uint); } contract MyContract {