import * as dotevnv from "dotenv" import {toUtf8String,parseUnits,ContractFactory, parseEther,JsonRpcProvider, Contract, JsonRpcSigner, Wallet,ContractTransactionResponse, MaxInt256 ,Transaction,formatEther, ZeroHash,ethers,keccak256,id, hexlify, BytesLike, toUtf8Bytes, zeroPadValue, stripZerosLeft } from 'ethers' import chalk from "chalk"; import {Calulator} from "../inc/calc"; import { TokenIssuer } from "../inc/TokenIssuer"; import { SecurityToken, SecurityToken__factory, } from '../typechain2' // import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers"; import { Partition } from '../inc/tokenData'; import { Operator } from '../typechain/contracts/access/Operator'; import { stringify } from 'querystring'; import {checkReceipt,checkReceipt2, setProvider,getDeploymentAddresses, getElapsed, sleep,getBlockInfo} from '../inc/util' dotevnv.config(); if (!process.env.RPCURL) { console.log(`No rpcur value specified...`) } console.log(`목적 서버 : ${process.env.RPCURL}`); import Web3 from 'web3'; const web3 = new Web3(); // 문자열을 bytes32로 변환하는 함수 const toBytes32 = (inputString: string): string => { return web3.utils.asciiToHex(inputString).padEnd(66, '0'); // 32 bytes로 패딩 추가 }; // bytes32를 문자열로 변환하는 함수 const bytes32ToString = (bytes32: string): string => { return web3.utils.hexToAscii(bytes32).replace(/\0/g, ''); // null 문자 제거 }; import tokenContract from '../SecurityToken.json' // function toBytes32(data: string): BytesLike { // return hexlify(zeroPadValue(toUtf8Bytes(data), 32)); // } // /** // * Converts solidity byte32 to utf8 string // */ // function bytes32ToString(data: BytesLike): string { // return toUtf8String(stripZerosLeft(data)); // } async function balanceOf(tokenAddress: string, operator: Wallet, isin: string, account: string) { const token = new ethers.Contract( tokenAddress, tokenContract.abi, operator ); // const token = new SecurityToken__factory(operator).attach(tokenAddress) as SecurityToken; // await token.connect(operator); const symbol = await token.symbol(); console.log(symbol); const i = await token.retrieveIsin(); console.log( bytes32ToString(i)); console.log(toBytes32(isin)); // const is = await token.retrieveIsinKSD(toBytes32('KR5STO000177')); // console.log( bytes32ToString(is)); const balance = await token.balanceOfKSD(toBytes32(isin),account); console.log(balance); } async function issueKSD(address: string, operator: Wallet ,isin: string, account: string, KSDAccount: string, qty: number, slipSeqKSD: string ) { const token = new SecurityToken__factory(operator).attach(address) as SecurityToken; await token.connect(operator); const decimals = await token.decimals(); console.log(decimals); const symbol = await token.symbol(); console.log(symbol); const is = await token.retrieveIsinKSD(toBytes32(isin)); console.log( bytes32ToString(is)); let r = await token.issueKSD(toBytes32(isin),account,toBytes32(KSDAccount),qty,toBytes32(slipSeqKSD),{gasLimit: 2100000}); const receipt1 = await r.wait(); console.log(receipt1.hash); } async function disposalLimitSetupKSD(address: string, operator: Wallet ,isin: string, account: string, KSDAccount: string, rsnCode: string, qty: number ) { const token = new SecurityToken__factory(operator).attach(address) as SecurityToken; await token.connect(operator); let r = await token.disposalLimitSetupKSD(toBytes32(isin),account,KSDAccount,toBytes32(rsnCode),qty); const receipt1 = await r.wait(); console.log(receipt1.hash); } //function erasureKSD(bytes32 isin, address account, bytes32 KSDAccount, uint256 qty, bytes32 rsnCode, bytes32 slipSeqKSD) external; async function erasureKSD(address: string, operator: Wallet ,isin: string, account: string, KSDAccount: string, qty: number, rsnCode: string, slipSeqKSD: string ) { const token = new SecurityToken__factory(operator).attach(address) as SecurityToken; await token.connect(operator); let r = await token.erasureKSD(toBytes32(isin),account,toBytes32(KSDAccount),qty,toBytes32(rsnCode),toBytes32(slipSeqKSD),{gasLimit: 2100000}); const receipt1 = await r.wait(); console.log(receipt1.hash); } const calc = new Calulator(); const rpcUrl = process.env.RPCURL; const provider = new JsonRpcProvider(rpcUrl); setProvider(provider); const admin = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',provider); const issuer = new Wallet('0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63',provider); const holder1 = new Wallet('0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f',provider); const holder2 = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',provider); const user1 = new Wallet('5c7ff82446654833ed4cbd3dc7cca94b114b556def572a5f2f7f29224c757adb',provider); const user2 = new Wallet('509157aeb1308d8ff8db8a3059d4392d92fb66960ef5083eda5a8dcc9118be31',provider); const newOperator = new Wallet('a0e4679c61e04969499af0c4cdcdc66e9a9f2e3f6cbc17ede9e2137518f8e75d',provider); // KR5STO000166 (토큰증권 테스트 종목16) -> 0x920c017843904A735458AA9d30779bE5FCfcF411 // KR5STO000177 (토큰증권 테스트 종목17) -> 0x3e7757d67F2DBc9C2D9d69d74eCF0E498988da4F // KR5STO000188 (토큰증권 테스트 종목18) -> 0x984f4DbAD8fC003138312293Fd431E5D8bAC1daf // KR5STO000199 (토큰증권 테스트 종목19) -> 0xa36116158Cdfbcc57c3FEB9cc2A1cdfF8Cf5e247 // KR5STO000202 (토큰증권 테스트 종목20) -> 0x93302A7eeD96b27D47Ec692c6560cA5Fd5E9e7ED // KR5STO000200 (토큰증권 테스트 종목20) -> 0x9D084404B8558604a1e69B9782A6f421870bd907 - 폐기된 종목 const accountSelf = '0x8909ba8b4dd517de907ab83dc5226352a151f74f'; const ksdAccountSelf = '000002000001'; const accountCustomer = '0x1C69DB7373505C1b69c9A2Dce0Be88EeE3c5f5e5'; const ksdAccountCustomer = '000002000002'; async function main() { console.log(bytes32ToString('0x4b523553544f3030303136360000000000000000000000000000000000000000')); console.log(bytes32ToString('0x3030303030323030303030320000000000000000000000000000000000000000')); console.log(bytes32ToString('0x3030303031303030303030320000000000000000000000000000000000000000')); console.log(bytes32ToString('0x3030303032313030303030320000000000000000000000000000000000000000')); console.log(bytes32ToString('0x3030313230323530333130303030303030303030380000000000000000000000')); } main();