@paulstinchcombe/kami721c-sdk
Version:
SDK for interacting with KAMI721C NFT contracts
60 lines (59 loc) • 2.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const ethers_1 = require("ethers");
/**
* Factory class for deploying CreatorTokenTransferValidator contracts
*/
class CreatorTokenTransferValidatorFactory {
/**
* Create a new factory instance
* @param runner An ethers.js ContractRunner (Provider or Signer)
*/
constructor(runner) {
this.runner = runner;
}
/**
* Deploy a new CreatorTokenTransferValidator contract
* Note: You'll need to replace the placeholder bytecode with actual contract bytecode
* @returns The deployed contract address
*/
async deploy() {
// ABI for the contract
const abi = [
'constructor()',
'function setCollectionSecurityPolicy(address collection, uint8 securityLevel, uint32 operatorWhitelistId, uint32 permittedContractReceiversAllowlistId) external',
'function addToList(uint256 listId, address account) external',
'function removeFromList(uint256 listId, address account) external',
'function isOperatorWhitelisted(uint256 listId, address operator) external view returns (bool)',
'function getSecurityPolicyRegistry() external view returns (address)',
];
// Bytecode would go here - you'll need to replace this with the actual contract bytecode
// This is a placeholder and would need to be replaced with the actual bytecode
const bytecode = '0x608060405234801561001057600080fd5b50610c7c806100206000396000f3fe...';
// Use ethers factory
const factory = new ethers_1.ethers.ContractFactory(abi, bytecode, this.runner);
// Deploy the contract
const contract = await factory.deploy();
const receipt = await contract.deploymentTransaction()?.wait();
if (!receipt || !receipt.contractAddress) {
throw new Error('Deployment failed - no contract address in receipt');
}
// Return the deployed contract address
return receipt.contractAddress;
}
/**
* Create a contract instance from a deployed address
* @param address The address of the deployed validator
* @returns A contract instance
*/
createInstance(address) {
const abi = [
'function setCollectionSecurityPolicy(address collection, uint8 securityLevel, uint32 operatorWhitelistId, uint32 permittedContractReceiversAllowlistId) external',
'function addToList(uint256 listId, address account) external',
'function removeFromList(uint256 listId, address account) external',
'function isOperatorWhitelisted(uint256 listId, address operator) external view returns (bool)',
'function getSecurityPolicyRegistry() external view returns (address)',
];
return new ethers_1.ethers.Contract(address, abi, this.runner);
}
}