@oracle-agent/oracle 0.28.13 → 0.28.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/skills/oracle-action-semantics/SKILL.md +3 -1
- package/dist/assets/skills/oracle-desk-product/SKILL.md +1 -1
- package/dist/bin/desk-server.mjs +26 -26
- package/dist/cli/commands/chat.mjs +140 -140
- package/dist/cli/commands/doctor.mjs +3 -3
- package/dist/cli/commands/eval.mjs +73 -74
- package/dist/cli/commands/model.mjs +143 -143
- package/dist/cli/commands/receipt.mjs +2 -2
- package/dist/cli/commands/setup.mjs +7 -7
- package/dist/cli/commands/sign.mjs +11 -11
- package/dist/cli/commands/signer.mjs +13 -13
- package/dist/cli/commands/venues.mjs +2 -2
- package/dist/data/desk-data.mjs +24 -24
- package/dist/index.mjs +29 -29
- package/dist/local-signer/anvil-attestation-worker.mjs +1 -1
- package/dist/local-signer/index.mjs +3 -3
- package/dist/local-signer/runtime.mjs +10 -10
- package/dist/public-api/agent-grants.mjs +2 -2
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import Fe from"node:fs";import{JsonRpcProvider as $e}from"ethers";import{Interface as W,keccak256 as Be}from"ethers";import{Transaction as zo}from"@scure/btc-signer";import{ed25519 as Go}from"@noble/curves/ed25519.js";import{base58 as vn}from"@scure/base";import{Interface as te}from"ethers";import{Interface as he,MaxUint256 as wt,isAddress as ht,keccak256 as gt,toUtf8Bytes as yt}from"ethers";import{Interface as me,isAddress as Ye}from"ethers";import{isAddress as He}from"ethers";var et=new me(["function approve(address spender,uint256 amount) returns (bool)"]);import{Interface as we,isAddress as nt}from"ethers";var st=new we(["function approve(address spender,uint256 amount) returns (bool)"]),ct=Object.freeze({42161:"0x1c3fa76e6e1088bce750f23a5bfcffa1efef6a41",43114:"0x8f550e53dfe96c055d5bdb267c21f268fcaf63b2"});var vt=new he(["function approve(address spender,uint256 amount) returns (bool)"]);var Tt=300*1e3,kt=(()=>{let e=Number(process.env.ORACLE_PREPARE_HARD_MAX_AGE_MS);return Number.isFinite(e)&&e>0?e:1800*1e3})();import{Address as Bt,NETWORK as Pt,OutScript as Rt,RawTx as Ft,SigHash as $t,TEST_NETWORK as _t,Transaction as qt}from"@scure/btc-signer";import{createHash as ye}from"node:crypto";import{base58 as jt}from"@scure/base";import{getCompiledTransactionMessageDecoder as Ht}from"@solana/transaction-messages";var Y=e=>ye("sha256").update(`global:${e}`).digest().subarray(0,8).toString("hex"),Jt=new Map([[Y("route"),{name:"route",prefixBytes:0}],[Y("shared_accounts_route"),{name:"shared_accounts_route",prefixBytes:1}]]);var Zt=64*1024;var dr=Object.freeze({"perp-order":"order","hip3-order":"order","hip4-order":"order","perp-bracket":"order","perp-cancel":"cancel","perp-leverage":"leverage","perp-isolated-margin":"margin","builder-fee-approval":"approveBuilder","hype-stake-deposit":"stake","hype-stake-withdraw":"unstake","hype-delegate":"delegate","hype-undelegate":"delegate"}),fr=Object.freeze({"perp-order":"order","hip3-order":"order","hip4-order":"order","perp-bracket":"order","perp-cancel":"cancel","perp-leverage":"updateLeverage","perp-isolated-margin":"updateIsolatedMargin","builder-fee-approval":"approveBuilderFee","hype-stake-deposit":"cDeposit","hype-stake-withdraw":"cWithdraw","hype-delegate":"tokenDelegate","hype-undelegate":"tokenDelegate"});var wr="0x"+"00".repeat(32);var Ee=Object.freeze([["salt","uint256"],["maker","address"],["signer","address"],["tokenId","uint256"],["makerAmount","uint256"],["takerAmount","uint256"],["side","uint8"],["signatureType","uint8"],["timestamp","uint256"],["metadata","bytes32"],["builder","bytes32"]]),br=Object.freeze(Ee.map(e=>e[0]));var ve=new Set(["evm","evm-swap","evm-bridge","evm-nft","btc","sol","hl","poly","lighter"]);var Mr=Object.freeze({swap:5,bridge:5,perps:0,nft:0,mint:0,transfer:0,approve:0,order:0,cancel:0,leverage:0,margin:0,approveBuilder:0,stake:0,unstake:0,delegate:0});var Ie=Object.freeze({"0x04e45aaf":{provider:"uniswap-v3",action:"swap",layout:"router02-exact-input-single"},"0x414bf389":{provider:"uniswap-v3",action:"swap",layout:"swap-router-exact-input-single"},"0xc04b8d59":{provider:"uniswap-v3",action:"swap",layout:"exact-input-deadline"},"0xb858183f":{provider:"uniswap-v3",action:"swap",layout:"exact-input"},"0x5ae401dc":{provider:"uniswap-v3",action:"swap",layout:"multicall-deadline"},"0xa026383e":{provider:"aerodrome",action:"swap",layout:"aerodrome-exact-input-single"},"0x7b939232":{provider:"across-v3",action:"bridge",layout:"across-deposit-v3"}}),Dr=Object.freeze({"0x161ac21f":{provider:"opensea-nft",action:"mint",layout:"seadrop-mint-public"},"0xc2f6663a":{provider:"opensea-nft",action:"mint",layout:"seadrop-mint-allowlist"}}),Ur=new te(["function buySpecificNFT(uint256 tokenId,uint256 maxCost) payable","function sellNFT(uint256 tokenId,uint256 minPayout) payable"]),jr=new te(["function mintAllowList(address nftContract,address feeRecipient,address minterIfNotPayer,uint256 quantity,(uint80 mintPrice,uint48 maxTotalMintableByWallet,uint48 startTime,uint48 endTime,uint48 dropStageIndex,uint32 maxTokenSupplyForStage,uint16 feeBps,bool restrictFeeRecipients) mintParams,bytes32[] proof) payable"]),Wr=Object.freeze({"0xa0712d68":{provider:"nft-mint",action:"mint",layout:"mint-quantity"},"0x1249c58b":{provider:"nft-mint",action:"mint",layout:"mint-no-args"},"0x2db11544":{provider:"nft-mint",action:"mint",layout:"mint-quantity"},"0xefef39a1":{provider:"nft-mint",action:"mint",layout:"mint-quantity"},"0xa6f2ae3a":{provider:"nft-mint",action:"mint",layout:"mint-no-args"}});var Te=Object.freeze([...ve]),Hr=Object.freeze({...Ie});import{ed25519 as sn}from"@noble/curves/ed25519.js";import{base58 as un}from"@scure/base";import{RawTx as dn,SigHash as fn,Transaction as pn}from"@scure/btc-signer";import{Transaction as wn,keccak256 as hn,verifyTypedData as gn}from"ethers";import{encode as Vr}from"@msgpack/msgpack";import{keccak256 as Kr,verifyTypedData as Yr}from"ethers";var Xr=Object.freeze({name:"Exchange",version:"1",chainId:1337,verifyingContract:"0x0000000000000000000000000000000000000000"}),Qr=Object.freeze({Agent:[{name:"source",type:"string"},{name:"connectionId",type:"bytes32"}]});var $n=Object.freeze({N:1<<17,r:8,p:1}),_n=256*1024*1024,qn=16*1024;import{homedir as D}from"node:os";import{join as U}from"node:path";var ne=process.env.ORACLE_PUBLIC_DESKTOP==="1",Oe=ne?process.env.ORACLE_CONFIG_DIR||U(D(),".config","oracle"):U(D(),".config","oracle"),jn=ne?Oe:U(D(),".config","mad-desk");var Vn="0".repeat(64),Gn=Object.freeze({PREPARE:"exec.prepare",SIGN:"exec.sign",BROADCAST:"exec.broadcast",POLICY_REJECT:"policy.reject",AUTH_GRANT:"auth.grant",AUTH_OK:"auth.verify.ok",AUTH_FAIL:"auth.verify.fail"});var Kn=Promise.resolve();import{Wallet as oo}from"ethers";import{base58 as ao}from"@scure/base";import{ed25519 as co}from"@noble/curves/ed25519.js";import{NETWORK as lo,TEST_NETWORK as fo,WIF as po,p2wpkh as mo}from"@scure/btc-signer";import{pubECDSA as ho}from"@scure/btc-signer/utils.js";var u=new W(["function collection() view returns (address)","function token() view returns (address)","function robinhoodSwapFeeWei() view returns (uint256)","function quoteSpecificBuy(uint256 tokenId) view returns (uint256 totalCost,uint256 baseCost,uint256 fee,uint256 protocolFee,bool available)","function quoteSellNFT() view returns (uint256 netPayout,uint256 grossPayout,uint256 fee,uint256 protocolFee)","function inventory(uint256 tokenId) view returns (bool)","function buySpecificNFT(uint256 tokenId,uint256 maxCost) payable","function sellNFT(uint256 tokenId,uint256 minPayout) payable"]),oe=new W(["function decimals() view returns (uint8)","function allowance(address owner,address spender) view returns (uint256)"]),j=new W(["function ownerOf(uint256 tokenId) view returns (address)","function getApproved(uint256 tokenId) view returns (address)","function isApprovedForAll(address owner,address operator) view returns (bool)"]);function c(e,t){let r=String(e||"").toLowerCase();if(!/^0x[0-9a-f]{40}$/.test(r))throw new Error(`signer: invalid ${t}`);return r}function ie(e,t){return Object.entries(e||{}).find(([r])=>r.toLowerCase()===t)?.[1]}function Pe(e,t){let r=e?.anvilQuote;if(!r||typeof r!="object"||Array.isArray(r))throw new Error("signer: exact prepared Anvil quote is required");if(!e?.artifact?.anvilQuote||JSON.stringify(e.artifact.anvilQuote)!==JSON.stringify(r))throw new Error("signer: exact prepared Anvil quote artifact mismatch");return Object.freeze(t==="buy"?{totalCostRaw:BigInt(r.totalCostRaw).toString(),baseCostRaw:BigInt(r.baseCostRaw).toString(),feeRaw:BigInt(r.feeRaw).toString(),protocolFeeRaw:BigInt(r.protocolFeeRaw).toString(),available:r.available===!0}:{netPayoutRaw:BigInt(r.netPayoutRaw).toString(),grossPayoutRaw:BigInt(r.grossPayoutRaw).toString(),feeRaw:BigInt(r.feeRaw).toString(),protocolFeeRaw:BigInt(r.protocolFeeRaw).toString()})}function Re(e,t,r){if(e.preconditions?.exactQuoteConfirmed!==!0)throw new Error("signer: exact prepared Anvil quote confirmation required");let a=e.artifact,p=t==="buy"?[r.totalCostRaw,e.maxPaymentTokenAmountRaw,a?.maxPaymentTokenAmountRaw,e.exactQuoteTotalCostRaw,a?.exactQuoteTotalCostRaw,e.preconditions?.confirmedTotalCostRaw]:[r.netPayoutRaw,e.minPayoutRaw,a?.minPayoutRaw,e.exactQuoteNetPayoutRaw,a?.exactQuoteNetPayoutRaw,e.preconditions?.confirmedNetPayoutRaw],n;try{n=BigInt(p[0]);for(let g of p.slice(1))if(BigInt(g)!==n)throw new Error("mismatch")}catch{throw new Error(`signer: exact Anvil ${t} settlement limit mismatch`)}let d=a?.transactions;if(!Array.isArray(d)||d.length!==1)throw new Error("signer: exact Anvil action transaction required");let h=t==="buy"?"buySpecificNFT":"sellNFT",f;try{if(f=u.decodeFunctionData(h,d[0].data),u.encodeFunctionData(h,[f[0],f[1]]).toLowerCase()!==String(d[0].data).toLowerCase())throw new Error("non-canonical")}catch{throw new Error(`signer: exact Anvil ${t} calldata required`)}if(BigInt(f[0])!==BigInt(e.tokenId)||BigInt(f[1])!==n)throw new Error(`signer: exact Anvil ${t} calldata limit mismatch`);return n}async function l(e,t,r,a,p,n=[]){let d=await e.send("eth_call",[{to:t,data:r.encodeFunctionData(a,n)},p]);return r.decodeFunctionResult(a,d)[0]}async function ae(e,t,r,{nowMs:a=Date.now(),signerAddress:p}={}){if(t?.surface!=="evm-nft"||String(t?.provider).toLowerCase()!=="anvil-nft")return null;if(!e||typeof e.send!="function")throw new Error("signer: trusted RPC cannot attest Anvil market");let n=c(t.destination,"Anvil market"),d=c(t.contract,"Anvil collection"),h=c(t.paymentToken,"Anvil payment token"),f=BigInt(t.nativeSwapFeeWei),g=Number(t.paymentTokenDecimals),y=c(p,"Anvil signer identity"),se=c(t.owner,"Anvil envelope owner");if(y!==se)throw new Error("signer: Anvil signer identity mismatch");let m=BigInt(t.tokenId);if(m<0n)throw new Error("signer: invalid Anvil tokenId");let w=String(t.nftAction||"").toLowerCase();if(w!=="buy"&&w!=="sell")throw new Error("signer: unsupported Anvil NFT action");let k=Pe(t,w),N=Re(t,w,k),b=t.anvilAttestation;if(!b||typeof b!="object"||Number(b.snapshotExpiresAtMs)<=Number(a))throw new Error("signer: fresh provider Anvil attestation required");let O=String(ie(r.anvilRuntimeCodeHashes,n)||"").toLowerCase();if(!/^0x[0-9a-f]{64}$/.test(O)||O!==String(b.runtimeCodeHash||"").toLowerCase())throw new Error("signer: Anvil runtime is not reviewed by policy");let H=ie(r.nftPaymentTokenCaps,h);if(!H||Number(H.decimals)!==g)throw new Error("signer: Anvil payment token decimals are not reviewed by policy");let J=String(await e.send("eth_chainId",[])).toLowerCase();if(!/^0x(?:0|[1-9a-f][0-9a-f]*)$/.test(J)||BigInt(J)!==4663n)throw new Error("signer: trusted RPC Anvil chain mismatch");let x=String(await e.send("eth_blockNumber",[])).toLowerCase();if(!/^0x(?:0|[1-9a-f][0-9a-f]*)$/.test(x))throw new Error("signer: trusted RPC returned an invalid Anvil block number");let ce=BigInt(x),z=await e.send("eth_getBlockByNumber",[x,!1]),L=String(z?.hash||"").toLowerCase();if(String(z?.number||"").toLowerCase()!==x||!/^0x[0-9a-f]{64}$/.test(L))throw new Error("signer: trusted RPC returned an invalid Anvil block attestation");let i=Object.freeze({blockHash:L,requireCanonical:!0}),C=String(await e.send("eth_getCode",[n,i])).toLowerCase();if(!/^0x[0-9a-f]+$/.test(C)||C==="0x")throw new Error("signer: Anvil market runtime is empty");let V=Be(C).toLowerCase();if(V!==O)throw new Error("signer: Anvil market runtime mismatch with reviewed policy");let[ue,le,de]=await Promise.all([l(e,n,u,"collection",i),l(e,n,u,"token",i),l(e,n,u,"robinhoodSwapFeeWei",i)]),E=c(ue,"live Anvil collection"),S=c(le,"live Anvil payment token"),G=BigInt(de).toString();if(E!==d)throw new Error("signer: live Anvil collection mismatch");if(S!==h)throw new Error("signer: live Anvil payment token mismatch");if(G!==f.toString())throw new Error("signer: live Anvil native swap fee mismatch");let B=Number(await l(e,S,oe,"decimals",i));if(!Number.isSafeInteger(B)||B!==g)throw new Error("signer: live Anvil payment token decimals mismatch");let P=c(await l(e,E,j,"ownerOf",i,[m]),"live Anvil token owner"),R=null,A=null,v=null,I=null,o;if(w==="buy"){let[F,$,_]=await Promise.all([l(e,n,u,"inventory",i,[m]),l(e,S,oe,"allowance",i,[y,n]),e.send("eth_call",[{to:n,data:u.encodeFunctionData("quoteSpecificBuy",[m])},i])]);R=!!F,A=BigInt($).toString();let s=u.decodeFunctionResult("quoteSpecificBuy",_);if(o=Object.freeze({totalCostRaw:BigInt(s[0]).toString(),baseCostRaw:BigInt(s[1]).toString(),feeRaw:BigInt(s[2]).toString(),protocolFeeRaw:BigInt(s[3]).toString(),available:!!s[4]}),JSON.stringify(o)!==JSON.stringify(k))throw new Error("signer: exact Anvil buy quote changed after preparation");if(P!==n)throw new Error("signer: exact Anvil token owner is not the market");if(!R)throw new Error("signer: exact Anvil token is not in market inventory");if(BigInt(A)!==BigInt(t.preconditions?.allowanceRaw))throw new Error("signer: live Anvil ERC20 allowance changed after preparation");if(BigInt(A)<N)throw new Error("signer: live Anvil ERC20 allowance is insufficient");if(!o.available)throw new Error("signer: exact Anvil buy quote is unavailable");if(BigInt(o.totalCostRaw)!==N)throw new Error("signer: live Anvil buy quote does not equal exact payment limit");if(BigInt(o.totalCostRaw)!==BigInt(o.baseCostRaw)+BigInt(o.feeRaw)+BigInt(o.protocolFeeRaw))throw new Error("signer: exact Anvil buy quote fee arithmetic mismatch")}else{let[F,$,_]=await Promise.all([l(e,E,j,"getApproved",i,[m]),l(e,E,j,"isApprovedForAll",i,[y,n]),e.send("eth_call",[{to:n,data:u.encodeFunctionData("quoteSellNFT")},i])]);v=c(F,"live Anvil token approval"),I=!!$;let s=u.decodeFunctionResult("quoteSellNFT",_);if(o=Object.freeze({netPayoutRaw:BigInt(s[0]).toString(),grossPayoutRaw:BigInt(s[1]).toString(),feeRaw:BigInt(s[2]).toString(),protocolFeeRaw:BigInt(s[3]).toString()}),JSON.stringify(o)!==JSON.stringify(k))throw new Error("signer: exact Anvil sell quote changed after preparation");if(P!==y)throw new Error("signer: exact Anvil token owner does not match signer");if(v!==n&&!I)throw new Error("signer: live Anvil NFT approval is insufficient");if(v!==c(t.preconditions?.approvedAddress,"prepared Anvil token approval")||I!==!!t.preconditions?.approvedForAll)throw new Error("signer: live Anvil NFT approval changed after preparation");if(BigInt(o.netPayoutRaw)!==N)throw new Error("signer: live Anvil sell quote does not equal exact payout limit");if(BigInt(o.netPayoutRaw)+BigInt(o.feeRaw)+BigInt(o.protocolFeeRaw)!==BigInt(o.grossPayoutRaw))throw new Error("signer: exact Anvil sell quote fee arithmetic mismatch")}return Object.freeze({source:"local-signer-trusted-rpc",chainId:4663,market:n,collection:E,paymentToken:S,paymentTokenDecimals:B,nativeSwapFeeWei:G,signerAddress:y,nftAction:w,tokenId:m.toString(),tokenOwner:P,inventoryMember:R,allowanceRaw:A,approvedAddress:v,approvedForAll:I,quote:o,blockNumber:ce.toString(),blockHash:L,runtimeCodeHash:V,verifiedAtMs:Number(a)})}try{let e=JSON.parse(Fe.readFileSync(0,"utf8")),t=new $e(e.rpcUrl,Number(e.chainId)),r=await ae(t,e.envelope,e.policy,{nowMs:Number(e.nowMs),signerAddress:e.signerAddress});process.stdout.write(JSON.stringify(r))}catch(e){process.stderr.write(`Anvil attestation failed: ${String(e?.message||e)}
|
|
1
|
+
import Fe from"node:fs";import{JsonRpcProvider as _e}from"ethers";import{Interface as J,keccak256 as Pe}from"ethers";import{Transaction as Vo}from"@scure/btc-signer";import{ed25519 as Ko}from"@noble/curves/ed25519.js";import{base58 as vn}from"@scure/base";import{Interface as re}from"ethers";import{Interface as ge,MaxUint256 as ht,isAddress as gt,keccak256 as yt,toUtf8Bytes as Et}from"ethers";import{Interface as we,isAddress as Xe}from"ethers";import{isAddress as Je}from"ethers";var tt=new we(["function approve(address spender,uint256 amount) returns (bool)"]);import{Interface as he,isAddress as ot}from"ethers";var ct=new he(["function approve(address spender,uint256 amount) returns (bool)"]),ut=Object.freeze({42161:"0x1c3fa76e6e1088bce750f23a5bfcffa1efef6a41",43114:"0x8f550e53dfe96c055d5bdb267c21f268fcaf63b2"});var It=new ge(["function approve(address spender,uint256 amount) returns (bool)"]);var Tt=300*1e3,Nt=(()=>{let e=Number(process.env.ORACLE_PREPARE_HARD_MAX_AGE_MS);return Number.isFinite(e)&&e>0?e:1800*1e3})();import{Address as Pt,NETWORK as Rt,OutScript as $t,RawTx as Ft,SigHash as _t,TEST_NETWORK as qt,Transaction as Mt}from"@scure/btc-signer";import{createHash as Ee}from"node:crypto";import{base58 as Wt}from"@scure/base";import{getCompiledTransactionMessageDecoder as Jt}from"@solana/transaction-messages";var X=e=>Ee("sha256").update(`global:${e}`).digest().subarray(0,8).toString("hex"),zt=new Map([[X("route"),{name:"route",prefixBytes:0}],[X("shared_accounts_route"),{name:"shared_accounts_route",prefixBytes:1}]]);var er=64*1024;var fr=Object.freeze({"perp-order":"order","hip3-order":"order","hip4-order":"order","perp-bracket":"order","perp-cancel":"cancel","perp-leverage":"leverage","perp-isolated-margin":"margin","builder-fee-approval":"approveBuilder","hype-stake-deposit":"stake","hype-stake-withdraw":"unstake","hype-delegate":"delegate","hype-undelegate":"delegate"}),pr=Object.freeze({"perp-order":"order","hip3-order":"order","hip4-order":"order","perp-bracket":"order","perp-cancel":"cancel","perp-leverage":"updateLeverage","perp-isolated-margin":"updateIsolatedMargin","builder-fee-approval":"approveBuilderFee","hype-stake-deposit":"cDeposit","hype-stake-withdraw":"cWithdraw","hype-delegate":"tokenDelegate","hype-undelegate":"tokenDelegate"});var hr="0x"+"00".repeat(32);var be=Object.freeze([["salt","uint256"],["maker","address"],["signer","address"],["tokenId","uint256"],["makerAmount","uint256"],["takerAmount","uint256"],["side","uint8"],["signatureType","uint8"],["timestamp","uint256"],["metadata","bytes32"],["builder","bytes32"]]),xr=Object.freeze(be.map(e=>e[0]));var Ie=new Set(["evm","evm-swap","evm-bridge","evm-nft","btc","sol","hl","poly","lighter"]);var Mr=Object.freeze({swap:5,bridge:5,perps:0,nft:0,mint:0,transfer:0,approve:0,order:0,cancel:0,leverage:0,margin:0,approveBuilder:0,stake:0,unstake:0,delegate:0});var ke=Object.freeze({"0x04e45aaf":{provider:"uniswap-v3",action:"swap",layout:"router02-exact-input-single"},"0x414bf389":{provider:"uniswap-v3",action:"swap",layout:"swap-router-exact-input-single"},"0xc04b8d59":{provider:"uniswap-v3",action:"swap",layout:"exact-input-deadline"},"0xb858183f":{provider:"uniswap-v3",action:"swap",layout:"exact-input"},"0x5ae401dc":{provider:"uniswap-v3",action:"swap",layout:"multicall-deadline"},"0xa026383e":{provider:"aerodrome",action:"swap",layout:"aerodrome-exact-input-single"},"0x7b939232":{provider:"across-v3",action:"bridge",layout:"across-deposit-v3"}}),Dr=Object.freeze({"0x161ac21f":{provider:"opensea-nft",action:"mint",layout:"seadrop-mint-public"},"0xc2f6663a":{provider:"opensea-nft",action:"mint",layout:"seadrop-mint-allowlist"}}),Ur=new re(["function buySpecificNFT(uint256 tokenId,uint256 maxCost) payable","function sellNFT(uint256 tokenId,uint256 minPayout) payable"]),jr=new re(["function mintAllowList(address nftContract,address feeRecipient,address minterIfNotPayer,uint256 quantity,(uint80 mintPrice,uint48 maxTotalMintableByWallet,uint48 startTime,uint48 endTime,uint48 dropStageIndex,uint32 maxTokenSupplyForStage,uint16 feeBps,bool restrictFeeRecipients) mintParams,bytes32[] proof) payable"]),Wr=Object.freeze({"0xa0712d68":{provider:"nft-mint",action:"mint",layout:"mint-quantity"},"0x1249c58b":{provider:"nft-mint",action:"mint",layout:"mint-no-args"},"0x2db11544":{provider:"nft-mint",action:"mint",layout:"mint-quantity"},"0xefef39a1":{provider:"nft-mint",action:"mint",layout:"mint-quantity"},"0xa6f2ae3a":{provider:"nft-mint",action:"mint",layout:"mint-no-args"}});var Te=Object.freeze([...Ie]),Hr=Object.freeze({...ke});import{ed25519 as sn}from"@noble/curves/ed25519.js";import{base58 as un}from"@scure/base";import{RawTx as dn,SigHash as fn,Transaction as pn}from"@scure/btc-signer";import{Transaction as wn,keccak256 as hn,verifyTypedData as gn}from"ethers";import{encode as Vr}from"@msgpack/msgpack";import{keccak256 as Kr,verifyTypedData as Yr}from"ethers";var Xr=Object.freeze({name:"Exchange",version:"1",chainId:1337,verifyingContract:"0x0000000000000000000000000000000000000000"}),Qr=Object.freeze({Agent:[{name:"source",type:"string"},{name:"connectionId",type:"bytes32"}]});var Fn=Object.freeze({N:1<<17,r:8,p:1}),_n=256*1024*1024,qn=16*1024;import{homedir as j}from"node:os";import{join as W}from"node:path";var oe=process.env.ORACLE_PUBLIC_DESKTOP==="1",Le=oe?process.env.ORACLE_CONFIG_DIR||W(j(),".config","oracle"):W(j(),".config","oracle"),jn=oe?Le:W(j(),".config","mad-desk");var Vn="0".repeat(64),Gn=Object.freeze({PREPARE:"exec.prepare",SIGN:"exec.sign",BROADCAST:"exec.broadcast",POLICY_REJECT:"policy.reject",AUTH_GRANT:"auth.grant",AUTH_OK:"auth.verify.ok",AUTH_FAIL:"auth.verify.fail"});var Kn=Promise.resolve();import{Wallet as io}from"ethers";import{base58 as so}from"@scure/base";import{ed25519 as uo}from"@noble/curves/ed25519.js";import{NETWORK as fo,TEST_NETWORK as po,WIF as mo,p2wpkh as wo}from"@scure/btc-signer";import{pubECDSA as go}from"@scure/btc-signer/utils.js";var u=new J(["function collection() view returns (address)","function token() view returns (address)","function robinhoodSwapFeeWei() view returns (uint256)","function quoteSpecificBuy(uint256 tokenId) view returns (uint256 totalCost,uint256 baseCost,uint256 fee,uint256 protocolFee,bool available)","function quoteSellNFT() view returns (uint256 netPayout,uint256 grossPayout,uint256 fee,uint256 protocolFee)","function inventory(uint256 tokenId) view returns (bool)","function buySpecificNFT(uint256 tokenId,uint256 maxCost) payable","function sellNFT(uint256 tokenId,uint256 minPayout) payable"]),ie=new J(["function decimals() view returns (uint8)","function allowance(address owner,address spender) view returns (uint256)"]),H=new J(["function ownerOf(uint256 tokenId) view returns (address)","function getApproved(uint256 tokenId) view returns (address)","function isApprovedForAll(address owner,address operator) view returns (bool)"]);function c(e,t){let r=String(e||"").toLowerCase();if(!/^0x[0-9a-f]{40}$/.test(r))throw new Error(`signer: invalid ${t}`);return r}function ae(e,t){return Object.entries(e||{}).find(([r])=>r.toLowerCase()===t)?.[1]}function Re(e,t){let r=e?.anvilQuote;if(!r||typeof r!="object"||Array.isArray(r))throw new Error("signer: exact prepared Anvil quote is required");if(!e?.artifact?.anvilQuote||JSON.stringify(e.artifact.anvilQuote)!==JSON.stringify(r))throw new Error("signer: exact prepared Anvil quote artifact mismatch");return Object.freeze(t==="buy"?{totalCostRaw:BigInt(r.totalCostRaw).toString(),baseCostRaw:BigInt(r.baseCostRaw).toString(),feeRaw:BigInt(r.feeRaw).toString(),protocolFeeRaw:BigInt(r.protocolFeeRaw).toString(),available:r.available===!0}:{netPayoutRaw:BigInt(r.netPayoutRaw).toString(),grossPayoutRaw:BigInt(r.grossPayoutRaw).toString(),feeRaw:BigInt(r.feeRaw).toString(),protocolFeeRaw:BigInt(r.protocolFeeRaw).toString()})}function $e(e,t,r){if(e.preconditions?.exactQuoteConfirmed!==!0)throw new Error("signer: exact prepared Anvil quote confirmation required");let a=e.artifact,p=t==="buy"?[r.totalCostRaw,e.maxPaymentTokenAmountRaw,a?.maxPaymentTokenAmountRaw,e.exactQuoteTotalCostRaw,a?.exactQuoteTotalCostRaw,e.preconditions?.confirmedTotalCostRaw]:[r.netPayoutRaw,e.minPayoutRaw,a?.minPayoutRaw,e.exactQuoteNetPayoutRaw,a?.exactQuoteNetPayoutRaw,e.preconditions?.confirmedNetPayoutRaw],n;try{n=BigInt(p[0]);for(let g of p.slice(1))if(BigInt(g)!==n)throw new Error("mismatch")}catch{throw new Error(`signer: exact Anvil ${t} settlement limit mismatch`)}let d=a?.transactions;if(!Array.isArray(d)||d.length!==1)throw new Error("signer: exact Anvil action transaction required");let h=t==="buy"?"buySpecificNFT":"sellNFT",f;try{if(f=u.decodeFunctionData(h,d[0].data),u.encodeFunctionData(h,[f[0],f[1]]).toLowerCase()!==String(d[0].data).toLowerCase())throw new Error("non-canonical")}catch{throw new Error(`signer: exact Anvil ${t} calldata required`)}if(BigInt(f[0])!==BigInt(e.tokenId)||BigInt(f[1])!==n)throw new Error(`signer: exact Anvil ${t} calldata limit mismatch`);return n}async function l(e,t,r,a,p,n=[]){let d=await e.send("eth_call",[{to:t,data:r.encodeFunctionData(a,n)},p]);return r.decodeFunctionResult(a,d)[0]}async function se(e,t,r,{nowMs:a=Date.now(),signerAddress:p}={}){if(t?.surface!=="evm-nft"||String(t?.provider).toLowerCase()!=="anvil-nft")return null;if(!e||typeof e.send!="function")throw new Error("signer: trusted RPC cannot attest Anvil market");let n=c(t.destination,"Anvil market"),d=c(t.contract,"Anvil collection"),h=c(t.paymentToken,"Anvil payment token"),f=BigInt(t.nativeSwapFeeWei),g=Number(t.paymentTokenDecimals),y=c(p,"Anvil signer identity"),ce=c(t.owner,"Anvil envelope owner");if(y!==ce)throw new Error("signer: Anvil signer identity mismatch");let m=BigInt(t.tokenId);if(m<0n)throw new Error("signer: invalid Anvil tokenId");let w=String(t.nftAction||"").toLowerCase();if(w!=="buy"&&w!=="sell")throw new Error("signer: unsupported Anvil NFT action");let T=Re(t,w),N=$e(t,w,T),b=t.anvilAttestation;if(!b||typeof b!="object"||Number(b.snapshotExpiresAtMs)<=Number(a))throw new Error("signer: fresh provider Anvil attestation required");let O=String(ae(r.anvilRuntimeCodeHashes,n)||"").toLowerCase();if(!/^0x[0-9a-f]{64}$/.test(O)||O!==String(b.runtimeCodeHash||"").toLowerCase())throw new Error("signer: Anvil runtime is not reviewed by policy");let z=ae(r.nftPaymentTokenCaps,h);if(!z||Number(z.decimals)!==g)throw new Error("signer: Anvil payment token decimals are not reviewed by policy");let V=String(await e.send("eth_chainId",[])).toLowerCase();if(!/^0x(?:0|[1-9a-f][0-9a-f]*)$/.test(V)||BigInt(V)!==4663n)throw new Error("signer: trusted RPC Anvil chain mismatch");let x=String(await e.send("eth_blockNumber",[])).toLowerCase();if(!/^0x(?:0|[1-9a-f][0-9a-f]*)$/.test(x))throw new Error("signer: trusted RPC returned an invalid Anvil block number");let ue=BigInt(x),G=await e.send("eth_getBlockByNumber",[x,!1]),L=String(G?.hash||"").toLowerCase();if(String(G?.number||"").toLowerCase()!==x||!/^0x[0-9a-f]{64}$/.test(L))throw new Error("signer: trusted RPC returned an invalid Anvil block attestation");let i=Object.freeze({blockHash:L,requireCanonical:!0}),B=String(await e.send("eth_getCode",[n,i])).toLowerCase();if(!/^0x[0-9a-f]+$/.test(B)||B==="0x")throw new Error("signer: Anvil market runtime is empty");let K=Pe(B).toLowerCase();if(K!==O)throw new Error("signer: Anvil market runtime mismatch with reviewed policy");let[le,de,fe]=await Promise.all([l(e,n,u,"collection",i),l(e,n,u,"token",i),l(e,n,u,"robinhoodSwapFeeWei",i)]),E=c(le,"live Anvil collection"),S=c(de,"live Anvil payment token"),Y=BigInt(fe).toString();if(E!==d)throw new Error("signer: live Anvil collection mismatch");if(S!==h)throw new Error("signer: live Anvil payment token mismatch");if(Y!==f.toString())throw new Error("signer: live Anvil native swap fee mismatch");let C=Number(await l(e,S,ie,"decimals",i));if(!Number.isSafeInteger(C)||C!==g)throw new Error("signer: live Anvil payment token decimals mismatch");let P=c(await l(e,E,H,"ownerOf",i,[m]),"live Anvil token owner"),R=null,A=null,v=null,I=null,o;if(w==="buy"){let[$,F,_]=await Promise.all([l(e,n,u,"inventory",i,[m]),l(e,S,ie,"allowance",i,[y,n]),e.send("eth_call",[{to:n,data:u.encodeFunctionData("quoteSpecificBuy",[m])},i])]);R=!!$,A=BigInt(F).toString();let s=u.decodeFunctionResult("quoteSpecificBuy",_);if(o=Object.freeze({totalCostRaw:BigInt(s[0]).toString(),baseCostRaw:BigInt(s[1]).toString(),feeRaw:BigInt(s[2]).toString(),protocolFeeRaw:BigInt(s[3]).toString(),available:!!s[4]}),JSON.stringify(o)!==JSON.stringify(T))throw new Error("signer: exact Anvil buy quote changed after preparation");if(P!==n)throw new Error("signer: exact Anvil token owner is not the market");if(!R)throw new Error("signer: exact Anvil token is not in market inventory");if(BigInt(A)!==BigInt(t.preconditions?.allowanceRaw))throw new Error("signer: live Anvil ERC20 allowance changed after preparation");if(BigInt(A)<N)throw new Error("signer: live Anvil ERC20 allowance is insufficient");if(!o.available)throw new Error("signer: exact Anvil buy quote is unavailable");if(BigInt(o.totalCostRaw)!==N)throw new Error("signer: live Anvil buy quote does not equal exact payment limit");if(BigInt(o.totalCostRaw)!==BigInt(o.baseCostRaw)+BigInt(o.feeRaw)+BigInt(o.protocolFeeRaw))throw new Error("signer: exact Anvil buy quote fee arithmetic mismatch")}else{let[$,F,_]=await Promise.all([l(e,E,H,"getApproved",i,[m]),l(e,E,H,"isApprovedForAll",i,[y,n]),e.send("eth_call",[{to:n,data:u.encodeFunctionData("quoteSellNFT")},i])]);v=c($,"live Anvil token approval"),I=!!F;let s=u.decodeFunctionResult("quoteSellNFT",_);if(o=Object.freeze({netPayoutRaw:BigInt(s[0]).toString(),grossPayoutRaw:BigInt(s[1]).toString(),feeRaw:BigInt(s[2]).toString(),protocolFeeRaw:BigInt(s[3]).toString()}),JSON.stringify(o)!==JSON.stringify(T))throw new Error("signer: exact Anvil sell quote changed after preparation");if(P!==y)throw new Error("signer: exact Anvil token owner does not match signer");if(v!==n&&!I)throw new Error("signer: live Anvil NFT approval is insufficient");if(v!==c(t.preconditions?.approvedAddress,"prepared Anvil token approval")||I!==!!t.preconditions?.approvedForAll)throw new Error("signer: live Anvil NFT approval changed after preparation");if(BigInt(o.netPayoutRaw)!==N)throw new Error("signer: live Anvil sell quote does not equal exact payout limit");if(BigInt(o.netPayoutRaw)+BigInt(o.feeRaw)+BigInt(o.protocolFeeRaw)!==BigInt(o.grossPayoutRaw))throw new Error("signer: exact Anvil sell quote fee arithmetic mismatch")}return Object.freeze({source:"local-signer-trusted-rpc",chainId:4663,market:n,collection:E,paymentToken:S,paymentTokenDecimals:C,nativeSwapFeeWei:Y,signerAddress:y,nftAction:w,tokenId:m.toString(),tokenOwner:P,inventoryMember:R,allowanceRaw:A,approvedAddress:v,approvedForAll:I,quote:o,blockNumber:ue.toString(),blockHash:L,runtimeCodeHash:K,verifiedAtMs:Number(a)})}try{let e=JSON.parse(Fe.readFileSync(0,"utf8")),t=new _e(e.rpcUrl,Number(e.chainId)),r=await se(t,e.envelope,e.policy,{nowMs:Number(e.nowMs),signerAddress:e.signerAddress});process.stdout.write(JSON.stringify(r))}catch(e){process.stderr.write(`Anvil attestation failed: ${String(e?.message||e)}
|
|
2
2
|
`),process.exitCode=1}
|