@xchainjs/xchain-aggregator 0.2.0 → 0.2.2

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.
@@ -1,15 +1,14 @@
1
1
  import { Asset, Chain } from '@xchainjs/xchain-util';
2
- import { Wallet } from '@xchainjs/xchain-wallet';
3
- import { IProtocol, QuoteSwap, QuoteSwapParams, SwapHistory, TxSubmitted } from '../../types';
2
+ import { IProtocol, ProtocolConfig, QuoteSwap, QuoteSwapParams, SwapHistory, TxSubmitted } from '../../types';
4
3
  /**
5
4
  * Chainflip protocol
6
5
  */
7
6
  export declare class ChainflipProtocol implements IProtocol {
8
7
  readonly name = "Chainflip";
9
8
  private sdk;
10
- private wallet;
9
+ private wallet?;
11
10
  private assetsData;
12
- constructor(wallet?: Wallet);
11
+ constructor(configuration?: ProtocolConfig);
13
12
  /**
14
13
  * Check if an asset is supported in the protocol
15
14
  * @param {Asset} asset Asset to check if it is supported
@@ -1,3 +1 @@
1
- export { MayachainProtocol } from './mayachain';
2
- export { ThorchainProtocol } from './thorchain';
3
- export { ChainflipProtocol } from './chainflip';
1
+ export { ProtocolFactory } from './protocolFactory';
@@ -1,11 +1,11 @@
1
1
  import { Asset, Chain } from '@xchainjs/xchain-util';
2
- import { Wallet } from '@xchainjs/xchain-wallet';
3
- import { IProtocol, QuoteSwap, QuoteSwapParams, SwapHistory, SwapHistoryParams, TxSubmitted } from '../../types';
2
+ import { IProtocol, ProtocolConfig, QuoteSwap, QuoteSwapParams, SwapHistory, SwapHistoryParams, TxSubmitted } from '../../types';
4
3
  export declare class MayachainProtocol implements IProtocol {
5
- readonly name: "Mayachain";
4
+ readonly name = "Mayachain";
6
5
  private mayachainQuery;
7
6
  private mayachainAmm;
8
- constructor(wallet?: Wallet);
7
+ private configuration;
8
+ constructor(configuration?: ProtocolConfig);
9
9
  /**
10
10
  * Check if an asset is supported in the protocol
11
11
  * @param {Asset} asset Asset to check if it is supported
@@ -0,0 +1,4 @@
1
+ import { Config, IProtocol, Protocol } from '../types';
2
+ export declare class ProtocolFactory {
3
+ static getProtocol(name: Protocol, configuration: Config): IProtocol;
4
+ }
@@ -1,11 +1,11 @@
1
1
  import { Asset, Chain } from '@xchainjs/xchain-util';
2
- import { Wallet } from '@xchainjs/xchain-wallet';
3
- import { IProtocol, QuoteSwap, QuoteSwapParams, SwapHistory, SwapHistoryParams, TxSubmitted } from '../../types';
2
+ import { IProtocol, ProtocolConfig, QuoteSwap, QuoteSwapParams, SwapHistory, SwapHistoryParams, TxSubmitted } from '../../types';
4
3
  export declare class ThorchainProtocol implements IProtocol {
5
- readonly name: "Thorchain";
4
+ readonly name = "Thorchain";
6
5
  private thorchainQuery;
7
6
  private thorchainAmm;
8
- constructor(wallet?: Wallet);
7
+ private configuration;
8
+ constructor(configuration?: ProtocolConfig);
9
9
  /**
10
10
  * Check if an asset is supported in the protocol
11
11
  * @param {Asset} asset Asset to check if it is supported
package/lib/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { TxHash } from '@xchainjs/xchain-client';
2
2
  import { Address, Asset, Chain, CryptoAmount } from '@xchainjs/xchain-util';
3
+ import { Wallet } from '@xchainjs/xchain-wallet';
3
4
  /**
4
5
  * TxSubmitted
5
6
  */
@@ -15,7 +16,48 @@ type Fees = {
15
16
  affiliateFee: CryptoAmount;
16
17
  outboundFee: CryptoAmount;
17
18
  };
19
+ /**
20
+ * Protocols supported by the Aggregator
21
+ */
18
22
  type Protocol = 'Thorchain' | 'Mayachain' | 'Chainflip';
23
+ /**
24
+ * Affiliate config for the aggregator
25
+ */
26
+ type AffiliateConfig = {
27
+ /**
28
+ * Basis points for the affiliate fee calculation. Value must be between 0 and 10000
29
+ */
30
+ basisPoints: number;
31
+ /**
32
+ * Affiliate address by protocol. ThorNames and MayaNames are supported for Thorchain and Mayachain protocols
33
+ */
34
+ affiliates: Partial<Record<Protocol, string>>;
35
+ };
36
+ /**
37
+ * Aggregator config
38
+ */
39
+ export type Config = Partial<{
40
+ /**
41
+ * List of protocols to enable. Undefined value means all protocols enabled
42
+ */
43
+ protocols: Protocol[];
44
+ /**
45
+ * Affiliate config
46
+ */
47
+ affiliate: AffiliateConfig;
48
+ /**
49
+ * Wallet
50
+ */
51
+ wallet: Wallet;
52
+ }>;
53
+ /**
54
+ * Protocol config
55
+ */
56
+ export type ProtocolConfig = Partial<{
57
+ wallet: Wallet;
58
+ affiliateBps: number;
59
+ affiliateAddress: string;
60
+ }>;
19
61
  /**
20
62
  * Represents a quote for a swap operation.
21
63
  */
@@ -43,8 +85,6 @@ type QuoteSwapParams = {
43
85
  destinationAddress?: string;
44
86
  height?: number;
45
87
  toleranceBps?: number;
46
- affiliateBps?: number;
47
- affiliateAddress?: string;
48
88
  };
49
89
  type SwapHistoryParams = {
50
90
  chainAddresses: {
@@ -69,7 +109,7 @@ type SwapHistory = {
69
109
  swaps: SwapResume[];
70
110
  };
71
111
  interface IProtocol {
72
- name: string;
112
+ name: Protocol;
73
113
  isAssetSupported(asset: Asset): Promise<boolean>;
74
114
  getSupportedChains(): Promise<Chain[]>;
75
115
  estimateSwap(params: QuoteSwapParams): Promise<QuoteSwap>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xchainjs/xchain-aggregator",
3
3
  "description": "Protocol aggregator to make actions in different protocols",
4
- "version": "0.2.0",
4
+ "version": "0.2.2",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
7
7
  "module": "lib/index.esm.js",
@@ -30,22 +30,22 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@chainflip/sdk": "1.3.0",
33
- "@xchainjs/xchain-client": "0.16.7",
34
- "@xchainjs/xchain-mayachain": "1.0.10",
35
- "@xchainjs/xchain-mayachain-amm": "2.0.9",
36
- "@xchainjs/xchain-mayachain-query": "0.1.16",
37
- "@xchainjs/xchain-thorchain": "1.1.0",
38
- "@xchainjs/xchain-thorchain-amm": "1.1.14",
39
- "@xchainjs/xchain-thorchain-query": "0.7.14",
40
- "@xchainjs/xchain-util": "0.13.6",
41
- "@xchainjs/xchain-wallet": "0.1.18"
33
+ "@xchainjs/xchain-client": "0.16.8",
34
+ "@xchainjs/xchain-mayachain": "1.0.11",
35
+ "@xchainjs/xchain-mayachain-amm": "2.0.11",
36
+ "@xchainjs/xchain-mayachain-query": "0.1.18",
37
+ "@xchainjs/xchain-thorchain": "1.1.1",
38
+ "@xchainjs/xchain-thorchain-amm": "1.1.16",
39
+ "@xchainjs/xchain-thorchain-query": "0.7.15",
40
+ "@xchainjs/xchain-util": "0.13.7",
41
+ "@xchainjs/xchain-wallet": "0.1.19"
42
42
  },
43
43
  "devDependencies": {
44
- "@xchainjs/xchain-avax": "0.5.5",
45
- "@xchainjs/xchain-binance": "5.7.16",
46
- "@xchainjs/xchain-bitcoin": "0.23.18",
47
- "@xchainjs/xchain-ethereum": "0.32.5",
48
- "@xchainjs/xchain-kujira": "0.1.20",
44
+ "@xchainjs/xchain-avax": "0.5.6",
45
+ "@xchainjs/xchain-binance": "5.7.17",
46
+ "@xchainjs/xchain-bitcoin": "0.23.19",
47
+ "@xchainjs/xchain-ethereum": "0.32.6",
48
+ "@xchainjs/xchain-kujira": "0.1.21",
49
49
  "axios": "1.3.6",
50
50
  "axios-mock-adapter": "1.20.0"
51
51
  }