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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. // function toBytes32(data: string): BytesLike {
  40. // return hexlify(zeroPadValue(toUtf8Bytes(data), 32));
  41. // }
  42. // /**
  43. // * Converts solidity byte32 to utf8 string
  44. // */
  45. // function bytes32ToString(data: BytesLike): string {
  46. // return toUtf8String(stripZerosLeft(data));
  47. // }
  48. async function balanceOf(tokenAddress: string, operator: Wallet,
  49. isin: string, account: string)
  50. {
  51. const token = new SecurityToken__factory(operator).attach(tokenAddress) as SecurityToken;
  52. await token.connect(operator);
  53. const balance = await token.balanceOfKSD(toBytes32(isin),account);
  54. console.log(balance);
  55. }
  56. async function issueKSD(address: string, operator: Wallet
  57. ,isin: string, account: string, KSDAccount: string, qty: number, slipSeqKSD: string
  58. ) {
  59. const token = new SecurityToken__factory(operator).attach(address) as SecurityToken;
  60. await token.connect(operator);
  61. const decimals = await token.decimals();
  62. console.log(decimals);
  63. const symbol = await token.symbol();
  64. console.log(symbol);
  65. const is = await token.retrieveIsinKSD(toBytes32(isin));
  66. console.log( bytes32ToString(is));
  67. let r = await token.issueKSD(toBytes32(isin),account,toBytes32(KSDAccount),qty,toBytes32(slipSeqKSD),{gasLimit: 2100000});
  68. const receipt1 = await r.wait();
  69. console.log(receipt1.hash);
  70. }
  71. async function disposalLimitSetupKSD(address: string, operator: Wallet
  72. ,isin: string,
  73. account: string, KSDAccount: string, rsnCode: string, qty: number
  74. ) {
  75. const token = new SecurityToken__factory(operator).attach(address) as SecurityToken;
  76. await token.connect(operator);
  77. let r = await token.disposalLimitSetupKSD(toBytes32(isin),account,KSDAccount,toBytes32(rsnCode),qty);
  78. const receipt1 = await r.wait();
  79. console.log(receipt1.hash);
  80. }
  81. //function erasureKSD(bytes32 isin, address account, bytes32 KSDAccount, uint256 qty, bytes32 rsnCode, bytes32 slipSeqKSD) external;
  82. async function erasureKSD(address: string, operator: Wallet
  83. ,isin: string, account: string, KSDAccount: string, qty: number, rsnCode: string, slipSeqKSD: string
  84. ) {
  85. const token = new SecurityToken__factory(operator).attach(address) as SecurityToken;
  86. await token.connect(operator);
  87. let r = await token.erasureKSD(toBytes32(isin),account,toBytes32(KSDAccount),qty,toBytes32(rsnCode),toBytes32(slipSeqKSD),{gasLimit: 2100000});
  88. const receipt1 = await r.wait();
  89. console.log(receipt1.hash);
  90. }
  91. const calc = new Calulator();
  92. const rpcUrl = process.env.RPCURL;
  93. const provider = new JsonRpcProvider(rpcUrl);
  94. setProvider(provider);
  95. const admin = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',provider);
  96. const issuer = new Wallet('0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63',provider);
  97. const holder1 = new Wallet('0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f',provider);
  98. const holder2 = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',provider);
  99. const user1 = new Wallet('5c7ff82446654833ed4cbd3dc7cca94b114b556def572a5f2f7f29224c757adb',provider);
  100. const user2 = new Wallet('509157aeb1308d8ff8db8a3059d4392d92fb66960ef5083eda5a8dcc9118be31',provider);
  101. const newOperator = new Wallet('a0e4679c61e04969499af0c4cdcdc66e9a9f2e3f6cbc17ede9e2137518f8e75d',provider);
  102. // KR5STO000166 (토큰증권 테스트 종목16) -> 0x920c017843904A735458AA9d30779bE5FCfcF411
  103. // KR5STO000177 (토큰증권 테스트 종목17) -> 0x3e7757d67F2DBc9C2D9d69d74eCF0E498988da4F
  104. // KR5STO000188 (토큰증권 테스트 종목18) -> 0x984f4DbAD8fC003138312293Fd431E5D8bAC1daf
  105. // KR5STO000199 (토큰증권 테스트 종목19) -> 0xa36116158Cdfbcc57c3FEB9cc2A1cdfF8Cf5e247
  106. // KR5STO000202 (토큰증권 테스트 종목20) -> 0x93302A7eeD96b27D47Ec692c6560cA5Fd5E9e7ED
  107. // KR5STO000202 (토큰증권 테스트 종목20) -> 0x9D084404B8558604a1e69B9782A6f421870bd907 - 폐기된 종목
  108. const accountSelf = '0x8909ba8b4dd517de907ab83dc5226352a151f74f';
  109. const ksdAccountSelf = '000002000001';
  110. const accountCustomer = '0x1C69DB7373505C1b69c9A2Dce0Be88EeE3c5f5e5';
  111. const ksdAccountCustomer = '000002000002';
  112. async function main() {
  113. //,isin: string, account: string, KSDAccount: string, qty: number, slipSeqKSD: string
  114. // 종목20
  115. let tokenAddress = '0x920c017843904A735458AA9d30779bE5FCfcF411';
  116. let slipSeqKSD = '0000000001';
  117. const Symbol1 = 'KR5STO000166';
  118. let qty = 100000;
  119. // await issueKSD(tokenAddress,admin,
  120. // Symbol1,
  121. // accountCustomer,
  122. // ksdAccountCustomer,
  123. // qty,
  124. // slipSeqKSD
  125. // );
  126. await balanceOf(tokenAddress,admin,Symbol1,accountCustomer);
  127. qty = 100000;
  128. let rsnCode = '203';
  129. // ,isin: string, account: string, KSDAccount: string, rsnCode: string, qty: number
  130. // await disposalLimitSetupKSD(tokenAddress,admin,
  131. // Symbol1,
  132. // accountCustomer,
  133. // ksdAccountCustomer,
  134. // rsnCode,
  135. // qty
  136. // );
  137. rsnCode = '203';
  138. // ,isin: string, account: string, KSDAccount: string, qty: number, rsnCode: string, slipSeqKSD: string
  139. // await erasureKSD(tokenAddress,admin,
  140. // Symbol1,
  141. // accountCustomer,
  142. // ksdAccountCustomer,
  143. // qty,
  144. // rsnCode,
  145. // slipSeqKSD
  146. // );
  147. }
  148. main();