@mento-protocol/mento-sdk 1.0.1 → 2.0.0-beta.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.
Files changed (196) hide show
  1. package/README.md +124 -8
  2. package/dist/abis/bipoolmanager.d.ts +15 -0
  3. package/dist/abis/bipoolmanager.d.ts.map +1 -0
  4. package/dist/abis/bipoolmanager.js +26 -0
  5. package/dist/abis/bipoolmanager.js.map +1 -0
  6. package/dist/abis/broker.d.ts +2 -0
  7. package/dist/abis/broker.d.ts.map +1 -0
  8. package/dist/abis/broker.js +8 -0
  9. package/dist/abis/broker.js.map +1 -0
  10. package/dist/abis/erc20.d.ts +2 -0
  11. package/dist/abis/erc20.d.ts.map +1 -0
  12. package/dist/abis/erc20.js +11 -0
  13. package/dist/abis/erc20.js.map +1 -0
  14. package/dist/abis/index.d.ts +4 -0
  15. package/dist/abis/index.d.ts.map +1 -0
  16. package/dist/{cjs → abis}/index.js +4 -5
  17. package/dist/abis/index.js.map +1 -0
  18. package/dist/abis/pricingmodule.d.ts +2 -0
  19. package/dist/abis/pricingmodule.d.ts.map +1 -0
  20. package/dist/abis/pricingmodule.js +5 -0
  21. package/dist/abis/pricingmodule.js.map +1 -0
  22. package/dist/abis/reserve.d.ts +2 -0
  23. package/dist/abis/reserve.d.ts.map +1 -0
  24. package/dist/abis/reserve.js +9 -0
  25. package/dist/abis/reserve.js.map +1 -0
  26. package/dist/adapters/implementations/ethersAdapter.d.ts +10 -0
  27. package/dist/adapters/implementations/ethersAdapter.d.ts.map +1 -0
  28. package/dist/adapters/implementations/ethersAdapter.js +22 -0
  29. package/dist/adapters/implementations/ethersAdapter.js.map +1 -0
  30. package/dist/adapters/implementations/ethersV5Adapter.d.ts +10 -0
  31. package/dist/adapters/implementations/ethersV5Adapter.d.ts.map +1 -0
  32. package/dist/adapters/implementations/ethersV5Adapter.js +22 -0
  33. package/dist/adapters/implementations/ethersV5Adapter.js.map +1 -0
  34. package/dist/adapters/implementations/viemAdapter.d.ts +10 -0
  35. package/dist/adapters/implementations/viemAdapter.d.ts.map +1 -0
  36. package/dist/adapters/implementations/viemAdapter.js +29 -0
  37. package/dist/adapters/implementations/viemAdapter.js.map +1 -0
  38. package/dist/adapters/index.d.ts +5 -0
  39. package/dist/adapters/index.d.ts.map +1 -0
  40. package/dist/adapters/index.js +10 -0
  41. package/dist/adapters/index.js.map +1 -0
  42. package/dist/adapters/proxies/ethersAdapterProxy.d.ts +27 -0
  43. package/dist/adapters/proxies/ethersAdapterProxy.d.ts.map +1 -0
  44. package/dist/adapters/proxies/ethersAdapterProxy.js +77 -0
  45. package/dist/adapters/proxies/ethersAdapterProxy.js.map +1 -0
  46. package/dist/adapters/proxies/ethersV5AdapterProxy.d.ts +27 -0
  47. package/dist/adapters/proxies/ethersV5AdapterProxy.d.ts.map +1 -0
  48. package/dist/adapters/proxies/ethersV5AdapterProxy.js +77 -0
  49. package/dist/adapters/proxies/ethersV5AdapterProxy.js.map +1 -0
  50. package/dist/adapters/proxies/viemAdapterProxy.d.ts +28 -0
  51. package/dist/adapters/proxies/viemAdapterProxy.d.ts.map +1 -0
  52. package/dist/adapters/proxies/viemAdapterProxy.js +77 -0
  53. package/dist/adapters/proxies/viemAdapterProxy.js.map +1 -0
  54. package/dist/constants/addresses.d.ts +14 -0
  55. package/dist/constants/addresses.d.ts.map +1 -0
  56. package/dist/{cjs/constants → constants}/addresses.js +14 -25
  57. package/dist/constants/addresses.js.map +1 -0
  58. package/dist/constants/chainId.d.ts +5 -0
  59. package/dist/constants/chainId.d.ts.map +1 -0
  60. package/dist/{cjs/enums → constants}/chainId.js +2 -2
  61. package/dist/constants/chainId.js.map +1 -0
  62. package/dist/constants/contractNames.d.ts +21 -0
  63. package/dist/constants/contractNames.d.ts.map +1 -0
  64. package/dist/constants/contractNames.js +24 -0
  65. package/dist/constants/contractNames.js.map +1 -0
  66. package/dist/constants/index.d.ts +6 -0
  67. package/dist/constants/index.d.ts.map +1 -0
  68. package/dist/{cjs/interfaces → constants}/index.js +6 -4
  69. package/dist/constants/index.js.map +1 -0
  70. package/dist/{cjs/enums → constants}/proposalState.d.ts +1 -0
  71. package/dist/constants/proposalState.d.ts.map +1 -0
  72. package/dist/{cjs/enums → constants}/proposalState.js +2 -1
  73. package/dist/constants/proposalState.js.map +1 -0
  74. package/dist/constants/stableTokenMetadata.d.ts +13 -0
  75. package/dist/constants/stableTokenMetadata.d.ts.map +1 -0
  76. package/dist/constants/stableTokenMetadata.js +30 -0
  77. package/dist/constants/stableTokenMetadata.js.map +1 -0
  78. package/dist/index.d.ts +67 -0
  79. package/dist/index.d.ts.map +1 -0
  80. package/dist/index.js +122 -0
  81. package/dist/index.js.map +1 -0
  82. package/dist/services/collateralAssetService.d.ts +8 -0
  83. package/dist/services/collateralAssetService.d.ts.map +1 -0
  84. package/dist/services/collateralAssetService.js +44 -0
  85. package/dist/services/collateralAssetService.js.map +1 -0
  86. package/dist/services/exchangeService.d.ts +18 -0
  87. package/dist/services/exchangeService.d.ts.map +1 -0
  88. package/dist/services/exchangeService.js +78 -0
  89. package/dist/services/exchangeService.js.map +1 -0
  90. package/dist/services/index.d.ts +3 -0
  91. package/dist/services/index.d.ts.map +1 -0
  92. package/dist/{cjs/enums → services}/index.js +3 -2
  93. package/dist/services/index.js.map +1 -0
  94. package/dist/services/stableTokenService.d.ts +8 -0
  95. package/dist/services/stableTokenService.d.ts.map +1 -0
  96. package/dist/services/stableTokenService.js +35 -0
  97. package/dist/services/stableTokenService.js.map +1 -0
  98. package/dist/services/tokenMetadataService.d.ts +8 -0
  99. package/dist/services/tokenMetadataService.d.ts.map +1 -0
  100. package/dist/services/tokenMetadataService.js +45 -0
  101. package/dist/services/tokenMetadataService.js.map +1 -0
  102. package/dist/{esm/types → types}/contractAddresses.d.ts +1 -0
  103. package/dist/types/contractAddresses.d.ts.map +1 -0
  104. package/dist/{cjs/types → types}/contractAddresses.js +1 -0
  105. package/dist/types/contractAddresses.js.map +1 -0
  106. package/dist/types/exchange.d.ts +12 -0
  107. package/dist/types/exchange.d.ts.map +1 -0
  108. package/dist/{cjs/interfaces/tradingLimit.js → types/exchange.js} +1 -0
  109. package/dist/types/exchange.js.map +1 -0
  110. package/dist/types/index.d.ts +5 -0
  111. package/dist/types/index.d.ts.map +1 -0
  112. package/dist/{cjs/types → types}/index.js +4 -1
  113. package/dist/types/index.js.map +1 -0
  114. package/dist/types/provider.d.ts +12 -0
  115. package/dist/types/provider.d.ts.map +1 -0
  116. package/dist/{cjs/interfaces/tradingLimitsConfig.js → types/provider.js} +1 -0
  117. package/dist/types/provider.js.map +1 -0
  118. package/dist/types/token.d.ts +12 -0
  119. package/dist/types/token.d.ts.map +1 -0
  120. package/dist/{cjs/interfaces/IChainClient.js → types/token.js} +1 -0
  121. package/dist/types/token.js.map +1 -0
  122. package/dist/utils/index.d.ts +2 -0
  123. package/dist/utils/index.d.ts.map +1 -0
  124. package/dist/{cjs/constants → utils}/index.js +2 -1
  125. package/dist/utils/index.js.map +1 -0
  126. package/dist/utils/retry.d.ts +12 -0
  127. package/dist/utils/retry.d.ts.map +1 -0
  128. package/dist/utils/retry.js +28 -0
  129. package/dist/utils/retry.js.map +1 -0
  130. package/package.json +32 -43
  131. package/dist/cjs/ChainClient.d.ts +0 -9
  132. package/dist/cjs/ChainClient.js +0 -58
  133. package/dist/cjs/TestChainClient.d.ts +0 -7
  134. package/dist/cjs/TestChainClient.js +0 -41
  135. package/dist/cjs/constants/addresses.d.ts +0 -2
  136. package/dist/cjs/constants/index.d.ts +0 -1
  137. package/dist/cjs/enums/chainId.d.ts +0 -5
  138. package/dist/cjs/enums/index.d.ts +0 -2
  139. package/dist/cjs/governance.d.ts +0 -62
  140. package/dist/cjs/governance.js +0 -151
  141. package/dist/cjs/index.d.ts +0 -5
  142. package/dist/cjs/interfaces/IChainClient.d.ts +0 -6
  143. package/dist/cjs/interfaces/index.d.ts +0 -4
  144. package/dist/cjs/interfaces/tradingLimit.d.ts +0 -7
  145. package/dist/cjs/interfaces/tradingLimitsConfig.d.ts +0 -10
  146. package/dist/cjs/interfaces/tradingLimitsState.d.ts +0 -9
  147. package/dist/cjs/interfaces/tradingLimitsState.js +0 -2
  148. package/dist/cjs/limits.d.ts +0 -33
  149. package/dist/cjs/limits.js +0 -130
  150. package/dist/cjs/mento.d.ts +0 -152
  151. package/dist/cjs/mento.js +0 -318
  152. package/dist/cjs/types/contractAddressMap.d.ts +0 -4
  153. package/dist/cjs/types/contractAddressMap.js +0 -2
  154. package/dist/cjs/types/contractAddresses.d.ts +0 -22
  155. package/dist/cjs/types/index.d.ts +0 -2
  156. package/dist/cjs/utils.d.ts +0 -36
  157. package/dist/cjs/utils.js +0 -98
  158. package/dist/esm/ChainClient.d.ts +0 -9
  159. package/dist/esm/ChainClient.js +0 -54
  160. package/dist/esm/TestChainClient.d.ts +0 -7
  161. package/dist/esm/TestChainClient.js +0 -37
  162. package/dist/esm/constants/addresses.d.ts +0 -2
  163. package/dist/esm/constants/addresses.js +0 -69
  164. package/dist/esm/constants/index.d.ts +0 -1
  165. package/dist/esm/constants/index.js +0 -1
  166. package/dist/esm/enums/chainId.d.ts +0 -5
  167. package/dist/esm/enums/chainId.js +0 -6
  168. package/dist/esm/enums/index.d.ts +0 -2
  169. package/dist/esm/enums/index.js +0 -2
  170. package/dist/esm/enums/proposalState.d.ts +0 -10
  171. package/dist/esm/enums/proposalState.js +0 -11
  172. package/dist/esm/governance.d.ts +0 -62
  173. package/dist/esm/governance.js +0 -147
  174. package/dist/esm/index.d.ts +0 -5
  175. package/dist/esm/index.js +0 -5
  176. package/dist/esm/interfaces/IChainClient.d.ts +0 -6
  177. package/dist/esm/interfaces/IChainClient.js +0 -1
  178. package/dist/esm/interfaces/index.d.ts +0 -4
  179. package/dist/esm/interfaces/index.js +0 -4
  180. package/dist/esm/interfaces/tradingLimit.d.ts +0 -7
  181. package/dist/esm/interfaces/tradingLimit.js +0 -1
  182. package/dist/esm/interfaces/tradingLimitsConfig.d.ts +0 -10
  183. package/dist/esm/interfaces/tradingLimitsConfig.js +0 -1
  184. package/dist/esm/interfaces/tradingLimitsState.d.ts +0 -9
  185. package/dist/esm/interfaces/tradingLimitsState.js +0 -1
  186. package/dist/esm/limits.d.ts +0 -33
  187. package/dist/esm/limits.js +0 -123
  188. package/dist/esm/mento.d.ts +0 -152
  189. package/dist/esm/mento.js +0 -314
  190. package/dist/esm/types/contractAddressMap.d.ts +0 -4
  191. package/dist/esm/types/contractAddressMap.js +0 -1
  192. package/dist/esm/types/contractAddresses.js +0 -1
  193. package/dist/esm/types/index.d.ts +0 -2
  194. package/dist/esm/types/index.js +0 -2
  195. package/dist/esm/utils.d.ts +0 -36
  196. package/dist/esm/utils.js +0 -90
