GithubHelp home page GithubHelp logo

isabella232 / pegout-cost-estimator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rsksmart/pegout-cost-estimator

0.0 0.0 0.0 516 KB

Library to help calculate peg-out costs

License: MIT License

JavaScript 100.00%

pegout-cost-estimator's Introduction

CI/CD Using Github actions workflow

Disclaimer

This is a beta version until audited by the security team. Any comments or suggestions feel free to contribute or reach out at our open slack.

pegout-cost-estimator

Library to help estimate peg-out costs. Includes a console tool to use it.

Keep in mind that it is not possible to make an exact calculation of the cost of a pegout transaction due to the dynamic nature of a blockchain. The results obtained by using this tool are only an approximation, the actual cost may differ.

Details

Some of the exposed functions expect to receive a web3 instance connected to a Rskj node, and the network settings of the corresponding network. This settings can be obtained using rsk-network-settings library.

estimatePegoutCostInWeis

estimatePegoutCostInWeis(amountToPegoutInSatoshis, web3, networkSettings)

Given the amount of satoshis the user expects to receive, this function returns an approximate amount in weis the user should send to the Bridge. This amount equals to the amount the user wants to receive plus the estimated fee.

estimatePegoutValueInSatoshis

estimatePegoutValueInSatoshis(amountToPegoutInWeis, web3, networkSettings)

Given the amount of weis the user will send to the Bridge, this function returns the approximate amount in satoshis the user will receive. This amount equals to the amount the user sends to the Bridge minus the estimated fee.

setUtxoSortingMethod

setUtxoSortingMethod((a, b) => {...})

Allows to override the function used to sort the utxos used to create the peg-out transactions. Expects to receive a function that, given 2 values, returns 1 if a > b, 0 if equal, and -1 if a < b.

The sorting function used by default replicates the logic used in Rskj node.

Tool

The library also provides a tool to be used from a console to estimate peg-out costs.

Usage

$ node tool/pegout-cost-in-weis.js [network] [amountInSatoshis]
$ node tool/pegout-value-in-satoshis.js [network] [amountInWeis]

network value can be mainnet, testnet or a network url to a host running a Rskj node

Example

$ node tool/pegout-cost-in-weis.js testnet 1000000

In order to receive 1000000 satoshis, the user needs to send approximately 10944000000000000 weis to the bridge
$ node tool/pegout-value-in-satoshis.js testnet 10000000000000000

By sending 10000000000000000 weis to the bridge, the user will receive approximately 905600 satoshis

pegout-cost-estimator's People

Contributors

josedahlquist avatar kelvinator07 avatar marcos-iov avatar

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.