|
|
|
@@ -24,6 +24,8 @@ async function getNonce(addr: string): Promise<number> { |
|
|
|
return nonce; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function info(symbol: string) { |
|
|
|
const proxy = getDeploymentAddresses(symbol).address; |
|
|
|
console.log(`토큰 주소 : ${proxy}`); |
|
|
|
@@ -50,8 +52,6 @@ async function info(symbol: string) { |
|
|
|
console.log('kyc check first!'); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// token.grantRole(keccak256('OPERATOR_ROLE'),'0xaaa') |
|
|
|
} |
|
|
|
|
|
|
|
@@ -65,9 +65,14 @@ function getAuthHeader(token: string) : any{ |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
async function getBalance(symbol: string, address: string ): Promise<number> { |
|
|
|
const path = `holders/${address}/tokens/${symbol}/balance`; |
|
|
|
const ret = await axios.get(gateWay + path, getAuthHeader(authToken)); |
|
|
|
return ret.data; |
|
|
|
} |
|
|
|
|
|
|
|
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, |
|
|
|
@@ -80,7 +85,6 @@ async function getTx(signerAddress:string, tokenSymbol: string, from: string, to |
|
|
|
operatorData:'0x0000000000000000000000000000000000000000000000000000000000000000' |
|
|
|
}] |
|
|
|
},getAuthHeader(authToken)); |
|
|
|
// console.log(ret); |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
@@ -89,58 +93,43 @@ async function send(signedTransaction: string) { |
|
|
|
const ret = await axios.post(gateWay + path, { |
|
|
|
signedTransaction |
|
|
|
},getAuthHeader(authToken)); |
|
|
|
|
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
async function getTx2(symbol: string, from: string, to: string, amount: number,nonce: number) { |
|
|
|
async function transfer(signer: Wallet,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 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 |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
return tx; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function transfer(symbol:string,from: Wallet, to: Wallet, amount: number = 1, count: number = 10) { |
|
|
|
const proxy = getDeploymentAddresses(symbol).address; |
|
|
|
console.log(`토큰 주소 : ${proxy}`); |
|
|
|
let fb = await getBalance(symbol,from.address); |
|
|
|
let tb = await getBalance(symbol,to.address); |
|
|
|
console.log(`from balance before : ${fb}, to balance before : ${tb}`); |
|
|
|
|
|
|
|
const token = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken; |
|
|
|
await token.connect(admin); |
|
|
|
const ops = await token.operators(); |
|
|
|
console.log(ops); |
|
|
|
|
|
|
|
const balance = await token.balanceOf(firstHolder); |
|
|
|
console.log(balance); |
|
|
|
|
|
|
|
// const balance = await token.balanceOf(firstHolder); |
|
|
|
// console.log(balance); |
|
|
|
|
|
|
|
const tx = await getTx(signer.address,symbol,firstHolder,holder1.address,1); |
|
|
|
const decimals = await token.decimals(); |
|
|
|
const digit = 10 ** Number(decimals); |
|
|
|
|
|
|
|
console.log(tx.data); |
|
|
|
const signed = await signer.signTransaction(tx.data); |
|
|
|
console.log(signed); |
|
|
|
//const txid = await send(signed); |
|
|
|
const rawTx = await getTx(signer.address,symbol,firstHolder,to.address, amount * digit); |
|
|
|
const tx = Transaction.from(rawTx.data); |
|
|
|
|
|
|
|
console.log(tx.nonce); |
|
|
|
|
|
|
|
const signed = await signer.signTransaction(tx); |
|
|
|
const txid = await send(signed); |
|
|
|
console.log(txid); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fb = await getBalance(symbol,from.address); |
|
|
|
tb = await getBalance(symbol,to.address); |
|
|
|
console.log(`from balance before : ${fb}, to balance before : ${tb}`); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@@ -158,15 +147,15 @@ const admin = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9e |
|
|
|
const issuer = new Wallet('0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63',provider); |
|
|
|
const holder1 = new Wallet('0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f',provider); |
|
|
|
const holder2 = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',provider); |
|
|
|
const signer = holder1; |
|
|
|
// const signer = holder1; |
|
|
|
|
|
|
|
async function main() { |
|
|
|
console.log(admin); |
|
|
|
console.log(issuer); |
|
|
|
console.log(holder1); |
|
|
|
console.log(holder2); |
|
|
|
// console.log(admin); |
|
|
|
// console.log(issuer); |
|
|
|
// console.log(holder1); |
|
|
|
// console.log(holder2); |
|
|
|
|
|
|
|
transfer('BCG_TEST',holder1, holder2,1, 2000); |
|
|
|
transfer(holder1,'BCG_TEST',holder1, holder2,1, 10); |
|
|
|
// info('BCG_TEST'); |
|
|
|
// getTx('0xf17f52151EbEF6C7334FAD080c5704D77216b732','BCG_TEST','0x2071ec931b2567a1418e9bc34b786d654a079b43',holder1.address,1); |
|
|
|
// getTx2('BCG_TEST'); |