Skip to content

Commit

Permalink
Merge pull request #201 from nevermined-io/feature/create_and_mint
Browse files Browse the repository at this point in the history
Allows to register a NFT and mint the ERC-1155 based NFT attached to it
  • Loading branch information
aaitor authored Dec 19, 2021
2 parents 623e240 + 9bc0cc2 commit ed45e37
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 33 deletions.
54 changes: 45 additions & 9 deletions contracts/registry/DIDRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ contract DIDRegistry is DIDFactory {
* @param _url refers to the url resolving the DID into a DID Document (DDO), limited to 2048 bytes.
* @param _cap refers to the mint cap
* @param _royalties refers to the royalties to reward to the DID creator in the secondary market
* @param _mint if true it mints the ERC-1155 NFTs attached to the asset
* @param _activityId refers to activity
* @param _attributes refers to the provenance attributes
* @return size refers to the size of the registry after the register action.
Expand All @@ -69,6 +70,7 @@ contract DIDRegistry is DIDFactory {
string memory _url,
uint256 _cap,
uint8 _royalties,
bool _mint,
bytes32 _activityId,
string memory _attributes
)
Expand All @@ -78,12 +80,46 @@ contract DIDRegistry is DIDFactory {
{
uint result = registerDID(_didSeed, _checksum, _providers, _url, _activityId, _attributes);
enableAndMintDidNft(
hashDID(_didSeed, msg.sender),
_cap,
_royalties,
false
hashDID(_didSeed, msg.sender),
_cap,
_royalties,
_mint
);
return result;
}

/**
* @notice Register a Mintable DID.
*
* @dev The first attribute of a DID registered sets the DID owner.
* Subsequent updates record _checksum and update info.
*
* @param _didSeed refers to decentralized identifier seed (a bytes32 length ID).
* @param _checksum includes a one-way HASH calculated using the DDO content.
* @param _providers list of addresses that can act as an asset provider
* @param _url refers to the url resolving the DID into a DID Document (DDO), limited to 2048 bytes.
* @param _cap refers to the mint cap
* @param _royalties refers to the royalties to reward to the DID creator in the secondary market
* @param _activityId refers to activity
* @param _attributes refers to the provenance attributes
* @return size refers to the size of the registry after the register action.
*/
function registerMintableDID(
bytes32 _didSeed,
bytes32 _checksum,
address[] memory _providers,
string memory _url,
uint256 _cap,
uint8 _royalties,
bytes32 _activityId,
string memory _attributes
)
public
onlyValidAttributes(_attributes)
returns (uint size)
{
return registerMintableDID(
_didSeed, _checksum, _providers, _url, _cap, _royalties, false, _activityId, _attributes);
}


Expand All @@ -97,21 +133,21 @@ contract DIDRegistry is DIDFactory {
* @param _did refers to decentralized identifier (a byte32 length ID)
* @param _cap refers to the mint cap
* @param _royalties refers to the royalties to reward to the DID creator in the secondary market
* @param _preMint if is true mint directly the amount capped tokens and lock in the _lockAddress
* @param _mint if is true mint directly the amount capped tokens and lock in the _lockAddress
*/
function enableAndMintDidNft(
bytes32 _did,
uint256 _cap,
uint8 _royalties,
bool _preMint
bool _mint
)
public
onlyDIDOwner(_did)
returns (bool success)
{
didRegisterList.initializeNftConfig(_did, _cap, _royalties);

if (_preMint) {
if (_mint) {
mint(_did, _cap);
}

Expand All @@ -123,15 +159,15 @@ contract DIDRegistry is DIDFactory {
function enableAndMintDidNft721(
bytes32 _did,
uint8 _royalties,
bool _preMint
bool _mint
)
public
onlyDIDOwner(_did)
returns (bool success)
{
didRegisterList.initializeNft721Config(_did, _royalties);

if (_preMint) {
if (_mint) {
mint721(_did);
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nevermined-io/contracts",
"version": "1.3.1",
"version": "1.3.2",
"description": "Nevermined implementation of Nevermined in Solidity",
"bugs": {
"url": "https://github.com/nevermined-io/contracts/issues"
Expand Down Expand Up @@ -147,4 +147,4 @@
"@gnosis.pm/safe-core-sdk": "^1.0.0",
"@gnosis.pm/safe-deployments": "^1.4.0"
}
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>io.keyko.nevermined</groupId>
<artifactId>contracts</artifactId>
<packaging>jar</packaging>
<version>1.3.1</version>
<version>1.3.2</version>
<name>Nevermined Contracts</name>
<description>Nevermined Data Platform Smart Contracts in Solidity</description>
<url>https://github.com/nevermined-io/contracts</url>
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/nevermined-io/contracts',
version='1.3.1',
version='1.3.2',
zip_safe=False,
)
10 changes: 5 additions & 5 deletions test/unit/conditions/NFT721LockCondition.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ contract('NFT721LockCondition', (accounts) => {

// register DID
await didRegistry.registerMintableDID(
didSeed, checksum, [], url, amount, 0, constants.activities.GENERATED, '')
didSeed, checksum, [], url, amount, 0, false, constants.activities.GENERATED, '')
await erc721.mint(did)
await erc721.approve(lockCondition.address, did)

Expand Down Expand Up @@ -119,7 +119,7 @@ contract('NFT721LockCondition', (accounts) => {

// register DID
await didRegistry.registerMintableDID(
didSeed, checksum, [], url, amount, 0, constants.activities.GENERATED, '')
didSeed, checksum, [], url, amount, 0, false, constants.activities.GENERATED, '')
await erc721.mint(did)
await erc721.approve(lockCondition.address, did)

Expand All @@ -138,7 +138,7 @@ contract('NFT721LockCondition', (accounts) => {

// register DID
await didRegistry.registerMintableDID(
didSeed, checksum, [], url, amount, 0, constants.activities.GENERATED, '')
didSeed, checksum, [], url, amount, 0, false, constants.activities.GENERATED, '')
await erc721.mint(did)
await erc721.approve(lockCondition.address, did)

Expand All @@ -164,7 +164,7 @@ contract('NFT721LockCondition', (accounts) => {

// register DID
await didRegistry.registerMintableDID(
didSeed, checksum, [], url, amount, 0, constants.activities.GENERATED, '')
didSeed, checksum, [], url, amount, 0, false, constants.activities.GENERATED, '')
await erc721.mint(did)
await erc721.approve(lockCondition.address, did)

Expand Down Expand Up @@ -202,7 +202,7 @@ contract('NFT721LockCondition', (accounts) => {

// register DID
await didRegistry.registerMintableDID(
didSeed, checksum, [], url, amount, 0, constants.activities.GENERATED, '')
didSeed, checksum, [], url, amount, 0, false, constants.activities.GENERATED, '')
await erc721.mint(did)
await erc721.approve(lockCondition.address, did)

Expand Down
4 changes: 2 additions & 2 deletions test/unit/conditions/NFTLockCondition.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ contract('NFTLockCondition', (accounts) => {

// register DID
await didRegistry.registerMintableDID(
didSeed, checksum, [], url, amount, 0, constants.activities.GENERATED, '')
await didRegistry.mint(did, amount)
didSeed, checksum, [], url, amount, 0, true, constants.activities.GENERATED, '')

await nft.setApprovalForAll(lockCondition.address, true)

await assert.isRejected(
Expand Down
4 changes: 2 additions & 2 deletions test/unit/conditions/rewards/EscrowPayment.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ contract('EscrowPaymentCondition contract', (accounts) => {

// register DID
await didRegistry.registerMintableDID(
didSeed, checksum, [], url, amounts[0], 0, constants.activities.GENERATED, '')
didSeed, checksum, [], url, amounts[0], 0, false, constants.activities.GENERATED, '')

const hashValuesLock = await lockPaymentCondition.hashValues(
did, escrowPayment.address, constants.address.zero, amounts, receivers)
Expand Down Expand Up @@ -349,7 +349,7 @@ contract('EscrowPaymentCondition contract', (accounts) => {

// register DID
await didRegistry.registerMintableDID(
didSeed, checksum, [], url, amounts[0], 0, constants.activities.GENERATED, '')
didSeed, checksum, [], url, amounts[0], 0, false, constants.activities.GENERATED, '')

const hashValuesLock = await lockPaymentCondition.hashValues(
did, escrowPayment.address, constants.address.zero, amounts, receivers)
Expand Down
14 changes: 3 additions & 11 deletions test/unit/registry/MintableDIDRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,10 @@ contract('Mintable DIDRegistry', (accounts) => {

await didRegistry.registerMintableDID(
didSeed, checksum, [], value, 20, 0, constants.activities.GENERATED, '', { from: owner })
await didRegistry.mint(did, 10, { from: owner })
/*
const result = await didRegistry.mint(did, 10, { from: owner })
testUtils.assertEmitted(
result,
1,
'TransferSingle'
) */
await didRegistry.mint(did, 20, { from: owner })

let balance = await nft.balanceOf(owner, did)
assert.strictEqual(10, balance.toNumber())
assert.strictEqual(20, balance.toNumber())

await didRegistry.burn(did, 5,
{
Expand All @@ -120,7 +113,7 @@ contract('Mintable DIDRegistry', (accounts) => {
)

balance = await nft.balanceOf(owner, did)
assert.strictEqual(5, balance.toNumber())
assert.strictEqual(15, balance.toNumber())
})

it('Should initialize the NFT in the registration', async () => {
Expand All @@ -129,7 +122,6 @@ contract('Mintable DIDRegistry', (accounts) => {
const checksum = testUtils.generateId()
await didRegistry.registerMintableDID(
didSeed, checksum, [], value, 10, 0, constants.activities.GENERATED, '', { from: owner })

await didRegistry.mint(did, 10, { from: owner })

const balance = await nft.balanceOf(owner, did)
Expand Down

0 comments on commit ed45e37

Please sign in to comment.