Skip to content

Commit

Permalink
docs: update docs for silk basket query
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinWoetzel committed Apr 26, 2024
1 parent c49dea7 commit dbf1945
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 12 deletions.
1 change: 1 addition & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default defineConfig({
{ text: 'stkd-SCRT', link: '/queries/derivativeScrt' },
{ text: 'Shade Staking', link: '/queries/shadeStaking' },
{ text: 'Batch Query', link: '/queries/batch-query' },
{ text: 'Silk', link: '/queries/silk' },
{ text: 'Snip20', link: '/queries/snip20' },
]
},
Expand Down
1 change: 1 addition & 0 deletions docs/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This page contains a list of deployed contracts.
| Lend Vault Registry (V2) | secret1qxk2scacpgj2mmm0af60674afl9e6qneg7yuny | ac5d501827d9a337a618ca493fcbf1323b20771378774a6bf466cb66361bf021 |
| Lend Vault Registry (V3) | secret1wj2czeeknya2n6jag7kpfxlm28dw7q96dgqmfs | d837f716de3732a4118fbcb6d4cd0ef1d84ee83fef924f27b7c2a821f8528b39 |
| Lend Stability Pool | secret1wdxqz26acf2e6rsac8007pd53ak7n8tgeqr46w | 4dcdce6a2f88ef2912b9988119b345b096909aa4ba3881eff19358d983c40210 |
| Index Oracle (SILK) | secret1552yh3rplmyrjwhcxrq0egg35uy6zwjtszecf0 | 8d2b439383091ecb7806757a2b202e0056e542ade67951a0d5c352e74ce416cc |

::: tip
The ShadeSwap pairs contracts are accessible via the factory registered pairs query.
Expand Down
140 changes: 140 additions & 0 deletions docs/queries/silk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# Silk Peg Examples

This page demonstrates how to query the Silk peg and information about the basket of currencies that make up the Silk peg.

## Silk Basket
Query info for the silk basket

**input**
```ts
/**
* query the silk basket data
*
* silkBasketExpectedOracleKeys is set to optional because if oracle keys are
* known in advance it will increase the efficiency of the response, but even if
* keys are unknown or incorrectly passed in compared to the true state of the
* basket this query will self-correct using a retry on the actual keys found.
*/
function querySilkBasket({
queryRouterContractAddress,
queryRouterCodeHash,
lcdEndpoint,
chainId,
oracleContractAddress,
oracleCodeHash,
silkBasketExpectedOracleKeys,
silkIndexOracleContractAddress,
silkIndexOracleCodeHash,
minBlockHeightValidationOptions,
}:{
queryRouterContractAddress: string,
queryRouterCodeHash?: string,
lcdEndpoint?: string,
chainId?: string,
oracleContractAddress: string,
oracleCodeHash: string,
silkBasketExpectedOracleKeys?: string[]
silkIndexOracleContractAddress: string,
silkIndexOracleCodeHash: string,
minBlockHeightValidationOptions?: MinBlockHeightValidationOptions,
}): Promise<SilkBasket>
```

**output**
```ts
type SilkBasket = {
symbol: string, // silk peg oracle key
oracleRouterContract: Contract,
staleInterval: number, // seconds before stale oracle would cause a peg freeze.
peg: {
value: string, // current value of the peg
initialValue: string, // starting value of the peg
isFrozen: boolean,
lastUpdatedAt: Date,
},
basket: BasketItem[],
blockHeight: number,
}
type BasketItem = {
symbol: string, // oracle key
amount: string, // fixed amount of the currency that makes up the peg
price?: string, // price of the currency
weight: {
initial: string, // expressed as decimal percent
current?: string,
}
}
```

