1.0.0 • Published 5 years ago

metronome-ops v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

metronome-ops

Build Status

Basic Metronome Token operations.

More detailed description or notes as needed.

Installation

npm install metronome-ops

Usage

const metOps = require('metronome-ops')
const MetronomeContracts = require('metronome-contracts')
const Web3 = require('web3')

const contracts = new MetronomeContracts(new Web3())
metOps.getAuctionStatus(contracts)
  .then(function (status) {
    // `status` contains the current auction data
  })

API

getAuctionStatus(contracts) ⇒ Promise.<AuctionStatus>

Get the status of the Auctions contract.

Returns: Promise.<AuctionStatus> - The status.

ParamTypeDescription
contractsObjectThe Metronome contracts.
contracts.AuctionsObjectThe Web3 Auctions contract instance.

getConverterStatus(contracts) ⇒ Promise.<AutonomousConverterStatus>

Get the status of the AutonomousConverter contract.

Returns: Promise.<AutonomousConverterStatus> - The status.

ParamTypeDescription
contractsObjectThe Metronome contracts.
contracts.AutonomousConverterObjectThe Web3 contract instance.

getMetBalance(contracts, owner) ⇒ Promise.<string>

Get the MET balance of an account.

Returns: Promise.<string> - The MET balance.

ParamTypeDescription
contractsObjectThe Metronome contracts.
contracts.METTokenObjectThe Web3 contract instance.
ownerstringThe address of the account.

getMetChainName(contracts) ⇒ Promise.<string>

Get the Metronome chain name.

Returns: Promise.<string> - The name i.e. 'ETH'.

ParamTypeDescription
contractsObjectThe Metronome contracts.
contracts.AuctionsObjectThe Web3 Auctions contract instance.

getCoinsToMetResult(contracts, depositAmount) ⇒ Promise.<string>

Calculate the coin to MET return conversion.

Returns: Promise.<string> - The MET amount that would be returned.

ParamTypeDescription
contractsObjectThe Metronome contracts.
contracts.AutonomousConverterObjectThe Web3 contract instance.
depositAmountstringThe coin amount to convert.

getMetToCoinsResult(contracts, depositAmount) ⇒ Promise.<string>

Calculate the MET to coin return conversion.

Returns: Promise.<string> - The coin amount that would be returned.

ParamTypeDescription
contractsObjectThe Metronome contracts.
contracts.AutonomousConverterObjectThe Web3 contract instance.
depositAmountstringThe MET amount to convert.

getDestinationChainData(contracts) ⇒ Promise.<DestinationChainData>

Get the destination chain data to perform an export.

Returns: Promise.<DestinationChainData> - The chain data.

ParamTypeDescription
contractsObjectThe Metronome contracts.
contracts.AuctionsObjectThe Web3 contract instance.
contracts.METTokenObjectThe Web3 contract instance.

getOriginChainData(contracts) ⇒ Promise.<OriginChainData>

Get the destination chain data to perform an export.

Returns: Promise.<OriginChainData> - The chain data.

ParamTypeDescription
contractsObjectThe Metronome contracts.
contracts.AuctionsObjectThe Web3 contract instance.

getMetExportFee(contracts, amount, givenFee) ⇒ Promise.<string>

Get the minimum MET fee required by the TokenPorter to process a port operation.

If a fee amount is provided, it will just return that for convenience.

Returns: Promise.<string> - The port fee.

ParamTypeDescription
contractsObjectThe Metronome contracts.
contracts.TokenPorterObjectThe Web3 TokenPorter contract instance.
amountstringThe coin amount to port.
givenFeestringThe fee amount.

getExportProof(contracts, burnSequence) ⇒ Promise.<string>

Get the Merkle root of a last 16 burns.

This is the proof required to import the burned MET into another chain.

Returns: Promise.<string> - The Merkle root hash.

ParamTypeDescription
contractsObjectThe Metronome contracts.
contracts.TokenPorterObjectThe Web3 TokenPorter contract instance.
burnSequencestringThe burn sequence number.

buyMet(web3, contracts, options) ⇒ Promise.<WrappedPromiEvent>

Buy MET in auction.

Returns: Promise.<WrappedPromiEvent> - The wrapped purchase Web3 PromiEvent.

ParamTypeDescription
web3ObjectA Web3 instance.
contractsObjectThe Metronome contracts.
contracts.AuctionsObjectThe Web3 Auctions contract instance.
optionsObjectThe purchase Web3 transaction object.
options.fromstringThe sender address.
options.gasnumberThe gas to use.
options.noncenumberThe nonce.
options.valuestringThe coins to send to the contract.

sendMet(contracts, params, options) ⇒ Promise.<WrappedPromiEvent>

Transfer MET.

Returns: Promise.<WrappedPromiEvent> - The weapped transfer Web3 PromiEvent.

ParamTypeDescription
contractsObjectThe Metronome contracts.
contracts.METTokenObjectThe Web3 contract instance.
paramsObjectThe transfer params.
params.tostringThe recipient address.
params.valuestringThe amount to transfer.
optionsObjectThe transfer Web3 transaction options.
options.fromstringThe sender address.
options.gasnumberThe gas to use.
options.noncenumberThe nonce.

approveMet(contracts, params, options) ⇒ Promise.<WrappedPromiEvent>

