1
0
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:
Miquel A. Cabot 2022-06-06 18:33:04 +02:00 committed by GitHub
commit 153baef87f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
53 changed files with 726 additions and 1016 deletions

View File

@ -1,4 +1,4 @@
import { DDO } from './DDO/DDO'
import { DDO } from '.'
export interface AssetNft {
/**

View File

@ -1,4 +1,4 @@
import { Metadata, MetadataAlgorithm } from './DDO/Metadata'
import { Metadata, MetadataAlgorithm } from '.'
export type ComputeResultType =
| 'algorithmLog'

View File

@ -1,7 +1,4 @@
import { Service } from './Service'
import { Metadata } from './Metadata'
import { Credentials } from './Credentials'
import { Event } from './Event'
import { Service, Metadata, Credentials, Event } from '..'
/**
* DID Descriptor Object.

View File

@ -5,3 +5,13 @@ export interface DispenserCreationParams {
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 interface DispenserToken {
active: boolean
owner: string
maxTokens: string
maxBalance: string
balance: string
isMinter: boolean
allowedSwapper: string
}

View File

@ -1,3 +1,5 @@
import { ProviderFees } from '.'
export interface Erc20CreateParams {
templateIndex: number
minter: string
@ -21,3 +23,22 @@ export interface PublishingMarketFee {
publishMarketFeeToken: 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
}

View File

@ -11,3 +11,10 @@ export interface MetadataAndTokenURI {
tokenURI: string
metadataProofs?: MetadataProof[]
}
export interface NftRoles {
manager: boolean
deployERC20: boolean
updateMetadata: boolean
store: boolean
}

View File

@ -25,3 +25,29 @@ export interface PriceAndFees {
marketFeeAmount: 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
View 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
}

View File

@ -26,3 +26,12 @@ export interface ProviderComputeInitializeResults {
algorithm?: ProviderComputeInitialize
datasets?: ProviderComputeInitialize[]
}
export interface ServiceEndpoint {
serviceName: string
method: string
urlPath: string
}
export interface UserCustomParameters {
[key: string]: any
}

View File

@ -1,14 +1,17 @@
export * from './DDO/DDO'
export * from './Asset'
export * from './DDO/Service'
export * from './DDO/Credentials'
export * from './DDO/DDO'
export * from './DDO/Event'
export * from './DDO/Metadata'
export * from './FileMetadata'
export * from './DDO/Service'
export * from './Asset'
export * from './Compute'
export * from './Provider'
export * from './FixedPrice'
export * from './Pool'
export * from './Dispenser'
export * from './DownloadResponse'
export * from './Erc20'
export * from './Erc721'
export * from './Dispenser'
export * from './FileMetadata'
export * from './FixedPrice'
export * from './NFTFactory'
export * from './Pool'
export * from './Provider'
export * from './Router'

View File

@ -1,5 +1,5 @@
import { LogLevel } from '../utils/Logger'
import { AbiItem } from 'web3-utils/types'
import { LogLevel } from '../utils'
export class Config {
/**
@ -195,5 +195,3 @@ export class Config {
*/
gasFeeMultiplier: number
}
export default Config

View File

@ -1,7 +1,7 @@
import Config from '../models/Config'
// eslint-disable-next-line import/no-named-default
import { default as DefaultContractsAddresses } from '@oceanprotocol/contracts/addresses/address.json'
import LoggerInstance from './Logger'
import { Config } from '.'
import { LoggerInstance } from '../utils'
const configHelperNetworksBase: Config = {
chainId: null,

2
src/config/index.ts Normal file
View File

@ -0,0 +1,2 @@
export * from './Config'
export * from './ConfigHelper'

View 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)
}
}

View 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
)
}
}

View File

