Skip to content

Instantly share code, notes, and snippets.

@monapasan
Created January 29, 2024 20:31
Show Gist options
  • Save monapasan/0442e2a34daf9369aba51eb87b8c935b to your computer and use it in GitHub Desktop.
Save monapasan/0442e2a34daf9369aba51eb87b8c935b to your computer and use it in GitHub Desktop.
export const deployWithSupply = async (item: Metadata): Promise<string> => {
console.log('🔗 Start deploying the following item: ', item.name);
const { maxFeePerGas, maxPriorityFeePerGas } =
await ethers.provider.getFeeData();
const CONTRACT_NAME = 'DMATLSP7';
const customToken = await ethers.getContractFactory(CONTRACT_NAME);
console.log(`🔗 Deploying contract (${item.name})...`);
let Token;
const symbol = "ROYAL"
const royaltiesData = [
['0x24871b3d', '0x77347c1ED3321A435Ae005E6197DdBCA3fBE84e7', 250],
['0x24871b3d', '0x4a8120323Fb10F5E5a3B1a8bDAFe6e48E871d0Fc', 250],
];
try {
Token = await customToken.deploy(
item.name,
symbol,
1,
item.totalSupply,
transformedRoyalties,
{
maxFeePerGas,
maxPriorityFeePerGas,
type: 2,
},
);
} catch (e) {
console.error(`🔗 Error when deploying ${item.name}`);
throw e;
}
const token = await Token.waitForDeployment();
const tokenAddress = await token.getAddress();
console.log(
`🔗 LSP7 Capped Token "${item.name}" deployed to: ${tokenAddress}`,
);
return tokenAddress;
};
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.9;
import '@lukso/lsp-smart-contracts/contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol';
import {LSP7CappedSupply} from '@lukso/lsp-smart-contracts/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol';
import {LSP7DigitalAssetCore} from '@lukso/lsp-smart-contracts/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol';
struct RoyaltyInfo {
bytes4 interfaceId;
address recipient;
uint32 points;
}
contract DMATLSP7 is LSP7Mintable, LSP7CappedSupply {
// Constants for LSP18Royalties
bytes32 constant LSP18RoyaltiesRecipients =
0xc0569ca6c9180acc2c3590f36330a36ae19015a19f4e85c28a7631e3317e6b9d;
bytes32 constant LSP18RoyaltiesEnforcePayment =
0x580d62ad353782eca17b89e5900e7df3b13b6f4ca9bbc2f8af8bceb0c3d1ecc6;
constructor(
string memory tokenName,
string memory tokenSymbol,
uint256 lsp4TokenType_,
uint256 tokenSupplyCap_,
RoyaltyInfo[] memory royalties
)
LSP7Mintable(tokenName, tokenSymbol, msg.sender, lsp4TokenType_, true)
LSP7CappedSupply(tokenSupplyCap_)
{
// Encode all royalties into a single bytes array
bytes memory royaltiesData = encodeRoyalties(royalties);
// Set the encoded royalties data using ERC725Y setData function
_setData(LSP18RoyaltiesRecipients, royaltiesData);
_setData(LSP18RoyaltiesEnforcePayment, abi.encode(true));
}
function _mint(
address to,
uint256 amount,
bool allowNonLSP1Recipient,
bytes memory data
) internal virtual override(LSP7DigitalAssetCore, LSP7CappedSupply) {
super._mint(to, amount, allowNonLSP1Recipient, data);
}
function encodeRoyalties(
RoyaltyInfo[] memory royalties
) internal pure returns (bytes memory) {
bytes memory royaltiesData = '';
for (uint i = 0; i < royalties.length; i++) {
// Encode each royalty entry
bytes memory encodedEntry = abi.encodePacked(
royalties[i].interfaceId,
royalties[i].recipient,
royalties[i].points
);
royaltiesData = abi.encodePacked(royaltiesData, encodedEntry);
}
return royaltiesData;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment