@omnity/ree-client-ts-sdk 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Ree Typescript SDK
1
+ # Ree Client TypesSript SDK
2
2
 
3
3
  A TypeScript SDK for interacting with the Ree protocol on Bitcoin, providing seamless integration with Bitcoin wallets and Rune tokens.
4
4
 
@@ -14,7 +14,7 @@ A TypeScript SDK for interacting with the Ree protocol on Bitcoin, providing sea
14
14
  ## Installation
15
15
 
16
16
  ```bash
17
- npm install @ree-network/ts-sdk
17
+ npm install @omnity/ree-client-ts-sdk
18
18
  ```
19
19
 
20
20
  ## Quick Start
@@ -22,7 +22,7 @@ npm install @ree-network/ts-sdk
22
22
  ### Initializing the Client
23
23
 
24
24
  ```typescript
25
- import { ReeClient, Network, type Config } from "@ree-network/ts-sdk";
25
+ import { ReeClient, Network, type Config } from "@omnity/ree-client-ts-sdk";
26
26
 
27
27
  const config: Config = {
28
28
  network: Network.Testnet,
package/dist/ree-sdk.js CHANGED
@@ -26246,18 +26246,20 @@ class A_ {
26246
26246
  * @returns Rune balance as a number, or undefined if rune not found
26247
26247
  */
26248
26248
  async getRuneBalance(t, n) {
26249
+ console.log("get rune balance");
26249
26250
  const [r, i] = await Promise.all([
26250
26251
  this.getRuneUtxos(t, n),
26251
26252
  this.getRuneInfo(n)
26252
26253
  ]);
26253
26254
  if (!r || !i)
26254
26255
  return;
26256
+ console.log(r);
26255
26257
  let s = BigInt(0);
26256
26258
  for (const o of r)
26257
26259
  s += BigInt(
26258
26260
  o.runes.find((c) => c.id === n)?.amount ?? 0
26259
26261
  );
26260
- return s > BigInt(0) ? new qi(s.toString()).div(Math.pow(i.divisibility, 10)).toNumber() : 0;
26262
+ return console.log("amount", s), s > BigInt(0) ? new qi(s.toString()).div(Math.pow(i.divisibility, 10)).toNumber() : 0;
26261
26263
  }
26262
26264
  /**
26263
26265
  * Get list of all available liquidity pools
@@ -143,4 +143,4 @@ ${String(e)}`)}catch(t){return t}},Dp=e=>{if(typeof e!="object"||e===null)throw
143
143
  divisibility
144
144
  }
145
145
  }
