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

Add confidential EVM flag when creating a datatoken 4 in NFT class (#1859)

* Add confidential EVM flag when creating a datatoken 4.

* Add comments.

* fix lint.

* fix lint.

* Add chain id check to bundled functions.

* Updating CodeExamples.md

* Updating ComputeExamples.md

* Used config object.

* Added check for sapphire confidential EVM. Fix tests.

* Added sapphire wrap signer for all contracts.

* Make network mandatory field.

* Undo making network mandatory.

* refactor condition.

* refactor condition.

* Add condition when creating NFT.

* Refactor with sdk.

* fix lint.

* tweak.

* tweak.

* Created protected function to get vthe signer according to the sdk from config.

* Fix lint. Add check for sdk within the config.

* Fix lint.

* Updating CodeExamples.md

* Updating ComputeExamples.md

---------

Co-authored-by: GitHub Actions Bot <>
This commit is contained in:
Maria Carmina 2024-10-16 15:27:41 +03:00 committed by GitHub
parent cc91e1d376
commit a0a8df328f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
32 changed files with 388 additions and 262 deletions

View File

@ -289,7 +289,11 @@ you need to mint oceans to mentioned accounts only if you are using barge to tes
### 6.1 Publish a dataset (create NFT + Datatoken) with a fixed rate exchange
```Typescript
const factory = new NftFactory(addresses.ERC721Factory, publisherAccount)
const factory = new NftFactory(
addresses.ERC721Factory,
publisherAccount,
await publisherAccount.getChainId()
)
const nftParams: NftCreateData = {
name: FRE_NFT_NAME,
@ -409,7 +413,11 @@ Now let's console log the DID to check everything is working
### 6.3 Marketplace displays fixed rate asset for sale
```Typescript
const fixedRate = new FixedRateExchange(freAddress, publisherAccount)
const fixedRate = new FixedRateExchange(
freAddress,
publisherAccount,
await publisherAccount.getChainId()
)
const oceanAmount = await (
await fixedRate.calcBaseInGivenDatatokensOut(freId, '1')
).baseTokenAmount
@ -424,7 +432,7 @@ Now that the market has fetched those values it can display the asset on the fro
### 7.1 Consumer buys a fixed rate asset data asset, and downloads it
```Typescript
datatoken = new Datatoken(publisherAccount)
datatoken = new Datatoken(publisherAccount, await publisherAccount.getChainId())
const DATATOKEN_AMOUNT = '10000'
await datatoken.mint(
@ -473,7 +481,11 @@ Before we call the contract we have to call `approve` so that the contract can m
DATATOKEN_AMOUNT
)
const fixedRate = new FixedRateExchange(freAddress, consumerAccount)
const fixedRate = new FixedRateExchange(
freAddress,
consumerAccount,
await consumerAccount.getChainId()
)
```
Now we can make the contract call
```Typescript
@ -517,7 +529,7 @@ Next, we need to initialize the provider
validUntil: initializeData.providerFee.validUntil
}
datatoken = new Datatoken(consumerAccount)
datatoken = new Datatoken(consumerAccount, await consumerAccount.getChainId())
```
Lets now make the payment
@ -574,7 +586,11 @@ Lets check that the download URL was successfully received
### 8.1 Publish a dataset (create NFT + Datatoken) with a dispenser
```Typescript
const factory = new NftFactory(addresses.ERC721Factory, publisherAccount)
const factory = new NftFactory(
addresses.ERC721Factory,
publisherAccount,
await publisherAccount.getChainId()
)
const nftParams: NftCreateData = {
name: DISP_NFT_NAME,
@ -679,8 +695,12 @@ Now we need to encrypt file(s) using provider
### 9.1 Consumer gets a dispenser data asset, and downloads it
```Typescript
datatoken = new Datatoken(publisherAccount)
const dispenser = new Dispenser(addresses.Dispenser, consumerAccount)
datatoken = new Datatoken(publisherAccount, await publisherAccount.getChainId())
const dispenser = new Dispenser(
addresses.Dispenser,
consumerAccount,
await consumerAccount.getChainId()
)
let consumerDTBalance = await balance(
consumerAccount,
@ -709,7 +729,7 @@ Now we need to encrypt file(s) using provider
const resolvedDDO = await aquarius.waitForAqua(fixedDDO.id)
assert(resolvedDDO, 'Cannot fetch DDO from Aquarius')
datatoken = new Datatoken(consumerAccount)
datatoken = new Datatoken(consumerAccount, await consumerAccount.getChainId())
```
At this point we need to encrypt file(s) using provider
@ -791,7 +811,7 @@ Here are the steps:
### 10.1 Add key-value pair to data NFT
Let's start by using the `setData` method to update the nft key value store with some data
```Typescript
const nft = new Nft(publisherAccount)
const nft = new Nft(publisherAccount, await publisherAccount.getChainId())
const data = 'SomeData'
try {
await nft.setData(

View File

@ -293,7 +293,11 @@ async function createAsset(
) {
const nft = new Nft(owner, (await owner.provider.getNetwork()).chainId)
const nftFactory = new NftFactory(addresses.ERC721Factory, owner)
const nftFactory = new NftFactory(
addresses.ERC721Factory,
owner,
await owner.getChainId()
)
const chain = (await owner.provider.getNetwork()).chainId

View File

@ -1,6 +1,8 @@
import { AbiItem } from '../@types'
import { LogLevel } from '../utils'
type SDK = 'evm' | 'oasis'
export class Config {
/**
* Ethereum node URL.
@ -187,6 +189,6 @@ export class Config {
veFeeEstimate?: string
// is confidential evm
confidentialEVM?: boolean
sdk?: SDK
accessListFactory?: string
}

View File

@ -35,11 +35,12 @@ export const configHelperNetworks: Config[] = [
// comment th following configs if running on macOS
metadataCacheUri: 'http://172.15.0.5:5000',
providerUri: 'http://172.15.0.4:8030',
subgraphUri: 'https://172.15.0.15:8000'
subgraphUri: 'https://172.15.0.15:8000',
// uncomment the following configs if running on macOS
// metadataCacheUri: 'http://127.0.0.1:5000',
// providerUri: 'http://127.0.0.1:8030/',
// subgraphUri: 'http://127.0.0.1:9000/'
sdk: 'evm'
},
{
...configHelperNetworksBase,
@ -48,7 +49,8 @@ export const configHelperNetworks: Config[] = [
nodeUri: 'https://sepolia.infura.io/v3',
subgraphUri: 'https://v4.subgraph.sepolia.oceanprotocol.com',
explorerUri: 'https://sepolia.etherscan.io',
gasFeeMultiplier: 1.1
gasFeeMultiplier: 1.1,
sdk: 'evm'
},
{
...configHelperNetworksBase,
@ -61,7 +63,8 @@ export const configHelperNetworks: Config[] = [
transactionBlockTimeout: 150,
transactionConfirmationBlocks: 5,
transactionPollingTimeout: 1750,
gasFeeMultiplier: 1.05
gasFeeMultiplier: 1.05,
sdk: 'evm'
},
{
...configHelperNetworksBase,
@ -71,7 +74,8 @@ export const configHelperNetworks: Config[] = [
subgraphUri: 'https://v4.subgraph.polygon.oceanprotocol.com',
explorerUri: 'https://polygonscan.com',
oceanTokenSymbol: 'mOCEAN',
gasFeeMultiplier: 1.6
gasFeeMultiplier: 1.6,
sdk: 'evm'
},
{
...configHelperNetworksBase,
@ -80,7 +84,8 @@ export const configHelperNetworks: Config[] = [
nodeUri: 'https://rpc.gaiaxtestnet.oceanprotocol.com',
providerUri: 'https://v4.provider.gaiaxtestnet.oceanprotocol.com',
subgraphUri: 'https://v4.subgraph.gaiaxtestnet.oceanprotocol.com',
explorerUri: 'https://blockscout.gaiaxtestnet.oceanprotocol.com'
explorerUri: 'https://blockscout.gaiaxtestnet.oceanprotocol.com',
sdk: 'evm'
},
{
...configHelperNetworksBase,
@ -89,7 +94,8 @@ export const configHelperNetworks: Config[] = [
nodeUri: 'https://polygon-mumbai.infura.io/v3',
subgraphUri: 'https://v4.subgraph.mumbai.oceanprotocol.com',
explorerUri: 'https://mumbai.polygonscan.com',
gasFeeMultiplier: 1.1
gasFeeMultiplier: 1.1,
sdk: 'evm'
},
{
...configHelperNetworksBase,
@ -98,7 +104,8 @@ export const configHelperNetworks: Config[] = [
nodeUri: 'https://bsc-dataseed.binance.org',
subgraphUri: 'https://v4.subgraph.bsc.oceanprotocol.com',
explorerUri: 'https://bscscan.com/',
gasFeeMultiplier: 1.05
gasFeeMultiplier: 1.05,
sdk: 'evm'
},
{
...configHelperNetworksBase,
@ -107,7 +114,8 @@ export const configHelperNetworks: Config[] = [
nodeUri: 'https://rpc.energyweb.org',
subgraphUri: 'https://v4.subgraph.energyweb.oceanprotocol.com',
explorerUri: 'https://explorer.energyweb.org',
gasFeeMultiplier: 1.05
gasFeeMultiplier: 1.05,
sdk: 'evm'
},
{
...configHelperNetworksBase,
@ -116,7 +124,8 @@ export const configHelperNetworks: Config[] = [
nodeUri: 'https://moonriver.api.onfinality.io/public',
subgraphUri: 'https://v4.subgraph.moonriver.oceanprotocol.com',
explorerUri: 'https://moonriver.moonscan.io/',
gasFeeMultiplier: 1.05
gasFeeMultiplier: 1.05,
sdk: 'evm'
},
{
...configHelperNetworksBase,
@ -127,7 +136,8 @@ export const configHelperNetworks: Config[] = [
providerUri: 'https://provider.v4.genx.delta-dao.com',
subgraphUri: 'https://subgraph.v4.genx.minimal-gaia-x.eu',
explorerUri: 'https://explorer.genx.minimal-gaia-x.eu/',
gasFeeMultiplier: 1
gasFeeMultiplier: 1,
sdk: 'evm'
},
{
...configHelperNetworksBase,
@ -136,7 +146,8 @@ export const configHelperNetworks: Config[] = [
nodeUri: 'https://mainnet.optimism.io',
subgraphUri: 'https://v4.subgraph.optimism.oceanprotocol.com',
explorerUri: 'https://optimistic.etherscan.io/',
gasFeeMultiplier: 1.1
gasFeeMultiplier: 1.1,
sdk: 'evm'
},
{
...configHelperNetworksBase,
@ -145,7 +156,8 @@ export const configHelperNetworks: Config[] = [
nodeUri: 'https://sepolia.optimism.io',
subgraphUri: 'https://v4.subgraph.optimism-sepolia.oceanprotocol.com',
explorerUri: 'https://sepolia-optimism.etherscan.io/',
gasFeeMultiplier: 1.1
gasFeeMultiplier: 1.1,
sdk: 'evm'
},
{
...configHelperNetworksBase,
@ -154,7 +166,8 @@ export const configHelperNetworks: Config[] = [
nodeUri: 'https://sapphire.oasis.io',
subgraphUri: 'https://v4.subgraph.sapphire-mainnet.oceanprotocol.com/',
explorerUri: 'https://explorer.oasis.io/mainnet/sapphire/',
gasFeeMultiplier: 1
gasFeeMultiplier: 1,
sdk: 'oasis'
},
{
...configHelperNetworksBase,
@ -164,7 +177,8 @@ export const configHelperNetworks: Config[] = [
subgraphUri:
'https://v4.subgraph.sapphire-testnet.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph',
explorerUri: 'https://explorer.oasis.io/testnet/sapphire/',
gasFeeMultiplier: 1
gasFeeMultiplier: 1,
sdk: 'oasis'
},
{
...configHelperNetworksBase,
@ -174,7 +188,8 @@ export const configHelperNetworks: Config[] = [
metadataCacheUri: 'https://aquarius.dev.pontus-x.eu',
providerUri: 'https://provider.dev.pontus-x.eu',
subgraphUri: 'https://subgraph.dev.pontus-x.eu',
explorerUri: 'https://explorer.dev.pontus-x.eu/testnet/pontusx'
explorerUri: 'https://explorer.dev.pontus-x.eu/testnet/pontusx',
sdk: 'evm'
}
]
@ -315,13 +330,16 @@ export class ConfigHelper {
addresses
)
}
config.confidentialEVM =
filterBy === 'chainId'
? KNOWN_CONFIDENTIAL_EVMS.includes(Number(network))
: network.toString().includes('oasis_sap')
if (config.confidentialEVM) {
config.accessListFactory = contractAddressesConfig.accessListFactory
if (!('sdk' in config) || config.sdk === null) {
if (KNOWN_CONFIDENTIAL_EVMS.includes(config.chainId)) {
config.sdk = 'oasis'
} else {
config.sdk = 'evm'
}
}
config.accessListFactory = contractAddressesConfig.accessListFactory
config = { ...config, ...contractAddressesConfig }

View File

@ -96,10 +96,9 @@ export class AccessListContract extends SmartContractWithAddress {
): Promise<ReceiptOrEstimate<G>> {
const estGas = await this.contract.estimateGas.mint(user, tokenUri)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.mint,
user,
@ -122,10 +121,9 @@ export class AccessListContract extends SmartContractWithAddress {
): Promise<ReceiptOrEstimate<G>> {
const estGas = await this.contract.estimateGas.batchMint(users, tokenUris)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.batchMint,
users,
@ -146,10 +144,9 @@ export class AccessListContract extends SmartContractWithAddress {
): Promise<ReceiptOrEstimate<G>> {
const estGas = await this.contract.estimateGas.burn(tokenId)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.burn,
tokenId
@ -169,10 +166,9 @@ export class AccessListContract extends SmartContractWithAddress {
): Promise<ReceiptOrEstimate<G>> {
const estGas = await this.contract.estimateGas.transferOwnership(newOwner)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.transferOwnership,
newOwner
@ -190,10 +186,9 @@ export class AccessListContract extends SmartContractWithAddress {
): Promise<ReceiptOrEstimate<G>> {
const estGas = await this.contract.estimateGas.renounceOwnership()
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.renounceOwnership
)

View File

@ -70,7 +70,7 @@ export class AccesslistFactory extends SmartContractWithAddress {
try {
const tx = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.deployAccessListContract,
nameAccessList,
@ -144,10 +144,9 @@ export class AccesslistFactory extends SmartContractWithAddress {
const estGas = await this.contract.estimateGas.changeTemplateAddress(templateAddress)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.functions.changeTemplateAddress,
templateAddress

View File

@ -44,7 +44,7 @@ export class Datatoken extends SmartContract {
) {
super(signer, network, config, abi)
this.abiEnterprise = abiEnterprise || (ERC20TemplateEnterprise.abi as AbiItem[])
this.nft = new Nft(this.signer)
this.nft = new Nft(this.signer, network)
}
/**
@ -62,7 +62,6 @@ export class Datatoken extends SmartContract {
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
const dtContract = this.getContract(dtAddress)
const estGas = await dtContract.estimateGas.approve(
spender,
amountToUnits(null, null, amount, 18)
@ -71,7 +70,7 @@ export class Datatoken extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
dtContract.approve,
spender,
@ -124,7 +123,7 @@ export class Datatoken extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
dtContract.createFixedRate,
fixedRateParams.fixedRateAddress,
@ -166,7 +165,6 @@ export class Datatoken extends SmartContract {
}
const dtContract = this.getContract(dtAddress)
if (!dispenserParams.allowedSwapper) dispenserParams.allowedSwapper = ZERO_ADDRESS
dispenserParams.withMint = dispenserParams.withMint !== false
@ -184,7 +182,7 @@ export class Datatoken extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
dtContract.createDispenser,
dispenserAddress,
@ -213,7 +211,6 @@ export class Datatoken extends SmartContract {
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
const dtContract = this.getContract(dtAddress)
if ((await this.getPermissions(dtAddress, address)).minter !== true) {
throw new Error(`Caller is not Minter`)
}
@ -228,7 +225,7 @@ export class Datatoken extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
dtContract.mint,
toAddress || address,
@ -256,7 +253,6 @@ export class Datatoken extends SmartContract {
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
const dtContract = this.getContract(dtAddress)
if ((await this.isDatatokenDeployer(dtAddress, address)) !== true) {
throw new Error(`Caller is not DatatokenDeployer`)
}
@ -266,7 +262,7 @@ export class Datatoken extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
dtContract.addMinter,
minter
@ -291,7 +287,6 @@ export class Datatoken extends SmartContract {
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
const dtContract = this.getContract(dtAddress)
if ((await this.isDatatokenDeployer(dtAddress, address)) !== true) {
throw new Error(`Caller is not DatatokenDeployer`)
}
@ -301,7 +296,7 @@ export class Datatoken extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
dtContract.removeMinter,
minter
@ -326,7 +321,6 @@ export class Datatoken extends SmartContract {
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
const dtContract = this.getContract(dtAddress)
if ((await this.isDatatokenDeployer(dtAddress, address)) !== true) {
throw new Error(`Caller is not DatatokenDeployer`)
}
@ -336,7 +330,7 @@ export class Datatoken extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
dtContract.addPaymentManager,
paymentManager
@ -361,7 +355,6 @@ export class Datatoken extends SmartContract {
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
const dtContract = this.getContract(dtAddress)
if ((await this.isDatatokenDeployer(dtAddress, address)) !== true) {
throw new Error(`Caller is not DatatokenDeployer`)
}
@ -371,7 +364,7 @@ export class Datatoken extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
dtContract.removePaymentManager,
paymentManager
@ -413,7 +406,7 @@ export class Datatoken extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
dtContract.setPaymentCollector,
paymentCollector
@ -469,13 +462,12 @@ export class Datatoken extends SmartContract {
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
const dtContract = this.getContract(dtAddress)
const estGas = await dtContract.estimateGas.transfer(toAddress, amount)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
dtContract.transfer,
toAddress,
@ -518,10 +510,9 @@ export class Datatoken extends SmartContract {
consumeMarketFee
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
dtContract.startOrder,
consumer,
@ -552,10 +543,9 @@ export class Datatoken extends SmartContract {
const estGas = await dtContract.estimateGas.reuseOrder(orderTxId, providerFees)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
dtContract.reuseOrder,
orderTxId,
@ -587,10 +577,9 @@ export class Datatoken extends SmartContract {
freContractParams
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
dtContract.buyFromFreAndOrder,
orderParams,
@ -620,10 +609,9 @@ export class Datatoken extends SmartContract {
dispenserContract
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
dtContract.buyFromDispenserAndOrder,
orderParams,
@ -652,7 +640,6 @@ export class Datatoken extends SmartContract {
}
const dtContract = this.getContract(dtAddress)
const valueHex = ethers.utils.hexlify(ethers.utils.toUtf8Bytes(value))
const estGas = await dtContract.estimateGas.setData(valueHex)
@ -660,7 +647,7 @@ export class Datatoken extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
dtContract.setData,
valueHex
@ -686,13 +673,12 @@ export class Datatoken extends SmartContract {
throw new Error('Caller is NOT Nft Owner')
}
const dtContract = this.getContract(dtAddress)
const estGas = await dtContract.estimateGas.cleanPermissions()
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
dtContract.cleanPermissions
)
@ -856,10 +842,9 @@ export class Datatoken extends SmartContract {
publishMarketFeeAmount
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
dtContract.setPublishingMarketFee,
publishMarketFeeAddress,

View File

@ -6,7 +6,6 @@ import { AbiItem, ReceiptOrEstimate } from '../@types'
import { AccessListContract } from './AccessList'
import { Config } from '../config'
import { sendTx } from '../utils'
import * as sapphire from '@oasisprotocol/sapphire-paratime'
export class Datatoken4 extends Datatoken {
public accessList: AccessListContract
@ -73,7 +72,6 @@ export class Datatoken4 extends Datatoken {
dtAddress: string,
address: string,
consumer: string,
confidentialEVM: boolean = true,
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
if (!(await this.isDatatokenDeployer(dtAddress, consumer))) {
@ -86,7 +84,7 @@ export class Datatoken4 extends Datatoken {
const trxReceipt = await sendTx(
estGas,
confidentialEVM === true ? sapphire.wrap(this.signer) : this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
dtContract.functions.setAllowListContract,
address
@ -108,7 +106,6 @@ export class Datatoken4 extends Datatoken {
dtAddress: string,
address: string,
consumer: string,
confidentialEVM: boolean = true,
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
if (!(await this.isDatatokenDeployer(dtAddress, consumer))) {
@ -121,7 +118,7 @@ export class Datatoken4 extends Datatoken {
const trxReceipt = await sendTx(
estGas,
confidentialEVM === true ? sapphire.wrap(this.signer) : this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
dtContract.functions.setDenyListContract,
address
@ -140,7 +137,6 @@ export class Datatoken4 extends Datatoken {
public async setFileObject<G extends boolean = false>(
dtAddress: string,
address: string,
confidentialEVM: boolean = true,
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
if (!(await this.isDatatokenDeployer(dtAddress, address))) {
@ -153,7 +149,7 @@ export class Datatoken4 extends Datatoken {
const trxReceipt = await sendTx(
estGas,
confidentialEVM === true ? sapphire.wrap(this.signer) : this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
dtContract.functions.setFilesObject,
this.fileObject

View File

@ -58,11 +58,10 @@ export class Dispenser extends SmartContractWithAddress {
allowedSwapper
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
// Call createFixedRate contract method
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.create,
dtAddress,
@ -95,10 +94,9 @@ export class Dispenser extends SmartContractWithAddress {
this.amountToUnits(null, maxBalance, 18)
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.activate,
dtAddress,
@ -121,10 +119,9 @@ export class Dispenser extends SmartContractWithAddress {
): Promise<ReceiptOrEstimate<G>> {
const estGas = await this.contract.estimateGas.deactivate(dtAddress)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.deactivate,
dtAddress
@ -150,10 +147,9 @@ export class Dispenser extends SmartContractWithAddress {
newAllowedSwapper
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.setAllowedSwapper,
dtAddress,
@ -184,10 +180,9 @@ export class Dispenser extends SmartContractWithAddress {
destination
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.dispense,
dtAddress,
@ -209,10 +204,9 @@ export class Dispenser extends SmartContractWithAddress {
): Promise<ReceiptOrEstimate<G>> {
const estGas = await this.contract.estimateGas.ownerWithdraw(dtAddress)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.ownerWithdraw,
dtAddress

View File

@ -64,10 +64,9 @@ export class FixedRateExchange extends SmartContractWithAddress {
consumeMarketFeeFormatted
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.buyDT,
exchangeId,
@ -118,10 +117,9 @@ export class FixedRateExchange extends SmartContractWithAddress {
consumeMarketFeeFormatted
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.sellDT,
exchangeId,
@ -159,10 +157,9 @@ export class FixedRateExchange extends SmartContractWithAddress {
await this.amountToUnits(null, newRate, 18)
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.setRate,
exchangeId,
@ -189,10 +186,9 @@ export class FixedRateExchange extends SmartContractWithAddress {
newAllowedSwapper
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.setAllowedSwapper,
exchangeId,
@ -216,10 +212,9 @@ export class FixedRateExchange extends SmartContractWithAddress {
if (exchange.active === true) return null
const estGas = await this.contract.estimateGas.toggleExchangeState(exchangeId)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.toggleExchangeState,
exchangeId
@ -243,10 +238,9 @@ export class FixedRateExchange extends SmartContractWithAddress {
const estGas = await this.contract.estimateGas.toggleExchangeState(exchangeId)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.toggleExchangeState,
exchangeId
@ -469,10 +463,9 @@ export class FixedRateExchange extends SmartContractWithAddress {
const estGas = await this.contract.estimateGas.toggleMintState(exchangeId, true)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.toggleMintState,
exchangeId,
@ -497,10 +490,9 @@ export class FixedRateExchange extends SmartContractWithAddress {
const estGas = await this.contract.estimateGas.toggleMintState(exchangeId, false)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.toggleMintState,
exchangeId,
@ -533,10 +525,9 @@ export class FixedRateExchange extends SmartContractWithAddress {
const estGas = await this.contract.estimateGas.collectBT(exchangeId, amountWei)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.collectBT,
exchangeId,
@ -569,10 +560,9 @@ export class FixedRateExchange extends SmartContractWithAddress {
const estGas = await this.contract.estimateGas.collectDT(exchangeId, amountWei)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.collectDT,
exchangeId,
@ -596,10 +586,9 @@ export class FixedRateExchange extends SmartContractWithAddress {
const estGas = await this.contract.estimateGas.collectMarketFee(exchangeId)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.collectMarketFee,
exchangeId
@ -623,10 +612,9 @@ export class FixedRateExchange extends SmartContractWithAddress {
const estGas = await this.contract.estimateGas.collectOceanFee(exchangeId)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.collectOceanFee,
exchangeId
@ -680,10 +668,9 @@ export class FixedRateExchange extends SmartContractWithAddress {
await this.amountToUnits(null, newMarketFee, 18)
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.updateMarketFee,
exchangeId,
@ -710,10 +697,9 @@ export class FixedRateExchange extends SmartContractWithAddress {
newMarketFeeCollector
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.updateMarketFeeCollector,
exchangeId,

View File

@ -104,7 +104,7 @@ export class Nft extends SmartContract {
const tx = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
nftContract.createERC20,
templateIndex,
@ -146,7 +146,7 @@ export class Nft extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
nftContract.addManager,
manager
@ -180,7 +180,7 @@ export class Nft extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
nftContract.removeManager,
manager
@ -215,7 +215,7 @@ export class Nft extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
nftContract.addToCreateERC20List,
datatokenDeployer
@ -254,7 +254,7 @@ export class Nft extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
nftContract.removeFromCreateERC20List,
datatokenDeployer
@ -288,7 +288,7 @@ export class Nft extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
nftContract.addToMetadataList,
metadataUpdater
@ -311,7 +311,6 @@ export class Nft extends SmartContract {
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
const nftContract = this.getContract(nftAddress)
if (
(await this.getNftPermissions(nftAddress, address)).manager !== true ||
(address !== metadataUpdater &&
@ -325,7 +324,7 @@ export class Nft extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
nftContract.removeFromMetadataList,
metadataUpdater
@ -358,7 +357,7 @@ export class Nft extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
nftContract.addTo725StoreList,
storeUpdater
@ -382,7 +381,6 @@ export class Nft extends SmartContract {
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
const nftContract = this.getContract(nftAddress)
if (
(await this.getNftPermissions(nftAddress, address)).manager !== true ||
(address !== storeUpdater &&
@ -396,7 +394,7 @@ export class Nft extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
nftContract.removeFrom725StoreList,
storeUpdater
@ -421,7 +419,6 @@ export class Nft extends SmartContract {
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
const nftContract = this.getContract(nftAddress)
if ((await this.getNftOwner(nftAddress)) !== address) {
throw new Error(`Caller is not NFT Owner`)
}
@ -431,7 +428,7 @@ export class Nft extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
nftContract.cleanPermissions
)
@ -457,7 +454,6 @@ export class Nft extends SmartContract {
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
const nftContract = this.getContract(nftAddress)
if ((await this.getNftOwner(nftAddress)) !== nftOwner) {
throw new Error(`Caller is not NFT Owner`)
}
@ -473,7 +469,7 @@ export class Nft extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
nftContract.transferFrom,
nftOwner,
@ -502,7 +498,6 @@ export class Nft extends SmartContract {
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
const nftContract = this.getContract(nftAddress)
if ((await this.getNftOwner(nftAddress)) !== nftOwner) {
throw new Error(`Caller is not NFT Owner`)
}
@ -518,7 +513,7 @@ export class Nft extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
nftContract.safeTransferFrom,
nftOwner,
@ -641,7 +636,6 @@ export class Nft extends SmartContract {
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
const nftContract = this.getContract(nftAddress)
if (!(await this.getNftPermissions(nftAddress, address)).updateMetadata) {
throw new Error(`Caller is not Metadata updater`)
}
@ -651,7 +645,7 @@ export class Nft extends SmartContract {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
nftContract.setMetaDataState,
metadataState
@ -672,13 +666,12 @@ export class Nft extends SmartContract {
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
const nftContract = this.getContract(nftAddress)
const estGas = await nftContract.estimateGas.setTokenURI('1', data)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
nftContract.setTokenURI,
'1',
@ -757,7 +750,6 @@ export class Nft extends SmartContract {
}
const nftContract = this.getContract(nftAddress)
const keyHash = ethers.utils.keccak256(key)
const valueHex = ethers.utils.hexlify(ethers.utils.toUtf8Bytes(value))
@ -765,7 +757,7 @@ export class Nft extends SmartContract {
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
nftContract.setNewData,
keyHash,

View File

@ -55,6 +55,7 @@ export class NftFactory extends SmartContractWithAddress {
if ((await this.getNFTTemplate(nftData.templateIndex)).isActive === false) {
throw new Error(`Template is not active`)
}
const estGas = await this.contract.estimateGas.deployERC721Contract(
nftData.name,
nftData.symbol,
@ -70,7 +71,7 @@ export class NftFactory extends SmartContractWithAddress {
try {
const tx = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.deployERC721Contract,
nftData.name,
@ -212,7 +213,7 @@ export class NftFactory extends SmartContractWithAddress {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.add721TokenTemplate,
templateAddress
@ -242,12 +243,13 @@ export class NftFactory extends SmartContractWithAddress {
if (templateIndex === 0) {
throw new Error(`Template index cannot be ZERO`)
}
const estGas = await this.contract.estimateGas.disable721TokenTemplate(templateIndex)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.disable721TokenTemplate,
templateIndex
@ -286,7 +288,7 @@ export class NftFactory extends SmartContractWithAddress {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.reactivate721TokenTemplate,
templateIndex
@ -319,7 +321,7 @@ export class NftFactory extends SmartContractWithAddress {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.addTokenTemplate,
templateAddress
@ -353,12 +355,13 @@ export class NftFactory extends SmartContractWithAddress {
if ((await this.getTokenTemplate(templateIndex)).isActive === false) {
throw new Error(`Template is already disabled`)
}
const estGas = await this.contract.estimateGas.disableTokenTemplate(templateIndex)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.disableTokenTemplate,
templateIndex
@ -398,7 +401,7 @@ export class NftFactory extends SmartContractWithAddress {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.reactivateTokenTemplate,
templateIndex
@ -431,7 +434,7 @@ export class NftFactory extends SmartContractWithAddress {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.startMultipleTokenOrder,
orders
@ -454,6 +457,7 @@ export class NftFactory extends SmartContractWithAddress {
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
const ercCreateData = await this.getErcCreationParams(dtParams)
const estGas = await this.contract.estimateGas.createNftWithErc20(
nftCreateData,
ercCreateData
@ -462,7 +466,7 @@ export class NftFactory extends SmartContractWithAddress {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.createNftWithErc20,
nftCreateData,
@ -499,7 +503,7 @@ export class NftFactory extends SmartContractWithAddress {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.createNftWithErc20WithFixedRate,
nftCreateData,
@ -548,7 +552,7 @@ export class NftFactory extends SmartContractWithAddress {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.createNftWithErc20WithDispenser,
nftCreateData,

View File

@ -28,7 +28,7 @@ export class Router extends SmartContractWithAddress {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.buyDTBatch,
operations
@ -93,7 +93,7 @@ export class Router extends SmartContractWithAddress {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.addApprovedToken,
tokenAddress
@ -123,7 +123,7 @@ export class Router extends SmartContractWithAddress {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.removeApprovedToken,
tokenAddress
@ -152,7 +152,7 @@ export class Router extends SmartContractWithAddress {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.addFixedRateContract,
tokenAddress
@ -182,7 +182,7 @@ export class Router extends SmartContractWithAddress {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.removeFixedRateContract,
tokenAddress
@ -212,7 +212,7 @@ export class Router extends SmartContractWithAddress {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.addDispenserContract,
tokenAddress
@ -241,7 +241,7 @@ export class Router extends SmartContractWithAddress {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.removeDispenserContract,
tokenAddress
@ -295,7 +295,7 @@ export class Router extends SmartContractWithAddress {
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.updateOPCFee,
newSwapOceanFee,

View File

@ -7,6 +7,7 @@ import {
setContractDefaults,
unitsToAmount
} from '../utils'
import * as sapphire from '@oasisprotocol/sapphire-paratime'
export abstract class SmartContract {
public signer: Signer
@ -29,10 +30,16 @@ export abstract class SmartContract {
abi?: AbiItem[]
) {
this.signer = signer
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
this.config = config || new ConfigHelper().getConfig(network)
this.abi = abi || this.getDefaultAbi()
}
protected getSignerAccordingSdk() {
return this.config && 'sdk' in this.config && this.config.sdk === 'oasis'
? sapphire.wrap(this.signer)
: this.signer
}
/**
* Converts an amount of tokens to units
* @param {string} token - The token to convert

View File

@ -40,11 +40,10 @@ export class DfRewards extends SmartContractWithAddress {
): Promise<ReceiptOrEstimate<G>> {
const estGas = await this.contract.estimateGas.claimFor(userAddress, tokenAddress)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
// Invoke function of the contract
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.claimFor,
userAddress,
@ -76,11 +75,10 @@ export class DfRewards extends SmartContractWithAddress {
tokenAddress
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
// Invoke function of the contract
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.allocate,
userAddresses,

View File

@ -43,11 +43,10 @@ export class DfStrategyV1 extends SmartContractWithAddress {
tokenAddresses
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
// Invoke function of the contract
const trxReceipt = await sendTx(
estGas,
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.claimMultiple,
userAddress,

View File

@ -4,7 +4,10 @@ export * from './Dispenser'
export * from './FixedRateExchange'
export * from './Router'
export * from './Datatoken'
export * from './Datatoken4'
export * from './NFT'
export * from './AccessList'
export * from './AccessListFactory'
export * from './NFTFactory'
export * from './ve/VeOcean'
export * from './ve/VeFeeDistributor'

View File

@ -30,7 +30,7 @@ export class VeAllocate extends SmartContractWithAddress {
// Invoke function of the contract
const trxReceipt = await sendTx(
estGas.add(20000),
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.setAllocation,
amount,
@ -60,11 +60,10 @@ export class VeAllocate extends SmartContractWithAddress {
chainId
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
// Invoke function of the contract
const trxReceipt = await sendTx(
estGas.add(20000),
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.setBatchAllocation,
amount,

View File

@ -29,7 +29,7 @@ export class VeFeeDistributor extends SmartContractWithAddress {
// Invoke function of the contract
const trxReceipt = await sendTx(
estGas.add(20000),
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.claim
)
@ -51,11 +51,10 @@ export class VeFeeDistributor extends SmartContractWithAddress {
): Promise<ReceiptOrEstimate<G>> {
const estGas = await this.contract.estimateGas.claim_many(addresses)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
// Invoke function of the contract
const trxReceipt = await sendTx(
estGas.add(20000),
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.claim_many,
addresses

View File

@ -28,11 +28,10 @@ export class VeOcean extends SmartContractWithAddress {
unlockTime
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
// Invoke function of the contract
const trxReceipt = await sendTx(
estGas.add(20000),
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.create_lock,
amountFormatted,
@ -57,11 +56,10 @@ export class VeOcean extends SmartContractWithAddress {
const amountFormatted = await this.amountToUnits(await this.getToken(), amount)
const estGas = await this.contract.estimateGas.deposit_for(toAddress, amountFormatted)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
// Invoke function of the contract
const trxReceipt = await sendTx(
estGas.add(20000),
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.deposit_for,
toAddress,
@ -83,11 +81,10 @@ export class VeOcean extends SmartContractWithAddress {
const amountFormatted = await this.amountToUnits(await this.getToken(), amount)
const estGas = await this.contract.estimateGas.increase_amount(amountFormatted)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
// Invoke function of the contract
const trxReceipt = await sendTx(
estGas.add(20000),
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.increase_amount,
amountFormatted
@ -107,11 +104,10 @@ export class VeOcean extends SmartContractWithAddress {
): Promise<ReceiptOrEstimate<G>> {
const estGas = await this.contract.estimateGas.increase_unlock_time(unlockTime)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
// Invoke function of the contract
const trxReceipt = await sendTx(
estGas.add(20000),
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.increase_unlock_time,
unlockTime
@ -129,11 +125,10 @@ export class VeOcean extends SmartContractWithAddress {
): Promise<ReceiptOrEstimate<G>> {
const estGas = await this.contract.estimateGas.withdraw()
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
// Invoke function of the contract
const trxReceipt = await sendTx(
estGas.add(20000),
this.signer,
this.getSignerAccordingSdk(),
this.config?.gasFeeMultiplier,
this.contract.withdraw
)

View File

@ -26,9 +26,9 @@ import ERC20Template4 from '@oceanprotocol/contracts/artifacts/contracts/templat
export const DEVELOPMENT_CHAIN_ID = 8996
// template address OR templateId
export function isConfidentialEVM(network: string | number): boolean {
export function useOasisSDK(network: string | number): boolean {
const config = new ConfigHelper().getConfig(network)
return config && config.confidentialEVM
return config && config.sdk === 'oasis'
}
/**
@ -196,7 +196,7 @@ export async function createAsset(
}
// include fileObject in the DT constructor
if (config.confidentialEVM) {
if (config.sdk === 'oasis') {
datatokenParams.filesObject = assetUrl
datatokenParams.accessListFactory = accessListFactory || config.accessListFactory
datatokenParams.allowAccessList = allowAccessList
@ -256,7 +256,7 @@ export async function createAsset(
assetUrl.datatokenAddress = datatokenAddressAsset
assetUrl.nftAddress = nftAddress
if (config.confidentialEVM) {
if (config.sdk === 'oasis') {
// we need to update files object on the SC otherwise it will fail validation on provider
// because DDO datatokenAddress and nftAddress will not match the values on files object
const contract = new ethers.Contract(datatokenAddressAsset, ERC20Template4.abi, owner)
@ -274,7 +274,7 @@ export async function createAsset(
}
// if confidential EVM no need to make encrypt call here
if (config.confidentialEVM) {
if (config.sdk === 'oasis') {
ddo.services[0].files = '' // on confidental EVM it needs to be empty string not null, for schema validation
} else {
ddo.services[0].files = await ProviderInstance.encrypt(assetUrl, chainID, providerUrl)

View File

@ -1,6 +1,6 @@
import { ethers, Signer, providers, Contract, ContractFunction, BigNumber } from 'ethers'
import { Config } from '../config'
import { Config, KNOWN_CONFIDENTIAL_EVMS } from '../config'
import { LoggerInstance, minAbi } from '.'
const MIN_GAS_FEE_POLYGON = 30000000000 // minimum recommended 30 gwei polygon main and mumbai fees
@ -9,8 +9,6 @@ const MIN_GAS_FEE_SAPPHIRE = 10000000000 // recommended for mainnet and testnet
const POLYGON_NETWORK_ID = 137
const MUMBAI_NETWORK_ID = 80001
const SEPOLIA_NETWORK_ID = 11155111
const SAPPHIRE_TESTNET_NETWORK_ID = 23295
const SAPPHIRE_MAINNET_NETWORK_ID = 23294
export function setContractDefaults(contract: Contract, config: Config): Contract {
// TO DO - since ethers does not provide this
@ -142,8 +140,7 @@ export async function sendTx(
: chainId === SEPOLIA_NETWORK_ID &&
Number(aggressiveFeePriorityFeePerGas) < MIN_GAS_FEE_SEPOLIA
? MIN_GAS_FEE_SEPOLIA
: (chainId === SAPPHIRE_MAINNET_NETWORK_ID ||
chainId === SAPPHIRE_TESTNET_NETWORK_ID) &&
: KNOWN_CONFIDENTIAL_EVMS.includes(chainId) &&
Number(aggressiveFeePriorityFeePerGas) < MIN_GAS_FEE_SAPPHIRE
? MIN_GAS_FEE_SAPPHIRE
: Number(aggressiveFeePriorityFeePerGas),
@ -155,8 +152,7 @@ export async function sendTx(
: chainId === SEPOLIA_NETWORK_ID &&
Number(aggressiveFeePerGas) < MIN_GAS_FEE_SEPOLIA
? MIN_GAS_FEE_SEPOLIA
: (chainId === SAPPHIRE_MAINNET_NETWORK_ID ||
chainId === SAPPHIRE_TESTNET_NETWORK_ID) &&
: KNOWN_CONFIDENTIAL_EVMS.includes(chainId) &&
Number(aggressiveFeePerGas) < MIN_GAS_FEE_SAPPHIRE
? MIN_GAS_FEE_SAPPHIRE
: Number(aggressiveFeePerGas)

View File

@ -289,7 +289,11 @@ describe('Marketplace flow tests', async () => {
it('6.1 Publish a dataset (create NFT + Datatoken) with a fixed rate exchange', async () => {
/// ```Typescript
const factory = new NftFactory(addresses.ERC721Factory, publisherAccount)
const factory = new NftFactory(
addresses.ERC721Factory,
publisherAccount,
await publisherAccount.getChainId()
)
const nftParams: NftCreateData = {
name: FRE_NFT_NAME,
@ -409,7 +413,11 @@ describe('Marketplace flow tests', async () => {
it('6.3 Marketplace displays fixed rate asset for sale', async () => {
/// ```Typescript
const fixedRate = new FixedRateExchange(freAddress, publisherAccount)
const fixedRate = new FixedRateExchange(
freAddress,
publisherAccount,
await publisherAccount.getChainId()
)
const oceanAmount = await (
await fixedRate.calcBaseInGivenDatatokensOut(freId, '1')
).baseTokenAmount
@ -424,7 +432,7 @@ describe('Marketplace flow tests', async () => {
it('7.1 Consumer buys a fixed rate asset data asset, and downloads it', async () => {
/// ```Typescript
datatoken = new Datatoken(publisherAccount)
datatoken = new Datatoken(publisherAccount, await publisherAccount.getChainId())
const DATATOKEN_AMOUNT = '10000'
await datatoken.mint(
@ -473,7 +481,11 @@ describe('Marketplace flow tests', async () => {
DATATOKEN_AMOUNT
)
const fixedRate = new FixedRateExchange(freAddress, consumerAccount)
const fixedRate = new FixedRateExchange(
freAddress,
consumerAccount,
await consumerAccount.getChainId()
)
/// ```
/// Now we can make the contract call
/// ```Typescript
@ -517,7 +529,7 @@ describe('Marketplace flow tests', async () => {
validUntil: initializeData.providerFee.validUntil
}
datatoken = new Datatoken(consumerAccount)
datatoken = new Datatoken(consumerAccount, await consumerAccount.getChainId())
/// ```
/// Lets now make the payment
@ -574,7 +586,11 @@ describe('Marketplace flow tests', async () => {
it('8.1 Publish a dataset (create NFT + Datatoken) with a dispenser', async () => {
/// ```Typescript
const factory = new NftFactory(addresses.ERC721Factory, publisherAccount)
const factory = new NftFactory(
addresses.ERC721Factory,
publisherAccount,
await publisherAccount.getChainId()
)
const nftParams: NftCreateData = {
name: DISP_NFT_NAME,
@ -679,8 +695,12 @@ describe('Marketplace flow tests', async () => {
it('9.1 Consumer gets a dispenser data asset, and downloads it', async () => {
/// ```Typescript
datatoken = new Datatoken(publisherAccount)
const dispenser = new Dispenser(addresses.Dispenser, consumerAccount)
datatoken = new Datatoken(publisherAccount, await publisherAccount.getChainId())
const dispenser = new Dispenser(
addresses.Dispenser,
consumerAccount,
await consumerAccount.getChainId()
)
let consumerDTBalance = await balance(
consumerAccount,
@ -709,7 +729,7 @@ describe('Marketplace flow tests', async () => {
const resolvedDDO = await aquarius.waitForAqua(fixedDDO.id)
assert(resolvedDDO, 'Cannot fetch DDO from Aquarius')
datatoken = new Datatoken(consumerAccount)
datatoken = new Datatoken(consumerAccount, await consumerAccount.getChainId())
/// ```
/// At this point we need to encrypt file(s) using provider
@ -791,7 +811,7 @@ describe('Marketplace flow tests', async () => {
it('10.1 Add key-value pair to data NFT', async () => {
/// Let's start by using the `setData` method to update the nft key value store with some data
/// ```Typescript
const nft = new Nft(publisherAccount)
const nft = new Nft(publisherAccount, await publisherAccount.getChainId())
const data = 'SomeData'
try {
await nft.setData(

View File

@ -293,7 +293,11 @@ async function createAsset(
) {
const nft = new Nft(owner, (await owner.provider.getNetwork()).chainId)
const nftFactory = new NftFactory(addresses.ERC721Factory, owner)
const nftFactory = new NftFactory(
addresses.ERC721Factory,
owner,
await owner.getChainId()
)
const chain = (await owner.provider.getNetwork()).chainId

View File

@ -94,8 +94,12 @@ describe('Publish tests', async () => {
})
it('initialize test classes', async () => {
nft = new Nft(publisherAccount)
factory = new NftFactory(addresses.ERC721Factory, publisherAccount)
nft = new Nft(publisherAccount, await publisherAccount.getChainId())
factory = new NftFactory(
addresses.ERC721Factory,
publisherAccount,
await publisherAccount.getChainId()
)
await approve(
publisherAccount,

View File

@ -56,6 +56,7 @@ describe('Sapphire tests', async () => {
]
const config: Config = {
sdk: 'oasis',
chainId: 23295,
network: 'oasis_sapphire_testnet',
nodeUri: 'https://testnet.sapphire.oasis.dev',

View File

@ -55,7 +55,8 @@ export async function createAsset(
const bundleNFT = await nftFactory.createNftWithDatatoken(
nftParamsAsset,
datatokenParams
datatokenParams,
false
)
const trxReceipt = await bundleNFT.wait()

View File

@ -1,7 +1,7 @@
import { assert } from 'chai'
import { KNOWN_CONFIDENTIAL_EVMS } from '../../src/config'
import { provider, getAddresses } from '../config'
import { calculateActiveTemplateIndex, isConfidentialEVM } from '../../src/utils'
import { calculateActiveTemplateIndex, useOasisSDK } from '../../src/utils'
import { Signer } from 'ethers/lib/ethers'
let nftOwner: Signer
@ -14,16 +14,13 @@ describe('Asset utils (createAsset)', () => {
it('should check if confidential EVM', async () => {
for (const chain of KNOWN_CONFIDENTIAL_EVMS) {
assert(
isConfidentialEVM(chain) === true,
`Chain Id: "${chain}" is not a confidental EVM`
)
assert(useOasisSDK(chain) === true, `Chain Id: "${chain}" is not a confidental EVM`)
}
// optimism sepolia
// 11155420
assert(
isConfidentialEVM(11155420) === false,
useOasisSDK(11155420) === false,
`Chain Id: "11155420" is wrongly considered a confidental EVM`
)
})

View File

@ -58,12 +58,20 @@ describe('Dispenser flow', () => {
})
it('should initialize Dispenser class', async () => {
DispenserClass = new Dispenser(addresses.Dispenser, factoryOwner)
DispenserClass = new Dispenser(
addresses.Dispenser,
factoryOwner,
await factoryOwner.getChainId()
)
assert(DispenserClass !== null)
})
it('#createNftwithErc - should create an NFT and a Datatoken ', async () => {
nftFactory = new NftFactory(addresses.ERC721Factory, factoryOwner)
nftFactory = new NftFactory(
addresses.ERC721Factory,
factoryOwner,
await factoryOwner.getChainId()
)
const tx = await nftFactory.createNftWithDatatoken(nftData, dtParams)
const trxReceipt = await tx.wait()
@ -76,7 +84,7 @@ describe('Dispenser flow', () => {
})
it('Make user2 minter', async () => {
datatoken = new Datatoken(factoryOwner)
datatoken = new Datatoken(factoryOwner, await factoryOwner.getChainId())
await datatoken.addMinter(
dtAddress,
await factoryOwner.getAddress(),
@ -144,7 +152,11 @@ describe('Dispenser flow', () => {
'1'
)
assert(check === true, 'isDispensable should return true')
const DispenserClassForUser2 = new Dispenser(addresses.Dispenser, user2)
const DispenserClassForUser2 = new Dispenser(
addresses.Dispenser,
user2,
await user2.getChainId()
)
const tx = await DispenserClassForUser2.dispense(
dtAddress,
'1',

View File

@ -69,7 +69,11 @@ describe('Fixed Rate unit test', () => {
// CREATE AN Exchange
// we prepare transaction parameters objects
const nftFactory = new NftFactory(addresses.ERC721Factory, exchangeOwner)
const nftFactory = new NftFactory(
addresses.ERC721Factory,
exchangeOwner,
await exchangeOwner.getChainId()
)
const freParams: FreCreationParams = {
fixedRateAddress: addresses.FixedPrice,
@ -99,7 +103,11 @@ describe('Fixed Rate unit test', () => {
// user1 has no dt1
expect(await balance(user1, dtAddress, await user1.getAddress())).to.equal('0.0')
fixedRate = new FixedRateExchange(addresses.FixedPrice, exchangeOwner)
fixedRate = new FixedRateExchange(
addresses.FixedPrice,
exchangeOwner,
await exchangeOwner.getChainId()
)
assert(fixedRate != null)
})
@ -197,7 +205,7 @@ describe('Fixed Rate unit test', () => {
it('#buyDatatokens - user1 should buy some dt', async () => {
// total supply is ZERO right now so dt owner mints 1000 DT and approves the fixed rate contract
const datatoken = new Datatoken(exchangeOwner)
const datatoken = new Datatoken(exchangeOwner, await exchangeOwner.getChainId())
await datatoken.mint(
dtAddress,
await exchangeOwner.getAddress(),
@ -238,7 +246,11 @@ describe('Fixed Rate unit test', () => {
)
// user1 buys 10 DT
fixedRate = new FixedRateExchange(addresses.FixedPrice, user1)
fixedRate = new FixedRateExchange(
addresses.FixedPrice,
user1,
await user1.getChainId()
)
const amount = '10'
const maxAmount = '11'
const tx = await fixedRate.buyDatatokens(exchangeId, amount, maxAmount)
@ -352,7 +364,11 @@ describe('Fixed Rate unit test', () => {
})
it('#setAllowedSwapper- should set an allowed swapper, if exchangeOwner', async () => {
fixedRate = new FixedRateExchange(addresses.FixedPrice, exchangeOwner)
fixedRate = new FixedRateExchange(
addresses.FixedPrice,
exchangeOwner,
await exchangeOwner.getChainId()
)
await fixedRate.setAllowedSwapper(exchangeId, await user1.getAddress())
expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(
await user1.getAddress()
@ -365,7 +381,11 @@ describe('Fixed Rate unit test', () => {
})
it('#collectBasetokens- should collect BT in the contract, if exchangeOwner', async () => {
fixedRate = new FixedRateExchange(addresses.FixedPrice, user1)
fixedRate = new FixedRateExchange(
addresses.FixedPrice,
user1,
await user1.getChainId()
)
// there are no bt in the contract
expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0.0')
// user1 buys 1 DT
@ -380,7 +400,11 @@ describe('Fixed Rate unit test', () => {
})
it('#collectDatatokens- should collect DT in the contract, if exchangeOwner', async () => {
fixedRate = new FixedRateExchange(addresses.FixedPrice, exchangeOwner)
fixedRate = new FixedRateExchange(
addresses.FixedPrice,
exchangeOwner,
await exchangeOwner.getChainId()
)
const result = await fixedRate.getExchange(exchangeId)
// 9 dts left
expect(result.dtBalance).to.equal('9.0')
@ -395,7 +419,11 @@ describe('Fixed Rate unit test', () => {
})
it('#collectMarketFee- should collect marketFee and send it to marketFeeCollector, anyone can call it', async () => {
fixedRate = new FixedRateExchange(addresses.FixedPrice, user2)
fixedRate = new FixedRateExchange(
addresses.FixedPrice,
user2,
await user2.getChainId()
)
let result = await fixedRate.getFeesInfo(exchangeId)
// we made 2 swaps for 10 DT at rate 1, the fee is 0.1% for market and always in baseToken so it's 0.01 DAI
// plus another swap for 1 DT
@ -435,7 +463,11 @@ describe('Fixed Rate unit test', () => {
})
it('#updateMarketFee- should update Market fee if market fee collector', async () => {
fixedRate = new FixedRateExchange(addresses.FixedPrice, user2)
fixedRate = new FixedRateExchange(
addresses.FixedPrice,
user2,
await user2.getChainId()
)
expect((await fixedRate.getFeesInfo(exchangeId)).marketFee).to.equal('0.001')
// user2 is marketFeeCollector
await fixedRate.updateMarketFee(exchangeId, '0.01')
@ -444,7 +476,11 @@ describe('Fixed Rate unit test', () => {
})
it('#updateMarketFeeCollector - should update Market fee collector if market fee collector', async () => {
fixedRate = new FixedRateExchange(addresses.FixedPrice, user2)
fixedRate = new FixedRateExchange(
addresses.FixedPrice,
user2,
await user2.getChainId()
)
expect((await fixedRate.getFeesInfo(exchangeId)).marketFeeCollector).to.equal(
await user2.getAddress()
)
@ -463,7 +499,11 @@ describe('Fixed Rate unit test', () => {
// since FRE is created without mint rights, owner has to send dt to that exchange
// we prepare transaction parameters objects
const nftFactory = new NftFactory(addresses.ERC721Factory, exchangeOwner)
const nftFactory = new NftFactory(
addresses.ERC721Factory,
exchangeOwner,
await exchangeOwner.getChainId()
)
const freParams: FreCreationParams = {
fixedRateAddress: addresses.FixedPrice,
@ -493,7 +533,11 @@ describe('Fixed Rate unit test', () => {
// user1 has no dt1
expect(await balance(user1, dtAddress, await user1.getAddress())).to.equal('0.0')
fixedRate = new FixedRateExchange(addresses.FixedPrice, exchangeOwner)
fixedRate = new FixedRateExchange(
addresses.FixedPrice,
exchangeOwner,
await exchangeOwner.getChainId()
)
assert(fixedRate != null)
})
@ -587,7 +631,7 @@ describe('Fixed Rate unit test', () => {
it('#buyDatatokens - user1 should buy some dt', async () => {
// total supply is ZERO right now so dt owner mints 1000 DT and approves the fixed rate contract
const datatoken = new Datatoken(exchangeOwner)
const datatoken = new Datatoken(exchangeOwner, await exchangeOwner.getChainId())
await datatoken.mint(
dtAddress,
await exchangeOwner.getAddress(),
@ -620,7 +664,11 @@ describe('Fixed Rate unit test', () => {
)
// user1 buys 10 DT
fixedRate = new FixedRateExchange(addresses.FixedPrice, user1)
fixedRate = new FixedRateExchange(
addresses.FixedPrice,
user1,
await user1.getChainId()
)
const amount = '10'
const maxAmount = '11'
const tx = await fixedRate.buyDatatokens(exchangeId, amount, maxAmount)
@ -736,7 +784,11 @@ describe('Fixed Rate unit test', () => {
})
it('#setAllowedSwapper- should set an allowed swapper, if exchangeOwner', async () => {
fixedRate = new FixedRateExchange(addresses.FixedPrice, exchangeOwner)
fixedRate = new FixedRateExchange(
addresses.FixedPrice,
exchangeOwner,
await exchangeOwner.getChainId()
)
await fixedRate.setAllowedSwapper(exchangeId, await user1.getAddress())
expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(
@ -750,14 +802,22 @@ describe('Fixed Rate unit test', () => {
})
it('#collectBasetokens- should collect BT in the contract, if exchangeOwner', async () => {
fixedRate = new FixedRateExchange(addresses.FixedPrice, user1)
fixedRate = new FixedRateExchange(
addresses.FixedPrice,
user1,
await user1.getChainId()
)
// there are no bt in the contract
expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0.0')
// user1 buys 1 DT
await fixedRate.buyDatatokens(exchangeId, '1', '2')
// 1 DAI in the contract
fixedRate = new FixedRateExchange(addresses.FixedPrice, exchangeOwner)
fixedRate = new FixedRateExchange(
addresses.FixedPrice,
exchangeOwner,
await exchangeOwner.getChainId()
)
const exchangeDetails = await fixedRate.getExchange(exchangeId)
expect(exchangeDetails.btBalance).to.equal('1.0')
@ -781,7 +841,11 @@ describe('Fixed Rate unit test', () => {
})
it('#updateMarketFee- should update Market fee if market fee collector', async () => {
fixedRate = new FixedRateExchange(addresses.FixedPrice, user2)
fixedRate = new FixedRateExchange(
addresses.FixedPrice,
user2,
await user2.getChainId()
)
expect((await fixedRate.getFeesInfo(exchangeId)).marketFee).to.equal('0.001')
// user2 is marketFeeCollector
@ -808,7 +872,11 @@ describe('Fixed Rate unit test', () => {
// CREATE AN Exchange
// we prepare transaction parameters objects
const nftFactory = new NftFactory(addresses.ERC721Factory, exchangeOwner)
const nftFactory = new NftFactory(
addresses.ERC721Factory,
exchangeOwner,
await exchangeOwner.getChainId()
)
const freParams: FreCreationParams = {
fixedRateAddress: addresses.FixedPrice,
@ -836,7 +904,7 @@ describe('Fixed Rate unit test', () => {
const datatokenAddress = tokenCreatedEvent.args.newTokenAddress
const datatoken = new Datatoken(exchangeOwner)
const datatoken = new Datatoken(exchangeOwner, await exchangeOwner.getChainId())
const publishingMarketFee = await datatoken.getPublishingMarketFee(datatokenAddress)
@ -850,7 +918,11 @@ describe('Fixed Rate unit test', () => {
// CREATE AN Exchange
// we prepare transaction parameters objects
const nftFactory = new NftFactory(addresses.ERC721Factory, exchangeOwner)
const nftFactory = new NftFactory(
addresses.ERC721Factory,
exchangeOwner,
await exchangeOwner.getChainId()
)
const freParams: FreCreationParams = {
fixedRateAddress: addresses.FixedPrice,
@ -878,7 +950,7 @@ describe('Fixed Rate unit test', () => {
const datatokenAddress = tokenCreatedEvent.args.newTokenAddress
const datatoken = new Datatoken(exchangeOwner)
const datatoken = new Datatoken(exchangeOwner, await exchangeOwner.getChainId())
const publishingMarketFee = await datatoken.getPublishingMarketFee(datatokenAddress)
assert(

View File

@ -66,7 +66,11 @@ describe('Nft Factory test', () => {
})
it('should initiate NFTFactory instance', async () => {
nftFactory = new NftFactory(addresses.ERC721Factory, nftOwner)
nftFactory = new NftFactory(
addresses.ERC721Factory,
nftOwner,
await nftOwner.getChainId()
)
})
it('#getOwner - should return actual owner', async () => {
@ -91,14 +95,14 @@ describe('Nft Factory test', () => {
nftAddress = await nftFactory.createNFT(nftData)
// we check the created nft
const nftDatatoken = new Nft(nftOwner)
const nftDatatoken = new Nft(nftOwner, await nftOwner.getChainId())
const tokenURI = await nftDatatoken.getTokenURI(nftAddress, 1)
assert(tokenURI === nftData.tokenURI)
})
it('#createNftwithErc - should create an NFT and a Datatoken', async () => {
// we prepare transaction parameters objects
const tx = await nftFactory.createNftWithDatatoken(nftData, dtParams)
const tx = await nftFactory.createNftWithDatatoken(nftData, dtParams, false)
const trxReceipt = await tx.wait()
const nftCreatedEvent = getEventFromTx(trxReceipt, 'NFTCreated')
const tokenCreatedEvent = getEventFromTx(trxReceipt, 'TokenCreated')
@ -114,7 +118,7 @@ describe('Nft Factory test', () => {
const currentNFTCount = await nftFactory.getCurrentNFTCount()
const currentTokenCount = await nftFactory.getCurrentTokenCount()
await nftFactory.createNftWithDatatoken(nftData, dtParams)
await nftFactory.createNftWithDatatoken(nftData, dtParams, false)
expect((await nftFactory.getCurrentNFTCount()) === currentNFTCount + 1)
expect((await nftFactory.getCurrentTokenCount()) === currentTokenCount + 1)
@ -187,14 +191,18 @@ describe('Nft Factory test', () => {
const consumeFeeAddress = user2 // marketplace fee Collector
const consumeFeeAmount = '0' // fee to be collected on top, requires approval
const consumeFeeToken = addresses.MockDAI // token address for the feeAmount, in this case DAI
nftFactory = new NftFactory(addresses.ERC721Factory, consumer)
nftFactory = new NftFactory(
addresses.ERC721Factory,
consumer,
await consumer.getChainId()
)
// we reuse a DT created in a previous test
expect(
parseInt(await balance(nftOwner, dtAddress, await user1.getAddress()))
).to.equal(0)
// dt owner mint DATA_TOKEN_AMOUNT to user1
const datatoken = new Datatoken(nftOwner)
const datatoken = new Datatoken(nftOwner, await nftOwner.getChainId())
datatoken.mint(
dtAddress,
await nftOwner.getAddress(),
@ -311,7 +319,11 @@ describe('Nft Factory test', () => {
it('#addNFTTemplate - should add a new NFT token template', async () => {
const currentNFTTemplateCount = await nftFactory.getCurrentNFTTemplateCount()
nftFactory = new NftFactory(addresses.ERC721Factory, factoryOwner)
nftFactory = new NftFactory(
addresses.ERC721Factory,
factoryOwner,
await factoryOwner.getChainId()
)
await nftFactory.addNFTTemplate(
await factoryOwner.getAddress(),
addresses.ERC721Template['1']
@ -324,7 +336,11 @@ describe('Nft Factory test', () => {
it('#disableNFTTemplate - should disable an NFT token template', async () => {
const currentNFTTemplateCount = await nftFactory.getCurrentNFTTemplateCount()
nftFactory = new NftFactory(addresses.ERC721Factory, factoryOwner)
nftFactory = new NftFactory(
addresses.ERC721Factory,
factoryOwner,
await factoryOwner.getChainId()
)
let nftTemplate = await nftFactory.getNFTTemplate(currentNFTTemplateCount)
assert(nftTemplate.isActive === true)
@ -339,7 +355,11 @@ describe('Nft Factory test', () => {
it('#reactivateNFTTemplate - should reactivate an NFT previously disabled token template', async () => {
const currentNFTTemplateCount = await nftFactory.getCurrentNFTTemplateCount()
nftFactory = new NftFactory(addresses.ERC721Factory, factoryOwner)
nftFactory = new NftFactory(
addresses.ERC721Factory,
factoryOwner,
await factoryOwner.getChainId()
)
let nftTemplate = await nftFactory.getNFTTemplate(currentNFTTemplateCount)
assert(nftTemplate.isActive === false)

View File

@ -82,7 +82,7 @@ describe('Router unit test', () => {
})
it('should initiate Router instance', async () => {
router = new Router(addresses.Router, user1)
router = new Router(addresses.Router, user1, await user1.getChainId())
})
it('#getOwner - should return actual owner', async () => {
@ -107,7 +107,7 @@ describe('Router unit test', () => {
it('#buyDatatokenBatch - should buy multiple DT in one call', async () => {
// APPROVE DAI
const daiContract = new Datatoken(factoryOwner)
const daiContract = new Datatoken(factoryOwner, await factoryOwner.getChainId())
await daiContract.transfer(addresses.MockDAI, await user1.getAddress(), DAI_AMOUNT)
await approve(
@ -133,7 +133,11 @@ describe('Router unit test', () => {
withMint: true
}
const nftFactory = new NftFactory(addresses.ERC721Factory, factoryOwner)
const nftFactory = new NftFactory(
addresses.ERC721Factory,
factoryOwner,
await factoryOwner.getChainId()
)
const tx = await nftFactory.createNftWithDatatokenWithFixedRate(
NFT_DATA,
ERC_PARAMS,
@ -152,7 +156,7 @@ describe('Router unit test', () => {
const freId1 = NewFixedRateEvent.args.exchangeId
const datatoken = new Datatoken(factoryOwner)
const datatoken = new Datatoken(factoryOwner, await factoryOwner.getChainId())
await datatoken.mint(
datatokenAddress,
await factoryOwner.getAddress(),