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
|
vestedBlocks: number
|
||||||
initialBasetokenLiquidity: string
|
initialBasetokenLiquidity: string
|
||||||
swapFeeLiquidityProvider: number
|
swapFeeLiquidityProvider: number
|
||||||
swapFeeMarketPlaceRunner: number
|
swapFeeMarketRunner: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CurrentFees {
|
export interface CurrentFees {
|
||||||
|
@ -42,13 +42,13 @@ export class Config {
|
|||||||
* Factory address
|
* Factory address
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
public factoryAddress?: string
|
public erc721FactoryAddress?: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory ABI
|
* Factory ABI
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
public factoryABI?: AbiItem | AbiItem[]
|
public erc721FFactoryABI?: AbiItem | AbiItem[]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* datatokens ABI
|
* datatokens ABI
|
||||||
@ -57,10 +57,10 @@ export class Config {
|
|||||||
public datatokensABI?: AbiItem | AbiItem[]
|
public datatokensABI?: AbiItem | AbiItem[]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pool Factory address
|
* Pool Template address
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
public poolFactoryAddress?: string
|
public poolTemplateAddress?: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pool Factory ABI
|
* Pool Factory ABI
|
||||||
@ -99,16 +99,17 @@ export class Config {
|
|||||||
public dispenserABI?: AbiItem | AbiItem[]
|
public dispenserABI?: AbiItem | AbiItem[]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DDOContractAddress
|
* OPFCommunityFeeCollector
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
public metadataContractAddress?: string
|
public opfCommunityFeeCollector?: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DDOContractABI
|
* SideStaking address
|
||||||
* @type {any}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
public metadataContractABI?: AbiItem | AbiItem[]
|
public sideStakingAddress?: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* block number of the deployment
|
* block number of the deployment
|
||||||
* @type {number}
|
* @type {number}
|
||||||
|
@ -113,39 +113,25 @@ export class Provider {
|
|||||||
return signature
|
return signature
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Encrypt DDO using the Provider's own symmetric key
|
/** Encrypt data using the Provider's own symmetric key
|
||||||
* @param {string} did Identifier of the asset to be registered in ocean
|
* @param {string} data data in json format that needs to be sent , it can either be a DDO or a File array
|
||||||
* @param {string} accountId Publisher address
|
|
||||||
* @param {string} document document description object (DDO)
|
|
||||||
* @param {string} providerUri provider uri address
|
* @param {string} providerUri provider uri address
|
||||||
* @param {string} fetchMethod fetch client instance
|
* @param {string} postMethod http post method
|
||||||
* @return {Promise<string>} urlDetails
|
* @return {Promise<string>} urlDetails
|
||||||
*/
|
*/
|
||||||
public async encrypt(
|
public async encrypt(data: any, providerUri: string, postMethod: any): Promise<any> {
|
||||||
did: string,
|
|
||||||
accountId: string,
|
|
||||||
document: any,
|
|
||||||
providerUri: string,
|
|
||||||
fetchMethod: any
|
|
||||||
): Promise<any> {
|
|
||||||
const providerEndpoints = await this.getEndpoints(providerUri)
|
const providerEndpoints = await this.getEndpoints(providerUri)
|
||||||
const serviceEndpoints = await this.getServiceEndpoints(
|
const serviceEndpoints = await this.getServiceEndpoints(
|
||||||
providerUri,
|
providerUri,
|
||||||
providerEndpoints
|
providerEndpoints
|
||||||
)
|
)
|
||||||
|
|
||||||
const args = {
|
|
||||||
documentId: did,
|
|
||||||
document: JSON.stringify(document),
|
|
||||||
publisherAddress: accountId
|
|
||||||
}
|
|
||||||
const path = this.getEndpointURL(serviceEndpoints, 'encrypt')
|
const path = this.getEndpointURL(serviceEndpoints, 'encrypt')
|
||||||
? this.getEndpointURL(serviceEndpoints, 'encrypt').urlPath
|
? this.getEndpointURL(serviceEndpoints, 'encrypt').urlPath
|
||||||
: null
|
: null
|
||||||
|
|
||||||
if (!path) return null
|
if (!path) return null
|
||||||
try {
|
try {
|
||||||
const response = await fetchMethod(path, decodeURI(JSON.stringify(args)))
|
const response = await postMethod(path, decodeURI(JSON.stringify(data)))
|
||||||
return response
|
return response
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(e)
|
LoggerInstance.error(e)
|
||||||
@ -153,13 +139,49 @@ export class Provider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get URL details (if possible)
|
/** Get DDO File details (if possible)
|
||||||
* @param {string | DID} url or did
|
* @param {string} did did
|
||||||
* @param {string} providerUri Identifier of the asset to be registered in ocean
|
* @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
|
* @param {string} fetchMethod fetch client instance
|
||||||
* @return {Promise<FileMetadata[]>} urlDetails
|
* @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,
|
url: string,
|
||||||
providerUri: string,
|
providerUri: string,
|
||||||
fetchMethod: any
|
fetchMethod: any
|
||||||
@ -169,7 +191,7 @@ export class Provider {
|
|||||||
providerUri,
|
providerUri,
|
||||||
providerEndpoints
|
providerEndpoints
|
||||||
)
|
)
|
||||||
const args = { url }
|
const args = { url: url, type: 'url' }
|
||||||
const files: FileMetadata[] = []
|
const files: FileMetadata[] = []
|
||||||
const path = this.getEndpointURL(serviceEndpoints, 'fileinfo')
|
const path = this.getEndpointURL(serviceEndpoints, 'fileinfo')
|
||||||
? this.getEndpointURL(serviceEndpoints, 'fileinfo').urlPath
|
? this.getEndpointURL(serviceEndpoints, 'fileinfo').urlPath
|
||||||
|
@ -15,11 +15,9 @@ const configHelperNetworksBase: Config = {
|
|||||||
explorerUri: null,
|
explorerUri: null,
|
||||||
oceanTokenAddress: null,
|
oceanTokenAddress: null,
|
||||||
oceanTokenSymbol: 'OCEAN',
|
oceanTokenSymbol: 'OCEAN',
|
||||||
factoryAddress: '0x1234',
|
poolTemplateAddress: null,
|
||||||
poolFactoryAddress: null,
|
|
||||||
fixedRateExchangeAddress: null,
|
fixedRateExchangeAddress: null,
|
||||||
dispenserAddress: null,
|
dispenserAddress: null,
|
||||||
metadataContractAddress: null,
|
|
||||||
startBlock: 0
|
startBlock: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,21 +156,23 @@ export class ConfigHelper {
|
|||||||
let configAddresses: Partial<Config>
|
let configAddresses: Partial<Config>
|
||||||
if (DefaultContractsAddresses[network]) {
|
if (DefaultContractsAddresses[network]) {
|
||||||
const {
|
const {
|
||||||
DTFactory,
|
|
||||||
BFactory,
|
|
||||||
FixedRateExchange,
|
FixedRateExchange,
|
||||||
Dispenser,
|
Dispenser,
|
||||||
Metadata,
|
Staking,
|
||||||
|
poolTemplate,
|
||||||
|
OPFCommunityFeeCollector,
|
||||||
|
ERC721Factory,
|
||||||
Ocean,
|
Ocean,
|
||||||
chainId,
|
chainId,
|
||||||
startBlock
|
startBlock
|
||||||
} = DefaultContractsAddresses[network]
|
} = DefaultContractsAddresses[network]
|
||||||
configAddresses = {
|
configAddresses = {
|
||||||
factoryAddress: DTFactory,
|
erc721FactoryAddress: ERC721Factory,
|
||||||
poolFactoryAddress: BFactory,
|
sideStakingAddress: Staking,
|
||||||
|
opfCommunityFeeCollector: OPFCommunityFeeCollector,
|
||||||
|
poolTemplateAddress: poolTemplate,
|
||||||
fixedRateExchangeAddress: FixedRateExchange,
|
fixedRateExchangeAddress: FixedRateExchange,
|
||||||
dispenserAddress: Dispenser,
|
dispenserAddress: Dispenser,
|
||||||
metadataContractAddress: Metadata,
|
|
||||||
oceanTokenAddress: Ocean,
|
oceanTokenAddress: Ocean,
|
||||||
chainId: chainId,
|
chainId: chainId,
|
||||||
startBlock: startBlock,
|
startBlock: startBlock,
|
||||||
@ -190,21 +190,23 @@ export class ConfigHelper {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
const {
|
const {
|
||||||
DTFactory,
|
|
||||||
BFactory,
|
|
||||||
FixedRateExchange,
|
FixedRateExchange,
|
||||||
Dispenser,
|
Dispenser,
|
||||||
Metadata,
|
Staking,
|
||||||
|
poolTemplate,
|
||||||
|
ERC721Factory,
|
||||||
|
OPFCommunityFeeCollector,
|
||||||
Ocean,
|
Ocean,
|
||||||
chainId,
|
chainId,
|
||||||
startBlock
|
startBlock
|
||||||
} = data[network]
|
} = data[network]
|
||||||
configAddresses = {
|
configAddresses = {
|
||||||
factoryAddress: DTFactory,
|
erc721FactoryAddress: ERC721Factory,
|
||||||
poolFactoryAddress: BFactory,
|
sideStakingAddress: Staking,
|
||||||
|
opfCommunityFeeCollector: OPFCommunityFeeCollector,
|
||||||
|
poolTemplateAddress: poolTemplate,
|
||||||
fixedRateExchangeAddress: FixedRateExchange,
|
fixedRateExchangeAddress: FixedRateExchange,
|
||||||
dispenserAddress: Dispenser,
|
dispenserAddress: Dispenser,
|
||||||
metadataContractAddress: Metadata,
|
|
||||||
oceanTokenAddress: Ocean,
|
oceanTokenAddress: Ocean,
|
||||||
chainId: chainId,
|
chainId: chainId,
|
||||||
startBlock: startBlock,
|
startBlock: startBlock,
|
||||||
|
@ -62,6 +62,6 @@ export function getPoolCreationParams(poolParams: PoolCreationParams): any {
|
|||||||
poolParams.vestedBlocks,
|
poolParams.vestedBlocks,
|
||||||
Web3.utils.toWei(poolParams.initialBasetokenLiquidity)
|
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 {
|
export function generateDid(erc721Address: string, chainId: number): string {
|
||||||
erc721Address = Web3.utils.toChecksumAddress(erc721Address)
|
erc721Address = Web3.utils.toChecksumAddress(erc721Address)
|
||||||
const checksum = sha256(erc721Address + chainId)
|
const checksum = sha256(erc721Address + chainId.toString(10))
|
||||||
return `did:op:${checksum.toString()}`
|
return `did:op:${checksum.toString()}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ describe('Nft Factory test', () => {
|
|||||||
vestedBlocks: 2500000,
|
vestedBlocks: 2500000,
|
||||||
initialBasetokenLiquidity: '2000',
|
initialBasetokenLiquidity: '2000',
|
||||||
swapFeeLiquidityProvider: 1e15,
|
swapFeeLiquidityProvider: 1e15,
|
||||||
swapFeeMarketPlaceRunner: 1e15
|
swapFeeMarketRunner: 1e15
|
||||||
}
|
}
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftErcWithPool(
|
const txReceipt = await nftFactory.createNftErcWithPool(
|
||||||
|
@ -203,7 +203,7 @@ describe('Router unit test', () => {
|
|||||||
vestedBlocks: 2500000,
|
vestedBlocks: 2500000,
|
||||||
initialBasetokenLiquidity: '2000',
|
initialBasetokenLiquidity: '2000',
|
||||||
swapFeeLiquidityProvider: 1e15,
|
swapFeeLiquidityProvider: 1e15,
|
||||||
swapFeeMarketPlaceRunner: 1e15
|
swapFeeMarketRunner: 1e15
|
||||||
}
|
}
|
||||||
|
|
||||||
const nftFactory = new NftFactory(
|
const nftFactory = new NftFactory(
|
||||||
@ -256,7 +256,7 @@ describe('Router unit test', () => {
|
|||||||
vestedBlocks: 2500000,
|
vestedBlocks: 2500000,
|
||||||
initialBasetokenLiquidity: '2000',
|
initialBasetokenLiquidity: '2000',
|
||||||
swapFeeLiquidityProvider: 1e15,
|
swapFeeLiquidityProvider: 1e15,
|
||||||
swapFeeMarketPlaceRunner: 1e15
|
swapFeeMarketRunner: 1e15
|
||||||
}
|
}
|
||||||
|
|
||||||
const txReceipt2 = await nftFactory.createNftErcWithPool(
|
const txReceipt2 = await nftFactory.createNftErcWithPool(
|
||||||
|
@ -157,7 +157,7 @@ describe('Pool unit test', () => {
|
|||||||
vestedBlocks: 2500000,
|
vestedBlocks: 2500000,
|
||||||
initialBasetokenLiquidity: '2000',
|
initialBasetokenLiquidity: '2000',
|
||||||
swapFeeLiquidityProvider: 1e15,
|
swapFeeLiquidityProvider: 1e15,
|
||||||
swapFeeMarketPlaceRunner: 1e15
|
swapFeeMarketRunner: 1e15
|
||||||
}
|
}
|
||||||
|
|
||||||
const nftFactory = new NftFactory(
|
const nftFactory = new NftFactory(
|
||||||
@ -630,7 +630,7 @@ describe('Pool unit test', () => {
|
|||||||
await pool.amountToUnits(contracts.usdcAddress, '2000')
|
await pool.amountToUnits(contracts.usdcAddress, '2000')
|
||||||
),
|
),
|
||||||
swapFeeLiquidityProvider: 1e15,
|
swapFeeLiquidityProvider: 1e15,
|
||||||
swapFeeMarketPlaceRunner: 1e15
|
swapFeeMarketRunner: 1e15
|
||||||
}
|
}
|
||||||
|
|
||||||
const nftFactory = new NftFactory(
|
const nftFactory = new NftFactory(
|
||||||
|
@ -170,7 +170,7 @@ describe('SideStaking unit test', () => {
|
|||||||
vestedBlocks: vestedBlocks,
|
vestedBlocks: vestedBlocks,
|
||||||
initialBasetokenLiquidity: '2000',
|
initialBasetokenLiquidity: '2000',
|
||||||
swapFeeLiquidityProvider: 1e15,
|
swapFeeLiquidityProvider: 1e15,
|
||||||
swapFeeMarketPlaceRunner: 1e15
|
swapFeeMarketRunner: 1e15
|
||||||
}
|
}
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftErcWithPool(
|
const txReceipt = await nftFactory.createNftErcWithPool(
|
||||||
@ -468,7 +468,7 @@ describe('SideStaking unit test', () => {
|
|||||||
await pool.amountToUnits(contracts.usdcAddress, '2000')
|
await pool.amountToUnits(contracts.usdcAddress, '2000')
|
||||||
),
|
),
|
||||||
swapFeeLiquidityProvider: 1e15,
|
swapFeeLiquidityProvider: 1e15,
|
||||||
swapFeeMarketPlaceRunner: 1e15
|
swapFeeMarketRunner: 1e15
|
||||||
}
|
}
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftErcWithPool(
|
const txReceipt = await nftFactory.createNftErcWithPool(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user