@omnity/ree-client-ts-sdk 0.1.2 → 0.1.3
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 +4 -6
- package/dist/ree-sdk.js +1 -3
- package/dist/ree-sdk.umd.cjs +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -266,7 +266,7 @@ function TradingDashboard() {
|
|
|
266
266
|
const { poolInfo } = usePoolInfo("bc1q...");
|
|
267
267
|
|
|
268
268
|
const handleSearch = () => {
|
|
269
|
-
searchRunes("
|
|
269
|
+
searchRunes("IRCH").then(setRunes); // Search for runes containing "RICH"
|
|
270
270
|
};
|
|
271
271
|
|
|
272
272
|
return (
|
|
@@ -308,8 +308,6 @@ function TradingDashboard() {
|
|
|
308
308
|
#### Hook Usage Examples
|
|
309
309
|
|
|
310
310
|
```tsx
|
|
311
|
-
// Search runes with auto-search
|
|
312
|
-
const { runes, loading, search } = useSearchRunes("DOG", { autoRefresh: true });
|
|
313
311
|
|
|
314
312
|
// Get rune info with polling
|
|
315
313
|
const { runeInfo } = useRuneInfo("840000:3", { refreshInterval: 30000 });
|
|
@@ -317,9 +315,9 @@ const { runeInfo } = useRuneInfo("840000:3", { refreshInterval: 30000 });
|
|
|
317
315
|
// Get pools with manual refresh only
|
|
318
316
|
const { pools, refetch } = usePoolList({ autoRefresh: false });
|
|
319
317
|
|
|
320
|
-
// Search
|
|
321
|
-
const
|
|
322
|
-
await
|
|
318
|
+
// Search runes
|
|
319
|
+
const searchRuens = useSearchRunes();
|
|
320
|
+
await searchRunes("RICH");
|
|
323
321
|
```
|
|
324
322
|
|
|
325
323
|
### Core useRee Hook
|
package/dist/ree-sdk.js
CHANGED
|
@@ -26246,20 +26246,18 @@ 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");
|
|
26250
26249
|
const [r, i] = await Promise.all([
|
|
26251
26250
|
this.getRuneUtxos(t, n),
|
|
26252
26251
|
this.getRuneInfo(n)
|
|
26253
26252
|
]);
|
|
26254
26253
|
if (!r || !i)
|
|
26255
26254
|
return;
|
|
26256
|
-
console.log(r);
|
|
26257
26255
|
let s = BigInt(0);
|
|
26258
26256
|
for (const o of r)
|
|
26259
26257
|
s += BigInt(
|
|
26260
26258
|
o.runes.find((c) => c.id === n)?.amount ?? 0
|
|
26261
26259
|
);
|
|
26262
|
-
return
|
|
26260
|
+
return s > BigInt(0) ? new qi(s.toString()).div(Math.pow(10, i.divisibility)).toNumber() : 0;
|
|
26263
26261
|
}
|
|
26264
26262
|
/**
|
|
26265
26263
|
* Get list of all available liquidity pools
|
package/dist/ree-sdk.umd.cjs
CHANGED
|
@@ -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){
|
|
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(10,i.divisibility)).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.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "A TypeScript SDK for interacting with the Ree protocol on Bitcoin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bitcoin",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"types": "./dist/index.d.ts",
|
|
32
32
|
"exports": {
|
|
33
33
|
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
34
35
|
"import": "./dist/ree-sdk.js",
|
|
35
36
|
"require": "./dist/ree-sdk.umd.cjs"
|
|
36
37
|
}
|