mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Merge pull request #1507 from oceanprotocol/issue-1474-refactoring-rename-from-erc20-to-datatoken
Issue-#1474: Refactoring (8): Rename from erc20 to datatoken
This commit is contained in:
commit
458dfde49b
@ -97,7 +97,7 @@ import {
|
||||
Dispenser,
|
||||
DispenserCreationParams,
|
||||
downloadFile,
|
||||
Erc20CreateParams,
|
||||
DatatokenCreateParams,
|
||||
FixedRateExchange,
|
||||
FreCreationParams,
|
||||
getHash,
|
||||
@ -252,7 +252,7 @@ For pool creation, the OCEAN token is used as the base token. The base token can
|
||||
owner: publisherAccount
|
||||
}
|
||||
|
||||
const erc20Params: Erc20CreateParams = {
|
||||
const datatokenParams: DatatokenCreateParams = {
|
||||
templateIndex: 1,
|
||||
cap: '100000',
|
||||
feeAmount: '0',
|
||||
@ -278,7 +278,7 @@ For pool creation, the OCEAN token is used as the base token. The base token can
|
||||
swapFeeMarketRunner: '0.001'
|
||||
}
|
||||
```
|
||||
Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 tokens
|
||||
Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 Datatokens
|
||||
```Typescript
|
||||
await approve(
|
||||
web3,
|
||||
@ -291,10 +291,10 @@ Before we call the contract we have to call `approve` so that the contract can m
|
||||
```
|
||||
Now we can make the contract call
|
||||
```Typescript
|
||||
const tx = await factory.createNftErc20WithPool(
|
||||
const tx = await factory.createNftWithDatatokenWithPool(
|
||||
publisherAccount,
|
||||
nftParams,
|
||||
erc20Params,
|
||||
datatokenParams,
|
||||
poolParams
|
||||
)
|
||||
|
||||
@ -353,7 +353,7 @@ Now let's console log the result to check everything is working
|
||||
const pool = new Pool(web3)
|
||||
|
||||
```
|
||||
Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 tokens
|
||||
Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 Datatokens
|
||||
```Typescript
|
||||
await approve(web3, stakerAccount, addresses.Ocean, poolAddress, '5', true)
|
||||
|
||||
@ -402,7 +402,7 @@ Now let's console log POOL_NFT_SYMBOL and consumerDTBalance to check everything
|
||||
console.log(`Consumer ${POOL_NFT_SYMBOL} balance before swap: ${consumerDTBalance}`)
|
||||
|
||||
```
|
||||
Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 tokens
|
||||
Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 Datatokens
|
||||
```Typescript
|
||||
await approve(web3, consumerAccount, addresses.Ocean, poolAddress, '100')
|
||||
|
||||
@ -526,7 +526,7 @@ Now let's console log the Consumer balance after order to check everything is wo
|
||||
owner: publisherAccount
|
||||
}
|
||||
|
||||
const erc20Params: Erc20CreateParams = {
|
||||
const datatokenParams: DatatokenCreateParams = {
|
||||
templateIndex: 1,
|
||||
cap: '100000',
|
||||
feeAmount: '0',
|
||||
@ -549,10 +549,10 @@ Now let's console log the Consumer balance after order to check everything is wo
|
||||
withMint: false
|
||||
}
|
||||
|
||||
const tx = await factory.createNftErc20WithFixedRate(
|
||||
const tx = await factory.createNftWithDatatokenWithFixedRate(
|
||||
publisherAccount,
|
||||
nftParams,
|
||||
erc20Params,
|
||||
datatokenParams,
|
||||
freParams
|
||||
)
|
||||
|
||||
@ -644,7 +644,7 @@ Let's do a quick check of the consumer ETH balance before the swap
|
||||
console.log(`Consumer ${FRE_NFT_SYMBOL} balance before swap: ${consumerDTBalance}`)
|
||||
|
||||
```
|
||||
Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 tokens
|
||||
Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 Datatokens
|
||||
```Typescript
|
||||
await approve(web3, consumerAccount, addresses.Ocean, freAddress, '100')
|
||||
await approve(
|
||||
@ -748,7 +748,7 @@ Lets check that the download URL was successfully received
|
||||
owner: publisherAccount
|
||||
}
|
||||
|
||||
const erc20Params: Erc20CreateParams = {
|
||||
const datatokenParams: DatatokenCreateParams = {
|
||||
templateIndex: 1,
|
||||
cap: '100000',
|
||||
feeAmount: '0',
|
||||
@ -766,10 +766,10 @@ Lets check that the download URL was successfully received
|
||||
allowedSwapper: ZERO_ADDRESS
|
||||
}
|
||||
|
||||
const tx = await factory.createNftErc20WithDispenser(
|
||||
const tx = await factory.createNftWithDatatokenWithDispenser(
|
||||
publisherAccount,
|
||||
nftParams,
|
||||
erc20Params,
|
||||
datatokenParams,
|
||||
dispenserParams
|
||||
)
|
||||
|
||||
|
@ -65,7 +65,7 @@ export interface Purgatory {
|
||||
|
||||
export interface AssetDatatoken {
|
||||
/**
|
||||
* Contract address of the deployed ERC20 contract.
|
||||
* Contract address of the deployed Datatoken contract.
|
||||
* @type {string}
|
||||
*/
|
||||
address: string
|
||||
@ -105,7 +105,7 @@ export interface Asset extends DDO {
|
||||
nft: AssetNft
|
||||
|
||||
/**
|
||||
* Contains information about the ERC20 datatokens attached to asset services.
|
||||
* Contains information about the ERC20 Datatokens attached to asset services.
|
||||
* @type {string}
|
||||
*/
|
||||
datatokens: AssetDatatoken[]
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { ProviderFees } from '.'
|
||||
|
||||
export interface Erc20CreateParams {
|
||||
export interface DatatokenCreateParams {
|
||||
templateIndex: number
|
||||
minter: string
|
||||
paymentCollector: string
|
@ -5,9 +5,9 @@ export * from './DDO/Metadata'
|
||||
export * from './DDO/Service'
|
||||
export * from './Asset'
|
||||
export * from './Compute'
|
||||
export * from './Datatoken'
|
||||
export * from './Dispenser'
|
||||
export * from './DownloadResponse'
|
||||
export * from './Erc20'
|
||||
export * from './FileMetadata'
|
||||
export * from './FixedPrice'
|
||||
export * from './NFT'
|
||||
|
@ -5,7 +5,7 @@ import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Fa
|
||||
import { LoggerInstance, generateDtName, estimateGas, ZERO_ADDRESS } from '../../utils'
|
||||
import {
|
||||
FreCreationParams,
|
||||
Erc20CreateParams,
|
||||
DatatokenCreateParams,
|
||||
PoolCreationParams,
|
||||
DispenserCreationParams,
|
||||
NftCreateData,
|
||||
@ -140,7 +140,7 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
}
|
||||
|
||||
/** Get Current Template Datatoken (ERC20) Count
|
||||
* @return {Promise<number>} Number of ERC20 Template added to this factory
|
||||
* @return {Promise<number>} Number of Datatoken Template added to this factory
|
||||
*/
|
||||
public async getCurrentTokenTemplateCount(): Promise<number> {
|
||||
const count = await this.contract.methods.getCurrentTemplateCount().call()
|
||||
@ -163,7 +163,7 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
return template
|
||||
}
|
||||
|
||||
/** Get Datatoken(erc20) Template
|
||||
/** Get Datatoken (ERC20) Template
|
||||
* @param {Number} index Template index
|
||||
* @return {Promise<Template>} DT Template info
|
||||
*/
|
||||
@ -172,7 +172,7 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
return template
|
||||
}
|
||||
|
||||
/** Check if ERC20 is deployed from the factory
|
||||
/** Check if Datatoken is deployed from the factory
|
||||
* @param {String} datatoken Datatoken address we want to check
|
||||
* @return {Promise<Boolean>} return true if deployed from this factory
|
||||
*/
|
||||
@ -529,11 +529,11 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
/**
|
||||
* @dev startMultipleTokenOrder
|
||||
* Used as a proxy to order multiple services
|
||||
* Users can have inifinite approvals for fees for factory instead of having one approval/ erc20 contract
|
||||
* Users can have inifinite approvals for fees for factory instead of having one approval/ Datatoken contract
|
||||
* Requires previous approval of all :
|
||||
* - consumeFeeTokens
|
||||
* - publishMarketFeeTokens
|
||||
* - erc20 datatokens
|
||||
* - ERC20 Datatokens
|
||||
* @param address Caller address
|
||||
* @param orders an array of struct tokenOrder
|
||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||
@ -563,19 +563,19 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas cost for createNftWithErc20 method
|
||||
* Estimate gas cost for createNftWithDatatoken method
|
||||
* @param address Caller address
|
||||
* @param _NftCreateData input data for nft creation
|
||||
* @param _ErcCreateData input data for erc20 creation
|
||||
* @param _NftCreateData input data for NFT creation
|
||||
* @param _ErcCreateData input data for Datatoken creation
|
||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||
*/
|
||||
|
||||
public async estGasCreateNftWithErc20(
|
||||
public async estGasCreateNftWithDatatoken(
|
||||
address: string,
|
||||
nftCreateData: NftCreateData,
|
||||
ercParams: Erc20CreateParams
|
||||
dtParams: DatatokenCreateParams
|
||||
): Promise<any> {
|
||||
const ercCreateData = this.getErcCreationParams(ercParams)
|
||||
const ercCreateData = this.getErcCreationParams(dtParams)
|
||||
return estimateGas(
|
||||
address,
|
||||
this.contract.methods.createNftWithErc20,
|
||||
@ -585,20 +585,20 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev createNftWithErc20
|
||||
* Creates a new NFT, then a ERC20,all in one call
|
||||
* @dev createNftWithDatatoken
|
||||
* Creates a new NFT, then a Datatoken,all in one call
|
||||
* @param address Caller address
|
||||
* @param _NftCreateData input data for nft creation
|
||||
* @param _ErcCreateData input data for erc20 creation
|
||||
* @param _ErcCreateData input data for Datatoken creation
|
||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||
*/
|
||||
|
||||
public async createNftWithErc20(
|
||||
public async createNftWithDatatoken(
|
||||
address: string,
|
||||
nftCreateData: NftCreateData,
|
||||
ercParams: Erc20CreateParams
|
||||
dtParams: DatatokenCreateParams
|
||||
): Promise<TransactionReceipt> {
|
||||
const ercCreateData = this.getErcCreationParams(ercParams)
|
||||
const ercCreateData = this.getErcCreationParams(dtParams)
|
||||
|
||||
const estGas = await estimateGas(
|
||||
address,
|
||||
@ -620,20 +620,20 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas cost for createNftErc20WithPool method
|
||||
* Estimate gas cost for createNftWithDatatokenWithPool method
|
||||
* @param address Caller address
|
||||
* @param nftCreateData input data for NFT Creation
|
||||
* @param ercParams input data for ERC20 Creation
|
||||
* @param dtParams input data for Datatoken Creation
|
||||
* @param poolParams input data for Pool Creation
|
||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||
*/
|
||||
public async estGasCreateNftErc20WithPool(
|
||||
public async estGasCreateNftWithDatatokenWithPool(
|
||||
address: string,
|
||||
nftCreateData: NftCreateData,
|
||||
ercParams: Erc20CreateParams,
|
||||
dtParams: DatatokenCreateParams,
|
||||
poolParams: PoolCreationParams
|
||||
): Promise<any> {
|
||||
const ercCreateData = this.getErcCreationParams(ercParams)
|
||||
const ercCreateData = this.getErcCreationParams(dtParams)
|
||||
const poolData = await this.getPoolCreationParams(poolParams)
|
||||
return estimateGas(
|
||||
address,
|
||||
@ -645,22 +645,22 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev createNftErc20WithPool
|
||||
* Creates a new NFT, then a ERC20, then a Pool, all in one call
|
||||
* @dev createNftWithDatatokenWithPool
|
||||
* Creates a new NFT, then a Datatoken, then a Pool, all in one call
|
||||
* Use this carefully, because if Pool creation fails, you are still going to pay a lot of gas
|
||||
* @param address Caller address
|
||||
* @param nftCreateData input data for NFT Creation
|
||||
* @param ercParams input data for ERC20 Creation
|
||||
* @param dtParams input data for Datatoken Creation
|
||||
* @param poolParams input data for Pool Creation
|
||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||
*/
|
||||
public async createNftErc20WithPool(
|
||||
public async createNftWithDatatokenWithPool(
|
||||
address: string,
|
||||
nftCreateData: NftCreateData,
|
||||
ercParams: Erc20CreateParams,
|
||||
dtParams: DatatokenCreateParams,
|
||||
poolParams: PoolCreationParams
|
||||
): Promise<TransactionReceipt> {
|
||||
const ercCreateData = this.getErcCreationParams(ercParams)
|
||||
const ercCreateData = this.getErcCreationParams(dtParams)
|
||||
const poolData = await this.getPoolCreationParams(poolParams)
|
||||
|
||||
const estGas = await estimateGas(
|
||||
@ -683,20 +683,20 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/** Estimate gas cost for createNftErc20WithFixedRate method
|
||||
/** Estimate gas cost for createNftWithDatatokenWithFixedRate method
|
||||
* @param address Caller address
|
||||
* @param nftCreateData input data for NFT Creation
|
||||
* @param ercParams input data for ERC20 Creation
|
||||
* @param dtParams input data for Datatoken Creation
|
||||
* @param freParams input data for FixedRate Creation
|
||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||
*/
|
||||
public async estGasCreateNftErc20WithFixedRate(
|
||||
public async estGasCreateNftWithDatatokenWithFixedRate(
|
||||
address: string,
|
||||
nftCreateData: NftCreateData,
|
||||
ercParams: Erc20CreateParams,
|
||||
dtParams: DatatokenCreateParams,
|
||||
freParams: FreCreationParams
|
||||
): Promise<any> {
|
||||
const ercCreateData = this.getErcCreationParams(ercParams)
|
||||
const ercCreateData = this.getErcCreationParams(dtParams)
|
||||
const fixedData = await this.getFreCreationParams(freParams)
|
||||
return estimateGas(
|
||||
address,
|
||||
@ -708,22 +708,22 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev createNftErc20WithFixedRate
|
||||
* Creates a new NFT, then a ERC20, then a FixedRateExchange, all in one call
|
||||
* @dev createNftWithDatatokenWithFixedRate
|
||||
* Creates a new NFT, then a Datatoken, then a FixedRateExchange, all in one call
|
||||
* Use this carefully, because if Fixed Rate creation fails, you are still going to pay a lot of gas
|
||||
* @param address Caller address
|
||||
* @param nftCreateData input data for NFT Creation
|
||||
* @param ercParams input data for ERC20 Creation
|
||||
* @param dtParams input data for Datatoken Creation
|
||||
* @param freParams input data for FixedRate Creation
|
||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||
*/
|
||||
public async createNftErc20WithFixedRate(
|
||||
public async createNftWithDatatokenWithFixedRate(
|
||||
address: string,
|
||||
nftCreateData: NftCreateData,
|
||||
ercParams: Erc20CreateParams,
|
||||
dtParams: DatatokenCreateParams,
|
||||
freParams: FreCreationParams
|
||||
): Promise<TransactionReceipt> {
|
||||
const ercCreateData = this.getErcCreationParams(ercParams)
|
||||
const ercCreateData = this.getErcCreationParams(dtParams)
|
||||
const fixedData = this.getFreCreationParams(freParams)
|
||||
|
||||
const estGas = await estimateGas(
|
||||
@ -746,20 +746,20 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/** Estimate gas cost for createNftErc20WithFixedRate method
|
||||
/** Estimate gas cost for estGasCreateNftWithDatatokenWithDispenser method
|
||||
* @param address Caller address
|
||||
* @param nftCreateData input data for NFT Creation
|
||||
* @param ercParams input data for ERC20 Creation
|
||||
* @param dtParams input data for Datatoken Creation
|
||||
* @param dispenserParams input data for Dispenser Creation
|
||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||
*/
|
||||
public async estGasCreateNftErc20WithDispenser(
|
||||
public async estGasCreateNftWithDatatokenWithDispenser(
|
||||
address: string,
|
||||
nftCreateData: NftCreateData,
|
||||
ercParams: Erc20CreateParams,
|
||||
dtParams: DatatokenCreateParams,
|
||||
dispenserParams: DispenserCreationParams
|
||||
): Promise<any> {
|
||||
const ercCreateData = this.getErcCreationParams(ercParams)
|
||||
const ercCreateData = this.getErcCreationParams(dtParams)
|
||||
return estimateGas(
|
||||
address,
|
||||
this.contract.methods.createNftWithErc20WithDispenser,
|
||||
@ -770,22 +770,22 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev createNftErc20WithDispenser
|
||||
* Creates a new NFT, then a ERC20, then a Dispenser, all in one call
|
||||
* @dev createNftWithDatatokenWithDispenser
|
||||
* Creates a new NFT, then a Datatoken, then a Dispenser, all in one call
|
||||
* Use this carefully, because if Dispenser creation fails, you are still going to pay a lot of gas
|
||||
* @param address Caller address
|
||||
* @param nftCreateData input data for NFT Creation
|
||||
* @param ercParams input data for ERC20 Creation
|
||||
* @param dtParams input data for Datatoken Creation
|
||||
* @param dispenserParams input data for Dispenser Creation
|
||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||
*/
|
||||
public async createNftErc20WithDispenser(
|
||||
public async createNftWithDatatokenWithDispenser(
|
||||
address: string,
|
||||
nftCreateData: NftCreateData,
|
||||
ercParams: Erc20CreateParams,
|
||||
dtParams: DatatokenCreateParams,
|
||||
dispenserParams: DispenserCreationParams
|
||||
): Promise<TransactionReceipt> {
|
||||
const ercCreateData = this.getErcCreationParams(ercParams)
|
||||
const ercCreateData = this.getErcCreationParams(dtParams)
|
||||
|
||||
dispenserParams.maxBalance = Web3.utils.toWei(dispenserParams.maxBalance)
|
||||
dispenserParams.maxTokens = Web3.utils.toWei(dispenserParams.maxTokens)
|
||||
@ -810,22 +810,22 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
private getErcCreationParams(ercParams: Erc20CreateParams): any {
|
||||
private getErcCreationParams(dtParams: DatatokenCreateParams): any {
|
||||
let name: string, symbol: string
|
||||
// Generate name & symbol if not present
|
||||
if (!ercParams.name || !ercParams.symbol) {
|
||||
if (!dtParams.name || !dtParams.symbol) {
|
||||
;({ name, symbol } = generateDtName())
|
||||
}
|
||||
return {
|
||||
templateIndex: ercParams.templateIndex,
|
||||
strings: [ercParams.name || name, ercParams.symbol || symbol],
|
||||
templateIndex: dtParams.templateIndex,
|
||||
strings: [dtParams.name || name, dtParams.symbol || symbol],
|
||||
addresses: [
|
||||
ercParams.minter,
|
||||
ercParams.paymentCollector,
|
||||
ercParams.mpFeeAddress,
|
||||
ercParams.feeToken
|
||||
dtParams.minter,
|
||||
dtParams.paymentCollector,
|
||||
dtParams.mpFeeAddress,
|
||||
dtParams.feeToken
|
||||
],
|
||||
uints: [Web3.utils.toWei(ercParams.cap), Web3.utils.toWei(ercParams.feeAmount)],
|
||||
uints: [Web3.utils.toWei(dtParams.cap), Web3.utils.toWei(dtParams.feeAmount)],
|
||||
bytess: []
|
||||
}
|
||||
}
|
||||
|
@ -742,7 +742,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect BaseTokens in the contract (anyone can call this, funds are sent to erc20.paymentCollector)
|
||||
* Collect BaseTokens in the contract (anyone can call this, funds are sent to Datatoken.paymentCollector)
|
||||
* @param {String} address User address
|
||||
* @param {String} exchangeId ExchangeId
|
||||
* @param {String} amount amount to be collected
|
||||
@ -808,7 +808,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect datatokens in the contract (anyone can call this, funds are sent to erc20.paymentCollector)
|
||||
* Collect datatokens in the contract (anyone can call this, funds are sent to Datatoken.paymentCollector)
|
||||
* @param {String} address User address
|
||||
* @param {String} exchangeId ExchangeId
|
||||
* @param {String} amount amount to be collected
|
||||
|
@ -185,14 +185,14 @@ export class Datatoken extends SmartContract {
|
||||
fixedRateParams: FreCreationParams
|
||||
): Promise<TransactionReceipt> {
|
||||
const dtContract = this.getContract(dtAddress)
|
||||
if (!(await this.isERC20Deployer(dtAddress, address))) {
|
||||
throw new Error(`User is not ERC20 Deployer`)
|
||||
if (!(await this.isDatatokenDeployer(dtAddress, address))) {
|
||||
throw new Error(`User is not Datatoken Deployer`)
|
||||
}
|
||||
if (!fixedRateParams.allowedConsumer) fixedRateParams.allowedConsumer = ZERO_ADDRESS
|
||||
|
||||
const withMint = fixedRateParams.withMint ? 1 : 0
|
||||
|
||||
// should check ERC20Deployer role using NFT level ..
|
||||
// should check DatatokenDeployer role using NFT level ..
|
||||
|
||||
const estGas = await estimateGas(
|
||||
address,
|
||||
@ -286,8 +286,8 @@ export class Datatoken extends SmartContract {
|
||||
dispenserAddress: string,
|
||||
dispenserParams: DispenserParams
|
||||
): Promise<TransactionReceipt> {
|
||||
if (!(await this.isERC20Deployer(dtAddress, address))) {
|
||||
throw new Error(`User is not ERC20 Deployer`)
|
||||
if (!(await this.isDatatokenDeployer(dtAddress, address))) {
|
||||
throw new Error(`User is not Datatoken Deployer`)
|
||||
}
|
||||
|
||||
const dtContract = this.getContract(dtAddress)
|
||||
@ -296,7 +296,7 @@ export class Datatoken extends SmartContract {
|
||||
|
||||
if (!dispenserParams.withMint) dispenserParams.withMint = false
|
||||
|
||||
// should check ERC20Deployer role using NFT level ..
|
||||
// should check DatatokenDeployer role using NFT level ..
|
||||
|
||||
const estGas = await estimateGas(
|
||||
address,
|
||||
@ -388,8 +388,8 @@ export class Datatoken extends SmartContract {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Minter for an ERC20 datatoken
|
||||
* only ERC20Deployer can succeed
|
||||
* Add Minter for an ERC20 Datatoken
|
||||
* only DatatokenDeployer can succeed
|
||||
* @param {String} dtAddress Datatoken address
|
||||
* @param {String} address User address
|
||||
* @param {String} minter User which is going to be a Minter
|
||||
@ -402,8 +402,8 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<TransactionReceipt> {
|
||||
const dtContract = this.getContract(dtAddress)
|
||||
|
||||
if ((await this.isERC20Deployer(dtAddress, address)) !== true) {
|
||||
throw new Error(`Caller is not ERC20Deployer`)
|
||||
if ((await this.isDatatokenDeployer(dtAddress, address)) !== true) {
|
||||
throw new Error(`Caller is not DatatokenDeployer`)
|
||||
}
|
||||
// Estimate gas cost for addMinter method
|
||||
const estGas = await estimateGas(address, dtContract.methods.addMinter, minter)
|
||||
@ -434,14 +434,14 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<any> {
|
||||
const dtContract = contractInstance || this.getContract(dtAddress)
|
||||
|
||||
// should check ERC20Deployer role using NFT level ..
|
||||
// should check DatatokenDeployer role using NFT level ..
|
||||
|
||||
return estimateGas(address, dtContract.methods.removeMinter, minter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke Minter permission for an ERC20 datatoken
|
||||
* only ERC20Deployer can succeed
|
||||
* Revoke Minter permission for an ERC20 Datatoken
|
||||
* only DatatokenDeployer can succeed
|
||||
* @param {String} dtAddress Datatoken address
|
||||
* @param {String} address User address
|
||||
* @param {String} minter User which will be removed from Minter permission
|
||||
@ -455,8 +455,8 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<TransactionReceipt> {
|
||||
const dtContract = this.getContract(dtAddress)
|
||||
|
||||
if ((await this.isERC20Deployer(dtAddress, address)) !== true) {
|
||||
throw new Error(`Caller is not ERC20Deployer`)
|
||||
if ((await this.isDatatokenDeployer(dtAddress, address)) !== true) {
|
||||
throw new Error(`Caller is not DatatokenDeployer`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(address, dtContract.methods.removeMinter, minter)
|
||||
@ -492,7 +492,7 @@ export class Datatoken extends SmartContract {
|
||||
|
||||
/**
|
||||
* Add addPaymentManager (can set who's going to collect fee when consuming orders)
|
||||
* only ERC20Deployer can succeed
|
||||
* only DatatokenDeployer can succeed
|
||||
* @param {String} dtAddress Datatoken address
|
||||
* @param {String} address User address
|
||||
* @param {String} paymentManager User which is going to be a Minter
|
||||
@ -505,8 +505,8 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<TransactionReceipt> {
|
||||
const dtContract = this.getContract(dtAddress)
|
||||
|
||||
if ((await this.isERC20Deployer(dtAddress, address)) !== true) {
|
||||
throw new Error(`Caller is not ERC20Deployer`)
|
||||
if ((await this.isDatatokenDeployer(dtAddress, address)) !== true) {
|
||||
throw new Error(`Caller is not DatatokenDeployer`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
@ -545,8 +545,8 @@ export class Datatoken extends SmartContract {
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke paymentManager permission for an ERC20 datatoken
|
||||
* only ERC20Deployer can succeed
|
||||
* Revoke paymentManager permission for an ERC20 Datatoken
|
||||
* only DatatokenDeployer can succeed
|
||||
* @param {String} dtAddress Datatoken address
|
||||
* @param {String} address User address
|
||||
* @param {String} paymentManager User which will be removed from paymentManager permission
|
||||
@ -559,8 +559,8 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<TransactionReceipt> {
|
||||
const dtContract = this.getContract(dtAddress)
|
||||
|
||||
if ((await this.isERC20Deployer(dtAddress, address)) !== true) {
|
||||
throw new Error(`Caller is not ERC20Deployer`)
|
||||
if ((await this.isDatatokenDeployer(dtAddress, address)) !== true) {
|
||||
throw new Error(`Caller is not DatatokenDeployer`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
@ -621,9 +621,9 @@ export class Datatoken extends SmartContract {
|
||||
const isNftOwner = nftAddress && (await this.nft.getNftOwner(nftAddress)) === address
|
||||
const nftPermissions =
|
||||
nftAddress && !isNftOwner && (await this.nft.getNftPermissions(nftAddress, address))
|
||||
const isErc20Deployer = nftPermissions?.deployERC20
|
||||
if (!isPaymentManager && !isNftOwner && !isErc20Deployer) {
|
||||
throw new Error(`Caller is not Fee Manager, owner or erc20 Deployer`)
|
||||
const isDatatokenDeployer = nftPermissions?.deployERC20
|
||||
if (!isPaymentManager && !isNftOwner && !isDatatokenDeployer) {
|
||||
throw new Error(`Caller is not Fee Manager, owner or Datatoken Deployer`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
@ -1011,8 +1011,8 @@ export class Datatoken extends SmartContract {
|
||||
}
|
||||
|
||||
/** setData
|
||||
* This function allows to store data with a preset key (keccak256(ERC20Address)) into NFT 725 Store
|
||||
* only ERC20Deployer can succeed
|
||||
* This function allows to store data with a preset key (keccak256(dtAddress)) into NFT 725 Store
|
||||
* only DatatokenDeployer can succeed
|
||||
* @param {String} dtAddress Datatoken address
|
||||
* @param {String} address User address
|
||||
* @param {String} value Data to be stored into 725Y standard
|
||||
@ -1023,8 +1023,8 @@ export class Datatoken extends SmartContract {
|
||||
address: string,
|
||||
value: string
|
||||
): Promise<TransactionReceipt> {
|
||||
if (!(await this.isERC20Deployer(dtAddress, address))) {
|
||||
throw new Error(`User is not ERC20 Deployer`)
|
||||
if (!(await this.isDatatokenDeployer(dtAddress, address))) {
|
||||
throw new Error(`User is not Datatoken Deployer`)
|
||||
}
|
||||
|
||||
const dtContract = this.getContract(dtAddress)
|
||||
@ -1058,7 +1058,7 @@ export class Datatoken extends SmartContract {
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean erc20level Permissions (minters, paymentManager and reset the paymentCollector) for an ERC20 datatoken
|
||||
* Clean Datatoken level Permissions (minters, paymentManager and reset the paymentCollector) for an ERC20 Datatoken
|
||||
* Only NFT Owner (at 721 level) can call it.
|
||||
* @param dtAddress Datatoken address where we want to clean permissions
|
||||
* @param address User adress
|
||||
@ -1085,7 +1085,7 @@ export class Datatoken extends SmartContract {
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/** Returns ERC20 user's permissions for a datatoken
|
||||
/** Returns ERC20 Datatoken user's permissions for a datatoken
|
||||
* @param {String} dtAddress Datatoken adress
|
||||
* @param {String} address user adress
|
||||
* @return {Promise<DatatokenRoles>}
|
||||
@ -1134,10 +1134,10 @@ export class Datatoken extends SmartContract {
|
||||
* @param {String} dtAddress Datatoken adress
|
||||
* @return {Promise<boolean>}
|
||||
*/
|
||||
public async isERC20Deployer(dtAddress: string, address: string): Promise<boolean> {
|
||||
public async isDatatokenDeployer(dtAddress: string, address: string): Promise<boolean> {
|
||||
const dtContract = this.getContract(dtAddress)
|
||||
const isERC20Deployer = await dtContract.methods.isERC20Deployer(address).call()
|
||||
return isERC20Deployer
|
||||
const isDatatokenDeployer = await dtContract.methods.isERC20Deployer(address).call()
|
||||
return isDatatokenDeployer
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,10 +12,10 @@ export class Nft extends SmartContract {
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas cost for createERC20 token creation
|
||||
* Estimate gas cost for createDatatoken token creation
|
||||
* @param {String} nftAddress NFT address
|
||||
* @param {String} address User address
|
||||
* @param {String} minter User set as initial minter for the ERC20
|
||||
* @param {String} minter User set as initial minter for the Datatoken
|
||||
* @param {String} paymentCollector initial paymentCollector for this DT
|
||||
* @param {String} mpFeeAddress Consume marketplace fee address
|
||||
* @param {String} feeToken address of the token marketplace wants to add fee on top
|
||||
@ -27,7 +27,7 @@ export class Nft extends SmartContract {
|
||||
* @param {Contract} nftContract optional contract instance
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
public async estGasGasCreateErc20(
|
||||
public async estGasGasCreateDatatoken(
|
||||
nftAddress: string,
|
||||
address: string,
|
||||
minter: string,
|
||||
@ -54,10 +54,10 @@ export class Nft extends SmartContract {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new ERC20 datatoken - only user with ERC20Deployer permission can succeed
|
||||
* Create new ERC20 Datatoken - only user with DatatokenDeployer permission can succeed
|
||||
* @param {String} nftAddress NFT address
|
||||
* @param {String} address User address
|
||||
* @param {String} minter User set as initial minter for the ERC20
|
||||
* @param {String} minter User set as initial minter for the Datatoken
|
||||
* @param {String} paymentCollector initial paymentCollector for this DT
|
||||
* @param {String} mpFeeAddress Consume marketplace fee address
|
||||
* @param {String} feeToken address of the token marketplace wants to add fee on top
|
||||
@ -66,9 +66,9 @@ export class Nft extends SmartContract {
|
||||
* @param {String} name Token name
|
||||
* @param {String} symbol Token symbol
|
||||
* @param {Number} templateIndex NFT template index
|
||||
* @return {Promise<string>} ERC20 datatoken address
|
||||
* @return {Promise<string>} ERC20 Datatoken address
|
||||
*/
|
||||
public async createErc20(
|
||||
public async createDatatoken(
|
||||
nftAddress: string,
|
||||
address: string,
|
||||
minter: string,
|
||||
@ -82,7 +82,7 @@ export class Nft extends SmartContract {
|
||||
templateIndex?: number
|
||||
): Promise<string> {
|
||||
if ((await this.getNftPermissions(nftAddress, address)).deployERC20 !== true) {
|
||||
throw new Error(`Caller is not ERC20Deployer`)
|
||||
throw new Error(`Caller is not DatatokenDeployer`)
|
||||
}
|
||||
if (!templateIndex) templateIndex = 1
|
||||
|
||||
@ -221,31 +221,35 @@ export class Nft extends SmartContract {
|
||||
* Estimate gas cost for addToCreateERC20List method
|
||||
* @param {String} nftAddress NFT contract address
|
||||
* @param {String} address NFT Manager adress
|
||||
* @param {String} erc20Deployer User adress which is going to have erc20Deployer permission
|
||||
* @param {String} datatokenDeployer User adress which is going to have DatatokenDeployer permission
|
||||
* @param {Contract} nftContract optional contract instance
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
public async estGasGasAddErc20Deployer(
|
||||
public async estGasGasAddDatatokenDeployer(
|
||||
nftAddress: string,
|
||||
address: string,
|
||||
erc20Deployer: string,
|
||||
datatokenDeployer: string,
|
||||
contractInstance?: Contract
|
||||
): Promise<any> {
|
||||
const nftContract = contractInstance || this.getContract(nftAddress)
|
||||
return estimateGas(address, nftContract.methods.addToCreateERC20List, erc20Deployer)
|
||||
return estimateGas(
|
||||
address,
|
||||
nftContract.methods.addToCreateERC20List,
|
||||
datatokenDeployer
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add ERC20Deployer permission - only Manager can succeed
|
||||
* Add DatatokenDeployer permission - only Manager can succeed
|
||||
* @param {String} nftAddress NFT contract address
|
||||
* @param {String} address NFT Manager adress
|
||||
* @param {String} erc20Deployer User adress which is going to have erc20Deployer permission
|
||||
* @param {String} datatokenDeployer User adress which is going to have DatatokenDeployer permission
|
||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||
*/
|
||||
public async addErc20Deployer(
|
||||
public async addDatatokenDeployer(
|
||||
nftAddress: string,
|
||||
address: string,
|
||||
erc20Deployer: string
|
||||
datatokenDeployer: string
|
||||
): Promise<TransactionReceipt> {
|
||||
const nftContract = this.getContract(nftAddress)
|
||||
|
||||
@ -257,12 +261,12 @@ export class Nft extends SmartContract {
|
||||
const estGas = await estimateGas(
|
||||
address,
|
||||
nftContract.methods.addToCreateERC20List,
|
||||
erc20Deployer
|
||||
datatokenDeployer
|
||||
)
|
||||
|
||||
// Invoke addToCreateERC20List function of the contract
|
||||
const trxReceipt = await nftContract.methods
|
||||
.addToCreateERC20List(erc20Deployer)
|
||||
.addToCreateERC20List(datatokenDeployer)
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
@ -276,14 +280,14 @@ export class Nft extends SmartContract {
|
||||
* Estimate gas cost for removeFromCreateERC20List method
|
||||
* @param {String} nftAddress NFT contract address
|
||||
* @param {String} address NFT Manager adress
|
||||
* @param {String} erc20Deployer Address of the user to be revoked ERC20Deployer Permission
|
||||
* @param {String} datatokenDeployer Address of the user to be revoked DatatokenDeployer Permission
|
||||
* @param {Contract} nftContract optional contract instance
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
public async estGasGasRemoveErc20Deployer(
|
||||
public async estGasGasRemoveDatatokenDeployer(
|
||||
nftAddress: string,
|
||||
address: string,
|
||||
erc20Deployer: string,
|
||||
datatokenDeployer: string,
|
||||
contractInstance?: Contract
|
||||
): Promise<any> {
|
||||
const nftContract = contractInstance || this.getContract(nftAddress)
|
||||
@ -291,40 +295,40 @@ export class Nft extends SmartContract {
|
||||
return estimateGas(
|
||||
address,
|
||||
nftContract.methods.removeFromCreateERC20List,
|
||||
erc20Deployer
|
||||
datatokenDeployer
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove ERC20Deployer permission - only Manager can succeed
|
||||
* Remove DatatokenDeployer permission - only Manager can succeed
|
||||
* @param {String} nftAddress NFT contract address
|
||||
* @param {String} address NFT Manager adress
|
||||
* @param {String} erc20Deployer Address of the user to be revoked ERC20Deployer Permission
|
||||
* @param {String} datatokenDeployer Address of the user to be revoked DatatokenDeployer Permission
|
||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||
*/
|
||||
public async removeErc20Deployer(
|
||||
public async removeDatatokenDeployer(
|
||||
nftAddress: string,
|
||||
address: string,
|
||||
erc20Deployer: string
|
||||
datatokenDeployer: string
|
||||
): Promise<TransactionReceipt> {
|
||||
const nftContract = this.getContract(nftAddress)
|
||||
|
||||
if (
|
||||
(await this.getNftPermissions(nftAddress, address)).manager !== true ||
|
||||
(address === erc20Deployer &&
|
||||
(address === datatokenDeployer &&
|
||||
(await this.getNftPermissions(nftAddress, address)).deployERC20 !== true)
|
||||
) {
|
||||
throw new Error(`Caller is not Manager nor ERC20Deployer`)
|
||||
throw new Error(`Caller is not Manager nor DatatokenDeployer`)
|
||||
}
|
||||
const estGas = await estimateGas(
|
||||
address,
|
||||
nftContract.methods.removeFromCreateERC20List,
|
||||
erc20Deployer
|
||||
datatokenDeployer
|
||||
)
|
||||
|
||||
// Call removeFromCreateERC20List function of the contract
|
||||
const trxReceipt = await nftContract.methods
|
||||
.removeFromCreateERC20List(erc20Deployer)
|
||||
.removeFromCreateERC20List(datatokenDeployer)
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
@ -581,9 +585,9 @@ export class Nft extends SmartContract {
|
||||
}
|
||||
|
||||
/**
|
||||
* This function allows to remove all ROLES at NFT level: Managers, ERC20Deployer, MetadataUpdater, StoreUpdater
|
||||
* This function allows to remove all ROLES at NFT level: Managers, DatatokenDeployer, MetadataUpdater, StoreUpdater
|
||||
* Even NFT Owner has to readd himself as Manager
|
||||
* Permissions at erc20 level stay.
|
||||
* Permissions at Datatoken level stay.
|
||||
* Only NFT Owner can call it.
|
||||
* @param {String} nftAddress NFT contract address
|
||||
* @param {String} address NFT Owner adress
|
||||
@ -641,7 +645,7 @@ export class Nft extends SmartContract {
|
||||
|
||||
/**
|
||||
* Transfers the NFT
|
||||
* will clean all permissions both on NFT and erc20 level.
|
||||
* will clean all permissions both on NFT and Datatoken level.
|
||||
* @param {String} nftAddress NFT contract address
|
||||
* @param {String} nftOwner Current NFT Owner adress
|
||||
* @param {String} nftReceiver User which will receive the NFT, will also be set as Manager
|
||||
@ -711,7 +715,7 @@ export class Nft extends SmartContract {
|
||||
|
||||
/**
|
||||
* safeTransferNFT Used for transferring the NFT, can be used by an approved relayer
|
||||
* will clean all permissions both on NFT and erc20 level.
|
||||
* will clean all permissions both on NFT and Datatoken level.
|
||||
* @param {String} nftAddress NFT contract address
|
||||
* @param {String} nftOwner Current NFT Owner adress
|
||||
* @param {String} nftReceiver User which will receive the NFT, will also be set as Manager
|
||||
@ -792,7 +796,7 @@ export class Nft extends SmartContract {
|
||||
|
||||
/**
|
||||
* safeTransferNFT Used for transferring the NFT, can be used by an approved relayer
|
||||
* will clean all permissions both on NFT and erc20 level.
|
||||
* will clean all permissions both on NFT and Datatoken level.
|
||||
* @param {String} nftAddress NFT contract address
|
||||
* @param {String} address Caller address NFT Owner adress
|
||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||
@ -1030,15 +1034,18 @@ export class Nft extends SmartContract {
|
||||
return await nftContract.methods.getMetaData().call()
|
||||
}
|
||||
|
||||
/** Get users ERC20Deployer role
|
||||
/** Get users DatatokenDeployer role
|
||||
* @param {String} nftAddress NFT contract address
|
||||
* @param {String} address user adress
|
||||
* @return {Promise<boolean>}
|
||||
*/
|
||||
public async isErc20Deployer(nftAddress: string, address: string): Promise<boolean> {
|
||||
public async isDatatokenDeployer(
|
||||
nftAddress: string,
|
||||
address: string
|
||||
): Promise<boolean> {
|
||||
const nftContract = this.getContract(nftAddress)
|
||||
const isERC20Deployer = await nftContract.methods.isERC20Deployer(address).call()
|
||||
return isERC20Deployer
|
||||
const isDatatokenDeployer = await nftContract.methods.isERC20Deployer(address).call()
|
||||
return isDatatokenDeployer
|
||||
}
|
||||
|
||||
/** Gets data at a given `key`
|
||||
|
@ -39,7 +39,7 @@ export async function estApprove(
|
||||
* @param {String} account
|
||||
* @param {String} tokenAddress
|
||||
* @param {String} spender
|
||||
* @param {String} amount amount of ERC20 tokens (always expressed as wei)
|
||||
* @param {String} amount amount of ERC20 Datatokens (always expressed as wei)
|
||||
* @param {boolean} force if true, will overwrite any previous allowence. Else, will check if allowence is enough and will not send a transaction if it's not needed
|
||||
* @param {number} tokenDecimals optional number of decimals of the token
|
||||
*/
|
||||
@ -110,7 +110,7 @@ export async function estTransfer(
|
||||
* @param {String} account
|
||||
* @param {String} tokenAddress
|
||||
* @param {String} recipient
|
||||
* @param {String} amount amount of ERC20 tokens (not as wei)
|
||||
* @param {String} amount amount of ERC20 Datatokens (not as wei)
|
||||
* @param {String} force if true, will overwrite any previous allowence. Else, will check if allowence is enough and will not send a transaction if it's not needed
|
||||
*/
|
||||
export async function transfer(
|
||||
@ -144,7 +144,7 @@ export async function transfer(
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Allowance for any erc20
|
||||
* Get Allowance for any Datatoken
|
||||
* @param {Web3} web3
|
||||
* @param {String } tokenAdress
|
||||
* @param {String} account
|
||||
@ -165,7 +165,7 @@ export async function allowance(
|
||||
}
|
||||
|
||||
/**
|
||||
* Get balance for any erc20
|
||||
* Get balance for any Datatoken
|
||||
* @param {Web3} web3
|
||||
* @param {String} tokenAdress
|
||||
* @param {String} owner
|
||||
@ -185,7 +185,7 @@ export async function balance(
|
||||
}
|
||||
|
||||
/**
|
||||
* Get decimals for any erc20
|
||||
* Get decimals for any Datatoken
|
||||
* @param {Web3} web3
|
||||
* @param {String} tokenAdress
|
||||
* @return {Promise<number>} Number of decimals of the token
|
||||
|
@ -49,7 +49,7 @@ const estimateGasAndDeployContract = async (
|
||||
export interface Addresses {
|
||||
opfCommunityFeeCollectorAddress: string
|
||||
poolTemplateAddress: string
|
||||
erc20TemplateAddress: string
|
||||
datatokenTemplateAddress: string
|
||||
nftTemplateAddress: string
|
||||
oceanAddress: string
|
||||
routerAddress: string
|
||||
@ -87,8 +87,8 @@ export const deployContracts = async (web3: Web3, owner: string): Promise<Addres
|
||||
owner
|
||||
))
|
||||
|
||||
// deploy ERC20 template
|
||||
addresses.erc20TemplateAddress =
|
||||
// deploy Datatoken template
|
||||
addresses.datatokenTemplateAddress =
|
||||
configAddresses.ERC20Template['1'] ||
|
||||
(await estimateGasAndDeployContract(
|
||||
web3,
|
||||
@ -179,7 +179,7 @@ export const deployContracts = async (web3: Web3, owner: string): Promise<Addres
|
||||
ERC721Factory.bytecode,
|
||||
[
|
||||
addresses.nftTemplateAddress,
|
||||
addresses.erc20TemplateAddress,
|
||||
addresses.datatokenTemplateAddress,
|
||||
addresses.opfCommunityFeeCollectorAddress,
|
||||
addresses.routerAddress
|
||||
],
|
||||
|
@ -97,7 +97,7 @@ import {
|
||||
Dispenser,
|
||||
DispenserCreationParams,
|
||||
downloadFile,
|
||||
Erc20CreateParams,
|
||||
DatatokenCreateParams,
|
||||
FixedRateExchange,
|
||||
FreCreationParams,
|
||||
getHash,
|
||||
@ -252,7 +252,7 @@ describe('Marketplace flow tests', async () => {
|
||||
owner: publisherAccount
|
||||
}
|
||||
|
||||
const erc20Params: Erc20CreateParams = {
|
||||
const datatokenParams: DatatokenCreateParams = {
|
||||
templateIndex: 1,
|
||||
cap: '100000',
|
||||
feeAmount: '0',
|
||||
@ -278,7 +278,7 @@ describe('Marketplace flow tests', async () => {
|
||||
swapFeeMarketRunner: '0.001'
|
||||
}
|
||||
/// ```
|
||||
/// Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 tokens
|
||||
/// Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 Datatokens
|
||||
/// ```Typescript
|
||||
await approve(
|
||||
web3,
|
||||
@ -291,10 +291,10 @@ describe('Marketplace flow tests', async () => {
|
||||
/// ```
|
||||
/// Now we can make the contract call
|
||||
/// ```Typescript
|
||||
const tx = await factory.createNftErc20WithPool(
|
||||
const tx = await factory.createNftWithDatatokenWithPool(
|
||||
publisherAccount,
|
||||
nftParams,
|
||||
erc20Params,
|
||||
datatokenParams,
|
||||
poolParams
|
||||
)
|
||||
|
||||
@ -353,7 +353,7 @@ describe('Marketplace flow tests', async () => {
|
||||
const pool = new Pool(web3)
|
||||
|
||||
/// ```
|
||||
/// Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 tokens
|
||||
/// Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 Datatokens
|
||||
/// ```Typescript
|
||||
await approve(web3, stakerAccount, addresses.Ocean, poolAddress, '5', true)
|
||||
|
||||
@ -402,7 +402,7 @@ describe('Marketplace flow tests', async () => {
|
||||
console.log(`Consumer ${POOL_NFT_SYMBOL} balance before swap: ${consumerDTBalance}`)
|
||||
|
||||
/// ```
|
||||
/// Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 tokens
|
||||
/// Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 Datatokens
|
||||
/// ```Typescript
|
||||
await approve(web3, consumerAccount, addresses.Ocean, poolAddress, '100')
|
||||
|
||||
@ -526,7 +526,7 @@ describe('Marketplace flow tests', async () => {
|
||||
owner: publisherAccount
|
||||
}
|
||||
|
||||
const erc20Params: Erc20CreateParams = {
|
||||
const datatokenParams: DatatokenCreateParams = {
|
||||
templateIndex: 1,
|
||||
cap: '100000',
|
||||
feeAmount: '0',
|
||||
@ -549,10 +549,10 @@ describe('Marketplace flow tests', async () => {
|
||||
withMint: false
|
||||
}
|
||||
|
||||
const tx = await factory.createNftErc20WithFixedRate(
|
||||
const tx = await factory.createNftWithDatatokenWithFixedRate(
|
||||
publisherAccount,
|
||||
nftParams,
|
||||
erc20Params,
|
||||
datatokenParams,
|
||||
freParams
|
||||
)
|
||||
|
||||
@ -644,7 +644,7 @@ describe('Marketplace flow tests', async () => {
|
||||
console.log(`Consumer ${FRE_NFT_SYMBOL} balance before swap: ${consumerDTBalance}`)
|
||||
|
||||
/// ```
|
||||
/// Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 tokens
|
||||
/// Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 Datatokens
|
||||
/// ```Typescript
|
||||
await approve(web3, consumerAccount, addresses.Ocean, freAddress, '100')
|
||||
await approve(
|
||||
@ -748,7 +748,7 @@ describe('Marketplace flow tests', async () => {
|
||||
owner: publisherAccount
|
||||
}
|
||||
|
||||
const erc20Params: Erc20CreateParams = {
|
||||
const datatokenParams: DatatokenCreateParams = {
|
||||
templateIndex: 1,
|
||||
cap: '100000',
|
||||
feeAmount: '0',
|
||||
@ -766,10 +766,10 @@ describe('Marketplace flow tests', async () => {
|
||||
allowedSwapper: ZERO_ADDRESS
|
||||
}
|
||||
|
||||
const tx = await factory.createNftErc20WithDispenser(
|
||||
const tx = await factory.createNftWithDatatokenWithDispenser(
|
||||
publisherAccount,
|
||||
nftParams,
|
||||
erc20Params,
|
||||
datatokenParams,
|
||||
dispenserParams
|
||||
)
|
||||
|
||||
|
@ -13,7 +13,7 @@ import {
|
||||
ZERO_ADDRESS
|
||||
} from '../../src'
|
||||
import {
|
||||
Erc20CreateParams,
|
||||
DatatokenCreateParams,
|
||||
ComputeJob,
|
||||
ComputeAsset,
|
||||
ComputeAlgorithm,
|
||||
@ -232,7 +232,7 @@ async function createAsset(
|
||||
transferable: true,
|
||||
owner: owner
|
||||
}
|
||||
const erc20ParamsAsset: Erc20CreateParams = {
|
||||
const datatokenParams: DatatokenCreateParams = {
|
||||
templateIndex: 1,
|
||||
cap: '100000',
|
||||
feeAmount: '0',
|
||||
@ -242,7 +242,11 @@ async function createAsset(
|
||||
mpFeeAddress: ZERO_ADDRESS
|
||||
}
|
||||
|
||||
const result = await Factory.createNftWithErc20(owner, nftParamsAsset, erc20ParamsAsset)
|
||||
const result = await Factory.createNftWithDatatoken(
|
||||
owner,
|
||||
nftParamsAsset,
|
||||
datatokenParams
|
||||
)
|
||||
|
||||
const nftAddress = result.events.NFTCreated.returnValues[0]
|
||||
const datatokenAddressAsset = result.events.TokenCreated.returnValues[0]
|
||||
|
@ -15,7 +15,7 @@ import {
|
||||
import {
|
||||
ValidateMetadata,
|
||||
DDO,
|
||||
Erc20CreateParams,
|
||||
DatatokenCreateParams,
|
||||
PoolCreationParams,
|
||||
FreCreationParams,
|
||||
DispenserCreationParams
|
||||
@ -95,7 +95,7 @@ describe('Publish tests', async () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('should publish a dataset with pool (create NFT + ERC20 + pool) and with Metdata proof', async () => {
|
||||
it('should publish a dataset with pool (create NFT + Datatoken + pool) and with Metdata proof', async () => {
|
||||
const poolDdo: DDO = { ...genericAsset }
|
||||
|
||||
const nftParams: NftCreateData = {
|
||||
@ -107,7 +107,7 @@ describe('Publish tests', async () => {
|
||||
owner: publisherAccount
|
||||
}
|
||||
|
||||
const erc20Params: Erc20CreateParams = {
|
||||
const datatokenParams: DatatokenCreateParams = {
|
||||
templateIndex: 1,
|
||||
cap: '100000',
|
||||
feeAmount: '0',
|
||||
@ -133,10 +133,10 @@ describe('Publish tests', async () => {
|
||||
swapFeeMarketRunner: '0.001'
|
||||
}
|
||||
|
||||
const bundleNFT = await factory.createNftErc20WithPool(
|
||||
const bundleNFT = await factory.createNftWithDatatokenWithPool(
|
||||
publisherAccount,
|
||||
nftParams,
|
||||
erc20Params,
|
||||
datatokenParams,
|
||||
poolParams
|
||||
)
|
||||
|
||||
@ -179,7 +179,7 @@ describe('Publish tests', async () => {
|
||||
assert(resolvedDDO, 'Cannot fetch DDO from Aquarius')
|
||||
})
|
||||
|
||||
it('should publish a dataset with fixed price (create NFT + ERC20 + fixed price) with an explicit empty Metadata Proof', async () => {
|
||||
it('should publish a dataset with fixed price (create NFT + Datoken + fixed price) with an explicit empty Metadata Proof', async () => {
|
||||
const fixedPriceDdo: DDO = { ...genericAsset }
|
||||
|
||||
const nftParams: NftCreateData = {
|
||||
@ -191,7 +191,7 @@ describe('Publish tests', async () => {
|
||||
owner: publisherAccount
|
||||
}
|
||||
|
||||
const erc20Params: Erc20CreateParams = {
|
||||
const datatokenParams: DatatokenCreateParams = {
|
||||
templateIndex: 1,
|
||||
cap: '100000',
|
||||
feeAmount: '0',
|
||||
@ -214,10 +214,10 @@ describe('Publish tests', async () => {
|
||||
withMint: false
|
||||
}
|
||||
|
||||
const bundleNFT = await factory.createNftErc20WithFixedRate(
|
||||
const bundleNFT = await factory.createNftWithDatatokenWithFixedRate(
|
||||
publisherAccount,
|
||||
nftParams,
|
||||
erc20Params,
|
||||
datatokenParams,
|
||||
fixedPriceParams
|
||||
)
|
||||
|
||||
@ -258,7 +258,7 @@ describe('Publish tests', async () => {
|
||||
assert(resolvedDDO, 'Cannot fetch DDO from Aquarius')
|
||||
})
|
||||
|
||||
it('should publish a dataset with dispenser (create NFT + ERC20 + dispenser) with no defined MetadataProof', async () => {
|
||||
it('should publish a dataset with dispenser (create NFT + Datatoken + dispenser) with no defined MetadataProof', async () => {
|
||||
const dispenserDdo: DDO = { ...genericAsset }
|
||||
|
||||
const nftParams: NftCreateData = {
|
||||
@ -270,7 +270,7 @@ describe('Publish tests', async () => {
|
||||
owner: publisherAccount
|
||||
}
|
||||
|
||||
const erc20Params: Erc20CreateParams = {
|
||||
const datatokenParams: DatatokenCreateParams = {
|
||||
templateIndex: 1,
|
||||
cap: '100000',
|
||||
feeAmount: '0',
|
||||
@ -288,10 +288,10 @@ describe('Publish tests', async () => {
|
||||
allowedSwapper: ZERO_ADDRESS
|
||||
}
|
||||
|
||||
const bundleNFT = await factory.createNftErc20WithDispenser(
|
||||
const bundleNFT = await factory.createNftWithDatatokenWithDispenser(
|
||||
publisherAccount,
|
||||
nftParams,
|
||||
erc20Params,
|
||||
datatokenParams,
|
||||
dispenserParams
|
||||
)
|
||||
|
||||
|
@ -13,7 +13,7 @@ import {
|
||||
downloadFile,
|
||||
ZERO_ADDRESS
|
||||
} from '../../src'
|
||||
import { ProviderFees, Erc20CreateParams, DDO } from '../../src/@types'
|
||||
import { ProviderFees, DatatokenCreateParams, DDO } from '../../src/@types'
|
||||
|
||||
describe('Simple Publish & consume test', async () => {
|
||||
let config: Config
|
||||
@ -72,7 +72,7 @@ describe('Simple Publish & consume test', async () => {
|
||||
consumerAccount = accounts[1]
|
||||
})
|
||||
|
||||
it('should publish a dataset (create NFT + ERC20)', async () => {
|
||||
it('should publish a dataset (create NFT + Datatoken)', async () => {
|
||||
const nft = new Nft(web3)
|
||||
const datatoken = new Datatoken(web3)
|
||||
const Factory = new NftFactory(addresses.ERC721Factory, web3)
|
||||
@ -86,7 +86,7 @@ describe('Simple Publish & consume test', async () => {
|
||||
owner: publisherAccount
|
||||
}
|
||||
|
||||
const erc20Params: Erc20CreateParams = {
|
||||
const datatokenParams: DatatokenCreateParams = {
|
||||
templateIndex: 1,
|
||||
cap: '100000',
|
||||
feeAmount: '0',
|
||||
@ -96,7 +96,11 @@ describe('Simple Publish & consume test', async () => {
|
||||
mpFeeAddress: ZERO_ADDRESS
|
||||
}
|
||||
|
||||
const tx = await Factory.createNftWithErc20(publisherAccount, nftParams, erc20Params)
|
||||
const tx = await Factory.createNftWithDatatoken(
|
||||
publisherAccount,
|
||||
nftParams,
|
||||
datatokenParams
|
||||
)
|
||||
const nftAddress = tx.events.NFTCreated.returnValues[0]
|
||||
const datatokenAddress = tx.events.TokenCreated.returnValues[0]
|
||||
|
||||
@ -127,7 +131,7 @@ describe('Simple Publish & consume test', async () => {
|
||||
const resolvedDDO = await aquarius.waitForAqua(ddo.id)
|
||||
assert(resolvedDDO, 'Cannot fetch DDO from Aquarius')
|
||||
|
||||
// mint 1 ERC20 and send it to the consumer
|
||||
// mint 1 Datatoken and send it to the consumer
|
||||
await datatoken.mint(datatokenAddress, publisherAccount, '1', consumerAccount)
|
||||
|
||||
// initialize provider
|
||||
|
@ -16,7 +16,7 @@ import {
|
||||
import {
|
||||
ProviderFees,
|
||||
FreCreationParams,
|
||||
Erc20CreateParams,
|
||||
DatatokenCreateParams,
|
||||
PoolCreationParams
|
||||
} from '../../../src/@types'
|
||||
|
||||
@ -43,7 +43,7 @@ describe('Nft Factory test', () => {
|
||||
owner: factoryOwner
|
||||
}
|
||||
|
||||
const ercParams: Erc20CreateParams = {
|
||||
const dtParams: DatatokenCreateParams = {
|
||||
templateIndex: 1,
|
||||
minter: nftOwner,
|
||||
paymentCollector: user2,
|
||||
@ -63,9 +63,9 @@ describe('Nft Factory test', () => {
|
||||
user2 = accounts[3]
|
||||
|
||||
nftData.owner = factoryOwner
|
||||
ercParams.minter = nftOwner
|
||||
ercParams.paymentCollector = user2
|
||||
ercParams.mpFeeAddress = user1
|
||||
dtParams.minter = nftOwner
|
||||
dtParams.paymentCollector = user2
|
||||
dtParams.mpFeeAddress = user1
|
||||
})
|
||||
|
||||
it('should deploy contracts', async () => {
|
||||
@ -90,7 +90,7 @@ describe('Nft Factory test', () => {
|
||||
it('#getTokenTemplate - should return Token template struct', async () => {
|
||||
const tokenTemplate = await nftFactory.getTokenTemplate(1)
|
||||
assert(tokenTemplate.isActive === true)
|
||||
assert(tokenTemplate.templateAddress === contracts.erc20TemplateAddress)
|
||||
assert(tokenTemplate.templateAddress === contracts.datatokenTemplateAddress)
|
||||
})
|
||||
|
||||
it('#createNft - should create an NFT', async () => {
|
||||
@ -105,7 +105,7 @@ describe('Nft Factory test', () => {
|
||||
|
||||
it('#createNftwithErc - should create an NFT and a Datatoken', async () => {
|
||||
// we prepare transaction parameters objects
|
||||
const txReceipt = await nftFactory.createNftWithErc20(nftOwner, nftData, ercParams)
|
||||
const txReceipt = await nftFactory.createNftWithDatatoken(nftOwner, nftData, dtParams)
|
||||
|
||||
// events have been emitted
|
||||
expect(txReceipt.events.NFTCreated.event === 'NFTCreated')
|
||||
@ -120,7 +120,7 @@ describe('Nft Factory test', () => {
|
||||
const currentNFTCount = await nftFactory.getCurrentNFTCount()
|
||||
const currentTokenCount = await nftFactory.getCurrentTokenCount()
|
||||
|
||||
await nftFactory.createNftWithErc20(nftOwner, nftData, ercParams)
|
||||
await nftFactory.createNftWithDatatoken(nftOwner, nftData, dtParams)
|
||||
|
||||
expect((await nftFactory.getCurrentNFTCount()) === currentNFTCount + 1)
|
||||
expect((await nftFactory.getCurrentTokenCount()) === currentTokenCount + 1)
|
||||
@ -160,10 +160,10 @@ describe('Nft Factory test', () => {
|
||||
poolParams.vestingAmount
|
||||
)
|
||||
|
||||
const txReceipt = await nftFactory.createNftErc20WithPool(
|
||||
const txReceipt = await nftFactory.createNftWithDatatokenWithPool(
|
||||
nftOwner,
|
||||
nftData,
|
||||
ercParams,
|
||||
dtParams,
|
||||
poolParams
|
||||
)
|
||||
|
||||
@ -188,10 +188,10 @@ describe('Nft Factory test', () => {
|
||||
withMint: false
|
||||
}
|
||||
|
||||
const txReceipt = await nftFactory.createNftErc20WithFixedRate(
|
||||
const txReceipt = await nftFactory.createNftWithDatatokenWithFixedRate(
|
||||
nftOwner,
|
||||
nftData,
|
||||
ercParams,
|
||||
dtParams,
|
||||
freParams
|
||||
)
|
||||
|
||||
@ -214,10 +214,10 @@ describe('Nft Factory test', () => {
|
||||
allowedSwapper: ZERO_ADDRESS
|
||||
}
|
||||
|
||||
const txReceipt = await nftFactory.createNftErc20WithDispenser(
|
||||
const txReceipt = await nftFactory.createNftWithDatatokenWithDispenser(
|
||||
nftOwner,
|
||||
nftData,
|
||||
ercParams,
|
||||
dtParams,
|
||||
dispenserParams
|
||||
)
|
||||
|
||||
@ -359,17 +359,17 @@ describe('Nft Factory test', () => {
|
||||
assert(nftTemplate.isActive === true)
|
||||
})
|
||||
|
||||
it('#addTokenTemplate - should add a new erc20 token template', async () => {
|
||||
it('#addTokenTemplate - should add a new Datatokent template', async () => {
|
||||
const currentTokenTemplateCount = await nftFactory.getCurrentTokenTemplateCount()
|
||||
|
||||
await nftFactory.addTokenTemplate(factoryOwner, contracts.erc20TemplateAddress)
|
||||
await nftFactory.addTokenTemplate(factoryOwner, contracts.datatokenTemplateAddress)
|
||||
|
||||
expect(
|
||||
(await nftFactory.getCurrentTokenTemplateCount()) === currentTokenTemplateCount + 1
|
||||
)
|
||||
})
|
||||
|
||||
it('#disableTokenTemplate - should disable an erc20 token template', async () => {
|
||||
it('#disableTokenTemplate - should disable an Datatoken template', async () => {
|
||||
const currentTokenTemplateCount = await nftFactory.getCurrentTokenTemplateCount()
|
||||
|
||||
let tokenTemplate = await nftFactory.getTokenTemplate(currentTokenTemplateCount)
|
||||
@ -381,7 +381,7 @@ describe('Nft Factory test', () => {
|
||||
assert(tokenTemplate.isActive === false)
|
||||
})
|
||||
|
||||
it('#reactivateTokenTemplate - should reactivate an previously disabled erc20 token template', async () => {
|
||||
it('#reactivateTokenTemplate - should reactivate an previously disabled Datatoken template', async () => {
|
||||
const currentTokenTemplateCount = await nftFactory.getCurrentTokenTemplateCount()
|
||||
|
||||
let tokenTemplate = await nftFactory.getTokenTemplate(currentTokenTemplateCount)
|
||||
|
@ -11,7 +11,7 @@ import {
|
||||
approve,
|
||||
ZERO_ADDRESS
|
||||
} from '../../../src'
|
||||
import { Erc20CreateParams, PoolCreationParams, Operation } from '../../../src/@types'
|
||||
import { DatatokenCreateParams, PoolCreationParams, Operation } from '../../../src/@types'
|
||||
|
||||
const { keccak256 } = require('@ethersproject/keccak256')
|
||||
|
||||
@ -25,8 +25,8 @@ describe('Router unit test', () => {
|
||||
const NFT_NAME = '72120Bundle'
|
||||
const NFT_SYMBOL = '72Bundle'
|
||||
const NFT_TOKEN_URI = 'https://oceanprotocol.com/nft/'
|
||||
const ERC20_NAME = 'ERC20B1'
|
||||
const ERC20_SYMBOL = 'ERC20DT1Symbol'
|
||||
const DATATOKEN_NAME = 'ERC20B1'
|
||||
const DATATOKEN_SYMBOL = 'ERC20DT1Symbol'
|
||||
const RATE = '1'
|
||||
const FEE = '0.001'
|
||||
const FEE_ZERO = '0'
|
||||
@ -51,7 +51,7 @@ describe('Router unit test', () => {
|
||||
owner: factoryOwner
|
||||
}
|
||||
|
||||
const ERC_PARAMS: Erc20CreateParams = {
|
||||
const ERC_PARAMS: DatatokenCreateParams = {
|
||||
templateIndex: 1,
|
||||
minter: factoryOwner,
|
||||
paymentCollector: user2,
|
||||
@ -59,8 +59,8 @@ describe('Router unit test', () => {
|
||||
feeToken: ZERO_ADDRESS,
|
||||
cap: CAP_AMOUNT,
|
||||
feeAmount: FEE_ZERO,
|
||||
name: ERC20_NAME,
|
||||
symbol: ERC20_SYMBOL
|
||||
name: DATATOKEN_NAME,
|
||||
symbol: DATATOKEN_SYMBOL
|
||||
}
|
||||
|
||||
before(async () => {
|
||||
@ -152,31 +152,31 @@ describe('Router unit test', () => {
|
||||
}
|
||||
|
||||
const nftFactory = new NftFactory(contracts.nftFactoryAddress, web3)
|
||||
const txReceipt = await nftFactory.createNftErc20WithPool(
|
||||
const txReceipt = await nftFactory.createNftWithDatatokenWithPool(
|
||||
factoryOwner,
|
||||
NFT_DATA,
|
||||
ERC_PARAMS,
|
||||
poolParams
|
||||
)
|
||||
|
||||
const erc20TokenAddress = txReceipt.events.TokenCreated.returnValues.newTokenAddress
|
||||
const datatokenAddress = txReceipt.events.TokenCreated.returnValues.newTokenAddress
|
||||
const pool1 = txReceipt.events.NewPool.returnValues.poolAddress
|
||||
|
||||
// CREATE A SECOND POOL
|
||||
const txReceipt2 = await nftFactory.createNftErc20WithPool(
|
||||
const txReceipt2 = await nftFactory.createNftWithDatatokenWithPool(
|
||||
factoryOwner,
|
||||
NFT_DATA,
|
||||
ERC_PARAMS,
|
||||
poolParams
|
||||
)
|
||||
|
||||
const erc20Token2Address = txReceipt2.events.TokenCreated.returnValues.newTokenAddress
|
||||
const datatoken2Address = txReceipt2.events.TokenCreated.returnValues.newTokenAddress
|
||||
const pool2 = txReceipt2.events.NewPool.returnValues.poolAddress
|
||||
|
||||
// user1 has no dt1
|
||||
expect(await balance(web3, erc20TokenAddress, user1)).to.equal('0')
|
||||
expect(await balance(web3, datatokenAddress, user1)).to.equal('0')
|
||||
// user1 has no dt2
|
||||
expect(await balance(web3, erc20Token2Address, user1)).to.equal('0')
|
||||
expect(await balance(web3, datatoken2Address, user1)).to.equal('0')
|
||||
|
||||
// we now can prepare the Operations objects
|
||||
|
||||
@ -190,7 +190,7 @@ describe('Router unit test', () => {
|
||||
operation: 0, // swapExactAmountIn
|
||||
tokenIn: contracts.daiAddress,
|
||||
amountsIn: AMOUNTS_IN, // when swapExactAmountIn is EXACT amount IN
|
||||
tokenOut: erc20TokenAddress,
|
||||
tokenOut: datatokenAddress,
|
||||
amountsOut: AMOUNTS_OUT, // when swapExactAmountIn is MIN amount OUT
|
||||
maxPrice: MAX_PRICE, // max price (only for pools),
|
||||
swapMarketFee: SWAP_MARKET_FEE,
|
||||
@ -203,7 +203,7 @@ describe('Router unit test', () => {
|
||||
operation: 0, // swapExactAmountIn
|
||||
tokenIn: contracts.daiAddress,
|
||||
amountsIn: AMOUNTS_IN, // when swapExactAmountIn is EXACT amount IN
|
||||
tokenOut: erc20Token2Address,
|
||||
tokenOut: datatoken2Address,
|
||||
amountsOut: AMOUNTS_OUT, // when swapExactAmountIn is MIN amount OUT
|
||||
maxPrice: MAX_PRICE, // max price (only for pools),
|
||||
swapMarketFee: SWAP_MARKET_FEE,
|
||||
@ -213,7 +213,7 @@ describe('Router unit test', () => {
|
||||
await router.buyDTBatch(user1, [operations1, operations2])
|
||||
|
||||
// user1 got his dts
|
||||
expect(+(await balance(web3, erc20TokenAddress, user1))).gt(0)
|
||||
expect(+(await balance(web3, erc20Token2Address, user1))).gt(0)
|
||||
expect(+(await balance(web3, datatokenAddress, user1))).gt(0)
|
||||
expect(+(await balance(web3, datatoken2Address, user1))).gt(0)
|
||||
})
|
||||
})
|
||||
|
@ -15,7 +15,7 @@ import {
|
||||
} from '../../../../src'
|
||||
import {
|
||||
PoolCreationParams,
|
||||
Erc20CreateParams,
|
||||
DatatokenCreateParams,
|
||||
CurrentFees,
|
||||
TokenInOutMarket,
|
||||
AmountsInMaxFee,
|
||||
@ -29,8 +29,8 @@ describe('Pool unit test', () => {
|
||||
let contracts: Addresses
|
||||
let pool: Pool
|
||||
let poolAddress: string
|
||||
let erc20Token: string
|
||||
let ercParams: Erc20CreateParams
|
||||
let datatoken: string
|
||||
let dtParams: DatatokenCreateParams
|
||||
|
||||
const nftData: NftCreateData = {
|
||||
name: '72120Bundle',
|
||||
@ -49,7 +49,7 @@ describe('Pool unit test', () => {
|
||||
|
||||
nftData.owner = factoryOwner
|
||||
|
||||
ercParams = {
|
||||
dtParams = {
|
||||
templateIndex: 1,
|
||||
minter: factoryOwner,
|
||||
paymentCollector: user2,
|
||||
@ -130,18 +130,18 @@ describe('Pool unit test', () => {
|
||||
|
||||
const nftFactory = new NftFactory(contracts.nftFactoryAddress, web3, 8996)
|
||||
|
||||
const txReceipt = await nftFactory.createNftErc20WithPool(
|
||||
const txReceipt = await nftFactory.createNftWithDatatokenWithPool(
|
||||
factoryOwner,
|
||||
nftData,
|
||||
ercParams,
|
||||
dtParams,
|
||||
poolParams
|
||||
)
|
||||
|
||||
erc20Token = txReceipt.events.TokenCreated.returnValues.newTokenAddress
|
||||
datatoken = txReceipt.events.TokenCreated.returnValues.newTokenAddress
|
||||
poolAddress = txReceipt.events.NewPool.returnValues.poolAddress
|
||||
|
||||
// user1 has no dt1
|
||||
expect(await balance(web3, erc20Token, user1)).to.equal('0')
|
||||
expect(await balance(web3, datatoken, user1)).to.equal('0')
|
||||
})
|
||||
|
||||
it('#sharesBalance - should return user shares balance (datatoken balance, LPT balance, etc) ', async () => {
|
||||
@ -168,13 +168,13 @@ describe('Pool unit test', () => {
|
||||
|
||||
it('#getCurrentTokens - should return current pool tokens', async () => {
|
||||
const currentTokens = await pool.getCurrentTokens(poolAddress)
|
||||
expect(currentTokens[0]).to.equal(erc20Token)
|
||||
expect(currentTokens[0]).to.equal(datatoken)
|
||||
expect(currentTokens[1]).to.equal(contracts.daiAddress)
|
||||
})
|
||||
|
||||
it('#getFinalTokens - should return final pool tokens', async () => {
|
||||
const finalTokens = await pool.getFinalTokens(poolAddress)
|
||||
expect(finalTokens[0]).to.equal(erc20Token)
|
||||
expect(finalTokens[0]).to.equal(datatoken)
|
||||
expect(finalTokens[1]).to.equal(contracts.daiAddress)
|
||||
})
|
||||
|
||||
@ -190,7 +190,7 @@ describe('Pool unit test', () => {
|
||||
it('#getReserve - should return final pool tokens', async () => {
|
||||
expect(await pool.getReserve(poolAddress, contracts.daiAddress)).to.equal('2000') // baseToken initial liquidity
|
||||
// rate is 1 so we have the same amount of DTs
|
||||
expect(await pool.getReserve(poolAddress, erc20Token)).to.equal('2000')
|
||||
expect(await pool.getReserve(poolAddress, datatoken)).to.equal('2000')
|
||||
})
|
||||
|
||||
it('#isFinalized - should return true if pool is finalized', async () => {
|
||||
@ -205,14 +205,14 @@ describe('Pool unit test', () => {
|
||||
expect(await pool.getNormalizedWeight(poolAddress, contracts.daiAddress)).to.equal(
|
||||
'0.5'
|
||||
)
|
||||
expect(await pool.getNormalizedWeight(poolAddress, erc20Token)).to.equal('0.5')
|
||||
expect(await pool.getNormalizedWeight(poolAddress, datatoken)).to.equal('0.5')
|
||||
})
|
||||
|
||||
it('#getDenormalizedWeight - should return the denormalized weight', async () => {
|
||||
expect(
|
||||
await pool.getDenormalizedWeight(poolAddress, contracts.daiAddress)
|
||||
).to.equal('5')
|
||||
expect(await pool.getDenormalizedWeight(poolAddress, erc20Token)).to.equal('5')
|
||||
expect(await pool.getDenormalizedWeight(poolAddress, datatoken)).to.equal('5')
|
||||
})
|
||||
|
||||
it('#getBaseToken - should return the baseToken address', async () => {
|
||||
@ -220,19 +220,19 @@ describe('Pool unit test', () => {
|
||||
})
|
||||
|
||||
it('#getDatatoken - should return the datatoken address', async () => {
|
||||
expect(await pool.getDatatoken(poolAddress)).to.equal(erc20Token)
|
||||
expect(await pool.getDatatoken(poolAddress)).to.equal(datatoken)
|
||||
})
|
||||
|
||||
it('#swapExactAmountIn - should swap', async () => {
|
||||
await transfer(web3, factoryOwner, contracts.daiAddress, user1, '1000')
|
||||
expect(await balance(web3, contracts.daiAddress, user1)).to.equal('1000')
|
||||
|
||||
expect(await balance(web3, erc20Token, user1)).to.equal('0')
|
||||
expect(await balance(web3, datatoken, user1)).to.equal('0')
|
||||
await approve(web3, user1, contracts.daiAddress, poolAddress, '10')
|
||||
|
||||
const tokenInOutMarket: TokenInOutMarket = {
|
||||
tokenIn: contracts.daiAddress,
|
||||
tokenOut: erc20Token,
|
||||
tokenOut: datatoken,
|
||||
marketFeeAddress: factoryOwner
|
||||
}
|
||||
const amountsInOutMaxFee: AmountsInMaxFee = {
|
||||
@ -246,10 +246,10 @@ describe('Pool unit test', () => {
|
||||
tokenInOutMarket,
|
||||
amountsInOutMaxFee
|
||||
)
|
||||
expect(await balance(web3, erc20Token, user1)).to.equal(
|
||||
expect(await balance(web3, datatoken, user1)).to.equal(
|
||||
await unitsToAmount(
|
||||
web3,
|
||||
erc20Token,
|
||||
datatoken,
|
||||
tx.events.LOG_SWAP.returnValues.tokenAmountOut
|
||||
)
|
||||
)
|
||||
@ -260,7 +260,7 @@ describe('Pool unit test', () => {
|
||||
expect(await balance(web3, contracts.daiAddress, user1)).to.equal('990')
|
||||
const tokenInOutMarket: TokenInOutMarket = {
|
||||
tokenIn: contracts.daiAddress,
|
||||
tokenOut: erc20Token,
|
||||
tokenOut: datatoken,
|
||||
marketFeeAddress: factoryOwner
|
||||
}
|
||||
const amountsInOutMaxFee: AmountsOutMaxFee = {
|
||||
@ -317,7 +317,7 @@ describe('Pool unit test', () => {
|
||||
expect(tx.events.LOG_EXIT[0].returnValues.tokenOut).to.equal(contracts.daiAddress)
|
||||
|
||||
// DTs were also unstaked in the same transaction (went to the staking contract)
|
||||
expect(tx.events.LOG_EXIT[1].returnValues.tokenOut).to.equal(erc20Token)
|
||||
expect(tx.events.LOG_EXIT[1].returnValues.tokenOut).to.equal(datatoken)
|
||||
})
|
||||
|
||||
it('#exitswapExternAmountOut- user1 exit the pool receiving only DAI', async () => {
|
||||
@ -336,7 +336,7 @@ describe('Pool unit test', () => {
|
||||
expect(tx.events.LOG_EXIT[0].returnValues.tokenOut).to.equal(contracts.daiAddress)
|
||||
|
||||
// DTs were also unstaked in the same transaction (went to the staking contract)
|
||||
expect(tx.events.LOG_EXIT[1].returnValues.tokenOut).to.equal(erc20Token)
|
||||
expect(tx.events.LOG_EXIT[1].returnValues.tokenOut).to.equal(datatoken)
|
||||
})
|
||||
|
||||
it('#getAmountInExactOut- should get the amount in for exact out', async () => {
|
||||
@ -344,7 +344,7 @@ describe('Pool unit test', () => {
|
||||
|
||||
const result = await pool.getAmountInExactOut(
|
||||
poolAddress,
|
||||
erc20Token,
|
||||
datatoken,
|
||||
contracts.daiAddress,
|
||||
exactDAIOut,
|
||||
'0.1'
|
||||
@ -357,7 +357,7 @@ describe('Pool unit test', () => {
|
||||
|
||||
const spotPrice = await pool.getSpotPrice(
|
||||
poolAddress,
|
||||
erc20Token,
|
||||
datatoken,
|
||||
contracts.daiAddress,
|
||||
'0.1'
|
||||
)
|
||||
@ -371,7 +371,7 @@ describe('Pool unit test', () => {
|
||||
|
||||
const result = await pool.getAmountOutExactIn(
|
||||
poolAddress,
|
||||
erc20Token,
|
||||
datatoken,
|
||||
contracts.daiAddress,
|
||||
exactDTIn,
|
||||
'0.1'
|
||||
@ -383,7 +383,7 @@ describe('Pool unit test', () => {
|
||||
const spotPrice = await pool.getSpotPrice(
|
||||
poolAddress,
|
||||
contracts.daiAddress,
|
||||
erc20Token,
|
||||
datatoken,
|
||||
'0.1'
|
||||
)
|
||||
// amount of DAI received will be slightly less than spotPrice
|
||||
@ -392,34 +392,34 @@ describe('Pool unit test', () => {
|
||||
|
||||
it('#getSpotPrice- should get the spot price', async () => {
|
||||
assert(
|
||||
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.daiAddress, '0.1')) !=
|
||||
(await pool.getSpotPrice(poolAddress, datatoken, contracts.daiAddress, '0.1')) !=
|
||||
null
|
||||
)
|
||||
assert(
|
||||
(await pool.getSpotPrice(poolAddress, contracts.daiAddress, erc20Token, '0.1')) !=
|
||||
(await pool.getSpotPrice(poolAddress, contracts.daiAddress, datatoken, '0.1')) !=
|
||||
null
|
||||
)
|
||||
})
|
||||
|
||||
it('#getMarketFees- should get market fees for each token', async () => {
|
||||
// we haven't performed any swap DT => DAI so there's no fee in erc20Token
|
||||
// we haven't performed any swap DT => DAI so there's no fee in datatoken
|
||||
// but there's a fee in DAI
|
||||
assert((await pool.getMarketFees(poolAddress, erc20Token)) === '0')
|
||||
assert((await pool.getMarketFees(poolAddress, datatoken)) === '0')
|
||||
assert((await pool.getMarketFees(poolAddress, contracts.daiAddress)) > '0')
|
||||
})
|
||||
|
||||
it('#getCommunityFees- should get community fees for each token', async () => {
|
||||
// we haven't performed any swap DT => DAI so there's no fee in erc20Token
|
||||
// we haven't performed any swap DT => DAI so there's no fee in datatoken
|
||||
// but there's a fee in DAI
|
||||
|
||||
assert((await pool.getCommunityFees(poolAddress, erc20Token)) === '0')
|
||||
assert((await pool.getCommunityFees(poolAddress, datatoken)) === '0')
|
||||
assert((await pool.getCommunityFees(poolAddress, contracts.daiAddress)) > '0')
|
||||
})
|
||||
|
||||
it('#collectMarketFee- should collect market fees for each token', async () => {
|
||||
const spotPriceBefore = await pool.getSpotPrice(
|
||||
poolAddress,
|
||||
erc20Token,
|
||||
datatoken,
|
||||
contracts.daiAddress,
|
||||
'0.1'
|
||||
)
|
||||
@ -435,12 +435,8 @@ describe('Pool unit test', () => {
|
||||
|
||||
// Spot price hasn't changed after fee collection
|
||||
assert(
|
||||
(await pool.getSpotPrice(
|
||||
poolAddress,
|
||||
erc20Token,
|
||||
contracts.daiAddress,
|
||||
'0.1'
|
||||
)) === spotPriceBefore
|
||||
(await pool.getSpotPrice(poolAddress, datatoken, contracts.daiAddress, '0.1')) ===
|
||||
spotPriceBefore
|
||||
)
|
||||
})
|
||||
|
||||
@ -452,7 +448,7 @@ describe('Pool unit test', () => {
|
||||
it('#collectCommunityFee- should get community fees for each token', async () => {
|
||||
const spotPriceBefore = await pool.getSpotPrice(
|
||||
poolAddress,
|
||||
erc20Token,
|
||||
datatoken,
|
||||
contracts.daiAddress,
|
||||
'0.1'
|
||||
)
|
||||
@ -480,12 +476,8 @@ describe('Pool unit test', () => {
|
||||
)
|
||||
// Spot price hasn't changed after fee collection
|
||||
assert(
|
||||
(await pool.getSpotPrice(
|
||||
poolAddress,
|
||||
erc20Token,
|
||||
contracts.daiAddress,
|
||||
'0.1'
|
||||
)) === spotPriceBefore
|
||||
(await pool.getSpotPrice(poolAddress, datatoken, contracts.daiAddress, '0.1')) ===
|
||||
spotPriceBefore
|
||||
)
|
||||
})
|
||||
|
||||
@ -525,18 +517,18 @@ describe('Pool unit test', () => {
|
||||
|
||||
const nftFactory = new NftFactory(contracts.nftFactoryAddress, web3, 8996)
|
||||
|
||||
const txReceipt = await nftFactory.createNftErc20WithPool(
|
||||
const txReceipt = await nftFactory.createNftWithDatatokenWithPool(
|
||||
factoryOwner,
|
||||
nftData,
|
||||
ercParams,
|
||||
dtParams,
|
||||
poolParams
|
||||
)
|
||||
|
||||
erc20Token = txReceipt.events.TokenCreated.returnValues.newTokenAddress
|
||||
datatoken = txReceipt.events.TokenCreated.returnValues.newTokenAddress
|
||||
poolAddress = txReceipt.events.NewPool.returnValues.poolAddress
|
||||
|
||||
// user1 has no dt1
|
||||
expect(await balance(web3, erc20Token, user1)).to.equal('0')
|
||||
expect(await balance(web3, datatoken, user1)).to.equal('0')
|
||||
})
|
||||
|
||||
it('#calcPoolOutGivenSingleIn - should get the amount of pool OUT for exact token IN', async () => {
|
||||
@ -544,7 +536,7 @@ describe('Pool unit test', () => {
|
||||
// amount of pool out received for same amount of different token In is equal
|
||||
const tokenInAmount = '10' // 10 USDC or 10 DTs
|
||||
expect(
|
||||
await pool.calcPoolOutGivenSingleIn(poolAddress, erc20Token, tokenInAmount)
|
||||
await pool.calcPoolOutGivenSingleIn(poolAddress, datatoken, tokenInAmount)
|
||||
).to.equal(
|
||||
await pool.calcPoolOutGivenSingleIn(
|
||||
poolAddress,
|
||||
@ -552,7 +544,7 @@ describe('Pool unit test', () => {
|
||||
tokenInAmount
|
||||
)
|
||||
)
|
||||
// console.log(await pool.calcPoolOutGivenSingleIn(poolAddress, erc20Token, tokenInAmount))
|
||||
// console.log(await pool.calcPoolOutGivenSingleIn(poolAddress, datatoken, tokenInAmount))
|
||||
})
|
||||
|
||||
it('#calcSingleInGivenPoolOut - should get the amount of token IN for exact pool token OUT', async () => {
|
||||
@ -561,7 +553,7 @@ describe('Pool unit test', () => {
|
||||
const poolAmountOut = '1'
|
||||
expect(
|
||||
parseInt(
|
||||
await pool.calcSingleInGivenPoolOut(poolAddress, erc20Token, poolAmountOut)
|
||||
await pool.calcSingleInGivenPoolOut(poolAddress, datatoken, poolAmountOut)
|
||||
)
|
||||
).to.be.closeTo(
|
||||
parseInt(
|
||||
@ -580,7 +572,7 @@ describe('Pool unit test', () => {
|
||||
// amount amount of different token Out for rediming the same pool In is equal
|
||||
const poolAmountIn = '10'
|
||||
expect(
|
||||
await pool.calcSingleOutGivenPoolIn(poolAddress, erc20Token, poolAmountIn)
|
||||
await pool.calcSingleOutGivenPoolIn(poolAddress, datatoken, poolAmountIn)
|
||||
).to.equal(
|
||||
await pool.calcSingleOutGivenPoolIn(
|
||||
poolAddress,
|
||||
@ -596,7 +588,7 @@ describe('Pool unit test', () => {
|
||||
const tokenAmountOut = '10'
|
||||
expect(
|
||||
parseInt(
|
||||
await pool.calcPoolInGivenSingleOut(poolAddress, erc20Token, tokenAmountOut)
|
||||
await pool.calcPoolInGivenSingleOut(poolAddress, datatoken, tokenAmountOut)
|
||||
)
|
||||
).to.be.closeTo(
|
||||
parseInt(
|
||||
@ -634,13 +626,13 @@ describe('Pool unit test', () => {
|
||||
|
||||
it('#getCurrentTokens - should return current pool tokens', async () => {
|
||||
const currentTokens = await pool.getCurrentTokens(poolAddress)
|
||||
expect(currentTokens[0]).to.equal(erc20Token)
|
||||
expect(currentTokens[0]).to.equal(datatoken)
|
||||
expect(currentTokens[1]).to.equal(contracts.usdcAddress)
|
||||
})
|
||||
|
||||
it('#getFinalTokens - should return final pool tokens', async () => {
|
||||
const finalTokens = await pool.getFinalTokens(poolAddress)
|
||||
expect(finalTokens[0]).to.equal(erc20Token)
|
||||
expect(finalTokens[0]).to.equal(datatoken)
|
||||
expect(finalTokens[1]).to.equal(contracts.usdcAddress)
|
||||
})
|
||||
|
||||
@ -656,7 +648,7 @@ describe('Pool unit test', () => {
|
||||
it('#getReserve - should return final pool tokens Reserve', async () => {
|
||||
expect(await pool.getReserve(poolAddress, contracts.usdcAddress)).to.equal('2000') // baseToken initial liquidity
|
||||
// rate is 1 so we have the same amount of DTs
|
||||
expect(await pool.getReserve(poolAddress, erc20Token)).to.equal('2000')
|
||||
expect(await pool.getReserve(poolAddress, datatoken)).to.equal('2000')
|
||||
})
|
||||
|
||||
it('#isFinalized - should return true if pool is finalized', async () => {
|
||||
@ -671,14 +663,14 @@ describe('Pool unit test', () => {
|
||||
expect(await pool.getNormalizedWeight(poolAddress, contracts.usdcAddress)).to.equal(
|
||||
'0.5'
|
||||
)
|
||||
expect(await pool.getNormalizedWeight(poolAddress, erc20Token)).to.equal('0.5')
|
||||
expect(await pool.getNormalizedWeight(poolAddress, datatoken)).to.equal('0.5')
|
||||
})
|
||||
|
||||
it('#getDenormalizedWeight - should return the denormalized weight', async () => {
|
||||
expect(
|
||||
await pool.getDenormalizedWeight(poolAddress, contracts.usdcAddress)
|
||||
).to.equal('5')
|
||||
expect(await pool.getDenormalizedWeight(poolAddress, erc20Token)).to.equal('5')
|
||||
expect(await pool.getDenormalizedWeight(poolAddress, datatoken)).to.equal('5')
|
||||
})
|
||||
|
||||
it('#getBaseToken - should return the baseToken address', async () => {
|
||||
@ -686,19 +678,19 @@ describe('Pool unit test', () => {
|
||||
})
|
||||
|
||||
it('#getDatatoken - should return the datatoken address', async () => {
|
||||
expect(await pool.getDatatoken(poolAddress)).to.equal(erc20Token)
|
||||
expect(await pool.getDatatoken(poolAddress)).to.equal(datatoken)
|
||||
})
|
||||
|
||||
it('#swapExactAmountIn - should swap', async () => {
|
||||
await transfer(web3, factoryOwner, contracts.usdcAddress, user1, '1000')
|
||||
expect(await balance(web3, contracts.usdcAddress, user1)).to.equal('1000')
|
||||
|
||||
expect(await balance(web3, erc20Token, user1)).to.equal('0')
|
||||
expect(await balance(web3, datatoken, user1)).to.equal('0')
|
||||
await approve(web3, user1, contracts.usdcAddress, poolAddress, '10')
|
||||
|
||||
const tokenInOutMarket: TokenInOutMarket = {
|
||||
tokenIn: contracts.usdcAddress,
|
||||
tokenOut: erc20Token,
|
||||
tokenOut: datatoken,
|
||||
marketFeeAddress: factoryOwner
|
||||
}
|
||||
const amountsInOutMaxFee: AmountsInMaxFee = {
|
||||
@ -712,10 +704,10 @@ describe('Pool unit test', () => {
|
||||
tokenInOutMarket,
|
||||
amountsInOutMaxFee
|
||||
)
|
||||
expect(await balance(web3, erc20Token, user1)).to.equal(
|
||||
expect(await balance(web3, datatoken, user1)).to.equal(
|
||||
await unitsToAmount(
|
||||
web3,
|
||||
erc20Token,
|
||||
datatoken,
|
||||
tx.events.LOG_SWAP.returnValues.tokenAmountOut
|
||||
)
|
||||
)
|
||||
@ -726,7 +718,7 @@ describe('Pool unit test', () => {
|
||||
expect(await balance(web3, contracts.usdcAddress, user1)).to.equal('990')
|
||||
const tokenInOutMarket: TokenInOutMarket = {
|
||||
tokenIn: contracts.usdcAddress,
|
||||
tokenOut: erc20Token,
|
||||
tokenOut: datatoken,
|
||||
marketFeeAddress: factoryOwner
|
||||
}
|
||||
const amountsInOutMaxFee: AmountsOutMaxFee = {
|
||||
@ -782,7 +774,7 @@ describe('Pool unit test', () => {
|
||||
expect(tx.events.LOG_EXIT[0].returnValues.tokenOut).to.equal(contracts.usdcAddress)
|
||||
|
||||
// DTs were also unstaked in the same transaction (went to the staking contract)
|
||||
expect(tx.events.LOG_EXIT[1].returnValues.tokenOut).to.equal(erc20Token)
|
||||
expect(tx.events.LOG_EXIT[1].returnValues.tokenOut).to.equal(datatoken)
|
||||
})
|
||||
|
||||
it('#getAmountInExactOut- should get the amount in for exact out', async () => {
|
||||
@ -790,7 +782,7 @@ describe('Pool unit test', () => {
|
||||
|
||||
const result = await pool.getAmountInExactOut(
|
||||
poolAddress,
|
||||
erc20Token,
|
||||
datatoken,
|
||||
contracts.usdcAddress,
|
||||
exactUSDCOut,
|
||||
'0.1'
|
||||
@ -800,7 +792,7 @@ describe('Pool unit test', () => {
|
||||
|
||||
const spotPrice = await pool.getSpotPrice(
|
||||
poolAddress,
|
||||
erc20Token,
|
||||
datatoken,
|
||||
contracts.usdcAddress,
|
||||
'0.1'
|
||||
)
|
||||
@ -813,7 +805,7 @@ describe('Pool unit test', () => {
|
||||
|
||||
const result = await pool.getAmountOutExactIn(
|
||||
poolAddress,
|
||||
erc20Token,
|
||||
datatoken,
|
||||
contracts.usdcAddress,
|
||||
exactDTIn,
|
||||
'0.1'
|
||||
@ -825,7 +817,7 @@ describe('Pool unit test', () => {
|
||||
const spotPrice = await pool.getSpotPrice(
|
||||
poolAddress,
|
||||
contracts.usdcAddress,
|
||||
erc20Token,
|
||||
datatoken,
|
||||
'0.1'
|
||||
)
|
||||
// amount of USDC received will be slightly less than spotPrice
|
||||
@ -834,42 +826,34 @@ describe('Pool unit test', () => {
|
||||
|
||||
it('#getSpotPrice- should get the spot price', async () => {
|
||||
assert(
|
||||
(await pool.getSpotPrice(
|
||||
poolAddress,
|
||||
erc20Token,
|
||||
contracts.usdcAddress,
|
||||
'0.1'
|
||||
)) != null
|
||||
(await pool.getSpotPrice(poolAddress, datatoken, contracts.usdcAddress, '0.1')) !=
|
||||
null
|
||||
)
|
||||
assert(
|
||||
(await pool.getSpotPrice(
|
||||
poolAddress,
|
||||
contracts.usdcAddress,
|
||||
erc20Token,
|
||||
'0.1'
|
||||
)) != null
|
||||
(await pool.getSpotPrice(poolAddress, contracts.usdcAddress, datatoken, '0.1')) !=
|
||||
null
|
||||
)
|
||||
})
|
||||
|
||||
it('#getMarketFees- should get market fees for each token', async () => {
|
||||
// we haven't performed any swap DT => USDC so there's no fee in erc20Token
|
||||
// we haven't performed any swap DT => USDC so there's no fee in datatoken
|
||||
// but there's a fee in USDC
|
||||
assert((await pool.getMarketFees(poolAddress, erc20Token)) === '0')
|
||||
assert((await pool.getMarketFees(poolAddress, datatoken)) === '0')
|
||||
assert((await pool.getMarketFees(poolAddress, contracts.usdcAddress)) > '0')
|
||||
})
|
||||
|
||||
it('#getCommunityFees- should get community fees for each token', async () => {
|
||||
// we haven't performed any swap DT => USDC so there's no fee in erc20Token
|
||||
// we haven't performed any swap DT => USDC so there's no fee in datatoken
|
||||
// but there's a fee in USDC
|
||||
|
||||
assert((await pool.getCommunityFees(poolAddress, erc20Token)) === '0')
|
||||
assert((await pool.getCommunityFees(poolAddress, datatoken)) === '0')
|
||||
assert((await pool.getCommunityFees(poolAddress, contracts.usdcAddress)) > '0')
|
||||
})
|
||||
|
||||
it('#collectMarketFee- should collect market fees for each token', async () => {
|
||||
const spotPriceBefore = await pool.getSpotPrice(
|
||||
poolAddress,
|
||||
erc20Token,
|
||||
datatoken,
|
||||
contracts.usdcAddress,
|
||||
'0.1'
|
||||
)
|
||||
@ -886,7 +870,7 @@ describe('Pool unit test', () => {
|
||||
assert(
|
||||
(await pool.getSpotPrice(
|
||||
poolAddress,
|
||||
erc20Token,
|
||||
datatoken,
|
||||
contracts.usdcAddress,
|
||||
'0.1'
|
||||
)) === spotPriceBefore
|
||||
@ -911,7 +895,7 @@ describe('Pool unit test', () => {
|
||||
it('#collectCommunityFee- should get community fees for each token', async () => {
|
||||
const spotPriceBefore = await pool.getSpotPrice(
|
||||
poolAddress,
|
||||
erc20Token,
|
||||
datatoken,
|
||||
contracts.usdcAddress,
|
||||
'0.1'
|
||||
)
|
||||
@ -941,7 +925,7 @@ describe('Pool unit test', () => {
|
||||
assert(
|
||||
(await pool.getSpotPrice(
|
||||
poolAddress,
|
||||
erc20Token,
|
||||
datatoken,
|
||||
contracts.usdcAddress,
|
||||
'0.1'
|
||||
)) === spotPriceBefore
|
||||
|
@ -9,7 +9,7 @@ import {
|
||||
Dispenser,
|
||||
ZERO_ADDRESS
|
||||
} from '../../../../src/'
|
||||
import { Erc20CreateParams } from '../../../../src/@types'
|
||||
import { DatatokenCreateParams } from '../../../../src/@types'
|
||||
|
||||
describe('Dispenser flow', () => {
|
||||
let factoryOwner: string
|
||||
@ -30,7 +30,7 @@ describe('Dispenser flow', () => {
|
||||
owner: null
|
||||
}
|
||||
|
||||
const ercParams: Erc20CreateParams = {
|
||||
const dtParams: DatatokenCreateParams = {
|
||||
templateIndex: 1,
|
||||
minter: null,
|
||||
paymentCollector: null,
|
||||
@ -49,9 +49,9 @@ describe('Dispenser flow', () => {
|
||||
user2 = accounts[4]
|
||||
|
||||
nftData.owner = factoryOwner
|
||||
ercParams.minter = factoryOwner
|
||||
ercParams.paymentCollector = user2
|
||||
ercParams.mpFeeAddress = user1
|
||||
dtParams.minter = factoryOwner
|
||||
dtParams.paymentCollector = user2
|
||||
dtParams.mpFeeAddress = user1
|
||||
})
|
||||
|
||||
it('should deploy contracts', async () => {
|
||||
@ -66,10 +66,10 @@ describe('Dispenser flow', () => {
|
||||
it('#createNftwithErc - should create an NFT and a Datatoken ', async () => {
|
||||
nftFactory = new NftFactory(contracts.nftFactoryAddress, web3)
|
||||
|
||||
const txReceipt = await nftFactory.createNftWithErc20(
|
||||
const txReceipt = await nftFactory.createNftWithDatatoken(
|
||||
factoryOwner,
|
||||
nftData,
|
||||
ercParams
|
||||
dtParams
|
||||
)
|
||||
|
||||
expect(txReceipt.events.NFTCreated.event === 'NFTCreated')
|
||||
|
@ -15,7 +15,7 @@ import {
|
||||
balance,
|
||||
unitsToAmount
|
||||
} from '../../../../src'
|
||||
import { FreCreationParams, Erc20CreateParams } from '../../../../src/@types'
|
||||
import { FreCreationParams, DatatokenCreateParams } from '../../../../src/@types'
|
||||
|
||||
describe('Fixed Rate unit test', () => {
|
||||
let factoryOwner: string
|
||||
@ -37,7 +37,7 @@ describe('Fixed Rate unit test', () => {
|
||||
owner: null
|
||||
}
|
||||
|
||||
const ercParams: Erc20CreateParams = {
|
||||
const dtParams: DatatokenCreateParams = {
|
||||
templateIndex: 1,
|
||||
minter: null,
|
||||
paymentCollector: null,
|
||||
@ -57,9 +57,9 @@ describe('Fixed Rate unit test', () => {
|
||||
exchangeOwner = accounts[0]
|
||||
|
||||
nftData.owner = factoryOwner
|
||||
ercParams.minter = factoryOwner
|
||||
ercParams.paymentCollector = user2
|
||||
ercParams.mpFeeAddress = factoryOwner
|
||||
dtParams.minter = factoryOwner
|
||||
dtParams.paymentCollector = user2
|
||||
dtParams.mpFeeAddress = factoryOwner
|
||||
})
|
||||
|
||||
it('should deploy contracts', async () => {
|
||||
@ -86,10 +86,10 @@ describe('Fixed Rate unit test', () => {
|
||||
withMint: false
|
||||
}
|
||||
|
||||
const txReceipt = await nftFactory.createNftErc20WithFixedRate(
|
||||
const txReceipt = await nftFactory.createNftWithDatatokenWithFixedRate(
|
||||
exchangeOwner,
|
||||
nftData,
|
||||
ercParams,
|
||||
dtParams,
|
||||
freParams
|
||||
)
|
||||
|
||||
@ -395,10 +395,10 @@ describe('Fixed Rate unit test', () => {
|
||||
withMint: false
|
||||
}
|
||||
|
||||
const txReceipt = await nftFactory.createNftErc20WithFixedRate(
|
||||
const txReceipt = await nftFactory.createNftWithDatatokenWithFixedRate(
|
||||
exchangeOwner,
|
||||
nftData,
|
||||
ercParams,
|
||||
dtParams,
|
||||
freParams
|
||||
)
|
||||
|
||||
|
@ -18,7 +18,7 @@ import {
|
||||
ZERO_ADDRESS
|
||||
} from '../../../../src'
|
||||
import {
|
||||
Erc20CreateParams,
|
||||
DatatokenCreateParams,
|
||||
PoolCreationParams,
|
||||
TokenInOutMarket,
|
||||
AmountsInMaxFee,
|
||||
@ -34,8 +34,8 @@ describe('SideStaking unit test', () => {
|
||||
let pool: Pool
|
||||
let sideStaking: SideStaking
|
||||
let poolAddress: string
|
||||
let erc20Token: string
|
||||
let erc20Contract: Contract
|
||||
let datatoken: string
|
||||
let datatokenContract: Contract
|
||||
let daiContract: Contract
|
||||
let usdcContract: Contract
|
||||
|
||||
@ -52,7 +52,7 @@ describe('SideStaking unit test', () => {
|
||||
owner: null
|
||||
}
|
||||
|
||||
const ercParams: Erc20CreateParams = {
|
||||
const dtParams: DatatokenCreateParams = {
|
||||
templateIndex: 1,
|
||||
minter: null,
|
||||
paymentCollector: null,
|
||||
@ -71,9 +71,9 @@ describe('SideStaking unit test', () => {
|
||||
user2 = accounts[2]
|
||||
|
||||
nftData.owner = factoryOwner
|
||||
ercParams.minter = factoryOwner
|
||||
ercParams.paymentCollector = user2
|
||||
ercParams.mpFeeAddress = factoryOwner
|
||||
dtParams.minter = factoryOwner
|
||||
dtParams.paymentCollector = user2
|
||||
dtParams.mpFeeAddress = factoryOwner
|
||||
})
|
||||
|
||||
it('should deploy contracts', async () => {
|
||||
@ -153,20 +153,20 @@ describe('SideStaking unit test', () => {
|
||||
swapFeeMarketRunner: '0.001'
|
||||
}
|
||||
|
||||
const txReceipt = await nftFactory.createNftErc20WithPool(
|
||||
const txReceipt = await nftFactory.createNftWithDatatokenWithPool(
|
||||
factoryOwner,
|
||||
nftData,
|
||||
ercParams,
|
||||
dtParams,
|
||||
poolParams
|
||||
)
|
||||
|
||||
initialBlock = await web3.eth.getBlockNumber()
|
||||
erc20Token = txReceipt.events.TokenCreated.returnValues.newTokenAddress
|
||||
datatoken = txReceipt.events.TokenCreated.returnValues.newTokenAddress
|
||||
poolAddress = txReceipt.events.NewPool.returnValues.poolAddress
|
||||
|
||||
erc20Contract = new web3.eth.Contract(ERC20Template.abi as AbiItem[], erc20Token)
|
||||
datatokenContract = new web3.eth.Contract(ERC20Template.abi as AbiItem[], datatoken)
|
||||
// user1 has no dt1
|
||||
expect(await erc20Contract.methods.balanceOf(user1).call()).to.equal('0')
|
||||
expect(await datatokenContract.methods.balanceOf(user1).call()).to.equal('0')
|
||||
})
|
||||
|
||||
it('#getRouter - should get Router address', async () => {
|
||||
@ -179,7 +179,7 @@ describe('SideStaking unit test', () => {
|
||||
expect(
|
||||
await sideStaking.getDatatokenCirculatingSupply(
|
||||
contracts.sideStakingAddress,
|
||||
erc20Token
|
||||
datatoken
|
||||
)
|
||||
).to.equal(web3.utils.toWei(BASE_TOKEN_LIQUIDITY.toString()))
|
||||
})
|
||||
@ -188,39 +188,39 @@ describe('SideStaking unit test', () => {
|
||||
expect(
|
||||
await sideStaking.getDatatokenCurrentCirculatingSupply(
|
||||
contracts.sideStakingAddress,
|
||||
erc20Token
|
||||
datatoken
|
||||
)
|
||||
).to.equal(web3.utils.toWei(BASE_TOKEN_LIQUIDITY.toString()))
|
||||
})
|
||||
|
||||
it('#getBaseToken - should get baseToken address', async () => {
|
||||
expect(
|
||||
await sideStaking.getBaseToken(contracts.sideStakingAddress, erc20Token)
|
||||
await sideStaking.getBaseToken(contracts.sideStakingAddress, datatoken)
|
||||
).to.equal(contracts.daiAddress)
|
||||
})
|
||||
|
||||
it('#getPoolAddress - should get pool address', async () => {
|
||||
expect(
|
||||
await sideStaking.getPoolAddress(contracts.sideStakingAddress, erc20Token)
|
||||
await sideStaking.getPoolAddress(contracts.sideStakingAddress, datatoken)
|
||||
).to.equal(poolAddress)
|
||||
})
|
||||
|
||||
it('#getPublisherAddress - should get publisher address', async () => {
|
||||
expect(
|
||||
await sideStaking.getPublisherAddress(contracts.sideStakingAddress, erc20Token)
|
||||
await sideStaking.getPublisherAddress(contracts.sideStakingAddress, datatoken)
|
||||
).to.equal(factoryOwner)
|
||||
})
|
||||
|
||||
it('#getBaseTokenBalance ', async () => {
|
||||
expect(
|
||||
await sideStaking.getBaseTokenBalance(contracts.sideStakingAddress, erc20Token)
|
||||
await sideStaking.getBaseTokenBalance(contracts.sideStakingAddress, datatoken)
|
||||
).to.equal('0')
|
||||
})
|
||||
|
||||
it('#getDatatokenBalance ', async () => {
|
||||
expect(
|
||||
await (
|
||||
await sideStaking.getDatatokenBalance(contracts.sideStakingAddress, erc20Token)
|
||||
await sideStaking.getDatatokenBalance(contracts.sideStakingAddress, datatoken)
|
||||
).toString()
|
||||
).to.equal(
|
||||
new BigNumber(2)
|
||||
@ -234,19 +234,19 @@ describe('SideStaking unit test', () => {
|
||||
|
||||
it('#getvestingAmount ', async () => {
|
||||
expect(
|
||||
await sideStaking.getvestingAmount(contracts.sideStakingAddress, erc20Token)
|
||||
await sideStaking.getvestingAmount(contracts.sideStakingAddress, datatoken)
|
||||
).to.equal('0')
|
||||
})
|
||||
|
||||
it('#getvestingLastBlock ', async () => {
|
||||
expect(
|
||||
await sideStaking.getvestingLastBlock(contracts.sideStakingAddress, erc20Token)
|
||||
await sideStaking.getvestingLastBlock(contracts.sideStakingAddress, datatoken)
|
||||
).to.equal(initialBlock.toString())
|
||||
})
|
||||
|
||||
it('#getvestingAmountSoFar ', async () => {
|
||||
expect(
|
||||
await sideStaking.getvestingAmountSoFar(contracts.sideStakingAddress, erc20Token)
|
||||
await sideStaking.getvestingAmountSoFar(contracts.sideStakingAddress, datatoken)
|
||||
).to.equal('0')
|
||||
})
|
||||
|
||||
@ -258,7 +258,7 @@ describe('SideStaking unit test', () => {
|
||||
|
||||
const tokenInOutMarket: TokenInOutMarket = {
|
||||
tokenIn: contracts.daiAddress,
|
||||
tokenOut: erc20Token,
|
||||
tokenOut: datatoken,
|
||||
marketFeeAddress: factoryOwner
|
||||
}
|
||||
|
||||
@ -275,7 +275,7 @@ describe('SideStaking unit test', () => {
|
||||
amountsInOutMaxFee
|
||||
)
|
||||
|
||||
expect(await erc20Contract.methods.balanceOf(user1).call()).to.equal(
|
||||
expect(await datatokenContract.methods.balanceOf(user1).call()).to.equal(
|
||||
tx.events.LOG_SWAP.returnValues.tokenAmountOut
|
||||
)
|
||||
})
|
||||
@ -284,7 +284,7 @@ describe('SideStaking unit test', () => {
|
||||
await approve(web3, user1, contracts.daiAddress, poolAddress, '100')
|
||||
const tokenInOutMarket: TokenInOutMarket = {
|
||||
tokenIn: contracts.daiAddress,
|
||||
tokenOut: erc20Token,
|
||||
tokenOut: datatoken,
|
||||
marketFeeAddress: factoryOwner
|
||||
}
|
||||
const amountsInOutMaxFee: AmountsOutMaxFee = {
|
||||
@ -341,7 +341,7 @@ describe('SideStaking unit test', () => {
|
||||
expect(tx.events.LOG_EXIT[0].returnValues.tokenOut).to.equal(contracts.daiAddress)
|
||||
|
||||
// DTs were also unstaked in the same transaction (went to the staking contract)
|
||||
expect(tx.events.LOG_EXIT[1].returnValues.tokenOut).to.equal(erc20Token)
|
||||
expect(tx.events.LOG_EXIT[1].returnValues.tokenOut).to.equal(datatoken)
|
||||
})
|
||||
})
|
||||
|
||||
@ -375,32 +375,32 @@ describe('SideStaking unit test', () => {
|
||||
swapFeeMarketRunner: '0.001'
|
||||
}
|
||||
|
||||
const txReceipt = await nftFactory.createNftErc20WithPool(
|
||||
const txReceipt = await nftFactory.createNftWithDatatokenWithPool(
|
||||
factoryOwner,
|
||||
nftData,
|
||||
ercParams,
|
||||
dtParams,
|
||||
poolParams
|
||||
)
|
||||
|
||||
initialBlock = await web3.eth.getBlockNumber()
|
||||
erc20Token = txReceipt.events.TokenCreated.returnValues.newTokenAddress
|
||||
datatoken = txReceipt.events.TokenCreated.returnValues.newTokenAddress
|
||||
poolAddress = txReceipt.events.NewPool.returnValues.poolAddress
|
||||
|
||||
erc20Contract = new web3.eth.Contract(ERC20Template.abi as AbiItem[], erc20Token)
|
||||
datatokenContract = new web3.eth.Contract(ERC20Template.abi as AbiItem[], datatoken)
|
||||
// user1 has no dt1
|
||||
expect(await erc20Contract.methods.balanceOf(user1).call()).to.equal('0')
|
||||
expect(await datatokenContract.methods.balanceOf(user1).call()).to.equal('0')
|
||||
})
|
||||
|
||||
it('#getBaseTokenBalance ', async () => {
|
||||
expect(
|
||||
await sideStaking.getBaseTokenBalance(contracts.sideStakingAddress, erc20Token)
|
||||
await sideStaking.getBaseTokenBalance(contracts.sideStakingAddress, datatoken)
|
||||
).to.equal('0')
|
||||
})
|
||||
|
||||
it('#getDatatokenBalance ', async () => {
|
||||
expect(
|
||||
await (
|
||||
await sideStaking.getDatatokenBalance(contracts.sideStakingAddress, erc20Token)
|
||||
await sideStaking.getDatatokenBalance(contracts.sideStakingAddress, datatoken)
|
||||
).toString()
|
||||
).to.equal(
|
||||
new BigNumber(2)
|
||||
@ -414,19 +414,19 @@ describe('SideStaking unit test', () => {
|
||||
|
||||
it('#getvestingAmount ', async () => {
|
||||
expect(
|
||||
await sideStaking.getvestingAmount(contracts.sideStakingAddress, erc20Token)
|
||||
await sideStaking.getvestingAmount(contracts.sideStakingAddress, datatoken)
|
||||
).to.equal('0')
|
||||
})
|
||||
|
||||
it('#getvestingLastBlock ', async () => {
|
||||
expect(
|
||||
await sideStaking.getvestingLastBlock(contracts.sideStakingAddress, erc20Token)
|
||||
await sideStaking.getvestingLastBlock(contracts.sideStakingAddress, datatoken)
|
||||
).to.equal(initialBlock.toString())
|
||||
})
|
||||
|
||||
it('#getvestingAmountSoFar ', async () => {
|
||||
expect(
|
||||
await sideStaking.getvestingAmountSoFar(contracts.sideStakingAddress, erc20Token)
|
||||
await sideStaking.getvestingAmountSoFar(contracts.sideStakingAddress, datatoken)
|
||||
).to.equal('0')
|
||||
})
|
||||
|
||||
@ -439,7 +439,7 @@ describe('SideStaking unit test', () => {
|
||||
await approve(web3, user1, contracts.usdcAddress, poolAddress, '10')
|
||||
const tokenInOutMarket: TokenInOutMarket = {
|
||||
tokenIn: contracts.usdcAddress,
|
||||
tokenOut: erc20Token,
|
||||
tokenOut: datatoken,
|
||||
marketFeeAddress: factoryOwner
|
||||
}
|
||||
const amountsInOutMaxFee: AmountsInMaxFee = {
|
||||
@ -453,7 +453,7 @@ describe('SideStaking unit test', () => {
|
||||
tokenInOutMarket,
|
||||
amountsInOutMaxFee
|
||||
)
|
||||
expect(await erc20Contract.methods.balanceOf(user1).call()).to.equal(
|
||||
expect(await datatokenContract.methods.balanceOf(user1).call()).to.equal(
|
||||
tx.events.LOG_SWAP.returnValues.tokenAmountOut
|
||||
)
|
||||
})
|
||||
@ -462,7 +462,7 @@ describe('SideStaking unit test', () => {
|
||||
await approve(web3, user1, contracts.usdcAddress, poolAddress, '100')
|
||||
const tokenInOutMarket: TokenInOutMarket = {
|
||||
tokenIn: contracts.usdcAddress,
|
||||
tokenOut: erc20Token,
|
||||
tokenOut: datatoken,
|
||||
marketFeeAddress: factoryOwner
|
||||
}
|
||||
const amountsInOutMaxFee: AmountsOutMaxFee = {
|
||||
@ -517,7 +517,7 @@ describe('SideStaking unit test', () => {
|
||||
expect(tx.events.LOG_EXIT[0].returnValues.tokenOut).to.equal(contracts.usdcAddress)
|
||||
|
||||
// DTs were also unstaked in the same transaction (went to the staking contract)
|
||||
expect(tx.events.LOG_EXIT[1].returnValues.tokenOut).to.equal(erc20Token)
|
||||
expect(tx.events.LOG_EXIT[1].returnValues.tokenOut).to.equal(datatoken)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -18,7 +18,7 @@ describe('Datatoken', () => {
|
||||
let user1: string
|
||||
let user2: string
|
||||
let user3: string
|
||||
let erc20DeployerUser: string
|
||||
let datatokenDeployer: string
|
||||
let contracts: Addresses
|
||||
let nftDatatoken: Nft
|
||||
let datatoken: Datatoken
|
||||
@ -44,7 +44,7 @@ describe('Datatoken', () => {
|
||||
user1 = accounts[1]
|
||||
user2 = accounts[2]
|
||||
user3 = accounts[3]
|
||||
erc20DeployerUser = accounts[4]
|
||||
datatokenDeployer = accounts[4]
|
||||
|
||||
nftData.owner = nftOwner
|
||||
})
|
||||
@ -71,9 +71,9 @@ describe('Datatoken', () => {
|
||||
nftDatatoken = new Nft(web3, 8996)
|
||||
})
|
||||
|
||||
it('#createERC20 - should create a new ERC20 DT from NFT contract', async () => {
|
||||
await nftDatatoken.addErc20Deployer(nftAddress, nftOwner, erc20DeployerUser)
|
||||
datatokenAddress = await nftDatatoken.createErc20(
|
||||
it('#createDatatoken - should create a new ERC20 Datatoken from NFT contract', async () => {
|
||||
await nftDatatoken.addDatatokenDeployer(nftAddress, nftOwner, datatokenDeployer)
|
||||
datatokenAddress = await nftDatatoken.createDatatoken(
|
||||
nftAddress,
|
||||
nftOwner,
|
||||
nftOwner,
|
||||
@ -102,8 +102,8 @@ describe('Datatoken', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('#addMinter - should add user1 as minter, if user has ERC20Deployer permission', async () => {
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
|
||||
it('#addMinter - should add user1 as minter, if user has DatatokenDeployer permission', async () => {
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, nftOwner)) === true)
|
||||
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === false)
|
||||
|
||||
await datatoken.addMinter(datatokenAddress, nftOwner, user1)
|
||||
@ -111,45 +111,45 @@ describe('Datatoken', () => {
|
||||
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === true)
|
||||
})
|
||||
|
||||
it('#addMinter - should FAIL TO add user1 as minter, if user has ERC20Deployer permission', async () => {
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user3)) === false)
|
||||
it('#addMinter - should FAIL TO add user1 as minter, if user has DatatokenDeployer permission', async () => {
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, user3)) === false)
|
||||
assert((await datatoken.getDTPermissions(datatokenAddress, user2)).minter === false)
|
||||
|
||||
try {
|
||||
await datatoken.addMinter(datatokenAddress, user3, user2)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e.message === 'Caller is not ERC20Deployer')
|
||||
assert(e.message === 'Caller is not DatatokenDeployer')
|
||||
}
|
||||
|
||||
assert((await datatoken.getDTPermissions(datatokenAddress, user2)).minter === false)
|
||||
})
|
||||
|
||||
it('#mint - should mint ERC20 datatoken to user1, if Minter', async () => {
|
||||
it('#mint - should mint ERC20 Datatoken to user1, if Minter', async () => {
|
||||
assert((await datatoken.getDTPermissions(datatokenAddress, nftOwner)).minter === true)
|
||||
await datatoken.mint(datatokenAddress, nftOwner, '10', user1)
|
||||
|
||||
assert((await datatoken.balance(datatokenAddress, user1)) === '10')
|
||||
})
|
||||
|
||||
it('#createFixedRate - should create FRE for the erc20 dt', async () => {
|
||||
it('#createFixedRate - should create FRE for the ERC20 Datatoken', async () => {
|
||||
const fre = await datatoken.createFixedRate(datatokenAddress, nftOwner, freParams)
|
||||
assert(fre !== null)
|
||||
fixedRateAddress = fre.events.NewFixedRate.address
|
||||
exchangeId = fre.events.NewFixedRate.returnValues[0]
|
||||
})
|
||||
|
||||
it('#createFixedRate - should FAIL create FRE if NOT ERC20Deployer', async () => {
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user3)) === false)
|
||||
it('#createFixedRate - should FAIL create FRE if NOT DatatokenDeployer', async () => {
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, user3)) === false)
|
||||
try {
|
||||
await datatoken.createFixedRate(datatokenAddress, user3, freParams)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e.message === 'User is not ERC20 Deployer')
|
||||
assert(e.message === 'User is not Datatoken Deployer')
|
||||
}
|
||||
})
|
||||
|
||||
it('#createDispenser - method creates a dispenser for the erc20DT', async () => {
|
||||
it('#createDispenser - method creates a dispenser for the ERC20 Datatoken', async () => {
|
||||
const dispenserParams: DispenserParams = {
|
||||
maxTokens: '10',
|
||||
maxBalance: '100'
|
||||
@ -164,12 +164,12 @@ describe('Datatoken', () => {
|
||||
assert(dispenser !== null)
|
||||
})
|
||||
|
||||
it('#createDispenser - should FAIL to create a Dispenser if not ERC20 Deployer', async () => {
|
||||
it('#createDispenser - should FAIL to create a Dispenser if not Datatoken Deployer', async () => {
|
||||
const dispenserParams: DispenserParams = {
|
||||
maxTokens: '10',
|
||||
maxBalance: '100'
|
||||
}
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user3)) === false)
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, user3)) === false)
|
||||
try {
|
||||
await datatoken.createDispenser(
|
||||
datatokenAddress,
|
||||
@ -179,25 +179,25 @@ describe('Datatoken', () => {
|
||||
)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e.message === 'User is not ERC20 Deployer')
|
||||
assert(e.message === 'User is not Datatoken Deployer')
|
||||
}
|
||||
})
|
||||
|
||||
it('#removeMinter - should FAIL to remove user1 as minter, if caller is NOT ERC20Deployer', async () => {
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user2)) === false)
|
||||
it('#removeMinter - should FAIL to remove user1 as minter, if caller is NOT DatatokenDeployer', async () => {
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, user2)) === false)
|
||||
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === true)
|
||||
|
||||
try {
|
||||
await datatoken.removeMinter(datatokenAddress, user2, user1)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e.message === 'Caller is not ERC20Deployer')
|
||||
assert(e.message === 'Caller is not DatatokenDeployer')
|
||||
}
|
||||
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === true)
|
||||
})
|
||||
|
||||
it('#removeMinter - should remove user1 as minter, if nftDatatoken has ERC20Deployer permission', async () => {
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
|
||||
it('#removeMinter - should remove user1 as minter, if nftDatatoken has DatatokenDeployer permission', async () => {
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, nftOwner)) === true)
|
||||
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === true)
|
||||
|
||||
await datatoken.removeMinter(datatokenAddress, nftOwner, user1)
|
||||
@ -205,8 +205,8 @@ describe('Datatoken', () => {
|
||||
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === false)
|
||||
})
|
||||
|
||||
it('#addPaymentManager - should FAIL TO add user2 as paymentManager, if caller is NOT ERC20Deployer', async () => {
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === false)
|
||||
it('#addPaymentManager - should FAIL TO add user2 as paymentManager, if caller is NOT DatatokenDeployer', async () => {
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, user1)) === false)
|
||||
assert(
|
||||
(await datatoken.getDTPermissions(datatokenAddress, user2)).paymentManager === false
|
||||
)
|
||||
@ -215,15 +215,15 @@ describe('Datatoken', () => {
|
||||
await datatoken.addPaymentManager(datatokenAddress, user1, user2)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e.message === 'Caller is not ERC20Deployer')
|
||||
assert(e.message === 'Caller is not DatatokenDeployer')
|
||||
}
|
||||
assert(
|
||||
(await datatoken.getDTPermissions(datatokenAddress, user2)).paymentManager === false
|
||||
)
|
||||
})
|
||||
|
||||
it('#addPaymentManager - should add user2 as paymentManager, if caller has ERC20Deployer permission', async () => {
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
|
||||
it('#addPaymentManager - should add user2 as paymentManager, if caller has DatatokenDeployer permission', async () => {
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, nftOwner)) === true)
|
||||
assert(
|
||||
(await datatoken.getDTPermissions(datatokenAddress, user2)).paymentManager === false
|
||||
)
|
||||
@ -235,8 +235,8 @@ describe('Datatoken', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('#removePaymentManager - should FAIL TO remove user2 as paymentManager, if nftDatatoken has ERC20Deployer permission', async () => {
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === false)
|
||||
it('#removePaymentManager - should FAIL TO remove user2 as paymentManager, if nftDatatoken has DatatokenDeployer permission', async () => {
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, user1)) === false)
|
||||
assert(
|
||||
(await datatoken.getDTPermissions(datatokenAddress, user2)).paymentManager === true
|
||||
)
|
||||
@ -244,7 +244,7 @@ describe('Datatoken', () => {
|
||||
await datatoken.removePaymentManager(datatokenAddress, user1, user2)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e.message === 'Caller is not ERC20Deployer')
|
||||
assert(e.message === 'Caller is not DatatokenDeployer')
|
||||
}
|
||||
|
||||
assert(
|
||||
@ -252,8 +252,8 @@ describe('Datatoken', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('#removePaymentManager - should remove user2 as paymentManager, if Caller has ERC20Deployer permission', async () => {
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
|
||||
it('#removePaymentManager - should remove user2 as paymentManager, if Caller has DatatokenDeployer permission', async () => {
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, nftOwner)) === true)
|
||||
assert(
|
||||
(await datatoken.getDTPermissions(datatokenAddress, user2)).paymentManager === true
|
||||
)
|
||||
@ -274,7 +274,7 @@ describe('Datatoken', () => {
|
||||
await datatoken.setPaymentCollector(datatokenAddress, user1, user2)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e.message === 'Caller is not Fee Manager, owner or erc20 Deployer')
|
||||
assert(e.message === 'Caller is not Fee Manager, owner or Datatoken Deployer')
|
||||
}
|
||||
})
|
||||
|
||||
@ -302,11 +302,11 @@ describe('Datatoken', () => {
|
||||
|
||||
it('#setPaymentCollector - should set a new paymentCollector, if ERC 20 DEPLOYER', async () => {
|
||||
assert(
|
||||
(await nftDatatoken.getNftPermissions(nftAddress, erc20DeployerUser))
|
||||
(await nftDatatoken.getNftPermissions(nftAddress, datatokenDeployer))
|
||||
.deployERC20 === true
|
||||
)
|
||||
|
||||
await datatoken.setPaymentCollector(datatokenAddress, erc20DeployerUser, user3)
|
||||
await datatoken.setPaymentCollector(datatokenAddress, datatokenDeployer, user3)
|
||||
|
||||
assert((await datatoken.getPaymentCollector(datatokenAddress)) === user3)
|
||||
})
|
||||
@ -494,7 +494,7 @@ describe('Datatoken', () => {
|
||||
assert(buyTx !== null)
|
||||
})
|
||||
|
||||
it('#cleanPermissions - should FAIL to clean permissions at ERC20 level, if NOT NFT Owner', async () => {
|
||||
it('#cleanPermissions - should FAIL to clean permissions at Datatoken level, if NOT NFT Owner', async () => {
|
||||
assert((await datatoken.getDTPermissions(datatokenAddress, nftOwner)).minter === true)
|
||||
|
||||
assert((await datatoken.getPaymentCollector(datatokenAddress)) === user3)
|
||||
@ -519,7 +519,7 @@ describe('Datatoken', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('#cleanPermissions - should clean permissions at ERC20 level', async () => {
|
||||
it('#cleanPermissions - should clean permissions at Datatoken level', async () => {
|
||||
assert((await datatoken.getDTPermissions(datatokenAddress, nftOwner)).minter === true)
|
||||
|
||||
assert((await datatoken.getPaymentCollector(datatokenAddress)) === user3)
|
||||
@ -546,10 +546,10 @@ describe('Datatoken', () => {
|
||||
assert(address, 'Not able to get the parent NFT address')
|
||||
})
|
||||
|
||||
it('#setData - should set a value into 725Y standard, if Caller has ERC20Deployer permission', async () => {
|
||||
it('#setData - should set a value into 725Y standard, if Caller has DatatokenDeployer permission', async () => {
|
||||
const data = web3.utils.asciiToHex('SomeData')
|
||||
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, nftOwner)) === true)
|
||||
|
||||
await datatoken.setData(datatokenAddress, nftOwner, data)
|
||||
|
||||
@ -557,16 +557,16 @@ describe('Datatoken', () => {
|
||||
assert((await nftDatatoken.getData(nftAddress, key)) === data)
|
||||
})
|
||||
|
||||
it('#setData - should FAIL to set a value into 725Y standard, if Caller has NOT ERC20Deployer permission', async () => {
|
||||
it('#setData - should FAIL to set a value into 725Y standard, if Caller has NOT DatatokenDeployer permission', async () => {
|
||||
const data = web3.utils.asciiToHex('NewData')
|
||||
const OldData = web3.utils.asciiToHex('SomeData')
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === false)
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, user1)) === false)
|
||||
|
||||
try {
|
||||
await datatoken.setData(datatokenAddress, user1, data)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e.message === 'User is not ERC20 Deployer')
|
||||
assert(e.message === 'User is not Datatoken Deployer')
|
||||
}
|
||||
const key = web3.utils.keccak256(datatokenAddress)
|
||||
assert((await nftDatatoken.getData(nftAddress, key)) === OldData)
|
||||
|
@ -50,8 +50,8 @@ describe('NFT', () => {
|
||||
assert(tokenURI === nftData.tokenURI)
|
||||
})
|
||||
|
||||
it('#createERC20 - should create a new ERC20 DT from NFT contract', async () => {
|
||||
const erc20Address = await nftDatatoken.createErc20(
|
||||
it('#createDatatoken - should create a new ERC20 Datatoken from NFT contract', async () => {
|
||||
const dtAddress = await nftDatatoken.createDatatoken(
|
||||
nftAddress,
|
||||
nftOwner,
|
||||
nftOwner,
|
||||
@ -64,12 +64,12 @@ describe('NFT', () => {
|
||||
nftData.symbol,
|
||||
1
|
||||
)
|
||||
assert(erc20Address !== null)
|
||||
assert(dtAddress !== null)
|
||||
})
|
||||
|
||||
it('#createERC20 - should fail to create a new ERC20 DT if not ERC20Deployer', async () => {
|
||||
it('#createDatatoken - should fail to create a new ERC20 Datatoken if not DatatokenDeployer', async () => {
|
||||
try {
|
||||
await nftDatatoken.createErc20(
|
||||
await nftDatatoken.createDatatoken(
|
||||
nftAddress,
|
||||
user1,
|
||||
nftOwner,
|
||||
@ -84,7 +84,7 @@ describe('NFT', () => {
|
||||
)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e.message === 'Caller is not ERC20Deployer')
|
||||
assert(e.message === 'Caller is not DatatokenDeployer')
|
||||
}
|
||||
})
|
||||
|
||||
@ -123,53 +123,53 @@ describe('NFT', () => {
|
||||
}
|
||||
})
|
||||
|
||||
// ERC20Deployer
|
||||
it('#addERC20Deployer -should add ERC20deployer if Manager', async () => {
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === false)
|
||||
// DatatokenDeployer
|
||||
it('#addDatatokenDeployer -should add DatatokenDeployer if Manager', async () => {
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, user1)) === false)
|
||||
|
||||
await nftDatatoken.addErc20Deployer(nftAddress, nftOwner, user1)
|
||||
await nftDatatoken.addDatatokenDeployer(nftAddress, nftOwner, user1)
|
||||
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === true)
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, user1)) === true)
|
||||
})
|
||||
|
||||
it('#addERC20Deployer - should fail to add ERC20deployer if NOT Manager', async () => {
|
||||
it('#addDatatokenDeployer - should fail to add DatatokenDeployer if NOT Manager', async () => {
|
||||
try {
|
||||
await nftDatatoken.addErc20Deployer(nftAddress, user1, user1)
|
||||
await nftDatatoken.addDatatokenDeployer(nftAddress, user1, user1)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e.message === 'Caller is not Manager')
|
||||
}
|
||||
})
|
||||
|
||||
it('#removeERC20Deployer - remove ERC20deployer if Manager', async () => {
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === true)
|
||||
it('#removeDatatokenDeployer - remove DatatokenDeployer if Manager', async () => {
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, user1)) === true)
|
||||
|
||||
await nftDatatoken.removeErc20Deployer(nftAddress, nftOwner, user1)
|
||||
await nftDatatoken.removeDatatokenDeployer(nftAddress, nftOwner, user1)
|
||||
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === false)
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, user1)) === false)
|
||||
})
|
||||
|
||||
it('#removeERC20Deployer - should fail and remove ERC20deployer if NOT Manager nor himself an ERC20Deployer', async () => {
|
||||
await nftDatatoken.addErc20Deployer(nftAddress, nftOwner, user1)
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === true)
|
||||
it('#removeDatatokenDeployer - should fail and remove DatatokenDeployer if NOT Manager nor himself an DatatokenDeployer', async () => {
|
||||
await nftDatatoken.addDatatokenDeployer(nftAddress, nftOwner, user1)
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, user1)) === true)
|
||||
try {
|
||||
await nftDatatoken.removeErc20Deployer(nftAddress, user1, user1)
|
||||
await nftDatatoken.removeDatatokenDeployer(nftAddress, user1, user1)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e.message === 'Caller is not Manager nor ERC20Deployer')
|
||||
assert(e.message === 'Caller is not Manager nor DatatokenDeployer')
|
||||
}
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === true)
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, user1)) === true)
|
||||
})
|
||||
|
||||
it('#removeERC20Deployer - should fail to remove himself as an ERC20Deployer', async () => {
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === true)
|
||||
it('#removeDatatokenDeployer - should fail to remove himself as an DatatokenDeployer', async () => {
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, user1)) === true)
|
||||
try {
|
||||
await nftDatatoken.removeErc20Deployer(nftAddress, user1, user1)
|
||||
await nftDatatoken.removeDatatokenDeployer(nftAddress, user1, user1)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e.message === 'Caller is not Manager nor ERC20Deployer')
|
||||
assert(e.message === 'Caller is not Manager nor DatatokenDeployer')
|
||||
}
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === true)
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, user1)) === true)
|
||||
})
|
||||
|
||||
// MetadataUpdate
|
||||
@ -264,15 +264,15 @@ describe('NFT', () => {
|
||||
|
||||
it('#transferNFT - should transfer the NFT and clean all permissions, set new owner as manager', async () => {
|
||||
await nftDatatoken.addManager(nftAddress, nftOwner, user2)
|
||||
await nftDatatoken.addErc20Deployer(nftAddress, user2, user1)
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === true)
|
||||
await nftDatatoken.addDatatokenDeployer(nftAddress, user2, user1)
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, user1)) === true)
|
||||
|
||||
assert((await nftDatatoken.getNftOwner(nftAddress)) === nftOwner)
|
||||
await nftDatatoken.transferNft(nftAddress, nftOwner, user1, 1)
|
||||
assert((await nftDatatoken.getNftOwner(nftAddress)) === user1)
|
||||
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === false)
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user2)) === false)
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, nftOwner)) === false)
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, user2)) === false)
|
||||
})
|
||||
|
||||
// Safe transfer test
|
||||
@ -292,8 +292,8 @@ describe('NFT', () => {
|
||||
|
||||
it('#safeTransferNft - should transfer the NFT and clean all permissions, set new owner as manager', async () => {
|
||||
await nftDatatoken.addManager(nftAddress, nftOwner, user2)
|
||||
await nftDatatoken.addErc20Deployer(nftAddress, user2, user1)
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === true)
|
||||
await nftDatatoken.addDatatokenDeployer(nftAddress, user2, user1)
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, user1)) === true)
|
||||
|
||||
assert((await nftDatatoken.getNftOwner(nftAddress)) === nftOwner)
|
||||
await nftDatatoken.safeTransferNft(nftAddress, nftOwner, user1, 1)
|
||||
@ -312,12 +312,12 @@ describe('NFT', () => {
|
||||
|
||||
it('#cleanPermissions - should cleanPermissions if NFTOwner', async () => {
|
||||
await nftDatatoken.addManager(nftAddress, user1, user1)
|
||||
await nftDatatoken.addErc20Deployer(nftAddress, user1, user2)
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user2)) === true)
|
||||
await nftDatatoken.addDatatokenDeployer(nftAddress, user1, user2)
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, user2)) === true)
|
||||
|
||||
await nftDatatoken.cleanPermissions(nftAddress, user1)
|
||||
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, user2)) === false)
|
||||
assert((await nftDatatoken.isDatatokenDeployer(nftAddress, user2)) === false)
|
||||
assert((await nftDatatoken.getNftPermissions(nftAddress, nftOwner)).manager === false)
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user