Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

start.ts 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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
  5. } from 'ethers'
  6. import {Calulator} from "../inc/calc";
  7. import axios from "axios";
  8. import {
  9. SecurityToken,
  10. SecurityToken__factory,
  11. } from '../typechain'
  12. // import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
  13. import {checkReceipt,checkReceipt2, setProvider,getDeploymentAddresses,
  14. getElapsed, sleep,getBlockInfo} from '../inc/util'
  15. import { sign } from "crypto";
  16. dotevnv.config();
  17. if (!process.env.RPCURL) {
  18. console.log(`No rpcur value specified...`)
  19. }
  20. console.log(`목적 서버 : ${process.env.RPCURL}`);
  21. async function getNonce(addr: string): Promise<number> {
  22. const nonce = await provider.getTransactionCount(addr);
  23. return nonce;
  24. }
  25. async function info(symbol: string) {
  26. const proxy = getDeploymentAddresses(symbol).address;
  27. console.log(`토큰 주소 : ${proxy}`);
  28. const token = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken;
  29. await token.connect(admin);
  30. const ops = await token.operators();
  31. console.log(ops);
  32. const balance = await token.balanceOf(firstHolder);
  33. console.log(`initial balance = ${balance}`);
  34. let b = await token.isTokenHolderKYC('0x2071ec931b2567a1418e9bc34b786d654a079b43');
  35. if(!b) {
  36. console.log('kyc check first!');
  37. return;
  38. }
  39. await token.KYCtokenHolders([holder1.address,holder2.address]);
  40. b = await token.isTokenHolderKYC(holder1.address);
  41. if(!b) {
  42. console.log('kyc check first!');
  43. return;
  44. }
  45. // token.grantRole(keccak256('OPERATOR_ROLE'),'0xaaa')
  46. }
  47. function getAuthHeader(token: string) : any{
  48. return {
  49. headers: {
  50. 'Content-Type': 'application/json;charset=UTF-8',
  51. 'Access-Control-Allow-Origin': '*',
  52. 'Authorization': `Bearer ${token}`
  53. }
  54. };
  55. }
  56. async function getBalance(symbol: string, address: string ): Promise<number> {
  57. const path = `holders/${address}/tokens/${symbol}/balance`;
  58. const ret = await axios.get(gateWay + path, getAuthHeader(authToken));
  59. return ret.data;
  60. }
  61. async function getTx(signerAddress:string, tokenSymbol: string, from: string, to: string, value: number) : Promise<any> {
  62. const path = 'transfer/tx/data';
  63. const ret = await axios.post(gateWay + path, {
  64. signerAddress,
  65. tokenSymbol,
  66. transfers : [{
  67. partitionName:'초기',
  68. from,
  69. to,
  70. value,
  71. data:'0x0000000000000000000000000000000000000000000000000000000000000000',
  72. operatorData:'0x0000000000000000000000000000000000000000000000000000000000000000'
  73. }]
  74. },getAuthHeader(authToken));
  75. return ret;
  76. }
  77. async function send(signedTransaction: string) {
  78. const path = 'transaction/send';
  79. const ret = await axios.post(gateWay + path, {
  80. signedTransaction
  81. },getAuthHeader(authToken));
  82. return ret;
  83. }
  84. async function transfer(signer: Wallet,symbol:string,from: Wallet, to: Wallet, amount: number = 1, count: number = 10) {
  85. const proxy = getDeploymentAddresses(symbol).address;
  86. console.log(`토큰 주소 : ${proxy}`);
  87. const token = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken;
  88. const decimals = await token.decimals();
  89. const digit = 10 ** Number(decimals);
  90. console.log(`자릿수 = ${digit}`);
  91. let fb = await getBalance(symbol,from.address);
  92. let tb = await getBalance(symbol,to.address);
  93. fb = (1/digit) * fb;
  94. tb = (1/digit) * tb;
  95. console.log(`from balance before : ${fb.toFixed(Number(decimals))}, to balance before : ${tb.toFixed(Number(decimals))}`);
  96. let signedData = [];
  97. for(let i = 0; i < count; i++) {
  98. const rawTx = await getTx(signer.address,symbol,from.address,to.address, amount * digit);
  99. const tx = Transaction.from(rawTx.data);
  100. const signed = await signer.signTransaction(tx);
  101. signedData.push(signed);
  102. }
  103. let proms = [];
  104. for(let i = 0; i < count; i++) {
  105. proms.push(send(signedData[i]));
  106. }
  107. let resolved = await Promise.all(proms);
  108. resolved.forEach(tx => {
  109. console.log(tx.data.transactionHash);
  110. });
  111. // for(let i = 0; i < count; i++) {
  112. // const rawTx = await getTx(signer.address,symbol,from.address,to.address, amount * digit);
  113. // const tx = Transaction.from(rawTx.data);
  114. // // console.log(tx.nonce);
  115. // const signed = await signer.signTransaction(tx);
  116. // const txid = await send(signed);
  117. // // console.log(txid);
  118. // }
  119. fb = await getBalance(symbol,from.address);
  120. tb = await getBalance(symbol,to.address);
  121. fb = (1/digit) * fb;
  122. tb = (1/digit) * tb;
  123. console.log(`from balance after : ${fb.toFixed(Number(decimals))}, to balance after : ${tb.toFixed(Number(decimals))}`);
  124. }
  125. const firstHolder = '0x2071ec931b2567a1418e9bc34b786d654a079b43';
  126. const calc = new Calulator();
  127. const rpcUrl = process.env.RPCURL;
  128. const gateWay = process.env.GATE_WAY;
  129. const authToken=process.env.AUTHTOKEN;
  130. const provider = new JsonRpcProvider(rpcUrl);
  131. setProvider(provider);
  132. const admin = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',provider);
  133. const issuer = new Wallet('0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63',provider);
  134. const holder1 = new Wallet('0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f',provider);
  135. const holder2 = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',provider);
  136. // const signer = holder1;
  137. async function main() {
  138. // console.log(admin);
  139. // console.log(issuer);
  140. // console.log(holder1);
  141. // console.log(holder2);
  142. transfer(holder1,'BCG_TEST',holder1, holder2,1, 10);
  143. }
  144. main();