@gardenfi/core 0.1.9 → 0.1.10
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/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/dist/src/lib/testUtils.d.ts +0 -26
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("ethers"),c=require("@gardenfi/orderbook"),h=require("@catalogfi/utils"),g=async(e,t,r,s)=>{const i=r[e],a=r[t];if(!a)throw new Error(`No ${e} wallet found`);if(!i)throw new Error(`No ${t} wallet found`);let d;if(w(e)){const o=u.sha256(h.with0x(Buffer.from("catalog.js"+s+await a.getAddress()).toString("hex"))).slice(2);d=await i.sign(o)}else{const o=u.sha256(h.with0x(Buffer.from("catalog.js"+s+await i.getAddress()).toString("hex"))).slice(2);d=await a.sign(o)}return h.trim0x(u.sha256(h.with0x(d)))},w=e=>e==="bitcoin"||e==="bitcoin_testnet"||e==="bitcoin_regtest",m={WALLET_NOT_FOUND:e=>`${e?"from":"to"} asset wallet not found; please pass the wallet associated with the chain of the asset swapping`,CHAIN_WALLET_NOT_FOUND:e=>`no ${e} wallet found`},p={NO_ACTION:"no actions can be performed in this state",NO_SECRET:"secret not found in order",INVALID_ACTION:(e,t)=>`can not ${e} on status: ${t}`};class _{constructor(t,r){this.order=t,this.wallets=r}get action(){return c.parseStatus(this.order)}get status(){return+`${this.order.status}${this.order.initiatorAtomicSwap.swapStatus}${this.order.followerAtomicSwap.swapStatus}`}async next(){switch(v[this.action]){case"Initiate":return await this.init();case"Redeem":return await this.redeem();case"Refund":return await this.refund();default:return L}}async init(){switch(this.action){case c.Actions.UserCanInitiate:{const t=this.wallets[this.order.initiatorAtomicSwap.chain];if(!t)throw new Error(`No ${this.order.initiatorAtomicSwap.chain} wallet found`);return{user:"initiator",action:"Initiate",output:await(await l(t,this.order,"native",this.order.initiatorAtomicSwap.asset)).init()}}case c.Actions.CounterpartyCanInitiate:{const t=this.wallets[this.order.followerAtomicSwap.chain];if(!t)throw new Error(`No ${this.order.followerAtomicSwap.chain} wallet`);return{user:"redeemer",action:"Initiate",output:await(await l(t,this.order,"foreign",this.order.followerAtomicSwap.asset)).init()}}default:throw new Error(p.INVALID_ACTION("init",this.status))}}async redeem(){const t=this.getWallet(this.order.followerAtomicSwap.chain),r=this.getWallet(this.order.initiatorAtomicSwap.chain);switch(this.action){case c.Actions.UserCanRedeem:{const s=await l(t,this.order,"foreign",this.order.followerAtomicSwap.asset),i=await g(this.order.initiatorAtomicSwap.chain,this.order.followerAtomicSwap.chain,this.wallets,this.order.secretNonce);return{user:"initiator",action:"Redeem",output:await s.redeem(i,this.order.userBtcWalletAddress)}}case c.Actions.CounterpartyCanRedeem:{if(!this.order.secret)throw new Error("Secret not found in order");return{user:"redeemer",action:"Redeem",output:await(await l(r,this.order,"native",this.order.initiatorAtomicSwap.asset)).redeem(this.order.secret)}}default:throw new Error(p.INVALID_ACTION("redeem",this.status))}}async refund(){const t=this.getWallet(this.order.initiatorAtomicSwap.chain),r=this.getWallet(this.order.followerAtomicSwap.chain);if(this.order.initiatorAtomicSwap.swapStatus===3)return{user:"initiator",action:"Refund",output:await(await l(t,this.order,"native",this.order.initiatorAtomicSwap.asset)).refund(this.order.userBtcWalletAddress)};if(this.order.followerAtomicSwap.swapStatus===3)return{user:"redeemer",action:"Refund",output:await(await l(r,this.order,"foreign",this.order.followerAtomicSwap.asset)).refund(this.order.userBtcWalletAddress)};throw new Error(p.INVALID_ACTION("refund",this.status))}id(){throw new Error("Method not implemented.")}getWallet(t){const r=this.wallets[t];if(!r)throw new Error(`No ${t} wallet found`);return r}}const l=async(e,t,r,s)=>{const i=r==="native"?t.initiatorAtomicSwap:t.followerAtomicSwap;return e.newSwap({recipientAddress:i.redeemerAddress,refundAddress:i.initiatorAddress,initiatorAddress:i.initiatorAddress,chain:c.chainToId[i.chain],expiryBlocks:+i.timelock,secretHash:t.secretHash,amount:+i.amount,contractAddress:s})};var N=(e=>(e.INITIATOR="initiator",e.REDEEMER="redeemer",e))(N||{}),I=(e=>(e.Init="Initiate",e.Redeem="Redeem",e.Refund="Refund",e.None="None",e))(I||{});const v={[c.Actions.UserCanInitiate]:"Initiate",[c.Actions.CounterpartyCanInitiate]:"Initiate",[c.Actions.UserCanRedeem]:"Redeem",[c.Actions.CounterpartyCanRedeem]:"Redeem",[c.Actions.UserCanRefund]:"Refund",[c.Actions.CounterpartyCanRefund]:"Refund",[c.Actions.NoAction]:"None"},L={user:"initiator",action:"None",output:""};class U{constructor(t){if(t)this.extensionId=t.id;else if($())this.extensionId=S("chrome");else if(E())this.extensionId=S("window");else throw new Error("Catalog wallet extension not found")}send(t,r){return new Promise((s,i)=>{const a={url:"",favicon:""},d=window.location.href.split("://")[1].replace(/\/$/,"");a.url=d;let o=document.querySelector("link[rel='icon']");if(o||(o=document.querySelector("link[rel='shortcut icon']")),o||(o=document.querySelector("link[rel='apple-touch-icon']")),o||(o=document.querySelector("meta[property='og:image']")),o)a.favicon=o instanceof HTMLMetaElement?o.content:o.href;else{const n=new URL(window.location.href);a.favicon=`${n.protocol}//${n.hostname}/favicon.ico`}chrome.runtime.sendMessage(this.extensionId,{method:t,params:r,metadata:a},n=>chrome.runtime.lastError?i(chrome.runtime.lastError):typeof n=="object"&&n&&"error"in n?i(n.error):s(n))})}}const E=()=>{try{const e=window;return e&&e.catalog&&e.catalog.id}catch{return!1}},S=e=>{if(e==="chrome")return chrome.runtime.id;if(e==="window")return window.catalog.id;throw new Error("Invalid medium to get wallet id")},$=()=>{try{return chrome&&!!chrome.runtime&&!!chrome.runtime.id}catch{return!1}},O={createOrderAndSwap:"createOrderAndSwap"};class x{constructor(t,r){this.orderbook=t,this.wallets=r}subscribeOrders(t,r){this.orderbook.subscribeOrders(t,r)}unsubscribeOrders(){return this.orderbook.unsubscribeOrders()}async swap(t,r,s,i,a){if(E()){const T=await new U().send(O.createOrderAndSwap,{from:t,to:r,amt:s,receiveAmount:i,opts:a});return Number(T)}const d=this.wallets[t.chain],o=this.wallets[r.chain];if(!d)throw new Error(m.WALLET_NOT_FOUND(!0));if(!o)throw new Error(m.WALLET_NOT_FOUND(!1));D(t.chain,r.chain),(a&&!a.btcUserAddress||!a)&&(a=a||{},a.btcUserAddress=await this.wallets[w(t.chain)?t.chain:r.chain].getAddress());const n=w(t.chain),A=n?o:d,f=n?d:o,W=await A.getAddress(),b=await this.orderbook.getOrders(W),R=n?await f.getAddress():await A.getAddress(),C=n?await A.getAddress():await f.getAddress(),y=await g(t.chain,r.chain,this.wallets,b.length+1);return this.orderbook.createOrder({fromAsset:t,toAsset:r,sendAmount:s.toString(),receiveAmount:i.toString(),receiveAddress:C,sendAddress:R,secretHash:u.sha256(h.with0x(y)),btcInputAddress:a.btcUserAddress??await f.getAddress()})}getSwap(t){return new _(t,this.wallets)}calculateReceiveAmt(t,r,s){return Promise.resolve(s-s*.03)}}const D=(e,t)=>{if(w(e)===w(t))throw new Error(w(e)?m.CHAIN_WALLET_NOT_FOUND("Bitcoin"):m.CHAIN_WALLET_NOT_FOUND("EVM"))};exports.GardenJS=x;exports.SwapperActions=I;exports.SwapperRole=N;exports.catalogWalletActions=O;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{sha256 as l}from"ethers";import{Actions as c,parseStatus as L,chainToId as v}from"@gardenfi/orderbook";import{with0x as u,trim0x as U}from"@catalogfi/utils";const S=async(e,t,r,a)=>{const i=r[e],s=r[t];if(!s)throw new Error(`No ${e} wallet found`);if(!i)throw new Error(`No ${t} wallet found`);let d;if(w(e)){const o=l(u(Buffer.from("catalog.js"+a+await s.getAddress()).toString("hex"))).slice(2);d=await i.sign(o)}else{const o=l(u(Buffer.from("catalog.js"+a+await i.getAddress()).toString("hex"))).slice(2);d=await s.sign(o)}return U(l(u(d)))},w=e=>e==="bitcoin"||e==="bitcoin_testnet"||e==="bitcoin_regtest",m={WALLET_NOT_FOUND:e=>`${e?"from":"to"} wallet not found`,CHAIN_WALLET_NOT_FOUND:e=>`no ${e} wallet found`},p={NO_ACTION:"no actions can be performed in this state",NO_SECRET:"secret not found in order",INVALID_ACTION:(e,t)=>`can not ${e} on status: ${t}`};class W{constructor(t,r){this.order=t,this.wallets=r}get action(){return L(this.order)}get status(){return+`${this.order.status}${this.order.initiatorAtomicSwap.swapStatus}${this.order.followerAtomicSwap.swapStatus}`}async next(){switch($[this.action]){case"Initiate":return await this.init();case"Redeem":return await this.redeem();case"Refund":return await this.refund();default:return x}}async init(){switch(this.action){case c.UserCanInitiate:{const t=this.wallets[this.order.initiatorAtomicSwap.chain];if(!t)throw new Error(`No ${this.order.initiatorAtomicSwap.chain} wallet found`);return{user:"initiator",action:"Initiate",output:await(await h(t,this.order,"native",this.order.initiatorAtomicSwap.asset)).init()}}case c.CounterpartyCanInitiate:{const t=this.wallets[this.order.followerAtomicSwap.chain];if(!t)throw new Error(`No ${this.order.followerAtomicSwap.chain} wallet`);return{user:"redeemer",action:"Initiate",output:await(await h(t,this.order,"foreign",this.order.followerAtomicSwap.asset)).init()}}default:throw new Error(p.INVALID_ACTION("init",this.status))}}async redeem(){const t=this.getWallet(this.order.followerAtomicSwap.chain),r=this.getWallet(this.order.initiatorAtomicSwap.chain);switch(this.action){case c.UserCanRedeem:{const a=await h(t,this.order,"foreign",this.order.followerAtomicSwap.asset),i=await S(this.order.initiatorAtomicSwap.chain,this.order.followerAtomicSwap.chain,this.wallets,this.order.secretNonce);return{user:"initiator",action:"Redeem",output:await a.redeem(i,this.order.userBtcWalletAddress)}}case c.CounterpartyCanRedeem:{if(!this.order.secret)throw new Error("Secret not found in order");return{user:"redeemer",action:"Redeem",output:await(await h(r,this.order,"native",this.order.initiatorAtomicSwap.asset)).redeem(this.order.secret)}}default:throw new Error(p.INVALID_ACTION("redeem",this.status))}}async refund(){const t=this.getWallet(this.order.initiatorAtomicSwap.chain),r=this.getWallet(this.order.followerAtomicSwap.chain);if(this.order.initiatorAtomicSwap.swapStatus===3)return{user:"initiator",action:"Refund",output:await(await h(t,this.order,"native",this.order.initiatorAtomicSwap.asset)).refund(this.order.userBtcWalletAddress)};if(this.order.followerAtomicSwap.swapStatus===3)return{user:"redeemer",action:"Refund",output:await(await h(r,this.order,"foreign",this.order.followerAtomicSwap.asset)).refund(this.order.userBtcWalletAddress)};throw new Error(p.INVALID_ACTION("refund",this.status))}id(){throw new Error("Method not implemented.")}getWallet(t){const r=this.wallets[t];if(!r)throw new Error(`No ${t} wallet found`);return r}}const h=async(e,t,r,a)=>{const i=r==="native"?t.initiatorAtomicSwap:t.followerAtomicSwap;return e.newSwap({recipientAddress:i.redeemerAddress,refundAddress:i.initiatorAddress,initiatorAddress:i.initiatorAddress,chain:v[i.chain],expiryBlocks:+i.timelock,secretHash:t.secretHash,amount:+i.amount,contractAddress:a})};var g=(e=>(e.INITIATOR="initiator",e.REDEEMER="redeemer",e))(g||{}),N=(e=>(e.Init="Initiate",e.Redeem="Redeem",e.Refund="Refund",e.None="None",e))(N||{});const $={[c.UserCanInitiate]:"Initiate",[c.CounterpartyCanInitiate]:"Initiate",[c.UserCanRedeem]:"Redeem",[c.CounterpartyCanRedeem]:"Redeem",[c.UserCanRefund]:"Refund",[c.CounterpartyCanRefund]:"Refund",[c.NoAction]:"None"},x={user:"initiator",action:"None",output:""};class D{constructor(t){if(t)this.extensionId=t.id;else if(k())this.extensionId=E("chrome");else if(I())this.extensionId=E("window");else throw new Error("Catalog wallet extension not found")}send(t,r){return new Promise((a,i)=>{const s={url:"",favicon:""},d=window.location.href.split("://")[1].replace(/\/$/,"");s.url=d;let o=document.querySelector("link[rel='icon']");if(o||(o=document.querySelector("link[rel='shortcut icon']")),o||(o=document.querySelector("link[rel='apple-touch-icon']")),o||(o=document.querySelector("meta[property='og:image']")),o)s.favicon=o instanceof HTMLMetaElement?o.content:o.href;else{const n=new URL(window.location.href);s.favicon=`${n.protocol}//${n.hostname}/favicon.ico`}chrome.runtime.sendMessage(this.extensionId,{method:t,params:r,metadata:s},n=>chrome.runtime.lastError?i(chrome.runtime.lastError):typeof n=="object"&&n&&"error"in n?i(n.error):a(n))})}}const I=()=>{try{const e=window;return e&&e.catalog&&e.catalog.id}catch{return!1}},E=e=>{if(e==="chrome")return chrome.runtime.id;if(e==="window")return window.catalog.id;throw new Error("Invalid medium to get wallet id")},k=()=>{try{return chrome&&!!chrome.runtime&&!!chrome.runtime.id}catch{return!1}},O={createOrderAndSwap:"createOrderAndSwap"};class B{constructor(t,r){this.orderbook=t,this.wallets=r}subscribeOrders(t,r){this.orderbook.subscribeOrders(t,r)}unsubscribeOrders(){return this.orderbook.unsubscribeOrders()}async swap(t,r,a,i,s){if(I()){const y=await new D().send(O.createOrderAndSwap,{from:t,to:r,amt:a,receiveAmount:i,opts:s});return Number(y)}const d=this.wallets[t.chain],o=this.wallets[r.chain];if(!d)throw new Error(m.WALLET_NOT_FOUND(!0));if(!o)throw new Error(m.WALLET_NOT_FOUND(!1));H(t.chain,r.chain),(s&&!s.btcUserAddress||!s)&&(s=s||{},s.btcUserAddress=await this.wallets[w(t.chain)?t.chain:r.chain].getAddress());const n=w(t.chain),f=n?o:d,A=n?d:o,R=await f.getAddress(),C=await this.orderbook.getOrders(R),b=n?await A.getAddress():await f.getAddress(),_=n?await f.getAddress():await A.getAddress(),T=await S(t.chain,r.chain,this.wallets,C.length+1);return this.orderbook.createOrder({fromAsset:t,toAsset:r,sendAmount:a.toString(),receiveAmount:i.toString(),receiveAddress:_,sendAddress:b,secretHash:l(u(T)),btcInputAddress:s.btcUserAddress??await A.getAddress()})}getSwap(t){return new W(t,this.wallets)}calculateReceiveAmt(t,r,a){return Promise.resolve(a-a*.03)}}const H=(e,t)=>{if(w(e)===w(t))throw new Error(w(e)?m.CHAIN_WALLET_NOT_FOUND("Bitcoin"):m.CHAIN_WALLET_NOT_FOUND("EVM"))};export{B as GardenJS,N as SwapperActions,g as SwapperRole,O as catalogWalletActions};
|
|
1
|
+
import{sha256 as l}from"ethers";import{Actions as c,parseStatus as L,chainToId as v}from"@gardenfi/orderbook";import{with0x as u,trim0x as U}from"@catalogfi/utils";const S=async(e,t,r,a)=>{const i=r[e],s=r[t];if(!s)throw new Error(`No ${e} wallet found`);if(!i)throw new Error(`No ${t} wallet found`);let d;if(w(e)){const o=l(u(Buffer.from("catalog.js"+a+await s.getAddress()).toString("hex"))).slice(2);d=await i.sign(o)}else{const o=l(u(Buffer.from("catalog.js"+a+await i.getAddress()).toString("hex"))).slice(2);d=await s.sign(o)}return U(l(u(d)))},w=e=>e==="bitcoin"||e==="bitcoin_testnet"||e==="bitcoin_regtest",m={WALLET_NOT_FOUND:e=>`${e?"from":"to"} asset wallet not found; please pass the wallet associated with the chain of the asset swapping`,CHAIN_WALLET_NOT_FOUND:e=>`no ${e} wallet found`},p={NO_ACTION:"no actions can be performed in this state",NO_SECRET:"secret not found in order",INVALID_ACTION:(e,t)=>`can not ${e} on status: ${t}`};class W{constructor(t,r){this.order=t,this.wallets=r}get action(){return L(this.order)}get status(){return+`${this.order.status}${this.order.initiatorAtomicSwap.swapStatus}${this.order.followerAtomicSwap.swapStatus}`}async next(){switch($[this.action]){case"Initiate":return await this.init();case"Redeem":return await this.redeem();case"Refund":return await this.refund();default:return x}}async init(){switch(this.action){case c.UserCanInitiate:{const t=this.wallets[this.order.initiatorAtomicSwap.chain];if(!t)throw new Error(`No ${this.order.initiatorAtomicSwap.chain} wallet found`);return{user:"initiator",action:"Initiate",output:await(await h(t,this.order,"native",this.order.initiatorAtomicSwap.asset)).init()}}case c.CounterpartyCanInitiate:{const t=this.wallets[this.order.followerAtomicSwap.chain];if(!t)throw new Error(`No ${this.order.followerAtomicSwap.chain} wallet`);return{user:"redeemer",action:"Initiate",output:await(await h(t,this.order,"foreign",this.order.followerAtomicSwap.asset)).init()}}default:throw new Error(p.INVALID_ACTION("init",this.status))}}async redeem(){const t=this.getWallet(this.order.followerAtomicSwap.chain),r=this.getWallet(this.order.initiatorAtomicSwap.chain);switch(this.action){case c.UserCanRedeem:{const a=await h(t,this.order,"foreign",this.order.followerAtomicSwap.asset),i=await S(this.order.initiatorAtomicSwap.chain,this.order.followerAtomicSwap.chain,this.wallets,this.order.secretNonce);return{user:"initiator",action:"Redeem",output:await a.redeem(i,this.order.userBtcWalletAddress)}}case c.CounterpartyCanRedeem:{if(!this.order.secret)throw new Error("Secret not found in order");return{user:"redeemer",action:"Redeem",output:await(await h(r,this.order,"native",this.order.initiatorAtomicSwap.asset)).redeem(this.order.secret)}}default:throw new Error(p.INVALID_ACTION("redeem",this.status))}}async refund(){const t=this.getWallet(this.order.initiatorAtomicSwap.chain),r=this.getWallet(this.order.followerAtomicSwap.chain);if(this.order.initiatorAtomicSwap.swapStatus===3)return{user:"initiator",action:"Refund",output:await(await h(t,this.order,"native",this.order.initiatorAtomicSwap.asset)).refund(this.order.userBtcWalletAddress)};if(this.order.followerAtomicSwap.swapStatus===3)return{user:"redeemer",action:"Refund",output:await(await h(r,this.order,"foreign",this.order.followerAtomicSwap.asset)).refund(this.order.userBtcWalletAddress)};throw new Error(p.INVALID_ACTION("refund",this.status))}id(){throw new Error("Method not implemented.")}getWallet(t){const r=this.wallets[t];if(!r)throw new Error(`No ${t} wallet found`);return r}}const h=async(e,t,r,a)=>{const i=r==="native"?t.initiatorAtomicSwap:t.followerAtomicSwap;return e.newSwap({recipientAddress:i.redeemerAddress,refundAddress:i.initiatorAddress,initiatorAddress:i.initiatorAddress,chain:v[i.chain],expiryBlocks:+i.timelock,secretHash:t.secretHash,amount:+i.amount,contractAddress:a})};var g=(e=>(e.INITIATOR="initiator",e.REDEEMER="redeemer",e))(g||{}),N=(e=>(e.Init="Initiate",e.Redeem="Redeem",e.Refund="Refund",e.None="None",e))(N||{});const $={[c.UserCanInitiate]:"Initiate",[c.CounterpartyCanInitiate]:"Initiate",[c.UserCanRedeem]:"Redeem",[c.CounterpartyCanRedeem]:"Redeem",[c.UserCanRefund]:"Refund",[c.CounterpartyCanRefund]:"Refund",[c.NoAction]:"None"},x={user:"initiator",action:"None",output:""};class D{constructor(t){if(t)this.extensionId=t.id;else if(k())this.extensionId=E("chrome");else if(I())this.extensionId=E("window");else throw new Error("Catalog wallet extension not found")}send(t,r){return new Promise((a,i)=>{const s={url:"",favicon:""},d=window.location.href.split("://")[1].replace(/\/$/,"");s.url=d;let o=document.querySelector("link[rel='icon']");if(o||(o=document.querySelector("link[rel='shortcut icon']")),o||(o=document.querySelector("link[rel='apple-touch-icon']")),o||(o=document.querySelector("meta[property='og:image']")),o)s.favicon=o instanceof HTMLMetaElement?o.content:o.href;else{const n=new URL(window.location.href);s.favicon=`${n.protocol}//${n.hostname}/favicon.ico`}chrome.runtime.sendMessage(this.extensionId,{method:t,params:r,metadata:s},n=>chrome.runtime.lastError?i(chrome.runtime.lastError):typeof n=="object"&&n&&"error"in n?i(n.error):a(n))})}}const I=()=>{try{const e=window;return e&&e.catalog&&e.catalog.id}catch{return!1}},E=e=>{if(e==="chrome")return chrome.runtime.id;if(e==="window")return window.catalog.id;throw new Error("Invalid medium to get wallet id")},k=()=>{try{return chrome&&!!chrome.runtime&&!!chrome.runtime.id}catch{return!1}},O={createOrderAndSwap:"createOrderAndSwap"};class B{constructor(t,r){this.orderbook=t,this.wallets=r}subscribeOrders(t,r){this.orderbook.subscribeOrders(t,r)}unsubscribeOrders(){return this.orderbook.unsubscribeOrders()}async swap(t,r,a,i,s){if(I()){const y=await new D().send(O.createOrderAndSwap,{from:t,to:r,amt:a,receiveAmount:i,opts:s});return Number(y)}const d=this.wallets[t.chain],o=this.wallets[r.chain];if(!d)throw new Error(m.WALLET_NOT_FOUND(!0));if(!o)throw new Error(m.WALLET_NOT_FOUND(!1));H(t.chain,r.chain),(s&&!s.btcUserAddress||!s)&&(s=s||{},s.btcUserAddress=await this.wallets[w(t.chain)?t.chain:r.chain].getAddress());const n=w(t.chain),f=n?o:d,A=n?d:o,R=await f.getAddress(),C=await this.orderbook.getOrders(R),b=n?await A.getAddress():await f.getAddress(),_=n?await f.getAddress():await A.getAddress(),T=await S(t.chain,r.chain,this.wallets,C.length+1);return this.orderbook.createOrder({fromAsset:t,toAsset:r,sendAmount:a.toString(),receiveAmount:i.toString(),receiveAddress:_,sendAddress:b,secretHash:l(u(T)),btcInputAddress:s.btcUserAddress??await A.getAddress()})}getSwap(t){return new W(t,this.wallets)}calculateReceiveAmt(t,r,a){return Promise.resolve(a-a*.03)}}const H=(e,t)=>{if(w(e)===w(t))throw new Error(w(e)?m.CHAIN_WALLET_NOT_FOUND("Bitcoin"):m.CHAIN_WALLET_NOT_FOUND("EVM"))};export{B as GardenJS,N as SwapperActions,g as SwapperRole,O as catalogWalletActions};
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@catalogfi/utils": "^0.1.6",
|
|
7
7
|
"@catalogfi/wallets": "^0.2.43",
|
|
8
|
-
"@gardenfi/orderbook": "^0.1.
|
|
8
|
+
"@gardenfi/orderbook": "^0.1.7",
|
|
9
9
|
"ethers": "6.8.0"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Chain, Order } from '@gardenfi/orderbook';
|
|
2
|
-
import { Wallet, JsonRpcProvider } from 'ethers';
|
|
3
|
-
|
|
4
|
-
export declare const orderFactory: ({ secret, secretHash, userBtcWalletAddress, secretNonce, initiatorTimelock, followerTimelock, initiatorAmount, followerAmount, initiatorInitatorAddress, initiatorRedeemerAddress, followerInitiatorAddress, followerRedeemerAddress, initiatorChain, redeemerChain, initiatorAsset, followerAsset, }: {
|
|
5
|
-
secret: string;
|
|
6
|
-
secretHash: string;
|
|
7
|
-
secretNonce: number;
|
|
8
|
-
userBtcWalletAddress: string;
|
|
9
|
-
initiatorTimelock: string;
|
|
10
|
-
followerTimelock: string;
|
|
11
|
-
initiatorAmount: string;
|
|
12
|
-
followerAmount: string;
|
|
13
|
-
initiatorInitatorAddress: string;
|
|
14
|
-
initiatorRedeemerAddress: string;
|
|
15
|
-
followerInitiatorAddress: string;
|
|
16
|
-
followerRedeemerAddress: string;
|
|
17
|
-
initiatorChain: Chain;
|
|
18
|
-
redeemerChain: Chain;
|
|
19
|
-
initiatorAsset: string;
|
|
20
|
-
followerAsset: string;
|
|
21
|
-
}) => Order;
|
|
22
|
-
export declare const atomicSwapStatus: (secretHash: string, initiator: Wallet) => Promise<{
|
|
23
|
-
initiator: any;
|
|
24
|
-
fulfilled: any;
|
|
25
|
-
}>;
|
|
26
|
-
export declare const fundEvmAddress: (provider: JsonRpcProvider, address: string, amount?: string) => Promise<void>;
|