| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- 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 문자 제거
- };
-
- async function balanceOf(tokenAddress: string, operator: Wallet,
- isin: string, account: string)
- {
- const token = new SecurityToken__factory(operator).attach(tokenAddress) as SecurityToken;
- await token.connect(operator);
-
-
- const balance = await token.balanceOfKSD(toBytes32(isin),account);
-
- console.log(balance);
-
- }
-
- /// @notice 계좌대체 표준 함수
- /// @param isin 종목 isin 코드
- /// @param accountFrom 송신 지갑주소
- /// @param KSDAccountFrom 송신 642계좌
- /// @param accountTo 수신 지갑주소
- /// @param KSDAccountTo 수신 642계좌
- /// @param qty 전송 수량
- /// @param rsnCode 사유코드
- //function transferKSD(bytes32 isin, address accountFrom, bytes32 KSDAccountFrom, address accountTo, bytes32 KSDAccountTo, uint256 qty, bytes32 rsnCode) external;
-
- async function transferKSD(address: string, operator: Wallet
- ,isin: string, accountFrom: string, KSDAccountFrom: string, accountTo: string, KSDAccountTo: string, qty: number, rsnCode: string
- ) {
- console.log(`transferKSD(${isin},${accountFrom},${KSDAccountFrom},${accountTo},${KSDAccountTo},${qty},${rsnCode})`);
-
- const token = new SecurityToken__factory(operator).attach(address) as SecurityToken;
- await token.connect(operator);
-
- let r = await token.transferKSD(
- toBytes32(isin),
- accountFrom,toBytes32(KSDAccountFrom),
- accountTo,toBytes32(KSDAccountTo),
- qty,
- toBytes32(rsnCode),
- {gasLimit: 2100000});
-
- const receipt1 = await r.wait();
- console.log(receipt1.hash);
-
- }
-
- 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);
- }
-
- const rpcUrl = process.env.RPCURL;
- const provider = new JsonRpcProvider(rpcUrl);
- setProvider(provider);
- const admin = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',provider);
- // KR5STO000166 (토큰증권 테스트 종목16) -> 0x920c017843904A735458AA9d30779bE5FCfcF411
- // KR5STO000177 (토큰증권 테스트 종목17) -> 0x3e7757d67F2DBc9C2D9d69d74eCF0E498988da4F
- // KR5STO000188 (토큰증권 테스트 종목18) -> 0x984f4DbAD8fC003138312293Fd431E5D8bAC1daf
- // KR5STO000199 (토큰증권 테스트 종목19) -> 0xa36116158Cdfbcc57c3FEB9cc2A1cdfF8Cf5e247
- // KR5STO000202 (토큰증권 테스트 종목20) -> 0x93302A7eeD96b27D47Ec692c6560cA5Fd5E9e7ED
-
- // 신한 자기분계좌
- const accountShinhanSelf = '0x8909ba8b4dd517de907ab83dc5226352a151f74f';
- const ksdAccountShinhanSelf = '000002000001';
- // 신한 고객분계좌
- const accountShinhan = '0x1C69DB7373505C1b69c9A2Dce0Be88EeE3c5f5e5';
- const ksdAccountShinhan = '000002000002';
-
- // 한화 자기분
- const accountHanwhaSelf = '0xc575ebd70f293a2d1a74c3cb4058e439f1996922';
- const ksdAccountHanwhaSelf = '000021000001';
- // 한화 고객분계좌
- const accountHanwha = '0xf48de4a0c2939e62891f3c6aca68982975477e45';
- const ksdAccountHanwha = '000021000002';
-
-
- // 메리츠 고객분계좌
- const accountMeritz = '0x0886328869e4e1f401e1052a5f4aae8b45f42610';
- const ksdAccountMeritz = '000010000002';
-
-
- async function main() {
-
-
- // 종목17
- let tokenAddress = '0x3e7757d67F2DBc9C2D9d69d74eCF0E498988da4F';
- let symbol = 'KR5STO000177';
- let qty = 500000;
- // 신한(고객) -> 한화(자기)
- // await transferKSD(tokenAddress,admin,
- // symbol,
- // accountShinhan,
- // ksdAccountShinhan,
- // accountHanwhaSelf,
- // ksdAccountHanwhaSelf,
- // qty,
- // '000'
- // );
-
- // 종목18
- tokenAddress = '0x984f4DbAD8fC003138312293Fd431E5D8bAC1daf';
- symbol = 'KR5STO000188';
- qty = 250000;
- // 신한(고객) -> 신한(자기)
- // await transferKSD(tokenAddress,admin,
- // symbol,
- // accountShinhan,
- // ksdAccountShinhan,
- // accountShinhanSelf,
- // ksdAccountShinhanSelf,
- // qty,
- // '000'
- // );
-
-
- // 종목20
- tokenAddress = '0x93302A7eeD96b27D47Ec692c6560cA5Fd5E9e7ED';
- symbol = 'KR5STO000202';
-
- qty = 200000;
- // 신한(고객) -> 메리츠(고객)
- // await transferKSD(tokenAddress,admin,
- // symbol,
- // accountShinhan,
- // ksdAccountShinhan,
- // accountMeritz,
- // ksdAccountMeritz,
- // qty,
- // '000'
- // );
-
- qty = 200000;
- // 메리츠(고객) -> 한화(고객)
- // await transferKSD(tokenAddress,admin,
- // symbol,
- // accountMeritz,
- // ksdAccountMeritz,
- // accountHanwha,
- // ksdAccountHanwha,
- // qty,
- // '000'
- // );
-
- qty = 200000;
- // 한화(고객) -> 신한(고객)
- // await transferKSD(tokenAddress,admin,
- // symbol,
- // accountHanwha,
- // ksdAccountHanwha,
- // accountShinhan,
- // ksdAccountShinhan,
- // qty,
- // '000'
- // );
-
-
- await balanceOf(tokenAddress,admin,symbol,accountShinhan);
- }
-
- main();
-
|