選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

start.ts 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. async function balanceOf(tokenAddress: string, operator: Wallet,
  40. isin: string, account: string)
  41. {
  42. const token = new SecurityToken__factory(operator).attach(tokenAddress) as SecurityToken;
  43. await token.connect(operator);
  44. const balance = await token.balanceOfKSD(toBytes32(isin),account);
  45. console.log(balance);
  46. }
  47. /// @notice 계좌대체 표준 함수
  48. /// @param isin 종목 isin 코드
  49. /// @param accountFrom 송신 지갑주소
  50. /// @param KSDAccountFrom 송신 642계좌
  51. /// @param accountTo 수신 지갑주소
  52. /// @param KSDAccountTo 수신 642계좌
  53. /// @param qty 전송 수량
  54. /// @param rsnCode 사유코드
  55. //function transferKSD(bytes32 isin, address accountFrom, bytes32 KSDAccountFrom, address accountTo, bytes32 KSDAccountTo, uint256 qty, bytes32 rsnCode) external;
  56. async function transferKSD(address: string, operator: Wallet
  57. ,isin: string, accountFrom: string, KSDAccountFrom: string, accountTo: string, KSDAccountTo: string, qty: number, rsnCode: string
  58. ) {
  59. console.log(`transferKSD(${isin},${accountFrom},${KSDAccountFrom},${accountTo},${KSDAccountTo},${qty},${rsnCode})`);
  60. const token = new SecurityToken__factory(operator).attach(address) as SecurityToken;
  61. await token.connect(operator);
  62. let r = await token.transferKSD(
  63. toBytes32(isin),
  64. accountFrom,toBytes32(KSDAccountFrom),
  65. accountTo,toBytes32(KSDAccountTo),
  66. qty,
  67. toBytes32(rsnCode),
  68. {gasLimit: 2100000});
  69. const receipt1 = await r.wait();
  70. console.log(receipt1.hash);
  71. }
  72. async function issueKSD(address: string, operator: Wallet
  73. ,isin: string, account: string, KSDAccount: string, qty: number, slipSeqKSD: string
  74. ) {
  75. const token = new SecurityToken__factory(operator).attach(address) as SecurityToken;
  76. await token.connect(operator);
  77. const decimals = await token.decimals();
  78. console.log(decimals);
  79. const symbol = await token.symbol();
  80. console.log(symbol);
  81. const is = await token.retrieveIsinKSD(toBytes32(isin));
  82. console.log( bytes32ToString(is));
  83. let r = await token.issueKSD(toBytes32(isin),account,toBytes32(KSDAccount),qty,toBytes32(slipSeqKSD),{gasLimit: 2100000});
  84. const receipt1 = await r.wait();
  85. console.log(receipt1.hash);
  86. }
  87. const rpcUrl = process.env.RPCURL;
  88. const provider = new JsonRpcProvider(rpcUrl);
  89. setProvider(provider);
  90. const admin = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',provider);
  91. // KR5STO000166 (토큰증권 테스트 종목16) -> 0x920c017843904A735458AA9d30779bE5FCfcF411
  92. // KR5STO000177 (토큰증권 테스트 종목17) -> 0x3e7757d67F2DBc9C2D9d69d74eCF0E498988da4F
  93. // KR5STO000188 (토큰증권 테스트 종목18) -> 0x984f4DbAD8fC003138312293Fd431E5D8bAC1daf
  94. // KR5STO000199 (토큰증권 테스트 종목19) -> 0xa36116158Cdfbcc57c3FEB9cc2A1cdfF8Cf5e247
  95. // KR5STO000202 (토큰증권 테스트 종목20) -> 0x93302A7eeD96b27D47Ec692c6560cA5Fd5E9e7ED
  96. // 신한 자기분계좌
  97. const accountShinhanSelf = '0x8909ba8b4dd517de907ab83dc5226352a151f74f';
  98. const ksdAccountShinhanSelf = '000002000001';
  99. // 신한 고객분계좌
  100. const accountShinhan = '0x1C69DB7373505C1b69c9A2Dce0Be88EeE3c5f5e5';
  101. const ksdAccountShinhan = '000002000002';
  102. // 한화 자기분
  103. const accountHanwhaSelf = '0xc575ebd70f293a2d1a74c3cb4058e439f1996922';
  104. const ksdAccountHanwhaSelf = '000021000001';
  105. // 한화 고객분계좌
  106. const accountHanwha = '0xf48de4a0c2939e62891f3c6aca68982975477e45';
  107. const ksdAccountHanwha = '000021000002';
  108. // 메리츠 고객분계좌
  109. const accountMeritz = '0x0886328869e4e1f401e1052a5f4aae8b45f42610';
  110. const ksdAccountMeritz = '000010000002';
  111. async function main() {
  112. // 종목17
  113. let tokenAddress = '0x3e7757d67F2DBc9C2D9d69d74eCF0E498988da4F';
  114. let symbol = 'KR5STO000177';
  115. let qty = 500000;
  116. // 신한(고객) -> 한화(자기)
  117. // await transferKSD(tokenAddress,admin,
  118. // symbol,
  119. // accountShinhan,
  120. // ksdAccountShinhan,
  121. // accountHanwhaSelf,
  122. // ksdAccountHanwhaSelf,
  123. // qty,
  124. // '000'
  125. // );
  126. // 종목18
  127. tokenAddress = '0x984f4DbAD8fC003138312293Fd431E5D8bAC1daf';
  128. symbol = 'KR5STO000188';
  129. qty = 250000;
  130. // 신한(고객) -> 신한(자기)
  131. // await transferKSD(tokenAddress,admin,
  132. // symbol,
  133. // accountShinhan,
  134. // ksdAccountShinhan,
  135. // accountShinhanSelf,
  136. // ksdAccountShinhanSelf,
  137. // qty,
  138. // '000'
  139. // );
  140. // 종목20
  141. tokenAddress = '0x93302A7eeD96b27D47Ec692c6560cA5Fd5E9e7ED';
  142. symbol = 'KR5STO000202';
  143. qty = 200000;
  144. // 신한(고객) -> 메리츠(고객)
  145. // await transferKSD(tokenAddress,admin,
  146. // symbol,
  147. // accountShinhan,
  148. // ksdAccountShinhan,
  149. // accountMeritz,
  150. // ksdAccountMeritz,
  151. // qty,
  152. // '000'
  153. // );
  154. qty = 200000;
  155. // 메리츠(고객) -> 한화(고객)
  156. // await transferKSD(tokenAddress,admin,
  157. // symbol,
  158. // accountMeritz,
  159. // ksdAccountMeritz,
  160. // accountHanwha,
  161. // ksdAccountHanwha,
  162. // qty,
  163. // '000'
  164. // );
  165. qty = 200000;
  166. // 한화(고객) -> 신한(고객)
  167. // await transferKSD(tokenAddress,admin,
  168. // symbol,
  169. // accountHanwha,
  170. // ksdAccountHanwha,
  171. // accountShinhan,
  172. // ksdAccountShinhan,
  173. // qty,
  174. // '000'
  175. // );
  176. await balanceOf(tokenAddress,admin,symbol,accountShinhan);
  177. }
  178. main();