146
- `,i=new gE(n),s=t.split("").filter(c=>!(c==="•"||c===" ")).join("•?"),{runes:o}=await i.request(r,{keyword:t,regex:`(?i)${s}`});return o.map(({rune_id:c,spaced_rune:a,symbol:u,divisibility:l,etching:h})=>({runeId:c,spacedRune:a,symbol:u,divisibility:l,etching:h}))}async getRuneInfo(t){return(await this.searchRunes(t))[0]}async getBtcBalance(t){const r=(await this.getBtcUtxos(t)).reduce((i,s)=>i+BigInt(s.satoshis),BigInt(0));return new $i(r.toString()).div(1e8).toNumber()}async getRuneBalance(t,n){const[r,i]=await Promise.all([this.getRuneUtxos(t,n),this.getRuneInfo(n)]);if(!r||!i)return;let s=BigInt(0);for(const o of r)s+=BigInt(o.runes.find(c=>c.id===n)?.amount??0);return s>BigInt(0)?new $i(s.toString()).div(Math.pow(i.divisibility,10)).toNumber():0}async getPoolList(){try{return await this.exchange.get_pool_list()??[]}catch(t){throw console.error("get pool list failed:",t),t}}async getPoolInfo(t){try{const n=await this.exchange.get_pool_info({pool_address:t});if(n.length===0)throw new Error("Pool not found");return n[0]}catch(n){throw console.error("get pool data failed:",n),n}}async createTransaction({address:t,paymentAddress:n,runeId:r,poolAddress:i,sendBtcAmount:s,sendRuneAmount:o,receiveBtcAmount:c,receiveRuneAmount:a}){const[u,l,h]=await Promise.all([this.getBtcUtxos(n),r?this.getRuneUtxos(t,r):Promise.resolve([]),this.getPoolInfo(i)]),y=h.utxos.map(({txid:p,vout:m,coins:g,sats:E})=>{const x=Ku(i,this.config.network);return{txid:p,vout:m,address:i,runes:g.map(({id:_,value:w})=>({id:_,amount:w.toString()})),satoshis:E.toString(),scriptPk:ju(x)}});return new bp({network:this.config.network,exchangeId:this.config.exchangeId,address:t,paymentAddress:n,poolAddress:i,runeId:r,sendBtcAmount:s,sendRuneAmount:o,receiveBtcAmount:c,receiveRuneAmount:a,btcUtxos:u,runeUtxos:l,poolUtxos:y},this.orchestrator)}}const cy=ye.createContext(null);function p_({children:e,config:t}){if(!t)throw new Error("ReeProvider: config is required");if(!t.network)throw new Error("ReeProvider: config.network is required");if(!t.maestroApiKey)throw new Error("ReeProvider: config.maestroApiKey is required");if(!t.exchangeIdlFactory)throw new Error("ReeProvider: config.exchangeIdlFactory is required");if(!t.exchangeCanisterId)throw new Error("ReeProvider: config.exchangeCanisterId is required");const[n,r]=ye.useState({address:"",paymentAddress:"",publicKey:"",paymentPublicKey:""}),i=ye.useCallback(a=>{r(u=>({...u,...a}))},[]),s=ye.useMemo(()=>new oy(t),[t]),o=ye.useCallback(async a=>{if(!s)throw new Error("Client not available");if(!n.address||!n.paymentAddress)throw new Error("Wallet not connected");return s.createTransaction({...a,address:n.address,paymentAddress:n.paymentAddress})},[s,n]),c=ye.useMemo(()=>({client:s,...n,exchange:s.exchange,updateWallet:i,createTransaction:o}),[s,n,i,o]);return nt.jsx(cy.Provider,{value:c,children:e})}function Gn(){const e=ye.useContext(cy);if(!e)throw new Error("useRee must be used within ReeProvider");return e}function y_(e={}){const{refreshInterval:t=0,autoRefresh:n=!0}=e,{client:r,paymentAddress:i}=Gn(),[s,o]=ye.useState(null),[c,a]=ye.useState(!1),[u,l]=ye.useState(null),h=ye.useCallback(async()=>{if(!i){o(null),l("Payment address not set");return}a(!0),l(null);try{const y=await r.getBtcBalance(i);o(y)}catch(y){l(y instanceof Error?y.message:"Failed to fetch BTC balance"),o(null)}finally{a(!1)}},[r,i]);return ye.useEffect(()=>{n&&h()},[i,h,n]),ye.useEffect(()=>{if(t>0){const y=setInterval(h,t);return()=>clearInterval(y)}},[t,i,h]),{balance:s,loading:c,error:u,refetch:h}}function m_(e,t={}){const{refreshInterval:n=0,autoRefresh:r=!0}=t,{client:i,address:s}=Gn(),[o,c]=ye.useState(null),[a,u]=ye.useState(!1),[l,h]=ye.useState(null),y=ye.useCallback(async()=>{if(!s){c(null),h("Address not set");return}if(!e){c(null),h("Rune ID is required");return}u(!0),h(null);try{const p=await i.getRuneBalance(s,e);c(p??null)}catch(p){h(p instanceof Error?p.message:"Failed to fetch rune balance"),c(null)}finally{u(!1)}},[i,s,e]);return ye.useEffect(()=>{r&&e&&y()},[s,e,y,r]),ye.useEffect(()=>{if(n>0&&e){const p=setInterval(y,n);return()=>clearInterval(p)}},[n,s,e,y]),{balance:o,loading:a,error:l,refetch:y}}function g_(e={}){const{refreshInterval:t=0,autoRefresh:n=!0}=e,{client:r,paymentAddress:i}=Gn(),[s,o]=ye.useState([]),[c,a]=ye.useState(!1),[u,l]=ye.useState(null),h=ye.useCallback(async()=>{if(!i){o([]),l("Payment address not set");return}a(!0),l(null);try{const y=await r.getBtcUtxos(i);o(y)}catch(y){l(y instanceof Error?y.message:"Failed to fetch BTC UTXOs"),o([])}finally{a(!1)}},[r,i]);return ye.useEffect(()=>{n&&i&&h()},[i,h,n]),ye.useEffect(()=>{if(t>0&&i){const y=setInterval(h,t);return()=>clearInterval(y)}},[t,i,h]),{utxos:s,loading:c,error:u,refetch:h}}function w_(e,t={}){const{refreshInterval:n=0,autoRefresh:r=!0}=t,{client:i,address:s}=Gn(),[o,c]=ye.useState([]),[a,u]=ye.useState(!1),[l,h]=ye.useState(null),y=ye.useCallback(async()=>{if(!s){c([]),h("Address not set");return}if(!e){c([]),h("Rune ID is required");return}u(!0),h(null);try{const p=await i.getRuneUtxos(s,e);c(p)}catch(p){h(p instanceof Error?p.message:"Failed to fetch rune UTXOs"),c([])}finally{u(!1)}},[i,s,e]);return ye.useEffect(()=>{r&&s&&e&&y()},[s,e,y,r]),ye.useEffect(()=>{if(n>0&&s&&e){const p=setInterval(y,n);return()=>clearInterval(p)}},[n,s,e,y]),{utxos:o,loading:a,error:l,refetch:y}}function b_(){const{client:e}=Gn();return ye.useCallback(async n=>{const r=n;if(!r)throw new Error("Search keyword is required");return await e.searchRunes(r)},[e])}function E_(e){const{client:t}=Gn(),[n,r]=ye.useState(null),[i,s]=ye.useState(!1),[o,c]=ye.useState(null),a=ye.useCallback(async()=>{if(!e){r(null),c("Rune ID is required");return}s(!0),c(null);try{const u=await t.getRuneInfo(e);r(u||null)}catch(u){c(u instanceof Error?u.message:"Failed to fetch rune info"),r(null)}finally{s(!1)}},[t,e]);return{runeInfo:n,loading:i,error:o,refetch:a}}function __(){const{client:e}=Gn(),[t,n]=ye.useState([]),[r,i]=ye.useState(!1),[s,o]=ye.useState(null),c=ye.useCallback(async()=>{i(!0),o(null);try{const a=await e.getPoolList();n(a)}catch(a){o(a instanceof Error?a.message:"Failed to fetch pool list"),n([])}finally{i(!1)}},[e]);return ye.useEffect(()=>{c()},[c]),{pools:t,loading:r,error:s,refetch:c}}function S_(e){const{client:t}=Gn(),[n,r]=ye.useState(null),[i,s]=ye.useState(!1),[o,c]=ye.useState(null),a=ye.useCallback(async()=>{if(!e){r(null),c("Pool address is required");return}s(!0),c(null);try{const u=await t.getPoolInfo(e);r(u)}catch(u){c(u instanceof Error?u.message:"Failed to fetch pool info"),r(null)}finally{s(!1)}},[t,e]);return ye.useEffect(()=>{a()},[e]),{poolInfo:n,loading:i,error:o,refetch:a}}Ie.Network=hs,Ie.ReeClient=oy,Ie.ReeProvider=p_,Ie.Transaction=bp,Ie.useBtcBalance=y_,Ie.useBtcUtxos=g_,Ie.usePoolInfo=S_,Ie.usePoolList=__,Ie.useRee=Gn,Ie.useRuneBalance=m_,Ie.useRuneInfo=E_,Ie.useRuneUtxos=w_,Ie.useSearchRunes=b_,Ie.utils=l2,Object.defineProperty(Ie,Symbol.toStringTag,{value:"Module"})}));
146
+ `,i=new gE(n),s=t.split("").filter(c=>!(c==="•"||c===" ")).join("•?"),{runes:o}=await i.request(r,{keyword:t,regex:`(?i)${s}`});return o.map(({rune_id:c,spaced_rune:a,symbol:u,divisibility:l,etching:h})=>({runeId:c,spacedRune:a,symbol:u,divisibility:l,etching:h}))}async getRuneInfo(t){return(await this.searchRunes(t))[0]}async getBtcBalance(t){const r=(await this.getBtcUtxos(t)).reduce((i,s)=>i+BigInt(s.satoshis),BigInt(0));return new $i(r.toString()).div(1e8).toNumber()}async getRuneBalance(t,n){console.log("get rune balance");const[r,i]=await Promise.all([this.getRuneUtxos(t,n),this.getRuneInfo(n)]);if(!r||!i)return;console.log(r);let s=BigInt(0);for(const o of r)s+=BigInt(o.runes.find(c=>c.id===n)?.amount??0);return console.log("amount",s),s>BigInt(0)?new $i(s.toString()).div(Math.pow(i.divisibility,10)).toNumber():0}async getPoolList(){try{return await this.exchange.get_pool_list()??[]}catch(t){throw console.error("get pool list failed:",t),t}}async getPoolInfo(t){try{const n=await this.exchange.get_pool_info({pool_address:t});if(n.length===0)throw new Error("Pool not found");return n[0]}catch(n){throw console.error("get pool data failed:",n),n}}async createTransaction({address:t,paymentAddress:n,runeId:r,poolAddress:i,sendBtcAmount:s,sendRuneAmount:o,receiveBtcAmount:c,receiveRuneAmount:a}){const[u,l,h]=await Promise.all([this.getBtcUtxos(n),r?this.getRuneUtxos(t,r):Promise.resolve([]),this.getPoolInfo(i)]),y=h.utxos.map(({txid:p,vout:m,coins:g,sats:E})=>{const x=Ku(i,this.config.network);return{txid:p,vout:m,address:i,runes:g.map(({id:_,value:w})=>({id:_,amount:w.toString()})),satoshis:E.toString(),scriptPk:ju(x)}});return new bp({network:this.config.network,exchangeId:this.config.exchangeId,address:t,paymentAddress:n,poolAddress:i,runeId:r,sendBtcAmount:s,sendRuneAmount:o,receiveBtcAmount:c,receiveRuneAmount:a,btcUtxos:u,runeUtxos:l,poolUtxos:y},this.orchestrator)}}const cy=ye.createContext(null);function p_({children:e,config:t}){if(!t)throw new Error("ReeProvider: config is required");if(!t.network)throw new Error("ReeProvider: config.network is required");if(!t.maestroApiKey)throw new Error("ReeProvider: config.maestroApiKey is required");if(!t.exchangeIdlFactory)throw new Error("ReeProvider: config.exchangeIdlFactory is required");if(!t.exchangeCanisterId)throw new Error("ReeProvider: config.exchangeCanisterId is required");const[n,r]=ye.useState({address:"",paymentAddress:"",publicKey:"",paymentPublicKey:""}),i=ye.useCallback(a=>{r(u=>({...u,...a}))},[]),s=ye.useMemo(()=>new oy(t),[t]),o=ye.useCallback(async a=>{if(!s)throw new Error("Client not available");if(!n.address||!n.paymentAddress)throw new Error("Wallet not connected");return s.createTransaction({...a,address:n.address,paymentAddress:n.paymentAddress})},[s,n]),c=ye.useMemo(()=>({client:s,...n,exchange:s.exchange,updateWallet:i,createTransaction:o}),[s,n,i,o]);return nt.jsx(cy.Provider,{value:c,children:e})}function Gn(){const e=ye.useContext(cy);if(!e)throw new Error("useRee must be used within ReeProvider");return e}function y_(e={}){const{refreshInterval:t=0,autoRefresh:n=!0}=e,{client:r,paymentAddress:i}=Gn(),[s,o]=ye.useState(null),[c,a]=ye.useState(!1),[u,l]=ye.useState(null),h=ye.useCallback(async()=>{if(!i){o(null),l("Payment address not set");return}a(!0),l(null);try{const y=await r.getBtcBalance(i);o(y)}catch(y){l(y instanceof Error?y.message:"Failed to fetch BTC balance"),o(null)}finally{a(!1)}},[r,i]);return ye.useEffect(()=>{n&&h()},[i,h,n]),ye.useEffect(()=>{if(t>0){const y=setInterval(h,t);return()=>clearInterval(y)}},[t,i,h]),{balance:s,loading:c,error:u,refetch:h}}function m_(e,t={}){const{refreshInterval:n=0,autoRefresh:r=!0}=t,{client:i,address:s}=Gn(),[o,c]=ye.useState(null),[a,u]=ye.useState(!1),[l,h]=ye.useState(null),y=ye.useCallback(async()=>{if(!s){c(null),h("Address not set");return}if(!e){c(null),h("Rune ID is required");return}u(!0),h(null);try{const p=await i.getRuneBalance(s,e);c(p??null)}catch(p){h(p instanceof Error?p.message:"Failed to fetch rune balance"),c(null)}finally{u(!1)}},[i,s,e]);return ye.useEffect(()=>{r&&e&&y()},[s,e,y,r]),ye.useEffect(()=>{if(n>0&&e){const p=setInterval(y,n);return()=>clearInterval(p)}},[n,s,e,y]),{balance:o,loading:a,error:l,refetch:y}}function g_(e={}){const{refreshInterval:t=0,autoRefresh:n=!0}=e,{client:r,paymentAddress:i}=Gn(),[s,o]=ye.useState([]),[c,a]=ye.useState(!1),[u,l]=ye.useState(null),h=ye.useCallback(async()=>{if(!i){o([]),l("Payment address not set");return}a(!0),l(null);try{const y=await r.getBtcUtxos(i);o(y)}catch(y){l(y instanceof Error?y.message:"Failed to fetch BTC UTXOs"),o([])}finally{a(!1)}},[r,i]);return ye.useEffect(()=>{n&&i&&h()},[i,h,n]),ye.useEffect(()=>{if(t>0&&i){const y=setInterval(h,t);return()=>clearInterval(y)}},[t,i,h]),{utxos:s,loading:c,error:u,refetch:h}}function w_(e,t={}){const{refreshInterval:n=0,autoRefresh:r=!0}=t,{client:i,address:s}=Gn(),[o,c]=ye.useState([]),[a,u]=ye.useState(!1),[l,h]=ye.useState(null),y=ye.useCallback(async()=>{if(!s){c([]),h("Address not set");return}if(!e){c([]),h("Rune ID is required");return}u(!0),h(null);try{const p=await i.getRuneUtxos(s,e);c(p)}catch(p){h(p instanceof Error?p.message:"Failed to fetch rune UTXOs"),c([])}finally{u(!1)}},[i,s,e]);return ye.useEffect(()=>{r&&s&&e&&y()},[s,e,y,r]),ye.useEffect(()=>{if(n>0&&s&&e){const p=setInterval(y,n);return()=>clearInterval(p)}},[n,s,e,y]),{utxos:o,loading:a,error:l,refetch:y}}function b_(){const{client:e}=Gn();return ye.useCallback(async n=>{const r=n;if(!r)throw new Error("Search keyword is required");return await e.searchRunes(r)},[e])}function E_(e){const{client:t}=Gn(),[n,r]=ye.useState(null),[i,s]=ye.useState(!1),[o,c]=ye.useState(null),a=ye.useCallback(async()=>{if(!e){r(null),c("Rune ID is required");return}s(!0),c(null);try{const u=await t.getRuneInfo(e);r(u||null)}catch(u){c(u instanceof Error?u.message:"Failed to fetch rune info"),r(null)}finally{s(!1)}},[t,e]);return{runeInfo:n,loading:i,error:o,refetch:a}}function __(){const{client:e}=Gn(),[t,n]=ye.useState([]),[r,i]=ye.useState(!1),[s,o]=ye.useState(null),c=ye.useCallback(async()=>{i(!0),o(null);try{const a=await e.getPoolList();n(a)}catch(a){o(a instanceof Error?a.message:"Failed to fetch pool list"),n([])}finally{i(!1)}},[e]);return ye.useEffect(()=>{c()},[c]),{pools:t,loading:r,error:s,refetch:c}}function S_(e){const{client:t}=Gn(),[n,r]=ye.useState(null),[i,s]=ye.useState(!1),[o,c]=ye.useState(null),a=ye.useCallback(async()=>{if(!e){r(null),c("Pool address is required");return}s(!0),c(null);try{const u=await t.getPoolInfo(e);r(u)}catch(u){c(u instanceof Error?u.message:"Failed to fetch pool info"),r(null)}finally{s(!1)}},[t,e]);return ye.useEffect(()=>{a()},[e]),{poolInfo:n,loading:i,error:o,refetch:a}}Ie.Network=hs,Ie.ReeClient=oy,Ie.ReeProvider=p_,Ie.Transaction=bp,Ie.useBtcBalance=y_,Ie.useBtcUtxos=g_,Ie.usePoolInfo=S_,Ie.usePoolList=__,Ie.useRee=Gn,Ie.useRuneBalance=m_,Ie.useRuneInfo=E_,Ie.useRuneUtxos=w_,Ie.useSearchRunes=b_,Ie.utils=l2,Object.defineProperty(Ie,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnity/ree-client-ts-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "A TypeScript SDK for interacting with the Ree protocol on Bitcoin",
5
5
  "keywords": [
6
6
  "bitcoin",