UNPKG

@citizenwallet/sdk

Version:

An sdk to easily work with citizen wallet.

79 lines 4.46 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateCalldataLink = exports.addOwnerCallData = exports.callOnCardCallData = exports.updateWhitelistCallData = exports.updateInstanceContractsCallData = exports.createInstanceCallData = exports.tokenMintCallData = exports.tokenTransferCallData = exports.roleRevokedEventTopic = exports.roleGrantedEventTopic = exports.tokenTransferSingleEventTopic = exports.tokenTransferEventTopic = void 0; const ethers_1 = require("ethers"); const ERC20_abi_json_1 = __importDefault(require("../abi/ERC20.abi.json")); const CardManagerModule_abi_json_1 = __importDefault(require("../abi/CardManagerModule.abi.json")); const erc20Interface = new ethers_1.Interface(ERC20_abi_json_1.default); const cardManagerModuleInterface = new ethers_1.Interface(CardManagerModule_abi_json_1.default); exports.tokenTransferEventTopic = (0, ethers_1.id)("Transfer(address,address,uint256)"); exports.tokenTransferSingleEventTopic = (0, ethers_1.id)("TransferSingle(address,address,address,uint256,uint256)"); exports.roleGrantedEventTopic = (0, ethers_1.id)("RoleGranted(bytes32,address,address)"); exports.roleRevokedEventTopic = (0, ethers_1.id)("RoleRevoked(bytes32,address,address)"); const tokenTransferCallData = (to, value) => { return (0, ethers_1.getBytes)(erc20Interface.encodeFunctionData("transfer", [to, value])); }; exports.tokenTransferCallData = tokenTransferCallData; const tokenMintCallData = (to, value) => { return (0, ethers_1.getBytes)(erc20Interface.encodeFunctionData("mint", [to, value])); }; exports.tokenMintCallData = tokenMintCallData; const createInstanceCallData = (config, contracts, instanceId) => { const cardConfig = config.primarySafeCardConfig; const hashedInstanceId = (0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(instanceId ?? cardConfig.instance_id)); return (0, ethers_1.getBytes)(cardManagerModuleInterface.encodeFunctionData("createInstance", [ hashedInstanceId, contracts, ])); }; exports.createInstanceCallData = createInstanceCallData; const updateInstanceContractsCallData = (config, contracts, instanceId) => { const cardConfig = config.primarySafeCardConfig; const hashedInstanceId = (0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(instanceId ?? cardConfig.instance_id)); return (0, ethers_1.getBytes)(cardManagerModuleInterface.encodeFunctionData("updateInstanceContracts", [ hashedInstanceId, contracts, ])); }; exports.updateInstanceContractsCallData = updateInstanceContractsCallData; const updateWhitelistCallData = (config, addresses, instanceId) => { const cardConfig = config.primarySafeCardConfig; const hashedInstanceId = (0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(instanceId ?? cardConfig.instance_id)); return (0, ethers_1.getBytes)(cardManagerModuleInterface.encodeFunctionData("updateWhitelist", [ hashedInstanceId, addresses, ])); }; exports.updateWhitelistCallData = updateWhitelistCallData; const callOnCardCallData = (config, hashedSerial, to, value, data, instanceId) => { const cardConfig = config.primarySafeCardConfig; const hashedInstanceId = (0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(instanceId ?? cardConfig.instance_id)); return (0, ethers_1.getBytes)(cardManagerModuleInterface.encodeFunctionData("callOnCard", [ hashedInstanceId, hashedSerial, to, value, data, ])); }; exports.callOnCardCallData = callOnCardCallData; const addOwnerCallData = (config, hashedSerial, newOwner, instanceId) => { const cardConfig = config.primarySafeCardConfig; const hashedInstanceId = (0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(instanceId ?? cardConfig.instance_id)); return (0, ethers_1.getBytes)(cardManagerModuleInterface.encodeFunctionData("addOwner", [ hashedInstanceId, hashedSerial, newOwner, ])); }; exports.addOwnerCallData = addOwnerCallData; const generateCalldataLink = (baseUrl, config, address, value, calldata) => { const alias = config.community.alias; const url = `${baseUrl}/?alias=${alias}&address=${address}&value=${value}&calldata=${calldata}`; return url; }; exports.generateCalldataLink = generateCalldataLink; //# sourceMappingURL=index.js.map