You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

start2.ts 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import * as dotevnv from "dotenv"
  2. import {toUtf8String,parseUnits,ContractFactory, parseEther,JsonRpcProvider, Contract, JsonRpcSigner, Wallet,ContractTransactionResponse, MaxInt256
  3. ,Transaction,formatEther,
  4. ZeroHash,ethers,keccak256,id,
  5. hexlify,
  6. BytesLike,
  7. toUtf8Bytes,
  8. zeroPadValue,
  9. stripZerosLeft
  10. } from 'ethers'
  11. import chalk from "chalk";
  12. import {Calulator} from "../inc/calc";
  13. import { TokenIssuer } from "../inc/TokenIssuer";
  14. import {
  15. SecurityToken,
  16. SecurityToken__factory,
  17. } from '../typechain2'
  18. // import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
  19. import { Partition } from '../inc/tokenData';
  20. import { Operator } from '../typechain/contracts/access/Operator';
  21. import { stringify } from 'querystring';
  22. import {checkReceipt,checkReceipt2, setProvider,getDeploymentAddresses,
  23. getElapsed, sleep,getBlockInfo} from '../inc/util'
  24. dotevnv.config();
  25. if (!process.env.RPCURL) {
  26. console.log(`No rpcur value specified...`)
  27. }
  28. console.log(`목적 서버 : ${process.env.RPCURL}`);
  29. import Web3 from 'web3';
  30. const web3 = new Web3();
  31. // 문자열을 bytes32로 변환하는 함수
  32. const toBytes32 = (inputString: string): string => {
  33. return web3.utils.asciiToHex(inputString).padEnd(66, '0'); // 32 bytes로 패딩 추가
  34. };
  35. // bytes32를 문자열로 변환하는 함수
  36. const bytes32ToString = (bytes32: string): string => {
  37. return web3.utils.hexToAscii(bytes32).replace(/\0/g, ''); // null 문자 제거
  38. };
  39. import tokenContract from '../SecurityToken.json'
  40. // function toBytes32(data: string): BytesLike {
  41. // return hexlify(zeroPadValue(toUtf8Bytes(data), 32));
  42. // }
  43. // /**
  44. // * Converts solidity byte32 to utf8 string
  45. // */
  46. // function bytes32ToString(data: BytesLike): string {
  47. // return toUtf8String(stripZerosLeft(data));
  48. // }
  49. async function balanceOf(tokenAddress: string, operator: Wallet,
  50. isin: string, account: string)
  51. {
  52. const token = new ethers.Contract(
  53. tokenAddress,
  54. tokenContract.abi,
  55. operator
  56. );
  57. // const token = new SecurityToken__factory(operator).attach(tokenAddress) as SecurityToken;
  58. // await token.connect(operator);
  59. const symbol = await token.symbol();
  60. console.log(symbol);
  61. const i = await token.retrieveIsin();
  62. console.log( bytes32ToString(i));
  63. console.log(toBytes32(isin));
  64. // const is = await token.retrieveIsinKSD(toBytes32('KR5STO000177'));
  65. // console.log( bytes32ToString(is));
  66. const balance = await token.balanceOfKSD(toBytes32(isin),account);
  67. console.log(balance);
  68. }
  69. async function issueKSD(address: string, operator: Wallet
  70. ,isin: string, account: string, KSDAccount: string, qty: number, slipSeqKSD: string
  71. ) {
  72. const token = new SecurityToken__factory(operator).attach(address) as SecurityToken;
  73. await token.connect(operator);
  74. const decimals = await token.decimals();
  75. console.log(decimals);
  76. const symbol = await token.symbol();
  77. console.log(symbol);
  78. const is = await token.retrieveIsinKSD(toBytes32(isin));
  79. console.log( bytes32ToString(is));
  80. let r = await token.issueKSD(toBytes32(isin),account,toBytes32(KSDAccount),qty,toBytes32(slipSeqKSD),{gasLimit: 2100000});
  81. const receipt1 = await r.wait();
  82. console.log(receipt1.hash);
  83. }
  84. async function disposalLimitSetupKSD(address: string, operator: Wallet
  85. ,isin: string,
  86. account: string, KSDAccount: string, rsnCode: string, qty: number
  87. ) {
  88. const token = new SecurityToken__factory(operator).attach(address) as SecurityToken;
  89. await token.connect(operator);
  90. let r = await token.disposalLimitSetupKSD(toBytes32(isin),account,KSDAccount,toBytes32(rsnCode),qty);
  91. const receipt1 = await r.wait();
  92. console.log(receipt1.hash);
  93. }
  94. //function erasureKSD(bytes32 isin, address account, bytes32 KSDAccount, uint256 qty, bytes32 rsnCode, bytes32 slipSeqKSD) external;
  95. async function erasureKSD(address: string, operator: Wallet
  96. ,isin: string, account: string, KSDAccount: string, qty: number, rsnCode: string, slipSeqKSD: string
  97. ) {
  98. const token = new SecurityToken__factory(operator).attach(address) as SecurityToken;
  99. await token.connect(operator);
  100. let r = await token.erasureKSD(toBytes32(isin),account,toBytes32(KSDAccount),qty,toBytes32(rsnCode),toBytes32(slipSeqKSD),{gasLimit: 2100000});
  101. const receipt1 = await r.wait();
  102. console.log(receipt1.hash);
  103. }
  104. const calc = new Calulator();
  105. const rpcUrl = process.env.RPCURL;
  106. const provider = new JsonRpcProvider(rpcUrl);
  107. setProvider(provider);
  108. const admin = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',provider);
  109. const issuer = new Wallet('0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63',provider);
  110. const holder1 = new Wallet('0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f',provider);
  111. const holder2 = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',provider);
  112. const user1 = new Wallet('5c7ff82446654833ed4cbd3dc7cca94b114b556def572a5f2f7f29224c757adb',provider);
  113. const user2 = new Wallet('509157aeb1308d8ff8db8a3059d4392d92fb66960ef5083eda5a8dcc9118be31',provider);
  114. const newOperator = new Wallet('a0e4679c61e04969499af0c4cdcdc66e9a9f2e3f6cbc17ede9e2137518f8e75d',provider);
  115. // KR5STO000166 (토큰증권 테스트 종목16) -> 0x920c017843904A735458AA9d30779bE5FCfcF411
  116. // KR5STO000177 (토큰증권 테스트 종목17) -> 0x3e7757d67F2DBc9C2D9d69d74eCF0E498988da4F
  117. // KR5STO000188 (토큰증권 테스트 종목18) -> 0x984f4DbAD8fC003138312293Fd431E5D8bAC1daf
  118. // KR5STO000199 (토큰증권 테스트 종목19) -> 0xa36116158Cdfbcc57c3FEB9cc2A1cdfF8Cf5e247
  119. // KR5STO000202 (토큰증권 테스트 종목20) -> 0x93302A7eeD96b27D47Ec692c6560cA5Fd5E9e7ED
  120. // KR5STO000200 (토큰증권 테스트 종목20) -> 0x9D084404B8558604a1e69B9782A6f421870bd907 - 폐기된 종목
  121. const accountSelf = '0x8909ba8b4dd517de907ab83dc5226352a151f74f';
  122. const ksdAccountSelf = '000002000001';
  123. const accountCustomer = '0x1C69DB7373505C1b69c9A2Dce0Be88EeE3c5f5e5';
  124. const ksdAccountCustomer = '000002000002';
  125. async function main() {
  126. console.log(bytes32ToString('0x4b523553544f3030303136360000000000000000000000000000000000000000'));
  127. console.log(bytes32ToString('0x3030303030323030303030320000000000000000000000000000000000000000'));
  128. console.log(bytes32ToString('0x3030303031303030303030320000000000000000000000000000000000000000'));
  129. console.log(bytes32ToString('0x3030303032313030303030320000000000000000000000000000000000000000'));
  130. console.log(bytes32ToString('0x3030313230323530333130303030303030303030380000000000000000000000'));
  131. }
  132. main();