@ -1,8 +1,7 @@
import { Contract } from 'web3-eth-contract'
import Web3 from 'web3'
import { TransactionReceipt } from 'web3-core'
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 {
LoggerInstance,
getFairGasPrice,
@ -10,74 +9,26 @@ import {
getFreCreationParams,
getErcCreationParams,
getPoolCreationParams,
setContractDefaults,
estimateGas,
ZERO_ADDRESS,
ConfigHelper
} from '../utils'
import { Config } from '../models/index.js'
ZERO_ADDRESS
} from '../../utils'
import {
ProviderFees,
FreCreationParams,
Erc20CreateParams,
PoolCreationParams,
DispenserCreationParams,
ConsumeMarketFee
} from '../@types/index.js'
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
}
NftCreateData,
Template,
TokenOrder
} from '../../@types'
import { SmartContractWithAddress } from '..'
/**
* Provides an interface for NFT Factory contract
*/
export class NftFactory {
public factory721Address: string
public factory721Abi: AbiItem | 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
)
export class NftFactory extends SmartContractWithAddress {
getDefaultAbi(): AbiItem | AbiItem[] {
return ERC721Factory.abi as AbiItem[]
}
/**
@ -89,7 +40,7 @@ export class NftFactory {
public async estGasCreateNFT(address: string, nftData: NftCreateData): Promise<string> {
return estimateGas(
address,
this.factory721.methods.deployERC721Contract,
this.contract.methods.deployERC721Contract,
nftData.name,
nftData.symbol,
nftData.templateIndex,
@ -127,7 +78,7 @@ export class NftFactory {
}
const estGas = await estimateGas(
address,
this.factory721.methods.deployERC721Contract,
this.contract.methods.deployERC721Contract,
nftData.name,
nftData.symbol,
nftData.templateIndex,
@ -139,7 +90,7 @@ export class NftFactory {
)
// Invoke createToken function of the contract
const trxReceipt = await this.factory721.methods
const trxReceipt = await this.contract.methods
.deployERC721Contract(
nftData.name,
nftData.symbol,
@ -169,7 +120,7 @@ export class NftFactory {
* @return {Promise<number>} Number of NFT created from this factory
*/
public async getCurrentNFTCount(): Promise<number> {
const trxReceipt = await this.factory721.methods.getCurrentNFTCount().call()
const trxReceipt = await this.contract.methods.getCurrentNFTCount().call()
return trxReceipt
}
@ -177,7 +128,7 @@ export class NftFactory {
* @return {Promise<number>} Number of DTs created from this factory
*/
public async getCurrentTokenCount(): Promise<number> {
const trxReceipt = await this.factory721.methods.getCurrentTokenCount().call()
const trxReceipt = await this.contract.methods.getCurrentTokenCount().call()
return trxReceipt
}
@ -185,7 +136,7 @@ export class NftFactory {
* @return {Promise<string>} Factory Owner address
*/
public async getOwner(): Promise<string> {
const trxReceipt = await this.factory721.methods.owner().call()
const trxReceipt = await this.contract.methods.owner().call()
return trxReceipt
}
@ -193,7 +144,7 @@ export class NftFactory {
* @return {Promise<number>} Number of NFT Template added to this factory
*/
public async getCurrentNFTTemplateCount(): Promise<number> {
const count = await this.factory721.methods.getCurrentNFTTemplateCount().call()
const count = await this.contract.methods.getCurrentNFTTemplateCount().call()
return count
}
@ -201,7 +152,7 @@ export class NftFactory {
* @return {Promise<number>} Number of ERC20 Template added to this factory
*/
public async getCurrentTokenTemplateCount(): Promise<number> {
const count = await this.factory721.methods.getCurrentTemplateCount().call()
const count = await this.contract.methods.getCurrentTemplateCount().call()
return count
}
@ -217,7 +168,7 @@ export class NftFactory {
if (index === 0) {
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
}
@ -226,7 +177,7 @@ export class NftFactory {
* @return {Promise<Template>} DT Template info
*/
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
}
@ -235,7 +186,7 @@ export class NftFactory {
* @return {Promise<Boolean>} return true if deployed from this factory
*/
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
}
@ -244,7 +195,7 @@ export class NftFactory {
* @return {Promise<String>} return address(0) if it's not, or the nftAddress if true
*/
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
}
@ -260,7 +211,7 @@ export class NftFactory {
): Promise<any> {
return estimateGas(
address,
this.factory721.methods.add721TokenTemplate,
this.contract.methods.add721TokenTemplate,
templateAddress
)
}
@ -284,12 +235,12 @@ export class NftFactory {
const estGas = await estimateGas(
address,
this.factory721.methods.add721TokenTemplate,
this.contract.methods.add721TokenTemplate,
templateAddress
)
// Invoke add721TokenTemplate function of the contract
const trxReceipt = await this.factory721.methods
const trxReceipt = await this.contract.methods
.add721TokenTemplate(templateAddress)
.send({
from: address,
@ -312,7 +263,7 @@ export class NftFactory {
): Promise<any> {
return estimateGas(
address,
this.factory721.methods.disable721TokenTemplate,
this.contract.methods.disable721TokenTemplate,
templateIndex
)
}
@ -339,12 +290,12 @@ export class NftFactory {
}
const estGas = await estimateGas(
address,
this.factory721.methods.disable721TokenTemplate,
this.contract.methods.disable721TokenTemplate,
templateIndex
)
// Invoke createToken function of the contract
const trxReceipt = await this.factory721.methods
const trxReceipt = await this.contract.methods
.disable721TokenTemplate(templateIndex)
.send({
from: address,
@ -367,7 +318,7 @@ export class NftFactory {
): Promise<any> {
return estimateGas(
address,
this.factory721.methods.reactivate721TokenTemplate,
this.contract.methods.reactivate721TokenTemplate,
templateIndex
)
}
@ -395,12 +346,12 @@ export class NftFactory {
const estGas = await estimateGas(
address,
this.factory721.methods.reactivate721TokenTemplate,
this.contract.methods.reactivate721TokenTemplate,
templateIndex
)
// Invoke createToken function of the contract
const trxReceipt = await this.factory721.methods
const trxReceipt = await this.contract.methods
.reactivate721TokenTemplate(templateIndex)
.send({
from: address,
@ -421,7 +372,7 @@ export class NftFactory {
address: string,
templateAddress: string
): 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(
address,
this.factory721.methods.addTokenTemplate,
this.contract.methods.addTokenTemplate,
templateAddress
)
// Invoke createToken function of the contract
const trxReceipt = await this.factory721.methods
const trxReceipt = await this.contract.methods
.addTokenTemplate(templateAddress)
.send({
from: address,
@ -469,11 +420,7 @@ export class NftFactory {
address: string,
templateIndex: number
): Promise<any> {
return estimateGas(
address,
this.factory721.methods.disableTokenTemplate,
templateIndex
)
return estimateGas(address, this.contract.methods.disableTokenTemplate, templateIndex)
}
/**
@ -501,12 +448,12 @@ export class NftFactory {
}
const estGas = await estimateGas(
address,
this.factory721.methods.disableTokenTemplate,
this.contract.methods.disableTokenTemplate,
templateIndex
)
// Invoke createToken function of the contract
const trxReceipt = await this.factory721.methods
const trxReceipt = await this.contract.methods
.disableTokenTemplate(templateIndex)
.send({
from: address,
@ -529,7 +476,7 @@ export class NftFactory {
): Promise<any> {
return estimateGas(
address,
this.factory721.methods.reactivateTokenTemplate,
this.contract.methods.reactivateTokenTemplate,
templateIndex
)
}
@ -560,12 +507,12 @@ export class NftFactory {
const estGas = await estimateGas(
address,
this.factory721.methods.reactivateTokenTemplate,
this.contract.methods.reactivateTokenTemplate,
templateIndex
)
// Invoke createToken function of the contract
const trxReceipt = await this.factory721.methods
const trxReceipt = await this.contract.methods
.reactivateTokenTemplate(templateIndex)
.send({
from: address,
@ -585,7 +532,7 @@ export class NftFactory {
address: string,
orders: TokenOrder[]
): Promise<any> {
return estimateGas(address, this.factory721.methods.startMultipleTokenOrder, orders)
return estimateGas(address, this.contract.methods.startMultipleTokenOrder, orders)
}
/**
@ -610,18 +557,16 @@ export class NftFactory {
const estGas = await estimateGas(
address,
this.factory721.methods.startMultipleTokenOrder,
this.contract.methods.startMultipleTokenOrder,
orders
)
// Invoke createToken function of the contract
const trxReceipt = await this.factory721.methods
.startMultipleTokenOrder(orders)
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
const trxReceipt = await this.contract.methods.startMultipleTokenOrder(orders).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
return trxReceipt
}
@ -642,7 +587,7 @@ export class NftFactory {
const ercCreateData = getErcCreationParams(ercParams)
return estimateGas(
address,
this.factory721.methods.createNftWithErc20,
this.contract.methods.createNftWithErc20,
nftCreateData,
ercCreateData
)
@ -666,13 +611,13 @@ export class NftFactory {
const estGas = await estimateGas(
address,
this.factory721.methods.createNftWithErc20,
this.contract.methods.createNftWithErc20,
nftCreateData,
ercCreateData
)
// Invoke createToken function of the contract
const trxReceipt = await this.factory721.methods
const trxReceipt = await this.contract.methods
.createNftWithErc20(nftCreateData, ercCreateData)
.send({
from: address,
@ -701,7 +646,7 @@ export class NftFactory {
const poolData = await getPoolCreationParams(this.web3, poolParams)
return estimateGas(
address,
this.factory721.methods.createNftWithErc20WithPool,
this.contract.methods.createNftWithErc20WithPool,
nftCreateData,
ercCreateData,
poolData
@ -729,14 +674,14 @@ export class NftFactory {
const estGas = await estimateGas(
address,
this.factory721.methods.createNftWithErc20WithPool,
this.contract.methods.createNftWithErc20WithPool,
nftCreateData,
ercCreateData,
poolData
)
// Invoke createToken function of the contract
const trxReceipt = await this.factory721.methods
const trxReceipt = await this.contract.methods
.createNftWithErc20WithPool(nftCreateData, ercCreateData, poolData)
.send({
from: address,
@ -764,7 +709,7 @@ export class NftFactory {
const fixedData = await getFreCreationParams(freParams)
return estimateGas(
address,
this.factory721.methods.createNftWithErc20WithFixedRate,
this.contract.methods.createNftWithErc20WithFixedRate,
nftCreateData,
ercCreateData,
fixedData
@ -792,14 +737,14 @@ export class NftFactory {
const estGas = await estimateGas(
address,
this.factory721.methods.createNftWithErc20WithFixedRate,
this.contract.methods.createNftWithErc20WithFixedRate,
nftCreateData,
ercCreateData,
fixedData
)
// Invoke createToken function of the contract
const trxReceipt = await this.factory721.methods
const trxReceipt = await this.contract.methods
.createNftWithErc20WithFixedRate(nftCreateData, ercCreateData, fixedData)
.send({
from: address,
@ -826,7 +771,7 @@ export class NftFactory {
const ercCreateData = getErcCreationParams(ercParams)
return estimateGas(
address,
this.factory721.methods.createNftWithErc20WithDispenser,
this.contract.methods.createNftWithErc20WithDispenser,
nftCreateData,
ercCreateData,
dispenserParams
@ -856,14 +801,14 @@ export class NftFactory {
const estGas = await estimateGas(
address,
this.factory721.methods.createNftWithErc20WithDispenser,
this.contract.methods.createNftWithErc20WithDispenser,
nftCreateData,
ercCreateData,
dispenserParams
)
// Invoke createToken function of the contract
const trxReceipt = await this.factory721.methods
const trxReceipt = await this.contract.methods
.createNftWithErc20WithDispenser(nftCreateData, ercCreateData, dispenserParams)
.send({
from: address,

10
src/contracts/index.ts Normal file
View 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'

View File

@ -1,58 +1,14 @@
import Web3 from 'web3'
import { AbiItem } from 'web3-utils'
import { Contract } from 'web3-eth-contract'
import { TransactionReceipt } from 'web3-eth'
import Decimal from 'decimal.js'
import defaultDispenserAbi from '@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json'
import {
LoggerInstance as logger,
getFairGasPrice,
setContractDefaults,
estimateGas,
ConfigHelper
} from '../../utils/'
import { Datatoken } from '../../tokens'
import { Config } from '../../models/index.js'
import DispenserAbi from '@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json'
import { LoggerInstance, getFairGasPrice, estimateGas } from '../../utils/'
import { Datatoken, SmartContractWithAddress } from '..'
import { DispenserToken } from '../../@types'
export interface DispenserToken {
active: boolean
owner: string
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
)
export class Dispenser extends SmartContractWithAddress {
getDefaultAbi(): AbiItem | AbiItem[] {
return DispenserAbi.abi as AbiItem[]
}
/**
@ -62,15 +18,13 @@ export class Dispenser {
*/
public async status(dtAdress: string): Promise<DispenserToken> {
try {
const result: DispenserToken = await this.dispenserContract.methods
.status(dtAdress)
.call()
const result: DispenserToken = await this.contract.methods.status(dtAdress).call()
result.maxTokens = this.web3.utils.fromWei(result.maxTokens)
result.maxBalance = this.web3.utils.fromWei(result.maxBalance)
result.balance = this.web3.utils.fromWei(result.balance)
return result
} catch (e) {
logger.warn(`No dispenser available for datatoken: ${dtAdress}`)
LoggerInstance.warn(`No dispenser available for datatoken: ${dtAdress}`)
}
return null
}
@ -93,7 +47,7 @@ export class Dispenser {
): Promise<any> {
return estimateGas(
address,
this.dispenserContract.methods.create,
this.contract.methods.create,
dtAddress,
this.web3.utils.toWei(maxTokens),
this.web3.utils.toWei(maxBalance),
@ -120,7 +74,7 @@ export class Dispenser {
): Promise<TransactionReceipt> {
const estGas = await estimateGas(
address,
this.dispenserContract.methods.create,
this.contract.methods.create,
dtAddress,
this.web3.utils.toWei(maxTokens),
this.web3.utils.toWei(maxBalance),
@ -129,7 +83,7 @@ export class Dispenser {
)
// Call createFixedRate contract method
const trxReceipt = await this.dispenserContract.methods
const trxReceipt = await this.contract.methods
.create(
dtAddress,
this.web3.utils.toWei(maxTokens),
@ -161,7 +115,7 @@ export class Dispenser {
): Promise<any> {
return estimateGas(
address,
this.dispenserContract.methods.activate,
this.contract.methods.activate,
dtAddress,
this.web3.utils.toWei(maxTokens),
this.web3.utils.toWei(maxBalance)
@ -185,13 +139,13 @@ export class Dispenser {
try {
const estGas = await estimateGas(
address,
this.dispenserContract.methods.activate,
this.contract.methods.activate,
dtAddress,
this.web3.utils.toWei(maxTokens),
this.web3.utils.toWei(maxBalance)
)
const trxReceipt = await this.dispenserContract.methods
const trxReceipt = await this.contract.methods
.activate(
dtAddress,
this.web3.utils.toWei(maxTokens),
@ -204,7 +158,7 @@ export class Dispenser {
})
return trxReceipt
} catch (e) {
logger.error(`ERROR: Failed to activate dispenser: ${e.message}`)
LoggerInstance.error(`ERROR: Failed to activate dispenser: ${e.message}`)
}
return null
}
@ -216,7 +170,7 @@ export class Dispenser {
* @return {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 {
const estGas = await estimateGas(
address,
this.dispenserContract.methods.deactivate,
this.contract.methods.deactivate,
dtAddress
)
const trxReceipt = await this.dispenserContract.methods.deactivate(dtAddress).send({
const trxReceipt = await this.contract.methods.deactivate(dtAddress).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
return trxReceipt
} catch (e) {
logger.error(`ERROR: Failed to activate dispenser: ${e.message}`)
LoggerInstance.error(`ERROR: Failed to activate dispenser: ${e.message}`)
}
return null
}
@ -262,7 +216,7 @@ export class Dispenser {
): Promise<any> {
return estimateGas(
address,
this.dispenserContract.methods.setAllowedSwapper,
this.contract.methods.setAllowedSwapper,
dtAddress,
newAllowedSwapper
)
@ -283,12 +237,12 @@ export class Dispenser {
try {
const estGas = await estimateGas(
address,
this.dispenserContract.methods.setAllowedSwapper,
this.contract.methods.setAllowedSwapper,
dtAddress,
newAllowedSwapper
)
const trxReceipt = await this.dispenserContract.methods
const trxReceipt = await this.contract.methods
.setAllowedSwapper(dtAddress, newAllowedSwapper)
.send({
from: address,
@ -297,7 +251,7 @@ export class Dispenser {
})
return trxReceipt
} catch (e) {
logger.error(`ERROR: Failed to activate dispenser: ${e.message}`)
LoggerInstance.error(`ERROR: Failed to activate dispenser: ${e.message}`)
}
return null
}
@ -317,7 +271,7 @@ export class Dispenser {
): Promise<any> {
return estimateGas(
address,
this.dispenserContract.methods.dispense,
this.contract.methods.dispense,
dtAddress,
this.web3.utils.toWei(amount),
destination
@ -342,14 +296,14 @@ export class Dispenser {
): Promise<TransactionReceipt> {
const estGas = await estimateGas(
address,
this.dispenserContract.methods.dispense,
this.contract.methods.dispense,
dtAddress,
this.web3.utils.toWei(amount),
destination
)
try {
const trxReceipt = await this.dispenserContract.methods
const trxReceipt = await this.contract.methods
.dispense(dtAddress, this.web3.utils.toWei(amount), destination)
.send({
from: address,
@ -358,7 +312,7 @@ export class Dispenser {
})
return trxReceipt
} catch (e) {
logger.error(`ERROR: Failed to dispense tokens: ${e.message}`)
LoggerInstance.error(`ERROR: Failed to dispense tokens: ${e.message}`)
}
return null
}
@ -371,7 +325,7 @@ export class Dispenser {
* @return {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> {
const estGas = await estimateGas(
address,
this.dispenserContract.methods.ownerWithdraw,
this.contract.methods.ownerWithdraw,
dtAddress
)
try {
const trxReceipt = await this.dispenserContract.methods
.ownerWithdraw(dtAddress)
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
const trxReceipt = await this.contract.methods.ownerWithdraw(dtAddress).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
return trxReceipt
} catch (e) {
logger.error(`ERROR: Failed to withdraw tokens: ${e.message}`)
LoggerInstance.error(`ERROR: Failed to withdraw tokens: ${e.message}`)
}
return null
}

View File

@ -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 { Contract } from 'web3-eth-contract'
import { AbiItem } from 'web3-utils/types'
import Web3 from 'web3'
import {
LoggerInstance,
getFairGasPrice,
setContractDefaults,
amountToUnits,
unitsToAmount,
estimateGas,
ZERO_ADDRESS,
ConfigHelper
} from '../../utils'
import { Config } from '../../models/index.js'
import { PriceAndFees } from '../..'
import { LoggerInstance, getFairGasPrice, estimateGas, ZERO_ADDRESS } from '../../utils'
import { PriceAndFees, FeesInfo, FixedPriceExchange } from '../../@types'
import { SmartContractWithAddress } from '..'
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
}
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)
export class FixedRateExchange extends SmartContractWithAddress {
getDefaultAbi(): AbiItem | AbiItem[] {
return FixedRateExchangeAbi.abi as AbiItem[]
}
/**
@ -114,7 +18,7 @@ export class FixedRateExchange {
* @return {Promise<string>} exchangeId
*/
public async generateExchangeId(baseToken: string, datatoken: string): Promise<string> {
const exchangeId = await this.fixedRateContract.methods
const exchangeId = await this.contract.methods
.generateExchangeId(baseToken, datatoken)
.call()
return exchangeId
@ -139,7 +43,7 @@ export class FixedRateExchange {
consumeMarketFee: string,
contractInstance?: Contract
): Promise<number> {
const fixedRate = contractInstance || this.fixedRateContract
const fixedRate = contractInstance || this.contract
return estimateGas(
account,
@ -185,7 +89,7 @@ export class FixedRateExchange {
const estGas = await estimateGas(
address,
this.fixedRateContract.methods.buyDT,
this.contract.methods.buyDT,
exchangeId,
dtAmountFormatted,
maxBtFormatted,
@ -193,7 +97,7 @@ export class FixedRateExchange {
consumeMarketFeeFormatted
)
try {
const trxReceipt = await this.fixedRateContract.methods
const trxReceipt = await this.contract.methods
.buyDT(
exchangeId,
dtAmountFormatted,
@ -232,7 +136,7 @@ export class FixedRateExchange {
consumeMarketFee: string,
contractInstance?: Contract
): Promise<number> {
const fixedRate = contractInstance || this.fixedRateContract
const fixedRate = contractInstance || this.contract
return estimateGas(
account,
@ -277,7 +181,7 @@ export class FixedRateExchange {
)
const estGas = await estimateGas(
address,
this.fixedRateContract.methods.sellDT,
this.contract.methods.sellDT,
exchangeId,
dtAmountFormatted,
minBtFormatted,
@ -285,7 +189,7 @@ export class FixedRateExchange {
consumeMarketFeeFormatted
)
try {
const trxReceipt = await this.fixedRateContract.methods
const trxReceipt = await this.contract.methods
.sellDT(
exchangeId,
dtAmountFormatted,
@ -312,9 +216,7 @@ export class FixedRateExchange {
* @return {Promise<Number>} no of available exchanges
*/
public async getNumberOfExchanges(): Promise<number> {
const numExchanges = await this.fixedRateContract.methods
.getNumberOfExchanges()
.call()
const numExchanges = await this.contract.methods.getNumberOfExchanges().call()
return numExchanges
}
@ -332,7 +234,7 @@ export class FixedRateExchange {
newRate: string,
contractInstance?: Contract
): Promise<number> {
const fixedRate = contractInstance || this.fixedRateContract
const fixedRate = contractInstance || this.contract
return estimateGas(
account,
@ -356,11 +258,11 @@ export class FixedRateExchange {
): Promise<TransactionReceipt> {
const estGas = await estimateGas(
address,
this.fixedRateContract.methods.setRate,
this.contract.methods.setRate,
exchangeId,
this.web3.utils.toWei(newRate)
)
const trxReceipt = await this.fixedRateContract.methods
const trxReceipt = await this.contract.methods
.setRate(exchangeId, this.web3.utils.toWei(newRate))
.send({
from: address,
@ -384,7 +286,7 @@ export class FixedRateExchange {
newAllowedSwapper: string,
contractInstance?: Contract
): Promise<number> {
const fixedRate = contractInstance || this.fixedRateContract
const fixedRate = contractInstance || this.contract
return estimateGas(
account,
@ -408,11 +310,11 @@ export class FixedRateExchange {
): Promise<TransactionReceipt> {
const estGas = await estimateGas(
address,
this.fixedRateContract.methods.setAllowedSwapper,
this.contract.methods.setAllowedSwapper,
exchangeId,
newAllowedSwapper
)
const trxReceipt = await this.fixedRateContract.methods
const trxReceipt = await this.contract.methods
.setAllowedSwapper(exchangeId, newAllowedSwapper)
.send({
from: address,
@ -434,7 +336,7 @@ export class FixedRateExchange {
exchangeId: string,
contractInstance?: Contract
): Promise<number> {
const fixedRate = contractInstance || this.fixedRateContract
const fixedRate = contractInstance || this.contract
return estimateGas(account, fixedRate.methods.toggleExchangeState, exchangeId)
}
@ -454,16 +356,14 @@ export class FixedRateExchange {
if (exchange.active === true) return null
const estGas = await estimateGas(
address,
this.fixedRateContract.methods.toggleExchangeState,
this.contract.methods.toggleExchangeState,
exchangeId
)
const trxReceipt = await this.fixedRateContract.methods
.toggleExchangeState(exchangeId)
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
const trxReceipt = await this.contract.methods.toggleExchangeState(exchangeId).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
return trxReceipt
}
@ -479,7 +379,7 @@ export class FixedRateExchange {
exchangeId: string,
contractInstance?: Contract
): Promise<number> {
const fixedRate = contractInstance || this.fixedRateContract
const fixedRate = contractInstance || this.contract
return estimateGas(account, fixedRate.methods.toggleExchangeState, exchangeId)
}
@ -500,17 +400,15 @@ export class FixedRateExchange {
const estGas = await estimateGas(
address,
this.fixedRateContract.methods.toggleExchangeState,
this.contract.methods.toggleExchangeState,
exchangeId
)
const trxReceipt = await this.fixedRateContract.methods
.toggleExchangeState(exchangeId)
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
const trxReceipt = await this.contract.methods.toggleExchangeState(exchangeId).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
return trxReceipt
}
@ -521,7 +419,7 @@ export class FixedRateExchange {
* @return {Promise<string>} Rate (converted from wei)
*/
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)
return rate
}
@ -532,7 +430,7 @@ export class FixedRateExchange {
* @return {Promise<string>} dt supply formatted
*/
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)
return await this.unitsToAmount(exchange.datatoken, dtSupply, +exchange.dtDecimals)
}
@ -543,7 +441,7 @@ export class FixedRateExchange {
* @return {Promise<string>} dt supply formatted
*/
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)
return await this.unitsToAmount(exchange.baseToken, btSupply, +exchange.btDecimals)
}
@ -554,7 +452,7 @@ export class FixedRateExchange {
* @return {Promise<string>} address of allowedSwapper
*/
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'
): Promise<PriceAndFees> {
const fixedRateExchange = await this.getExchange(exchangeId)
const result = await this.fixedRateContract.methods
const result = await this.contract.methods
.calcBaseInGivenOutDT(
exchangeId,
await this.amountToUnits(
@ -620,7 +518,7 @@ export class FixedRateExchange {
consumeMarketFee: string = '0'
): Promise<string> {
const exchange = await this.getExchange(exchangeId)
const result = await this.fixedRateContract.methods
const result = await this.contract.methods
.calcBaseOutGivenInDT(
exchangeId,
await this.amountToUnits(
@ -641,7 +539,7 @@ export class FixedRateExchange {
* @return {Promise<FixedPricedExchange>} Exchange details
*/
public async getExchange(exchangeId: string): Promise<FixedPriceExchange> {
const result: FixedPriceExchange = await this.fixedRateContract.methods
const result: FixedPriceExchange = await this.contract.methods
.getExchange(exchangeId)
.call()
result.dtDecimals = result.dtDecimals.toString()
@ -677,9 +575,7 @@ export class FixedRateExchange {
* @return {Promise<FixedPricedExchange>} Exchange details
*/
public async getFeesInfo(exchangeId: string): Promise<FeesInfo> {
const result: FeesInfo = await this.fixedRateContract.methods
.getFeesInfo(exchangeId)
.call()
const result: FeesInfo = await this.contract.methods.getFeesInfo(exchangeId).call()
result.opcFee = this.web3.utils.fromWei(result.opcFee.toString())
result.marketFee = this.web3.utils.fromWei(result.marketFee.toString())
@ -705,7 +601,7 @@ export class FixedRateExchange {
* @return {Promise<String[]>} Exchanges list
*/
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
*/
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
}
@ -730,7 +626,7 @@ export class FixedRateExchange {
exchangeId: string,
contractInstance?: Contract
): Promise<number> {
const fixedRate = contractInstance || this.fixedRateContract
const fixedRate = contractInstance || this.contract
return estimateGas(account, fixedRate.methods.toggleMintState, exchangeId, true)
}
@ -751,11 +647,11 @@ export class FixedRateExchange {
const estGas = await estimateGas(
address,
this.fixedRateContract.methods.toggleMintState,
this.contract.methods.toggleMintState,
exchangeId,
true
)
const trxReceipt = await this.fixedRateContract.methods
const trxReceipt = await this.contract.methods
.toggleMintState(exchangeId, true)
.send({
from: address,
@ -777,7 +673,7 @@ export class FixedRateExchange {
exchangeId: string,
contractInstance?: Contract
): Promise<number> {
const fixedRate = contractInstance || this.fixedRateContract
const fixedRate = contractInstance || this.contract
return estimateGas(
account,
@ -803,12 +699,12 @@ export class FixedRateExchange {
const estGas = await estimateGas(
address,
this.fixedRateContract.methods.toggleMintState,
this.contract.methods.toggleMintState,
exchangeId,
false
)
const trxReceipt = await this.fixedRateContract.methods
const trxReceipt = await this.contract.methods
.toggleMintState(exchangeId, false)
.send({
from: address,
@ -833,8 +729,8 @@ export class FixedRateExchange {
amount: string,
contractInstance?: Contract
): Promise<number> {
const fixedRate = contractInstance || this.fixedRateContract
const fixedrate: FixedPriceExchange = await this.fixedRateContract.methods
const fixedRate = contractInstance || this.contract
const fixedrate: FixedPriceExchange = await this.contract.methods
.getExchange(exchangeId)
.call()
const amountWei = await this.amountToUnits(
@ -860,7 +756,7 @@ export class FixedRateExchange {
const exchange = await this.getExchange(exchangeId)
if (!exchange) return null
const fixedrate: FixedPriceExchange = await this.fixedRateContract.methods
const fixedrate: FixedPriceExchange = await this.contract.methods
.getExchange(exchangeId)
.call()
const amountWei = await this.amountToUnits(
@ -871,18 +767,16 @@ export class FixedRateExchange {
const estGas = await estimateGas(
address,
this.fixedRateContract.methods.collectBT,
this.contract.methods.collectBT,
exchangeId,
amountWei
)
const trxReceipt = await this.fixedRateContract.methods
.collectBT(exchangeId, amountWei)
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
const trxReceipt = await this.contract.methods.collectBT(exchangeId, amountWei).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
return trxReceipt
}
@ -900,8 +794,8 @@ export class FixedRateExchange {
amount: string,
contractInstance?: Contract
): Promise<number> {
const fixedRate = contractInstance || this.fixedRateContract
const fixedrate: FixedPriceExchange = await this.fixedRateContract.methods
const fixedRate = contractInstance || this.contract
const fixedrate: FixedPriceExchange = await this.contract.methods
.getExchange(exchangeId)
.call()
@ -928,7 +822,7 @@ export class FixedRateExchange {
const exchange = await this.getExchange(exchangeId)
if (!exchange) return null
const fixedrate: FixedPriceExchange = await this.fixedRateContract.methods
const fixedrate: FixedPriceExchange = await this.contract.methods
.getExchange(exchangeId)
.call()
const amountWei = await this.amountToUnits(
@ -939,18 +833,16 @@ export class FixedRateExchange {
const estGas = await estimateGas(
address,
this.fixedRateContract.methods.collectDT,
this.contract.methods.collectDT,
exchangeId,
amountWei
)
const trxReceipt = await this.fixedRateContract.methods
.collectDT(exchangeId, amountWei)
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
const trxReceipt = await this.contract.methods.collectDT(exchangeId, amountWei).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
return trxReceipt
}
@ -966,7 +858,7 @@ export class FixedRateExchange {
exchangeId: string,
contractInstance?: Contract
): Promise<number> {
const fixedRate = contractInstance || this.fixedRateContract
const fixedRate = contractInstance || this.contract
return estimateGas(account, fixedRate.methods.collectMarketFee, exchangeId)
}
@ -986,16 +878,14 @@ export class FixedRateExchange {
const estGas = await estimateGas(
address,
this.fixedRateContract.methods.collectMarketFee,
this.contract.methods.collectMarketFee,
exchangeId
)
const trxReceipt = await this.fixedRateContract.methods
.collectMarketFee(exchangeId)
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
const trxReceipt = await this.contract.methods.collectMarketFee(exchangeId).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
return trxReceipt
}
@ -1011,7 +901,7 @@ export class FixedRateExchange {
exchangeId: string,
contractInstance?: Contract
): Promise<number> {
const fixedRate = contractInstance || this.fixedRateContract
const fixedRate = contractInstance || this.contract
return estimateGas(account, fixedRate.methods.collectMarketFee, exchangeId)
}
@ -1031,16 +921,14 @@ export class FixedRateExchange {
const estGas = await estimateGas(
address,
this.fixedRateContract.methods.collectOceanFee,
this.contract.methods.collectOceanFee,
exchangeId
)
const trxReceipt = await this.fixedRateContract.methods
.collectOceanFee(exchangeId)
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
const trxReceipt = await this.contract.methods.collectOceanFee(exchangeId).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
return trxReceipt
}
@ -1051,7 +939,7 @@ export class FixedRateExchange {
async getOPCCollector(): Promise<string> {
let result = null
try {
result = await this.fixedRateContract.methods.opcCollector().call()
result = await this.contract.methods.opcCollector().call()
} catch (e) {
LoggerInstance.error(`ERROR: Failed to get OPC Collector address: ${e.message}`)
}
@ -1065,7 +953,7 @@ export class FixedRateExchange {
async getRouter(): Promise<string> {
let result = null
try {
result = await this.fixedRateContract.methods.router().call()
result = await this.contract.methods.router().call()
} catch (e) {
LoggerInstance.error(`ERROR: Failed to get Router address: ${e.message}`)
}
@ -1101,7 +989,7 @@ export class FixedRateExchange {
newMarketFee: string,
contractInstance?: Contract
): Promise<number> {
const fixedRate = contractInstance || this.fixedRateContract
const fixedRate = contractInstance || this.contract
return estimateGas(
account,
@ -1125,11 +1013,11 @@ export class FixedRateExchange {
): Promise<TransactionReceipt> {
const estGas = await estimateGas(
address,
this.fixedRateContract.methods.updateMarketFee,
this.contract.methods.updateMarketFee,
exchangeId,
this.web3.utils.toWei(newMarketFee)
)
const trxReceipt = await this.fixedRateContract.methods
const trxReceipt = await this.contract.methods
.updateMarketFee(exchangeId, this.web3.utils.toWei(newMarketFee))
.send({
from: address,
@ -1153,7 +1041,7 @@ export class FixedRateExchange {
newMarketFeeCollector: string,
contractInstance?: Contract
): Promise<number> {
const fixedRate = contractInstance || this.fixedRateContract
const fixedRate = contractInstance || this.contract
return estimateGas(
account,
@ -1177,11 +1065,11 @@ export class FixedRateExchange {
): Promise<TransactionReceipt> {
const estGas = await estimateGas(
address,
this.fixedRateContract.methods.updateMarketFeeCollector,
this.contract.methods.updateMarketFeeCollector,
exchangeId,
newMarketFeeCollector
)
const trxReceipt = await this.fixedRateContract.methods
const trxReceipt = await this.contract.methods
.updateMarketFeeCollector(exchangeId, newMarketFeeCollector)
.send({
from: address,

View File

@ -1,19 +1,21 @@
import Web3 from 'web3'
import { AbiItem } from 'web3-utils/types'
import { TransactionReceipt } from 'web3-core'
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 {
getFairGasPrice,
setContractDefaults,
unitsToAmount,
amountToUnits,
LoggerInstance,
estimateGas,
ConfigHelper
getMaxAddLiquidity,
getMaxRemoveLiquidity,
getMaxSwapExactIn,
getMaxSwapExactOut,
MAX_UINT_256,
decimals
} 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 {
CurrentFees,
TokenInOutMarket,
@ -21,51 +23,14 @@ import {
AmountsOutMaxFee,
PoolPriceAndFees
} from '../../@types'
import { Config } from '../../models'
import {
getMaxAddLiquidity,
getMaxRemoveLiquidity,
getMaxSwapExactIn,
getMaxSwapExactOut
} from '../../utils/PoolHelpers'
import Decimal from 'decimal.js'
const MaxUint256 =
'115792089237316195423570985008687907853269984665640564039457584007913129639934'
import { SmartContract } from '..'
/**
* Provides an interface to Ocean friendly fork from Balancer BPool
*/
export class Pool {
public poolAbi: AbiItem | AbiItem[]
public web3: Web3
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)
export class Pool extends SmartContract {
getDefaultAbi(): AbiItem | AbiItem[] {
return Bpool.abi as AbiItem[]
}
/**
@ -78,7 +43,7 @@ export class Pool {
let result = null
try {
const token = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
const balance = await token.methods.balanceOf(account).call()
@ -108,7 +73,7 @@ export class Pool {
const poolContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(defaultErc20Abi.abi as AbiItem[], poolAddress),
new this.web3.eth.Contract(this.abi as AbiItem[], poolAddress),
this.config
)
@ -127,7 +92,7 @@ export class Pool {
fee: string
): Promise<TransactionReceipt> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress, {
new this.web3.eth.Contract(this.abi, poolAddress, {
from: account
}),
this.config
@ -154,7 +119,7 @@ export class Pool {
*/
async getNumTokens(poolAddress: string): Promise<string> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let result = null
@ -173,7 +138,7 @@ export class Pool {
*/
async getPoolSharesTotalSupply(poolAddress: string): Promise<string> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let amount = null
@ -196,7 +161,7 @@ export class Pool {
*/
async getCurrentTokens(poolAddress: string): Promise<string[]> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let result = null
@ -218,7 +183,7 @@ export class Pool {
*/
async getFinalTokens(poolAddress: string): Promise<string[]> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let result = null
@ -239,7 +204,7 @@ export class Pool {
*/
async getController(poolAddress: string): Promise<string> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let result = null
@ -258,7 +223,7 @@ export class Pool {
*/
async getBaseToken(poolAddress: string): Promise<string> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let result = null
@ -277,7 +242,7 @@ export class Pool {
*/
async getDatatoken(poolAddress: string): Promise<string> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let result = null
@ -296,7 +261,7 @@ export class Pool {
*/
async getMarketFee(poolAddress: string): Promise<string> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let result = null
@ -315,7 +280,7 @@ export class Pool {
*/
async getMarketFeeCollector(poolAddress: string): Promise<string> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let result = null
@ -338,7 +303,7 @@ export class Pool {
*/
async isBound(poolAddress: string, token: string): Promise<boolean> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let result = null
@ -366,7 +331,7 @@ export class Pool {
let amount = null
try {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
const result = await pool.methods.getBalance(token).call()
@ -386,7 +351,7 @@ export class Pool {
*/
async isFinalized(poolAddress: string): Promise<boolean> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let result = null
@ -407,7 +372,7 @@ export class Pool {
*/
async getSwapFee(poolAddress: string): Promise<string> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let fee = null
@ -430,7 +395,7 @@ export class Pool {
*/
async getNormalizedWeight(poolAddress: string, token: string): Promise<string> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let weight = null
@ -453,7 +418,7 @@ export class Pool {
*/
async getDenormalizedWeight(poolAddress: string, token: string): Promise<string> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let weight = null
@ -476,7 +441,7 @@ export class Pool {
*/
async getTotalDenormalizedWeight(poolAddress: string): Promise<string> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let weight = null
@ -505,7 +470,7 @@ export class Pool {
tokenDecimals?: number
): Promise<string> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let weight = null
@ -524,7 +489,7 @@ export class Pool {
*/
async getCurrentMarketFees(poolAddress: string): Promise<CurrentFees> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
try {
@ -543,7 +508,7 @@ export class Pool {
*/
async getCurrentOPCFees(poolAddress: string): Promise<CurrentFees> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
try {
@ -569,7 +534,7 @@ export class Pool {
tokenDecimals?: number
): Promise<string> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let weight = null
@ -599,7 +564,7 @@ export class Pool {
const poolContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.poolAbi as AbiItem[], poolAddress),
new this.web3.eth.Contract(this.abi as AbiItem[], poolAddress),
this.config
)
@ -614,7 +579,7 @@ export class Pool {
*/
async collectOPC(address: string, poolAddress: string): Promise<TransactionReceipt> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let result = null
@ -648,7 +613,7 @@ export class Pool {
const poolContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.poolAbi as AbiItem[], poolAddress),
new this.web3.eth.Contract(this.abi as AbiItem[], poolAddress),
this.config
)
@ -670,7 +635,7 @@ export class Pool {
throw new Error(`Caller is not MarketFeeCollector`)
}
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let result = null
@ -707,7 +672,7 @@ export class Pool {
const poolContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.poolAbi as AbiItem[], poolAddress),
new this.web3.eth.Contract(this.abi as AbiItem[], poolAddress),
this.config
)
@ -737,7 +702,7 @@ export class Pool {
throw new Error(`Caller is not MarketFeeCollector`)
}
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let result = null
@ -784,7 +749,7 @@ export class Pool {
const poolContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.poolAbi as AbiItem[], poolAddress),
new this.web3.eth.Contract(this.abi as AbiItem[], poolAddress),
this.config
)
@ -805,7 +770,7 @@ export class Pool {
await this.getBaseToken(poolAddress),
amountsInOutMaxFee.maxPrice
)
: MaxUint256
: MAX_UINT_256
return estimateGas(
address,
@ -844,7 +809,7 @@ export class Pool {
amountsInOutMaxFee: AmountsInMaxFee
): Promise<TransactionReceipt> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
@ -870,7 +835,7 @@ export class Pool {
await this.getBaseToken(poolAddress),
amountsInOutMaxFee.maxPrice
)
: MaxUint256
: MAX_UINT_256
const estGas = await estimateGas(
address,
@ -935,7 +900,7 @@ export class Pool {
const poolContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.poolAbi as AbiItem[], poolAddress),
new this.web3.eth.Contract(this.abi as AbiItem[], poolAddress),
this.config
)
@ -956,7 +921,7 @@ export class Pool {
await this.getBaseToken(poolAddress),
amountsInOutMaxFee.maxPrice
)
: MaxUint256
: MAX_UINT_256
return estimateGas(
address,
@ -990,7 +955,7 @@ export class Pool {
amountsInOutMaxFee: AmountsOutMaxFee
): Promise<TransactionReceipt> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let result = null
@ -1017,7 +982,7 @@ export class Pool {
await this.getBaseToken(poolAddress),
amountsInOutMaxFee.maxPrice
)
: MaxUint256
: MAX_UINT_256
const estGas = await estimateGas(
account,
@ -1081,7 +1046,7 @@ export class Pool {
const poolContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.poolAbi as AbiItem[], poolAddress),
new this.web3.eth.Contract(this.abi as AbiItem[], poolAddress),
this.config
)
@ -1112,7 +1077,7 @@ export class Pool {
tokenInDecimals?: number
): Promise<TransactionReceipt> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let result = null
@ -1171,7 +1136,7 @@ export class Pool {
const poolContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.poolAbi as AbiItem[], poolAddress),
new this.web3.eth.Contract(this.abi as AbiItem[], poolAddress),
this.config
)
@ -1202,7 +1167,7 @@ export class Pool {
poolDecimals?: number
): Promise<TransactionReceipt> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let result = null
@ -1260,27 +1225,19 @@ export class Pool {
swapMarketFee: string
): Promise<string> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let decimalsTokenIn = 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 {
decimalsTokenIn = await tokenInContract.methods.decimals().call()
decimalsTokenIn = await decimals(this.web3, tokenIn)
} catch (e) {
LoggerInstance.error(`ERROR: FAILED TO CALL DECIMALS(), USING 18 ${e.message}`)
}
try {
decimalsTokenOut = await tokenOutContract.methods.decimals().call()
decimalsTokenOut = await decimals(this.web3, tokenOut)
} catch (e) {
LoggerInstance.error(`ERROR: FAILED TO CALL DECIMALS(), USING 18 ${e.message}`)
}
@ -1332,7 +1289,7 @@ export class Pool {
tokenOutDecimals?: number
): Promise<PoolPriceAndFees> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
@ -1412,7 +1369,7 @@ export class Pool {
tokenOutDecimals?: number
): Promise<PoolPriceAndFees> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
@ -1487,7 +1444,7 @@ export class Pool {
tokenInDecimals?: number
): Promise<string> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let amount = null
@ -1524,7 +1481,7 @@ export class Pool {
tokenInDecimals?: number
): Promise<string> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let amount = null
@ -1562,7 +1519,7 @@ export class Pool {
tokenOutDecimals?: number
): Promise<string> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let amount = null
@ -1596,7 +1553,7 @@ export class Pool {
tokenOutDecimals?: number
): Promise<string> {
const pool = setContractDefaults(
new this.web3.eth.Contract(this.poolAbi, poolAddress),
new this.web3.eth.Contract(this.abi, poolAddress),
this.config
)
let amount = null
@ -1623,7 +1580,7 @@ export class Pool {
* @return {String}
*/
public getSwapEventSignature(): string {
const abi = this.poolAbi as AbiItem[]
const abi = this.abi as AbiItem[]
const eventdata = abi.find(function (o) {
if (o.name === 'LOG_SWAP' && o.type === 'event') return o
})
@ -1636,7 +1593,7 @@ export class Pool {
* @return {String}
*/
public getJoinEventSignature(): string {
const abi = this.poolAbi as AbiItem[]
const abi = this.abi as AbiItem[]
const eventdata = abi.find(function (o) {
if (o.name === 'LOG_JOIN' && o.type === 'event') return o
})
@ -1649,7 +1606,7 @@ export class Pool {
* @return {String}
*/
public getExitEventSignature(): string {
const abi = this.poolAbi as AbiItem[]
const abi = this.abi as AbiItem[]
const eventdata = abi.find(function (o) {
if (o.name === 'LOG_EXIT' && o.type === 'event') return o
})

View File

@ -1,43 +1,17 @@
import { Contract } from 'web3-eth-contract'
import Web3 from 'web3'
import { TransactionReceipt } from 'web3-core'
import { AbiItem } from 'web3-utils'
import defaultRouter from '@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json'
import { getFairGasPrice, setContractDefaults, ConfigHelper, estimateGas } from '../utils'
import { Operation } from '../@types/Router'
import { Config } from '../models/index.js'
import FactoryRouter from '@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json'
import { getFairGasPrice, estimateGas } from '../../utils'
import { Operation } from '../../@types'
import { SmartContractWithAddress } from '..'
/**
* Provides an interface for FactoryRouter contract
*/
export class Router {
public routerAddress: string
public RouterAbi: AbiItem | 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
)
export class Router extends SmartContractWithAddress {
getDefaultAbi(): AbiItem | AbiItem[] {
return FactoryRouter.abi as AbiItem[]
}
/**
@ -47,7 +21,7 @@ export class Router {
* @return {Promise<TransactionReceipt>} Transaction receipt
*/
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,
operations: Operation[]
): 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
const trxReceipt = await this.router.methods.buyDTBatch(operations).send({
const trxReceipt = await this.contract.methods.buyDTBatch(operations).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
@ -76,42 +54,42 @@ export class Router {
* @return {Promise<boolean>} true if is on the list.
*/
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.
* @return {Promise<boolean>} true if is a SS contract
*/
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.
* @return {Promise<boolean>} true if is a Fixed Rate contract
*/
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
* @return {Promise<string>} Router Owner address
*/
public async getOwner(): Promise<string> {
return await this.router.methods.routerOwner().call()
return await this.contract.methods.routerOwner().call()
}
/** Get NFT Factory address
* @return {Promise<string>} NFT Factory address
*/
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.
* @return {Promise<boolean>} true if is a Template
*/
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,
contractInstance?: Contract
): 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(
address,
this.router.methods.addApprovedToken,
this.contract.methods.addApprovedToken,
tokenAddress
)
// 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,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
@ -171,7 +149,7 @@ export class Router {
tokenAddress: string,
contractInstance?: Contract
): Promise<any> {
return estimateGas(address, this.router.methods.removeApprovedToken, tokenAddress)
return estimateGas(address, this.contract.methods.removeApprovedToken, tokenAddress)
}
/**
@ -190,16 +168,18 @@ export class Router {
const estGas = await estimateGas(
address,
this.router.methods.removeApprovedToken,
this.contract.methods.removeApprovedToken,
tokenAddress
)
// Invoke createToken function of the contract
const trxReceipt = await this.router.methods.removeApprovedToken(tokenAddress).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
const trxReceipt = await this.contract.methods
.removeApprovedToken(tokenAddress)
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
return trxReceipt
}
@ -211,7 +191,7 @@ export class Router {
* @return {Promise<TransactionReceipt>}
*/
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(
address,
this.router.methods.addSSContract,
this.contract.methods.addSSContract,
tokenAddress
)
// 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,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
@ -254,7 +234,7 @@ export class Router {
address: string,
tokenAddress: string
): 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(
address,
this.router.methods.removeSSContract,
this.contract.methods.removeSSContract,
tokenAddress
)
// 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,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
@ -297,7 +277,7 @@ export class Router {
address: string,
tokenAddress: string
): Promise<any> {
return estimateGas(address, this.router.methods.addFixedRateContract, tokenAddress)
return estimateGas(address, this.contract.methods.addFixedRateContract, tokenAddress)
}
/**
@ -316,16 +296,18 @@ export class Router {
const estGas = await estimateGas(
address,
this.router.methods.addFixedRateContract,
this.contract.methods.addFixedRateContract,
tokenAddress
)
// Invoke createToken function of the contract
const trxReceipt = await this.router.methods.addFixedRateContract(tokenAddress).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
const trxReceipt = await this.contract.methods
.addFixedRateContract(tokenAddress)
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
return trxReceipt
}
@ -340,7 +322,11 @@ export class Router {
address: string,
tokenAddress: string
): 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(
address,
this.router.methods.removeFixedRateContract,
this.contract.methods.removeFixedRateContract,
tokenAddress
)
// Invoke removeFixedRateContract function of the contract
const trxReceipt = await this.router.methods
const trxReceipt = await this.contract.methods
.removeFixedRateContract(tokenAddress)
.send({
from: address,
@ -385,7 +371,7 @@ export class Router {
address: string,
tokenAddress: string
): Promise<any> {
return estimateGas(address, this.router.methods.addDispenserContract, tokenAddress)
return estimateGas(address, this.contract.methods.addDispenserContract, tokenAddress)
}
/**
@ -404,16 +390,18 @@ export class Router {
const estGas = await estimateGas(
address,
this.router.methods.addDispenserContract,
this.contract.methods.addDispenserContract,
tokenAddress
)
// Invoke createToken function of the contract
const trxReceipt = await this.router.methods.addDispenserContract(tokenAddress).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
const trxReceipt = await this.contract.methods
.addDispenserContract(tokenAddress)
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
})
return trxReceipt
}
@ -428,7 +416,11 @@ export class Router {
address: string,
tokenAddress: string
): 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(
address,
this.router.methods.removeDispenserContract,
this.contract.methods.removeDispenserContract,
tokenAddress
)
// Invoke createToken function of the contract
const trxReceipt = await this.router.methods
const trxReceipt = await this.contract.methods
.removeDispenserContract(tokenAddress)
.send({
from: address,
@ -467,14 +459,14 @@ export class Router {
* @return {Promise<number>} OPC fee for a specific baseToken
*/
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
* @return {Promise<number>} OPF fee
*/
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> {
return estimateGas(
address,
this.router.methods.updateOPCFee,
this.contract.methods.updateOPCFee,
newSwapOceanFee,
newSwapNonOceanFee,
newConsumeFee,
@ -522,7 +514,7 @@ export class Router {
const estGas = await estimateGas(
address,
this.router.methods.updateOPCFee,
this.contract.methods.updateOPCFee,
newSwapOceanFee,
newSwapNonOceanFee,
newConsumeFee,
@ -530,7 +522,7 @@ export class Router {
)
// Invoke createToken function of the contract
const trxReceipt = await this.router.methods
const trxReceipt = await this.contract.methods
.updateOPCFee(newSwapOceanFee, newSwapNonOceanFee, newConsumeFee, newProviderFee)
.send({
from: address,
@ -551,7 +543,7 @@ export class Router {
address: string,
templateAddress: string
): 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(
address,
this.router.methods.addPoolTemplate,
this.contract.methods.addPoolTemplate,
templateAddress
)
// 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,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3, this.config)
@ -594,7 +586,7 @@ export class Router {
address: string,
templateAddress: string
): 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(
address,
this.router.methods.removePoolTemplate,
this.contract.methods.removePoolTemplate,
templateAddress
)
// Invoke createToken function of the contract
const trxReceipt = await this.router.methods
const trxReceipt = await this.contract.methods
.removePoolTemplate(templateAddress)
.send({
from: address,

View File

@ -1,40 +1,13 @@
import Web3 from 'web3'
import { AbiItem } from 'web3-utils/types'
import { TransactionReceipt } from 'web3-core'
import { Contract } from 'web3-eth-contract'
import {
LoggerInstance,
getFairGasPrice,
ConfigHelper,
estimateGas,
unitsToAmount
} from '../../utils'
import SideStakingTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
import { Config } from '../../models'
import SideStakingAbi from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
import { LoggerInstance, getFairGasPrice, estimateGas } from '../../utils'
import { SmartContract } from '..'
export class SideStaking {
public ssAbi: AbiItem | AbiItem[]
public web3: Web3
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)
export class SideStaking extends SmartContract {
getDefaultAbi(): AbiItem | AbiItem[] {
return SideStakingAbi.abi as AbiItem[]
}
/**
@ -47,7 +20,7 @@ export class SideStaking {
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
try {
result = await sideStaking.methods
@ -71,7 +44,7 @@ export class SideStaking {
datatokenAddress: string
): Promise<string> {
try {
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
let result = null
result = await sideStaking.methods
.getDatatokenCurrentCirculatingSupply(datatokenAddress)
@ -92,7 +65,7 @@ export class SideStaking {
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
try {
result = await sideStaking.methods.getPublisherAddress(datatokenAddress).call()
@ -109,7 +82,7 @@ export class SideStaking {
* @return {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
try {
result = await sideStaking.methods.getBaseTokenAddress(datatokenAddress).call()
@ -126,7 +99,7 @@ export class SideStaking {
* @return {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
try {
result = await sideStaking.methods.getPoolAddress(datatokenAddress).call()
@ -146,7 +119,7 @@ export class SideStaking {
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
try {
result = await sideStaking.methods.getBaseTokenBalance(datatokenAddress).call()
@ -168,7 +141,7 @@ export class SideStaking {
datatokenAddress: string,
tokenDecimals?: number
): 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
try {
result = await sideStaking.methods.getDatatokenBalance(datatokenAddress).call()
@ -186,7 +159,7 @@ export class SideStaking {
* @return {String} end block for vesting amount
*/
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
try {
result = await sideStaking.methods.getvestingEndBlock(datatokenAddress).call()
@ -208,7 +181,7 @@ export class SideStaking {
datatokenAddress: string,
tokenDecimals?: number
): 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
try {
result = await sideStaking.methods.getvestingAmount(datatokenAddress).call()
@ -229,7 +202,7 @@ export class SideStaking {
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
try {
result = await sideStaking.methods.getvestingLastBlock(datatokenAddress).call()
@ -251,7 +224,7 @@ export class SideStaking {
datatokenAddress: string,
tokenDecimals?: number
): 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
try {
result = await sideStaking.methods.getvestingAmountSoFar(datatokenAddress).call()
@ -277,7 +250,7 @@ export class SideStaking {
contractInstance?: Contract
): Promise<number> {
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)
}
@ -294,7 +267,7 @@ export class SideStaking {
ssAddress: string,
datatokenAddress: string
): 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
const estGas = await estimateGas(
@ -332,7 +305,7 @@ export class SideStaking {
contractInstance?: Contract
): Promise<number> {
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,
@ -357,7 +330,7 @@ export class SideStaking {
poolAddress: string,
swapFee: number
): 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
const estGas = await estimateGas(
@ -388,7 +361,7 @@ export class SideStaking {
* @return {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
try {
result = await sideStaking.methods.router().call()

View File

@ -3,58 +3,38 @@ import { AbiItem } from 'web3-utils'
import { TransactionReceipt } from 'web3-eth'
import { Contract } from 'web3-eth-contract'
import Decimal from 'decimal.js'
import defaultDatatokensAbi from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
import defaultDatatokensEnterpriseAbi from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json'
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
import ERC20TemplateEnterprise from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json'
import {
LoggerInstance,
getFairGasPrice,
setContractDefaults,
getFreOrderParams,
estimateGas,
ZERO_ADDRESS,
ConfigHelper
} from '../utils'
ZERO_ADDRESS
} from '../../utils'
import {
ConsumeMarketFee,
FreOrderParams,
FreCreationParams,
ProviderFees,
PublishingMarketFee
} from '../@types'
PublishingMarketFee,
DispenserParams,
OrderParams,
DatatokenRoles
} from '../../@types'
import { Nft } from './NFT'
import { Config } from '../models/index.js'
import { Config } from '../../config'
import { SmartContract } from '..'
/**
* ERC20 ROLES
*/
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
export class Datatoken extends SmartContract {
public abiEnterprise: AbiItem | AbiItem[]
public nft: Nft
getDefaultAbi(): AbiItem | AbiItem[] {
return ERC20Template.abi as AbiItem[]
}
/**
* Instantiate ERC20 Datatokens
* @param {AbiItem | AbiItem[]} datatokensAbi
@ -63,15 +43,12 @@ export class Datatoken {
constructor(
web3: Web3,
network?: string | number,
datatokensAbi?: AbiItem | AbiItem[],
datatokensEnterpriseAbi?: AbiItem | AbiItem[],
config?: Config
config?: Config,
abi?: AbiItem | AbiItem[],
abiEnterprise?: AbiItem | AbiItem[]
) {
this.web3 = web3
this.datatokensAbi = datatokensAbi || (defaultDatatokensAbi.abi as AbiItem[])
this.datatokensEnterpriseAbi =
datatokensEnterpriseAbi || (defaultDatatokensEnterpriseAbi.abi as AbiItem[])
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
super(web3, network, config, abi)
this.abiEnterprise = abiEnterprise || (ERC20TemplateEnterprise.abi as AbiItem[])
this.nft = new Nft(this.web3)
}
@ -93,10 +70,7 @@ export class Datatoken {
): Promise<any> {
const dtContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
return estimateGas(
address,
@ -121,7 +95,7 @@ export class Datatoken {
address: string
): Promise<TransactionReceipt> {
const dtContract = setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
new this.web3.eth.Contract(this.abi, dtAddress),
this.config
)
@ -161,10 +135,7 @@ export class Datatoken {
): Promise<any> {
const dtContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
return estimateGas(
address,
@ -191,10 +162,7 @@ export class Datatoken {
): Promise<any> {
const dtContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
if (!fixedRateParams.allowedConsumer) fixedRateParams.allowedConsumer = ZERO_ADDRESS
const withMint = fixedRateParams.withMint ? 1 : 0
@ -233,7 +201,7 @@ export class Datatoken {
fixedRateParams: FreCreationParams
): Promise<TransactionReceipt> {
const dtContract = setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
new this.web3.eth.Contract(this.abi, dtAddress),
this.config
)
if (!(await this.isERC20Deployer(dtAddress, address))) {
@ -308,10 +276,7 @@ export class Datatoken {
): Promise<any> {
const dtContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
if (!dispenserParams.allowedSwapper) dispenserParams.allowedSwapper = ZERO_ADDRESS
@ -347,7 +312,7 @@ export class Datatoken {
}
const dtContract = setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
new this.web3.eth.Contract(this.abi, dtAddress),
this.config
)
@ -399,7 +364,7 @@ export class Datatoken {
toAddress?: string
): Promise<TransactionReceipt> {
const dtContract = setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
new this.web3.eth.Contract(this.abi, dtAddress),
this.config
)
@ -446,10 +411,7 @@ export class Datatoken {
): Promise<any> {
const dtContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
return estimateGas(address, dtContract.methods.addMinter, minter)
}
@ -468,7 +430,7 @@ export class Datatoken {
minter: string
): Promise<TransactionReceipt> {
const dtContract = setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
new this.web3.eth.Contract(this.abi, dtAddress),
this.config
)
@ -504,10 +466,7 @@ export class Datatoken {
): Promise<any> {
const dtContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
// should check ERC20Deployer role using erc721 level ..
@ -529,7 +488,7 @@ export class Datatoken {
minter: string
): Promise<TransactionReceipt> {
const dtContract = setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
new this.web3.eth.Contract(this.abi, dtAddress),
this.config
)
@ -565,10 +524,7 @@ export class Datatoken {
): Promise<any> {
const dtContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
return estimateGas(address, dtContract.methods.addPaymentManager, paymentManager)
}
@ -587,7 +543,7 @@ export class Datatoken {
paymentManager: string
): Promise<TransactionReceipt> {
const dtContract = setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
new this.web3.eth.Contract(this.abi, dtAddress),
this.config
)
@ -627,10 +583,7 @@ export class Datatoken {
): Promise<any> {
const dtContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
return estimateGas(address, dtContract.methods.removePaymentManager, paymentManager)
}
@ -649,7 +602,7 @@ export class Datatoken {
paymentManager: string
): Promise<TransactionReceipt> {
const dtContract = setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
new this.web3.eth.Contract(this.abi, dtAddress),
this.config
)
@ -691,10 +644,7 @@ export class Datatoken {
): Promise<any> {
const dtContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
return estimateGas(address, dtContract.methods.setPaymentCollector, paymentCollector)
}
@ -714,7 +664,7 @@ export class Datatoken {
paymentCollector: string
): Promise<TransactionReceipt> {
const dtContract = setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
new this.web3.eth.Contract(this.abi, dtAddress),
this.config
)
const isPaymentManager = (await this.getDTPermissions(dtAddress, address))
@ -752,7 +702,7 @@ export class Datatoken {
*/
public async getPaymentCollector(dtAddress: string): Promise<string> {
const dtContract = setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
new this.web3.eth.Contract(this.abi, dtAddress),
this.config
)
const paymentCollector = await dtContract.methods.getPaymentCollector().call()
@ -795,10 +745,7 @@ export class Datatoken {
): Promise<any> {
const dtContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
return estimateGas(address, dtContract.methods.transfer, toAddress, amount)
}
@ -818,7 +765,7 @@ export class Datatoken {
address: string
): Promise<TransactionReceipt> {
const dtContract = setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
new this.web3.eth.Contract(this.abi, dtAddress),
this.config
)
try {
@ -862,10 +809,7 @@ export class Datatoken {
): Promise<any> {
const dtContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
return estimateGas(
address,
@ -895,7 +839,7 @@ export class Datatoken {
consumeMarketFee?: ConsumeMarketFee
): Promise<TransactionReceipt> {
const dtContract = setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
new this.web3.eth.Contract(this.abi, dtAddress),
this.config
)
if (!consumeMarketFee) {
@ -946,10 +890,7 @@ export class Datatoken {
): Promise<any> {
const dtContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
return estimateGas(address, dtContract.methods.reuseOrder, orderTxId, providerFees)
}
@ -970,7 +911,7 @@ export class Datatoken {
providerFees: ProviderFees
): Promise<TransactionReceipt> {
const dtContract = setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
new this.web3.eth.Contract(this.abi, dtAddress),
this.config
)
try {
@ -1011,8 +952,7 @@ export class Datatoken {
contractInstance?: Contract
): Promise<any> {
const dtContract =
contractInstance ||
new this.web3.eth.Contract(this.datatokensEnterpriseAbi, dtAddress)
contractInstance || new this.web3.eth.Contract(this.abiEnterprise, dtAddress)
return estimateGas(
address,
@ -1035,7 +975,7 @@ export class Datatoken {
orderParams: OrderParams,
freParams: FreOrderParams
): Promise<TransactionReceipt> {
const dtContract = new this.web3.eth.Contract(this.datatokensEnterpriseAbi, dtAddress)
const dtContract = new this.web3.eth.Contract(this.abiEnterprise, dtAddress)
try {
const freContractParams = getFreOrderParams(freParams)
@ -1076,8 +1016,7 @@ export class Datatoken {
contractInstance?: Contract
): Promise<any> {
const dtContract =
contractInstance ||
new this.web3.eth.Contract(this.datatokensEnterpriseAbi, dtAddress)
contractInstance || new this.web3.eth.Contract(this.abiEnterprise, dtAddress)
return estimateGas(
address,
@ -1100,7 +1039,7 @@ export class Datatoken {
orderParams: OrderParams,
dispenserContract: string
): Promise<TransactionReceipt> {
const dtContract = new this.web3.eth.Contract(this.datatokensEnterpriseAbi, dtAddress)
const dtContract = new this.web3.eth.Contract(this.abiEnterprise, dtAddress)
try {
const estGas = await estimateGas(
address,
@ -1138,10 +1077,7 @@ export class Datatoken {
): Promise<any> {
const dtContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
return estimateGas(address, dtContract.methods.setData, value)
}
@ -1164,7 +1100,7 @@ export class Datatoken {
}
const dtContract = setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
new this.web3.eth.Contract(this.abi, dtAddress),
this.config
)
@ -1193,10 +1129,7 @@ export class Datatoken {
): Promise<any> {
const dtContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, dtAddress), this.config)
return estimateGas(address, dtContract.methods.cleanPermissions)
}
@ -1216,7 +1149,7 @@ export class Datatoken {
throw new Error('Caller is NOT Nft Owner')
}
const dtContract = setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
new this.web3.eth.Contract(this.abi, dtAddress),
this.config
)
@ -1235,11 +1168,14 @@ export class Datatoken {
/** Returns ERC20 user's permissions for a datatoken
* @param {String} dtAddress Datatoken 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(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
new this.web3.eth.Contract(this.abi, dtAddress),
this.config
)
const roles = await dtContract.methods.permissions(address).call()
@ -1252,7 +1188,7 @@ export class Datatoken {
*/
public async getCap(dtAddress: string): Promise<string> {
const dtContract = setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
new this.web3.eth.Contract(this.abi, dtAddress),
this.config
)
const cap = await dtContract.methods.cap().call()
@ -1265,7 +1201,7 @@ export class Datatoken {
*/
public async getDecimals(dtAddress: string): Promise<string> {
const dtContract = setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
new this.web3.eth.Contract(this.abi, dtAddress),
this.config
)
const decimals = await dtContract.methods.decimals().call()
@ -1278,7 +1214,7 @@ export class Datatoken {
*/
public async getNFTAddress(dtAddress: string): Promise<string> {
const dtContract = setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
new this.web3.eth.Contract(this.abi, dtAddress),
this.config
)
const nftAddress = await dtContract.methods.getERC721Address().call()
@ -1292,7 +1228,7 @@ export class Datatoken {
*/
public async isERC20Deployer(dtAddress: string, address: string): Promise<boolean> {
const dtContract = setContractDefaults(
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
new this.web3.eth.Contract(this.abi, dtAddress),
this.config
)
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
*/
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
})
const balance = await dtContract.methods.balanceOf(address).call()
@ -1330,7 +1266,7 @@ export class Datatoken {
address: string
): Promise<number> {
// 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
})
return estimateGas(
@ -1359,7 +1295,7 @@ export class Datatoken {
publishMarketFeeAmount: 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
})
const mktFeeAddress = (await dtContract.methods.getPublishingMarketFee().call())[0]
@ -1398,7 +1334,7 @@ export class Datatoken {
datatokenAddress: string,
address: string
): Promise<PublishingMarketFee> {
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, datatokenAddress, {
const dtContract = new this.web3.eth.Contract(this.abi, datatokenAddress, {
from: address
})

View File

@ -1,47 +1,20 @@
import Web3 from 'web3'
import { AbiItem } from 'web3-utils'
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 {
LoggerInstance,
getFairGasPrice,
generateDtName,
setContractDefaults,
estimateGas,
ConfigHelper
} from '../utils'
estimateGas
} from '../../utils'
import { Contract } from 'web3-eth-contract'
import { MetadataProof } from '../../src/@types'
import { Config } from '../models/index.js'
import { MetadataAndTokenURI } from '../@types'
import { MetadataProof, MetadataAndTokenURI, NftRoles } from '../../@types'
import { SmartContract } from '..'
/**
* ERC721 ROLES
*/
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')
export class Nft extends SmartContract {
getDefaultAbi(): AbiItem | AbiItem[] {
return ERC721Template.abi as AbiItem[]
}
/**
@ -76,10 +49,7 @@ export class Nft {
): Promise<any> {
const nftContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
return estimateGas(
address,
nftContract.methods.createERC20,
@ -131,7 +101,7 @@ export class Nft {
// Create 721contract object
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
@ -185,10 +155,7 @@ export class Nft {
) {
const nftContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
return estimateGas(address, nftContract.methods.addManager, manager)
}
@ -202,7 +169,7 @@ export class Nft {
*/
public async addManager(nftAddress: string, address: string, manager: string) {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
@ -238,10 +205,7 @@ export class Nft {
) {
const nftContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
return estimateGas(address, nftContract.methods.removeManager, manager)
}
@ -254,7 +218,7 @@ export class Nft {
*/
public async removeManager(nftAddress: string, address: string, manager: string) {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
@ -290,10 +254,7 @@ export class Nft {
): Promise<any> {
const nftContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
return estimateGas(address, nftContract.methods.addToCreateERC20List, erc20Deployer)
}
@ -310,7 +271,7 @@ export class Nft {
erc20Deployer: string
): Promise<TransactionReceipt> {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
@ -353,10 +314,7 @@ export class Nft {
): Promise<any> {
const nftContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
return estimateGas(
address,
@ -378,7 +336,7 @@ export class Nft {
erc20Deployer: string
): Promise<TransactionReceipt> {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
@ -423,10 +381,7 @@ export class Nft {
): Promise<any> {
const nftContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
return estimateGas(address, nftContract.methods.addToMetadataList, metadataUpdater)
}
@ -444,7 +399,7 @@ export class Nft {
metadataUpdater: string
): Promise<TransactionReceipt> {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
@ -484,10 +439,7 @@ export class Nft {
): Promise<any> {
const nftContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
return estimateGas(
address,
@ -509,7 +461,7 @@ export class Nft {
metadataUpdater: string
): Promise<TransactionReceipt> {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
@ -556,10 +508,7 @@ export class Nft {
): Promise<any> {
const nftContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
return estimateGas(address, nftContract.methods.addTo725StoreList, storeUpdater)
}
@ -577,7 +526,7 @@ export class Nft {
storeUpdater: string
): Promise<TransactionReceipt> {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
@ -617,10 +566,7 @@ export class Nft {
): Promise<any> {
const nftContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
return estimateGas(address, nftContract.methods.removeFrom725StoreList, storeUpdater)
}
@ -638,7 +584,7 @@ export class Nft {
storeUpdater: string
): Promise<TransactionReceipt> {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
@ -682,10 +628,7 @@ export class Nft {
): Promise<any> {
const nftContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
return estimateGas(address, nftContract.methods.cleanPermissions)
}
@ -705,7 +648,7 @@ export class Nft {
address: string
): Promise<TransactionReceipt> {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
@ -743,10 +686,7 @@ export class Nft {
): Promise<any> {
const nftContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
return estimateGas(
nftOwner,
@ -773,7 +713,7 @@ export class Nft {
tokenId?: number
): Promise<TransactionReceipt> {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
@ -821,10 +761,7 @@ export class Nft {
): Promise<any> {
const nftContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
return estimateGas(
nftOwner,
@ -851,7 +788,7 @@ export class Nft {
tokenId?: number
): Promise<TransactionReceipt> {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
@ -906,10 +843,7 @@ export class Nft {
): Promise<any> {
const nftContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
if (!metadataProofs) metadataProofs = []
return estimateGas(
metadataUpdater,
@ -943,7 +877,7 @@ export class Nft {
metadataProofs?: MetadataProof[]
): Promise<TransactionReceipt> {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
if (!metadataProofs) metadataProofs = []
@ -996,10 +930,7 @@ export class Nft {
): Promise<any> {
const nftContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
const sanitizedMetadataAndTokenURI = {
...metadataAndTokenURI,
metadataProofs: metadataAndTokenURI.metadataProofs || []
@ -1024,7 +955,7 @@ export class Nft {
metadataAndTokenURI: MetadataAndTokenURI
): Promise<TransactionReceipt> {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
if (!(await this.getNftPermissions(nftAddress, metadataUpdater)).updateMetadata) {
@ -1066,10 +997,7 @@ export class Nft {
): Promise<any> {
const nftContract =
contractInstance ||
setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
this.config
)
setContractDefaults(new this.web3.eth.Contract(this.abi, nftAddress), this.config)
return estimateGas(
metadataUpdater,
@ -1091,7 +1019,7 @@ export class Nft {
metadataState: number
): Promise<TransactionReceipt> {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
@ -1127,7 +1055,7 @@ export class Nft {
data: string
): Promise<any> {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
@ -1146,7 +1074,7 @@ export class Nft {
data: string
): Promise<any> {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
@ -1165,7 +1093,7 @@ export class Nft {
*/
public async getNftOwner(nftAddress: string): Promise<string> {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
const trxReceipt = await nftContract.methods.ownerOf(1).call()
@ -1175,11 +1103,11 @@ export class Nft {
/** Get users NFT Permissions
* @param {String} nftAddress erc721 contract 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(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
const roles = await nftContract.methods.getPermissions(address).call()
@ -1192,7 +1120,7 @@ export class Nft {
*/
public async getMetadata(nftAddress: string): Promise<Object> {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
return await nftContract.methods.getMetaData().call()
@ -1201,11 +1129,11 @@ export class Nft {
/** Get users ERC20Deployer role
* @param {String} nftAddress erc721 contract adress
* @param {String} address user adress
* @return {Promise<Roles>}
* @return {Promise<boolean>}
*/
public async isErc20Deployer(nftAddress: string, address: string): Promise<boolean> {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
const isERC20Deployer = await nftContract.methods.isERC20Deployer(address).call()
@ -1219,7 +1147,7 @@ export class Nft {
*/
public async getData(nftAddress: string, key: string): Promise<string> {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
const data = await nftContract.methods.getData(key).call()
@ -1233,7 +1161,7 @@ export class Nft {
*/
public async getTokenURI(nftAddress: string, id: number): Promise<string> {
const nftContract = setContractDefaults(
new this.web3.eth.Contract(this.nftAbi, nftAddress),
new this.web3.eth.Contract(this.abi, nftAddress),
this.config
)
const data = await nftContract.methods.tokenURI(id).call()

View File

@ -1 +0,0 @@
export * from './NFTFactory'

View File

@ -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 './provider'
export * from './config'
export * from './contracts'
export * from './services'
export * from './utils'

View File

@ -1 +0,0 @@
export * from './Config'

View File

@ -1 +0,0 @@
export * from './Pool'

View File

@ -1 +0,0 @@
export * from './Dispenser'

View File

@ -1 +0,0 @@
export * from './FixedRateExchange'

View File

@ -1,5 +0,0 @@
export * from './balancer'
export * from './dispenser'
export * from './fixedRate'
export * from './ssContracts'
export * from './Router'

View File

@ -1 +0,0 @@
export * from './SideStaking'

View File

@ -1 +0,0 @@
export * from './Provider'

View File

@ -1,6 +1,7 @@
import { LoggerInstance, sleep } from '../utils'
import { Asset, DDO, ValidateMetadata } from '../@types/'
import fetch from 'cross-fetch'
import { LoggerInstance, sleep } from '../utils'
import { Asset, DDO, ValidateMetadata } from '../@types'
export class Aquarius {
public aquariusURL
/**
@ -122,5 +123,3 @@ export class Aquarius {
return status
}
}
export default Aquarius

View File

@ -1,5 +1,6 @@
import Web3 from 'web3'
import { LoggerInstance, getData } from '../utils'
import fetch from 'cross-fetch'
import { LoggerInstance, getData, noZeroX } from '../utils'
import {
FileMetadata,
ComputeJob,
@ -8,22 +9,10 @@ import {
ComputeAsset,
ComputeEnvironment,
ProviderInitialize,
ProviderComputeInitializeResults
} from '../@types/'
import { noZeroX } from '../utils/ConversionTypeHelper'
import fetch from 'cross-fetch'
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
}
ProviderComputeInitializeResults,
ServiceEndpoint,
UserCustomParameters
} from '../@types'
export class Provider {
/**
@ -780,4 +769,3 @@ export class Provider {
}
export const ProviderInstance = new Provider()
export default ProviderInstance

View File

@ -1 +1,2 @@
export * from './Aquarius'
export * from './Provider'

View File

@ -1,2 +0,0 @@
export * from './Datatoken'
export * from './NFT'

View File

@ -1,2 +1,4 @@
export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
export const GASLIMIT_DEFAULT = 1000000
export const MAX_UINT_256 =
'115792089237316195423570985008687907853269984665640564039457584007913129639934'

View File

@ -1,17 +1,14 @@
import Web3 from 'web3'
import BigNumber from 'bignumber.js'
import { Contract } from 'web3-eth-contract'
import { generateDtName } from './DatatokenName'
import {
Erc20CreateParams,
FreCreationParams,
FreOrderParams,
PoolCreationParams
} from '../@types'
import { Config } from '../models'
import { minAbi } from './minAbi'
import LoggerInstance from './Logger'
import { GASLIMIT_DEFAULT, ZERO_ADDRESS } from './Constants'
import { Config } from '../config'
import { generateDtName, minAbi, LoggerInstance, GASLIMIT_DEFAULT, ZERO_ADDRESS } from '.'
export function setContractDefaults(contract: Contract, config: Config): Contract {
if (config) {

View File

@ -1,4 +1,4 @@
import { LoggerInstance } from './Logger'
import { LoggerInstance } from '.'
export const zeroX = (input: string): string => zeroXTransformer(input, true)
export const noZeroX = (input: string): string => zeroXTransformer(input, false)

View File

@ -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

View File

@ -1,6 +1,6 @@
import sha256 from 'crypto-js/sha256'
import Web3 from 'web3'
import LoggerInstance from './Logger'
import { LoggerInstance } from '.'
export function generateDid(erc721Address: string, chainId: number): string {
erc721Address = Web3.utils.toChecksumAddress(erc721Address)

View File

@ -1,6 +1,6 @@
import fetch from 'cross-fetch'
import LoggerInstance from './Logger'
import { DownloadResponse } from '../@types/DownloadResponse'
import { DownloadResponse } from '../@types'
import { LoggerInstance } from '.'
export async function fetchData(url: string, opts: RequestInit): Promise<Response> {
const result = await fetch(url, opts)

View File

@ -43,4 +43,3 @@ export class Logger {
}
export const LoggerInstance = new Logger()
export default LoggerInstance

View File

@ -1,5 +1,5 @@
import Decimal from 'decimal.js'
import { Pool } from '..'
import { Pool } from '../contracts'
export function calcMaxExactOut(balance: string): Decimal {
return new Decimal(balance).div(2)

View File

@ -1,5 +1,4 @@
import Web3 from 'web3'
import { LoggerInstance } from './Logger'
export async function signHash(web3: Web3, message: string, address: string) {
let signedMessage = await web3.eth.sign(message, address)

View File

@ -1,15 +1,15 @@
import Decimal from 'decimal.js'
import { Contract } from 'web3-eth-contract'
import { TransactionReceipt } from 'web3-core'
import Web3 from 'web3'
import {
amountToUnits,
estimateGas,
getFairGasPrice,
unitsToAmount
} from './ContractUtils'
import { minAbi } from './minAbi'
import LoggerInstance from './Logger'
import { TransactionReceipt } from 'web3-core'
import Web3 from 'web3'
unitsToAmount,
minAbi,
LoggerInstance
} from '.'
/**
* Estimate gas cost for approval function

View File

@ -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 './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 './TokenUtils'
export * from './General'
export * from './PoolHelpers'

View File

@ -1,12 +1,8 @@
import Web3 from 'web3'
import fs from 'fs'
import { homedir } from 'os'
import {
ConfigHelper,
configHelperNetworks,
LoggerInstance,
LogLevel
} from '../src/utils'
import { ConfigHelper, configHelperNetworks } from '../src/config'
import { LoggerInstance, LogLevel } from '../src/utils'
LoggerInstance.setLevel(LogLevel.Error)

View File

@ -614,7 +614,7 @@ describe('Marketplace flow tests', async () => {
it('7.3 Marketplace displays fixed rate asset for sale', async () => {
/// ```Typescript
const fixedRate = new FixedRateExchange(web3, freAddress)
const fixedRate = new FixedRateExchange(freAddress, web3)
const oceanAmount = await (
await fixedRate.calcBaseInGivenOutDT(freId, '1')
).baseTokenAmount
@ -655,7 +655,7 @@ describe('Marketplace flow tests', async () => {
DATATOKEN_AMOUNT
)
const fixedRate = new FixedRateExchange(web3, freAddress)
const fixedRate = new FixedRateExchange(freAddress, web3)
/// ```
/// Now we can make the contract call
/// ```Typescript
@ -826,7 +826,7 @@ describe('Marketplace flow tests', async () => {
it('8.3 Consumer gets a dispenser data asset, and downloads it', async () => {
/// ```Typescript
const datatoken = new Datatoken(web3)
const dispenser = new Dispenser(web3, null, addresses.Dispenser)
const dispenser = new Dispenser(addresses.Dispenser, web3)
let consumerDTBalance = await balance(
web3,

View File

@ -59,7 +59,7 @@ describe('Dispenser flow', () => {
})
it('should initialize Dispenser class', async () => {
DispenserClass = new Dispenser(web3, 8996, contracts.dispenserAddress)
DispenserClass = new Dispenser(contracts.dispenserAddress, web3, 8996)
assert(DispenserClass !== null)
})

View File

@ -100,13 +100,7 @@ describe('Fixed Rate unit test', () => {
// user1 has no dt1
expect(await balance(web3, dtAddress, user1)).to.equal('0')
fixedRate = new FixedRateExchange(
web3,
contracts.fixedRateAddress,
8996,
null,
contracts.oceanAddress
)
fixedRate = new FixedRateExchange(contracts.fixedRateAddress, web3, 8996)
assert(fixedRate != null)
})
@ -415,13 +409,7 @@ describe('Fixed Rate unit test', () => {
// user1 has no dt1
expect(await balance(web3, dtAddress, user1)).to.equal('0')
fixedRate = new FixedRateExchange(
web3,
contracts.fixedRateAddress,
8996,
null,
contracts.oceanAddress
)
fixedRate = new FixedRateExchange(contracts.fixedRateAddress, web3, 8996)
assert(fixedRate != null)
})