@mento-protocol/mento-sdk 1.10.2 → 2.0.0-beta.10

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 (254) hide show
  1. package/README.md +114 -48
  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 +5 -0
  15. package/dist/abis/index.d.ts.map +1 -0
  16. package/dist/{cjs/constants → abis}/index.js +5 -2
  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/abis/uniswapV3.d.ts +4 -0
  27. package/dist/abis/uniswapV3.d.ts.map +1 -0
  28. package/dist/abis/uniswapV3.js +15 -0
  29. package/dist/abis/uniswapV3.js.map +1 -0
  30. package/dist/adapters/implementations/ethersAdapter.d.ts +9 -0
  31. package/dist/adapters/implementations/ethersAdapter.d.ts.map +1 -0
  32. package/dist/adapters/implementations/ethersAdapter.js +19 -0
  33. package/dist/adapters/implementations/ethersAdapter.js.map +1 -0
  34. package/dist/adapters/implementations/ethersV5Adapter.d.ts +9 -0
  35. package/dist/adapters/implementations/ethersV5Adapter.d.ts.map +1 -0
  36. package/dist/adapters/implementations/ethersV5Adapter.js +19 -0
  37. package/dist/adapters/implementations/ethersV5Adapter.js.map +1 -0
  38. package/dist/adapters/implementations/viemAdapter.d.ts +9 -0
  39. package/dist/adapters/implementations/viemAdapter.d.ts.map +1 -0
  40. package/dist/adapters/implementations/viemAdapter.js +26 -0
  41. package/dist/adapters/implementations/viemAdapter.js.map +1 -0
  42. package/dist/adapters/index.d.ts +5 -0
  43. package/dist/adapters/index.d.ts.map +1 -0
  44. package/dist/adapters/index.js +10 -0
  45. package/dist/adapters/index.js.map +1 -0
  46. package/dist/adapters/proxies/ethersAdapterProxy.d.ts +25 -0
  47. package/dist/adapters/proxies/ethersAdapterProxy.d.ts.map +1 -0
  48. package/dist/adapters/proxies/ethersAdapterProxy.js +71 -0
  49. package/dist/adapters/proxies/ethersAdapterProxy.js.map +1 -0
  50. package/dist/adapters/proxies/ethersV5AdapterProxy.d.ts +25 -0
  51. package/dist/adapters/proxies/ethersV5AdapterProxy.d.ts.map +1 -0
  52. package/dist/adapters/proxies/ethersV5AdapterProxy.js +71 -0
  53. package/dist/adapters/proxies/ethersV5AdapterProxy.js.map +1 -0
  54. package/dist/adapters/proxies/viemAdapterProxy.d.ts +25 -0
  55. package/dist/adapters/proxies/viemAdapterProxy.d.ts.map +1 -0
  56. package/dist/adapters/proxies/viemAdapterProxy.js +71 -0
  57. package/dist/adapters/proxies/viemAdapterProxy.js.map +1 -0
  58. package/dist/constants/aaveConfig.d.ts +7 -0
  59. package/dist/constants/aaveConfig.d.ts.map +1 -0
  60. package/dist/constants/aaveConfig.js +22 -0
  61. package/dist/constants/aaveConfig.js.map +1 -0
  62. package/dist/constants/addresses.d.ts +14 -0
  63. package/dist/constants/addresses.d.ts.map +1 -0
  64. package/dist/{esm/constants → constants}/addresses.js +17 -16
  65. package/dist/constants/addresses.js.map +1 -0
  66. package/dist/{cjs/enums → constants}/chainId.d.ts +1 -0
  67. package/dist/constants/chainId.d.ts.map +1 -0
  68. package/dist/{cjs/enums → constants}/chainId.js +2 -1
  69. package/dist/constants/chainId.js.map +1 -0
  70. package/dist/constants/contractNames.d.ts +21 -0
  71. package/dist/constants/contractNames.d.ts.map +1 -0
  72. package/dist/constants/contractNames.js +24 -0
  73. package/dist/constants/contractNames.js.map +1 -0
  74. package/dist/constants/index.d.ts +9 -0
  75. package/dist/constants/index.d.ts.map +1 -0
  76. package/dist/constants/index.js +25 -0
  77. package/dist/constants/index.js.map +1 -0
  78. package/dist/constants/mentoAddresses.d.ts +6 -0
  79. package/dist/constants/mentoAddresses.d.ts.map +1 -0
  80. package/dist/constants/mentoAddresses.js +9 -0
  81. package/dist/constants/mentoAddresses.js.map +1 -0
  82. package/dist/{cjs/enums → constants}/proposalState.d.ts +1 -0
  83. package/dist/constants/proposalState.d.ts.map +1 -0
  84. package/dist/{cjs/enums → constants}/proposalState.js +2 -1
  85. package/dist/constants/proposalState.js.map +1 -0
  86. package/dist/constants/protocolAddresses.d.ts +5 -0
  87. package/dist/constants/protocolAddresses.d.ts.map +1 -0
  88. package/dist/constants/protocolAddresses.js +8 -0
  89. package/dist/constants/protocolAddresses.js.map +1 -0
  90. package/dist/constants/stableTokenMetadata.d.ts +12 -0
  91. package/dist/constants/stableTokenMetadata.d.ts.map +1 -0
  92. package/dist/constants/stableTokenMetadata.js +14 -0
  93. package/dist/constants/stableTokenMetadata.js.map +1 -0
  94. package/dist/index.d.ts +67 -0
  95. package/dist/index.d.ts.map +1 -0
  96. package/dist/index.js +122 -0
  97. package/dist/index.js.map +1 -0
  98. package/dist/services/collateralAssetService.d.ts +8 -0
  99. package/dist/services/collateralAssetService.d.ts.map +1 -0
  100. package/dist/services/collateralAssetService.js +47 -0
  101. package/dist/services/collateralAssetService.js.map +1 -0
  102. package/dist/services/index.d.ts +6 -0
  103. package/dist/services/index.d.ts.map +1 -0
  104. package/dist/{cjs/interfaces → services}/index.js +6 -4
  105. package/dist/services/index.js.map +1 -0
  106. package/dist/services/stableTokenService.d.ts +9 -0
  107. package/dist/services/stableTokenService.d.ts.map +1 -0
  108. package/dist/services/stableTokenService.js +40 -0
  109. package/dist/services/stableTokenService.js.map +1 -0
  110. package/dist/services/supply/ISupplyCalculator.d.ts +14 -0
  111. package/dist/services/supply/ISupplyCalculator.d.ts.map +1 -0
  112. package/dist/{cjs/interfaces/tradingLimitsState.js → services/supply/ISupplyCalculator.js} +1 -0
  113. package/dist/services/supply/ISupplyCalculator.js.map +1 -0
  114. package/dist/services/supply/aaveSupplyCalculator.d.ts +21 -0
  115. package/dist/services/supply/aaveSupplyCalculator.d.ts.map +1 -0
  116. package/dist/services/supply/aaveSupplyCalculator.js +46 -0
  117. package/dist/services/supply/aaveSupplyCalculator.js.map +1 -0
  118. package/dist/services/supply/calculatorFactory.d.ts +8 -0
  119. package/dist/services/supply/calculatorFactory.d.ts.map +1 -0
  120. package/dist/services/supply/calculatorFactory.js +3 -0
  121. package/dist/services/supply/calculatorFactory.js.map +1 -0
  122. package/dist/services/supply/defaultCalculatorFactory.d.ts +9 -0
  123. package/dist/services/supply/defaultCalculatorFactory.d.ts.map +1 -0
  124. package/dist/services/supply/defaultCalculatorFactory.js +27 -0
  125. package/dist/services/supply/defaultCalculatorFactory.js.map +1 -0
  126. package/dist/services/supply/index.d.ts +7 -0
  127. package/dist/services/supply/index.d.ts.map +1 -0
  128. package/dist/{cjs → services/supply}/index.js +7 -6
  129. package/dist/services/supply/index.js.map +1 -0
  130. package/dist/services/supply/multisigSupplyCalculator.d.ts +9 -0
  131. package/dist/services/supply/multisigSupplyCalculator.d.ts.map +1 -0
  132. package/dist/services/supply/multisigSupplyCalculator.js +33 -0
  133. package/dist/services/supply/multisigSupplyCalculator.js.map +1 -0
  134. package/dist/services/supply/uniV3SupplyCalculator.d.ts +21 -0
  135. package/dist/services/supply/uniV3SupplyCalculator.d.ts.map +1 -0
  136. package/dist/services/supply/uniV3SupplyCalculator.js +233 -0
  137. package/dist/services/supply/uniV3SupplyCalculator.js.map +1 -0
  138. package/dist/services/supplyAdjustmentService.d.ts +14 -0
  139. package/dist/services/supplyAdjustmentService.d.ts.map +1 -0
  140. package/dist/services/supplyAdjustmentService.js +46 -0
  141. package/dist/services/supplyAdjustmentService.js.map +1 -0
  142. package/dist/services/tokenMetadataService.d.ts +8 -0
  143. package/dist/services/tokenMetadataService.d.ts.map +1 -0
  144. package/dist/services/tokenMetadataService.js +44 -0
  145. package/dist/services/tokenMetadataService.js.map +1 -0
  146. package/dist/{cjs/types → types}/contractAddresses.d.ts +1 -1
  147. package/dist/types/contractAddresses.d.ts.map +1 -0
  148. package/dist/{cjs/types → types}/contractAddresses.js +1 -0
  149. package/dist/types/contractAddresses.js.map +1 -0
  150. package/dist/types/exchange.d.ts +6 -0
  151. package/dist/types/exchange.d.ts.map +1 -0
  152. package/dist/{cjs/interfaces/tradingLimit.js → types/exchange.js} +1 -0
  153. package/dist/types/exchange.js.map +1 -0
  154. package/dist/types/index.d.ts +5 -0
  155. package/dist/types/index.d.ts.map +1 -0
  156. package/dist/{cjs/types → types}/index.js +4 -1
  157. package/dist/types/index.js.map +1 -0
  158. package/dist/types/provider.d.ts +11 -0
  159. package/dist/types/provider.d.ts.map +1 -0
  160. package/dist/{cjs/interfaces/tradingLimitsConfig.js → types/provider.js} +1 -0
  161. package/dist/types/provider.js.map +1 -0
  162. package/dist/types/token.d.ts +25 -0
  163. package/dist/types/token.d.ts.map +1 -0
  164. package/dist/{cjs/interfaces/IChainClient.js → types/token.js} +1 -0
  165. package/dist/types/token.js.map +1 -0
  166. package/dist/utils/index.d.ts +2 -0
  167. package/dist/utils/index.d.ts.map +1 -0
  168. package/dist/{cjs/enums → utils}/index.js +2 -2
  169. package/dist/utils/index.js.map +1 -0
  170. package/dist/utils/retry.d.ts +12 -0
  171. package/dist/utils/retry.d.ts.map +1 -0
  172. package/dist/utils/retry.js +28 -0
  173. package/dist/utils/retry.js.map +1 -0
  174. package/package.json +33 -61
  175. package/dist/cjs/ChainClient.d.ts +0 -9
  176. package/dist/cjs/ChainClient.js +0 -58
  177. package/dist/cjs/TestChainClient.d.ts +0 -7
  178. package/dist/cjs/TestChainClient.js +0 -41
  179. package/dist/cjs/constants/addresses.d.ts +0 -4
  180. package/dist/cjs/constants/addresses.js +0 -64
  181. package/dist/cjs/constants/index.d.ts +0 -2
  182. package/dist/cjs/constants/tradablePairs.42220.d.ts +0 -2
  183. package/dist/cjs/constants/tradablePairs.42220.js +0 -6407
  184. package/dist/cjs/constants/tradablePairs.44787.d.ts +0 -2
  185. package/dist/cjs/constants/tradablePairs.44787.js +0 -7391
  186. package/dist/cjs/constants/tradablePairs.d.ts +0 -16
  187. package/dist/cjs/constants/tradablePairs.js +0 -53
  188. package/dist/cjs/enums/index.d.ts +0 -2
  189. package/dist/cjs/governance.d.ts +0 -62
  190. package/dist/cjs/governance.js +0 -151
  191. package/dist/cjs/index.d.ts +0 -6
  192. package/dist/cjs/interfaces/IChainClient.d.ts +0 -6
  193. package/dist/cjs/interfaces/index.d.ts +0 -4
  194. package/dist/cjs/interfaces/tradingLimit.d.ts +0 -7
  195. package/dist/cjs/interfaces/tradingLimitsConfig.d.ts +0 -10
  196. package/dist/cjs/interfaces/tradingLimitsState.d.ts +0 -9
  197. package/dist/cjs/limits.d.ts +0 -33
  198. package/dist/cjs/limits.js +0 -130
  199. package/dist/cjs/mento.d.ts +0 -238
  200. package/dist/cjs/mento.js +0 -559
  201. package/dist/cjs/routeUtils.d.ts +0 -304
  202. package/dist/cjs/routeUtils.js +0 -372
  203. package/dist/cjs/types/contractAddressMap.d.ts +0 -4
  204. package/dist/cjs/types/contractAddressMap.js +0 -2
  205. package/dist/cjs/types/index.d.ts +0 -2
  206. package/dist/cjs/utils.d.ts +0 -50
  207. package/dist/cjs/utils.js +0 -129
  208. package/dist/esm/ChainClient.d.ts +0 -9
  209. package/dist/esm/ChainClient.js +0 -54
  210. package/dist/esm/TestChainClient.d.ts +0 -7
  211. package/dist/esm/TestChainClient.js +0 -37
  212. package/dist/esm/constants/addresses.d.ts +0 -4
  213. package/dist/esm/constants/index.d.ts +0 -2
  214. package/dist/esm/constants/index.js +0 -2
  215. package/dist/esm/constants/tradablePairs.42220.d.ts +0 -2
  216. package/dist/esm/constants/tradablePairs.42220.js +0 -6404
  217. package/dist/esm/constants/tradablePairs.44787.d.ts +0 -2
  218. package/dist/esm/constants/tradablePairs.44787.js +0 -7388
  219. package/dist/esm/constants/tradablePairs.d.ts +0 -16
  220. package/dist/esm/constants/tradablePairs.js +0 -26
  221. package/dist/esm/enums/chainId.d.ts +0 -4
  222. package/dist/esm/enums/chainId.js +0 -5
  223. package/dist/esm/enums/index.d.ts +0 -2
  224. package/dist/esm/enums/index.js +0 -2
  225. package/dist/esm/enums/proposalState.d.ts +0 -10
  226. package/dist/esm/enums/proposalState.js +0 -11
  227. package/dist/esm/governance.d.ts +0 -62
  228. package/dist/esm/governance.js +0 -147
  229. package/dist/esm/index.d.ts +0 -6
  230. package/dist/esm/index.js +0 -6
  231. package/dist/esm/interfaces/IChainClient.d.ts +0 -6
  232. package/dist/esm/interfaces/IChainClient.js +0 -1
  233. package/dist/esm/interfaces/index.d.ts +0 -4
  234. package/dist/esm/interfaces/index.js +0 -4
  235. package/dist/esm/interfaces/tradingLimit.d.ts +0 -7
  236. package/dist/esm/interfaces/tradingLimit.js +0 -1
  237. package/dist/esm/interfaces/tradingLimitsConfig.d.ts +0 -10
  238. package/dist/esm/interfaces/tradingLimitsConfig.js +0 -1
  239. package/dist/esm/interfaces/tradingLimitsState.d.ts +0 -9
  240. package/dist/esm/interfaces/tradingLimitsState.js +0 -1
  241. package/dist/esm/limits.d.ts +0 -33
  242. package/dist/esm/limits.js +0 -123
  243. package/dist/esm/mento.d.ts +0 -238
  244. package/dist/esm/mento.js +0 -555
  245. package/dist/esm/routeUtils.d.ts +0 -304
  246. package/dist/esm/routeUtils.js +0 -362
  247. package/dist/esm/types/contractAddressMap.d.ts +0 -4
  248. package/dist/esm/types/contractAddressMap.js +0 -1
  249. package/dist/esm/types/contractAddresses.d.ts +0 -23
  250. package/dist/esm/types/contractAddresses.js +0 -1
  251. package/dist/esm/types/index.d.ts +0 -2
  252. package/dist/esm/types/index.js +0 -2
  253. package/dist/esm/utils.d.ts +0 -50
  254. package/dist/esm/utils.js +0 -119
