EOSDT JS
A JavaScript library to execute EOSDT contracts methods.
Usage
Install the module using NPM:
Use service module Connector
to initiate one of four functional modules (Positions
, Governance
, Liquidator
or Balances
). Connector
uses EOS node address and an array of private keys. Transactions would be signed with given keys and sent to blockchain through given node.
Modules
Connector
Creates a connector object, used to initiate functional modules and invoke their methods.
Positions
Module to manage EOSDT positions. Methods:
create
- creates new position, using specified amount of EOS as collateral and issuing specified amount of EOSDT to creator. IfeosAmount
arg is equal to zero, creates an empty position.createWithReferral
- same ascreate
, but also sets a referral on position.close
- used to close a position in event of a global shutdown.del
- deletes position that has 0 debt.give
- transfers position ownership to another account.addCollateral
- sends EOS to position to increase it's collateralization.deleteCollateral
- returns specified part of used collateral to user if LTV stays above critical.generateDebt
- issues additional EOSDT for position if this does not bring LTV below critical.burnbackDebt
- repays specified amount of EOSDT decreasing debt.marginCall
- called on a position with critical LTV, to perform a margin call.getContractEosAmount
- returns eosdtcntract EOS balancegetRates
- returns table of current system token prices (rates).getPositionById
- returns a position object, selecting it by id.getAllUserPositions
- returns an array of all positions for specified user (up to 100 positions).getParameters
- returns Positions contract parameters.getSettings
- return Positions contract settings.addReferral
- creates new referral, staking given amount of NUT. Rejects when amount is less thenreferral_min_stake
in positions contract settings.deleteReferral
- removes referral and unstakes that referral's NUT.getReferralById
- returns a referral object.getReferralByName
- returns a referral object.getAllReferrals
- returns table of existing referrals.getPositionReferral
- returns referral of a given position (undefined
if none exists).getPositionReferralsTable
- returns an array of positions ids and those positions referrals.getAllReferralPositionsIds
- returns an array of positions with given referral id.
Governance
Governance methods help manage the system: create proposals to change system parameters, vote on them and stake NUT tokens for voting. Methods:
propose
- creates a proposal.expire
- expires an active proposal.applyChanges
- apply proposed changes (at least 51% of all issued NUT tokens must vote, at least 55% of votes must be positive).cleanProposal
- remove specified amount of votes from an expired proposal. If 0 votes left, removes proposal.stake
- sends NUT tokens to contract, staking them and allowing to vote on proposals.unstake
- unstakes NUT tokens, returning them to user and lowering amount of available votes.vote
- vote for or against a proposal. Vote1
as "yes",0
or any other number as "no".unvote
- removes all user votes from a proposal.voteForBlockProducers
- voting with staked NUTs for specified block producers.stakeAndVoteForBlockProducers
- stakes NUT and votes for BPs in one transaction.getVoterInfo
- returns amount of NUTs staked by account in EOSDT Governance contract and their unstake date.getVoterInfosTable
- returns the whole table of information on accounts that staked NUTgetVotes
- returns an array with all votes (up to 1000).getProposals
- returns an array with all proposals (up to 1000).getBpVotes
- returns array of block producers names and amount of NUT votes for them.getProxyInfo
- returns voter info foreosdtbpproxy
.getSettings
- returns governance contract settings.
Bp manager
Governance account methods for block producers to manage their voting positions: register, change reward amount, deposit EOS, unregister.
getBpPosition
- returns information about registered block producer.getAllBpPositions
- returns an array of objects, that contain information about registered block producers.registerBlockProducer
- registers a block producer in BP voting reward program.changeBlockProducerReward
- changes amount of EOS reward payed out by block producer.unRegisterBlockProducer
- make block producer position inactive.depositEos
- deposit EOS to block producer position.
Liquidator
Methods to get Liquidator contract parameters and exchange EOS and EOSDT in case of global shutdown.
marginCallAndBuyoutEos
- performes margin call on a position and transfers specified amount of EOSDT to buyout freed EOS.transferEos
- sends EOS to Liquidator contract. It is used to buyout surplus debt with discount.transferEosdt
- sends EOSDT to liquidator contract. It is used to cancel bad debt and buyout liquidator EOS with discount.transferNut
- sends NUT tokens to liquidator contract. It is used to buyout EOS intended to be bought for NUT tokens (parameter "nut_collat_balance").getSurplusDebt
- returns amount of system surplus debt.getBadDebt
- returns amount of system bad debt.getEosBalance
- returns amount of EOS on liquidator contract balance.getParameters
- returns all liquidator contract parameters.
Balances
Module to get account's balances of EOSDT, EOS and NUT. Methods:
getNut
- returns NUT balance of accountgetEosdt
- returns EOSDT balance of accountgetEos
- returns EOS balance of account
Examples
You can find working example scripts in module directory examples
.
Connecting to blockchain
This code block is required for any other example to work.
Position operations
Creating position, adding collateral, issuing addintional debt then returning it, returning collateral from postion and closing it.
Proposals management
Creating, expiring and applying a proposal.
Voting
Staking NUT tokens to vote for and against proposals.
Balances operations
Gettings balances of EOS, EOSDT or NUT
Last updated