metronome-ops
v1.0.0
Published
Basic Metronome Token operations
Downloads
4
Maintainers
Readme
metronome-ops
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.
| Param | Type | Description | | --- | --- | --- | | contracts | Object | The Metronome contracts. | | contracts.Auctions | Object | The Web3 Auctions contract instance. |
getConverterStatus(contracts) ⇒ Promise.<AutonomousConverterStatus>
Get the status of the AutonomousConverter contract.
Returns: Promise.<AutonomousConverterStatus> - The status.
| Param | Type | Description | | --- | --- | --- | | contracts | Object | The Metronome contracts. | | contracts.AutonomousConverter | Object | The Web3 contract instance. |
getMetBalance(contracts, owner) ⇒ Promise.<string>
Get the MET balance of an account.
Returns: Promise.<string> - The MET balance.
| Param | Type | Description | | --- | --- | --- | | contracts | Object | The Metronome contracts. | | contracts.METToken | Object | The Web3 contract instance. | | owner | string | The address of the account. |
getMetChainName(contracts) ⇒ Promise.<string>
Get the Metronome chain name.
Returns: Promise.<string> - The name i.e. 'ETH'
.
| Param | Type | Description | | --- | --- | --- | | contracts | Object | The Metronome contracts. | | contracts.Auctions | Object | The 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.
| Param | Type | Description | | --- | --- | --- | | contracts | Object | The Metronome contracts. | | contracts.AutonomousConverter | Object | The Web3 contract instance. | | depositAmount | string | The 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.
| Param | Type | Description | | --- | --- | --- | | contracts | Object | The Metronome contracts. | | contracts.AutonomousConverter | Object | The Web3 contract instance. | | depositAmount | string | The MET amount to convert. |
getDestinationChainData(contracts) ⇒ Promise.<DestinationChainData>
Get the destination chain data to perform an export.
Returns: Promise.<DestinationChainData> - The chain data.
| Param | Type | Description | | --- | --- | --- | | contracts | Object | The Metronome contracts. | | contracts.Auctions | Object | The Web3 contract instance. | | contracts.METToken | Object | The Web3 contract instance. |
getOriginChainData(contracts) ⇒ Promise.<OriginChainData>
Get the destination chain data to perform an export.
Returns: Promise.<OriginChainData> - The chain data.
| Param | Type | Description | | --- | --- | --- | | contracts | Object | The Metronome contracts. | | contracts.Auctions | Object | The 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.
| Param | Type | Description | | --- | --- | --- | | contracts | Object | The Metronome contracts. | | contracts.TokenPorter | Object | The Web3 TokenPorter contract instance. | | amount | string | The coin amount to port. | | [givenFee] | string | The 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.
| Param | Type | Description | | --- | --- | --- | | contracts | Object | The Metronome contracts. | | contracts.TokenPorter | Object | The Web3 TokenPorter contract instance. | | burnSequence | string | The burn sequence number. |
buyMet(web3, contracts, options) ⇒ Promise.<WrappedPromiEvent>
Buy MET in auction.
Returns: Promise.<WrappedPromiEvent> - The wrapped purchase Web3 PromiEvent.
| Param | Type | Description | | --- | --- | --- | | web3 | Object | A Web3 instance. | | contracts | Object | The Metronome contracts. | | contracts.Auctions | Object | The Web3 Auctions contract instance. | | options | Object | The purchase Web3 transaction object. | | options.from | string | The sender address. | | [options.gas] | number | The gas to use. | | [options.nonce] | number | The nonce. | | options.value | string | The coins to send to the contract. |
sendMet(contracts, params, options) ⇒ Promise.<WrappedPromiEvent>
Transfer MET.
Returns: Promise.<WrappedPromiEvent> - The weapped transfer Web3 PromiEvent.
| Param | Type | Description | | --- | --- | --- | | contracts | Object | The Metronome contracts. | | contracts.METToken | Object | The Web3 contract instance. | | params | Object | The transfer params. | | params.to | string | The recipient address. | | params.value | string | The amount to transfer. | | options | Object | The transfer Web3 transaction options. | | options.from | string | The sender address. | | [options.gas] | number | The gas to use. | | [options.nonce] | number | The nonce. |
approveMet(contracts, params, options) ⇒ Promise.<WrappedPromiEvent>
Set MET allowance.
Returns: Promise.<WrappedPromiEvent> - The weapped allowance Web3 PromiEvent.
| Param | Type | Description | | --- | --- | --- | | contracts | Object | The Metronome contracts. | | contracts.METToken | Object | The Web3 contract instance. | | params | Object | The allowance params. | | params.spender | string | The address allowed to spend tokens. | | params.value | string | The amount to approve. | | options | Object | The allowance Web3 transaction options. | | options.from | string | The sender address. | | [options.gas] | number | The gas to use. | | [options.nonce] | number | The nonce. |
convertCoinsToMet(contracts, params, options) ⇒ Promise.<WrappedPromiEvent>
Convert coins to MET.
Returns: Promise.<WrappedPromiEvent> - The weapped conversion Web3 PromiEvent.
| Param | Type | Description | | --- | --- | --- | | contracts | Object | The Metronome contracts. | | contracts.AutonomousConverter | Object | The Web3 contract instance. | | params | Object | The conversion params. | | [params.minReturn] | string | Will cancel conversion if minReturn tokens are not obtained. | | options | Object | The conversion Web3 transaction options. | | options.from | string | The sender address. | | [options.gas] | number | The gas to use. | | [options.nonce] | number | The nonce. | | options.value | string | The 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.
| Param | Type | Description | | --- | --- | --- | | web3 | Object | A Web3 instance. | | contracts | Object | The Metronome contracts. | | contracts.AutonomousConverter | Object | The Web3 contract instance. | | contracts.METToken | Object | The Web3 contract instance. | | params | Object | The conversion params. | | params.amount | string | The MET amount to convert. | | [params.minReturn] | string | Will cancel conversion if minReturn tokens are not obtained. | | options | Object | The conversion Web3 transaction options. | | options.from | string | The 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.
| Param | Type | Description | | --- | --- | --- | | contracts | Object | The Metronome contracts. | | contracts.METToken | Object | The Web3 contract instance. | | contracts.TokenPorter | Object | The Web3 contract instance. | | params | Object | The export params. | | params.amount | string | The MET amount to burn and export. | | params.destinationData | DestinationChainData | The destination chain data. | | [params.destRecipAddr] | string | The recipient address. Defaults to sender. | | [params.extraData] | string | Extra information. | | [params.fee] | string | The export fee. | | options | Object | The export Web3 transaction options. | | options.from | string | The sender address. | | [options.gas] | number | The gas to use. | | [options.nonce] | number | The 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.
| Param | Type | Description | | --- | --- | --- | | contracts | Object | The Metronome contracts. | | contracts.METToken | Object | The Web3 contract instance. | | params | Object | The import params. | | params.exportData | Object | The data obtained when the tokens were exported. | | params.originData | OriginChainData | The origin chain data. | | params.proof | string | The burn proof on the origin chain. | | options | Object | The export Web3 transaction options. | | options.from | string | The sender address. | | [options.gas] | number | The gas to use. | | [options.nonce] | number | The nonce. |
AuctionStatus : Object.<string, any>
An object representing the auction status.
Properties
| Name | Type | Description | | --- | --- | --- | | currAuction | string | The auction number. | | currentAuctionPrice | string | The MET price. | | dailyAuctionStartTime | number | The daily auctions start time (ms). | | genesisTime | number | The ISA start time (ms). | | lastPurchasePrice | string | The last purchase price. | | lastPurchaseTime | number | The last purchase time (ms). | | minting | string | The coins available in the current auction. | | nextAuctionTime | number | The 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
| Name | Type | Description | | --- | --- | --- | | currentConverterPrice | string | The coins returned for 1 MET. | | ethBalance | string | The contract's coins balance. I.e. ETH. | | metBalance | string | The contract's MET balance. |
DestinationChainData : Object
An object having destination contracts data.
Properties
| Name | Type | Description | | --- | --- | --- | | destChain | string | The Metronome chain name. | | destMetronomeAddr | string | The METToken contract address. |
OriginChainData : Object
An object having destination contracts data.
Properties
| Name | Type | Description | | --- | --- | --- | | dailyAuctionStartTime | number | The METToken contract address. | | genesisTime | number | The METToken contract address. | | originChain | string | The Metronome chain name. |
WrappedPromiEvent : Object.<string, any>
A wrapped PromiEvent object.
Properties
| Name | Type | Description | | --- | --- | --- | | promiEvent | Object | A Web3 PromiEvent instance. |
License
MIT