您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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,id
  5. } from 'ethers'
  6. import chalk from "chalk";
  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,checkReceipt2, setProvider,getDeploymentAddresses,
  15. getElapsed, sleep,getBlockInfo} from '../inc/util'
  16. import { sign } from "crypto";
  17. dotevnv.config();
  18. if (!process.env.RPCURL) {
  19. console.log(`No rpcur value specified...`)
  20. }
  21. console.log(`목적 서버 : ${process.env.RPCURL}`);
  22. async function getNonce(addr: string): Promise<number> {
  23. const nonce = await provider.getTransactionCount(addr);
  24. return nonce;
  25. }
  26. async function getTransferData(symbol:string,from: Wallet, to: Wallet, amount: number = 1): Promise<any> {
  27. const proxy = getDeploymentAddresses(symbol).address;
  28. console.log(`토큰 주소 : ${proxy}`);
  29. const token = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken;
  30. const partitions = await token.getDefaultPartitions();
  31. let nonce = await getNonce(signer.address);
  32. const tx = await token.operatorTransferByPartition.populateTransaction(
  33. partitions[0],
  34. from.address,
  35. to.address,
  36. amount,
  37. ZeroHash,
  38. ZeroHash,
  39. {
  40. // gasPrice: 0,
  41. gasLimit: 2100000,
  42. nonce: nonce,
  43. type: 2,
  44. chainId: 1337
  45. }
  46. );
  47. const signed = await signer.signTransaction(tx);
  48. return signed;
  49. }
  50. async function getOperatorGrantData(symbol:string,signer:Wallet,tobeOperator: Wallet): Promise<any> {
  51. const proxy = getDeploymentAddresses(symbol).address;
  52. console.log(`토큰 주소 : ${proxy}`);
  53. let nonce = await getNonce(signer.address);
  54. const token = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken;
  55. const tx = await token.grantRole.populateTransaction(
  56. id('OPERATOR_ROLE'),tobeOperator,
  57. {
  58. gasLimit: 2100000,
  59. nonce: nonce,
  60. type: 2,
  61. chainId: 1337
  62. }
  63. );
  64. const signed = await signer.signTransaction(tx);
  65. return signed;
  66. }
  67. async function revokeOperator(symbol: string, address: string): Promise<any> {
  68. const proxy = getDeploymentAddresses(symbol).address;
  69. console.log(`토큰 주소 : ${proxy}`);
  70. let nonce = await getNonce(signer.address);
  71. const token = new SecurityToken__factory(admin).attach(proxy) as SecurityToken;
  72. console.log('....');
  73. const ret = await token.revokeRole( id('OPERATOR_ROLE'),address,{ gasLimit: 20000000});
  74. await ret.wait();
  75. console.log(`operator ${address} revoked..`)
  76. }
  77. async function printOperator(symbol: string) {
  78. const proxy = getDeploymentAddresses(symbol).address;
  79. console.log(`토큰 주소 : ${proxy}`);
  80. const token = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken;
  81. console.log(chalk.green('등록된 오퍼레이터 목록'));
  82. const ops = await token.operators();
  83. console.log(ops);
  84. }
  85. const calc = new Calulator();
  86. const rpcUrl = process.env.RPCURL;
  87. const provider = new JsonRpcProvider(rpcUrl);
  88. setProvider(provider);
  89. const admin = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',provider);
  90. const issuer = new Wallet('0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63',provider);
  91. // const signer = new Wallet('0x55d1000aa2057a878b5f7902158615f889cb1e9b811f7e1e9c0b4518399ba84a',provider);
  92. const signer = issuer;
  93. const holder1 = new Wallet('0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f',provider);
  94. const holder2 = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',provider);
  95. async function main() {
  96. console.log(admin.address);
  97. console.log(issuer.address);
  98. console.log(holder1.address);
  99. console.log(holder2.address);
  100. // 전송데이타 생성
  101. // const tx = await getTransferData('test001',holder2, holder1,1);
  102. // console.log(tx);
  103. console.log('holder2를 오퍼레이터로 등록하는 txData');
  104. const tx = await getOperatorGrantData('test001',admin,holder2);
  105. console.log(tx);
  106. // await revokeOperator('test001',holder2.address);
  107. // await printOperator('test001');
  108. }
  109. main();