info_tfgrid/collections/projectinca/specs_blockchain/oracle_contract.md

93 lines
3.2 KiB
Markdown
Raw Permalink Normal View History

2024-08-17 11:22:25 +00:00
# Oracle Contracts
An oracle can get information from the world as well as from other blockchains e.g. price of a token
- name e.g. TFT_PRICE
- description
- address, the address of this oracle contract
- link (link to more info about the oracle)
- multisig_accounts e.g. 9 accounts need to sign
- multisig_min_signature e.g. 6 need to sign, this is for releasing the generated token INCA
- smart_contract_addr: address of the smart contract
- period_measure: period in seconds we will measure
- period_calc: period in seconds over which we will calculate min, max and avg (is rolling window)
## default methods
- get(name:string) -> fl64
- will return minimum, maximum, average over the specified period _calc
## Example record in Blockchain DB
```json
{
"oracle_contract": {
"name": "TFT_PRICE",
"description": "Oracle contract for retrieving TFT token price",
"address": "0xFEDCBA9876543210FEDCBA9876543210FEDCBA98",
"link": "https://example.com/tft_price_oracle_info",
"multisig_accounts": [
"0x1111111111111111111111111111111111111111",
"0x2222222222222222222222222222222222222222",
"0x3333333333333333333333333333333333333333",
"0x4444444444444444444444444444444444444444",
"0x5555555555555555555555555555555555555555",
"0x6666666666666666666666666666666666666666",
"0x7777777777777777777777777777777777777777",
"0x8888888888888888888888888888888888888888",
"0x9999999999999999999999999999999999999999"
],
"multisig_min_signature": 6,
"smart_contract_addr": "0xABCDEF1234567890ABCDEF1234567890ABCDEF12",
"period_measure": 3600,
"period_calc": 86400
}
}
```
### Implementation
```mermaid
sequenceDiagram
participant ExternalSource
participant OracleContract
participant MultisigAccounts
participant SmartContract
participant BlockchainDB
participant Requester
loop Every period_measure (3600 seconds)
ExternalSource->>OracleContract: Provide TFT price data
OracleContract->>SmartContract: Validate and process data
alt Data is valid
SmartContract->>MultisigAccounts: Request signatures
loop Until multisig_min_signature reached
MultisigAccounts->>MultisigAccounts: Collect signatures
end
MultisigAccounts-->>SmartContract: Return collected signatures
alt Sufficient signatures collected
SmartContract->>BlockchainDB: Store price data
BlockchainDB-->>SmartContract: Confirm storage
else Insufficient signatures
SmartContract->>OracleContract: Discard data (insufficient signatures)
end
else Data is invalid
SmartContract->>OracleContract: Reject invalid data
end
end
Requester->>OracleContract: Call get("TFT_PRICE")
OracleContract->>SmartContract: Process request
SmartContract->>BlockchainDB: Retrieve price data for period_calc (86400 seconds)
BlockchainDB-->>SmartContract: Return price data
SmartContract->>SmartContract: Calculate min, max, avg
SmartContract-->>OracleContract: Return calculated values
OracleContract-->>Requester: Provide min, max, avg price
```