1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

Merge pull request #1748 from oceanprotocol/issue-1746-feeTOken-decimals

Fixing fee token decimals
This commit is contained in:
Jamie Hewitt 2023-07-12 14:30:41 +03:00 committed by GitHub
commit 419ff6c631
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 106 additions and 4 deletions

View File

@ -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: []
}

View File

@ -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()
)
})
})
})