Skip to main content

Class: Mangrove

Constructors​

constructor​

β€’ new Mangrove(params): Mangrove

Parameters​

NameType
paramsObject
params.signerSigner
params.networkProviderNetwork
params.readOnlyboolean
params.blockManagerOptionsOptions
params.reliableHttpProviderOptions
params.getLogsTimeoutnumber
params.eventEmitterEventEmitter
params.reliableWebSocketOptions?Object
params.reliableWebSocketOptions.optionsOptions
params.reliableWebSocketOptions.wsUrlstring
params.shouldNotListenToNewEvents?boolean
params.multicallContractMulticall2
params.addressstring
params.contractIMangrove
params.readerContractMgvReader
params.orderContractMangroveOrder
params.configGlobalConfig

Returns​

Mangrove

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:306

Properties​

provider​

β€’ provider: Provider

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:123


signer​

β€’ signer: Signer

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:124


network​

β€’ network: ProviderNetwork

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:125


_readOnly​

β€’ _readOnly: boolean

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:126


address​

β€’ address: string

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:127


contract​

β€’ contract: IMangrove

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:128


readerContract​

β€’ readerContract: MgvReader

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:129


multicallContract​

β€’ multicallContract: Multicall2

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:130


orderContract​

β€’ orderContract: MangroveOrder

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:131


reliableProvider​

β€’ reliableProvider: ReliableProvider

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:132


mangroveEventSubscriber​

β€’ mangroveEventSubscriber: MangroveEventSubscriber

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:133


shouldNotListenToNewEvents​

β€’ shouldNotListenToNewEvents: boolean

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:134


olKeyHashToOLKeyStructMap​

β€’ olKeyHashToOLKeyStructMap: Map<string, OLKeyStruct>

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:135


olKeyStructToOlKeyHashMap​

β€’ olKeyStructToOlKeyHashMap: Map<string, string>

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:136


nativeToken​

β€’ nativeToken: TokenCalculations

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:137


eventEmitter​

β€’ eventEmitter: EventEmitter

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:139


_config​

β€’ _config: GlobalConfig

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:140


devNode​

β–ͺ Static devNode: DevNode

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:142


typechain​

β–ͺ Static typechain: __module = typechain

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:143

Methods​

connect​

β–Έ connect(options?): Promise<Mangrove>

Creates an instance of the Mangrove Typescript object

Parameters​

NameTypeDescription
options?string | CreateOptionsOptional provider options

Returns​

Promise<Mangrove>

Returns an instance mangrove.js

Example

const mgv = await require('mangrove.js').connect(options); // web browser

if options is a string s, it is considered to be {provider:s} const mgv = await require('mangrove.js').connect('http://127.0.0.1:8545'); // HTTP provider

Options:

  • privateKey: 0x...
  • mnemonic: horse battery ...
  • path: m/44'/60'/0'/...
  • provider: url, provider object, or chain string

See

Mangrove.CreateOptions for more details on optional provider parameters.

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:168


disconnect​

β–Έ disconnect(): void

Disconnect from Mangrove.

Removes all listeners from the provider and stops the reliable provider.

Returns​

void

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:295


getOlKeyHash​

β–Έ getOlKeyHash(olKey): string

Parameters​

NameType
olKeyOLKeyStruct

Returns​

string

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:384


getOlKeyStruct​

β–Έ getOlKeyStruct(olKeyHash): Promise<undefined | OLKeyStruct>

Parameters​

NameType
olKeyHashstring

Returns​

Promise<undefined | OLKeyStruct>

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:397


calculateOLKeyHash​

β–Έ calculateOLKeyHash(olKey): string

Parameters​

NameType
olKeyOLKeyStruct

Returns​

string

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:417


updateConfiguration​

β–Έ updateConfiguration(config?): void

Update the configuration by providing a partial configuration containing only the values that should be changed/added.

Parameters​

NameTypeDescription
config?RecursivePartial<Configuration>Partial configuration that should be merged into the existing configuration.

Returns​

void

Example

updateConfiguration({
tokens: {
SYM: {
decimals: 18
}
}
})

This adds configuration for a new token with symbol "SYM". Or, if "SYM" was already configured, ensures that its decimals is set to 18.

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:440


resetConfiguration​

β–Έ resetConfiguration(): void

Reset the configuration to defaults provided by mangrove.js

Returns​

void

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:445


market​

β–Έ market(params): Promise<Market>


Parameters​

NameType
paramsKey & { bookOptions?: BookOptions }

Returns​

Promise<Market>

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:481


offerLogic​

β–Έ offerLogic(logic): OfferLogic

