Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/github.com/vektra/mock…
Browse files Browse the repository at this point in the history
…ery/v2-2.46.1
  • Loading branch information
aljo242 authored Sep 30, 2024
2 parents d8f3d86 + fc1e299 commit 5a7d521
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 206 deletions.
36 changes: 18 additions & 18 deletions cmd/constants/marketmaps/markets.go
Original file line number Diff line number Diff line change
Expand Up @@ -1156,10 +1156,10 @@ var (
}
]
},
"MATIC/USD": {
"POL/USD": {
"ticker": {
"currency_pair": {
"Base": "MATIC",
"Base": "POL",
"Quote": "USD"
},
"decimals": 10,
Expand All @@ -1169,7 +1169,7 @@ var (
"provider_configs": [
{
"name": "coinmarketcap_api",
"off_chain_ticker": "3890"
"off_chain_ticker": "28321"
}
]
},
Expand Down Expand Up @@ -5743,10 +5743,10 @@ var (
}
]
},
"MATIC/USD": {
"POL/USD": {
"ticker": {
"currency_pair": {
"Base": "MATIC",
"Base": "POL",
"Quote": "USD"
},
"decimals": 10,
Expand All @@ -5756,71 +5756,71 @@ var (
"provider_configs": [
{
"name": "binance_ws",
"off_chain_ticker": "MATICUSDT",
"off_chain_ticker": "POLUSDT",
"normalize_by_pair": {
"Base": "USDT",
"Quote": "USD"
}
},
{
"name": "bybit_ws",
"off_chain_ticker": "MATICUSDT",
"off_chain_ticker": "POLUSDT",
"normalize_by_pair": {
"Base": "USDT",
"Quote": "USD"
}
},
{
"name": "coinbase_ws",
"off_chain_ticker": "MATIC-USD"
"off_chain_ticker": "POL-USD"
},
{
"name": "gate_ws",
"off_chain_ticker": "MATIC_USDT",
"off_chain_ticker": "POL_USDT",
"normalize_by_pair": {
"Base": "USDT",
"Quote": "USD"
}
},
{
"name": "huobi_ws",
"off_chain_ticker": "maticusdt",
"off_chain_ticker": "polusdt",
"normalize_by_pair": {
"Base": "USDT",
"Quote": "USD"
}
},
{
"name": "kraken_api",
"off_chain_ticker": "MATICUSD"
"off_chain_ticker": "POLUSD"
},
{
"name": "kucoin_ws",
"off_chain_ticker": "MATIC-USDT",
"off_chain_ticker": "POL-USDT",
"normalize_by_pair": {
"Base": "USDT",
"Quote": "USD"
}
},
{
"name": "mexc_ws",
"off_chain_ticker": "MATICUSDT",
"off_chain_ticker": "POLUSDT",
"normalize_by_pair": {
"Base": "USDT",
"Quote": "USD"
}
},
{
"name": "okx_ws",
"off_chain_ticker": "MATIC-USDT",
"off_chain_ticker": "POL-USDT",
"normalize_by_pair": {
"Base": "USDT",
"Quote": "USD"
}
},
{
"name": "crypto_dot_com_ws",
"off_chain_ticker": "MATIC_USD"
"off_chain_ticker": "POL_USD"
}
]
},
Expand Down Expand Up @@ -8999,10 +8999,10 @@ var (
}
]
},
"MATIC/USD": {
"POL/USD": {
"ticker": {
"currency_pair": {
"Base": "MATIC",
"Base": "POL",
"Quote": "USD"
},
"decimals": 10,
Expand All @@ -9012,7 +9012,7 @@ var (
"provider_configs": [
{
"name": "coingecko_api",
"off_chain_ticker": "matic-network/usd"
"off_chain_ticker": "pol-network/usd"
}
]
},
Expand Down
98 changes: 98 additions & 0 deletions docs/developers/connect-sdk.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
title: CosmWasm Connect SDK
description: Querying Connect prices using CosmWasm and Connect SDK
icon: atom-simple
---

<Note>
**Building with Connect? Join our [Discord](https://discord.gg/amAgf9Z39w)**!
</Note>

The Connect SDK provides bindings for the `x/oracle` and `x/marketmap` modules.

## Adding Connect SDK To Your Contract

The version of the Connect SDK for your contract depends on the Connect protocol version of the chain.

| Connect Protocol Version | Connect SDK Version |
|--------------------------|---------------------------------------|
| v1.x | v0.1.0 |
| v2.x | v0.2.0 |

<Tip>
How to find the Connect Protocol version

The protocol version of Connect can be found on the chain by either:

1. Checking the chain's `go.mod` file.
2. Checking the required version in the [quickstart](../validators/quickstart#run-connect-sidecar)
</Tip>

Add the following line to the `dependencies` section of your `Cargo.toml`:

`connect-sdk = { git = "https://github.com/skip-mev/connect-sdk", tag = "CONNECT SDK VERSION HERE", package = "connect-sdk" }`



## Safely Accessing Price Data

The following checks should be made before utilizing a price from Connect in a contract:

1. currency-pair exists within the `x/oracle` and `x/marketmap` modules.
2. currency-pair is `enabled` within the `x/marketmap`.
3. price `block_height` is not older than a few blocks.
4. price nonce is not 0.


### Code Example

This code example is for `v0.1.0` of the Connect SDK.

```rust contract.rs
use connect_sdk::bindings::query::ConnectQuery;
use connect_sdk::bindings::querier::ConnectQuerier;
use connect_sdk::bindings::marketmap::types::CurrencyPair;
use cosmwasm_std::{Deps, Env, StdResult, Int128, StdError};

fn do_something_with_price(
deps: Deps<ConnectQuery>,
env: Env,
currency_pair: CurrencyPair
) -> StdResult<Int128> {
let connect_querier = ConnectQuerier::new(&deps.querier);
let base = currency_pair.base.to_uppercase();
let quote = currency_pair.quote.to_uppercase();

// Check if the market exists and is enabled
let market = connect_querier.get_marketmap_market(base.clone(), quote.clone())?;
if !market.market.ticker.enabled {
return Err(StdError::generic_err("market is not enabled"));
}

// Check price validity
let price_response = connect_querier.get_oracle_price(base, quote)?;
if price_response.nonce == 0 {
return Err(StdError::generic_err("price has never been updated"));
}

let max_price_age: u64 = 3; // adjust based on appetite for price freshness
let price_age = env.block.height - price_response.price.block_height.unwrap();
if price_age > max_price_age {
return Err(StdError::generic_err("price is too old"));
}

// We can now do something with the price
let valid_price = price_response.price.price;

// Placeholder for actual price processing
Ok(valid_price)
}
```



## Full Example Contract

Example Contract here: [example](https://github.com/skip-mev/connect-sdk/tree/trunk/contracts/x-oracle-passthrough).


Loading

0 comments on commit 5a7d521

Please sign in to comment.