16 KiB
@oceanprotocol/lib / Exports / Router
Class: Router
Provides an interface for FactoryRouter contract
Hierarchy
-
↳
Router
Table of contents
Constructors
Properties
Methods
- addApprovedToken
- addDispenserContract
- addFixedRateContract
- amountToUnits
- buyDatatokenBatch
- getContract
- getCurrentOPCFee
- getDefaultAbi
- getFairGasPrice
- getNFTFactory
- getOPCFee
- getOwner
- isApprovedToken
- isFixedPrice
- removeApprovedToken
- removeDispenserContract
- removeFixedRateContract
- unitsToAmount
- updateOPCFee
Constructors
constructor
• new Router(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
Defined in
address
• address: string
Inherited from
SmartContractWithAddress.address
Defined in
contracts/SmartContractWithAddress.ts:6
config
• config: Config
Inherited from
SmartContractWithAddress.config
Defined in
contract
• contract: Contract
Inherited from
SmartContractWithAddress.contract
Defined in
contracts/SmartContractWithAddress.ts:7
signer
• signer: Signer
Inherited from
SmartContractWithAddress.signer
Defined in
Methods
addApprovedToken
▸ addApprovedToken<G
>(address
, tokenAddress
, estimateGas?
): Promise
<ReceiptOrEstimate
<G
>>
Adds a token to the list of tokens with reduced fees
Type parameters
Name | Type |
---|---|
G |
extends boolean = false |
Parameters
Name | Type | Description |
---|---|---|
address |
string |
caller address |
tokenAddress |
string |
token address to add |
estimateGas? |
G |
if True, return gas estimate |
Returns
Promise
<ReceiptOrEstimate
<G
>>
Defined in
addDispenserContract
▸ addDispenserContract<G
>(address
, tokenAddress
, estimateGas?
): Promise
<ReceiptOrEstimate
<G
>>
Adds an address to the list of dispensers
Type parameters
Name | Type |
---|---|
G |
extends boolean = false |
Parameters
Name | Type | Description |
---|---|---|
address |
string |
caller address |
tokenAddress |
string |
contract address to add |
estimateGas? |
G |
if True, return gas estimate |
Returns
Promise
<ReceiptOrEstimate
<G
>>
Defined in
addFixedRateContract
▸ addFixedRateContract<G
>(address
, tokenAddress
, estimateGas?
): Promise
<ReceiptOrEstimate
<G
>>
Adds an address to the list of fixed rate contracts
Type parameters
Name | Type |
---|---|
G |
extends boolean = false |
Parameters
Name | Type | Description |
---|---|---|
address |
string |
caller address |
tokenAddress |
string |
contract address to add |
estimateGas? |
G |
if True, return gas estimate |
Returns
Promise
<ReceiptOrEstimate
<G
>>
Defined in
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
buyDatatokenBatch
▸ buyDatatokenBatch<G
>(operations
, estimateGas?
): Promise
<ReceiptOrEstimate
<G
>>
- Buys a batch of datatokens. one single call to buy multiple DT for multiple assets. require tokenIn approvals for router from user. (except for dispenser operations)
Type parameters
Name | Type |
---|---|
G |
extends boolean = false |
Parameters
Name | Type | Description |
---|---|---|
operations |
Operation [] |
The operations to execute. |
estimateGas? |
G |
Whether to return only the estimate gas or not. |
Returns
Promise
<ReceiptOrEstimate
<G
>>
Transaction receipt
Defined in
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
getCurrentOPCFee
▸ getCurrentOPCFee(): Promise
<number
>
Get Current OPF Fee
Returns
Promise
<number
>
OPF fee
Defined in
getDefaultAbi
▸ getDefaultAbi(): AbiItem
[]
Returns
AbiItem
[]
Overrides
SmartContractWithAddress.getDefaultAbi
Defined in
getFairGasPrice
▸ Protected
getFairGasPrice(): Promise
<string
>
Retruns the gas price
Returns
Promise
<string
>
- The fair gas price
Inherited from
SmartContractWithAddress.getFairGasPrice
Defined in
getNFTFactory
▸ getNFTFactory(): Promise
<string
>
Get NFT Factory address
Returns
Promise
<string
>
NFT Factory address
Defined in
getOPCFee
▸ getOPCFee(baseToken
): Promise
<number
>
Get OPF Fee per token
Parameters
Name | Type |
---|---|
baseToken |
string |
Returns
Promise
<number
>
OPC fee for a specific baseToken
Defined in
getOwner
▸ getOwner(): Promise
<string
>
Get Router Owner
Returns
Promise
<string
>
Router Owner address
Defined in
isApprovedToken
▸ isApprovedToken(address
): Promise
<boolean
>
Checks if a token is on approved tokens list, if true opfFee is lower in pools with that token/DT
Parameters
Name | Type | Description |
---|---|---|
address |
string |
The address of the token to check. |
Returns
Promise
<boolean
>
true if is on the list.
Defined in
isFixedPrice
▸ isFixedPrice(address
): Promise
<boolean
>
Check if an address is a Fixed Rate contract.
Parameters
Name | Type | Description |
---|---|---|
address |
string |
The address of the fixed rate exchange to check. |
Returns
Promise
<boolean
>
true if is a Fixed Rate contract
Defined in
removeApprovedToken
▸ removeApprovedToken<G
>(address
, tokenAddress
, estimateGas?
): Promise
<ReceiptOrEstimate
<G
>>
Removes a token if exists from the list of tokens with reduced fees
Type parameters
Name | Type |
---|---|
G |
extends boolean = false |
Parameters
Name | Type | Description |
---|---|---|
address |
string |
caller address |
tokenAddress |
string |
token address to remove |
estimateGas? |
G |
if True, return gas estimate |
Returns
Promise
<ReceiptOrEstimate
<G
>>
Defined in
removeDispenserContract
▸ removeDispenserContract<G
>(address
, tokenAddress
, estimateGas?
): Promise
<ReceiptOrEstimate
<G
>>
Removes an address from the list of dispensers
Type parameters
Name | Type |
---|---|
G |
extends boolean = false |
Parameters
Name | Type | Description |
---|---|---|
address |
string |
caller address |
tokenAddress |
string |
address Contract to be removed |
estimateGas? |
G |
if True, return gas estimate |
Returns
Promise
<ReceiptOrEstimate
<G
>>
Defined in
removeFixedRateContract
▸ removeFixedRateContract<G
>(address
, tokenAddress
, estimateGas?
): Promise
<ReceiptOrEstimate
<G
>>
Removes an address from the list of fixed rate contracts
Type parameters
Name | Type |
---|---|
G |
extends boolean = false |
Parameters
Name | Type | Description |
---|---|---|
address |
string |
caller address |
tokenAddress |
string |
contract address to add |
estimateGas? |
G |
if True, return gas estimate |
Returns
Promise
<ReceiptOrEstimate
<G
>>
Defined in
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
updateOPCFee
▸ updateOPCFee<G
>(address
, newSwapOceanFee
, newSwapNonOceanFee
, newConsumeFee
, newProviderFee
, estimateGas?
): Promise
<ReceiptOrEstimate
<G
>>
Updates OP Community Fees
Type parameters
Name | Type |
---|---|
G |
extends boolean = false |
Parameters
Name | Type | Description |
---|---|---|
address |
string |
caller address |
newSwapOceanFee |
number |
Amount charged for swapping with ocean approved tokens |
newSwapNonOceanFee |
number |
Amount charged for swapping with non ocean approved tokens |
newConsumeFee |
number |
Amount charged from consumeFees |
newProviderFee |
number |
Amount charged for providerFees |
estimateGas? |
G |
if True, return gas estimate |
Returns
Promise
<ReceiptOrEstimate
<G
>>