@gardenfi/core 2.0.22 → 2.0.23

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.
@@ -0,0 +1,29 @@
1
+ import { MatchedOrder } from '@gardenfi/orderbook';
2
+ import { AsyncResult } from '@gardenfi/utils';
3
+
4
+ export interface IEVMHTLC {
5
+ /**
6
+ * Returns the HTLC actor address.
7
+ * This is the user's wallet address in the case of EVM.
8
+ */
9
+ get htlcActorAddress(): string;
10
+ /**
11
+ * Initiates the HTLC by sending funds to the HTLC contract.
12
+ * @param order - The matched order.
13
+ * @returns A promise resolving to the transaction hash of the initiation.
14
+ */
15
+ initiate(order: MatchedOrder): AsyncResult<string, string>;
16
+ /**
17
+ * Redeems funds from the HTLC contract to the actor's address.
18
+ * @param order - The matched order.
19
+ * @param secret - The secret required to unlock the htlc.
20
+ * @returns A promise resolving to the transaction hash of the redemption.
21
+ */
22
+ redeem(order: MatchedOrder, secret: string): AsyncResult<string, string>;
23
+ /**
24
+ * Refunds funds from the HTLC contract back to the actor's address upon expiration.
25
+ * @param order - The matched order.
26
+ * @returns A promise resolving to the transaction hash of the refund.
27
+ */
28
+ refund(order: MatchedOrder): AsyncResult<string, string>;
29
+ }
@@ -1,13 +1,15 @@
1
+ import { AsyncResult, IAuth, Url } from '@gardenfi/utils';
1
2
  import { WalletClient } from 'viem';
2
3
  import { MatchedOrder } from '@gardenfi/orderbook';
3
- import { IEVMRelay } from './evmRelay.types';
4
- import { AsyncResult } from '@catalogfi/utils';
5
- import { IAuth, Url } from '@gardenfi/utils';
4
+ import { IEVMHTLC } from '../htlc.types';
6
5
 
