Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Price Oracles support #2688

Merged
merged 45 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
5757126
add OracleSet
khancode May 3, 2024
7d93e5a
update all HISTORY.md
khancode May 3, 2024
13109ef
fix faucet; unrelated to PR
khancode May 3, 2024
6d709b0
use rippled v2.2.0-b3
khancode May 3, 2024
fe57f67
add OracleDelete
khancode May 3, 2024
552779b
small unit test update
khancode May 3, 2024
3362952
enable PriceOracle in rippled.cfg
khancode May 7, 2024
dbe74ee
add get_aggregate_price request
khancode May 7, 2024
9335a57
add OracleSet integ test
khancode May 7, 2024
c03203b
make PriceDataSeries required field
khancode May 7, 2024
e79142e
add missing PriceData field
khancode May 7, 2024
1123d79
Merge branch 'main' into price-oracle
khancode May 8, 2024
0dfab5c
use unix timestamp in test
khancode May 8, 2024
d0857f5
convert unix timestamp to seconds
khancode May 8, 2024
6ba1f4e
encode Provider & AssetClass to hex in test
khancode May 9, 2024
2a429aa
fix unit test
khancode May 9, 2024
856de28
fix GetAggregatePriceResponse
khancode May 9, 2024
12be2de
resolve duplicate name conflict with Oracle
khancode May 14, 2024
cdeff9f
add transactions to codec-fixtures
khancode May 14, 2024
db85e10
add jsdocs
khancode May 14, 2024
7cb32bd
unrelated: fix fund wallet test
khancode May 15, 2024
5ebc871
set oracle_document_id as union of string and number
khancode May 16, 2024
f4abcab
remove ledger_hash and set required for ledger_index and validated
khancode May 16, 2024
063ea40
set trimmed_set to optional
khancode May 16, 2024
014e478
rename to ledger_current_index
khancode May 16, 2024
ad5fe58
add OracleDelete integ test
khancode May 16, 2024
06eed78
add PriceDataSeries max length validation
khancode May 16, 2024
524eb7c
add get_aggregate_price integ test
khancode May 16, 2024
28550e7
add Oracle ledger entry model
khancode May 16, 2024
6b6a9eb
add TODO
khancode May 16, 2024
03dd1f8
nit: update OracleSet validation
khancode May 16, 2024
41b9da1
add getUnixTimestamp util
khancode May 16, 2024
75c1d8a
rename to getCurrentUnixTimestamp
khancode May 16, 2024
cada52b
add Scale validation
khancode May 16, 2024
6ceb9fd
use account_objects in oracle set/delete integ tests
khancode May 16, 2024
91695f7
update integ tests and Oracle class
khancode May 17, 2024
80d91ec
remove getCurrentTimestamp()
khancode May 20, 2024
845d811
import PriceData in Oracle
khancode May 20, 2024
dd0d702
move PriceData to /common
khancode May 22, 2024
7e6c086
use type: 'oracle' in integ tests
khancode May 22, 2024
7a69273
debug: remove integ tests
khancode May 22, 2024
2102c9d
debug: add back in oracleSet integ test and remove stringToHex
khancode May 22, 2024
1280ff2
add back in tx integ tests fixing import path of stringToHex
khancode May 22, 2024
91e1be9
add back in get_aggregate_price integ test with fixed import
khancode May 22, 2024
77481f7
ensure PriceData is the only prop
khancode May 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .ci-config/rippled.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,11 @@ fixNFTokenRemint
# 2.0.0 Amendments
XChainBridge
DID
# 2.2.0-b3 Amendments
fixNFTokenReserve
fixInnerObjTemplate
fixAMMOverflowOffer
PriceOracle
fixEmptyDID
fixXChainRewardRounding
fixPreviousTxnID
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name: Node.js CI

