| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- //
-
- import {toUtf8String,parseUnits,ContractFactory, parseEther,JsonRpcProvider, ethers ,Contract, JsonRpcSigner, Wallet,ContractTransactionResponse, MaxInt256
- ,Transaction,formatEther,
- decodeBase64
- } from 'ethers'
- import { connect } from 'http2';
-
- const PF_TOKEN_ABI = [
- "function mint(address to, uint256 amount) external",
- "function transfer(address to, uint256 amount) external returns (bool)",
- "function batchMint(address[] calldata recipients, uint256[] calldata amounts) external",
- "function balanceOf(address account) external view returns (uint256)",
- "function totalSupply() external view returns (uint256)",
- "function name() external view returns (string)",
- "function symbol() external view returns (string)",
- "function decimals() external view returns (uint8)",
- "function hasRole(bytes32 role, address account) external view returns (bool)",
- "event TokensMinted(address indexed to, uint256 amount, address indexed minter)",
-
- "function recordInterestPayment(uint256 amount) external",
- ];
-
- const SHS_ADDRESS="0x306f182eEdfe85d61aC2eA88acE58f565edf3DFe";
- const SHS_PRIVATE_KEY="0x3221ea02f27a2929f3a7ec75f5cac6f8207eb910a66f7e31d6391143dfbef5bf";
- const MASSET_ADDESS="0xDfc4dB2811a325DDd296C55D7A4055eD3bdB391D";
- const MASSET_PRIVATE_KEY="0x920a8a7f062b2f31da7bea211af1a5c0adb316e32301040c19d1d3748d6b7ab0";
-
-
- //TR_A
- // export const SPF_CONTRACT_ADDRESS =
- // "0x4e4637E3199E8a11a6dDafF64F1DCc8c7C2Aab36"; // sPF 주소
- // export const SPF_CONTRACT_ADDRESS =
- // "0x3B24bfdD5D52d4b25EE5812F35334A831ecA553d"; // sPF 주소 (이자함수포함)
-
-
- //TR_B
- // export const SPF_CONTRACT_ADDRESS =
- // "0xa1b2A55AEaEf5093fc9b04438Dc194C3B631f118"; // sPF 주소
- export const SPF_CONTRACT_ADDRESS =
- "0xaB72Fe1511ac371E369DFf3B0f6Bba23198baFD2"; // sPF 주소 (이자함수포함)
-
-
- const PULSE_RPC_URL = "https://secuchain.testnet.stopulse.co.kr/";
-
-
- // export const SOL_ADDRESS = "0x8DFeB78ecEe391149b1c2739cEd0f6992D0a5663";
- // const PRIVATE_KEY =
- // "0x47c496fe62e38aebcf4c5298cdae6889efed27b308fb473311d4a209e512f20e";
-
- const PULSE_PRIVATE_KEY =
- "0xcd2336d7c471a0f2f1da77e91bcaf71e96e40481415bdb062152b4d045e1702c";
-
- const provider = new ethers.JsonRpcProvider(PULSE_RPC_URL);
- const wallet = new ethers.Wallet(SHS_PRIVATE_KEY, provider);
- const wallet2 = new ethers.Wallet(MASSET_PRIVATE_KEY, provider);
- const walletAdmin = new ethers.Wallet(PULSE_PRIVATE_KEY, provider);
-
- const contractAdmin = new ethers.Contract(
- SPF_CONTRACT_ADDRESS,
- PF_TOKEN_ABI,
- walletAdmin
- );
- const contract = new ethers.Contract(
- SPF_CONTRACT_ADDRESS,
- PF_TOKEN_ABI,
- wallet
- );
-
-
- function getNewPrivateKey(){
- const newWallet = ethers.Wallet.createRandom();
- const wallet = new ethers.Wallet(newWallet.privateKey, provider);
-
- console.log(newWallet.address);
- console.log(newWallet.privateKey);
- return newWallet.privateKey;
- }
- async function setup() {
-
- // await mintToAddress(SHS_ADDRESS, "30000000000");
- await mintToAddress(MASSET_ADDESS, "16000000000");
-
- }
-
-
-
- async function view() {
- // const precision = await mmfToken.getNAVPrecision();
- const precision = await contract.getNAVPrecision();
- console.log(precision.toString());
-
-
- const currentNAV = await contract.currentNAV();
- console.log(currentNAV.toString());
-
- const balance = await contract.balanceOf(SHS_ADDRESS);
-
- console.log(`balance = ${balance.toString()}}`);
- }
-
-
-
- /**
- * 특정 주소에 원하는 만큼 SPF 토큰을 minting하는 함수
- * @param toAddress - 토큰을 받을 주소
- * @param amount - minting할 토큰 양 (ether 단위)
- */
- async function mintToAddress(toAddress: string, amount: string) {
- console.log(`Minting ${amount} SPF tokens to ${toAddress}...`);
-
- const tx = await contractAdmin.mint(
- toAddress,
- ethers.parseEther(amount),
- {
- gasLimit: 500000,
- gasPrice: 0,
- }
- );
-
- await tx.wait(1);
- console.log(`Successfully minted ${amount} SPF tokens to ${toAddress}`);
-
- // 잔액 확인
- const balance = await contractAdmin.balanceOf(toAddress);
- console.log(`New balance: ${ethers.formatEther(balance)} SPF`);
- }
-
- /**
- * 특정 주소의 SPF 토큰을 burn하는 함수 (dead address로 전송)
- * @param fromAddress - 토큰을 burn할 주소 (이 주소의 private key를 가진 wallet 필요)
- * @param amount - burn할 토큰 양 (ether 단위)
- * @param privateKey - fromAddress의 private key
- */
- async function burnFromAddress(fromAddress: string, amount: string, privateKey: string) {
- const DEAD_ADDRESS = "0x000000000000000000000000000000000000dEaD";
- console.log(`Burning ${amount} SPF tokens from ${fromAddress} to dead address...`);
-
- // burn할 주소의 wallet 생성
- const burnerWallet = new ethers.Wallet(privateKey, provider);
- const burnerContract = new ethers.Contract(
- SPF_CONTRACT_ADDRESS,
- PF_TOKEN_ABI,
- burnerWallet
- );
-
- const tx = await burnerContract.transfer(
- DEAD_ADDRESS,
- ethers.parseEther(amount),
- {
- gasLimit: 500000,
- gasPrice: 0,
- }
- );
-
- await tx.wait(1);
- console.log(`Successfully burned ${amount} SPF tokens from ${fromAddress}`);
-
- // 잔액 확인
- const balance = await burnerContract.balanceOf(fromAddress);
- console.log(`Remaining balance: ${ethers.formatEther(balance)} SPF`);
- }
-
- /**
- * SPF 토큰을 특정 주소에서 다른 주소로 전송하는 함수
- * @param fromAddress - 토큰을 보낼 주소
- * @param toAddress - 토큰을 받을 주소
- * @param amount - 전송할 토큰 양 (ether 단위)
- * @param privateKey - fromAddress의 private key
- */
- async function transferToken(fromAddress: string, toAddress: string, amount: string, privateKey: string) {
- console.log(`Transferring ${amount} SPF tokens from ${fromAddress} to ${toAddress}...`);
-
- // 전송할 주소의 wallet 생성
- const senderWallet = new ethers.Wallet(privateKey, provider);
- const senderContract = new ethers.Contract(
- SPF_CONTRACT_ADDRESS,
- PF_TOKEN_ABI,
- senderWallet
- );
-
- // 전송 전 잔액 확인
- const beforeBalance = await senderContract.balanceOf(fromAddress);
- console.log(`Current balance: ${ethers.formatEther(beforeBalance)} SPF`);
-
- const amountWei = ethers.parseEther(amount);
-
- if (beforeBalance < amountWei) {
- throw new Error(`Insufficient balance. Have: ${ethers.formatEther(beforeBalance)} SPF, Need: ${amount} SPF`);
- }
-
- const tx = await senderContract.transfer(
- toAddress,
- amountWei,
- {
- gasLimit: 500000,
- gasPrice: 0,
- }
- );
-
- await tx.wait(1);
- console.log(`Successfully transferred ${amount} SPF tokens from ${fromAddress} to ${toAddress}`);
-
- // 양쪽 주소의 잔액 확인
- const fromBalance = await senderContract.balanceOf(fromAddress);
- const toBalance = await senderContract.balanceOf(toAddress);
- console.log(`From address balance: ${ethers.formatEther(fromBalance)} SPF`);
- console.log(`To address balance: ${ethers.formatEther(toBalance)} SPF`);
- }
-
- async function recordInterestPayment(amount: string) {
- console.log(`Recording interest payment of ${amount} SPF...`);
-
- console.log(`payInterest of ${amount} ...`);
-
- const tx = await contractAdmin.recordInterestPayment(
- ethers.parseEther(amount),
- {
- gasLimit: 500000,
- gasPrice: 0,
- }
- );
-
- await tx.wait(1);
- console.log(`Successfully payed ${amount} of interests`);
-
- }
-
- async function main() {
-
- // recordInterestPayment("750000000");
-
- // recordInterestPayment("1200000000");
-
- // await setup();
-
- // await transferToken(SHS_ADDRESS,MASSET_ADDESS,"300000",SHS_PRIVATE_KEY);
-
- //await setNav();
- // await view();
-
- // getNewPrivateKey();
- // getNewPrivateKey();
-
- }
-
-
-
- main();
|