Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use createAsset function from SDK. #73

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

mariacarmina
Copy link
Member

@mariacarmina mariacarmina commented Nov 7, 2024

Fixes # .

Changes proposed in this PR:

  • use createAsset function from SDK
  • replace all hardcoded chain IDs value with null, because the chain ID will be automatically & correctly filled in by SDK

@paulo-ocean paulo-ocean mentioned this pull request Nov 11, 2024
@mariacarmina mariacarmina marked this pull request as draft November 18, 2024 13:21

// Create Allow List
allowListAddress = await accessListFactory.deployAccessListContract(
await accessListFactoryObj.deployAccessListContract(
Copy link
Contributor

@paulo-ocean paulo-ocean Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we sure about these params?
config.accessListFactory
allowAccessList
denyAccessList
if they do not match probably there will be errors at smart contract level (not sure if console.log will help if the issue is on those)
btw, there is a function to deploy the access list on the SDK as well
export async function createAccessListFactory(
we could probably just use that one instead

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I double-checked, I put them in place to match createAsset from ocean.js

Copy link
Contributor

@paulo-ocean paulo-ocean Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its not about the order of the params:
accessListFactoryObj, allowAccessList and denyAccessList should be contract addresses (strings)

Here, you're creating a new access list factory and a new access list deployed from that factory

// Create Access List Factory
		const accessListFactoryObj = new AccesslistFactory(config.accessListFactory, wrappedSigner, chainId);

		// Create Allow List
		await accessListFactoryObj.deployAccessListContract(
			'AllowList',
			'ALLOW',
			['https://oceanprotocol.com/nft/'],
			false,
			await owner.getAddress(),
			[await owner.getAddress(), ZERO_ADDRESS]
		)
		return await createAsset(name, symbol, wrappedSigner, assetUrl, templateIndex, ddo, encryptDDO, providerUrl || macOsProviderUrl, providerFeeToken, aquariusInstance, accessListFactory, allowAccessList, denyAccessList)

But you're calling the function with other values, the factory addresses and the allow access list addresses do not match (you're creating new ones and passing something else)
In fact this code is not doing anything.. you can probably delete most of it
cause you're passing the values received on the function (which are not defined btw)

src/helpers.ts Outdated
const nftFactory = new NftFactory(config.nftFactoryAddress, owner);

let wrappedSigner
let allowListAddress
if(templateIndex === 4){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be the template id or the template address...
template index is something else (and must be calculated on SDK side)
might work, but is not exactly the same

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name is misleading, it should be template id, correct, I'll update this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this still needs to be updated

@paulo-ocean
Copy link
Contributor

paulo-ocean commented Nov 19, 2024

btw, just published an asset on ganache from this branch... all good on my side

> [email protected] cli
> TS_NODE_PROJECT='./tsconfig.json' ./node_modules/ts-node/dist/bin.js src/index.ts publish metadata/simpleDownloadDataset.json

Using RPC: http://127.0.0.1:8545
Using account: 0x6c957a45C801035d3297d43d0Ce83a237Ec5E0d1
Using Provider : http://localhost:8001
Using Aquarius : http://localhost:8001
start publishing
No config found for given network 'undefined'
No config found for given network 'undefined'
did:  did:op:fadce5db248397ccccc43d4ea36a727ef000c0d4c5dd0e45d0f430c9d1cf2432
Asset published. ID:  did:op:fadce5db248397ccccc43d4ea36a727ef000c0d4c5dd0e45d0f430c9d1cf2432
paulo@paulo-VivoBook-ASUSLaptop-X515EA-F515EA:~/workspace/OCEAN/ocean-cli$ npm run cli getDDO did:op:fadce5db248397ccccc43d4ea36a727ef000c0d4c5dd0e45d0f430c9d1cf2432 

> [email protected] cli
> TS_NODE_PROJECT='./tsconfig.json' ./node_modules/ts-node/dist/bin.js src/index.ts getDDO did:op:fadce5db248397ccccc43d4ea36a727ef000c0d4c5dd0e45d0f430c9d1cf2432

Using RPC: http://127.0.0.1:8545
Using account: 0x6c957a45C801035d3297d43d0Ce83a237Ec5E0d1
Using Provider : http://localhost:8001
Using Aquarius : http://localhost:8001
Resolving Asset with DID: did:op:fadce5db248397ccccc43d4ea36a727ef000c0d4c5dd0e45d0f430c9d1cf2432
{
  '@context': [ 'https://w3id.org/did/v1' ],
  id: 'did:op:fadce5db248397ccccc43d4ea36a727ef000c0d4c5dd0e45d0f430c9d1cf2432',
  nftAddress: '0x53d1456E80AE480E6C38b7d057EdAddB53D8583f',
  version: '4.1.0',
  chainId: 8996,
  metadata: {
    created: '2021-12-20T14:35:20Z',
    updated: '2021-12-20T14:35:20Z',
    type: 'dataset',
    name: 'ocean-cli demo asset',
    description: 'asset published using ocean cli tool',
    tags: [ 'test' ],
    author: 'oceanprotocol',
    license: 'https://market.oceanprotocol.com/terms',
    additionalInformation: { termsAndConditions: true }
  },
  services: [
    {
      id: 'ccb398c50d6abd5b456e8d7242bd856a1767a890b537c2f8c10ba8b8a10e6025',
      type: 'access',
      files: '0x040000f7cdc53f2ca20b4e407bedb5a345cd54f1ccd4541f6008821a7d9831d96793d2115db8c252d5652ccba9af1363b2e6bd5a48480ac72e6645015ef34b77ad84006c82a889e2b78263602f7f6c514d1a0062e5d9ad8efd704ea046c14136ef7521e08b74f7c0ef9bf5a31ec03efa9ce6b6863ae1607de6f00304cefd170f80c14a86adf1a65ae1737bf993a0a41d4d7da793bdad66732977ae3bb27d0bdc50b495498bd367d6dcc0de3988c771957cd63cf1e82b59ba0800aefebc78fac394d828121fab0c0afb8e1e6b82b1c163caa56725bd0816f5f2d0bf8d8b8e9ecc5a12e4b6440bb5fcba5fa07efd1b5afdc1272bb7de6a37969479ee377c8adbb15cf8a28d781f1440e72a77607d751cc44490c8809c690666c99c1c3d2ffeaf3122a4a473b730b65604823234279cca31fd2316b79bafa27056d3d0e71b759e52c79681781b0f306ec3b23b93299882e23e5005553033816093e1ab85e7af',
      datatokenAddress: '0x0c6aEB6238BAB5FB328Aca29dc7B8b2dBEc49768',
      serviceEndpoint: 'http://localhost:8001',
      timeout: 86400
    }
  ],
  event: {
    tx: '0xd7c4eeb718767c75da379d7cdbb884dd28412e5ba1b3ffacb567203f985e7082',
    from: '0x6c957a45C801035d3297d43d0Ce83a237Ec5E0d1',
    contract: '0x53d1456E80AE480E6C38b7d057EdAddB53D8583f',
    block: 1061,
    datetime: '2024-11-19T14:45:53.000Z'
  },
  nft: {
    state: 0,
    address: '0x53d1456E80AE480E6C38b7d057EdAddB53D8583f',
    name: 'Ocean Data NFT',
    symbol: 'OCEAN-NFT',
    owner: '0x6c957a45C801035d3297d43d0Ce83a237Ec5E0d1',
    created: '2024-11-19T14:45:53Z',
    tokenURI: 'aaa'
  },
  purgatory: { state: false },
  datatokens: [
    {
      address: '0x0c6aEB6238BAB5FB328Aca29dc7B8b2dBEc49768',
      name: 'Datatoken',
      symbol: 'DT1',
      serviceId: 'ccb398c50d6abd5b456e8d7242bd856a1767a890b537c2f8c10ba8b8a10e6025'
    }
  ],
  stats: { allocated: 0, orders: 0, price: { value: '2' } }
}

@paulo-ocean
Copy link
Contributor

paulo-ocean commented Nov 19, 2024

@mariacarmina Check the chain id on the tests.
I think you're victim of you own code :-)
https://github.com/oceanprotocol/ocean.js/blob/6e0d0e85a656850b3d2d1899244269be733652ce/src/utils/Assets.ts#L157
The test fails because the chain id of simpleComputeDataset.json is not the expected one.. That's why i was against these "check chain" changes, its easy to get confusing...

better also use a try/catch on the caller side... so we know whats happening (as we throw errors)

@mariacarmina
Copy link
Member Author

@mariacarmina Check the chain id on the tests. I think you're victim of you own code :-) https://github.com/oceanprotocol/ocean.js/blob/6e0d0e85a656850b3d2d1899244269be733652ce/src/utils/Assets.ts#L157 The test fails because the chain id of simpleComputeDataset.json is not the expected one.. That's why i was against these "check chain" changes, its easy to get confusing...

better also use a try/catch on the caller side... so we know whats happening (as we throw errors)

Hello @paulo-ocean, if you tested on barge, the chain id from simpleComputeDataset.json is set correctly, maybe the issue was on simpleDownloadDataset.json which is the mumbai chain id, I updated in the code the chain id to see if the tests pass.
Btw, when you did the test with successfully publsihed the ddo, did you also update the chain id in the sample before publishing?

@mariacarmina
Copy link
Member Author

better also use a try/catch on the caller side... so we know whats happening (as we throw errors)

I've seen that within the commands and publish.ts file there are try/catch blocks and they print the errors when they are raised, one spot was missing when publishing the algo, I've added right now, is there any other place that you were referring to?

@mariacarmina
Copy link
Member Author

@mariacarmina Check the chain id on the tests. I think you're victim of you own code :-) https://github.com/oceanprotocol/ocean.js/blob/6e0d0e85a656850b3d2d1899244269be733652ce/src/utils/Assets.ts#L157 The test fails because the chain id of simpleComputeDataset.json is not the expected one.. That's why i was against these "check chain" changes, its easy to get confusing...
better also use a try/catch on the caller side... so we know whats happening (as we throw errors)

Hello @paulo-ocean, if you tested on barge, the chain id from simpleComputeDataset.json is set correctly, maybe the issue was on simpleDownloadDataset.json which is the mumbai chain id, I updated in the code the chain id to see if the tests pass. Btw, when you did the test with successfully publsihed the ddo, did you also update the chain id in the sample before publishing?

The test are still failing can you share how did you receive the chain id error? the tests from CI indicate another type of error.

@mariacarmina
Copy link
Member Author

@paulo-ocean I have updated the chain ids, now it helped to advance the tests suite, PR to fix the check on ocean.js is merged, I think we need to do a minor release for ocean.js. Thank you!

@mariacarmina mariacarmina marked this pull request as ready for review November 20, 2024 13:36
@paulo-ocean
Copy link
Contributor

simpleDownloadDataset

Yes, the wrong one was simpleDownloadDataset

@paulo-ocean
Copy link
Contributor

The test are still failing can you share how did you receive the chain id error? the tests from CI indicate another type of error.

We don't get any errors when we code like "throw new Error()" and don't use try/catch :-)

Copy link
Contributor

@paulo-ocean paulo-ocean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm still not sure this is enough..
the template id = 4 could be used on any other network..

if(templateId === 4){
		// Wrap the signer for Sapphire
		const wrappedSigner = sapphire.wrap(owner);

We're assuming that every time we have template 4 is sapphire network wich might not always be true (i have no idea of what happens if we wrap the signer for any other network using sapphire SDK)

@mariacarmina
Copy link
Member Author

mariacarmina commented Nov 25, 2024

i'm still not sure this is enough.. the template id = 4 could be used on any other network..

if(templateId === 4){
		// Wrap the signer for Sapphire
		const wrappedSigner = sapphire.wrap(owner);

We're assuming that every time we have template 4 is sapphire network wich might not always be true (i have no idea of what happens if we wrap the signer for any other network using sapphire SDK)

Right, we also need to check the sdk part, I'm fixing it right now.

this.config,
this.aquarius,
encryptDDO
);
Copy link
Contributor

@paulo-ocean paulo-ocean Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is still not OK, we are not able to properly publish to oasis shappire for instance (it publishes but with wrong template and we will not be able to download the asset)...
as we're always assuming template 1, as we don't pass template id or template address

@@ -44,13 +44,7 @@ export async function publishAsset(params: PublishAssetParams, signer: Signer, c
license: 'MIT',
tags: params.tags
},
stats: {
Copy link
Contributor

@paulo-ocean paulo-ocean Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we turned back the Asset into a DDO, removing the stats..
but by removing this lines:

price: {
          value: params.isCharged ? params.price : "0"
        }

we now have a FixedPrice datatoken instead of Dispenser one
We totally changed the behavior of the previous function
Before it was doing:
bundleNFT = await nftFactory.createNftWithDatatokenWithDispenser(
Now it does always
bundleNFT = await nftFactory.createNftWithDatatokenWithFixedRate(

These changes + the default template of 1 ... breaks download of the asset (on SDK OrderUtils) at least for oasis shappire
you can check the previous version of createAsset here:

export async function createAsset(

and then compare with the SDK one:
https://github.com/oceanprotocol/ocean.js/blob/4437713b2243a87ae1a01730196abc27c872ac24/src/utils/Assets.ts#L46
To make sure we're passing all the relevant/needed parameters
specially the templateIDorAddress and the stats fields are very important

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants