Skip to content

Commit

Permalink
Add mintNonFungible functions with token index support
Browse files Browse the repository at this point in the history
Signed-off-by: Enrique Lacal <enrique.lacal@kaleido.io>
  • Loading branch information
EnriqueL8 committed Nov 21, 2024
1 parent c0d7284 commit 4c7bed0
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/tokens/erc1155.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,43 @@ export const DynamicMethods: Record<TokenOperation, MethodSignature[]> = {
return undefined;
},
},
{
// Option with token index and single receiver
name: 'mintNonFungibleWithURI',
inputs: [{ type: 'uint256' }, { type: 'uint256' }, { type: 'address' }, { type: 'bytes' }, { type: 'string' }],
map: (poolLocator: PoolLocator, dto: TokenMint) => {
if (!poolLocator.isFungible) {
const amount = BigInt(dto.amount);
if (amount !== BigInt(1)) {
throw new BadRequestException('Amount for nonfungible tokens must be 1');
}
return [
computeTokenId(poolLocator),
dto.tokenIndex,
dto.to,
encodeHex(dto.data ?? ''),
dto.uri ?? '',
];
}
return undefined;
},
},
{
// Option with token index and single receiver
name: 'mintNonFungible',
inputs: [{ type: 'uint256' }, { type: 'uint256' }, { type: 'address' }, { type: 'bytes' }],
map: (poolLocator: PoolLocator, dto: TokenMint) => {
if (!poolLocator.isFungible) {
// In the case of a non-fungible token, we parse the value as a whole integer count of NFTs to mint
const amount = parseInt(dto.amount);
if (amount !== 1) {
throw new BadRequestException('Amount for nonfungible tokens must be 1');
}
return [computeTokenId(poolLocator), dto.tokenIndex, dto.to, encodeHex(dto.data ?? '')];
}
return undefined;
},
},
{
// Source: OpenZeppelin extension
name: 'mint',
Expand Down

0 comments on commit 4c7bed0

Please sign in to comment.