7
- export declare class EvmRelay implements IEVMRelay {
6
+ export declare class EvmRelay implements IEVMHTLC {
8
7
  private url;
9
8
  private auth;
10
- constructor(url: string | Url, auth: IAuth);
11
- init(walletClient: WalletClient, order: MatchedOrder): AsyncResult<string, string>;
12
- redeem(orderId: string, secret: string): AsyncResult<string, string>;
9
+ private wallet;
10
+ constructor(url: string | Url, wallet: WalletClient, auth: IAuth);
11
+ get htlcActorAddress(): string;
12
+ initiate(order: MatchedOrder): AsyncResult<string, string>;
13
+ redeem(order: MatchedOrder, secret: string): AsyncResult<string, string>;
14
+ refund(): AsyncResult<string, string>;
13
15
  }
@@ -0,0 +1,11 @@
1
+ export declare class DigestKey {
2
+ private _digestKey;
3
+ private _userId;
4
+ constructor(digestKey: string);
5
+ static from(digestKey: string): import('@catalogfi/utils').Result<never, string> | import('@catalogfi/utils').Result<DigestKey, never>;
6
+ static generateRandom(): import('@catalogfi/utils').Result<never, string> | import('@catalogfi/utils').Result<DigestKey, never>;
7
+ private static isValidPrivateKey;
8
+ private static generateRandomDigestKey;
9
+ get digestKey(): string;
10
+ get userId(): string;
11
+ }
@@ -2,16 +2,20 @@ import { ISecretManager } from './../secretManager/secretManager.types';
2
2
  import { AsyncResult } from '@catalogfi/utils';
3
3
  import { GardenEvents, GardenProps, IGardenJS, SwapParams } from './garden.types';
4
4
  import { IOrderbook, MatchedOrder } from '@gardenfi/orderbook';
5
- import { EventBroker } from '@gardenfi/utils';
5
+ import { Environment, EventBroker, IAuth } from '@gardenfi/utils';
6
6
  import { IQuote } from '../quote/quote.types';
7
7
  import { IBitcoinWallet } from '@catalogfi/wallets';
8
8
  import { IBlockNumberFetcher } from '../blockNumberFetcher/blockNumber';
9
- import { IEVMRelay } from '../evm/relay/evmRelay.types';
9
+ import { IEVMHTLC } from '../evm/htlc.types';
10
+ import { DigestKey } from './digestKey/digestKey';
11
+ import { WalletClient } from 'viem';
12
+ import { IStarknetHTLC } from '../starknet/starknetHTLC.types';
13
+ import { Account } from 'starknet';
10
14
 
11
15
  export declare class Garden extends EventBroker<GardenEvents> implements IGardenJS {
12
16
  private environment;
13
17
  private _secretManager;
14
- private _orderBook;
18
+ private _orderbook;
15
19
  private _quote;
16
20
  private getOrderThreshold;
17
21
  private _orderbookUrl;
@@ -19,18 +23,30 @@ export declare class Garden extends EventBroker<GardenEvents> implements IGarden
19
23
  private orderExecutorCache;
20
24
  private _blockNumberFetcher;
21
25
  private refundSacpCache;
22
- private _evmRelay;
23
- private _evmWallet;
26
+ private _evmHTLC;
27
+ private _starknetHTLC;
24
28
  private _btcWallet;
25
29
  private bitcoinRedeemCache;
30
+ private _digestKey;
26
31
  constructor(config: GardenProps);
32
+ static from(config: {
33
+ environment: Environment;
34
+ digestKey: string;
35
+ wallets: {
36
+ evm: WalletClient;
37
+ starknet: Account;
38
+ };
39
+ }): Garden;
27
40
  get orderbookUrl(): string;
28
- get evmRelay(): IEVMRelay;
41
+ get evmHTLC(): IEVMHTLC | undefined;
42
+ get starknetHTLC(): IStarknetHTLC | undefined;
29
43
  get quote(): IQuote;
30
44
  get btcWallet(): IBitcoinWallet | undefined;
31
45
  get orderbook(): IOrderbook;
32
46
  get blockNumberFetcher(): IBlockNumberFetcher;
33
47
  get secretManager(): ISecretManager;
48
+ get auth(): IAuth;
49
+ get digestKey(): DigestKey;
34
50
  private initializeSMandBTCWallet;
35
51
  swap(params: SwapParams): AsyncResult<MatchedOrder, string>;
36
52
  private validateAndFillParams;
@@ -39,11 +55,10 @@ export declare class Garden extends EventBroker<GardenEvents> implements IGarden
39
55
  private pollOrder;
40
56
  execute(interval?: number): Promise<() => void>;
41
57
  private evmRedeem;
58
+ private starknetRedeem;
42
59
  private btcRedeem;
43
60
  private btcRefund;
44
- private getWallet;
45
61
  private postRefundSACP;
46
- private fetchCurrentBlockNumbers;
47
62
  private filterExpiredAndAssignStatus;
48
63
  private broadcastRedeemTx;
49
64
  }
@@ -1,13 +1,14 @@
1
1
  import { AsyncResult } from '@catalogfi/utils';
2
2
  import { Asset, IOrderbook, MatchedOrder } from '@gardenfi/orderbook';
3
- import { OrderStatus } from '../status';
4
- import { Environment, EventBroker, SiweOpts } from '@gardenfi/utils';
5
- import { WalletClient } from 'viem';
3
+ import { OrderStatus } from '../orderStatus/status';
4
+ import { Environment, EventBroker, IAuth } from '@gardenfi/utils';
6
5
  import { ISecretManager } from '../secretManager/secretManager.types';
7
6
  import { IQuote } from '../quote/quote.types';
8
7
  import { IBlockNumberFetcher } from '../blockNumberFetcher/blockNumber';
9
- import { IEVMRelay } from '../evm/relay/evmRelay.types';
10
8
  import { IBitcoinWallet } from '@catalogfi/wallets';
9
+ import { IEVMHTLC } from '../evm/htlc.types';
10
+ import { DigestKey } from './digestKey/digestKey';
11
+ import { IStarknetHTLC } from '../starknet/starknetHTLC.types';
11
12
 
12
13
  export type SwapParams = {
13
14
  /**
@@ -19,11 +20,11 @@ export type SwapParams = {
19
20
  */
20
21
  toAsset: Asset;
21
22
  /**
22
- * Amount in lowest denomination of the asset.
23
+ * Amount in lowest denomination of the sendAsset.
23
24
  */
24
25
  sendAmount: string;
25
26
  /**
26
- * Amount in lowest denomination of the asset.
27
+ * Amount in lowest denomination of the toAsset.
27
28
  */
28
29
  receiveAmount: string;
29
30
  /**
@@ -87,7 +88,12 @@ export interface IGardenJS extends EventBroker<GardenEvents> {
87
88
  * The EVM relay.
88
89
  * @readonly
89
90
  */
90
- get evmRelay(): IEVMRelay;
91
+ get evmHTLC(): IEVMHTLC | undefined;
92
+ /**
93
+ * The Starknet relay.
94
+ * @readonly
95
+ */
96
+ get starknetHTLC(): IStarknetHTLC | undefined;
91
97
  /**
92
98
  * The current quote.
93
99
  * @readonly
@@ -113,6 +119,16 @@ export interface IGardenJS extends EventBroker<GardenEvents> {
113
119
  * @readonly
114
120
  */
115
121
  get secretManager(): ISecretManager;
122
+ /**
123
+ * The auth.
124
+ * @readonly
125
+ */
126
+ get auth(): IAuth;
127
+ /**
128
+ * The digest key.
129
+ * @readonly
130
+ */
131
+ get digestKey(): DigestKey;
116
132
  }
117
133
  export type OrderCacheValue = {
118
134
  txHash: string;
@@ -126,13 +142,16 @@ export interface IOrderExecutorCache {
126
142
  }
127
143
  export type GardenProps = {
128
144
  environment: Environment;
129
- apiKey?: string;
130
- evmWallet: WalletClient;
145
+ digestKey: string;
146
+ api?: string;
131
147
  secretManager?: ISecretManager;
132
- siweOpts?: SiweOpts;
133
- orderbookURl?: string;
134
- quote?: string;
148
+ orderbook?: IOrderbook;
149
+ quote?: IQuote;
135
150
  blockNumberFetcher?: IBlockNumberFetcher;
151
+ htlc: {
152
+ evm?: IEVMHTLC;
153
+ starknet?: IStarknetHTLC;
154
+ };
136
155
  };
137
156
  /**
138
157
  * Actions that can be performed on the order.
@@ -1,5 +1,5 @@
1
1
  import { MatchedOrder, Swap } from '@gardenfi/orderbook';
2
- import { OrderActions } from './garden/garden.types';
2
+ import { OrderActions } from '../garden/garden.types';
3
3
  import { OrderStatus, SwapStatus } from './status';
4
4
 
5
5
  /**
@@ -0,0 +1,86 @@
1
+ export declare const starknetHtlcABI: ({
2
+ name: string;
3
+ type: string;
4
+ interface_name: string;
5
+ members?: undefined;
6
+ items?: undefined;
7
+ inputs?: undefined;
8
+ kind?: undefined;
9
+ variants?: undefined;
10
+ } | {
11
+ name: string;
12
+ type: string;
13
+ members: {
14
+ name: string;
15
+ type: string;
16
+ }[];
17
+ interface_name?: undefined;
18
+ items?: undefined;
19
+ inputs?: undefined;
20
+ kind?: undefined;
21
+ variants?: undefined;
22
+ } | {
23
+ name: string;
24
+ type: string;
25
+ items: ({
26
+ name: string;
27
+ type: string;
28
+ inputs: never[];
29
+ outputs: {
30
+ type: string;
31
+ }[];
32
+ state_mutability: string;
33
+ } | {
34
+ name: string;
35
+ type: string;
36
+ inputs: {
37
+ name: string;
38
+ type: string;
39
+ }[];
40
+ outputs: never[];
41
+ state_mutability: string;
42
+ })[];
43
+ interface_name?: undefined;
44
+ members?: undefined;
45
+ inputs?: undefined;
46
+ kind?: undefined;
47
+ variants?: undefined;
48
+ } | {
49
+ name: string;
50
+ type: string;
51
+ inputs: {
52
+ name: string;
53
+ type: string;
54
+ }[];
55
+ interface_name?: undefined;
56
+ members?: undefined;
57
+ items?: undefined;
58
+ kind?: undefined;
59
+ variants?: undefined;
60
+ } | {
61
+ kind: string;
62
+ name: string;
63
+ type: string;
64
+ members: {
65
+ kind: string;
66
+ name: string;
67
+ type: string;
68
+ }[];
69
+ interface_name?: undefined;
70
+ items?: undefined;
71
+ inputs?: undefined;
72
+ variants?: undefined;
73
+ } | {
74
+ kind: string;
75
+ name: string;
76
+ type: string;
77
+ variants: {
78
+ kind: string;
79
+ name: string;
80
+ type: string;
81
+ }[];
82
+ interface_name?: undefined;
83
+ members?: undefined;
84
+ items?: undefined;
85
+ inputs?: undefined;
86
+ })[];
@@ -0,0 +1,122 @@
1
+ export declare const TokenABI: ({
2
+ name: string;
3
+ type: string;
4
+ interface_name: string;
5
+ members?: undefined;
6
+ variants?: undefined;
7
+ items?: undefined;
8
+ inputs?: undefined;
9
+ outputs?: undefined;
10
+ state_mutability?: undefined;
11
+ kind?: undefined;
12
+ } | {
13
+ name: string;
14
+ type: string;
15
+ members: {
16
+ name: string;
17
+ type: string;
18
+ }[];
19
+ interface_name?: undefined;
20
+ variants?: undefined;
21
+ items?: undefined;
22
+ inputs?: undefined;
23
+ outputs?: undefined;
24
+ state_mutability?: undefined;
25
+ kind?: undefined;
26
+ } | {
27
+ name: string;
28
+ type: string;
29
+ variants: {
30
+ name: string;
31
+ type: string;
32
+ }[];
33
+ interface_name?: undefined;
34
+ members?: undefined;
35
+ items?: undefined;
36
+ inputs?: undefined;
37
+ outputs?: undefined;
38
+ state_mutability?: undefined;
39
+ kind?: undefined;
40
+ } | {
41
+ name: string;
42
+ type: string;
43
+ items: {
44
+ name: string;
45
+ type: string;
46
+ inputs: {
47
+ name: string;
48
+ type: string;
49
+ }[];
50
+ outputs: {
51
+ type: string;
52
+ }[];
53
+ state_mutability: string;
54
+ }[];
55
+ interface_name?: undefined;
56
+ members?: undefined;
57
+ variants?: undefined;
58
+ inputs?: undefined;
59
+ outputs?: undefined;
60
+ state_mutability?: undefined;
61
+ kind?: undefined;
62
+ } | {
63
+ name: string;
64
+ type: string;
65
+ inputs: {
66
+ name: string;
67
+ type: string;
68
+ }[];
69
+ interface_name?: undefined;
70
+ members?: undefined;
71
+ variants?: undefined;
72
+ items?: undefined;
73
+ outputs?: undefined;
74
+ state_mutability?: undefined;
75
+ kind?: undefined;
76
+ } | {
77
+ name: string;
78
+ type: string;
79
+ inputs: {
80
+ name: string;
81
+ type: string;
82
+ }[];
83
+ outputs: {
84
+ type: string;
85
+ }[];
86
+ state_mutability: string;
87
+ interface_name?: undefined;
88
+ members?: undefined;
89
+ variants?: undefined;
90
+ items?: undefined;
91
+ kind?: undefined;
92
+ } | {
93
+ kind: string;
94
+ name: string;
95
+ type: string;
96
+ members: {
97
+ kind: string;
98
+ name: string;
99
+ type: string;
100
+ }[];
101
+ interface_name?: undefined;
102
+ variants?: undefined;
103
+ items?: undefined;
104
+ inputs?: undefined;
105
+ outputs?: undefined;
106
+ state_mutability?: undefined;
107
+ } | {
108
+ kind: string;
109
+ name: string;
110
+ type: string;
111
+ variants: {
112
+ kind: string;
113
+ name: string;
114
+ type: string;
115
+ }[];
116
+ interface_name?: undefined;
117
+ members?: undefined;
118
+ items?: undefined;
119
+ inputs?: undefined;
120
+ outputs?: undefined;
121
+ state_mutability?: undefined;
122
+ })[];
@@ -0,0 +1,4 @@
1
+ import { Account } from 'starknet';
2
+ import { AsyncResult } from '@catalogfi/utils';
3
+
4
+ export declare const checkAllowanceAndApprove: (account: Account, tokenAddress: string, htlcAddress: string, amount: bigint, nodeUrl: string) => AsyncResult<string, string>;
@@ -0,0 +1,34 @@
1
+ import { MatchedOrder } from '@gardenfi/orderbook';
2
+ import { AsyncResult } from '@catalogfi/utils';
3
+ import { Account, CallData } from 'starknet';
4
+ import { IStarknetHTLC } from '../starknetHTLC.types';
5
+
6
+ export declare class StarknetHTLC implements IStarknetHTLC {
7
+ private nodeUrl;
8
+ private account;
9
+ constructor(account: Account, nodeUrl?: string);
10
+ get htlcActorAddress(): string;
11
+ private getHTLCContract;
12
+ /**
13
+ * Initiates the HTLC
14
+ * @param order Order to initiate HTLC for
15
+ * @returns Transaction ID
16
+ */
17
+ initiate(order: MatchedOrder): AsyncResult<string, string>;
18
+ callData: CallData;
19
+ /**
20
+ * Redeems the HTLC
21
+ *
22
+ * @param order Order to redeem HTLC for
23
+ * @param secret Secret to redeem HTLC with
24
+ * @returns Transaction ID
25
+ */
26
+ redeem(order: MatchedOrder, secret: string): AsyncResult<string, string>;
27
+ /**
28
+ * Refunds the HTLC
29
+ *
30
+ * @param order Order to refund HTLC for
31
+ * @returns Refund transaction ID
32
+ */
33
+ refund(order: MatchedOrder): AsyncResult<string, string>;
34
+ }
@@ -0,0 +1,16 @@
1
+ import { Account } from 'starknet';
2
+ import { MatchedOrder } from '@gardenfi/orderbook';
3
+ import { AsyncResult } from '@catalogfi/utils';
4
+ import { Url } from '@gardenfi/utils';
5
+ import { IStarknetHTLC } from '../starknetHTLC.types';
6
+
7
+ export declare class StarknetRelay implements IStarknetHTLC {
8
+ private url;
9
+ private nodeUrl;
10
+ private account;
11
+ constructor(relayerUrl: string | Url, account: Account, nodeUrl?: string);
12
+ get htlcActorAddress(): string;
13
+ initiate(order: MatchedOrder): AsyncResult<string, string>;
14
+ redeem(order: MatchedOrder, secret: string): AsyncResult<string, string>;
15
+ refund(): AsyncResult<string, string>;
16
+ }
@@ -0,0 +1,28 @@
1
+ import { MatchedOrder } from '@gardenfi/orderbook';
2
+ import { AsyncResult } from '@catalogfi/utils';
3
+
4
+ export interface IStarknetHTLC {
5
+ /**
6
+ * The address of the HTLC actor.
7
+ */
8
+ get htlcActorAddress(): string;
9
+ /**
10
+ * Initiates the HTLC by sending funds to the HTLC contract.
11
+ * @param order - The matched order.
12
+ * @returns A promise resolving to the transaction hash of the initiation.
13
+ */
14
+ initiate(order: MatchedOrder): AsyncResult<string, string>;
15
+ /**
16
+ * Redeems funds from the HTLC contract to the actor's address.
17
+ * @param order - The matched order.
18
+ * @param secret - The secret required to unlock the htlc.
19
+ * @returns A promise resolving to the transaction hash of the redemption.
20
+ */
21
+ redeem(order: MatchedOrder, secret: string): AsyncResult<string, string>;
22
+ /**
23
+ * Refunds funds from the HTLC contract back to the actor's address upon expiration.
24
+ * @param order - The matched order.
25
+ * @returns A promise resolving to the transaction hash of the refund.
26
+ */
27
+ refund(order: MatchedOrder): AsyncResult<string, string>;
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/core",
3
- "version": "2.0.22",
3
+ "version": "2.0.23",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "vite build",
@@ -27,10 +27,12 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@catalogfi/wallets": "^0.2.59",
30
- "@gardenfi/orderbook": "^2.0.6",
31
- "@gardenfi/utils": "^2.0.3",
30
+ "@gardenfi/orderbook": "^2.0.7",
31
+ "@gardenfi/utils": "^2.0.5",
32
32
  "bignumber.js": "^9.1.2",
33
33
  "bitcoinjs-lib": "^6.1.6",
34
+ "crypto-browserify": "^3.12.1",
35
+ "starknet": "6.23.1",
34
36
  "tiny-secp256k1": "^2.2.3",
35
37
  "varuint-bitcoin": "^1.1.2",
36
38
  "viem": "^2.21.23"