| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- 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() {
-
- //,isin: string, account: string, KSDAccount: string, qty: number, slipSeqKSD: string
- // 종목20
- let tokenAddress = '0x3e7757d67F2DBc9C2D9d69d74eCF0E498988da4F';
- let slipSeqKSD = '0000000001';
- const Symbol1 = 'KR5STO000177';
- let qty = 100000;
- // await issueKSD(tokenAddress,admin,
- // Symbol1,
- // accountCustomer,
- // ksdAccountCustomer,
- // qty,
- // slipSeqKSD
- // );
-
- await balanceOf(tokenAddress,admin,Symbol1,accountCustomer);
-
- qty = 100000;
- let rsnCode = '203';
- // ,isin: string, account: string, KSDAccount: string, rsnCode: string, qty: number
- // await disposalLimitSetupKSD(tokenAddress,admin,
- // Symbol1,
- // accountCustomer,
- // ksdAccountCustomer,
- // rsnCode,
- // qty
- // );
-
- rsnCode = '203';
- // ,isin: string, account: string, KSDAccount: string, qty: number, rsnCode: string, slipSeqKSD: string
- // await erasureKSD(tokenAddress,admin,
- // Symbol1,
- // accountCustomer,
- // ksdAccountCustomer,
- // qty,
- // rsnCode,
- // slipSeqKSD
- // );
-
-
- }
-
- main();
-
|