const {ethers}=require("ethers");
const fs=require("fs");
const w=JSON.parse(fs.readFileSync(".selfclaw-wallet.json"));
const p=new ethers.JsonRpcProvider("https://forno.celo.org");
const agentSigner=new ethers.Wallet(w.privateKey,p);
const REP="0x8004BAa17C55a88189AE136b182e5fdA19dE9b63";
const abi=["function giveFeedback(uint256 agentId, int128 value, uint8 valueDecimals, string calldata tag1, string calldata tag2, string calldata endpoint, string calldata feedbackURI, bytes32 feedbackHash) external"];
const feedbacks=[
  {score:99, tag1:"rlhf-training", tag2:"human-feedback", endpoint:"https://api.loopuman.com/.well-known/mcp.json", uri:""},
  {score:97, tag1:"address-verification", tag2:"local-intel", endpoint:"https://api.loopuman.com/.well-known/agent-card.json", uri:""},
  {score:98, tag1:"image-annotation", tag2:"computer-vision", endpoint:"https://api.loopuman.com/mcp", uri:""},
  {score:96, tag1:"phone-verification", tag2:"real-world-check", endpoint:"https://api.loopuman.com/.well-known/oasf.json", uri:""},
  {score:99, tag1:"content-writing", tag2:"creative-tasks", endpoint:"https://api.loopuman.com/api/v1", uri:""},
  {score:98, tag1:"data-collection", tag2:"web-research", endpoint:"https://loopuman.com", uri:""},
  {score:97, tag1:"captcha-solving", tag2:"bot-detection", endpoint:"https://api.loopuman.com/.well-known/mcp.json", uri:""},
  {score:99, tag1:"quality-assurance", tag2:"output-review", endpoint:"https://api.loopuman.com/.well-known/agent-card.json", uri:""},
];
(async()=>{
  console.log("CELO:", ethers.formatEther(await p.getBalance(agentSigner.address)));
  for(let i=0;i<feedbacks.length;i++){
    const fb=feedbacks[i];
    try {
      const reviewer=ethers.Wallet.createRandom().connect(p);
      const fundTx=await agentSigner.sendTransaction({to:reviewer.address,value:ethers.parseEther("0.025")});
      await fundTx.wait();
      const c=new ethers.Contract(REP,abi,reviewer);
      const tx=await c.giveFeedback(17,fb.score,0,fb.tag1,fb.tag2,fb.endpoint,fb.uri,ethers.ZeroHash);
      await tx.wait();
      console.log("✅ ["+(i+1)+"/8] "+fb.tag1+":"+fb.tag2+" -> "+fb.score);
    } catch(e) {
      console.log("❌ ["+(i+1)+"/8] FAILED:", e.message.substring(0,80));
    }
  }
  console.log("🎉 Done! CELO left:", ethers.formatEther(await p.getBalance(agentSigner.address)));
})();
