Skip to content

Commit

Permalink
Merge pull request #727 from nevermined-io/feat/burn_batch
Browse files Browse the repository at this point in the history
feat: burn batch (requires contracts v3.5.9)
  • Loading branch information
aaitor authored Nov 15, 2024
2 parents 8824594 + aba110c commit 6c6d9f9
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 3 deletions.
18 changes: 17 additions & 1 deletion integration/nevermined/Credits.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ describe('Credit Subscriptions using NFT ERC-1155 End-to-End', () => {
console.log(`Running first test`)
// Deploy NFT
TestContractHandler.setConfig(config)
const networkName = await nevermined.keeper.getNetworkName()

const contractABI = await TestContractHandler.getABIArtifact(
'NFT1155SubscriptionUpgradeable',
'./test/resources/artifacts/',
config.artifactsFolder,
networkName,
)
subscriptionNFT = await SubscriptionCreditsNFTApi.deployInstance(
config,
Expand Down Expand Up @@ -393,5 +395,19 @@ describe('Credit Subscriptions using NFT ERC-1155 End-to-End', () => {
console.log(`Balance After TopUp: ${balanceAfterTopUp}`)
assert.isTrue(balanceAfterTopUp > accessCostInCredits)
})

it('Should be able to burn in batch', async () => {
const beforeBalance = await subscriptionNFT.balance(subscriptionDDO.id, subscriber.getId())

await nevermined.nfts1155.burnBatchFromHolders(
[subscriber.getId(), subscriber.getId()],
[subscriptionDDO.id, subscriptionDDO.id],
[1n, 2n],
editor,
)

const afterBalance = await subscriptionNFT.balance(subscriptionDDO.id, subscriber.getId())
assert.equal(beforeBalance - 3n, afterBalance)
})
})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nevermined-io/sdk",
"version": "3.0.41",
"version": "3.0.42",
"description": "Javascript SDK for connecting with Nevermined Data Platform ",
"main": "./dist/node/sdk.js",
"typings": "./dist/node/sdk.d.ts",
Expand Down
22 changes: 22 additions & 0 deletions src/keeper/contracts/Nft1155Contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,28 @@ export class Nft1155Contract extends NFTContractsBase {
return this.send('burn', from, [holder, didToTokenId(tokenId), BigInt(amount)], txParams)
}

/**
* It burns some editions of a NFT (ERC-1155)
*
* @param holders - Array of addresses of the accounts holding the NFT editions that are going to be burned
* @param tokenIds - Array of the NFT ids to burn
* @param amounts - Array of number of editions to burn
* @param from - Account burning the NFT editions
* @param txParams - Transaction additional parameters
* @returns Contract Receipt
*/
public async burnBatchFromHolders(
holders: string[],
tokenIds: string[],
amounts: bigint[],
from: NvmAccount,
txParams?: TxParameters,
) {
const _tokenIds = tokenIds.map((did) => didToTokenId(did))
const _amounts = amounts.map((amount) => BigInt(amount))
return this.send('burnBatchFromHolders', from, [holders, _tokenIds, _amounts], txParams)
}

/**
* It returns the NFT metadata uri
*
Expand Down
36 changes: 35 additions & 1 deletion src/nevermined/api/nfts/NFT1155Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class NFT1155Api extends NFTsBaseApi {
*
* @example
* ```ts
* await nevermined.nfts1155.burnTo(
* await nevermined.nfts1155.burnFromHolder(
* holder,
* tokenId,
* 2n,
Expand All @@ -224,6 +224,40 @@ export class NFT1155Api extends NFTsBaseApi {
return await this.nftContract.burnFromHolder(holder, tokenId, nftAmount, from, txParams)
}

/**
* Burns NFTs associated with an asset of a specific account.
*
* @remarks
* The publisher can only burn NFTs of an account if is an operator. NFTs that were already transferred cannot be burned by the publisher.
*
* @example
* ```ts
* await nevermined.nfts1155.burnBatchFromHolders(
* [holder1, holder2],
* [tokenId, tokenId],
* [2n, 3n],
* burner
* )
* ```
*
* @param holders - Array of addresses of the accounts holding the NFT editions that are going to be burned
* @param tokenIds - Array of the NFT ids to burn
* @param amounts - Array of number of editions to burn
* @param from - The account of the publisher of the NFT.
* @param txParams - Optional transaction parameters.
*
* @returns The {@link TransactionReceipt}
*/
public async burnBatchFromHolders(
holders: string[],
tokenIds: string[],
amounts: bigint[],
from: NvmAccount,
txParams?: TxParameters,
) {
return this.nftContract.burnBatchFromHolders(holders, tokenIds, amounts, from, txParams)
}

// TODO: We need to improve this to allow for secondary market sales
// Right now it fetches the rewards from the DDO which don't change.

Expand Down

0 comments on commit 6c6d9f9

Please sign in to comment.