GithubHelp home page GithubHelp logo

yyolk / xrpl-price-persist-oracle Goto Github PK

View Code? Open in Web Editor NEW
9.0 7.0 2.0 92 KB

A Serverless Application Model stack that persists the $XRP price to the XRPL every minute as a TrustLine. There are no servers, it is effectively a "smart contract" in Python for the XRPL.

Home Page: https://egge.gg

License: Other

Python 100.00%
aws-sam sam serverless aws-lambda xrpl xrp price-oracle xrpl-contract serverless-application-model

xrpl-price-persist-oracle's Introduction

xrpl-price-persist-oracle

Mainnet

💳: rEGGEgg9hQSHLxUwycGnmjW2GKX9thn2yH 🧭

▶️: Mainnet

Testnet

💳: rayZw5nJmueB5ps2bfL85aJgiKub7FsVYN 🧭

▶️: Testnet

Prices via Oracle

These graphs are generated from the CloudWatch Metric data pushed in the contract, the code that generates these images is in the metrics repo

🚧 Gaps indicate the oracle didn't reliably publish during this time see #27 🚧

price USD PT-3H

price USD PT-1D

price USD PT-7D

This shows the Testnet updates less frequently than the mainnet.

price USD PT-3H Mainnet & Testnet

This is a XRPL Oracle that publishes external data into the XRPL.

This Oracle was inspired by XRPL-Labs/XRPL-Persist-Price-Oracle. Also see the DEV post.

This Oracle is coded in python and built as a Serverless Application Model (SAM).

Take a look at the handler() in contract.py — where it's expected to run on any FaaS, such as OpenFaaS.

Deploying to your AWS account

To deploy to your AWS Account use the aws-sam-cli. If you don't have aws-sam-cli installed, you can grab it from pip or follow the installation documentation.

pip install -U aws-sam-cli

After installing aws-sam-cli, you can Build and Deploy.

# zip our function along with it's requirements from requirements.txt
# this also makes a new template pointing at those zips
sam build 
# now it's built, you'll be prompted to deploy, do so interactively with:
sam deploy --guided

Don't feel like doing it yourself? Expand me to see termcasts.

  1. New stack, accepting all the defaults, besides the wallet secret.
  • asciicast
  1. A current stack, getting updated and deployed to
  • asciicast

This will walk you through the deployment of the Oracle, name the stack input the parameters (the wallet seed parameter is NoEcho)

You may generate a Testnet wallet at the Testnet faucet: https://xrpl.org/xrp-testnet-faucet.html Click "Generate Testnet Credentials" and use the Secret as the input to the WalletSecret parameter.

Besides the one required parameter without a default (the wallet secret seed), you can accept all the defaults (including the stack name) and you'll be persisting aggregate prices to the XRPL Testnet.

Tailing Logs

After deployment, you can tail the logs of the function like, where my-stack-name is what you chose to name your stack during the --guided deploy, if you chose the default it's sam-app:

sam logs --stack-name my-stack-name -n OracleFunction -t

Note on NoEcho Cloudformation Parameter for Wallet Secret Seed

The NoEcho parameter of the wallet secret seed ensures that the parameter may not be read or may not be logged during any cloudformation events.

The produced resource that !Ref's the parameter in use, the function with it's environment variable. Be aware that any other user able to access the AWS account used to stand this stack will be able to read the secret on the lambda function itself.

If you're in a trusted account, and don't provide access to tools or services that would have access to these things you'll be fine.

Otherwise, you'll have a couple options:

