diff --git a/src/@types/Dispenser.ts b/src/@types/Dispenser.ts index 6919ef22..02749dfb 100644 --- a/src/@types/Dispenser.ts +++ b/src/@types/Dispenser.ts @@ -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 +} diff --git a/src/@types/Erc20.ts b/src/@types/Erc20.ts index 19643b47..96cdb2bb 100644 --- a/src/@types/Erc20.ts +++ b/src/@types/Erc20.ts @@ -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 +} diff --git a/src/@types/Erc721.ts b/src/@types/Erc721.ts index 5b2289e3..4ba47066 100644 --- a/src/@types/Erc721.ts +++ b/src/@types/Erc721.ts @@ -11,3 +11,10 @@ export interface MetadataAndTokenURI { tokenURI: string metadataProofs?: MetadataProof[] } + +export interface NftRoles { + manager: boolean + deployERC20: boolean + updateMetadata: boolean + store: boolean +} diff --git a/src/@types/FixedPrice.ts b/src/@types/FixedPrice.ts index 3fe6ea43..8527a7f0 100644 --- a/src/@types/FixedPrice.ts +++ b/src/@types/FixedPrice.ts @@ -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 +} diff --git a/src/@types/NFTFactory.ts b/src/@types/NFTFactory.ts new file mode 100644 index 00000000..5e20ac9d --- /dev/null +++ b/src/@types/NFTFactory.ts @@ -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 +} diff --git a/src/@types/Provider.ts b/src/@types/Provider.ts index a8be432c..1b2e64c6 100644 --- a/src/@types/Provider.ts +++ b/src/@types/Provider.ts @@ -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 +} diff --git a/src/@types/index.ts b/src/@types/index.ts index dbadc5be..7ff08ef4 100644 --- a/src/@types/index.ts +++ b/src/@types/index.ts @@ -11,6 +11,7 @@ export * from './Erc20' export * from './Erc721' export * from './FileMetadata' export * from './FixedPrice' +export * from './NFTFactory' export * from './Pool' export * from './Provider' export * from './Router' diff --git a/src/contracts/factories/NFTFactory.ts b/src/contracts/factories/NFTFactory.ts index cca80872..f4e0ef69 100644 --- a/src/contracts/factories/NFTFactory.ts +++ b/src/contracts/factories/NFTFactory.ts @@ -16,36 +16,15 @@ import { } from '../../utils' import { Config, ConfigHelper } from '../../config' import { - ProviderFees, FreCreationParams, Erc20CreateParams, PoolCreationParams, DispenserCreationParams, - ConsumeMarketFee + NftCreateData, + Template, + TokenOrder } from '../../@types' -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 -} - /** * Provides an interface for NFT Factory contract */ diff --git a/src/contracts/pools/Dispenser.ts b/src/contracts/pools/Dispenser.ts index d50a0668..61797fa5 100644 --- a/src/contracts/pools/Dispenser.ts +++ b/src/contracts/pools/Dispenser.ts @@ -12,16 +12,7 @@ import { } from '../../utils/' import { Datatoken } from '..' import { Config, ConfigHelper } from '../../config' - -export interface DispenserToken { - active: boolean - owner: string - maxTokens: string - maxBalance: string - balance: string - isMinter: boolean - allowedSwapper: string -} +import { DispenserToken } from '../../@types' export class Dispenser { public web3: Web3 = null diff --git a/src/contracts/pools/FixedRateExchange.ts b/src/contracts/pools/FixedRateExchange.ts index 88fc921b..ef1217b7 100644 --- a/src/contracts/pools/FixedRateExchange.ts +++ b/src/contracts/pools/FixedRateExchange.ts @@ -13,50 +13,10 @@ import { ZERO_ADDRESS } from '../../utils' import { Config, ConfigHelper } from '../../config' -import { PriceAndFees } from '../../@types' - -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 */ +import { PriceAndFees, FeesInfo, FixedPriceExchange } from '../../@types' export class FixedRateExchange { /** Ocean related functions */ - public oceanAddress: string = null public fixedRateAddress: string public fixedRateExchangeAbi: AbiItem | AbiItem[] public web3: Web3 @@ -75,14 +35,12 @@ export class FixedRateExchange { 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), diff --git a/src/contracts/pools/Pool.ts b/src/contracts/pools/Pool.ts index 5f5dd1ee..381912fd 100644 --- a/src/contracts/pools/Pool.ts +++ b/src/contracts/pools/Pool.ts @@ -16,7 +16,8 @@ import { getMaxAddLiquidity, getMaxRemoveLiquidity, getMaxSwapExactIn, - getMaxSwapExactOut + getMaxSwapExactOut, + MAX_UINT_256 } from '../../utils' import { CurrentFees, @@ -27,9 +28,6 @@ import { } from '../../@types' import { Config, ConfigHelper } from '../../config' -const MaxUint256 = - '115792089237316195423570985008687907853269984665640564039457584007913129639934' - /** * Provides an interface to Ocean friendly fork from Balancer BPool */ @@ -803,7 +801,7 @@ export class Pool { await this.getBaseToken(poolAddress), amountsInOutMaxFee.maxPrice ) - : MaxUint256 + : MAX_UINT_256 return estimateGas( address, @@ -868,7 +866,7 @@ export class Pool { await this.getBaseToken(poolAddress), amountsInOutMaxFee.maxPrice ) - : MaxUint256 + : MAX_UINT_256 const estGas = await estimateGas( address, @@ -954,7 +952,7 @@ export class Pool { await this.getBaseToken(poolAddress), amountsInOutMaxFee.maxPrice ) - : MaxUint256 + : MAX_UINT_256 return estimateGas( address, @@ -1015,7 +1013,7 @@ export class Pool { await this.getBaseToken(poolAddress), amountsInOutMaxFee.maxPrice ) - : MaxUint256 + : MAX_UINT_256 const estGas = await estimateGas( account, diff --git a/src/contracts/tokens/Datatoken.ts b/src/contracts/tokens/Datatoken.ts index 21912fb5..26d8b9f3 100644 --- a/src/contracts/tokens/Datatoken.ts +++ b/src/contracts/tokens/Datatoken.ts @@ -18,36 +18,16 @@ import { FreOrderParams, FreCreationParams, ProviderFees, - PublishingMarketFee + PublishingMarketFee, + DispenserParams, + OrderParams, + DatatokenRoles } from '../../@types' import { Nft } from './NFT' import { Config, ConfigHelper } from '../../config' -/** - * 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 @@ -1234,9 +1214,12 @@ export class Datatoken { /** Returns ERC20 user's permissions for a datatoken * @param {String} dtAddress Datatoken adress * @param {String} address user adress - * @return {Promise} + * @return {Promise} */ - public async getDTPermissions(dtAddress: string, address: string): Promise { + public async getDTPermissions( + dtAddress: string, + address: string + ): Promise { const dtContract = setContractDefaults( new this.web3.eth.Contract(this.datatokensAbi, dtAddress), this.config diff --git a/src/contracts/tokens/NFT.ts b/src/contracts/tokens/NFT.ts index 202d9f51..4cc19f25 100644 --- a/src/contracts/tokens/NFT.ts +++ b/src/contracts/tokens/NFT.ts @@ -10,22 +10,11 @@ import { estimateGas } from '../../utils' import { Contract } from 'web3-eth-contract' -import { MetadataProof, MetadataAndTokenURI } from '../../@types' +import { MetadataProof, MetadataAndTokenURI, NftRoles } from '../../@types' import { Config, ConfigHelper } from '../../config' -/** - * 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 @@ -1173,9 +1162,9 @@ export class Nft { /** Get users NFT Permissions * @param {String} nftAddress erc721 contract adress * @param {String} address user adress - * @return {Promise} + * @return {Promise} */ - public async getNftPermissions(nftAddress: string, address: string): Promise { + public async getNftPermissions(nftAddress: string, address: string): Promise { const nftContract = setContractDefaults( new this.web3.eth.Contract(this.nftAbi, nftAddress), this.config @@ -1199,7 +1188,7 @@ export class Nft { /** Get users ERC20Deployer role * @param {String} nftAddress erc721 contract adress * @param {String} address user adress - * @return {Promise} + * @return {Promise} */ public async isErc20Deployer(nftAddress: string, address: string): Promise { const nftContract = setContractDefaults( diff --git a/src/services/Provider.ts b/src/services/Provider.ts index 602d95c3..412a8469 100644 --- a/src/services/Provider.ts +++ b/src/services/Provider.ts @@ -9,22 +9,11 @@ import { ComputeAsset, ComputeEnvironment, ProviderInitialize, - ProviderComputeInitializeResults + ProviderComputeInitializeResults, + ServiceEndpoint, + UserCustomParameters } from '../@types' -export interface HttpCallback { - (httpMethod: string, url: string, body: string, header: any): Promise -} - -export interface ServiceEndpoint { - serviceName: string - method: string - urlPath: string -} -export interface UserCustomParameters { - [key: string]: any -} - export class Provider { /** * Returns the provider endpoints diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index 7295e074..2b97edbf 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -1,2 +1,4 @@ export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' export const GASLIMIT_DEFAULT = 1000000 +export const MAX_UINT_256 = + '115792089237316195423570985008687907853269984665640564039457584007913129639934' diff --git a/test/unit/pools/fixedRate/FixedRateExchange.test.ts b/test/unit/pools/fixedRate/FixedRateExchange.test.ts index dba2b639..6d09be46 100644 --- a/test/unit/pools/fixedRate/FixedRateExchange.test.ts +++ b/test/unit/pools/fixedRate/FixedRateExchange.test.ts @@ -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(web3, contracts.fixedRateAddress, 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(web3, contracts.fixedRateAddress, 8996) assert(fixedRate != null) })