@gardenfi/orderbook 2.5.3 → 3.0.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/dist/index.cjs +1 -1
- package/dist/index.js +56 -28
- package/dist/index10.cjs +1 -0
- package/dist/index10.js +188 -0
- package/dist/index11.cjs +1 -0
- package/dist/index11.js +219 -0
- package/dist/index12.cjs +1 -0
- package/dist/index12.js +31 -0
- package/dist/index2.cjs +1 -1
- package/dist/index2.js +78 -101
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +2 -57
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +925 -392
- package/dist/index5.cjs +1 -1
- package/dist/index5.js +91 -6
- package/dist/index6.cjs +1 -0
- package/dist/index6.js +18 -0
- package/dist/index7.cjs +1 -0
- package/dist/index7.js +46 -0
- package/dist/index8.cjs +1 -0
- package/dist/index8.js +28 -0
- package/dist/index9.cjs +1 -0
- package/dist/index9.js +31 -0
- package/dist/src/index.d.ts +13 -2
- package/dist/src/lib/api.d.ts +1 -1
- package/dist/src/lib/asset.d.ts +0 -81
- package/dist/src/lib/assetManager/AssetManager.d.ts +82 -0
- package/dist/src/lib/assetManager/index.d.ts +2 -0
- package/dist/src/lib/assetManager/routeValidator/routeValidator.d.ts +76 -0
- package/dist/src/lib/assetManager/types.d.ts +39 -0
- package/dist/src/lib/assetManager/utils.d.ts +9 -0
- package/dist/src/lib/chainAsset/chainAsset.d.ts +19 -0
- package/dist/src/lib/constants/asset.d.ts +2028 -0
- package/dist/src/lib/constants/asset.types.d.ts +43 -0
- package/dist/src/lib/constants/localnetConstants.d.ts +47 -0
- package/dist/src/lib/constants/utils.d.ts +15 -0
- package/dist/src/lib/orderStatus/orderStatus.d.ts +14 -0
- package/dist/src/lib/orderStatus/status.d.ts +0 -0
- package/dist/src/lib/orderbook/orderbook.d.ts +15 -22
- package/dist/src/lib/orderbook/orderbook.types.d.ts +150 -214
- package/dist/src/lib/utils.d.ts +37 -0
- package/package.json +3 -2
- package/dist/src/lib/constants.d.ts +0 -374
package/dist/index5.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 e={id:1001,name:"Starknet Localnet",nativeCurrency:{name:"Stark Token",symbol:"STRK",decimals:18},rpcUrls:{default:{http:["http://127.0.0.1:8547/"]}},testnet:!0},t={id:31338,name:"Arbitrum Localnet",nativeCurrency:{name:"Ethereum",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["http://localhost:8546/"]}},testnet:!0},a={id:31337,name:"Ethereum Localnet",nativeCurrency:{name:"Ethereum",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["http://localhost:8545/"]}},testnet:!0},s={name:"SOL Solana Localnet",decimals:9,symbol:"SOL",atomicSwapAddress:"primary",tokenAddress:"primary"},n={name:"Bitcoin Regtest",decimals:8,symbol:"BTC",atomicSwapAddress:"primary",tokenAddress:"primary"},c={name:"WBTC Arbitrum Localnet",decimals:8,symbol:"WBTC",atomicSwapAddress:"0x0165878A594ca255338adfa4d48449f69242Eb8F",tokenAddress:"0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512"},o={name:"WBTC Ethereum Localnet",decimals:8,symbol:"WBTC",atomicSwapAddress:"0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",tokenAddress:"0x5FbDB2315678afecb367f032d93F642f64180aa3"},r={name:"STRK Starknet Localnet",decimals:18,symbol:"STRK",atomicSwapAddress:"0x15cf8b127aa850c97ed10de6f8b300cabc4f09232a57e63667af02fdef8a55a",tokenAddress:"0x51aa025f1c9948790113e4ebea826dee24542bc50902076c05892774210e8d2"},l={name:"ETH Starknet Localnet",decimals:18,symbol:"ETH",atomicSwapAddress:"0x1890470168440bbb9df50988748924a74ea22de10d22a081e458737b9574e75",tokenAddress:"0x51aa025f1c9948790113e4ebea826dee24542bc50902076c05892774210e8d2"};exports.ArbitrumLocalnet=t;exports.ETHStarknetLocalnetAsset=l;exports.EthereumLocalnet=a;exports.SOLSolanaLocalnetAsset=s;exports.STRKStarknetLocalnetAsset=r;exports.StarknetLocalnet=e;exports.WBTCArbitrumLocalnetAsset=c;exports.WBTCEthereumLocalnetAsset=o;exports.bitcoinRegtestAsset=n;
|
package/dist/index5.js
CHANGED
|
@@ -1,9 +1,94 @@
|
|
|
1
|
-
const e =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
const e = {
|
|
2
|
+
id: 1001,
|
|
3
|
+
name: "Starknet Localnet",
|
|
4
|
+
nativeCurrency: {
|
|
5
|
+
name: "Stark Token",
|
|
6
|
+
symbol: "STRK",
|
|
7
|
+
decimals: 18
|
|
8
|
+
},
|
|
9
|
+
rpcUrls: {
|
|
10
|
+
default: {
|
|
11
|
+
http: ["http://127.0.0.1:8547/"]
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
testnet: !0
|
|
15
|
+
}, t = {
|
|
16
|
+
id: 31338,
|
|
17
|
+
name: "Arbitrum Localnet",
|
|
18
|
+
nativeCurrency: {
|
|
19
|
+
name: "Ethereum",
|
|
20
|
+
symbol: "ETH",
|
|
21
|
+
decimals: 18
|
|
22
|
+
},
|
|
23
|
+
rpcUrls: {
|
|
24
|
+
default: {
|
|
25
|
+
http: ["http://localhost:8546/"]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
testnet: !0
|
|
29
|
+
}, a = {
|
|
30
|
+
id: 31337,
|
|
31
|
+
name: "Ethereum Localnet",
|
|
32
|
+
nativeCurrency: {
|
|
33
|
+
name: "Ethereum",
|
|
34
|
+
symbol: "ETH",
|
|
35
|
+
decimals: 18
|
|
36
|
+
},
|
|
37
|
+
rpcUrls: {
|
|
38
|
+
default: {
|
|
39
|
+
http: ["http://localhost:8545/"]
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
testnet: !0
|
|
43
|
+
}, s = {
|
|
44
|
+
name: "SOL Solana Localnet",
|
|
45
|
+
decimals: 9,
|
|
46
|
+
symbol: "SOL",
|
|
47
|
+
atomicSwapAddress: "primary",
|
|
48
|
+
tokenAddress: "primary"
|
|
49
|
+
}, c = {
|
|
50
|
+
name: "Bitcoin Regtest",
|
|
51
|
+
decimals: 8,
|
|
52
|
+
symbol: "BTC",
|
|
53
|
+
atomicSwapAddress: "primary",
|
|
54
|
+
tokenAddress: "primary"
|
|
55
|
+
}, n = {
|
|
56
|
+
name: "WBTC Arbitrum Localnet",
|
|
57
|
+
decimals: 8,
|
|
58
|
+
symbol: "WBTC",
|
|
59
|
+
// atomicSwapAddress: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9',
|
|
60
|
+
atomicSwapAddress: "0x0165878A594ca255338adfa4d48449f69242Eb8F",
|
|
61
|
+
//present on localnet
|
|
62
|
+
tokenAddress: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512"
|
|
63
|
+
}, r = {
|
|
64
|
+
name: "WBTC Ethereum Localnet",
|
|
65
|
+
decimals: 8,
|
|
66
|
+
symbol: "WBTC",
|
|
67
|
+
// atomicSwapAddress: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512',
|
|
68
|
+
atomicSwapAddress: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
|
|
69
|
+
//present on localnet
|
|
70
|
+
tokenAddress: "0x5FbDB2315678afecb367f032d93F642f64180aa3"
|
|
71
|
+
}, o = {
|
|
72
|
+
name: "STRK Starknet Localnet",
|
|
73
|
+
decimals: 18,
|
|
74
|
+
symbol: "STRK",
|
|
75
|
+
atomicSwapAddress: "0x15cf8b127aa850c97ed10de6f8b300cabc4f09232a57e63667af02fdef8a55a",
|
|
76
|
+
tokenAddress: "0x51aa025f1c9948790113e4ebea826dee24542bc50902076c05892774210e8d2"
|
|
77
|
+
}, d = {
|
|
78
|
+
name: "ETH Starknet Localnet",
|
|
79
|
+
decimals: 18,
|
|
80
|
+
symbol: "ETH",
|
|
81
|
+
atomicSwapAddress: "0x1890470168440bbb9df50988748924a74ea22de10d22a081e458737b9574e75",
|
|
82
|
+
tokenAddress: "0x51aa025f1c9948790113e4ebea826dee24542bc50902076c05892774210e8d2"
|
|
6
83
|
};
|
|
7
84
|
export {
|
|
8
|
-
|
|
85
|
+
t as ArbitrumLocalnet,
|
|
86
|
+
d as ETHStarknetLocalnetAsset,
|
|
87
|
+
a as EthereumLocalnet,
|
|
88
|
+
s as SOLSolanaLocalnetAsset,
|
|
89
|
+
o as STRKStarknetLocalnetAsset,
|
|
90
|
+
e as StarknetLocalnet,
|
|
91
|
+
n as WBTCArbitrumLocalnetAsset,
|
|
92
|
+
r as WBTCEthereumLocalnetAsset,
|
|
93
|
+
c as bitcoinRegtestAsset
|
|
9
94
|
};
|
package/dist/index6.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function u(n){const e={};for(const t of Object.keys(n)){const i=n[t],{network:a,type:b,...o}=i,s={};for(const c of Object.keys(o)){const r=o[c];s[c]={...r,chain:t}}e[t]=s}return e}exports.buildAssetsWithChain=u;
|
package/dist/index6.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function h(n) {
|
|
2
|
+
const o = {};
|
|
3
|
+
for (const t of Object.keys(n)) {
|
|
4
|
+
const i = n[t], { network: r, type: a, ...e } = i, s = {};
|
|
5
|
+
for (const c of Object.keys(e)) {
|
|
6
|
+
const k = e[c];
|
|
7
|
+
s[c] = {
|
|
8
|
+
...k,
|
|
9
|
+
chain: t
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
o[t] = s;
|
|
13
|
+
}
|
|
14
|
+
return o;
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
h as buildAssetsWithChain
|
|
18
|
+
};
|
package/dist/index7.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@gardenfi/utils"),i=require("./index3.cjs"),p=(t,r,d)=>{const a=t.endpoint(r);return d&&Object.entries(d).forEach(([l,n])=>{n!==void 0&&(Array.isArray(n)?a.searchParams.append(l,n.join(",")):a.searchParams.append(l,n.toString()))}),a},c=t=>e.hasKeys(t,["typed_data","initiate_transaction"])&&typeof t.initiate_transaction=="object"&&t.initiate_transaction&&e.hasKeys(t.initiate_transaction,["to","value","data","gas_limit","chain_id"]),s=t=>e.hasKeys(t,["typed_data","initiate_transaction"])&&typeof t.initiate_transaction=="object"&&t.initiate_transaction&&e.hasKeys(t.initiate_transaction,["to","selector","calldata"]),o=t=>e.hasKeys(t,["to","amount"])&&typeof t.to=="string"&&typeof t.amount=="string",y=t=>e.hasKeys(t,["versioned_tx"])&&typeof t.versioned_tx=="string",u=t=>e.hasKeys(t,["ptb_bytes"])&&Array.isArray(t.ptb_bytes)&&t.ptb_bytes.every(r=>typeof r=="number"),f=t=>e.hasKeys(t,["source_swap","destination_swap"])&&typeof t.source_swap=="object"&&typeof t.destination_swap=="object";function h(t){return c(t)?{type:i.BlockchainType.evm,...t}:s(t)?{type:i.BlockchainType.starknet,...t}:o(t)?{type:i.BlockchainType.bitcoin,...t}:y(t)?{type:i.BlockchainType.solana,...t}:u(t)?{type:i.BlockchainType.sui,...t}:null}function _(t){return c(t)?i.BlockchainType.evm:s(t)?i.BlockchainType.starknet:o(t)?i.BlockchainType.bitcoin:y(t)?i.BlockchainType.solana:u(t)?i.BlockchainType.sui:null}exports.ConstructUrl=p;exports.discriminateOrderResponse=h;exports.getOrderResponseType=_;exports.isBitcoinOrderResponse=o;exports.isEvmOrderResponse=c;exports.isOrder=f;exports.isSolanaOrderResponse=y;exports.isStarknetOrderResponse=s;exports.isSuiOrderResponse=u;
|
package/dist/index7.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { hasKeys as r } from "@gardenfi/utils";
|
|
2
|
+
import { BlockchainType as i } from "./index3.js";
|
|
3
|
+
const l = (t, a, o) => {
|
|
4
|
+
const e = t.endpoint(a);
|
|
5
|
+
return o && Object.entries(o).forEach(([c, n]) => {
|
|
6
|
+
n !== void 0 && (Array.isArray(n) ? e.searchParams.append(c, n.join(",")) : e.searchParams.append(c, n.toString()));
|
|
7
|
+
}), e;
|
|
8
|
+
}, u = (t) => r(t, ["typed_data", "initiate_transaction"]) && typeof t.initiate_transaction == "object" && t.initiate_transaction && r(t.initiate_transaction, [
|
|
9
|
+
"to",
|
|
10
|
+
"value",
|
|
11
|
+
"data",
|
|
12
|
+
"gas_limit",
|
|
13
|
+
"chain_id"
|
|
14
|
+
]), f = (t) => r(t, ["typed_data", "initiate_transaction"]) && typeof t.initiate_transaction == "object" && t.initiate_transaction && r(t.initiate_transaction, ["to", "selector", "calldata"]), y = (t) => r(t, ["to", "amount"]) && typeof t.to == "string" && typeof t.amount == "string", d = (t) => r(t, ["versioned_tx"]) && typeof t.versioned_tx == "string", _ = (t) => r(t, ["ptb_bytes"]) && Array.isArray(t.ptb_bytes) && t.ptb_bytes.every((a) => typeof a == "number"), m = (t) => r(t, ["source_swap", "destination_swap"]) && typeof t.source_swap == "object" && typeof t.destination_swap == "object";
|
|
15
|
+
function p(t) {
|
|
16
|
+
return u(t) ? {
|
|
17
|
+
type: i.evm,
|
|
18
|
+
...t
|
|
19
|
+
} : f(t) ? {
|
|
20
|
+
type: i.starknet,
|
|
21
|
+
...t
|
|
22
|
+
} : y(t) ? {
|
|
23
|
+
type: i.bitcoin,
|
|
24
|
+
...t
|
|
25
|
+
} : d(t) ? {
|
|
26
|
+
type: i.solana,
|
|
27
|
+
...t
|
|
28
|
+
} : _(t) ? {
|
|
29
|
+
type: i.sui,
|
|
30
|
+
...t
|
|
31
|
+
} : null;
|
|
32
|
+
}
|
|
33
|
+
function O(t) {
|
|
34
|
+
return u(t) ? i.evm : f(t) ? i.starknet : y(t) ? i.bitcoin : d(t) ? i.solana : _(t) ? i.sui : null;
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
l as ConstructUrl,
|
|
38
|
+
p as discriminateOrderResponse,
|
|
39
|
+
O as getOrderResponseType,
|
|
40
|
+
y as isBitcoinOrderResponse,
|
|
41
|
+
u as isEvmOrderResponse,
|
|
42
|
+
m as isOrder,
|
|
43
|
+
d as isSolanaOrderResponse,
|
|
44
|
+
f as isStarknetOrderResponse,
|
|
45
|
+
_ as isSuiOrderResponse
|
|
46
|
+
};
|
package/dist/index8.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index4.cjs");class o{constructor(t,r){this.chain=t,this.symbol=r,this.blockchainType=e.getBlockchainType(t),this.formatted=`${t.toLowerCase()}:${r.toLowerCase()}`,this.network=e.Config[t].network,this.asset=e.Assets[t][r]}static from(t){return t instanceof o?t:typeof t=="string"?o.fromString(t):o.fromAsset(t)}static fromChainAndSymbol(t,r){return new o(t,r)}static fromString(t){const[r,n]=t.split(":");if(!(r in e.Chains))throw new Error(`Invalid chain in asset string: ${r}`);return new o(r,n)}static fromAsset(t){return new o(t.chain,t.symbol)}toString(){return this.formatted}}exports.ChainAsset=o;
|
package/dist/index8.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getBlockchainType as i, Config as e, Assets as f, Chains as s } from "./index4.js";
|
|
2
|
+
class o {
|
|
3
|
+
constructor(t, r) {
|
|
4
|
+
this.chain = t, this.symbol = r, this.blockchainType = i(t), this.formatted = `${t.toLowerCase()}:${r.toLowerCase()}`, this.network = e[t].network, this.asset = f[t][r];
|
|
5
|
+
}
|
|
6
|
+
/* ---------------- factories ---------------- */
|
|
7
|
+
static from(t) {
|
|
8
|
+
return t instanceof o ? t : typeof t == "string" ? o.fromString(t) : o.fromAsset(t);
|
|
9
|
+
}
|
|
10
|
+
static fromChainAndSymbol(t, r) {
|
|
11
|
+
return new o(t, r);
|
|
12
|
+
}
|
|
13
|
+
static fromString(t) {
|
|
14
|
+
const [r, n] = t.split(":");
|
|
15
|
+
if (!(r in s))
|
|
16
|
+
throw new Error(`Invalid chain in asset string: ${r}`);
|
|
17
|
+
return new o(r, n);
|
|
18
|
+
}
|
|
19
|
+
static fromAsset(t) {
|
|
20
|
+
return new o(t.chain, t.symbol);
|
|
21
|
+
}
|
|
22
|
+
toString() {
|
|
23
|
+
return this.formatted;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
o as ChainAsset
|
|
28
|
+
};
|
package/dist/index9.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index4.cjs"),u=t=>{const{created_at:n,source_swap:r,destination_swap:d}=t;if(d.redeem_tx_hash)return Number(d.redeem_block_number)||e.isBitcoin(d.chain)?e.OrderStatus.Redeemed:e.OrderStatus.RedeemDetected;if(e.isBitcoin(d.chain)&&r.redeem_tx_hash&&!d.redeem_tx_hash)return e.OrderStatus.Redeemed;if(r.refund_tx_hash)return Number(r.refund_block_number)?e.OrderStatus.Refunded:e.OrderStatus.RefundDetected;if(d.refund_tx_hash)return e.OrderStatus.AwaitingRefund;const a=e.isBitcoin(r.chain)?s(new Date(n),6):s(new Date(n),1);return d.initiate_tx_hash?e.OrderStatus.AwaitingRedeem:r.initiate_tx_hash?a?e.OrderStatus.AwaitingRefund:Number(r.initiate_block_number)?e.OrderStatus.Initiated:e.OrderStatus.InitiateDetected:a?e.OrderStatus.Expired:e.OrderStatus.Created},s=(t,n=1)=>{const r=new Date,d=new Date(t);return d.setHours(d.getHours()+n),r>d},_=t=>{const n=u(t);return n===e.OrderStatus.Redeemed||n===e.OrderStatus.Refunded||n===e.OrderStatus.Expired};var i=(t=>(t.Initiate="Initiate",t.PostRefundSACP="PostRefundSACP",t.Redeem="Redeem",t.Refund="Refund",t.Idle="Idle",t))(i||{});const o=t=>{const{source_swap:n,destination_swap:r}=t;return r.redeem_tx_hash&&Number(r.redeem_block_number)||n.refund_tx_hash&&Number(n.refund_block_number)?"Idle":!r.refund_tx_hash&&r.initiate_tx_hash?"Redeem":"Idle"};exports.OrderAction=i;exports.ParseOrderStatus=u;exports.isCompleted=_;exports.isDeadlinePassed=s;exports.parseAction=o;
|
package/dist/index9.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { OrderStatus as e, isBitcoin as d } from "./index4.js";
|
|
2
|
+
const s = (t) => {
|
|
3
|
+
const { created_at: r, source_swap: n, destination_swap: i } = t;
|
|
4
|
+
if (i.redeem_tx_hash)
|
|
5
|
+
return Number(i.redeem_block_number) ? e.Redeemed : d(i.chain) ? e.Redeemed : e.RedeemDetected;
|
|
6
|
+
if (d(i.chain) && n.redeem_tx_hash && !i.redeem_tx_hash)
|
|
7
|
+
return e.Redeemed;
|
|
8
|
+
if (n.refund_tx_hash)
|
|
9
|
+
return Number(n.refund_block_number) ? e.Refunded : e.RefundDetected;
|
|
10
|
+
if (i.refund_tx_hash) return e.AwaitingRefund;
|
|
11
|
+
const u = d(n.chain) ? a(new Date(r), 6) : a(new Date(r), 1);
|
|
12
|
+
return i.initiate_tx_hash ? e.AwaitingRedeem : n.initiate_tx_hash ? u ? e.AwaitingRefund : Number(n.initiate_block_number) ? e.Initiated : e.InitiateDetected : u ? e.Expired : e.Created;
|
|
13
|
+
}, a = (t, r = 1) => {
|
|
14
|
+
const n = /* @__PURE__ */ new Date(), i = new Date(t);
|
|
15
|
+
return i.setHours(i.getHours() + r), n > i;
|
|
16
|
+
}, m = (t) => {
|
|
17
|
+
const r = s(t);
|
|
18
|
+
return r === e.Redeemed || r === e.Refunded || r === e.Expired;
|
|
19
|
+
};
|
|
20
|
+
var _ = /* @__PURE__ */ ((t) => (t.Initiate = "Initiate", t.PostRefundSACP = "PostRefundSACP", t.Redeem = "Redeem", t.Refund = "Refund", t.Idle = "Idle", t))(_ || {});
|
|
21
|
+
const o = (t) => {
|
|
22
|
+
const { source_swap: r, destination_swap: n } = t;
|
|
23
|
+
return n.redeem_tx_hash && Number(n.redeem_block_number) || r.refund_tx_hash && Number(r.refund_block_number) ? "Idle" : !n.refund_tx_hash && n.initiate_tx_hash ? "Redeem" : "Idle";
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
_ as OrderAction,
|
|
27
|
+
s as ParseOrderStatus,
|
|
28
|
+
m as isCompleted,
|
|
29
|
+
a as isDeadlinePassed,
|
|
30
|
+
o as parseAction
|
|
31
|
+
};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
export { Orderbook } from './lib/orderbook/orderbook';
|
|
2
2
|
export type * from './lib/orderbook/orderbook.types';
|
|
3
|
-
export
|
|
4
|
-
export
|
|
3
|
+
export { BlockchainType } from './lib/constants/asset.types';
|
|
4
|
+
export type { Asset, BitcoinChains, Chain, ChainsByBlockchainType, ChainsByNetwork, EVMChains, LocalnetOnlyChains, MainnetOnlyChains, SolanaChains, SuiChains, StarknetChains, TestnetOnlyChains, } from './lib/constants/asset.types';
|
|
5
|
+
export * from './lib/constants/asset';
|
|
6
|
+
export * from './lib/constants/localnetConstants';
|
|
7
|
+
export * from './lib/constants/utils';
|
|
8
|
+
export { isSuiOrderResponse, ConstructUrl, discriminateOrderResponse, getOrderResponseType, isBitcoinOrderResponse, isEvmOrderResponse, isOrder, isSolanaOrderResponse, isStarknetOrderResponse, } from './lib/utils';
|
|
9
|
+
export { ChainAsset } from './lib/chainAsset/chainAsset';
|
|
10
|
+
export type { ChainAssetString, AssetLike } from './lib/chainAsset/chainAsset';
|
|
11
|
+
export { OrderAction, ParseOrderStatus, isCompleted, isDeadlinePassed, parseAction, } from './lib/orderStatus/orderStatus';
|
|
12
|
+
export { AssetManager } from './lib/assetManager/AssetManager';
|
|
13
|
+
export type { ApiChainData, ApiChainsResponse, AssetManagerState, BaseChainData, ChainData, FiatResponse, } from './lib/assetManager/types';
|
|
14
|
+
export { RouteValidator } from './lib/assetManager/routeValidator/routeValidator';
|
|
15
|
+
export type { RoutePolicy } from './lib/assetManager/routeValidator/routeValidator';
|
package/dist/src/lib/api.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const MAINNET_ORDERBOOK_API = "https://api.garden.finance";
|
|
2
|
-
export declare const TESTNET_ORDERBOOK_API = "https://
|
|
2
|
+
export declare const TESTNET_ORDERBOOK_API = "https://testnet.api.garden.finance";
|
package/dist/src/lib/asset.d.ts
CHANGED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
export type AssetCommon = {
|
|
2
|
-
name: string;
|
|
3
|
-
decimals: number;
|
|
4
|
-
symbol: string;
|
|
5
|
-
chain: Chain;
|
|
6
|
-
logo?: string;
|
|
7
|
-
atomicSwapAddress: string;
|
|
8
|
-
};
|
|
9
|
-
export type AssetToken = AssetCommon & {
|
|
10
|
-
tokenAddress: string;
|
|
11
|
-
};
|
|
12
|
-
export type Asset = AssetToken;
|
|
13
|
-
export declare enum BlockchainType {
|
|
14
|
-
Bitcoin = "Bitcoin",
|
|
15
|
-
EVM = "EVM",
|
|
16
|
-
Solana = "Solana",
|
|
17
|
-
Starknet = "Starknet",
|
|
18
|
-
Sui = "Sui"
|
|
19
|
-
}
|
|
20
|
-
export declare enum NetworkType {
|
|
21
|
-
mainnet = "mainnet",
|
|
22
|
-
testnet = "testnet",
|
|
23
|
-
localnet = "localnet"
|
|
24
|
-
}
|
|
25
|
-
export type Network = {
|
|
26
|
-
[networkName: string]: {
|
|
27
|
-
chainId: number;
|
|
28
|
-
fillerAddresses: string[];
|
|
29
|
-
networkLogo: string;
|
|
30
|
-
explorer: string;
|
|
31
|
-
networkType: NetworkType;
|
|
32
|
-
assets?: Asset[];
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
export declare const Chains: {
|
|
36
|
-
readonly bitcoin: "bitcoin";
|
|
37
|
-
readonly bitcoin_testnet: "bitcoin_testnet";
|
|
38
|
-
readonly bitcoin_regtest: "bitcoin_regtest";
|
|
39
|
-
readonly ethereum: "ethereum";
|
|
40
|
-
readonly base: "base";
|
|
41
|
-
readonly arbitrum: "arbitrum";
|
|
42
|
-
readonly ethereum_sepolia: "ethereum_sepolia";
|
|
43
|
-
readonly arbitrum_localnet: "arbitrum_localnet";
|
|
44
|
-
readonly arbitrum_sepolia: "arbitrum_sepolia";
|
|
45
|
-
readonly ethereum_localnet: "ethereum_localnet";
|
|
46
|
-
readonly base_sepolia: "base_sepolia";
|
|
47
|
-
readonly solana: "solana";
|
|
48
|
-
readonly solana_testnet: "solana_testnet";
|
|
49
|
-
readonly solana_localnet: "solana_localnet";
|
|
50
|
-
readonly bera_testnet: "bera_testnet";
|
|
51
|
-
readonly citrea_testnet: "citrea_testnet";
|
|
52
|
-
readonly bera: "bera";
|
|
53
|
-
readonly monad_testnet: "monad_testnet";
|
|
54
|
-
readonly starknet: "starknet";
|
|
55
|
-
readonly starknet_sepolia: "starknet_sepolia";
|
|
56
|
-
readonly starknet_devnet: "starknet_devnet";
|
|
57
|
-
readonly hyperliquid_testnet: "hyperliquid_testnet";
|
|
58
|
-
readonly hyperliquid: "hyperliquid";
|
|
59
|
-
readonly unichain: "unichain";
|
|
60
|
-
readonly corn: "corn";
|
|
61
|
-
readonly botanix: "botanix";
|
|
62
|
-
readonly bnbchain: "bnbchain";
|
|
63
|
-
readonly bnbchain_testnet: "bnbchain_testnet";
|
|
64
|
-
readonly sui: "sui";
|
|
65
|
-
readonly sui_testnet: "sui_testnet";
|
|
66
|
-
readonly core: "core";
|
|
67
|
-
};
|
|
68
|
-
export type Chain = keyof typeof Chains;
|
|
69
|
-
export type EvmChain = keyof Omit<typeof Chains, 'bitcoin' | 'bitcoin_testnet' | 'bitcoin_regtest' | 'solana' | 'solana_testnet' | 'solana_localnet' | 'starknet' | 'starknet_devnet' | 'starknet_sepolia' | 'sui' | 'sui_testnet'>;
|
|
70
|
-
export declare const isMainnet: (chain: Chain) => chain is "bitcoin" | "ethereum" | "base" | "arbitrum" | "solana" | "bera" | "starknet" | "hyperliquid" | "unichain" | "corn" | "botanix" | "bnbchain" | "sui" | "core";
|
|
71
|
-
export declare const isBitcoin: (chain: Chain) => chain is "bitcoin" | "bitcoin_testnet" | "bitcoin_regtest";
|
|
72
|
-
export declare const isEVM: (chain: Chain) => chain is "ethereum" | "base" | "arbitrum" | "ethereum_sepolia" | "arbitrum_localnet" | "arbitrum_sepolia" | "ethereum_localnet" | "base_sepolia" | "bera_testnet" | "citrea_testnet" | "bera" | "monad_testnet" | "hyperliquid_testnet" | "hyperliquid" | "unichain" | "corn" | "botanix" | "bnbchain" | "bnbchain_testnet" | "core";
|
|
73
|
-
export declare const isSolana: (chain: Chain) => chain is "solana" | "solana_testnet" | "solana_localnet";
|
|
74
|
-
export declare const isStarknet: (chain: Chain) => chain is "starknet" | "starknet_sepolia" | "starknet_devnet";
|
|
75
|
-
export declare const isSui: (chain: Chain) => chain is "sui" | "sui_testnet";
|
|
76
|
-
export declare const getBlockchainType: (chain: Chain) => BlockchainType;
|
|
77
|
-
export declare const NativeTokenAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
78
|
-
export declare const isEvmNativeToken: (chain: Chain, tokenAddress: string) => boolean;
|
|
79
|
-
export declare const isSolanaNativeToken: (chain: Chain, tokenAddress: string) => boolean;
|
|
80
|
-
export declare const isSuiNativeToken: (chain: Chain, tokenAddress: string) => boolean;
|
|
81
|
-
export declare const isNativeToken: (asset: Asset) => boolean;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Url, AsyncResult, IAuth } from '@gardenfi/utils';
|
|
2
|
+
import { RouteValidator } from './routeValidator/routeValidator';
|
|
3
|
+
import { Assets, ChainData, Chains } from './types';
|
|
4
|
+
import { ChainAsset } from '../chainAsset/chainAsset';
|
|
5
|
+
import { Asset, Chain } from '../constants/asset.types';
|
|
6
|
+
|
|
7
|
+
type AssetManagerUrlConfig = {
|
|
8
|
+
baseUrl: string | Url;
|
|
9
|
+
assetsUrl?: string | Url;
|
|
10
|
+
policyUrl?: string | Url;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* AssetManager
|
|
14
|
+
*
|
|
15
|
+
* It fetches asset data from our API, caches it locally, and provides methods
|
|
16
|
+
* to check if routes between assets are valid. Also builds a route matrix
|
|
17
|
+
* to make route lookups fast.
|
|
18
|
+
*/
|
|
19
|
+
export declare class AssetManager {
|
|
20
|
+
assets: Assets | null;
|
|
21
|
+
chains: Chains | null;
|
|
22
|
+
routeValidator: RouteValidator;
|
|
23
|
+
routeMatrix: Record<string, ChainAsset[]> | null;
|
|
24
|
+
isLoading: boolean;
|
|
25
|
+
error: string | null;
|
|
26
|
+
private readonly urls;
|
|
27
|
+
private auth;
|
|
28
|
+
constructor(urlConfig: AssetManagerUrlConfig, apiKey: IAuth | string);
|
|
29
|
+
/**
|
|
30
|
+
* Initialize the AssetManager by fetching all required data
|
|
31
|
+
*/
|
|
32
|
+
initialize(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Fetch and cache asset and chain data from API
|
|
35
|
+
*/
|
|
36
|
+
fetchAndSetAssetsAndChains(): AsyncResult<string, string>;
|
|
37
|
+
/**
|
|
38
|
+
* Check if a swap route from one asset to another is valid
|
|
39
|
+
*/
|
|
40
|
+
isRouteValid(from: Asset, to: Asset): Promise<boolean>;
|
|
41
|
+
/**
|
|
42
|
+
* Get all valid destination assets for a given source asset
|
|
43
|
+
*/
|
|
44
|
+
getValidDestinations(asset: Asset): Asset[];
|
|
45
|
+
/**
|
|
46
|
+
* Get asset by chain and token address
|
|
47
|
+
*/
|
|
48
|
+
getAsset(asset: string | Asset | ChainAsset): Asset | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Get all assets for a specific chain
|
|
51
|
+
*/
|
|
52
|
+
getAssetsByChain(chain: Chain): Asset[];
|
|
53
|
+
/**
|
|
54
|
+
* Search assets by symbol or name
|
|
55
|
+
*/
|
|
56
|
+
searchAssets(query: string): Asset[];
|
|
57
|
+
/**
|
|
58
|
+
* Get chain data by chain identifier
|
|
59
|
+
*/
|
|
60
|
+
getChain(chain: Chain): ChainData | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Build route matrix for fast O(1) route lookups
|
|
63
|
+
*/
|
|
64
|
+
buildRouteMatrix(): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Process raw API data into structured format
|
|
67
|
+
*/
|
|
68
|
+
private processApiData;
|
|
69
|
+
/**
|
|
70
|
+
* Parse chain identifier from string
|
|
71
|
+
*/
|
|
72
|
+
private parseChainIdentifier;
|
|
73
|
+
/**
|
|
74
|
+
* Format chain name for display
|
|
75
|
+
*/
|
|
76
|
+
private formatChainName;
|
|
77
|
+
/**
|
|
78
|
+
* Refresh all data
|
|
79
|
+
*/
|
|
80
|
+
refresh(): Promise<void>;
|
|
81
|
+
}
|
|
82
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { AsyncResult, IAuth } from '@gardenfi/utils';
|
|
2
|
+
import { ChainAsset } from '../../chainAsset/chainAsset';
|
|
3
|
+
import { default as NodeCache } from 'node-cache';
|
|
4
|
+
|
|
5
|
+
type RoutePolicy = {
|
|
6
|
+
default: 'open' | 'closed';
|
|
7
|
+
isolation_groups: string[];
|
|
8
|
+
blacklist_pairs: string[];
|
|
9
|
+
whitelist_overrides: string[];
|
|
10
|
+
};
|
|
11
|
+
declare class RouteValidator {
|
|
12
|
+
policy: NodeCache;
|
|
13
|
+
private static readonly POLICY_CACHE_KEY;
|
|
14
|
+
private apiBaseUrl;
|
|
15
|
+
private auth;
|
|
16
|
+
constructor(apiBaseUrl: string, apiKey: string | IAuth);
|
|
17
|
+
getPolicy(): RoutePolicy | undefined;
|
|
18
|
+
setPolicy(policy: RoutePolicy): RoutePolicy;
|
|
19
|
+
/**
|
|
20
|
+
* Loads the current route policy, cached or via API.
|
|
21
|
+
*/
|
|
22
|
+
loadPolicy(): AsyncResult<RoutePolicy, string>;
|
|
23
|
+
/**
|
|
24
|
+
* Checks if a given route is valid based on all route rules.
|
|
25
|
+
*/
|
|
26
|
+
isValidRoute(fromAsset: ChainAsset, toAsset: ChainAsset): Promise<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* Returns all valid destinations for a given source asset.
|
|
29
|
+
*/
|
|
30
|
+
getValidDestinations(fromAsset: ChainAsset, allAssets: ChainAsset[]): Promise<ChainAsset[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Returns every valid route (from-to pair) among the provided assets.
|
|
33
|
+
*/
|
|
34
|
+
getAllValidRoutes(assets: ChainAsset[]): Promise<Array<{
|
|
35
|
+
from: ChainAsset;
|
|
36
|
+
to: ChainAsset;
|
|
37
|
+
}>>;
|
|
38
|
+
/**
|
|
39
|
+
* Turns policy string rules into sorted ParsedRule objects.
|
|
40
|
+
*/
|
|
41
|
+
private preprocessRules;
|
|
42
|
+
/**
|
|
43
|
+
* Parses a rule string (e.g. "ethereum:usdc -> base:usdt") into parts.
|
|
44
|
+
*/
|
|
45
|
+
private parseRule;
|
|
46
|
+
/**
|
|
47
|
+
* Gives a specificity score to a rule pattern for prioritizing.
|
|
48
|
+
*/
|
|
49
|
+
private calculateSpecificity;
|
|
50
|
+
/**
|
|
51
|
+
* Finds the first matching rule for an asset given the rule "side".
|
|
52
|
+
*/
|
|
53
|
+
private findMatchingRule;
|
|
54
|
+
/**
|
|
55
|
+
* Checks if a given toAsset matches the rule's destination side.
|
|
56
|
+
*/
|
|
57
|
+
private matchesRuleDestination;
|
|
58
|
+
/**
|
|
59
|
+
* Checks if a given fromAsset matches the rule's source side.
|
|
60
|
+
*/
|
|
61
|
+
private matchesRuleSource;
|
|
62
|
+
/**
|
|
63
|
+
* Checks if any rule in a list matches fromAsset and toAsset.
|
|
64
|
+
*/
|
|
65
|
+
private matchesRuleList;
|
|
66
|
+
/**
|
|
67
|
+
* Checks if a rule matches fromAsset and toAsset (forward or backward if bidirectional).
|
|
68
|
+
*/
|
|
69
|
+
private matchesRule;
|
|
70
|
+
/**
|
|
71
|
+
* Checks if an asset string matches a rule's pattern (wildcards supported).
|
|
72
|
+
*/
|
|
73
|
+
private matchesAssetPattern;
|
|
74
|
+
buildRouteMatrix(assets: ChainAsset[]): Promise<Record<string, ChainAsset[]>>;
|
|
75
|
+
}
|
|
76
|
+
export { RouteValidator, type RoutePolicy };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Asset, Chain } from '../constants/asset.types';
|
|
2
|
+
|
|
3
|
+
export type BaseChainData = {
|
|
4
|
+
id: string;
|
|
5
|
+
chain: string | Chain;
|
|
6
|
+
icon: string;
|
|
7
|
+
explorer_url: string;
|
|
8
|
+
confirmation_target: number;
|
|
9
|
+
source_timelock: string;
|
|
10
|
+
destination_timelock: string;
|
|
11
|
+
supported_htlc_schemas: string[];
|
|
12
|
+
supported_token_schemas: string[];
|
|
13
|
+
};
|
|
14
|
+
export type ChainData = BaseChainData & {
|
|
15
|
+
chain: Chain;
|
|
16
|
+
name: string;
|
|
17
|
+
};
|
|
18
|
+
export type ApiChainData = BaseChainData & {
|
|
19
|
+
assets: Asset[];
|
|
20
|
+
};
|
|
21
|
+
export type ApiChainsResponse = {
|
|
22
|
+
status: string;
|
|
23
|
+
result: ApiChainData[];
|
|
24
|
+
};
|
|
25
|
+
export type FiatResponse = {
|
|
26
|
+
status: string;
|
|
27
|
+
result: Record<string, string>;
|
|
28
|
+
};
|
|
29
|
+
export type Assets = Record<string, Asset>;
|
|
30
|
+
export type Chains = Partial<Record<Chain, ChainData>>;
|
|
31
|
+
export type AssetManagerState = {
|
|
32
|
+
allChains: Chains | null;
|
|
33
|
+
allAssets: Assets | null;
|
|
34
|
+
assets: Assets | null;
|
|
35
|
+
chains: Chains | null;
|
|
36
|
+
fiatData: Record<string, number | undefined>;
|
|
37
|
+
isLoading: boolean;
|
|
38
|
+
error: string | null;
|
|
39
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Url } from '@gardenfi/utils';
|
|
2
|
+
import { ChainAsset } from '../chainAsset/chainAsset';
|
|
3
|
+
|
|
4
|
+
export declare function parseAssetNameSymbol(input: string | undefined, assetId?: string | ChainAsset, fallbackSymbol?: string): {
|
|
5
|
+
name: string;
|
|
6
|
+
symbol: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function ensureUrl(value: string | Url): Url;
|
|
9
|
+
export declare function buildDefaultEndpoint(baseUrl: Url, path: string): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Network } from '@gardenfi/utils';
|
|
2
|
+
import { Asset, BlockchainType, Chain } from '../constants/asset.types';
|
|
3
|
+
|
|
4
|
+
export type ChainAssetString = `${Chain}:${string}`;
|
|
5
|
+
export type AssetLike = Asset | ChainAssetString | ChainAsset | string;
|
|
6
|
+
export declare class ChainAsset {
|
|
7
|
+
chain: Chain;
|
|
8
|
+
symbol: string;
|
|
9
|
+
blockchainType: BlockchainType;
|
|
10
|
+
formatted: ChainAssetString;
|
|
11
|
+
network: Network;
|
|
12
|
+
asset: Asset;
|
|
13
|
+
constructor(chain: Chain, symbol: string);
|
|
14
|
+
static from(asset: AssetLike): ChainAsset;
|
|
15
|
+
static fromChainAndSymbol(chain: Chain, symbol: string): ChainAsset;
|
|
16
|
+
static fromString(formatted: ChainAssetString | string): ChainAsset;
|
|
17
|
+
static fromAsset(asset: Asset): ChainAsset;
|
|
18
|
+
toString(): string;
|
|
19
|
+
}
|