env:
RIPPLED_DOCKER_IMAGE: rippleci/rippled:2.0.0-b4
RIPPLED_DOCKER_IMAGE: rippleci/rippled:2.2.0-b3

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ This should be run from the `xrpl.js` top level folder (one above the `packages`
```bash
npm run build
# sets up the rippled standalone Docker container - you can skip this step if you already have it set up
docker run -p 6006:6006 --interactive -t --volume $PWD/.ci-config:/opt/ripple/etc/ --platform linux/amd64 rippleci/rippled:2.0.0-b3 /opt/ripple/bin/rippled -a --conf /opt/ripple/etc/rippled.cfg
docker run -p 6006:6006 --interactive -t --volume $PWD/.ci-config:/opt/ripple/etc/ --platform linux/amd64 rippleci/rippled:2.2.0-b3 /opt/ripple/bin/rippled -a --conf /opt/ripple/etc/rippled.cfg
npm run test:browser
```

Expand Down
3 changes: 3 additions & 0 deletions packages/ripple-binary-codec/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

### Added
* Support for the Price Oracles amendment (XLS-47).

## 2.0.0 (2024-02-01)

### BREAKING CHANGES
Expand Down
114 changes: 112 additions & 2 deletions packages/ripple-binary-codec/src/enums/definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"UInt512": 23,
"Issue": 24,
"XChainBridge": 25,
"Currency": 26,
"Transaction": 10001,
"LedgerEntry": 10002,
"Validation": 10003,
Expand Down Expand Up @@ -51,6 +52,7 @@
"NFTokenOffer": 55,
"AMM": 121,
"DID": 73,
"Oracle": 128,
"Any": -3,
"Child": -2,
"Nickname": 110,
Expand Down Expand Up @@ -208,6 +210,16 @@
"type": "UInt8"
}
],
[
"Scale",
{
"nth": 4,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "UInt8"
}
],
[
"TickSize",
{
Expand Down Expand Up @@ -498,6 +510,16 @@
"type": "UInt32"
}
],
[
"LastUpdateTime",
{
"nth": 15,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "UInt32"
}
],
[
"HighQualityIn",
{
Expand Down Expand Up @@ -828,6 +850,16 @@
"type": "UInt32"
}
],
[
"OracleDocumentID",
{
"nth": 51,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "UInt32"
}
],
[
"IndexNext",
{
Expand Down Expand Up @@ -1028,6 +1060,16 @@
"type": "UInt64"
}
],
[
"AssetPrice",
{
"nth": 23,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "UInt64"
}
],
[
"EmailHash",
{
Expand Down Expand Up @@ -1918,6 +1960,26 @@
"type": "Blob"
}
],
[
"AssetClass",
{
"nth": 28,
"isVLEncoded": true,
"isSerialized": true,
"isSigningField": true,
"type": "Blob"
}
],
[
"Provider",
{
"nth": 29,
"isVLEncoded": true,
"isSerialized": true,
"isSigningField": true,
"type": "Blob"
}
],
[
"Account",
{
Expand Down Expand Up @@ -2128,6 +2190,26 @@
"type": "PathSet"
}
],
[
"BaseAsset",
{
"nth": 1,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "Currency"
}
],
[
"QuoteAsset",
{
"nth": 2,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "Currency"
}
],
[
"LockingChainIssue",
{
Expand Down Expand Up @@ -2458,6 +2540,16 @@
"type": "STObject"
}
],
[
"PriceData",
{
"nth": 32,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "STObject"
}
],
[
"Signers",
{
Expand Down Expand Up @@ -2628,6 +2720,16 @@
"type": "STArray"
}
],
[
"PriceDataSeries",
{
"nth": 24,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "STArray"
}
],
[
"AuthAccounts",
{
Expand Down Expand Up @@ -2656,6 +2758,7 @@
"telWRONG_NETWORK": -386,
"telREQUIRES_NETWORK_ID": -385,
"telNETWORK_ID_MAKES_TX_NON_CANONICAL": -384,
"telENV_RPC_FAILED": -383,

"temMALFORMED": -299,
"temBAD_AMOUNT": -298,
Expand Down Expand Up @@ -2703,6 +2806,8 @@
"temXCHAIN_BRIDGE_BAD_MIN_ACCOUNT_CREATE_AMOUNT": -256,
"temXCHAIN_BRIDGE_BAD_REWARD_AMOUNT": -255,
"temEMPTY_DID": -254,
"temARRAY_EMPTY": -253,
"temARRAY_TOO_LARGE": -252,

"tefFAILURE": -199,
"tefALREADY": -198,
Expand Down Expand Up @@ -2739,7 +2844,6 @@
"terQUEUED": -89,
"terPRE_TICKET": -88,
"terNO_AMM": -87,
"terSUBMITTED": -86,

"tesSUCCESS": 0,

Expand Down Expand Up @@ -2815,7 +2919,11 @@
"tecXCHAIN_SELF_COMMIT": 184,
"tecXCHAIN_BAD_PUBLIC_KEY_ACCOUNT_PAIR": 185,
"tecXCHAIN_CREATE_ACCOUNT_DISABLED": 186,
"tecEMPTY_DID": 187
"tecEMPTY_DID": 187,
"tecINVALID_UPDATE_TIME": 188,
"tecTOKEN_PAIR_NOT_FOUND": 189,
"tecARRAY_EMPTY": 190,
"tecARRAY_TOO_LARGE": 191
},
"TRANSACTION_TYPES": {
"Invalid": -1,
Expand Down Expand Up @@ -2864,6 +2972,8 @@
"XChainCreateBridge": 48,
"DIDSet": 49,
"DIDDelete": 50,
"OracleSet": 51,
"OracleDelete": 52,
"EnableAmendment": 100,
"SetFee": 101,
"UNLModify": 102
Expand Down
3 changes: 3 additions & 0 deletions packages/xrpl/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr
### BREAKING CHANGES
* Small fix in the API to use a new flag name `tfNoDirectRipple` instead of the existing flag name `tfNoRippleDirect`

### Added
* Support for the Price Oracles amendment (XLS-47).

### Fixed
* Typo in `Channel` type `source_tab` -> `source_tag`
* Fix `client.requestAll` to handle filters better
Expand Down
69 changes: 69 additions & 0 deletions packages/xrpl/src/models/methods/getAggregatePrice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { BaseRequest, BaseResponse } from './baseMethod'

export interface Oracle {
account: string
oracle_document_id: number
}

/**
* The `get_aggregate_price` method retrieves the aggregate price of specified Oracle objects,
* returning three price statistics: mean, median, and trimmed mean.
* Returns an {@link GetAggregatePriceResponse}.
*
* @category Requests
*/
export interface GetAggregatePriceRequest extends BaseRequest {
khancode marked this conversation as resolved.
Show resolved Hide resolved
command: 'get_aggregate_price'

base_asset: string

quote_asset: string

oracles: Oracle[]
khancode marked this conversation as resolved.
Show resolved Hide resolved

trim?: number

trim_threshold?: number
}

/**
* Response expected from an {@link GetAggregatePriceRequest}.
*
* @category Responses
*/
export interface GetAggregatePriceResponse extends BaseResponse {
result: {
entire_set: {
mean: string
size: number
standard_deviation: number
}

trimmed_set: {
khancode marked this conversation as resolved.
Show resolved Hide resolved
mean: string
size: number
standard_deviation: number
}

time: number

/**
* The identifying hash of the ledger that was used to generate this
* response.
*/
ledger_hash?: string

/**
* The ledger index of the ledger version that was used to generate this
* response.
*/
ledger_index?: number

/**
* If included and set to true, the information in this response comes from
* a validated ledger version. Otherwise, the information is subject to
* change.
*/
validated?: boolean
khancode marked this conversation as resolved.
Show resolved Hide resolved
}
}
12 changes: 12 additions & 0 deletions packages/xrpl/src/models/methods/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ import {
GatewayBalancesRequest,
GatewayBalancesResponse,
} from './gatewayBalances'
import {
GetAggregatePriceRequest,
GetAggregatePriceResponse,
} from './getAggregatePrice'
import {
LedgerBinary,
LedgerModifiedOfferCreateTransaction,
Expand Down Expand Up @@ -210,6 +214,8 @@ type Request =
| NFTHistoryRequest
// AMM methods
| AMMInfoRequest
// Price Oracle methods
| GetAggregatePriceRequest

/**
* @category Responses
Expand Down Expand Up @@ -264,6 +270,8 @@ type Response =
| NFTHistoryResponse
// AMM methods
| AMMInfoResponse
// Price Oracle methods
| GetAggregatePriceResponse

export type RequestResponseMap<T> = T extends AccountChannelsRequest
? AccountChannelsResponse
Expand All @@ -285,6 +293,8 @@ export type RequestResponseMap<T> = T extends AccountChannelsRequest
? AMMInfoResponse
: T extends GatewayBalancesRequest
? GatewayBalancesResponse
: T extends GetAggregatePriceRequest
? GetAggregatePriceResponse
: T extends NoRippleCheckRequest
? NoRippleCheckResponse
: // NOTE: The order of these LedgerRequest types is important
Expand Down Expand Up @@ -473,6 +483,8 @@ export {
GatewayBalance,
GatewayBalancesRequest,
GatewayBalancesResponse,
GetAggregatePriceRequest,
GetAggregatePriceResponse,
NoRippleCheckRequest,
NoRippleCheckResponse,
// ledger methods
Expand Down
2 changes: 2 additions & 0 deletions packages/xrpl/src/models/transactions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export {
OfferCreateFlagsInterface,
OfferCreate,
} from './offerCreate'
export { OracleDelete } from './oracleDelete'
export { OracleSet } from './oracleSet'
export { PaymentFlags, PaymentFlagsInterface, Payment } from './payment'
export {
PaymentChannelClaimFlags,
Expand Down
Loading
Loading