|
|
|
@@ -1,179 +1,177 @@ |
|
|
|
import * as dotevnv from "dotenv" |
|
|
|
import {toUtf8String,parseUnits,ContractFactory, parseEther,JsonRpcProvider, Contract, JsonRpcSigner, Wallet,ContractTransactionResponse, MaxInt256 |
|
|
|
,Transaction,formatEther, |
|
|
|
ZeroHash |
|
|
|
ZeroHash,ethers,keccak256 |
|
|
|
} from 'ethers' |
|
|
|
import {ethers} from 'hardhat'; |
|
|
|
import {Calulator} from "../inc/calc"; |
|
|
|
import { TokenIssuer } from "../inc/TokenIssuer"; |
|
|
|
import axios from "axios"; |
|
|
|
|
|
|
|
import { |
|
|
|
SecurityToken, |
|
|
|
SecurityToken__factory, |
|
|
|
} from '../typechain' |
|
|
|
import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers"; |
|
|
|
import {checkReceipt, setProvider} from '../inc/util' |
|
|
|
|
|
|
|
// import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers"; |
|
|
|
import {checkReceipt,checkReceipt2, setProvider,getDeploymentAddresses, |
|
|
|
getElapsed, sleep,getBlockInfo} 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<string> { |
|
|
|
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<string> { |
|
|
|
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<string> { |
|
|
|
const wallet = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3', provider); |
|
|
|
|
|
|
|
const balance = await provider.getBalance(addr); |
|
|
|
return formatEther(balance); |
|
|
|
} |
|
|
|
console.log(`목적 서버 : ${process.env.RPCURL}`); |
|
|
|
|
|
|
|
async function getNonce(addr: string): Promise<number> { |
|
|
|
const nonce = await provider.getTransactionCount(addr); |
|
|
|
return nonce; |
|
|
|
} |
|
|
|
|
|
|
|
async function info(symbol: string) { |
|
|
|
const proxy = getDeploymentAddresses(symbol).address; |
|
|
|
console.log(`토큰 주소 : ${proxy}`); |
|
|
|
|
|
|
|
const token = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken; |
|
|
|
await token.connect(admin); |
|
|
|
const ops = await token.operators(); |
|
|
|
console.log(ops); |
|
|
|
|
|
|
|
async function send() { |
|
|
|
let to = '0xfe3b557e8fb62b89f4916b721be55ceb828dbd73'; |
|
|
|
let from = '0x627306090abaB3A6e1400e9345bC60c78a8BEf57'; |
|
|
|
let fromKey = '0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3'; |
|
|
|
|
|
|
|
let nonce = await getNonce(from); |
|
|
|
let txids = []; |
|
|
|
const balance = await token.balanceOf(firstHolder); |
|
|
|
console.log(`initial balance = ${balance}`); |
|
|
|
|
|
|
|
const count = 1; |
|
|
|
let startTime = 0; |
|
|
|
let b = await token.isTokenHolderKYC('0x2071ec931b2567a1418e9bc34b786d654a079b43'); |
|
|
|
if(!b) { |
|
|
|
console.log('kyc check first!'); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
for(let i = 0; i < count; i++) { |
|
|
|
let txid = await sendDirect(fromKey,to,'0.1',nonce++); |
|
|
|
await token.KYCtokenHolders([holder1.address,holder2.address]); |
|
|
|
|
|
|
|
// start time setting |
|
|
|
if(i == 0) { |
|
|
|
startTime = Date.now(); |
|
|
|
} |
|
|
|
// console.log(txid); |
|
|
|
txids.push({txid}); |
|
|
|
b = await token.isTokenHolderKYC(holder1.address); |
|
|
|
if(!b) { |
|
|
|
console.log('kyc check first!'); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 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); |
|
|
|
// token.grantRole(keccak256('OPERATOR_ROLE'),'0xaaa') |
|
|
|
} |
|
|
|
|
|
|
|
function getAuthHeader(token: string) : any{ |
|
|
|
return { |
|
|
|
headers: { |
|
|
|
'Content-Type': 'application/json;charset=UTF-8', |
|
|
|
'Access-Control-Allow-Origin': '*', |
|
|
|
'Authorization': `Bearer ${token}` |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
tx = await provider.send('eth_getTransactionByHash',[txids[count-1].txid]); |
|
|
|
const lastBlock = await provider.getBlock(tx.blockNumber); |
|
|
|
// console.log(lastBlock); |
|
|
|
async function getTx(signerAddress:string, tokenSymbol: string, from: string, to: string, value: number) : Promise<any> { |
|
|
|
const path = 'transfer/tx/data'; |
|
|
|
|
|
|
|
const ret = await axios.post(gateWay + path, { |
|
|
|
signerAddress, |
|
|
|
tokenSymbol, |
|
|
|
transfers : [{ |
|
|
|
partitionName:'초기', |
|
|
|
from, |
|
|
|
to, |
|
|
|
value, |
|
|
|
data:'0x0000000000000000000000000000000000000000000000000000000000000000', |
|
|
|
operatorData:'0x0000000000000000000000000000000000000000000000000000000000000000' |
|
|
|
}] |
|
|
|
},getAuthHeader(authToken)); |
|
|
|
// console.log(ret); |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
console.log(startTime); |
|
|
|
console.log(firstBlock.timestamp); |
|
|
|
console.log(lastBlock.timestamp); |
|
|
|
async function send(signedTransaction: string) { |
|
|
|
const path = 'transaction/send'; |
|
|
|
const ret = await axios.post(gateWay + path, { |
|
|
|
signedTransaction |
|
|
|
},getAuthHeader(authToken)); |
|
|
|
|
|
|
|
// let balance= await getBalance(to); |
|
|
|
// console.log(balance); |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
const calc = new Calulator(); |
|
|
|
async function getTx2(symbol: string, from: string, to: string, amount: number,nonce: number) { |
|
|
|
const proxy = getDeploymentAddresses(symbol).address; |
|
|
|
console.log(`토큰 주소 : ${proxy}`); |
|
|
|
const token = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken; |
|
|
|
await token.connect(admin); |
|
|
|
|
|
|
|
const partitions = await token.getDefaultPartitions(); |
|
|
|
console.log(partitions); |
|
|
|
|
|
|
|
const tx = await token.operatorTransferByPartition.populateTransaction( |
|
|
|
partitions[0], |
|
|
|
from, |
|
|
|
to, |
|
|
|
amount, |
|
|
|
ZeroHash, |
|
|
|
ZeroHash, |
|
|
|
{ |
|
|
|
// gasPrice: 0, |
|
|
|
gasLimit: 2100000, |
|
|
|
nonce: nonce, |
|
|
|
type: 2, |
|
|
|
chainId: 1337 |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
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); |
|
|
|
return tx; |
|
|
|
} |
|
|
|
|
|
|
|
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); |
|
|
|
async function transfer(symbol:string,from: Wallet, to: Wallet, amount: number = 1, count: number = 10) { |
|
|
|
const proxy = getDeploymentAddresses(symbol).address; |
|
|
|
console.log(`토큰 주소 : ${proxy}`); |
|
|
|
|
|
|
|
const token = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken; |
|
|
|
await token.connect(admin); |
|
|
|
const ops = await token.operators(); |
|
|
|
console.log(ops); |
|
|
|
|
|
|
|
txids = []; |
|
|
|
txids.push({txid: r.hash}); |
|
|
|
await checkReceipt(txids, 'wait for transaction confirmed'); |
|
|
|
const balance = await token.balanceOf(firstHolder); |
|
|
|
console.log(balance); |
|
|
|
|
|
|
|
let balance = await tokenForIssuer.balanceOf(holder1); |
|
|
|
console.log(`holder1's balance = ${balance}`); |
|
|
|
|
|
|
|
balance = await tokenForIssuer.balanceOf(holder2); |
|
|
|
console.log(`holder2's balance = ${balance}`); |
|
|
|
const tx = await getTx(signer.address,symbol,firstHolder,holder1.address,1); |
|
|
|
|
|
|
|
console.log(tx.data); |
|
|
|
const signed = await signer.signTransaction(tx.data); |
|
|
|
console.log(signed); |
|
|
|
//const txid = await send(signed); |
|
|
|
|
|
|
|
console.log('TestData created!'); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const firstHolder = '0x2071ec931b2567a1418e9bc34b786d654a079b43'; |
|
|
|
const calc = new Calulator(); |
|
|
|
const rpcUrl = process.env.RPCURL; |
|
|
|
const gateWay = process.env.GATE_WAY; |
|
|
|
const authToken=process.env.AUTHTOKEN; |
|
|
|
const provider = new JsonRpcProvider(rpcUrl); |
|
|
|
setProvider(provider); |
|
|
|
|
|
|
|
|
|
|
|
const admin = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',provider); |
|
|
|
const issuer = new Wallet('0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63',provider); |
|
|
|
const holder1 = new Wallet('0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f',provider); |
|
|
|
const holder2 = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',provider); |
|
|
|
const signer = holder1; |
|
|
|
|
|
|
|
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'); |
|
|
|
|
|
|
|
console.log(admin); |
|
|
|
console.log(issuer); |
|
|
|
console.log(holder1); |
|
|
|
console.log(holder2); |
|
|
|
|
|
|
|
transfer('BCG_TEST',holder1, holder2,1, 2000); |
|
|
|
// info('BCG_TEST'); |
|
|
|
// getTx('0xf17f52151EbEF6C7334FAD080c5704D77216b732','BCG_TEST','0x2071ec931b2567a1418e9bc34b786d654a079b43',holder1.address,1); |
|
|
|
// getTx2('BCG_TEST'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
main(); |
|
|
|
|
|
|
|
|