From 507f2d4aaa1f6035be6ff36c3f8b5bc498618770 Mon Sep 17 00:00:00 2001 From: Sawit Trisirisatayawong Date: Thu, 17 Oct 2024 06:51:35 +0700 Subject: [PATCH] feat: update slinky oracle contract to connect v2 --- abis/ConnectOracle.json | 52 +++++++ abis/IConnectOracle.json | 54 ++++++++ abis/ISlinky.abi.json | 122 ----------------- abis/Slinky.abi.json | 127 ------------------ src/{Slinky.sol => ConnectOracle.sol} | 20 ++- .../{ISlinky.sol => IConnectOracle.sol} | 2 +- src/interfaces/ICosmos.sol | 2 +- 7 files changed, 117 insertions(+), 262 deletions(-) create mode 100644 abis/ConnectOracle.json create mode 100644 abis/IConnectOracle.json delete mode 100644 abis/ISlinky.abi.json delete mode 100644 abis/Slinky.abi.json rename src/{Slinky.sol => ConnectOracle.sol} (86%) rename src/interfaces/{ISlinky.sol => IConnectOracle.sol} (94%) diff --git a/abis/ConnectOracle.json b/abis/ConnectOracle.json new file mode 100644 index 0000000..1f74970 --- /dev/null +++ b/abis/ConnectOracle.json @@ -0,0 +1,52 @@ +[ + { "type": "constructor", "inputs": [], "stateMutability": "nonpayable" }, + { + "type": "function", + "name": "get_all_currency_pairs", + "inputs": [], + "outputs": [{ "name": "", "type": "string", "internalType": "string" }], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "get_price", + "inputs": [{ "name": "pair_id", "type": "string", "internalType": "string" }], + "outputs": [ + { + "name": "", + "type": "tuple", + "internalType": "struct ConnectOracle.Price", + "components": [ + { "name": "price", "type": "uint256", "internalType": "uint256" }, + { "name": "timestamp", "type": "uint256", "internalType": "uint256" }, + { "name": "height", "type": "uint64", "internalType": "uint64" }, + { "name": "nonce", "type": "uint64", "internalType": "uint64" }, + { "name": "decimal", "type": "uint64", "internalType": "uint64" }, + { "name": "id", "type": "uint64", "internalType": "uint64" } + ] + } + ], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "get_prices", + "inputs": [{ "name": "pair_ids", "type": "string[]", "internalType": "string[]" }], + "outputs": [ + { + "name": "", + "type": "tuple[]", + "internalType": "struct ConnectOracle.Price[]", + "components": [ + { "name": "price", "type": "uint256", "internalType": "uint256" }, + { "name": "timestamp", "type": "uint256", "internalType": "uint256" }, + { "name": "height", "type": "uint64", "internalType": "uint64" }, + { "name": "nonce", "type": "uint64", "internalType": "uint64" }, + { "name": "decimal", "type": "uint64", "internalType": "uint64" }, + { "name": "id", "type": "uint64", "internalType": "uint64" } + ] + } + ], + "stateMutability": "nonpayable" + } +] diff --git a/abis/IConnectOracle.json b/abis/IConnectOracle.json new file mode 100644 index 0000000..8ee7765 --- /dev/null +++ b/abis/IConnectOracle.json @@ -0,0 +1,54 @@ +[ + { + "type": "function", + "name": "get_all_currency_pairs", + "inputs": [], + "outputs": [{ "name": "", "type": "string", "internalType": "string" }], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "get_price", + "inputs": [ + { "name": "base", "type": "string", "internalType": "string" }, + { "name": "quote", "type": "string", "internalType": "string" } + ], + "outputs": [ + { + "name": "", + "type": "tuple", + "internalType": "struct ConnectOracle.Price", + "components": [ + { "name": "price", "type": "uint256", "internalType": "uint256" }, + { "name": "timestamp", "type": "uint256", "internalType": "uint256" }, + { "name": "height", "type": "uint64", "internalType": "uint64" }, + { "name": "nonce", "type": "uint64", "internalType": "uint64" }, + { "name": "decimal", "type": "uint64", "internalType": "uint64" }, + { "name": "id", "type": "uint64", "internalType": "uint64" } + ] + } + ], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "get_prices", + "inputs": [{ "name": "pair_ids", "type": "string[]", "internalType": "string[]" }], + "outputs": [ + { + "name": "", + "type": "tuple[]", + "internalType": "struct ConnectOracle.Price[]", + "components": [ + { "name": "price", "type": "uint256", "internalType": "uint256" }, + { "name": "timestamp", "type": "uint256", "internalType": "uint256" }, + { "name": "height", "type": "uint64", "internalType": "uint64" }, + { "name": "nonce", "type": "uint64", "internalType": "uint64" }, + { "name": "decimal", "type": "uint64", "internalType": "uint64" }, + { "name": "id", "type": "uint64", "internalType": "uint64" } + ] + } + ], + "stateMutability": "nonpayable" + } +] diff --git a/abis/ISlinky.abi.json b/abis/ISlinky.abi.json deleted file mode 100644 index 79f253f..0000000 --- a/abis/ISlinky.abi.json +++ /dev/null @@ -1,122 +0,0 @@ -[ - { - "type": "function", - "name": "get_all_currency_pairs", - "inputs": [], - "outputs": [ - { - "name": "", - "type": "string", - "internalType": "string" - } - ], - "stateMutability": "nonpayable" - }, - { - "type": "function", - "name": "get_price", - "inputs": [ - { - "name": "base", - "type": "string", - "internalType": "string" - }, - { - "name": "quote", - "type": "string", - "internalType": "string" - } - ], - "outputs": [ - { - "name": "", - "type": "tuple", - "internalType": "struct ISlinky.Price", - "components": [ - { - "name": "price", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "timestamp", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "height", - "type": "uint64", - "internalType": "uint64" - }, - { - "name": "nonce", - "type": "uint64", - "internalType": "uint64" - }, - { - "name": "decimal", - "type": "uint64", - "internalType": "uint64" - }, - { - "name": "id", - "type": "uint64", - "internalType": "uint64" - } - ] - } - ], - "stateMutability": "nonpayable" - }, - { - "type": "function", - "name": "get_prices", - "inputs": [ - { - "name": "pair_ids", - "type": "string[]", - "internalType": "string[]" - } - ], - "outputs": [ - { - "name": "", - "type": "tuple[]", - "internalType": "struct ISlinky.Price[]", - "components": [ - { - "name": "price", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "timestamp", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "height", - "type": "uint64", - "internalType": "uint64" - }, - { - "name": "nonce", - "type": "uint64", - "internalType": "uint64" - }, - { - "name": "decimal", - "type": "uint64", - "internalType": "uint64" - }, - { - "name": "id", - "type": "uint64", - "internalType": "uint64" - } - ] - } - ], - "stateMutability": "nonpayable" - } -] diff --git a/abis/Slinky.abi.json b/abis/Slinky.abi.json deleted file mode 100644 index 5890674..0000000 --- a/abis/Slinky.abi.json +++ /dev/null @@ -1,127 +0,0 @@ -[ - { - "type": "constructor", - "inputs": [], - "stateMutability": "nonpayable" - }, - { - "type": "function", - "name": "get_all_currency_pairs", - "inputs": [], - "outputs": [ - { - "name": "", - "type": "string", - "internalType": "string" - } - ], - "stateMutability": "nonpayable" - }, - { - "type": "function", - "name": "get_price", - "inputs": [ - { - "name": "base", - "type": "string", - "internalType": "string" - }, - { - "name": "quote", - "type": "string", - "internalType": "string" - } - ], - "outputs": [ - { - "name": "", - "type": "tuple", - "internalType": "struct Slinky.Price", - "components": [ - { - "name": "price", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "timestamp", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "height", - "type": "uint64", - "internalType": "uint64" - }, - { - "name": "nonce", - "type": "uint64", - "internalType": "uint64" - }, - { - "name": "decimal", - "type": "uint64", - "internalType": "uint64" - }, - { - "name": "id", - "type": "uint64", - "internalType": "uint64" - } - ] - } - ], - "stateMutability": "nonpayable" - }, - { - "type": "function", - "name": "get_prices", - "inputs": [ - { - "name": "pair_ids", - "type": "string[]", - "internalType": "string[]" - } - ], - "outputs": [ - { - "name": "", - "type": "tuple[]", - "internalType": "struct Slinky.Price[]", - "components": [ - { - "name": "price", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "timestamp", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "height", - "type": "uint64", - "internalType": "uint64" - }, - { - "name": "nonce", - "type": "uint64", - "internalType": "uint64" - }, - { - "name": "decimal", - "type": "uint64", - "internalType": "uint64" - }, - { - "name": "id", - "type": "uint64", - "internalType": "uint64" - } - ] - } - ], - "stateMutability": "nonpayable" - } -] diff --git a/src/Slinky.sol b/src/ConnectOracle.sol similarity index 86% rename from src/Slinky.sol rename to src/ConnectOracle.sol index 7451eef..a067833 100644 --- a/src/Slinky.sol +++ b/src/ConnectOracle.sol @@ -5,7 +5,7 @@ import "./interfaces/ICosmos.sol"; import "./utils/JsmnSolLib.sol"; import "./utils/IsoToUnix.sol"; -contract Slinky { +contract ConnectOracle { struct Price { uint256 price; uint256 timestamp; @@ -20,20 +20,18 @@ contract Slinky { constructor() {} function get_all_currency_pairs() external returns (string memory) { - string memory path = "/slinky.oracle.v1.Query/GetAllCurrencyPairs"; + string memory path = "/connect.oracle.v2.Query/GetAllCurrencyPairs"; string memory req = "{}"; return ICosmos(cosmosContract).query_cosmos(path, req); } - function get_price(string memory base, string memory quote) external returns (Price memory) { - string memory path = "/slinky.oracle.v1.Query/GetPrice"; + function get_price(string memory pair_id) external returns (Price memory) { + string memory path = "/connect.oracle.v2.Query/GetPrice"; - string[] memory join_strs = new string[](5); - join_strs[0] = '{"currency_pair": {"Base": "'; - join_strs[1] = base; - join_strs[2] = '", "Quote": "'; - join_strs[3] = quote; - join_strs[4] = '"}}'; + string[] memory join_strs = new string[](3); + join_strs[0] = '{"currency_pair": "'; + join_strs[1] = pair_id; + join_strs[2] = '"}'; string memory req = join(join_strs, ""); string memory queryRes = COSMOS_CONTRACT.query_cosmos(path, req); @@ -46,7 +44,7 @@ contract Slinky { } function get_prices(string[] memory pair_ids) external returns (Price[] memory) { - string memory path = "/slinky.oracle.v1.Query/GetPrices"; + string memory path = "/connect.oracle.v2.Query/GetPrices"; string memory req = string.concat(string.concat('{"currency_pair_ids":["', join(pair_ids, '","')), '"]}'); uint256 numberElements = 3 + pair_ids.length * 15; diff --git a/src/interfaces/ISlinky.sol b/src/interfaces/IConnectOracle.sol similarity index 94% rename from src/interfaces/ISlinky.sol rename to src/interfaces/IConnectOracle.sol index 8d29823..4108b8d 100644 --- a/src/interfaces/ISlinky.sol +++ b/src/interfaces/IConnectOracle.sol @@ -1,6 +1,6 @@ pragma solidity ^0.8.24; -interface ISlinky { +interface ConnectOracle { struct Price { uint256 price; uint256 timestamp; diff --git a/src/interfaces/ICosmos.sol b/src/interfaces/ICosmos.sol index d7fa9b2..34bbab2 100644 --- a/src/interfaces/ICosmos.sol +++ b/src/interfaces/ICosmos.sol @@ -47,7 +47,7 @@ interface ICosmos { // query a whitelisted cosmos querys. // // example) - // path: "/slinky.oracle.v1.Query/GetPrices" + // path: "/connect.oracle.v2.Query/GetPrices" // req: { // "currency_pair_ids": ["BITCOIN/USD", "ETHEREUM/USD"] // }