@mento-protocol/mento-sdk 1.0.1 → 1.0.3

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,6 +1,6 @@
1
- import { Address, TradingLimit, TradingLimitsConfig, TradingLimitsState } from './interfaces';
2
1
  import { IBroker } from '@mento-protocol/mento-core-ts';
3
2
  import { BigNumber, BigNumberish, Signer, providers } from 'ethers';
3
+ import { Address, TradingLimit, TradingLimitsConfig, TradingLimitsState } from './interfaces';
4
4
  export interface Exchange {
5
5
  providerAddr: Address;
6
6
  id: string;
@@ -10,9 +10,19 @@ export interface Asset {
10
10
  address: Address;
11
11
  symbol: string;
12
12
  }
13
+ export interface TradablePair {
14
+ id: string;
15
+ assets: [Asset, Asset];
16
+ path: Array<{
17
+ providerAddr: Address;
18
+ id: string;
19
+ assets: [Address, Address];
20
+ }>;
21
+ }
13
22
  export declare class Mento {
14
23
  private readonly signerOrProvider;
15
24
  private readonly broker;
25
+ private readonly router;
16
26
  private exchanges;
17
27
  /**
18
28
  * This constructor is private, use the static create or createWithParams methods
@@ -37,7 +47,7 @@ export declare class Mento {
37
47
  * @param exchanges the exchanges data for the broker
38
48
  * @returns a new Mento object instance
39
49
  */
40
- static createWithParams(signerOrProvider: Signer | providers.Provider, brokerAddr: Address, exchanges?: Exchange[]): Mento;
50
+ static createWithParams(signerOrProvider: Signer | providers.Provider, brokerAddr: Address, routerAddr: Address, exchanges?: Exchange[]): Mento;
41
51
  /**
42
52
  * Returns a new Mento instance connected to the given signer
43
53
  * @param signer an ethers signer
@@ -45,58 +55,124 @@ export declare class Mento {
45
55
  */
46
56
  connectSigner(signer: Signer): Mento;
47
57
  /**
48
- * Returns a list of all the pairs that can be traded on Mento
49
- * @returns The list of tradeable pairs in the form of [{address, symbol}]
58
+ * Get tradable pairs for backwards compatibility
59
+ * @returns an array of Asset pairs
60
+ */
61
+ getTradablePairs(options?: {
62
+ cached?: boolean;
63
+ }): Promise<[Asset, Asset][]>;
64
+ /**
65
+ * Returns a list of all tradable pairs on Mento via direct exchanges.
66
+ * Each pair is represented using the TradablePair interface, with its id
67
+ * (a concatenation of the two asset symbols in alphabetical order),
68
+ * the two Asset objects, and a path (an array with a single direct exchange hop).
69
+ * @returns An array of direct TradablePair objects.
50
70
  */
51
- getTradeablePairs(): Promise<[Asset, Asset][]>;
71
+ getDirectPairs(): Promise<TradablePair[]>;
52
72
  /**
53
- * Returns the amount of tokenIn to be sold to buy amountOut of tokenOut
73
+ * Returns a list of all tradable pairs on Mento, including those achievable
74
+ * via two-hop routes. For two-hop pairs, the path will contain two exchange hops.
75
+ * Each TradablePair contains an id (the concatenation of the two asset symbols in alphabetical order),
76
+ * the two Asset objects, and an array of exchange details for each hop.
77
+ * @returns An array of TradablePair objects representing available trade routes.
78
+ */
79
+ getTradablePairsWithPath(options?: {
80
+ cached?: boolean;
81
+ }): Promise<readonly TradablePair[]>;
82
+ /**
83
+ * Returns the amount of tokenIn to be sold to buy amountOut of tokenOut.
84
+ * If the provided tradablePair has a single (direct) pricing path, then direct pricing is used.
85
+ * Otherwise, routed pricing via the MentoRouter is applied.
54
86
  * @param tokenIn the token to be sold
55
87
  * @param tokenOut the token to be bought
56
- * @param amountOut the amount of tokenOut to be bought
88
+ * @param amountOut the desired amount of tokenOut to be obtained
89
+ * @param tradablePair the TradablePair object containing the pricing path information
57
90
  * @returns the amount of tokenIn to be sold
58
91
  */
59
- getAmountIn(tokenIn: Address, tokenOut: Address, amountOut: BigNumberish): Promise<BigNumber>;
92
+ getAmountIn(tokenIn: Address, tokenOut: Address, amountOut: BigNumberish, tradablePair?: TradablePair): Promise<BigNumber>;
60
93
  /**
61
- * Returns the amount of tokenOut to be bought by selling amountIn of tokenIn
94
+ * Returns the amount of tokenOut to be bought by selling amountIn of tokenIn.
95
+ * If the provided tradablePair has a single (direct) pricing path, then direct pricing is used.
96
+ * Otherwise, routed pricing via the MentoRouter is applied.
62
97
  * @param tokenIn the token to be sold
63
98
  * @param tokenOut the token to be bought
64
99
  * @param amountIn the amount of tokenIn to be sold
100
+ * @param tradablePair the TradablePair object containing the pricing path information
65
101
  * @returns the amount of tokenOut to be bought
66
102
  */
67
- getAmountOut(tokenIn: Address, tokenOut: Address, amountIn: BigNumberish): Promise<BigNumber>;
103
+ getAmountOut(tokenIn: Address, tokenOut: Address, amountIn: BigNumberish, tradablePair?: TradablePair): Promise<BigNumber>;
104
+ /**
105
+ * Internal method for direct pricing: retrieves the exchange for the given tokens
106
+ * and returns the amountIn using the broker.
107
+ */
108
+ private getAmountInDirect;
109
+ /**
110
+ * Internal method for direct pricing: retrieves the exchange for the given tokens
111
+ * and returns the amountOut using the broker.
112
+ */
113
+ private getAmountOutDirect;
114
+ /**
115
+ * Internal method for routed pricing: uses the MentoRouter to determine the required tokenIn
116
+ * for obtaining amountOut through a multi-hop route specified in tradablePair.path.
117
+ */
118
+ private getAmountInRouted;
119
+ /**
120
+ * Internal method for routed pricing: uses the MentoRouter to determine the amountOut
121
+ * obtainable by selling amountIn through a multi-hop route specified in tradablePair.path.
122
+ */
123
+ private getAmountOutRouted;
68
124
  /**
69
125
  * Increases the broker's trading allowance for the given token
70
126
  * @param token the token to increase the allowance for
71
127
  * @param amount the amount to increase the allowance by
72
128
  * @returns the populated TransactionRequest object
73
129
  */
74
- increaseTradingAllowance(token: Address, amount: BigNumberish): Promise<providers.TransactionRequest>;
130
+ increaseTradingAllowance(tokenIn: Address, amount: BigNumberish, tradablePair?: TradablePair): Promise<providers.TransactionRequest>;
75
131
  /**
76
- * Returns a token swap populated tx object with a fixed amount of tokenIn and a minimum amount of tokenOut
77
- * Submitting the transaction to execute the swap is left to the consumer
132
+ * Returns a token swap populated tx object with a fixed amount of tokenIn and a minimum amount of tokenOut.
133
+ * If the tradablePair contains a single-hop route, a direct swap is executed using swapExactTokensForTokens on the broker.
134
+ * Otherwise, a routed swap is executed via the router.
78
135
  * @param tokenIn the token to be sold
79
136
  * @param tokenOut the token to be bought
80
137
  * @param amountIn the amount of tokenIn to be sold
81
138
  * @param amountOutMin the minimum amount of tokenOut to be bought
139
+ * @param tradablePair the tradable pair details to determine routing
82
140
  * @returns the populated TransactionRequest object
83
141
  */
84
- swapIn(tokenIn: Address, tokenOut: Address, amountIn: BigNumberish, amountOutMin: BigNumberish): Promise<providers.TransactionRequest>;
142
+ swapIn(tokenIn: Address, tokenOut: Address, amountIn: BigNumberish, amountOutMin: BigNumberish, tradablePair?: TradablePair): Promise<providers.TransactionRequest>;
143
+ private swapInDirect;
144
+ private swapInRouted;
85
145
  /**
86
- * Returns a token swap populated tx object with a maximum amount of tokenIn and a fixed amount of tokenOut
87
- * Submitting the transaction to execute the swap is left to the consumer
146
+ * Returns a token swap populated tx object with a maximum amount of tokenIn and a fixed amount of tokenOut.
147
+ * If the tradablePair contains a single-hop route, a direct swap is executed using swapTokensForExactTokens on the broker.
148
+ * Otherwise, a routed swap is executed via the router.
88
149
  * @param tokenIn the token to be sold
89
150
  * @param tokenOut the token to be bought
90
151
  * @param amountOut the amount of tokenOut to be bought
91
152
  * @param amountInMax the maximum amount of tokenIn to be sold
92
153
  * @returns the populated TransactionRequest object
93
154
  */
94
- swapOut(tokenIn: Address, tokenOut: Address, amountOut: BigNumberish, amountInMax: BigNumberish): Promise<providers.TransactionRequest>;
155
+ swapOut(tokenIn: Address, tokenOut: Address, amountOut: BigNumberish, amountInMax: BigNumberish, tradablePair?: TradablePair): Promise<providers.TransactionRequest>;
156
+ private swapOutDirect;
157
+ private swapOutRouted;
158
+ /**
159
+ * Helper method to build the steps for a routed swap, ensuring proper token ordering
160
+ * through the path segments
161
+ */
162
+ private buildSteps;
95
163
  /**
96
164
  * Returns the mento instance's broker contract
97
165
  * @returns broker contract
98
166
  */
99
167
  getBroker(): IBroker;
168
+ /**
169
+ * Finds a tradable pair for the given input and output tokens
170
+ * @param tokenIn the input token address
171
+ * @param tokenOut the output token address
172
+ * @returns the tradable pair containing the path between the tokens
173
+ * @throws if no path is found between the tokens
174
+ */
175
+ findPairForTokens(tokenIn: Address, tokenOut: Address): Promise<TradablePair>;
100
176
  /**
101
177
  * Returns the list of exchanges available in Mento (cached)
102
178
  * @returns the list of exchanges