@@ -1,130 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getLimitId = exports.getLimits = exports.getLimitsState = exports.getLimitsConfig = void 0;
13
- const assert_1 = require("assert");
14
- const ethers_1 = require("ethers");
15
- /**
16
- * Returns the limit configuration in the broker for the given exchange and asset
17
- * @param broker an instance of the broker
18
- * @param exchangeId the id of the exchange
19
- * @param asset the address of the limited asset
20
- * @returns the limit configuration
21
- */
22
- function getLimitsConfig(broker, exchangeId, asset) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- const limitId = getLimitId(exchangeId, asset);
25
- const cfg = yield broker.tradingLimitsConfig(limitId);
26
- return {
27
- asset,
28
- timestep0: cfg['timestep0'],
29
- timestep1: cfg['timestep1'],
30
- limit0: cfg['limit0'],
31
- limit1: cfg['limit1'],
32
- limitGlobal: cfg['limitGlobal'],
33
- flags: cfg['flags'],
34
- };
35
- });
36
- }
37
- exports.getLimitsConfig = getLimitsConfig;
38
- /**
39
- * Returns the limit state in the broker for the given exchange and asset
40
- * @param broker an instance of the broker
41
- * @param exchangeId the id of the exchange
42
- * @param asset the address of the limited asset
43
- * @returns the limit state
44
- */
45
- function getLimitsState(broker, exchangeId, asset) {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- const limitId = getLimitId(exchangeId, asset);
48
- const [cfg, state] = yield Promise.all([
49
- getLimitsConfig(broker, exchangeId, asset),
50
- broker.tradingLimitsState(limitId),
51
- ]);
52
- const isL0Enabled = cfg.timestep0 > 0;
53
- const isL1Enabled = cfg.timestep1 > 0;
54
- const nowEpoch = Math.floor(Date.now() / 1000);
55
- const isL0Outdated = isL0Enabled && nowEpoch > state['lastUpdated0'] + cfg.timestep0;
56
- const isL1Outdated = isL1Enabled && nowEpoch > state['lastUpdated1'] + cfg.timestep1;
57
- return {
58
- asset,
59
- lastUpdated0: isL0Outdated ? nowEpoch : state['lastUpdated0'],
60
- lastUpdated1: isL1Outdated ? nowEpoch : state['lastUpdated1'],
61
- netflow0: isL0Outdated ? 0 : state['netflow0'],
62
- netflow1: isL1Outdated ? 0 : state['netflow1'],
63
- netflowGlobal: state['netflowGlobal'],
64
- };
65
- });
66
- }
67
- exports.getLimitsState = getLimitsState;
68
- /**
69
- * Returns a human-friendly representation of the limits for the given exchange and asset
70
- * @param broker an instance of the broker
71
- * @param exchangeId the id of the exchange
72
- * @param asset the address of the asset with the limit
73
- * @returns a list of TradingLimit objects
74
- */
75
- function getLimits(broker, exchangeId, asset) {
76
- return __awaiter(this, void 0, void 0, function* () {
77
- const [cfg, state] = yield Promise.all([
78
- getLimitsConfig(broker, exchangeId, asset),
79
- getLimitsState(broker, exchangeId, asset),
80
- ]);
81
- const limits = [];
82
- if (cfg.limit0 > 0) {
83
- limits.push({
84
- asset: asset,
85
- maxIn: cfg.limit0 - state.netflow0,
86
- maxOut: cfg.limit0 + state.netflow0,
87
- until: state.lastUpdated0 + cfg.timestep0,
88
- });
89
- }
90
- if (cfg.limit1 > 0) {
91
- limits.push({
92
- asset: asset,
93
- maxIn: cfg.limit1 - state.netflow1,
94
- maxOut: cfg.limit1 + state.netflow1,
95
- until: state.lastUpdated1 + cfg.timestep1,
96
- });
97
- }
98
- if (cfg.limitGlobal > 0) {
99
- const timestampIn2030 = 1893456000; // a far away timestamp
100
- limits.push({
101
- asset: asset,
102
- maxIn: cfg.limitGlobal - state.netflowGlobal,
103
- maxOut: cfg.limitGlobal + state.netflowGlobal,
104
- until: timestampIn2030,
105
- });
106
- }
107
- // Limits with a smaller timeframe are restricted by the ones with a larger one
108
- // e.g: if maxIn is 0 in LG, it should also be 0 in L1 and L0
109
- for (let i = limits.length - 1; i > 0; i--) {
110
- limits[i - 1].maxIn = Math.min(limits[i - 1].maxIn, limits[i].maxIn);
111
- limits[i - 1].maxOut = Math.min(limits[i - 1].maxOut, limits[i].maxOut);
112
- }
113
- return limits;
114
- });
115
- }
116
- exports.getLimits = getLimits;
117
- /**
118
- * Returns the limit id for the given exchange and asset
119
- * @param exchangeId the id of the exchange
120
- * @param asset the address of the asset with the limit
121
- * @returns the limit id
122
- */
123
- function getLimitId(exchangeId, asset) {
124
- const assetBytes32 = ethers_1.utils.zeroPad(asset, 32);
125
- const exchangeIdBytes = ethers_1.utils.arrayify(exchangeId);
126
- const assetBytes = ethers_1.utils.arrayify(assetBytes32);
127
- (0, assert_1.strict)(exchangeIdBytes.length === assetBytes.length, 'exchangeId and asset0 must be the same length');
128
- return ethers_1.utils.hexlify(exchangeIdBytes.map((b, i) => b ^ assetBytes[i]));
129
- }
130
- exports.getLimitId = getLimitId;
@@ -1,152 +0,0 @@
1
- import { Address, TradingLimit, TradingLimitsConfig, TradingLimitsState } from './interfaces';
2
- import { IBroker } from '@mento-protocol/mento-core-ts';
3
- import { BigNumber, BigNumberish, Signer, providers } from 'ethers';
4
- export interface Exchange {
5
- providerAddr: Address;
6
- id: string;
7
- assets: Address[];
8
- }
9
- export interface Asset {
10
- address: Address;
11
- symbol: string;
12
- }
13
- export declare class Mento {
14
- private readonly signerOrProvider;
15
- private readonly broker;
16
- private exchanges;
17
- /**
18
- * This constructor is private, use the static create or createWithParams methods
19
- * to create a new Mento instance
20
- * @param signerOrProvider an ethers provider or connected signer
21
- * @param brokerAddress the address of the broker contract
22
- * @param exchanges exchange data for the broker
23
- */
24
- private constructor();
25
- /**
26
- * Creates a new Mento object instance.
27
- * When constructed with only a Provider only read-only operations are supported
28
- * @param signerOrProvider an ethers signer or provider. A signer is required to execute swaps
29
- * @returns a new Mento object instance
30
- */
31
- static create(signerOrProvider: Signer | providers.Provider): Promise<Mento>;
32
- /**
33
- * Create a new Mento object instance given a broker address and optional exchanges data
34
- * When constructed with a Provider, only read-only operations are supported
35
- * @param signerOrProvider an ethers signer or provider. A signer is required to execute swaps
36
- * @param brokerAddr the address of the broker contract
37
- * @param exchanges the exchanges data for the broker
38
- * @returns a new Mento object instance
39
- */
40
- static createWithParams(signerOrProvider: Signer | providers.Provider, brokerAddr: Address, exchanges?: Exchange[]): Mento;
41
- /**
42
- * Returns a new Mento instance connected to the given signer
43
- * @param signer an ethers signer
44
- * @returns new Mento object instance
45
- */
46
- connectSigner(signer: Signer): Mento;
47
- /**
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}]
50
- */
51
- getTradeablePairs(): Promise<[Asset, Asset][]>;
52
- /**
53
- * Returns the amount of tokenIn to be sold to buy amountOut of tokenOut
54
- * @param tokenIn the token to be sold
55
- * @param tokenOut the token to be bought
56
- * @param amountOut the amount of tokenOut to be bought
57
- * @returns the amount of tokenIn to be sold
58
- */
59
- getAmountIn(tokenIn: Address, tokenOut: Address, amountOut: BigNumberish): Promise<BigNumber>;
60
- /**
61
- * Returns the amount of tokenOut to be bought by selling amountIn of tokenIn
62
- * @param tokenIn the token to be sold
63
- * @param tokenOut the token to be bought
64
- * @param amountIn the amount of tokenIn to be sold
65
- * @returns the amount of tokenOut to be bought
66
- */
67
- getAmountOut(tokenIn: Address, tokenOut: Address, amountIn: BigNumberish): Promise<BigNumber>;
68
- /**
69
- * Increases the broker's trading allowance for the given token
70
- * @param token the token to increase the allowance for
71
- * @param amount the amount to increase the allowance by
72
- * @returns the populated TransactionRequest object
73
- */
74
- increaseTradingAllowance(token: Address, amount: BigNumberish): Promise<providers.TransactionRequest>;
75
- /**
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
78
- * @param tokenIn the token to be sold
79
- * @param tokenOut the token to be bought
80
- * @param amountIn the amount of tokenIn to be sold
81
- * @param amountOutMin the minimum amount of tokenOut to be bought
82
- * @returns the populated TransactionRequest object
83
- */
84
- swapIn(tokenIn: Address, tokenOut: Address, amountIn: BigNumberish, amountOutMin: BigNumberish): Promise<providers.TransactionRequest>;
85
- /**
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
88
- * @param tokenIn the token to be sold
89
- * @param tokenOut the token to be bought
90
- * @param amountOut the amount of tokenOut to be bought
91
- * @param amountInMax the maximum amount of tokenIn to be sold
92
- * @returns the populated TransactionRequest object
93
- */
94
- swapOut(tokenIn: Address, tokenOut: Address, amountOut: BigNumberish, amountInMax: BigNumberish): Promise<providers.TransactionRequest>;
95
- /**
96
- * Returns the mento instance's broker contract
97
- * @returns broker contract
98
- */
99
- getBroker(): IBroker;
100
- /**
101
- * Returns the list of exchanges available in Mento (cached)
102
- * @returns the list of exchanges
103
- */
104
- getExchanges(): Promise<Exchange[]>;
105
- /**
106
- * Returns the list of exchanges for a given exchange provider address
107
- * @returns list of exchanges
108
- */
109
- getExchangesForProvider(exchangeProviderAddr: Address): Promise<Exchange[]>;
110
- /**
111
- * Returns the Mento exchange (if any) for a given pair of tokens
112
- * @param token0 the address of the first token
113
- * @param token1 the address of the second token
114
- * @returns exchange
115
- */
116
- getExchangeForTokens(token0: Address, token1: Address): Promise<Exchange>;
117
- /**
118
- * Returns the Mento exchange for a given exchange id
119
- * @param exchangeId the id of the exchange
120
- * @returns the exchange with the given id
121
- */
122
- getExchangeById(exchangeId: string): Promise<Exchange>;
123
- /**
124
- * Returns whether trading is enabled in the given mode for a given exchange id
125
- * @param exchangeId the id of the exchange
126
- * @param mode the trading mode
127
- * @returns true if trading is enabled in the given mode, false otherwise
128
- */
129
- isTradingEnabled(exchangeId: string): Promise<boolean>;
130
- /**
131
- * Return the trading limits for a given exchange id. Each limit is an object with the following fields:
132
- * asset: the address of the asset with the limit
133
- * maxIn: the maximum amount of the asset that can be sold
134
- * maxOut: the maximum amount of the asset that can be bought
135
- * until: the timestamp until which the limit is valid
136
- * @param exchangeId the id of the exchange
137
- * @returns the list of trading limits
138
- */
139
- getTradingLimits(exchangeId: string): Promise<TradingLimit[]>;
140
- /**
141
- * Returns the trading limits configurations for a given exchange id
142
- * @param exchangeId the id of the exchange
143
- * @returns the trading limits configuration
144
- */
145
- getTradingLimitConfig(exchangeId: string): Promise<TradingLimitsConfig[]>;
146
- /**
147
- * Returns the trading limits state for a given exchange id
148
- * @param exchangeId the id of the exchange
149
- * @returns the trading limits state
150
- */
151
- getTradingLimitState(exchangeId: string): Promise<TradingLimitsState[]>;
152
- }
package/dist/cjs/mento.js DELETED
@@ -1,318 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Mento = void 0;
13
- const mento_core_ts_1 = require("@mento-protocol/mento-core-ts");
14
- const ethers_1 = require("ethers");
15
- const utils_1 = require("./utils");
16
- const limits_1 = require("./limits");
17
- const assert_1 = require("assert");
18
- class Mento {
19
- /**
20
- * This constructor is private, use the static create or createWithParams methods
21
- * to create a new Mento instance
22
- * @param signerOrProvider an ethers provider or connected signer
23
- * @param brokerAddress the address of the broker contract
24
- * @param exchanges exchange data for the broker
25
- */
26
- constructor(signerOrProvider, brokerAddress, exchanges) {
27
- this.signerOrProvider = signerOrProvider;
28
- this.broker = mento_core_ts_1.IBroker__factory.connect(brokerAddress, signerOrProvider);
29
- this.exchanges = exchanges || [];
30
- }
31
- /**
32
- * Creates a new Mento object instance.
33
- * When constructed with only a Provider only read-only operations are supported
34
- * @param signerOrProvider an ethers signer or provider. A signer is required to execute swaps
35
- * @returns a new Mento object instance
36
- */
37
- static create(signerOrProvider) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- (0, utils_1.validateSignerOrProvider)(signerOrProvider);
40
- return new Mento(signerOrProvider, yield (0, utils_1.getBrokerAddressFromRegistry)(signerOrProvider));
41
- });
42
- }
43
- /**
44
- * Create a new Mento object instance given a broker address and optional exchanges data
45
- * When constructed with a Provider, only read-only operations are supported
46
- * @param signerOrProvider an ethers signer or provider. A signer is required to execute swaps
47
- * @param brokerAddr the address of the broker contract
48
- * @param exchanges the exchanges data for the broker
49
- * @returns a new Mento object instance
50
- */
51
- static createWithParams(signerOrProvider, brokerAddr, exchanges) {
52
- (0, utils_1.validateSignerOrProvider)(signerOrProvider);
53
- return new Mento(signerOrProvider, brokerAddr, exchanges);
54
- }
55
- /**
56
- * Returns a new Mento instance connected to the given signer
57
- * @param signer an ethers signer
58
- * @returns new Mento object instance
59
- */
60
- connectSigner(signer) {
61
- (0, utils_1.validateSigner)(signer);
62
- return new Mento(signer, this.broker.address, this.exchanges);
63
- }
64
- /**
65
- * Returns a list of all the pairs that can be traded on Mento
66
- * @returns The list of tradeable pairs in the form of [{address, symbol}]
67
- */
68
- getTradeablePairs() {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- const exchanges = yield this.getExchanges();
71
- const pairs = [];
72
- for (const exchange of exchanges) {
73
- const asset0 = exchange.assets[0];
74
- const asset1 = exchange.assets[1];
75
- const symbols = yield Promise.all([
76
- (0, utils_1.getSymbolFromTokenAddress)(asset0, this.signerOrProvider),
77
- (0, utils_1.getSymbolFromTokenAddress)(asset1, this.signerOrProvider),
78
- ]);
79
- pairs.push([
80
- { address: asset0, symbol: symbols[0] },
81
- { address: asset1, symbol: symbols[1] },
82
- ]);
83
- }
84
- return pairs;
85
- });
86
- }
87
- /**
88
- * Returns the amount of tokenIn to be sold to buy amountOut of tokenOut
89
- * @param tokenIn the token to be sold
90
- * @param tokenOut the token to be bought
91
- * @param amountOut the amount of tokenOut to be bought
92
- * @returns the amount of tokenIn to be sold
93
- */
94
- getAmountIn(tokenIn, tokenOut, amountOut) {
95
- return __awaiter(this, void 0, void 0, function* () {
96
- const exchange = yield this.getExchangeForTokens(tokenIn, tokenOut);
97
- return this.broker.getAmountIn(exchange.providerAddr, exchange.id, tokenIn, tokenOut, amountOut);
98
- });
99
- }
100
- /**
101
- * Returns the amount of tokenOut to be bought by selling amountIn of tokenIn
102
- * @param tokenIn the token to be sold
103
- * @param tokenOut the token to be bought
104
- * @param amountIn the amount of tokenIn to be sold
105
- * @returns the amount of tokenOut to be bought
106
- */
107
- getAmountOut(tokenIn, tokenOut, amountIn) {
108
- return __awaiter(this, void 0, void 0, function* () {
109
- const exchange = yield this.getExchangeForTokens(tokenIn, tokenOut);
110
- return this.broker.getAmountOut(exchange.providerAddr, exchange.id, tokenIn, tokenOut, amountIn);
111
- });
112
- }
113
- /**
114
- * Increases the broker's trading allowance for the given token
115
- * @param token the token to increase the allowance for
116
- * @param amount the amount to increase the allowance by
117
- * @returns the populated TransactionRequest object
118
- */
119
- increaseTradingAllowance(token, amount) {
120
- return __awaiter(this, void 0, void 0, function* () {
121
- const spender = this.broker.address;
122
- const tx = yield (0, utils_1.increaseAllowance)(token, spender, amount, this.signerOrProvider);
123
- if (ethers_1.Signer.isSigner(this.signerOrProvider)) {
124
- // The contract call doesn't populate all of the signer fields, so we need an extra call for the signer
125
- return this.signerOrProvider.populateTransaction(tx);
126
- }
127
- else {
128
- return tx;
129
- }
130
- });
131
- }
132
- /**
133
- * Returns a token swap populated tx object with a fixed amount of tokenIn and a minimum amount of tokenOut
134
- * Submitting the transaction to execute the swap is left to the consumer
135
- * @param tokenIn the token to be sold
136
- * @param tokenOut the token to be bought
137
- * @param amountIn the amount of tokenIn to be sold
138
- * @param amountOutMin the minimum amount of tokenOut to be bought
139
- * @returns the populated TransactionRequest object
140
- */
141
- swapIn(tokenIn, tokenOut, amountIn, amountOutMin) {
142
- return __awaiter(this, void 0, void 0, function* () {
143
- const exchange = yield this.getExchangeForTokens(tokenIn, tokenOut);
144
- const tx = yield this.broker.populateTransaction.swapIn(exchange.providerAddr, exchange.id, tokenIn, tokenOut, amountIn, amountOutMin);
145
- if (ethers_1.Signer.isSigner(this.signerOrProvider)) {
146
- // The contract call doesn't populate all of the signer fields, so we need an extra call for the signer
147
- return this.signerOrProvider.populateTransaction(tx);
148
- }
149
- else {
150
- return tx;
151
- }
152
- });
153
- }
154
- /**
155
- * Returns a token swap populated tx object with a maximum amount of tokenIn and a fixed amount of tokenOut
156
- * Submitting the transaction to execute the swap is left to the consumer
157
- * @param tokenIn the token to be sold
158
- * @param tokenOut the token to be bought
159
- * @param amountOut the amount of tokenOut to be bought
160
- * @param amountInMax the maximum amount of tokenIn to be sold
161
- * @returns the populated TransactionRequest object
162
- */
163
- swapOut(tokenIn, tokenOut, amountOut, amountInMax) {
164
- return __awaiter(this, void 0, void 0, function* () {
165
- const exchange = yield this.getExchangeForTokens(tokenIn, tokenOut);
166
- const tx = yield this.broker.populateTransaction.swapOut(exchange.providerAddr, exchange.id, tokenIn, tokenOut, amountOut, amountInMax);
167
- if (ethers_1.Signer.isSigner(this.signerOrProvider)) {
168
- // The contract call doesn't populate all of the signer fields, so we need an extra call for the signer
169
- return this.signerOrProvider.populateTransaction(tx);
170
- }
171
- else {
172
- return tx;
173
- }
174
- });
175
- }
176
- /**
177
- * Returns the mento instance's broker contract
178
- * @returns broker contract
179
- */
180
- getBroker() {
181
- return this.broker;
182
- }
183
- /**
184
- * Returns the list of exchanges available in Mento (cached)
185
- * @returns the list of exchanges
186
- */
187
- getExchanges() {
188
- return __awaiter(this, void 0, void 0, function* () {
189
- if (this.exchanges.length > 0) {
190
- return this.exchanges;
191
- }
192
- const exchangeProvidersAddresses = yield this.broker.getExchangeProviders();
193
- const exchanges = (yield Promise.all(exchangeProvidersAddresses.map((a) => this.getExchangesForProvider(a)))).flat();
194
- this.exchanges = exchanges;
195
- return exchanges;
196
- });
197
- }
198
- /**
199
- * Returns the list of exchanges for a given exchange provider address
200
- * @returns list of exchanges
201
- */
202
- getExchangesForProvider(exchangeProviderAddr) {
203
- return __awaiter(this, void 0, void 0, function* () {
204
- const exchangeProvider = mento_core_ts_1.IExchangeProvider__factory.connect(exchangeProviderAddr, this.signerOrProvider);
205
- const exchangesInProvider = yield exchangeProvider.getExchanges();
206
- return exchangesInProvider.map((e) => {
207
- (0, assert_1.strict)(e.assets.length === 2, 'Exchange must have 2 assets');
208
- return {
209
- providerAddr: exchangeProviderAddr,
210
- id: e.exchangeId,
211
- assets: e.assets,
212
- };
213
- });
214
- });
215
- }
216
- /**
217
- * Returns the Mento exchange (if any) for a given pair of tokens
218
- * @param token0 the address of the first token
219
- * @param token1 the address of the second token
220
- * @returns exchange
221
- */
222
- getExchangeForTokens(token0, token1) {
223
- return __awaiter(this, void 0, void 0, function* () {
224
- const exchanges = (yield this.getExchanges()).filter((e) => e.assets.includes(token0) && e.assets.includes(token1));
225
- if (exchanges.length === 0) {
226
- throw Error(`No exchange found for ${token0} and ${token1}`);
227
- }
228
- (0, assert_1.strict)(exchanges.length === 1, `More than one exchange found for ${token0} and ${token1}`);
229
- return exchanges[0];
230
- });
231
- }
232
- /**
233
- * Returns the Mento exchange for a given exchange id
234
- * @param exchangeId the id of the exchange
235
- * @returns the exchange with the given id
236
- */
237
- getExchangeById(exchangeId) {
238
- return __awaiter(this, void 0, void 0, function* () {
239
- const exchanges = (yield this.getExchanges()).filter((e) => e.id === exchangeId);
240
- if (exchanges.length === 0) {
241
- throw Error(`No exchange found for id ${exchangeId}`);
242
- }
243
- (0, assert_1.strict)(exchanges.length === 1, `More than one exchange found with id ${exchangeId}`);
244
- return exchanges[0];
245
- });
246
- }
247
- /**
248
- * Returns whether trading is enabled in the given mode for a given exchange id
249
- * @param exchangeId the id of the exchange
250
- * @param mode the trading mode
251
- * @returns true if trading is enabled in the given mode, false otherwise
252
- */
253
- isTradingEnabled(exchangeId) {
254
- return __awaiter(this, void 0, void 0, function* () {
255
- const exchange = yield this.getExchangeById(exchangeId);
256
- const biPoolManager = mento_core_ts_1.BiPoolManager__factory.connect(exchange.providerAddr, this.signerOrProvider);
257
- const [breakerBoxAddr, exchangeConfig] = yield Promise.all([
258
- biPoolManager.breakerBox(),
259
- biPoolManager.getPoolExchange(exchangeId),
260
- ]);
261
- const breakerBox = mento_core_ts_1.IBreakerBox__factory.connect(breakerBoxAddr, this.signerOrProvider);
262
- const currentMode = yield breakerBox.getRateFeedTradingMode(exchangeConfig.config.referenceRateFeedID);
263
- const BI_DIRECTIONAL_TRADING_MODE = 0;
264
- return currentMode == BI_DIRECTIONAL_TRADING_MODE;
265
- });
266
- }
267
- /**
268
- * Return the trading limits for a given exchange id. Each limit is an object with the following fields:
269
- * asset: the address of the asset with the limit
270
- * maxIn: the maximum amount of the asset that can be sold
271
- * maxOut: the maximum amount of the asset that can be bought
272
- * until: the timestamp until which the limit is valid
273
- * @param exchangeId the id of the exchange
274
- * @returns the list of trading limits
275
- */
276
- getTradingLimits(exchangeId) {
277
- return __awaiter(this, void 0, void 0, function* () {
278
- const exchange = yield this.getExchangeById(exchangeId);
279
- const broker = mento_core_ts_1.Broker__factory.connect(this.broker.address, this.signerOrProvider);
280
- const asset0Limits = yield (0, limits_1.getLimits)(broker, exchangeId, exchange.assets[0]);
281
- const asset1Limits = yield (0, limits_1.getLimits)(broker, exchangeId, exchange.assets[1]);
282
- return asset0Limits.concat(asset1Limits);
283
- });
284
- }
285
- /**
286
- * Returns the trading limits configurations for a given exchange id
287
- * @param exchangeId the id of the exchange
288
- * @returns the trading limits configuration
289
- */
290
- getTradingLimitConfig(exchangeId) {
291
- return __awaiter(this, void 0, void 0, function* () {
292
- const exchange = yield this.getExchangeById(exchangeId);
293
- const broker = mento_core_ts_1.Broker__factory.connect(this.broker.address, this.signerOrProvider);
294
- const cfgs = [];
295
- for (const asset of exchange.assets) {
296
- const limitCfg = yield (0, limits_1.getLimitsConfig)(broker, exchangeId, asset);
297
- const isLimitConfigured = limitCfg.flags > 0;
298
- if (isLimitConfigured) {
299
- cfgs.push(limitCfg);
300
- }
301
- }
302
- return cfgs;
303
- });
304
- }
305
- /**
306
- * Returns the trading limits state for a given exchange id
307
- * @param exchangeId the id of the exchange
308
- * @returns the trading limits state
309
- */
310
- getTradingLimitState(exchangeId) {
311
- return __awaiter(this, void 0, void 0, function* () {
312
- const broker = mento_core_ts_1.Broker__factory.connect(this.broker.address, this.signerOrProvider);
313
- const configuredLimitCfgs = yield this.getTradingLimitConfig(exchangeId);
314
- return yield Promise.all(configuredLimitCfgs.map((cfg) => __awaiter(this, void 0, void 0, function* () { return yield (0, limits_1.getLimitsState)(broker, exchangeId, cfg.asset); })));
315
- });
316
- }
317
- }
318
- exports.Mento = Mento;
@@ -1,4 +0,0 @@
1
- import { ContractAddresses } from '.';
2
- export type ContractAddressMap = {
3
- [chainId: number]: ContractAddresses;
4
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,22 +0,0 @@
1
- export type ContractAddresses = {
2
- GovernanceFactory: string;
3
- Airgrab: string;
4
- Emission: string;
5
- MentoGovernor: string;
6
- MentoToken: string;
7
- TimelockController: string;
8
- Locking: string;
9
- Broker: string;
10
- BiPoolManager: string;
11
- BreakerBox: string;
12
- Reserve: string;
13
- ConstantSumPricingModule: string;
14
- ConstantProductPricingModule: string;
15
- MedianDeltaBreaker: string;
16
- ValueDeltaBreaker: string;
17
- StableToken: string;
18
- StableTokenEUR: string;
19
- StableTokenBRL: string;
20
- StableTokenXOF: string;
21
- SortedOracles: string;
22
- };
@@ -1,2 +0,0 @@
1
- export * from './contractAddresses';
2
- export * from './contractAddressMap';
@@ -1,36 +0,0 @@
1
- import { BigNumberish, providers, Signer } from 'ethers';
2
- import { Address } from './interfaces';
3
- /**
4
- * Ensures that given signer is truly a a connected signer
5
- * @param signer an ethers signer
6
- * @throws if signer is invalid or not connected
7
- */
8
- export declare function validateSigner(signer: Signer): void;
9
- /**
10
- * Ensures that given signerOrProvider is truly a provider or a connected signer
11
- * @param signerOrProvider an ethers provider or signer
12
- * @throws if signerOrProvider is invalid or not connected
13
- */
14
- export declare function validateSignerOrProvider(signerOrProvider: Signer | providers.Provider): void;
15
- /**
16
- * Returns the broker address from the Celo registry
17
- * @param signerOrProvider an ethers provider or signer
18
- * @returns the broker address
19
- */
20
- export declare function getBrokerAddressFromRegistry(signerOrProvider: Signer | providers.Provider): Promise<Address>;
21
- /**
22
- * Returns the symbol of an erc20 token
23
- * @param tokenAddr the address of the erc20 token
24
- * @param signerOrProvider an ethers provider or signer
25
- * @returns the symbol of the erc20 token
26
- */
27
- export declare function getSymbolFromTokenAddress(tokenAddr: Address, signerOrProvider: Signer | providers.Provider): Promise<string>;
28
- /**
29
- * Returns a populated tx obj for increasing the allowance of a spender for a given erc20 token by a given amount
30
- * @param tokenAddr the address of the erc20 token
31
- * @param spender the address of the spender
32
- * @param amount the amount to increase the allowance by
33
- * @param signerOrProvider an ethers signer or provider
34
- * @returns the populated TransactionRequest object
35
- */
36
- export declare function increaseAllowance(tokenAddr: string, spender: string, amount: BigNumberish, signerOrProvider: Signer | providers.Provider): Promise<providers.TransactionRequest>;