Browse Source

优化合约

wkw 2 days ago
parent
commit
200935cabe
5 changed files with 1004 additions and 55 deletions
  1. 29 2
      src/pages/home/index.vue
  2. 1 1
      src/pages/trade/index.vue
  3. 385 0
      src/utils/abijson/bmabi.json
  4. 460 0
      src/utils/abijson/pub.json
  5. 129 52
      src/utils/web.js

+ 29 - 2
src/pages/home/index.vue

@@ -16,7 +16,7 @@
       <view class="home-code">
         <view class="home-url">
           <view class="url">http://www.wgt.cool</view>
-          <view class="btn">分享链接</view>
+          <view class="btn" @click="awardFun">分享链接</view>
         </view>
         <view class="code-img">
           <image src="@/static/image/test/code-img.png" mode="scaleToFill" />
@@ -86,6 +86,7 @@ import { ref, onMounted, reactive } from "vue";
 import Header from "@/components/Header";
 import { getCoinList } from "@/api/currency";
 import { matchList } from "@/api/game";
+import { getWalletAddress } from "@/utils/utils";
 import { useCounterStore } from "@/stores/counter";
 const Login = async () => {
   let res = await getCoinList();
@@ -105,7 +106,6 @@ counter.$patch({ count: counter.count + 1 });
 // 或使用 action 代替
 counter.increment();
 const title = ref("Hello");
-import { getWalletAddress } from "@/utils/utils";
 const star = ref(3);
 const count = ref(0);
 const address = ref("");
@@ -119,6 +119,33 @@ onMounted(async () => {
     address.value = "未连接钱包";
   }
 });
+
+
+
+
+
+import { WGTForToken,STTForToken,getBalance } from "@/utils/web.js";
+
+// 例子  存WGT或者STT
+const awardFun = async () => {
+  // const privateKey = window.android.getPrivateKey();//app
+  const privateKey = "0x4553077da5d773773dad0511c6e5d33142ae2c1bd05a3a8a4a7becbc0d23d9b5"; //h5
+  try {
+    const result = await WGTForToken(privateKey, 0.0012);
+    if (result.status === "success") {
+      console.log(result);
+    }else{
+      console.log(result);
+    }
+  } catch (error) {}
+
+  // try {
+  //   const balance = await getBalance(privateKey,'stt');
+  //   console.log(balance)
+  // }catch(error){
+
+  // }
+};
 </script>
   
   <style lang="scss" scoped>

+ 1 - 1
src/pages/trade/index.vue

@@ -158,7 +158,7 @@
               <view class="game-num-num">*.00</view>
             </view>
           </view>
-          <view class="game-item-btn">领取</view>
+          <view class="game-item-btn" @click="awardFun">领取</view>
         </view>
       </view>
     </view>

+ 385 - 0
src/utils/abijson/bmabi.json

