@gardenfi/core 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/{ccip-DSGVoxhU.cjs → ccip-DGrkijK3.cjs} +1 -1
- package/dist/{ccip-Bg3f6Dwh.js → ccip-DoKK2Eev.js} +1 -1
- package/dist/index-BB1moYTm.cjs +106 -0
- package/dist/index-dcGJN5tW.js +33698 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +32 -39
- package/dist/src/index.d.ts +7 -12
- package/dist/src/lib/bitcoin/API.d.ts +3 -1
- package/dist/src/lib/bitcoin/bitcoinHtlc.d.ts +98 -0
- package/dist/src/lib/bitcoin/bitcoinhtlc.types.d.ts +53 -0
- package/dist/src/lib/bitcoin/provider/provider.d.ts +2 -1
- package/dist/src/lib/bitcoin/wallet/abstractWallet.d.ts +1 -1
- package/dist/src/lib/bitcoin/wallet/wallet.d.ts +1 -1
- package/dist/src/lib/bitcoin/wallet/wallet.interface.d.ts +1 -1
- package/dist/src/lib/constants.d.ts +4 -9
- package/dist/src/lib/evm/htlc/evmHTLC.d.ts +102 -102
- package/dist/src/lib/evm/htlc.types.d.ts +4 -4
- package/dist/src/lib/evm/relay/evmRelay.d.ts +9 -11
- package/dist/src/lib/evm/relay/htlcInitiate.d.ts +25 -0
- package/dist/src/lib/garden/cache/GardenCache.d.ts +45 -0
- package/dist/src/lib/garden/executor/executor.d.ts +26 -0
- package/dist/src/lib/garden/garden.d.ts +43 -52
- package/dist/src/lib/garden/garden.types.d.ts +70 -103
- package/dist/src/lib/garden/utils.d.ts +4 -0
- package/dist/src/lib/quote/quote.d.ts +8 -7
- package/dist/src/lib/quote/quote.types.d.ts +21 -13
- package/dist/src/lib/relayer/relayer.d.ts +9 -0
- package/dist/src/lib/solana/htlc/ISolanaHTLC.d.ts +4 -4
- package/dist/src/lib/solana/htlc/solanaHTLC.d.ts +7 -7
- package/dist/src/lib/solana/relayer/solanaRelay.d.ts +28 -35
- package/dist/src/lib/solana/solanaTypes.d.ts +6 -6
- package/dist/src/lib/starknet/htlc/starknetHTLC.d.ts +4 -4
- package/dist/src/lib/starknet/relay/starknetRelay.d.ts +9 -5
- package/dist/src/lib/starknet/starknetHTLC.types.d.ts +4 -4
- package/dist/src/lib/sui/htlc/suiHTLC.d.ts +7 -6
- package/dist/src/lib/sui/relay/suiRelay.d.ts +8 -5
- package/dist/src/lib/sui/suiHTLC.types.d.ts +4 -4
- package/dist/src/lib/switchOrAddNetwork.d.ts +5 -3
- package/dist/src/lib/utils.d.ts +38 -6
- package/package.json +4 -3
- package/dist/index-D-NHDZrP.js +0 -31936
- package/dist/index-s2tkcnpk.cjs +0 -105
- package/dist/src/lib/bitcoin/htlc.d.ts +0 -106
- package/dist/src/lib/blockNumberFetcher/blockNumber.d.ts +0 -15
- package/dist/src/lib/evm/relay/evmRelay.types.d.ts +0 -26
- package/dist/src/lib/garden/cache/executorCache.d.ts +0 -14
- package/dist/src/lib/orderStatus/orderStatusParser.d.ts +0 -37
- package/dist/src/lib/orderStatus/status.d.ts +0 -130
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EvmOrderResponse, Order } from '@gardenfi/orderbook';
|
|
2
2
|
import { AsyncResult } from '@gardenfi/utils';
|
|
3
3
|
|
|
4
4
|
export interface IEVMHTLC {
|
|
@@ -12,18 +12,18 @@ export interface IEVMHTLC {
|
|
|
12
12
|
* @param order - The matched order.
|
|
13
13
|
* @returns A promise resolving to the transaction hash of the initiation.
|
|
14
14
|
*/
|
|
15
|
-
initiate(order:
|
|
15
|
+
initiate(order: Order | EvmOrderResponse): AsyncResult<string, string>;
|
|
16
16
|
/**
|
|
17
17
|
* Redeems funds from the HTLC contract to the actor's address.
|
|
18
18
|
* @param order - The matched order.
|
|
19
19
|
* @param secret - The secret required to unlock the htlc.
|
|
20
20
|
* @returns A promise resolving to the transaction hash of the redemption.
|
|
21
21
|
*/
|
|
22
|
-
redeem(order:
|
|
22
|
+
redeem(order: Order, secret: string): AsyncResult<string, string>;
|
|
23
23
|
/**
|
|
24
24
|
* Refunds funds from the HTLC contract back to the actor's address upon expiration.
|
|
25
25
|
* @param order - The matched order.
|
|
26
26
|
* @returns A promise resolving to the transaction hash of the refund.
|
|
27
27
|
*/
|
|
28
|
-
refund(order:
|
|
28
|
+
refund(order: Order): AsyncResult<string, string>;
|
|
29
29
|
}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { AsyncResult, IAuth, Url } from '@gardenfi/utils';
|
|
2
|
+
import { EvmOrderResponse, Order } from '@gardenfi/orderbook';
|
|
2
3
|
import { WalletClient } from 'viem';
|
|
3
|
-
import { MatchedOrder } from '@gardenfi/orderbook';
|
|
4
|
-
import { IEVMHTLC } from '../htlc.types';
|
|
5
4
|
|
|
6
|
-
export declare class EvmRelay
|
|
7
|
-
private url;
|
|
8
|
-
private auth;
|
|
5
|
+
export declare class EvmRelay {
|
|
9
6
|
private wallet;
|
|
7
|
+
private auth;
|
|
8
|
+
private url;
|
|
9
|
+
private relayer;
|
|
10
10
|
constructor(url: string | Url, wallet: WalletClient, auth: IAuth);
|
|
11
|
-
get htlcActorAddress(): string
|
|
12
|
-
initiate(order:
|
|
13
|
-
private
|
|
14
|
-
|
|
15
|
-
private _initiateOnErc20HTLC;
|
|
16
|
-
redeem(order: MatchedOrder, secret: string): AsyncResult<string, string>;
|
|
11
|
+
get htlcActorAddress(): `0x${string}`;
|
|
12
|
+
initiate(order: Order | EvmOrderResponse): AsyncResult<string, string>;
|
|
13
|
+
private initiateFromAPI;
|
|
14
|
+
redeem(order: Order, secret: string): AsyncResult<string, string>;
|
|
17
15
|
refund(): AsyncResult<string, string>;
|
|
18
16
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AsyncResult, Url, IAuth } from '@gardenfi/utils';
|
|
2
|
+
import { WalletClient } from 'viem';
|
|
3
|
+
|
|
4
|
+
export declare const initiateNative: (wallet: WalletClient, data: {
|
|
5
|
+
htlc: string;
|
|
6
|
+
redeemer: string;
|
|
7
|
+
timelock: bigint;
|
|
8
|
+
amount: bigint;
|
|
9
|
+
secretHash: string;
|
|
10
|
+
}) => AsyncResult<string, string>;
|
|
11
|
+
export declare const initiateERC20: (wallet: WalletClient, url: Url, auth: IAuth, data: {
|
|
12
|
+
htlc: string;
|
|
13
|
+
token: string;
|
|
14
|
+
orderId: string;
|
|
15
|
+
redeemer: string;
|
|
16
|
+
timelock: bigint;
|
|
17
|
+
amount: bigint;
|
|
18
|
+
secretHash: string;
|
|
19
|
+
}) => AsyncResult<string, string>;
|
|
20
|
+
export declare const executeApprovalTransaction: (wallet: WalletClient, approvalTx: {
|
|
21
|
+
to: string;
|
|
22
|
+
value: string;
|
|
23
|
+
data: string;
|
|
24
|
+
gas_limit: string;
|
|
25
|
+
}) => AsyncResult<string, string>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Order, OrderAction } from '@gardenfi/orderbook';
|
|
2
|
+
|
|
3
|
+
export declare enum CacheType {
|
|
4
|
+
OrderExecutor = "orderExecutor",
|
|
5
|
+
BitcoinRedeem = "bitcoinRedeem",
|
|
6
|
+
RefundSacp = "refundSacp"
|
|
7
|
+
}
|
|
8
|
+
export type OrderExecutorCacheValue = {
|
|
9
|
+
txHash: string;
|
|
10
|
+
timeStamp: number;
|
|
11
|
+
btcRedeemUTXO?: string;
|
|
12
|
+
};
|
|
13
|
+
export type RefundSacpCacheValue = {
|
|
14
|
+
initTxHash: string;
|
|
15
|
+
};
|
|
16
|
+
export type BitcoinRedeemCacheValue = {
|
|
17
|
+
redeemedFromUTXO: string;
|
|
18
|
+
redeemedAt: number;
|
|
19
|
+
redeemTxHash: string;
|
|
20
|
+
};
|
|
21
|
+
interface CacheOptions {
|
|
22
|
+
max?: number;
|
|
23
|
+
ttl?: number;
|
|
24
|
+
}
|
|
25
|
+
export declare class GardenCache {
|
|
26
|
+
private cache;
|
|
27
|
+
constructor(options?: CacheOptions);
|
|
28
|
+
private makeKey;
|
|
29
|
+
set<T>(type: CacheType, key: string, value: T, ttl?: number): void;
|
|
30
|
+
get<T>(type: CacheType, key: string): T | undefined;
|
|
31
|
+
remove(type: CacheType, key: string): void;
|
|
32
|
+
clear(type?: CacheType): void;
|
|
33
|
+
setBitcoinRedeem(orderId: string, data: BitcoinRedeemCacheValue, ttl?: number): void;
|
|
34
|
+
getBitcoinRedeem(orderId: string): BitcoinRedeemCacheValue | undefined;
|
|
35
|
+
setOrderExecution(order: Order, action: OrderAction | string, txHash: string, utxo?: string, ttl?: number): void;
|
|
36
|
+
getOrderExecution(order: Order, action: OrderAction | string): OrderExecutorCacheValue | undefined;
|
|
37
|
+
removeOrderExecution(order: Order, action: OrderAction | string): void;
|
|
38
|
+
private makeOrderKey;
|
|
39
|
+
setSacpCache(orderId: string, data: RefundSacpCacheValue, ttl?: number): void;
|
|
40
|
+
getSacpCache(orderId: string): RefundSacpCacheValue | undefined;
|
|
41
|
+
has(type: CacheType, key: string): boolean;
|
|
42
|
+
peek<T>(type: CacheType, key: string): T | undefined;
|
|
43
|
+
getRemainingTTL(type: CacheType, key: string): number;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DigestKey, IAuth } from '@gardenfi/utils';
|
|
2
|
+
import { GardenEventEmitter, GardenHTLCModules } from './../garden.types';
|
|
3
|
+
import { IOrderbook } from '@gardenfi/orderbook';
|
|
4
|
+
import { Api } from '../../constants';
|
|
5
|
+
|
|
6
|
+
export declare class Executor {
|
|
7
|
+
#private;
|
|
8
|
+
private htlcs;
|
|
9
|
+
private events;
|
|
10
|
+
private isBackgroundServiceRunning;
|
|
11
|
+
private stopBackgroundExecution;
|
|
12
|
+
constructor(digestKey: DigestKey, htlcs: GardenHTLCModules, orderbook: IOrderbook, auth: IAuth, api: Api, events: GardenEventEmitter);
|
|
13
|
+
private getAddressesFromHTLCs;
|
|
14
|
+
start(interval: number | undefined, redeemServiceEnabled: boolean): void;
|
|
15
|
+
stop(): void;
|
|
16
|
+
execute(interval?: number): Promise<() => void>;
|
|
17
|
+
private processOrderActions;
|
|
18
|
+
private handleRedeemAction;
|
|
19
|
+
private evmRedeem;
|
|
20
|
+
private starknetRedeem;
|
|
21
|
+
private solRedeem;
|
|
22
|
+
private suiRedeem;
|
|
23
|
+
private btcRedeem;
|
|
24
|
+
private postRefundSACP;
|
|
25
|
+
private broadcastRedeemTx;
|
|
26
|
+
}
|
|
@@ -1,67 +1,58 @@
|
|
|
1
1
|
import { ISecretManager } from './../secretManager/secretManager.types';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { IGardenJS, SwapParams, GardenConfigWithHTLCs, GardenConfigWithWallets, GardenEvents } from './garden.types';
|
|
3
|
+
import { BlockchainType, CreateOrderRequest, CreateOrderResponse, Orderbook } from '@gardenfi/orderbook';
|
|
4
|
+
import { IAuth, DigestKey, AsyncResult } from '@gardenfi/utils';
|
|
5
5
|
import { IQuote } from '../quote/quote.types';
|
|
6
|
-
import {
|
|
7
|
-
import { IEVMHTLC } from '../evm/htlc.types';
|
|
8
|
-
import { IStarknetHTLC } from '../starknet/starknetHTLC.types';
|
|
9
|
-
import { IBitcoinWallet } from '../bitcoin/wallet/wallet.interface';
|
|
10
|
-
import { ISolanaHTLC } from '../solana/htlc/ISolanaHTLC';
|
|
11
|
-
import { ISuiHTLC } from '../sui/suiHTLC.types';
|
|
6
|
+
import { Executor } from './executor/executor';
|
|
12
7
|
|
|
13
|
-
export declare class Garden extends
|
|
14
|
-
private
|
|
15
|
-
private _secretManager;
|
|
16
|
-
private _orderbook;
|
|
8
|
+
export declare class Garden extends Orderbook implements IGardenJS {
|
|
9
|
+
private network;
|
|
17
10
|
private _quote;
|
|
18
|
-
private getOrderThreshold;
|
|
19
11
|
private _auth;
|
|
20
|
-
private
|
|
21
|
-
private _blockNumberFetcher;
|
|
22
|
-
private refundSacpCache;
|
|
23
|
-
private _evmHTLC;
|
|
24
|
-
private _starknetHTLC;
|
|
25
|
-
private _solanaHTLC;
|
|
26
|
-
private _suiHTLC;
|
|
27
|
-
private _btcWallet;
|
|
28
|
-
private bitcoinRedeemCache;
|
|
29
|
-
private _digestKey;
|
|
12
|
+
private _htlcs;
|
|
30
13
|
private _api;
|
|
31
|
-
private
|
|
14
|
+
private _executor;
|
|
15
|
+
private _events;
|
|
16
|
+
/**
|
|
17
|
+
* If true, the redeem service will be enabled.
|
|
18
|
+
*/
|
|
19
|
+
private _redeemServiceEnabled;
|
|
20
|
+
private _secretManager;
|
|
21
|
+
private _digestKey;
|
|
22
|
+
private executeInterval;
|
|
32
23
|
constructor(config: GardenConfigWithHTLCs);
|
|
33
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Enables or disables the auto-redeem service provided by Garden API.
|
|
26
|
+
*
|
|
27
|
+
* If enabled, make sure to pass DigestKey to the constructor.
|
|
28
|
+
* @default true
|
|
29
|
+
* @param enabled - boolean
|
|
30
|
+
* @returns this
|
|
31
|
+
*/
|
|
32
|
+
setRedeemServiceEnabled(enabled: boolean): this;
|
|
34
33
|
static fromWallets(config: GardenConfigWithWallets): Garden;
|
|
35
|
-
get
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
get htlcs(): {
|
|
35
|
+
readonly evm: import('../..').IEVMHTLC | undefined;
|
|
36
|
+
readonly starknet: import('../..').IStarknetHTLC | undefined;
|
|
37
|
+
readonly solana: import('../..').ISolanaHTLC | undefined;
|
|
38
|
+
readonly sui: import('../sui/suiHTLC.types').ISuiHTLC | undefined;
|
|
39
|
+
readonly bitcoin: import('../bitcoin/bitcoinhtlc.types').IBitcoinHTLC | undefined;
|
|
40
|
+
};
|
|
39
41
|
get quote(): IQuote;
|
|
40
|
-
get btcWallet(): IBitcoinWallet | undefined;
|
|
41
|
-
get orderbook(): IOrderbook;
|
|
42
|
-
get blockNumberFetcher(): IBlockNumberFetcher;
|
|
43
42
|
get secretManager(): ISecretManager;
|
|
44
43
|
get auth(): IAuth;
|
|
45
|
-
get digestKey(): DigestKey;
|
|
44
|
+
get digestKey(): DigestKey | undefined;
|
|
45
|
+
get executor(): Executor | undefined;
|
|
46
|
+
get redeemServiceEnabled(): boolean;
|
|
46
47
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* @
|
|
50
|
-
* @returns MatchedOrder
|
|
48
|
+
* Creates an order for a swap operation and initiates the HTLC on the source chain.
|
|
49
|
+
* @param params SwapParams
|
|
50
|
+
* @returns AsyncResult<Order, string>
|
|
51
51
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
createSwap(params: SwapParams): AsyncResult<CreateOrderResponse | string, string>;
|
|
53
|
+
createOrder<T extends BlockchainType>(arg: CreateOrderRequest | SwapParams): AsyncResult<CreateOrderResponse<T>, string>;
|
|
54
54
|
private validateAndFillParams;
|
|
55
|
-
private
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
private solRedeem;
|
|
59
|
-
private suiRedeem;
|
|
60
|
-
private evmRedeem;
|
|
61
|
-
private starknetRedeem;
|
|
62
|
-
private btcRedeem;
|
|
63
|
-
private btcRefund;
|
|
64
|
-
private postRefundSACP;
|
|
65
|
-
private assignStatus;
|
|
66
|
-
private broadcastRedeemTx;
|
|
55
|
+
private _getAddresses;
|
|
56
|
+
on<K extends keyof GardenEvents>(event: K, listener: GardenEvents[K]): this;
|
|
57
|
+
off<K extends keyof GardenEvents>(event: K, listener: GardenEvents[K]): this;
|
|
67
58
|
}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { AsyncResult, Environment, EventBroker, IAuth, DigestKey } from '@gardenfi/utils';
|
|
1
|
+
import { AffiliateFee, AssetLike, BitcoinOrderResponse, BlockchainType, EvmOrderResponse, IOrderbook, Order, OrderAction, OrderStatus, SolanaOrderResponse, StarknetOrderResponse, SuiOrderResponse, CreateOrderResponse } from '@gardenfi/orderbook';
|
|
2
|
+
import { ApiKey, AsyncResult, IAuth, Network, DigestKey } from '@gardenfi/utils';
|
|
4
3
|
import { ISecretManager } from '../secretManager/secretManager.types';
|
|
5
4
|
import { IQuote } from '../quote/quote.types';
|
|
6
|
-
import { IBlockNumberFetcher } from '../blockNumberFetcher/blockNumber';
|
|
7
5
|
import { IEVMHTLC } from '../evm/htlc.types';
|
|
8
6
|
import { IStarknetHTLC } from '../starknet/starknetHTLC.types';
|
|
9
7
|
import { AccountInterface } from 'starknet';
|
|
10
8
|
import { WalletClient } from 'viem';
|
|
11
|
-
import { Api } from '../constants';
|
|
12
9
|
import { IBitcoinWallet } from '../bitcoin/wallet/wallet.interface';
|
|
13
10
|
import { ISolanaHTLC } from '../solana/htlc/ISolanaHTLC';
|
|
14
11
|
import { AnchorProvider } from '@coral-xyz/anchor';
|
|
12
|
+
import { Api } from '../constants';
|
|
15
13
|
import { ISuiHTLC } from '../sui/suiHTLC.types';
|
|
16
14
|
import { WalletWithRequiredFeatures } from '@mysten/wallet-standard';
|
|
15
|
+
import { IBitcoinHTLC } from '../bitcoin/bitcoinhtlc.types';
|
|
16
|
+
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
17
17
|
|
|
18
18
|
export type SwapParams = {
|
|
19
19
|
/**
|
|
20
20
|
* Asset to be sent.
|
|
21
21
|
*/
|
|
22
|
-
fromAsset:
|
|
22
|
+
fromAsset: AssetLike;
|
|
23
23
|
/**
|
|
24
24
|
* Asset to be received.
|
|
25
25
|
*/
|
|
26
|
-
toAsset:
|
|
26
|
+
toAsset: AssetLike;
|
|
27
27
|
/**
|
|
28
28
|
* Amount in lowest denomination of the sendAsset.
|
|
29
29
|
*/
|
|
@@ -33,101 +33,56 @@ export type SwapParams = {
|
|
|
33
33
|
*/
|
|
34
34
|
receiveAmount: string;
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
37
|
-
*/
|
|
38
|
-
timelock?: number;
|
|
39
|
-
/**
|
|
40
|
-
* This will wait for the specified number of confirmations before redeeming the funds.
|
|
36
|
+
* Solver ID for the order.
|
|
41
37
|
*/
|
|
42
|
-
|
|
38
|
+
solverId: string;
|
|
43
39
|
/**
|
|
44
|
-
*
|
|
40
|
+
* Slippage for the order.
|
|
45
41
|
*/
|
|
46
|
-
|
|
42
|
+
slippage?: number;
|
|
47
43
|
/**
|
|
48
|
-
*
|
|
44
|
+
* Addresses for the order.
|
|
49
45
|
*/
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Get strategy id from the quote
|
|
53
|
-
*/
|
|
54
|
-
strategyId: string;
|
|
55
|
-
/**
|
|
56
|
-
* Provide btcAddress if the destination or source chain is bitcoin. This address is used as refund address if source chain is bitcoin, and as redeem address if destination chain is bitcoin.
|
|
57
|
-
*/
|
|
58
|
-
btcAddress?: string;
|
|
59
|
-
};
|
|
46
|
+
addresses?: Partial<Record<BlockchainType, string>>;
|
|
60
47
|
/**
|
|
61
48
|
* Integrator fee for the order.
|
|
62
49
|
*/
|
|
63
|
-
affiliateFee?:
|
|
50
|
+
affiliateFee?: AffiliateFee[];
|
|
64
51
|
};
|
|
65
|
-
export type OrderWithStatus =
|
|
52
|
+
export type OrderWithStatus = Order & {
|
|
66
53
|
status: OrderStatus;
|
|
67
54
|
};
|
|
68
55
|
export type GardenEvents = {
|
|
69
|
-
error: (order:
|
|
70
|
-
success: (order:
|
|
56
|
+
error: (order: Order, error: string) => void;
|
|
57
|
+
success: (order: Order, action: OrderAction, result: string) => void;
|
|
71
58
|
onPendingOrdersChanged: (orders: OrderWithStatus[]) => void;
|
|
72
59
|
log: (id: string, message: string) => void;
|
|
73
|
-
rbf: (order:
|
|
60
|
+
rbf: (order: Order, result: string) => void;
|
|
61
|
+
};
|
|
62
|
+
export type GardenEventEmitter = {
|
|
63
|
+
emit: <K extends keyof GardenEvents>(event: K, ...args: Parameters<GardenEvents[K]>) => void;
|
|
74
64
|
};
|
|
75
65
|
export type EventCallback = (...args: any[]) => void;
|
|
76
66
|
/**
|
|
77
67
|
* Interface representing the GardenJS library.
|
|
78
68
|
*/
|
|
79
|
-
export interface IGardenJS extends
|
|
69
|
+
export interface IGardenJS extends IOrderbook {
|
|
80
70
|
/**
|
|
81
71
|
* Create Order
|
|
82
72
|
* @param {SwapParams} params - The parameters for creating the order.
|
|
83
|
-
* @returns {AsyncResult<
|
|
84
|
-
*/
|
|
85
|
-
swap(params: SwapParams): AsyncResult<MatchedOrder, string>;
|
|
86
|
-
/**
|
|
87
|
-
* Execute an action.
|
|
88
|
-
* @returns {Promise<() => void>} A promise that resolves to a function to cancel the execution.
|
|
89
|
-
*/
|
|
90
|
-
execute(): Promise<() => void>;
|
|
91
|
-
/**
|
|
92
|
-
* The EVM relay.
|
|
93
|
-
* @readonly
|
|
73
|
+
* @returns {AsyncResult<string, string>} The result of the swap operation.
|
|
94
74
|
*/
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* The Starknet relay.
|
|
98
|
-
* @readonly
|
|
99
|
-
*/
|
|
100
|
-
get starknetHTLC(): IStarknetHTLC | undefined;
|
|
101
|
-
/**
|
|
102
|
-
* The Solana relay.
|
|
103
|
-
* @readonly
|
|
104
|
-
*/
|
|
105
|
-
get solanaHTLC(): ISolanaHTLC | undefined;
|
|
106
|
-
/**
|
|
107
|
-
* The Sui relay.
|
|
108
|
-
* @readonly
|
|
109
|
-
*/
|
|
110
|
-
get suiHTLC(): ISuiHTLC | undefined;
|
|
75
|
+
createSwap(params: SwapParams): AsyncResult<CreateOrderResponse | string, string>;
|
|
111
76
|
/**
|
|
112
77
|
* The current quote.
|
|
113
78
|
* @readonly
|
|
114
79
|
*/
|
|
115
80
|
get quote(): IQuote;
|
|
116
81
|
/**
|
|
117
|
-
*
|
|
82
|
+
* All HTLC modules at once.
|
|
118
83
|
* @readonly
|
|
119
84
|
*/
|
|
120
|
-
get
|
|
121
|
-
/**
|
|
122
|
-
* The orderbook.
|
|
123
|
-
* @readonly
|
|
124
|
-
*/
|
|
125
|
-
get orderbook(): IOrderbook;
|
|
126
|
-
/**
|
|
127
|
-
* The block number fetcher.
|
|
128
|
-
* @readonly
|
|
129
|
-
*/
|
|
130
|
-
get blockNumberFetcher(): IBlockNumberFetcher;
|
|
85
|
+
get htlcs(): GardenHTLCModules;
|
|
131
86
|
/**
|
|
132
87
|
* The secret manager.
|
|
133
88
|
* @readonly
|
|
@@ -142,7 +97,20 @@ export interface IGardenJS extends EventBroker<GardenEvents> {
|
|
|
142
97
|
* The digest key.
|
|
143
98
|
* @readonly
|
|
144
99
|
*/
|
|
145
|
-
get digestKey(): DigestKey;
|
|
100
|
+
get digestKey(): DigestKey | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* The redeem service enabled.
|
|
103
|
+
* @readonly
|
|
104
|
+
*/
|
|
105
|
+
get redeemServiceEnabled(): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* The events.
|
|
108
|
+
*/
|
|
109
|
+
on<K extends keyof GardenEvents>(event: K, listener: GardenEvents[K]): this;
|
|
110
|
+
/**
|
|
111
|
+
* The events.
|
|
112
|
+
*/
|
|
113
|
+
off<K extends keyof GardenEvents>(event: K, listener: GardenEvents[K]): this;
|
|
146
114
|
}
|
|
147
115
|
export type OrderCacheValue = {
|
|
148
116
|
txHash: string;
|
|
@@ -150,51 +118,50 @@ export type OrderCacheValue = {
|
|
|
150
118
|
btcRedeemUTXO?: string;
|
|
151
119
|
};
|
|
152
120
|
export interface IOrderExecutorCache {
|
|
153
|
-
set(order:
|
|
154
|
-
get(order:
|
|
155
|
-
remove(order:
|
|
121
|
+
set(order: Order, action: OrderAction, txHash: string, utxo?: string): void;
|
|
122
|
+
get(order: Order, action: OrderAction): OrderCacheValue | null;
|
|
123
|
+
remove(order: Order, action: OrderAction): void;
|
|
156
124
|
}
|
|
157
|
-
export type ApiConfig =
|
|
158
|
-
|
|
125
|
+
export type ApiConfig = Network | (Partial<Api> & {
|
|
126
|
+
network: Network;
|
|
159
127
|
});
|
|
160
128
|
export type GardenCoreConfig = {
|
|
161
129
|
environment: ApiConfig;
|
|
162
|
-
|
|
130
|
+
apiKey: string | ApiKey;
|
|
131
|
+
digestKey?: string | DigestKey;
|
|
163
132
|
secretManager?: ISecretManager;
|
|
164
133
|
auth?: IAuth;
|
|
165
134
|
orderbook?: IOrderbook;
|
|
166
135
|
quote?: IQuote;
|
|
167
|
-
blockNumberFetcher?: IBlockNumberFetcher;
|
|
168
|
-
btcWallet?: IBitcoinWallet;
|
|
169
136
|
solanaProgramAddress?: {
|
|
170
137
|
native?: string;
|
|
171
138
|
spl?: string;
|
|
172
139
|
};
|
|
173
140
|
};
|
|
174
141
|
export type GardenHTLCModules = {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
};
|
|
142
|
+
evm?: IEVMHTLC;
|
|
143
|
+
starknet?: IStarknetHTLC;
|
|
144
|
+
solana?: ISolanaHTLC;
|
|
145
|
+
sui?: ISuiHTLC;
|
|
146
|
+
bitcoin?: IBitcoinHTLC;
|
|
181
147
|
};
|
|
182
148
|
export type GardenWalletModules = {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
149
|
+
evm?: WalletClient;
|
|
150
|
+
starknet?: AccountInterface;
|
|
151
|
+
solana?: AnchorProvider;
|
|
152
|
+
sui?: WalletWithRequiredFeatures | Ed25519Keypair;
|
|
153
|
+
bitcoin?: IBitcoinWallet;
|
|
154
|
+
};
|
|
155
|
+
export type GardenConfigWithWallets = GardenCoreConfig & {
|
|
156
|
+
wallets?: GardenWalletModules;
|
|
157
|
+
};
|
|
158
|
+
export type GardenConfigWithHTLCs = GardenCoreConfig & {
|
|
159
|
+
htlc?: GardenHTLCModules;
|
|
160
|
+
};
|
|
161
|
+
export type ResponseTypeMap = {
|
|
162
|
+
[BlockchainType.evm]: EvmOrderResponse;
|
|
163
|
+
[BlockchainType.bitcoin]: BitcoinOrderResponse;
|
|
164
|
+
[BlockchainType.starknet]: StarknetOrderResponse;
|
|
165
|
+
[BlockchainType.solana]: SolanaOrderResponse;
|
|
166
|
+
[BlockchainType.sui]: SuiOrderResponse;
|
|
189
167
|
};
|
|
190
|
-
export type GardenConfigWithWallets = GardenCoreConfig & GardenWalletModules;
|
|
191
|
-
export type GardenConfigWithHTLCs = GardenCoreConfig & GardenHTLCModules;
|
|
192
|
-
/**
|
|
193
|
-
* Actions that can be performed on the order.
|
|
194
|
-
*/
|
|
195
|
-
export declare enum OrderActions {
|
|
196
|
-
Idle = "Idle",
|
|
197
|
-
Initiate = "Initiate",
|
|
198
|
-
Redeem = "Redeem",
|
|
199
|
-
Refund = "Refund"
|
|
200
|
-
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { Err, Ok, Request as UtilsRequest } from '@gardenfi/utils';
|
|
2
|
-
import { IQuote, QuoteParamsForAssets, QuoteResponse
|
|
1
|
+
import { Err, IAuth, Ok, Request as UtilsRequest } from '@gardenfi/utils';
|
|
2
|
+
import { IQuote, QuoteParamsForAssets, QuoteResponse } from './quote.types';
|
|
3
|
+
import { AssetLike } from '@gardenfi/orderbook';
|
|
3
4
|
|
|
4
5
|
export declare class Quote implements IQuote {
|
|
5
6
|
private quoteUrl;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
private auth;
|
|
8
|
+
constructor(quoteUrl: string, auth: IAuth);
|
|
9
|
+
getQuoteFromAssets({ fromAsset, toAsset, amount, isExactOut, options, }: QuoteParamsForAssets): Promise<Err<string> | Ok<QuoteResponse[]>>;
|
|
10
|
+
getQuote(from: AssetLike, to: AssetLike, amount: number, isExactOut?: boolean, options?: {
|
|
9
11
|
affiliateFee?: number;
|
|
10
12
|
request?: UtilsRequest;
|
|
11
|
-
}): Promise<Err<string> | Ok<QuoteResponse>>;
|
|
12
|
-
getStrategies(): Promise<Err<string> | Ok<Strategies>>;
|
|
13
|
+
}): Promise<Err<string> | Ok<QuoteResponse[]>>;
|
|
13
14
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Asset, Chain } from '@gardenfi/orderbook';
|
|
1
|
+
import { Asset, AssetLike, Chain, ChainAsset } from '@gardenfi/orderbook';
|
|
2
2
|
import { APIResponse, AsyncResult, Request } from '@gardenfi/utils';
|
|
3
3
|
|
|
4
4
|
export interface IQuote {
|
|
@@ -12,7 +12,7 @@ export interface IQuote {
|
|
|
12
12
|
* @param options { affiliateFee?: number; request?: Request } - The options for the quote request, affiliate fee in bps and request object
|
|
13
13
|
*
|
|
14
14
|
*/
|
|
15
|
-
getQuoteFromAssets(params: QuoteParamsForAssets): AsyncResult<QuoteResponse, string>;
|
|
15
|
+
getQuoteFromAssets(params: QuoteParamsForAssets): AsyncResult<QuoteResponse[], string>;
|
|
16
16
|
/**
|
|
17
17
|
* Get a quote for the given orderpair and amount
|
|
18
18
|
* @param orderpair - A string representing the order pair for which the quote is requested.
|
|
@@ -24,12 +24,7 @@ export interface IQuote {
|
|
|
24
24
|
* @param isExactOut - Whether the amount is exact out
|
|
25
25
|
* @param options { affiliateFee?: number; request?: Request } - The options for the quote request, affiliate fee in bps and request object
|
|
26
26
|
*/
|
|
27
|
-
getQuote(
|
|
28
|
-
/**
|
|
29
|
-
* Get the strategies available for quoting
|
|
30
|
-
* @returns {Strategies} The strategies available
|
|
31
|
-
*/
|
|
32
|
-
getStrategies(): AsyncResult<Strategies, string>;
|
|
27
|
+
getQuote(from: AssetLike, to: AssetLike, amount: number, isExactOut: boolean, options?: QuoteOptions): AsyncResult<QuoteResponse[], string>;
|
|
33
28
|
}
|
|
34
29
|
export type QuoteOptions = {
|
|
35
30
|
affiliateFee?: number;
|
|
@@ -45,14 +40,27 @@ export type QuoteParamsForAssets = BaseQuoteParams & {
|
|
|
45
40
|
toAsset: Asset;
|
|
46
41
|
};
|
|
47
42
|
export type QuoteParamsForOrderPair = BaseQuoteParams & {
|
|
48
|
-
|
|
43
|
+
from: ChainAsset;
|
|
44
|
+
to: ChainAsset;
|
|
49
45
|
};
|
|
50
46
|
export type QuoteResponse = {
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
source: {
|
|
48
|
+
asset: string;
|
|
49
|
+
amount: string;
|
|
50
|
+
display: string;
|
|
51
|
+
value: string;
|
|
53
52
|
};
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
destination: {
|
|
54
|
+
asset: string;
|
|
55
|
+
amount: string;
|
|
56
|
+
display: string;
|
|
57
|
+
value: string;
|
|
58
|
+
};
|
|
59
|
+
solver_id: string;
|
|
60
|
+
estimated_time: number;
|
|
61
|
+
slippage: number;
|
|
62
|
+
fee: number;
|
|
63
|
+
fixed_fee: string;
|
|
56
64
|
};
|
|
57
65
|
export type Strategies = Record<string, {
|
|
58
66
|
id: string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AsyncResult, IAuth, Url } from '@gardenfi/utils';
|
|
2
|
+
|
|
3
|
+
export declare class Relayer {
|
|
4
|
+
private auth;
|
|
5
|
+
private url;
|
|
6
|
+
constructor(auth: IAuth, url: string | Url);
|
|
7
|
+
initiate(orderId: string, signature: string | string[]): AsyncResult<string, string>;
|
|
8
|
+
redeem(orderId: string, secret: string): AsyncResult<string, string>;
|
|
9
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Order, SolanaOrderResponse } from '@gardenfi/orderbook';
|
|
2
2
|
import { AsyncResult } from '@gardenfi/utils';
|
|
3
3
|
|
|
4
4
|
export interface ISolanaHTLC {
|
|
@@ -11,18 +11,18 @@ export interface ISolanaHTLC {
|
|
|
11
11
|
* @param order - The matched order.
|
|
12
12
|
* @returns A promise resolving to the transaction hash of the initiation.
|
|
13
13
|
*/
|
|
14
|
-
initiate(order:
|
|
14
|
+
initiate(order: Order | SolanaOrderResponse): AsyncResult<string, string>;
|
|
15
15
|
/**
|
|
16
16
|
* Redeems funds from the HTLC contract to the actor's address.
|
|
17
17
|
* @param order - The matched order.
|
|
18
18
|
* @param secret - The secret required to unlock the htlc.
|
|
19
19
|
* @returns A promise resolving to the transaction hash of the redemption.
|
|
20
20
|
*/
|
|
21
|
-
redeem(order:
|
|
21
|
+
redeem(order: Order, secret: string): AsyncResult<string, string>;
|
|
22
22
|
/**
|
|
23
23
|
* Refunds funds from the HTLC contract back to the actor's address upon expiration.
|
|
24
24
|
* @param order - The matched order.
|
|
25
25
|
* @returns A promise resolving to the transaction hash of the refund.
|
|
26
26
|
*/
|
|
27
|
-
refund(order:
|
|
27
|
+
refund(order: Order): AsyncResult<string, string>;
|
|
28
28
|
}
|