From 8bcffc00a652565bd73a97fd5eae8e2811f522bc Mon Sep 17 00:00:00 2001 From: mihaisc Date: Thu, 23 Dec 2021 03:05:07 -0800 Subject: [PATCH] config and encrypt fixes (#1173) * config and encrypt fixes * small comment * fix * change in PoolCreationParams * fix * fixes * fix fileinfo * rename fileinfo -> checkFileUrl, add checkDidFiles * ensure chainId is base 10 Signed-off-by: mihaisc --- src/interfaces/PoolInterface.ts | 2 +- src/models/Config.ts | 19 ++--- src/provider/Provider.ts | 70 ++++++++++++------- src/utils/ConfigHelper.ts | 32 +++++---- src/utils/ContractParams.ts | 2 +- src/utils/DdoHelpers.ts | 2 +- test/unit/NftFactory.test.ts | 2 +- test/unit/pools/Router.test.ts | 4 +- test/unit/pools/balancer/Pool.test.ts | 4 +- .../pools/ssContracts/SideStaking.test.ts | 4 +- 10 files changed, 83 insertions(+), 58 deletions(-) diff --git a/src/interfaces/PoolInterface.ts b/src/interfaces/PoolInterface.ts index 8f4b9d9b..f2368a79 100644 --- a/src/interfaces/PoolInterface.ts +++ b/src/interfaces/PoolInterface.ts @@ -11,7 +11,7 @@ export interface PoolCreationParams { vestedBlocks: number initialBasetokenLiquidity: string swapFeeLiquidityProvider: number - swapFeeMarketPlaceRunner: number + swapFeeMarketRunner: number } export interface CurrentFees { diff --git a/src/models/Config.ts b/src/models/Config.ts index ff46c1cd..faf4d559 100644 --- a/src/models/Config.ts +++ b/src/models/Config.ts @@ -42,13 +42,13 @@ export class Config { * Factory address * @type {string} */ - public factoryAddress?: string + public erc721FactoryAddress?: string /** * Factory ABI * @type {string} */ - public factoryABI?: AbiItem | AbiItem[] + public erc721FFactoryABI?: AbiItem | AbiItem[] /** * datatokens ABI @@ -57,10 +57,10 @@ export class Config { public datatokensABI?: AbiItem | AbiItem[] /** - * Pool Factory address + * Pool Template address * @type {string} */ - public poolFactoryAddress?: string + public poolTemplateAddress?: string /** * Pool Factory ABI @@ -99,16 +99,17 @@ export class Config { public dispenserABI?: AbiItem | AbiItem[] /** - * DDOContractAddress + * OPFCommunityFeeCollector * @type {string} */ - public metadataContractAddress?: string + public opfCommunityFeeCollector?: string /** - * DDOContractABI - * @type {any} + * SideStaking address + * @type {string} */ - public metadataContractABI?: AbiItem | AbiItem[] + public sideStakingAddress?: string + /** * block number of the deployment * @type {number} diff --git a/src/provider/Provider.ts b/src/provider/Provider.ts index fee2a45b..7e5dc92a 100644 --- a/src/provider/Provider.ts +++ b/src/provider/Provider.ts @@ -113,39 +113,25 @@ export class Provider { return signature } - /** Encrypt DDO using the Provider's own symmetric key - * @param {string} did Identifier of the asset to be registered in ocean - * @param {string} accountId Publisher address - * @param {string} document document description object (DDO) + /** Encrypt data using the Provider's own symmetric key + * @param {string} data data in json format that needs to be sent , it can either be a DDO or a File array * @param {string} providerUri provider uri address - * @param {string} fetchMethod fetch client instance + * @param {string} postMethod http post method * @return {Promise} urlDetails */ - public async encrypt( - did: string, - accountId: string, - document: any, - providerUri: string, - fetchMethod: any - ): Promise { + public async encrypt(data: any, providerUri: string, postMethod: any): Promise { const providerEndpoints = await this.getEndpoints(providerUri) const serviceEndpoints = await this.getServiceEndpoints( providerUri, providerEndpoints ) - - const args = { - documentId: did, - document: JSON.stringify(document), - publisherAddress: accountId - } const path = this.getEndpointURL(serviceEndpoints, 'encrypt') ? this.getEndpointURL(serviceEndpoints, 'encrypt').urlPath : null if (!path) return null try { - const response = await fetchMethod(path, decodeURI(JSON.stringify(args))) + const response = await postMethod(path, decodeURI(JSON.stringify(data))) return response } catch (e) { LoggerInstance.error(e) @@ -153,13 +139,49 @@ export class Provider { } } - /** Get URL details (if possible) - * @param {string | DID} url or did - * @param {string} providerUri Identifier of the asset to be registered in ocean + /** Get DDO File details (if possible) + * @param {string} did did + * @param {number} serviceId the id of the service for which to check the files + * @param {string} providerUri uri of the provider that will be used to check the file * @param {string} fetchMethod fetch client instance * @return {Promise} urlDetails */ - public async fileinfo( + public async checkDidFiles( + did: string, + serviceId: number, + providerUri: string, + fetchMethod: any + ): Promise { + const providerEndpoints = await this.getEndpoints(providerUri) + const serviceEndpoints = await this.getServiceEndpoints( + providerUri, + providerEndpoints + ) + const args = { did: did, serviceId: serviceId } + const files: FileMetadata[] = [] + const path = this.getEndpointURL(serviceEndpoints, 'fileinfo') + ? this.getEndpointURL(serviceEndpoints, 'fileinfo').urlPath + : null + if (!path) return null + try { + const response = await fetchMethod(path, JSON.stringify(args)) + const results: FileMetadata[] = await response.json() + for (const result of results) { + files.push(result) + } + return files + } catch (e) { + return null + } + } + + /** Get URL details (if possible) + * @param {string} url or did + * @param {string} providerUri uri of the provider that will be used to check the file + * @param {string} fetchMethod fetch client instance + * @return {Promise} urlDetails + */ + public async checkFileUrl( url: string, providerUri: string, fetchMethod: any @@ -169,7 +191,7 @@ export class Provider { providerUri, providerEndpoints ) - const args = { url } + const args = { url: url, type: 'url' } const files: FileMetadata[] = [] const path = this.getEndpointURL(serviceEndpoints, 'fileinfo') ? this.getEndpointURL(serviceEndpoints, 'fileinfo').urlPath diff --git a/src/utils/ConfigHelper.ts b/src/utils/ConfigHelper.ts index e1cd0bc9..7f12c9bb 100644 --- a/src/utils/ConfigHelper.ts +++ b/src/utils/ConfigHelper.ts @@ -15,11 +15,9 @@ const configHelperNetworksBase: Config = { explorerUri: null, oceanTokenAddress: null, oceanTokenSymbol: 'OCEAN', - factoryAddress: '0x1234', - poolFactoryAddress: null, + poolTemplateAddress: null, fixedRateExchangeAddress: null, dispenserAddress: null, - metadataContractAddress: null, startBlock: 0 } @@ -158,21 +156,23 @@ export class ConfigHelper { let configAddresses: Partial if (DefaultContractsAddresses[network]) { const { - DTFactory, - BFactory, FixedRateExchange, Dispenser, - Metadata, + Staking, + poolTemplate, + OPFCommunityFeeCollector, + ERC721Factory, Ocean, chainId, startBlock } = DefaultContractsAddresses[network] configAddresses = { - factoryAddress: DTFactory, - poolFactoryAddress: BFactory, + erc721FactoryAddress: ERC721Factory, + sideStakingAddress: Staking, + opfCommunityFeeCollector: OPFCommunityFeeCollector, + poolTemplateAddress: poolTemplate, fixedRateExchangeAddress: FixedRateExchange, dispenserAddress: Dispenser, - metadataContractAddress: Metadata, oceanTokenAddress: Ocean, chainId: chainId, startBlock: startBlock, @@ -190,21 +190,23 @@ export class ConfigHelper { ) ) const { - DTFactory, - BFactory, FixedRateExchange, Dispenser, - Metadata, + Staking, + poolTemplate, + ERC721Factory, + OPFCommunityFeeCollector, Ocean, chainId, startBlock } = data[network] configAddresses = { - factoryAddress: DTFactory, - poolFactoryAddress: BFactory, + erc721FactoryAddress: ERC721Factory, + sideStakingAddress: Staking, + opfCommunityFeeCollector: OPFCommunityFeeCollector, + poolTemplateAddress: poolTemplate, fixedRateExchangeAddress: FixedRateExchange, dispenserAddress: Dispenser, - metadataContractAddress: Metadata, oceanTokenAddress: Ocean, chainId: chainId, startBlock: startBlock, diff --git a/src/utils/ContractParams.ts b/src/utils/ContractParams.ts index 4622c182..f2523048 100644 --- a/src/utils/ContractParams.ts +++ b/src/utils/ContractParams.ts @@ -62,6 +62,6 @@ export function getPoolCreationParams(poolParams: PoolCreationParams): any { poolParams.vestedBlocks, Web3.utils.toWei(poolParams.initialBasetokenLiquidity) ], - swapFees: [poolParams.swapFeeLiquidityProvider, poolParams.swapFeeMarketPlaceRunner] + swapFees: [poolParams.swapFeeLiquidityProvider, poolParams.swapFeeMarketRunner] } } diff --git a/src/utils/DdoHelpers.ts b/src/utils/DdoHelpers.ts index 2991f9a6..23b9406f 100644 --- a/src/utils/DdoHelpers.ts +++ b/src/utils/DdoHelpers.ts @@ -3,7 +3,7 @@ import Web3 from 'web3' export function generateDid(erc721Address: string, chainId: number): string { erc721Address = Web3.utils.toChecksumAddress(erc721Address) - const checksum = sha256(erc721Address + chainId) + const checksum = sha256(erc721Address + chainId.toString(10)) return `did:op:${checksum.toString()}` } diff --git a/test/unit/NftFactory.test.ts b/test/unit/NftFactory.test.ts index 362769d6..6b48ca0d 100644 --- a/test/unit/NftFactory.test.ts +++ b/test/unit/NftFactory.test.ts @@ -237,7 +237,7 @@ describe('Nft Factory test', () => { vestedBlocks: 2500000, initialBasetokenLiquidity: '2000', swapFeeLiquidityProvider: 1e15, - swapFeeMarketPlaceRunner: 1e15 + swapFeeMarketRunner: 1e15 } const txReceipt = await nftFactory.createNftErcWithPool( diff --git a/test/unit/pools/Router.test.ts b/test/unit/pools/Router.test.ts index f403e1b7..0a136cc4 100644 --- a/test/unit/pools/Router.test.ts +++ b/test/unit/pools/Router.test.ts @@ -203,7 +203,7 @@ describe('Router unit test', () => { vestedBlocks: 2500000, initialBasetokenLiquidity: '2000', swapFeeLiquidityProvider: 1e15, - swapFeeMarketPlaceRunner: 1e15 + swapFeeMarketRunner: 1e15 } const nftFactory = new NftFactory( @@ -256,7 +256,7 @@ describe('Router unit test', () => { vestedBlocks: 2500000, initialBasetokenLiquidity: '2000', swapFeeLiquidityProvider: 1e15, - swapFeeMarketPlaceRunner: 1e15 + swapFeeMarketRunner: 1e15 } const txReceipt2 = await nftFactory.createNftErcWithPool( diff --git a/test/unit/pools/balancer/Pool.test.ts b/test/unit/pools/balancer/Pool.test.ts index bfe21965..5dfe1a15 100644 --- a/test/unit/pools/balancer/Pool.test.ts +++ b/test/unit/pools/balancer/Pool.test.ts @@ -157,7 +157,7 @@ describe('Pool unit test', () => { vestedBlocks: 2500000, initialBasetokenLiquidity: '2000', swapFeeLiquidityProvider: 1e15, - swapFeeMarketPlaceRunner: 1e15 + swapFeeMarketRunner: 1e15 } const nftFactory = new NftFactory( @@ -630,7 +630,7 @@ describe('Pool unit test', () => { await pool.amountToUnits(contracts.usdcAddress, '2000') ), swapFeeLiquidityProvider: 1e15, - swapFeeMarketPlaceRunner: 1e15 + swapFeeMarketRunner: 1e15 } const nftFactory = new NftFactory( diff --git a/test/unit/pools/ssContracts/SideStaking.test.ts b/test/unit/pools/ssContracts/SideStaking.test.ts index 0ca606e6..399c816d 100644 --- a/test/unit/pools/ssContracts/SideStaking.test.ts +++ b/test/unit/pools/ssContracts/SideStaking.test.ts @@ -170,7 +170,7 @@ describe('SideStaking unit test', () => { vestedBlocks: vestedBlocks, initialBasetokenLiquidity: '2000', swapFeeLiquidityProvider: 1e15, - swapFeeMarketPlaceRunner: 1e15 + swapFeeMarketRunner: 1e15 } const txReceipt = await nftFactory.createNftErcWithPool( @@ -468,7 +468,7 @@ describe('SideStaking unit test', () => { await pool.amountToUnits(contracts.usdcAddress, '2000') ), swapFeeLiquidityProvider: 1e15, - swapFeeMarketPlaceRunner: 1e15 + swapFeeMarketRunner: 1e15 } const txReceipt = await nftFactory.createNftErcWithPool(