mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
use hardhat getContractAt
This commit is contained in:
parent
e855f787c5
commit
a049a1a488
2154
package-lock.json
generated
2154
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -53,11 +53,13 @@
|
|||||||
"web3": "^1.8.0"
|
"web3": "^1.8.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@nomiclabs/hardhat-ethers": "^2.2.3",
|
||||||
"@oceanprotocol/contracts": "^2.2.0",
|
"@oceanprotocol/contracts": "^2.2.0",
|
||||||
"cross-fetch": "^4.0.0",
|
"cross-fetch": "^4.0.0",
|
||||||
"crypto-js": "^4.1.1",
|
"crypto-js": "^4.1.1",
|
||||||
"decimal.js": "^10.4.1",
|
"decimal.js": "^10.4.1",
|
||||||
"ethers": "^5.7.2"
|
"ethers": "^5.7.2",
|
||||||
|
"hardhat": "^2.22.10"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@truffle/hdwallet-provider": "^2.0.14",
|
"@truffle/hdwallet-provider": "^2.0.14",
|
||||||
|
@ -18,6 +18,16 @@ import { FreCreationParams } from '../@types/FixedPrice'
|
|||||||
import { getEventFromTx } from './ContractUtils'
|
import { getEventFromTx } from './ContractUtils'
|
||||||
import { ProviderInstance } from '../services/Provider'
|
import { ProviderInstance } from '../services/Provider'
|
||||||
|
|
||||||
|
import { HardhatEthersHelpers } from '@nomiclabs/hardhat-ethers/types'
|
||||||
|
import { HardhatRuntimeEnvironment } from 'hardhat/types'
|
||||||
|
import hre from 'hardhat'
|
||||||
|
|
||||||
|
const hardhatEthers = hre as HardhatRuntimeEnvironment & { ethers: any } & {
|
||||||
|
ethers: typeof ethers & HardhatEthersHelpers
|
||||||
|
}
|
||||||
|
|
||||||
|
// import * as hre from 'hardhat'
|
||||||
|
|
||||||
export const DEVELOPMENT_CHAIN_ID = 8996
|
export const DEVELOPMENT_CHAIN_ID = 8996
|
||||||
// template address OR templateId
|
// template address OR templateId
|
||||||
export function isConfidentialEVM(network: string | number): boolean {
|
export function isConfidentialEVM(network: string | number): boolean {
|
||||||
@ -113,6 +123,38 @@ export async function calculateTemplateIndex(
|
|||||||
return null
|
return null
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
export async function calculateTemplateIndexV2(
|
||||||
|
owner: Signer,
|
||||||
|
nftContractAddress: string, // addresses.ERC721Factory,
|
||||||
|
template: string | number
|
||||||
|
): Promise<number> {
|
||||||
|
// is an ID number?
|
||||||
|
const isTemplateID = typeof template === 'number'
|
||||||
|
|
||||||
|
const factoryERC721 = new NftFactory(nftContractAddress, owner)
|
||||||
|
const currentTokenCount = await factoryERC721.getCurrentTokenTemplateCount()
|
||||||
|
for (let i = 1; i <= currentTokenCount; i++) {
|
||||||
|
const tokenTemplate = await factoryERC721.getTokenTemplate(i)
|
||||||
|
console.log('\n\n------------\ntemplateIndex:' + i)
|
||||||
|
console.log(tokenTemplate)
|
||||||
|
const erc20Template = await hardhatEthers.ethers.getContractAt(
|
||||||
|
'ERC20Template',
|
||||||
|
tokenTemplate.templateAddress
|
||||||
|
)
|
||||||
|
// check for ID
|
||||||
|
if (isTemplateID) {
|
||||||
|
const id = await erc20Template.connect(owner).getId()
|
||||||
|
console.log('templateId: ' + id)
|
||||||
|
if (tokenTemplate.isActive && id.toString() === template) {
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
} else if (tokenTemplate.isActive && tokenTemplate.templateAddress === template) {
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param name asset name
|
* @param name asset name
|
||||||
@ -159,6 +201,14 @@ export async function createAsset(
|
|||||||
const config = new ConfigHelper().getConfig(parseInt(String(chainID)))
|
const config = new ConfigHelper().getConfig(parseInt(String(chainID)))
|
||||||
|
|
||||||
let templateIndex = await calculateTemplateIndex(chainID, template)
|
let templateIndex = await calculateTemplateIndex(chainID, template)
|
||||||
|
|
||||||
|
const templateIndexV2 = await calculateTemplateIndexV2(
|
||||||
|
owner,
|
||||||
|
nftContractAddress,
|
||||||
|
template
|
||||||
|
)
|
||||||
|
console.log('first template index:', templateIndex)
|
||||||
|
console.log('last template index:', templateIndexV2)
|
||||||
if (templateIndex < 1) {
|
if (templateIndex < 1) {
|
||||||
// for testing purposes only
|
// for testing purposes only
|
||||||
if (chainID === DEVELOPMENT_CHAIN_ID) {
|
if (chainID === DEVELOPMENT_CHAIN_ID) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user