Class: Mangrove
Constructorsβ
constructorβ
β’ new Mangrove(params
): Mangrove
Parametersβ
Name | Type |
---|---|
params | Object |
params.signer | Signer |
params.network | ProviderNetwork |
params.readOnly | boolean |
params.blockManagerOptions | Options |
params.reliableHttpProvider | Options |
params.getLogsTimeout | number |
params.eventEmitter | EventEmitter |
params.reliableWebSocketOptions? | Object |
params.reliableWebSocketOptions.options | Options |
params.reliableWebSocketOptions.wsUrl | string |
params.shouldNotListenToNewEvents? | boolean |
params.multicallContract | Multicall2 |
params.address | string |
params.contract | IMangrove |
params.readerContract | MgvReader |
params.orderContract | MangroveOrder |
params.config | GlobalConfig |
Returnsβ
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β
Name | Type | Description |
---|---|---|
options? | string | CreateOptions | Optional 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β
Name | Type |
---|---|
olKey | OLKeyStruct |
Returnsβ
string
Defined inβ
@mangrovedao/mangrove.js/src/mangrove.ts:384
getOlKeyStructβ
βΈ getOlKeyStruct(olKeyHash
): Promise
<undefined
| OLKeyStruct
>
Parametersβ
Name | Type |
---|---|
olKeyHash | string |
Returnsβ
Promise
<undefined
| OLKeyStruct
>
Defined inβ
@mangrovedao/mangrove.js/src/mangrove.ts:397
calculateOLKeyHashβ
βΈ calculateOLKeyHash(olKey
): string
Parametersβ
Name | Type |
---|---|
olKey | OLKeyStruct |
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β
Name | Type | Description |
---|---|---|
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β
Name | Type |
---|---|
params | Key & { 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β
Name | Type |
---|---|
logic | string |
Returnsβ
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β
Name | Type |
---|---|
p | Market | { 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β
Name | Type |
---|---|
symbolOrId | string |
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β
Name | Type |
---|---|
symbol | string |
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β
Name | Type |
---|---|
tokenId | string |
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β
Name | Type |
---|---|
address | string |
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β
Name | Type |
---|---|
name | string |
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β
Name | Type |
---|---|
symbolOrId | string |
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β
Name | Type |
---|---|
name | string |
address | string |
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β
Name | Type |
---|---|
address | string |
overrides | Overrides |
Returnsβ
Promise
<Big
>
Defined inβ
@mangrovedao/mangrove.js/src/mangrove.ts:616
fundMangroveβ
βΈ fundMangrove(amount
, maker
, overrides?
): Promise
<ContractTransaction
>
Parametersβ
Name | Type |
---|---|
amount | BigSource |
maker | string |
overrides | Overrides |
Returnsβ
Promise
<ContractTransaction
>
Defined inβ
@mangrovedao/mangrove.js/src/mangrove.ts:624
withdrawβ
βΈ withdraw(amount
, overrides?
): Promise
<ContractTransaction
>
Parametersβ
Name | Type |
---|---|
amount | BigSource |
overrides | Overrides |
Returnsβ
Promise
<ContractTransaction
>
Defined inβ
@mangrovedao/mangrove.js/src/mangrove.ts:636
optValueToPayableOverrideβ
βΈ optValueToPayableOverride(overrides
, fund?
): PayableOverrides
Parametersβ
Name | Type |
---|---|
overrides | Overrides |
fund? | BigSource |
Returnsβ
PayableOverrides
Defined inβ
@mangrovedao/mangrove.js/src/mangrove.ts:643
approveMangroveβ
βΈ approveMangrove(tokenId
, arg?
): Promise
<ContractTransaction
>
Parametersβ
Name | Type |
---|---|
tokenId | string |
arg | ApproveArgs |
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β
Name | Type | Description |
---|---|---|
gasprice | number | the gas price for the offer in Mwei. |
gasreq | number | the gas requirement for the offer |
gasbase | number | the 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β
Name | Type | Description |
---|---|---|
offers | OfferProvisionParams [] | 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β
Name | Type | Description |
---|---|---|
lockedProvision | BigSource | the provision already locked for an offer. |
totalRequiredProvision | BigSource | the 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β
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β
Name | Type |
---|---|
rawConfig | GlobalUnpackedStructOutput |
Returnsβ
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β
Name | Type |
---|---|
params | SimplePermitData |
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β
Name | Type |
---|---|
params | SimplePermitData |
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β
Name | Type |
---|---|
data | PermitData |
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β
Name | Type |
---|---|
params | SimplePermitData |
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β
Name | Type |
---|---|
network | string |
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β
Name | Type |
---|---|
name | string |
network | string |
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β
Name | Type |
---|---|
name | string |
address | string |
network | string |
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β
Name | Type |
---|---|
devNode | DevNode |
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β
Name | Type | Description |
---|---|---|
params | Object | - |
params.from? | number | start at market from . Default 0. |
params.maxLen? | number | BigNumber | max number of markets returned. Default all. |
params.configs? | boolean | fetch 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β
Name | Type |
---|---|
token0 | Token |
token1 | Token |
Returnsβ
Object
Name | Type |
---|---|
base | Token |
quote | Token |
Defined inβ
@mangrovedao/mangrove.js/src/mangrove.ts:979