| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- import * as dotevnv from "dotenv"
- import {toUtf8String,parseUnits,ContractFactory, parseEther,JsonRpcProvider, Contract, JsonRpcSigner, Wallet,ContractTransactionResponse, MaxInt256
- ,Transaction,formatEther,
- ZeroHash,ethers,keccak256,id
- } from 'ethers'
- import chalk from "chalk";
- 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,checkReceipt2, setProvider,getDeploymentAddresses,
- getElapsed, sleep,getBlockInfo} from '../inc/util'
- import { sign } from "crypto";
- dotevnv.config();
- if (!process.env.RPCURL) {
- console.log(`No rpcur value specified...`)
- }
-
-
- console.log(`목적 서버 : ${process.env.RPCURL}`);
-
- async function getNonce(addr: string): Promise<number> {
- const nonce = await provider.getTransactionCount(addr);
- return nonce;
- }
-
-
- async function getTransferData(symbol:string,from: Wallet, to: Wallet, amount: number = 1): Promise<any> {
- const proxy = getDeploymentAddresses(symbol).address;
- console.log(`토큰 주소 : ${proxy}`);
- const token = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken;
- const partitions = await token.getDefaultPartitions();
- let nonce = await getNonce(signer.address);
- const tx = await token.operatorTransferByPartition.populateTransaction(
- partitions[0],
- from.address,
- to.address,
- amount,
- ZeroHash,
- ZeroHash,
- {
- // gasPrice: 0,
- gasLimit: 2100000,
- nonce: nonce,
- type: 2,
- chainId: 1337
- }
- );
- const signed = await signer.signTransaction(tx);
- return signed;
- }
-
- async function getOperatorGrantData(symbol:string,signer:Wallet,tobeOperator: Wallet): Promise<any> {
- const proxy = getDeploymentAddresses(symbol).address;
- console.log(`토큰 주소 : ${proxy}`);
- let nonce = await getNonce(signer.address);
- const token = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken;
- const tx = await token.grantRole.populateTransaction(
- id('OPERATOR_ROLE'),tobeOperator,
- {
- gasLimit: 2100000,
- nonce: nonce,
- type: 2,
- chainId: 1337
- }
- );
- const signed = await signer.signTransaction(tx);
- return signed;
- }
-
- async function revokeOperator(symbol: string, address: string): Promise<any> {
-
- const proxy = getDeploymentAddresses(symbol).address;
- console.log(`토큰 주소 : ${proxy}`);
- let nonce = await getNonce(signer.address);
- const token = new SecurityToken__factory(admin).attach(proxy) as SecurityToken;
-
- console.log('....');
- const ret = await token.revokeRole( id('OPERATOR_ROLE'),address,{ gasLimit: 20000000});
- await ret.wait();
- console.log(`operator ${address} revoked..`)
-
- }
-
- async function printOperator(symbol: string) {
- const proxy = getDeploymentAddresses(symbol).address;
- console.log(`토큰 주소 : ${proxy}`);
- const token = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken;
-
- console.log(chalk.green('등록된 오퍼레이터 목록'));
- const ops = await token.operators();
- console.log(ops);
- }
-
- const calc = new Calulator();
- const rpcUrl = process.env.RPCURL;
- const provider = new JsonRpcProvider(rpcUrl);
- setProvider(provider);
-
- const admin = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',provider);
- const issuer = new Wallet('0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63',provider);
- // const signer = new Wallet('0x55d1000aa2057a878b5f7902158615f889cb1e9b811f7e1e9c0b4518399ba84a',provider);
- const signer = issuer;
- const holder1 = new Wallet('0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f',provider);
- const holder2 = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',provider);
-
- async function main() {
-
- console.log(admin.address);
- console.log(issuer.address);
- console.log(holder1.address);
- console.log(holder2.address);
-
- // 전송데이타 생성
- // const tx = await getTransferData('test001',holder2, holder1,1);
- // console.log(tx);
-
- console.log('holder2를 오퍼레이터로 등록하는 txData');
- const tx = await getOperatorGrantData('test001',admin,holder2);
- console.log(tx);
-
- // await revokeOperator('test001',holder2.address);
- // await printOperator('test001');
- }
-
- main();
|