simon 1 rok temu
rodzic
commit
4fdfaaa1cd
6 zmienionych plików z 167 dodań i 128 usunięć
  1. 2
    1
      .env
  2. 3
    0
      BCG_TEST_deployments.json
  3. 124
    126
      TC2/start.ts
  4. 28
    1
      TC4/start.ts
  5. 1
    0
      package.json
  6. 9
    0
      yarn.lock

+ 2
- 1
.env Wyświetl plik

@@ -7,4 +7,5 @@
#OCI
RPCURL=http://193.123.252.127:80
CHAINID=1337

GATE_WAY=https://api.stopulse.co.kr/main/v1/
AUTHTOKEN=580c6006687220df84f83d7c345c00ad9829de0694bd00c09e211d8c810b7510

+ 3
- 0
BCG_TEST_deployments.json Wyświetl plik

@@ -0,0 +1,3 @@
{
"address": "0x42707a63160580896582e65703e0985d920f9ca6"
}

+ 124
- 126
TC2/start.ts Wyświetl plik

@@ -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();



+ 28
- 1
TC4/start.ts Wyświetl plik

@@ -25,6 +25,20 @@ async function getNonce(addr: string): Promise<number> {
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);

// token.grantRole(keccak256('OPERATOR_ROLE'),'0xaaa')
}

async function transfer(symbol:string,from: Wallet, to: Wallet, amount: number = 1, count: number = 10) {

const proxy = getDeploymentAddresses(symbol).address;
@@ -34,6 +48,7 @@ async function transfer(symbol:string,from: Wallet, to: Wallet, amount: number =

const token = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken;
await token.connect(admin);
// const ops = await token.operators();
// console.log(ops);
@@ -145,7 +160,19 @@ const holder1 = new Wallet('0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c
const holder2 = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',provider);

async function main() {
transfer('test001',holder1, holder2,1, 1000);


console.log(admin);
console.log(issuer);
console.log(holder1);
console.log(holder2);


// transfer('test001',holder2, holder1,1, 2000);

info('BCG_TEST');


// for(let i = 13489; i < 13492; i++ ) {
// try {
// await send(i);

+ 1
- 0
package.json Wyświetl plik

@@ -10,6 +10,7 @@
"license": "ISC",
"dependencies": {
"@types/node": "^22.9.0",
"axios": "^1.7.9",
"dotenv": "^16.4.5",
"ethers": "^6.13.4",
"hardhat-ethers": "^1.0.1",

+ 9
- 0
yarn.lock Wyświetl plik

@@ -1257,6 +1257,15 @@ axios@^1.6.7, axios@^1.7.2:
form-data "^4.0.0"
proxy-from-env "^1.1.0"

axios@^1.7.9:
version "1.7.9"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.9.tgz#d7d071380c132a24accda1b2cfc1535b79ec650a"
integrity sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==
dependencies:
follow-redirects "^1.15.6"
form-data "^4.0.0"
proxy-from-env "^1.1.0"

balanced-match@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"

Ładowanie…
Anuluj
Zapisz