mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Merge 8699e4a8bb30b3ecb7ee894412ebe85267fddd67 into ae2ff1ccde53ace9841844c316a855de271f9a3f
This commit is contained in:
commit
9da0268be6
@ -1,6 +1,13 @@
|
||||
import { BigNumber } from 'ethers'
|
||||
import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
|
||||
import { generateDtName, ZERO_ADDRESS, sendTx, getEventFromTx } from '../utils'
|
||||
import {
|
||||
generateDtName,
|
||||
ZERO_ADDRESS,
|
||||
sendTx,
|
||||
getEventFromTx,
|
||||
getTokenDecimals,
|
||||
LoggerInstance
|
||||
} from '../utils'
|
||||
import {
|
||||
AbiItem,
|
||||
FreCreationParams,
|
||||
@ -553,6 +560,16 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
if (!dtParams.name || !dtParams.symbol) {
|
||||
;({ name, symbol } = generateDtName())
|
||||
}
|
||||
|
||||
let feeTokenDecimals = 18
|
||||
if (dtParams.feeToken !== ZERO_ADDRESS) {
|
||||
try {
|
||||
feeTokenDecimals = await getTokenDecimals(this.signer, dtParams.feeToken)
|
||||
} catch (error) {
|
||||
LoggerInstance.error('getTokenDecimals error', error)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
templateIndex: dtParams.templateIndex,
|
||||
strings: [dtParams.name || name, dtParams.symbol || symbol],
|
||||
@ -564,7 +581,7 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
],
|
||||
uints: [
|
||||
await this.amountToUnits(null, dtParams.cap, 18),
|
||||
await this.amountToUnits(null, dtParams.feeAmount, 18)
|
||||
await this.amountToUnits(null, dtParams.feeAmount, feeTokenDecimals)
|
||||
],
|
||||
bytess: []
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ describe('Fixed Rate unit test', () => {
|
||||
dtParams.mpFeeAddress = await factoryOwner.getAddress()
|
||||
})
|
||||
|
||||
describe('Test a Fixed Rate Exchange with DAI (18 Decimals)', () => {
|
||||
describe('Test a Fixed Rate Exchange with DAI (18 Decimals) as Basetoken', () => {
|
||||
it('#create an exchange', async () => {
|
||||
// CREATE AN Exchange
|
||||
// we prepare transaction parameters objects
|
||||
@ -459,7 +459,7 @@ describe('Fixed Rate unit test', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Test a Fixed Rate Exchange with USDC (6 Decimals)', () => {
|
||||
describe('Test a Fixed Rate Exchange with USDC (6 Decimals) as Basetoken', () => {
|
||||
it('#create an exchange', async () => {
|
||||
// CREATE AN Exchange
|
||||
// we prepare transaction parameters objects
|
||||
@ -811,4 +811,89 @@ describe('Fixed Rate unit test', () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Test a Fixed Rate Exchange With Different Fee Tokens', () => {
|
||||
it('#create a fixed rate exchange with DAI as feetoken', async () => {
|
||||
// CREATE AN Exchange
|
||||
// we prepare transaction parameters objects
|
||||
|
||||
const nftFactory = new NftFactory(addresses.ERC721Factory, exchangeOwner)
|
||||
|
||||
const freParams: FreCreationParams = {
|
||||
fixedRateAddress: addresses.FixedPrice,
|
||||
baseTokenAddress: addresses.MockDAI,
|
||||
owner: await exchangeOwner.getAddress(),
|
||||
marketFeeCollector: await user2.getAddress(),
|
||||
baseTokenDecimals: 18,
|
||||
datatokenDecimals: 18,
|
||||
fixedRate: '1',
|
||||
marketFee: '0.001',
|
||||
allowedConsumer: ZERO_ADDRESS,
|
||||
withMint: false
|
||||
}
|
||||
|
||||
dtParams.feeToken = addresses.MockDAI
|
||||
dtParams.feeAmount = '0.123456789'
|
||||
|
||||
const tx = await nftFactory.createNftWithDatatokenWithFixedRate(
|
||||
nftData,
|
||||
dtParams,
|
||||
freParams
|
||||
)
|
||||
const txReceipt = await tx.wait()
|
||||
const tokenCreatedEvent = getEventFromTx(txReceipt, 'TokenCreated')
|
||||
|
||||
const datatokenAddress = tokenCreatedEvent.args.newTokenAddress
|
||||
|
||||
const datatoken = new Datatoken(exchangeOwner)
|
||||
|
||||
const publishingMarketFee = await datatoken.getPublishingMarketFee(datatokenAddress)
|
||||
|
||||
assert(
|
||||
publishingMarketFee.publishMarketFeeAmount ===
|
||||
ethers.utils.parseUnits('0.123456789').toString()
|
||||
)
|
||||
})
|
||||
|
||||
it('#create a fixed rate exchange with USDC as feetoken', async () => {
|
||||
// CREATE AN Exchange
|
||||
// we prepare transaction parameters objects
|
||||
|
||||
const nftFactory = new NftFactory(addresses.ERC721Factory, exchangeOwner)
|
||||
|
||||
const freParams: FreCreationParams = {
|
||||
fixedRateAddress: addresses.FixedPrice,
|
||||
baseTokenAddress: addresses.MockDAI,
|
||||
owner: await exchangeOwner.getAddress(),
|
||||
marketFeeCollector: await user2.getAddress(),
|
||||
baseTokenDecimals: 18,
|
||||
datatokenDecimals: 18,
|
||||
fixedRate: '1',
|
||||
marketFee: '0.001',
|
||||
allowedConsumer: ZERO_ADDRESS,
|
||||
withMint: false
|
||||
}
|
||||
|
||||
dtParams.feeToken = addresses.MockUSDC
|
||||
dtParams.feeAmount = '987654321'
|
||||
|
||||
const tx = await nftFactory.createNftWithDatatokenWithFixedRate(
|
||||
nftData,
|
||||
dtParams,
|
||||
freParams
|
||||
)
|
||||
const txReceipt = await tx.wait()
|
||||
const tokenCreatedEvent = getEventFromTx(txReceipt, 'TokenCreated')
|
||||
|
||||
const datatokenAddress = tokenCreatedEvent.args.newTokenAddress
|
||||
|
||||
const datatoken = new Datatoken(exchangeOwner)
|
||||
|
||||
const publishingMarketFee = await datatoken.getPublishingMarketFee(datatokenAddress)
|
||||
assert(
|
||||
publishingMarketFee.publishMarketFeeAmount ===
|
||||
ethers.utils.parseUnits('987654321', 6).toString()
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user