mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Merge pull request #1428 from oceanprotocol/issue-1335-setPublishingMarketFee-function
Creating set publishing market fee function
This commit is contained in:
commit
1e2ed45a8f
@ -15,3 +15,9 @@ export interface ConsumeMarketFee {
|
|||||||
consumeMarketFeeToken: string // address of the token marketplace wants to add fee on top
|
consumeMarketFeeToken: string // address of the token marketplace wants to add fee on top
|
||||||
consumeMarketFeeAmount: string
|
consumeMarketFeeAmount: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PublishingMarketFee {
|
||||||
|
publishMarketFeeAddress: string
|
||||||
|
publishMarketFeeToken: string
|
||||||
|
publishMarketFeeAmount: string
|
||||||
|
}
|
||||||
|
@ -18,7 +18,8 @@ import {
|
|||||||
ConsumeMarketFee,
|
ConsumeMarketFee,
|
||||||
FreOrderParams,
|
FreOrderParams,
|
||||||
FreCreationParams,
|
FreCreationParams,
|
||||||
ProviderFees
|
ProviderFees,
|
||||||
|
PublishingMarketFee
|
||||||
} from '../@types'
|
} from '../@types'
|
||||||
import { Nft } from './NFT'
|
import { Nft } from './NFT'
|
||||||
import { Config } from '../models/index.js'
|
import { Config } from '../models/index.js'
|
||||||
@ -1311,4 +1312,102 @@ export class Datatoken {
|
|||||||
const balance = await dtContract.methods.balanceOf(address).call()
|
const balance = await dtContract.methods.balanceOf(address).call()
|
||||||
return this.web3.utils.fromWei(balance)
|
return this.web3.utils.fromWei(balance)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev estGasSetPublishingMarketFee
|
||||||
|
* Estimating gas for publishMarketFeeAddress method
|
||||||
|
* @param {string} datatokenAddress Datatoken adress
|
||||||
|
* @param {string} publishMarketFeeAddress new publish Market Fee Address
|
||||||
|
* @param {string} publishMarketFeeToken new publish Market Fee Token
|
||||||
|
* @param {string} publishMarketFeeAmount new fee amount
|
||||||
|
* @param {String} address user adress
|
||||||
|
*/
|
||||||
|
public async estGasSetPublishingMarketFee(
|
||||||
|
datatokenAddress: string,
|
||||||
|
publishMarketFeeAddress: string,
|
||||||
|
publishMarketFeeToken: string,
|
||||||
|
publishMarketFeeAmount: string,
|
||||||
|
address: string
|
||||||
|
): Promise<number> {
|
||||||
|
// Estimate gas cost for publishMarketFeeAddress method
|
||||||
|
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, datatokenAddress, {
|
||||||
|
from: address
|
||||||
|
})
|
||||||
|
return estimateGas(
|
||||||
|
address,
|
||||||
|
dtContract.methods.setPublishingMarketFee,
|
||||||
|
publishMarketFeeAddress,
|
||||||
|
publishMarketFeeToken,
|
||||||
|
publishMarketFeeAmount
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev setPublishingMarketFee
|
||||||
|
* Only publishMarketFeeAddress can call it
|
||||||
|
* This function allows to set the fee required by the publisherMarket
|
||||||
|
* @param {string} datatokenAddress Datatoken adress
|
||||||
|
* @param {string} publishMarketFeeAddress new publish Market Fee Address
|
||||||
|
* @param {string} publishMarketFeeToken new publish Market Fee Token
|
||||||
|
* @param {string} publishMarketFeeAmount new fee amount
|
||||||
|
* @param {String} address user adress
|
||||||
|
*/
|
||||||
|
public async setPublishingMarketFee(
|
||||||
|
datatokenAddress: string,
|
||||||
|
publishMarketFeeAddress: string,
|
||||||
|
publishMarketFeeToken: string,
|
||||||
|
publishMarketFeeAmount: string,
|
||||||
|
address: string
|
||||||
|
) {
|
||||||
|
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, datatokenAddress, {
|
||||||
|
from: address
|
||||||
|
})
|
||||||
|
const mktFeeAddress = (await dtContract.methods.getPublishingMarketFee().call())[0]
|
||||||
|
if (mktFeeAddress !== address) {
|
||||||
|
throw new Error(`Caller is not the Publishing Market Fee Address`)
|
||||||
|
}
|
||||||
|
const estGas = await this.estGasSetPublishingMarketFee(
|
||||||
|
datatokenAddress,
|
||||||
|
publishMarketFeeAddress,
|
||||||
|
publishMarketFeeToken,
|
||||||
|
publishMarketFeeAmount,
|
||||||
|
address
|
||||||
|
)
|
||||||
|
await dtContract.methods
|
||||||
|
.setPublishingMarketFee(
|
||||||
|
publishMarketFeeAddress,
|
||||||
|
publishMarketFeeToken,
|
||||||
|
publishMarketFeeAmount
|
||||||
|
)
|
||||||
|
.send({
|
||||||
|
from: address,
|
||||||
|
gas: estGas + 1,
|
||||||
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev getPublishingMarketFee
|
||||||
|
* Get publishingMarket Fee
|
||||||
|
* This function allows to get the current fee set by the publishing market
|
||||||
|
* @param {String} datatokenAddress Datatoken adress
|
||||||
|
* @param {String} address user adress
|
||||||
|
* @return {Promise<PublishingMarketFee>} Current fee set by the publishing market
|
||||||
|
*/
|
||||||
|
public async getPublishingMarketFee(
|
||||||
|
datatokenAddress: string,
|
||||||
|
address: string
|
||||||
|
): Promise<PublishingMarketFee> {
|
||||||
|
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, datatokenAddress, {
|
||||||
|
from: address
|
||||||
|
})
|
||||||
|
|
||||||
|
const publishingMarketFee = await dtContract.methods.getPublishingMarketFee().call()
|
||||||
|
const returnValues = {
|
||||||
|
publishMarketFeeAddress: publishingMarketFee[0],
|
||||||
|
publishMarketFeeToken: publishingMarketFee[1],
|
||||||
|
publishMarketFeeAmount: publishingMarketFee[2]
|
||||||
|
}
|
||||||
|
return returnValues
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -595,4 +595,66 @@ describe('Datatoken', () => {
|
|||||||
const key = web3.utils.keccak256(datatokenAddress)
|
const key = web3.utils.keccak256(datatokenAddress)
|
||||||
assert((await nftDatatoken.getData(nftAddress, key)) === OldData)
|
assert((await nftDatatoken.getData(nftAddress, key)) === OldData)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('#setPublishingMarketFee - User should not be able to set the Publishing Market Fee', async () => {
|
||||||
|
const originalPublishingMarketFee = await datatoken.getPublishingMarketFee(
|
||||||
|
datatokenAddress,
|
||||||
|
user1
|
||||||
|
)
|
||||||
|
try {
|
||||||
|
await datatoken.setPublishingMarketFee(
|
||||||
|
datatokenAddress,
|
||||||
|
user1,
|
||||||
|
contracts.daiAddress,
|
||||||
|
web3.utils.toWei('10'),
|
||||||
|
user1
|
||||||
|
)
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Message:', e.message)
|
||||||
|
assert(e.message === 'Caller is not the Publishing Market Fee Address')
|
||||||
|
}
|
||||||
|
const newPublishingMarketFee = await datatoken.getPublishingMarketFee(
|
||||||
|
datatokenAddress,
|
||||||
|
user3
|
||||||
|
)
|
||||||
|
|
||||||
|
assert(
|
||||||
|
newPublishingMarketFee.publishMarketFeeAddress ===
|
||||||
|
originalPublishingMarketFee.publishMarketFeeAddress
|
||||||
|
)
|
||||||
|
assert(
|
||||||
|
newPublishingMarketFee.publishMarketFeeAmount ===
|
||||||
|
originalPublishingMarketFee.publishMarketFeeAmount
|
||||||
|
)
|
||||||
|
assert(
|
||||||
|
newPublishingMarketFee.publishMarketFeeToken ===
|
||||||
|
originalPublishingMarketFee.publishMarketFeeToken
|
||||||
|
)
|
||||||
|
})
|
||||||
|
it('#setPublishingMarketFee - Marketplace fee address should be able to set the Publishing Market Fee', async () => {
|
||||||
|
const originalPublishingMarketFee = await datatoken.getPublishingMarketFee(
|
||||||
|
datatokenAddress,
|
||||||
|
user2
|
||||||
|
)
|
||||||
|
try {
|
||||||
|
await datatoken.setPublishingMarketFee(
|
||||||
|
datatokenAddress,
|
||||||
|
user2,
|
||||||
|
contracts.daiAddress,
|
||||||
|
web3.utils.toWei('10'),
|
||||||
|
user2
|
||||||
|
)
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Error:', e)
|
||||||
|
}
|
||||||
|
const newPublishingMarketFee = await datatoken.getPublishingMarketFee(
|
||||||
|
datatokenAddress,
|
||||||
|
user2
|
||||||
|
)
|
||||||
|
|
||||||
|
assert(newPublishingMarketFee !== originalPublishingMarketFee)
|
||||||
|
assert(newPublishingMarketFee.publishMarketFeeAddress === user2)
|
||||||
|
assert(newPublishingMarketFee.publishMarketFeeAmount === web3.utils.toWei('10'))
|
||||||
|
assert(newPublishingMarketFee.publishMarketFeeToken === contracts.daiAddress)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user