@avalabs/bitcoin-module 0.0.20 → 0.0.21
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/.turbo/turbo-build.log +6 -6
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-test.log +3 -3
- package/CHANGELOG.md +6 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @avalabs/bitcoin-module@0.0.
|
|
2
|
+
> @avalabs/bitcoin-module@0.0.21 build /home/runner/work/vm-modules/vm-modules/packages/bitcoin-module
|
|
3
3
|
> tsup
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: ./src/index.ts
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
[34mESM[39m Build start
|
|
13
13
|
[34mDTS[39m Build start
|
|
14
14
|
[32mCJS[39m [1mdist/index.cjs [22m[32m277.92 KB[39m
|
|
15
|
-
[32mCJS[39m [1mdist/index.cjs.map [22m[32m916.
|
|
16
|
-
[32mCJS[39m ⚡️ Build success in
|
|
15
|
+
[32mCJS[39m [1mdist/index.cjs.map [22m[32m916.88 KB[39m
|
|
16
|
+
[32mCJS[39m ⚡️ Build success in 17901ms
|
|
17
17
|
[32mESM[39m [1mdist/index.js [22m[32m277.03 KB[39m
|
|
18
|
-
[32mESM[39m [1mdist/index.js.map [22m[32m916.
|
|
19
|
-
[32mESM[39m ⚡️ Build success in
|
|
20
|
-
[32mDTS[39m ⚡️ Build success in
|
|
18
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m916.88 KB[39m
|
|
19
|
+
[32mESM[39m ⚡️ Build success in 17902ms
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 25585ms
|
|
21
21
|
[32mDTS[39m [1mdist/index.d.cts [22m[32m1.25 KB[39m
|
|
22
22
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m1.25 KB[39m
|
package/.turbo/turbo-lint.log
CHANGED
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
|
-
> @avalabs/bitcoin-module@0.0.
|
|
2
|
+
> @avalabs/bitcoin-module@0.0.21 test /home/runner/work/vm-modules/vm-modules/packages/bitcoin-module
|
|
3
3
|
> jest
|
|
4
4
|
|
|
5
|
-
PASS src/handlers/get-balances/get-balances.test.ts (
|
|
5
|
+
PASS src/handlers/get-balances/get-balances.test.ts (35.723 s)
|
|
6
6
|
PASS src/handlers/get-transaction-history/convert-btc-transaction.test.ts
|
|
7
7
|
PASS src/handlers/get-transaction-history/get-transaction-history.test.ts
|
|
8
8
|
PASS src/module.test.ts
|
|
@@ -12,5 +12,5 @@ PASS src/handlers/get-network-fee/get-network-fee.test.ts
|
|
|
12
12
|
Test Suites: 6 passed, 6 total
|
|
13
13
|
Tests: 20 passed, 20 total
|
|
14
14
|
Snapshots: 0 total
|
|
15
|
-
Time:
|
|
15
|
+
Time: 43.146 s
|
|
16
16
|
Ran all test suites.
|
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -40,7 +40,7 @@ status: ${s.status} ${s.statusText}
|
|
|
40
40
|
cause:
|
|
41
41
|
${d.error.message}
|
|
42
42
|
received:
|
|
43
|
-
${JSON.stringify(s.data,null,2)}`,i,s.data,d.error);co(e)&&(s.data=d.data);}return s}:void 0}}var lo=class{constructor(a,e){this.plugins=[],this.key=`${a}-${e}`;}indexOf(a){return this.plugins.findIndex(e=>e?.name===a)}use(a){if(a.name){let e=this.indexOf(a.name);if(e!==-1)return this.plugins[e]=a,{key:this.key,value:e}}return this.plugins.push(a),{key:this.key,value:this.plugins.length-1}}eject(a){if(typeof a=="string"){let e=this.indexOf(a);if(e===-1)throw new Error(`Plugin with name '${a}' not found`);this.plugins[e]=void 0;}else {if(a.key!==this.key)throw new Error(`Plugin with key '${a.key}' is not registered for endpoint '${this.key}'`);this.plugins[a.value]=void 0;}}async interceptRequest(a,e){let t=e;for(let n of this.plugins)n!=null&&n.request&&(t=await n.request(a,t));return t}async interceptResponse(a,e,t){let n=t;for(let i=this.plugins.length-1;i>=0;i--){let s=this.plugins[i];s&&(n=n.then(s!=null&&s.response?o=>s.response(a,e,o):void 0,s!=null&&s.error?o=>s.error(a,e,o):void 0));}return n}count(){return this.plugins.reduce((a,e)=>e?a+1:a,0)}};function pl(a){let e=new Set;for(let n of a){let i=`${n.method} ${n.path}`;if(e.has(i))throw new Error(`Zodios: Duplicate path '${i}'`);e.add(i);}let t=new Set;for(let n of a)if(n.alias){if(t.has(n.alias))throw new Error(`Zodios: Duplicate alias '${n.alias}'`);t.add(n.alias);}for(let n of a)if(n.parameters&&n.parameters.filter(i=>i.type==="Body").length>1)throw new Error(`Zodios: Multiple body parameters in endpoint '${n.path}'`)}var ll=class{constructor(a,e,t){this.endpointPlugins=new Map;let n;if(!a)throw Array.isArray(e)?new Error("Zodios: missing base url"):new Error("Zodios: missing api description");let i;if(typeof a=="string"&&Array.isArray(e))i=a,this.api=e,n=t||{};else if(Array.isArray(a)&&!Array.isArray(e))this.api=a,n=e||{};else throw new Error("Zodios: api must be an array");pl(this.api),this.options={validate:!0,transform:!0,sendDefaults:!1,...n},this.options.axiosInstance?this.axiosInstance=this.options.axiosInstance:this.axiosInstance=Et.create({...this.options.axiosConfig}),i&&(this.axiosInstance.defaults.baseURL=i),this.injectAliasEndpoints(),this.initPlugins(),[!0,"all","request","response"].includes(this.options.validate)&&this.use(cl(this.options));}initPlugins(){this.endpointPlugins.set("any-any",new lo("any","any")),this.api.forEach(a=>{let e=new lo(a.method,a.path);switch(a.requestFormat){case"binary":e.use(ro("Content-Type","application/octet-stream"));break;case"form-data":e.use(sl());break;case"form-url":e.use(rl());break;case"text":e.use(ro("Content-Type","text/plain"));break}this.endpointPlugins.set(`${a.method}-${a.path}`,e);});}getAnyEndpointPlugins(){return this.endpointPlugins.get("any-any")}findAliasEndpointPlugins(a){let e=this.api.find(t=>t.alias===a);if(e)return this.endpointPlugins.get(`${e.method}-${e.path}`)}findEnpointPlugins(a,e){return this.endpointPlugins.get(`${a}-${e}`)}get baseURL(){return this.axiosInstance.defaults.baseURL}get axios(){return this.axiosInstance}use(...a){if(typeof a[0]=="object")return this.getAnyEndpointPlugins().use(a[0]);if(typeof a[0]=="string"&&typeof a[1]=="object"){let e=this.findAliasEndpointPlugins(a[0]);if(!e)throw new Error(`Zodios: no alias '${a[0]}' found to register plugin`);return e.use(a[1])}else if(typeof a[0]=="string"&&typeof a[1]=="string"&&typeof a[2]=="object"){let e=this.findEnpointPlugins(a[0],a[1]);if(!e)throw new Error(`Zodios: no endpoint '${a[0]} ${a[1]}' found to register plugin`);return e.use(a[2])}throw new Error("Zodios: invalid plugin registration")}eject(a){var e;if(typeof a=="string"){this.getAnyEndpointPlugins().eject(a);return}(e=this.endpointPlugins.get(a.key))==null||e.eject(a);}injectAliasEndpoints(){this.api.forEach(a=>{a.alias&&(["post","put","patch","delete"].includes(a.method)?this[a.alias]=(e,t)=>this.request({...t,method:a.method,url:a.path,data:e}):this[a.alias]=e=>this.request({...e,method:a.method,url:a.path}));});}async request(a){let e=a,t=this.getAnyEndpointPlugins(),n=this.findEnpointPlugins(e.method,e.url);e=await t.interceptRequest(this.api,e),n&&(e=await n.interceptRequest(this.api,e));let i=this.axiosInstance.request({...el(e,["params","queries"]),url:tl(e),params:e.queries});return n&&(i=n.interceptResponse(this.api,e,i)),i=t.interceptResponse(this.api,e,i),(await i).data}async get(a,...[e]){return this.request({...e,method:"get",url:a})}async post(a,e,...[t]){return this.request({...t,method:"post",url:a,data:e})}async put(a,e,...[t]){return this.request({...t,method:"put",url:a,data:e})}async patch(a,e,...[t]){return this.request({...t,method:"patch",url:a,data:e})}async delete(a,e,...[t]){return this.request({...t,method:"delete",url:a,data:e})}},uo=ll;var Zn=a=>new uo(`${a}/proxy/coingecko`,[{method:"post",path:"/simple/price",parameters:[{name:"ids",type:"Query",schema:be()},{name:"vs_currencies",type:"Query",schema:be()},{name:"include_market_cap",type:"Query",schema:be().optional()},{name:"include_24hr_vol",type:"Query",schema:be().optional()},{name:"include_24hr_change",type:"Query",schema:be().optional()},{name:"include_last_updated_at",type:"Query",schema:be().optional()}],alias:"simplePrice",response:vmModuleTypes.RawSimplePriceResponseSchema},{method:"post",path:"/simple/token_price/:id",parameters:[{name:"id",type:"Path",schema:be()},{name:"contract_addresses",type:"Query",schema:be().array()},{name:"vs_currencies",type:"Query",schema:be().array()},{name:"include_market_cap",type:"Query",schema:Ot().optional()},{name:"include_24hr_vol",type:"Query",schema:Ot().optional()},{name:"include_24hr_change",type:"Query",schema:Ot().optional()}],alias:"simplePriceByContractAddresses",response:vmModuleTypes.SimplePriceResponseSchema}],{axiosConfig:{headers:{"Content-Type":"application/json"}}});var mo=coingeckoSdk.getBasicCoingeckoHttp(),Ae,ha,Ka=class{constructor({storage:e,proxyApiUrl:t}){ba(this,Ae,void 0);ba(this,ha,void 0);Hn(this,"transformSimplePriceResponse",(e,t=[coingeckoSdk.VsCurrencyType.USD])=>{let n={};return Object.keys(e).forEach(i=>{let s=e[i];n[i]={},t.forEach(o=>{n[i]={[o]:{price:s?.[o],change24:s?.[`${o}_24h_change`],vol24:s?.[`${o}_24h_vol`],marketCap:s?.[`${o}_market_cap`]}};});}),n});ga(this,Ae,e),ga(this,ha,t);}async getSimplePrice({coinIds:e=[],currencies:t=[coingeckoSdk.VsCurrencyType.USD]}){let n,s=`getSimplePrice-${e?`${qt(e)}-${t.toString()}`:`${t.toString()}`}`;if(n=ce(this,Ae)?.get?.(s),n)return n;try{n=await Bt(o=>this.simplePrice({coinIds:e,currencies:t,marketCap:!0,vol24:!0,change24:!0,useCoingeckoProxy:o}));}catch{n=void 0;}return ce(this,Ae)?.set?.(s,n),n}async getPricesByAddresses(e,t,n=coingeckoSdk.VsCurrencyType.USD){let i,o=`getPricesWithMarketDataByAddresses-${`${qt(e)}-${t}-${n}`}`;if(i=ce(this,Ae)?.get?.(o),i)return i;try{i=await Bt(r=>this.fetchPricesByAddresses({assetPlatformId:t,tokenAddresses:e,currency:n,useCoingeckoProxy:r}));}catch{i=void 0;}return ce(this,Ae)?.set?.(o,i),i}async fetchPricesByAddresses({assetPlatformId:e,tokenAddresses:t,currency:n=coingeckoSdk.VsCurrencyType.USD,useCoingeckoProxy:i=!1}){return i?Zn(ce(this,ha)).simplePriceByContractAddresses(void 0,{params:{id:e},queries:{contract_addresses:t,vs_currencies:[n],include_market_cap:!0,include_24hr_vol:!0,include_24hr_change:!0}}):coingeckoSdk.simpleTokenPrice(mo,{assetPlatformId:e,tokenAddresses:t,currencies:[n],marketCap:!0,vol24:!0,change24:!0})}async simplePrice({coinIds:e=[],currencies:t=[coingeckoSdk.VsCurrencyType.USD],marketCap:n=!1,vol24:i=!1,change24:s=!1,lastUpdated:o=!1,useCoingeckoProxy:r=!1,shouldThrow:p=!0}){if(r){let l=await Zn(ce(this,ha)).simplePrice(void 0,{queries:{ids:e?.join(","),vs_currencies:t.join(","),include_market_cap:String(n),include_24hr_vol:String(i),include_24hr_change:String(s),include_last_updated_at:String(o)}});return this.transformSimplePriceResponse(l)}return coingeckoSdk.simplePrice(mo,{coinIds:e,currencies:t,marketCap:n,vol24:i,change24:s,lastUpdated:o,shouldThrow:p})}};Ae=new WeakMap,ha=new WeakMap;var fo=(a,e,t)=>{let n=t?.[a]?.[e??""]??{};return {priceInCurrency:n.price??void 0,marketCap:n.marketCap??void 0,vol24:n.vol24??void 0,change24:n.change24??void 0}};var bo=async({addresses:a,currency:e,network:t,withScripts:n,proxyApiUrl:i,storage:s})=>{let o=$e({isTestnet:!!t.isTestnet,proxyApiUrl:i}),r=new Ka({proxyApiUrl:i,storage:s}),p=t.pricingProviders?.coingecko.nativeTokenId,c=typeof e=="string"&&typeof p=="string"?await r.getSimplePrice({coinIds:[p],currencies:[e]}):void 0,d=t.networkToken.decimals,{priceInCurrency:h,change24:_,marketCap:f,vol24:v}=fo(p??"",e,c);return (await Promise.allSettled(a.map(async j=>{let{balance:N,utxos:k,balanceUnconfirmed:q,utxosUnconfirmed:U}=await o.getUtxoBalance(j,n),$=new vo__default.default(N).div(10**d),G=utilsSdk.bigToBN($,d),ne=utilsSdk.balanceToDisplayValue(G,d),ge=h===void 0?void 0:$.times(h).toNumber(),xa=ge?.toFixed(2),Ya=new vo__default.default(q).div(10**d),ke=utilsSdk.bigToBN(Ya,d),Qa=utilsSdk.balanceToDisplayValue(ke,d),M=h===void 0?void 0:Ya.times(h).toNumber(),De=M?.toFixed(2),va=t.networkToken.symbol;return {[j]:{[va]:{...t.networkToken,utxos:k,utxosUnconfirmed:U,coingeckoId:p??"",type:vmModuleTypes.TokenType.NATIVE,balance:G,balanceDisplayValue:ne,balanceInCurrency:ge,balanceCurrencyDisplayValue:xa,priceInCurrency:h,marketCap:f,vol24:v,change24:_,unconfirmedBalance:ke,unconfirmedBalanceDisplayValue:Qa,unconfirmedBalanceInCurrency:M,unconfirmedBalanceCurrencyDisplayValue:De}}}}))).reduce((j,N)=>N.status==="rejected"?j:{...j,...N.value},{})};var Ie,go=class{constructor({environment:e}){ba(this,Ie,void 0);let{proxyApiUrl:t}=Gn(e);ga(this,Ie,t);}getAddress(){return Promise.resolve("Bitcoin address")}getBalances({addresses:e,currency:t,network:n,storage:i}){return bo({addresses:e,currency:t,network:n,proxyApiUrl:ce(this,Ie),storage:i})}getManifest(){let e=vmModuleTypes.parseManifest(Jn);return e.success?e.data:void 0}getNetworkFee(e){return Kn({isTestnet:!!e.isTestnet,proxyApiUrl:ce(this,Ie)})}async getTransactionHistory({address:e,network:t}){return {transactions:await Xn({address:e,network:t,proxyApiUrl:ce(this,Ie)})}}getTokens(e){return Promise.resolve([])}async onRpcRequest(e,t){switch(e.method){default:return {error:rpcErrors.rpcErrors.methodNotSupported(`Method ${e.method} not supported`)}}}};Ie=new WeakMap;/*! Bundled license information:
|
|
43
|
+
${JSON.stringify(s.data,null,2)}`,i,s.data,d.error);co(e)&&(s.data=d.data);}return s}:void 0}}var lo=class{constructor(a,e){this.plugins=[],this.key=`${a}-${e}`;}indexOf(a){return this.plugins.findIndex(e=>e?.name===a)}use(a){if(a.name){let e=this.indexOf(a.name);if(e!==-1)return this.plugins[e]=a,{key:this.key,value:e}}return this.plugins.push(a),{key:this.key,value:this.plugins.length-1}}eject(a){if(typeof a=="string"){let e=this.indexOf(a);if(e===-1)throw new Error(`Plugin with name '${a}' not found`);this.plugins[e]=void 0;}else {if(a.key!==this.key)throw new Error(`Plugin with key '${a.key}' is not registered for endpoint '${this.key}'`);this.plugins[a.value]=void 0;}}async interceptRequest(a,e){let t=e;for(let n of this.plugins)n!=null&&n.request&&(t=await n.request(a,t));return t}async interceptResponse(a,e,t){let n=t;for(let i=this.plugins.length-1;i>=0;i--){let s=this.plugins[i];s&&(n=n.then(s!=null&&s.response?o=>s.response(a,e,o):void 0,s!=null&&s.error?o=>s.error(a,e,o):void 0));}return n}count(){return this.plugins.reduce((a,e)=>e?a+1:a,0)}};function pl(a){let e=new Set;for(let n of a){let i=`${n.method} ${n.path}`;if(e.has(i))throw new Error(`Zodios: Duplicate path '${i}'`);e.add(i);}let t=new Set;for(let n of a)if(n.alias){if(t.has(n.alias))throw new Error(`Zodios: Duplicate alias '${n.alias}'`);t.add(n.alias);}for(let n of a)if(n.parameters&&n.parameters.filter(i=>i.type==="Body").length>1)throw new Error(`Zodios: Multiple body parameters in endpoint '${n.path}'`)}var ll=class{constructor(a,e,t){this.endpointPlugins=new Map;let n;if(!a)throw Array.isArray(e)?new Error("Zodios: missing base url"):new Error("Zodios: missing api description");let i;if(typeof a=="string"&&Array.isArray(e))i=a,this.api=e,n=t||{};else if(Array.isArray(a)&&!Array.isArray(e))this.api=a,n=e||{};else throw new Error("Zodios: api must be an array");pl(this.api),this.options={validate:!0,transform:!0,sendDefaults:!1,...n},this.options.axiosInstance?this.axiosInstance=this.options.axiosInstance:this.axiosInstance=Et.create({...this.options.axiosConfig}),i&&(this.axiosInstance.defaults.baseURL=i),this.injectAliasEndpoints(),this.initPlugins(),[!0,"all","request","response"].includes(this.options.validate)&&this.use(cl(this.options));}initPlugins(){this.endpointPlugins.set("any-any",new lo("any","any")),this.api.forEach(a=>{let e=new lo(a.method,a.path);switch(a.requestFormat){case"binary":e.use(ro("Content-Type","application/octet-stream"));break;case"form-data":e.use(sl());break;case"form-url":e.use(rl());break;case"text":e.use(ro("Content-Type","text/plain"));break}this.endpointPlugins.set(`${a.method}-${a.path}`,e);});}getAnyEndpointPlugins(){return this.endpointPlugins.get("any-any")}findAliasEndpointPlugins(a){let e=this.api.find(t=>t.alias===a);if(e)return this.endpointPlugins.get(`${e.method}-${e.path}`)}findEnpointPlugins(a,e){return this.endpointPlugins.get(`${a}-${e}`)}get baseURL(){return this.axiosInstance.defaults.baseURL}get axios(){return this.axiosInstance}use(...a){if(typeof a[0]=="object")return this.getAnyEndpointPlugins().use(a[0]);if(typeof a[0]=="string"&&typeof a[1]=="object"){let e=this.findAliasEndpointPlugins(a[0]);if(!e)throw new Error(`Zodios: no alias '${a[0]}' found to register plugin`);return e.use(a[1])}else if(typeof a[0]=="string"&&typeof a[1]=="string"&&typeof a[2]=="object"){let e=this.findEnpointPlugins(a[0],a[1]);if(!e)throw new Error(`Zodios: no endpoint '${a[0]} ${a[1]}' found to register plugin`);return e.use(a[2])}throw new Error("Zodios: invalid plugin registration")}eject(a){var e;if(typeof a=="string"){this.getAnyEndpointPlugins().eject(a);return}(e=this.endpointPlugins.get(a.key))==null||e.eject(a);}injectAliasEndpoints(){this.api.forEach(a=>{a.alias&&(["post","put","patch","delete"].includes(a.method)?this[a.alias]=(e,t)=>this.request({...t,method:a.method,url:a.path,data:e}):this[a.alias]=e=>this.request({...e,method:a.method,url:a.path}));});}async request(a){let e=a,t=this.getAnyEndpointPlugins(),n=this.findEnpointPlugins(e.method,e.url);e=await t.interceptRequest(this.api,e),n&&(e=await n.interceptRequest(this.api,e));let i=this.axiosInstance.request({...el(e,["params","queries"]),url:tl(e),params:e.queries});return n&&(i=n.interceptResponse(this.api,e,i)),i=t.interceptResponse(this.api,e,i),(await i).data}async get(a,...[e]){return this.request({...e,method:"get",url:a})}async post(a,e,...[t]){return this.request({...t,method:"post",url:a,data:e})}async put(a,e,...[t]){return this.request({...t,method:"put",url:a,data:e})}async patch(a,e,...[t]){return this.request({...t,method:"patch",url:a,data:e})}async delete(a,e,...[t]){return this.request({...t,method:"delete",url:a,data:e})}},uo=ll;var Zn=a=>new uo(`${a}/proxy/coingecko`,[{method:"post",path:"/simple/price",parameters:[{name:"ids",type:"Query",schema:be()},{name:"vs_currencies",type:"Query",schema:be()},{name:"include_market_cap",type:"Query",schema:be().optional()},{name:"include_24hr_vol",type:"Query",schema:be().optional()},{name:"include_24hr_change",type:"Query",schema:be().optional()},{name:"include_last_updated_at",type:"Query",schema:be().optional()}],alias:"simplePrice",response:vmModuleTypes.RawSimplePriceResponseSchema},{method:"post",path:"/simple/token_price/:id",parameters:[{name:"id",type:"Path",schema:be()},{name:"contract_addresses",type:"Query",schema:be().array()},{name:"vs_currencies",type:"Query",schema:be().array()},{name:"include_market_cap",type:"Query",schema:Ot().optional()},{name:"include_24hr_vol",type:"Query",schema:Ot().optional()},{name:"include_24hr_change",type:"Query",schema:Ot().optional()}],alias:"simplePriceByContractAddresses",response:vmModuleTypes.SimplePriceResponseSchema}],{axiosConfig:{headers:{"Content-Type":"application/json"}}});var mo=coingeckoSdk.getBasicCoingeckoHttp(),Ae,ha,Ka=class{constructor({storage:e,proxyApiUrl:t}){ba(this,Ae,void 0);ba(this,ha,void 0);Hn(this,"transformSimplePriceResponse",(e,t=[coingeckoSdk.VsCurrencyType.USD])=>{let n={};return Object.keys(e).forEach(i=>{let s=e[i];n[i]={},t.forEach(o=>{n[i]={[o]:{price:s?.[o],change24:s?.[`${o}_24h_change`],vol24:s?.[`${o}_24h_vol`],marketCap:s?.[`${o}_market_cap`]}};});}),n});ga(this,Ae,e),ga(this,ha,t);}async getSimplePrice({coinIds:e=[],currencies:t=[coingeckoSdk.VsCurrencyType.USD]}){let n,s=`getSimplePrice-${e?`${qt(e)}-${t.toString()}`:`${t.toString()}`}`;if(n=ce(this,Ae)?.get?.(s),n)return n;try{n=await Bt(o=>this.simplePrice({coinIds:e,currencies:t,marketCap:!0,vol24:!0,change24:!0,useCoingeckoProxy:o}));}catch{n=void 0;}return ce(this,Ae)?.set?.(s,n),n}async getPricesByAddresses(e,t,n=coingeckoSdk.VsCurrencyType.USD){let i,o=`getPricesWithMarketDataByAddresses-${`${qt(e)}-${t}-${n}`}`;if(i=ce(this,Ae)?.get?.(o),i)return i;try{i=await Bt(r=>this.fetchPricesByAddresses({assetPlatformId:t,tokenAddresses:e,currency:n,useCoingeckoProxy:r}));}catch{i=void 0;}return ce(this,Ae)?.set?.(o,i),i}async fetchPricesByAddresses({assetPlatformId:e,tokenAddresses:t,currency:n=coingeckoSdk.VsCurrencyType.USD,useCoingeckoProxy:i=!1}){return i?Zn(ce(this,ha)).simplePriceByContractAddresses(void 0,{params:{id:e},queries:{contract_addresses:t,vs_currencies:[n],include_market_cap:!0,include_24hr_vol:!0,include_24hr_change:!0}}):coingeckoSdk.simpleTokenPrice(mo,{assetPlatformId:e,tokenAddresses:t,currencies:[n],marketCap:!0,vol24:!0,change24:!0})}async simplePrice({coinIds:e=[],currencies:t=[coingeckoSdk.VsCurrencyType.USD],marketCap:n=!1,vol24:i=!1,change24:s=!1,lastUpdated:o=!1,useCoingeckoProxy:r=!1,shouldThrow:p=!0}){if(r){let l=await Zn(ce(this,ha)).simplePrice(void 0,{queries:{ids:e?.join(","),vs_currencies:t.join(","),include_market_cap:String(n),include_24hr_vol:String(i),include_24hr_change:String(s),include_last_updated_at:String(o)}});return this.transformSimplePriceResponse(l,t)}return coingeckoSdk.simplePrice(mo,{coinIds:e,currencies:t,marketCap:n,vol24:i,change24:s,lastUpdated:o,shouldThrow:p})}};Ae=new WeakMap,ha=new WeakMap;var fo=(a,e,t)=>{let n=t?.[a]?.[e??""]??{};return {priceInCurrency:n.price??void 0,marketCap:n.marketCap??void 0,vol24:n.vol24??void 0,change24:n.change24??void 0}};var bo=async({addresses:a,currency:e,network:t,withScripts:n,proxyApiUrl:i,storage:s})=>{let o=$e({isTestnet:!!t.isTestnet,proxyApiUrl:i}),r=new Ka({proxyApiUrl:i,storage:s}),p=t.pricingProviders?.coingecko.nativeTokenId,c=typeof e=="string"&&typeof p=="string"?await r.getSimplePrice({coinIds:[p],currencies:[e]}):void 0,d=t.networkToken.decimals,{priceInCurrency:h,change24:_,marketCap:f,vol24:v}=fo(p??"",e,c);return (await Promise.allSettled(a.map(async j=>{let{balance:N,utxos:k,balanceUnconfirmed:q,utxosUnconfirmed:U}=await o.getUtxoBalance(j,n),$=new vo__default.default(N).div(10**d),G=utilsSdk.bigToBN($,d),ne=utilsSdk.balanceToDisplayValue(G,d),ge=h===void 0?void 0:$.times(h).toNumber(),xa=ge?.toFixed(2),Ya=new vo__default.default(q).div(10**d),ke=utilsSdk.bigToBN(Ya,d),Qa=utilsSdk.balanceToDisplayValue(ke,d),M=h===void 0?void 0:Ya.times(h).toNumber(),De=M?.toFixed(2),va=t.networkToken.symbol;return {[j]:{[va]:{...t.networkToken,utxos:k,utxosUnconfirmed:U,coingeckoId:p??"",type:vmModuleTypes.TokenType.NATIVE,balance:G,balanceDisplayValue:ne,balanceInCurrency:ge,balanceCurrencyDisplayValue:xa,priceInCurrency:h,marketCap:f,vol24:v,change24:_,unconfirmedBalance:ke,unconfirmedBalanceDisplayValue:Qa,unconfirmedBalanceInCurrency:M,unconfirmedBalanceCurrencyDisplayValue:De}}}}))).reduce((j,N)=>N.status==="rejected"?j:{...j,...N.value},{})};var Ie,go=class{constructor({environment:e}){ba(this,Ie,void 0);let{proxyApiUrl:t}=Gn(e);ga(this,Ie,t);}getAddress(){return Promise.resolve("Bitcoin address")}getBalances({addresses:e,currency:t,network:n,storage:i}){return bo({addresses:e,currency:t,network:n,proxyApiUrl:ce(this,Ie),storage:i})}getManifest(){let e=vmModuleTypes.parseManifest(Jn);return e.success?e.data:void 0}getNetworkFee(e){return Kn({isTestnet:!!e.isTestnet,proxyApiUrl:ce(this,Ie)})}async getTransactionHistory({address:e,network:t}){return {transactions:await Xn({address:e,network:t,proxyApiUrl:ce(this,Ie)})}}getTokens(e){return Promise.resolve([])}async onRpcRequest(e,t){switch(e.method){default:return {error:rpcErrors.rpcErrors.methodNotSupported(`Method ${e.method} not supported`)}}}};Ie=new WeakMap;/*! Bundled license information:
|
|
44
44
|
|
|
45
45
|
mime-db/index.js:
|
|
46
46
|
(*!
|