@moonpay/cli 1.31.0 → 1.33.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/dist/{chunk-J4VBRJS6.js → chunk-2CBFFXK6.js} +2 -2
- package/dist/{chunk-TWXXABZG.js → chunk-NRL3YIPT.js} +3 -3
- package/dist/{chunk-CIGFUBC2.js → chunk-PHXOVWSJ.js} +1 -1
- package/dist/{chunk-PVU4MEDX.js → chunk-SFNE2JF2.js} +1 -1
- package/dist/{client-6Z3DZSK2.js → client-5SOFUSPS.js} +1 -1
- package/dist/index.js +2 -2
- package/dist/{ledger-URJOD3KS.js → ledger-EYLA3JNM.js} +2 -2
- package/dist/{mcp-2O2HFTZL.js → mcp-EJQKDZ7X.js} +1 -1
- package/dist/{store-WM7ALY6L.js → store-WOL7ZY42.js} +1 -1
- package/package.json +1 -1
- package/skills/moonpay-portfolio/SKILL.md +240 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
|
|
2
|
-
import{b as m,d as b}from"./chunk-LMDE72OE.js";var G={};b(G,{decrypt:()=>k,encrypt:()=>T,encryptedFileSchema:()=>O});import{randomBytes as A,scryptSync as v,createCipheriv as X,createDecipheriv as $}from"crypto";import{z as i}from"zod";function T(n,t){let r=A(32),o=v(t,r,D,{N:R,r:L,p:F,maxmem:K}),s=A(12),c=X("aes-256-gcm",o,s),_=Buffer.concat([c.update(n,"utf8"),c.final()]);return{encryption:{cipher:"aes-256-gcm",kdf:"scrypt",kdfparams:{n:R,r:L,p:F},salt:r.toString("base64"),iv:s.toString("base64"),tag:c.getAuthTag().toString("base64")},data:_.toString("base64")}}function k(n,t){let{salt:r,iv:o,tag:s,kdfparams:c}=n.encryption,_=v(t,Buffer.from(r,"base64"),D,{N:c.n,r:c.r,p:c.p,maxmem:K}),x=$("aes-256-gcm",_,Buffer.from(o,"base64"),{authTagLength:16});return x.setAuthTag(Buffer.from(s,"base64")),Buffer.concat([x.update(Buffer.from(n.data,"base64")),x.final()]).toString("utf8")}var R,L,F,D,K,O,P=m(()=>{"use strict";R=2**18,L=8,F=1,D=32,K=512*1024*1024,O=i.object({encryption:i.object({cipher:i.literal("aes-256-gcm"),kdf:i.literal("scrypt"),kdfparams:i.object({n:i.number(),r:i.number(),p:i.number()}),salt:i.string(),iv:i.string(),tag:i.string()}),data:i.string()})});import{readFileSync as W}from"fs";import{join as z}from"path";import{homedir as q}from"os";function en(){if(f!==void 0)return f;try{f=JSON.parse(W(z(q(),".config","moonpay","consent.json"),"utf-8")).agentId??null}catch{f=null}return f??null}function rn(){return process.env.OPENCLAW_SHELL?"openclaw":process.env.CLAUDECODE?"claude-code":process.env.CODEX_CI?"codex":process.env.GEMINI_CLI?"gemini-cli":"human"}function U(){let n={"Content-Type":"application/json",[Z]:Q,[tn]:rn()},t=en();return t&&(n[nn]=t),n}var Q,Z,nn,f,tn,j=m(()=>{"use strict";Q="1.
|
|
2
|
+
import{b as m,d as b}from"./chunk-LMDE72OE.js";var G={};b(G,{decrypt:()=>k,encrypt:()=>T,encryptedFileSchema:()=>O});import{randomBytes as A,scryptSync as v,createCipheriv as X,createDecipheriv as $}from"crypto";import{z as i}from"zod";function T(n,t){let r=A(32),o=v(t,r,D,{N:R,r:L,p:F,maxmem:K}),s=A(12),c=X("aes-256-gcm",o,s),_=Buffer.concat([c.update(n,"utf8"),c.final()]);return{encryption:{cipher:"aes-256-gcm",kdf:"scrypt",kdfparams:{n:R,r:L,p:F},salt:r.toString("base64"),iv:s.toString("base64"),tag:c.getAuthTag().toString("base64")},data:_.toString("base64")}}function k(n,t){let{salt:r,iv:o,tag:s,kdfparams:c}=n.encryption,_=v(t,Buffer.from(r,"base64"),D,{N:c.n,r:c.r,p:c.p,maxmem:K}),x=$("aes-256-gcm",_,Buffer.from(o,"base64"),{authTagLength:16});return x.setAuthTag(Buffer.from(s,"base64")),Buffer.concat([x.update(Buffer.from(n.data,"base64")),x.final()]).toString("utf8")}var R,L,F,D,K,O,P=m(()=>{"use strict";R=2**18,L=8,F=1,D=32,K=512*1024*1024,O=i.object({encryption:i.object({cipher:i.literal("aes-256-gcm"),kdf:i.literal("scrypt"),kdfparams:i.object({n:i.number(),r:i.number(),p:i.number()}),salt:i.string(),iv:i.string(),tag:i.string()}),data:i.string()})});import{readFileSync as W}from"fs";import{join as z}from"path";import{homedir as q}from"os";function en(){if(f!==void 0)return f;try{f=JSON.parse(W(z(q(),".config","moonpay","consent.json"),"utf-8")).agentId??null}catch{f=null}return f??null}function rn(){return process.env.OPENCLAW_SHELL?"openclaw":process.env.CLAUDECODE?"claude-code":process.env.CODEX_CI?"codex":process.env.GEMINI_CLI?"gemini-cli":"human"}function U(){let n={"Content-Type":"application/json",[Z]:Q,[tn]:rn()},t=en();return t&&(n[nn]=t),n}var Q,Z,nn,f,tn,j=m(()=>{"use strict";Q="1.33.0",Z="X-CLI-Version",nn="X-Agent-Id";tn="X-Agent"});import*as e from"fs";import*as Y from"os";import*as g from"path";function d(){e.existsSync(l)||e.mkdirSync(l,{recursive:!0,mode:448})}function H(n,t,r){let o=n+`.tmp.${process.pid}`;e.writeFileSync(o,t,{encoding:"utf-8",mode:r}),e.renameSync(o,n)}function sn(){d();try{let n=e.openSync(u,e.constants.O_CREAT|e.constants.O_EXCL|e.constants.O_WRONLY,384);e.writeSync(n,JSON.stringify({pid:process.pid,ts:Date.now()})),e.closeSync(n)}catch(n){if(n.code!=="EEXIST")throw n;try{let t=JSON.parse(e.readFileSync(u,"utf-8"));if(Date.now()-t.ts<on)return null}catch{}try{e.unlinkSync(u)}catch{}try{let t=e.openSync(u,e.constants.O_CREAT|e.constants.O_EXCL|e.constants.O_WRONLY,384);e.writeSync(t,JSON.stringify({pid:process.pid,ts:Date.now()})),e.closeSync(t)}catch{return null}}return()=>{try{e.unlinkSync(u)}catch{}}}function B(){if(!e.existsSync(w))return null;try{let n=JSON.parse(e.readFileSync(w,"utf-8"));return n.baseUrl?n:null}catch{return null}}function Pn(){let n=B();return n||(an(N),N)}function S(){if(!e.existsSync(p))return null;let n=h();if(!n)return null;try{let t=JSON.parse(e.readFileSync(p,"utf-8")),r=O.parse(t),o=k(r,n),s=JSON.parse(o);return!s.accessToken||!s.baseUrl?null:s}catch{return null}}function cn(n){let t=I(),r=T(JSON.stringify(n),t);d(),H(p,JSON.stringify(r,null,2),384)}function an(n){d(),H(w,JSON.stringify(n,null,2),384)}function Un(){e.existsSync(p)&&e.unlinkSync(p)}function jn(){let n=B(),t=S();return n?.baseUrl??t?.baseUrl??N.baseUrl}async function fn(n,t,r){let o=await fetch(`${n}/api/tools/${encodeURIComponent(t)}`,{method:"POST",signal:AbortSignal.timeout(15e3),headers:U(),body:JSON.stringify(r)}),s=await o.json();if(!o.ok){let c=s;throw new Error(c?.error??`${t} failed (${o.status})`)}return s}async function un(n){if(!n.refreshToken)throw new Error("No refresh token available");let t=sn();if(!t){await new Promise(o=>setTimeout(o,2e3));let r=S();if(r&&r.expiresAt>Date.now())return r;throw new Error("Token refresh failed (concurrent refresh in progress)")}try{let r=S();if(r&&r.expiresAt>Date.now()+6e4)return r;let o=await fn(n.baseUrl,"refresh",{refreshToken:n.refreshToken}),s={accessToken:o.accessToken,refreshToken:o.refreshToken,expiresAt:o.expiresAt*1e3,baseUrl:n.baseUrl};return cn(s),s}finally{t()}}async function Jn(){let n=S();if(!n)return null;if(Date.now()>=n.expiresAt-ln){if(n.refreshToken)try{return(await un(n)).accessToken}catch{return null}return null}return n.accessToken}var l,w,p,u,N,on,ln,V=m(()=>{"use strict";P();J();j();l=g.join(Y.homedir(),".config","moonpay"),w=g.join(l,"config.json"),p=g.join(l,"credentials.json"),u=g.join(l,".credentials.lock"),N={baseUrl:"https://agents.moonpay.com"};on=3e4;ln=300*1e3});var Nn={};b(Nn,{ensureEncryptionKey:()=>I,getEncryptionKey:()=>h});import{execFileSync as C,execSync as pn}from"child_process";import{randomBytes as gn}from"crypto";import{existsSync as dn,readFileSync as yn,writeFileSync as mn}from"fs";import{homedir as Sn,platform as M}from"os";import{join as hn}from"path";function Cn(n){try{C("security",["delete-generic-password","-s",a,"-a",y],{stdio:"ignore"})}catch{}C("security",["add-generic-password","-s",a,"-a",y,"-w",n],{stdio:"ignore"})}function En(){try{return C("security",["find-generic-password","-s",a,"-a",y,"-w"],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim()}catch{return null}}function _n(n){pn(`printf '%s' | secret-tool store --label="${a}" service "${a}" account "${y}"`,{input:n,stdio:["pipe","ignore","ignore"]})}function xn(){try{return C("secret-tool",["lookup","service",a,"account",y],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim()}catch{return null}}function On(n){d(),mn(E,n,{encoding:"utf-8",mode:384})}function Tn(){try{return dn(E)&&yn(E,"utf-8").trim()||null}catch{return null}}function kn(n){try{let t=M();return t==="darwin"?(Cn(n),!0):t==="linux"?(_n(n),!0):!1}catch{return!1}}function wn(){let n=M();return n==="darwin"?En():n==="linux"?xn():null}function h(){let n=process.env.MOONPAY_ENCRYPTION_KEY;return n||(wn()??Tn())}function I(){let n=h();if(n)return n;let t=gn(32).toString("hex");return kn(t)||(On(t),process.stderr.write("Note: Keychain unavailable. Encryption key stored in "+E+`
|
|
3
3
|
`)),t}var a,y,E,J=m(()=>{"use strict";V();a="moonpay-cli",y="encryption-key",E=hn(Sn(),".config","moonpay",".encryption-key")});export{G as a,P as b,Nn as c,J as d,Q as e,U as f,j as g,d as h,Pn as i,S as j,cn as k,Un as l,jn as m,un as n,Jn as o,V as p};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
|
|
2
|
-
import{f as it,g as lt,j as ut,m as ct,n as ot,o as at,p as pt}from"./chunk-CIGFUBC2.js";var n=class extends Error{constructor(r,i,u){super(r);this.status=i;this.toolName=u;this.name="MoonPayError"}},o=class extends n{constructor(t="Authentication required"){super(t,401),this.name="AuthError"}},a=class extends n{constructor(t="Rate limit exceeded"){super(t,429),this.name="RateLimitError"}},s=class extends n{constructor(t,r){super(t,400,r),this.name="ValidationError"}},l=class extends n{constructor(t){super(`Tool not found: ${t}`,404,t),this.name="ToolNotFoundError"}},p=class extends n{constructor(t,r){super(`Tool "${t}" has been renamed to "${r}"`,410,t),this.name="ToolRenamedError",this.newName=r}};var mt="https://agents.moonpay.com",ht=6e4,h=class{constructor(t={}){this.baseUrl=(t.baseUrl??mt).replace(/\/$/,""),this.auth=t.auth??{type:"none"},this.timeout=t.timeout??ht,this.headers=t.headers??{}}async _call(t,r){let i=`${this.baseUrl}/api/tools/${encodeURIComponent(t)}`,u=await this.buildHeaders(),c=await fetch(i,{method:"POST",headers:u,body:JSON.stringify(r),signal:AbortSignal.timeout(this.timeout)});if(c.status===401&&this.auth.type==="bearer"&&this.auth.refreshToken)try{let st=await this.auth.refreshToken();u.Authorization=`Bearer ${st}`,c=await fetch(i,{method:"POST",headers:u,body:JSON.stringify(r),signal:AbortSignal.timeout(this.timeout)})}catch{throw new o("Token refresh failed")}return this.handleResponse(c,t)}async buildHeaders(){let t={"Content-Type":"application/json",...this.headers};if(this.auth.type==="bearer"){let r=await this.auth.getToken();r&&(t.Authorization=`Bearer ${r}`)}return t}async handleResponse(t,r){if(t.ok)return t.json();let i;try{i=await t.json()}catch{i={error:t.statusText}}let u=i?.error??i?.message,c=typeof u=="string"?u:u?JSON.stringify(u):`Request failed with status ${t.status}`;switch(t.status){case 400:throw new s(c,r);case 401:throw new o(c);case 404:throw new l(r);case 410:throw new p(r,i?.newName??"unknown");case 429:throw new a(c);default:throw new n(c,t.status,r)}}};var _=class{constructor(t){this.client=t}list(t){return this.client._call("chain_list",t)}retrieve(t){return this.client._call("chain_retrieve",t)}},v=class{constructor(t){this.client=t}create(t){return this.client._call("cli_activation_create",t)}update(t){return this.client._call("cli_activation_update",t)}},O=class{constructor(t){this.client=t}get activation(){return new v(this.client)}},d=class{constructor(t){this.client=t}add(t){return this.client._call("commerce_cart_add",t)}remove(t){return this.client._call("commerce_cart_remove",t)}retrieve(t){return this.client._call("commerce_cart_retrieve",t)}update(t){return this.client._call("commerce_cart_update",t)}},k=class{constructor(t){this.client=t}pay(t){return this.client._call("commerce_checkout_pay",t)}start(t){return this.client._call("commerce_checkout_start",t)}},C=class{constructor(t){this.client=t}retrieve(t){return this.client._call("commerce_product_retrieve",t)}search(t){return this.client._call("commerce_product_search",t)}},I=class{constructor(t){this.client=t}list(t){return this.client._call("commerce_store_list",t)}retrieve(t){return this.client._call("commerce_store_retrieve",t)}},A=class{constructor(t){this.client=t}get cart(){return new d(this.client)}get checkout(){return new k(this.client)}get product(){return new C(this.client)}get store(){return new I(this.client)}},y=class{constructor(t){this.client=t}list(t){return this.client._call("deposit_transaction_list",t)}},g=class{constructor(t){this.client=t}get transaction(){return new y(this.client)}create(t){return this.client._call("deposit_create",t)}retrieve(t){return this.client._call("deposit_retrieve",t)}},f=class{constructor(t){this.client=t}create(t){return this.client._call("feedback_create",t)}},M=class{constructor(t){this.client=t}list(t){return this.client._call("prediction-market_activity_list",t)}},R=class{constructor(t){this.client=t}retrieve(t){return this.client._call("prediction-market_market_event_retrieve",t)}},T=class{constructor(t){this.client=t}list(t){return this.client._call("prediction-market_market_price_history_list",t)}},V=class{constructor(t){this.client=t}get history(){return new T(this.client)}retrieve(t){return this.client._call("prediction-market_market_price_retrieve",t)}},w=class{constructor(t){this.client=t}list(t){return this.client._call("prediction-market_market_tag_list",t)}},L=class{constructor(t){this.client=t}list(t){return this.client._call("prediction-market_market_trending_list",t)}},x=class{constructor(t){this.client=t}get event(){return new R(this.client)}get price(){return new V(this.client)}get tag(){return new w(this.client)}get trending(){return new L(this.client)}search(t){return this.client._call("prediction-market_market_search",t)}},S=class{constructor(t){this.client=t}retrieve(t){return this.client._call("prediction-market_pnl_retrieve",t)}},b=class{constructor(t){this.client=t}buy(t){return this.client._call("prediction-market_position_buy",t)}list(t){return this.client._call("prediction-market_position_list",t)}redeem(t){return this.client._call("prediction-market_position_redeem",t)}sell(t){return this.client._call("prediction-market_position_sell",t)}},B=class{constructor(t){this.client=t}list(t){return this.client._call("prediction-market_trade_list",t)}},U=class{constructor(t){this.client=t}create(t){return this.client._call("prediction-market_user_create",t)}},E=class{constructor(t){this.client=t}get activity(){return new M(this.client)}get market(){return new x(this.client)}get pnl(){return new S(this.client)}get position(){return new b(this.client)}get trade(){return new B(this.client)}get user(){return new U(this.client)}},D=class{constructor(t){this.client=t}build(t){return this.client._call("swaps_transaction_build",t)}},W=class{constructor(t){this.client=t}get transaction(){return new D(this.client)}},H=class{constructor(t){this.client=t}list(t){return this.client._call("token_balance_list",t)}},$=class{constructor(t){this.client=t}list(t){return this.client._call("token_holder_list",t)}},F=class{constructor(t){this.client=t}list(t){return this.client._call("token_trending_list",t)}},K=class{constructor(t){this.client=t}get balance(){return new H(this.client)}get holder(){return new $(this.client)}get trending(){return new F(this.client)}check(t){return this.client._call("token_check",t)}retrieve(t){return this.client._call("token_retrieve",t)}search(t){return this.client._call("token_search",t)}transfer(t){return this.client._call("token_transfer",t)}},j=class{constructor(t){this.client=t}list(t){return this.client._call("transaction_list",t)}prepare(t){return this.client._call("transaction_prepare",t)}register(t){return this.client._call("transaction_register",t)}retrieve(t){return this.client._call("transaction_retrieve",t)}send(t){return this.client._call("transaction_send",t)}},J=class{constructor(t){this.client=t}retrieve(t){return this.client._call("user_retrieve",t)}},q=class{constructor(t){this.client=t}accept(t){return this.client._call("virtual-account_agreement_accept",t)}list(t){return this.client._call("virtual-account_agreement_list",t)}},z=class{constructor(t){this.client=t}delete(t){return this.client._call("virtual-account_bank-account_delete",t)}list(t){return this.client._call("virtual-account_bank-account_list",t)}register(t){return this.client._call("virtual-account_bank-account_register",t)}retrieve(t){return this.client._call("virtual-account_bank-account_retrieve",t)}},G=class{constructor(t){this.client=t}continue(t){return this.client._call("virtual-account_kyc_continue",t)}restart(t){return this.client._call("virtual-account_kyc_restart",t)}},Q=class{constructor(t){this.client=t}cancel(t){return this.client._call("virtual-account_offramp_cancel",t)}create(t){return this.client._call("virtual-account_offramp_create",t)}initiate(t){return this.client._call("virtual-account_offramp_initiate",t)}list(t){return this.client._call("virtual-account_offramp_list",t)}retrieve(t){return this.client._call("virtual-account_offramp_retrieve",t)}update(t){return this.client._call("virtual-account_offramp_update",t)}},X=class{constructor(t){this.client=t}create(t){return this.client._call("virtual-account_onramp_payment_create",t)}retrieve(t){return this.client._call("virtual-account_onramp_payment_retrieve",t)}},Y=class{constructor(t){this.client=t}get payment(){return new X(this.client)}cancel(t){return this.client._call("virtual-account_onramp_cancel",t)}create(t){return this.client._call("virtual-account_onramp_create",t)}list(t){return this.client._call("virtual-account_onramp_list",t)}retrieve(t){return this.client._call("virtual-account_onramp_retrieve",t)}update(t){return this.client._call("virtual-account_onramp_update",t)}},Z=class{constructor(t){this.client=t}list(t){return this.client._call("virtual-account_transaction_list",t)}},N=class{constructor(t){this.client=t}list(t){return this.client._call("virtual-account_wallet_list",t)}register(t){return this.client._call("virtual-account_wallet_register",t)}},tt=class{constructor(t){this.client=t}get agreement(){return new q(this.client)}get bankAccount(){return new z(this.client)}get kyc(){return new G(this.client)}get offramp(){return new Q(this.client)}get onramp(){return new Y(this.client)}get transaction(){return new Z(this.client)}get wallet(){return new N(this.client)}create(t){return this.client._call("virtual-account_create",t)}retrieve(t){return this.client._call("virtual-account_retrieve",t)}},et=class{constructor(t){this.client=t}list(t){return this.client._call("wallet_activity_list",t)}},rt=class{constructor(t){this.client=t}retrieve(t){return this.client._call("wallet_pnl_retrieve",t)}},nt=class{constructor(t){this.client=t}get activity(){return new et(this.client)}get pnl(){return new rt(this.client)}discover(t){return this.client._call("wallet_discover",t)}},m=class extends h{constructor(t={}){super(t)}get chain(){return new _(this)}get cli(){return new O(this)}get commerce(){return new A(this)}get deposit(){return new g(this)}get feedback(){return new f(this)}get predictionMarket(){return new E(this)}get swaps(){return new W(this)}get token(){return new K(this)}get transaction(){return new j(this)}get user(){return new J(this)}get virtualAccount(){return new tt(this)}get wallet(){return new nt(this)}buy(t){return this._call("buy",t)}login(t){return this._call("login",t)}refresh(t){return this._call("refresh",t)}verify(t){return this._call("verify",t)}};pt();lt();var P=null;function Pt(){return P||(P=new m({baseUrl:ct(),auth:{type:"bearer",getToken:at,refreshToken:async()=>{let e=ut();if(!e?.refreshToken)throw new Error("No refresh token available");return(await ot(e)).accessToken}},headers:it()})),P}var Rt=new Proxy({},{get(e,t){return Reflect.get(Pt(),t)}});function Tt(){P=null}export{m as a,Rt as b,Tt as c};
|
|
2
|
+
import{f as it,g as lt,j as ut,m as ct,n as ot,o as at,p as pt}from"./chunk-PHXOVWSJ.js";var n=class extends Error{constructor(r,i,u){super(r);this.status=i;this.toolName=u;this.name="MoonPayError"}},o=class extends n{constructor(t="Authentication required"){super(t,401),this.name="AuthError"}},a=class extends n{constructor(t="Rate limit exceeded"){super(t,429),this.name="RateLimitError"}},s=class extends n{constructor(t,r){super(t,400,r),this.name="ValidationError"}},l=class extends n{constructor(t){super(`Tool not found: ${t}`,404,t),this.name="ToolNotFoundError"}},p=class extends n{constructor(t,r){super(`Tool "${t}" has been renamed to "${r}"`,410,t),this.name="ToolRenamedError",this.newName=r}};var mt="https://agents.moonpay.com",ht=6e4,h=class{constructor(t={}){this.baseUrl=(t.baseUrl??mt).replace(/\/$/,""),this.auth=t.auth??{type:"none"},this.timeout=t.timeout??ht,this.headers=t.headers??{}}async _call(t,r){let i=`${this.baseUrl}/api/tools/${encodeURIComponent(t)}`,u=await this.buildHeaders(),c=await fetch(i,{method:"POST",headers:u,body:JSON.stringify(r),signal:AbortSignal.timeout(this.timeout)});if(c.status===401&&this.auth.type==="bearer"&&this.auth.refreshToken)try{let st=await this.auth.refreshToken();u.Authorization=`Bearer ${st}`,c=await fetch(i,{method:"POST",headers:u,body:JSON.stringify(r),signal:AbortSignal.timeout(this.timeout)})}catch{throw new o("Token refresh failed")}return this.handleResponse(c,t)}async buildHeaders(){let t={"Content-Type":"application/json",...this.headers};if(this.auth.type==="bearer"){let r=await this.auth.getToken();r&&(t.Authorization=`Bearer ${r}`)}return t}async handleResponse(t,r){if(t.ok)return t.json();let i;try{i=await t.json()}catch{i={error:t.statusText}}let u=i?.error??i?.message,c=typeof u=="string"?u:u?JSON.stringify(u):`Request failed with status ${t.status}`;switch(t.status){case 400:throw new s(c,r);case 401:throw new o(c);case 404:throw new l(r);case 410:throw new p(r,i?.newName??"unknown");case 429:throw new a(c);default:throw new n(c,t.status,r)}}};var _=class{constructor(t){this.client=t}list(t){return this.client._call("chain_list",t)}retrieve(t){return this.client._call("chain_retrieve",t)}},v=class{constructor(t){this.client=t}create(t){return this.client._call("cli_activation_create",t)}update(t){return this.client._call("cli_activation_update",t)}},O=class{constructor(t){this.client=t}get activation(){return new v(this.client)}},d=class{constructor(t){this.client=t}add(t){return this.client._call("commerce_cart_add",t)}remove(t){return this.client._call("commerce_cart_remove",t)}retrieve(t){return this.client._call("commerce_cart_retrieve",t)}update(t){return this.client._call("commerce_cart_update",t)}},k=class{constructor(t){this.client=t}pay(t){return this.client._call("commerce_checkout_pay",t)}start(t){return this.client._call("commerce_checkout_start",t)}},C=class{constructor(t){this.client=t}retrieve(t){return this.client._call("commerce_product_retrieve",t)}search(t){return this.client._call("commerce_product_search",t)}},I=class{constructor(t){this.client=t}list(t){return this.client._call("commerce_store_list",t)}retrieve(t){return this.client._call("commerce_store_retrieve",t)}},A=class{constructor(t){this.client=t}get cart(){return new d(this.client)}get checkout(){return new k(this.client)}get product(){return new C(this.client)}get store(){return new I(this.client)}},y=class{constructor(t){this.client=t}list(t){return this.client._call("deposit_transaction_list",t)}},g=class{constructor(t){this.client=t}get transaction(){return new y(this.client)}create(t){return this.client._call("deposit_create",t)}retrieve(t){return this.client._call("deposit_retrieve",t)}},f=class{constructor(t){this.client=t}create(t){return this.client._call("feedback_create",t)}},M=class{constructor(t){this.client=t}list(t){return this.client._call("prediction-market_activity_list",t)}},R=class{constructor(t){this.client=t}retrieve(t){return this.client._call("prediction-market_market_event_retrieve",t)}},T=class{constructor(t){this.client=t}list(t){return this.client._call("prediction-market_market_price_history_list",t)}},V=class{constructor(t){this.client=t}get history(){return new T(this.client)}retrieve(t){return this.client._call("prediction-market_market_price_retrieve",t)}},w=class{constructor(t){this.client=t}list(t){return this.client._call("prediction-market_market_tag_list",t)}},L=class{constructor(t){this.client=t}list(t){return this.client._call("prediction-market_market_trending_list",t)}},x=class{constructor(t){this.client=t}get event(){return new R(this.client)}get price(){return new V(this.client)}get tag(){return new w(this.client)}get trending(){return new L(this.client)}search(t){return this.client._call("prediction-market_market_search",t)}},S=class{constructor(t){this.client=t}retrieve(t){return this.client._call("prediction-market_pnl_retrieve",t)}},b=class{constructor(t){this.client=t}buy(t){return this.client._call("prediction-market_position_buy",t)}list(t){return this.client._call("prediction-market_position_list",t)}redeem(t){return this.client._call("prediction-market_position_redeem",t)}sell(t){return this.client._call("prediction-market_position_sell",t)}},B=class{constructor(t){this.client=t}list(t){return this.client._call("prediction-market_trade_list",t)}},U=class{constructor(t){this.client=t}create(t){return this.client._call("prediction-market_user_create",t)}},E=class{constructor(t){this.client=t}get activity(){return new M(this.client)}get market(){return new x(this.client)}get pnl(){return new S(this.client)}get position(){return new b(this.client)}get trade(){return new B(this.client)}get user(){return new U(this.client)}},D=class{constructor(t){this.client=t}build(t){return this.client._call("swaps_transaction_build",t)}},W=class{constructor(t){this.client=t}get transaction(){return new D(this.client)}},H=class{constructor(t){this.client=t}list(t){return this.client._call("token_balance_list",t)}},$=class{constructor(t){this.client=t}list(t){return this.client._call("token_holder_list",t)}},F=class{constructor(t){this.client=t}list(t){return this.client._call("token_trending_list",t)}},K=class{constructor(t){this.client=t}get balance(){return new H(this.client)}get holder(){return new $(this.client)}get trending(){return new F(this.client)}check(t){return this.client._call("token_check",t)}retrieve(t){return this.client._call("token_retrieve",t)}search(t){return this.client._call("token_search",t)}transfer(t){return this.client._call("token_transfer",t)}},j=class{constructor(t){this.client=t}list(t){return this.client._call("transaction_list",t)}prepare(t){return this.client._call("transaction_prepare",t)}register(t){return this.client._call("transaction_register",t)}retrieve(t){return this.client._call("transaction_retrieve",t)}send(t){return this.client._call("transaction_send",t)}},J=class{constructor(t){this.client=t}retrieve(t){return this.client._call("user_retrieve",t)}},q=class{constructor(t){this.client=t}accept(t){return this.client._call("virtual-account_agreement_accept",t)}list(t){return this.client._call("virtual-account_agreement_list",t)}},z=class{constructor(t){this.client=t}delete(t){return this.client._call("virtual-account_bank-account_delete",t)}list(t){return this.client._call("virtual-account_bank-account_list",t)}register(t){return this.client._call("virtual-account_bank-account_register",t)}retrieve(t){return this.client._call("virtual-account_bank-account_retrieve",t)}},G=class{constructor(t){this.client=t}continue(t){return this.client._call("virtual-account_kyc_continue",t)}restart(t){return this.client._call("virtual-account_kyc_restart",t)}},Q=class{constructor(t){this.client=t}cancel(t){return this.client._call("virtual-account_offramp_cancel",t)}create(t){return this.client._call("virtual-account_offramp_create",t)}initiate(t){return this.client._call("virtual-account_offramp_initiate",t)}list(t){return this.client._call("virtual-account_offramp_list",t)}retrieve(t){return this.client._call("virtual-account_offramp_retrieve",t)}update(t){return this.client._call("virtual-account_offramp_update",t)}},X=class{constructor(t){this.client=t}create(t){return this.client._call("virtual-account_onramp_payment_create",t)}retrieve(t){return this.client._call("virtual-account_onramp_payment_retrieve",t)}},Y=class{constructor(t){this.client=t}get payment(){return new X(this.client)}cancel(t){return this.client._call("virtual-account_onramp_cancel",t)}create(t){return this.client._call("virtual-account_onramp_create",t)}list(t){return this.client._call("virtual-account_onramp_list",t)}retrieve(t){return this.client._call("virtual-account_onramp_retrieve",t)}update(t){return this.client._call("virtual-account_onramp_update",t)}},Z=class{constructor(t){this.client=t}list(t){return this.client._call("virtual-account_transaction_list",t)}},N=class{constructor(t){this.client=t}list(t){return this.client._call("virtual-account_wallet_list",t)}register(t){return this.client._call("virtual-account_wallet_register",t)}},tt=class{constructor(t){this.client=t}get agreement(){return new q(this.client)}get bankAccount(){return new z(this.client)}get kyc(){return new G(this.client)}get offramp(){return new Q(this.client)}get onramp(){return new Y(this.client)}get transaction(){return new Z(this.client)}get wallet(){return new N(this.client)}create(t){return this.client._call("virtual-account_create",t)}retrieve(t){return this.client._call("virtual-account_retrieve",t)}},et=class{constructor(t){this.client=t}list(t){return this.client._call("wallet_activity_list",t)}},rt=class{constructor(t){this.client=t}retrieve(t){return this.client._call("wallet_pnl_retrieve",t)}},nt=class{constructor(t){this.client=t}get activity(){return new et(this.client)}get pnl(){return new rt(this.client)}discover(t){return this.client._call("wallet_discover",t)}},m=class extends h{constructor(t={}){super(t)}get chain(){return new _(this)}get cli(){return new O(this)}get commerce(){return new A(this)}get deposit(){return new g(this)}get feedback(){return new f(this)}get predictionMarket(){return new E(this)}get swaps(){return new W(this)}get token(){return new K(this)}get transaction(){return new j(this)}get user(){return new J(this)}get virtualAccount(){return new tt(this)}get wallet(){return new nt(this)}buy(t){return this._call("buy",t)}login(t){return this._call("login",t)}refresh(t){return this._call("refresh",t)}verify(t){return this._call("verify",t)}};pt();lt();var P=null;function Pt(){return P||(P=new m({baseUrl:ct(),auth:{type:"bearer",getToken:at,refreshToken:async()=>{let e=ut();if(!e?.refreshToken)throw new Error("No refresh token available");return(await ot(e)).accessToken}},headers:it()})),P}var Rt=new Proxy({},{get(e,t){return Reflect.get(Pt(),t)}});function Tt(){P=null}export{m as a,Rt as b,Tt as c};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
|
|
2
|
-
import{b as a,c as b}from"./chunk-
|
|
2
|
+
import{b as a,c as b}from"./chunk-SFNE2JF2.js";import"./chunk-PHXOVWSJ.js";import"./chunk-LMDE72OE.js";export{a as moonpay,b as resetClient};
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
|
|
3
|
-
import{a as j,b as J,c as v,d as N}from"./chunk-
|
|
3
|
+
import{a as j,b as J,c as v,d as N}from"./chunk-NRL3YIPT.js";import{b as O}from"./chunk-SFNE2JF2.js";import{m as R}from"./chunk-2CBFFXK6.js";import{e as C,g as q}from"./chunk-PHXOVWSJ.js";import"./chunk-LMDE72OE.js";import{Command as ne}from"commander";var Y=!process.env.NO_COLOR&&process.stdout.isTTY===!0;function w(e){return t=>Y?`${e}${t}\x1B[0m`:t}var p={bold:w("\x1B[1m"),dim:w("\x1B[2m"),green:w("\x1B[32m"),yellow:w("\x1B[33m"),cyan:w("\x1B[36m"),red:w("\x1B[31m")};function k(e){if(e==null)return!0;let t=typeof e;return t==="string"||t==="number"||t==="boolean"}function $(e){return e==null?"-":String(e)}function S(e,t=0){let n=" ".repeat(t);return k(e)?`${n}${$(e)}`:Array.isArray(e)?e.length===0?`${n}${p.dim("(empty)")}`:e.every(k)?e.map(s=>`${n}- ${$(s)}`).join(`
|
|
4
4
|
`):e.map(s=>{if(typeof s!="object"||s===null)return`${n}- ${$(s)}`;let r=Object.entries(s),a=[],[c,l]=r[0];k(l)?a.push(`${n}- ${p.bold(c)}: ${$(l)}`):(a.push(`${n}- ${p.bold(c)}:`),a.push(S(l,t+2)));for(let[u,y]of r.slice(1))k(y)?a.push(`${n} ${p.bold(u)}: ${$(y)}`):(a.push(`${n} ${p.bold(u)}:`),a.push(S(y,t+2)));return a.join(`
|
|
5
5
|
`)}).join(`
|
|
6
6
|
|
|
@@ -14,5 +14,5 @@ ${S(a,t+1)}`).join(`
|
|
|
14
14
|
|
|
15
15
|
Run \`mp skill install\` to install AI skills for Claude Code.
|
|
16
16
|
|
|
17
|
-
`+J).version(C).option("--json","Output as JSON instead of YAML");function re(){return h.opts().json?"json":"yaml"}function L(e){console.log(A(e,re()))}function I(){let e=te();e&&process.stderr.write(e)}h.command("mcp").description("Start MCP server over stdio (for Claude Desktop, Claude Code, etc.)").action(async()=>{let{startMcpServer:e}=await import("./mcp-
|
|
17
|
+
`+J).version(C).option("--json","Output as JSON instead of YAML");function re(){return h.opts().json?"json":"yaml"}function L(e){console.log(A(e,re()))}function I(){let e=te();e&&process.stderr.write(e)}h.command("mcp").description("Start MCP server over stdio (for Claude Desktop, Claude Code, etc.)").action(async()=>{let{startMcpServer:e}=await import("./mcp-EJQKDZ7X.js");await e()});function Z(e,t){let n=e;for(let s of t){let r=n.commands.find(a=>a.name()===s);r||(r=n.command(s)),n=r}return n}function M(e,t=""){let n=[];for(let[s,r]of Object.entries(e)){let a=t?`${t}-${s}`:s,c=r;for(;c._def.typeName==="ZodEffects";)c=c._def.schema;let l=c;l._def.typeName==="ZodNullable"&&(l=l._def.innerType),l._def.typeName==="ZodObject"&&l.shape?n.push(...M(l.shape,a)):n.push({flatKey:a,field:r,path:a.split("-")})}return n}function oe(e,t){let n={};for(let{flatKey:s,path:r}of t){let a=s.replace(/-([a-z])/g,(l,u)=>u.toUpperCase()),c=a in e?e[a]:e[s];if(r.length===1)n[r[0]]=c;else{let l=n;for(let u=0;u<r.length-1;u++)(!l[r[u]]||typeof l[r[u]]!="object")&&(l[r[u]]={}),l=l[r[u]];l[r[r.length-1]]=c}}return n}function se(e,t){for(let n of t){let s=n.schema.name.split("_"),r=s.pop(),c=Z(e,s).command(r).description(n.schema.description),l=n.schema.input.shape??{},u=M(l),y=[],b=[],_=[];for(let{flatKey:f,field:i}of u){let o=i.description??f,m=i;for(;m._def.typeName==="ZodEffects";)m=m._def.schema;let g=m._def.typeName,d=m;d._def.typeName==="ZodNullable"&&(d=d._def.innerType),d._def.typeName==="ZodNumber"&&b.push(f),d._def.typeName==="ZodRecord"&&_.push(f),g==="ZodBoolean"?c.option(`--${f}`,o,!1):g==="ZodNullable"?(c.option(`--${f} <${f}>`,o),y.push(f)):c.requiredOption(`--${f} <${f}>`,o)}c.action(async f=>{n.schema.name.startsWith("consent_")||await v.handler({});for(let o of y){let m=o.replace(/-([a-z])/g,(g,d)=>d.toUpperCase());f[m]===void 0&&(f[m]=null)}for(let o of b){let m=o.replace(/-([a-z])/g,(g,d)=>d.toUpperCase());f[m]!=null&&typeof f[m]=="string"&&(f[m]=Number(f[m]))}for(let o of _){let m=o.replace(/-([a-z])/g,(g,d)=>d.toUpperCase());if(typeof f[m]=="string")try{f[m]=JSON.parse(f[m])}catch{console.error(`Invalid JSON for --${o}`),process.exit(1)}}let i=oe(f,u);try{let o=await n.handler(i);L(o)}catch(o){console.error(o instanceof Error?o.message:String(o)),process.exit(1)}})}}function ie(e){if(e.$ref&&e.definitions){let t=e.$ref.replace("#/definitions/","");return e.definitions[t]}return e}function ae(e){return Array.isArray(e.type)?e.type.includes("null"):e.anyOf?e.anyOf.some(t=>t.type==="null"):!1}function ce(e){return Array.isArray(e.type)?e.type.includes("object"):e.anyOf?e.anyOf.some(t=>t.type==="object"):e.type==="object"}function le(e){return Array.isArray(e.type)?e.type.some(t=>t==="number"||t==="integer"):e.anyOf?e.anyOf.some(t=>t.type==="number"||t.type==="integer"):e.type==="number"||e.type==="integer"}var U=new Set(["swaps_transaction_build","token_transfer","transaction_register","virtual-account_offramp_initiate","prediction-market_position_buy","prediction-market_position_sell","prediction-market_position_redeem","commerce_cart_update","commerce_checkout_start","commerce_checkout_pay"]);function fe(e,t){for(let n of t){if(U.has(n.name))continue;let s=n.name.split("_"),r=s.pop(),a=Z(e,s);if(a.commands.find(i=>i.name()===r))continue;let c=a.command(r).description(n.description),l=ie(n.inputSchema),u=l.properties??{},y=new Set(l.required??[]),b=[],_=[],f=[];for(let[i,o]of Object.entries(u)){let m=o.description??i,g=ae(o),d=ce(o);le(o)&&_.push(i),d?(f.push(i),y.has(i)&&!g?c.requiredOption(`--${i} <json>`,`${m} (as JSON)`):(c.option(`--${i} <json>`,`${m} (as JSON)`),b.push(i))):g||!y.has(i)?(c.option(`--${i} <${i}>`,m),b.push(i)):c.requiredOption(`--${i} <${i}>`,m)}c.action(async i=>{await v.handler({});for(let o of b)i[o]===void 0&&(i[o]=null);for(let o of _)i[o]!=null&&typeof i[o]=="string"&&(i[o]=Number(i[o]));for(let o of f)if(typeof i[o]=="string")try{i[o]=JSON.parse(i[o])}catch{console.error(`Invalid JSON for --${o}`),process.exit(1)}try{await D(i);let o=await O._call(n.name,i);L(o),I()}catch(o){console.error(o instanceof Error?o.message:String(o)),process.exit(1)}})}}se(h,N);fe(h,j);h.command("tools").description("List available tools").action(()=>{let e=[...N.map(n=>({name:n.schema.name,description:n.schema.description})),...j.filter(n=>!N.some(s=>s.schema.name===n.name)&&!U.has(n.name)).map(n=>({name:n.name,description:n.description}))].sort((n,s)=>n.name.localeCompare(s.name)),t=[];for(let n of e){let s=n.name.replace(/_/g," ");t.push(` ${p.green(s.padEnd(28))} ${p.dim(n.description)}`)}t.push(""),t.push(p.dim(`${e.length} tools`)),console.log(t.join(`
|
|
18
18
|
`)),I()});h.parse();
|
|
@@ -7,6 +7,6 @@ Run: npm i -g @moonpay/cli --include=optional`;function y(){try{let e=S("@ledger
|
|
|
7
7
|
`),p}async function U(){if(!p)return null;try{let e=y(),i=f().getDeviceSessionState({sessionId:p}),s=await e.firstValueFrom(i.pipe(e.take(1),e.timeout(3e3)));return s.sessionStateType>=1?s.currentApp?.name??null:null}catch{return null}}var M={evm:"Ethereum",solana:"Solana"};function _(e){let n=String(e);return n.includes("6807")||n.includes("6a15")||n.includes("UnknownDeviceExchangeError")}async function C(e){process.stderr.write(`Installing ${e} app on your Ledger...
|
|
8
8
|
`);let{OpenAppWithDependenciesDeviceAction:n}=y(),i=new n({input:{appName:e}}),t=f().executeDeviceAction({sessionId:E(),deviceAction:i});await m(t,`Install ${e}`,18e4),process.stderr.write(`Installed ${e} app
|
|
9
9
|
`)}async function R(e){let n=M[e];if(!n||await U()===n)return;process.stderr.write(`Opening ${n} app on your Ledger...
|
|
10
|
-
`);let{OpenAppDeviceAction:s}=y(),t=new s({input:{appName:n}}),u=f().executeDeviceAction({sessionId:E(),deviceAction:t});try{await m(u,`Open ${n}`)}catch(c){if(_(c)){await D(),await C(n),await D();return}if(!String(c).includes("isconnect"))throw c}await D()}async function D(){try{await f().disconnect({sessionId:p})}catch{}p=null,await new Promise(e=>setTimeout(e,500)),await P()}function $(e,n=0){switch(e){case"evm":return`44'/60'/${n}'/0/0`;case"solana":return`44'/501'/${n}'/0'`;default:throw new Error(`${e} derivation via Ledger is not supported.`)}}function k(e){return e.startsWith("0x")?e.slice(2):e}function T(e){return e.startsWith("0x")?e:`0x${e}`}async function x(e){let{moonpay:n}=await import("./client-
|
|
10
|
+
`);let{OpenAppDeviceAction:s}=y(),t=new s({input:{appName:n}}),u=f().executeDeviceAction({sessionId:E(),deviceAction:t});try{await m(u,`Open ${n}`)}catch(c){if(_(c)){await D(),await C(n),await D();return}if(!String(c).includes("isconnect"))throw c}await D()}async function D(){try{await f().disconnect({sessionId:p})}catch{}p=null,await new Promise(e=>setTimeout(e,500)),await P()}function $(e,n=0){switch(e){case"evm":return`44'/60'/${n}'/0/0`;case"solana":return`44'/501'/${n}'/0'`;default:throw new Error(`${e} derivation via Ledger is not supported.`)}}function k(e){return e.startsWith("0x")?e.slice(2):e}function T(e){return e.startsWith("0x")?e:`0x${e}`}async function x(e){let{moonpay:n}=await import("./client-5SOFUSPS.js"),s=(await n.chain.retrieve({chain:e})).keyFamily;if(s==="bitcoin")throw new Error("Bitcoin address derivation via Ledger is not yet supported.");if(s==="tron")throw new Error("Tron address derivation via Ledger is not supported. The Ethereum signer cannot interact with the Tron Ledger app.");await R(s);let t=$(s),a=E(),u=f();switch(s){case"evm":{let{SignerEthBuilder:c}=I(),l=new c({dmk:u,sessionId:a}).build().getAddress(t,{skipOpenApp:!1});return(await m(l,"Get Ethereum address")).address}case"solana":{let{SignerSolanaBuilder:c}=L(),l=new c({dmk:u,sessionId:a}).build().getAddress(t,{skipOpenApp:!1});return await m(l,"Get Solana address")}default:throw new Error(`Ledger address derivation not supported for ${s}`)}}async function F(){let e={};try{e.ethereum=await x("ethereum")}catch(n){process.stderr.write(`Failed to get Ethereum address: ${n}
|
|
11
11
|
`)}try{e.solana=await x("solana")}catch(n){process.stderr.write(`Failed to get Solana address: ${n}
|
|
12
|
-
`)}if(!e.ethereum&&!e.solana)throw new Error("Could not derive any addresses from Ledger device");return e}async function H(e,n){let{moonpay:i}=await import("./client-
|
|
12
|
+
`)}if(!e.ethereum&&!e.solana)throw new Error("Could not derive any addresses from Ledger device");return e}async function H(e,n){let{moonpay:i}=await import("./client-5SOFUSPS.js"),t=(await i.chain.retrieve({chain:e})).keyFamily;if(t==="bitcoin")throw new Error("Bitcoin transaction signing via Ledger is not yet supported. Use a software wallet for Bitcoin transactions.");if(t==="tron")throw new Error("Tron transaction signing via Ledger is not supported. Use a software wallet for Tron transactions.");await R(t);let a=$(t),u=E(),c=f();switch(t){case"evm":{let{SignerEthBuilder:d}=I(),l=new d({dmk:c,sessionId:u}).build(),w=T(n.startsWith("0x")?n:Buffer.from(n,"base64").toString("hex")),o=Uint8Array.from(Buffer.from(k(w),"hex")),r=l.signTransaction(a,o,{skipOpenApp:!1}),g=await m(r,"Sign transaction"),{parseTransaction:v,serializeTransaction:A}=await import("viem"),B=v(w);return{transaction:A(B,{r:T(k(g.r)),s:T(k(g.s)),v:BigInt(g.v)})}}case"solana":{let{SignerSolanaBuilder:d}=L(),l=new d({dmk:c,sessionId:u}).build(),{VersionedTransaction:w}=await import("@solana/web3.js"),o=Uint8Array.from(Buffer.from(n,"base64")),r=w.deserialize(o),g=r.message.serialize(),v=l.signTransaction(a,g,{skipOpenApp:!1}),A=await m(v,"Sign Solana transaction");return r.signatures[0]=A,{transaction:Buffer.from(r.serialize()).toString("base64")}}default:throw new Error(`Ledger transaction signing not supported for ${t}`)}}async function V(e,n){let{moonpay:i}=await import("./client-5SOFUSPS.js"),t=(await i.chain.retrieve({chain:e})).keyFamily;if(t==="bitcoin")throw new Error("Bitcoin message signing via Ledger is not yet supported. Use a software wallet for Bitcoin message signing.");if(t==="tron")throw new Error("Tron message signing via Ledger is not supported. Use a software wallet for Tron message signing.");await R(t);let a=$(t),u=E(),c=f();switch(t){case"evm":{let{SignerEthBuilder:d}=I(),w=new d({dmk:c,sessionId:u}).build().signMessage(a,n,{skipOpenApp:!1}),o=await m(w,"Sign message"),r=k(o.r),g=k(o.s),v=o.v.toString(16).padStart(2,"0");return{signature:`0x${r}${g}${v}`}}case"solana":{let{SignerSolanaBuilder:d}=L(),l=new d({dmk:c,sessionId:u}).build(),w=Buffer.from(n,"utf8").toString("hex"),o=l.signMessage(a,w,{skipOpenApp:!1}),r=await m(o,"Sign Solana message");return{signature:(await import("bs58")).default.encode(r)}}default:throw new Error(`Ledger message signing not supported for ${t}`)}}async function q(){if(p){try{await f().disconnect({sessionId:p})}catch{}p=null}if(h){try{h.close()}catch{}h=null}}export{P as connectLedger,q as disconnectLedger,x as ledgerGetAddress,F as ledgerGetAllAddresses,V as ledgerSignMessage,H as ledgerSignTransaction};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
|
|
2
|
-
import{a as f,d as u}from"./chunk-
|
|
2
|
+
import{a as f,d as u}from"./chunk-NRL3YIPT.js";import{b as d}from"./chunk-SFNE2JF2.js";import"./chunk-2CBFFXK6.js";import{e as l,g as R}from"./chunk-PHXOVWSJ.js";import"./chunk-LMDE72OE.js";import{Server as N}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as O}from"@modelcontextprotocol/sdk/server/stdio.js";import{CallToolRequestSchema as T,ListToolsRequestSchema as x}from"@modelcontextprotocol/sdk/types.js";import{zodToJsonSchema as k}from"zod-to-json-schema";R();var y=new Map(u.map(s=>[s.schema.name,s]));function q(s){let n=s.inputSchema;if(n.$ref&&n.definitions){let c=n.$ref.replace("#/definitions/","");return n.definitions[c]??n}return n}async function P(){let s=new N({name:"moonpay",version:l},{capabilities:{tools:{listChanged:!0}}}),n=u.map(e=>({name:e.schema.name,description:e.schema.description,inputSchema:k(e.schema.input)})),c=new Map;for(let e of f){if(y.has(e.name))continue;let t=q(e);c.set(e.name,t.properties??{}),n.push({name:e.name,description:e.description,inputSchema:{type:"object",properties:t.properties??{},...t.required?{required:t.required}:{},...t.additionalProperties!==void 0?{additionalProperties:t.additionalProperties}:{}}})}let h=new Map(n.map(e=>[e.name,e]));s.setRequestHandler(x,async()=>({tools:n.map(e=>({name:e.name,description:e.description,inputSchema:e.inputSchema}))})),s.setRequestHandler(T,async e=>{let{name:t,arguments:o={}}=e.params;if(!h.has(t))return{content:[{type:"text",text:`Unknown tool: ${t}`}],isError:!0};try{let i=y.get(t);if(i){let p=i.schema.input.shape??{};for(let[m,a]of Object.entries(p))o[m]===void 0&&a._def.typeName==="ZodNullable"&&(o[m]=null);let r=await i.handler(o);return{content:[{type:"text",text:JSON.stringify(r,null,2)}]}}let S=c.get(t)??{};for(let[p,r]of Object.entries(S))o[p]===void 0&&(Array.isArray(r.type)?r.type.includes("null"):r.anyOf?.some(w=>w.type==="null"))&&(o[p]=null),(r.type==="number"||r.type==="integer"||Array.isArray(r.type)&&r.type.some(a=>a==="number"||a==="integer")||r.anyOf?.some(a=>a.type==="number"||a.type==="integer"))&&typeof o[p]=="string"&&(o[p]=Number(o[p]));let b=await d._call(t,o);return{content:[{type:"text",text:JSON.stringify(b,null,2)}]}}catch(i){return{content:[{type:"text",text:i instanceof Error?i.message:String(i)}],isError:!0}}});let g=new O;await s.connect(g)}export{P as startMcpServer};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
|
|
2
|
-
import{A as v,B as w,f as a,g as b,h as c,i as d,j as e,k as f,l as g,m as h,n as i,o as j,p as k,q as l,r as m,s as n,t as o,u as p,v as q,w as r,x as s,y as t,z as u}from"./chunk-
|
|
2
|
+
import{A as v,B as w,f as a,g as b,h as c,i as d,j as e,k as f,l as g,m as h,n as i,o as j,p as k,q as l,r as m,s as n,t as o,u as p,v as q,w as r,x as s,y as t,z as u}from"./chunk-2CBFFXK6.js";import"./chunk-PHXOVWSJ.js";import"./chunk-LMDE72OE.js";export{m as addHardwareWallet,u as addWallet,d as createWallet,j as deleteWallet,l as exportSecret,h as findWallet,i as findWalletOrThrow,a as getVaultPath,e as importMnemonic,f as importPrivateKey,g as listWallets,s as loadWallets,c as migrateWallets,w as mutateWallets,p as owsSignMessage,o as owsSignTransaction,q as owsSignTypedData,n as refreshHardwareAddresses,t as removeWallet,k as renameWallet,b as requireMigrationCheck,r as resolveSigningKey,v as saveWallets};
|
package/package.json
CHANGED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: moonpay-portfolio
|
|
3
|
+
description: Manage auto-rebalancing tokenized stock portfolios on Solana. Buy into preset or custom portfolios of xStocks (tokenized US equities), check allocation drift, and rebalance via MoonPay CLI swaps. Use when the user says "portfolio", "rebalance", "mag 7", "tokenized stocks", or "xstocks".
|
|
4
|
+
tags: [portfolio, trading, rebalance, xstocks]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Tokenized Stock Portfolios
|
|
8
|
+
|
|
9
|
+
Manage portfolios of tokenized US stocks (xStocks by Backed Finance) on Solana. Check allocation drift, plan rebalances, and execute swaps via `mp token swap`. All trades route through USDC.
|
|
10
|
+
|
|
11
|
+
xStocks are 1:1 backed by underlying equities, EU-regulated, tradeable 24/7, and composable with DeFi on Solana.
|
|
12
|
+
|
|
13
|
+
## Prerequisites
|
|
14
|
+
|
|
15
|
+
- `mp` CLI installed and authenticated (`mp login` / `mp verify`)
|
|
16
|
+
- A funded Solana wallet with USDC (`mp wallet list`)
|
|
17
|
+
|
|
18
|
+
## Constants
|
|
19
|
+
|
|
20
|
+
- **USDC Mint:** `EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v`
|
|
21
|
+
- **Chain:** `solana`
|
|
22
|
+
- **xStocks decimals:** 8
|
|
23
|
+
|
|
24
|
+
## Asset Registry
|
|
25
|
+
|
|
26
|
+
Only xStocks with verified DEX liquidity. Refresh liquidity with `mp token retrieve` before large trades.
|
|
27
|
+
|
|
28
|
+
| Symbol | Underlying | Mint |
|
|
29
|
+
|--------|-----------|------|
|
|
30
|
+
| NVDAx | NVIDIA | Xsc9qvGR1efVDFGLrVsmkzv3qi45LTBjeUKSPmx9qEh |
|
|
31
|
+
| TSLAx | Tesla | XsDoVfqeBukxuZHWhdvWHBhgEHjGNst4MLodqsJHzoB |
|
|
32
|
+
| SPYx | S&P 500 ETF | XsoCS1TfEyfFhfvj8EtZ528L3CaKBDBRqRapnBbDF2W |
|
|
33
|
+
| QQQx | Nasdaq 100 ETF | Xs8S1uUs1zvS2p7iwtsG3b6fkhpvmwz4GYU3gWAmWHZ |
|
|
34
|
+
| CRCLx | Circle | XsueG8BtpquVJX9LVLLEGuViXUungE6WmK5YZ3p3bd1 |
|
|
35
|
+
| MSTRx | MicroStrategy | XsP7xzNPvEHS1m6qfanPUGjNmdnmsLKEoNAnHjdxxyZ |
|
|
36
|
+
| GOOGLx | Alphabet | XsCPL9dNWBMvFtTmwcCA5v3xWPSMEBCszbQdiLLq6aN |
|
|
37
|
+
| COINx | Coinbase | Xs7ZdzSHLU9ftNJsii5fCeJhoRWSC32SQGzGQtePxNu |
|
|
38
|
+
| AMZNx | Amazon | Xs3eBt7uRfJX8QUs4suhyU8p2M6DoUDrJyWBa8LLZsg |
|
|
39
|
+
| HOODx | Robinhood | XsvNBAYkrDRNhA7wPHQfX3ZUXZyZLdnCQDfHZ56bzpg |
|
|
40
|
+
| GLDx | SPDR Gold ETF | Xsv9hRk1z5ystj9MhnA7Lq4vjSsLwzL2nxrwmwtD3re |
|
|
41
|
+
| MSFTx | Microsoft | XspzcW1PRtgf6Wj92HCiZdjzKCyFekVD8P5Ueh3dRMX |
|
|
42
|
+
| AAPLx | Apple | XsbEhLAtcf6HdfpFZ5xEMdqW8nfAvcsP5bdudRLJzJp |
|
|
43
|
+
| METAx | Meta | Xsa62P5mvPszXL1krVUnU5ar38bBSVcWAB6fmPCo5Zu |
|
|
44
|
+
|
|
45
|
+
## Portfolio Templates
|
|
46
|
+
|
|
47
|
+
These are example starting points. Weights should be calculated fresh before first buy — see "Calculating Weights" below.
|
|
48
|
+
|
|
49
|
+
### mag7 — Magnificent 7
|
|
50
|
+
|
|
51
|
+
The seven largest US tech companies weighted by real-world market cap.
|
|
52
|
+
|
|
53
|
+
**Tokens:** AAPLx, MSFTx, NVDAx, GOOGLx, AMZNx, METAx, TSLAx
|
|
54
|
+
|
|
55
|
+
### onchain_finance — Onchain Finance
|
|
56
|
+
|
|
57
|
+
Companies building the onchain financial stack. Equal weight or market-cap weight — user's choice.
|
|
58
|
+
|
|
59
|
+
**Tokens:** CRCLx, COINx, MSTRx, HOODx
|
|
60
|
+
|
|
61
|
+
### barbell — Tech + Gold Barbell
|
|
62
|
+
|
|
63
|
+
Growth + safety hedge. Heavy tech index exposure with gold and broad market as ballast.
|
|
64
|
+
|
|
65
|
+
**Tokens:** QQQx, GLDx, SPYx
|
|
66
|
+
|
|
67
|
+
## Calculating Weights
|
|
68
|
+
|
|
69
|
+
Weights must be calculated at portfolio creation time and refreshed periodically.
|
|
70
|
+
|
|
71
|
+
### Market-cap weighted
|
|
72
|
+
|
|
73
|
+
For portfolios like mag7 where weights should be proportional to company size:
|
|
74
|
+
|
|
75
|
+
1. **Get real-world market caps from Google Finance.** xStock prices track the underlying 1:1, but price alone doesn't give you market cap (different companies have different share counts). Fetch from:
|
|
76
|
+
```
|
|
77
|
+
https://www.google.com/finance/quote/AAPL:NASDAQ
|
|
78
|
+
https://www.google.com/finance/quote/MSFT:NASDAQ
|
|
79
|
+
https://www.google.com/finance/quote/NVDA:NASDAQ
|
|
80
|
+
...
|
|
81
|
+
```
|
|
82
|
+
Parse the "Market cap" field from each page. Alternatively, web search "[TICKER] market cap" for each stock.
|
|
83
|
+
|
|
84
|
+
2. **Calculate weights:** `weight_i = market_cap_i / sum(all_market_caps) * 100`
|
|
85
|
+
|
|
86
|
+
3. **Get latest on-chain data** for each token via `mp token retrieve --token <mint> --chain solana` to verify liquidity and volume are sufficient before committing weights.
|
|
87
|
+
|
|
88
|
+
### Equal weight
|
|
89
|
+
|
|
90
|
+
Divide 100% by the number of tokens. Use a tighter drift threshold (3%) since equal-weight benefits from frequent rebalancing.
|
|
91
|
+
|
|
92
|
+
### Custom weight
|
|
93
|
+
|
|
94
|
+
User picks arbitrary weights. Must sum to 100%. Save to `~/.config/moonpay/portfolios/<name>.json`.
|
|
95
|
+
|
|
96
|
+
## Commands
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
mp wallet list # list wallets
|
|
100
|
+
mp token balance list --wallet <address> --chain solana # balances
|
|
101
|
+
mp token retrieve --token <mint> --chain solana # price, volume, liquidity
|
|
102
|
+
mp token quote --from-chain solana --from-token <mint> --from-amount <amt> --to-chain solana --to-token <mint>
|
|
103
|
+
mp token swap --wallet <name> --chain solana --from-token <mint> --from-amount <amt> --to-token <mint>
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Workflow: Portfolio Status
|
|
107
|
+
|
|
108
|
+
1. `mp wallet list` → get Solana address for wallet name.
|
|
109
|
+
2. `mp token balance list --wallet <address> --chain solana` → holdings. Response: `{ items: [...] }`, each item has `address` (mint), `symbol`, `balance: { amount, value, price }`.
|
|
110
|
+
3. For each portfolio token: `mp token retrieve --token <mint> --chain solana` → `marketData.price`.
|
|
111
|
+
4. Calculate per position:
|
|
112
|
+
- `current_usd` = amount * price
|
|
113
|
+
- `current_weight` = current_usd / total_portfolio_usd * 100
|
|
114
|
+
- `drift` = current_weight - target_weight
|
|
115
|
+
5. Show table. Flag positions where `|drift| > threshold` with `←`.
|
|
116
|
+
|
|
117
|
+
## Workflow: Rebalance
|
|
118
|
+
|
|
119
|
+
Rebalancing does NOT require knowing market caps. It's purely mechanical: compare current weights to target weights, trade the difference through USDC.
|
|
120
|
+
|
|
121
|
+
### Plan (always first)
|
|
122
|
+
|
|
123
|
+
1. Run Status workflow.
|
|
124
|
+
2. For each position where `|drift| > threshold`:
|
|
125
|
+
- **Overweight**: excess tokens to sell = `delta_usd / price`
|
|
126
|
+
- **Underweight**: USDC to buy = `|delta_usd|`
|
|
127
|
+
3. Show swap plan. **Stop. Do NOT execute without explicit user confirmation.**
|
|
128
|
+
|
|
129
|
+
### Execute (after user says go)
|
|
130
|
+
|
|
131
|
+
1. **Sells first** (overweight → USDC):
|
|
132
|
+
```bash
|
|
133
|
+
mp token swap --wallet <name> --chain solana \
|
|
134
|
+
--from-token <overweight-mint> --from-amount <excess-tokens> \
|
|
135
|
+
--to-token EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
|
|
136
|
+
```
|
|
137
|
+
2. **Buys second** (USDC → underweight, largest deficit first):
|
|
138
|
+
```bash
|
|
139
|
+
mp token swap --wallet <name> --chain solana \
|
|
140
|
+
--from-token EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v \
|
|
141
|
+
--from-amount <usdc-amount> --to-token <underweight-mint>
|
|
142
|
+
```
|
|
143
|
+
3. Re-run Status to confirm final allocation.
|
|
144
|
+
|
|
145
|
+
## Workflow: Initial Buy
|
|
146
|
+
|
|
147
|
+
When wallet has USDC but no xStocks:
|
|
148
|
+
|
|
149
|
+
1. Confirm portfolio and USDC amount.
|
|
150
|
+
2. Split: `usdc_per_token = total * weight / 100`.
|
|
151
|
+
3. Show plan. After user confirms, execute each buy (USDC → xStock).
|
|
152
|
+
|
|
153
|
+
## Workflow: Custom Portfolio
|
|
154
|
+
|
|
155
|
+
1. Show asset registry. User picks tokens + weights (must sum to 100%).
|
|
156
|
+
2. Save to `~/.config/moonpay/portfolios/<name>.json`:
|
|
157
|
+
```json
|
|
158
|
+
{ "name": "My Portfolio", "threshold_pct": 5, "allocations": { "NVDAx": 25, "TSLAx": 25, "SPYx": 50 } }
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Workflow: Schedule Auto-Rebalance
|
|
162
|
+
|
|
163
|
+
Set up a cron-triggered Claude Code session that checks drift and rebalances automatically.
|
|
164
|
+
|
|
165
|
+
### The rebalance script
|
|
166
|
+
|
|
167
|
+
Generate `~/.config/moonpay/scripts/rebalance-<portfolio>.sh`. This script invokes Claude Code headlessly to run the rebalance workflow:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
#!/bin/bash
|
|
171
|
+
set -euo pipefail
|
|
172
|
+
|
|
173
|
+
LOG="$HOME/.config/moonpay/logs/rebalance.log"
|
|
174
|
+
mkdir -p "$(dirname "$LOG")"
|
|
175
|
+
|
|
176
|
+
WALLET="<wallet-name>"
|
|
177
|
+
PORTFOLIO="<portfolio-name>"
|
|
178
|
+
|
|
179
|
+
echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] START $PORTFOLIO rebalance" >> "$LOG"
|
|
180
|
+
|
|
181
|
+
# Claude Code runs the rebalance skill headlessly
|
|
182
|
+
claude -p "Rebalance my $PORTFOLIO portfolio using wallet $WALLET. Execute any needed swaps." \
|
|
183
|
+
--allowedTools "Bash(moonpay*),Bash(mp *),Read,Write" \
|
|
184
|
+
>> "$LOG" 2>&1
|
|
185
|
+
|
|
186
|
+
echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] END $PORTFOLIO rebalance" >> "$LOG"
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
chmod +x ~/.config/moonpay/scripts/rebalance-<portfolio>.sh
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### macOS (launchd)
|
|
194
|
+
|
|
195
|
+
Write `~/Library/LaunchAgents/com.moonpay.rebalance-<portfolio>.plist`:
|
|
196
|
+
|
|
197
|
+
```xml
|
|
198
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
199
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
|
|
200
|
+
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
201
|
+
<plist version="1.0">
|
|
202
|
+
<dict>
|
|
203
|
+
<key>Label</key><string>com.moonpay.rebalance-PORTFOLIO</string>
|
|
204
|
+
<key>ProgramArguments</key>
|
|
205
|
+
<array>
|
|
206
|
+
<string>/bin/bash</string>
|
|
207
|
+
<string>SCRIPT_PATH</string>
|
|
208
|
+
</array>
|
|
209
|
+
<key>StartCalendarInterval</key>
|
|
210
|
+
<dict><key>Hour</key><integer>9</integer><key>Minute</key><integer>0</integer></dict>
|
|
211
|
+
<key>StandardOutPath</key><string>LOG_DIR/stdout.log</string>
|
|
212
|
+
<key>StandardErrorPath</key><string>LOG_DIR/stderr.log</string>
|
|
213
|
+
</dict>
|
|
214
|
+
</plist>
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Replace PORTFOLIO, SCRIPT_PATH, LOG_DIR with actual values. Load: `launchctl load ~/Library/LaunchAgents/com.moonpay.rebalance-<portfolio>.plist`
|
|
218
|
+
|
|
219
|
+
### Linux (cron)
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
0 9 * * * ~/.config/moonpay/scripts/rebalance-mag7.sh # daily 9am UTC
|
|
223
|
+
0 9 * * 1 ~/.config/moonpay/scripts/rebalance-mag7.sh # weekly Monday 9am
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Workflow: Liquidate
|
|
227
|
+
|
|
228
|
+
Sell all xStocks back to USDC:
|
|
229
|
+
|
|
230
|
+
1. Get balances. For each xStock with balance > 0, sell full amount to USDC.
|
|
231
|
+
2. Show total USDC recovered.
|
|
232
|
+
|
|
233
|
+
## Safety Rules
|
|
234
|
+
|
|
235
|
+
1. **Never execute without confirmation.** Always show the plan first.
|
|
236
|
+
2. **Skip dust.** Ignore trades < $1.
|
|
237
|
+
3. **Slippage warning.** If trade > 20% of token's `marketData.liquidity`, warn user.
|
|
238
|
+
4. **Sells before buys.** Frees USDC before spending it.
|
|
239
|
+
5. **Log everything** to `~/.config/moonpay/logs/rebalance.log`.
|
|
240
|
+
6. **Verify mints** against the Asset Registry above before any swap.
|