One option is to encrypt the Lambda environment vars in transit (they're encrypted at rest by default). This would then require decrypting it in the function using a KMS call. (see Securing Environment Variables)

Alternatively you might want to call some key management service / secrets management service independently. There is two other AWS services that you could use, for managing encrypted secrets in transit.

One is Simple Systems Manager (ssm, specifically ssm-encrypted parameter store type). This includes some additional costs if the function needs to cold start (assuming you're persisting the client in the outer scope for subsequent executions). (see Sharing Secrets with AWS Lambda Using AWS Systems Manager Parameter Store)

You'll want to attach a policy to the function like in 5603945 include a policy attached to the OracleFunction resource under the Properties dict.

    Properties:
      CodeUri: oracle/
      Handler: contract.handler
      Runtime: python3.8
      Policies:
        - SSMParameterReadPolicy:
            # this should be a path you decide, here's an example:
            ParameterName: xrpl-oracle/test/wallet/secret
            # you can also use `!Sub`:
            # ParameterName: !Sub "xrpl-oracle/${XRPLNodeEnvironment}/wallet/secret"

Another is Secrets Manager aws-secrets-manager, which is also an additional cost. (see secretsmanager_basics.py)

There are many options! This is just a minimal example :)

xrpl-price-persist-oracle's People

Contributors

yyolk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

xrpl-price-persist-oracle's Issues

🏗️ fixing 🕳️ in data 🚧

🕳️ in data as a result of a few causes that will be fixed soon :)

I do see this as a bug+enhancement, the end result most likely is we may we spend a bit more drops to ensure we're publishing every minute.

Data sources

Not a bug but a suggestion

  • i would look at changing up some of the data sources compared with xumm
  • there is value in having some over lap but your well over 50%

My suggestion is as follows.

  • Bistamp and Kraken should def stay
  • FTX is mostly a derivatives exchange, but they do have the one fiat pair (keep that in mind from its data) it a good outsider.
  • Bitrue is USD via tether! It should have a lower weighting in the overall price, if you want to keep that in the price calculation.
  • add Bitso, cryptocom I am waiting on the new coinsph websocket to launch when that pro exchange fires up that def should go in there.
  • Lastly is phemex they provide most of the tech for all the fiat on ramps all exchanges use, this IMO is an important one.

Rocking.

An abundance of JSONDecodeError

While using the JsonRPCClient; the oracle will see an abundance of JSONDecodeErrors that are coming as a result of the server saying it's too busy.
image
image

I was aware of this happening, and was swallowing, notifying and then raising FailedExecutionWillRetry

Got a JSONDecodeError of 'Expecting value: line 1 column 1 (char 0)'. Retrying the transaction by failing this execution.


JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
  File "/var/lang/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/var/task/contract.py", line 45, in <module>
    base_fee = get_fee(xrpl_client)
  File "/var/task/xrpl/ledger/main.py", line 54, in get_fee
    return asyncio.run(main.get_fee(client))
  File "/var/lang/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/var/lang/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/var/task/xrpl/asyncio/ledger/main.py", line 64, in get_fee
    response = await client.request_impl(Fee())
  File "/var/task/xrpl/asyncio/clients/json_rpc_base.py", line 46, in request_impl
    return json_to_response(response.json())
  File "/var/task/httpx/_models.py", line 1415, in json
    return jsonlib.loads(self.text, **kwargs)
  File "/var/lang/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/var/lang/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/var/lang/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None

New Oracle Address rEGGEgg… ("🥚🥚" / EGGE.gg)

A new wallet address that is domain verified with the domain displayed in the vanity address.

The domain is EGGE.gg - this feels more apt. 🍳

I wouldn't want someone to go to the domain, like "EGGD.gg" and be thrown into some scammy stuff because they saw a link in a vanity address. There is the context that .gg domains don't like that sort of stuff and they would be banned from registering, but that wouldn't be a great experience for the community.

This will be the new address.

rEGGEgg9hQSHLxUwycGnmjW2GKX9thn2yH

This replaces the old address

rEGGDggxupqxJ3ZbDTLUzKtpHxHyhtUtiU

The rollout 🚜:

  • 1. New stack created with new wallet and secret seed in a pull-request branch that overwrites mainnet stack workflow
    • This will be using the same code, but based on it's invocation time; it may produce different results as it will reflect the markets during it's invocation.
  • 2. Announce change via twitter
  • 3. Reach out to ShortTheFomo where the oracle is featured, to notify of change
  • 4. Domain verify "🥚🥚" / with a EGGE.gg/.well-known/xrp-ledger.toml
  • #39
    • NOTE this might not be possible if the previous trust lines count towards the ledger objects imagevia
      • if that's the case I'll black-hole the wallet, extracting what is possible 😙

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.