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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import * as dotevnv from "dotenv"
  2. import {toUtf8String,parseUnits,ContractFactory, parseEther,JsonRpcProvider, Contract, JsonRpcSigner, Wallet,ContractTransactionResponse, MaxInt256
  3. ,Transaction,formatEther,
  4. ZeroHash
  5. } from 'ethers'
  6. import {ethers} from 'hardhat';
  7. import {Calulator} from "../inc/calc";
  8. import { TokenIssuer } from "../inc/TokenIssuer";
  9. import {
  10. SecurityToken,
  11. SecurityToken__factory,
  12. } from '../typechain'
  13. import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
  14. import {checkReceipt, setProvider} from '../inc/util'
  15. dotevnv.config();
  16. if (!process.env.RPCURL) {
  17. console.log(`No rpcur value specified...`)
  18. }
  19. async function sendTx(fromKey: string, to: string, amount: string, nonce: number): Promise<string> {
  20. const wallet = new Wallet(fromKey, provider);
  21. const tx = await wallet.sendTransaction({
  22. to: to,
  23. value: parseUnits(amount, 'ether'),
  24. nonce: nonce
  25. });
  26. return tx.hash;
  27. }
  28. async function sendDirect(fromKey:string, to: string, amount: string,nonce: number) : Promise<string> {
  29. const wallet = new Wallet(fromKey);
  30. const sender = wallet.address;
  31. // const nonce = await provider.getTransactionCount(sender);
  32. // console.log(`block nonce = ${nonce}`);
  33. const tx = {
  34. to: to,
  35. value: parseEther(amount.toString()),
  36. //gasPrice: 0,
  37. //gasPrice: gas,
  38. gasLimit: 21000, //21000으로 고정권장(너무 높으면 속도가 느려짐)
  39. //gasLimit: gasLimit,
  40. // maxPriorityFeePerGas: parseUnits("5", "gwei"),
  41. // maxFeePerGas: parseUnits("20", "gwei"),
  42. nonce: nonce,
  43. type: 2,
  44. chainId: 1337, // Corresponds to ETH_GOERLI
  45. };
  46. const signed = await wallet.signTransaction(tx);
  47. const txid = await provider.send('eth_sendRawTransaction',[signed]);
  48. return txid;
  49. }
  50. async function getBalance(addr: string): Promise<string> {
  51. const wallet = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3', provider);
  52. const balance = await provider.getBalance(addr);
  53. return formatEther(balance);
  54. }
  55. async function getNonce(addr: string): Promise<number> {
  56. const nonce = await provider.getTransactionCount(addr);
  57. return nonce;
  58. }
  59. async function send() {
  60. let to = '0xfe3b557e8fb62b89f4916b721be55ceb828dbd73';
  61. let from = '0x627306090abaB3A6e1400e9345bC60c78a8BEf57';
  62. let fromKey = '0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3';
  63. let nonce = await getNonce(from);
  64. let txids = [];
  65. const count = 1;
  66. let startTime = 0;
  67. for(let i = 0; i < count; i++) {
  68. let txid = await sendDirect(fromKey,to,'0.1',nonce++);
  69. // start time setting
  70. if(i == 0) {
  71. startTime = Date.now();
  72. }
  73. // console.log(txid);
  74. txids.push({txid});
  75. }
  76. // let txid = await sendTx(to,'0.1',nonce++);
  77. await checkReceipt(txids, 'check receipt....');
  78. let tx = await provider.send('eth_getTransactionByHash',[txids[0].txid]);
  79. const firstBlock = await provider.getBlock(tx.blockNumber);
  80. // console.log(firstBlock);
  81. tx = await provider.send('eth_getTransactionByHash',[txids[count-1].txid]);
  82. const lastBlock = await provider.getBlock(tx.blockNumber);
  83. // console.log(lastBlock);
  84. console.log(startTime);
  85. console.log(firstBlock.timestamp);
  86. console.log(lastBlock.timestamp);
  87. // let balance= await getBalance(to);
  88. // console.log(balance);
  89. }
  90. const calc = new Calulator();
  91. async function prepareToken(contractOwner: Wallet | HardhatEthersSigner, issuer: Wallet | HardhatEthersSigner, holder1: string, holder2: string) {
  92. const deployed = require('../security_token_deployments.json');
  93. const tokenService = new TokenIssuer(contractOwner as Wallet,deployed.tokenBeacon,deployed.rulesBeacon,contractOwner.address);
  94. const proxy = await tokenService.deploy('테스트토큰','st0015',6,100000,issuer.address);
  95. console.log(`new token deployed at ${proxy}`);
  96. const token = new SecurityToken__factory(contractOwner).attach(proxy) as SecurityToken;
  97. //token.connect(contractOwner);
  98. console.log(await token.name());
  99. console.log(await token.symbol());
  100. console.log(await token.maxSupply());
  101. const tokenForIssuer = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken;
  102. await tokenForIssuer.connect(issuer);
  103. let r = await tokenForIssuer.KYCtokenHolders([holder1]);
  104. await tokenForIssuer.KYCtokenHolders([holder2]);
  105. let txids = [];
  106. txids.push({txid: r.hash});
  107. await checkReceipt(txids, 'wait for transaction confirmed');
  108. const b = await tokenForIssuer.isTokenHolderKYC(holder1);
  109. if(!b) {
  110. console.log('holder kyc error');
  111. return;
  112. }
  113. await tokenForIssuer.issue(holder1,10_000n,ZeroHash);
  114. r = await tokenForIssuer.issue(holder2,5000,ZeroHash);
  115. txids = [];
  116. txids.push({txid: r.hash});
  117. await checkReceipt(txids, 'wait for transaction confirmed');
  118. let balance = await tokenForIssuer.balanceOf(holder1);
  119. console.log(`holder1's balance = ${balance}`);
  120. balance = await tokenForIssuer.balanceOf(holder2);
  121. console.log(`holder2's balance = ${balance}`);
  122. console.log('TestData created!');
  123. }
  124. const rpcUrl = process.env.RPCURL;
  125. const provider = new JsonRpcProvider(rpcUrl);
  126. async function main() {
  127. setProvider(provider);
  128. const admin = await ethers.provider.getSigner(0);
  129. const issuer = await ethers.provider.getSigner(1);
  130. const holder1 = await ethers.provider.getSigner(2);
  131. const holder2 = await ethers.provider.getSigner(3);
  132. await prepareToken(admin, issuer, holder1.address, holder2.address);
  133. // await test('0x1411CB266FCEd1587b0AA29E9d5a9Ef3Db64A9C5');
  134. }
  135. main();