mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
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 <mihai.scarlat@smartcontrol.ro>
This commit is contained in:
parent
f42673ef5e
commit
8bcffc00a6
@ -11,7 +11,7 @@ export interface PoolCreationParams {
|
||||
vestedBlocks: number
|
||||
initialBasetokenLiquidity: string
|
||||
swapFeeLiquidityProvider: number
|
||||
swapFeeMarketPlaceRunner: number
|
||||
swapFeeMarketRunner: number
|
||||
}
|
||||
|
||||
export interface CurrentFees {
|
||||
|
@ -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}
|
||||
|
@ -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<string>} urlDetails
|
||||
*/
|
||||
public async encrypt(
|
||||
did: string,
|
||||
accountId: string,
|
||||
document: any,
|
||||
providerUri: string,
|
||||
fetchMethod: any
|
||||
): Promise<any> {
|
||||
public async encrypt(data: any, providerUri: string, postMethod: any): Promise<any> {
|
||||
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<FileMetadata[]>} urlDetails
|
||||
*/
|
||||
public async fileinfo(
|
||||
public async checkDidFiles(
|
||||
did: string,
|
||||
serviceId: number,
|
||||
providerUri: string,
|
||||
fetchMethod: any
|
||||
): Promise<FileMetadata[]> {
|
||||
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<FileMetadata[]>} 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
|
||||
|
@ -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<Config>
|
||||
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,
|
||||
|
@ -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]
|
||||
}
|
||||
}
|
||||
|
@ -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()}`
|
||||
}
|
||||
|
||||
|
@ -237,7 +237,7 @@ describe('Nft Factory test', () => {
|
||||
vestedBlocks: 2500000,
|
||||
initialBasetokenLiquidity: '2000',
|
||||
swapFeeLiquidityProvider: 1e15,
|
||||
swapFeeMarketPlaceRunner: 1e15
|
||||
swapFeeMarketRunner: 1e15
|
||||
}
|
||||
|
||||
const txReceipt = await nftFactory.createNftErcWithPool(
|
||||
|
@ -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(
|
||||
|
@ -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(
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user