graz 0.1.0-alpha.4 → 0.1.0-beta.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 Strangelove Ventures
3
+ Copyright (c) 2023 Graz
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  [![npm/v](https://badgen.net/npm/v/graz)](https://www.npmjs.com/package/graz)
4
4
  [![npm/dt](https://badgen.net/npm/dt/graz)](https://www.npmjs.com/package/graz)
5
- [![stars](https://badgen.net/github/stars/strangelove-ventures/graz)](https://github.com/strangelove-ventures/graz)
5
+ [![stars](https://badgen.net/github/stars/graz-sh/graz)](https://github.com/graz-sh/graz)
6
6
 
7
- React hooks for Cosmos. Learn more about graz on the [official GitHub repository](https://github.com/strangelove-ventures/graz).
7
+ React hooks for Cosmos. Learn more about graz on the [official GitHub repository](https://github.com/graz-sh/graz).
8
8
 
9
- [MIT License, Copyright (c) 2023 Strangelove Ventures](./LICENSE)
9
+ [MIT License, Copyright (c) 2023 Graz](./LICENSE)
package/dist/.gitkeep ADDED
File without changes
package/dist/cli.js ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ var R = require('fs/promises');
5
+ var K = require('path');
6
+ var cosmos = require('@keplr-wallet/cosmos');
7
+ var cosmosDirectoryClient = require('cosmos-directory-client');
8
+
9
+ function _interopNamespace(e) {
10
+ if (e && e.__esModule) return e;
11
+ var n = Object.create(null);
12
+ if (e) {
13
+ Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default') {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
21
+ });
22
+ }
23
+ n.default = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var R__namespace = /*#__PURE__*/_interopNamespace(R);
28
+ var K__namespace = /*#__PURE__*/_interopNamespace(K);
29
+
30
+ var X=Object.create;var L=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var Z=Object.getPrototypeOf,ee=Object.prototype.hasOwnProperty;var te=(e,t)=>()=>(e&&(t=e(e=0)),t);var ne=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var oe=(e,t,r,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of W(t))!ee.call(e,o)&&o!==r&&L(e,o,{get:()=>t[o],enumerable:!(p=J(t,o))||p.enumerable});return e};var re=(e,t,r)=>(r=e!=null?X(Z(e)):{},oe(t||!e||!e.__esModule?L(r,"default",{value:e,enumerable:!0}):r,e));var g=(e,t,r)=>new Promise((p,o)=>{var m=s=>{try{n(r.next(s));}catch(a){o(a);}},h=s=>{try{n(r.throw(s));}catch(a){o(a);}},n=s=>s.done?p(s.value):Promise.resolve(s.value).then(m,h);n((r=r.apply(e,t)).next());});var I=te(()=>{});var Y=ne((me,z)=>{I();var $=Symbol("arg flag"),d=class e extends Error{constructor(t,r){super(t),this.name="ArgError",this.code=r,Object.setPrototypeOf(this,e.prototype);}};function C(e,{argv:t=process.argv.slice(2),permissive:r=!1,stopAtPositional:p=!1}={}){if(!e)throw new d("argument specification object is required","ARG_CONFIG_NO_SPEC");let o={_:[]},m={},h={};for(let n of Object.keys(e)){if(!n)throw new d("argument key cannot be an empty string","ARG_CONFIG_EMPTY_KEY");if(n[0]!=="-")throw new d(`argument key must start with '-' but found: '${n}'`,"ARG_CONFIG_NONOPT_KEY");if(n.length===1)throw new d(`argument key must have a name; singular '-' keys are not allowed: ${n}`,"ARG_CONFIG_NONAME_KEY");if(typeof e[n]=="string"){m[n]=e[n];continue}let s=e[n],a=!1;if(Array.isArray(s)&&s.length===1&&typeof s[0]=="function"){let[f]=s;s=(u,l,c=[])=>(c.push(f(u,l,c[c.length-1])),c),a=f===Boolean||f[$]===!0;}else if(typeof s=="function")a=s===Boolean||s[$]===!0;else throw new d(`type missing or not a function or valid array type: ${n}`,"ARG_CONFIG_VAD_TYPE");if(n[1]!=="-"&&n.length>2)throw new d(`short argument keys (with a single hyphen) must have only one character: ${n}`,"ARG_CONFIG_SHORTOPT_TOOLONG");h[n]=[s,a];}for(let n=0,s=t.length;n<s;n++){let a=t[n];if(p&&o._.length>0){o._=o._.concat(t.slice(n));break}if(a==="--"){o._=o._.concat(t.slice(n+1));break}if(a.length>1&&a[0]==="-"){let f=a[1]==="-"||a.length===2?[a]:a.slice(1).split("").map(u=>`-${u}`);for(let u=0;u<f.length;u++){let l=f[u],[c,_]=l[1]==="-"?l.split(/=(.*)/,2):[l,void 0],i=c;for(;i in m;)i=m[i];if(!(i in h))if(r){o._.push(l);continue}else throw new d(`unknown or unexpected option: ${c}`,"ARG_UNKNOWN_OPTION");let[y,O]=h[i];if(!O&&u+1<f.length)throw new d(`option requires argument (but was followed by another short argument): ${c}`,"ARG_MISSING_REQUIRED_SHORTARG");if(O)o[i]=y(!0,i,o[i]);else if(_===void 0){if(t.length<n+2||t[n+1].length>1&&t[n+1][0]==="-"&&!(t[n+1].match(/^-?\d*(\.(?=\d))?\d*$/)&&(y===Number||typeof BigInt!="undefined"&&y===BigInt))){let N=c===i?"":` (alias for ${i})`;throw new d(`option requires argument: ${c}${N}`,"ARG_MISSING_REQUIRED_LONGARG")}o[i]=y(t[n+1],i,o[i]),++n;}else o[i]=y(_,i,o[i]);}}else o._.push(a);}return o}C.flag=e=>(e[$]=!0,e);C.COUNT=C.flag((e,t,r)=>(r||0)+1);C.ArgError=d;z.exports=C;});I();var V=re(Y(),1);I();var M=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t;}},H=e=>globalThis.DOMException===void 0?new M(e):new DOMException(e),B=e=>{let t=e.reason===void 0?H("This operation was aborted."):e.reason;return t instanceof Error?t:H(t)};function D(m,h){return g(this,arguments,function*(e,t,{concurrency:r=Number.POSITIVE_INFINITY,stopOnError:p=!0,signal:o}={}){return new Promise((n,s)=>{if(e[Symbol.iterator]===void 0&&e[Symbol.asyncIterator]===void 0)throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof e})`);if(typeof t!="function")throw new TypeError("Mapper function is required");if(!((Number.isSafeInteger(r)||r===Number.POSITIVE_INFINITY)&&r>=1))throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${r}\` (${typeof r})`);let a=[],f=[],u=new Map,l=!1,c=!1,_=!1,i=0,y=0,O=e[Symbol.iterator]===void 0?e[Symbol.asyncIterator]():e[Symbol.iterator](),N=A=>{l=!0,c=!0,s(A);};o&&(o.aborted&&N(B(o)),o.addEventListener("abort",()=>{N(B(o));}));let k=()=>g(this,null,function*(){if(c)return;let A=yield O.next(),T=y;if(y++,A.done){if(_=!0,i===0&&!c){if(!p&&f.length>0){N(new AggregateError(f));return}if(c=!0,u.size===0){n(a);return}let b=[];for(let[w,Q]of a.entries())u.get(w)!==U&&b.push(Q);n(b);}return}i++,g(this,null,function*(){try{let b=yield A.value;if(c)return;let w=yield t(b,T);w===U&&u.set(T,w),a[T]=w,i--,yield k();}catch(b){if(p)N(b);else {f.push(b),i--;try{yield k();}catch(w){N(w);}}}});});g(this,null,function*(){for(let A=0;A<r;A++){try{yield k();}catch(T){N(T);break}if(_||l)break}});})})}var U=Symbol("skip");var ce=e=>/^\d+$/.test(e),j=e=>ce(e[0])?`_${e}`:e,v=`Usage: graz [options]
31
+
32
+ Options:
33
+
34
+ -g, --generate Generate chain definitions and export to "graz/chains"
35
+ -h, --help Show this help message
36
+
37
+ Generate options:
38
+ -b, --best Set REST and RPC endpoint to best available nodes instead or first listed ones
39
+ -M, --mainnet Generate given mainnet chain paths seperated by commas (e.g. "axelar,cosmoshub,juno")
40
+ -T, --testnet Generate given testnet chain paths seperated by commas (e.g. "atlantic,bitcannadev,cheqdtestnet")
41
+ --authz Generate only authz compatible chains
42
+
43
+ https://github.com/graz-sh/graz
44
+ `,E=(0, V.default)({"--generate":Boolean,"-g":"--generate","--authz":Boolean,"--best":Boolean,"--mainnet":String,"--testnet":String,"-b":"--best","-M":"--mainnet","-T":"--testnet","--help":Boolean,"-h":"--help"}),le=()=>g(void 0,null,function*(){if(E["--help"]){console.log(v);return}if(E["--generate"]){yield ue();return}console.log(v);}),ue=()=>g(void 0,null,function*(){console.log("\u23F3 Generating chain list from cosmos.directory..."),E["--authz"]&&console.log("\u270D\uFE0F Detected authz flag, generating only compatible chains..."),E["--best"]&&console.log("\u{1F481}\u200D\u2642\uFE0F Detected best flag, setting REST and RPC endpoints to best latency..."),(E["--mainnet"]||E["--testnet"])&&console.log("\u{1F419} Detected chain filtering flag, generating only given chain paths...");let[e,t]=yield Promise.all([q(cosmosDirectoryClient.createClient(),{filter:E["--mainnet"]}),q(cosmosDirectoryClient.createTestnetClient(),{filter:E["--testnet"]})]),[r,p]=yield Promise.all([R__namespace.readFile(x("index.js.stub"),{encoding:"utf-8"}),R__namespace.readFile(x("index.mjs.stub"),{encoding:"utf-8"})]),o=r.replace("/* REPLACE_MAINNET_DEFS */",G(e)).replace("/* REPLACE_TESTNET_DEFS */",G(t,{testnet:!0})).replace("/* REPLACE_MAINNET_CHAINS */",P(e)).replace("/* REPLACE_TESTNET_CHAINS */",P(t,{testnet:!0})).replace("/* REPLACE_MAINNET_CHAINS_ARRAY */",S(e)).replace("/* REPLACE_TESTNET_CHAINS_ARRAY */",S(t,{testnet:!0})).replace("/* REPLACE_MAINNET_EXPORTS */",S(e)).replace("/* REPLACE_TESTNET_EXPORTS */",S(t,{testnet:!0})).replace(/"(.+)":/g,"$1:").trim(),m=p.replace("/* REPLACE_MAINNET_DEFS */",G(e,{mjs:!0})).replace("/* REPLACE_TESTNET_DEFS */",G(t,{mjs:!0,testnet:!0})).replace("/* REPLACE_MAINNET_CHAINS */",P(e)).replace("/* REPLACE_TESTNET_CHAINS */",P(t,{testnet:!0})).replace("/* REPLACE_MAINNET_CHAINS_ARRAY */",S(e)).replace("/* REPLACE_TESTNET_CHAINS_ARRAY */",S(t,{testnet:!0})).replace(/"(.+)":/g,"$1:").trim();yield Promise.all([R__namespace.writeFile(x("index.js"),o,{encoding:"utf-8"}),R__namespace.writeFile(x("index.mjs"),m.replace('"../dist"','"../dist/index.mjs"'),{encoding:"utf-8"}),R__namespace.writeFile(x("index.ts"),m,{encoding:"utf-8"})]),console.log('\u2728 Generate complete! You can import `mainnetChains` and `testnetChains` from "graz/chains".\n');}),x=(...e)=>K__namespace.resolve(__dirname,"../chains",...e),P=(e,{testnet:t=!1}={})=>Object.keys(e).map(r=>` ${j(r)}: ${j(r)},`).join(`
45
+ `),G=(e,{mjs:t=!1,testnet:r=!1}={})=>Object.entries(e).map(([p,o])=>{let m=`${j(p)}`,h=JSON.stringify(o,null,2);return `${t?"export ":""}const ${m} = defineChainInfo(${h});
46
+ `}).join(""),S=(e,{testnet:t=!1}={})=>Object.keys(e).map(r=>` ${j(r)},`).join(`
47
+ `),q=(r,...p)=>g(void 0,[r,...p],function*(e,{filter:t=""}={}){let o=t?t.split(",").map(n=>({path:n})):yield e.fetchChains().then(n=>n.chains.map(({path:s})=>({path:s}))),m=yield D(o,n=>g(void 0,null,function*(){return e.fetchChain(n.path).then(s=>s.chain)}),{concurrency:4}),h={};return m.forEach(n=>{var s,a,f,u;try{if(E["--authz"]&&!((s=n.params)!=null&&s.authz))return;let l=E["--best"]?n.best_apis:n.apis;if(!l||!((a=l.rest)!=null&&a[0])||!((f=l.rpc)!=null&&f[0]))throw new Error(`\u26A0\uFE0F ${n.name} has no REST/RPC endpoints, skipping codegen...`);if(!n.assets)throw new Error(`\u26A0\uFE0F ${n.name} has no assets, skipping codegen...`);let c=n.assets[0],_={coinDenom:c.denom_units[c.denom_units.length-1].denom,coinMinimalDenom:c.denom_units[0].denom,coinDecimals:c.denom_units[c.denom_units.length-1].exponent,coinGeckoId:c.coingecko_id};h[n.path]={chainId:n.chain_id,currencies:n.assets.map(i=>({coinDenom:i.denom_units[i.denom_units.length-1].denom,coinMinimalDenom:i.denom_units[0].denom,coinDecimals:i.denom_units[i.denom_units.length-1].exponent,coinGeckoId:i.coingecko_id})),rest:l.rest[0].address||"",rpc:l.rpc[0].address||"",bech32Config:cosmos.Bech32Address.defaultBech32Config(n.bech32_prefix),chainName:n.chain_name,feeCurrencies:[_],stakeCurrency:_,bip44:{coinType:(u=n.slip44)!=null?u:0}};}catch(l){console.error(l instanceof Error?l.message:String(l));}}),h});le();