@@ -1,16 +0,0 @@
1
- import { TradablePair } from '../mento';
2
- export interface TradablePairWithSpread extends TradablePair {
3
- spreadData: {
4
- totalSpreadPercent: number;
5
- hops: Array<{
6
- exchangeId: string;
7
- spreadPercent: number;
8
- }>;
9
- };
10
- }
11
- /**
12
- * Gets cached tradable pairs for a specific chain ID
13
- * @param chainId - The chain ID to get cached pairs for
14
- * @returns Promise resolving to the cached tradable pairs or undefined if not available
15
- */
16
- export declare function getCachedTradablePairs(chainId: number): Promise<readonly (TradablePair | TradablePairWithSpread)[] | undefined>;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.getCachedTradablePairs = void 0;
36
- /**
37
- * Gets cached tradable pairs for a specific chain ID
38
- * @param chainId - The chain ID to get cached pairs for
39
- * @returns Promise resolving to the cached tradable pairs or undefined if not available
40
- */
41
- function getCachedTradablePairs(chainId) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- switch (chainId) {
44
- case 42220:
45
- return yield Promise.resolve().then(() => __importStar(require('./tradablePairs.42220'))).then((module) => module.tradablePairs42220);
46
- case 44787:
47
- return yield Promise.resolve().then(() => __importStar(require('./tradablePairs.44787'))).then((module) => module.tradablePairs44787);
48
- default:
49
- return undefined;
50
- }
51
- });
52
- }
53
- exports.getCachedTradablePairs = getCachedTradablePairs;
@@ -1,2 +0,0 @@
1
- export * from './proposalState';
2
- export * from './chainId';
@@ -1,62 +0,0 @@
1
- import { BigNumberish, Signer, providers } from 'ethers';
2
- import { MentoGovernor } from '@mento-protocol/mento-core-ts';
3
- import { IChainClient } from './interfaces';
4
- export declare class Governance {
5
- private chainClient;
6
- constructor(chainClient: IChainClient);
7
- constructor(signerOrProvider: Signer | providers.Provider);
8
- /**
9
- * This function retrieves the MentoGovernor contract.
10
- * @returns The MentoGovernor contract.
11
- */
12
- getGovernorContract(): Promise<MentoGovernor>;
13
- /**
14
- * Generates a transaction that submits a proposal to be created to the Mento Governor contract using the specified values.
15
- * @param targets The addresses of the contracts to be called during proposal execution.
16
- * @param values The values to be passed to the calls to the target contracts.
17
- * @param calldatas The calldata to be passed to the calls to the target contracts.
18
- * @param description A human readable description of the proposal.
19
- * @returns The transaction request.
20
- */
21
- createProposal(targets: string[], values: BigNumberish[], calldatas: string[], description: string): Promise<providers.TransactionRequest>;
22
- /**
23
- * Generates a transaction that will queue the proposal with the specified id to be executed.
24
- * @param proposalId The id of the proposal to queue.
25
- * @returns The transaction request.
26
- */
27
- queueProposal(proposalId: BigNumberish): Promise<providers.TransactionRequest>;
28
- /**
29
- * Executes the proposal with the specified id.
30
- * @param proposalId The id of the proposal to execute.
31
- * @returns The transaction request.
32
- */
33
- executeProposal(proposalId: BigNumberish): Promise<providers.TransactionRequest>;
34
- /**
35
- * Submits a vote to the Mento Governor contract for the specified proposal.
36
- * @param proposalId The id of the proposal to vote on.
37
- * @param support Whether or not to support the proposal.
38
- * @returns The transaction request.
39
- */
40
- castVote(proposalId: BigNumberish, support: BigNumberish): Promise<providers.TransactionRequest>;
41
- /**
42
- * Cancels the proposal with the specified id.
43
- * @param proposalId The id of the proposal to vote on.
44
- * @param support Whether or not to support the proposal.
45
- * @returns The transaction request.
46
- */
47
- cancelProposal(proposalId: BigNumberish): Promise<providers.TransactionRequest>;
48
- /**
49
- * Returns the state of the proposal with the specified id.
50
- * @param proposalId The id of the proposal to get the state of.
51
- * @returns The state of the proposal.
52
- */
53
- getProposalState(proposalId: BigNumberish): Promise<string>;
54
- /**
55
- * This function validates the args that are to be used in the createProposal function.
56
- * @param targets The addresses of the contracts to be called during proposal execution.
57
- * @param values The values to be passed to the calls to the target contracts.
58
- * @param calldatas The calldata to be passed to the calls to the target contracts.
59
- * @param description A human readable description of the proposal.
60
- */
61
- private validateProposalArgs;
62
- }
@@ -1,151 +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.Governance = void 0;
13
- const ethers_1 = require("ethers");
14
- const mento_core_ts_1 = require("@mento-protocol/mento-core-ts");
15
- const ChainClient_1 = require("./ChainClient");
16
- const TestChainClient_1 = require("./TestChainClient");
17
- const enums_1 = require("./enums");
18
- const constants_1 = require("./constants");
19
- class Governance {
20
- constructor(arg) {
21
- // TODO: Remove use of TestChainClient in future this is only meant for testing
22
- if (arg instanceof ChainClient_1.ChainClient || arg instanceof TestChainClient_1.TestChainClient) {
23
- this.chainClient = arg;
24
- }
25
- else if (ethers_1.Signer.isSigner(arg) || ethers_1.providers.Provider.isProvider(arg)) {
26
- this.chainClient = new ChainClient_1.ChainClient(arg);
27
- }
28
- else {
29
- throw new Error('Invalid constructor argument');
30
- }
31
- }
32
- /**
33
- * This function retrieves the MentoGovernor contract.
34
- * @returns The MentoGovernor contract.
35
- */
36
- getGovernorContract() {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- const chainId = yield this.chainClient.getChainId();
39
- const contracts = constants_1.addresses[chainId];
40
- if (!contracts) {
41
- throw new Error(`Contracts not deployed on network with chain id ${chainId}`);
42
- }
43
- const mentoGovernorAddress = contracts.MentoGovernor;
44
- return mento_core_ts_1.MentoGovernor__factory.connect(mentoGovernorAddress, yield this.chainClient.getSigner());
45
- });
46
- }
47
- /**
48
- * Generates a transaction that submits a proposal to be created to the Mento Governor contract using the specified values.
49
- * @param targets The addresses of the contracts to be called during proposal execution.
50
- * @param values The values to be passed to the calls to the target contracts.
51
- * @param calldatas The calldata to be passed to the calls to the target contracts.
52
- * @param description A human readable description of the proposal.
53
- * @returns The transaction request.
54
- */
55
- createProposal(targets, values, calldatas, description) {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- this.validateProposalArgs(targets, values, calldatas, description);
58
- const governor = yield this.getGovernorContract();
59
- const tx = yield governor.populateTransaction['propose(address[],uint256[],bytes[],string)'](targets, values, calldatas, description);
60
- return yield this.chainClient.populateTransaction(tx);
61
- });
62
- }
63
- /**
64
- * Generates a transaction that will queue the proposal with the specified id to be executed.
65
- * @param proposalId The id of the proposal to queue.
66
- * @returns The transaction request.
67
- */
68
- queueProposal(proposalId) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- const governor = yield this.getGovernorContract();
71
- const tx = yield governor.populateTransaction['queue(uint256)'](proposalId);
72
- return yield this.chainClient.populateTransaction(tx);
73
- });
74
- }
75
- /**
76
- * Executes the proposal with the specified id.
77
- * @param proposalId The id of the proposal to execute.
78
- * @returns The transaction request.
79
- */
80
- executeProposal(proposalId) {
81
- return __awaiter(this, void 0, void 0, function* () {
82
- const governor = yield this.getGovernorContract();
83
- const tx = yield governor.populateTransaction['execute(uint256)'](proposalId);
84
- return yield this.chainClient.populateTransaction(tx);
85
- });
86
- }
87
- /**
88
- * Submits a vote to the Mento Governor contract for the specified proposal.
89
- * @param proposalId The id of the proposal to vote on.
90
- * @param support Whether or not to support the proposal.
91
- * @returns The transaction request.
92
- */
93
- castVote(proposalId, support) {
94
- return __awaiter(this, void 0, void 0, function* () {
95
- const governor = yield this.getGovernorContract();
96
- const tx = yield governor.populateTransaction.castVote(proposalId, support);
97
- return yield this.chainClient.populateTransaction(tx);
98
- });
99
- }
100
- /**
101
- * Cancels the proposal with the specified id.
102
- * @param proposalId The id of the proposal to vote on.
103
- * @param support Whether or not to support the proposal.
104
- * @returns The transaction request.
105
- */
106
- cancelProposal(proposalId) {
107
- return __awaiter(this, void 0, void 0, function* () {
108
- const governor = yield this.getGovernorContract();
109
- const tx = yield governor.populateTransaction.cancel(proposalId);
110
- return yield this.chainClient.populateTransaction(tx);
111
- });
112
- }
113
- /**
114
- * Returns the state of the proposal with the specified id.
115
- * @param proposalId The id of the proposal to get the state of.
116
- * @returns The state of the proposal.
117
- */
118
- getProposalState(proposalId) {
119
- return __awaiter(this, void 0, void 0, function* () {
120
- const governor = yield this.getGovernorContract();
121
- const state = (yield governor.functions.state(proposalId))[0];
122
- return enums_1.ProposalState[state];
123
- });
124
- }
125
- /**
126
- * This function validates the args that are to be used in the createProposal function.
127
- * @param targets The addresses of the contracts to be called during proposal execution.
128
- * @param values The values to be passed to the calls to the target contracts.
129
- * @param calldatas The calldata to be passed to the calls to the target contracts.
130
- * @param description A human readable description of the proposal.
131
- */
132
- validateProposalArgs(targets, values, calldatas, description) {
133
- if (!targets || targets.length === 0) {
134
- throw new Error('Targets must be specified');
135
- }
136
- if (!values || values.length === 0) {
137
- throw new Error('Values must be specified');
138
- }
139
- if (!calldatas || calldatas.length === 0) {
140
- throw new Error('Calldatas must be specified');
141
- }
142
- if (!description) {
143
- throw new Error('Description must be specified');
144
- }
145
- if (targets.length !== values.length ||
146
- targets.length !== calldatas.length) {
147
- throw new Error('Targets, values, and calldatas must all have the same length');
148
- }
149
- }
150
- }
151
- exports.Governance = Governance;
@@ -1,6 +0,0 @@
1
- export * from './constants';
2
- export * from './governance';
3
- export * from './mento';
4
- export * from './routeUtils';
5
- export { ContractAddresses } from './types';
6
- export * from './utils';
@@ -1,6 +0,0 @@
1
- import { ethers, providers } from 'ethers';
2
- export interface IChainClient {
3
- getSigner(): Promise<ethers.Signer | providers.Provider>;
4
- getChainId(): Promise<number>;
5
- populateTransaction(tx: ethers.PopulatedTransaction): Promise<providers.TransactionRequest>;
6
- }
@@ -1,4 +0,0 @@
1
- export * from './tradingLimit';
2
- export * from './tradingLimitsConfig';
3
- export * from './tradingLimitsState';
4
- export * from './IChainClient';
@@ -1,7 +0,0 @@
1
- export type Address = string;
2
- export interface TradingLimit {
3
- asset: Address;
4
- maxIn: number;
5
- maxOut: number;
6
- until: number;
7
- }
@@ -1,10 +0,0 @@
1
- import { Address } from './tradingLimit';
2
- export interface TradingLimitsConfig {
3
- asset: Address;
4
- timestep0: number;
5
- timestep1: number;
6
- limit0: number;
7
- limit1: number;
8
- limitGlobal: number;
9
- flags: number;
10
- }
@@ -1,9 +0,0 @@
1
- import { Address } from './tradingLimit';
2
- export interface TradingLimitsState {
3
- asset: Address;
4
- lastUpdated0: number;
5
- lastUpdated1: number;
6
- netflow0: number;
7
- netflow1: number;
8
- netflowGlobal: number;
9
- }
@@ -1,33 +0,0 @@
1
- import { Address, TradingLimit, TradingLimitsConfig, TradingLimitsState } from './interfaces';
2
- import { Broker } from '@mento-protocol/mento-core-ts';
3
- /**
4
- * Returns the limit configuration in the broker for the given exchange and asset
5
- * @param broker an instance of the broker
6
- * @param exchangeId the id of the exchange
7
- * @param asset the address of the limited asset
8
- * @returns the limit configuration
9
- */
10
- export declare function getLimitsConfig(broker: Broker, exchangeId: string, asset: Address): Promise<TradingLimitsConfig>;
11
- /**
12
- * Returns the limit state in the broker for the given exchange and asset
13
- * @param broker an instance of the broker
14
- * @param exchangeId the id of the exchange
15
- * @param asset the address of the limited asset
16
- * @returns the limit state
17
- */
18
- export declare function getLimitsState(broker: Broker, exchangeId: string, asset: Address): Promise<TradingLimitsState>;
19
- /**
20
- * Returns a human-friendly representation of the limits for the given exchange and asset
21
- * @param broker an instance of the broker
22
- * @param exchangeId the id of the exchange
23
- * @param asset the address of the asset with the limit
24
- * @returns a list of TradingLimit objects
25
- */
26
- export declare function getLimits(broker: Broker, exchangeId: string, asset: Address): Promise<TradingLimit[]>;
27
- /**
28
- * Returns the limit id for the given exchange and asset
29
- * @param exchangeId the id of the exchange
30
- * @param asset the address of the asset with the limit
31
- * @returns the limit id
32
- */
33
- export declare function getLimitId(exchangeId: string, asset: Address): string;
@@ -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;