1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00
ocean.js/docs/classes/FixedRateExchange.md
Alex Coseru 9bf71ba4f0
Features/ethers (#1696)
* add ethers

* global updates

* ve updates

* ve tests

* contract updates

* first test passing

* downgrade to ethers 5.7.2

* add log

* add tx wait

* full NftFactory.test

* add wait

* add Router tests

* fix dispenser

* Nft test

* add dispenser tests

* add fre tests part 1

* WIP datatoken unit tests

* add DFRewards test

* increase gas estimate

* increase gas estimate

* Work datatoken unit tests

* datatoken test more tests

* finished datatoken tests

* fix nft get data

* fix nft transfer tests

* Provider int tests

* Updating CodeExamples.md

* update provider & fix publish flow int test

* wip publish edit consume integration test

* more work on  publish edit consume integration test

* fix edit  publish edit consume integration test

* add 3 int tests

* Updating ComputeExamples.md

* fix signature and download

* fix compute flow integration test

* udapte handleComputeOrder helper

* update datatoken instance

* update datatoken global variable

* mint ocean tokens to consumer as well and added logs

* update compute exammples

* Updating ComputeExamples.md

* wip code examples readme

* update code examples readme

* Updating CodeExamples.md

* run all tests

* update dep in readme

* update readme

* code examples update metadata flags

* update dt instance in code examples md

* set metadata updates

* Updating CodeExamples.md

* update code examples readme structure

* Updating CodeExamples.md

* update readmes table links

* Updating CodeExamples.md

* Updating ComputeExamples.md

* clean-up

* Updating CodeExamples.md

* added missing unit tests for usdc fixed rate exchange tests

* more cleanup and jsdoc updates

* more  jsdoc updates

* donw with jsdoc updates

* handle provider errors

* add missing error handling file

* adds most of the provider errors

* update get compute env return type

* Release 3.0.0-next.0

* adding Typedoc to ethers branch

* update provider signature message

* fix lint

* Release 3.0.0-next.1

* fix lint

* adding Typedoc to ethers branch

* Updating CI to build and commit the documentation

* Updating documentation

* Updating script permissions

* fix todos add missing logic to send tx

* npm package cleanups

* Release 3.0.0-next.2

* update log messages for errors

* Release 3.0.0-next.3

* fix gasFee issue on sendTx

* Release 3.0.0-next.4

* add consume params typings (#1731)

* fix gas fee estimate

* remove comments

* add some delays before resolving datasets

* adds delay to Publish flow tests

* Release 3.0.0-next.5

---------

Co-authored-by: Bogdan Fazakas <bogdan.fazakas@gmail.com>
Co-authored-by: GitHub Actions Bot <>
Co-authored-by: Jamie Hewitt <jamie.hewitt15@gmail.com>
Co-authored-by: Jamie Hewitt <jamie@oceanprotocol.com>
2023-05-29 11:20:38 +03:00

26 KiB

@oceanprotocol/lib / Exports / FixedRateExchange

Class: FixedRateExchange

Hierarchy

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new FixedRateExchange(address, signer, network?, config?, abi?)

Instantiate the smart contract.

Parameters

Name Type Description
address string The address of the contract.
signer Signer The signer object.
network? string | number Network id or name
config? Config The configuration object.
abi? AbiItem[] ABI array of the smart contract

Inherited from

SmartContractWithAddress.constructor

Defined in

contracts/SmartContractWithAddress.ts:17

Properties

abi

abi: AbiItem[]

Inherited from

SmartContractWithAddress.abi

Defined in

contracts/SmartContract.ts:14


address

address: string

Inherited from

SmartContractWithAddress.address

Defined in

contracts/SmartContractWithAddress.ts:6


config

config: Config

Inherited from

SmartContractWithAddress.config

Defined in

contracts/SmartContract.ts:13


contract

contract: Contract

Inherited from

SmartContractWithAddress.contract

Defined in

contracts/SmartContractWithAddress.ts:7


signer

signer: Signer

Inherited from

SmartContractWithAddress.signer

Defined in

contracts/SmartContract.ts:12

Methods

activate

activate<G>(exchangeId, estimateGas?): Promise<ReceiptOrEstimate<G>>

Activate an exchange

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
exchangeId string ExchangeId
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transaction receipt

Defined in

contracts/FixedRateExchange.ts:210


activateMint

activateMint<G>(exchangeId, estimateGas?): Promise<ReceiptOrEstimate<G>>

Activate minting option for fixed rate contract

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
exchangeId string Exchang eId
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transaction receipt

Defined in

contracts/FixedRateExchange.ts:462


amountToUnits

Protected amountToUnits(token, amount, tokenDecimals?): Promise<string>

Converts an amount of tokens to units

Parameters

Name Type Description
token string The token to convert
amount string The amount of tokens to convert
tokenDecimals? number The number of decimals of the token

Returns

Promise<string>

  • The converted amount in units

Inherited from

SmartContractWithAddress.amountToUnits

Defined in

contracts/SmartContract.ts:43


buyDatatokens

buyDatatokens<G>(exchangeId, datatokenAmount, maxBaseTokenAmount, consumeMarketAddress?, consumeMarketFee?, estimateGas?): Promise<ReceiptOrEstimate<G>>

Atomic swap

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Default value Description
exchangeId string undefined ExchangeId
datatokenAmount string undefined Amount of datatokens
maxBaseTokenAmount string undefined max amount of baseToken we want to pay for datatokenAmount
consumeMarketAddress string ZERO_ADDRESS consumeMarketAddress
consumeMarketFee string '0' consumeMarketFee in fraction
estimateGas? G undefined if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transaction receipt

Defined in

contracts/FixedRateExchange.ts:38


calcBaseInGivenDatatokensOut

calcBaseInGivenDatatokensOut(exchangeId, datatokenAmount, consumeMarketFee?): Promise<PriceAndFees>

calcBaseInGivenDatatokensOut - Calculates how many base tokens are needed to get specified amount of datatokens

Parameters

Name Type Default value Description
exchangeId string undefined Exchange Id
datatokenAmount string undefined Amount of datatokens user wants to buy
consumeMarketFee string '0' consumeMarketFee in fraction

Returns

Promise<PriceAndFees>

how many base tokens are needed and fees

Defined in

contracts/FixedRateExchange.ts:305


collectBasetokens

collectBasetokens<G>(exchangeId, amount, estimateGas?): Promise<ReceiptOrEstimate<G>>

Collect BaseTokens in the contract (anyone can call this, funds are sent to Datatoken.paymentCollector)

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
exchangeId string Exchange Id
amount string amount to be collected
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transaction receipt

Defined in

contracts/FixedRateExchange.ts:519


collectDatatokens

collectDatatokens<G>(exchangeId, amount, estimateGas?): Promise<ReceiptOrEstimate<G>>

Collect datatokens in the contract (anyone can call this, funds are sent to Datatoken.paymentCollector)

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
exchangeId string Exchange Id
amount string amount to be collected
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transaction receipt

Defined in

contracts/FixedRateExchange.ts:555


collectMarketFee

collectMarketFee<G>(exchangeId, estimateGas?): Promise<ReceiptOrEstimate<G>>

Collect market fee and send it to marketFeeCollector (anyone can call it)

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
exchangeId string Exchange Id
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transaction receipt

Defined in

contracts/FixedRateExchange.ts:590


collectOceanFee

collectOceanFee<G>(exchangeId, estimateGas?): Promise<ReceiptOrEstimate<G>>

Collect ocean fee and send it to OPF collector (anyone can call it)

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
exchangeId string Exchange Id
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transaction receipt

Defined in

contracts/FixedRateExchange.ts:617


deactivate

deactivate<G>(exchangeId, estimateGas?): Promise<ReceiptOrEstimate<G>>

Deactivate an exchange

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
exchangeId string ExchangeId
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transaction receipt

Defined in

contracts/FixedRateExchange.ts:236


deactivateMint

deactivateMint<G>(exchangeId, estimateGas?): Promise<ReceiptOrEstimate<G>>

Deactivate minting for fixed rate

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
exchangeId string ExchangeId
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transaction receipt

Defined in

contracts/FixedRateExchange.ts:490


generateExchangeId

generateExchangeId(baseToken, datatoken): Promise<string>

Creates unique exchange identifier.

Parameters

Name Type Description
baseToken string baseToken contract address
datatoken string Datatoken contract address

Returns

Promise<string>

exchangeId

Defined in

contracts/FixedRateExchange.ts:23


getAllowedSwapper

getAllowedSwapper(exchangeId): Promise<string>

Get Allower Swapper (if set this is the only account which can use this exchange, else is set at address(0))

Parameters

Name Type Description
exchangeId string Exchange Id

Returns

Promise<string>

address of allowed swapper

Defined in

contracts/FixedRateExchange.ts:294


getAmountBasetokensOut

getAmountBasetokensOut(exchangeId, datatokenAmount, consumeMarketFee?): Promise<string>

Returns amount in baseToken that user will receive for datatokenAmount sold

Parameters

Name Type Default value Description
exchangeId string undefined Exchange Id
datatokenAmount string undefined Amount of datatokens
consumeMarketFee string '0' consumeMarketFee in fraction

Returns

Promise<string>

Amount of baseTokens user will receive

Defined in

contracts/FixedRateExchange.ts:352


getBasetokenSupply

getBasetokenSupply(exchangeId): Promise<string>

Returns basetoken supply in the exchange

Parameters

Name Type Description
exchangeId string Exchange Id

Returns

Promise<string>

dt supply formatted

Defined in

contracts/FixedRateExchange.ts:283


getContract

Protected getContract(address, abi?): Contract

Returns a contract instance for the given address

Parameters

Name Type Description
address string The address of the contract
abi? AbiItem[] The ABI of the contract

Returns

Contract

  • The contract instance

Inherited from

SmartContractWithAddress.getContract

Defined in

contracts/SmartContract.ts:80


getDatatokenSupply

getDatatokenSupply(exchangeId): Promise<string>

Get Datatoken Supply in the exchange

Parameters

Name Type Description
exchangeId string Exchange Id

Returns

Promise<string>

dt supply formatted

Defined in

contracts/FixedRateExchange.ts:272


getDefaultAbi

getDefaultAbi(): AbiItem[]

Returns

AbiItem[]

Overrides

SmartContractWithAddress.getDefaultAbi

Defined in

contracts/FixedRateExchange.ts:13


getExchange

getExchange(exchangeId): Promise<FixedPriceExchange>

Get exchange details

Parameters

Name Type Description
exchangeId string Exchange Id

Returns

Promise<FixedPriceExchange>

Exchange details

Defined in

contracts/FixedRateExchange.ts:372


getExchangeOwner

getExchangeOwner(exchangeId): Promise<string>

Get Exchange Owner given an exchangeId

Parameters

Name Type Description
exchangeId string Exchange Id

Returns

Promise<string>

return exchange owner

Defined in

contracts/FixedRateExchange.ts:661


getExchanges

getExchanges(): Promise<string[]>

Returns all exchanges

Returns

Promise<string[]>

Exchanges list

Defined in

contracts/FixedRateExchange.ts:442


getFairGasPrice

Protected getFairGasPrice(): Promise<string>

Retruns the gas price

Returns

Promise<string>

  • The fair gas price

Inherited from

SmartContractWithAddress.getFairGasPrice

Defined in

contracts/SmartContract.ts:70


getFeesInfo

getFeesInfo(exchangeId): Promise<FeesInfo>

Get fee details for an exchange

Parameters

Name Type Description
exchangeId string Exchange Id

Returns

Promise<FeesInfo>

Exchange details

Defined in

contracts/FixedRateExchange.ts:414


getNumberOfExchanges

getNumberOfExchanges(): Promise<number>

Gets total number of exchanges

Returns

Promise<number>

no of available exchanges

Defined in

contracts/FixedRateExchange.ts:140


getOPCCollector

getOPCCollector(): Promise<string>

Get OPF Collector of fixed rate contract

Returns

Promise<string>

Defined in

contracts/FixedRateExchange.ts:642


getRate

getRate(exchangeId): Promise<string>

Get Exchange Rate

Parameters

Name Type Description
exchangeId string Exchange ID

Returns

Promise<string>

Rate (converted from wei)

Defined in

contracts/FixedRateExchange.ts:262


getRouter

getRouter(): Promise<string>

Get Router address set in fixed rate contract

Returns

Promise<string>

Defined in

contracts/FixedRateExchange.ts:651


isActive

isActive(exchangeId): Promise<boolean>

Check if an exchange is active

Parameters

Name Type Description
exchangeId string ExchangeId

Returns

Promise<boolean>

Defined in

contracts/FixedRateExchange.ts:451


sellDatatokens

sellDatatokens<G>(exchangeId, datatokenAmount, minBaseTokenAmount, consumeMarketAddress?, consumeMarketFee?, estimateGas?): Promise<ReceiptOrEstimate<G>>

Sell datatokenAmount while expecting at least minBaseTokenAmount

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Default value Description
exchangeId string undefined ExchangeId
datatokenAmount string undefined Amount of datatokens
minBaseTokenAmount string undefined min amount of baseToken we want to receive back
consumeMarketAddress string ZERO_ADDRESS consumeMarketAddress
consumeMarketFee string '0' consumeMarketFee in fraction
estimateGas? G undefined if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transaction receipt

Defined in

contracts/FixedRateExchange.ts:93


setAllowedSwapper

setAllowedSwapper<G>(exchangeId, newAllowedSwapper, estimateGas?): Promise<ReceiptOrEstimate<G>>

Sets a new allowedSwapper

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
exchangeId string Exchange ID
newAllowedSwapper string The address of the new allowed swapper (set address zero if we want to remove allowed swapper)
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transaction receipt

Defined in

contracts/FixedRateExchange.ts:182


setRate

setRate<G>(exchangeId, newRate, estimateGas?): Promise<ReceiptOrEstimate<G>>

Set new rate

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
exchangeId string Exchange ID
newRate string New rate
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transaction receipt

Defined in

contracts/FixedRateExchange.ts:152


unitsToAmount

Protected unitsToAmount(token, amount, tokenDecimals?): Promise<string>

Converts an amount of units to tokens

Parameters

Name Type Description
token string The token to convert
amount string The amount of units to convert
tokenDecimals? number The number of decimals in the token

Returns

Promise<string>

  • The converted amount in tokens

Inherited from

SmartContractWithAddress.unitsToAmount

Defined in

contracts/SmartContract.ts:58


updateMarketFee

updateMarketFee<G>(exchangeId, newMarketFee, estimateGas?): Promise<ReceiptOrEstimate<G>>

Set new market fee, only market fee collector can update it

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
exchangeId string Exchange Id
newMarketFee string New market fee
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transaction receipt

Defined in

contracts/FixedRateExchange.ts:673


updateMarketFeeCollector

updateMarketFeeCollector<G>(exchangeId, newMarketFeeCollector, estimateGas?): Promise<ReceiptOrEstimate<G>>

Set new market fee collector, only market fee collector can update it

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
exchangeId string Exchange Id
newMarketFeeCollector string New market fee collector
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transaction receipt

Defined in

contracts/FixedRateExchange.ts:703