import * as dotevnv from "dotenv" import {toUtf8String,parseUnits,ContractFactory, parseEther,JsonRpcProvider, Contract, JsonRpcSigner, Wallet,ContractTransactionResponse, MaxInt256 ,Transaction,formatEther, ZeroHash } from 'ethers' import {ethers} from 'hardhat'; import {Calulator} from "../inc/calc"; import { TokenIssuer } from "../inc/TokenIssuer"; import { SecurityToken, SecurityToken__factory, } from '../typechain' import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers"; import {checkReceipt, setProvider} from '../inc/util' dotevnv.config(); if (!process.env.RPCURL) { console.log(`No rpcur value specified...`) } async function sendTx(fromKey: string, to: string, amount: string, nonce: number): Promise { const wallet = new Wallet(fromKey, provider); const tx = await wallet.sendTransaction({ to: to, value: parseUnits(amount, 'ether'), nonce: nonce }); return tx.hash; } async function sendDirect(fromKey:string, to: string, amount: string,nonce: number) : Promise { const wallet = new Wallet(fromKey); const sender = wallet.address; // const nonce = await provider.getTransactionCount(sender); // console.log(`block nonce = ${nonce}`); const tx = { to: to, value: parseEther(amount.toString()), //gasPrice: 0, //gasPrice: gas, gasLimit: 21000, //21000으로 고정권장(너무 높으면 속도가 느려짐) //gasLimit: gasLimit, // maxPriorityFeePerGas: parseUnits("5", "gwei"), // maxFeePerGas: parseUnits("20", "gwei"), nonce: nonce, type: 2, chainId: 1337, // Corresponds to ETH_GOERLI }; const signed = await wallet.signTransaction(tx); const txid = await provider.send('eth_sendRawTransaction',[signed]); return txid; } async function getBalance(addr: string): Promise { const wallet = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3', provider); const balance = await provider.getBalance(addr); return formatEther(balance); } async function getNonce(addr: string): Promise { const nonce = await provider.getTransactionCount(addr); return nonce; } async function send() { let to = '0xfe3b557e8fb62b89f4916b721be55ceb828dbd73'; let from = '0x627306090abaB3A6e1400e9345bC60c78a8BEf57'; let fromKey = '0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3'; let nonce = await getNonce(from); let txids = []; const count = 1; let startTime = 0; for(let i = 0; i < count; i++) { let txid = await sendDirect(fromKey,to,'0.1',nonce++); // start time setting if(i == 0) { startTime = Date.now(); } // console.log(txid); txids.push({txid}); } // let txid = await sendTx(to,'0.1',nonce++); await checkReceipt(txids, 'check receipt....'); let tx = await provider.send('eth_getTransactionByHash',[txids[0].txid]); const firstBlock = await provider.getBlock(tx.blockNumber); // console.log(firstBlock); tx = await provider.send('eth_getTransactionByHash',[txids[count-1].txid]); const lastBlock = await provider.getBlock(tx.blockNumber); // console.log(lastBlock); console.log(startTime); console.log(firstBlock.timestamp); console.log(lastBlock.timestamp); // let balance= await getBalance(to); // console.log(balance); } const calc = new Calulator(); async function prepareToken(contractOwner: Wallet | HardhatEthersSigner, issuer: Wallet | HardhatEthersSigner, holder1: string, holder2: string) { const deployed = require('../security_token_deployments.json'); const tokenService = new TokenIssuer(contractOwner as Wallet,deployed.tokenBeacon,deployed.rulesBeacon,contractOwner.address); const proxy = await tokenService.deploy('테스트토큰','st0015',6,100000,issuer.address); console.log(`new token deployed at ${proxy}`); const token = new SecurityToken__factory(contractOwner).attach(proxy) as SecurityToken; //token.connect(contractOwner); console.log(await token.name()); console.log(await token.symbol()); console.log(await token.maxSupply()); const tokenForIssuer = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken; await tokenForIssuer.connect(issuer); let r = await tokenForIssuer.KYCtokenHolders([holder1]); await tokenForIssuer.KYCtokenHolders([holder2]); let txids = []; txids.push({txid: r.hash}); await checkReceipt(txids, 'wait for transaction confirmed'); const b = await tokenForIssuer.isTokenHolderKYC(holder1); if(!b) { console.log('holder kyc error'); return; } await tokenForIssuer.issue(holder1,10_000n,ZeroHash); r = await tokenForIssuer.issue(holder2,5000,ZeroHash); txids = []; txids.push({txid: r.hash}); await checkReceipt(txids, 'wait for transaction confirmed'); let balance = await tokenForIssuer.balanceOf(holder1); console.log(`holder1's balance = ${balance}`); balance = await tokenForIssuer.balanceOf(holder2); console.log(`holder2's balance = ${balance}`); console.log('TestData created!'); } const rpcUrl = process.env.RPCURL; const provider = new JsonRpcProvider(rpcUrl); async function main() { setProvider(provider); const admin = await ethers.provider.getSigner(0); const issuer = await ethers.provider.getSigner(1); const holder1 = await ethers.provider.getSigner(2); const holder2 = await ethers.provider.getSigner(3); await prepareToken(admin, issuer, holder1.address, holder2.address); // await test('0x1411CB266FCEd1587b0AA29E9d5a9Ef3Db64A9C5'); } main();