@oracle-agent/oracle 0.29.0 → 0.31.0
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/README.md +1 -1
- package/dist/assets/skills/oracle-desk-product/SKILL.md +1 -1
- package/dist/bin/desk-server.mjs +28 -28
- package/dist/bin/oracle-data-mcp.mjs +11 -11
- package/dist/bin/oracle-gateway.mjs +37 -37
- package/dist/cli/commands/chat.mjs +154 -154
- package/dist/cli/commands/doctor.mjs +4 -4
- package/dist/cli/commands/eval.mjs +88 -88
- package/dist/cli/commands/model.mjs +158 -158
- package/dist/cli/commands/receipt.mjs +3 -3
- package/dist/cli/commands/sign.mjs +14 -14
- package/dist/cli/commands/signer.mjs +16 -13
- package/dist/cli/commands/strategy.mjs +5 -5
- package/dist/cli/commands/venues.mjs +3 -3
- package/dist/data/desk-data.mjs +26 -26
- package/dist/index.mjs +40 -40
- package/dist/local-signer/anvil-attestation-worker.mjs +1 -1
- package/dist/local-signer/index.mjs +3 -3
- package/dist/local-signer/runtime.mjs +13 -10
- package/dist/strategy/index.mjs +3 -3
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import We from"node:fs";import{JsonRpcProvider as He}from"ethers";import{Interface as J,keccak256 as De}from"ethers";import{Transaction as _i}from"@scure/btc-signer";import{ed25519 as Mi}from"@noble/curves/ed25519.js";import{base58 as lo}from"@scure/base";import{Interface as te}from"ethers";import{Interface as ge,MaxUint256 as Sr,isAddress as vr,keccak256 as kr,toUtf8Bytes as Tr}from"ethers";import{Interface as we,isAddress as or}from"ethers";import{isAddress as Qe}from"ethers";var cr=new we(["function approve(address spender,uint256 amount) returns (bool)"]);import{Interface as he,isAddress as dr}from"ethers";var wr=new he(["function approve(address spender,uint256 amount) returns (bool)"]),hr=Object.freeze({42161:"0x1c3fa76e6e1088bce750f23a5bfcffa1efef6a41",43114:"0x8f550e53dfe96c055d5bdb267c21f268fcaf63b2"});var Br=new ge(["function approve(address spender,uint256 amount) returns (bool)"]);var Rr=300*1e3,$r=(()=>{let e=Number(process.env.ORACLE_PREPARE_HARD_MAX_AGE_MS);return Number.isFinite(e)&&e>0?e:1800*1e3})();import{Address as Dr,NETWORK as Ur,OutScript as jr,RawTx as Wr,SigHash as Hr,TEST_NETWORK as Jr,Transaction as zr}from"@scure/btc-signer";import{createHash as be}from"node:crypto";import{base58 as Yr}from"@scure/base";import{getCompiledTransactionMessageDecoder as Qr}from"@solana/transaction-messages";var X=e=>be("sha256").update(`global:${e}`).digest().subarray(0,8).toString("hex"),Zr=new Map([[X("route"),{name:"route",prefixBytes:0}],[X("shared_accounts_route"),{name:"shared_accounts_route",prefixBytes:1}]]);var st=64*1024;var yt=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"}),bt=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 At="0x"+"00".repeat(32);var xe=Object.freeze([["salt","uint256"],["maker","address"],["signer","address"],["tokenId","uint256"],["makerAmount","uint256"],["takerAmount","uint256"],["side","uint8"],["signatureType","uint8"],["timestamp","uint256"],["metadata","bytes32"],["builder","bytes32"]]),It=Object.freeze(xe.map(e=>e[0]));import{TypedDataEncoder as on,getAddress as an}from"ethers";import{TypedDataEncoder as Bt,getAddress as Pt,isAddress as Rt}from"ethers";var Se=Object.freeze({1:"0x111111125421cA6dc452d289314280a0f8842A65",8453:"0x111111125421cA6dc452d289314280a0f8842A65",42161:"0x111111125421cA6dc452d289314280a0f8842A65",10:"0x111111125421cA6dc452d289314280a0f8842A65",137:"0x111111125421cA6dc452d289314280a0f8842A65",56:"0x111111125421cA6dc452d289314280a0f8842A65"}),ve=Object.freeze({Order:[{name:"salt",type:"uint256"},{name:"maker",type:"address"},{name:"receiver",type:"address"},{name:"makerAsset",type:"address"},{name:"takerAsset",type:"address"},{name:"makingAmount",type:"uint256"},{name:"takingAmount",type:"uint256"},{name:"makerTraits",type:"uint256"}]});import{TypedDataEncoder as Jt,getAddress as zt,isAddress as Gt}from"ethers";var Ft=Object.freeze({READ:"read",PREPARE:"prepare",EXECUTE:"execute",AUTONOMOUS:"autonomous"});var ke=Object.freeze({1:"0x9008D19f58AAbD9eD0D60971565AA8510560ab41",100:"0x9008D19f58AAbD9eD0D60971565AA8510560ab41",42161:"0x9008D19f58AAbD9eD0D60971565AA8510560ab41",8453:"0x9008D19f58AAbD9eD0D60971565AA8510560ab41"}),en=Object.freeze({1:"0xC92E8bdf79f0507f65a392b0ab4667716BFE0110",100:"0xC92E8bdf79f0507f65a392b0ab4667716BFE0110",42161:"0xC92E8bdf79f0507f65a392b0ab4667716BFE0110",8453:"0xC92E8bdf79f0507f65a392b0ab4667716BFE0110"});var Te=Object.freeze({Order:[{name:"sellToken",type:"address"},{name:"buyToken",type:"address"},{name:"receiver",type:"address"},{name:"sellAmount",type:"uint256"},{name:"buyAmount",type:"uint256"},{name:"validTo",type:"uint32"},{name:"appData",type:"bytes32"},{name:"feeAmount",type:"uint256"},{name:"kind",type:"string"},{name:"partiallyFillable",type:"bool"},{name:"sellTokenBalance",type:"string"},{name:"buyTokenBalance",type:"string"}]}),rn=Object.freeze({OrderCancellations:[{name:"orderUids",type:"bytes[]"}]});var un=Object.freeze(["https://limit-orders.1inch.io","https://api.1inch.dev/orderbook"]);var Be=new Set(["evm","evm-swap","evm-bridge","evm-nft","evm-order","btc","sol","hl","poly","lighter"]);var Tn=Object.freeze({swap:5,bridge:5,perps:0,nft:0,mint:0,transfer:0,approve:0,delegate:0,identity:0,order:0,cancel:0,leverage:0,margin:0,approveBuilder:0,stake:0,unstake:0});var Pe=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"}}),In=Object.freeze({"0x161ac21f":{provider:"opensea-nft",action:"mint",layout:"seadrop-mint-public"},"0xc2f6663a":{provider:"opensea-nft",action:"mint",layout:"seadrop-mint-allowlist"}}),On=new te(["function buySpecificNFT(uint256 tokenId,uint256 maxCost) payable","function sellNFT(uint256 tokenId,uint256 minPayout) payable"]),Nn=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"]),Cn=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 Re=Object.freeze([...Be]),Ln=Object.freeze({...Pe});import{ed25519 as Gn}from"@noble/curves/ed25519.js";import{base58 as Kn}from"@scure/base";import{RawTx as Xn,SigHash as Qn,Transaction as Zn}from"@scure/btc-signer";import{Transaction as ro,keccak256 as to,verifyTypedData as no}from"ethers";import{encode as Rn}from"@msgpack/msgpack";import{keccak256 as _n,verifyTypedData as Fn}from"ethers";var Mn=Object.freeze({name:"Exchange",version:"1",chainId:1337,verifyingContract:"0x0000000000000000000000000000000000000000"}),qn=Object.freeze({Agent:[{name:"source",type:"string"},{name:"connectionId",type:"bytes32"}]});var So=Object.freeze({N:1<<17,r:8,p:1}),vo=256*1024*1024,ko=16*1024;var Io=Object.freeze({1:{name:"ethereum",mode:"mempool-private",endpoints:["https://rpc.flashbots.net/fast","https://rpc.mevblocker.io"]},8453:{name:"base",mode:"sequencer",endpoints:["https://mainnet-sequencer.base.org"]},10:{name:"optimism",mode:"sequencer",endpoints:["https://mainnet-sequencer.optimism.io"]},42161:{name:"arbitrum",mode:"sequencer",endpoints:["https://arb1-sequencer.arbitrum.io/rpc"]},56:{name:"bsc",mode:"mempool-private",endpoints:["https://rpc.48.club","https://bsc.rpc.blxrbdn.com"]},137:{name:"polygon",mode:"mempool-private",endpoints:["https://polygon-bor-rpc.publicnode.com"]},43114:{name:"avalanche",mode:"public-only",endpoints:[]},999:{name:"hyperevm",mode:"public-only",endpoints:[]}});import{homedir as j}from"node:os";import{join as W}from"node:path";var oe=process.env.ORACLE_PUBLIC_DESKTOP==="1",Fe=oe?process.env.ORACLE_CONFIG_DIR||W(j(),".config","oracle"):W(j(),".config","oracle"),Lo=oe?Fe:W(j(),".config","mad-desk");var _o="0".repeat(64),Fo=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 Mo=Promise.resolve();import{Wallet as Vo}from"ethers";import{base58 as Yo}from"@scure/base";import{ed25519 as Qo}from"@noble/curves/ed25519.js";import{NETWORK as ei,TEST_NETWORK as ri,WIF as ti,p2wpkh as ni}from"@scure/btc-signer";import{pubECDSA as ii}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,r){let t=String(e||"").toLowerCase();if(!/^0x[0-9a-f]{40}$/.test(t))throw new Error(`signer: invalid ${r}`);return t}function ae(e,r){return Object.entries(e||{}).find(([t])=>t.toLowerCase()===r)?.[1]}function Ue(e,r){let t=e?.anvilQuote;if(!t||typeof t!="object"||Array.isArray(t))throw new Error("signer: exact prepared Anvil quote is required");if(!e?.artifact?.anvilQuote||JSON.stringify(e.artifact.anvilQuote)!==JSON.stringify(t))throw new Error("signer: exact prepared Anvil quote artifact mismatch");return Object.freeze(r==="buy"?{totalCostRaw:BigInt(t.totalCostRaw).toString(),baseCostRaw:BigInt(t.baseCostRaw).toString(),feeRaw:BigInt(t.feeRaw).toString(),protocolFeeRaw:BigInt(t.protocolFeeRaw).toString(),available:t.available===!0}:{netPayoutRaw:BigInt(t.netPayoutRaw).toString(),grossPayoutRaw:BigInt(t.grossPayoutRaw).toString(),feeRaw:BigInt(t.feeRaw).toString(),protocolFeeRaw:BigInt(t.protocolFeeRaw).toString()})}function je(e,r,t){if(e.preconditions?.exactQuoteConfirmed!==!0)throw new Error("signer: exact prepared Anvil quote confirmation required");let a=e.artifact,p=r==="buy"?[t.totalCostRaw,e.maxPaymentTokenAmountRaw,a?.maxPaymentTokenAmountRaw,e.exactQuoteTotalCostRaw,a?.exactQuoteTotalCostRaw,e.preconditions?.confirmedTotalCostRaw]:[t.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 ${r} 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=r==="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 ${r} calldata required`)}if(BigInt(f[0])!==BigInt(e.tokenId)||BigInt(f[1])!==n)throw new Error(`signer: exact Anvil ${r} calldata limit mismatch`);return n}async function l(e,r,t,a,p,n=[]){let d=await e.send("eth_call",[{to:r,data:t.encodeFunctionData(a,n)},p]);return t.decodeFunctionResult(a,d)[0]}async function se(e,r,t,{nowMs:a=Date.now(),signerAddress:p}={}){if(r?.surface!=="evm-nft"||String(r?.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(r.destination,"Anvil market"),d=c(r.contract,"Anvil collection"),h=c(r.paymentToken,"Anvil payment token"),f=BigInt(r.nativeSwapFeeWei),g=Number(r.paymentTokenDecimals),y=c(p,"Anvil signer identity"),ce=c(r.owner,"Anvil envelope owner");if(y!==ce)throw new Error("signer: Anvil signer identity mismatch");let m=BigInt(r.tokenId);if(m<0n)throw new Error("signer: invalid Anvil tokenId");let w=String(r.nftAction||"").toLowerCase();if(w!=="buy"&&w!=="sell")throw new Error("signer: unsupported Anvil NFT action");let I=Ue(r,w),O=je(r,w,I),E=r.anvilAttestation;if(!E||typeof E!="object"||Number(E.snapshotExpiresAtMs)<=Number(a))throw new Error("signer: fresh provider Anvil attestation required");let N=String(ae(t.anvilRuntimeCodeHashes,n)||"").toLowerCase();if(!/^0x[0-9a-f]{64}$/.test(N)||N!==String(E.runtimeCodeHash||"").toLowerCase())throw new Error("signer: Anvil runtime is not reviewed by policy");let z=ae(t.nftPaymentTokenCaps,h);if(!z||Number(z.decimals)!==g)throw new Error("signer: Anvil payment token decimals are not reviewed by policy");let G=String(await e.send("eth_chainId",[])).toLowerCase();if(!/^0x(?:0|[1-9a-f][0-9a-f]*)$/.test(G)||BigInt(G)!==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),V=await e.send("eth_getBlockByNumber",[x,!1]),C=String(V?.hash||"").toLowerCase();if(String(V?.number||"").toLowerCase()!==x||!/^0x[0-9a-f]{64}$/.test(C))throw new Error("signer: trusted RPC returned an invalid Anvil block attestation");let i=Object.freeze({blockHash:C,requireCanonical:!0}),L=String(await e.send("eth_getCode",[n,i])).toLowerCase();if(!/^0x[0-9a-f]+$/.test(L)||L==="0x")throw new Error("signer: Anvil market runtime is empty");let K=De(L).toLowerCase();if(K!==N)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)]),b=c(le,"live Anvil collection"),A=c(de,"live Anvil payment token"),Y=BigInt(fe).toString();if(b!==d)throw new Error("signer: live Anvil collection mismatch");if(A!==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 B=Number(await l(e,A,ie,"decimals",i));if(!Number.isSafeInteger(B)||B!==g)throw new Error("signer: live Anvil payment token decimals mismatch");let P=c(await l(e,b,H,"ownerOf",i,[m]),"live Anvil token owner"),R=null,S=null,v=null,k=null,o;if(w==="buy"){let[$,_,F]=await Promise.all([l(e,n,u,"inventory",i,[m]),l(e,A,ie,"allowance",i,[y,n]),e.send("eth_call",[{to:n,data:u.encodeFunctionData("quoteSpecificBuy",[m])},i])]);R=!!$,S=BigInt(_).toString();let s=u.decodeFunctionResult("quoteSpecificBuy",F);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(I))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(S)!==BigInt(r.preconditions?.allowanceRaw))throw new Error("signer: live Anvil ERC20 allowance changed after preparation");if(BigInt(S)<O)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)!==O)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,b,H,"getApproved",i,[m]),l(e,b,H,"isApprovedForAll",i,[y,n]),e.send("eth_call",[{to:n,data:u.encodeFunctionData("quoteSellNFT")},i])]);v=c($,"live Anvil token approval"),k=!!_;let s=u.decodeFunctionResult("quoteSellNFT",F);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(I))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&&!k)throw new Error("signer: live Anvil NFT approval is insufficient");if(v!==c(r.preconditions?.approvedAddress,"prepared Anvil token approval")||k!==!!r.preconditions?.approvedForAll)throw new Error("signer: live Anvil NFT approval changed after preparation");if(BigInt(o.netPayoutRaw)!==O)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:b,paymentToken:A,paymentTokenDecimals:B,nativeSwapFeeWei:Y,signerAddress:y,nftAction:w,tokenId:m.toString(),tokenOwner:P,inventoryMember:R,allowanceRaw:S,approvedAddress:v,approvedForAll:k,quote:o,blockNumber:ue.toString(),blockHash:C,runtimeCodeHash:K,verifiedAtMs:Number(a)})}try{let e=JSON.parse(We.readFileSync(0,"utf8")),r=new He(e.rpcUrl,Number(e.chainId)),t=await se(r,e.envelope,e.policy,{nowMs:Number(e.nowMs),signerAddress:e.signerAddress});process.stdout.write(JSON.stringify(t))}catch(e){process.stderr.write(`Anvil attestation failed: ${String(e?.message||e)}
|
|
1
|
+
import Ge from"node:fs";import{JsonRpcProvider as Ve}from"ethers";import{Interface as J,keccak256 as We}from"ethers";import{Transaction as Ea}from"@scure/btc-signer";import{ed25519 as Sa}from"@noble/curves/ed25519.js";import{base58 as wo}from"@scure/base";import{Interface as ne}from"ethers";import{Interface as Ee,MaxUint256 as Tt,isAddress as Ot,keccak256 as Ct,toUtf8Bytes as Nt}from"ethers";import{Interface as ye,isAddress as ct}from"ethers";import{isAddress as rt}from"ethers";var ft=new ye(["function approve(address spender,uint256 amount) returns (bool)"]);import{Interface as be,isAddress as wt}from"ethers";var bt=new be(["function approve(address spender,uint256 amount) returns (bool)"]),Et=Object.freeze({42161:"0x1c3fa76e6e1088bce750f23a5bfcffa1efef6a41",43114:"0x8f550e53dfe96c055d5bdb267c21f268fcaf63b2"});var Rt=new Ee(["function approve(address spender,uint256 amount) returns (bool)"]);var Mt=300*1e3,qt=(()=>{let e=Number(process.env.ORACLE_PREPARE_HARD_MAX_AGE_MS);return Number.isFinite(e)&&e>0?e:1800*1e3})();import{Address as Wt,NETWORK as Ht,OutScript as Jt,RawTx as Gt,SigHash as Vt,TEST_NETWORK as Kt,Transaction as Xt}from"@scure/btc-signer";import{createHash as Se}from"node:crypto";import{base58 as er}from"@scure/base";import{getCompiledTransactionMessageDecoder as rr}from"@solana/transaction-messages";var Y=e=>Se("sha256").update(`global:${e}`).digest().subarray(0,8).toString("hex"),nr=new Map([[Y("route"),{name:"route",prefixBytes:0}],[Y("shared_accounts_route"),{name:"shared_accounts_route",prefixBytes:1}]]);var dr=64*1024;var Sr=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"}),Ar=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 kr="0x"+"00".repeat(32);var ve=Object.freeze([["salt","uint256"],["maker","address"],["signer","address"],["tokenId","uint256"],["makerAmount","uint256"],["takerAmount","uint256"],["side","uint8"],["signatureType","uint8"],["timestamp","uint256"],["metadata","bytes32"],["builder","bytes32"]]),Lr=Object.freeze(ve.map(e=>e[0]));import{TypedDataEncoder as un,getAddress as ln}from"ethers";import{TypedDataEncoder as Rr,getAddress as Fr,isAddress as Mr}from"ethers";var ke=Object.freeze({1:"0x111111125421cA6dc452d289314280a0f8842A65",8453:"0x111111125421cA6dc452d289314280a0f8842A65",42161:"0x111111125421cA6dc452d289314280a0f8842A65",10:"0x111111125421cA6dc452d289314280a0f8842A65",137:"0x111111125421cA6dc452d289314280a0f8842A65",56:"0x111111125421cA6dc452d289314280a0f8842A65"}),Te=Object.freeze({Order:[{name:"salt",type:"uint256"},{name:"maker",type:"address"},{name:"receiver",type:"address"},{name:"makerAsset",type:"address"},{name:"takerAsset",type:"address"},{name:"makingAmount",type:"uint256"},{name:"takingAmount",type:"uint256"},{name:"makerTraits",type:"uint256"}]});import{TypedDataEncoder as Kr,getAddress as Xr,isAddress as Qr}from"ethers";var jr=Object.freeze({READ:"read",PREPARE:"prepare",EXECUTE:"execute",AUTONOMOUS:"autonomous"});var Oe=Object.freeze({1:"0x9008D19f58AAbD9eD0D60971565AA8510560ab41",100:"0x9008D19f58AAbD9eD0D60971565AA8510560ab41",42161:"0x9008D19f58AAbD9eD0D60971565AA8510560ab41",8453:"0x9008D19f58AAbD9eD0D60971565AA8510560ab41"}),on=Object.freeze({1:"0xC92E8bdf79f0507f65a392b0ab4667716BFE0110",100:"0xC92E8bdf79f0507f65a392b0ab4667716BFE0110",42161:"0xC92E8bdf79f0507f65a392b0ab4667716BFE0110",8453:"0xC92E8bdf79f0507f65a392b0ab4667716BFE0110"});var Ce=Object.freeze({Order:[{name:"sellToken",type:"address"},{name:"buyToken",type:"address"},{name:"receiver",type:"address"},{name:"sellAmount",type:"uint256"},{name:"buyAmount",type:"uint256"},{name:"validTo",type:"uint32"},{name:"appData",type:"bytes32"},{name:"feeAmount",type:"uint256"},{name:"kind",type:"string"},{name:"partiallyFillable",type:"bool"},{name:"sellTokenBalance",type:"string"},{name:"buyTokenBalance",type:"string"}]}),an=Object.freeze({OrderCancellations:[{name:"orderUids",type:"bytes[]"}]});var pn=Object.freeze(["https://limit-orders.1inch.io","https://api.1inch.dev/orderbook"]);var _e=new Set(["evm","evm-swap","evm-bridge","evm-nft","evm-order","btc","sol","hl","poly","lighter"]);var Nn=Object.freeze({swap:5,bridge:5,perps:0,nft:0,mint:0,transfer:0,approve:0,delegate:0,identity:0,order:0,cancel:0,leverage:0,margin:0,approveBuilder:0,stake:0,unstake:0});var Re=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"}}),Ln=Object.freeze({"0x161ac21f":{provider:"opensea-nft",action:"mint",layout:"seadrop-mint-public"},"0xc2f6663a":{provider:"opensea-nft",action:"mint",layout:"seadrop-mint-allowlist"}}),Bn=new ne(["function buySpecificNFT(uint256 tokenId,uint256 maxCost) payable","function sellNFT(uint256 tokenId,uint256 minPayout) payable"]),Pn=new ne(["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"]),$n=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 Fe=Object.freeze([..._e]),_n=Object.freeze({...Re});import{ed25519 as Qn}from"@noble/curves/ed25519.js";import{base58 as Zn}from"@scure/base";import{RawTx as to,SigHash as ro,Transaction as no}from"@scure/btc-signer";import{Transaction as io,keccak256 as ao,verifyTypedData as so}from"ethers";import{encode as Mn}from"@msgpack/msgpack";import{keccak256 as Dn,verifyTypedData as jn}from"ethers";var Un=Object.freeze({name:"Exchange",version:"1",chainId:1337,verifyingContract:"0x0000000000000000000000000000000000000000"}),zn=Object.freeze({Agent:[{name:"source",type:"string"},{name:"connectionId",type:"bytes32"}]});var To=Object.freeze({N:1<<17,r:8,p:1}),Oo=256*1024*1024,Co=16*1024;var Lo=Object.freeze({1:{name:"ethereum",mode:"mempool-private",endpoints:["https://rpc.flashbots.net/fast","https://rpc.mevblocker.io"]},8453:{name:"base",mode:"sequencer",endpoints:["https://mainnet-sequencer.base.org"]},10:{name:"optimism",mode:"sequencer",endpoints:["https://mainnet-sequencer.optimism.io"]},42161:{name:"arbitrum",mode:"sequencer",endpoints:["https://arb1-sequencer.arbitrum.io/rpc"]},56:{name:"bsc",mode:"mempool-private",endpoints:["https://rpc.48.club","https://bsc.rpc.blxrbdn.com"]},137:{name:"polygon",mode:"mempool-private",endpoints:["https://polygon-bor-rpc.publicnode.com"]},43114:{name:"avalanche",mode:"public-only",endpoints:[]},999:{name:"hyperevm",mode:"public-only",endpoints:[]}});import{homedir as U}from"node:os";import{join as z}from"node:path";var ie=process.env.ORACLE_PUBLIC_DESKTOP==="1",De=ie?process.env.ORACLE_CONFIG_DIR||z(U(),".config","oracle"):z(U(),".config","oracle"),_o=ie?De:z(U(),".config","mad-desk");var Do="0".repeat(64),jo=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 Uo=Promise.resolve();import{Wallet as Yo}from"ethers";import{base58 as ei}from"@scure/base";import{ed25519 as ri}from"@noble/curves/ed25519.js";import{NETWORK as oi,TEST_NETWORK as ii,WIF as ai,p2wpkh as si}from"@scure/btc-signer";import{pubECDSA as ui}from"@scure/btc-signer/utils.js";var fi=Object.freeze(["spot-limit-create","spot-limit-cancel","spot-order-status"]),pi=Object.freeze(["binance","bybit","okx","coinbase"]),mi=Object.freeze({binance:"https://api.binance.com",bybit:"https://api.bybit.com",okx:"https://openapi.okx.com",coinbase:"https://api.exchange.coinbase.com"}),wi=Object.freeze({binance:"/api/v3",bybit:"/v5/order",okx:"/api/v5/trade",coinbase:"/orders"}),hi=Object.freeze(["version","surface","kind","venue","credentialRef","symbol","base","quote","side","baseSize","limitPrice","maxQuoteNotional","timeInForce","clientOrderId","expiresAtMs","venueOrderId","nonce","grantId","artifactHash"]),gi=Object.freeze(["market-create","withdraw","transfer","subaccount","leverage","futures","margin","convert","api-key"]),yi=Object.freeze(["url","host","path","method","headers","signature","apiKey","apiSecret","passphrase","privateKey","redirect","proxy"]),bi=Object.freeze(["ccxt","binance-api-node","node-binance-api","coinbase-advanced-node","@okx-dex/okx-dex-sdk","bybit-api"]),Ei=Object.freeze({perOrderQuote:"sealed-owner-policy",dailyGrossQuote:"sealed-owner-policy",scope:Object.freeze(["per-order","UTC-day","account","venue","quote"]),envelopeFieldIsNotCeiling:!0}),xi=Object.freeze({binanceRecvWindowMs:5e3,bybitWindowMs:5e3,maxLocalSkewMs:2e3}),Si=Object.freeze({perSecond:1,perMinute:30,bind:"tighter"});var ze=Object.freeze({binance:Object.freeze({create:["POST","/api/v3/order"],cancel:["DELETE","/api/v3/order"],status:["GET","/api/v3/order"]}),bybit:Object.freeze({create:["POST","/v5/order/create"],cancel:["POST","/v5/order/cancel"],status:["GET","/v5/order/realtime"]}),okx:Object.freeze({create:["POST","/api/v5/trade/order"],cancel:["POST","/api/v5/trade/cancel-order"],status:["GET","/api/v5/trade/order"]}),coinbase:Object.freeze({create:["POST","/orders"],cancel:["DELETE","/orders/{order_id}"],status:["GET","/orders/{order_id}"]})}),se=Object.freeze({binance:"https://api.binance.com",bybit:"https://api.bybit.com",okx:"https://openapi.okx.com",coinbase:"https://api.exchange.coinbase.com"});var Bi=256*1024;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"]),ce=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 ue(e,t){return Object.entries(e||{}).find(([r])=>r.toLowerCase()===t)?.[1]}function He(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 Je(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 le(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"),de=c(t.owner,"Anvil envelope owner");if(y!==de)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=He(t,w),O=Je(t,w,T),E=t.anvilAttestation;if(!E||typeof E!="object"||Number(E.snapshotExpiresAtMs)<=Number(a))throw new Error("signer: fresh provider Anvil attestation required");let C=String(ue(r.anvilRuntimeCodeHashes,n)||"").toLowerCase();if(!/^0x[0-9a-f]{64}$/.test(C)||C!==String(E.runtimeCodeHash||"").toLowerCase())throw new Error("signer: Anvil runtime is not reviewed by policy");let G=ue(r.nftPaymentTokenCaps,h);if(!G||Number(G.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 fe=BigInt(x),K=await e.send("eth_getBlockByNumber",[x,!1]),N=String(K?.hash||"").toLowerCase();if(String(K?.number||"").toLowerCase()!==x||!/^0x[0-9a-f]{64}$/.test(N))throw new Error("signer: trusted RPC returned an invalid Anvil block attestation");let i=Object.freeze({blockHash:N,requireCanonical:!0}),L=String(await e.send("eth_getCode",[n,i])).toLowerCase();if(!/^0x[0-9a-f]+$/.test(L)||L==="0x")throw new Error("signer: Anvil market runtime is empty");let X=We(L).toLowerCase();if(X!==C)throw new Error("signer: Anvil market runtime mismatch with reviewed policy");let[pe,me,we]=await Promise.all([l(e,n,u,"collection",i),l(e,n,u,"token",i),l(e,n,u,"robinhoodSwapFeeWei",i)]),b=c(pe,"live Anvil collection"),S=c(me,"live Anvil payment token"),Q=BigInt(we).toString();if(b!==d)throw new Error("signer: live Anvil collection mismatch");if(S!==h)throw new Error("signer: live Anvil payment token mismatch");if(Q!==f.toString())throw new Error("signer: live Anvil native swap fee mismatch");let B=Number(await l(e,S,ce,"decimals",i));if(!Number.isSafeInteger(B)||B!==g)throw new Error("signer: live Anvil payment token decimals mismatch");let P=c(await l(e,b,H,"ownerOf",i,[m]),"live Anvil token owner"),$=null,A=null,v=null,I=null,o;if(w==="buy"){let[_,R,F]=await Promise.all([l(e,n,u,"inventory",i,[m]),l(e,S,ce,"allowance",i,[y,n]),e.send("eth_call",[{to:n,data:u.encodeFunctionData("quoteSpecificBuy",[m])},i])]);$=!!_,A=BigInt(R).toString();let s=u.decodeFunctionResult("quoteSpecificBuy",F);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(!$)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)<O)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)!==O)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[_,R,F]=await Promise.all([l(e,b,H,"getApproved",i,[m]),l(e,b,H,"isApprovedForAll",i,[y,n]),e.send("eth_call",[{to:n,data:u.encodeFunctionData("quoteSellNFT")},i])]);v=c(_,"live Anvil token approval"),I=!!R;let s=u.decodeFunctionResult("quoteSellNFT",F);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)!==O)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:b,paymentToken:S,paymentTokenDecimals:B,nativeSwapFeeWei:Q,signerAddress:y,nftAction:w,tokenId:m.toString(),tokenOwner:P,inventoryMember:$,allowanceRaw:A,approvedAddress:v,approvedForAll:I,quote:o,blockNumber:fe.toString(),blockHash:N,runtimeCodeHash:X,verifiedAtMs:Number(a)})}try{let e=JSON.parse(Ge.readFileSync(0,"utf8")),t=new Ve(e.rpcUrl,Number(e.chainId)),r=await le(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}
|