Set MET allowance.

Returns: Promise.<WrappedPromiEvent> - The weapped allowance Web3 PromiEvent.

ParamTypeDescription
contractsObjectThe Metronome contracts.
contracts.METTokenObjectThe Web3 contract instance.
paramsObjectThe allowance params.
params.spenderstringThe address allowed to spend tokens.
params.valuestringThe amount to approve.
optionsObjectThe allowance Web3 transaction options.
options.fromstringThe sender address.
options.gasnumberThe gas to use.
options.noncenumberThe nonce.

convertCoinsToMet(contracts, params, options) ⇒ Promise.<WrappedPromiEvent>

Convert coins to MET.

Returns: Promise.<WrappedPromiEvent> - The weapped conversion Web3 PromiEvent.

ParamTypeDescription
contractsObjectThe Metronome contracts.
contracts.AutonomousConverterObjectThe Web3 contract instance.
paramsObjectThe conversion params.
params.minReturnstringWill cancel conversion if minReturn tokens are not obtained.
optionsObjectThe conversion Web3 transaction options.
options.fromstringThe sender address.
options.gasnumberThe gas to use.
options.noncenumberThe nonce.
options.valuestringThe coin amount to convert.

convertMetToCoins(web3, contracts, params, options) ⇒ Promise.<Array.<WrappedPromiEvent>>

Convert MET to coins.

This is a high-level operation that ensure the AutonomousConverter contract is allowed to spend MET by the amount willing to be converted. The operation might then send 1, 2 or 3 transactions depending on the scenario and therefore will return the same amount of PromiEvents.

Returns: Promise.<Array.<WrappedPromiEvent>> - The weapped conversion Web3 PromiEvents.

ParamTypeDescription
web3ObjectA Web3 instance.
contractsObjectThe Metronome contracts.
contracts.AutonomousConverterObjectThe Web3 contract instance.
contracts.METTokenObjectThe Web3 contract instance.
paramsObjectThe conversion params.
params.amountstringThe MET amount to convert.
params.minReturnstringWill cancel conversion if minReturn tokens are not obtained.
optionsObjectThe conversion Web3 transaction options.
options.fromstringThe sender address.

exportMet(contracts, params, options) ⇒ Promise.<WrappedPromiEvent>

Initiate an export of MET to another chain and obtain the burn data.

Returns: Promise.<WrappedPromiEvent> - The weapped export Web3 PromiEvent.

ParamTypeDescription
contractsObjectThe Metronome contracts.
contracts.METTokenObjectThe Web3 contract instance.
contracts.TokenPorterObjectThe Web3 contract instance.
paramsObjectThe export params.
params.amountstringThe MET amount to burn and export.
params.destinationDataDestinationChainDataThe destination chain data.
params.destRecipAddrstringThe recipient address. Defaults to sender.
params.extraDatastringExtra information.
params.feestringThe export fee.
optionsObjectThe export Web3 transaction options.
options.fromstringThe sender address.
options.gasnumberThe gas to use.
options.noncenumberThe nonce.

importMet(contracts, params, options) ⇒ Promise.<WrappedPromiEvent>

Request the import of MET burned on another chain.

This operation will log events the validators will listen in order to complete the import process by signaling the METToken contract to mint and transfer the tokens.

Returns: Promise.<WrappedPromiEvent> - The weapped export Web3 PromiEvent.

ParamTypeDescription
contractsObjectThe Metronome contracts.
contracts.METTokenObjectThe Web3 contract instance.
paramsObjectThe import params.
params.exportDataObjectThe data obtained when the tokens were exported.
params.originDataOriginChainDataThe origin chain data.
params.proofstringThe burn proof on the origin chain.
optionsObjectThe export Web3 transaction options.
options.fromstringThe sender address.
options.gasnumberThe gas to use.
options.noncenumberThe nonce.

AuctionStatus : Object.<string, any>

An object representing the auction status.

Properties

NameTypeDescription
currAuctionstringThe auction number.
currentAuctionPricestringThe MET price.
dailyAuctionStartTimenumberThe daily auctions start time (ms).
genesisTimenumberThe ISA start time (ms).
lastPurchasePricestringThe last purchase price.
lastPurchaseTimenumberThe last purchase time (ms).
mintingstringThe coins available in the current auction.
nextAuctionTimenumberThe next auction start time (ms).

AutonomousConverterStatus : Object

An object representing the autonomous converter status.

The converter price returned is for informational purposes only as the conversion price will change depending on the amount sent and the contract's balance.

Properties

NameTypeDescription
currentConverterPricestringThe coins returned for 1 MET.
ethBalancestringThe contract's coins balance. I.e. ETH.
metBalancestringThe contract's MET balance.

DestinationChainData : Object

An object having destination contracts data.

Properties

NameTypeDescription
destChainstringThe Metronome chain name.
destMetronomeAddrstringThe METToken contract address.

OriginChainData : Object

An object having destination contracts data.

Properties

NameTypeDescription
dailyAuctionStartTimenumberThe METToken contract address.
genesisTimenumberThe METToken contract address.
originChainstringThe Metronome chain name.

WrappedPromiEvent : Object.<string, any>

A wrapped PromiEvent object.

Properties

NameTypeDescription
promiEventObjectA Web3 PromiEvent instance.

License

MIT