mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Merge b6cbd89406dac33eb3a63628a0f0a79868109edf into 87edac976fc49d7d2685f66b0c58f4b3bb6fc2df
This commit is contained in:
commit
153baef87f
@ -1,4 +1,4 @@
|
|||||||
import { DDO } from './DDO/DDO'
|
import { DDO } from '.'
|
||||||
|
|
||||||
export interface AssetNft {
|
export interface AssetNft {
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Metadata, MetadataAlgorithm } from './DDO/Metadata'
|
import { Metadata, MetadataAlgorithm } from '.'
|
||||||
|
|
||||||
export type ComputeResultType =
|
export type ComputeResultType =
|
||||||
| 'algorithmLog'
|
| 'algorithmLog'
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
import { Service } from './Service'
|
import { Service, Metadata, Credentials, Event } from '..'
|
||||||
import { Metadata } from './Metadata'
|
|
||||||
import { Credentials } from './Credentials'
|
|
||||||
import { Event } from './Event'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DID Descriptor Object.
|
* DID Descriptor Object.
|
||||||
|
@ -5,3 +5,13 @@ export interface DispenserCreationParams {
|
|||||||
withMint?: boolean // true if we want to allow the dispenser to be a minter
|
withMint?: boolean // true if we want to allow the dispenser to be a minter
|
||||||
allowedSwapper?: string // only account that can ask tokens. set address(0) if not required
|
allowedSwapper?: string // only account that can ask tokens. set address(0) if not required
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DispenserToken {
|
||||||
|
active: boolean
|
||||||
|
owner: string
|
||||||
|
maxTokens: string
|
||||||
|
maxBalance: string
|
||||||
|
balance: string
|
||||||
|
isMinter: boolean
|
||||||
|
allowedSwapper: string
|
||||||
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { ProviderFees } from '.'
|
||||||
|
|
||||||
export interface Erc20CreateParams {
|
export interface Erc20CreateParams {
|
||||||
templateIndex: number
|
templateIndex: number
|
||||||
minter: string
|
minter: string
|
||||||
@ -21,3 +23,22 @@ export interface PublishingMarketFee {
|
|||||||
publishMarketFeeToken: string
|
publishMarketFeeToken: string
|
||||||
publishMarketFeeAmount: string
|
publishMarketFeeAmount: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DatatokenRoles {
|
||||||
|
minter: boolean
|
||||||
|
paymentManager: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OrderParams {
|
||||||
|
consumer: string
|
||||||
|
serviceIndex: number
|
||||||
|
_providerFee: ProviderFees
|
||||||
|
_consumeMarketFee: ConsumeMarketFee
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DispenserParams {
|
||||||
|
maxTokens: string
|
||||||
|
maxBalance: string
|
||||||
|
withMint?: boolean // true if we want to allow the dispenser to be a minter
|
||||||
|
allowedSwapper?: string // only account that can ask tokens. set address(0) if not required
|
||||||
|
}
|
||||||
|
@ -11,3 +11,10 @@ export interface MetadataAndTokenURI {
|
|||||||
tokenURI: string
|
tokenURI: string
|
||||||
metadataProofs?: MetadataProof[]
|
metadataProofs?: MetadataProof[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface NftRoles {
|
||||||
|
manager: boolean
|
||||||
|
deployERC20: boolean
|
||||||
|
updateMetadata: boolean
|
||||||
|
store: boolean
|
||||||
|
}
|
||||||
|
@ -25,3 +25,29 @@ export interface PriceAndFees {
|
|||||||
marketFeeAmount: string
|
marketFeeAmount: string
|
||||||
consumeMarketFeeAmount: string
|
consumeMarketFeeAmount: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FixedPriceExchange {
|
||||||
|
active: boolean
|
||||||
|
exchangeOwner: string
|
||||||
|
datatoken: string
|
||||||
|
baseToken: string
|
||||||
|
fixedRate: string
|
||||||
|
dtDecimals: string
|
||||||
|
btDecimals: string
|
||||||
|
dtBalance: string
|
||||||
|
btBalance: string
|
||||||
|
dtSupply: string
|
||||||
|
btSupply: string
|
||||||
|
withMint: boolean
|
||||||
|
allowedSwapper: string
|
||||||
|
exchangeId?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FeesInfo {
|
||||||
|
opcFee: string
|
||||||
|
marketFee: string
|
||||||
|
marketFeeCollector: string
|
||||||
|
marketFeeAvailable: string
|
||||||
|
oceanFeeAvailable: string
|
||||||
|
exchangeId: string
|
||||||
|
}
|
||||||
|
23
src/@types/NFTFactory.ts
Normal file
23
src/@types/NFTFactory.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { ConsumeMarketFee, ProviderFees } from '.'
|
||||||
|
|
||||||
|
export interface Template {
|
||||||
|
templateAddress: string
|
||||||
|
isActive: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TokenOrder {
|
||||||
|
tokenAddress: string
|
||||||
|
consumer: string
|
||||||
|
serviceIndex: number
|
||||||
|
_providerFee: ProviderFees
|
||||||
|
_consumeMarketFee: ConsumeMarketFee
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NftCreateData {
|
||||||
|
name: string
|
||||||
|
symbol: string
|
||||||
|
templateIndex: number
|
||||||
|
tokenURI: string
|
||||||
|
transferable: boolean
|
||||||
|
owner: string
|
||||||
|
}
|
@ -26,3 +26,12 @@ export interface ProviderComputeInitializeResults {
|
|||||||
algorithm?: ProviderComputeInitialize
|
algorithm?: ProviderComputeInitialize
|
||||||
datasets?: ProviderComputeInitialize[]
|
datasets?: ProviderComputeInitialize[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ServiceEndpoint {
|
||||||
|
serviceName: string
|
||||||
|
method: string
|
||||||
|
urlPath: string
|
||||||
|
}
|
||||||
|
export interface UserCustomParameters {
|
||||||
|
[key: string]: any
|
||||||
|
}
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
export * from './DDO/DDO'
|
|
||||||
export * from './Asset'
|
|
||||||
export * from './DDO/Service'
|
|
||||||
export * from './DDO/Credentials'
|
export * from './DDO/Credentials'
|
||||||
|
export * from './DDO/DDO'
|
||||||
|
export * from './DDO/Event'
|
||||||
export * from './DDO/Metadata'
|
export * from './DDO/Metadata'
|
||||||
export * from './FileMetadata'
|
export * from './DDO/Service'
|
||||||
|
export * from './Asset'
|
||||||
export * from './Compute'
|
export * from './Compute'
|
||||||
export * from './Provider'
|
export * from './Dispenser'
|
||||||
export * from './FixedPrice'
|
export * from './DownloadResponse'
|
||||||
export * from './Pool'
|
|
||||||
export * from './Erc20'
|
export * from './Erc20'
|
||||||
export * from './Erc721'
|
export * from './Erc721'
|
||||||
export * from './Dispenser'
|
export * from './FileMetadata'
|
||||||
|
export * from './FixedPrice'
|
||||||
|
export * from './NFTFactory'
|
||||||
|
export * from './Pool'
|
||||||
|
export * from './Provider'
|
||||||
export * from './Router'
|
export * from './Router'
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { LogLevel } from '../utils/Logger'
|
|
||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
|
import { LogLevel } from '../utils'
|
||||||
|
|
||||||
export class Config {
|
export class Config {
|
||||||
/**
|
/**
|
||||||
@ -195,5 +195,3 @@ export class Config {
|
|||||||
*/
|
*/
|
||||||
gasFeeMultiplier: number
|
gasFeeMultiplier: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Config
|
|
@ -1,7 +1,7 @@
|
|||||||
import Config from '../models/Config'
|
|
||||||
// eslint-disable-next-line import/no-named-default
|
// eslint-disable-next-line import/no-named-default
|
||||||
import { default as DefaultContractsAddresses } from '@oceanprotocol/contracts/addresses/address.json'
|
import { default as DefaultContractsAddresses } from '@oceanprotocol/contracts/addresses/address.json'
|
||||||
import LoggerInstance from './Logger'
|
import { Config } from '.'
|
||||||
|
import { LoggerInstance } from '../utils'
|
||||||
|
|
||||||
const configHelperNetworksBase: Config = {
|
const configHelperNetworksBase: Config = {
|
||||||
chainId: null,
|
chainId: null,
|
2
src/config/index.ts
Normal file
2
src/config/index.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export * from './Config'
|
||||||
|
export * from './ConfigHelper'
|
46
src/contracts/SmartContract.ts
Normal file
46
src/contracts/SmartContract.ts
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import Web3 from 'web3'
|
||||||
|
import { AbiItem } from 'web3-utils'
|
||||||
|
import { Config, ConfigHelper } from '../config'
|
||||||
|
import { amountToUnits, unitsToAmount } from '../utils'
|
||||||
|
|
||||||
|
export abstract class SmartContract {
|
||||||
|
public web3: Web3
|
||||||
|
public config: Config
|
||||||
|
public abi: AbiItem | AbiItem[]
|
||||||
|
|
||||||
|
abstract getDefaultAbi(): AbiItem | AbiItem[]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate the smart contract.
|
||||||
|
* @param {Web3} web3
|
||||||
|
* @param {string | number} network Network id or name
|
||||||
|
* @param {Config} config Configutation of the smart contract
|
||||||
|
* @param {AbiItem | AbiItem[]} abi ABI of the smart contract
|
||||||
|
*/
|
||||||
|
constructor(
|
||||||
|
web3: Web3,
|
||||||
|
network?: string | number,
|
||||||
|
config?: Config,
|
||||||
|
abi?: AbiItem | AbiItem[]
|
||||||
|
) {
|
||||||
|
this.web3 = web3
|
||||||
|
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
|
||||||
|
this.abi = abi || (this.getDefaultAbi() as AbiItem[])
|
||||||
|
}
|
||||||
|
|
||||||
|
async amountToUnits(
|
||||||
|
token: string,
|
||||||
|
amount: string,
|
||||||
|
tokenDecimals?: number
|
||||||
|
): Promise<string> {
|
||||||
|
return amountToUnits(this.web3, token, amount, tokenDecimals)
|
||||||
|
}
|
||||||
|
|
||||||
|
async unitsToAmount(
|
||||||
|
token: string,
|
||||||
|
amount: string,
|
||||||
|
tokenDecimals?: number
|
||||||
|
): Promise<string> {
|
||||||
|
return unitsToAmount(this.web3, token, amount, tokenDecimals)
|
||||||
|
}
|
||||||
|
}
|
34
src/contracts/SmartContractWithAddress.ts
Normal file
34
src/contracts/SmartContractWithAddress.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import Web3 from 'web3'
|
||||||
|
import { Contract } from 'web3-eth-contract'
|
||||||
|
import { AbiItem } from 'web3-utils'
|
||||||
|
import { Config } from '../config'
|
||||||
|
import { setContractDefaults } from '../utils'
|
||||||
|
import { SmartContract } from '.'
|
||||||
|
|
||||||
|
export abstract class SmartContractWithAddress extends SmartContract {
|
||||||
|
public address: string
|
||||||
|
public contract: Contract
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate the smart contract.
|
||||||
|
* @param {string} address Address of the smart contract
|
||||||
|
* @param {Web3} web3
|
||||||
|
* @param {string | number} network Network id or name
|
||||||
|
* @param {Config} config Configutation of the smart contract
|
||||||
|
* @param {AbiItem | AbiItem[]} abi ABI of the smart contract
|
||||||
|
*/
|
||||||
|
constructor(
|
||||||
|
address: string,
|
||||||
|
web3: Web3,
|
||||||
|
network?: string | number,
|
||||||
|
config?: Config,
|
||||||
|
abi?: AbiItem | AbiItem[]
|
||||||
|
) {
|
||||||
|
super(web3, network, config, abi)
|
||||||
|
this.address = address
|
||||||
|
this.contract = setContractDefaults(
|
||||||
|
new this.web3.eth.Contract(this.getDefaultAbi(), this.address),
|
||||||
|
this.config
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,7 @@
|
|||||||
import { Contract } from 'web3-eth-contract'
|
|
||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
import { AbiItem } from 'web3-utils'
|
import { AbiItem } from 'web3-utils'
|
||||||
import defaultFactory721Abi from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
|
import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
|
||||||
import {
|
import {
|
||||||
LoggerInstance,
|
LoggerInstance,
|
||||||
getFairGasPrice,
|
getFairGasPrice,
|
||||||
@ -10,74 +9,26 @@ import {
|
|||||||
getFreCreationParams,
|
getFreCreationParams,
|
||||||
getErcCreationParams,
|
getErcCreationParams,
|
||||||
getPoolCreationParams,
|
getPoolCreationParams,
|
||||||
setContractDefaults,
|
|
||||||
estimateGas,
|
estimateGas,
|
||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS
|
||||||
ConfigHelper
|
} from '../../utils'
|
||||||
} from '../utils'
|
|
||||||
import { Config } from '../models/index.js'
|
|
||||||
import {
|
import {
|
||||||
ProviderFees,
|
|
||||||
FreCreationParams,
|
FreCreationParams,
|
||||||
Erc20CreateParams,
|
Erc20CreateParams,
|
||||||
PoolCreationParams,
|
PoolCreationParams,
|
||||||
DispenserCreationParams,
|
DispenserCreationParams,
|
||||||
ConsumeMarketFee
|
NftCreateData,
|
||||||
} from '../@types/index.js'
|
Template,
|
||||||
|
TokenOrder
|
||||||
interface Template {
|
} from '../../@types'
|
||||||
templateAddress: string
|
import { SmartContractWithAddress } from '..'
|
||||||
isActive: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface TokenOrder {
|
|
||||||
tokenAddress: string
|
|
||||||
consumer: string
|
|
||||||
serviceIndex: number
|
|
||||||
_providerFee: ProviderFees
|
|
||||||
_consumeMarketFee: ConsumeMarketFee
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NftCreateData {
|
|
||||||
name: string
|
|
||||||
symbol: string
|
|
||||||
templateIndex: number
|
|
||||||
tokenURI: string
|
|
||||||
transferable: boolean
|
|
||||||
owner: string
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides an interface for NFT Factory contract
|
* Provides an interface for NFT Factory contract
|
||||||
*/
|
*/
|
||||||
export class NftFactory {
|
export class NftFactory extends SmartContractWithAddress {
|
||||||
public factory721Address: string
|
getDefaultAbi(): AbiItem | AbiItem[] {
|
||||||
public factory721Abi: AbiItem | AbiItem[]
|
return ERC721Factory.abi as AbiItem[]
|
||||||
public web3: Web3
|
|
||||||
public config: Config
|
|
||||||
public factory721: Contract
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiate Datatokens.
|
|
||||||
* @param {String} factory721Address
|
|
||||||
* @param {AbiItem | AbiItem[]} factory721ABI
|
|
||||||
* @param {Web3} web3
|
|
||||||
*/
|
|
||||||
constructor(
|
|
||||||
factory721Address: string,
|
|
||||||
web3: Web3,
|
|
||||||
network?: string | number,
|
|
||||||
factory721Abi?: AbiItem | AbiItem[],
|
|
||||||
config?: Config
|
|
||||||
) {
|
|
||||||
this.factory721Address = factory721Address
|
|
||||||
this.factory721Abi = factory721Abi || (defaultFactory721Abi.abi as AbiItem[])
|
|
||||||
this.web3 = web3
|
|
||||||
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
|
|
||||||
this.factory721 = setContractDefaults(
|
|
||||||
new this.web3.eth.Contract(this.factory721Abi, this.factory721Address),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,7 +40,7 @@ export class NftFactory {
|
|||||||
public async estGasCreateNFT(address: string, nftData: NftCreateData): Promise<string> {
|
public async estGasCreateNFT(address: string, nftData: NftCreateData): Promise<string> {
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.deployERC721Contract,
|
this.contract.methods.deployERC721Contract,
|
||||||
nftData.name,
|
nftData.name,
|
||||||
nftData.symbol,
|
nftData.symbol,
|
||||||
nftData.templateIndex,
|
nftData.templateIndex,
|
||||||
@ -127,7 +78,7 @@ export class NftFactory {
|
|||||||
}
|
}
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.deployERC721Contract,
|
this.contract.methods.deployERC721Contract,
|
||||||
nftData.name,
|
nftData.name,
|
||||||
nftData.symbol,
|
nftData.symbol,
|
||||||
nftData.templateIndex,
|
nftData.templateIndex,
|
||||||
@ -139,7 +90,7 @@ export class NftFactory {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.deployERC721Contract(
|
.deployERC721Contract(
|
||||||
nftData.name,
|
nftData.name,
|
||||||
nftData.symbol,
|
nftData.symbol,
|
||||||
@ -169,7 +120,7 @@ export class NftFactory {
|
|||||||
* @return {Promise<number>} Number of NFT created from this factory
|
* @return {Promise<number>} Number of NFT created from this factory
|
||||||
*/
|
*/
|
||||||
public async getCurrentNFTCount(): Promise<number> {
|
public async getCurrentNFTCount(): Promise<number> {
|
||||||
const trxReceipt = await this.factory721.methods.getCurrentNFTCount().call()
|
const trxReceipt = await this.contract.methods.getCurrentNFTCount().call()
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +128,7 @@ export class NftFactory {
|
|||||||
* @return {Promise<number>} Number of DTs created from this factory
|
* @return {Promise<number>} Number of DTs created from this factory
|
||||||
*/
|
*/
|
||||||
public async getCurrentTokenCount(): Promise<number> {
|
public async getCurrentTokenCount(): Promise<number> {
|
||||||
const trxReceipt = await this.factory721.methods.getCurrentTokenCount().call()
|
const trxReceipt = await this.contract.methods.getCurrentTokenCount().call()
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +136,7 @@ export class NftFactory {
|
|||||||
* @return {Promise<string>} Factory Owner address
|
* @return {Promise<string>} Factory Owner address
|
||||||
*/
|
*/
|
||||||
public async getOwner(): Promise<string> {
|
public async getOwner(): Promise<string> {
|
||||||
const trxReceipt = await this.factory721.methods.owner().call()
|
const trxReceipt = await this.contract.methods.owner().call()
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,7 +144,7 @@ export class NftFactory {
|
|||||||
* @return {Promise<number>} Number of NFT Template added to this factory
|
* @return {Promise<number>} Number of NFT Template added to this factory
|
||||||
*/
|
*/
|
||||||
public async getCurrentNFTTemplateCount(): Promise<number> {
|
public async getCurrentNFTTemplateCount(): Promise<number> {
|
||||||
const count = await this.factory721.methods.getCurrentNFTTemplateCount().call()
|
const count = await this.contract.methods.getCurrentNFTTemplateCount().call()
|
||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,7 +152,7 @@ export class NftFactory {
|
|||||||
* @return {Promise<number>} Number of ERC20 Template added to this factory
|
* @return {Promise<number>} Number of ERC20 Template added to this factory
|
||||||
*/
|
*/
|
||||||
public async getCurrentTokenTemplateCount(): Promise<number> {
|
public async getCurrentTokenTemplateCount(): Promise<number> {
|
||||||
const count = await this.factory721.methods.getCurrentTemplateCount().call()
|
const count = await this.contract.methods.getCurrentTemplateCount().call()
|
||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +168,7 @@ export class NftFactory {
|
|||||||
if (index === 0) {
|
if (index === 0) {
|
||||||
throw new Error(`Template index cannot be ZERO`)
|
throw new Error(`Template index cannot be ZERO`)
|
||||||
}
|
}
|
||||||
const template = await this.factory721.methods.getNFTTemplate(index).call()
|
const template = await this.contract.methods.getNFTTemplate(index).call()
|
||||||
return template
|
return template
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +177,7 @@ export class NftFactory {
|
|||||||
* @return {Promise<Template>} DT Template info
|
* @return {Promise<Template>} DT Template info
|
||||||
*/
|
*/
|
||||||
public async getTokenTemplate(index: number): Promise<Template> {
|
public async getTokenTemplate(index: number): Promise<Template> {
|
||||||
const template = await this.factory721.methods.getTokenTemplate(index).call()
|
const template = await this.contract.methods.getTokenTemplate(index).call()
|
||||||
return template
|
return template
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +186,7 @@ export class NftFactory {
|
|||||||
* @return {Promise<Boolean>} return true if deployed from this factory
|
* @return {Promise<Boolean>} return true if deployed from this factory
|
||||||
*/
|
*/
|
||||||
public async checkDatatoken(datatoken: string): Promise<Boolean> {
|
public async checkDatatoken(datatoken: string): Promise<Boolean> {
|
||||||
const isDeployed = await this.factory721.methods.erc20List(datatoken).call()
|
const isDeployed = await this.contract.methods.erc20List(datatoken).call()
|
||||||
return isDeployed
|
return isDeployed
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +195,7 @@ export class NftFactory {
|
|||||||
* @return {Promise<String>} return address(0) if it's not, or the nftAddress if true
|
* @return {Promise<String>} return address(0) if it's not, or the nftAddress if true
|
||||||
*/
|
*/
|
||||||
public async checkNFT(nftAddress: string): Promise<String> {
|
public async checkNFT(nftAddress: string): Promise<String> {
|
||||||
const confirmAddress = await this.factory721.methods.erc721List(nftAddress).call()
|
const confirmAddress = await this.contract.methods.erc721List(nftAddress).call()
|
||||||
return confirmAddress
|
return confirmAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,7 +211,7 @@ export class NftFactory {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.add721TokenTemplate,
|
this.contract.methods.add721TokenTemplate,
|
||||||
templateAddress
|
templateAddress
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -284,12 +235,12 @@ export class NftFactory {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.add721TokenTemplate,
|
this.contract.methods.add721TokenTemplate,
|
||||||
templateAddress
|
templateAddress
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke add721TokenTemplate function of the contract
|
// Invoke add721TokenTemplate function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.add721TokenTemplate(templateAddress)
|
.add721TokenTemplate(templateAddress)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -312,7 +263,7 @@ export class NftFactory {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.disable721TokenTemplate,
|
this.contract.methods.disable721TokenTemplate,
|
||||||
templateIndex
|
templateIndex
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -339,12 +290,12 @@ export class NftFactory {
|
|||||||
}
|
}
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.disable721TokenTemplate,
|
this.contract.methods.disable721TokenTemplate,
|
||||||
templateIndex
|
templateIndex
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.disable721TokenTemplate(templateIndex)
|
.disable721TokenTemplate(templateIndex)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -367,7 +318,7 @@ export class NftFactory {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.reactivate721TokenTemplate,
|
this.contract.methods.reactivate721TokenTemplate,
|
||||||
templateIndex
|
templateIndex
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -395,12 +346,12 @@ export class NftFactory {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.reactivate721TokenTemplate,
|
this.contract.methods.reactivate721TokenTemplate,
|
||||||
templateIndex
|
templateIndex
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.reactivate721TokenTemplate(templateIndex)
|
.reactivate721TokenTemplate(templateIndex)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -421,7 +372,7 @@ export class NftFactory {
|
|||||||
address: string,
|
address: string,
|
||||||
templateAddress: string
|
templateAddress: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(address, this.factory721.methods.addTokenTemplate, templateAddress)
|
return estimateGas(address, this.contract.methods.addTokenTemplate, templateAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -443,12 +394,12 @@ export class NftFactory {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.addTokenTemplate,
|
this.contract.methods.addTokenTemplate,
|
||||||
templateAddress
|
templateAddress
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.addTokenTemplate(templateAddress)
|
.addTokenTemplate(templateAddress)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -469,11 +420,7 @@ export class NftFactory {
|
|||||||
address: string,
|
address: string,
|
||||||
templateIndex: number
|
templateIndex: number
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(
|
return estimateGas(address, this.contract.methods.disableTokenTemplate, templateIndex)
|
||||||
address,
|
|
||||||
this.factory721.methods.disableTokenTemplate,
|
|
||||||
templateIndex
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -501,12 +448,12 @@ export class NftFactory {
|
|||||||
}
|
}
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.disableTokenTemplate,
|
this.contract.methods.disableTokenTemplate,
|
||||||
templateIndex
|
templateIndex
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.disableTokenTemplate(templateIndex)
|
.disableTokenTemplate(templateIndex)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -529,7 +476,7 @@ export class NftFactory {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.reactivateTokenTemplate,
|
this.contract.methods.reactivateTokenTemplate,
|
||||||
templateIndex
|
templateIndex
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -560,12 +507,12 @@ export class NftFactory {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.reactivateTokenTemplate,
|
this.contract.methods.reactivateTokenTemplate,
|
||||||
templateIndex
|
templateIndex
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.reactivateTokenTemplate(templateIndex)
|
.reactivateTokenTemplate(templateIndex)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -585,7 +532,7 @@ export class NftFactory {
|
|||||||
address: string,
|
address: string,
|
||||||
orders: TokenOrder[]
|
orders: TokenOrder[]
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(address, this.factory721.methods.startMultipleTokenOrder, orders)
|
return estimateGas(address, this.contract.methods.startMultipleTokenOrder, orders)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -610,14 +557,12 @@ export class NftFactory {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.startMultipleTokenOrder,
|
this.contract.methods.startMultipleTokenOrder,
|
||||||
orders
|
orders
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.contract.methods.startMultipleTokenOrder(orders).send({
|
||||||
.startMultipleTokenOrder(orders)
|
|
||||||
.send({
|
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
@ -642,7 +587,7 @@ export class NftFactory {
|
|||||||
const ercCreateData = getErcCreationParams(ercParams)
|
const ercCreateData = getErcCreationParams(ercParams)
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.createNftWithErc20,
|
this.contract.methods.createNftWithErc20,
|
||||||
nftCreateData,
|
nftCreateData,
|
||||||
ercCreateData
|
ercCreateData
|
||||||
)
|
)
|
||||||
@ -666,13 +611,13 @@ export class NftFactory {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.createNftWithErc20,
|
this.contract.methods.createNftWithErc20,
|
||||||
nftCreateData,
|
nftCreateData,
|
||||||
ercCreateData
|
ercCreateData
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.createNftWithErc20(nftCreateData, ercCreateData)
|
.createNftWithErc20(nftCreateData, ercCreateData)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -701,7 +646,7 @@ export class NftFactory {
|
|||||||
const poolData = await getPoolCreationParams(this.web3, poolParams)
|
const poolData = await getPoolCreationParams(this.web3, poolParams)
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.createNftWithErc20WithPool,
|
this.contract.methods.createNftWithErc20WithPool,
|
||||||
nftCreateData,
|
nftCreateData,
|
||||||
ercCreateData,
|
ercCreateData,
|
||||||
poolData
|
poolData
|
||||||
@ -729,14 +674,14 @@ export class NftFactory {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.createNftWithErc20WithPool,
|
this.contract.methods.createNftWithErc20WithPool,
|
||||||
nftCreateData,
|
nftCreateData,
|
||||||
ercCreateData,
|
ercCreateData,
|
||||||
poolData
|
poolData
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.createNftWithErc20WithPool(nftCreateData, ercCreateData, poolData)
|
.createNftWithErc20WithPool(nftCreateData, ercCreateData, poolData)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -764,7 +709,7 @@ export class NftFactory {
|
|||||||
const fixedData = await getFreCreationParams(freParams)
|
const fixedData = await getFreCreationParams(freParams)
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.createNftWithErc20WithFixedRate,
|
this.contract.methods.createNftWithErc20WithFixedRate,
|
||||||
nftCreateData,
|
nftCreateData,
|
||||||
ercCreateData,
|
ercCreateData,
|
||||||
fixedData
|
fixedData
|
||||||
@ -792,14 +737,14 @@ export class NftFactory {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.createNftWithErc20WithFixedRate,
|
this.contract.methods.createNftWithErc20WithFixedRate,
|
||||||
nftCreateData,
|
nftCreateData,
|
||||||
ercCreateData,
|
ercCreateData,
|
||||||
fixedData
|
fixedData
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.createNftWithErc20WithFixedRate(nftCreateData, ercCreateData, fixedData)
|
.createNftWithErc20WithFixedRate(nftCreateData, ercCreateData, fixedData)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -826,7 +771,7 @@ export class NftFactory {
|
|||||||
const ercCreateData = getErcCreationParams(ercParams)
|
const ercCreateData = getErcCreationParams(ercParams)
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.createNftWithErc20WithDispenser,
|
this.contract.methods.createNftWithErc20WithDispenser,
|
||||||
nftCreateData,
|
nftCreateData,
|
||||||
ercCreateData,
|
ercCreateData,
|
||||||
dispenserParams
|
dispenserParams
|
||||||
@ -856,14 +801,14 @@ export class NftFactory {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.factory721.methods.createNftWithErc20WithDispenser,
|
this.contract.methods.createNftWithErc20WithDispenser,
|
||||||
nftCreateData,
|
nftCreateData,
|
||||||
ercCreateData,
|
ercCreateData,
|
||||||
dispenserParams
|
dispenserParams
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.createNftWithErc20WithDispenser(nftCreateData, ercCreateData, dispenserParams)
|
.createNftWithErc20WithDispenser(nftCreateData, ercCreateData, dispenserParams)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
10
src/contracts/index.ts
Normal file
10
src/contracts/index.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
export * from './SmartContract'
|
||||||
|
export * from './SmartContractWithAddress'
|
||||||
|
export * from './factories/NFTFactory'
|
||||||
|
export * from './pools/Dispenser'
|
||||||
|
export * from './pools/FixedRateExchange'
|
||||||
|
export * from './pools/Pool'
|
||||||
|
export * from './pools/Router'
|
||||||
|
export * from './pools/SideStaking'
|
||||||
|
export * from './tokens/Datatoken'
|
||||||
|
export * from './tokens/NFT'
|
@ -1,58 +1,14 @@
|
|||||||
import Web3 from 'web3'
|
|
||||||
import { AbiItem } from 'web3-utils'
|
import { AbiItem } from 'web3-utils'
|
||||||
import { Contract } from 'web3-eth-contract'
|
|
||||||
import { TransactionReceipt } from 'web3-eth'
|
import { TransactionReceipt } from 'web3-eth'
|
||||||
import Decimal from 'decimal.js'
|
import Decimal from 'decimal.js'
|
||||||
import defaultDispenserAbi from '@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json'
|
import DispenserAbi from '@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json'
|
||||||
import {
|
import { LoggerInstance, getFairGasPrice, estimateGas } from '../../utils/'
|
||||||
LoggerInstance as logger,
|
import { Datatoken, SmartContractWithAddress } from '..'
|
||||||
getFairGasPrice,
|
import { DispenserToken } from '../../@types'
|
||||||
setContractDefaults,
|
|
||||||
estimateGas,
|
|
||||||
ConfigHelper
|
|
||||||
} from '../../utils/'
|
|
||||||
import { Datatoken } from '../../tokens'
|
|
||||||
import { Config } from '../../models/index.js'
|
|
||||||
|
|
||||||
export interface DispenserToken {
|
export class Dispenser extends SmartContractWithAddress {
|
||||||
active: boolean
|
getDefaultAbi(): AbiItem | AbiItem[] {
|
||||||
owner: string
|
return DispenserAbi.abi as AbiItem[]
|
||||||
maxTokens: string
|
|
||||||
maxBalance: string
|
|
||||||
balance: string
|
|
||||||
isMinter: boolean
|
|
||||||
allowedSwapper: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Dispenser {
|
|
||||||
public web3: Web3 = null
|
|
||||||
public dispenserAddress: string
|
|
||||||
public config: Config
|
|
||||||
public dispenserAbi: AbiItem | AbiItem[]
|
|
||||||
public dispenserContract: Contract
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiate Dispenser
|
|
||||||
* @param {any} web3
|
|
||||||
* @param {String} dispenserAddress
|
|
||||||
* @param {any} dispenserABI
|
|
||||||
*/
|
|
||||||
constructor(
|
|
||||||
web3: Web3,
|
|
||||||
network?: string | number,
|
|
||||||
dispenserAddress: string = null,
|
|
||||||
dispenserAbi: AbiItem | AbiItem[] = null,
|
|
||||||
config?: Config
|
|
||||||
) {
|
|
||||||
this.web3 = web3
|
|
||||||
this.dispenserAddress = dispenserAddress
|
|
||||||
this.dispenserAbi = dispenserAbi || (defaultDispenserAbi.abi as AbiItem[])
|
|
||||||
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
|
|
||||||
if (web3)
|
|
||||||
this.dispenserContract = setContractDefaults(
|
|
||||||
new this.web3.eth.Contract(this.dispenserAbi, this.dispenserAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,15 +18,13 @@ export class Dispenser {
|
|||||||
*/
|
*/
|
||||||
public async status(dtAdress: string): Promise<DispenserToken> {
|
public async status(dtAdress: string): Promise<DispenserToken> {
|
||||||
try {
|
try {
|
||||||
const result: DispenserToken = await this.dispenserContract.methods
|
const result: DispenserToken = await this.contract.methods.status(dtAdress).call()
|
||||||
.status(dtAdress)
|
|
||||||
.call()
|
|
||||||
result.maxTokens = this.web3.utils.fromWei(result.maxTokens)
|
result.maxTokens = this.web3.utils.fromWei(result.maxTokens)
|
||||||
result.maxBalance = this.web3.utils.fromWei(result.maxBalance)
|
result.maxBalance = this.web3.utils.fromWei(result.maxBalance)
|
||||||
result.balance = this.web3.utils.fromWei(result.balance)
|
result.balance = this.web3.utils.fromWei(result.balance)
|
||||||
return result
|
return result
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.warn(`No dispenser available for datatoken: ${dtAdress}`)
|
LoggerInstance.warn(`No dispenser available for datatoken: ${dtAdress}`)
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@ -93,7 +47,7 @@ export class Dispenser {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
this.dispenserContract.methods.create,
|
this.contract.methods.create,
|
||||||
dtAddress,
|
dtAddress,
|
||||||
this.web3.utils.toWei(maxTokens),
|
this.web3.utils.toWei(maxTokens),
|
||||||
this.web3.utils.toWei(maxBalance),
|
this.web3.utils.toWei(maxBalance),
|
||||||
@ -120,7 +74,7 @@ export class Dispenser {
|
|||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.dispenserContract.methods.create,
|
this.contract.methods.create,
|
||||||
dtAddress,
|
dtAddress,
|
||||||
this.web3.utils.toWei(maxTokens),
|
this.web3.utils.toWei(maxTokens),
|
||||||
this.web3.utils.toWei(maxBalance),
|
this.web3.utils.toWei(maxBalance),
|
||||||
@ -129,7 +83,7 @@ export class Dispenser {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Call createFixedRate contract method
|
// Call createFixedRate contract method
|
||||||
const trxReceipt = await this.dispenserContract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.create(
|
.create(
|
||||||
dtAddress,
|
dtAddress,
|
||||||
this.web3.utils.toWei(maxTokens),
|
this.web3.utils.toWei(maxTokens),
|
||||||
@ -161,7 +115,7 @@ export class Dispenser {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
this.dispenserContract.methods.activate,
|
this.contract.methods.activate,
|
||||||
dtAddress,
|
dtAddress,
|
||||||
this.web3.utils.toWei(maxTokens),
|
this.web3.utils.toWei(maxTokens),
|
||||||
this.web3.utils.toWei(maxBalance)
|
this.web3.utils.toWei(maxBalance)
|
||||||
@ -185,13 +139,13 @@ export class Dispenser {
|
|||||||
try {
|
try {
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.dispenserContract.methods.activate,
|
this.contract.methods.activate,
|
||||||
dtAddress,
|
dtAddress,
|
||||||
this.web3.utils.toWei(maxTokens),
|
this.web3.utils.toWei(maxTokens),
|
||||||
this.web3.utils.toWei(maxBalance)
|
this.web3.utils.toWei(maxBalance)
|
||||||
)
|
)
|
||||||
|
|
||||||
const trxReceipt = await this.dispenserContract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.activate(
|
.activate(
|
||||||
dtAddress,
|
dtAddress,
|
||||||
this.web3.utils.toWei(maxTokens),
|
this.web3.utils.toWei(maxTokens),
|
||||||
@ -204,7 +158,7 @@ export class Dispenser {
|
|||||||
})
|
})
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error(`ERROR: Failed to activate dispenser: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to activate dispenser: ${e.message}`)
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@ -216,7 +170,7 @@ export class Dispenser {
|
|||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
public async estGasDeactivate(dtAddress: string, address: string): Promise<any> {
|
public async estGasDeactivate(dtAddress: string, address: string): Promise<any> {
|
||||||
return estimateGas(address, this.dispenserContract.methods.deactivate, dtAddress)
|
return estimateGas(address, this.contract.methods.deactivate, dtAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -232,18 +186,18 @@ export class Dispenser {
|
|||||||
try {
|
try {
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.dispenserContract.methods.deactivate,
|
this.contract.methods.deactivate,
|
||||||
dtAddress
|
dtAddress
|
||||||
)
|
)
|
||||||
|
|
||||||
const trxReceipt = await this.dispenserContract.methods.deactivate(dtAddress).send({
|
const trxReceipt = await this.contract.methods.deactivate(dtAddress).send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
})
|
})
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error(`ERROR: Failed to activate dispenser: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to activate dispenser: ${e.message}`)
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@ -262,7 +216,7 @@ export class Dispenser {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
this.dispenserContract.methods.setAllowedSwapper,
|
this.contract.methods.setAllowedSwapper,
|
||||||
dtAddress,
|
dtAddress,
|
||||||
newAllowedSwapper
|
newAllowedSwapper
|
||||||
)
|
)
|
||||||
@ -283,12 +237,12 @@ export class Dispenser {
|
|||||||
try {
|
try {
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.dispenserContract.methods.setAllowedSwapper,
|
this.contract.methods.setAllowedSwapper,
|
||||||
dtAddress,
|
dtAddress,
|
||||||
newAllowedSwapper
|
newAllowedSwapper
|
||||||
)
|
)
|
||||||
|
|
||||||
const trxReceipt = await this.dispenserContract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.setAllowedSwapper(dtAddress, newAllowedSwapper)
|
.setAllowedSwapper(dtAddress, newAllowedSwapper)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -297,7 +251,7 @@ export class Dispenser {
|
|||||||
})
|
})
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error(`ERROR: Failed to activate dispenser: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to activate dispenser: ${e.message}`)
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@ -317,7 +271,7 @@ export class Dispenser {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
this.dispenserContract.methods.dispense,
|
this.contract.methods.dispense,
|
||||||
dtAddress,
|
dtAddress,
|
||||||
this.web3.utils.toWei(amount),
|
this.web3.utils.toWei(amount),
|
||||||
destination
|
destination
|
||||||
@ -342,14 +296,14 @@ export class Dispenser {
|
|||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.dispenserContract.methods.dispense,
|
this.contract.methods.dispense,
|
||||||
dtAddress,
|
dtAddress,
|
||||||
this.web3.utils.toWei(amount),
|
this.web3.utils.toWei(amount),
|
||||||
destination
|
destination
|
||||||
)
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const trxReceipt = await this.dispenserContract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.dispense(dtAddress, this.web3.utils.toWei(amount), destination)
|
.dispense(dtAddress, this.web3.utils.toWei(amount), destination)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -358,7 +312,7 @@ export class Dispenser {
|
|||||||
})
|
})
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error(`ERROR: Failed to dispense tokens: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to dispense tokens: ${e.message}`)
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@ -371,7 +325,7 @@ export class Dispenser {
|
|||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
public async estGasOwnerWithdraw(dtAddress: string, address: string): Promise<any> {
|
public async estGasOwnerWithdraw(dtAddress: string, address: string): Promise<any> {
|
||||||
return estimateGas(address, this.dispenserContract.methods.ownerWithdraw, dtAddress)
|
return estimateGas(address, this.contract.methods.ownerWithdraw, dtAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -386,21 +340,19 @@ export class Dispenser {
|
|||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.dispenserContract.methods.ownerWithdraw,
|
this.contract.methods.ownerWithdraw,
|
||||||
dtAddress
|
dtAddress
|
||||||
)
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const trxReceipt = await this.dispenserContract.methods
|
const trxReceipt = await this.contract.methods.ownerWithdraw(dtAddress).send({
|
||||||
.ownerWithdraw(dtAddress)
|
|
||||||
.send({
|
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
})
|
})
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error(`ERROR: Failed to withdraw tokens: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to withdraw tokens: ${e.message}`)
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
@ -1,110 +1,14 @@
|
|||||||
import defaultFixedRateExchangeAbi from '@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json'
|
import FixedRateExchangeAbi from '@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json'
|
||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
import Web3 from 'web3'
|
import { LoggerInstance, getFairGasPrice, estimateGas, ZERO_ADDRESS } from '../../utils'
|
||||||
import {
|
import { PriceAndFees, FeesInfo, FixedPriceExchange } from '../../@types'
|
||||||
LoggerInstance,
|
import { SmartContractWithAddress } from '..'
|
||||||
getFairGasPrice,
|
|
||||||
setContractDefaults,
|
|
||||||
amountToUnits,
|
|
||||||
unitsToAmount,
|
|
||||||
estimateGas,
|
|
||||||
ZERO_ADDRESS,
|
|
||||||
ConfigHelper
|
|
||||||
} from '../../utils'
|
|
||||||
import { Config } from '../../models/index.js'
|
|
||||||
import { PriceAndFees } from '../..'
|
|
||||||
|
|
||||||
export interface FixedPriceExchange {
|
export class FixedRateExchange extends SmartContractWithAddress {
|
||||||
active: boolean
|
getDefaultAbi(): AbiItem | AbiItem[] {
|
||||||
exchangeOwner: string
|
return FixedRateExchangeAbi.abi as AbiItem[]
|
||||||
datatoken: string
|
|
||||||
baseToken: string
|
|
||||||
fixedRate: string
|
|
||||||
dtDecimals: string
|
|
||||||
btDecimals: string
|
|
||||||
dtBalance: string
|
|
||||||
btBalance: string
|
|
||||||
dtSupply: string
|
|
||||||
btSupply: string
|
|
||||||
withMint: boolean
|
|
||||||
allowedSwapper: string
|
|
||||||
exchangeId?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FeesInfo {
|
|
||||||
opcFee: string
|
|
||||||
marketFee: string
|
|
||||||
marketFeeCollector: string
|
|
||||||
marketFeeAvailable: string
|
|
||||||
oceanFeeAvailable: string
|
|
||||||
exchangeId: string
|
|
||||||
}
|
|
||||||
export interface FixedPriceSwap {
|
|
||||||
exchangeId: string
|
|
||||||
caller: string
|
|
||||||
baseTokenAmount: string
|
|
||||||
datatokenAmount: string
|
|
||||||
}
|
|
||||||
|
|
||||||
/* eslint-disable no-unused-vars */
|
|
||||||
export enum FixedRateCreateProgressStep {
|
|
||||||
CreatingExchange,
|
|
||||||
ApprovingDatatoken
|
|
||||||
}
|
|
||||||
/* eslint-enable no-unused-vars */
|
|
||||||
|
|
||||||
export class FixedRateExchange {
|
|
||||||
/** Ocean related functions */
|
|
||||||
public oceanAddress: string = null
|
|
||||||
public fixedRateAddress: string
|
|
||||||
public fixedRateExchangeAbi: AbiItem | AbiItem[]
|
|
||||||
public web3: Web3
|
|
||||||
public fixedRateContract: Contract = null
|
|
||||||
|
|
||||||
public config: Config
|
|
||||||
public ssAbi: AbiItem | AbiItem[]
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiate FixedRateExchange
|
|
||||||
* @param {any} web3
|
|
||||||
* @param {any} fixedRateExchangeAbi
|
|
||||||
*/
|
|
||||||
constructor(
|
|
||||||
web3: Web3,
|
|
||||||
fixedRateAddress: string,
|
|
||||||
network?: string | number,
|
|
||||||
fixedRateExchangeAbi: AbiItem | AbiItem[] = null,
|
|
||||||
oceanAddress: string = null,
|
|
||||||
config?: Config
|
|
||||||
) {
|
|
||||||
this.web3 = web3
|
|
||||||
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
|
|
||||||
this.fixedRateExchangeAbi =
|
|
||||||
fixedRateExchangeAbi || (defaultFixedRateExchangeAbi.abi as AbiItem[])
|
|
||||||
this.oceanAddress = oceanAddress
|
|
||||||
this.fixedRateAddress = fixedRateAddress
|
|
||||||
this.fixedRateContract = setContractDefaults(
|
|
||||||
new this.web3.eth.Contract(this.fixedRateExchangeAbi, this.fixedRateAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async amountToUnits(
|
|
||||||
token: string,
|
|
||||||
amount: string,
|
|
||||||
tokenDecimals: number
|
|
||||||
): Promise<string> {
|
|
||||||
return amountToUnits(this.web3, token, amount, tokenDecimals)
|
|
||||||
}
|
|
||||||
|
|
||||||
async unitsToAmount(
|
|
||||||
token: string,
|
|
||||||
amount: string,
|
|
||||||
tokenDecimals: number
|
|
||||||
): Promise<string> {
|
|
||||||
return unitsToAmount(this.web3, token, amount, tokenDecimals)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,7 +18,7 @@ export class FixedRateExchange {
|
|||||||
* @return {Promise<string>} exchangeId
|
* @return {Promise<string>} exchangeId
|
||||||
*/
|
*/
|
||||||
public async generateExchangeId(baseToken: string, datatoken: string): Promise<string> {
|
public async generateExchangeId(baseToken: string, datatoken: string): Promise<string> {
|
||||||
const exchangeId = await this.fixedRateContract.methods
|
const exchangeId = await this.contract.methods
|
||||||
.generateExchangeId(baseToken, datatoken)
|
.generateExchangeId(baseToken, datatoken)
|
||||||
.call()
|
.call()
|
||||||
return exchangeId
|
return exchangeId
|
||||||
@ -139,7 +43,7 @@ export class FixedRateExchange {
|
|||||||
consumeMarketFee: string,
|
consumeMarketFee: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
account,
|
account,
|
||||||
@ -185,7 +89,7 @@ export class FixedRateExchange {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.buyDT,
|
this.contract.methods.buyDT,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
dtAmountFormatted,
|
dtAmountFormatted,
|
||||||
maxBtFormatted,
|
maxBtFormatted,
|
||||||
@ -193,7 +97,7 @@ export class FixedRateExchange {
|
|||||||
consumeMarketFeeFormatted
|
consumeMarketFeeFormatted
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.buyDT(
|
.buyDT(
|
||||||
exchangeId,
|
exchangeId,
|
||||||
dtAmountFormatted,
|
dtAmountFormatted,
|
||||||
@ -232,7 +136,7 @@ export class FixedRateExchange {
|
|||||||
consumeMarketFee: string,
|
consumeMarketFee: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
account,
|
account,
|
||||||
@ -277,7 +181,7 @@ export class FixedRateExchange {
|
|||||||
)
|
)
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.sellDT,
|
this.contract.methods.sellDT,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
dtAmountFormatted,
|
dtAmountFormatted,
|
||||||
minBtFormatted,
|
minBtFormatted,
|
||||||
@ -285,7 +189,7 @@ export class FixedRateExchange {
|
|||||||
consumeMarketFeeFormatted
|
consumeMarketFeeFormatted
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.sellDT(
|
.sellDT(
|
||||||
exchangeId,
|
exchangeId,
|
||||||
dtAmountFormatted,
|
dtAmountFormatted,
|
||||||
@ -312,9 +216,7 @@ export class FixedRateExchange {
|
|||||||
* @return {Promise<Number>} no of available exchanges
|
* @return {Promise<Number>} no of available exchanges
|
||||||
*/
|
*/
|
||||||
public async getNumberOfExchanges(): Promise<number> {
|
public async getNumberOfExchanges(): Promise<number> {
|
||||||
const numExchanges = await this.fixedRateContract.methods
|
const numExchanges = await this.contract.methods.getNumberOfExchanges().call()
|
||||||
.getNumberOfExchanges()
|
|
||||||
.call()
|
|
||||||
return numExchanges
|
return numExchanges
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,7 +234,7 @@ export class FixedRateExchange {
|
|||||||
newRate: string,
|
newRate: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
account,
|
account,
|
||||||
@ -356,11 +258,11 @@ export class FixedRateExchange {
|
|||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.setRate,
|
this.contract.methods.setRate,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
this.web3.utils.toWei(newRate)
|
this.web3.utils.toWei(newRate)
|
||||||
)
|
)
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.setRate(exchangeId, this.web3.utils.toWei(newRate))
|
.setRate(exchangeId, this.web3.utils.toWei(newRate))
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -384,7 +286,7 @@ export class FixedRateExchange {
|
|||||||
newAllowedSwapper: string,
|
newAllowedSwapper: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
account,
|
account,
|
||||||
@ -408,11 +310,11 @@ export class FixedRateExchange {
|
|||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.setAllowedSwapper,
|
this.contract.methods.setAllowedSwapper,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
newAllowedSwapper
|
newAllowedSwapper
|
||||||
)
|
)
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.setAllowedSwapper(exchangeId, newAllowedSwapper)
|
.setAllowedSwapper(exchangeId, newAllowedSwapper)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -434,7 +336,7 @@ export class FixedRateExchange {
|
|||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(account, fixedRate.methods.toggleExchangeState, exchangeId)
|
return estimateGas(account, fixedRate.methods.toggleExchangeState, exchangeId)
|
||||||
}
|
}
|
||||||
@ -454,12 +356,10 @@ export class FixedRateExchange {
|
|||||||
if (exchange.active === true) return null
|
if (exchange.active === true) return null
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.toggleExchangeState,
|
this.contract.methods.toggleExchangeState,
|
||||||
exchangeId
|
exchangeId
|
||||||
)
|
)
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods.toggleExchangeState(exchangeId).send({
|
||||||
.toggleExchangeState(exchangeId)
|
|
||||||
.send({
|
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
@ -479,7 +379,7 @@ export class FixedRateExchange {
|
|||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(account, fixedRate.methods.toggleExchangeState, exchangeId)
|
return estimateGas(account, fixedRate.methods.toggleExchangeState, exchangeId)
|
||||||
}
|
}
|
||||||
@ -500,13 +400,11 @@ export class FixedRateExchange {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.toggleExchangeState,
|
this.contract.methods.toggleExchangeState,
|
||||||
exchangeId
|
exchangeId
|
||||||
)
|
)
|
||||||
|
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods.toggleExchangeState(exchangeId).send({
|
||||||
.toggleExchangeState(exchangeId)
|
|
||||||
.send({
|
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
@ -521,7 +419,7 @@ export class FixedRateExchange {
|
|||||||
* @return {Promise<string>} Rate (converted from wei)
|
* @return {Promise<string>} Rate (converted from wei)
|
||||||
*/
|
*/
|
||||||
public async getRate(exchangeId: string): Promise<string> {
|
public async getRate(exchangeId: string): Promise<string> {
|
||||||
const weiRate = await this.fixedRateContract.methods.getRate(exchangeId).call()
|
const weiRate = await this.contract.methods.getRate(exchangeId).call()
|
||||||
const rate = await this.web3.utils.fromWei(weiRate)
|
const rate = await this.web3.utils.fromWei(weiRate)
|
||||||
return rate
|
return rate
|
||||||
}
|
}
|
||||||
@ -532,7 +430,7 @@ export class FixedRateExchange {
|
|||||||
* @return {Promise<string>} dt supply formatted
|
* @return {Promise<string>} dt supply formatted
|
||||||
*/
|
*/
|
||||||
public async getDTSupply(exchangeId: string): Promise<string> {
|
public async getDTSupply(exchangeId: string): Promise<string> {
|
||||||
const dtSupply = await this.fixedRateContract.methods.getDTSupply(exchangeId).call()
|
const dtSupply = await this.contract.methods.getDTSupply(exchangeId).call()
|
||||||
const exchange = await this.getExchange(exchangeId)
|
const exchange = await this.getExchange(exchangeId)
|
||||||
return await this.unitsToAmount(exchange.datatoken, dtSupply, +exchange.dtDecimals)
|
return await this.unitsToAmount(exchange.datatoken, dtSupply, +exchange.dtDecimals)
|
||||||
}
|
}
|
||||||
@ -543,7 +441,7 @@ export class FixedRateExchange {
|
|||||||
* @return {Promise<string>} dt supply formatted
|
* @return {Promise<string>} dt supply formatted
|
||||||
*/
|
*/
|
||||||
public async getBTSupply(exchangeId: string): Promise<string> {
|
public async getBTSupply(exchangeId: string): Promise<string> {
|
||||||
const btSupply = await this.fixedRateContract.methods.getBTSupply(exchangeId).call()
|
const btSupply = await this.contract.methods.getBTSupply(exchangeId).call()
|
||||||
const exchange = await this.getExchange(exchangeId)
|
const exchange = await this.getExchange(exchangeId)
|
||||||
return await this.unitsToAmount(exchange.baseToken, btSupply, +exchange.btDecimals)
|
return await this.unitsToAmount(exchange.baseToken, btSupply, +exchange.btDecimals)
|
||||||
}
|
}
|
||||||
@ -554,7 +452,7 @@ export class FixedRateExchange {
|
|||||||
* @return {Promise<string>} address of allowedSwapper
|
* @return {Promise<string>} address of allowedSwapper
|
||||||
*/
|
*/
|
||||||
public async getAllowedSwapper(exchangeId: string): Promise<string> {
|
public async getAllowedSwapper(exchangeId: string): Promise<string> {
|
||||||
return await this.fixedRateContract.methods.getAllowedSwapper(exchangeId).call()
|
return await this.contract.methods.getAllowedSwapper(exchangeId).call()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -570,7 +468,7 @@ export class FixedRateExchange {
|
|||||||
consumeMarketFee: string = '0'
|
consumeMarketFee: string = '0'
|
||||||
): Promise<PriceAndFees> {
|
): Promise<PriceAndFees> {
|
||||||
const fixedRateExchange = await this.getExchange(exchangeId)
|
const fixedRateExchange = await this.getExchange(exchangeId)
|
||||||
const result = await this.fixedRateContract.methods
|
const result = await this.contract.methods
|
||||||
.calcBaseInGivenOutDT(
|
.calcBaseInGivenOutDT(
|
||||||
exchangeId,
|
exchangeId,
|
||||||
await this.amountToUnits(
|
await this.amountToUnits(
|
||||||
@ -620,7 +518,7 @@ export class FixedRateExchange {
|
|||||||
consumeMarketFee: string = '0'
|
consumeMarketFee: string = '0'
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const exchange = await this.getExchange(exchangeId)
|
const exchange = await this.getExchange(exchangeId)
|
||||||
const result = await this.fixedRateContract.methods
|
const result = await this.contract.methods
|
||||||
.calcBaseOutGivenInDT(
|
.calcBaseOutGivenInDT(
|
||||||
exchangeId,
|
exchangeId,
|
||||||
await this.amountToUnits(
|
await this.amountToUnits(
|
||||||
@ -641,7 +539,7 @@ export class FixedRateExchange {
|
|||||||
* @return {Promise<FixedPricedExchange>} Exchange details
|
* @return {Promise<FixedPricedExchange>} Exchange details
|
||||||
*/
|
*/
|
||||||
public async getExchange(exchangeId: string): Promise<FixedPriceExchange> {
|
public async getExchange(exchangeId: string): Promise<FixedPriceExchange> {
|
||||||
const result: FixedPriceExchange = await this.fixedRateContract.methods
|
const result: FixedPriceExchange = await this.contract.methods
|
||||||
.getExchange(exchangeId)
|
.getExchange(exchangeId)
|
||||||
.call()
|
.call()
|
||||||
result.dtDecimals = result.dtDecimals.toString()
|
result.dtDecimals = result.dtDecimals.toString()
|
||||||
@ -677,9 +575,7 @@ export class FixedRateExchange {
|
|||||||
* @return {Promise<FixedPricedExchange>} Exchange details
|
* @return {Promise<FixedPricedExchange>} Exchange details
|
||||||
*/
|
*/
|
||||||
public async getFeesInfo(exchangeId: string): Promise<FeesInfo> {
|
public async getFeesInfo(exchangeId: string): Promise<FeesInfo> {
|
||||||
const result: FeesInfo = await this.fixedRateContract.methods
|
const result: FeesInfo = await this.contract.methods.getFeesInfo(exchangeId).call()
|
||||||
.getFeesInfo(exchangeId)
|
|
||||||
.call()
|
|
||||||
result.opcFee = this.web3.utils.fromWei(result.opcFee.toString())
|
result.opcFee = this.web3.utils.fromWei(result.opcFee.toString())
|
||||||
result.marketFee = this.web3.utils.fromWei(result.marketFee.toString())
|
result.marketFee = this.web3.utils.fromWei(result.marketFee.toString())
|
||||||
|
|
||||||
@ -705,7 +601,7 @@ export class FixedRateExchange {
|
|||||||
* @return {Promise<String[]>} Exchanges list
|
* @return {Promise<String[]>} Exchanges list
|
||||||
*/
|
*/
|
||||||
public async getExchanges(): Promise<string[]> {
|
public async getExchanges(): Promise<string[]> {
|
||||||
return await this.fixedRateContract.methods.getExchanges().call()
|
return await this.contract.methods.getExchanges().call()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -714,7 +610,7 @@ export class FixedRateExchange {
|
|||||||
* @return {Promise<Boolean>} Result
|
* @return {Promise<Boolean>} Result
|
||||||
*/
|
*/
|
||||||
public async isActive(exchangeId: string): Promise<boolean> {
|
public async isActive(exchangeId: string): Promise<boolean> {
|
||||||
const result = await this.fixedRateContract.methods.isActive(exchangeId).call()
|
const result = await this.contract.methods.isActive(exchangeId).call()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -730,7 +626,7 @@ export class FixedRateExchange {
|
|||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(account, fixedRate.methods.toggleMintState, exchangeId, true)
|
return estimateGas(account, fixedRate.methods.toggleMintState, exchangeId, true)
|
||||||
}
|
}
|
||||||
@ -751,11 +647,11 @@ export class FixedRateExchange {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.toggleMintState,
|
this.contract.methods.toggleMintState,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.toggleMintState(exchangeId, true)
|
.toggleMintState(exchangeId, true)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -777,7 +673,7 @@ export class FixedRateExchange {
|
|||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
account,
|
account,
|
||||||
@ -803,12 +699,12 @@ export class FixedRateExchange {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.toggleMintState,
|
this.contract.methods.toggleMintState,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
|
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.toggleMintState(exchangeId, false)
|
.toggleMintState(exchangeId, false)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -833,8 +729,8 @@ export class FixedRateExchange {
|
|||||||
amount: string,
|
amount: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
const fixedrate: FixedPriceExchange = await this.fixedRateContract.methods
|
const fixedrate: FixedPriceExchange = await this.contract.methods
|
||||||
.getExchange(exchangeId)
|
.getExchange(exchangeId)
|
||||||
.call()
|
.call()
|
||||||
const amountWei = await this.amountToUnits(
|
const amountWei = await this.amountToUnits(
|
||||||
@ -860,7 +756,7 @@ export class FixedRateExchange {
|
|||||||
const exchange = await this.getExchange(exchangeId)
|
const exchange = await this.getExchange(exchangeId)
|
||||||
if (!exchange) return null
|
if (!exchange) return null
|
||||||
|
|
||||||
const fixedrate: FixedPriceExchange = await this.fixedRateContract.methods
|
const fixedrate: FixedPriceExchange = await this.contract.methods
|
||||||
.getExchange(exchangeId)
|
.getExchange(exchangeId)
|
||||||
.call()
|
.call()
|
||||||
const amountWei = await this.amountToUnits(
|
const amountWei = await this.amountToUnits(
|
||||||
@ -871,14 +767,12 @@ export class FixedRateExchange {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.collectBT,
|
this.contract.methods.collectBT,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
amountWei
|
amountWei
|
||||||
)
|
)
|
||||||
|
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods.collectBT(exchangeId, amountWei).send({
|
||||||
.collectBT(exchangeId, amountWei)
|
|
||||||
.send({
|
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
@ -900,8 +794,8 @@ export class FixedRateExchange {
|
|||||||
amount: string,
|
amount: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
const fixedrate: FixedPriceExchange = await this.fixedRateContract.methods
|
const fixedrate: FixedPriceExchange = await this.contract.methods
|
||||||
.getExchange(exchangeId)
|
.getExchange(exchangeId)
|
||||||
.call()
|
.call()
|
||||||
|
|
||||||
@ -928,7 +822,7 @@ export class FixedRateExchange {
|
|||||||
const exchange = await this.getExchange(exchangeId)
|
const exchange = await this.getExchange(exchangeId)
|
||||||
if (!exchange) return null
|
if (!exchange) return null
|
||||||
|
|
||||||
const fixedrate: FixedPriceExchange = await this.fixedRateContract.methods
|
const fixedrate: FixedPriceExchange = await this.contract.methods
|
||||||
.getExchange(exchangeId)
|
.getExchange(exchangeId)
|
||||||
.call()
|
.call()
|
||||||
const amountWei = await this.amountToUnits(
|
const amountWei = await this.amountToUnits(
|
||||||
@ -939,14 +833,12 @@ export class FixedRateExchange {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.collectDT,
|
this.contract.methods.collectDT,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
amountWei
|
amountWei
|
||||||
)
|
)
|
||||||
|
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods.collectDT(exchangeId, amountWei).send({
|
||||||
.collectDT(exchangeId, amountWei)
|
|
||||||
.send({
|
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
@ -966,7 +858,7 @@ export class FixedRateExchange {
|
|||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(account, fixedRate.methods.collectMarketFee, exchangeId)
|
return estimateGas(account, fixedRate.methods.collectMarketFee, exchangeId)
|
||||||
}
|
}
|
||||||
@ -986,12 +878,10 @@ export class FixedRateExchange {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.collectMarketFee,
|
this.contract.methods.collectMarketFee,
|
||||||
exchangeId
|
exchangeId
|
||||||
)
|
)
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods.collectMarketFee(exchangeId).send({
|
||||||
.collectMarketFee(exchangeId)
|
|
||||||
.send({
|
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
@ -1011,7 +901,7 @@ export class FixedRateExchange {
|
|||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(account, fixedRate.methods.collectMarketFee, exchangeId)
|
return estimateGas(account, fixedRate.methods.collectMarketFee, exchangeId)
|
||||||
}
|
}
|
||||||
@ -1031,12 +921,10 @@ export class FixedRateExchange {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.collectOceanFee,
|
this.contract.methods.collectOceanFee,
|
||||||
exchangeId
|
exchangeId
|
||||||
)
|
)
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods.collectOceanFee(exchangeId).send({
|
||||||
.collectOceanFee(exchangeId)
|
|
||||||
.send({
|
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
@ -1051,7 +939,7 @@ export class FixedRateExchange {
|
|||||||
async getOPCCollector(): Promise<string> {
|
async getOPCCollector(): Promise<string> {
|
||||||
let result = null
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await this.fixedRateContract.methods.opcCollector().call()
|
result = await this.contract.methods.opcCollector().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to get OPC Collector address: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get OPC Collector address: ${e.message}`)
|
||||||
}
|
}
|
||||||
@ -1065,7 +953,7 @@ export class FixedRateExchange {
|
|||||||
async getRouter(): Promise<string> {
|
async getRouter(): Promise<string> {
|
||||||
let result = null
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await this.fixedRateContract.methods.router().call()
|
result = await this.contract.methods.router().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to get Router address: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get Router address: ${e.message}`)
|
||||||
}
|
}
|
||||||
@ -1101,7 +989,7 @@ export class FixedRateExchange {
|
|||||||
newMarketFee: string,
|
newMarketFee: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
account,
|
account,
|
||||||
@ -1125,11 +1013,11 @@ export class FixedRateExchange {
|
|||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.updateMarketFee,
|
this.contract.methods.updateMarketFee,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
this.web3.utils.toWei(newMarketFee)
|
this.web3.utils.toWei(newMarketFee)
|
||||||
)
|
)
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.updateMarketFee(exchangeId, this.web3.utils.toWei(newMarketFee))
|
.updateMarketFee(exchangeId, this.web3.utils.toWei(newMarketFee))
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -1153,7 +1041,7 @@ export class FixedRateExchange {
|
|||||||
newMarketFeeCollector: string,
|
newMarketFeeCollector: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
account,
|
account,
|
||||||
@ -1177,11 +1065,11 @@ export class FixedRateExchange {
|
|||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.updateMarketFeeCollector,
|
this.contract.methods.updateMarketFeeCollector,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
newMarketFeeCollector
|
newMarketFeeCollector
|
||||||
)
|
)
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.updateMarketFeeCollector(exchangeId, newMarketFeeCollector)
|
.updateMarketFeeCollector(exchangeId, newMarketFeeCollector)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
@ -1,19 +1,21 @@
|
|||||||
import Web3 from 'web3'
|
|
||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
|
import Decimal from 'decimal.js'
|
||||||
|
import BigNumber from 'bignumber.js'
|
||||||
|
import Bpool from '@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json'
|
||||||
import {
|
import {
|
||||||
getFairGasPrice,
|
getFairGasPrice,
|
||||||
setContractDefaults,
|
setContractDefaults,
|
||||||
unitsToAmount,
|
|
||||||
amountToUnits,
|
|
||||||
LoggerInstance,
|
LoggerInstance,
|
||||||
estimateGas,
|
estimateGas,
|
||||||
ConfigHelper
|
getMaxAddLiquidity,
|
||||||
|
getMaxRemoveLiquidity,
|
||||||
|
getMaxSwapExactIn,
|
||||||
|
getMaxSwapExactOut,
|
||||||
|
MAX_UINT_256,
|
||||||
|
decimals
|
||||||
} from '../../utils'
|
} from '../../utils'
|
||||||
import BigNumber from 'bignumber.js'
|
|
||||||
import PoolTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json'
|
|
||||||
import defaultErc20Abi from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
|
||||||
import {
|
import {
|
||||||
CurrentFees,
|
CurrentFees,
|
||||||
TokenInOutMarket,
|
TokenInOutMarket,
|
||||||
@ -21,51 +23,14 @@ import {
|
|||||||
AmountsOutMaxFee,
|
AmountsOutMaxFee,
|
||||||
PoolPriceAndFees
|
PoolPriceAndFees
|
||||||
} from '../../@types'
|
} from '../../@types'
|
||||||
import { Config } from '../../models'
|
import { SmartContract } from '..'
|
||||||
import {
|
|
||||||
getMaxAddLiquidity,
|
|
||||||
getMaxRemoveLiquidity,
|
|
||||||
getMaxSwapExactIn,
|
|
||||||
getMaxSwapExactOut
|
|
||||||
} from '../../utils/PoolHelpers'
|
|
||||||
import Decimal from 'decimal.js'
|
|
||||||
const MaxUint256 =
|
|
||||||
'115792089237316195423570985008687907853269984665640564039457584007913129639934'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides an interface to Ocean friendly fork from Balancer BPool
|
* Provides an interface to Ocean friendly fork from Balancer BPool
|
||||||
*/
|
*/
|
||||||
export class Pool {
|
export class Pool extends SmartContract {
|
||||||
public poolAbi: AbiItem | AbiItem[]
|
getDefaultAbi(): AbiItem | AbiItem[] {
|
||||||
public web3: Web3
|
return Bpool.abi as AbiItem[]
|
||||||
private config: Config
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
web3: Web3,
|
|
||||||
network?: string | number,
|
|
||||||
poolAbi: AbiItem | AbiItem[] = null,
|
|
||||||
config?: Config
|
|
||||||
) {
|
|
||||||
if (poolAbi) this.poolAbi = poolAbi
|
|
||||||
else this.poolAbi = PoolTemplate.abi as AbiItem[]
|
|
||||||
this.web3 = web3
|
|
||||||
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
|
|
||||||
}
|
|
||||||
|
|
||||||
async amountToUnits(
|
|
||||||
token: string,
|
|
||||||
amount: string,
|
|
||||||
tokenDecimals?: number
|
|
||||||
): Promise<string> {
|
|
||||||
return amountToUnits(this.web3, token, amount, tokenDecimals)
|
|
||||||
}
|
|
||||||
|
|
||||||
async unitsToAmount(
|
|
||||||
token: string,
|
|
||||||
amount: string,
|
|
||||||
tokenDecimals?: number
|
|
||||||
): Promise<string> {
|
|
||||||
return unitsToAmount(this.web3, token, amount, tokenDecimals)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,7 +43,7 @@ export class Pool {
|
|||||||
let result = null
|
let result = null
|
||||||
try {
|
try {
|
||||||
const token = setContractDefaults(
|
const token = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
const balance = await token.methods.balanceOf(account).call()
|
const balance = await token.methods.balanceOf(account).call()
|
||||||
@ -108,7 +73,7 @@ export class Pool {
|
|||||||
const poolContract =
|
const poolContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(
|
||||||
new this.web3.eth.Contract(defaultErc20Abi.abi as AbiItem[], poolAddress),
|
new this.web3.eth.Contract(this.abi as AbiItem[], poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -127,7 +92,7 @@ export class Pool {
|
|||||||
fee: string
|
fee: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress, {
|
new this.web3.eth.Contract(this.abi, poolAddress, {
|
||||||
from: account
|
from: account
|
||||||
}),
|
}),
|
||||||
this.config
|
this.config
|
||||||
@ -154,7 +119,7 @@ export class Pool {
|
|||||||
*/
|
*/
|
||||||
async getNumTokens(poolAddress: string): Promise<string> {
|
async getNumTokens(poolAddress: string): Promise<string> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
@ -173,7 +138,7 @@ export class Pool {
|
|||||||
*/
|
*/
|
||||||
async getPoolSharesTotalSupply(poolAddress: string): Promise<string> {
|
async getPoolSharesTotalSupply(poolAddress: string): Promise<string> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let amount = null
|
let amount = null
|
||||||
@ -196,7 +161,7 @@ export class Pool {
|
|||||||
*/
|
*/
|
||||||
async getCurrentTokens(poolAddress: string): Promise<string[]> {
|
async getCurrentTokens(poolAddress: string): Promise<string[]> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
@ -218,7 +183,7 @@ export class Pool {
|
|||||||
*/
|
*/
|
||||||
async getFinalTokens(poolAddress: string): Promise<string[]> {
|
async getFinalTokens(poolAddress: string): Promise<string[]> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
@ -239,7 +204,7 @@ export class Pool {
|
|||||||
*/
|
*/
|
||||||
async getController(poolAddress: string): Promise<string> {
|
async getController(poolAddress: string): Promise<string> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
@ -258,7 +223,7 @@ export class Pool {
|
|||||||
*/
|
*/
|
||||||
async getBaseToken(poolAddress: string): Promise<string> {
|
async getBaseToken(poolAddress: string): Promise<string> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
@ -277,7 +242,7 @@ export class Pool {
|
|||||||
*/
|
*/
|
||||||
async getDatatoken(poolAddress: string): Promise<string> {
|
async getDatatoken(poolAddress: string): Promise<string> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
@ -296,7 +261,7 @@ export class Pool {
|
|||||||
*/
|
*/
|
||||||
async getMarketFee(poolAddress: string): Promise<string> {
|
async getMarketFee(poolAddress: string): Promise<string> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
@ -315,7 +280,7 @@ export class Pool {
|
|||||||
*/
|
*/
|
||||||
async getMarketFeeCollector(poolAddress: string): Promise<string> {
|
async getMarketFeeCollector(poolAddress: string): Promise<string> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
@ -338,7 +303,7 @@ export class Pool {
|
|||||||
*/
|
*/
|
||||||
async isBound(poolAddress: string, token: string): Promise<boolean> {
|
async isBound(poolAddress: string, token: string): Promise<boolean> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
@ -366,7 +331,7 @@ export class Pool {
|
|||||||
let amount = null
|
let amount = null
|
||||||
try {
|
try {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
const result = await pool.methods.getBalance(token).call()
|
const result = await pool.methods.getBalance(token).call()
|
||||||
@ -386,7 +351,7 @@ export class Pool {
|
|||||||
*/
|
*/
|
||||||
async isFinalized(poolAddress: string): Promise<boolean> {
|
async isFinalized(poolAddress: string): Promise<boolean> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
@ -407,7 +372,7 @@ export class Pool {
|
|||||||
*/
|
*/
|
||||||
async getSwapFee(poolAddress: string): Promise<string> {
|
async getSwapFee(poolAddress: string): Promise<string> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let fee = null
|
let fee = null
|
||||||
@ -430,7 +395,7 @@ export class Pool {
|
|||||||
*/
|
*/
|
||||||
async getNormalizedWeight(poolAddress: string, token: string): Promise<string> {
|
async getNormalizedWeight(poolAddress: string, token: string): Promise<string> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let weight = null
|
let weight = null
|
||||||
@ -453,7 +418,7 @@ export class Pool {
|
|||||||
*/
|
*/
|
||||||
async getDenormalizedWeight(poolAddress: string, token: string): Promise<string> {
|
async getDenormalizedWeight(poolAddress: string, token: string): Promise<string> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let weight = null
|
let weight = null
|
||||||
@ -476,7 +441,7 @@ export class Pool {
|
|||||||
*/
|
*/
|
||||||
async getTotalDenormalizedWeight(poolAddress: string): Promise<string> {
|
async getTotalDenormalizedWeight(poolAddress: string): Promise<string> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let weight = null
|
let weight = null
|
||||||
@ -505,7 +470,7 @@ export class Pool {
|
|||||||
tokenDecimals?: number
|
tokenDecimals?: number
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let weight = null
|
let weight = null
|
||||||
@ -524,7 +489,7 @@ export class Pool {
|
|||||||
*/
|
*/
|
||||||
async getCurrentMarketFees(poolAddress: string): Promise<CurrentFees> {
|
async getCurrentMarketFees(poolAddress: string): Promise<CurrentFees> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
@ -543,7 +508,7 @@ export class Pool {
|
|||||||
*/
|
*/
|
||||||
async getCurrentOPCFees(poolAddress: string): Promise<CurrentFees> {
|
async getCurrentOPCFees(poolAddress: string): Promise<CurrentFees> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
@ -569,7 +534,7 @@ export class Pool {
|
|||||||
tokenDecimals?: number
|
tokenDecimals?: number
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let weight = null
|
let weight = null
|
||||||
@ -599,7 +564,7 @@ export class Pool {
|
|||||||
const poolContract =
|
const poolContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi as AbiItem[], poolAddress),
|
new this.web3.eth.Contract(this.abi as AbiItem[], poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -614,7 +579,7 @@ export class Pool {
|
|||||||
*/
|
*/
|
||||||
async collectOPC(address: string, poolAddress: string): Promise<TransactionReceipt> {
|
async collectOPC(address: string, poolAddress: string): Promise<TransactionReceipt> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
@ -648,7 +613,7 @@ export class Pool {
|
|||||||
const poolContract =
|
const poolContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi as AbiItem[], poolAddress),
|
new this.web3.eth.Contract(this.abi as AbiItem[], poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -670,7 +635,7 @@ export class Pool {
|
|||||||
throw new Error(`Caller is not MarketFeeCollector`)
|
throw new Error(`Caller is not MarketFeeCollector`)
|
||||||
}
|
}
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
@ -707,7 +672,7 @@ export class Pool {
|
|||||||
const poolContract =
|
const poolContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi as AbiItem[], poolAddress),
|
new this.web3.eth.Contract(this.abi as AbiItem[], poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -737,7 +702,7 @@ export class Pool {
|
|||||||
throw new Error(`Caller is not MarketFeeCollector`)
|
throw new Error(`Caller is not MarketFeeCollector`)
|
||||||
}
|
}
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
@ -784,7 +749,7 @@ export class Pool {
|
|||||||
const poolContract =
|
const poolContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi as AbiItem[], poolAddress),
|
new this.web3.eth.Contract(this.abi as AbiItem[], poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -805,7 +770,7 @@ export class Pool {
|
|||||||
await this.getBaseToken(poolAddress),
|
await this.getBaseToken(poolAddress),
|
||||||
amountsInOutMaxFee.maxPrice
|
amountsInOutMaxFee.maxPrice
|
||||||
)
|
)
|
||||||
: MaxUint256
|
: MAX_UINT_256
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
@ -844,7 +809,7 @@ export class Pool {
|
|||||||
amountsInOutMaxFee: AmountsInMaxFee
|
amountsInOutMaxFee: AmountsInMaxFee
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -870,7 +835,7 @@ export class Pool {
|
|||||||
await this.getBaseToken(poolAddress),
|
await this.getBaseToken(poolAddress),
|
||||||
amountsInOutMaxFee.maxPrice
|
amountsInOutMaxFee.maxPrice
|
||||||
)
|
)
|
||||||
: MaxUint256
|
: MAX_UINT_256
|
||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
@ -935,7 +900,7 @@ export class Pool {
|
|||||||
const poolContract =
|
const poolContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi as AbiItem[], poolAddress),
|
new this.web3.eth.Contract(this.abi as AbiItem[], poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -956,7 +921,7 @@ export class Pool {
|
|||||||
await this.getBaseToken(poolAddress),
|
await this.getBaseToken(poolAddress),
|
||||||
amountsInOutMaxFee.maxPrice
|
amountsInOutMaxFee.maxPrice
|
||||||
)
|
)
|
||||||
: MaxUint256
|
: MAX_UINT_256
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
@ -990,7 +955,7 @@ export class Pool {
|
|||||||
amountsInOutMaxFee: AmountsOutMaxFee
|
amountsInOutMaxFee: AmountsOutMaxFee
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
@ -1017,7 +982,7 @@ export class Pool {
|
|||||||
await this.getBaseToken(poolAddress),
|
await this.getBaseToken(poolAddress),
|
||||||
amountsInOutMaxFee.maxPrice
|
amountsInOutMaxFee.maxPrice
|
||||||
)
|
)
|
||||||
: MaxUint256
|
: MAX_UINT_256
|
||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
account,
|
account,
|
||||||
@ -1081,7 +1046,7 @@ export class Pool {
|
|||||||
const poolContract =
|
const poolContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi as AbiItem[], poolAddress),
|
new this.web3.eth.Contract(this.abi as AbiItem[], poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1112,7 +1077,7 @@ export class Pool {
|
|||||||
tokenInDecimals?: number
|
tokenInDecimals?: number
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
@ -1171,7 +1136,7 @@ export class Pool {
|
|||||||
const poolContract =
|
const poolContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi as AbiItem[], poolAddress),
|
new this.web3.eth.Contract(this.abi as AbiItem[], poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1202,7 +1167,7 @@ export class Pool {
|
|||||||
poolDecimals?: number
|
poolDecimals?: number
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
@ -1260,27 +1225,19 @@ export class Pool {
|
|||||||
swapMarketFee: string
|
swapMarketFee: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let decimalsTokenIn = 18
|
let decimalsTokenIn = 18
|
||||||
let decimalsTokenOut = 18
|
let decimalsTokenOut = 18
|
||||||
|
|
||||||
const tokenInContract = setContractDefaults(
|
|
||||||
new this.web3.eth.Contract(defaultErc20Abi.abi as AbiItem[], tokenIn),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
const tokenOutContract = setContractDefaults(
|
|
||||||
new this.web3.eth.Contract(defaultErc20Abi.abi as AbiItem[], tokenOut),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
try {
|
try {
|
||||||
decimalsTokenIn = await tokenInContract.methods.decimals().call()
|
decimalsTokenIn = await decimals(this.web3, tokenIn)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: FAILED TO CALL DECIMALS(), USING 18 ${e.message}`)
|
LoggerInstance.error(`ERROR: FAILED TO CALL DECIMALS(), USING 18 ${e.message}`)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
decimalsTokenOut = await tokenOutContract.methods.decimals().call()
|
decimalsTokenOut = await decimals(this.web3, tokenOut)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: FAILED TO CALL DECIMALS(), USING 18 ${e.message}`)
|
LoggerInstance.error(`ERROR: FAILED TO CALL DECIMALS(), USING 18 ${e.message}`)
|
||||||
}
|
}
|
||||||
@ -1332,7 +1289,7 @@ export class Pool {
|
|||||||
tokenOutDecimals?: number
|
tokenOutDecimals?: number
|
||||||
): Promise<PoolPriceAndFees> {
|
): Promise<PoolPriceAndFees> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1412,7 +1369,7 @@ export class Pool {
|
|||||||
tokenOutDecimals?: number
|
tokenOutDecimals?: number
|
||||||
): Promise<PoolPriceAndFees> {
|
): Promise<PoolPriceAndFees> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1487,7 +1444,7 @@ export class Pool {
|
|||||||
tokenInDecimals?: number
|
tokenInDecimals?: number
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let amount = null
|
let amount = null
|
||||||
@ -1524,7 +1481,7 @@ export class Pool {
|
|||||||
tokenInDecimals?: number
|
tokenInDecimals?: number
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let amount = null
|
let amount = null
|
||||||
@ -1562,7 +1519,7 @@ export class Pool {
|
|||||||
tokenOutDecimals?: number
|
tokenOutDecimals?: number
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let amount = null
|
let amount = null
|
||||||
@ -1596,7 +1553,7 @@ export class Pool {
|
|||||||
tokenOutDecimals?: number
|
tokenOutDecimals?: number
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.abi, poolAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let amount = null
|
let amount = null
|
||||||
@ -1623,7 +1580,7 @@ export class Pool {
|
|||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
public getSwapEventSignature(): string {
|
public getSwapEventSignature(): string {
|
||||||
const abi = this.poolAbi as AbiItem[]
|
const abi = this.abi as AbiItem[]
|
||||||
const eventdata = abi.find(function (o) {
|
const eventdata = abi.find(function (o) {
|
||||||
if (o.name === 'LOG_SWAP' && o.type === 'event') return o
|
if (o.name === 'LOG_SWAP' && o.type === 'event') return o
|
||||||
})
|
})
|
||||||
@ -1636,7 +1593,7 @@ export class Pool {
|
|||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
public getJoinEventSignature(): string {
|
public getJoinEventSignature(): string {
|
||||||
const abi = this.poolAbi as AbiItem[]
|
const abi = this.abi as AbiItem[]
|
||||||
const eventdata = abi.find(function (o) {
|
const eventdata = abi.find(function (o) {
|
||||||
if (o.name === 'LOG_JOIN' && o.type === 'event') return o
|
if (o.name === 'LOG_JOIN' && o.type === 'event') return o
|
||||||
})
|
})
|
||||||
@ -1649,7 +1606,7 @@ export class Pool {
|
|||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
public getExitEventSignature(): string {
|
public getExitEventSignature(): string {
|
||||||
const abi = this.poolAbi as AbiItem[]
|
const abi = this.abi as AbiItem[]
|
||||||
const eventdata = abi.find(function (o) {
|
const eventdata = abi.find(function (o) {
|
||||||
if (o.name === 'LOG_EXIT' && o.type === 'event') return o
|
if (o.name === 'LOG_EXIT' && o.type === 'event') return o
|
||||||
})
|
})
|
@ -1,43 +1,17 @@
|
|||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
import Web3 from 'web3'
|
|
||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
import { AbiItem } from 'web3-utils'
|
import { AbiItem } from 'web3-utils'
|
||||||
import defaultRouter from '@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json'
|
import FactoryRouter from '@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json'
|
||||||
import { getFairGasPrice, setContractDefaults, ConfigHelper, estimateGas } from '../utils'
|
import { getFairGasPrice, estimateGas } from '../../utils'
|
||||||
import { Operation } from '../@types/Router'
|
import { Operation } from '../../@types'
|
||||||
import { Config } from '../models/index.js'
|
import { SmartContractWithAddress } from '..'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides an interface for FactoryRouter contract
|
* Provides an interface for FactoryRouter contract
|
||||||
*/
|
*/
|
||||||
export class Router {
|
export class Router extends SmartContractWithAddress {
|
||||||
public routerAddress: string
|
getDefaultAbi(): AbiItem | AbiItem[] {
|
||||||
public RouterAbi: AbiItem | AbiItem[]
|
return FactoryRouter.abi as AbiItem[]
|
||||||
public web3: Web3
|
|
||||||
public config: Config
|
|
||||||
public router: Contract
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiate Router.
|
|
||||||
* @param {String} routerAddress
|
|
||||||
* @param {AbiItem | AbiItem[]} Router
|
|
||||||
* @param {Web3} web3
|
|
||||||
*/
|
|
||||||
constructor(
|
|
||||||
routerAddress: string,
|
|
||||||
web3: Web3,
|
|
||||||
network?: string | number,
|
|
||||||
RouterAbi?: AbiItem | AbiItem[],
|
|
||||||
config?: Config
|
|
||||||
) {
|
|
||||||
this.routerAddress = routerAddress
|
|
||||||
this.RouterAbi = RouterAbi || (defaultRouter.abi as AbiItem[])
|
|
||||||
this.web3 = web3
|
|
||||||
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
|
|
||||||
this.router = setContractDefaults(
|
|
||||||
new this.web3.eth.Contract(this.RouterAbi, this.routerAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,7 +21,7 @@ export class Router {
|
|||||||
* @return {Promise<TransactionReceipt>} Transaction receipt
|
* @return {Promise<TransactionReceipt>} Transaction receipt
|
||||||
*/
|
*/
|
||||||
public async estGasBuyDTBatch(address: string, operations: Operation[]): Promise<any> {
|
public async estGasBuyDTBatch(address: string, operations: Operation[]): Promise<any> {
|
||||||
return estimateGas(address, this.router.methods.buyDTBatch, operations)
|
return estimateGas(address, this.contract.methods.buyDTBatch, operations)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,10 +34,14 @@ export class Router {
|
|||||||
address: string,
|
address: string,
|
||||||
operations: Operation[]
|
operations: Operation[]
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await estimateGas(address, this.router.methods.buyDTBatch, operations)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.contract.methods.buyDTBatch,
|
||||||
|
operations
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods.buyDTBatch(operations).send({
|
const trxReceipt = await this.contract.methods.buyDTBatch(operations).send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
@ -76,42 +54,42 @@ export class Router {
|
|||||||
* @return {Promise<boolean>} true if is on the list.
|
* @return {Promise<boolean>} true if is on the list.
|
||||||
*/
|
*/
|
||||||
public async isApprovedToken(address: string): Promise<boolean> {
|
public async isApprovedToken(address: string): Promise<boolean> {
|
||||||
return await this.router.methods.isApprovedToken(address).call()
|
return await this.contract.methods.isApprovedToken(address).call()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if an address is a side staking contract.
|
/** Check if an address is a side staking contract.
|
||||||
* @return {Promise<boolean>} true if is a SS contract
|
* @return {Promise<boolean>} true if is a SS contract
|
||||||
*/
|
*/
|
||||||
public async isSideStaking(address: string): Promise<boolean> {
|
public async isSideStaking(address: string): Promise<boolean> {
|
||||||
return await this.router.methods.isSSContract(address).call()
|
return await this.contract.methods.isSSContract(address).call()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if an address is a Fixed Rate contract.
|
/** Check if an address is a Fixed Rate contract.
|
||||||
* @return {Promise<boolean>} true if is a Fixed Rate contract
|
* @return {Promise<boolean>} true if is a Fixed Rate contract
|
||||||
*/
|
*/
|
||||||
public async isFixedPrice(address: string): Promise<boolean> {
|
public async isFixedPrice(address: string): Promise<boolean> {
|
||||||
return await this.router.methods.isFixedRateContract(address).call()
|
return await this.contract.methods.isFixedRateContract(address).call()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get Router Owner
|
/** Get Router Owner
|
||||||
* @return {Promise<string>} Router Owner address
|
* @return {Promise<string>} Router Owner address
|
||||||
*/
|
*/
|
||||||
public async getOwner(): Promise<string> {
|
public async getOwner(): Promise<string> {
|
||||||
return await this.router.methods.routerOwner().call()
|
return await this.contract.methods.routerOwner().call()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get NFT Factory address
|
/** Get NFT Factory address
|
||||||
* @return {Promise<string>} NFT Factory address
|
* @return {Promise<string>} NFT Factory address
|
||||||
*/
|
*/
|
||||||
public async getNFTFactory(): Promise<string> {
|
public async getNFTFactory(): Promise<string> {
|
||||||
return await this.router.methods.factory().call()
|
return await this.contract.methods.factory().call()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if an address is a pool template contract.
|
/** Check if an address is a pool template contract.
|
||||||
* @return {Promise<boolean>} true if is a Template
|
* @return {Promise<boolean>} true if is a Template
|
||||||
*/
|
*/
|
||||||
public async isPoolTemplate(address: string): Promise<boolean> {
|
public async isPoolTemplate(address: string): Promise<boolean> {
|
||||||
return await this.router.methods.isPoolTemplate(address).call()
|
return await this.contract.methods.isPoolTemplate(address).call()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,7 +104,7 @@ export class Router {
|
|||||||
tokenAddress: string,
|
tokenAddress: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(address, this.router.methods.addApprovedToken, tokenAddress)
|
return estimateGas(address, this.contract.methods.addApprovedToken, tokenAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -145,12 +123,12 @@ export class Router {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.router.methods.addApprovedToken,
|
this.contract.methods.addApprovedToken,
|
||||||
tokenAddress
|
tokenAddress
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods.addApprovedToken(tokenAddress).send({
|
const trxReceipt = await this.contract.methods.addApprovedToken(tokenAddress).send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
@ -171,7 +149,7 @@ export class Router {
|
|||||||
tokenAddress: string,
|
tokenAddress: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(address, this.router.methods.removeApprovedToken, tokenAddress)
|
return estimateGas(address, this.contract.methods.removeApprovedToken, tokenAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -190,12 +168,14 @@ export class Router {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.router.methods.removeApprovedToken,
|
this.contract.methods.removeApprovedToken,
|
||||||
tokenAddress
|
tokenAddress
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods.removeApprovedToken(tokenAddress).send({
|
const trxReceipt = await this.contract.methods
|
||||||
|
.removeApprovedToken(tokenAddress)
|
||||||
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
@ -211,7 +191,7 @@ export class Router {
|
|||||||
* @return {Promise<TransactionReceipt>}
|
* @return {Promise<TransactionReceipt>}
|
||||||
*/
|
*/
|
||||||
public async estGasAddSSContract(address: string, tokenAddress: string): Promise<any> {
|
public async estGasAddSSContract(address: string, tokenAddress: string): Promise<any> {
|
||||||
return estimateGas(address, this.router.methods.addSSContract, tokenAddress)
|
return estimateGas(address, this.contract.methods.addSSContract, tokenAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -230,12 +210,12 @@ export class Router {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.router.methods.addSSContract,
|
this.contract.methods.addSSContract,
|
||||||
tokenAddress
|
tokenAddress
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods.addSSContract(tokenAddress).send({
|
const trxReceipt = await this.contract.methods.addSSContract(tokenAddress).send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
@ -254,7 +234,7 @@ export class Router {
|
|||||||
address: string,
|
address: string,
|
||||||
tokenAddress: string
|
tokenAddress: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(address, this.router.methods.removeSSContract, tokenAddress)
|
return estimateGas(address, this.contract.methods.removeSSContract, tokenAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -273,12 +253,12 @@ export class Router {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.router.methods.removeSSContract,
|
this.contract.methods.removeSSContract,
|
||||||
tokenAddress
|
tokenAddress
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods.removeSSContract(tokenAddress).send({
|
const trxReceipt = await this.contract.methods.removeSSContract(tokenAddress).send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
@ -297,7 +277,7 @@ export class Router {
|
|||||||
address: string,
|
address: string,
|
||||||
tokenAddress: string
|
tokenAddress: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(address, this.router.methods.addFixedRateContract, tokenAddress)
|
return estimateGas(address, this.contract.methods.addFixedRateContract, tokenAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -316,12 +296,14 @@ export class Router {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.router.methods.addFixedRateContract,
|
this.contract.methods.addFixedRateContract,
|
||||||
tokenAddress
|
tokenAddress
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods.addFixedRateContract(tokenAddress).send({
|
const trxReceipt = await this.contract.methods
|
||||||
|
.addFixedRateContract(tokenAddress)
|
||||||
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
@ -340,7 +322,11 @@ export class Router {
|
|||||||
address: string,
|
address: string,
|
||||||
tokenAddress: string
|
tokenAddress: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(address, this.router.methods.removeFixedRateContract, tokenAddress)
|
return estimateGas(
|
||||||
|
address,
|
||||||
|
this.contract.methods.removeFixedRateContract,
|
||||||
|
tokenAddress
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -359,12 +345,12 @@ export class Router {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.router.methods.removeFixedRateContract,
|
this.contract.methods.removeFixedRateContract,
|
||||||
tokenAddress
|
tokenAddress
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke removeFixedRateContract function of the contract
|
// Invoke removeFixedRateContract function of the contract
|
||||||
const trxReceipt = await this.router.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.removeFixedRateContract(tokenAddress)
|
.removeFixedRateContract(tokenAddress)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -385,7 +371,7 @@ export class Router {
|
|||||||
address: string,
|
address: string,
|
||||||
tokenAddress: string
|
tokenAddress: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(address, this.router.methods.addDispenserContract, tokenAddress)
|
return estimateGas(address, this.contract.methods.addDispenserContract, tokenAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -404,12 +390,14 @@ export class Router {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.router.methods.addDispenserContract,
|
this.contract.methods.addDispenserContract,
|
||||||
tokenAddress
|
tokenAddress
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods.addDispenserContract(tokenAddress).send({
|
const trxReceipt = await this.contract.methods
|
||||||
|
.addDispenserContract(tokenAddress)
|
||||||
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
@ -428,7 +416,11 @@ export class Router {
|
|||||||
address: string,
|
address: string,
|
||||||
tokenAddress: string
|
tokenAddress: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(address, this.router.methods.removeDispenserContract, tokenAddress)
|
return estimateGas(
|
||||||
|
address,
|
||||||
|
this.contract.methods.removeDispenserContract,
|
||||||
|
tokenAddress
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -447,12 +439,12 @@ export class Router {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.router.methods.removeDispenserContract,
|
this.contract.methods.removeDispenserContract,
|
||||||
tokenAddress
|
tokenAddress
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.removeDispenserContract(tokenAddress)
|
.removeDispenserContract(tokenAddress)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -467,14 +459,14 @@ export class Router {
|
|||||||
* @return {Promise<number>} OPC fee for a specific baseToken
|
* @return {Promise<number>} OPC fee for a specific baseToken
|
||||||
*/
|
*/
|
||||||
public async getOPCFee(baseToken: string): Promise<number> {
|
public async getOPCFee(baseToken: string): Promise<number> {
|
||||||
return await this.router.methods.getOPCFee(baseToken).call()
|
return await this.contract.methods.getOPCFee(baseToken).call()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get Current OPF Fee
|
/** Get Current OPF Fee
|
||||||
* @return {Promise<number>} OPF fee
|
* @return {Promise<number>} OPF fee
|
||||||
*/
|
*/
|
||||||
public async getCurrentOPCFee(): Promise<number> {
|
public async getCurrentOPCFee(): Promise<number> {
|
||||||
return await this.router.methods.swapOceanFee().call()
|
return await this.contract.methods.swapOceanFee().call()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -492,7 +484,7 @@ export class Router {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
this.router.methods.updateOPCFee,
|
this.contract.methods.updateOPCFee,
|
||||||
newSwapOceanFee,
|
newSwapOceanFee,
|
||||||
newSwapNonOceanFee,
|
newSwapNonOceanFee,
|
||||||
newConsumeFee,
|
newConsumeFee,
|
||||||
@ -522,7 +514,7 @@ export class Router {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.router.methods.updateOPCFee,
|
this.contract.methods.updateOPCFee,
|
||||||
newSwapOceanFee,
|
newSwapOceanFee,
|
||||||
newSwapNonOceanFee,
|
newSwapNonOceanFee,
|
||||||
newConsumeFee,
|
newConsumeFee,
|
||||||
@ -530,7 +522,7 @@ export class Router {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.updateOPCFee(newSwapOceanFee, newSwapNonOceanFee, newConsumeFee, newProviderFee)
|
.updateOPCFee(newSwapOceanFee, newSwapNonOceanFee, newConsumeFee, newProviderFee)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -551,7 +543,7 @@ export class Router {
|
|||||||
address: string,
|
address: string,
|
||||||
templateAddress: string
|
templateAddress: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(address, this.router.methods.addPoolTemplate, templateAddress)
|
return estimateGas(address, this.contract.methods.addPoolTemplate, templateAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -570,12 +562,12 @@ export class Router {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.router.methods.addPoolTemplate,
|
this.contract.methods.addPoolTemplate,
|
||||||
templateAddress
|
templateAddress
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods.addPoolTemplate(templateAddress).send({
|
const trxReceipt = await this.contract.methods.addPoolTemplate(templateAddress).send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
@ -594,7 +586,7 @@ export class Router {
|
|||||||
address: string,
|
address: string,
|
||||||
templateAddress: string
|
templateAddress: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return estimateGas(address, this.router.methods.removePoolTemplate, templateAddress)
|
return estimateGas(address, this.contract.methods.removePoolTemplate, templateAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -613,12 +605,12 @@ export class Router {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.router.methods.removePoolTemplate,
|
this.contract.methods.removePoolTemplate,
|
||||||
templateAddress
|
templateAddress
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.removePoolTemplate(templateAddress)
|
.removePoolTemplate(templateAddress)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
@ -1,40 +1,13 @@
|
|||||||
import Web3 from 'web3'
|
|
||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
import {
|
import SideStakingAbi from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
|
||||||
LoggerInstance,
|
import { LoggerInstance, getFairGasPrice, estimateGas } from '../../utils'
|
||||||
getFairGasPrice,
|
import { SmartContract } from '..'
|
||||||
ConfigHelper,
|
|
||||||
estimateGas,
|
|
||||||
unitsToAmount
|
|
||||||
} from '../../utils'
|
|
||||||
import SideStakingTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
|
|
||||||
import { Config } from '../../models'
|
|
||||||
|
|
||||||
export class SideStaking {
|
export class SideStaking extends SmartContract {
|
||||||
public ssAbi: AbiItem | AbiItem[]
|
getDefaultAbi(): AbiItem | AbiItem[] {
|
||||||
public web3: Web3
|
return SideStakingAbi.abi as AbiItem[]
|
||||||
public config: Config
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
web3: Web3,
|
|
||||||
network?: string | number,
|
|
||||||
ssAbi: AbiItem | AbiItem[] = null,
|
|
||||||
config?: Config
|
|
||||||
) {
|
|
||||||
if (ssAbi) this.ssAbi = ssAbi
|
|
||||||
else this.ssAbi = SideStakingTemplate.abi as AbiItem[]
|
|
||||||
this.web3 = web3
|
|
||||||
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
|
|
||||||
}
|
|
||||||
|
|
||||||
async unitsToAmount(
|
|
||||||
token: string,
|
|
||||||
amount: string,
|
|
||||||
tokenDecimals?: number
|
|
||||||
): Promise<string> {
|
|
||||||
return unitsToAmount(this.web3, token, amount, tokenDecimals)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,7 +20,7 @@ export class SideStaking {
|
|||||||
ssAddress: string,
|
ssAddress: string,
|
||||||
datatokenAddress: string
|
datatokenAddress: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||||
let result = null
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods
|
result = await sideStaking.methods
|
||||||
@ -71,7 +44,7 @@ export class SideStaking {
|
|||||||
datatokenAddress: string
|
datatokenAddress: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
try {
|
try {
|
||||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||||
let result = null
|
let result = null
|
||||||
result = await sideStaking.methods
|
result = await sideStaking.methods
|
||||||
.getDatatokenCurrentCirculatingSupply(datatokenAddress)
|
.getDatatokenCurrentCirculatingSupply(datatokenAddress)
|
||||||
@ -92,7 +65,7 @@ export class SideStaking {
|
|||||||
ssAddress: string,
|
ssAddress: string,
|
||||||
datatokenAddress: string
|
datatokenAddress: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||||
let result = null
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getPublisherAddress(datatokenAddress).call()
|
result = await sideStaking.methods.getPublisherAddress(datatokenAddress).call()
|
||||||
@ -109,7 +82,7 @@ export class SideStaking {
|
|||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
async getBaseToken(ssAddress: string, datatokenAddress: string): Promise<string> {
|
async getBaseToken(ssAddress: string, datatokenAddress: string): Promise<string> {
|
||||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||||
let result = null
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getBaseTokenAddress(datatokenAddress).call()
|
result = await sideStaking.methods.getBaseTokenAddress(datatokenAddress).call()
|
||||||
@ -126,7 +99,7 @@ export class SideStaking {
|
|||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
async getPoolAddress(ssAddress: string, datatokenAddress: string): Promise<string> {
|
async getPoolAddress(ssAddress: string, datatokenAddress: string): Promise<string> {
|
||||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||||
let result = null
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getPoolAddress(datatokenAddress).call()
|
result = await sideStaking.methods.getPoolAddress(datatokenAddress).call()
|
||||||
@ -146,7 +119,7 @@ export class SideStaking {
|
|||||||
ssAddress: string,
|
ssAddress: string,
|
||||||
datatokenAddress: string
|
datatokenAddress: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||||
let result = null
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getBaseTokenBalance(datatokenAddress).call()
|
result = await sideStaking.methods.getBaseTokenBalance(datatokenAddress).call()
|
||||||
@ -168,7 +141,7 @@ export class SideStaking {
|
|||||||
datatokenAddress: string,
|
datatokenAddress: string,
|
||||||
tokenDecimals?: number
|
tokenDecimals?: number
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||||
let result = null
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getDatatokenBalance(datatokenAddress).call()
|
result = await sideStaking.methods.getDatatokenBalance(datatokenAddress).call()
|
||||||
@ -186,7 +159,7 @@ export class SideStaking {
|
|||||||
* @return {String} end block for vesting amount
|
* @return {String} end block for vesting amount
|
||||||
*/
|
*/
|
||||||
async getvestingEndBlock(ssAddress: string, datatokenAddress: string): Promise<string> {
|
async getvestingEndBlock(ssAddress: string, datatokenAddress: string): Promise<string> {
|
||||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||||
let result = null
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getvestingEndBlock(datatokenAddress).call()
|
result = await sideStaking.methods.getvestingEndBlock(datatokenAddress).call()
|
||||||
@ -208,7 +181,7 @@ export class SideStaking {
|
|||||||
datatokenAddress: string,
|
datatokenAddress: string,
|
||||||
tokenDecimals?: number
|
tokenDecimals?: number
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||||
let result = null
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getvestingAmount(datatokenAddress).call()
|
result = await sideStaking.methods.getvestingAmount(datatokenAddress).call()
|
||||||
@ -229,7 +202,7 @@ export class SideStaking {
|
|||||||
ssAddress: string,
|
ssAddress: string,
|
||||||
datatokenAddress: string
|
datatokenAddress: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||||
let result = null
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getvestingLastBlock(datatokenAddress).call()
|
result = await sideStaking.methods.getvestingLastBlock(datatokenAddress).call()
|
||||||
@ -251,7 +224,7 @@ export class SideStaking {
|
|||||||
datatokenAddress: string,
|
datatokenAddress: string,
|
||||||
tokenDecimals?: number
|
tokenDecimals?: number
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||||
let result = null
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getvestingAmountSoFar(datatokenAddress).call()
|
result = await sideStaking.methods.getvestingAmountSoFar(datatokenAddress).call()
|
||||||
@ -277,7 +250,7 @@ export class SideStaking {
|
|||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const sideStaking =
|
const sideStaking =
|
||||||
contractInstance || new this.web3.eth.Contract(this.ssAbi as AbiItem[], ssAddress)
|
contractInstance || new this.web3.eth.Contract(this.abi as AbiItem[], ssAddress)
|
||||||
|
|
||||||
return estimateGas(account, sideStaking.methods.getVesting, datatokenAddress)
|
return estimateGas(account, sideStaking.methods.getVesting, datatokenAddress)
|
||||||
}
|
}
|
||||||
@ -294,7 +267,7 @@ export class SideStaking {
|
|||||||
ssAddress: string,
|
ssAddress: string,
|
||||||
datatokenAddress: string
|
datatokenAddress: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||||
let result = null
|
let result = null
|
||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
@ -332,7 +305,7 @@ export class SideStaking {
|
|||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const sideStaking =
|
const sideStaking =
|
||||||
contractInstance || new this.web3.eth.Contract(this.ssAbi as AbiItem[], ssAddress)
|
contractInstance || new this.web3.eth.Contract(this.abi as AbiItem[], ssAddress)
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
account,
|
account,
|
||||||
@ -357,7 +330,7 @@ export class SideStaking {
|
|||||||
poolAddress: string,
|
poolAddress: string,
|
||||||
swapFee: number
|
swapFee: number
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||||
let result = null
|
let result = null
|
||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
@ -388,7 +361,7 @@ export class SideStaking {
|
|||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
async getRouter(ssAddress: string): Promise<string> {
|
async getRouter(ssAddress: string): Promise<string> {
|
||||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||||
let result = null
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.router().call()
|
result = await sideStaking.methods.router().call()
|
@ -3,58 +3,38 @@ import { AbiItem } from 'web3-utils'
|
|||||||
import { TransactionReceipt } from 'web3-eth'
|
import { TransactionReceipt } from 'web3-eth'
|
||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
import Decimal from 'decimal.js'
|
import Decimal from 'decimal.js'
|
||||||
import defaultDatatokensAbi from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
||||||
import defaultDatatokensEnterpriseAbi from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json'
|
import ERC20TemplateEnterprise from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json'
|
||||||
import {
|
import {
|
||||||
LoggerInstance,
|
LoggerInstance,
|
||||||
getFairGasPrice,
|
getFairGasPrice,
|
||||||
setContractDefaults,
|
setContractDefaults,
|
||||||
getFreOrderParams,
|
getFreOrderParams,
|
||||||
estimateGas,
|
estimateGas,
|
||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS
|
||||||
ConfigHelper
|
} from '../../utils'
|
||||||
} from '../utils'
|
|
||||||
import {
|
import {
|
||||||
ConsumeMarketFee,
|
ConsumeMarketFee,
|
||||||
FreOrderParams,
|
FreOrderParams,
|
||||||
FreCreationParams,
|
FreCreationParams,
|
||||||
ProviderFees,
|
ProviderFees,
|
||||||
PublishingMarketFee
|
PublishingMarketFee,
|
||||||
} from '../@types'
|
DispenserParams,
|
||||||
|
OrderParams,
|
||||||
|
DatatokenRoles
|
||||||
|
} from '../../@types'
|
||||||
import { Nft } from './NFT'
|
import { Nft } from './NFT'
|
||||||
import { Config } from '../models/index.js'
|
import { Config } from '../../config'
|
||||||
|
import { SmartContract } from '..'
|
||||||
|
|
||||||
/**
|
export class Datatoken extends SmartContract {
|
||||||
* ERC20 ROLES
|
public abiEnterprise: AbiItem | AbiItem[]
|
||||||
*/
|
|
||||||
interface Roles {
|
|
||||||
minter: boolean
|
|
||||||
paymentManager: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface OrderParams {
|
|
||||||
consumer: string
|
|
||||||
serviceIndex: number
|
|
||||||
_providerFee: ProviderFees
|
|
||||||
_consumeMarketFee: ConsumeMarketFee
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DispenserParams {
|
|
||||||
maxTokens: string
|
|
||||||
maxBalance: string
|
|
||||||
withMint?: boolean // true if we want to allow the dispenser to be a minter
|
|
||||||
allowedSwapper?: string // only account that can ask tokens. set address(0) if not required
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Datatoken {
|
|
||||||
public factoryAddress: string
|
|
||||||
public factoryABI: AbiItem | AbiItem[]
|
|
||||||
public datatokensAbi: AbiItem | AbiItem[]
|
|
||||||
public datatokensEnterpriseAbi: AbiItem | AbiItem[]
|
|
||||||
public web3: Web3
|
|
||||||
public config: Config
|
|
||||||
public nft: Nft
|
public nft: Nft
|
||||||
|
|
||||||
|
getDefaultAbi(): AbiItem | AbiItem[] {
|
||||||
|
return ERC20Template.abi as AbiItem[]
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiate ERC20 Datatokens
|
* Instantiate ERC20 Datatokens
|
||||||
* @param {AbiItem | AbiItem[]} datatokensAbi
|
* @param {AbiItem | AbiItem[]} datatokensAbi
|
||||||
@ -63,15 +43,12 @@ export class Datatoken {
|
|||||||
constructor(
|
constructor(
|
||||||
web3: Web3,
|
web3: Web3,
|
||||||
network?: string | number,
|
network?: string | number,
|
||||||
datatokensAbi?: AbiItem | AbiItem[],
|
config?: Config,
|
||||||
datatokensEnterpriseAbi?: AbiItem | AbiItem[],
|
abi?: AbiItem | AbiItem[],
|
||||||
config?: Config
|
abiEnterprise?: AbiItem | AbiItem[]
|
||||||
) {
|
) {
|
||||||
this.web3 = web3
|
super(web3, network, config, abi)
|
||||||
this.datatokensAbi = datatokensAbi || (defaultDatatokensAbi.abi as AbiItem[])
|
this.abiEnterprise = abiEnterprise || (ERC20TemplateEnterprise.abi as AbiItem[])
|
||||||
this.datatokensEnterpriseAbi =
|
|
||||||
datatokensEnterpriseAbi || (defaultDatatokensEnterpriseAbi.abi as AbiItem[])
|
|
||||||
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
|
|
||||||
this.nft = new Nft(this.web3)
|
this.nft = new Nft(this.web3)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,10 +70,7 @@ export class Datatoken {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const dtContract =
|
const dtContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
@ -121,7 +95,7 @@ export class Datatoken {
|
|||||||
address: string
|
address: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dtContract = setContractDefaults(
|
const dtContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
new this.web3.eth.Contract(this.abi, dtAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -161,10 +135,7 @@ export class Datatoken {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const dtContract =
|
const dtContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
@ -191,10 +162,7 @@ export class Datatoken {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const dtContract =
|
const dtContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!fixedRateParams.allowedConsumer) fixedRateParams.allowedConsumer = ZERO_ADDRESS
|
if (!fixedRateParams.allowedConsumer) fixedRateParams.allowedConsumer = ZERO_ADDRESS
|
||||||
const withMint = fixedRateParams.withMint ? 1 : 0
|
const withMint = fixedRateParams.withMint ? 1 : 0
|
||||||
@ -233,7 +201,7 @@ export class Datatoken {
|
|||||||
fixedRateParams: FreCreationParams
|
fixedRateParams: FreCreationParams
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dtContract = setContractDefaults(
|
const dtContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
new this.web3.eth.Contract(this.abi, dtAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
if (!(await this.isERC20Deployer(dtAddress, address))) {
|
if (!(await this.isERC20Deployer(dtAddress, address))) {
|
||||||
@ -308,10 +276,7 @@ export class Datatoken {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const dtContract =
|
const dtContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!dispenserParams.allowedSwapper) dispenserParams.allowedSwapper = ZERO_ADDRESS
|
if (!dispenserParams.allowedSwapper) dispenserParams.allowedSwapper = ZERO_ADDRESS
|
||||||
|
|
||||||
@ -347,7 +312,7 @@ export class Datatoken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const dtContract = setContractDefaults(
|
const dtContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
new this.web3.eth.Contract(this.abi, dtAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -399,7 +364,7 @@ export class Datatoken {
|
|||||||
toAddress?: string
|
toAddress?: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dtContract = setContractDefaults(
|
const dtContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
new this.web3.eth.Contract(this.abi, dtAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -446,10 +411,7 @@ export class Datatoken {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const dtContract =
|
const dtContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(address, dtContract.methods.addMinter, minter)
|
return estimateGas(address, dtContract.methods.addMinter, minter)
|
||||||
}
|
}
|
||||||
@ -468,7 +430,7 @@ export class Datatoken {
|
|||||||
minter: string
|
minter: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dtContract = setContractDefaults(
|
const dtContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
new this.web3.eth.Contract(this.abi, dtAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -504,10 +466,7 @@ export class Datatoken {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const dtContract =
|
const dtContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
// should check ERC20Deployer role using erc721 level ..
|
// should check ERC20Deployer role using erc721 level ..
|
||||||
|
|
||||||
@ -529,7 +488,7 @@ export class Datatoken {
|
|||||||
minter: string
|
minter: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dtContract = setContractDefaults(
|
const dtContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
new this.web3.eth.Contract(this.abi, dtAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -565,10 +524,7 @@ export class Datatoken {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const dtContract =
|
const dtContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(address, dtContract.methods.addPaymentManager, paymentManager)
|
return estimateGas(address, dtContract.methods.addPaymentManager, paymentManager)
|
||||||
}
|
}
|
||||||
@ -587,7 +543,7 @@ export class Datatoken {
|
|||||||
paymentManager: string
|
paymentManager: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dtContract = setContractDefaults(
|
const dtContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
new this.web3.eth.Contract(this.abi, dtAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -627,10 +583,7 @@ export class Datatoken {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const dtContract =
|
const dtContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(address, dtContract.methods.removePaymentManager, paymentManager)
|
return estimateGas(address, dtContract.methods.removePaymentManager, paymentManager)
|
||||||
}
|
}
|
||||||
@ -649,7 +602,7 @@ export class Datatoken {
|
|||||||
paymentManager: string
|
paymentManager: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dtContract = setContractDefaults(
|
const dtContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
new this.web3.eth.Contract(this.abi, dtAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -691,10 +644,7 @@ export class Datatoken {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const dtContract =
|
const dtContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(address, dtContract.methods.setPaymentCollector, paymentCollector)
|
return estimateGas(address, dtContract.methods.setPaymentCollector, paymentCollector)
|
||||||
}
|
}
|
||||||
@ -714,7 +664,7 @@ export class Datatoken {
|
|||||||
paymentCollector: string
|
paymentCollector: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dtContract = setContractDefaults(
|
const dtContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
new this.web3.eth.Contract(this.abi, dtAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
const isPaymentManager = (await this.getDTPermissions(dtAddress, address))
|
const isPaymentManager = (await this.getDTPermissions(dtAddress, address))
|
||||||
@ -752,7 +702,7 @@ export class Datatoken {
|
|||||||
*/
|
*/
|
||||||
public async getPaymentCollector(dtAddress: string): Promise<string> {
|
public async getPaymentCollector(dtAddress: string): Promise<string> {
|
||||||
const dtContract = setContractDefaults(
|
const dtContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
new this.web3.eth.Contract(this.abi, dtAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
const paymentCollector = await dtContract.methods.getPaymentCollector().call()
|
const paymentCollector = await dtContract.methods.getPaymentCollector().call()
|
||||||
@ -795,10 +745,7 @@ export class Datatoken {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const dtContract =
|
const dtContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(address, dtContract.methods.transfer, toAddress, amount)
|
return estimateGas(address, dtContract.methods.transfer, toAddress, amount)
|
||||||
}
|
}
|
||||||
@ -818,7 +765,7 @@ export class Datatoken {
|
|||||||
address: string
|
address: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dtContract = setContractDefaults(
|
const dtContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
new this.web3.eth.Contract(this.abi, dtAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
@ -862,10 +809,7 @@ export class Datatoken {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const dtContract =
|
const dtContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
@ -895,7 +839,7 @@ export class Datatoken {
|
|||||||
consumeMarketFee?: ConsumeMarketFee
|
consumeMarketFee?: ConsumeMarketFee
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dtContract = setContractDefaults(
|
const dtContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
new this.web3.eth.Contract(this.abi, dtAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
if (!consumeMarketFee) {
|
if (!consumeMarketFee) {
|
||||||
@ -946,10 +890,7 @@ export class Datatoken {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const dtContract =
|
const dtContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(address, dtContract.methods.reuseOrder, orderTxId, providerFees)
|
return estimateGas(address, dtContract.methods.reuseOrder, orderTxId, providerFees)
|
||||||
}
|
}
|
||||||
@ -970,7 +911,7 @@ export class Datatoken {
|
|||||||
providerFees: ProviderFees
|
providerFees: ProviderFees
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dtContract = setContractDefaults(
|
const dtContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
new this.web3.eth.Contract(this.abi, dtAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
@ -1011,8 +952,7 @@ export class Datatoken {
|
|||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const dtContract =
|
const dtContract =
|
||||||
contractInstance ||
|
contractInstance || new this.web3.eth.Contract(this.abiEnterprise, dtAddress)
|
||||||
new this.web3.eth.Contract(this.datatokensEnterpriseAbi, dtAddress)
|
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
@ -1035,7 +975,7 @@ export class Datatoken {
|
|||||||
orderParams: OrderParams,
|
orderParams: OrderParams,
|
||||||
freParams: FreOrderParams
|
freParams: FreOrderParams
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dtContract = new this.web3.eth.Contract(this.datatokensEnterpriseAbi, dtAddress)
|
const dtContract = new this.web3.eth.Contract(this.abiEnterprise, dtAddress)
|
||||||
try {
|
try {
|
||||||
const freContractParams = getFreOrderParams(freParams)
|
const freContractParams = getFreOrderParams(freParams)
|
||||||
|
|
||||||
@ -1076,8 +1016,7 @@ export class Datatoken {
|
|||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const dtContract =
|
const dtContract =
|
||||||
contractInstance ||
|
contractInstance || new this.web3.eth.Contract(this.abiEnterprise, dtAddress)
|
||||||
new this.web3.eth.Contract(this.datatokensEnterpriseAbi, dtAddress)
|
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
@ -1100,7 +1039,7 @@ export class Datatoken {
|
|||||||
orderParams: OrderParams,
|
orderParams: OrderParams,
|
||||||
dispenserContract: string
|
dispenserContract: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dtContract = new this.web3.eth.Contract(this.datatokensEnterpriseAbi, dtAddress)
|
const dtContract = new this.web3.eth.Contract(this.abiEnterprise, dtAddress)
|
||||||
try {
|
try {
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
@ -1138,10 +1077,7 @@ export class Datatoken {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const dtContract =
|
const dtContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(address, dtContract.methods.setData, value)
|
return estimateGas(address, dtContract.methods.setData, value)
|
||||||
}
|
}
|
||||||
@ -1164,7 +1100,7 @@ export class Datatoken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const dtContract = setContractDefaults(
|
const dtContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
new this.web3.eth.Contract(this.abi, dtAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1193,10 +1129,7 @@ export class Datatoken {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const dtContract =
|
const dtContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(address, dtContract.methods.cleanPermissions)
|
return estimateGas(address, dtContract.methods.cleanPermissions)
|
||||||
}
|
}
|
||||||
@ -1216,7 +1149,7 @@ export class Datatoken {
|
|||||||
throw new Error('Caller is NOT Nft Owner')
|
throw new Error('Caller is NOT Nft Owner')
|
||||||
}
|
}
|
||||||
const dtContract = setContractDefaults(
|
const dtContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
new this.web3.eth.Contract(this.abi, dtAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1235,11 +1168,14 @@ export class Datatoken {
|
|||||||
/** Returns ERC20 user's permissions for a datatoken
|
/** Returns ERC20 user's permissions for a datatoken
|
||||||
* @param {String} dtAddress Datatoken adress
|
* @param {String} dtAddress Datatoken adress
|
||||||
* @param {String} address user adress
|
* @param {String} address user adress
|
||||||
* @return {Promise<Roles>}
|
* @return {Promise<DatatokenRoles>}
|
||||||
*/
|
*/
|
||||||
public async getDTPermissions(dtAddress: string, address: string): Promise<Roles> {
|
public async getDTPermissions(
|
||||||
|
dtAddress: string,
|
||||||
|
address: string
|
||||||
|
): Promise<DatatokenRoles> {
|
||||||
const dtContract = setContractDefaults(
|
const dtContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
new this.web3.eth.Contract(this.abi, dtAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
const roles = await dtContract.methods.permissions(address).call()
|
const roles = await dtContract.methods.permissions(address).call()
|
||||||
@ -1252,7 +1188,7 @@ export class Datatoken {
|
|||||||
*/
|
*/
|
||||||
public async getCap(dtAddress: string): Promise<string> {
|
public async getCap(dtAddress: string): Promise<string> {
|
||||||
const dtContract = setContractDefaults(
|
const dtContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
new this.web3.eth.Contract(this.abi, dtAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
const cap = await dtContract.methods.cap().call()
|
const cap = await dtContract.methods.cap().call()
|
||||||
@ -1265,7 +1201,7 @@ export class Datatoken {
|
|||||||
*/
|
*/
|
||||||
public async getDecimals(dtAddress: string): Promise<string> {
|
public async getDecimals(dtAddress: string): Promise<string> {
|
||||||
const dtContract = setContractDefaults(
|
const dtContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
new this.web3.eth.Contract(this.abi, dtAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
const decimals = await dtContract.methods.decimals().call()
|
const decimals = await dtContract.methods.decimals().call()
|
||||||
@ -1278,7 +1214,7 @@ export class Datatoken {
|
|||||||
*/
|
*/
|
||||||
public async getNFTAddress(dtAddress: string): Promise<string> {
|
public async getNFTAddress(dtAddress: string): Promise<string> {
|
||||||
const dtContract = setContractDefaults(
|
const dtContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
new this.web3.eth.Contract(this.abi, dtAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
const nftAddress = await dtContract.methods.getERC721Address().call()
|
const nftAddress = await dtContract.methods.getERC721Address().call()
|
||||||
@ -1292,7 +1228,7 @@ export class Datatoken {
|
|||||||
*/
|
*/
|
||||||
public async isERC20Deployer(dtAddress: string, address: string): Promise<boolean> {
|
public async isERC20Deployer(dtAddress: string, address: string): Promise<boolean> {
|
||||||
const dtContract = setContractDefaults(
|
const dtContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
new this.web3.eth.Contract(this.abi, dtAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
const isERC20Deployer = await dtContract.methods.isERC20Deployer(address).call()
|
const isERC20Deployer = await dtContract.methods.isERC20Deployer(address).call()
|
||||||
@ -1306,7 +1242,7 @@ export class Datatoken {
|
|||||||
* @return {Promise<String>} balance Number of datatokens. Will be converted from wei
|
* @return {Promise<String>} balance Number of datatokens. Will be converted from wei
|
||||||
*/
|
*/
|
||||||
public async balance(datatokenAddress: string, address: string): Promise<string> {
|
public async balance(datatokenAddress: string, address: string): Promise<string> {
|
||||||
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, datatokenAddress, {
|
const dtContract = new this.web3.eth.Contract(this.abi, datatokenAddress, {
|
||||||
from: address
|
from: address
|
||||||
})
|
})
|
||||||
const balance = await dtContract.methods.balanceOf(address).call()
|
const balance = await dtContract.methods.balanceOf(address).call()
|
||||||
@ -1330,7 +1266,7 @@ export class Datatoken {
|
|||||||
address: string
|
address: string
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
// Estimate gas cost for publishMarketFeeAddress method
|
// Estimate gas cost for publishMarketFeeAddress method
|
||||||
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, datatokenAddress, {
|
const dtContract = new this.web3.eth.Contract(this.abi, datatokenAddress, {
|
||||||
from: address
|
from: address
|
||||||
})
|
})
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
@ -1359,7 +1295,7 @@ export class Datatoken {
|
|||||||
publishMarketFeeAmount: string,
|
publishMarketFeeAmount: string,
|
||||||
address: string
|
address: string
|
||||||
) {
|
) {
|
||||||
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, datatokenAddress, {
|
const dtContract = new this.web3.eth.Contract(this.abi, datatokenAddress, {
|
||||||
from: address
|
from: address
|
||||||
})
|
})
|
||||||
const mktFeeAddress = (await dtContract.methods.getPublishingMarketFee().call())[0]
|
const mktFeeAddress = (await dtContract.methods.getPublishingMarketFee().call())[0]
|
||||||
@ -1398,7 +1334,7 @@ export class Datatoken {
|
|||||||
datatokenAddress: string,
|
datatokenAddress: string,
|
||||||
address: string
|
address: string
|
||||||
): Promise<PublishingMarketFee> {
|
): Promise<PublishingMarketFee> {
|
||||||
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, datatokenAddress, {
|
const dtContract = new this.web3.eth.Contract(this.abi, datatokenAddress, {
|
||||||
from: address
|
from: address
|
||||||
})
|
})
|
||||||
|
|
@ -1,47 +1,20 @@
|
|||||||
import Web3 from 'web3'
|
|
||||||
import { AbiItem } from 'web3-utils'
|
import { AbiItem } from 'web3-utils'
|
||||||
import { TransactionReceipt } from 'web3-eth'
|
import { TransactionReceipt } from 'web3-eth'
|
||||||
import defaultNftAbi from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json'
|
import ERC721Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json'
|
||||||
import {
|
import {
|
||||||
LoggerInstance,
|
LoggerInstance,
|
||||||
getFairGasPrice,
|
getFairGasPrice,
|
||||||
generateDtName,
|
generateDtName,
|
||||||
setContractDefaults,
|
setContractDefaults,
|
||||||
estimateGas,
|
estimateGas
|
||||||
ConfigHelper
|
} from '../../utils'
|
||||||
} from '../utils'
|
|
||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
import { MetadataProof } from '../../src/@types'
|
import { MetadataProof, MetadataAndTokenURI, NftRoles } from '../../@types'
|
||||||
import { Config } from '../models/index.js'
|
import { SmartContract } from '..'
|
||||||
import { MetadataAndTokenURI } from '../@types'
|
|
||||||
|
|
||||||
/**
|
export class Nft extends SmartContract {
|
||||||
* ERC721 ROLES
|
getDefaultAbi(): AbiItem | AbiItem[] {
|
||||||
*/
|
return ERC721Template.abi as AbiItem[]
|
||||||
interface Roles {
|
|
||||||
manager: boolean
|
|
||||||
deployERC20: boolean
|
|
||||||
updateMetadata: boolean
|
|
||||||
store: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Nft {
|
|
||||||
public factory721Address: string
|
|
||||||
public factory721Abi: AbiItem | AbiItem[]
|
|
||||||
public nftAbi: AbiItem | AbiItem[]
|
|
||||||
public web3: Web3
|
|
||||||
public startBlock: number
|
|
||||||
public config: Config
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
web3: Web3,
|
|
||||||
network?: string | number,
|
|
||||||
nftAbi?: AbiItem | AbiItem[],
|
|
||||||
config?: Config
|
|
||||||
) {
|
|
||||||
this.nftAbi = nftAbi || (defaultNftAbi.abi as AbiItem[])
|
|
||||||
this.web3 = web3
|
|
||||||
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,10 +49,7 @@ export class Nft {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const nftContract =
|
const nftContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
nftContract.methods.createERC20,
|
nftContract.methods.createERC20,
|
||||||
@ -131,7 +101,7 @@ export class Nft {
|
|||||||
|
|
||||||
// Create 721contract object
|
// Create 721contract object
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -185,10 +155,7 @@ export class Nft {
|
|||||||
) {
|
) {
|
||||||
const nftContract =
|
const nftContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(address, nftContract.methods.addManager, manager)
|
return estimateGas(address, nftContract.methods.addManager, manager)
|
||||||
}
|
}
|
||||||
@ -202,7 +169,7 @@ export class Nft {
|
|||||||
*/
|
*/
|
||||||
public async addManager(nftAddress: string, address: string, manager: string) {
|
public async addManager(nftAddress: string, address: string, manager: string) {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -238,10 +205,7 @@ export class Nft {
|
|||||||
) {
|
) {
|
||||||
const nftContract =
|
const nftContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
return estimateGas(address, nftContract.methods.removeManager, manager)
|
return estimateGas(address, nftContract.methods.removeManager, manager)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,7 +218,7 @@ export class Nft {
|
|||||||
*/
|
*/
|
||||||
public async removeManager(nftAddress: string, address: string, manager: string) {
|
public async removeManager(nftAddress: string, address: string, manager: string) {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -290,10 +254,7 @@ export class Nft {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const nftContract =
|
const nftContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
return estimateGas(address, nftContract.methods.addToCreateERC20List, erc20Deployer)
|
return estimateGas(address, nftContract.methods.addToCreateERC20List, erc20Deployer)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,7 +271,7 @@ export class Nft {
|
|||||||
erc20Deployer: string
|
erc20Deployer: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -353,10 +314,7 @@ export class Nft {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const nftContract =
|
const nftContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
@ -378,7 +336,7 @@ export class Nft {
|
|||||||
erc20Deployer: string
|
erc20Deployer: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -423,10 +381,7 @@ export class Nft {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const nftContract =
|
const nftContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(address, nftContract.methods.addToMetadataList, metadataUpdater)
|
return estimateGas(address, nftContract.methods.addToMetadataList, metadataUpdater)
|
||||||
}
|
}
|
||||||
@ -444,7 +399,7 @@ export class Nft {
|
|||||||
metadataUpdater: string
|
metadataUpdater: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -484,10 +439,7 @@ export class Nft {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const nftContract =
|
const nftContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
address,
|
address,
|
||||||
@ -509,7 +461,7 @@ export class Nft {
|
|||||||
metadataUpdater: string
|
metadataUpdater: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -556,10 +508,7 @@ export class Nft {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const nftContract =
|
const nftContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(address, nftContract.methods.addTo725StoreList, storeUpdater)
|
return estimateGas(address, nftContract.methods.addTo725StoreList, storeUpdater)
|
||||||
}
|
}
|
||||||
@ -577,7 +526,7 @@ export class Nft {
|
|||||||
storeUpdater: string
|
storeUpdater: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -617,10 +566,7 @@ export class Nft {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const nftContract =
|
const nftContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(address, nftContract.methods.removeFrom725StoreList, storeUpdater)
|
return estimateGas(address, nftContract.methods.removeFrom725StoreList, storeUpdater)
|
||||||
}
|
}
|
||||||
@ -638,7 +584,7 @@ export class Nft {
|
|||||||
storeUpdater: string
|
storeUpdater: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -682,10 +628,7 @@ export class Nft {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const nftContract =
|
const nftContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(address, nftContract.methods.cleanPermissions)
|
return estimateGas(address, nftContract.methods.cleanPermissions)
|
||||||
}
|
}
|
||||||
@ -705,7 +648,7 @@ export class Nft {
|
|||||||
address: string
|
address: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -743,10 +686,7 @@ export class Nft {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const nftContract =
|
const nftContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
nftOwner,
|
nftOwner,
|
||||||
@ -773,7 +713,7 @@ export class Nft {
|
|||||||
tokenId?: number
|
tokenId?: number
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -821,10 +761,7 @@ export class Nft {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const nftContract =
|
const nftContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
nftOwner,
|
nftOwner,
|
||||||
@ -851,7 +788,7 @@ export class Nft {
|
|||||||
tokenId?: number
|
tokenId?: number
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -906,10 +843,7 @@ export class Nft {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const nftContract =
|
const nftContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
if (!metadataProofs) metadataProofs = []
|
if (!metadataProofs) metadataProofs = []
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
metadataUpdater,
|
metadataUpdater,
|
||||||
@ -943,7 +877,7 @@ export class Nft {
|
|||||||
metadataProofs?: MetadataProof[]
|
metadataProofs?: MetadataProof[]
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
if (!metadataProofs) metadataProofs = []
|
if (!metadataProofs) metadataProofs = []
|
||||||
@ -996,10 +930,7 @@ export class Nft {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const nftContract =
|
const nftContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
const sanitizedMetadataAndTokenURI = {
|
const sanitizedMetadataAndTokenURI = {
|
||||||
...metadataAndTokenURI,
|
...metadataAndTokenURI,
|
||||||
metadataProofs: metadataAndTokenURI.metadataProofs || []
|
metadataProofs: metadataAndTokenURI.metadataProofs || []
|
||||||
@ -1024,7 +955,7 @@ export class Nft {
|
|||||||
metadataAndTokenURI: MetadataAndTokenURI
|
metadataAndTokenURI: MetadataAndTokenURI
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
if (!(await this.getNftPermissions(nftAddress, metadataUpdater)).updateMetadata) {
|
if (!(await this.getNftPermissions(nftAddress, metadataUpdater)).updateMetadata) {
|
||||||
@ -1066,10 +997,7 @@ export class Nft {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const nftContract =
|
const nftContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
setContractDefaults(
|
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
metadataUpdater,
|
metadataUpdater,
|
||||||
@ -1091,7 +1019,7 @@ export class Nft {
|
|||||||
metadataState: number
|
metadataState: number
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1127,7 +1055,7 @@ export class Nft {
|
|||||||
data: string
|
data: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1146,7 +1074,7 @@ export class Nft {
|
|||||||
data: string
|
data: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1165,7 +1093,7 @@ export class Nft {
|
|||||||
*/
|
*/
|
||||||
public async getNftOwner(nftAddress: string): Promise<string> {
|
public async getNftOwner(nftAddress: string): Promise<string> {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
const trxReceipt = await nftContract.methods.ownerOf(1).call()
|
const trxReceipt = await nftContract.methods.ownerOf(1).call()
|
||||||
@ -1175,11 +1103,11 @@ export class Nft {
|
|||||||
/** Get users NFT Permissions
|
/** Get users NFT Permissions
|
||||||
* @param {String} nftAddress erc721 contract adress
|
* @param {String} nftAddress erc721 contract adress
|
||||||
* @param {String} address user adress
|
* @param {String} address user adress
|
||||||
* @return {Promise<Roles>}
|
* @return {Promise<NftRoles>}
|
||||||
*/
|
*/
|
||||||
public async getNftPermissions(nftAddress: string, address: string): Promise<Roles> {
|
public async getNftPermissions(nftAddress: string, address: string): Promise<NftRoles> {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
const roles = await nftContract.methods.getPermissions(address).call()
|
const roles = await nftContract.methods.getPermissions(address).call()
|
||||||
@ -1192,7 +1120,7 @@ export class Nft {
|
|||||||
*/
|
*/
|
||||||
public async getMetadata(nftAddress: string): Promise<Object> {
|
public async getMetadata(nftAddress: string): Promise<Object> {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
return await nftContract.methods.getMetaData().call()
|
return await nftContract.methods.getMetaData().call()
|
||||||
@ -1201,11 +1129,11 @@ export class Nft {
|
|||||||
/** Get users ERC20Deployer role
|
/** Get users ERC20Deployer role
|
||||||
* @param {String} nftAddress erc721 contract adress
|
* @param {String} nftAddress erc721 contract adress
|
||||||
* @param {String} address user adress
|
* @param {String} address user adress
|
||||||
* @return {Promise<Roles>}
|
* @return {Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
public async isErc20Deployer(nftAddress: string, address: string): Promise<boolean> {
|
public async isErc20Deployer(nftAddress: string, address: string): Promise<boolean> {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
const isERC20Deployer = await nftContract.methods.isERC20Deployer(address).call()
|
const isERC20Deployer = await nftContract.methods.isERC20Deployer(address).call()
|
||||||
@ -1219,7 +1147,7 @@ export class Nft {
|
|||||||
*/
|
*/
|
||||||
public async getData(nftAddress: string, key: string): Promise<string> {
|
public async getData(nftAddress: string, key: string): Promise<string> {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
const data = await nftContract.methods.getData(key).call()
|
const data = await nftContract.methods.getData(key).call()
|
||||||
@ -1233,7 +1161,7 @@ export class Nft {
|
|||||||
*/
|
*/
|
||||||
public async getTokenURI(nftAddress: string, id: number): Promise<string> {
|
public async getTokenURI(nftAddress: string, id: number): Promise<string> {
|
||||||
const nftContract = setContractDefaults(
|
const nftContract = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.abi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
const data = await nftContract.methods.tokenURI(id).call()
|
const data = await nftContract.methods.tokenURI(id).call()
|
@ -1 +0,0 @@
|
|||||||
export * from './NFTFactory'
|
|
11
src/index.ts
11
src/index.ts
@ -1,8 +1,5 @@
|
|||||||
export * from './aquarius'
|
|
||||||
export * from './pools'
|
|
||||||
export * from './tokens'
|
|
||||||
export * from './factories'
|
|
||||||
export * from './models'
|
|
||||||
export * from './utils'
|
|
||||||
export * from './@types'
|
export * from './@types'
|
||||||
export * from './provider'
|
export * from './config'
|
||||||
|
export * from './contracts'
|
||||||
|
export * from './services'
|
||||||
|
export * from './utils'
|
||||||
|
@ -1 +0,0 @@
|
|||||||
export * from './Config'
|
|
@ -1 +0,0 @@
|
|||||||
export * from './Pool'
|
|
@ -1 +0,0 @@
|
|||||||
export * from './Dispenser'
|
|
@ -1 +0,0 @@
|
|||||||
export * from './FixedRateExchange'
|
|
@ -1,5 +0,0 @@
|
|||||||
export * from './balancer'
|
|
||||||
export * from './dispenser'
|
|
||||||
export * from './fixedRate'
|
|
||||||
export * from './ssContracts'
|
|
||||||
export * from './Router'
|
|
@ -1 +0,0 @@
|
|||||||
export * from './SideStaking'
|
|
@ -1 +0,0 @@
|
|||||||
export * from './Provider'
|
|
@ -1,6 +1,7 @@
|
|||||||
import { LoggerInstance, sleep } from '../utils'
|
|
||||||
import { Asset, DDO, ValidateMetadata } from '../@types/'
|
|
||||||
import fetch from 'cross-fetch'
|
import fetch from 'cross-fetch'
|
||||||
|
import { LoggerInstance, sleep } from '../utils'
|
||||||
|
import { Asset, DDO, ValidateMetadata } from '../@types'
|
||||||
|
|
||||||
export class Aquarius {
|
export class Aquarius {
|
||||||
public aquariusURL
|
public aquariusURL
|
||||||
/**
|
/**
|
||||||
@ -122,5 +123,3 @@ export class Aquarius {
|
|||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Aquarius
|
|
@ -1,5 +1,6 @@
|
|||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import { LoggerInstance, getData } from '../utils'
|
import fetch from 'cross-fetch'
|
||||||
|
import { LoggerInstance, getData, noZeroX } from '../utils'
|
||||||
import {
|
import {
|
||||||
FileMetadata,
|
FileMetadata,
|
||||||
ComputeJob,
|
ComputeJob,
|
||||||
@ -8,22 +9,10 @@ import {
|
|||||||
ComputeAsset,
|
ComputeAsset,
|
||||||
ComputeEnvironment,
|
ComputeEnvironment,
|
||||||
ProviderInitialize,
|
ProviderInitialize,
|
||||||
ProviderComputeInitializeResults
|
ProviderComputeInitializeResults,
|
||||||
} from '../@types/'
|
ServiceEndpoint,
|
||||||
import { noZeroX } from '../utils/ConversionTypeHelper'
|
UserCustomParameters
|
||||||
import fetch from 'cross-fetch'
|
} from '../@types'
|
||||||
export interface HttpCallback {
|
|
||||||
(httpMethod: string, url: string, body: string, header: any): Promise<any>
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ServiceEndpoint {
|
|
||||||
serviceName: string
|
|
||||||
method: string
|
|
||||||
urlPath: string
|
|
||||||
}
|
|
||||||
export interface UserCustomParameters {
|
|
||||||
[key: string]: any
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Provider {
|
export class Provider {
|
||||||
/**
|
/**
|
||||||
@ -780,4 +769,3 @@ export class Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const ProviderInstance = new Provider()
|
export const ProviderInstance = new Provider()
|
||||||
export default ProviderInstance
|
|
@ -1 +1,2 @@
|
|||||||
export * from './Aquarius'
|
export * from './Aquarius'
|
||||||
|
export * from './Provider'
|
@ -1,2 +0,0 @@
|
|||||||
export * from './Datatoken'
|
|
||||||
export * from './NFT'
|
|
@ -1,2 +1,4 @@
|
|||||||
export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
||||||
export const GASLIMIT_DEFAULT = 1000000
|
export const GASLIMIT_DEFAULT = 1000000
|
||||||
|
export const MAX_UINT_256 =
|
||||||
|
'115792089237316195423570985008687907853269984665640564039457584007913129639934'
|
||||||
|
@ -1,17 +1,14 @@
|
|||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import BigNumber from 'bignumber.js'
|
import BigNumber from 'bignumber.js'
|
||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
import { generateDtName } from './DatatokenName'
|
|
||||||
import {
|
import {
|
||||||
Erc20CreateParams,
|
Erc20CreateParams,
|
||||||
FreCreationParams,
|
FreCreationParams,
|
||||||
FreOrderParams,
|
FreOrderParams,
|
||||||
PoolCreationParams
|
PoolCreationParams
|
||||||
} from '../@types'
|
} from '../@types'
|
||||||
import { Config } from '../models'
|
import { Config } from '../config'
|
||||||
import { minAbi } from './minAbi'
|
import { generateDtName, minAbi, LoggerInstance, GASLIMIT_DEFAULT, ZERO_ADDRESS } from '.'
|
||||||
import LoggerInstance from './Logger'
|
|
||||||
import { GASLIMIT_DEFAULT, ZERO_ADDRESS } from './Constants'
|
|
||||||
|
|
||||||
export function setContractDefaults(contract: Contract, config: Config): Contract {
|
export function setContractDefaults(contract: Contract, config: Config): Contract {
|
||||||
if (config) {
|
if (config) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { LoggerInstance } from './Logger'
|
import { LoggerInstance } from '.'
|
||||||
|
|
||||||
export const zeroX = (input: string): string => zeroXTransformer(input, true)
|
export const zeroX = (input: string): string => zeroXTransformer(input, true)
|
||||||
export const noZeroX = (input: string): string => zeroXTransformer(input, false)
|
export const noZeroX = (input: string): string => zeroXTransformer(input, false)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import wordListDefault from '../data/words.json'
|
import wordListDefault from './data/words.json'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate new datatoken name & symbol from a word list
|
* Generate new datatoken name & symbol from a word list
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import sha256 from 'crypto-js/sha256'
|
import sha256 from 'crypto-js/sha256'
|
||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import LoggerInstance from './Logger'
|
import { LoggerInstance } from '.'
|
||||||
|
|
||||||
export function generateDid(erc721Address: string, chainId: number): string {
|
export function generateDid(erc721Address: string, chainId: number): string {
|
||||||
erc721Address = Web3.utils.toChecksumAddress(erc721Address)
|
erc721Address = Web3.utils.toChecksumAddress(erc721Address)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import fetch from 'cross-fetch'
|
import fetch from 'cross-fetch'
|
||||||
import LoggerInstance from './Logger'
|
import { DownloadResponse } from '../@types'
|
||||||
import { DownloadResponse } from '../@types/DownloadResponse'
|
import { LoggerInstance } from '.'
|
||||||
|
|
||||||
export async function fetchData(url: string, opts: RequestInit): Promise<Response> {
|
export async function fetchData(url: string, opts: RequestInit): Promise<Response> {
|
||||||
const result = await fetch(url, opts)
|
const result = await fetch(url, opts)
|
||||||
|
@ -43,4 +43,3 @@ export class Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const LoggerInstance = new Logger()
|
export const LoggerInstance = new Logger()
|
||||||
export default LoggerInstance
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import Decimal from 'decimal.js'
|
import Decimal from 'decimal.js'
|
||||||
import { Pool } from '..'
|
import { Pool } from '../contracts'
|
||||||
|
|
||||||
export function calcMaxExactOut(balance: string): Decimal {
|
export function calcMaxExactOut(balance: string): Decimal {
|
||||||
return new Decimal(balance).div(2)
|
return new Decimal(balance).div(2)
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import { LoggerInstance } from './Logger'
|
|
||||||
|
|
||||||
export async function signHash(web3: Web3, message: string, address: string) {
|
export async function signHash(web3: Web3, message: string, address: string) {
|
||||||
let signedMessage = await web3.eth.sign(message, address)
|
let signedMessage = await web3.eth.sign(message, address)
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import Decimal from 'decimal.js'
|
import Decimal from 'decimal.js'
|
||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
|
import { TransactionReceipt } from 'web3-core'
|
||||||
|
import Web3 from 'web3'
|
||||||
import {
|
import {
|
||||||
amountToUnits,
|
amountToUnits,
|
||||||
estimateGas,
|
estimateGas,
|
||||||
getFairGasPrice,
|
getFairGasPrice,
|
||||||
unitsToAmount
|
unitsToAmount,
|
||||||
} from './ContractUtils'
|
minAbi,
|
||||||
import { minAbi } from './minAbi'
|
LoggerInstance
|
||||||
import LoggerInstance from './Logger'
|
} from '.'
|
||||||
import { TransactionReceipt } from 'web3-core'
|
|
||||||
import Web3 from 'web3'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Estimate gas cost for approval function
|
* Estimate gas cost for approval function
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
export * from './Logger'
|
|
||||||
export * from './DatatokenName'
|
|
||||||
export * from './ContractUtils'
|
|
||||||
export * from './FetchHelper'
|
|
||||||
export * from './ConfigHelper'
|
|
||||||
export * from './DdoHelpers'
|
|
||||||
export * from './Constants'
|
export * from './Constants'
|
||||||
|
export * from './ContractUtils'
|
||||||
|
export * from './ConversionTypeHelper'
|
||||||
|
export * from './DatatokenName'
|
||||||
|
export * from './DdoHelpers'
|
||||||
|
export * from './FetchHelper'
|
||||||
|
export * from './General'
|
||||||
|
export * from './Logger'
|
||||||
|
export * from './minAbi'
|
||||||
|
export * from './PoolHelpers'
|
||||||
export * from './SignatureUtils'
|
export * from './SignatureUtils'
|
||||||
export * from './TokenUtils'
|
export * from './TokenUtils'
|
||||||
export * from './General'
|
|
||||||
export * from './PoolHelpers'
|
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import { homedir } from 'os'
|
import { homedir } from 'os'
|
||||||
import {
|
import { ConfigHelper, configHelperNetworks } from '../src/config'
|
||||||
ConfigHelper,
|
import { LoggerInstance, LogLevel } from '../src/utils'
|
||||||
configHelperNetworks,
|
|
||||||
LoggerInstance,
|
|
||||||
LogLevel
|
|
||||||
} from '../src/utils'
|
|
||||||
|
|
||||||
LoggerInstance.setLevel(LogLevel.Error)
|
LoggerInstance.setLevel(LogLevel.Error)
|
||||||
|
|
||||||
|
@ -614,7 +614,7 @@ describe('Marketplace flow tests', async () => {
|
|||||||
|
|
||||||
it('7.3 Marketplace displays fixed rate asset for sale', async () => {
|
it('7.3 Marketplace displays fixed rate asset for sale', async () => {
|
||||||
/// ```Typescript
|
/// ```Typescript
|
||||||
const fixedRate = new FixedRateExchange(web3, freAddress)
|
const fixedRate = new FixedRateExchange(freAddress, web3)
|
||||||
const oceanAmount = await (
|
const oceanAmount = await (
|
||||||
await fixedRate.calcBaseInGivenOutDT(freId, '1')
|
await fixedRate.calcBaseInGivenOutDT(freId, '1')
|
||||||
).baseTokenAmount
|
).baseTokenAmount
|
||||||
@ -655,7 +655,7 @@ describe('Marketplace flow tests', async () => {
|
|||||||
DATATOKEN_AMOUNT
|
DATATOKEN_AMOUNT
|
||||||
)
|
)
|
||||||
|
|
||||||
const fixedRate = new FixedRateExchange(web3, freAddress)
|
const fixedRate = new FixedRateExchange(freAddress, web3)
|
||||||
/// ```
|
/// ```
|
||||||
/// Now we can make the contract call
|
/// Now we can make the contract call
|
||||||
/// ```Typescript
|
/// ```Typescript
|
||||||
@ -826,7 +826,7 @@ describe('Marketplace flow tests', async () => {
|
|||||||
it('8.3 Consumer gets a dispenser data asset, and downloads it', async () => {
|
it('8.3 Consumer gets a dispenser data asset, and downloads it', async () => {
|
||||||
/// ```Typescript
|
/// ```Typescript
|
||||||
const datatoken = new Datatoken(web3)
|
const datatoken = new Datatoken(web3)
|
||||||
const dispenser = new Dispenser(web3, null, addresses.Dispenser)
|
const dispenser = new Dispenser(addresses.Dispenser, web3)
|
||||||
|
|
||||||
let consumerDTBalance = await balance(
|
let consumerDTBalance = await balance(
|
||||||
web3,
|
web3,
|
||||||
|
@ -59,7 +59,7 @@ describe('Dispenser flow', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should initialize Dispenser class', async () => {
|
it('should initialize Dispenser class', async () => {
|
||||||
DispenserClass = new Dispenser(web3, 8996, contracts.dispenserAddress)
|
DispenserClass = new Dispenser(contracts.dispenserAddress, web3, 8996)
|
||||||
assert(DispenserClass !== null)
|
assert(DispenserClass !== null)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -100,13 +100,7 @@ describe('Fixed Rate unit test', () => {
|
|||||||
// user1 has no dt1
|
// user1 has no dt1
|
||||||
expect(await balance(web3, dtAddress, user1)).to.equal('0')
|
expect(await balance(web3, dtAddress, user1)).to.equal('0')
|
||||||
|
|
||||||
fixedRate = new FixedRateExchange(
|
fixedRate = new FixedRateExchange(contracts.fixedRateAddress, web3, 8996)
|
||||||
web3,
|
|
||||||
contracts.fixedRateAddress,
|
|
||||||
8996,
|
|
||||||
null,
|
|
||||||
contracts.oceanAddress
|
|
||||||
)
|
|
||||||
assert(fixedRate != null)
|
assert(fixedRate != null)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -415,13 +409,7 @@ describe('Fixed Rate unit test', () => {
|
|||||||
// user1 has no dt1
|
// user1 has no dt1
|
||||||
expect(await balance(web3, dtAddress, user1)).to.equal('0')
|
expect(await balance(web3, dtAddress, user1)).to.equal('0')
|
||||||
|
|
||||||
fixedRate = new FixedRateExchange(
|
fixedRate = new FixedRateExchange(contracts.fixedRateAddress, web3, 8996)
|
||||||
web3,
|
|
||||||
contracts.fixedRateAddress,
|
|
||||||
8996,
|
|
||||||
null,
|
|
||||||
contracts.oceanAddress
|
|
||||||
)
|
|
||||||
assert(fixedRate != null)
|
assert(fixedRate != null)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user