Get an OfferLogic object allowing one to monitor and set up an onchain offer logic

Parameters​

NameType
logicstring

Returns​

OfferLogic

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:506


liquidityProvider​

β–Έ liquidityProvider(p): Promise<LiquidityProvider>

Get a LiquidityProvider object to enable Mangrove's signer to pass buy and sell orders.

Parameters​

NameType
pMarket | { base: string ; quote: string ; tickSpacing: number ; bookOptions?: BookOptions }

Returns​

Promise<LiquidityProvider>

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:522


token​

β–Έ token(symbolOrId, options?): Promise<Token>

Return Token instance, fetching data (decimals) from chain if needed.

Parameters​

NameType
symbolOrIdstring
options?ConstructorOptions

Returns​

Promise<Token>

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:551


tokenFromSymbol​

β–Έ tokenFromSymbol(symbol, options?): Promise<Token>

Return Token instance, fetching data (decimals) from chain if needed.

Parameters​

NameType
symbolstring
options?ConstructorOptions

Returns​

Promise<Token>

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:559


tokenFromId​

β–Έ tokenFromId(tokenId, options?): Promise<Token>

Return Token instance, fetching data (decimals) from chain if needed.

Parameters​

NameType
tokenIdstring
options?ConstructorOptions

Returns​

Promise<Token>

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:567


tokenFromAddress​

β–Έ tokenFromAddress(address): Promise<Token>

Return token instance from address, fetching data (decimals) from chain if needed.

Parameters​

NameType
addressstring

Returns​

Promise<Token>

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:577


getAddress​

β–Έ getAddress(name): string

Read a contract address on the current network.

Note that this reads from the static Mangrove address registry which is shared across instances of this class.

Parameters​

NameType
namestring

Returns​

string

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:586


getTokenAddress​

β–Έ getTokenAddress(symbolOrId): string

Read a token address on the current network.

Note that this reads from the static Mangrove address registry which is shared across instances of this class.

Parameters​

NameType
symbolOrIdstring

Returns​

string

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:598


setAddress​

β–Έ setAddress(name, address): void

Set a contract address on the current network.

Note that this writes to the static Mangrove address registry which is shared across instances of this class.

Parameters​

NameType
namestring
addressstring

Returns​

void

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:607


balanceOf​

β–Έ balanceOf(address, overrides?): Promise<Big>

Provision available at mangrove for address given in argument, in ethers

Parameters​

NameType
addressstring
overridesOverrides

Returns​

Promise<Big>

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:616


fundMangrove​

β–Έ fundMangrove(amount, maker, overrides?): Promise<ContractTransaction>

Parameters​

NameType
amountBigSource
makerstring
overridesOverrides

Returns​

Promise<ContractTransaction>

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:624


withdraw​

β–Έ withdraw(amount, overrides?): Promise<ContractTransaction>

Parameters​

NameType
amountBigSource
overridesOverrides

Returns​

Promise<ContractTransaction>

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:636


optValueToPayableOverride​

β–Έ optValueToPayableOverride(overrides, fund?): PayableOverrides

Parameters​

NameType
overridesOverrides
fund?BigSource

Returns​

PayableOverrides

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:643


approveMangrove​

β–Έ approveMangrove(tokenId, arg?): Promise<ContractTransaction>

Parameters​

NameType
tokenIdstring
argApproveArgs

Returns​

Promise<ContractTransaction>

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:654


calculateOfferProvision​

β–Έ calculateOfferProvision(gasprice, gasreq, gasbase): Big

Calculates the provision required or locked for an offer based on the given parameters

Parameters​

NameTypeDescription
gaspricenumberthe gas price for the offer in Mwei.
gasreqnumberthe gas requirement for the offer
gasbasenumberthe offer list's offer_gasbase.

Returns​

Big

the required provision, in ethers.

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:668


calculateOffersProvision​

β–Έ calculateOffersProvision(offers): Big

Calculates the provision required or locked for offers based on the given parameters

Parameters​

NameTypeDescription
offersOfferProvisionParams[]the offers to calculate provision for.

Returns​

Big

the required provision, in ethers.

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:680


getMissingProvision​

β–Έ getMissingProvision(lockedProvision, totalRequiredProvision): Big

Gets the missing provision based on the required provision and the locked provision.

Parameters​

NameTypeDescription
lockedProvisionBigSourcethe provision already locked for an offer.
totalRequiredProvisionBigSourcethe provision required for an offer.

Returns​

Big

the additional required provision, in ethers.

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:699


config​

β–Έ config(): GlobalConfig

Return global Mangrove config from cache.

Returns​

GlobalConfig

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:711


fetchConfig​

