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 all 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).

### Fixed
* Better error handling/error messages for serialization/deserialization errors.

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
30 changes: 30 additions & 0 deletions packages/ripple-binary-codec/test/fixtures/codec-fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -4868,6 +4868,36 @@
"TxnSignature": "AACD31A04CAE14670FC483A1382F393AA96B49C84479B58067F049FBD772999325667A6AA2520A63756EE84F3657298815019DD56A1AECE796B08535C4009C08",
"URI": "6469645F6578616D706C65"
}
},
{
"binary": "1200332FFFFFFFFF2033000004D2750B6469645F6578616D706C65701C0863757272656E6379701D0870726F7669646572811401476926B590BA3245F63C829116A0A3AF7F382DF018E020301700000000000001E2041003011A0000000000000000000000000000000000000000021A0000000000000000000000005553440000000000E1F1",
"json": {
"TransactionType": "OracleSet",
"Account": "rfmDuhDyLGgx94qiwf3YF8BUV5j6KSvE8",
"OracleDocumentID": 1234,
"LastUpdateTime": 4294967295,
"PriceDataSeries": [
{
"PriceData": {
"BaseAsset": "XRP",
"QuoteAsset": "USD",
"AssetPrice": "00000000000001E2",
"Scale": 3
}
}
],
"Provider": "70726F7669646572",
"URI": "6469645F6578616D706C65",
"AssetClass": "63757272656E6379"
}
},
{
"binary": "1200342033000004D2811401476926B590BA3245F63C829116A0A3AF7F382D",
"json": {
"TransactionType": "OracleDelete",
"Account": "rfmDuhDyLGgx94qiwf3YF8BUV5j6KSvE8",
"OracleDocumentID": 1234
}
}
],
"ledgerData": [{
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
33 changes: 33 additions & 0 deletions packages/xrpl/src/models/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,36 @@ export interface XChainBridge {
IssuingChainDoor: string
IssuingChainIssue: Currency
}

/**
* A PriceData object represents the price information for a token pair.
*
*/
export interface PriceData {
PriceData: {
/**
* The primary asset in a trading pair. Any valid identifier, such as a stock symbol, bond CUSIP, or currency code is allowed.
* For example, in the BTC/USD pair, BTC is the base asset; in 912810RR9/BTC, 912810RR9 is the base asset.
*/
BaseAsset: string

/**
* The quote asset in a trading pair. The quote asset denotes the price of one unit of the base asset. For example, in the
* BTC/USD pair,BTC is the base asset; in 912810RR9/BTC, 912810RR9 is the base asset.
*/
QuoteAsset: string

/**
* The asset price after applying the Scale precision level. It's not included if the last update transaction didn't include
* the BaseAsset/QuoteAsset pair.
*/
AssetPrice?: number | string

/**
* The scaling factor to apply to an asset price. For example, if Scale is 6 and original price is 0.155, then the scaled
* price is 155000. Valid scale ranges are 0-10. It's not included if the last update transaction didn't include the
* BaseAsset/QuoteAsset pair.
*/
Scale?: number
}
}
3 changes: 3 additions & 0 deletions packages/xrpl/src/models/ledger/LedgerEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import FeeSettings from './FeeSettings'
import LedgerHashes from './LedgerHashes'
import NegativeUNL from './NegativeUNL'
import Offer from './Offer'
import Oracle from './Oracle'
import PayChannel from './PayChannel'
import RippleState from './RippleState'
import SignerList from './SignerList'
Expand All @@ -30,6 +31,7 @@ type LedgerEntry =
| LedgerHashes
| NegativeUNL
| Offer
| Oracle
| PayChannel
| RippleState
| SignerList
Expand All @@ -52,6 +54,7 @@ type LedgerEntryFilter =
| 'nft_offer'
| 'nft_page'
| 'offer'
| 'oracle'
| 'payment_channel'
| 'signer_list'
| 'state'
Expand Down
Loading
Loading