Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. //
  2. import {toUtf8String,parseUnits,ContractFactory, parseEther,JsonRpcProvider, ethers ,Contract, JsonRpcSigner, Wallet,ContractTransactionResponse, MaxInt256
  3. ,Transaction,formatEther,
  4. decodeBase64
  5. } from 'ethers'
  6. import { connect } from 'http2';
  7. const PF_TOKEN_ABI = [
  8. "function mint(address to, uint256 amount) external",
  9. "function transfer(address to, uint256 amount) external returns (bool)",
  10. "function batchMint(address[] calldata recipients, uint256[] calldata amounts) external",
  11. "function balanceOf(address account) external view returns (uint256)",
  12. "function totalSupply() external view returns (uint256)",
  13. "function name() external view returns (string)",
  14. "function symbol() external view returns (string)",
  15. "function decimals() external view returns (uint8)",
  16. "function hasRole(bytes32 role, address account) external view returns (bool)",
  17. "event TokensMinted(address indexed to, uint256 amount, address indexed minter)",
  18. "function recordInterestPayment(uint256 amount) external",
  19. ];
  20. const SHS_ADDRESS="0x306f182eEdfe85d61aC2eA88acE58f565edf3DFe";
  21. const SHS_PRIVATE_KEY="0x3221ea02f27a2929f3a7ec75f5cac6f8207eb910a66f7e31d6391143dfbef5bf";
  22. const MASSET_ADDESS="0xDfc4dB2811a325DDd296C55D7A4055eD3bdB391D";
  23. const MASSET_PRIVATE_KEY="0x920a8a7f062b2f31da7bea211af1a5c0adb316e32301040c19d1d3748d6b7ab0";
  24. //TR_A
  25. // export const SPF_CONTRACT_ADDRESS =
  26. // "0x4e4637E3199E8a11a6dDafF64F1DCc8c7C2Aab36"; // sPF 주소
  27. // export const SPF_CONTRACT_ADDRESS =
  28. // "0x3B24bfdD5D52d4b25EE5812F35334A831ecA553d"; // sPF 주소 (이자함수포함)
  29. //TR_B
  30. // export const SPF_CONTRACT_ADDRESS =
  31. // "0xa1b2A55AEaEf5093fc9b04438Dc194C3B631f118"; // sPF 주소
  32. export const SPF_CONTRACT_ADDRESS =
  33. "0xaB72Fe1511ac371E369DFf3B0f6Bba23198baFD2"; // sPF 주소 (이자함수포함)
  34. const PULSE_RPC_URL = "https://secuchain.testnet.stopulse.co.kr/";
  35. // export const SOL_ADDRESS = "0x8DFeB78ecEe391149b1c2739cEd0f6992D0a5663";
  36. // const PRIVATE_KEY =
  37. // "0x47c496fe62e38aebcf4c5298cdae6889efed27b308fb473311d4a209e512f20e";
  38. const PULSE_PRIVATE_KEY =
  39. "0xcd2336d7c471a0f2f1da77e91bcaf71e96e40481415bdb062152b4d045e1702c";
  40. const provider = new ethers.JsonRpcProvider(PULSE_RPC_URL);
  41. const wallet = new ethers.Wallet(SHS_PRIVATE_KEY, provider);
  42. const wallet2 = new ethers.Wallet(MASSET_PRIVATE_KEY, provider);
  43. const walletAdmin = new ethers.Wallet(PULSE_PRIVATE_KEY, provider);
  44. const contractAdmin = new ethers.Contract(
  45. SPF_CONTRACT_ADDRESS,
  46. PF_TOKEN_ABI,
  47. walletAdmin
  48. );
  49. const contract = new ethers.Contract(
  50. SPF_CONTRACT_ADDRESS,
  51. PF_TOKEN_ABI,
  52. wallet
  53. );
  54. function getNewPrivateKey(){
  55. const newWallet = ethers.Wallet.createRandom();
  56. const wallet = new ethers.Wallet(newWallet.privateKey, provider);
  57. console.log(newWallet.address);
  58. console.log(newWallet.privateKey);
  59. return newWallet.privateKey;
  60. }
  61. async function setup() {
  62. // await mintToAddress(SHS_ADDRESS, "30000000000");
  63. await mintToAddress(MASSET_ADDESS, "16000000000");
  64. }
  65. async function view() {
  66. // const precision = await mmfToken.getNAVPrecision();
  67. const precision = await contract.getNAVPrecision();
  68. console.log(precision.toString());
  69. const currentNAV = await contract.currentNAV();
  70. console.log(currentNAV.toString());
  71. const balance = await contract.balanceOf(SHS_ADDRESS);
  72. console.log(`balance = ${balance.toString()}}`);
  73. }
  74. /**
  75. * 특정 주소에 원하는 만큼 SPF 토큰을 minting하는 함수
  76. * @param toAddress - 토큰을 받을 주소
  77. * @param amount - minting할 토큰 양 (ether 단위)
  78. */
  79. async function mintToAddress(toAddress: string, amount: string) {
  80. console.log(`Minting ${amount} SPF tokens to ${toAddress}...`);
  81. const tx = await contractAdmin.mint(
  82. toAddress,
  83. ethers.parseEther(amount),
  84. {
  85. gasLimit: 500000,
  86. gasPrice: 0,
  87. }
  88. );
  89. await tx.wait(1);
  90. console.log(`Successfully minted ${amount} SPF tokens to ${toAddress}`);
  91. // 잔액 확인
  92. const balance = await contractAdmin.balanceOf(toAddress);
  93. console.log(`New balance: ${ethers.formatEther(balance)} SPF`);
  94. }
  95. /**
  96. * 특정 주소의 SPF 토큰을 burn하는 함수 (dead address로 전송)
  97. * @param fromAddress - 토큰을 burn할 주소 (이 주소의 private key를 가진 wallet 필요)
  98. * @param amount - burn할 토큰 양 (ether 단위)
  99. * @param privateKey - fromAddress의 private key
  100. */
  101. async function burnFromAddress(fromAddress: string, amount: string, privateKey: string) {
  102. const DEAD_ADDRESS = "0x000000000000000000000000000000000000dEaD";
  103. console.log(`Burning ${amount} SPF tokens from ${fromAddress} to dead address...`);
  104. // burn할 주소의 wallet 생성
  105. const burnerWallet = new ethers.Wallet(privateKey, provider);
  106. const burnerContract = new ethers.Contract(
  107. SPF_CONTRACT_ADDRESS,
  108. PF_TOKEN_ABI,
  109. burnerWallet
  110. );
  111. const tx = await burnerContract.transfer(
  112. DEAD_ADDRESS,
  113. ethers.parseEther(amount),
  114. {
  115. gasLimit: 500000,
  116. gasPrice: 0,
  117. }
  118. );
  119. await tx.wait(1);
  120. console.log(`Successfully burned ${amount} SPF tokens from ${fromAddress}`);
  121. // 잔액 확인
  122. const balance = await burnerContract.balanceOf(fromAddress);
  123. console.log(`Remaining balance: ${ethers.formatEther(balance)} SPF`);
  124. }
  125. /**
  126. * SPF 토큰을 특정 주소에서 다른 주소로 전송하는 함수
  127. * @param fromAddress - 토큰을 보낼 주소
  128. * @param toAddress - 토큰을 받을 주소
  129. * @param amount - 전송할 토큰 양 (ether 단위)
  130. * @param privateKey - fromAddress의 private key
  131. */
  132. async function transferToken(fromAddress: string, toAddress: string, amount: string, privateKey: string) {
  133. console.log(`Transferring ${amount} SPF tokens from ${fromAddress} to ${toAddress}...`);
  134. // 전송할 주소의 wallet 생성
  135. const senderWallet = new ethers.Wallet(privateKey, provider);
  136. const senderContract = new ethers.Contract(
  137. SPF_CONTRACT_ADDRESS,
  138. PF_TOKEN_ABI,
  139. senderWallet
  140. );
  141. // 전송 전 잔액 확인
  142. const beforeBalance = await senderContract.balanceOf(fromAddress);
  143. console.log(`Current balance: ${ethers.formatEther(beforeBalance)} SPF`);
  144. const amountWei = ethers.parseEther(amount);
  145. if (beforeBalance < amountWei) {
  146. throw new Error(`Insufficient balance. Have: ${ethers.formatEther(beforeBalance)} SPF, Need: ${amount} SPF`);
  147. }
  148. const tx = await senderContract.transfer(
  149. toAddress,
  150. amountWei,
  151. {
  152. gasLimit: 500000,
  153. gasPrice: 0,
  154. }
  155. );
  156. await tx.wait(1);
  157. console.log(`Successfully transferred ${amount} SPF tokens from ${fromAddress} to ${toAddress}`);
  158. // 양쪽 주소의 잔액 확인
  159. const fromBalance = await senderContract.balanceOf(fromAddress);
  160. const toBalance = await senderContract.balanceOf(toAddress);
  161. console.log(`From address balance: ${ethers.formatEther(fromBalance)} SPF`);
  162. console.log(`To address balance: ${ethers.formatEther(toBalance)} SPF`);
  163. }
  164. async function recordInterestPayment(amount: string) {
  165. console.log(`Recording interest payment of ${amount} SPF...`);
  166. console.log(`payInterest of ${amount} ...`);
  167. const tx = await contractAdmin.recordInterestPayment(
  168. ethers.parseEther(amount),
  169. {
  170. gasLimit: 500000,
  171. gasPrice: 0,
  172. }
  173. );
  174. await tx.wait(1);
  175. console.log(`Successfully payed ${amount} of interests`);
  176. }
  177. async function main() {
  178. // recordInterestPayment("750000000");
  179. // recordInterestPayment("1200000000");
  180. // await setup();
  181. // await transferToken(SHS_ADDRESS,MASSET_ADDESS,"300000",SHS_PRIVATE_KEY);
  182. //await setNav();
  183. // await view();
  184. // getNewPrivateKey();
  185. // getNewPrivateKey();
  186. }
  187. main();