@@ -0,0 +1,385 @@
+[
+    {
+        "inputs": [
+            {
+                "internalType": "contract IERC20",
+                "name": "token",
+                "type": "address"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amount",
+                "type": "uint256"
+            },
+            {
+                "internalType": "address",
+                "name": "to",
+                "type": "address"
+            }
+        ],
+        "name": "emergencyWithdraw",
+        "outputs": [],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "address",
+                "name": "_wgtToken",
+                "type": "address"
+            },
+            {
+                "internalType": "address",
+                "name": "_sttToken",
+                "type": "address"
+            },
+            {
+                "internalType": "address",
+                "name": "_targetContract",
+                "type": "address"
+            }
+        ],
+        "stateMutability": "nonpayable",
+        "type": "constructor"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "address",
+                "name": "owner",
+                "type": "address"
+            }
+        ],
+        "name": "OwnableInvalidOwner",
+        "type": "error"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "address",
+                "name": "account",
+                "type": "address"
+            }
+        ],
+        "name": "OwnableUnauthorizedAccount",
+        "type": "error"
+    },
+    {
+        "anonymous": false,
+        "inputs": [
+            {
+                "indexed": true,
+                "internalType": "address",
+                "name": "previousOwner",
+                "type": "address"
+            },
+            {
+                "indexed": true,
+                "internalType": "address",
+                "name": "newOwner",
+                "type": "address"
+            }
+        ],
+        "name": "OwnershipTransferred",
+        "type": "event"
+    },
+    {
+        "inputs": [],
+        "name": "pause",
+        "outputs": [],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "anonymous": false,
+        "inputs": [
+            {
+                "indexed": false,
+                "internalType": "address",
+                "name": "account",
+                "type": "address"
+            }
+        ],
+        "name": "Paused",
+        "type": "event"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "uint256",
+                "name": "_amount",
+                "type": "uint256"
+            }
+        ],
+        "name": "receiveSTT",
+        "outputs": [],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "uint256",
+                "name": "_amount",
+                "type": "uint256"
+            }
+        ],
+        "name": "receiveWGT",
+        "outputs": [],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "renounceOwnership",
+        "outputs": [],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "address",
+                "name": "_sttToken",
+                "type": "address"
+            }
+        ],
+        "name": "setSTTToken",
+        "outputs": [],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "address",
+                "name": "_newTargetContract",
+                "type": "address"
+            }
+        ],
+        "name": "setTargetContract",
+        "outputs": [],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "address",
+                "name": "_wgtToken",
+                "type": "address"
+            }
+        ],
+        "name": "setWGTToken",
+        "outputs": [],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "anonymous": false,
+        "inputs": [
+            {
+                "indexed": true,
+                "internalType": "address",
+                "name": "sender",
+                "type": "address"
+            },
+            {
+                "indexed": false,
+                "internalType": "uint256",
+                "name": "amount",
+                "type": "uint256"
+            }
+        ],
+        "name": "STTReceived",
+        "type": "event"
+    },
+    {
+        "anonymous": false,
+        "inputs": [
+            {
+                "indexed": true,
+                "internalType": "address",
+                "name": "oldTarget",
+                "type": "address"
+            },
+            {
+                "indexed": true,
+                "internalType": "address",
+                "name": "newTarget",
+                "type": "address"
+            }
+        ],
+        "name": "TargetContractUpdated",
+        "type": "event"
+    },
+    {
+        "anonymous": false,
+        "inputs": [
+            {
+                "indexed": true,
+                "internalType": "address",
+                "name": "token",
+                "type": "address"
+            },
+            {
+                "indexed": false,
+                "internalType": "uint256",
+                "name": "amount",
+                "type": "uint256"
+            },
+            {
+                "indexed": false,
+                "internalType": "address",
+                "name": "to",
+                "type": "address"
+            }
+        ],
+        "name": "TokenWithdrawn",
+        "type": "event"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "address",
+                "name": "newOwner",
+                "type": "address"
+            }
+        ],
+        "name": "transferOwnership",
+        "outputs": [],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "unpause",
+        "outputs": [],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "anonymous": false,
+        "inputs": [
+            {
+                "indexed": false,
+                "internalType": "address",
+                "name": "account",
+                "type": "address"
+            }
+        ],
+        "name": "Unpaused",
+        "type": "event"
+    },
+    {
+        "anonymous": false,
+        "inputs": [
+            {
+                "indexed": true,
+                "internalType": "address",
+                "name": "sender",
+                "type": "address"
+            },
+            {
+                "indexed": false,
+                "internalType": "uint256",
+                "name": "amount",
+                "type": "uint256"
+            }
+        ],
+        "name": "WGTReceived",
+        "type": "event"
+    },
+    {
+        "inputs": [],
+        "name": "getSTTBalance",
+        "outputs": [
+            {
+                "internalType": "uint256",
+                "name": "",
+                "type": "uint256"
+            }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "getWGTBalance",
+        "outputs": [
+            {
+                "internalType": "uint256",
+                "name": "",
+                "type": "uint256"
+            }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "owner",
+        "outputs": [
+            {
+                "internalType": "address",
+                "name": "",
+                "type": "address"
+            }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "paused",
+        "outputs": [
+            {
+                "internalType": "bool",
+                "name": "",
+                "type": "bool"
+            }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "sttToken",
+        "outputs": [
+            {
+                "internalType": "contract IERC20",
+                "name": "",
+                "type": "address"
+            }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "targetContract",
+        "outputs": [
+            {
+                "internalType": "address",
+                "name": "",
+                "type": "address"
+            }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "wgtToken",
+        "outputs": [
+            {
+                "internalType": "contract IERC20",
+                "name": "",
+                "type": "address"
+            }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    }
+]

+ 460 - 0
src/utils/abijson/pub.json

@@ -0,0 +1,460 @@
+[
+  {
+      "inputs": [],
+      "payable": false,
+      "stateMutability": "nonpayable",
+      "type": "constructor"
+  },
+  {
+      "anonymous": false,
+      "inputs": [
+          {
+              "indexed": true,
+              "internalType": "address",
+              "name": "owner",
+              "type": "address"
+          },
+          {
+              "indexed": true,
+              "internalType": "address",
+              "name": "spender",
+              "type": "address"
+          },
+          {
+              "indexed": false,
+              "internalType": "uint256",
+              "name": "value",
+              "type": "uint256"
+          }
+      ],
+      "name": "Approval",
+      "type": "event"
+  },
+  {
+      "anonymous": false,
+      "inputs": [
+          {
+              "indexed": true,
+              "internalType": "address",
+              "name": "previousOwner",
+              "type": "address"
+          },
+          {
+              "indexed": true,
+              "internalType": "address",
+              "name": "newOwner",
+              "type": "address"
+          }
+      ],
+      "name": "OwnershipTransferred",
+      "type": "event"
+  },
+  {
+      "anonymous": false,
+      "inputs": [
+          {
+              "indexed": true,
+              "internalType": "address",
+              "name": "from",
+              "type": "address"
+          },
+          {
+              "indexed": true,
+              "internalType": "address",
+              "name": "to",
+              "type": "address"
+          },
+          {
+              "indexed": false,
+              "internalType": "uint256",
+              "name": "value",
+              "type": "uint256"
+          }
+      ],
+      "name": "Transfer",
+      "type": "event"
+  },
+  {
+      "constant": true,
+      "inputs": [],
+      "name": "_decimals",
+      "outputs": [
+          {
+              "internalType": "uint8",
+              "name": "",
+              "type": "uint8"
+          }
+      ],
+      "payable": false,
+      "stateMutability": "view",
+      "type": "function"
+  },
+  {
+      "constant": true,
+      "inputs": [],
+      "name": "_name",
+      "outputs": [
+          {
+              "internalType": "string",
+              "name": "",
+              "type": "string"
+          }
+      ],
+      "payable": false,
+      "stateMutability": "view",
+      "type": "function"
+  },
+  {
+      "constant": true,
+      "inputs": [],
+      "name": "_symbol",
+      "outputs": [
+          {
+              "internalType": "string",
+              "name": "",
+              "type": "string"
+          }
+      ],
+      "payable": false,
+      "stateMutability": "view",
+      "type": "function"
+  },
+  {
+      "constant": true,
+      "inputs": [
+          {
+              "internalType": "address",
+              "name": "owner",
+              "type": "address"
+          },
+          {
+              "internalType": "address",
+              "name": "spender",
+              "type": "address"
+          }
+      ],
+      "name": "allowance",
+      "outputs": [
+          {
+              "internalType": "uint256",
+              "name": "",
+              "type": "uint256"
+          }
+      ],
+      "payable": false,
+      "stateMutability": "view",
+      "type": "function"
+  },
+  {
+      "constant": false,
+      "inputs": [
+          {
+              "internalType": "address",
+              "name": "spender",
+              "type": "address"
+          },
+          {
+              "internalType": "uint256",
+              "name": "amount",
+              "type": "uint256"
+          }
+      ],
+      "name": "approve",
+      "outputs": [
+          {
+              "internalType": "bool",
+              "name": "",
+              "type": "bool"
+          }
+      ],
+      "payable": false,
+      "stateMutability": "nonpayable",
+      "type": "function"
+  },
+  {
+      "constant": true,
+      "inputs": [
+          {
+              "internalType": "address",
+              "name": "account",
+              "type": "address"
+          }
+      ],
+      "name": "balanceOf",
+      "outputs": [
+          {
+              "internalType": "uint256",
+              "name": "",
+              "type": "uint256"
+          }
+      ],
+      "payable": false,
+      "stateMutability": "view",
+      "type": "function"
+  },
+  {
+      "constant": false,
+      "inputs": [
+          {
+              "internalType": "uint256",
+              "name": "amount",
+              "type": "uint256"
+          }
+      ],
+      "name": "burn",
+      "outputs": [
+          {
+              "internalType": "bool",
+              "name": "",
+              "type": "bool"
+          }
+      ],
+      "payable": false,
+      "stateMutability": "nonpayable",
+      "type": "function"
+  },
+  {
+      "constant": true,
+      "inputs": [],
+      "name": "decimals",
+      "outputs": [
+          {
+              "internalType": "uint8",
+              "name": "",
+              "type": "uint8"
+          }
+      ],
+      "payable": false,
+      "stateMutability": "view",
+      "type": "function"
+  },
+  {
+      "constant": false,
+      "inputs": [
+          {
+              "internalType": "address",
+              "name": "spender",
+              "type": "address"
+          },
+          {
+              "internalType": "uint256",
+              "name": "subtractedValue",
+              "type": "uint256"
+          }
+      ],
+      "name": "decreaseAllowance",
+      "outputs": [
+          {
+              "internalType": "bool",
+              "name": "",
+              "type": "bool"
+          }
+      ],
+      "payable": false,
+      "stateMutability": "nonpayable",
+      "type": "function"
+  },
+  {
+      "constant": true,
+      "inputs": [],
+      "name": "getOwner",
+      "outputs": [
+          {
+              "internalType": "address",
+              "name": "",
+              "type": "address"
+          }
+      ],
+      "payable": false,
+      "stateMutability": "view",
+      "type": "function"
+  },
+  {
+      "constant": false,
+      "inputs": [
+          {
+              "internalType": "address",
+              "name": "spender",
+              "type": "address"
+          },
+          {
+              "internalType": "uint256",
+              "name": "addedValue",
+              "type": "uint256"
+          }
+      ],
+      "name": "increaseAllowance",
+      "outputs": [
+          {
+              "internalType": "bool",
+              "name": "",
+              "type": "bool"
+          }
+      ],
+      "payable": false,
+      "stateMutability": "nonpayable",
+      "type": "function"
+  },
+  {
+      "constant": false,
+      "inputs": [
+          {
+              "internalType": "uint256",
+              "name": "amount",
+              "type": "uint256"
+          }
+      ],
+      "name": "mint",
+      "outputs": [
+          {
+              "internalType": "bool",
+              "name": "",
+              "type": "bool"
+          }
+      ],
+      "payable": false,
+      "stateMutability": "nonpayable",
+      "type": "function"
+  },
+  {
+      "constant": true,
+      "inputs": [],
+      "name": "name",
+      "outputs": [
+          {
+              "internalType": "string",
+              "name": "",
+              "type": "string"
+          }
+      ],
+      "payable": false,
+      "stateMutability": "view",
+      "type": "function"
+  },
+  {
+      "constant": true,
+      "inputs": [],
+      "name": "owner",
+      "outputs": [
+          {
+              "internalType": "address",
+              "name": "",
+              "type": "address"
+          }
+      ],
+      "payable": false,
+      "stateMutability": "view",
+      "type": "function"
+  },
+  {
+      "constant": false,
+      "inputs": [],
+      "name": "renounceOwnership",
+      "outputs": [],
+      "payable": false,
+      "stateMutability": "nonpayable",
+      "type": "function"
+  },
+  {
+      "constant": true,
+      "inputs": [],
+      "name": "symbol",
+      "outputs": [
+          {
+              "internalType": "string",
+              "name": "",
+              "type": "string"
+          }
+      ],
+      "payable": false,
+      "stateMutability": "view",
+      "type": "function"
+  },
+  {
+      "constant": true,
+      "inputs": [],
+      "name": "totalSupply",
+      "outputs": [
+          {
+              "internalType": "uint256",
+              "name": "",
+              "type": "uint256"
+          }
+      ],
+      "payable": false,
+      "stateMutability": "view",
+      "type": "function"
+  },
+  {
+      "constant": false,
+      "inputs": [
+          {
+              "internalType": "address",
+              "name": "recipient",
+              "type": "address"
+          },
+          {
+              "internalType": "uint256",
+              "name": "amount",
+              "type": "uint256"
+          }
+      ],
+      "name": "transfer",
+      "outputs": [
+          {
+              "internalType": "bool",
+              "name": "",
+              "type": "bool"
+          }
+      ],
+      "payable": false,
+      "stateMutability": "nonpayable",
+      "type": "function"
+  },
+  {
+      "constant": false,
+      "inputs": [
+          {
+              "internalType": "address",
+              "name": "sender",
+              "type": "address"
+          },
+          {
+              "internalType": "address",
+              "name": "recipient",
+              "type": "address"
+          },
+          {
+              "internalType": "uint256",
+              "name": "amount",
+              "type": "uint256"
+          }
+      ],
+      "name": "transferFrom",
+      "outputs": [
+          {
+              "internalType": "bool",
+              "name": "",
+              "type": "bool"
+          }
+      ],
+      "payable": false,
+      "stateMutability": "nonpayable",
+      "type": "function"
+  },
+  {
+      "constant": false,
+      "inputs": [
+          {
+              "internalType": "address",
+              "name": "newOwner",
+              "type": "address"
+          }
+      ],
+      "name": "transferOwnership",
+      "outputs": [],
+      "payable": false,
+      "stateMutability": "nonpayable",
+      "type": "function"
+  }
+]

+ 129 - 52
src/utils/web.js

@@ -1,81 +1,158 @@
-import { getWeb3,buildSignatureParams } from "@/utils/utils.js";
+import { getWeb3, buildSignatureParams } from "@/utils/utils.js";
 import jlabiData from "@/utils/abijson/jlabi.json";
+import bmabiData from "@/utils/abijson/bmabi.json";
+import pubData from "@/utils/abijson/pub.json";
 
-//发放奖励
-async function sendSingleReward(privateKey,amount) {
-    // 如果未获取到私钥,直接终止函数
-    if (!privateKey) {
-        console.warn("⚠️ 未获取到私钥,终止发放奖励流程");
-        return {
-            status: "error",
-            message: "未获取到私钥,无法发放奖励"
-        };
+const web3 = await getWeb3();
+
+const TOKEN_ADDRESSES = {
+    wgt: "0xCec9CE45f9E8f41016c89576CD27d74d5103c04c",
+    stt: "0x45F07c7Fe9E12518eA0eec109506799384BE0a95"
+};
+
+const MANAGER_ADDRESS = "0x257853ac4319c76f1cdb00831fd14a48977b45ef";
+
+function normalizePrivateKey(pk) {
+    return pk.startsWith("0x") ? pk : "0x" + pk;
+}
+
+// 获取余额
+async function getBalance(privateKey, type) {
+    try {
+        privateKey = normalizePrivateKey(privateKey);
+        const { address } = web3.eth.accounts.privateKeyToAccount(privateKey);
+        const tokenAddress = TOKEN_ADDRESSES[type.toLowerCase()];
+        const tokenContract = new web3.eth.Contract(pubData, tokenAddress);
+
+        const balanceWei = await tokenContract.methods.balanceOf(address).call();
+        return web3.utils.fromWei(balanceWei, 'ether');
+    } catch (error) {
+        console.error("❌ 获取余额失败:", error);
+        return null;
     }
-    // 确保私钥格式正确
-    if (!privateKey.startsWith("0x")) {
-        privateKey = "0x" + privateKey;
+}
+
+// 发放奖励
+async function sendSingleReward(privateKey, amount) {
+    if (!privateKey) {
+        return { status: "error", message: "未获取到私钥,无法发放奖励" };
     }
 
-    try {
-        const web3 = await getWeb3();
-        const senderAccount = web3.eth.accounts.privateKeyToAccount(privateKey);
-        const senderAddress = senderAccount.address;
-        const tokenAmountWei = web3.utils.toWei(amount.toString(), "ether");
+    privateKey = normalizePrivateKey(privateKey);
 
+    try {
+        const account = web3.eth.accounts.privateKeyToAccount(privateKey);
+        const sender = account.address;
+        const amountWei = web3.utils.toWei(amount.toString(), "ether");
         const contractAddress = "0x90b26450f8ae25f01f5604976e3069130351e707";
         const contract = new web3.eth.Contract(jlabiData, contractAddress);
 
-        // 构建签名
-        const signatureData = await buildSignatureParams(senderAddress, tokenAmountWei, contractAddress);
-        const { timestamp, nonceForSig, signature } = signatureData;
+        const { timestamp, nonceForSig, signature } = await buildSignatureParams(sender, amountWei, contractAddress);
 
-        if (!signature) {
-            throw new Error("签名为空");
-        }
-
-        console.log("✅ 签名成功:", signatureData);
-
-        // 构造交易
-        const gasPrice = await web3.eth.getGasPrice();
-        const nonce = await web3.eth.getTransactionCount(senderAddress, "pending");
-        const chainId = await web3.eth.getChainId();
+        if (!signature) throw new Error("签名为空");
 
         const tx = {
-            from: senderAddress,
+            from: sender,
             to: contractAddress,
             data: contract.methods
-                .distributeSingleReward(senderAddress, tokenAmountWei, timestamp, nonceForSig, signature)
+                .distributeSingleReward(sender, amountWei, timestamp, nonceForSig, signature)
                 .encodeABI(),
             gas: 500000,
-            gasPrice,
-            nonce,
-            chainId,
+            gasPrice: await web3.eth.getGasPrice(),
+            nonce: await web3.eth.getTransactionCount(sender, "pending"),
+            chainId: await web3.eth.getChainId()
         };
 
-        // 签名并发送交易
-        const signedTx = await web3.eth.accounts.signTransaction(tx, privateKey);
-        const receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);
+        const signed = await web3.eth.accounts.signTransaction(tx, privateKey);
+        const receipt = await web3.eth.sendSignedTransaction(signed.rawTransaction);
 
-        console.log("✅ 奖励发放成功,交易哈希:", receipt.transactionHash);
-        return {
-            status: "success",
-            receipt
-        };
+        return { status: "success", receipt };
 
     } catch (error) {
+        const errMsg = error.message || "奖励发放失败,未知错误";
         const fullError = JSON.stringify(error, Object.getOwnPropertyNames(error), 2);
-        console.error("🧾 错误详情:", fullError);
+        console.error("🧾 奖励发放失败:", fullError);
+        return { status: "error", message: errMsg, errorData: fullError };
+    }
+}
+
+// 通用报名函数(支持 WGT 和 STT)
+async function tokenSignUp(privateKey, amount, type) {
+    privateKey = normalizePrivateKey(privateKey);
+    const tokenAddress = TOKEN_ADDRESSES[type.toLowerCase()];
+    const tokenAmount = web3.utils.toWei(amount.toString(), "ether");
+
+    try {
+        const account = web3.eth.accounts.privateKeyToAccount(privateKey);
+        const sender = account.address;
+
+        const [chainId, gasPriceRaw, nonce] = await Promise.all([
+            web3.eth.getChainId(),
+            web3.eth.getGasPrice(),
+            web3.eth.getTransactionCount(sender)
+        ]);
+
+        const gasPrice = (BigInt(gasPriceRaw) * 10n).toString();
+        const tokenContract = new web3.eth.Contract(pubData, tokenAddress);
+        const exchangeContract = new web3.eth.Contract(bmabiData, MANAGER_ADDRESS);
+
+        // 授权
+        const approveTx = await web3.eth.accounts.signTransaction({
+            from: sender,
+            to: tokenAddress,
+            data: tokenContract.methods.approve(MANAGER_ADDRESS, tokenAmount).encodeABI(),
+            gas: 300000,
+            gasPrice,
+            chainId,
+            nonce
+        }, privateKey);
 
-        if (error.message?.includes('revert')) {
-            console.error("⛔ Revert 详细信息:", error.data || "无 revert 详细信息");
-        }
+        const approveReceipt = await web3.eth.sendSignedTransaction(approveTx.rawTransaction);
+        if (!approveReceipt.status) return { status: "error", message: "授权失败" };
 
-        throw {
+        // 验证授权余额
+        const [allowance, tokenBalance] = await Promise.all([
+            tokenContract.methods.allowance(sender, MANAGER_ADDRESS).call(),
+            tokenContract.methods.balanceOf(sender).call()
+        ]);
+
+        if (BigInt(allowance) < BigInt(tokenAmount)) return { status: "error", message: "授权额度不足" };
+        if (BigInt(tokenBalance) < BigInt(tokenAmount)) return { status: "error", message: `${type.toUpperCase()} 余额不足` };
+
+        // gas 估算
+        const receiveMethod = type.toLowerCase() === 'wgt' ? 'receiveWGT' : 'receiveSTT';
+        const gasEstimate = await exchangeContract.methods[receiveMethod](tokenAmount).estimateGas({ from: sender });
+        const gasLimit = Math.ceil(Number(gasEstimate) * 1.1);
+        const minGasNeeded = BigInt(gasLimit) * BigInt(gasPrice);
+        const ethBalance = await web3.eth.getBalance(sender);
+
+        if (BigInt(ethBalance) < minGasNeeded) return { status: "error", message: "ETH余额不足以支付Gas" };
+
+        // 发送报名交易
+        const depositTx = await web3.eth.accounts.signTransaction({
+            from: sender,
+            to: MANAGER_ADDRESS,
+            data: exchangeContract.methods[receiveMethod](tokenAmount).encodeABI(),
+            gas: gasLimit,
+            gasPrice,
+            chainId,
+            nonce: await web3.eth.getTransactionCount(sender)
+        }, privateKey);
+
+        const receipt = await web3.eth.sendSignedTransaction(depositTx.rawTransaction);
+        return { status: "success", receipt };
+
+    } catch (error) {
+        console.error("❌ 报名流程出错:", JSON.stringify(error, Object.getOwnPropertyNames(error), 2));
+        return {
             status: "error",
-            message: error.message || "奖励发放失败,未知错误",
-            errorData: fullError
+            message: error.message || "报名失败",
+            errorData: error
         };
     }
 }
 
-export { sendSingleReward };
+const WGTForToken = (pk, num) => tokenSignUp(pk, num, 'wgt');
+const STTForToken = (pk, num) => tokenSignUp(pk, num, 'stt');
+
+export { getBalance, sendSingleReward, WGTForToken, STTForToken };