β–Έ fetchConfig(): Promise<GlobalConfig>

Return global Mangrove config from chain.

Returns​

Promise<GlobalConfig>

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:718


rawConfigToConfig​

β–Έ rawConfigToConfig(rawConfig): GlobalConfig

Parameters​

NameType
rawConfigGlobalUnpackedStructOutput

Returns​

GlobalConfig

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:724


normalizePermitData​

β–Έ normalizePermitData(params): Promise<PermitData>

Permit data normalization Autofill/convert 'nonce' field of permit data if need, convert deadline to num if needed.

Parameters​

NameType
paramsSimplePermitData

Returns​

Promise<PermitData>

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:743


simpleSignPermitData​

β–Έ simpleSignPermitData(params): Promise<string>

Sign typed data for permit(). To set the deadline to +days or +months, you can do let date = new Date(); date.setDate(date.getDate() + days); date.setMonth(date.getMonth() + months);

  • Nonce is auto-selected if needed and can be a number
  • Date can be a Date or a number

Parameters​

NameType
paramsSimplePermitData

Returns​

Promise<string>

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:774


signPermitData​

β–Έ signPermitData(data): Promise<string>

Permit data generator for normalized permit data input

Parameters​

NameType
dataPermitData

Returns​

Promise<string>

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:780


permit​

β–Έ permit(params): Promise<ContractTransaction>

Give permit to Mangrove. Permit params.spender to buy on behalf of owner on the outbound/inbound offer list up to value. Default deadline is now + 1 day. Default nonce is current owner nonce.

Parameters​

NameType
paramsSimplePermitData

Returns​

Promise<ContractTransaction>

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:816


getAllAddresses​

β–Έ getAllAddresses(network): [string, string][]

Read all contract addresses on the given network.

Parameters​

NameType
networkstring

Returns​

[string, string][]

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:848


getAddress​

β–Έ getAddress(name, network): string

Read a contract address on a given network.

Parameters​

NameType
namestring
networkstring

Returns​

string

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:855


setAddress​

β–Έ setAddress(name, address, network): void

Set a contract address on the given network.

Parameters​

NameType
namestring
addressstring
networkstring

Returns​

void

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:862


initAndListenToDevNode​

β–Έ initAndListenToDevNode(devNode): Promise<void>

Setup dev node necessary contracts if needed, register dev Multicall2 address, listen to future additions (a script external to mangrove.js may deploy contracts during execution).

Parameters​

NameType
devNodeDevNode

Returns​

Promise<void>

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:871


openMarkets​

β–Έ openMarkets(params?): Promise<OpenMarketInfo[]>

Returns open markets data according to MgvReader.

Parameters​

NameTypeDescription
paramsObject-
params.from?numberstart at market from. Default 0.
params.maxLen?number | BigNumbermax number of markets returned. Default all.
params.configs?booleanfetch market's config information. Default true.

Returns​

Promise<OpenMarketInfo[]>

Note

If an open market has a token with no/bad decimals/symbol function, this function will revert.

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:902


toBaseQuoteByCashness​

β–Έ toBaseQuoteByCashness(token0, token1): Object

Parameters​

NameType
token0Token
token1Token

Returns​

Object

NameType
baseToken
quoteToken

Defined in​

@mangrovedao/mangrove.js/src/mangrove.ts:979

  • Constructors
    • constructor
  • Properties
    • provider
    • signer
    • network
    • _readOnly
    • address
    • contract
    • readerContract
    • multicallContract
    • orderContract
    • reliableProvider
    • mangroveEventSubscriber
    • shouldNotListenToNewEvents
    • olKeyHashToOLKeyStructMap
    • olKeyStructToOlKeyHashMap
    • nativeToken
    • eventEmitter
    • _config
    • devNode
    • typechain
  • Methods
    • connect
    • disconnect
    • getOlKeyHash
    • getOlKeyStruct
    • calculateOLKeyHash
    • updateConfiguration
    • resetConfiguration
    • market
    • offerLogic
    • liquidityProvider
    • token
    • tokenFromSymbol
    • tokenFromId
    • tokenFromAddress
    • getAddress
    • getTokenAddress
    • setAddress
    • balanceOf
    • fundMangrove
    • withdraw
    • optValueToPayableOverride
    • approveMangrove
    • calculateOfferProvision
    • calculateOffersProvision
    • getMissingProvision
    • config
    • fetchConfig
    • rawConfigToConfig
    • normalizePermitData
    • simpleSignPermitData
    • signPermitData
    • permit
    • getAllAddresses
    • getAddress
    • setAddress
    • initAndListenToDevNode
    • openMarkets
    • toBaseQuoteByCashness