```md
{
symbol: 'SILK Peg',
oracleRouterContract: {
address: 'secret10n2xl5jmez6r9umtdrth78k0vwmce0l5m9f5dm',
codeHash: '32c4710842b97a526c243a68511b15f58d6e72a388af38a7221ff3244c754e91',
},
staleInterval: 3600,
peg: {
value: '1.149881971',
initialValue: '1.05',
isFrozen: false,
lastUpdatedAt: new Date(1714053218000),
},
basket: [{
symbol: 'CAD',
amount: '0.107192209875052435',
price: '0.731678675',
weight: {
current: '0.068207221323326828',
initial: '0.077167854630036405',
},
},
{
symbol: 'USD',
amount: '0.353843538457366364',
price: '1',
weight: {
current: '0.307721616114778065',
initial: '0.337301580837853137',
},
},
{
symbol: 'JPY',
amount: '15.684456395164345505',
price: '0.006425558',
weight: {
current: '0.087644981665339478',
initial: '0.103589679459286984',
},
},
{
symbol: 'BTC',
amount: '0.000002334689261109',
price: '64526.1',
weight: {
current: '0.131012048654205263',
initial: '0.068084956080984917',
},
},
{
symbol: 'EUR',
amount: '0.223108470434723066',
price: '1.072833942',
weight: {
current: '0.20815905098669853',
initial: '0.232086119065448055',
},
},
{
symbol: 'XAU',
amount: '0.000099333104038645',
price: '2332.0433247',
weight: {
current: '0.201454677990644557',
initial: '0.181769809926390499',
},
}],
blockHeight: 123456789,
}
```
24 changes: 12 additions & 12 deletions src/contracts/services/silkBasket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import { batchQuery$ } from './batchQuery';
const ORACLE_NORMALIZATION_FACTOR = 18;

/**
* parses the direct contract query into the data model
* parses the silk basket individual contract responses from the queries
* into the shared data model.
* This includes adding a parsing status to the output type for use in downstream
* error/retry handling
*/
const parseSilkBasketAndPricesResponse = ({
silkBasketResponse,
Expand All @@ -33,13 +36,12 @@ const parseSilkBasketAndPricesResponse = ({
basketPricesResponseBlockHeight,
}:{
silkBasketResponse: SilkBasketResponse,
// return the prices batch data here for error handling purposes
// return the prices batch data here instead of raw response
// for error handling purposes
batchBasketPricesResponse: BatchQueryParsedResponseItem,
silkBasketResponseBlockHeight: number,
basketPricesResponseBlockHeight: number,
}): SilkBasket & { status: SilkBasketParsingStatus } => {
// error checking

// block height validation
// data should be returned in a single batch with a single block height and
// never cause this error, but in case for any reason it does not, we will validate that here
Expand Down Expand Up @@ -168,8 +170,8 @@ function parseSilkBasketAndPricesResponseFromQueryRouter(
throw new Error('prices response not found in query router response');
}

// for price error state we will not throw an error here as there is still useful
// data to get out of the peg info that we would like to parse.
// for price error state we will not throw an error like we did with the basket
// data as there is still useful data to get out of the peg info that we would like to parse.
// Instead, we will pass the full batch data into the parser (which includes the
// error status) and handle the error downstream.

Expand All @@ -191,7 +193,7 @@ function querySilkBasket$({
chainId,
oracleContractAddress,
oracleCodeHash,
silkBasketExpectedOracleKeys, // if keys are known in advance it will
silkBasketExpectedOracleKeys = [], // if keys are known in advance it will
// increase the efficiency of the response, but even if keys are unknown or
// incorrectly passed in compared to the state of the basket,
// this service will self-correct using a retry on the actual keys found.
Expand Down Expand Up @@ -225,9 +227,7 @@ function querySilkBasket$({
address: oracleContractAddress,
codeHash: oracleCodeHash,
},
queryMsg: silkBasketExpectedOracleKeys
? msgQueryOraclePrices(silkBasketExpectedOracleKeys)
: msgQueryOraclePrices([]),
queryMsg: msgQueryOraclePrices(silkBasketExpectedOracleKeys),
};

return batchQuery$({
Expand Down Expand Up @@ -278,7 +278,7 @@ function querySilkBasket$({
}

/**
* query the stability pool info
* query the silk basket data
*/
function querySilkBasket({
queryRouterContractAddress,
Expand All @@ -301,7 +301,7 @@ function querySilkBasket({
chainId?: string,
oracleContractAddress: string,
oracleCodeHash: string,
silkBasketExpectedOracleKeys: string[]
silkBasketExpectedOracleKeys?: string[]
silkIndexOracleContractAddress: string,
silkIndexOracleCodeHash: string,
minBlockHeightValidationOptions?: MinBlockHeightValidationOptions,
Expand Down

0 comments on commit dbf1945

Please sign in to comment.